# Arya Qwen

An agent preset built from [Qwen Code](https://github.com/QwenLM/qwen-code)'s
prompt and history-compression prompt, on this harness's loop.

For the measured three-way comparison against the shipped `standard` preset and
Arya Standard, see [The presets compared](preset-comparison.md).

## What it is, and what it is not

Arya Qwen **is not** Qwen Code's agent loop. Whatever preset a session mounts, the
turn machine is DSH's `ReactLoopAgent`; a preset cannot replace it. What this
preset does is adopt the two artefacts that are actually calibrated for Qwen
models:

1. **Qwen Code's system prompt** — Core Mandates, Primary Workflows (software
   engineering and new applications), and Operational Guidelines (communicating,
   tone, security, tool use), with its tool names mapped onto this harness's:
   `read`, `write`, `edit`, `grep`, `glob`, the shell tool, `todo_write`,
   `exit_plan_mode`, `skill`, `ask_user_question`, `web_fetch`.
2. **Qwen Code's compression prompt** — an `<analysis>` drafting scratchpad that
   is stripped before the checkpoint enters history, followed by a 9-section
   `<state_snapshot>` XML envelope (`primary_request_and_intent`,
   `key_technical_concepts`, `files_and_code_sections`, `errors_and_fixes`,
   `problem_solving`, `all_user_messages`, `pending_tasks`, `current_work`,
   `next_step`), and a one-line resume trailer appended after the body rather
   than regenerated by the summarizer on every fold.

Both are vendored byte-for-byte from the upstream repository (Apache-2.0,
© 2025 Google LLC and Qwen) in `prompt.md`, `checkpoint-prompt.md` and
`summary-suffix.md`, with an adaptation pass that restores the identity line and
validates that no extraction hole survived.

## How it differs from Arya Standard

| | Arya Standard | Arya Qwen |
|---|---|---|
| Persona | Codex's base instructions | Qwen Code's instructions |
| Checkpoint | Codex `CONTEXT CHECKPOINT COMPACTION` + handoff prefix | Qwen Code compression prompt + `<state_snapshot>`, resume trailer |
| Analysis block | n/a | `<analysis>…</analysis>` stripped before commit |
| User messages kept verbatim | up to 20k tokens | none — the prompt reproduces them in `<all_user_messages>` |
| Tools, groups, plan mode, pruner | — | identical (the row list is derived from Arya Standard's) |
| Compaction policy knobs | shared settings group | shared settings group |
| Compaction tab | `aryaStandard` projection | the same projection; the engine commits the same `compaction/*` events |

The policy service is separate (`aryaQwenPolicy`, provided inside the preset's
own isolated realm), so a Qwen session can never read a Codex session's policy —
and both presets can be registered at once without either seeing the other's
state.

## Verified

Live on 2026-11-01 in the dev profile (plugin 0.111.0, `deepseek-account/deepseek-flash`):

- the session log records `agent-preset/selected: arya-qwen`, so the preset really
  mounted — not just appeared in the picker;
- one shell turn (`echo arya-qwen-ok`) replied `arya-qwen-ok` in 3 s, 69.1k input
  tokens, so the persona and the tool surface both work end to end;
- a manual `/compact` committed a checkpoint whose body **starts with
  `<state_snapshot>`**, contains **no `<analysis>` block**, and ends with the resume
  trailer — the two properties this port adds;
- that same fold found a defect: the span was only ~1,029 tokens, so the envelope
  was end-truncated and lost `<next_step>` (8 of 9 sections). 0.111.1 adds the
  `minBodyTokens` floor, and a regression test reproduces the tiny-span case.

## What was dropped

Qwen Code machinery this harness does not have: interaction modes and their
question guidance, `UserPromptSubmit` hooks, agent teams and the task/cron tools,
LSP, programmatic tool calling (`tools.<name>(…)` receivers), and the `qwen` CLI
itself. Plan mode, `todo_write` and `ask_user_question` are kept because the
harness provides equivalents.

## Boundary

- **Thinking parameters are not handled here.** `enable_thinking`, thinking
  budgets and `reasoning_content` belong to the LLM adapter; another plugin owns
  that, and this preset neither reads nor sets them.
- **Not byte-identical to Qwen Code's runtime prompt.** Qwen Code assembles its
  prompt from conditionals at runtime; this preset carries the extracted default
  configuration (todos on, code mode off) and documents the removals above.
- **Very short sessions do not fold.** The envelope needs roughly 800 tokens of body
  room; below that the fold is skipped (manual `/compact` reports why) instead of
  committing a checkpoint with its last sections cut off.
- **Qwen Code's microcompaction is not ported.** Upstream clears old tool results by
  tool class before paying for a summary; this bundle has the pruner and the
  checkpoint but not the per-tool-class clearing.
- **No projection of its own.** The Compaction tab's numbers come from the shared
  `aryaStandard` projection, which folds every session's `compaction/*` events
  regardless of preset.
