Skip to content

Add Qwen CLI driver - #114

Open
simone-stacks wants to merge 20 commits into
protocol-security:masterfrom
simone-stacks:feat/qwen-cli-driver
Open

simone-stacks wants to merge 20 commits into
protocol-security:masterfrom
simone-stacks:feat/qwen-cli-driver

Conversation

@simone-stacks

Copy link
Copy Markdown
Contributor

Builds on top of #113 (kimi driver); the diff shrinks to the qwen commits once that merges.

Summary

  • Add a qwen-cli driver so swarms can run Qwen Code CLI alongside the existing drivers.
  • Install Qwen Code CLI in the agent image from the official standalone archive, with a qwen_cli_version pin.
  • Wire the driver through launch, dashboard, docs, and tests.
  • Detect token-plan quota exhaustion even when the CLI exits 0, so agents back off and resume instead of dying mid-run.
  • Sum kimi token usage from the session wire.jsonl, so the swarmfile pricing map produces real costs for kimi (small fix riding on this branch).

Changes

  • lib/drivers/qwen-cli.sh: new driver implementing the swarm interface.
  • Dockerfile + launch.sh: install Qwen Code CLI and expose qwen_cli_version; forward QWEN_CONTEXT_WINDOW into agent containers.
  • dashboard.sh, USAGE.md, README.md, CHANGELOG.md: surface the new driver.
  • lib/drivers/kimi-cli.sh: read token usage from the session wire.jsonl (stream-json carries no usage object).
  • tests/: driver/config/dashboard/harness/launch coverage and qwen fixture swarmfiles.

Self-review checklist

  • This PR addresses a single concern (why?). If it covers multiple independent changes, I've split them into separate PRs.
  • The new driver is covered by unit tests.
  • The quota detection and wire-usage paths are covered by unit tests.
  • shellcheck -s bash passes on all modified .sh files.
  • New lines match the surrounding style (these files already have pre-existing >79-col lines).

Test plan

  • shellcheck -s bash lib/drivers/qwen-cli.sh lib/drivers/kimi-cli.sh dashboard.sh launch.sh tests/test_config.sh tests/test_dashboard.sh tests/test_drivers.sh tests/test_harness.sh tests/test_launch.sh
  • tests/test_drivers.sh (557 passed)
  • tests/test_config.sh (375 passed)
  • ./tests/test.sh --unit (note: test_harvest.sh has pre-existing failures on this machine — signing env, green in CI)
  • Live runs on stacks-swarm (9-agent validation + 4-agent engagement on qwen3.8-max): real token counts in the dashboard, quota backoff triggered instead of agent death, one triaged finding produced.

@simone-stacks
simone-stacks force-pushed the feat/qwen-cli-driver branch 2 times, most recently from 983e53d to 9235c22 Compare August 18, 2026 16:31
@simone-stacks
simone-stacks marked this pull request as draft August 24, 2026 10:48
@simone-stacks
simone-stacks marked this pull request as ready for review September 1, 2026 16:14
@radubahmata radubahmata mentioned this pull request Sep 3, 2026
5 of 10 tasks

@radubahmata radubahmata left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work and thanks for the PR! Left some comments.

Comment thread lib/drivers/qwen-cli.sh
Comment on lines +72 to +75
if [ -n "${DASHSCOPE_API_KEY:-}" ]; then
_qwen_write_settings "$model"
args+=(-m "${model##*/}")
else

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Keeping _qwen_write_settings behind the DASHSCOPE_API_KEY check appears intentional. API-key mode has no mounted Qwen configuration, so the driver must synthesize the provider, endpoint, authentication, and model settings. OAuth mode already has host configuration, and running the full writer there would overwrite its provider and login selection.

The effort override should not share that gate. agent_docker_env exports the swarmfile's effort as QWEN_REASONING_EFFORT for every authentication mode, but Qwen Code CLI does not consume that environment variable. Its supported model.reasoningEffort setting applies across all providers. Qwen also treats QWEN_OAUTH as a DashScope provider and preserves the global effort through initial authentication.

For auth: "oauth", agent_settings copies the host settings unchanged, so an agent configured with an effort such as high silently continues using the host or CLI default even though the dashboard shows high. Do not run the API-key settings writer for OAuth. Instead, when the swarmfile sets effort, merge only model.reasoningEffort into the writable OAuth settings copy while preserving every host provider and login field.

Can you please add an OAuth-path regression test that starts with host settings, applies the requested effort, and asserts the existing configuration is unchanged?

Comment thread USAGE.md
Comment on lines +87 to +89
- Qwen Code CLI: `low`, `medium`, `high`, `xhigh`, `max` (written to
`model.reasoningEffort`; on DashScope-backed qwen models any set tier
currently collapses to `enable_thinking: true`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here, it says every effort tier on DashScope-backed Qwen models collapses to enable_thinking: true. Qwen Code CLI explicitly special-cases qwen3.8-max, the driver's default model, and passes all five tiers through as reasoning_effort. Other Qwen models may use the boolean enable_thinking mapping.

Document the qwen3.8-max pass-through behavior separately from the fallback behavior used by other Qwen models. Update the matching comment at https://github.com/simone-stacks/claude-swarm/blob/24b3ae8ad55c59ebd39e50e0693d478dc42f0ee1/lib/drivers/qwen-cli.sh#L318-L323 at the same time.

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