Skip to content

feat: add Qwen Code parser - #70

Open
RHL-RWT-01 wants to merge 1 commit into
Entelligence-AI:mainfrom
RHL-RWT-01:feat/qwen-code-parser
Open

RHL-RWT-01 wants to merge 1 commit into
Entelligence-AI:mainfrom
RHL-RWT-01:feat/qwen-code-parser

Conversation

@RHL-RWT-01

Copy link
Copy Markdown

Summary

Adds Qwen Code as a supported agent. Closes #65

  • Parser (parsers/qwen_code.py): reads the uuid-linked ChatRecords in ~/.qwen/projects/<project>/chats/<session-id>.jsonl. User prompts open turns (mid-turn user messages join the running turn), assistant functionCall parts become tool spans, and results are matched by toolCallResult.callId (falling back to functionResponse.id). status of error / cancelled marks the tool failed, and a call with no result stays unset. Duplicate uuids keep the last copy, sidechain records are skipped, and chat_compression records count as compactions.
  • Tokens: completion is totalTokenCount - promptTokenCount when a total is recorded, so thoughts are not counted twice by OpenAI-compatible providers (which include them in candidatesTokenCount). Otherwise it is candidates + thoughts.
  • Tools (tool_taxonomy.py): the 11 Qwen Code 0.26 tool names mapped to canonical tools (run_shell_command → Bash, read_file → Read, edit → Edit, write_file → Write, agent → Task, …).
  • Discovery: ~/.qwen home, overridable with AGENTPLAY_QWEN_HOMES. Shows up in agentplay agents. The indexer skips sessions with no prompt or reply. README tables are updated.
  • Detection (base.py): a qwen-code rule placed before the Claude Code and opencode rules, since both of those also match Qwen records by shape.

Test plan

  • make check: ruff clean, pytest 1501 passed, viewer typecheck clean, vitest 354 passed, check_clean.py clean.
  • test_qwen_code_parser.py (44 tests): detection for every record type (Claude Code and opencode records are not claimed), turns and tools, every status value, missing results, mid-turn messages, sidechains, token math, compaction, malformed and empty input, discovery and env override, and no-leak tests on prompts, output, arguments and shell commands (verb only).
  • Fixtures: two redacted real Qwen Code 0.26.5 sessions. failed_read has two failed reads (invalid_tool_params). edit_then_read has a failed write (edit_requires_prior_read) followed by a successful read. Tests check the classified events and that no placeholder text, path or file name reaches the map.
  • End to end against a real ~/.qwen with a temp AGENTPLAY_HOME: agentplay agents lists qwen-code, and agentplay build --agents qwen-code built 13 sessions (1 skipped, no events). Grepping the built maps for prompt text, replies, file contents, error messages and the home path found nothing.

Not tested: none of the captured sessions ran a shell command, so the shell path (verb, exit code) is covered only by synthetic records. Subagent transcripts are not read (main lane only). Not run on Windows.

  • make check passes
  • No prompt text, model output, tool input/output, file contents or command arguments can reach a map, a log line or the viewer (redaction contract)
  • No new network calls or Python runtime dependencies

Qwen Code keeps each session in
~/.qwen/projects/<project>/chats/<session-id>.jsonl (override with
AGENTPLAY_QWEN_HOMES). Records are uuid-linked ChatRecords whose messages
carry Gemini-style `parts`: text, thoughts, functionCall and
functionResponse.

- Detection runs before the Claude Code and opencode rules, which both
  match Qwen records by shape.
- Tool failures come from toolCallResult.status (error, cancelled); a call
  with no result stays unset.
- Completion tokens are total - prompt when a total is recorded, so
  thoughts are not counted twice by OpenAI-compatible providers.
- chat_compression system records count as compactions.
- Subagent transcripts are not read (main lane only).

Fixtures are two redacted real Qwen Code 0.26.5 sessions, one with failed
tool calls.

Closes Entelligence-AI#65
Copilot AI balanced review requested due to automatic review settings November 3, 2026 05:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@entelligence-ai-pr-reviews entelligence-ai-pr-reviews Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entelligence: code quality 5/5 — Excellent.

@entelligence-ai-pr-reviews

entelligence-ai-pr-reviews Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

EntelligenceAI PR Summary

Adds Qwen Code session discovery and parsing, including turn and tool spans, tool results and failures, token usage, compactions, and tool-name aliases. Registers the new agent and documents its location and home-directory override, with fixtures and tests covering parsing, discovery, and map output.


Review Scorecard

Dimension Rating Basis
Code Quality ●●●●● 5/5 — Excellent no critical/significant findings — rated Excellent
Blast Radius Low _output_text is referenced in 1 other file(s), 7 file(s) / ~649 line(s) changed (size only — not a blast signal)
Merge Confidence ●●●●● 5/5 — Safe to Merge equals code quality; blast radius is shown for context only
Test Coverage — unavailable dependencies failed to install
Security Scan No findings on changed lines SonarQube · Semgrep · TruffleHog on 12 changed files

Safe to merge with a low blast radius; code quality rated Excellent (5/5): the review found nothing to flag.

Key Findings:

  • No critical or significant issues found
Evaluated against
  • 12/12 changed files reviewed
  • criteria: correctness, security & access control, robustness & error handling, concurrency & data integrity, repo conventions / steering docs
  • steering docs: none found in repo
  • PR checks: unit tests (unavailable) · security scan (SonarQube, Semgrep, TruffleHog on 12 changed files)

@entelligence-ai-pr-reviews

Copy link
Copy Markdown

Walkthrough

Adds end-to-end Qwen Code transcript support, from configurable local discovery and session indexing through parsing, tool normalization, and span generation. Documentation and tests cover transcript formats, tool workflows, usage metadata, compaction events, and malformed-input handling.

Changes

Files

  • README.md
  • python/src/agentplay/discover.py

Documents Qwen Code support, transcript locations, working-directory detection, and the AGENTPLAY_QWEN_HOMES setting. Registers configurable Qwen homes with agent discovery.

Files

  • python/src/agentplay/_core/ingestion/coding_agent/_sources/local/parsers/__init__.py
  • python/src/agentplay/_core/ingestion/coding_agent/_sources/local/parsers/base.py
  • python/src/agentplay/_core/ingestion/coding_agent/_sources/local/parsers/qwen_code.py

Adds Qwen record detection and exports a parser that converts JSONL sessions into shared session, turn, and tool spans. Parsing handles sidechains, duplicate UUIDs, tool results and failures, usage data, metadata, edit evidence, and compaction events.

Files

  • python/src/agentplay/_core/ingestion/coding_agent/_sources/local/source.py

Discovers Qwen session files under configured homes, extracts session IDs and working directories, and indexes valid transcripts while skipping invalid or unsuitable files. Dispatches indexed sessions to the Qwen parser.

Files

  • python/src/agentplay/_core/ingestion/coding_agent/tool_taxonomy.py

Adds Qwen Code tool aliases that normalize built-in tool names to canonical names while leaving unlisted meta and MCP tools unchanged.

Files

  • python/tests/core/fixtures/qwen_code/edit_then_read.jsonl
  • python/tests/core/fixtures/qwen_code/failed_read.jsonl
  • python/tests/core/test_parser_robustness.py
  • python/tests/core/test_qwen_code_parser.py
  • python/tests/core/test_tool_taxonomy.py

Adds transcript fixtures and coverage for parsing, detection, local discovery, tool workflows and failures, token accounting, compaction records, malformed input, privacy-safe maps, and tool alias mappings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a parser for Qwen Code

2 participants