ckb/.agents/skills/ckb-add-conversation/SKILL.md
Michał Kopeć 6f5534fabf Template 1.14.0: session identity from git on workload, log and conversations
- Rule E resolves git user.name/user.email once per session; OS user as
  stated fallback.
- Rule D: one workload file per person per day,
  YYYY-MM-DD_<author>_summary.md with type: session frontmatter; older
  files read as before.
- Rule B log format gains an optional, lint-neutral **Author:** line;
  wiki/log.md header and ckb-upgrade example updated.
- save_conversation.py records an author row (--author override); smoke
  fixture passes a fixed author.
- ckb-project-summary and ckb-module cite the new workload name.
- D-0004 records the decision; manual, READMEs and changelogs in English
  and Polish.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-16 09:45:22 +02:00

235 lines
12 KiB
Markdown

---
name: ckb-add-conversation
description: Save the current Claude Code conversation (or an earlier session of this project) verbatim into raw/saved-conversations/<YYYY-MM-DD>/ as the original JSONL plus a readable Markdown rendering, and search those saved conversations when asked what was discussed or instructed before. Saved conversations never enter retrieval or the wiki on their own. Use for "save this conversation", "save the chat", "archive this session", "keep a copy of our talk", for "did we discuss X", "what did I tell you about X", "what did I ask you to do about Y last time", "find the conversation where ...", and for toggling the autosave switch: "save conversations automatically", "turn on/off conversation autosave", "stop saving every conversation".
---
# Add conversation skill
## Purpose
Keep a verbatim copy of a conversation inside the KB, on the user's request
only. Two jobs:
1. **Save** — copy the session's transcript file into
`raw/saved-conversations/<YYYY-MM-DD>/` and render it as Markdown.
2. **Recall** — when the user asks whether something was discussed or what
instruction they gave earlier, search the saved conversations and answer
from them, quoting the exact exchange.
What this skill is **not**:
- Not retrieval. `raw/saved-conversations/` is outside the cascade.
`ckb-retrieve` never reads it, lint never fingerprints it, and nothing in
it counts as a source for a wiki page until it has been ingested.
- Not ingest. A saved conversation becomes wiki knowledge only when the user
copies its `.md` into `raw/inbox/` and says "Ingest" — the copy is theirs
to make, so the choice of what enters the wiki stays explicit.
- Not automatic by default. The agent asks at session end (Rule E) and
saves only on a clear yes. Never save because a session "seems
important". The one exception is the `autosave` switch below, which the
user turns on deliberately.
## Where transcripts come from
Claude Code writes every session as a JSONL file:
```
<config>/projects/<encoded-cwd>/<session-id>.jsonl
```
`<config>` is `$CLAUDE_CONFIG_DIR` when set, else `~/.claude`.
`<encoded-cwd>` is the KB's absolute path with every character that is not a
letter or digit replaced by `-` (`/home/me/My KB` → `-home-me-My-KB`). The
file still being written is the current session, so "most recently modified"
is the right default. The script does this lookup; the fallback section shows
it by hand.
## How to run this skill — Save
### Step 1 — Confirm the target
If the user said "save this conversation", the target is the current session.
If they named an earlier one ("save yesterday's session", "the one about
billing"), list candidates and let them pick:
```bash
<python> .agents/skills/ckb-add-conversation/scripts/save_conversation.py --list
```
Each row shows a session-id prefix, last activity, size, user-turn count and
the title. Pass the chosen prefix with `--session <prefix>`.
### Step 2 — Say what will be captured
Before writing, tell the user in one or two sentences that the transcript is
verbatim: every message, every tool call, and the first few hundred characters
of every tool result, including file contents the agent printed during the
session. It will be a tracked file in the repo. If the session touched
anything secret-looking (`.env`, keys, tokens, credentials, personal data),
say so and let them decide. Thinking blocks are never rendered into the
Markdown but remain in the JSONL copy.
### Step 3 — Save
```bash
<python> .agents/skills/ckb-add-conversation/scripts/save_conversation.py # current session
<python> .agents/skills/ckb-add-conversation/scripts/save_conversation.py --session <prefix>
<python> .agents/skills/ckb-add-conversation/scripts/save_conversation.py --title "Short name" # override the derived title
```
The script writes, under `raw/saved-conversations/<today>/`:
- `<slug>_<sid8>.jsonl` — byte-for-byte copy of the transcript
- `<slug>_<sid8>.md` — readable rendering: a metadata table (session id,
author from the repo's git identity, start and last-message times,
working directory, branch, Claude Code version, turn counts, sha256 of
the JSONL), then the exchange in order.
User and assistant text verbatim; tool calls as one-line
`> **Tool:**` notes; tool results truncated; harness `<system-reminder>`
blocks stripped; thinking omitted.
and updates `raw/saved-conversations/index.md` (one row per session, newest
first; re-saving a session that continued replaces its files and its row).
The slug comes from Claude Code's own session title when present, otherwise
from the first user line. `--author "Name <email>"` overrides the git
identity. `--dry-run` shows the paths without writing.
### Step 4 — Report and log
Report the two paths, the title and the turn counts the script printed. Then
append a line to today's `workload/` summary naming the saved file. Nothing
under `wiki/` changed, so `wiki/log.md` is **not** touched — Rule B covers
the wiki only.
If the user wants the conversation's content in the wiki, say so plainly:
copy the `.md` into `raw/inbox/` and say "Ingest". Do not copy it for them
unless they ask.
### Without Python
Resolve `<python>` as `AGENTS.md` §3 describes. If no interpreter runs, copy
the JSONL by hand and skip the Markdown rendering:
```bash
CFG="${CLAUDE_CONFIG_DIR:-$HOME/.claude}"
PROJ="$CFG/projects/$(pwd | sed 's/[^A-Za-z0-9]/-/g')"
SRC=$(ls -t "$PROJ"/*.jsonl | head -1) # current session
DEST="raw/saved-conversations/$(date +%F)"; mkdir -p "$DEST"
cp "$SRC" "$DEST/conversation_$(basename "$SRC" .jsonl | cut -c1-8).jsonl"
```
Add a row to `raw/saved-conversations/index.md` by hand (create the file
with the header the script would write, see `INDEX_HEADER` in the script).
Tell the user once that the readable `.md` can be produced later by re-running
the script with `--from <that jsonl>` once Python is available.
## The autosave switch
`ckb.yaml` carries:
```yaml
conversations:
autosave: false # true: save every session's transcript at session end without asking
```
With `autosave: true`, Rule E saves the conversation at session end without
asking and reports the path in one line; the workload note names the file as
usual. With `false` or no block at all, the agent asks once, as described
above. The switch is repo-level and committed, so everyone working in this
KB gets the same behaviour.
**Toggling it on request** ("save conversations automatically", "turn off
autosave"): read `ckb.yaml`, change only the `autosave` value, write the
file back with everything else byte-for-byte intact (`template:` and
`kb_modules:` belong to other skills). Add the `conversations:` block if it
is missing. Confirm the new value in one line, then run the per-machine
check described below and ask about the hook. When turning it on, say once
that every session will become a tracked file in the repo, including
whatever file contents and command output the agent prints — the caveat in
Save Step 2 no longer gets a chance to be said per session.
**The per-machine half.** The agent-side rule saves at session end only
when the agent reaches that step; a session killed mid-turn is not saved. A
Claude Code `Stop` hook closes that gap: it runs `save_conversation.py
--from-hook` after every turn, and the script updates the same files in
place. The hook reads the transcript path from the hook's stdin JSON, so the
right session is saved even when several run in parallel.
Hooks are machine configuration, not template: they live in
`.claude/settings.local.json`, which is gitignored. So the switch in
`ckb.yaml` travels with the repo, and every machine that opens the repo has
to be brought in line separately. `scripts/autosave_hook.py` does that:
```bash
<python> .agents/skills/ckb-add-conversation/scripts/autosave_hook.py --check # exit 0 = consistent, 1 = action needed
<python> .agents/skills/ckb-add-conversation/scripts/autosave_hook.py --install # merge the hook into settings.local.json
<python> .agents/skills/ckb-add-conversation/scripts/autosave_hook.py --remove # take it out, leave the rest intact
```
`--install` takes `--python <cmd>` so the hook command uses the interpreter
that actually works on this machine (resolve `<python>` as `AGENTS.md` §3
describes and pass it). It merges into an existing file and refuses to
touch one that is not valid JSON.
**Never change machine configuration silently.** Two moments call for the
check, and both end in a question, not an action:
1. *Session start* (Rule E) — when `autosave: true`, run `--check`. On exit 1
tell the user in one line what is out of line and ask whether to
install (or remove) the hook on this machine. Apply only on a yes. If
they decline, do not ask again this session; autosave then relies on the
session-end rule alone, which is worth saying once.
2. *Toggling the switch* — right after flipping `autosave` in `ckb.yaml`,
run `--check` and ask the same question, so the switch and this machine
agree from the first session. Turning autosave off and leaving the hook
installed would keep saving every session, which is exactly what the
user just asked to stop.
Without Python the hook cannot run either, so there is nothing to install:
say so once and rely on the session-end rule.
## How to run this skill — Recall
Triggers: "did we discuss X", "have we talked about X before", "what did I
tell you about X", "what instructions did I give about Y", "what did I ask
you to do last time", "find the conversation where ...".
1. Read `raw/saved-conversations/index.md`. If it is missing or empty, say no
conversations have been saved and stop — do not fall back to `workload/`
or the wiki as if they were transcripts (they are summaries, offer them
as such).
2. Search the `.md` renderings, not the JSONL:
```bash
grep -ril "<term>" raw/saved-conversations/*/*.md
grep -n -i -B2 -A6 "<term>" raw/saved-conversations/<date>/<file>.md
```
Try two or three phrasings; people rarely reuse their exact words.
3. For an "instruction I gave" question, prefer `## User` blocks over
`## Assistant` ones — the user's own words are the instruction, the
assistant's restatement is not.
4. Answer with the exact exchange quoted, attributed as
`` — `raw/saved-conversations/<date>/<file>.md`, under "User — <timestamp>" ``,
and the date. If nothing matches, say that no saved conversation mentions
it, and name the date range the saved conversations cover so the user
knows whether the gap is "never discussed" or "not saved".
5. Never promote a recalled instruction into `wiki/` on the strength of the
transcript alone. If it deserves to be durable, offer `ckb-decide`
(for a decision) or ingest (for knowledge) as the next step.
## Edge cases
- **No transcript directory** (exit code 2): the KB is being driven by
something other than Claude Code, or `CLAUDE_CONFIG_DIR` points elsewhere.
Report the path the script looked in and ask the user for the transcript
file; then use `--from <file>`.
- **Ambiguous `--session` prefix**: the script lists the matches; pass a
longer prefix.
- **Same session saved twice in one day**: files and index row are replaced,
the script prints `updated` (or `unchanged` when nothing grew). A session
saved again on a later day gets a new dated folder; both stay.
- **Subagent turns** are rendered with a `(subagent)` marker on the heading.
- **Very long tool results** are cut at 400 characters in the Markdown; the
JSONL has them in full.
- **`ckb-reset`** treats `raw/saved-conversations/` as tier 3 source
material: asked about, never deleted silently.