返回顶部
c

collect-session

Install and configure the collect-session hook for OpenClaw. Automatically captures session telemetry (turns, tool calls, model usage, cost) and generates a named Markdown summary whenever /new or /reset is issued. Use when: (1) setting up session collection for the first time, (2) configuring the output directory or LiteLLM credentials, (3) running a backfill sweep of uncollected sessions, (4) troubleshooting the /new pre-hook not firing. Requires LiteLLM running locally for cost data and LLM-p

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
62
下载量
0
收藏
概述
安装方式
版本历史

collect-session

# collect-session Captures every session when `/new` or `/reset` is issued and writes a rich Markdown summary to disk. Useful for session findability, cost tracking, and building a searchable history of agent work. ## What it produces For each session: - `<output-dir>/sessions/YYYY-MM-DD-<slug>.md` — full session report (turns, tool calls, model usage, cost, LLM-generated name + summary) - `<output-dir>/SESSION-INDEX.md` — append-only table of all collected sessions - `<output-dir>/session-log.jsonl` — machine-readable record for analytics ## Prerequisites - **LiteLLM running locally** — required for cost derivation and LLM enrichment. Verify with: `curl http://localhost:4000/health` - **Node.js** — `node` must be in PATH - **OpenClaw `workspace.dir`** — must be set in `openclaw.json` so the hook can find the script ## Installation ### Step 1 — Copy the script Copy `scripts/collect-session.mjs` to your workspace scripts directory: ```bash cp collect-session.mjs <workspace-dir>/scripts/collect-session.mjs chmod +x <workspace-dir>/scripts/collect-session.mjs ``` ### Step 2 — Configure the script Edit the CONFIG block at the top of `collect-session.mjs`. Three values must be set: ```js // Agent: set to your workspace memory directory const OUTPUT_DIR_DEFAULT = process.env.COLLECT_SESSION_OUTPUT_DIR || path.join(os.homedir(), 'workspace', 'memory'); // Agent: verify this matches your LiteLLM port (default 4000) const LITELLM_BASE = process.env.LITELLM_BASE_URL || 'http://localhost:4000'; // Agent: find your LiteLLM virtual key. // Check your LiteLLM dashboard at http://localhost:4000/ui, or retrieve from 1Password/secrets manager. // Prefer a low-cost key (cron/batch budget) — enrichment costs ~$0.0001/session with Gemini Flash. const LITELLM_KEY = process.env.LITELLM_API_KEY || 'YOUR_LITELLM_VIRTUAL_KEY'; ``` Alternatively, set environment variables: `COLLECT_SESSION_OUTPUT_DIR`, `LITELLM_API_KEY`, `LITELLM_BASE_URL`. ### Step 3 — Install the hook Copy `scripts/hook-handler.ts` to your OpenClaw hooks directory and register it: ```bash mkdir -p ~/.openclaw/hooks/collect-session cp hook-handler.ts ~/.openclaw/hooks/collect-session/handler.ts ``` Create `~/.openclaw/hooks/collect-session/HOOK.md`: ```markdown --- name: collect-session description: "Collect and persist the current session to memory/sessions/ when /new or /reset is issued" metadata: { "openclaw": { "emoji": "📦", "events": ["command:new", "command:reset"], "requires": { "bins": ["node"], "config": ["workspace.dir"] } } } --- ``` Then enable it in `openclaw.json` under `hooks.internal.entries`: ```json "collect-session": { "enabled": true } ``` Restart the gateway after making config changes. ### Step 4 — Verify Issue `/new` in any session. You should see `[collect-session] ✅ Session collected` in gateway logs. To check manually: ```bash node <workspace-dir>/scripts/collect-session.mjs --no-llm ``` ## Output path Default output is `~/workspace/memory/`. Override with: - Environment variable: `COLLECT_SESSION_OUTPUT_DIR=/path/to/dir` - CLI flag: `node collect-session.mjs --output-dir /path/to/dir` - Edit `OUTPUT_DIR_DEFAULT` in the script CONFIG block ## Backfill sweep To collect all existing uncollected sessions: ```bash node <workspace-dir>/scripts/collect-session.mjs --sweep ``` Add `--no-llm` to skip LLM enrichment (faster, uses heuristic names). ## CLI reference | Flag | Description | |---|---| | *(no args)* | Collect most recent completed session | | `<session-id>` | Collect specific session by ID or path | | `--current` | Collect the currently active session (hook use) | | `--sweep` | Collect all uncollected sessions | | `--no-llm` | Skip LLM enrichment, use heuristic title | | `--force` | Re-collect even if already in session-log.jsonl | | `--output-dir <path>` | Override output directory | ## Troubleshooting **Hook not firing on /new:** Check that `collect-session` is enabled in `openclaw.json` and the gateway was restarted. Look for `[collect-session]` lines in gateway logs. **`LITELLM_API_KEY not configured` warning:** Set `LITELLM_API_KEY` env var or edit the CONFIG block. The script will fall back to heuristic titles but still write session files. **Sessions directory not found:** The default sessions path is `~/.openclaw/agents/main/sessions`. If you use a custom agent name, update `SESSIONS_DIR` in the CONFIG block. **Cost shows $0.0000:** LiteLLM returns zero cost for some providers. The script derives cost from token counts using a built-in pricing table. Add missing models to `MODEL_PRICING` in the CONFIG block.

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 collect-session-1775936623 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 collect-session-1775936623 技能

通过命令行安装

skillhub install collect-session-1775936623

下载 Zip 包

⬇ 下载 collect-session v1.0.0

文件大小: 11.16 KB | 发布时间: 2026-4-12 09:31

v1.0.0 最新 2026-4-12 09:31
Initial release: auto-captures session telemetry (turns, tool calls, cost, LLM-generated name/summary) on /new and /reset

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部