Repository navigation
feat: add Command Code parser - #51
Conversation
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
EntelligenceAI PR SummaryAdds 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;
Review Scorecard
Safe to merge with a low blast radius; code quality rated Excellent (5/5): the review found nothing to flag. Key Findings:
Evaluated against
|
WalkthroughAdds 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. ChangesFiles
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 Files
Registered Command Code as a supported agent and added local discovery for Files
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
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.
|
lgtm! thanks for the parser @Monika-rolls |
Summary
Adds a parser for Command Code, which writes one JSONL file per session at
~/.commandcode/projects/<project>/<session-id>.jsonl(override withAGENTPLAY_COMMANDCODE_HOMES). It follows the Gemini CLI parser's layout.Detection: the
type: "session"header (stringidandcwd, intversion). Atype: "message"record withparentIdandmessage.meta.sourcecovers 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
userorfollowupprompt opens a turn. Asteeringmessage (typed while the agent works) joins the running turn.injectedmessages open none.Failures:
tool_resulthas no error flag, so a call is an error when:Exit code: <n>;shell_outputreports a non-zero code on its own line;[sub-agent interrupted, ...).Every rule matches wording seen in real sessions.
Tokens: one cost event per request from
usage.inputTokensincludescacheReadTokens.Subagents: main lane only. The
agenttool leaves no separate transcript.Command Code's own
usage.costUsdis not used, matching the rate-card approach the other parsers take. Sessions on a model the rate card doesn't list (such asdeepseek/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
gitcommands.pytest tests/core: 858 passed. That includes the newtest_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 untouchedmainon this machine. Eight need symlink privileges, and one istest_robustness.py's malformed host/origin case, which failed on a different parameter in each run.ruff check src testsandscripts/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.relpathraises for a path whose last part isnul. 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 checkpasses (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