Skip to content

fix(api): wire task controls and sidebar-targeted configuration (vps2 F5) - #1557

Draft
easonLiangWorldedtech wants to merge 9 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:vps2/f5-api-wiring
Draft

fix(api): wire task controls and sidebar-targeted configuration (vps2 F5)#1557
easonLiangWorldedtech wants to merge 9 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:vps2/f5-api-wiring

Conversation

@easonLiangWorldedtech

@easonLiangWorldedtech easonLiangWorldedtech commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Tracking: easonLiangWorldedtech#41 (vps2 series ledger). Upstream issue: #1556 (this series' gap record; the original upstream bug is #982). Port source: upstream PR #983 (closed/superseded; named in the #41 ledger).

Scope

5 files vs the F4 head 80c147f:

  1. packages/types/src/api.ts (20+/2-) — the two documented doc fixes from the [BUG] GPT-5.5 Codex uses incorrect context window #41 F5 scope row: the preserveOpenTabs @PARAM JSDoc on startNewTask, and the stale setConfiguration JSDoc rewrite (writes target the extension-host (sidebar) view: view-local values pinned to the sidebar's per-view state, global values to the shared ContextProxy). Comment/type-level only; zero executable change.
  2. src/extension/api.ts (116+/6-) — the wiring port: setConfiguration/getConfiguration synced through provider state; task registry on TaskCreated/TaskCompleted/TaskAborted; approveTaskAsk/denyAsk; selectTaskFollowupSuggestion (the mode-switch-failure path still delivers the follow-up answer and logs to the output channel); preserveOpenTabs passthrough; getGlobalState.
  3. src/extension/tests/api-task-control.spec.ts (new, 320).
  4. src/extension/tests/api-set-configuration.spec.ts (new, 55).
  5. src/extension/tests/api-configuration.spec.ts (new, 38).

Standalone diff vs stack base 80c147f: 5 files changed, 549 insertions(+), 8 deletions(-) — a+d 557.

Budget

  • a+d 557 vs the 400-soft / 1000-hard budget: soft exceeded, under hard. Rationale: the [BUG] GPT-5.5 Codex uses incorrect context window #41 estimate (~250) assumed the wiring existed at the base — it did not. At the F1a head, src/extension/api.ts had no preserveOpenTabs, no task registry, no approveTaskAsk, no selectTaskFollowupSuggestion, no getGlobalState; setConfiguration called contextProxy.setValues directly; getConfiguration had no flatten/secret-strip. The [BUG] Sync API setConfiguration through provider state wiring #982 wiring-exists verdict is therefore NOT HELD, and the CS src/extension/api.ts code port is included (this is the bulk of the diff).
  • Stryker-diff gate (vs 80c147f): 46 executable changed lines / 26 ranges in the extension package (under the 500-line cap); 42 raw mutants, all Killed — 0 Survived / 0 NoCoverage / 0 Timeout (exit 0 at head 95a18b2 on the F4 base). The F1a-head (126a1fc4d) and F2-head (b587511) runs recorded the identical 46/26/42 profile — the re-stacks move only the base, not the five files.
  • vitest: 17/17 (task-control 13, set-configuration 1, configuration 3) (task-control 13 = 12 CS-verbatim tests + 1 coordinator-added; set-configuration 1; configuration 3).
  • check-types (src + packages/types), eslint (--prune-suppressions, 0 as any, suppression counts flat), prettier (--end-of-line=auto): all green.

Port fidelity (coordinator-verified against the vps2 CS e9a44b2)

  • src/extension/api.ts: byte-identical to the CS blob (verified by diff and by SHA-256).
  • packages/types/src/api.ts: CS blob + exactly the two F5-only JSDoc deltas above (the fix(api): sync setConfiguration with provider state #983 doc fixes); no other divergence.
  • The three spec files: CS-verbatim, except api-task-control.spec.ts carries 15 lines of coordinator-added mutation-kill tests:
    1. "still delivers the follow-up answer when the mode switch fails" now constructs the API with enableLogging=true and asserts the output-channel line "[API#selectTaskFollowupSuggestion] mode switch failed for task task-failing-switch: persist failed";
    2. new test "ignores a late teardown event after the registry entry was already removed" — TaskCompleted removes the registry entry; a late duplicate TaskAborted is a silent no-op and approveTaskAsk resolves false.
  • Re-stack integrity: the five file blobs are byte-identical across all three commits 126a1fc4d (F1a head), b587511 (F2 head), and 95a18b2 (F4 head) — verified by blob SHA (a0456290 / 1dd9b48d / 9fd0118c / 5572c6e7 / 23619c89), so every gate result carried across the re-stacks.

Parked limitation (documented, not fixed)

Sidebar-only API targeting (#41 parked item 10, the A4 major): the extension API always targets the sidebar/extension-host provider — setConfiguration/getConfiguration/getGlobalState and the task controls operate against that one provider instance. A per-view API handle would be a redesign (architectural fix) and is out of scope for this series; documented here as a known limitation.

Series mechanics

  • Base of record: upstream/main @ 0d937c0; PR base is main; the branch is stacked on the F4 head 80c147f (commit 95a18b2) — re-stacked twice: from the F1a-head commit 126a1fc4d onto the F2 head (b587511), then onto the F4 head because F6's e2e suite needs the F3/F4 per-view write content; F1b/F1c/F2/F3/F4 touch none of the five files, so each restack applies cleanly (blob-identical diff).
  • Draft PR per unit; merge order F1a → F1b → F1c → F2 → F3 → F4 → F5 → F6 → F7.
  • Merge check against upstream main 4c7474d (merge-base = base of record 0d937c0), via git merge-tree on the full F0-to-F5 stack: tree b0b57d464c43ae2a9d0ae41112c8dac6ded65e50; auto-merges Task.ts, Task.spec.ts, ClineProvider.ts, ClineProvider.spec.ts; the sole conflict is src/eslint-suppressions.json (stage blobs base 0706dbe6fb5c / upstream 381cf0c1e03f / F5 73323b9f3c43 — F3's flat-suppression state vs upstream drift; resolved by mechanical prune at merge time).
  • CS not-ported register (for consistency): kimi-code OAuth try/catch + routerModels.spec +29; ApiConfigManager min-w-0→grow; ApiConfigManager.visual.tsx deletion + 2 PNG baselines; mojibake comment; providers/, .coderabbit.yaml, .github/, CONTRIBUTING.md, .gitignore churn — none of these touch the five files in this PR.

@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • coderabbit-review-active

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 2ddcadc8-fce4-406a-a407-4b9a5d30d7dc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Mark the PR ready. Required CI must pass before CodeRabbit starts.

Review-state labels are managed by this workflow; do not edit them manually.

@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.56757% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/core/webview/ClineProvider.ts 98.38% 0 Missing and 4 partials ⚠️
webview-ui/src/utils/vscode.ts 86.36% 1 Missing and 2 partials ⚠️
src/extension/api.ts 94.28% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added the has-conflicts PR has merge conflicts with the base branch label Sep 7, 2026
…States

Each ClineProvider instance now owns a unique viewId (renderContext plus a
monotonic counter) and registers a stable viewStateId for durable persistence.

- Per-view state buffer (viewLocalState) holds mode / currentApiConfigName /
  apiConfiguration overrides in memory; saveViewState persists the non-secret
  subset durably under the active view id, rekeyed to the stable id on
  registration.
- viewStates is stored as a map pruned to the newest 50 entries; writes go
  through a serialized queue so concurrent provider instances merge without
  lost updates.
- setViewStateId sanitizes ids and rejects "__proto__" so a per-view entry can
  never be keyed through the Object.prototype setter.
- postMessageToWebview no longer awaits the webview ack: a remounted or
  disposed page never acknowledges, and awaiting would wedge task-critical
  callers.
- History restore falls back to the default mode view-locally instead of
  writing the shared global mode.
- GlobalState gains the "viewStates" key and GLOBAL_STATE_KEYS tracks it.

Adds F1a coverage in ClineProvider.spec.ts (viewId uniqueness, saveViewState
persistence semantics, loadViewState fallback and failure, pruning, the
__proto__ guard) and adapts the two history-restore tests in
ClineProvider.sticky-mode.spec.ts to the view-local restore. getState()
merging of hydrated per-view values and the remaining view-state suites land
in the follow-up (F1b).
…overrides

Fold ClineProvider viewLocalState on top of ContextProxy values in getState() (mode, apiConfiguration, and all per-view fields) so each webview reports its own selections while falling back to shared global state for everything else. Ports the getState-merging and local-state-isolation spec coverage from the superseded vps2 source.

Also pins the full default surface of the merged read path, including the apiConfiguration provider fill-in when provider settings sanitize the raw value away (mutation-diff gate).
… state

WMH webviewDidLaunch persists the webview view-state id via provider.setViewStateId and re-pins the view-local currentApiConfigName through provider.saveViewState when the view-local profile is missing but the shared global selection is still valid. updateSettings is routed through provider.setValue so view-local buffer and pin sync stay consistent with the other mutation paths. The webview VSCodeAPIWrapper gains a stable getViewStateId persisted via setState (with an in-memory fallback) and the launch effect posts the id with the webviewDidLaunch message.
Port vps2 F3 (mode/profile writes) from upstream 978, hunk-by-hunk against
the F1c..CS residual:

- ClineProvider: add repointPersistedViewStates() to re-point
  currentApiConfigName across per-view entries when a profile is renamed
  or replaced, and prune orphaned entries; validate handleModeSwitch slugs
  against the custom-modes manager and no-op with a log on unknown modes;
  drop the as-any cast in delegateParentAndOpenChild.
- Task: route mode switches through provider.handleModeSwitch(task) and
  keep the submitted message on failure instead of setMode().
- SwitchModeTool and specs: durable per-view mode writes.
- webviewMessageHandler: no change vs base - the kimi-code OAuth hunk in
  the residual is CS-only divergence (not-ported register item 1), not
  part of Zoo-Code-Org#978/Zoo-Code-Org#979.
- webviewMessageHandler.spec: ported only Zoo-Code-Org#979's 4 mock fields +
  defaultModeSlug import; the stack-side legacy-repair test, Key-aware
  getValue mock and em-dash comment are retained (register item 4).
  Zoo-Code-Org#979's mode-routing WMH.spec describe ("routes mode messages through
  handleModeSwitch instead of writing ContextProxy directly") exists in
  neither CS nor the stack and is ported by no unit (open question,
  logged).
- Tests: H3/H4 durable handleModeSwitch writes in ClineProvider.spec.ts;
  profile-mutation, profile-activation and handleModeSwitch-integration
  describes (incl. A4 non-focused-target regression and new
  mutation-killing tests) in ClineProvider.parallelMode.spec.ts;
  sticky-mode and webviewMessageHandler spec updates; retain the
  setViewStateId __proto__ guard + spec test - shipped F1a hardening;
  the residual's guard removal is lineage divergence, not F3 content.
- eslint-suppressions.json: no-explicit-any counts decrease for
  core/webview/ClineProvider.ts (12 -> 11) and
  core/webview/__tests__/ClineProvider.sticky-mode.spec.ts (36 -> 33).

Upstream: Zoo-Code-Org#978 (vps2 F3) - issue Zoo-Code-Org#978; content ported
hunk-by-hunk from the F1c..CS residual, cross-checked against upstream PR
…s import

- ClineProvider: new broadcastResetToAllInstances() clears each live instance's
  view-local cache and issues the single global contextProxy setValue("viewStates", undefined)
  write (single write-queue clear; no secrets involved, no prune-cap regression).
- resetState: awaits broadcastResetToAllInstances() before the final postStateToWebview
  so parallel tabs do not keep stale durable/in-memory per-view state.
- importExport: ImportWithProviderOptions.provider gains optional
  broadcastResetToAllInstances?(); importSettingsWithFeedback calls it in a guarded
  try/catch (log-only) after a successful import, so a failing broadcast never fails the import.
- importExport spec: 3 new tests (broadcast called when available / skipped when missing /
  import result preserved when broadcast throws, console.warn asserted; the skip test also
  asserts the broadcast-failure warn is NOT reached). Provider identifiers use
  providerIdentifiers.* per the zoo/no-raw-provider-identifiers rule (lint-required
  adaptation from Zoo-Code-Org#981's raw-string casts; no semantic change).
- parallelMode spec: appends the CS source-of-record describes (multi-instance isolation,
  _clearViewLocalState) — 5 new tests.
- ClineProvider spec: forward fix of the F3 resetState sentinel (F4's global viewStates
  clear removes the key; the F3-era toEqual({}) expectation is replaced by toBeUndefined())
  plus a new cross-instance resetState test pinning the multi-instance broadcast path
  (sibling view-local cache cleared; sibling and caller each post state exactly once).
- webviewMessageHandler.ts was NOT edited: the importSettings case already passes the full
  ClineProvider, which structurally satisfies the extended provider type and reaches the real
  broadcast method — Zoo-Code-Org#981's structural wrapper hunk is redundant in this stack.

Upstream: Zoo-Code-Org#980 / PR Zoo-Code-Org#981 (vps2 F4)
Ports the vps2 CS API wiring onto the F4 head 80c147f:

- startNewTask(newTab, preserveOpenTabs): skips editor revert/close-all
  when preserveOpenTabs is set
- task ask registry: approveTaskAsk + selectTaskFollowupSuggestion
  (per-provider mode validation; a failed mode switch does not swallow
  the follow-up answer; a stale instance's teardown cannot evict its
  replacement)
- setConfiguration routes through ClineProvider.setValues so the
  view-local subset stays in sync with the sidebar view's state
- getConfiguration flattens the nested view-local apiConfiguration and
  strips secrets before returning
- getGlobalState read surface (test-only)
- docs: setConfiguration JSDoc now states writes target the
  extension-host (sidebar) view (parked A4 major, documented
  limitation); @PARAM note added for preserveOpenTabs
- specs: api-task-control (12 tests), api-set-configuration (1),
  api-configuration getConfiguration flatten/strip-secrets (1)

Upstream: Zoo-Code-Org#982 (vps2 F5)
@github-actions github-actions Bot removed the has-conflicts PR has merge conflicts with the base branch label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants