Skip to content

fix(cosh): filter unavailable agents in key sharing prompt#394

Merged
kongche-jbw merged 1 commit intoalibaba:mainfrom
samchu-zsl:fix/cosh/386-filter-agent-options
Apr 28, 2026
Merged

fix(cosh): filter unavailable agents in key sharing prompt#394
kongche-jbw merged 1 commit intoalibaba:mainfrom
samchu-zsl:fix/cosh/386-filter-agent-options

Conversation

@samchu-zsl
Copy link
Copy Markdown
Collaborator

Description

Fix the Custom Provider auth flow so the Agent Key Sharing prompt only
offers agents whose config directory actually exists on the host.

Previously the share list was hard-coded to OpenClaw and Qwen Code,
and the flow was gated by a single "any agent config dir present"
boolean. When only one of the two was installed, users still saw the
missing agent in the list (the exact scenario reported in #386
~/.qwen is absent but the Qwen Code option is shown anyway). The
auto-skip to manual config also required both agents to fail, so a
user with only one installed agent whose key could not be read got
stuck re-selecting the same agent instead of falling through to manual
entry.

Per-agent detection results (hasOpenclawDir, hasQwenCodeDir) are
now computed once on entering the USE_OPENAI flow and used both to
filter the CustomAgentKeySharePrompt (missing agents are added to
excludedChoices) and to gate the idle → done transition (all
detectable agents failed, not all agents). File I/O behavior is
unchanged: directory probing still uses existsSync only, no config
files are read until the user picks an agent.

Related Issue

closes #386

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Scope

  • cosh (copilot-shell)

Checklist

  • I have read the Contributing Guide
  • My code follows the project's code style
  • I have added tests that prove my fix is effective or that my feature works
  • For cosh: Lint passes, type check passes, and tests pass
  • Lock files are up to date (package-lock.json / Cargo.lock)

Testing

cd src/copilot-shell
npm run format && npm run build && npm run lint && npm run typecheck && npm run test
# format OK, build OK, lint OK, typecheck OK
# cli:  Test Files 218 passed, Tests 3421 passed | 7 skipped
# core: Test Files 178 passed, Tests 3858 passed | 2 skipped
# Added CustomAgentKeySharePrompt.test.tsx (4 tests) covering the
# excludedChoices filter for missing agents.

Additional Notes

The Custom Provider auth flow previously rendered a hard-coded list of
agents (OpenClaw, Qwen Code) whenever any single agent config dir was
detected, so users without the corresponding install still saw import
prompts for missing agents and got stuck if their only present agent
failed key detection.

Per-agent detection results are now used to filter the share list
and the done-transition condition, so only agents whose config dir
actually exists are offered, and the flow auto-skips to manual config
once every detectable agent has failed.

Closes alibaba#386
@gemini-code-assist
Copy link
Copy Markdown

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@samchu-zsl
Copy link
Copy Markdown
Collaborator Author

Caution

This PR was generated and submitted by AI.
Please review all changes carefully before merging. Pay special attention to logic correctness, edge cases, and potential side effects.

@github-actions github-actions Bot added the component:cosh src/copilot-shell/ label Apr 28, 2026
@samchu-zsl
Copy link
Copy Markdown
Collaborator Author

Manual testing successful:

  1. If ~/{.openclaw, .qwen} does not exist, key sharing is skipped automatically
  2. If only one of .openclaw/.qwen exists, only existing agent entries are shown
  3. If both exist, both are displayed together

Confirmed the fix has no impact on other code logic.

@samchu-zsl samchu-zsl marked this pull request as ready for review April 28, 2026 03:17
@samchu-zsl samchu-zsl requested a review from kongche-jbw as a code owner April 28, 2026 03:17
@gemini-code-assist
Copy link
Copy Markdown

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

Copy link
Copy Markdown
Collaborator

@kongche-jbw kongche-jbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@samchu-zsl samchu-zsl requested a review from KaiLongZhou April 28, 2026 07:19
@kongche-jbw
Copy link
Copy Markdown
Collaborator

Consider deduplicating excludedChoices — using a Set prevents any future edge case.

@kongche-jbw kongche-jbw merged commit 7fbf9a8 into alibaba:main Apr 28, 2026
13 checks passed
@samchu-zsl samchu-zsl deleted the fix/cosh/386-filter-agent-options branch April 29, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:cosh src/copilot-shell/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cosh] bug: root目录下默认没有Qwen Code的配置,但进入Custom Provider界面却提示用户是否要从Qwen Code导入API Key

2 participants