ce-session-extract

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Session extract

会话提取

Agent-facing primitive. Extract filtered content from a single Claude Code, Codex, or Cursor session file — either a conversation skeleton or error signals.
This skill exists so that agents do not read multi-megabyte session files into context. The scripts under
scripts/
own the JSONL shape knowledge and emit a narrative-readable digest.
面向Agent的基础工具。从单个Claude Code、Codex或Cursor会话文件中提取过滤后的内容——可以是对话框架或错误信号。
该技能的存在是为了避免Agent将数兆字节的会话文件读入上下文。
scripts/
目录下的脚本掌握JSONL格式相关知识,并生成便于阅读的摘要内容。

Arguments

参数

Space-separated positional args:
  1. <file>
    — absolute path to a session JSONL file (typically a
    file
    value returned by
    ce-session-inventory
    ).
  2. <mode>
    skeleton
    or
    errors
    .
  3. <limit>
    (optional)
    head:N
    or
    tail:N
    to cap output at N lines (e.g.,
    head:200
    ). Omit to return full extraction.
空格分隔的位置参数:
  1. <file>
    — 会话JSONL文件的绝对路径(通常是
    ce-session-inventory
    返回的
    file
    值)。
  2. <mode>
    skeleton
    (框架)或
    errors
    (错误)。
  3. <limit>
    (可选)——
    head:N
    tail:N
    ,用于将输出限制为N行(例如
    head:200
    )。省略则返回完整提取结果。

Execution

执行

Skeleton mode — narrative of user messages, assistant text, and collapsed tool-call summaries:
bash
cat <file> | python3 scripts/extract-skeleton.py
Errors mode — just error signals:
bash
cat <file> | python3 scripts/extract-errors.py
If
<limit>
is
head:N
, pipe through
head -n N
. If
tail:N
, pipe through
tail -n N
. Apply the limit after the Python script, never before — the
_meta
line is emitted last and a head cap may drop it; that is acceptable when the caller asks for a head cap.
Return the raw stdout verbatim. Do not paraphrase, annotate, or synthesize — the caller does synthesis across multiple sessions.
框架模式 — 用户消息、助手文本和折叠后的工具调用摘要的叙述性内容:
bash
cat <file> | python3 scripts/extract-skeleton.py
错误模式 — 仅返回错误信号:
bash
cat <file> | python3 scripts/extract-errors.py
如果
<limit>
head:N
,则通过管道传递给
head -n N
;如果是
tail:N
,则传递给
tail -n N
。限制操作应在Python脚本之后执行,绝不能在之前——
_meta
行最后输出,头部限制可能会丢弃该行;当调用方要求头部限制时,这种情况是可接受的。
原样返回原始标准输出。不要进行转述、注释或合成——调用方会在多个会话间进行合成操作。

What each mode returns

各模式返回内容

Skeleton

框架模式

Narrative output with one logical event per block, separated by
---
:
  • User messages (text only, no tool results, framework wrapper tags stripped)
  • Assistant text (no thinking/reasoning blocks — those are internal or encrypted)
  • Tool call summaries; 3+ consecutive same-name calls are collapsed (e.g.,
    [tools] 5x Read (file1, file2, +3 more) -> all ok
    )
Ends with a
_meta
line:
{"_meta": true, "lines": N, "parse_errors": N, "user": N, "assistant": N, "tool": N}
.
叙述性输出,每个逻辑事件为一个块,用
---
分隔:
  • 用户消息(仅文本,无工具结果,已去除框架包装标签)
  • 助手文本(无思考/推理块——这些是内部内容或已加密)
  • 工具调用摘要;连续3次及以上同名调用会被折叠(例如
    [tools] 5x Read (file1, file2, +3 more) -> all ok
结尾包含
_meta
行:
{"_meta": true, "lines": N, "parse_errors": N, "user": N, "assistant": N, "tool": N}

Errors

错误模式

One line per error, separated by
---
:
  • Claude Code: tool results with
    is_error: true
  • Codex:
    exec_command_end
    events with non-zero exit or non-empty stderr
  • Cursor: always empty — Cursor agent transcripts do not log tool results
Ends with a
_meta
line:
{"_meta": true, "lines": N, "parse_errors": N, "errors_found": N}
.
每个错误占一行,用
---
分隔:
  • Claude Code:
    is_error: true
    的工具结果
  • Codex:
    exec_command_end
    事件中退出码非零或stderr非空的情况
  • Cursor:始终为空——Cursor Agent的会话记录不记录工具结果
结尾包含
_meta
行:
{"_meta": true, "lines": N, "parse_errors": N, "errors_found": N}

Error handling

错误处理

If the file cannot be read, let the error surface to the caller. If
_meta
reports
parse_errors > 0
, return the output as-is — partial extraction is still useful and the caller decides whether to widen the search or deep-dive further.
如果无法读取文件,让错误直接暴露给调用方。如果
_meta
报告
parse_errors > 0
,则原样返回输出——部分提取结果仍然有用,调用方可决定是否扩大搜索范围或进一步深入研究。