@weave_protocol/adapter-qwencode
v0.1.1
Published
Weave Protocol adapter for Qwen Code - enforces WARD.md policies via Qwen Code's PreToolUse hook
Maintainers
Readme
🛡️ @weave_protocol/adapter-qwencode
Enforce WARD.md in Qwen Code, Alibaba's open-source terminal coding agent, with its
PreToolUsehook. Every tool call the agent makes is checked against your policy before it runs, whatever model you point Qwen Code at.
This adapter is for Qwen Code only. Other coding agents, including Trae, Qoder, CodeBuddy and Kimi Code, each need their own.
The eighth WARD harness adapter. The same WARD.md works in Claude Code, Antigravity, Microsoft Agent Framework, Gemini CLI, Codex, OpenCode, Cursor and Qwen Code.
Quick start
npm i -g @weave_protocol/adapter-qwencode
weave-qwen init # adds the hook to ~/.qwen/settings.json
weave-qwen status # hook installed? which WARD.md is active?Then restart Qwen Code. Add a WARD.md to your project (npx @weave_protocol/ward init), or a user-wide one at ~/.qwen/WARD.md.
What it checks
The hook uses Ward's shared evaluator, so the rules match the other adapters exactly. That includes session and spend limits, the payment guard, outbound-data checks, model endpoints by jurisdiction, signed policies and decision receipts.
- Capability: the tool's WARD capability (
run_shell_command→shell_exec,read_file→file_read,edit→file_write, …) or its raw name. - Arguments: every path and URL argument, with
..and~normalized. - Shell commands: every URL and every absolute or
~path inrun_shell_command, with relative paths resolved against itsdirectory. tool_call: Qwen Code reaches its deferred tools throughtool_call. The hook decides the tool being called, with that tool's arguments, so the wrapper can't hide a call.exec(code mode): its JavaScript source is scanned like a shell command, for URLs, secret references and dangerous commands.- MCP tools: by name, plus their path and URL arguments.
Tools that act on their own or later have their own capabilities, so a default-deny policy keeps them off until you allow them:
- scheduling (
cron_create→scheduled_task); - subagents (
agent→subagent); - messaging other agents (
send_message→agent_message); - pushing PRs (
autofix_pr→git_push).
The planning and interaction tools (todo_write, ask_user_question, plan mode, the task list, tool_search) share one capability, task_planning:
## Capabilities
allow:
- file_read
- task_planning
default: denyDecisions
| WARD decision | What Qwen Code sees |
|---|---|
| allow | nothing ({}): Qwen Code's own permission rules and prompts still apply |
| deny | permissionDecision: "deny" with the reason; the agent gets it as the tool result |
| require_approval | permissionDecision: "ask": Qwen Code asks you in the terminal. Headless runs, background subagents and ACP sessions treat it as deny |
Qwen Code lets a call through if a hook crashes, times out or exits with anything but 2. So this hook never exits non-zero; every outcome is an explicit decision:
- An invalid or unreadable WARD.md always denies, so a typo can't silently switch enforcement off.
- No WARD.md anywhere means no enforcement.
- Malformed payloads and evaluator errors allow by default, like Weave's other adapters.
weave-qwen init --fail-closedmakes them deny.
WARD.md is looked up in this order:
$WEAVE_WARD_PATH<project>/WARD.md<project>/.qwen/WARD.md<project>/.weave/WARD.md~/.qwen/WARD.md
Commands
weave-qwen init [--matcher=REGEX] [--timeout=SECONDS] [--fail-closed]
weave-qwen disable
weave-qwen status
weave-qwen test read_file --input='{"file_path":"secrets/key"}' # dry run
weave-qwen hook pre-tool-use # what Qwen Code runsinit backs up settings.json, edits it atomically, and finds its own entry by the hook name weave-ward, so your other hooks and settings are untouched. It installs at user level, so it covers every project. The default timeout is 10 seconds.
Dashboard
Set WEAVE_DASHBOARD_URL (and WEAVE_API_KEY) where you run the agent, and each decision is reported to a local Weave API dashboard as qwen-code. Only the decision and the tool name are sent, never command or argument contents. Reporting never changes a decision and gives up after 250 ms.
Verified
Built against Qwen Code's hooks documentation, and its tool names and parameter schemas in packages/core/src/tools.
Live-checked in Qwen Code 0.26.6. It ran headless against a local scripted model, so no API key or account was involved, and every decision was confirmed by Ward's signed receipts:
- a
read_fileand agrep_searchof denied paths were blocked, and the model got the WARD reason as the tool result; - an allowed read and
globwent through; - with a user rule in
settings.jsonallowingcurl, Ward still blockedcurlto an unlisted host and allowed it to a listed one; - the same calls replayed by Qwen Code's background memory agent were decided too.
🕸️ Part of Weave Protocol
One WARD.md policy for every agent you run, locally or at scale, plus the tools around it.
| Package | What it does | |---|---| | Ward | The WARD.md policy standard and the tool-call evaluator every adapter shares | | Mund | Scans content for prompt injection (English and Chinese), secrets, PII and exfiltration | | Hord | Encrypted vaults, PII tokenization, sandboxes, capability tokens, attestations | | Dōmere | Audit threads, compliance checkpoints, GDPR and CCPA records, anchoring | | Witan | Multi-agent consensus and spending caps | | Hundredmen | MCP proxy that enforces WARD.md on tool calls | | Tollere | Supply-chain checks: typosquats, CVEs, suspicious version diffs | | Browser | WARD.md and injection scanning for Playwright browser agents | | Adapters | WARD.md in Claude Code, Antigravity, MSAF, Gemini CLI, Codex, OpenCode, Cursor and Qwen Code | | Adversary · AgentSecBench | Red-team engine and locked benchmark | | API · CLI · LangChain | REST API and dashboard, setup CLI, LangChain.js integration | | full | Every defensive package in one install | | Yoxallismus | Post-quantum hybrid cipher (experimental beta) |
License
Apache-2.0
