* perf(dev): add pnpm worktree bootstrap foundation Co-authored-by: Qwen-Coder <[email protected]> * fix(dev): harden worktree bootstrap process handling Co-authored-by: Qwen-Coder <[email protected]> * perf(dev): prefer cache-only worktree installs Co-authored-by: Qwen-Coder <[email protected]> * fix(dev): preserve cached install cancellation Co-authored-by: Qwen-Coder <[email protected]> * fix(build): harden pnpm worktree bootstrap Validate pnpm lock updates in releases and exercise real installs and builds across supported hosts. Preserve npm release compatibility and keep dependency-only setup from rewriting npm-layout notices. Co-authored-by: Qwen-Coder <[email protected]> * chore: record merge attribution Record the required attribution for the Stage 1 merge without rewriting published history. Co-authored-by: Qwen-Coder <[email protected]> * fix(dev): keep worktree bootstrap clean Use a bootstrap-scoped notice guard because nested npm lifecycle commands replace npm_lifecycle_event. This preserves explicit notice generation while preventing dependency setup from rewriting tracked output. Co-authored-by: Qwen-Coder <[email protected]> * ci: track pnpm smoke workflow size Register the new workflow in the repository size ratchet as required by the main CI gate. Co-authored-by: Qwen-Coder <[email protected]> * fix(ci): drop stale importers from the new pnpm lockfile The lockfile was generated before the WebShell cutover (#9811) removed @qwen-code/webui from web-shell and the tailwind tooling plus @qwen-code/webui from vscode-ide-companion, so frozen-lockfile installs fail on all three smoke platforms with ERR_PNPM_OUTDATED_LOCKFILE. Drop the five stale importer entries so the lockfile matches the current package.json manifests; verified with pnpm 11.24.0 install --frozen-lockfile --lockfile-only. Co-authored-by: Qwen-Coder <[email protected]> * fix(ci): refresh pnpm lockfile after merging main The merge of origin/main added remend@^1.3.1 to packages/cli/package.json without updating pnpm-lock.yaml, breaking the pnpm Worktree Smoke workflow frozen-lockfile install. Regenerated with pnpm install. Co-authored-by: Qwen-Coder <[email protected]> Patrol-Run: qwen-pr-conflict/jmtid3rse9h * fix(scripts): resolve the path variable case-insensitively on Windows A spread of process.env is an ordinary object, and native Windows shells expose the path variable as `Path`, so `env.PATH` was undefined there and findOnPath never located corepack — the offline-first Corepack bootstrap silently degraded to npx on exactly the hosts it exists for. Co-authored-by: Qwen-Coder <[email protected]> * test(scripts): pin the worktree bootstrap guards against mutation - Split the fallback log on /\r?\n/ like the sibling cmd.exe mocks, so the assertion holds on the Windows lane's CRLF output. - Add a win32 variant bootstrapping with the native `Path` casing to pin the case-insensitive lookup. - Assert the smoke workflow's fail-fast flag, the install-before-clean step order, and the no-build guard via a substring on the raw job text. - Extend the pnpmfile rewrite fixture to devDependencies and optionalDependencies, which the committed lockfile already uses. - Assert the notice-skip guard by effect (writeFile never called) and add the flag-absent companion test with I/O stubbed. Co-authored-by: Qwen-Coder <[email protected]> * chore(deps): sync pnpm-lock.yaml with qwen-live ACP backend deps Co-authored-by: Qwen-Coder <[email protected]> Patrol-Run: qwen-pr-conflict/jmtjyz3tdco * fix(dev): stop patch-package from corrupting the pnpm store The root postinstall runs patch-package, which rewrites files under node_modules in place. With pnpm's default import method those files are hard links into the content-addressable store, so the patch rewrites the store entry too and its contents stop matching the sha512 it is filed under. Every subsequent fresh worktree then fails its --offline stage with ERR_PNPM_NO_OFFLINE_TARBALL, silently falls back to the registry (exit 0), and the fallback's postinstall corrupts the store again, so the offline path never hits. The advertised offline timing was only reachable on a same-tree reinstall, which needs no relinking. Set packageImportMethod to clone-or-copy: a copy-on-write clone where the filesystem supports it, a plain copy elsewhere. Either way patch-package edits only the worktree's own copy and the store entry stays intact, so later worktrees resolve entirely from the store. Verified on an isolated fixture store: under the default method the node_modules file and its store entry share an inode, and an in-place edit moves the store file's sha512 off its address, after which a fresh offline install fails with ERR_PNPM_NO_OFFLINE_TARBALL; under clone-or-copy the same edit leaves the store hash unchanged and the fresh offline install reports reused 1, downloaded 0. Also add pnpm-lock.yaml to .prettierignore. prettier reflows it into a shape pnpm does not emit, so `npm run format` and `pnpm install` fight over the file; .yamllint.yml already ignores it for the same reason. Both facts are pinned by tests in scripts/tests/package-scripts.test.js. Claude-Session: https://claude.ai/code/session_012797rgiteWJxLT9TLkKq8G * fix(ci): refresh pnpm-lock.yaml for qwen-live prompts deps Main added prompts/@types/prompts (and the ACP sdk) to packages/qwen-live/package.json after this branch generated its lockfile, so the pnpm Worktree Smoke frozen-lockfile install failed with ERR_PNPM_OUTDATED_LOCKFILE. Regenerated with pnpm 11.24.0 (--lockfile-only); frozen-lockfile and supply-chain policy checks pass. Co-authored-by: Qwen-Coder <[email protected]> Patrol-Run: qwen-pr-conflict/jmtlc9sozfg * fix(pnpm): close review findings on worktree bootstrap - Declare @qwen-code/qwen-code-core in vscode-ide-companion so the pnpm linker materializes it; regenerate both lockfiles and assert the link in the smoke workflow (R5-1) - Pin @types/node 20.19.1 in packages/core so the pnpm layout compiles against the same types npm hoists (D6-1) - Accept and pin the corepack +sha512 integrity suffix on packageManager; strip it for the npx fallback spec (D6-2) - Cover every workspace member in the pnpmfile rewrite set, mirror the npm channel list in pnpm-workspace.yaml, and cross-check both in tests - Run setup-worktree.js installs with cwd pinned to the checkout, gate the smoke clean-check on git status --porcelain, stop post-merge runs from cancelling each other, and extend check-lockfile.js to pnpm-lock.yaml * merge(main): realign pnpm workspace set and lockfiles Main removed the webui and cua-driver packages; drop both from the pnpm rewrite set and regenerate the pnpm lockfile against the merged manifests (picks up playwright, react-markdown, and the other main-side dependency changes) so the frozen bootstrap matches what the PR merge ref will run. * style(ci): quote smoke workflow scalars per yamllint * fix(dev): require Corepack for pnpm bootstrap * fix(dev): close pnpm bootstrap review blockers --------- Co-authored-by: Qwen-Coder <[email protected]> Co-authored-by: yiliang114 <[email protected]>
15 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
npm install # Install all dependencies
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 directly from TypeScript source (no build needed)
Runs the CLI via tsx with DEV=true. Changes to packages/core or
packages/cli are reflected immediately without rebuilding.
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
npm ci 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
pnpm worktree bootstrap (opt-in): an additional Git worktree can install
dependencies with node scripts/setup-worktree.js, which runs the pinned
pnpm with --frozen-lockfile (warm store ≈ 99 MiB on copy-on-write
filesystems such as APFS, btrfs, and XFS with reflink; without reflink it is
≈ 1.2 GiB). npm remains the authoritative path for build, CI, packaging, and
release; the pnpm layout is install-only for now. When dependencies change,
regenerate the pnpm lockfile with
corepack pnpm install --lockfile-only --no-frozen-lockfile and commit both
lockfiles together.
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 - 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. - 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.
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 |