The Session JSON adapter is a small compatibility importer for Claude Code, Codex, and similar agent session exports. It reads a JSON array or a JSON object containing tool-call entries and normalizes those entries into an AgentScope trace.
This is intentionally permissive. Agent session formats change, so the adapter looks for common field names instead of requiring one exact schema.
npm run agentscope -- import-session examples/agent-session.json
npm run agentscope -- validate .agentscope/*.trace.json
npm run devThen import the generated trace via the Web UI Import button or drag and drop.
The input may be either:
- A JSON array of tool-call entries
- A JSON object with one of these array fields:
events,messages,actions,entries,toolCalls,tool_calls, orsteps
Example:
{
"title": "Fix auth token expiry test",
"agent": "Claude Code",
"events": [
{
"tool": "Read",
"input": {
"file_path": "src/auth/session.test.ts"
},
"summary": "Read the failing test before editing code."
},
{
"tool": "Bash",
"input": {
"command": "npm test -- session.test.ts"
},
"output": "PASS src/auth/session.test.ts"
}
]
}The adapter recognizes common fields from Claude/Codex-like logs:
| AgentScope field | Source fields checked |
|---|---|
| Tool name | tool, toolName, tool_name, name, type, action, function.name |
| Input object | input, tool_input, arguments, args, params, request |
| File path | file, path, file_path, filepath, target_file, or the same fields under input |
| Command | command, cmd, or the same fields under input |
| Diff | diff, patch, or the same fields under input |
| Output | output, stdout, stderr, content, result, response, tool_result |
| Timestamp | timestamp, time, startedAt, started_at, created_at |
| Duration | duration, elapsed, durationMs, duration_ms, elapsed_ms |
The adapter maps common tool names and content to AgentScope action types:
| Source signal | AgentScope action type |
|---|---|
Read, View, Open, Cat, Grep, Search with a file |
read_file |
Edit, Write, MultiEdit, apply_patch, Replace, or a patch/diff |
edit_file |
Bash, Shell, Terminal, Exec, Command, or a command field |
run_command |
| Command/test output with failure keywords | test_failed |
| Command/test output with pass/success keywords | test_passed |
Summarize, Report, Wrap up |
generate_summary |
Unrecognized entries are skipped. If no supported tool-call actions are found, the CLI exits with an error.
The adapter generates a valid single-run trace:
id:run-session-<timestamp>title: fromtitle,task,summary, or the file nameagent: explicitagentif present, otherwise inferred from Claude/Codex stringsbranch: explicitbranchif present, otherwise current git branchstatus:failedif anytest_failed, otherwisepassedif anytest_passed, otherwisewarningtrustScore: 85 for passed, 60 for warning, 35 for failedfilesChanged: unique edited filescommands: command and test action count
- This is a best-effort importer, not a native parser for every upstream session format.
- It only reads files you explicitly pass to the CLI.
- It does not scrape private IDE data or call external services.
- If a native export format changes, the mapping may need a small update.