Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66bacb655c | ||
|
|
6224cc80aa | ||
|
|
cb0092e343 | ||
|
|
0905884ab5 | ||
|
|
d8221325fa | ||
|
|
0cf47f5851 | ||
|
|
063ce7c06d | ||
|
|
173837314b | ||
|
|
3871851962 | ||
|
|
025baa8fb7 | ||
|
|
d6d4566451 | ||
|
|
964a0fc36d | ||
|
|
fb1d838085 | ||
|
|
99db7582b0 | ||
|
|
15f001ad0b | ||
|
|
186ac22e29 | ||
|
|
fc68af9660 | ||
|
|
b675eb6189 | ||
|
|
82b8e1fa04 | ||
|
|
6e8bea1cba | ||
|
|
8739d4953c | ||
|
|
c17c82b79a | ||
|
|
cb0b20f791 | ||
|
|
2198414245 | ||
|
|
d718dd16f8 | ||
|
|
128ec277d5 | ||
|
|
18477898e0 | ||
|
|
9f19f047d2 | ||
|
|
e21b5903c2 | ||
|
|
17529c8cb1 | ||
|
|
36905f11cc | ||
|
|
722b640c28 | ||
|
|
067b865f97 | ||
|
|
c925a9c94c | ||
|
|
899e8f3da4 | ||
|
|
e10183f2a8 | ||
|
|
00daef8f89 | ||
|
|
94980446c9 | ||
|
|
c2ac5feecb | ||
|
|
97afeaccf0 | ||
|
|
b4b980d9a1 | ||
|
|
9de01af92d | ||
|
|
d896a0ac84 | ||
|
|
f80dd1eeff | ||
|
|
19ddebb3b9 | ||
|
|
c1c0b55ca0 | ||
|
|
ccb62e6b39 | ||
|
|
81abe4978c | ||
|
|
ea7c7f11a9 | ||
|
|
cfe9cadab9 | ||
|
|
e7d224dec6 | ||
|
|
632fce5071 | ||
|
|
e15bb0a7e5 | ||
|
|
efa9a17caf | ||
|
|
ac082be7c5 | ||
|
|
7e20bbc0e0 | ||
|
|
a7c1dfc298 | ||
|
|
23924da84f | ||
|
|
dd50b97192 | ||
|
|
5142921a54 | ||
|
|
e4f1df2c5a | ||
|
|
3f74808a43 | ||
|
|
1636215231 | ||
|
|
a0a8c060fb | ||
|
|
31b0dd9900 | ||
|
|
ea368a1fc5 | ||
|
|
f6359842a5 | ||
|
|
a35f9c7e35 | ||
|
|
05dbe644d1 | ||
|
|
7877d0e0a3 | ||
|
|
4063e1731e | ||
|
|
75ac98a3c8 | ||
|
|
258227dbe0 | ||
|
|
fc3273bbe0 | ||
|
|
ae0c86f11f | ||
|
|
46ba1d3228 |
@@ -1,34 +1,33 @@
|
||||
---
|
||||
name: publish-extension
|
||||
description: Use when releasing the Cline VS Code extension — stable (currently the combined legacy+next A/B VSIX via ext-vscode-ab-package), nightly (ext-vscode-publish-nightly), or a legacy-branch hotfix (ext-vscode-publish-legacy). Guides version selection, changelog, PostHog rollout-flag coordination, workflow dispatch, environment approvals, tagging, and post-publish verification, plus the eventual cutover to publishing the SDK extension standalone.
|
||||
description: Use when releasing the Cline VS Code extension — stable (standalone SDK build of main via ext-vscode-publish-stable), nightly (ext-vscode-publish-nightly, manual dispatch), or an emergency legacy-branch hotfix (ext-vscode-publish-legacy). Guides version selection, changelog, workflow dispatch, environment approvals, tagging, post-publish verification, and the remaining retirement of the finished A/B rollout machinery.
|
||||
---
|
||||
|
||||
# VS Code Extension Release
|
||||
|
||||
Use this skill when the user asks to release, publish, or ship the VS Code extension — stable, nightly, or a legacy hotfix — or to dial the rollout, or to cut over to the SDK extension permanently.
|
||||
Use this skill when the user asks to release, publish, or ship the VS Code extension — stable, nightly, or an emergency legacy hotfix — or to retire the leftover A/B rollout machinery.
|
||||
|
||||
> Working directory: repo root. All workflows are dispatched from `main` (GitHub requires the workflow file on the default branch; each workflow checks out the refs it actually builds).
|
||||
|
||||
## The current era: combined A/B rollout
|
||||
## The current era: standalone SDK extension from `main`
|
||||
|
||||
We are mid-migration from the legacy (npm, pre-SDK) extension to the next (SDK-based, bun) extension. Until the cutover is complete, **the stable and nightly listings ship a combined VSIX**: a small loader + two complete extensions (`next/` built from `main`, `legacy/` built from the `legacy-extension` branch). The loader picks one per window based on the PostHog flag `ext-sdk-bundle-rollout`. Deep-dive docs: `apps/vscode-rollout/README.md` (authoritative) and PR #12253 (design + runbook comments).
|
||||
**The legacy → SDK migration is complete.** The PostHog flag `ext-sdk-bundle-rollout` reached 100% (verified empirically 2026-09-15: 200/200 `/decide` probes returned `true`), so every user on the combined VSIX runs the `next` (SDK, bun) bundle and the `legacy/` half is dead weight. Stable releases now ship a **plain build of `main`** through `ext-vscode-publish-stable.yml`. The combined A/B path (`ext-vscode-ab-package.yml`) is no longer used for releases and is pending deletion — see "Retiring the A/B machinery" at the bottom for what is still left to clean up and the one caveat (leave the flag at 100%).
|
||||
|
||||
Endgame (see "Cutover" at the bottom): once the next bundle is trusted at 100%, stable goes back to a plain build of `main` via `ext-vscode-publish-stable.yml` and all the legacy/rollout machinery is retired.
|
||||
History, for context only: the A/B era ran `4.1.0` → `4.1.17` (Jul–Sep 2026). Design docs remain at `apps/vscode-rollout/README.md` and PR #12253 until that directory is removed.
|
||||
|
||||
### The listings and the workflows
|
||||
|
||||
| Channel | Marketplace ID | Workflow | Trigger | Version |
|
||||
|---|---|---|---|---|
|
||||
| Stable (combined) | `saoudrizwan.claude-dev` | `ext-vscode-ab-package.yml` | dispatch only; `publish` input defaults false | manual input (semver, e.g. `4.1.0`) |
|
||||
| Nightly (combined) | `saoudrizwan.cline-nightly` | `ext-vscode-publish-nightly.yml` | cron 12:00 UTC + dispatch | auto `<major>.<minor>.<unix-ts>` from main's `apps/vscode/package.json` |
|
||||
| Legacy hotfix (standalone) | `saoudrizwan.claude-dev` | `ext-vscode-publish-legacy.yml` | dispatch | from `apps/vscode/package.json` on `legacy-extension` |
|
||||
| Stable standalone (post-cutover) | `saoudrizwan.claude-dev` | `ext-vscode-publish-stable.yml` | dispatch | from `apps/vscode/package.json` on `main` |
|
||||
| **Stable** | `saoudrizwan.claude-dev` | `ext-vscode-publish-stable.yml` | dispatch, from `main` | `apps/vscode/package.json` on `main`; tag `v<version>` must match |
|
||||
| Nightly | `saoudrizwan.cline-nightly` | `ext-vscode-publish-nightly.yml` | **manual dispatch only** (cron deliberately removed) | auto `<major>.<minor>.<unix-ts>` from main's `apps/vscode/package.json` |
|
||||
| Legacy hotfix (emergency only) | `saoudrizwan.claude-dev` | `ext-vscode-publish-legacy.yml` | dispatch | `apps/vscode/package.json` on `legacy-extension` |
|
||||
|
||||
All three publish paths gate on tests before publishing: nightly and ab-package run the reusable bun suite (`ext-vscode-test.yml`, tests `main`) — ab-package additionally runs the legacy branch's npm suite — and the legacy workflow inlines the npm suite. Environment gates: stable paths use `publish` → `Publish` environment (required reviewers approve in the Actions UI); nightly uses `PublishNightly` (branch policy only, no reviewers — a reviewer requirement would block the cron).
|
||||
Stable runs the reusable bun suite (`ext-vscode-test.yml`, tests `main`) before an environment-gated publish job (`publish` environment — required reviewers approve in the Actions UI). Nightly uses `PublishNightly` (branch policy only). Nightly **still builds the combined loader VSIX** (loader + `next/` + `legacy/`) until it is converted back to a plain build — that conversion is on the retirement list below.
|
||||
|
||||
## Golden rules (read before any release)
|
||||
|
||||
1. **One listing, one version line.** `claude-dev` is published from multiple workflows/branches. Every stable publish must use a version **strictly above the highest version ever published to the listing from any branch** — marketplace versions are monotonic and cannot be unpublished (supersede, never delete). Check what's live first:
|
||||
1. **One listing, one version line.** `claude-dev` has been published from multiple workflows and branches. Every stable publish must use a version **strictly above the highest version ever published to the listing from any branch** — marketplace versions are monotonic and cannot be unpublished (supersede, never delete). Check what's live first:
|
||||
|
||||
```bash
|
||||
curl -s -X POST "https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery" \
|
||||
@@ -37,13 +36,123 @@ All three publish paths gate on tests before publishing: nightly and ab-package
|
||||
| python3 -c "import json,sys; v=json.load(sys.stdin)['results'][0]['extensions'][0]['versions'][0]; print(v['version'], v['lastUpdated'])"
|
||||
```
|
||||
|
||||
`ext-vscode-ab-package` also enforces this automatically for `publish=true` runs: a preflight job validates the version format (plain `X.Y.Z`) and hard-fails unless it exceeds the live Marketplace version, and the publish job re-checks right before publishing (the approval wait can last days — a legacy hotfix landing in between is caught). Still run the query yourself when *choosing* the version.
|
||||
**`ext-vscode-publish-stable` has no marketplace-monotonicity preflight** (that check only ever lived in the retired ab-package workflow), so this query is the only guard. The `legacy-extension` branch sits at `4.0.12`, so it cannot collide with the `4.1.x` line, but a legacy hotfix would have to be numbered above the live stable version (see the emergency section).
|
||||
|
||||
2. **Check the flag BEFORE any stable combined publish.** `ext-sdk-bundle-rollout` is **shared between nightly and stable** — the loader sends only a machine id to `/decide`, no channel property, so there is no per-channel targeting. If the flag is high (nightly dogfooding) and you publish stable, stable users get the next bundle at that same percentage. Verify the effective percentage empirically (no PostHog admin needed — sample `/decide` with random ids using the key inlined in any shipped loader):
|
||||
2. **Tag == package version, enforced.** The workflow reads `apps/vscode/package.json`, requires the `tag` input to equal `v<that version>`, and hard-fails otherwise. Bump the version on `main` first.
|
||||
|
||||
3. **Changelog lives at the repo ROOT** (`CHANGELOG.md`) — not `apps/vscode/CHANGELOG.md` (doesn't exist). The workflow hard-fails unless the first `## [` heading is exactly `## [<version>]`. The section body becomes the GitHub release notes and the Slack post (Slack copy is trimmed to 3000 chars with a link out; the release body stays whole).
|
||||
|
||||
4. **Ask before pushing** commits or tags. **Never approve the `publish` environment gate yourself via `gh api`** — hand the maintainer the run URL to click "Review deployments".
|
||||
|
||||
5. **Concurrency**: the workflow groups on the tag with `cancel-in-progress: false`. A publish run left `waiting` on approval blocks every later dispatch of the same tag until cancelled (`gh run cancel <id>`).
|
||||
|
||||
## Stable release — the current path
|
||||
|
||||
### Pre-flight
|
||||
|
||||
```bash
|
||||
# 1. What's live (rule 1) → pick <VERSION> strictly above it (normally patch bump).
|
||||
# 2. Confirm main's package.json is at the *previous* published version, i.e. the repo
|
||||
# reflects the live line and nothing unreleased is already bumped:
|
||||
node -p "require('./apps/vscode/package.json').version"
|
||||
# 3. What's in the release:
|
||||
git fetch origin main --tags
|
||||
git log v<PREV>..origin/main --oneline --no-merges -- apps/vscode sdk/packages
|
||||
```
|
||||
|
||||
The CLI/SDK notes are the best starting point for the extension notes — the extension bundles `@cline/*` from source, so an SDK release in the same window ships here too. Read `sdk/CHANGELOG.md` for the matching SDK version and translate what's extension-visible; skip CLI-only and desktop-only items.
|
||||
|
||||
### Release prep on `main` (PR, not direct push)
|
||||
|
||||
- Bump `apps/vscode/package.json` → `<VERSION>`.
|
||||
- Prepend `## [<VERSION>]` to root `CHANGELOG.md` with the approved notes.
|
||||
- Side effect of the bump: nightly versions become `<major>.<minor>.<unix-ts>` of the new base — harmless (separate listing, still monotonic).
|
||||
|
||||
Optional local rehearsal of the exact packaging step (the workflow has no dry-run input, and the build runs inside the gated publish job, so this is the only pre-approval check):
|
||||
|
||||
```bash
|
||||
bun install --frozen-lockfile && bun run build:sdk
|
||||
cd apps/vscode && npx @vscode/vsce package --no-dependencies --allow-package-secrets sendgrid --out /tmp/rehearsal.vsix
|
||||
# vsce runs vscode:prepublish → `bun run package` (check-types + build:webview + lint + esbuild --production),
|
||||
# i.e. the same build the workflow performs. Telemetry env is NOT set locally, so expect
|
||||
# telemetry to be dark in this artifact — that is fine for a build rehearsal, not for shipping.
|
||||
```
|
||||
|
||||
### Dispatch
|
||||
|
||||
```bash
|
||||
gh workflow run ext-vscode-publish-stable.yml --ref main \
|
||||
-f release-type=release \
|
||||
-f auto_create_tag_from_main=true \
|
||||
-f tag=v<VERSION>
|
||||
gh run list --workflow=ext-vscode-publish-stable.yml --limit 1 --json databaseId,url,status
|
||||
```
|
||||
|
||||
What the run does, in order: test gate on `main` → publish job checks out `main`, **creates and pushes `v<VERSION>` at the tested SHA** (auto-create mode; refuses if the tag already exists elsewhere) → `bun install --frozen-lockfile` → `bun run build:sdk` → asserts the `better-sqlite3` native binary → verifies tag/version/changelog/PATs → `vsce package` → `bun run publish:marketplace` (vsce publish **and** `npx ovsx publish`, both `--no-dependencies`) → GitHub release with the `.vsix` attached → Slack post. The publish job waits for `publish` environment approval before any of that. Check what a run is waiting on:
|
||||
|
||||
```bash
|
||||
gh api repos/cline/cline/actions/runs/<run-id>/pending_deployments
|
||||
```
|
||||
|
||||
`release-type=pre-release` publishes to the pre-release channel of the same listing; it is a real publish, not a rehearsal.
|
||||
|
||||
### Post-publish
|
||||
|
||||
1. Verify both registries serve the new version (expect minutes-to-an-hour of Marketplace validation lag after "Published" appears in the logs):
|
||||
|
||||
```bash
|
||||
# Marketplace: query from rule 1
|
||||
curl -s "https://open-vsx.org/api/saoudrizwan/claude-dev" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d['version'], d['timestamp'])"
|
||||
```
|
||||
|
||||
2. Verify the bookkeeping landed: `git fetch --tags && git tag --list 'v<VERSION>'`, `gh release view v<VERSION>`, Slack post in the release channel. Tag creation happens **before** the build in this workflow, so a tag-push failure fails the run early (no publish) rather than leaving a published-but-untagged release. Known cause: the built commit touches `.github/workflows/**` (default token cannot create such refs). Workaround: create and push the tag yourself at `origin/main` HEAD (ask first), then re-dispatch with `auto_create_tag_from_main=false` from `main` — the workflow requires the existing tag to point at the exact SHA it tested.
|
||||
|
||||
3. Artifact check (`gh run download <run-id>` or the release asset): `package.json` inside is `saoudrizwan.claude-dev@<VERSION>`; `grep -c 'process.env.TELEMETRY_SERVICE_API_KEY' extension/dist/extension.js` must be **0** (a leftover literal means the build ran without its env and telemetry is silently dead). `CLINE_ROLLOUT_VARIANT` is defined to `""` for ordinary builds by `apps/vscode/esbuild.mjs`, so no literal is expected and telemetry carries no `extension_variant` — correct for a standalone build.
|
||||
|
||||
4. Monitor errors on `extension_version = '<VERSION>'` in `otel.otel_logs` (stable cohort is cleanly separable — nightly versions are timestamps). Metabase dashboards 17 (task error rate) and 19 (error deep dive).
|
||||
|
||||
## Nightly release
|
||||
|
||||
**Manual dispatch only.** The cron was removed on purpose: the `PublishNightly` environment made scheduled runs sit `waiting`, hold the concurrency group, and silently cancel every later scheduled run behind them. A stale nightly listing is therefore expected, not a bug.
|
||||
|
||||
```bash
|
||||
gh workflow run ext-vscode-publish-nightly.yml --ref main # real publish
|
||||
gh workflow run ext-vscode-publish-nightly.yml --ref main -f dry-run=true # artifact only
|
||||
```
|
||||
|
||||
No changelog/version prep — the version is computed. Verify with the Marketplace query against `saoudrizwan.cline-nightly`. Until converted, nightly still ships the combined loader VSIX with a `legacy/` bundle built from `legacy-extension`.
|
||||
|
||||
**Red run ≠ failed publish** on this path: its tag-push step runs *after* publishing and fails whenever main's HEAD touches `.github/workflows/**`. If "Published" appears in the logs, the release went out; push the `nightly-main-<UTC ts>-<sha12>` tag manually with user credentials.
|
||||
|
||||
## Emergency rollback
|
||||
|
||||
Preferred: **ship a fixed build of `main` at a higher version** through the stable workflow above. It is the same path, fully gated, and the only rollback that keeps users on the SDK extension.
|
||||
|
||||
Last resort — the legacy hotfix path — still exists but is degraded: `legacy-extension` is the pre-SDK npm codebase, last touched 2026-08-18 at `4.0.12`, and a publish from it would move every user back onto code that is weeks behind. If it is ever needed:
|
||||
|
||||
```bash
|
||||
# On legacy-extension: commit the fix, bump apps/vscode/package.json ABOVE the
|
||||
# live stable version (rule 1 — e.g. 4.1.18 live -> hotfix is 4.1.19, not 4.0.13),
|
||||
# add the matching `## [x.y.z]` entry to root CHANGELOG.md, push.
|
||||
gh workflow run ext-vscode-publish-legacy.yml --ref main -f release-type=release
|
||||
# (the branch is hardcoded to legacy-extension in the workflow)
|
||||
```
|
||||
|
||||
The npm suite runs ungated, the publish job waits on the `publish` environment, the workflow tags and creates the GitHub release itself, and it publishes to Marketplace **and** Open VSX. On that branch use `npm`, never `bun`, and expect the old monolith layout (`apps/vscode/src/core/...`).
|
||||
|
||||
## Retiring the A/B machinery (still to do)
|
||||
|
||||
The rollout is done but the scaffolding is still in the repo. Retire it in this order, each as its own PR:
|
||||
|
||||
1. **Nightly → plain build of `main`**: drop the loader/`legacy-src` stitching from `ext-vscode-publish-nightly.yml` so nightly matches stable. Preserve the `|| 'default'` fallbacks for `inputs.*` while editing.
|
||||
2. Delete `ext-vscode-ab-package.yml` and, once the emergency path above is judged unnecessary, `ext-vscode-publish-legacy.yml`; keep the `legacy-extension` branch for history.
|
||||
3. Remove `apps/vscode-rollout/` and the rollout-only code paths in `apps/vscode/src/services/telemetry/rollout-metadata.ts` (the `extension_variant` metadata and `extension.rollout.bundle_activated` event).
|
||||
4. Optionally port the marketplace-monotonicity preflight from the old ab-package workflow into `ext-vscode-publish-stable.yml` — the only automated guard for rule 1 was retired with it.
|
||||
5. **Archive the PostHog flag last, and not yet.** Machines still on a combined VSIX (`≤ 4.1.17`) consult `ext-sdk-bundle-rollout` on every window load and treat a *deleted* flag as `legacy`. Leave it at 100% until `extension.rollout.bundle_activated` for combined versions flatlines, then archive. Re-verify the percentage empirically before touching it (no PostHog admin needed — the key is inlined in any shipped combined loader; download the 4.1.17 VSIX from the Marketplace `vspackage` URL, `gunzip`, `unzip`, `grep -o 'phc_[A-Za-z0-9]*' extension/extension.js`):
|
||||
|
||||
```bash
|
||||
node -e '
|
||||
const KEY = process.argv[1]; // phc_... extracted from a shipped VSIX loader
|
||||
const KEY = process.argv[1];
|
||||
(async () => {
|
||||
let t = 0, n = 200;
|
||||
for (let i = 0; i < n; i += 20) {
|
||||
@@ -58,129 +167,15 @@ All three publish paths gate on tests before publishing: nightly and ab-package
|
||||
})()' "$KEY"
|
||||
```
|
||||
|
||||
Flag changes are made in the PostHog UI (Cline project). **0% is the kill switch** — the flag is two-way; there is no separate killswitch flag. Dialing down demotes machines back to legacy on their next window reload.
|
||||
|
||||
3. **Ask before pushing** commits or tags. Environment approvals are the maintainer's to give.
|
||||
|
||||
4. **Changelog lives at the repo ROOT** (`CHANGELOG.md`), on the branch being released — not `apps/vscode/CHANGELOG.md` (doesn't exist). The legacy and stable workflows hard-fail unless the first heading is exactly `## [<version>]`.
|
||||
|
||||
5. **Stuck concurrency groups**: `ext-vscode-ab-package` groups on the version with `cancel-in-progress: false`. Only `publish=true` runs wait on environment approval (build-only rehearsals run ungated to completion), but a publish run left `waiting` still blocks every later dispatch of the same version — cancel it (`gh run cancel <id>`) before re-dispatching.
|
||||
|
||||
## Stable release (combined A/B VSIX) — the current stable path
|
||||
|
||||
### Pre-flight
|
||||
|
||||
```bash
|
||||
# 1. What's live, and what version comes next (must exceed it — rule 1)
|
||||
# 2. Flag percentage (rule 2) — decide where it should be for this release
|
||||
# 3. Legacy tip = what the non-promoted cohort will run; confirm it's the shipped hotfix line
|
||||
git fetch origin main legacy-extension
|
||||
git log --oneline -3 origin/legacy-extension
|
||||
|
||||
# 4. Cheap local rehearsal of the most likely build failure: the union manifest
|
||||
# hard-fails if views/viewsContainers/configuration diverged between branches.
|
||||
git show origin/main:apps/vscode/package.json > /tmp/next.json
|
||||
git show origin/legacy-extension:apps/vscode/package.json > /tmp/legacy.json
|
||||
node apps/vscode-rollout/scripts/gen-manifest.mjs --next /tmp/next.json --legacy /tmp/legacy.json --version <VERSION>
|
||||
# Expected warnings only: engines union (takes newer) + walkthrough copy drift.
|
||||
```
|
||||
|
||||
Release prep on `main` (PR, not direct push):
|
||||
- Add `## [<VERSION>]` entry at the top of root `CHANGELOG.md`.
|
||||
- Bump `apps/vscode/package.json` to `<VERSION>` so the repo reflects the published line. Side effect: nightly versions become `<major>.<minor>.<unix-ts>` of the new base — harmless (separate listing, still monotonic).
|
||||
|
||||
### Dispatch
|
||||
|
||||
```bash
|
||||
gh workflow run ext-vscode-ab-package.yml --ref main \
|
||||
-f version=<VERSION> -f next-ref=main -f publish=true
|
||||
# (the legacy bundle always builds from the protected legacy-extension branch;
|
||||
# it is deliberately not an input)
|
||||
# publish=false builds an installable .vsix artifact without publishing and
|
||||
# needs NO environment approval — the ungated build job uploads the artifact
|
||||
# and the run completes.
|
||||
gh run list --workflow=ext-vscode-ab-package.yml --limit 1
|
||||
```
|
||||
|
||||
Preflight (version format + monotonicity) and both test suites run first, then the ungated `build` job packages and uploads the VSIX; for `publish=true` the `publish` job then **waits for `Publish` environment approval** (Actions → run → "Review deployments"). Both bundles build the exact revisions their test gates ran against (branch names are resolved once — commits landing on either branch mid-run or during the approval wait are not picked up); `publish=true` is additionally refused for any `next-ref` other than `main` (the bun gate only tests main — non-main next-refs are for build-only artifact rehearsals). Check what a run is waiting on:
|
||||
|
||||
```bash
|
||||
gh api repos/cline/cline/actions/runs/<run-id>/pending_deployments
|
||||
```
|
||||
|
||||
### Post-publish
|
||||
|
||||
1. Verify the marketplace serves the new version (query from rule 1) — expect minutes-to-an-hour of validation lag after "Published" appears in the logs. Also verify Open VSX:
|
||||
|
||||
```bash
|
||||
curl -s "https://open-vsx.org/api/saoudrizwan/claude-dev" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d['version'], d['timestamp'])"
|
||||
```
|
||||
2. Tag, GitHub Release (with the .vsix attached), and the Slack release-bot post happen **automatically** after a real publish (all `continue-on-error` — the publish itself already succeeded, so bookkeeping failures leave the run green). Verify they landed; the known failure is the tag push when the built commit touches `.github/workflows/**` (default token cannot create such refs — no grantable permission fixes it). Manual fallback:
|
||||
|
||||
```bash
|
||||
git tag v<VERSION> <main-sha-built> # ask before pushing
|
||||
git push origin v<VERSION>
|
||||
gh release create v<VERSION> --title "v<VERSION>" --notes "<changelog section>" <path-to.vsix>
|
||||
```
|
||||
|
||||
A real publish also **hard-fails early** if root `CHANGELOG.md` on the built main revision doesn't start with `## [<VERSION>]` — the release prep PR must be merged before dispatching.
|
||||
|
||||
3. Thorough artifact check (`gh run download <run-id>`): union `package.json` is `saoudrizwan.claude-dev@<VERSION>`, `next/package.json` and `legacy/package.json` carry the SAME version, `grep -c 'phc_' extension/extension.js` ≥ 1 (loader key inlined), no leftover `process.env.TELEMETRY_SERVICE_API_KEY` / `process.env.CLINE_ROLLOUT_VARIANT` literals in either bundle's dist (leftovers = a build ran without its env and telemetry is silently dead).
|
||||
4. Monitor: `extension.rollout.bundle_activated` in `otel.otel_logs` filtered to `extension_version = '<VERSION>'` (stable cohort is cleanly separable — nightly versions are timestamps). Watch the next/legacy ratio and the crash-fallback rate; Metabase dashboards 17 (rollout + task error rate) and 19 (error deep dive). `extension.rollout.loader_decision` (incl. `double_failure`) is PostHog-only, not in ClickHouse.
|
||||
5. Dial the flag per the rollout plan (e.g. 0% at publish → 1% → up), verifying each change with the probe from rule 2. Announce demotions ahead of time — dialing down also demotes nightly dogfooders unless they set `"cline-nightly.rollout.bundleOverride": "next"`.
|
||||
|
||||
### Known caveats of this path
|
||||
|
||||
- **`engines.vscode` unions upward** (main's floor wins, e.g. `^1.101.0` vs legacy's `^1.84.0`): users on older VS Code are never offered the combined VSIX. Fail-safe during rollout; must be resolved before 100%.
|
||||
- A red run can still mean a successful publish on paths that tag (see Gotchas).
|
||||
|
||||
## Nightly release
|
||||
|
||||
Happens automatically (cron 12:00 UTC). Manual cut:
|
||||
|
||||
```bash
|
||||
gh workflow run ext-vscode-publish-nightly.yml --ref main # real publish
|
||||
gh workflow run ext-vscode-publish-nightly.yml --ref main -f dry-run=true # artifact only
|
||||
gh run watch <run-id> --exit-status --interval 60
|
||||
```
|
||||
|
||||
No changelog/version prep — the version is computed. Verify with the marketplace query against `saoudrizwan.cline-nightly`.
|
||||
|
||||
**Red run ≠ failed publish**: the final tag-push step fails whenever main's HEAD touches `.github/workflows/**` (default token cannot create such refs). If "Published" appears in the logs, the release went out; push the `nightly-main-<UTC ts>-<sha12>` tag manually with user credentials.
|
||||
|
||||
## Legacy hotfix release (and emergency full rollback)
|
||||
|
||||
For shipping a fix on the `legacy-extension` branch — or as the **structural rollback** from a bad combined stable VSIX: a standalone legacy publish at a higher version supersedes the combined VSIX entirely (loader and all) for every user. (For "next bundle misbehaving" you don't need this — dial the flag to 0% instead.)
|
||||
|
||||
```bash
|
||||
# On legacy-extension: commit the fix, bump apps/vscode/package.json ABOVE the
|
||||
# highest version ever published to the listing (rule 1 — including combined
|
||||
# versions, e.g. combined 4.1.0 live -> hotfix is 4.1.1, not 4.0.13),
|
||||
# add the matching `## [x.y.z]` entry to root CHANGELOG.md, push.
|
||||
gh workflow run ext-vscode-publish-legacy.yml --ref main \
|
||||
-f release-type=release
|
||||
# (the branch is hardcoded to legacy-extension in the workflow; it is
|
||||
# deliberately not an input)
|
||||
```
|
||||
|
||||
npm test suite runs ungated; the publish job waits on the `Publish` environment. This workflow derives + pushes the `v<version>` tag itself and creates the GitHub release — no manual tagging. Publishes to Marketplace **and** Open VSX. The branch is the npm codebase: use `npm`, never `bun`, and expect the old monolith layout (`apps/vscode/src/core/...`).
|
||||
|
||||
## Cutover: retiring the A/B machinery (the endgame)
|
||||
|
||||
When the next bundle has held at 100% long enough to trust:
|
||||
|
||||
1. **Resolve the engines floor**: decide whether stranding VS Code < main's `engines.vscode` on the last combined version is acceptable, or lower main's floor first.
|
||||
2. Bump `apps/vscode/package.json` on `main` above everything ever published; root `CHANGELOG.md` entry to match (both are enforced by the workflow).
|
||||
3. Ship standalone from main: `gh workflow run ext-vscode-publish-stable.yml --ref main` — tests main, tags `v<version>` itself, creates the GitHub release, publishes Marketplace + Open VSX.
|
||||
4. Watch the same rollout telemetry through the transition — `extension_variant` disappears from events as users leave combined builds, which is itself the adoption signal.
|
||||
5. Only after the standalone version dominates: retire `legacy-extension` (keep for history), delete `ext-vscode-publish-legacy.yml` and `ext-vscode-ab-package.yml`, convert the nightly workflow back to a plain build of main, remove `apps/vscode-rollout/`, and archive the `ext-sdk-bundle-rollout` flag in PostHog (harmless to machines still on a combined VSIX: absent flag fails safe to... nothing changing until they update, but their loader treats a deleted flag as legacy — leave the flag at 100% until combined-VSIX activations flatline, then archive).
|
||||
6. Update this skill: delete the combined-era sections and keep the standalone flow.
|
||||
6. Update this skill: delete this section and the combined-loader notes under Nightly.
|
||||
|
||||
## Gotchas index
|
||||
|
||||
- `inputs.*` are empty strings on `schedule` events — preserve `|| 'default'` fallbacks when editing the nightly workflow.
|
||||
- `bun run package` in `apps/vscode` does not build `@cline/*` workspace deps — fresh checkouts need `bun run build:sdk` first (workflows handle this).
|
||||
- `bun run package` in `apps/vscode` does not build `@cline/*` workspace deps — fresh checkouts need `bun run build:sdk` first (the workflows handle this).
|
||||
- Every ext workflow pins `bun-version: 1.3.14` while the root `packageManager` is `bun@1.3.13`. This is consistent across all of them and has shipped fine — don't "fix" it in one workflow alone.
|
||||
- The publish job pins **Node 22** on purpose: Node 24 / npm 11 can make vsce's `npm list` detection fail with `ELSPROBLEMS` during packaging. `setup-bun` provides no Node runtime, and the publish scripts and `npx ovsx` need one.
|
||||
- `gh run watch --exit-status` has returned exit 0 on a failed run. Always confirm with `gh run view <id> --json status,conclusion` before acting on a result.
|
||||
- Job-level `if:` ref checks in workflow YAML are advisory (a dispatched branch runs its own copy of the file); the enforced boundary is each environment's deployment-branch policy in repo settings.
|
||||
- Marketplace PATs (`VSCE_PAT`/`OVSX_PAT`) are only mounted into publish steps; neither publish workflow has an untrusted trigger surface.
|
||||
- Environment-approval runs left waiting don't time out quickly — they sit for days and (for ab-package publish runs) block their version's concurrency group.
|
||||
- Local forcing for manual testing: `CLINE_BUNDLE_OVERRIDE=next|legacy` env (launch VS Code fresh from a terminal) or the `<prefix>.rollout.bundleOverride` setting + reload; both report as `override` in telemetry so they don't pollute cohort data.
|
||||
- Marketplace PATs (`VSCE_PAT`/`OVSX_PAT`) are only mounted into publish steps; no publish workflow has an untrusted trigger surface.
|
||||
- Environment-approval runs left waiting don't time out quickly — they sit for days and block their tag's concurrency group.
|
||||
- Open VSX has held a first-time publish in moderation before (logs say "Published", API 404s for hours). Verify with the API query rather than the log line.
|
||||
|
||||
@@ -154,6 +154,8 @@ jobs:
|
||||
OTEL_TELEMETRY_ENABLED: ${{ secrets.OTEL_TELEMETRY_ENABLED }}
|
||||
OTEL_LOGS_EXPORTER: otlp
|
||||
OTEL_METRICS_EXPORTER: otlp
|
||||
OTEL_TRACES_EXPORTER: otlp
|
||||
CLINE_TRACE_RECORD_CONTENT: "true"
|
||||
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 }}
|
||||
@@ -423,6 +425,8 @@ jobs:
|
||||
OTEL_TELEMETRY_ENABLED: ${{ secrets.OTEL_TELEMETRY_ENABLED }}
|
||||
OTEL_LOGS_EXPORTER: otlp
|
||||
OTEL_METRICS_EXPORTER: otlp
|
||||
OTEL_TRACES_EXPORTER: otlp
|
||||
CLINE_TRACE_RECORD_CONTENT: "true"
|
||||
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 }}
|
||||
|
||||
@@ -284,6 +284,8 @@ jobs:
|
||||
OTEL_TELEMETRY_ENABLED: ${{ secrets.OTEL_TELEMETRY_ENABLED }}
|
||||
OTEL_LOGS_EXPORTER: otlp
|
||||
OTEL_METRICS_EXPORTER: otlp
|
||||
OTEL_TRACES_EXPORTER: otlp
|
||||
CLINE_TRACE_RECORD_CONTENT: "true"
|
||||
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 }}
|
||||
|
||||
@@ -161,6 +161,8 @@ jobs:
|
||||
OTEL_TELEMETRY_ENABLED: ${{ secrets.OTEL_TELEMETRY_ENABLED }}
|
||||
OTEL_LOGS_EXPORTER: otlp
|
||||
OTEL_METRICS_EXPORTER: otlp
|
||||
OTEL_TRACES_EXPORTER: otlp
|
||||
CLINE_TRACE_RECORD_CONTENT: "true"
|
||||
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 }}
|
||||
|
||||
@@ -272,6 +272,8 @@ jobs:
|
||||
OTEL_TELEMETRY_ENABLED: ${{ secrets.OTEL_TELEMETRY_ENABLED }}
|
||||
OTEL_LOGS_EXPORTER: otlp
|
||||
OTEL_METRICS_EXPORTER: otlp
|
||||
OTEL_TRACES_EXPORTER: otlp
|
||||
CLINE_TRACE_RECORD_CONTENT: "true"
|
||||
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 }}
|
||||
|
||||
@@ -6,13 +6,13 @@ on:
|
||||
- main
|
||||
paths:
|
||||
- "sdk/**"
|
||||
- "apps/examples/desktop-app/**"
|
||||
- ".github/workflows/sdk-test.yml"
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "sdk/**"
|
||||
- "apps/examples/desktop-app/**"
|
||||
- ".github/workflows/sdk-test.yml"
|
||||
workflow_call:
|
||||
|
||||
@@ -98,6 +98,14 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build_sdk_step.outcome == 'success' && steps.build_cli_step.outcome == 'success' && matrix.os == 'windows-latest' }}
|
||||
run: bun -F './sdk/packages/**' test
|
||||
|
||||
- name: Run Desktop Sidecar Tests
|
||||
if: ${{ !cancelled() && steps.build_sdk_step.outcome == 'success' && matrix.os == 'ubuntu-latest' }}
|
||||
run: bun -F @cline/code test:sidecar
|
||||
|
||||
- name: Run Desktop Settings UI Tests
|
||||
if: ${{ !cancelled() && steps.build_sdk_step.outcome == 'success' }}
|
||||
run: bun -F @cline/code test:settings-ui
|
||||
|
||||
- name: Smoke test SQLite under Node
|
||||
if: ${{ !cancelled() && steps.build_sdk_step.outcome == 'success' && matrix.os != 'windows-latest' }}
|
||||
timeout-minutes: 10
|
||||
|
||||
@@ -1,5 +1,40 @@
|
||||
# Changelog
|
||||
|
||||
## [4.1.18]
|
||||
|
||||
### Added
|
||||
|
||||
- Images attached to a model that cannot read them are now flagged instead of silently discarded. Thumbnails get a warning badge and the composer explains that the images will be ignored, with a button to switch to an image-capable model. Previously the thumbnail looked normal and the image was replaced with a text placeholder just before the request, so there was no way to tell it had been dropped. Model info and the attachment picker also report image support accurately for models that declare text-only input without listing capabilities.
|
||||
|
||||
### Fixed
|
||||
|
||||
- On Windows, opening a repository that contains a file named `rg.exe`, `git.exe`, or `powershell.exe` no longer runs that file in place of the real program. Bare program names were resolved through the workspace directory before PATH, so a planted executable ran with your privileges as soon as the workspace was indexed. Cline now sets Windows' `NoDefaultCurrentDirectoryInExePath` opt-out at startup, in both the VS Code extension and the JetBrains core. Processes Cline launches inherit it, so inside a Command Prompt shell a program in the current directory now needs `.\` as it already does in PowerShell.
|
||||
- A model turn that fails mid-stream with a transient provider error is now retried up to three times with backoff instead of ending the task. A single rate-limit response forwarded by a gateway previously surfaced as a failed task. A turn that has already streamed output is never retried, so nothing is duplicated.
|
||||
- Terminal commands that succeed without printing anything (`git add -A` on a clean tree, for example) are now reported as empty output. They were treated as a shell-integration failure, which fed the model a snapshot of unrelated terminal scrollback prefixed with a warning that the output could not be captured, so silent commands intermittently looked like failures.
|
||||
- Checkpoints no longer re-hash every untracked file on each message. In workspaces holding large untracked directories this delayed every message by seconds to minutes; a persistent per-task index now lets git skip files it has already seen.
|
||||
- `run_commands` no longer hangs until its timeout after a command that backgrounds a child process. The command had finished, but the backgrounded process held the output pipes open.
|
||||
- `apply_patch` no longer silently overwrites an existing file when the model uses "Add File" on a path that already exists. The file's contents were replaced with no error and no record of what was lost.
|
||||
- PowerShell commands the model wrapped in another `powershell -Command "..."` are no longer parsed twice. The outer shell consumed `$_` before the inner command ran, so pipelines using it emitted an error for every item processed while still reporting success.
|
||||
- Opening your home directory as a workspace no longer drives the extension host to exhaustion. Typing an `@` mention indexed every file beneath it and re-ranked the whole index on each keystroke.
|
||||
- The "Supports Images" checkbox in OpenAI Compatible model settings now stays where you put it. The checkbox rendered the last committed value, and the re-sync that arrived during the save round-trip was re-emitted as a change event that wrote the old value back over your edit.
|
||||
- The error shown to the model when an `editor` call omits the text to replace now names the file and explains how to recover. The previous message was terse enough that some models re-sent the identical call until the task stopped.
|
||||
- Credentials are now stripped of invisible characters when saved, not only when pasted, and the cleanup covers AWS, GCP, and SAP fields and custom header values in addition to API keys.
|
||||
- Cline Pass now defaults to a model from your subscription rather than a free one. Its model list contains both tiers and the default was whichever model was published most recently, so a subscriber who never picked a model could be left on the free tier.
|
||||
- Cline Pass and free models now show no cost rather than the underlying market price, which is not what you are billed for.
|
||||
- Model pickers now fall back to the full Recommended, Free, and Subscribed lists when the models endpoint cannot be reached. The offline fallback was a short hardcoded list with no subscription tier at all.
|
||||
- Model lists for providers sharing the built-in catalog now refresh from the live catalog, so newly published models appear without an extension update, with timeouts so an unresponsive provider endpoint cannot stall the list.
|
||||
- Claude Code and OpenCode no longer ask for an API key they never read. Both authenticate from their own local CLI's credentials, but they were treated as key-based providers; the workaround was storing a dummy key. A missing CLI on `PATH` now warns rather than blocking, since a configured path or bundled binary also works.
|
||||
- The OpenAI Codex (ChatGPT subscription) model list no longer offers models the backend rejects, and Codex context limits are applied to every Codex model instead of being inherited from the OpenAI API catalog, which inflated both the context budget and the usage figures derived from it.
|
||||
- Models served by OpenCode Go are now sent over the wire protocol each one actually speaks. Every model was sent over the OpenAI chat-completions adapter, so models on that endpoint speaking other protocols failed or misbehaved.
|
||||
- Task history no longer goes blank when a task spawns many subagents. Subagent rows crowded out the tasks that created them, hiding the parent task and everything older.
|
||||
- Langfuse tracing, when configured, is now limited to the Cline and Cline Pass providers. The provider was ignored, so prompts and responses sent to third-party and bring-your-own-key providers were exported too.
|
||||
|
||||
### Changed
|
||||
|
||||
- Web search is now enabled by default on models that support it, outside YOLO mode. It can still be turned off in settings, and a settings file that cannot be read leaves it disabled rather than silently on.
|
||||
- The `run_commands` tool description now names the PowerShell edition in use — `Windows PowerShell (powershell.exe)` versus `PowerShell (pwsh.exe)` — quotes its guidance against that executable, and tells the model to run commands directly rather than wrapping them in another shell invocation. It also no longer describes the environment as Windows when `pwsh` is the configured shell on macOS or Linux.
|
||||
- Refreshed the built-in model catalog. Adds four providers (Infer by Flow7, Melious, NaN, and Wallaby) and takes the catalog from 5,788 to 6,079 models. This is a wide refresh: the resolved default model changes for 44 providers, most of them landing on DeepSeek V4.1 Flash — among them Hugging Face, Fireworks, Requesty, Nebius, Cortecs, CrossModel, DigitalOcean, Eden AI, and OpenCode Go. Gemini and Vertex now resolve to Gemini 3.8 Flash, GitHub Copilot and Vivgrid to GPT-6 Astra, and NVIDIA to GLM 5.3 Flash. If you use a provider without pinning a model, expect a different default.
|
||||
|
||||
## [4.1.17]
|
||||
|
||||
Everything here lands through the SDK bundle, so it applies to windows running that bundle.
|
||||
|
||||
@@ -63,7 +63,7 @@ Cline as a native app for macOS and Windows.
|
||||
Run agent sessions in any folder, schedule
|
||||
routines, and manage models, plugins, and MCP servers.
|
||||
|
||||
<a href="https://github.com/cline/cline/releases?q=desktop-v&expanded=true">Download for macOS and Windows</a>
|
||||
<a href="https://cline.bot/desktop">Download for macOS and Windows</a>
|
||||
<br><br>
|
||||
|
||||
</td>
|
||||
@@ -182,7 +182,7 @@ const deployTool = createTool({
|
||||
|
||||
const agent = new Agent({ tools: [deployTool], /* ... */ })
|
||||
```
|
||||
...or use [MCP servers](https://github.com/modelcontextprotocol) to connect to databases, query APIs, manage cloud infrastructure, and interact with external systems. Use [community-built servers](https://github.com/modelcontextprotocol/servers) or ask Cline to create custom tools on the fly. In the CLI, manage servers with `cline mcp`.
|
||||
...or use [MCPs](https://github.com/modelcontextprotocol) to connect to databases, query APIs, manage cloud infrastructure, and interact with external systems. Use [community-built servers](https://github.com/modelcontextprotocol/servers) or ask Cline to create custom tools on the fly. In the CLI, manage servers with `cline mcp`.
|
||||
|
||||
## Multi-Agent Teams
|
||||
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# Cline CLI Changelog
|
||||
|
||||
## 3.0.62
|
||||
|
||||
- Introducing Cline Desktop: a native app for working with open-weight models, with task import from Claude Code and Codex, scheduled runs, web search and voice input, and a marketplace for plugins, MCP servers, and skills. The CLI now shows a one-time startup notice pointing at cline.bot/desktop. At most one notice appears per launch, and `CLINE_DISABLE_CLINE_PASS_NOTICE=1` still suppresses all of them
|
||||
- Agent Plugins are now managed through the Hub. Packages under `~/.agents/plugins/*` are discovered and validated, their skills are exposed through the skills tool as `plugin-name:skill-name`, and their MCP servers start without touching `cline_mcp_settings.json`. The config screen lists them separately from Cline Plugins and Space toggles them. Workspace `.agents/plugins` directories are deliberately not scanned, so opening a repo cannot implicitly start repo-controlled MCP servers
|
||||
- A model turn that dies mid-stream with a transient provider error is now retried up to 3 times with backoff instead of failing the run — a single forwarded 429 from OpenRouter previously ended the run with exit 1. A turn that already streamed output is never retried, so nothing is duplicated
|
||||
- Streaming output is no longer throttled by the Hub. Every streamed token was proxied to client hooks as a round trip carrying a full copy of the session, with the agent loop waiting on it
|
||||
- Checkpoints no longer stall every message in workspaces with large untracked directories. Each turn re-hashed every untracked file before the model call, which on multi-GB workspaces blocked messages for seconds to minutes; a persistent per-session snapshot index now lets git skip unchanged files
|
||||
- Fixed `run_commands` hanging until timeout after a command that backgrounds a child process. The command had finished, but the backgrounded child held the output pipes open
|
||||
- Fixed `cline` being OOM-killed when run from your home directory. Typing an `@` mention indexed every file under `$HOME` and re-ranked it on each keystroke
|
||||
- Fixed `apply_patch` silently overwriting an existing file when the model used "Add File" on a path that already exists
|
||||
- Fixed PowerShell commands that the model wrapped in another `powershell -Command "..."` being parsed twice, which stripped `$_` out of pipelines and produced an error per enumerated item while still reporting success. The tool description now also names which PowerShell edition is in use and tells the model not to wrap commands
|
||||
- API keys pasted with an invisible character (BOM, zero-width space) are now cleaned before being saved. They were stored corrupted and the provider's 401 was indistinguishable from a wrong key
|
||||
- Signing in with Claude Code no longer demands an API key it never reads. It authenticates from the `claude` CLI's own credential store, but onboarding treated it as an API-key provider and dropped you into the sign-in wizard; the workaround was storing a dummy key. A missing `claude` on PATH now warns instead of blocking, since a configured path, bundled binary, or npx also works. OpenCode gets the same local-CLI treatment
|
||||
- Web search is now on by default in non-yolo sessions on models that support it
|
||||
- A running Hub on the same core version as your CLI no longer prompts you to update it. Anyone with both the desktop app and the CLI installed saw a "Cline Hub was updated" dialog on every launch that could never resolve
|
||||
- Scheduled runs no longer stall behind each other — one long turn blocked dispatch of every other schedule. Parallelism limits are now enforced at claim time, work resumed after system sleep is no longer started twice, and a schedule created without a timezone uses your local one instead of an implicit default
|
||||
- Session history no longer goes blank when a session spawns many subagents. Child rows crowded out the roots, hiding the parent session and everything older
|
||||
- Fixed TUI toasts being clipped to their first line. The Hub messages that use them are all longer than that, so the keep-Hub reminder never showed the `cline hub upgrade` command it exists to deliver
|
||||
- Cline Pass now defaults to a subscribed model instead of a free one. Its model list mixes both tiers and the default was whichever model shipped most recently, so subscribers who never picked a model were put on the free tier
|
||||
- Cline Pass and free models now show zero cost instead of the upstream market price for requests you are not billed per token for
|
||||
- Model pickers now fall back to the full Recommended, Free, and Subscribed tiers when the models endpoint is unreachable. Previously the offline fallback was six hardcoded models with no subscribed tier at all
|
||||
- The OpenAI Codex (ChatGPT subscription) model list no longer includes models the backend rejects, and Codex context limits are applied to every Codex model instead of being inherited from the OpenAI API catalog, which was inflating the context budget and the usage math
|
||||
- Model lists for all shared-catalog providers now refresh from the live catalog, so newly published models appear without a CLI update, with timeouts so a hung provider endpoint cannot stall the list
|
||||
- Cline Pass now shows as a configured provider after sign-in — it stores credentials under Cline, so one sign-in configured both but only Cline appeared
|
||||
- Fixed OpenCode Go serving several wire protocols behind one URL while every model was sent over the OpenAI chat-completions adapter
|
||||
- Collapsed a nested `undici@5.29.0` (CVE-2026-1525) onto 7.x. The earlier remediation's version-scoped override key was silently ignored by Bun, so a vulnerable copy survived
|
||||
- Refreshed the model catalog. Adds four providers (Infer by Flow7, Melious, NaN, and Wallaby) and takes the bundled catalog from 5,788 to 6,079 models. This is a wide refresh: the resolved default model changes for 44 providers, most of them landing on DeepSeek V4.1 Flash — among them Hugging Face, Fireworks, Requesty, Nebius, Cortecs, CrossModel, DigitalOcean, Eden AI, and OpenCode Go. Gemini and Vertex now resolve to Gemini 3.8 Flash, GitHub Copilot and Vivgrid to GPT-6 Astra, and NVIDIA to GLM 5.3 Flash. If you use any provider without pinning a model, expect a different default
|
||||
|
||||
## 3.0.61
|
||||
|
||||
- Cline now handles a running Hub that is older than your CLI. Instead of quietly talking to a hub executing stale code, you get a prompt showing how many active sessions a replacement would interrupt, with enter-to-replace or escape-to-keep. The replacement drains the Hub first so in-flight turns finish, and a hub too old or wedged to accept the drain is left alone rather than killed
|
||||
|
||||
@@ -109,6 +109,12 @@ const result = await Bun.build({
|
||||
"OTEL_METRICS_EXPORTER",
|
||||
),
|
||||
"process.env.OTEL_LOGS_EXPORTER": defineProcessEnv("OTEL_LOGS_EXPORTER"),
|
||||
"process.env.OTEL_TRACES_EXPORTER": defineProcessEnv(
|
||||
"OTEL_TRACES_EXPORTER",
|
||||
),
|
||||
"process.env.CLINE_TRACE_RECORD_CONTENT": defineProcessEnv(
|
||||
"CLINE_TRACE_RECORD_CONTENT",
|
||||
),
|
||||
"process.env.OTEL_EXPORTER_OTLP_PROTOCOL": defineProcessEnv(
|
||||
"OTEL_EXPORTER_OTLP_PROTOCOL",
|
||||
),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@cline/cli",
|
||||
"displayName": "cline",
|
||||
"version": "3.0.61",
|
||||
"version": "3.0.62",
|
||||
"description": "Autonomous coding agent CLI - capable of creating/editing files, running commands, using the browser, and more",
|
||||
"type": "module",
|
||||
"publishConfig": {
|
||||
|
||||
@@ -32,6 +32,9 @@ const BUILD_TIME_INLINED_ENV_VARS = [
|
||||
"OTEL_TELEMETRY_ENABLED",
|
||||
"OTEL_LOGS_EXPORTER",
|
||||
"OTEL_METRICS_EXPORTER",
|
||||
"OTEL_TRACES_EXPORTER",
|
||||
"CLINE_TRACE_SAMPLE_PERCENT",
|
||||
"CLINE_TRACE_RECORD_CONTENT",
|
||||
"OTEL_EXPORTER_OTLP_PROTOCOL",
|
||||
"OTEL_EXPORTER_OTLP_ENDPOINT",
|
||||
"OTEL_EXPORTER_OTLP_HEADERS",
|
||||
|
||||
@@ -4,6 +4,7 @@ import { isMainThread } from "node:worker_threads";
|
||||
import {
|
||||
claimHubDaemonProcess,
|
||||
claimSupervisedConnectorProcess,
|
||||
disableCurrentDirectoryExecutableSearch,
|
||||
disposeAll,
|
||||
initVcr,
|
||||
setConnectorCliLaunchSpec,
|
||||
@@ -21,6 +22,9 @@ import { writeErr } from "./utils/output";
|
||||
// Set CLINE_VCR=record|playback and CLINE_VCR_CASSETTE=<path> to enable.
|
||||
initVcr(process.env.CLINE_VCR);
|
||||
|
||||
// Before any personality below can spawn a child with the workspace as cwd.
|
||||
disableCurrentDirectoryExecutableSearch();
|
||||
|
||||
if (!isMainThread) {
|
||||
// Worker imports of the bundled CLI entrypoint should not start the CLI.
|
||||
} else if (claimHubDaemonProcess()) {
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
// @jsxImportSource @opentui/react
|
||||
import type { ChoiceContext } from "@opentui-ui/dialog";
|
||||
import { useDialogKeyboard } from "@opentui-ui/dialog/react";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { useCallback, useState } from "react";
|
||||
import { useDialogPalette } from "../tui/hooks/use-theme";
|
||||
import {
|
||||
type DialogDismissKey,
|
||||
isAnyKeyDismiss,
|
||||
} from "../tui/utils/dialog-keys";
|
||||
import { getCliSubscriptionUrl } from "../utils/cline-pass-errors";
|
||||
import open from "../utils/open";
|
||||
import type { CliMigrationNotice } from "./notice";
|
||||
|
||||
/**
|
||||
* Enter opens the subscription page; any other (unmodified) key dismisses the
|
||||
* Enter opens the notice's page; any other (unmodified) key dismisses the
|
||||
* dialog; modifier-held keys are ignored.
|
||||
*
|
||||
* The dialog used to be dismissible only with Esc, but Esc is the least
|
||||
@@ -20,7 +19,7 @@ import type { CliMigrationNotice } from "./notice";
|
||||
* timeout disambiguation, and Windows console input layers are known to
|
||||
* swallow it), which left users stuck behind the promo with no way out.
|
||||
* Modifier-held keys are ignored so that holding Cmd/Ctrl to click the
|
||||
* subscription link never dismisses the dialog mid-click.
|
||||
* link never dismisses the dialog mid-click.
|
||||
*/
|
||||
export function resolveMigrationNoticeKeyAction(
|
||||
key: DialogDismissKey,
|
||||
@@ -36,27 +35,26 @@ export function MigrationNoticeContent(
|
||||
) {
|
||||
const { dialogId, notice, resolve } = props;
|
||||
const palette = useDialogPalette();
|
||||
const subscriptionUrl = useMemo(() => getCliSubscriptionUrl(), []);
|
||||
const [status, setStatus] = useState<string | undefined>();
|
||||
|
||||
const openSubscriptionPage = useCallback(() => {
|
||||
setStatus("Opening ClinePass in your browser...");
|
||||
void open(subscriptionUrl, { wait: false })
|
||||
const openNoticePage = useCallback(() => {
|
||||
setStatus("Opening in your browser...");
|
||||
void open(notice.url, { wait: false })
|
||||
.then(() => {
|
||||
setStatus("Opened ClinePass in your browser.");
|
||||
setStatus("Opened in your browser.");
|
||||
})
|
||||
.catch(() => {
|
||||
setStatus(
|
||||
"Could not open the browser automatically. Use the URL below.",
|
||||
);
|
||||
});
|
||||
}, [subscriptionUrl]);
|
||||
}, [notice.url]);
|
||||
|
||||
useDialogKeyboard((key) => {
|
||||
const action = resolveMigrationNoticeKeyAction(key);
|
||||
if (action === "ignore") return;
|
||||
if (action === "open") {
|
||||
openSubscriptionPage();
|
||||
openNoticePage();
|
||||
return;
|
||||
}
|
||||
resolve(true);
|
||||
@@ -66,20 +64,20 @@ export function MigrationNoticeContent(
|
||||
<box flexDirection="column" paddingX={1} gap={1}>
|
||||
<text fg={palette.act}>{notice.title}</text>
|
||||
<box flexDirection="column">
|
||||
<text selectable>
|
||||
ClinePass is a $9.99/month subscription plan to get access to the
|
||||
latest open-weight coding models with enough quota for day-to-day
|
||||
work, at a much lower cost than paying API costs directly.
|
||||
</text>
|
||||
{notice.body.split("\n").map((line) => (
|
||||
<text key={line} selectable>
|
||||
{line}
|
||||
</text>
|
||||
))}
|
||||
</box>
|
||||
<box flexDirection="row">
|
||||
<text fg={palette.act} selectable>
|
||||
<a href={subscriptionUrl}>{subscriptionUrl}</a>
|
||||
<a href={notice.url}>{notice.url}</a>
|
||||
</text>
|
||||
</box>
|
||||
<box flexDirection="row">
|
||||
<box paddingX={1} backgroundColor={palette.act}>
|
||||
<text fg={palette.textOnSelection}>Open ClinePass</text>
|
||||
<text fg={palette.textOnSelection}>{notice.openLabel}</text>
|
||||
</box>
|
||||
</box>
|
||||
{status && <text fg={palette.muted}>{status}</text>}
|
||||
|
||||
@@ -55,11 +55,42 @@ describe("migration notice", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("does not show after the notice is marked as shown", () => {
|
||||
it("does not show after every notice is marked as shown", () => {
|
||||
const dataDir = createTempDataDir();
|
||||
|
||||
markClineCliMigrationNoticeShown(dataDir);
|
||||
markClineCliMigrationNoticeShown(dataDir, "cline-cli-desktop-launch");
|
||||
|
||||
expect(getClineCliMigrationNotice(dataDir)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("shows the desktop launch notice once the ClinePass intro was shown", () => {
|
||||
const dataDir = createTempDataDir();
|
||||
|
||||
markClineCliMigrationNoticeShown(dataDir);
|
||||
|
||||
const notice = getClineCliMigrationNotice(dataDir);
|
||||
expect(notice?.id).toBe("cline-cli-desktop-launch");
|
||||
expect(notice?.url).toBe("https://cline.bot/desktop");
|
||||
});
|
||||
|
||||
it("shows only one notice per launch", () => {
|
||||
const dataDir = createTempDataDir();
|
||||
|
||||
expect(getClineCliMigrationNotice(dataDir)?.id).toBe(
|
||||
"cline-cli-cline-pass-intro",
|
||||
);
|
||||
});
|
||||
|
||||
it("marks the desktop launch notice as shown by id", () => {
|
||||
const dataDir = createTempDataDir();
|
||||
|
||||
markClineCliMigrationNoticeShown(dataDir);
|
||||
markClineCliMigrationNoticeShown(dataDir, "cline-cli-desktop-launch");
|
||||
|
||||
const rawState = readFileSync(resolveCliNoticeStatePath(dataDir), "utf8");
|
||||
expect(rawState).toContain('"cline-cli-cline-pass-intro": true');
|
||||
expect(rawState).toContain('"cline-cli-desktop-launch": true');
|
||||
expect(getClineCliMigrationNotice(dataDir)).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -85,7 +116,7 @@ describe("migration notice", () => {
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not show when ClinePass is already the active provider", () => {
|
||||
it("does not show the ClinePass intro when ClinePass is already the active provider", () => {
|
||||
const dataDir = createTempDataDir();
|
||||
|
||||
expect(
|
||||
@@ -93,8 +124,8 @@ describe("migration notice", () => {
|
||||
dataDir,
|
||||
{},
|
||||
{ activeProviderId: "cline-pass" },
|
||||
),
|
||||
).toBeUndefined();
|
||||
)?.id,
|
||||
).toBe("cline-cli-desktop-launch");
|
||||
});
|
||||
|
||||
it("suppresses the active ClinePass provider even when the provider id has surrounding whitespace", () => {
|
||||
@@ -141,6 +172,8 @@ describe("migration notice", () => {
|
||||
|
||||
const rawState = readFileSync(resolveCliNoticeStatePath(dataDir), "utf8");
|
||||
expect(rawState).toContain("cline-cli-cline-pass-intro");
|
||||
expect(getClineCliMigrationNotice(dataDir)).toBeUndefined();
|
||||
expect(getClineCliMigrationNotice(dataDir)?.id).not.toBe(
|
||||
"cline-cli-cline-pass-intro",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,20 +1,54 @@
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { resolveClineDataDir } from "@cline/shared/storage";
|
||||
import { getCliSubscriptionUrl } from "../utils/cline-pass-errors";
|
||||
|
||||
const NOTICE_ID = "cline-cli-cline-pass-intro";
|
||||
export const CLINE_PASS_NOTICE_ID = "cline-cli-cline-pass-intro";
|
||||
const DESKTOP_NOTICE_ID = "cline-cli-desktop-launch";
|
||||
const FORCE_NOTICE_ENV = "CLINE_FORCE_CLINE_PASS_NOTICE";
|
||||
// Historically named for the ClinePass promo; disables every startup notice.
|
||||
const DISABLE_NOTICE_ENV = "CLINE_DISABLE_CLINE_PASS_NOTICE";
|
||||
const DESKTOP_APP_URL = "https://cline.bot/desktop";
|
||||
|
||||
export interface CliMigrationNotice {
|
||||
id: string;
|
||||
title: string;
|
||||
body: string;
|
||||
url: string;
|
||||
openLabel: string;
|
||||
}
|
||||
|
||||
export interface CliMigrationNoticeOptions {
|
||||
activeProviderId?: string;
|
||||
}
|
||||
|
||||
function getClinePassNotice(): CliMigrationNotice {
|
||||
return {
|
||||
id: CLINE_PASS_NOTICE_ID,
|
||||
title: "Try ClinePass",
|
||||
body: "ClinePass is a $9.99/month subscription plan to get access to the latest open-weight coding models with enough quota for day-to-day work, at a much lower cost than paying API costs directly.",
|
||||
url: getCliSubscriptionUrl(),
|
||||
openLabel: "Open ClinePass",
|
||||
};
|
||||
}
|
||||
|
||||
function getDesktopNotice(): CliMigrationNotice {
|
||||
return {
|
||||
id: DESKTOP_NOTICE_ID,
|
||||
title: "Introducing Cline Desktop",
|
||||
body: [
|
||||
"A native app for working with open weights models. Use it with ClinePass and our free models, or BYOK.",
|
||||
"- Import tasks from Claude Code and Codex",
|
||||
"- Run Cline on a regular schedule",
|
||||
"- Use web search tool and voice input",
|
||||
"- Browse Marketplace for plugins, MCPs, and skills",
|
||||
"Available for macOS and Windows.",
|
||||
].join("\n"),
|
||||
url: DESKTOP_APP_URL,
|
||||
openLabel: "Get Cline Desktop",
|
||||
};
|
||||
}
|
||||
|
||||
interface CliNoticeState {
|
||||
shown: Record<string, boolean>;
|
||||
}
|
||||
@@ -84,32 +118,33 @@ export function getClineCliMigrationNotice(
|
||||
if (disableNotice && !forceNotice) {
|
||||
return undefined;
|
||||
}
|
||||
// At most one notice per launch, oldest first, so a user who has already
|
||||
// dismissed the ClinePass intro sees the desktop launch on their next start.
|
||||
if (
|
||||
shouldSuppressClineCliMigrationNoticeForActiveProvider(
|
||||
!shouldSuppressClineCliMigrationNoticeForActiveProvider(
|
||||
options.activeProviderId,
|
||||
env,
|
||||
)
|
||||
) &&
|
||||
(forceNotice || !noticeState.shown[CLINE_PASS_NOTICE_ID])
|
||||
) {
|
||||
return undefined;
|
||||
return getClinePassNotice();
|
||||
}
|
||||
if (noticeState.shown[NOTICE_ID] && !forceNotice) {
|
||||
return undefined;
|
||||
if (!noticeState.shown[DESKTOP_NOTICE_ID]) {
|
||||
return getDesktopNotice();
|
||||
}
|
||||
return {
|
||||
id: NOTICE_ID,
|
||||
title: "Try ClinePass",
|
||||
};
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function markClineCliMigrationNoticeShown(
|
||||
dataDir = resolveClineDataDir(),
|
||||
noticeId = CLINE_PASS_NOTICE_ID,
|
||||
): void {
|
||||
const noticePath = resolveCliNoticeStatePath(dataDir);
|
||||
const noticeState = readNoticeState(noticePath);
|
||||
const nextState: CliNoticeState = {
|
||||
shown: {
|
||||
...noticeState.shown,
|
||||
[NOTICE_ID]: true,
|
||||
[noticeId]: true,
|
||||
},
|
||||
};
|
||||
mkdirSync(dirname(noticePath), { recursive: true, mode: 0o700 });
|
||||
|
||||
@@ -165,8 +165,14 @@ vi.mock("./runtime/run-interactive", () => {
|
||||
vi.mock("./utils/session", () => sessionMocks);
|
||||
vi.mock("./session/session", () => sessionMocks);
|
||||
vi.mock("@cline/core", async () => {
|
||||
// Keep dispatch tests independent of the full SDK runtime import graph.
|
||||
// Only persisted-settings behavior needs its real implementation here.
|
||||
const { readGlobalSettings } = await vi.importActual<
|
||||
typeof import("../../../sdk/packages/core/src/services/global-settings")
|
||||
>("../../../sdk/packages/core/src/services/global-settings");
|
||||
return {
|
||||
...(await vi.importActual("@cline/core")),
|
||||
readGlobalSettings,
|
||||
setSdkLogger: vi.fn(),
|
||||
resolveProviderConfig: llmMocks.resolveProviderConfig,
|
||||
createTeamName: vi.fn(() => "team-test"),
|
||||
createUserInstructionConfigService: vi.fn(() => ({
|
||||
@@ -787,6 +793,9 @@ describe("runCli lightweight command dispatch", () => {
|
||||
const notice = {
|
||||
id: "cline-cli-cline-pass-intro",
|
||||
title: "Try ClinePass",
|
||||
body: "ClinePass body",
|
||||
url: "https://app.cline.bot/dashboard/subscription?personal=true",
|
||||
openLabel: "Open ClinePass",
|
||||
};
|
||||
migrationNoticeMocks.getClineCliMigrationNotice.mockReturnValue(notice);
|
||||
process.argv = ["bun", "src/index.ts"];
|
||||
@@ -810,7 +819,7 @@ describe("runCli lightweight command dispatch", () => {
|
||||
await options?.onInitialNoticeShown?.(notice);
|
||||
expect(
|
||||
migrationNoticeMocks.markClineCliMigrationNoticeShown,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
).toHaveBeenCalledWith(undefined, notice.id);
|
||||
});
|
||||
|
||||
it("passes the active ClinePass provider into the migration notice gate", async () => {
|
||||
@@ -1171,6 +1180,9 @@ describe("runCli lightweight command dispatch", () => {
|
||||
migrationNoticeMocks.getClineCliMigrationNotice.mockReturnValue({
|
||||
id: "cline-cli-cline-pass-intro",
|
||||
title: "Try ClinePass",
|
||||
body: "ClinePass body",
|
||||
url: "https://app.cline.bot/dashboard/subscription?personal=true",
|
||||
openLabel: "Open ClinePass",
|
||||
});
|
||||
process.argv = ["bun", "src/index.ts", "history"];
|
||||
|
||||
|
||||
@@ -1198,8 +1198,8 @@ export async function runCli(): Promise<void> {
|
||||
activeProviderId: provider,
|
||||
});
|
||||
if (initialNotice) {
|
||||
markInitialNoticeShown = () => {
|
||||
markClineCliMigrationNoticeShown();
|
||||
markInitialNoticeShown = (notice) => {
|
||||
markClineCliMigrationNoticeShown(undefined, notice.id);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,27 +14,6 @@ export function resolveHubUpdateRequiredKeyAction(
|
||||
return "ignore";
|
||||
}
|
||||
|
||||
/**
|
||||
* Human phrase for the live work an outdated Hub is serving, used by the
|
||||
* "Hub update required" dialog. Falls back to an unquantified phrase when the
|
||||
* Hub could not answer the activity query.
|
||||
*/
|
||||
export function describeOutdatedHubSessions(counts: {
|
||||
activeSessionCount?: number;
|
||||
participantClientCount?: number;
|
||||
}): string {
|
||||
const sessions = counts.activeSessionCount;
|
||||
if (typeof sessions !== "number" || sessions <= 0) {
|
||||
return "active sessions from other Cline clients";
|
||||
}
|
||||
const sessionsPhrase = `${sessions} active session${sessions === 1 ? "" : "s"}`;
|
||||
const clients = counts.participantClientCount;
|
||||
if (typeof clients !== "number" || clients <= 0) {
|
||||
return sessionsPhrase;
|
||||
}
|
||||
return `${sessionsPhrase} from ${clients} connected Cline client${clients === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Yolo and sandbox sessions force the local backend and never attach to the
|
||||
* shared managed Hub (see the forceLocalBackend condition in the interactive
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
// @jsxImportSource @opentui/react
|
||||
import { describeOutdatedHubSessions } from "@cline/shared";
|
||||
import type { ChoiceContext } from "@opentui-ui/dialog";
|
||||
import { useDialogKeyboard } from "@opentui-ui/dialog/react";
|
||||
import { useDialogPalette } from "../../hooks/use-theme";
|
||||
import {
|
||||
describeOutdatedHubSessions,
|
||||
resolveHubUpdateRequiredKeyAction,
|
||||
} from "./hub-update-required-helpers";
|
||||
import { resolveHubUpdateRequiredKeyAction } from "./hub-update-required-helpers";
|
||||
|
||||
export interface HubUpdateRequiredDetails {
|
||||
hubCoreVersion?: string;
|
||||
|
||||
@@ -36,7 +36,7 @@ export function QueuedPrompts(props: {
|
||||
? "Waiting. ↑/↓ navigate, Tab edit, Esc cancels turn"
|
||||
: `Steered next. ↑/↓ navigate, Tab edit, ${escapeHint}`
|
||||
: `↑/↓ navigate, Enter steer, Tab edit, ${escapeHint}`
|
||||
: "↑ steer or edit messages";
|
||||
: "Enter with empty input to steer first · ↑ select or edit";
|
||||
|
||||
return (
|
||||
<box
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { KeyEvent } from "@opentui/core";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { useRootKeyboard } from "./use-root-keyboard";
|
||||
import { shouldHandleInputHistory } from "./root-keyboard-routing";
|
||||
|
||||
describe("root keyboard input history routing", () => {
|
||||
@@ -29,3 +31,58 @@ describe("root keyboard input history routing", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
const keyboard = vi.hoisted(() => ({ handle: (_key: KeyEvent) => {} }));
|
||||
vi.mock("@opentui/react", () => ({
|
||||
useKeyboard: (handle: (key: KeyEvent) => void) => {
|
||||
keyboard.handle = handle;
|
||||
},
|
||||
}));
|
||||
vi.mock("react", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("react")>()),
|
||||
useRef: (current: unknown) => ({ current }),
|
||||
}));
|
||||
vi.mock("../contexts/session-context", () => ({
|
||||
useSession: () => ({ isRunning: true, isExitRequested: false }),
|
||||
}));
|
||||
|
||||
describe("empty-input queue steering", () => {
|
||||
it.each([
|
||||
{ text: "", shift: false, promote: true },
|
||||
{ text: " ", shift: false, promote: true },
|
||||
{ text: "new draft", shift: false, promote: false },
|
||||
{ text: "", shift: true, promote: false },
|
||||
])("routes Enter with $text and shift=$shift", ({ text, shift, promote }) => {
|
||||
const promotePrompt = vi.fn();
|
||||
useRootKeyboard({
|
||||
isDialogOpen: false,
|
||||
appView: "chat",
|
||||
autocomplete: { mode: false },
|
||||
transcriptScrollRef: { current: null },
|
||||
getCurrentInputText: () => text,
|
||||
queuedPromptSelection: {
|
||||
items: [
|
||||
{ id: "first", prompt: "first", steer: false, attachmentCount: 0 },
|
||||
{ id: "second", prompt: "second", steer: false, attachmentCount: 0 },
|
||||
],
|
||||
selectedId: null,
|
||||
editingId: null,
|
||||
promote: promotePrompt,
|
||||
},
|
||||
} as unknown as Parameters<typeof useRootKeyboard>[0]);
|
||||
const preventDefault = vi.fn();
|
||||
keyboard.handle({
|
||||
name: "return",
|
||||
ctrl: false,
|
||||
meta: false,
|
||||
shift,
|
||||
repeated: false,
|
||||
preventDefault,
|
||||
} as unknown as KeyEvent);
|
||||
expect(promotePrompt).toHaveBeenCalledTimes(promote ? 1 : 0);
|
||||
if (promote) {
|
||||
expect(promotePrompt).toHaveBeenCalledWith("first");
|
||||
expect(preventDefault).toHaveBeenCalledOnce();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -209,6 +209,22 @@ export function useRootKeyboard(input: {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!hasInputText &&
|
||||
hasQueuedPrompts &&
|
||||
!key.shift &&
|
||||
!key.ctrl &&
|
||||
!key.meta &&
|
||||
(key.name === "enter" || key.name === "return")
|
||||
) {
|
||||
key.preventDefault();
|
||||
const firstPrompt = queuedSelection.items[0];
|
||||
if (firstPrompt && !firstPrompt.steer && !key.repeated) {
|
||||
queuedSelection.promote(firstPrompt.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.name === "up" && canHandleInputHistory) {
|
||||
if (
|
||||
input.inputHistory.navigateHistory("up", input.inputValueRef.current)
|
||||
|
||||
@@ -15,7 +15,10 @@ import {
|
||||
useDialogState,
|
||||
} from "@opentui-ui/dialog/react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { shouldSuppressClineCliMigrationNoticeForActiveProvider } from "../kanban-migration/notice";
|
||||
import {
|
||||
CLINE_PASS_NOTICE_ID,
|
||||
shouldSuppressClineCliMigrationNoticeForActiveProvider,
|
||||
} from "../kanban-migration/notice";
|
||||
import { MigrationNoticeContent } from "../kanban-migration/notice-dialog";
|
||||
import {
|
||||
isSameRepoStatus,
|
||||
@@ -552,6 +555,7 @@ function App(props: TuiProps) {
|
||||
if (initialNoticeShownRef.current) return;
|
||||
if (appView !== "home") return;
|
||||
if (
|
||||
notice.id === CLINE_PASS_NOTICE_ID &&
|
||||
shouldSuppressClineCliMigrationNoticeForActiveProvider(currentProviderId)
|
||||
) {
|
||||
initialNoticeShownRef.current = true;
|
||||
|
||||
@@ -106,7 +106,7 @@ function renderDevIndexHtml(devServerUrl: string): string {
|
||||
window.__vite_plugin_react_preamble_installed__ = true;
|
||||
</script>
|
||||
<script type="module" src="${devServerUrl}/@vite/client"></script>
|
||||
<link rel="icon" type="image/svg+xml" href="${devServerUrl}/cline-logo-filled.svg" />
|
||||
<link rel="icon" type="image/svg+xml" href="${devServerUrl}/favicon.svg" />
|
||||
<title>Cline Hub</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/cline-logo-filled.svg" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Cline Hub</title>
|
||||
</head>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.7 KiB |
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg id="Ebene_1" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 466.73 487.04">
|
||||
<!-- Generator: Adobe Illustrator 29.8.1, SVG Export Plug-In . SVG Version: 2.1.1 Build 2) -->
|
||||
<path d="M463.6,275.08l-29.26-58.75v-33.83c0-56.08-45.01-101.5-100.53-101.5h-50.01c3.62-7.43,5.61-15.79,5.61-24.61,0-31.17-25.08-56.39-56.07-56.39s-56.07,25.22-56.07,56.39c0,8.82,1.99,17.17,5.61,24.61h-50.01c-55.51,0-100.52,45.42-100.52,101.5v33.83l-29.87,58.59c-3.01,5.9-3.01,12.92,0,18.81l29.87,57.93v33.83c0,56.08,45.01,101.5,100.52,101.5h200.95c55.51,0,100.53-45.42,100.53-101.5v-33.83l29.21-58.13c2.9-5.79,2.9-12.61.05-18.46ZM202.75,322.96c0,25.48-20.54,46.14-45.88,46.14s-45.88-20.66-45.88-46.14v-82.02c0-25.48,20.54-46.14,45.88-46.14s45.88,20.66,45.88,46.14v82.02ZM350.58,322.96c0,25.48-20.54,46.14-45.88,46.14s-45.88-20.66-45.88-46.14v-82.02c0-25.48,20.54-46.14,45.88-46.14s45.88,20.66,45.88,46.14v82.02Z"/>
|
||||
</svg>
|
||||
<svg width="113" height="113" viewBox="0 0 113 113" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M56.4998 8.99805L56.4999 5.29805H56.4998V8.99805ZM68.4998 20.708L72.1998 20.7081V20.708H68.4998ZM67.9929 25L64.3662 24.2671L63.4704 28.7H67.9929V25ZM84.4998 25L84.4998 21.3H84.4998V25ZM95.7 49.7998H92V51.2066L92.9346 52.258L95.7 49.7998ZM108.027 63.667L110.793 61.2088L110.792 61.2088L108.027 63.667ZM108.027 64.7305L110.792 67.1887L110.793 67.1883L108.027 64.7305ZM95.7 78.5977L92.9346 76.1394L92 77.1909V78.5977H95.7ZM95.7 92.2002L99.3999 92.2002V92.2002H95.7ZM84.4998 103.4V107.1H84.4998L84.4998 103.4ZM17.2996 92.2002H13.5996V92.2002L17.2996 92.2002ZM17.2996 78.5986H20.9996V77.1918L20.0649 76.1404L17.2996 78.5986ZM4.97144 64.7305L2.20602 67.1886L2.20611 67.1887L4.97144 64.7305ZM4.97144 63.667L7.73685 66.1251L7.73685 66.1251L4.97144 63.667ZM17.2996 49.7979L20.065 52.256L20.9996 51.2046V49.7979H17.2996ZM45.0066 25V28.7H49.5292L48.6333 24.267L45.0066 25ZM44.4998 20.708H40.7998V20.7081L44.4998 20.708ZM56.4998 8.99805L56.4996 12.698C61.1812 12.6982 64.7998 16.3247 64.7998 20.708H68.4998H72.1998C72.1998 12.0452 65.0728 5.29829 56.4999 5.29805L56.4998 8.99805ZM68.4998 20.708L64.7998 20.7079C64.7997 21.6154 64.6614 22.8066 64.3662 24.2671L67.9929 25L71.6196 25.7329C71.969 24.004 72.1997 22.2864 72.1998 20.7081L68.4998 20.708ZM67.9929 25V28.7H84.4998V25V21.3H67.9929V25ZM84.4998 25L84.4997 28.7C88.6419 28.7001 92 32.0582 92 36.2002H95.7H99.3999C99.3999 27.9712 92.7287 21.3001 84.4998 21.3L84.4998 25ZM95.7 36.2002H92V49.7998H95.7H99.3999V36.2002H95.7ZM95.7 49.7998L92.9346 52.258L105.262 66.1252L108.027 63.667L110.792 61.2088L98.4653 47.3416L95.7 49.7998ZM108.027 63.667L105.262 66.1251C104.285 65.026 104.285 63.371 105.261 62.2727L108.027 64.7305L110.793 67.1883C112.308 65.4837 112.308 62.9141 110.793 61.2088L108.027 63.667ZM108.027 64.7305L105.262 62.2722L92.9346 76.1394L95.7 78.5977L98.4653 81.0559L110.792 67.1887L108.027 64.7305ZM95.7 78.5977H92V92.2002H95.7H99.3999V78.5977H95.7ZM95.7 92.2002L92 92.2002C91.9999 96.3422 88.6418 99.7003 84.4997 99.7004L84.4998 103.4L84.4998 107.1C92.7287 107.1 99.3999 100.429 99.3999 92.2002L95.7 92.2002ZM84.4998 103.4V99.7004H28.4998V103.4V107.1H84.4998V103.4ZM28.4998 103.4V99.7004C24.3577 99.7004 20.9996 96.3423 20.9996 92.2002L17.2996 92.2002L13.5996 92.2002C13.5996 100.429 20.2707 107.1 28.4998 107.1V103.4ZM17.2996 92.2002H20.9996V78.5986H17.2996H13.5996V92.2002H17.2996ZM17.2996 78.5986L20.0649 76.1404L7.73676 62.2722L4.97144 64.7305L2.20611 67.1887L14.5342 81.0569L17.2996 78.5986ZM4.97144 64.7305L7.73685 62.2723C8.71353 63.3711 8.71353 65.0264 7.73685 66.1251L4.97144 63.667L2.20602 61.2088C0.690476 62.9138 0.690476 65.4836 2.20602 67.1886L4.97144 64.7305ZM4.97144 63.667L7.73685 66.1251L20.065 52.256L17.2996 49.7979L14.5341 47.3397L2.20602 61.2088L4.97144 63.667ZM17.2996 49.7979H20.9996V36.2002H17.2996H13.5996V49.7979H17.2996ZM17.2996 36.2002H20.9996C20.9996 32.0581 24.3576 28.7 28.4998 28.7V25V21.3C20.2707 21.3 13.5996 27.9712 13.5996 36.2002H17.2996ZM28.4998 25V28.7H45.0066V25V21.3H28.4998V25ZM45.0066 25L48.6333 24.267C48.3381 22.8066 48.1998 21.6154 48.1998 20.7079L44.4998 20.708L40.7998 20.7081C40.7998 22.2864 41.0305 24.0039 41.3799 25.733L45.0066 25ZM44.4998 20.708H48.1998C48.1998 16.3244 51.8182 12.698 56.4998 12.698V8.99805V5.29805C47.9264 5.29805 40.7998 12.0451 40.7998 20.708H44.4998Z" fill="#1C1C24"/>
|
||||
<rect x="66.1001" y="49.8008" width="9.6" height="28.8" rx="4.8" fill="#1C1C24"/>
|
||||
<rect x="37.3" y="49.8008" width="9.6" height="28.8" rx="4.8" fill="#1C1C24"/>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 957 B After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 28 KiB |
@@ -1,16 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="92px" height="96px" viewBox="0 0 92 96" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Group Copy 2</title>
|
||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="icon-copy" transform="translate(-34, -40)" fill="#24292F">
|
||||
<g id="Group-Copy-2" transform="translate(34, 40.5)">
|
||||
<g id="Group-3-Copy-4" transform="translate(0, 0)">
|
||||
<path d="M65.4492701,16.3 C76.3374701,16.3 85.1635558,25.16479 85.1635558,36.1 L85.1635558,42.7 L90.9027661,54.1647464 C91.4694141,55.2966923 91.4668177,56.6300535 90.8957658,57.7597839 L85.1635558,69.1 L85.1635558,75.7 C85.1635558,86.63554 76.3374701,95.5 65.4492701,95.5 L26.0206986,95.5 C15.1328272,95.5 6.30641291,86.63554 6.30641291,75.7 L6.30641291,69.1 L0.448507752,57.7954874 C-0.14693501,56.6464093 -0.149634367,55.2802504 0.441262896,54.1288283 L6.30641291,42.7 L6.30641291,36.1 C6.30641291,25.16479 15.1328272,16.3 26.0206986,16.3 L65.4492701,16.3 Z M62.9301895,22 L29.189529,22 C19.8723267,22 12.3191987,29.5552188 12.3191987,38.875 L12.3191987,44.5 L7.44288578,53.9634655 C6.84794449,55.1180686 6.85066096,56.4896598 7.45017099,57.6418974 L12.3191987,67 L12.3191987,72.625 C12.3191987,81.9450625 19.8723267,89.5 29.189529,89.5 L62.9301895,89.5 C72.2476729,89.5 79.8005198,81.9450625 79.8005198,72.625 L79.8005198,67 L84.5682187,57.6061395 C85.1432011,56.473244 85.1458141,55.1345713 84.5752587,53.9994398 L79.8005198,44.5 L79.8005198,38.875 C79.8005198,29.5552188 72.2476729,22 62.9301895,22 Z" id="Combined-Shape" fill-rule="nonzero"></path>
|
||||
<circle id="Oval" cx="45.7349843" cy="11" r="11"></circle>
|
||||
</g>
|
||||
<rect id="Rectangle-Copy" stroke="#24292F" stroke-width="8" x="31" y="44.5" width="5" height="22" rx="2.5"></rect>
|
||||
<rect id="Rectangle-Copy-2" stroke="#24292F" stroke-width="8" x="55" y="44.5" width="5" height="22" rx="2.5"></rect>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
<svg width="113" height="113" viewBox="0 0 113 113" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M56.4998 8.99805L56.4999 5.29805H56.4998V8.99805ZM68.4998 20.708L72.1998 20.7081V20.708H68.4998ZM67.9929 25L64.3662 24.2671L63.4704 28.7H67.9929V25ZM84.4998 25L84.4998 21.3H84.4998V25ZM95.7 49.7998H92V51.2066L92.9346 52.258L95.7 49.7998ZM108.027 63.667L110.793 61.2088L110.792 61.2088L108.027 63.667ZM108.027 64.7305L110.792 67.1887L110.793 67.1883L108.027 64.7305ZM95.7 78.5977L92.9346 76.1394L92 77.1909V78.5977H95.7ZM95.7 92.2002L99.3999 92.2002V92.2002H95.7ZM84.4998 103.4V107.1H84.4998L84.4998 103.4ZM17.2996 92.2002H13.5996V92.2002L17.2996 92.2002ZM17.2996 78.5986H20.9996V77.1918L20.0649 76.1404L17.2996 78.5986ZM4.97144 64.7305L2.20602 67.1886L2.20611 67.1887L4.97144 64.7305ZM4.97144 63.667L7.73685 66.1251L7.73685 66.1251L4.97144 63.667ZM17.2996 49.7979L20.065 52.256L20.9996 51.2046V49.7979H17.2996ZM45.0066 25V28.7H49.5292L48.6333 24.267L45.0066 25ZM44.4998 20.708H40.7998V20.7081L44.4998 20.708ZM56.4998 8.99805L56.4996 12.698C61.1812 12.6982 64.7998 16.3247 64.7998 20.708H68.4998H72.1998C72.1998 12.0452 65.0728 5.29829 56.4999 5.29805L56.4998 8.99805ZM68.4998 20.708L64.7998 20.7079C64.7997 21.6154 64.6614 22.8066 64.3662 24.2671L67.9929 25L71.6196 25.7329C71.969 24.004 72.1997 22.2864 72.1998 20.7081L68.4998 20.708ZM67.9929 25V28.7H84.4998V25V21.3H67.9929V25ZM84.4998 25L84.4997 28.7C88.6419 28.7001 92 32.0582 92 36.2002H95.7H99.3999C99.3999 27.9712 92.7287 21.3001 84.4998 21.3L84.4998 25ZM95.7 36.2002H92V49.7998H95.7H99.3999V36.2002H95.7ZM95.7 49.7998L92.9346 52.258L105.262 66.1252L108.027 63.667L110.792 61.2088L98.4653 47.3416L95.7 49.7998ZM108.027 63.667L105.262 66.1251C104.285 65.026 104.285 63.371 105.261 62.2727L108.027 64.7305L110.793 67.1883C112.308 65.4837 112.308 62.9141 110.793 61.2088L108.027 63.667ZM108.027 64.7305L105.262 62.2722L92.9346 76.1394L95.7 78.5977L98.4653 81.0559L110.792 67.1887L108.027 64.7305ZM95.7 78.5977H92V92.2002H95.7H99.3999V78.5977H95.7ZM95.7 92.2002L92 92.2002C91.9999 96.3422 88.6418 99.7003 84.4997 99.7004L84.4998 103.4L84.4998 107.1C92.7287 107.1 99.3999 100.429 99.3999 92.2002L95.7 92.2002ZM84.4998 103.4V99.7004H28.4998V103.4V107.1H84.4998V103.4ZM28.4998 103.4V99.7004C24.3577 99.7004 20.9996 96.3423 20.9996 92.2002L17.2996 92.2002L13.5996 92.2002C13.5996 100.429 20.2707 107.1 28.4998 107.1V103.4ZM17.2996 92.2002H20.9996V78.5986H17.2996H13.5996V92.2002H17.2996ZM17.2996 78.5986L20.0649 76.1404L7.73676 62.2722L4.97144 64.7305L2.20611 67.1887L14.5342 81.0569L17.2996 78.5986ZM4.97144 64.7305L7.73685 62.2723C8.71353 63.3711 8.71353 65.0264 7.73685 66.1251L4.97144 63.667L2.20602 61.2088C0.690476 62.9138 0.690476 65.4836 2.20602 67.1886L4.97144 64.7305ZM4.97144 63.667L7.73685 66.1251L20.065 52.256L17.2996 49.7979L14.5341 47.3397L2.20602 61.2088L4.97144 63.667ZM17.2996 49.7979H20.9996V36.2002H17.2996H13.5996V49.7979H17.2996ZM17.2996 36.2002H20.9996C20.9996 32.0581 24.3576 28.7 28.4998 28.7V25V21.3C20.2707 21.3 13.5996 27.9712 13.5996 36.2002H17.2996ZM28.4998 25V28.7H45.0066V25V21.3H28.4998V25ZM45.0066 25L48.6333 24.267C48.3381 22.8066 48.1998 21.6154 48.1998 20.7079L44.4998 20.708L40.7998 20.7081C40.7998 22.2864 41.0305 24.0039 41.3799 25.733L45.0066 25ZM44.4998 20.708H48.1998C48.1998 16.3244 51.8182 12.698 56.4998 12.698V8.99805V5.29805C47.9264 5.29805 40.7998 12.0451 40.7998 20.708H44.4998Z" fill="#1C1C24"/>
|
||||
<rect x="66.1001" y="49.8008" width="9.6" height="28.8" rx="4.8" fill="#1C1C24"/>
|
||||
<rect x="37.3" y="49.8008" width="9.6" height="28.8" rx="4.8" fill="#1C1C24"/>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 3.5 KiB |
@@ -60,6 +60,7 @@ import { desktopClient } from "@/lib/desktop-client";
|
||||
import { readModelSelectionStorageFromWindow } from "@/lib/model-selection";
|
||||
import { normalizeProviderId } from "@/lib/provider-id";
|
||||
import {
|
||||
filterChatModels,
|
||||
loadProviderModelCatalog,
|
||||
loadProviderModels,
|
||||
} from "@/lib/provider-model-catalog";
|
||||
@@ -492,7 +493,9 @@ export function RoutineSchedulesContent() {
|
||||
|
||||
async function loadModelsForProvider() {
|
||||
try {
|
||||
const models = await loadProviderModels(normalizedProvider);
|
||||
const models = filterChatModels(
|
||||
await loadProviderModels(normalizedProvider),
|
||||
);
|
||||
if (cancelled || models.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,57 +16,48 @@ export type ProviderModelCatalog = {
|
||||
providerReasoningModels: Record<string, string[]>;
|
||||
};
|
||||
|
||||
function toModelIds(models: ProviderModel[] | undefined): string[] {
|
||||
return (models ?? [])
|
||||
.filter((model) =>
|
||||
isChatCompatibleModel({
|
||||
operation: model.operation,
|
||||
modalities: {
|
||||
input: model.inputModalities,
|
||||
output: model.outputModalities,
|
||||
},
|
||||
}),
|
||||
)
|
||||
.map((model) => model.id);
|
||||
}
|
||||
|
||||
function toReasoningModelIds(models: ProviderModel[] | undefined): string[] {
|
||||
return (models ?? [])
|
||||
.filter(
|
||||
(model) =>
|
||||
model.supportsReasoning &&
|
||||
isChatCompatibleModel({
|
||||
operation: model.operation,
|
||||
modalities: {
|
||||
input: model.inputModalities,
|
||||
output: model.outputModalities,
|
||||
},
|
||||
}),
|
||||
)
|
||||
.map((model) => model.id);
|
||||
export function filterChatModels(
|
||||
models: ProviderModel[] | undefined,
|
||||
): ProviderModel[] {
|
||||
return (models ?? []).filter((model) =>
|
||||
isChatCompatibleModel({
|
||||
operation: model.operation,
|
||||
modalities: {
|
||||
input: model.inputModalities,
|
||||
output: model.outputModalities,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function buildProviderModelCatalog(
|
||||
providers: Provider[],
|
||||
): ProviderModelCatalog {
|
||||
const providerEntries = providers.map((provider) => {
|
||||
const chatModels = filterChatModels(provider.modelList);
|
||||
return {
|
||||
provider,
|
||||
modelIds: chatModels.map((model) => model.id),
|
||||
reasoningModelIds: chatModels
|
||||
.filter((model) => model.supportsReasoning)
|
||||
.map((model) => model.id),
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
providers,
|
||||
enabledProviderIds: providers
|
||||
enabledProviderIds: providerEntries
|
||||
.filter(
|
||||
(provider) =>
|
||||
provider.enabled && toModelIds(provider.modelList).length > 0,
|
||||
({ provider, modelIds }) => provider.enabled && modelIds.length > 0,
|
||||
)
|
||||
.map((provider) => provider.id),
|
||||
.map(({ provider }) => provider.id),
|
||||
providerModels: Object.fromEntries(
|
||||
providers.map((provider) => [
|
||||
provider.id,
|
||||
toModelIds(provider.modelList),
|
||||
]),
|
||||
providerEntries.map(({ provider, modelIds }) => [provider.id, modelIds]),
|
||||
),
|
||||
providerReasoningModels: Object.fromEntries(
|
||||
providers.map((provider) => [
|
||||
providerEntries.map(({ provider, reasoningModelIds }) => [
|
||||
provider.id,
|
||||
toReasoningModelIds(provider.modelList),
|
||||
reasoningModelIds,
|
||||
]),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,65 @@
|
||||
# Cline Desktop Changelog
|
||||
|
||||
## 0.0.30
|
||||
|
||||
- Windows updates no longer fail with "Error opening file for writing". The installer hook meant to stop the running backend never terminated anything: Tauri ships a 32-bit NSIS installer, so its PowerShell ran under WOW64, where `Get-Process` reports an empty path for every 64-bit process — the filter matched no sidecar on any x64 machine. The installer then wrote over an executable the detached Hub daemon still held open, which is why updating from 0.0.25 through 0.0.28 failed exactly as 0.0.24 did. The installer now asks the Windows Restart Manager which processes hold this install's files and shuts those down; that is bitness-independent, covers the connector processes the Hub spawns, and leaves a side-by-side Cline Beta alone. If Restart Manager itself fails you get a Retry/Cancel prompt rather than a half-replaced install
|
||||
- On Windows, Cline no longer runs a program out of your workspace when it means to run the system one. Windows resolves a bare program name through the child process's working directory before it searches PATH, and Cline runs `rg`, `git`, and `powershell` with your workspace as that directory — so a repository that happened to contain its own `rg.exe` would have that copy executed as soon as the workspace was indexed. Cline now opts out of current-directory executable search at startup, and every process it spawns inherits the setting
|
||||
- Long sessions now compact when they actually need to rather than running out of room. The trigger compared a character-based estimate of the transcript (~3 characters per token) against the model's context limit, so content that tokenizes far denser than that — disassembly, image dumps, minified sources — could fill the real context window while the estimate stayed under the threshold and compaction never fired; the turn was then squeezed down to a handful of output tokens. The trigger now also uses the token count the provider itself reports, and how much history is kept is scaled by how far off the estimate turned out to be. The summarizer's output budget also doubled, so a model that reasons before answering can no longer spend the whole budget thinking and return no summary at all
|
||||
- A tool that streams its output no longer keeps spinning after it has finished. When a tool streamed everything as it went, its completion event carried no final output, which chat read as "still running" — so the tool kept its running presentation, spinner included, for the rest of the turn
|
||||
- Refreshed Cline's logo and app icons throughout the app, the Dock and taskbar, and the installer
|
||||
- The CoreWeave provider's branding and setup links now match CoreWeave's current documentation, and Weights & Biases gained a direct link to its API key page from provider setup
|
||||
|
||||
## 0.0.29
|
||||
|
||||
- Queued messages can now be sent into the running turn with Enter. While the agent is working, pressing Enter with an empty composer steers the first message in the queue, so it is picked up at the next turn boundary instead of waiting for the whole task to finish; the composer placeholder says so whenever the queue is non-empty. The queue head is claimed atomically, so a fast second Enter can't steer a message that has already left the queue, and a steer that fails now surfaces as a toast rather than silently doing nothing
|
||||
- The macOS Dock icon now has the standard margin other apps use. The bundled icon and the selectable runtime icons (Classic, Chip, Hologram, Midnight) were edge-to-edge, so Cline rendered visibly larger than its neighbours in the Dock. Windows keeps its existing artwork
|
||||
- The session sidebar's sort toggle now shows the mode a click switches to, not the one already active — a folder icon while sorted by time, a clock while grouped by project
|
||||
|
||||
## 0.0.28
|
||||
|
||||
- The app no longer gets stuck on "Desktop backend unavailable" when the backend is slow to start. The window asked for the backend's address exactly once and the shell stops waiting after about 15 seconds, so on a slower machine — where starting the hub pushed past that — you were left on the error screen until you relaunched, and the relaunch could lose the same race. Connection attempts now keep retrying and re-resolve the address each time, so a backend that has since restarted is reached at its current one
|
||||
- Confirming text with a Chinese or Japanese IME no longer sends the message. The Enter that commits an in-progress composition also reached the composer, so choosing a candidate fired off a half-typed message; Enter and the arrow keys now belong to the IME while you are composing
|
||||
- The model picker refreshes its list every time you open it, instead of staying frozen until you restart the app. The Recommended and Free groupings come from a live feed, so a newly promoted free model would otherwise not show up for the rest of the session
|
||||
- Signing in with Cline now explains what the plan includes. The sign-in card lists the regular free model promotions, ClinePass for generous usage across open-weight models like DeepSeek, Kimi, and GLM, and that no API key is needed; the last onboarding step then shows the current free models alongside a ClinePass summary. This only appears when you sign in with Cline, not when you bring your own API key
|
||||
- Cline Pass now starts you on a model from your subscription. Its model list carries both subscription and free models and the default was simply the most recently published entry, so a subscriber who never picked a model was left on a free model instead of the tier they pay for
|
||||
- A turn that fails partway through with a temporary provider error is now retried up to three times instead of failing the task. A single rate-limit response passed along by a provider gateway previously ended the turn outright. A turn that has already produced output is never retried, so nothing is duplicated
|
||||
- Long responses stream faster. Every chunk of a streaming reply was being handed to client-side hooks as a round trip carrying a full copy of the session, with the agent waiting on each one before continuing
|
||||
- The command-running tool now tells the model which PowerShell edition it is talking to — `Windows PowerShell (powershell.exe)` versus `PowerShell (pwsh.exe)` — and to write commands directly rather than wrapping them in a second shell invocation, which was corrupting pipelines that use `$_`
|
||||
- Refreshed the model catalog. Adds three providers (Infer by Flow7, Melious, and Wallaby) and takes the catalog from 5,923 to 6,079 models. The resolved default model changes for 33 providers, most of them landing on DeepSeek V4.1 Flash — among them Hugging Face, Fireworks, Requesty, Cortecs, CrossModel, DigitalOcean, Eden AI, and OpenCode Go — while NVIDIA moves to GLM 5.3 Flash and NanoGPT to GPT Astra. If you use a provider without pinning a model, expect a different default
|
||||
|
||||
## 0.0.27
|
||||
|
||||
- An expired Cline sign-in now produces one actionable error instead of two dead ends. A turn that fails before the runtime takes the prompt was reported twice — the hub's detail-less `run.failed` appended a bubble, then the send RPC resolved with the real error and overwrote the error banner underneath it — so you got a vague bubble stacked on a detailed banner. The failure now renders exactly once, upgrading in place when the detailed report arrives. Credential failures also carry a fix button: **Sign in to Cline** for the Cline provider (Settings → API Providers reads a stale token as "Signed in via browser", so there is nothing to fix there), **Open model settings** for others, and local-CLI providers keep pointing at their CLI. Sessions that fail to start over credentials get the same hint and action
|
||||
- The Account page now offers a sign-in prompt when your Cline refresh token is rejected, instead of an error card whose **Retry** failed the same way. A rejected refresh was falling back to the persisted access token, which is dead too, so the account request 401'd; a rejected refresh now reports as signed out. Transient refresh failures still fall back
|
||||
- Signing out of Cline and Cline Pass now sticks. Sign-out removes the provider entry, but the runtime re-imports missing providers from the classic extension's stored credentials on every command, so you appeared signed straight back in — the same root cause as the ChatGPT/Codex fix in 0.0.26, which only cleared Codex secrets. Cline Pass sign-out did nothing at all, because its credentials live under the Cline provider entry rather than its own
|
||||
- The settings sidebar's **Models** section is now **API Providers**, with an icon to match — it is where you configure providers and their credentials, not where you pick a model
|
||||
- A failed voice input now shows a "Speech input failed" toast in chat with the actual error, instead of dropping you into Settings → Voice. Any error that wasn't a browser exception was treated as a configuration problem, even though the microphone is already gated on a configured transcription model — so a connection or transcription failure interrupted the chat and hid the real reason. Your draft and the microphone button stay put so you can retry; microphone-permission guidance is unchanged
|
||||
- OpenCode Go models work again. Requests were missing the `x-opencode-session` header Go requires to route a conversation ("Request is missing x-opencode-session and cannot be routed efficiently"), and every model was sent to `/chat/completions` because catalog normalization discarded the per-model adapter declaration — so Muse Spark, GPT, and Grok models that expect `/responses`, and MiniMax/Qwen models that expect `/messages`, failed with internal server errors. Model-level protocol routing is now preserved end to end, retries reuse the same session identity, and Go Qwen entries that omit the declaration fall back to Messages
|
||||
- Added Crusoe as an OpenAI-compatible provider
|
||||
- Settings switches are lighter in light mode and are now a shared native control — real keyboard, label, and form behavior, a guaranteed 24px hit area, and support for reduced-motion and forced-colors
|
||||
- The welcome screen's eye color matches the dark theme, and its animation no longer triggers layout work each frame
|
||||
|
||||
## 0.0.26
|
||||
|
||||
- The composer now shows the current branch's GitHub pull request — PR number, merge status, changed-line totals, and CI checks. Click through to open it in your browser, or expand CI to inspect individual checks and their logs; status refreshes every 30 seconds while visible, on window focus, and on demand. If the branch has no PR, **Create PR** opens GitHub's comparison form. Requires the GitHub CLI (`gh`) installed and signed in, plus a GitHub.com `origin` remote; the row hides itself on the default branch, detached HEAD, and unsupported repositories. Cline does not push commits or submit the PR for you
|
||||
- The Customize view's Tools, Skills, and Rules tabs now read as one consistent list instead of three different ones, matching the pattern Plugins already used. Tools gets a search bar that filters both sections and per-section Enable all/Disable all that only touches what's visible; Skills gets an in-place enable/disable toggle — previously the desktop app had no concept of a disabled skill, so disabled ones were hidden and unreachable — and the same Copy path / Uninstall menu Plugins use. Tabs are reordered to Tools, Plugins, Skills, Rules, MCP, Hooks and open on Tools, and the sidebar's "New Task" button is now "New Session"
|
||||
- Deleting a queued prompt no longer leaves it in the transcript as a message that never ran. The sidecar inferred a queued prompt had started whenever the pending list shrank and its head changed — which is exactly what deleting the first queued prompt (or discarding the queue) looks like. It now relies only on the runtime's real start event
|
||||
- A session forked from a checkpoint restore no longer comes back stuck on "Thinking...". Sessions that materialize with seeded history never passed their status when persisting, so the row and manifest were written as "running" while the live session was idle; resuming from that manifest then showed a session that was never going to finish
|
||||
- Sending an image with no text no longer fails with "session input requires a prompt string" — the composer asks for a message instead of letting the request through to a backend that rejects it
|
||||
- Image attachments in formats the model pipeline can't read (HEIC, TIFF, SVG, BMP, ICO, and friends) are now rejected at attach time — by picker, paste, or drag-and-drop — instead of failing later in the turn. Files whose type has to be inferred from the extension are classified the same way
|
||||
- Signing out of ChatGPT (Codex) now sticks. Sign-out removes the provider entry, but the runtime re-imports any missing provider from the classic extension's stored credentials on every command, so the next action signed you straight back in. The legacy Codex credentials are now cleared too, and a failed clear reports the sign-out as failed instead of quietly succeeding
|
||||
- Auth failures on providers that log in through a local CLI — Claude Code, Codex CLI, OpenCode — now point you at that CLI instead of Settings → Models, where there is nothing to fix. "OAuth session expired", "Not logged in · Please run /login", and similar messages are also recognized as credential failures now, so they get a hint at all
|
||||
- Model lists now refresh from the live catalog for every provider that uses the shared catalog, not just Cline and Cline Pass. Providers with their own endpoint-owned model lists are unaffected, and the first providers listing is still network-free
|
||||
- Cline Pass and free models now report zero cost instead of the upstream provider's price
|
||||
- Session history rows no longer overlap their own hover metadata when a label is wider than the fixed label column
|
||||
- Scheduled sessions no longer stall out. The poller could stop advancing, and capacity waits were counted as run attempts, so a schedule could burn through its retries without ever running. Execution lifecycle and capacity claims are now fenced atomically. New recurring schedules also default to your local timezone instead of UTC; existing schedules without a timezone keep it that way when edited
|
||||
- Automation event acceptance is now atomic and retryable, so an event can't be half-accepted and lost if delivery fails mid-way
|
||||
- Nested PowerShell commands no longer flood errors and look like a hang. Commands run through an outer PowerShell bootstrap, so a nested `powershell -Command "... $_ ..."` had `$_` interpolated away by the outer parser before the inner shell saw it — a `Where-Object { $_.Name ... }` pipeline then errored once per item over a large tree while still exiting 0. Redundant nested invocations are now unwrapped and run directly, only when that provably preserves semantics (same PowerShell edition, no profile loading, fully quoted command). Cline is also told which edition it's actually on — Windows PowerShell vs. Microsoft PowerShell — and to stop wrapping commands in a shell it's already running in
|
||||
- Prompt telemetry to Cline's tracing backend is now limited to Cline and Cline Pass requests. Turns run against your own provider keys are not traced
|
||||
- Cline Pass now appears in the composer's provider picker alongside Cline. One Cline sign-in configures both — Cline Pass stores its credentials under the Cline account rather than having its own — but the picker only listed providers with their own saved settings entry, and onboarding writes just the Cline one. A new Cline Pass user therefore saw a single row
|
||||
- The composer's provider picker has a **Set up another provider** row at the bottom that opens Settings → Models. The picker only lists what you have already configured, so there was no way to reach the rest of the catalog from the composer
|
||||
- Dropped the "Configured" checkmark from the composer's provider picker (added in 0.0.25). Every row in that picker has a saved settings entry, so for anyone who set their providers up in the app every row carried the same green check and it read as decoration. Settings is still where provider readiness is shown, and it distinguishes a real credential from an entry a legacy migration left behind
|
||||
|
||||
## 0.0.25
|
||||
|
||||
- ChatGPT Subscription (Codex) now lists only the models your plan can actually use. Two separate paths filled the picker from the shared OpenAI catalog, so GPT-4o, GPT-4.1, and `chatgpt-image-latest` showed up alongside the Codex models, and the runtime lost the Codex context caps. The model rules also match what the backend now accepts: `gpt-5.4` and `gpt-5.4-mini` were retired for ChatGPT accounts on 2026-08-31 and are gone, the default moves to `gpt-5.6-terra`, and every Codex model is capped at the real 400K/272K/128K backend budget instead of inheriting the API's 1.05M limits
|
||||
|
||||
@@ -10,13 +10,76 @@ From `apps/examples/desktop-app/`:
|
||||
- `bun run dev:web` - Next.js UI only (approval-gated tools require `dev:headless` or the native app)
|
||||
- `bun run dev:sidecar` - sidecar backend only (approval-gated tools require `dev:headless` or the native app)
|
||||
- `bun run dev` - Tauri desktop dev
|
||||
- `bun run build` - build web assets
|
||||
- `bun run build:web` - build production web assets only (includes the shared UI build)
|
||||
- `bun run build` - build web assets and the sidecar binary
|
||||
- `bun run build:sidecar` - build the Bun sidecar bundle
|
||||
- `bun run build:sidecar:bin` - compile the Bun sidecar into a local binary
|
||||
- `bun run build:binary` - build desktop binary
|
||||
- `bun run package:desktop` - package the current OS desktop app into `dist/desktop/`
|
||||
- `bun run typecheck` - TypeScript check
|
||||
|
||||
### Checking webview changes
|
||||
|
||||
Run `bun run build:web` from this directory when changing webview imports or shared browser APIs. Type checking and Vitest do not check the production browser bundle: a valid TypeScript import can still pull Node-only modules into a client chunk. Use `@cline/shared/browser` for runtime imports in the webview; the bare `@cline/shared` source alias points to the Node entry point.
|
||||
|
||||
## Pull Requests
|
||||
|
||||
The composer shows the current branch's GitHub pull request, merge status,
|
||||
changed-line totals, and CI checks. Click the PR number to open it in your
|
||||
browser, or expand CI to inspect individual checks and their logs. Status
|
||||
refreshes every 30 seconds while visible, when the app regains focus, and
|
||||
when you click refresh.
|
||||
|
||||
This requires GitHub CLI (`gh`) installed and authenticated with `gh auth login`,
|
||||
and a GitHub.com `origin` remote (HTTPS or SSH). The row is hidden for the
|
||||
default branch, detached HEAD, and unsupported repositories. If the branch
|
||||
has no PR, **Create PR** opens GitHub's comparison form; push your commits
|
||||
before submitting the form. The app does not push commits or submit PRs itself.
|
||||
|
||||
Missing or unauthenticated GitHub CLI also hides the row. Availability checks
|
||||
are shared across workspaces and cached for five minutes, so unavailable CLI
|
||||
installs do not spawn a failing process on every poll or window focus. After
|
||||
installing or signing into `gh`, the feature becomes available on the first
|
||||
refresh after the cache expires (or after restarting the desktop backend).
|
||||
Initial lookup failures stay hidden. Errors after a successful status load
|
||||
can be dismissed and remain dismissed through retries until a load succeeds.
|
||||
|
||||
### Pull request telemetry
|
||||
|
||||
These events use the desktop telemetry service and respect telemetry opt-out:
|
||||
|
||||
| Event | Trigger |
|
||||
| --- | --- |
|
||||
| `desktop.pull_request.shown` | First visible PR/create row per mounted workspace and branch |
|
||||
| `desktop.pull_request.open_clicked` | Click the PR link |
|
||||
| `desktop.pull_request.create_clicked` | Click Create PR (intent only, not PR submission) |
|
||||
| `desktop.pull_request.checks_expanded` | Open the CI popover |
|
||||
| `desktop.pull_request.check_clicked` | Click a check's details link |
|
||||
| `desktop.pull_request.refresh_clicked` | Click manual refresh |
|
||||
|
||||
Each event contains only `prState`, `ciState`, and `mergeTone` categories.
|
||||
The sidecar validates these values and strips extra fields. Repository/branch
|
||||
names, paths, PR numbers/titles, check names, and URLs are not included.
|
||||
Automatic polling does not emit additional impressions. Telemetry delivery
|
||||
does not block interactions, and failures do not interrupt the feature.
|
||||
|
||||
## App Icons
|
||||
|
||||
`src-tauri/app-icon.png` (1024x1024, edge-to-edge) is the source for
|
||||
`bun tauri icon`, which generates the Windows `.ico` and Linux PNGs in
|
||||
`src-tauri/icons/`. macOS is the exception: Dock icons are expected to have a
|
||||
transparent margin, with the artwork filling 824 of the 1024 canvas, so the
|
||||
committed `icons/icon.icns` is built from a padded copy of the source, and the
|
||||
selectable runtime icons in `icons/app/macos/` are padded copies of the
|
||||
Windows ones in `icons/app/`. To regenerate the macOS icon after changing the
|
||||
artwork:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
magick app-icon.png -resize 824x824 -background none -gravity center -extent 1024x1024 /tmp/app-icon-macos.png
|
||||
bun tauri icon /tmp/app-icon-macos.png -o /tmp/icons-macos && cp /tmp/icons-macos/icon.icns icons/icon.icns
|
||||
```
|
||||
|
||||
## Customizing the macOS Install Window
|
||||
|
||||
The drag-to-Applications window is configured by `bundle.macOS.dmg` in
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cline/code",
|
||||
"version": "0.0.25",
|
||||
"version": "0.0.30",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build:ui": "bun -F @cline/ui build",
|
||||
@@ -10,6 +10,8 @@
|
||||
"predev:headless": "bun run build:ui",
|
||||
"dev:headless": "bun run scripts/dev-headless.ts",
|
||||
"dev": "tauri dev --config src-tauri/tauri.dev.conf.json",
|
||||
"prebuild:web": "bun run build:ui",
|
||||
"build:web": "next build webview",
|
||||
"prebuild": "bun run build:ui",
|
||||
"build": "bun run bun.mts",
|
||||
"build:sidecar": "mkdir -p dist/sidecar && bun build ./sidecar/index.ts --outfile ./dist/sidecar/index.js --target bun",
|
||||
@@ -27,6 +29,9 @@
|
||||
"typecheck": "tsc -p tsconfig.dev.json --noEmit",
|
||||
"pretest:chat-ui": "bun run build:ui",
|
||||
"test:chat-ui": "vitest run webview/components/views/chat/chat-messages.test.tsx webview/components/views/chat/messages --config vitest.config.ts",
|
||||
"pretest:settings-ui": "bun run build:ui",
|
||||
"test:settings-ui": "vitest run webview/components/views/settings webview/components/ui/switch-integration.test.tsx --config vitest.config.ts",
|
||||
"test:sidecar": "vitest run sidecar scripts/telemetry-define-args.test.ts --config vitest.config.ts",
|
||||
"clean": "rm -rf webview/.next webview/out node_modules dist && (cd src-tauri && rm -rf target node_modules dist)"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -60,7 +65,6 @@
|
||||
"@radix-ui/react-separator": "1.1.8",
|
||||
"@radix-ui/react-slider": "1.3.6",
|
||||
"@radix-ui/react-slot": "1.2.4",
|
||||
"@radix-ui/react-switch": "1.2.6",
|
||||
"@radix-ui/react-tabs": "1.1.13",
|
||||
"@radix-ui/react-toast": "1.2.15",
|
||||
"@radix-ui/react-toggle": "1.1.10",
|
||||
|
||||
@@ -65,6 +65,18 @@ describe("telemetryDefineArgs", () => {
|
||||
expect(withKeys["process.env.ERROR_SERVICE_API_KEY"]).toBe('"ek"');
|
||||
});
|
||||
|
||||
it("inlines the cloud-agents toggle only when set at build time", () => {
|
||||
const withoutToggle = defineMap(telemetryDefineArgs({}));
|
||||
expect(withoutToggle).not.toHaveProperty(
|
||||
"process.env.CLINE_CODE_CLOUD_AGENTS",
|
||||
);
|
||||
|
||||
const withToggle = defineMap(
|
||||
telemetryDefineArgs({ CLINE_CODE_CLOUD_AGENTS: "1" }),
|
||||
);
|
||||
expect(withToggle["process.env.CLINE_CODE_CLOUD_AGENTS"]).toBe('"1"');
|
||||
});
|
||||
|
||||
it("JSON-escapes values so headers with quotes survive the define", () => {
|
||||
const defines = defineMap(
|
||||
telemetryDefineArgs({
|
||||
|
||||
@@ -15,6 +15,9 @@ const OPTIONAL_SECRET_ENV_VARS = [
|
||||
"ERROR_SERVICE_API_KEY",
|
||||
] as const;
|
||||
|
||||
/** Optional build-time overrides for packaged dogfood builds. */
|
||||
const OPTIONAL_FEATURE_ENV_VARS = ["CLINE_CODE_CLOUD_AGENTS"] as const;
|
||||
|
||||
/**
|
||||
* Every env var `getTelemetryBuildTimeConfig` reads
|
||||
* (sdk/packages/shared/src/services/telemetry-config.ts). Always inlined,
|
||||
@@ -42,7 +45,10 @@ export function telemetryDefineArgs(
|
||||
const define = (name: string, value: string) => {
|
||||
args.push("--define", `process.env.${name}=${JSON.stringify(value)}`);
|
||||
};
|
||||
for (const name of OPTIONAL_SECRET_ENV_VARS) {
|
||||
for (const name of [
|
||||
...OPTIONAL_SECRET_ENV_VARS,
|
||||
...OPTIONAL_FEATURE_ENV_VARS,
|
||||
]) {
|
||||
const value = env[name];
|
||||
if (value) {
|
||||
define(name, value);
|
||||
|
||||
@@ -144,6 +144,17 @@ The frontend `desktop-client.ts` connects directly to the sidecar WebSocket:
|
||||
|
||||
## Command Map
|
||||
|
||||
The model picker first uses `list_provider_catalog`, which reads the bundled and
|
||||
registered models without network access. It then calls `list_provider_models`
|
||||
for the active provider, both on mount and when the provider changes. All built-in
|
||||
providers backed by the shared catalog refresh from the live feed (including
|
||||
OpenCode); concurrent requests share one fetch and reuse its ten-minute cache.
|
||||
Endpoint-owned lists such as Baseten, Hicap, Poolside, LiteLLM, Ollama, and LM Studio use their existing
|
||||
discovery endpoints instead. Catalog and public endpoint requests time out after
|
||||
five seconds, and the initial picker remains usable while a refresh is pending.
|
||||
The sidecar omits bundled `knownModels` from the discovery config so they cannot
|
||||
override live metadata; explicitly registered model overrides retain precedence.
|
||||
|
||||
Supported commands:
|
||||
|
||||
| Command | Implementation |
|
||||
|
||||
@@ -2280,3 +2280,35 @@ describe("mistake-limit prompt", () => {
|
||||
expect(start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("queue steering routing", () => {
|
||||
it.each([
|
||||
undefined,
|
||||
"selected-prompt",
|
||||
])("routes steering with prompt ID %s", async (promptId) => {
|
||||
const result = { sessionId: "session", prompts: [], updated: false };
|
||||
const steerFirst = vi.fn(async () => result);
|
||||
const update = vi.fn(async () => result);
|
||||
const ctx = {
|
||||
liveSessions: new Map(),
|
||||
wsClients: new Set(),
|
||||
sessionManager: { pendingPrompts: { steerFirst, update } },
|
||||
} as unknown as SidecarContext;
|
||||
await handleChatSessionCommand(ctx, {
|
||||
action: "steer_prompt",
|
||||
sessionId: "session",
|
||||
promptId,
|
||||
});
|
||||
if (promptId === undefined) {
|
||||
expect(steerFirst).toHaveBeenCalledWith({ sessionId: "session" });
|
||||
expect(update).not.toHaveBeenCalled();
|
||||
} else {
|
||||
expect(update).toHaveBeenCalledWith({
|
||||
sessionId: "session",
|
||||
promptId,
|
||||
delivery: "steer",
|
||||
});
|
||||
expect(steerFirst).not.toHaveBeenCalled();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1711,14 +1711,17 @@ async function handleSteerPrompt(
|
||||
): Promise<unknown> {
|
||||
const sessionId = request.sessionId?.trim();
|
||||
const promptId = request.promptId?.trim();
|
||||
if (!sessionId || !promptId)
|
||||
throw new Error("sessionId and promptId are required");
|
||||
if (!sessionId) throw new Error("sessionId is required");
|
||||
if (request.promptId !== undefined && !promptId)
|
||||
throw new Error("promptId cannot be empty");
|
||||
const manager = getSessionManager(ctx);
|
||||
const result = await manager.pendingPrompts.update({
|
||||
sessionId,
|
||||
promptId,
|
||||
delivery: "steer",
|
||||
});
|
||||
const result = promptId
|
||||
? await manager.pendingPrompts.update({
|
||||
sessionId,
|
||||
promptId,
|
||||
delivery: "steer",
|
||||
})
|
||||
: await manager.pendingPrompts.steerFirst({ sessionId });
|
||||
return {
|
||||
sessionId,
|
||||
updated: result.updated === true,
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
captureAuthRefreshSoftFailure,
|
||||
getProviderAuthHandler,
|
||||
OAuthReauthRequiredError,
|
||||
type ProviderSettingsManager,
|
||||
RuntimeOAuthTokenManager,
|
||||
} from "@cline/core";
|
||||
import type { SidecarContext } from "./types";
|
||||
|
||||
// Share the refresh-aware manager so single-use refresh tokens stay single-flight.
|
||||
let clineOAuthTokenManager: RuntimeOAuthTokenManager | undefined;
|
||||
|
||||
export async function resolveFreshClineAuthToken(
|
||||
manager: ProviderSettingsManager,
|
||||
ctx?: SidecarContext,
|
||||
): Promise<string | undefined> {
|
||||
let refreshError: Error | undefined;
|
||||
try {
|
||||
clineOAuthTokenManager ??= new RuntimeOAuthTokenManager();
|
||||
const resolution = await clineOAuthTokenManager.resolveProviderApiKey({
|
||||
providerId: "cline",
|
||||
});
|
||||
if (resolution?.apiKey) {
|
||||
return resolution.apiKey;
|
||||
}
|
||||
} catch (error) {
|
||||
// A persisted token may still let the account request surface the failure.
|
||||
refreshError = error instanceof Error ? error : new Error(String(error));
|
||||
}
|
||||
// Apply canonical OAuth-token formatting while preserving raw API keys.
|
||||
const persisted = getProviderAuthHandler("cline")?.getApiKey(
|
||||
manager.getProviderSettings("cline"),
|
||||
);
|
||||
if (!persisted && refreshError && ctx) {
|
||||
ctx.logger?.error?.("Cline auth token refresh failed with no fallback", {
|
||||
error: refreshError,
|
||||
});
|
||||
captureAuthRefreshSoftFailure(ctx.telemetry, "cline", {
|
||||
errorName: refreshError.name,
|
||||
errorCode: "desktop_refresh_failed_no_fallback_token",
|
||||
});
|
||||
}
|
||||
// A rejected refresh token means the persisted access token is dead too.
|
||||
// Handing it out would turn the signed-out state into an opaque request
|
||||
// failure (an error card whose Retry fails the same way) instead of the
|
||||
// sign-in prompt. Transient refresh failures still fall back to it.
|
||||
if (refreshError instanceof OAuthReauthRequiredError) {
|
||||
return undefined;
|
||||
}
|
||||
return persisted;
|
||||
}
|
||||
@@ -0,0 +1,505 @@
|
||||
import type { HubEventEnvelope } from "@cline/shared";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { reconcileBufferedCloudEvents } from "./cloud-session-snapshots";
|
||||
|
||||
describe("reconcileBufferedCloudEvents", () => {
|
||||
const event = (
|
||||
name: HubEventEnvelope["event"],
|
||||
id: string,
|
||||
payload: Record<string, unknown> = {},
|
||||
): HubEventEnvelope => ({
|
||||
version: "v1",
|
||||
event: name,
|
||||
eventId: id,
|
||||
timestamp: Date.now(),
|
||||
sessionId: "inner-1",
|
||||
payload,
|
||||
});
|
||||
|
||||
it.each([
|
||||
"Continue",
|
||||
"",
|
||||
])("preserves submitted lifecycle while marking only newly reflected %j prompts", (prompt) => {
|
||||
const submitted = (id: string) =>
|
||||
event("session.pending_prompt_submitted", id, {
|
||||
prompt: {
|
||||
id,
|
||||
prompt,
|
||||
delivery: "queue",
|
||||
...(prompt
|
||||
? {}
|
||||
: {
|
||||
userImages: ["data:image/png;base64,AA=="],
|
||||
attachmentCount: 1,
|
||||
}),
|
||||
},
|
||||
});
|
||||
const first = submitted("q-1");
|
||||
const later = submitted("q-2");
|
||||
const baseline = [
|
||||
{
|
||||
role: "user",
|
||||
content: prompt || [
|
||||
{
|
||||
type: "image",
|
||||
source: { type: "base64", media_type: "image/png", data: "AA==" },
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
// An older identical user message must not consume a new submission.
|
||||
expect(
|
||||
reconcileBufferedCloudEvents([first], baseline, {
|
||||
baselineMessages: baseline,
|
||||
}),
|
||||
).toEqual([first]);
|
||||
const toolResult = {
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "tool_result", tool_use_id: "call-1", content: "done" },
|
||||
],
|
||||
};
|
||||
expect(
|
||||
reconcileBufferedCloudEvents([first], [...baseline, toolResult], {
|
||||
baselineMessages: baseline,
|
||||
}),
|
||||
).toEqual([first]);
|
||||
const snapshot = [
|
||||
...baseline,
|
||||
toolResult,
|
||||
{
|
||||
...baseline[0],
|
||||
...(prompt
|
||||
? {
|
||||
content: [
|
||||
...toolResult.content,
|
||||
{ type: "text", text: `<user_input>${prompt}</user_input>` },
|
||||
],
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
];
|
||||
const completed = event("run.completed", "done");
|
||||
const running = event("run.started", "next");
|
||||
// Keep the next turn's start between lifecycle events; only its bubble is reflected.
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(
|
||||
[completed, first, running, later],
|
||||
snapshot,
|
||||
{
|
||||
baselineMessages: baseline,
|
||||
},
|
||||
),
|
||||
).toEqual([
|
||||
completed,
|
||||
{ ...first, payload: { ...first.payload, transcriptReflected: true } },
|
||||
running,
|
||||
later,
|
||||
]);
|
||||
// A submission received after the transcript reply cannot be in it.
|
||||
expect(
|
||||
reconcileBufferedCloudEvents([later], snapshot, {
|
||||
baselineMessages: baseline,
|
||||
messagesSnapshotEventCutoff: 0,
|
||||
}),
|
||||
).toEqual([later]);
|
||||
});
|
||||
|
||||
it("replays content the snapshot does NOT contain", () => {
|
||||
const buffered = [
|
||||
event("assistant.delta", "a-1", { text: "unpersisted reply" }),
|
||||
event("run.completed", "done-1"),
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, [
|
||||
{ role: "assistant", content: "a completely different answer" },
|
||||
]).map((item) => item.event),
|
||||
).toEqual(["assistant.delta", "run.completed"]);
|
||||
});
|
||||
|
||||
it("does not let an interior substring claim another run's snapshot", () => {
|
||||
const buffered = [
|
||||
event("assistant.finished", "a-1", { text: "foo" }),
|
||||
event("run.completed", "done-1"),
|
||||
event("assistant.finished", "a-2", { text: "The answer is foobar" }),
|
||||
event("run.completed", "done-2"),
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, [
|
||||
{ role: "assistant", content: "The answer is foobar" },
|
||||
]).map((item) => item.eventId),
|
||||
).toEqual(["a-1", "done-1", "done-2"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["bar", "foobar", false],
|
||||
["bar", "foobar", true],
|
||||
["Done", "Done", false],
|
||||
] as const)("preserves aborted %j beside saved %j (reverse: %s)", (partial, saved, reverse) => {
|
||||
const aborted = [
|
||||
event("assistant.delta", "partial", { text: partial }),
|
||||
event("run.aborted", "aborted"),
|
||||
];
|
||||
const completed = [
|
||||
event("assistant.delta", "saved-delta", { text: saved }),
|
||||
event("assistant.finished", "saved-finished", { text: saved }),
|
||||
event("run.completed", "completed"),
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(
|
||||
reverse ? [...completed, ...aborted] : [...aborted, ...completed],
|
||||
[{ role: "assistant", content: saved }],
|
||||
).map((item) => item.eventId),
|
||||
).toEqual(
|
||||
reverse
|
||||
? ["completed", "partial", "aborted"]
|
||||
: ["partial", "aborted", "completed"],
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"assistant",
|
||||
"reasoning",
|
||||
] as const)("does not let finished %s hide the other aborted content", (finished) => {
|
||||
const partial = finished === "assistant" ? "reasoning" : "assistant";
|
||||
const buffered = [
|
||||
event(`${finished}.finished`, "saved", {
|
||||
text: "foobar",
|
||||
reasoning: "foobar",
|
||||
}),
|
||||
event(`${partial}.delta`, "partial", { text: "bar" }),
|
||||
event("run.aborted", "aborted"),
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "text", text: "foobar" },
|
||||
{ type: "thinking", thinking: "foobar" },
|
||||
],
|
||||
},
|
||||
]).map((item) => item.eventId),
|
||||
).toEqual(["partial", "aborted"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["assistant", false],
|
||||
["reasoning", false],
|
||||
["reasoning", true],
|
||||
] as const)("preserves unfinished %s after saved output (redacted: %s)", (kind, redacted) => {
|
||||
const saved = [
|
||||
event(`${kind}.delta`, "saved-delta", {
|
||||
text: redacted ? "" : "saved",
|
||||
redacted,
|
||||
}),
|
||||
event(`${kind}.finished`, "saved-finished", {
|
||||
[kind === "assistant" ? "text" : "reasoning"]: redacted
|
||||
? undefined
|
||||
: "saved",
|
||||
}),
|
||||
];
|
||||
const partial = event(`${kind}.delta`, "partial", { text: "unfinished" });
|
||||
const snapshot = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
redacted
|
||||
? { type: "redacted_thinking", data: "opaque" }
|
||||
: kind === "assistant"
|
||||
? { type: "text", text: "saved" }
|
||||
: { type: "thinking", thinking: "saved" },
|
||||
],
|
||||
},
|
||||
];
|
||||
for (const terminal of ["run.aborted", "run.failed"] as const) {
|
||||
const end = event(terminal, "end");
|
||||
const buffered = [...saved, partial, end];
|
||||
expect(reconcileBufferedCloudEvents(buffered, snapshot)).toEqual([
|
||||
partial,
|
||||
end,
|
||||
]);
|
||||
const earlier = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
kind === "assistant"
|
||||
? { type: "text", text: "earlier" }
|
||||
: { type: "thinking", thinking: "earlier" },
|
||||
],
|
||||
},
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(
|
||||
[
|
||||
event(`${kind}.finished`, "earlier", {
|
||||
[kind === "assistant" ? "text" : "reasoning"]: "earlier",
|
||||
}),
|
||||
...buffered,
|
||||
],
|
||||
[...earlier, ...snapshot],
|
||||
{ baselineMessages: earlier },
|
||||
),
|
||||
).toEqual([partial, end]);
|
||||
expect(reconcileBufferedCloudEvents(buffered, [])).toEqual(buffered);
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, snapshot, {
|
||||
baselineMessages: snapshot,
|
||||
}),
|
||||
).toEqual(buffered);
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, snapshot, {
|
||||
messagesSnapshotEventCutoff: 1,
|
||||
}),
|
||||
).toEqual(
|
||||
terminal === "run.aborted" ? buffered : [saved[1], partial, end],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
"assistant",
|
||||
"reasoning",
|
||||
] as const)("preserves %s output completed after the snapshot", (kind) => {
|
||||
const key = kind === "assistant" ? "text" : "reasoning";
|
||||
const saved = event(`${kind}.finished`, "saved", { [key]: "saved" });
|
||||
const partial = event(`${kind}.delta`, "partial", { text: "new reply" });
|
||||
const finished = event(`${kind}.finished`, "finished", {
|
||||
[key]: "new reply",
|
||||
});
|
||||
const end = event("run.completed", "end");
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(
|
||||
[saved, partial, finished, end],
|
||||
[
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{
|
||||
type: kind === "assistant" ? "text" : "thinking",
|
||||
[kind === "assistant" ? "text" : "thinking"]: "saved",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
{ messagesSnapshotEventCutoff: 2 },
|
||||
),
|
||||
).toEqual([partial, finished, end]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"run.completed",
|
||||
"run.aborted",
|
||||
"run.failed",
|
||||
] as const)("ignores empty finishes after saved content in %s", (terminal) => {
|
||||
const end = event(terminal, "end");
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(
|
||||
[
|
||||
event("assistant.finished", "saved", { text: "saved" }),
|
||||
event("assistant.finished", "empty", { text: "" }),
|
||||
event("assistant.finished", "missing"),
|
||||
end,
|
||||
],
|
||||
[{ role: "assistant", content: "saved" }],
|
||||
),
|
||||
).toEqual([end]);
|
||||
});
|
||||
|
||||
it("supersedes despite trailing whitespace in the streamed text", () => {
|
||||
const buffered = [
|
||||
event("assistant.finished", "f-1", { text: "the answer \n" }),
|
||||
event("run.completed", "done-1"),
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, [
|
||||
{ role: "assistant", content: "prefix the answer" },
|
||||
]).map((item) => item.event),
|
||||
).toEqual(["run.completed"]);
|
||||
});
|
||||
|
||||
it("drops buffered queue snapshots when a fresh queue snapshot was applied", () => {
|
||||
const buffered = [
|
||||
event("session.pending_prompts", "q-1", { prompts: [] }),
|
||||
event("assistant.delta", "a-1", { text: "live tail" }),
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, []).map((item) => item.event),
|
||||
).toEqual(["assistant.delta"]);
|
||||
});
|
||||
|
||||
it("replays the newest buffered queue snapshot when the queue fetch failed", () => {
|
||||
const buffered = [
|
||||
event("session.pending_prompts", "q-1", { prompts: [] }),
|
||||
event("session.pending_prompts", "q-2", {
|
||||
prompts: [{ id: "p-1", prompt: "queued work" }],
|
||||
}),
|
||||
event("assistant.delta", "a-1", { text: "live tail" }),
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, [], {
|
||||
queueSnapshotApplied: false,
|
||||
}).map((item) => item.eventId),
|
||||
).toEqual(["q-2", "a-1"]);
|
||||
});
|
||||
|
||||
it("replays a queue snapshot received after the queue fetch", () => {
|
||||
const buffered = [
|
||||
event("session.pending_prompts", "q-old", { prompts: [] }),
|
||||
event("assistant.delta", "a-1", { text: "live tail" }),
|
||||
event("session.pending_prompts", "q-new", {
|
||||
prompts: [{ id: "p-1", prompt: "queued work" }],
|
||||
}),
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, [], {
|
||||
queueSnapshotEventCutoff: 1,
|
||||
}).map((item) => item.eventId),
|
||||
).toEqual(["a-1", "q-new"]);
|
||||
});
|
||||
|
||||
it("supersedes content independently across two terminal run segments", () => {
|
||||
const buffered = [
|
||||
event("assistant.delta", "a-1", { text: "first tail" }),
|
||||
event("run.completed", "done-1"),
|
||||
event("assistant.delta", "a-2", { text: "second tail" }),
|
||||
event("run.completed", "done-2"),
|
||||
];
|
||||
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, [
|
||||
{ role: "assistant", content: "prefix first tail" },
|
||||
{ role: "assistant", content: "prefix second tail" },
|
||||
]).map((item) => item.event),
|
||||
).toEqual(["run.completed", "run.completed"]);
|
||||
});
|
||||
|
||||
it("does not let an older identical reply supersede a new buffered turn", () => {
|
||||
const buffered = [
|
||||
event("assistant.delta", "a-2", { text: "Done" }),
|
||||
event("run.completed", "done-2"),
|
||||
];
|
||||
const baseline = [{ role: "assistant", content: "Done" }];
|
||||
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, baseline, {
|
||||
baselineMessages: baseline,
|
||||
}).map((item) => item.event),
|
||||
).toEqual(["assistant.delta", "run.completed"]);
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(
|
||||
buffered,
|
||||
[...baseline, { role: "assistant", content: "Done" }],
|
||||
{ baselineMessages: baseline },
|
||||
).map((item) => item.event),
|
||||
).toEqual(["run.completed"]);
|
||||
});
|
||||
|
||||
it("keeps run.failed while suppressing reflected content and dedupes tools by id", () => {
|
||||
const buffered = [
|
||||
event("assistant.delta", "a-1", { text: "partial failure" }),
|
||||
event("tool.started", "tool-1", { toolCallId: "call-1" }),
|
||||
event("run.failed", "failed-1", { error: "boom" }),
|
||||
];
|
||||
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, [
|
||||
{ role: "assistant", content: "saved partial failure" },
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "tool_use", id: "call-1", name: "read_file" }],
|
||||
},
|
||||
]).map((item) => item.event),
|
||||
).toEqual(["run.failed"]);
|
||||
});
|
||||
|
||||
it("only suppresses tool phases present in the transcript before its cutoff", () => {
|
||||
const started = event("tool.started", "start", { toolCallId: "call-1" });
|
||||
const finished = event("tool.finished", "finish", {
|
||||
toolCallId: "call-1",
|
||||
output: "done",
|
||||
});
|
||||
const snapshot = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "tool_use", id: "call-1", name: "read_file" }],
|
||||
},
|
||||
];
|
||||
expect(reconcileBufferedCloudEvents([started, finished], snapshot)).toEqual(
|
||||
[finished],
|
||||
);
|
||||
const completedSnapshot = [
|
||||
...snapshot,
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "tool_result", tool_use_id: "call-1", content: "done" },
|
||||
],
|
||||
},
|
||||
];
|
||||
expect(
|
||||
reconcileBufferedCloudEvents([started, finished], completedSnapshot),
|
||||
).toEqual([]);
|
||||
expect(
|
||||
reconcileBufferedCloudEvents([started, finished], completedSnapshot, {
|
||||
messagesSnapshotEventCutoff: 1,
|
||||
}),
|
||||
).toEqual([finished]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["run.failed", false],
|
||||
["run.aborted", false],
|
||||
["run.aborted", true],
|
||||
] as const)("does not replay persisted thinking for %s (redacted: %s)", (terminal, redacted) => {
|
||||
const buffered = [
|
||||
event("reasoning.delta", "thinking", {
|
||||
text: redacted ? "" : "Checking",
|
||||
redacted,
|
||||
}),
|
||||
event("reasoning.finished", "thought", {
|
||||
reasoning: redacted ? undefined : "Checking",
|
||||
}),
|
||||
event(terminal, "end"),
|
||||
];
|
||||
const snapshot = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
redacted
|
||||
? { type: "redacted_thinking", data: "opaque" }
|
||||
: { type: "thinking", thinking: "Checking" },
|
||||
],
|
||||
},
|
||||
];
|
||||
expect(reconcileBufferedCloudEvents(buffered, snapshot)).toEqual([
|
||||
buffered[2],
|
||||
]);
|
||||
expect(reconcileBufferedCloudEvents(buffered, [])).toEqual(buffered);
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, snapshot, {
|
||||
baselineMessages: snapshot,
|
||||
}),
|
||||
).toEqual(buffered);
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(buffered, snapshot, {
|
||||
messagesSnapshotEventCutoff: 0,
|
||||
}),
|
||||
).toEqual(buffered);
|
||||
});
|
||||
|
||||
it("does not treat persisted assistant text as proof that thinking was saved", () => {
|
||||
const thinking = event("reasoning.delta", "thinking", { text: "Checking" });
|
||||
const done = event("run.completed", "done");
|
||||
expect(
|
||||
reconcileBufferedCloudEvents(
|
||||
[
|
||||
thinking,
|
||||
event("assistant.finished", "answer", { text: "Done" }),
|
||||
done,
|
||||
],
|
||||
[{ role: "assistant", content: "Done" }],
|
||||
),
|
||||
).toEqual([thinking, done]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,362 @@
|
||||
import { isUserRunMessage } from "@cline/core";
|
||||
import type { HubEventEnvelope } from "@cline/shared";
|
||||
import type { JsonRecord, PromptInQueue } from "./types";
|
||||
|
||||
export function readSessionRows(
|
||||
payload: Record<string, unknown> | undefined,
|
||||
): JsonRecord[] {
|
||||
return Array.isArray(payload?.sessions)
|
||||
? payload.sessions.filter(
|
||||
(item): item is JsonRecord =>
|
||||
Boolean(item) && typeof item === "object" && !Array.isArray(item),
|
||||
)
|
||||
: [];
|
||||
}
|
||||
|
||||
export function updatedAt(record: JsonRecord): number {
|
||||
const value = record.updatedAt;
|
||||
return typeof value === "number"
|
||||
? value
|
||||
: Date.parse(String(value ?? "")) || 0;
|
||||
}
|
||||
|
||||
export function sessionRowModelId(record: JsonRecord | undefined): string {
|
||||
const metadata =
|
||||
record?.metadata && typeof record.metadata === "object"
|
||||
? (record.metadata as JsonRecord)
|
||||
: undefined;
|
||||
return String(metadata?.model ?? record?.model ?? "").trim();
|
||||
}
|
||||
|
||||
export function isRootSessionRow(record: JsonRecord): boolean {
|
||||
const metadata =
|
||||
record.metadata && typeof record.metadata === "object"
|
||||
? (record.metadata as JsonRecord)
|
||||
: undefined;
|
||||
return !String(
|
||||
metadata?.parentSessionId ?? record.parentSessionId ?? "",
|
||||
).trim();
|
||||
}
|
||||
|
||||
function messageText(
|
||||
message: unknown,
|
||||
kind: "text" | "thinking" = "text",
|
||||
): string {
|
||||
if (!message || typeof message !== "object" || Array.isArray(message)) {
|
||||
return "";
|
||||
}
|
||||
const content = (message as JsonRecord).content;
|
||||
if (typeof content === "string") {
|
||||
return kind === "text" ? content.trim() : "";
|
||||
}
|
||||
if (!Array.isArray(content)) {
|
||||
return "";
|
||||
}
|
||||
return content
|
||||
.map((part) =>
|
||||
part && typeof part === "object" && !Array.isArray(part)
|
||||
? kind === "thinking" &&
|
||||
(part as JsonRecord).type === "redacted_thinking"
|
||||
? "[redacted]"
|
||||
: String((part as JsonRecord)[kind] ?? "")
|
||||
: "",
|
||||
)
|
||||
.join("")
|
||||
.trim();
|
||||
}
|
||||
|
||||
function normalizeUserPrompt(text: string): string {
|
||||
const trimmed = text.trim();
|
||||
const match = trimmed.match(/^<user_input\b[^>]*>([\s\S]*)<\/user_input>$/);
|
||||
return (match ? match[1] : trimmed).trim();
|
||||
}
|
||||
|
||||
export function countPromptOccurrences(
|
||||
messages: unknown[],
|
||||
prompts: PromptInQueue[],
|
||||
prompt: string,
|
||||
): number {
|
||||
const expected = normalizeUserPrompt(prompt);
|
||||
return (
|
||||
messages.filter(
|
||||
(message) =>
|
||||
Boolean(message) &&
|
||||
typeof message === "object" &&
|
||||
!Array.isArray(message) &&
|
||||
String((message as JsonRecord).role ?? "").toLowerCase() === "user" &&
|
||||
(expected !== "" || isUserRunMessage(message as JsonRecord)) &&
|
||||
normalizeUserPrompt(messageText(message)) === expected,
|
||||
).length +
|
||||
prompts.filter((item) => normalizeUserPrompt(item.prompt) === expected)
|
||||
.length
|
||||
);
|
||||
}
|
||||
|
||||
export function submittedPromptsFromEvents(
|
||||
events: HubEventEnvelope[],
|
||||
): PromptInQueue[] {
|
||||
return events.flatMap((event) => {
|
||||
if (event.event !== "session.pending_prompt_submitted") return [];
|
||||
const prompt =
|
||||
event.payload?.prompt &&
|
||||
typeof event.payload.prompt === "object" &&
|
||||
!Array.isArray(event.payload.prompt)
|
||||
? (event.payload.prompt as JsonRecord)
|
||||
: undefined;
|
||||
const id = String(prompt?.id ?? "").trim();
|
||||
if (!id) return [];
|
||||
return [
|
||||
{
|
||||
id,
|
||||
prompt: String(prompt?.prompt ?? ""),
|
||||
steer: prompt?.delivery === "steer",
|
||||
attachmentCount:
|
||||
typeof prompt?.attachmentCount === "number"
|
||||
? prompt.attachmentCount
|
||||
: 0,
|
||||
userImages: Array.isArray(prompt?.userImages)
|
||||
? prompt.userImages.filter(
|
||||
(image): image is string => typeof image === "string",
|
||||
)
|
||||
: undefined,
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
const TERMINAL_RUN_EVENTS = new Set([
|
||||
"run.completed",
|
||||
"run.aborted",
|
||||
"run.failed",
|
||||
]);
|
||||
const SUPERSEDABLE_CONTENT_EVENTS = new Set([
|
||||
"assistant.delta",
|
||||
"assistant.finished",
|
||||
"reasoning.delta",
|
||||
"reasoning.finished",
|
||||
]);
|
||||
|
||||
function assistantTexts(
|
||||
messages: unknown[],
|
||||
kind: "text" | "thinking",
|
||||
): string[] {
|
||||
return messages
|
||||
.filter(
|
||||
(message): message is JsonRecord =>
|
||||
Boolean(message) &&
|
||||
typeof message === "object" &&
|
||||
!Array.isArray(message) &&
|
||||
String((message as JsonRecord).role ?? "").toLowerCase() ===
|
||||
"assistant",
|
||||
)
|
||||
.map((message) => messageText(message, kind))
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function newlyPersistedAssistantTexts(
|
||||
snapshotMessages: unknown[],
|
||||
baselineMessages: unknown[],
|
||||
kind: "text" | "thinking" = "text",
|
||||
): string[] {
|
||||
const baselineCounts = new Map<string, number>();
|
||||
for (const text of assistantTexts(baselineMessages, kind)) {
|
||||
baselineCounts.set(text, (baselineCounts.get(text) ?? 0) + 1);
|
||||
}
|
||||
return assistantTexts(snapshotMessages, kind).filter((text) => {
|
||||
const count = baselineCounts.get(text) ?? 0;
|
||||
if (count === 0) return true;
|
||||
if (count === 1) baselineCounts.delete(text);
|
||||
else baselineCounts.set(text, count - 1);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function collectToolCallIds(
|
||||
value: unknown,
|
||||
phase: "tool_use" | "tool_result",
|
||||
result = new Set<string>(),
|
||||
): Set<string> {
|
||||
if (!value || typeof value !== "object") return result;
|
||||
if (Array.isArray(value)) {
|
||||
for (const item of value) collectToolCallIds(item, phase, result);
|
||||
return result;
|
||||
}
|
||||
const record = value as JsonRecord;
|
||||
const id = phase === "tool_use" ? record.id : record.tool_use_id;
|
||||
if (record.type === phase && typeof id === "string") {
|
||||
result.add(id);
|
||||
}
|
||||
for (const child of Object.values(record))
|
||||
collectToolCallIds(child, phase, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
function streamedAssistantText(
|
||||
events: HubEventEnvelope[],
|
||||
kind: "assistant" | "reasoning" = "assistant",
|
||||
): string {
|
||||
let finishedText = "";
|
||||
let deltas = "";
|
||||
for (const event of events) {
|
||||
if (event.event === `${kind}.delta`) {
|
||||
deltas +=
|
||||
kind === "reasoning" && event.payload?.redacted && !event.payload?.text
|
||||
? "[redacted]"
|
||||
: typeof event.payload?.text === "string"
|
||||
? event.payload.text
|
||||
: "";
|
||||
} else if (event.event === `${kind}.finished`) {
|
||||
const text = event.payload?.[kind === "assistant" ? "text" : "reasoning"];
|
||||
const completed = typeof text === "string" && text ? text : deltas;
|
||||
if (completed) finishedText = completed;
|
||||
deltas = "";
|
||||
}
|
||||
}
|
||||
return (finishedText || deltas).trim();
|
||||
}
|
||||
|
||||
/** Reconciles each completed run separately; tools dedupe by stable call id. */
|
||||
export function reconcileBufferedCloudEvents(
|
||||
events: HubEventEnvelope[],
|
||||
snapshotMessages: unknown[],
|
||||
options: {
|
||||
/**
|
||||
* Whether a fresh queue snapshot was fetched and applied during
|
||||
* rehydration. When it was, queue events received before its reply are
|
||||
* stale; later events still win. When the fetch failed, the newest
|
||||
* buffered queue event is the best state available.
|
||||
*/
|
||||
queueSnapshotApplied?: boolean;
|
||||
queueSnapshotEventCutoff?: number;
|
||||
/** Events received after the transcript reply cannot be reflected in it. */
|
||||
messagesSnapshotEventCutoff?: number;
|
||||
baselineMessages?: unknown[];
|
||||
} = {},
|
||||
): HubEventEnvelope[] {
|
||||
const queueSnapshotApplied = options.queueSnapshotApplied !== false;
|
||||
const unclaimedAssistantTexts = newlyPersistedAssistantTexts(
|
||||
snapshotMessages,
|
||||
options.baselineMessages ?? [],
|
||||
);
|
||||
const unclaimedThinking = newlyPersistedAssistantTexts(
|
||||
snapshotMessages,
|
||||
options.baselineMessages ?? [],
|
||||
"thinking",
|
||||
);
|
||||
const snapshotToolCallIds = collectToolCallIds(snapshotMessages, "tool_use");
|
||||
const snapshotToolResultIds = collectToolCallIds(
|
||||
snapshotMessages,
|
||||
"tool_result",
|
||||
);
|
||||
const beforeTranscript = new Set(
|
||||
events.slice(0, options.messagesSnapshotEventCutoff ?? events.length),
|
||||
);
|
||||
const reflectedSubmissions = new Set<HubEventEnvelope>();
|
||||
const unclaimedUserCounts = new Map<string, number>();
|
||||
for (const event of events.slice(
|
||||
0,
|
||||
options.messagesSnapshotEventCutoff ?? events.length,
|
||||
)) {
|
||||
const submitted = submittedPromptsFromEvents([event])[0];
|
||||
if (!submitted) continue;
|
||||
const prompt = normalizeUserPrompt(submitted.prompt);
|
||||
const count =
|
||||
unclaimedUserCounts.get(prompt) ??
|
||||
Math.max(
|
||||
0,
|
||||
countPromptOccurrences(snapshotMessages, [], prompt) -
|
||||
countPromptOccurrences(options.baselineMessages ?? [], [], prompt),
|
||||
);
|
||||
unclaimedUserCounts.set(prompt, Math.max(0, count - 1));
|
||||
if (count > 0) reflectedSubmissions.add(event);
|
||||
}
|
||||
// Queue events are full snapshots, so only the newest one matters.
|
||||
const queueEvents = queueSnapshotApplied
|
||||
? events.slice(options.queueSnapshotEventCutoff ?? events.length)
|
||||
: events;
|
||||
const lastQueueEvent = queueEvents.findLast(
|
||||
(event) => event.event === "session.pending_prompts",
|
||||
);
|
||||
const reconciled: HubEventEnvelope[] = [];
|
||||
let segment: HubEventEnvelope[] = [];
|
||||
|
||||
const flush = (terminal: boolean) => {
|
||||
if (segment.length === 0) return;
|
||||
const snapshotSegment = segment.filter((event) =>
|
||||
beforeTranscript.has(event),
|
||||
);
|
||||
// A buffered run can contain saved replies followed by unsaved output.
|
||||
const contentEnd = (kind: "assistant" | "reasoning") => {
|
||||
if (!terminal) return -1;
|
||||
const finished = snapshotSegment.findLastIndex(
|
||||
(event) => event.event === `${kind}.finished`,
|
||||
);
|
||||
return finished >= 0 || segment.at(-1)?.event === "run.aborted"
|
||||
? finished
|
||||
: snapshotSegment.length - 1;
|
||||
};
|
||||
const assistantEnd = contentEnd("assistant");
|
||||
const reasoningEnd = contentEnd("reasoning");
|
||||
const streamed = streamedAssistantText(
|
||||
snapshotSegment.slice(0, assistantEnd + 1),
|
||||
);
|
||||
const persistedIndex = streamed
|
||||
? unclaimedAssistantTexts.findIndex((text) => text.endsWith(streamed))
|
||||
: -1;
|
||||
const contentPersisted = persistedIndex >= 0;
|
||||
if (contentPersisted) unclaimedAssistantTexts.splice(persistedIndex, 1);
|
||||
const thinking = streamedAssistantText(
|
||||
snapshotSegment.slice(0, reasoningEnd + 1),
|
||||
"reasoning",
|
||||
);
|
||||
const thinkingIndex = thinking
|
||||
? unclaimedThinking.findIndex((text) => text.endsWith(thinking))
|
||||
: -1;
|
||||
if (thinkingIndex >= 0) unclaimedThinking.splice(thinkingIndex, 1);
|
||||
for (const [index, event] of segment.entries()) {
|
||||
// Preserve the turn-start lifecycle; the UI must only skip its user bubble.
|
||||
if (reflectedSubmissions.has(event)) {
|
||||
reconciled.push({
|
||||
...event,
|
||||
payload: { ...event.payload, transcriptReflected: true },
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
beforeTranscript.has(event) &&
|
||||
SUPERSEDABLE_CONTENT_EVENTS.has(event.event) &&
|
||||
(event.event.startsWith("reasoning.")
|
||||
? thinkingIndex >= 0 && index <= reasoningEnd
|
||||
: contentPersisted && index <= assistantEnd)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
event.event === "session.pending_prompts" &&
|
||||
event !== lastQueueEvent
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// Keep terminal events: run.failed may carry the only error detail.
|
||||
if (beforeTranscript.has(event) && event.event.startsWith("tool.")) {
|
||||
const toolCallId = String(event.payload?.toolCallId ?? "").trim();
|
||||
if (
|
||||
snapshotToolResultIds.has(toolCallId) ||
|
||||
(event.event === "tool.started" &&
|
||||
snapshotToolCallIds.has(toolCallId))
|
||||
)
|
||||
continue;
|
||||
}
|
||||
reconciled.push(event);
|
||||
}
|
||||
segment = [];
|
||||
};
|
||||
|
||||
for (const event of events) {
|
||||
segment.push(event);
|
||||
if (TERMINAL_RUN_EVENTS.has(event.event)) flush(true);
|
||||
}
|
||||
// Never supersede an unterminated tail.
|
||||
flush(false);
|
||||
return reconciled;
|
||||
}
|
||||
@@ -0,0 +1,820 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
CloudSessionApi,
|
||||
CloudSessionError,
|
||||
type CloudSessionRecord,
|
||||
} from "./cloud-sessions";
|
||||
|
||||
const REMOTE_SESSION: CloudSessionRecord = {
|
||||
id: "ses-outer",
|
||||
status: "ready",
|
||||
sandboxUrl: "https://pod.example/hub",
|
||||
repoContext: { repoUrl: "https://github.com/cline/test" },
|
||||
metadata: { modelId: "anthropic/claude-sonnet-5" },
|
||||
createdAt: "2026-08-05T10:00:00.000Z",
|
||||
updatedAt: "2026-08-05T10:01:00.000Z",
|
||||
};
|
||||
|
||||
function jsonResponse(body: unknown, status = 200): Response {
|
||||
return new Response(JSON.stringify(body), {
|
||||
status,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
function jwtFor(subject: string, nonce: string): string {
|
||||
const encode = (value: unknown) =>
|
||||
Buffer.from(JSON.stringify(value)).toString("base64url");
|
||||
return (
|
||||
"workos:" +
|
||||
encode({ alg: "none" }) +
|
||||
"." +
|
||||
encode({ sub: subject, nonce }) +
|
||||
".sig"
|
||||
);
|
||||
}
|
||||
|
||||
describe("CloudSessionApi", () => {
|
||||
it("resolves a fresh bearer token for every REST request", async () => {
|
||||
const tokens = ["workos:first", "workos:second"];
|
||||
const authorizations: string[] = [];
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example/",
|
||||
appBaseUrl: "https://app.example/",
|
||||
getAuthToken: async () => tokens.shift(),
|
||||
fetch: async (_input, init) => {
|
||||
authorizations.push(
|
||||
new Headers(init?.headers).get("Authorization") ?? "",
|
||||
);
|
||||
return jsonResponse({ success: true, data: [] });
|
||||
},
|
||||
});
|
||||
|
||||
await api.list();
|
||||
await api.list();
|
||||
|
||||
expect(authorizations).toEqual([
|
||||
"Bearer workos:first",
|
||||
"Bearer workos:second",
|
||||
]);
|
||||
});
|
||||
|
||||
it("uses the dashboard create body and includes branch only when requested", async () => {
|
||||
const bodies: Array<Record<string, unknown>> = [];
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "sk_test",
|
||||
fetch: async (_input, init) => {
|
||||
bodies.push(JSON.parse(String(init?.body)));
|
||||
return jsonResponse(
|
||||
{ success: true, data: { sessionId: "ses-1", sandboxUrl: "pod" } },
|
||||
201,
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
await api.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
branch: "feature/login-fix",
|
||||
});
|
||||
await api.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
});
|
||||
|
||||
expect(bodies[0]).toMatchObject({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
branch: "feature/login-fix",
|
||||
title: expect.stringMatching(/^__cline_create_request__:/),
|
||||
});
|
||||
expect(bodies[1]).toMatchObject({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
title: expect.stringMatching(/^__cline_create_request__:/),
|
||||
});
|
||||
expect(bodies[1]).not.toHaveProperty("branch");
|
||||
});
|
||||
|
||||
it("treats a missing history snapshot (404) as null, not an empty archive", async () => {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "sk_test",
|
||||
fetch: async () => new Response("not found", { status: 404 }),
|
||||
});
|
||||
|
||||
expect(await api.history("ses-1")).toBeNull();
|
||||
});
|
||||
|
||||
it("accepts v1 history and rejects malformed snapshots instead of returning empty history", async () => {
|
||||
const messages = [{ role: "user", content: "Hello" }];
|
||||
let snapshot: unknown = { version: 1, messages };
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "sk_test",
|
||||
fetch: async () => jsonResponse(snapshot),
|
||||
});
|
||||
|
||||
expect(await api.history("ses-1")).toEqual(messages);
|
||||
snapshot = { version: 1, messages: [] };
|
||||
expect(await api.history("ses-1")).toEqual([]);
|
||||
for (const invalid of [
|
||||
null,
|
||||
{ version: 1 },
|
||||
{ version: 2, messages: [] },
|
||||
]) {
|
||||
snapshot = invalid;
|
||||
await expect(api.history("ses-1")).rejects.toMatchObject({
|
||||
code: "request_failed",
|
||||
detail: "Invalid archived session history",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("returns the real id before polling readiness and reports provisioning phases", async () => {
|
||||
vi.useFakeTimers();
|
||||
const tokens = ["workos:create", "workos:create", "workos:new-account"];
|
||||
const authorizations: string[] = [];
|
||||
let statusCalls = 0;
|
||||
const phases: Array<string | undefined> = [];
|
||||
try {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => tokens.shift(),
|
||||
fetch: async (input, init) => {
|
||||
authorizations.push(
|
||||
new Headers(init?.headers).get("Authorization") ?? "",
|
||||
);
|
||||
const url = new URL(String(input));
|
||||
if (init?.method === "POST") {
|
||||
return jsonResponse(
|
||||
{
|
||||
success: true,
|
||||
data: { sessionId: "ses-1", status: "provisioning" },
|
||||
},
|
||||
201,
|
||||
);
|
||||
}
|
||||
expect(url.pathname).toBe("/api/v1/session/ses-1/status");
|
||||
statusCalls += 1;
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: {
|
||||
sessionId: "ses-1",
|
||||
status: statusCalls === 1 ? "provisioning" : "ready",
|
||||
phase: statusCalls === 1 ? "cloning_repo" : "ready",
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const created = await api.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
});
|
||||
expect(created).toMatchObject({
|
||||
sessionId: "ses-1",
|
||||
status: "provisioning",
|
||||
});
|
||||
expect(statusCalls).toBe(0);
|
||||
const ready = api.waitUntilReady(
|
||||
created.sessionId,
|
||||
new AbortController().signal,
|
||||
({ phase }) => phases.push(phase),
|
||||
);
|
||||
await vi.waitFor(() => expect(statusCalls).toBe(1));
|
||||
await vi.advanceTimersByTimeAsync(3_000);
|
||||
|
||||
await expect(ready).resolves.toBeUndefined();
|
||||
expect(statusCalls).toBe(2);
|
||||
expect(phases).toEqual(["cloning_repo", "ready"]);
|
||||
expect(authorizations).toEqual([
|
||||
"Bearer workos:create",
|
||||
"Bearer workos:create",
|
||||
"Bearer workos:create",
|
||||
]);
|
||||
expect(tokens).toEqual(["workos:new-account"]);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("refreshes an expired provisioning token without switching accounts", async () => {
|
||||
const original = jwtFor("user-1", "original");
|
||||
const refreshed = jwtFor("user-1", "refreshed");
|
||||
const tokens = [original, refreshed];
|
||||
const authorizations: string[] = [];
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => tokens.shift(),
|
||||
fetch: async (_input, init) => {
|
||||
const authorization =
|
||||
new Headers(init?.headers).get("Authorization") ?? "";
|
||||
authorizations.push(authorization);
|
||||
if (authorization === `Bearer ${original}`) {
|
||||
return jsonResponse(
|
||||
{ success: false, error: "authentication required" },
|
||||
401,
|
||||
);
|
||||
}
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: { sessionId: "ses-1", status: "ready" },
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
api.waitUntilReady("ses-1", new AbortController().signal),
|
||||
).resolves.toBeUndefined();
|
||||
expect(authorizations).toEqual([
|
||||
`Bearer ${original}`,
|
||||
`Bearer ${refreshed}`,
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not switch accounts while refreshing provisioning auth", async () => {
|
||||
const original = jwtFor("user-1", "original");
|
||||
const otherAccount = jwtFor("user-2", "refreshed");
|
||||
const tokens = [original, otherAccount];
|
||||
let statusCalls = 0;
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => tokens.shift(),
|
||||
fetch: async () => {
|
||||
statusCalls += 1;
|
||||
return jsonResponse(
|
||||
{ success: false, error: "authentication required" },
|
||||
401,
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
api.waitUntilReady("ses-1", new AbortController().signal),
|
||||
).rejects.toMatchObject({ code: "authentication_required" });
|
||||
expect(statusCalls).toBe(1);
|
||||
});
|
||||
|
||||
it("returns a recovered real id without waiting for provisioning", async () => {
|
||||
const requests: string[] = [];
|
||||
let recoveryTitle = "";
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
fetch: async (input, init) => {
|
||||
requests.push(
|
||||
`${init?.method ?? "GET"} ${new URL(String(input)).pathname}`,
|
||||
);
|
||||
if (init?.method === "POST") {
|
||||
recoveryTitle = String(JSON.parse(String(init.body)).title);
|
||||
return jsonResponse({ success: false, error: "gateway" }, 500);
|
||||
}
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
...REMOTE_SESSION,
|
||||
id: "ses-recovered",
|
||||
title: recoveryTitle,
|
||||
status: "provisioning",
|
||||
sandboxUrl: "",
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
api.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
sessionId: "ses-recovered",
|
||||
status: "provisioning",
|
||||
});
|
||||
expect(requests).toEqual(["POST /api/v1/session", "GET /api/v1/session"]);
|
||||
});
|
||||
|
||||
it("recovers the real id after the create request times out", async () => {
|
||||
vi.useFakeTimers();
|
||||
const requests: string[] = [];
|
||||
let recoveryTitle = "";
|
||||
try {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
createTimeoutMs: 100,
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
fetch: async (input, init) => {
|
||||
requests.push(
|
||||
`${init?.method ?? "GET"} ${new URL(String(input)).pathname}`,
|
||||
);
|
||||
if (init?.method === "POST") {
|
||||
recoveryTitle = String(JSON.parse(String(init.body)).title);
|
||||
return await new Promise<Response>((_resolve, reject) => {
|
||||
init.signal?.addEventListener(
|
||||
"abort",
|
||||
() => reject(init.signal?.reason),
|
||||
{ once: true },
|
||||
);
|
||||
});
|
||||
}
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
...REMOTE_SESSION,
|
||||
id: "ses-recovered",
|
||||
title: recoveryTitle,
|
||||
status: "provisioning",
|
||||
sandboxUrl: "",
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const creating = api.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
});
|
||||
await vi.advanceTimersByTimeAsync(100);
|
||||
|
||||
await expect(creating).resolves.toMatchObject({
|
||||
sessionId: "ses-recovered",
|
||||
});
|
||||
expect(requests).toEqual(["POST /api/v1/session", "GET /api/v1/session"]);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("returns a failed recovered session without hiding its real id", async () => {
|
||||
let recoveryTitle = "";
|
||||
const requests: string[] = [];
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
fetch: async (input, init) => {
|
||||
requests.push(
|
||||
`${init?.method ?? "GET"} ${new URL(String(input)).pathname}`,
|
||||
);
|
||||
if (init?.method === "POST") {
|
||||
recoveryTitle = String(JSON.parse(String(init.body)).title);
|
||||
return jsonResponse({ success: false, error: "gateway" }, 500);
|
||||
}
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
...REMOTE_SESSION,
|
||||
title: recoveryTitle,
|
||||
status: "failed",
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
api.create({
|
||||
modelId: REMOTE_SESSION.metadata.modelId ?? "",
|
||||
repoUrl: REMOTE_SESSION.repoContext.repoUrl ?? "",
|
||||
}),
|
||||
).resolves.toMatchObject({ sessionId: "ses-outer", status: "failed" });
|
||||
expect(requests).toEqual(["POST /api/v1/session", "GET /api/v1/session"]);
|
||||
});
|
||||
|
||||
it("recovers a create accepted before a raw network failure", async () => {
|
||||
let recoveryTitle = "";
|
||||
let listCalls = 0;
|
||||
const now = new Date().toISOString();
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "sk_test",
|
||||
fetch: async (_input, init) => {
|
||||
if (init?.method === "POST") {
|
||||
recoveryTitle = String(JSON.parse(String(init.body)).title);
|
||||
throw new TypeError("fetch failed");
|
||||
}
|
||||
listCalls += 1;
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
...REMOTE_SESSION,
|
||||
id: "ses-recovered",
|
||||
title: recoveryTitle,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
api.create({
|
||||
requestId: "request-a",
|
||||
modelId: REMOTE_SESSION.metadata.modelId ?? "",
|
||||
repoUrl: REMOTE_SESSION.repoContext.repoUrl ?? "",
|
||||
}),
|
||||
).resolves.toMatchObject({ sessionId: "ses-recovered" });
|
||||
expect(listCalls).toBe(1);
|
||||
});
|
||||
|
||||
it("does not recover another process's identical session", async () => {
|
||||
const now = new Date().toISOString();
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "sk_test",
|
||||
fetch: async (_input, init) =>
|
||||
init?.method === "POST"
|
||||
? jsonResponse({ success: false, error: "gateway timeout" }, 500)
|
||||
: jsonResponse({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
...REMOTE_SESSION,
|
||||
id: "ses-other-process",
|
||||
title: "__cline_create_request__:other-request",
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
|
||||
await expect(
|
||||
api.create({
|
||||
requestId: "this-request",
|
||||
modelId: REMOTE_SESSION.metadata.modelId ?? "",
|
||||
repoUrl: REMOTE_SESSION.repoContext.repoUrl ?? "",
|
||||
}),
|
||||
).rejects.toMatchObject({ code: "request_failed" });
|
||||
});
|
||||
|
||||
it("hides temporary create request titles from session lists", async () => {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "sk_test",
|
||||
fetch: async () =>
|
||||
jsonResponse({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
...REMOTE_SESSION,
|
||||
title: "__cline_create_request__:request-a",
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
|
||||
await expect(api.list()).resolves.toEqual([
|
||||
expect.objectContaining({
|
||||
id: "ses-outer",
|
||||
title: undefined,
|
||||
metadata: expect.objectContaining({
|
||||
createRequestTitle: "__cline_create_request__:request-a",
|
||||
}),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("returns a stable, environment-aware GitHub connection error", async () => {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://staging-app.example/",
|
||||
getAuthToken: async () => "workos:test",
|
||||
fetch: async () =>
|
||||
jsonResponse({ success: false, error: "GitHub is not connected" }, 412),
|
||||
});
|
||||
|
||||
const error = await api
|
||||
.create({ modelId: "model", repoUrl: "https://github.com/cline/test" })
|
||||
.catch((caught) => caught);
|
||||
|
||||
expect(error).toBeInstanceOf(CloudSessionError);
|
||||
expect(error.code).toBe("github_not_connected");
|
||||
expect(error.message).toBe(
|
||||
'CLOUD_SESSION_ERROR:{"code":"github_not_connected","message":"GitHub is not connected","connectUrl":"https://staging-app.example/dashboard/integrations"}',
|
||||
);
|
||||
});
|
||||
|
||||
it("routes organization GitHub setup to organization integrations", async () => {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://staging-app.example/",
|
||||
getAuthToken: async () => "workos:test",
|
||||
fetch: async () =>
|
||||
jsonResponse({ success: false, error: "GitHub is not connected" }, 412),
|
||||
});
|
||||
|
||||
const error = await api
|
||||
.create({
|
||||
modelId: "model",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
organizationId: "org-cline-bot",
|
||||
})
|
||||
.catch((caught) => caught);
|
||||
|
||||
expect(error).toBeInstanceOf(CloudSessionError);
|
||||
expect(error.connectUrl).toBe(
|
||||
"https://staging-app.example/dashboard/organization/integrations",
|
||||
);
|
||||
});
|
||||
|
||||
it("lists connected GitHub repositories and their branches", async () => {
|
||||
const requestedPaths: string[] = [];
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "workos:test",
|
||||
fetch: async (input) => {
|
||||
const path = new URL(String(input)).pathname;
|
||||
requestedPaths.push(path);
|
||||
if (path.endsWith("/branches")) {
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: [{ name: "main" }, { name: "feature/cloud" }],
|
||||
});
|
||||
}
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
id: 42,
|
||||
name: "cline",
|
||||
full_name: "cline/cline",
|
||||
html_url: "https://github.com/cline/cline",
|
||||
clone_url: "https://github.com/cline/cline.git",
|
||||
default_branch: "main",
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
expect(await api.listRepositories()).toEqual({
|
||||
connected: true,
|
||||
connectUrl: "https://app.example/dashboard/integrations",
|
||||
repositories: [
|
||||
{
|
||||
id: 42,
|
||||
name: "cline",
|
||||
fullName: "cline/cline",
|
||||
url: "https://github.com/cline/cline",
|
||||
defaultBranch: "main",
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(await api.listBranches(42)).toEqual({
|
||||
available: true,
|
||||
branches: ["main", "feature/cloud"],
|
||||
nextToken: "",
|
||||
});
|
||||
expect(requestedPaths).toEqual([
|
||||
"/api/v1/integrations/github/repositories",
|
||||
"/api/v1/integrations/github/repositories/42/branches",
|
||||
]);
|
||||
});
|
||||
|
||||
it("reads paginated branch responses and forwards search cursors", async () => {
|
||||
let requestedUrl = "";
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "workos:test",
|
||||
fetch: async (input) => {
|
||||
requestedUrl = String(input);
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: {
|
||||
items: [{ name: "feature/cloud" }],
|
||||
nextToken: "next/page",
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
await api.listBranches(42, undefined, {
|
||||
cursor: "search cursor",
|
||||
query: "feature/cloud",
|
||||
}),
|
||||
).toEqual({
|
||||
available: true,
|
||||
branches: ["feature/cloud"],
|
||||
nextToken: "next/page",
|
||||
});
|
||||
const url = new URL(requestedUrl);
|
||||
expect(url.pathname).toBe(
|
||||
"/api/v1/integrations/github/repositories/42/branches",
|
||||
);
|
||||
expect(url.searchParams.get("query")).toBe("feature/cloud");
|
||||
expect(url.searchParams.get("cursor")).toBe("search cursor");
|
||||
});
|
||||
|
||||
it("filters legacy branch responses while backends roll out", async () => {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "workos:test",
|
||||
fetch: async () =>
|
||||
jsonResponse({
|
||||
success: true,
|
||||
data: [{ name: "main" }, { name: "feature/cloud" }],
|
||||
}),
|
||||
});
|
||||
|
||||
expect(await api.listBranches(42, undefined, { query: "FEATURE" })).toEqual(
|
||||
{
|
||||
available: true,
|
||||
branches: ["feature/cloud"],
|
||||
nextToken: "",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to the repository default when the branch API is unavailable", async () => {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "workos:test",
|
||||
fetch: async () =>
|
||||
jsonResponse({ success: false, error: "route not found" }, 404),
|
||||
});
|
||||
|
||||
expect(await api.listBranches(42)).toEqual({
|
||||
available: false,
|
||||
branches: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("uses organization-scoped repository and branch endpoints", async () => {
|
||||
const requestedPaths: string[] = [];
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "workos:test",
|
||||
fetch: async (input) => {
|
||||
const path = new URL(String(input)).pathname;
|
||||
requestedPaths.push(path);
|
||||
return jsonResponse({ success: true, data: [] });
|
||||
},
|
||||
});
|
||||
|
||||
expect(await api.listRepositories("org-cline-bot")).toMatchObject({
|
||||
connected: true,
|
||||
connectUrl: "https://app.example/dashboard/organization/integrations",
|
||||
});
|
||||
await api.listBranches(42, "org-cline-bot");
|
||||
expect(requestedPaths).toEqual([
|
||||
"/api/v1/organizations/org-cline-bot/integrations/github/repositories",
|
||||
"/api/v1/organizations/org-cline-bot/integrations/github/repositories/42/branches",
|
||||
]);
|
||||
});
|
||||
|
||||
it("refuses ambiguous recovery for overlapping identical create requests", async () => {
|
||||
const now = new Date().toISOString();
|
||||
const record = (id: string, createdAt: string) => ({
|
||||
id,
|
||||
title: "__cline_create_request__:same-request",
|
||||
status: "running",
|
||||
sandboxUrl: `pod-${id}`,
|
||||
repoContext: { repoUrl: "https://github.com/cline/test" },
|
||||
metadata: { modelId: "anthropic/claude-sonnet-5" },
|
||||
createdAt,
|
||||
updatedAt: createdAt,
|
||||
});
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "sk_test",
|
||||
fetch: async (_input, init) =>
|
||||
init?.method === "POST"
|
||||
? jsonResponse({ success: false, error: "gateway timeout" }, 500)
|
||||
: jsonResponse({
|
||||
success: true,
|
||||
data: [
|
||||
record("ses-newer", now),
|
||||
record("ses-older", new Date(Date.now() - 1_000).toISOString()),
|
||||
],
|
||||
}),
|
||||
});
|
||||
const input = {
|
||||
requestId: "same-request",
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
};
|
||||
|
||||
const error = await api.create(input).catch((caught) => caught);
|
||||
expect(error).toMatchObject({ code: "request_failed" });
|
||||
expect(String(error)).toContain("ambiguous result");
|
||||
});
|
||||
|
||||
it("reports provisioning failure without deleting the known session", async () => {
|
||||
const authorizations: string[] = [];
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "workos:create",
|
||||
fetch: async (input, init) => {
|
||||
authorizations.push(
|
||||
new Headers(init?.headers).get("Authorization") ?? "",
|
||||
);
|
||||
expect(new URL(String(input)).pathname).toBe(
|
||||
"/api/v1/session/ses-failed/status",
|
||||
);
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
data: {
|
||||
sessionId: "ses-failed",
|
||||
status: "failed",
|
||||
statusReason: "clone failed",
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
api.waitUntilReady("ses-failed", new AbortController().signal),
|
||||
).rejects.toMatchObject({ code: "session_failed", detail: "clone failed" });
|
||||
expect(authorizations).toEqual(["Bearer workos:create"]);
|
||||
});
|
||||
|
||||
it("turns a generic forbidden response into actionable account guidance", async () => {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "workos:test",
|
||||
fetch: async () =>
|
||||
jsonResponse({ success: false, error: "forbidden" }, 403),
|
||||
});
|
||||
|
||||
const error = await api
|
||||
.create({ modelId: "model", repoUrl: "https://github.com/cline/test" })
|
||||
.catch((caught) => caught);
|
||||
|
||||
expect(error).toBeInstanceOf(CloudSessionError);
|
||||
expect(error.code).toBe("request_failed");
|
||||
expect(error.status).toBe(403);
|
||||
expect(error.message).toContain(
|
||||
"Switch to Personal or another organization in Settings → Account",
|
||||
);
|
||||
});
|
||||
|
||||
it("does not run list recovery after a fast client-side rejection", async () => {
|
||||
let listRequests = 0;
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example",
|
||||
getAuthToken: async () => "sk_test",
|
||||
fetch: async (_input, init) => {
|
||||
if (init?.method === "POST") {
|
||||
return jsonResponse({ success: false, error: "invalid branch" }, 422);
|
||||
}
|
||||
listRequests += 1;
|
||||
return jsonResponse({ success: true, data: [] });
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
api.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
}),
|
||||
).rejects.toThrow(/invalid branch/);
|
||||
expect(listRequests).toBe(0);
|
||||
});
|
||||
|
||||
it("returns the GitHub connection action when no integration exists", async () => {
|
||||
const api = new CloudSessionApi({
|
||||
apiBaseUrl: "https://api.example",
|
||||
appBaseUrl: "https://app.example/",
|
||||
getAuthToken: async () => "workos:test",
|
||||
fetch: async () =>
|
||||
jsonResponse({ success: false, error: "not connected" }, 404),
|
||||
});
|
||||
|
||||
expect(await api.listRepositories()).toEqual({
|
||||
connected: false,
|
||||
connectUrl: "https://app.example/dashboard/integrations",
|
||||
repositories: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,431 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
type CloudSessionApi,
|
||||
CloudSessionError,
|
||||
CloudSessionManager,
|
||||
type CloudSessionRecord,
|
||||
cloudSessionToDiscoveryRecord,
|
||||
} from "./cloud-sessions";
|
||||
import type { SidecarContext } from "./types";
|
||||
|
||||
const REMOTE_SESSION: CloudSessionRecord = {
|
||||
id: "ses-outer",
|
||||
status: "ready",
|
||||
sandboxUrl: "https://pod.example/hub",
|
||||
repoContext: { repoUrl: "https://github.com/cline/test" },
|
||||
metadata: { modelId: "anthropic/claude-sonnet-5" },
|
||||
createdAt: "2026-08-05T10:00:00.000Z",
|
||||
updatedAt: "2026-08-05T10:01:00.000Z",
|
||||
};
|
||||
|
||||
function createContext(): { ctx: SidecarContext } {
|
||||
const ctx = {
|
||||
liveSessions: new Map(),
|
||||
restoringWorkspacePaths: new Set(),
|
||||
streamIndices: new Map(),
|
||||
coreStreamActivity: new Map(),
|
||||
bootId: "cloud-test-boot",
|
||||
wsClients: new Set([
|
||||
{
|
||||
data: { canApproveTools: true },
|
||||
send() {},
|
||||
},
|
||||
]),
|
||||
pendingApprovals: new Map(),
|
||||
pendingQuestions: new Map(),
|
||||
sessionManager: null,
|
||||
cloudSessionManager: null,
|
||||
hubClient: null,
|
||||
workspaceRoot: "/local/workspace",
|
||||
unsubscribeSessionEvents: null,
|
||||
hubBuildMismatch: null,
|
||||
} as SidecarContext;
|
||||
return { ctx };
|
||||
}
|
||||
|
||||
describe("CloudSessionManager lifecycle", () => {
|
||||
it.each([
|
||||
"upstream request failed",
|
||||
"couldn't authenticate with GitHub; try reconnecting the integration",
|
||||
])("surfaces create failure without retrying: %s", async (message) => {
|
||||
const { ctx } = createContext();
|
||||
const create = vi.fn(async () => {
|
||||
throw new CloudSessionError("request_failed", message, undefined, 502);
|
||||
});
|
||||
const manager = new CloudSessionManager(ctx, {
|
||||
api: { create } as unknown as CloudSessionApi,
|
||||
apiBaseUrl: "https://api.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
});
|
||||
|
||||
await expect(
|
||||
manager.create({
|
||||
modelId: "model",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
}),
|
||||
).rejects.toThrow(message);
|
||||
expect(create).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("projects the outer remote-session id as the desktop session id", () => {
|
||||
expect(
|
||||
cloudSessionToDiscoveryRecord({
|
||||
...REMOTE_SESSION,
|
||||
repoContext: {
|
||||
...REMOTE_SESSION.repoContext,
|
||||
branch: "feature/cloud",
|
||||
},
|
||||
}),
|
||||
).toMatchObject({
|
||||
sessionId: "ses-outer",
|
||||
origin: "cloud",
|
||||
executionTarget: "cloud",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
workspaceRoot: "/workspace",
|
||||
branch: "feature/cloud",
|
||||
metadata: {
|
||||
git: {
|
||||
url: "https://github.com/cline/test",
|
||||
branch: "feature/cloud",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("treats a live session's future expiredAt as a TTL, not an end time", () => {
|
||||
const alive = cloudSessionToDiscoveryRecord({
|
||||
...REMOTE_SESSION,
|
||||
expiredAt: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
|
||||
});
|
||||
expect(alive.endedAt).toBeUndefined();
|
||||
|
||||
const expired = cloudSessionToDiscoveryRecord({
|
||||
...REMOTE_SESSION,
|
||||
expiredAt: "2026-08-01T00:00:00.000Z",
|
||||
});
|
||||
expect(expired.endedAt).toBe("2026-08-01T00:00:00.000Z");
|
||||
});
|
||||
|
||||
it("overlays live status and prompt-derived title on refreshed REST rows", async () => {
|
||||
const { ctx } = createContext();
|
||||
ctx.liveSessions.set("ses-outer", {
|
||||
config: { executionTarget: "cloud" },
|
||||
messages: [],
|
||||
promptsInQueue: [],
|
||||
busy: true,
|
||||
startedAt: Date.now(),
|
||||
status: "running",
|
||||
prompt: "Fix reconnect behavior\nwith a regression test",
|
||||
attachedViaHub: true,
|
||||
});
|
||||
const manager = new CloudSessionManager(ctx, {
|
||||
api: { list: async () => [REMOTE_SESSION] } as CloudSessionApi,
|
||||
apiBaseUrl: "https://api.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
});
|
||||
|
||||
const [session] = await manager.listForDiscovery();
|
||||
|
||||
expect(session).toMatchObject({
|
||||
sessionId: "ses-outer",
|
||||
origin: "cloud",
|
||||
status: "running",
|
||||
prompt: "Fix reconnect behavior\nwith a regression test",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
metadata: {
|
||||
title: "Fix reconnect behavior",
|
||||
origin: "cloud",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
"expired",
|
||||
"failed",
|
||||
] as const)("reconciles a %s session without a Hub connection", async (status) => {
|
||||
const { ctx } = createContext();
|
||||
const remote: CloudSessionRecord = { ...REMOTE_SESSION };
|
||||
const manager = new CloudSessionManager(ctx, {
|
||||
api: {
|
||||
create: async () => ({
|
||||
sessionId: remote.id,
|
||||
status: "provisioning",
|
||||
sandboxUrl: "",
|
||||
}),
|
||||
list: async () => [remote],
|
||||
} as unknown as CloudSessionApi,
|
||||
apiBaseUrl: "https://api.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
});
|
||||
await manager.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
});
|
||||
expect((await manager.listForDiscovery())[0].status).toBe("ready");
|
||||
|
||||
const endedAt = new Date(Date.now() - 1_000).toISOString();
|
||||
if (status === "expired") {
|
||||
remote.expiredAt = endedAt;
|
||||
} else {
|
||||
remote.status = "failed";
|
||||
remote.lastActivityAt = endedAt;
|
||||
}
|
||||
expect((await manager.listForDiscovery())[0]).toMatchObject({
|
||||
status,
|
||||
endedAt,
|
||||
});
|
||||
expect(ctx.liveSessions.get(remote.id)).toMatchObject({
|
||||
status,
|
||||
busy: false,
|
||||
endedAt: Date.parse(endedAt),
|
||||
});
|
||||
if (status === "failed") {
|
||||
remote.title = "Renamed after failure";
|
||||
remote.updatedAt = new Date().toISOString();
|
||||
expect((await manager.listForDiscovery())[0].endedAt).toBe(endedAt);
|
||||
const live = ctx.liveSessions.get(remote.id)!;
|
||||
ctx.liveSessions.clear();
|
||||
expect((await manager.listForDiscovery())[0].endedAt).toBe(endedAt);
|
||||
|
||||
const hubEndedAt = Date.parse(endedAt) + 500;
|
||||
live.endedAt = hubEndedAt;
|
||||
ctx.liveSessions.set(remote.id, live);
|
||||
expect((await manager.listForDiscovery())[0].endedAt).toBe(
|
||||
new Date(hubEndedAt).toISOString(),
|
||||
);
|
||||
ctx.liveSessions.clear();
|
||||
delete remote.lastActivityAt;
|
||||
expect((await manager.listForDiscovery())[0].endedAt).toBe(
|
||||
remote.createdAt,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("single-flights repeated starts for the same client request", async () => {
|
||||
const { ctx } = createContext();
|
||||
let createCalls = 0;
|
||||
let finishCreate:
|
||||
| ((value: {
|
||||
sessionId: string;
|
||||
status: string;
|
||||
sandboxUrl: string;
|
||||
}) => void)
|
||||
| undefined;
|
||||
const manager = new CloudSessionManager(ctx, {
|
||||
api: {
|
||||
list: async () => [],
|
||||
create: () => {
|
||||
createCalls += 1;
|
||||
return new Promise((resolve) => {
|
||||
finishCreate = resolve;
|
||||
});
|
||||
},
|
||||
} as unknown as CloudSessionApi,
|
||||
apiBaseUrl: "https://api.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
});
|
||||
const input = {
|
||||
requestId: "client-start-1",
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
};
|
||||
|
||||
const first = manager.create(input);
|
||||
const second = manager.create(input);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
expect(createCalls).toBe(1);
|
||||
expect(await manager.listForDiscovery()).toEqual([]);
|
||||
|
||||
finishCreate?.({
|
||||
sessionId: "ses-created",
|
||||
status: "provisioning",
|
||||
sandboxUrl: "",
|
||||
});
|
||||
await expect(Promise.all([first, second])).resolves.toEqual([
|
||||
expect.objectContaining({ sessionId: "ses-created" }),
|
||||
expect.objectContaining({ sessionId: "ses-created" }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps identical starts from separate chats independent", async () => {
|
||||
const { ctx } = createContext();
|
||||
let createCalls = 0;
|
||||
const manager = new CloudSessionManager(ctx, {
|
||||
api: {
|
||||
list: async () => [],
|
||||
create: async () => {
|
||||
createCalls += 1;
|
||||
return {
|
||||
sessionId: `ses-created-${createCalls}`,
|
||||
status: "provisioning",
|
||||
sandboxUrl: "pod",
|
||||
};
|
||||
},
|
||||
} as unknown as CloudSessionApi,
|
||||
apiBaseUrl: "https://api.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
});
|
||||
const input = {
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
};
|
||||
|
||||
const [first, second] = await Promise.all([
|
||||
manager.create({ ...input, requestId: "chat-a" }),
|
||||
manager.create({ ...input, requestId: "chat-b" }),
|
||||
]);
|
||||
|
||||
expect(createCalls).toBe(2);
|
||||
expect(first.sessionId).not.toBe(second.sessionId);
|
||||
});
|
||||
|
||||
it("returns cached cloud discovery promptly while a refresh is slow", async () => {
|
||||
const { ctx } = createContext();
|
||||
let listCalls = 0;
|
||||
let finishRefresh: ((value: CloudSessionRecord[]) => void) | undefined;
|
||||
const manager = new CloudSessionManager(ctx, {
|
||||
api: {
|
||||
list: async () => {
|
||||
listCalls += 1;
|
||||
if (listCalls === 1) return [REMOTE_SESSION];
|
||||
return await new Promise((resolve) => {
|
||||
finishRefresh = resolve;
|
||||
});
|
||||
},
|
||||
} as unknown as CloudSessionApi,
|
||||
apiBaseUrl: "https://api.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
});
|
||||
await manager.listForDiscovery();
|
||||
|
||||
const cached = await manager.listForDiscovery({ timeoutMs: 1 });
|
||||
|
||||
expect(cached).toEqual([
|
||||
expect.objectContaining({ sessionId: "ses-outer", origin: "cloud" }),
|
||||
]);
|
||||
finishRefresh?.([]);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
});
|
||||
|
||||
it("uses only the active organization for billing and session listing", async () => {
|
||||
const { ctx } = createContext();
|
||||
const listCalls: Array<string | undefined> = [];
|
||||
const repositoryScopes: Array<string | undefined> = [];
|
||||
const branchScopes: Array<string | undefined> = [];
|
||||
let createInput: Record<string, unknown> | undefined;
|
||||
const orgSession = { ...REMOTE_SESSION, id: "ses-org", title: undefined };
|
||||
const manager = new CloudSessionManager(ctx, {
|
||||
api: {
|
||||
list: async (organizationId?: string) => {
|
||||
listCalls.push(organizationId);
|
||||
return organizationId
|
||||
? [orgSession]
|
||||
: [{ ...REMOTE_SESSION, title: undefined }];
|
||||
},
|
||||
create: async (input: Record<string, unknown>) => {
|
||||
createInput = input;
|
||||
return {
|
||||
sessionId: "ses-created",
|
||||
status: "provisioning",
|
||||
sandboxUrl: "",
|
||||
};
|
||||
},
|
||||
listRepositories: async (organizationId?: string) => {
|
||||
repositoryScopes.push(organizationId);
|
||||
return { connected: true, connectUrl: "", repositories: [] };
|
||||
},
|
||||
listBranches: async (
|
||||
_repositoryId: number,
|
||||
organizationId?: string,
|
||||
) => {
|
||||
branchScopes.push(organizationId);
|
||||
return { available: true, branches: [] };
|
||||
},
|
||||
} as unknown as CloudSessionApi,
|
||||
apiBaseUrl: "https://api.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
getActiveOrganizationId: async () => "org-cline-bot",
|
||||
});
|
||||
const scoped = await manager.list();
|
||||
expect(listCalls).toEqual(["org-cline-bot"]);
|
||||
expect(scoped.map((session) => session.id)).toEqual(["ses-org"]);
|
||||
await manager.listRepositories();
|
||||
await manager.listBranches(42);
|
||||
expect(repositoryScopes).toEqual(["org-cline-bot"]);
|
||||
expect(branchScopes).toEqual(["org-cline-bot"]);
|
||||
|
||||
await manager.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
});
|
||||
expect(createInput).toMatchObject({ organizationId: "org-cline-bot" });
|
||||
});
|
||||
|
||||
it("refreshes the active organization before creating a session", async () => {
|
||||
const { ctx } = createContext();
|
||||
let serverScope = "org-a";
|
||||
let cachedScope = serverScope;
|
||||
const lookupOptions: Array<{ fresh?: boolean } | undefined> = [];
|
||||
let createInput: Record<string, unknown> | undefined;
|
||||
const manager = new CloudSessionManager(ctx, {
|
||||
api: {
|
||||
list: async () => [],
|
||||
create: async (input: Record<string, unknown>) => {
|
||||
createInput = input;
|
||||
return {
|
||||
sessionId: "ses-created",
|
||||
status: "provisioning",
|
||||
sandboxUrl: "",
|
||||
};
|
||||
},
|
||||
} as unknown as CloudSessionApi,
|
||||
apiBaseUrl: "https://api.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
getActiveOrganizationId: async (options) => {
|
||||
lookupOptions.push(options);
|
||||
if (options?.fresh) cachedScope = serverScope;
|
||||
return cachedScope;
|
||||
},
|
||||
});
|
||||
|
||||
await manager.list();
|
||||
serverScope = "org-b";
|
||||
await manager.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
});
|
||||
|
||||
expect(lookupOptions).toEqual([undefined, { fresh: true }]);
|
||||
expect(createInput).toMatchObject({ organizationId: "org-b" });
|
||||
});
|
||||
|
||||
it("does not silently bill personal credits when account scope lookup fails", async () => {
|
||||
const { ctx } = createContext();
|
||||
let createInput: Record<string, unknown> | undefined;
|
||||
const manager = new CloudSessionManager(ctx, {
|
||||
api: {
|
||||
list: async () => [],
|
||||
create: async (input: Record<string, unknown>) => {
|
||||
createInput = input;
|
||||
return {
|
||||
sessionId: "ses-created",
|
||||
status: "provisioning",
|
||||
sandboxUrl: "",
|
||||
};
|
||||
},
|
||||
} as unknown as CloudSessionApi,
|
||||
apiBaseUrl: "https://api.example",
|
||||
getAuthToken: async () => "workos:fresh",
|
||||
getActiveOrganizationId: async () => {
|
||||
throw new Error("account endpoint down");
|
||||
},
|
||||
});
|
||||
await expect(
|
||||
manager.create({
|
||||
modelId: "anthropic/claude-sonnet-5",
|
||||
repoUrl: "https://github.com/cline/test",
|
||||
}),
|
||||
).rejects.toThrow("account endpoint down");
|
||||
expect(createInput?.organizationId).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,11 @@ const getProviderSettingsMock = vi.hoisted(() => vi.fn());
|
||||
const saveProviderSettingsMock = vi.hoisted(() => vi.fn());
|
||||
const persistProviderSettingsMock = vi.hoisted(() => vi.fn());
|
||||
const resolveProviderApiKeyMock = vi.hoisted(() => vi.fn());
|
||||
const clearLegacyProviderCredentialsMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("./legacy-provider-credentials", () => ({
|
||||
clearLegacyProviderCredentials: clearLegacyProviderCredentialsMock,
|
||||
}));
|
||||
|
||||
vi.mock("@cline/core", async () => {
|
||||
const actual =
|
||||
@@ -59,6 +64,7 @@ beforeEach(() => {
|
||||
saveProviderSettingsMock.mockReset();
|
||||
persistProviderSettingsMock.mockReset();
|
||||
resolveProviderApiKeyMock.mockReset();
|
||||
clearLegacyProviderCredentialsMock.mockReset();
|
||||
});
|
||||
|
||||
describe("cline_account command auth states", () => {
|
||||
@@ -128,11 +134,30 @@ describe("cline_account command auth states", () => {
|
||||
getAuthToken: () => Promise<string | undefined>;
|
||||
};
|
||||
await expect(serviceOptions.getAuthToken()).resolves.toBe(
|
||||
"persisted-token",
|
||||
"workos:persisted-token",
|
||||
);
|
||||
expect(capture).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reports signed out when the refresh token is rejected even though a stale access token is persisted", async () => {
|
||||
// The stale token would only fail the account request with a 401,
|
||||
// which rendered an error card whose Retry failed the same way.
|
||||
const { ctx } = createContext();
|
||||
const { OAuthReauthRequiredError } =
|
||||
await vi.importActual<typeof import("@cline/core")>("@cline/core");
|
||||
resolveProviderApiKeyMock.mockRejectedValue(
|
||||
new OAuthReauthRequiredError("cline"),
|
||||
);
|
||||
getProviderSettingsMock.mockReturnValue({
|
||||
auth: { accessToken: "persisted-token" },
|
||||
});
|
||||
|
||||
const result = await runClineAccountCommand(ctx);
|
||||
|
||||
expect(isClineAccountNotAuthenticatedResult(result)).toBe(true);
|
||||
expect(executeClineAccountActionMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reports one auth refresh soft-failure event when the refresh fails and no fallback token exists", async () => {
|
||||
const { ctx, capture } = createContext();
|
||||
const refreshError = new Error(
|
||||
@@ -365,6 +390,31 @@ describe("cline_account keeps feature-flag identity in sync", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("signs out of the shared cline entry and legacy secrets when cline-pass is disabled", async () => {
|
||||
const { ctx } = createContext();
|
||||
getProviderSettingsMock.mockReturnValue(undefined);
|
||||
saveProviderSettingsMock.mockImplementation(
|
||||
(_manager: unknown, request: { providerId: string }) => ({
|
||||
providerId: request.providerId,
|
||||
enabled: false,
|
||||
settingsPath: "/tmp/settings.json",
|
||||
}),
|
||||
);
|
||||
const { handleCommand } = await import("./commands");
|
||||
await handleCommand(ctx, "save_provider_settings", {
|
||||
provider: "cline-pass",
|
||||
enabled: false,
|
||||
});
|
||||
|
||||
// Cline Pass stores its credentials under "cline", so both entries go,
|
||||
// and the legacy secrets are cleared for the storage provider.
|
||||
expect(saveProviderSettingsMock.mock.calls.map(([, r]) => r)).toEqual([
|
||||
expect.objectContaining({ providerId: "cline-pass", enabled: false }),
|
||||
{ providerId: "cline", enabled: false },
|
||||
]);
|
||||
expect(clearLegacyProviderCredentialsMock).toHaveBeenCalledWith("cline");
|
||||
});
|
||||
|
||||
it("ignores settings writes for other providers", async () => {
|
||||
const { ctx } = createContext();
|
||||
resolveProviderApiKeyMock.mockResolvedValue({ apiKey: "token" });
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
addLocalProvider,
|
||||
ClineAccountService,
|
||||
type ClineAccountUser,
|
||||
captureAuthRefreshSoftFailure,
|
||||
clearAccountTelemetryIdentity,
|
||||
createConfiguredStreamingTranscriptionSession,
|
||||
createUserInstructionConfigService,
|
||||
@@ -25,6 +24,7 @@ import {
|
||||
fetchClineRecommendedModels,
|
||||
getCoreBuiltinToolCatalog,
|
||||
getLocalProviderModels,
|
||||
getProviderAuthHandler,
|
||||
identifyAccount,
|
||||
listHookConfigFiles,
|
||||
listLocalProviders,
|
||||
@@ -33,10 +33,8 @@ import {
|
||||
parseMcpServerRegistration,
|
||||
persistClineAccountTelemetryIdentity,
|
||||
probeMcpServerConnection,
|
||||
RuntimeOAuthTokenManager,
|
||||
readGlobalSettings,
|
||||
resolveClineAccountTelemetryIdentity,
|
||||
resolveLocalClineAuthToken,
|
||||
resolveMcpServerRegistration,
|
||||
resolveSessionBackend,
|
||||
resolveAgentConfigSearchPaths as resolveSharedAgentConfigSearchPaths,
|
||||
@@ -72,6 +70,7 @@ import packageJson from "../package.json";
|
||||
import { CLINE_ACCOUNT_NOT_AUTHENTICATED_RESULT } from "../webview/lib/cline-account-state";
|
||||
import { MAX_RECORDED_AUDIO_BYTES } from "../webview/lib/voice-input-limits";
|
||||
import { resolveDesktopTelemetryUser } from "./client-context";
|
||||
import { resolveFreshClineAuthToken } from "./cline-auth";
|
||||
import {
|
||||
listClineGitHubRepositories,
|
||||
listClineIntegrations,
|
||||
@@ -92,6 +91,7 @@ import {
|
||||
identifyDesktopFeatureFlagsAccount,
|
||||
refreshDesktopFeatureFlags,
|
||||
} from "./feature-flags";
|
||||
import { clearLegacyProviderCredentials } from "./legacy-provider-credentials";
|
||||
import {
|
||||
installMarketplaceEntryForDesktopCommand,
|
||||
listMarketplaceInstalledEntries,
|
||||
@@ -121,6 +121,8 @@ import {
|
||||
sessionLogPath,
|
||||
sharedSessionDataDir,
|
||||
} from "./paths";
|
||||
import { getPullRequestStatus } from "./pull-request";
|
||||
import { capturePullRequestEvent } from "./pull-request-telemetry";
|
||||
import { listSessionAgents } from "./session-data/agents";
|
||||
import { readSessionHooks } from "./session-data/artifacts";
|
||||
import { normalizeSessionTitle } from "./session-data/common";
|
||||
@@ -309,13 +311,6 @@ function removePathIfExists(
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cline access tokens expire between app launches, so account requests must
|
||||
// resolve through the refresh-aware OAuth manager instead of reading the
|
||||
// persisted token directly. A single shared instance keeps concurrent account
|
||||
// requests single-flight; the refresh token is single-use, so parallel
|
||||
// refreshes would invalidate each other.
|
||||
let clineOAuthTokenManager: RuntimeOAuthTokenManager | undefined;
|
||||
|
||||
function syncAccountContextFromResult(
|
||||
ctx: SidecarContext,
|
||||
manager: ProviderSettingsManager,
|
||||
@@ -379,43 +374,6 @@ function syncSignedOutAccountContext(ctx: SidecarContext): void {
|
||||
);
|
||||
}
|
||||
|
||||
async function resolveFreshClineAuthToken(
|
||||
ctx: SidecarContext,
|
||||
manager: ProviderSettingsManager,
|
||||
): Promise<string | undefined> {
|
||||
let refreshError: Error | undefined;
|
||||
try {
|
||||
clineOAuthTokenManager ??= new RuntimeOAuthTokenManager();
|
||||
const resolution = await clineOAuthTokenManager.resolveProviderApiKey({
|
||||
providerId: "cline",
|
||||
});
|
||||
if (resolution?.apiKey) {
|
||||
return resolution.apiKey;
|
||||
}
|
||||
} catch (error) {
|
||||
// Fall back to the persisted token; when one exists the account request
|
||||
// surfaces the auth failure to the caller.
|
||||
refreshError = error instanceof Error ? error : new Error(String(error));
|
||||
}
|
||||
const persisted = resolveLocalClineAuthToken(
|
||||
manager.getProviderSettings("cline"),
|
||||
);
|
||||
// Never-signed-in resolves to undefined without a refresh attempt and is
|
||||
// silent. A refresh failure with no persisted fallback means credentials
|
||||
// existed but yielded nothing — that is the signal a real auth regression
|
||||
// would show up as, so report exactly one event for it.
|
||||
if (!persisted && refreshError) {
|
||||
ctx.logger?.error?.("Cline auth token refresh failed with no fallback", {
|
||||
error: refreshError,
|
||||
});
|
||||
captureAuthRefreshSoftFailure(ctx.telemetry, "cline", {
|
||||
errorName: refreshError.name,
|
||||
errorCode: "desktop_refresh_failed_no_fallback_token",
|
||||
});
|
||||
}
|
||||
return persisted;
|
||||
}
|
||||
|
||||
function mergePersistedSessionRecord(
|
||||
store: SqliteSessionStore,
|
||||
sessionId: string,
|
||||
@@ -690,9 +648,13 @@ function toPositiveInt(value: unknown): number | undefined {
|
||||
return rounded > 0 ? rounded : undefined;
|
||||
}
|
||||
|
||||
function routineScheduleTiming(
|
||||
args?: Record<string, unknown>,
|
||||
): { cronPattern: string; metadata?: Record<string, number> } | undefined {
|
||||
function routineScheduleTiming(args?: Record<string, unknown>):
|
||||
| {
|
||||
cronPattern: string;
|
||||
timezone?: string;
|
||||
metadata?: Record<string, number>;
|
||||
}
|
||||
| undefined {
|
||||
if (args?.schedule_type === "once") {
|
||||
const runAt =
|
||||
typeof args.run_at === "number" ? args.run_at : Number(args?.run_at);
|
||||
@@ -704,7 +666,9 @@ function routineScheduleTiming(
|
||||
: undefined;
|
||||
}
|
||||
const cronPattern = asTrimmedString(args?.cron_pattern);
|
||||
return cronPattern ? { cronPattern } : undefined;
|
||||
return cronPattern
|
||||
? { cronPattern, timezone: asTrimmedString(args?.timezone) }
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function asTrimmedString(value: unknown): string | undefined {
|
||||
@@ -962,7 +926,7 @@ async function listHubSettings(
|
||||
async function toggleHubSetting(
|
||||
ctx: SidecarContext,
|
||||
input: {
|
||||
type: "plugins" | "tools";
|
||||
type: "plugins" | "tools" | "skills";
|
||||
path?: string;
|
||||
name?: string;
|
||||
enabled?: boolean;
|
||||
@@ -1001,13 +965,18 @@ async function listUserInstructionConfigs(
|
||||
const items: unknown[] = [];
|
||||
for (const record of userInstructionService.listRecords(type)) {
|
||||
const item = record.item as unknown as JsonRecord;
|
||||
if (item.disabled === true) continue;
|
||||
const disabled = item.disabled === true;
|
||||
// Rules and workflows have no toggle UI, so keep hiding disabled
|
||||
// ones; skills need to stay visible (disabled) so they can be
|
||||
// re-enabled from the Skills tab.
|
||||
if (disabled && type !== "skill") continue;
|
||||
items.push({
|
||||
id: record.id,
|
||||
name: item.name ?? record.id,
|
||||
description: item.description,
|
||||
instructions: item.instructions,
|
||||
path: record.filePath,
|
||||
...(type === "skill" ? { enabled: !disabled } : {}),
|
||||
});
|
||||
}
|
||||
return items;
|
||||
@@ -1867,7 +1836,7 @@ export async function handleCommand(
|
||||
// token up front and return a typed result the webview can act on
|
||||
// instead of letting the account service throw a generic error that
|
||||
// would be captured as error telemetry and shown raw to the user.
|
||||
const authToken = await resolveFreshClineAuthToken(ctx, manager);
|
||||
const authToken = await resolveFreshClineAuthToken(manager, ctx);
|
||||
if (!authToken) {
|
||||
// Backstop for credentials that go away without a settings write —
|
||||
// an expired or server-revoked token. Explicit sign-out is handled
|
||||
@@ -1896,7 +1865,7 @@ export async function handleCommand(
|
||||
if (!operation) throw new Error("operation is required");
|
||||
const manager = new ProviderSettingsManager();
|
||||
|
||||
const authToken = await resolveFreshClineAuthToken(ctx, manager);
|
||||
const authToken = await resolveFreshClineAuthToken(manager, ctx);
|
||||
if (!authToken) {
|
||||
return CLINE_ACCOUNT_NOT_AUTHENTICATED_RESULT;
|
||||
}
|
||||
@@ -2088,6 +2057,24 @@ export async function handleCommand(
|
||||
apiKey: typeof args?.api_key === "string" ? args.api_key : undefined,
|
||||
baseUrl: typeof args?.base_url === "string" ? args.base_url : undefined,
|
||||
});
|
||||
if (!saved.enabled) {
|
||||
// Cline Pass keeps its credentials under "cline", so removing only
|
||||
// its own entry would leave the account signed in.
|
||||
const storageProviderId =
|
||||
getProviderAuthHandler(saved.providerId)?.storageProviderId ??
|
||||
saved.providerId;
|
||||
if (storageProviderId !== saved.providerId) {
|
||||
saveLocalProviderSettings(manager, {
|
||||
providerId: storageProviderId,
|
||||
enabled: false,
|
||||
});
|
||||
}
|
||||
// Removing a providers.json entry lets the legacy import restore it
|
||||
// from the extension's secrets.json on the next command unless those
|
||||
// credentials go too. A failed write throws so the webview reports
|
||||
// the sign-out as failed and resyncs.
|
||||
clearLegacyProviderCredentials(storageProviderId);
|
||||
}
|
||||
// Sign-out is a `save_provider_settings` that blanks the cline auth block
|
||||
// (see signOut in webview settings/account-view.tsx), so this is the
|
||||
// authoritative signal — it fires the moment credentials are cleared
|
||||
@@ -2431,6 +2418,17 @@ export async function handleCommand(
|
||||
}
|
||||
|
||||
// ── Git operations ─────────────────────────────────────────────────
|
||||
if (command === "capture_pull_request_event") {
|
||||
capturePullRequestEvent(ctx.telemetry, args);
|
||||
return null;
|
||||
}
|
||||
if (command === "get_pull_request_status") {
|
||||
return await getPullRequestStatus(
|
||||
typeof args?.cwd === "string" && args.cwd.trim()
|
||||
? args.cwd.trim()
|
||||
: ctx.workspaceRoot,
|
||||
);
|
||||
}
|
||||
if (command === "get_git_branch") {
|
||||
const cwd =
|
||||
typeof args?.cwd === "string" && args.cwd.trim()
|
||||
@@ -2550,6 +2548,18 @@ export async function handleCommand(
|
||||
});
|
||||
return await listUserInstructionConfigs(ctx, snapshot);
|
||||
}
|
||||
if (command === "set_skill_disabled") {
|
||||
const skillPath = String(args?.path ?? "").trim();
|
||||
if (!skillPath) {
|
||||
throw new Error("skill path is required");
|
||||
}
|
||||
const snapshot = await toggleHubSetting(ctx, {
|
||||
type: "skills",
|
||||
path: skillPath,
|
||||
enabled: args?.disabled !== true,
|
||||
});
|
||||
return await listUserInstructionConfigs(ctx, snapshot);
|
||||
}
|
||||
|
||||
// ── Native OS commands ────────────────────────────────────────────
|
||||
if (command === "validate_workspace_directory") {
|
||||
|
||||
@@ -531,6 +531,65 @@ describe("Code sidecar runtime capabilities", () => {
|
||||
).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("does not announce a queued prompt start when the head is deleted from the queue", async () => {
|
||||
const { createSidecarContext, initializeSessionManager } = await import(
|
||||
"./context"
|
||||
);
|
||||
let onEvent: ((event: unknown) => void) | undefined;
|
||||
createCoreMock.mockResolvedValue({
|
||||
runtimeAddress: "ws://127.0.0.1:25463/hub",
|
||||
subscribe: vi.fn((handler: (event: unknown) => void) => {
|
||||
onEvent = handler;
|
||||
return () => {};
|
||||
}),
|
||||
dispose: vi.fn(),
|
||||
});
|
||||
|
||||
const ctx = createSidecarContext("/workspace/project");
|
||||
ctx.wsClients.add({ send: vi.fn() });
|
||||
await initializeSessionManager(ctx);
|
||||
ctx.liveSessions.set("session-1", {
|
||||
config: {},
|
||||
messages: [],
|
||||
promptsInQueue: [
|
||||
{ id: "prompt-1", prompt: "first", steer: false, attachmentCount: 0 },
|
||||
{ id: "prompt-2", prompt: "second", steer: false, attachmentCount: 0 },
|
||||
],
|
||||
busy: true,
|
||||
startedAt: Date.now(),
|
||||
status: "running",
|
||||
});
|
||||
|
||||
// Removing the head only produces a shrunken snapshot — no
|
||||
// pending_prompt_submitted — so nothing must reach the transcript.
|
||||
onEvent?.({
|
||||
type: "pending_prompts",
|
||||
payload: {
|
||||
sessionId: "session-1",
|
||||
prompts: [{ id: "prompt-2", prompt: "second", delivery: "queue" }],
|
||||
},
|
||||
});
|
||||
|
||||
const events = readEvents(ctx);
|
||||
expect(
|
||||
events.filter(
|
||||
(message) =>
|
||||
message.event.name === "chat_event" &&
|
||||
(message.event.payload as { stream?: string }).stream ===
|
||||
"chat_queued_prompt_start",
|
||||
),
|
||||
).toHaveLength(0);
|
||||
expect(
|
||||
events.find((message) => message.event.name === "prompts_in_queue_state")
|
||||
?.event.payload,
|
||||
).toEqual({
|
||||
sessionId: "session-1",
|
||||
items: [
|
||||
{ id: "prompt-2", prompt: "second", steer: false, attachmentCount: 0 },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("relays generated media for attach-only Hub sessions", async () => {
|
||||
const { createSidecarContext, handleHubLiveEvent } = await import(
|
||||
"./context"
|
||||
|
||||
@@ -426,10 +426,8 @@ function handleAgentEvent(
|
||||
// CoreSessionEvent routing
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// The runtime's queue drain emits a pending_prompts snapshot (head removed)
|
||||
// and a pending_prompt_submitted event for the same prompt back-to-back, and
|
||||
// both are translated here into chat_queued_prompt_start — dedupe by prompt
|
||||
// id or the UI renders the user message twice.
|
||||
// Dedupe by prompt id so a repeated pending_prompt_submitted for the same
|
||||
// prompt cannot render the user message twice.
|
||||
function emitQueuedPromptStart(
|
||||
ctx: SidecarContext,
|
||||
sessionId: string,
|
||||
@@ -490,20 +488,10 @@ export function handleCoreSessionEvent(
|
||||
session,
|
||||
mapped.map((item) => item.id),
|
||||
);
|
||||
const previous = session.promptsInQueue;
|
||||
// A shrinking snapshot is not evidence that the head started
|
||||
// running: the user may have deleted it or the queue may have been
|
||||
// discarded. Only pending_prompt_submitted announces a start.
|
||||
session.promptsInQueue = mapped;
|
||||
if (
|
||||
previous.length > mapped.length &&
|
||||
previous[0] &&
|
||||
previous[0].id !== mapped[0]?.id
|
||||
) {
|
||||
emitQueuedPromptStart(ctx, sessionId, session, {
|
||||
promptId: previous[0].id,
|
||||
prompt: previous[0].prompt,
|
||||
attachmentCount: previous[0].attachmentCount ?? 0,
|
||||
userImages: previous[0].userImages,
|
||||
});
|
||||
}
|
||||
}
|
||||
sendPromptsInQueueSnapshot(ctx, sessionId);
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readFileSync,
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
readDesktopSettings,
|
||||
resolveDesktopSettingsPath,
|
||||
setCloudSessionsEnabled,
|
||||
} from "./desktop-settings";
|
||||
|
||||
let dataDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
dataDir = mkdtempSync(join(tmpdir(), "cline-desktop-settings-"));
|
||||
process.env.CLINE_DATA_DIR = dataDir;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env.CLINE_DATA_DIR;
|
||||
rmSync(dataDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe("desktop settings", () => {
|
||||
it("defaults cloud sessions to off when no settings file exists", () => {
|
||||
expect(readDesktopSettings()).toEqual({ cloudSessionsEnabled: false });
|
||||
});
|
||||
|
||||
it("persists the cloud sessions opt-in and reads it back", () => {
|
||||
expect(setCloudSessionsEnabled(true)).toEqual({
|
||||
cloudSessionsEnabled: true,
|
||||
});
|
||||
expect(readDesktopSettings()).toEqual({ cloudSessionsEnabled: true });
|
||||
expect(resolveDesktopSettingsPath().endsWith("code-settings.json")).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
JSON.parse(readFileSync(resolveDesktopSettingsPath(), "utf8")),
|
||||
).toMatchObject({ cloudSessionsEnabled: true });
|
||||
expect(setCloudSessionsEnabled(false)).toEqual({
|
||||
cloudSessionsEnabled: false,
|
||||
});
|
||||
expect(readDesktopSettings()).toEqual({ cloudSessionsEnabled: false });
|
||||
});
|
||||
|
||||
it("treats malformed files and non-boolean values as off", () => {
|
||||
mkdirSync(dirname(resolveDesktopSettingsPath()), { recursive: true });
|
||||
writeFileSync(resolveDesktopSettingsPath(), "{not json", "utf8");
|
||||
expect(readDesktopSettings()).toEqual({ cloudSessionsEnabled: false });
|
||||
writeFileSync(
|
||||
resolveDesktopSettingsPath(),
|
||||
JSON.stringify({ cloudSessionsEnabled: "yes" }),
|
||||
"utf8",
|
||||
);
|
||||
expect(readDesktopSettings()).toEqual({ cloudSessionsEnabled: false });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { resolveClineDataDir } from "@cline/shared/storage";
|
||||
|
||||
/** Desktop-only preferences kept separate from strict shared global settings. */
|
||||
export type DesktopSettings = {
|
||||
/** Opt-in gate for cloud sessions while the feature is in preview. */
|
||||
cloudSessionsEnabled: boolean;
|
||||
};
|
||||
|
||||
const DEFAULT_SETTINGS: DesktopSettings = {
|
||||
cloudSessionsEnabled: false,
|
||||
};
|
||||
|
||||
export function resolveDesktopSettingsPath(): string {
|
||||
return join(resolveClineDataDir(), "settings", "code-settings.json");
|
||||
}
|
||||
|
||||
export function readDesktopSettings(): DesktopSettings {
|
||||
let raw: string;
|
||||
try {
|
||||
raw = readFileSync(resolveDesktopSettingsPath(), "utf8");
|
||||
} catch {
|
||||
return { ...DEFAULT_SETTINGS };
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as Record<string, unknown>;
|
||||
return {
|
||||
cloudSessionsEnabled: parsed.cloudSessionsEnabled === true,
|
||||
};
|
||||
} catch {
|
||||
return { ...DEFAULT_SETTINGS };
|
||||
}
|
||||
}
|
||||
|
||||
export function writeDesktopSettings(settings: DesktopSettings): void {
|
||||
const filePath = resolveDesktopSettingsPath();
|
||||
mkdirSync(dirname(filePath), { recursive: true });
|
||||
// Avoid leaving torn settings if the process exits mid-write.
|
||||
const tempPath = `${filePath}.${process.pid}.tmp`;
|
||||
writeFileSync(tempPath, `${JSON.stringify(settings, null, 2)}\n`, "utf8");
|
||||
renameSync(tempPath, filePath);
|
||||
}
|
||||
|
||||
export function setCloudSessionsEnabled(enabled: boolean): DesktopSettings {
|
||||
const next = { ...readDesktopSettings(), cloudSessionsEnabled: enabled };
|
||||
writeDesktopSettings(next);
|
||||
return next;
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
@@ -18,6 +21,7 @@ const mocks = vi.hoisted(() => ({
|
||||
poll: vi.fn(async () => {}),
|
||||
dispose: vi.fn(async () => {}),
|
||||
setContext: vi.fn(),
|
||||
getBooleanFlagEnabled: vi.fn((_flag: unknown): boolean => false),
|
||||
getFlagPayload: vi.fn((_flag: unknown): unknown => undefined),
|
||||
}));
|
||||
|
||||
@@ -39,6 +43,7 @@ vi.mock("@cline/core", async () => {
|
||||
poll = mocks.poll;
|
||||
dispose = mocks.dispose;
|
||||
setContext = mocks.setContext;
|
||||
getBooleanFlagEnabled = mocks.getBooleanFlagEnabled;
|
||||
getFlagPayload = mocks.getFlagPayload;
|
||||
},
|
||||
};
|
||||
@@ -61,15 +66,26 @@ import {
|
||||
|
||||
const originalApiKey = process.env.TELEMETRY_SERVICE_API_KEY;
|
||||
const originalIsTest = process.env.IS_TEST;
|
||||
const originalDataDir = process.env.CLINE_DATA_DIR;
|
||||
let dataDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
dataDir = mkdtempSync(join(tmpdir(), "cline-feature-flags-"));
|
||||
process.env.CLINE_DATA_DIR = dataDir;
|
||||
vi.clearAllMocks();
|
||||
mocks.getBooleanFlagEnabled.mockReset().mockReturnValue(false);
|
||||
resetDesktopFeatureFlagsForTesting();
|
||||
delete process.env.IS_TEST;
|
||||
delete process.env.E2E_TEST;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(dataDir, { recursive: true, force: true });
|
||||
if (originalDataDir === undefined) {
|
||||
delete process.env.CLINE_DATA_DIR;
|
||||
} else {
|
||||
process.env.CLINE_DATA_DIR = originalDataDir;
|
||||
}
|
||||
if (originalApiKey === undefined) {
|
||||
delete process.env.TELEMETRY_SERVICE_API_KEY;
|
||||
} else {
|
||||
@@ -239,3 +255,53 @@ describe("disposeDesktopFeatureFlagsService", () => {
|
||||
expect(mocks.dispose).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("cloud agents gate", () => {
|
||||
beforeEach(() => {
|
||||
delete process.env.CLINE_CODE_CLOUD_AGENTS;
|
||||
});
|
||||
|
||||
it("is unavailable and disabled while the rollout flag is off", async () => {
|
||||
const { isCloudAgentsAvailable, isCloudAgentsEnabled } = await import(
|
||||
"./feature-flags"
|
||||
);
|
||||
expect(isCloudAgentsAvailable()).toBe(false);
|
||||
expect(isCloudAgentsEnabled()).toBe(false);
|
||||
});
|
||||
|
||||
it("does not enable a boolean rollout from a truthy variant payload", async () => {
|
||||
const { isCloudAgentsAvailable } = await import("./feature-flags");
|
||||
mocks.getFlagPayload.mockReturnValue("control");
|
||||
expect(isCloudAgentsAvailable()).toBe(false);
|
||||
expect(mocks.getBooleanFlagEnabled).toHaveBeenCalledWith(
|
||||
"code-cloud-agents",
|
||||
);
|
||||
});
|
||||
|
||||
it("needs both the rollout flag and the user's opt-in to enable", async () => {
|
||||
const { isCloudAgentsEnabled, isCloudAgentsAvailable } = await import(
|
||||
"./feature-flags"
|
||||
);
|
||||
const { setCloudSessionsEnabled } = await import("./desktop-settings");
|
||||
mocks.getBooleanFlagEnabled.mockImplementation(
|
||||
(flag: unknown) => flag === "code-cloud-agents",
|
||||
);
|
||||
expect(isCloudAgentsAvailable()).toBe(true);
|
||||
setCloudSessionsEnabled(false);
|
||||
expect(isCloudAgentsEnabled()).toBe(false);
|
||||
setCloudSessionsEnabled(true);
|
||||
expect(isCloudAgentsEnabled()).toBe(true);
|
||||
});
|
||||
|
||||
it("lets the env override force the gate in both directions", async () => {
|
||||
const { isCloudAgentsEnabled, isCloudAgentsAvailable } = await import(
|
||||
"./feature-flags"
|
||||
);
|
||||
mocks.getFlagPayload.mockReturnValue(undefined);
|
||||
process.env.CLINE_CODE_CLOUD_AGENTS = "1";
|
||||
expect(isCloudAgentsAvailable()).toBe(true);
|
||||
expect(isCloudAgentsEnabled()).toBe(true);
|
||||
process.env.CLINE_CODE_CLOUD_AGENTS = "0";
|
||||
expect(isCloudAgentsEnabled()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,7 +13,11 @@ import {
|
||||
buildClinePostHogClient,
|
||||
PostHogFeatureFlagsProvider,
|
||||
} from "@cline/core/services/feature-flags/posthog";
|
||||
import { FeatureFlag as SharedFeatureFlag } from "@cline/shared";
|
||||
import { resolveClineDataDir } from "@cline/shared/storage";
|
||||
import { readDesktopSettings } from "./desktop-settings";
|
||||
|
||||
const FEATURE_FLAG_CODE_CLOUD_AGENTS = SharedFeatureFlag.CODE_CLOUD_AGENTS;
|
||||
|
||||
const DESKTOP_FEATURE_FLAGS_CACHE_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
|
||||
|
||||
@@ -169,3 +173,33 @@ export function resetDesktopFeatureFlagsForTesting(): void {
|
||||
desktopFeatureFlagsService = undefined;
|
||||
desktopFeatureFlagsContext = { clientName: "cline-code" };
|
||||
}
|
||||
|
||||
export function readCloudAgentsEnvOverride(): boolean | undefined {
|
||||
const override = process.env.CLINE_CODE_CLOUD_AGENTS?.trim().toLowerCase();
|
||||
if (override === "1" || override === "true") return true;
|
||||
if (override === "0" || override === "false") return false;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Whether the rollout makes cloud sessions available to this install. */
|
||||
export function isCloudAgentsAvailable(options?: {
|
||||
logger?: BasicLogger;
|
||||
telemetry?: ITelemetryService;
|
||||
}): boolean {
|
||||
const override = readCloudAgentsEnvOverride();
|
||||
if (override !== undefined) return override;
|
||||
return getDesktopFeatureFlagsService(options).getBooleanFlagEnabled(
|
||||
FEATURE_FLAG_CODE_CLOUD_AGENTS,
|
||||
);
|
||||
}
|
||||
|
||||
/** Whether cloud sessions are both available and enabled by the user. */
|
||||
export function isCloudAgentsEnabled(options?: {
|
||||
logger?: BasicLogger;
|
||||
telemetry?: ITelemetryService;
|
||||
}): boolean {
|
||||
const override = readCloudAgentsEnvOverride();
|
||||
if (override !== undefined) return override;
|
||||
if (!isCloudAgentsAvailable(options)) return false;
|
||||
return readDesktopSettings().cloudSessionsEnabled;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,11 @@ import {
|
||||
setModelToolEnabledGlobally,
|
||||
watchManagedHubBuildMismatch,
|
||||
} from "@cline/core";
|
||||
import { captureSdkError, claimHubDaemonProcess } from "@cline/shared";
|
||||
import {
|
||||
captureSdkError,
|
||||
claimHubDaemonProcess,
|
||||
disableCurrentDirectoryExecutableSearch,
|
||||
} from "@cline/shared";
|
||||
import { prewarmWorkspaceMetadata } from "./chat-session";
|
||||
import { configureConnectorCliLaunch } from "./connectors";
|
||||
import {
|
||||
@@ -232,6 +236,7 @@ async function runEntrypoint(): Promise<void> {
|
||||
runTelemetrySelfcheck();
|
||||
return;
|
||||
}
|
||||
disableCurrentDirectoryExecutableSearch();
|
||||
// Claim rather than read: consuming the sentinel keeps daemon-hosted sessions
|
||||
// from handing it to every process they spawn.
|
||||
if (claimHubDaemonProcess()) {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { clearLegacyProviderCredentials } from "./legacy-provider-credentials";
|
||||
|
||||
describe("clearLegacyProviderCredentials", () => {
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const dir of tempDirs.splice(0)) {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("removes only the Codex credentials from the legacy secrets file", () => {
|
||||
const dataDir = mkdtempSync(path.join(os.tmpdir(), "desktop-legacy-"));
|
||||
tempDirs.push(dataDir);
|
||||
const secretsPath = path.join(dataDir, "secrets.json");
|
||||
writeFileSync(
|
||||
secretsPath,
|
||||
JSON.stringify({
|
||||
"openai-codex-oauth-credentials": JSON.stringify({
|
||||
access_token: "a",
|
||||
refresh_token: "r",
|
||||
}),
|
||||
openRouterApiKey: "sk-or-keep",
|
||||
}),
|
||||
);
|
||||
|
||||
expect(clearLegacyProviderCredentials("openai-codex", dataDir)).toBe(true);
|
||||
expect(JSON.parse(readFileSync(secretsPath, "utf8"))).toEqual({
|
||||
openRouterApiKey: "sk-or-keep",
|
||||
});
|
||||
});
|
||||
|
||||
it("removes both Cline account secrets from the legacy secrets file", () => {
|
||||
const dataDir = mkdtempSync(path.join(os.tmpdir(), "desktop-legacy-"));
|
||||
tempDirs.push(dataDir);
|
||||
const secretsPath = path.join(dataDir, "secrets.json");
|
||||
writeFileSync(
|
||||
secretsPath,
|
||||
JSON.stringify({
|
||||
"cline:clineAccountId": JSON.stringify({ idToken: "t" }),
|
||||
clineApiKey: "cline-key",
|
||||
openRouterApiKey: "sk-or-keep",
|
||||
}),
|
||||
);
|
||||
|
||||
expect(clearLegacyProviderCredentials("cline", dataDir)).toBe(true);
|
||||
expect(JSON.parse(readFileSync(secretsPath, "utf8"))).toEqual({
|
||||
openRouterApiKey: "sk-or-keep",
|
||||
});
|
||||
});
|
||||
|
||||
it("is a no-op when the file is missing, has no matching credentials, or the provider is unknown", () => {
|
||||
const dataDir = mkdtempSync(path.join(os.tmpdir(), "desktop-legacy-"));
|
||||
tempDirs.push(dataDir);
|
||||
expect(clearLegacyProviderCredentials("openai-codex", dataDir)).toBe(false);
|
||||
|
||||
const secretsPath = path.join(dataDir, "secrets.json");
|
||||
writeFileSync(secretsPath, JSON.stringify({ apiKey: "keep" }));
|
||||
expect(clearLegacyProviderCredentials("cline", dataDir)).toBe(false);
|
||||
expect(clearLegacyProviderCredentials("anthropic", dataDir)).toBe(false);
|
||||
expect(readFileSync(secretsPath, "utf8")).toBe(
|
||||
JSON.stringify({ apiKey: "keep" }),
|
||||
);
|
||||
|
||||
writeFileSync(secretsPath, "{not json");
|
||||
expect(clearLegacyProviderCredentials("openai-codex", dataDir)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { resolveClineDataDir } from "@cline/shared/storage";
|
||||
|
||||
/**
|
||||
* Legacy VS Code extension secrets.json keys that the legacy import in
|
||||
* ProviderSettingsManager turns back into a providers.json entry.
|
||||
*/
|
||||
const LEGACY_SECRET_KEYS_BY_PROVIDER: Record<string, string[]> = {
|
||||
"openai-codex": ["openai-codex-oauth-credentials"],
|
||||
cline: ["cline:clineAccountId", "clineApiKey"],
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes a provider's credentials from the legacy VS Code extension's
|
||||
* secrets.json. The legacy import in ProviderSettingsManager runs on
|
||||
* construction and re-adds any provider missing from providers.json, so
|
||||
* leaving these credentials on disk would sign the user straight back in
|
||||
* after they sign out in the desktop app. Temporary until the legacy import
|
||||
* is retired.
|
||||
*
|
||||
* A missing or unparseable file is a no-op (the import ignores those too).
|
||||
* A failed write throws so the sign-out is reported as failed instead of
|
||||
* succeeding and then being undone by the next import.
|
||||
*/
|
||||
export function clearLegacyProviderCredentials(
|
||||
providerId: string,
|
||||
dataDir: string = resolveClineDataDir(),
|
||||
): boolean {
|
||||
const keys = LEGACY_SECRET_KEYS_BY_PROVIDER[providerId];
|
||||
const secretsPath = join(dataDir, "secrets.json");
|
||||
if (!keys || !existsSync(secretsPath)) {
|
||||
return false;
|
||||
}
|
||||
let secrets: unknown;
|
||||
try {
|
||||
secrets = JSON.parse(readFileSync(secretsPath, "utf8"));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
if (!secrets || typeof secrets !== "object" || Array.isArray(secrets)) {
|
||||
return false;
|
||||
}
|
||||
const present = keys.filter((key) => key in secrets);
|
||||
if (present.length === 0) {
|
||||
return false;
|
||||
}
|
||||
for (const key of present) {
|
||||
delete (secrets as Record<string, unknown>)[key];
|
||||
}
|
||||
writeFileSync(secretsPath, `${JSON.stringify(secrets, null, 2)}\n`, {
|
||||
encoding: "utf8",
|
||||
mode: 0o600,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { ITelemetryService } from "@cline/shared";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { capturePullRequestEvent } from "./pull-request-telemetry";
|
||||
|
||||
const event = {
|
||||
action: "open_clicked",
|
||||
prState: "open",
|
||||
ciState: "success",
|
||||
mergeTone: "success",
|
||||
};
|
||||
function service(enabled = true) {
|
||||
const capture = vi.fn();
|
||||
return {
|
||||
capture,
|
||||
telemetry: {
|
||||
capture,
|
||||
isEnabled: () => enabled,
|
||||
} as unknown as ITelemetryService,
|
||||
};
|
||||
}
|
||||
|
||||
it("captures only allowlisted status categories and strips identifiers", () => {
|
||||
const { capture, telemetry } = service();
|
||||
capturePullRequestEvent(telemetry, {
|
||||
...event,
|
||||
repository: "private/repo",
|
||||
cwd: "/private/path",
|
||||
url: "https://github.com/private/repo",
|
||||
title: "Secret",
|
||||
number: 42,
|
||||
});
|
||||
expect(capture).toHaveBeenCalledExactlyOnceWith({
|
||||
event: "desktop.pull_request.open_clicked",
|
||||
properties: {
|
||||
prState: "open",
|
||||
ciState: "success",
|
||||
mergeTone: "success",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ ...event, action: "arbitrary.event" },
|
||||
{ ...event, prState: "private/repo" },
|
||||
{ ...event, ciState: "test name" },
|
||||
{ ...event, mergeTone: "secret" },
|
||||
{},
|
||||
null,
|
||||
])("drops invalid payloads", (input) => {
|
||||
const { capture, telemetry } = service();
|
||||
capturePullRequestEvent(telemetry, input);
|
||||
expect(capture).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("respects telemetry opt-out", () => {
|
||||
const { capture, telemetry } = service(false);
|
||||
capturePullRequestEvent(telemetry, event);
|
||||
expect(capture).not.toHaveBeenCalled();
|
||||
expect(() => capturePullRequestEvent(undefined, event)).not.toThrow();
|
||||
});
|
||||
|
||||
it("does not fail the command when the provider throws", () => {
|
||||
const { capture, telemetry } = service();
|
||||
capture.mockImplementation(() => {
|
||||
throw new Error("Telemetry unavailable");
|
||||
});
|
||||
expect(() => capturePullRequestEvent(telemetry, event)).not.toThrow();
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { ITelemetryService } from "@cline/shared";
|
||||
import { pullRequestTelemetrySchema } from "../webview/lib/pull-request-telemetry-schema";
|
||||
|
||||
export function capturePullRequestEvent(
|
||||
telemetry: ITelemetryService | undefined,
|
||||
input: unknown,
|
||||
): void {
|
||||
const parsed = pullRequestTelemetrySchema.safeParse(input);
|
||||
if (!parsed.success) return;
|
||||
try {
|
||||
if (!telemetry?.isEnabled()) return;
|
||||
const { action, ...properties } = parsed.data;
|
||||
telemetry.capture({ event: `desktop.pull_request.${action}`, properties });
|
||||
} catch {
|
||||
// Product interactions must continue if the telemetry provider fails.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { getMergeStatus, summarizeChecks } from "../webview/lib/pull-request";
|
||||
import {
|
||||
createPullRequestStatusReader,
|
||||
GITHUB_AVAILABILITY_CACHE_MS,
|
||||
githubRepository,
|
||||
normalizeCheck,
|
||||
} from "./pull-request";
|
||||
|
||||
const pr = {
|
||||
number: 42,
|
||||
title: "Feature",
|
||||
url: "https://github.com/cline/cline/pull/42",
|
||||
state: "OPEN",
|
||||
isDraft: false,
|
||||
mergeable: "MERGEABLE",
|
||||
mergeStateStatus: "CLEAN",
|
||||
additions: 12,
|
||||
deletions: 3,
|
||||
headRepositoryOwner: { login: "cline" },
|
||||
headRepository: { name: "cline" },
|
||||
statusCheckRollup: [
|
||||
{
|
||||
__typename: "CheckRun",
|
||||
name: "Test",
|
||||
status: "COMPLETED",
|
||||
conclusion: "SUCCESS",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
function runner(prs: unknown[] = [pr], branch = "feature/pr-ui") {
|
||||
return vi.fn(async (file: string, args: string[], _cwd: string) => {
|
||||
if (file === "git")
|
||||
return args[0] === "branch" ? branch : "git@github.com:cline/cline.git";
|
||||
if (args[0] === "pr" && args[1] === "view")
|
||||
return JSON.stringify(
|
||||
prs.find((item) => (item as typeof pr).number === Number(args[2])),
|
||||
);
|
||||
return JSON.stringify(
|
||||
args[0] === "repo" ? { defaultBranchRef: { name: "main" } } : prs,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
describe("pull request status", () => {
|
||||
it("reads the active workspace, filters same-named fork branches and prefers an open PR", async () => {
|
||||
const run = runner([
|
||||
{ ...pr, number: 99, headRepositoryOwner: { login: "someone" } },
|
||||
{ ...pr, number: 41, state: "MERGED" },
|
||||
pr,
|
||||
]);
|
||||
const result = await createPullRequestStatusReader({ run })("/worktree");
|
||||
expect(result?.pullRequest?.number).toBe(42);
|
||||
expect(result?.pullRequest?.checks[0].state).toBe("success");
|
||||
expect(result?.createUrl).toBe(
|
||||
"https://github.com/cline/cline/compare/main...feature%2Fpr-ui?expand=1",
|
||||
);
|
||||
expect(run.mock.calls.every((call) => call[2] === "/worktree")).toBe(true);
|
||||
expect(run.mock.calls.find((call) => call[1][0] === "pr")?.[1]).toContain(
|
||||
"feature/pr-ui",
|
||||
);
|
||||
});
|
||||
it("offers creation for a feature branch and hides it for the default branch", async () => {
|
||||
expect(
|
||||
(await createPullRequestStatusReader({ run: runner([]) })("/repo"))
|
||||
?.pullRequest,
|
||||
).toBeNull();
|
||||
expect(
|
||||
await createPullRequestStatusReader({ run: runner([], "main") })("/repo"),
|
||||
).toBeNull();
|
||||
});
|
||||
it("keeps merged and closed PR states", async () => {
|
||||
for (const state of ["MERGED", "CLOSED"] as const) {
|
||||
const result = await createPullRequestStatusReader({
|
||||
run: runner([{ ...pr, state }]),
|
||||
})("/repo");
|
||||
expect(result?.pullRequest?.state).toBe(state);
|
||||
}
|
||||
});
|
||||
it("does not invoke GitHub for detached HEAD or unsupported remotes", async () => {
|
||||
const detached = runner([], "");
|
||||
expect(
|
||||
await createPullRequestStatusReader({ run: detached })("/repo"),
|
||||
).toBeNull();
|
||||
expect(detached).toHaveBeenCalledTimes(1);
|
||||
const local = vi.fn(async () => "local");
|
||||
expect(
|
||||
await createPullRequestStatusReader({ run: local })("/repo"),
|
||||
).toBeNull();
|
||||
expect(local).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
it.each([
|
||||
"ENOENT",
|
||||
1,
|
||||
4,
|
||||
])("hides unavailable GitHub CLI (%s), shares the cooldown, and recovers after login", async (code) => {
|
||||
let time = 0;
|
||||
let authenticated = false;
|
||||
const base = runner();
|
||||
const run = vi.fn(async (file: string, args: string[], cwd: string) => {
|
||||
if (file === "gh" && args[0] === "auth" && !authenticated)
|
||||
throw Object.assign(new Error("private stderr"), { code });
|
||||
return base(file, args, cwd);
|
||||
});
|
||||
const read = createPullRequestStatusReader({ run, now: () => time });
|
||||
expect(await read("/repo")).toBeNull();
|
||||
const attempts = run.mock.calls.length;
|
||||
authenticated = true;
|
||||
time = GITHUB_AVAILABILITY_CACHE_MS - 1;
|
||||
expect(await read("/other-workspace")).toBeNull();
|
||||
expect(run).toHaveBeenCalledTimes(attempts);
|
||||
time++;
|
||||
expect((await read("/repo"))?.pullRequest?.number).toBe(42);
|
||||
expect(run.mock.calls.filter((call) => call[1][0] === "auth")).toHaveLength(
|
||||
2,
|
||||
);
|
||||
});
|
||||
|
||||
it("shares an in-flight availability check across concurrent workspaces", async () => {
|
||||
let finish!: () => void;
|
||||
const waiting = new Promise<void>((resolve) => {
|
||||
finish = resolve;
|
||||
});
|
||||
const base = runner();
|
||||
const run = vi.fn(async (file: string, args: string[], cwd: string) => {
|
||||
if (args[0] === "auth") await waiting;
|
||||
return base(file, args, cwd);
|
||||
});
|
||||
const read = createPullRequestStatusReader({ run });
|
||||
const first = read("/first");
|
||||
const second = read("/second");
|
||||
await vi.waitFor(() =>
|
||||
expect(
|
||||
run.mock.calls.filter((call) => call[1][0] === "auth"),
|
||||
).toHaveLength(1),
|
||||
);
|
||||
finish();
|
||||
await Promise.all([first, second]);
|
||||
expect(run.mock.calls.filter((call) => call[1][0] === "auth")).toHaveLength(
|
||||
1,
|
||||
);
|
||||
});
|
||||
|
||||
it("hides default-branch authentication failures before any repository query", async () => {
|
||||
const base = runner([], "main");
|
||||
const run = vi.fn(async (file: string, args: string[], cwd: string) => {
|
||||
if (file === "gh")
|
||||
throw Object.assign(new Error("Not logged in"), { code: 1 });
|
||||
return base(file, args, cwd);
|
||||
});
|
||||
expect(await createPullRequestStatusReader({ run })("/repo")).toBeNull();
|
||||
expect(
|
||||
run.mock.calls.filter((call) => call[0] === "gh").map((call) => call[1]),
|
||||
).toEqual([["auth", "status", "--active", "--hostname", "github.com"]]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ code: 4 },
|
||||
{ code: 1, stderr: "HTTP 401: Bad credentials" },
|
||||
])("invalidates cached availability if authentication expires during a lookup", async (failure) => {
|
||||
let expired = false;
|
||||
const base = runner();
|
||||
const run = vi.fn(async (file: string, args: string[], cwd: string) => {
|
||||
if (args[0] === "repo" && expired)
|
||||
throw Object.assign(new Error("Failed"), failure);
|
||||
return base(file, args, cwd);
|
||||
});
|
||||
const read = createPullRequestStatusReader({ run });
|
||||
expect((await read("/repo"))?.pullRequest?.number).toBe(42);
|
||||
expired = true;
|
||||
expect(await read("/repo")).toBeNull();
|
||||
const attempts = run.mock.calls.length;
|
||||
expect(await read("/other")).toBeNull();
|
||||
expect(run).toHaveBeenCalledTimes(attempts);
|
||||
});
|
||||
|
||||
it("preserves transient lookup errors after successful authentication", async () => {
|
||||
const base = runner();
|
||||
const run = async (file: string, args: string[], cwd: string) => {
|
||||
if (args[0] === "repo")
|
||||
throw Object.assign(new Error("private stderr"), {
|
||||
code: 1,
|
||||
stderr: "error connecting to api.github.com",
|
||||
});
|
||||
return base(file, args, cwd);
|
||||
};
|
||||
await expect(
|
||||
createPullRequestStatusReader({ run })("/repo"),
|
||||
).rejects.toThrow(
|
||||
"Could not load pull request status. Check your connection and try again.",
|
||||
);
|
||||
});
|
||||
|
||||
it("accepts GitHub SSH/HTTPS remotes only", () => {
|
||||
for (const remote of [
|
||||
"git@github.com:cline/cline.git",
|
||||
"https://github.com/cline/cline.git",
|
||||
"ssh://git@github.com/cline/cline",
|
||||
])
|
||||
expect(githubRepository(remote)).toBe("cline/cline");
|
||||
expect(
|
||||
githubRepository("https://github.com.evil.test/cline/cline"),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("check and merge states", () => {
|
||||
it("handles check runs, legacy statuses, skipped checks and unsafe links", () => {
|
||||
const pending = normalizeCheck({
|
||||
__typename: "CheckRun",
|
||||
status: "IN_PROGRESS",
|
||||
conclusion: "SUCCESS",
|
||||
});
|
||||
const failed = normalizeCheck({
|
||||
__typename: "StatusContext",
|
||||
state: "ERROR",
|
||||
context: "Build",
|
||||
targetUrl: "javascript:alert(1)",
|
||||
});
|
||||
const skipped = normalizeCheck({
|
||||
__typename: "CheckRun",
|
||||
status: "COMPLETED",
|
||||
conclusion: "SKIPPED",
|
||||
});
|
||||
expect(pending.state).toBe("pending");
|
||||
expect(failed).toEqual({ name: "Build", state: "failure", url: undefined });
|
||||
expect(summarizeChecks([pending, failed])).toBe("failure");
|
||||
expect(summarizeChecks([skipped])).toBe("skipped");
|
||||
expect(summarizeChecks([])).toBe("none");
|
||||
});
|
||||
it("never calls an unknown, draft or blocked PR ready to merge", async () => {
|
||||
const result = await createPullRequestStatusReader({ run: runner() })(
|
||||
"/repo",
|
||||
);
|
||||
const value = result!.pullRequest!;
|
||||
expect(
|
||||
getMergeStatus({ ...value, mergeStateStatus: "BLOCKED" }).label,
|
||||
).toBe("Blocked");
|
||||
expect(getMergeStatus({ ...value, isDraft: true }).label).toBe("Draft");
|
||||
expect(
|
||||
getMergeStatus({
|
||||
...value,
|
||||
mergeable: "UNKNOWN",
|
||||
mergeStateStatus: "UNKNOWN",
|
||||
}).label,
|
||||
).toBe("Merge status pending");
|
||||
expect(getMergeStatus({ ...value, mergeable: "CONFLICTING" }).label).toBe(
|
||||
"Conflicts",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,269 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import type {
|
||||
PullRequestCheck,
|
||||
PullRequestStatus,
|
||||
} from "../webview/lib/pull-request";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
type RunCommand = (
|
||||
file: string,
|
||||
args: string[],
|
||||
cwd: string,
|
||||
) => Promise<string>;
|
||||
const runCommand: RunCommand = async (file, args, cwd) => {
|
||||
const { stdout } = await execFileAsync(file, args, {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
timeout: 15_000,
|
||||
maxBuffer: 2 * 1024 * 1024,
|
||||
env: { ...process.env, GH_PROMPT_DISABLED: "1", GIT_TERMINAL_PROMPT: "0" },
|
||||
});
|
||||
return stdout.trim();
|
||||
};
|
||||
|
||||
type GitHubCheck = {
|
||||
__typename: string;
|
||||
name?: string;
|
||||
context?: string;
|
||||
status?: string;
|
||||
conclusion?: string;
|
||||
state?: string;
|
||||
detailsUrl?: string;
|
||||
targetUrl?: string;
|
||||
};
|
||||
|
||||
export function normalizeCheck(check: GitHubCheck): PullRequestCheck {
|
||||
const result =
|
||||
check.__typename === "CheckRun"
|
||||
? check.status === "COMPLETED"
|
||||
? check.conclusion
|
||||
: "PENDING"
|
||||
: check.state;
|
||||
return {
|
||||
name: check.name || check.context || "Check",
|
||||
state:
|
||||
result === "SUCCESS"
|
||||
? "success"
|
||||
: result === "NEUTRAL" || result === "SKIPPED"
|
||||
? "skipped"
|
||||
: [
|
||||
"FAILURE",
|
||||
"ERROR",
|
||||
"CANCELLED",
|
||||
"TIMED_OUT",
|
||||
"ACTION_REQUIRED",
|
||||
"STALE",
|
||||
"STARTUP_FAILURE",
|
||||
].includes(result ?? "")
|
||||
? "failure"
|
||||
: "pending",
|
||||
url: safeHttpUrl(check.detailsUrl || check.targetUrl),
|
||||
};
|
||||
}
|
||||
|
||||
function safeHttpUrl(value?: string): string | undefined {
|
||||
if (!value) return undefined;
|
||||
try {
|
||||
const url = new URL(value);
|
||||
return ["https:", "http:"].includes(url.protocol) ? url.href : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function githubRepository(remote: string): string | null {
|
||||
const match = remote.match(
|
||||
/^(?:https:\/\/github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([^/]+)\/([^/]+?)\/?$/,
|
||||
);
|
||||
return match ? `${match[1]}/${match[2].replace(/\.git$/, "")}` : null;
|
||||
}
|
||||
|
||||
type GitHubPullRequest = Omit<
|
||||
NonNullable<PullRequestStatus["pullRequest"]>,
|
||||
"checks"
|
||||
> & {
|
||||
headRepositoryOwner: { login: string } | null;
|
||||
headRepository: { name: string } | null;
|
||||
statusCheckRollup: GitHubCheck[] | null;
|
||||
};
|
||||
|
||||
// Shared across workspaces: missing credentials are a machine-level capability,
|
||||
// not a repository failure. Retry after installation/login without polling gh.
|
||||
export const GITHUB_AVAILABILITY_CACHE_MS = 5 * 60_000;
|
||||
|
||||
function commandErrorCode(error: unknown): unknown {
|
||||
return error && typeof error === "object" && "code" in error
|
||||
? error.code
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function isAuthenticationFailure(error: unknown): boolean {
|
||||
if (commandErrorCode(error) === 4) return true;
|
||||
const stderr =
|
||||
error && typeof error === "object" && "stderr" in error
|
||||
? String(error.stderr)
|
||||
: "";
|
||||
return /HTTP 401|Bad credentials/i.test(stderr);
|
||||
}
|
||||
|
||||
export function createPullRequestStatusReader({
|
||||
run = runCommand,
|
||||
now = Date.now,
|
||||
}: {
|
||||
run?: RunCommand;
|
||||
now?: () => number;
|
||||
} = {}) {
|
||||
let available: boolean | undefined;
|
||||
let expiresAt = 0;
|
||||
let probe: Promise<boolean> | undefined;
|
||||
|
||||
function markUnavailable() {
|
||||
available = false;
|
||||
expiresAt = now() + GITHUB_AVAILABILITY_CACHE_MS;
|
||||
}
|
||||
|
||||
async function isAvailable(cwd: string): Promise<boolean> {
|
||||
if (available !== undefined && now() < expiresAt) return available;
|
||||
if (probe) return probe;
|
||||
probe = (async () => {
|
||||
try {
|
||||
await run(
|
||||
"gh",
|
||||
["auth", "status", "--active", "--hostname", "github.com"],
|
||||
cwd,
|
||||
);
|
||||
available = true;
|
||||
expiresAt = now() + GITHUB_AVAILABILITY_CACHE_MS;
|
||||
return true;
|
||||
} catch (error) {
|
||||
// gh auth status documents exit 1 for missing/invalid authentication.
|
||||
const code = commandErrorCode(error);
|
||||
if (code === "ENOENT" || code === 1 || code === 4) {
|
||||
markUnavailable();
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
})();
|
||||
try {
|
||||
return await probe;
|
||||
} finally {
|
||||
probe = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/** Read-only: creation is reviewed and submitted in GitHub's compare form. */
|
||||
return async function readPullRequestStatus(
|
||||
cwd: string,
|
||||
): Promise<PullRequestStatus | null> {
|
||||
if (available === false && now() < expiresAt) return null;
|
||||
const branch = await run("git", ["branch", "--show-current"], cwd).catch(
|
||||
() => "",
|
||||
);
|
||||
if (!branch) return null;
|
||||
const remote = await run("git", ["remote", "get-url", "origin"], cwd).catch(
|
||||
() => "",
|
||||
);
|
||||
const repository = githubRepository(remote);
|
||||
if (!repository) return null;
|
||||
try {
|
||||
if (!(await isAvailable(cwd))) return null;
|
||||
const repo = JSON.parse(
|
||||
await run(
|
||||
"gh",
|
||||
["repo", "view", repository, "--json", "defaultBranchRef"],
|
||||
cwd,
|
||||
),
|
||||
) as { defaultBranchRef: { name: string } | null };
|
||||
const base = repo.defaultBranchRef?.name;
|
||||
// The default branch can have years-old PRs from earlier branch workflows.
|
||||
// Those do not describe the current work, and it is not a PR source branch.
|
||||
if (branch === base) return null;
|
||||
const prsJson = await run(
|
||||
"gh",
|
||||
[
|
||||
"pr",
|
||||
"list",
|
||||
"--repo",
|
||||
repository,
|
||||
"--head",
|
||||
branch,
|
||||
"--state",
|
||||
"all",
|
||||
"--limit",
|
||||
"100",
|
||||
"--json",
|
||||
"number,state,headRepositoryOwner,headRepository",
|
||||
],
|
||||
cwd,
|
||||
);
|
||||
const [owner, name] = repository.split("/");
|
||||
const candidates = (
|
||||
JSON.parse(prsJson) as Pick<
|
||||
GitHubPullRequest,
|
||||
"number" | "state" | "headRepositoryOwner" | "headRepository"
|
||||
>[]
|
||||
).filter(
|
||||
(pr) =>
|
||||
pr.headRepositoryOwner?.login.toLowerCase() === owner.toLowerCase() &&
|
||||
pr.headRepository?.name.toLowerCase() === name.toLowerCase(),
|
||||
);
|
||||
const candidate =
|
||||
candidates.find((pr) => pr.state === "OPEN") ?? candidates[0];
|
||||
const pr = candidate
|
||||
? (JSON.parse(
|
||||
await run(
|
||||
"gh",
|
||||
[
|
||||
"pr",
|
||||
"view",
|
||||
String(candidate.number),
|
||||
"--repo",
|
||||
repository,
|
||||
"--json",
|
||||
"number,title,url,state,isDraft,mergeable,mergeStateStatus,additions,deletions,statusCheckRollup",
|
||||
],
|
||||
cwd,
|
||||
),
|
||||
) as GitHubPullRequest)
|
||||
: null;
|
||||
return {
|
||||
repository,
|
||||
branch,
|
||||
createUrl:
|
||||
base && branch !== base
|
||||
? `https://github.com/${repository}/compare/${encodeURIComponent(base)}...${encodeURIComponent(branch)}?expand=1`
|
||||
: null,
|
||||
pullRequest: pr
|
||||
? {
|
||||
number: pr.number,
|
||||
title: pr.title,
|
||||
url: pr.url,
|
||||
state: pr.state,
|
||||
isDraft: pr.isDraft,
|
||||
mergeable: pr.mergeable,
|
||||
mergeStateStatus: pr.mergeStateStatus,
|
||||
additions: pr.additions,
|
||||
deletions: pr.deletions,
|
||||
checks: (pr.statusCheckRollup ?? []).map(normalizeCheck),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
} catch (error) {
|
||||
// Authentication can expire while a positive availability result is cached.
|
||||
if (
|
||||
commandErrorCode(error) === "ENOENT" ||
|
||||
isAuthenticationFailure(error)
|
||||
) {
|
||||
markUnavailable();
|
||||
return null;
|
||||
}
|
||||
throw new Error(
|
||||
"Could not load pull request status. Check your connection and try again.",
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const getPullRequestStatus = createPullRequestStatusReader();
|
||||
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 8.9 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 923 KiB |
|
After Width: | Height: | Size: 879 KiB |
|
After Width: | Height: | Size: 282 KiB |
|
After Width: | Height: | Size: 736 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 238 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.7 KiB |