mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-10-19 12:43:39 +00:00
chore(docs,test): batch three small docs and test fixes (#7373)
* docs(sdk): document auto permission mode * docs(sdk): clarify auto permission mode * docs(action): fix GitHub Action input names * test(weixin): cover exported AES key parser --------- Co-authored-by: 俊良 <zzj542558@alibaba-inc.com>
This commit is contained in:
parent
fe9fbe0fc7
commit
cf6c51396c
4 changed files with 21 additions and 34 deletions
|
|
@ -60,7 +60,7 @@ Creates a new query session with the Qwen Code.
|
|||
| `cwd` | `string` | `process.cwd()` | The working directory for the query session. Determines the context in which file operations and commands are executed. |
|
||||
| `model` | `string` | - | The AI model to use (e.g., `'qwen-max'`, `'qwen-plus'`, `'qwen-turbo'`). Takes precedence over `OPENAI_MODEL` and `QWEN_MODEL` environment variables. |
|
||||
| `pathToQwenExecutable` | `string` | Auto-detected | Path to the Qwen Code executable. Supports multiple formats: `'qwen'` (native binary from PATH), `'/path/to/qwen'` (explicit path), `'/path/to/cli.js'` (Node.js bundle), `'node:/path/to/cli.js'` (force Node.js runtime), `'bun:/path/to/cli.js'` (force Bun runtime). If not provided, auto-detects from: `QWEN_CODE_CLI_PATH` env var, `~/.volta/bin/qwen`, `~/.npm-global/bin/qwen`, `/usr/local/bin/qwen`, `~/.local/bin/qwen`, `~/node_modules/.bin/qwen`, `~/.yarn/bin/qwen`. |
|
||||
| `permissionMode` | `'default' \| 'plan' \| 'auto-edit' \| 'yolo'` | `'default'` | Permission mode controlling tool execution approval. See [Permission Modes](#permission-modes) for details. |
|
||||
| `permissionMode` | `'default' \| 'plan' \| 'auto-edit' \| 'auto' \| 'yolo'` | `'default'` | Permission mode controlling tool execution approval. See [Permission Modes](#permission-modes) for details. |
|
||||
| `canUseTool` | `CanUseTool` | - | Custom permission handler for tool execution approval. Invoked when a tool requires confirmation. Must respond within 60 seconds or the request will be auto-denied. See [Custom Permission Handler](#custom-permission-handler). |
|
||||
| `env` | `Record<string, string>` | - | Environment variables to pass to the Qwen Code process. Merged with the current process environment. |
|
||||
| `systemPrompt` | `string \| QuerySystemPromptPreset` | - | System prompt configuration for the main session. Use a string to fully override the built-in Qwen Code system prompt, or a preset object to keep the built-in prompt and append extra instructions. |
|
||||
|
|
@ -164,6 +164,7 @@ The SDK supports different permission modes for controlling tool execution:
|
|||
- **`default`**: Write tools are denied unless approved via `canUseTool` callback or in `allowedTools`. Read-only tools execute without confirmation.
|
||||
- **`plan`**: Blocks all write tools, instructing AI to present a plan first.
|
||||
- **`auto-edit`**: Auto-approve edit tools (`edit`, `write_file`, `notebook_edit`) while other tools require confirmation.
|
||||
- **`auto`**: Uses the built-in classifier to auto-approve safe tool calls and block risky ones, with manual-approval fallback after repeated policy blocks or classifier outages.
|
||||
- **`yolo`**: All tools execute automatically without confirmation.
|
||||
|
||||
### Permission Priority Chain
|
||||
|
|
@ -177,8 +178,9 @@ The first matching rule wins.
|
|||
3. `permissionMode: 'plan'` - Blocks all non-read-only tools
|
||||
4. `permissionMode: 'yolo'` - Auto-approves all tools
|
||||
5. `allowedTools` / `permissions.allow` - Auto-approves matching tools
|
||||
6. `canUseTool` callback - Custom approval logic (if provided, not called for allowed tools)
|
||||
7. Default behavior - Auto-deny in SDK mode (write tools require explicit approval)
|
||||
6. `permissionMode: 'auto'` - Classifier-mediated approval for remaining tools
|
||||
7. `canUseTool` callback - Custom approval logic (if provided, not called for allowed tools)
|
||||
8. Default behavior - Auto-deny in SDK mode (write tools require explicit approval)
|
||||
|
||||
## Examples
|
||||
|
||||
|
|
|
|||
|
|
@ -112,32 +112,32 @@ This type of action can be used to invoke a general-purpose, conversational Qwen
|
|||
|
||||
<!-- BEGIN_AUTOGEN_INPUTS -->
|
||||
|
||||
- <a name="__input_qwen_api_key"></a><a href="#user-content-__input_qwen_api_key"><code>qwen*api_key</code></a>: *(Optional)\_ The API key for the Qwen API.
|
||||
- <a name="__input_qwen_api_key"></a><a href="#user-content-__input_qwen_api_key"><code>qwen_api_key</code></a>: _(Optional)_ The API key for the Qwen API.
|
||||
|
||||
- <a name="__input_qwen_cli_version"></a><a href="#user-content-__input_qwen_cli_version"><code>qwen*cli_version</code></a>: *(Optional, default: `latest`)\_ The version of the Qwen Code CLI to install. Can be "latest", "preview", "nightly", a specific version number, or a git branch, tag, or commit. For more information, see [Qwen Code CLI releases](https://github.com/QwenLM/qwen-code-action/blob/main/docs/releases.md).
|
||||
- <a name="__input_qwen_cli_version"></a><a href="#user-content-__input_qwen_cli_version"><code>qwen_cli_version</code></a>: _(Optional, default: `latest`)_ The version of the Qwen Code CLI to install. Can be "latest", "preview", "nightly", a specific version number, or a git branch, tag, or commit. For more information, see [Qwen Code CLI releases](https://github.com/QwenLM/qwen-code-action/blob/main/docs/releases.md).
|
||||
|
||||
- <a name="__input_qwen_debug"></a><a href="#user-content-__input_qwen_debug"><code>qwen*debug</code></a>: *(Optional)\_ Enable debug logging and output streaming.
|
||||
- <a name="__input_qwen_debug"></a><a href="#user-content-__input_qwen_debug"><code>qwen_debug</code></a>: _(Optional)_ Enable debug logging and output streaming.
|
||||
|
||||
- <a name="__input_qwen_model"></a><a href="#user-content-__input_qwen_model"><code>qwen*model</code></a>: *(Optional)\_ The model to use with Qwen Code.
|
||||
- <a name="__input_qwen_model"></a><a href="#user-content-__input_qwen_model"><code>qwen_model</code></a>: _(Optional)_ The model to use with Qwen Code.
|
||||
|
||||
- <a name="__input_prompt"></a><a href="#user-content-__input_prompt"><code>prompt</code></a>: _(Optional, default: `You are a helpful assistant.`)_ A string passed to the Qwen Code CLI's [`--prompt` argument](https://github.com/QwenLM/qwen-code-action/blob/main/docs/cli/configuration.md#command-line-arguments).
|
||||
|
||||
- <a name="__input_settings"></a><a href="#user-content-__input_settings"><code>settings</code></a>: _(Optional)_ A JSON string written to `.qwen/settings.json` to configure the CLI's _project_ settings.
|
||||
For more details, see the documentation on [settings files](https://github.com/QwenLM/qwen-code-action/blob/main/docs/cli/configuration.md#settings-files).
|
||||
|
||||
- <a name="__input_use_qwen_code_assist"></a><a href="#user-content-__input_use_qwen_code_assist"><code>use*qwen_code_assist</code></a>: *(Optional, default: `false`)\_ Whether to use Code Assist for Qwen Code model access instead of the default Qwen Code API key.
|
||||
- <a name="__input_use_qwen_code_assist"></a><a href="#user-content-__input_use_qwen_code_assist"><code>use_qwen_code_assist</code></a>: _(Optional, default: `false`)_ Whether to use Code Assist for Qwen Code model access instead of the default Qwen Code API key.
|
||||
For more information, see the [Qwen Code CLI documentation](https://github.com/QwenLM/qwen-code-action/blob/main/docs/cli/authentication.md).
|
||||
|
||||
- <a name="__input_use_vertex_ai"></a><a href="#user-content-__input_use_vertex_ai"><code>use*vertex_ai</code></a>: *(Optional, default: `false`)\_ Whether to use Vertex AI for Qwen Code model access instead of the default Qwen Code API key.
|
||||
- <a name="__input_use_vertex_ai"></a><a href="#user-content-__input_use_vertex_ai"><code>use_vertex_ai</code></a>: _(Optional, default: `false`)_ Whether to use Vertex AI for Qwen Code model access instead of the default Qwen Code API key.
|
||||
For more information, see the [Qwen Code CLI documentation](https://github.com/QwenLM/qwen-code-action/blob/main/docs/cli/authentication.md).
|
||||
|
||||
- <a name="__input_extensions"></a><a href="#user-content-__input_extensions"><code>extensions</code></a>: _(Optional)_ A list of Qwen Code CLI extensions to install.
|
||||
|
||||
- <a name="__input_upload_artifacts"></a><a href="#user-content-__input_upload_artifacts"><code>upload*artifacts</code></a>: *(Optional, default: `false`)\_ Whether to upload artifacts to the github action.
|
||||
- <a name="__input_upload_artifacts"></a><a href="#user-content-__input_upload_artifacts"><code>upload_artifacts</code></a>: _(Optional, default: `false`)_ Whether to upload artifacts to the github action.
|
||||
|
||||
- <a name="__input_use_pnpm"></a><a href="#user-content-__input_use_pnpm"><code>use*pnpm</code></a>: *(Optional, default: `false`)\_ Whether or not to use pnpm instead of npm to install qwen-code-cli
|
||||
- <a name="__input_use_pnpm"></a><a href="#user-content-__input_use_pnpm"><code>use_pnpm</code></a>: _(Optional, default: `false`)_ Whether or not to use pnpm instead of npm to install qwen-code-cli
|
||||
|
||||
- <a name="__input_workflow_name"></a><a href="#user-content-__input_workflow_name"><code>workflow*name</code></a>: *(Optional, default: `${{ github.workflow }}`)\_ The GitHub workflow name, used for telemetry purposes.
|
||||
- <a name="__input_workflow_name"></a><a href="#user-content-__input_workflow_name"><code>workflow_name</code></a>: _(Optional, default: `${{ github.workflow }}`)_ The GitHub workflow name, used for telemetry purposes.
|
||||
|
||||
<!-- END_AUTOGEN_INPUTS -->
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,12 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { createDecipheriv, createCipheriv } from 'node:crypto';
|
||||
import { encryptAesEcb, computeMd5 } from './media.js';
|
||||
import { encryptAesEcb, computeMd5, parseAesKey } from './media.js';
|
||||
|
||||
/**
|
||||
* Test the AES key parsing and decryption logic used in media.ts.
|
||||
* We test the pure crypto functions by reimplementing them here
|
||||
* since they're not exported, but the behavior must match.
|
||||
* decryptAesEcb remains private, so keep only that helper here.
|
||||
*/
|
||||
|
||||
function parseAesKey(aesKeyBase64: string): Buffer {
|
||||
const decoded = Buffer.from(aesKeyBase64, 'base64');
|
||||
if (decoded.length === 16) {
|
||||
return decoded;
|
||||
}
|
||||
if (
|
||||
decoded.length === 32 &&
|
||||
/^[0-9a-fA-F]{32}$/.test(decoded.toString('ascii'))
|
||||
) {
|
||||
return Buffer.from(decoded.toString('ascii'), 'hex');
|
||||
}
|
||||
throw new Error(
|
||||
`Invalid aes_key: expected 16 raw bytes or 32 hex chars, got ${decoded.length} bytes`,
|
||||
);
|
||||
}
|
||||
|
||||
function decryptAesEcb(ciphertext: Buffer, key: Buffer): Buffer {
|
||||
const decipher = createDecipheriv('aes-128-ecb', key, null);
|
||||
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ Creates a new query session with the Qwen Code.
|
|||
| `cwd` | `string` | `process.cwd()` | The working directory for the query session. Determines the context in which file operations and commands are executed. |
|
||||
| `model` | `string` | - | The AI model to use (e.g., `'qwen-max'`, `'qwen-plus'`, `'qwen-turbo'`). Takes precedence over `OPENAI_MODEL` and `QWEN_MODEL` environment variables. |
|
||||
| `pathToQwenExecutable` | `string` | Auto-detected | Path to the Qwen Code executable. Supports multiple formats: `'qwen'` (native binary from PATH), `'/path/to/qwen'` (explicit path), `'/path/to/cli.js'` (Node.js bundle), `'node:/path/to/cli.js'` (force Node.js runtime), `'bun:/path/to/cli.js'` (force Bun runtime). If not provided, auto-detects from: `QWEN_CODE_CLI_PATH` env var, `~/.volta/bin/qwen`, `~/.npm-global/bin/qwen`, `/usr/local/bin/qwen`, `~/.local/bin/qwen`, `~/node_modules/.bin/qwen`, `~/.yarn/bin/qwen`. |
|
||||
| `permissionMode` | `'default' \| 'plan' \| 'auto-edit' \| 'yolo'` | `'default'` | Permission mode controlling tool execution approval. See [Permission Modes](#permission-modes) for details. |
|
||||
| `permissionMode` | `'default' \| 'plan' \| 'auto-edit' \| 'auto' \| 'yolo'` | `'default'` | Permission mode controlling tool execution approval. See [Permission Modes](#permission-modes) for details. |
|
||||
| `canUseTool` | `CanUseTool` | - | Custom permission handler for tool execution approval. Invoked when a tool requires confirmation. Must respond within 60 seconds or the request will be auto-denied. See [Custom Permission Handler](#custom-permission-handler). |
|
||||
| `env` | `Record<string, string>` | - | Environment variables to pass to the Qwen Code process. Merged with the current process environment. |
|
||||
| `systemPrompt` | `string \| QuerySystemPromptPreset` | - | System prompt configuration for the main session. Use a string to fully override the built-in Qwen Code system prompt, or a preset object to keep the built-in prompt and append extra instructions. |
|
||||
|
|
@ -256,6 +256,7 @@ The SDK supports different permission modes for controlling tool execution:
|
|||
- **`default`**: Write tools are denied unless approved via `canUseTool` callback or in `allowedTools`. Read-only tools execute without confirmation.
|
||||
- **`plan`**: Blocks all write tools, instructing AI to present a plan first.
|
||||
- **`auto-edit`**: Auto-approve edit tools (`edit`, `write_file`, `notebook_edit`) while other tools require confirmation.
|
||||
- **`auto`**: Uses the built-in classifier to auto-approve safe tool calls and block risky ones, with manual-approval fallback after repeated policy blocks or classifier outages.
|
||||
- **`yolo`**: All tools execute automatically without confirmation.
|
||||
|
||||
### Permission Priority Chain
|
||||
|
|
@ -269,8 +270,9 @@ The first matching rule wins.
|
|||
3. `permissionMode: 'plan'` - Blocks all non-read-only tools
|
||||
4. `permissionMode: 'yolo'` - Auto-approves all tools
|
||||
5. `allowedTools` / `permissions.allow` - Auto-approves matching tools
|
||||
6. `canUseTool` callback - Custom approval logic (if provided, not called for allowed tools)
|
||||
7. Default behavior - Auto-deny in SDK mode (write tools require explicit approval)
|
||||
6. `permissionMode: 'auto'` - Classifier-mediated approval for remaining tools
|
||||
7. `canUseTool` callback - Custom approval logic (if provided, not called for allowed tools)
|
||||
8. Default behavior - Auto-deny in SDK mode (write tools require explicit approval)
|
||||
|
||||
## Examples
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue