Community程式設計與開發github.com

session-logs

使用 jq 搜尋並分析你自己的對話記錄(較舊的上層對話)。

session-logs 是什麼?

這個技能讓 AI 代理能直接搜尋與分析儲存在 JSONL 檔案中的完整對話歷史記錄。它最適合用於使用者提及較舊的對話、上層對話,或需要查詢未存在於記憶檔案中的歷史情境時。此技能支援 OpenClaw 平台,並且與所有使用其狀態目錄結構的代理相容。此技能透過讀取位於 `$OPENCLAW_STATE_DIR/agents/<agentId>/sessions/` 路徑下的 `sessions.json` 索引檔與各個 `<session-id>.jsonl` 轉錄檔來運作。它包含處理有效記錄與歸檔記錄(如 `.reset.*` 和 `.deleted.*` 檔案)的 Bash 指令碼,確保能完整回顧歷史。此外,它也提供大量實用的 jq 查詢範例,讓使用者能根據日期列出記錄、依角色(使用者/助理)篩選訊息、搜尋關鍵字、計算總成本,以及分析工具使用情況。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/clawdbot/clawdbot/tree/main/skills/session-logs

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

session-logs 是做什麼的?

搜尋儲存在 session JSONL 檔案中的完整對話歷史記錄。當使用者提及較舊的對話、上層對話,或詢問不在記憶檔案中的歷史脈絡時,請使用此技能。

觸發時機

當使用者問及先前的對話、上層對話,或不在記憶檔案中的歷史脈絡時,請使用此技能。

檔案位置

Session 記錄位於作用中狀態目錄下: $OPENCLAW_STATE_DIR/agents/<agentId>/sessions/(預設:~/.openclaw/agents/<agentId>/sessions/)。 請使用系統提示字串 Runtime 行中的 agent=<id> 值。

  • sessions.json - 將 session 鍵值對應到 session ID 的索引
  • <session-id>.jsonl - 每個 session 的完整對話記錄
  • <session-id>.jsonl.reset.<timestamp>Z - 透過 /new 或 /reset 歸檔的記錄
  • <session-id>.jsonl.deleted.<timestamp>Z - 當 session 被刪除時歸檔的記錄

搜尋歷史記錄時,請一併納入歸檔的變體(.reset.*, .deleted.*)——它們仍包含真實的對話內容。下列純 glob 範例僅會匹配到作用中的 *.jsonl 檔案;若需要完整回顧,請使用「包含歸檔記錄」的程式碼片段。

結構

每個 .jsonl 檔案包含的訊息具有以下欄位:

  • type:"session"(中繼資料)或 "message"
  • timestamp:ISO 時間戳
  • message.role:"user"、"assistant" 或 "toolResult"
  • message.content[]:文字、思考過程或工具呼叫(篩選 type=="text" 以取得人類可讀的內容)
  • message.usage.cost.total:每個回應的成本

常用查詢

包含歸檔記錄(.reset.*, .deleted.*)

# Bash 輔助函式,輸出所有可搜尋的記錄路徑——包含作用中與歸檔的。
# 會在本機儲存並還原 `nullglob`,以免影響呼叫端的 shell 選項。
AGENT_ID="<agentId>"
SESSION_DIR="${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/agents/$AGENT_ID/sessions"
list_session_transcripts() {
  local _nullglob_state
  _nullglob_state=$(shopt -p nullglob 2>/dev/null)
  shopt -s nullglob
  for f in "$SESSION_DIR"/*.jsonl \
           "$SESSION_DIR"/*.jsonl.reset.*Z \
           "$SESSION_DIR"/*.jsonl.deleted.*Z; do
    [ -f "$f" ] && printf '%s\n' "$f"
  done
  eval "$_nullglob_state"
}

在下方顯示純 *.jsonl glob 的地方,若需要包含歸檔的 session,請使用 list_session_transcripts(或等效的 find 呼叫):

find "$SESSION_DIR" -maxdepth 1 -type f \
  \( -name '*.jsonl' -o -name '*.jsonl.reset.*Z' -o -name '*.jsonl.deleted.*Z' \) -print

依日期與大小列出所有 session

AGENT_ID="<agentId>"
SESSION_DIR="${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/agents/$AGENT_ID/sessions"
for f in "$SESSION_DIR"/*.jsonl; do
  date=$(head -1 "$f" | jq -r '.timestamp' | cut -dT -f1)
  size=$(ls -lh "$f" | awk '{print $5}')
  echo "$date $size $(basename $f)"
done | sort -r

提示: 若想在清單中也包含歸檔的 .reset / .deleted 檔案,請將 for f in ... 那一行替換成 while-read 迴圈搭配 list_session_transcripts(請見上方程式碼片段)。while-read 模式能安全處理路徑中包含空格或其他 IFS 字元的情況:

while IFS= read -r f; do
  date=$(head -1 "$f" | jq -r '.timestamp' | cut -dT -f1)
  size=$(ls -lh "$f" | awk '{print $5}')
  echo "$date $size $(basename "$f")"
done < <(list_session_transcripts) | sort -r

找出特定日期的 session

AGENT_ID="<agentId>"
SESSION_DIR="${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/agents/$AGENT_ID/sessions"
for f in "$SESSION_DIR"/*.jsonl; do
  head -1 "$f" | jq -r '.timestamp' | grep -q "2026-01-06" && echo "$f"
done

從 session 中萃取使用者訊息

jq -r 'select(.message.role == "user") | .message.content[]? | select(.type == "text") | .text' <session>.jsonl

在助理回應中搜尋關鍵字

jq -r 'select(.message.role == "assistant") | .message.content[]? | select(.type == "text") | .text' <session>.jsonl | rg -i "keyword"

計算 session 總成本

jq -s '[.[] | .message.usage.cost.total // 0] | add' <session>.jsonl

每日成本總計

AGENT_ID="<agentId>"
SESSION_DIR="${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/agents/$AGENT_ID/sessions"
for f in "$SESSION_DIR"/*.jsonl; do
  date=$(head -1 "$f" | jq -r '.timestamp' | cut -dT -f1)
  cost=$(jq -s '[.[] | .message.usage.cost.total // 0] | add' "$f")
  echo "$date $cost"
done | awk '{a[$1]+=$2} END {for(d in a) print d, "$"a[d]}' | sort -r

計算 session 中的訊息數與 token 數

jq -s '{
  messages: length,
  user: [.[] | select(.message.role == "user")] | length,
  assistant: [.[] | select(.message.role == "assistant")] | length,
  first: .[0].timestamp,
  last: .[-1].timestamp
}' <session>.jsonl

工具使用分析

jq -r '.message.content[]? | select(.type == "toolCall") | .name' <session>.jsonl | sort | uniq -c | sort -rn

在所有 session 中搜尋某個詞組

AGENT_ID="<agentId>"
SESSION_DIR="${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/agents/$AGENT_ID/sessions"

# 僅限作用中 session:
rg -l "phrase" "$SESSION_DIR"/*.jsonl

# 作用中 + 歸檔(`.reset.*`, `.deleted.*`)——檢查可能已被壓縮/重設/刪除的內容時請使用這個:
rg -l "phrase" "$SESSION_DIR"/*.jsonl \
               "$SESSION_DIR"/*.jsonl.reset.*Z \
               "$SESSION_DIR"/*.jsonl.deleted.*Z 2>/dev/null

技巧

  • Session 是僅附加的 JSONL(每行一個 JSON 物件)
  • 大型 session 可能達數 MB——可使用 head/tail 來取樣
  • sessions.json 索引會將聊天提供者(discord、whatsapp 等)對應到 session ID
  • 已重設/壓縮的 session 有 .jsonl.reset.<timestamp>Z 後綴——仍包含完整的記錄且可搜尋。
  • 已刪除的 session 有 .jsonl.deleted.<timestamp>Z 後綴——同樣仍可搜尋。
  • 單純的 *.jsonl glob 會_遺漏_這兩種歸檔形式。需要完整歷史時,請明確將它們納入(請見上方的「包含歸檔記錄」程式碼片段)。

快速純文字提示(低干擾)

AGENT_ID="<agentId>"
SESSION_DIR="${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/agents/$AGENT_ID/sessions"
jq -r 'select(.type=="message") | .message.content[]? | select(.type=="text") | .text' "$SESSION_DIR"/<id>.jsonl | rg 'keyword'

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

1password

Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.

acp-router

Route plain-language requests for Claude Code, Cursor, Copilot, OpenClaw ACP, OpenCode, Gemini CLI, Grok Build, Qwen, Kiro, Kimi, iFlow, Factory Droid, Kilocode, or explicit ACP harness work into either OpenClaw ACP runtime sessions or direct acpx-driven sessions ("telephone game" flow). For coding-agent thread requests, read this skill first, then use only `sessions_spawn` for thread creation. Codex chat binding defaults to the native Codex app-server plugin unless ACP is explicit or background spawn needs ACP.

add-model-provider

Add and live-prove a model provider with non-interactive config one-liners, without exposing credentials.

agent-transcript

Requested GitHub PR/issue agent transcripts: redact, trim, preview, and insert safely.

apple-notes

Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.

apple-reminders

List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.

auto-qa

Run OpenClaw-wide autonomous QA and live/stress campaigns across independent subsystem lanes, with verified fixes and a resumable evidence report.

autoreview

Structured code review through the shared OpenClaw agent-skills installation.

bear-notes

Create, search, and manage Bear notes via grizzly CLI.

blacksmith-testbox

Run Blacksmith Testbox for CI-parity checks, secrets, hosted services, migrations, or builds local cannot reproduce.

block-kit

Use proactively for structured or interactive Slack replies, and when asked to author or validate native Slack Block Kit JSON.

blogwatcher

Monitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.

blucli

BluOS CLI (blu) for discovery, playback, grouping, and volume.

bluebubbles

Send and manage iMessages via BlueBubbles, including attachments, tapbacks, edits, replies, and groups.

browser-automation

Use when controlling web pages with the OpenClaw browser tool, especially multi-step flows, login checks, tab management, or recovery from stale refs/timeouts.

camsnap

Capture frames or clips from RTSP/ONVIF cameras and local webcams, including USB pan/tilt/zoom control.

canvas

Present HTML on connected OpenClaw node canvases, navigate/eval/snapshot, and debug canvas host URLs.

channel-message-flows

Use when running QA Lab channel message flow evidence.

clawdtributor

Clawtributor PRs here, last week or another window: discover conversation refs, recheck GitHub, rank by impact.

clawhub

Search ClawHub for plugins by default, or skills and agent Templates when requested; add Templates; install, verify, update, uninstall, publish, or sync skills.

相關技能