Skip to content

Conversation

@Mingholy
Copy link
Collaborator

@Mingholy Mingholy commented Nov 25, 2025

TLDR

This PR introduces TypeScript SDK (@qwen-code/sdk-typescript) for programmatic access to qwen-code CLI.

Todo Actions

  • Refined type exports
  • Comprehensive E2E and unit tests
  • Logging utilities with scoped logger support
  • allowedTools and permission control
  • Extra error handling for plan mode in SDK
  • Extra error handling for 429 rate limit errors
  • Automatic build and release workflow

Dive Deeper

SDK Package

Added packages/sdk-typescript:

  • Query API: query() function and Query class for CLI interaction
  • Transport Layer: ProcessTransport with JSON Lines protocol
  • Stream Utilities: Async iteration and data flow handling
  • CLI Path Resolution: Cross-environment CLI spawning
  • Type Definitions: Full TypeScript types for messages and protocol
  • Subagent Support: Interact with qwen-code subagents
  • External MCP Server: Connect to 3rd party MCP servers
  • Tool Control: allowedTools for fine-grained tool access control
  • Logging: Scoped logger with configurable log levels

CLI & Core Updates

  • Refactored non-interactive session for SDK control protocol
  • Updated control service and permission controllers for SDK flow
  • Enhanced subagent manager for SDK-based operations
  • Updated configuration handling for SDK integration

Testing

  • E2E: single-turn, multi-turn, abort/lifecycle, permission control, MCP servers, subagents, tool control, system control, configuration options
  • Unit: transport, query, streams, CLI path resolution, MCP server

Reviewer Test Plan

  1. Run SDK Tests: npm test in packages/sdk-typescript to verify all unit and e2e tests pass
  2. Test SDK Query: Create a simple script using query() to send a prompt to qwen-code CLI
  3. Test External MCP Servers: Verify SDK can connect to 3rd party MCP servers via query options
  4. Test Subagent Integration: Run the subagent e2e tests to verify SDK can interact with subagents
  5. Test CLI Integration: Run existing CLI tests to ensure backward compatibility

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Part of the SDK development initiative.

@github-actions
Copy link
Contributor

📋 Review Summary

This PR introduces a foundational TypeScript SDK (@qwen-code/sdk-typescript) for programmatic access to the qwen-code CLI, along with significant updates to the CLI's non-interactive mode to support SDK integration. The changes enable developers to programmatically interact with qwen-code through a well-defined API, supporting features like single/multi-turn conversations, subagent management, and MCP server integration.

🔍 General Feedback

  • The SDK implementation follows good architectural patterns with clear separation of concerns between transport, query, and utility layers
  • Comprehensive test coverage with both unit and end-to-end tests demonstrates attention to quality
  • Good use of TypeScript types and Zod schemas for validation enhances type safety
  • CLI modifications appropriately extend functionality without breaking existing behavior
  • The introduction of stream-json input/output formats enables robust programmatic communication

🎯 Specific Feedback

🟢 Medium

  • File: packages/sdk-typescript/src/query/Query.ts:140 - Consider adding more detailed error handling for edge cases in the message router to improve debugging experience
  • File: packages/sdk-typescript/src/transport/ProcessTransport.ts:85 - The buildCliArguments method could benefit from more granular unit tests to cover all parameter combinations
  • File: packages/cli/src/config/config.ts:404 - CLI option parsing for array values (core-tools, exclude-tools) uses flatMap which may not handle all edge cases with whitespace; consider adding more robust input validation

🔵 Low

  • File: packages/sdk-typescript/src/utils/cliPath.ts:135 - The runtime detection logic could be enhanced to check for specific version requirements for runtimes like Bun or Deno
  • File: packages/sdk-typescript/src/query/createQuery.ts:75 - Consider adding JSDoc comments to exported functions to improve developer experience
  • File: packages/cli/src/nonInteractive/session.ts:170 - The deferred initialization logic for stream-json mode could benefit from additional logging to help with debugging connection issues

✅ Highlights

  • Excellent test coverage with thoughtful end-to-end scenarios covering single-turn, multi-turn, subagents, and MCP server integration
  • Well-designed Transport abstraction that cleanly separates process management from protocol concerns
  • Clean implementation of CLI argument passing from SDK to spawned processes
  • Thoughtful error handling with custom error types and proper propagation
  • Good use of TypeScript generics and type guards to ensure type safety across async boundaries

…pescript

- Introduced a new logging system with adjustable log levels (debug, info, warn, error).
- Updated query options to include a logLevel parameter for controlling verbosity.
- Refactored existing code to utilize the new logging system for better error handling and debugging.
- Cleaned up unused code and improved the structure of the SDK.
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