SuperAPI AI 工具集

pi-session-logs

智能体与模型

查看项目

更新于 10-15 23:47

技能介绍

用途:查询 pi 智能体会话日志。日志以 JSON Lines(.jsonl)文件存放在 ~/.pi/agent/sessions/<project-path>/,每行是一个 JSON 对象,代表一个会话事件。

主要能力:可加载单个或整个项目的会话,按事件类型过滤,提取工具调用、Bash 命令、读取的文件路径、思考内容,查看 hook 错误与 VCS 通知,并统计事件数量、工具调用次数和 token 用量。

事件类型:session(元数据:version、id、timestamp、cwd)、message(用户或助手消息,含内容与工具调用)、model_change(provider/model 切换)、thinking_level_change(思考级别调整)、custom_message(hook 输出/错误、VCS 通知)、compaction(会话截断时的上下文摘要)。

使用方式:在 Nushell 中定义辅助函数 open-jsonl [file: path] { open $file --raw | lines | each { from json } },然后加载会话,例如 open-jsonl ~/.pi/agent/sessions/<project>/<session>.jsonl;加载项目全部会话可用 ls ~/.pi/agent/sessions/<project>/*.jsonl | each { |f| open-jsonl $f.name } | flatten。查找工具调用时,先 where type == "message" 且 message.role == "assistant",再 get message.content | flatten,然后 where type == "toolCall",可 select id name arguments,或按 name == "bash" 取 arguments.command、按 name == "read" 取 arguments.path。思考内容用 where type == "thinking" | get thinking。hook 错误用 where type == "custom_message" | where customType == "hook-error"。统计可用 get type | uniq --count,或对 message.usage 做 math sum。

限制:会话路径包含带 -- 前缀/后缀的编码目录路径;工具调用嵌套在 assistant 消息的 message.content[] 中,需用 flatten 展开;时间戳为 ISO 8601 字符串或 Unix 毫秒。其余细节暂未提供。