Skip to content

feat: add Command Code parser - #51

Merged
adityajha2005 merged 2 commits into
Entelligence-AI:mainfrom
Monika-rolls:feat/command-code-parser
Nov 2, 2026
Merged

adityajha2005 merged 2 commits into
Entelligence-AI:mainfrom
Monika-rolls:feat/command-code-parser

Conversation

@Monika-rolls

Copy link
Copy Markdown

Summary

Adds a parser for Command Code, which writes one JSONL file per session at ~/.commandcode/projects/<project>/<session-id>.jsonl (override with AGENTPLAY_COMMANDCODE_HOMES). It follows the Gemini CLI parser's layout.

  • Detection: the type: "session" header (string id and cwd, int version). A type: "message" record with parentId and message.meta.source covers a file whose header was cut off.

  • Indexer: walks projects/*/*.jsonl, skips the sibling *.checkpoints.jsonl, and takes the session id and cwd from the header.

  • Turns: a user or followup prompt opens a turn. A steering message (typed while the agent works) joins the running turn. injected messages open none.

  • Failures: tool_result has no error flag, so a call is an error when:

    • a shell tool's result starts with a non-zero Exit code: <n>;
    • shell_output reports a non-zero code on its own line;
    • the result opens with one of the CLI's refusals ("File has not been read yet", "Plan not approved", [sub-agent interrupted, ...).

    Every rule matches wording seen in real sessions.

  • Tokens: one cost event per request from usage. inputTokens includes cacheReadTokens.

  • Subagents: main lane only. The agent tool leaves no separate transcript.

Command Code's own usage.costUsd is not used, matching the rate-card approach the other parsers take. Sessions on a model the rate card doesn't list (such as deepseek/deepseek-v4-flash) show no cost.

Closes #50

Test plan

  • Three fixtures from real sessions (format version 3), with every prompt, reply, thought, path, argument value and output replaced by a placeholder. They cover reads, search, a failing run and its retry, writes and edits, a steering message, and failing git commands.

  • pytest tests/core: 858 passed. That includes the new test_command_code_parser.py, the new robustness and taxonomy rows, and a test that no fixture placeholder reaches a built map.

  • pytest (whole suite) on Windows 11, Python 3.13: 1402 passed, 9 failed. The same 9 fail on an untouched main on this machine. Eight need symlink privileges, and one is test_robustness.py's malformed host/origin case, which failed on a different parameter in each run.

  • ruff check src tests and scripts/check_clean.py: clean.

  • 13 local Command Code sessions: all indexed, 12 built, and every one of their 2,067 tool calls is classified. The 13th fails in the builder on any agent: on Windows Python 3.13, os.path.relpath raises for a path whose last part is nul. That needs its own fix, outside this PR.

  • Not run: make (not installed here; I ran its Python steps directly) and the viewer typecheck and tests (no viewer changes). Not tested on macOS or Linux.

  • make check passes (its Python steps pass; see above)

  • 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

Read Command Code sessions from ~/.commandcode/projects/<project>/<id>.jsonl
(override with AGENTPLAY_COMMANDCODE_HOMES).

Command Code's tool results carry no error flag, so a call fails when its
result starts with a non-zero `Exit code: <n>` (shell tools), reports one on a
line of its own (shell_output), or opens with one of the CLI's own refusals.
Steering messages join the running turn; injected messages open none.

Closes Entelligence-AI#50

@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 4/5 — Good. No critical or significant findings; nits only.

@entelligence-ai-pr-reviews

entelligence-ai-pr-reviews Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

EntelligenceAI PR Summary

Adds local discovery and parsing for Command Code session JSONL files, including configurable home directories and filtering of checkpoint files and sessions without usable messages. The parser builds session, turn, and tool spans with normalized tool names, token usage, and failure status inferred from tool-result text, enabling Command Code sessions to appear in Agentplay’s maps and timelines.

flowchart TD
    classDef newBehavior fill:#dcfce7,stroke:#16a34a,color:#14532d;
    A["Command Code session JSONL"] --> B["Local discovery and indexing"]
    B --> C["Detect session header or message fallback"]
    C --> D["Parse turns, tool calls, usage, and results"]
    D --> E["Build session and tool spans"]
    E --> F["Maps and timelines"]
    class A,B,C,D,E,F newBehavior;
Loading

🟢 Green = new or changed in this PR


Review Scorecard

Dimension Rating Basis
Code Quality ●●●●● 5/5 — Excellent no critical/significant findings — rated Excellent
Blast Radius Low changed symbols are referenced only within their own file(s); no high-impact surface touched, 7 file(s) / ~668 line(s) changed (size only — not a blast signal)
Merge Confidence ●●●●● 5/5 — Safe to Merge code quality 5/5 × Low blast radius
Test Coverage — unavailable dependencies failed to install
Security Scan No findings on changed lines SonarQube · Semgrep · TruffleHog on 3 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
  • 3/3 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 3 changed files)

@entelligence-ai-pr-reviews

entelligence-ai-pr-reviews Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Walkthrough

Adds end-to-end support for discovering, indexing, and parsing Command Code JSONL sessions as coding-agent traces. The update includes local-home configuration, tool-name normalization, span and usage extraction, failure detection, input robustness, documentation, and fixture-based tests.

Changes

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/command_code.py

Added and exported a Command Code JSONL parser that builds session, turn, and tool spans with message deduplication, prompt boundaries, tool-result matching, timestamps, usage, source metadata, failure status, and edit evidence. Agent detection recognizes Command Code records, and deeply nested JSON lines are skipped on RecursionError.

Files

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

Registered Command Code as a supported agent and added local discovery for ~/.commandcode/projects/*/*.jsonl, configurable through AGENTPLAY_COMMANDCODE_HOMES. Session indexing validates headers and messages, excludes checkpoints and unrelated or promptless sessions, records discovery outcomes, and dispatches valid sessions to the parser; the README documents coverage and failure detection.

Files

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

Added and registered a 12-entry Command Code tool alias map to normalize built-in shell, file, search, directory, web, todo, and agent tools to canonical names.

Files

  • python/tests/core/fixtures/command_code/edit_and_steer.jsonl
  • python/tests/core/fixtures/command_code/failed_shell.jsonl
  • python/tests/core/fixtures/command_code/read_and_search.jsonl
  • python/tests/core/test_command_code_parser.py
  • python/tests/core/test_parser_robustness.py
  • python/tests/core/test_tool_taxonomy.py

Added anonymized session fixtures and tests for parsing, discovery, indexing, malformed and deeply nested input, steering, tool failures and retries, usage and edit evidence, privacy-safe map generation, and tool taxonomy mappings.

…ed lines

Discovery counted a user message marked `meta.injected` as a prompt, but the
parser opens no turn for it, so a session of only injected text was indexed
and built an empty map. Skip those messages in the discovery check too.

A deeply nested JSON line in a file's head made `detect_agent` raise
RecursionError, which escaped the index walk and dropped every session in the
scan, for any agent. Skip that line like any other unparseable one, and do the
same in the Command Code header scan.

@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.

@adityajha2005

Copy link
Copy Markdown
Contributor

lgtm! thanks for the parser @Monika-rolls

@adityajha2005
adityajha2005 merged commit 80a3e28 into Entelligence-AI:main Nov 2, 2026
18 checks passed
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 Command Code

3 participants