Compare commits

...

276 Commits

Author SHA1 Message Date
Saoud Rizwan b43fb7777c Merge PR #13069 head (cloud models, prompt dedupe, org scope fixes) into desktop-experimental
# Conflicts:
#	apps/examples/desktop-app/sidecar/chat-session.ts
2026-08-17 18:27:06 -07:00
John Choi 8ea71e3278 fix(desktop): align cloud header status 2026-08-17 18:23:38 -07:00
John Choi f4abb7e14b feat(desktop): load Cline Cloud agent models 2026-08-17 18:16:56 -07:00
John Choi 1e08d8f277 fix(desktop): refresh cloud organization scope 2026-08-17 18:16:49 -07:00
John Choi 8bebcd1f37 Merge remote-tracking branch 'origin/main' into work/pr-13069-four-fixes
# Conflicts:
#	apps/examples/desktop-app/webview/components/agent-sidebar.tsx
2026-08-17 18:07:11 -07:00
Saoud Rizwan d4b415f8ab fix(desktop): trim the persisted transcript on checkpoint restore (#13259)
A restore that reuses the source session id rolled the workspace back but
left the persisted transcript describing the discarded turns, so the chat
kept showing turns whose file changes had just been reverted.

Before #13075 the restore reply carried the trimmed messages and the
webview rendered them directly. Now the webview always re-reads through
read_session_messages, which prefers the persisted file over the live
session, so the trimmed history the sidecar puts on the live session is
never read. Persist it as well.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-17 18:03:52 -07:00
John Choi 14f9def7ed fix(desktop): reconcile terminal cloud replies 2026-08-17 17:56:42 -07:00
John Choi 2e6c25785e fix(desktop): dedupe live cloud prompts 2026-08-17 17:41:06 -07:00
Saoud Rizwan b565e5b9ca Merge PR #13069 head (cloud provisioning/handoff fixes) into desktop-experimental
# Conflicts:
#	apps/examples/desktop-app/webview/hooks/use-chat-session.ts
2026-08-17 17:36:14 -07:00
Bee 6b3f034bce fix(desktop): align usage table columns CLINE-2996 (#13325)
* fix(desktop): align usage table columns

* fix(desktop): show usage link for empty history
2026-08-17 17:30:08 -07:00
Saoud Rizwan 0313c34b1a chore(desktop): release v0.0.14-beta.1 2026-08-17 17:29:42 -07:00
Saoud Rizwan d0f49330a3 Merge remote-tracking branch 'origin/main' into desktop-experimental
# Conflicts:
#	apps/examples/desktop-app/webview/components/agent-sidebar.tsx
#	apps/examples/desktop-app/webview/components/views/settings/settings-view.tsx
2026-08-17 17:27:25 -07:00
Saoud Rizwan 05a6974ef8 feat(desktop): surface beta channel identity in-app (#13322)
Beta builds (prerelease versions from desktop-experimental, shipped as
'Cline Code Beta') now identify themselves everywhere users look: a Beta
pill in the sidebar footer, the product name in the sidebar hover card,
an About row in Settings > General with version + channel, the runtime
window title, and the tray menu/tooltip (via package_info, which carries
the overlay's productName).

Channel detection is a pure version-string check (-beta suffix) in the
new webview/lib/app-channel.ts — the version is baked into package.json
at build time and reported by the sidecar's get_process_context, so it
works in both the Tauri shell and web dev mode with no new plumbing.
Stable builds render no channel UI at all.
2026-08-17 17:24:22 -07:00
Saoud Rizwan 5ad2dd5fc8 feat(desktop): beta release channel from desktop-experimental branch (#13321)
* feat(desktop): add beta release channel from desktop-experimental branch

Adds a 'channel' input (stable|beta) to desktop-publish.yml. Beta releases
are tagged desktop-vX.Y.Z-beta.N on the desktop-experimental branch, built
with the tauri.beta.conf.json overlay (Cline Code Beta / bot.cline.app.beta,
side-by-side install with stable), published as prerelease GitHub releases,
and served by a separate rolling desktop-beta update feed. Both channels
dispatch from main so the PublishDesktop signing gates are unchanged.

Guards: stable channel now rejects prerelease tags (previously a beta tag
could clobber desktop-latest and auto-update every stable install onto it),
feed selection is fail-closed and cross-checked in the release job, and the
build asserts the compiled binary embeds exactly its own channel's feed URL.
Changelog extraction is exact-version now that stable and beta sections
interleave across branch merges.

Process doc in apps/examples/desktop-app/EXPERIMENTAL.md; publish-desktop
skill now asks stable-or-beta.

* docs(desktop): warn against renaming the desktop-latest feed

* docs(desktop): document the code-trust model for publish approvals

The beta dispatch-from-main invariant protects the workflow definition, not
the checked-out tag's build scripts, which run with signing secrets in scope
for stable and beta alike. Make explicit that the PublishDesktop reviewer
approval is the trust gate for that code, and that desktop-experimental
therefore needs main-grade merge controls.
2026-08-17 17:24:01 -07:00
John Choi db31380268 Merge remote-tracking branch 'origin/main' into work/pr-13069-four-fixes 2026-08-17 17:18:21 -07:00
Bee 87be867599 fix(desktop): make routine selectors clickable (#13324) 2026-08-17 17:05:33 -07:00
Saoud Rizwan b123f2eb54 Merge remote-tracking branch 'origin/main' into desktop-experimental 2026-08-17 16:21:56 -07:00
Bee 26cb0ec9eb test(llms): use Google language operation (#13318) 2026-08-17 15:35:56 -07:00
John Choi 303722a559 fix(desktop): show prompt during cloud provisioning 2026-08-17 14:34:43 -07:00
John Choi 5fff9cbb4c fix(desktop): preserve prompt during cloud handoff 2026-08-17 12:30:16 -07:00
John Choi 70e0a3731d fix(desktop): harden cloud provisioning recovery 2026-08-17 12:18:18 -07:00
Haley Park eed78103a4 feat(ui): AskQuestion component redesign (#13236)
* feat(ui): support explicit follow-up question submission

* Fix Enter handling for question options

* Strengthen question keyboard regression test
2026-08-17 09:32:03 -07:00
Haley Park 456f86bb3a style(desktop): session hover cards styling (#13256)
* style(desktop): simplify session hover cards

* docs: add hover card screenshots

* chore: remove PR screenshot assets

* style(desktop): address hover card review
2026-08-17 09:31:56 -07:00
Haley Park e86d988234 feat(ui): add animated reasoning and tool disclosures (#13254)
* feat(ui): add animated disclosure presentation

* docs: add disclosure screenshots

* docs: remove PR screenshots

* fix(ui): support inert across React versions
2026-08-17 09:31:41 -07:00
Fnine59 041afb718b fix(vscode): restore Gemini custom base URL (#13247) 2026-08-17 13:16:43 +02:00
John Choi d52af3112d Merge remote-tracking branch 'origin/pr/13069' into feat/experimental-desktop-pr-bundle
# Conflicts:
#	apps/examples/desktop-app/webview/app/page.tsx
2026-08-14 19:21:03 -07:00
John Choi eccb0db669 fix(desktop): recover cloud provisioning handoff 2026-08-14 19:17:50 -07:00
John Choi a9af97a83f fix(desktop): preserve cloud session routing with SSH environments 2026-08-14 19:16:41 -07:00
John Choi 53388f5f9c Merge remote-tracking branch 'origin/pr/13069' into feat/experimental-desktop-pr-bundle
# Conflicts:
#	apps/examples/desktop-app/sidecar/cloud-sessions.test.ts
#	apps/examples/desktop-app/sidecar/commands.ts
#	apps/examples/desktop-app/webview/components/views/chat/chat-input-bar.tsx
#	apps/examples/desktop-app/webview/components/views/settings/settings-view.tsx
#	apps/examples/desktop-app/webview/hooks/use-chat-session.test.tsx
#	apps/examples/desktop-app/webview/hooks/use-chat-session.ts
2026-08-14 19:00:05 -07:00
John Choi 093e9dd3d5 fix(desktop): harden cloud session creation 2026-08-14 18:54:31 -07:00
John Choi d35f4a043b fix: reconcile experimental desktop feature stack 2026-08-14 18:34:07 -07:00
John Choi bd9ee23f6c Merge origin/main into desktop cloud sessions 2026-08-14 18:32:55 -07:00
John Choi 10ff456e93 Merge remote-tracking branch 'origin/pr/13225' into feat/experimental-desktop-pr-bundle 2026-08-14 17:58:48 -07:00
John Choi cb34ba5cf9 Merge remote-tracking branch 'origin/pr/13031' into feat/experimental-desktop-pr-bundle 2026-08-14 17:58:44 -07:00
John Choi 2ed4b811be Merge remote-tracking branch 'origin/pr/12890' into feat/experimental-desktop-pr-bundle 2026-08-14 17:53:04 -07:00
John Choi 7bf542ddab Merge remote-tracking branch 'origin/pr/13069' into feat/experimental-desktop-pr-bundle
# Conflicts:
#	apps/examples/desktop-app/sidecar/commands.ts
#	apps/examples/desktop-app/sidecar/session-data/messages.test.ts
#	apps/examples/desktop-app/webview/components/views/chat/chat-input-bar.test.tsx
#	apps/examples/desktop-app/webview/components/views/chat/chat-input-bar.tsx
#	apps/examples/desktop-app/webview/components/views/settings/settings-view.tsx
#	apps/examples/desktop-app/webview/hooks/use-chat-session.test.tsx
#	apps/examples/desktop-app/webview/hooks/use-chat-session.ts
2026-08-14 17:43:00 -07:00
Bee 8bbdde2a5c feat(llms): add model-driven image generation (#13025)
* feat: add image generation support

* fix(llms): preserve mixed image model behavior

* fix(llms): validate generated image models

* fix(llms): preserve mixed image response streaming

* fix(llms): preserve runtime tool ownership

* fix(llms): address image generation review feedback

* fix(desktop): relay images for attached hub sessions

* chore(llms): regenerate provider and model catalog

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(vscode): preserve SDK model capabilities across the catalog boundary

The new modelSupportsToolCalling gate treats a populated capability list
without "tools" as authoritative. But the VS Code host round-trips model
metadata through the legacy ModelInfo shape, and toSdkModelInfo
reconstructed capability arrays from the legacy booleans alone — which
have no "tools" projection. Every model with any capability flag set
came back as "cannot call tools", so sessions registered zero tools and
the file-edit e2e failed on all platforms (the editor tool call resolved
to "Unknown tool" and the edit never reached disk).

Fix, following the modalities-passthrough pattern so stacked capability
PRs can reuse it:

- Preserve the SDK capability list verbatim on legacy ModelInfo at the
  catalog boundary (adaptSdkModelInfo); union user overrides into it
  without ever fabricating a list from overrides alone.
- Seed toSdkModelInfo from the preserved list, and when none survived,
  emit an explicit "tools" signal (honoring legacy supportsTools=false)
  so reconstructed arrays can never silently disable tool calling.
- Add a shared modelHasCapability(model, capability,
  {assumeWhenUnspecified}) helper: missing or empty capability lists
  carry no signal and each check declares its own default. Future
  capability gates should route through it instead of reading
  model.capabilities directly.

Verified: file-edit e2e (Single Root + Multi-Roots) passes locally;
shared/core/llms/model-catalog/session-factory suites and typechecks
pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* chore(llms): refresh generated model catalog

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-14 12:58:53 -07:00
Bee da05eeb02d feat(desktop): add microphone transcription input (#13023)
* feat(desktop): add voice input

* fix(desktop): harden voice transcription input

* fix(llms): scope voice transcription models

* fix(desktop): guard batch voice transcripts

* refactor(voice): defer chat model filtering

* fix(desktop): invalidate stale streaming transcripts

* fix(desktop): preserve batch transcription lifecycle

* chore(llms): refresh voice model catalog

* Mic Icon

* Auto

* test(desktop): align speech input icon assertions
2026-08-14 10:57:29 -07:00
Saoud Rizwan 2be49cf91b chore(desktop): release v0.0.13 2026-08-14 10:18:33 -07:00
Haley Park b851cd86d1 docs(ui): expand agent component stories (#13235) 2026-08-14 09:49:22 -07:00
Saoud Rizwan 3e0aac53a2 chore(vscode): prepare 4.1.10 release 2026-08-14 01:44:30 -07:00
Saoud Rizwan ad442cbb6a chore(cli): release v3.0.55 2026-08-14 00:39:01 -07:00
Saoud Rizwan 225f65cc0e chore(sdk): release v0.0.75 2026-08-14 00:16:53 -07:00
Saoud Rizwan 8a619a9ea6 test(llms): decouple Vertex web-search coverage from the catalog default
The Vertex case asserted that a bare providerId resolves to a model
without web search, which only held because the generated catalog's
Vertex default happened to be a Claude route. models.dev has since moved
that default to gemini-3.7-flash, which does support native web search,
so the assertion failed on the next catalog regen while the behavior it
guarded was unchanged.

Drop the catalog-dependent case and cover the default-model fallback
against a synthetic manifest instead, where the excluded route is stated
by the test rather than inherited from upstream data.
2026-08-14 00:16:48 -07:00
Saoud Rizwan 2e46676952 style: apply biome formatting to files that drifted on main 2026-08-14 00:16:43 -07:00
Bee 102e08f5f4 fix(core): reclaim idle plugin sandbox processes (#13227)
* fix(core): reclaim idle plugin sandboxes

* fix(core): centralize sandbox idle shutdown

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-13 23:40:07 -07:00
Saoud Rizwan 942f76e8e7 feat: add web search settings toggle to VS Code extension and desktop app (#13245) 2026-08-13 23:18:18 -07:00
Saoud Rizwan 57eb181bab fix(cli): say nothing when the Hub is only finishing an update (#13249)
The outdated_hub notice reports a state the user cannot act on: this CLI
is already the newer build, the Hub is behind only because retiring it
would kill the sessions it is serving, and the swap happens on its own at
the next launch. A toast that interrupts to say "no action needed" is
still an interruption, and the desktop surface already concluded the same
thing by rendering nothing for this reason.

It also could not deliver the message it existed for. Toast caps at
maxWidth = Math.min(44, width - 4), and the 61-character string did not
wrap, so what actually rendered was "Update finishes the next time Cline"
- a sentence cut off before the reassuring half. Identical at 120 and 200
columns, so widening the terminal did not help.

The classification stays in core and still earns its keep at this call
site: outdated_hub is what stops the update-and-restart prompt from
firing at someone who has nothing to update. Only the rendering goes.
The build_mismatch direction, where the user does have something to do,
is untouched.
2026-08-13 23:01:34 -07:00
Saoud Rizwan 63e9c99031 fix(cli): stop streaming markdown from flashing raw text on every chunk (#13248)
Render assistant markdown with internalBlockMode="top-level" so each
top-level markdown block gets its own renderable. The default coalesced
mode merged the entire message into one block that was rebuilt and
re-highlighted on every streamed chunk, flashing settled headings and
links back to raw uncolored markdown (visible ###, unconcealed syntax)
until the async tree-sitter highlight landed, and re-wrapping rows so
the transcript jumped vertically.

Top-level blocks are reused by token identity, so settled content never
re-renders; only the trailing unstable block updates per chunk. Pass
tableOptions style=grid to keep the bordered table rendering coalesced
mode used by default.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-13 22:57:35 -07:00
Bee afab68f3a3 fix(core): defer replacing a Hub that is serving live sessions (#13231)
* fix(core): stop concurrent Hub installs from retiring each other

Two Cline installations on different builds would shut each other's Hub
daemon down in a loop, and every session died with an abnormal socket
close (code=1006) as its daemon was killed mid-handshake.

The retire decision was a one-sided predicate: each client independently
asked "may I reuse this Hub?", and two clients on differing builds both
answered no. #13177 added build-epoch ordering to break the tie, but left
every unordered case - missing epoch, missing build id - retiring as
before, so any pair involving a build from before epochs were embedded
still looped.

Derive the decision from a total order instead. compareHubBuilds orders
two builds by embedded epoch, then core release version, then build id,
and is antisymmetric by construction, so at most one side of a pair can
ever decide to retire. A Hub that is newer or cannot be ordered is
attached over the compatible wire protocol and left to the build-mismatch
watcher to prompt about. Genuine protocol incompatibility still replaces.

Identity is now read from the same fields on both sides. Filling in a
coreVersion locally that the wire record omits made a build's identity
depend on which role it was playing, and the two directions of a pair were
then decided by different tiers with both concluding they were newer -
a second, independent way to produce the loop.

Also:
- Scope the development Hub owner by build id, so differing dev builds run
  their own daemon side by side instead of contending for one record.
  Production keeps its singleton.
- Break the circuit after repeated retirements of the same URL, bounding
  any future ordering bug to a stale-build prompt rather than an
  unusable Hub.
- Report `cline doctor fix` honestly: separate processes that survived a
  kill from ones that appeared while the fix ran, name the live parent
  respawning a daemon, and mark a startup lock held by a running process
  as held rather than leaked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(cli): only blame a live parent for processes seen during doctor fix

The advice printed under "started during fix" asserted that every such
process was respawned by a live parent, and told the user to go stop it. A
process can also start on its own mid-repair - someone opening a new
session - and then the instruction points at an unrelated process, or at
none at all.

Derive the wording from whether a live parent actually exists: name it
when every process has one, state the facts when none do, and split the
list when it is mixed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(core): order the builds in the stale-discovery hub server case

The case stubbed two build ids and expected the second to replace the
first, but supplied nothing that says which came first: no epochs, and both
servers report the same core version. Ordering therefore fell to the
build-id tiebreak, where "new-build" sorts before "old-build" and the
replacement was judged the older of the two.

Give the case the epochs its name implies, and add the missing sibling for
an unorderable pair, which is attached to rather than retired - the
behavior that keeps two installations from shutting each other down.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(core): defer replacing a Hub that is serving live sessions

Retiring a Hub kills its established WebSockets, so replacing one under a
running session ends that turn with an abnormal close (code=1006). The
replacement is correct - the newer build should own the Hub - but the
timing is not the user's to absorb mid-turn.

Defer instead while the Hub reports live sessions: the newer client
attaches to the older Hub over the compatible wire protocol, and the swap
happens once those sessions end. Attaching rather than spawning matters -
a second daemon would race the busy one for the port.

Deferring silently would be worse than the interruption it avoids, because
a long-lived session pins the Hub to old code indefinitely with nothing to
show for it. The build-mismatch watcher only ever prompted in the
direction where updating the client resolves the mismatch; its own comment
notes that older Hubs "are retired and replaced automatically, so
prompting would only flash a stale dialog", which stops being true once
replacement can be deferred.

Add the missing direction as `outdated_hub`, reported only when a mismatch
survives consecutive checks - an idle older Hub is replaced within moments
of being seen, so a single sighting would flash exactly the stale dialog
the original comment warns about. The CLI and desktop dialogs render it as
information rather than an update prompt: nothing to install, the Hub
swaps itself when the sessions end.

The direction is decided by compareHubBuilds rather than reusability,
because a Hub that is newer and one that carries too little metadata to
order are both "reusable" but need opposite advice.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(core): key the outdated-Hub check by daemon instance, not build

The consecutive-sighting check that keeps a routine replacement from
flashing an informational dialog was keyed by build id. Two daemons from
the same build share one, so an outdated Hub replaced by another daemon of
the same older build satisfied the check and reported exactly the churn the
check exists to hide.

Carry a hubInstanceId on the mismatch event - the Hub's own id, falling
back to pid and start time - and key the pending sighting by it. A
replacement instance now restarts the count instead of confirming it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(core): source Hub instance identity from the discovery record

The instance id added in the previous commit was read from the probe
response, but the watcher probes without an auth token and `/health`
deliberately reports only build and address fields - no hubId, pid, or
startedAt. So the id was always undefined in production and the check it
guards still conflated two daemons of the same build. The test missed it by
injecting a hubId into a mocked probe, a shape `/health` never returns.

Take identity from the discovery record instead, which every daemon version
writes with all three fields and which a replacement daemon rewrites as its
own. The probe is still preferred when it does carry an id, since that is
the process just spoken to.

The tests now use the real `/health` payload shape and vary identity through
the discovery record, including the pid-and-start-time fallback for records
written before Hubs carried an id.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(core): confirm the Hub record still describes the daemon just probed

Instance identity is read from discovery before the probe and build data
comes back after it, so a daemon replaced between those two steps was
described with its predecessor's identity - the replacement then satisfied
the prior daemon's pending sighting and emitted the notification the
consecutive-instance check exists to suppress.

Re-read discovery after the probe and report nothing when the record no
longer describes the same daemon. A Hub mid-swap is churn; the next check
sees whatever it settles into.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* revert(core): drop the watcher instance-identity hardening

Reverts the three follow-up commits that keyed the outdated-hub
consecutive-sighting check by daemon instance (42a83beae, 931431371,
9d634f7b3). They guarded one scenario - a different daemon of the same
outdated build swapping in between two watcher ticks - where the only
consequence is an informational dialog showing one interval early or
late. The unauthenticated probe carries no instance fields in
production, which is why the first attempt needed two more patches; the
original reason+buildId consecutive-sighting suppression from this PR's
base commit already covers the case that matters (not flashing a dialog
for a hub that is mid-replacement).

* fix(core): only count sessions that stopping the hub would actually harm

hasActiveHubSessions treated every non-terminal status as busy. But a
session's hub-side runtime outlives its client: a TUI that is killed or
crashes never stops its session, which then sits in the hub with no
participants and a status that never reaches a terminal state. Under the
defer-while-busy rule that pinned the displaced hub as "serving
sessions" forever - it was never retired, every new CLI kept attaching
to the old build, and the outdated-hub dialog recurred with a promise
("replaced once those sessions end") that could never come true.
Verified empirically: a cleanly detached+disposed client leaves its
session status "running" indefinitely.

Busy now means: someone is attached (participants), or a turn may be
executing hub-side (running/pending, which covers headless and scheduled
runs). An idle session with a confirmed-empty participant list is
resumable persisted state, not live work. Hubs from core < 0.0.75 omit
the participants field entirely, so idle stays conservative (busy)
there - an attached client cannot be ruled out.

updatedAt-freshness was considered and rejected as the discriminator:
the sessions row only updates on status transitions, so a single long
agentic turn looks stale while genuinely executing.

* fix(core): gate hub busyness on attached participants only

Simplifies the busy-check to the one signal that cannot go stale:
participants are live socket subscriptions the hub drops the moment a
client's connection closes, so a crashed client can never leave a ghost
that counts as busy. Session status is deliberately not consulted - a
client killed mid-turn strands its session in a non-terminal status
forever, and QA reproduced that pinning an outdated hub as "serving
sessions" until reboot. This replaces the earlier status+participants
heuristic (and drops the aging bound it was growing) with the rule the
deferred-update design stated from the start: the hub is busy while a
client is connected to a session, and replaceable otherwise.

The accepted cost: a participant-less background run executing at the
exact moment of a hub swap dies with the old hub. Rare, and its next
scheduled tick runs normally on the replacement.

* fix(cli): tell the truth about when the outdated Hub is replaced

The outdated-hub dialog and toast said the Hub is replaced "once those
sessions end". It is not: nothing retires a hub except a fresh launch
running the ensure path, so a user who quits the busy session and
watches sees the old hub stay put and concludes something is stuck
(observed in hands-on QA). Say what actually happens - the newer build
takes over the next time Cline starts after those sessions end.

* fix(cli): speak to users, not architecture, in the pending-update notice

"Cline Hub is running an older build" assumes the reader knows what the
Hub is and why builds differ. The user-relevant facts are only: your
update is not fully active yet, your work is safe, and it finishes by
itself. Say exactly that, in both the TUI and desktop dialogs and the
toast, with the version tucked in parentheses for bug reports.

* fix(cli): drop the outdated-hub dialog for a single quiet toast

The dialog interrupted the user to say that nothing is wrong and no
action is needed - the ideal number of modals for that message is zero.
The TUI now shows one info toast ("Update finishes the next time Cline
starts. No action needed.") and the desktop app shows nothing for the
outdated_hub reason; both dialog components return to their shipped
update-and-restart form, which still appears for the build_mismatch
direction where the user genuinely has something to do. The watcher
keeps reporting outdated_hub - surfaces decide, core informs.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-13 19:46:55 -07:00
Saoud Rizwan d3d3bd8749 fix(cli): defer auto-update install until no CLI is attached to the hub (#13233)
* fix(core): bridge protections for updates landing under pre-3.0.55 clients

Three pieces, each proven against real released artifacts:

- postinstall shield: CLI versions <= 3.0.54 restart the hub daemon after a
  background auto-update even while it serves live sessions, and their
  fingerprint check then rejects every replacement hub, bricking the running
  TUI. That code is on users' machines and cannot be patched — but it runs
  only after the install completes, and it bails out harmlessly when no hub
  discovery record exists. The newly installed package's postinstall sets
  the record aside so the old updater never fires.
- superseded-record fallback: the set-aside record is also the only source
  of the auth token and pid the next new-build launch needs to retire the
  displaced hub (a port probe carries neither); ensure reads it back.
- bind retry: a hub retired on the fixed port can hold it ~2s after acking
  shutdown (watchdog force-exit); the replacement daemon retries EADDRINUSE
  for up to 5s instead of dying and leaving no hub at all.

* fix(cli): defer auto-update install until no CLI is attached to the hub

Installing while cline processes run swaps the npm package under them:
their respawn paths break on the new build fingerprint, and the updater
then restarted the hub daemon out from under live sessions (the 'Hub
connection closed (code=1006)' incident). Guarding the restart treats the
symptom; the fix is to never install under a running process.

The startup check now only records that an update is available. The
install runs at process exit, and only when the hub confirms no other
cli* client is attached — desktop sidecars and connectors ship their own
binaries, so only cli* clients make the swap unsafe. With nothing old
running at install time, no hub restart is needed at all: the next launch
retires the stale hub through the existing ensure path. Deletes
restartHubServerIfRunning, ensureCliHubServerAfterUpdate, and their
support code; manual 'cline update' still installs immediately and now
just notes that the update applies on next start.

* fix(cli): apply deferred update from the entrypoint exit sequence

The CLI entrypoint always terminates with an explicit process.exit(),
which never emits beforeExit — the hook the deferred installer waited on,
so it would never have run (caught by review). Invoke applyDeferredUpdate
directly from the entrypoint's exit sequence after disposeAll(), where
every normal termination passes; crash paths deliberately skip it. Also
clear the pending update once an install spawns so the apply is
idempotent.

* test(cli): isolate unit tests from the real ~/.cline

A full vitest run could leave a real hub daemon running against the
developer's actual ~/.cline discovery record (observed while validating
this PR: a daemon spawned from the globally installed cline binary,
attached to the real data dir). Point CLINE_DIR, CLINE_DATA_DIR, and
CLINE_HUB_DISCOVERY_PATH at a per-worker temp dir and disable auto-update
before any test file loads; subprocesses inherit the isolation via env.

* fix(core): discard the superseded discovery record once consumed

The set-aside record is one-shot recovery metadata, but nothing deleted
it, and it feeds a pid into retireDiscoveredHub's SIGTERM. Weeks later a
launch that finds no live record (routine after any retirement) could
read the stale file and signal whatever process the OS recycled that pid
onto (review finding by @abeatrix). Unlink it at every ensure resolution
that ends with a live, verified hub; failure paths keep it for the next
attempt.

* fix(cli): harden the exit-time update gate

Three review findings on the deferred-apply path:

- A wedged hub could stall an otherwise-finished CLI for tens of seconds
  via the hub client's default timeouts; the whole exit-time query is now
  bounded to 3s, with timeout counting as attached (never install unless
  the hub positively confirms).
- Sub-second commands exited before the startup version check resolved
  and silently dropped the update every time for one-shot-only usage;
  exit now grants the in-flight check a 250ms grace.
- client.list can lose a TUI's registration during transport churn while
  its session connection survives, so an empty client list is not proof
  of safety; cross-check sessions with participants. Participants rather
  than session status: finished sessions linger idle forever and must
  not pin updates, and participant-less scheduled runs live in the hub
  process, which the binary swap does not touch. Verified live: a
  session-holding client invisible to client.list defers the install,
  and the gate opens once it disconnects.

* docs(cli): fix stale beforeExit reference in the exit-gate comment

* style(cli): apply biome formatting to update deferral code

* fix(cli): let doctor see a hub whose record the update shield set aside

During the shielded update window the discovery record is renamed to
.superseded so pre-3.0.55 updaters cannot restart a busy hub. Doctor
read only the primary record, so in that window it reported the live
daemon - the one serving the user's still-open old session - as a stale
hub daemon and advised 'cline doctor fix', which kills it and reproduces
the exact 1006 incident the shield exists to prevent (found by QA).
Doctor now falls back to the set-aside record the same way the ensure
path does, and doctor fix clears the set-aside file along with the
primary record so a deliberate reset does not leave stale retirement
metadata pointing at a recyclable pid.

* fix(core): keep shielded sessions on one Hub authority (#13244)

* fix(core): recover shielded busy hub discovery

* chore(core): instrument shielded hub recovery

* fix(core): recover shielded hubs with attached clients

* fix(cli): recognize shielded hubs in doctor

* refactor(core): keep shield recovery minimal

* fix(core): retain shared Hub idle helper semantics

* chore(core): align busyness helper with the #13231 wording

The participants-only hasActiveHubSessions here duplicates the change on
bee/hub-lifecycle (this branch needs its semantics for the participant
gate). Matching that version byte for byte lets the two merges resolve
cleanly instead of conflicting. Also restores the module-registry reset
comment this branch dropped - it documents a real local-vs-CI gotcha.
2026-08-13 19:39:44 -07:00
Bee afab86dcbd fix(core): stop concurrent Hub installs from retiring each other (#13230)
* fix(core): stop concurrent Hub installs from retiring each other

Two Cline installations on different builds would shut each other's Hub
daemon down in a loop, and every session died with an abnormal socket
close (code=1006) as its daemon was killed mid-handshake.

The retire decision was a one-sided predicate: each client independently
asked "may I reuse this Hub?", and two clients on differing builds both
answered no. #13177 added build-epoch ordering to break the tie, but left
every unordered case - missing epoch, missing build id - retiring as
before, so any pair involving a build from before epochs were embedded
still looped.

Derive the decision from a total order instead. compareHubBuilds orders
two builds by embedded epoch, then core release version, then build id,
and is antisymmetric by construction, so at most one side of a pair can
ever decide to retire. A Hub that is newer or cannot be ordered is
attached over the compatible wire protocol and left to the build-mismatch
watcher to prompt about. Genuine protocol incompatibility still replaces.

Identity is now read from the same fields on both sides. Filling in a
coreVersion locally that the wire record omits made a build's identity
depend on which role it was playing, and the two directions of a pair were
then decided by different tiers with both concluding they were newer -
a second, independent way to produce the loop.

Also:
- Scope the development Hub owner by build id, so differing dev builds run
  their own daemon side by side instead of contending for one record.
  Production keeps its singleton.
- Break the circuit after repeated retirements of the same URL, bounding
  any future ordering bug to a stale-build prompt rather than an
  unusable Hub.
- Report `cline doctor fix` honestly: separate processes that survived a
  kill from ones that appeared while the fix ran, name the live parent
  respawning a daemon, and mark a startup lock held by a running process
  as held rather than leaked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(cli): only blame a live parent for processes seen during doctor fix

The advice printed under "started during fix" asserted that every such
process was respawned by a live parent, and told the user to go stop it. A
process can also start on its own mid-repair - someone opening a new
session - and then the instruction points at an unrelated process, or at
none at all.

Derive the wording from whether a live parent actually exists: name it
when every process has one, state the facts when none do, and split the
list when it is mixed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(core): order the builds in the stale-discovery hub server case

The case stubbed two build ids and expected the second to replace the
first, but supplied nothing that says which came first: no epochs, and both
servers report the same core version. Ordering therefore fell to the
build-id tiebreak, where "new-build" sorts before "old-build" and the
replacement was judged the older of the two.

Give the case the epochs its name implies, and add the missing sibling for
an unorderable pair, which is attached to rather than retired - the
behavior that keeps two installations from shutting each other down.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-13 19:39:18 -07:00
Bee 6d7e745fb7 feat(core, llms): add provider-aware web search tools (#13075)
* feat(core, llms): Cline custom provider & web search

* fix(llms): preserve reasoning model token parameter

* fix(llms): keep ClinePass provider options on the wire in the shared Cline provider

The shared Cline provider hardcoded the AI SDK provider name to "cline",
but the openai-compatible model reads request-body passthrough options from
providerOptions[<name>]. Option routing emits ClinePass options under the
"cline-pass"/"clinePass" buckets, so gateway reasoning (extended thinking
budgets) silently stopped reaching the wire for cline-pass after it moved
off the generic openai-compatible module.

Thread the gateway provider id through as the provider name, and restore
strictJsonSchema: false for the new "cline" provider-options target so the
wire format matches the previous openai-compatible behavior. Add cline-pass
coverage at both the option-routing and request-body levels.

* feat(sdk): persist provider-executed tool activity (#13077)

* feat(core, llms): Cline custom provider & web search

* fix(llms): preserve reasoning model token parameter

* feat(sdk): persist provider-executed tool activity

* fix(vscode): restore state proto and settings section reverted by merge

The merge of origin/bee/websearch into this branch resolved conflicts by
keeping this branch's pre-#13126 copies of apps/vscode files, which
deleted the auto_approve_all_toggled = 174 proto field (without reserving
the number) and dropped a formatting line in FeatureSettingsSection.tsx.
Neither file is in scope for this PR. Restore both to main's content so
the proto source matches the checked-in generated code again.

* chore(vscode): match main byte-for-byte in FeatureSettingsSection.tsx

The pre-commit biome hook strips a blank line that exists on main, which
kept this out-of-scope file in the PR diff. Commit the exact main content
with --no-verify so the PR no longer touches apps/vscode at all.

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>

* refactor(llms): key ClinePass provider options to the shared cline bucket

Both Cline gateway ids (cline and cline-pass) are served by the same
shared "cline" AI SDK provider and hit the same Cline API, so threading
the gateway provider id through as the AI SDK provider name (78dc6f3e7)
was unnecessary indirection. Revert the name threading and instead
normalize option-routing bucket keys: buildProviderAndAliasPatch now
keys both Cline gateway ids to the shared "cline" providerOptions
bucket, which is the only bucket the openai-compatible model reads for
request-body passthrough.

Also tighten the regression coverage that motivated the original fix:
the previous effort-based test rows were vacuously satisfied through the
portable-reasoning early return (effort reasoning never reaches provider
option buckets by design). The rows now use explicit reasoning budgets,
which do flow through the gateway bucket path, and the wire-level test
composes real provider options end to end instead of hand-feeding
buckets.

* revert(llms): drop the cline strictJsonSchema special case in generic-compatible

Restores buildCompatibleProviderOptions to its pre-78dc6f3e7 state. The
strictJsonSchema passthrough is verified inert for the gateway (nothing
in @cline/llms sets a response format), so keeping a hardcoded provider
target in the generic helper bought nothing. If structured outputs are
ever added, strictness for the cline target can be decided deliberately
then.

* fix(llms): claim native web search for openai-native, not the openai alias

supportsModelTool listed "openai", but that id aliases to
openai-compatible (PROVIDER_ID_ALIASES), whose module has no native web
search. The actual native OpenAI builtin id is "openai-native", which is
served by the OpenAI Responses module that does implement
buildModelTools with provider.tools.webSearch(). Without this, the
web_search tool was never offered to native OpenAI users, and was
wrongly offered for the compatible alias.

* refactor(llms): declare model tools in provider manifests

* feat(sdk): project provider tool activity in session history

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-13 18:12:10 -07:00
abeatrix 1cb61ab925 Merge remote-tracking branch 'origin/main' into bee/agent-voice
# Conflicts:
#	apps/examples/desktop-app/package.json
#	apps/examples/desktop-app/sidecar/commands.ts
#	apps/examples/desktop-app/webview/app/globals.css
#	apps/examples/desktop-app/webview/app/page.tsx
#	apps/examples/desktop-app/webview/components/agent-header.tsx
#	apps/examples/desktop-app/webview/components/agent-sidebar.tsx
#	apps/examples/desktop-app/webview/components/views/chat/chat-input-bar.tsx
#	apps/examples/desktop-app/webview/components/views/chat/chat-messages.test.tsx
#	apps/examples/desktop-app/webview/components/views/chat/chat-messages.tsx
#	apps/examples/desktop-app/webview/components/views/chat/welcome-chat.test.tsx
#	apps/examples/desktop-app/webview/components/views/chat/welcome-chat.tsx
#	apps/examples/desktop-app/webview/components/views/chat/workspace-selector.tsx
#	apps/examples/desktop-app/webview/components/views/settings/provider-list-view.tsx
#	apps/examples/desktop-app/webview/components/views/settings/settings-view.tsx
#	apps/examples/desktop-app/webview/hooks/use-chat-session.test.tsx
#	apps/examples/desktop-app/webview/hooks/use-chat-session.ts
#	apps/examples/desktop-app/webview/lib/desktop-tray.test.ts
#	apps/examples/desktop-app/webview/lib/desktop-tray.ts
#	apps/examples/desktop-app/webview/lib/session-history.ts
#	bun.lock
#	sdk/packages/llms/package.json
#	sdk/packages/llms/src/catalog/catalog.generated.ts
#	sdk/packages/llms/src/providers/providers.generated.ts
#	sdk/packages/shared/src/llms/ai-sdk-format.ts
#	sdk/packages/ui/package.json
2026-08-13 15:54:16 -07:00
John Choi 7bf495878e fix(desktop): harden cloud session lifecycle 2026-08-13 15:52:04 -07:00
Tomás Barreiro 677a5cd915 Merge branch 'main' into add-integrations-onboarding-step 2026-08-13 19:05:59 -03:00
Bee fcd5a9e0fb feat(desktop): add app font size bootstrap script (#13232)
* feat: add app font size bootstrap script

- Import and inject APP_FONT_SIZE_BOOTSTRAP_SCRIPT in root layout
- Call syncAppFontSize on app initialization
- Add aria attributes (describedby, label, labelledby, valuetext) to Slider component
- Replace thumb key generation with useId hook for better stability
- Add settings view tests for font size functionality

* feat(desktop): add native zoom menu shortcuts
2026-08-13 14:08:09 -07:00
Tomás Barreiro 4524e884a7 Merge branch 'main' into add-integrations-onboarding-step 2026-08-13 15:42:32 -03:00
BarreiroT 75d1d6654b validate domain and fix errors on auth 2026-08-13 14:56:45 -03:00
BarreiroT 45027ee4e3 Add a GitHub integration step to the onboarding 2026-08-13 14:33:14 -03:00
John Choi 7f8fd0b62d fix(desktop): harden cloud session synchronization 2026-08-13 08:16:53 -07:00
John Choi 6df53ddf64 Merge origin/main into desktop cloud sessions 2026-08-13 08:15:59 -07:00
Saoud Rizwan c8afb44368 chore(vscode): prepare 4.1.9 release 2026-08-13 00:08:09 -07:00
Saoud Rizwan d30cce4cf1 chore(cli): release v3.0.54 2026-08-12 23:13:29 -07:00
Saoud Rizwan 3f39c46026 chore(sdk): release v0.0.74 2026-08-12 22:45:26 -07:00
Saoud Rizwan 274ad3bdb2 chore(desktop): release v0.0.12 2026-08-12 22:37:06 -07:00
Saoud Rizwan e6b1c3fbc8 chore(ui): bump @cline/ui to 0.2.0-next.4
Picks up the shared button primitives (#13164), the one-row-per-tool-call
chat rendering (#13186), the refined session chat layout (#13205), and the
@pierre/diffs hunk renderer (#13201) that landed since 0.2.0-next.3.
2026-08-12 20:40:03 -07:00
Bee 5b22490d41 fix(desktop): filter scheduled Core sessions (#13213) 2026-08-12 18:18:09 -07:00
Saoud Rizwan d03e88e50b Render desktop diff view hunks with the shared @pierre/diffs renderer (#13201)
* Render desktop diff view hunks with shared @pierre/diffs renderer

Replace DiffView's hand-rolled DiffHunk +/- line rows with ToolFileDiff
from @cline/ui (backed by @pierre/diffs), matching the chat tool rows.
Hunks carrying complete new contents (created files) render with real
line numbers; fragment hunks hide them, mirroring ToolCallRow. All of
DiffView's chrome (collapse, copy, open-in-editor, counts) is unchanged.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Make ToolFileDiff syntax palette follow the app theme, not browser preference

@pierre/diffs declares 'color-scheme: light dark' on its shadow :host, so
its light-dark() token colors resolve from the browser's preferred scheme.
Apps themed by the .dark class (desktop app) got the light palette's
near-black text on dark surfaces. Inline colorScheme: inherit on the host
wins over the :host rule and follows the app's color-scheme, which the
@cline/ui theme already flips with .dark. Skipped when a caller pins an
explicit themeType.

Also key diff-view hunks by index so repeated same-shaped hunks (a file
created twice with identical contents) don't collide.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-12 18:06:44 -07:00
Sufiyan Khan 02a1bfd0a8 fix(webview): use editor foreground for diff block text colors (#13200) 2026-08-13 09:41:52 +09:00
Saoud Rizwan 4559f12c66 feat(desktop): temporarily disable welcome prompt suggestions and center input (#13170)
Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-12 14:59:03 -07:00
Saoud Rizwan 6d6f79f948 Fix Claude Code provider: anchor session on workspace, load user settings, allow edits (#13152)
The Claude Code provider was unusable for agentic work (#13146):
- The claude-code manifest lacked the provider-tools capability, so the
  gateway sent Cline's tool definitions (which the provider drops as
  unbridgeable) while the CLI's native tools stayed enabled with no
  approval plumbing - every write was refused and no prompt appeared.
- ai-sdk-provider-claude-code defaults settingSources to [], so the
  spawned session read neither ~/.claude/settings.json nor project
  settings, silently ignoring user-configured permission rules.
- No cwd was passed, so the session inherited the extension host's
  cwd (/ on macOS) and refused writes outside it.

Changes:
- Mark claude-code with provider-tools (same treatment as the Codex
  CLI provider): stop sending unbridgeable external tools and let the
  CLI execute its own, tagged executionMode=provider for the runtime.
- Forward the session workspace cwd from @cline/core into the
  claude-code gateway provider options and lift it into the agent
  session settings.
- Default settingSources to [user, project] and permissionMode to
  acceptEdits (file edits under cwd auto-approved; command execution
  stays gated by the user's own Claude settings), all overridable via
  explicit defaultSettings.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-12 14:51:37 -07:00
Saoud Rizwan cde49170db fix(desktop): first turn of a fresh session no longer wedges the composer (#13122)
* fix(desktop): don't let a stale queued send response wedge the composer

A fresh session is still busy while its interactive loop starts, so the
sidecar coerces the first send onto the pending-prompt queue and replies
{queued:true} with a queue snapshot taken at enqueue time. The turn itself
runs via the runtime's queue drain and completes through stream events
(chat_queued_prompt_start -> deltas -> chat_done). On cold/slow sidecars the
RPC response lands only after those events; the webview then applied the
stale snapshot and unconditionally set status back to "running", leaving
the composer on "Agent is working..." forever and resurrecting a phantom
queue entry.

Webview: capture the turn epoch at send dispatch; chat_queued_prompt_start
bumps it, so a mismatch when the queued response arrives means the stream
already advanced the turn lifecycle and the response is ignored. Aborts now
resolve the queued branch to "cancelled" like the direct path.

Sidecar: the queued send response no longer routes its enqueue-time snapshot
through applyPendingPrompts, which overwrote the event-maintained
session.promptsInQueue and rebroadcast the stale list to every webview.

Includes deterministic regression tests for the stale-response orderings
plus temporary [P0DBG] debug instrumentation (region-marked, to be removed
after runtime verification).

* fix(desktop): ignore stale hub 'running' status after turn settles

The sidecar core is hub-attached, so chat_session_status events are
asynchronous projections of the hub's session record. A stale 'running'
can trail the stream's chat_done and flip a settled turn back to busy,
wedging the composer on 'Agent is working…' with nothing left to
reconcile. Track the epoch at which the turn settled and drop 'running'
status events until a new turn bumps the epoch.

* chore: remove stray QA screenshot artifacts from repo root

* chore(desktop): remove P0 debug instrumentation and fault injection

Strips all [P0DBG] logging, the /p0dbg sidecar route, the webview log
mirror + heartbeat, and the P0DBG_STARTUP_BUSY_MS /
P0DBG_DELAY_QUEUED_RESPONSE_MS fault-injection paths used to reproduce
the stuck-composer P0. The two real fixes (stale queued-response epoch
guard + stale-running-after-settle guard in the webview, and the
sidecar's non-clobbering queued-send snapshot) and the regression tests
remain.

* refactor(desktop): replace turn-epoch guards with an explicit turn lifecycle

The stuck-composer fixes left the hook with two hand-rolled epoch refs
(turnEpochRef / turnSettledEpochRef) mutated and compared inline across
eight call sites. Extract the rules into a pure TurnLifecycle module that
is now the only writer of the session status:

- a settled turn cannot be reopened: stale hub 'running' projections and
  stale queued-send acknowledgements are dropped by the lifecycle instead
  of by inline epoch comparisons
- async work (send RPC responses, queue reconciliation) captures an opaque
  token and the lifecycle decides whether the world moved on, instead of
  handlers comparing counters
- every status write goes through a named operation (begin, turnStarted,
  settle, projectStatus, apply, reset), so the state machine is explicit
  and unit-testable in isolation

No behavior change: the 5 wedge regression tests and the full hook suite
pass unchanged, plus 10 new unit tests for the lifecycle module itself.

* Revert "refactor(desktop): replace turn-epoch guards with an explicit turn lifecycle"

This reverts commit c480aaabe8.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-08-12 14:50:39 -07:00
Haley Park e703f7af2a style(desktop): refine session chat layout (#13205)
* style(ui): refine chat message surfaces and actions

* feat(desktop): refine session transcript layout

* style(desktop): refine conversation composer

* style(ui): format chat theme changes
2026-08-12 14:38:50 -07:00
Saoud Rizwan 105d357b12 fix(vscode): stop legacy-task migration backlog telemetry spam (#13185)
* fix(vscode): stop legacy-migration backlog telemetry spam, emit real migration outcomes

* refactor(vscode): slim migration telemetry fix to minimal surface

* fix(vscode): emit legacy migration outcome only after seeded session start settles

The completed event fired at in-memory conversion time, before the
seeded session start persisted the migration, so a start/persistence
failure was misreported as a successful migration and never produced an
error outcome. Conversion now records a pending migration; the followup
and compaction coordinators settle it after the session start resolves
(completed) or rejects (error/session_start_failed).

* fix(vscode): surface seeded-persistence failures in migration outcomes

LocalRuntimeHost.startSession deliberately swallows seeded-message
persistence failures (the in-memory session still works), so a resolved
start was not proof the legacy conversion became durable. The start
result now reports seededMessagesPersistence, and the resume/compaction
coordinators settle the migration from that result: completed only when
the seed write succeeded, error/seed_persistence_failed when the start
resolved but the write failed, error/session_start_failed when the
start rejected. durationMs now spans conversion through settlement.

Adds the core boundary test forcing persistSessionMessages to fail and
asserting the start still resolves with the failure visible on the
result, plus coordinator tests for both failure modes.

* refactor(vscode): drop per-task migration outcome events, keep volume fixes only

Scope the PR down to the zero-behavioral-risk telemetry fixes, per
review: keep the backlog event transition gating and the one-line
migratedSdkTaskCount fix (counting resumed legacy sessions via their
legacyTask metadata), and revert the per-task terminal outcome
plumbing (pending-migration settlement, coordinator hooks, and the
core StartSessionResult.seededMessagesPersistence field) along with
the success->completed outcome rename on the now-uncalled
captureLegacyTaskMigration. The per-task outcome events can land
separately on the observable persistence boundary.
2026-08-12 14:22:28 -07:00
Sufiyan Khan 274e0c574f Fix silently repaired truncated tool-call JSON (#13015)
* fix(llms): reject truncated tool-call JSON with unterminated strings

* fix(llms): scope truncation guard to jsonrepair only and handle single quotes

* fix(shared): keep jsonrepair ahead of bare-object repair for typed literals

Restores main's precedence for inputs both strategies can handle:
{"flag": True} must repair to a typed true, not the string "True".
The truncation guard now gates only the jsonrepair step, which is the
only strategy that can invent a string terminator.

---------

Co-authored-by: Mikołaj Kondratek <19799111+mkondratek@users.noreply.github.com>
2026-08-12 22:32:03 +02:00
Saoud Rizwan 98d883bf6e fix(llms): replace all-empty-text messages with placeholder content (#13204)
A message whose content array held only empty text parts slipped past the
existing empty-content guards in formatMessagesForAiSdk (which cover
content: "" and content: []). The AI SDK then strips empty text parts,
producing {"role":"user","content":[]} on the wire, which strict
providers reject — seen in prod as Vercel 400s for kimi-k3:
"user message must have content".
2026-08-12 13:15:44 -07:00
Saoud Rizwan 6ff6a1ecbb fix(telemetry): emit per-request deltas in task.tokens on SDK surfaces (#13188)
* fix(telemetry): emit disjoint per-request token buckets in task.tokens

SDK usage events follow the AI SDK convention where inputTokens is the
full request input including cache reads/writes. task.tokens forwarded
that value as tokensIn while also reporting cacheReadTokens and
cacheWriteTokens, so every event re-counted the whole (mostly cached)
conversation context and per-task token sums inflated ~5x on
cache-heavy sessions relative to the legacy contract (tokensIn =
uncached input only, disjoint buckets).

task.tokens now subtracts the cache buckets from tokensIn at the
capture site (mirroring the webview's normalizeUsageEvent), defaults
the cache buckets to 0 instead of undefined, and stamps the provider
attribute for parity with the legacy event schema. Event and attribute
names are unchanged.

* fix(core): normalize registered ApiHandler usage to cache-inclusive inputTokens

Review follow-up: two producer contracts shared AgentUsage.inputTokens.
Native AI SDK usage reports the full cache-inclusive prompt size, but the
ApiHandler adapter forwarded classic disjoint chunk.inputTokens unchanged,
so the task.tokens cache subtraction would zero out real uncached input
for a cache-reporting registered handler.

Normalize at the adapter boundary (inputTokens + cacheReadTokens +
cacheWriteTokens) so every producer entering AgentUsage satisfies the
same cache-inclusive invariant, document that invariant on
AgentTokenUsage.inputTokens, and reframe the telemetry clamp as a
defensive guard rather than a supported producer shape. Adds an adapter
normalization test and a boundary test from an ApiStreamUsageChunk
through task.tokens asserting the disjoint buckets round-trip.

* Revert "fix(core): normalize registered ApiHandler usage to cache-inclusive inputTokens"

This reverts commit 9a9aff374a.
2026-08-12 12:53:50 -07:00
Saoud Rizwan 0f8d715dc7 fix(telemetry): report involuntary Cline logouts from the SDK auth service (#13183)
* fix(telemetry): report involuntary Cline logouts from the SDK auth service

The SDK auth service cleared credentials silently when a refresh token was
rejected (invalid grant), both mid-session and during startup restore, so
user.auth_logged_out never captured involuntary logouts on the next bundle.
Emit token_invalid at both credential-clearing sites and restore_error when
startup restore throws, matching the reason vocabulary the legacy bundle now
uses so the same warehouse query measures involuntary logouts across rollout
variants. Startup with no stored session still emits nothing.

* refactor(telemetry): trim logout-reason parity change to the minimum

* fix(telemetry): report Cline invalid-grant logouts as token_invalid in the SDK resolver

getValidClineCredentials is the single owner of the involuntary-logout
event for the Cline provider; normalize its reason to the legacy
extension's LogoutReason vocabulary (token_invalid) so warehouse queries
cover both bundles. The raw OAuth code stays in errorCode. Codex/OCA
paths keep emitting invalid_grant and are unaffected.

* fix(telemetry): let the SDK resolver own token_invalid; keep restore_error for real restore failures

Address review on the SDK-adapter half of the logout-reason split:
- drop both adapter-side token_invalid emissions - the SDK resolver
  already emits user.auth_logged_out on the same telemetry instance, so
  the adapter was double-counting the exact signal being measured
- transient failures refreshing the stored session on startup (resolver
  throws: network/timeout/5xx) no longer book as restore_error; stored
  credentials are kept and the SDK books auth_refresh_soft_failure, so
  an offline startup is not a logout
- single-source LogoutReason in services/auth/types.ts and re-export it
  from the SDK auth service instead of maintaining two parallel enums
- boundary test runs the real getValidClineCredentials and asserts
  exactly one auth_logged_out (reason=token_invalid) total, so a
  reintroduced adapter emission fails the suite
2026-08-12 12:52:01 -07:00
Saoud Rizwan 3d460d7add feat(hub): directional Hub upgrades with update-and-restart prompts in CLI and desktop (#13177)
* feat(hub): prompt update and restart when another install replaces the shared Hub

* feat(hub): make managed Hub build-watch interval configurable via CLINE_HUB_BUILD_WATCH_INTERVAL_MS

* feat(hub): reuse newer managed Hub builds instead of retiring them

Embed a build epoch alongside the deterministic runtime fingerprint so
managed-Hub compatibility can order builds in time. When fingerprints
differ, a Hub produced after the client's own build is attached over the
compatible wire protocol (and the build-mismatch watcher prompts the user
to update) instead of being retired, so concurrent installations converge
on the newest build rather than replacing each other's daemons. Older,
unordered, or metadata-less Hubs are retired and replaced as before.

* refactor(hub): simplify mismatch status derivation and dedupe sidecar event encoding

* fix(cli): only watch for managed Hub build mismatches in hub-attached sessions

Yolo and sandbox sessions force the local backend and never attach to the
shared managed Hub, so a newer Hub owned by another installation must not
interrupt them with the blocking update dialog.

* fix(desktop): stage an app update before hub-mismatch restart

'Update and restart' previously invoked restart_to_apply_update directly,
which only relaunches the current bundle. With no update staged by the
background 2h updater loop, the app came back on the same version, hit the
same newer Hub, and re-prompted immediately.

Add a check_for_update_now Tauri command that runs one updater
check/download/stage cycle on demand and reports the resulting status. The
dialog now stages the update first and restarts only when the updater
reports 'ready'; otherwise it stays open and explains that no update is
downloadable yet (or that the check failed) instead of restarting into the
same version. Addresses the outstanding Greptile P1 on the dialog.

* fix(desktop): reset the no-update hint when a new hub mismatch arrives

Without this, a dialog for a fresh mismatch reopened pre-set to 'Try again'
with the previous prompt's stale hint.

* fix(desktop): serialize updater cycles so overlapping checks cannot clobber a staged update

The periodic update loop and the on-demand check_for_update_now command
run the same check/download/stage cycle against shared state. Without
exclusion, two overlapping cycles could download the same bundle
concurrently, and the later one could overwrite a freshly staged "ready"
status with "idle" or "error" decided from its stale pre-await
ready_version snapshot - making the update dialog deny that a staged
update exists. A tokio::sync::Mutex now serializes whole cycles; the
ready_version snapshot is read under the lock, so it stays authoritative
for the cycle that took it.
2026-08-12 12:33:27 -07:00
Bee 24f66a4673 fix(core): harden Cline Hub daemon lifecycle (#13168)
* fix(core): harden Hub daemon lifecycle

* fix(core): wait for Hub listener before replacement

* fix(core): recover after Hub cleanup errors

* fix(core): assign the close memo handle before socket termination re-enters beginClose

On every shutdown with a connected client, the daemon logged
'unhandledRejection: AggregateError: hub server close failed' and exited
with code 1 instead of 0. Root cause: beginClose() terminated the
tracked WebSockets before assigning closeHandle. terminate() fires close
events whose microtask continuations advance the daemon coordinator's
deferred cleanup into server.beginClose() while the first invocation is
still mid-body, so the memo guard passes twice and a second set of
wss.close()/server.close() calls runs against the already-closing server,
rejecting with 'Server is not running' and spuriously failing the close
aggregate. The rejection then rode the daemon's unhandledRejection
fatal path and escalated the exit code.

Construct the close promises and assign the memo handle first, and only
then terminate sockets and run detach handlers; a re-entrant call now
hits the memo guard. Also observe the /shutdown handler's
fire-and-forget closeServer() so a genuine close failure is reported
solely by the owner's own await on the same memoized promise instead of
the unhandledRejection path.

Verified with a real daemon: shutdown with zero clients stays graceful
(exit 0, ~26ms); shutdown with a held-open authenticated WebSocket now
exits 0 with no unhandled rejection, still bounded by the 2s coordinator
deadline for the genuine Bun listener-close stall, with the discovery
record cleaned. Hub suites (228) and the shutdown e2e (5) pass.

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-12 12:33:27 -07:00
Saoud Rizwan 354c80df7b fix(llms): update AI SDK deps so streamed tool calls with non-zero indexes don't crash (hasFinished) (#13123)
* fix(llms): update AI SDK deps to fix streamed tool calls with non-zero indexes

LiteLLM's Anthropic passthrough emits chat-completions tool_call deltas
whose index mirrors the Anthropic content-block index (1 when a text
block precedes the tool call; see BerriAI/litellm#11580).
@ai-sdk/provider-utils 5.0.18 stored streamed tool calls in a sparse
array keyed by that index and crashed at stream flush with
"Cannot read properties of undefined (reading 'hasFinished')",
aborting the agent turn. Upstream fixed this in provider-utils 5.0.21
("Fix streamed tool calls with non-zero, non-contiguous, reused, or
missing indexes.").

Update the ai / @ai-sdk packages so every chat-completions streaming
path resolves @ai-sdk/provider-utils 5.0.25, and drop the root
">=4.0.0" override on @ai-sdk/provider-utils: with intersect semantics
it pinned the workspace to the already-locked 5.0.18 even after parents
began requiring 5.0.25, and it force-upgraded dify-ai-provider two
majors past its declared ^3 range. Each package now resolves the
version line it declares.

Fixes #13119

* test(llms): pin non-zero streamed tool_call index regression (#13119)

Wire-level regression test: an openai-compatible SSE stream whose only
tool_call delta carries index 1 (Anthropic content-block numbering via
LiteLLM) must complete and emit the tool-call part instead of throwing
at flush.

* fix: address review findings from merge-conflict resolution

- Restore apps/vscode/proto/cline/state.proto to main's version: the
  merge commit's pre-commit hook regenerated it with a stale generator,
  deleting auto_approve_all_toggled = 174 and moving a reserved line,
  creating drift against the checked-in descriptor. The deletion was
  never intended.
- Restore FeatureSettingsSection.tsx to main's version (the same hook
  reformatted main's file during the merge).
- Regenerate bun.lock narrowly from main's lockfile without --force so
  the diff contains only the @ai-sdk family and its direct transitives;
  drop the spurious webview-ui-scoped @radix-ui duplicate entries the
  previous install introduced (hoisted resolutions still satisfy
  webview-ui's unchanged ranges; verified with --frozen-lockfile).
- Align @ai-sdk/provider to ^4.0.7 in @cline/llms to match the rest of
  the AI SDK family and avoid parallel provider resolutions.

Revalidated: wire repro streams to finishReason=tool-calls, @cline/llms
suite passes incl. the index-1 regression test, all workspaces
typecheck, SDK builds clean.

* fix: restore FeatureSettingsSection.tsx to main's formatting

The branch's pre-commit biome hook (--semicolons=as-needed, --write
--staged) strips a blank line from this file whenever it is staged,
which is how the unintended diff appeared in the merge commit. Commit
with --no-verify to keep the file byte-identical to main; this PR does
not touch the VS Code webview.
2026-08-12 11:30:42 -07:00
John Choi 8437a01906 fix(hub): correlate run start acknowledgments (#13054) 2026-08-12 11:26:16 -07:00
Haley Park 986f0b010b feat(ui): add shared button primitives (#13164)
* feat(ui): add shared button primitives

* fix(ui): disable composed button links

* fix(ui): block disabled composed capture handlers

* fix(ui): protect composed disabled semantics
2026-08-12 10:57:12 -07:00
Haley Park 1be2d20349 refactor(desktop): extract chat message components to messages/ (#13155)
* refactor(desktop): extract chat transcript logic to messages/

Verbatim moves out of chat-messages.tsx (2,415 -> ~1,300 lines), with no behavior changes.

- Extract shared constants, grouping and reasoning helpers, tool summaries, and tool icons into messages/.
- Add unit tests for the extracted pure logic.
- Update test:chat-ui to include tests under messages/.

chat-messages.test.tsx remains unchanged and continues to pass.

* refactor(desktop): extract chat message components to messages/

Moves MessageBubble, ReasoningBlock, ToolMessageBlock, ToolApprovalPanel
(+ formatApprovalTimestamp and the ToolApprovalRequestItem type), and the
image lightbox out of chat-messages.tsx into their own modules under
messages/. Memo wrappers, comparators, and prop contracts are unchanged;
chat-messages.tsx keeps only the ChatMessages orchestration (~780 lines).
chat-messages.test.tsx is untouched and still passes.

* refactor(desktop): extract chat transcript logic to messages/

Verbatim moves out of chat-messages.tsx (2,415 -> ~1,300 lines), with no behavior changes.

- Extract shared constants, grouping and reasoning helpers, tool summaries, and tool icons into messages/.
- Add unit tests for the extracted pure logic.
- Update test:chat-ui to include tests under messages/.

chat-messages.test.tsx remains unchanged and continues to pass.

* refactor(desktop): extract chat message components to messages/

Moves MessageBubble, ReasoningBlock, ToolMessageBlock, ToolApprovalPanel
(+ formatApprovalTimestamp and the ToolApprovalRequestItem type), and the
image lightbox out of chat-messages.tsx into their own modules under
messages/. Memo wrappers, comparators, and prop contracts are unchanged;
chat-messages.tsx keeps only the ChatMessages orchestration (~780 lines).
chat-messages.test.tsx is untouched and still passes.

* refactor(desktop): extract chat message components to messages/

Moves MessageBubble, ReasoningBlock, ToolMessageBlock, ToolApprovalPanel
(+ formatApprovalTimestamp and the ToolApprovalRequestItem type), and the
image lightbox out of chat-messages.tsx into their own modules under
messages/. Memo wrappers, comparators, and prop contracts are unchanged;
chat-messages.tsx keeps only the ChatMessages orchestration (~780 lines).
chat-messages.test.tsx is untouched and still passes.
2026-08-12 10:39:17 -07:00
John Choi 243b6fe9d9 Merge remote-tracking branch 'origin/main' into work/pr-13069-four-fixes
# Conflicts:
#	apps/examples/desktop-app/webview/app/page.tsx
#	apps/examples/desktop-app/webview/components/views/chat/chat-input-bar.test.tsx
#	apps/examples/desktop-app/webview/components/views/chat/chat-input-bar.tsx
#	apps/examples/desktop-app/webview/components/views/chat/chat-messages.tsx
#	apps/examples/desktop-app/webview/components/views/chat/welcome-chat.tsx
#	apps/examples/desktop-app/webview/components/views/chat/welcome-workspace-controls.test.tsx
#	apps/examples/desktop-app/webview/components/views/chat/welcome-workspace-controls.tsx
#	apps/examples/desktop-app/webview/hooks/use-chat-session.test.tsx
#	apps/examples/desktop-app/webview/lib/workspace-paths.ts
2026-08-12 09:11:57 -07:00
Saoud Rizwan a56af4efaf fix(telemetry): stop mirroring per-token stream deltas into telemetry (#13180)
* fix(telemetry): stop mirroring per-token stream deltas into telemetry

Gate assistant-text-delta, assistant-reasoning-delta, and tool-updated
runtime events out of the unconditional telemetry.capture mirror in
AgentRuntime.emit. These fire once per streamed token or tool progress
chunk and accounted for ~97% of all agent.* telemetry volume in the
field with no analytical value. Listeners, hooks.onEvent, and the
run-failed sdk.error reporting are unchanged; the gate is a static
Set lookup so no per-event allocation is added.

* refactor(telemetry): inline stream-delta telemetry gate as a switch

Replace the module-level Set constant with case labels directly at the
capture site; same behavior, less indirection.
2026-08-12 18:20:47 +09:00
Saoud Rizwan 10e5176ed8 refactor(ui): one row per tool call, terminal-style commands, and review fixes (#13186)
* feat(ui): styled label parts, terminal-style commands, and patch fidelity fixes

Label segments: ToolSummary gains labelParts ({text, code?}[]) so
consumers can render code-ish segments (file names, commands, queries,
URLs) in a monospace face. Single commands now read like a terminal
prompt — '$ bun test' — and an untruncated single command no longer
duplicates itself as a detail line.

Review fixes folded in:
- apply_patch preserves hunk boundaries: per-hunk oldText/newText on
  ApplyPatchFile and file items (re-diffing concatenated hunks let a
  deletion in one hunk pair with an addition in another), plus action
  metadata — Delete File labels as 'Deleted x' with no phantom diff,
  '*** Move to:' renames display as 'old → new'.
- run_commands accepts every RunCommandsInputUnionSchema shape (single
  entry, bare arrays, top-level {command,args}, {cmd}).
- makeUnifiedDiff treats empty text as zero lines, so creating an empty
  file or deleting all content no longer reports a phantom +1.
- parseWebFetchInput drops non-string urls instead of stringifying
  objects into labels.
- hoisted a double normalizeValue in the unknown-tool fallback.

* refactor(desktop): render each tool call as its own chat row

Drops the consecutive-call grouping ('Read 3 files · Ran 2 commands')
in favor of one row per tool call — each with its own icon, status,
disclosure, and treatment per kind:

- commands read like a terminal: '$ bun run test' in monospace, with
  the captured output in a capped scrollable mono block on expand and
  '$ '-prefixed detail lines for multi-command calls
- edit rows carry mono filenames, the +/- badge, and their pierre
  diffs pre-expanded (one diff per hunk for multi-hunk patches),
  keeping the user-toggle override from the grouped implementation
- reads/searches/fetches keep inline specifics with mono code segments
  via the shared labelParts

Also fixes the test:chat-ui exit-1 regression flagged in review:
@pierre/diffs' custom element calls CSSStyleSheet.replaceSync, which
jsdom lacks — a prototype polyfill in the suite keeps the real
component in the test tree (and the pre-expand assertions meaningful)
while letting the run exit 0. This suite gates ui-publish.yml.

* fix(desktop): keep the thinking indicator up during quiet turn stretches

The indicator only covered the gap right after a user message, so the
turn looked frozen while the model composed its next step — most
noticeably while streaming tool-call arguments, when neither text nor
a tool row is on screen. It now shows whenever the turn is running and
nothing else is visibly active (no streaming text, no in-progress tool
row, no pending approval/question).

* feat(ui): action-first tool labels

Every row leads with the plain action phrase — 'Ran command',
'Read file', 'Edited file', 'Created file', 'Deleted file' — with the
specifics (command, file name, line range) following as a monospace
segment. The mono segment renders at full size; the previous 0.92em
downscale made it look smaller than the surrounding prose.

* fix(desktop): chat polish — indicator alignment, action spacing, no expanded fade

- The Thinking indicator now mirrors the tool-row trigger metrics
  (min-h-7, py-1, gap-2, 16px icon, font-medium, 8px rhythm) so the
  text no longer shifts when the indicator swaps with an arriving
  tool row.
- The copy/fork/timestamp action row sat 4px up into the message text
  above it (-translate-y-1); it now rests 2px below the message block.
- Expanded reasoning/tool panels rendered at 70% opacity with
  hover-to-unfade; expanded content is what the user is reading, so it
  now renders at full opacity.

* feat(ui): violet active rows, gray finished rows, no green hover

Tool-row colors follow activity: running/pending rows (and the row
spinner) carry the brand violet, finished rows settle into
muted-foreground gray, and hover brightens toward the foreground
instead of hue-shifting to the success green. Errors stay red.

Also: maxInlineChars default raised 60 → 200 so real commands stop
getting truncated (the cap is now only a guard against pathological
payloads; layout handles overflow), and expanded editor rows lead with
the fuller file path above the diff, matching read rows.

* refactor(ui): let layout own label overflow instead of char caps

maxInlineChars now defaults to unlimited — labels carry the full
command/task/question text (whitespace collapsed to one line) and
.cline-chat-tool-label ellipsizes at the container edge via CSS
(nowrap + text-overflow) instead of wrapping. The cap remains as an
opt-in for width-constrained surfaces like TUIs. Since the label can
now be visually cut by layout, single-command rows always carry the
full command in their expanded details.

* fix(ui): drop stale green base color on tool triggers

The redesign moved finished tool rows to muted gray and running rows to
brand violet, but a leftover .cline-chat-tool-trigger { color:
var(--success-text) } rule later in the sheet overrode the gray base, so
every settled row still rendered green.

* fix(desktop): give message actions clear separation from message text

2px below the text read as touching; 6px (translate-y-1.5) gives the
copy/fork/timestamp row visible breathing room.

* feat(ui): spinner replaces the tool icon while a call is in flight

The progress ring used to append to the right of the label, so running
rows sprouted chrome instead of reading as one glyph + label. It now
takes the icon slot and fills the same 1rem box, so the label never
shifts when the icon swaps back in on completion.

* fix(desktop): align thinking indicator with the tool row that replaces it

The indicator sits outside the message column, so it already inherits the
conversation gap; its own mt-2 stacked on top and rendered it 8px lower
than the tool row that swaps in.

* style(desktop): message actions match chat text scale in a lighter gray

Copy/edit/restore/fork icons go from 12-14px to the 16px the rest of the
chat chrome uses, the timestamp moves from 11px to text-sm, and the whole
row renders at 70% muted-foreground so it reads as secondary chrome;
hover still brightens to full foreground.

* style(ui): running tool rows share the thinking indicator's gray

Violet-on-running read as a different system than the muted thinking
state it replaces; the spinner alone now signals activity. The progress
ring draws in currentColor so it stays gray on normal rows and red on
error rows without extra rules.

* style(desktop): nudge message actions down 2px and scale them down a step

Actions row moves from 6px to 8px below the message text; icons go
16px -> 14px and the timestamp text-sm -> text-xs after the previous
bump overshot.

* fix(ui): don't unstick conversation follow when content grows

Stick-to-bottom flipped off whenever a scroll event landed between a
content-height jump (tall diff rows mounting) and the resize observer's
re-pin: the handler read the new distance-from-bottom as the user having
left the bottom. Sticking is now released only by an actual upward
scroll and always restored on reaching the bottom, so the transcript
keeps following while rows stream in.

* feat(ui): user message bubbles on a filled brand-violet surface

The card-colored bubble sat too close to the app background to read at
a glance. New brand-violet-surface tokens (deep enough for near-white
text in both themes) fill the user bubble.

* style(desktop): give the conversation bottom padding above the composer

The last message (and its hover actions hanging below) butted against
the composer border.

* fix(desktop): composer keeps its two-line height when unfocused

Collapsing to one row on blur made the input and the conversation above
it jump on every focus change; the focus-tracking state existed only to
drive that resize.

* refactor(ui): simplify AgentAskQuestion and move it to the brand accent

The 'Follow-up question' heading, intro sentence, and box-in-box nesting
made a one-question prompt read like a form. The question now leads the
card directly (icon + text + option buttons) and the accent shifts from
blue to brand violet, with the section still labelled for assistive
tech.

* fix(desktop): pending questions and approvals render at the end of the transcript

They rendered above the whole conversation like a banner, so a follow-up
question appeared at the top of the chat instead of where the
conversation actually is.

* fix(desktop): keep message actions reachable and make hover/focus feedback instant

The 8px offset under a message was a translated gap — dead space that
dropped the parent's :hover midway to the buttons, hiding them before
they could be clicked. The offset is now padding on the actions element
so the hover chain stays unbroken. Also removes the opacity fade on the
actions row and the composer's focus border transition: both read as lag
rather than polish.
2026-08-11 21:00:04 -07:00
Saoud Rizwan a5611e8f6d feat(ui): shared tool-summary module for consistent tool-call chat rows (#13151)
* feat(ui): add shared tool-summary presentation module

Pure, framework-free tool-call presentation logic under
@cline/ui/components/agent-chat/tool-summary: buildToolSummary and
buildGroupedToolLabel turn raw {toolName, input, result} payloads into
rich row labels (file names with line ranges, inline commands, search
queries, URLs), per-item details, +/- diff counts, per-file unified
diffs (editor old/new text and apply_patch envelopes), team_* labels,
and MCP-aware output text extraction. Merges the desktop app's
buildToolSummary layer with the CLI's tool-parsing/diff utilities so
every @cline/ui consumer renders tool rows consistently.

Exports the new subpath from package.json, extends the packed-tarball
smoke test to cover it, documents the boundary change in ADOPTION.md,
and bumps the package to 0.2.0-next.3.

* refactor(desktop): adopt shared tool-summary for chat tool rows

Replaces ~950 lines of app-local tool extraction (buildToolSummary,
teamSummary, parsers, grouped-label logic) in chat-messages.tsx with
the @cline/ui tool-summary module. Desktop tool rows gain single-call
specifics inline (Read app.tsx (10-80), Ran bun test, Edited util.ts
with +/- badge), line ranges on reads, shortened paths with directory
context in expanded details, per-file unified diffs in the expanded
panel, and grouped labels joined with a middot. Detail keys switch to
index-based to fix duplicate-line key collisions. Icons re-key on the
shared ToolKind classification.

* fix(ui): stop fabricating line positions in fragment tool diffs

Editor str_replace payloads carry old_text/new_text as fragments of the
file, but makeUnifiedDiff treated them as whole files and emitted hunk
headers anchored at line 1, mislocating the change in expanded edit
rows (Greptile P1 on #13151). Fragment diffs now use a neutral
'@@ … @@' separator; only whole-file content (editor create,
apply_patch Add File sections) keeps real hunk positions.

File items also expose the raw oldText/newText (reconstructed from
hunks for apply_patch) plus a fragment flag, so rich diff renderers
can consume the texts directly instead of re-parsing unified output.

* feat(ui): render tool-row edit diffs with @pierre/diffs

Adds @cline/ui/components/agent-chat/tool-diff exporting ToolFileDiff,
a thin wrapper over @pierre/diffs (optional peer dependency) that
renders a tool-summary file item as a syntax-highlighted, theme-aware
unified diff. Fragment diffs hide line numbers instead of showing
misleading ones. The desktop chat renders edit diffs through it, and
tool groups containing an edit diff now open pre-expanded so the diff
is immediately visible.

ADOPTION.md reframes the shared-module story: extracting presentation
logic products would otherwise duplicate is the direction @cline/ui is
headed, with tool-summary and tool-diff as the first two modules. The
packed-tarball smoke test covers the new subpath in both consumers.

* fix(ui): blend tool diffs into the app surface

Two polish fixes to ToolFileDiff from design review:

- Normalize trailing newlines on both sides before diffing so tool
  payload fragments (which rarely end in a newline) don't litter every
  diff with 'No newline at end of file' markers.
- Map @pierre/diffs' background hooks (--diffs-light-bg/--diffs-dark-bg)
  to the host app's --background token (stock white/black fallback),
  so the diff surface and all its color-mixed tints (context lines,
  gutters, separators) derive from the app background instead of
  pierre's pure white/black. Overridable via a new background prop.

Storybook's ToolSummaries story now renders file items through
ToolFileDiff pre-expanded (matching the apps) and adds a multi-file
apply_patch fixture.

* fix(desktop): pre-expand tool groups when edit diffs arrive mid-stream

defaultOpen only applies at mount, but a streaming tool group mounts
with its first (often read) call and gains the edit later, so live runs
never saw the promised pre-expanded diff. Drive the disclosure with
controlled state that opens when a file diff first appears, unless the
user has toggled the row themselves. Covers the streaming path with a
rerender test.
2026-08-11 17:54:52 -07:00
Bee 66883f584c fix(desktop): top-align welcome chat input (#13174)
Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-11 14:41:41 -07:00
Haley Park e370732545 refactor(ui): migrate fonts to Inter and Geist Mono (#13142)
* chore(ui): replace font dependencies

* refactor(ui): migrate shared typography tokens

* refactor(ui): adopt Inter and Geist Mono in apps

* fix(hub): preserve variable font weight tokens

* feat(ui): tune font weights for dark mode

* docs(ui): add font migration screenshots

* (chore)ui: misc typography adjustments

* fix(hub): make dark-mode font-weight overrides take effect

Tailwind's @theme inline bakes literal values into utilities, so the
.dark --font-weight-* overrides were dead code and dark mode rendered
the heavier light-mode weights. Declare the weights in :root instead so
font-* utilities keep their var() references, matching the @cline/ui
tokens approach. Also rewrap --font-mono to satisfy biome format.

* fix(ui): restore light-mode semibold to 640 and pin weight scales in test

The PR intent is a 480/560/640/640 light scale with 400/500/600/600
dark overrides, and the Hub already uses 640; tokens.css had drifted to
600 for light semibold. Regenerate scoped-tokens.css and assert both
the light and dark weight scales in the theme contract test.

* chore(desktop): remove stray double space in provider header class

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-11 14:39:57 -07:00
Haley Park ee4adda2da refactor(desktop): extract chat transcript logic to messages/ (#13153)
Verbatim moves out of chat-messages.tsx (2,415 -> ~1,300 lines), with no behavior changes.

- Extract shared constants, grouping and reasoning helpers, tool summaries, and tool icons into messages/.
- Add unit tests for the extracted pure logic.
- Update test:chat-ui to include tests under messages/.

chat-messages.test.tsx remains unchanged and continues to pass.
2026-08-11 14:33:27 -07:00
Saoud Rizwan 651829b24a chore(cli): release v3.0.53 2026-08-11 11:32:41 -07:00
Saoud Rizwan 00ba2ff7da chore(sdk): release v0.0.73 2026-08-11 11:00:44 -07:00
Mikołaj Kondratek 3f03159737 fix(vscode): don't discard a successfully refreshed Cline token after expiry (#13139)
getAuthToken captured expiresAt before refreshing, then validated the new
token against that stale value. When the old token was already past expiry
(not just inside the 5-minute buffer), a successful refresh was thrown
away and null returned, so the first call after long idle failed despite
valid credentials. Re-read the expiry from the refreshed auth info.
2026-08-11 18:23:12 +02:00
Mikołaj Kondratek 3087bd3d32 fix(hub): recoverable agent errors must not end the turn in the dashboard (#12962)
* fix(hub): don't forward recoverable agent errors to dashboard peers

Recoverable error events are in-run notices, not turn outcomes: the
MistakeTracker emits one for every recorded mistake (e.g. a plan-mode
guard-blocked run_commands call) while the run continues. The hub
dashboard forwarded every error event to peers, so the webview dropped
out of the sending state and appended an error row mid-turn — the same
host bug fixed for VS Code and the CLI in #12953.

Gate the forward on recoverable, matching those hosts: the tool failure
is already shown inline via the failed tool_event, and the turn's
outcome stays decided by how it actually ends (turn_done or a
non-recoverable error). Recoverable errors are logged server-side.

* fix(hub): forward recoverable flag to peers instead of filtering server-side

Per review: the server is a translation layer between agent events and
the webview protocol, so it should not embed display policy or console
logging. Forward every agent error with its recoverable flag on the
peer message and let each peer decide — the webview keeps recoverable
errors out of the transcript and keeps the turn state, matching how the
CLI gates display on the same flag while the information stays
available to any peer that wants it.
2026-08-11 18:11:40 +02:00
Bee 9b59090967 fix(desktop): reconnecting to stale managed Hub daemons (#13145)
* fix(core): replace stale managed hub daemons

* fix(core): fingerprint hub runtime builds

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-11 01:34:00 -07:00
Saoud Rizwan 7e31fb9e0d chore(vscode): prepare 4.1.8 release 2026-08-10 20:03:53 -07:00
John Simone e0eb0167da feat(vscode): add Fable 5 + custom model IDs to Vertex; drop global-region picker filter (#12461)
* add custom model selection to the vertex provider

* fix race conditions from PR review

* fix linter warnings

* fix test failures

* refactor(vscode): drop Vertex global-endpoint picker filtering

The SDK catalog is live (models.dev), so a static host allowlist of
global-endpoint-capable models lags every model launch and silently hides
new models from users on vertexRegion=global. Remove the allowlist, the
host override that injected supportsGlobalEndpoint, and the picker filter;
show the full catalog for every region.

An unsupported pick now fails loudly at request time: map Vertex's
'model not available in region: global' (and Google's Publisher Model
locations/global not-found body) to recovery guidance in the error row.

Also drop Anthropic's universal pricing from the Vertex Fable 5 overlay —
Vertex bills region-dependently, so the copied price understated recorded
cost; the record now carries no pricing instead of a wrong one.

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-10 19:58:20 -07:00
John Choi edd6e2c29b fix(desktop): close cloud session interaction gaps
Forward image attachments, allow session-scoped model changes, recover queued streaming after abort, and surface relayed run failures.
2026-08-10 16:49:03 -07:00
Mikołaj Kondratek d5748b2939 fix: remove stale Double-Check Completion feature tip (#13147)
* fix: remove stale Double-Check Completion feature tip

The rotating feature tips still told users to enable "Double-Check
Completion" in settings, but that toggle was removed in the new UI —
the Features section now offers Auto Compact, Feature Tips, Background
Edit, Checkpoints, Worktrees and Hooks. Following the tip sent users
searching the settings panel for something that isn't there.

Drop the tip. The remaining ten were checked against the current UI and
all still hold, including the "Settings → Features → Feature Tips" path.

* chore: remove dead CLI settings e2e page object and orphaned test

`page-objects/settings.ts` asserted the CLI settings Features tab shows
"Double-check completion" — the same removed setting behind the stale
feature tip. Nothing in the live tui-test suite (apps/cli/src/tests)
imported it; only chat.ts and auth.ts page objects are in use.

Its one importer, apps/vscode/tests/e2e/cli/interactive.test.ts, is a
leftover from the pre-2026-06-02 SDK migration squash: all three of its
imports resolve to files that don't exist, there's no tui-test config in
that tree, and no npm script runs it. It cannot execute.
2026-08-11 00:54:41 +02:00
Mikołaj Kondratek ffd6a6b1db fix: respect user max output tokens in compaction summarizer requests (#13137)
* fix: respect user max output tokens in compaction summarizer requests

The compaction summarizer hardcoded max_tokens to 1024 and the VSCode host
never mirrored the user's Max Output Tokens onto providerConfig, so summary
requests were always capped at 1024 tokens. Reasoning models can spend that
entire budget thinking; the reasoning stream is discarded, so no summary
text arrives and compaction is skipped on every attempt.

- Mirror maxTokensPerTurn onto providerConfig.maxOutputTokens in the VSCode
  session factory so consumers that build handlers straight from it (the
  compaction summarizer) honor the user's setting, matching the CLI.
- Resolve the summarizer output budget from explicit config, then model
  info, then knownModels, before the default; raise the default to 4096.
- Log a diagnostic warning (reasoning chars, incompleteReason, likely
  cause) when the summarizer returns no summary text instead of silently
  skipping.

* fix: clamp summarizer default output budget by model metadata instead of adopting it

Model maxTokens is reported capability, not a product default: without an
explicit configuration the summarizer now requests the 4096 default, lowered
by model metadata when the model reports less, never raised by it. Explicit
values still win as-is.
2026-08-11 00:20:45 +02:00
cline-cloud[bot] 51784a3bf1 docs: add Qwen3.8 Max to ClinePass model list and reference pricing (#13144)
Co-authored-by: Cline <cline@users.noreply.github.com>
2026-08-10 14:52:43 -07:00
Saoud Rizwan 149abb0ddb feat(vscode): remove YOLO mode setting, migrate old users to auto-approve all (#13126)
* feat(vscode): remove YOLO mode setting, migrate old users to auto-approve all

The SDK extension's YOLO toggle was cosmetic: nothing in the approval
path read it, so runs were silently governed by the per-action
auto-approval settings underneath (cline/cline#13114). Instead of
keeping a parallel override system, remove the setting entirely and
make the auto-approve menu the single source of truth:

- drop yoloModeToggled (and the equally dead autoApproveAllToggled)
  from state keys, settings handlers, state posts, telemetry, the
  remote-config yoloModeAllowed transform, and the settings protos
  (field numbers reserved)
- remove the Yolo Mode toggle from Settings -> Features (the whole
  Experimental section, it was the only entry) and the
  "Auto-approve: YOLO" AutoApproveBar takeover
- add a v3 storage migration that folds a previously-enabled YOLO /
  auto-approve-all toggle into autoApprovalSettings by enabling every
  action, so previously-unattended setups keep running unattended;
  the dead keys are cleared from the file store

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* refactor(vscode): keep dead yolo keys in place instead of clearing them

Current builds never read the removed keys (the state loader only visits
known keys), so deleting them buys nothing - and the file store is shared
with older builds that still know them, so clearing would flip YOLO off
for a user who downgrades. Same downgrade-safety rule as the v1 export.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* chore(vscode): rename wasUnattended to shouldEnableAllActions in yolo migration

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* chore(vscode): drop dead toggleActModeForYoloMode and stale yoloModeAllowed comment

The method was a legacy-controller carryover nothing called, and it set
the mode without rebuilding the session, which is wrong for the SDK
architecture. The comment cited yoloModeAllowed as a live remote-config
example; it no longer maps to anything.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* chore(vscode): refresh checked-in proto descriptor_set.pb

The tracked descriptor set had not been regenerated since the repo
move and still advertised long-changed schemas (including the removed
yolo_mode_toggled fields) to gRPC reflection clients. Sync it with the
output of bun run protos.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-09 17:15:37 -07:00
Saoud Rizwan b3cee3f973 chore(desktop): release v0.0.11 2026-08-08 20:53:18 -07:00
Saoud Rizwan c68f553856 chore(vscode): prepare 4.1.7 release 2026-08-08 20:38:09 -07:00
Saoud Rizwan fd794ce3be chore(cli): release v3.0.52 2026-08-08 19:34:11 -07:00
Saoud Rizwan f5f1071af2 chore(sdk): release v0.0.72 2026-08-08 19:00:03 -07:00
Saoud Rizwan 4540390096 desktop: hide git jargon for non-git folders (CLIENTS-100) (#13059) 2026-08-08 15:57:00 -07:00
Saoud Rizwan b590e14b91 desktop: paste clipboard images into the composer (CLIENTS-78) (#13057)
* desktop: paste clipboard images into the composer as attachments (CLIENTS-78)

Pasting a screenshot into the composer did nothing: only drag-and-drop
and the paperclip file picker fed the attachment pipeline. Add an
onPaste handler on the composer textarea that extracts image files from
the clipboard, renames them to timestamped pasted-image-*.png files, and
routes them through the existing onAttachFiles flow. Text pastes are
untouched.

* desktop: only extract clipboard images in formats message serialization supports

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-08 15:56:27 -07:00
Saoud Rizwan 54cc156089 desktop: context-aware welcome suggestions for non-code folders (CLIENTS-98) (#13060)
* desktop: context-aware welcome suggestions for non-code folders (CLIENTS-98)

* desktop: treat pending branch discovery as its own state for welcome cards

The welcome-card classifier read the "no-git" sentinel as a confirmed
non-repo, but page.tsx also used that value for the initial state and
while a workspace switch was awaiting branch discovery, so a git repo
could briefly show the plain-folder cards. Branch state is now null
while discovery is pending: the welcome screen shows no cards until the
folder is classified, and chat-mode cards (which never depend on git
state) still show immediately. Other branch consumers keep the string
contract via a "no-git" fallback.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* desktop: carry nullable branch state to all consumers

Propagate the pending-discovery null through ChatInputBar,
WorkspaceSelector, and the welcome workspace controls instead of
coercing to "no-git" at the page boundary, so only display leaves
fall back and the welcome classifier is the single consumer that
distinguishes pending from confirmed non-repo.

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-08 15:45:29 -07:00
Saoud Rizwan 6c599d18c3 desktop: surface folder picker failures and add manual path fallback (CLIENTS-73) (#13056)
* desktop: never let 'Add project…' fail silently; add manual folder path entry (CLIENTS-73)

- sidecar picker tries zenity then kdialog on Linux and throws a descriptive
  error when neither exists, instead of returning null (indistinguishable
  from user cancel); picked paths are trimmed of trailing separators
- picker failures now surface as visible error messages in both workspace
  selectors, with a manual path-entry fallback (typed absolute or ~ paths
  in the search box offer an 'Open folder' action)
- failed workspace switches (invalid/nonexistent paths) show an inline
  error instead of silently doing nothing
- validate_workspace_directory expands ~ and returns the resolved path

* desktop: keep workspace menu search/error state through catalog refreshes

The welcome-screen workspace picker reset its search text and error
message whenever onRefreshWorkspaces changed identity, which happens on
every session-history poll. Typing a path or reading an inline error
raced against the timer: the menu would silently wipe mid-interaction.
Hold the refresh callback in a ref so the reset only runs when the menu
actually opens.

* desktop: format welcome-workspace-controls test

* desktop: distinguish picker launch failures from user cancellation

A zenity/kdialog rejection with a non-ENOENT spawn error (EACCES, EMFILE,
ENOMEM) or a crash signal was classified as a user cancel, which skipped
the kdialog fallback and suppressed the inline error - recreating the
silent no-op this branch is meant to eliminate. Only a clean exit code 1
from a dialog that actually opened now counts as cancellation; broken
backends fall through to the next candidate and surface a descriptive
error otherwise. Picker logic moved to sidecar/workspace-picker.ts with
an injectable exec so the classification is unit-tested.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Classify picker launch failures separately from user cancellation

zenity/kdialog failures like EACCES, EMFILE, or ENOMEM were treated as
user cancellation, suppressing the kdialog fallback and the inline
manual-entry error. Only a clean exit code 1 now counts as a cancel;
any other failure falls through to the next backend or throws the
picker-unavailable error. Picker logic moved to sidecar/folder-picker.ts
with an injectable exec so the classification is unit tested.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Revert "Classify picker launch failures separately from user cancellation"

This reverts commit 24d27a004d.

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-08 15:43:52 -07:00
Saoud Rizwan 513aacc0e6 fix(core): full-stop semantics and abort-window queue edits for surviving queues (#13100)
* fix(core): preserve queued prompts across user-initiated aborts

Pressing stop while prompts were queued silently destroyed them:
abort() called clearAborted(), which emptied the pending prompt queue
with no way to recover the typed input. The prompts vanished from the
UI, were never sent, and left no trace in session artifacts.

Aborting now only stops the in-flight turn. Queued prompts stay in the
queue and drain once the abort settles, matching the drain behavior
that already existed for self-aborted turns (loop detector / mistake
limit). The thrown-abort path (completeAbortedInteractiveTurn) now
schedules the same drain that runTurn schedules for turns resolving
with an aborted finish.

* fix(core): full-stop semantics and abort-window queue edits for surviving queues

Follow-up to the queued-prompt survival change: aborting a user turn keeps
the queue and auto-runs it, but two gaps remained.

1. No full stop: aborting a queue-initiated turn also kept draining, so
   every Escape consumed one queued prompt and started a fresh provider
   call - a session with queued messages could never be brought to rest.
   Aborting a drained turn now discards the remaining queue: the first
   Escape skips to your queued follow-ups, a second Escape stops the
   queued work too.

2. Queue operations were still rejected while an abort settled: a prompt
   typed right after Escape was silently dropped, and queued prompts were
   briefly uneditable and undeletable even though they were about to
   auto-run. enqueue/update/delete now work during the abort window;
   scheduleDrain/drain still wait for the abort to settle.
2026-08-08 12:37:18 -07:00
Saoud Rizwan ff2f860941 test(core): pin abort + hub-restart durability, and title seeded sessions (#13097)
* test(core): cover abort + host restart + seeded recovery durability

Adds an e2e regression guard for the reported "cancel a turn, lose the
conversation" failure: a cancelled turn, a daemon restart, a
client-side recovery seeded from disk, and a second restart before that
replacement ever runs a turn. Reverting the eager seeded-history
persistence makes the final read come back empty.

Materializing a seeded session at start also left its history row with
no prompt and no title, since there is no first prompt to derive one
from. Seed the title from the inherited transcript using the same
inference listSessionHistory hydration applies, so forks and recoveries
stay identifiable in unhydrated surfaces too.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(core): retitle seeded sessions from their first user prompt

Eagerly-materialized seeded sessions kept the interim transcript-
inferred title forever, a behavior change from pre-eager persistence
where a fork's history row was titled by the first post-fork prompt.

The interim title now only covers the window where no turn has run
(previously those rows were simply absent), and the first user prompt
after the seed backfills the row's prompt and retitles it — unless the
user renamed the session in the meantime, in which case only the prompt
column is backfilled. The resident manifest and session metadata are
updated in step so the end-of-turn usage-metadata merge cannot clobber
the title back through a stale in-memory fallback.

The e2e mock's updateSession now mirrors the real persistence-service
contract (row + manifest file), and the durability e2e covers both the
retitle and the rename guard; removing the retitle call fails the
'now add tests' assertion.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* refactor(core): collapse seeded-session titling to the old mechanism

The interim transcript-derived title, retitle flags, rename comparison,
and resident-manifest syncing existed only to title forks that never
run a turn - a new nicety, not parity. Dropping it collapses the whole
design back to what rows did before eager persistence: the persistence
service derives the title from the prompt when a row gains one, so the
host only needs to backfill the promptless row with the first user
prompt via updateSession. Renames win automatically because the service
preserves an existing title when no explicit title is passed.

Net production change vs main is a single 20-line backfill block in
executeTurn. The e2e mock's updateSession now models the service's
title semantics (explicit title wins, existing title preserved,
untitled rows derive from prompt), and the durability e2e asserts the
raw row stays untitled until first prompt while history hydration
infers a display title from the transcript.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-08 12:30:30 -07:00
Saoud Rizwan 62a6b5a0b2 fix(core): preserve queued prompts across user-initiated aborts (#13090)
Pressing stop while prompts were queued silently destroyed them:
abort() called clearAborted(), which emptied the pending prompt queue
with no way to recover the typed input. The prompts vanished from the
UI, were never sent, and left no trace in session artifacts.

Aborting now only stops the in-flight turn. Queued prompts stay in the
queue and drain once the abort settles, matching the drain behavior
that already existed for self-aborted turns (loop detector / mistake
limit). The thrown-abort path (completeAbortedInteractiveTurn) now
schedules the same drain that runTurn schedules for turns resolving
with an aborted finish.
2026-08-08 12:20:08 -07:00
Saoud Rizwan 0caf617b50 fix(core): keep a hung MCP server from taking down session creation (#13086)
* fix(core): keep a hung MCP server from taking down session creation

A stdio MCP server that never finishes initializing used to hold its
connect open for the full DEFAULT_MCP_CONNECT_TIMEOUT_MS (doubled across
the newline/framed attempts). MCP tool discovery runs on the
session.create critical path, so that wait blew past the 30s hub command
timeout and the CLI tore the whole interactive session down instead of
just skipping the bad server.

- Bound MCP tool loading during session build with a startup budget that
  is safely under the hub command timeout. Servers that connect in time
  contribute their tools; slower/hung servers are skipped for the session
  (their error still surfaces via the MCP manager) instead of failing
  session creation. Budget is overridable via CLINE_MCP_STARTUP_BUDGET_MS
  for tests.
- Add StdioMcpClient.close() (and optional McpServerClient.close) that
  marks the client disposed so an in-flight connect() aborts its retry
  loop instead of respawning the framed fallback.
- Dispose the manager by closing clients up front, outside the per-server
  operation locks, so a server hung in initialize can no longer stall
  teardown for the full connect budget.

Adds regression tests covering both the non-blocking build and prompt
disposal while a client is hung in connect().

* refactor(core): simplify hung-MCP-server fix to a startup budget

Replace the bespoke per-server race/tracking in loadConfiguredMcpTools
with a small withStartupBudget() wrapper around the existing
Promise.allSettled: a server that exceeds the budget becomes a normal
rejection that the existing loop already logs and skips. The connect
budget, MCP settings display (initialize timeout 30s), and the rest of
the loader are left untouched.

The client close()/manager.dispose() cleanup is kept minimal: it is what
lets teardown abort a still-in-flight connect instead of blocking on the
per-server lock (and clears the pending request timer).

* fix(mcp): cap the default initialize budget at 3s to protect session creation

Supersedes the startup-budget approach on this branch with the simple
constant fix.

MCP initialize runs on the session.create critical path, which the hub
caps at 30s, and connect() can spend the budget twice (newline then
Content-Length framing). The 30s default from #13067 meant a server that
never initializes held session.create for up to 60s, so the hub RPC
timed out and the CLI tore the whole session down and exited.

Return to the pre-#13067 shape with a bigger probe: 3s instead of 1.5s.
That still covers the ~2s starters the old probe killed (#13035) and
keeps the worst case at ~6s per server, far under the hub deadline.
Genuinely slow starters (JVM-based servers like Oracle SQLcl) now need
an explicit timeout in cline_mcp_settings.json, which continues to
override the default in either direction.

Tests: update the slow-start regression tests to the new policy (2s
connects by default, 4s connects with a configured timeout), refresh the
displayed initialize-timeout assertions, and add an invariant test that
keeps the doubled default well under HUB_DEFAULT_COMMAND_TIMEOUT_MS so
the budget cannot silently creep past the session deadline again.
2026-08-08 12:18:11 -07:00
Saoud Rizwan 930575991d fix(desktop): stop opening a session from replacing the remembered model (#13091)
* fix(desktop): stop opening a session from replacing the remembered model

The composer's ModelSelector mirrored every provider/model prop change
into the remembered last selection (localStorage), which seeds new
sessions via getInitialChatConfig(). Opening an existing session drives
those props to that session's config, so merely viewing an old session
silently replaced the user's explicitly picked default model.

The remembered selection is now written only from the explicit picker
handlers (provider select and model select). Passive prop changes, such
as opening a session, no longer touch it.

* fix(desktop): re-seed remembered provider/model on chat reset

reset() kept the previous config's provider/model and only cleared the
session ID, so a chat pane that had hydrated a historical session could
carry that session's model into the next chat. Re-seed provider/model
(and apiKey when the provider changes) from the remembered defaults --
the same source a freshly mounted thread uses -- so reset and remount
behave identically.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-08 12:10:39 -07:00
Saoud Rizwan e40d7d44ae fix(desktop): stop treating leftover plugin install dirs as installed (#13095)
* fix(desktop): stop treating leftover plugin install dirs as installed

isOfficialPluginInstalled() only checked that the marketplace install
directory existed. A failed or interrupted install can leave that
directory behind with no plugin inside, and the next install attempt
then short-circuited with a fake 'already installed' success: the
marketplace button flipped to Uninstall with no error while nothing
actually worked, and the installed-entries listing kept reporting the
broken entry as installed.

The check now requires a loadable plugin module inside the directory
(via discoverPluginModulePaths) before reporting the entry as
installed, so partial directories fall through to a real install
attempt whose outcome is surfaced to the UI.

* fix(desktop): reclaim leftover partial plugin install dirs with --force
2026-08-08 12:06:35 -07:00
Saoud Rizwan e973ce4f33 fix(cli): make queued message text readable on light theme TUI (#13098)
Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-08 12:00:50 -07:00
Saoud Rizwan 1eb28e553e test(desktop): make the pagination-recovery test deterministic
Waiting on rendered text could pass in a stale window between the search
clearing and the base reload effect running, letting the scroll fire a
stale observer whose captured request key mismatched. Drop the captured
observer callback before clearing and wait for the effect to recreate it,
which only happens after the post-clear base list applied.
2026-08-08 18:58:56 +00:00
Saoud Rizwan 42225f9219 refactor(desktop): consolidate cloud-session helpers before review
No behavior changes; review-readiness cleanup of the cloud sessions diff:

- one cloudRepositoryLabel helper in webview/lib/cloud-repositories.ts
  replaces four copies of the owner/repo label parser (sidecar placeholder
  title, repository picker, composer context label, provisioning phases)
- the cloud-provisioning- placeholder id prefix moves behind
  isCloudProvisioningSessionId, shared by the sidecar that mints the ids
  and the webview affordance gates that check them
- the two identical cloud status mappers in use-chat-session collapse into
  mapCloudRuntimeStatus in chat-session/helpers.ts
- attach() and attachExpired() share one attachResultPayload builder
  instead of duplicating the reply literal
- settings-view drops the commented-out PostHog lookup block in favor of a
  short pointer comment
- welcome-chat derives its fallback connect URL from the environment
  config instead of hardcoding production
- refresh the stale claim-set comment in create-recovery to describe the
  post-fix wait-all semantics
2026-08-08 18:58:55 +00:00
Saoud Rizwan 4f25692d70 fix(desktop): canonicalize diff panel paths against the session cwd (#13092)
* fix(desktop): canonicalize diff panel paths against the session cwd

Tool calls address the same file inconsistently across a session: one
edit uses a workspace-relative path (journal.txt), a later one the
absolute path (/tmp/ws/journal.txt). mergeToolDiffs keyed entries by the
raw string, so the same file was listed twice in the diff panel with
split +/- counts and inconsistent naming, most visibly after git was
initialized mid-session and the model switched to absolute paths.

Diff paths are now canonicalized against the session cwd before
merging: entries for the same file collapse into one, files inside the
cwd display as workspace-relative paths, and files outside it display
their resolved path. Without a cwd the previous raw-key behavior is
kept.

* style: collapse editorReplaceEvent signature per biome format

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(desktop): collapse dot segments and keep root cwd in diff path keys

* fix(desktop): compare Windows diff path keys case-insensitively

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-08 11:55:58 -07:00
Saoud Rizwan b0bba2e5d6 fix(vscode): hide View Changes on completion rows until there are changes to show (#13096)
* fix(vscode): hide View Changes on completion rows until there are changes to show

The button previously always rendered on the latest completion row, faded
and disabled when the count check came back 0 - which covers both 'nothing
changed since your last message' and 'no checkpoint to compare against'
(non-git workspace, repo with no commits, comparison failure). A dead
button with a misleading tooltip in the non-git case is worse than no
button: now the row renders nothing until the host confirms there are
actual changes, and the button is always enabled when shown.

* fix(vscode): reset View Changes state when showViewChanges toggles

Greptile review: a stale positive hasChanges from a previous evaluation
could flash the button before the host confirms the new comparison when
showViewChanges flips false and back true on the same row. Reset to
'still checking' whenever the effect re-runs.
2026-08-08 11:41:41 -07:00
Saoud Rizwan a6e2c0c431 fix(core): never run a foreign compiled plugin-sandbox bootstrap for a source host (#13094)
* fix(core): never run a foreign compiled plugin-sandbox bootstrap for a source host

When @cline/core runs from source (e.g. the desktop hub daemon in dev)
with CLINE_WRAPPER_PATH set, resolveBootstrap() picked the compiled
plugin-sandbox-bootstrap.js from a separately installed CLI platform
package (such as a published version sitting in the package-manager
cache) before falling back to the source bootstrap. That bootstrap
resolves modules against the other installation's layout, so every
plugin failed to load with "Cannot find module '@cline/core'" - and
the settings pipeline swallowed the failure, leaving Settings > Tools
showing "No plugin tools found" and plugins showing no contributions
even though the same plugins loaded fine in chat sessions.

Bootstrap selection now prefers, in order: a compiled bootstrap next to
this module (always matches the host build), the source bootstrap when
the host runs from source, and only then wrapper/executable-derived
bootstraps - which remain the path for compiled binaries where
import.meta points inside the bunfs bundle.

* chore(core): restore untouched settings-service formatting
2026-08-08 11:23:25 -07:00
Saoud Rizwan da759853ea test(desktop): wait out the post-clear branch reload before paginating again 2026-08-08 05:37:23 +00:00
Saoud Rizwan 6fed0f0d38 style(desktop): format new test fixtures 2026-08-08 05:34:04 +00:00
Saoud Rizwan b456ce73dd fix(desktop): webview polish for cloud sessions from deep review
- humanize cloud error envelopes in the sync-failed banner and the
  rehydration fetch fallback (and scope the fallback to the active session)
- align the recovered-send status mapper with the rehydrated handler:
  cover cancelled, and leave unknown statuses alone instead of flipping a
  running turn to completed
- disable Delete on provisioning placeholders in the sidebar and sessions
  view; the sidecar always rejects it until the create settles
- surface the CLINE_CODE_CLOUD_AGENTS override in Settings when it makes
  the toggle diverge from effective behavior, and load the settings
  sections concurrently
- gate the slash-command menu to local sessions like @-mentions; the
  sandbox cannot resolve local skills/workflows
- stop the model selector from silently 'correcting' a locked cloud
  session's model when its id is missing from the local catalog
2026-08-08 05:32:53 +00:00
Saoud Rizwan 2b9d1c3e6a fix(desktop): harden cloud session lifecycle edges
- reap connections whose session vanished from a successful list (deleted
  remotely or re-scoped): they otherwise redial the dead proxy every ~5s
  forever, with a REST list per attempt, until app restart
- clear desktop-visible state synchronously at the start of dispose() so
  a manager rebuilt mid-dispose (account/credential change) cannot have
  its fresh liveSessions/pendingApprovals entries deleted from under it
- report rehydrated failed runs with the same chat_session_ended reason
  (error) the live run.failed path uses
2026-08-08 05:32:53 +00:00
Saoud Rizwan 82277128aa fix(desktop): only honor Connect GitHub URLs from Cline app origins
The cloud error envelope travels in Error.message and is authenticated by
string prefix only, so error strings a session pod controls (hub command
replies pass through verbatim) could spoof a github_not_connected envelope
whose connectUrl pointed anywhere. The webview rendered that as a trusted
looking Connect GitHub button and open_external_url validates protocol,
not origin. Drop connectUrls whose origin is not a known Cline app base
URL before they reach the action button.
2026-08-08 05:26:59 +00:00
Saoud Rizwan ee4edfeaf6 fix(desktop): keep the cloud setup snapshot fresh across org switches
The stale-selection guard compared repoUrl against a repositoryUrls
snapshot refreshed only on mount, account-id change, focus, or the
onboarding poll (which stops in ready status). An in-app org switch
refreshed none of those, so picking a repository from the new scope's
correctly filtered picker got immediately wiped against the old scope's
list. Route the picker's own loads through the same request-id-guarded
snapshot application, and re-check setup on the sidecar's
cloud_sessions_changed broadcast.
2026-08-08 05:25:00 +00:00
Saoud Rizwan 17b0ad7a76 fix(desktop): close both directions of the create-recovery claim race
Recovery previously waited only for earlier identical peers, so an
earlier create failing fast (any request_failed, including an instant
5xx) could adopt a later in-flight POST's listed session and hand two
composers the same sandbox. Branchless and branch-specific creates also
hashed to different claim keys while the branchless recovery filter
ignores branch, allowing cross-key adoption with no ordering at all.

- key in-flight peers by repo/model/org (branch excluded) so
  branchless recoveries see branch-specific peers
- settle each create's peer entry when its POST settles (never after
  recovery), then make recovery wait for every other in-flight peer in
  both directions, re-snapshotting until stable; waits cannot cycle
- gate recovery on timeout/5xx/no-status failures: a fast 4xx never
  provisioned anything, and recovering on one risks adopting an
  identical-config session created by another device on the account
2026-08-08 05:21:55 +00:00
Saoud Rizwan be8bb302a8 fix(desktop): re-key the first cloud prompt's bubble to the server session id
A cloud create returns a server-assigned session id, but the optimistic
user bubble kept the client-planned id. mergeCloudSnapshotWithLive drops
other-session messages before consulting the optimistic map, so the first
prompt's bubble silently lost its retention semantics: a lagging snapshot
could merge to a transcript with no user prompt, and a failed first send
lost its bubble on the next rehydration.

Also pins the previously untested merge behaviors: the reflected-prompt
budget (zero-budget retention and one-consumption-per-new-copy) and
error-bubble preservation on the unmatched-live drop path.
2026-08-08 05:18:45 +00:00
Saoud Rizwan f4f573c395 fix(desktop): release the branch picker's loading flag when a page fetch goes stale
loadMore reset loadingMore only when the request key still matched. Typing
a search character while a page fetch was in flight changed the key, so
the stale fetch never released the flag and pagination was dead for the
rest of the welcome screen's life (the observer effect and loadMore both
short-circuit on loadingMore). Only one page fetch can be in flight, so
the reset can be unconditional.
2026-08-08 05:16:29 +00:00
Saoud Rizwan e03b4577b4 fix(sdk): close the hub client zombie-connection race around registration
The post-registration continuation was the one mutation window not guarded
by the connect generation: a close() landing after the register reply
resolved but before the continuation ran would mark a closed client
registered. That stale flag then made a later failed registration skip
closing its socket, leaving a permanently unregistered zombie connection
that isConnected() reported healthy.

- generation-guard the continuation so a superseded attempt closes its
  socket and rejects instead of touching shared state
- drop the registered-flag condition from the connect() catch guard; the
  socket identity check alone decides ownership and cannot be poisoned
- keep a stale attempt's late timeout/error/close handlers from clobbering
  lastCloseError and sawSocketClose for a newer attempt
- stop close() from wiping the real connect failure cause when no socket
  was ever opened
2026-08-08 05:15:03 +00:00
Saoud Rizwan 16d36e53f2 Merge branch 'main' into saoudrizwan/desktop-cloud-sessions-9a9b 2026-08-07 21:50:08 -07:00
Saoud Rizwan d011d049a1 fix(core): keep session context durable across aborts and hub restarts (#13078)
* fix(core): keep session context durable across aborts and hub restarts

Users on slow self-hosted endpoints reported sessions losing their entire
conversation after cancelling a long-running request: the TUI still showed
the transcript, but the next turn greeted them like a brand-new session.

Root cause is a stack of two failures:
1. The hub daemon exits on any unhandled rejection that is not an
   AgentRuntimeAbortError, so a floating abort-family rejection from a
   cancelled provider stream kills every resident session.
2. When the CLI recovers the missing session it rebuilds from the persisted
   messages file - but aborting a turn never flushed the transcript, and
   lazy session persistence (SDK 0.0.70) kept seeded history (mode-switch
   restarts, forks, previous recoveries) memory-only until the first
   completed turn. Recovery then seeds an empty session: silent context wipe.

Fixes:
- completeAbortedInteractiveTurn now flushes the transcript to disk, so an
  aborted exchange survives a hub restart.
- Sessions started with initialMessages persist them (and any compaction
  sidecar) immediately; brand-new empty sessions stay lazy, so closing an
  unused runtime still leaves no empty history entry.
- The hub daemon ignores abort-family unhandled rejections (DOMException
  AbortError, Node ABORT_ERR) the same way it already ignores
  AgentRuntimeAbortError, instead of exiting with every session resident.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(core): write seeded history atomically with session materialization

Greptile review flagged a residual crash window in the seeded-session
persistence: ensureSessionPersisted created the session row (with an empty
messages file) and only then called persistSessionMessages, so a crash
between the two left a discoverable session whose seeded history was gone.

Close the window by threading initialMessages/systemPrompt through
createRootSessionWithArtifacts: the messages artifact is now written with
the seeded transcript before the session row is committed, so every crash
point leaves either nothing discoverable or complete data. The follow-up
persistSessionMessages call at session start is gone; the seed travels
inside session materialization.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Revert "fix(core): write seeded history atomically with session materialization"

This reverts commit 5a7e0b37f1.

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 21:44:40 -07:00
Saoud Rizwan e09afced69 fix(core/hub): report queued-turn failures as run.failed (#13074)
Turns drained from the pending-prompt queue resolve their errored
AgentResult inside PendingPromptsController.drain(), which discards it,
and the legacy 'error' agent event had no projection in the hub's
session-event projector — so a failed queued turn never produced any
terminal hub event. Interactive clients (e.g. the desktop app) hung on
'Thinking...' with no error shown.

The projector now publishes run.failed (with the error text and a core
session snapshot) for non-recoverable lead-agent error events, but only
when no RPC-driven turn is awaiting sessionHost.runTurn for that
session — the awaiting run.start handler already publishes the
authoritative terminal event, so this avoids double-reporting a turn
that resolves through both paths.
2026-08-07 20:52:01 -07:00
Saoud Rizwan 74a1910505 Merge branch 'main' into saoudrizwan/desktop-cloud-sessions-9a9b 2026-08-07 20:50:44 -07:00
Saoud Rizwan f3db7a0a98 fix(desktop): order concurrent identical creates so recovery cannot steal an in-flight session
A session is listed the moment the server starts provisioning it, minutes
before its successful POST returns. Timeout recovery now waits for every
earlier identical in-flight create to record its claim before adopting a
listed candidate; later peers wait on earlier ones only, so waits cannot
cycle. Regression test covers the slow-success/fast-failure overlap.
2026-08-08 03:21:07 +00:00
Saoud Rizwan 3f83be51a2 feat(vscode): fade View Changes button until changes since last message are confirmed (#13076) 2026-08-07 20:16:15 -07:00
Saoud Rizwan 2b62f7b447 fix(desktop): webview review fixes for cloud sessions
- Emit cloud_session_provisioning_failed from the sidecar and render a
  terminal error pane in an open placeholder thread instead of an
  infinite provisioning spinner.
- Cloud-aware delete confirmations in the sidebar and sessions view (the
  action destroys the remote workspace, not just local history).
- Humanize cloud rename failures instead of showing the raw envelope.
- Preserve UI error bubbles through cloud rehydration merges; ignore
  unknown snapshot statuses instead of flipping a running turn to done.
- Clear a stale repository selection when the account can no longer
  access it so the send gate re-engages.
- Migrate cloud optimistic bookkeeping across queued-prompt re-keys,
  clear cloud refs on reset, session-scope the cloud merge, fix the
  impure provisioning-phase updater, gate rename on provisioning
  placeholder rows, and stop advertising local-only mentions/commands in
  cloud composer placeholders.
2026-08-08 03:03:15 +00:00
Saoud Rizwan 6b8b5726c3 fix(desktop): cloud session lifecycle hardening from deep review
- Reap connections whose sandbox expired (attach, sidebar poll, and
  reconnect-failure paths) so dead sessions stop reconnect-looping and
  spamming sync-failure events; sync failures now notify on transition
  only.
- Tombstone sessions mid-delete so a concurrent attach/send cannot dial a
  fresh connection that outlives the delete; treat remotely-gone sessions
  (404/410) as deletable locally.
- Guard disposed connections against resurrection by late reconnect timers
  and approval responses; purge approvals stored during failed connection
  setup.
- Leave cloud approvals pending on app shutdown instead of denying tool
  calls on pods that outlive the app.
- Use a fresh auth token (with fallback) for create-timeout recovery;
  normalize list rows so one malformed record cannot crash discovery;
  widen the recovery clock-skew window now that claims prevent
  double-adoption.
- Drop the queue-shrink 'prompt started' inference on the hub path (the
  hub emits explicit submitted events; a shrink can also mean removal).
- Reset the transcript baseline on reconnect; answer pendingPrompts with
  [] for sessions with no inner session instead of throwing.
2026-08-08 02:55:37 +00:00
Saoud Rizwan f6d8e54089 fix(desktop): cross-cutting review fixes for cloud sessions
- Use core's canonical getProviderAuthHandler("cline") for the persisted
  token fallback instead of a hand-rolled prefix heuristic that could
  corrupt unprefixed API keys; drop the dead test-only reset export.
- Reset the cloud session manager and broadcast cloud_sessions_changed
  after a cline OAuth login, and broadcast on the save_provider_settings
  (sign-out) reset, so the sidebar re-scopes immediately.
- Log cloud discovery failures instead of silently emptying the sidebar.
- Atomic write-then-rename for the desktop settings file.
- Share the repository/branch wire types between sidecar and webview.
- Add command-layer tests for the settings/flag commands; refresh the
  stale sidecar ARCHITECTURE.md; delete an orphaned comment.
2026-08-08 02:47:00 +00:00
Saoud Rizwan ef09caa3e6 fix(sdk,desktop): harden hub header resolution and onboarding poll
Review findings: bound resolveConnectionHeaders with the connect timeout so
a hung token refresh cannot pin connect() and every deduped caller forever;
record resolver failures in lastCloseError so getConnectionError() reports
the real cause; add a connect-generation token so close() during header
resolution cannot leave a doomed attempt satisfying the next connect();
stop header-auth clients from inheriting registry tokens for loopback URLs;
use the shared extractSessionId in approval.list_pending. Desktop: make the
onboarding poll read status from a ref instead of running side effects in a
state updater, and re-check GitHub connectivity when the account changes.
2026-08-08 02:42:20 +00:00
Saoud Rizwan 1efe5577e1 fix(core/cli): drain queued prompts after self-aborted turns and surface the stop (#13061)
* fix(core/cli): drain queued prompts after self-aborted turns and surface the stop

When a run ends with finishReason "aborted" without a user abort request
(loop detector hard escalation or the consecutive-mistake safety stop),
runTurn skipped the pending-prompt drain, stranding user-queued messages
forever, and the CLI rendered nothing - the task appeared to silently
stop with queued messages never consumed (#13030).

- core: schedule the drain after every completed turn, including
  aborted/error finishes. User-initiated aborts are unaffected because
  abortSession() already clears the queue, and drain() stops after one
  failed send so an erroring provider cannot spin the queue.
- cli: when a turn comes back aborted without the user having requested
  an abort, append a "Task stopped before completion." status entry
  instead of ending the turn silently.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(core): hold queued prompts on error finishes instead of consuming them

Addresses the Greptile P1 review on #13061: a drained prompt whose turn
resolved with finishReason "error" returned normally, so the
exception-only requeue path treated the send as successful - the failed
prompt was consumed and draining continued firing the remaining queue
into a failing provider.

- drain() now stops the chain when a drained send resolves with an
  error finish. The errored entry itself is not requeued (its turn ran:
  the prompt is in the conversation and the error is surfaced), but the
  rest of the queue is held.
- runTurn() no longer schedules a drain after "error" finishes (the
  skip is removed only for "aborted", which is the #13030 fix).
  Held prompts still drain via the existing enqueue/update/delete
  triggers or the next successful turn.
- Two new unit tests cover both layers.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* revert(cli): drop the 'Task stopped before completion' status line

Keep the change scoped to the queue-drain fix in @cline/core. The CLI
no longer prints a notice for non-user-initiated aborted finishes;
apps/cli is back to parity with main. When messages are queued, the
drain itself makes the stop visible (the queued message runs); richer
stop-reason surfacing can be a follow-up.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 19:27:47 -07:00
Saoud Rizwan bdb5f30f5e refactor(desktop,sdk): remove the PostHog flag plumbing cloud sessions no longer use
Reverts the SDK feature-flags service/provider changes and barrel exports to
main, and strips the desktop sidecar's PostHog-backed flag service (context
targeting, cache file, refresh/dispose lifecycle). isCloudAgentsEnabled() is
now just the env override plus the Settings toggle, and get_feature_flags
answers synchronously.
2026-08-08 01:50:57 +00:00
Saoud Rizwan 2fa0be8940 refactor(desktop,sdk): drop the code-cloud-agents flag from the SDK catalog
Cloud sessions are gated by the explicit Settings toggle now, so the SDK no
longer registers the unused PostHog flag. The Settings row is wrapped in a
visibility gate that is hard-wired on, with the future flag lookup left
commented out until the flag actually exists in PostHog.
2026-08-08 01:21:40 +00:00
Saoud Rizwan 9cbc24d6e5 Restore "View Changes" on completion rows using SDK checkpoints (#13072)
* fix(core): read untracked-at-snapshot files from stash third parent in checkpoint diff

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* feat(vscode): restore View Changes button on completion rows via SDK checkpoint diff

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* refactor(vscode): integrate View Changes as a footer inside the completion card

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* style(vscode): place the View Changes button inside the completion card

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 18:11:25 -07:00
Saoud Rizwan 551286d33b fix(cli): preserve binary MCP payloads in expanded TUI tool output (#13071)
* fix(cli): preserve binary MCP payloads in expanded TUI tool output

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* simplify to minimal payload-preserving fix

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 18:10:28 -07:00
Saoud Rizwan 2e5a565090 fix(desktop): harden queue snapshot validation and recovery claiming
- applyQueueSnapshot now rejects replies without a prompts array instead of
  publishing an authoritative empty queue from the pending/update/remove
  command paths.
- Timeout-recovery candidate selection and claiming now happen in one
  synchronous helper so the claim can never be separated from the check,
  and the regression test exercises truly concurrent create requests.
2026-08-08 00:24:42 +00:00
Saoud Rizwan 361ac90978 fix(llms): route LiteLLM through Chat Completions instead of the Responses API (#13053)
The litellm builtin spec pinned protocol: "openai-responses", so every
request went to POST {baseUrl}/responses. Self-hosted LiteLLM proxies
commonly implement only /chat/completions, so all prompts failed with
404 Not Found on the SDK path (CLI, and now the Next extension bundle).

Drop the override so litellm inherits the openai-compatible family
default (openai-chat -> /chat/completions), matching every sibling
openai-compatible builtin and the Legacy extension behavior.

Fixes #13003, fixes #10781
2026-08-08 02:06:46 +02:00
Saoud Rizwan eb95908737 fix(desktop): only treat valid pending-prompts replies as authoritative queue snapshots
An unsuccessful or malformed session.pending_prompts reply during
rehydration no longer publishes an empty queue or discards buffered queue
events; the newest buffered queue snapshot is replayed instead.
2026-08-08 00:05:44 +00:00
Saoud Rizwan 4eb7402334 fix(cli): render MCP tool result text instead of escaped JSON in TUI (#13066)
* fix(cli): render MCP tool result text instead of escaped JSON in TUI

MCP tools return {content: [{type: "text", text}]} which
extractFullOutputText JSON-stringified, escaping newlines into one giant
line that word-wrapped across the whole terminal and never triggered the
line-based collapse. Extract the text parts with real newlines so the
existing collapse works.

Fixes #13038

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(cli): keep placeholders for non-text blocks in mixed MCP results

Addresses Greptile review on #13066: text-only filtering silently
dropped image/resource/audio blocks from mixed MCP content. Render them
as [type] placeholders instead.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(cli): surface non-text MCP block metadata in TUI output

Extract embedded resource text, and include resource/resource_link URIs
and image/audio mime types in placeholders so expanded mixed MCP
results keep identifying metadata.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 17:05:22 -07:00
Saoud Rizwan ffb61a865f fix(mcp): give unconfigured stdio servers a 30s initialize budget (#13067)
The stdio MCP client gave servers without a configured `timeout` only
1.5 seconds to answer initialize before killing the process, so
slow-starting servers (e.g. Oracle SQLcl's JVM-based `sql -mcp`) could
never load and were silently skipped at session start.

Raise the default connect budget to 30s, in line with the startup
budget other MCP clients allow. A configured `timeout` still overrides
it in either direction, dead commands still fail fast through the spawn
error/exit path, and the newline -> Content-Length framing fallback is
unchanged.

Fixes #13035

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 16:49:28 -07:00
Bee d3616b96ae feat(desktop): route /team prompts through core runtime (#12372)
* feat(desktop): route /team prompts through core runtime

Rewrite desktop `/team` commands as structured user command blocks before sending them to the core runtime. Validate task input and respect the globally disabled Teams tool setting.

Remove legacy agent spawn and team enablement flags from session configuration, and add coverage for prompt rewriting and disabled-tool behavior.

* fix(desktop): preserve team tool defaults

* fix(desktop): display queued /team prompts as their slash form

Queued prompts are stored in their runtime form, so a queued /team
command showed its raw <user_command> envelope in the prompt queue chip
and edit textarea. Fold queue items through formatDisplayUserInput for
display; saving an edit re-resolves the slash form through the sidecar,
so the round trip is lossless.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* chore(hub): align builtin tool catalog flags with the desktop sidecar

The desktop sidecar pins enableSpawnAgent/enableAgentTeams when listing
the builtin tool catalog; the hub's parallel listing did not, so the two
would drift if the preset defaults ever change. Pin the same flags in
the hub and cross-reference the two call sites.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* chore(desktop): drop inert enableSpawn/enableTeams config leftovers

buildCoreSessionConfig no longer reads these keys, so remove the dead
schema fields, default-config initializers, and chat-test payload
entries. The chat-session regression test still sends them on purpose
to prove legacy flags cannot override the runtime's tool presets.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(desktop): reject /team when the mode's tool preset disables teams

The /team guard only checked the global disabled-tools setting, but the
runtime resolves tool availability from the mode's preset, so a preset
without team tools (yolo) would still send the model a spawn-a-team
instruction it cannot act on. Resolve the teams catalog entry for the
session's mode and reject /team when it is unavailable, mirroring the
runtime's own availability logic.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 16:45:49 -07:00
Saoud Rizwan b091c72e40 fix(desktop): address cloud-session review findings
- Keep the newest buffered queue snapshot when rehydration's queue fetch
  fails instead of silently dropping queued/steered prompts (Greptile P1).
- Claim recovered/created session ids per process so overlapping identical
  create requests cannot adopt the same record and orphan a sandbox
  (Greptile P1).
- Use crypto.randomUUID() for provisioning placeholder ids (CodeQL
  insecure-randomness alerts).
2026-08-07 23:44:05 +00:00
Bee 98e5458b09 feat(hub): centralize plugin settings and contributions (#12942)
* fix(desktop): plugin package names

* feat(hub): centralize plugin settings and contributions

* fix(hub): address plugin settings review feedback

* fix(settings): make plugin snapshots host-aware

* fix(core): make host plugin toggles atomic

---------

Co-authored-by: cline-cloud[bot] <cline-cloud[bot]@users.noreply.github.com>
Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-07 16:44:02 -07:00
Saoud Rizwan 031b8d94e1 fix(core): surface OAuth authorization for SSE MCP servers on 401 (#13050)
* fix(core): surface OAuth authorization for SSE MCP servers on 401

A 401 from an SSE MCP server never persisted authorizationRequired: the
fetch-boundary UnauthorizedError was consumed by EventSource and re-thrown
as a status-less SseError, so the instanceof check routed it to
markConnectionError and hosts never offered the OAuth connect action.

Give the SSE stream request a raw fetch so a 401 fails the connection with
the SDK's typed SseError(401), and recognize 401s across transports with a
single isMcpUnauthorizedError predicate at every detection site.

* style(core): apply biome formatting to MCP oauth changes
2026-08-07 16:42:43 -07:00
Saoud Rizwan e5bcba8ef9 fix(vscode): settle the turn phase when a mode switch aborts a running turn (#13063)
Toggling Plan/Act while a turn was streaming or waiting on a tool approval
aborted the turn but left the TurnStateTracker on its last live phase: the
aborted session's done event is fenced off as stale once the rebuild
unsubscribes it, so nothing ever settled the phase. The webview then kept
rendering that phase forever - an eternal Thinking spinner with the input
disabled (aborted while streaming), or dead Approve/Run Command buttons wired
to an approval that clearPending had already denied (aborted while awaiting
approval). Users experienced this as 'switched to act mode and nothing
happened / it never wrote the files'.

Mirror cancelTask: after aborting the turn for the mode change, append a
resume_task ask row and set the phase to resumable, so the footer offers
Resume Task with the input enabled in the new mode.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 16:41:13 -07:00
Saoud Rizwan ebf5b52e9b Merge origin/main into saoudrizwan/desktop-cloud-sessions-9a9b
Resolves conflicts with #13028 (native-feel polish and render-path
performance): keep dynamic view imports and the memoized headerDiff from
main while preserving the cloud-session behaviors from this branch (Cloud
icon import, Connect GitHub error-action button in the chat error banner,
and hiding the diff header for cloud sessions).
2026-08-07 23:36:29 +00:00
Saoud Rizwan 83182c0d96 fix(llms): retry mid-stream network interruptions before any model output (#13052)
* fix(llms): retry mid-stream network interruptions before any model output

* fix(llms): scale network retry backoff by network retry count, not shared attempt number
2026-08-07 16:36:27 -07:00
Saoud Rizwan 40ebd09dfa desktop: native-feel polish, render-path performance, and transition fixes (#13028)
* desktop: native-feel polish and render-path performance fixes

- Suppress the WebView browser context menu on app chrome (keep it for
  editable fields and active text selections)
- Make UI chrome unselectable app-wide; opt chat messages, markdown,
  code, diffs, and error banners back into text selection
- Contain overscroll so inner scrollers don't rubber-band the window
- Lazy-load Settings/Sessions/Onboarding/Diff views out of the entry chunk
- Memoize ChatInputBar and AgentHeader; stabilize their props in the chat
  pane so stream flushes only re-render the affected message bubble
- Stop refocusing the composer textarea on every keystroke (caret flicker)
- Cache slash commands across menu opens (stale-while-revalidate)
- Avoid rebuilding reversed message arrays and ask-question JSX per render
- Drop core info/debug console logging on the streaming hot path behind a
  cline:debug-logs opt-in; remove leftover [webview:delete] debug logs
- SearchCombobox (provider/model picker): Escape closes and restores focus
- Remove unused @vercel/analytics, recharts, embla-carousel deps and the
  unused chart/carousel UI components

* desktop: surface failed-turn errors instead of leaving the chat blank

On a failed run the runtime reports its error string in result.text.
The webview rendered that as an assistant bubble, which the canonical
history rehydration then wiped (the failed turn is never persisted),
so provider errors like a retired model id left the user staring at a
silently empty chat. Route failed-turn text to a persistent error-role
message added after rehydration instead.

* desktop: fade the welcome/conversation swap instead of hard-cutting

Sending the first message replaced the hero layout with the message
grid in a single commit, which read as a white flash. A 180ms enter
animation now plays when either side becomes visible; disabled under
prefers-reduced-motion.

* desktop: render new-chat panes instantly from the last catalog load

Clicking + remounts ChatThreadPane, which refused to render until the
provider catalog (a large fetch) and workspace list resolved again —
about a second of blank pane plus boot spinner on every new chat.
Seed remounts from a module-level snapshot of the last successful
load; the mount effect still refreshes both in the background.

* desktop: invalidate the provider-catalog snapshot with the cache

Seeding remounted chat panes from the last catalog load left a window
where a pane created right after a credential change could act on the
old keys. The snapshot now lives in the catalog module and is dropped
by invalidateProviderCatalogCache(), so credential edits force the
next remount to wait for fresh data.
2026-08-07 16:18:47 -07:00
Saoud Rizwan 7bc18f7e15 Bring back a copy button on turn-final response rows with a subtle header (#13051)
* Add subtle response header with copy button to completion and plan rows

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Add changeset for response header copy button

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Rename turn-final headers to Completed and Plan

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 16:12:43 -07:00
Bee fad8006730 feat(hub): add execution context for scheduled run reports (#12718)
* feat(hub): add execution context for scheduled run reports

Add human-readable headers, schedule metadata, durations, and lifecycle error context to cron run reports. Resolve file-based definitions to real paths while clearly identifying Hub-managed schedules stored in cron.db.

* fix cron report formatting edge cases

* Escape schedule titles in reports

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-07 15:57:33 -07:00
Saoud Rizwan 28f35a2ec8 fix(cli): harden tool input/output formatters against malformed payloads (#13048)
* fix(cli): harden tool input/output formatters against malformed payloads

Tool inputs cross the model/tool boundary and may not match their
TypeScript annotations (e.g. run_commands with { command: null }).
truncate() called str.replace() on such values, crashing the TUI with
'.replace is not a function' and making persisted sessions containing
the payload non-resumable, since hydration replays the same input
through formatToolInput().

Normalize untrusted values at the formatting boundary: truncate() now
accepts unknown and safely stringifies null/undefined/objects (including
circular structures and throwing toJSON), formatStructuredCommand no
longer returns non-string commands verbatim, and fetch_web_content
request summaries tolerate malformed entries.

Fixes #13036

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(cli): keep valid empty-string args in structured command summaries

Greptile review: filtering normalized args by truthiness also dropped
genuine empty-string argv entries, so summaries could show a different
argument list than the one executed. Filter only nullish entries before
normalization instead.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 15:53:01 -07:00
Saoud Rizwan 13d801b578 fix(desktop): allow renaming cloud sessions from the sessions view
Rename was already supported by the sidecar and offered in the sidebar and
chat header; the sessions view context menu was the odd one out. Includes
biome format fixes picked up in touched files.
2026-08-07 22:52:44 +00:00
Saoud Rizwan 642c2f643b feat(desktop): cloud sessions onboarding panel for GitHub connect flow
When the cloud composer cannot start a session yet (signed out, GitHub not
connected, or the GitHub App has no repository access) replace the composer
with an onboarding panel that explains cloud sessions, walks through the
dashboard hand-off with visual steps, and auto-detects completion via polling
and window-focus refetches. Adds a teaching hint under the ready composer.
2026-08-07 22:52:44 +00:00
Saoud Rizwan 528c6b8ff2 feat(desktop): gate cloud sessions behind an explicit settings toggle
Cloud sessions are in preview, so replace the remote rollout flag with an
opt-in toggle in Settings -> General, persisted in a desktop-owned settings
file (kept out of global-settings.json so older CLI writers cannot strip it).
The CLINE_CODE_CLOUD_AGENTS env override still wins for development. Toggling
broadcasts feature_flags_changed so open composers react without a restart.
2026-08-07 22:52:36 +00:00
Saoud Rizwan 1e24807d1a fix(vscode): fall back to session cwd or Desktop for @-mention file search in empty windows (#12982)
* fix(vscode): fall back to session cwd/Desktop for @-mention search in empty windows

* fix(vscode): use the shared chat workspace as the no-folder fallback root
2026-08-07 15:38:43 -07:00
Saoud Rizwan 2f1c94505a Merge origin/main into desktop cloud sessions branch 2026-08-07 22:32:38 +00:00
Saoud Rizwan a5f90e0d53 fix(core): pick up checkpoints when git is initialized mid-session (#13026)
ensureGitRepository cached a negative probe for the lifetime of the hook
instance, so a session started in a non-git folder never got checkpoints
even after the user ran git init. Cache only the positive answer and
re-probe otherwise; the probe runs at most once per user turn.
2026-08-07 15:25:11 -07:00
Saoud Rizwan adabfc6bd5 fix(desktop): treat signed-out state as a typed result instead of a command error (#12976)
* fix(desktop): treat signed-out state as a typed result instead of a command error

* fix(desktop): sign out when the organization balance fetch reports the typed signed-out result

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* chore: retrigger checks after runner outage

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-07 15:06:45 -07:00
Saoud Rizwan 397d6f344f fix(desktop): resolve startup script-load SyntaxError and attribute webview errors to their source URL (#12974)
* fix(desktop): remove Vercel Analytics injection that breaks packaged webview startup

* fix(desktop): attribute webview uncaught errors to their source URL

* chore: drop unrelated claude-dev version bump from lockfile

* chore: retrigger checks after runner outage
2026-08-07 15:02:36 -07:00
Bee 8ca3068b73 refactor(desktop): update team tools component (#13047)
* refactor(desktop): update team tools component

* fix(desktop): address team tool review feedback
2026-08-07 22:58:06 +02:00
John Choi 6e6befdb65 fix(ui): remove nested tool output scrolling (#13043)
* fix(ui): remove nested tool output scrolling

* fix(desktop): avoid nested tool output scrolling

* chore(desktop): remove obsolete scroll utility

* fix(desktop): preserve multiline tool details
2026-08-07 13:44:23 -07:00
Haley Park 71536e55aa refactor(ui): introduce Cline-owned semantic color system (#12941)
* refactor(ui): introduce Cline-owned semantic color system

* refactor(desktop): adopt shared semantic theme roles

* refactor(ui): set 15px root and recalibrate xs/sm type scale

Scale rem steps so xs/sm stay 12/13px visually, and slightly lift dark-mode neutral-4.

* refactor(ui): align SearchCombobox with package type and hover tokens

Use host-safe cline-ui utilities and keep option font inheritance from CSS.

* fix(ui): use standard stroke-2 utility on approval spinner

* refactor(desktop): modernize shared UI primitives for Tailwind v4

Replace legacy arbitrary/has selectors with current utility syntax.

* refactor(desktop): bump chat chrome typography to text-sm

Keep composer controls and pickers on the shared sm type step.

* refactor(desktop): use max-w-344 for page frame content width

* chore(desktop): disable Next.js dev indicators

* chore: ignore desktop-app Cursor settings

* docs(pr): add before/after screenshots for #12941

* chore: retrigger checks

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-07 10:15:18 -07:00
John Choi 5b7005b003 fix(desktop): paginate cloud branch picker 2026-08-07 08:51:45 -07:00
abeatrix e48a7c9c91 feat(code): add SSH remote environments PoC 2026-08-07 00:20:13 -07:00
Saoud Rizwan 7348ba1847 chore(desktop): release v0.0.10 2026-08-06 23:45:56 -07:00
John Choi 71e1c59ab8 feat(desktop): switch models in cloud sessions 2026-08-06 20:38:53 -07:00
Bee 3e96fc6112 feat(cli): add mcp uninstall command (#12985)
* feat(cli): add mcp uninstall command

* unit test wiring

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-06 19:40:45 -07:00
Saoud Rizwan d84d09c543 desktop: fix silent turn failures, message duplication, and stuck composer; add first-run setup guidance (#12984)
* desktop: fix silent turn failures, message duplication, and stuck composer; add first-run setup guidance

Findings from two full computer-use UX audits of the desktop app:

- Surface failed turns in the transcript: queued turns (incl. the first
  prompt of a fresh session) only signal errors via chat_done, which the
  UI previously ignored - sending a message with no credentials failed
  in complete silence. Failed turns now show an error message enriched
  with the latest core error log and a pointer to Settings -> Models.
- Fix duplicated user messages: a live send's optimistic user message
  was materialized a second time by the runtime's queued-prompt-start
  event.
- Fix composer stuck on 'Agent is working...': drop prompts from the
  local queue snapshot when they start, emit a fresh queue snapshot from
  the sidecar on pending_prompt_submitted, and double-check the server
  queue on turn completion.
- Add a 'Connect a model' notice on the welcome screen when no provider
  has credentials, with actions to reopen onboarding at the connect step
  or jump to model settings; it reacts live to credential changes.
- Add 'Get an API key' links for popular providers in onboarding and
  Settings -> Models (the catalog docUrl is never populated), and link
  the Cline dashboard from the Cline API key form.
- Explain what Cline is on the onboarding welcome step.
- Make the stop button visible (was 8px with no padding) and support
  Esc to stop; add Cmd/Ctrl+N (new session) and Cmd/Ctrl+, (settings).
- Remove leftover [webview:delete] console.error debug logging that
  surfaced an error badge after deleting a session.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* desktop: remove remaining delete debug logging in session history hook

The sidebar right-click delete path had the same leftover [webview:delete]
console.error instrumentation, which made the Next dev-mode issues badge
appear after every deletion.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* desktop: fix Biome a11y error in WelcomeSetupNotice

biome's lint/a11y/useSemanticElements errors on role="status" divs;
use the semantic <output> element (implicit status role) instead. This
was failing the repo's 'bun run lint'.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* desktop: count structured-config and keyless providers as connected

The welcome setup notice previously only recognized apiKey/OAuth
credentials, so users running Bedrock/Vertex (structured configValues)
or a deliberately enabled keyless local endpoint (e.g. Ollama) were
nagged to connect a model they already use. isProviderConnected now
also counts an enabled provider whose required config fields are all
filled, or an enabled provider that has no API-key field at all.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* desktop: keep re-key eligible when chat_done lands in the same batch as its prompt start

When a turn fails fast, chat_queued_prompt_start and chat_done can be
dispatched in one React batch. Clearing the outstanding-optimistic-
bubble registry synchronously in the chat_done handler ran before the
re-key updater enqueued by the prompt-start event, so the optimistic
bubble was appended a second time instead of re-keyed. Clear the
registry inside a state updater so it executes in event order after
the re-key. Caught by the queued-turn-failure regression test.

* desktop: make the queued-prompt re-key updater idempotent under StrictMode

React StrictMode double-invokes state updaters in dev. The
chat_queued_prompt_start re-key updater consumed the optimistic
bubble's id from outstandingOptimisticUserIdsRef on its first run, so
the second run against the same prev found no eligible candidate and
appended the same user message a second time (and, without a promptId,
makeId() minted a different id per invocation). Hoist the message id
out of the updater and remember which optimistic bubble each queued
message id re-keyed so a re-run reaches the identical result. The memo
resets alongside the outstanding set (error state, reset, hydration).

Root-caused with runtime instrumentation: the duplicate only appeared
on turns that exercised the queue-drain re-key path, and hydration
later collapsed it to one message because the duplicate never existed
in persisted state.

* desktop: preserve failure messages across post-send canonical hydration

Persisted history never contains UI-only error bubbles, so the two
post-send read_session_messages replacements in sendPrompt wiped the
failure explanation appended from chat_done ~40ms after it rendered
(confirmed with runtime instrumentation). Re-append the active
session's error messages after the canonical history. Includes a
regression test reproducing the chat_done-error-then-RPC-resolution
race.

* desktop: don't let an optional API-key field veto a connected provider

Greptile P1 follow-up: Bedrock's catalog entry carries an optional
apiKey field ('Optional Bedrock bearer token') alongside IAM/profile
authentication, and keyless local endpoints can also surface one — so
treating the mere presence of an apiKey field as proof of disconnection
kept nagging configured users. An enabled provider (the user
deliberately persisted settings for it) now counts as connected unless
a required config field is unmet; auth may legitimately live outside
the catalog (IAM, env vars, local endpoints). Brand-new users have no
enabled providers, so the first-run notice still shows for them.

* desktop: tighten credential-error guidance and stop re-pinning stale failure bubbles

* desktop: invalidate the shared provider catalog after settings OAuth login

Greptile P1 follow-up: runOAuthProviderLogin only updated the settings
view's local provider state, so the shared catalog cache and its
invalidation subscribers (the composer selector and the welcome
screen's 'Connect a model' notice) kept reporting the provider as
disconnected until an unrelated invalidation or a pane remount. Notify
the shared cache on successful OAuth login, like the account view and
the API-key save path already do.

* desktop: clear the remembered core error on turn end, reset, and hydration

Greptile flagged that turn-start events are the only thing clearing
lastCoreErrorBySessionRef, and websocket events are not replayed: a
transport interruption that drops a turn's start event lets a later
detail-less failure resurrect an earlier turn's error. The remembered
error belongs to exactly one turn, so clear it whenever a turn ends
(chat_done, any reason) as well as on reset() and history hydration.
Regression test covers the dropped-start-event sequence.

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-06 19:25:42 -07:00
Bee 6f7f817d63 feat(core): support pre-registered OAuth clients for remote MCP (#12983)
* feat(core): support pre-registered OAuth clients for remote MCP

* fix(core): invalidate tokens when OAuth client changes

* fix(core): preserve compatible MCP OAuth sessions

* fix tests

* feat(desktop): wire mcp oauth in desktop

* UI update

* fix(core): reject stale mcp oauth callbacks

* fix(mcp): handle invalid settings and preserve state

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-06 18:58:52 -07:00
abeatrix d7b61de54f Merge remote-tracking branch 'origin/main' into bee/agent-voice
# Conflicts:
#	apps/examples/desktop-app/sidecar/context.test.ts
#	sdk/packages/llms/src/catalog/catalog.generated.ts
#	sdk/packages/llms/src/providers/ai-sdk.ts
#	sdk/packages/llms/src/providers/builtins.ts
#	sdk/packages/llms/src/providers/provider-ids.generated.ts
#	sdk/packages/llms/src/providers/providers.generated.ts
#	sdk/packages/llms/src/providers/routing/provider-option-rules.ts
#	sdk/packages/llms/src/providers/routing/provider-options.test.ts
2026-08-06 18:15:57 -07:00
Bee c18d9478ba feat(cli): use saved provider settings for schedules (#10667)
Co-authored-by: Cline Agent <cline-agent@users.noreply.github.com>
2026-08-06 17:34:40 -07:00
Ara 574b8eb45e fix(llms): use configured fetch for Vertex ADC refreshes (#12981) (#12991) 2026-08-06 10:07:06 -07:00
John Choi 7350294f7d fix(desktop): harden cloud session lifecycle and flags 2026-08-06 10:01:27 -07:00
John Choi fe90cbfdf1 Merge remote-tracking branch 'origin/main' into codex/desktop-cloud-agents 2026-08-06 09:49:19 -07:00
John Choi 44cf50cee7 fix(desktop): cloud sessions follow the active account scope
The sidebar now shows exactly the active scope's cloud sessions (personal
or the active organization — matching the dashboard), instead of merging
both. On account/organization switch the sidecar broadcasts
cloud_sessions_changed so the sidebar re-scopes immediately rather than
on the next poll; the cloud manager reset already discards the org cache
and connections.

The session registry is now upsert-only: a session opened under another
scope stays routable (send/abort keep working) when the server-side
active org drifts mid-run, even though it leaves the visible list.
Display truth stays lastListedSessions (active scope only).

Known behavior: after a full account/org SWITCH (manager reset), stale
threads from the previous scope report session-not-found on cold reopen —
the list no longer shows them, so this is reachable only via stale
webview state.
2026-08-06 09:43:04 -07:00
John Choi b39c7e0319 feat(desktop,sdk): cloud transcript synchronization + approval recovery
Implements the agreed convergence design (mirrors experiment/mobile-app):
subscribe → buffer → attach → snapshot (messages/status/queue) → install →
replay unreflected events → live. Single-flight with one queued rerun;
failed snapshots never become an authoritative empty transcript;
segment-scoped substring supersession in the sidecar; multiset count-delta
optimistic reconciliation with first-hydrate gating in the webview.

Review-round fixes on top of the sync implementation:
- Recovery baseline advances on delivered sends — a lost duplicate prompt
  can no longer be falsely confirmed by an earlier identical delivery.
- Prompt occurrence matching normalizes the pod's <user_input> wrapper
  (real transcripts never matched raw prompts; tests used unwrapped
  fixtures, so recovery was inert in production).
- Streamed-text trim symmetry so whitespace cannot defeat supersession
  and duplicate an entire already-persisted reply on reconnect.
- Buffered queue snapshots are dropped during replay (always older than
  the synced queue; replaying could regress it and double-bubble).
- approval.list_pending advertised in HUB_CAPABILITIES (capability-gated
  clients could never discover it) and the sidecar's approvals refresh
  never wipes observed state unless the reply provably carries the list.
- Safety tests: replay-when-not-contained, whitespace supersession,
  queue-snapshot drop, wrapped-prompt recovery, baseline advance.

Tracked follow-ups (not in this change): approval.respond and event
delivery remain unscoped hub-wide (scoping naively would break the
desktop's second approvals client); sessionId is mandatory here vs
optional on the mobile branch.
2026-08-06 09:34:16 -07:00
Saoud Rizwan 81cce3d70e chore(vscode): prepare 4.1.6 release 2026-08-06 00:47:54 -07:00
Saoud Rizwan e1352fa709 chore(cli): release v3.0.51 2026-08-06 00:28:37 -07:00
Saoud Rizwan 394fb04518 chore(sdk): release v0.0.71 2026-08-06 00:14:21 -07:00
Saoud Rizwan f1aebbfd5a feat(llms): surface meta/muse-spark-1.2-contributor for the Cline provider (#12995)
* chore(llms): regenerate model catalog from models.dev

* feat(llms): surface meta/muse-spark-1.2-contributor for the Cline provider

* test(llms): guard Vercel-only Cline model allowlist
2026-08-06 00:04:16 -07:00
abeatrix 378fdf147b feat: avatar overlay 2026-08-05 22:34:31 -07:00
John Choi 9c62406da9 fix(desktop,sdk): pre-PR review round — connection lifecycle and UX hardening
From a three-lens adversarial review of the branch:

Sidecar (cloud-sessions)
- BLOCKER: remove the connections-map entry when inner-session creation
  fails — the poisoned entry returned a disposed client whose event
  subscription was gone, silently streaming nothing for every later send.
- Single-flight inner-session creation: concurrent sends could fork two
  inner sessions on the pod, permanently dropping one run's events.
- Cache the active-organization lookup (60s, successes only) — the
  sidebar poll was making two authed REST calls per tick.
- delete() now drains an in-flight connect (zombie-connection race).
- Cold-cache expiry surfaces the clean session_expired envelope on
  send/read paths, not a raw WS upgrade failure.
- A provisioned-but-connect-failed create no longer reports failure for
  a live, billed sandbox; connect happens on demand instead.
- Guard against empty 2xx create responses (raw TypeError before).

SDK (hub client)
- Socket-identity guards in every connect-attempt cleanup path: a stale
  attempt's late timeout/error/close can no longer clobber a newer
  in-flight attempt's socket or dedupe state.

Webview
- Placeholder→real swap keeps the placeholder thread when opening the
  real session fails (was: deleted it and dumped the user on a blank
  fallback thread).
- Reset executionTarget to local when the cloud flag flips off on a
  fresh thread (was: permanently stranded cloud-gated composer).
- inferStatusFromMessages preserves 'provisioning' (the hydration pass
  was clobbering the sidebar state to idle within a second).
- Humanize cloud error envelopes in the delete toast and rename failure
  (rename previously had no catch at all).

Regression tests: poisoned-connection recovery, inner-session
single-flight.
2026-08-05 22:05:22 -07:00
John Choi a988d6a6ee fix(desktop): keep cloud loading continuous through the provisioning swap
The placeholder → real-session swap mounts a fresh thread whose hydration
briefly showed the skeleton between the provisioning row and the
conversation. An empty cloud session mid-hydration now shows the same
compact row ("Opening session...") so the loading treatment never
changes shape.
2026-08-05 21:36:52 -07:00
John Choi f1ec8c897c fix(desktop): cloud session dogfood round — billing, UX, and reliability
From live dogfooding of cloud agent sessions:

Billing & sessions
- Bill the user's ACTIVE organization (server-side active flag, cached
  resolver; personal fallback) instead of always personal credits, and
  list both personal and org-scoped sessions.
- Auto-title sessions from the first prompt; support rename via REST.
- Optional branch passthrough (picker + create body + recovery match).
- Forward autoApproveTools into cloud session creation.

Provisioning experience
- Sidebar placeholder while the synchronous create provisions (REST list
  cannot see the session yet), pulsing status dot, instant list nudge.
- Unified compact loading row (shared cycling phase line) for both the
  originating thread and the placeholder pane; phases advance once and
  hold rather than looping.
- cloud_session_provisioned event swaps placeholder threads to the real
  session when the sandbox is ready.
- Opening a placeholder is benign (loading state), reads return empty,
  only mutating actions error.

Correctness
- Surface run.failed error payloads in the chat (silent-failure fix; the
  raw CLOUD_SESSION_ERROR envelope can no longer reach the screen).
- Emit chat_session_status only on real status changes (pods stream
  periodic snapshots — every visited session was marked unread forever).
- expiredAt is a TTL deadline, not an end time; display uses createdAt
  (backend bumps updatedAt on every WS connect).
- provisioning is a first-class SessionHistoryStatus (the normalizer was
  collapsing it to idle).
- The new-prompt hero requires a thread WITHOUT a history session —
  fixes every flash-of-intro-screen path for existing sessions.
- Archived-history fallback only replaces a live failure when a snapshot
  actually exists (404 = null, not empty).

Plus GitHub repository/branch pickers, org-scoped integration URLs,
thinking-effort passthrough, and feature-flag targeting by account id.
2026-08-05 21:32:51 -07:00
John Choi 0b1f083531 fix(desktop): evaluate cloud-agents flag inside ChatThreadPane
The flag sync referenced ChatThreadPane state from Home, which only
surfaced at next-build prerender (tsconfig.dev does not cover webview).
2026-08-05 18:01:13 -07:00
John Choi d79ad49de3 Merge remote-tracking branch 'origin/main' into codex/desktop-cloud-agents 2026-08-05 17:58:02 -07:00
John Choi ce78c667cf feat(desktop): cloud agent sessions behind code-cloud-agents flag
Cloud sessions via core-platform remote-session API + Hub protocol v1:
sidecar CloudSessionManager (REST lifecycle, per-session NodeHubClient with
Bearer header auth, event translation, approvals, pending-prompt bridge,
expired-session archived history), webview Local/Cloud selector with repo +
optional branch picker, and a default-off PostHog feature flag gating
creation and the selector (existing sessions always remain accessible).
SDK: NodeHubClient resolveConnectionHeaders option; close unregistered
socket on registration failure; export FeatureFlag const from @cline/shared.
2026-08-05 17:57:57 -07:00
Saoud Rizwan 543dd0d818 fix(telemetry): attribute agent.run sdk.error events to the active model (#12972)
* fix(telemetry): attribute agent.run sdk.error events to the active model

* fix(telemetry): strip undefined values from sdk.error properties
2026-08-05 17:51:06 -07:00
abeatrix 2140996303 feat(desktop): avatar pet
- Add native Tauri avatar-window lifecycle, positioning, tray integration, and persisted preferences.
- Add the `/avatar-overlay` webview route and v2 spritesheet animation runtime.
- Play the standard wave animation when the avatar first appears.
- Add bundled Cline Bot and Mom spritesheets.
- Add avatar discovery, selection, visibility, and manifest-precedence support.
- Add Settings controls for enabling and selecting desktop avatars.
- Add an animated voice orb driven by microphone intensity.
- Improve realtime voice panel visibility, mute/stop controls, playback coordination, and tests.
- Reorganize chat input controls so speech, realtime voice, stop, and send actions do not compete.
- Document avatar package structure and storage.
2026-08-05 14:19:28 -07:00
Saoud Rizwan 1f2cbbeb9f chore(vscode): prepare 4.1.5 release 2026-08-05 14:04:04 -07:00
Saoud Rizwan b1a89156d6 feat(vscode): explain when a free model promotion ends (#12970)
* feat(vscode): explain when a free model promotion ends

Once a free promotion ends, the cline-free/ model is removed from the
catalog and the backend answers 'model not found' to requests against it.
The CLI has shown a dedicated 'Free model promotion ended' banner for this
since #12593; the extension instead rewrote the answer into generic
model-not-found guidance with no model-picker offramp.

Detect the case in the host where the active model id is known
(reshapeErrorForWebview, fed by a new MessageTranslatorState model-id
source), stamp the payload with a cline_free_promotion_ended code, and
render a dedicated card in the webview with a button into the model
picker. Classification is gated on the cline-free/ prefix so ordinary
model-not-found errors keep their generic path, and it runs before the
auth branch since the 404 status falls inside the generic auth range.

* fix(vscode): prefer the live task model over session-start metadata

A mid-task model-only switch updates the running session's model in place
(updateActiveSessionModel) and refreshes the task API shim, but never
touches the session's startConfig/manifest. Preferring the session-start
snapshot could therefore misclassify after such a switch: a genuine
retired-model 404 would miss the promotion-ended card, and the reverse
switch could show it for the wrong model. Provider switches restart the
session, so both sources agree there; the shim starts as "unknown"
(filtered out), so fresh sessions still resolve through start metadata.
2026-08-05 14:00:09 -07:00
Bee 1d7d9ce5e2 feat(llms): add portable reasoning resolution for AI SDK providers (#12946)
* feat(llms): add portable reasoning resolution for AI SDK providers

Introduce resolvePortableReasoning to map gateway reasoning requests
(effort levels, enabled/disabled flags) to the AI SDK's top-level
reasoning setting, applying it in buildAiSdkStreamConfig for supported
providers including Ollama.

- Defer exact token budgets to provider-specific options
- Omit reasoning when the caller expresses no explicit intent
- Replace manual provider-specific thinking overrides (e.g. Anthropic
  budget clamping, Moonshot/OpenAI-compatible toggles) with the
  portable reasoning path where applicable
- Add tests covering effort mapping, budget passthrough, and provider
  stream config integration

* fix(llms): prioritize explicit reasoning disable

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-05 12:17:49 -07:00
abeatrix 0d1a72f009 ui update 2026-08-05 12:13:53 -07:00
abeatrix a6c0cfd5c3 move audio-player to shared ui package 2026-08-05 11:19:05 -07:00
abeatrix 17e8c0cbc9 feat(desktop): add media player 2026-08-05 11:14:57 -07:00
Mikołaj Kondratek 78b7c3d8ac fix(desktop): stop rendering the first chat message twice (#12779)
* fix(desktop): dedupe chat_queued_prompt_start emitted for the same prompt

PendingPromptService.drain() emits a pending_prompts snapshot (head
removed) and a pending_prompt_submitted event back-to-back for the same
prompt. The sidecar translated both into chat_queued_prompt_start, so
the webview rendered the user's message twice until the chat was
re-hydrated from history. Track the last announced prompt id per live
session and emit the start chunk once.

* fix(desktop): re-key optimistic user bubble when the runtime queues the prompt

The send path renders an optimistic user bubble for prompts dispatched
while the session is idle, keyed by a random id. When the runtime
routes that prompt through its pending queue (e.g. during session
startup), the queued-prompt-start event appended a second bubble under
queued_user_<promptId> — the same message rendered twice until the
chat was re-hydrated from history. Re-key the trailing optimistic
bubble to the event's id instead of appending.

* fix(desktop): re-key only outstanding optimistic bubbles on queued prompt start

Review follow-up: matching by content alone could swallow a new queued
prompt that repeats the text of a message left at the transcript tail
by an earlier cancelled/failed turn. Track in-flight optimistic bubble
ids explicitly (registered on optimistic append; cleared on re-key,
turn end, error, and history hydration) and only re-key those.
2026-08-05 14:49:05 +02:00
Saoud Rizwan d626cfb0b5 chore(vscode): prepare 4.1.4 release 2026-08-05 03:03:51 -07:00
Saoud Rizwan e14f354c59 chore(desktop): release v0.0.9 2026-08-05 02:29:46 -07:00
Saoud Rizwan 41ba332f0a chore(cli): release v3.0.50 2026-08-05 02:16:56 -07:00
Saoud Rizwan 6997fae815 chore(sdk): release v0.0.70 2026-08-05 01:59:51 -07:00
Saoud Rizwan 5594512eb0 fix(vscode,cli): recoverable agent errors must not kill a turn that completes with a plan (#12953)
* fix(core): don't count plan-mode guard-blocked commands as model mistakes

The plan-mode command guard (#12906) rejects file-editing run_commands
calls with a tool error. The orchestrator counted that error as a failed
tool call, so a turn whose only tool call was guard-blocked fed the
MistakeTracker, which emits a recoverable "error" AgentEvent
("1 tool call(s) failed: [run_commands] ...").

Hosts render that event as a failed turn. In the VS Code extension the
turn ended in the "error" phase (Retry / Start New Task footer), the
final plan text was never retagged to plan_completion_result, and
toggling to Act therefore rebuilt the session without the auto-continue
send - the toggle appeared to do nothing and the presented plan was
never acted on. In the CLI TUI the same event flipped the footer to
idle mid-turn.

A guard rejection is deliberate session policy, not a model mistake:
the run continues and the model is expected to fold the change into
its plan. Tag the guard error with a stable marker sentence, expose
isPlanModeBlockedCommandError, and skip the failed-tool bookkeeping for
matching results so no mistake is recorded and no error event is
emitted. Repeated blocked attempts are still bounded by loop detection
and maxIterations.

* docs(core): flag plan-mode guard error string matching for typed skip channel

FIXME on isPlanModeBlockedCommandError: recognizing guard rejections by
sniffing the error text is brittle. The intended replacement is a typed
skipSource/skipCode on the tool-finished runtime event so the
orchestrator (and the VS Code approval-denial suppression) can identify
skipped tools structurally instead of via string matching.

* Revert core mistake-counting change for plan-guard blocks

A model attempting a file-editing command in plan mode is disobeying
its instructions - that IS a model mistake, and the MistakeTracker
should keep counting it (it is the brake that stops weak models from
flailing at blocked commands indefinitely). The real bug is host-side:
a recoverable mid-turn mistake must not kill a turn that afterwards
completes with a presented plan. The follow-up commit fixes that in
the hosts instead.

* fix(vscode,cli): treat recoverable agent errors as in-run notices, not turn outcomes

The MistakeTracker emits a recoverable error event for every recorded
mistake while the run continues - e.g. a plan-mode guard-blocked
run_commands call as the turn's only tool call. Both hosts treated any
error event as terminal:

- The VS Code translator cleared the pending completion retag, set
  errorSeen (turn phase "error": Retry / Start New Task footer), marked
  the turn complete, and rendered the error recovery UI. A plan turn
  that recovered from the mistake and completed cleanly therefore never
  produced plan_completion_result, so togglePlanActMode's planPresented
  check failed and switching to act mode rebuilt the session without
  the auto-continue send - the toggle appeared to do nothing.

- The CLI TUI flipped isRunning/isStreaming to idle mid-turn, so the
  footer lied about the still-running turn.

Recoverable errors are informational: the turn's outcome is decided by
how it actually ends (done/error). VS Code now logs them and keeps them
out of the chat (the tool failure is already shown inline on its tool
row, and provider-failure telemetry already ignores recoverable events
for the same reason); the CLI keeps its running state and surfaces them
only in verbose mode, as it already did for display. Genuine run
failures carry recoverable: false and keep the existing error UI.
2026-08-05 01:02:23 -07:00
abeatrix e2b97792b1 feat(desktop): play generated audio artifacts 2026-08-04 22:19:09 -07:00
abeatrix e4a7c19432 feat(desktop): add generated video support 2026-08-04 22:15:50 -07:00
abeatrix 589f32d13e feat(desktop): improve realtime voice sessions 2026-08-04 22:15:21 -07:00
abeatrix 879c085fdb feat(desktop): add realtime voice and UI refinements 2026-08-04 22:15:21 -07:00
Saoud Rizwan 6712d43c69 Revert "fix(llms): flatten top-level tool schema unions before sending to pro…" (#12950)
This reverts commit 21edad82a6.
2026-08-04 21:11:33 -07:00
Bee bd27d9c41b feat(desktop): session source filtering (#12943)
Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-04 21:01:40 -07:00
Saoud Rizwan 21edad82a6 fix(llms): flatten top-level tool schema unions before sending to providers (#12948)
Anthropic (and several providers OpenRouter fans out to) rejects any tool
whose input_schema has oneOf, allOf, or anyOf at the top level, failing the
whole request with:

  tools.N.custom.input_schema: input_schema does not support oneOf, allOf,
  or anyOf at the top level

MCP servers commonly advertise tools whose input schema is a union of object
shapes (e.g. generated from a Zod union), so one such tool bricked every
turn of the session. Merge union branch properties into a single object
schema at the provider boundary; tools still validate their real input
shapes in execute().

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 20:56:39 -07:00
Tomás Barreiro 2f58bbe4ed Add Auto Approval to ACP (#12897)
* Add Auto Approval to ACP

* Update apps/cli/src/acp/auto-approve.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Update apps/cli/src/acp/auto-approve.test.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-04 20:54:39 -07:00
Saoud Rizwan ddfb67515b fix(desktop): inline telemetry config into the packaged sidecar binary (#12925)
* fix(desktop): inline telemetry config into the packaged sidecar binary

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(desktop): reject non-http OTLP endpoints in the telemetry selfcheck

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 20:43:01 -07:00
Saoud Rizwan 472f9c88c5 Add plan-mode command blocklist to run_commands (#12906)
* Add plan-mode command blocklist to run_commands

Plan mode kept run_commands available (needed for read-only
investigation) but relied on prompting alone to prevent file edits,
and weaker models routinely ignore that. Add a hard guard in
@cline/core's createShellTool that inspects each command before
execution and rejects file-editing constructs with a plan-mode tool
error instead of running them.

The guard is a quote/heredoc-aware scan that blocks file-manipulation
commands (rm/mv/cp/tee/touch/...), in-place editors (sed -i, perl -i,
gawk -i inplace, sort -o), output redirection to files (allowing /dev
sinks and /tmp for the documented output-capture pattern), mutating
git subcommands, package-manager installs, find -delete/-exec, and
nested command strings (sh -c, eval, sudo, xargs, ...). Windows and
PowerShell equivalents are covered too.

Enabled via a new blockFileEditingCommands flag on DefaultToolsConfig,
set by the plan tool preset (CLI and core runtime) and plumbed through
the VS Code extension's custom run_commands tool from the session mode.
The tool description and PLAN_MODE_INSTRUCTIONS now state the hard
block so models are forewarned.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Simplify plan-mode command guard to a plain blacklist

Replace the char-by-char shell tokenizer (heredoc queues, process
substitution, recursion into sh -c/eval, find -exec analysis) with a
simple scan: mask quoted text/heredoc bodies/escapes/comments so they
cannot false-positive, split on shell separators, and compare the
leading command word of each part against flat blacklists (commands,
mutating subcommands, in-place edit flags), plus one redirect check.
Quoted nested commands (bash -c 'rm x') are a documented false
negative. Also drop the guard from the package's public exports; it
is internal to createShellTool.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Move plan-mode command guard into a built-in beforeTool hook

Review feedback (abeatrix): command blocking is session policy, not
shell-executor configuration. Replace the blockFileEditingCommands
flag threaded through preset -> tool config -> VS Code host with a
core extension registered by the runtime builder for plan-mode
sessions. The beforeTool hook intercepts every run_commands tool in
the runtime - the SDK builtin, host replacements like the VS Code
terminal tool, and delegated sub-agents - and rejects file-editing
calls with the plan-mode error before tool policy and user approval,
so users are no longer prompted to approve a command that would only
fail. All VS Code wiring for the guard is removed.

Also adds block telemetry (sdk.plan_mode_command_blocked with the
blocked construct, never raw command content), per review.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Address review feedback on the plan-mode command blacklist

False positives (mkondratek):
- perl -Ilib / uppercase value-taking flags no longer match the
  in-place check; the flag cluster must end at a lowercase i
  (sed -Ei still blocked)
- awk inplace detection is tied to the -i/--include flag instead of
  matching the substring anywhere (filenames like inplace-notes.txt
  no longer trip it)
- read-only git forms allowed: stash list/show, worktree list,
  submodule status/summary, and any git subcommand with --help/-h
- arithmetic expansion (1) is masked before the redirect scan

Hardening and coverage (mkondratek, dominiccooney):
- temp-path redirect allowance rejects .. traversal (/tmp/../...)
- Windows gets a temp escape hatch: %TEMP%/%TMP%/$env:TEMP redirect
  targets are allowed and the block error mentions it
- curl -o/-O/--output/--remote-name and wget downloads blocked
  (--spider and -qO- stdout forms stay allowed)
- python -m pip resolves to the pip subcommand check
- unambiguous PowerShell aliases (mi, ri, cpi, rni, ac, clc) plus a
  case-variant test
- more package managers: winget, nuget, gem, composer, dotnet add,
  go install/get; bare classic yarn blocked again
- find -exec/-execdir/-ok chains and xargs -I {} placeholders are
  checked for mutating commands

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 20:35:54 -07:00
Saoud Rizwan f77d0930ba fix(llms): preserve models.dev reasoning options in generated catalog so adaptive-era Claude models never get manual thinking (#12908)
* chore(llms): regenerate model catalog from models.dev to pick up reasoning options

The baked fallback catalog was last regenerated before toModelInfo started
mapping models.dev reasoning_options into ModelInfo.reasoningOptions, so it
carried no reasoning metadata. Whenever the live models.dev fetch fails or a
model resolves from the baked catalog, adaptive-era Claude models (4.6+/5.x)
fell through the missing-reasoningOptions path to Anthropic manual thinking
and the API rejected the request with 'thinking.type.enabled is not
supported'.

This regen also picks up upstream models.dev drift; test expectations that
hardcoded stale catalog values (GLM 5.2 context window, OpenRouter GLM 4.7
reasoning controls, Vercel AI Gateway Qwen 3.6 Plus budget controls) are
updated to the current published values.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(llms): infer adaptive thinking for adaptive-era Claude ids when catalog reasoning options are missing

Claude 4.6+ and 5.x models reject the manual thinking wire shape
(thinking.type 'enabled') on the Anthropic API. When a model resolves
without reasoningOptions metadata (offline baked catalog before the regen,
or user-typed unlisted ids such as claude-opus-4-6:1m), the reasoning
policy previously fell through to anthropic-manual and every
reasoning-enabled request failed with a hard API error.

Add isClaudeAdaptiveEraModelId as a narrowly scoped id fallback (name-first
Claude ids with version 4.6+ or 5.x, plus the Fable line) and use it in the
missing-reasoningOptions branch of resolveAnthropicReasoningRequestPolicy.
Genuinely old or unknown Claude-compatible ids keep the manual default,
which remains the safe shape for third-party Claude-compatible endpoints.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(llms): prefer adaptive thinking over manual when a model advertises an effort control

A numeric reasoning.budgetTokens (e.g. a thinkingBudgetTokens setting
migrated from the legacy extension) used to force the anthropic-manual
policy whenever the model advertised a budget_tokens control. Claude 4.6+
models advertise both effort and budget_tokens on models.dev but reject
thinking.type 'enabled' on the Anthropic API, so those requests failed.
Effort now wins: adaptive is selected and the numeric budget is ignored.
Budget-only models (Sonnet 4.5 and older) keep honoring explicit budgets
via the manual shape.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* test(llms): guard baked catalog reasoning options for adaptive-era Claude models

Resolve adaptive-era Claude models through the generated (offline fallback)
catalog and assert their entries carry effort reasoning options that the
Anthropic reasoning policy resolves to adaptive thinking.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* test(core): update GLM 5.2 context window to current models.dev value

The catalog regen picked up upstream drift: models.dev now publishes a
1,000,000-token context window for zai/glm-5.2 (was 1,040,000).

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* revert(llms): drop the Claude id-based adaptive-thinking fallback

Keep the fix surface minimal: the catalog regen covers every model
models.dev lists (the overwhelming share of the production failures), and
the effort-over-budget policy covers listed models that advertise both
controls. Unlisted id variants (e.g. claude-opus-4-6:1m) keep the
pre-existing manual fallback rather than introducing id-version parsing in
model-facts.ts; if they appear in models.dev the catalog picks them up
automatically.

This reverts commit 6d725b1ecd7c896a08c3c58dbb37afeaf34bb31e, keeping the
regenerated catalog and the effort-precedence change.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(llms): default unknown Claude ids to adaptive thinking when catalog options are missing

Reintroduce the id-based fallback with the forward-compatible policy the
ecosystem converged on (vercel/ai#17804 for @ai-sdk/anthropic's capability
lookup; opencode's transform.ts after repeated allowlist misses for
opus-4.7, sonnet-5, and opus-5): when catalog reasoningOptions metadata is
unavailable, treat unrecognized Claude ids as newer than the known model
list and use adaptive thinking, since new Claude releases reject the manual
wire shape. Known legacy families (Instant, 2.x, 3.x, and name-first 4.0-4.5)
keep manual, as do non-Claude Anthropic-compatible ids and unknown Claude
ids carrying an explicit numeric budget (a custom-endpoint signal).

Unlike the earlier reverted allowlist (which defaulted unknown ids to
manual), this fails open for future models: claude-opus-4-6:1m-style
variants and next year's Claude work without a code change.

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 20:34:13 -07:00
Saoud Rizwan d1462cf919 fix(llms): retry empty model turns on all providers, not just Ollama (#12927)
* fix(llms): retry empty model turns on all providers, not just Ollama

Production telemetry shows 'Model returned empty response' hard failures
on hosted backends (openrouter, cline, openai-compatible endpoints), not
just local Ollama — 46 tasks / 120 events in 24h on the SDK extension vs
~0 on legacy, which has its own empty-response fallback.

The retry-empty-response middleware already existed but was wired only
into the Ollama vendor. Move the wrap to the central AI SDK composition
point (createAiSdkProvider in ai-sdk.ts), where every vendor's model is
constructed, so all providers get it: retry only when a turn produced
genuinely nothing (no text, no reasoning, no tool call), tool-call-only
turns are never retried, non-empty turns stream through live, and error/
token-limit finishes pass through unchanged. Vendors can opt out or tune
attempts via ProviderFactoryResult.retryEmptyResponses. The agent
runtime's loud failure after persistently empty turns is unchanged.

* docs(sdk): drop changelog edit — release commits own the changelog

v0.0.69 is already published; its section must not be edited
retroactively. The next release commit will describe this change.

* ci: re-trigger checks (flaky Windows runner test timeouts)

* ci: re-trigger checks (flaky Windows runner test timeouts)

* fix(llms): classify stream parts exhaustively, buffer retry attempts, aggregate usage

Review follow-up (dominiccooney): the retry predicate and the response
parser were two independent, incomplete interpretations of the
LanguageModelV4StreamPart union, and rejected attempts leaked structural
parts and dropped billable usage.

- stream-part-classification.ts is now the single exhaustive boundary:
  every part is converted content, explicitly unsupported output,
  structural metadata, stream-start, finish, or error, with a never
  check so new AI SDK part types fail compilation. Retry eligibility
  derives from it: only turns with no output at all are retried;
  unsupported-but-real output (custom, reasoning-file, source,
  provider-executed tool-result) is never retried.
- Generated file parts are converted end to end: emitAiSdkEvents emits
  a new file AgentModelEvent and the agent runtime assembles it onto
  the assistant message (image part for image/*, file part otherwise),
  so a file-only turn is no longer an empty message. The legacy
  ApiStream bridge explicitly skips file events (no chunk type).
- Each retry attempt is buffered until it proves non-empty (first
  output or error part), so discarded attempts leak nothing — one
  retried request produces one clean stream with exactly one
  stream-start.
- finish.usage from discarded attempts is aggregated field-by-field
  (cache and reasoning detail included) into the emitted finish, so a
  three-request turn reports three requests' worth of tokens.
2026-08-04 20:33:06 -07:00
Saoud Rizwan 49d33aa793 fix(vscode): show cwd-relative tool paths in the chat view (#12900)
* fix(vscode): show cwd-relative tool paths in the chat view

The SDK message translator copied the model's absolute file paths straight
into the ClineSayTool messages, so chat cards like "Cline wants to read this
file" showed full absolute paths. Relativize them against the task's cwd for
display (classic getReadablePath behavior: relative inside the cwd, basename
for the cwd itself, absolute when outside), including apply_patch's
"*** Update File:" markers which DiffEditRow parses for its headers.

Also restores the readFile card's click-to-open target by setting content to
the absolute path, matching the classic extension.

* refactor: apply display-path relativization as a single ClineSayTool transform

Instead of threading cwd through every case of sdkToolToClineSayTool, leave
the tool mapping untouched and apply one toDisplaySayTool transform (with a
filesystem-path tool whitelist) at the points where tool cards are emitted.
Same behavior, much smaller footprint; MCP/unknown tools keep their exact
prior behavior.

* fix: keep absolute readFile open-target untouched on Windows; match '..' as whole segment

path.resolve(cwd, absPath) rewrites a drive-less absolute path onto the
current drive on Windows, breaking the readFile card's click-to-open target
(and the tests asserting it). Guard with path.isAbsolute instead.

Also match '..' only as a whole path segment in toDisplayPath so an in-cwd
entry literally named '..config' is not misclassified as outside the cwd
(greptile P1).

* fix: keep Desktop-fallback paths absolute; relativize '*** Move to:' destinations

When VS Code has no workspace open, getWorkspaceRoot() falls back to the
Desktop; classic getReadablePath deliberately keeps full absolute paths in
that case so the user can see where operations occur. Restore that guard in
toDisplayPath.

Also enroll PATCH_MARKERS.MOVE in relativizePatchPaths so a rename renders
both source and destination relative (covers the split-patch path too).
2026-08-04 20:03:07 -07:00
Saoud Rizwan 9b5dcc6405 Fix Bedrock prompt caching: emit Converse cachePoint markers instead of anthropic cache_control (#12928)
* Fix Bedrock prompt caching: emit Converse cachePoint markers instead of anthropic cache_control

The Bedrock provider manifest routed prompt caching through the
anthropic-cache-control format, so requests carried cache_control
provider options that @ai-sdk/amazon-bedrock silently drops - its
Converse message converter only reads providerOptions.bedrock.cachePoint.
Bedrock never received a cache checkpoint, cacheRead/cacheWrite were
always 0, and a stray top-level cache_control field leaked into the
Converse request body.

Adds a bedrock-cache-point prompt-cache format that attaches a
message-level cachePoint marker to the last user message, which the
converter appends as a cachePoint content block, caching the whole
prefix up to it.

Fixes #12913

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Format gateway.test.ts assertion

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 20:00:16 -07:00
Bee f2ac1ef10a fix(desktop): show skills in slash command menu (#12894)
* fix(desktop): show skills in slash command menu

* fix(core): normalize runtime slash command names

* fix(core): disambiguate colliding slash commands

* fix(core): preserve same-kind slash commands

* fix(core): stabilize colliding slash command aliases

* fix(core): avoid slow runtime command regex

* fix(core): remove quadratic hyphen trim

* fix(core): prefer skills over workflows on slash command collisions

Workflows are effectively deprecated in favor of skills, so when a
workflow's normalized name collides with a skill the skill now owns the
token and the workflow is dropped. This removes the collision
qualification machinery (-skill/-workflow/-hash aliases), which silently
renamed established CLI and VS Code command tokens, and removes the
duplicate-token throw that sat in the CLI send path, the hub snapshot
capability, and the desktop list_user_instruction_configs command.
Same-kind collisions resolve to the first entry of the deterministic
(name, id) sort, stable across discovery order.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(vscode): resolve typed workflow filenames through record ids

Name normalization broke the legacy /my-workflow.md fallback for
workflows renamed via frontmatter: the configured record name (e.g.
"Ship It") no longer compares equal to the normalized command token
("ship-it"), so a typed filename stopped expanding. Match the discovered
record to its runtime command by the stable record id instead, keeping
the canonical-name comparison as a fallback for callers that pass
records without ids.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(core): normalize snapshot names in hub slash command proxy

The hub-side proxy normalizes the typed token but compared it against
snapshot command names verbatim. Snapshots served by older clients carry
raw configured names (e.g. "Ship It"), which could previously exact-match
typed input and would now never match. Normalize both sides of the
comparison so mixed-version hub setups keep resolving.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(desktop): expand slash commands in the sidecar send path

Selecting a skill or workflow from the desktop slash menu inserted the
token but the sidecar dispatched it verbatim, so the model received
literal text like '/publish-ui write docs' instead of the configured
instructions. handleSend now expands a leading runtime slash command via
the core user-instruction service before dispatch (mirroring the CLI's
buildUserInputMessage), keeping the raw token as the session's display
prompt. Built-in webview commands (/fork, /team) and unknown tokens pass
through unchanged, and discovery failures fall back to the raw prompt.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(desktop): expand slash commands when editing queued prompts

Editing a pending prompt stored the raw slash token, which the runtime
later delivered to the model unexpanded — only the initial send path
went through expandRuntimeSlashCommand. handleUpdatePendingPrompt now
expands a leading skill/workflow token before persisting the update,
matching the enqueue behavior in handleSend.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(core): preserve Unicode letters in slash command tokens

Normalization stripped all non-ASCII characters, so a skill named 发布
got an unrelated generated token while typing /发布 could never resolve —
a regression from pre-normalization behavior where the exact name
matched. Keep Unicode letters and numbers in normalized tokens and only
collapse whitespace and symbol runs into hyphens.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-04 19:59:05 -07:00
Saoud Rizwan 10da3bf5d6 fix: emit AI SDK 7 image shapes and correct the claude-code peer range (#12901)
* fix(shared): emit AI SDK 7 file parts for images

formatMessagesForAiSdk still built the retired shapes: user images as
{type:'image'} message parts and tool-result images as {type:'image-data'}
content parts. AI SDK 7 auto-migrates both at runtime, but logs a
DeprecationWarning through process.emitWarning on every image-bearing
request, and the shims are slated for removal in the next major.

Emit the canonical shapes instead: {type:'file', data, mediaType} for
user images and {type:'file', data:{type:'data', data}, mediaType} for
tool-result media. mediaType is required on file parts, so URL-backed
images without a known type use the bare 'image' top-level segment,
which AI SDK 7 resolves per provider.

* fix(llms): allow the AI SDK 7 major of ai-sdk-provider-claude-code peer

The AI SDK 7 upgrade moved the ai-sdk-provider-claude-code
devDependency to ^4 but left the peer range at ^3.4.3, so consumers
resolving the peer would install the AI SDK 6 (Provider V3) major.
Align the peer range with the version the package is built against.
2026-08-04 19:53:51 -07:00
Saoud Rizwan 0034efe48c fix(llms): send max_completion_tokens for reasoning models on OpenAI-compatible endpoints (#12902)
* fix(llms): send max_completion_tokens for reasoning models on OpenAI-compatible endpoints

* fix(llms): require leading boundary in gpt-5 model-id pattern

* docs(llms): add maintenance notes to reasoning-era model-id patterns
2026-08-04 19:42:44 -07:00
Saoud Rizwan 64993e78d5 fix(llms): substitute image content for models without image support (#12903)
Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 17:34:44 -07:00
Saoud Rizwan 06f31f2821 fix(llms): route Bedrock foundation models through geo inference profiles (#12926)
* fix(llms): route Bedrock foundation models through geo inference profiles

AWS Bedrock offers no on-demand throughput for newer foundation models;
they must be invoked through an inference profile. The SDK Bedrock vendor
passed model ids through unmodified, so every request with a bare modern
model id (e.g. anthropic.claude-sonnet-4-6) failed with "Invocation of
model ID ... with on-demand throughput isn't supported".

Resolve the wire-level model id in the Bedrock vendor: honor the existing
useCrossRegionInference / useGlobalInference settings (already plumbed
through provider config but previously ignored), and auto-prefix bare ids
of models known to have no on-demand throughput so they work without the
toggle. Ids that are already profile-prefixed, ARNs, and custom-model
configurations are never rewritten; unknown regions fall back to the raw
id. Country profiles (jp./au.) are preferred over apac. where the model
catalog shows AWS ships them.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(llms): future-proof Bedrock profile-required model patterns

Match Anthropic tier-first naming generically (excluding the frozen
legacy claude-3-*/claude-v2/claude-instant naming schemes) instead of
enumerating tier names, so future profile-only Claude tiers work without
pattern-list updates. Also cover the profile-only Amazon Nova 2 series.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(llms): gate Bedrock geo profiles on catalog availability

Address review feedback on inference-profile resolution:

- Never manufacture apac. (or other unconfirmed) profile ids: prefer a
  catalog-confirmed variant among the region's candidates (jp./au./apac.),
  and otherwise keep the raw id so AWS returns the actionable on-demand
  error instead of "provided model identifier is invalid". Profile-only
  models still fall back to us./us-gov./eu. prefixes, where AWS reliably
  ships geo profiles for such models.

- Drop the customModelBaseId short-circuit: legacy migration copies the
  base id without the custom-selected flag, so its presence must not
  disable profile routing for a normal catalog model. Custom/provisioned
  ids stay raw on the cross-region path because no catalog variant can be
  confirmed for them, and ARN-based custom models were already passed
  through.

Adds a per-region wire-id table test, an injected-catalog apac test, and
a stale-customModelBaseId regression test.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(llms): require catalog confirmation for every Bedrock geo profile

Remove the us./us-gov./eu. pattern fallback: AWS documents
inference-profile availability per model and geography, so no geographic
prefix is assumed valid without a catalog-confirmed variant (the catalog
had bare amazon.nova-lite/micro/pro ids with no geo variants, which the
fallback would have rewritten to unconfirmed eu./us. ids). The pattern
list now only gates eligibility for automatic routing; the catalog
always picks the actual prefix, and the raw id is preserved when no
variant is confirmed.

Adds boundary tests asserting pattern-matched models without confirmed
variants stay raw (with and without cross-region inference), plus
injected-catalog positive tests for us-gov. and future tier-first ids.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 17:34:13 -07:00
Saoud Rizwan 71e6b44ef7 Consolidate plugin display-name resolution into @cline/shared (#12905)
* Fix installed plugins all displaying as "index" in the desktop app

Hoist getPluginDisplayName (nearest-ancestor package.json name with
basename fallback) into @cline/shared storage paths, re-export it via
@cline/core, and replace the duplicated copies in cline-hub, the CLI
TUI, and VS Code marketplace helpers. Fix the desktop sidecar and
'cline config plugins', which still named plugins by entry-file
basename, so package-backed installs showed up as "index".

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Use shared getPluginDisplayName in desktop sidecar after #12933

Merging main brought in PR #12933, which fixed the desktop plugin
naming with another local copy of the helper. Drop that copy in favor
of the shared @cline/shared implementation this branch introduces, and
remove the node:path imports it needed.

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 17:25:36 -07:00
Saoud Rizwan 0bcd602150 fix: task with attachments not resetting on New Task click (#12924) (#12937)
The webview posts an optimistic say:'task' message carrying the user's
images/files, and only clears it once an identical authoritative message
arrives from the extension. emitInitialTaskMessage omitted attachments,
so the optimistic copy was never confirmed and withPendingUserMessage
kept re-injecting the old task into the transcript even after New Task
cleared it - leaving the chat permanently stuck on the previous task.

- Include images/files on the authoritative initial task message so the
  optimistic pending copy is confirmed and cleared as designed.
- Defensively drop any unconfirmed optimistic message in startNewTask so
  an explicit New Task click always yields a clean slate.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 17:02:27 -07:00
Saoud Rizwan d759f4c646 fix(cli): track external git branch changes in the TUI status bar (#12930)
* fix(cli): track external git branch changes in the TUI status bar

The branch shown below the prompt was read once at startup and only
refreshed after an agent turn, so checkouts made from another terminal
or an editor left the TUI showing a stale branch (#12911).

Watch the repo's git dir for HEAD changes (git replaces HEAD via
rename, so a directory watch is used) and refresh the status bar
immediately, with a slow 5s poll as a fallback for filesystems where
fs.watch is unreliable. State updates are skipped when nothing changed
to avoid needless re-renders.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* refactor(cli): replace subprocess polling with stat-based HEAD backstop

Drop the unconditional 5s git-subprocess poll from useRepoStatus. The
fs.watch directory watcher stays for instant updates where the runtime
delivers HEAD events, but Bun on Linux drops them, so add fs.watchFile
on the HEAD file as the backstop: one in-process stat() every 2s that
only triggers git subprocesses when HEAD actually changed. Verified in
the Bun-run TUI that external checkouts show up within ~2s.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* refactor(cli): simplify HEAD watching to a single fs.watchFile

Drop the fs.watch directory watcher (Bun on Linux never delivers its
HEAD events, making it dead weight on the runtime the CLI ships on) and
the debounce it required. watchGitHead now just stat-watches the single
.git/HEAD file via fs.watchFile, which survives git's rename-based HEAD
updates and works on network mounts.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* refactor(cli): use a plain 5s poll for repo status

Remove the HEAD watcher entirely per review preference for minimal
code: root.tsx now just polls readRepoStatus every 5 seconds, skipping
state updates (via isSameRepoStatus) when nothing changed so idle ticks
don't re-render the app.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* fix(cli): skip repo status poll ticks while a read is in flight

Bounds concurrent git subprocesses when a read exceeds the 5s interval
(slow git on huge repos) and prevents an older completion from
overwriting newer status. Addresses Greptile review feedback.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 16:50:30 -07:00
Saoud Rizwan b035bf9255 fix(desktop): give chat message actions breathing room under the last line (#12921)
The copy/fork (and user copy/edit/restore) action row was pulled up 8px
(-translate-y-2), which made the icons collide with the descenders of the
message's last line of text. Reduce the raise to 4px (-translate-y-1) so the
actions sit with a small, deliberate gap under the message content while
still hugging the message closely enough to read as attached to it.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 16:49:09 -07:00
Saoud Rizwan ca9cb7f554 Slow hero heading verb rotation from 2.6s to 5s (#12940)
Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 16:27:12 -07:00
Saoud Rizwan 1ae2f71a0f fix(telemetry): dedupe sdk.error across layers and rate-limit repeated failures (#12931)
* fix(telemetry): dedupe sdk.error across layers and rate-limit repeated failures

Every provider failure was emitted twice — once by the model layer
(provider.stream, handled: true) and again verbatim by the agent loop
(agent.run, handled: false) — and unattended retry loops emitted the
same failure every iteration, unbounded. 24h of CLI data: 300K events
from 1.7K users, top 10 machines at 70% of volume.

Two changes:

- The agent loop no longer re-reports model stream failures. run-failed
  events carry errorClass exactly when the run failed on a model stream
  error, and the model layer already reports those at its own error
  boundary — so the run loop reports only failures that originate in
  the loop itself (empty response, max iterations, ...).

- captureSdkError caps identical failures per process: 5 per hour per
  (event, component, operation, error_type, normalized message), with
  digit runs collapsed so retry counters coalesce. Suppressed emissions
  surface as suppressed_count on the next emission after the window
  rolls over. In-memory only; the cap never blocks reporting.

Event name, attributes, and all call sites are unchanged;
suppressed_count is the only additive field.

* fix(telemetry): make sdk.error dedup ownership explicit and key limiter on status/code

Review follow-ups (#12931):

- Reporting ownership is now an explicit signal instead of being inferred
  from errorClass. captureSdkError returns whether the failure was
  recorded, the model layer forwards that as errorReported on the finish
  event, and the run loop skips only failures marked reported. Custom
  AgentModel implementations that never call captureSdkError leave the
  bit unset, so their failures still produce exactly one sdk.error from
  the run loop (regression test added).

- The rate-limit key now includes the structured error_status and
  error_code that normalizeSdkError already extracts, so an HTTP 429
  hot loop cannot consume an HTTP 401's budget even though their
  messages differ only by digits (tests added for both fields).

- resetSdkErrorRateLimiterForTests is tagged @internal; it stays
  re-exported because package test suites can only reach it through the
  package entry point.
2026-08-04 16:25:44 -07:00
Saoud Rizwan 62c57a0ccd ci(ui): publish @cline/ui without a manual approval gate (#12938)
The publish job ran under the shared `Publish` GitHub environment, whose
required reviewers turned every @cline/ui release into a two-person
ceremony. Nothing in the job reads secrets from that environment — it
authenticates to npm purely over OIDC trusted publishing — so the
environment bought us an approval prompt and nothing else. sdk-publish
and cli-publish already publish unattended the same way.

The npm trusted publisher for @cline/ui was registered with
`environment: Publish`, which pins the OIDC token's environment claim, so
it has been re-registered without it (same repo, workflow file, and
permissions). That change is already live; landing this without it would
have broken publishing.

Access is still gated by workflow_dispatch (write access required), the
`refs/heads/main` ref check, and the typed `publish` confirmation.
2026-08-04 16:23:46 -07:00
Saoud Rizwan f3c8b6748b Remove model-initiated plan-to-act switching from the VS Code extension (#12929)
* Remove model-initiated plan-to-act switching from the VS Code extension

Match the legacy extension: the model can no longer call switch_to_act_mode
to move itself from plan mode to act mode. The user must flip the Plan/Act
toggle manually. The CLI keeps the tool and its prompt unchanged.

- Stop registering the switch_to_act_mode extra tool in plan-mode sessions
  and drop the pending-mode-change queue, beforeModel stop hook, and idle
  apply path that existed only for the tool-initiated switch.
- Add a planModeSwitchTool option to buildClineSystemPrompt (default true,
  CLI output unchanged) and a PLAN_MODE_INSTRUCTIONS_MANUAL_SWITCH variant
  that directs the model to ask the user to toggle to Act mode instead of
  calling a tool it does not have; the extension passes false.
- The user-driven toggle path (togglePlanActModeProto), including
  auto-continue when a completed plan is presented, is unchanged.

* Use a generic completing-tool name in translator retag test

Review feedback: submit_and_exit is a yolo-mode tool and does not exist
in plan/act sessions. The test exercises tool-agnostic translator
behavior, so use a neutral example name and clarify the comment.
2026-08-04 16:09:05 -07:00
Bee e6104cfd2c feat(desktop): capture application errors in telemetry (#12893)
* feat(desktop): capture application errors in telemetry

* fix(desktop): deduplicate errors across reporting layers

* fix desktop error telemetry fallback

* fix(desktop): skip idle transport-close reports and reuse http endpoint helper

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 15:42:28 -07:00
Bee 12431cd97b fix(cli): claim connector instance before socket connect (#12765)
* fix(cli): claim connector instance before socket connect

Prevent racing foreground or detached connector launches from
both opening socket-mode with the same bot token by exclusively
claiming the state file via tryClaimConnectorStateFile before
connecting, and exit with CONNECT_ALREADY_RUNNING_EXIT_CODE when
another live instance already holds the claim.

* serializes stale-generation replacement without a removable mutex

* lint

* fix

* base

* fix(cli): keep pre-claim Slack state files manageable

State files written by CLI versions that predate connector claiming have
no claimId, so requiring it in readConnectorState made a live legacy
connector invisible: stop deleted its state without stopping it, which
let the next connect open a second socket-mode connection with the same
bot token. Treat claimId as optional metadata; claiming itself never
relied on the validator.

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 15:41:19 -07:00
Bee 2b34b48ec6 fix(desktop): plugin package names (#12933) 2026-08-04 15:38:28 -07:00
Mikołaj Kondratek dc7eb755cf chore(telemetry): drop capture defs @cline/core owns, keep agent identity on late tool events (#12914)
* chore(telemetry): remove duplicate capture defs owned by @cline/core

The cline-core bundle layer (apps/vscode, which also compiles into the
cline-core.js that JetBrains runs) still carries event constants and
public capture methods inherited from the legacy architecture. Where
@cline/core now emits the same event, the bundle-layer twin is a second
capture path on the same telemetry service — which is how the
task.provider_api_error double-emission happened (cline/cline#12820,
follow-up to the removals in cline/cline#12818).

Removes 20 such methods and the EVENTS constants only they referenced:

- 15 whose signal @cline/core emits today (task lifecycle, tokens, tool
  and skill usage, auth start/success/failure, opt-out, workspace init,
  and summarize_task, which core replaced with task.compaction_*).
- 3 obsolete on both architecture lines: captureModelSelected (its
  model_selected signal survives as an action on
  captureOnboardingProgress), captureRulesMenuOpened, captureHostEvent.
- 2 whose trigger moved into core/sdk, so this layer can no longer
  observe them and re-wiring here would be wrong:
  captureWorkspacePathResolved (core already owns workspace.path_resolved)
  and captureGeminiApiPerformance (providers live in core; generic
  provider-timing events supersede it).

Deliberately NOT removed: capture methods with no caller here but a live
caller on legacy-extension. Those emit signals originating in this bundle
(webview UI, VS Code storage, host terminal, checkpoints, focus chain,
legacy-task migration), so core cannot emit them and the missing piece is
a call site on this line, not a redundant definition. They are the
SDK-parity backlog and are flagged as such in the file.

Verified against the JetBrains plugin repo: it references none of these
methods or event names, and no proto surface changes.

Also drops the unused TokenUsage interface, the taskTurnCounts and
taskToolCallCounts maps (only deleted methods wrote to them), and EVENTS
constants that were already orphaned before this change.

Tests that only exercised a removed method are gone; tests that used one
merely as a vehicle for provider/metadata assertions now use a surviving
method, so that coverage is preserved.

* fix(telemetry): keep agent identity on events dispatched after session teardown

A small share of task.tool_used events (~285 of 229k over 48h on
extension_variant=next) arrive without any agentId/agentKind/isSubagent
attributes. Root cause: AgentEventBridge.dispatchAgentEvent resolves
identity solely from the live-session map (AgentEvent metadata never
carries agentId in practice), and session teardown deletes the map entry
before the agent's run fully drains — dispose/stopSession paths can skip
or fail agent.shutdown() without aborting first. Late events from the
still-draining run then hit the session-map miss branch, which passed no
identity at all, so buildTelemetryAgentIdentity returned undefined and
the event was emitted bare.

Fix: snapshot the identity stamped on each session's events while the
session is registered (bounded FIFO map) and reuse it on a session-map
miss. Purely additive — no event is added, removed, or renamed; the
live-session and sub-agent paths emit byte-identical properties.
2026-08-04 22:44:19 +02:00
Bee accd7e5809 feat(sdk): add session initiation mode and lazy session persistence (#12807)
* feat(sdk): add session initiation mode and lazy session persistence

- Introduce top-level `StartSessionInput.mode` (`user`, `automation`, `subagent`, `team`) alongside `source`, so persisted history records both the client surface and how the session began; missing mode defaults to `user`.
- Make root-session persistence lazy: starting a runtime allocates the session ID in memory without creating a database row, manifest, or messages artifact. The first accepted user turn persists that same ID, so closing a runtime before any user turn leaves no empty history entry, and persistence never allocates a replacement ID for unknown sessions.
- Require automation runtime adapters to explicitly persist `mode: "automation"` for every run.
- Document the provenance model in `sdk/ARCHITECTURE.md`, update the VS Code session factory comment, and add tests for the automation runtime handlers.

* fix(sdk): persist automation trigger source as session provenance

The runtime adapters stopped writing the cron request source into the
session row when source became the client surface, which silently
dropped the spec-defined trigger label. Record it as
sessionHistoryOrigin.trigger instead, surface it in the messages-file
origin, and sort the new history-origin import in HubRuntimeHost.

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-04 13:29:36 -07:00
Bee 400ba47387 fix(llms): switch ollama provider package (#12892)
* fix(ollama): use native AI SDK provider

* fix(ollama): patch ollama-ai-provider-v2 wire contracts and lock them with real-provider tests

The pinned ollama-ai-provider-v2@4.0.1 breaks four native Ollama wire
contracts (review findings on #12892). Patch the package via Bun
patchedDependencies:

- omit think from the request when no reasoning setting resolves,
  instead of forcing think: false (lets the server default apply)
- surface mid-stream {"error": ...} objects as error stream parts with
  an error finish reason, instead of dropping them before a clean finish
- serialize attachment-only user turns as string content (""), not []
- include the documented tool_name field on tool result messages

Add ollama.wire.test.ts exercising doStream through the vendor module
against the real (patched) package with a stubbed fetch, asserting on
the actual /api/chat request bodies and parsed stream so regressions in
the dependency's request converter or stream parser are caught.

* fix ollama model list refresh

---------

Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-04 13:28:53 -07:00
Bee 3af23c1c4c fix(cli,core): stop duplicate connector launches (#12770)
* fix: prevent duplicate connector launches during doctor/connect

Mark connectors as starting before the hub daemon spawns so autostart
skips in-flight instances, and improve doctor process filtering with
container-aware namespace/cgroup checks plus detached log rotation.

* Update apps/cli/src/connectors/common.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* feat(hub): supervise connector processes

* feat(connectors): enable tools by default, and stop replaying the Slack greeting

Tools were on by default only for Telegram (via --no-tools); Slack, Discord,
Linear, Google Chat and WhatsApp all required an explicit --enable-tools. All
six now default to tools on and opt out with --no-tools.

--enable-tools still parses everywhere, including Telegram which never accepted
it, so deployed scripts, systemd units and persisted autostart arguments keep
working. Passing both resolves to the safer answer: --no-tools wins. This also
affects hub/webview starts, which never emitted a tools flag and so ran those
five connectors with tools off.

Slack no longer posts the "Connected to Cline." first-contact message. It was
gated on per-thread welcomeSentAt, so a connector restart or a cleared history
made the next user message look like first contact and replayed the greeting.
The host mechanism is unchanged and the other adapters still greet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(connectors): recover a thread whose session is wedged mid-run

A connector thread keeps a long-lived mapping to a hub session. When that
session's runtime still had a run in flight and no abort had been requested,
every message in the thread came back as "SessionRuntime.shutdown called while a
run is in progress" instead of an answer, and stayed that way until someone
cleared the binding by hand. Observed on the Cline Mom Slack bot after a stack
restart.

The connector host already recovers from a session the hub no longer knows
about: it forgets the mapping and replays the turn once against a fresh session.
This widens the trigger from "session not found" to "session cannot serve
another turn" via isUnusableSessionError, so a wedged runtime takes the same
path.

The shutdown error now carries a stable code (SessionRunInProgressError,
session_run_in_progress) so callers can recognise it structurally. The predicate
also matches on message, because an error reaching a connector has crossed the
hub's JSON boundary and arrives as a bare message - and because a host commonly
runs a hub and CLI of different versions. Ordinary run failures still propagate
untouched: replacing the session on those would hide real errors and drop the
conversation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(connectors): serialise turns that share a session

Answering "what happens if I message the bot in another thread while it is still
replying": channel threads were already independent, but DMs were not.

findBindingForThread deliberately reuses one binding — and therefore one runtime
session — for every message in a DM channel, so a DM stays one continuous
conversation. The turn queue, though, was keyed by thread id, and a DM thread id
carries the message timestamp. Two messages in flight in the same DM therefore
got two independent queues and ran concurrently against a single session, which
fails with "shutdown called while a run is in progress" or interleaves two
conversations in one session history.

The queue key now follows the same identity rule as the binding lookup, via
resolveThreadTurnQueueKey next to findBindingForThread so the two cannot drift.
DM messages queue behind each other on the shared session; channel threads keep
their own key and still run in parallel. Applied to all six adapters, which all
had the same mismatch.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(core): abort an in-flight run before tearing its session down

Where the Slack bot's "plugin-sandbox process exited (code=null, signal=SIGTERM)"
came from, and its "shutdown called while a run is in progress" sibling: both are
one event, a session released while a run was still going.

stopSession aborts the agent first "so shutdown can proceed", but callers that
reach shutdownSession or releaseSessionRuntime another way did not - hub
dispose() on a restart being the one that hurt. Without an abort the runtime
refuses to shut down, that error is rethrown from the cleanup, and the plugin
sandbox is SIGTERMed while tool calls are still pending, so those calls reject
with "plugin-sandbox process exited". A connector turn awaiting the run reports
whichever surfaced first instead of answering.

Both paths now abort and let the run drain before shutting the agent, runtime and
sandbox down, guarded on session.aborting so callers that already aborted do not
abort twice.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(connectors): stop announcing "Steering current task."

Every follow-up sent while the bot was replying added an acknowledgement line to
the thread, and the wording overstated what happens: the host treats delivery
"steer" the same as "queue", enqueuing the prompt for the session rather than
injecting it into the loop already running. The follow-up is now handed over
silently.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(core): retire a dead supervised entry before replacing it

A start arriving while an instance sat in backoff left the old entry's
restart timer live. The timer closes over the old entry object, so when
it fired it spawned a second process for the same (channel, instanceId)
- untracked by the supervisor's map, so invisible to list() and
unreachable by stop() - two connectors holding one bot token, which is
the exact failure supervision exists to prevent. Its exit handler then
kept reaping the live instance's state and rescheduling restarts.

The same window exists before the timer is even scheduled: the
exit-cleanup chain runs first, and a replacement made mid-chain would be
followed by a restart scheduled for the retired entry.

start() now retires a dead existing entry explicitly - cancel its timer,
mark it stopped, drop its exit listener. Both the timer callback and the
cleanup chain already stand down on "stopped", so one mark covers both
phases.

* fix(core): serialise supervisor start/stop and wait for stopped processes to die

Found by exercising a hub restart against a live webhook connector: the
new hub's boot reconnect restarts the adopted survivor - which suspends
inside stop() on the CLI cleanup - while the user's `cline connect`
arrives as connector.start. With no per-instance serialisation the two
starts interleaved across that suspension and both spawned. The map
tracked one process while the other lived on untracked, holding the
connector's webhook port; the tracked chain crash-looped on EADDRINUSE
through all five attempts and ended state=failed, while the ghost kept
running with no way to reach it through list() or stop().

Two changes:

- start/stop (and the backoff-restart spawn) now run under a per-
  instance-key promise queue, so one instance has exactly one lifecycle
  operation in flight. The exit-cleanup chain also stands down when its
  entry is no longer the one in the map.
- stop() waits for the process to actually die after SIGTERM (bounded,
  then SIGKILL) instead of returning while it still holds its listen
  port - the race that turned the double-spawn into a crash loop, and
  that could burn a backoff cycle on any webhook connector restart.

process.kill is now injectable (killProcess), which also stops the test
suite from signalling arbitrary real pids like 600 on the host.

Verified live: the same kill-hub-then-reconnect sequence now converges
to one tracked running process, with the concurrent user start
correctly answered "already running under the hub".

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
2026-08-04 13:28:18 -07:00
dependabot[bot] ce04e80909 chore(deps): bump rand (#11231)
Bumps the cargo group with 1 update in the /apps/examples/desktop-app/src-tauri directory: [rand](https://github.com/rust-random/rand).


Updates `rand` from 0.9.2 to 0.9.4
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/0.9.4/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/compare/rand_core-0.9.2...0.9.4)

---
updated-dependencies:
- dependency-name: rand
  dependency-version: 0.9.4
  dependency-type: indirect
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-08-04 12:53:15 -07:00
Saoud Rizwan 058c8c90a2 feat(desktop): ship a single universal macOS DMG instead of per-arch downloads (#12923)
Tauri's universal-apple-darwin target lipos the Rust binary but expects
sidecars to already be fat binaries, so build-sidecar-bin.ts now compiles
both Bun slices and merges them when the target triple is universal.
The publish workflow builds one universal bundle instead of a two-leg
matrix, verifies every Mach-O in the bundle carries both slices, and the
updater manifest points both darwin-aarch64 and darwin-x86_64 at the same
universal artifact so existing per-arch installs migrate automatically.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 12:42:55 -07:00
Saoud Rizwan 0f7e4b66ef Add themes to the CLI (#12899)
* Add user-selectable color themes to the CLI TUI

Adds a theme system to the interactive TUI (cline -i):
- New tuiTheme global setting persisted in global-settings.json
- Built-in themes: Auto (terminal-adaptive, default), Cline Dark,
  Cline Light, Tokyo Night, Gruvbox Dark, Nord, Dracula, Catppuccin
  Mocha, One Dark, Solarized Dark, Solarized Light
- /theme command, command palette entry, and a Theme row in
  /settings General tab, all opening a live-preview theme picker
- Named themes paint their background, default foreground, accents,
  syntax highlighting, and derived diff colors across the TUI
- CLINE_THEME env var overrides the persisted theme at startup

Closes #12872

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Widen theme picker dialog and label column

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Format theme picker

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Give each theme a descriptive picker blurb

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* Theme all main-surface components instead of static palette colors

The ask-question / tool-approval element, toasts, queued prompts,
autocomplete dropdown, chat error cards, searchable lists, and the
onboarding screens hardcoded the brand palette (act blue, selection
highlight, black-on-selection text) and fixed dark grays, so they
ignored the active theme.

- ResolvedTheme gains selection/textOnSelection; the selected-row text
  flips between black and white by WCAG contrast against the accent
- Inline ask-question / tool-approval, Toast, QueuedPrompts,
  AutocompleteDropdown, SearchableList, and chat error cards now use
  theme accents and the themed selection pair
- Onboarding screens derive subtle borders/details from the theme
  background instead of #333333/#555555, and use themed accents
- Dialog surfaces (settings, pickers, history) intentionally keep their
  static dark surface styling

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-04 12:26:00 -07:00
Bee f1c45b63c8 feat(desktop): add token usage warning colors (#12919)
* feat(desktop): add token usage warning colors

* context info
2026-08-04 11:17:20 -07:00
Deach d6d1c789b3 fix: correct Linux keybinding label in Plan/Act mode tooltip (#11067)
* fix: correct Linux keybinding label in Plan/Act mode tooltip

On Linux, event.metaKey maps to the Super (Win) key, not Alt.
detectMetaKeyChar was returning "Alt" for Linux, causing the Plan/Act
mode toggle tooltip to display "Alt+Shift+A" instead of "Super+Shift+A".

Fixes #11026

* fix: update platformUtils.spec.ts Linux test expectation to Super

---------

Co-authored-by: Dominic Cooney <dominic.cooney@cline.bot>
2026-08-04 10:44:18 -07:00
oab24413gmai 3e81006863 docs: capitalize GitHub in security note (#11088)
Co-authored-by: Mira Sato <275437409+oab24413gmai@users.noreply.github.com>
2026-08-04 10:11:29 -07:00
John Choi 8ea52a2eea fix(desktop): make agent header draggable (#12910)
* fix(desktop): make agent header draggable

* fix(desktop): keep read-only title draggable
2026-08-04 09:21:22 -07:00
John Choi 5ec2d47b21 refactor(ui): extract agent prompt queue (#12791)
* feat(ui): extract agent prompt queue

* fix(ui): keep prompt queue usable on failures

* fix(ui): surface prompt queue action failures

- report failed edit, steer, and remove callbacks inline as a row alert
- disable all queue actions while any action is in flight
- mark the busy row aria-busy and accept readonly item arrays

* fix(ui): preserve prompt queue failures

* chore(ui): drop unrelated formatting changes

* refactor(ui): style prompt queue with Tailwind

* style(ui): remove redundant prompt queue reset
2026-08-03 20:01:37 -07:00
Saoud Rizwan 46fcde0a96 ci(desktop): drop the Rust build cache from the code-signing job (#12898)
* ci(desktop): drop the Rust build cache from the code-signing job

The `build` job is the only one that can read the Apple Developer ID
certificate and the Tauri updater signing key, and it restored a
swatinem/rust-cache archive before running them. A restored cache archive
is attacker-controlled the moment the Actions cache is poisoned, which is
the pivot used against this repo's nightly workflow in Feb 2026 and the
reason actions/cache was stripped from the credential-bearing publish
jobs at the time. This workflow was added months later and reintroduced
the pattern. The updater key is the worst thing here to leak: it signs
every auto-update the installed desktop app accepts.

The cache was also not buying anything. Across the eight runs of this
workflow, seven logged "No cache found" on both matrix legs; only the run
32 minutes after another one hit, saving 1-3 minutes. A release cadence
measured in days does not outlive the entry under the repo's 10 GB LRU
eviction, so the steady state was a cold build regardless. Cold builds
took 5-7 minutes against a 90-minute timeout.

No behaviour change otherwise: the step had no id and no outputs, so
nothing referenced it.

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

* ci(desktop): trim the cache-removal comment to the constraint

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>

---------

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-03 19:16:23 -07:00
John Choi fbaa44be96 refactor(ui): extract agent ask question (#12790)
* feat(ui): extract agent ask question

* fix(ui): harden ask-question presentation

- dedupe repeated model-supplied options so keys stay stable
- mark pending items aria-busy to match the approval card
- expose the accent palette as overridable custom properties

* fix(ui): polish ask question feedback

* fix(ui): label follow-up question sections

* refactor(ui): style ask question with Tailwind
2026-08-03 18:55:12 -07:00
John Choi aec350bb9d refactor(ui): use Tailwind for shared components (#12719)
* refactor(ui): extract desktop approval card

* fix(ui): preserve approval card parity

* refactor(ui): keep approval labels fixed

* refactor(ui): use Tailwind for shared components

* test(ui): cover each Tailwind component source

* refactor(ui): migrate approval card styles

* fix(ui): preserve host and quick-action behavior

* fix(ui): preserve component hover behavior

* fix(ui): preserve selected option hover

* fix(ui): isolate embedded Tailwind contract

* fix(ui): reset approval button block padding

* chore(ui): bump preview package version
2026-08-03 18:28:57 -07:00
oab24413gmai 16129cf90a docs: capitalize GitHub in security note (#10723)
Co-authored-by: Mira Sato <275437409+oab24413gmai@users.noreply.github.com>
2026-08-03 17:34:27 -07:00
James Arlen 3520786f4a security: hygiene sweep — docs pin lifts, example next bump, workspace overrides (closes ~153 Vanta findings) (#12749)
* security: docs/examples/tooling hygiene sweep — lift fix-blocking pins, bump example next, workspace overrides

VMP 2026-07-30 quarterly run, PR 3 of the condensed worklist (closes ~153 Vanta findings).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* chore(deps): refresh lockfiles for security updates

* fix(deps): keep Discord on patched Undici 6

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Cline Agent <cline-agent@users.noreply.github.com>
2026-08-03 17:21:03 -07:00
Bee 8f0ff70215 chore(llms): upgrade to AI SDK 7 (#12891)
* chore(llms): upgrade to AI SDK 7

* fix(llms): include Codex provider during builds

* fix(llms): address AI SDK 7 runtime regressions
2026-08-03 17:10:41 -07:00
Saoud Rizwan 0619e5a016 fix(cli): deliver Telegram slash commands to the connector command host (#12888)
The @chat-adapter/telegram library intercepts any message whose leading
entity is a bot_command and routes it to slash-command handlers instead
of the mention/subscribed-message handlers. The Telegram connector
registered no onSlashCommand handler (unlike Discord and Slack), so
commands like /clear were consumed by the library and silently dropped.

Register a slash-command handler that rebuilds the originating chat
thread and forwards the original message text (preserving @bot
addressing for group chats) into the same turn pipeline as regular
messages, so connector commands reach the chat command host.

Fixes #12871

Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
2026-08-03 15:57:41 -07:00
Dominic Cooney 2a0dd197bf chore(vscode): remove dead next-gen model classifier (#12887)
Co-authored-by: Cline Agent <cline-agent@users.noreply.github.com>
2026-08-04 07:10:04 +09:00
Tomás Barreiro 82e3596f96 Add a script to do dev work on ACP (#12886) 2026-08-03 22:21:16 +02:00
Octopus 895ab53b78 fix(llms): inherit MiniMax default from models.dev (#11218)
Co-authored-by: Cline Agent <cline-agent@users.noreply.github.com>
2026-08-03 21:23:44 +02:00
Tran Binh Minh b8f51b9e55 fix(vscode): surface a clear error when a provider has no API key (#12859)
* fix(vscode): surface a clear error when a provider has no API key

A key-based provider with no API key sends the request without an Authorization header, and the provider's raw 401 reached the chat panel unclassified because reshapeErrorForWebview falls through to the raw message and ClineError's auth regexes do not match it. Rewrite the missing-Authorization-header case into actionable guidance naming the provider, alongside the existing model-not-found matcher. Matching is limited to the no-header signature so a present-but-wrong key is never relabelled as missing, and no preflight is added because authMethod misclassifies local providers and 175 of 179 builtins resolve keys from the environment.

* fix: don't name a fallback provider in the missing-key message

reshapeErrorForWebview defaults providerId to "cline" for its
ClineError-JSON branches, but state.activeProviderId() can be undefined —
the missing-credential message would then blame the cline provider for a
key it doesn't take. Keep the "cline" fallback for the JSON branches and
pass the raw id to the credential matcher, which now only names a provider
it was actually given.

---------

Co-authored-by: Mikołaj Kondratek <19799111+mkondratek@users.noreply.github.com>
2026-08-03 11:27:08 -07:00
Michael Gasperini 25dc89eab4 feat(vscode): recognize Chutes provider (#12068) 2026-08-03 11:16:09 -07:00
Mikołaj Kondratek 5fdd840d5f refactor(llms): classify typed AI SDK errors before the structural walk (#12814)
* refactor(llms): classify typed AI SDK errors before the structural walk

Add a typed pre-pass to classifyProviderError that recognizes real AI SDK
error instances via their symbol-based isInstance() guards: RetryError
unwraps to its last attempt, APICallError is judged on message/responseBody/
data with its typed statusCode as the sole authoritative status,
TypeValidationError on the payload in value, and any other AISDKError
recurses into its cause. The detection rules (overflow patterns, provider
codes, rate-limit vetoes, invalid-request status gate) are extracted into a
shared verdict function used unchanged by both the typed pass and the
existing structural walk, which remains the fallback for gateway-forwarded
plain-JSON payloads that only name an AI SDK error (ENG-2394).

* fix(llms): classify a RetryError by its final attempt even when untyped

When a RetryError's last attempt was not a typed AI SDK error, the typed
pre-pass fell back to structurally walking the whole wrapper, letting
signals from earlier (retried-away) attempts veto or fake the final
attempt's verdict — e.g. a retryable 429 on attempt one vetoing a plain
overflow rejection on the final attempt. Walk the final attempt alone
instead; a RetryError with no recorded attempts still falls back to the
plain structural walk.

* fix(llms): gate typed APICallError verdicts on the authoritative statusCode

verdictFromSignals checks the explicit context_length_exceeded code before
the rate-limit veto and the invalid-request status gate, so a typed
APICallError with statusCode 429 or 500 whose body echoed that code was
still classified as an overflow, contradicting the branch's contract that
the typed statusCode is the sole authoritative status. Gate the whole
payload verdict on the typed statusCode first (absent a statusCode the
payload still decides), and cover the explicit-code case at 429/500/400
with real instances.
2026-08-03 06:40:40 -07:00
Mikołaj Kondratek cdcaa74422 feat(sdk): detect and recover from context-window overflow errors (#12804)
* feat(sdk): detect and recover from context-window overflow errors

Port of the legacy arch's context-window-exceeded handling to the SDK
arch (the SDK arch previously surfaced these as raw unclassified stream
errors with no recovery; see ENG-2394 root-cause investigation).

- llms: new classifyProviderError() walks the raw provider error
  structure (AI SDK wrappers, gateway value.error_message, responseBody,
  cause chains) and classifies it before extractErrorMessage flattens
  it. Reuses the legacy detectors' message patterns with rate-limit
  vetoes and an invalid-request status gate.
- shared: ProviderErrorClass union; errorClass on the model finish
  event, run-failed event, runtime snapshot, and prepare-turn contexts.
- core: prepare-turn overflowRecovery flag forces a compaction that
  bypasses the token-estimate trigger (the estimate just proved wrong)
  and runs the deterministic basic strategy directly, so recovery never
  depends on another successful LLM request. New overflow_recovery
  compaction mode in status notices and compaction telemetry.
- agents: on a classified overflow the runtime force-compacts and
  retries once per run, emitting a status notice. Terminal states fail
  with actionable messages instead of raw provider dumps: nothing to
  compact (first-prompt overflow), no prepare-turn pipeline, or a retry
  that still overflows. The doomed request is not re-sent when forced
  compaction cannot shrink the transcript.
- telemetry: task.provider_api_error gains errorClass and
  task.provider_stream_failed gains error_class, populated from the
  same classification, so context-overflow failures become countable.

* fix(core): keep overflow-recovery compaction deterministic with custom compactors

A session-supplied compaction.compact previously took precedence over
the overflow_recovery basic-strategy branch, so an LLM-backed custom
compactor could hit the same context overflow mid-recovery. The custom
compactor still gets first shot (it sees mode overflow_recovery and
owns its transcript invariants), but if it throws or declines, basic
compaction now runs so recovery never depends on another successful
LLM request. Cancellation still propagates.

* fix(core): fall back to basic compaction when a custom compactor does not shrink during overflow recovery

A custom compactor that returns unchanged or larger messages would
previously satisfy the recovery branch, and the runtime would then
reject the retry as non-shrinking and fail terminally even though
basic compaction could still prune the transcript. Recovery now
treats a non-shrinking custom result like a decline and runs basic
compaction.

* fix(core): hold custom overflow-recovery compaction to the recovery token target

A custom compactor result that was only marginally smaller than the
input passed the shrink check, skipped the basic fallback, and spent
the run's single recovery retry on a request that still could not fit.
The custom result is now accepted only when it is strictly smaller AND
within the recovery token target basic compaction aims for; otherwise
basic compaction runs.

* fix(core): reject empty custom compaction results during overflow recovery

An empty transcript from a custom compactor passed both the shrink and
token-target checks (trivially smaller, zero tokens) and suppressed the
basic fallback, so the retry would have been sent without the request
it was supposed to re-send. The acceptance bar now covers the full
input space in one predicate: non-empty AND strictly smaller AND within
the recovery token target.

* feat(core): expose the turn abort signal to custom compactors

CoreCompactionContext now carries the prepare-turn abort signal, so a
custom compact implementation that calls a model or external service
can observe cancellation instead of blocking the turn (including the
overflow-recovery path) on a stalled request. Builtin strategies
already received the signal via providerConfig; this closes the gap
for custom compactors across auto, manual, and recovery modes.

* fix(sdk): classify provider errors from registered ApiHandler models

Registered handlers (VS Code LM and any other host-supplied provider)
reach the runtime through createAgentModelFromApiHandler, which flattens
failures to a message string — so context-window rejections on that path
were never classified and never entered overflow recovery.

- The adapter now classifies at its own error boundary, where the raw
  error is still structured (status codes, response bodies), for both
  thrown errors and failed done chunks. Aborts stay unclassified.
- The runtime falls back to classifying the finish message when a model
  supplies no class, so custom AgentModel implementations are covered
  too.
- Hold the custom-compactor acceptance check to token estimates on both
  sides instead of mixing serialized length with a token target, and
  document why the runtime's shrink backstop keeps a serialized-size
  proxy (the shared estimator is linear in characters, so the verdict is
  identical) with a TODO to surface real estimates from prepareTurn.
- Drop the now-unused errorClass parameter from captureProviderApiError:
  #12820 removed core's capture site, so host adapters own that event.

* test(core): reuse the handler harness for the overflow classification case

The hand-rolled throwing generator had no yield, which biome's
correctness/useYield rejects as an error (the repo's lint gate runs on
sdk/ and apps/, and biome does not honor the eslint require-yield
directive the existing harness carries). fakeHandler now accepts the
error to throw, so the new case reuses it instead.
2026-08-03 09:03:22 +02:00
Mikołaj Kondratek 5acc98474a fix(mcp): refresh lists on list_changed notifications instead of toasting (#12619)
* fix(mcp): refresh lists on list_changed notifications instead of toasting

Servers emit notifications/tools/list_changed in bursts (a toolset change
or shutdown can produce a dozen at once), and the fallback notification
handler surfaced every one of them as a host toast, flooding the user
with identical messages (ENG-2298, found testing the JetBrains IDE MCP
server integration).

Handle tools/resources/prompts list_changed notifications by refreshing
the corresponding cached lists, debounced 300ms per server and list
kind, then pushing the update through notifyWebviewOfServerChanges() so
the webview and the SDK session tool-list check pick it up. Downgrade
remaining unhandled notification types to logger output.

* fix(mcp): guard list_changed refreshes against races and failed fetches

Address review: serialize per-key refreshes by chaining onto any
in-flight one, so overlapping fetches can't complete out of order and
publish a stale list. Make the fetch helpers return undefined on
failure (instead of an empty list) so the refresh path can keep the
previous cached list and skip the webview notification, rather than
erasing valid entries on a transient error; connect-time call sites
keep their old empty-list fallback.

* fix(mcp): drop in-flight list refresh when the connection was replaced

Address review: refreshChangedList captured the connection object before
awaiting the list fetches, so a reconnect mid-fetch wrote the result to
the removed connection while the replacement kept its own state. Re-check
connection identity after the fetches and drop the result when it
changed — the replacement fetched fresh lists at connect time, after the
change that produced the notification, so the in-flight result is older.

* fix(mcp): retry failed list refreshes and publish state after reconnect

Address review. A list_changed notification consumes the server's change
signal, so a transiently failed refresh left the cached list stale until
the next notification; retry with exponential backoff (1s/2s/4s, max 3)
per server and list kind, with a fresh notification superseding any
pending retry. Also publish server state after a successful streamable
HTTP reconnect: connectToServer() loads fresh lists but never sent them,
leaving the webview on 'connecting' with pre-reconnect capabilities.

* fix(mcp): don't restart a live connection when post-reconnect publish fails

Address review: the post-reconnect notifyWebviewOfServerChanges() sat
inside the connect retry loop's try block, so a publication failure
(e.g. a settings file read error) was treated as a transport failure
and re-ran connectToServer() against the already-live connection,
leaking its client/transport. Publication now happens outside the
connect try/catch and only logs on failure.

* fix(mcp): drop superseded in-flight list refreshes instead of publishing

Address review: a newer list_changed notification queued its refresh
behind one already in flight without invalidating it, so the older run
could briefly publish an obsolete list (and churn the SDK session)
before the newer refresh corrected it. Each schedule now starts a new
generation per server+kind; a run whose generation is no longer current
skips fetching (when caught early), drops its result before publishing,
and doesn't schedule retries — the superseding refresh covers it.

* fix(mcp): harden list refresh and reconnect publication paths

Address review (post-reconnect publish failure leaving consumers stuck
on 'connecting' with stale lists) plus an adversarial pass over the
whole change to close the remaining gaps in one batch:

- Retry publications bounded (publishServerChanges) after a successful
  reconnect AND in both terminal disconnected paths, which are equally
  terminal; never throw from handleError, whose promise transport.onerror
  discards. Guard the stdio/SSE onerror publishes the same way.
- Treat an undeclared capability or a method-not-found answer as an
  authoritatively empty list instead of a retryable failure, so servers
  without e.g. resources/templates/list don't burn the full retry ladder
  on every list_changed notification.
- Retry when the fetch succeeded but the webview publish failed: the
  cache is updated but consumers haven't seen it.
- Cap debounce deferral at 2s so a sustained sub-300ms notification
  stream can't starve the refresh indefinitely.
- Cancel pending refresh timers in deleteConnection; return 'skipped'
  (not 'failed') when a fetch failure coincides with connection
  teardown or supersession, so no retry fires against a replacement
  connection that already fetched fresh lists.
- Clear the pre-existing toolListChangeDebounceTimer in dispose().

* fix(mcp): supersede in-flight refreshes during connection teardown

Address review: deleteConnection removes the connection from
this.connections only after awaiting transport/client close, so a list
refresh completing inside that window passed its identity check and
published state for a connection being torn down. Bump the per-key
generation at the start of deleteConnection so any in-flight refresh is
superseded and drops its result; bumping (never resetting) keeps
generations monotonic across reconnects.

* fix(mcp): close reconnect-retry and teardown-publication races

Address review (cline-cloud):

1. The streamable HTTP reconnect loop revalidated only after the first
   backoff. Later retries could resurrect a server removed or disabled
   from settings during a delay, or displace a replacement connection
   another path had installed — connectToServer() drops a same-name
   connection without closing it, leaking its transport. The loop now
   revalidates before every attempt: it aborts when a live replacement
   exists (our own original connection and the 'disconnected' husk left
   by our own failed attempt don't count) or when fresh-read settings no
   longer define the server as enabled (isStillWanted callback; a
   settings read failure keeps the chain alive).

2. deleteConnection removed the connection from this.connections only
   after awaiting transport/client close, so a publication passing its
   suspension points inside that window could still serialize and
   publish the dying connection's state. The connection is now removed
   from published state before the close handshake is awaited.

The exhausted-retries test's partial-connection mock now carries status
'disconnected', matching what connectToServer's error path actually
leaves behind — that status is what distinguishes our own husk from a
live replacement.

* fix(mcp): don't displace an OAuth-required replacement during reconnect retries

Address review: the retry loop's replacement guard treated every
'disconnected' connection as our own failed-connect husk. An
OAuth-required connection is also 'disconnected' but retains its
client, transport, and authProvider for authentication — a retry that
displaced it would orphan that session and clobber the pending auth
state. Distinguish by client presence: the husk's creation sites set
client: null, so a 'disconnected' connection holding a client is a
replacement and aborts the retry chain.

* fix(mcp): distinguish OAuth replacements by flag, not client presence

Address review: an ordinary post-registration connect failure leaves a
'disconnected' connection with its (already-closed) client still
attached, so the client-presence check classified it as an OAuth-style
replacement — aborting the reconnect chain after a single failure,
including our own retries. Discriminate on server.oauthRequired
instead: only the OAuth-required connection retains live
client/transport/authProvider state worth protecting; ordinary failed
connections closed their client before being marked disconnected, so
retrying past them displaces nothing live. The exhausted-retries test
mock now carries the real husk shape (closed client attached) to pin
this regression.

* test(mcp): cover retry succeeding after a failed attempt's registered connection

Requested in review: the guard must recognize the 'disconnected'
connection a failed non-OAuth connectToServer() leaves behind (closed
client still attached) as our own attempt, and the following retry must
proceed and succeed.

* fix(mcp): don't retry reconnects with a config settings no longer define

Address review: a retry reconnects with the config captured at
connection creation, so if the user changed the server's config during
a backoff delay (and the watcher's reconnect with the new config
failed, leaving a disconnected husk our guard rightly retries past),
the retry would resurrect the obsolete URL/headers/command — and a
successful stale connection would contradict settings until the next
file touch. isStillWanted now also compares the captured config against
current settings via configsRequireRestart (connection-relevant fields
only), aborting the chain when they differ: the settings watcher owns
reconnection after a config change.
2026-08-03 07:51:04 +02:00
Bee 53a5266239 feat(desktop): show token usage in input toolbar (#12803)
* feat(desktop): show token usage in input toolbar

Load per-model context window sizes from the provider catalog and
pass the active model's limit down to ChatInputBar. Render a token
ring that visualizes current token usage against the model's context
window, and hydrate token usage plus cumulative cost from messages
and chat_usage events so the indicator stays accurate across turns
and session reloads. Add tests covering the ring rendering and usage
hydration.

* bigger ring

* move submit button to input box

* fix

* add cost tracker

* fix

* fix queued turn cost tracking
2026-08-02 17:19:33 +02:00
Saoud Rizwan 1654517614 ci(desktop): gate desktop publish secrets behind PublishDesktop environment (#12854)
* ci(desktop): gate desktop publish secrets behind PublishDesktop environment

The Apple signing/notarization and Tauri updater secrets were repository
secrets, readable by any workflow in the repo and by anyone with push
access via a branch carrying a modified workflow. Move them behind the
PublishDesktop environment, which requires reviewer approval and
restricts deployments to main.

The build job now declares the environment, so those secrets are readable
only there and only after an approval. Add a preflight check because a
missing secret fails dangerously rather than loudly: Tauri silently skips
code signing when APPLE_CERTIFICATE is empty and skips notarization when
APPLE_API_KEY is empty, so a misconfigured environment would still
publish an unsigned, un-notarized bundle. Only a missing updater key was
already caught, by the .sig check in Collect artifacts.

validate stays ungated so a bad tag fails in seconds rather than after an
approval, matching the ungated-build/gated-publish split in
ext-vscode-ab-package. The shared Slack and telemetry secrets stay where
they are; scoping them to this environment would silently empty them in
the CLI, SDK, and extension publish workflows.

* ci(desktop): verify signing secrets are not repository-scoped

The preflight added in the previous commit checks that the signing
secrets are non-empty, which proves presence but not scope, and then
reported that they had resolved from PublishDesktop. An environment-gated
job resolves repository and organization secrets too — environment values
merely take precedence — so a credential left at repository level would
pass that check while the message claimed the migration had worked. This
workflow already demonstrates it: the gated build job reads the shared
Slack and telemetry secrets, none of which are on the environment.

Add the complementary check to validate, which declares no environment: a
signing secret that resolves there can only be repository- or
organization-scoped, so it fails the run and names the offenders. Neither
check establishes provenance alone; together they do. validate is
ungated, so a misplaced secret now fails before the approval rather than
after it.

Also drop the provenance claim from the build message and correct the
skill doc, which stated that a repository-level secret would be invisible
to the gated job.

Reported by greptile on #12854.
2026-08-02 01:55:24 -07:00
Saoud Rizwan bbfcbcd31d chore(vscode): bump to 4.1.3 for stable release 2026-08-01 22:11:03 -07:00
Saoud Rizwan 102ef1ab84 chore(desktop): release v0.0.8 2026-08-01 21:53:13 -07:00
889 changed files with 168265 additions and 26237 deletions
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Bring back a copy button on turn-final response rows, under a new subtle "Completed" / "Plan" header
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Hide the "View Changes" button on completion rows until there are actually changes to show, instead of rendering it faded and disabled. Turns that changed nothing, non-git workspaces, and repos without commits no longer show a dead button with a misleading tooltip.
+74 -24
View File
@@ -1,28 +1,34 @@
---
name: publish-desktop
description: Use when preparing, tagging, and publishing a Cline Code desktop app (apps/examples/desktop-app) release. Guides changelog drafting, version bumps in package.json + tauri.conf.json, desktop-vX.Y.Z tags, and the desktop-publish GitHub workflow that builds, signs, notarizes, and updates the auto-update feed.
description: Use when preparing, tagging, and publishing a Cline Code desktop app (apps/examples/desktop-app) release — stable (desktop-vX.Y.Z from main) or beta (desktop-vX.Y.Z-beta.N from desktop-experimental, shipped as the side-by-side "Cline Code Beta" app). Guides changelog drafting, version bumps in package.json + tauri.conf.json, tagging, and the desktop-publish GitHub workflow that builds, signs, notarizes, and updates the per-channel auto-update feed.
---
# Desktop App Release
Use this skill when the user asks to release the desktop app, publish Cline Code, bump the desktop version, create a `desktop-vX.Y.Z` tag, or trigger the desktop publish workflow.
Use this skill when the user asks to release the desktop app, publish Cline Code, cut a desktop beta, bump the desktop version, create a `desktop-vX.Y.Z` (or `desktop-vX.Y.Z-beta.N`) tag, or trigger the desktop publish workflow.
> Working directory: run every command below from the repository root.
Desktop releases are macOS-only today (signed + notarized DMG for Apple Silicon and Intel) and are built entirely in GitHub Actions — there is no local publish path. Installed apps discover new releases automatically through the Tauri updater, so publishing a release is what ships the update to every existing user.
Desktop releases are macOS-only today (a single signed + notarized universal DMG that runs natively on both Apple Silicon and Intel) and are built entirely in GitHub Actions — there is no local publish path. Installed apps discover new releases automatically through the Tauri updater, so publishing a release is what ships the update to every existing user **on that channel**.
## Release contract
- Two channels, one workflow (`channel` input on `desktop-publish.yml`):
- **stable** — tag `desktop-vX.Y.Z` (no suffix; the workflow rejects prerelease suffixes on this channel), cut from `main`, feeds the rolling `desktop-latest` release, ships as "Cline Code".
- **beta** — tag `desktop-vX.Y.Z-beta.N`, cut from `desktop-experimental`, feeds the rolling `desktop-beta` release, ships as "Cline Code Beta" (separate bundle identifier `bot.cline.app.beta`; installs side by side with stable). Built with the extra `src-tauri/tauri.beta.conf.json` overlay. Process background: `apps/examples/desktop-app/EXPERIMENTAL.md`.
- Version sources (must match each other and the tag): `apps/examples/desktop-app/package.json` and `apps/examples/desktop-app/src-tauri/tauri.conf.json`. (`src-tauri/Cargo.toml` has its own version but `tauri.conf.json` overrides it; no need to touch it.)
- Release tag: `desktop-vX.Y.Z`, where `X.Y.Z` matches both version files.
- Release prep includes approved release notes, the version bumps, and an `apps/examples/desktop-app/CHANGELOG.md` update.
- Publish path: `.github/workflows/desktop-publish.yml` (workflow_dispatch, requires the tag to exist, point at the checked-out commit, and be reachable from `origin/main`).
- The workflow creates the `desktop-vX.Y.Z` GitHub release (DMGs + updater artifacts + `latest.json`) and refreshes the rolling `desktop-latest` release, which is the static auto-update feed every installed app polls. Never delete the `desktop-latest` release or tag.
- The changelog's top `## X.Y.Z` section is extracted verbatim into the GitHub release body, the Slack announcement, and the updater manifest notes.
- Beta versions are prereleases of the **next** stable: stable `0.0.13` → betas `0.0.14-beta.1`, `-beta.2`, … Once a stable ≥ the beta base ships, the next beta bumps its base (`0.0.15-beta.1`).
- Release prep includes approved release notes, the version bumps, and an `apps/examples/desktop-app/CHANGELOG.md` update — committed on `main` for stable, on `desktop-experimental` for beta.
- Publish path: `.github/workflows/desktop-publish.yml` (workflow_dispatch, requires the tag to exist, point at the checked-out commit, and be reachable from the channel's branch — `origin/main` for stable, `origin/desktop-experimental` for beta).
- **Both channels dispatch from `main`.** This is a security invariant, not a convenience: the run executes `main`'s workflow copy and only the checkout points at the tag, so the signing-secret gates (the `github.ref == main` check and the PublishDesktop environment's main-only deployment-branch policy) hold for beta too. Never add `desktop-experimental` to the PublishDesktop deployment-branch policy.
- The workflow creates the tag's GitHub release (universal DMG + updater artifact + `latest.json`; marked prerelease for beta) and refreshes the channel's rolling feed release, which is the static auto-update feed every installed app on that channel polls. Never delete the `desktop-latest` or `desktop-beta` release or tag.
- The changelog's `## <version>` section (exact-match, not "topmost") is extracted verbatim into the GitHub release body, the Slack announcement, and the updater manifest notes.
- Always ask before pushing commits or tags.
## Workflow
0. Ask which channel this release is for — **stable or beta** — if the user has not said. Everything below branches on it; never guess.
1. Gather context.
```sh
@@ -35,10 +41,15 @@ node -p "require('./apps/examples/desktop-app/src-tauri/tauri.conf.json').versio
If there is no `desktop-v*` tag yet, this is the first release; use the desktop app's first commit as the baseline and say the baseline is inferred.
For a **beta** release, work on `desktop-experimental` (check out `origin/desktop-experimental`; merge `origin/main` into it first if it is behind — see EXPERIMENTAL.md for the conflict policy) and read the version files from that branch. The last-tag baseline is the newest `desktop-v*` tag of either channel that is an ancestor of the branch.
2. Collect release commits.
```sh
# stable (on main):
git log <last-desktop-tag>..HEAD --oneline --no-merges -- apps/examples/desktop-app sdk/packages .github/workflows/desktop-publish.yml
# beta (on desktop-experimental):
git log <last-desktop-tag>..origin/desktop-experimental --oneline --no-merges -- apps/examples/desktop-app sdk/packages .github/workflows/desktop-publish.yml
```
The sidecar bundles `@cline/core` and friends from the monorepo, so SDK changes ship inside the desktop app too. Fold user-visible SDK changes (providers, models, behavior fixes) into the notes; skip purely internal ones.
@@ -49,13 +60,15 @@ Flat bullet list, user-facing language. Present the draft and wait for approval
4. Decide the version bump.
Ask whether this is patch, minor, major, or an explicit version. Do not guess if the user has not made it clear.
Stable: ask whether this is patch, minor, major, or an explicit version. Do not guess if the user has not made it clear.
5. Update release files.
Beta: apply the versioning rule — base = next stable version, increment `N` (`0.0.14-beta.1``0.0.14-beta.2`; after stable `0.0.14` ships, next is `0.0.15-beta.1`). Confirm the computed version with the user.
5. Update release files (on `main` for stable, on `desktop-experimental` for beta).
- `apps/examples/desktop-app/package.json` → new version
- `apps/examples/desktop-app/src-tauri/tauri.conf.json` → same version
- Prepend `## X.Y.Z` (no date) to `apps/examples/desktop-app/CHANGELOG.md` with the approved notes.
- Prepend `## X.Y.Z` (no date; `## X.Y.Z-beta.N` for beta) to `apps/examples/desktop-app/CHANGELOG.md` with the approved notes.
6. Verify before committing.
@@ -77,40 +90,73 @@ Ask before pushing the release commit, then before creating and pushing the tag:
```sh
git push origin HEAD
git tag -a desktop-vX.Y.Z -m "Desktop vX.Y.Z"
git tag -a desktop-vX.Y.Z -m "Desktop vX.Y.Z" # beta: desktop-vX.Y.Z-beta.N / "Desktop vX.Y.Z-beta.N"
git push origin refs/tags/desktop-vX.Y.Z
```
8. Publish.
The release commit must be on `main` and the tag pushed first.
The release commit must be on the channel's branch (`main` for stable, `desktop-experimental` for beta) and the tag pushed first. Dispatch from `main` for **both** channels (see the release contract for why).
```sh
gh workflow run desktop-publish.yml -f git_tag=desktop-vX.Y.Z -f confirm_publish=publish
# stable:
gh workflow run desktop-publish.yml --ref main -f git_tag=desktop-vX.Y.Z -f channel=stable -f confirm_publish=publish
# beta:
gh workflow run desktop-publish.yml --ref main -f git_tag=desktop-vX.Y.Z-beta.N -f channel=beta -f confirm_publish=publish
gh run list --workflow=desktop-publish.yml --limit=1 --json url,status,conclusion,createdAt --jq '.[0]'
```
The workflow builds both architectures in parallel (aarch64 native, x86_64 cross-compiled), signs with the Developer ID certificate, notarizes with the App Store Connect API key, signs updater artifacts with the Tauri updater key, creates the GitHub release, refreshes `desktop-latest/latest.json`, and posts to Slack. Notarization typically adds 210 minutes.
**The run pauses for approval.** `validate` runs immediately, then the `build`
job waits on the `PublishDesktop` environment until a required reviewer approves
it — the run sits in `waiting`, which is expected, not a hang. Approve it in the
run's web UI ("Review deployments"), or:
If the workflow fails on missing credentials, see "Repo secrets (one-time setup)" below.
```sh
gh api repos/cline/cline/actions/runs/<run-id>/pending_deployments \
--method POST -f state=approved -f comment="desktop vX.Y.Z" \
-F 'environment_ids[]=19152605990' # PublishDesktop
```
Nothing after `validate` runs — and no signing key is readable — until then.
The workflow builds one universal macOS bundle (`tauri build --target universal-apple-darwin` lipos the aarch64 + x86_64 Rust binaries; the Bun sidecar is lipo'd by `build-sidecar-bin.ts`; beta adds the `tauri.beta.conf.json` overlay), verifies every Mach-O in the bundle carries both slices and that the compiled binary embeds exactly its own channel's feed URL, signs with the Developer ID certificate, notarizes with the App Store Connect API key, signs the updater artifact with the Tauri updater key, creates the GitHub release (prerelease for beta), refreshes the channel's feed (`desktop-latest/latest.json` or `desktop-beta/latest.json`), and posts to Slack. Notarization typically adds 210 minutes.
If the workflow fails on missing credentials, see "Publish secrets (one-time setup)" below.
9. Verify the update feed after the run succeeds.
```sh
curl -sL https://github.com/cline/cline/releases/download/desktop-latest/latest.json | head -30
curl -sL https://github.com/cline/cline/releases/download/desktop-latest/latest.json | head -30 # stable
curl -sL https://github.com/cline/cline/releases/download/desktop-beta/latest.json | head -30 # beta
```
The `version` field must be the new release and both `darwin-aarch64` and `darwin-x86_64` URLs must point at the new `desktop-vX.Y.Z` assets. Installed apps pick the update up on next launch or within 2 hours.
The `version` field must be the new release and both `darwin-aarch64` and `darwin-x86_64` entries must point at the same new universal `.app.tar.gz` asset under the release tag (each slice of the fat binary requests its own arch key at runtime, so both keys serve the one artifact). Installed apps on that channel — including older per-arch installs — pick the update up on next launch or within 2 hours.
After a **beta** publish, also confirm the stable feed was not touched: `desktop-latest/latest.json` must still serve the previous stable version. (The workflow guards this fail-closed, but it is cheap to verify and catastrophic to miss — the updater comparator is a plain semver "newer than", so a beta manifest on `desktop-latest` would auto-update every stable install onto the beta.)
10. Final response.
Report: version, tag, changelog updated, commit hash, what was pushed, workflow URL, and the feed verification result.
Report: channel, version, tag, changelog updated, commit hash, what was pushed, workflow URL, and the feed verification result.
## Repo secrets (one-time setup)
## Publish secrets (one-time setup)
The workflow needs these repository secrets. The Apple ones come from the same
Apple Developer account used for manual signing (see the app README's "macOS
signing & notarization" section for how to obtain them):
These live on the **`PublishDesktop` environment**, not at repository level, so
only the `build` job can read them and only after an approval. Set them under
Settings → Environments → PublishDesktop → Environment secrets. The environment
also restricts deployments to `main` and requires a reviewer.
Adding one of these as a *repository* secret is the common mistake. The build
would still succeed — an environment-gated job resolves repository secrets too,
with environment values simply taking precedence — so the credential would sit
repo-wide while everything looked fine. `validate` therefore fails the run if any
of them resolves in a job with no environment. If you hit that, delete the
repository-level copy rather than duplicating it.
If a secret is missing everywhere, the preflight in `build` fails the run naming
the missing entries. The Apple values come from the same Apple Developer account
used for manual signing (see the app README's "macOS signing & notarization"
section for how to obtain them):
| Secret | Value |
| --- | --- |
@@ -124,4 +170,8 @@ signing & notarization" section for how to obtain them):
| `TAURI_SIGNING_PRIVATE_KEY_PASSWORD` | Password for that key |
The Slack + telemetry secrets (`SLACK_RELEASE_BOT_TOKEN`, `TELEMETRY_SERVICE_API_KEY`,
OTEL settings) are shared with the CLI publish workflow and already configured.
`ERROR_SERVICE_API_KEY`, OTEL settings) are shared with the CLI, SDK, and extension
publish workflows and already configured. **Do not move these into
`PublishDesktop`** — scoping them to this environment empties them in every other
publish workflow, silently, with no error beyond missing telemetry and a failed
Slack post.
+363 -45
View File
@@ -11,6 +11,14 @@ on:
description: 'Type "publish" to confirm the desktop release.'
required: true
type: string
channel:
description: "Release channel"
required: true
type: choice
options:
- stable
- beta
default: stable
permissions:
contents: read
@@ -30,7 +38,49 @@ jobs:
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
channel: ${{ steps.version.outputs.channel }}
feed: ${{ steps.version.outputs.feed }}
product: ${{ steps.version.outputs.product }}
steps:
# Companion to the presence check in `build`, and the half that actually
# establishes scope. This job declares no environment, so a signing secret
# that resolves here can only be a repository or organization secret —
# meaning it is still readable by every workflow in the repo, which is the
# thing the PublishDesktop environment exists to prevent. Neither check
# proves provenance alone (an environment-gated job resolves repository
# secrets too, with environment values merely taking precedence), but
# together they do: empty here plus present in `build` means the value came
# from the environment.
- name: Verify signing secrets are not repository-scoped
env:
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
APPLE_API_KEY_CONTENT: ${{ secrets.APPLE_API_KEY_CONTENT }}
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
run: |
unscoped=()
for name in APPLE_API_ISSUER APPLE_API_KEY APPLE_API_KEY_CONTENT \
APPLE_CERTIFICATE APPLE_CERTIFICATE_PASSWORD APPLE_SIGNING_IDENTITY \
TAURI_SIGNING_PRIVATE_KEY TAURI_SIGNING_PRIVATE_KEY_PASSWORD; do
[ -z "${!name}" ] || unscoped+=("$name")
done
if [ ${#unscoped[@]} -gt 0 ]; then
echo "These signing secrets resolve in a job with no environment:"
printf ' - %s\n' "${unscoped[@]}"
echo
echo "That means they are still repository or organization secrets and"
echo "are readable by any workflow in this repo. Delete them at that"
echo "level and add them to the PublishDesktop environment instead."
exit 1
fi
echo "No signing secret resolves outside the PublishDesktop environment."
- name: Checkout code
uses: actions/checkout@v4
with:
@@ -42,11 +92,41 @@ jobs:
id: version
env:
TAG: ${{ github.event.inputs.git_tag }}
# inputs.* (not github.event.inputs.*) so the declared default
# applies when an API dispatch omits the channel input entirely.
CHANNEL: ${{ inputs.channel }}
run: |
if ! printf "%s\n" "$TAG" | grep -Eq '^desktop-v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
echo "git_tag must look like desktop-vX.Y.Z, got: ${TAG}"
exit 1
fi
# Fail-closed channel mapping: every channel defines its tag shape,
# its ancestry source, its feed, and its product name, and an unknown
# channel dies here. The feed assignment is the load-bearing one —
# the updater comparator is a plain semver "newer than", so a beta
# manifest landing on desktop-latest would auto-update every stable
# install onto the beta. The stable regex rejects prerelease
# suffixes for the same reason.
case "$CHANNEL" in
stable)
if ! printf "%s\n" "$TAG" | grep -Eq '^desktop-v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "stable git_tag must look like desktop-vX.Y.Z with no suffix, got: ${TAG}"
exit 1
fi
ANCESTOR_REF=main
FEED=desktop-latest
PRODUCT="Cline Code"
;;
beta)
if ! printf "%s\n" "$TAG" | grep -Eq '^desktop-v[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+$'; then
echo "beta git_tag must look like desktop-vX.Y.Z-beta.N, got: ${TAG}"
exit 1
fi
ANCESTOR_REF=desktop-experimental
FEED=desktop-beta
PRODUCT="Cline Code Beta"
;;
*)
echo "unknown channel: ${CHANNEL}"
exit 1
;;
esac
VERSION="${TAG#desktop-v}"
PACKAGE_VERSION=$(node -p "require('./apps/examples/desktop-app/package.json').version")
@@ -69,29 +149,91 @@ jobs:
exit 1
fi
git fetch origin +main:refs/remotes/origin/main
if ! git merge-base --is-ancestor "$HEAD_COMMIT" origin/main; then
echo "${TAG} is not reachable from origin/main"
git fetch origin "+${ANCESTOR_REF}:refs/remotes/origin/${ANCESTOR_REF}"
if ! git merge-base --is-ancestor "$HEAD_COMMIT" "origin/${ANCESTOR_REF}"; then
echo "${TAG} is not reachable from origin/${ANCESTOR_REF}"
exit 1
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "channel=${CHANNEL}" >> "$GITHUB_OUTPUT"
echo "feed=${FEED}" >> "$GITHUB_OUTPUT"
echo "product=${PRODUCT}" >> "$GITHUB_OUTPUT"
build:
name: Build macOS (${{ matrix.arch }})
name: Build macOS (universal)
needs: validate
# The Apple signing/notarization and Tauri updater secrets live in the
# PublishDesktop environment rather than at repository level, so they are
# readable only by this job and only once a required reviewer approves the
# run. Defense in depth: this `if` is advisory because a dispatched branch
# runs its own copy of this file; the enforced gate is the PublishDesktop
# environment's deployment-branch policy, which must also allow only main.
#
# Beta releases do not weaken this: a beta publish is ALSO dispatched from
# main (so this gate, the branch policy, and the workflow file executed all
# stay main's) — only the checked-out tag points into desktop-experimental,
# which validate pins via the ancestry check. A workflow copy edited on
# desktop-experimental can therefore never reach the signing secrets.
#
# What dispatch-from-main does NOT protect: the checked-out tag's own
# build scripts (bun install hooks, build:sdk, Tauri's beforeBuildCommand,
# build.rs) run inside this job with the signing secrets in scope, for
# stable and beta alike. The control for that is this environment's
# required-reviewer approval — the approver is vouching for the code the
# tag points at, not just for "a release happening". Two consequences:
# desktop-experimental must keep main-grade merge controls (branch
# protection, maintainer-only pushes), and an approval should only follow
# a look at what the tag actually contains. Building betas without these
# secrets is not an option: unsigned bundles fail Gatekeeper and updater
# artifacts must be signed with the same key or beta installs cannot
# verify their updates.
if: github.ref == 'refs/heads/main'
environment: PublishDesktop
runs-on: macos-latest
timeout-minutes: 90
strategy:
fail-fast: true
matrix:
include:
- target: aarch64-apple-darwin
arch: aarch64
- target: x86_64-apple-darwin
arch: x86_64
steps:
# A secret missing here is dangerous rather than merely broken: Tauri skips
# code signing when APPLE_CERTIFICATE is empty and skips notarization when
# APPLE_API_KEY is empty, both silently, so the build would still succeed
# and publish an unsigned, un-notarized bundle. Only the missing updater
# key is caught later (by the .sig check in "Collect artifacts"). Fail up
# front instead, before any build work, if the environment is misconfigured.
- name: Verify PublishDesktop secrets are present
env:
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
APPLE_API_KEY_CONTENT: ${{ secrets.APPLE_API_KEY_CONTENT }}
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
run: |
missing=()
for name in APPLE_API_ISSUER APPLE_API_KEY APPLE_API_KEY_CONTENT \
APPLE_CERTIFICATE APPLE_CERTIFICATE_PASSWORD APPLE_SIGNING_IDENTITY \
TAURI_SIGNING_PRIVATE_KEY TAURI_SIGNING_PRIVATE_KEY_PASSWORD; do
[ -n "${!name}" ] || missing+=("$name")
done
if [ ${#missing[@]} -gt 0 ]; then
echo "Missing from the PublishDesktop environment:"
printf ' - %s\n' "${missing[@]}"
echo
echo "Check that every secret above is set on the PublishDesktop"
echo "environment and that this job still declares"
echo "'environment: PublishDesktop'."
exit 1
fi
# Deliberately not phrased as "resolved from PublishDesktop": a
# non-empty value here could also be a repository or organization
# secret. The repository-scope check in `validate` is what rules that
# out.
echo "All 8 signing secrets are present."
- name: Checkout code
uses: actions/checkout@v4
with:
@@ -102,16 +244,18 @@ jobs:
with:
bun-version: "1.3.13"
# A universal (fat) macOS bundle needs both architecture slices, so
# install both Rust targets; `tauri build --target universal-apple-darwin`
# compiles each and lipos the results into one binary.
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
targets: aarch64-apple-darwin,x86_64-apple-darwin
- name: Cache Rust build
uses: swatinem/rust-cache@v2
with:
workspaces: apps/examples/desktop-app/src-tauri
key: ${{ matrix.target }}
# No Rust build cache here, deliberately. This is the only job that can
# read the Apple signing certificate and the Tauri updater key, and a
# restored cache archive is attacker-controlled the moment the Actions
# cache is poisoned.
- name: Install dependencies
run: bun install
@@ -142,8 +286,27 @@ jobs:
- name: Build, sign, and notarize desktop bundle
working-directory: apps/examples/desktop-app
run: bunx tauri build --target ${{ matrix.target }} --config src-tauri/tauri.release.conf.json
# Tauri merges repeated --config flags in order, so the beta overlay
# (product name, bundle identifier, beta update feed) layers on top of
# the release overlay without duplicating it. $CONFIG_ARGS is
# deliberately unquoted: it must word-split into separate flags.
run: bunx tauri build --target universal-apple-darwin $CONFIG_ARGS
env:
CONFIG_ARGS: ${{ needs.validate.outputs.channel == 'beta' && '--config src-tauri/tauri.release.conf.json --config src-tauri/tauri.beta.conf.json' || '--config src-tauri/tauri.release.conf.json' }}
# Telemetry config for the sidecar binary. Tauri's beforeBuildCommand
# (`bun run build` -> build:sidecar:bin) compiles the sidecar during
# this step and inlines these values into the binary via `--define`
# (scripts/telemetry-define-args.ts); a packaged app launched from
# Finder/the Dock has no runtime env, so build-time inlining is the
# only way the shipped sidecar can ever report telemetry.
TELEMETRY_SERVICE_API_KEY: ${{ secrets.TELEMETRY_SERVICE_API_KEY }}
ERROR_SERVICE_API_KEY: ${{ secrets.ERROR_SERVICE_API_KEY }}
OTEL_TELEMETRY_ENABLED: ${{ secrets.OTEL_TELEMETRY_ENABLED }}
OTEL_LOGS_EXPORTER: otlp
OTEL_METRICS_EXPORTER: otlp
OTEL_EXPORTER_OTLP_PROTOCOL: ${{ secrets.OTEL_EXPORTER_OTLP_PROTOCOL }}
OTEL_EXPORTER_OTLP_ENDPOINT: ${{ secrets.OTEL_EXPORTER_OTLP_ENDPOINT }}
OTEL_EXPORTER_OTLP_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_HEADERS }}
# Developer ID signing (Tauri imports the cert into a temp keychain)
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
@@ -157,38 +320,145 @@ jobs:
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
# Tauri lipos the main binary itself but sidecars are merged by our own
# build-sidecar-bin.ts, so assert every Mach-O in the bundle really
# carries both slices before anything is published. A single-arch
# sidecar would otherwise ship fine and only crash on the other arch.
- name: Verify bundle is a universal binary
working-directory: apps/examples/desktop-app
env:
PRODUCT: ${{ needs.validate.outputs.product }}
run: |
APP="src-tauri/target/universal-apple-darwin/release/bundle/macos/${PRODUCT}.app"
if [ ! -d "$APP" ]; then
echo "app bundle not found at $APP"
exit 1
fi
for bin in "$APP/Contents/MacOS/"*; do
archs=$(lipo -archs "$bin")
echo "$bin: $archs"
case "$archs" in
*arm64*x86_64*|*x86_64*arm64*) ;;
*)
echo "$bin is not a universal binary (archs: $archs)"
exit 1
;;
esac
done
# Guardrail: the updater endpoint is compiled into the main binary as a
# string literal (tauri-build embeds the merged config via codegen), so
# assert the bundle carries this channel's feed URL and not the other
# channel's, before anything gets signed into a release. This catches a
# --config overlay that silently failed to apply: a beta bundle polling
# desktop-latest would pull its users onto stable builds, and a stable
# bundle polling desktop-beta would push betas to every stable install.
- name: Verify updater feed endpoint
working-directory: apps/examples/desktop-app
env:
CHANNEL: ${{ needs.validate.outputs.channel }}
PRODUCT: ${{ needs.validate.outputs.product }}
run: |
APP="src-tauri/target/universal-apple-darwin/release/bundle/macos/${PRODUCT}.app"
case "$CHANNEL" in
stable)
WANT="releases/download/desktop-latest/latest.json"
FORBID="releases/download/desktop-beta/latest.json"
;;
beta)
WANT="releases/download/desktop-beta/latest.json"
FORBID="releases/download/desktop-latest/latest.json"
;;
*)
echo "unknown channel: ${CHANNEL}"
exit 1
;;
esac
# Plain grep >/dev/null rather than grep -q: -q exits at the first
# match, SIGPIPEs strings, and would read as a failed pipeline under
# pipefail.
found=0
for bin in "$APP/Contents/MacOS/"*; do
if strings -a "$bin" | grep "$FORBID" >/dev/null; then
echo "$bin embeds the other channel's feed URL (${FORBID})"
exit 1
fi
if strings -a "$bin" | grep "$WANT" >/dev/null; then
found=1
fi
done
if [ "$found" -ne 1 ]; then
echo "No binary in ${APP}/Contents/MacOS embeds ${WANT}."
echo "The updater endpoint overlay did not apply; check the"
echo "--config flags on the build step and tauri.beta.conf.json."
exit 1
fi
echo "Updater endpoint verified: ${WANT}"
# Guardrail: assert the telemetry config actually made it into the
# compiled sidecar. Missing env on the build step (or a regression in
# the --define inlining) would otherwise ship a release with telemetry
# silently disabled — exactly what happened for every release before
# this check existed. Being enabled is not enough on its own: an empty,
# malformed, or non-http(s) OTLP endpoint would still drop every event
# at runtime (the SDK exporters speak OTLP http/json only), so the
# selfcheck must also report a usable endpoint host.
- name: Verify sidecar telemetry config was inlined
working-directory: apps/examples/desktop-app
run: |
SELFCHECK=$(./src-tauri/bin/code-sidecar-universal-apple-darwin --telemetry-selfcheck)
echo "$SELFCHECK"
if ! printf '%s' "$SELFCHECK" | grep -q '"enabled":true'; then
echo "Packaged sidecar reports telemetry disabled."
echo "Check the OTEL_* / TELEMETRY_SERVICE_API_KEY env on the"
echo "'Build, sign, and notarize desktop bundle' step and the"
echo "--define inlining in scripts/build-sidecar-bin.ts."
exit 1
fi
if printf '%s' "$SELFCHECK" | grep -Eq '"otlp_endpoint_host":"(invalid-endpoint-url)?"'; then
echo "Packaged sidecar reports telemetry enabled but its OTLP"
echo "endpoint is missing, unparseable, or not an http(s) URL, so"
echo "every event would be dropped at runtime. Check the"
echo "OTEL_EXPORTER_OTLP_ENDPOINT secret."
exit 1
fi
- name: Collect artifacts
working-directory: apps/examples/desktop-app
env:
VERSION: ${{ needs.validate.outputs.version }}
ARCH: ${{ matrix.arch }}
TARGET: ${{ matrix.target }}
PRODUCT: ${{ needs.validate.outputs.product }}
run: |
BUNDLE_DIR="src-tauri/target/${TARGET}/release/bundle"
BUNDLE_DIR="src-tauri/target/universal-apple-darwin/release/bundle"
OUT="dist/publish"
mkdir -p "$OUT"
# "Cline Code" -> Cline-Code, "Cline Code Beta" -> Cline-Code-Beta
PREFIX="${PRODUCT// /-}"
DMG=$(find "$BUNDLE_DIR/dmg" -name '*.dmg' -print -quit)
if [ -z "$DMG" ]; then
echo "no DMG produced under $BUNDLE_DIR/dmg"
exit 1
fi
cp "$DMG" "$OUT/Cline-Code_${VERSION}_${ARCH}.dmg"
cp "$DMG" "$OUT/${PREFIX}_${VERSION}_universal.dmg"
TARBALL=$(find "$BUNDLE_DIR/macos" -name '*.app.tar.gz' -print -quit)
if [ -z "$TARBALL" ] || [ ! -f "${TARBALL}.sig" ]; then
echo "updater artifact or signature missing under $BUNDLE_DIR/macos"
exit 1
fi
cp "$TARBALL" "$OUT/Cline-Code_${VERSION}_${ARCH}.app.tar.gz"
cp "${TARBALL}.sig" "$OUT/Cline-Code_${VERSION}_${ARCH}.app.tar.gz.sig"
cp "$TARBALL" "$OUT/${PREFIX}_${VERSION}_universal.app.tar.gz"
cp "${TARBALL}.sig" "$OUT/${PREFIX}_${VERSION}_universal.app.tar.gz.sig"
ls -lh "$OUT"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: desktop-${{ matrix.arch }}
name: desktop-universal
path: apps/examples/desktop-app/dist/publish/*
if-no-files-found: error
@@ -219,9 +489,18 @@ jobs:
- name: Get Changelog Entry
id: changelog
env:
VERSION: ${{ needs.validate.outputs.version }}
run: |
# Grab content between the first "## " header and the next one
CONTENT=$(awk '/^## [0-9]/{if(found) exit; found=1; next} found{print}' apps/examples/desktop-app/CHANGELOG.md)
# Grab content between this release's "## <version>" header and the
# next one. Exact match, not "first section": once main and
# desktop-experimental cross-merge, stable and beta sections
# interleave and the top section may belong to the other channel.
CONTENT=$(awk -v ver="$VERSION" '$0 == "## " ver {found=1; next} /^## [0-9]/ {if (found) exit} found {print}' apps/examples/desktop-app/CHANGELOG.md)
if [ -z "$CONTENT" ]; then
echo "No '## ${VERSION}' section found in apps/examples/desktop-app/CHANGELOG.md"
exit 1
fi
echo "content<<EOF" >> $GITHUB_OUTPUT
echo "$CONTENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
@@ -245,8 +524,15 @@ jobs:
id: prev_tag
env:
CURRENT_TAG: ${{ needs.validate.outputs.tag }}
CHANNEL: ${{ needs.validate.outputs.channel }}
run: |
PREV_TAG=$(git describe --tags --abbrev=0 --match 'desktop-v*' "$CURRENT_TAG^" 2>/dev/null || echo "")
# Stable compare links skip beta tags so they read stable -> stable;
# beta compares against whatever shipped last on either channel.
if [ "$CHANNEL" = "stable" ]; then
PREV_TAG=$(git describe --tags --abbrev=0 --match 'desktop-v*' --exclude 'desktop-v*-beta*' "$CURRENT_TAG^" 2>/dev/null || echo "")
else
PREV_TAG=$(git describe --tags --abbrev=0 --match 'desktop-v*' "$CURRENT_TAG^" 2>/dev/null || echo "")
fi
echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT
- name: Create GitHub Release
@@ -257,6 +543,7 @@ jobs:
# The repo-wide "latest" release stays owned by CLI releases; the
# desktop auto-update feed is the rolling desktop-latest release.
make_latest: "false"
prerelease: ${{ needs.validate.outputs.channel == 'beta' }}
files: dist/desktop/*
body: |
${{ steps.changelog.outputs.content }}
@@ -265,27 +552,58 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update auto-update feed (desktop-latest)
- name: Update auto-update feed
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANNEL: ${{ needs.validate.outputs.channel }}
FEED: ${{ needs.validate.outputs.feed }}
run: |
if ! gh release view desktop-latest >/dev/null 2>&1; then
gh release create desktop-latest \
--title "Cline Code desktop (auto-update feed)" \
--notes "Rolling release backing the desktop app auto-updater. The latest.json asset points at the newest desktop-vX.Y.Z release. Do not delete." \
--latest=false \
--target "$(git rev-parse HEAD)"
# Belt and braces: recompute the feed from the channel and require it
# to agree with validate's output, so no single threading bug can
# point a publish at the other channel's feed. Stable installs poll
# desktop-latest and beta installs poll desktop-beta; crossing the
# streams either pushes betas to every stable user or strands beta
# users on stale builds.
case "$CHANNEL" in
stable) EXPECTED_FEED=desktop-latest ;;
beta) EXPECTED_FEED=desktop-beta ;;
*)
echo "unknown channel: ${CHANNEL}"
exit 1
;;
esac
if [ "$FEED" != "$EXPECTED_FEED" ]; then
echo "feed mismatch: validate says '${FEED}' but channel '${CHANNEL}' expects '${EXPECTED_FEED}'"
exit 1
fi
gh release upload desktop-latest dist/desktop/latest.json --clobber
if ! gh release view "$FEED" >/dev/null 2>&1; then
if [ "$CHANNEL" = "beta" ]; then
gh release create "$FEED" \
--title "Cline Code desktop beta (auto-update feed)" \
--notes "Rolling release backing the beta desktop app auto-updater. The latest.json asset points at the newest desktop-vX.Y.Z-beta.N release. Only beta installs poll this feed; stable installs use desktop-latest. Do not delete." \
--latest=false \
--prerelease \
--target "$(git rev-parse HEAD)"
else
gh release create "$FEED" \
--title "Cline Code desktop (auto-update feed)" \
--notes "Rolling release backing the desktop app auto-updater. The latest.json asset points at the newest desktop-vX.Y.Z release. Do not delete." \
--latest=false \
--target "$(git rev-parse HEAD)"
fi
fi
gh release upload "$FEED" dist/desktop/latest.json --clobber
- name: Summary
env:
VERSION: ${{ needs.validate.outputs.version }}
TAG: ${{ needs.validate.outputs.tag }}
FEED: ${{ needs.validate.outputs.feed }}
run: |
echo "Published Cline Code desktop v${VERSION}"
echo "Release: https://github.com/${GITHUB_REPOSITORY}/releases/tag/${TAG}"
echo "Auto-update feed refreshed: https://github.com/${GITHUB_REPOSITORY}/releases/download/desktop-latest/latest.json"
echo "Auto-update feed refreshed: https://github.com/${GITHUB_REPOSITORY}/releases/download/${FEED}/latest.json"
- name: Post release to Slack
uses: slackapi/slack-github-action@v3.0.1
@@ -294,12 +612,12 @@ jobs:
token: ${{ secrets.SLACK_RELEASE_BOT_TOKEN }}
payload: |
channel: "C0APVKGGZFC"
text: "Cline Code desktop v${{ needs.validate.outputs.version }}"
text: "Cline Code desktop v${{ needs.validate.outputs.version }}${{ needs.validate.outputs.channel == 'beta' && ' (beta)' || '' }}"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "Cline Code desktop v${{ needs.validate.outputs.version }}"
text: "Cline Code desktop v${{ needs.validate.outputs.version }}${{ needs.validate.outputs.channel == 'beta' && ' (beta)' || '' }}"
- type: "section"
text:
type: "mrkdwn"
@@ -307,4 +625,4 @@ jobs:
- type: "context"
elements:
- type: "mrkdwn"
text: "<https://github.com/${{ github.repository }}/releases/tag/${{ needs.validate.outputs.tag }}|Download DMG> — installed apps auto-update on next launch${{ steps.prev_tag.outputs.prev_tag != '' && format(' | Full Changelog: https://github.com/{0}/compare/{1}...{2}', github.repository, steps.prev_tag.outputs.prev_tag, needs.validate.outputs.tag) || '' }}"
text: "<https://github.com/${{ github.repository }}/releases/tag/${{ needs.validate.outputs.tag }}|Download DMG> — ${{ needs.validate.outputs.channel == 'beta' && 'beta channel: installs side by side with the stable app and only beta installs auto-update; stable users are unaffected' || 'installed apps auto-update on next launch' }}${{ steps.prev_tag.outputs.prev_tag != '' && format(' | Full Changelog: https://github.com/{0}/compare/{1}...{2}', github.repository, steps.prev_tag.outputs.prev_tag, needs.validate.outputs.tag) || '' }}"
-1
View File
@@ -102,7 +102,6 @@ jobs:
!endsWith(github.actor, '[bot]')
needs: quality
runs-on: ubuntu-latest
environment: Publish
permissions:
contents: read
id-token: write
+1
View File
@@ -92,3 +92,4 @@ apps/examples/desktop-app/webview/.next
# Next.js generated type shim (churns between dev and build)
apps/examples/desktop-app/webview/next-env.d.ts
apps/examples/desktop-app/.cursor/settings.json
+158
View File
@@ -1,5 +1,163 @@
# Changelog
## [4.1.10]
Everything in this release lands through the SDK bundle, so it applies to windows running that bundle and not the legacy one. The legacy bundle is unchanged from 4.1.9.
### Added
- Let models that support it search the web during a task, with a toggle in Feature Settings to turn it on. Search calls and their results appear in the conversation and persist across reloads.
### Fixed
- Stop two Cline installations on different builds from shutting each other's Hub daemon down in a loop, which killed live sessions with an abnormal socket close. Build identity is now compared through a total order, so at most one side of a pair can decide to retire the other.
- Leave a Hub that is still serving sessions in place instead of replacing it mid-handshake; the swap happens once it goes idle.
- Reclaim idle plugin sandbox processes instead of leaving them running for the life of the session.
### Changed
- Refresh the model catalog, which adds Crusoe as a provider and updates model lists and per-provider default models across the board.
## [4.1.9]
### Changed
- Use the editor's foreground color for diff block text, so diffs stay legible in themes where the previous hardcoded color washed them out.
- Switch the interface to Inter and Geist Mono.
### Fixed
- Don't discard a successfully refreshed Cline token when the old one was already past expiry, which made the first request after a long idle period fail despite valid credentials.
- Stop the legacy-task migration backlog from spamming telemetry, and record a migration outcome only once the seeded session actually persists, so a failed migration is no longer reported as a success.
- Report involuntary Cline logouts (a rejected refresh token) instead of clearing credentials silently.
### Fixed (SDK bundle only)
These land through SDK v0.0.74 and therefore apply to windows running the SDK bundle, not the legacy one.
- Fix the Claude Code provider being unusable for agentic work: it now runs its own native tools instead of receiving tool definitions it cannot bridge, anchors the session on your workspace directory, and loads `~/.claude` plus project settings so your permission rules apply.
- Reject truncated tool-call JSON instead of silently "repairing" it into wrong arguments.
- Fix strict providers rejecting a turn with "user message must have content" when a message's content held only empty text parts.
- Fix a mid-turn crash on streamed tool calls with non-zero or non-contiguous indexes, hit through LiteLLM's Anthropic passthrough.
- Report disjoint per-request token buckets instead of re-counting the whole cached conversation on every request, which inflated per-task totals roughly 5x on cache-heavy sessions.
## [4.1.8]
### Added
- Enter any Vertex model ID by hand, including models the catalog doesn't list yet.
- Support Fable 5 on Vertex.
### Changed
- Show the full model catalog for every Vertex region instead of filtering the picker down to a hardcoded list of global-endpoint models, which lagged behind every model launch. Picking a model the region doesn't serve now fails at request time with recovery guidance in the error row.
- Report Fable 5 cost on Vertex as unknown rather than applying Anthropic's list price, which understated what Vertex actually bills — its rates are region-dependent.
- Make the auto-approve menu the single source of truth for unattended runs and remove the Yolo Mode toggle, which was cosmetic: nothing in the approval path read it. Setups that had Yolo Mode (or auto-approve-all) turned on are migrated to auto-approving every action, so they keep running unattended.
### Fixed
- Respect your configured max output tokens when the compaction summarizer requests a summary.
- Remove the stale "Double-Check Completion" feature tip.
## [4.1.7]
### Added
- Restore the "View Changes" button on completion rows, backed by SDK checkpoints, so you can review everything a task touched from the completion card.
- Bring back a copy button on turn-final response rows.
- Support pre-registered OAuth clients for remote MCP servers, for setups where dynamic client registration isn't available.
### Changed
- Fade the "View Changes" button until changes since the last message are confirmed, and hide it entirely when there is nothing to show.
- Centralize plugin settings and contributions, with host-aware snapshots and atomic plugin toggles.
- Carry execution context in scheduled run reports — readable headers, schedule metadata, durations, and lifecycle error details.
### Fixed
- Preserve prompts queued during a turn when that turn is interrupted: they survive aborts, are drained after a turn aborts itself, and the stop is surfaced instead of the queue being silently dropped.
- Keep session context durable across aborts and hub restarts, so an interrupted session resumes with the state it had.
- Settle the turn phase when a mode switch aborts a running turn.
- Report queued-turn failures as `run.failed` instead of letting them complete silently.
- Keep a hung MCP server from taking down session creation, and give stdio servers that were never configured a 30-second initialize budget instead of blocking indefinitely.
- Surface OAuth authorization for SSE MCP servers on a 401 instead of failing outright.
- Route LiteLLM through Chat Completions instead of the Responses API, fixing requests against LiteLLM proxies.
- Retry network interruptions that happen mid-stream but before any model output, instead of failing the turn.
- Use the configured fetch for Vertex ADC token refreshes, so they work behind proxies and custom transports.
- Include files that were untracked when a snapshot was taken in checkpoint diffs, and pick up checkpoints when git is initialized part-way through a session.
- Fall back to the session cwd or Desktop for @-mention file search in empty windows.
- Never run a foreign compiled plugin-sandbox bootstrap for a source host.
## [4.1.6]
### Added
- Offer `meta/muse-spark-1.2-contributor` on the Cline provider, alongside a refreshed model catalog.
### Fixed
- Attribute error telemetry to the model actually in use for a run, so failures are no longer reported against the wrong model.
## [4.1.5]
### Added
- Explain when a free model promotion ends. Requests to a retired free model now show a dedicated notice with a button to pick another model, instead of a generic error with nothing but a Retry prompt.
### Changed
- Map reasoning settings onto a shared path across AI SDK providers, so effort levels and enable/disable toggles behave consistently (including on Ollama) instead of relying on per-provider overrides.
## [4.1.4]
### Added
- Recognize Chutes as a provider.
- Show skills alongside workflows in the slash command menu, and disambiguate commands that share a name instead of letting one shadow the other.
### Changed
- Remove model-initiated plan-to-act switching. Switching out of plan mode is now driven by you, not by the model deciding mid-turn.
- Hard-block file-editing shell commands in plan mode instead of relying on prompting alone. Read-only investigation still works, but file manipulation, in-place editors, redirection to files, mutating git subcommands, and package installs are refused.
### Fixed
- Stop treating a turn that completes with a plan as a failed turn when a plan-blocked command was its only tool call. The turn no longer ends in the error state with a Retry footer, and toggling to Act correctly re-runs the presented plan instead of appearing to do nothing.
- Show tool paths relative to the workspace in the chat view instead of absolute paths.
- Reset pending attachments when starting a new task, so images from the previous task no longer carry over.
- Surface a clear error when the selected provider has no API key configured, instead of a generic failure.
- Refresh MCP tool and resource lists when a server sends a `list_changed` notification, instead of only showing a toast.
- Show installed plugins under their real package names instead of all appearing as "index".
- Correct the Linux keybinding label in the Plan/Act mode tooltip.
- Recover from running out of context instead of failing with a raw provider error — the run compacts and retries once, and the cases that genuinely cannot be recovered explain why.
- Retry empty model responses on every provider rather than only Ollama, fixing hard "Model returned empty response" failures on OpenRouter, Cline, and OpenAI-compatible endpoints.
- Stop Claude 4.6+ and 5.x models being rejected with "thinking.type.enabled is not supported" when they resolve from the offline catalog or from a hand-typed model id.
- Restore Bedrock prompt caching, which reported zero cache reads and writes because the provider sent a cache format Bedrock discards, and route Bedrock foundation models through geo inference profiles.
- Send `max_completion_tokens` for reasoning models on OpenAI-compatible endpoints, and substitute image content for models without image support instead of failing the request.
- Inherit the MiniMax default model from models.dev, and refresh the bundled catalog, which adds Infomaniak and SCX.ai.
- Report the same provider failure once instead of twice in error telemetry, and rate-limit repeated failures from unattended retry loops.
## [4.1.3]
### Fixed
- Stop the two bundles of the combined rollout package from invalidating each other's Cline account session. A still-open legacy window that refreshed its token after the machine was promoted to the new extension would consume the shared refresh token, producing spurious "Unauthorized" / re-authenticate prompts and unexpected sign-outs. Promoted legacy windows now keep working on their current session and offer a one-time Reload Window prompt instead.
- Fall back to the default Cline model when migrating a setup that references a model id the new extension doesn't recognize, instead of leaving the provider unconfigured.
- Restore reliable checkpoints: checkpoints are created consistently, and restoring one now rewinds the whole workspace rather than a subset of files.
- Keep settings edits that are made before the provider config finishes loading — base URLs, API keys, and the Qwen/Moonshot API line are no longer silently discarded.
- Stop losing keystrokes in custom base URL fields, and keep the custom URL checkbox state after a failed clear.
- Use the AskSage custom API URL at inference time instead of ignoring it.
- Settle a pending tool approval when an edited message replaces the session, so the task no longer hangs waiting on a prompt that is gone.
- Drop attachments from messages that have been edited.
- Complete terminal commands when the shell execution ends, so tasks no longer stall on commands that already finished.
- Include untracked files when generating commit messages.
- Run Windows Store PowerShell profiles correctly.
- Surface the upstream provider error when a gateway-forwarded stream fails, instead of a generic failure.
- Retry empty Ollama responses at the model boundary, and raise the response-start timeout to 5 minutes so cold model loads no longer error out.
- Show proper display names for Cline free models and recommended models in the model picker.
- Preserve video input capability for models that support it.
- Keep the plan/act input border in sync with the actual textarea focus.
## [4.1.2]
### Added
+1 -1
View File
@@ -7,7 +7,7 @@ We're thrilled you're interested in contributing to Cline. Whether you're fixing
Bug reports help make Cline better for everyone! Before creating a new issue, please [search existing ones](https://github.com/cline/cline/issues) to avoid duplicates. When you're ready to report a bug, head over to our [issues page](https://github.com/cline/cline/issues/new/choose) where you'll find a template to help you with filling out the relevant information.
<blockquote class='warning-note'>
🔐 <b>Important:</b> If you discover a security vulnerability, please use the <a href="https://github.com/cline/cline/security/advisories/new">Github security tool to report it privately</a>.
🔐 <b>Important:</b> If you discover a security vulnerability, please use the <a href="https://github.com/cline/cline/security/advisories/new">GitHub security tool to report it privately</a>.
</blockquote>
+72
View File
@@ -1,5 +1,77 @@
# Cline CLI Changelog
## 3.0.55
- Auto-updates no longer install while a CLI is attached to the Hub. The update is recorded at startup and installed on exit, once the Hub confirms nothing else is attached, so a background update can no longer swap the package out from under a live session and kill it with `Hub connection closed (code=1006)`. `cline update` still installs immediately and now tells you the update applies on next start
- Added protections for an update landing under CLI 3.0.54 and earlier, whose updater restarts the Hub mid-session and then rejects every replacement, bricking a running session. The newly installed package defuses that path during install instead of leaving it to fire
- Fixed two Cline installations on different builds shutting each other's Hub daemon down in a loop, which killed every live session with an abnormal socket close. Build identity is now compared through a total order, so at most one side of a pair can ever decide to retire the other (from SDK v0.0.75)
- A newer build no longer replaces a Hub that is still serving sessions — it attaches to it and the swap happens on a later launch, instead of the sessions dying mid-handshake (from SDK v0.0.75)
- Removed the "outdated Hub" notice. It reported a state you cannot act on, and the toast was capped narrower than the message, so it rendered cut off before the reassuring half of the sentence at every terminal width. The prompt for a genuine build mismatch, where there is something to do, is unchanged
- Streaming assistant markdown no longer flashes back to raw text. Settled headings, links, and code stay rendered as new chunks arrive instead of the whole message being rebuilt and re-highlighted on every chunk, which also stops the transcript from jumping vertically mid-stream
- Web search calls and their results from models that run search natively now render in the transcript (from SDK v0.0.75)
- Idle plugin sandbox processes are now reclaimed instead of lingering for the life of the session (from SDK v0.0.75)
- `cline doctor fix` now reports honestly: processes that survived a kill are separated from ones that appeared while the fix ran, a live parent respawning a daemon is named, and a startup lock held by a running process is reported as held rather than leaked (from SDK v0.0.75)
- Refreshed the model catalog, which adds Crusoe as a provider and updates model lists and per-provider default models across the board (from SDK v0.0.75)
## 3.0.54
- Fixed the Claude Code provider being unusable for agentic work: the provider now runs its own native tools instead of receiving tool definitions it cannot bridge, the session is anchored on your workspace directory instead of inheriting the host's cwd, and `~/.claude` plus project settings are loaded so your permission rules apply. File edits under the workspace are auto-approved; command execution stays gated by your own Claude settings (from SDK v0.0.74)
- Fixed truncated tool-call JSON being silently "repaired" into wrong arguments — a payload with an unterminated string is now rejected rather than getting an invented terminator (from SDK v0.0.74)
- Fixed strict providers rejecting a turn with "user message must have content" when a message's content held only empty text parts (from SDK v0.0.74)
- Fixed a mid-turn crash on streamed tool calls with non-zero or non-contiguous indexes, hit through LiteLLM's Anthropic passthrough (from SDK v0.0.74)
- Managed Hub daemons now upgrade directionally: when another Cline install ships a newer Hub build, the CLI attaches to the newer daemon and prompts you to update and restart instead of the two installs repeatedly retiring each other's daemons. Yolo and sandbox sessions, which never attach to the shared Hub, are not interrupted by that prompt (from SDK v0.0.74)
- Fixed the Hub daemon logging an unhandled `hub server close failed` error and exiting non-zero whenever a client was still connected at shutdown (from SDK v0.0.74)
- Fixed per-task token totals being inflated roughly 5x on cache-heavy sessions — token telemetry now reports disjoint uncached-input, cache-read, and cache-write buckets instead of re-counting the whole cached conversation on every request (from SDK v0.0.74)
- Upgrading the CLI now retires an already-running Hub daemon and respawns it on the new code, instead of the upgraded CLI continuing to talk to a daemon executing the previous release
## 3.0.53
- Fixed the CLI reconnecting to a stale Hub daemon after an upgrade. Hub daemons now carry a runtime build fingerprint, so an upgraded CLI retires and respawns a daemon still running older code instead of attaching to it (from SDK v0.0.73)
- Fixed compaction being silently skipped on reasoning models. The summarizer no longer hardcodes a 1024-token output cap — it honors your max output tokens setting, defaults to 4096 (lowered when the model reports less), and logs a diagnostic when a summary comes back empty (from SDK v0.0.73)
- Added Fable 5 (`claude-fable-5`) to the Vertex model catalog. Pricing is intentionally omitted because Vertex bills region-dependently, so cost shows as unknown rather than wrong (from SDK v0.0.73)
- Custom Vertex model IDs are now passed through unchanged, routing Claude-style IDs to the Anthropic-on-Vertex path (from SDK v0.0.73)
## 3.0.52
- Added `cline mcp uninstall` for removing an installed MCP server
- Schedules now reuse your saved provider settings instead of needing provider configuration of their own
- Queued messages are legible on light-theme terminals — they were previously rendered in a color that washed out against a light background
- MCP tool results render as readable text in the TUI instead of escaped JSON, and binary payloads survive being expanded instead of being mangled
- Malformed tool input/output payloads no longer break rendering — the formatters degrade gracefully instead of throwing
- Prompts queued during a turn now survive being interrupted: they are preserved across aborts, drained after a turn aborts itself, and the stop is surfaced instead of leaving the queue silently dropped (from SDK v0.0.72)
- Session context stays durable across aborts and hub restarts, so an interrupted session resumes with the state it had (from SDK v0.0.72)
- A hung MCP server no longer takes down session creation, and stdio servers that were never configured get a 30-second initialize budget instead of blocking indefinitely (from SDK v0.0.72)
- Remote SSE MCP servers surface an OAuth authorization prompt on a 401 instead of failing outright, and pre-registered OAuth clients are supported for setups without dynamic client registration (from SDK v0.0.72)
- LiteLLM requests route through Chat Completions instead of the Responses API, fixing calls against LiteLLM proxies (from SDK v0.0.72)
- Network interruptions that happen mid-stream but before any model output are retried instead of failing the turn (from SDK v0.0.72)
- Vertex ADC token refreshes use the configured fetch, so they work behind proxies and custom transports (from SDK v0.0.72)
- Checkpoint diffs include files that were untracked when the snapshot was taken, and checkpoints are picked up when git is initialized part-way through a session (from SDK v0.0.72)
- Scheduled run reports carry execution context — readable headers, schedule metadata, durations, and lifecycle error details (from SDK v0.0.72)
## 3.0.51
- Reasoning effort now applies consistently across providers instead of going through per-provider thinking overrides, including Ollama, and asking for reasoning to be off is respected everywhere (from SDK v0.0.71)
- `meta/muse-spark-1.2-contributor` is now selectable on the Cline provider, alongside a refreshed model catalog (from SDK v0.0.71)
- Error telemetry now reports the model that was actually in use for the run (from SDK v0.0.71)
## 3.0.50
- Added user-selectable color themes to the interactive TUI. Pick one with `/theme`, the command palette, or the Theme row in `/settings` — the picker previews each theme live. Built-in themes are Auto (terminal-adaptive, the default), Cline Dark, Cline Light, Tokyo Night, Gruvbox Dark, Nord, Dracula, Catppuccin Mocha, One Dark, Solarized Dark, and Solarized Light. Named themes paint the background, foreground, accents, syntax highlighting, and diff colors, and `CLINE_THEME` overrides the persisted choice at startup
- The git branch shown below the prompt now updates when you switch branches from another terminal or your editor, instead of showing whatever was checked out when the TUI started
- Telegram slash commands such as `/clear` now reach the connector command host — the Telegram library was intercepting them and they were silently dropped
- Racing connector launches no longer collide: an instance is claimed before it opens socket mode, the hub supervises connector processes, and `doctor`/`connect` skip connectors that are already starting. Connector tools are also enabled by default, and the Slack greeting is no longer replayed on reconnect
- Auto-approval settings are now honored over ACP
- Plan mode now hard-blocks file-editing shell commands instead of relying on prompting alone — `run_commands` stays available for read-only investigation, but file-manipulation commands, in-place editors (`sed -i`, `perl -i`), redirection to files, mutating git subcommands, package installs, and nested command strings (`sh -c`, `eval`, `sudo`) are rejected, on Windows and PowerShell too (from SDK v0.0.70)
- A turn that ends with a completed plan is no longer rendered as a failed turn when a plan-blocked command was its only tool call
- Running out of context is now recovered from instead of failing with a raw provider error: the run force-compacts and retries once, and the cases that genuinely cannot be recovered report why (from SDK v0.0.70)
- Empty model responses are now retried on every provider, not just Ollama — OpenRouter, Cline, and OpenAI-compatible endpoints previously failed the task outright with "Model returned empty response" (from SDK v0.0.70)
- Claude 4.6+ and 5.x models are no longer rejected with "thinking.type.enabled is not supported" when they resolve from the offline catalog or from a hand-typed model id (from SDK v0.0.70)
- Bedrock prompt caching works again — the provider was sending a cache format Bedrock silently discards, so cache reads and writes were always 0 — and Bedrock foundation models are now routed through geo inference profiles (from SDK v0.0.70)
- Reasoning models on OpenAI-compatible endpoints now receive `max_completion_tokens` instead of the rejected `max_tokens`, and requests to models without image support substitute the image content instead of failing (from SDK v0.0.70)
- MiniMax now inherits its default model from models.dev, and the model catalog picked up two new providers, Infomaniak and SCX.ai (from SDK v0.0.70)
- Upgraded the model layer to AI SDK 7 and switched Ollama to the native AI SDK provider (from SDK v0.0.70)
- Error telemetry no longer reports the same provider failure twice, and repeated failures from unattended retry loops are rate-limited (from SDK v0.0.70)
## 3.0.49
- `/undo` works again once the agent has used tools — the checkpoint picker counted tool results as user turns, so restore aborted with "Could not find user message for run N"
+4 -2
View File
@@ -221,13 +221,15 @@ In chat surfaces, connector slash commands include `/help`, `/start`, `/new`, `/
Schedule agents on cron-like intervals or external events.
If `--provider` and `--model` are omitted, schedules use the last configured
provider and model. If only `--provider` is given, the schedule uses that
provider's saved model.
```sh
cline schedule create "Daily code review" \
--cron "0 9 * * MON-FRI" \
--prompt "Review PRs opened yesterday and summarize issues." \
--workspace /path/to/repo \
--provider cline \
--model openai/gpt-5.3-codex \
--timeout 3600 \
--tags automation,review
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@cline/cli",
"displayName": "cline",
"version": "3.0.49",
"version": "3.0.55",
"description": "Autonomous coding agent CLI - capable of creating/editing files, running commands, using the browser, and more",
"type": "module",
"publishConfig": {
+37
View File
@@ -17,6 +17,35 @@ import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const require = createRequire(import.meta.url);
// CLI versions <= 3.0.54 restart the hub daemon after a background
// auto-update even while it is serving live sessions, killing those sessions
// mid-turn — and their build-fingerprint check then rejects every replacement
// hub, bricking the running TUI. That restart code is the *old* version's, so
// it cannot be patched here; but it bails out harmlessly when no hub
// discovery record exists, and it runs only after this install (and this
// script) completes. Setting the record aside protects any attached clients:
// a running hub keeps serving its established connections, clients that share
// its build fingerprint rebuild the record from a port probe, and the next
// fresh launch retires stale hubs regardless of the record.
function shieldRunningHubDiscovery() {
const explicitPath = process.env.CLINE_HUB_DISCOVERY_PATH?.trim();
const dataDir =
process.env.CLINE_DATA_DIR?.trim() ||
path.join(
process.env.CLINE_DIR?.trim() || path.join(os.homedir(), ".cline"),
"data",
);
const recordPath =
explicitPath || path.join(dataDir, "locks", "hub", "production.json");
if (!fs.existsSync(recordPath)) {
return;
}
const asidePath = `${recordPath}.superseded`;
fs.rmSync(asidePath, { force: true });
fs.renameSync(recordPath, asidePath);
console.log("Set aside hub discovery record for the updated CLI");
}
function main() {
if (os.platform() === "win32") {
// On Windows, npm creates .cmd shims from the bin field.
@@ -79,6 +108,14 @@ function main() {
console.log(`Cached cline binary at ${target}`);
}
try {
shieldRunningHubDiscovery();
} catch (error) {
// Best-effort: without the shield the worst case is the pre-3.0.55
// restart-while-busy behavior, never a broken install.
console.error(`postinstall: hub discovery shield skipped: ${error.message}`);
}
try {
main();
} catch (error) {
+39
View File
@@ -0,0 +1,39 @@
#!/bin/bash
# Launch the Cline CLI in ACP mode from source, for use as a Zed custom agent.
#
# Zed spawns agents without your interactive shell's PATH, so `bun` (installed
# via mise/asdf/nvm/homebrew) is usually not resolvable. This wrapper finds bun
# explicitly and execs it from the repo root.
#
# IMPORTANT: stdout is the JSON-RPC channel. Never echo to stdout here — any
# stray byte corrupts the ACP stream. Diagnostics go to stderr.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
# Prefer an explicit override, then PATH, then common version-manager locations.
if [ -n "${BUN_BIN:-}" ]; then
bun_bin="$BUN_BIN"
elif command -v bun > /dev/null 2>&1; then
bun_bin="$(command -v bun)"
else
bun_bin=""
for candidate in \
"$HOME"/.local/share/mise/installs/bun/*/bin/bun \
"$HOME"/.bun/bin/bun \
/opt/homebrew/bin/bun \
/usr/local/bin/bun; do
if [ -x "$candidate" ]; then
bun_bin="$candidate"
break
fi
done
fi
if [ -z "$bun_bin" ]; then
echo "acp-dev.sh: could not find the 'bun' executable; set BUN_BIN to its path" >&2
exit 127
fi
cd "$REPO_ROOT"
exec "$bun_bin" --conditions=development --cwd apps/cli dev --acp "$@"
+37 -7
View File
@@ -30,7 +30,7 @@ import {
ProviderSettingsManager,
SessionSource,
} from "@cline/core";
import { isLikelyAuthError, type Message } from "@cline/shared";
import { isLikelyAuthError, type MessageWithMetadata } from "@cline/shared";
import { getPersistedProviderApiKey } from "../commands/auth";
import { resolveSystemPrompt } from "../runtime/prompt";
import { subscribeToAgentEvents } from "../runtime/session-events";
@@ -46,6 +46,11 @@ import {
authenticateAcpProvider,
isAcpAuthMethodId,
} from "./auth";
import {
AUTO_APPROVE_CONFIG_ID,
buildAutoApproveConfigOption,
parseAutoApproveValue,
} from "./auto-approve";
import {
buildOrganizationConfigOption,
fetchClineOrganizations,
@@ -75,6 +80,8 @@ interface SessionState {
currentProviderId: string;
/** Current model id for the session. */
currentModelId: string;
/** When true, all tool calls are approved without asking the client. */
autoApproveTools: boolean;
/** Active session manager for the running agent, if any. */
sessionManager?: ClineCore;
/** Internal session id within the session manager. */
@@ -93,19 +100,24 @@ interface SessionState {
*/
fatalError?: Error;
/** Messages to inject into the next session manager for conversation continuity. */
pendingInitialMessages?: Message[];
pendingInitialMessages?: MessageWithMetadata[];
}
export class AcpAgent implements Agent {
private sessions = new Map<string, SessionState>();
private readonly conn: AgentSideConnection;
private readonly providerSettingsManager = new ProviderSettingsManager();
private readonly defaultAutoApproveTools: boolean;
/** Set after a successful `authenticate` call. */
private authResult?: AcpAuthResult;
constructor(conn: AgentSideConnection) {
constructor(
conn: AgentSideConnection,
options?: { autoApproveTools?: boolean },
) {
this.conn = conn;
this.defaultAutoApproveTools = options?.autoApproveTools ?? false;
}
async initialize(_params: InitializeRequest): Promise<InitializeResponse> {
@@ -190,6 +202,7 @@ export class AcpAgent implements Agent {
currentMode: defaultMode,
currentProviderId: providerId,
currentModelId: defaultModelId,
autoApproveTools: this.defaultAutoApproveTools,
});
const availableModels = Object.entries(providerModels).map(
@@ -217,6 +230,7 @@ export class AcpAgent implements Agent {
await buildProviderConfigOption(providerId),
buildModelConfigOption(defaultModelId, providerModels),
buildModeConfigOption(defaultMode),
buildAutoApproveConfigOption(this.defaultAutoApproveTools),
...(organizationOption ? [organizationOption] : []),
],
};
@@ -226,7 +240,7 @@ export class AcpAgent implements Agent {
this.isSessionReady();
let session = this.sessions.get(params.sessionId);
let messages: Message[];
let messages: MessageWithMetadata[];
if (session?.sessionManager && session.activeSessionId) {
// The session is still live in this connection — replay its current
@@ -254,6 +268,7 @@ export class AcpAgent implements Agent {
process.env.CLINE_MODEL,
providerModels,
),
autoApproveTools: this.defaultAutoApproveTools,
};
this.sessions.set(params.sessionId, session);
}
@@ -511,6 +526,18 @@ export class AcpAgent implements Agent {
break;
}
case AUTO_APPROVE_CONFIG_ID: {
const autoApprove = parseAutoApproveValue(params.value);
if (autoApprove === undefined) {
throw RequestError.invalidParams(
undefined,
`Invalid auto-approve value: ${String(params.value)} (must be a boolean)`,
);
}
session.autoApproveTools = autoApprove;
break;
}
default:
throw RequestError.invalidParams(
undefined,
@@ -649,7 +676,7 @@ export class AcpAgent implements Agent {
session: SessionState,
acpSessionId: string,
options?: { resume?: boolean },
): Promise<Message[] | undefined> {
): Promise<MessageWithMetadata[] | undefined> {
if (session.sessionManager) {
return undefined;
}
@@ -660,13 +687,15 @@ export class AcpAgent implements Agent {
toolPolicies: config.toolPolicies,
capabilities: {
requestToolApproval: (request) =>
requestAcpToolApproval(this.conn, acpSessionId, request),
session.autoApproveTools
? Promise.resolve({ approved: true })
: requestAcpToolApproval(this.conn, acpSessionId, request),
},
cwd: config.cwd,
workspaceRoot: config.workspaceRoot,
});
let initialMessages: Message[] | undefined;
let initialMessages: MessageWithMetadata[] | undefined;
if (options?.resume) {
initialMessages = await sessionManager
.readMessages(acpSessionId)
@@ -884,6 +913,7 @@ async function buildAllConfigOptions(
providerOption,
buildModelConfigOption(session.currentModelId, providerModels),
buildModeConfigOption(session.currentMode),
buildAutoApproveConfigOption(session.autoApproveTools),
];
}
+47
View File
@@ -0,0 +1,47 @@
import { describe, expect, it } from "vitest";
import {
AUTO_APPROVE_CONFIG_ID,
buildAutoApproveConfigOption,
parseAutoApproveValue,
} from "./auto-approve";
describe("buildAutoApproveConfigOption", () => {
it("builds a boolean config option reflecting the current value", () => {
const option = buildAutoApproveConfigOption(true);
expect(option).toMatchObject({
type: "boolean",
id: AUTO_APPROVE_CONFIG_ID,
currentValue: true,
});
expect(option.name).toBeTruthy();
});
it("defaults to disabled when the session has it off", () => {
const option = buildAutoApproveConfigOption(false);
expect(option).toMatchObject({ type: "boolean", currentValue: false });
});
});
describe("parseAutoApproveValue", () => {
it("accepts booleans", () => {
expect(parseAutoApproveValue(true)).toBe(true);
expect(parseAutoApproveValue(false)).toBe(false);
});
it("accepts the string forms sent by older clients", () => {
expect(parseAutoApproveValue("true")).toBe(true);
expect(parseAutoApproveValue("false")).toBe(false);
});
it("fails closed for unrecognized values", () => {
expect(parseAutoApproveValue("yes")).toBeUndefined();
expect(parseAutoApproveValue(1)).toBeUndefined();
expect(parseAutoApproveValue(null)).toBeUndefined();
});
it("returns undefined when no value was provided", () => {
expect(parseAutoApproveValue(undefined)).toBeUndefined();
});
});
+32
View File
@@ -0,0 +1,32 @@
import type { SessionConfigOption } from "@agentclientprotocol/sdk";
export const AUTO_APPROVE_CONFIG_ID = "auto_approve";
export function buildAutoApproveConfigOption(
currentValue: boolean,
): SessionConfigOption {
return {
type: "boolean",
id: AUTO_APPROVE_CONFIG_ID,
name: "Auto-approve tools",
description:
"Automatically approve all tool calls without asking for permission",
currentValue,
};
}
/**
* Interpret the value of a `session/set_config_option` request for the
* auto-approve option.
*
* The ACP schema sends booleans for boolean options, but clients that predate
* boolean options may send the string form, so both are accepted. Returns
* `undefined` for anything else so the caller can reject the request.
*/
export function parseAutoApproveValue(value: unknown): boolean | undefined {
if (typeof value === "boolean" || value === undefined) {
return value;
}
return value === "true" ? true : value === "false" ? false : undefined;
}
+8 -2
View File
@@ -1,7 +1,11 @@
import { Readable, Writable } from "node:stream";
import { writeDiagnostic } from "../utils/output";
export async function runAcpMode(): Promise<void> {
export interface AcpModeOptions {
autoApproveTools?: boolean;
}
export async function runAcpMode(options?: AcpModeOptions): Promise<void> {
const { AgentSideConnection, ndJsonStream } = await import(
"@agentclientprotocol/sdk"
);
@@ -15,7 +19,9 @@ export async function runAcpMode(): Promise<void> {
);
const connection = new AgentSideConnection((conn) => {
return new AcpAgent(conn);
return new AcpAgent(conn, {
autoApproveTools: options?.autoApproveTools,
});
}, stream);
// Keep the process alive until the connection closes
+70
View File
@@ -225,6 +225,76 @@ describe("translateHistoricalMessage", () => {
},
]);
});
it("replays provider model tools with the ordinary ACP tool updates", () => {
expect(
translateHistoricalMessage({
role: "assistant",
content: "Found it",
metadata: {
modelToolActivities: [
{
toolCallId: "search-1",
toolName: "web_search",
execution: "provider",
input: { query: "latest Bun release" },
output: "Bun 1.3.14",
},
],
},
} as Parameters<typeof translateHistoricalMessage>[0]),
).toEqual([
{
sessionUpdate: "tool_call",
toolCallId: "search-1",
title: expect.any(String),
kind: "search",
status: "pending",
rawInput: { query: "latest Bun release" },
},
{
sessionUpdate: "tool_call_update",
toolCallId: "search-1",
status: "completed",
rawOutput: "Bun 1.3.14",
},
{
sessionUpdate: "agent_message_chunk",
content: { type: "text", text: "Found it" },
},
]);
});
it("preserves structured native web-search results", () => {
const nativeResult = {
type: "web_search_result",
url: "https://bun.sh/blog/bun-v1.3.14",
title: "Bun v1.3.14",
pageAge: "2026-08-12",
encryptedContent: "encrypted",
};
const updates = translateHistoricalMessage({
role: "assistant",
content: "Found it",
metadata: {
modelToolActivities: [
{
toolCallId: "search-native",
toolName: "web_search",
execution: "provider",
input: { query: "latest Bun" },
output: [nativeResult],
},
],
},
} as Parameters<typeof translateHistoricalMessage>[0]);
expect(updates[1]).toMatchObject({
sessionUpdate: "tool_call_update",
toolCallId: "search-native",
rawOutput: JSON.stringify(nativeResult),
});
});
});
describe("replaySessionHistory", () => {
+46 -4
View File
@@ -2,10 +2,11 @@ import type {
AgentSideConnection,
SessionUpdate,
} from "@agentclientprotocol/sdk";
import { projectSessionMessagesForDisplay } from "@cline/core";
import {
type ContentBlock,
formatDisplayUserInput,
type Message,
type MessageWithMetadata,
type ToolResultContent,
} from "@cline/shared";
import { ACT_MODE_CONTINUATION_PROMPT } from "../runtime/interactive/mode";
@@ -29,7 +30,7 @@ function isSyntheticUserText(text: string): boolean {
export async function replaySessionHistory(
conn: AgentSideConnection,
sessionId: string,
messages: Message[],
messages: MessageWithMetadata[],
): Promise<void> {
for (const message of messages) {
for (const update of translateHistoricalMessage(message)) {
@@ -38,7 +39,17 @@ export async function replaySessionHistory(
}
}
export function translateHistoricalMessage(message: Message): SessionUpdate[] {
export function translateHistoricalMessage(
message: MessageWithMetadata,
): SessionUpdate[] {
return projectSessionMessagesForDisplay([message]).flatMap(({ message }) =>
translateProjectedHistoricalMessage(message),
);
}
function translateProjectedHistoricalMessage(
message: MessageWithMetadata,
): SessionUpdate[] {
const blocks: ContentBlock[] =
typeof message.content === "string"
? [{ type: "text", text: message.content }]
@@ -92,6 +103,31 @@ export function translateHistoricalMessage(message: Message): SessionUpdate[] {
);
break;
}
case "media": {
const media = block.media;
if (media.modality === "image" && media.source.type === "base64") {
updates.push({
sessionUpdate:
message.role === "user"
? "user_message_chunk"
: "agent_message_chunk",
content: {
type: "image",
data: media.source.data,
mimeType: media.mediaType,
},
});
} else {
updates.push({
sessionUpdate: "agent_message_chunk",
content: {
type: "text",
text: `[Generated ${media.modality}: ${media.mediaType}]`,
},
});
}
break;
}
case "tool_use": {
updates.push({
sessionUpdate: "tool_call",
@@ -133,8 +169,14 @@ function flattenToolResultContent(
return part.text;
case "file":
return part.content;
default:
case "image":
return "[image]";
default:
try {
return JSON.stringify(part);
} catch {
return String(part);
}
}
})
.join("\n");
+34
View File
@@ -0,0 +1,34 @@
import type { AgentSideConnection } from "@agentclientprotocol/sdk";
import type { AgentEvent } from "@cline/core";
import { describe, expect, it, vi } from "vitest";
import { forwardAgentEvent } from "./session-updates";
describe("forwardAgentEvent", () => {
it("forwards generated images as ACP agent message chunks", () => {
const sessionUpdate = vi.fn().mockResolvedValue(undefined);
const connection = { sessionUpdate } as unknown as AgentSideConnection;
forwardAgentEvent(connection, "session-1", {
type: "content_end",
contentType: "media",
media: {
id: "generated-1",
modality: "image",
mediaType: "image/png",
source: { type: "base64", data: "aGVsbG8=" },
},
} as AgentEvent);
expect(sessionUpdate).toHaveBeenCalledWith({
sessionId: "session-1",
update: {
sessionUpdate: "agent_message_chunk",
content: {
type: "image",
data: "aGVsbG8=",
mimeType: "image/png",
},
},
});
});
});
+25
View File
@@ -4,6 +4,7 @@ import type {
SessionUpdate,
} from "@agentclientprotocol/sdk";
import type { AgentEvent } from "@cline/core";
import type { GeneratedMedia } from "@cline/shared";
import { getErrorMessage } from "@cline/shared";
import { buildToolTitle, mapToolKind } from "./tool-utils";
@@ -100,6 +101,7 @@ function translateContentEnd(
output?: unknown;
error?: string;
durationMs?: number;
media?: GeneratedMedia;
};
switch (e.contentType) {
@@ -109,6 +111,29 @@ function translateContentEnd(
case "reasoning":
// Reasoning was already streamed via content_start chunks; don't re-send.
return [];
case "media":
if (!e.media) return [];
if (e.media.modality !== "image" || e.media.source.type !== "base64") {
return [
{
sessionUpdate: "agent_message_chunk",
content: {
type: "text",
text: `[Generated ${e.media.modality}: ${e.media.mediaType}]`,
},
},
];
}
return [
{
sessionUpdate: "agent_message_chunk",
content: {
type: "image",
data: e.media.source.data,
mimeType: e.media.mediaType,
},
},
];
case "tool": {
const toolCallId = e.toolCallId ?? "unknown";
const failed = !!e.error;
+1
View File
@@ -17,6 +17,7 @@ const TOOL_KIND_MAP: Record<string, ToolKind> = {
WebFetch: "fetch",
fetch_web_content: "fetch",
WebSearch: "search",
web_search: "search",
Agent: "think",
spawn_agent: "think",
NotebookEdit: "edit",
+65
View File
@@ -767,6 +767,71 @@ Break work into clear steps.`,
);
});
it("routes mcp uninstall and its rm alias", () => {
const tempRoot = mkdtempSync(path.join(os.tmpdir(), "cli-e2e-mcp-rm-"));
tempDirs.push(tempRoot);
const settingsPath = path.join(tempRoot, "cline_mcp_settings.json");
const writeSettings = () => {
writeFileSync(
settingsPath,
JSON.stringify(
{
mcpServers: {
docs: { transport: { type: "stdio", command: "node" } },
remote: {
transport: {
type: "streamableHttp",
url: "https://mcp.example.com",
},
},
},
customTopLevelKey: true,
},
null,
2,
),
"utf8",
);
};
const readServers = () =>
(
JSON.parse(readFileSync(settingsPath, "utf8")) as {
mcpServers?: Record<string, unknown>;
}
).mcpServers ?? {};
writeSettings();
const uninstallResult = runCli(["mcp", "uninstall", "docs"], {
env: { ...createIsolatedEnv(), CLINE_MCP_SETTINGS_PATH: settingsPath },
});
expect(uninstallResult.status).toBe(0);
expect(asText(uninstallResult.stdout)).toContain(
"Uninstalled MCP server docs.",
);
expect(Object.keys(readServers())).toEqual(["remote"]);
writeSettings();
const aliasResult = runCli(["mcp", "rm", "remote", "--json"], {
env: { ...createIsolatedEnv(), CLINE_MCP_SETTINGS_PATH: settingsPath },
});
expect(aliasResult.status).toBe(0);
expect(JSON.parse(asText(aliasResult.stdout).trim())).toEqual({
name: "remote",
status: "uninstalled",
});
expect(Object.keys(readServers())).toEqual(["docs"]);
writeSettings();
const missingResult = runCli(["mcp", "remove", "missing"], {
env: { ...createIsolatedEnv(), CLINE_MCP_SETTINGS_PATH: settingsPath },
});
expect(missingResult.status).toBe(1);
expect(asText(missingResult.stderr)).toContain(
'MCP server "missing" is not installed.',
);
expect(Object.keys(readServers())).toEqual(["docs", "remote"]);
});
it("lists available tools", () => {
const homeDir = mkdtempSync(path.join(os.tmpdir(), "cli-e2e-home-"));
const dataDir = mkdtempSync(path.join(os.tmpdir(), "cli-e2e-data-"));
+2 -1
View File
@@ -5,6 +5,7 @@ import {
type BuiltinToolAvailabilityContext,
createUserInstructionConfigService,
discoverPluginModulePaths,
getPluginDisplayName,
hasMcpSettingsFile,
listHookConfigFiles,
listPluginTools,
@@ -270,7 +271,7 @@ async function runPluginsConfigCommand(
continue;
}
pluginsByPath.set(filePath, {
name: basename(filePath, extname(filePath)),
name: getPluginDisplayName(filePath, directory),
path: filePath,
});
}
@@ -0,0 +1,304 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { ConnectIo } from "../connectors/types";
const mocks = vi.hoisted(() => ({
ensureDetachedHubServer: vi.fn(),
readHubDiscovery: vi.fn(),
connect: vi.fn(),
command: vi.fn(),
close: vi.fn(),
clientOptions: vi.fn(),
}));
vi.mock("@cline/core", () => ({
ensureDetachedHubServer: mocks.ensureDetachedHubServer,
readHubDiscovery: mocks.readHubDiscovery,
resolveProductionHubOwnerContext: () => ({
ownerId: "hub-production",
discoveryPath: "/tmp/production.json",
}),
resolveSharedHubOwnerContext: () => ({
ownerId: "hub-owner",
discoveryPath: "/tmp/owner.json",
}),
NodeHubClient: class {
constructor(options: unknown) {
mocks.clientOptions(options);
}
connect = mocks.connect;
command = mocks.command;
close = mocks.close;
},
}));
import { startConnectorViaHub, stopConnectorsViaHub } from "./connect-via-hub";
describe("startConnectorViaHub", () => {
const io: ConnectIo = { writeln: vi.fn(), writeErr: vi.fn() };
beforeEach(() => {
vi.clearAllMocks();
mocks.ensureDetachedHubServer.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
authToken: "token",
});
mocks.readHubDiscovery.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
capabilities: ["session.create", "connector.start"],
});
mocks.connect.mockResolvedValue(undefined);
});
afterEach(() => {
vi.clearAllMocks();
});
function startRequest(overrides: Record<string, unknown> = {}) {
return {
channel: "slack",
instanceId: "cline-slack",
args: ["--bot-token", "xoxb"],
io,
cwd: "/workspace",
...overrides,
};
}
it("hands the start to the hub and reports supervision", async () => {
mocks.command.mockResolvedValue({
version: "v1",
ok: true,
payload: {
started: true,
record: { pid: 4242, state: "running" },
},
});
await expect(startConnectorViaHub(startRequest())).resolves.toEqual({
delegated: true,
exitCode: 0,
});
expect(mocks.command).toHaveBeenCalledWith("connector.start", {
channel: "slack",
instanceId: "cline-slack",
args: ["--bot-token", "xoxb"],
restart: false,
});
expect(io.writeln).toHaveBeenCalledWith(
expect.stringContaining("started under hub supervision pid=4242"),
);
expect(mocks.close).toHaveBeenCalled();
});
it("passes a restart through", async () => {
mocks.command.mockResolvedValue({
version: "v1",
ok: true,
payload: { started: true, record: { state: "running" } },
});
await startConnectorViaHub(startRequest({ restart: true }));
expect(mocks.command).toHaveBeenCalledWith(
"connector.start",
expect.objectContaining({ restart: true }),
);
});
it("treats an already-running instance as success", async () => {
mocks.command.mockResolvedValue({
version: "v1",
ok: true,
payload: {
started: false,
reason: "already_running",
record: { pid: 99, state: "running" },
},
});
await expect(startConnectorViaHub(startRequest())).resolves.toEqual({
delegated: true,
exitCode: 0,
});
expect(io.writeln).toHaveBeenCalledWith(
expect.stringContaining("already running under the hub"),
);
});
it("falls back when the hub cannot be reached", async () => {
mocks.ensureDetachedHubServer.mockRejectedValue(new Error("EADDRINUSE"));
const outcome = await startConnectorViaHub(startRequest());
expect(outcome.delegated).toBe(false);
expect(mocks.command).not.toHaveBeenCalled();
});
it("falls back when a running hub predates connector supervision", async () => {
// The normal state of a long-lived host mid-upgrade: a new CLI, an old hub.
mocks.readHubDiscovery.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
capabilities: ["session.create"],
});
const outcome = await startConnectorViaHub(startRequest());
expect(outcome).toEqual({
delegated: false,
reason: "hub does not support connector supervision",
});
expect(mocks.command).not.toHaveBeenCalled();
});
it("falls back when the hub reports supervision unavailable", async () => {
mocks.command.mockResolvedValue({
version: "v1",
ok: false,
error: {
code: "connector_command_failed",
message: "connector supervision is unavailable in this hub",
},
});
const outcome = await startConnectorViaHub(startRequest());
expect(outcome.delegated).toBe(false);
});
it("falls back when the hub command throws", async () => {
mocks.command.mockRejectedValue(new Error("socket closed"));
const outcome = await startConnectorViaHub(startRequest());
expect(outcome.delegated).toBe(false);
expect(mocks.close).toHaveBeenCalled();
});
it("surfaces a genuine start refusal instead of starting locally", async () => {
mocks.command.mockResolvedValue({
version: "v1",
ok: false,
error: {
code: "connector_command_failed",
message: "instanceId is required",
},
});
await expect(startConnectorViaHub(startRequest())).resolves.toEqual({
delegated: true,
exitCode: 1,
});
expect(io.writeErr).toHaveBeenCalledWith(
expect.stringContaining("hub refused to start slack"),
);
});
it("reports a hub that accepted the command but did not start anything", async () => {
mocks.command.mockResolvedValue({
version: "v1",
ok: true,
payload: {
started: false,
record: { state: "failed", lastError: "bad token" },
},
});
await expect(startConnectorViaHub(startRequest())).resolves.toEqual({
delegated: true,
exitCode: 1,
});
expect(io.writeErr).toHaveBeenCalledWith(
expect.stringContaining("bad token"),
);
});
});
describe("stopConnectorsViaHub", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.readHubDiscovery.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
capabilities: [
"connector.start",
"connector.stop",
"connector.supervised",
],
});
mocks.connect.mockResolvedValue(undefined);
});
it("retires every supervised instance of a channel", async () => {
mocks.command.mockImplementation(async (command: string) => {
if (command === "connector.supervised") {
return {
ok: true,
payload: {
supervised: [
{ channel: "slack", instanceId: "a" },
{ channel: "slack", instanceId: "b" },
{ channel: "telegram", instanceId: "c" },
],
},
};
}
return { ok: true, payload: { stopped: true } };
});
await expect(stopConnectorsViaHub({ channel: "slack" })).resolves.toBe(2);
expect(mocks.command).toHaveBeenCalledWith("connector.stop", {
channel: "slack",
instanceId: "a",
});
expect(mocks.command).toHaveBeenCalledWith("connector.stop", {
channel: "slack",
instanceId: "b",
});
// A different channel is left alone.
expect(mocks.command).not.toHaveBeenCalledWith("connector.stop", {
channel: "telegram",
instanceId: "c",
});
});
it("retires only the requested instance", async () => {
mocks.command.mockImplementation(async (command: string) => {
if (command === "connector.supervised") {
return {
ok: true,
payload: {
supervised: [
{ channel: "slack", instanceId: "a" },
{ channel: "slack", instanceId: "b" },
],
},
};
}
return { ok: true, payload: { stopped: true } };
});
await expect(
stopConnectorsViaHub({ channel: "slack", instanceId: "b" }),
).resolves.toBe(1);
expect(mocks.command).toHaveBeenCalledWith("connector.stop", {
channel: "slack",
instanceId: "b",
});
});
it("reports nothing to stop when the hub supervises none of them", async () => {
mocks.command.mockResolvedValue({ ok: true, payload: { supervised: [] } });
await expect(stopConnectorsViaHub({ channel: "slack" })).resolves.toBe(0);
});
it("returns undefined when the hub cannot supervise", async () => {
mocks.readHubDiscovery.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
capabilities: ["session.create"],
});
await expect(
stopConnectorsViaHub({ channel: "slack" }),
).resolves.toBeUndefined();
});
});
+289
View File
@@ -0,0 +1,289 @@
import {
ensureDetachedHubServer,
NodeHubClient,
readHubDiscovery,
resolveProductionHubOwnerContext,
resolveSharedHubOwnerContext,
} from "@cline/core";
import {
type ConnectorStartResult,
resolveClineBuildEnv,
type SupervisedConnectorRecord,
} from "@cline/shared";
import type { ConnectIo } from "../connectors/types";
/**
* Error codes that mean "this hub cannot supervise connectors", as opposed to
* "the start failed". Both are answers from the hub, but only the former should
* send the caller back to starting the connector itself.
*/
const UNSUPPORTED_ERROR_CODES = new Set([
"unsupported_command",
"unsupported_connector_command",
]);
const UNSUPPORTED_MESSAGE_FRAGMENT = "connector supervision is unavailable";
export type HubDelegationOutcome =
/** The hub owns the connector now; `exitCode` is the command's result. */
| { delegated: true; exitCode: number }
/** Nothing was started; the caller should start the connector locally. */
| { delegated: false; reason: string };
function resolveHubOwnerContext() {
return resolveClineBuildEnv() === "production"
? resolveProductionHubOwnerContext()
: resolveSharedHubOwnerContext();
}
/**
* Whether the hub at `url` advertises connector supervision.
*
* A newer CLI regularly talks to an older running hub — that is the normal state
* of a long-lived host mid-upgrade — and such a hub would reject
* `connector.start` outright. Checking the advertised capability first keeps that
* case on the local path instead of turning it into a failed start.
*/
async function hubSupportsSupervision(): Promise<boolean> {
try {
const owner = resolveHubOwnerContext();
const record = await readHubDiscovery(owner.discoveryPath);
return record?.capabilities?.includes("connector.start") === true;
} catch {
return false;
}
}
function describeRecord(record: SupervisedConnectorRecord | undefined): string {
if (!record) {
return "";
}
const details = [
record.pid === undefined ? undefined : `pid=${record.pid}`,
`state=${record.state}`,
].filter(Boolean);
return details.length > 0 ? ` ${details.join(" ")}` : "";
}
/**
* What the running hub is supervising, or undefined when it cannot say.
*
* Deliberately does not start a hub: this exists for diagnostics, and `cline
* doctor` reporting on the system must never change it.
*/
export async function listSupervisedConnectorsViaHub(): Promise<
SupervisedConnectorRecord[] | undefined
> {
let url: string;
let authToken: string | undefined;
try {
const owner = resolveHubOwnerContext();
const record = await readHubDiscovery(owner.discoveryPath);
if (
!record?.url ||
!record.capabilities?.includes("connector.supervised")
) {
return undefined;
}
url = record.url;
authToken = record.authToken;
} catch {
return undefined;
}
const client = new NodeHubClient({
url,
...(authToken ? { authToken } : {}),
clientType: "cli-doctor",
displayName: "doctor",
});
try {
await client.connect();
const reply = await client.command("connector.supervised");
if (!reply.ok) {
return undefined;
}
const supervised = (reply.payload as { supervised?: unknown })?.supervised;
return Array.isArray(supervised)
? (supervised as SupervisedConnectorRecord[])
: undefined;
} catch {
return undefined;
} finally {
try {
client.close();
} catch {
// One-shot connection; a failed close changes nothing.
}
}
}
/**
* Ask the hub to stop supervising a channel's connectors, or one instance of it.
*
* Returns how many the hub stopped, or undefined when it cannot supervise. The
* local stop path alone is not enough: it finds processes through their state
* files, so a connector that has not written one yet — still starting, or failing
* to start — would keep running under the hub and be restarted.
*/
export async function stopConnectorsViaHub(input: {
channel: string;
instanceId?: string;
}): Promise<number | undefined> {
const supervised = await listSupervisedConnectorsViaHub();
if (!supervised) {
return undefined;
}
const targets = supervised.filter(
(record) =>
record.channel === input.channel &&
(input.instanceId === undefined ||
record.instanceId === input.instanceId),
);
if (targets.length === 0) {
return 0;
}
let url: string;
let authToken: string | undefined;
try {
const owner = resolveHubOwnerContext();
const record = await readHubDiscovery(owner.discoveryPath);
if (!record?.url) {
return undefined;
}
url = record.url;
authToken = record.authToken;
} catch {
return undefined;
}
const client = new NodeHubClient({
url,
...(authToken ? { authToken } : {}),
clientType: "cli-connect",
displayName: `stop ${input.channel}`,
});
let stopped = 0;
try {
await client.connect();
for (const target of targets) {
const reply = await client.command("connector.stop", {
channel: target.channel,
instanceId: target.instanceId,
});
if (reply.ok) {
stopped += 1;
}
}
return stopped;
} catch {
return stopped > 0 ? stopped : undefined;
} finally {
try {
client.close();
} catch {
// One-shot connection; a failed close changes nothing.
}
}
}
/**
* Ask the hub to start and own a connector.
*
* The hub spawning the connector — rather than the connector spawning itself and
* then bringing up a hub — is what makes the hub the single authority on how many
* processes hold one connector's credentials, and what lets it reap and restart
* them when they die. Every failure mode here falls back to the local path so a
* missing or older hub cannot stop a connector from starting.
*/
export async function startConnectorViaHub(input: {
channel: string;
instanceId: string;
args: string[];
restart?: boolean;
io: ConnectIo;
cwd?: string;
}): Promise<HubDelegationOutcome> {
const cwd = input.cwd ?? process.cwd();
let hub: { url: string; authToken: string };
try {
hub = await ensureDetachedHubServer(cwd);
} catch (error) {
return {
delegated: false,
reason: `hub unavailable: ${
error instanceof Error ? error.message : String(error)
}`,
};
}
if (!(await hubSupportsSupervision())) {
return {
delegated: false,
reason: "hub does not support connector supervision",
};
}
const client = new NodeHubClient({
url: hub.url,
authToken: hub.authToken,
clientType: "cli-connect",
displayName: `connect ${input.channel}`,
cwd,
});
try {
await client.connect();
const reply = await client.command("connector.start", {
channel: input.channel,
instanceId: input.instanceId,
args: input.args,
restart: input.restart === true,
});
if (!reply.ok) {
const code = reply.error?.code ?? "";
const message = reply.error?.message ?? "connector start failed";
if (
UNSUPPORTED_ERROR_CODES.has(code) ||
message.includes(UNSUPPORTED_MESSAGE_FRAGMENT)
) {
return { delegated: false, reason: message };
}
input.io.writeErr(
`[connect] hub refused to start ${input.channel}: ${message}`,
);
return { delegated: true, exitCode: 1 };
}
const payload = reply.payload as ConnectorStartResult | undefined;
const record = payload?.record;
if (payload?.started === false && payload.reason === "already_running") {
input.io.writeln(
`[connect] ${input.channel} connector ${input.instanceId} is already running under the hub${describeRecord(record)}`,
);
return { delegated: true, exitCode: 0 };
}
if (payload?.started !== true) {
input.io.writeErr(
`[connect] hub could not start ${input.channel} connector ${input.instanceId}${
record?.lastError ? `: ${record.lastError}` : ""
}`,
);
return { delegated: true, exitCode: 1 };
}
input.io.writeln(
`[connect] ${input.channel} connector ${input.instanceId} started under hub supervision${describeRecord(record)}`,
);
input.io.writeln(
"[connect] the hub will restart it if it exits; use `cline connect --stop` to retire it",
);
return { delegated: true, exitCode: 0 };
} catch (error) {
return {
delegated: false,
reason: `hub command failed: ${
error instanceof Error ? error.message : String(error)
}`,
};
} finally {
try {
client.close();
} catch {
// The connection is one-shot; a failed close changes nothing.
}
}
}
+200
View File
@@ -5,6 +5,7 @@ import {
} from "../connectors/common";
import type { ConnectIo, ConnectRunContext } from "../connectors/types";
import {
runCleanupConnectorInstance,
runConnectAdapter,
runRestartConnector,
runStopAllConnectors,
@@ -12,6 +13,8 @@ import {
} from "./connect";
const mocks = vi.hoisted(() => ({
startConnectorViaHub: vi.fn(),
stopConnectorsViaHub: vi.fn(async () => undefined as number | undefined),
disableConnectorAutostart: vi.fn(),
getPersistedConnectorConnection: vi.fn(),
getConnector: vi.fn(),
@@ -36,6 +39,11 @@ vi.mock("../connectors/registry", () => ({
listConnectors: mocks.listConnectors,
}));
vi.mock("./connect-via-hub", () => ({
startConnectorViaHub: mocks.startConnectorViaHub,
stopConnectorsViaHub: mocks.stopConnectorsViaHub,
}));
describe("runConnectAdapter", () => {
const previousDetachedChild = process.env[CLINE_CONNECTOR_DETACHED_CHILD_ENV];
const io: ConnectIo = {
@@ -492,3 +500,195 @@ describe("runConnectAdapter", () => {
expect(mocks.persistConnectorConnection).not.toHaveBeenCalled();
});
});
describe("runCleanupConnectorInstance", () => {
const io: ConnectIo = {
writeln: vi.fn(),
writeErr: vi.fn(),
};
beforeEach(() => {
vi.clearAllMocks();
});
it("reaps one instance without disabling its autostart", async () => {
const stopInstance = vi.fn().mockResolvedValue({
stoppedProcesses: 0,
failedProcesses: 0,
stoppedSessions: 2,
});
mocks.getConnector.mockResolvedValue({
name: "slack",
description: "Slack",
run: mocks.run,
validate: mocks.validate,
showHelp: vi.fn(),
stopInstance,
});
await expect(
runCleanupConnectorInstance("slack", "cline-slack", io),
).resolves.toBe(0);
expect(stopInstance).toHaveBeenCalledWith("cline-slack", io);
// The instance crashed; it was not retired. Disabling autostart here would
// make every crash silently opt the connector out of supervision.
expect(mocks.disableConnectorAutostart).not.toHaveBeenCalled();
});
it("reports a failed reap", async () => {
mocks.getConnector.mockResolvedValue({
name: "slack",
description: "Slack",
run: mocks.run,
validate: mocks.validate,
showHelp: vi.fn(),
stopInstance: vi.fn().mockResolvedValue({
stoppedProcesses: 0,
failedProcesses: 1,
stoppedSessions: 0,
}),
});
await expect(
runCleanupConnectorInstance("slack", "cline-slack", io),
).resolves.toBe(1);
});
it("rejects an adapter without per-instance stop", async () => {
mocks.getConnector.mockResolvedValue({
name: "slack",
description: "Slack",
run: mocks.run,
validate: mocks.validate,
showHelp: vi.fn(),
});
await expect(
runCleanupConnectorInstance("slack", "cline-slack", io),
).resolves.toBe(1);
expect(io.writeErr).toHaveBeenCalledWith(
'connect adapter "slack" does not support per-instance stop',
);
});
it("rejects an unknown adapter", async () => {
mocks.getConnector.mockResolvedValue(undefined);
await expect(
runCleanupConnectorInstance("nope", "instance", io),
).resolves.toBe(1);
expect(io.writeErr).toHaveBeenCalledWith('unknown connect adapter "nope"');
});
});
describe("hub-delegated connector starts", () => {
const io: ConnectIo = { writeln: vi.fn(), writeErr: vi.fn() };
beforeEach(() => {
vi.clearAllMocks();
mocks.listConnectors.mockReturnValue([]);
mocks.listActiveConnectors.mockReturnValue([]);
mocks.validate.mockResolvedValue(0);
mocks.run.mockResolvedValue(0);
mocks.getConnector.mockResolvedValue({
name: "slack",
description: "Slack",
run: mocks.run,
validate: mocks.validate,
showHelp: vi.fn(),
resolveInstanceId: () => "cline-slack",
});
mocks.startConnectorViaHub.mockResolvedValue({
delegated: true,
exitCode: 0,
});
});
afterEach(() => {
delete process.env.CLINE_CONNECTOR_SUPERVISED;
});
it("asks the hub to own a background connector and records the intent", async () => {
await expect(
runConnectAdapter("slack", ["--bot-token", "xoxb"], io),
).resolves.toBe(0);
expect(mocks.startConnectorViaHub).toHaveBeenCalledWith(
expect.objectContaining({
channel: "slack",
instanceId: "cline-slack",
args: ["--bot-token", "xoxb"],
}),
);
// The adapter must not also run here: the hub owns the process now.
expect(mocks.run).not.toHaveBeenCalled();
expect(mocks.persistConnectorConnection).toHaveBeenCalledWith(
"slack",
"cline-slack",
["--bot-token", "xoxb"],
);
});
it("runs locally for a foreground connector", async () => {
await runConnectAdapter("slack", ["--bot-token", "xoxb", "-i"], io);
expect(mocks.startConnectorViaHub).not.toHaveBeenCalled();
expect(mocks.run).toHaveBeenCalled();
});
it("runs locally inside a supervised process instead of asking the hub again", async () => {
process.env.CLINE_CONNECTOR_SUPERVISED = "1";
await runConnectAdapter("slack", ["--bot-token", "xoxb"], io);
// Delegating here would send the hub straight back to spawning this same
// process.
expect(mocks.startConnectorViaHub).not.toHaveBeenCalled();
expect(mocks.run).toHaveBeenCalled();
});
it("runs locally when the instance id cannot be known up front", async () => {
mocks.getConnector.mockResolvedValue({
name: "telegram",
description: "Telegram",
run: mocks.run,
validate: mocks.validate,
showHelp: vi.fn(),
resolveInstanceId: () => undefined,
});
await runConnectAdapter("telegram", ["-k", "token"], io);
expect(mocks.startConnectorViaHub).not.toHaveBeenCalled();
expect(mocks.run).toHaveBeenCalled();
});
it("falls back to a local start when the hub declines", async () => {
mocks.startConnectorViaHub.mockResolvedValue({
delegated: false,
reason: "hub does not support connector supervision",
});
await runConnectAdapter("slack", ["--bot-token", "xoxb"], io);
expect(mocks.run).toHaveBeenCalled();
});
it("does not validate or delegate a help invocation", async () => {
await runConnectAdapter("slack", ["--help"], io);
expect(mocks.startConnectorViaHub).not.toHaveBeenCalled();
expect(mocks.validate).not.toHaveBeenCalled();
});
it("reports a validation failure without contacting the hub", async () => {
mocks.validate.mockResolvedValue(2);
await expect(
runConnectAdapter("slack", ["--bot-token", "bad"], io),
).resolves.toBe(2);
expect(mocks.startConnectorViaHub).not.toHaveBeenCalled();
expect(mocks.run).not.toHaveBeenCalled();
});
});
+143 -1
View File
@@ -5,6 +5,10 @@ import {
persistConnectorConnection,
removePersistedConnectorConnection,
} from "@cline/core";
import {
isSupervisedConnectorProcess,
setStartingConnectorInstance,
} from "@cline/shared";
import {
CLINE_CONNECTOR_DETACHED_CHILD_ENV,
CONNECT_ALREADY_RUNNING_EXIT_CODE,
@@ -15,6 +19,7 @@ import type {
ConnectRunContext,
ConnectStopResult,
} from "../connectors/types";
import { startConnectorViaHub, stopConnectorsViaHub } from "./connect-via-hub";
const HELP_FLAGS = new Set(["-h", "--help"]);
const INTERACTIVE_FLAGS = new Set(["-i", "--interactive"]);
@@ -83,6 +88,20 @@ export async function runStopConnector(
io.writeErr(`connect adapter "${adapterName}" does not support stop`);
return 1;
}
// Retire it with the hub first. The local stop below finds processes through
// their state files, so a supervised connector that has not written one yet
// would survive and be restarted.
const stoppedByHub = await stopConnectorsViaHub({
channel: connector.name,
...(options.instanceId === undefined
? {}
: { instanceId: options.instanceId }),
});
if (stoppedByHub) {
io.writeln(
`[connect] hub stopped supervising ${stoppedByHub} ${connector.name} connector${stoppedByHub === 1 ? "" : "s"}`,
);
}
const result = await stop();
if (!result) {
io.writeErr(`connect adapter "${adapterName}" does not support stop`);
@@ -97,6 +116,39 @@ export async function runStopConnector(
return result.failedProcesses === 0 ? 0 : 1;
}
/**
* Reap one connector instance that is no longer running.
*
* Invoked by the hub supervisor when it observes a connector die. It clears the
* same things a normal stop does — process state file, thread→session bindings,
* the instance's hub sessions — but deliberately leaves the autostart record
* intact: the instance crashed, it was not retired, so the supervisor still
* intends to restart it. `runStopConnector` with `autostart: "disable"` would
* make every crash silently opt the connector out of recovery.
*/
export async function runCleanupConnectorInstance(
adapterName: string,
instanceId: string,
io: ConnectIo,
): Promise<number> {
const connector = await getConnector(adapterName);
if (!connector) {
io.writeErr(`unknown connect adapter "${adapterName}"`);
return 1;
}
if (!connector.stopInstance) {
io.writeErr(
`connect adapter "${adapterName}" does not support per-instance stop`,
);
return 1;
}
const result = await connector.stopInstance(instanceId, io);
io.writeln(
`[connect] ${connector.name} instance=${instanceId} cleaned processes=${result.stoppedProcesses} failed=${result.failedProcesses} sessions=${result.stoppedSessions}`,
);
return result.failedProcesses === 0 ? 0 : 1;
}
export async function runRestartConnector(
adapterName: string,
passthroughArgs: string[],
@@ -132,6 +184,21 @@ export async function runRestartConnector(
if (validationExitCode !== 0) {
return validationExitCode;
}
// The supervisor replaces an instance in one step, so let it do the whole
// restart rather than stopping here and racing it to start the replacement.
// Only when the target is the instance these arguments describe: a
// `--restart-instance` pointing elsewhere is not ours to reinterpret.
if (
requestedInstanceId === undefined ||
connector.resolveInstanceId?.(passthroughArgs) === requestedInstanceId
) {
const delegated = await tryDelegateToHub(connector, passthroughArgs, io, {
restart: true,
});
if (delegated !== undefined) {
return delegated;
}
}
const previousConnection = getPersistedConnectorConnection(
adapterName,
instanceId,
@@ -208,6 +275,14 @@ async function runConnectAdapterWithResult(
},
setPersistenceInstanceId: (instanceId) => {
persistenceInstanceId = instanceId;
// Adapters report their instance id before they build a Cline core, so
// this lands in the environment before the hub daemon is spawned and
// inherited by it. Without it the daemon's autostart pass cannot tell
// that this instance is mid-startup and launches a second copy of it.
setStartingConnectorInstance({
channel: connector.name,
instanceId,
});
},
};
const exitCode = await connector.run(passthroughArgs, io, context);
@@ -218,8 +293,12 @@ async function runConnectAdapterWithResult(
const isInteractiveInvocation = passthroughArgs.some((arg) =>
INTERACTIVE_FLAGS.has(arg),
);
// A supervised process is the hub's own connector, not a user invocation, so
// it makes the same autostart bookkeeping choices as a detached child: the
// process that asked for the start already recorded the intent.
const isDetachedChild =
process.env[CLINE_CONNECTOR_DETACHED_CHILD_ENV] === "1";
process.env[CLINE_CONNECTOR_DETACHED_CHILD_ENV] === "1" ||
isSupervisedConnectorProcess();
if (
exitCode === 0 &&
!isHelpInvocation &&
@@ -242,11 +321,74 @@ async function runConnectAdapterWithResult(
return { exitCode, instanceId: persistenceInstanceId };
}
/**
* Hand a background connector start to the hub, when that is possible.
*
* Returns the exit code once the hub owns the connector, or undefined to mean
* "start it locally instead". Delegation is skipped for foreground (`-i`) runs,
* which are attached to the user's terminal, and for connectors the hub itself
* launched, which would otherwise ask the hub to start them again.
*/
async function tryDelegateToHub(
connector: {
name: string;
validate: (args: string[], io: ConnectIo) => Promise<number>;
resolveInstanceId?: (args: string[]) => string | undefined;
},
passthroughArgs: string[],
io: ConnectIo,
options: { restart?: boolean } = {},
): Promise<number | undefined> {
if (
passthroughArgs.some((arg) => HELP_FLAGS.has(arg)) ||
passthroughArgs.some((arg) => INTERACTIVE_FLAGS.has(arg)) ||
process.env[CLINE_CONNECTOR_DETACHED_CHILD_ENV] === "1" ||
isSupervisedConnectorProcess()
) {
return undefined;
}
// Without an instance id the hub cannot enforce one process per connector,
// which is the entire point of routing through it.
const instanceId = connector.resolveInstanceId?.(passthroughArgs);
if (!instanceId) {
return undefined;
}
// Check the arguments here rather than after handing off: a bad token should
// fail in front of the user instead of becoming a supervised crash loop.
const validationExitCode = await connector.validate(passthroughArgs, io);
if (validationExitCode !== 0) {
return validationExitCode;
}
const outcome = await startConnectorViaHub({
channel: connector.name,
instanceId,
args: passthroughArgs,
...(options.restart === undefined ? {} : { restart: options.restart }),
io,
});
if (!outcome.delegated) {
return undefined;
}
if (outcome.exitCode === 0) {
// Recorded here rather than in the hub-spawned process: this is the
// invocation that expressed the intent to keep the connector running.
persistConnectorConnection(connector.name, instanceId, passthroughArgs);
}
return outcome.exitCode;
}
export async function runConnectAdapter(
adapterName: string,
passthroughArgs: string[],
io: ConnectIo,
): Promise<number> {
const connector = await getConnector(adapterName);
if (connector) {
const delegated = await tryDelegateToHub(connector, passthroughArgs, io);
if (delegated !== undefined) {
return delegated;
}
}
const result = await runConnectAdapterWithResult(
adapterName,
passthroughArgs,
+276 -1
View File
@@ -18,12 +18,14 @@ const {
mockResolveProductionHubOwnerContext,
mockResolveSharedHubOwnerContext,
mockReadHubDiscovery,
mockReadSupersededHubDiscovery,
mockProbeHubServer,
mockClearHubDiscovery,
mockStopLocalHubServerGracefully,
mockEnsureFileExists,
mockListActiveConnectors,
mockStopAllConnectors,
mockListSupervisedConnectors,
} = vi.hoisted(() => ({
mockSpawnSync: vi.fn(),
mockResolveClineDataDir: vi.fn(() => "/tmp/cline-data"),
@@ -47,6 +49,7 @@ const {
),
})),
mockReadHubDiscovery: vi.fn(),
mockReadSupersededHubDiscovery: vi.fn(() => undefined as unknown),
mockProbeHubServer: vi.fn(),
mockClearHubDiscovery: vi.fn(),
mockStopLocalHubServerGracefully: vi.fn(async () => false),
@@ -58,6 +61,7 @@ const {
stoppedSessions: 0,
executed: 0,
})),
mockListSupervisedConnectors: vi.fn(async () => undefined as unknown),
}));
vi.mock("node:child_process", () => ({
@@ -71,6 +75,7 @@ vi.mock("@cline/core", () => ({
clearHubDiscovery: mockClearHubDiscovery,
probeHubServer: mockProbeHubServer,
readHubDiscovery: mockReadHubDiscovery,
readSupersededHubDiscovery: mockReadSupersededHubDiscovery,
stopLocalHubServerGracefully: mockStopLocalHubServerGracefully,
ensureFileExists: mockEnsureFileExists,
listActiveConnectors: mockListActiveConnectors,
@@ -84,7 +89,11 @@ vi.mock("./connect", () => ({
stopAllConnectors: mockStopAllConnectors,
}));
import { createDoctorCommand, runDoctorCommand } from "./doctor";
vi.mock("./connect-via-hub", () => ({
listSupervisedConnectorsViaHub: mockListSupervisedConnectors,
}));
import { __test__, createDoctorCommand, runDoctorCommand } from "./doctor";
describe("runDoctorCommand", () => {
const tempDirs: string[] = [];
@@ -180,6 +189,65 @@ describe("runDoctorCommand", () => {
);
});
it("sees the hub through the set-aside record during the shielded update window", async () => {
const cwd = "/workspace";
// The npm postinstall shield renamed the discovery record aside; the
// hub is alive and serving an old client's sessions.
mockReadHubDiscovery.mockResolvedValue(undefined);
mockReadSupersededHubDiscovery.mockReturnValue({
url: "ws://127.0.0.1:25463/hub",
authToken: "shielded-token",
pid: 50174,
});
mockProbeHubServer.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
port: 25463,
pid: 50174,
});
mockSpawnSync.mockImplementation((command: string, args?: string[]) => {
if (command === "lsof") {
return { status: 0, stdout: "50174\n" };
}
if (
command === "pgrep" &&
Array.isArray(args) &&
args[2] === "--cline-hub-daemon"
) {
return {
status: 0,
stdout: "50174 /usr/local/bin/cline --cline-hub-daemon\n",
};
}
return { status: 1, stdout: "" };
});
const output: string[] = [];
const code = await runDoctorCommand(
{ cwd, json: true },
{
writeln: (text) => {
output.push(text ?? "");
},
writeErr: () => {},
},
);
expect(code).toBe(0);
expect(mockProbeHubServer).toHaveBeenCalledWith(
"ws://127.0.0.1:25463/hub",
{
authToken: "shielded-token",
},
);
// Without the fallback the live daemon reads as stale and doctor's
// advice (\"run doctor fix\") would kill the sessions the shield exists
// to protect.
expect(JSON.parse(output[0] || "")).toMatchObject({
hubHealthy: true,
staleHubPids: [],
});
});
it("reports CLI and running hub Core versions", async () => {
const cwd = "/workspace";
mockReadHubDiscovery.mockResolvedValue({
@@ -450,3 +518,210 @@ describe("createDoctorCommand log subcommand", () => {
expect(errors[0]).toContain("open failed");
});
});
describe("container-aware process filtering", () => {
const { decideForeignContainer, CONTAINER_CGROUP_PATTERN } = __test__;
it("treats a process in a different pid namespace as foreign", () => {
expect(
decideForeignContainer({
platform: "linux",
namespacePairs: [
["pid:[4026531836]", "pid:[4026532500]"],
[undefined, undefined],
],
ownContainerId: undefined,
otherContainerId: undefined,
}),
).toBe(true);
});
it("keeps a sibling process in our own namespaces", () => {
expect(
decideForeignContainer({
platform: "linux",
namespacePairs: [
["pid:[4026531836]", "pid:[4026531836]"],
["mnt:[4026531840]", "mnt:[4026531840]"],
],
ownContainerId: undefined,
otherContainerId: undefined,
}),
).toBe(false);
});
it("falls back to cgroup container ids when namespaces are unreadable", () => {
expect(
decideForeignContainer({
platform: "linux",
namespacePairs: [[undefined, undefined]],
ownContainerId: undefined,
otherContainerId: "7c6ffadc42f0bc0bc7c6ca47de4cd702",
}),
).toBe(true);
// Same container: our own sibling process, not something to retire.
expect(
decideForeignContainer({
platform: "linux",
namespacePairs: [[undefined, undefined]],
ownContainerId: "7c6ffadc42f0bc0bc7c6ca47de4cd702",
otherContainerId: "7c6ffadc42f0bc0bc7c6ca47de4cd702",
}),
).toBe(false);
});
it("never filters off Linux, where containers cannot share our pid space", () => {
expect(
decideForeignContainer({
platform: "darwin",
namespacePairs: [["pid:[1]", "pid:[2]"]],
ownContainerId: undefined,
otherContainerId: "abcdef123456",
}),
).toBe(false);
});
it("extracts container ids from real cgroup paths", () => {
const docker =
"0::/system.slice/docker-7c6ffadc42f0bc0bc7c6ca47de4cd702206e79b4068d172d8c2a2350063913ad.scope";
expect(docker.match(CONTAINER_CGROUP_PATTERN)?.[1]).toBe(
"7c6ffadc42f0bc0bc7c6ca47de4cd702206e79b4068d172d8c2a2350063913ad",
);
// A plain host session must not look like a container.
expect(
"0::/user.slice/user-1001.slice/session-121.scope".match(
CONTAINER_CGROUP_PATTERN,
),
).toBeNull();
});
});
describe("doctor supervision reporting", () => {
const { formatSupervisedConnector } = __test__;
afterEach(() => {
vi.clearAllMocks();
mockListSupervisedConnectors.mockResolvedValue(undefined);
});
async function runDoctorJson(): Promise<Record<string, unknown>> {
const output: string[] = [];
await runDoctorCommand(
{ cwd: "/workspace", json: true },
{
writeln: (text) => {
output.push(text ?? "");
},
writeErr: () => {},
},
);
return JSON.parse(output[0] || "{}") as Record<string, unknown>;
}
it("reports what the hub is supervising", async () => {
mockListSupervisedConnectors.mockResolvedValue([
{
channel: "slack",
instanceId: "cline-slack",
state: "backoff",
origin: "spawned",
restarts: 3,
},
]);
await expect(runDoctorJson()).resolves.toMatchObject({
supervisedConnectors: [
{ channel: "slack", instanceId: "cline-slack", state: "backoff" },
],
});
});
it("omits supervision when the hub cannot report it", async () => {
mockListSupervisedConnectors.mockResolvedValue(undefined);
const status = await runDoctorJson();
expect(status.supervisedConnectors).toBeUndefined();
});
it("stays usable when the supervision query fails", async () => {
mockListSupervisedConnectors.mockRejectedValue(new Error("hub gone"));
// Diagnostics must degrade quietly rather than fail.
const status = await runDoctorJson();
expect(status.supervisedConnectors).toBeUndefined();
expect(status).toHaveProperty("hubHealthy");
});
it("formats restart and failure state so a crash loop is visible", () => {
expect(
formatSupervisedConnector({
channel: "slack",
instanceId: "cline-slack",
state: "failed",
origin: "adopted",
pid: 42,
restarts: 5,
lastExitCode: 1,
lastError: "invalid token",
}),
).toBe(
"slack | instance=cline-slack | state=failed | origin=adopted | pid=42 | restarts=5 | lastExit=1 | error=invalid token",
);
});
it("leaves out fields that do not apply to a healthy connector", () => {
expect(
formatSupervisedConnector({
channel: "telegram",
instanceId: "cline_bot",
state: "running",
origin: "spawned",
pid: 7,
restarts: 0,
}),
).toBe(
"telegram | instance=cline_bot | state=running | origin=spawned | pid=7",
);
});
});
describe("describeProcessesStartedDuringFix", () => {
const { describeProcessesStartedDuringFix } = __test__;
const liveParents = new Map([
[100, 10],
[200, 20],
]);
const resolveLiveParent = (pid: number) => liveParents.get(pid);
it("says nothing when no process started during the fix", () => {
expect(
describeProcessesStartedDuringFix([], resolveLiveParent),
).toBeUndefined();
});
it("blames the parent only when every process has a live one", () => {
expect(
describeProcessesStartedDuringFix([100, 200], resolveLiveParent),
).toBe(
"\nThese processes were respawned by a live parent. Stop the parent process listed above, then re-run.",
);
});
// A process can start on its own mid-repair - a user opening a new session,
// say - and telling them to go kill an unrelated parent would be wrong.
it("states the facts when no process has a live parent", () => {
expect(describeProcessesStartedDuringFix([777], resolveLiveParent)).toBe(
"\nThese processes started after the fix began, so they were not targeted. Re-run to see whether they persist.",
);
});
it("separates respawns from independent starts in a mixed batch", () => {
expect(
describeProcessesStartedDuringFix([100, 777], resolveLiveParent),
).toBe(
"\nSome of these were respawned by a live parent (100); stop the parent process listed above, then re-run. The rest started after the fix began and were not targeted.",
);
});
});
+280 -16
View File
@@ -1,5 +1,5 @@
import { spawnSync } from "node:child_process";
import { existsSync, readFileSync, rmSync } from "node:fs";
import { existsSync, readFileSync, readlinkSync, rmSync } from "node:fs";
import { dirname, join } from "node:path";
import {
clearHubDiscovery,
@@ -7,6 +7,7 @@ import {
listActiveConnectors,
probeHubServer,
readHubDiscovery,
readSupersededHubDiscovery,
resolveClineDataDir,
resolveProductionHubOwnerContext,
resolveSharedHubOwnerContext,
@@ -16,6 +17,7 @@ import {
type ActiveConnectorRecord,
formatUptime,
resolveClineBuildEnv,
type SupervisedConnectorRecord,
} from "@cline/shared";
import { Command } from "commander";
import { version as cliVersion } from "../../package.json";
@@ -24,6 +26,7 @@ import { getCliBuildInfo } from "../utils/common";
import open from "../utils/open";
import { c, writeln } from "../utils/output";
import { stopAllConnectors } from "./connect";
import { listSupervisedConnectorsViaHub } from "./connect-via-hub";
type DoctorIo = {
writeln: (text?: string) => void;
@@ -64,6 +67,8 @@ type DoctorStatus = {
staleCliPids: number[];
staleSidecarPids: number[];
activeConnectors: ActiveConnectorRecord[];
/** Undefined when the running hub cannot report supervision. */
supervisedConnectors?: SupervisedConnectorRecord[];
recentSpawnedProcesses: SpawnedProcessRecord[];
};
@@ -72,6 +77,13 @@ type ProcessRecord = {
command: string;
};
// Container id inside a cgroup path, e.g.
// "0::/system.slice/docker-<64-hex>.scope" (docker/containerd/podman) or
// "/kubepods/.../<64-hex>" (kubernetes). Captures the id so two different
// containers can be told apart, not merely "is containerised".
const CONTAINER_CGROUP_PATTERN =
/(?:docker[-/]|containerd[-/]|libpod[-/]|crio[-/]|lxc[-/.])([0-9a-f]{12,64})/;
function parsePids(raw: string): number[] {
return raw
.split(/\r?\n/)
@@ -79,6 +91,77 @@ function parsePids(raw: string): number[] {
.filter((pid) => Number.isInteger(pid) && pid > 0);
}
function tryReadLink(target: string): string | undefined {
try {
return readlinkSync(target);
} catch {
return undefined;
}
}
function readContainerCgroupId(pid: number | "self"): string | undefined {
let raw: string;
try {
raw = readFileSync(`/proc/${pid}/cgroup`, "utf8");
} catch {
return undefined;
}
return raw.match(CONTAINER_CGROUP_PATTERN)?.[1];
}
/**
* Decide whether a process belongs to a container other than our own.
*
* Namespace identity is the reliable signal: a containerised process has
* different PID/mount namespaces than the host process running the scan.
* Container ids parsed from cgroup paths are the fallback for kernels where the
* namespace links are unreadable. Unknown on both sides means "assume ours",
* preserving the previous behaviour rather than silently dropping processes the
* user does want cleaned up.
*/
function decideForeignContainer(input: {
platform: string;
namespacePairs: Array<[string | undefined, string | undefined]>;
ownContainerId: string | undefined;
otherContainerId: string | undefined;
}): boolean {
// /proc/<pid>/ns exists only on Linux. Elsewhere containers run inside a VM
// and never share a pid space with us, so there is nothing to disambiguate.
if (input.platform !== "linux") {
return false;
}
for (const [own, other] of input.namespacePairs) {
if (own && other && own !== other) {
return true;
}
}
return (
Boolean(input.otherContainerId) &&
input.otherContainerId !== input.ownContainerId
);
}
/**
* True when `pid` belongs to a container other than this process's own.
*
* `pgrep` sees every process on the host, containers included: a Docker agent's
* hub daemon shows up beside ours, and when the container shares our uid `kill`
* on it succeeds. Those daemons are emphatically not stale — they belong to a
* live agent with its own data dir — so reporting them, and killing them in
* `doctor fix`, takes down an unrelated agent.
*/
function isForeignContainerPid(pid: number): boolean {
return decideForeignContainer({
platform: process.platform,
namespacePairs: (["pid", "mnt"] as const).map((namespace) => [
tryReadLink(`/proc/self/ns/${namespace}`),
tryReadLink(`/proc/${pid}/ns/${namespace}`),
]),
ownContainerId: readContainerCgroupId("self"),
otherContainerId: readContainerCgroupId(pid),
});
}
function listMatchingProcesses(pattern: string): ProcessRecord[] {
if (process.platform === "win32") {
return [];
@@ -108,7 +191,8 @@ function listMatchingProcesses(pattern: string): ProcessRecord[] {
pid <= 0 ||
!command ||
pid === process.pid ||
pid === process.ppid
pid === process.ppid ||
isForeignContainerPid(pid)
) {
continue;
}
@@ -301,6 +385,12 @@ async function clearHubStartupArtifacts(
await clearHubDiscovery(owner.discoveryPath);
clearedDiscovery = 1;
}
if (options?.clearDiscovery) {
// The set-aside copy the npm postinstall shield leaves behind. Once
// doctor has deliberately stopped everything, keeping it risks a much
// later launch SIGTERMing whatever process has recycled its pid.
clearPathIfExists(`${owner.discoveryPath}.superseded`);
}
return {
startupLocks: clearedStartupLocks,
discovery: clearedDiscovery,
@@ -328,7 +418,25 @@ function resolveCliHubOwnerContext() {
async function collectDoctorStatus(cwd: string): Promise<DoctorStatus> {
const owner = resolveCliHubOwnerContext();
const discovery = await readHubDiscovery(owner.discoveryPath);
// The npm postinstall shield sets the discovery record aside (see
// readSupersededHubDiscovery) while an older hub finishes serving its
// sessions. Without the fallback, doctor cannot see that hub, classifies
// the live daemon as stale, and its "run doctor fix" advice kills the
// sessions the shield exists to protect.
const recorded = await readHubDiscovery(owner.discoveryPath);
// The set-aside record carries only url/token/pid; widen so the two
// sources read uniformly below.
const discovery:
| {
url?: string;
authToken?: string;
pid?: number;
port?: number;
coreVersion?: string;
}
| undefined = recorded?.url
? recorded
: readSupersededHubDiscovery(owner.discoveryPath);
const health = discovery?.url
? await probeHubServer(discovery.url, { authToken: discovery.authToken })
: undefined;
@@ -354,6 +462,7 @@ async function collectDoctorStatus(cwd: string): Promise<DoctorStatus> {
staleCliPids: listStaleCliPids(),
staleSidecarPids: listStaleSidecarPids(),
activeConnectors: listActiveConnectors(),
...((await listSupervisedConnectorsSafely()) ?? {}),
recentSpawnedProcesses: readRecentSpawnedProcesses(),
};
}
@@ -365,6 +474,80 @@ function formatPidList(label: string, pids: number[]): string {
return `${label} ${c.dim}${pids.join(", ")}${c.reset}`;
}
function readParentPid(pid: number): number | undefined {
try {
const output = spawnSync("ps", ["-o", "ppid=", "-p", String(pid)], {
encoding: "utf8",
});
const parsed = Number(output.stdout?.trim());
return Number.isInteger(parsed) && parsed > 0 ? parsed : undefined;
} catch {
return undefined;
}
}
function liveParentPid(pid: number): number | undefined {
const parent = readParentPid(pid);
return parent && isProcessRunning(parent) ? parent : undefined;
}
/**
* A daemon whose parent is still running was almost certainly just spawned by
* that parent, and killing it only invites the parent to spawn another. Naming
* the parent points at the process the user actually has to stop.
*/
function formatDaemonPidList(label: string, pids: number[]): string {
if (pids.length === 0) {
return `${label} ${c.dim}0${c.reset}`;
}
const described = pids.map((pid) => {
const parent = liveParentPid(pid);
return parent ? `${pid} (spawned by ${parent})` : String(pid);
});
return `${label} ${c.dim}${described.join(", ")}${c.reset}`;
}
/**
* Advice for processes first seen during the fix. Only a process with a live
* parent is known to have been respawned by it; anything else may have been
* started independently (a user opening a new session mid-repair), so it gets
* a statement of fact rather than an instruction to go kill something.
*/
export function describeProcessesStartedDuringFix(
pids: number[],
resolveLiveParent: (pid: number) => number | undefined,
): string | undefined {
if (pids.length === 0) {
return undefined;
}
const respawned = pids.filter((pid) => resolveLiveParent(pid) !== undefined);
if (respawned.length === 0) {
return "\nThese processes started after the fix began, so they were not targeted. Re-run to see whether they persist.";
}
if (respawned.length === pids.length) {
return "\nThese processes were respawned by a live parent. Stop the parent process listed above, then re-run.";
}
return `\nSome of these were respawned by a live parent (${respawned.join(", ")}); stop the parent process listed above, then re-run. The rest started after the fix began and were not targeted.`;
}
function formatStartupLockList(
label: string,
locks: StartupArtifact[],
): string {
const described = locks
.map((lock) => {
if (lock.pid === undefined) {
return "unreadable";
}
return lock.stale ? `${lock.pid} (stale)` : `${lock.pid} (held, live)`;
})
.filter((entry) => entry.length > 0);
if (described.length === 0) {
return `${label} ${c.dim}0${c.reset}`;
}
return `${label} ${c.dim}${described.join(", ")}${c.reset}`;
}
function formatRecentSpawnedProcess(record: SpawnedProcessRecord): string {
const pieces = [
record.timestamp ?? "unknown-time",
@@ -378,6 +561,39 @@ function formatRecentSpawnedProcess(record: SpawnedProcessRecord): string {
return pieces.join(" | ");
}
/**
* Supervision is reported by the running hub, so it is unavailable whenever
* there is no hub or it predates supervision. Diagnostics must degrade quietly
* rather than fail.
*/
async function listSupervisedConnectorsSafely(): Promise<
{ supervisedConnectors: SupervisedConnectorRecord[] } | undefined
> {
try {
const supervised = await listSupervisedConnectorsViaHub();
return supervised ? { supervisedConnectors: supervised } : undefined;
} catch {
return undefined;
}
}
function formatSupervisedConnector(record: SupervisedConnectorRecord): string {
const pieces = [
record.channel,
`instance=${record.instanceId}`,
`state=${record.state}`,
`origin=${record.origin}`,
record.pid === undefined ? undefined : `pid=${record.pid}`,
record.restarts > 0 ? `restarts=${record.restarts}` : undefined,
record.nextRestartAt ? `nextRestart=${record.nextRestartAt}` : undefined,
record.lastExitCode === undefined
? undefined
: `lastExit=${record.lastExitCode}`,
record.lastError ? `error=${record.lastError}` : undefined,
];
return pieces.filter(Boolean).join(" | ");
}
function formatActiveConnector(record: ActiveConnectorRecord): string {
const identity =
record.type === "telegram"
@@ -411,6 +627,13 @@ function killPids(pids: number[]): number {
return killed;
}
export const __test__ = {
decideForeignContainer,
CONTAINER_CGROUP_PATTERN,
describeProcessesStartedDuringFix,
formatSupervisedConnector,
};
export async function runDoctorCommand(
opts: { cwd: string; json?: boolean; fix?: boolean; verbose?: boolean },
io: DoctorIo,
@@ -433,13 +656,8 @@ export async function runDoctorCommand(
);
writeln(`hub uptime ${c.dim}${before.hubUptime ?? "n/a"}${c.reset}`);
writeln(formatPidList("hub listeners", before.listeningPids));
writeln(formatPidList("stale hub daemons", before.staleHubPids));
writeln(
formatPidList(
"hub startup locks",
before.hubStartupLocks.map((a) => a.pid ?? -1).filter((pid) => pid > 0),
),
);
writeln(formatDaemonPidList("stale hub daemons", before.staleHubPids));
writeln(formatStartupLockList("hub startup locks", before.hubStartupLocks));
writeln(formatPidList("cli processes", before.staleCliPids));
writeln(formatPidList("sidecar processes", before.staleSidecarPids));
if (before.activeConnectors.length === 0) {
@@ -450,6 +668,12 @@ export async function runDoctorCommand(
writeln(`- ${c.dim}${formatActiveConnector(record)}${c.reset}`);
}
}
if (before.supervisedConnectors?.length) {
writeln("hub-supervised connectors:");
for (const record of before.supervisedConnectors) {
writeln(`- ${c.dim}${formatSupervisedConnector(record)}${c.reset}`);
}
}
if (verbose && before.recentSpawnedProcesses.length > 0) {
writeln("recent spawned processes:");
for (const record of before.recentSpawnedProcesses) {
@@ -544,16 +768,56 @@ export async function runDoctorCommand(
`cleared hub discovery records ${c.dim}${clearedArtifacts.discovery}${c.reset}`,
);
writeln(`hub healthy after fix: ${after.hubHealthy ? "yes" : "no"}`);
writeln(formatPidList("remaining hub listeners", after.listeningPids));
writeln(formatPidList("remaining stale hub daemons", after.staleHubPids));
// "Remaining" means a process this run tried to kill and failed to. A
// re-scan alone cannot tell that apart from a process that appeared while
// the fix was running, and reporting the two together reads as a failure
// to kill something that was never targeted.
const survived = (targets: number[], remaining: number[]) =>
remaining.filter((pid) => targets.includes(pid));
const appeared = (targets: number[], remaining: number[]) =>
remaining.filter((pid) => !targets.includes(pid));
writeln(
formatPidList(
"remaining hub startup locks",
after.hubStartupLocks.map((a) => a.pid ?? -1).filter((pid) => pid > 0),
"remaining hub listeners",
survived(refreshedAfterGracefulStop.listeningPids, after.listeningPids),
),
);
writeln(formatPidList("remaining cli processes", after.staleCliPids));
writeln(formatPidList("remaining sidecar processes", after.staleSidecarPids));
writeln(
formatDaemonPidList(
"remaining stale hub daemons",
survived(staleHubTargets, after.staleHubPids),
),
);
writeln(
formatStartupLockList("remaining hub startup locks", after.hubStartupLocks),
);
writeln(
formatPidList(
"remaining cli processes",
survived(staleCliTargets, after.staleCliPids),
),
);
writeln(
formatPidList(
"remaining sidecar processes",
survived(staleSidecarTargets, after.staleSidecarPids),
),
);
const spawnedDuringFix = [
...appeared(staleHubTargets, after.staleHubPids),
...appeared(staleCliTargets, after.staleCliPids),
...appeared(staleSidecarTargets, after.staleSidecarPids),
];
if (spawnedDuringFix.length > 0) {
writeln(formatDaemonPidList("started during fix", spawnedDuringFix));
const advice = describeProcessesStartedDuringFix(
spawnedDuringFix,
liveParentPid,
);
if (advice) {
io.writeln(advice);
}
}
return 0;
}
+146 -1
View File
@@ -1,9 +1,13 @@
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { installMcpServer } from "@cline/core";
import { describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
buildMcpInstallDefaults,
buildMcpInstallTransport,
runMcpInstallCommand,
runMcpUninstallCommand,
} from "./mcp";
vi.mock("@cline/core", async (importOriginal) => {
@@ -56,6 +60,19 @@ describe("mcp install command", () => {
});
});
it("shows mcp-remote marketplace entries as native remote servers", () => {
expect(
buildMcpInstallDefaults({
name: "linear",
targetArgs: ["npx", "-y", "mcp-remote", "https://mcp.linear.app/mcp"],
}),
).toEqual({
name: "linear",
type: "streamableHttp",
url: "https://mcp.linear.app/mcp",
});
});
it("normalizes streamable-http transport", () => {
expect(
buildMcpInstallDefaults({
@@ -269,3 +286,131 @@ describe("mcp install command", () => {
});
});
});
describe("mcp uninstall command", () => {
let root = "";
beforeEach(() => {
root = mkdtempSync(join(tmpdir(), "cli-mcp-uninstall-"));
});
afterEach(() => {
rmSync(root, { recursive: true, force: true });
});
function writeSettings(): string {
const settingsPath = join(root, "cline_mcp_settings.json");
writeFileSync(
settingsPath,
JSON.stringify(
{
mcpServers: {
docs: {
transport: {
type: "streamableHttp",
url: "https://example.com/mcp",
},
},
keep: {
transport: { type: "stdio", command: "node" },
disabled: true,
},
},
customTopLevelKey: true,
},
null,
2,
),
"utf8",
);
return settingsPath;
}
function readSettings(settingsPath: string): Record<string, unknown> & {
mcpServers?: Record<string, unknown>;
} {
return JSON.parse(readFileSync(settingsPath, "utf8")) as Record<
string,
unknown
> & { mcpServers?: Record<string, unknown> };
}
it("uninstalls the requested server and reports success", async () => {
const settingsPath = writeSettings();
const writeln = vi.fn();
const writeErr = vi.fn();
const code = await runMcpUninstallCommand({
name: "docs",
settingsPath,
io: { writeln, writeErr },
});
expect(code).toBe(0);
expect(writeln).toHaveBeenCalledWith("Uninstalled MCP server docs.");
expect(writeErr).not.toHaveBeenCalled();
const written = readSettings(settingsPath);
expect(Object.keys(written.mcpServers ?? {})).toEqual(["keep"]);
expect(written.mcpServers?.keep).toEqual({
transport: { type: "stdio", command: "node" },
disabled: true,
});
expect(written.customTopLevelKey).toBe(true);
});
it("prints uninstall JSON with --json", async () => {
const settingsPath = writeSettings();
const writeln = vi.fn();
const code = await runMcpUninstallCommand({
name: "docs",
settingsPath,
json: true,
io: { writeln, writeErr: vi.fn() },
});
expect(code).toBe(0);
expect(JSON.parse(writeln.mock.calls[0]?.[0])).toEqual({
name: "docs",
status: "uninstalled",
});
expect(writeln).toHaveBeenCalledTimes(1);
});
it("reports an error and leaves settings intact for an unknown server", async () => {
const settingsPath = writeSettings();
const before = readFileSync(settingsPath, "utf8");
const writeln = vi.fn();
const writeErr = vi.fn();
const code = await runMcpUninstallCommand({
name: "missing",
settingsPath,
io: { writeln, writeErr },
});
expect(code).toBe(1);
expect(writeErr).toHaveBeenCalledWith(
'MCP server "missing" is not installed.',
);
expect(writeln).not.toHaveBeenCalled();
expect(readFileSync(settingsPath, "utf8")).toBe(before);
});
it("rejects a blank name without rewriting settings", async () => {
const settingsPath = writeSettings();
const before = readFileSync(settingsPath, "utf8");
const writeErr = vi.fn();
const code = await runMcpUninstallCommand({
name: " ",
settingsPath,
io: { writeErr },
});
expect(code).toBe(1);
expect(writeErr).toHaveBeenCalledWith("MCP server name is required");
expect(readFileSync(settingsPath, "utf8")).toBe(before);
});
});
+52 -58
View File
@@ -1,12 +1,16 @@
import {
buildMcpInstallTransport as buildCoreMcpInstallTransport,
type McpInstallOptions as CoreMcpInstallOptions,
installMcpServer,
type McpInstallResult,
type McpServerTransportConfig,
type McpUninstallOptions as CoreMcpUninstallOptions,
type McpUninstallResult as CoreMcpUninstallResult,
uninstallMcpServer,
} from "@cline/core";
import type { McpAddDefaults } from "../wizards/mcp";
export { buildMcpInstallTransport } from "@cline/core";
export { buildMcpInstallTransport, uninstallMcpServer } from "@cline/core";
export interface McpCommandIo {
writeln?: (text: string) => void;
@@ -28,39 +32,6 @@ export interface McpInstallDirectResult {
warnings: string[];
}
function normalizeTransportType(
value: string | undefined,
): McpServerTransportConfig["type"] {
const normalized = (value ?? "stdio").trim();
if (normalized === "http" || normalized === "streamable-http") {
return "streamableHttp";
}
if (
normalized === "stdio" ||
normalized === "sse" ||
normalized === "streamableHttp"
) {
return normalized;
}
throw new Error(
`Unsupported MCP transport "${normalized}". Expected stdio, sse, http, streamable-http, or streamableHttp.`,
);
}
function assertValidUrl(url: string): void {
let parsed: URL;
try {
parsed = new URL(url);
} catch {
throw new Error(`Invalid MCP server URL: ${url}`);
}
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
throw new Error(
`Invalid MCP server URL: ${url} (only http and https are supported)`,
);
}
}
function quoteCommandArg(arg: string): string {
if (/^[^\s"'\\]+$/.test(arg)) {
return arg;
@@ -73,36 +44,20 @@ export function buildMcpInstallDefaults(options: {
targetArgs?: string[];
transport?: string;
}): McpAddDefaults {
const name = options.name.trim();
if (!name) {
throw new Error("MCP server name is required");
}
const type = normalizeTransportType(options.transport);
const targetArgs = options.targetArgs ?? [];
if (type === "stdio") {
if (targetArgs.length === 0) {
throw new Error(
"Stdio MCP install requires a command after the server name, for example: cline mcp install fs -- npx -y @modelcontextprotocol/server-filesystem /tmp",
);
}
const { name, transport } = buildCoreMcpInstallTransport(options);
if (transport.type === "stdio") {
return {
name,
type,
command: targetArgs.map(quoteCommandArg).join(" "),
type: transport.type,
command: [transport.command, ...(transport.args ?? [])]
.map(quoteCommandArg)
.join(" "),
};
}
if (targetArgs.length !== 1) {
throw new Error(
"Remote MCP install requires exactly one URL argument after the server name.",
);
}
const url = targetArgs[0]?.trim() ?? "";
assertValidUrl(url);
return {
name,
type,
url,
type: transport.type,
url: transport.url,
};
}
@@ -158,3 +113,42 @@ export async function runMcpInstallCommand(
return 1;
}
}
export interface McpUninstallOptions extends CoreMcpUninstallOptions {
io?: McpCommandIo;
json?: boolean;
}
export interface McpUninstallDirectResult extends CoreMcpUninstallResult {}
export function uninstallMcpServerDirect(
options: McpUninstallOptions,
): McpUninstallDirectResult {
const result: CoreMcpUninstallResult = uninstallMcpServer(options);
return {
name: result.name,
status: result.status,
};
}
export async function runMcpUninstallCommand(
options: McpUninstallOptions,
): Promise<number> {
try {
const name = options.name?.trim() ?? "";
if (!name) {
throw new Error("MCP server name is required");
}
const result = uninstallMcpServerDirect({ ...options, name });
if (options.json) {
options.io?.writeln?.(JSON.stringify(result));
} else {
options.io?.writeln?.(`Uninstalled MCP server ${result.name}.`);
}
return 0;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
options.io?.writeErr(message);
return 1;
}
}
+177 -4
View File
@@ -6,11 +6,29 @@ import { createScheduleCommand } from "./schedule";
const mockSendHubCommand = vi.hoisted(() => vi.fn());
const mockEnsureCliHubServer = vi.hoisted(() => vi.fn());
vi.mock("@cline/core", () => ({
sendHubCommand: mockSendHubCommand,
const mockProviderSettings = vi.hoisted(() => ({
lastUsed: undefined as { provider?: string; model?: string } | undefined,
providers: {} as Record<string, { provider?: string; model?: string }>,
}));
vi.mock("@cline/core", async () => {
const actual =
await vi.importActual<typeof import("@cline/core")>("@cline/core");
return {
...actual,
sendHubCommand: mockSendHubCommand,
ProviderSettingsManager: class {
getLastUsedProviderSettings() {
return mockProviderSettings.lastUsed;
}
getProviderSettings(providerId: string) {
return mockProviderSettings.providers[providerId];
}
},
};
});
vi.mock("../utils/hub-runtime", () => ({
ensureCliHubServer: mockEnsureCliHubServer,
parseHubEndpointOverride: (rawAddress: string | undefined) => {
@@ -47,6 +65,8 @@ async function runScheduleCommand(
describe("runScheduleCommand list output", () => {
afterEach(() => {
vi.clearAllMocks();
mockProviderSettings.lastUsed = undefined;
mockProviderSettings.providers = {};
});
it('prints "No schedules found." for empty non-json list output', async () => {
@@ -121,9 +141,158 @@ describe("runScheduleCommand list output", () => {
});
});
describe("runScheduleCommand create delivery metadata", () => {
describe("runScheduleCommand create", () => {
afterEach(() => {
vi.clearAllMocks();
mockProviderSettings.lastUsed = undefined;
mockProviderSettings.providers = {};
});
it("uses the last used provider and model when both flags are omitted", async () => {
mockProviderSettings.lastUsed = {
provider: "anthropic",
model: "claude-sonnet-4-6",
};
mockEnsureCliHubServer.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
authToken: "test-token",
});
mockSendHubCommand.mockResolvedValue({
ok: true,
payload: { schedule: { scheduleId: "sched_123" } },
});
const output: string[] = [];
const errors: string[] = [];
const code = await runScheduleCommand(
[
"create",
"Health check",
"--cron",
"0 */6 * * *",
"--prompt",
"Run tests",
"--workspace",
"/tmp/workspace",
"--address",
"127.0.0.1:25463",
],
{
writeln: (text?: string) => {
output.push(text ?? "");
},
writeErr: (text: string) => {
errors.push(text);
},
},
);
expect(code).toBe(0);
expect(errors).toEqual([]);
expect(mockSendHubCommand).toHaveBeenCalledWith(
{ host: "127.0.0.1", port: 25463, pathname: "/hub" },
expect.objectContaining({
clientId: "cline-schedule",
command: "schedule.create",
payload: expect.objectContaining({
provider: "anthropic",
model: "claude-sonnet-4-6",
}),
}),
);
});
it("uses an explicit provider with that provider's configured model", async () => {
mockProviderSettings.lastUsed = {
provider: "cline",
model: "openai/gpt-5.3-codex",
};
mockProviderSettings.providers.anthropic = {
provider: "anthropic",
model: "claude-sonnet-4-6",
};
mockEnsureCliHubServer.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
authToken: "test-token",
});
mockSendHubCommand.mockResolvedValue({
ok: true,
payload: { schedule: { scheduleId: "sched_123" } },
});
const errors: string[] = [];
const code = await runScheduleCommand(
[
"create",
"Health check",
"--cron",
"0 */6 * * *",
"--prompt",
"Run tests",
"--workspace",
"/tmp/workspace",
"--provider",
"anthropic",
"--address",
"127.0.0.1:25463",
],
{
writeln: () => {},
writeErr: (text: string) => {
errors.push(text);
},
},
);
expect(code).toBe(0);
expect(errors).toEqual([]);
expect(mockSendHubCommand).toHaveBeenCalledWith(
{ host: "127.0.0.1", port: 25463, pathname: "/hub" },
expect.objectContaining({
command: "schedule.create",
payload: expect.objectContaining({
provider: "anthropic",
model: "claude-sonnet-4-6",
}),
}),
);
});
it("fails when an explicit provider has no configured model and no model flag", async () => {
mockEnsureCliHubServer.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
authToken: "test-token",
});
const errors: string[] = [];
const code = await runScheduleCommand(
[
"create",
"Health check",
"--cron",
"0 */6 * * *",
"--prompt",
"Run tests",
"--workspace",
"/tmp/workspace",
"--provider",
"anthropic",
"--address",
"127.0.0.1:25463",
],
{
writeln: () => {},
writeErr: (text: string) => {
errors.push(text);
},
},
);
expect(code).toBe(1);
expect(errors).toEqual([
'No model is configured for provider "anthropic". Pass --model or save a model for that provider before creating the schedule.',
]);
expect(mockSendHubCommand).not.toHaveBeenCalled();
});
it("maps --delivery-bot to delivery.userName", async () => {
@@ -192,6 +361,8 @@ describe("runScheduleCommand create delivery metadata", () => {
describe("runScheduleCommand import", () => {
afterEach(() => {
vi.clearAllMocks();
mockProviderSettings.lastUsed = undefined;
mockProviderSettings.providers = {};
});
it("preserves exported modelSelection providerId/modelId values", async () => {
@@ -257,6 +428,8 @@ describe("runScheduleCommand import", () => {
describe("runScheduleCommand export", () => {
afterEach(() => {
vi.clearAllMocks();
mockProviderSettings.lastUsed = undefined;
mockProviderSettings.providers = {};
});
it("writes JSON content to the --to file path", async () => {
+9 -5
View File
@@ -1,4 +1,3 @@
import { CLINE_DEFAULT_MODEL_ID } from "@cline/shared";
import type { Command } from "commander";
import { ensureSchedulerHub } from "./client";
import {
@@ -19,6 +18,7 @@ import {
registerScheduleImportCommand,
registerScheduleUpdateCommand,
} from "./import-export";
import { resolveScheduleModelSelection } from "./model-selection";
import type { CommandIo, ScheduleActionWrapper } from "./types";
export function registerScheduleCommands(
@@ -66,8 +66,8 @@ export function registerScheduleCommands(
.option("--max-parallel <n>", "Max parallel executions", "1")
.option("--metadata-json <json>", "Metadata as JSON object")
.option("--mode <act|plan|yolo>", "Execution mode", "yolo")
.option("--model <model>", "Model to use", CLINE_DEFAULT_MODEL_ID)
.option("--provider <id>", "Provider ID", "cline")
.option("--model <model>", "Model to use")
.option("--provider <id>", "Provider ID")
.option("--system-prompt <text>", "System prompt override")
.option("--tags <list>", "Comma-separated tags")
.option("--timeout <seconds>", "Timeout in seconds");
@@ -92,12 +92,16 @@ export function registerScheduleCommands(
parseJsonObjectFlag(opts.metadataJson),
opts,
);
const modelSelection = resolveScheduleModelSelection({
provider: opts.provider,
model: opts.model,
});
const created = await client.createSchedule({
name,
cronPattern: opts.cron,
prompt: opts.prompt,
provider: opts.provider,
model: opts.model,
provider: modelSelection.provider,
model: modelSelection.model,
mode: parseMode(opts.mode) ?? "yolo",
workspaceRoot: opts.workspace,
cwd: opts.cwd,
+15 -14
View File
@@ -1,6 +1,5 @@
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { dirname, isAbsolute, resolve } from "node:path";
import { CLINE_DEFAULT_MODEL_ID } from "@cline/shared";
import type { Command } from "commander";
import { ensureSchedulerHub } from "./client";
import {
@@ -18,8 +17,13 @@ import {
resolveAddress,
toPositiveInt,
} from "./common";
import { resolveScheduleModelSelection } from "./model-selection";
import type { CommandIo, ScheduleActionWrapper } from "./types";
function stringValue(value: unknown): string | undefined {
return typeof value === "string" ? value : undefined;
}
function resolveImportedModelSelection(parsed: Record<string, unknown>): {
provider: string;
model: string;
@@ -30,19 +34,16 @@ function resolveImportedModelSelection(parsed: Record<string, unknown>): {
!Array.isArray(parsed.modelSelection)
? (parsed.modelSelection as Record<string, unknown>)
: undefined;
const provider = String(
modelSelection?.providerId ??
parsed.providerId ??
parsed.provider ??
"cline",
).trim();
const model = String(
modelSelection?.modelId ??
parsed.modelId ??
parsed.model ??
CLINE_DEFAULT_MODEL_ID,
).trim();
return { provider, model };
return resolveScheduleModelSelection({
provider:
stringValue(modelSelection?.providerId) ??
stringValue(parsed.providerId) ??
stringValue(parsed.provider),
model:
stringValue(modelSelection?.modelId) ??
stringValue(parsed.modelId) ??
stringValue(parsed.model),
});
}
export function registerScheduleExportCommand(
@@ -0,0 +1,52 @@
import { type ProviderSettings, ProviderSettingsManager } from "@cline/core";
import { CLINE_DEFAULT_MODEL_ID } from "@cline/shared";
export const DEFAULT_SCHEDULE_PROVIDER = "cline";
interface ProviderSettingsReader {
getLastUsedProviderSettings(): ProviderSettings | undefined;
getProviderSettings(providerId: string): ProviderSettings | undefined;
}
function trimToUndefined(value: string | undefined): string | undefined {
const trimmed = value?.trim();
return trimmed ? trimmed : undefined;
}
export function resolveScheduleModelSelection(
options: {
provider?: string;
model?: string;
},
providerSettingsManager?: ProviderSettingsReader,
): { provider: string; model: string } {
const explicitProvider = trimToUndefined(options.provider);
const explicitModel = trimToUndefined(options.model);
if (explicitProvider && explicitModel) {
return { provider: explicitProvider, model: explicitModel };
}
const manager = providerSettingsManager ?? new ProviderSettingsManager();
const lastUsedSettings = manager.getLastUsedProviderSettings();
const provider =
explicitProvider ??
trimToUndefined(lastUsedSettings?.provider) ??
DEFAULT_SCHEDULE_PROVIDER;
const selectedProviderSettings = explicitProvider
? manager.getProviderSettings(provider)
: lastUsedSettings;
const model =
explicitModel ??
trimToUndefined(selectedProviderSettings?.model) ??
(provider === DEFAULT_SCHEDULE_PROVIDER
? CLINE_DEFAULT_MODEL_ID
: undefined);
if (!model) {
throw new Error(
`No model is configured for provider "${provider}". Pass --model or save a model for that provider before creating the schedule.`,
);
}
return { provider, model };
}
+86 -68
View File
@@ -1,12 +1,10 @@
import type { ChildProcess } from "node:child_process";
import { EventEmitter } from "node:events";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
const { mockEnsureCliHubServer, mockSpawn } = vi.hoisted(() => ({
mockEnsureCliHubServer: vi.fn(),
const { mockSpawn } = vi.hoisted(() => ({
mockSpawn: vi.fn(),
}));
@@ -18,14 +16,10 @@ vi.mock("node:child_process", async (importOriginal) => {
};
});
vi.mock("../utils/hub-runtime", () => ({
ensureCliHubServer: mockEnsureCliHubServer,
}));
import {
applyDeferredUpdate,
autoUpdateOnStartup,
checkForUpdates,
ensureCliHubServerAfterUpdate,
getInstallationInfo,
PackageManager,
resolveCliHubOwnerContext,
@@ -42,14 +36,6 @@ const originalIsDev = process.env.IS_DEV;
const originalNoAutoUpdate = process.env.CLINE_NO_AUTO_UPDATE;
const tempDirs: string[] = [];
function createChildProcessThatCloses(exitCode: number): ChildProcess {
const child = new EventEmitter();
queueMicrotask(() => {
child.emit("close", exitCode);
});
return child as ChildProcess;
}
function createFile(path: string): string {
mkdirSync(dirname(path), { recursive: true });
writeFileSync(path, "");
@@ -265,68 +251,100 @@ describe("hub restart owner selection", () => {
});
});
describe("post-update hub launch", () => {
describe("deferred auto update", () => {
afterEach(() => {
mockEnsureCliHubServer.mockReset();
mockSpawn.mockReset();
if (originalBuildEnv === undefined) {
delete process.env.CLINE_BUILD_ENV;
} else {
process.env.CLINE_BUILD_ENV = originalBuildEnv;
}
if (originalHubDiscoveryPath === undefined) {
delete process.env.CLINE_HUB_DISCOVERY_PATH;
} else {
process.env.CLINE_HUB_DISCOVERY_PATH = originalHubDiscoveryPath;
}
for (const dir of tempDirs.splice(0)) {
rmSync(dir, { recursive: true, force: true });
}
});
it("uses the freshly installed wrapper instead of the current executable", async () => {
mockSpawn.mockReturnValue(createChildProcessThatCloses(0));
const env = {
CLINE_WRAPPER_PATH: "/opt/cline/lib/node_modules/cline/bin/cline",
CLINE_NO_AUTO_UPDATE: "0",
};
await ensureCliHubServerAfterUpdate("/workspace/project", env, "linux");
expect(mockSpawn).toHaveBeenCalledWith(
"/opt/cline/lib/node_modules/cline/bin/cline",
["hub", "ensure"],
{
cwd: "/workspace/project",
env: {
...env,
CLINE_NO_AUTO_UPDATE: "1",
},
stdio: "ignore",
windowsHide: true,
},
);
expect(mockEnsureCliHubServer).not.toHaveBeenCalled();
});
it("uses the in-process ensure path when no executable cache can be deleted", async () => {
mockEnsureCliHubServer.mockResolvedValue({
url: "ws://127.0.0.1:25463/hub",
authToken: "token",
});
await ensureCliHubServerAfterUpdate(
"C:\\workspace\\project",
{ CLINE_WRAPPER_PATH: "C:\\npm\\node_modules\\cline\\bin\\cline" },
"win32",
);
expect(mockEnsureCliHubServer).toHaveBeenCalledWith(
"C:\\workspace\\project",
);
it("does nothing when no update was recorded", async () => {
expect(await applyDeferredUpdate(undefined)).toBe("none");
expect(mockSpawn).not.toHaveBeenCalled();
});
it("surfaces a failure from the freshly installed CLI", async () => {
mockSpawn.mockReturnValue(createChildProcessThatCloses(1));
it("starts the detached install when no hub is discoverable", async () => {
const root = mkdtempSync(join(tmpdir(), "cline-update-test-"));
tempDirs.push(root);
process.env.CLINE_BUILD_ENV = "production";
process.env.CLINE_HUB_DISCOVERY_PATH = join(root, "production.json");
const unref = vi.fn();
mockSpawn.mockReturnValue({ unref } as unknown as ChildProcess);
await expect(
ensureCliHubServerAfterUpdate(
"/workspace/project",
{ CLINE_WRAPPER_PATH: "/opt/cline/bin/cline" },
"linux",
),
).rejects.toThrow(
"freshly installed Cline failed to start the hub (exit code 1)",
const outcome = await applyDeferredUpdate({
command: "npm update -g cline --tag latest --min-release-age=0",
});
expect(outcome).toBe("started");
expect(mockSpawn).toHaveBeenCalledWith(
"npm update -g cline --tag latest --min-release-age=0",
expect.objectContaining({
detached: true,
shell: true,
stdio: "ignore",
}),
);
expect(unref).toHaveBeenCalled();
});
it("defers while another cli client is attached to the hub", async () => {
const root = mkdtempSync(join(tmpdir(), "cline-update-test-"));
tempDirs.push(root);
const discoveryPath = join(root, "production.json");
process.env.CLINE_BUILD_ENV = "production";
process.env.CLINE_HUB_DISCOVERY_PATH = discoveryPath;
const {
createLocalHubScheduleRuntimeHandlers,
NodeHubClient,
startHubWebSocketServer,
} = await import("@cline/core");
const server = await startHubWebSocketServer({
host: "127.0.0.1",
port: 0,
owner: { ownerId: "update-test", discoveryPath },
runtimeHandlers: createLocalHubScheduleRuntimeHandlers(),
});
const cliClient = new NodeHubClient({
url: server.url,
authToken: server.authToken,
clientType: "cli",
displayName: "fake attached cli",
});
try {
await cliClient.command("client.list", {});
expect(await applyDeferredUpdate({ command: "echo update" })).toBe(
"deferred",
);
expect(mockSpawn).not.toHaveBeenCalled();
await cliClient.dispose();
const unref = vi.fn();
mockSpawn.mockReturnValue({ unref } as unknown as ChildProcess);
// The hub unregisters the client when its socket closes; poll
// briefly rather than assuming the close is processed instantly.
let outcome = "deferred";
const deadline = Date.now() + 3_000;
while (outcome === "deferred" && Date.now() < deadline) {
outcome = await applyDeferredUpdate({ command: "echo update" });
}
expect(outcome).toBe("started");
} finally {
await cliClient.dispose().catch(() => undefined);
await server.close();
}
}, 15_000);
});
describe("withMinimumReleaseAgeBypass", () => {
+137 -134
View File
@@ -1,17 +1,14 @@
import { type ChildProcess, spawn } from "node:child_process";
import { realpathSync } from "node:fs";
import {
clearHubDiscovery,
isAutoUpdateEnabledGlobally,
probeHubServer,
NodeHubClient,
readHubDiscovery,
resolveProductionHubOwnerContext,
resolveSharedHubOwnerContext,
stopLocalHubServerGracefully,
} from "@cline/core";
import { resolveClineBuildEnv } from "@cline/shared";
import { version } from "../../package.json";
import { ensureCliHubServer } from "../utils/hub-runtime";
import { c, writeErr, writeln } from "../utils/output";
import {
getInstalledKanbanVersion,
@@ -237,50 +234,6 @@ async function runKanbanUpdate(
return waitForProcessExit(updateProcess);
}
/**
* Start the hub through the freshly installed CLI after a self-update.
*
* On Unix, the npm wrapper normally starts the CLI from bin/.cline. npm 12 may
* remove that cached executable while replacing the package and then block the
* postinstall script that recreates it. The current process keeps running from
* the unlinked executable, but process.execPath is no longer spawnable. Going
* back through the wrapper makes it resolve the newly installed platform
* binary instead.
*
* Windows does not create the bin/.cline cache, and development builds do not
* have CLINE_WRAPPER_PATH, so those cases keep using the normal in-process
* ensure path.
*/
export async function ensureCliHubServerAfterUpdate(
workspaceRoot: string,
env: NodeJS.ProcessEnv = process.env,
platform: NodeJS.Platform = process.platform,
): Promise<void> {
const wrapperPath = env.CLINE_WRAPPER_PATH?.trim();
if (!wrapperPath || platform === "win32") {
await ensureCliHubServer(workspaceRoot);
return;
}
const child = spawn(wrapperPath, ["hub", "ensure"], {
cwd: workspaceRoot,
env: {
...env,
// The fresh CLI only exists to start the hub. Do not let it launch
// another background update check while this update is finishing.
CLINE_NO_AUTO_UPDATE: "1",
},
stdio: "ignore",
windowsHide: true,
});
const exitCode = await waitForProcessExit(child);
if (exitCode !== 0) {
throw new Error(
`freshly installed Cline failed to start the hub (exit code ${exitCode})`,
);
}
}
function formatUpdateSummaryTargets(targets: string[]): string {
if (targets.length === 0) {
return "";
@@ -318,86 +271,40 @@ export function getPreferredKanbanInstaller(
);
}
const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
export function resolveCliHubOwnerContext() {
return resolveClineBuildEnv() === "production"
? resolveProductionHubOwnerContext()
: resolveSharedHubOwnerContext();
}
async function waitForHubToStop(
url: string,
authToken: string | undefined,
timeoutMs: number,
): Promise<boolean> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const check = await probeHubServer(url, { authToken }).catch(
() => undefined,
);
if (!check?.url) return true;
await sleep(100);
}
return false;
}
let pendingAutoUpdate: ManualUpdateCommand | undefined;
let pendingAutoUpdateCheck: Promise<void> | undefined;
/**
* Restart the hub server if one is currently running.
* Gracefully asks the running hub process to stop, falls back to process signals,
* clears stale discovery, then re-ensures a fresh instance is spawned.
*/
async function restartHubServerIfRunning(): Promise<void> {
const owner = resolveCliHubOwnerContext();
const discovery = await readHubDiscovery(owner.discoveryPath).catch(
() => undefined,
);
const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
const health = discovery?.url
? await probeHubServer(discovery.url, {
authToken: discovery.authToken,
}).catch(() => undefined)
: undefined;
if (!discovery || !health?.url) return;
// How long the exit sequence will wait for a still-in-flight startup version
// check before giving up on it. Long enough for a typical registry response,
// short enough that one-shot commands do not feel it.
const UPDATE_CHECK_EXIT_GRACE_MS = 250;
const pid = discovery?.pid;
writeln(`${c.dim}[hub] restarting server…${c.reset}`);
let stopped = await stopLocalHubServerGracefully(owner).catch(() => false);
if (!stopped && pid) {
try {
process.kill(pid, "SIGTERM");
} catch {
// best-effort
}
}
stopped = await waitForHubToStop(health.url, discovery.authToken, 3_000);
if (!stopped && pid) {
try {
process.kill(pid, "SIGKILL");
} catch {
// best-effort
}
stopped = await waitForHubToStop(health.url, discovery.authToken, 2_000);
}
await clearHubDiscovery(owner.discoveryPath).catch(() => undefined);
// Re-ensure a fresh hub instance is spawned.
try {
await ensureCliHubServerAfterUpdate(process.cwd());
writeln(`${c.green}${c.reset} ${c.dim}[hub] server restarted${c.reset}`);
} catch (err) {
writeErr(
`[hub] failed to restart server: ${err instanceof Error ? err.message : String(err)}`,
);
}
}
// Hard cap on the exit-time hub query. The hub client's default connect and
// command timeouts add up to tens of seconds against a wedged hub, and this
// runs while the user is waiting for their shell prompt back.
const CLIENT_COUNT_EXIT_TIMEOUT_MS = 3_000;
/**
* Non-blocking auto-update check for CLI startup.
* Spawns a detached install process if a newer version is available.
*
* Deliberately does NOT install right away: replacing the npm package while
* cline processes are running swaps the binary under them — their respawn
* paths break on the new build fingerprint — and historically also restarted
* the hub daemon out from under live sessions. The check only records that an
* update is available; the CLI entrypoint calls applyDeferredUpdate() from
* its exit sequence (an explicit process.exit() follows, so a beforeExit hook
* would never fire), and the install runs only when no other CLI is attached
* to the hub — at that point nothing is running that the swap could hurt.
* The next launch picks up the new binary and a fresh hub.
*
* Skipped for npx, dev, unknown installs. Disable with CLINE_NO_AUTO_UPDATE=1.
*/
export function autoUpdateOnStartup(): void {
@@ -409,35 +316,129 @@ export function autoUpdateOnStartup(): void {
getInstallationInfo(version);
if (!updateCommand) return;
void (async () => {
pendingAutoUpdateCheck = (async () => {
try {
const latest = await getLatestVersion(packageName, version);
if (!latest || compareVersions(version, latest) >= 0) return;
const autoUpdateCommand = withMinimumReleaseAgeBypass(
pendingAutoUpdate = withMinimumReleaseAgeBypass(
updateCommand,
packageManager,
);
const child = spawn(autoUpdateCommand.command, {
shell: true,
detached: true,
stdio: "ignore",
env: autoUpdateCommand.env
? { ...process.env, ...autoUpdateCommand.env }
: process.env,
// Prevent a console window from flashing on Windows; detached
// processes otherwise allocate a new visible console.
windowsHide: true,
});
const exitCode = await waitForProcessExit(child);
if (exitCode === 0) {
await restartHubServerIfRunning();
}
} catch {
// Best-effort, silently ignore
}
})();
}
/**
* True when a hub is reachable and another cli* client is attached to it.
* Only cli* clients run the npm-installed binary — desktop sidecars and
* connectors ship their own — so only they make the swap unsafe. This runs
* after the entrypoint's disposeAll(), so this process's own registrations
* are closed and any cli client still listed belongs to another process. Errors count as attached:
* never install unless the hub positively confirms nothing would be hurt.
*/
async function otherCliClientsAttached(): Promise<boolean> {
const owner = resolveCliHubOwnerContext();
const discovery = await readHubDiscovery(owner.discoveryPath).catch(
() => undefined,
);
if (!discovery?.url) {
return false;
}
const client = new NodeHubClient({
url: discovery.url,
authToken: discovery.authToken,
clientType: "cli-update-check",
displayName: "cline update check",
});
try {
const reply = await client.command("client.list", {}, undefined, {
timeoutMs: CLIENT_COUNT_EXIT_TIMEOUT_MS,
});
const clients =
(reply.payload as { clients?: Array<{ clientType?: unknown }> })
.clients ?? [];
if (
clients.some(
(entry) =>
typeof entry?.clientType === "string" &&
entry.clientType.startsWith("cli") &&
entry.clientType !== "cli-update-check",
)
) {
return true;
}
// A TUI's registration can be lost in transport churn while its session
// connection survives (observed in review), so an empty client list is
// not proof of safety. Cross-check for sessions somebody is attached to.
// Participants, not session status: finished sessions can linger idle
// forever and must not pin updates, and participant-less scheduled runs
// live in the hub process, which a binary swap does not touch.
const sessions = await client.command(
"session.list",
{ limit: 500 },
undefined,
{ timeoutMs: CLIENT_COUNT_EXIT_TIMEOUT_MS },
);
const sessionRecords =
(sessions.payload as { sessions?: Array<{ participants?: unknown }> })
.sessions ?? [];
return sessionRecords.some(
(session) =>
Array.isArray(session?.participants) && session.participants.length > 0,
);
} finally {
await client.dispose().catch(() => undefined);
}
}
/**
* Spawns the recorded update install, detached, if no other CLI would be
* affected by the package swap. Fire-and-forget: the install outlives this
* process and its postinstall never blocks an exit.
*/
export async function applyDeferredUpdate(
pending?: ManualUpdateCommand,
): Promise<"none" | "deferred" | "started"> {
if (!pending) {
// Short-lived commands can reach exit before the startup version check
// resolves; give it a brief grace so one-shot-only usage still updates.
if (pendingAutoUpdateCheck) {
await Promise.race([
pendingAutoUpdateCheck,
sleep(UPDATE_CHECK_EXIT_GRACE_MS),
]);
}
pending = pendingAutoUpdate;
}
if (!pending) {
return "none";
}
// The whole query is bounded: the user is waiting on their prompt, and a
// wedged hub must not turn a finished command into a hung one. A timeout
// counts as "attached" — never install unless the hub positively confirms.
const attached = await Promise.race([
otherCliClientsAttached(),
sleep(CLIENT_COUNT_EXIT_TIMEOUT_MS).then(() => true),
]).catch(() => true);
if (attached) {
return "deferred";
}
pendingAutoUpdate = undefined;
const child = spawn(pending.command, {
shell: true,
detached: true,
stdio: "ignore",
env: pending.env ? { ...process.env, ...pending.env } : process.env,
// Prevent a console window from flashing on Windows; detached
// processes otherwise allocate a new visible console.
windowsHide: true,
});
child.unref();
return "started";
}
export interface CheckForUpdatesOptions {
verbose?: boolean;
includeKanban?: boolean;
@@ -554,7 +555,9 @@ export async function checkForUpdates(
const exitCode = await runCliUpdate(manualUpdateCommand);
if (exitCode === 0) {
installedUpdates.push(`${packageName}@${latestVersion}`);
await restartHubServerIfRunning();
writeln(
`${c.dim}The update takes effect the next time cline starts.${c.reset}`,
);
} else {
writeErr(
`Cline update failed (exit code ${exitCode}). Try running: ${manualUpdateCommand.command}`,
+74 -56
View File
@@ -2,6 +2,7 @@ import {
createDiscordAdapter,
type DiscordAdapter,
} from "@chat-adapter/discord";
// TODO: Remove the root Undici 6 override when discord.js no longer requires Undici ^6.27.0.
import type { ChatStartSessionRequest } from "@cline/core";
import {
createUserInstructionConfigService,
@@ -55,6 +56,7 @@ import {
loadThreadState,
persistMergedThreadState,
readBindings,
resolveThreadTurnQueueKey,
} from "../thread-bindings";
import type {
ConnectCommandDefinition,
@@ -729,60 +731,69 @@ class DiscordConnector extends ConnectorBase<
}
protected override createCommand(): Command {
return super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "Discord bot username label")
.option("--application-id <id>", "Discord application id")
.option("--app-id <id>", "Alias for --application-id")
.option("--bot-token <token>", "Discord bot token")
.option("--token <token>", "Alias for --bot-token")
.option("--public-key <key>", "Discord application public key")
.option(
"--owner-user-id <id>",
"Discord user id that should be marked as connector owner",
)
.option("--ignore-bot-authors", "Ignore messages from other Discord bots")
.option(
"--mention-role-ids <ids>",
"Comma-separated role IDs that should trigger mention handlers",
)
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--enable-tools", "Enable tools for Discord sessions")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() || resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option(
"--base-url <url>",
"Public base URL for Discord interactions webhook",
)
.addHelpText(
"after",
[
"",
"Environment:",
" DISCORD_APPLICATION_ID Discord application id",
" DISCORD_BOT_TOKEN Discord bot token",
" DISCORD_PUBLIC_KEY Discord application public key",
" DISCORD_OWNER_USER_ID Optional connector owner user id",
" DISCORD_IGNORE_BOT_AUTHORS Set to 1 to ignore messages from other bots",
" DISCORD_MENTION_ROLE_IDS Optional comma-separated role ids",
].join("\n"),
);
return (
super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "Discord bot username label")
.option("--application-id <id>", "Discord application id")
.option("--app-id <id>", "Alias for --application-id")
.option("--bot-token <token>", "Discord bot token")
.option("--token <token>", "Alias for --bot-token")
.option("--public-key <key>", "Discord application public key")
.option(
"--owner-user-id <id>",
"Discord user id that should be marked as connector owner",
)
.option(
"--ignore-bot-authors",
"Ignore messages from other Discord bots",
)
.option(
"--mention-role-ids <ids>",
"Comma-separated role IDs that should trigger mention handlers",
)
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--no-tools", "Disable tools for Discord sessions")
// Retained so existing invocations and persisted autostart arguments
// keep parsing; tools are on unless --no-tools is passed.
.option("--enable-tools", "Enable tools (default)")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() ||
resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option(
"--base-url <url>",
"Public base URL for Discord interactions webhook",
)
.addHelpText(
"after",
[
"",
"Environment:",
" DISCORD_APPLICATION_ID Discord application id",
" DISCORD_BOT_TOKEN Discord bot token",
" DISCORD_PUBLIC_KEY Discord application public key",
" DISCORD_OWNER_USER_ID Optional connector owner user id",
" DISCORD_IGNORE_BOT_AUTHORS Set to 1 to ignore messages from other bots",
" DISCORD_MENTION_ROLE_IDS Optional comma-separated role ids",
].join("\n"),
)
);
}
protected override readOptions(command: Command): ConnectDiscordOptions {
@@ -804,6 +815,7 @@ class DiscordConnector extends ConnectorBase<
mode?: string;
interactive?: boolean;
enableTools?: boolean;
tools?: boolean;
rpcAddress?: string;
hookCommand?: string;
port?: string;
@@ -856,7 +868,7 @@ class DiscordConnector extends ConnectorBase<
systemPrompt: opts.system,
mode: this.parseMode(opts.mode),
interactive: Boolean(opts.interactive),
enableTools: Boolean(opts.enableTools),
enableTools: opts.tools !== false,
rpcAddress:
opts.rpcAddress?.trim() ||
process.env.CLINE_RPC_ADDRESS?.trim() ||
@@ -973,6 +985,12 @@ class DiscordConnector extends ConnectorBase<
return 0;
}
protected override instanceIdFromOptions(
options: ConnectDiscordOptions,
): string | undefined {
return options.applicationId;
}
protected override async runWithOptions(
options: ConnectDiscordOptions,
rawArgs: string[],
@@ -1119,7 +1137,7 @@ class DiscordConnector extends ConnectorBase<
isSubscribedThreadMessage?: boolean;
},
) => {
const queueKey = thread.id;
const queueKey = resolveThreadTurnQueueKey(thread);
const enqueueTurn = (work: () => Promise<void>) =>
enqueueThreadTurn(threadQueues, queueKey, work);
const runTurn = async () => {
+58 -44
View File
@@ -51,6 +51,7 @@ import {
loadThreadState,
persistMergedThreadState,
readBindings,
resolveThreadTurnQueueKey,
} from "../thread-bindings";
import type {
ConnectCommandDefinition,
@@ -235,48 +236,54 @@ class GoogleChatConnector extends ConnectorBase<
}
protected override createCommand(): Command {
return super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "Google Chat bot username label")
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--enable-tools", "Enable tools for Google Chat sessions")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() || resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option("--base-url <url>", "Public base URL for webhook configuration")
.option(
"--pubsub-topic <topic>",
"Optional Pub/Sub topic for all-message events",
)
.option("--impersonate-user <email>", "Optional delegation user email")
.option("--use-adc", "Use Google Application Default Credentials")
.option("--credentials-json <json>", "Service account credentials JSON")
.addHelpText(
"after",
[
"",
"Environment:",
" GOOGLE_CHAT_CREDENTIALS Service account JSON",
" GOOGLE_CHAT_USE_ADC=true Use Application Default Credentials",
" GOOGLE_CHAT_PUBSUB_TOPIC Optional Pub/Sub topic",
" GOOGLE_CHAT_IMPERSONATE_USER Optional delegation user",
].join("\n"),
);
return (
super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "Google Chat bot username label")
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--no-tools", "Disable tools for Google Chat sessions")
// Retained so existing invocations and persisted autostart arguments
// keep parsing; tools are on unless --no-tools is passed.
.option("--enable-tools", "Enable tools (default)")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() ||
resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option("--base-url <url>", "Public base URL for webhook configuration")
.option(
"--pubsub-topic <topic>",
"Optional Pub/Sub topic for all-message events",
)
.option("--impersonate-user <email>", "Optional delegation user email")
.option("--use-adc", "Use Google Application Default Credentials")
.option("--credentials-json <json>", "Service account credentials JSON")
.addHelpText(
"after",
[
"",
"Environment:",
" GOOGLE_CHAT_CREDENTIALS Service account JSON",
" GOOGLE_CHAT_USE_ADC=true Use Application Default Credentials",
" GOOGLE_CHAT_PUBSUB_TOPIC Optional Pub/Sub topic",
" GOOGLE_CHAT_IMPERSONATE_USER Optional delegation user",
].join("\n"),
)
);
}
protected override readOptions(command: Command): ConnectGoogleChatOptions {
@@ -290,6 +297,7 @@ class GoogleChatConnector extends ConnectorBase<
mode?: string;
interactive?: boolean;
enableTools?: boolean;
tools?: boolean;
rpcAddress?: string;
hookCommand?: string;
port?: string;
@@ -316,7 +324,7 @@ class GoogleChatConnector extends ConnectorBase<
systemPrompt: opts.system,
mode: this.parseMode(opts.mode),
interactive: Boolean(opts.interactive),
enableTools: Boolean(opts.enableTools),
enableTools: opts.tools !== false,
rpcAddress:
opts.rpcAddress?.trim() ||
process.env.CLINE_RPC_ADDRESS?.trim() ||
@@ -463,6 +471,12 @@ class GoogleChatConnector extends ConnectorBase<
}
}
protected override instanceIdFromOptions(
options: ConnectGoogleChatOptions,
): string | undefined {
return options.userName;
}
protected override async runWithOptions(
options: ConnectGoogleChatOptions,
rawArgs: string[],
@@ -614,7 +628,7 @@ class GoogleChatConnector extends ConnectorBase<
thread: Thread<GoogleChatThreadState>,
text: string,
) => {
const queueKey = thread.id;
const queueKey = resolveThreadTurnQueueKey(thread);
const enqueueTurn = (work: () => Promise<void>) =>
enqueueThreadTurn(threadQueues, queueKey, work);
const runTurn = async () => {
+58 -44
View File
@@ -47,6 +47,7 @@ import {
loadThreadState,
persistMergedThreadState,
readBindings,
resolveThreadTurnQueueKey,
} from "../thread-bindings";
import type {
ConnectCommandDefinition,
@@ -290,48 +291,54 @@ class LinearConnector extends ConnectorBase<
}
protected override createCommand(): Command {
return super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "Linear bot display name")
.option("--api-key <key>", "Linear personal API key")
.option("--client-id <id>", "Linear OAuth client id")
.option("--client-secret <secret>", "Linear OAuth client secret")
.option("--access-token <token>", "Pre-obtained Linear access token")
.option("--webhook-secret <secret>", "Linear webhook signing secret")
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--provider-api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--enable-tools", "Enable tools for Linear sessions")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() || resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option("--base-url <url>", "Public base URL for webhook configuration")
.addHelpText(
"after",
[
"",
"Environment:",
" LINEAR_API_KEY Personal API key",
" LINEAR_CLIENT_ID OAuth client id",
" LINEAR_CLIENT_SECRET OAuth client secret",
" LINEAR_ACCESS_TOKEN Pre-obtained access token",
" LINEAR_WEBHOOK_SECRET Webhook signing secret",
" LINEAR_BOT_USERNAME Bot display name (default: linear-bot)",
].join("\n"),
);
return (
super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "Linear bot display name")
.option("--api-key <key>", "Linear personal API key")
.option("--client-id <id>", "Linear OAuth client id")
.option("--client-secret <secret>", "Linear OAuth client secret")
.option("--access-token <token>", "Pre-obtained Linear access token")
.option("--webhook-secret <secret>", "Linear webhook signing secret")
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--provider-api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--no-tools", "Disable tools for Linear sessions")
// Retained so existing invocations and persisted autostart arguments
// keep parsing; tools are on unless --no-tools is passed.
.option("--enable-tools", "Enable tools (default)")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() ||
resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option("--base-url <url>", "Public base URL for webhook configuration")
.addHelpText(
"after",
[
"",
"Environment:",
" LINEAR_API_KEY Personal API key",
" LINEAR_CLIENT_ID OAuth client id",
" LINEAR_CLIENT_SECRET OAuth client secret",
" LINEAR_ACCESS_TOKEN Pre-obtained access token",
" LINEAR_WEBHOOK_SECRET Webhook signing secret",
" LINEAR_BOT_USERNAME Bot display name (default: linear-bot)",
].join("\n"),
)
);
}
protected override readOptions(command: Command): ConnectLinearOptions {
@@ -350,6 +357,7 @@ class LinearConnector extends ConnectorBase<
mode?: string;
interactive?: boolean;
enableTools?: boolean;
tools?: boolean;
rpcAddress?: string;
hookCommand?: string;
port?: string;
@@ -396,7 +404,7 @@ class LinearConnector extends ConnectorBase<
systemPrompt: opts.system,
mode: this.parseMode(opts.mode),
interactive: Boolean(opts.interactive),
enableTools: Boolean(opts.enableTools),
enableTools: opts.tools !== false,
rpcAddress:
opts.rpcAddress?.trim() ||
process.env.CLINE_RPC_ADDRESS?.trim() ||
@@ -488,6 +496,12 @@ class LinearConnector extends ConnectorBase<
);
}
protected override instanceIdFromOptions(
options: ConnectLinearOptions,
): string | undefined {
return options.userName;
}
protected override async runWithOptions(
options: ConnectLinearOptions,
rawArgs: string[],
@@ -637,7 +651,7 @@ class LinearConnector extends ConnectorBase<
thread: Thread<LinearThreadState>,
text: string,
) => {
const queueKey = thread.id;
const queueKey = resolveThreadTurnQueueKey(thread);
const enqueueTurn = (work: () => Promise<void>) =>
enqueueThreadTurn(threadQueues, queueKey, work);
const runTurn = async () => {
@@ -433,3 +433,53 @@ describe("slack binding lookup", () => {
).toBe(false);
});
});
describe("slack legacy connector state", () => {
it("stops a live connector recorded by a pre-claim state file (no claimId)", async () => {
const { spawn } = await import("node:child_process");
const { mkdirSync, mkdtempSync, rmSync, writeFileSync } = await import(
"node:fs"
);
const { tmpdir } = await import("node:os");
const { join } = await import("node:path");
const previousDataDir = process.env.CLINE_DATA_DIR;
const dataDir = mkdtempSync(join(tmpdir(), "slack-legacy-state-"));
process.env.CLINE_DATA_DIR = dataDir;
const child = spawn(
process.execPath,
["-e", "setInterval(() => {}, 1000)"],
{ stdio: "ignore" },
);
try {
const stateDir = join(dataDir, "connectors", "slack");
mkdirSync(stateDir, { recursive: true });
writeFileSync(
join(stateDir, "mybot.json"),
JSON.stringify({
userName: "mybot",
connectionMode: "socket",
pid: child.pid,
// Unreachable on purpose: session cleanup falls back to
// local storage inside the isolated data dir.
rpcAddress: "ws://127.0.0.1:1/hub",
startedAt: new Date(0).toISOString(),
}),
"utf8",
);
const io = { writeln: () => {}, writeErr: () => {} };
const result = await slackConnector.stopInstance?.("mybot", io);
expect(result?.stoppedProcesses).toBe(1);
} finally {
child.kill("SIGKILL");
if (previousDataDir === undefined) {
delete process.env.CLINE_DATA_DIR;
} else {
process.env.CLINE_DATA_DIR = previousDataDir;
}
rmSync(dataDir, { recursive: true, force: true });
}
});
});
+117 -77
View File
@@ -28,7 +28,7 @@ import {
enqueueThreadTurn,
startConnectorWebhookServer,
} from "../chat-runtime";
import { isProcessRunning } from "../common";
import { CONNECT_ALREADY_RUNNING_EXIT_CODE, isProcessRunning } from "../common";
import {
type ActiveConnectorTurn,
handleConnectorUserTurn,
@@ -56,6 +56,7 @@ import {
loadThreadState,
persistMergedThreadState,
readBindings,
resolveThreadTurnQueueKey,
writeBindings,
} from "../thread-bindings";
import type {
@@ -64,19 +65,13 @@ import type {
ConnectRunContext,
ConnectStopResult,
} from "../types";
import {
getConnectorFirstContactMessage,
getConnectorSystemPrompt,
getConnectorSystemRules,
} from "./prompts";
import { getConnectorSystemPrompt, getConnectorSystemRules } from "./prompts";
const SLACK_SYSTEM_RULES = getConnectorSystemRules(
"Slack",
"You can respond to user messages in threads and DMs, and you can use tools according to user's requests and your capabilities.",
);
const SLACK_FIRST_CONTACT_MESSAGE = getConnectorFirstContactMessage();
type SlackThreadState = ConnectorThreadState & {
teamId?: string;
};
@@ -501,62 +496,68 @@ class SlackConnector extends ConnectorBase<
}
protected override createCommand(): Command {
return super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "Slack bot username label")
.option(
"--bot-token <token>",
"Slack bot token for single-workspace mode",
)
.option("--signing-secret <secret>", "Slack signing secret")
.option("--app-token <token>", "Slack app-level token for socket mode")
.option("--client-id <id>", "Slack OAuth client id")
.option("--client-secret <secret>", "Slack OAuth client secret")
.option(
"--encryption-key <key>",
"Base64 32-byte key for encrypted installations",
)
.option(
"--installation-key-prefix <prefix>",
"Override stored installation key prefix",
)
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--enable-tools", "Enable tools for Slack sessions")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() || resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option(
"--base-url <url>",
"Public base URL for webhooks and OAuth callback",
)
.addHelpText(
"after",
[
"",
"Environment:",
" SLACK_BOT_TOKEN Single-workspace bot token",
" SLACK_SIGNING_SECRET Slack signing secret",
" SLACK_APP_TOKEN App-level token for socket mode",
" SLACK_CLIENT_ID OAuth client id",
" SLACK_CLIENT_SECRET OAuth client secret",
" SLACK_ENCRYPTION_KEY Optional installation encryption key",
].join("\n"),
);
return (
super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "Slack bot username label")
.option(
"--bot-token <token>",
"Slack bot token for single-workspace mode",
)
.option("--signing-secret <secret>", "Slack signing secret")
.option("--app-token <token>", "Slack app-level token for socket mode")
.option("--client-id <id>", "Slack OAuth client id")
.option("--client-secret <secret>", "Slack OAuth client secret")
.option(
"--encryption-key <key>",
"Base64 32-byte key for encrypted installations",
)
.option(
"--installation-key-prefix <prefix>",
"Override stored installation key prefix",
)
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--no-tools", "Disable tools for Slack sessions")
// Retained so existing invocations and persisted autostart arguments
// keep parsing; tools are on unless --no-tools is passed.
.option("--enable-tools", "Enable tools (default)")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() ||
resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option(
"--base-url <url>",
"Public base URL for webhooks and OAuth callback",
)
.addHelpText(
"after",
[
"",
"Environment:",
" SLACK_BOT_TOKEN Single-workspace bot token",
" SLACK_SIGNING_SECRET Slack signing secret",
" SLACK_APP_TOKEN App-level token for socket mode",
" SLACK_CLIENT_ID OAuth client id",
" SLACK_CLIENT_SECRET OAuth client secret",
" SLACK_ENCRYPTION_KEY Optional installation encryption key",
].join("\n"),
)
);
}
protected override readOptions(command: Command): ConnectSlackOptions {
@@ -577,6 +578,7 @@ class SlackConnector extends ConnectorBase<
mode?: string;
interactive?: boolean;
enableTools?: boolean;
tools?: boolean;
rpcAddress?: string;
hookCommand?: string;
port?: string;
@@ -643,7 +645,7 @@ class SlackConnector extends ConnectorBase<
systemPrompt: opts.system,
mode: this.parseMode(opts.mode),
interactive: Boolean(opts.interactive),
enableTools: Boolean(opts.enableTools),
enableTools: opts.tools !== false,
rpcAddress:
opts.rpcAddress?.trim() ||
process.env.CLINE_RPC_ADDRESS?.trim() ||
@@ -682,6 +684,9 @@ class SlackConnector extends ConnectorBase<
Boolean(
value &&
typeof value === "object" &&
// claimId is optional: state files written by older CLI
// versions predate claiming and must stay manageable
// (already-running detection, status, stop).
typeof (value as SlackConnectorState).pid === "number" &&
typeof (value as SlackConnectorState).userName === "string",
),
@@ -733,6 +738,12 @@ class SlackConnector extends ConnectorBase<
);
}
protected override instanceIdFromOptions(
options: ConnectSlackOptions,
): string | undefined {
return options.userName;
}
protected override async runWithOptions(
options: ConnectSlackOptions,
rawArgs: string[],
@@ -743,14 +754,18 @@ class SlackConnector extends ConnectorBase<
const statePath = this.resolveConnectorStatePath(options.userName);
const bindingsPath = this.resolveBindingsPath(options.userName);
const stateStorePath = this.resolveStateStorePath(options.userName);
const staleState = this.removeStaleState(
statePath,
(path) => this.readConnectorState(path),
(state) => state.pid,
);
const existingState = this.readConnectorState(statePath);
const staleState =
existingState && !isProcessRunning(existingState.pid)
? existingState
: undefined;
if (staleState) {
clearBindingSessionIds<SlackThreadState>(bindingsPath);
}
const formatAlreadyRunning = (state: SlackConnectorState) =>
state.connectionMode === "socket"
? `[slack] connector already running pid=${state.pid} rpc=${state.rpcAddress} mode=socket`
: `[slack] connector already running pid=${state.pid} rpc=${state.rpcAddress} url=${state.baseUrl}`;
const backgroundExitCode = await this.maybeRunInBackground({
rawArgs,
io,
@@ -759,10 +774,7 @@ class SlackConnector extends ConnectorBase<
statePath,
readState: (path) => this.readConnectorState(path),
isRunning: (state) => isProcessRunning(state.pid),
formatAlreadyRunningMessage: (state) =>
state.connectionMode === "socket"
? `[slack] connector already running pid=${state.pid} rpc=${state.rpcAddress} mode=socket`
: `[slack] connector already running pid=${state.pid} rpc=${state.rpcAddress} url=${state.baseUrl}`,
formatAlreadyRunningMessage: formatAlreadyRunning,
formatBackgroundStartMessage: (pid) =>
`[slack] starting background connector pid=${pid} user=${options.userName} mode=${options.connectionMode}`,
foregroundHint:
@@ -773,6 +785,34 @@ class SlackConnector extends ConnectorBase<
return backgroundExitCode;
}
// Foreground / detached-child path: exclusively claim the instance before
// opening Slack socket-mode so a second process cannot share the token.
const startedAt = new Date().toISOString();
const claim = this.claimConnectorInstance({
statePath,
createState: (claimId) => ({
claimId,
userName: options.userName,
connectionMode: options.connectionMode,
pid: process.pid,
rpcAddress: "pending",
startedAt,
...(options.connectionMode === "webhook"
? { port: options.port, baseUrl: options.baseUrl }
: {}),
}),
readState: (path) => this.readConnectorState(path),
getPid: (state) => state.pid,
});
if (!claim.claimed) {
io.writeln(
claim.running
? formatAlreadyRunning(claim.running)
: `[slack] connector already running for user=${options.userName}`,
);
return CONNECT_ALREADY_RUNNING_EXIT_CODE;
}
const loggerAdapter = createCliLoggerAdapter({
runtime: "cli",
component: "slack-connect",
@@ -860,6 +900,7 @@ class SlackConnector extends ConnectorBase<
});
await client.connect();
this.writeConnectorState(statePath, {
claimId: claim.claimId,
userName: options.userName,
connectionMode: options.connectionMode,
pid: process.pid,
@@ -867,7 +908,7 @@ class SlackConnector extends ConnectorBase<
...(options.connectionMode === "webhook"
? { port: options.port, baseUrl: options.baseUrl }
: {}),
startedAt: new Date().toISOString(),
startedAt,
});
let stopping = false;
@@ -892,7 +933,7 @@ class SlackConnector extends ConnectorBase<
bindingsPath,
startRequest,
);
const queueKey = thread.id;
const queueKey = resolveThreadTurnQueueKey(thread);
const enqueueTurn = (work: () => Promise<void>) =>
enqueueThreadTurn(threadQueues, queueKey, work);
const runTurn = async () => {
@@ -919,7 +960,6 @@ class SlackConnector extends ConnectorBase<
hookCommand: options.hookCommand,
systemRules: SLACK_SYSTEM_RULES,
errorLabel: "Slack",
firstContactMessage: SLACK_FIRST_CONTACT_MESSAGE,
userInstructionService,
chatCommandHost,
activeTurns,
@@ -4,6 +4,7 @@ import { join } from "node:path";
import type { ConnectTelegramOptions } from "@cline/shared";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { CONNECT_ALREADY_RUNNING_EXIT_CODE } from "../common";
import { handleConnectorUserTurn } from "../connector-host";
import { __test__, telegramConnector } from "./telegram";
const mocks = vi.hoisted(() => ({
@@ -468,3 +469,322 @@ describe("telegram binding lookup", () => {
expect(result).toBeUndefined();
});
});
type SlashTestState = Record<string, unknown>;
function createSlashTestThread(input: {
id: string;
channelId: string;
isDM: boolean;
initialState?: SlashTestState;
}) {
let state: SlashTestState = { ...(input.initialState ?? {}) };
const posts: unknown[] = [];
let subscribed = false;
const thread = {
id: input.id,
channelId: input.channelId,
isDM: input.isDM,
get state() {
return Promise.resolve(state);
},
async setState(nextState: SlashTestState) {
state = { ...nextState };
},
async subscribe() {
subscribed = true;
},
async post(message: unknown) {
posts.push(message);
const sentMessage = {
edit: async (nextMessage: unknown) => {
posts.push(nextMessage);
return sentMessage;
},
delete: async () => undefined,
};
return sentMessage;
},
async startTyping() {},
toJSON() {
return {
id: input.id,
channelId: input.channelId,
isDM: input.isDM,
state,
};
},
};
return {
thread,
posts,
getState: () => state,
isSubscribed: () => subscribed,
};
}
function slashTestStartRequest() {
return {
enableTools: false,
autoApproveTools: false,
cwd: "/tmp/work",
workspaceRoot: "/tmp/work",
systemPrompt: "system",
provider: "cline",
model: "test-model",
mode: "act",
};
}
describe("telegram slash command delivery", () => {
it("receives bot_command updates intercepted by the telegram chat library", async () => {
// The Telegram Bot API tags any leading-slash message with a
// `bot_command` entity, and @chat-adapter/telegram diverts those
// updates away from the mention/subscribed-message handlers. This
// pins the delivery contract: an intercepted update must still reach
// the connector turn handler through the slash-command path.
vi.stubGlobal(
"fetch",
vi.fn(
async () =>
new Response(JSON.stringify({ ok: true, result: {} }), {
status: 200,
}),
),
);
const { createTelegramAdapter } = await import("@chat-adapter/telegram");
const { Chat, ConsoleLogger } = await import("chat");
const { InMemoryStateAdapter } = await import("../stores/memory-state");
const telegram = createTelegramAdapter({
mode: "polling",
botToken: "123456:TEST-TOKEN",
userName: "test_bot",
logger: new ConsoleLogger("error", "telegram-slash-test"),
});
const bot = new Chat({
userName: "test_bot",
adapters: { telegram },
state: new InMemoryStateAdapter(),
logger: new ConsoleLogger("error", "telegram-slash-test"),
});
// bot.initialize() assigns this reference before polling starts; set
// it directly to avoid the real getMe/long-polling network calls.
(telegram as unknown as { chat: unknown }).chat = bot;
const dir = mkdtempSync(join(tmpdir(), "cline-telegram-slash-"));
tempDataDirs.push(dir);
const turns: Array<{ threadId: string; isDM: boolean; text: string }> = [];
bot.onSlashCommand(
__test__.createTelegramSlashCommandHandler({
bot,
bindingsPath: join(dir, "threads.json"),
baseStartRequest: slashTestStartRequest() as never,
handleTurn: async (thread, text) => {
turns.push({ threadId: thread.id, isDM: thread.isDM, text });
},
}) as never,
);
const completions: Promise<unknown>[] = [];
(
telegram as unknown as {
processUpdate: (update: unknown, options?: unknown) => void;
}
).processUpdate(
{
update_id: 1,
message: {
message_id: 42,
date: Math.floor(Date.now() / 1000),
chat: { id: 555, type: "private" },
from: {
id: 999,
is_bot: false,
first_name: "Alice",
username: "alice",
},
text: "/clear",
entities: [{ type: "bot_command", offset: 0, length: 6 }],
},
},
{
waitUntil: (task: Promise<unknown>) =>
completions.push(task.catch(() => undefined)),
},
);
await Promise.all(completions);
await vi.waitFor(() => {
expect(turns).toHaveLength(1);
});
expect(turns[0]).toEqual({
threadId: "telegram:555",
isDM: true,
text: "/clear",
});
});
it("routes intercepted slash commands into the connector turn handler", async () => {
const dir = mkdtempSync(join(tmpdir(), "cline-telegram-slash-"));
tempDataDirs.push(dir);
const bindingsPath = join(dir, "threads.json");
const { thread, isSubscribed, getState } = createSlashTestThread({
id: "telegram:12345",
channelId: "telegram:12345",
isDM: true,
});
const botThread = vi.fn(() => thread);
const handleTurn = vi.fn(async () => undefined);
const handler = __test__.createTelegramSlashCommandHandler({
bot: { thread: botThread } as never,
bindingsPath,
baseStartRequest: slashTestStartRequest() as never,
handleTurn: handleTurn as never,
});
await handler({
channel: { id: "telegram:12345" },
command: "/clear",
text: "",
raw: {
message_id: 7,
chat: { id: 12345, type: "private" },
from: { id: 999, username: "alice", first_name: "Alice" },
text: "/clear",
entities: [{ type: "bot_command", offset: 0, length: 6 }],
},
});
expect(botThread).toHaveBeenCalledWith("telegram:12345");
expect(isSubscribed()).toBe(true);
expect(handleTurn).toHaveBeenCalledWith(thread, "/clear");
expect(getState().participantKey).toBe("telegram:id:999");
});
it("preserves group-chat bot addressing in the forwarded command text", async () => {
const dir = mkdtempSync(join(tmpdir(), "cline-telegram-slash-"));
tempDataDirs.push(dir);
const { thread } = createSlashTestThread({
id: "telegram:-100200",
channelId: "telegram:-100200",
isDM: false,
});
const handleTurn = vi.fn(async () => undefined);
const handler = __test__.createTelegramSlashCommandHandler({
bot: { thread: () => thread } as never,
bindingsPath: join(dir, "threads.json"),
baseStartRequest: slashTestStartRequest() as never,
handleTurn: handleTurn as never,
});
// The chat adapter strips "@test_bot" into command targeting before
// invoking slash handlers; the raw message text keeps it so the
// connector host can enforce group addressing rules.
await handler({
channel: { id: "telegram:-100200" },
command: "/tools",
text: "on",
raw: {
message_id: 8,
chat: { id: -100200, type: "supergroup" },
from: { id: 999, username: "alice" },
text: "/tools@test_bot on",
entities: [{ type: "bot_command", offset: 0, length: 15 }],
},
});
expect(handleTurn).toHaveBeenCalledWith(thread, "/tools@test_bot on");
});
it("falls back to the parsed command when the raw payload has no text", async () => {
const dir = mkdtempSync(join(tmpdir(), "cline-telegram-slash-"));
tempDataDirs.push(dir);
const { thread } = createSlashTestThread({
id: "telegram:12345",
channelId: "telegram:12345",
isDM: true,
});
const handleTurn = vi.fn(async () => undefined);
const handler = __test__.createTelegramSlashCommandHandler({
bot: { thread: () => thread } as never,
bindingsPath: join(dir, "threads.json"),
baseStartRequest: slashTestStartRequest() as never,
handleTurn: handleTurn as never,
});
await handler({
channel: { id: "telegram:12345" },
command: "/cwd",
text: "/tmp",
raw: undefined,
});
expect(handleTurn).toHaveBeenCalledWith(thread, "/cwd /tmp");
});
it("delivers intercepted slash commands to the chat command host", async () => {
const dir = mkdtempSync(join(tmpdir(), "cline-telegram-slash-"));
tempDataDirs.push(dir);
const bindingsPath = join(dir, "threads.json");
const { thread, posts } = createSlashTestThread({
id: "telegram:777",
channelId: "telegram:777",
isDM: true,
initialState: {
sessionId: "session-1",
participantKey: "telegram:id:999",
participantLabel: "alice",
welcomeSentAt: "2026-03-17T00:00:00.000Z",
},
});
const stopRuntimeSession = vi.fn(async () => undefined);
const deleteSession = vi.fn(async () => undefined);
const baseStartRequest = slashTestStartRequest();
const handler = __test__.createTelegramSlashCommandHandler({
bot: { thread: () => thread } as never,
bindingsPath,
baseStartRequest: baseStartRequest as never,
handleTurn: (async (
turnThread: typeof thread,
text: string,
): Promise<void> => {
await handleConnectorUserTurn({
thread: turnThread as never,
text,
client: { stopRuntimeSession, deleteSession } as never,
pendingApprovals: new Map(),
baseStartRequest: baseStartRequest as never,
explicitSystemPrompt: undefined,
clientId: "client-1",
logger: {
core: { debug: vi.fn(), log: vi.fn(), error: vi.fn() },
} as never,
transport: "telegram",
botUserName: "test_bot",
requestStop: vi.fn(),
bindingsPath,
systemRules: "rules",
errorLabel: "Telegram",
getSessionMetadata: () => ({}),
reusedLogMessage: "reused",
});
}) as never,
});
await handler({
channel: { id: "telegram:777" },
command: "/clear",
text: "",
raw: {
message_id: 9,
chat: { id: 777, type: "private" },
from: { id: 999, username: "alice" },
text: "/clear",
entities: [{ type: "bot_command", offset: 0, length: 6 }],
},
});
expect(deleteSession).toHaveBeenCalledWith("session-1", true);
expect(posts).toContainEqual({ raw: "Started a fresh session." });
});
});
+119 -42
View File
@@ -47,6 +47,7 @@ import {
loadThreadState,
persistMergedThreadState,
readBindings,
resolveThreadTurnQueueKey,
} from "../thread-bindings";
import type {
ConnectCommandDefinition,
@@ -266,6 +267,55 @@ async function persistTelegramThreadContext(input: {
);
}
type TelegramSlashCommandEvent = {
channel: { id: string };
command: string;
text: string;
raw: unknown;
};
/**
* The Telegram chat adapter intercepts any message whose leading entity is a
* `bot_command` and delivers it to slash-command handlers instead of the
* normal mention/subscribed-message handlers. Without a registered handler
* the command is consumed and dropped, so connector commands like /clear
* never reach the chat command host. Rebuild the originating chat thread and
* forward the original message text (preserving any `@bot` addressing used
* in group chats) into the same turn pipeline as regular messages.
*/
function createTelegramSlashCommandHandler(input: {
bot: Pick<Chat, "thread">;
bindingsPath: string;
baseStartRequest: ChatStartSessionRequest;
handleTurn: (
thread: Thread<TelegramThreadState>,
text: string,
) => Promise<void>;
}): (event: TelegramSlashCommandEvent) => Promise<void> {
return async (event) => {
const raw = asRecord(event.raw);
const commandText =
readString(raw?.text) ??
readString(raw?.caption) ??
[event.command.trim(), event.text.trim()].filter(Boolean).join(" ");
if (!commandText) {
return;
}
const thread = input.bot.thread(
event.channel.id,
) as Thread<TelegramThreadState>;
await thread.subscribe();
await persistTelegramThreadContext({
thread,
bindingsPath: input.bindingsPath,
baseStartRequest: input.baseStartRequest,
rawMessage: event.raw,
errorLabel: "Telegram",
});
await input.handleTurn(thread, commandText);
};
}
async function deliverScheduledResult(input: {
bot: Chat;
client: HubSessionClient;
@@ -417,47 +467,53 @@ class TelegramConnector extends ConnectorBase<
}
protected override createCommand(): Command {
return super
.createCommand()
.usage("-k <TELEGRAM_BOT_TOKEN> [options]")
.option(
"-m, --bot-username <name>",
"Telegram bot username; fetched from token if omitted",
)
.option("-k, --bot-token <token>", "Telegram bot token")
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--no-tools", "Disable tools for Telegram sessions")
.option(
"--allowed-user-id <id>",
"Only allow this Telegram user ID to use the bot",
)
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() || resolveDefaultCliRpcAddress(),
)
.addHelpText(
"after",
[
"",
"Notes:",
" - Without -i, the connector is launched in the background.",
" - Tools are enabled by default for Telegram sessions.",
" - Use --allowed-user-id or `cline connect` to restrict Telegram access.",
" - Bot username is discovered from the Telegram bot token when omitted.",
" - Provider/model default to the CLI's last-used provider settings.",
].join("\n"),
);
return (
super
.createCommand()
.usage("-k <TELEGRAM_BOT_TOKEN> [options]")
.option(
"-m, --bot-username <name>",
"Telegram bot username; fetched from token if omitted",
)
.option("-k, --bot-token <token>", "Telegram bot token")
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--no-tools", "Disable tools for Telegram sessions")
// Retained so existing invocations and persisted autostart arguments
// keep parsing; tools are on unless --no-tools is passed.
.option("--enable-tools", "Enable tools (default)")
.option(
"--allowed-user-id <id>",
"Only allow this Telegram user ID to use the bot",
)
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() ||
resolveDefaultCliRpcAddress(),
)
.addHelpText(
"after",
[
"",
"Notes:",
" - Without -i, the connector is launched in the background.",
" - Tools are enabled by default for Telegram sessions.",
" - Use --allowed-user-id or `cline connect` to restrict Telegram access.",
" - Bot username is discovered from the Telegram bot token when omitted.",
" - Provider/model default to the CLI's last-used provider settings.",
].join("\n"),
)
);
}
protected override readOptions(command: Command): ConnectTelegramOptions {
@@ -631,6 +687,17 @@ class TelegramConnector extends ConnectorBase<
}
}
/**
* Only knowable up front when `--bot-username` was supplied; otherwise the
* username is resolved from Telegram's API during startup, and the caller
* has to start this connector locally instead of through the hub.
*/
protected override instanceIdFromOptions(
options: ConnectTelegramOptions,
): string | undefined {
return options.botUsername;
}
protected override async runWithOptions(
inputOptions: ConnectTelegramOptions,
rawArgs: string[],
@@ -816,7 +883,7 @@ class TelegramConnector extends ConnectorBase<
thread: Thread<TelegramThreadState>,
text: string,
) => {
const queueKey = thread.id;
const queueKey = resolveThreadTurnQueueKey(thread);
const enqueueTurn = (work: () => Promise<void>) =>
enqueueThreadTurn(threadQueues, queueKey, work);
const runTurn = async () => {
@@ -1007,6 +1074,15 @@ class TelegramConnector extends ConnectorBase<
await handleTurn(thread, message.text);
});
bot.onSlashCommand(
createTelegramSlashCommandHandler({
bot,
bindingsPath,
baseStartRequest: startRequest,
handleTurn,
}),
);
await bot.initialize();
const stopTaskUpdateStream =
startConnectorTaskUpdateRelay<TelegramThreadState>({
@@ -1151,6 +1227,7 @@ export const telegramConnector: ConnectCommandDefinition =
new TelegramConnector();
export const __test__ = {
createTelegramSlashCommandHandler,
fetchTelegramBotUsername,
readTelegramBotId,
resolveTelegramBotUsername,
@@ -0,0 +1,100 @@
import { describe, expect, it } from "vitest";
import { discordConnector } from "./discord";
import { gchatConnector } from "./gchat";
import { linearConnector } from "./linear";
import { slackConnector } from "./slack";
import { telegramConnector } from "./telegram";
import { whatsappConnector } from "./whatsapp";
/**
* Every connector runs with tools enabled unless the operator opts out, so this
* has to hold for all of them at once rather than per adapter the whole point
* is that there is no adapter where the default is different.
*/
const connectors: Array<{
name: string;
connector: unknown;
/** Minimal arguments that parse for this adapter. */
baseArgs: string[];
}> = [
{
name: "slack",
connector: slackConnector,
baseArgs: ["--user-name", "bot"],
},
{
name: "discord",
connector: discordConnector,
baseArgs: ["--application-id", "app-1", "--bot-token", "token"],
},
{
name: "linear",
connector: linearConnector,
baseArgs: [
"--user-name",
"bot",
"--api-key",
"key",
"--webhook-secret",
"secret",
],
},
{
name: "gchat",
connector: gchatConnector,
baseArgs: ["--user-name", "bot"],
},
{
name: "whatsapp",
connector: whatsappConnector,
baseArgs: ["--user-name", "bot", "--phone-number-id", "123"],
},
{
name: "telegram",
connector: telegramConnector,
baseArgs: ["--bot-token", "123:token"],
},
];
function parse(
connector: unknown,
rawArgs: string[],
): { enableTools: boolean } {
return (
connector as {
parseArgs(rawArgs: string[]): { enableTools: boolean };
}
).parseArgs(rawArgs);
}
describe("connector tools default", () => {
for (const { name, connector, baseArgs } of connectors) {
it(`${name}: enables tools when nothing is passed`, () => {
expect(parse(connector, baseArgs).enableTools).toBe(true);
});
it(`${name}: disables tools with --no-tools`, () => {
expect(parse(connector, [...baseArgs, "--no-tools"]).enableTools).toBe(
false,
);
});
it(`${name}: an explicit --no-tools beats --enable-tools`, () => {
// Ambiguous input resolves to the safer answer.
expect(
parse(connector, [...baseArgs, "--enable-tools", "--no-tools"])
.enableTools,
).toBe(false);
});
}
it("keeps accepting --enable-tools so existing invocations still parse", () => {
// Persisted autostart arguments and deployed scripts carry this flag; it is
// redundant now but must not become an unknown-option error.
for (const { connector, baseArgs } of connectors) {
expect(
parse(connector, [...baseArgs, "--enable-tools"]).enableTools,
).toBe(true);
}
});
});
+60 -43
View File
@@ -51,6 +51,7 @@ import {
loadThreadState,
persistMergedThreadState,
readBindings,
resolveThreadTurnQueueKey,
} from "../thread-bindings";
import type {
ConnectCommandDefinition,
@@ -273,47 +274,53 @@ class WhatsAppConnector extends ConnectorBase<
}
protected override createCommand(): Command {
return super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "WhatsApp bot username label")
.option("--phone-number-id <id>", "WhatsApp Business phone number id")
.option("--access-token <token>", "Meta access token")
.option("--app-secret <secret>", "Meta app secret")
.option("--verify-token <token>", "Webhook verify token")
.option("--api-version <version>", "Graph API version", "v21.0")
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--enable-tools", "Enable tools for WhatsApp sessions")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() || resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option("--base-url <url>", "Public base URL for webhook configuration")
.addHelpText(
"after",
[
"",
"Environment:",
" WHATSAPP_ACCESS_TOKEN Meta access token",
" WHATSAPP_APP_SECRET Meta app secret",
" WHATSAPP_PHONE_NUMBER_ID WhatsApp Business phone number id",
" WHATSAPP_VERIFY_TOKEN Webhook verification token",
" WHATSAPP_BOT_USERNAME Bot username label",
].join("\n"),
);
return (
super
.createCommand()
.usage("--base-url <PUBLIC_BASE_URL> [options]")
.option("--user-name <name>", "WhatsApp bot username label")
.option("--phone-number-id <id>", "WhatsApp Business phone number id")
.option("--access-token <token>", "Meta access token")
.option("--app-secret <secret>", "Meta app secret")
.option("--verify-token <token>", "Webhook verify token")
.option("--api-version <version>", "Graph API version", "v21.0")
.option("--provider <id>", "Provider override")
.option("--model <id>", "Model override")
.option("--api-key <key>", "Provider API key override")
.option("--system <prompt>", "System prompt override")
.option("--cwd <path>", "Workspace / cwd for runtime")
.option("--mode <act|plan>", "Agent mode", "act")
.option("-i, --interactive", "Keep connector in foreground")
.option("--no-tools", "Disable tools for WhatsApp sessions")
// Retained so existing invocations and persisted autostart arguments
// keep parsing; tools are on unless --no-tools is passed.
.option("--enable-tools", "Enable tools (default)")
.option(
"--hook-command <command>",
"Run a shell command for connector events",
)
.option(
"--rpc-address <host:port>",
"RPC address",
process.env.CLINE_RPC_ADDRESS?.trim() ||
resolveDefaultCliRpcAddress(),
)
.option("--host <host>", "Webhook listen host")
.option("--port <port>", "Webhook listen port")
.option("--base-url <url>", "Public base URL for webhook configuration")
.addHelpText(
"after",
[
"",
"Environment:",
" WHATSAPP_ACCESS_TOKEN Meta access token",
" WHATSAPP_APP_SECRET Meta app secret",
" WHATSAPP_PHONE_NUMBER_ID WhatsApp Business phone number id",
" WHATSAPP_VERIFY_TOKEN Webhook verification token",
" WHATSAPP_BOT_USERNAME Bot username label",
].join("\n"),
)
);
}
protected override readOptions(command: Command): ConnectWhatsAppOptions {
@@ -332,6 +339,7 @@ class WhatsAppConnector extends ConnectorBase<
mode?: string;
interactive?: boolean;
enableTools?: boolean;
tools?: boolean;
rpcAddress?: string;
hookCommand?: string;
port?: string;
@@ -364,7 +372,7 @@ class WhatsAppConnector extends ConnectorBase<
systemPrompt: opts.system,
mode: this.parseMode(opts.mode),
interactive: Boolean(opts.interactive),
enableTools: Boolean(opts.enableTools),
enableTools: opts.tools !== false,
rpcAddress:
opts.rpcAddress?.trim() ||
process.env.CLINE_RPC_ADDRESS?.trim() ||
@@ -455,6 +463,15 @@ class WhatsAppConnector extends ConnectorBase<
);
}
protected override instanceIdFromOptions(
options: ConnectWhatsAppOptions,
): string | undefined {
return resolveInstanceKey({
phoneNumberId: options.phoneNumberId,
userName: options.userName,
});
}
protected override async runWithOptions(
options: ConnectWhatsAppOptions,
rawArgs: string[],
@@ -608,7 +625,7 @@ class WhatsAppConnector extends ConnectorBase<
thread: Thread<WhatsAppThreadState>,
text: string,
) => {
const queueKey = thread.id;
const queueKey = resolveThreadTurnQueueKey(thread);
const enqueueTurn = (work: () => Promise<void>) =>
enqueueThreadTurn(threadQueues, queueKey, work);
const runTurn = async () => {
+24 -2
View File
@@ -116,7 +116,29 @@ describe("ConnectorBase background launch", () => {
await expect(new TestConnector().runBackground(io)).resolves.toBe(1);
expect(io.writeErr).toHaveBeenCalledWith(
"launch failed: child exited before becoming ready",
expect.stringContaining(
"launch failed: child exited before becoming ready",
),
);
});
it("points at the child log so a startup failure is diagnosable", async () => {
mocks.spawnDetachedConnector.mockReturnValue(42);
mocks.isProcessRunning.mockReturnValue(false);
await new TestConnector().runBackground(io);
const [message] = vi.mocked(io.writeErr).mock.calls[0] ?? [];
expect(message).toContain("logs/connectors/test/test-connector.log");
expect(mocks.spawnDetachedConnector).toHaveBeenCalledWith(
["connect", "test"],
["--token", "secret"],
"CLINE_TEST_CONNECT_CHILD",
expect.objectContaining({
logPath: expect.stringContaining(
"logs/connectors/test/test-connector.log",
),
}),
);
});
@@ -129,7 +151,7 @@ describe("ConnectorBase background launch", () => {
expect(mocks.terminateProcess).toHaveBeenCalledWith(42);
expect(io.writeErr).toHaveBeenCalledWith(
"launch failed: timed out after 0ms",
expect.stringContaining("launch failed: timed out after 0ms"),
);
});
+154 -5
View File
@@ -1,14 +1,24 @@
import { existsSync, readdirSync } from "node:fs";
import { join } from "node:path";
import {
closeSync,
existsSync,
openSync,
readdirSync,
readSync,
statSync,
} from "node:fs";
import { basename, join } from "node:path";
import { resolveClineDataDir } from "@cline/core";
import { isSupervisedConnectorProcess } from "@cline/shared";
import { Command, CommanderError } from "commander";
import {
CONNECT_ALREADY_RUNNING_EXIT_CODE,
isProcessRunning,
readJsonFile,
removeFile,
resolveConnectorDebugLogPath,
spawnDetachedConnector,
terminateProcess,
tryClaimConnectorStateFile,
writeJsonFile,
} from "./common";
import type {
@@ -21,6 +31,65 @@ import type {
const SHOW_HELP_ERROR = "__SHOW_HELP__";
const CONNECTOR_STARTUP_TIMEOUT_MS = 15_000;
const CONNECTOR_STARTUP_POLL_MS = 100;
const CHILD_LOG_TAIL_BYTES = 8_192;
const CHILD_LOG_TAIL_LINES = 3;
const ESC = String.fromCharCode(27);
const BEL = String.fromCharCode(7);
const ANSI_SEQUENCE_PATTERN = new RegExp(
`${ESC}(?:[@-Z\\\\-_]|\\[[0-?]*[ -/]*[@-~]|\\][^${BEL}]*(?:${BEL}|${ESC}\\\\))`,
"g",
);
function stripAnsiCodes(text: string): string {
return text.replace(ANSI_SEQUENCE_PATTERN, "");
}
/**
* Surface why a detached connector child died. The child's own error is the
* useful part; the parent only knows that it exited, so quote the tail of the
* child's log and point at the file for the rest.
*/
function formatChildLogHint(logPath: string): string {
const suffix = ` See ${logPath} for details.`;
let handle: number | undefined;
try {
const { size } = statSync(logPath);
if (size === 0) {
return suffix;
}
const length = Math.min(size, CHILD_LOG_TAIL_BYTES);
const buffer = Buffer.alloc(length);
handle = openSync(logPath, "r");
const read = readSync(handle, buffer, 0, length, size - length);
const lines = buffer
.subarray(0, read)
.toString("utf8")
// A partial first line is likely when starting mid-file.
.split("\n")
.slice(size > length ? 1 : 0)
.map((line) => stripAnsiCodes(line).trim())
.filter((line) => line.length > 0)
.slice(-CHILD_LOG_TAIL_LINES);
if (lines.length === 0) {
return suffix;
}
return ` Last output from the child:\n${lines
.map((line) => ` ${line}`)
.join("\n")}\n${suffix.trimStart()}`;
} catch {
// The log is best-effort: a missing or unreadable file must never turn a
// startup failure into a crash.
return suffix;
} finally {
if (handle !== undefined) {
try {
closeSync(handle);
} catch {
// Nothing actionable if the descriptor is already gone.
}
}
}
}
export abstract class ConnectorBase<Options, State>
implements ConnectCommandDefinition
@@ -87,6 +156,31 @@ export abstract class ConnectorBase<Options, State>
return this.runWithOptions(options, rawArgs, io, context);
}
/**
* The instance id `rawArgs` would run as, when that is knowable from the
* arguments alone.
*
* The hub keys supervision by (channel, instanceId), so it needs the id
* before anything is spawned. Adapters that can only determine it with a side
* effect Telegram resolves its bot username from the API when the flag is
* omitted return undefined, and the caller falls back to starting the
* connector locally.
*/
resolveInstanceId(rawArgs: string[]): string | undefined {
let options: Options;
try {
options = this.parseArgs(rawArgs);
} catch {
return undefined;
}
const instanceId = this.instanceIdFromOptions(options);
return instanceId?.trim() ? instanceId.trim() : undefined;
}
protected instanceIdFromOptions(_options: Options): string | undefined {
return undefined;
}
async validate(rawArgs: string[], io: ConnectIo): Promise<number> {
let options: Options;
try {
@@ -170,6 +264,49 @@ export abstract class ConnectorBase<Options, State>
return undefined;
}
/**
* Exclusively claim the connector state path for this process before
* connecting to Slack/Discord/etc. Prevents two foreground (`-i`) or
* racing detached launches from both opening socket-mode with the same
* bot token.
*/
protected claimConnectorInstance(input: {
statePath: string;
createState: (claimId: string) => State & { claimId: string; pid: number };
readState: (path: string) => State | undefined;
getPid: (state: State) => number;
}): { claimed: true; claimId: string } | { claimed: false; running?: State } {
const existing = input.readState(input.statePath);
if (existing && isProcessRunning(input.getPid(existing))) {
return { claimed: false, running: existing };
}
const claim = tryClaimConnectorStateFile(
input.statePath,
input.createState,
);
if (!claim) {
const raced = input.readState(input.statePath);
return {
claimed: false,
...(raced ? { running: raced } : {}),
};
}
return { claimed: true, claimId: claim.claimId };
}
/**
* Where a detached child's stdout/stderr is captured. Without this the
* child is spawned with stdio "ignore", so a child that dies during startup
* takes its only diagnostic with it and the parent can report nothing but
* "child exited before becoming ready".
*/
protected resolveDetachedLogPath(statePath: string): string {
return resolveConnectorDebugLogPath(
this.name,
basename(statePath, ".json") || this.name,
);
}
protected async maybeRunInBackground(input: {
rawArgs: string[];
io: ConnectIo;
@@ -184,7 +321,13 @@ export abstract class ConnectorBase<Options, State>
launchFailureMessage: string;
startupTimeoutMs?: number;
}): Promise<number | undefined> {
if (input.interactive || process.env[input.childEnvVar] === "1") {
if (
input.interactive ||
process.env[input.childEnvVar] === "1" ||
// A supervised connector is the process the hub is tracking, so it must
// run the adapter here instead of handing off to a detached child.
isSupervisedConnectorProcess()
) {
return undefined;
}
const runningState = input.readState(input.statePath);
@@ -192,10 +335,16 @@ export abstract class ConnectorBase<Options, State>
input.io.writeln(input.formatAlreadyRunningMessage(runningState));
return CONNECT_ALREADY_RUNNING_EXIT_CODE;
}
const logPath = this.resolveDetachedLogPath(input.statePath);
const pid = spawnDetachedConnector(
["connect", this.name],
input.rawArgs,
input.childEnvVar,
{
logPath,
component: `${this.name}-connect`,
metadata: { statePath: input.statePath },
},
);
if (!pid) {
input.io.writeErr(input.launchFailureMessage);
@@ -212,7 +361,7 @@ export abstract class ConnectorBase<Options, State>
}
if (!isProcessRunning(pid)) {
input.io.writeErr(
`${input.launchFailureMessage}: child exited before becoming ready`,
`${input.launchFailureMessage}: child exited before becoming ready.${formatChildLogHint(logPath)}`,
);
return 1;
}
@@ -222,7 +371,7 @@ export abstract class ConnectorBase<Options, State>
}
await terminateProcess(pid);
input.io.writeErr(
`${input.launchFailureMessage}: timed out after ${timeoutMs}ms`,
`${input.launchFailureMessage}: timed out after ${timeoutMs}ms.${formatChildLogHint(logPath)}`,
);
return 1;
}
+344 -1
View File
@@ -1,4 +1,6 @@
import { dirname, resolve } from "node:path";
import { existsSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
import {
@@ -189,3 +191,344 @@ describe("readSessionReplyText", () => {
).resolves.toBe(2);
});
});
describe("tryClaimConnectorStateFile", () => {
it("claims an empty path and rejects a second live claim", async () => {
const { mkdtempSync, readFileSync, rmSync } = await import("node:fs");
const { join } = await import("node:path");
const { tmpdir } = await import("node:os");
const { tryClaimConnectorStateFile } = await import("./common");
const dir = mkdtempSync(join(tmpdir(), "connector-claim-"));
const statePath = join(dir, "instance.json");
try {
const first = tryClaimConnectorStateFile(
statePath,
(claimId) => ({ claimId, pid: process.pid, userName: "bot" }),
{
isRunning: () => true,
getStartToken: (pid) => `process-${pid}`,
},
);
expect(first).toBeDefined();
const parsed = JSON.parse(readFileSync(statePath, "utf8")) as {
claimId: string;
pid: number;
};
expect(parsed.claimId).toBe(first?.claimId);
expect(parsed.pid).toBe(process.pid);
const second = tryClaimConnectorStateFile(
statePath,
(claimId) => ({
claimId,
pid: process.pid + 1,
userName: "bot",
}),
{
isRunning: () => true,
getStartToken: (pid) => `process-${pid}`,
},
);
expect(second).toBeUndefined();
expect(JSON.parse(readFileSync(statePath, "utf8")).pid).toBe(process.pid);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
it("replaces a dead-pid claim", async () => {
const { mkdtempSync, writeFileSync, readFileSync, rmSync } = await import(
"node:fs"
);
const { join } = await import("node:path");
const { tmpdir } = await import("node:os");
const { tryClaimConnectorStateFile } = await import("./common");
const dir = mkdtempSync(join(tmpdir(), "connector-claim-"));
const statePath = join(dir, "instance.json");
writeFileSync(
statePath,
JSON.stringify({ pid: 1, userName: "stale" }),
"utf8",
);
try {
const claimed = tryClaimConnectorStateFile(
statePath,
(claimId) => ({ claimId, pid: process.pid, userName: "bot" }),
{
isRunning: (pid) => pid === process.pid,
getStartToken: (pid) => `process-${pid}`,
},
);
expect(claimed).toBeDefined();
expect(JSON.parse(readFileSync(statePath, "utf8")).pid).toBe(process.pid);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
it("allows only one contender to replace the same stale generation", async () => {
const { mkdtempSync, writeFileSync, readFileSync, rmSync } = await import(
"node:fs"
);
const { join } = await import("node:path");
const { tmpdir } = await import("node:os");
const dir = mkdtempSync(join(tmpdir(), "connector-claim-"));
const statePath = join(dir, "instance.json");
const stalePayload = `${JSON.stringify({
claimId: "stale",
pid: 1,
userName: "stale",
})}
`;
const firstPayload = `${JSON.stringify({
claimId: "first",
pid: 2,
userName: "bot",
})}
`;
const secondPayload = `${JSON.stringify({
claimId: "second",
pid: 3,
userName: "bot",
})}
`;
writeFileSync(statePath, stalePayload, "utf8");
try {
expect(
__test__.tryReplaceStaleConnectorStateFile(
statePath,
stalePayload,
firstPayload,
{
isRunning: () => false,
getStartToken: (pid) => `process-${pid}`,
},
),
).toBe(true);
expect(
__test__.tryReplaceStaleConnectorStateFile(
statePath,
stalePayload,
secondPayload,
{
isRunning: () => false,
getStartToken: (pid) => `process-${pid}`,
},
),
).toBe(false);
expect(readFileSync(statePath, "utf8")).toBe(firstPayload);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
it("recovers when a stale-generation guard owner exits before replacement", async () => {
const { createHash } = await import("node:crypto");
const { mkdtempSync, writeFileSync, readFileSync, rmSync } = await import(
"node:fs"
);
const { join } = await import("node:path");
const { tmpdir } = await import("node:os");
const dir = mkdtempSync(join(tmpdir(), "connector-claim-"));
const statePath = join(dir, "instance.json");
const stalePayload = `${JSON.stringify({
claimId: "stale",
pid: 1,
userName: "stale",
})}
`;
const replacementPayload = `${JSON.stringify({
claimId: "replacement",
pid: 2,
userName: "bot",
})}
`;
const generation = createHash("sha256").update(stalePayload).digest("hex");
const orphanedGuardPath = `${statePath}.${generation}.claim`;
writeFileSync(statePath, stalePayload, "utf8");
writeFileSync(
orphanedGuardPath,
`${JSON.stringify(
{
claimId: "orphaned",
pid: 3,
processStartToken: "process-3",
},
null,
2,
)}
`,
"utf8",
);
try {
expect(
__test__.tryReplaceStaleConnectorStateFile(
statePath,
stalePayload,
replacementPayload,
{
isRunning: () => false,
getStartToken: (pid) => `process-${pid}`,
},
),
).toBe(true);
expect(readFileSync(statePath, "utf8")).toBe(replacementPayload);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
it("does not succeed a live stale-generation guard owner", async () => {
const { createHash } = await import("node:crypto");
const { mkdtempSync, writeFileSync, readFileSync, rmSync } = await import(
"node:fs"
);
const { join } = await import("node:path");
const { tmpdir } = await import("node:os");
const dir = mkdtempSync(join(tmpdir(), "connector-claim-"));
const statePath = join(dir, "instance.json");
const stalePayload = `${JSON.stringify({
claimId: "stale",
pid: 1,
userName: "stale",
})}
`;
const replacementPayload = `${JSON.stringify({
claimId: "replacement",
pid: 2,
userName: "bot",
})}
`;
const generation = createHash("sha256").update(stalePayload).digest("hex");
writeFileSync(statePath, stalePayload, "utf8");
writeFileSync(
`${statePath}.${generation}.claim`,
`${JSON.stringify(
{
claimId: "live",
pid: 3,
processStartToken: "process-3",
},
null,
2,
)}
`,
"utf8",
);
try {
expect(
__test__.tryReplaceStaleConnectorStateFile(
statePath,
stalePayload,
replacementPayload,
{
isRunning: (pid) => pid === 3,
getStartToken: (pid) => `process-${pid}`,
},
),
).toBe(false);
expect(readFileSync(statePath, "utf8")).toBe(stalePayload);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
it("recovers when an orphaned guard pid belongs to a different process", async () => {
const { createHash } = await import("node:crypto");
const { mkdtempSync, writeFileSync, readFileSync, rmSync } = await import(
"node:fs"
);
const { join } = await import("node:path");
const { tmpdir } = await import("node:os");
const dir = mkdtempSync(join(tmpdir(), "connector-claim-"));
const statePath = join(dir, "instance.json");
const stalePayload = `${JSON.stringify({
claimId: "stale",
pid: 1,
userName: "stale",
})}
`;
const replacementPayload = `${JSON.stringify({
claimId: "replacement",
pid: 2,
userName: "bot",
})}
`;
const generation = createHash("sha256").update(stalePayload).digest("hex");
writeFileSync(statePath, stalePayload, "utf8");
writeFileSync(
`${statePath}.${generation}.claim`,
`${JSON.stringify(
{
claimId: "orphaned",
pid: 3,
processStartToken: "original-process-3",
},
null,
2,
)}
`,
"utf8",
);
try {
expect(
__test__.tryReplaceStaleConnectorStateFile(
statePath,
stalePayload,
replacementPayload,
{
isRunning: (pid) => pid === 3,
getStartToken: (pid) =>
pid === 3 ? "reused-process-3" : `process-${pid}`,
},
),
).toBe(true);
expect(readFileSync(statePath, "utf8")).toBe(replacementPayload);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
});
describe("detached connector log rotation", () => {
it("keeps one generation once the log grows past the cap", () => {
const dir = mkdtempSync(join(tmpdir(), "cline-connector-log-"));
const logPath = join(dir, "cline-slack.log");
writeFileSync(logPath, "x".repeat(__test__.DETACHED_LOG_MAX_BYTES + 1));
__test__.rotateOversizedLog(logPath);
expect(existsSync(logPath)).toBe(false);
expect(readFileSync(`${logPath}.1`, "utf8").length).toBe(
__test__.DETACHED_LOG_MAX_BYTES + 1,
);
});
it("leaves a small log in place so restarts keep their history", () => {
const dir = mkdtempSync(join(tmpdir(), "cline-connector-log-"));
const logPath = join(dir, "cline-slack.log");
writeFileSync(logPath, "recent failure");
__test__.rotateOversizedLog(logPath);
expect(readFileSync(logPath, "utf8")).toBe("recent failure");
expect(existsSync(`${logPath}.1`)).toBe(false);
});
it("does nothing when there is no log yet", () => {
const dir = mkdtempSync(join(tmpdir(), "cline-connector-log-"));
expect(() =>
__test__.rotateOversizedLog(join(dir, "missing.log")),
).not.toThrow();
});
});
+290 -1
View File
@@ -1,10 +1,14 @@
import { spawn } from "node:child_process";
import { spawn, spawnSync } from "node:child_process";
import { createHash, randomUUID } from "node:crypto";
import {
closeSync,
existsSync,
linkSync,
openSync,
readFileSync,
renameSync,
rmSync,
statSync,
writeFileSync,
} from "node:fs";
import { join } from "node:path";
@@ -28,6 +32,9 @@ export const CLINE_CONNECTOR_DETACHED_CHILD_ENV =
*/
export const CONNECT_ALREADY_RUNNING_EXIT_CODE = 75;
/** Rotate a detached connector log once it passes this size. */
const DETACHED_LOG_MAX_BYTES = 8 * 1024 * 1024;
export function parseBooleanFlag(rawArgs: string[], flag: string): boolean {
return rawArgs.includes(flag);
}
@@ -73,6 +80,70 @@ export function isProcessRunning(pid: number): boolean {
}
}
type ProcessProbe = {
isRunning: (pid: number) => boolean;
getStartToken: (pid: number) => string | undefined;
};
function getProcessStartToken(pid: number): string | undefined {
if (!Number.isInteger(pid) || pid <= 0) {
return undefined;
}
try {
if (process.platform === "linux") {
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
const commandEnd = stat.lastIndexOf(")");
if (commandEnd < 0) {
return undefined;
}
// Fields after the command name begin at field 3 (state), so field
// 22 (starttime) is index 19.
const startTime = stat
.slice(commandEnd + 1)
.trim()
.split(/\s+/)[19];
const bootId = readFileSync(
"/proc/sys/kernel/random/boot_id",
"utf8",
).trim();
return startTime && bootId ? `linux:${bootId}:${startTime}` : undefined;
}
const result =
process.platform === "win32"
? spawnSync(
"powershell.exe",
[
"-NoLogo",
"-NoProfile",
"-NonInteractive",
"-Command",
`(Get-Process -Id ${pid} -ErrorAction Stop).StartTime.ToUniversalTime().Ticks`,
],
{
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
windowsHide: true,
},
)
: spawnSync("ps", ["-p", String(pid), "-o", "lstart="], {
encoding: "utf8",
env: { ...process.env, LC_ALL: "C", TZ: "UTC" },
stdio: ["ignore", "pipe", "ignore"],
windowsHide: true,
});
const startTime = result.status === 0 ? result.stdout.trim() : "";
return startTime ? `${process.platform}:${startTime}` : undefined;
} catch {
return undefined;
}
}
const defaultProcessProbe: ProcessProbe = {
isRunning: isProcessRunning,
getStartToken: getProcessStartToken,
};
export async function terminateProcess(pid: number): Promise<boolean> {
if (!isProcessRunning(pid)) {
return false;
@@ -164,12 +235,30 @@ export function resolveConnectorDebugLogPath(
);
}
/**
* Connectors are long-lived and restart often, so an append-only log would grow
* without bound on a host that runs them for weeks. Keep one previous
* generation and start fresh once the current one gets large.
*/
function rotateOversizedLog(path: string): void {
try {
if (statSync(path).size < DETACHED_LOG_MAX_BYTES) {
return;
}
rmSync(`${path}.1`, { force: true });
renameSync(path, `${path}.1`);
} catch {
// No log yet, or it cannot be rotated: appending is still fine.
}
}
function tryOpenDetachedLogFd(path: string | undefined): number | undefined {
if (!path?.trim()) {
return undefined;
}
try {
ensureParentDir(path);
rotateOversizedLog(path);
return openSync(path, "a");
} catch {
return undefined;
@@ -269,6 +358,9 @@ export const __test__ = {
buildDetachedConnectorArgs,
buildDetachedConnectorCommand,
buildDetachedConnectorEnv,
tryReplaceStaleConnectorStateFile,
rotateOversizedLog,
DETACHED_LOG_MAX_BYTES,
};
export function readJsonFile<T>(path: string, fallback: T): T {
@@ -289,6 +381,203 @@ export function writeJsonFile(path: string, value: unknown): void {
writeFileSync(path, JSON.stringify(value, null, 2), "utf8");
}
/**
* Atomically claim a connector state path for this process.
*
* Uses O_EXCL so two concurrent `cline connect` launches cannot both observe
* "no running instance" and both proceed. Returns undefined when another live
* connector already owns the path (or a concurrent claim won the race).
*/
export function tryClaimConnectorStateFile(
statePath: string,
createState: (
claimId: string,
) => { claimId: string; pid: number } & Record<string, unknown>,
processProbe: ProcessProbe = defaultProcessProbe,
): { claimId: string } | undefined {
ensureParentDir(statePath);
const claimId = randomUUID();
const state = createState(claimId);
const payload = `${JSON.stringify(state, null, 2)}
`;
if (tryCreateConnectorStateFile(statePath, payload)) {
return { claimId };
}
let observedPayload: string;
try {
observedPayload = readFileSync(statePath, "utf8");
} catch {
return undefined;
}
try {
const existing = JSON.parse(observedPayload) as { pid?: unknown };
const existingPid =
typeof existing.pid === "number" ? existing.pid : undefined;
if (existingPid !== undefined && processProbe.isRunning(existingPid)) {
return undefined;
}
} catch (error) {
if (!(error instanceof SyntaxError)) {
return undefined;
}
}
return tryReplaceStaleConnectorStateFile(
statePath,
observedPayload,
payload,
processProbe,
)
? { claimId }
: undefined;
}
function tryCreateConnectorStateFile(
statePath: string,
payload: string,
): boolean {
let fd: number;
try {
fd = openSync(statePath, "wx");
} catch (error) {
const code =
error && typeof error === "object" && "code" in error
? String((error as NodeJS.ErrnoException).code)
: undefined;
if (code === "EEXIST") {
return false;
}
throw error;
}
try {
writeFileSync(fd, payload, "utf8");
} finally {
closeSync(fd);
}
return true;
}
/**
* Replaces exactly the stale generation that the caller observed.
*
* Each contender atomically links its ownership record into a guard keyed by
* the observed generation. A live guard owner blocks replacement. If an owner
* dies in the critical section, contenders append a successor guard rather
* than deleting the existing one, so stale recovery remains crash-safe.
*/
function tryReplaceStaleConnectorStateFile(
statePath: string,
observedPayload: string,
replacementPayload: string,
processProbe: ProcessProbe = defaultProcessProbe,
): boolean {
let replacement: { claimId?: unknown; pid?: unknown };
try {
replacement = JSON.parse(replacementPayload) as {
claimId?: unknown;
pid?: unknown;
};
} catch {
return false;
}
if (
typeof replacement.claimId !== "string" ||
typeof replacement.pid !== "number"
) {
return false;
}
const generation = createHash("sha256").update(observedPayload).digest("hex");
const ownerPayload = `${JSON.stringify(
{
claimId: replacement.claimId,
pid: replacement.pid,
processStartToken: processProbe.getStartToken(replacement.pid),
},
null,
2,
)}
`;
const candidatePath = `${statePath}.${replacement.claimId}.candidate`;
if (!tryCreateConnectorStateFile(candidatePath, ownerPayload)) {
return false;
}
const guardPaths: string[] = [];
let acquiredGuard = false;
try {
let guardPath = `${statePath}.${generation}.claim`;
while (true) {
guardPaths.push(guardPath);
try {
linkSync(candidatePath, guardPath);
acquiredGuard = true;
break;
} catch (error) {
const code =
error && typeof error === "object" && "code" in error
? String((error as NodeJS.ErrnoException).code)
: undefined;
if (code !== "EEXIST") {
throw error;
}
}
let guardPayload: string;
try {
guardPayload = readFileSync(guardPath, "utf8");
} catch {
return false;
}
try {
const guardOwner = JSON.parse(guardPayload) as {
pid?: unknown;
processStartToken?: unknown;
};
if (
typeof guardOwner.pid === "number" &&
processProbe.isRunning(guardOwner.pid)
) {
const runningStartToken = processProbe.getStartToken(guardOwner.pid);
if (
typeof guardOwner.processStartToken !== "string" ||
runningStartToken === undefined ||
runningStartToken === guardOwner.processStartToken
) {
return false;
}
}
} catch {
// Invalid ownership metadata cannot identify a live owner.
}
const successor = createHash("sha256")
.update(guardPath)
.update("\0")
.update(guardPayload)
.digest("hex");
guardPath = `${statePath}.${generation}.${successor}.claim`;
}
if (readFileSync(statePath, "utf8") !== observedPayload) {
return false;
}
rmSync(statePath);
return tryCreateConnectorStateFile(statePath, replacementPayload);
} catch {
return false;
} finally {
rmSync(candidatePath, { force: true });
if (acquiredGuard) {
for (const guardPath of guardPaths) {
rmSync(guardPath, { force: true });
}
}
}
}
export function removeFile(path: string): void {
try {
rmSync(path, { force: true });
+131 -2
View File
@@ -178,6 +178,52 @@ describe("handleConnectorUserTurn", () => {
}
});
it("posts no greeting when the adapter configures none", async () => {
// Slack deliberately configures no first-contact message: the greeting is
// gated on per-thread state, so a restart or a cleared history replayed it
// on the user's next message.
const dir = mkdtempSync(join(tmpdir(), "connector-host-test-"));
tempDirs.push(dir);
const bindingsPath = join(dir, "threads.json");
const { thread, posts } = createThread({
enableTools: false,
autoApproveTools: false,
cwd: "/tmp/work",
workspaceRoot: "/tmp/work",
participantKey: "slack:user:alice",
participantLabel: "alice",
});
await handleConnectorUserTurn({
thread: thread as never,
client: {} as never,
pendingApprovals: new Map(),
baseStartRequest: baseStartRequest() as never,
explicitSystemPrompt: undefined,
clientId: "client-1",
logger: {
core: { debug: vi.fn(), log: vi.fn(), error: vi.fn() },
} as never,
transport: "slack",
botUserName: "cline-slack",
requestStop: vi.fn(),
bindingsPath,
systemRules: "rules",
errorLabel: "Slack",
getSessionMetadata: () => ({}),
reusedLogMessage: "reused",
text: "/whereami",
});
expect(
posts.filter((message) => messageText(message).includes("Connected")),
).toEqual([]);
// The turn itself still answers.
expect(messageText(posts.at(-1))).toContain(
"participantKey=slack:user:alice",
);
});
it("sends a first-contact message only once per persisted thread state", async () => {
const dir = mkdtempSync(join(tmpdir(), "connector-host-test-"));
tempDirs.push(dir);
@@ -644,6 +690,81 @@ describe("handleConnectorUserTurn", () => {
).toBe(false);
});
it("recovers when the bound session is wedged on a run that never drained", async () => {
// Cline Mom's failure: the thread pointed at a session whose runtime still
// had a run in flight, so every message came back as "SessionRuntime.shutdown
// called while a run is in progress" instead of answering.
const dir = mkdtempSync(join(tmpdir(), "connector-host-test-"));
tempDirs.push(dir);
const bindingsPath = join(dir, "threads.json");
const { thread, posts, getState } = createThread({
enableTools: false,
autoApproveTools: false,
cwd: "/tmp/work",
workspaceRoot: "/tmp/work",
sessionId: "wedged-session",
welcomeSentAt: new Date().toISOString(),
});
const runtime = createRuntimeClient("recovered reply");
runtime.getSession.mockImplementation(async (sessionId: string) => ({
sessionId,
}));
runtime.startRuntimeSession.mockResolvedValue({
sessionId: "fresh-session",
});
runtime.sendRuntimeSession.mockImplementation(async (sessionId: string) => {
if (sessionId === "wedged-session") {
// Crossing the hub's JSON boundary strips the error class, so only the
// message survives — which is exactly what the connector sees.
throw new Error(
"SessionRuntime.shutdown called while a run is in progress (agentId=agent_123)",
);
}
return {
result: {
text: "recovered reply",
finishReason: "stop",
iterations: 1,
},
};
});
await handleConnectorUserTurn({
thread: thread as never,
text: "are you there?",
client: runtime.client as never,
pendingApprovals: new Map(),
baseStartRequest: baseStartRequest() as never,
explicitSystemPrompt: undefined,
clientId: "client-1",
logger: {
core: { debug: vi.fn(), log: vi.fn(), error: vi.fn() },
} as never,
transport: "slack",
botUserName: "ClineAdapterBot",
requestStop: vi.fn(),
bindingsPath,
systemRules: "rules",
errorLabel: "Slack",
getSessionMetadata: () => ({}),
reusedLogMessage: "reused",
startedLogMessage: "started",
});
expect(
runtime.sendRuntimeSession.mock.calls.map((call) => call[0]),
).toEqual(["wedged-session", "fresh-session"]);
// The stale mapping is replaced, so the thread is not wedged next time.
expect(getState().sessionId).toBe("fresh-session");
expect(messageText(posts.at(-1))).toBe("recovered reply");
expect(
posts.some((message) =>
messageText(message).includes("run is in progress"),
),
).toBe(false);
});
it("does not retry forever when the replacement session is also missing", async () => {
const dir = mkdtempSync(join(tmpdir(), "connector-host-test-"));
tempDirs.push(dir);
@@ -1777,7 +1898,11 @@ describe("handleConnectorUserTurn", () => {
}),
{ timeoutMs: null },
);
expect(posts.at(-1)).toEqual({ raw: "Steering current task." });
// Handing the follow-up to the running session is silent: no acknowledgement
// line is added to the thread.
expect(
posts.some((message) => messageText(message).includes("Steering")),
).toBe(false);
});
it("steers when the same session is active under a different turn key", async () => {
@@ -1829,7 +1954,11 @@ describe("handleConnectorUserTurn", () => {
}),
{ timeoutMs: null },
);
expect(posts.at(-1)).toEqual({ raw: "Steering current task." });
// Handing the follow-up to the running session is silent: no acknowledgement
// line is added to the thread.
expect(
posts.some((message) => messageText(message).includes("Steering")),
).toBe(false);
});
it("starts a normal turn when the active session is in a different thread", async () => {
+82 -9
View File
@@ -6,7 +6,8 @@ import type {
HubSessionClient,
UserInstructionConfigService,
} from "@cline/core";
import { isSessionNotFoundError } from "@cline/core";
import { isUnusableSessionError } from "@cline/core";
import type { GeneratedMedia } from "@cline/shared";
import type { SentMessage, Thread } from "chat";
import type { CliLoggerAdapter } from "../logging/adapter";
import { buildUserInputMessage, resolveSystemPrompt } from "../runtime/prompt";
@@ -125,6 +126,7 @@ async function postConnectorRuntimeReply<TState extends ConnectorThreadState>(
stream: AsyncIterable<string>,
postFinalReply?: (text: string) => Promise<void>,
resolveFallbackText?: () => Promise<string | undefined>,
hasNonTextReply?: () => boolean,
): Promise<void> {
if (transport !== "telegram" && !postFinalReply && !resolveFallbackText) {
await thread.post(stream);
@@ -135,6 +137,9 @@ async function postConnectorRuntimeReply<TState extends ConnectorThreadState>(
for await (const chunk of stream) {
text += chunk;
}
if (!text.trim() && hasNonTextReply?.()) {
return;
}
if (!text.trim()) {
text = (await resolveFallbackText?.())?.trim() || "";
}
@@ -151,6 +156,67 @@ async function postConnectorRuntimeReply<TState extends ConnectorThreadState>(
await postConnectorText(thread, transport, text);
}
const CONNECTOR_MEDIA_EXTENSIONS: Readonly<Record<string, string>> = {
"image/png": "png",
"image/jpeg": "jpg",
"image/gif": "gif",
"image/webp": "webp",
"audio/mpeg": "mp3",
"audio/wav": "wav",
"audio/ogg": "ogg",
"video/mp4": "mp4",
"video/webm": "webm",
};
async function postConnectorGeneratedMedia<TState extends ConnectorThreadState>(
thread: Thread<TState>,
mediaItems: readonly GeneratedMedia[],
): Promise<void> {
if (mediaItems.length === 0) {
return;
}
const files: Array<{ data: Buffer; filename: string; mimeType: string }> = [];
const references: string[] = [];
for (const [index, media] of mediaItems.entries()) {
const label = media.name?.trim() || `Generated ${media.modality}`;
switch (media.source.type) {
case "base64": {
const data = Buffer.from(media.source.data, "base64");
if (data.byteLength === 0) {
references.push(
`${label} (${media.mediaType}) could not be attached.`,
);
break;
}
const extension =
CONNECTOR_MEDIA_EXTENSIONS[media.mediaType.toLowerCase()] ?? "bin";
const suppliedName = media.name ? basename(media.name) : "";
files.push({
data,
filename: suppliedName || `generated-${index + 1}.${extension}`,
mimeType: media.mediaType,
});
break;
}
case "url":
references.push(`[${label}](${media.source.url})`);
break;
case "artifact":
references.push(`${label}: artifact ${media.source.artifactId}`);
break;
}
}
if (files.length === 0 && references.length === 0) {
return;
}
await thread.post({
markdown: references.length > 0 ? references.join("\n") : "Generated media",
...(files.length > 0 ? { files } : {}),
});
}
/**
* Clears a thread's stale session mapping after the hub reported the mapped
* session no longer exists, so the next turn starts a fresh session instead of
@@ -975,10 +1041,12 @@ export async function handleConnectorUserTurn<
{ timeoutMs: null },
);
} catch (error) {
if (!isSessionNotFoundError(error)) {
if (!isUnusableSessionError(error)) {
throw error;
}
// The tracked turn points at a session the hub no longer knows about.
// The tracked turn points at a session that can no longer serve it —
// the hub does not know it, or its runtime is stuck on a run that never
// drained.
// Remove only the entry we attempted to steer, then route recovery
// through the normal per-thread queue. Concurrent messages that saw
// the same stale turn will line up behind this one instead of creating
@@ -1002,11 +1070,10 @@ export async function handleConnectorUserTurn<
);
return;
}
await postConnectorText(
input.thread,
input.transport,
"Steering current task.",
);
// No acknowledgement: the follow-up is handed to the running session and its
// effect shows up in the answer. Announcing it added a line to every thread
// and overstated what happens, since the prompt is queued for the session
// rather than injected into the loop already running.
return;
}
@@ -1104,7 +1171,7 @@ async function runConnectorRuntimeTurnWithRecovery<
});
break;
} catch (error) {
if (!allowStaleSessionRetry || !isSessionNotFoundError(error)) {
if (!allowStaleSessionRetry || !isUnusableSessionError(error)) {
throw error;
}
allowStaleSessionRetry = false;
@@ -1150,6 +1217,7 @@ async function runConnectorRuntimeTurn<
client: input.client,
sessionId,
});
const generatedMedia: GeneratedMedia[] = [];
const activeTurn: ActiveConnectorTurn = {
sessionId,
@@ -1199,6 +1267,9 @@ async function runConnectorRuntimeTurn<
formatConnectorApprovalPrompt(approval),
);
},
onMedia: (media) => {
generatedMedia.push(media);
},
onCompleted: async (result) => {
await input.onReplyCompleted?.({
sessionId,
@@ -1218,7 +1289,9 @@ async function runConnectorRuntimeTurn<
}),
postFinalReply,
resolveFallbackText,
() => generatedMedia.length > 0,
);
await postConnectorGeneratedMedia(input.thread, generatedMedia);
} finally {
input.pendingApprovals.delete(input.thread.id);
if (input.activeTurns?.get(turnKey) === activeTurn) {
@@ -11,6 +11,49 @@ type StreamHandlers = {
};
describe("createConnectorRuntimeTurnStream", () => {
it("forwards generated media without adding binary data to the text stream", async () => {
let handlers: StreamHandlers | undefined;
const media = {
id: "generated-1",
modality: "image" as const,
mediaType: "image/png",
source: { type: "base64" as const, data: "aGVsbG8=" },
};
const client = {
streamEvents: (_request: unknown, callbacks: StreamHandlers) => {
handlers = callbacks;
return () => {};
},
sendRuntimeSession: async () => {
handlers?.onEvent({
eventType: "runtime.chat.media",
payload: { media },
});
return { result: { text: "", finishReason: "stop", iterations: 1 } };
},
};
const receivedMedia: unknown[] = [];
const chunks: string[] = [];
for await (const chunk of createConnectorRuntimeTurnStream({
client: client as never,
sessionId: "session-1",
request: { config: {} as never, prompt: "make an image" },
clientId: "client-1",
logger: { core: {} } as unknown as CliLoggerAdapter,
transport: "slack",
conversationId: "thread-1",
onMedia: (item) => {
receivedMedia.push(item);
},
})) {
chunks.push(chunk);
}
expect(chunks).toEqual([]);
expect(receivedMedia).toEqual([media]);
});
it("delivers tool status via callbacks instead of appending it to streamed text", async () => {
let handlers: StreamHandlers | undefined;
+9
View File
@@ -1,4 +1,5 @@
import type { ChatRunTurnRequest, HubSessionClient } from "@cline/core";
import { type GeneratedMedia, isGeneratedMedia } from "@cline/shared";
import type { CliLoggerAdapter } from "../logging/adapter";
export type PendingConnectorApproval = {
@@ -141,6 +142,7 @@ export function createConnectorRuntimeTurnStream(input: {
conversationId: string;
onToolStatus?: (message: string) => Promise<void>;
onApprovalRequested?: (approval: PendingConnectorApproval) => Promise<void>;
onMedia?: (media: GeneratedMedia) => Promise<void> | void;
onCompleted?: (result: {
text: string;
finishReason?: string;
@@ -189,6 +191,13 @@ export function createConnectorRuntimeTurnStream(input: {
},
{
onEvent: (event) => {
if (event.eventType === "runtime.chat.media") {
const media = event.payload.media;
if (isGeneratedMedia(media)) {
void input.onMedia?.(media);
}
return;
}
if (event.eventType === "approval.requested") {
const approvalId =
typeof event.payload.approvalId === "string"
@@ -62,7 +62,10 @@ vi.mock("../commands/auth", async () => {
};
});
import { buildConnectorStartRequest } from "./session-runtime";
import {
buildConnectorStartRequest,
isReusableConnectorSession,
} from "./session-runtime";
describe("buildConnectorStartRequest", () => {
beforeEach(() => {
@@ -161,3 +164,32 @@ describe("buildConnectorStartRequest", () => {
expect(request.model).toBe("cline-pass/glm-5.2");
});
});
describe("isReusableConnectorSession", () => {
it("rejects missing and terminal sessions", () => {
expect(isReusableConnectorSession(undefined)).toBe(false);
expect(isReusableConnectorSession({ sessionId: "" })).toBe(false);
expect(
isReusableConnectorSession({ sessionId: "s1", status: "completed" }),
).toBe(false);
expect(
isReusableConnectorSession({ sessionId: "s1", status: "failed" }),
).toBe(false);
expect(
isReusableConnectorSession({ sessionId: "s1", status: "aborted" }),
).toBe(false);
expect(
isReusableConnectorSession({ sessionId: "s1", status: "cancelled" }),
).toBe(false);
});
it("accepts live and status-omitted sessions", () => {
expect(
isReusableConnectorSession({ sessionId: "s1", status: "running" }),
).toBe(true);
expect(
isReusableConnectorSession({ sessionId: "s1", status: "idle" }),
).toBe(true);
expect(isReusableConnectorSession({ sessionId: "s1" })).toBe(true);
});
});
+28 -2
View File
@@ -137,6 +137,29 @@ export function buildThreadStartRequest<TState extends ConnectorThreadState>(
};
}
/** Terminal hub statuses are not reusable for a new connector turn. */
const TERMINAL_HUB_SESSION_STATUSES = new Set([
"completed",
"failed",
"aborted",
"cancelled",
]);
export function isReusableConnectorSession(
session: { sessionId?: string; status?: string } | undefined | null,
): boolean {
if (!session?.sessionId?.trim()) {
return false;
}
const status = session.status?.trim().toLowerCase();
if (!status) {
// Older hubs omit status; treat presence as reusable and let send-time
// session_not_found recovery handle true zombies.
return true;
}
return !TERMINAL_HUB_SESSION_STATUSES.has(status);
}
export async function getOrCreateSessionId<
TState extends ConnectorThreadState,
>(input: {
@@ -162,7 +185,7 @@ export async function getOrCreateSessionId<
const existing = threadState.sessionId?.trim();
if (existing) {
const existingSession = await input.client.getSession(existing);
if (existingSession) {
if (isReusableConnectorSession(existingSession)) {
await persistMergedThreadState(
input.thread,
input.bindingsPath,
@@ -204,12 +227,15 @@ export async function getOrCreateSessionId<
input.errorLabel,
);
input.logger.core.log(
"Connector thread session missing; starting a new session",
existingSession
? "Connector thread session is terminal; starting a new session"
: "Connector thread session missing; starting a new session",
{
severity: "warn",
transport: input.transport,
threadId: input.thread.id,
sessionId: existing,
...(existingSession?.status ? { status: existingSession.status } : {}),
},
);
}
@@ -153,6 +153,26 @@ export function writeBindings<TState extends ConnectorThreadState>(
writeJsonFile(path, bindings);
}
/**
* Key under which turns for `thread` must be serialised.
*
* This has to follow the same identity rule as {@link findBindingForThread},
* because whatever shares a session has to share a queue. A DM reuses one
* binding and therefore one runtime session for every message in the
* channel, so keying the queue by thread id would let two messages in the same
* DM run against that one session concurrently. That surfaces as
* "SessionRuntime.shutdown called while a run is in progress", or as two
* conversations interleaved in one session's history.
*
* Channel threads each own their binding, so they keep their own key and go on
* running independently of one another.
*/
export function resolveThreadTurnQueueKey(
thread: Pick<ConnectorBindingThreadIdentity, "id" | "channelId" | "isDM">,
): string {
return thread.isDM ? `dm:${thread.channelId}` : thread.id;
}
export function findBindingForThread<TState extends ConnectorThreadState>(
bindings: ConnectorBindingStore<TState>,
thread: ConnectorBindingThreadIdentity,
@@ -0,0 +1,132 @@
import { describe, expect, it } from "vitest";
import { enqueueThreadTurn } from "./chat-runtime";
import { resolveThreadTurnQueueKey } from "./thread-bindings";
describe("resolveThreadTurnQueueKey", () => {
it("gives every channel thread its own key", () => {
// Channel threads each own a binding and a session, so they run in parallel.
const first = resolveThreadTurnQueueKey({
id: "slack:C1:1111.1",
channelId: "slack:C1",
isDM: false,
});
const second = resolveThreadTurnQueueKey({
id: "slack:C1:2222.2",
channelId: "slack:C1",
isDM: false,
});
expect(first).not.toBe(second);
expect(first).toBe("slack:C1:1111.1");
});
it("collapses every message in one DM onto a single key", () => {
// findBindingForThread reuses one binding for a whole DM channel, so those
// messages share a session and must not run concurrently.
const first = resolveThreadTurnQueueKey({
id: "slack:D1:1111.1",
channelId: "slack:D1",
isDM: true,
});
const second = resolveThreadTurnQueueKey({
id: "slack:D1:2222.2",
channelId: "slack:D1",
isDM: true,
});
expect(first).toBe(second);
});
it("keeps separate DM channels separate", () => {
expect(
resolveThreadTurnQueueKey({
id: "slack:D1:1111.1",
channelId: "slack:D1",
isDM: true,
}),
).not.toBe(
resolveThreadTurnQueueKey({
id: "slack:D2:1111.1",
channelId: "slack:D2",
isDM: true,
}),
);
});
});
describe("thread turn scheduling", () => {
function deferred() {
let resolve!: () => void;
const promise = new Promise<void>((r) => {
resolve = r;
});
return { promise, resolve };
}
it("runs two messages in the same DM one after the other", async () => {
const queues = new Map<string, Promise<void>>();
const dm = { id: "slack:D1:1.1", channelId: "slack:D1", isDM: true };
const later = { id: "slack:D1:2.2", channelId: "slack:D1", isDM: true };
const order: string[] = [];
const first = deferred();
const firstTurn = enqueueThreadTurn(
queues,
resolveThreadTurnQueueKey(dm),
async () => {
order.push("first:start");
await first.promise;
order.push("first:end");
},
);
const secondTurn = enqueueThreadTurn(
queues,
resolveThreadTurnQueueKey(later),
async () => {
order.push("second:start");
},
);
// The second message must not touch the shared session until the first
// message's run has finished.
await new Promise((resolve) => setImmediate(resolve));
expect(order).toEqual(["first:start"]);
first.resolve();
await Promise.all([firstTurn, secondTurn]);
expect(order).toEqual(["first:start", "first:end", "second:start"]);
});
it("runs two channel threads at the same time", async () => {
const queues = new Map<string, Promise<void>>();
const threadA = { id: "slack:C1:1.1", channelId: "slack:C1", isDM: false };
const threadB = { id: "slack:C1:2.2", channelId: "slack:C1", isDM: false };
const order: string[] = [];
const blocked = deferred();
const turnA = enqueueThreadTurn(
queues,
resolveThreadTurnQueueKey(threadA),
async () => {
order.push("a:start");
await blocked.promise;
order.push("a:end");
},
);
const turnB = enqueueThreadTurn(
queues,
resolveThreadTurnQueueKey(threadB),
async () => {
order.push("b:start");
},
);
// B answers while A is still working: separate threads, separate sessions.
await new Promise((resolve) => setImmediate(resolve));
expect(order).toEqual(["a:start", "b:start"]);
blocked.resolve();
await Promise.all([turnA, turnB]);
expect(order).toEqual(["a:start", "b:start", "a:end"]);
});
});
+6
View File
@@ -24,6 +24,12 @@ export interface ConnectCommandDefinition {
): Promise<number>;
validate(args: string[], io: ConnectIo): Promise<number>;
showHelp(io: ConnectIo): void;
/**
* Instance id `args` would run as, when it is knowable without side effects.
* The hub keys connector supervision by (channel, instanceId) and needs it
* before spawning; undefined sends the caller to the local start path.
*/
resolveInstanceId?(args: string[]): string | undefined;
stopAll?(io: ConnectIo): Promise<ConnectStopResult>;
stopInstance?(instanceId: string, io: ConnectIo): Promise<ConnectStopResult>;
}
+19 -2
View File
@@ -2,9 +2,10 @@
import { isMainThread } from "node:worker_threads";
import {
claimHubDaemonProcess,
claimSupervisedConnectorProcess,
disposeAll,
initVcr,
isHubDaemonProcess,
setConnectorCliLaunchSpec,
} from "@cline/shared";
import { logCliProcessError } from "./logging/errors";
@@ -22,11 +23,18 @@ initVcr(process.env.CLINE_VCR);
if (!isMainThread) {
// Worker imports of the bundled CLI entrypoint should not start the CLI.
} else if (isHubDaemonProcess()) {
} else if (claimHubDaemonProcess()) {
// Claim rather than read: the sentinel is consumed here so the processes a
// daemon-hosted session spawns do not inherit it and try to become daemons.
// The hub daemon owns its process-level abort handling. Installing the CLI's
// fatal rejection handler first would make expected abort rejections exit it.
void import("@cline/core/hub/daemon-entry");
} else {
// Same reasoning as the daemon sentinel above: consume the supervised-connector
// marker so the processes an agent session spawns cannot inherit it and mistake
// themselves for the connector the hub is tracking.
claimSupervisedConnectorProcess();
const cliLaunchSpec = resolveCliLaunchSpec({ debugRole: "connector" });
if (cliLaunchSpec) {
setConnectorCliLaunchSpec({
@@ -89,6 +97,15 @@ if (!isMainThread) {
} finally {
await disposeAll();
}
// The explicit process.exit below means beforeExit never fires, so a
// startup-recorded auto-update must be applied here, after all runtime
// teardown. It spawns detached and only when no other CLI is attached.
try {
const { applyDeferredUpdate } = await import("./commands/update");
await applyDeferredUpdate();
} catch {
// Best-effort; never block exit on the updater.
}
process.exit(exitCode || (process.exitCode as number) || 0);
})();
}
+63
View File
@@ -66,6 +66,7 @@ const dashboardMocks = vi.hoisted(() => ({
}));
const connectMocks = vi.hoisted(() => ({
formatAdapterList: vi.fn(() => ""),
runCleanupConnectorInstance: vi.fn(async () => 0),
runConnectAdapter: vi.fn(async () => 0),
runRestartConnector: vi.fn(async () => 0),
runStopAllConnectors: vi.fn(async () => 0),
@@ -396,6 +397,68 @@ describe("runCli lightweight command dispatch", () => {
expect(connectMocks.runStopConnector).not.toHaveBeenCalled();
});
it("routes a supervised cleanup to one connector instance", async () => {
connectMocks.runCleanupConnectorInstance.mockClear();
connectMocks.runConnectAdapter.mockClear();
process.argv = [
"bun",
"src/index.ts",
"connect",
"--cleanup-instance",
"cline-slack",
"slack",
];
const { runCli } = await import("./main");
await expect(runCli()).resolves.toBeUndefined();
expect(process.exitCode).toBe(0);
expect(connectMocks.runCleanupConnectorInstance).toHaveBeenCalledWith(
"slack",
"cline-slack",
expect.any(Object),
);
expect(connectMocks.runConnectAdapter).not.toHaveBeenCalled();
});
it("rejects combining cleanup with another connect mode", async () => {
connectMocks.runCleanupConnectorInstance.mockClear();
connectMocks.runStopConnector.mockClear();
process.argv = [
"bun",
"src/index.ts",
"connect",
"--cleanup-instance",
"cline-slack",
"--stop",
"slack",
];
const { runCli } = await import("./main");
await runCli();
expect(process.exitCode).toBe(1);
expect(connectMocks.runCleanupConnectorInstance).not.toHaveBeenCalled();
expect(connectMocks.runStopConnector).not.toHaveBeenCalled();
});
it("requires a channel for a supervised cleanup", async () => {
connectMocks.runCleanupConnectorInstance.mockClear();
process.argv = [
"bun",
"src/index.ts",
"connect",
"--cleanup-instance",
"x",
];
const { runCli } = await import("./main");
await runCli();
expect(process.exitCode).toBe(1);
expect(connectMocks.runCleanupConnectorInstance).not.toHaveBeenCalled();
});
it("routes a targeted connector restart to one instance", async () => {
process.argv = [
"bun",
+47 -3
View File
@@ -384,6 +384,10 @@ export async function runCli(): Promise<void> {
"--restart-instance <id>",
"Restart one connector instance (used by daemon recovery)",
)
.option(
"--cleanup-instance <id>",
"Reap one dead connector instance, preserving autostart (used by hub supervision)",
)
.allowUnknownOption()
.passThroughOptions()
.addHelpText(
@@ -393,15 +397,34 @@ export async function runCli(): Promise<void> {
.action(async (adapter: string | undefined) => {
const {
formatAdapterList,
runCleanupConnectorInstance,
runConnectAdapter,
runRestartConnector,
runStopAllConnectors,
runStopConnector,
} = await import("./commands/connect");
const opts = connectCmd.opts();
if (opts.stop && (opts.restart || opts.restartInstance)) {
io.writeErr("connect accepts only one of --stop or --restart");
const exclusiveModes = [
opts.stop,
opts.restart || opts.restartInstance,
opts.cleanupInstance,
].filter(Boolean).length;
if (exclusiveModes > 1) {
io.writeErr(
"connect accepts only one of --stop, --restart or --cleanup-instance",
);
ctx.exitCode = 1;
} else if (opts.cleanupInstance) {
if (!adapter) {
io.writeErr("connect --cleanup-instance requires a channel");
ctx.exitCode = 1;
} else {
ctx.exitCode = await runCleanupConnectorInstance(
adapter,
opts.cleanupInstance,
io,
);
}
} else if (opts.stop) {
if (adapter) {
ctx.exitCode = await runStopConnector(adapter, io);
@@ -482,6 +505,24 @@ export async function runCli(): Promise<void> {
io,
});
});
const mcpUninstallCmd = mcpCmd
.command("uninstall")
.alias("remove")
.alias("rm")
.description("Uninstall an MCP server by name")
.argument("<name>", "MCP server name")
.option("--json", "Output as JSON")
.action(async (name: string) => {
const opts = mcpUninstallCmd.opts<{
json?: boolean;
}>();
const { runMcpUninstallCommand } = await import("./commands/mcp");
ctx.exitCode = await runMcpUninstallCommand({
name,
json: opts.json === true || program.opts().json === true,
io,
});
});
const createDoctorRuntimeCommand = async () => {
const { createDoctorCommand } = await import("./commands/doctor");
@@ -775,7 +816,10 @@ export async function runCli(): Promise<void> {
// Enters the Agent Client Protocol stdio transport and never falls through.
if (args.acpMode) {
const { runAcpMode } = await import("./acp/index");
await runAcpMode();
// Only an explicit `--auto-approve true` (or `--yolo`) enables
// auto-approval in ACP mode; We do not respect the default to
// avoid accidental auto-approval in ACP mode.
await runAcpMode({ autoApproveTools: args.autoApproveOverride === true });
return;
}
@@ -1012,7 +1012,9 @@ Review with the bundled skill.`,
const linear = data.mcp.find((item) => item.name === "linear");
const docs = data.mcp.find((item) => item.name === "docs");
expect(linear?.description).toBe("streamableHttp, oauth error, timeout 60s");
expect(linear?.description).toBe(
"streamableHttp, oauth error, timeout 60s",
);
expect(linear?.loadError).toBe("OAuth authorization failed");
expect(docs?.description).toBe("sse, oauth authorized, timeout 60s");
expect(docs?.loadError).toBeUndefined();
@@ -15,7 +15,7 @@ import {
type ToolApprovalResult,
type UserInstructionConfigService,
} from "@cline/core";
import type { Message } from "@cline/shared";
import type { MessageWithMetadata } from "@cline/shared";
import { createCliCore } from "../../session/session";
import { submitAndExitInTerminal } from "../../utils/approval";
import type {
@@ -56,11 +56,11 @@ type AskQuestionRef = {
current: ((question: string, options: string[]) => Promise<string>) | null;
};
type CurrentMessagesRead =
| { messages: Message[]; status: "read" }
| { messages: Message[]; status: "recovered" }
| { messages: Message[]; status: "stale" };
| { messages: MessageWithMetadata[]; status: "read" }
| { messages: MessageWithMetadata[]; status: "recovered" }
| { messages: MessageWithMetadata[]; status: "stale" };
type MissingSessionRecovery = {
messages: Message[];
messages: MessageWithMetadata[];
};
type ToolPolicyResolver = (
toolName: string,
@@ -210,7 +210,7 @@ export function createInteractiveSessionRuntime(input: {
};
const startFreshSession = async (
initial: Message[] = [],
initial: MessageWithMetadata[] = [],
sessionMetadata?: Record<string, unknown>,
initialCompactionState?: SessionCompactionState,
// Restarting an old session associate with this ID,
@@ -243,7 +243,7 @@ export function createInteractiveSessionRuntime(input: {
const startResumedSession = async (
resumeId: string,
initial: Message[] | undefined,
initial: MessageWithMetadata[] | undefined,
): Promise<void> => {
const generation = sessionStartGeneration;
const manager = await ensureSessionManager();
@@ -421,7 +421,7 @@ export function createInteractiveSessionRuntime(input: {
};
const restartWithMessages = async (
messages: Message[],
messages: MessageWithMetadata[],
sessionMetadata?: Record<string, unknown>,
initialCompactionState?: SessionCompactionState,
options?: { preserveSessionId?: boolean },
@@ -659,7 +659,9 @@ export function createInteractiveSessionRuntime(input: {
};
};
const resumeSession = async (sessionId: string): Promise<Message[]> => {
const resumeSession = async (
sessionId: string,
): Promise<MessageWithMetadata[]> => {
const manager = await ensureSessionManager();
const sessionRecord = await manager.get(sessionId);
if (!sessionRecord) {
@@ -754,7 +756,7 @@ export function createInteractiveSessionRuntime(input: {
const getCheckpointData = async (): Promise<
| {
messages: Message[];
messages: MessageWithMetadata[];
checkpointHistory: CheckpointEntry[];
}
| undefined
@@ -777,7 +779,9 @@ export function createInteractiveSessionRuntime(input: {
const restoreCheckpoint = async (
runCount: number,
restoreWorkspace: boolean,
): Promise<{ newSessionId: string; messages: Message[] } | undefined> => {
): Promise<
{ newSessionId: string; messages: MessageWithMetadata[] } | undefined
> => {
const manager = sessionManager;
if (!manager || !activeSessionId) {
return undefined;
@@ -80,7 +80,9 @@ describe("applyInteractiveModelChange", () => {
}));
const saveProviderSettings = vi.fn(() => ({
version: 1 as const,
modes: {},
providers: {},
modes: {},
}));
const ensureReady = vi.fn(async () => {});
const restartWithCurrentMessages = vi.fn(async () => {});
+20
View File
@@ -490,6 +490,7 @@ export async function runInteractive(
tuiApp?.destroy();
});
let startupErrorReported = false;
let updateCliAfterExit = false;
const loadDeferredInitialMessages = resumeSessionId?.trim()
? async () => {
try {
@@ -749,6 +750,10 @@ export async function runInteractive(
onExit: () => {
tuiApp?.destroy();
},
onHubUpdateRestart: () => {
updateCliAfterExit = true;
tuiApp?.destroy();
},
onRunningChange: (running) => {
isRunning = running;
if (!running) {
@@ -877,4 +882,19 @@ export async function runInteractive(
prepareTerminalForPostTuiOutput();
writeln(formatInteractiveExitSummary(exitSummary));
}
if (updateCliAfterExit) {
if (!exitSummary) {
prepareTerminalForPostTuiOutput();
}
writeln(
"The shared Cline Hub was updated by another Cline installation. Updating this CLI…",
);
const { checkForUpdates } = await import("../commands/update");
const exitCode = await checkForUpdates({ includeKanban: false });
writeln(
exitCode === 0
? "Start cline again to reconnect to the updated Hub."
: "Update did not complete. Run 'cline update' manually, then start cline again.",
);
}
}
+7
View File
@@ -2,6 +2,7 @@ import {
type BuiltinToolAvailabilityContext,
getCoreBuiltinToolCatalog,
resolveDisabledToolNames,
resolveModelToolSettings,
type ToolCatalogEntry,
} from "@cline/core";
@@ -10,8 +11,14 @@ export type { ToolCatalogEntry } from "@cline/core";
export function getToolCatalog(
availabilityContext?: BuiltinToolAvailabilityContext,
): ToolCatalogEntry[] {
const modelToolSettings = resolveModelToolSettings();
return getCoreBuiltinToolCatalog({
disabledToolIds: resolveDisabledToolNames(),
enabledModelToolIds: new Set(
Object.entries(modelToolSettings)
.filter(([, setting]) => setting?.enabled === true)
.map(([name]) => name),
),
...availabilityContext,
});
}
+37
View File
@@ -0,0 +1,37 @@
import { describe, expect, it } from "vitest";
import { generateConversationHTML } from "./export";
describe("generateConversationHTML", () => {
it("renders provider model activity with the ordinary tool HTML", () => {
const html = generateConversationHTML(
{
version: 1,
updated_at: "2026-08-13T00:00:00.000Z",
messages: [
{
id: "assistant-search",
role: "assistant",
content: "Bun 1.3.14 is current.",
metadata: {
modelToolActivities: [
{
toolCallId: "search-1",
toolName: "web_search",
execution: "provider",
input: { query: "latest Bun release" },
output: "Bun 1.3.14",
},
],
},
},
],
},
"session",
);
expect(html).toContain("web_search");
expect(html).toContain("latest Bun release");
expect(html).toContain('<span class="success">Success</span>');
expect(html).toContain("Bun 1.3.14 is current.");
});
});
+45 -2
View File
@@ -1,3 +1,4 @@
import { projectSessionMessagesForDisplay } from "@cline/core";
import {
type ContentBlock,
formatDisplayUserInput,
@@ -30,9 +31,12 @@ export function generateConversationHTML(
data: ConversationHistory,
fileName: string,
): string {
const displayMessages = projectSessionMessagesForDisplay(data.messages).map(
({ message }) => message,
);
// Build tool results map
const toolResultsMap = new Map<string, ToolResultContent>();
data.messages.forEach((msg) => {
displayMessages.forEach((msg) => {
if (!isStringContent(msg.content)) {
msg.content.forEach((block) => {
if (block.type === "tool_result") {
@@ -43,7 +47,7 @@ export function generateConversationHTML(
});
// Filter messages (same logic as viewer)
const filteredMessages = data.messages.filter((msg) => {
const filteredMessages = displayMessages.filter((msg) => {
if (msg.role === "assistant") return true;
if (isStringContent(msg.content)) {
return msg.content.trim().length > 0;
@@ -696,6 +700,14 @@ function renderContentHTML(
return renderToolUseHTML(block, toolResultsMap.get(block.id));
case "tool_result":
return ""; // Tool results are rendered with their corresponding tool_use
case "image":
return renderGeneratedMediaHTML({
modality: "image",
mediaType: block.mediaType,
source: { type: "base64", data: block.data },
});
case "media":
return renderGeneratedMediaHTML(block.media);
default:
return "";
}
@@ -703,6 +715,37 @@ function renderContentHTML(
.join("\n");
}
function renderGeneratedMediaHTML(media: {
modality: "image" | "audio" | "video" | "file";
mediaType: string;
source:
| { type: "base64"; data: string }
| { type: "url"; url: string }
| { type: "artifact"; artifactId: string };
}): string {
const source =
media.source.type === "base64"
? `data:${media.mediaType};base64,${media.source.data}`
: media.source.type === "url"
? media.source.url
: undefined;
if (!source) {
return `<p class="generated-media">Generated ${escapeHtml(media.modality)} (${escapeHtml(media.mediaType)})</p>`;
}
const escapedSource = escapeHtml(source);
const escapedType = escapeHtml(media.mediaType);
switch (media.modality) {
case "image":
return `<img class="generated-media" src="${escapedSource}" alt="Generated image" />`;
case "audio":
return `<audio class="generated-media" controls src="${escapedSource}" type="${escapedType}"></audio>`;
case "video":
return `<video class="generated-media" controls src="${escapedSource}" type="${escapedType}"></video>`;
case "file":
return `<a class="generated-media" href="${escapedSource}" download>Generated file (${escapedType})</a>`;
}
}
function renderTextHTML(text: string): string {
// Simple markdown-like rendering
let html = escapeHtml(text);
@@ -1,89 +0,0 @@
// ---------------------------------------------------------------------------
// Page-object helpers for the /settings view.
// ---------------------------------------------------------------------------
import type { Terminal } from "@microsoft/tui-test/lib/terminal/term";
import { expectVisible } from "../terminal.js";
const TAB_ORDER = [
"API",
"Auto-approve",
"Features",
"Account",
"Other",
] as const;
export type SettingsTab = (typeof TAB_ORDER)[number];
/**
* Navigate to a specific settings tab by pressing Right from the API tab (index 0).
* Waits for each tab's content to appear before pressing the next key, making
* navigation deterministic regardless of machine speed.
*/
export async function goToSettingsTab(
terminal: Terminal,
tab: SettingsTab,
): Promise<void> {
const targetIndex = TAB_ORDER.indexOf(tab);
for (let i = 0; i < targetIndex; i++) {
terminal.keyRight();
// Wait for the next tab's content to appear before pressing again
await assertTabContent(terminal, TAB_ORDER[i + 1]);
}
}
/** Assert the API tab content is visible */
export async function assertApiTab(terminal: Terminal): Promise<void> {
await expectVisible(terminal, ["Provider:", "Model ID:"]);
}
/** Assert the Auto-approve tab content is visible */
export async function assertAutoApproveTab(terminal: Terminal): Promise<void> {
await expectVisible(terminal, [
"Read project files",
"Execute safe commands",
"Edit project files",
]);
}
/** Assert the Features tab content is visible */
export async function assertFeaturesTab(terminal: Terminal): Promise<void> {
await expectVisible(terminal, [
"Subagents",
"Web tools",
"Double-check completion",
]);
}
/** Assert the Account tab content is visible */
export async function assertAccountTab(terminal: Terminal): Promise<void> {
// The account tab shows sign-in options when not authenticated to Cline
await expectVisible(terminal, /sign in|sign out/i);
}
/** Assert the Other tab content is visible */
export async function assertOtherTab(terminal: Terminal): Promise<void> {
await expectVisible(terminal, ["Preferred language:", "Cline v"]);
}
/**
* Assert the content for a given tab is visible.
* Used internally by goToSettingsTab to confirm navigation landed correctly.
*/
export async function assertTabContent(
terminal: Terminal,
tab: SettingsTab,
): Promise<void> {
switch (tab) {
case "API":
return assertApiTab(terminal);
case "Auto-approve":
return assertAutoApproveTab(terminal);
case "Features":
return assertFeaturesTab(terminal);
case "Account":
return assertAccountTab(terminal);
case "Other":
return assertOtherTab(terminal);
}
}
+2 -2
View File
@@ -2,10 +2,9 @@ import {
type ClineAccountBalance,
type ClineAccountOrganization,
type ClineAccountOrganizationBalance,
type ClineSubscriptionPlan,
type UserCurrentPlan,
ClineAccountService,
type ClineAccountUser,
type ClineSubscriptionPlan,
formatProviderOAuthApiKey,
getPersistedProviderApiKey,
getProviderOAuthCredentialsFromSettings,
@@ -13,6 +12,7 @@ import {
type ProviderSettings,
ProviderSettingsManager,
saveLocalProviderOAuthCredentials,
type UserCurrentPlan,
} from "@cline/core";
import { getClineEnvironmentConfig } from "@cline/shared";
import { formatCreditBalance, normalizeCreditBalance } from "../utils/output";
@@ -17,6 +17,7 @@ export type LocalSlashCommandName =
| "plugins"
| "account"
| "model"
| "theme"
| "compact"
| "skills"
| "fork"
@@ -62,6 +63,10 @@ const TUI_LOCAL_COMMANDS: Array<{
name: "model",
description: "Switch model or provider",
},
{
name: "theme",
description: "Change color theme",
},
{
name: "account",
description: "View Cline account",
@@ -112,6 +117,7 @@ const TUI_LOCAL_COMMANDS: Array<{
const SYSTEM_COMMAND_ORDER = [
"settings",
"model",
"theme",
"account",
"mcp",
"plugins",
@@ -3,8 +3,7 @@ import type {
AutocompleteMode,
AutocompleteOption,
} from "../hooks/use-autocomplete";
import { useTerminalBackground } from "../hooks/use-terminal-background";
import { getDefaultForeground, palette } from "../palette";
import { useTheme } from "../hooks/use-theme";
const MAX_ROWS = 7;
export const DROPDOWN_MAX_HEIGHT = MAX_ROWS + 2;
@@ -19,7 +18,9 @@ export interface AutocompleteDropdownProps {
}
export function AutocompleteDropdown(props: AutocompleteDropdownProps) {
const { mode, options, selected, onSelect, accent = palette.act } = props;
const theme = useTheme();
const { mode, options, selected, onSelect } = props;
const accent = props.accent ?? theme.accents.act;
const { width: termWidth } = useTerminalDimensions();
if (!mode || options.length === 0) return null;
@@ -122,8 +123,8 @@ function OptionRow(props: {
accent: string;
onSelect: (option: AutocompleteOption) => void;
}) {
const terminalBg = useTerminalBackground();
const defaultFg = getDefaultForeground(terminalBg);
const theme = useTheme();
const defaultFg = theme.defaultForeground;
const { opt, isSelected, rowBudget, mode, accent, onSelect } = props;
if (opt.isHeader) {
@@ -172,12 +173,12 @@ function OptionRow(props: {
onMouseDown={() => onSelect(opt)}
>
<text wrapMode="none">
<span fg={isSelected ? palette.textOnSelection : "gray"}>{prefix}</span>
<span fg={isSelected ? palette.textOnSelection : defaultFg}>
<span fg={isSelected ? theme.textOnSelection : "gray"}>{prefix}</span>
<span fg={isSelected ? theme.textOnSelection : defaultFg}>
{displayName}
</span>
{descText ? (
<span fg={isSelected ? palette.textOnSelection : "gray"}>
<span fg={isSelected ? theme.textOnSelection : "gray"}>
{" ".repeat(descGap)}
{descText}
</span>
+106 -53
View File
@@ -21,14 +21,8 @@ import {
CLINE_CREDITS_DASHBOARD_URL,
isClineAccountCreditsErrorMessage,
} from "../cline-account";
import { useTerminalBackground } from "../hooks/use-terminal-background";
import {
getDefaultForeground,
getModeAccent,
getUserMessageBackground,
palette,
type TerminalTheme,
} from "../palette";
import { getUserMessageBackground } from "../palette";
import type { ResolvedTheme } from "../themes";
import type { ChatEntry } from "../types";
import { formatCompactionDividerLabel } from "../utils/compaction-status";
import { getSyntaxStyle, type SyntaxAccentMode } from "../utils/syntax-style";
@@ -51,6 +45,13 @@ function trimLeading(text: string): string {
return text.replace(/^\n+/, "");
}
function formatMediaSize(byteLength: number): string {
if (byteLength <= 0) return "unknown size";
if (byteLength < 1024) return `${byteLength} B`;
if (byteLength < 1024 * 1024) return `${(byteLength / 1024).toFixed(1)} KiB`;
return `${(byteLength / (1024 * 1024)).toFixed(1)} MiB`;
}
function ReasoningBlock(props: { text: string; streaming: boolean }) {
const [expanded, setExpanded] = useState(false);
const { width } = useTerminalDimensions();
@@ -218,7 +219,7 @@ function ToolCallView(props: {
toolName: string;
inputSummary: string;
rawInput?: unknown;
accent?: string;
accent: string;
defaultFg?: string;
streaming: boolean;
result?: {
@@ -227,14 +228,8 @@ function ToolCallView(props: {
error?: string;
};
}) {
const {
toolName,
inputSummary,
streaming,
result,
accent = palette.act,
defaultFg,
} = props;
const { toolName, inputSummary, streaming, result, accent, defaultFg } =
props;
const failed = result?.error != null;
const warningFailure = isWarningToolError(result?.error);
const params = formatToolParams(toolName, props.rawInput, inputSummary);
@@ -279,7 +274,11 @@ function ToolCallView(props: {
);
}
function ClineCreditsClinePassErrorView(props: { defaultFg?: string }) {
function ClineCreditsClinePassErrorView(props: {
defaultFg?: string;
theme: ResolvedTheme;
}) {
const linkColor = props.theme.accents.act;
const subscriptionUrl = getCliSubscriptionUrl();
return (
<box flexDirection="row">
@@ -301,7 +300,7 @@ function ClineCreditsClinePassErrorView(props: { defaultFg?: string }) {
/>
<box flexDirection="row">
<text fg="gray">Purchase Credits: </text>
<text fg={palette.act} selectable>
<text fg={linkColor} selectable>
<a href={CLINE_CREDITS_DASHBOARD_URL}>
{CLINE_CREDITS_DASHBOARD_URL}
</a>
@@ -309,7 +308,7 @@ function ClineCreditsClinePassErrorView(props: { defaultFg?: string }) {
</box>
<box flexDirection="row">
<text fg="gray">Purchase ClinePass: </text>
<text fg={palette.act} selectable>
<text fg={linkColor} selectable>
<a href={subscriptionUrl}>{subscriptionUrl}</a>
</text>
</box>
@@ -324,18 +323,26 @@ function ClineCreditsClinePassErrorView(props: { defaultFg?: string }) {
);
}
function ClineCreditsErrorView(props: { defaultFg?: string }) {
return <ClineCreditsClinePassErrorView defaultFg={props.defaultFg} />;
function ClineCreditsErrorView(props: {
defaultFg?: string;
theme: ResolvedTheme;
}) {
return (
<ClineCreditsClinePassErrorView
defaultFg={props.defaultFg}
theme={props.theme}
/>
);
}
function ClinePassSubscriptionErrorView(props: {
defaultFg?: string;
loadIndividualSubscriptionPlans?: () => Promise<ClineSubscriptionPlan[]>;
terminalTheme: TerminalTheme;
theme: ResolvedTheme;
}) {
const subscriptionUrl = getCliSubscriptionUrl();
const [planFeatures, setPlanFeatures] = useState<string[]>([]);
const planAccent = getModeAccent("plan", props.terminalTheme);
const planAccent = props.theme.accents.plan;
useEffect(() => {
if (!props.loadIndividualSubscriptionPlans) {
@@ -387,13 +394,13 @@ function ClinePassSubscriptionErrorView(props: {
)}
<box flexDirection="row">
<text fg="gray">Subscribe: </text>
<text fg={palette.act} selectable>
<text fg={props.theme.accents.act} selectable>
<a href={subscriptionUrl}>Open subscription page</a>
</text>
</box>
<box flexDirection="row">
<text fg="gray">URL: </text>
<text fg={palette.act} selectable>
<text fg={props.theme.accents.act} selectable>
<a href={subscriptionUrl}>{subscriptionUrl}</a>
</text>
</box>
@@ -404,9 +411,9 @@ function ClinePassSubscriptionErrorView(props: {
function ClineOrgIndividualInferenceSubscriptionErrorView(props: {
defaultFg?: string;
terminalTheme: TerminalTheme;
theme: ResolvedTheme;
}) {
const planAccent = getModeAccent("plan", props.terminalTheme);
const planAccent = props.theme.accents.plan;
return (
<box flexDirection="row">
@@ -464,21 +471,22 @@ function CompactionDividerRow(props: {
function ClinePassLimitErrorView(props: {
message: string;
defaultFg?: string;
terminalTheme: TerminalTheme;
theme: ResolvedTheme;
}) {
const detail = getClinePassLimitDetailMessage(props.message) ?? props.message;
const accent = props.theme.accents.act;
return (
<box flexDirection="row">
<text fg={palette.act} content="* " />
<text fg={accent} content="* " />
<box
flexDirection="column"
border
borderStyle="rounded"
borderColor={palette.act}
borderColor={accent}
paddingX={1}
>
<text fg="red">ClinePass limit reached</text>
<text fg={props.theme.accents.error}>ClinePass limit reached</text>
<text fg={props.defaultFg} selectable content={detail} />
<text
fg={props.defaultFg}
@@ -491,7 +499,7 @@ function ClinePassLimitErrorView(props: {
<code
content="--provider cline"
filetype="bash"
syntaxStyle={getSyntaxStyle(props.terminalTheme)}
syntaxStyle={getSyntaxStyle(props.theme)}
selectable
/>
<text fg={props.defaultFg} selectable content="." />
@@ -504,20 +512,24 @@ function ClinePassLimitErrorView(props: {
function ClineFreeModelLimitErrorView(props: {
message: string;
defaultFg?: string;
theme: ResolvedTheme;
}) {
const resetTime = extractClineFreeModelLimitResetTime(props.message);
const accent = props.theme.accents.act;
return (
<box flexDirection="row">
<text fg={palette.act} content="* " />
<text fg={accent} content="* " />
<box
flexDirection="column"
border
borderStyle="rounded"
borderColor={palette.act}
borderColor={accent}
paddingX={1}
>
<text fg="red">Daily free model limit reached</text>
<text fg={props.theme.accents.error}>
Daily free model limit reached
</text>
<text
fg={props.defaultFg}
selectable
@@ -538,18 +550,22 @@ function ClineFreeModelLimitErrorView(props: {
);
}
function ClineFreePromotionEndedErrorView(props: { defaultFg?: string }) {
function ClineFreePromotionEndedErrorView(props: {
defaultFg?: string;
theme: ResolvedTheme;
}) {
const accent = props.theme.accents.act;
return (
<box flexDirection="row">
<text fg={palette.act} content="* " />
<text fg={accent} content="* " />
<box
flexDirection="column"
border
borderStyle="rounded"
borderColor={palette.act}
borderColor={accent}
paddingX={1}
>
<text fg="red">Free model promotion ended</text>
<text fg={props.theme.accents.error}>Free model promotion ended</text>
<text
fg={props.defaultFg}
selectable
@@ -572,12 +588,12 @@ export function ChatEntryView(props: {
/** Mode the entry was produced in (resolved with the current-mode fallback). */
mode?: SyntaxAccentMode;
loadIndividualSubscriptionPlans?: () => Promise<ClineSubscriptionPlan[]>;
terminalTheme: TerminalTheme;
theme: ResolvedTheme;
}) {
const { entry, accent = palette.act, mode = "act", terminalTheme } = props;
const terminalBg = useTerminalBackground();
const defaultFg = getDefaultForeground(terminalBg);
const userMsgBg = getUserMessageBackground(terminalBg);
const { entry, mode = "act", theme } = props;
const accent = props.accent ?? theme.accents.act;
const defaultFg = theme.defaultForeground;
const userMsgBg = getUserMessageBackground(theme.background);
switch (entry.kind) {
case "user":
@@ -631,10 +647,23 @@ export function ChatEntryView(props: {
)}
</box>
<box flexGrow={1}>
{/*
* internalBlockMode="top-level" keeps each markdown block as its
* own renderable. The default coalesced mode merges the whole
* message into one block that is torn down and re-highlighted on
* every streamed chunk, which flashes already-rendered headings
* and links back to raw uncolored markdown while tree-sitter
* re-highlights asynchronously. Top-level blocks are reused by
* token identity, so settled content never re-renders.
* tableOptions preserves the bordered table style that coalesced
* mode used by default (top-level defaults to borderless columns).
*/}
<markdown
content={content}
syntaxStyle={getSyntaxStyle(terminalTheme, mode)}
syntaxStyle={getSyntaxStyle(theme, mode)}
streaming={entry.streaming}
internalBlockMode="top-level"
tableOptions={{ style: "grid" }}
fg={defaultFg}
/>
</box>
@@ -642,6 +671,20 @@ export function ChatEntryView(props: {
);
}
case "assistant_media":
return (
<box flexDirection="row">
<box width={2}>
<text fg={accent}>*</text>
</box>
<text fg={defaultFg} selectable>
{entry.location
? `Generated ${entry.modality} (${entry.mediaType}, ${formatMediaSize(entry.byteLength)}): ${entry.location}`
: `Generated ${entry.modality} (${entry.mediaType}) could not be saved`}
</text>
</box>
);
case "reasoning":
return <ReasoningBlock text={entry.text} streaming={entry.streaming} />;
@@ -660,13 +703,13 @@ export function ChatEntryView(props: {
case "error":
if (isClineAccountCreditsErrorMessage(entry.text)) {
return <ClineCreditsErrorView defaultFg={defaultFg} />;
return <ClineCreditsErrorView defaultFg={defaultFg} theme={theme} />;
}
if (isClineOrgIndividualInferenceSubscriptionErrorMessage(entry.text)) {
return (
<ClineOrgIndividualInferenceSubscriptionErrorView
defaultFg={defaultFg}
terminalTheme={terminalTheme}
theme={theme}
/>
);
}
@@ -677,7 +720,7 @@ export function ChatEntryView(props: {
loadIndividualSubscriptionPlans={
props.loadIndividualSubscriptionPlans
}
terminalTheme={terminalTheme}
theme={theme}
/>
);
}
@@ -686,7 +729,7 @@ export function ChatEntryView(props: {
<ClinePassLimitErrorView
message={entry.text}
defaultFg={defaultFg}
terminalTheme={terminalTheme}
theme={theme}
/>
);
}
@@ -695,16 +738,26 @@ export function ChatEntryView(props: {
<ClineFreeModelLimitErrorView
defaultFg={defaultFg}
message={entry.text}
theme={theme}
/>
);
}
if (isClineFreePromotionEndedErrorMessage(entry.text)) {
return <ClineFreePromotionEndedErrorView defaultFg={defaultFg} />;
return (
<ClineFreePromotionEndedErrorView
defaultFg={defaultFg}
theme={theme}
/>
);
}
return (
<box flexDirection="row">
<text fg="red" content="* " />
<text fg="red" selectable content={`Error: ${entry.text}`} />
<text fg={theme.accents.error} content="* " />
<text
fg={theme.accents.error}
selectable
content={`Error: ${entry.text}`}
/>
</box>
);
@@ -9,8 +9,8 @@ import {
useRef,
} from "react";
import type { TranscriptCommand } from "../hooks/transcript-keybinds";
import { useTerminalTheme } from "../hooks/use-terminal-background";
import { getModeAccent } from "../palette";
import { useTheme } from "../hooks/use-theme";
import { getThemeModeAccent } from "../themes";
import type { ChatEntry } from "../types";
import { ChatEntryView } from "./chat-entry";
@@ -31,8 +31,8 @@ export const ChatMessageList = forwardRef<
>(function ChatMessageList(props, ref) {
const scrollboxRef = useRef<ScrollBoxRenderable | null>(null);
const lastEntry = props.entries.at(-1);
const terminalTheme = useTerminalTheme();
const accent = getModeAccent(props.uiMode ?? "act", terminalTheme);
const theme = useTheme();
const accent = getThemeModeAccent(theme, props.uiMode ?? "act");
const userSubmissionScrollKey =
lastEntry?.kind === "user_submitted" ? props.entries.length : 0;
@@ -103,12 +103,12 @@ export const ChatMessageList = forwardRef<
<ChatEntryView
key={key}
entry={entry}
accent={getModeAccent(entryMode, terminalTheme)}
accent={getThemeModeAccent(theme, entryMode)}
mode={entryMode === "plan" ? "plan" : "act"}
loadIndividualSubscriptionPlans={
props.loadIndividualSubscriptionPlans
}
terminalTheme={terminalTheme}
theme={theme}
/>
);
})}
@@ -2,6 +2,7 @@ export type CommandPaletteAction =
| "settings"
| "change-model"
| "change-provider"
| "theme"
| "account"
| "mcp"
| "plugins"
@@ -57,6 +58,13 @@ const ACTION_ITEMS: Array<{
description: "Switch provider and configure credentials",
keywords: ["provider", "api key", "account", "auth"],
},
{
action: "theme",
label: "Change Theme",
shortcut: "Opt+T",
description: "Pick a color theme for the TUI",
keywords: ["theme", "colors", "dark", "light", "appearance"],
},
{
action: "mcp",
label: "Manage MCP Servers",
@@ -127,6 +127,12 @@ const HELP_ROWS: HelpRow[] = [
key: "/settings",
desc: "Open interactive config browser",
},
{
kind: "entry",
id: "c-theme",
key: "/theme",
desc: "Change color theme",
},
{
kind: "entry",
id: "c-mcp",
@@ -0,0 +1,27 @@
import type { Config } from "../../../utils/types";
import type { DialogDismissKey } from "../../utils/dialog-keys";
/**
* Enter starts the update-and-restart flow; Esc dismisses (the mismatch toast
* reminds the user to update manually). Other keys are ignored so the dialog
* is not lost to a stray keystroke mid-task.
*/
export function resolveHubUpdateRequiredKeyAction(
key: DialogDismissKey,
): "update" | "dismiss" | "ignore" {
if (key.name === "return" || key.name === "enter") return "update";
if (key.name === "escape") return "dismiss";
return "ignore";
}
/**
* Yolo and sandbox sessions force the local backend and never attach to the
* shared managed Hub (see the forceLocalBackend condition in the interactive
* session runtime), so a build mismatch on that Hub is another installation's
* concern and must not interrupt these sessions with an update dialog.
*/
export function shouldWatchManagedHubBuild(
config: Pick<Config, "mode" | "sandbox">,
): boolean {
return config.mode !== "yolo" && config.sandbox !== true;
}
@@ -0,0 +1,48 @@
import { describe, expect, it } from "vitest";
import {
resolveHubUpdateRequiredKeyAction,
shouldWatchManagedHubBuild,
} from "./hub-update-required-helpers";
describe("hub update required dialog", () => {
it("updates on Enter", () => {
expect(resolveHubUpdateRequiredKeyAction({ name: "return" })).toBe(
"update",
);
expect(resolveHubUpdateRequiredKeyAction({ name: "enter" })).toBe("update");
});
it("dismisses only on Esc", () => {
expect(resolveHubUpdateRequiredKeyAction({ name: "escape" })).toBe(
"dismiss",
);
});
it("ignores stray keystrokes so a mid-task keypress cannot lose the prompt", () => {
expect(resolveHubUpdateRequiredKeyAction({ name: "a" })).toBe("ignore");
expect(resolveHubUpdateRequiredKeyAction({ name: "space" })).toBe("ignore");
expect(resolveHubUpdateRequiredKeyAction({ name: "c", ctrl: true })).toBe(
"ignore",
);
});
});
describe("shouldWatchManagedHubBuild", () => {
it("watches for hub-attached modes", () => {
expect(shouldWatchManagedHubBuild({ mode: "act", sandbox: false })).toBe(
true,
);
expect(shouldWatchManagedHubBuild({ mode: "plan", sandbox: false })).toBe(
true,
);
});
it("skips yolo and sandbox sessions, which force the local backend and never attach to the managed Hub", () => {
expect(shouldWatchManagedHubBuild({ mode: "yolo", sandbox: false })).toBe(
false,
);
expect(shouldWatchManagedHubBuild({ mode: "act", sandbox: true })).toBe(
false,
);
});
});
@@ -0,0 +1,50 @@
// @jsxImportSource @opentui/react
import type { ChoiceContext } from "@opentui-ui/dialog";
import { useDialogKeyboard } from "@opentui-ui/dialog/react";
import { palette } from "../../palette";
import { resolveHubUpdateRequiredKeyAction } from "./hub-update-required-helpers";
export interface HubUpdateRequiredDetails {
hubCoreVersion?: string;
}
export function HubUpdateRequiredContent(
props: ChoiceContext<boolean> & HubUpdateRequiredDetails,
) {
const { dialogId, dismiss, hubCoreVersion, resolve } = props;
useDialogKeyboard((key) => {
const action = resolveHubUpdateRequiredKeyAction(key);
if (action === "ignore") return;
if (action === "update") {
resolve(true);
return;
}
dismiss();
}, dialogId);
return (
<box flexDirection="column" paddingX={1} gap={1}>
<text fg="yellow">Cline Hub was updated</text>
<box flexDirection="column">
<text selectable>
Another Cline installation restarted the shared Cline Hub
{hubCoreVersion ? ` (core ${hubCoreVersion})` : ""}, and it no longer
matches this CLI.
</text>
<text selectable>
Update and restart Cline so this CLI and the Hub run the same version
again.
</text>
</box>
<box flexDirection="row">
<box paddingX={1} backgroundColor={palette.act}>
<text fg={palette.textOnSelection}>Update and restart</text>
</box>
</box>
<text fg={palette.muted}>
Press Enter to update and restart, Esc to dismiss
</text>
</box>
);
}
@@ -0,0 +1,140 @@
import { useTerminalDimensions } from "@opentui/react";
import type { ChoiceContext } from "@opentui-ui/dialog";
import { useDialogKeyboard } from "@opentui-ui/dialog/react";
import { useEffect, useRef, useState } from "react";
import { useThemeController } from "../../hooks/use-theme";
import { palette } from "../../palette";
import { getThemeSwatchColors, THEMES } from "../../themes";
const SWATCH_BLOCK = "\u25a0";
export function ThemePickerContent(props: ChoiceContext<string>) {
const { resolve, dismiss, dialogId } = props;
const { height } = useTerminalDimensions();
const controller = useThemeController();
const [selected, setSelected] = useState(() => {
const index = THEMES.findIndex(
(theme) => theme.id === controller.selectedThemeId,
);
return index >= 0 ? index : 0;
});
const selectedRef = useRef(selected);
selectedRef.current = selected;
const controllerRef = useRef(controller);
controllerRef.current = controller;
// Live preview: moving the selection repaints the whole TUI with the
// highlighted theme so users see exactly what they would get.
useEffect(() => {
const theme = THEMES[selected];
if (theme) {
controllerRef.current.previewThemeId(theme.id);
}
}, [selected]);
// Clear any dangling preview when the dialog closes without a confirm
// (escape, backdrop click, dialog replaced). setThemeId already clears the
// preview on confirm, so this is a no-op in that path.
useEffect(() => {
return () => {
controllerRef.current.previewThemeId(null);
};
}, []);
useDialogKeyboard((key) => {
if (key.name === "escape") {
dismiss();
return;
}
if (key.name === "return" || key.name === "enter" || key.name === "tab") {
const theme = THEMES[selectedRef.current];
if (theme) {
controllerRef.current.setThemeId(theme.id);
resolve(theme.id);
}
return;
}
if (key.name === "up") {
setSelected((index) => (index <= 0 ? THEMES.length - 1 : index - 1));
return;
}
if (key.name === "down") {
setSelected((index) => (index >= THEMES.length - 1 ? 0 : index + 1));
}
}, dialogId);
const maxVisible = Math.max(3, height - 10);
const start = Math.max(
0,
Math.min(
selected - Math.floor(maxVisible / 2),
Math.max(0, THEMES.length - maxVisible),
),
);
const visibleThemes = THEMES.slice(start, start + maxVisible);
// Selection prefix (2 cells) + longest label + separating gap.
const labelWidth = Math.max(...THEMES.map((theme) => theme.label.length)) + 4;
return (
<box flexDirection="column" gap={1}>
<box flexDirection="row" justifyContent="space-between">
<text fg="white">
<strong>Theme</strong>
</text>
<text fg="gray">esc</text>
</box>
<box flexDirection="column">
{visibleThemes.map((theme, i) => {
const absoluteIndex = start + i;
const isSelected = absoluteIndex === selected;
const isCurrent = theme.id === controller.selectedThemeId;
const swatches = getThemeSwatchColors(theme);
return (
<box
key={theme.id}
flexDirection="row"
backgroundColor={isSelected ? palette.selection : undefined}
onMouseDown={() => {
setSelected(absoluteIndex);
controllerRef.current.setThemeId(theme.id);
resolve(theme.id);
}}
height={1}
>
<text
fg={isSelected ? palette.textOnSelection : "white"}
width={labelWidth}
flexShrink={0}
>
{isSelected ? "\u276f " : " "}
{theme.label}
</text>
<text flexShrink={0}>
{swatches.map((color, swatchIndex) => (
<span
// biome-ignore lint/suspicious/noArrayIndexKey: fixed-size color strip
key={swatchIndex}
fg={color}
>
{SWATCH_BLOCK}
</span>
))}
</text>
<text fg={isSelected ? palette.textOnSelection : "gray"}>
{" "}
{theme.description}
{isCurrent ? " (current)" : ""}
</text>
</box>
);
})}
</box>
<text fg="gray">
<em>{"\u2191/\u2193 preview, Enter to apply, Esc to cancel"}</em>
</text>
</box>
);
}
@@ -1,7 +1,7 @@
import type { ScrollBoxRenderable } from "@opentui/core";
import { useKeyboard, useTerminalDimensions } from "@opentui/react";
import { useCallback, useEffect, useRef, useState } from "react";
import { palette } from "../palette";
import { useTheme } from "../hooks/use-theme";
import type { RuntimeToolInteraction } from "../types";
import { formatApprovalParams } from "./dialogs/tool-approval";
@@ -152,7 +152,7 @@ function Shell(
gap={1}
>
<box flexDirection="row" gap={1}>
<text fg={palette.act}>{props.title}</text>
<text fg={props.accent}>{props.title}</text>
</box>
{props.children}
</box>
@@ -165,17 +165,18 @@ function ChoiceButton(props: {
selectedFg?: string;
onPress: () => void;
}) {
const theme = useTheme();
return (
// biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI boxes handle terminal mouse input.
<box
paddingX={1}
backgroundColor={props.selected ? palette.selection : undefined}
backgroundColor={props.selected ? theme.selection : undefined}
onMouseDown={props.onPress}
>
<text
fg={
props.selected
? (props.selectedFg ?? palette.textOnSelection)
? (props.selectedFg ?? theme.textOnSelection)
: undefined
}
>
@@ -190,6 +191,7 @@ function ToolApprovalResponse(
interaction: Extract<RuntimeToolInteraction, { kind: "tool_approval" }>;
},
) {
const theme = useTheme();
const [selected, setSelected] = useState<"approve" | "deny">("approve");
const selectedRef = useRef(selected);
selectedRef.current = selected;
@@ -231,7 +233,7 @@ function ToolApprovalResponse(
inputForeground={props.inputForeground}
>
<box flexDirection="column" gap={1}>
<text fg="yellow">Approve tool call?</text>
<text fg={theme.accents.plan}>Approve tool call?</text>
<text fg={props.accent} selectable>
{request.toolName}
</text>
@@ -263,6 +265,7 @@ function AskQuestionResponse(
},
) {
const { interaction } = props;
const theme = useTheme();
const { height, width } = useTerminalDimensions();
const [selected, setSelected] = useState(0);
const [customValue, setCustomValue] = useState("");
@@ -439,13 +442,11 @@ function AskQuestionResponse(
gap={1}
flexShrink={0}
width="100%"
backgroundColor={
optionSelected ? palette.selection : undefined
}
backgroundColor={optionSelected ? theme.selection : undefined}
onMouseDown={() => resolveAnswer(option)}
>
<text
fg={optionSelected ? palette.textOnSelection : "gray"}
fg={optionSelected ? theme.textOnSelection : "gray"}
flexShrink={0}
>
{optionSelected ? ">" : " "}
@@ -453,7 +454,7 @@ function AskQuestionResponse(
<text
fg={
optionSelected
? palette.textOnSelection
? theme.textOnSelection
: props.inputForeground
}
flexGrow={1}
@@ -472,17 +473,17 @@ function AskQuestionResponse(
gap={1}
flexShrink={0}
width="100%"
backgroundColor={isTyping ? palette.selection : undefined}
backgroundColor={isTyping ? theme.selection : undefined}
onMouseDown={() => selectIndex(customIndex)}
>
<text
fg={isTyping ? palette.textOnSelection : "gray"}
fg={isTyping ? theme.textOnSelection : "gray"}
flexShrink={0}
>
{isTyping ? ">" : " "}
</text>
{isTyping ? (
<text fg={palette.textOnSelection} flexGrow={1} flexShrink={1}>
<text fg={theme.textOnSelection} flexGrow={1} flexShrink={1}>
{customText}
</text>
) : (
+17 -12
View File
@@ -1,7 +1,7 @@
import "opentui-spinner/react";
import { useEffect, useState } from "react";
import { useSession } from "../contexts/session-context";
import { palette } from "../palette";
import { useTheme } from "../hooks/use-theme";
import type { QueuedPromptItem } from "../types";
function truncatePrompt(prompt: string): string {
@@ -20,6 +20,7 @@ export function QueuedPrompts(props: {
onEditConfirm: (id: string, prompt: string) => void;
}) {
const session = useSession();
const theme = useTheme();
if (props.items.length === 0) return null;
const selected = props.selectedId
@@ -42,7 +43,7 @@ export function QueuedPrompts(props: {
flexDirection="column"
border
borderStyle="rounded"
borderColor={selected ? palette.selection : "gray"}
borderColor={selected ? theme.selection : "gray"}
paddingX={1}
>
<text fg="gray">
@@ -75,6 +76,7 @@ function QueuedPromptRow(props: {
onEditConfirm: (prompt: string) => void;
}) {
const { item, selected, editing } = props;
const theme = useTheme();
const [editValue, setEditValue] = useState(item.prompt);
useEffect(() => {
@@ -88,15 +90,15 @@ function QueuedPromptRow(props: {
paddingX={1}
flexDirection="row"
gap={1}
backgroundColor={selected ? palette.selection : undefined}
backgroundColor={selected ? theme.selection : undefined}
>
{item.steer && !editing ? (
<spinner
name="dots"
color={selected ? palette.textOnSelection : "gray"}
color={selected ? theme.textOnSelection : "gray"}
/>
) : (
<text fg={selected ? palette.textOnSelection : "gray"} flexShrink={0}>
<text fg={selected ? theme.textOnSelection : "gray"} flexShrink={0}>
{selected ? "" : " "}
</text>
)}
@@ -106,21 +108,24 @@ function QueuedPromptRow(props: {
onInput={setEditValue}
onSubmit={() => props.onEditConfirm(editValue)}
placeholder="Edit message..."
backgroundColor={palette.selection}
focusedBackgroundColor={palette.selection}
textColor={palette.textOnSelection}
cursorColor={palette.textOnSelection}
placeholderColor={palette.textOnSelection}
backgroundColor={theme.selection}
focusedBackgroundColor={theme.selection}
textColor={theme.textOnSelection}
cursorColor={theme.textOnSelection}
placeholderColor={theme.textOnSelection}
focused
flexGrow={1}
/>
) : (
<text fg={selected ? palette.textOnSelection : undefined} flexGrow={1}>
<text
fg={selected ? theme.textOnSelection : theme.defaultForeground}
flexGrow={1}
>
{truncatePrompt(item.prompt)}
</text>
)}
{!editing && item.attachmentCount > 0 && (
<text fg={selected ? palette.textOnSelection : "gray"} flexShrink={0}>
<text fg={selected ? theme.textOnSelection : "gray"} flexShrink={0}>
{attachmentLabel(item.attachmentCount)}
</text>
)}
+10 -13
View File
@@ -1,6 +1,5 @@
import { useMemo, useState } from "react";
import { useTerminalBackground } from "../hooks/use-terminal-background";
import { getDefaultForeground, palette } from "../palette";
import { useTheme } from "../hooks/use-theme";
export interface SearchableItem {
key: string;
@@ -229,8 +228,8 @@ export function SearchableList(props: {
emptyText?: string;
borderColor?: string;
}) {
const terminalBg = useTerminalBackground();
const defaultFg = getDefaultForeground(terminalBg);
const theme = useTheme();
const defaultFg = theme.defaultForeground;
const {
items,
selected,
@@ -288,23 +287,23 @@ export function SearchableList(props: {
paddingX={1}
flexDirection="row"
gap={1}
backgroundColor={isSel ? palette.selection : undefined}
backgroundColor={isSel ? theme.selection : undefined}
onMouseDown={() => onItemSelect?.(item)}
overflow="hidden"
height={1}
>
<text
fg={isSel ? palette.textOnSelection : "gray"}
fg={isSel ? theme.textOnSelection : "gray"}
flexShrink={0}
>
{isSel ? "\u276f" : " "}
</text>
<text fg={isSel ? palette.textOnSelection : defaultFg}>
<text fg={isSel ? theme.textOnSelection : defaultFg}>
{item.label}
</text>
{item.detail && (
<text
fg={isSel ? palette.textOnSelection : "gray"}
fg={isSel ? theme.textOnSelection : "gray"}
flexShrink={1}
>
{item.detail}
@@ -313,9 +312,7 @@ export function SearchableList(props: {
{item.tag && (
<text
fg={
isSel
? palette.textOnSelection
: (item.tagColor ?? "gray")
isSel ? theme.textOnSelection : (item.tagColor ?? "gray")
}
flexShrink={0}
>
@@ -326,8 +323,8 @@ export function SearchableList(props: {
<text
fg={
isSel
? palette.textOnSelection
: (item.rightLabelColor ?? palette.success)
? theme.textOnSelection
: (item.rightLabelColor ?? theme.accents.success)
}
flexShrink={0}
>
+6 -15
View File
@@ -4,15 +4,7 @@ import {
shouldShowCliUsageCost,
shouldShowCliUsageCoveredBySubscription,
} from "../../utils/usage-cost-display";
import {
useTerminalBackground,
useTerminalTheme,
} from "../hooks/use-terminal-background";
import {
getDefaultForeground,
getModeAccent,
getSuccessColor,
} from "../palette";
import { useTheme } from "../hooks/use-theme";
import { HOME_VIEW_MAX_WIDTH } from "../types";
export function createContextBar(
@@ -163,13 +155,12 @@ export function StatusBar(props: StatusBarProps) {
} = props;
const { width } = useTerminalDimensions();
const terminalBg = useTerminalBackground();
const terminalTheme = useTerminalTheme();
const defaultFg = getDefaultForeground(terminalBg);
const theme = useTheme();
const defaultFg = theme.defaultForeground;
const contextBarFilledFg = resolveContextBarFilledForeground(defaultFg);
const actAccent = getModeAccent("act", terminalTheme);
const planAccent = getModeAccent("plan", terminalTheme);
const successColor = getSuccessColor(terminalTheme);
const actAccent = theme.accents.act;
const planAccent = theme.accents.plan;
const successColor = theme.accents.success;
const hasMaxInputTokens =
typeof maxInputTokens === "number" &&
Number.isFinite(maxInputTokens) &&
+7 -7
View File
@@ -1,5 +1,5 @@
import { useTerminalDimensions } from "@opentui/react";
import { palette } from "../palette";
import { useTheme } from "../hooks/use-theme";
export type ToastVariant = "info" | "success" | "error";
@@ -8,19 +8,19 @@ export type ToastState = {
variant: ToastVariant;
};
const variantColor: Record<ToastVariant, string> = {
info: palette.selection,
success: palette.success,
error: palette.error,
};
export function Toast(props: { toast: ToastState | null }) {
const { width } = useTerminalDimensions();
const theme = useTheme();
if (!props.toast) {
return null;
}
const variantColor: Record<ToastVariant, string> = {
info: theme.accents.act,
success: theme.accents.success,
error: theme.accents.error,
};
const availableWidth = Math.max(1, width - 4);
const maxWidth = Math.min(44, availableWidth);
const right = width < 32 ? 0 : 2;
+22 -12
View File
@@ -1,6 +1,6 @@
import { useState } from "react";
import { useTerminalTheme } from "../hooks/use-terminal-background";
import { diffPalettes, palette, type TerminalTheme } from "../palette";
import { useTheme } from "../hooks/use-theme";
import type { ResolvedTheme } from "../themes";
import { makeUnifiedDiff } from "../utils/diff";
import { getSyntaxStyle } from "../utils/syntax-style";
import { getToolErrorPresentation } from "../utils/tool-errors";
@@ -45,7 +45,7 @@ function isEditTool(toolName: string): boolean {
);
}
function BashOutput(props: { fullText: string; theme: TerminalTheme }) {
function BashOutput(props: { fullText: string; theme: ResolvedTheme }) {
const [expanded, setExpanded] = useState(false);
const { fullText } = props;
const trimmed = fullText.trimEnd();
@@ -55,6 +55,7 @@ function BashOutput(props: { fullText: string; theme: TerminalTheme }) {
if (!expanded) {
return (
// biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI box is a terminal renderable, not a DOM element; mouse expands optional output.
<box
flexDirection="column"
paddingLeft={2}
@@ -75,6 +76,7 @@ function BashOutput(props: { fullText: string; theme: TerminalTheme }) {
}
return (
// biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI box is a terminal renderable, not a DOM element; mouse collapses output.
<box
flexDirection="column"
paddingLeft={2}
@@ -115,18 +117,19 @@ function DiffStats(props: {
added: number;
removed: number;
language?: string;
theme: ResolvedTheme;
}) {
const { added, removed, language } = props;
const { added, removed, language, theme } = props;
return (
<text fg="gray">
{RESULT}{" "}
{removed > 0 ? (
<>
<span fg={palette.success}>+{added}</span>{" "}
<span fg="red">-{removed}</span> lines
<span fg={theme.accents.success}>+{added}</span>{" "}
<span fg={theme.accents.error}>-{removed}</span> lines
</>
) : (
<span fg={palette.success}>+{added} lines (new)</span>
<span fg={theme.accents.success}>+{added} lines (new)</span>
)}
{language ? ` | ${language}` : ""}
</text>
@@ -136,7 +139,7 @@ function DiffStats(props: {
function EditOutput(props: {
rawInput?: unknown;
outputSummary: string;
theme: TerminalTheme;
theme: ResolvedTheme;
}) {
const [expanded, setExpanded] = useState(true);
const editorInfo = parseEditorInput(props.rawInput);
@@ -156,9 +159,10 @@ function EditOutput(props: {
const language = detectLanguage(editorInfo.path);
const addedLines = newText.split("\n").length;
const removedLines = oldText ? oldText.split("\n").length : 0;
const diffPalette = diffPalettes[props.theme];
const diffPalette = props.theme.diff;
return (
// biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI box is a terminal renderable, not a DOM element; mouse toggles the diff.
<box
flexDirection="column"
paddingLeft={2}
@@ -168,6 +172,7 @@ function EditOutput(props: {
added={addedLines}
removed={removedLines}
language={language}
theme={props.theme}
/>
{expanded && (
<box marginLeft={2} marginTop={1} marginBottom={1}>
@@ -194,7 +199,7 @@ function EditOutput(props: {
function ApplyPatchOutput(props: {
rawInput?: unknown;
outputSummary: string;
theme: TerminalTheme;
theme: ResolvedTheme;
}) {
const [expanded, setExpanded] = useState(true);
const info = parseApplyPatchInput(props.rawInput);
@@ -211,9 +216,10 @@ function ApplyPatchOutput(props: {
const fileLabel = info.files.map((f) => shortenPath(f, 40)).join(", ");
const language = detectLanguage(info.files[0] ?? "");
const diffPalette = diffPalettes[props.theme];
const diffPalette = props.theme.diff;
return (
// biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI box is a terminal renderable, not a DOM element; mouse toggles the diff.
<box
flexDirection="column"
paddingLeft={2}
@@ -223,6 +229,7 @@ function ApplyPatchOutput(props: {
added={info.additions}
removed={info.deletions}
language={fileLabel}
theme={props.theme}
/>
{expanded && (
<box marginLeft={2} marginTop={1} marginBottom={1}>
@@ -260,6 +267,7 @@ function GenericOutput(props: { outputSummary: string; fullText?: string }) {
: displayText;
return (
// biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI box is a terminal renderable, not a DOM element; mouse expands long output.
<box
flexDirection="column"
paddingLeft={2}
@@ -275,6 +283,7 @@ function GenericOutput(props: { outputSummary: string; fullText?: string }) {
}
return (
// biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI box is a terminal renderable, not a DOM element; mouse collapses output.
<box
flexDirection="column"
paddingLeft={2}
@@ -292,7 +301,7 @@ function GenericOutput(props: { outputSummary: string; fullText?: string }) {
export function ToolOutput(props: ToolOutputProps) {
const { toolName, outputSummary, rawOutput, rawInput, error } = props;
const terminalTheme = useTerminalTheme();
const terminalTheme = useTheme();
const [errorExpanded, setErrorExpanded] = useState(false);
if (error) {
@@ -301,6 +310,7 @@ export function ToolOutput(props: ToolOutputProps) {
const showDetail =
errorExpanded && presentation.detail !== presentation.summary.trim();
return (
// biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI box is a terminal renderable, not a DOM element; mouse toggles error details.
<box
flexDirection="column"
paddingLeft={2}
@@ -1,6 +1,5 @@
import { useCallback, useRef, useState } from "react";
import { useTerminalBackground } from "../hooks/use-terminal-background";
import { getDefaultForeground } from "../palette";
import { useTheme } from "../hooks/use-theme";
import { RobotAnimation } from "./robot-animation";
export function useMouseTracker() {
@@ -18,8 +17,7 @@ export function useMouseTracker() {
}
export function TrackedRobot(props: { cursorX?: number; cursorY?: number }) {
const terminalBg = useTerminalBackground();
const defaultFg = getDefaultForeground(terminalBg);
const defaultFg = useTheme().defaultForeground;
return (
<box width="100%" flexShrink={1} overflow="hidden">
<RobotAnimation
@@ -9,6 +9,7 @@ export interface LocalSlashCommandActionInput {
openMcpManager: () => Promise<boolean>;
openModelSelector: () => void;
openSkills: (invocation?: LocalSlashCommandInvocation) => void;
openThemePicker: () => void;
invocation?: LocalSlashCommandInvocation;
runCompact: () => void;
runFork: () => void;
@@ -46,6 +47,10 @@ export function runLocalSlashCommandAction(
input.openModelSelector();
return true;
}
if (normalized === "theme") {
input.openThemePicker();
return true;
}
if (normalized === "compact") {
// Autocomplete can invoke local commands while a turn is running. Keep
// /compact handled, but do not let it take ownership of the active turn's
+75
View File
@@ -0,0 +1,75 @@
import { readTuiThemeGlobally, setTuiThemeGlobally } from "@cline/core";
import { useRenderer } from "@opentui/react";
import {
type ReactNode,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from "react";
import { AUTO_THEME_ID, normalizeThemeId, resolveTheme } from "../themes";
import { TerminalColorsContext, ThemeContext } from "./use-theme";
/**
* Resolves the theme to boot with: CLINE_THEME env override first, then the
* persisted setting, falling back to terminal auto-detection.
*/
export function getInitialThemeId(): string {
const fromEnv = process.env.CLINE_THEME?.trim();
if (fromEnv) {
return normalizeThemeId(fromEnv);
}
try {
return normalizeThemeId(readTuiThemeGlobally());
} catch {
return AUTO_THEME_ID;
}
}
export function ThemeProvider(props: {
initialThemeId?: string;
children: ReactNode;
}) {
const detected = useContext(TerminalColorsContext);
const renderer = useRenderer();
const [selectedThemeId, setSelectedThemeId] = useState(() =>
normalizeThemeId(props.initialThemeId ?? getInitialThemeId()),
);
const [previewId, setPreviewId] = useState<string | null>(null);
const activeThemeId = previewId ?? selectedThemeId;
const theme = useMemo(
() => resolveTheme(activeThemeId, detected),
[activeThemeId, detected],
);
useEffect(() => {
if (renderer.isDestroyed) {
return;
}
renderer.setBackgroundColor(theme.appBackground ?? "transparent");
}, [renderer, theme.appBackground]);
const setThemeId = useCallback((id: string) => {
const normalized = normalizeThemeId(id);
setSelectedThemeId(normalized);
setPreviewId(null);
try {
setTuiThemeGlobally(normalized);
} catch {
// Persisting is best-effort; the in-session theme still applies.
}
}, []);
const previewThemeId = useCallback((id: string | null) => {
setPreviewId(id === null ? null : normalizeThemeId(id));
}, []);
const value = useMemo(
() => ({ theme, selectedThemeId, setThemeId, previewThemeId }),
[theme, selectedThemeId, setThemeId, previewThemeId],
);
return <ThemeContext value={value}>{props.children}</ThemeContext>;
}
+39 -6
View File
@@ -7,6 +7,7 @@ import type {
} from "../../runtime/session-events";
import { formatCliErrorMessage } from "../../utils/cline-pass-errors";
import { resolveNonCompactionStatusLabel } from "../../utils/events";
import { materializeGeneratedMedia } from "../../utils/generated-media";
import {
formatToolInput,
formatToolOutput,
@@ -205,6 +206,26 @@ export function useAgentEventHandlers(deps: AgentEventDeps) {
closeToolEntry(event);
break;
}
case "media": {
closeInlineStream();
const media = event.media;
if (!media) break;
const saved = materializeGeneratedMedia(media);
appendEntry({
kind: "assistant_media",
modality: media.modality,
mediaType: media.mediaType,
byteLength: saved?.byteLength ?? media.sizeBytes ?? 0,
location:
saved?.path ??
(media.source.type === "url"
? media.source.url
: media.source.type === "artifact"
? `artifact:${media.source.artifactId}`
: undefined),
});
break;
}
}
break;
}
@@ -216,6 +237,20 @@ export function useAgentEventHandlers(deps: AgentEventDeps) {
finalizeDanglingCompactionEntry("cancelled");
break;
case "error":
// Recoverable errors are in-run notices (the MistakeTracker
// emits one for every recorded mistake, e.g. a plan-mode
// guard-blocked command) — the run continues, so the footer
// must keep reflecting the active turn instead of flipping
// to idle mid-run. Surface them only in verbose mode.
if (event.recoverable) {
if (verbose) {
appendEntry({
kind: "error",
text: formatCliErrorMessage(event.error, { modelId }),
});
}
break;
}
setIsRunning(false);
setIsStreaming(false);
closeInlineStream();
@@ -223,12 +258,10 @@ export function useAgentEventHandlers(deps: AgentEventDeps) {
finalizeDanglingCompactionEntry("failed");
turnErrorReportedRef.current = true;
onTurnErrorReported(true);
if (!event.recoverable || verbose) {
appendEntry({
kind: "error",
text: formatCliErrorMessage(event.error, { modelId }),
});
}
appendEntry({
kind: "error",
text: formatCliErrorMessage(event.error, { modelId }),
});
break;
case "notice":
if (event.displayRole === "status") {
@@ -45,6 +45,7 @@ export function useConfigPanel(opts: {
) => Promise<InteractiveConfigData | undefined>;
openModelSelector: (options?: OpenModelSelectorOptions) => Promise<void>;
openMcpManager: (options?: { refocus?: boolean }) => Promise<boolean>;
openThemePicker: (options?: { refocus?: boolean }) => Promise<void>;
refocusTextarea: () => void;
}) {
const emptyConfigData = useMemo(
@@ -118,6 +119,8 @@ export function useConfigPanel(opts: {
});
} else if (action.kind === "open-model") {
await opts.openModelSelector({ onCancel: () => {} });
} else if (action.kind === "open-theme") {
await opts.openThemePicker({ refocus: false });
} else if (action.kind === "toggle-item") {
await opts.onToggleConfigItem?.(action.item);
} else if (action.kind === "delete-item") {
@@ -15,6 +15,7 @@ function makeActions(
openMcpManager: vi.fn(async () => false),
openModelSelector: vi.fn(),
openSkills: vi.fn(),
openThemePicker: vi.fn(),
runCompact: vi.fn(),
runFork: vi.fn(),
runUndo: vi.fn(async () => {}),
@@ -23,6 +23,7 @@ export function useLocalCommandActions(input: {
openMcpManager: () => Promise<boolean>;
openModelSelector: () => void;
openSkills: (invocation?: LocalSlashCommandInvocation) => void;
openThemePicker: () => void;
refocusTextarea: () => void;
setAppView: (view: AppView) => void;
onClearConversation: () => Promise<void>;
@@ -45,6 +46,7 @@ export function useLocalCommandActions(input: {
openMcpManager,
openModelSelector,
openSkills,
openThemePicker,
refocusTextarea,
setAppView,
onClearConversation,
@@ -227,6 +229,7 @@ export function useLocalCommandActions(input: {
openMcpManager,
openModelSelector,
openSkills,
openThemePicker,
runCompact,
runFork,
runUndo: onUndo,
@@ -247,6 +250,7 @@ export function useLocalCommandActions(input: {
openHistory,
openModelSelector,
openSkills,
openThemePicker,
runCompact,
runFork,
session.isRunning,
@@ -1,25 +0,0 @@
import { createContext, useContext } from "react";
import { getTerminalTheme, type TerminalTheme } from "../palette";
export interface TerminalColors {
background: string | null;
foreground: string | null;
}
export const TerminalColorsContext = createContext<TerminalColors>({
background: null,
foreground: null,
});
export function useTerminalBackground(): string | null {
return useContext(TerminalColorsContext).background;
}
export function useTerminalForeground(): string | null {
return useContext(TerminalColorsContext).foreground;
}
export function useTerminalTheme(): TerminalTheme {
const { background, foreground } = useContext(TerminalColorsContext);
return getTerminalTheme(background, foreground);
}
+58
View File
@@ -0,0 +1,58 @@
import { createContext, useContext } from "react";
import type { TerminalTheme } from "../palette";
import { AUTO_THEME_ID, type ResolvedTheme, resolveTheme } from "../themes";
export interface TerminalColors {
background: string | null;
foreground: string | null;
}
export const TerminalColorsContext = createContext<TerminalColors>({
background: null,
foreground: null,
});
export interface ThemeController {
theme: ResolvedTheme;
/** The persisted selection (previews do not change this). */
selectedThemeId: string;
/** Select and persist a theme. */
setThemeId: (id: string) => void;
/** Temporarily render a theme (live preview); null reverts to selection. */
previewThemeId: (id: string | null) => void;
}
/** Provided by ThemeProvider (see theme-provider.tsx). */
export const ThemeContext = createContext<ThemeController | null>(null);
export function useThemeController(): ThemeController {
const controller = useContext(ThemeContext);
if (!controller) {
throw new Error("useThemeController must be used within ThemeProvider");
}
return controller;
}
export function useTheme(): ResolvedTheme {
const controller = useContext(ThemeContext);
const detected = useContext(TerminalColorsContext);
// Fall back to auto resolution so components render sensibly when mounted
// without a ThemeProvider (e.g. in isolated tests).
return controller?.theme ?? resolveTheme(AUTO_THEME_ID, detected);
}
/**
* Background that adaptive colors (input field, user bubbles, rules) derive
* from: the theme's painted background when set, else the detected one.
*/
export function useTerminalBackground(): string | null {
return useTheme().background;
}
export function useTerminalForeground(): string | null {
return useContext(TerminalColorsContext).foreground;
}
export function useTerminalTheme(): TerminalTheme {
return useTheme().variant;
}
+14
View File
@@ -1,7 +1,9 @@
import { createCliRenderer } from "@opentui/core";
import { createRoot } from "@opentui/react";
import { getInitialThemeId } from "./hooks/theme-provider";
import { Root } from "./root";
import { installTuiStdioCapture } from "./stdio-capture";
import { resolveTheme } from "./themes";
import type { TuiProps } from "./types";
export type { TuiProps } from "./types";
@@ -22,6 +24,17 @@ export async function renderOpenTui(
const terminalBackground = detectedPalette?.defaultBackground ?? null;
const terminalForeground = detectedPalette?.defaultForeground ?? null;
// Paint the selected theme's background before the first frame so themed
// sessions don't flash the terminal's own background on startup.
const initialThemeId = getInitialThemeId();
const initialTheme = resolveTheme(initialThemeId, {
background: terminalBackground,
foreground: terminalForeground,
});
if (initialTheme.appBackground) {
renderer.setBackgroundColor(initialTheme.appBackground);
}
let root: ReturnType<typeof createRoot>;
try {
root = createRoot(renderer);
@@ -30,6 +43,7 @@ export async function renderOpenTui(
{...props}
terminalBackground={terminalBackground}
terminalForeground={terminalForeground}
initialThemeId={initialThemeId}
/>,
);
} catch (error) {
+3 -3
View File
@@ -2,13 +2,13 @@ import { describe, expect, it } from "vitest";
import { getMcpDescription } from "./interactive-config";
describe("getMcpDescription", () => {
it("discloses the fast initialize probe for unconfigured stdio servers", () => {
it("discloses the default initialize timeout for unconfigured stdio servers", () => {
expect(
getMcpDescription({
name: "local",
transport: { type: "stdio", command: "node" },
}),
).toBe("stdio, local, request timeout 60s, initialize probe 1.5s");
).toBe("stdio, local, request timeout 60s, initialize timeout 3s");
});
it("shows one configured timeout when it also applies to initialize", () => {
@@ -40,6 +40,6 @@ describe("getMcpDescription", () => {
transport: { type: "stdio", command: "node" },
timeoutSeconds: Number.NaN,
}),
).toBe("stdio, local, request timeout 60s, initialize probe 1.5s");
).toBe("stdio, local, request timeout 60s, initialize timeout 3s");
});
});
+4 -37
View File
@@ -1,7 +1,6 @@
import { existsSync, readdirSync, readFileSync } from "node:fs";
import { existsSync, readdirSync } from "node:fs";
import {
basename,
dirname,
extname,
isAbsolute,
join,
@@ -10,7 +9,9 @@ import {
} from "node:path";
import {
type BuiltinToolAvailabilityContext,
DEFAULT_MCP_CONNECT_TIMEOUT_MS,
discoverPluginModulePaths,
getPluginDisplayName,
hasMcpSettingsFile,
listHookConfigFiles,
listPluginToolsWithDiagnostics,
@@ -183,7 +184,7 @@ export function getMcpDescription(registration: McpServerRegistration): string {
const timeoutDescription =
registration.transport.type === "stdio" &&
!isMcpTimeoutConfigured(registration.timeoutSeconds)
? `request timeout ${timeoutSeconds}s, initialize probe 1.5s`
? `request timeout ${timeoutSeconds}s, initialize timeout ${DEFAULT_MCP_CONNECT_TIMEOUT_MS / 1000}s`
: `timeout ${timeoutSeconds}s`;
return `${registration.transport.type}, ${getMcpAuthLabel(registration)}, ${timeoutDescription}`;
}
@@ -243,40 +244,6 @@ function loadAgentConfigItems(workspaceRoot: string): InteractiveConfigItem[] {
return [...agentsById.values()];
}
function readPackageName(packageJsonPath: string): string | undefined {
try {
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8")) as {
name?: unknown;
};
return typeof packageJson.name === "string" && packageJson.name.trim()
? packageJson.name.trim()
: undefined;
} catch {
return undefined;
}
}
function getPluginDisplayName(filePath: string, searchRoot: string): string {
let current = dirname(filePath);
const root = resolve(searchRoot);
while (isPathWithin(root, current)) {
const packageJsonPath = join(current, "package.json");
if (existsSync(packageJsonPath)) {
const packageName = readPackageName(packageJsonPath);
if (packageName) {
return packageName;
}
break;
}
const parent = resolve(current, "..");
if (parent === current) {
break;
}
current = parent;
}
return basename(filePath, extname(filePath));
}
function isPathWithin(parentPath: string, childPath: string): boolean {
const relativePath = relative(resolve(parentPath), resolve(childPath));
return (

Some files were not shown because too many files have changed in this diff Show More