cogpit-memory 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/skill/SKILL.md CHANGED
@@ -1,29 +1,31 @@
1
1
  ---
2
2
  name: cogpit-memory
3
- description: CLI tool for Claude Code and Codex session introspection -- retrieves conversation history, tool calls, thinking, sub-agent/team activity, full-text search, and session discovery. All output is JSON to stdout.
3
+ description: CLI tool for Claude Code, Codex, and GitHub Copilot CLI session introspection -- retrieves conversation history, tool calls, thinking, full-text search, session discovery, and supported sub-agent/team activity. All output is JSON to stdout.
4
4
  ---
5
5
 
6
6
  # Cogpit Memory -- Session Context CLI
7
7
 
8
- CLI tool that gives any AI assistant memory of past Claude Code and Codex sessions. Retrieve conversation history, tool usage, thinking, and sub-agent activity via a layered command structure. Session discovery and layered context support both providers; cross-session full-text indexing currently covers Claude Code history, while `search --session` supports either provider.
8
+ CLI tool that gives any AI assistant memory of past Claude Code, Codex, and GitHub Copilot CLI sessions. Retrieve conversation history, tool usage, thinking, and supported sub-agent activity via a layered command structure. Session discovery, root context and cross-session full-text indexing all cover every provider. Copilot nested activity is included inline in the root session, but `context --agent` is unavailable because Copilot CLI does not write separate sub-agent transcript files.
9
9
 
10
10
  Always start with session discovery or the overview (Layer 1), and drill into specific turns or sub-agents only as needed. Use search when you need to **find** content rather than browse known sessions.
11
11
 
12
- **Prerequisite:** Bun must be installed (uses bun:sqlite for FTS5 search).
13
-
14
- ## Step 1 -- Verify the tool works
12
+ ## Step 1 -- Use the installed CLI
15
13
 
16
14
  ```bash
17
- bunx cogpit-memory --help
15
+ command -v cogpit-memory
16
+ cogpit-memory --help
18
17
  ```
19
18
 
20
- If this prints usage info, proceed to Step 2. If `bunx` is not available, install the package globally:
19
+ If missing, install it once, wait for installation to finish, then use the installed command:
21
20
 
22
21
  ```bash
23
- npm install -g cogpit-memory
22
+ bun install --global cogpit-memory
23
+ cogpit-memory --help
24
24
  ```
25
25
 
26
- Then use `cogpit-memory` directly instead of `bunx cogpit-memory`.
26
+ The npm package requires Node.js 20 or newer. If Bun's global bin directory is not on PATH, resolve it with `bun pm bin --global` and invoke `cogpit-memory` there. Do not run parallel `bunx cogpit-memory` installs: transient native-dependency installation can race. Parallel calls to the installed CLI do not reinstall anything.
27
+
28
+ JSON goes to stdout. Keep stderr separate when piping to `jq` or Python; never merge it with `2>&1` before a JSON parser. A JSON `{ "error": ... }` response exits nonzero and is a failed lookup, not an empty successful result. Use complete session IDs from discovery or search, not abbreviated IDs.
27
29
 
28
30
  ## Step 2 -- Find sessions
29
31
 
@@ -31,13 +33,13 @@ Then use `cogpit-memory` directly instead of `bunx cogpit-memory`.
31
33
 
32
34
  ```bash
33
35
  # List recent sessions (default: last 7 days, up to 20 results)
34
- bunx cogpit-memory sessions
36
+ cogpit-memory sessions
35
37
 
36
38
  # Filter by working directory
37
- bunx cogpit-memory sessions --cwd /path/to/project
39
+ cogpit-memory sessions --cwd /path/to/project
38
40
 
39
41
  # Customize limit and time window
40
- bunx cogpit-memory sessions --limit 50 --max-age 30d
42
+ cogpit-memory sessions --limit 50 --max-age 30d
41
43
  ```
42
44
 
43
45
  Options:
@@ -53,7 +55,7 @@ Response: array of session summaries with `sessionId`, `cwd`, `model`, `firstMes
53
55
  ### Get current session for a directory
54
56
 
55
57
  ```bash
56
- bunx cogpit-memory sessions --current --cwd /path/to/project
58
+ cogpit-memory sessions --current --cwd /path/to/project
57
59
  ```
58
60
 
59
61
  Returns the most recently active session for the given working directory. The `--cwd` flag is required when using `--current` (defaults to the current working directory if omitted).
@@ -63,7 +65,7 @@ Returns the most recently active session for the given working directory. The `-
63
65
  This gives you every user prompt and AI reply, plus a tool usage summary per turn. **You must call this before Layer 2 or Layer 3** -- it provides the `turnIndex` and `agentId` values you need for drill-downs.
64
66
 
65
67
  ```bash
66
- bunx cogpit-memory context <SESSION_ID>
68
+ cogpit-memory context <SESSION_ID>
67
69
  ```
68
70
 
69
71
  Response shape:
@@ -117,7 +119,7 @@ Key fields:
117
119
  Use this to drill into a specific turn. Get thinking, full tool call inputs/outputs, and sub-agent summaries in chronological order.
118
120
 
119
121
  ```bash
120
- bunx cogpit-memory context <SESSION_ID> --turn <TURN_INDEX>
122
+ cogpit-memory context <SESSION_ID> --turn <TURN_INDEX>
121
123
  ```
122
124
 
123
125
  Response shape:
@@ -154,7 +156,7 @@ Key details:
154
156
  - `contentBlocks` kinds: `thinking`, `text`, `tool_calls`, `sub_agent`, `background_agent`, `queued_prompt`, `hook_event`, `plan_mode`, `recap`, `agent_message`
155
157
  - Tool call `result` is truncated at 10,000 chars -- check `resultTruncated: true`
156
158
  - Tool call `result` may be `null` if the tool hasn't returned yet
157
- - Sub-agent blocks show prompt + result text. For full sub-agent conversation, use Layer 3
159
+ - Sub-agent blocks show prompt + result text. When the provider writes a separate sub-agent transcript, use Layer 3 for the full conversation
158
160
 
159
161
  **Make separate requests per turn** -- do not try to batch multiple turns in one call.
160
162
 
@@ -163,7 +165,7 @@ Key details:
163
165
  Drill into a specific sub-agent's full conversation. Returns the same shape as Layer 1 (an overview of the sub-agent's own turns).
164
166
 
165
167
  ```bash
166
- bunx cogpit-memory context <SESSION_ID> --agent <AGENT_ID>
168
+ cogpit-memory context <SESSION_ID> --agent <AGENT_ID>
167
169
  ```
168
170
 
169
171
  Get the `AGENT_ID` from Layer 1's `subAgents[].agentId` field.
@@ -188,7 +190,7 @@ Response shape:
188
190
  The `overview` field has the exact same shape as Layer 1. You can then drill into specific sub-agent turns:
189
191
 
190
192
  ```bash
191
- bunx cogpit-memory context <SESSION_ID> --agent <AGENT_ID> --turn <TURN_INDEX>
193
+ cogpit-memory context <SESSION_ID> --agent <AGENT_ID> --turn <TURN_INDEX>
192
194
  ```
193
195
 
194
196
  This returns the same shape as Layer 2.
@@ -214,32 +216,42 @@ The typical workflow for drilling into sub-agent activity:
214
216
 
215
217
  1. Call Layer 1 to get the session overview
216
218
  2. Look at `turns[].subAgents[]` to find agent IDs
217
- 3. Call Layer 3 with the `--agent` flag to get that sub-agent's overview
219
+ 3. If the provider writes a separate sub-agent transcript, call Layer 3 with the `--agent` flag to get that sub-agent's overview
218
220
  4. Call Layer 3 + `--turn` to drill into a specific sub-agent turn
219
221
  5. If the sub-agent itself had sub-agents, repeat from step 2 using the sub-agent's overview
220
222
 
221
223
  ## Session Search -- Find keywords across sessions
222
224
 
223
- Search for keywords across all sessions or within a specific session. Searches **everything**: user messages, assistant responses, thinking blocks, tool call inputs/results, sub-agent messages, sub-agent tool calls, and compaction summaries.
225
+ Cross-session search indexes every provider's history. With `--session`, Claude Code, Codex, and Copilot CLI sessions are all supported, including user and assistant messages, thinking, tool I/O, inline sub-agent content, and compaction summaries when the provider records them.
224
226
 
225
227
  **When to use search vs Layer 1:**
226
228
  - You know the session -> Use Layer 1 overview, then drill with Layer 2/3
227
229
  - You need to **find** which session discussed something -> Use search first, then drill into hits
228
230
 
231
+ When recalling earlier work, exclude this session if its ID is known, so your search commands and copied results do not crowd out history:
232
+
233
+ ```bash
234
+ cogpit-memory search "authentication" --max-age 90d --exclude-session "$COGPIT_SESSION_ID"
235
+ ```
236
+
237
+ Only pass that flag when the environment variable is set, or supply a known full session ID. Do not guess that the most recently modified session is yours when agents share a project. Omit the flag when searching this session itself. The exclusion also covers its indexed subagents.
238
+
239
+ Search automatically removes index entries for transcript files that no longer exist. It cannot recover deleted transcripts. If a file disappears between search and `context`, report that the source is unavailable and continue with other hits.
240
+
229
241
  ### Basic usage
230
242
 
231
243
  ```bash
232
- # Search across all recent sessions (last 5 days)
233
- bunx cogpit-memory search "authentication"
244
+ # Search recent indexed sessions from all supported CLIs (last 5 days)
245
+ cogpit-memory search "authentication"
234
246
 
235
247
  # Search within a specific session
236
- bunx cogpit-memory search "authentication" --session <SESSION_ID>
248
+ cogpit-memory search "authentication" --session <SESSION_ID>
237
249
 
238
250
  # Search with custom time window and more results
239
- bunx cogpit-memory search "authentication" --max-age 30d --limit 50
251
+ cogpit-memory search "authentication" --max-age 30d --limit 50
240
252
 
241
253
  # Case-sensitive search
242
- bunx cogpit-memory search "AuthProvider" --case-sensitive
254
+ cogpit-memory search "AuthProvider" --case-sensitive
243
255
  ```
244
256
 
245
257
  ### Options
@@ -247,6 +259,7 @@ bunx cogpit-memory search "AuthProvider" --case-sensitive
247
259
  | Flag | Default | Description |
248
260
  |------|---------|-------------|
249
261
  | `--session` | all sessions | Scope to single session |
262
+ | `--exclude-session` | none | Omit one session and its subagents |
250
263
  | `--max-age` | `5d` | Time window: `5d`, `12h`, `30d` |
251
264
  | `--limit` | `20` | Max total hits returned |
252
265
  | `--session-limit` | all | Cap unique sessions in results |
@@ -298,48 +311,45 @@ Locations map directly to Layer 2/3 drill-down commands -- use them to fetch ful
298
311
  - `turn/{i}/toolCall/{id}/input` -- tool call input -> drill with `--turn {i}`
299
312
  - `turn/{i}/toolCall/{id}/result` -- tool call result -> drill with `--turn {i}`
300
313
  - `turn/{i}/compactionSummary` -- compaction summary -> drill with `--turn {i}`
301
- - `agent/{agentId}/...` -- sub-agent content -> drill with `--agent {agentId}` then `--agent {agentId} --turn {i}`
314
+ - `agent/{agentId}/...` -- sub-agent content; drill with `--agent {agentId}` only when the provider writes a separate transcript
302
315
 
303
316
  ### Typical workflow
304
317
 
305
- 1. Search for keyword: `bunx cogpit-memory search "auth"`
318
+ 1. Search for keyword: `cogpit-memory search "auth"`
306
319
  2. Pick a hit from results (e.g., `sessionId: "abc-123"`, `location: "turn/3/assistantMessage"`)
307
- 3. Get full turn context: `bunx cogpit-memory context abc-123 --turn 3`
308
- 4. If hit is in a sub-agent, get agent overview first: `bunx cogpit-memory context abc-123 --agent a7f3bc2`
320
+ 3. Get full turn context: `cogpit-memory context abc-123 --turn 3`
321
+ 4. If a hit is in a sub-agent with a separate transcript, get its overview: `cogpit-memory context abc-123 --agent a7f3bc2`
309
322
 
310
- ### Performance notes
323
+ ### Search behavior
311
324
 
312
- - Cross-session search uses a raw-text pre-filter -- files that can't match are skipped before expensive parsing
313
- - Default 5-day window keeps search fast; increase `--max-age` only if needed
314
- - Single-session search (`--session` flag) is much faster than cross-session
315
- - Typical cross-session search: ~150 sessions in ~1-2 seconds
325
+ Cross-session search uses an incrementally updated SQLite FTS5 index, with a raw-file fallback if the index is unavailable. The default window is 5 days. Increase `--max-age` for older work. FTS matches whole tokens, so `auth` does not match `authentication`. `--limit` is capped at 200; narrow a broad query or use `--session` to investigate further.
316
326
 
317
327
  ## Index management
318
328
 
319
- The search index is an FTS5 trigram database at `~/.claude/cogpit-memory/search-index.db`. Most commands work without the index (falling back to raw file scanning), but indexed search is significantly faster.
329
+ The search index is an FTS5 database at `~/.claude/cogpit-memory/search-index.db`. Most commands work without the index (falling back to raw file scanning), but indexed search is significantly faster.
320
330
 
321
331
  ```bash
322
332
  # Show index stats (session count, staleness, DB size)
323
- bunx cogpit-memory index stats
333
+ cogpit-memory index stats
324
334
 
325
335
  # Rebuild the full index from scratch
326
- bunx cogpit-memory index rebuild
336
+ cogpit-memory index rebuild
327
337
  ```
328
338
 
329
339
  ## Quick reference
330
340
 
331
341
  | Goal | Command |
332
342
  |------|---------|
333
- | List recent sessions | `bunx cogpit-memory sessions` |
334
- | Sessions for a directory | `bunx cogpit-memory sessions --cwd <path>` |
335
- | Current session for a directory | `bunx cogpit-memory sessions --current --cwd <path>` |
336
- | Session overview (always first) | `bunx cogpit-memory context <sessionId>` |
337
- | Turn detail | `bunx cogpit-memory context <sessionId> --turn <N>` |
338
- | Sub-agent overview | `bunx cogpit-memory context <sessionId> --agent <agentId>` |
339
- | Sub-agent turn detail | `bunx cogpit-memory context <sessionId> --agent <agentId> --turn <N>` |
340
- | **Search across sessions** | `bunx cogpit-memory search "<query>"` |
341
- | **Search single session** | `bunx cogpit-memory search "<query>" --session <sessionId>` |
342
- | Index stats | `bunx cogpit-memory index stats` |
343
- | Index rebuild | `bunx cogpit-memory index rebuild` |
343
+ | List recent sessions | `cogpit-memory sessions` |
344
+ | Sessions for a directory | `cogpit-memory sessions --cwd <path>` |
345
+ | Current session for a directory | `cogpit-memory sessions --current --cwd <path>` |
346
+ | Session overview (always first) | `cogpit-memory context <sessionId>` |
347
+ | Turn detail | `cogpit-memory context <sessionId> --turn <N>` |
348
+ | Sub-agent overview | `cogpit-memory context <sessionId> --agent <agentId>` |
349
+ | Sub-agent turn detail | `cogpit-memory context <sessionId> --agent <agentId> --turn <N>` |
350
+ | **Search indexed sessions** | `cogpit-memory search "<query>"` |
351
+ | **Search any single provider session** | `cogpit-memory search "<query>" --session <sessionId>` |
352
+ | Index stats | `cogpit-memory index stats` |
353
+ | Index rebuild | `cogpit-memory index rebuild` |
344
354
 
345
355
  **Default to Layer 1 only. Drill into Layer 2/3 only when you have a specific reason.**
@@ -1,27 +0,0 @@
1
- /**
2
- * Token display estimation and cost formatting.
3
- *
4
- * Pricing lives in shared/usageCost/pricing.ts, driven by LiteLLM's live rate
5
- * table — nothing here carries hardcoded rates. What remains is display-only
6
- * accounting of the thinking/visible output split.
7
- *
8
- * Claude Code 2.1.19x+ reports thinking tokens directly on the assistant
9
- * record, so that half of the split is now exact. Older transcripts recorded
10
- * only the message_start placeholder usage, so they still fall back to a
11
- * content estimate at ≈4 chars/token — as does the visible-output half, which
12
- * the CLI does not break out.
13
- */
14
- import type { Turn } from "./types";
15
- /** Approximate characters per token for content-based estimation. */
16
- export declare const CHARS_PER_TOKEN = 4;
17
- /**
18
- * Thinking tokens for a turn: the count the model reported when it is
19
- * available, falling back to a character estimate for older transcripts.
20
- *
21
- * A reported 0 is a fact — a turn that did no thinking — so presence is tested
22
- * rather than truthiness.
23
- */
24
- export declare function estimateThinkingTokens(turn: Turn): number;
25
- /** Estimate non-thinking output tokens (text + tool use JSON). */
26
- export declare function estimateVisibleOutputTokens(turn: Turn): number;
27
- export declare function formatCost(usd: number): string;