* ci(pnpm): install dependencies with pnpm in CI and release CI tests the graph release ships only if both install it the same way, so this moves both, keeping every `npm run` script and `npm publish` as they are. - ci.yml (7), release.yml (3) and release-vscode-companion.yml (2) install with `corepack pnpm install --frozen-lockfile`; release keeps --ignore-scripts plus its explicit postinstall and generate steps. - setup-node drops the npm cache and sets package-manager-cache: false, which setup-node v5+ needs once package.json declares a pnpm packageManager. - A composite action caches the pnpm store on the three always-hosted jobs; the ECS pool keeps its store on local disk. - version.js no longer lets npm reify node_modules: --no-workspaces-update on both `npm version` calls, and a package-lock-only refresh in step 9. - The notices generator, prepare-package's sharp pin and the standalone release's native package specs read the installed tree or pnpm-lock.yaml instead of package-lock.json keys. - New size baselines for the three workflows, which were already over them. * chore(vscode): regenerate NOTICES from the pnpm-installed tree Generated in CI (pnpm Worktree Smoke on ubuntu-latest) by the ported generator. Same entry set as before except the five packages npm and pnpm resolve differently: fdir 6.5.0, picomatch 4.0.5, mdurl 2.1.0, @types/node 22.20.1 and mime-db 1.52.0 (form-data's pinned copy). No entry lacks a license text or repository. * fix(pnpm): resolve undeclared zod peers to the repo's zod, as npm does The first CI run on this branch failed the export renderer's size budget: 1,930,015 bytes against 1,930,000, where the same commit built on npm's tree comes to 1,858,186. Comparing both trees' esbuild metafiles and prebuilt bundles put the whole difference in web-shell's transcript.js (+100,903 bytes pre-minify), and the added code is zod 4 plus the @modelcontextprotocol/ext-apps schemas; the sdk daemon bundle is identical. web-shell bundles ext-apps, whose zod and MCP SDK are peers, and declares no zod itself, so pnpm filled the peer with the highest locked zod (4.4.3) while npm serves the hoisted 3.25.76. Declaring zod 3.25.76 as a root devDependency makes pnpm resolve every such peer to it (resolve-peers-from-workspace-root is on by default), which is npm's hoisting behaviour. mobile-mcp keeps its own zod 4.4.3, as under npm; the npm tree does not change. * fix(pnpm): keep npm's root @types/node so root-level typechecks match The no-AK integration gate typechecks integration-tests/, which takes Node's types from the root node_modules. npm hoists @types/node 20.19.1 there, because acp-bridge and core pin it; pnpm, with no root declaration, hoisted 22.20.1, whose spawnSync overloads type process-registry.ts's stdout as string | NonSharedBuffer and fail TS2322. The same code passes on every npm-installed PR. Declaring 20.19.1 as a root devDependency puts npm's copy back where a root-level tsconfig looks. The npm tree does not change. * ci(pnpm): install with pnpm in the remaining workflows The follow-up to switching CI and release: every other workflow that installs the root workspace now uses the pinned pnpm with --frozen-lockfile, so no job tests a graph that release does not ship. - e2e, tui-parity, repo-hygiene, web-shell-visuals, serve-ab, sdk-java, windows-runner-smoke, qwen-autofix, the SDK releases, finalize-release, sync-release-to-oss, the root install in desktop-release and cd-cua-driver, and the sandbox Dockerfile. - setup-node drops the root npm cache (package-manager-cache: false); hosted jobs restore the pnpm store through the shared composite action, and qwen-autofix keeps af-012's rule that the persistent pool restores no remote cache. - serve-ab and web-shell-visuals install a separate base checkout that can predate pnpm-lock.yaml, so those installs fall back to npm ci there. - Out of scope, unchanged: packages with their own lockfile (cua-driver's TypeScript SDK, desktop-shell, live-host, mobile-mcp), and the triage lanes with npm-cache.yml and the npm audit gate, which move with the package-lock.json retirement. - New size baselines for the touched workflows; qwen-autofix stays under the 470000-byte gate. * fix(pnpm): link the workspace packages that root-level code imports npm links every workspace package into the root node_modules, so integration-tests/ and scripts/, which are not workspace packages themselves, can import @qwen-code/* by name. pnpm links a workspace package only where it is a declared dependency, and the root declared none, so the no-AK integration gate could not find @qwen-code/qwen-code-core. The root now declares the seven packages that root-level code imports at runtime as file: devDependencies: acp-bridge, channel-base, the CLI, core, sdk, web-shell and web-templates. npm already links them, so its tree does not change (letting npm re-resolve the lock reproduces the same root entry); .pnpmfile.mjs rewrites them to workspace:*, which pnpm links at the root. * ci(pnpm): move triage, the store producer and the root audit to pnpm - qwen-triage's verify and tmux-testing lanes install the PR with `corepack pnpm install --frozen-lockfile` from a restored pnpm store. The one retry clears node_modules first, because pnpm install, unlike npm ci, keeps it. - npm-cache.yml becomes pnpm-store.yml, keyed on pnpm-lock.yaml. - security-checks audits the root workspace with `pnpm audit`, which reads the lockfile, so the root install step goes. The vendored lockfiles keep npm, and the retry recognises pnpm's endpoint error too. - qwen-autofix drops the hosted-only store cache: its heavy jobs forbid local `uses: './...'` actions, and the file sits at the size gate. - cd-cua-driver: setup-node@v4 has no package-manager-cache input. - package-assets fixtures install sharp rather than listing it in package-lock.json, matching how prepare-package now resolves it. - AGENTS.md, CONTRIBUTING.md and the npm workspace guide install with pnpm. * feat(review): install pnpm repos in qwen review's build/test qwen review installed dependencies only for a repo with package-lock.json and reported a pnpm repo as unsupported, so reviews of qwen-code would lose their build and test once its npm lockfile goes. - lockfileInstaller() picks npm or pnpm from the committed lockfile. With both, `packageManager: pnpm@...` chooses pnpm; anything else keeps npm. - A pnpm repo installs with `corepack pnpm install --frozen-lockfile` through the same disk, budget and sandbox path as `npm ci`, and counts as installed once node_modules/.modules.yaml exists. - Scripts still run through `npm run`, and the npm path is unchanged. * ci(pnpm): retire the root package-lock.json pnpm-lock.yaml is now the only root lockfile. - check-lockfile keeps the pnpm integrity check and Playwright parity, which now reads pnpm importers and snapshots. The npm-vs-pnpm agreement and build-approval checks go: pnpm 11's strictDepBuilds and every CI install's --frozen-lockfile enforce what they covered. - pnpm-lock-freshness.yml goes; it regenerated pnpm-lock.yaml from package-lock.json. - Release: version.js drops its package-lock refresh, the release commit stages pnpm-lock.yaml and the SDK release stages no lockfile, so neither `git add` fails on the missing file. `npm version` in the SDK and mobile-mcp releases passes --no-workspaces-update so it cannot reinstall the root with npm. - cd-mobile-mcp installs from the root pnpm lockfile. setup-node in cd-mobile-mcp, qwen-code-pr-review and desktop-release no longer keys an npm cache on the root lockfile. - check-desktop-isolation reads pnpm importers; build.js, build_sandbox.js and preflight install with pnpm. - pnpm-lock.yaml, pnpm-workspace.yaml and .pnpmfile.mjs join the autofix supply-chain class and repo-hygiene's deny list; pnpm-lock.yaml joins autofix's generated-diff exclusions, sdk-java's path filter and the platform-sensitivity manifests. - .gitignore lists /package-lock.json so an npm install cannot commit it back. Tests and docs follow. * fix(standalone): read the node-pty versions from the pnpm lockfile * chore(vscode-ide-companion): regenerate NOTICES.txt after the lockfile swap * chore(vscode-ide-companion): regenerate NOTICES.txt from the pnpm dependency tree The committed NOTICES.txt was generated from an npm install and does not match the tree produced by the pnpm install the release pipeline now uses (659 resolved dependencies, differing @types/node and mime-db versions). Regenerating with the pinned pnpm install makes the freshness check reproducible. * fix(ci): drop the npm cache from the daily dependency audit actions/setup-node's npm cache keys off the root package-lock.json, which this branch retires, so the scheduled job would fail at Set up Node before the audit ran. No pull_request run reaches this workflow to catch it. The root tree is never installed here either: pnpm audit reads pnpm-lock.yaml directly. Matches the sibling workflows that already set package-manager-cache: false; scripts/tests/security-workflows.test.js now pins it. * chore(ci): stop banking main-side drift in the workflow size ratchet The ratchet exists to turn a workflow's growth into one reviewed line. This branch re-recorded entries for 17 workflows it never touches, several upward by 0.4-2.8 KB - drift that happened on main, banked into the manifest without review. Restore those to their merge-base values, so .size-baseline changes only for the 22 workflows this branch actually edits. The entries were not needed to go green: ci.yml passes the PR's base commit, so a file that drifted on main and is otherwise untouched earns a warning, not a failure. * fix(release): initialize standalone state before main * test(browser-use): read Playwright pin from pnpm lock * fix(ci): address pnpm migration review blockers * fix(desktop): stop reading the retired root lockfile --------- Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
17 KiB
AGENTS.md
Working Principles
Simplicity First
Minimum code that solves the problem. Nothing speculative. (This is the principle we care about most.)
- No features beyond what was asked.
- No abstractions for single-use code.
- No "flexibility" or "configurability" that wasn't requested.
- No error handling for impossible scenarios.
- If you write 200 lines and it could be 50, rewrite it.
Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
Core Infrastructure Is Maintainer-Only (triage gate, two-tier rule)
Core modules — packages/core/src/**, packages/*/src/auth/**,
packages/*/src/providers/**, packages/*/src/models/**,
packages/*/src/config/**, packages/*/src/tools/**,
packages/*/src/services/**, cross-package changes — are the architectural
backbone. External PRs touching them face a two-tier gate (maintainer-authored
PRs are exempt):
- Large-scope
refactorchanges (500+ production logic lines in core, excluding test and generated/schema files) → hard block. Skip evaluation entirely — the maintainer exemption above is the sole exception. Large-scale core refactors must be maintainer-initiated. When counting lines, exclude files matching*.test.ts,*.test.tsx,*.spec.ts,*.spec.tsx,__tests__/**,*.schema.ts,*.schema.json,*.generated.ts, and**/generated/**— only production logic counts.feat-type and other non-refactorPRs are NOT hard-blocked on size; they escalate to the maintainer for awareness instead. A non-blocking advisory also applies at 1000+ production logic lines. Breadth alone is not size — a low-risk sweep that touches 10+ files but changes a line or two each is escalated to a maintainer for awareness and otherwise judged under Tier 2's 100%-confidence bar, not auto-rejected on file count. - Small-scope changes → gate may evaluate, but must be 100% confident. Any doubt at all → escalate to maintainer. "The direction looks correct" is not confidence. The gate must name every downstream consumer; if it cannot, escalate.
When in doubt, escalate. Better to wrongly escalate than to wrongly approve.
Common Commands
Building
corepack pnpm install --frozen-lockfile # Install all dependencies (the tree CI tests)
npm run build # Build all packages (TypeScript compilation + asset copying)
npm run build:all # Build everything including sandbox container
npm run bundle # Bundle dist/ into a single dist/cli.js via esbuild
# (requires build first)
Development
npm run dev # Run CLI from TypeScript source
Runs the CLI via tsx with DEV=true. Changes to packages/core or
packages/cli are reflected immediately without rebuilding. Browser Use reuses
its built runtime, like other compiled workspace dependencies. After editing
Browser Use, run npm run build --workspace=@qwen-code/browser-use to rebuild
and stage its runtime for dev. Normal npm install prepares it automatically.
Unit Testing
Tests must be run from within the specific package directory, not the project root.
Fresh clone or new worktree: packages/cli unit tests import workspace
packages (@qwen-code/acp-bridge, @qwen-code/web-templates,
packages/channels/*, ...) through their built dist/ output, and
packages/core tests import the package's own entry
(@qwen-code/qwen-code-core), which also resolves into dist/. A plain
corepack pnpm install --frozen-lockfile already builds them via the
prepare script, but a worktree that shares the main checkout's
node_modules (or a deep-cleaned copy) does not have them. If any
prerequisite is missing, a vitest globalSetup guard stops the run and names
the fix; build once from the repository root:
npm run build
Installing dependencies: CI, release and every workflow install with the
pnpm version pinned in packageManager (corepack pnpm install --frozen-lockfile); scripts still run through npm run. An additional Git
worktree can use node scripts/setup-worktree.js, which runs the same install
from a shared store (≈ 99 MiB on copy-on-write filesystems such as APFS, btrfs,
and XFS with reflink; ≈ 1.2 GiB on ext4) and skips the prepare build, so run
npm run build before package tests. When dependencies change, edit the
manifest, run corepack pnpm install (or corepack pnpm add), and commit
pnpm-lock.yaml; every CI install runs with --frozen-lockfile, so a
lockfile that no longer matches the manifests fails the build.
Run individual test files (always preferred):
cd packages/core && npx vitest run src/path/to/file.test.ts
cd packages/cli && npx vitest run src/path/to/file.test.ts
Update snapshots:
cd packages/cli && npx vitest run src/path/to/file.test.ts --update
Avoid:
npm run test -- --filter=...— does NOT filter; runs the entire suitenpx vitestfrom the project root — fails due to package-specific vitest configs- Running the whole test suite unless necessary (e.g., final PR verification)
Test gotchas:
- In CLI tests, use
vi.hoisted()for mocks consumed byvi.mock()— the mock factory runs at module load time, before test execution.
Integration Testing
Build the bundle first: npm run build && npm run bundle
Run from the project root using the dedicated npm scripts:
npm run test:integration:cli:sandbox:none
npm run test:integration:interactive:sandbox:none
Or combined in one command:
cd integration-tests && \
cross-env QWEN_SANDBOX=false npx vitest run cli interactive
Gotcha: In interactive tests, always call session.idle() between sends —
ANSI output streams asynchronously.
Linting & Formatting
npm run lint # ESLint check
npm run lint:fix # Auto-fix lint issues
npm run format # Prettier formatting
npm run typecheck # TypeScript type checking
npm run preflight # Full check: clean → install → format → lint → build
# → typecheck → test
Code Conventions
- Module system: ESM throughout (
"type": "module"in all packages) - TypeScript: Strict mode with
noImplicitAny,strictNullChecks,noUnusedLocals,verbatimModuleSyntax - Formatting: Prettier — single quotes, semicolons, trailing commas, 2-space indent, 80-char width
- Linting: No
anytypes, consistent type imports, no relative imports between packages - Core imports in cli: production code in
packages/cli/srcimports core values from the module that defines them (@qwen-code/qwen-code-core/utils/debugLogger.js), not the package root, which evaluates all of core in every test that reaches the file. Type-only imports are exempt. Files that predate the rule are allowlisted ineslint.legacy-core-barrel-imports.mjs; drop an entry when you move its file off the root, never add one. - Tests: Collocated with source (
file.test.tsnext tofile.ts), vitest framework - File naming:
PascalCase.tsxfor React components,kebab-case.tsfor.tsfiles inpackages/coreandpackages/cli(enforced by ESLint). Existing camelCase files are allowlisted ineslint.legacy-filenames.mjs; rename opportunistically when touching them, updating all imports in the same commit (note: renames losegit blamehistory). - Comments: Default to none. Add only when why is non-obvious; don't delete existing ones as cleanup.
- Commits: Conventional Commits (e.g.,
feat(cli): Add --json flag) - Node.js: Development and production both require
>=22(Ink 7 + React 19.2 requirement)
Web Shell UI development
- Prefer the shared primitives in
packages/web-shell/client/components/uiwhen developing Web Shell UI. Do not duplicate an existing primitive or rewrite stable CSS Modules solely for consistency. - If a required primitive is missing, run
npx shadcn@latest add <component>frompackages/web-shell, then review the generated diff. Do not let the CLI overwrite the existing global CSS, semantic tokens, CSS scoping, or portal-root integration. Keep generated components internal unless a public package API is explicitly required. - Web Shell supports React 18 and React 19. Generated shadcn components often
assume React 19 ref semantics, so wrappers that accept or receive refs —
including Radix
asChild,Slot,Presence, and portal children — must useReact.forwardRefand pass the ref to the underlying DOM or Radix primitive. Add a regression test for any ref-sensitive component path. - Use unprefixed Tailwind classes and shadcn semantic color tokens such as
background,primary, andmuted. The package build scopes generated CSS to the Web Shell root and portal root and prefixes global animations and CSS property registrations; changes must preserve that isolation from host-page styles. - Components with portals, such as dialogs, popovers, dropdown menus, and
tooltips, must use
useWebShellPortalRoot()as the Radix portal container so themes, scoped CSS, and z-index variables continue to apply. Preserve existingdata-web-shell-*attributes and public--web-shell-*CSS variables. Seepackages/web-shell/README.mdfor the full conventions.
Development Guidelines
General workflow
- Design doc for non-trivial work — write one in
docs/design/if the change touches multiple files or involves design decisions. Skip for small bugfixes. Provide both an English<name>.mdand a Chinese<name>.zh-CN.mdversion in the same directory, following the design documentation requirements. Add reciprocal language links and keep both versions complete and synchronized in the same change, including when updating an existing design. - Test plan for behavioral changes — write an E2E test plan in
.qwen/e2e-tests/when the change affects user-observable behavior. Dry-run against the globalqwenCLI first to confirm the baseline. - Build, typecheck, and test before declaring done:
npm run build && npm run typecheck, plus unit tests for the files you changed. - Self-audit before declaring done — read the full diff you are about to ship, including new untracked files, in open-ended passes, not hunting for anything specific. Then verify each change, and each green test you rely on as evidence, presuming it wrong (a passing test can assert the wrong thing). Stop after two consecutive clean passes — a clean pass is evidence about that pass, not the code. A fix re-runs step 3, resets the clean-pass count, and gets a further pass over the updated diff — never exit on a pass that found something. If five passes bring no convergence, say so instead of declaring done. Scale to the diff: one clean, careful pass suffices for a trivial change.
Feature development
Use the /feat-dev skill for the full workflow: investigate, design, test plan,
dry-run, implement, verify, self-audit, code review, and iterate.
Bugfix
Use the /bugfix skill for the reproduce-first workflow: reproduce, fix,
verify, test, self-audit, and code review.
Code Review
Project-specific rules for /review. The skill loads this section verbatim (by
its ## Code Review heading) and hands it to every review agent, so keep it to
things a reviewer of this codebase must check — not general advice.
- Verify a finding against the exact reviewed commit before reporting it. Read the lines you are about to cite. A Critical that quotes code not present at the commit under review is worse than no finding — it blocks the author over nothing. Do not report a defect you have only inferred from a symbol name or a diff fragment.
- A
C=0/ APPROVE is a claim, not a default. Before submitting one, take each unresolved Critical already on the PR and check it against the code as it stands: still stands / fixed by this diff / cannot tell. A GitHub thread can readisResolved: false, isOutdated: falsefor a bug that a later commit fixed on an adjacent line — the flag tracks the anchored line, not the fix. - For every added field, option, or optional parameter, grep its read sites,
including outside the diff. A
foo?: booleanthat is declared and read but never set by any caller is a dead switch (options.foo ?? truealways takes the default). Decide severity at the read site; never explain an unpopulated field with author intent you cannot observe. - Classify every added or changed daemon route by ownership. Name whether it is process-global, legacy-primary, selected-runtime, live-session-owner, or persisted-workspace scoped, and verify every downstream consumer matches that scope.
- Verify workspace-scoped routes stay inside the resolved runtime. Check the environment, bridge, service, filesystem, trust boundary, and failure paths. Each unknown, untrusted, ambiguous, bootstrapping, draining, or removed state must follow its declared failure semantics and must never fall back to the primary runtime.
- Match the house style when judging. ESM only; no
any; no relative imports between packages;kebab-case.tsfor.tsinpackages/coreandpackages/cli,PascalCase.tsxfor React components; tests collocated asfile.test.ts. Comments default to none — flag a missing comment only where the why is genuinely non-obvious, and never fault a diff for deleting a comment that no longer applies. - A missing test for changed behavior is a Suggestion, not a Critical, unless the untested path is itself the defect.
- Check design documentation in both languages. New or updated designs must include linked English and Chinese versions with matching structure, decisions, constraints, and acceptance criteria. A translation gap alone is a Suggestion, not a Critical.
GitHub Operations
Use the gh CLI for all GitHub-related operations — issues, pull requests,
comments, CI checks, releases, and API calls. Prefer gh issue view,
gh pr view, gh pr checks, gh run view, gh api, etc. over web fetches
or manual REST calls.
Testing, Debugging, and Bug Fixes
- Bug reproduction & verification: spawn the
test-engineeragent. It reads code and docs to understand the bug, then reproduces it via E2E testing (or a test-script fallback). It also handles post-fix verification. It cannot edit source code — only observe and report. - Hard bugs: use the
structured-debuggingskill when debugging requires more than a quick glance — especially when the first attempt at a fix didn't work or the behavior seems impossible. - E2E testing: the
e2e-testingskill covers headless mode, interactive (tmux) mode, MCP server testing, and API traffic inspection. Thetest-engineeragent invokes this skill internally — you typically don't need to use it directly.
Submitting PRs
When creating a PR, follow the template at .github/pull_request_template.md.
After the PR is submitted, post a separate comment with the E2E test report if
applicable.
- PR description: explain the motivation and changes in prose. Avoid referencing file names or function names.
- Reviewer Test Plan (template section): describe behaviors a reviewer should verify and what to expect, not scripted test commands. Use How to verify for reproduction steps; Before/After for TUI evidence when applicable.
- Line wrapping: do not hard-wrap the PR body at a fixed column width.
GitHub renders single newlines as
<br>, so a wrapped description displays as a narrow column. Write each paragraph or list item as one long line. - Don't let review rounds balloon the PR. Every accepted change widens the diff and tends to trigger another round, so a PR can drift far past its original intent. Once a PR has been through roughly 5 review rounds, land only Critical fixes — correctness, security, data loss, regressions — and defer remaining Suggestions to a follow-up issue or PR. Record each deferral in the PR thread so nothing is silently dropped.
Project Directories
Design docs and implementation plans are committed under docs/ so they are
tracked in version control:
| Directory | Purpose |
|---|---|
docs/design/ |
Design docs for planned features |
docs/plans/ |
Implementation plans |
Other working artifacts live under .qwen/ (git-ignored):
| Directory | Purpose |
|---|---|
.qwen/e2e-tests/ |
E2E test plans and results |
.qwen/issues/ |
Issue drafts before filing on GitHub |
.qwen/pr-drafts/ |
PR drafts before submitting |
.qwen/pr-reviews/ |
PR review notes |
.qwen/investigations/ |
Structured debugging journals |
.qwen/scripts/ |
Utility scripts |