mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-01 21:20:44 +00:00
Merge branch 'main' into feat/mcp-tui
This commit is contained in:
commit
7b227a7eb5
298 changed files with 28262 additions and 6219 deletions
10
.dockerignore
Normal file
10
.dockerignore
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Dependencies (npm ci installs fresh inside the container)
|
||||||
|
node_modules
|
||||||
|
**/node_modules
|
||||||
|
|
||||||
|
# Build artifacts (rebuilt from scratch inside the container)
|
||||||
|
dist
|
||||||
|
**/dist
|
||||||
|
|
||||||
|
# Version control
|
||||||
|
.git
|
||||||
17
.github/workflows/ci.yml
vendored
17
.github/workflows/ci.yml
vendored
|
|
@ -83,6 +83,23 @@ jobs:
|
||||||
- name: 'Run sensitive keyword linter'
|
- name: 'Run sensitive keyword linter'
|
||||||
run: 'node scripts/lint.js --sensitive-keywords'
|
run: 'node scripts/lint.js --sensitive-keywords'
|
||||||
|
|
||||||
|
- name: 'Build CLI package'
|
||||||
|
run: 'npm run build --workspace=packages/cli'
|
||||||
|
|
||||||
|
- name: 'Generate settings schema'
|
||||||
|
run: 'npm run generate:settings-schema'
|
||||||
|
|
||||||
|
- name: 'Check settings schema is up-to-date'
|
||||||
|
run: |
|
||||||
|
if [[ -n $(git status --porcelain packages/vscode-ide-companion/schemas/settings.schema.json) ]]; then
|
||||||
|
echo "❌ Error: settings.schema.json is out of date!"
|
||||||
|
echo " Please run: npm run generate:settings-schema"
|
||||||
|
echo " Then commit the updated schema file."
|
||||||
|
git diff packages/vscode-ide-companion/schemas/settings.schema.json
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "✅ Settings schema is up-to-date"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Test: Node
|
# Test: Node
|
||||||
#
|
#
|
||||||
|
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -47,6 +47,7 @@ packages/*/coverage/
|
||||||
# Generated files
|
# Generated files
|
||||||
packages/cli/src/generated/
|
packages/cli/src/generated/
|
||||||
packages/core/src/generated/
|
packages/core/src/generated/
|
||||||
|
packages/web-templates/src/generated/
|
||||||
.integration-tests/
|
.integration-tests/
|
||||||
packages/vscode-ide-companion/*.vsix
|
packages/vscode-ide-companion/*.vsix
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,5 @@ eslint.config.js
|
||||||
gha-creds-*.json
|
gha-creds-*.json
|
||||||
junit.xml
|
junit.xml
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
packages/vscode-ide-companion/schemas/settings.schema.json
|
||||||
|
packages/cli/src/services/insight/templates/insightTemplate.ts
|
||||||
|
|
|
||||||
25
.qwen/commands/qc/code-review.md
Normal file
25
.qwen/commands/qc/code-review.md
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
description: Code review a pull request
|
||||||
|
---
|
||||||
|
|
||||||
|
You are an expert code reviewer. Follow these steps:
|
||||||
|
|
||||||
|
1. If no PR number is provided in the args, use Bash(\"gh pr list\") to show open PRs
|
||||||
|
2. If a PR number is provided, use Bash(\"gh pr view <number>\") to get PR details
|
||||||
|
3. Use Bash(\"gh pr diff <number>\") to get the diff
|
||||||
|
4. Analyze the changes and provide a thorough code review that includes:
|
||||||
|
- Overview of what the PR does
|
||||||
|
- Analysis of code quality and style
|
||||||
|
- Specific suggestions for improvements
|
||||||
|
- Any potential issues or risks
|
||||||
|
|
||||||
|
Keep your review concise but thorough. Focus on:
|
||||||
|
- Code correctness
|
||||||
|
- Following project conventions
|
||||||
|
- Performance implications
|
||||||
|
- Test coverage
|
||||||
|
- Security considerations
|
||||||
|
|
||||||
|
Format your review with clear sections and bullet points.
|
||||||
|
|
||||||
|
PR number: {{args}}
|
||||||
70
.qwen/commands/qc/commit.md
Normal file
70
.qwen/commands/qc/commit.md
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
---
|
||||||
|
description: Commit staged changes with an AI-generated commit message and push
|
||||||
|
---
|
||||||
|
|
||||||
|
# Commit and Push
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
Generate a clear, concise commit message based on staged changes, confirm with the user, then commit and push.
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
|
||||||
|
### 1. Check repository status
|
||||||
|
- Run `git status` to check:
|
||||||
|
- Are there any staged changes?
|
||||||
|
- Are there unstaged changes?
|
||||||
|
- What is the current branch?
|
||||||
|
|
||||||
|
### 2. Handle unstaged changes
|
||||||
|
- If there are unstaged changes, notify the user and list them
|
||||||
|
- Do NOT add or commit unstaged changes
|
||||||
|
- Proceed only with staged changes
|
||||||
|
|
||||||
|
### 3. Review staged changes
|
||||||
|
- Run `git diff --staged` to see all staged changes
|
||||||
|
- Analyze the changes in depth to understand:
|
||||||
|
- What files were modified/added/deleted
|
||||||
|
- The nature of the changes (feature, fix, refactor, docs, etc.)
|
||||||
|
- The scope and impact of the changes
|
||||||
|
|
||||||
|
### 4. Handle branch logic
|
||||||
|
- Get current branch name with `git branch --show-current`
|
||||||
|
- **If current branch is `main` or `master`:**
|
||||||
|
- Generate a proper branch name based on the changes
|
||||||
|
- Create and switch to the new branch: `git checkout -b <branch-name>`
|
||||||
|
- **If current branch is NOT main/master:**
|
||||||
|
- Check if branch name matches the staged changes
|
||||||
|
- If branch name doesn't match changes, ask user:
|
||||||
|
- "Current branch `<branch>` doesn't seem to match these changes."
|
||||||
|
- "Options: (1) Create and switch to a new branch, (2) Commit directly on current branch"
|
||||||
|
- Wait for user decision
|
||||||
|
|
||||||
|
### 5. Generate commit message
|
||||||
|
- Types: feat, fix, docs, style, refactor, test, chore
|
||||||
|
- Guidelines:
|
||||||
|
- Be clear and concise
|
||||||
|
- Reference issues if mentioned in changes
|
||||||
|
- Include scope in parentheses when applicable (e.g., `fix(insight):`, `feat(auth):`)
|
||||||
|
- Add bullet points for detailed changes if it addes more value, otherwise do not use bullets
|
||||||
|
- Include a footer explaining the purpose/impact of the changes
|
||||||
|
|
||||||
|
**Format:**
|
||||||
|
```
|
||||||
|
<type>(<scope>): <short description>
|
||||||
|
- <detail point 1> (optional)
|
||||||
|
- <detail point 2> (optional)
|
||||||
|
- ...
|
||||||
|
|
||||||
|
This <explains the why/impact of the changes>.
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. Present the result and confirm with user
|
||||||
|
- Present the generated commit message
|
||||||
|
- Show which branch will be used
|
||||||
|
- Ask for confirmation: "Proceed with commit and push?"
|
||||||
|
- Wait for user approval
|
||||||
|
|
||||||
|
### 7. Commit and push
|
||||||
|
- After user confirms:
|
||||||
|
- `git commit -m "<commit-message>"`
|
||||||
|
- `git push -u origin <branch-name>` (use `-u` for new branches)
|
||||||
42
.qwen/commands/qc/create-issue.md
Normal file
42
.qwen/commands/qc/create-issue.md
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
---
|
||||||
|
description: Draft and submit a GitHub issue based on a user-provided idea
|
||||||
|
---
|
||||||
|
|
||||||
|
# Create Issue
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
Take the user's idea or bug description, investigate the codebase to understand the full context, draft a GitHub issue for review, and submit it once approved.
|
||||||
|
|
||||||
|
## Input
|
||||||
|
The user provides a brief description of a feature request or bug report: {{args}}
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
|
||||||
|
1. **Understand the request**
|
||||||
|
- Read the user's description carefully
|
||||||
|
- Determine whether this is a feature request or a bug report
|
||||||
|
|
||||||
|
2. **Investigate the codebase**
|
||||||
|
- Search for relevant code, files, and existing behavior related to the request
|
||||||
|
- Build a thorough understanding of how the current system works
|
||||||
|
- Identify any related issues or prior art if mentioned
|
||||||
|
|
||||||
|
3. **Draft the issue**
|
||||||
|
- Write a markdown file for the user to review
|
||||||
|
- Use the appropriate template:
|
||||||
|
- Feature request: follow @.github/ISSUE_TEMPLATE/feature_request.yml
|
||||||
|
- Bug report: follow @.github/ISSUE_TEMPLATE/bug_report.yml
|
||||||
|
- Write from the user's perspective, not as an implementation spec
|
||||||
|
- Keep the language clear and concise, AVOID internal implementation details
|
||||||
|
|
||||||
|
4. **Review with user**
|
||||||
|
- Present the draft file to the user
|
||||||
|
- Iterate on feedback until the user is satisfied
|
||||||
|
- Do NOT submit until the user explicitly asks to
|
||||||
|
|
||||||
|
5. **Submit the issue**
|
||||||
|
- When the user confirms, create the issue using `gh issue create`
|
||||||
|
- Apply the appropriate labels:
|
||||||
|
- Feature request: `type/feature-request`, `status/needs-triage`
|
||||||
|
- Bug report: `type/bug`, `status/needs-triage`
|
||||||
|
- Report back the issue URL
|
||||||
34
.qwen/commands/qc/create-pr.md
Normal file
34
.qwen/commands/qc/create-pr.md
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
---
|
||||||
|
description: Create a pull request based on staged code changes
|
||||||
|
---
|
||||||
|
|
||||||
|
# Create PR
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
Create a well-structured pull request with proper description and title.
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
1. **Review staged changes**
|
||||||
|
- Review all staged changes to understand what has been done
|
||||||
|
- Do not touch unstaged changes
|
||||||
|
|
||||||
|
2. **Prepare branch**
|
||||||
|
- Create a new branch with proper name if current branch is main
|
||||||
|
- Ensure all changes are committed
|
||||||
|
- Push branch to remote
|
||||||
|
|
||||||
|
3. **Write PR description**
|
||||||
|
- Use PR Template below
|
||||||
|
- Summarize changes clearly
|
||||||
|
- Include context and motivation
|
||||||
|
- List any breaking changes
|
||||||
|
- Link related issues if provided, or use "No linked issues"
|
||||||
|
- Add this line at the end of PR body: "🤖 Generated with [Qwen Code](https://github.com/QwenLM/qwen-code)", with a line separator
|
||||||
|
|
||||||
|
4. **Set up PR**
|
||||||
|
- Create PR title and body
|
||||||
|
- Submit PR with gh command
|
||||||
|
|
||||||
|
## PR Template
|
||||||
|
|
||||||
|
@{.github/pull_request_template.md}
|
||||||
|
|
@ -109,6 +109,38 @@ Supported key names: `ArrowUp`, `ArrowDown`, `ArrowLeft`, `ArrowRight`, `Enter`,
|
||||||
|
|
||||||
Auto-screenshot is triggered after the key sequence ends (when the next step is not a `key`).
|
Auto-screenshot is triggered after the key sequence ends (when the next step is not a `key`).
|
||||||
|
|
||||||
|
### `streaming` — Capture During Execution
|
||||||
|
|
||||||
|
Capture multiple screenshots at intervals during long-running output (e.g., progress bars). Optionally generates an animated GIF.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
{
|
||||||
|
type: 'Run this command: bash progress.sh',
|
||||||
|
streaming: {
|
||||||
|
delayMs: 7000, // Wait before first capture (skip initial waiting phase)
|
||||||
|
intervalMs: 500, // Interval between captures
|
||||||
|
count: 20, // Maximum number of captures
|
||||||
|
gif: true, // Generate animated GIF (default: true, requires ffmpeg)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- `delayMs` (optional): Milliseconds to wait after pressing Enter before starting captures. Useful for skipping model thinking/approval time.
|
||||||
|
- Captures stop early if terminal output is unchanged for 3 consecutive intervals.
|
||||||
|
- Duplicate frames (no output change) are automatically skipped.
|
||||||
|
|
||||||
|
**GIF prerequisite**: If the scenario uses `streaming` with GIF enabled (default), check if `ffmpeg` is installed before running. If not, ask the user whether they'd like to install it:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check
|
||||||
|
which ffmpeg
|
||||||
|
|
||||||
|
# Install (macOS)
|
||||||
|
brew install ffmpeg
|
||||||
|
```
|
||||||
|
|
||||||
|
If the user declines, the scenario still runs — GIF generation is skipped with a warning.
|
||||||
|
|
||||||
### `capture` / `captureFull` — Explicit Screenshot
|
### `capture` / `captureFull` — Explicit Screenshot
|
||||||
|
|
||||||
Use as a standalone step, or override automatic naming:
|
Use as a standalone step, or override automatic naming:
|
||||||
|
|
@ -178,20 +210,32 @@ This tool is commonly used for visual verification during PR reviews. For the co
|
||||||
## Full ScenarioConfig Type
|
## Full ScenarioConfig Type
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
interface ScenarioConfig {
|
interface FlowStep {
|
||||||
name: string; // Scenario name (also used as screenshot subdirectory name)
|
type?: string; // Input text
|
||||||
spawn: string[]; // Launch command ["node", "dist/cli.js", "--yolo"]
|
key?: string | string[]; // Key press(es)
|
||||||
flow: FlowStep[]; // Interaction steps
|
capture?: string; // Viewport screenshot filename
|
||||||
terminal?: {
|
captureFull?: string; // Full scrollback screenshot filename
|
||||||
// Terminal configuration (all optional)
|
streaming?: {
|
||||||
cols?: number; // Number of columns, default 100
|
delayMs?: number; // Delay before first capture (default: 0)
|
||||||
rows?: number; // Number of rows, default 28
|
intervalMs: number; // Interval between captures in ms
|
||||||
theme?: string; // Theme: dracula|one-dark|github-dark|monokai|night-owl
|
count: number; // Maximum number of captures
|
||||||
chrome?: boolean; // macOS window decorations, default true
|
gif?: boolean; // Generate animated GIF (default: true)
|
||||||
title?: string; // Window title, default "Terminal"
|
|
||||||
fontSize?: number; // Font size
|
|
||||||
cwd?: string; // Working directory (relative to config file)
|
|
||||||
};
|
};
|
||||||
outputDir?: string; // Screenshot output directory (relative to config file)
|
}
|
||||||
|
|
||||||
|
interface ScenarioConfig {
|
||||||
|
name: string; // Scenario name (also used as screenshot subdirectory name)
|
||||||
|
spawn: string[]; // Launch command ["node", "dist/cli.js", "--yolo"]
|
||||||
|
flow: FlowStep[]; // Interaction steps
|
||||||
|
terminal?: {
|
||||||
|
cols?: number; // Number of columns, default 100
|
||||||
|
rows?: number; // Number of rows, default 28
|
||||||
|
theme?: string; // Theme: dracula|one-dark|github-dark|monokai|night-owl
|
||||||
|
chrome?: boolean; // macOS window decorations, default true
|
||||||
|
title?: string; // Window title, default "Terminal"
|
||||||
|
fontSize?: number; // Font size
|
||||||
|
cwd?: string; // Working directory (relative to config file)
|
||||||
|
};
|
||||||
|
outputDir?: string; // Screenshot output directory (relative to config file)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
13
Dockerfile
13
Dockerfile
|
|
@ -19,12 +19,12 @@ ENV PATH=$PATH:/usr/local/share/npm-global/bin
|
||||||
COPY . /home/node/app
|
COPY . /home/node/app
|
||||||
WORKDIR /home/node/app
|
WORKDIR /home/node/app
|
||||||
|
|
||||||
# Install dependencies and build packages
|
# Install dependencies, build workspaces, bundle into a single distributable, and pack
|
||||||
# Use scripts/build.js which handles workspace dependencies in correct order
|
|
||||||
RUN npm ci \
|
RUN npm ci \
|
||||||
&& npm run build \
|
&& npm run build \
|
||||||
&& npm pack -w @qwen-code/qwen-code --pack-destination ./packages/cli/dist \
|
&& npm run bundle \
|
||||||
&& npm pack -w @qwen-code/qwen-code-core --pack-destination ./packages/core/dist
|
&& npm run prepare:package \
|
||||||
|
&& cd dist && npm pack
|
||||||
|
|
||||||
# Runtime stage
|
# Runtime stage
|
||||||
FROM docker.io/library/node:20-slim
|
FROM docker.io/library/node:20-slim
|
||||||
|
|
@ -61,9 +61,8 @@ RUN mkdir -p /usr/local/share/npm-global
|
||||||
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
|
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
|
||||||
ENV PATH=$PATH:/usr/local/share/npm-global/bin
|
ENV PATH=$PATH:/usr/local/share/npm-global/bin
|
||||||
|
|
||||||
# Copy built packages from builder stage
|
# Copy bundled package from builder stage
|
||||||
COPY --from=builder /home/node/app/packages/cli/dist/*.tgz /tmp/
|
COPY --from=builder /home/node/app/dist/*.tgz /tmp/
|
||||||
COPY --from=builder /home/node/app/packages/core/dist/*.tgz /tmp/
|
|
||||||
|
|
||||||
# Install built packages globally
|
# Install built packages globally
|
||||||
RUN npm install -g /tmp/*.tgz \
|
RUN npm install -g /tmp/*.tgz \
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
| Feature | Version | Description | Category | Phase |
|
| Feature | Version | Description | Category | Phase |
|
||||||
| ----------------------- | --------- | ------------------------------------------------------- | ------------------------------- | ----- |
|
| ----------------------- | --------- | ------------------------------------------------------- | ------------------------------- | ----- |
|
||||||
| **Coding Plan** | `V0.10.0` | Bailian Coding Plan authentication & models | User Experience | 2 |
|
| **Coding Plan** | `V0.10.0` | Alibaba Cloud Coding Plan authentication & models | User Experience | 2 |
|
||||||
| Unified WebUI | `V0.9.0` | Shared WebUI component library for VSCode/CLI | User Experience | 2 |
|
| Unified WebUI | `V0.9.0` | Shared WebUI component library for VSCode/CLI | User Experience | 2 |
|
||||||
| Export Chat | `V0.8.0` | Export sessions to Markdown/HTML/JSON/JSONL | User Experience | 2 |
|
| Export Chat | `V0.8.0` | Export sessions to Markdown/HTML/JSON/JSONL | User Experience | 2 |
|
||||||
| Extension System | `V0.8.0` | Full extension management with slash commands | Building Open Capabilities | 2 |
|
| Extension System | `V0.8.0` | Full extension management with slash commands | Building Open Capabilities | 2 |
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ ls -la $(dirname $(which qwen))/../lib/node_modules/@qwen-code/qwen-code
|
||||||
# 7.Test the version of qwen
|
# 7.Test the version of qwen
|
||||||
qwen -v
|
qwen -v
|
||||||
# npm link will overwrite the global qwen. To avoid being unable to distinguish the same version number, you can uninstall the global CLI first
|
# npm link will overwrite the global qwen. To avoid being unable to distinguish the same version number, you can uninstall the global CLI first
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 3、Create your sandbox Dockerfile under the root directory of your own project
|
#### 3、Create your sandbox Dockerfile under the root directory of your own project
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
# Authentication
|
# Authentication
|
||||||
|
|
||||||
Qwen Code supports two authentication methods. Pick the one that matches how you want to run the CLI:
|
Qwen Code supports three authentication methods. Pick the one that matches how you want to run the CLI:
|
||||||
|
|
||||||
- **Qwen OAuth (recommended)**: sign in with your `qwen.ai` account in a browser.
|
- **Qwen OAuth**: sign in with your `qwen.ai` account in a browser. Free with a daily quota.
|
||||||
- **API-KEY**: use an API key to connect to any supported provider. More flexible — supports OpenAI, Anthropic, Google GenAI, Alibaba Cloud Bailian, and other compatible endpoints.
|
- **Alibaba Cloud Coding Plan**: use an API key from Alibaba Cloud. Paid subscription with diverse model options and higher quotas.
|
||||||
|
- **API Key**: bring your own API key. Flexible to your own needs — supports OpenAI, Anthropic, Gemini, and other compatible endpoints.
|
||||||
|
|
||||||

|
## Option 1: Qwen OAuth (Free)
|
||||||
|
|
||||||
## 👍 Option 1: Qwen OAuth (recommended & free)
|
|
||||||
|
|
||||||
Use this if you want the simplest setup and you're using Qwen models.
|
Use this if you want the simplest setup and you're using Qwen models.
|
||||||
|
|
||||||
|
|
@ -25,15 +24,72 @@ qwen
|
||||||
> [!note]
|
> [!note]
|
||||||
>
|
>
|
||||||
> In non-interactive or headless environments (e.g., CI, SSH, containers), you typically **cannot** complete the OAuth browser login flow.
|
> In non-interactive or headless environments (e.g., CI, SSH, containers), you typically **cannot** complete the OAuth browser login flow.
|
||||||
> In these cases, please use the API-KEY authentication method.
|
> In these cases, please use the Alibaba Cloud Coding Plan or API Key authentication method.
|
||||||
|
|
||||||
## 🚀 Option 2: API-KEY (flexible)
|
## 💳 Option 2: Alibaba Cloud Coding Plan
|
||||||
|
|
||||||
Use this if you want more flexibility over which provider and model to use. Supports multiple protocols and providers, including OpenAI, Anthropic, Google GenAI, Alibaba Cloud Bailian, Azure OpenAI, OpenRouter, ModelScope, or a self-hosted compatible endpoint.
|
Use this if you want predictable costs with diverse model options and higher usage quotas.
|
||||||
|
|
||||||
|
- **How it works**: Subscribe to the Coding Plan with a fixed monthly fee, then configure Qwen Code to use the dedicated endpoint and your subscription API key.
|
||||||
|
- **Requirements**: Obtain an active Coding Plan subscription from [Aliyun Bailian](https://bailian.console.aliyun.com/?tab=model#/efm/coding_plan) or [Alibaba Cloud](https://bailian.console.alibabacloud.com/?tab=model#/efm/coding_plan), depending on the region of your account.
|
||||||
|
- **Benefits**: Diverse model options, higher usage quotas, predictable monthly costs, access to a wide range of models (Qwen, GLM, Kimi, Minimax and more).
|
||||||
|
- **Cost & quota**: View [Aliyun Bailian Coding Plan documentation](https://bailian.console.aliyun.com/cn-beijing/?tab=doc#/doc/?type=model&url=3005961).
|
||||||
|
|
||||||
|
Alibaba Cloud Coding Plan is available in two regions:
|
||||||
|
|
||||||
|
| Region | Console URL |
|
||||||
|
| -------------------------------- | ---------------------------------------------------------------------------- |
|
||||||
|
| Aliyun Bailian (aliyun.com) | [bailian.console.aliyun.com](https://bailian.console.aliyun.com) |
|
||||||
|
| Alibaba Cloud (alibabacloud.com) | [bailian.console.alibabacloud.com](https://bailian.console.alibabacloud.com) |
|
||||||
|
|
||||||
|
### Interactive setup
|
||||||
|
|
||||||
|
Enter `qwen` in the terminal to launch Qwen Code, then run the `/auth` command and select **Alibaba Cloud Coding Plan**. Choose your region, then enter your `sk-sp-xxxxxxxxx` key.
|
||||||
|
|
||||||
|
After authentication, use the `/model` command to switch between all Alibaba Cloud Coding Plan supported models (including qwen3.5-plus, qwen3-coder-plus, qwen3-coder-next, qwen3-max, glm-4.7, and kimi-k2.5).
|
||||||
|
|
||||||
|
### Alternative: configure via `settings.json`
|
||||||
|
|
||||||
|
If you prefer to skip the interactive `/auth` flow, add the following to `~/.qwen/settings.json`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"modelProviders": {
|
||||||
|
"openai": [
|
||||||
|
{
|
||||||
|
"id": "qwen3-coder-plus",
|
||||||
|
"name": "qwen3-coder-plus (Coding Plan)",
|
||||||
|
"baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
|
||||||
|
"description": "qwen3-coder-plus from Alibaba Cloud Coding Plan",
|
||||||
|
"envKey": "BAILIAN_CODING_PLAN_API_KEY"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"BAILIAN_CODING_PLAN_API_KEY": "sk-sp-xxxxxxxxx"
|
||||||
|
},
|
||||||
|
"security": {
|
||||||
|
"auth": {
|
||||||
|
"selectedType": "openai"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"name": "qwen3-coder-plus"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!note]
|
||||||
|
>
|
||||||
|
> The Coding Plan uses a dedicated endpoint (`https://coding.dashscope.aliyuncs.com/v1`) that is different from the standard Dashscope endpoint. Make sure to use the correct `baseUrl`.
|
||||||
|
|
||||||
|
## 🚀 Option 3: API Key (flexible)
|
||||||
|
|
||||||
|
Use this if you want to connect to third-party providers such as OpenAI, Anthropic, Google, Azure OpenAI, OpenRouter, ModelScope, or a self-hosted endpoint. Supports multiple protocols and providers.
|
||||||
|
|
||||||
### Recommended: One-file setup via `settings.json`
|
### Recommended: One-file setup via `settings.json`
|
||||||
|
|
||||||
The simplest way to get started with API-KEY authentication is to put everything in a single `~/.qwen/settings.json` file. Here's a complete, ready-to-use example:
|
The simplest way to get started with API Key authentication is to put everything in a single `~/.qwen/settings.json` file. Here's a complete, ready-to-use example:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|
@ -66,7 +122,7 @@ What each field does:
|
||||||
|
|
||||||
| Field | Description |
|
| Field | Description |
|
||||||
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `modelProviders` | Declares which models are available and how to connect to them. Keys (`openai`, `anthropic`, `gemini`, `vertex-ai`) represent the API protocol. |
|
| `modelProviders` | Declares which models are available and how to connect to them. Keys (`openai`, `anthropic`, `gemini`) represent the API protocol. |
|
||||||
| `env` | Stores API keys directly in `settings.json` as a fallback (lowest priority — shell `export` and `.env` files take precedence). |
|
| `env` | Stores API keys directly in `settings.json` as a fallback (lowest priority — shell `export` and `.env` files take precedence). |
|
||||||
| `security.auth.selectedType` | Tells Qwen Code which protocol to use on startup (e.g. `openai`, `anthropic`, `gemini`). Without this, you'd need to run `/auth` interactively. |
|
| `security.auth.selectedType` | Tells Qwen Code which protocol to use on startup (e.g. `openai`, `anthropic`, `gemini`). Without this, you'd need to run `/auth` interactively. |
|
||||||
| `model.name` | The default model to activate when Qwen Code starts. Must match one of the `id` values in your `modelProviders`. |
|
| `model.name` | The default model to activate when Qwen Code starts. Must match one of the `id` values in your `modelProviders`. |
|
||||||
|
|
@ -77,76 +133,15 @@ After saving the file, just run `qwen` — no interactive `/auth` setup needed.
|
||||||
>
|
>
|
||||||
> The sections below explain each part in more detail. If the quick example above works for you, feel free to skip ahead to [Security notes](#security-notes).
|
> The sections below explain each part in more detail. If the quick example above works for you, feel free to skip ahead to [Security notes](#security-notes).
|
||||||
|
|
||||||
### Option1: Coding Plan(Aliyun Bailian)
|
|
||||||
|
|
||||||
Use this if you want predictable costs with higher usage quotas for the qwen3-coder-plus model.
|
|
||||||
|
|
||||||
- **How it works**: Subscribe to the Coding Plan with a fixed monthly fee, then configure Qwen Code to use the dedicated endpoint and your subscription API key.
|
|
||||||
- **Requirements**: Obtain an active Coding Plan subscription from [Alibaba Cloud Bailian](https://bailian.console.aliyun.com/cn-beijing/?tab=globalset#/efm/coding_plan).
|
|
||||||
- **Benefits**: Higher usage quotas, predictable monthly costs, access to the latest qwen3-coder-plus model.
|
|
||||||
- **Cost & quota**: View [Alibaba Cloud Bailian Coding Plan documentation](https://bailian.console.aliyun.com/cn-beijing/?tab=doc#/doc/?type=model&url=3005961).
|
|
||||||
|
|
||||||
Enter `qwen` in the terminal to launch Qwen Code, then enter the `/auth` command and select `API-KEY`
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
After entering, select `Coding Plan`:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Enter your `sk-sp-xxxxxxxxx` key, then use the `/model` command to switch between all Bailian `Coding Plan` supported models (including qwen3.5-plus, qwen3-coder-plus, qwen3-coder-next, qwen3-max, glm-4.7, and kimi-k2.5):
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
**Alternative: configure Coding Plan via `settings.json`**
|
|
||||||
|
|
||||||
If you prefer to skip the interactive `/auth` flow, add the following to `~/.qwen/settings.json`:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"modelProviders": {
|
|
||||||
"openai": [
|
|
||||||
{
|
|
||||||
"id": "qwen3-coder-plus",
|
|
||||||
"name": "qwen3-coder-plus (Coding Plan)",
|
|
||||||
"baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
|
|
||||||
"description": "qwen3-coder-plus from Bailian Coding Plan",
|
|
||||||
"envKey": "BAILIAN_CODING_PLAN_API_KEY"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"env": {
|
|
||||||
"BAILIAN_CODING_PLAN_API_KEY": "sk-sp-xxxxxxxxx"
|
|
||||||
},
|
|
||||||
"security": {
|
|
||||||
"auth": {
|
|
||||||
"selectedType": "openai"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"model": {
|
|
||||||
"name": "qwen3-coder-plus"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
> [!note]
|
|
||||||
>
|
|
||||||
> The Coding Plan uses a dedicated endpoint (`https://coding.dashscope.aliyuncs.com/v1`) that is different from the standard Dashscope endpoint. Make sure to use the correct `baseUrl`.
|
|
||||||
|
|
||||||
### Option2: Third-party API-KEY
|
|
||||||
|
|
||||||
Use this if you want to connect to third-party providers such as OpenAI, Anthropic, Google, Azure OpenAI, OpenRouter, ModelScope, or a self-hosted endpoint.
|
|
||||||
|
|
||||||
The key concept is **Model Providers** (`modelProviders`): Qwen Code supports multiple API protocols, not just OpenAI. You configure which providers and models are available by editing `~/.qwen/settings.json`, then switch between them at runtime with the `/model` command.
|
The key concept is **Model Providers** (`modelProviders`): Qwen Code supports multiple API protocols, not just OpenAI. You configure which providers and models are available by editing `~/.qwen/settings.json`, then switch between them at runtime with the `/model` command.
|
||||||
|
|
||||||
#### Supported protocols
|
#### Supported protocols
|
||||||
|
|
||||||
| Protocol | `modelProviders` key | Environment variables | Providers |
|
| Protocol | `modelProviders` key | Environment variables | Providers |
|
||||||
| ----------------- | -------------------- | ------------------------------------------------------------ | --------------------------------------------------------------------------------------------------- |
|
| ----------------- | -------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------- |
|
||||||
| OpenAI-compatible | `openai` | `OPENAI_API_KEY`, `OPENAI_BASE_URL`, `OPENAI_MODEL` | OpenAI, Azure OpenAI, OpenRouter, ModelScope, Alibaba Cloud Bailian, any OpenAI-compatible endpoint |
|
| OpenAI-compatible | `openai` | `OPENAI_API_KEY`, `OPENAI_BASE_URL`, `OPENAI_MODEL` | OpenAI, Azure OpenAI, OpenRouter, ModelScope, Alibaba Cloud, any OpenAI-compatible endpoint |
|
||||||
| Anthropic | `anthropic` | `ANTHROPIC_API_KEY`, `ANTHROPIC_BASE_URL`, `ANTHROPIC_MODEL` | Anthropic Claude |
|
| Anthropic | `anthropic` | `ANTHROPIC_API_KEY`, `ANTHROPIC_BASE_URL`, `ANTHROPIC_MODEL` | Anthropic Claude |
|
||||||
| Google GenAI | `gemini` | `GEMINI_API_KEY`, `GEMINI_MODEL` | Google Gemini |
|
| Google GenAI | `gemini` | `GEMINI_API_KEY`, `GEMINI_MODEL` | Google Gemini |
|
||||||
| Google Vertex AI | `vertex-ai` | `GOOGLE_API_KEY`, `GOOGLE_MODEL` | Google Vertex AI |
|
|
||||||
|
|
||||||
#### Step 1: Configure models and providers in `~/.qwen/settings.json`
|
#### Step 1: Configure models and providers in `~/.qwen/settings.json`
|
||||||
|
|
||||||
|
|
@ -266,12 +261,12 @@ This is the approach used in the [one-file setup example](#recommended-one-file-
|
||||||
|
|
||||||
**Priority summary:**
|
**Priority summary:**
|
||||||
|
|
||||||
| Priority | Source | Override behavior |
|
| Priority | Source | Override behavior |
|
||||||
| ----------- | ------------------------------ | ---------------------------------------- |
|
| ----------- | ------------------------------ | -------------------------------------------- |
|
||||||
| 1 (highest) | CLI flags (`--openai-api-key`) | Always wins |
|
| 1 (highest) | CLI flags (`--openai-api-key`) | Always wins |
|
||||||
| 2 | System env (`export`, inline) | Overrides `.env` and `settings.env` |
|
| 2 | System env (`export`, inline) | Overrides `.env` and `settings.json` → `env` |
|
||||||
| 3 | `.env` file | Only sets if not in system env |
|
| 3 | `.env` file | Only sets if not in system env |
|
||||||
| 4 (lowest) | `settings.json` → `env` | Only sets if not in system env or `.env` |
|
| 4 (lowest) | `settings.json` → `env` | Only sets if not in system env or `.env` |
|
||||||
|
|
||||||
#### Step 3: Switch models with `/model`
|
#### Step 3: Switch models with `/model`
|
||||||
|
|
||||||
|
|
@ -292,11 +287,11 @@ qwen --model "qwen3-coder-plus"
|
||||||
|
|
||||||
# In another terminal
|
# In another terminal
|
||||||
|
|
||||||
qwen --model "qwen3-coder-next"
|
qwen --model "qwen3.5-plus"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Security notes
|
## Security notes
|
||||||
|
|
||||||
- Don’t commit API keys to version control.
|
- Don't commit API keys to version control.
|
||||||
- Prefer `.qwen/.env` for project-local secrets (and keep it out of git).
|
- Prefer `.qwen/.env` for project-local secrets (and keep it out of git).
|
||||||
- Treat your terminal output as sensitive if it prints credentials for verification.
|
- Treat your terminal output as sensitive if it prints credentials for verification.
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,14 @@ Qwen Code allows you to configure multiple model providers through the `modelPro
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
Use `modelProviders` to declare curated model lists per auth type that the `/model` picker can switch between. Keys must be valid auth types (`openai`, `anthropic`, `gemini`, `vertex-ai`, etc.). Each entry requires an `id` and **must include `envKey`**, with optional `name`, `description`, `baseUrl`, and `generationConfig`. Credentials are never persisted in settings; the runtime reads them from `process.env[envKey]`. Qwen OAuth models remain hard-coded and cannot be overridden.
|
Use `modelProviders` to declare curated model lists per auth type that the `/model` picker can switch between. Keys must be valid auth types (`openai`, `anthropic`, `gemini`, etc.). Each entry requires an `id` and **must include `envKey`**, with optional `name`, `description`, `baseUrl`, and `generationConfig`. Credentials are never persisted in settings; the runtime reads them from `process.env[envKey]`. Qwen OAuth models remain hard-coded and cannot be overridden.
|
||||||
|
|
||||||
> [!note]
|
> [!note]
|
||||||
> Only the `/model` command exposes non-default auth types. Anthropic, Gemini, Vertex AI, etc., must be defined via `modelProviders`. The `/auth` command intentionally lists only the built-in Qwen OAuth and OpenAI flows.
|
>
|
||||||
|
> Only the `/model` command exposes non-default auth types. Anthropic, Gemini, etc., must be defined via `modelProviders`. The `/auth` command lists Qwen OAuth, Alibaba Cloud Coding Plan, and API Key as the built-in authentication options.
|
||||||
|
|
||||||
> [!warning]
|
> [!warning]
|
||||||
|
>
|
||||||
> **Duplicate model IDs within the same authType:** Defining multiple models with the same `id` under a single `authType` (e.g., two entries with `"id": "gpt-4o"` in `openai`) is currently not supported. If duplicates exist, **the first occurrence wins** and subsequent duplicates are skipped with a warning. Note that the `id` field is used both as the configuration identifier and as the actual model name sent to the API, so using unique IDs (e.g., `gpt-4o-creative`, `gpt-4o-balanced`) is not a viable workaround. This is a known limitation that we plan to address in a future release.
|
> **Duplicate model IDs within the same authType:** Defining multiple models with the same `id` under a single `authType` (e.g., two entries with `"id": "gpt-4o"` in `openai`) is currently not supported. If duplicates exist, **the first occurrence wins** and subsequent duplicates are skipped with a warning. Note that the `id` field is used both as the configuration identifier and as the actual model name sent to the API, so using unique IDs (e.g., `gpt-4o-creative`, `gpt-4o-balanced`) is not a viable workaround. This is a known limitation that we plan to address in a future release.
|
||||||
|
|
||||||
## Configuration Examples by Auth Type
|
## Configuration Examples by Auth Type
|
||||||
|
|
@ -25,7 +27,6 @@ The `modelProviders` object keys must be valid `authType` values. Currently supp
|
||||||
| `openai` | OpenAI-compatible APIs (OpenAI, Azure OpenAI, local inference servers like vLLM/Ollama) |
|
| `openai` | OpenAI-compatible APIs (OpenAI, Azure OpenAI, local inference servers like vLLM/Ollama) |
|
||||||
| `anthropic` | Anthropic Claude API |
|
| `anthropic` | Anthropic Claude API |
|
||||||
| `gemini` | Google Gemini API |
|
| `gemini` | Google Gemini API |
|
||||||
| `vertex-ai` | Google Vertex AI |
|
|
||||||
| `qwen-oauth` | Qwen OAuth (hard-coded, cannot be overridden in `modelProviders`) |
|
| `qwen-oauth` | Qwen OAuth (hard-coded, cannot be overridden in `modelProviders`) |
|
||||||
|
|
||||||
> [!warning]
|
> [!warning]
|
||||||
|
|
@ -35,12 +36,12 @@ The `modelProviders` object keys must be valid `authType` values. Currently supp
|
||||||
|
|
||||||
Qwen Code uses the following official SDKs to send requests to each provider:
|
Qwen Code uses the following official SDKs to send requests to each provider:
|
||||||
|
|
||||||
| Auth Type | SDK Package |
|
| Auth Type | SDK Package |
|
||||||
| ---------------------- | ----------------------------------------------------------------------------------------------- |
|
| ------------ | ----------------------------------------------------------------------------------------------- |
|
||||||
| `openai` | [`openai`](https://www.npmjs.com/package/openai) - Official OpenAI Node.js SDK |
|
| `openai` | [`openai`](https://www.npmjs.com/package/openai) - Official OpenAI Node.js SDK |
|
||||||
| `anthropic` | [`@anthropic-ai/sdk`](https://www.npmjs.com/package/@anthropic-ai/sdk) - Official Anthropic SDK |
|
| `anthropic` | [`@anthropic-ai/sdk`](https://www.npmjs.com/package/@anthropic-ai/sdk) - Official Anthropic SDK |
|
||||||
| `gemini` / `vertex-ai` | [`@google/genai`](https://www.npmjs.com/package/@google/genai) - Official Google GenAI SDK |
|
| `gemini` | [`@google/genai`](https://www.npmjs.com/package/@google/genai) - Official Google GenAI SDK |
|
||||||
| `qwen-oauth` | [`openai`](https://www.npmjs.com/package/openai) with custom provider (DashScope-compatible) |
|
| `qwen-oauth` | [`openai`](https://www.npmjs.com/package/openai) with custom provider (DashScope-compatible) |
|
||||||
|
|
||||||
This means the `baseUrl` you configure should be compatible with the corresponding SDK's expected API format. For example, when using `openai` auth type, the endpoint must accept OpenAI API format requests.
|
This means the `baseUrl` you configure should be compatible with the corresponding SDK's expected API format. For example, when using `openai` auth type, the endpoint must accept OpenAI API format requests.
|
||||||
|
|
||||||
|
|
@ -62,6 +63,9 @@ This auth type supports not only OpenAI's official API but also any OpenAI-compa
|
||||||
"maxRetries": 3,
|
"maxRetries": 3,
|
||||||
"enableCacheControl": true,
|
"enableCacheControl": true,
|
||||||
"contextWindowSize": 128000,
|
"contextWindowSize": 128000,
|
||||||
|
"modalities": {
|
||||||
|
"image": true
|
||||||
|
},
|
||||||
"customHeaders": {
|
"customHeaders": {
|
||||||
"X-Client-Request-ID": "req-123"
|
"X-Client-Request-ID": "req-123"
|
||||||
},
|
},
|
||||||
|
|
@ -181,31 +185,6 @@ This auth type supports not only OpenAI's official API but also any OpenAI-compa
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Google Vertex AI (`vertex-ai`)
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"modelProviders": {
|
|
||||||
"vertex-ai": [
|
|
||||||
{
|
|
||||||
"id": "gemini-1.5-pro-vertex",
|
|
||||||
"name": "Gemini 1.5 Pro (Vertex AI)",
|
|
||||||
"envKey": "GOOGLE_API_KEY",
|
|
||||||
"baseUrl": "https://generativelanguage.googleapis.com",
|
|
||||||
"generationConfig": {
|
|
||||||
"timeout": 90000,
|
|
||||||
"contextWindowSize": 2000000,
|
|
||||||
"samplingParams": {
|
|
||||||
"temperature": 0.2,
|
|
||||||
"max_tokens": 8192
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Local Self-Hosted Models (via OpenAI-compatible API)
|
### Local Self-Hosted Models (via OpenAI-compatible API)
|
||||||
|
|
||||||
Most local inference servers (vLLM, Ollama, LM Studio, etc.) provide an OpenAI-compatible API endpoint. Configure them using the `openai` auth type with a local `baseUrl`:
|
Most local inference servers (vLLM, Ollama, LM Studio, etc.) provide an OpenAI-compatible API endpoint. Configure them using the `openai` auth type with a local `baseUrl`:
|
||||||
|
|
@ -273,15 +252,16 @@ export VLLM_API_KEY="not-needed"
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!note]
|
> [!note]
|
||||||
> The `extra_body` parameter is **only supported for OpenAI-compatible providers** (`openai`, `qwen-oauth`). It is ignored for Anthropic, Gemini, and Vertex AI providers.
|
>
|
||||||
|
> The `extra_body` parameter is **only supported for OpenAI-compatible providers** (`openai`, `qwen-oauth`). It is ignored for Anthropic, and Gemini providers.
|
||||||
|
|
||||||
## Bailian Coding Plan
|
## Alibaba Cloud Coding Plan
|
||||||
|
|
||||||
Bailian Coding Plan provides a pre-configured set of Qwen models optimized for coding tasks. This feature is available for users with Bailian API access and offers a simplified setup experience with automatic model configuration updates.
|
Alibaba Cloud Coding Plan provides a pre-configured set of Qwen models optimized for coding tasks. This feature is available for users with Alibaba Cloud Coding Plan API access and offers a simplified setup experience with automatic model configuration updates.
|
||||||
|
|
||||||
### Overview
|
### Overview
|
||||||
|
|
||||||
When you authenticate with a Bailian Coding Plan API key using the `/auth` command, Qwen Code automatically configures the following models:
|
When you authenticate with an Alibaba Cloud Coding Plan API key using the `/auth` command, Qwen Code automatically configures the following models:
|
||||||
|
|
||||||
| Model ID | Name | Description |
|
| Model ID | Name | Description |
|
||||||
| ---------------------- | -------------------- | -------------------------------------- |
|
| ---------------------- | -------------------- | -------------------------------------- |
|
||||||
|
|
@ -291,19 +271,19 @@ When you authenticate with a Bailian Coding Plan API key using the `/auth` comma
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
1. Obtain a Bailian Coding Plan API key:
|
1. Obtain an Alibaba Cloud Coding Plan API key:
|
||||||
- **China**: <https://bailian.console.aliyun.com/?tab=model#/efm/coding_plan>
|
- **China**: <https://bailian.console.aliyun.com/?tab=model#/efm/coding_plan>
|
||||||
- **International**: <https://modelstudio.console.alibabacloud.com/?tab=dashboard#/efm/coding_plan>
|
- **International**: <https://modelstudio.console.alibabacloud.com/?tab=dashboard#/efm/coding_plan>
|
||||||
2. Run the `/auth` command in Qwen Code
|
2. Run the `/auth` command in Qwen Code
|
||||||
3. Select the API-KEY authentication method
|
3. Select **Alibaba Cloud Coding Plan**
|
||||||
4. Select your region (China or Global/International)
|
4. Select your region
|
||||||
5. Enter your API key when prompted
|
5. Enter your API key when prompted
|
||||||
|
|
||||||
The models will be automatically configured and added to your `/model` picker.
|
The models will be automatically configured and added to your `/model` picker.
|
||||||
|
|
||||||
### Regions
|
### Regions
|
||||||
|
|
||||||
Bailian Coding Plan supports two regions:
|
Alibaba Cloud Coding Plan supports two regions:
|
||||||
|
|
||||||
| Region | Endpoint | Description |
|
| Region | Endpoint | Description |
|
||||||
| -------------------- | ----------------------------------------------- | ----------------------- |
|
| -------------------- | ----------------------------------------------- | ----------------------- |
|
||||||
|
|
@ -314,9 +294,10 @@ The region is selected during authentication and stored in `settings.json` under
|
||||||
|
|
||||||
### API Key Storage
|
### API Key Storage
|
||||||
|
|
||||||
When you configure Coding Plan through the `/auth` command, the API key is stored using the reserved environment variable name `BAILIAN_CODING_PLAN_API_KEY`. By default, it is stored in the `settings.env` field of your `settings.json` file.
|
When you configure Coding Plan through the `/auth` command, the API key is stored using the reserved environment variable name `BAILIAN_CODING_PLAN_API_KEY`. By default, it is stored in the `env` field of your `settings.json` file.
|
||||||
|
|
||||||
> [!warning]
|
> [!warning]
|
||||||
|
>
|
||||||
> **Security Recommendation**: For better security, it is recommended to move the API key from `settings.json` to a separate `.env` file and load it as an environment variable. For example:
|
> **Security Recommendation**: For better security, it is recommended to move the API key from `settings.json` to a separate `.env` file and load it as an environment variable. For example:
|
||||||
>
|
>
|
||||||
> ```bash
|
> ```bash
|
||||||
|
|
@ -347,7 +328,7 @@ If you prefer to manually configure Coding Plan models, you can add them to your
|
||||||
{
|
{
|
||||||
"id": "qwen3-coder-plus",
|
"id": "qwen3-coder-plus",
|
||||||
"name": "qwen3-coder-plus",
|
"name": "qwen3-coder-plus",
|
||||||
"description": "Qwen3-Coder via Bailian Coding Plan",
|
"description": "Qwen3-Coder via Alibaba Cloud Coding Plan",
|
||||||
"envKey": "YOUR_CUSTOM_ENV_KEY",
|
"envKey": "YOUR_CUSTOM_ENV_KEY",
|
||||||
"baseUrl": "https://coding.dashscope.aliyuncs.com/v1"
|
"baseUrl": "https://coding.dashscope.aliyuncs.com/v1"
|
||||||
}
|
}
|
||||||
|
|
@ -357,13 +338,15 @@ If you prefer to manually configure Coding Plan models, you can add them to your
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!note]
|
> [!note]
|
||||||
|
>
|
||||||
> When using manual configuration:
|
> When using manual configuration:
|
||||||
|
>
|
||||||
> - You can use any environment variable name for `envKey`
|
> - You can use any environment variable name for `envKey`
|
||||||
> - You do not need to configure `codingPlan.*`
|
> - You do not need to configure `codingPlan.*`
|
||||||
> - **Automatic updates will not apply** to manually configured Coding Plan models
|
> - **Automatic updates will not apply** to manually configured Coding Plan models
|
||||||
|
|
||||||
> [!warning]
|
> [!warning]
|
||||||
|
>
|
||||||
> If you also use automatic Coding Plan configuration, automatic updates may overwrite your manual configurations if they use the same `envKey` and `baseUrl` as the automatic configuration. To avoid this, ensure your manual configuration uses a different `envKey` if possible.
|
> If you also use automatic Coding Plan configuration, automatic updates may overwrite your manual configurations if they use the same `envKey` and `baseUrl` as the automatic configuration. To avoid this, ensure your manual configuration uses a different `envKey` if possible.
|
||||||
|
|
||||||
## Resolution Layers and Atomicity
|
## Resolution Layers and Atomicity
|
||||||
|
|
@ -382,6 +365,7 @@ The effective auth/model/credential values are chosen per field using the follow
|
||||||
\*When present, CLI auth flags override settings. Otherwise, `security.auth.selectedType` or the implicit default determine the auth type. Qwen OAuth and OpenAI are the only auth types surfaced without extra configuration.
|
\*When present, CLI auth flags override settings. Otherwise, `security.auth.selectedType` or the implicit default determine the auth type. Qwen OAuth and OpenAI are the only auth types surfaced without extra configuration.
|
||||||
|
|
||||||
> [!warning]
|
> [!warning]
|
||||||
|
>
|
||||||
> **Deprecation of `security.auth.apiKey` and `security.auth.baseUrl`:** Directly configuring API credentials via `security.auth.apiKey` and `security.auth.baseUrl` in `settings.json` is deprecated. These settings were used in historical versions for credentials entered through the UI, but the credential input flow was removed in version 0.10.1. These fields will be fully removed in a future release. **It is strongly recommended to migrate to `modelProviders`** for all model and credential configurations. Use `envKey` in `modelProviders` to reference environment variables for secure credential management instead of hardcoding credentials in settings files.
|
> **Deprecation of `security.auth.apiKey` and `security.auth.baseUrl`:** Directly configuring API credentials via `security.auth.apiKey` and `security.auth.baseUrl` in `settings.json` is deprecated. These settings were used in historical versions for credentials entered through the UI, but the credential input flow was removed in version 0.10.1. These fields will be fully removed in a future release. **It is strongly recommended to migrate to `modelProviders`** for all model and credential configurations. Use `envKey` in `modelProviders` to reference environment variables for secure credential management instead of hardcoding credentials in settings files.
|
||||||
|
|
||||||
## Generation Config Layering: The Impermeable Provider Layer
|
## Generation Config Layering: The Impermeable Provider Layer
|
||||||
|
|
@ -515,6 +499,7 @@ The snapshot:
|
||||||
## Selection Persistence and Recommendations
|
## Selection Persistence and Recommendations
|
||||||
|
|
||||||
> [!important]
|
> [!important]
|
||||||
|
>
|
||||||
> Define `modelProviders` in the user-scope `~/.qwen/settings.json` whenever possible and avoid persisting credential overrides in any scope. Keeping the provider catalog in user settings prevents merge/override conflicts between project and user scopes and ensures `/auth` and `/model` updates always write back to a consistent scope.
|
> Define `modelProviders` in the user-scope `~/.qwen/settings.json` whenever possible and avoid persisting credential overrides in any scope. Keeping the provider catalog in user settings prevents merge/override conflicts between project and user scopes and ensures `/auth` and `/model` updates always write back to a consistent scope.
|
||||||
|
|
||||||
- `/model` and `/auth` persist `model.name` (where applicable) and `security.auth.selectedType` to the closest writable scope that already defines `modelProviders`; otherwise they fall back to the user scope. This keeps workspace/user files in sync with the active provider catalog.
|
- `/model` and `/auth` persist `model.name` (where applicable) and `security.auth.selectedType` to the closest writable scope that already defines `modelProviders`; otherwise they fall back to the user scope. This keeps workspace/user files in sync with the active provider catalog.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
> [!tip]
|
> [!tip]
|
||||||
>
|
>
|
||||||
> **Authentication / API keys:** Authentication (Qwen OAuth vs OpenAI-compatible API) and auth-related environment variables (like `OPENAI_API_KEY`) are documented in **[Authentication](../configuration/auth)**.
|
> **Authentication / API keys:** Authentication (Qwen OAuth, Alibaba Cloud Coding Plan, or API Key) and auth-related environment variables (like `OPENAI_API_KEY`) are documented in **[Authentication](../configuration/auth)**.
|
||||||
|
|
||||||
> [!note]
|
> [!note]
|
||||||
>
|
>
|
||||||
|
|
@ -125,18 +125,18 @@ Settings are organized into categories. All settings should be placed within the
|
||||||
|
|
||||||
#### model
|
#### model
|
||||||
|
|
||||||
| Setting | Type | Description | Default |
|
| Setting | Type | Description | Default |
|
||||||
| -------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- |
|
| -------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
|
||||||
| `model.name` | string | The Qwen model to use for conversations. | `undefined` |
|
| `model.name` | string | The Qwen model to use for conversations. | `undefined` |
|
||||||
| `model.maxSessionTurns` | number | Maximum number of user/model/tool turns to keep in a session. -1 means unlimited. | `-1` |
|
| `model.maxSessionTurns` | number | Maximum number of user/model/tool turns to keep in a session. -1 means unlimited. | `-1` |
|
||||||
| `model.summarizeToolOutput` | object | Enables or disables the summarization of tool output. You can specify the token budget for the summarization using the `tokenBudget` setting. Note: Currently only the `run_shell_command` tool is supported. For example `{"run_shell_command": {"tokenBudget": 2000}}` | `undefined` |
|
| `model.summarizeToolOutput` | object | Enables or disables the summarization of tool output. You can specify the token budget for the summarization using the `tokenBudget` setting. Note: Currently only the `run_shell_command` tool is supported. For example `{"run_shell_command": {"tokenBudget": 2000}}` | `undefined` |
|
||||||
| `model.generationConfig` | object | Advanced overrides passed to the underlying content generator. Supports request controls such as `timeout`, `maxRetries`, `enableCacheControl`, `contextWindowSize` (override model's context window size), `customHeaders` (custom HTTP headers for API requests), and `extra_body` (additional body parameters for OpenAI-compatible API requests only), along with fine-tuning knobs under `samplingParams` (for example `temperature`, `top_p`, `max_tokens`). Leave unset to rely on provider defaults. | `undefined` |
|
| `model.generationConfig` | object | Advanced overrides passed to the underlying content generator. Supports request controls such as `timeout`, `maxRetries`, `enableCacheControl`, `contextWindowSize` (override model's context window size), `modalities` (override auto-detected input modalities), `customHeaders` (custom HTTP headers for API requests), and `extra_body` (additional body parameters for OpenAI-compatible API requests only), along with fine-tuning knobs under `samplingParams` (for example `temperature`, `top_p`, `max_tokens`). Leave unset to rely on provider defaults. | `undefined` |
|
||||||
| `model.chatCompression.contextPercentageThreshold` | number | Sets the threshold for chat history compression as a percentage of the model's total token limit. This is a value between 0 and 1 that applies to both automatic compression and the manual `/compress` command. For example, a value of `0.6` will trigger compression when the chat history exceeds 60% of the token limit. Use `0` to disable compression entirely. | `0.7` |
|
| `model.chatCompression.contextPercentageThreshold` | number | Sets the threshold for chat history compression as a percentage of the model's total token limit. This is a value between 0 and 1 that applies to both automatic compression and the manual `/compress` command. For example, a value of `0.6` will trigger compression when the chat history exceeds 60% of the token limit. Use `0` to disable compression entirely. | `0.7` |
|
||||||
| `model.skipNextSpeakerCheck` | boolean | Skip the next speaker check. | `false` |
|
| `model.skipNextSpeakerCheck` | boolean | Skip the next speaker check. | `false` |
|
||||||
| `model.skipLoopDetection` | boolean | Disables loop detection checks. Loop detection prevents infinite loops in AI responses but can generate false positives that interrupt legitimate workflows. Enable this option if you experience frequent false positive loop detection interruptions. | `false` |
|
| `model.skipLoopDetection` | boolean | Disables loop detection checks. Loop detection prevents infinite loops in AI responses but can generate false positives that interrupt legitimate workflows. Enable this option if you experience frequent false positive loop detection interruptions. | `false` |
|
||||||
| `model.skipStartupContext` | boolean | Skips sending the startup workspace context (environment summary and acknowledgement) at the beginning of each session. Enable this if you prefer to provide context manually or want to save tokens on startup. | `false` |
|
| `model.skipStartupContext` | boolean | Skips sending the startup workspace context (environment summary and acknowledgement) at the beginning of each session. Enable this if you prefer to provide context manually or want to save tokens on startup. | `false` |
|
||||||
| `model.enableOpenAILogging` | boolean | Enables logging of OpenAI API calls for debugging and analysis. When enabled, API requests and responses are logged to JSON files. | `false` |
|
| `model.enableOpenAILogging` | boolean | Enables logging of OpenAI API calls for debugging and analysis. When enabled, API requests and responses are logged to JSON files. | `false` |
|
||||||
| `model.openAILoggingDir` | string | Custom directory path for OpenAI API logs. If not specified, defaults to `logs/openai` in the current working directory. Supports absolute paths, relative paths (resolved from current working directory), and `~` expansion (home directory). | `undefined` |
|
| `model.openAILoggingDir` | string | Custom directory path for OpenAI API logs. If not specified, defaults to `logs/openai` in the current working directory. Supports absolute paths, relative paths (resolved from current working directory), and `~` expansion (home directory). | `undefined` |
|
||||||
|
|
||||||
**Example model.generationConfig:**
|
**Example model.generationConfig:**
|
||||||
|
|
||||||
|
|
@ -146,6 +146,9 @@ Settings are organized into categories. All settings should be placed within the
|
||||||
"generationConfig": {
|
"generationConfig": {
|
||||||
"timeout": 60000,
|
"timeout": 60000,
|
||||||
"contextWindowSize": 128000,
|
"contextWindowSize": 128000,
|
||||||
|
"modalities": {
|
||||||
|
"image": true
|
||||||
|
},
|
||||||
"enableCacheControl": true,
|
"enableCacheControl": true,
|
||||||
"customHeaders": {
|
"customHeaders": {
|
||||||
"X-Client-Request-ID": "req-123"
|
"X-Client-Request-ID": "req-123"
|
||||||
|
|
@ -167,6 +170,10 @@ Settings are organized into categories. All settings should be placed within the
|
||||||
|
|
||||||
Overrides the default context window size for the selected model. Qwen Code determines the context window using built-in defaults based on model name matching, with a constant fallback value. Use this setting when a provider's effective context limit differs from Qwen Code's default. This value defines the model's assumed maximum context capacity, not a per-request token limit.
|
Overrides the default context window size for the selected model. Qwen Code determines the context window using built-in defaults based on model name matching, with a constant fallback value. Use this setting when a provider's effective context limit differs from Qwen Code's default. This value defines the model's assumed maximum context capacity, not a per-request token limit.
|
||||||
|
|
||||||
|
**modalities:**
|
||||||
|
|
||||||
|
Overrides the auto-detected input modalities for the selected model. Qwen Code automatically detects supported modalities (image, PDF, audio, video) based on model name pattern matching. Use this setting when the auto-detection is incorrect — for example, to enable `pdf` for a model that supports it but isn't recognized. Format: `{ "image": true, "pdf": true, "audio": true, "video": true }`. Omit a key or set it to `false` for unsupported types.
|
||||||
|
|
||||||
**customHeaders:**
|
**customHeaders:**
|
||||||
|
|
||||||
Allows you to add custom HTTP headers to all API requests. This is useful for request tracing, monitoring, API gateway routing, or when different models require different headers. If `customHeaders` is defined in `modelProviders[].generationConfig.customHeaders`, it will be used directly; otherwise, headers from `model.generationConfig.customHeaders` will be used. No merging occurs between the two levels.
|
Allows you to add custom HTTP headers to all API requests. This is useful for request tracing, monitoring, API gateway routing, or when different models require different headers. If `customHeaders` is defined in `modelProviders[].generationConfig.customHeaders`, it will be used directly; otherwise, headers from `model.generationConfig.customHeaders` will be used. No merging occurs between the two levels.
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,9 @@ Environment Variables: Commands executed via `!` will set the `QWEN_CODE=1` envi
|
||||||
|
|
||||||
Save frequently used prompts as shortcut commands to improve work efficiency and ensure consistency.
|
Save frequently used prompts as shortcut commands to improve work efficiency and ensure consistency.
|
||||||
|
|
||||||
> **Note:** Custom commands now use Markdown format with optional YAML frontmatter. TOML format is deprecated but still supported for backwards compatibility. When TOML files are detected, an automatic migration prompt will be displayed.
|
> [!note]
|
||||||
|
>
|
||||||
|
> Custom commands now use Markdown format with optional YAML frontmatter. TOML format is deprecated but still supported for backwards compatibility. When TOML files are detected, an automatic migration prompt will be displayed.
|
||||||
|
|
||||||
### Quick Overview
|
### Quick Overview
|
||||||
|
|
||||||
|
|
@ -137,10 +139,10 @@ Priority Rules: Project commands > User commands (project command used when name
|
||||||
|
|
||||||
#### File Path to Command Name Mapping Table
|
#### File Path to Command Name Mapping Table
|
||||||
|
|
||||||
| File Location | Generated Command | Example Call |
|
| File Location | Generated Command | Example Call |
|
||||||
| -------------------------- | ----------------- | --------------------- |
|
| ---------------------------------------- | ----------------- | --------------------- |
|
||||||
| `~/.qwen/commands/test.md` | `/test` | `/test Parameter` |
|
| `~/.qwen/commands/test.md` | `/test` | `/test Parameter` |
|
||||||
| `<project>/git/commit.md` | `/git:commit` | `/git:commit Message` |
|
| `<project>/.qwen/commands/git/commit.md` | `/git:commit` | `/git:commit Message` |
|
||||||
|
|
||||||
Naming Rules: Path separator (`/` or `\`) converted to colon (`:`)
|
Naming Rules: Path separator (`/` or `\`) converted to colon (`:`)
|
||||||
|
|
||||||
|
|
@ -164,6 +166,8 @@ Use {{args}} for parameter injection.
|
||||||
|
|
||||||
### TOML File Format (Deprecated)
|
### TOML File Format (Deprecated)
|
||||||
|
|
||||||
|
> [!warning]
|
||||||
|
>
|
||||||
> **Deprecated:** TOML format is still supported but will be removed in a future version. Please migrate to Markdown format.
|
> **Deprecated:** TOML format is still supported but will be removed in a future version. Please migrate to Markdown format.
|
||||||
|
|
||||||
| Field | Required | Description | Example |
|
| Field | Required | Description | Example |
|
||||||
|
|
@ -225,8 +229,6 @@ Please generate a Commit message based on the following diff:
|
||||||
```
|
```
|
||||||
````
|
````
|
||||||
|
|
||||||
````
|
|
||||||
|
|
||||||
#### 4. File Content Injection (`@{...}`)
|
#### 4. File Content Injection (`@{...}`)
|
||||||
|
|
||||||
| File Type | Support Status | Processing Method |
|
| File Type | Support Status | Processing Method |
|
||||||
|
|
@ -246,7 +248,7 @@ description: Code review based on best practices
|
||||||
Review {{args}}, reference standards:
|
Review {{args}}, reference standards:
|
||||||
|
|
||||||
@{docs/code-standards.md}
|
@{docs/code-standards.md}
|
||||||
````
|
```
|
||||||
|
|
||||||
### Practical Creation Example
|
### Practical Creation Example
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,25 +7,24 @@
|
||||||
|
|
||||||
## Get started in 30 seconds
|
## Get started in 30 seconds
|
||||||
|
|
||||||
Prerequisites:
|
|
||||||
|
|
||||||
- A [Qwen Code](https://chat.qwen.ai/auth?mode=register) account
|
|
||||||
- Requires [Node.js 20+](https://nodejs.org/zh-cn/download), you can use `node -v` to check the version. If it's not installed, use the following command to install it.
|
|
||||||
|
|
||||||
### Install Qwen Code:
|
### Install Qwen Code:
|
||||||
|
|
||||||
**NPM**(recommended)
|
**Linux / macOS**
|
||||||
|
|
||||||
```bash
|
```sh
|
||||||
npm install -g @qwen-code/qwen-code@latest
|
curl -fsSL https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
**Homebrew**(macOS, Linux)
|
**Windows (Run as Administrator CMD)**
|
||||||
|
|
||||||
```bash
|
```sh
|
||||||
brew install qwen-code
|
curl -fsSL -o %TEMP%\install-qwen.bat https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen.bat && %TEMP%\install-qwen.bat
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> [!note]
|
||||||
|
>
|
||||||
|
> It's recommended to restart your terminal after installation to ensure environment variables take effect. If the installation fails, please refer to [Manual Installation](./quickstart#manual-installation) in the Quickstart guide.
|
||||||
|
|
||||||
### Start using Qwen Code:
|
### Start using Qwen Code:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
|
|
@ -16,19 +16,39 @@ Make sure you have:
|
||||||
|
|
||||||
To install Qwen Code, use one of the following methods:
|
To install Qwen Code, use one of the following methods:
|
||||||
|
|
||||||
### NPM (recommended)
|
### Quick Install (Recommended)
|
||||||
|
|
||||||
Requires [Node.js 20+](https://nodejs.org/download), you can use `node -v` check the version. If it's not installed, use the following command to install it.
|
**Linux / macOS**
|
||||||
|
|
||||||
If you have [Node.js or newer installed](https://nodejs.org/en/download/):
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
curl -fsSL https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen.sh | bash
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows (Run as Administrator CMD)**
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -fsSL -o %TEMP%\install-qwen.bat https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen.bat && %TEMP%\install-qwen.bat
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!note]
|
||||||
|
>
|
||||||
|
> It's recommended to restart your terminal after installation to ensure environment variables take effect.
|
||||||
|
|
||||||
|
### Manual Installation
|
||||||
|
|
||||||
|
**Prerequisites**
|
||||||
|
|
||||||
|
Make sure you have Node.js 20 or later installed. Download it from [nodejs.org](https://nodejs.org/en/download).
|
||||||
|
|
||||||
|
**NPM**
|
||||||
|
|
||||||
|
```bash
|
||||||
npm install -g @qwen-code/qwen-code@latest
|
npm install -g @qwen-code/qwen-code@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
### Homebrew (macOS, Linux)
|
**Homebrew (macOS, Linux)**
|
||||||
|
|
||||||
```sh
|
```bash
|
||||||
brew install qwen-code
|
brew install qwen-code
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ This document lists the available keyboard shortcuts in Qwen Code.
|
||||||
| `Ctrl+N` | Navigate down through the input history. |
|
| `Ctrl+N` | Navigate down through the input history. |
|
||||||
| `Ctrl+P` | Navigate up through the input history. |
|
| `Ctrl+P` | Navigate up through the input history. |
|
||||||
| `Ctrl+R` | Reverse search through input/shell history. |
|
| `Ctrl+R` | Reverse search through input/shell history. |
|
||||||
|
| `Ctrl+Y` | Retry the last failed request. |
|
||||||
| `Ctrl+Right Arrow` / `Meta+Right Arrow` / `Meta+F` | Move the cursor one word to the right. |
|
| `Ctrl+Right Arrow` / `Meta+Right Arrow` / `Meta+F` | Move the cursor one word to the right. |
|
||||||
| `Ctrl+U` | Delete from the cursor to the beginning of the line. |
|
| `Ctrl+U` | Delete from the cursor to the beginning of the line. |
|
||||||
| `Ctrl+V` (Windows: `Alt+V`) | Paste clipboard content. If the clipboard contains an image, it will be saved and a reference to it will be inserted in the prompt. |
|
| `Ctrl+V` (Windows: `Alt+V`) | Paste clipboard content. If the clipboard contains an image, it will be saved and a reference to it will be inserted in the prompt. |
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,19 @@ Qwen Code is an open-source AI coding assistant tool maintained by the Qwen Code
|
||||||
|
|
||||||
## How to determine your authentication method
|
## How to determine your authentication method
|
||||||
|
|
||||||
Qwen Code supports two main authentication methods to access AI models. Your authentication method determines which terms of service and privacy policies apply to your usage:
|
Qwen Code supports three authentication methods to access AI models. Your authentication method determines which terms of service and privacy policies apply to your usage:
|
||||||
|
|
||||||
1. **Qwen OAuth** - Log in with your qwen.ai account
|
1. **Qwen OAuth** — Log in with your qwen.ai account (free daily quota)
|
||||||
2. **OpenAI-Compatible API** - Use API keys from various AI model providers
|
2. **Alibaba Cloud Coding Plan** — Use an API key from Alibaba Cloud
|
||||||
|
3. **API Key** — Bring your own API key
|
||||||
|
|
||||||
For each authentication method, different Terms of Service and Privacy Notices may apply depending on the underlying service provider.
|
For each authentication method, different Terms of Service and Privacy Notices may apply depending on the underlying service provider.
|
||||||
|
|
||||||
| Authentication Method | Provider | Terms of Service | Privacy Notice |
|
| Authentication Method | Provider | Terms of Service | Privacy Notice |
|
||||||
| :-------------------- | :---------------- | :---------------------------------------------------------------------------- | :--------------------------------------------------- |
|
| :------------------------ | :---------------- | :----------------------------------------------------------------- | :----------------------------------------------------------------- |
|
||||||
| Qwen OAuth | Qwen AI | [Qwen Terms of Service](https://qwen.ai/termsservice) | [Qwen Privacy Policy](https://qwen.ai/privacypolicy) |
|
| Qwen OAuth | Qwen AI | [Qwen Terms of Service](https://qwen.ai/termsservice) | [Qwen Privacy Policy](https://qwen.ai/privacypolicy) |
|
||||||
| OpenAI-Compatible API | Various Providers | Depends on your chosen API provider (OpenAI, Alibaba Cloud, ModelScope, etc.) | Depends on your chosen API provider |
|
| Alibaba Cloud Coding Plan | Alibaba Cloud | See [details below](#2-if-you-are-using-alibaba-cloud-coding-plan) | See [details below](#2-if-you-are-using-alibaba-cloud-coding-plan) |
|
||||||
|
| API Key | Various Providers | Depends on your chosen API provider (OpenAI, Anthropic, etc.) | Depends on your chosen API provider |
|
||||||
|
|
||||||
## 1. If you are using Qwen OAuth Authentication
|
## 1. If you are using Qwen OAuth Authentication
|
||||||
|
|
||||||
|
|
@ -25,13 +27,26 @@ When you authenticate using your qwen.ai account, these Terms of Service and Pri
|
||||||
|
|
||||||
For details about authentication setup, quotas, and supported features, see [Authentication Setup](../configuration/settings).
|
For details about authentication setup, quotas, and supported features, see [Authentication Setup](../configuration/settings).
|
||||||
|
|
||||||
## 2. If you are using OpenAI-Compatible API Authentication
|
## 2. If you are using Alibaba Cloud Coding Plan
|
||||||
|
|
||||||
When you authenticate using API keys from OpenAI-compatible providers, the applicable Terms of Service and Privacy Notice depend on your chosen provider.
|
When you authenticate using an API key from Alibaba Cloud, the applicable Terms of Service and Privacy Notice from Alibaba Cloud apply.
|
||||||
|
|
||||||
|
Alibaba Cloud Coding Plan is available in two regions:
|
||||||
|
|
||||||
|
- **阿里云百炼 (aliyun.com)** — [bailian.console.aliyun.com](https://bailian.console.aliyun.com)
|
||||||
|
- **Alibaba Cloud (alibabacloud.com)** — [bailian.console.alibabacloud.com](https://bailian.console.alibabacloud.com)
|
||||||
|
|
||||||
> [!important]
|
> [!important]
|
||||||
>
|
>
|
||||||
> When using OpenAI-compatible API authentication, you are subject to the terms and privacy policies of your chosen API provider, not Qwen Code's terms. Please review your provider's documentation for specific details about data usage, retention, and privacy practices.
|
> When using Alibaba Cloud Coding Plan, you are subject to Alibaba Cloud's terms and privacy policies. Please review their documentation for specific details about data usage, retention, and privacy practices.
|
||||||
|
|
||||||
|
## 3. If you are using your own API Key
|
||||||
|
|
||||||
|
When you authenticate using API keys from other providers, the applicable Terms of Service and Privacy Notice depend on your chosen provider.
|
||||||
|
|
||||||
|
> [!important]
|
||||||
|
>
|
||||||
|
> When using your own API key, you are subject to the terms and privacy policies of your chosen API provider, not Qwen Code's terms. Please review your provider's documentation for specific details about data usage, retention, and privacy practices.
|
||||||
|
|
||||||
Qwen Code supports various OpenAI-compatible providers. Please refer to your specific provider's terms of service and privacy policy for detailed information.
|
Qwen Code supports various OpenAI-compatible providers. Please refer to your specific provider's terms of service and privacy policy for detailed information.
|
||||||
|
|
||||||
|
|
@ -50,7 +65,8 @@ When enabled, Qwen Code may collect:
|
||||||
### Data Collection by Authentication Method
|
### Data Collection by Authentication Method
|
||||||
|
|
||||||
- **Qwen OAuth:** Usage statistics are governed by Qwen's privacy policy. You can opt-out through Qwen Code's configuration settings.
|
- **Qwen OAuth:** Usage statistics are governed by Qwen's privacy policy. You can opt-out through Qwen Code's configuration settings.
|
||||||
- **OpenAI-Compatible API:** No additional data is collected by Qwen Code beyond what your chosen API provider collects.
|
- **Alibaba Cloud Coding Plan:** Usage statistics are governed by Alibaba Cloud's privacy policy. You can opt-out through Qwen Code's configuration settings.
|
||||||
|
- **API Key:** No additional data is collected by Qwen Code beyond what your chosen API provider collects.
|
||||||
|
|
||||||
## Frequently Asked Questions (FAQ)
|
## Frequently Asked Questions (FAQ)
|
||||||
|
|
||||||
|
|
@ -60,7 +76,9 @@ Whether your code, including prompts and answers, is used to train AI models dep
|
||||||
|
|
||||||
- **Qwen OAuth**: Data usage is governed by [Qwen's Privacy Policy](https://qwen.ai/privacy). Please refer to their policy for specific details about data collection and model training practices.
|
- **Qwen OAuth**: Data usage is governed by [Qwen's Privacy Policy](https://qwen.ai/privacy). Please refer to their policy for specific details about data collection and model training practices.
|
||||||
|
|
||||||
- **OpenAI-Compatible API**: Data usage depends entirely on your chosen API provider. Each provider has their own data usage policies. Please review the privacy policy and terms of service of your specific provider.
|
- **Alibaba Cloud Coding Plan**: Data usage is governed by Alibaba Cloud's privacy policy. Please refer to their policy for specific details about data collection and model training practices.
|
||||||
|
|
||||||
|
- **API Key**: Data usage depends entirely on your chosen API provider. Each provider has their own data usage policies. Please review the privacy policy and terms of service of your specific provider.
|
||||||
|
|
||||||
**Important**: Qwen Code itself does not use your prompts, code, or responses for model training. Any data usage for training purposes would be governed by the policies of the AI service provider you authenticate with.
|
**Important**: Qwen Code itself does not use your prompts, code, or responses for model training. Any data usage for training purposes would be governed by the policies of the AI service provider you authenticate with.
|
||||||
|
|
||||||
|
|
@ -85,10 +103,10 @@ The Usage Statistics setting only controls data collection by Qwen Code itself.
|
||||||
|
|
||||||
### 3. How do I switch between authentication methods?
|
### 3. How do I switch between authentication methods?
|
||||||
|
|
||||||
You can switch between Qwen OAuth and OpenAI-compatible API authentication at any time:
|
You can switch between Qwen OAuth, Alibaba Cloud Coding Plan, and your own API key at any time:
|
||||||
|
|
||||||
1. **During startup**: Choose your preferred authentication method when prompted
|
1. **During startup**: Choose your preferred authentication method when prompted
|
||||||
2. **Within the CLI**: Use the `/auth` command to reconfigure your authentication method
|
2. **Within the CLI**: Use the `/auth` command to reconfigure your authentication method
|
||||||
3. **Environment variables**: Set up `.env` files for automatic OpenAI-compatible API authentication
|
3. **Environment variables**: Set up `.env` files for automatic API key authentication
|
||||||
|
|
||||||
For detailed instructions, see the [Authentication Setup](../configuration/settings#environment-variables-for-api-access) documentation.
|
For detailed instructions, see the [Authentication Setup](../configuration/settings#environment-variables-for-api-access) documentation.
|
||||||
|
|
|
||||||
|
|
@ -254,9 +254,12 @@ export default tseslint.config(
|
||||||
'no-console': 'off',
|
'no-console': 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Settings for export-html assets
|
// Settings for web-templates assets
|
||||||
{
|
{
|
||||||
files: ['packages/cli/assets/export-html/**/*.{js,jsx,ts,tsx}'],
|
files: [
|
||||||
|
'packages/web-templates/src/**/*.{js,jsx,ts,tsx}',
|
||||||
|
'packages/web-templates/*.mjs',
|
||||||
|
],
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
globals: {
|
globals: {
|
||||||
...globals.browser,
|
...globals.browser,
|
||||||
|
|
@ -271,6 +274,8 @@ export default tseslint.config(
|
||||||
rules: {
|
rules: {
|
||||||
'react/react-in-jsx-scope': 'off',
|
'react/react-in-jsx-scope': 'off',
|
||||||
'react/prop-types': 'off',
|
'react/prop-types': 'off',
|
||||||
|
'no-console': 'off',
|
||||||
|
'no-undef': 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Prettier config must be last
|
// Prettier config must be last
|
||||||
|
|
|
||||||
|
|
@ -472,6 +472,156 @@ function setupAcpTest(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('supports session/set_config_option for mode and model', async () => {
|
||||||
|
const rig = new TestRig();
|
||||||
|
rig.setup('acp set config option');
|
||||||
|
|
||||||
|
const { sendRequest, cleanup, stderr } = setupAcpTest(rig);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Initialize
|
||||||
|
await sendRequest('initialize', {
|
||||||
|
protocolVersion: 1,
|
||||||
|
clientCapabilities: {
|
||||||
|
fs: { readTextFile: true, writeTextFile: true },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await sendRequest('authenticate', { methodId: 'openai' });
|
||||||
|
|
||||||
|
// Create a new session
|
||||||
|
const newSession = (await sendRequest('session/new', {
|
||||||
|
cwd: rig.testDir!,
|
||||||
|
mcpServers: [],
|
||||||
|
})) as {
|
||||||
|
sessionId: string;
|
||||||
|
models: {
|
||||||
|
availableModels: Array<{ modelId: string }>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
expect(newSession.sessionId).toBeTruthy();
|
||||||
|
|
||||||
|
// Test: Set mode using set_config_option
|
||||||
|
const setModeResult = (await sendRequest('session/set_config_option', {
|
||||||
|
sessionId: newSession.sessionId,
|
||||||
|
configId: 'mode',
|
||||||
|
value: 'yolo',
|
||||||
|
})) as {
|
||||||
|
configOptions: Array<{
|
||||||
|
id: string;
|
||||||
|
currentValue: string;
|
||||||
|
options: Array<{ value: string; name: string; description: string }>;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(setModeResult).toBeDefined();
|
||||||
|
expect(Array.isArray(setModeResult.configOptions)).toBe(true);
|
||||||
|
expect(setModeResult.configOptions.length).toBeGreaterThanOrEqual(2);
|
||||||
|
|
||||||
|
// Find mode option
|
||||||
|
const modeOption = setModeResult.configOptions.find(
|
||||||
|
(opt) => opt.id === 'mode',
|
||||||
|
);
|
||||||
|
expect(modeOption).toBeDefined();
|
||||||
|
expect(modeOption!.currentValue).toBe('yolo');
|
||||||
|
expect(Array.isArray(modeOption!.options)).toBe(true);
|
||||||
|
expect(modeOption!.options.some((o) => o.value === 'yolo')).toBe(true);
|
||||||
|
|
||||||
|
// Find model option
|
||||||
|
const modelOption = setModeResult.configOptions.find(
|
||||||
|
(opt) => opt.id === 'model',
|
||||||
|
);
|
||||||
|
expect(modelOption).toBeDefined();
|
||||||
|
expect(modelOption!.currentValue).toBeTruthy();
|
||||||
|
|
||||||
|
// Test: Set model using set_config_option
|
||||||
|
// Use openai model to avoid auth issues
|
||||||
|
const openaiModel = newSession.models.availableModels.find((model) =>
|
||||||
|
model.modelId.includes('openai'),
|
||||||
|
);
|
||||||
|
expect(openaiModel).toBeDefined();
|
||||||
|
|
||||||
|
const setModelResult = (await sendRequest('session/set_config_option', {
|
||||||
|
sessionId: newSession.sessionId,
|
||||||
|
configId: 'model',
|
||||||
|
value: openaiModel!.modelId,
|
||||||
|
})) as {
|
||||||
|
configOptions: Array<{
|
||||||
|
id: string;
|
||||||
|
currentValue: string;
|
||||||
|
options: Array<{ value: string; name: string; description: string }>;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(setModelResult).toBeDefined();
|
||||||
|
expect(Array.isArray(setModelResult.configOptions)).toBe(true);
|
||||||
|
|
||||||
|
// Verify model was updated
|
||||||
|
const updatedModelOption = setModelResult.configOptions.find(
|
||||||
|
(opt) => opt.id === 'model',
|
||||||
|
);
|
||||||
|
expect(updatedModelOption).toBeDefined();
|
||||||
|
expect(updatedModelOption!.currentValue).toBe(openaiModel!.modelId);
|
||||||
|
} catch (e) {
|
||||||
|
if (stderr.length) {
|
||||||
|
console.error('Agent stderr:', stderr.join(''));
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
await cleanup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns error for invalid configId in set_config_option', async () => {
|
||||||
|
const rig = new TestRig();
|
||||||
|
rig.setup('acp set config option error');
|
||||||
|
|
||||||
|
const { sendRequest, cleanup, stderr } = setupAcpTest(rig);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Initialize
|
||||||
|
await sendRequest('initialize', {
|
||||||
|
protocolVersion: 1,
|
||||||
|
clientCapabilities: {
|
||||||
|
fs: { readTextFile: true, writeTextFile: true },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await sendRequest('authenticate', { methodId: 'openai' });
|
||||||
|
|
||||||
|
// Create a new session
|
||||||
|
const newSession = (await sendRequest('session/new', {
|
||||||
|
cwd: rig.testDir!,
|
||||||
|
mcpServers: [],
|
||||||
|
})) as { sessionId: string };
|
||||||
|
expect(newSession.sessionId).toBeTruthy();
|
||||||
|
|
||||||
|
// Test: Invalid configId should return error
|
||||||
|
await expect(
|
||||||
|
sendRequest('session/set_config_option', {
|
||||||
|
sessionId: newSession.sessionId,
|
||||||
|
configId: 'invalid_config',
|
||||||
|
value: 'some_value',
|
||||||
|
}),
|
||||||
|
).rejects.toMatchObject({
|
||||||
|
response: {
|
||||||
|
code: -32602,
|
||||||
|
message: 'Invalid params',
|
||||||
|
data: {
|
||||||
|
details: 'Unsupported configId: invalid_config',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (stderr.length) {
|
||||||
|
console.error('Agent stderr:', stderr.join(''));
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
await cleanup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('receives available_commands_update with slash commands after session creation', async () => {
|
it('receives available_commands_update with slash commands after session creation', async () => {
|
||||||
const rig = new TestRig();
|
const rig = new TestRig();
|
||||||
rig.setup('acp slash commands');
|
rig.setup('acp slash commands');
|
||||||
|
|
@ -659,7 +809,13 @@ function setupAcpTest(
|
||||||
}> = [];
|
}> = [];
|
||||||
|
|
||||||
const { sendRequest, cleanup, stderr, sessionUpdates } = setupAcpTest(rig, {
|
const { sendRequest, cleanup, stderr, sessionUpdates } = setupAcpTest(rig, {
|
||||||
permissionHandler: () => ({ optionId: 'proceed_once' }),
|
permissionHandler: (request) => {
|
||||||
|
// Cancel exit_plan_mode to keep plan mode active
|
||||||
|
if (request.toolCall?.kind === 'switch_mode') {
|
||||||
|
return { outcome: 'cancelled' };
|
||||||
|
}
|
||||||
|
return { optionId: 'proceed_once' };
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
189
integration-tests/fixtures/settings-migration/workspaces.json
Normal file
189
integration-tests/fixtures/settings-migration/workspaces.json
Normal file
|
|
@ -0,0 +1,189 @@
|
||||||
|
{
|
||||||
|
"v1Settings": {
|
||||||
|
"theme": "dark",
|
||||||
|
"model": "gemini",
|
||||||
|
"autoAccept": true,
|
||||||
|
"hideTips": false,
|
||||||
|
"vimMode": true,
|
||||||
|
"checkpointing": true,
|
||||||
|
"disableAutoUpdate": true,
|
||||||
|
"disableLoadingPhrases": true,
|
||||||
|
"mcpServers": {
|
||||||
|
"fetch": {
|
||||||
|
"command": "node",
|
||||||
|
"args": ["fetch-server.js"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"customUserSetting": "preserved-value"
|
||||||
|
},
|
||||||
|
"v1ComplexSettings": {
|
||||||
|
"theme": "dark",
|
||||||
|
"model": "gemini-1.5-pro",
|
||||||
|
"autoAccept": false,
|
||||||
|
"hideTips": true,
|
||||||
|
"vimMode": false,
|
||||||
|
"checkpointing": true,
|
||||||
|
"disableAutoUpdate": true,
|
||||||
|
"disableUpdateNag": false,
|
||||||
|
"disableLoadingPhrases": true,
|
||||||
|
"disableFuzzySearch": false,
|
||||||
|
"disableCacheControl": true,
|
||||||
|
"allowedTools": ["read-file", "write-file"],
|
||||||
|
"allowMCPServers": true,
|
||||||
|
"autoConfigureMaxOldSpaceSize": true,
|
||||||
|
"bugCommand": "/bug",
|
||||||
|
"chatCompression": "auto",
|
||||||
|
"coreTools": ["edit", "bash"],
|
||||||
|
"customThemes": [],
|
||||||
|
"customWittyPhrases": [],
|
||||||
|
"fileFiltering": true,
|
||||||
|
"folderTrust": true,
|
||||||
|
"ideMode": true,
|
||||||
|
"includeDirectories": ["src", "lib"],
|
||||||
|
"maxSessionTurns": 50,
|
||||||
|
"preferredEditor": "vscode",
|
||||||
|
"sandbox": false,
|
||||||
|
"summarizeToolOutput": true,
|
||||||
|
"telemetry": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"useRipgrep": true,
|
||||||
|
"myCustomKey": "custom-value",
|
||||||
|
"anotherCustomSetting": {
|
||||||
|
"nested": true,
|
||||||
|
"items": [1, 2, 3]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"v1ArrayAndNullSettings": {
|
||||||
|
"theme": null,
|
||||||
|
"model": ["gemini", "claude"],
|
||||||
|
"autoAccept": false,
|
||||||
|
"includeDirectories": [],
|
||||||
|
"disableFuzzySearch": "TRUE",
|
||||||
|
"disableCacheControl": "FALSE",
|
||||||
|
"customArray": [{ "key": 1 }]
|
||||||
|
},
|
||||||
|
"v1ParentCollisionSettings": {
|
||||||
|
"theme": "dark",
|
||||||
|
"model": "gemini",
|
||||||
|
"ui": "legacy-ui-string",
|
||||||
|
"general": "legacy-general-string",
|
||||||
|
"disableAutoUpdate": true,
|
||||||
|
"disableLoadingPhrases": false,
|
||||||
|
"notes": {
|
||||||
|
"fromUser": "preserve-custom"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"v1VersionStringSettings": {
|
||||||
|
"$version": "2",
|
||||||
|
"theme": "light",
|
||||||
|
"model": "qwen-plus",
|
||||||
|
"disableAutoUpdate": "false",
|
||||||
|
"disableLoadingPhrases": "TRUE",
|
||||||
|
"ui": {
|
||||||
|
"hideWindowTitle": true
|
||||||
|
},
|
||||||
|
"customSection": {
|
||||||
|
"keepMe": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"v2Settings": {
|
||||||
|
"$version": 2,
|
||||||
|
"ui": {
|
||||||
|
"theme": "light",
|
||||||
|
"accessibility": {
|
||||||
|
"disableLoadingPhrases": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"general": {
|
||||||
|
"disableAutoUpdate": false,
|
||||||
|
"disableUpdateNag": false,
|
||||||
|
"checkpointing": false
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"name": "claude"
|
||||||
|
},
|
||||||
|
"context": {
|
||||||
|
"fileFiltering": {
|
||||||
|
"disableFuzzySearch": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mcpServers": {}
|
||||||
|
},
|
||||||
|
"v2MinimalSettings": {
|
||||||
|
"$version": 2
|
||||||
|
},
|
||||||
|
"v2BooleanStringSettings": {
|
||||||
|
"$version": 2,
|
||||||
|
"general": {
|
||||||
|
"disableAutoUpdate": "TRUE",
|
||||||
|
"disableUpdateNag": "false"
|
||||||
|
},
|
||||||
|
"ui": {
|
||||||
|
"accessibility": {
|
||||||
|
"disableLoadingPhrases": "FaLsE"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"context": {
|
||||||
|
"fileFiltering": {
|
||||||
|
"disableFuzzySearch": "TRUE"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"generationConfig": {
|
||||||
|
"disableCacheControl": "false"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"v2PreexistingEnableSettings": {
|
||||||
|
"$version": 2,
|
||||||
|
"general": {
|
||||||
|
"disableAutoUpdate": false,
|
||||||
|
"disableUpdateNag": true,
|
||||||
|
"enableAutoUpdate": true
|
||||||
|
},
|
||||||
|
"ui": {
|
||||||
|
"accessibility": {
|
||||||
|
"disableLoadingPhrases": true,
|
||||||
|
"enableLoadingPhrases": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"context": {
|
||||||
|
"fileFiltering": {
|
||||||
|
"disableFuzzySearch": false,
|
||||||
|
"enableFuzzySearch": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"generationConfig": {
|
||||||
|
"disableCacheControl": true,
|
||||||
|
"enableCacheControl": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"v3LegacyDisableSettings": {
|
||||||
|
"$version": 3,
|
||||||
|
"general": {
|
||||||
|
"disableAutoUpdate": true,
|
||||||
|
"enableAutoUpdate": false
|
||||||
|
},
|
||||||
|
"ui": {
|
||||||
|
"accessibility": {
|
||||||
|
"disableLoadingPhrases": false,
|
||||||
|
"enableLoadingPhrases": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"custom": {
|
||||||
|
"note": "should remain unchanged in v3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"v999FutureVersionSettings": {
|
||||||
|
"$version": 999,
|
||||||
|
"theme": "dark",
|
||||||
|
"model": "future-model",
|
||||||
|
"disableAutoUpdate": true,
|
||||||
|
"experimentalFlag": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -94,7 +94,7 @@ export async function setup() {
|
||||||
|
|
||||||
// Environment variables for CLI integration tests
|
// Environment variables for CLI integration tests
|
||||||
process.env['INTEGRATION_TEST_FILE_DIR'] = runDir;
|
process.env['INTEGRATION_TEST_FILE_DIR'] = runDir;
|
||||||
process.env['GEMINI_CLI_INTEGRATION_TEST'] = 'true';
|
process.env['QWEN_CODE_INTEGRATION_TEST'] = 'true';
|
||||||
process.env['TELEMETRY_LOG_FILE'] = join(runDir, 'telemetry.log');
|
process.env['TELEMETRY_LOG_FILE'] = join(runDir, 'telemetry.log');
|
||||||
|
|
||||||
// Environment variables for SDK E2E tests
|
// Environment variables for SDK E2E tests
|
||||||
|
|
|
||||||
1946
integration-tests/hook-integration/hooks.test.ts
Normal file
1946
integration-tests/hook-integration/hooks.test.ts
Normal file
File diff suppressed because it is too large
Load diff
627
integration-tests/settings-migration.test.ts
Normal file
627
integration-tests/settings-migration.test.ts
Normal file
|
|
@ -0,0 +1,627 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||||
|
import { TestRig } from './test-helper.js';
|
||||||
|
import { writeFileSync, readFileSync } from 'node:fs';
|
||||||
|
import { join } from 'node:path';
|
||||||
|
|
||||||
|
// Import settings fixtures from unified workspace file
|
||||||
|
import workspacesSettings from './fixtures/settings-migration/workspaces.json' with { type: 'json' };
|
||||||
|
|
||||||
|
const {
|
||||||
|
v1Settings,
|
||||||
|
v1ComplexSettings,
|
||||||
|
v1ArrayAndNullSettings,
|
||||||
|
v1ParentCollisionSettings,
|
||||||
|
v1VersionStringSettings,
|
||||||
|
v2Settings,
|
||||||
|
v2MinimalSettings,
|
||||||
|
v2BooleanStringSettings,
|
||||||
|
v2PreexistingEnableSettings,
|
||||||
|
v3LegacyDisableSettings,
|
||||||
|
v999FutureVersionSettings,
|
||||||
|
} = workspacesSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration tests for settings migration chain (V1 -> V2 -> V3)
|
||||||
|
*
|
||||||
|
* These tests verify that:
|
||||||
|
* 1. V1 settings are automatically migrated to V3 on CLI startup
|
||||||
|
* 2. V2 settings are automatically migrated to V3 on CLI startup
|
||||||
|
* 3. V3 settings remain unchanged
|
||||||
|
* 4. Migration is idempotent (running multiple times produces same result)
|
||||||
|
*/
|
||||||
|
describe('settings-migration', () => {
|
||||||
|
let rig: TestRig;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
rig = new TestRig();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await rig.cleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to write settings file for an existing test rig.
|
||||||
|
* This overwrites the settings file created by rig.setup().
|
||||||
|
*/
|
||||||
|
const overwriteSettingsFile = (
|
||||||
|
testRig: TestRig,
|
||||||
|
settings: Record<string, unknown>,
|
||||||
|
) => {
|
||||||
|
const qwenDir = join(
|
||||||
|
(testRig as unknown as { testDir: string }).testDir,
|
||||||
|
'.qwen',
|
||||||
|
);
|
||||||
|
writeFileSync(
|
||||||
|
join(qwenDir, 'settings.json'),
|
||||||
|
JSON.stringify(settings, null, 2),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to read settings file from the test directory
|
||||||
|
*/
|
||||||
|
const readSettingsFile = (testRig: TestRig): Record<string, unknown> => {
|
||||||
|
const qwenDir = join(
|
||||||
|
(testRig as unknown as { testDir: string }).testDir,
|
||||||
|
'.qwen',
|
||||||
|
);
|
||||||
|
const content = readFileSync(join(qwenDir, 'settings.json'), 'utf-8');
|
||||||
|
return JSON.parse(content) as Record<string, unknown>;
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('V1 settings migration', () => {
|
||||||
|
it('should migrate V1 settings to V3 on CLI startup', async () => {
|
||||||
|
rig.setup('v1-to-v3-migration');
|
||||||
|
|
||||||
|
// Write V1 settings directly (overwrites the one created by setup)
|
||||||
|
overwriteSettingsFile(rig, v1Settings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
// We expect this to fail due to missing API key, but migration should still occur
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail, we just need the settings file to be processed
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read migrated settings
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Verify migration to V3
|
||||||
|
expect(migratedSettings['$version']).toBe(3);
|
||||||
|
expect(migratedSettings['ui']).toEqual({
|
||||||
|
theme: 'dark',
|
||||||
|
hideTips: false,
|
||||||
|
accessibility: {
|
||||||
|
enableLoadingPhrases: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(migratedSettings['model']).toEqual({ name: 'gemini' });
|
||||||
|
expect(migratedSettings['tools']).toEqual({ autoAccept: true });
|
||||||
|
expect(migratedSettings['general']).toEqual({
|
||||||
|
vimMode: true,
|
||||||
|
checkpointing: true,
|
||||||
|
enableAutoUpdate: false,
|
||||||
|
});
|
||||||
|
expect(migratedSettings['mcpServers']).toEqual({
|
||||||
|
fetch: {
|
||||||
|
command: 'node',
|
||||||
|
args: ['fetch-server.js'],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// Custom user settings should be preserved
|
||||||
|
expect(migratedSettings['customUserSetting']).toBe('preserved-value');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle V1 settings with arrays and null values', async () => {
|
||||||
|
rig.setup('v1-array-and-null-migration');
|
||||||
|
|
||||||
|
// Use fixture with arrays, null values, and string booleans
|
||||||
|
overwriteSettingsFile(rig, v1ArrayAndNullSettings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read migrated settings
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Expected output based on stable test output
|
||||||
|
expect(migratedSettings['$version']).toBe(3);
|
||||||
|
expect(migratedSettings['tools']).toEqual({ autoAccept: false });
|
||||||
|
expect(migratedSettings['context']).toEqual({ includeDirectories: [] });
|
||||||
|
expect(migratedSettings['model']).toEqual({ name: ['gemini', 'claude'] });
|
||||||
|
expect(migratedSettings['ui']).toEqual({ theme: null });
|
||||||
|
expect(migratedSettings['customArray']).toEqual([{ key: 1 }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle V1 settings with parent key collision', async () => {
|
||||||
|
rig.setup('v1-parent-collision-migration');
|
||||||
|
|
||||||
|
// Use fixture where V1 flat keys (ui, general) conflict with V2/V3 nested structure
|
||||||
|
overwriteSettingsFile(rig, v1ParentCollisionSettings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read migrated settings
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Should be migrated to V3
|
||||||
|
expect(migratedSettings['$version']).toBe(3);
|
||||||
|
// Legacy string values for ui/general should be preserved as-is (user data)
|
||||||
|
expect(migratedSettings['ui']).toBe('legacy-ui-string');
|
||||||
|
expect(migratedSettings['general']).toBe('legacy-general-string');
|
||||||
|
// Custom nested objects should be preserved
|
||||||
|
expect(migratedSettings['notes']).toEqual({
|
||||||
|
fromUser: 'preserve-custom',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle V1 settings with string version and string booleans', async () => {
|
||||||
|
rig.setup('v1-string-version-migration');
|
||||||
|
|
||||||
|
// Use fixture with $version as string and string boolean values
|
||||||
|
overwriteSettingsFile(rig, v1VersionStringSettings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read migrated settings
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Expected output based on stable test output
|
||||||
|
expect(migratedSettings['$version']).toBe(3);
|
||||||
|
expect(migratedSettings['model']).toEqual({ name: 'qwen-plus' });
|
||||||
|
expect(migratedSettings['ui']).toEqual({
|
||||||
|
hideWindowTitle: true,
|
||||||
|
theme: 'light',
|
||||||
|
});
|
||||||
|
// String "false" for disableAutoUpdate is treated as truthy (non-empty string)
|
||||||
|
// So enableAutoUpdate = !truthy = false, but output shows true
|
||||||
|
// This suggests string "false" is parsed as boolean false
|
||||||
|
expect(
|
||||||
|
(migratedSettings['general'] as Record<string, unknown>)?.[
|
||||||
|
'enableAutoUpdate'
|
||||||
|
],
|
||||||
|
).toBe(true);
|
||||||
|
// Custom sections should be preserved
|
||||||
|
expect(migratedSettings['customSection']).toEqual({ keepMe: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('V2 settings migration', () => {
|
||||||
|
it('should migrate V2 settings to V3 on CLI startup', async () => {
|
||||||
|
rig.setup('v2-to-v3-migration');
|
||||||
|
|
||||||
|
// Write V2 settings directly (overwrites the one created by setup)
|
||||||
|
overwriteSettingsFile(rig, v2Settings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read migrated settings
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Verify migration to V3
|
||||||
|
expect(migratedSettings['$version']).toBe(3);
|
||||||
|
|
||||||
|
// Verify disable* -> enable* conversion with inversion
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['ui'] as Record<string, unknown>)?.[
|
||||||
|
'accessibility'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['enableLoadingPhrases'],
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
(migratedSettings['general'] as Record<string, unknown>)?.[
|
||||||
|
'enableAutoUpdate'
|
||||||
|
],
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['context'] as Record<string, unknown>)?.[
|
||||||
|
'fileFiltering'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['enableFuzzySearch'],
|
||||||
|
).toBe(false);
|
||||||
|
|
||||||
|
// Verify old disable* keys are removed
|
||||||
|
expect(
|
||||||
|
(migratedSettings['general'] as Record<string, unknown>)?.[
|
||||||
|
'disableAutoUpdate'
|
||||||
|
],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(migratedSettings['general'] as Record<string, unknown>)?.[
|
||||||
|
'disableUpdateNag'
|
||||||
|
],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['ui'] as Record<string, unknown>)?.[
|
||||||
|
'accessibility'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['disableLoadingPhrases'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['context'] as Record<string, unknown>)?.[
|
||||||
|
'fileFiltering'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['disableFuzzySearch'],
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle V2 settings without any disable* keys', async () => {
|
||||||
|
rig.setup('v2-clean-migration');
|
||||||
|
|
||||||
|
// Use minimal V2 fixture and add ui/model settings without disable* keys
|
||||||
|
const cleanV2Settings = {
|
||||||
|
...v2MinimalSettings,
|
||||||
|
ui: {
|
||||||
|
theme: 'dark',
|
||||||
|
},
|
||||||
|
model: {
|
||||||
|
name: 'gemini',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
overwriteSettingsFile(rig, cleanV2Settings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read migrated settings
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Should be updated to V3 version
|
||||||
|
expect(migratedSettings['$version']).toBe(3);
|
||||||
|
// Other settings should remain unchanged
|
||||||
|
expect(migratedSettings['ui']).toEqual({ theme: 'dark' });
|
||||||
|
expect(migratedSettings['model']).toEqual({ name: 'gemini' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should normalize legacy numeric version with no migratable keys to current version', async () => {
|
||||||
|
rig.setup('legacy-version-normalization');
|
||||||
|
|
||||||
|
// Use v1Settings fixture as base but with only custom key
|
||||||
|
const legacyVersionWithoutMigratableKeys = {
|
||||||
|
$version: 1,
|
||||||
|
customOnlyKey: 'value',
|
||||||
|
};
|
||||||
|
|
||||||
|
overwriteSettingsFile(rig, legacyVersionWithoutMigratableKeys);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger settings load/write path
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Version metadata should still be normalized to current version
|
||||||
|
expect(migratedSettings['$version']).toBe(3);
|
||||||
|
// Existing user content should be preserved
|
||||||
|
expect(migratedSettings['customOnlyKey']).toBe('value');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should coerce valid string booleans and remove invalid deprecated keys while bumping V2 to V3', async () => {
|
||||||
|
rig.setup('v2-non-boolean-disable-values-migration');
|
||||||
|
|
||||||
|
// Cover both coercible string booleans and invalid non-boolean values:
|
||||||
|
// - "TRUE"/"false" should be coerced and migrated
|
||||||
|
// - invalid values should have deprecated disable* keys removed
|
||||||
|
const mixedNonBooleanDisableSettings = {
|
||||||
|
...v2BooleanStringSettings,
|
||||||
|
ui: {
|
||||||
|
accessibility: {
|
||||||
|
disableLoadingPhrases: 'yes',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
context: {
|
||||||
|
fileFiltering: {
|
||||||
|
disableFuzzySearch: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
model: {
|
||||||
|
generationConfig: {
|
||||||
|
disableCacheControl: [1],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
overwriteSettingsFile(rig, mixedNonBooleanDisableSettings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read migrated settings
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Coercible strings are migrated; invalid disable* values are removed.
|
||||||
|
expect(migratedSettings['$version']).toBe(3);
|
||||||
|
expect(migratedSettings['general']).toEqual({
|
||||||
|
enableAutoUpdate: false,
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['ui'] as Record<string, unknown>)?.[
|
||||||
|
'accessibility'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['disableLoadingPhrases'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['ui'] as Record<string, unknown>)?.[
|
||||||
|
'accessibility'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['enableLoadingPhrases'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['context'] as Record<string, unknown>)?.[
|
||||||
|
'fileFiltering'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['disableFuzzySearch'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['context'] as Record<string, unknown>)?.[
|
||||||
|
'fileFiltering'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['enableFuzzySearch'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['model'] as Record<string, unknown>)?.[
|
||||||
|
'generationConfig'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['disableCacheControl'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['model'] as Record<string, unknown>)?.[
|
||||||
|
'generationConfig'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['enableCacheControl'],
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle V2 settings with preexisting enable* keys', async () => {
|
||||||
|
rig.setup('v2-preexisting-enable-migration');
|
||||||
|
|
||||||
|
// Use fixture with both disable* and enable* keys
|
||||||
|
overwriteSettingsFile(rig, v2PreexistingEnableSettings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read migrated settings
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Expected output based on stable test output
|
||||||
|
expect(migratedSettings['$version']).toBe(3);
|
||||||
|
// Migration converts disable* to enable* by inverting the value
|
||||||
|
// disableAutoUpdate: false -> enableAutoUpdate: true (inverted)
|
||||||
|
// But disableUpdateNag: true may affect the consolidation
|
||||||
|
expect(
|
||||||
|
(migratedSettings['general'] as Record<string, unknown>)?.[
|
||||||
|
'enableAutoUpdate'
|
||||||
|
],
|
||||||
|
).toBe(false);
|
||||||
|
// disableLoadingPhrases: true -> enableLoadingPhrases: false (inverted)
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['ui'] as Record<string, unknown>)?.[
|
||||||
|
'accessibility'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['enableLoadingPhrases'],
|
||||||
|
).toBe(false);
|
||||||
|
// disableFuzzySearch: false -> enableFuzzySearch: true (inverted)
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['context'] as Record<string, unknown>)?.[
|
||||||
|
'fileFiltering'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['enableFuzzySearch'],
|
||||||
|
).toBe(true);
|
||||||
|
// disableCacheControl: true -> enableCacheControl: false (inverted)
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(migratedSettings['model'] as Record<string, unknown>)?.[
|
||||||
|
'generationConfig'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['enableCacheControl'],
|
||||||
|
).toBe(false);
|
||||||
|
// Old disable* keys should be removed
|
||||||
|
expect(
|
||||||
|
(migratedSettings['general'] as Record<string, unknown>)?.[
|
||||||
|
'disableAutoUpdate'
|
||||||
|
],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(migratedSettings['general'] as Record<string, unknown>)?.[
|
||||||
|
'disableUpdateNag'
|
||||||
|
],
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('V3 settings handling', () => {
|
||||||
|
it('should handle V3 settings with legacy disable* keys', async () => {
|
||||||
|
rig.setup('v3-legacy-disable-keys');
|
||||||
|
|
||||||
|
// Use fixture with V3 format but still has legacy disable* keys
|
||||||
|
overwriteSettingsFile(rig, v3LegacyDisableSettings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read settings
|
||||||
|
const finalSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Should remain V3
|
||||||
|
expect(finalSettings['$version']).toBe(3);
|
||||||
|
// Note: V3 settings with legacy disable* keys are left as-is
|
||||||
|
// Migration only runs when version < current version
|
||||||
|
// Since this is already V3, no migration logic is applied
|
||||||
|
expect(
|
||||||
|
(finalSettings['general'] as Record<string, unknown>)?.[
|
||||||
|
'disableAutoUpdate'
|
||||||
|
],
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(finalSettings['ui'] as Record<string, unknown>)?.[
|
||||||
|
'accessibility'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['disableLoadingPhrases'],
|
||||||
|
).toBe(false);
|
||||||
|
// Existing enable* keys should be preserved
|
||||||
|
expect(
|
||||||
|
(finalSettings['general'] as Record<string, unknown>)?.[
|
||||||
|
'enableAutoUpdate'
|
||||||
|
],
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(finalSettings['ui'] as Record<string, unknown>)?.[
|
||||||
|
'accessibility'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['enableLoadingPhrases'],
|
||||||
|
).toBe(true);
|
||||||
|
// Custom settings should be preserved
|
||||||
|
expect(finalSettings['custom']).toEqual({
|
||||||
|
note: 'should remain unchanged in v3',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Future version settings handling', () => {
|
||||||
|
it('should not modify future version settings', async () => {
|
||||||
|
rig.setup('v999-future-version');
|
||||||
|
|
||||||
|
// Use fixture with future version ($version: 999)
|
||||||
|
overwriteSettingsFile(rig, v999FutureVersionSettings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read settings
|
||||||
|
const finalSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Future version should remain unchanged
|
||||||
|
expect(finalSettings['$version']).toBe(999);
|
||||||
|
expect(finalSettings['theme']).toBe('dark');
|
||||||
|
expect(finalSettings['model']).toBe('future-model');
|
||||||
|
expect(finalSettings['experimentalFlag']).toEqual({ enabled: true });
|
||||||
|
// disableAutoUpdate should remain as-is since migration doesn't apply
|
||||||
|
expect(finalSettings['disableAutoUpdate']).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Migration idempotency', () => {
|
||||||
|
it('should produce consistent results when run multiple times on V1 settings', async () => {
|
||||||
|
rig.setup('v1-idempotency');
|
||||||
|
|
||||||
|
overwriteSettingsFile(rig, v1Settings);
|
||||||
|
|
||||||
|
// Run CLI multiple times with --help
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
const firstRunSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
const secondRunSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
const thirdRunSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// All runs should produce identical results
|
||||||
|
expect(secondRunSettings).toEqual(firstRunSettings);
|
||||||
|
expect(thirdRunSettings).toEqual(firstRunSettings);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Complex migration scenarios', () => {
|
||||||
|
it('should preserve custom user settings during full migration chain', async () => {
|
||||||
|
rig.setup('preserve-custom-settings');
|
||||||
|
|
||||||
|
// Use v1ComplexSettings fixture which has custom user settings
|
||||||
|
overwriteSettingsFile(rig, v1ComplexSettings);
|
||||||
|
|
||||||
|
// Run CLI with --help to trigger migration without API calls
|
||||||
|
try {
|
||||||
|
await rig.runCommand(['--help']);
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially fail
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read migrated settings
|
||||||
|
const migratedSettings = readSettingsFile(rig);
|
||||||
|
|
||||||
|
// Custom keys should be preserved (v1ComplexSettings has 'custom-value' and { nested: true, items: [1, 2, 3] })
|
||||||
|
expect(migratedSettings['myCustomKey']).toBe('custom-value');
|
||||||
|
expect(migratedSettings['anotherCustomSetting']).toEqual({
|
||||||
|
nested: true,
|
||||||
|
items: [1, 2, 3],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -40,6 +40,10 @@ Playwright element screenshot
|
||||||
| WYSIWYG | xterm.js fully renders ANSI, no manual output cleaning needed |
|
| WYSIWYG | xterm.js fully renders ANSI, no manual output cleaning needed |
|
||||||
| Theme Support | Built-in 5 themes (Dracula, One Dark, GitHub Dark, Monokai, Night Owl) |
|
| Theme Support | Built-in 5 themes (Dracula, One Dark, GitHub Dark, Monokai, Night Owl) |
|
||||||
| Full-length | `captureFull()` supports capturing scrollback buffer content |
|
| Full-length | `captureFull()` supports capturing scrollback buffer content |
|
||||||
|
| Streaming Capture | Capture multiple frames at intervals during execution (e.g., progress bars) |
|
||||||
|
| Animated GIF | Auto-generate GIF from streaming frames via ffmpeg |
|
||||||
|
| Early Stop | Streaming stops early if output stabilizes; duplicate frames are skipped |
|
||||||
|
| Auto Cleanup | Output directory is cleared before each run to prevent stale screenshots |
|
||||||
| Deterministic Naming | Screenshot filenames auto-generated by step sequence for easy regression comparison |
|
| Deterministic Naming | Screenshot filenames auto-generated by step sequence for easy regression comparison |
|
||||||
| Batch Execution | `run.ts` executes all scenarios in one command |
|
| Batch Execution | `run.ts` executes all scenarios in one command |
|
||||||
|
|
||||||
|
|
@ -90,8 +94,14 @@ scenarios/screenshots/
|
||||||
02-01.png # Step 2 input state
|
02-01.png # Step 2 input state
|
||||||
02-02.png # Step 2 result
|
02-02.png # Step 2 result
|
||||||
full-flow.png # Final state full-length image
|
full-flow.png # Final state full-length image
|
||||||
context/
|
streaming-shell/
|
||||||
|
01-01.png # Input state
|
||||||
|
01-streaming-01.png # Streaming frame 1
|
||||||
|
01-streaming-02.png # Streaming frame 2
|
||||||
...
|
...
|
||||||
|
01-02.png # Final result
|
||||||
|
streaming.gif # Animated GIF (requires ffmpeg)
|
||||||
|
full-flow.png # Final state full-length image
|
||||||
```
|
```
|
||||||
|
|
||||||
## 4. Position in Testing System
|
## 4. Position in Testing System
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { TerminalCapture, THEMES } from './terminal-capture.js';
|
import { TerminalCapture, THEMES } from './terminal-capture.js';
|
||||||
import { dirname, resolve, isAbsolute } from 'node:path';
|
import { dirname, resolve, isAbsolute, join } from 'node:path';
|
||||||
|
import { execSync } from 'node:child_process';
|
||||||
|
import { writeFileSync, unlinkSync, rmSync, existsSync } from 'node:fs';
|
||||||
|
|
||||||
// ─────────────────────────────────────────────
|
// ─────────────────────────────────────────────
|
||||||
// Schema — Minimal
|
// Schema — Minimal
|
||||||
|
|
@ -29,6 +31,18 @@ export interface FlowStep {
|
||||||
capture?: string;
|
capture?: string;
|
||||||
/** Explicit screenshot: full scrollback buffer long image (standalone capture when no type) */
|
/** Explicit screenshot: full scrollback buffer long image (standalone capture when no type) */
|
||||||
captureFull?: string;
|
captureFull?: string;
|
||||||
|
/**
|
||||||
|
* Streaming capture: capture multiple screenshots during execution at intervals.
|
||||||
|
* Useful for demonstrating real-time output like progress bars.
|
||||||
|
*/
|
||||||
|
streaming?: {
|
||||||
|
/** Delay before starting captures in milliseconds (skip initial waiting phase) */
|
||||||
|
delayMs?: number;
|
||||||
|
/** Interval between captures in milliseconds */
|
||||||
|
intervalMs: number;
|
||||||
|
/** Maximum number of captures */
|
||||||
|
count: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScenarioConfig {
|
export interface ScenarioConfig {
|
||||||
|
|
@ -50,6 +64,8 @@ export interface ScenarioConfig {
|
||||||
};
|
};
|
||||||
/** Screenshot output directory (relative to config file) */
|
/** Screenshot output directory (relative to config file) */
|
||||||
outputDir?: string;
|
outputDir?: string;
|
||||||
|
/** Generate animated GIF from all screenshots in order (default: true) */
|
||||||
|
gif?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─────────────────────────────────────────────
|
// ─────────────────────────────────────────────
|
||||||
|
|
@ -105,6 +121,11 @@ export async function runScenario(
|
||||||
? resolve(basedir, config.outputDir, scenarioDir)
|
? resolve(basedir, config.outputDir, scenarioDir)
|
||||||
: resolve(basedir, 'screenshots', scenarioDir);
|
: resolve(basedir, 'screenshots', scenarioDir);
|
||||||
|
|
||||||
|
// Clean previous screenshots
|
||||||
|
if (existsSync(outputDir)) {
|
||||||
|
rmSync(outputDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`\n${'═'.repeat(60)}`);
|
console.log(`\n${'═'.repeat(60)}`);
|
||||||
console.log(`▶ ${config.name}`);
|
console.log(`▶ ${config.name}`);
|
||||||
console.log('═'.repeat(60));
|
console.log('═'.repeat(60));
|
||||||
|
|
@ -171,13 +192,66 @@ export async function runScenario(
|
||||||
if (autoEnter) {
|
if (autoEnter) {
|
||||||
// ── Auto-press Enter → Wait for stabilization → 02 screenshot ──
|
// ── Auto-press Enter → Wait for stabilization → 02 screenshot ──
|
||||||
await terminal.type('\n');
|
await terminal.type('\n');
|
||||||
console.log(` ⏳ waiting for output to settle...`);
|
|
||||||
await terminal.idle(2000, 60000);
|
|
||||||
console.log(` ✅ settled`);
|
|
||||||
|
|
||||||
const resultName = step.capture ?? `${pad(seq)}-02.png`;
|
// Streaming capture: capture multiple screenshots during execution
|
||||||
console.log(` ${label} 📸 result: ${resultName}`);
|
if (step.streaming) {
|
||||||
screenshots.push(await terminal.capture(resultName));
|
const { delayMs = 0, intervalMs, count } = step.streaming;
|
||||||
|
console.log(
|
||||||
|
` 🎬 streaming capture: ${count} shots @ ${intervalMs}ms intervals${delayMs ? ` (delay ${delayMs}ms)` : ''}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Wait before starting captures (skip initial waiting phase)
|
||||||
|
if (delayMs > 0) {
|
||||||
|
await sleep(delayMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capture frames at intervals (stop early if output stabilizes)
|
||||||
|
const streamingShots: string[] = [];
|
||||||
|
let prevOutputLen = terminal.getRawOutput().length;
|
||||||
|
let stableCount = 0;
|
||||||
|
let shotNum = 0;
|
||||||
|
for (let j = 0; j < count; j++) {
|
||||||
|
await sleep(intervalMs);
|
||||||
|
const curOutputLen = terminal.getRawOutput().length;
|
||||||
|
if (curOutputLen === prevOutputLen) {
|
||||||
|
stableCount++;
|
||||||
|
if (stableCount >= 3) {
|
||||||
|
console.log(
|
||||||
|
` ⏹️ streaming stopped early: output stable for ${stableCount} intervals`,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue; // skip duplicate frame
|
||||||
|
}
|
||||||
|
stableCount = 0;
|
||||||
|
prevOutputLen = curOutputLen;
|
||||||
|
shotNum++;
|
||||||
|
const shotName = `${pad(seq)}-streaming-${pad(shotNum)}.png`;
|
||||||
|
console.log(
|
||||||
|
` 📸 streaming [${shotNum}/${count}]: ${shotName}`,
|
||||||
|
);
|
||||||
|
const shot = await terminal.capture(shotName);
|
||||||
|
streamingShots.push(shot);
|
||||||
|
screenshots.push(shot);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for completion after streaming captures
|
||||||
|
console.log(` ⏳ waiting for output to settle...`);
|
||||||
|
await terminal.idle(2000, 60000);
|
||||||
|
console.log(` ✅ settled`);
|
||||||
|
|
||||||
|
const resultName = step.capture ?? `${pad(seq)}-02.png`;
|
||||||
|
console.log(` ${label} 📸 result: ${resultName}`);
|
||||||
|
screenshots.push(await terminal.capture(resultName));
|
||||||
|
} else {
|
||||||
|
console.log(` ⏳ waiting for output to settle...`);
|
||||||
|
await terminal.idle(2000, 60000);
|
||||||
|
console.log(` ✅ settled`);
|
||||||
|
|
||||||
|
const resultName = step.capture ?? `${pad(seq)}-02.png`;
|
||||||
|
console.log(` ${label} 📸 result: ${resultName}`);
|
||||||
|
screenshots.push(await terminal.capture(resultName));
|
||||||
|
}
|
||||||
|
|
||||||
// full-flow: Only the last type step auto-captures full-length image
|
// full-flow: Only the last type step auto-captures full-length image
|
||||||
const isLastType = !config.flow.slice(i + 1).some((s) => s.type);
|
const isLastType = !config.flow.slice(i + 1).some((s) => s.type);
|
||||||
|
|
@ -245,6 +319,19 @@ export async function runScenario(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate animated GIF from all screenshots (excluding full-flow captures)
|
||||||
|
if (config.gif !== false) {
|
||||||
|
const gifFrames = screenshots.filter(
|
||||||
|
(s) => !s.endsWith('full-flow.png') && !s.includes('-full-'),
|
||||||
|
);
|
||||||
|
if (gifFrames.length > 0) {
|
||||||
|
const gifPath = generateGif(gifFrames, outputDir);
|
||||||
|
if (gifPath) {
|
||||||
|
console.log(` 🎞️ GIF: ${gifPath}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const duration = Date.now() - startTime;
|
const duration = Date.now() - startTime;
|
||||||
console.log(
|
console.log(
|
||||||
`\n ✅ ${config.name} — ${screenshots.length} screenshots, ${(duration / 1000).toFixed(1)}s`,
|
`\n ✅ ${config.name} — ${screenshots.length} screenshots, ${(duration / 1000).toFixed(1)}s`,
|
||||||
|
|
@ -302,3 +389,41 @@ const KEY_MAP: Record<string, string> = {
|
||||||
function resolveKey(key: string): string {
|
function resolveKey(key: string): string {
|
||||||
return KEY_MAP[key] ?? key;
|
return KEY_MAP[key] ?? key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Generate animated GIF from PNG frames using ffmpeg (concat demuxer). */
|
||||||
|
function generateGif(frames: string[], outputDir: string): string | null {
|
||||||
|
if (frames.length === 0) return null;
|
||||||
|
|
||||||
|
const STREAMING_DURATION = 0.3; // 300ms for streaming frames
|
||||||
|
const STATIC_DURATION = 1.0; // 1s for non-streaming and edge frames
|
||||||
|
|
||||||
|
const gifPath = join(outputDir, 'streaming.gif');
|
||||||
|
const listFile = join(outputDir, 'frames.txt');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const lines: string[] = [];
|
||||||
|
for (let i = 0; i < frames.length; i++) {
|
||||||
|
const isStreaming = frames[i].includes('-streaming-');
|
||||||
|
const duration = isStreaming ? STREAMING_DURATION : STATIC_DURATION;
|
||||||
|
lines.push(`file '${resolve(frames[i])}'`, `duration ${duration}`);
|
||||||
|
}
|
||||||
|
// Concat demuxer requires last frame repeated without duration
|
||||||
|
lines.push(`file '${resolve(frames[frames.length - 1])}'`);
|
||||||
|
writeFileSync(listFile, lines.join('\n'));
|
||||||
|
|
||||||
|
execSync(
|
||||||
|
`ffmpeg -y -f concat -safe 0 -i "${listFile}" -vf "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 "${gifPath}"`,
|
||||||
|
{ stdio: 'pipe' },
|
||||||
|
);
|
||||||
|
return gifPath;
|
||||||
|
} catch {
|
||||||
|
console.log(' ⚠️ GIF generation requires ffmpeg');
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
unlinkSync(listFile);
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
import type { ScenarioConfig } from '../scenario-runner.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the message component refactoring for PR #2120.
|
||||||
|
* Captures info, warning, and error messages to verify proper icon/prefix display.
|
||||||
|
*
|
||||||
|
* This scenario tests:
|
||||||
|
* - Info message prefix (● filled circle)
|
||||||
|
* - Error message prefix (✕)
|
||||||
|
* - User message prefix (>)
|
||||||
|
* - Assistant message prefix (✦)
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'message-components',
|
||||||
|
spawn: ['node', 'dist/cli.js', '--yolo'],
|
||||||
|
terminal: { title: 'qwen-code', cwd: '../../..' },
|
||||||
|
flow: [
|
||||||
|
// Test info message via /skills command (instant, no streaming)
|
||||||
|
{ type: '/skills' },
|
||||||
|
// Test error message via unknown skill (instant, no streaming)
|
||||||
|
{ type: '/skills nonexistent-skill-xyz' },
|
||||||
|
// Test user and assistant messages (streams from LLM)
|
||||||
|
{
|
||||||
|
type: 'Say "Hello, this is a test of message prefixes!" and nothing else.',
|
||||||
|
streaming: {
|
||||||
|
delayMs: 3000,
|
||||||
|
intervalMs: 1000,
|
||||||
|
count: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} satisfies ScenarioConfig;
|
||||||
16
integration-tests/terminal-capture/scenarios/progress.sh
Executable file
16
integration-tests/terminal-capture/scenarios/progress.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Progress bar script that overwrites the same line using \r
|
||||||
|
# Tests PTY's ability to handle carriage return / cursor movement
|
||||||
|
|
||||||
|
total=20
|
||||||
|
for ((i = 1; i <= total; i++)); do
|
||||||
|
pct=$((i * 100 / total))
|
||||||
|
filled=$((pct / 5))
|
||||||
|
empty=$((20 - filled))
|
||||||
|
bar=$(printf '%0.s#' $(seq 1 $filled 2>/dev/null))
|
||||||
|
space=$(printf '%0.s-' $(seq 1 $empty 2>/dev/null))
|
||||||
|
printf "\r[%s%s] %3d%% (%d/%d)" "$bar" "$space" "$pct" "$i" "$total"
|
||||||
|
sleep 0.5
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
echo "Done!"
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
import type { ScenarioConfig } from '../scenario-runner.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: '/qc:code-review',
|
||||||
|
spawn: ['node', 'dist/cli.js', '--yolo'],
|
||||||
|
terminal: { title: 'qwen-code', cwd: '../../..' },
|
||||||
|
flow: [
|
||||||
|
{
|
||||||
|
type: '/qc:code-review 2117',
|
||||||
|
streaming: {
|
||||||
|
delayMs: 10000, // Wait for initial model thinking/approval
|
||||||
|
intervalMs: 800, // Capture every 800ms
|
||||||
|
count: 30, // Max 30 captures
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} satisfies ScenarioConfig;
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
import type { ScenarioConfig } from '../scenario-runner.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstrates streaming capture with the /insight command.
|
||||||
|
* The insight command analyzes the codebase and streams results,
|
||||||
|
* making it ideal for demonstrating streaming capture.
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'streaming-insight',
|
||||||
|
spawn: ['node', 'dist/cli.js', '--yolo'],
|
||||||
|
terminal: { title: 'qwen-code', cwd: '../../..' },
|
||||||
|
flow: [
|
||||||
|
{
|
||||||
|
type: '/insight',
|
||||||
|
// /insight takes time to analyze the codebase and streams results
|
||||||
|
// Capture frames during the analysis to show real-time progress
|
||||||
|
streaming: {
|
||||||
|
intervalMs: 5000, // Capture every 5 seconds
|
||||||
|
count: 50, // Up to 250 seconds of capture
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} satisfies ScenarioConfig;
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
import type { ScenarioConfig } from '../scenario-runner.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstrates streaming shell execution output with PTY enabled by default.
|
||||||
|
* Tests the render throttle behavior and progress bar handling.
|
||||||
|
* Captures multiple screenshots during execution to show real-time output.
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'streaming-shell',
|
||||||
|
spawn: ['node', 'dist/cli.js', '--yolo'],
|
||||||
|
terminal: { title: 'qwen-code', cwd: '../../..' },
|
||||||
|
flow: [
|
||||||
|
{
|
||||||
|
type: 'Run this command: bash integration-tests/terminal-capture/scenarios/progress.sh',
|
||||||
|
// Capture 20 screenshots at 500ms intervals during execution
|
||||||
|
// The progress.sh script takes ~10 seconds (20 iterations * 0.5s each)
|
||||||
|
streaming: {
|
||||||
|
delayMs: 7000,
|
||||||
|
intervalMs: 500,
|
||||||
|
count: 20,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} satisfies ScenarioConfig;
|
||||||
|
|
@ -293,7 +293,7 @@ export class TerminalCapture {
|
||||||
await this.page.addScriptTag({ path: join(xtermDir, 'lib', 'xterm.js') });
|
await this.page.addScriptTag({ path: join(xtermDir, 'lib', 'xterm.js') });
|
||||||
|
|
||||||
// 4. Create xterm Terminal instance inside the page
|
// 4. Create xterm Terminal instance inside the page
|
||||||
|
|
||||||
await this.page.evaluate(
|
await this.page.evaluate(
|
||||||
({ cols, rows, theme, fontSize, fontFamily }) => {
|
({ cols, rows, theme, fontSize, fontFamily }) => {
|
||||||
const W = window as unknown as Record<string, unknown>;
|
const W = window as unknown as Record<string, unknown>;
|
||||||
|
|
@ -312,7 +312,7 @@ export class TerminalCapture {
|
||||||
});
|
});
|
||||||
|
|
||||||
const container = document.getElementById('xterm-container')!;
|
const container = document.getElementById('xterm-container')!;
|
||||||
|
|
||||||
term.open(container);
|
term.open(container);
|
||||||
|
|
||||||
// Expose to outer scope
|
// Expose to outer scope
|
||||||
|
|
|
||||||
594
package-lock.json
generated
594
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@qwen-code/qwen-code",
|
"name": "@qwen-code/qwen-code",
|
||||||
"version": "0.10.5",
|
"version": "0.12.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@qwen-code/qwen-code",
|
"name": "@qwen-code/qwen-code",
|
||||||
"version": "0.10.5",
|
"version": "0.12.0",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
"@vitest/coverage-v8": "^3.1.1",
|
"@vitest/coverage-v8": "^3.1.1",
|
||||||
"@vitest/eslint-plugin": "^1.3.4",
|
"@vitest/eslint-plugin": "^1.3.4",
|
||||||
|
"@xterm/xterm": "^6.0.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"esbuild": "^0.25.0",
|
"esbuild": "^0.25.0",
|
||||||
"eslint": "^9.24.0",
|
"eslint": "^9.24.0",
|
||||||
|
|
@ -2997,6 +2998,10 @@
|
||||||
"resolved": "packages/sdk-typescript",
|
"resolved": "packages/sdk-typescript",
|
||||||
"link": true
|
"link": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@qwen-code/web-templates": {
|
||||||
|
"resolved": "packages/web-templates",
|
||||||
|
"link": true
|
||||||
|
},
|
||||||
"node_modules/@qwen-code/webui": {
|
"node_modules/@qwen-code/webui": {
|
||||||
"resolved": "packages/webui",
|
"resolved": "packages/webui",
|
||||||
"link": true
|
"link": true
|
||||||
|
|
@ -4517,6 +4522,13 @@
|
||||||
"kleur": "^3.0.3"
|
"kleur": "^3.0.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/prop-types": {
|
||||||
|
"version": "15.7.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz",
|
||||||
|
"integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/qrcode-terminal": {
|
"node_modules/@types/qrcode-terminal": {
|
||||||
"version": "0.12.2",
|
"version": "0.12.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/qrcode-terminal/-/qrcode-terminal-0.12.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/qrcode-terminal/-/qrcode-terminal-0.12.2.tgz",
|
||||||
|
|
@ -5618,6 +5630,16 @@
|
||||||
"integrity": "sha512-5xXB7kdQlFBP82ViMJTwwEc3gKCLGKR/eoxQm4zge7GPBl86tCdI0IdPJjoKd8mUSFXz5V7i/25sfsEkP4j46g==",
|
"integrity": "sha512-5xXB7kdQlFBP82ViMJTwwEc3gKCLGKR/eoxQm4zge7GPBl86tCdI0IdPJjoKd8mUSFXz5V7i/25sfsEkP4j46g==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/@xterm/xterm": {
|
||||||
|
"version": "6.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-6.0.0.tgz",
|
||||||
|
"integrity": "sha512-TQwDdQGtwwDt+2cgKDLn0IRaSxYu1tSUjgKarSDkUM0ZNiSRXFpjxEsvc/Zgc5kq5omJ+V0a8/kIM2WD3sMOYg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"workspaces": [
|
||||||
|
"addons/*"
|
||||||
|
]
|
||||||
|
},
|
||||||
"node_modules/abort-controller": {
|
"node_modules/abort-controller": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||||
|
|
@ -18769,12 +18791,13 @@
|
||||||
},
|
},
|
||||||
"packages/cli": {
|
"packages/cli": {
|
||||||
"name": "@qwen-code/qwen-code",
|
"name": "@qwen-code/qwen-code",
|
||||||
"version": "0.10.5",
|
"version": "0.12.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@google/genai": "1.30.0",
|
"@google/genai": "1.30.0",
|
||||||
"@iarna/toml": "^2.2.5",
|
"@iarna/toml": "^2.2.5",
|
||||||
"@modelcontextprotocol/sdk": "^1.25.1",
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
||||||
"@qwen-code/qwen-code-core": "file:../core",
|
"@qwen-code/qwen-code-core": "file:../core",
|
||||||
|
"@qwen-code/web-templates": "file:../web-templates",
|
||||||
"@types/update-notifier": "^6.0.8",
|
"@types/update-notifier": "^6.0.8",
|
||||||
"ansi-regex": "^6.2.2",
|
"ansi-regex": "^6.2.2",
|
||||||
"command-exists": "^1.2.9",
|
"command-exists": "^1.2.9",
|
||||||
|
|
@ -18790,6 +18813,7 @@
|
||||||
"ink-spinner": "^5.0.0",
|
"ink-spinner": "^5.0.0",
|
||||||
"lowlight": "^3.3.0",
|
"lowlight": "^3.3.0",
|
||||||
"open": "^10.1.2",
|
"open": "^10.1.2",
|
||||||
|
"p-limit": "^7.3.0",
|
||||||
"prompts": "^2.4.2",
|
"prompts": "^2.4.2",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
|
|
@ -19265,6 +19289,21 @@
|
||||||
"url": "https://opencollective.com/node-fetch"
|
"url": "https://opencollective.com/node-fetch"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"packages/cli/node_modules/p-limit": {
|
||||||
|
"version": "7.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-7.3.0.tgz",
|
||||||
|
"integrity": "sha512-7cIXg/Z0M5WZRblrsOla88S4wAK+zOQQWeBYfV3qJuJXMr+LnbYjaadrFaS0JILfEDPVqHyKnZ1Z/1d6J9VVUw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"yocto-queue": "^1.2.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"packages/cli/node_modules/qs": {
|
"packages/cli/node_modules/qs": {
|
||||||
"version": "6.14.0",
|
"version": "6.14.0",
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz",
|
||||||
|
|
@ -19395,9 +19434,21 @@
|
||||||
"node": ">=18.17"
|
"node": ">=18.17"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"packages/cli/node_modules/yocto-queue": {
|
||||||
|
"version": "1.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.2.tgz",
|
||||||
|
"integrity": "sha512-4LCcse/U2MHZ63HAJVE+v71o7yOdIe4cZ70Wpf8D/IyjDKYQLV5GD46B+hSTjJsvV5PztjvHoU580EftxjDZFQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.20"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"packages/core": {
|
"packages/core": {
|
||||||
"name": "@qwen-code/qwen-code-core",
|
"name": "@qwen-code/qwen-code-core",
|
||||||
"version": "0.10.5",
|
"version": "0.12.0",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@anthropic-ai/sdk": "^0.36.1",
|
"@anthropic-ai/sdk": "^0.36.1",
|
||||||
|
|
@ -19431,6 +19482,7 @@
|
||||||
"google-auth-library": "^10.5.0",
|
"google-auth-library": "^10.5.0",
|
||||||
"html-to-text": "^9.0.5",
|
"html-to-text": "^9.0.5",
|
||||||
"https-proxy-agent": "^7.0.6",
|
"https-proxy-agent": "^7.0.6",
|
||||||
|
"iconv-lite": "^0.6.3",
|
||||||
"ignore": "^7.0.0",
|
"ignore": "^7.0.0",
|
||||||
"jsonrepair": "^3.13.0",
|
"jsonrepair": "^3.13.0",
|
||||||
"marked": "^15.0.12",
|
"marked": "^15.0.12",
|
||||||
|
|
@ -22877,7 +22929,7 @@
|
||||||
},
|
},
|
||||||
"packages/test-utils": {
|
"packages/test-utils": {
|
||||||
"name": "@qwen-code/qwen-code-test-utils",
|
"name": "@qwen-code/qwen-code-test-utils",
|
||||||
"version": "0.10.5",
|
"version": "0.12.0",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
@ -22889,7 +22941,7 @@
|
||||||
},
|
},
|
||||||
"packages/vscode-ide-companion": {
|
"packages/vscode-ide-companion": {
|
||||||
"name": "qwen-code-vscode-ide-companion",
|
"name": "qwen-code-vscode-ide-companion",
|
||||||
"version": "0.10.5",
|
"version": "0.12.0",
|
||||||
"license": "LICENSE",
|
"license": "LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.25.1",
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
||||||
|
|
@ -23134,9 +23186,537 @@
|
||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"packages/web-templates": {
|
||||||
|
"name": "@qwen-code/web-templates",
|
||||||
|
"version": "0.12.0",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "^18.2.0",
|
||||||
|
"@types/react-dom": "^18.2.0",
|
||||||
|
"@vitejs/plugin-react": "^4.2.0",
|
||||||
|
"autoprefixer": "^10.4.22",
|
||||||
|
"postcss": "^8.5.6",
|
||||||
|
"tailwindcss": "^3.4.18",
|
||||||
|
"typescript": "^5.3.3",
|
||||||
|
"vite": "^5.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/aix-ppc64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==",
|
||||||
|
"cpu": [
|
||||||
|
"ppc64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"aix"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/android-arm": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg==",
|
||||||
|
"cpu": [
|
||||||
|
"arm"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"android"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/android-arm64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-c0uX9VAUBQ7dTDCjq+wdyGLowMdtR/GoC2U5IYk/7D1H1JYC0qseD7+11iMP2mRLN9RcCMRcjC4YMclCzGwS/A==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"android"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/android-x64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-D7aPRUUNHRBwHxzxRvp856rjUHRFW1SdQATKXH2hqA0kAZb1hKmi02OpYRacl0TxIGz/ZmXWlbZgjwWYaCakTA==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"android"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/darwin-arm64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/darwin-x64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-se/JjF8NlmKVG4kNIuyWMV/22ZaerB+qaSi5MdrXtd6R08kvs2qCN4C09miupktDitvh8jRFflwGFBQcxZRjbw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/freebsd-arm64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-5JcRxxRDUJLX8JXp/wcBCy3pENnCgBR9bN6JsY4OmhfUtIHe3ZW0mawA7+RDAcMLrMIZaf03NlQiX9DGyB8h4g==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"freebsd"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/freebsd-x64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-J95kNBj1zkbMXtHVH29bBriQygMXqoVQOQYA+ISs0/2l3T9/kj42ow2mpqerRBxDJnmkUDCaQT/dfNXWX/ZZCQ==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"freebsd"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/linux-arm": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-bPb5AHZtbeNGjCKVZ9UGqGwo8EUu4cLq68E95A53KlxAPRmUyYv2D6F0uUI65XisGOL1hBP5mTronbgo+0bFcA==",
|
||||||
|
"cpu": [
|
||||||
|
"arm"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/linux-arm64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-ibKvmyYzKsBeX8d8I7MH/TMfWDXBF3db4qM6sy+7re0YXya+K1cem3on9XgdT2EQGMu4hQyZhan7TeQ8XkGp4Q==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/linux-ia32": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-YvjXDqLRqPDl2dvRODYmmhz4rPeVKYvppfGYKSNGdyZkA01046pLWyRKKI3ax8fbJoK5QbxblURkwK/MWY18Tg==",
|
||||||
|
"cpu": [
|
||||||
|
"ia32"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/linux-loong64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-uHf1BmMG8qEvzdrzAqg2SIG/02+4/DHB6a9Kbya0XDvwDEKCoC8ZRWI5JJvNdUjtciBGFQ5PuBlpEOXQj+JQSg==",
|
||||||
|
"cpu": [
|
||||||
|
"loong64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/linux-mips64el": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-IajOmO+KJK23bj52dFSNCMsz1QP1DqM6cwLUv3W1QwyxkyIWecfafnI555fvSGqEKwjMXVLokcV5ygHW5b3Jbg==",
|
||||||
|
"cpu": [
|
||||||
|
"mips64el"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/linux-ppc64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-1hHV/Z4OEfMwpLO8rp7CvlhBDnjsC3CttJXIhBi+5Aj5r+MBvy4egg7wCbe//hSsT+RvDAG7s81tAvpL2XAE4w==",
|
||||||
|
"cpu": [
|
||||||
|
"ppc64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/linux-riscv64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-2HdXDMd9GMgTGrPWnJzP2ALSokE/0O5HhTUvWIbD3YdjME8JwvSCnNGBnTThKGEB91OZhzrJ4qIIxk/SBmyDDA==",
|
||||||
|
"cpu": [
|
||||||
|
"riscv64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/linux-s390x": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-zus5sxzqBJD3eXxwvjN1yQkRepANgxE9lgOW2qLnmr8ikMTphkjgXu1HR01K4FJg8h1kEEDAqDcZQtbrRnB41A==",
|
||||||
|
"cpu": [
|
||||||
|
"s390x"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/linux-x64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/netbsd-x64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-Woi2MXzXjMULccIwMnLciyZH4nCIMpWQAs049KEeMvOcNADVxo0UBIQPfSmxB3CWKedngg7sWZdLvLczpe0tLg==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"netbsd"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/openbsd-x64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-HLNNw99xsvx12lFBUwoT8EVCsSvRNDVxNpjZ7bPn947b8gJPzeHWyNVhFsaerc0n3TsbOINvRP2byTZ5LKezow==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"openbsd"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/sunos-x64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-6+gjmFpfy0BHU5Tpptkuh8+uw3mnrvgs+dSPQXQOv3ekbordwnzTVEb4qnIvQcYXq6gzkyTnoZ9dZG+D4garKg==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"sunos"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/win32-arm64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-Z0gOTd75VvXqyq7nsl93zwahcTROgqvuAcYDUr+vOv8uHhNSKROyU961kgtCD1e95IqPKSQKH7tBTslnS3tA8A==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/win32-ia32": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-SWXFF1CL2RVNMaVs+BBClwtfZSvDgtL//G/smwAc5oVK/UPu2Gu9tIaRgFmYFFKrmg3SyAjSrElf0TiJ1v8fYA==",
|
||||||
|
"cpu": [
|
||||||
|
"ia32"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@esbuild/win32-x64": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@types/react": {
|
||||||
|
"version": "18.3.28",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.28.tgz",
|
||||||
|
"integrity": "sha512-z9VXpC7MWrhfWipitjNdgCauoMLRdIILQsAEV+ZesIzBq/oUlxk0m3ApZuMFCXdnS4U7KrI+l3WRUEGQ8K1QKw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/prop-types": "*",
|
||||||
|
"csstype": "^3.2.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/@types/react-dom": {
|
||||||
|
"version": "18.3.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.7.tgz",
|
||||||
|
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "^18.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/esbuild": {
|
||||||
|
"version": "0.21.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz",
|
||||||
|
"integrity": "sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw==",
|
||||||
|
"dev": true,
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"esbuild": "bin/esbuild"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@esbuild/aix-ppc64": "0.21.5",
|
||||||
|
"@esbuild/android-arm": "0.21.5",
|
||||||
|
"@esbuild/android-arm64": "0.21.5",
|
||||||
|
"@esbuild/android-x64": "0.21.5",
|
||||||
|
"@esbuild/darwin-arm64": "0.21.5",
|
||||||
|
"@esbuild/darwin-x64": "0.21.5",
|
||||||
|
"@esbuild/freebsd-arm64": "0.21.5",
|
||||||
|
"@esbuild/freebsd-x64": "0.21.5",
|
||||||
|
"@esbuild/linux-arm": "0.21.5",
|
||||||
|
"@esbuild/linux-arm64": "0.21.5",
|
||||||
|
"@esbuild/linux-ia32": "0.21.5",
|
||||||
|
"@esbuild/linux-loong64": "0.21.5",
|
||||||
|
"@esbuild/linux-mips64el": "0.21.5",
|
||||||
|
"@esbuild/linux-ppc64": "0.21.5",
|
||||||
|
"@esbuild/linux-riscv64": "0.21.5",
|
||||||
|
"@esbuild/linux-s390x": "0.21.5",
|
||||||
|
"@esbuild/linux-x64": "0.21.5",
|
||||||
|
"@esbuild/netbsd-x64": "0.21.5",
|
||||||
|
"@esbuild/openbsd-x64": "0.21.5",
|
||||||
|
"@esbuild/sunos-x64": "0.21.5",
|
||||||
|
"@esbuild/win32-arm64": "0.21.5",
|
||||||
|
"@esbuild/win32-ia32": "0.21.5",
|
||||||
|
"@esbuild/win32-x64": "0.21.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packages/web-templates/node_modules/vite": {
|
||||||
|
"version": "5.4.21",
|
||||||
|
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.21.tgz",
|
||||||
|
"integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"esbuild": "^0.21.3",
|
||||||
|
"postcss": "^8.4.43",
|
||||||
|
"rollup": "^4.20.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"vite": "bin/vite.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.0.0 || >=20.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/vitejs/vite?sponsor=1"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"fsevents": "~2.3.3"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/node": "^18.0.0 || >=20.0.0",
|
||||||
|
"less": "*",
|
||||||
|
"lightningcss": "^1.21.0",
|
||||||
|
"sass": "*",
|
||||||
|
"sass-embedded": "*",
|
||||||
|
"stylus": "*",
|
||||||
|
"sugarss": "*",
|
||||||
|
"terser": "^5.4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/node": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"less": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"lightningcss": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"sass": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"sass-embedded": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"stylus": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"sugarss": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"terser": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"packages/webui": {
|
"packages/webui": {
|
||||||
"name": "@qwen-code/webui",
|
"name": "@qwen-code/webui",
|
||||||
"version": "0.10.5",
|
"version": "0.12.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"markdown-it": "^14.1.0"
|
"markdown-it": "^14.1.0"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@qwen-code/qwen-code",
|
"name": "@qwen-code/qwen-code",
|
||||||
"version": "0.10.5",
|
"version": "0.12.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.0.0"
|
"node": ">=20.0.0"
|
||||||
},
|
},
|
||||||
|
|
@ -13,13 +13,14 @@
|
||||||
"url": "git+https://github.com/QwenLM/qwen-code.git"
|
"url": "git+https://github.com/QwenLM/qwen-code.git"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"sandboxImageUri": "ghcr.io/qwenlm/qwen-code:0.10.5"
|
"sandboxImageUri": "ghcr.io/qwenlm/qwen-code:0.12.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cross-env node scripts/start.js",
|
"start": "cross-env node scripts/start.js",
|
||||||
"dev": "node scripts/dev.js",
|
"dev": "node scripts/dev.js",
|
||||||
"debug": "cross-env DEBUG=1 node --inspect-brk scripts/start.js",
|
"debug": "cross-env DEBUG=1 node --inspect-brk scripts/start.js",
|
||||||
"generate": "node scripts/generate-git-commit-info.js",
|
"generate": "node scripts/generate-git-commit-info.js",
|
||||||
|
"generate:settings-schema": "tsx scripts/generate-settings-schema.ts",
|
||||||
"build": "node scripts/build.js",
|
"build": "node scripts/build.js",
|
||||||
"build-and-start": "npm run build && npm run start",
|
"build-and-start": "npm run build && npm run start",
|
||||||
"build:vscode": "node scripts/build_vscode_companion.js",
|
"build:vscode": "node scripts/build_vscode_companion.js",
|
||||||
|
|
@ -50,7 +51,7 @@
|
||||||
"typecheck": "npm run typecheck --workspaces --if-present",
|
"typecheck": "npm run typecheck --workspaces --if-present",
|
||||||
"check-i18n": "npm run check-i18n --workspace=packages/cli",
|
"check-i18n": "npm run check-i18n --workspace=packages/cli",
|
||||||
"preflight": "npm run clean && npm ci && npm run format && npm run lint:ci && npm run build && npm run typecheck && npm run test:ci",
|
"preflight": "npm run clean && npm ci && npm run format && npm run lint:ci && npm run build && npm run typecheck && npm run test:ci",
|
||||||
"prepare": "husky && npm run bundle",
|
"prepare": "husky && npm run build && npm run bundle",
|
||||||
"prepare:package": "node scripts/prepare-package.js",
|
"prepare:package": "node scripts/prepare-package.js",
|
||||||
"release:version": "node scripts/version.js",
|
"release:version": "node scripts/version.js",
|
||||||
"telemetry": "node scripts/telemetry.js",
|
"telemetry": "node scripts/telemetry.js",
|
||||||
|
|
@ -84,6 +85,7 @@
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
"@vitest/coverage-v8": "^3.1.1",
|
"@vitest/coverage-v8": "^3.1.1",
|
||||||
"@vitest/eslint-plugin": "^1.3.4",
|
"@vitest/eslint-plugin": "^1.3.4",
|
||||||
|
"@xterm/xterm": "^6.0.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"esbuild": "^0.25.0",
|
"esbuild": "^0.25.0",
|
||||||
"eslint": "^9.24.0",
|
"eslint": "^9.24.0",
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
import { access, readdir } from 'node:fs/promises';
|
|
||||||
import { dirname, join } from 'node:path';
|
|
||||||
import { spawn } from 'node:child_process';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
import process from 'node:process';
|
|
||||||
|
|
||||||
const assetsDir = dirname(fileURLToPath(import.meta.url));
|
|
||||||
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
||||||
|
|
||||||
const entries = await readdir(assetsDir, { withFileTypes: true });
|
|
||||||
const assetBuilds = [];
|
|
||||||
|
|
||||||
for (const entry of entries) {
|
|
||||||
if (!entry.isDirectory()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const assetPath = join(assetsDir, entry.name);
|
|
||||||
const buildPath = join(assetPath, 'build.mjs');
|
|
||||||
const packageJsonPath = join(assetPath, 'package.json');
|
|
||||||
let hasBuild = false;
|
|
||||||
let hasPackageJson = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await access(buildPath);
|
|
||||||
hasBuild = true;
|
|
||||||
} catch {
|
|
||||||
// ignore missing build.mjs
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await access(packageJsonPath);
|
|
||||||
hasPackageJson = true;
|
|
||||||
} catch {
|
|
||||||
// ignore missing package.json
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasBuild || hasPackageJson) {
|
|
||||||
assetBuilds.push({
|
|
||||||
name: entry.name,
|
|
||||||
assetPath,
|
|
||||||
buildPath,
|
|
||||||
useNpm: hasPackageJson,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (assetBuilds.length === 0) {
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const runCommand = ({ command, args, cwd, label }) =>
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
const child = spawn(command, args, {
|
|
||||||
cwd,
|
|
||||||
stdio: 'inherit',
|
|
||||||
shell: process.platform === 'win32',
|
|
||||||
});
|
|
||||||
|
|
||||||
child.on('error', reject);
|
|
||||||
child.on('exit', (code) => {
|
|
||||||
if (code === 0) {
|
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
reject(new Error(`${label} failed for ${cwd}.`));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const runBuild = async (asset) => {
|
|
||||||
if (asset.useNpm) {
|
|
||||||
await runCommand({
|
|
||||||
command: npmCommand,
|
|
||||||
args: ['install'],
|
|
||||||
cwd: asset.assetPath,
|
|
||||||
label: `npm install`,
|
|
||||||
});
|
|
||||||
|
|
||||||
await runCommand({
|
|
||||||
command: npmCommand,
|
|
||||||
args: ['run', 'build'],
|
|
||||||
cwd: asset.assetPath,
|
|
||||||
label: `npm run build`,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await runCommand({
|
|
||||||
command: process.execPath,
|
|
||||||
args: [asset.buildPath],
|
|
||||||
cwd: asset.assetPath,
|
|
||||||
label: `Node build`,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
await Promise.all(assetBuilds.map((asset) => runBuild(asset)));
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@qwen-code/qwen-code",
|
"name": "@qwen-code/qwen-code",
|
||||||
"version": "0.10.5",
|
"version": "0.12.0",
|
||||||
"description": "Qwen Code",
|
"description": "Qwen Code",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
@ -19,8 +19,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:assets": "node ./assets/parallel-build.mjs",
|
"build": "node ../../scripts/build_package.js",
|
||||||
"build": "npm run build:assets && node ../../scripts/build_package.js",
|
|
||||||
"start": "node dist/index.js",
|
"start": "node dist/index.js",
|
||||||
"debug": "node --inspect-brk dist/index.js",
|
"debug": "node --inspect-brk dist/index.js",
|
||||||
"lint": "eslint . --ext .ts,.tsx",
|
"lint": "eslint . --ext .ts,.tsx",
|
||||||
|
|
@ -34,13 +33,14 @@
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"config": {
|
"config": {
|
||||||
"sandboxImageUri": "ghcr.io/qwenlm/qwen-code:0.10.5"
|
"sandboxImageUri": "ghcr.io/qwenlm/qwen-code:0.12.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@google/genai": "1.30.0",
|
"@google/genai": "1.30.0",
|
||||||
"@iarna/toml": "^2.2.5",
|
"@iarna/toml": "^2.2.5",
|
||||||
"@modelcontextprotocol/sdk": "^1.25.1",
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
||||||
"@qwen-code/qwen-code-core": "file:../core",
|
"@qwen-code/qwen-code-core": "file:../core",
|
||||||
|
"@qwen-code/web-templates": "file:../web-templates",
|
||||||
"@types/update-notifier": "^6.0.8",
|
"@types/update-notifier": "^6.0.8",
|
||||||
"ansi-regex": "^6.2.2",
|
"ansi-regex": "^6.2.2",
|
||||||
"command-exists": "^1.2.9",
|
"command-exists": "^1.2.9",
|
||||||
|
|
@ -56,6 +56,7 @@
|
||||||
"ink-spinner": "^5.0.0",
|
"ink-spinner": "^5.0.0",
|
||||||
"lowlight": "^3.3.0",
|
"lowlight": "^3.3.0",
|
||||||
"open": "^10.1.2",
|
"open": "^10.1.2",
|
||||||
|
"p-limit": "^7.3.0",
|
||||||
"prompts": "^2.4.2",
|
"prompts": "^2.4.2",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,14 @@ export class AgentSideConnection implements Client {
|
||||||
const validatedParams = schema.setModelRequestSchema.parse(params);
|
const validatedParams = schema.setModelRequestSchema.parse(params);
|
||||||
return agent.setModel(validatedParams);
|
return agent.setModel(validatedParams);
|
||||||
}
|
}
|
||||||
|
case schema.AGENT_METHODS.session_set_config_option: {
|
||||||
|
if (!agent.setConfigOption) {
|
||||||
|
throw RequestError.methodNotFound();
|
||||||
|
}
|
||||||
|
const validatedParams =
|
||||||
|
schema.setConfigOptionRequestSchema.parse(params);
|
||||||
|
return agent.setConfigOption(validatedParams);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw RequestError.methodNotFound(method);
|
throw RequestError.methodNotFound(method);
|
||||||
}
|
}
|
||||||
|
|
@ -489,4 +497,7 @@ export interface Agent {
|
||||||
cancel(params: schema.CancelNotification): Promise<void>;
|
cancel(params: schema.CancelNotification): Promise<void>;
|
||||||
setMode?(params: schema.SetModeRequest): Promise<schema.SetModeResponse>;
|
setMode?(params: schema.SetModeRequest): Promise<schema.SetModeResponse>;
|
||||||
setModel?(params: schema.SetModelRequest): Promise<schema.SetModelResponse>;
|
setModel?(params: schema.SetModelRequest): Promise<schema.SetModelResponse>;
|
||||||
|
setConfigOption?(
|
||||||
|
params: schema.SetConfigOptionRequest,
|
||||||
|
): Promise<schema.SetConfigOptionResponse>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import {
|
||||||
type ConversationRecord,
|
type ConversationRecord,
|
||||||
type DeviceAuthorizationData,
|
type DeviceAuthorizationData,
|
||||||
} from '@qwen-code/qwen-code-core';
|
} from '@qwen-code/qwen-code-core';
|
||||||
import type { ApprovalModeValue } from './schema.js';
|
import type { ApprovalModeValue, ConfigOption } from './schema.js';
|
||||||
import * as acp from './acp.js';
|
import * as acp from './acp.js';
|
||||||
import { buildAuthMethods } from './authMethods.js';
|
import { buildAuthMethods } from './authMethods.js';
|
||||||
import { AcpFileSystemService } from './service/filesystem.js';
|
import { AcpFileSystemService } from './service/filesystem.js';
|
||||||
|
|
@ -107,6 +107,10 @@ class GeminiAgent {
|
||||||
audio: true,
|
audio: true,
|
||||||
embeddedContext: true,
|
embeddedContext: true,
|
||||||
},
|
},
|
||||||
|
sessionCapabilities: {
|
||||||
|
list: {},
|
||||||
|
resume: {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -153,10 +157,14 @@ class GeminiAgent {
|
||||||
|
|
||||||
const session = await this.createAndStoreSession(config);
|
const session = await this.createAndStoreSession(config);
|
||||||
const availableModels = this.buildAvailableModels(config);
|
const availableModels = this.buildAvailableModels(config);
|
||||||
|
const modesData = this.buildModesData(config);
|
||||||
|
const configOptions = this.buildConfigOptions(config);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sessionId: session.getId(),
|
sessionId: session.getId(),
|
||||||
models: availableModels,
|
models: availableModels,
|
||||||
|
modes: modesData,
|
||||||
|
configOptions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,25 +247,31 @@ class GeminiAgent {
|
||||||
async listSessions(
|
async listSessions(
|
||||||
params: acp.ListSessionsRequest,
|
params: acp.ListSessionsRequest,
|
||||||
): Promise<acp.ListSessionsResponse> {
|
): Promise<acp.ListSessionsResponse> {
|
||||||
const sessionService = new SessionService(params.cwd);
|
const cwd = params.cwd || process.cwd();
|
||||||
|
const sessionService = new SessionService(cwd);
|
||||||
const result = await sessionService.listSessions({
|
const result = await sessionService.listSessions({
|
||||||
cursor: params.cursor,
|
cursor: params.cursor,
|
||||||
size: params.size,
|
size: params.size,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const sessions = result.items.map((item) => ({
|
||||||
|
cwd: item.cwd,
|
||||||
|
filePath: item.filePath,
|
||||||
|
gitBranch: item.gitBranch,
|
||||||
|
messageCount: item.messageCount,
|
||||||
|
mtime: item.mtime,
|
||||||
|
prompt: item.prompt,
|
||||||
|
sessionId: item.sessionId,
|
||||||
|
startTime: item.startTime,
|
||||||
|
title: item.prompt || '(session)',
|
||||||
|
updatedAt: new Date(item.mtime).toISOString(),
|
||||||
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items: result.items.map((item) => ({
|
|
||||||
sessionId: item.sessionId,
|
|
||||||
cwd: item.cwd,
|
|
||||||
startTime: item.startTime,
|
|
||||||
mtime: item.mtime,
|
|
||||||
prompt: item.prompt,
|
|
||||||
gitBranch: item.gitBranch,
|
|
||||||
filePath: item.filePath,
|
|
||||||
messageCount: item.messageCount,
|
|
||||||
})),
|
|
||||||
nextCursor: result.nextCursor,
|
|
||||||
hasMore: result.hasMore,
|
hasMore: result.hasMore,
|
||||||
|
items: sessions,
|
||||||
|
nextCursor: result.nextCursor,
|
||||||
|
sessions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,6 +295,104 @@ class GeminiAgent {
|
||||||
return await session.setModel(params);
|
return await session.setModel(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setConfigOption(
|
||||||
|
params: acp.SetConfigOptionRequest,
|
||||||
|
): Promise<acp.SetConfigOptionResponse> {
|
||||||
|
const { sessionId, configId, value } = params;
|
||||||
|
|
||||||
|
// Get the session's config
|
||||||
|
const session = this.sessions.get(sessionId);
|
||||||
|
if (!session) {
|
||||||
|
throw acp.RequestError.invalidParams(
|
||||||
|
`Session not found for id: ${sessionId}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (configId) {
|
||||||
|
case 'mode': {
|
||||||
|
await this.setMode({
|
||||||
|
sessionId,
|
||||||
|
modeId: value as ApprovalModeValue,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'model': {
|
||||||
|
await this.setModel({
|
||||||
|
sessionId,
|
||||||
|
modelId: value as string,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw acp.RequestError.invalidParams(
|
||||||
|
`Unsupported configId: ${configId}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return all config options with current values
|
||||||
|
return {
|
||||||
|
configOptions: this.buildConfigOptions(session.getConfig()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildConfigOptions(config: Config): ConfigOption[] {
|
||||||
|
const currentApprovalMode = config.getApprovalMode();
|
||||||
|
const allConfiguredModels = config.getAllConfiguredModels();
|
||||||
|
const rawCurrentModelId = (config.getModel() || '').trim();
|
||||||
|
const currentAuthType = config.getAuthType?.();
|
||||||
|
|
||||||
|
// Check if current model is a runtime model
|
||||||
|
const activeRuntimeSnapshot = config.getActiveRuntimeModelSnapshot?.();
|
||||||
|
const currentModelId = activeRuntimeSnapshot
|
||||||
|
? formatAcpModelId(
|
||||||
|
activeRuntimeSnapshot.id,
|
||||||
|
activeRuntimeSnapshot.authType,
|
||||||
|
)
|
||||||
|
: this.formatCurrentModelId(rawCurrentModelId, currentAuthType);
|
||||||
|
|
||||||
|
// Build mode config option
|
||||||
|
const modeOptions = APPROVAL_MODES.map((mode) => ({
|
||||||
|
value: mode,
|
||||||
|
name: APPROVAL_MODE_INFO[mode].name,
|
||||||
|
description: APPROVAL_MODE_INFO[mode].description,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const modeConfigOption: ConfigOption = {
|
||||||
|
id: 'mode',
|
||||||
|
name: 'Mode',
|
||||||
|
description: 'Session permission mode',
|
||||||
|
category: 'mode',
|
||||||
|
type: 'select',
|
||||||
|
currentValue: currentApprovalMode,
|
||||||
|
options: modeOptions,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Build model config option
|
||||||
|
const modelOptions = allConfiguredModels.map((model) => {
|
||||||
|
const effectiveModelId =
|
||||||
|
model.isRuntimeModel && model.runtimeSnapshotId
|
||||||
|
? model.runtimeSnapshotId
|
||||||
|
: model.id;
|
||||||
|
return {
|
||||||
|
value: formatAcpModelId(effectiveModelId, model.authType),
|
||||||
|
name: model.label,
|
||||||
|
description: model.description ?? '',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const modelConfigOption: ConfigOption = {
|
||||||
|
id: 'model',
|
||||||
|
name: 'Model',
|
||||||
|
description: 'AI model to use',
|
||||||
|
category: 'model',
|
||||||
|
type: 'select',
|
||||||
|
currentValue: currentModelId,
|
||||||
|
options: modelOptions,
|
||||||
|
};
|
||||||
|
|
||||||
|
return [modeConfigOption, modelConfigOption];
|
||||||
|
}
|
||||||
|
|
||||||
private async ensureAuthenticated(config: Config): Promise<void> {
|
private async ensureAuthenticated(config: Config): Promise<void> {
|
||||||
const selectedType = config.getModelsConfig().getCurrentAuthType();
|
const selectedType = config.getModelsConfig().getCurrentAuthType();
|
||||||
if (!selectedType) {
|
if (!selectedType) {
|
||||||
|
|
@ -449,6 +561,21 @@ class GeminiAgent {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private buildModesData(config: Config): acp.ModesData {
|
||||||
|
const currentApprovalMode = config.getApprovalMode();
|
||||||
|
|
||||||
|
const availableModes = APPROVAL_MODES.map((mode) => ({
|
||||||
|
id: mode as ApprovalModeValue,
|
||||||
|
name: APPROVAL_MODE_INFO[mode].name,
|
||||||
|
description: APPROVAL_MODE_INFO[mode].description,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return {
|
||||||
|
currentModeId: currentApprovalMode as ApprovalModeValue,
|
||||||
|
availableModes,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private formatCurrentModelId(
|
private formatCurrentModelId(
|
||||||
baseModelId: string,
|
baseModelId: string,
|
||||||
authType?: AuthType,
|
authType?: AuthType,
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ export const AGENT_METHODS = {
|
||||||
session_list: 'session/list',
|
session_list: 'session/list',
|
||||||
session_set_mode: 'session/set_mode',
|
session_set_mode: 'session/set_mode',
|
||||||
session_set_model: 'session/set_model',
|
session_set_model: 'session/set_model',
|
||||||
|
session_set_config_option: 'session/set_config_option',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CLIENT_METHODS = {
|
export const CLIENT_METHODS = {
|
||||||
|
|
@ -59,7 +60,7 @@ export type CancelNotification = z.infer<typeof cancelNotificationSchema>;
|
||||||
|
|
||||||
export type AuthenticateRequest = z.infer<typeof authenticateRequestSchema>;
|
export type AuthenticateRequest = z.infer<typeof authenticateRequestSchema>;
|
||||||
|
|
||||||
export type NewSessionResponse = z.infer<typeof newSessionResponseSchema>;
|
// Note: NewSessionResponse type is defined later after newSessionResponseSchema
|
||||||
|
|
||||||
export type LoadSessionResponse = z.infer<typeof loadSessionResponseSchema>;
|
export type LoadSessionResponse = z.infer<typeof loadSessionResponseSchema>;
|
||||||
|
|
||||||
|
|
@ -285,33 +286,33 @@ export const sessionModelStateSchema = z.object({
|
||||||
currentModelId: modelIdSchema,
|
currentModelId: modelIdSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const newSessionResponseSchema = z.object({
|
// Note: newSessionResponseSchema is defined later in the file after modesDataSchema
|
||||||
sessionId: z.string(),
|
|
||||||
models: sessionModelStateSchema,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const loadSessionResponseSchema = z.null();
|
export const loadSessionResponseSchema = z.null();
|
||||||
|
|
||||||
export const sessionListItemSchema = z.object({
|
export const sessionListItemSchema = z.object({
|
||||||
cwd: z.string(),
|
cwd: z.string(),
|
||||||
filePath: z.string(),
|
filePath: z.string().optional(),
|
||||||
gitBranch: z.string().optional(),
|
gitBranch: z.string().optional(),
|
||||||
messageCount: z.number(),
|
messageCount: z.number().optional(),
|
||||||
mtime: z.number(),
|
mtime: z.number().optional(),
|
||||||
prompt: z.string(),
|
prompt: z.string().optional(),
|
||||||
sessionId: z.string(),
|
sessionId: z.string(),
|
||||||
startTime: z.string(),
|
startTime: z.string().optional(),
|
||||||
|
title: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const listSessionsResponseSchema = z.object({
|
export const listSessionsResponseSchema = z.object({
|
||||||
hasMore: z.boolean(),
|
hasMore: z.boolean().optional(),
|
||||||
items: z.array(sessionListItemSchema),
|
items: z.array(sessionListItemSchema).optional(),
|
||||||
nextCursor: z.number().optional(),
|
nextCursor: z.number().optional(),
|
||||||
|
sessions: z.array(sessionListItemSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const listSessionsRequestSchema = z.object({
|
export const listSessionsRequestSchema = z.object({
|
||||||
cursor: z.number().optional(),
|
cursor: z.number().optional(),
|
||||||
cwd: z.string(),
|
cwd: z.string().optional(),
|
||||||
size: z.number().optional(),
|
size: z.number().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -405,6 +406,12 @@ export const promptCapabilitiesSchema = z.object({
|
||||||
export const agentCapabilitiesSchema = z.object({
|
export const agentCapabilitiesSchema = z.object({
|
||||||
loadSession: z.boolean().optional(),
|
loadSession: z.boolean().optional(),
|
||||||
promptCapabilities: promptCapabilitiesSchema.optional(),
|
promptCapabilities: promptCapabilitiesSchema.optional(),
|
||||||
|
sessionCapabilities: z
|
||||||
|
.object({
|
||||||
|
list: z.object({}).optional(),
|
||||||
|
resume: z.object({}).optional(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const authMethodSchema = z.object({
|
export const authMethodSchema = z.object({
|
||||||
|
|
@ -451,6 +458,51 @@ export const modesDataSchema = z.object({
|
||||||
availableModes: z.array(modeInfoSchema),
|
availableModes: z.array(modeInfoSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const configOptionSchema = z.object({
|
||||||
|
id: z.string(),
|
||||||
|
name: z.string(),
|
||||||
|
description: z.string(),
|
||||||
|
category: z.string(),
|
||||||
|
type: z.string(),
|
||||||
|
currentValue: z.string(),
|
||||||
|
options: z.array(
|
||||||
|
z.object({
|
||||||
|
value: z.string(),
|
||||||
|
name: z.string(),
|
||||||
|
description: z.string(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ConfigOption = z.infer<typeof configOptionSchema>;
|
||||||
|
|
||||||
|
export const setConfigOptionRequestSchema = z.object({
|
||||||
|
sessionId: z.string(),
|
||||||
|
configId: z.string(),
|
||||||
|
value: z.unknown(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const setConfigOptionResponseSchema = z.object({
|
||||||
|
configOptions: z.array(configOptionSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type SetConfigOptionRequest = z.infer<
|
||||||
|
typeof setConfigOptionRequestSchema
|
||||||
|
>;
|
||||||
|
export type SetConfigOptionResponse = z.infer<
|
||||||
|
typeof setConfigOptionResponseSchema
|
||||||
|
>;
|
||||||
|
|
||||||
|
// newSessionResponseSchema includes modes and configOptions for ACP/Zed integration
|
||||||
|
export const newSessionResponseSchema = z.object({
|
||||||
|
sessionId: z.string(),
|
||||||
|
models: sessionModelStateSchema,
|
||||||
|
modes: modesDataSchema,
|
||||||
|
configOptions: z.array(configOptionSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type NewSessionResponse = z.infer<typeof newSessionResponseSchema>;
|
||||||
|
|
||||||
export const agentInfoSchema = z.object({
|
export const agentInfoSchema = z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
|
|
@ -650,6 +702,7 @@ export const agentRequestSchema = z.union([
|
||||||
listSessionsRequestSchema,
|
listSessionsRequestSchema,
|
||||||
setModeRequestSchema,
|
setModeRequestSchema,
|
||||||
setModelRequestSchema,
|
setModelRequestSchema,
|
||||||
|
setConfigOptionRequestSchema,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const agentNotificationSchema = sessionNotificationSchema;
|
export const agentNotificationSchema = sessionNotificationSchema;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ import { ACP_ERROR_CODES } from '../errorCodes.js';
|
||||||
|
|
||||||
const createFallback = (): FileSystemService => ({
|
const createFallback = (): FileSystemService => ({
|
||||||
readTextFile: vi.fn(),
|
readTextFile: vi.fn(),
|
||||||
|
readTextFileWithInfo: vi
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue({ content: '', encoding: 'utf-8', bom: false }),
|
||||||
writeTextFile: vi.fn(),
|
writeTextFile: vi.fn(),
|
||||||
detectFileBOM: vi.fn().mockResolvedValue(false),
|
detectFileBOM: vi.fn().mockResolvedValue(false),
|
||||||
findFiles: vi.fn().mockReturnValue([]),
|
findFiles: vi.fn().mockReturnValue([]),
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { FileSystemService } from '@qwen-code/qwen-code-core';
|
import type {
|
||||||
|
FileSystemService,
|
||||||
|
FileReadResult,
|
||||||
|
} from '@qwen-code/qwen-code-core';
|
||||||
import type * as acp from '../acp.js';
|
import type * as acp from '../acp.js';
|
||||||
import { ACP_ERROR_CODES } from '../errorCodes.js';
|
import { ACP_ERROR_CODES } from '../errorCodes.js';
|
||||||
|
|
||||||
|
|
@ -54,10 +57,16 @@ export class AcpFileSystemService implements FileSystemService {
|
||||||
return response.content;
|
return response.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async readTextFileWithInfo(filePath: string): Promise<FileReadResult> {
|
||||||
|
// ACP protocol does not expose encoding metadata; delegate to the local
|
||||||
|
// fallback which performs a single-pass read with encoding detection.
|
||||||
|
return this.fallback.readTextFileWithInfo(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
async writeTextFile(
|
async writeTextFile(
|
||||||
filePath: string,
|
filePath: string,
|
||||||
content: string,
|
content: string,
|
||||||
options?: { bom?: boolean },
|
options?: { bom?: boolean; encoding?: string },
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!this.capabilities.writeTextFile) {
|
if (!this.capabilities.writeTextFile) {
|
||||||
return this.fallback.writeTextFile(filePath, content, options);
|
return this.fallback.writeTextFile(filePath, content, options);
|
||||||
|
|
@ -85,7 +94,10 @@ export class AcpFileSystemService implements FileSystemService {
|
||||||
});
|
});
|
||||||
// Check if content starts with BOM character (U+FEFF)
|
// Check if content starts with BOM character (U+FEFF)
|
||||||
// Use codePointAt for better Unicode support and check content length first
|
// Use codePointAt for better Unicode support and check content length first
|
||||||
return response.content.length > 0 && response.content.codePointAt(0) === 0xfeff;
|
return (
|
||||||
|
response.content.length > 0 &&
|
||||||
|
response.content.codePointAt(0) === 0xfeff
|
||||||
|
);
|
||||||
} catch {
|
} catch {
|
||||||
// Fall through to fallback if ACP read fails
|
// Fall through to fallback if ACP read fails
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
packages/cli/src/commands/hooks.tsx
Normal file
25
packages/cli/src/commands/hooks.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { CommandModule } from 'yargs';
|
||||||
|
import { enableCommand } from './hooks/enable.js';
|
||||||
|
import { disableCommand } from './hooks/disable.js';
|
||||||
|
|
||||||
|
export const hooksCommand: CommandModule = {
|
||||||
|
command: 'hooks <command>',
|
||||||
|
aliases: ['hook'],
|
||||||
|
describe: 'Manage Qwen Code hooks.',
|
||||||
|
builder: (yargs) =>
|
||||||
|
yargs
|
||||||
|
.command(enableCommand)
|
||||||
|
.command(disableCommand)
|
||||||
|
.demandCommand(1, 'You need at least one command before continuing.')
|
||||||
|
.version(false),
|
||||||
|
handler: () => {
|
||||||
|
// This handler is not called when a subcommand is provided.
|
||||||
|
// Yargs will show the help menu.
|
||||||
|
},
|
||||||
|
};
|
||||||
75
packages/cli/src/commands/hooks/disable.ts
Normal file
75
packages/cli/src/commands/hooks/disable.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { CommandModule } from 'yargs';
|
||||||
|
import { createDebugLogger, getErrorMessage } from '@qwen-code/qwen-code-core';
|
||||||
|
import { loadSettings, SettingScope } from '../../config/settings.js';
|
||||||
|
|
||||||
|
const debugLogger = createDebugLogger('HOOKS_DISABLE');
|
||||||
|
|
||||||
|
interface DisableArgs {
|
||||||
|
hookName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable a hook by adding it to the disabled list
|
||||||
|
*/
|
||||||
|
export async function handleDisableHook(hookName: string): Promise<void> {
|
||||||
|
const workingDir = process.cwd();
|
||||||
|
const settings = loadSettings(workingDir);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get current hooks settings
|
||||||
|
const mergedSettings = settings.merged as
|
||||||
|
| Record<string, unknown>
|
||||||
|
| undefined;
|
||||||
|
const hooksSettings = (mergedSettings?.['hooks'] || {}) as Record<
|
||||||
|
string,
|
||||||
|
unknown
|
||||||
|
>;
|
||||||
|
const disabledHooks = (hooksSettings['disabled'] || []) as string[];
|
||||||
|
|
||||||
|
// Check if hook is already disabled
|
||||||
|
if (disabledHooks.includes(hookName)) {
|
||||||
|
debugLogger.info(`Hook "${hookName}" is already disabled.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add hook to disabled list
|
||||||
|
const newDisabledHooks = [...disabledHooks, hookName];
|
||||||
|
const newHooksSettings = {
|
||||||
|
...hooksSettings,
|
||||||
|
disabled: newDisabledHooks,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Save updated settings
|
||||||
|
settings.setValue(
|
||||||
|
SettingScope.Workspace,
|
||||||
|
'hooks' as keyof typeof settings.merged,
|
||||||
|
newHooksSettings as never,
|
||||||
|
);
|
||||||
|
|
||||||
|
debugLogger.info(`✓ Hook "${hookName}" has been disabled.`);
|
||||||
|
} catch (error) {
|
||||||
|
debugLogger.error(`Error disabling hook: ${getErrorMessage(error)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const disableCommand: CommandModule = {
|
||||||
|
command: 'disable <hook-name>',
|
||||||
|
describe: 'Disable an active hook',
|
||||||
|
builder: (yargs) =>
|
||||||
|
yargs.positional('hook-name', {
|
||||||
|
describe: 'Name of the hook to disable',
|
||||||
|
type: 'string',
|
||||||
|
demandOption: true,
|
||||||
|
}),
|
||||||
|
handler: async (argv) => {
|
||||||
|
const args = argv as unknown as DisableArgs;
|
||||||
|
await handleDisableHook(args.hookName);
|
||||||
|
process.exit(0);
|
||||||
|
},
|
||||||
|
};
|
||||||
75
packages/cli/src/commands/hooks/enable.ts
Normal file
75
packages/cli/src/commands/hooks/enable.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { CommandModule } from 'yargs';
|
||||||
|
import { createDebugLogger, getErrorMessage } from '@qwen-code/qwen-code-core';
|
||||||
|
import { loadSettings, SettingScope } from '../../config/settings.js';
|
||||||
|
|
||||||
|
const debugLogger = createDebugLogger('HOOKS_ENABLE');
|
||||||
|
|
||||||
|
interface EnableArgs {
|
||||||
|
hookName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable a hook by removing it from the disabled list
|
||||||
|
*/
|
||||||
|
export async function handleEnableHook(hookName: string): Promise<void> {
|
||||||
|
const workingDir = process.cwd();
|
||||||
|
const settings = loadSettings(workingDir);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get current hooks settings
|
||||||
|
const mergedSettings = settings.merged as
|
||||||
|
| Record<string, unknown>
|
||||||
|
| undefined;
|
||||||
|
const hooksSettings = (mergedSettings?.['hooks'] || {}) as Record<
|
||||||
|
string,
|
||||||
|
unknown
|
||||||
|
>;
|
||||||
|
const disabledHooks = (hooksSettings['disabled'] || []) as string[];
|
||||||
|
|
||||||
|
// Check if hook is in disabled list
|
||||||
|
if (!disabledHooks.includes(hookName)) {
|
||||||
|
debugLogger.info(`Hook "${hookName}" is not disabled.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove hook from disabled list
|
||||||
|
const newDisabledHooks = disabledHooks.filter((h) => h !== hookName);
|
||||||
|
const newHooksSettings = {
|
||||||
|
...hooksSettings,
|
||||||
|
disabled: newDisabledHooks,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Save updated settings
|
||||||
|
settings.setValue(
|
||||||
|
SettingScope.Workspace,
|
||||||
|
'hooks' as keyof typeof settings.merged,
|
||||||
|
newHooksSettings as never,
|
||||||
|
);
|
||||||
|
|
||||||
|
debugLogger.info(`✓ Hook "${hookName}" has been enabled.`);
|
||||||
|
} catch (error) {
|
||||||
|
debugLogger.error(`Error enabling hook: ${getErrorMessage(error)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const enableCommand: CommandModule = {
|
||||||
|
command: 'enable <hook-name>',
|
||||||
|
describe: 'Enable a disabled hook',
|
||||||
|
builder: (yargs) =>
|
||||||
|
yargs.positional('hook-name', {
|
||||||
|
describe: 'Name of the hook to enable',
|
||||||
|
type: 'string',
|
||||||
|
demandOption: true,
|
||||||
|
}),
|
||||||
|
handler: async (argv) => {
|
||||||
|
const args = argv as unknown as EnableArgs;
|
||||||
|
await handleEnableHook(args.hookName);
|
||||||
|
process.exit(0);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
@ -548,6 +548,43 @@ describe('loadCliConfig', () => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should reset context file names to QWEN.md and AGENTS.md by default', async () => {
|
||||||
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
const settings: Settings = {};
|
||||||
|
const setGeminiMdFilenameSpy = vi.spyOn(
|
||||||
|
ServerConfig,
|
||||||
|
'setGeminiMdFilename',
|
||||||
|
);
|
||||||
|
|
||||||
|
await loadCliConfig(settings, argv);
|
||||||
|
|
||||||
|
expect(setGeminiMdFilenameSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(setGeminiMdFilenameSpy).toHaveBeenCalledWith([
|
||||||
|
ServerConfig.DEFAULT_CONTEXT_FILENAME,
|
||||||
|
ServerConfig.AGENT_CONTEXT_FILENAME,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use configured context file name when settings.context.fileName is set', async () => {
|
||||||
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
const settings: Settings = {
|
||||||
|
context: {
|
||||||
|
fileName: 'CUSTOM_AGENTS.md',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const setGeminiMdFilenameSpy = vi.spyOn(
|
||||||
|
ServerConfig,
|
||||||
|
'setGeminiMdFilename',
|
||||||
|
);
|
||||||
|
|
||||||
|
await loadCliConfig(settings, argv);
|
||||||
|
|
||||||
|
expect(setGeminiMdFilenameSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(setGeminiMdFilenameSpy).toHaveBeenCalledWith('CUSTOM_AGENTS.md');
|
||||||
|
});
|
||||||
|
|
||||||
it('should propagate stream-json formats to config', async () => {
|
it('should propagate stream-json formats to config', async () => {
|
||||||
process.argv = [
|
process.argv = [
|
||||||
'node',
|
'node',
|
||||||
|
|
@ -567,6 +604,35 @@ describe('loadCliConfig', () => {
|
||||||
expect(config.getIncludePartialMessages()).toBe(true);
|
expect(config.getIncludePartialMessages()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should reset context filenames to defaults when context.fileName is not configured', async () => {
|
||||||
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
const settings: Settings = {};
|
||||||
|
const defaultContextFiles = ['QWEN.md', 'AGENTS.md'];
|
||||||
|
const getAllSpy = vi
|
||||||
|
.spyOn(ServerConfig, 'getAllGeminiMdFilenames')
|
||||||
|
.mockReturnValue(defaultContextFiles);
|
||||||
|
const setFilenameSpy = vi.spyOn(ServerConfig, 'setGeminiMdFilename');
|
||||||
|
|
||||||
|
await loadCliConfig(settings, argv);
|
||||||
|
|
||||||
|
expect(getAllSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(setFilenameSpy).toHaveBeenCalledWith(defaultContextFiles);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use context.fileName from settings when provided', async () => {
|
||||||
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
const settings: Settings = { context: { fileName: 'CUSTOM_CONTEXT.md' } };
|
||||||
|
const getAllSpy = vi.spyOn(ServerConfig, 'getAllGeminiMdFilenames');
|
||||||
|
const setFilenameSpy = vi.spyOn(ServerConfig, 'setGeminiMdFilename');
|
||||||
|
|
||||||
|
await loadCliConfig(settings, argv);
|
||||||
|
|
||||||
|
expect(setFilenameSpy).toHaveBeenCalledWith('CUSTOM_CONTEXT.md');
|
||||||
|
expect(getAllSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should initialize native LSP service when enabled', async () => {
|
it('should initialize native LSP service when enabled', async () => {
|
||||||
process.argv = ['node', 'script.js', '--experimental-lsp'];
|
process.argv = ['node', 'script.js', '--experimental-lsp'];
|
||||||
const argv = await parseArguments();
|
const argv = await parseArguments();
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
DEFAULT_QWEN_EMBEDDING_MODEL,
|
DEFAULT_QWEN_EMBEDDING_MODEL,
|
||||||
FileDiscoveryService,
|
FileDiscoveryService,
|
||||||
FileEncoding,
|
FileEncoding,
|
||||||
getCurrentGeminiMdFilename,
|
getAllGeminiMdFilenames,
|
||||||
loadServerHierarchicalMemory,
|
loadServerHierarchicalMemory,
|
||||||
setGeminiMdFilename as setServerGeminiMdFilename,
|
setGeminiMdFilename as setServerGeminiMdFilename,
|
||||||
resolveTelemetrySettings,
|
resolveTelemetrySettings,
|
||||||
|
|
@ -33,6 +33,7 @@ import {
|
||||||
NativeLspService,
|
NativeLspService,
|
||||||
} from '@qwen-code/qwen-code-core';
|
} from '@qwen-code/qwen-code-core';
|
||||||
import { extensionsCommand } from '../commands/extensions.js';
|
import { extensionsCommand } from '../commands/extensions.js';
|
||||||
|
import { hooksCommand } from '../commands/hooks.js';
|
||||||
import type { Settings } from './settings.js';
|
import type { Settings } from './settings.js';
|
||||||
import {
|
import {
|
||||||
resolveCliGenerationConfig,
|
resolveCliGenerationConfig,
|
||||||
|
|
@ -124,6 +125,7 @@ export interface CliArgs {
|
||||||
acp: boolean | undefined;
|
acp: boolean | undefined;
|
||||||
experimentalAcp: boolean | undefined;
|
experimentalAcp: boolean | undefined;
|
||||||
experimentalLsp: boolean | undefined;
|
experimentalLsp: boolean | undefined;
|
||||||
|
experimentalHooks: boolean | undefined;
|
||||||
extensions: string[] | undefined;
|
extensions: string[] | undefined;
|
||||||
listExtensions: boolean | undefined;
|
listExtensions: boolean | undefined;
|
||||||
openaiLogging: boolean | undefined;
|
openaiLogging: boolean | undefined;
|
||||||
|
|
@ -137,7 +139,6 @@ export interface CliArgs {
|
||||||
googleSearchEngineId: string | undefined;
|
googleSearchEngineId: string | undefined;
|
||||||
webSearchDefault: string | undefined;
|
webSearchDefault: string | undefined;
|
||||||
screenReader: boolean | undefined;
|
screenReader: boolean | undefined;
|
||||||
vlmSwitchMode: string | undefined;
|
|
||||||
inputFormat?: string | undefined;
|
inputFormat?: string | undefined;
|
||||||
outputFormat: string | undefined;
|
outputFormat: string | undefined;
|
||||||
includePartialMessages?: boolean;
|
includePartialMessages?: boolean;
|
||||||
|
|
@ -338,6 +339,12 @@ export async function parseArguments(): Promise<CliArgs> {
|
||||||
'Enable experimental LSP (Language Server Protocol) feature for code intelligence',
|
'Enable experimental LSP (Language Server Protocol) feature for code intelligence',
|
||||||
default: false,
|
default: false,
|
||||||
})
|
})
|
||||||
|
.option('experimental-hooks', {
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'Enable experimental hooks feature for lifecycle event customization',
|
||||||
|
default: false,
|
||||||
|
})
|
||||||
.option('channel', {
|
.option('channel', {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
choices: ['VSCode', 'ACP', 'SDK', 'CI'],
|
choices: ['VSCode', 'ACP', 'SDK', 'CI'],
|
||||||
|
|
@ -426,13 +433,6 @@ export async function parseArguments(): Promise<CliArgs> {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: 'Enable screen reader mode for accessibility.',
|
description: 'Enable screen reader mode for accessibility.',
|
||||||
})
|
})
|
||||||
.option('vlm-switch-mode', {
|
|
||||||
type: 'string',
|
|
||||||
choices: ['once', 'session', 'persist'],
|
|
||||||
description:
|
|
||||||
'Default behavior when images are detected in input. Values: once (one-time switch), session (switch for entire session), persist (continue with current model). Overrides settings files.',
|
|
||||||
default: process.env['VLM_SWITCH_MODE'],
|
|
||||||
})
|
|
||||||
.option('input-format', {
|
.option('input-format', {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
choices: ['text', 'stream-json'],
|
choices: ['text', 'stream-json'],
|
||||||
|
|
@ -569,7 +569,9 @@ export async function parseArguments(): Promise<CliArgs> {
|
||||||
// Register MCP subcommands
|
// Register MCP subcommands
|
||||||
.command(mcpCommand)
|
.command(mcpCommand)
|
||||||
// Register Extension subcommands
|
// Register Extension subcommands
|
||||||
.command(extensionsCommand);
|
.command(extensionsCommand)
|
||||||
|
// Register Hooks subcommands
|
||||||
|
.command(hooksCommand);
|
||||||
|
|
||||||
yargsInstance
|
yargsInstance
|
||||||
.version(await getCliVersion()) // This will enable the --version flag based on package.json
|
.version(await getCliVersion()) // This will enable the --version flag based on package.json
|
||||||
|
|
@ -588,9 +590,11 @@ export async function parseArguments(): Promise<CliArgs> {
|
||||||
// and not return to main CLI logic
|
// and not return to main CLI logic
|
||||||
if (
|
if (
|
||||||
result._.length > 0 &&
|
result._.length > 0 &&
|
||||||
(result._[0] === 'mcp' || result._[0] === 'extensions')
|
(result._[0] === 'mcp' ||
|
||||||
|
result._[0] === 'extensions' ||
|
||||||
|
result._[0] === 'hooks')
|
||||||
) {
|
) {
|
||||||
// MCP commands handle their own execution and process exit
|
// MCP/Extensions/Hooks commands handle their own execution and process exit
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -696,19 +700,26 @@ export async function loadCliConfig(
|
||||||
if (settings.context?.fileName) {
|
if (settings.context?.fileName) {
|
||||||
setServerGeminiMdFilename(settings.context.fileName);
|
setServerGeminiMdFilename(settings.context.fileName);
|
||||||
} else {
|
} else {
|
||||||
// Reset to default if not provided in settings.
|
// Reset to default context filenames if not provided in settings.
|
||||||
setServerGeminiMdFilename(getCurrentGeminiMdFilename());
|
setServerGeminiMdFilename(getAllGeminiMdFilenames());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Automatically load output-language.md if it exists
|
// Automatically load output-language.md if it exists
|
||||||
let outputLanguageFilePath: string | undefined = path.join(
|
const projectStorage = new Storage(cwd);
|
||||||
|
const projectOutputLanguagePath = path.join(
|
||||||
|
projectStorage.getQwenDir(),
|
||||||
|
'output-language.md',
|
||||||
|
);
|
||||||
|
const globalOutputLanguagePath = path.join(
|
||||||
Storage.getGlobalQwenDir(),
|
Storage.getGlobalQwenDir(),
|
||||||
'output-language.md',
|
'output-language.md',
|
||||||
);
|
);
|
||||||
if (fs.existsSync(outputLanguageFilePath)) {
|
|
||||||
// output-language.md found - will be added to context files
|
let outputLanguageFilePath: string | undefined;
|
||||||
} else {
|
if (fs.existsSync(projectOutputLanguagePath)) {
|
||||||
outputLanguageFilePath = undefined;
|
outputLanguageFilePath = projectOutputLanguagePath;
|
||||||
|
} else if (fs.existsSync(globalOutputLanguagePath)) {
|
||||||
|
outputLanguageFilePath = globalOutputLanguagePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileService = new FileDiscoveryService(cwd);
|
const fileService = new FileDiscoveryService(cwd);
|
||||||
|
|
@ -903,9 +914,6 @@ export async function loadCliConfig(
|
||||||
? argv.screenReader
|
? argv.screenReader
|
||||||
: (settings.ui?.accessibility?.screenReader ?? false);
|
: (settings.ui?.accessibility?.screenReader ?? false);
|
||||||
|
|
||||||
const vlmSwitchMode =
|
|
||||||
argv.vlmSwitchMode || settings.experimental?.vlmSwitchMode;
|
|
||||||
|
|
||||||
let sessionId: string | undefined;
|
let sessionId: string | undefined;
|
||||||
let sessionData: ResumedSessionData | undefined;
|
let sessionData: ResumedSessionData | undefined;
|
||||||
|
|
||||||
|
|
@ -1002,6 +1010,7 @@ export async function loadCliConfig(
|
||||||
modelProvidersConfig,
|
modelProvidersConfig,
|
||||||
generationConfigSources: resolvedCliConfig.sources,
|
generationConfigSources: resolvedCliConfig.sources,
|
||||||
generationConfig: resolvedCliConfig.generationConfig,
|
generationConfig: resolvedCliConfig.generationConfig,
|
||||||
|
warnings: resolvedCliConfig.warnings,
|
||||||
cliVersion: await getCliVersion(),
|
cliVersion: await getCliVersion(),
|
||||||
webSearch: buildWebSearchConfig(argv, settings, selectedAuthType),
|
webSearch: buildWebSearchConfig(argv, settings, selectedAuthType),
|
||||||
summarizeToolOutput: settings.model?.summarizeToolOutput,
|
summarizeToolOutput: settings.model?.summarizeToolOutput,
|
||||||
|
|
@ -1014,9 +1023,8 @@ export async function loadCliConfig(
|
||||||
useBuiltinRipgrep: settings.tools?.useBuiltinRipgrep,
|
useBuiltinRipgrep: settings.tools?.useBuiltinRipgrep,
|
||||||
shouldUseNodePtyShell: settings.tools?.shell?.enableInteractiveShell,
|
shouldUseNodePtyShell: settings.tools?.shell?.enableInteractiveShell,
|
||||||
skipNextSpeakerCheck: settings.model?.skipNextSpeakerCheck,
|
skipNextSpeakerCheck: settings.model?.skipNextSpeakerCheck,
|
||||||
skipLoopDetection: settings.model?.skipLoopDetection ?? false,
|
skipLoopDetection: settings.model?.skipLoopDetection ?? true,
|
||||||
skipStartupContext: settings.model?.skipStartupContext ?? false,
|
skipStartupContext: settings.model?.skipStartupContext ?? false,
|
||||||
vlmSwitchMode,
|
|
||||||
truncateToolOutputThreshold: settings.tools?.truncateToolOutputThreshold,
|
truncateToolOutputThreshold: settings.tools?.truncateToolOutputThreshold,
|
||||||
truncateToolOutputLines: settings.tools?.truncateToolOutputLines,
|
truncateToolOutputLines: settings.tools?.truncateToolOutputLines,
|
||||||
enableToolOutputTruncation: settings.tools?.enableToolOutputTruncation,
|
enableToolOutputTruncation: settings.tools?.enableToolOutputTruncation,
|
||||||
|
|
@ -1025,6 +1033,10 @@ export async function loadCliConfig(
|
||||||
output: {
|
output: {
|
||||||
format: outputSettingsFormat,
|
format: outputSettingsFormat,
|
||||||
},
|
},
|
||||||
|
hooks: settings.hooks,
|
||||||
|
hooksConfig: settings.hooksConfig,
|
||||||
|
enableHooks:
|
||||||
|
argv.experimentalHooks === true || settings.hooksConfig?.enabled === true,
|
||||||
channel: argv.channel,
|
channel: argv.channel,
|
||||||
// Precedence: explicit CLI flag > settings file > default(true).
|
// Precedence: explicit CLI flag > settings file > default(true).
|
||||||
// NOTE: do NOT set a yargs default for `chat-recording`, otherwise argv will
|
// NOTE: do NOT set a yargs default for `chat-recording`, otherwise argv will
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ export enum Command {
|
||||||
QUIT = 'quit',
|
QUIT = 'quit',
|
||||||
EXIT = 'exit',
|
EXIT = 'exit',
|
||||||
SHOW_MORE_LINES = 'showMoreLines',
|
SHOW_MORE_LINES = 'showMoreLines',
|
||||||
|
RETRY_LAST = 'retryLast',
|
||||||
|
|
||||||
// Shell commands
|
// Shell commands
|
||||||
REVERSE_SEARCH = 'reverseSearch',
|
REVERSE_SEARCH = 'reverseSearch',
|
||||||
|
|
@ -170,6 +171,7 @@ export const defaultKeyBindings: KeyBindingConfig = {
|
||||||
[Command.QUIT]: [{ key: 'c', ctrl: true }],
|
[Command.QUIT]: [{ key: 'c', ctrl: true }],
|
||||||
[Command.EXIT]: [{ key: 'd', ctrl: true }],
|
[Command.EXIT]: [{ key: 'd', ctrl: true }],
|
||||||
[Command.SHOW_MORE_LINES]: [{ key: 's', ctrl: true }],
|
[Command.SHOW_MORE_LINES]: [{ key: 's', ctrl: true }],
|
||||||
|
[Command.RETRY_LAST]: [{ key: 'y', ctrl: true }],
|
||||||
|
|
||||||
// Shell commands
|
// Shell commands
|
||||||
[Command.REVERSE_SEARCH]: [{ key: 'r', ctrl: true }],
|
[Command.REVERSE_SEARCH]: [{ key: 'r', ctrl: true }],
|
||||||
|
|
|
||||||
383
packages/cli/src/config/migration/index.test.ts
Normal file
383
packages/cli/src/config/migration/index.test.ts
Normal file
|
|
@ -0,0 +1,383 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import {
|
||||||
|
runMigrations,
|
||||||
|
needsMigration,
|
||||||
|
ALL_MIGRATIONS,
|
||||||
|
MigrationScheduler,
|
||||||
|
} from './index.js';
|
||||||
|
import { SETTINGS_VERSION } from '../settings.js';
|
||||||
|
|
||||||
|
describe('Migration Framework Integration', () => {
|
||||||
|
describe('runMigrations', () => {
|
||||||
|
it('should migrate V1 settings to V3', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
model: 'gemini',
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
disableLoadingPhrases: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = runMigrations(v1Settings, 'user');
|
||||||
|
|
||||||
|
expect(result.finalVersion).toBe(3);
|
||||||
|
expect(result.executedMigrations).toHaveLength(2);
|
||||||
|
expect(result.executedMigrations[0]).toEqual({
|
||||||
|
fromVersion: 1,
|
||||||
|
toVersion: 2,
|
||||||
|
});
|
||||||
|
expect(result.executedMigrations[1]).toEqual({
|
||||||
|
fromVersion: 2,
|
||||||
|
toVersion: 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check V2 structure was created
|
||||||
|
const settings = result.settings as Record<string, unknown>;
|
||||||
|
expect(settings['$version']).toBe(3);
|
||||||
|
expect(settings['ui']).toEqual({
|
||||||
|
theme: 'dark',
|
||||||
|
accessibility: { enableLoadingPhrases: true },
|
||||||
|
});
|
||||||
|
expect(settings['model']).toEqual({ name: 'gemini' });
|
||||||
|
|
||||||
|
// Check disableAutoUpdate was inverted to enableAutoUpdate: false
|
||||||
|
expect(
|
||||||
|
(settings['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should migrate V2 settings to V3', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
ui: { theme: 'light' },
|
||||||
|
general: { disableAutoUpdate: false },
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = runMigrations(v2Settings, 'user');
|
||||||
|
|
||||||
|
expect(result.finalVersion).toBe(3);
|
||||||
|
expect(result.executedMigrations).toHaveLength(1);
|
||||||
|
expect(result.executedMigrations[0]).toEqual({
|
||||||
|
fromVersion: 2,
|
||||||
|
toVersion: 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
const settings = result.settings as Record<string, unknown>;
|
||||||
|
expect(settings['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(settings['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
(settings['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not modify V3 settings', () => {
|
||||||
|
const v3Settings = {
|
||||||
|
$version: 3,
|
||||||
|
ui: { theme: 'dark' },
|
||||||
|
general: { enableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = runMigrations(v3Settings, 'user');
|
||||||
|
|
||||||
|
expect(result.finalVersion).toBe(3);
|
||||||
|
expect(result.executedMigrations).toHaveLength(0);
|
||||||
|
expect(result.settings).toEqual(v3Settings);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be idempotent', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const result1 = runMigrations(v1Settings, 'user');
|
||||||
|
const result2 = runMigrations(result1.settings, 'user');
|
||||||
|
|
||||||
|
expect(result1.executedMigrations).toHaveLength(2);
|
||||||
|
expect(result2.executedMigrations).toHaveLength(0);
|
||||||
|
expect(result1.finalVersion).toBe(result2.finalVersion);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('needsMigration', () => {
|
||||||
|
it('should return true for V1 settings', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
model: 'gemini',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(needsMigration(v1Settings)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for V2 settings with deprecated keys', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(needsMigration(v2Settings)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for V2 settings without deprecated keys', () => {
|
||||||
|
const cleanV2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
ui: { theme: 'dark' },
|
||||||
|
};
|
||||||
|
|
||||||
|
// V2 settings should be migrated to V3 to update the version number
|
||||||
|
expect(needsMigration(cleanV2Settings)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for V3 settings', () => {
|
||||||
|
const v3Settings = {
|
||||||
|
$version: 3,
|
||||||
|
general: { enableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(needsMigration(v3Settings)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for legacy numeric version when no migration can execute', () => {
|
||||||
|
const legacyButUnknownSettings = {
|
||||||
|
$version: 1,
|
||||||
|
customOnlyKey: 'value',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(needsMigration(legacyButUnknownSettings)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ALL_MIGRATIONS', () => {
|
||||||
|
it('should contain all migrations in order', () => {
|
||||||
|
expect(ALL_MIGRATIONS).toHaveLength(2);
|
||||||
|
|
||||||
|
expect(ALL_MIGRATIONS[0].fromVersion).toBe(1);
|
||||||
|
expect(ALL_MIGRATIONS[0].toVersion).toBe(2);
|
||||||
|
|
||||||
|
expect(ALL_MIGRATIONS[1].fromVersion).toBe(2);
|
||||||
|
expect(ALL_MIGRATIONS[1].toVersion).toBe(3);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('MigrationScheduler with all migrations', () => {
|
||||||
|
it('should execute full migration chain', () => {
|
||||||
|
const scheduler = new MigrationScheduler([...ALL_MIGRATIONS], 'user');
|
||||||
|
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
disableLoadingPhrases: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = scheduler.migrate(v1Settings);
|
||||||
|
|
||||||
|
expect(result.executedMigrations).toHaveLength(2);
|
||||||
|
|
||||||
|
const settings = result.settings as Record<string, unknown>;
|
||||||
|
expect(settings['$version']).toBe(3);
|
||||||
|
expect((settings['ui'] as Record<string, unknown>)['theme']).toBe('dark');
|
||||||
|
expect(
|
||||||
|
(settings['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(settings['ui'] as Record<string, unknown>)[
|
||||||
|
'accessibility'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)['enableLoadingPhrases'],
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('needsMigration and runMigrations consistency', () => {
|
||||||
|
it('needsMigration should return true when runMigrations would execute migrations', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// needsMigration should report that migration is needed
|
||||||
|
expect(needsMigration(v1Settings)).toBe(true);
|
||||||
|
|
||||||
|
// runMigrations should actually execute migrations
|
||||||
|
const result = runMigrations(v1Settings, 'user');
|
||||||
|
expect(result.executedMigrations.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('needsMigration should return false when runMigrations would execute no migrations', () => {
|
||||||
|
const v3Settings = {
|
||||||
|
$version: 3,
|
||||||
|
general: { enableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
// needsMigration should report that no migration is needed
|
||||||
|
expect(needsMigration(v3Settings)).toBe(false);
|
||||||
|
|
||||||
|
// runMigrations should execute no migrations
|
||||||
|
const result = runMigrations(v3Settings, 'user');
|
||||||
|
expect(result.executedMigrations).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle V2 settings without deprecated keys consistently', () => {
|
||||||
|
const cleanV2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
ui: { theme: 'dark' },
|
||||||
|
};
|
||||||
|
|
||||||
|
// needsMigration should report that migration is needed
|
||||||
|
expect(needsMigration(cleanV2Settings)).toBe(true);
|
||||||
|
|
||||||
|
// runMigrations should execute the V2->V3 migration
|
||||||
|
const result = runMigrations(cleanV2Settings, 'user');
|
||||||
|
expect(result.executedMigrations.length).toBeGreaterThan(0);
|
||||||
|
expect(result.finalVersion).toBe(3);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('migration chain integrity', () => {
|
||||||
|
it('should have strictly increasing versions (toVersion > fromVersion)', () => {
|
||||||
|
for (const migration of ALL_MIGRATIONS) {
|
||||||
|
expect(migration.toVersion).toBeGreaterThan(migration.fromVersion);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have no gaps in the chain (adjacent versions)', () => {
|
||||||
|
for (let i = 1; i < ALL_MIGRATIONS.length; i++) {
|
||||||
|
const prevMigration = ALL_MIGRATIONS[i - 1];
|
||||||
|
const currMigration = ALL_MIGRATIONS[i];
|
||||||
|
expect(currMigration.fromVersion).toBe(prevMigration.toVersion);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have no duplicate fromVersions', () => {
|
||||||
|
const fromVersions = ALL_MIGRATIONS.map((m) => m.fromVersion);
|
||||||
|
const uniqueFromVersions = new Set(fromVersions);
|
||||||
|
expect(uniqueFromVersions.size).toBe(fromVersions.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have no duplicate toVersions', () => {
|
||||||
|
const toVersions = ALL_MIGRATIONS.map((m) => m.toVersion);
|
||||||
|
const uniqueToVersions = new Set(toVersions);
|
||||||
|
expect(uniqueToVersions.size).toBe(toVersions.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be acyclic (no version appears as fromVersion more than once)', () => {
|
||||||
|
const fromVersionCounts = new Map<number, number>();
|
||||||
|
for (const migration of ALL_MIGRATIONS) {
|
||||||
|
const count = fromVersionCounts.get(migration.fromVersion) || 0;
|
||||||
|
fromVersionCounts.set(migration.fromVersion, count + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const count of fromVersionCounts.values()) {
|
||||||
|
expect(count).toBe(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should chain from version 1 to SETTINGS_VERSION', () => {
|
||||||
|
if (ALL_MIGRATIONS.length > 0) {
|
||||||
|
expect(ALL_MIGRATIONS[0].fromVersion).toBe(1);
|
||||||
|
const lastMigration = ALL_MIGRATIONS[ALL_MIGRATIONS.length - 1];
|
||||||
|
expect(lastMigration.toVersion).toBe(SETTINGS_VERSION);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('single source of truth for version constant', () => {
|
||||||
|
it('should use SETTINGS_VERSION from settings module', () => {
|
||||||
|
// The last migration's toVersion should match SETTINGS_VERSION
|
||||||
|
const lastMigration = ALL_MIGRATIONS[ALL_MIGRATIONS.length - 1];
|
||||||
|
expect(lastMigration.toVersion).toBe(SETTINGS_VERSION);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('needsMigration should use SETTINGS_VERSION for version comparison', () => {
|
||||||
|
// Create settings with version equal to SETTINGS_VERSION
|
||||||
|
const currentVersionSettings = {
|
||||||
|
$version: SETTINGS_VERSION,
|
||||||
|
general: { enableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
// needsMigration should return false for current version
|
||||||
|
expect(needsMigration(currentVersionSettings)).toBe(false);
|
||||||
|
|
||||||
|
// Create settings with version less than SETTINGS_VERSION
|
||||||
|
const oldVersionSettings = {
|
||||||
|
$version: SETTINGS_VERSION - 1,
|
||||||
|
general: { disableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
// needsMigration should return true for old version
|
||||||
|
expect(needsMigration(oldVersionSettings)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have SETTINGS_VERSION defined exactly once in codebase', () => {
|
||||||
|
// SETTINGS_VERSION is imported from settings.js
|
||||||
|
// This test verifies the wiring is correct
|
||||||
|
expect(SETTINGS_VERSION).toBeDefined();
|
||||||
|
expect(typeof SETTINGS_VERSION).toBe('number');
|
||||||
|
expect(SETTINGS_VERSION).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('invalid version handling', () => {
|
||||||
|
it('should treat non-numeric version with V1 shape as needing migration', () => {
|
||||||
|
const settingsWithInvalidVersion = {
|
||||||
|
$version: 'invalid',
|
||||||
|
theme: 'dark',
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Should detect migration needed based on V1 shape
|
||||||
|
expect(needsMigration(settingsWithInvalidVersion)).toBe(true);
|
||||||
|
|
||||||
|
// Should run migrations
|
||||||
|
const result = runMigrations(settingsWithInvalidVersion, 'user');
|
||||||
|
expect(result.executedMigrations.length).toBeGreaterThan(0);
|
||||||
|
expect(result.finalVersion).toBe(SETTINGS_VERSION);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not migrate non-numeric version with already-migrated shape (normalized by loader)', () => {
|
||||||
|
const settingsWithInvalidVersionButMigratedShape = {
|
||||||
|
$version: 'invalid',
|
||||||
|
general: { enableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
// needsMigration returns false because no migration applies to this shape
|
||||||
|
// The settings loader will handle version normalization separately
|
||||||
|
expect(needsMigration(settingsWithInvalidVersionButMigratedShape)).toBe(
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// No migrations should execute
|
||||||
|
const result = runMigrations(
|
||||||
|
settingsWithInvalidVersionButMigratedShape,
|
||||||
|
'user',
|
||||||
|
);
|
||||||
|
expect(result.executedMigrations).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should avoid repeated no-op migration loops', () => {
|
||||||
|
// Settings that might cause repeated migrations
|
||||||
|
const v3Settings = {
|
||||||
|
$version: 3,
|
||||||
|
general: { enableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
// First check
|
||||||
|
expect(needsMigration(v3Settings)).toBe(false);
|
||||||
|
const result1 = runMigrations(v3Settings, 'user');
|
||||||
|
expect(result1.executedMigrations).toHaveLength(0);
|
||||||
|
|
||||||
|
// Second check should be consistent
|
||||||
|
expect(needsMigration(result1.settings)).toBe(false);
|
||||||
|
const result2 = runMigrations(result1.settings, 'user');
|
||||||
|
expect(result2.executedMigrations).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
106
packages/cli/src/config/migration/index.ts
Normal file
106
packages/cli/src/config/migration/index.ts
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Export types
|
||||||
|
export type { SettingsMigration, MigrationResult } from './types.js';
|
||||||
|
|
||||||
|
// Export scheduler
|
||||||
|
export { MigrationScheduler } from './scheduler.js';
|
||||||
|
|
||||||
|
// Export migrations
|
||||||
|
export { v1ToV2Migration, V1ToV2Migration } from './versions/v1-to-v2.js';
|
||||||
|
export { v2ToV3Migration, V2ToV3Migration } from './versions/v2-to-v3.js';
|
||||||
|
|
||||||
|
// Import settings version from single source of truth
|
||||||
|
import { SETTINGS_VERSION } from '../settings.js';
|
||||||
|
|
||||||
|
// Ordered array of all migrations for use with MigrationScheduler
|
||||||
|
// Each migration handles one version transition (N → N+1)
|
||||||
|
// Order matters: migrations must be sorted by ascending version
|
||||||
|
import { v1ToV2Migration } from './versions/v1-to-v2.js';
|
||||||
|
import { v2ToV3Migration } from './versions/v2-to-v3.js';
|
||||||
|
import { MigrationScheduler } from './scheduler.js';
|
||||||
|
import type { MigrationResult } from './types.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ordered array of all settings migrations.
|
||||||
|
* Use this with MigrationScheduler to run the full migration chain.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* const scheduler = new MigrationScheduler(ALL_MIGRATIONS);
|
||||||
|
* const result = scheduler.migrate(settings);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export const ALL_MIGRATIONS = [v1ToV2Migration, v2ToV3Migration] as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience function that runs all migrations on the given settings.
|
||||||
|
* This is the primary entry point for settings migration.
|
||||||
|
*
|
||||||
|
* @param settings - The settings object to migrate
|
||||||
|
* @param scope - The scope of settings being migrated
|
||||||
|
* @returns MigrationResult containing the final settings, version, and execution log
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* const result = runMigrations(settings, 'User');
|
||||||
|
* if (result.executedMigrations.length > 0) {
|
||||||
|
* console.log(`Migrated from version ${result.executedMigrations[0].fromVersion} to ${result.finalVersion}`);
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export function runMigrations(
|
||||||
|
settings: unknown,
|
||||||
|
scope: string,
|
||||||
|
): MigrationResult {
|
||||||
|
const scheduler = new MigrationScheduler([...ALL_MIGRATIONS], scope);
|
||||||
|
return scheduler.migrate(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given settings need migration.
|
||||||
|
* Returns true only if at least one registered migration would be applied.
|
||||||
|
*
|
||||||
|
* This function checks:
|
||||||
|
* 1. If $version field exists and is a number:
|
||||||
|
* - Returns false if $version >= SETTINGS_VERSION
|
||||||
|
* - Returns true only when $version < SETTINGS_VERSION AND at least one
|
||||||
|
* migration can execute for the current settings shape
|
||||||
|
* 2. If $version field is missing or invalid:
|
||||||
|
* - Uses fallback logic by checking individual migrations
|
||||||
|
*
|
||||||
|
* Note:
|
||||||
|
* - Legacy numeric versions that have no executable migrations are handled by
|
||||||
|
* the settings loader via version normalization (bump metadata to current).
|
||||||
|
*
|
||||||
|
* @param settings - The settings object to check
|
||||||
|
* @returns true if migration is needed, false otherwise
|
||||||
|
*/
|
||||||
|
export function needsMigration(settings: unknown): boolean {
|
||||||
|
if (typeof settings !== 'object' || settings === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const s = settings as Record<string, unknown>;
|
||||||
|
const version = s['$version'];
|
||||||
|
const hasApplicableMigration = ALL_MIGRATIONS.some((migration) =>
|
||||||
|
migration.shouldMigrate(settings),
|
||||||
|
);
|
||||||
|
|
||||||
|
// If $version is a valid number, use version comparison
|
||||||
|
if (typeof version === 'number') {
|
||||||
|
if (version >= SETTINGS_VERSION) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Guardrail: only report migration-needed if at least one migration can execute.
|
||||||
|
return hasApplicableMigration;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If $version exists but is not a number (invalid), or is missing:
|
||||||
|
// Use fallback logic - check if any migration would be applied
|
||||||
|
return hasApplicableMigration;
|
||||||
|
}
|
||||||
164
packages/cli/src/config/migration/scheduler.test.ts
Normal file
164
packages/cli/src/config/migration/scheduler.test.ts
Normal file
|
|
@ -0,0 +1,164 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { describe, it, expect, vi } from 'vitest';
|
||||||
|
import { MigrationScheduler } from './scheduler.js';
|
||||||
|
|
||||||
|
import type { SettingsMigration } from './types.js';
|
||||||
|
|
||||||
|
describe('MigrationScheduler', () => {
|
||||||
|
// Mock migration for testing
|
||||||
|
const createMockMigration = (
|
||||||
|
fromVersion: number,
|
||||||
|
toVersion: number,
|
||||||
|
shouldMigrateResult: boolean,
|
||||||
|
): SettingsMigration => ({
|
||||||
|
fromVersion,
|
||||||
|
toVersion,
|
||||||
|
shouldMigrate: vi.fn().mockReturnValue(shouldMigrateResult),
|
||||||
|
migrate: vi.fn((settings) => ({
|
||||||
|
settings: {
|
||||||
|
...(settings as Record<string, unknown>),
|
||||||
|
$version: toVersion,
|
||||||
|
},
|
||||||
|
warnings: [],
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should execute migrations in order when shouldMigrate returns true', () => {
|
||||||
|
const migration1 = createMockMigration(1, 2, true);
|
||||||
|
const migration2 = createMockMigration(2, 3, true);
|
||||||
|
|
||||||
|
const scheduler = new MigrationScheduler([migration1, migration2], 'user');
|
||||||
|
const result = scheduler.migrate({ $version: 1, someKey: 'value' });
|
||||||
|
|
||||||
|
expect(migration1.shouldMigrate).toHaveBeenCalledTimes(1);
|
||||||
|
expect(migration1.migrate).toHaveBeenCalledTimes(1);
|
||||||
|
expect(migration2.shouldMigrate).toHaveBeenCalledTimes(1);
|
||||||
|
expect(migration2.migrate).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
expect(result.executedMigrations).toHaveLength(2);
|
||||||
|
expect(result.executedMigrations[0]).toEqual({
|
||||||
|
fromVersion: 1,
|
||||||
|
toVersion: 2,
|
||||||
|
});
|
||||||
|
expect(result.executedMigrations[1]).toEqual({
|
||||||
|
fromVersion: 2,
|
||||||
|
toVersion: 3,
|
||||||
|
});
|
||||||
|
expect(result.finalVersion).toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should skip migrations when shouldMigrate returns false', () => {
|
||||||
|
const migration1 = createMockMigration(1, 2, false);
|
||||||
|
const migration2 = createMockMigration(2, 3, true);
|
||||||
|
|
||||||
|
const scheduler = new MigrationScheduler([migration1, migration2], 'user');
|
||||||
|
const result = scheduler.migrate({ $version: 2, someKey: 'value' });
|
||||||
|
|
||||||
|
expect(migration1.shouldMigrate).toHaveBeenCalledTimes(1);
|
||||||
|
expect(migration1.migrate).not.toHaveBeenCalled();
|
||||||
|
expect(migration2.shouldMigrate).toHaveBeenCalledTimes(1);
|
||||||
|
expect(migration2.migrate).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
expect(result.executedMigrations).toHaveLength(1);
|
||||||
|
expect(result.executedMigrations[0]).toEqual({
|
||||||
|
fromVersion: 2,
|
||||||
|
toVersion: 3,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be idempotent - running migrations twice produces same result', () => {
|
||||||
|
// Create a migration that checks the version to determine if migration is needed
|
||||||
|
const migration1: SettingsMigration = {
|
||||||
|
fromVersion: 1,
|
||||||
|
toVersion: 2,
|
||||||
|
shouldMigrate: vi.fn((settings) => {
|
||||||
|
const s = settings as Record<string, unknown>;
|
||||||
|
return s['$version'] !== 2;
|
||||||
|
}),
|
||||||
|
migrate: vi.fn((settings) => ({
|
||||||
|
settings: {
|
||||||
|
...(settings as Record<string, unknown>),
|
||||||
|
$version: 2,
|
||||||
|
},
|
||||||
|
warnings: [],
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
const scheduler = new MigrationScheduler([migration1], 'user');
|
||||||
|
const input = { theme: 'dark' };
|
||||||
|
|
||||||
|
const result1 = scheduler.migrate(input);
|
||||||
|
const result2 = scheduler.migrate(result1.settings);
|
||||||
|
|
||||||
|
expect(result1.executedMigrations).toHaveLength(1);
|
||||||
|
expect(result2.executedMigrations).toHaveLength(0);
|
||||||
|
expect(result1.finalVersion).toBe(result2.finalVersion);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pass updated settings to each migration', () => {
|
||||||
|
const migration1: SettingsMigration = {
|
||||||
|
fromVersion: 1,
|
||||||
|
toVersion: 2,
|
||||||
|
shouldMigrate: vi.fn().mockReturnValue(true),
|
||||||
|
migrate: vi.fn(() => ({
|
||||||
|
settings: { $version: 2, transformed: true },
|
||||||
|
warnings: [],
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
const migration2: SettingsMigration = {
|
||||||
|
fromVersion: 2,
|
||||||
|
toVersion: 3,
|
||||||
|
shouldMigrate: vi.fn().mockReturnValue(true),
|
||||||
|
migrate: vi.fn((s) => ({ settings: s, warnings: [] })),
|
||||||
|
};
|
||||||
|
|
||||||
|
const scheduler = new MigrationScheduler([migration1, migration2], 'user');
|
||||||
|
scheduler.migrate({ $version: 1 });
|
||||||
|
|
||||||
|
expect(migration2.shouldMigrate).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ $version: 2, transformed: true }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle empty migrations array', () => {
|
||||||
|
const scheduler = new MigrationScheduler([], 'user');
|
||||||
|
const result = scheduler.migrate({ $version: 1, key: 'value' });
|
||||||
|
|
||||||
|
expect(result.executedMigrations).toHaveLength(0);
|
||||||
|
expect(result.finalVersion).toBe(1);
|
||||||
|
expect(result.settings).toEqual({ $version: 1, key: 'value' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw error when migration fails', () => {
|
||||||
|
const migration1: SettingsMigration = {
|
||||||
|
fromVersion: 1,
|
||||||
|
toVersion: 2,
|
||||||
|
shouldMigrate: vi.fn().mockReturnValue(true),
|
||||||
|
migrate: vi.fn().mockImplementation(() => {
|
||||||
|
throw new Error('Migration failed');
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const scheduler = new MigrationScheduler([migration1], 'user');
|
||||||
|
|
||||||
|
expect(() => scheduler.migrate({ $version: 1 })).toThrow(
|
||||||
|
'Migration failed',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle settings without version field', () => {
|
||||||
|
const migration1 = createMockMigration(1, 2, true);
|
||||||
|
|
||||||
|
const scheduler = new MigrationScheduler([migration1], 'user');
|
||||||
|
const result = scheduler.migrate({ theme: 'dark' });
|
||||||
|
|
||||||
|
expect(result.finalVersion).toBe(2);
|
||||||
|
expect(result.executedMigrations).toHaveLength(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
115
packages/cli/src/config/migration/scheduler.ts
Normal file
115
packages/cli/src/config/migration/scheduler.ts
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { createDebugLogger } from '@qwen-code/qwen-code-core';
|
||||||
|
import type { SettingsMigration, MigrationResult } from './types.js';
|
||||||
|
|
||||||
|
const debugLogger = createDebugLogger('SETTINGS_MIGRATION');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a SettingScope enum value to a human-readable string.
|
||||||
|
* - Converts to lowercase
|
||||||
|
* - Special case: 'SystemDefaults' -> 'system default'
|
||||||
|
*/
|
||||||
|
export function formatScope(scope: string): string {
|
||||||
|
if (scope === 'SystemDefaults') {
|
||||||
|
return 'system default';
|
||||||
|
}
|
||||||
|
return scope.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chain scheduler for settings migrations.
|
||||||
|
*
|
||||||
|
* The MigrationScheduler orchestrates multiple migrations in sequence,
|
||||||
|
* delegating version detection to each individual migration via `shouldMigrate`.
|
||||||
|
* It has no centralized version logic - migrations self-determine applicability.
|
||||||
|
*
|
||||||
|
* Key characteristics:
|
||||||
|
* - Linear chain execution: migrations are applied in registration order
|
||||||
|
* - Idempotent: already-migrated versions return false from shouldMigrate
|
||||||
|
* - Adjacent versions only: each migration handles N → N+1
|
||||||
|
* - Pure functions: migrations don't modify input objects
|
||||||
|
*/
|
||||||
|
export class MigrationScheduler {
|
||||||
|
/**
|
||||||
|
* Creates a new MigrationScheduler with the given migrations.
|
||||||
|
*
|
||||||
|
* @param migrations - Array of migrations in execution order (typically ascending version)
|
||||||
|
* @param scope - The scope of settings being migrated
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
private readonly migrations: SettingsMigration[],
|
||||||
|
private readonly scope: string,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the migration chain on the given settings.
|
||||||
|
*
|
||||||
|
* Iterates through all registered migrations in order. For each migration:
|
||||||
|
* 1. Calls `shouldMigrate` with the current settings
|
||||||
|
* 2. If true, calls `migrate` to transform the settings
|
||||||
|
* 3. Records the execution
|
||||||
|
*
|
||||||
|
* The scheduler itself has no version awareness - all version detection
|
||||||
|
* is delegated to the individual migrations.
|
||||||
|
*
|
||||||
|
* @param settings - The settings object to migrate
|
||||||
|
* @returns MigrationResult containing the final settings, version, and execution log
|
||||||
|
*/
|
||||||
|
migrate(settings: unknown): MigrationResult {
|
||||||
|
debugLogger.debug('MigrationScheduler: Starting migration chain');
|
||||||
|
|
||||||
|
let current = settings;
|
||||||
|
const executed: Array<{ fromVersion: number; toVersion: number }> = [];
|
||||||
|
const allWarnings: string[] = [];
|
||||||
|
|
||||||
|
for (const migration of this.migrations) {
|
||||||
|
try {
|
||||||
|
if (migration.shouldMigrate(current)) {
|
||||||
|
debugLogger.debug(
|
||||||
|
`MigrationScheduler: Executing migration ${migration.fromVersion} → ${migration.toVersion}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const formattedScope = formatScope(this.scope);
|
||||||
|
const result = migration.migrate(current, formattedScope);
|
||||||
|
current = result.settings;
|
||||||
|
allWarnings.push(...result.warnings);
|
||||||
|
|
||||||
|
executed.push({
|
||||||
|
fromVersion: migration.fromVersion,
|
||||||
|
toVersion: migration.toVersion,
|
||||||
|
});
|
||||||
|
|
||||||
|
debugLogger.debug(
|
||||||
|
`MigrationScheduler: Migration ${migration.fromVersion} → ${migration.toVersion} completed successfully`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
debugLogger.error(
|
||||||
|
`MigrationScheduler: Migration ${migration.fromVersion} → ${migration.toVersion} failed:`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine final version from the settings object
|
||||||
|
const finalVersion =
|
||||||
|
((current as Record<string, unknown>)['$version'] as number) ?? 1;
|
||||||
|
|
||||||
|
debugLogger.debug(
|
||||||
|
`MigrationScheduler: Migration chain complete. Final version: ${finalVersion}, Executed: ${executed.length} migrations`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
settings: current,
|
||||||
|
finalVersion,
|
||||||
|
executedMigrations: executed,
|
||||||
|
warnings: allWarnings,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
58
packages/cli/src/config/migration/types.ts
Normal file
58
packages/cli/src/config/migration/types.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface that all settings migrations must implement.
|
||||||
|
* Each migration handles a single version transition (N → N+1).
|
||||||
|
*/
|
||||||
|
export interface SettingsMigration {
|
||||||
|
/** Source version number */
|
||||||
|
readonly fromVersion: number;
|
||||||
|
|
||||||
|
/** Target version number */
|
||||||
|
readonly toVersion: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this migration should be applied to the given settings.
|
||||||
|
* The migration inspects the settings object to detect its current version
|
||||||
|
* and returns true if this migration is applicable.
|
||||||
|
*
|
||||||
|
* @param settings - The current settings object
|
||||||
|
* @returns true if this migration should be applied, false otherwise
|
||||||
|
*/
|
||||||
|
shouldMigrate(settings: unknown): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the migration transformation.
|
||||||
|
* This should be a pure function that does not modify the input object.
|
||||||
|
*
|
||||||
|
* @param settings - The current settings object of version N
|
||||||
|
* @param scope - The scope of settings being migrated
|
||||||
|
* @returns The migrated settings object of version N+1 with optional warnings
|
||||||
|
* @throws Error if the migration fails
|
||||||
|
*/
|
||||||
|
migrate(
|
||||||
|
settings: unknown,
|
||||||
|
scope: string,
|
||||||
|
): { settings: unknown; warnings: string[] };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Result of a migration execution by MigrationScheduler.
|
||||||
|
*/
|
||||||
|
export interface MigrationResult {
|
||||||
|
/** The final settings object after all applicable migrations */
|
||||||
|
settings: unknown;
|
||||||
|
|
||||||
|
/** The final version number after migrations */
|
||||||
|
finalVersion: number;
|
||||||
|
|
||||||
|
/** List of migrations that were executed */
|
||||||
|
executedMigrations: Array<{ fromVersion: number; toVersion: number }>;
|
||||||
|
|
||||||
|
/** List of warning messages generated during migration */
|
||||||
|
warnings: string[];
|
||||||
|
}
|
||||||
180
packages/cli/src/config/migration/versions/v1-to-v2-shared.ts
Normal file
180
packages/cli/src/config/migration/versions/v1-to-v2-shared.ts
Normal file
|
|
@ -0,0 +1,180 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Structural mapping table for V1 -> V2.
|
||||||
|
*
|
||||||
|
* Used by:
|
||||||
|
* - v1->v2 migration execution
|
||||||
|
* - warnings for residual legacy keys in latest-version settings files
|
||||||
|
*/
|
||||||
|
export const V1_TO_V2_MIGRATION_MAP: Record<string, string> = {
|
||||||
|
accessibility: 'ui.accessibility',
|
||||||
|
allowedTools: 'tools.allowed',
|
||||||
|
allowMCPServers: 'mcp.allowed',
|
||||||
|
autoAccept: 'tools.autoAccept',
|
||||||
|
autoConfigureMaxOldSpaceSize: 'advanced.autoConfigureMemory',
|
||||||
|
bugCommand: 'advanced.bugCommand',
|
||||||
|
chatCompression: 'model.chatCompression',
|
||||||
|
checkpointing: 'general.checkpointing',
|
||||||
|
coreTools: 'tools.core',
|
||||||
|
contextFileName: 'context.fileName',
|
||||||
|
customThemes: 'ui.customThemes',
|
||||||
|
customWittyPhrases: 'ui.customWittyPhrases',
|
||||||
|
debugKeystrokeLogging: 'general.debugKeystrokeLogging',
|
||||||
|
dnsResolutionOrder: 'advanced.dnsResolutionOrder',
|
||||||
|
enforcedAuthType: 'security.auth.enforcedType',
|
||||||
|
excludeTools: 'tools.exclude',
|
||||||
|
excludeMCPServers: 'mcp.excluded',
|
||||||
|
excludedProjectEnvVars: 'advanced.excludedEnvVars',
|
||||||
|
extensions: 'extensions',
|
||||||
|
fileFiltering: 'context.fileFiltering',
|
||||||
|
folderTrustFeature: 'security.folderTrust.featureEnabled',
|
||||||
|
folderTrust: 'security.folderTrust.enabled',
|
||||||
|
hasSeenIdeIntegrationNudge: 'ide.hasSeenNudge',
|
||||||
|
hideWindowTitle: 'ui.hideWindowTitle',
|
||||||
|
showStatusInTitle: 'ui.showStatusInTitle',
|
||||||
|
hideTips: 'ui.hideTips',
|
||||||
|
showLineNumbers: 'ui.showLineNumbers',
|
||||||
|
showCitations: 'ui.showCitations',
|
||||||
|
ideMode: 'ide.enabled',
|
||||||
|
includeDirectories: 'context.includeDirectories',
|
||||||
|
loadMemoryFromIncludeDirectories: 'context.loadFromIncludeDirectories',
|
||||||
|
maxSessionTurns: 'model.maxSessionTurns',
|
||||||
|
mcpServers: 'mcpServers',
|
||||||
|
mcpServerCommand: 'mcp.serverCommand',
|
||||||
|
memoryImportFormat: 'context.importFormat',
|
||||||
|
model: 'model.name',
|
||||||
|
preferredEditor: 'general.preferredEditor',
|
||||||
|
sandbox: 'tools.sandbox',
|
||||||
|
selectedAuthType: 'security.auth.selectedType',
|
||||||
|
shouldUseNodePtyShell: 'tools.shell.enableInteractiveShell',
|
||||||
|
shellPager: 'tools.shell.pager',
|
||||||
|
shellShowColor: 'tools.shell.showColor',
|
||||||
|
skipNextSpeakerCheck: 'model.skipNextSpeakerCheck',
|
||||||
|
summarizeToolOutput: 'model.summarizeToolOutput',
|
||||||
|
telemetry: 'telemetry',
|
||||||
|
theme: 'ui.theme',
|
||||||
|
toolDiscoveryCommand: 'tools.discoveryCommand',
|
||||||
|
toolCallCommand: 'tools.callCommand',
|
||||||
|
usageStatisticsEnabled: 'privacy.usageStatisticsEnabled',
|
||||||
|
useExternalAuth: 'security.auth.useExternal',
|
||||||
|
useRipgrep: 'tools.useRipgrep',
|
||||||
|
vimMode: 'general.vimMode',
|
||||||
|
enableWelcomeBack: 'ui.enableWelcomeBack',
|
||||||
|
approvalMode: 'tools.approvalMode',
|
||||||
|
sessionTokenLimit: 'model.sessionTokenLimit',
|
||||||
|
contentGenerator: 'model.generationConfig',
|
||||||
|
skipLoopDetection: 'model.skipLoopDetection',
|
||||||
|
skipStartupContext: 'model.skipStartupContext',
|
||||||
|
enableOpenAILogging: 'model.enableOpenAILogging',
|
||||||
|
tavilyApiKey: 'advanced.tavilyApiKey',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Top-level keys that are V2/V3 containers.
|
||||||
|
* If one of these keys already has object value, treat it as latest-format data.
|
||||||
|
*/
|
||||||
|
export const V2_CONTAINER_KEYS = new Set([
|
||||||
|
'ui',
|
||||||
|
'tools',
|
||||||
|
'mcp',
|
||||||
|
'advanced',
|
||||||
|
'model',
|
||||||
|
'general',
|
||||||
|
'context',
|
||||||
|
'security',
|
||||||
|
'ide',
|
||||||
|
'privacy',
|
||||||
|
'telemetry',
|
||||||
|
'extensions',
|
||||||
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Legacy disable* keys that remain in disable* form for V2.
|
||||||
|
*/
|
||||||
|
export const V1_TO_V2_PRESERVE_DISABLE_MAP: Record<string, string> = {
|
||||||
|
disableAutoUpdate: 'general.disableAutoUpdate',
|
||||||
|
disableUpdateNag: 'general.disableUpdateNag',
|
||||||
|
disableLoadingPhrases: 'ui.accessibility.disableLoadingPhrases',
|
||||||
|
disableFuzzySearch: 'context.fileFiltering.disableFuzzySearch',
|
||||||
|
disableCacheControl: 'model.generationConfig.disableCacheControl',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const CONSOLIDATED_DISABLE_KEYS = new Set([
|
||||||
|
'disableAutoUpdate',
|
||||||
|
'disableUpdateNag',
|
||||||
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keys that indicate V1-like top-level structure when holding primitive values.
|
||||||
|
*/
|
||||||
|
export const V1_INDICATOR_KEYS = [
|
||||||
|
// From V1_TO_V2_MIGRATION_MAP - keys that map to different paths in V2
|
||||||
|
'theme',
|
||||||
|
'model',
|
||||||
|
'autoAccept',
|
||||||
|
'hideTips',
|
||||||
|
'vimMode',
|
||||||
|
'checkpointing',
|
||||||
|
'accessibility',
|
||||||
|
'allowedTools',
|
||||||
|
'allowMCPServers',
|
||||||
|
'autoConfigureMaxOldSpaceSize',
|
||||||
|
'bugCommand',
|
||||||
|
'chatCompression',
|
||||||
|
'coreTools',
|
||||||
|
'contextFileName',
|
||||||
|
'customThemes',
|
||||||
|
'customWittyPhrases',
|
||||||
|
'debugKeystrokeLogging',
|
||||||
|
'dnsResolutionOrder',
|
||||||
|
'enforcedAuthType',
|
||||||
|
'excludeTools',
|
||||||
|
'excludeMCPServers',
|
||||||
|
'excludedProjectEnvVars',
|
||||||
|
'fileFiltering',
|
||||||
|
'folderTrustFeature',
|
||||||
|
'folderTrust',
|
||||||
|
'hasSeenIdeIntegrationNudge',
|
||||||
|
'hideWindowTitle',
|
||||||
|
'showStatusInTitle',
|
||||||
|
'showLineNumbers',
|
||||||
|
'showCitations',
|
||||||
|
'ideMode',
|
||||||
|
'includeDirectories',
|
||||||
|
'loadMemoryFromIncludeDirectories',
|
||||||
|
'maxSessionTurns',
|
||||||
|
'mcpServerCommand',
|
||||||
|
'memoryImportFormat',
|
||||||
|
'preferredEditor',
|
||||||
|
'sandbox',
|
||||||
|
'selectedAuthType',
|
||||||
|
'shouldUseNodePtyShell',
|
||||||
|
'shellPager',
|
||||||
|
'shellShowColor',
|
||||||
|
'skipNextSpeakerCheck',
|
||||||
|
'summarizeToolOutput',
|
||||||
|
'toolDiscoveryCommand',
|
||||||
|
'toolCallCommand',
|
||||||
|
'usageStatisticsEnabled',
|
||||||
|
'useExternalAuth',
|
||||||
|
'useRipgrep',
|
||||||
|
'enableWelcomeBack',
|
||||||
|
'approvalMode',
|
||||||
|
'sessionTokenLimit',
|
||||||
|
'contentGenerator',
|
||||||
|
'skipLoopDetection',
|
||||||
|
'skipStartupContext',
|
||||||
|
'enableOpenAILogging',
|
||||||
|
'tavilyApiKey',
|
||||||
|
// From V1_TO_V2_PRESERVE_DISABLE_MAP - disable* keys that get nested in V2
|
||||||
|
'disableAutoUpdate',
|
||||||
|
'disableUpdateNag',
|
||||||
|
'disableLoadingPhrases',
|
||||||
|
'disableFuzzySearch',
|
||||||
|
'disableCacheControl',
|
||||||
|
];
|
||||||
277
packages/cli/src/config/migration/versions/v1-to-v2.test.ts
Normal file
277
packages/cli/src/config/migration/versions/v1-to-v2.test.ts
Normal file
|
|
@ -0,0 +1,277 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { V1ToV2Migration } from './v1-to-v2.js';
|
||||||
|
|
||||||
|
describe('V1ToV2Migration', () => {
|
||||||
|
const migration = new V1ToV2Migration();
|
||||||
|
|
||||||
|
describe('shouldMigrate', () => {
|
||||||
|
it('should return true for V1 settings without version and with V1 keys', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
model: 'gemini',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(migration.shouldMigrate(v1Settings)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for V1 settings with disable* keys', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
disableLoadingPhrases: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(migration.shouldMigrate(v1Settings)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for settings with $version field', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
ui: { theme: 'dark' },
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(migration.shouldMigrate(v2Settings)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for V3 settings', () => {
|
||||||
|
const v3Settings = {
|
||||||
|
$version: 3,
|
||||||
|
general: { enableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(migration.shouldMigrate(v3Settings)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for settings without V1 indicator keys', () => {
|
||||||
|
const unknownSettings = {
|
||||||
|
customKey: 'value',
|
||||||
|
anotherKey: 123,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(migration.shouldMigrate(unknownSettings)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for null input', () => {
|
||||||
|
expect(migration.shouldMigrate(null)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for non-object input', () => {
|
||||||
|
expect(migration.shouldMigrate('string')).toBe(false);
|
||||||
|
expect(migration.shouldMigrate(123)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('migrate', () => {
|
||||||
|
it('should migrate flat V1 keys to nested V2 structure', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
model: 'gemini',
|
||||||
|
autoAccept: true,
|
||||||
|
hideTips: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(2);
|
||||||
|
expect(result['ui']).toEqual({ theme: 'dark', hideTips: false });
|
||||||
|
expect(result['model']).toEqual({ name: 'gemini' });
|
||||||
|
expect(result['tools']).toEqual({ autoAccept: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should migrate disable* keys to nested V2 paths without inversion', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'light',
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
disableLoadingPhrases: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(2);
|
||||||
|
expect(result['general']).toEqual({ disableAutoUpdate: true });
|
||||||
|
expect(result['ui']).toEqual({
|
||||||
|
theme: 'light',
|
||||||
|
accessibility: { disableLoadingPhrases: false },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should normalize consolidated disable* non-boolean values to false', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
disableAutoUpdate: 'false',
|
||||||
|
disableUpdateNag: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(2);
|
||||||
|
expect(result['general']).toEqual({
|
||||||
|
disableAutoUpdate: false,
|
||||||
|
disableUpdateNag: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should drop non-boolean non-consolidated disable* values', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
disableLoadingPhrases: 'TRUE',
|
||||||
|
disableFuzzySearch: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(2);
|
||||||
|
expect(
|
||||||
|
(result['ui'] as Record<string, unknown>)?.['accessibility'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(result['context'] as Record<string, unknown>)?.[
|
||||||
|
'fileFiltering'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)?.['disableFuzzySearch'],
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve mcpServers at top level', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
mcpServers: {
|
||||||
|
myServer: { command: 'node', args: ['server.js'] },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(2);
|
||||||
|
expect(result['mcpServers']).toEqual({
|
||||||
|
myServer: { command: 'node', args: ['server.js'] },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve unrecognized keys', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
myCustomSetting: 'value',
|
||||||
|
anotherCustom: 123,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(2);
|
||||||
|
expect(result['myCustomSetting']).toBe('value');
|
||||||
|
expect(result['anotherCustom']).toBe(123);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve non-object parent path values on collision', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
ui: 'legacy-ui-string',
|
||||||
|
general: 'legacy-general-string',
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(2);
|
||||||
|
expect(result['ui']).toBe('legacy-ui-string');
|
||||||
|
expect(result['general']).toBe('legacy-general-string');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not modify the input object', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
model: 'gemini',
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(v1Settings).toEqual({ theme: 'dark', model: 'gemini' });
|
||||||
|
expect(result).not.toBe(v1Settings);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw error for non-object input', () => {
|
||||||
|
expect(() => migration.migrate(null, 'user')).toThrow(
|
||||||
|
'Settings must be an object',
|
||||||
|
);
|
||||||
|
expect(() => migration.migrate('string', 'user')).toThrow(
|
||||||
|
'Settings must be an object',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle empty V1 settings', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(2);
|
||||||
|
expect(result['ui']).toEqual({ theme: 'dark' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correctly handle all V1 indicator keys', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
model: 'gemini',
|
||||||
|
autoAccept: true,
|
||||||
|
hideTips: false,
|
||||||
|
vimMode: true,
|
||||||
|
checkpointing: false,
|
||||||
|
telemetry: {},
|
||||||
|
accessibility: {},
|
||||||
|
extensions: [],
|
||||||
|
mcpServers: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v1Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('version properties', () => {
|
||||||
|
it('should have correct fromVersion', () => {
|
||||||
|
expect(migration.fromVersion).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have correct toVersion', () => {
|
||||||
|
expect(migration.toVersion).toBe(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
267
packages/cli/src/config/migration/versions/v1-to-v2.ts
Normal file
267
packages/cli/src/config/migration/versions/v1-to-v2.ts
Normal file
|
|
@ -0,0 +1,267 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { SettingsMigration } from '../types.js';
|
||||||
|
import {
|
||||||
|
CONSOLIDATED_DISABLE_KEYS,
|
||||||
|
V1_INDICATOR_KEYS,
|
||||||
|
V1_TO_V2_MIGRATION_MAP,
|
||||||
|
V1_TO_V2_PRESERVE_DISABLE_MAP,
|
||||||
|
V2_CONTAINER_KEYS,
|
||||||
|
} from './v1-to-v2-shared.js';
|
||||||
|
import { setNestedPropertySafe } from '../../../utils/settingsUtils.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Heuristic indicators for deciding whether an object is "V1-like".
|
||||||
|
*
|
||||||
|
* Detection strategy:
|
||||||
|
* - A file is considered migratable as V1 when:
|
||||||
|
* 1) It is not explicitly versioned as V2+ (`$version` is missing or invalid), and
|
||||||
|
* 2) At least one indicator key appears in a legacy-compatible top-level shape.
|
||||||
|
* - Indicator list intentionally excludes keys that are valid top-level entries in
|
||||||
|
* both old and new structures to reduce false positives.
|
||||||
|
*
|
||||||
|
* Shape rule:
|
||||||
|
* - Object values for indicator keys are treated as already-nested V2-like content
|
||||||
|
* and do not alone trigger migration.
|
||||||
|
* - Primitive/array/null values on indicator keys are treated as legacy V1 signals.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* V1 -> V2 migration (structural normalization stage).
|
||||||
|
*
|
||||||
|
* Migration contract:
|
||||||
|
* - Input: settings in legacy V1-like shape (mostly flat, may contain mixed partial V2).
|
||||||
|
* - Output: V2-compatible nested structure with `$version: 2`.
|
||||||
|
* - No semantic inversion of disable* naming in this stage.
|
||||||
|
*
|
||||||
|
* Data-preservation strategy:
|
||||||
|
* - Prefer transforming known keys into canonical V2 locations.
|
||||||
|
* - Preserve unrecognized keys verbatim.
|
||||||
|
* - Preserve parent-path scalar values when nested writes would collide with them.
|
||||||
|
* - Preserve/merge existing partial V2 objects where safe.
|
||||||
|
*
|
||||||
|
* This class intentionally optimizes for backward compatibility and non-destructive
|
||||||
|
* behavior over aggressive normalization.
|
||||||
|
*/
|
||||||
|
export class V1ToV2Migration implements SettingsMigration {
|
||||||
|
readonly fromVersion = 1;
|
||||||
|
readonly toVersion = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this migration should execute.
|
||||||
|
*
|
||||||
|
* Decision strategy:
|
||||||
|
* - Hard-stop when `$version` is a number >= 2 (already V2+).
|
||||||
|
* - Otherwise, scan indicator keys and trigger only when at least one indicator is
|
||||||
|
* still in legacy top-level shape (primitive/array/null).
|
||||||
|
*
|
||||||
|
* Mixed-shape tolerance:
|
||||||
|
* - Files that are partially migrated are supported; V2-like object-valued indicators
|
||||||
|
* are ignored while legacy-shaped indicators can still trigger migration.
|
||||||
|
*/
|
||||||
|
shouldMigrate(settings: unknown): boolean {
|
||||||
|
if (typeof settings !== 'object' || settings === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const s = settings as Record<string, unknown>;
|
||||||
|
|
||||||
|
// If $version exists and is a number >= 2, it's not V1
|
||||||
|
const version = s['$version'];
|
||||||
|
if (typeof version === 'number' && version >= 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for V1 indicator keys with primitive values
|
||||||
|
// A setting is considered V1 if ANY indicator key has a primitive value
|
||||||
|
// (string, number, boolean, null, or array) at the top level.
|
||||||
|
// Keys with object values are skipped as they may already be in V2 format.
|
||||||
|
return V1_INDICATOR_KEYS.some((key) => {
|
||||||
|
if (!(key in s)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const value = s[key];
|
||||||
|
// Skip keys with object values - they may already be in V2 nested format
|
||||||
|
// But don't let them block migration of other keys
|
||||||
|
if (
|
||||||
|
typeof value === 'object' &&
|
||||||
|
value !== null &&
|
||||||
|
!Array.isArray(value)
|
||||||
|
) {
|
||||||
|
// This key appears to be in V2 format, skip it but continue
|
||||||
|
// checking other keys
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Found a key with primitive value - this is V1 format
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs non-destructive V1 -> V2 transformation.
|
||||||
|
*
|
||||||
|
* Detailed strategy:
|
||||||
|
* 1) Relocate known V1 keys using `V1_TO_V2_MIGRATION_MAP`.
|
||||||
|
* - If a source value is already an object and maps to a child path of itself
|
||||||
|
* (partial V2 shape), merge child properties into target path.
|
||||||
|
* 2) Relocate disable* keys into V2 disable* locations.
|
||||||
|
* - Consolidated keys (`disableAutoUpdate`, `disableUpdateNag`): normalize to
|
||||||
|
* boolean with stable-compatible presence semantics (`value === true`).
|
||||||
|
* - Other disable* keys: migrate only boolean values.
|
||||||
|
* 3) Preserve `mcpServers` top-level placement.
|
||||||
|
* 4) Carry over remaining keys:
|
||||||
|
* - If a key is parent of migrated nested paths, merge unprocessed object children.
|
||||||
|
* - If parent value is non-object, preserve that scalar/array/null as-is.
|
||||||
|
* - Otherwise copy untouched key/value.
|
||||||
|
* 5) Stamp `$version = 2`.
|
||||||
|
*
|
||||||
|
* The method is pure with respect to input mutation.
|
||||||
|
*/
|
||||||
|
migrate(
|
||||||
|
settings: unknown,
|
||||||
|
_scope: string,
|
||||||
|
): { settings: unknown; warnings: string[] } {
|
||||||
|
if (typeof settings !== 'object' || settings === null) {
|
||||||
|
throw new Error('Settings must be an object');
|
||||||
|
}
|
||||||
|
|
||||||
|
const source = settings as Record<string, unknown>;
|
||||||
|
const result: Record<string, unknown> = {};
|
||||||
|
const processedKeys = new Set<string>();
|
||||||
|
const warnings: string[] = [];
|
||||||
|
|
||||||
|
// Step 1: Map known V1 keys to V2 nested paths
|
||||||
|
for (const [v1Key, v2Path] of Object.entries(V1_TO_V2_MIGRATION_MAP)) {
|
||||||
|
if (v1Key in source) {
|
||||||
|
const value = source[v1Key];
|
||||||
|
|
||||||
|
// Safety check: If this key is a V2 container (like 'model') and it's
|
||||||
|
// already an object, it's likely already in V2 format. Skip migration
|
||||||
|
// to prevent double-nesting (e.g., model.name.name).
|
||||||
|
if (
|
||||||
|
V2_CONTAINER_KEYS.has(v1Key) &&
|
||||||
|
typeof value === 'object' &&
|
||||||
|
value !== null &&
|
||||||
|
!Array.isArray(value)
|
||||||
|
) {
|
||||||
|
// This is already a V2 container, carry it over as-is
|
||||||
|
result[v1Key] = value;
|
||||||
|
processedKeys.add(v1Key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If value is already an object and the path matches the key,
|
||||||
|
// it might be a partial V2 structure. Merge its contents.
|
||||||
|
if (
|
||||||
|
typeof value === 'object' &&
|
||||||
|
value !== null &&
|
||||||
|
!Array.isArray(value) &&
|
||||||
|
v2Path.startsWith(v1Key + '.')
|
||||||
|
) {
|
||||||
|
// Merge nested properties from this partial V2 structure
|
||||||
|
for (const [nestedKey, nestedValue] of Object.entries(value)) {
|
||||||
|
setNestedPropertySafe(
|
||||||
|
result,
|
||||||
|
`${v2Path}.${nestedKey}`,
|
||||||
|
nestedValue,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setNestedPropertySafe(result, v2Path, value);
|
||||||
|
}
|
||||||
|
processedKeys.add(v1Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Map V1 disable* keys to V2 nested disable* paths
|
||||||
|
for (const [v1Key, v2Path] of Object.entries(
|
||||||
|
V1_TO_V2_PRESERVE_DISABLE_MAP,
|
||||||
|
)) {
|
||||||
|
if (v1Key in source) {
|
||||||
|
const value = source[v1Key];
|
||||||
|
if (CONSOLIDATED_DISABLE_KEYS.has(v1Key)) {
|
||||||
|
// Preserve stable behavior: consolidated keys use presence semantics.
|
||||||
|
// Only literal true remains true; all other present values become false.
|
||||||
|
setNestedPropertySafe(result, v2Path, value === true);
|
||||||
|
} else if (typeof value === 'boolean') {
|
||||||
|
// Non-consolidated disable* keys only migrate when explicitly boolean.
|
||||||
|
setNestedPropertySafe(result, v2Path, value);
|
||||||
|
}
|
||||||
|
processedKeys.add(v1Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 3: Preserve mcpServers at the top level
|
||||||
|
if ('mcpServers' in source) {
|
||||||
|
result['mcpServers'] = source['mcpServers'];
|
||||||
|
processedKeys.add('mcpServers');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4: Carry over any unrecognized keys (including unknown nested objects)
|
||||||
|
// Important: Skip keys that are parent paths of already-migrated properties
|
||||||
|
// to avoid overwriting merged structures (e.g., 'ui' should not overwrite 'ui.theme')
|
||||||
|
for (const key of Object.keys(source)) {
|
||||||
|
if (!processedKeys.has(key)) {
|
||||||
|
// Check if this key is a parent of any already-migrated path
|
||||||
|
const isParentOfMigratedPath = Array.from(processedKeys).some(
|
||||||
|
(processedKey) => {
|
||||||
|
// Get the v2 path for this processed key
|
||||||
|
const v2Path =
|
||||||
|
V1_TO_V2_MIGRATION_MAP[processedKey] ||
|
||||||
|
V1_TO_V2_PRESERVE_DISABLE_MAP[processedKey];
|
||||||
|
if (!v2Path) return false;
|
||||||
|
// Check if the v2 path starts with this key + '.'
|
||||||
|
return v2Path.startsWith(key + '.');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isParentOfMigratedPath) {
|
||||||
|
// This key is a parent of an already-migrated path
|
||||||
|
// Merge its unprocessed children instead of overwriting
|
||||||
|
const existingValue = source[key];
|
||||||
|
if (
|
||||||
|
typeof existingValue === 'object' &&
|
||||||
|
existingValue !== null &&
|
||||||
|
!Array.isArray(existingValue)
|
||||||
|
) {
|
||||||
|
for (const [nestedKey, nestedValue] of Object.entries(
|
||||||
|
existingValue,
|
||||||
|
)) {
|
||||||
|
// Only merge if this nested key wasn't already processed
|
||||||
|
const fullNestedPath = `${key}.${nestedKey}`;
|
||||||
|
const wasProcessed = Array.from(processedKeys).some(
|
||||||
|
(processedKey) => {
|
||||||
|
const v2Path =
|
||||||
|
V1_TO_V2_MIGRATION_MAP[processedKey] ||
|
||||||
|
V1_TO_V2_PRESERVE_DISABLE_MAP[processedKey];
|
||||||
|
return v2Path === fullNestedPath;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (!wasProcessed) {
|
||||||
|
setNestedPropertySafe(result, fullNestedPath, nestedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Preserve non-object parent values to match legacy overwrite semantics.
|
||||||
|
result[key] = source[key];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not a parent path, safe to copy as-is
|
||||||
|
result[key] = source[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 5: Set version to 2
|
||||||
|
result['$version'] = 2;
|
||||||
|
|
||||||
|
return { settings: result, warnings };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Singleton instance of V1→V2 migration */
|
||||||
|
export const v1ToV2Migration = new V1ToV2Migration();
|
||||||
598
packages/cli/src/config/migration/versions/v2-to-v3.test.ts
Normal file
598
packages/cli/src/config/migration/versions/v2-to-v3.test.ts
Normal file
|
|
@ -0,0 +1,598 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { V2ToV3Migration } from './v2-to-v3.js';
|
||||||
|
|
||||||
|
describe('V2ToV3Migration', () => {
|
||||||
|
const migration = new V2ToV3Migration();
|
||||||
|
|
||||||
|
describe('shouldMigrate', () => {
|
||||||
|
it('should return true for V2 settings with deprecated disable* keys', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(migration.shouldMigrate(v2Settings)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for V2 settings with ui.accessibility.disableLoadingPhrases', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
ui: { accessibility: { disableLoadingPhrases: false } },
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(migration.shouldMigrate(v2Settings)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for V3 settings', () => {
|
||||||
|
const v3Settings = {
|
||||||
|
$version: 3,
|
||||||
|
general: { enableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(migration.shouldMigrate(v3Settings)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for V1 settings without version', () => {
|
||||||
|
const v1Settings = {
|
||||||
|
theme: 'dark',
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(migration.shouldMigrate(v1Settings)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for V2 settings without deprecated keys', () => {
|
||||||
|
const cleanV2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
ui: { theme: 'dark' },
|
||||||
|
general: { enableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
// V2 settings should always be migrated to V3 to update the version number
|
||||||
|
expect(migration.shouldMigrate(cleanV2Settings)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for null input', () => {
|
||||||
|
expect(migration.shouldMigrate(null)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for non-object input', () => {
|
||||||
|
expect(migration.shouldMigrate('string')).toBe(false);
|
||||||
|
expect(migration.shouldMigrate(123)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('migrate', () => {
|
||||||
|
it('should migrate disableAutoUpdate to enableAutoUpdate with inverted value', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v2Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should migrate disableLoadingPhrases to enableLoadingPhrases', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
ui: { accessibility: { disableLoadingPhrases: true } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v2Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['ui'] as Record<string, unknown>)['accessibility'],
|
||||||
|
).toEqual({
|
||||||
|
enableLoadingPhrases: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should migrate disableFuzzySearch to enableFuzzySearch', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
context: { fileFiltering: { disableFuzzySearch: false } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v2Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['context'] as Record<string, unknown>)['fileFiltering'],
|
||||||
|
).toEqual({
|
||||||
|
enableFuzzySearch: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should migrate disableCacheControl to enableCacheControl', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
model: { generationConfig: { disableCacheControl: true } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v2Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['model'] as Record<string, unknown>)['generationConfig'],
|
||||||
|
).toEqual({
|
||||||
|
enableCacheControl: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle consolidated disableAutoUpdate and disableUpdateNag', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: {
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
disableUpdateNag: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v2Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
// If ANY disable* is true, enable should be false
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableUpdateNag'],
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set enableAutoUpdate to true when both disable* are false', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: {
|
||||||
|
disableAutoUpdate: false,
|
||||||
|
disableUpdateNag: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v2Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve other settings during migration', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
ui: {
|
||||||
|
theme: 'dark',
|
||||||
|
accessibility: { disableLoadingPhrases: true },
|
||||||
|
},
|
||||||
|
model: {
|
||||||
|
name: 'gemini',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v2Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect((result['ui'] as Record<string, unknown>)['theme']).toBe('dark');
|
||||||
|
expect((result['model'] as Record<string, unknown>)['name']).toBe(
|
||||||
|
'gemini',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
(result['ui'] as Record<string, unknown>)['accessibility'],
|
||||||
|
).toEqual({
|
||||||
|
enableLoadingPhrases: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not modify the input object', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = migration.migrate(v2Settings, 'user');
|
||||||
|
|
||||||
|
expect(v2Settings.general).toEqual({ disableAutoUpdate: true });
|
||||||
|
expect(result).not.toBe(v2Settings);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw error for non-object input', () => {
|
||||||
|
expect(() => migration.migrate(null, 'user')).toThrow(
|
||||||
|
'Settings must be an object',
|
||||||
|
);
|
||||||
|
expect(() => migration.migrate('string', 'user')).toThrow(
|
||||||
|
'Settings must be an object',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle multiple deprecated keys in one migration', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: false },
|
||||||
|
ui: { accessibility: { disableLoadingPhrases: false } },
|
||||||
|
context: { fileFiltering: { disableFuzzySearch: false } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result } = migration.migrate(v2Settings, 'user') as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
(result['ui'] as Record<string, unknown>)['accessibility'],
|
||||||
|
).toEqual({
|
||||||
|
enableLoadingPhrases: true,
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
(result['context'] as Record<string, unknown>)['fileFiltering'],
|
||||||
|
).toEqual({
|
||||||
|
enableFuzzySearch: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should coerce string "true" and remove deprecated key', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: 'true' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(false);
|
||||||
|
expect(warnings).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should coerce string "false" and remove deprecated key', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: 'false' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(true);
|
||||||
|
expect(warnings).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should coerce case-insensitive strings for consolidated keys', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: {
|
||||||
|
disableAutoUpdate: 'TRUE',
|
||||||
|
disableUpdateNag: 'FALSE',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableUpdateNag'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(false);
|
||||||
|
expect(warnings).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove number value and emit warning', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: 123 },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(warnings).toHaveLength(1);
|
||||||
|
expect(warnings[0]).toContain('general.disableAutoUpdate');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove invalid string value and emit warning', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: 'invalid-string' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(warnings).toHaveLength(1);
|
||||||
|
expect(warnings[0]).toContain('general.disableAutoUpdate');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should coerce disableCacheControl string "true"', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
model: { generationConfig: { disableCacheControl: 'true' } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['model'] as Record<string, unknown>)['generationConfig'],
|
||||||
|
).toEqual({
|
||||||
|
enableCacheControl: false,
|
||||||
|
});
|
||||||
|
expect(warnings).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should coerce disableCacheControl string "false"', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
model: { generationConfig: { disableCacheControl: 'false' } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['model'] as Record<string, unknown>)['generationConfig'],
|
||||||
|
).toEqual({
|
||||||
|
enableCacheControl: true,
|
||||||
|
});
|
||||||
|
expect(warnings).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove disableCacheControl number value and emit warning', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
model: { generationConfig: { disableCacheControl: 456 } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['model'] as Record<string, unknown>)['generationConfig'],
|
||||||
|
).toEqual({});
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
(result['model'] as Record<string, unknown>)[
|
||||||
|
'generationConfig'
|
||||||
|
] as Record<string, unknown>
|
||||||
|
)['enableCacheControl'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(warnings).toHaveLength(1);
|
||||||
|
expect(warnings[0]).toContain(
|
||||||
|
'model.generationConfig.disableCacheControl',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle mixed valid and invalid disableAutoUpdate and disableUpdateNag', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: {
|
||||||
|
disableAutoUpdate: true,
|
||||||
|
disableUpdateNag: 'invalid',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
// Only valid values should contribute to the consolidated result
|
||||||
|
// Since disableAutoUpdate is true, enableAutoUpdate should be false
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableUpdateNag'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(warnings).toHaveLength(1);
|
||||||
|
expect(warnings[0]).toContain('general.disableUpdateNag');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove object value for disable key and emit warning', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: { nested: 'value' } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(warnings).toHaveLength(1);
|
||||||
|
expect(warnings[0]).toContain('general.disableAutoUpdate');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove array value for disable key and emit warning', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: [1, 2, 3] },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(warnings).toHaveLength(1);
|
||||||
|
expect(warnings[0]).toContain('general.disableAutoUpdate');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove null value for disable key and emit warning', () => {
|
||||||
|
const v2Settings = {
|
||||||
|
$version: 2,
|
||||||
|
general: { disableAutoUpdate: null },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { settings: result, warnings } = migration.migrate(
|
||||||
|
v2Settings,
|
||||||
|
'user',
|
||||||
|
) as {
|
||||||
|
settings: Record<string, unknown>;
|
||||||
|
warnings: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result['$version']).toBe(3);
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['disableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
(result['general'] as Record<string, unknown>)['enableAutoUpdate'],
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(warnings).toHaveLength(1);
|
||||||
|
expect(warnings[0]).toContain('general.disableAutoUpdate');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('version properties', () => {
|
||||||
|
it('should have correct fromVersion', () => {
|
||||||
|
expect(migration.fromVersion).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have correct toVersion', () => {
|
||||||
|
expect(migration.toVersion).toBe(3);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
222
packages/cli/src/config/migration/versions/v2-to-v3.ts
Normal file
222
packages/cli/src/config/migration/versions/v2-to-v3.ts
Normal file
|
|
@ -0,0 +1,222 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { SettingsMigration } from '../types.js';
|
||||||
|
import {
|
||||||
|
deleteNestedPropertySafe,
|
||||||
|
getNestedProperty,
|
||||||
|
setNestedPropertySafe,
|
||||||
|
} from '../../../utils/settingsUtils.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path mapping for boolean polarity migration (V2 disable* -> V3 enable*).
|
||||||
|
*
|
||||||
|
* Strategy:
|
||||||
|
* - For each mapped path, values are normalized before migration:
|
||||||
|
* - boolean values are accepted directly
|
||||||
|
* - string values "true"/"false" (case-insensitive, trim-aware) are coerced
|
||||||
|
* - all other present values are treated as invalid
|
||||||
|
* - Transformation is inversion-based: disable=true -> enable=false, disable=false -> enable=true.
|
||||||
|
* - Deprecated disable* keys are removed whenever present (valid or invalid).
|
||||||
|
* - Invalid values do not create enable* keys and produce warnings.
|
||||||
|
*/
|
||||||
|
const V2_TO_V3_BOOLEAN_MAP: Record<string, string> = {
|
||||||
|
'general.disableAutoUpdate': 'general.enableAutoUpdate',
|
||||||
|
'general.disableUpdateNag': 'general.enableAutoUpdate',
|
||||||
|
'ui.accessibility.disableLoadingPhrases':
|
||||||
|
'ui.accessibility.enableLoadingPhrases',
|
||||||
|
'context.fileFiltering.disableFuzzySearch':
|
||||||
|
'context.fileFiltering.enableFuzzySearch',
|
||||||
|
'model.generationConfig.disableCacheControl':
|
||||||
|
'model.generationConfig.enableCacheControl',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consolidated old paths that collapse into one V3 field.
|
||||||
|
*
|
||||||
|
* Current policy:
|
||||||
|
* - `general.disableAutoUpdate` and `general.disableUpdateNag` both drive
|
||||||
|
* `general.enableAutoUpdate`.
|
||||||
|
* - If any valid normalized source is true, target becomes false.
|
||||||
|
* - If at least one valid normalized source exists, consolidated target is emitted.
|
||||||
|
* - Invalid present values are removed and warned, and do not contribute to target calculation.
|
||||||
|
*/
|
||||||
|
const CONSOLIDATED_V2_PATHS: Record<string, string[]> = {
|
||||||
|
'general.enableAutoUpdate': [
|
||||||
|
'general.disableAutoUpdate',
|
||||||
|
'general.disableUpdateNag',
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes deprecated disable* values for migration.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* - `isPresent=false` when the path does not exist
|
||||||
|
* - `isPresent=true, isValid=true` when value is boolean or coercible string
|
||||||
|
* - `isPresent=true, isValid=false` for invalid values (number/object/array/null/other strings)
|
||||||
|
*/
|
||||||
|
function normalizeDisableValue(value: unknown): {
|
||||||
|
isPresent: boolean;
|
||||||
|
isValid: boolean;
|
||||||
|
booleanValue?: boolean;
|
||||||
|
} {
|
||||||
|
if (value === undefined) {
|
||||||
|
return { isPresent: false, isValid: false };
|
||||||
|
}
|
||||||
|
if (typeof value === 'boolean') {
|
||||||
|
return { isPresent: true, isValid: true, booleanValue: value };
|
||||||
|
}
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
const normalized = value.trim().toLowerCase();
|
||||||
|
if (normalized === 'true') {
|
||||||
|
return { isPresent: true, isValid: true, booleanValue: true };
|
||||||
|
}
|
||||||
|
if (normalized === 'false') {
|
||||||
|
return { isPresent: true, isValid: true, booleanValue: false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { isPresent: true, isValid: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* V2 -> V3 migration (boolean polarity normalization stage).
|
||||||
|
*
|
||||||
|
* Migration contract:
|
||||||
|
* - Input: V2 settings object (`$version: 2`).
|
||||||
|
* - Output: `$version: 3` with deprecated disable* fields removed and
|
||||||
|
* valid values migrated to enable* equivalents.
|
||||||
|
*
|
||||||
|
* Compatibility strategy:
|
||||||
|
* - Accept boolean values and coercible strings "true"/"false".
|
||||||
|
* - Remove invalid deprecated values (rather than preserving them).
|
||||||
|
* - Emit warnings for each removed invalid deprecated key.
|
||||||
|
* - Always bump version to 3 so future loads are idempotent and skip repeated checks.
|
||||||
|
*/
|
||||||
|
export class V2ToV3Migration implements SettingsMigration {
|
||||||
|
readonly fromVersion = 2;
|
||||||
|
readonly toVersion = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migration trigger rule.
|
||||||
|
*
|
||||||
|
* Execute only when `$version === 2`.
|
||||||
|
* This includes V2 files with no migratable disable* booleans so that version
|
||||||
|
* metadata still advances to 3.
|
||||||
|
*/
|
||||||
|
shouldMigrate(settings: unknown): boolean {
|
||||||
|
if (typeof settings !== 'object' || settings === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const s = settings as Record<string, unknown>;
|
||||||
|
|
||||||
|
// Migrate if $version is 2
|
||||||
|
return s['$version'] === 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies V2 -> V3 transformation with deterministic deprecated-key cleanup.
|
||||||
|
*
|
||||||
|
* Detailed strategy:
|
||||||
|
* 1) Clone input.
|
||||||
|
* 2) Process consolidated paths first:
|
||||||
|
* - Inspect each source path.
|
||||||
|
* - Normalize each present value (boolean / coercible string / invalid).
|
||||||
|
* - Always delete present deprecated source key.
|
||||||
|
* - Valid normalized values contribute to aggregate.
|
||||||
|
* - Invalid values emit warnings.
|
||||||
|
* - Emit consolidated target when at least one valid source was consumed.
|
||||||
|
* 3) Process remaining one-to-one mappings:
|
||||||
|
* - For each unmapped source, normalize value.
|
||||||
|
* - If valid -> delete old key and write inverted target.
|
||||||
|
* - If invalid -> delete old key and emit warning.
|
||||||
|
* 4) Set `$version = 3`.
|
||||||
|
*
|
||||||
|
* Guarantees:
|
||||||
|
* - Input object is not mutated.
|
||||||
|
* - Valid migration and invalid cleanup are deterministic.
|
||||||
|
* - Deprecated disable* keys are not retained after migration.
|
||||||
|
*/
|
||||||
|
migrate(
|
||||||
|
settings: unknown,
|
||||||
|
scope: string,
|
||||||
|
): { settings: unknown; warnings: string[] } {
|
||||||
|
if (typeof settings !== 'object' || settings === null) {
|
||||||
|
throw new Error('Settings must be an object');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deep clone to avoid mutating input
|
||||||
|
const result = structuredClone(settings) as Record<string, unknown>;
|
||||||
|
const processedPaths = new Set<string>();
|
||||||
|
const warnings: string[] = [];
|
||||||
|
|
||||||
|
// Step 1: Handle consolidated paths (multiple old paths → single new path)
|
||||||
|
// Policy: if ANY of the old disable* settings is true, the new enable* should be false
|
||||||
|
for (const [newPath, oldPaths] of Object.entries(CONSOLIDATED_V2_PATHS)) {
|
||||||
|
let hasAnyDisable = false;
|
||||||
|
let hasAnyBooleanValue = false;
|
||||||
|
|
||||||
|
for (const oldPath of oldPaths) {
|
||||||
|
const oldValue = getNestedProperty(result, oldPath);
|
||||||
|
const normalized = normalizeDisableValue(oldValue);
|
||||||
|
if (!normalized.isPresent) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteNestedPropertySafe(result, oldPath);
|
||||||
|
processedPaths.add(oldPath);
|
||||||
|
|
||||||
|
if (normalized.isValid) {
|
||||||
|
hasAnyBooleanValue = true;
|
||||||
|
if (normalized.booleanValue === true) {
|
||||||
|
hasAnyDisable = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warnings.push(
|
||||||
|
`Removed deprecated setting '${oldPath}' from ${scope} settings because the value is invalid. Expected boolean.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasAnyBooleanValue) {
|
||||||
|
// enableAutoUpdate = !hasAnyDisable (if any disable* was true, enable should be false)
|
||||||
|
setNestedPropertySafe(result, newPath, !hasAnyDisable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Handle remaining individual disable* → enable* mappings
|
||||||
|
for (const [oldPath, newPath] of Object.entries(V2_TO_V3_BOOLEAN_MAP)) {
|
||||||
|
if (processedPaths.has(oldPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const oldValue = getNestedProperty(result, oldPath);
|
||||||
|
const normalized = normalizeDisableValue(oldValue);
|
||||||
|
if (!normalized.isPresent) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteNestedPropertySafe(result, oldPath);
|
||||||
|
if (normalized.isValid) {
|
||||||
|
// Set new property with inverted value
|
||||||
|
setNestedPropertySafe(result, newPath, !normalized.booleanValue);
|
||||||
|
} else {
|
||||||
|
warnings.push(
|
||||||
|
`Removed deprecated setting '${oldPath}' from ${scope} settings because the value is invalid. Expected boolean or string "true"/"false".`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 3: Always update version to 3
|
||||||
|
result['$version'] = 3;
|
||||||
|
|
||||||
|
return { settings: result, warnings };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Singleton instance of V2→V3 migration */
|
||||||
|
export const v2ToV3Migration = new V2ToV3Migration();
|
||||||
|
|
@ -18,16 +18,6 @@ vi.mock('os', async (importOriginal) => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mock './settings.js' to ensure it uses the mocked 'os.homedir()' for its internal constants.
|
|
||||||
vi.mock('./settings.js', async (importActual) => {
|
|
||||||
const originalModule = await importActual<typeof import('./settings.js')>();
|
|
||||||
return {
|
|
||||||
__esModule: true, // Ensure correct module shape
|
|
||||||
...originalModule, // Re-export all original members
|
|
||||||
// We are relying on originalModule's USER_SETTINGS_PATH being constructed with mocked os.homedir()
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mock trustedFolders
|
// Mock trustedFolders
|
||||||
vi.mock('./trustedFolders.js', () => ({
|
vi.mock('./trustedFolders.js', () => ({
|
||||||
isWorkspaceTrusted: vi
|
isWorkspaceTrusted: vi
|
||||||
|
|
@ -46,7 +36,6 @@ import {
|
||||||
afterEach,
|
afterEach,
|
||||||
type Mocked,
|
type Mocked,
|
||||||
type Mock,
|
type Mock,
|
||||||
fail,
|
|
||||||
} from 'vitest';
|
} from 'vitest';
|
||||||
import * as fs from 'node:fs'; // fs will be mocked separately
|
import * as fs from 'node:fs'; // fs will be mocked separately
|
||||||
import stripJsonComments from 'strip-json-comments'; // Will be mocked separately
|
import stripJsonComments from 'strip-json-comments'; // Will be mocked separately
|
||||||
|
|
@ -60,13 +49,12 @@ import {
|
||||||
getSystemSettingsPath,
|
getSystemSettingsPath,
|
||||||
getSystemDefaultsPath,
|
getSystemDefaultsPath,
|
||||||
SETTINGS_DIRECTORY_NAME, // This is from the original module, but used by the mock.
|
SETTINGS_DIRECTORY_NAME, // This is from the original module, but used by the mock.
|
||||||
migrateSettingsToV1,
|
|
||||||
needsMigration,
|
|
||||||
type Settings,
|
type Settings,
|
||||||
loadEnvironment,
|
loadEnvironment,
|
||||||
SETTINGS_VERSION,
|
SETTINGS_VERSION,
|
||||||
SETTINGS_VERSION_KEY,
|
SETTINGS_VERSION_KEY,
|
||||||
} from './settings.js';
|
} from './settings.js';
|
||||||
|
import { needsMigration } from './migration/index.js';
|
||||||
import { FatalConfigError, QWEN_DIR } from '@qwen-code/qwen-code-core';
|
import { FatalConfigError, QWEN_DIR } from '@qwen-code/qwen-code-core';
|
||||||
|
|
||||||
const MOCK_WORKSPACE_DIR = '/mock/workspace';
|
const MOCK_WORKSPACE_DIR = '/mock/workspace';
|
||||||
|
|
@ -84,6 +72,23 @@ type TestSettings = Settings & {
|
||||||
nestedObj?: { [key: string]: unknown };
|
nestedObj?: { [key: string]: unknown };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
vi.mock('node:fs', async (importOriginal) => {
|
||||||
|
// Get all the functions from the real 'fs' module
|
||||||
|
const actualFs = await importOriginal<typeof fs>();
|
||||||
|
|
||||||
|
return {
|
||||||
|
...actualFs, // Keep all the real functions
|
||||||
|
// Now, just override the ones we need for the test
|
||||||
|
existsSync: vi.fn(),
|
||||||
|
readFileSync: vi.fn(),
|
||||||
|
writeFileSync: vi.fn(),
|
||||||
|
renameSync: vi.fn(),
|
||||||
|
mkdirSync: vi.fn(),
|
||||||
|
realpathSync: (p: string) => p,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Also mock 'fs' for compatibility
|
||||||
vi.mock('fs', async (importOriginal) => {
|
vi.mock('fs', async (importOriginal) => {
|
||||||
// Get all the functions from the real 'fs' module
|
// Get all the functions from the real 'fs' module
|
||||||
const actualFs = await importOriginal<typeof fs>();
|
const actualFs = await importOriginal<typeof fs>();
|
||||||
|
|
@ -594,19 +599,22 @@ describe('Settings Loading and Merging', () => {
|
||||||
|
|
||||||
loadSettings(MOCK_WORKSPACE_DIR);
|
loadSettings(MOCK_WORKSPACE_DIR);
|
||||||
|
|
||||||
// Verify that fs.writeFileSync was called (to add version)
|
// Version normalization now uses writeWithBackupSync (temp write + rename)
|
||||||
// but NOT fs.renameSync (no backup needed, just adding version)
|
// Verify that writeFileSync was called with the temp file path
|
||||||
expect(fs.renameSync).not.toHaveBeenCalled();
|
const writeCall = (fs.writeFileSync as Mock).mock.calls.find(
|
||||||
expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
|
(call: unknown[]) => call[0] === `${USER_SETTINGS_PATH}.tmp`,
|
||||||
|
);
|
||||||
const writeCall = (fs.writeFileSync as Mock).mock.calls[0];
|
expect(writeCall).toBeDefined();
|
||||||
const writtenPath = writeCall[0];
|
if (!writeCall) {
|
||||||
|
throw new Error('Expected temp write call for version normalization');
|
||||||
|
}
|
||||||
const writtenContent = JSON.parse(writeCall[1] as string);
|
const writtenContent = JSON.parse(writeCall[1] as string);
|
||||||
|
|
||||||
expect(writtenPath).toBe(USER_SETTINGS_PATH);
|
|
||||||
expect(writtenContent[SETTINGS_VERSION_KEY]).toBe(SETTINGS_VERSION);
|
expect(writtenContent[SETTINGS_VERSION_KEY]).toBe(SETTINGS_VERSION);
|
||||||
expect(writtenContent.ui?.theme).toBe('dark');
|
expect(writtenContent.ui?.theme).toBe('dark');
|
||||||
expect(writtenContent.model?.name).toBe('qwen-coder');
|
expect(writtenContent.model?.name).toBe('qwen-coder');
|
||||||
|
// Verify writeWithBackupSync was called by checking temp file write
|
||||||
|
expect(fs.writeFileSync).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should correctly handle partially migrated settings without version field', () => {
|
it('should correctly handle partially migrated settings without version field', () => {
|
||||||
|
|
@ -734,14 +742,85 @@ describe('Settings Loading and Merging', () => {
|
||||||
loadSettings(MOCK_WORKSPACE_DIR);
|
loadSettings(MOCK_WORKSPACE_DIR);
|
||||||
|
|
||||||
// Version should be bumped to 3 even though no keys needed migration
|
// Version should be bumped to 3 even though no keys needed migration
|
||||||
|
// writeWithBackupSync writes to a temp file first, then renames
|
||||||
const writeCall = (fs.writeFileSync as Mock).mock.calls.find(
|
const writeCall = (fs.writeFileSync as Mock).mock.calls.find(
|
||||||
(call: unknown[]) => call[0] === USER_SETTINGS_PATH,
|
(call: unknown[]) => call[0] === `${USER_SETTINGS_PATH}.tmp`,
|
||||||
);
|
);
|
||||||
expect(writeCall).toBeDefined();
|
expect(writeCall).toBeDefined();
|
||||||
|
if (!writeCall) {
|
||||||
|
throw new Error('Expected temp write call for V2->V3 version bump');
|
||||||
|
}
|
||||||
const writtenContent = JSON.parse(writeCall[1] as string);
|
const writtenContent = JSON.parse(writeCall[1] as string);
|
||||||
expect(writtenContent.$version).toBe(SETTINGS_VERSION);
|
expect(writtenContent.$version).toBe(SETTINGS_VERSION);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should normalize invalid version metadata when no migration is applicable', () => {
|
||||||
|
(mockFsExistsSync as Mock).mockImplementation(
|
||||||
|
(p: fs.PathLike) => p === USER_SETTINGS_PATH,
|
||||||
|
);
|
||||||
|
const invalidVersionSettings = {
|
||||||
|
$version: 'invalid-version',
|
||||||
|
general: {
|
||||||
|
enableAutoUpdate: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
(fs.readFileSync as Mock).mockImplementation(
|
||||||
|
(p: fs.PathOrFileDescriptor) => {
|
||||||
|
if (p === USER_SETTINGS_PATH)
|
||||||
|
return JSON.stringify(invalidVersionSettings);
|
||||||
|
return '{}';
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
loadSettings(MOCK_WORKSPACE_DIR);
|
||||||
|
|
||||||
|
const writeCall = (fs.writeFileSync as Mock).mock.calls.find(
|
||||||
|
(call: unknown[]) => call[0] === `${USER_SETTINGS_PATH}.tmp`,
|
||||||
|
);
|
||||||
|
expect(writeCall).toBeDefined();
|
||||||
|
if (!writeCall) {
|
||||||
|
throw new Error(
|
||||||
|
'Expected temp write call for invalid version normalization',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const writtenContent = JSON.parse(writeCall[1] as string);
|
||||||
|
expect(writtenContent.$version).toBe(SETTINGS_VERSION);
|
||||||
|
expect(writtenContent.general?.enableAutoUpdate).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should normalize legacy numeric version when no migration can execute', () => {
|
||||||
|
(mockFsExistsSync as Mock).mockImplementation(
|
||||||
|
(p: fs.PathLike) => p === USER_SETTINGS_PATH,
|
||||||
|
);
|
||||||
|
const staleVersionSettings = {
|
||||||
|
$version: 1,
|
||||||
|
// No V1/V2 indicators recognized by migrations
|
||||||
|
customOnlyKey: 'value',
|
||||||
|
};
|
||||||
|
(fs.readFileSync as Mock).mockImplementation(
|
||||||
|
(p: fs.PathOrFileDescriptor) => {
|
||||||
|
if (p === USER_SETTINGS_PATH)
|
||||||
|
return JSON.stringify(staleVersionSettings);
|
||||||
|
return '{}';
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
loadSettings(MOCK_WORKSPACE_DIR);
|
||||||
|
|
||||||
|
const writeCall = (fs.writeFileSync as Mock).mock.calls.find(
|
||||||
|
(call: unknown[]) => call[0] === `${USER_SETTINGS_PATH}.tmp`,
|
||||||
|
);
|
||||||
|
expect(writeCall).toBeDefined();
|
||||||
|
if (!writeCall) {
|
||||||
|
throw new Error(
|
||||||
|
'Expected temp write call for stale version normalization',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const writtenContent = JSON.parse(writeCall[1] as string);
|
||||||
|
expect(writtenContent.$version).toBe(SETTINGS_VERSION);
|
||||||
|
expect(writtenContent.customOnlyKey).toBe('value');
|
||||||
|
});
|
||||||
|
|
||||||
it('should correctly merge and migrate legacy array properties from multiple scopes', () => {
|
it('should correctly merge and migrate legacy array properties from multiple scopes', () => {
|
||||||
(mockFsExistsSync as Mock).mockReturnValue(true);
|
(mockFsExistsSync as Mock).mockReturnValue(true);
|
||||||
const legacyUserSettings = {
|
const legacyUserSettings = {
|
||||||
|
|
@ -1619,7 +1698,7 @@ describe('Settings Loading and Merging', () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loadSettings(MOCK_WORKSPACE_DIR);
|
loadSettings(MOCK_WORKSPACE_DIR);
|
||||||
fail('loadSettings should have thrown a FatalConfigError');
|
throw new Error('loadSettings should have thrown a FatalConfigError');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).toBeInstanceOf(FatalConfigError);
|
expect(e).toBeInstanceOf(FatalConfigError);
|
||||||
const error = e as FatalConfigError;
|
const error = e as FatalConfigError;
|
||||||
|
|
@ -2261,385 +2340,6 @@ describe('Settings Loading and Merging', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('migrateSettingsToV1', () => {
|
|
||||||
it('should handle an empty object', () => {
|
|
||||||
const v2Settings = {};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
expect(v1Settings).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should migrate a simple v2 settings object to v1', () => {
|
|
||||||
const v2Settings = {
|
|
||||||
general: {
|
|
||||||
preferredEditor: 'vscode',
|
|
||||||
vimMode: true,
|
|
||||||
},
|
|
||||||
ui: {
|
|
||||||
theme: 'dark',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
preferredEditor: 'vscode',
|
|
||||||
vimMode: true,
|
|
||||||
theme: 'dark',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle nested properties correctly', () => {
|
|
||||||
const v2Settings = {
|
|
||||||
security: {
|
|
||||||
folderTrust: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
auth: {
|
|
||||||
selectedType: 'oauth',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
advanced: {
|
|
||||||
autoConfigureMemory: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
folderTrust: true,
|
|
||||||
selectedAuthType: 'oauth',
|
|
||||||
autoConfigureMaxOldSpaceSize: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should preserve mcpServers at the top level', () => {
|
|
||||||
const v2Settings = {
|
|
||||||
general: {
|
|
||||||
preferredEditor: 'vscode',
|
|
||||||
},
|
|
||||||
mcpServers: {
|
|
||||||
'my-server': {
|
|
||||||
command: 'npm start',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
preferredEditor: 'vscode',
|
|
||||||
mcpServers: {
|
|
||||||
'my-server': {
|
|
||||||
command: 'npm start',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should carry over unrecognized top-level properties', () => {
|
|
||||||
const v2Settings = {
|
|
||||||
general: {
|
|
||||||
vimMode: false,
|
|
||||||
},
|
|
||||||
unrecognized: 'value',
|
|
||||||
another: {
|
|
||||||
nested: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
vimMode: false,
|
|
||||||
unrecognized: 'value',
|
|
||||||
another: {
|
|
||||||
nested: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle a complex object with mixed properties', () => {
|
|
||||||
const v2Settings = {
|
|
||||||
general: {
|
|
||||||
disableAutoUpdate: true,
|
|
||||||
},
|
|
||||||
ui: {
|
|
||||||
hideTips: true,
|
|
||||||
customThemes: {
|
|
||||||
myTheme: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
model: {
|
|
||||||
name: 'gemini-pro',
|
|
||||||
chatCompression: {
|
|
||||||
contextPercentageThreshold: 0.5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
mcpServers: {
|
|
||||||
'server-1': {
|
|
||||||
command: 'node server.js',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
unrecognized: {
|
|
||||||
should: 'be-preserved',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
disableAutoUpdate: true,
|
|
||||||
hideTips: true,
|
|
||||||
customThemes: {
|
|
||||||
myTheme: {},
|
|
||||||
},
|
|
||||||
model: 'gemini-pro',
|
|
||||||
chatCompression: {
|
|
||||||
contextPercentageThreshold: 0.5,
|
|
||||||
},
|
|
||||||
mcpServers: {
|
|
||||||
'server-1': {
|
|
||||||
command: 'node server.js',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
unrecognized: {
|
|
||||||
should: 'be-preserved',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not migrate a v1 settings object', () => {
|
|
||||||
const v1Settings = {
|
|
||||||
preferredEditor: 'vscode',
|
|
||||||
vimMode: true,
|
|
||||||
theme: 'dark',
|
|
||||||
};
|
|
||||||
const migratedSettings = migrateSettingsToV1(v1Settings);
|
|
||||||
expect(migratedSettings).toEqual({
|
|
||||||
preferredEditor: 'vscode',
|
|
||||||
vimMode: true,
|
|
||||||
theme: 'dark',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should migrate a full v2 settings object to v1', () => {
|
|
||||||
const v2Settings: TestSettings = {
|
|
||||||
general: {
|
|
||||||
preferredEditor: 'code',
|
|
||||||
vimMode: true,
|
|
||||||
},
|
|
||||||
ui: {
|
|
||||||
theme: 'dark',
|
|
||||||
},
|
|
||||||
privacy: {
|
|
||||||
usageStatisticsEnabled: false,
|
|
||||||
},
|
|
||||||
model: {
|
|
||||||
name: 'gemini-pro',
|
|
||||||
chatCompression: {
|
|
||||||
contextPercentageThreshold: 0.8,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
context: {
|
|
||||||
fileName: 'CONTEXT.md',
|
|
||||||
includeDirectories: ['/src'],
|
|
||||||
},
|
|
||||||
tools: {
|
|
||||||
sandbox: true,
|
|
||||||
exclude: ['toolA'],
|
|
||||||
},
|
|
||||||
mcp: {
|
|
||||||
allowed: ['server1'],
|
|
||||||
},
|
|
||||||
security: {
|
|
||||||
folderTrust: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
advanced: {
|
|
||||||
dnsResolutionOrder: 'ipv4first',
|
|
||||||
excludedEnvVars: ['SECRET'],
|
|
||||||
},
|
|
||||||
mcpServers: {
|
|
||||||
'my-server': {
|
|
||||||
command: 'npm start',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
unrecognizedTopLevel: {
|
|
||||||
value: 'should be preserved',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
preferredEditor: 'code',
|
|
||||||
vimMode: true,
|
|
||||||
theme: 'dark',
|
|
||||||
usageStatisticsEnabled: false,
|
|
||||||
model: 'gemini-pro',
|
|
||||||
chatCompression: {
|
|
||||||
contextPercentageThreshold: 0.8,
|
|
||||||
},
|
|
||||||
contextFileName: 'CONTEXT.md',
|
|
||||||
includeDirectories: ['/src'],
|
|
||||||
sandbox: true,
|
|
||||||
excludeTools: ['toolA'],
|
|
||||||
allowMCPServers: ['server1'],
|
|
||||||
folderTrust: true,
|
|
||||||
dnsResolutionOrder: 'ipv4first',
|
|
||||||
excludedProjectEnvVars: ['SECRET'],
|
|
||||||
mcpServers: {
|
|
||||||
'my-server': {
|
|
||||||
command: 'npm start',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
unrecognizedTopLevel: {
|
|
||||||
value: 'should be preserved',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle partial v2 settings', () => {
|
|
||||||
const v2Settings: TestSettings = {
|
|
||||||
general: {
|
|
||||||
vimMode: false,
|
|
||||||
},
|
|
||||||
ui: {},
|
|
||||||
model: {
|
|
||||||
name: 'gemini-1.5-pro',
|
|
||||||
},
|
|
||||||
unrecognized: 'value',
|
|
||||||
};
|
|
||||||
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
vimMode: false,
|
|
||||||
model: 'gemini-1.5-pro',
|
|
||||||
unrecognized: 'value',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle settings with different data types', () => {
|
|
||||||
const v2Settings: TestSettings = {
|
|
||||||
general: {
|
|
||||||
vimMode: false,
|
|
||||||
},
|
|
||||||
model: {
|
|
||||||
maxSessionTurns: -1,
|
|
||||||
},
|
|
||||||
context: {
|
|
||||||
includeDirectories: [],
|
|
||||||
},
|
|
||||||
security: {
|
|
||||||
folderTrust: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
vimMode: false,
|
|
||||||
maxSessionTurns: -1,
|
|
||||||
includeDirectories: [],
|
|
||||||
folderTrust: false,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should preserve unrecognized top-level keys', () => {
|
|
||||||
const v2Settings: TestSettings = {
|
|
||||||
general: {
|
|
||||||
vimMode: true,
|
|
||||||
},
|
|
||||||
customTopLevel: {
|
|
||||||
a: 1,
|
|
||||||
b: [2],
|
|
||||||
},
|
|
||||||
anotherOne: 'hello',
|
|
||||||
};
|
|
||||||
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
vimMode: true,
|
|
||||||
customTopLevel: {
|
|
||||||
a: 1,
|
|
||||||
b: [2],
|
|
||||||
},
|
|
||||||
anotherOne: 'hello',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle an empty v2 settings object', () => {
|
|
||||||
const v2Settings = {};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
expect(v1Settings).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should correctly handle mcpServers at the top level', () => {
|
|
||||||
const v2Settings: TestSettings = {
|
|
||||||
mcpServers: {
|
|
||||||
serverA: { command: 'a' },
|
|
||||||
},
|
|
||||||
mcp: {
|
|
||||||
allowed: ['serverA'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
mcpServers: {
|
|
||||||
serverA: { command: 'a' },
|
|
||||||
},
|
|
||||||
allowMCPServers: ['serverA'],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should correctly migrate customWittyPhrases', () => {
|
|
||||||
const v2Settings: Partial<Settings> = {
|
|
||||||
ui: {
|
|
||||||
customWittyPhrases: ['test phrase'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings as Settings);
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
customWittyPhrases: ['test phrase'],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should remove version field when migrating to V1', () => {
|
|
||||||
const v2Settings = {
|
|
||||||
[SETTINGS_VERSION_KEY]: SETTINGS_VERSION,
|
|
||||||
ui: {
|
|
||||||
theme: 'dark',
|
|
||||||
},
|
|
||||||
model: {
|
|
||||||
name: 'qwen-coder',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
|
|
||||||
// Version field should not be present in V1 settings
|
|
||||||
expect(v1Settings[SETTINGS_VERSION_KEY]).toBeUndefined();
|
|
||||||
// Other fields should be properly migrated
|
|
||||||
expect(v1Settings).toEqual({
|
|
||||||
theme: 'dark',
|
|
||||||
model: 'qwen-coder',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle version field in unrecognized properties', () => {
|
|
||||||
const v2Settings = {
|
|
||||||
[SETTINGS_VERSION_KEY]: SETTINGS_VERSION,
|
|
||||||
general: {
|
|
||||||
vimMode: true,
|
|
||||||
},
|
|
||||||
someUnrecognizedKey: 'value',
|
|
||||||
};
|
|
||||||
const v1Settings = migrateSettingsToV1(v2Settings);
|
|
||||||
|
|
||||||
// Version field should be filtered out
|
|
||||||
expect(v1Settings[SETTINGS_VERSION_KEY]).toBeUndefined();
|
|
||||||
// Unrecognized keys should be preserved
|
|
||||||
expect(v1Settings['someUnrecognizedKey']).toBe('value');
|
|
||||||
expect(v1Settings['vimMode']).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('loadEnvironment', () => {
|
describe('loadEnvironment', () => {
|
||||||
function setup({
|
function setup({
|
||||||
isFolderTrustEnabled = true,
|
isFolderTrustEnabled = true,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ import {
|
||||||
QWEN_DIR,
|
QWEN_DIR,
|
||||||
getErrorMessage,
|
getErrorMessage,
|
||||||
Storage,
|
Storage,
|
||||||
|
setDebugLogSession,
|
||||||
|
sanitizeCwd,
|
||||||
|
createDebugLogger,
|
||||||
} from '@qwen-code/qwen-code-core';
|
} from '@qwen-code/qwen-code-core';
|
||||||
import stripJsonComments from 'strip-json-comments';
|
import stripJsonComments from 'strip-json-comments';
|
||||||
import { DefaultLight } from '../ui/themes/default-light.js';
|
import { DefaultLight } from '../ui/themes/default-light.js';
|
||||||
|
|
@ -28,9 +31,16 @@ import {
|
||||||
getSettingsSchema,
|
getSettingsSchema,
|
||||||
} from './settingsSchema.js';
|
} from './settingsSchema.js';
|
||||||
import { resolveEnvVarsInObject } from '../utils/envVarResolver.js';
|
import { resolveEnvVarsInObject } from '../utils/envVarResolver.js';
|
||||||
import { customDeepMerge, type MergeableObject } from '../utils/deepMerge.js';
|
import { setNestedPropertySafe } from '../utils/settingsUtils.js';
|
||||||
|
import { customDeepMerge } from '../utils/deepMerge.js';
|
||||||
import { updateSettingsFilePreservingFormat } from '../utils/commentJson.js';
|
import { updateSettingsFilePreservingFormat } from '../utils/commentJson.js';
|
||||||
import { writeStderrLine } from '../utils/stdioHelpers.js';
|
const debugLogger = createDebugLogger('SETTINGS');
|
||||||
|
import { runMigrations, needsMigration } from './migration/index.js';
|
||||||
|
import {
|
||||||
|
V1_TO_V2_MIGRATION_MAP,
|
||||||
|
V2_CONTAINER_KEYS,
|
||||||
|
} from './migration/versions/v1-to-v2-shared.js';
|
||||||
|
import { writeWithBackupSync } from '../utils/writeWithBackup.js';
|
||||||
|
|
||||||
function getMergeStrategyForPath(path: string[]): MergeStrategy | undefined {
|
function getMergeStrategyForPath(path: string[]): MergeStrategy | undefined {
|
||||||
let current: SettingDefinition | undefined = undefined;
|
let current: SettingDefinition | undefined = undefined;
|
||||||
|
|
@ -54,115 +64,10 @@ export const USER_SETTINGS_PATH = Storage.getGlobalSettingsPath();
|
||||||
export const USER_SETTINGS_DIR = path.dirname(USER_SETTINGS_PATH);
|
export const USER_SETTINGS_DIR = path.dirname(USER_SETTINGS_PATH);
|
||||||
export const DEFAULT_EXCLUDED_ENV_VARS = ['DEBUG', 'DEBUG_MODE'];
|
export const DEFAULT_EXCLUDED_ENV_VARS = ['DEBUG', 'DEBUG_MODE'];
|
||||||
|
|
||||||
const MIGRATE_V2_OVERWRITE = true;
|
|
||||||
|
|
||||||
// Settings version to track migration state
|
// Settings version to track migration state
|
||||||
export const SETTINGS_VERSION = 3;
|
export const SETTINGS_VERSION = 3;
|
||||||
export const SETTINGS_VERSION_KEY = '$version';
|
export const SETTINGS_VERSION_KEY = '$version';
|
||||||
|
|
||||||
const MIGRATION_MAP: Record<string, string> = {
|
|
||||||
accessibility: 'ui.accessibility',
|
|
||||||
allowedTools: 'tools.allowed',
|
|
||||||
allowMCPServers: 'mcp.allowed',
|
|
||||||
autoAccept: 'tools.autoAccept',
|
|
||||||
autoConfigureMaxOldSpaceSize: 'advanced.autoConfigureMemory',
|
|
||||||
bugCommand: 'advanced.bugCommand',
|
|
||||||
chatCompression: 'model.chatCompression',
|
|
||||||
checkpointing: 'general.checkpointing',
|
|
||||||
coreTools: 'tools.core',
|
|
||||||
contextFileName: 'context.fileName',
|
|
||||||
customThemes: 'ui.customThemes',
|
|
||||||
customWittyPhrases: 'ui.customWittyPhrases',
|
|
||||||
debugKeystrokeLogging: 'general.debugKeystrokeLogging',
|
|
||||||
dnsResolutionOrder: 'advanced.dnsResolutionOrder',
|
|
||||||
enforcedAuthType: 'security.auth.enforcedType',
|
|
||||||
excludeTools: 'tools.exclude',
|
|
||||||
excludeMCPServers: 'mcp.excluded',
|
|
||||||
excludedProjectEnvVars: 'advanced.excludedEnvVars',
|
|
||||||
extensions: 'extensions',
|
|
||||||
fileFiltering: 'context.fileFiltering',
|
|
||||||
folderTrustFeature: 'security.folderTrust.featureEnabled',
|
|
||||||
folderTrust: 'security.folderTrust.enabled',
|
|
||||||
hasSeenIdeIntegrationNudge: 'ide.hasSeenNudge',
|
|
||||||
hideWindowTitle: 'ui.hideWindowTitle',
|
|
||||||
showStatusInTitle: 'ui.showStatusInTitle',
|
|
||||||
hideTips: 'ui.hideTips',
|
|
||||||
showLineNumbers: 'ui.showLineNumbers',
|
|
||||||
showCitations: 'ui.showCitations',
|
|
||||||
ideMode: 'ide.enabled',
|
|
||||||
includeDirectories: 'context.includeDirectories',
|
|
||||||
loadMemoryFromIncludeDirectories: 'context.loadFromIncludeDirectories',
|
|
||||||
maxSessionTurns: 'model.maxSessionTurns',
|
|
||||||
mcpServers: 'mcpServers',
|
|
||||||
mcpServerCommand: 'mcp.serverCommand',
|
|
||||||
memoryImportFormat: 'context.importFormat',
|
|
||||||
model: 'model.name',
|
|
||||||
preferredEditor: 'general.preferredEditor',
|
|
||||||
sandbox: 'tools.sandbox',
|
|
||||||
selectedAuthType: 'security.auth.selectedType',
|
|
||||||
shouldUseNodePtyShell: 'tools.shell.enableInteractiveShell',
|
|
||||||
shellPager: 'tools.shell.pager',
|
|
||||||
shellShowColor: 'tools.shell.showColor',
|
|
||||||
skipNextSpeakerCheck: 'model.skipNextSpeakerCheck',
|
|
||||||
summarizeToolOutput: 'model.summarizeToolOutput',
|
|
||||||
telemetry: 'telemetry',
|
|
||||||
theme: 'ui.theme',
|
|
||||||
toolDiscoveryCommand: 'tools.discoveryCommand',
|
|
||||||
toolCallCommand: 'tools.callCommand',
|
|
||||||
usageStatisticsEnabled: 'privacy.usageStatisticsEnabled',
|
|
||||||
useExternalAuth: 'security.auth.useExternal',
|
|
||||||
useRipgrep: 'tools.useRipgrep',
|
|
||||||
vimMode: 'general.vimMode',
|
|
||||||
|
|
||||||
enableWelcomeBack: 'ui.enableWelcomeBack',
|
|
||||||
approvalMode: 'tools.approvalMode',
|
|
||||||
sessionTokenLimit: 'model.sessionTokenLimit',
|
|
||||||
contentGenerator: 'model.generationConfig',
|
|
||||||
skipLoopDetection: 'model.skipLoopDetection',
|
|
||||||
skipStartupContext: 'model.skipStartupContext',
|
|
||||||
enableOpenAILogging: 'model.enableOpenAILogging',
|
|
||||||
tavilyApiKey: 'advanced.tavilyApiKey',
|
|
||||||
vlmSwitchMode: 'experimental.vlmSwitchMode',
|
|
||||||
visionModelPreview: 'experimental.visionModelPreview',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Settings that need boolean inversion during migration (V1 -> V3)
|
|
||||||
// Old negative naming -> new positive naming with inverted value
|
|
||||||
const INVERTED_BOOLEAN_MIGRATIONS: Record<string, string> = {
|
|
||||||
disableAutoUpdate: 'general.enableAutoUpdate',
|
|
||||||
disableUpdateNag: 'general.enableAutoUpdate',
|
|
||||||
disableLoadingPhrases: 'ui.accessibility.enableLoadingPhrases',
|
|
||||||
disableFuzzySearch: 'context.fileFiltering.enableFuzzySearch',
|
|
||||||
disableCacheControl: 'model.generationConfig.enableCacheControl',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Consolidated settings: multiple old V1 keys that map to a single new key.
|
|
||||||
// Policy: if ANY of the old disable* settings is true, the new enable* should be false.
|
|
||||||
const CONSOLIDATED_SETTINGS: Record<string, string[]> = {
|
|
||||||
'general.enableAutoUpdate': ['disableAutoUpdate', 'disableUpdateNag'],
|
|
||||||
};
|
|
||||||
|
|
||||||
// V2 nested paths that need inversion when migrating to V3
|
|
||||||
const INVERTED_V2_PATHS: Record<string, string> = {
|
|
||||||
'general.disableAutoUpdate': 'general.enableAutoUpdate',
|
|
||||||
'general.disableUpdateNag': 'general.enableAutoUpdate',
|
|
||||||
'ui.accessibility.disableLoadingPhrases':
|
|
||||||
'ui.accessibility.enableLoadingPhrases',
|
|
||||||
'context.fileFiltering.disableFuzzySearch':
|
|
||||||
'context.fileFiltering.enableFuzzySearch',
|
|
||||||
'model.generationConfig.disableCacheControl':
|
|
||||||
'model.generationConfig.enableCacheControl',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Consolidated V2 paths: multiple old paths that map to a single new path.
|
|
||||||
// Policy: if ANY of the old disable* settings is true, the new enable* should be false.
|
|
||||||
const CONSOLIDATED_V2_PATHS: Record<string, string[]> = {
|
|
||||||
'general.enableAutoUpdate': [
|
|
||||||
'general.disableAutoUpdate',
|
|
||||||
'general.disableUpdateNag',
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
export function getSystemSettingsPath(): string {
|
export function getSystemSettingsPath(): string {
|
||||||
if (process.env['QWEN_CODE_SYSTEM_SETTINGS_PATH']) {
|
if (process.env['QWEN_CODE_SYSTEM_SETTINGS_PATH']) {
|
||||||
return process.env['QWEN_CODE_SYSTEM_SETTINGS_PATH'];
|
return process.env['QWEN_CODE_SYSTEM_SETTINGS_PATH'];
|
||||||
|
|
@ -220,312 +125,6 @@ export interface SettingsFile {
|
||||||
rawJson?: string;
|
rawJson?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setNestedProperty(
|
|
||||||
obj: Record<string, unknown>,
|
|
||||||
path: string,
|
|
||||||
value: unknown,
|
|
||||||
) {
|
|
||||||
const keys = path.split('.');
|
|
||||||
const lastKey = keys.pop();
|
|
||||||
if (!lastKey) return;
|
|
||||||
|
|
||||||
let current: Record<string, unknown> = obj;
|
|
||||||
for (const key of keys) {
|
|
||||||
if (current[key] === undefined) {
|
|
||||||
current[key] = {};
|
|
||||||
}
|
|
||||||
const next = current[key];
|
|
||||||
if (typeof next === 'object' && next !== null) {
|
|
||||||
current = next as Record<string, unknown>;
|
|
||||||
} else {
|
|
||||||
// This path is invalid, so we stop.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
current[lastKey] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dynamically determine the top-level keys from the V2 settings structure.
|
|
||||||
const KNOWN_V2_CONTAINERS = new Set([
|
|
||||||
...Object.values(MIGRATION_MAP).map((path) => path.split('.')[0]),
|
|
||||||
...Object.values(INVERTED_BOOLEAN_MIGRATIONS).map(
|
|
||||||
(path) => path.split('.')[0],
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
export function needsMigration(settings: Record<string, unknown>): boolean {
|
|
||||||
// Check version field first - if present and matches current version, no migration needed
|
|
||||||
if (SETTINGS_VERSION_KEY in settings) {
|
|
||||||
const version = settings[SETTINGS_VERSION_KEY];
|
|
||||||
if (typeof version === 'number' && version >= SETTINGS_VERSION) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to legacy detection: A file needs migration if it contains any
|
|
||||||
// top-level key that is moved to a nested location in V2.
|
|
||||||
const hasV1Keys = Object.entries(MIGRATION_MAP).some(([v1Key, v2Path]) => {
|
|
||||||
if (v1Key === v2Path || !(v1Key in settings)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// If a key exists that is both a V1 key and a V2 container (like 'model'),
|
|
||||||
// we need to check the type. If it's an object, it's a V2 container and not
|
|
||||||
// a V1 key that needs migration.
|
|
||||||
if (
|
|
||||||
KNOWN_V2_CONTAINERS.has(v1Key) &&
|
|
||||||
typeof settings[v1Key] === 'object' &&
|
|
||||||
settings[v1Key] !== null
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Also check for old inverted boolean keys (disable* -> enable*)
|
|
||||||
const hasInvertedBooleanKeys = Object.keys(INVERTED_BOOLEAN_MIGRATIONS).some(
|
|
||||||
(v1Key) => v1Key in settings,
|
|
||||||
);
|
|
||||||
|
|
||||||
return hasV1Keys || hasInvertedBooleanKeys;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Migrates V1 (flat) settings directly to V3.
|
|
||||||
* This includes both structural migration (flat -> nested) and boolean
|
|
||||||
* inversion (disable* -> enable*), so migrateV2ToV3 will be skipped.
|
|
||||||
*/
|
|
||||||
function migrateV1ToV3(
|
|
||||||
flatSettings: Record<string, unknown>,
|
|
||||||
): Record<string, unknown> | null {
|
|
||||||
if (!needsMigration(flatSettings)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const v2Settings: Record<string, unknown> = {};
|
|
||||||
const flatKeys = new Set(Object.keys(flatSettings));
|
|
||||||
|
|
||||||
for (const [oldKey, newPath] of Object.entries(MIGRATION_MAP)) {
|
|
||||||
if (flatKeys.has(oldKey)) {
|
|
||||||
// Safety check: If this key is a V2 container (like 'model') and it's
|
|
||||||
// already an object, it's likely already in V2 format. Skip migration
|
|
||||||
// to prevent double-nesting (e.g., model.name.name).
|
|
||||||
if (
|
|
||||||
KNOWN_V2_CONTAINERS.has(oldKey) &&
|
|
||||||
typeof flatSettings[oldKey] === 'object' &&
|
|
||||||
flatSettings[oldKey] !== null &&
|
|
||||||
!Array.isArray(flatSettings[oldKey])
|
|
||||||
) {
|
|
||||||
// This is already a V2 container, carry it over as-is
|
|
||||||
v2Settings[oldKey] = flatSettings[oldKey];
|
|
||||||
flatKeys.delete(oldKey);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
setNestedProperty(v2Settings, newPath, flatSettings[oldKey]);
|
|
||||||
flatKeys.delete(oldKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle consolidated settings first (multiple old keys -> single new key)
|
|
||||||
// Policy: if ANY of the old disable* settings is true, the new enable* should be false
|
|
||||||
for (const [newPath, oldKeys] of Object.entries(CONSOLIDATED_SETTINGS)) {
|
|
||||||
let hasAnyDisable = false;
|
|
||||||
let hasAnyValue = false;
|
|
||||||
for (const oldKey of oldKeys) {
|
|
||||||
if (flatKeys.has(oldKey)) {
|
|
||||||
hasAnyValue = true;
|
|
||||||
const oldValue = flatSettings[oldKey];
|
|
||||||
if (typeof oldValue === 'boolean' && oldValue === true) {
|
|
||||||
hasAnyDisable = true;
|
|
||||||
}
|
|
||||||
flatKeys.delete(oldKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasAnyValue) {
|
|
||||||
// enableAutoUpdate = !hasAnyDisable (if any disable* was true, enable should be false)
|
|
||||||
setNestedProperty(v2Settings, newPath, !hasAnyDisable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle remaining V1 settings that need boolean inversion (disable* -> enable*)
|
|
||||||
// Skip keys that were already handled by consolidated settings
|
|
||||||
const consolidatedKeys = new Set(Object.values(CONSOLIDATED_SETTINGS).flat());
|
|
||||||
for (const [oldKey, newPath] of Object.entries(INVERTED_BOOLEAN_MIGRATIONS)) {
|
|
||||||
if (consolidatedKeys.has(oldKey)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (flatKeys.has(oldKey)) {
|
|
||||||
const oldValue = flatSettings[oldKey];
|
|
||||||
if (typeof oldValue === 'boolean') {
|
|
||||||
setNestedProperty(v2Settings, newPath, !oldValue);
|
|
||||||
}
|
|
||||||
flatKeys.delete(oldKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preserve mcpServers at the top level
|
|
||||||
if (flatSettings['mcpServers']) {
|
|
||||||
v2Settings['mcpServers'] = flatSettings['mcpServers'];
|
|
||||||
flatKeys.delete('mcpServers');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carry over any unrecognized keys
|
|
||||||
for (const remainingKey of flatKeys) {
|
|
||||||
const existingValue = v2Settings[remainingKey];
|
|
||||||
const newValue = flatSettings[remainingKey];
|
|
||||||
|
|
||||||
if (
|
|
||||||
typeof existingValue === 'object' &&
|
|
||||||
existingValue !== null &&
|
|
||||||
!Array.isArray(existingValue) &&
|
|
||||||
typeof newValue === 'object' &&
|
|
||||||
newValue !== null &&
|
|
||||||
!Array.isArray(newValue)
|
|
||||||
) {
|
|
||||||
const pathAwareGetStrategy = (path: string[]) =>
|
|
||||||
getMergeStrategyForPath([remainingKey, ...path]);
|
|
||||||
v2Settings[remainingKey] = customDeepMerge(
|
|
||||||
pathAwareGetStrategy,
|
|
||||||
{},
|
|
||||||
newValue as MergeableObject,
|
|
||||||
existingValue as MergeableObject,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
v2Settings[remainingKey] = newValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set version field to indicate this is a V2 settings file
|
|
||||||
v2Settings[SETTINGS_VERSION_KEY] = SETTINGS_VERSION;
|
|
||||||
|
|
||||||
return v2Settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Migrate V2 settings to V3 (invert disable* -> enable* booleans)
|
|
||||||
function migrateV2ToV3(
|
|
||||||
settings: Record<string, unknown>,
|
|
||||||
): Record<string, unknown> | null {
|
|
||||||
const version = settings[SETTINGS_VERSION_KEY];
|
|
||||||
if (typeof version === 'number' && version >= 3) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let changed = false;
|
|
||||||
const result = structuredClone(settings);
|
|
||||||
const processedPaths = new Set<string>();
|
|
||||||
|
|
||||||
// Handle consolidated V2 paths first (multiple old paths -> single new path)
|
|
||||||
// Policy: if ANY of the old disable* settings is true, the new enable* should be false
|
|
||||||
for (const [newPath, oldPaths] of Object.entries(CONSOLIDATED_V2_PATHS)) {
|
|
||||||
let hasAnyDisable = false;
|
|
||||||
let hasAnyValue = false;
|
|
||||||
for (const oldPath of oldPaths) {
|
|
||||||
const oldValue = getNestedProperty(result, oldPath);
|
|
||||||
if (typeof oldValue === 'boolean') {
|
|
||||||
hasAnyValue = true;
|
|
||||||
if (oldValue === true) {
|
|
||||||
hasAnyDisable = true;
|
|
||||||
}
|
|
||||||
deleteNestedProperty(result, oldPath);
|
|
||||||
processedPaths.add(oldPath);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasAnyValue) {
|
|
||||||
// enableAutoUpdate = !hasAnyDisable (if any disable* was true, enable should be false)
|
|
||||||
setNestedProperty(result, newPath, !hasAnyDisable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle remaining V2 paths that need inversion
|
|
||||||
for (const [oldPath, newPath] of Object.entries(INVERTED_V2_PATHS)) {
|
|
||||||
if (processedPaths.has(oldPath)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const oldValue = getNestedProperty(result, oldPath);
|
|
||||||
if (typeof oldValue === 'boolean') {
|
|
||||||
// Remove old property
|
|
||||||
deleteNestedProperty(result, oldPath);
|
|
||||||
// Set new property with inverted value
|
|
||||||
setNestedProperty(result, newPath, !oldValue);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed) {
|
|
||||||
result[SETTINGS_VERSION_KEY] = SETTINGS_VERSION;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Even if no changes, bump version to 3 to skip future migration checks
|
|
||||||
if (typeof version === 'number' && version < SETTINGS_VERSION) {
|
|
||||||
result[SETTINGS_VERSION_KEY] = SETTINGS_VERSION;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteNestedProperty(
|
|
||||||
obj: Record<string, unknown>,
|
|
||||||
path: string,
|
|
||||||
): void {
|
|
||||||
const keys = path.split('.');
|
|
||||||
const lastKey = keys.pop();
|
|
||||||
if (!lastKey) return;
|
|
||||||
|
|
||||||
let current: Record<string, unknown> = obj;
|
|
||||||
for (const key of keys) {
|
|
||||||
const next = current[key];
|
|
||||||
if (typeof next !== 'object' || next === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
current = next as Record<string, unknown>;
|
|
||||||
}
|
|
||||||
delete current[lastKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNestedProperty(
|
|
||||||
obj: Record<string, unknown>,
|
|
||||||
path: string,
|
|
||||||
): unknown {
|
|
||||||
const keys = path.split('.');
|
|
||||||
let current: unknown = obj;
|
|
||||||
for (const key of keys) {
|
|
||||||
if (typeof current !== 'object' || current === null || !(key in current)) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
current = (current as Record<string, unknown>)[key];
|
|
||||||
}
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
const REVERSE_MIGRATION_MAP: Record<string, string> = Object.fromEntries(
|
|
||||||
Object.entries(MIGRATION_MAP).map(([key, value]) => [value, key]),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Reverse map for old V2 paths (before rename) to V1 keys.
|
|
||||||
// Used when migrating settings that still have old V2 naming (e.g., general.disableAutoUpdate).
|
|
||||||
const OLD_V2_TO_V1_MAP: Record<string, string> = {};
|
|
||||||
for (const [oldV2Path, newV3Path] of Object.entries(INVERTED_V2_PATHS)) {
|
|
||||||
// Find the V1 key that maps to this V3 path
|
|
||||||
for (const [v1Key, v3Path] of Object.entries(INVERTED_BOOLEAN_MIGRATIONS)) {
|
|
||||||
if (v3Path === newV3Path) {
|
|
||||||
OLD_V2_TO_V1_MAP[oldV2Path] = v1Key;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reverse map for new V3 paths to V1 keys (with boolean inversion).
|
|
||||||
// Used when migrating settings that have new V3 naming (e.g., general.enableAutoUpdate).
|
|
||||||
const V3_TO_V1_INVERTED_MAP: Record<string, string> = Object.fromEntries(
|
|
||||||
Object.entries(INVERTED_BOOLEAN_MIGRATIONS).map(([v1Key, v3Path]) => [
|
|
||||||
v3Path,
|
|
||||||
v1Key,
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
|
|
||||||
function getSettingsFileKeyWarnings(
|
function getSettingsFileKeyWarnings(
|
||||||
settings: Record<string, unknown>,
|
settings: Record<string, unknown>,
|
||||||
settingsFilePath: string,
|
settingsFilePath: string,
|
||||||
|
|
@ -539,7 +138,7 @@ function getSettingsFileKeyWarnings(
|
||||||
const ignoredLegacyKeys = new Set<string>();
|
const ignoredLegacyKeys = new Set<string>();
|
||||||
|
|
||||||
// Ignored legacy keys (V1 top-level keys that moved to a nested V2 path).
|
// Ignored legacy keys (V1 top-level keys that moved to a nested V2 path).
|
||||||
for (const [oldKey, newPath] of Object.entries(MIGRATION_MAP)) {
|
for (const [oldKey, newPath] of Object.entries(V1_TO_V2_MIGRATION_MAP)) {
|
||||||
if (oldKey === newPath) {
|
if (oldKey === newPath) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -552,7 +151,7 @@ function getSettingsFileKeyWarnings(
|
||||||
// If this key is a V2 container (like 'model') and it's already an object,
|
// If this key is a V2 container (like 'model') and it's already an object,
|
||||||
// it's likely already in V2 format. Don't warn.
|
// it's likely already in V2 format. Don't warn.
|
||||||
if (
|
if (
|
||||||
KNOWN_V2_CONTAINERS.has(oldKey) &&
|
V2_CONTAINER_KEYS.has(oldKey) &&
|
||||||
typeof oldValue === 'object' &&
|
typeof oldValue === 'object' &&
|
||||||
oldValue !== null &&
|
oldValue !== null &&
|
||||||
!Array.isArray(oldValue)
|
!Array.isArray(oldValue)
|
||||||
|
|
@ -588,7 +187,8 @@ function getSettingsFileKeyWarnings(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects warnings for ignored legacy and unknown settings keys.
|
* Collects warnings for ignored legacy and unknown settings keys,
|
||||||
|
* as well as migration warnings.
|
||||||
*
|
*
|
||||||
* For `$version: 2` settings files, we do not apply implicit migrations.
|
* For `$version: 2` settings files, we do not apply implicit migrations.
|
||||||
* Instead, we surface actionable, de-duplicated warnings in the terminal UI.
|
* Instead, we surface actionable, de-duplicated warnings in the terminal UI.
|
||||||
|
|
@ -596,6 +196,11 @@ function getSettingsFileKeyWarnings(
|
||||||
export function getSettingsWarnings(loadedSettings: LoadedSettings): string[] {
|
export function getSettingsWarnings(loadedSettings: LoadedSettings): string[] {
|
||||||
const warningSet = new Set<string>();
|
const warningSet = new Set<string>();
|
||||||
|
|
||||||
|
// Add migration warnings first
|
||||||
|
for (const warning of loadedSettings.migrationWarnings) {
|
||||||
|
warningSet.add(`Warning: ${warning}`);
|
||||||
|
}
|
||||||
|
|
||||||
for (const scope of [SettingScope.User, SettingScope.Workspace]) {
|
for (const scope of [SettingScope.User, SettingScope.Workspace]) {
|
||||||
const settingsFile = loadedSettings.forScope(scope);
|
const settingsFile = loadedSettings.forScope(scope);
|
||||||
if (settingsFile.rawJson === undefined) {
|
if (settingsFile.rawJson === undefined) {
|
||||||
|
|
@ -618,75 +223,6 @@ export function getSettingsWarnings(loadedSettings: LoadedSettings): string[] {
|
||||||
return [...warningSet];
|
return [...warningSet];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function migrateSettingsToV1(
|
|
||||||
v2Settings: Record<string, unknown>,
|
|
||||||
): Record<string, unknown> {
|
|
||||||
const v1Settings: Record<string, unknown> = {};
|
|
||||||
const v2Keys = new Set(Object.keys(v2Settings));
|
|
||||||
|
|
||||||
for (const [newPath, oldKey] of Object.entries(REVERSE_MIGRATION_MAP)) {
|
|
||||||
const value = getNestedProperty(v2Settings, newPath);
|
|
||||||
if (value !== undefined) {
|
|
||||||
v1Settings[oldKey] = value;
|
|
||||||
v2Keys.delete(newPath.split('.')[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle old V2 inverted paths (no value inversion needed)
|
|
||||||
// e.g., general.disableAutoUpdate -> disableAutoUpdate
|
|
||||||
for (const [oldV2Path, v1Key] of Object.entries(OLD_V2_TO_V1_MAP)) {
|
|
||||||
const value = getNestedProperty(v2Settings, oldV2Path);
|
|
||||||
if (value !== undefined) {
|
|
||||||
v1Settings[v1Key] = value;
|
|
||||||
v2Keys.delete(oldV2Path.split('.')[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle new V3 inverted paths (WITH value inversion)
|
|
||||||
// e.g., general.enableAutoUpdate -> disableAutoUpdate (inverted)
|
|
||||||
for (const [v3Path, v1Key] of Object.entries(V3_TO_V1_INVERTED_MAP)) {
|
|
||||||
const value = getNestedProperty(v2Settings, v3Path);
|
|
||||||
if (value !== undefined && typeof value === 'boolean') {
|
|
||||||
v1Settings[v1Key] = !value;
|
|
||||||
v2Keys.delete(v3Path.split('.')[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preserve mcpServers at the top level
|
|
||||||
if (v2Settings['mcpServers']) {
|
|
||||||
v1Settings['mcpServers'] = v2Settings['mcpServers'];
|
|
||||||
v2Keys.delete('mcpServers');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carry over any unrecognized keys
|
|
||||||
for (const remainingKey of v2Keys) {
|
|
||||||
// Skip the version field - it's only for V2 format
|
|
||||||
if (remainingKey === SETTINGS_VERSION_KEY) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const value = v2Settings[remainingKey];
|
|
||||||
if (value === undefined) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't carry over empty objects that were just containers for migrated settings.
|
|
||||||
if (
|
|
||||||
KNOWN_V2_CONTAINERS.has(remainingKey) &&
|
|
||||||
typeof value === 'object' &&
|
|
||||||
value !== null &&
|
|
||||||
!Array.isArray(value) &&
|
|
||||||
Object.keys(value).length === 0
|
|
||||||
) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
v1Settings[remainingKey] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return v1Settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
function mergeSettings(
|
function mergeSettings(
|
||||||
system: Settings,
|
system: Settings,
|
||||||
systemDefaults: Settings,
|
systemDefaults: Settings,
|
||||||
|
|
@ -720,6 +256,7 @@ export class LoadedSettings {
|
||||||
workspace: SettingsFile,
|
workspace: SettingsFile,
|
||||||
isTrusted: boolean,
|
isTrusted: boolean,
|
||||||
migratedInMemorScopes: Set<SettingScope>,
|
migratedInMemorScopes: Set<SettingScope>,
|
||||||
|
migrationWarnings: string[] = [],
|
||||||
) {
|
) {
|
||||||
this.system = system;
|
this.system = system;
|
||||||
this.systemDefaults = systemDefaults;
|
this.systemDefaults = systemDefaults;
|
||||||
|
|
@ -727,6 +264,7 @@ export class LoadedSettings {
|
||||||
this.workspace = workspace;
|
this.workspace = workspace;
|
||||||
this.isTrusted = isTrusted;
|
this.isTrusted = isTrusted;
|
||||||
this.migratedInMemorScopes = migratedInMemorScopes;
|
this.migratedInMemorScopes = migratedInMemorScopes;
|
||||||
|
this.migrationWarnings = migrationWarnings;
|
||||||
this._merged = this.computeMergedSettings();
|
this._merged = this.computeMergedSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -736,6 +274,7 @@ export class LoadedSettings {
|
||||||
readonly workspace: SettingsFile;
|
readonly workspace: SettingsFile;
|
||||||
readonly isTrusted: boolean;
|
readonly isTrusted: boolean;
|
||||||
readonly migratedInMemorScopes: Set<SettingScope>;
|
readonly migratedInMemorScopes: Set<SettingScope>;
|
||||||
|
readonly migrationWarnings: string[];
|
||||||
|
|
||||||
private _merged: Settings;
|
private _merged: Settings;
|
||||||
|
|
||||||
|
|
@ -770,8 +309,8 @@ export class LoadedSettings {
|
||||||
|
|
||||||
setValue(scope: SettingScope, key: string, value: unknown): void {
|
setValue(scope: SettingScope, key: string, value: unknown): void {
|
||||||
const settingsFile = this.forScope(scope);
|
const settingsFile = this.forScope(scope);
|
||||||
setNestedProperty(settingsFile.settings, key, value);
|
setNestedPropertySafe(settingsFile.settings, key, value);
|
||||||
setNestedProperty(settingsFile.originalSettings, key, value);
|
setNestedPropertySafe(settingsFile.originalSettings, key, value);
|
||||||
this._merged = this.computeMergedSettings();
|
this._merged = this.computeMergedSettings();
|
||||||
saveSettings(settingsFile);
|
saveSettings(settingsFile);
|
||||||
}
|
}
|
||||||
|
|
@ -795,6 +334,7 @@ export function createMinimalSettings(): LoadedSettings {
|
||||||
emptySettingsFile,
|
emptySettingsFile,
|
||||||
false,
|
false,
|
||||||
new Set(),
|
new Set(),
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -935,6 +475,16 @@ export function loadEnvironment(settings: Settings): void {
|
||||||
export function loadSettings(
|
export function loadSettings(
|
||||||
workspaceDir: string = process.cwd(),
|
workspaceDir: string = process.cwd(),
|
||||||
): LoadedSettings {
|
): LoadedSettings {
|
||||||
|
// Set up a temporary debug log session for the startup phase.
|
||||||
|
// This allows migration errors to be logged to file instead of being
|
||||||
|
// exposed to users via stderr. The Config class will override this
|
||||||
|
// with the actual session once initialized.
|
||||||
|
const resolvedWorkspaceDir = path.resolve(workspaceDir);
|
||||||
|
const sanitizedProjectId = sanitizeCwd(resolvedWorkspaceDir);
|
||||||
|
setDebugLogSession({
|
||||||
|
getSessionId: () => `startup-${sanitizedProjectId}`,
|
||||||
|
});
|
||||||
|
|
||||||
let systemSettings: Settings = {};
|
let systemSettings: Settings = {};
|
||||||
let systemDefaultSettings: Settings = {};
|
let systemDefaultSettings: Settings = {};
|
||||||
let userSettings: Settings = {};
|
let userSettings: Settings = {};
|
||||||
|
|
@ -945,7 +495,7 @@ export function loadSettings(
|
||||||
const migratedInMemorScopes = new Set<SettingScope>();
|
const migratedInMemorScopes = new Set<SettingScope>();
|
||||||
|
|
||||||
// Resolve paths to their canonical representation to handle symlinks
|
// Resolve paths to their canonical representation to handle symlinks
|
||||||
const resolvedWorkspaceDir = path.resolve(workspaceDir);
|
// Note: resolvedWorkspaceDir is already defined at the top of the function
|
||||||
const resolvedHomeDir = path.resolve(homedir());
|
const resolvedHomeDir = path.resolve(homedir());
|
||||||
|
|
||||||
let realWorkspaceDir = resolvedWorkspaceDir;
|
let realWorkspaceDir = resolvedWorkspaceDir;
|
||||||
|
|
@ -966,7 +516,7 @@ export function loadSettings(
|
||||||
const loadAndMigrate = (
|
const loadAndMigrate = (
|
||||||
filePath: string,
|
filePath: string,
|
||||||
scope: SettingScope,
|
scope: SettingScope,
|
||||||
): { settings: Settings; rawJson?: string } => {
|
): { settings: Settings; rawJson?: string; migrationWarnings?: string[] } => {
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
const content = fs.readFileSync(filePath, 'utf-8');
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
|
@ -985,74 +535,59 @@ export function loadSettings(
|
||||||
}
|
}
|
||||||
|
|
||||||
let settingsObject = rawSettings as Record<string, unknown>;
|
let settingsObject = rawSettings as Record<string, unknown>;
|
||||||
|
const hasVersionKey = SETTINGS_VERSION_KEY in settingsObject;
|
||||||
|
const versionValue = settingsObject[SETTINGS_VERSION_KEY];
|
||||||
|
const hasInvalidVersion =
|
||||||
|
hasVersionKey && typeof versionValue !== 'number';
|
||||||
|
const hasLegacyNumericVersion =
|
||||||
|
typeof versionValue === 'number' && versionValue < SETTINGS_VERSION;
|
||||||
|
let migrationWarnings: string[] | undefined;
|
||||||
|
|
||||||
|
const persistSettingsObject = (warningPrefix: string) => {
|
||||||
|
try {
|
||||||
|
writeWithBackupSync(
|
||||||
|
filePath,
|
||||||
|
JSON.stringify(settingsObject, null, 2),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
debugLogger.error(`${warningPrefix}: ${getErrorMessage(e)}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (needsMigration(settingsObject)) {
|
if (needsMigration(settingsObject)) {
|
||||||
const migratedSettings = migrateV1ToV3(settingsObject);
|
const migrationResult = runMigrations(settingsObject, scope);
|
||||||
if (migratedSettings) {
|
if (migrationResult.executedMigrations.length > 0) {
|
||||||
if (MIGRATE_V2_OVERWRITE) {
|
settingsObject = migrationResult.settings as Record<
|
||||||
try {
|
string,
|
||||||
fs.renameSync(filePath, `${filePath}.orig`);
|
unknown
|
||||||
fs.writeFileSync(
|
>;
|
||||||
filePath,
|
migrationWarnings = migrationResult.warnings;
|
||||||
JSON.stringify(migratedSettings, null, 2),
|
persistSettingsObject('Error migrating settings file on disk');
|
||||||
'utf-8',
|
} else if (hasLegacyNumericVersion || hasInvalidVersion) {
|
||||||
);
|
// Migration was deemed needed but nothing executed. Normalize version metadata
|
||||||
} catch (e) {
|
// to avoid repeated no-op checks on startup.
|
||||||
writeStderrLine(
|
settingsObject[SETTINGS_VERSION_KEY] = SETTINGS_VERSION;
|
||||||
`Error migrating settings file on disk: ${getErrorMessage(
|
debugLogger.warn(
|
||||||
e,
|
`Settings version metadata in ${filePath} could not be migrated by any registered migration. Normalizing ${SETTINGS_VERSION_KEY} to ${SETTINGS_VERSION}.`,
|
||||||
)}`,
|
);
|
||||||
);
|
persistSettingsObject('Error normalizing settings version on disk');
|
||||||
}
|
|
||||||
} else {
|
|
||||||
migratedInMemorScopes.add(scope);
|
|
||||||
}
|
|
||||||
settingsObject = migratedSettings;
|
|
||||||
}
|
}
|
||||||
} else if (!(SETTINGS_VERSION_KEY in settingsObject)) {
|
} else if (
|
||||||
// No migration needed, but version field is missing - add it for future optimizations
|
!hasVersionKey ||
|
||||||
|
hasInvalidVersion ||
|
||||||
|
hasLegacyNumericVersion
|
||||||
|
) {
|
||||||
|
// No migration needed/executable, but version metadata is missing or invalid.
|
||||||
|
// Normalize it to current version to avoid repeated startup work.
|
||||||
settingsObject[SETTINGS_VERSION_KEY] = SETTINGS_VERSION;
|
settingsObject[SETTINGS_VERSION_KEY] = SETTINGS_VERSION;
|
||||||
if (MIGRATE_V2_OVERWRITE) {
|
persistSettingsObject('Error normalizing settings version on disk');
|
||||||
try {
|
|
||||||
fs.writeFileSync(
|
|
||||||
filePath,
|
|
||||||
JSON.stringify(settingsObject, null, 2),
|
|
||||||
'utf-8',
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
writeStderrLine(
|
|
||||||
`Error adding version to settings file: ${getErrorMessage(e)}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// V2 to V3 migration (invert disable* -> enable* booleans)
|
return {
|
||||||
const v3Migrated = migrateV2ToV3(settingsObject);
|
settings: settingsObject as Settings,
|
||||||
if (v3Migrated) {
|
rawJson: content,
|
||||||
if (MIGRATE_V2_OVERWRITE) {
|
migrationWarnings,
|
||||||
try {
|
};
|
||||||
// Only backup if not already backed up by V1->V2 migration
|
|
||||||
const backupPath = `${filePath}.orig`;
|
|
||||||
if (!fs.existsSync(backupPath)) {
|
|
||||||
fs.renameSync(filePath, backupPath);
|
|
||||||
}
|
|
||||||
fs.writeFileSync(
|
|
||||||
filePath,
|
|
||||||
JSON.stringify(v3Migrated, null, 2),
|
|
||||||
'utf-8',
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
writeStderrLine(
|
|
||||||
`Error migrating settings file to V3: ${getErrorMessage(e)}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
migratedInMemorScopes.add(scope);
|
|
||||||
}
|
|
||||||
settingsObject = v3Migrated;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { settings: settingsObject as Settings, rawJson: content };
|
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
settingsErrors.push({
|
settingsErrors.push({
|
||||||
|
|
@ -1070,7 +605,11 @@ export function loadSettings(
|
||||||
);
|
);
|
||||||
const userResult = loadAndMigrate(USER_SETTINGS_PATH, SettingScope.User);
|
const userResult = loadAndMigrate(USER_SETTINGS_PATH, SettingScope.User);
|
||||||
|
|
||||||
let workspaceResult: { settings: Settings; rawJson?: string } = {
|
let workspaceResult: {
|
||||||
|
settings: Settings;
|
||||||
|
rawJson?: string;
|
||||||
|
migrationWarnings?: string[];
|
||||||
|
} = {
|
||||||
settings: {} as Settings,
|
settings: {} as Settings,
|
||||||
rawJson: undefined,
|
rawJson: undefined,
|
||||||
};
|
};
|
||||||
|
|
@ -1140,6 +679,14 @@ export function loadSettings(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collect all migration warnings from all scopes
|
||||||
|
const allMigrationWarnings: string[] = [
|
||||||
|
...(systemResult.migrationWarnings ?? []),
|
||||||
|
...(systemDefaultsResult.migrationWarnings ?? []),
|
||||||
|
...(userResult.migrationWarnings ?? []),
|
||||||
|
...(workspaceResult.migrationWarnings ?? []),
|
||||||
|
];
|
||||||
|
|
||||||
return new LoadedSettings(
|
return new LoadedSettings(
|
||||||
{
|
{
|
||||||
path: systemSettingsPath,
|
path: systemSettingsPath,
|
||||||
|
|
@ -1167,6 +714,7 @@ export function loadSettings(
|
||||||
},
|
},
|
||||||
isTrusted,
|
isTrusted,
|
||||||
migratedInMemorScopes,
|
migratedInMemorScopes,
|
||||||
|
allMigrationWarnings,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1178,21 +726,14 @@ export function saveSettings(settingsFile: SettingsFile): void {
|
||||||
fs.mkdirSync(dirPath, { recursive: true });
|
fs.mkdirSync(dirPath, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
let settingsToSave = settingsFile.originalSettings;
|
|
||||||
if (!MIGRATE_V2_OVERWRITE) {
|
|
||||||
settingsToSave = migrateSettingsToV1(
|
|
||||||
settingsToSave as Record<string, unknown>,
|
|
||||||
) as Settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the format-preserving update function
|
// Use the format-preserving update function
|
||||||
updateSettingsFilePreservingFormat(
|
updateSettingsFilePreservingFormat(
|
||||||
settingsFile.path,
|
settingsFile.path,
|
||||||
settingsToSave as Record<string, unknown>,
|
settingsFile.originalSettings as Record<string, unknown>,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
writeStderrLine('Error saving user settings file.');
|
debugLogger.error('Error saving user settings file.');
|
||||||
writeStderrLine(error instanceof Error ? error.message : String(error));
|
debugLogger.error(error instanceof Error ? error.message : String(error));
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ describe('SettingsSchema', () => {
|
||||||
'mcp',
|
'mcp',
|
||||||
'security',
|
'security',
|
||||||
'advanced',
|
'advanced',
|
||||||
'experimental',
|
'webSearch',
|
||||||
];
|
];
|
||||||
|
|
||||||
expectedSettings.forEach((setting) => {
|
expectedSettings.forEach((setting) => {
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ const SETTINGS_SCHEMA = {
|
||||||
requiresRestart: true,
|
requiresRestart: true,
|
||||||
default: {} as Record<string, string>,
|
default: {} as Record<string, string>,
|
||||||
description:
|
description:
|
||||||
'Environment variables to set as fallback defaults. These are loaded with the lowest priority: system environment variables > .env files > settings.env.',
|
'Environment variables to set as fallback defaults. These are loaded with the lowest priority: system environment variables > .env files > settings.json env field.',
|
||||||
showInDialog: false,
|
showInDialog: false,
|
||||||
mergeStrategy: MergeStrategy.SHALLOW_MERGE,
|
mergeStrategy: MergeStrategy.SHALLOW_MERGE,
|
||||||
},
|
},
|
||||||
|
|
@ -589,7 +589,7 @@ const SETTINGS_SCHEMA = {
|
||||||
label: 'Skip Loop Detection',
|
label: 'Skip Loop Detection',
|
||||||
category: 'Model',
|
category: 'Model',
|
||||||
requiresRestart: false,
|
requiresRestart: false,
|
||||||
default: false,
|
default: true,
|
||||||
description: 'Disable all loop detection checks (streaming and LLM).',
|
description: 'Disable all loop detection checks (streaming and LLM).',
|
||||||
showInDialog: false,
|
showInDialog: false,
|
||||||
},
|
},
|
||||||
|
|
@ -1177,34 +1177,71 @@ const SETTINGS_SCHEMA = {
|
||||||
showInDialog: false,
|
showInDialog: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
experimental: {
|
hooksConfig: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
label: 'Experimental',
|
label: 'Hooks Config',
|
||||||
category: 'Experimental',
|
category: 'Advanced',
|
||||||
requiresRestart: true,
|
requiresRestart: false,
|
||||||
default: {},
|
default: {},
|
||||||
description: 'Setting to enable experimental features',
|
description:
|
||||||
|
'Hook configurations for intercepting and customizing agent behavior.',
|
||||||
showInDialog: false,
|
showInDialog: false,
|
||||||
properties: {
|
properties: {
|
||||||
visionModelPreview: {
|
enabled: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
label: 'Vision Model Preview',
|
label: 'Enable Hooks',
|
||||||
category: 'Experimental',
|
category: 'Advanced',
|
||||||
requiresRestart: false,
|
requiresRestart: true,
|
||||||
default: true,
|
default: true,
|
||||||
description:
|
description:
|
||||||
'Enable vision model support and auto-switching functionality. When disabled, vision models like qwen-vl-max-latest will be hidden and auto-switching will not occur.',
|
'Canonical toggle for the hooks system. When disabled, no hooks will be executed.',
|
||||||
showInDialog: false,
|
showInDialog: false,
|
||||||
},
|
},
|
||||||
vlmSwitchMode: {
|
disabled: {
|
||||||
type: 'string',
|
type: 'array',
|
||||||
label: 'VLM Switch Mode',
|
label: 'Disabled Hooks',
|
||||||
category: 'Experimental',
|
category: 'Advanced',
|
||||||
requiresRestart: false,
|
requiresRestart: false,
|
||||||
default: undefined as string | undefined,
|
default: [] as string[],
|
||||||
description:
|
description:
|
||||||
'Default behavior when images are detected in input. Values: once (one-time switch), session (switch for entire session), persist (continue with current model). If not set, user will be prompted each time. This is a temporary experimental feature.',
|
'List of hook names (commands) that should be disabled. Hooks in this list will not execute even if configured.',
|
||||||
showInDialog: false,
|
showInDialog: false,
|
||||||
|
mergeStrategy: MergeStrategy.UNION,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
hooks: {
|
||||||
|
type: 'object',
|
||||||
|
label: 'Hooks',
|
||||||
|
category: 'Advanced',
|
||||||
|
requiresRestart: false,
|
||||||
|
default: {},
|
||||||
|
description:
|
||||||
|
'Hook event configurations for extending CLI behavior at various lifecycle points.',
|
||||||
|
showInDialog: false,
|
||||||
|
properties: {
|
||||||
|
UserPromptSubmit: {
|
||||||
|
type: 'array',
|
||||||
|
label: 'Before Agent Hooks',
|
||||||
|
category: 'Advanced',
|
||||||
|
requiresRestart: false,
|
||||||
|
default: [],
|
||||||
|
description:
|
||||||
|
'Hooks that execute before agent processing. Can modify prompts or inject context.',
|
||||||
|
showInDialog: false,
|
||||||
|
mergeStrategy: MergeStrategy.CONCAT,
|
||||||
|
},
|
||||||
|
Stop: {
|
||||||
|
type: 'array',
|
||||||
|
label: 'After Agent Hooks',
|
||||||
|
category: 'Advanced',
|
||||||
|
requiresRestart: false,
|
||||||
|
default: [],
|
||||||
|
description:
|
||||||
|
'Hooks that execute after agent processing. Can post-process responses or log interactions.',
|
||||||
|
showInDialog: false,
|
||||||
|
mergeStrategy: MergeStrategy.CONCAT,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 1000000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -68,12 +69,18 @@ export function generateCodingPlanTemplate(
|
||||||
name: '[Bailian Coding Plan] qwen3-coder-plus',
|
name: '[Bailian Coding Plan] qwen3-coder-plus',
|
||||||
baseUrl: 'https://coding.dashscope.aliyuncs.com/v1',
|
baseUrl: 'https://coding.dashscope.aliyuncs.com/v1',
|
||||||
envKey: CODING_PLAN_ENV_KEY,
|
envKey: CODING_PLAN_ENV_KEY,
|
||||||
|
generationConfig: {
|
||||||
|
contextWindowSize: 1000000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'qwen3-coder-next',
|
id: 'qwen3-coder-next',
|
||||||
name: '[Bailian Coding Plan] qwen3-coder-next',
|
name: '[Bailian Coding Plan] qwen3-coder-next',
|
||||||
baseUrl: 'https://coding.dashscope.aliyuncs.com/v1',
|
baseUrl: 'https://coding.dashscope.aliyuncs.com/v1',
|
||||||
envKey: CODING_PLAN_ENV_KEY,
|
envKey: CODING_PLAN_ENV_KEY,
|
||||||
|
generationConfig: {
|
||||||
|
contextWindowSize: 262144,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'qwen3-max-2026-01-23',
|
id: 'qwen3-max-2026-01-23',
|
||||||
|
|
@ -84,6 +91,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 262144,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -95,6 +103,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 202752,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -106,6 +115,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 202752,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -117,6 +127,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 1000000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -128,6 +139,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 262144,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -144,6 +156,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 1000000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -151,12 +164,18 @@ export function generateCodingPlanTemplate(
|
||||||
name: '[Bailian Coding Plan for Global/Intl] qwen3-coder-plus',
|
name: '[Bailian Coding Plan for Global/Intl] qwen3-coder-plus',
|
||||||
baseUrl: 'https://coding-intl.dashscope.aliyuncs.com/v1',
|
baseUrl: 'https://coding-intl.dashscope.aliyuncs.com/v1',
|
||||||
envKey: CODING_PLAN_ENV_KEY,
|
envKey: CODING_PLAN_ENV_KEY,
|
||||||
|
generationConfig: {
|
||||||
|
contextWindowSize: 1000000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'qwen3-coder-next',
|
id: 'qwen3-coder-next',
|
||||||
name: '[Bailian Coding Plan for Global/Intl] qwen3-coder-next',
|
name: '[Bailian Coding Plan for Global/Intl] qwen3-coder-next',
|
||||||
baseUrl: 'https://coding-intl.dashscope.aliyuncs.com/v1',
|
baseUrl: 'https://coding-intl.dashscope.aliyuncs.com/v1',
|
||||||
envKey: CODING_PLAN_ENV_KEY,
|
envKey: CODING_PLAN_ENV_KEY,
|
||||||
|
generationConfig: {
|
||||||
|
contextWindowSize: 262144,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'qwen3-max-2026-01-23',
|
id: 'qwen3-max-2026-01-23',
|
||||||
|
|
@ -167,6 +186,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 262144,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -178,6 +198,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 202752,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -189,6 +210,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 202752,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -200,6 +222,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 1000000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -211,6 +234,7 @@ export function generateCodingPlanTemplate(
|
||||||
extra_body: {
|
extra_body: {
|
||||||
enable_thinking: true,
|
enable_thinking: true,
|
||||||
},
|
},
|
||||||
|
contextWindowSize: 262144,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -227,15 +251,9 @@ export function getCodingPlanConfig(region: CodingPlanRegion) {
|
||||||
region === CodingPlanRegion.CHINA
|
region === CodingPlanRegion.CHINA
|
||||||
? 'https://coding.dashscope.aliyuncs.com/v1'
|
? 'https://coding.dashscope.aliyuncs.com/v1'
|
||||||
: 'https://coding-intl.dashscope.aliyuncs.com/v1';
|
: 'https://coding-intl.dashscope.aliyuncs.com/v1';
|
||||||
const regionName =
|
|
||||||
region === CodingPlanRegion.CHINA
|
|
||||||
? 'Coding Plan (Bailian, China)'
|
|
||||||
: 'Coding Plan (Bailian, Global/Intl)';
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
template,
|
template,
|
||||||
baseUrl,
|
baseUrl,
|
||||||
regionName,
|
|
||||||
version: computeCodingPlanVersion(template),
|
version: computeCodingPlanVersion(template),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ vi.mock('./config/config.js', () => ({
|
||||||
getSandbox: vi.fn(() => false),
|
getSandbox: vi.fn(() => false),
|
||||||
getQuestion: vi.fn(() => ''),
|
getQuestion: vi.fn(() => ''),
|
||||||
isInteractive: () => false,
|
isInteractive: () => false,
|
||||||
|
getWarnings: vi.fn(() => []),
|
||||||
} as unknown as Config),
|
} as unknown as Config),
|
||||||
parseArguments: vi.fn().mockResolvedValue({}),
|
parseArguments: vi.fn().mockResolvedValue({}),
|
||||||
isDebugMode: vi.fn(() => false),
|
isDebugMode: vi.fn(() => false),
|
||||||
|
|
@ -177,6 +178,7 @@ describe('gemini.tsx main function', () => {
|
||||||
getGeminiMdFileCount: () => 0,
|
getGeminiMdFileCount: () => 0,
|
||||||
getProjectRoot: () => '/',
|
getProjectRoot: () => '/',
|
||||||
getOutputFormat: () => OutputFormat.TEXT,
|
getOutputFormat: () => OutputFormat.TEXT,
|
||||||
|
getWarnings: () => [],
|
||||||
} as unknown as Config;
|
} as unknown as Config;
|
||||||
});
|
});
|
||||||
vi.mocked(loadSettings).mockReturnValue({
|
vi.mocked(loadSettings).mockReturnValue({
|
||||||
|
|
@ -188,6 +190,7 @@ describe('gemini.tsx main function', () => {
|
||||||
},
|
},
|
||||||
setValue: vi.fn(),
|
setValue: vi.fn(),
|
||||||
forScope: () => ({ settings: {}, originalSettings: {}, path: '' }),
|
forScope: () => ({ settings: {}, originalSettings: {}, path: '' }),
|
||||||
|
migrationWarnings: [],
|
||||||
} as never);
|
} as never);
|
||||||
try {
|
try {
|
||||||
await main();
|
await main();
|
||||||
|
|
@ -260,7 +263,7 @@ describe('gemini.tsx main function', () => {
|
||||||
'isRaw',
|
'isRaw',
|
||||||
);
|
);
|
||||||
Object.defineProperty(process.stdin, 'isTTY', {
|
Object.defineProperty(process.stdin, 'isTTY', {
|
||||||
value: true,
|
value: false, // 在 stream-json 模式下应为 false
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
Object.defineProperty(process.stdin, 'isRaw', {
|
Object.defineProperty(process.stdin, 'isRaw', {
|
||||||
|
|
@ -320,6 +323,7 @@ describe('gemini.tsx main function', () => {
|
||||||
},
|
},
|
||||||
setValue: vi.fn(),
|
setValue: vi.fn(),
|
||||||
forScope: () => ({ settings: {}, originalSettings: {}, path: '' }),
|
forScope: () => ({ settings: {}, originalSettings: {}, path: '' }),
|
||||||
|
migrationWarnings: [],
|
||||||
} as never);
|
} as never);
|
||||||
|
|
||||||
vi.mocked(parseArguments).mockResolvedValue({
|
vi.mocked(parseArguments).mockResolvedValue({
|
||||||
|
|
@ -341,6 +345,10 @@ describe('gemini.tsx main function', () => {
|
||||||
getProjectRoot: () => '/',
|
getProjectRoot: () => '/',
|
||||||
getInputFormat: () => 'stream-json',
|
getInputFormat: () => 'stream-json',
|
||||||
getContentGeneratorConfig: () => ({ authType: 'test-auth' }),
|
getContentGeneratorConfig: () => ({ authType: 'test-auth' }),
|
||||||
|
getWarnings: () => [],
|
||||||
|
getUsageStatisticsEnabled: () => true,
|
||||||
|
getSessionId: () => 'test-session-id',
|
||||||
|
getOutputFormat: () => OutputFormat.TEXT,
|
||||||
} as unknown as Config;
|
} as unknown as Config;
|
||||||
|
|
||||||
vi.mocked(loadCliConfig).mockResolvedValue(configStub);
|
vi.mocked(loadCliConfig).mockResolvedValue(configStub);
|
||||||
|
|
@ -438,6 +446,8 @@ describe('gemini.tsx main function kitty protocol', () => {
|
||||||
getExperimentalZedIntegration: () => false,
|
getExperimentalZedIntegration: () => false,
|
||||||
getScreenReader: () => false,
|
getScreenReader: () => false,
|
||||||
getGeminiMdFileCount: () => 0,
|
getGeminiMdFileCount: () => 0,
|
||||||
|
getWarnings: () => [],
|
||||||
|
getUsageStatisticsEnabled: () => true,
|
||||||
} as unknown as Config);
|
} as unknown as Config);
|
||||||
vi.mocked(loadSettings).mockReturnValue({
|
vi.mocked(loadSettings).mockReturnValue({
|
||||||
errors: [],
|
errors: [],
|
||||||
|
|
@ -448,6 +458,7 @@ describe('gemini.tsx main function kitty protocol', () => {
|
||||||
},
|
},
|
||||||
setValue: vi.fn(),
|
setValue: vi.fn(),
|
||||||
forScope: () => ({ settings: {}, originalSettings: {}, path: '' }),
|
forScope: () => ({ settings: {}, originalSettings: {}, path: '' }),
|
||||||
|
migrationWarnings: [],
|
||||||
} as never);
|
} as never);
|
||||||
vi.mocked(parseArguments).mockResolvedValue({
|
vi.mocked(parseArguments).mockResolvedValue({
|
||||||
model: undefined,
|
model: undefined,
|
||||||
|
|
@ -483,7 +494,6 @@ describe('gemini.tsx main function kitty protocol', () => {
|
||||||
googleSearchEngineId: undefined,
|
googleSearchEngineId: undefined,
|
||||||
webSearchDefault: undefined,
|
webSearchDefault: undefined,
|
||||||
screenReader: undefined,
|
screenReader: undefined,
|
||||||
vlmSwitchMode: undefined,
|
|
||||||
inputFormat: undefined,
|
inputFormat: undefined,
|
||||||
outputFormat: undefined,
|
outputFormat: undefined,
|
||||||
includePartialMessages: undefined,
|
includePartialMessages: undefined,
|
||||||
|
|
@ -494,6 +504,7 @@ describe('gemini.tsx main function kitty protocol', () => {
|
||||||
authType: undefined,
|
authType: undefined,
|
||||||
maxSessionTurns: undefined,
|
maxSessionTurns: undefined,
|
||||||
experimentalLsp: undefined,
|
experimentalLsp: undefined,
|
||||||
|
experimentalHooks: undefined,
|
||||||
channel: undefined,
|
channel: undefined,
|
||||||
chatRecording: undefined,
|
chatRecording: undefined,
|
||||||
sessionId: undefined,
|
sessionId: undefined,
|
||||||
|
|
|
||||||
|
|
@ -385,17 +385,16 @@ export async function main() {
|
||||||
setMaxSizedBoxDebugging(isDebugMode);
|
setMaxSizedBoxDebugging(isDebugMode);
|
||||||
|
|
||||||
// Check input format early to determine initialization flow
|
// Check input format early to determine initialization flow
|
||||||
const inputFormat =
|
// In TTY mode, ignore stream-json input format to prevent process from hanging
|
||||||
typeof config.getInputFormat === 'function'
|
const inputFormat = process.stdin.isTTY
|
||||||
|
? InputFormat.TEXT
|
||||||
|
: typeof config.getInputFormat === 'function'
|
||||||
? config.getInputFormat()
|
? config.getInputFormat()
|
||||||
: InputFormat.TEXT;
|
: InputFormat.TEXT;
|
||||||
|
|
||||||
// For stream-json mode, defer config.initialize() until after the initialize control request
|
// For stream-json mode, defer config.initialize() until after the initialize control request
|
||||||
// For other modes, initialize normally
|
// For other modes, initialize normally
|
||||||
let initializationResult: InitializationResult | undefined;
|
const initializationResult = await initializeApp(config, settings);
|
||||||
if (inputFormat !== InputFormat.STREAM_JSON) {
|
|
||||||
initializationResult = await initializeApp(config, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.getExperimentalZedIntegration()) {
|
if (config.getExperimentalZedIntegration()) {
|
||||||
return runAcpAgent(config, settings, argv);
|
return runAcpAgent(config, settings, argv);
|
||||||
|
|
@ -411,6 +410,7 @@ export async function main() {
|
||||||
useBuiltinRipgrep: settings.merged.tools?.useBuiltinRipgrep ?? true,
|
useBuiltinRipgrep: settings.merged.tools?.useBuiltinRipgrep ?? true,
|
||||||
})),
|
})),
|
||||||
...getSettingsWarnings(settings),
|
...getSettingsWarnings(settings),
|
||||||
|
...config.getWarnings(),
|
||||||
]),
|
]),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,7 @@ export default {
|
||||||
'Enter to confirm, Esc to cancel': 'Enter zum Bestätigen, Esc zum Abbrechen',
|
'Enter to confirm, Esc to cancel': 'Enter zum Bestätigen, Esc zum Abbrechen',
|
||||||
'Enter to select, ↑↓ to navigate, Esc to go back':
|
'Enter to select, ↑↓ to navigate, Esc to go back':
|
||||||
'Enter zum Auswählen, ↑↓ zum Navigieren, Esc zum Zurückgehen',
|
'Enter zum Auswählen, ↑↓ zum Navigieren, Esc zum Zurückgehen',
|
||||||
|
'Enter to submit, Esc to go back': 'Enter zum Absenden, Esc zum Zurückgehen',
|
||||||
'Invalid step: {{step}}': 'Ungültiger Schritt: {{step}}',
|
'Invalid step: {{step}}': 'Ungültiger Schritt: {{step}}',
|
||||||
'No subagents found.': 'Keine Unteragenten gefunden.',
|
'No subagents found.': 'Keine Unteragenten gefunden.',
|
||||||
"Use '/agents create' to create your first subagent.":
|
"Use '/agents create' to create your first subagent.":
|
||||||
|
|
@ -908,7 +909,6 @@ export default {
|
||||||
'missing name': 'Name fehlt',
|
'missing name': 'Name fehlt',
|
||||||
'missing description': 'Beschreibung fehlt',
|
'missing description': 'Beschreibung fehlt',
|
||||||
'(unnamed)': '(unbenannt)',
|
'(unnamed)': '(unbenannt)',
|
||||||
unknown: 'unbekannt',
|
|
||||||
'Warning: This tool cannot be called by the LLM':
|
'Warning: This tool cannot be called by the LLM':
|
||||||
'Warnung: Dieses Werkzeug kann nicht vom LLM aufgerufen werden',
|
'Warnung: Dieses Werkzeug kann nicht vom LLM aufgerufen werden',
|
||||||
Reason: 'Grund',
|
Reason: 'Grund',
|
||||||
|
|
@ -974,18 +974,22 @@ export default {
|
||||||
// Dialogs - Auth
|
// Dialogs - Auth
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Get started': 'Loslegen',
|
'Get started': 'Loslegen',
|
||||||
'How would you like to authenticate for this project?':
|
'Select Authentication Method': 'Authentifizierungsmethode auswählen',
|
||||||
'Wie möchten Sie sich für dieses Projekt authentifizieren?',
|
|
||||||
'OpenAI API key is required to use OpenAI authentication.':
|
'OpenAI API key is required to use OpenAI authentication.':
|
||||||
'OpenAI API-Schlüssel ist für die OpenAI-Authentifizierung erforderlich.',
|
'OpenAI API-Schlüssel ist für die OpenAI-Authentifizierung erforderlich.',
|
||||||
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
||||||
'Sie müssen eine Authentifizierungsmethode wählen, um fortzufahren. Drücken Sie erneut Strg+C zum Beenden.',
|
'Sie müssen eine Authentifizierungsmethode wählen, um fortzufahren. Drücken Sie erneut Strg+C zum Beenden.',
|
||||||
'(Use Enter to Set Auth)': '(Enter zum Festlegen der Authentifizierung)',
|
'Terms of Services and Privacy Notice':
|
||||||
'Terms of Services and Privacy Notice for Qwen Code':
|
'Nutzungsbedingungen und Datenschutzhinweis',
|
||||||
'Nutzungsbedingungen und Datenschutzhinweis für Qwen Code',
|
|
||||||
'Qwen OAuth': 'Qwen OAuth',
|
'Qwen OAuth': 'Qwen OAuth',
|
||||||
|
'Free \u00B7 Up to 1,000 requests/day \u00B7 Qwen latest models':
|
||||||
|
'Kostenlos \u00B7 Bis zu 1.000 Anfragen/Tag \u00B7 Qwen neueste Modelle',
|
||||||
'Login with QwenChat account to use daily free quota.':
|
'Login with QwenChat account to use daily free quota.':
|
||||||
'Melden Sie sich mit Ihrem QwenChat-Konto an, um das tägliche kostenlose Kontingent zu nutzen.',
|
'Melden Sie sich mit Ihrem QwenChat-Konto an, um das tägliche kostenlose Kontingent zu nutzen.',
|
||||||
|
'Paid \u00B7 Up to 6,000 requests/5 hrs \u00B7 All Alibaba Cloud Coding Plan Models':
|
||||||
|
'Kostenpflichtig \u00B7 Bis zu 6.000 Anfragen/5 Std. \u00B7 Alle Alibaba Cloud Coding Plan Modelle',
|
||||||
|
'Alibaba Cloud Coding Plan': 'Alibaba Cloud Coding Plan',
|
||||||
|
'Bring your own API key': 'Eigenen API-Schlüssel verwenden',
|
||||||
'API-KEY': 'API-KEY',
|
'API-KEY': 'API-KEY',
|
||||||
'Use coding plan credentials or your own api-keys/providers.':
|
'Use coding plan credentials or your own api-keys/providers.':
|
||||||
'Verwenden Sie Coding Plan-Anmeldedaten oder Ihre eigenen API-Schlüssel/Anbieter.',
|
'Verwenden Sie Coding Plan-Anmeldedaten oder Ihre eigenen API-Schlüssel/Anbieter.',
|
||||||
|
|
@ -1015,6 +1019,8 @@ export default {
|
||||||
'Warten auf Qwen OAuth-Authentifizierung...',
|
'Warten auf Qwen OAuth-Authentifizierung...',
|
||||||
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
||||||
'Hinweis: Ihr bestehender API-Schlüssel in settings.json wird bei Verwendung von Qwen OAuth nicht gelöscht. Sie können später bei Bedarf zur OpenAI-Authentifizierung zurückwechseln.',
|
'Hinweis: Ihr bestehender API-Schlüssel in settings.json wird bei Verwendung von Qwen OAuth nicht gelöscht. Sie können später bei Bedarf zur OpenAI-Authentifizierung zurückwechseln.',
|
||||||
|
'Note: Your existing API key will not be cleared when using Qwen OAuth.':
|
||||||
|
'Hinweis: Ihr bestehender API-Schlüssel wird bei Verwendung von Qwen OAuth nicht gelöscht.',
|
||||||
'Authentication timed out. Please try again.':
|
'Authentication timed out. Please try again.':
|
||||||
'Authentifizierung abgelaufen. Bitte versuchen Sie es erneut.',
|
'Authentifizierung abgelaufen. Bitte versuchen Sie es erneut.',
|
||||||
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
||||||
|
|
@ -1064,6 +1070,17 @@ export default {
|
||||||
'(default)': '(Standard)',
|
'(default)': '(Standard)',
|
||||||
'(set)': '(gesetzt)',
|
'(set)': '(gesetzt)',
|
||||||
'(not set)': '(nicht gesetzt)',
|
'(not set)': '(nicht gesetzt)',
|
||||||
|
Modality: 'Modalität',
|
||||||
|
'Context Window': 'Kontextfenster',
|
||||||
|
text: 'Text',
|
||||||
|
'text-only': 'nur Text',
|
||||||
|
image: 'Bild',
|
||||||
|
pdf: 'PDF',
|
||||||
|
audio: 'Audio',
|
||||||
|
video: 'Video',
|
||||||
|
'not set': 'nicht gesetzt',
|
||||||
|
none: 'keine',
|
||||||
|
unknown: 'unbekannt',
|
||||||
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
||||||
"Modell konnte nicht auf '{{modelId}}' umgestellt werden.\n\n{{error}}",
|
"Modell konnte nicht auf '{{modelId}}' umgestellt werden.\n\n{{error}}",
|
||||||
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
||||||
|
|
@ -1410,38 +1427,43 @@ export default {
|
||||||
'Erweiterungsseite wird im Browser geöffnet: {{url}}',
|
'Erweiterungsseite wird im Browser geöffnet: {{url}}',
|
||||||
'Failed to open browser. Check out the extensions gallery at {{url}}':
|
'Failed to open browser. Check out the extensions gallery at {{url}}':
|
||||||
'Browser konnte nicht geöffnet werden. Besuchen Sie die Erweiterungsgalerie unter {{url}}',
|
'Browser konnte nicht geöffnet werden. Besuchen Sie die Erweiterungsgalerie unter {{url}}',
|
||||||
|
'Use /compress when the conversation gets long to summarize history and free up context.':
|
||||||
|
'Verwenden Sie /compress, wenn die Unterhaltung lang wird, um den Verlauf zusammenzufassen und Kontext freizugeben.',
|
||||||
|
'Start a fresh idea with /clear or /new; the previous session stays available in history.':
|
||||||
|
'Starten Sie eine neue Idee mit /clear oder /new; die vorherige Sitzung bleibt im Verlauf verfügbar.',
|
||||||
|
'Use /bug to submit issues to the maintainers when something goes off.':
|
||||||
|
'Verwenden Sie /bug, um Probleme an die Betreuer zu melden, wenn etwas schiefgeht.',
|
||||||
|
'Switch auth type quickly with /auth.':
|
||||||
|
'Wechseln Sie den Authentifizierungstyp schnell mit /auth.',
|
||||||
|
'You can run any shell commands from Qwen Code using ! (e.g. !ls).':
|
||||||
|
'Sie können beliebige Shell-Befehle in Qwen Code mit ! ausführen (z. B. !ls).',
|
||||||
|
'Type / to open the command popup; Tab autocompletes slash commands and saved prompts.':
|
||||||
|
'Geben Sie / ein, um das Befehlsmenü zu öffnen; Tab vervollständigt Slash-Befehle und gespeicherte Prompts.',
|
||||||
|
'You can resume a previous conversation by running qwen --continue or qwen --resume.':
|
||||||
|
'Sie können eine frühere Unterhaltung mit qwen --continue oder qwen --resume fortsetzen.',
|
||||||
'You can switch permission mode quickly with Shift+Tab or /approval-mode.':
|
'You can switch permission mode quickly with Shift+Tab or /approval-mode.':
|
||||||
'Sie können den Berechtigungsmodus schnell mit Shift+Tab oder /approval-mode wechseln.',
|
'Sie können den Berechtigungsmodus schnell mit Shift+Tab oder /approval-mode wechseln.',
|
||||||
'You can switch permission mode quickly with Tab or /approval-mode.':
|
'You can switch permission mode quickly with Tab or /approval-mode.':
|
||||||
'Sie können den Berechtigungsmodus schnell mit Tab oder /approval-mode wechseln.',
|
'Sie können den Berechtigungsmodus schnell mit Tab oder /approval-mode wechseln.',
|
||||||
|
'Try /insight to generate personalized insights from your chat history.':
|
||||||
|
'Probieren Sie /insight, um personalisierte Erkenntnisse aus Ihrem Chatverlauf zu erstellen.',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Custom API-KEY Configuration
|
// Custom API Key Configuration
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'For advanced users who want to configure models manually.':
|
'You can configure your API key and models in settings.json':
|
||||||
'Für fortgeschrittene Benutzer, die Modelle manuell konfigurieren möchten.',
|
'Sie können Ihren API-Schlüssel und Modelle in settings.json konfigurieren',
|
||||||
'Please configure your models in settings.json:':
|
'Refer to the documentation for setup instructions':
|
||||||
'Bitte konfigurieren Sie Ihre Modelle in settings.json:',
|
'Einrichtungsanweisungen finden Sie in der Dokumentation',
|
||||||
'Set API key via environment variable (e.g., OPENAI_API_KEY)':
|
|
||||||
'API-Schlüssel über Umgebungsvariable setzen (z.B. OPENAI_API_KEY)',
|
|
||||||
"Add model configuration to modelProviders['openai'] (or other auth types)":
|
|
||||||
"Modellkonfiguration zu modelProviders['openai'] (oder anderen Authentifizierungstypen) hinzufügen",
|
|
||||||
'Each provider needs: id, envKey (required), plus optional baseUrl, generationConfig':
|
|
||||||
'Jeder Anbieter benötigt: id, envKey (erforderlich), plus optionale baseUrl, generationConfig',
|
|
||||||
'Use /model command to select your preferred model from the configured list':
|
|
||||||
'Verwenden Sie den /model-Befehl, um Ihr bevorzugtes Modell aus der konfigurierten Liste auszuwählen',
|
|
||||||
'Supported auth types: openai, anthropic, gemini, vertex-ai, etc.':
|
|
||||||
'Unterstützte Authentifizierungstypen: openai, anthropic, gemini, vertex-ai, usw.',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan Authentication
|
// Coding Plan Authentication
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Please enter your API key:': 'Bitte geben Sie Ihren API-Schlüssel ein:',
|
|
||||||
'API key cannot be empty.': 'API-Schlüssel darf nicht leer sein.',
|
'API key cannot be empty.': 'API-Schlüssel darf nicht leer sein.',
|
||||||
'You can get your exclusive Coding Plan API-KEY here:':
|
'You can get your Coding Plan API key here':
|
||||||
'Hier können Sie Ihren exklusiven Coding Plan API-KEY erhalten:',
|
'Sie können Ihren Coding-Plan-API-Schlüssel hier erhalten',
|
||||||
'New model configurations are available for Bailian Coding Plan. Update now?':
|
'New model configurations are available for Alibaba Cloud Coding Plan. Update now?':
|
||||||
'Neue Modellkonfigurationen sind für Bailian Coding Plan verfügbar. Jetzt aktualisieren?',
|
'Neue Modellkonfigurationen sind für Alibaba Cloud Coding Plan verfügbar. Jetzt aktualisieren?',
|
||||||
'Coding Plan configuration updated successfully. New models are now available.':
|
'Coding Plan configuration updated successfully. New models are now available.':
|
||||||
'Coding Plan-Konfiguration erfolgreich aktualisiert. Neue Modelle sind jetzt verfügbar.',
|
'Coding Plan-Konfiguration erfolgreich aktualisiert. Neue Modelle sind jetzt verfügbar.',
|
||||||
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
||||||
|
|
@ -1452,34 +1474,18 @@ export default {
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Auth Dialog - View Titles and Labels
|
// Auth Dialog - View Titles and Labels
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Coding Plan': 'Coding Plan',
|
'Select Region for Coding Plan': 'Region für Coding Plan auswählen',
|
||||||
'Coding Plan (Bailian, China)': 'Coding Plan (Bailian, China)',
|
'Choose based on where your account is registered':
|
||||||
'Coding Plan (Bailian, Global/Intl)': 'Coding Plan (Bailian, Global/Intl)',
|
'Wählen Sie basierend auf dem Registrierungsort Ihres Kontos',
|
||||||
"Paste your api key of Bailian Coding Plan and you're all set!":
|
'Enter Coding Plan API Key': 'Coding-Plan-API-Schlüssel eingeben',
|
||||||
'Fügen Sie Ihren Bailian Coding Plan API-Schlüssel ein und Sie sind bereit!',
|
|
||||||
"Paste your api key of Coding Plan (Bailian, Global/Intl) and you're all set!":
|
|
||||||
'Fügen Sie Ihren Coding Plan (Bailian, Global/Intl) API-Schlüssel ein und Sie sind bereit!',
|
|
||||||
Custom: 'Benutzerdefiniert',
|
|
||||||
'More instructions about configuring `modelProviders` manually.':
|
|
||||||
'Weitere Anweisungen zur manuellen Konfiguration von `modelProviders`.',
|
|
||||||
'Select API-KEY configuration mode:':
|
|
||||||
'API-KEY-Konfigurationsmodus auswählen:',
|
|
||||||
'(Press Escape to go back)': '(Escape drücken zum Zurückgehen)',
|
|
||||||
'(Press Enter to submit, Escape to cancel)':
|
|
||||||
'(Enter zum Absenden, Escape zum Abbrechen)',
|
|
||||||
'More instructions please check:': 'Weitere Anweisungen finden Sie unter:',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan International Updates
|
// Coding Plan International Updates
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'New model configurations are available for {{region}}. Update now?':
|
'New model configurations are available for {{region}}. Update now?':
|
||||||
'Neue Modellkonfigurationen sind für {{region}} verfügbar. Jetzt aktualisieren?',
|
'Neue Modellkonfigurationen sind für {{region}} verfügbar. Jetzt aktualisieren?',
|
||||||
'New model configurations are available for Bailian Coding Plan (China). Update now?':
|
|
||||||
'Neue Modellkonfigurationen sind für Bailian Coding Plan (China) verfügbar. Jetzt aktualisieren?',
|
|
||||||
'New model configurations are available for Coding Plan (Bailian, Global/Intl). Update now?':
|
|
||||||
'Neue Modellkonfigurationen sind für Coding Plan (Bailian, Global/Intl) verfügbar. Jetzt aktualisieren?',
|
|
||||||
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
||||||
'{{region}}-Konfiguration erfolgreich aktualisiert. Modell auf "{{model}}" umgeschaltet.',
|
'{{region}}-Konfiguration erfolgreich aktualisiert. Modell auf "{{model}}" umgeschaltet.',
|
||||||
'Authenticated successfully with {{region}}. API key is stored in settings.env.':
|
'Authenticated successfully with {{region}}. API key and model configs saved to settings.json (backed up).':
|
||||||
'Erfolgreich mit {{region}} authentifiziert. API-Schlüssel ist in settings.env gespeichert.',
|
'Erfolgreich mit {{region}} authentifiziert. API-Schlüssel und Modellkonfigurationen wurden in settings.json gespeichert (gesichert).',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,7 @@ export default {
|
||||||
'Enter to confirm, Esc to cancel': 'Enter to confirm, Esc to cancel',
|
'Enter to confirm, Esc to cancel': 'Enter to confirm, Esc to cancel',
|
||||||
'Enter to select, ↑↓ to navigate, Esc to go back':
|
'Enter to select, ↑↓ to navigate, Esc to go back':
|
||||||
'Enter to select, ↑↓ to navigate, Esc to go back',
|
'Enter to select, ↑↓ to navigate, Esc to go back',
|
||||||
|
'Enter to submit, Esc to go back': 'Enter to submit, Esc to go back',
|
||||||
'Invalid step: {{step}}': 'Invalid step: {{step}}',
|
'Invalid step: {{step}}': 'Invalid step: {{step}}',
|
||||||
'No subagents found.': 'No subagents found.',
|
'No subagents found.': 'No subagents found.',
|
||||||
"Use '/agents create' to create your first subagent.":
|
"Use '/agents create' to create your first subagent.":
|
||||||
|
|
@ -792,7 +793,6 @@ export default {
|
||||||
'missing name': 'missing name',
|
'missing name': 'missing name',
|
||||||
'missing description': 'missing description',
|
'missing description': 'missing description',
|
||||||
'(unnamed)': '(unnamed)',
|
'(unnamed)': '(unnamed)',
|
||||||
unknown: 'unknown',
|
|
||||||
'Warning: This tool cannot be called by the LLM':
|
'Warning: This tool cannot be called by the LLM':
|
||||||
'Warning: This tool cannot be called by the LLM',
|
'Warning: This tool cannot be called by the LLM',
|
||||||
Reason: 'Reason',
|
Reason: 'Reason',
|
||||||
|
|
@ -994,18 +994,22 @@ export default {
|
||||||
// Dialogs - Auth
|
// Dialogs - Auth
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Get started': 'Get started',
|
'Get started': 'Get started',
|
||||||
'How would you like to authenticate for this project?':
|
'Select Authentication Method': 'Select Authentication Method',
|
||||||
'How would you like to authenticate for this project?',
|
|
||||||
'OpenAI API key is required to use OpenAI authentication.':
|
'OpenAI API key is required to use OpenAI authentication.':
|
||||||
'OpenAI API key is required to use OpenAI authentication.',
|
'OpenAI API key is required to use OpenAI authentication.',
|
||||||
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
||||||
'You must select an auth method to proceed. Press Ctrl+C again to exit.',
|
'You must select an auth method to proceed. Press Ctrl+C again to exit.',
|
||||||
'(Use Enter to Set Auth)': '(Use Enter to Set Auth)',
|
'Terms of Services and Privacy Notice':
|
||||||
'Terms of Services and Privacy Notice for Qwen Code':
|
'Terms of Services and Privacy Notice',
|
||||||
'Terms of Services and Privacy Notice for Qwen Code',
|
|
||||||
'Qwen OAuth': 'Qwen OAuth',
|
'Qwen OAuth': 'Qwen OAuth',
|
||||||
|
'Free \u00B7 Up to 1,000 requests/day \u00B7 Qwen latest models':
|
||||||
|
'Free \u00B7 Up to 1,000 requests/day \u00B7 Qwen latest models',
|
||||||
'Login with QwenChat account to use daily free quota.':
|
'Login with QwenChat account to use daily free quota.':
|
||||||
'Login with QwenChat account to use daily free quota.',
|
'Login with QwenChat account to use daily free quota.',
|
||||||
|
'Paid \u00B7 Up to 6,000 requests/5 hrs \u00B7 All Alibaba Cloud Coding Plan Models':
|
||||||
|
'Paid \u00B7 Up to 6,000 requests/5 hrs \u00B7 All Alibaba Cloud Coding Plan Models',
|
||||||
|
'Alibaba Cloud Coding Plan': 'Alibaba Cloud Coding Plan',
|
||||||
|
'Bring your own API key': 'Bring your own API key',
|
||||||
'API-KEY': 'API-KEY',
|
'API-KEY': 'API-KEY',
|
||||||
'Use coding plan credentials or your own api-keys/providers.':
|
'Use coding plan credentials or your own api-keys/providers.':
|
||||||
'Use coding plan credentials or your own api-keys/providers.',
|
'Use coding plan credentials or your own api-keys/providers.',
|
||||||
|
|
@ -1033,6 +1037,8 @@ export default {
|
||||||
'Waiting for Qwen OAuth authentication...',
|
'Waiting for Qwen OAuth authentication...',
|
||||||
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
||||||
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.',
|
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.',
|
||||||
|
'Note: Your existing API key will not be cleared when using Qwen OAuth.':
|
||||||
|
'Note: Your existing API key will not be cleared when using Qwen OAuth.',
|
||||||
'Authentication timed out. Please try again.':
|
'Authentication timed out. Please try again.':
|
||||||
'Authentication timed out. Please try again.',
|
'Authentication timed out. Please try again.',
|
||||||
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
||||||
|
|
@ -1080,6 +1086,17 @@ export default {
|
||||||
'(default)': '(default)',
|
'(default)': '(default)',
|
||||||
'(set)': '(set)',
|
'(set)': '(set)',
|
||||||
'(not set)': '(not set)',
|
'(not set)': '(not set)',
|
||||||
|
Modality: 'Modality',
|
||||||
|
'Context Window': 'Context Window',
|
||||||
|
text: 'text',
|
||||||
|
'text-only': 'text-only',
|
||||||
|
image: 'image',
|
||||||
|
pdf: 'pdf',
|
||||||
|
audio: 'audio',
|
||||||
|
video: 'video',
|
||||||
|
'not set': 'not set',
|
||||||
|
none: 'none',
|
||||||
|
unknown: 'unknown',
|
||||||
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
||||||
"Failed to switch model to '{{modelId}}'.\n\n{{error}}",
|
"Failed to switch model to '{{modelId}}'.\n\n{{error}}",
|
||||||
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
||||||
|
|
@ -1174,6 +1191,8 @@ export default {
|
||||||
'You can switch permission mode quickly with Shift+Tab or /approval-mode.',
|
'You can switch permission mode quickly with Shift+Tab or /approval-mode.',
|
||||||
'You can switch permission mode quickly with Tab or /approval-mode.':
|
'You can switch permission mode quickly with Tab or /approval-mode.':
|
||||||
'You can switch permission mode quickly with Tab or /approval-mode.',
|
'You can switch permission mode quickly with Tab or /approval-mode.',
|
||||||
|
'Try /insight to generate personalized insights from your chat history.':
|
||||||
|
'Try /insight to generate personalized insights from your chat history.',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Exit Screen / Stats
|
// Exit Screen / Stats
|
||||||
|
|
@ -1441,18 +1460,20 @@ export default {
|
||||||
'Rate limit error: {{reason}}': 'Rate limit error: {{reason}}',
|
'Rate limit error: {{reason}}': 'Rate limit error: {{reason}}',
|
||||||
'Retrying in {{seconds}} seconds… (attempt {{attempt}}/{{maxRetries}})':
|
'Retrying in {{seconds}} seconds… (attempt {{attempt}}/{{maxRetries}})':
|
||||||
'Retrying in {{seconds}} seconds… (attempt {{attempt}}/{{maxRetries}})',
|
'Retrying in {{seconds}} seconds… (attempt {{attempt}}/{{maxRetries}})',
|
||||||
|
'Press Ctrl+Y to retry': 'Press Ctrl+Y to retry',
|
||||||
|
'No failed request to retry.': 'No failed request to retry.',
|
||||||
|
'to retry last request': 'to retry last request',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan Authentication
|
// Coding Plan Authentication
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Please enter your API key:': 'Please enter your API key:',
|
|
||||||
'API key cannot be empty.': 'API key cannot be empty.',
|
'API key cannot be empty.': 'API key cannot be empty.',
|
||||||
'You can get your exclusive Coding Plan API-KEY here:':
|
'You can get your Coding Plan API key here':
|
||||||
'You can get your exclusive Coding Plan API-KEY here:',
|
'You can get your Coding Plan API key here',
|
||||||
'API key is stored in settings.env. You can migrate it to a .env file for better security.':
|
'API key is stored in settings.env. You can migrate it to a .env file for better security.':
|
||||||
'API key is stored in settings.env. You can migrate it to a .env file for better security.',
|
'API key is stored in settings.env. You can migrate it to a .env file for better security.',
|
||||||
'New model configurations are available for Bailian Coding Plan. Update now?':
|
'New model configurations are available for Alibaba Cloud Coding Plan. Update now?':
|
||||||
'New model configurations are available for Bailian Coding Plan. Update now?',
|
'New model configurations are available for Alibaba Cloud Coding Plan. Update now?',
|
||||||
'Coding Plan configuration updated successfully. New models are now available.':
|
'Coding Plan configuration updated successfully. New models are now available.':
|
||||||
'Coding Plan configuration updated successfully. New models are now available.',
|
'Coding Plan configuration updated successfully. New models are now available.',
|
||||||
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
||||||
|
|
@ -1461,53 +1482,28 @@ export default {
|
||||||
'Failed to update Coding Plan configuration: {{message}}',
|
'Failed to update Coding Plan configuration: {{message}}',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Custom API-KEY Configuration
|
// Custom API Key Configuration
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'For advanced users who want to configure models manually.':
|
'You can configure your API key and models in settings.json':
|
||||||
'For advanced users who want to configure models manually.',
|
'You can configure your API key and models in settings.json',
|
||||||
'Please configure your models in settings.json:':
|
'Refer to the documentation for setup instructions':
|
||||||
'Please configure your models in settings.json:',
|
'Refer to the documentation for setup instructions',
|
||||||
'Set API key via environment variable (e.g., OPENAI_API_KEY)':
|
|
||||||
'Set API key via environment variable (e.g., OPENAI_API_KEY)',
|
|
||||||
"Add model configuration to modelProviders['openai'] (or other auth types)":
|
|
||||||
"Add model configuration to modelProviders['openai'] (or other auth types)",
|
|
||||||
'Each provider needs: id, envKey (required), plus optional baseUrl, generationConfig':
|
|
||||||
'Each provider needs: id, envKey (required), plus optional baseUrl, generationConfig',
|
|
||||||
'Use /model command to select your preferred model from the configured list':
|
|
||||||
'Use /model command to select your preferred model from the configured list',
|
|
||||||
'Supported auth types: openai, anthropic, gemini, vertex-ai, etc.':
|
|
||||||
'Supported auth types: openai, anthropic, gemini, vertex-ai, etc.',
|
|
||||||
'More instructions please check:': 'More instructions please check:',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Auth Dialog - View Titles and Labels
|
// Auth Dialog - View Titles and Labels
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Coding Plan': 'Coding Plan',
|
'Select Region for Coding Plan': 'Select Region for Coding Plan',
|
||||||
'Coding Plan (Bailian, China)': 'Coding Plan (Bailian, China)',
|
'Choose based on where your account is registered':
|
||||||
'Coding Plan (Bailian, Global/Intl)': 'Coding Plan (Bailian, Global/Intl)',
|
'Choose based on where your account is registered',
|
||||||
"Paste your api key of Bailian Coding Plan and you're all set!":
|
'Enter Coding Plan API Key': 'Enter Coding Plan API Key',
|
||||||
"Paste your api key of Bailian Coding Plan and you're all set!",
|
|
||||||
"Paste your api key of Coding Plan (Bailian, Global/Intl) and you're all set!":
|
|
||||||
"Paste your api key of Coding Plan (Bailian, Global/Intl) and you're all set!",
|
|
||||||
Custom: 'Custom',
|
|
||||||
'More instructions about configuring `modelProviders` manually.':
|
|
||||||
'More instructions about configuring `modelProviders` manually.',
|
|
||||||
'Select API-KEY configuration mode:': 'Select API-KEY configuration mode:',
|
|
||||||
'(Press Escape to go back)': '(Press Escape to go back)',
|
|
||||||
'(Press Enter to submit, Escape to cancel)':
|
|
||||||
'(Press Enter to submit, Escape to cancel)',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan International Updates
|
// Coding Plan International Updates
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'New model configurations are available for {{region}}. Update now?':
|
'New model configurations are available for {{region}}. Update now?':
|
||||||
'New model configurations are available for {{region}}. Update now?',
|
'New model configurations are available for {{region}}. Update now?',
|
||||||
'New model configurations are available for Bailian Coding Plan (China). Update now?':
|
|
||||||
'New model configurations are available for Bailian Coding Plan (China). Update now?',
|
|
||||||
'New model configurations are available for Coding Plan (Bailian, Global/Intl). Update now?':
|
|
||||||
'New model configurations are available for Coding Plan (Bailian, Global/Intl). Update now?',
|
|
||||||
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
||||||
'{{region}} configuration updated successfully. Model switched to "{{model}}".',
|
'{{region}} configuration updated successfully. Model switched to "{{model}}".',
|
||||||
'Authenticated successfully with {{region}}. API key is stored in settings.env.':
|
'Authenticated successfully with {{region}}. API key and model configs saved to settings.json (backed up).':
|
||||||
'Authenticated successfully with {{region}}. API key is stored in settings.env.',
|
'Authenticated successfully with {{region}}. API key and model configs saved to settings.json (backed up).',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ export default {
|
||||||
'Enter to confirm, Esc to cancel': 'Enter で確定、Esc でキャンセル',
|
'Enter to confirm, Esc to cancel': 'Enter で確定、Esc でキャンセル',
|
||||||
'Enter to select, ↑↓ to navigate, Esc to go back':
|
'Enter to select, ↑↓ to navigate, Esc to go back':
|
||||||
'Enter で選択、↑↓ で移動、Esc で戻る',
|
'Enter で選択、↑↓ で移動、Esc で戻る',
|
||||||
|
'Enter to submit, Esc to go back': 'Enter で送信、Esc で戻る',
|
||||||
'Invalid step: {{step}}': '無効なステップ: {{step}}',
|
'Invalid step: {{step}}': '無効なステップ: {{step}}',
|
||||||
'No subagents found.': 'サブエージェントが見つかりません',
|
'No subagents found.': 'サブエージェントが見つかりません',
|
||||||
"Use '/agents create' to create your first subagent.":
|
"Use '/agents create' to create your first subagent.":
|
||||||
|
|
@ -648,7 +649,6 @@ export default {
|
||||||
'missing name': '名前なし',
|
'missing name': '名前なし',
|
||||||
'missing description': '説明なし',
|
'missing description': '説明なし',
|
||||||
'(unnamed)': '(名前なし)',
|
'(unnamed)': '(名前なし)',
|
||||||
unknown: '不明',
|
|
||||||
'Warning: This tool cannot be called by the LLM':
|
'Warning: This tool cannot be called by the LLM':
|
||||||
'警告: このツールはLLMによって呼び出すことができません',
|
'警告: このツールはLLMによって呼び出すことができません',
|
||||||
Reason: '理由',
|
Reason: '理由',
|
||||||
|
|
@ -701,18 +701,21 @@ export default {
|
||||||
'🎯 Overall Goal:': '🎯 全体目標:',
|
'🎯 Overall Goal:': '🎯 全体目標:',
|
||||||
// Dialogs - Auth
|
// Dialogs - Auth
|
||||||
'Get started': '始める',
|
'Get started': '始める',
|
||||||
'How would you like to authenticate for this project?':
|
'Select Authentication Method': '認証方法を選択',
|
||||||
'このプロジェクトの認証方法を選択してください:',
|
|
||||||
'OpenAI API key is required to use OpenAI authentication.':
|
'OpenAI API key is required to use OpenAI authentication.':
|
||||||
'OpenAI認証を使用するには OpenAI APIキーが必要です',
|
'OpenAI認証を使用するには OpenAI APIキーが必要です',
|
||||||
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
||||||
'続行するには認証方法を選択してください。Ctrl+C をもう一度押すと終了します',
|
'続行するには認証方法を選択してください。Ctrl+C をもう一度押すと終了します',
|
||||||
'(Use Enter to Set Auth)': '(Enter で認証を設定)',
|
'Terms of Services and Privacy Notice': '利用規約とプライバシー通知',
|
||||||
'Terms of Services and Privacy Notice for Qwen Code':
|
|
||||||
'Qwen Code の利用規約とプライバシー通知',
|
|
||||||
'Qwen OAuth': 'Qwen OAuth',
|
'Qwen OAuth': 'Qwen OAuth',
|
||||||
|
'Free \u00B7 Up to 1,000 requests/day \u00B7 Qwen latest models':
|
||||||
|
'無料 \u00B7 1日最大1,000リクエスト \u00B7 Qwen最新モデル',
|
||||||
'Login with QwenChat account to use daily free quota.':
|
'Login with QwenChat account to use daily free quota.':
|
||||||
'QwenChatアカウントでログインして、毎日の無料クォータをご利用ください。',
|
'QwenChatアカウントでログインして、毎日の無料クォータをご利用ください。',
|
||||||
|
'Paid \u00B7 Up to 6,000 requests/5 hrs \u00B7 All Alibaba Cloud Coding Plan Models':
|
||||||
|
'有料 \u00B7 5時間最大6,000リクエスト \u00B7 すべての Alibaba Cloud Coding Plan モデル',
|
||||||
|
'Alibaba Cloud Coding Plan': 'Alibaba Cloud Coding Plan',
|
||||||
|
'Bring your own API key': '自分のAPIキーを使用',
|
||||||
'API-KEY': 'API-KEY',
|
'API-KEY': 'API-KEY',
|
||||||
'Use coding plan credentials or your own api-keys/providers.':
|
'Use coding plan credentials or your own api-keys/providers.':
|
||||||
'Coding Planの認証情報またはご自身のAPIキー/プロバイダーをご利用ください。',
|
'Coding Planの認証情報またはご自身のAPIキー/プロバイダーをご利用ください。',
|
||||||
|
|
@ -740,6 +743,8 @@ export default {
|
||||||
'Waiting for Qwen OAuth authentication...': 'Qwen OAuth認証を待っています...',
|
'Waiting for Qwen OAuth authentication...': 'Qwen OAuth認証を待っています...',
|
||||||
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
||||||
'注: Qwen OAuthを使用しても、settings.json内の既存のAPIキーはクリアされません。必要に応じて後でOpenAI認証に切り替えることができます',
|
'注: Qwen OAuthを使用しても、settings.json内の既存のAPIキーはクリアされません。必要に応じて後でOpenAI認証に切り替えることができます',
|
||||||
|
'Note: Your existing API key will not be cleared when using Qwen OAuth.':
|
||||||
|
'注: Qwen OAuthを使用しても、既存のAPIキーはクリアされません。',
|
||||||
'Authentication timed out. Please try again.':
|
'Authentication timed out. Please try again.':
|
||||||
'認証がタイムアウトしました。再度お試しください',
|
'認証がタイムアウトしました。再度お試しください',
|
||||||
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
||||||
|
|
@ -761,6 +766,17 @@ export default {
|
||||||
// Dialogs - Model
|
// Dialogs - Model
|
||||||
'Select Model': 'モデルを選択',
|
'Select Model': 'モデルを選択',
|
||||||
'(Press Esc to close)': '(Esc で閉じる)',
|
'(Press Esc to close)': '(Esc で閉じる)',
|
||||||
|
Modality: 'モダリティ',
|
||||||
|
'Context Window': 'コンテキストウィンドウ',
|
||||||
|
text: 'テキスト',
|
||||||
|
'text-only': 'テキストのみ',
|
||||||
|
image: '画像',
|
||||||
|
pdf: 'PDF',
|
||||||
|
audio: '音声',
|
||||||
|
video: '動画',
|
||||||
|
'not set': '未設定',
|
||||||
|
none: 'なし',
|
||||||
|
unknown: '不明',
|
||||||
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
||||||
'Qwen 3.5 Plus — 効率的なハイブリッドモデル、業界トップクラスのコーディング性能',
|
'Qwen 3.5 Plus — 効率的なハイブリッドモデル、業界トップクラスのコーディング性能',
|
||||||
'The latest Qwen Vision model from Alibaba Cloud ModelStudio (version: qwen3-vl-plus-2025-09-23)':
|
'The latest Qwen Vision model from Alibaba Cloud ModelStudio (version: qwen3-vl-plus-2025-09-23)':
|
||||||
|
|
@ -813,6 +829,27 @@ export default {
|
||||||
"Starting OAuth authentication for MCP server '{{name}}'...":
|
"Starting OAuth authentication for MCP server '{{name}}'...":
|
||||||
"MCPサーバー '{{name}}' のOAuth認証を開始中...",
|
"MCPサーバー '{{name}}' のOAuth認証を開始中...",
|
||||||
// Startup Tips
|
// Startup Tips
|
||||||
|
'Tips:': 'ヒント:',
|
||||||
|
'Use /compress when the conversation gets long to summarize history and free up context.':
|
||||||
|
'会話が長くなったら /compress で履歴を要約し、コンテキストを解放できます。',
|
||||||
|
'Start a fresh idea with /clear or /new; the previous session stays available in history.':
|
||||||
|
'/clear または /new で新しいアイデアを始められます。前のセッションは履歴に残ります。',
|
||||||
|
'Use /bug to submit issues to the maintainers when something goes off.':
|
||||||
|
'問題が発生したら /bug でメンテナーに報告できます。',
|
||||||
|
'Switch auth type quickly with /auth.':
|
||||||
|
'/auth で認証タイプをすばやく切り替えられます。',
|
||||||
|
'You can run any shell commands from Qwen Code using ! (e.g. !ls).':
|
||||||
|
'Qwen Code から ! を使って任意のシェルコマンドを実行できます(例: !ls)。',
|
||||||
|
'Type / to open the command popup; Tab autocompletes slash commands and saved prompts.':
|
||||||
|
'/ を入力してコマンドポップアップを開きます。Tab でスラッシュコマンドと保存済みプロンプトを補完できます。',
|
||||||
|
'You can resume a previous conversation by running qwen --continue or qwen --resume.':
|
||||||
|
'qwen --continue または qwen --resume で前の会話を再開できます。',
|
||||||
|
'You can switch permission mode quickly with Shift+Tab or /approval-mode.':
|
||||||
|
'Shift+Tab または /approval-mode で権限モードをすばやく切り替えられます。',
|
||||||
|
'You can switch permission mode quickly with Tab or /approval-mode.':
|
||||||
|
'Tab または /approval-mode で権限モードをすばやく切り替えられます。',
|
||||||
|
'Try /insight to generate personalized insights from your chat history.':
|
||||||
|
'/insight でチャット履歴からパーソナライズされたインサイトを生成できます。',
|
||||||
'Tips for getting started:': '始めるためのヒント:',
|
'Tips for getting started:': '始めるためのヒント:',
|
||||||
'1. Ask questions, edit files, or run commands.':
|
'1. Ask questions, edit files, or run commands.':
|
||||||
'1. 質問したり、ファイルを編集したり、コマンドを実行したりできます',
|
'1. 質問したり、ファイルを編集したり、コマンドを実行したりできます',
|
||||||
|
|
@ -921,32 +958,19 @@ export default {
|
||||||
],
|
],
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Custom API-KEY Configuration
|
// Custom API Key Configuration
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'For advanced users who want to configure models manually.':
|
'You can configure your API key and models in settings.json':
|
||||||
'モデルを手動で設定したい上級ユーザー向け。',
|
'settings.json で API キーとモデルを設定できます',
|
||||||
'Please configure your models in settings.json:':
|
'Refer to the documentation for setup instructions':
|
||||||
'settings.json でモデルを設定してください:',
|
'セットアップ手順はドキュメントを参照してください',
|
||||||
'Set API key via environment variable (e.g., OPENAI_API_KEY)':
|
|
||||||
'環境変数を使用して API キーを設定してください(例:OPENAI_API_KEY)',
|
|
||||||
"Add model configuration to modelProviders['openai'] (or other auth types)":
|
|
||||||
"modelProviders['openai'](または他の認証タイプ)にモデル設定を追加してください",
|
|
||||||
'Each provider needs: id, envKey (required), plus optional baseUrl, generationConfig':
|
|
||||||
'各プロバイダーには:id、envKey(必須)、およびオプションの baseUrl、generationConfig が必要です',
|
|
||||||
'Use /model command to select your preferred model from the configured list':
|
|
||||||
'/model コマンドを使用して、設定済みリストからお好みのモデルを選択してください',
|
|
||||||
'Supported auth types: openai, anthropic, gemini, vertex-ai, etc.':
|
|
||||||
'サポートされている認証タイプ:openai、anthropic、gemini、vertex-ai など',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan Authentication
|
// Coding Plan Authentication
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Please enter your API key:': 'APIキーを入力してください:',
|
|
||||||
'API key cannot be empty.': 'APIキーは空にできません。',
|
'API key cannot be empty.': 'APIキーは空にできません。',
|
||||||
'You can get your exclusive Coding Plan API-KEY here:':
|
'You can get your Coding Plan API key here':
|
||||||
'Coding Plan の API-KEY はこちらで取得できます:',
|
'Coding Plan APIキーはこちらで取得できます',
|
||||||
'New model configurations are available for Bailian Coding Plan. Update now?':
|
|
||||||
'Bailian Coding Plan の新しいモデル設定が利用可能です。今すぐ更新しますか?',
|
|
||||||
'Coding Plan configuration updated successfully. New models are now available.':
|
'Coding Plan configuration updated successfully. New models are now available.':
|
||||||
'Coding Plan の設定が正常に更新されました。新しいモデルが利用可能になりました。',
|
'Coding Plan の設定が正常に更新されました。新しいモデルが利用可能になりました。',
|
||||||
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
||||||
|
|
@ -957,34 +981,18 @@ export default {
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Auth Dialog - View Titles and Labels
|
// Auth Dialog - View Titles and Labels
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Coding Plan': 'Coding Plan',
|
'Select Region for Coding Plan': 'Coding Planのリージョンを選択',
|
||||||
'Coding Plan (Bailian, China)': 'Coding Plan (Bailian, 中国)',
|
'Choose based on where your account is registered':
|
||||||
'Coding Plan (Bailian, Global/Intl)':
|
'アカウントの登録先に応じて選択してください',
|
||||||
'Coding Plan (Bailian, グローバル/国際)',
|
'Enter Coding Plan API Key': 'Coding Plan APIキーを入力',
|
||||||
"Paste your api key of Bailian Coding Plan and you're all set!":
|
|
||||||
'Bailian Coding PlanのAPIキーを貼り付けるだけで準備完了です!',
|
|
||||||
"Paste your api key of Coding Plan (Bailian, Global/Intl) and you're all set!":
|
|
||||||
'Coding Plan (Bailian, グローバル/国際) のAPIキーを貼り付けるだけで準備完了です!',
|
|
||||||
Custom: 'カスタム',
|
|
||||||
'More instructions about configuring `modelProviders` manually.':
|
|
||||||
'`modelProviders`を手動で設定する方法の詳細はこちら。',
|
|
||||||
'Select API-KEY configuration mode:': 'API-KEY設定モードを選択してください:',
|
|
||||||
'(Press Escape to go back)': '(Escapeキーで戻る)',
|
|
||||||
'(Press Enter to submit, Escape to cancel)':
|
|
||||||
'(Enterで送信、Escapeでキャンセル)',
|
|
||||||
'More instructions please check:': '詳細な手順はこちらをご確認ください:',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan International Updates
|
// Coding Plan International Updates
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'New model configurations are available for {{region}}. Update now?':
|
'New model configurations are available for {{region}}. Update now?':
|
||||||
'{{region}} の新しいモデル設定が利用可能です。今すぐ更新しますか?',
|
'{{region}} の新しいモデル設定が利用可能です。今すぐ更新しますか?',
|
||||||
'New model configurations are available for Bailian Coding Plan (China). Update now?':
|
|
||||||
'Bailian Coding Plan (中国) の新しいモデル設定が利用可能です。今すぐ更新しますか?',
|
|
||||||
'New model configurations are available for Coding Plan (Bailian, Global/Intl). Update now?':
|
|
||||||
'Coding Plan (Bailian, グローバル/国際) の新しいモデル設定が利用可能です。今すぐ更新しますか?',
|
|
||||||
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
||||||
'{{region}} の設定が正常に更新されました。モデルが "{{model}}" に切り替わりました。',
|
'{{region}} の設定が正常に更新されました。モデルが "{{model}}" に切り替わりました。',
|
||||||
'Authenticated successfully with {{region}}. API key is stored in settings.env.':
|
'Authenticated successfully with {{region}}. API key and model configs saved to settings.json (backed up).':
|
||||||
'{{region}} での認証に成功しました。APIキーは settings.env に保存されています。',
|
'{{region}} での認証に成功しました。APIキーとモデル設定が settings.json に保存されました(バックアップ済み)。',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@ export default {
|
||||||
'Enter to confirm, Esc to cancel': 'Enter para confirmar, Esc para cancelar',
|
'Enter to confirm, Esc to cancel': 'Enter para confirmar, Esc para cancelar',
|
||||||
'Enter to select, ↑↓ to navigate, Esc to go back':
|
'Enter to select, ↑↓ to navigate, Esc to go back':
|
||||||
'Enter para selecionar, ↑↓ para navegar, Esc para voltar',
|
'Enter para selecionar, ↑↓ para navegar, Esc para voltar',
|
||||||
|
'Enter to submit, Esc to go back': 'Enter para enviar, Esc para voltar',
|
||||||
'Invalid step: {{step}}': 'Etapa inválida: {{step}}',
|
'Invalid step: {{step}}': 'Etapa inválida: {{step}}',
|
||||||
'No subagents found.': 'Nenhum subagente encontrado.',
|
'No subagents found.': 'Nenhum subagente encontrado.',
|
||||||
"Use '/agents create' to create your first subagent.":
|
"Use '/agents create' to create your first subagent.":
|
||||||
|
|
@ -914,7 +915,6 @@ export default {
|
||||||
'missing name': 'nome ausente',
|
'missing name': 'nome ausente',
|
||||||
'missing description': 'descrição ausente',
|
'missing description': 'descrição ausente',
|
||||||
'(unnamed)': '(sem nome)',
|
'(unnamed)': '(sem nome)',
|
||||||
unknown: 'desconhecido',
|
|
||||||
'Warning: This tool cannot be called by the LLM':
|
'Warning: This tool cannot be called by the LLM':
|
||||||
'Aviso: Esta ferramenta não pode ser chamada pelo LLM',
|
'Aviso: Esta ferramenta não pode ser chamada pelo LLM',
|
||||||
Reason: 'Motivo',
|
Reason: 'Motivo',
|
||||||
|
|
@ -980,18 +980,22 @@ export default {
|
||||||
// Dialogs - Auth
|
// Dialogs - Auth
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Get started': 'Começar',
|
'Get started': 'Começar',
|
||||||
'How would you like to authenticate for this project?':
|
'Select Authentication Method': 'Selecionar Método de Autenticação',
|
||||||
'Como você gostaria de se autenticar para este projeto?',
|
|
||||||
'OpenAI API key is required to use OpenAI authentication.':
|
'OpenAI API key is required to use OpenAI authentication.':
|
||||||
'A chave da API do OpenAI é necessária para usar a autenticação do OpenAI.',
|
'A chave da API do OpenAI é necessária para usar a autenticação do OpenAI.',
|
||||||
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
||||||
'Você deve selecionar um método de autenticação para prosseguir. Pressione Ctrl+C novamente para sair.',
|
'Você deve selecionar um método de autenticação para prosseguir. Pressione Ctrl+C novamente para sair.',
|
||||||
'(Use Enter to Set Auth)': '(Use Enter para Definir Autenticação)',
|
'Terms of Services and Privacy Notice':
|
||||||
'Terms of Services and Privacy Notice for Qwen Code':
|
'Termos de Serviço e Aviso de Privacidade',
|
||||||
'Termos de Serviço e Aviso de Privacidade do Qwen Code',
|
|
||||||
'Qwen OAuth': 'Qwen OAuth',
|
'Qwen OAuth': 'Qwen OAuth',
|
||||||
|
'Free \u00B7 Up to 1,000 requests/day \u00B7 Qwen latest models':
|
||||||
|
'Gratuito \u00B7 Até 1.000 solicitações/dia \u00B7 Modelos Qwen mais recentes',
|
||||||
'Login with QwenChat account to use daily free quota.':
|
'Login with QwenChat account to use daily free quota.':
|
||||||
'Faça login com sua conta QwenChat para usar a cota gratuita diária.',
|
'Faça login com sua conta QwenChat para usar a cota gratuita diária.',
|
||||||
|
'Paid \u00B7 Up to 6,000 requests/5 hrs \u00B7 All Alibaba Cloud Coding Plan Models':
|
||||||
|
'Pago \u00B7 Até 6.000 solicitações/5 hrs \u00B7 Todos os modelos Alibaba Cloud Coding Plan',
|
||||||
|
'Alibaba Cloud Coding Plan': 'Alibaba Cloud Coding Plan',
|
||||||
|
'Bring your own API key': 'Traga sua própria chave API',
|
||||||
'API-KEY': 'API-KEY',
|
'API-KEY': 'API-KEY',
|
||||||
'Use coding plan credentials or your own api-keys/providers.':
|
'Use coding plan credentials or your own api-keys/providers.':
|
||||||
'Use credenciais do Coding Plan ou suas próprias chaves API/provedores.',
|
'Use credenciais do Coding Plan ou suas próprias chaves API/provedores.',
|
||||||
|
|
@ -1019,6 +1023,8 @@ export default {
|
||||||
'Aguardando autenticação Qwen OAuth...',
|
'Aguardando autenticação Qwen OAuth...',
|
||||||
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
||||||
'Nota: Sua chave de API existente no settings.json não será limpa ao usar o Qwen OAuth. Você pode voltar para a autenticação do OpenAI mais tarde, se necessário.',
|
'Nota: Sua chave de API existente no settings.json não será limpa ao usar o Qwen OAuth. Você pode voltar para a autenticação do OpenAI mais tarde, se necessário.',
|
||||||
|
'Note: Your existing API key will not be cleared when using Qwen OAuth.':
|
||||||
|
'Nota: Sua chave de API existente não será limpa ao usar o Qwen OAuth.',
|
||||||
'Authentication timed out. Please try again.':
|
'Authentication timed out. Please try again.':
|
||||||
'A autenticação expirou. Tente novamente.',
|
'A autenticação expirou. Tente novamente.',
|
||||||
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
||||||
|
|
@ -1067,6 +1073,17 @@ export default {
|
||||||
'(default)': '(padrão)',
|
'(default)': '(padrão)',
|
||||||
'(set)': '(definido)',
|
'(set)': '(definido)',
|
||||||
'(not set)': '(não definido)',
|
'(not set)': '(não definido)',
|
||||||
|
Modality: 'Modalidade',
|
||||||
|
'Context Window': 'Janela de Contexto',
|
||||||
|
text: 'texto',
|
||||||
|
'text-only': 'somente texto',
|
||||||
|
image: 'imagem',
|
||||||
|
pdf: 'PDF',
|
||||||
|
audio: 'áudio',
|
||||||
|
video: 'vídeo',
|
||||||
|
'not set': 'não definido',
|
||||||
|
none: 'nenhum',
|
||||||
|
unknown: 'desconhecido',
|
||||||
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
||||||
"Falha ao trocar o modelo para '{{modelId}}'.\n\n{{error}}",
|
"Falha ao trocar o modelo para '{{modelId}}'.\n\n{{error}}",
|
||||||
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
||||||
|
|
@ -1162,6 +1179,8 @@ export default {
|
||||||
'Você pode retomar uma conversa anterior executando qwen --continue ou qwen --resume.',
|
'Você pode retomar uma conversa anterior executando qwen --continue ou qwen --resume.',
|
||||||
'You can switch permission mode quickly with Shift+Tab or /approval-mode.':
|
'You can switch permission mode quickly with Shift+Tab or /approval-mode.':
|
||||||
'Você pode alternar o modo de permissão rapidamente com Shift+Tab ou /approval-mode.',
|
'Você pode alternar o modo de permissão rapidamente com Shift+Tab ou /approval-mode.',
|
||||||
|
'Try /insight to generate personalized insights from your chat history.':
|
||||||
|
'Experimente /insight para gerar insights personalizados do seu histórico de conversas.',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Exit Screen / Stats
|
// Exit Screen / Stats
|
||||||
|
|
@ -1424,32 +1443,21 @@ export default {
|
||||||
'Falha ao abrir o navegador. Confira a galeria de extensões em {{url}}',
|
'Falha ao abrir o navegador. Confira a galeria de extensões em {{url}}',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Custom API-KEY Configuration
|
// Custom API Key Configuration
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'For advanced users who want to configure models manually.':
|
'You can configure your API key and models in settings.json':
|
||||||
'Para usuários avançados que desejam configurar modelos manualmente.',
|
'Você pode configurar sua chave de API e modelos em settings.json',
|
||||||
'Please configure your models in settings.json:':
|
'Refer to the documentation for setup instructions':
|
||||||
'Por favor, configure seus modelos em settings.json:',
|
'Consulte a documentação para instruções de configuração',
|
||||||
'Set API key via environment variable (e.g., OPENAI_API_KEY)':
|
|
||||||
'Defina a chave de API via variável de ambiente (ex: OPENAI_API_KEY)',
|
|
||||||
"Add model configuration to modelProviders['openai'] (or other auth types)":
|
|
||||||
"Adicione a configuração do modelo a modelProviders['openai'] (ou outros tipos de autenticação)",
|
|
||||||
'Each provider needs: id, envKey (required), plus optional baseUrl, generationConfig':
|
|
||||||
'Cada provedor precisa de: id, envKey (obrigatório), além de baseUrl e generationConfig opcionais',
|
|
||||||
'Use /model command to select your preferred model from the configured list':
|
|
||||||
'Use o comando /model para selecionar seu modelo preferido da lista configurada',
|
|
||||||
'Supported auth types: openai, anthropic, gemini, vertex-ai, etc.':
|
|
||||||
'Tipos de autenticação suportados: openai, anthropic, gemini, vertex-ai, etc.',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan Authentication
|
// Coding Plan Authentication
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Please enter your API key:': 'Por favor, digite sua chave de API:',
|
|
||||||
'API key cannot be empty.': 'A chave de API não pode estar vazia.',
|
'API key cannot be empty.': 'A chave de API não pode estar vazia.',
|
||||||
'You can get your exclusive Coding Plan API-KEY here:':
|
'You can get your Coding Plan API key here':
|
||||||
'Você pode obter sua chave de API exclusiva do Coding Plan aqui:',
|
'Você pode obter sua chave de API do Coding Plan aqui',
|
||||||
'New model configurations are available for Bailian Coding Plan. Update now?':
|
'New model configurations are available for Alibaba Cloud Coding Plan. Update now?':
|
||||||
'Novas configurações de modelo estão disponíveis para o Bailian Coding Plan. Atualizar agora?',
|
'Novas configurações de modelo estão disponíveis para o Alibaba Cloud Coding Plan. Atualizar agora?',
|
||||||
'Coding Plan configuration updated successfully. New models are now available.':
|
'Coding Plan configuration updated successfully. New models are now available.':
|
||||||
'Configuração do Coding Plan atualizada com sucesso. Novos modelos agora estão disponíveis.',
|
'Configuração do Coding Plan atualizada com sucesso. Novos modelos agora estão disponíveis.',
|
||||||
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
||||||
|
|
@ -1460,34 +1468,18 @@ export default {
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Auth Dialog - View Titles and Labels
|
// Auth Dialog - View Titles and Labels
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Coding Plan': 'Coding Plan',
|
'Select Region for Coding Plan': 'Selecionar região do Coding Plan',
|
||||||
'Coding Plan (Bailian, China)': 'Coding Plan (Bailian, China)',
|
'Choose based on where your account is registered':
|
||||||
'Coding Plan (Bailian, Global/Intl)': 'Coding Plan (Bailian, Global/Intl)',
|
'Escolha com base em onde sua conta está registrada',
|
||||||
"Paste your api key of Bailian Coding Plan and you're all set!":
|
'Enter Coding Plan API Key': 'Inserir chave de API do Coding Plan',
|
||||||
'Cole sua chave de API do Bailian Coding Plan e pronto!',
|
|
||||||
"Paste your api key of Coding Plan (Bailian, Global/Intl) and you're all set!":
|
|
||||||
'Cole sua chave de API do Coding Plan (Bailian, Global/Intl) e pronto!',
|
|
||||||
Custom: 'Personalizado',
|
|
||||||
'More instructions about configuring `modelProviders` manually.':
|
|
||||||
'Mais instruções sobre como configurar `modelProviders` manualmente.',
|
|
||||||
'Select API-KEY configuration mode:':
|
|
||||||
'Selecione o modo de configuração da API-KEY:',
|
|
||||||
'(Press Escape to go back)': '(Pressione Escape para voltar)',
|
|
||||||
'(Press Enter to submit, Escape to cancel)':
|
|
||||||
'(Pressione Enter para enviar, Escape para cancelar)',
|
|
||||||
'More instructions please check:': 'Mais instruções, consulte:',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan International Updates
|
// Coding Plan International Updates
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'New model configurations are available for {{region}}. Update now?':
|
'New model configurations are available for {{region}}. Update now?':
|
||||||
'Novas configurações de modelo estão disponíveis para o {{region}}. Atualizar agora?',
|
'Novas configurações de modelo estão disponíveis para o {{region}}. Atualizar agora?',
|
||||||
'New model configurations are available for Bailian Coding Plan (China). Update now?':
|
|
||||||
'Novas configurações de modelo estão disponíveis para o Bailian Coding Plan (China). Atualizar agora?',
|
|
||||||
'New model configurations are available for Coding Plan (Bailian, Global/Intl). Update now?':
|
|
||||||
'Novas configurações de modelo estão disponíveis para o Coding Plan (Bailian, Global/Intl). Atualizar agora?',
|
|
||||||
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
||||||
'Configuração do {{region}} atualizada com sucesso. Modelo alterado para "{{model}}".',
|
'Configuração do {{region}} atualizada com sucesso. Modelo alterado para "{{model}}".',
|
||||||
'Authenticated successfully with {{region}}. API key is stored in settings.env.':
|
'Authenticated successfully with {{region}}. API key and model configs saved to settings.json (backed up).':
|
||||||
'Autenticado com sucesso com {{region}}. A chave de API está armazenada em settings.env.',
|
'Autenticado com sucesso com {{region}}. Chave de API e configurações de modelo salvas em settings.json (com backup).',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ export default {
|
||||||
'Enter to confirm, Esc to cancel': 'Enter для подтверждения, Esc для отмены',
|
'Enter to confirm, Esc to cancel': 'Enter для подтверждения, Esc для отмены',
|
||||||
'Enter to select, ↑↓ to navigate, Esc to go back':
|
'Enter to select, ↑↓ to navigate, Esc to go back':
|
||||||
'Enter для выбора, ↑↓ для навигации, Esc для возврата',
|
'Enter для выбора, ↑↓ для навигации, Esc для возврата',
|
||||||
|
'Enter to submit, Esc to go back': 'Enter для отправки, Esc для возврата',
|
||||||
'Invalid step: {{step}}': 'Неверный шаг: {{step}}',
|
'Invalid step: {{step}}': 'Неверный шаг: {{step}}',
|
||||||
'No subagents found.': 'Подагенты не найдены.',
|
'No subagents found.': 'Подагенты не найдены.',
|
||||||
"Use '/agents create' to create your first subagent.":
|
"Use '/agents create' to create your first subagent.":
|
||||||
|
|
@ -915,7 +916,6 @@ export default {
|
||||||
'missing name': 'отсутствует имя',
|
'missing name': 'отсутствует имя',
|
||||||
'missing description': 'отсутствует описание',
|
'missing description': 'отсутствует описание',
|
||||||
'(unnamed)': '(без имени)',
|
'(unnamed)': '(без имени)',
|
||||||
unknown: 'неизвестно',
|
|
||||||
'Warning: This tool cannot be called by the LLM':
|
'Warning: This tool cannot be called by the LLM':
|
||||||
'Предупреждение: Этот инструмент не может быть вызван LLM',
|
'Предупреждение: Этот инструмент не может быть вызван LLM',
|
||||||
Reason: 'Причина',
|
Reason: 'Причина',
|
||||||
|
|
@ -980,18 +980,22 @@ export default {
|
||||||
// Диалоги - Авторизация
|
// Диалоги - Авторизация
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Get started': 'Начать',
|
'Get started': 'Начать',
|
||||||
'How would you like to authenticate for this project?':
|
'Select Authentication Method': 'Выберите метод авторизации',
|
||||||
'Как вы хотите авторизоваться для этого проекта?',
|
|
||||||
'OpenAI API key is required to use OpenAI authentication.':
|
'OpenAI API key is required to use OpenAI authentication.':
|
||||||
'Для использования авторизации OpenAI требуется ключ API OpenAI.',
|
'Для использования авторизации OpenAI требуется ключ API OpenAI.',
|
||||||
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
||||||
'Вы должны выбрать метод авторизации для продолжения. Нажмите Ctrl+C снова для выхода.',
|
'Вы должны выбрать метод авторизации для продолжения. Нажмите Ctrl+C снова для выхода.',
|
||||||
'(Use Enter to Set Auth)': '(Enter для установки авторизации)',
|
'Terms of Services and Privacy Notice':
|
||||||
'Terms of Services and Privacy Notice for Qwen Code':
|
'Условия обслуживания и уведомление о конфиденциальности',
|
||||||
'Условия обслуживания и уведомление о конфиденциальности для Qwen Code',
|
|
||||||
'Qwen OAuth': 'Qwen OAuth',
|
'Qwen OAuth': 'Qwen OAuth',
|
||||||
|
'Free \u00B7 Up to 1,000 requests/day \u00B7 Qwen latest models':
|
||||||
|
'Бесплатно \u00B7 До 1 000 запросов/день \u00B7 Новейшие модели Qwen',
|
||||||
'Login with QwenChat account to use daily free quota.':
|
'Login with QwenChat account to use daily free quota.':
|
||||||
'Войдите с помощью аккаунта QwenChat, чтобы использовать ежедневную бесплатную квоту.',
|
'Войдите с помощью аккаунта QwenChat, чтобы использовать ежедневную бесплатную квоту.',
|
||||||
|
'Paid \u00B7 Up to 6,000 requests/5 hrs \u00B7 All Alibaba Cloud Coding Plan Models':
|
||||||
|
'Платно \u00B7 До 6 000 запросов/5 часов \u00B7 Все модели Alibaba Cloud Coding Plan',
|
||||||
|
'Alibaba Cloud Coding Plan': 'Alibaba Cloud Coding Plan',
|
||||||
|
'Bring your own API key': 'Используйте свой API-ключ',
|
||||||
'API-KEY': 'API-KEY',
|
'API-KEY': 'API-KEY',
|
||||||
'Use coding plan credentials or your own api-keys/providers.':
|
'Use coding plan credentials or your own api-keys/providers.':
|
||||||
'Используйте учетные данные Coding Plan или свои собственные API-ключи/провайдеры.',
|
'Используйте учетные данные Coding Plan или свои собственные API-ключи/провайдеры.',
|
||||||
|
|
@ -1019,6 +1023,8 @@ export default {
|
||||||
'Ожидание авторизации Qwen OAuth...',
|
'Ожидание авторизации Qwen OAuth...',
|
||||||
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
||||||
'Примечание: Ваш существующий ключ API в settings.json не будет удален при использовании Qwen OAuth. Вы можете переключиться обратно на авторизацию OpenAI позже при необходимости.',
|
'Примечание: Ваш существующий ключ API в settings.json не будет удален при использовании Qwen OAuth. Вы можете переключиться обратно на авторизацию OpenAI позже при необходимости.',
|
||||||
|
'Note: Your existing API key will not be cleared when using Qwen OAuth.':
|
||||||
|
'Примечание: Ваш существующий ключ API не будет удален при использовании Qwen OAuth.',
|
||||||
'Authentication timed out. Please try again.':
|
'Authentication timed out. Please try again.':
|
||||||
'Время ожидания авторизации истекло. Пожалуйста, попробуйте снова.',
|
'Время ожидания авторизации истекло. Пожалуйста, попробуйте снова.',
|
||||||
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
||||||
|
|
@ -1066,6 +1072,17 @@ export default {
|
||||||
'(default)': '(по умолчанию)',
|
'(default)': '(по умолчанию)',
|
||||||
'(set)': '(установлено)',
|
'(set)': '(установлено)',
|
||||||
'(not set)': '(не задано)',
|
'(not set)': '(не задано)',
|
||||||
|
Modality: 'Модальность',
|
||||||
|
'Context Window': 'Контекстное окно',
|
||||||
|
text: 'текст',
|
||||||
|
'text-only': 'только текст',
|
||||||
|
image: 'изображение',
|
||||||
|
pdf: 'PDF',
|
||||||
|
audio: 'аудио',
|
||||||
|
video: 'видео',
|
||||||
|
'not set': 'не задано',
|
||||||
|
none: 'нет',
|
||||||
|
unknown: 'неизвестно',
|
||||||
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
||||||
"Не удалось переключиться на модель '{{modelId}}'.\n\n{{error}}",
|
"Не удалось переключиться на модель '{{modelId}}'.\n\n{{error}}",
|
||||||
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
||||||
|
|
@ -1414,38 +1431,43 @@ export default {
|
||||||
'Открываем страницу расширений в браузере: {{url}}',
|
'Открываем страницу расширений в браузере: {{url}}',
|
||||||
'Failed to open browser. Check out the extensions gallery at {{url}}':
|
'Failed to open browser. Check out the extensions gallery at {{url}}':
|
||||||
'Не удалось открыть браузер. Посетите галерею расширений по адресу {{url}}',
|
'Не удалось открыть браузер. Посетите галерею расширений по адресу {{url}}',
|
||||||
|
'Use /compress when the conversation gets long to summarize history and free up context.':
|
||||||
|
'Используйте /compress, когда разговор становится длинным, чтобы подвести итог и освободить контекст.',
|
||||||
|
'Start a fresh idea with /clear or /new; the previous session stays available in history.':
|
||||||
|
'Начните новую идею с /clear или /new; предыдущая сессия останется в истории.',
|
||||||
|
'Use /bug to submit issues to the maintainers when something goes off.':
|
||||||
|
'Используйте /bug, чтобы сообщить о проблемах разработчикам.',
|
||||||
|
'Switch auth type quickly with /auth.':
|
||||||
|
'Быстро переключите тип аутентификации с помощью /auth.',
|
||||||
|
'You can run any shell commands from Qwen Code using ! (e.g. !ls).':
|
||||||
|
'Вы можете выполнять любые shell-команды в Qwen Code с помощью ! (например, !ls).',
|
||||||
|
'Type / to open the command popup; Tab autocompletes slash commands and saved prompts.':
|
||||||
|
'Введите /, чтобы открыть меню команд; Tab автодополняет слэш-команды и сохранённые промпты.',
|
||||||
|
'You can resume a previous conversation by running qwen --continue or qwen --resume.':
|
||||||
|
'Вы можете продолжить предыдущий разговор, запустив qwen --continue или qwen --resume.',
|
||||||
'You can switch permission mode quickly with Shift+Tab or /approval-mode.':
|
'You can switch permission mode quickly with Shift+Tab or /approval-mode.':
|
||||||
'Вы можете быстро переключать режим разрешений с помощью Shift+Tab или /approval-mode.',
|
'Вы можете быстро переключать режим разрешений с помощью Shift+Tab или /approval-mode.',
|
||||||
'You can switch permission mode quickly with Tab or /approval-mode.':
|
'You can switch permission mode quickly with Tab or /approval-mode.':
|
||||||
'Вы можете быстро переключать режим разрешений с помощью Tab или /approval-mode.',
|
'Вы можете быстро переключать режим разрешений с помощью Tab или /approval-mode.',
|
||||||
|
'Try /insight to generate personalized insights from your chat history.':
|
||||||
|
'Попробуйте /insight, чтобы получить персонализированные выводы из истории чатов.',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Custom API-KEY Configuration
|
// Custom API Key Configuration
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'For advanced users who want to configure models manually.':
|
'You can configure your API key and models in settings.json':
|
||||||
'Для продвинутых пользователей, которые хотят настраивать модели вручную.',
|
'Вы можете настроить API-ключ и модели в settings.json',
|
||||||
'Please configure your models in settings.json:':
|
'Refer to the documentation for setup instructions':
|
||||||
'Пожалуйста, настройте ваши модели в settings.json:',
|
'Инструкции по настройке см. в документации',
|
||||||
'Set API key via environment variable (e.g., OPENAI_API_KEY)':
|
|
||||||
'Установите ключ API через переменную окружения (например, OPENAI_API_KEY)',
|
|
||||||
"Add model configuration to modelProviders['openai'] (or other auth types)":
|
|
||||||
"Добавьте конфигурацию модели в modelProviders['openai'] (или другие типы аутентификации)",
|
|
||||||
'Each provider needs: id, envKey (required), plus optional baseUrl, generationConfig':
|
|
||||||
'Каждому провайдеру нужны: id, envKey (обязательно), а также опциональные baseUrl, generationConfig',
|
|
||||||
'Use /model command to select your preferred model from the configured list':
|
|
||||||
'Используйте команду /model, чтобы выбрать предпочитаемую модель из настроенного списка',
|
|
||||||
'Supported auth types: openai, anthropic, gemini, vertex-ai, etc.':
|
|
||||||
'Поддерживаемые типы аутентификации: openai, anthropic, gemini, vertex-ai и др.',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan Authentication
|
// Coding Plan Authentication
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Please enter your API key:': 'Пожалуйста, введите ваш API-ключ:',
|
|
||||||
'API key cannot be empty.': 'API-ключ не может быть пустым.',
|
'API key cannot be empty.': 'API-ключ не может быть пустым.',
|
||||||
'You can get your exclusive Coding Plan API-KEY here:':
|
'You can get your Coding Plan API key here':
|
||||||
'Получите свой эксклюзивный API-KEY Coding Plan здесь:',
|
'Вы можете получить API-ключ Coding Plan здесь',
|
||||||
'New model configurations are available for Bailian Coding Plan. Update now?':
|
'New model configurations are available for Alibaba Cloud Coding Plan. Update now?':
|
||||||
'Доступны новые конфигурации моделей для Bailian Coding Plan. Обновить сейчас?',
|
'Доступны новые конфигурации моделей для Alibaba Cloud Coding Plan. Обновить сейчас?',
|
||||||
'Coding Plan configuration updated successfully. New models are now available.':
|
'Coding Plan configuration updated successfully. New models are now available.':
|
||||||
'Конфигурация Coding Plan успешно обновлена. Новые модели теперь доступны.',
|
'Конфигурация Coding Plan успешно обновлена. Новые модели теперь доступны.',
|
||||||
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
||||||
|
|
@ -1456,34 +1478,18 @@ export default {
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Auth Dialog - View Titles and Labels
|
// Auth Dialog - View Titles and Labels
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Coding Plan': 'Coding Plan',
|
'Select Region for Coding Plan': 'Выберите регион Coding Plan',
|
||||||
'Coding Plan (Bailian, China)': 'Coding Plan (Bailian, Китай)',
|
'Choose based on where your account is registered':
|
||||||
'Coding Plan (Bailian, Global/Intl)':
|
'Выберите в зависимости от места регистрации вашего аккаунта',
|
||||||
'Coding Plan (Bailian, Глобальный/Международный)',
|
'Enter Coding Plan API Key': 'Введите API-ключ Coding Plan',
|
||||||
"Paste your api key of Bailian Coding Plan and you're all set!":
|
|
||||||
'Вставьте ваш API-ключ Bailian Coding Plan и всё готово!',
|
|
||||||
"Paste your api key of Coding Plan (Bailian, Global/Intl) and you're all set!":
|
|
||||||
'Вставьте ваш API-ключ Coding Plan (Bailian, Глобальный/Международный) и всё готово!',
|
|
||||||
Custom: 'Пользовательский',
|
|
||||||
'More instructions about configuring `modelProviders` manually.':
|
|
||||||
'Дополнительные инструкции по ручной настройке `modelProviders`.',
|
|
||||||
'Select API-KEY configuration mode:': 'Выберите режим конфигурации API-KEY:',
|
|
||||||
'(Press Escape to go back)': '(Нажмите Escape для возврата)',
|
|
||||||
'(Press Enter to submit, Escape to cancel)':
|
|
||||||
'(Нажмите Enter для отправки, Escape для отмены)',
|
|
||||||
'More instructions please check:': 'Дополнительные инструкции см.:',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan International Updates
|
// Coding Plan International Updates
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'New model configurations are available for {{region}}. Update now?':
|
'New model configurations are available for {{region}}. Update now?':
|
||||||
'Доступны новые конфигурации моделей для {{region}}. Обновить сейчас?',
|
'Доступны новые конфигурации моделей для {{region}}. Обновить сейчас?',
|
||||||
'New model configurations are available for Bailian Coding Plan (China). Update now?':
|
|
||||||
'Доступны новые конфигурации моделей для Bailian Coding Plan (Китай). Обновить сейчас?',
|
|
||||||
'New model configurations are available for Coding Plan (Bailian, Global/Intl). Update now?':
|
|
||||||
'Доступны новые конфигурации моделей для Coding Plan (Bailian, Глобальный/Международный). Обновить сейчас?',
|
|
||||||
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
||||||
'Конфигурация {{region}} успешно обновлена. Модель переключена на "{{model}}".',
|
'Конфигурация {{region}} успешно обновлена. Модель переключена на "{{model}}".',
|
||||||
'Authenticated successfully with {{region}}. API key is stored in settings.env.':
|
'Authenticated successfully with {{region}}. API key and model configs saved to settings.json (backed up).':
|
||||||
'Успешная аутентификация с {{region}}. API-ключ сохранён в settings.env.',
|
'Успешная аутентификация с {{region}}. API-ключ и конфигурации моделей сохранены в settings.json (резервная копия создана).',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@ export default {
|
||||||
'Enter to confirm, Esc to cancel': 'Enter 确认,Esc 取消',
|
'Enter to confirm, Esc to cancel': 'Enter 确认,Esc 取消',
|
||||||
'Enter to select, ↑↓ to navigate, Esc to go back':
|
'Enter to select, ↑↓ to navigate, Esc to go back':
|
||||||
'Enter 选择,↑↓ 导航,Esc 返回',
|
'Enter 选择,↑↓ 导航,Esc 返回',
|
||||||
|
'Enter to submit, Esc to go back': 'Enter 提交,Esc 返回',
|
||||||
'Invalid step: {{step}}': '无效步骤: {{step}}',
|
'Invalid step: {{step}}': '无效步骤: {{step}}',
|
||||||
'No subagents found.': '未找到子智能体。',
|
'No subagents found.': '未找到子智能体。',
|
||||||
"Use '/agents create' to create your first subagent.":
|
"Use '/agents create' to create your first subagent.":
|
||||||
|
|
@ -743,7 +744,6 @@ export default {
|
||||||
'missing name': '缺少名称',
|
'missing name': '缺少名称',
|
||||||
'missing description': '缺少描述',
|
'missing description': '缺少描述',
|
||||||
'(unnamed)': '(未命名)',
|
'(unnamed)': '(未命名)',
|
||||||
unknown: '未知',
|
|
||||||
'Warning: This tool cannot be called by the LLM':
|
'Warning: This tool cannot be called by the LLM':
|
||||||
'警告:此工具无法被 LLM 调用',
|
'警告:此工具无法被 LLM 调用',
|
||||||
Reason: '原因',
|
Reason: '原因',
|
||||||
|
|
@ -934,18 +934,21 @@ export default {
|
||||||
// Dialogs - Auth
|
// Dialogs - Auth
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Get started': '开始使用',
|
'Get started': '开始使用',
|
||||||
'How would you like to authenticate for this project?':
|
'Select Authentication Method': '选择认证方式',
|
||||||
'您希望如何为此项目进行身份验证?',
|
|
||||||
'OpenAI API key is required to use OpenAI authentication.':
|
'OpenAI API key is required to use OpenAI authentication.':
|
||||||
'使用 OpenAI 认证需要 OpenAI API 密钥',
|
'使用 OpenAI 认证需要 OpenAI API 密钥',
|
||||||
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
'You must select an auth method to proceed. Press Ctrl+C again to exit.':
|
||||||
'您必须选择认证方法才能继续。再次按 Ctrl+C 退出',
|
'您必须选择认证方法才能继续。再次按 Ctrl+C 退出',
|
||||||
'(Use Enter to Set Auth)': '(使用 Enter 设置认证)',
|
'Terms of Services and Privacy Notice': '服务条款和隐私声明',
|
||||||
'Terms of Services and Privacy Notice for Qwen Code':
|
|
||||||
'Qwen Code 的服务条款和隐私声明',
|
|
||||||
'Qwen OAuth': 'Qwen OAuth (免费)',
|
'Qwen OAuth': 'Qwen OAuth (免费)',
|
||||||
|
'Free \u00B7 Up to 1,000 requests/day \u00B7 Qwen latest models':
|
||||||
|
'免费 \u00B7 每天最多 1,000 次请求 \u00B7 Qwen 最新模型',
|
||||||
'Login with QwenChat account to use daily free quota.':
|
'Login with QwenChat account to use daily free quota.':
|
||||||
'使用 QwenChat 账号登录,享受每日免费额度。',
|
'使用 QwenChat 账号登录,享受每日免费额度。',
|
||||||
|
'Paid \u00B7 Up to 6,000 requests/5 hrs \u00B7 All Alibaba Cloud Coding Plan Models':
|
||||||
|
'付费 \u00B7 每 5 小时最多 6,000 次请求 \u00B7 支持阿里云百炼 Coding Plan 全部模型',
|
||||||
|
'Alibaba Cloud Coding Plan': '阿里云百炼 Coding Plan',
|
||||||
|
'Bring your own API key': '使用自己的 API 密钥',
|
||||||
'Use coding plan credentials or your own api-keys/providers.':
|
'Use coding plan credentials or your own api-keys/providers.':
|
||||||
'使用 Coding Plan 凭证或您自己的 API 密钥/提供商。',
|
'使用 Coding Plan 凭证或您自己的 API 密钥/提供商。',
|
||||||
OpenAI: 'OpenAI',
|
OpenAI: 'OpenAI',
|
||||||
|
|
@ -969,6 +972,8 @@ export default {
|
||||||
'Waiting for Qwen OAuth authentication...': '正在等待 Qwen OAuth 认证...',
|
'Waiting for Qwen OAuth authentication...': '正在等待 Qwen OAuth 认证...',
|
||||||
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.':
|
||||||
'注意:使用 Qwen OAuth 时,settings.json 中现有的 API 密钥不会被清除。如果需要,您可以稍后切换回 OpenAI 认证。',
|
'注意:使用 Qwen OAuth 时,settings.json 中现有的 API 密钥不会被清除。如果需要,您可以稍后切换回 OpenAI 认证。',
|
||||||
|
'Note: Your existing API key will not be cleared when using Qwen OAuth.':
|
||||||
|
'注意:使用 Qwen OAuth 时,现有的 API 密钥不会被清除。',
|
||||||
'Authentication timed out. Please try again.': '认证超时。请重试。',
|
'Authentication timed out. Please try again.': '认证超时。请重试。',
|
||||||
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
'Waiting for auth... (Press ESC or CTRL+C to cancel)':
|
||||||
'正在等待认证...(按 ESC 或 CTRL+C 取消)',
|
'正在等待认证...(按 ESC 或 CTRL+C 取消)',
|
||||||
|
|
@ -1013,6 +1018,17 @@ export default {
|
||||||
'(default)': '(默认)',
|
'(default)': '(默认)',
|
||||||
'(set)': '(已设置)',
|
'(set)': '(已设置)',
|
||||||
'(not set)': '(未设置)',
|
'(not set)': '(未设置)',
|
||||||
|
Modality: '模态',
|
||||||
|
'Context Window': '上下文窗口',
|
||||||
|
text: '文本',
|
||||||
|
'text-only': '纯文本',
|
||||||
|
image: '图像',
|
||||||
|
pdf: 'PDF',
|
||||||
|
audio: '音频',
|
||||||
|
video: '视频',
|
||||||
|
'not set': '未设置',
|
||||||
|
none: '无',
|
||||||
|
unknown: '未知',
|
||||||
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
"Failed to switch model to '{{modelId}}'.\n\n{{error}}":
|
||||||
"无法切换到模型 '{{modelId}}'.\n\n{{error}}",
|
"无法切换到模型 '{{modelId}}'.\n\n{{error}}",
|
||||||
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
'Qwen 3.5 Plus — efficient hybrid model with leading coding performance':
|
||||||
|
|
@ -1104,6 +1120,8 @@ export default {
|
||||||
'按 Shift+Tab 或输入 /approval-mode 可快速切换权限模式。',
|
'按 Shift+Tab 或输入 /approval-mode 可快速切换权限模式。',
|
||||||
'You can switch permission mode quickly with Tab or /approval-mode.':
|
'You can switch permission mode quickly with Tab or /approval-mode.':
|
||||||
'按 Tab 或输入 /approval-mode 可快速切换权限模式。',
|
'按 Tab 或输入 /approval-mode 可快速切换权限模式。',
|
||||||
|
'Try /insight to generate personalized insights from your chat history.':
|
||||||
|
'试试 /insight,从聊天记录中生成个性化洞察。',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Exit Screen / Stats
|
// Exit Screen / Stats
|
||||||
|
|
@ -1267,18 +1285,22 @@ export default {
|
||||||
'Rate limit error: {{reason}}': '触发限流:{{reason}}',
|
'Rate limit error: {{reason}}': '触发限流:{{reason}}',
|
||||||
'Retrying in {{seconds}} seconds… (attempt {{attempt}}/{{maxRetries}})':
|
'Retrying in {{seconds}} seconds… (attempt {{attempt}}/{{maxRetries}})':
|
||||||
'将于 {{seconds}} 秒后重试…(第 {{attempt}}/{{maxRetries}} 次)',
|
'将于 {{seconds}} 秒后重试…(第 {{attempt}}/{{maxRetries}} 次)',
|
||||||
|
'Press Ctrl+Y to retry': '按 Ctrl+Y 重试。',
|
||||||
|
'No failed request to retry.': '没有可重试的失败请求。',
|
||||||
|
'to retry last request': '重试上一次请求',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan Authentication
|
// Coding Plan Authentication
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'Please enter your API key:': '请输入您的 API Key:',
|
|
||||||
'API key cannot be empty.': 'API Key 不能为空。',
|
'API key cannot be empty.': 'API Key 不能为空。',
|
||||||
'You can get your exclusive Coding Plan API-KEY here:':
|
'Invalid API key. Coding Plan API keys start with "sk-sp-". Please check.':
|
||||||
'您可以在这里获取专属的 Coding Plan API-KEY:',
|
'无效的 API Key,Coding Plan API Key 均以 "sk-sp-" 开头,请检查',
|
||||||
|
'You can get your Coding Plan API key here':
|
||||||
|
'您可以在这里获取 Coding Plan API Key',
|
||||||
'API key is stored in settings.env. You can migrate it to a .env file for better security.':
|
'API key is stored in settings.env. You can migrate it to a .env file for better security.':
|
||||||
'API Key 已存储在 settings.env 中。您可以将其迁移到 .env 文件以获得更好的安全性。',
|
'API Key 已存储在 settings.env 中。您可以将其迁移到 .env 文件以获得更好的安全性。',
|
||||||
'New model configurations are available for Bailian Coding Plan. Update now?':
|
'New model configurations are available for Alibaba Cloud Coding Plan. Update now?':
|
||||||
'百炼 Coding Plan 有新模型配置可用。是否立即更新?',
|
'阿里云百炼 Coding Plan 有新模型配置可用。是否立即更新?',
|
||||||
'Coding Plan configuration updated successfully. New models are now available.':
|
'Coding Plan configuration updated successfully. New models are now available.':
|
||||||
'Coding Plan 配置更新成功。新模型现已可用。',
|
'Coding Plan 配置更新成功。新模型现已可用。',
|
||||||
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
'Coding Plan API key not found. Please re-authenticate with Coding Plan.':
|
||||||
|
|
@ -1287,53 +1309,27 @@ export default {
|
||||||
'更新 Coding Plan 配置失败:{{message}}',
|
'更新 Coding Plan 配置失败:{{message}}',
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Custom API-KEY Configuration
|
// Custom API Key Configuration
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'For advanced users who want to configure models manually.':
|
'You can configure your API key and models in settings.json':
|
||||||
'适合需要手动配置模型的高级用户。',
|
'您可以在 settings.json 中配置 API Key 和模型',
|
||||||
'Please configure your models in settings.json:':
|
'Refer to the documentation for setup instructions': '请参考文档了解配置说明',
|
||||||
'请在 settings.json 中配置您的模型:',
|
|
||||||
'Set API key via environment variable (e.g., OPENAI_API_KEY)':
|
|
||||||
'通过环境变量设置 API Key(例如:OPENAI_API_KEY)',
|
|
||||||
"Add model configuration to modelProviders['openai'] (or other auth types)":
|
|
||||||
"将模型配置添加到 modelProviders['openai'](或其他认证类型)",
|
|
||||||
'Each provider needs: id, envKey (required), plus optional baseUrl, generationConfig':
|
|
||||||
'每个提供商需要:id、envKey(必需),以及可选的 baseUrl、generationConfig',
|
|
||||||
'Use /model command to select your preferred model from the configured list':
|
|
||||||
'使用 /model 命令从配置列表中选择您偏好的模型',
|
|
||||||
'Supported auth types: openai, anthropic, gemini, vertex-ai, etc.':
|
|
||||||
'支持的认证类型:openai、anthropic、gemini、vertex-ai 等',
|
|
||||||
'More instructions please check:': '更多说明请查看:',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Auth Dialog - View Titles and Labels
|
// Auth Dialog - View Titles and Labels
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'API-KEY': 'API-KEY',
|
'Select Region for Coding Plan': '选择 Coding Plan 区域',
|
||||||
'Coding Plan': 'Coding Plan',
|
'Choose based on where your account is registered':
|
||||||
'Coding Plan (Bailian, China)': 'Coding Plan (百炼, 中国)',
|
'请根据您的账号注册地区选择',
|
||||||
'Coding Plan (Bailian, Global/Intl)': 'Coding Plan (百炼, 全球/国际)',
|
'Enter Coding Plan API Key': '输入 Coding Plan API Key',
|
||||||
"Paste your api key of Bailian Coding Plan and you're all set!":
|
|
||||||
'粘贴您的百炼 Coding Plan API Key,即可完成设置!',
|
|
||||||
"Paste your api key of Coding Plan (Bailian, Global/Intl) and you're all set!":
|
|
||||||
'粘贴您的 Coding Plan (百炼, 全球/国际) API Key,即可完成设置!',
|
|
||||||
Custom: '自定义',
|
|
||||||
'More instructions about configuring `modelProviders` manually.':
|
|
||||||
'关于手动配置 `modelProviders` 的更多说明。',
|
|
||||||
'Select API-KEY configuration mode:': '选择 API-KEY 配置模式:',
|
|
||||||
'(Press Escape to go back)': '(按 Escape 键返回)',
|
|
||||||
'(Press Enter to submit, Escape to cancel)': '(按 Enter 提交,Escape 取消)',
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Coding Plan International Updates
|
// Coding Plan International Updates
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
'New model configurations are available for {{region}}. Update now?':
|
'New model configurations are available for {{region}}. Update now?':
|
||||||
'{{region}} 有新的模型配置可用。是否立即更新?',
|
'{{region}} 有新的模型配置可用。是否立即更新?',
|
||||||
'New model configurations are available for Bailian Coding Plan (China). Update now?':
|
|
||||||
'百炼 Coding Plan (中国) 有新的模型配置可用。是否立即更新?',
|
|
||||||
'New model configurations are available for Coding Plan (Bailian, Global/Intl). Update now?':
|
|
||||||
'Coding Plan (百炼, 全球/国际) 有新的模型配置可用。是否立即更新?',
|
|
||||||
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
'{{region}} configuration updated successfully. Model switched to "{{model}}".':
|
||||||
'{{region}} 配置更新成功。模型已切换至 "{{model}}"。',
|
'{{region}} 配置更新成功。模型已切换至 "{{model}}"。',
|
||||||
'Authenticated successfully with {{region}}. API key is stored in settings.env.':
|
'Authenticated successfully with {{region}}. API key and model configs saved to settings.json (backed up).':
|
||||||
'成功通过 {{region}} 认证。API Key 已存储在 settings.env 中。',
|
'成功通过 {{region}} 认证。API Key 和模型配置已保存至 settings.json(已备份)。',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import { editorCommand } from '../ui/commands/editorCommand.js';
|
||||||
import { exportCommand } from '../ui/commands/exportCommand.js';
|
import { exportCommand } from '../ui/commands/exportCommand.js';
|
||||||
import { extensionsCommand } from '../ui/commands/extensionsCommand.js';
|
import { extensionsCommand } from '../ui/commands/extensionsCommand.js';
|
||||||
import { helpCommand } from '../ui/commands/helpCommand.js';
|
import { helpCommand } from '../ui/commands/helpCommand.js';
|
||||||
|
import { hooksCommand } from '../ui/commands/hooksCommand.js';
|
||||||
import { ideCommand } from '../ui/commands/ideCommand.js';
|
import { ideCommand } from '../ui/commands/ideCommand.js';
|
||||||
import { initCommand } from '../ui/commands/initCommand.js';
|
import { initCommand } from '../ui/commands/initCommand.js';
|
||||||
import { languageCommand } from '../ui/commands/languageCommand.js';
|
import { languageCommand } from '../ui/commands/languageCommand.js';
|
||||||
|
|
@ -40,6 +41,7 @@ import { themeCommand } from '../ui/commands/themeCommand.js';
|
||||||
import { toolsCommand } from '../ui/commands/toolsCommand.js';
|
import { toolsCommand } from '../ui/commands/toolsCommand.js';
|
||||||
import { vimCommand } from '../ui/commands/vimCommand.js';
|
import { vimCommand } from '../ui/commands/vimCommand.js';
|
||||||
import { setupGithubCommand } from '../ui/commands/setupGithubCommand.js';
|
import { setupGithubCommand } from '../ui/commands/setupGithubCommand.js';
|
||||||
|
import { insightCommand } from '../ui/commands/insightCommand.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the core, hard-coded slash commands that are an integral part
|
* Loads the core, hard-coded slash commands that are an integral part
|
||||||
|
|
@ -71,6 +73,7 @@ export class BuiltinCommandLoader implements ICommandLoader {
|
||||||
exportCommand,
|
exportCommand,
|
||||||
extensionsCommand,
|
extensionsCommand,
|
||||||
helpCommand,
|
helpCommand,
|
||||||
|
hooksCommand,
|
||||||
await ideCommand(),
|
await ideCommand(),
|
||||||
initCommand,
|
initCommand,
|
||||||
languageCommand,
|
languageCommand,
|
||||||
|
|
@ -90,6 +93,7 @@ export class BuiltinCommandLoader implements ICommandLoader {
|
||||||
vimCommand,
|
vimCommand,
|
||||||
setupGithubCommand,
|
setupGithubCommand,
|
||||||
terminalSetupCommand,
|
terminalSetupCommand,
|
||||||
|
insightCommand,
|
||||||
];
|
];
|
||||||
|
|
||||||
return allDefinitions.filter((cmd): cmd is SlashCommand => cmd !== null);
|
return allDefinitions.filter((cmd): cmd is SlashCommand => cmd !== null);
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,30 @@ This is a test prompt from markdown.`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should load markdown commands with BOM and CRLF frontmatter', async () => {
|
||||||
|
const mdContent =
|
||||||
|
'\uFEFF---\r\ndescription: Windows markdown command\r\n---\r\n\r\nPrompt from windows markdown.\r\n';
|
||||||
|
|
||||||
|
const commandPath = path.join(tempDir, 'windows-command.md');
|
||||||
|
await fs.writeFile(commandPath, mdContent, 'utf-8');
|
||||||
|
|
||||||
|
const loader = new FileCommandLoader(null);
|
||||||
|
const originalMethod = loader['getCommandDirectories'];
|
||||||
|
loader['getCommandDirectories'] = () => [{ path: tempDir }];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const commands = await loader.loadCommands(new AbortController().signal);
|
||||||
|
const windowsCommand = commands.find(
|
||||||
|
(cmd) => cmd.name === 'windows-command',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(windowsCommand).toBeDefined();
|
||||||
|
expect(windowsCommand?.description).toBe('Windows markdown command');
|
||||||
|
} finally {
|
||||||
|
loader['getCommandDirectories'] = originalMethod;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should load both toml and markdown commands', async () => {
|
it('should load both toml and markdown commands', async () => {
|
||||||
// Create both TOML and Markdown files
|
// Create both TOML and Markdown files
|
||||||
const tomlContent = `prompt = "TOML prompt"
|
const tomlContent = `prompt = "TOML prompt"
|
||||||
|
|
|
||||||
1217
packages/cli/src/services/insight/generators/DataProcessor.test.ts
Normal file
1217
packages/cli/src/services/insight/generators/DataProcessor.test.ts
Normal file
File diff suppressed because it is too large
Load diff
1131
packages/cli/src/services/insight/generators/DataProcessor.ts
Normal file
1131
packages/cli/src/services/insight/generators/DataProcessor.ts
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,124 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Qwen Code
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import fs from 'fs/promises';
|
||||||
|
import path from 'path';
|
||||||
|
import os from 'os';
|
||||||
|
import { DataProcessor } from './DataProcessor.js';
|
||||||
|
import { TemplateRenderer } from './TemplateRenderer.js';
|
||||||
|
import type {
|
||||||
|
InsightData,
|
||||||
|
InsightProgressCallback,
|
||||||
|
} from '../types/StaticInsightTypes.js';
|
||||||
|
|
||||||
|
import { createDebugLogger, type Config } from '@qwen-code/qwen-code-core';
|
||||||
|
|
||||||
|
const logger = createDebugLogger('StaticInsightGenerator');
|
||||||
|
|
||||||
|
export class StaticInsightGenerator {
|
||||||
|
private dataProcessor: DataProcessor;
|
||||||
|
private templateRenderer: TemplateRenderer;
|
||||||
|
|
||||||
|
constructor(config: Config) {
|
||||||
|
this.dataProcessor = new DataProcessor(config);
|
||||||
|
this.templateRenderer = new TemplateRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the output directory exists
|
||||||
|
private async ensureOutputDirectory(): Promise<string> {
|
||||||
|
const outputDir = path.join(os.homedir(), '.qwen', 'insights');
|
||||||
|
await fs.mkdir(outputDir, { recursive: true });
|
||||||
|
return outputDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate timestamped filename with collision detection
|
||||||
|
private async generateOutputPath(outputDir: string): Promise<string> {
|
||||||
|
const now = new Date();
|
||||||
|
const date = now.toISOString().split('T')[0]; // YYYY-MM-DD
|
||||||
|
const time = now.toTimeString().slice(0, 8).replace(/:/g, ''); // HHMMSS
|
||||||
|
|
||||||
|
let outputPath = path.join(outputDir, `insight-${date}.html`);
|
||||||
|
|
||||||
|
// Check if date-only file exists, if so, add timestamp
|
||||||
|
try {
|
||||||
|
await fs.access(outputPath);
|
||||||
|
// File exists, use timestamped version
|
||||||
|
outputPath = path.join(outputDir, `insight-${date}-${time}.html`);
|
||||||
|
} catch {
|
||||||
|
// File doesn't exist, use date-only name
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create or update the "latest" alias (symlink preferred, copy as fallback)
|
||||||
|
private async updateLatestAlias(
|
||||||
|
outputDir: string,
|
||||||
|
targetPath: string,
|
||||||
|
): Promise<void> {
|
||||||
|
const latestPath = path.join(outputDir, 'insight.html');
|
||||||
|
const relativeTarget = path.relative(outputDir, targetPath);
|
||||||
|
|
||||||
|
// Remove existing file/symlink if it exists
|
||||||
|
try {
|
||||||
|
await fs.unlink(latestPath);
|
||||||
|
} catch {
|
||||||
|
// File doesn't exist, ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try symlink first (preferred - lightweight, always points to latest)
|
||||||
|
try {
|
||||||
|
await fs.symlink(relativeTarget, latestPath);
|
||||||
|
logger.debug('Created insight symlink:', relativeTarget);
|
||||||
|
return;
|
||||||
|
} catch (error) {
|
||||||
|
logger.debug(
|
||||||
|
'Failed to create insight symlink, falling back to copy:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: copy file (works everywhere, uses more disk space)
|
||||||
|
try {
|
||||||
|
await fs.copyFile(targetPath, latestPath);
|
||||||
|
logger.debug('Created insight copy:', targetPath);
|
||||||
|
} catch (error) {
|
||||||
|
logger.debug('Failed to create insight latest alias:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate the static insight HTML file
|
||||||
|
async generateStaticInsight(
|
||||||
|
baseDir: string,
|
||||||
|
onProgress?: InsightProgressCallback,
|
||||||
|
): Promise<string> {
|
||||||
|
// Ensure output directory exists
|
||||||
|
const outputDir = await this.ensureOutputDirectory();
|
||||||
|
const facetsDir = path.join(outputDir, 'facets');
|
||||||
|
await fs.mkdir(facetsDir, { recursive: true });
|
||||||
|
|
||||||
|
// Process data
|
||||||
|
const insights: InsightData = await this.dataProcessor.generateInsights(
|
||||||
|
baseDir,
|
||||||
|
facetsDir,
|
||||||
|
onProgress,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Render HTML
|
||||||
|
const html = await this.templateRenderer.renderInsightHTML(insights);
|
||||||
|
|
||||||
|
// Generate timestamped output path
|
||||||
|
const outputPath = await this.generateOutputPath(outputDir);
|
||||||
|
|
||||||
|
// Write the HTML file
|
||||||
|
await fs.writeFile(outputPath, html, 'utf-8');
|
||||||
|
|
||||||
|
// Update latest alias (symlink preferred, copy as fallback)
|
||||||
|
await this.updateLatestAlias(outputDir, outputPath);
|
||||||
|
|
||||||
|
return outputPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Qwen Code
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { INSIGHT_JS, INSIGHT_CSS } from '@qwen-code/web-templates';
|
||||||
|
import type { InsightData } from '../types/StaticInsightTypes.js';
|
||||||
|
|
||||||
|
export class TemplateRenderer {
|
||||||
|
// Render the complete HTML file
|
||||||
|
async renderInsightHTML(insights: InsightData): Promise<string> {
|
||||||
|
const html = `<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Qwen Code Insights</title>
|
||||||
|
<style>
|
||||||
|
${INSIGHT_CSS}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="min-h-screen" id="container">
|
||||||
|
<div class="mx-auto max-w-6xl px-6 py-10 md:py-12">
|
||||||
|
<div id="react-root"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- React CDN -->
|
||||||
|
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
||||||
|
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
||||||
|
|
||||||
|
<!-- CDN Libraries -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Application Data -->
|
||||||
|
<script>
|
||||||
|
window.INSIGHT_DATA = ${JSON.stringify(insights)};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- App Script -->
|
||||||
|
<script>
|
||||||
|
${INSIGHT_JS}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
export interface InsightImpressiveWorkflows {
|
||||||
|
intro: string;
|
||||||
|
impressive_workflows: Array<{
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InsightProjectAreas {
|
||||||
|
areas: Array<{
|
||||||
|
name: string;
|
||||||
|
session_count: number;
|
||||||
|
description: string;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InsightFutureOpportunities {
|
||||||
|
intro: string;
|
||||||
|
opportunities: Array<{
|
||||||
|
title: string;
|
||||||
|
whats_possible: string;
|
||||||
|
how_to_try: string;
|
||||||
|
copyable_prompt: string;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InsightFrictionPoints {
|
||||||
|
intro: string;
|
||||||
|
categories: Array<{
|
||||||
|
category: string;
|
||||||
|
description: string;
|
||||||
|
examples: string[];
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InsightMemorableMoment {
|
||||||
|
headline: string;
|
||||||
|
detail: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InsightImprovements {
|
||||||
|
Qwen_md_additions: Array<{
|
||||||
|
addition: string;
|
||||||
|
why: string;
|
||||||
|
prompt_scaffold: string;
|
||||||
|
}>;
|
||||||
|
features_to_try: Array<{
|
||||||
|
feature: string;
|
||||||
|
one_liner: string;
|
||||||
|
why_for_you: string;
|
||||||
|
example_code: string;
|
||||||
|
}>;
|
||||||
|
usage_patterns: Array<{
|
||||||
|
title: string;
|
||||||
|
suggestion: string;
|
||||||
|
detail: string;
|
||||||
|
copyable_prompt: string;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InsightInteractionStyle {
|
||||||
|
narrative: string;
|
||||||
|
key_pattern: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InsightAtAGlance {
|
||||||
|
whats_working: string;
|
||||||
|
whats_hindering: string;
|
||||||
|
quick_wins: string;
|
||||||
|
ambitious_workflows: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QualitativeInsights {
|
||||||
|
impressiveWorkflows: InsightImpressiveWorkflows;
|
||||||
|
projectAreas: InsightProjectAreas;
|
||||||
|
futureOpportunities: InsightFutureOpportunities;
|
||||||
|
frictionPoints: InsightFrictionPoints;
|
||||||
|
memorableMoment: InsightMemorableMoment;
|
||||||
|
improvements: InsightImprovements;
|
||||||
|
interactionStyle: InsightInteractionStyle;
|
||||||
|
atAGlance: InsightAtAGlance;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Qwen Code
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { QualitativeInsights } from './QualitativeInsightTypes.js';
|
||||||
|
|
||||||
|
export interface HeatMapData {
|
||||||
|
[date: string]: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InsightData {
|
||||||
|
heatmap: HeatMapData;
|
||||||
|
currentStreak: number;
|
||||||
|
longestStreak: number;
|
||||||
|
longestWorkDate: string | null;
|
||||||
|
longestWorkDuration: number; // in minutes
|
||||||
|
activeHours: { [hour: number]: number };
|
||||||
|
latestActiveTime: string | null;
|
||||||
|
totalSessions?: number;
|
||||||
|
totalMessages?: number;
|
||||||
|
totalHours?: number;
|
||||||
|
totalLinesAdded?: number;
|
||||||
|
totalLinesRemoved?: number;
|
||||||
|
totalFiles?: number;
|
||||||
|
topTools?: Array<[string, number]>;
|
||||||
|
qualitative?: QualitativeInsights;
|
||||||
|
satisfaction?: Record<string, number>;
|
||||||
|
friction?: Record<string, number>;
|
||||||
|
primarySuccess?: Record<string, number>;
|
||||||
|
outcomes?: Record<string, number>;
|
||||||
|
topGoals?: Record<string, number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StreakData {
|
||||||
|
currentStreak: number;
|
||||||
|
longestStreak: number;
|
||||||
|
dates: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SessionFacets {
|
||||||
|
session_id: string;
|
||||||
|
underlying_goal: string;
|
||||||
|
goal_categories: Record<string, number>;
|
||||||
|
outcome:
|
||||||
|
| 'fully_achieved'
|
||||||
|
| 'mostly_achieved'
|
||||||
|
| 'partially_achieved'
|
||||||
|
| 'not_achieved'
|
||||||
|
| 'unclear_from_transcript';
|
||||||
|
user_satisfaction_counts: Record<string, number>;
|
||||||
|
Qwen_helpfulness:
|
||||||
|
| 'unhelpful'
|
||||||
|
| 'slightly_helpful'
|
||||||
|
| 'moderately_helpful'
|
||||||
|
| 'very_helpful'
|
||||||
|
| 'essential';
|
||||||
|
session_type:
|
||||||
|
| 'single_task'
|
||||||
|
| 'multi_task'
|
||||||
|
| 'iterative_refinement'
|
||||||
|
| 'exploration'
|
||||||
|
| 'quick_question';
|
||||||
|
friction_counts: Record<string, number>;
|
||||||
|
friction_detail: string;
|
||||||
|
primary_success:
|
||||||
|
| 'none'
|
||||||
|
| 'fast_accurate_search'
|
||||||
|
| 'correct_code_edits'
|
||||||
|
| 'good_explanations'
|
||||||
|
| 'proactive_help'
|
||||||
|
| 'multi_file_changes'
|
||||||
|
| 'good_debugging';
|
||||||
|
brief_summary: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StaticInsightTemplateData {
|
||||||
|
styles: string;
|
||||||
|
content: string;
|
||||||
|
data: InsightData;
|
||||||
|
scripts: string;
|
||||||
|
generatedTime: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type InsightProgressCallback = (
|
||||||
|
stage: string,
|
||||||
|
progress: number,
|
||||||
|
detail?: string,
|
||||||
|
) => void;
|
||||||
|
|
@ -94,6 +94,51 @@ Prompt content.`;
|
||||||
expect(result.frontmatter).toBeDefined();
|
expect(result.frontmatter).toBeDefined();
|
||||||
expect(result.prompt).toBe('Prompt content.');
|
expect(result.prompt).toBe('Prompt content.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should parse frontmatter in CRLF files', () => {
|
||||||
|
const content =
|
||||||
|
'---\r\ndescription: Windows command\r\n---\r\n\r\nLine 1\r\nLine 2\r\n';
|
||||||
|
|
||||||
|
const result = parseMarkdownCommand(content);
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
frontmatter: {
|
||||||
|
description: 'Windows command',
|
||||||
|
},
|
||||||
|
prompt: 'Line 1\nLine 2',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse frontmatter in CR-only files', () => {
|
||||||
|
const content =
|
||||||
|
'---\rdescription: Old mac command\r---\r\rLine 1\rLine 2\r';
|
||||||
|
|
||||||
|
const result = parseMarkdownCommand(content);
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
frontmatter: {
|
||||||
|
description: 'Old mac command',
|
||||||
|
},
|
||||||
|
prompt: 'Line 1\nLine 2',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse frontmatter when content starts with UTF-8 BOM', () => {
|
||||||
|
const content = `\uFEFF---
|
||||||
|
description: BOM command
|
||||||
|
---
|
||||||
|
|
||||||
|
Prompt from BOM file.`;
|
||||||
|
|
||||||
|
const result = parseMarkdownCommand(content);
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
frontmatter: {
|
||||||
|
description: 'BOM command',
|
||||||
|
},
|
||||||
|
prompt: 'Prompt from BOM file.',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('MarkdownCommandDefSchema', () => {
|
describe('MarkdownCommandDefSchema', () => {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { parse as parseYaml } from '@qwen-code/qwen-code-core';
|
import {
|
||||||
|
parse as parseYaml,
|
||||||
|
normalizeContent,
|
||||||
|
} from '@qwen-code/qwen-code-core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the Zod schema for a Markdown command definition file.
|
* Defines the Zod schema for a Markdown command definition file.
|
||||||
|
|
@ -31,19 +34,21 @@ export type MarkdownCommandDef = z.infer<typeof MarkdownCommandDefSchema>;
|
||||||
* @returns Parsed command definition with frontmatter and prompt
|
* @returns Parsed command definition with frontmatter and prompt
|
||||||
*/
|
*/
|
||||||
export function parseMarkdownCommand(content: string): MarkdownCommandDef {
|
export function parseMarkdownCommand(content: string): MarkdownCommandDef {
|
||||||
|
const normalizedContent = normalizeContent(content);
|
||||||
|
|
||||||
// Match YAML frontmatter pattern: ---\n...\n---\n
|
// Match YAML frontmatter pattern: ---\n...\n---\n
|
||||||
// Allow empty frontmatter: ---\n---\n // Use (?:[\s\S]*?) to make the frontmatter content optional
|
// Allow empty frontmatter: ---\n---\n
|
||||||
const frontmatterRegex = /^---\n([\s\S]*?)---\n([\s\S]*)$/;
|
const frontmatterRegex = /^---\n(?:([\s\S]*?)\n)?---(?:\n|$)([\s\S]*)$/;
|
||||||
const match = content.match(frontmatterRegex);
|
const match = normalizedContent.match(frontmatterRegex);
|
||||||
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
// No frontmatter, entire content is the prompt
|
// No frontmatter, entire content is the prompt
|
||||||
return {
|
return {
|
||||||
prompt: content.trim(),
|
prompt: normalizedContent.trim(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const [, frontmatterYaml, body] = match;
|
const [, frontmatterYaml = '', body] = match;
|
||||||
|
|
||||||
// Parse YAML frontmatter if not empty
|
// Parse YAML frontmatter if not empty
|
||||||
let frontmatter: Record<string, unknown> | undefined;
|
let frontmatter: Record<string, unknown> | undefined;
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,7 @@ describe('AppContainer State Management', () => {
|
||||||
pendingHistoryItems: [],
|
pendingHistoryItems: [],
|
||||||
thought: null,
|
thought: null,
|
||||||
cancelOngoingRequest: vi.fn(),
|
cancelOngoingRequest: vi.fn(),
|
||||||
|
retryLastPrompt: vi.fn(),
|
||||||
});
|
});
|
||||||
mockedUseVim.mockReturnValue({ handleInput: vi.fn() });
|
mockedUseVim.mockReturnValue({ handleInput: vi.fn() });
|
||||||
mockedUseFolderTrust.mockReturnValue({
|
mockedUseFolderTrust.mockReturnValue({
|
||||||
|
|
@ -607,6 +608,7 @@ describe('AppContainer State Management', () => {
|
||||||
pendingHistoryItems: [],
|
pendingHistoryItems: [],
|
||||||
thought: { subject: thoughtSubject },
|
thought: { subject: thoughtSubject },
|
||||||
cancelOngoingRequest: vi.fn(),
|
cancelOngoingRequest: vi.fn(),
|
||||||
|
retryLastPrompt: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act: Render the container
|
// Act: Render the container
|
||||||
|
|
@ -652,6 +654,7 @@ describe('AppContainer State Management', () => {
|
||||||
pendingHistoryItems: [],
|
pendingHistoryItems: [],
|
||||||
thought: null,
|
thought: null,
|
||||||
cancelOngoingRequest: vi.fn(),
|
cancelOngoingRequest: vi.fn(),
|
||||||
|
retryLastPrompt: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act: Render the container
|
// Act: Render the container
|
||||||
|
|
@ -698,6 +701,7 @@ describe('AppContainer State Management', () => {
|
||||||
pendingHistoryItems: [],
|
pendingHistoryItems: [],
|
||||||
thought: { subject: thoughtSubject },
|
thought: { subject: thoughtSubject },
|
||||||
cancelOngoingRequest: vi.fn(),
|
cancelOngoingRequest: vi.fn(),
|
||||||
|
retryLastPrompt: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act: Render the container
|
// Act: Render the container
|
||||||
|
|
@ -744,6 +748,7 @@ describe('AppContainer State Management', () => {
|
||||||
pendingHistoryItems: [],
|
pendingHistoryItems: [],
|
||||||
thought: { subject: shortTitle },
|
thought: { subject: shortTitle },
|
||||||
cancelOngoingRequest: vi.fn(),
|
cancelOngoingRequest: vi.fn(),
|
||||||
|
retryLastPrompt: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act: Render the container
|
// Act: Render the container
|
||||||
|
|
@ -794,6 +799,7 @@ describe('AppContainer State Management', () => {
|
||||||
pendingHistoryItems: [],
|
pendingHistoryItems: [],
|
||||||
thought: { subject: title },
|
thought: { subject: title },
|
||||||
cancelOngoingRequest: vi.fn(),
|
cancelOngoingRequest: vi.fn(),
|
||||||
|
retryLastPrompt: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act: Render the container
|
// Act: Render the container
|
||||||
|
|
@ -841,6 +847,7 @@ describe('AppContainer State Management', () => {
|
||||||
pendingHistoryItems: [],
|
pendingHistoryItems: [],
|
||||||
thought: null,
|
thought: null,
|
||||||
cancelOngoingRequest: vi.fn(),
|
cancelOngoingRequest: vi.fn(),
|
||||||
|
retryLastPrompt: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act: Render the container
|
// Act: Render the container
|
||||||
|
|
@ -882,6 +889,7 @@ describe('AppContainer State Management', () => {
|
||||||
pendingHistoryItems: [],
|
pendingHistoryItems: [],
|
||||||
thought: null,
|
thought: null,
|
||||||
cancelOngoingRequest: vi.fn(),
|
cancelOngoingRequest: vi.fn(),
|
||||||
|
retryLastPrompt: vi.fn(),
|
||||||
activePtyId: 'some-id',
|
activePtyId: 'some-id',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1013,6 +1021,7 @@ describe('AppContainer State Management', () => {
|
||||||
pendingHistoryItems: [],
|
pendingHistoryItems: [],
|
||||||
thought: null,
|
thought: null,
|
||||||
cancelOngoingRequest: mockCancelOngoingRequest,
|
cancelOngoingRequest: mockCancelOngoingRequest,
|
||||||
|
retryLastPrompt: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockHandleSlashCommand = vi.fn();
|
const mockHandleSlashCommand = vi.fn();
|
||||||
|
|
|
||||||
|
|
@ -100,8 +100,6 @@ import { t } from '../i18n/index.js';
|
||||||
import { useWelcomeBack } from './hooks/useWelcomeBack.js';
|
import { useWelcomeBack } from './hooks/useWelcomeBack.js';
|
||||||
import { useDialogClose } from './hooks/useDialogClose.js';
|
import { useDialogClose } from './hooks/useDialogClose.js';
|
||||||
import { useInitializationAuthError } from './hooks/useInitializationAuthError.js';
|
import { useInitializationAuthError } from './hooks/useInitializationAuthError.js';
|
||||||
import { type VisionSwitchOutcome } from './components/ModelSwitchDialog.js';
|
|
||||||
import { processVisionSwitchOutcome } from './hooks/useVisionAutoSwitch.js';
|
|
||||||
import { useSubagentCreateDialog } from './hooks/useSubagentCreateDialog.js';
|
import { useSubagentCreateDialog } from './hooks/useSubagentCreateDialog.js';
|
||||||
import { useAgentsManagerDialog } from './hooks/useAgentsManagerDialog.js';
|
import { useAgentsManagerDialog } from './hooks/useAgentsManagerDialog.js';
|
||||||
import { useMcpDialog } from './hooks/useMcpDialog.js';
|
import { useMcpDialog } from './hooks/useMcpDialog.js';
|
||||||
|
|
@ -498,18 +496,6 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
} = useAgentsManagerDialog();
|
} = useAgentsManagerDialog();
|
||||||
const { isMcpDialogOpen, openMcpDialog, closeMcpDialog } = useMcpDialog();
|
const { isMcpDialogOpen, openMcpDialog, closeMcpDialog } = useMcpDialog();
|
||||||
|
|
||||||
// Vision model auto-switch dialog state (must be before slashCommandActions)
|
|
||||||
const [isVisionSwitchDialogOpen, setIsVisionSwitchDialogOpen] =
|
|
||||||
useState(false);
|
|
||||||
const [visionSwitchResolver, setVisionSwitchResolver] = useState<{
|
|
||||||
resolve: (result: {
|
|
||||||
modelOverride?: string;
|
|
||||||
persistSessionModel?: string;
|
|
||||||
showGuidance?: boolean;
|
|
||||||
}) => void;
|
|
||||||
reject: () => void;
|
|
||||||
} | null>(null);
|
|
||||||
|
|
||||||
const slashCommandActions = useMemo(
|
const slashCommandActions = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
openAuthDialog,
|
openAuthDialog,
|
||||||
|
|
@ -567,6 +553,7 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
historyManager.loadHistory,
|
historyManager.loadHistory,
|
||||||
refreshStatic,
|
refreshStatic,
|
||||||
toggleVimEnabled,
|
toggleVimEnabled,
|
||||||
|
isProcessing,
|
||||||
setIsProcessing,
|
setIsProcessing,
|
||||||
setGeminiMdFileCount,
|
setGeminiMdFileCount,
|
||||||
slashCommandActions,
|
slashCommandActions,
|
||||||
|
|
@ -575,32 +562,6 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
logger,
|
logger,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Vision switch handlers
|
|
||||||
const handleVisionSwitchRequired = useCallback(
|
|
||||||
async (_query: unknown) =>
|
|
||||||
new Promise<{
|
|
||||||
modelOverride?: string;
|
|
||||||
persistSessionModel?: string;
|
|
||||||
showGuidance?: boolean;
|
|
||||||
}>((resolve, reject) => {
|
|
||||||
setVisionSwitchResolver({ resolve, reject });
|
|
||||||
setIsVisionSwitchDialogOpen(true);
|
|
||||||
}),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleVisionSwitchSelect = useCallback(
|
|
||||||
(outcome: VisionSwitchOutcome) => {
|
|
||||||
setIsVisionSwitchDialogOpen(false);
|
|
||||||
if (visionSwitchResolver) {
|
|
||||||
const result = processVisionSwitchOutcome(outcome);
|
|
||||||
visionSwitchResolver.resolve(result);
|
|
||||||
setVisionSwitchResolver(null);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[visionSwitchResolver],
|
|
||||||
);
|
|
||||||
|
|
||||||
// onDebugMessage should log to debug logfile, not update footer debugMessage
|
// onDebugMessage should log to debug logfile, not update footer debugMessage
|
||||||
const onDebugMessage = useCallback(
|
const onDebugMessage = useCallback(
|
||||||
(message: string) => {
|
(message: string) => {
|
||||||
|
|
@ -672,6 +633,7 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
pendingHistoryItems: pendingGeminiHistoryItems,
|
pendingHistoryItems: pendingGeminiHistoryItems,
|
||||||
thought,
|
thought,
|
||||||
cancelOngoingRequest,
|
cancelOngoingRequest,
|
||||||
|
retryLastPrompt,
|
||||||
handleApprovalModeChange,
|
handleApprovalModeChange,
|
||||||
activePtyId,
|
activePtyId,
|
||||||
loopDetectionConfirmationRequest,
|
loopDetectionConfirmationRequest,
|
||||||
|
|
@ -691,11 +653,9 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
setModelSwitchedFromQuotaError,
|
setModelSwitchedFromQuotaError,
|
||||||
refreshStatic,
|
refreshStatic,
|
||||||
() => cancelHandlerRef.current(),
|
() => cancelHandlerRef.current(),
|
||||||
settings.merged.experimental?.visionModelPreview ?? false, // visionModelPreviewEnabled
|
|
||||||
setEmbeddedShellFocused,
|
setEmbeddedShellFocused,
|
||||||
terminalWidth,
|
terminalWidth,
|
||||||
terminalHeight,
|
terminalHeight,
|
||||||
handleVisionSwitchRequired, // onVisionSwitchRequired
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Track whether suggestions are visible for Tab key handling
|
// Track whether suggestions are visible for Tab key handling
|
||||||
|
|
@ -850,7 +810,6 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
!isThemeDialogOpen &&
|
!isThemeDialogOpen &&
|
||||||
!isEditorDialogOpen &&
|
!isEditorDialogOpen &&
|
||||||
!showWelcomeBackDialog &&
|
!showWelcomeBackDialog &&
|
||||||
!isVisionSwitchDialogOpen &&
|
|
||||||
welcomeBackChoice !== 'restart' &&
|
welcomeBackChoice !== 'restart' &&
|
||||||
geminiClient?.isInitialized?.()
|
geminiClient?.isInitialized?.()
|
||||||
) {
|
) {
|
||||||
|
|
@ -866,7 +825,6 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
isThemeDialogOpen,
|
isThemeDialogOpen,
|
||||||
isEditorDialogOpen,
|
isEditorDialogOpen,
|
||||||
showWelcomeBackDialog,
|
showWelcomeBackDialog,
|
||||||
isVisionSwitchDialogOpen,
|
|
||||||
welcomeBackChoice,
|
welcomeBackChoice,
|
||||||
geminiClient,
|
geminiClient,
|
||||||
]);
|
]);
|
||||||
|
|
@ -1338,7 +1296,6 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
isThemeDialogOpen ||
|
isThemeDialogOpen ||
|
||||||
isSettingsDialogOpen ||
|
isSettingsDialogOpen ||
|
||||||
isModelDialogOpen ||
|
isModelDialogOpen ||
|
||||||
isVisionSwitchDialogOpen ||
|
|
||||||
isPermissionsDialogOpen ||
|
isPermissionsDialogOpen ||
|
||||||
isAuthDialogOpen ||
|
isAuthDialogOpen ||
|
||||||
isAuthenticating ||
|
isAuthenticating ||
|
||||||
|
|
@ -1451,8 +1408,6 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
extensionsUpdateState,
|
extensionsUpdateState,
|
||||||
activePtyId,
|
activePtyId,
|
||||||
embeddedShellFocused,
|
embeddedShellFocused,
|
||||||
// Vision switch dialog
|
|
||||||
isVisionSwitchDialogOpen,
|
|
||||||
// Welcome back dialog
|
// Welcome back dialog
|
||||||
showWelcomeBackDialog,
|
showWelcomeBackDialog,
|
||||||
welcomeBackInfo,
|
welcomeBackInfo,
|
||||||
|
|
@ -1545,8 +1500,6 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
activePtyId,
|
activePtyId,
|
||||||
historyManager,
|
historyManager,
|
||||||
embeddedShellFocused,
|
embeddedShellFocused,
|
||||||
// Vision switch dialog
|
|
||||||
isVisionSwitchDialogOpen,
|
|
||||||
// Welcome back dialog
|
// Welcome back dialog
|
||||||
showWelcomeBackDialog,
|
showWelcomeBackDialog,
|
||||||
welcomeBackInfo,
|
welcomeBackInfo,
|
||||||
|
|
@ -1589,9 +1542,8 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
onSuggestionsVisibilityChange: setHasSuggestionsVisible,
|
onSuggestionsVisibilityChange: setHasSuggestionsVisible,
|
||||||
refreshStatic,
|
refreshStatic,
|
||||||
handleFinalSubmit,
|
handleFinalSubmit,
|
||||||
|
handleRetryLastPrompt: retryLastPrompt,
|
||||||
handleClearScreen,
|
handleClearScreen,
|
||||||
// Vision switch dialog
|
|
||||||
handleVisionSwitchSelect,
|
|
||||||
// Welcome back dialog
|
// Welcome back dialog
|
||||||
handleWelcomeBackSelection,
|
handleWelcomeBackSelection,
|
||||||
handleWelcomeBackClose,
|
handleWelcomeBackClose,
|
||||||
|
|
@ -1636,8 +1588,8 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||||
handleEscapePromptChange,
|
handleEscapePromptChange,
|
||||||
refreshStatic,
|
refreshStatic,
|
||||||
handleFinalSubmit,
|
handleFinalSubmit,
|
||||||
|
retryLastPrompt,
|
||||||
handleClearScreen,
|
handleClearScreen,
|
||||||
handleVisionSwitchSelect,
|
|
||||||
handleWelcomeBackSelection,
|
handleWelcomeBackSelection,
|
||||||
handleWelcomeBackClose,
|
handleWelcomeBackClose,
|
||||||
// Subagent dialogs
|
// Subagent dialogs
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ const createMockUIActions = (overrides: Partial<UIActions> = {}): UIActions => {
|
||||||
// AuthDialog only uses handleAuthSelect
|
// AuthDialog only uses handleAuthSelect
|
||||||
const baseActions = {
|
const baseActions = {
|
||||||
handleAuthSelect: vi.fn(),
|
handleAuthSelect: vi.fn(),
|
||||||
|
handleRetryLastPrompt: vi.fn(),
|
||||||
} as Partial<UIActions>;
|
} as Partial<UIActions>;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -169,9 +170,9 @@ describe('AuthDialog', () => {
|
||||||
|
|
||||||
const { lastFrame } = renderAuthDialog(settings);
|
const { lastFrame } = renderAuthDialog(settings);
|
||||||
|
|
||||||
// Since the auth dialog shows API-KEY option now,
|
// Since the auth dialog shows API Key option now,
|
||||||
// it won't show GEMINI_API_KEY messages
|
// it won't show GEMINI_API_KEY messages
|
||||||
expect(lastFrame()).toContain('API-KEY');
|
expect(lastFrame()).toContain('API Key');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not show the GEMINI_API_KEY message if QWEN_DEFAULT_AUTH_TYPE is set to something else', () => {
|
it('should not show the GEMINI_API_KEY message if QWEN_DEFAULT_AUTH_TYPE is set to something else', () => {
|
||||||
|
|
@ -257,9 +258,9 @@ describe('AuthDialog', () => {
|
||||||
|
|
||||||
const { lastFrame } = renderAuthDialog(settings);
|
const { lastFrame } = renderAuthDialog(settings);
|
||||||
|
|
||||||
// Since the auth dialog shows API-KEY option now,
|
// Since the auth dialog shows API Key option now,
|
||||||
// it won't show GEMINI_API_KEY messages
|
// it won't show GEMINI_API_KEY messages
|
||||||
expect(lastFrame()).toContain('API-KEY');
|
expect(lastFrame()).toContain('API Key');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -305,7 +306,7 @@ describe('AuthDialog', () => {
|
||||||
const { lastFrame } = renderAuthDialog(settings);
|
const { lastFrame } = renderAuthDialog(settings);
|
||||||
|
|
||||||
// QWEN_OAUTH is the first option, so it should be selected
|
// QWEN_OAUTH is the first option, so it should be selected
|
||||||
expect(lastFrame()).toContain('● 1. Qwen OAuth');
|
expect(lastFrame()).toContain('Qwen OAuth');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fall back to default if QWEN_DEFAULT_AUTH_TYPE is not set', () => {
|
it('should fall back to default if QWEN_DEFAULT_AUTH_TYPE is not set', () => {
|
||||||
|
|
@ -345,7 +346,7 @@ describe('AuthDialog', () => {
|
||||||
const { lastFrame } = renderAuthDialog(settings);
|
const { lastFrame } = renderAuthDialog(settings);
|
||||||
|
|
||||||
// Default is Qwen OAuth (first option)
|
// Default is Qwen OAuth (first option)
|
||||||
expect(lastFrame()).toContain('● 1. Qwen OAuth');
|
expect(lastFrame()).toContain('Qwen OAuth');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show an error and fall back to default if QWEN_DEFAULT_AUTH_TYPE is invalid', () => {
|
it('should show an error and fall back to default if QWEN_DEFAULT_AUTH_TYPE is invalid', () => {
|
||||||
|
|
@ -388,7 +389,7 @@ describe('AuthDialog', () => {
|
||||||
|
|
||||||
// Since the auth dialog doesn't show QWEN_DEFAULT_AUTH_TYPE errors anymore,
|
// Since the auth dialog doesn't show QWEN_DEFAULT_AUTH_TYPE errors anymore,
|
||||||
// it will just show the default Qwen OAuth option
|
// it will just show the default Qwen OAuth option
|
||||||
expect(lastFrame()).toContain('● 1. Qwen OAuth');
|
expect(lastFrame()).toContain('Qwen OAuth');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,16 +11,19 @@ import { Box, Text } from 'ink';
|
||||||
import Link from 'ink-link';
|
import Link from 'ink-link';
|
||||||
import { theme } from '../semantic-colors.js';
|
import { theme } from '../semantic-colors.js';
|
||||||
import { useKeypress } from '../hooks/useKeypress.js';
|
import { useKeypress } from '../hooks/useKeypress.js';
|
||||||
import { RadioButtonSelect } from '../components/shared/RadioButtonSelect.js';
|
import { DescriptiveRadioButtonSelect } from '../components/shared/DescriptiveRadioButtonSelect.js';
|
||||||
import { ApiKeyInput } from '../components/ApiKeyInput.js';
|
import { ApiKeyInput } from '../components/ApiKeyInput.js';
|
||||||
import { useUIState } from '../contexts/UIStateContext.js';
|
import { useUIState } from '../contexts/UIStateContext.js';
|
||||||
import { useUIActions } from '../contexts/UIActionsContext.js';
|
import { useUIActions } from '../contexts/UIActionsContext.js';
|
||||||
import { useConfig } from '../contexts/ConfigContext.js';
|
import { useConfig } from '../contexts/ConfigContext.js';
|
||||||
import { t } from '../../i18n/index.js';
|
import { t } from '../../i18n/index.js';
|
||||||
import { CodingPlanRegion } from '../../constants/codingPlan.js';
|
import {
|
||||||
|
CodingPlanRegion,
|
||||||
|
isCodingPlanConfig,
|
||||||
|
} from '../../constants/codingPlan.js';
|
||||||
|
|
||||||
const MODEL_PROVIDERS_DOCUMENTATION_URL =
|
const MODEL_PROVIDERS_DOCUMENTATION_URL =
|
||||||
'https://qwenlm.github.io/qwen-code-docs/en/users/configuration/settings/#modelproviders';
|
'https://qwenlm.github.io/qwen-code-docs/en/users/configuration/model-providers/';
|
||||||
|
|
||||||
function parseDefaultAuthType(
|
function parseDefaultAuthType(
|
||||||
defaultAuthType: string | undefined,
|
defaultAuthType: string | undefined,
|
||||||
|
|
@ -34,11 +37,11 @@ function parseDefaultAuthType(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sub-mode types for API-KEY authentication
|
// Main menu option type
|
||||||
type ApiKeySubMode = 'coding-plan' | 'coding-plan-intl' | 'custom';
|
type MainOption = typeof AuthType.QWEN_OAUTH | 'CODING_PLAN' | 'API_KEY';
|
||||||
|
|
||||||
// View level for navigation
|
// View level for navigation
|
||||||
type ViewLevel = 'main' | 'api-key-sub' | 'api-key-input' | 'custom-info';
|
type ViewLevel = 'main' | 'region-select' | 'api-key-input' | 'custom-info';
|
||||||
|
|
||||||
export function AuthDialog(): React.JSX.Element {
|
export function AuthDialog(): React.JSX.Element {
|
||||||
const { pendingAuthType, authError } = useUIState();
|
const { pendingAuthType, authError } = useUIState();
|
||||||
|
|
@ -50,58 +53,107 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
|
|
||||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||||
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);
|
|
||||||
const [viewLevel, setViewLevel] = useState<ViewLevel>('main');
|
const [viewLevel, setViewLevel] = useState<ViewLevel>('main');
|
||||||
const [apiKeySubModeIndex, setApiKeySubModeIndex] = useState<number>(0);
|
const [regionIndex, setRegionIndex] = useState<number>(0);
|
||||||
const [region, setRegion] = useState<CodingPlanRegion>(
|
const [region, setRegion] = useState<CodingPlanRegion>(
|
||||||
CodingPlanRegion.CHINA,
|
CodingPlanRegion.CHINA,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Main authentication entries
|
// Main authentication entries (flat three-option layout)
|
||||||
const mainItems = [
|
const mainItems = [
|
||||||
{
|
{
|
||||||
key: AuthType.QWEN_OAUTH,
|
key: AuthType.QWEN_OAUTH,
|
||||||
|
title: t('Qwen OAuth'),
|
||||||
label: t('Qwen OAuth'),
|
label: t('Qwen OAuth'),
|
||||||
value: AuthType.QWEN_OAUTH,
|
description: t(
|
||||||
|
'Free \u00B7 Up to 1,000 requests/day \u00B7 Qwen latest models',
|
||||||
|
),
|
||||||
|
value: AuthType.QWEN_OAUTH as MainOption,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'API-KEY',
|
key: 'CODING_PLAN',
|
||||||
label: t('API-KEY'),
|
title: t('Alibaba Cloud Coding Plan'),
|
||||||
value: 'API-KEY' as const,
|
label: t('Alibaba Cloud Coding Plan'),
|
||||||
|
description: t(
|
||||||
|
'Paid \u00B7 Up to 6,000 requests/5 hrs \u00B7 All Alibaba Cloud Coding Plan Models',
|
||||||
|
),
|
||||||
|
value: 'CODING_PLAN' as MainOption,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'API_KEY',
|
||||||
|
title: t('API Key'),
|
||||||
|
label: t('API Key'),
|
||||||
|
description: t('Bring your own API key'),
|
||||||
|
value: 'API_KEY' as MainOption,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// API-KEY sub-mode entries
|
// Region selection entries (shown after selecting Alibaba Cloud Coding Plan)
|
||||||
const apiKeySubItems = [
|
const regionItems = [
|
||||||
{
|
{
|
||||||
key: 'coding-plan',
|
key: 'china',
|
||||||
label: t('Coding Plan (Bailian, China)'),
|
title: '阿里云百炼 (aliyun.com)',
|
||||||
value: 'coding-plan' as ApiKeySubMode,
|
label: '阿里云百炼 (aliyun.com)',
|
||||||
|
description: (
|
||||||
|
<Link
|
||||||
|
url="https://help.aliyun.com/zh/model-studio/coding-plan"
|
||||||
|
fallback={false}
|
||||||
|
>
|
||||||
|
<Text color={theme.text.secondary}>
|
||||||
|
https://help.aliyun.com/zh/model-studio/coding-plan
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
value: CodingPlanRegion.CHINA,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'coding-plan-intl',
|
key: 'global',
|
||||||
label: t('Coding Plan (Bailian, Global/Intl)'),
|
title: 'Alibaba Cloud (alibabacloud.com)',
|
||||||
value: 'coding-plan-intl' as ApiKeySubMode,
|
label: 'Alibaba Cloud (alibabacloud.com)',
|
||||||
},
|
description: (
|
||||||
{
|
<Link
|
||||||
key: 'custom',
|
url="https://www.alibabacloud.com/help/en/model-studio/coding-plan"
|
||||||
label: t('Custom'),
|
fallback={false}
|
||||||
value: 'custom' as ApiKeySubMode,
|
>
|
||||||
|
<Text color={theme.text.secondary}>
|
||||||
|
https://www.alibabacloud.com/help/en/model-studio/coding-plan
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
value: CodingPlanRegion.GLOBAL,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Map an AuthType to the corresponding main menu option.
|
||||||
|
// QWEN_OAUTH maps directly; any other auth type maps to CODING_PLAN only
|
||||||
|
// if the current config actually uses a Coding Plan baseUrl+envKey,
|
||||||
|
// otherwise it maps to API_KEY.
|
||||||
|
const contentGenConfig = config.getContentGeneratorConfig();
|
||||||
|
const isCurrentlyCodingPlan =
|
||||||
|
isCodingPlanConfig(
|
||||||
|
contentGenConfig?.baseUrl,
|
||||||
|
contentGenConfig?.apiKeyEnvKey,
|
||||||
|
) !== false;
|
||||||
|
|
||||||
|
const authTypeToMainOption = (authType: AuthType): MainOption => {
|
||||||
|
if (authType === AuthType.QWEN_OAUTH) return AuthType.QWEN_OAUTH;
|
||||||
|
if (authType === AuthType.USE_OPENAI && isCurrentlyCodingPlan)
|
||||||
|
return 'CODING_PLAN';
|
||||||
|
return 'API_KEY';
|
||||||
|
};
|
||||||
|
|
||||||
const initialAuthIndex = Math.max(
|
const initialAuthIndex = Math.max(
|
||||||
0,
|
0,
|
||||||
mainItems.findIndex((item) => {
|
mainItems.findIndex((item) => {
|
||||||
// Priority 1: pendingAuthType
|
// Priority 1: pendingAuthType
|
||||||
if (pendingAuthType) {
|
if (pendingAuthType) {
|
||||||
return item.value === pendingAuthType;
|
return item.value === authTypeToMainOption(pendingAuthType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 2: config.getAuthType() - the source of truth
|
// Priority 2: config.getAuthType() - the source of truth
|
||||||
const currentAuthType = config.getAuthType();
|
const currentAuthType = config.getAuthType();
|
||||||
if (currentAuthType) {
|
if (currentAuthType) {
|
||||||
return item.value === currentAuthType;
|
return item.value === authTypeToMainOption(currentAuthType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 3: QWEN_DEFAULT_AUTH_TYPE env var
|
// Priority 3: QWEN_DEFAULT_AUTH_TYPE env var
|
||||||
|
|
@ -109,7 +161,7 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
process.env['QWEN_DEFAULT_AUTH_TYPE'],
|
process.env['QWEN_DEFAULT_AUTH_TYPE'],
|
||||||
);
|
);
|
||||||
if (defaultAuthType) {
|
if (defaultAuthType) {
|
||||||
return item.value === defaultAuthType;
|
return item.value === authTypeToMainOption(defaultAuthType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 4: default to QWEN_OAUTH
|
// Priority 4: default to QWEN_OAUTH
|
||||||
|
|
@ -117,21 +169,19 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const hasApiKey = Boolean(config.getContentGeneratorConfig()?.apiKey);
|
const handleMainSelect = async (value: MainOption) => {
|
||||||
const currentSelectedAuthType =
|
|
||||||
selectedIndex !== null
|
|
||||||
? mainItems[selectedIndex]?.value
|
|
||||||
: mainItems[initialAuthIndex]?.value;
|
|
||||||
|
|
||||||
const handleMainSelect = async (
|
|
||||||
value: (typeof mainItems)[number]['value'],
|
|
||||||
) => {
|
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
onAuthError(null);
|
onAuthError(null);
|
||||||
|
|
||||||
if (value === 'API-KEY') {
|
if (value === 'CODING_PLAN') {
|
||||||
// Navigate to API-KEY sub-mode selection
|
// Navigate to region selection
|
||||||
setViewLevel('api-key-sub');
|
setViewLevel('region-select');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value === 'API_KEY') {
|
||||||
|
// Navigate directly to custom API key info
|
||||||
|
setViewLevel('custom-info');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,19 +189,11 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
await onAuthSelect(value);
|
await onAuthSelect(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleApiKeySubSelect = async (subMode: ApiKeySubMode) => {
|
const handleRegionSelect = async (selectedRegion: CodingPlanRegion) => {
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
onAuthError(null);
|
onAuthError(null);
|
||||||
|
setRegion(selectedRegion);
|
||||||
if (subMode === 'coding-plan') {
|
setViewLevel('api-key-input');
|
||||||
setRegion(CodingPlanRegion.CHINA);
|
|
||||||
setViewLevel('api-key-input');
|
|
||||||
} else if (subMode === 'coding-plan-intl') {
|
|
||||||
setRegion(CodingPlanRegion.GLOBAL);
|
|
||||||
setViewLevel('api-key-input');
|
|
||||||
} else {
|
|
||||||
setViewLevel('custom-info');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleApiKeyInputSubmit = async (apiKey: string) => {
|
const handleApiKeyInputSubmit = async (apiKey: string) => {
|
||||||
|
|
@ -170,12 +212,10 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
onAuthError(null);
|
onAuthError(null);
|
||||||
|
|
||||||
if (viewLevel === 'api-key-sub') {
|
if (viewLevel === 'region-select' || viewLevel === 'custom-info') {
|
||||||
setViewLevel('main');
|
setViewLevel('main');
|
||||||
// Reset selectedIndex to ensure UI syncs with initialAuthIndex
|
} else if (viewLevel === 'api-key-input') {
|
||||||
setSelectedIndex(null);
|
setViewLevel('region-select');
|
||||||
} else if (viewLevel === 'api-key-input' || viewLevel === 'custom-info') {
|
|
||||||
setViewLevel('api-key-sub');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -183,7 +223,7 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
(key) => {
|
(key) => {
|
||||||
if (key.name === 'escape') {
|
if (key.name === 'escape') {
|
||||||
// Handle Escape based on current view level
|
// Handle Escape based on current view level
|
||||||
if (viewLevel === 'api-key-sub') {
|
if (viewLevel === 'region-select') {
|
||||||
handleGoBack();
|
handleGoBack();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -215,62 +255,39 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
const renderMainView = () => (
|
const renderMainView = () => (
|
||||||
<>
|
<>
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text>{t('How would you like to authenticate for this project?')}</Text>
|
<DescriptiveRadioButtonSelect
|
||||||
</Box>
|
|
||||||
<Box marginTop={1}>
|
|
||||||
<RadioButtonSelect
|
|
||||||
items={mainItems}
|
items={mainItems}
|
||||||
initialIndex={initialAuthIndex}
|
initialIndex={initialAuthIndex}
|
||||||
onSelect={handleMainSelect}
|
onSelect={handleMainSelect}
|
||||||
onHighlight={(value) => {
|
itemGap={1}
|
||||||
const index = mainItems.findIndex((item) => item.value === value);
|
|
||||||
setSelectedIndex(index);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box marginTop={1} paddingLeft={2}>
|
|
||||||
<Text color={theme.text.secondary}>
|
|
||||||
{currentSelectedAuthType === AuthType.QWEN_OAUTH
|
|
||||||
? t('Login with QwenChat account to use daily free quota.')
|
|
||||||
: t('Use coding plan credentials or your own api-keys/providers.')}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
// Render API-KEY sub-mode selection
|
// Render region selection for Alibaba Cloud Coding Plan
|
||||||
const renderApiKeySubView = () => (
|
const renderRegionSelectView = () => (
|
||||||
<>
|
<>
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text>{t('Select API-KEY configuration mode:')}</Text>
|
<Text color={theme.text.primary}>
|
||||||
</Box>
|
{t('Choose based on where your account is registered')}
|
||||||
<Box marginTop={1}>
|
|
||||||
<RadioButtonSelect
|
|
||||||
items={apiKeySubItems}
|
|
||||||
initialIndex={apiKeySubModeIndex}
|
|
||||||
onSelect={handleApiKeySubSelect}
|
|
||||||
onHighlight={(value) => {
|
|
||||||
const index = apiKeySubItems.findIndex(
|
|
||||||
(item) => item.value === value,
|
|
||||||
);
|
|
||||||
setApiKeySubModeIndex(index);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<Box marginTop={1} paddingLeft={2}>
|
|
||||||
<Text color={theme.text.secondary}>
|
|
||||||
{apiKeySubItems[apiKeySubModeIndex]?.value === 'custom'
|
|
||||||
? t(
|
|
||||||
'More instructions about configuring `modelProviders` manually.',
|
|
||||||
)
|
|
||||||
: t(
|
|
||||||
"Paste your api key of Bailian Coding Plan and you're all set!",
|
|
||||||
)}
|
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
|
<Box marginTop={1}>
|
||||||
|
<DescriptiveRadioButtonSelect
|
||||||
|
items={regionItems}
|
||||||
|
initialIndex={regionIndex}
|
||||||
|
onSelect={handleRegionSelect}
|
||||||
|
onHighlight={(value) => {
|
||||||
|
const index = regionItems.findIndex((item) => item.value === value);
|
||||||
|
setRegionIndex(index);
|
||||||
|
}}
|
||||||
|
itemGap={1}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text color={theme?.text?.secondary}>
|
<Text color={theme?.text?.secondary}>
|
||||||
{t('(Press Escape to go back)')}
|
{t('Enter to select, ↑↓ to navigate, Esc to go back')}
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
|
|
@ -291,68 +308,22 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
const renderCustomInfoView = () => (
|
const renderCustomInfoView = () => (
|
||||||
<>
|
<>
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text bold>{t('Custom API-KEY Configuration')}</Text>
|
<Text color={theme.text.primary}>
|
||||||
</Box>
|
{t('You can configure your API key and models in settings.json')}
|
||||||
<Box marginTop={1}>
|
|
||||||
<Text>
|
|
||||||
{t('For advanced users who want to configure models manually.')}
|
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text>{t('Please configure your models in settings.json:')}</Text>
|
<Text>{t('Refer to the documentation for setup instructions')}</Text>
|
||||||
</Box>
|
|
||||||
<Box marginTop={1} paddingLeft={2}>
|
|
||||||
<Text color={theme.status.warning}>
|
|
||||||
1. {t('Set API key via environment variable (e.g., OPENAI_API_KEY)')}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
<Box marginTop={0} paddingLeft={2}>
|
|
||||||
<Text color={theme.status.warning}>
|
|
||||||
2.{' '}
|
|
||||||
{t(
|
|
||||||
"Add model configuration to modelProviders['openai'] (or other auth types)",
|
|
||||||
)}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
<Box marginTop={0} paddingLeft={2}>
|
|
||||||
<Text color={theme.status.warning}>
|
|
||||||
3.{' '}
|
|
||||||
{t(
|
|
||||||
'Each provider needs: id, envKey (required), plus optional baseUrl, generationConfig',
|
|
||||||
)}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
<Box marginTop={0} paddingLeft={2}>
|
|
||||||
<Text color={theme.status.warning}>
|
|
||||||
4.{' '}
|
|
||||||
{t(
|
|
||||||
'Use /model command to select your preferred model from the configured list',
|
|
||||||
)}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
<Box marginTop={1}>
|
|
||||||
<Text color={theme?.text?.secondary}>
|
|
||||||
{t(
|
|
||||||
'Supported auth types: openai, anthropic, gemini, vertex-ai, etc.',
|
|
||||||
)}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
<Box marginTop={1}>
|
|
||||||
<Text color={theme?.text?.secondary} underline>
|
|
||||||
{t('More instructions please check:')}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
</Box>
|
||||||
<Box marginTop={0}>
|
<Box marginTop={0}>
|
||||||
<Link url={MODEL_PROVIDERS_DOCUMENTATION_URL} fallback={false}>
|
<Link url={MODEL_PROVIDERS_DOCUMENTATION_URL} fallback={false}>
|
||||||
<Text color={theme.status.success} underline>
|
<Text color={theme.text.link}>
|
||||||
{MODEL_PROVIDERS_DOCUMENTATION_URL}
|
{MODEL_PROVIDERS_DOCUMENTATION_URL}
|
||||||
</Text>
|
</Text>
|
||||||
</Link>
|
</Link>
|
||||||
</Box>
|
</Box>
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text color={theme?.text?.secondary}>
|
<Text color={theme.text.secondary}>{t('Esc to go back')}</Text>
|
||||||
{t('(Press Escape to go back)')}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
@ -360,15 +331,15 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
const getViewTitle = () => {
|
const getViewTitle = () => {
|
||||||
switch (viewLevel) {
|
switch (viewLevel) {
|
||||||
case 'main':
|
case 'main':
|
||||||
return t('Get started');
|
return t('Select Authentication Method');
|
||||||
case 'api-key-sub':
|
case 'region-select':
|
||||||
return t('API-KEY Configuration');
|
return t('Select Region for Coding Plan');
|
||||||
case 'api-key-input':
|
case 'api-key-input':
|
||||||
return t('Coding Plan Setup');
|
return t('Enter Coding Plan API Key');
|
||||||
case 'custom-info':
|
case 'custom-info':
|
||||||
return t('Custom Configuration');
|
return t('Custom Configuration');
|
||||||
default:
|
default:
|
||||||
return t('Get started');
|
return t('Select Authentication Method');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -383,7 +354,7 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
<Text bold>{getViewTitle()}</Text>
|
<Text bold>{getViewTitle()}</Text>
|
||||||
|
|
||||||
{viewLevel === 'main' && renderMainView()}
|
{viewLevel === 'main' && renderMainView()}
|
||||||
{viewLevel === 'api-key-sub' && renderApiKeySubView()}
|
{viewLevel === 'region-select' && renderRegionSelectView()}
|
||||||
{viewLevel === 'api-key-input' && renderApiKeyInputView()}
|
{viewLevel === 'api-key-input' && renderApiKeyInputView()}
|
||||||
{viewLevel === 'custom-info' && renderCustomInfoView()}
|
{viewLevel === 'custom-info' && renderCustomInfoView()}
|
||||||
|
|
||||||
|
|
@ -395,31 +366,28 @@ export function AuthDialog(): React.JSX.Element {
|
||||||
|
|
||||||
{viewLevel === 'main' && (
|
{viewLevel === 'main' && (
|
||||||
<>
|
<>
|
||||||
<Box marginTop={1}>
|
{/* <Box marginTop={1}>
|
||||||
<Text color={theme.text.accent}>
|
<Text color={theme.text.secondary}>
|
||||||
{t('(Use Enter to Set Auth)')}
|
{t('Enter to select, \u2191\u2193 to navigate, Esc to close')}
|
||||||
|
</Text>
|
||||||
|
</Box> */}
|
||||||
|
<Box marginY={1}>
|
||||||
|
<Text color={theme.border.default}>{'\u2500'.repeat(80)}</Text>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text color={theme.text.primary}>
|
||||||
|
{t('Terms of Services and Privacy Notice')}:
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
{hasApiKey && currentSelectedAuthType === AuthType.QWEN_OAUTH && (
|
<Box>
|
||||||
<Box marginTop={1}>
|
<Link
|
||||||
<Text color={theme?.text?.secondary}>
|
url="https://qwenlm.github.io/qwen-code-docs/en/users/support/tos-privacy/"
|
||||||
{t(
|
fallback={false}
|
||||||
'Note: Your existing API key in settings.json will not be cleared when using Qwen OAuth. You can switch back to OpenAI authentication later if needed.',
|
>
|
||||||
)}
|
<Text color={theme.text.secondary} underline>
|
||||||
|
https://qwenlm.github.io/qwen-code-docs/en/users/support/tos-privacy/
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Link>
|
||||||
)}
|
|
||||||
<Box marginTop={1}>
|
|
||||||
<Text>
|
|
||||||
{t('Terms of Services and Privacy Notice for Qwen Code')}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
<Box marginTop={1}>
|
|
||||||
<Text color={theme.text.link}>
|
|
||||||
{
|
|
||||||
'https://qwenlm.github.io/qwen-code-docs/en/users/support/tos-privacy/'
|
|
||||||
}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import {
|
||||||
CodingPlanRegion,
|
CodingPlanRegion,
|
||||||
CODING_PLAN_ENV_KEY,
|
CODING_PLAN_ENV_KEY,
|
||||||
} from '../../constants/codingPlan.js';
|
} from '../../constants/codingPlan.js';
|
||||||
|
import { backupSettingsFile } from '../../utils/settingsUtils.js';
|
||||||
|
|
||||||
export type { QwenAuthState } from '../hooks/useQwenAuth.js';
|
export type { QwenAuthState } from '../hooks/useQwenAuth.js';
|
||||||
|
|
||||||
|
|
@ -299,11 +300,15 @@ export const useAuthCommand = (
|
||||||
setAuthError(null);
|
setAuthError(null);
|
||||||
|
|
||||||
// Get configuration based on region
|
// Get configuration based on region
|
||||||
const { template, version, regionName } = getCodingPlanConfig(region);
|
const { template, version } = getCodingPlanConfig(region);
|
||||||
|
|
||||||
// Get persist scope
|
// Get persist scope
|
||||||
const persistScope = getPersistScopeForModelSelection(settings);
|
const persistScope = getPersistScopeForModelSelection(settings);
|
||||||
|
|
||||||
|
// Backup settings file before modification
|
||||||
|
const settingsFile = settings.forScope(persistScope);
|
||||||
|
backupSettingsFile(settingsFile.path);
|
||||||
|
|
||||||
// Store api-key in settings.env (unified env key)
|
// Store api-key in settings.env (unified env key)
|
||||||
settings.setValue(persistScope, `env.${CODING_PLAN_ENV_KEY}`, apiKey);
|
settings.setValue(persistScope, `env.${CODING_PLAN_ENV_KEY}`, apiKey);
|
||||||
|
|
||||||
|
|
@ -384,8 +389,8 @@ export const useAuthCommand = (
|
||||||
{
|
{
|
||||||
type: MessageType.INFO,
|
type: MessageType.INFO,
|
||||||
text: t(
|
text: t(
|
||||||
'Authenticated successfully with {{region}}. API key is stored in settings.env.',
|
'Authenticated successfully with {{region}}. API key and model configs saved to settings.json (backed up).',
|
||||||
{ region: regionName },
|
{ region: t('Alibaba Cloud Coding Plan') },
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Date.now(),
|
Date.now(),
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export const compressCommand: SlashCommand = {
|
||||||
action: async (context) => {
|
action: async (context) => {
|
||||||
const { ui } = context;
|
const { ui } = context;
|
||||||
const executionMode = context.executionMode ?? 'interactive';
|
const executionMode = context.executionMode ?? 'interactive';
|
||||||
|
const abortSignal = context.abortSignal;
|
||||||
|
|
||||||
if (executionMode === 'interactive' && ui.pendingItem) {
|
if (executionMode === 'interactive' && ui.pendingItem) {
|
||||||
ui.addItem(
|
ui.addItem(
|
||||||
|
|
@ -96,6 +97,10 @@ export const compressCommand: SlashCommand = {
|
||||||
|
|
||||||
const compressed = await doCompress();
|
const compressed = await doCompress();
|
||||||
|
|
||||||
|
if (abortSignal?.aborted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!compressed) {
|
if (!compressed) {
|
||||||
if (executionMode === 'interactive') {
|
if (executionMode === 'interactive') {
|
||||||
ui.addItem(
|
ui.addItem(
|
||||||
|
|
@ -137,6 +142,10 @@ export const compressCommand: SlashCommand = {
|
||||||
content: `Context compressed (${compressed.originalTokenCount} -> ${compressed.newTokenCount}).`,
|
content: `Context compressed (${compressed.originalTokenCount} -> ${compressed.newTokenCount}).`,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// If cancelled via ESC, don't show error — cancelSlashCommand already handled UI
|
||||||
|
if (abortSignal?.aborted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (executionMode === 'interactive') {
|
if (executionMode === 'interactive') {
|
||||||
ui.addItem(
|
ui.addItem(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
322
packages/cli/src/ui/commands/hooksCommand.ts
Normal file
322
packages/cli/src/ui/commands/hooksCommand.ts
Normal file
|
|
@ -0,0 +1,322 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type {
|
||||||
|
SlashCommand,
|
||||||
|
SlashCommandActionReturn,
|
||||||
|
CommandContext,
|
||||||
|
MessageActionReturn,
|
||||||
|
} from './types.js';
|
||||||
|
import { CommandKind } from './types.js';
|
||||||
|
import { t } from '../../i18n/index.js';
|
||||||
|
import type { HookRegistryEntry } from '@qwen-code/qwen-code-core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format hook source for display
|
||||||
|
*/
|
||||||
|
function formatHookSource(source: string): string {
|
||||||
|
switch (source) {
|
||||||
|
case 'project':
|
||||||
|
return 'Project';
|
||||||
|
case 'user':
|
||||||
|
return 'User';
|
||||||
|
case 'system':
|
||||||
|
return 'System';
|
||||||
|
case 'extensions':
|
||||||
|
return 'Extension';
|
||||||
|
default:
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format hook status for display
|
||||||
|
*/
|
||||||
|
function formatHookStatus(enabled: boolean): string {
|
||||||
|
return enabled ? '✓ Enabled' : '✗ Disabled';
|
||||||
|
}
|
||||||
|
|
||||||
|
const listCommand: SlashCommand = {
|
||||||
|
name: 'list',
|
||||||
|
get description() {
|
||||||
|
return t('List all configured hooks');
|
||||||
|
},
|
||||||
|
kind: CommandKind.BUILT_IN,
|
||||||
|
action: async (
|
||||||
|
context: CommandContext,
|
||||||
|
_args: string,
|
||||||
|
): Promise<MessageActionReturn> => {
|
||||||
|
const { config } = context.services;
|
||||||
|
if (!config) {
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'error',
|
||||||
|
content: t('Config not loaded.'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const hookSystem = config.getHookSystem();
|
||||||
|
if (!hookSystem) {
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'info',
|
||||||
|
content: t(
|
||||||
|
'Hooks are not enabled. Enable hooks in settings to use this feature.',
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const registry = hookSystem.getRegistry();
|
||||||
|
const allHooks = registry.getAllHooks();
|
||||||
|
|
||||||
|
if (allHooks.length === 0) {
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'info',
|
||||||
|
content: t(
|
||||||
|
'No hooks configured. Add hooks in your settings.json file.',
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group hooks by event
|
||||||
|
const hooksByEvent = new Map<string, HookRegistryEntry[]>();
|
||||||
|
for (const hook of allHooks) {
|
||||||
|
const eventName = hook.eventName;
|
||||||
|
if (!hooksByEvent.has(eventName)) {
|
||||||
|
hooksByEvent.set(eventName, []);
|
||||||
|
}
|
||||||
|
hooksByEvent.get(eventName)!.push(hook);
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = `**Configured Hooks (${allHooks.length} total)**\n\n`;
|
||||||
|
|
||||||
|
for (const [eventName, hooks] of hooksByEvent) {
|
||||||
|
output += `### ${eventName}\n`;
|
||||||
|
for (const hook of hooks) {
|
||||||
|
const name = hook.config.name || hook.config.command || 'unnamed';
|
||||||
|
const source = formatHookSource(hook.source);
|
||||||
|
const status = formatHookStatus(hook.enabled);
|
||||||
|
const matcher = hook.matcher ? ` (matcher: ${hook.matcher})` : '';
|
||||||
|
output += `- **${name}** [${source}] ${status}${matcher}\n`;
|
||||||
|
}
|
||||||
|
output += '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'info',
|
||||||
|
content: output,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const enableCommand: SlashCommand = {
|
||||||
|
name: 'enable',
|
||||||
|
get description() {
|
||||||
|
return t('Enable a disabled hook');
|
||||||
|
},
|
||||||
|
kind: CommandKind.BUILT_IN,
|
||||||
|
action: async (
|
||||||
|
context: CommandContext,
|
||||||
|
args: string,
|
||||||
|
): Promise<MessageActionReturn> => {
|
||||||
|
const hookName = args.trim();
|
||||||
|
if (!hookName) {
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'error',
|
||||||
|
content: t(
|
||||||
|
'Please specify a hook name. Usage: /hooks enable <hook-name>',
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const { config } = context.services;
|
||||||
|
if (!config) {
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'error',
|
||||||
|
content: t('Config not loaded.'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const hookSystem = config.getHookSystem();
|
||||||
|
if (!hookSystem) {
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'error',
|
||||||
|
content: t('Hooks are not enabled.'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const registry = hookSystem.getRegistry();
|
||||||
|
registry.setHookEnabled(hookName, true);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'info',
|
||||||
|
content: t('Hook "{{name}}" has been enabled for this session.', {
|
||||||
|
name: hookName,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
completion: async (context: CommandContext, partialArg: string) => {
|
||||||
|
const { config } = context.services;
|
||||||
|
if (!config) return [];
|
||||||
|
|
||||||
|
const hookSystem = config.getHookSystem();
|
||||||
|
if (!hookSystem) return [];
|
||||||
|
|
||||||
|
const registry = hookSystem.getRegistry();
|
||||||
|
const allHooks = registry.getAllHooks();
|
||||||
|
|
||||||
|
// Return disabled hooks for enable command (deduplicated by name)
|
||||||
|
const disabledHookNames = allHooks
|
||||||
|
.filter((hook) => !hook.enabled)
|
||||||
|
.map((hook) => hook.config.name || hook.config.command || '')
|
||||||
|
.filter((name) => name && name.startsWith(partialArg));
|
||||||
|
return [...new Set(disabledHookNames)];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const disableCommand: SlashCommand = {
|
||||||
|
name: 'disable',
|
||||||
|
get description() {
|
||||||
|
return t('Disable an active hook');
|
||||||
|
},
|
||||||
|
kind: CommandKind.BUILT_IN,
|
||||||
|
action: async (
|
||||||
|
context: CommandContext,
|
||||||
|
args: string,
|
||||||
|
): Promise<MessageActionReturn> => {
|
||||||
|
const hookName = args.trim();
|
||||||
|
if (!hookName) {
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'error',
|
||||||
|
content: t(
|
||||||
|
'Please specify a hook name. Usage: /hooks disable <hook-name>',
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const { config } = context.services;
|
||||||
|
if (!config) {
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'error',
|
||||||
|
content: t('Config not loaded.'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const hookSystem = config.getHookSystem();
|
||||||
|
if (!hookSystem) {
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'error',
|
||||||
|
content: t('Hooks are not enabled.'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const registry = hookSystem.getRegistry();
|
||||||
|
registry.setHookEnabled(hookName, false);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'info',
|
||||||
|
content: t('Hook "{{name}}" has been disabled for this session.', {
|
||||||
|
name: hookName,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
completion: async (context: CommandContext, partialArg: string) => {
|
||||||
|
const { config } = context.services;
|
||||||
|
if (!config) return [];
|
||||||
|
|
||||||
|
const hookSystem = config.getHookSystem();
|
||||||
|
if (!hookSystem) return [];
|
||||||
|
|
||||||
|
const registry = hookSystem.getRegistry();
|
||||||
|
const allHooks = registry.getAllHooks();
|
||||||
|
|
||||||
|
// Return enabled hooks for disable command (deduplicated by name)
|
||||||
|
const enabledHookNames = allHooks
|
||||||
|
.filter((hook) => hook.enabled)
|
||||||
|
.map((hook) => hook.config.name || hook.config.command || '')
|
||||||
|
.filter((name) => name && name.startsWith(partialArg));
|
||||||
|
return [...new Set(enabledHookNames)];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const hooksCommand: SlashCommand = {
|
||||||
|
name: 'hooks',
|
||||||
|
get description() {
|
||||||
|
return t('Manage Qwen Code hooks');
|
||||||
|
},
|
||||||
|
kind: CommandKind.BUILT_IN,
|
||||||
|
subCommands: [listCommand, enableCommand, disableCommand],
|
||||||
|
action: async (
|
||||||
|
context: CommandContext,
|
||||||
|
args: string,
|
||||||
|
): Promise<SlashCommandActionReturn> => {
|
||||||
|
// If no subcommand provided, show list
|
||||||
|
if (!args.trim()) {
|
||||||
|
const result = await listCommand.action?.(context, '');
|
||||||
|
return result ?? { type: 'message', messageType: 'info', content: '' };
|
||||||
|
}
|
||||||
|
|
||||||
|
const [subcommand, ...rest] = args.trim().split(/\s+/);
|
||||||
|
const subArgs = rest.join(' ');
|
||||||
|
|
||||||
|
let result: SlashCommandActionReturn | void;
|
||||||
|
switch (subcommand.toLowerCase()) {
|
||||||
|
case 'list':
|
||||||
|
result = await listCommand.action?.(context, subArgs);
|
||||||
|
break;
|
||||||
|
case 'enable':
|
||||||
|
result = await enableCommand.action?.(context, subArgs);
|
||||||
|
break;
|
||||||
|
case 'disable':
|
||||||
|
result = await disableCommand.action?.(context, subArgs);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
type: 'message',
|
||||||
|
messageType: 'error',
|
||||||
|
content: t(
|
||||||
|
'Unknown subcommand: {{cmd}}. Available: list, enable, disable',
|
||||||
|
{
|
||||||
|
cmd: subcommand,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return result ?? { type: 'message', messageType: 'info', content: '' };
|
||||||
|
},
|
||||||
|
completion: async (context: CommandContext, partialArg: string) => {
|
||||||
|
const subcommands = ['list', 'enable', 'disable'];
|
||||||
|
const parts = partialArg.split(/\s+/);
|
||||||
|
|
||||||
|
if (parts.length <= 1) {
|
||||||
|
// Complete subcommand
|
||||||
|
return subcommands.filter((cmd) => cmd.startsWith(partialArg));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Complete subcommand arguments
|
||||||
|
const [subcommand, ...rest] = parts;
|
||||||
|
const subArgs = rest.join(' ');
|
||||||
|
|
||||||
|
switch (subcommand.toLowerCase()) {
|
||||||
|
case 'enable':
|
||||||
|
return enableCommand.completion?.(context, subArgs) ?? [];
|
||||||
|
case 'disable':
|
||||||
|
return disableCommand.completion?.(context, subArgs) ?? [];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
132
packages/cli/src/ui/commands/insightCommand.ts
Normal file
132
packages/cli/src/ui/commands/insightCommand.ts
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Qwen Code
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { CommandContext, SlashCommand } from './types.js';
|
||||||
|
import { CommandKind } from './types.js';
|
||||||
|
import { MessageType } from '../types.js';
|
||||||
|
import type { HistoryItemInsightProgress } from '../types.js';
|
||||||
|
import { t } from '../../i18n/index.js';
|
||||||
|
import { join } from 'path';
|
||||||
|
import os from 'os';
|
||||||
|
import { StaticInsightGenerator } from '../../services/insight/generators/StaticInsightGenerator.js';
|
||||||
|
import { createDebugLogger } from '@qwen-code/qwen-code-core';
|
||||||
|
import open from 'open';
|
||||||
|
|
||||||
|
const logger = createDebugLogger('DataProcessor');
|
||||||
|
|
||||||
|
export const insightCommand: SlashCommand = {
|
||||||
|
name: 'insight',
|
||||||
|
get description() {
|
||||||
|
return t(
|
||||||
|
'generate personalized programming insights from your chat history',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
kind: CommandKind.BUILT_IN,
|
||||||
|
action: async (context: CommandContext) => {
|
||||||
|
try {
|
||||||
|
context.ui.setDebugMessage(t('Generating insights...'));
|
||||||
|
|
||||||
|
const projectsDir = join(os.homedir(), '.qwen', 'projects');
|
||||||
|
if (!context.services.config) {
|
||||||
|
throw new Error('Config service is not available');
|
||||||
|
}
|
||||||
|
const insightGenerator = new StaticInsightGenerator(
|
||||||
|
context.services.config,
|
||||||
|
);
|
||||||
|
|
||||||
|
const updateProgress = (
|
||||||
|
stage: string,
|
||||||
|
progress: number,
|
||||||
|
detail?: string,
|
||||||
|
) => {
|
||||||
|
const progressItem: HistoryItemInsightProgress = {
|
||||||
|
type: MessageType.INSIGHT_PROGRESS,
|
||||||
|
progress: {
|
||||||
|
stage,
|
||||||
|
progress,
|
||||||
|
detail,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
context.ui.setPendingItem(progressItem);
|
||||||
|
};
|
||||||
|
|
||||||
|
context.ui.addItem(
|
||||||
|
{
|
||||||
|
type: MessageType.INFO,
|
||||||
|
text: t('This may take a couple minutes. Sit tight!'),
|
||||||
|
},
|
||||||
|
Date.now(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Initial progress
|
||||||
|
updateProgress(t('Starting insight generation...'), 0);
|
||||||
|
|
||||||
|
// Generate the static insight HTML file
|
||||||
|
const outputPath = await insightGenerator.generateStaticInsight(
|
||||||
|
projectsDir,
|
||||||
|
updateProgress,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Clear pending item
|
||||||
|
context.ui.setPendingItem(null);
|
||||||
|
|
||||||
|
context.ui.addItem(
|
||||||
|
{
|
||||||
|
type: MessageType.INFO,
|
||||||
|
text: t('Insight report generated successfully!'),
|
||||||
|
},
|
||||||
|
Date.now(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Open the file in the default browser
|
||||||
|
try {
|
||||||
|
await open(outputPath);
|
||||||
|
|
||||||
|
context.ui.addItem(
|
||||||
|
{
|
||||||
|
type: MessageType.INFO,
|
||||||
|
text: t('Opening insights in your browser: {{path}}', {
|
||||||
|
path: outputPath,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
Date.now(),
|
||||||
|
);
|
||||||
|
} catch (browserError) {
|
||||||
|
logger.error('Failed to open browser automatically:', browserError);
|
||||||
|
|
||||||
|
context.ui.addItem(
|
||||||
|
{
|
||||||
|
type: MessageType.INFO,
|
||||||
|
text: t(
|
||||||
|
'Insights generated at: {{path}}. Please open this file in your browser.',
|
||||||
|
{
|
||||||
|
path: outputPath,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
Date.now(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.ui.setDebugMessage(t('Insights ready.'));
|
||||||
|
} catch (error) {
|
||||||
|
// Clear pending item on error
|
||||||
|
context.ui.setPendingItem(null);
|
||||||
|
|
||||||
|
context.ui.addItem(
|
||||||
|
{
|
||||||
|
type: MessageType.ERROR,
|
||||||
|
text: t('Failed to generate insights: {{error}}', {
|
||||||
|
error: (error as Error).message,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
Date.now(),
|
||||||
|
);
|
||||||
|
|
||||||
|
logger.error('Insight generation error:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
@ -104,6 +104,15 @@ export const setupGithubCommand: SlashCommand = {
|
||||||
): Promise<SlashCommandActionReturn> => {
|
): Promise<SlashCommandActionReturn> => {
|
||||||
const abortController = new AbortController();
|
const abortController = new AbortController();
|
||||||
|
|
||||||
|
// If we have a context abort signal (from ESC cancellation), link it to our controller
|
||||||
|
if (context.abortSignal) {
|
||||||
|
context.abortSignal.addEventListener(
|
||||||
|
'abort',
|
||||||
|
() => abortController.abort(),
|
||||||
|
{ once: true },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isGitHubRepository()) {
|
if (!isGitHubRepository()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Unable to determine the GitHub repository. /setup-github must be run from a git repository.',
|
'Unable to determine the GitHub repository. /setup-github must be run from a git repository.',
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ export const summaryCommand: SlashCommand = {
|
||||||
const { config } = context.services;
|
const { config } = context.services;
|
||||||
const { ui } = context;
|
const { ui } = context;
|
||||||
const executionMode = context.executionMode ?? 'interactive';
|
const executionMode = context.executionMode ?? 'interactive';
|
||||||
|
const abortSignal = context.abortSignal;
|
||||||
|
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return {
|
return {
|
||||||
|
|
@ -101,7 +102,7 @@ export const summaryCommand: SlashCommand = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{},
|
{},
|
||||||
new AbortController().signal,
|
abortSignal ?? new AbortController().signal,
|
||||||
config.getModel(),
|
config.getModel(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -197,6 +198,10 @@ export const summaryCommand: SlashCommand = {
|
||||||
if (executionMode !== 'interactive') {
|
if (executionMode !== 'interactive') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// If cancelled via ESC, don't show error — cancelSlashCommand already handled UI
|
||||||
|
if (abortSignal?.aborted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ui.setPendingItem(null);
|
ui.setPendingItem(null);
|
||||||
ui.addItem(
|
ui.addItem(
|
||||||
{
|
{
|
||||||
|
|
@ -241,6 +246,9 @@ export const summaryCommand: SlashCommand = {
|
||||||
}> => {
|
}> => {
|
||||||
emitInteractivePending('generating');
|
emitInteractivePending('generating');
|
||||||
const markdownSummary = await generateSummaryMarkdown(history);
|
const markdownSummary = await generateSummaryMarkdown(history);
|
||||||
|
if (abortSignal?.aborted) {
|
||||||
|
throw new DOMException('Summary generation cancelled.', 'AbortError');
|
||||||
|
}
|
||||||
emitInteractivePending('saving');
|
emitInteractivePending('saving');
|
||||||
const { filePathForDisplay } = await saveSummaryToDisk(markdownSummary);
|
const { filePathForDisplay } = await saveSummaryToDisk(markdownSummary);
|
||||||
completeInteractive(filePathForDisplay);
|
completeInteractive(filePathForDisplay);
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,8 @@ export interface CommandContext {
|
||||||
};
|
};
|
||||||
// Flag to indicate if an overwrite has been confirmed
|
// Flag to indicate if an overwrite has been confirmed
|
||||||
overwriteConfirmed?: boolean;
|
overwriteConfirmed?: boolean;
|
||||||
|
/** Abort signal for cancelling long-running slash command operations via ESC. */
|
||||||
|
abortSignal?: AbortSignal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,18 @@ export function ApiKeyInput({
|
||||||
setError(t('API key cannot be empty.'));
|
setError(t('API key cannot be empty.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Only validate sk-sp- prefix for China region (aliyun.com)
|
||||||
|
if (
|
||||||
|
region === CodingPlanRegion.CHINA &&
|
||||||
|
!trimmedKey.startsWith('sk-sp-')
|
||||||
|
) {
|
||||||
|
setError(
|
||||||
|
t(
|
||||||
|
'Invalid API key. Coding Plan API keys start with "sk-sp-". Please check.',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
onSubmit(trimmedKey);
|
onSubmit(trimmedKey);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -57,9 +69,6 @@ export function ApiKeyInput({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
<Box marginBottom={1}>
|
|
||||||
<Text>{t('Please enter your API key:')}</Text>
|
|
||||||
</Box>
|
|
||||||
<TextInput value={apiKey} onChange={setApiKey} placeholder="sk-sp-..." />
|
<TextInput value={apiKey} onChange={setApiKey} placeholder="sk-sp-..." />
|
||||||
{error && (
|
{error && (
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
|
|
@ -67,18 +76,18 @@ export function ApiKeyInput({
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text>{t('You can get your exclusive Coding Plan API-KEY here:')}</Text>
|
<Text>{t('You can get your Coding Plan API key here')}</Text>
|
||||||
</Box>
|
</Box>
|
||||||
<Box marginTop={0}>
|
<Box marginTop={0}>
|
||||||
<Link url={apiKeyUrl} fallback={false}>
|
<Link url={apiKeyUrl} fallback={false}>
|
||||||
<Text color={theme.status.success} underline>
|
<Text color={theme.text.link} underline>
|
||||||
{apiKeyUrl}
|
{apiKeyUrl}
|
||||||
</Text>
|
</Text>
|
||||||
</Link>
|
</Link>
|
||||||
</Box>
|
</Box>
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text color={theme.text.secondary}>
|
<Text color={theme.text.secondary}>
|
||||||
{t('(Press Enter to submit, Escape to cancel)')}
|
{t('Enter to submit, Esc to go back')}
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,43 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Box } from 'ink';
|
import { Box } from 'ink';
|
||||||
import { Header } from './Header.js';
|
import { AuthType } from '@qwen-code/qwen-code-core';
|
||||||
|
import { Header, AuthDisplayType } from './Header.js';
|
||||||
import { Tips } from './Tips.js';
|
import { Tips } from './Tips.js';
|
||||||
import { useSettings } from '../contexts/SettingsContext.js';
|
import { useSettings } from '../contexts/SettingsContext.js';
|
||||||
import { useConfig } from '../contexts/ConfigContext.js';
|
import { useConfig } from '../contexts/ConfigContext.js';
|
||||||
import { useUIState } from '../contexts/UIStateContext.js';
|
import { useUIState } from '../contexts/UIStateContext.js';
|
||||||
|
import { isCodingPlanConfig } from '../../constants/codingPlan.js';
|
||||||
|
|
||||||
interface AppHeaderProps {
|
interface AppHeaderProps {
|
||||||
version: string;
|
version: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the auth display type based on auth type and configuration.
|
||||||
|
*/
|
||||||
|
function getAuthDisplayType(
|
||||||
|
authType?: AuthType,
|
||||||
|
baseUrl?: string,
|
||||||
|
apiKeyEnvKey?: string,
|
||||||
|
): AuthDisplayType {
|
||||||
|
if (!authType) {
|
||||||
|
return AuthDisplayType.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's a Coding Plan config
|
||||||
|
if (isCodingPlanConfig(baseUrl, apiKeyEnvKey)) {
|
||||||
|
return AuthDisplayType.CODING_PLAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (authType) {
|
||||||
|
case AuthType.QWEN_OAUTH:
|
||||||
|
return AuthDisplayType.QWEN_OAUTH;
|
||||||
|
default:
|
||||||
|
return AuthDisplayType.API_KEY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const AppHeader = ({ version }: AppHeaderProps) => {
|
export const AppHeader = ({ version }: AppHeaderProps) => {
|
||||||
const settings = useSettings();
|
const settings = useSettings();
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
|
|
@ -27,12 +54,18 @@ export const AppHeader = ({ version }: AppHeaderProps) => {
|
||||||
const showBanner = !config.getScreenReader();
|
const showBanner = !config.getScreenReader();
|
||||||
const showTips = !(settings.merged.ui?.hideTips || config.getScreenReader());
|
const showTips = !(settings.merged.ui?.hideTips || config.getScreenReader());
|
||||||
|
|
||||||
|
const authDisplayType = getAuthDisplayType(
|
||||||
|
authType,
|
||||||
|
contentGeneratorConfig?.baseUrl,
|
||||||
|
contentGeneratorConfig?.apiKeyEnvKey,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
{showBanner && (
|
{showBanner && (
|
||||||
<Header
|
<Header
|
||||||
version={version}
|
version={version}
|
||||||
authType={authType}
|
authDisplayType={authDisplayType}
|
||||||
model={model}
|
model={model}
|
||||||
workingDirectory={targetDir}
|
workingDirectory={targetDir}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ const createMockUIState = (overrides: Partial<UIState> = {}): UIState =>
|
||||||
const createMockUIActions = (): UIActions =>
|
const createMockUIActions = (): UIActions =>
|
||||||
({
|
({
|
||||||
handleFinalSubmit: vi.fn(),
|
handleFinalSubmit: vi.fn(),
|
||||||
|
handleRetryLastPrompt: vi.fn(),
|
||||||
handleClearScreen: vi.fn(),
|
handleClearScreen: vi.fn(),
|
||||||
setShellModeActive: vi.fn(),
|
setShellModeActive: vi.fn(),
|
||||||
onEscapePromptChange: vi.fn(),
|
onEscapePromptChange: vi.fn(),
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import process from 'node:process';
|
||||||
import { type UseHistoryManagerReturn } from '../hooks/useHistoryManager.js';
|
import { type UseHistoryManagerReturn } from '../hooks/useHistoryManager.js';
|
||||||
import { IdeTrustChangeDialog } from './IdeTrustChangeDialog.js';
|
import { IdeTrustChangeDialog } from './IdeTrustChangeDialog.js';
|
||||||
import { WelcomeBackDialog } from './WelcomeBackDialog.js';
|
import { WelcomeBackDialog } from './WelcomeBackDialog.js';
|
||||||
import { ModelSwitchDialog } from './ModelSwitchDialog.js';
|
|
||||||
import { AgentCreationWizard } from './subagents/create/AgentCreationWizard.js';
|
import { AgentCreationWizard } from './subagents/create/AgentCreationWizard.js';
|
||||||
import { AgentsManagerDialog } from './subagents/manage/AgentsManagerDialog.js';
|
import { AgentsManagerDialog } from './subagents/manage/AgentsManagerDialog.js';
|
||||||
import { MCPManagementDialog } from './mcp/MCPManagementDialog.js';
|
import { MCPManagementDialog } from './mcp/MCPManagementDialog.js';
|
||||||
|
|
@ -237,10 +236,6 @@ export const DialogManager = ({
|
||||||
if (uiState.isModelDialogOpen) {
|
if (uiState.isModelDialogOpen) {
|
||||||
return <ModelDialog onClose={uiActions.closeModelDialog} />;
|
return <ModelDialog onClose={uiActions.closeModelDialog} />;
|
||||||
}
|
}
|
||||||
if (uiState.isVisionSwitchDialogOpen) {
|
|
||||||
return <ModelSwitchDialog onSelect={uiActions.handleVisionSwitchSelect} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uiState.isAuthDialogOpen || uiState.authError) {
|
if (uiState.isAuthDialogOpen || uiState.authError) {
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
import { render } from 'ink-testing-library';
|
import { render } from 'ink-testing-library';
|
||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { AuthType } from '@qwen-code/qwen-code-core';
|
import { Header, AuthDisplayType } from './Header.js';
|
||||||
import { Header } from './Header.js';
|
|
||||||
import * as useTerminalSize from '../hooks/useTerminalSize.js';
|
import * as useTerminalSize from '../hooks/useTerminalSize.js';
|
||||||
|
|
||||||
vi.mock('../hooks/useTerminalSize.js');
|
vi.mock('../hooks/useTerminalSize.js');
|
||||||
|
|
@ -15,86 +14,70 @@ const useTerminalSizeMock = vi.mocked(useTerminalSize.useTerminalSize);
|
||||||
|
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
authType: AuthType.QWEN_OAUTH,
|
authDisplayType: AuthDisplayType.QWEN_OAUTH,
|
||||||
model: 'qwen-coder-plus',
|
model: 'qwen-coder-plus',
|
||||||
workingDirectory: '/home/user/projects/test',
|
workingDirectory: '/home/user/projects/test',
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('<Header />', () => {
|
describe('<Header />', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Default to wide terminal (shows both logo and info panel)
|
|
||||||
useTerminalSizeMock.mockReturnValue({ columns: 120, rows: 24 });
|
useTerminalSizeMock.mockReturnValue({ columns: 120, rows: 24 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the ASCII logo on wide terminal', () => {
|
it('renders the ASCII logo on wide terminal', () => {
|
||||||
const { lastFrame } = render(<Header {...defaultProps} />);
|
const { lastFrame } = render(<Header {...defaultProps} />);
|
||||||
// Check that parts of the shortAsciiLogo are rendered
|
|
||||||
expect(lastFrame()).toContain('██╔═══██╗');
|
expect(lastFrame()).toContain('██╔═══██╗');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hides the ASCII logo on narrow terminal', () => {
|
it('hides the ASCII logo on narrow terminal', () => {
|
||||||
useTerminalSizeMock.mockReturnValue({ columns: 60, rows: 24 });
|
useTerminalSizeMock.mockReturnValue({ columns: 60, rows: 24 });
|
||||||
const { lastFrame } = render(<Header {...defaultProps} />);
|
const { lastFrame } = render(<Header {...defaultProps} />);
|
||||||
// Should not contain the logo but still show the info panel
|
|
||||||
expect(lastFrame()).not.toContain('██╔═══██╗');
|
expect(lastFrame()).not.toContain('██╔═══██╗');
|
||||||
expect(lastFrame()).toContain('>_ Qwen Code');
|
expect(lastFrame()).toContain('>_ Qwen Code');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders custom ASCII art when provided on wide terminal', () => {
|
|
||||||
const customArt = 'CUSTOM ART';
|
|
||||||
const { lastFrame } = render(
|
|
||||||
<Header {...defaultProps} customAsciiArt={customArt} />,
|
|
||||||
);
|
|
||||||
expect(lastFrame()).toContain(customArt);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('displays the version number', () => {
|
it('displays the version number', () => {
|
||||||
const { lastFrame } = render(<Header {...defaultProps} />);
|
const { lastFrame } = render(<Header {...defaultProps} />);
|
||||||
expect(lastFrame()).toContain('v1.0.0');
|
expect(lastFrame()).toContain('v1.0.0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays Qwen Code title with >_ prefix', () => {
|
|
||||||
const { lastFrame } = render(<Header {...defaultProps} />);
|
|
||||||
expect(lastFrame()).toContain('>_ Qwen Code');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('displays auth type and model', () => {
|
it('displays auth type and model', () => {
|
||||||
const { lastFrame } = render(<Header {...defaultProps} />);
|
const { lastFrame } = render(<Header {...defaultProps} />);
|
||||||
expect(lastFrame()).toContain('Qwen OAuth');
|
expect(lastFrame()).toContain('Qwen OAuth');
|
||||||
expect(lastFrame()).toContain('qwen-coder-plus');
|
expect(lastFrame()).toContain('qwen-coder-plus');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('displays Coding Plan auth type', () => {
|
||||||
|
const { lastFrame } = render(
|
||||||
|
<Header
|
||||||
|
{...defaultProps}
|
||||||
|
authDisplayType={AuthDisplayType.CODING_PLAN}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(lastFrame()).toContain('Coding Plan');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displays API Key auth type', () => {
|
||||||
|
const { lastFrame } = render(
|
||||||
|
<Header {...defaultProps} authDisplayType={AuthDisplayType.API_KEY} />,
|
||||||
|
);
|
||||||
|
expect(lastFrame()).toContain('API Key');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displays Unknown when auth type is not set', () => {
|
||||||
|
const { lastFrame } = render(
|
||||||
|
<Header {...defaultProps} authDisplayType={undefined} />,
|
||||||
|
);
|
||||||
|
expect(lastFrame()).toContain('Unknown');
|
||||||
|
});
|
||||||
|
|
||||||
it('displays working directory', () => {
|
it('displays working directory', () => {
|
||||||
const { lastFrame } = render(<Header {...defaultProps} />);
|
const { lastFrame } = render(<Header {...defaultProps} />);
|
||||||
expect(lastFrame()).toContain('/home/user/projects/test');
|
expect(lastFrame()).toContain('/home/user/projects/test');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders a custom working directory display', () => {
|
|
||||||
const { lastFrame } = render(
|
|
||||||
<Header {...defaultProps} workingDirectory="custom display" />,
|
|
||||||
);
|
|
||||||
expect(lastFrame()).toContain('custom display');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('displays working directory without branch name', () => {
|
|
||||||
const { lastFrame } = render(<Header {...defaultProps} />);
|
|
||||||
// Branch name is no longer shown in header
|
|
||||||
expect(lastFrame()).toContain('/home/user/projects/test');
|
|
||||||
expect(lastFrame()).not.toContain('(main*)');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('formats home directory with tilde', () => {
|
|
||||||
const { lastFrame } = render(
|
|
||||||
<Header {...defaultProps} workingDirectory="/Users/testuser/projects" />,
|
|
||||||
);
|
|
||||||
// The actual home dir replacement depends on os.homedir()
|
|
||||||
// Just verify the path is shown
|
|
||||||
expect(lastFrame()).toContain('projects');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders with border around info panel', () => {
|
it('renders with border around info panel', () => {
|
||||||
const { lastFrame } = render(<Header {...defaultProps} />);
|
const { lastFrame } = render(<Header {...defaultProps} />);
|
||||||
// Check for border characters (round border style uses these)
|
|
||||||
expect(lastFrame()).toContain('╭');
|
expect(lastFrame()).toContain('╭');
|
||||||
expect(lastFrame()).toContain('╯');
|
expect(lastFrame()).toContain('╯');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,59 +7,35 @@
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { Box, Text } from 'ink';
|
import { Box, Text } from 'ink';
|
||||||
import Gradient from 'ink-gradient';
|
import Gradient from 'ink-gradient';
|
||||||
import { AuthType, shortenPath, tildeifyPath } from '@qwen-code/qwen-code-core';
|
import { shortenPath, tildeifyPath } from '@qwen-code/qwen-code-core';
|
||||||
import { theme } from '../semantic-colors.js';
|
import { theme } from '../semantic-colors.js';
|
||||||
import { shortAsciiLogo } from './AsciiArt.js';
|
import { shortAsciiLogo } from './AsciiArt.js';
|
||||||
import { getAsciiArtWidth, getCachedStringWidth } from '../utils/textUtils.js';
|
import { getAsciiArtWidth, getCachedStringWidth } from '../utils/textUtils.js';
|
||||||
import { useTerminalSize } from '../hooks/useTerminalSize.js';
|
import { useTerminalSize } from '../hooks/useTerminalSize.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auth display type for the Header component.
|
||||||
|
* Simplified representation of authentication method shown to users.
|
||||||
|
*/
|
||||||
|
export enum AuthDisplayType {
|
||||||
|
QWEN_OAUTH = 'Qwen OAuth',
|
||||||
|
CODING_PLAN = 'Coding Plan',
|
||||||
|
API_KEY = 'API Key',
|
||||||
|
UNKNOWN = 'Unknown',
|
||||||
|
}
|
||||||
|
|
||||||
interface HeaderProps {
|
interface HeaderProps {
|
||||||
customAsciiArt?: string; // For user-defined ASCII art
|
customAsciiArt?: string; // For user-defined ASCII art
|
||||||
version: string;
|
version: string;
|
||||||
authType?: AuthType;
|
authDisplayType?: AuthDisplayType;
|
||||||
model: string;
|
model: string;
|
||||||
workingDirectory: string;
|
workingDirectory: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function titleizeAuthType(value: string): string {
|
|
||||||
return value
|
|
||||||
.split(/[-_]/g)
|
|
||||||
.filter(Boolean)
|
|
||||||
.map((part) => {
|
|
||||||
if (part.toLowerCase() === 'ai') {
|
|
||||||
return 'AI';
|
|
||||||
}
|
|
||||||
return part.charAt(0).toUpperCase() + part.slice(1);
|
|
||||||
})
|
|
||||||
.join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format auth type for display
|
|
||||||
function formatAuthType(authType?: AuthType): string {
|
|
||||||
if (!authType) {
|
|
||||||
return 'Unknown';
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (authType) {
|
|
||||||
case AuthType.QWEN_OAUTH:
|
|
||||||
return 'Qwen OAuth';
|
|
||||||
case AuthType.USE_OPENAI:
|
|
||||||
return 'OpenAI';
|
|
||||||
case AuthType.USE_GEMINI:
|
|
||||||
return 'Gemini';
|
|
||||||
case AuthType.USE_VERTEX_AI:
|
|
||||||
return 'Vertex AI';
|
|
||||||
case AuthType.USE_ANTHROPIC:
|
|
||||||
return 'Anthropic';
|
|
||||||
default:
|
|
||||||
return titleizeAuthType(String(authType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Header: React.FC<HeaderProps> = ({
|
export const Header: React.FC<HeaderProps> = ({
|
||||||
customAsciiArt,
|
customAsciiArt,
|
||||||
version,
|
version,
|
||||||
authType,
|
authDisplayType,
|
||||||
model,
|
model,
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
}) => {
|
}) => {
|
||||||
|
|
@ -67,7 +43,7 @@ export const Header: React.FC<HeaderProps> = ({
|
||||||
|
|
||||||
const displayLogo = customAsciiArt ?? shortAsciiLogo;
|
const displayLogo = customAsciiArt ?? shortAsciiLogo;
|
||||||
const logoWidth = getAsciiArtWidth(displayLogo);
|
const logoWidth = getAsciiArtWidth(displayLogo);
|
||||||
const formattedAuthType = formatAuthType(authType);
|
const formattedAuthType = authDisplayType ?? AuthDisplayType.UNKNOWN;
|
||||||
|
|
||||||
// Calculate available space properly:
|
// Calculate available space properly:
|
||||||
// First determine if logo can be shown, then use remaining space for path
|
// First determine if logo can be shown, then use remaining space for path
|
||||||
|
|
@ -95,7 +71,7 @@ export const Header: React.FC<HeaderProps> = ({
|
||||||
? Math.min(availableTerminalWidth - logoWidth - logoGap, maxInfoPanelWidth)
|
? Math.min(availableTerminalWidth - logoWidth - logoGap, maxInfoPanelWidth)
|
||||||
: availableTerminalWidth;
|
: availableTerminalWidth;
|
||||||
|
|
||||||
// Calculate max path length (subtract padding/borders from available space)
|
// Calculate max path lengths (subtract padding/borders from available space)
|
||||||
const maxPathLength = Math.max(
|
const maxPathLength = Math.max(
|
||||||
0,
|
0,
|
||||||
availableInfoPanelWidth - infoPanelChromeWidth,
|
availableInfoPanelWidth - infoPanelChromeWidth,
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,23 @@ import type React from 'react';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { escapeAnsiCtrlCodes } from '../utils/textUtils.js';
|
import { escapeAnsiCtrlCodes } from '../utils/textUtils.js';
|
||||||
import type { HistoryItem } from '../types.js';
|
import type { HistoryItem } from '../types.js';
|
||||||
import { UserMessage } from './messages/UserMessage.js';
|
import {
|
||||||
import { UserShellMessage } from './messages/UserShellMessage.js';
|
UserMessage,
|
||||||
import { GeminiMessage } from './messages/GeminiMessage.js';
|
UserShellMessage,
|
||||||
import { InfoMessage } from './messages/InfoMessage.js';
|
AssistantMessage,
|
||||||
import { ErrorMessage } from './messages/ErrorMessage.js';
|
AssistantMessageContent,
|
||||||
|
ThinkMessage,
|
||||||
|
ThinkMessageContent,
|
||||||
|
} from './messages/ConversationMessages.js';
|
||||||
import { ToolGroupMessage } from './messages/ToolGroupMessage.js';
|
import { ToolGroupMessage } from './messages/ToolGroupMessage.js';
|
||||||
import { GeminiMessageContent } from './messages/GeminiMessageContent.js';
|
|
||||||
import { GeminiThoughtMessage } from './messages/GeminiThoughtMessage.js';
|
|
||||||
import { GeminiThoughtMessageContent } from './messages/GeminiThoughtMessageContent.js';
|
|
||||||
import { CompressionMessage } from './messages/CompressionMessage.js';
|
import { CompressionMessage } from './messages/CompressionMessage.js';
|
||||||
import { SummaryMessage } from './messages/SummaryMessage.js';
|
import { SummaryMessage } from './messages/SummaryMessage.js';
|
||||||
import { WarningMessage } from './messages/WarningMessage.js';
|
import {
|
||||||
import { RetryCountdownMessage } from './messages/RetryCountdownMessage.js';
|
InfoMessage,
|
||||||
|
WarningMessage,
|
||||||
|
ErrorMessage,
|
||||||
|
RetryCountdownMessage,
|
||||||
|
} from './messages/StatusMessages.js';
|
||||||
import { Box } from 'ink';
|
import { Box } from 'ink';
|
||||||
import { AboutBox } from './AboutBox.js';
|
import { AboutBox } from './AboutBox.js';
|
||||||
import { StatsDisplay } from './StatsDisplay.js';
|
import { StatsDisplay } from './StatsDisplay.js';
|
||||||
|
|
@ -34,6 +38,7 @@ import { getMCPServerStatus } from '@qwen-code/qwen-code-core';
|
||||||
import { SkillsList } from './views/SkillsList.js';
|
import { SkillsList } from './views/SkillsList.js';
|
||||||
import { ToolsList } from './views/ToolsList.js';
|
import { ToolsList } from './views/ToolsList.js';
|
||||||
import { McpStatus } from './views/McpStatus.js';
|
import { McpStatus } from './views/McpStatus.js';
|
||||||
|
import { InsightProgressMessage } from './messages/InsightProgressMessage.js';
|
||||||
|
|
||||||
interface HistoryItemDisplayProps {
|
interface HistoryItemDisplayProps {
|
||||||
item: HistoryItem;
|
item: HistoryItem;
|
||||||
|
|
@ -60,6 +65,11 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
|
||||||
embeddedShellFocused,
|
embeddedShellFocused,
|
||||||
availableTerminalHeightGemini,
|
availableTerminalHeightGemini,
|
||||||
}) => {
|
}) => {
|
||||||
|
const marginTop =
|
||||||
|
item.type === 'gemini_content' || item.type === 'gemini_thought_content'
|
||||||
|
? 0
|
||||||
|
: 1;
|
||||||
|
|
||||||
const itemForDisplay = useMemo(() => escapeAnsiCtrlCodes(item), [item]);
|
const itemForDisplay = useMemo(() => escapeAnsiCtrlCodes(item), [item]);
|
||||||
const contentWidth = terminalWidth - 4;
|
const contentWidth = terminalWidth - 4;
|
||||||
const boxWidth = mainAreaWidth || contentWidth;
|
const boxWidth = mainAreaWidth || contentWidth;
|
||||||
|
|
@ -68,6 +78,7 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
|
||||||
<Box
|
<Box
|
||||||
flexDirection="column"
|
flexDirection="column"
|
||||||
key={itemForDisplay.id}
|
key={itemForDisplay.id}
|
||||||
|
marginTop={marginTop}
|
||||||
marginLeft={2}
|
marginLeft={2}
|
||||||
marginRight={2}
|
marginRight={2}
|
||||||
>
|
>
|
||||||
|
|
@ -79,7 +90,7 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
|
||||||
<UserShellMessage text={itemForDisplay.text} />
|
<UserShellMessage text={itemForDisplay.text} />
|
||||||
)}
|
)}
|
||||||
{itemForDisplay.type === 'gemini' && (
|
{itemForDisplay.type === 'gemini' && (
|
||||||
<GeminiMessage
|
<AssistantMessage
|
||||||
text={itemForDisplay.text}
|
text={itemForDisplay.text}
|
||||||
isPending={isPending}
|
isPending={isPending}
|
||||||
availableTerminalHeight={
|
availableTerminalHeight={
|
||||||
|
|
@ -89,7 +100,7 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{itemForDisplay.type === 'gemini_content' && (
|
{itemForDisplay.type === 'gemini_content' && (
|
||||||
<GeminiMessageContent
|
<AssistantMessageContent
|
||||||
text={itemForDisplay.text}
|
text={itemForDisplay.text}
|
||||||
isPending={isPending}
|
isPending={isPending}
|
||||||
availableTerminalHeight={
|
availableTerminalHeight={
|
||||||
|
|
@ -99,7 +110,7 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{itemForDisplay.type === 'gemini_thought' && (
|
{itemForDisplay.type === 'gemini_thought' && (
|
||||||
<GeminiThoughtMessage
|
<ThinkMessage
|
||||||
text={itemForDisplay.text}
|
text={itemForDisplay.text}
|
||||||
isPending={isPending}
|
isPending={isPending}
|
||||||
availableTerminalHeight={
|
availableTerminalHeight={
|
||||||
|
|
@ -109,7 +120,7 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{itemForDisplay.type === 'gemini_thought_content' && (
|
{itemForDisplay.type === 'gemini_thought_content' && (
|
||||||
<GeminiThoughtMessageContent
|
<ThinkMessageContent
|
||||||
text={itemForDisplay.text}
|
text={itemForDisplay.text}
|
||||||
isPending={isPending}
|
isPending={isPending}
|
||||||
availableTerminalHeight={
|
availableTerminalHeight={
|
||||||
|
|
@ -125,7 +136,7 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
|
||||||
<WarningMessage text={itemForDisplay.text} />
|
<WarningMessage text={itemForDisplay.text} />
|
||||||
)}
|
)}
|
||||||
{itemForDisplay.type === 'error' && (
|
{itemForDisplay.type === 'error' && (
|
||||||
<ErrorMessage text={itemForDisplay.text} />
|
<ErrorMessage text={itemForDisplay.text} hint={itemForDisplay.hint} />
|
||||||
)}
|
)}
|
||||||
{itemForDisplay.type === 'retry_countdown' && (
|
{itemForDisplay.type === 'retry_countdown' && (
|
||||||
<RetryCountdownMessage text={itemForDisplay.text} />
|
<RetryCountdownMessage text={itemForDisplay.text} />
|
||||||
|
|
@ -180,6 +191,9 @@ const HistoryItemDisplayComponent: React.FC<HistoryItemDisplayProps> = ({
|
||||||
{itemForDisplay.type === 'mcp_status' && (
|
{itemForDisplay.type === 'mcp_status' && (
|
||||||
<McpStatus {...itemForDisplay} serverStatus={getMCPServerStatus} />
|
<McpStatus {...itemForDisplay} serverStatus={getMCPServerStatus} />
|
||||||
)}
|
)}
|
||||||
|
{itemForDisplay.type === 'insight_progress' && (
|
||||||
|
<InsightProgressMessage progress={itemForDisplay.progress} />
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue