Add transcript backup tracking system and pre-compact hook improvements
- pre-compact-backup.sh: derive transcript path from session_id+cwd (no longer relies on transcript_path field that Claude Code stopped providing); register each backup in tracking.json after saving - extract-transcripts.py: new script managing tracking.json — register, list, extract conversation text, mark-processed modes - list-transcripts-here.sh: thin wrapper for extract-transcripts --list using $(pwd); needed because SKILL.md bang commands reject $() substitution - install-hooks.sh: now also symlinks skill-helper scripts into ~/.claude/scripts/ via a curated SKILL_HELPERS list - Memory docs: new script-extract-transcripts.md, script-list-transcripts-here.md; updated skill-log.md, script-install-hooks.md, MEMORY.md index Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
41
memory/script-extract-transcripts.md
Normal file
41
memory/script-extract-transcripts.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# script: extract-transcripts
|
||||
|
||||
**Location:** `claude-foundations/scripts/extract-transcripts.py`
|
||||
**Symlinked to:** `~/.claude/scripts/extract-transcripts.py`
|
||||
|
||||
## Purpose
|
||||
|
||||
Manages the transcript backup tracking system. Registers pre-compaction JSONL backups, lists unprocessed ones per project, extracts readable conversation text for analysis, and marks entries as processed after a log is written.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
# Register a new backup (called by pre-compact-backup.sh hook)
|
||||
python3 ~/.claude/scripts/extract-transcripts.py \
|
||||
--register BACKUP_NAME --session-id SESSION_ID --cwd PROJECT_CWD
|
||||
|
||||
# List unprocessed transcripts for a project (used by /log skill)
|
||||
python3 ~/.claude/scripts/extract-transcripts.py --list /home/paul/dev/claude/projects/foo
|
||||
# → compact JSON array of {backup, session_id, saved_at, path, exists}
|
||||
|
||||
# Extract readable conversation from one backup (used by /log Sonnet subagent)
|
||||
python3 ~/.claude/scripts/extract-transcripts.py --extract BACKUP_NAME
|
||||
|
||||
# Mark all unprocessed backups for a project as done
|
||||
python3 ~/.claude/scripts/extract-transcripts.py \
|
||||
--mark-all-processed /home/paul/dev/claude/projects/foo --log-file memory/log/YYYY-MM-DD.HHMMSS-transcripts.md
|
||||
```
|
||||
|
||||
## How it works
|
||||
|
||||
- Tracking state lives in `~/.claude/transcript-backups/tracking.json`, keyed by backup filename
|
||||
- Each entry: `{session_id, cwd, saved_at, processed, log_file, processed_at}`
|
||||
- `--list` filters by `cwd == project_cwd` and `processed == false` — output is metadata only (no content), safe for skill pre-gathering
|
||||
- `--extract` reads the JSONL, skips sidechain entries, extracts `user`/`assistant` message text, truncates per-message at 3000 chars
|
||||
- Tool use blocks are summarised as `[tool: ToolName(key=...)]` rather than shown in full
|
||||
|
||||
## Gotchas
|
||||
|
||||
- `sys.exit(0)` inside a bare `except: pass` block is caught as SystemExit — always use specific exception types or `break` when early exit is needed inside exception handlers
|
||||
- The JSONL entries for `type: "user"` without a `message` field (e.g., file-history snapshots) are skipped silently
|
||||
- Old backups with `-auto` suffix (from before this system) are not in tracking.json and will never appear in `--list`
|
||||
Reference in New Issue
Block a user