cogpit-memory 0.1.10 → 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/LICENSE +21 -0
- package/README.md +34 -25
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +3090 -1211
- package/dist/commands/search.d.ts +1 -1
- package/dist/commands/sessions.d.ts +2 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +3062 -1264
- package/dist/lib/agent-descriptors.d.ts +387 -0
- package/dist/lib/agentEnvelope.d.ts +24 -0
- package/dist/lib/agents.d.ts +112 -0
- package/dist/lib/claude.d.ts +49 -0
- package/dist/lib/codex-exec.d.ts +39 -0
- package/dist/lib/codex-tool-normalization.d.ts +31 -4
- package/dist/lib/codex.d.ts +29 -1
- package/dist/lib/copilot.d.ts +51 -0
- package/dist/lib/dirs.d.ts +9 -0
- package/dist/lib/helpers.d.ts +0 -6
- package/dist/lib/interactiveState.d.ts +16 -2
- package/dist/lib/messageTypeGuards.d.ts +10 -1
- package/dist/lib/metadata.d.ts +16 -14
- package/dist/lib/parser.d.ts +6 -4
- package/dist/lib/search-index.d.ts +7 -67
- package/dist/lib/sessionStats.d.ts +6 -1
- package/dist/lib/sessionStatus.d.ts +12 -27
- package/dist/lib/stores.d.ts +47 -0
- package/dist/lib/turnBuilder.d.ts +55 -0
- package/dist/lib/turnContent.d.ts +2 -0
- package/dist/lib/types.d.ts +200 -10
- package/package.json +22 -3
- package/skill/SKILL.md +59 -49
- package/dist/lib/pricingTiers.d.ts +0 -30
- package/dist/lib/token-costs.d.ts +0 -48
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
/** The agent CLIs Cogpit can drive. */
|
|
2
|
+
export type AgentKind = "claude" | "codex" | "copilot";
|
|
3
|
+
/**
|
|
4
|
+
* Every agent kind, in transcript-detection order. Codex and Copilot carry
|
|
5
|
+
* positive discriminators in their records; Claude is the terminal fallback and
|
|
6
|
+
* must stay last.
|
|
7
|
+
*/
|
|
8
|
+
export declare const AGENT_KINDS: readonly AgentKind[];
|
|
9
|
+
export type SessionStatus = "idle" | "thinking" | "tool_use" | "processing" | "completed" | "compacting" | "deferred" | "awaiting_agents";
|
|
10
|
+
export interface SessionStatusInfo {
|
|
11
|
+
status: SessionStatus;
|
|
12
|
+
/** Name of the tool currently being used (if status is tool_use) */
|
|
13
|
+
toolName?: string;
|
|
14
|
+
/** Number of pending queue items (user messages waiting to be processed) */
|
|
15
|
+
pendingQueue?: number;
|
|
16
|
+
/** Why the session terminated (from Claude Code's terminal_reason). Only set for non-normal endings. */
|
|
17
|
+
terminalReason?: string;
|
|
18
|
+
/** Number of background agents/workflows still running (status awaiting_agents) */
|
|
19
|
+
pendingAgents?: number;
|
|
20
|
+
/** Short descriptions of the pending background agents, oldest first */
|
|
21
|
+
pendingAgentDescriptions?: string[];
|
|
22
|
+
}
|
|
23
|
+
/** A raw transcript record, before any agent-specific interpretation. */
|
|
24
|
+
export type RawRecord = {
|
|
25
|
+
type: string;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
};
|
|
1
28
|
export interface TextBlock {
|
|
2
29
|
type: "text";
|
|
3
30
|
text: string;
|
|
@@ -80,6 +107,21 @@ export interface UserMessage extends BaseMessage {
|
|
|
80
107
|
content: UserContent;
|
|
81
108
|
};
|
|
82
109
|
isMeta?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Set on the synthetic user message Claude Code writes after a compaction.
|
|
112
|
+
* Its content is the real compaction summary wrapped in resume boilerplate —
|
|
113
|
+
* `compact_boundary.content` is only ever the fixed string "Conversation
|
|
114
|
+
* compacted", so this message is the sole source of the summary text.
|
|
115
|
+
*/
|
|
116
|
+
isCompactSummary?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Why Claude Code wrote this record. `"task-notification"` marks a
|
|
119
|
+
* background task reporting back, not a prompt the reader typed. Absent on
|
|
120
|
+
* records written before Claude Code added the field (pre-2.1.220).
|
|
121
|
+
*/
|
|
122
|
+
origin?: {
|
|
123
|
+
kind?: string;
|
|
124
|
+
} | null;
|
|
83
125
|
permissionMode?: string;
|
|
84
126
|
thinkingMetadata?: {
|
|
85
127
|
maxThinkingTokens: number;
|
|
@@ -94,6 +136,25 @@ export interface TokenUsage {
|
|
|
94
136
|
cache_read_input_tokens?: number;
|
|
95
137
|
/** "fast" when the turn ran in fast mode (billed at a higher tier on Opus 4.6/4.7) */
|
|
96
138
|
speed?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Claude Code 2.1.19x+ reports the thinking slice of `output_tokens`
|
|
141
|
+
* exactly. Already counted inside output_tokens — never add it to a cost sum.
|
|
142
|
+
*/
|
|
143
|
+
output_tokens_details?: {
|
|
144
|
+
thinking_tokens?: number;
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* What drove a response, when Claude Code could attribute it (CC 2.1.17x+).
|
|
149
|
+
* Written as flat `attribution*` fields on the assistant record.
|
|
150
|
+
*/
|
|
151
|
+
export interface MessageAttribution {
|
|
152
|
+
/** Subagent type, e.g. "Explore", "implementer", "workflow-subagent". */
|
|
153
|
+
agent?: string;
|
|
154
|
+
skill?: string;
|
|
155
|
+
plugin?: string;
|
|
156
|
+
mcpServer?: string;
|
|
157
|
+
mcpTool?: string;
|
|
97
158
|
}
|
|
98
159
|
export interface AssistantMessage extends BaseMessage {
|
|
99
160
|
type: "assistant";
|
|
@@ -106,6 +167,17 @@ export interface AssistantMessage extends BaseMessage {
|
|
|
106
167
|
usage: TokenUsage;
|
|
107
168
|
};
|
|
108
169
|
requestId?: string;
|
|
170
|
+
/**
|
|
171
|
+
* Reasoning effort this response ran at (CC 2.1.212+): low | medium | high |
|
|
172
|
+
* xhigh | max. Codex spells its own levels differently (e.g. "trivial"), so
|
|
173
|
+
* this stays a plain string rather than a union.
|
|
174
|
+
*/
|
|
175
|
+
effort?: string;
|
|
176
|
+
attributionAgent?: string;
|
|
177
|
+
attributionSkill?: string;
|
|
178
|
+
attributionPlugin?: string;
|
|
179
|
+
attributionMcpServer?: string;
|
|
180
|
+
attributionMcpTool?: string;
|
|
109
181
|
}
|
|
110
182
|
/**
|
|
111
183
|
* @deprecated Claude Code v2.1.63+ no longer emits inline agent_progress messages.
|
|
@@ -195,10 +267,12 @@ export interface SystemMessage extends BaseMessage {
|
|
|
195
267
|
durationMs?: number;
|
|
196
268
|
isMeta?: boolean;
|
|
197
269
|
content?: string;
|
|
198
|
-
compactMetadata?:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
270
|
+
compactMetadata?: CompactionMeta;
|
|
271
|
+
}
|
|
272
|
+
export interface CompactionMeta {
|
|
273
|
+
trigger: "auto" | "manual";
|
|
274
|
+
preTokens: number;
|
|
275
|
+
postTokens?: number;
|
|
202
276
|
}
|
|
203
277
|
export interface FileHistorySnapshotMessage extends BaseMessage {
|
|
204
278
|
type: "file-history-snapshot";
|
|
@@ -221,14 +295,74 @@ export interface QueueOperationMessage extends BaseMessage {
|
|
|
221
295
|
operation: "enqueue" | "dequeue" | "remove" | string;
|
|
222
296
|
content?: string | null;
|
|
223
297
|
}
|
|
224
|
-
|
|
298
|
+
/**
|
|
299
|
+
* Claude Code persists the text of a prompt queued mid-turn here, not on the
|
|
300
|
+
* queue-operation record. `commandMode` separates prompts the user typed
|
|
301
|
+
* ("prompt") from Claude's own injected notices ("task-notification").
|
|
302
|
+
*/
|
|
303
|
+
export interface AttachmentMessage extends BaseMessage {
|
|
304
|
+
type: "attachment";
|
|
305
|
+
attachment?: {
|
|
306
|
+
type?: string;
|
|
307
|
+
prompt?: string | ContentBlock[] | null;
|
|
308
|
+
commandMode?: string;
|
|
309
|
+
timestamp?: string;
|
|
310
|
+
/**
|
|
311
|
+
* Who queued this prompt. `"human"` is the reader typing mid-turn;
|
|
312
|
+
* `"peer"` is another agent sending this session a message. `body` is the
|
|
313
|
+
* message with its envelope already stripped, so it beats re-parsing
|
|
314
|
+
* `prompt`. Absent on records written before Claude Code added the field.
|
|
315
|
+
*/
|
|
316
|
+
origin?: {
|
|
317
|
+
kind?: string;
|
|
318
|
+
from?: string;
|
|
319
|
+
name?: string;
|
|
320
|
+
senderTaskId?: string;
|
|
321
|
+
body?: string;
|
|
322
|
+
} | null;
|
|
323
|
+
} | null;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Written when a session enters or leaves a `.claude/worktrees/*` checkout.
|
|
327
|
+
* The record is the session's current worktree state, so a later one supersedes
|
|
328
|
+
* an earlier one, and a null `worktreeSession` means the session left.
|
|
329
|
+
*/
|
|
330
|
+
export interface WorktreeStateMessage extends BaseMessage {
|
|
331
|
+
type: "worktree-state";
|
|
332
|
+
worktreeSession?: {
|
|
333
|
+
originalCwd?: string;
|
|
334
|
+
preEnterOriginalCwd?: string;
|
|
335
|
+
worktreePath?: string;
|
|
336
|
+
worktreeName?: string;
|
|
337
|
+
worktreeBranch?: string;
|
|
338
|
+
originalBranch?: string;
|
|
339
|
+
originalHeadCommit?: string;
|
|
340
|
+
sessionId?: string;
|
|
341
|
+
} | null;
|
|
342
|
+
}
|
|
343
|
+
/** The agent type a session was launched as, e.g. "general-purpose". */
|
|
344
|
+
export interface AgentSettingMessage extends BaseMessage {
|
|
345
|
+
type: "agent-setting";
|
|
346
|
+
agentSetting?: string;
|
|
347
|
+
}
|
|
348
|
+
export type RawMessage = UserMessage | AssistantMessage | ProgressMessage | SystemMessage | FileHistorySnapshotMessage | SummaryMessage | QueueOperationMessage | AttachmentMessage;
|
|
225
349
|
export interface ToolCall {
|
|
226
350
|
id: string;
|
|
227
351
|
name: string;
|
|
228
352
|
input: Record<string, unknown>;
|
|
229
353
|
result: string | null;
|
|
354
|
+
/** Binary images returned by a tool, when the provider persists them. */
|
|
355
|
+
resultImages?: ImageBlock[];
|
|
230
356
|
isError: boolean;
|
|
231
357
|
timestamp: string;
|
|
358
|
+
/**
|
|
359
|
+
* A question whose tool result is only an acceptance receipt. Codex's
|
|
360
|
+
* `request_user_input_async` returns `{"accepted":true}` at once and the
|
|
361
|
+
* agent keeps working, so the answer arrives later as an ordinary message
|
|
362
|
+
* rather than as this call's result — `result !== null` does not mean
|
|
363
|
+
* answered here.
|
|
364
|
+
*/
|
|
365
|
+
asyncQuestion?: boolean;
|
|
232
366
|
/** Set by parser when a PostToolUse hook replaced this tool's output */
|
|
233
367
|
outputReplacedByHook?: boolean;
|
|
234
368
|
/** Total duration of PostToolUse hooks attached to this call, summed in ms */
|
|
@@ -272,6 +406,26 @@ export type TurnContentBlock = {
|
|
|
272
406
|
kind: "queued_prompt";
|
|
273
407
|
content: string;
|
|
274
408
|
timestamp?: string;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* A message another agent sent this session mid-turn. Distinct from
|
|
412
|
+
* `queued_prompt`, which is the reader's own text. `reply` is filled by the
|
|
413
|
+
* pairing pass when a later SendMessage answered this sender.
|
|
414
|
+
*
|
|
415
|
+
* Deliberately carries no sender task id. `origin.senderTaskId` on the record
|
|
416
|
+
* identifies the sending agent's *task*, not the message — one agent's
|
|
417
|
+
* question and its later done-report share an id — so it is useless as a
|
|
418
|
+
* per-message key and destructive as a dedup key.
|
|
419
|
+
*/
|
|
420
|
+
| {
|
|
421
|
+
kind: "agent_message";
|
|
422
|
+
sender: string;
|
|
423
|
+
body: string;
|
|
424
|
+
timestamp?: string;
|
|
425
|
+
reply?: {
|
|
426
|
+
summary: string;
|
|
427
|
+
timestamp: string;
|
|
428
|
+
};
|
|
275
429
|
} | {
|
|
276
430
|
kind: "sub_agent";
|
|
277
431
|
messages: SubAgentMessage[];
|
|
@@ -302,6 +456,18 @@ export type TurnContentBlock = {
|
|
|
302
456
|
kind: "recap";
|
|
303
457
|
content: string;
|
|
304
458
|
timestamp?: string;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* A background task reporting back, which resumes the turn that launched it
|
|
462
|
+
* rather than opening one of its own. `content` is the raw record text —
|
|
463
|
+
* one or more `<task-notification>` blocks, possibly inside a
|
|
464
|
+
* `<system-reminder>` envelope (Claude Code 2.1.234+) — left unparsed here
|
|
465
|
+
* for the same reason `queued_prompt` is: the renderers own that grammar.
|
|
466
|
+
*/
|
|
467
|
+
| {
|
|
468
|
+
kind: "task_notification";
|
|
469
|
+
content: string;
|
|
470
|
+
timestamp?: string;
|
|
305
471
|
};
|
|
306
472
|
export interface Turn {
|
|
307
473
|
id: string;
|
|
@@ -316,15 +482,38 @@ export interface Turn {
|
|
|
316
482
|
durationMs: number | null;
|
|
317
483
|
tokenUsage: TokenUsage | null;
|
|
318
484
|
model: string | null;
|
|
319
|
-
/**
|
|
485
|
+
/**
|
|
486
|
+
* Summary of the compaction that happened before this turn, as written by
|
|
487
|
+
* the compacting model. Absent when the transcript records the boundary but
|
|
488
|
+
* not the summary (e.g. the session ended right after compacting).
|
|
489
|
+
*/
|
|
320
490
|
compactionSummary?: string;
|
|
491
|
+
/** Trigger and token counts of the compaction that happened before this turn */
|
|
492
|
+
compactionMeta?: CompactionMeta;
|
|
493
|
+
/**
|
|
494
|
+
* Reasoning effort the turn ran at, when the transcript recorded one.
|
|
495
|
+
* A turn spanning several assistant messages reports the last one, since
|
|
496
|
+
* effort can be changed mid-session.
|
|
497
|
+
*/
|
|
498
|
+
effort?: string;
|
|
499
|
+
/**
|
|
500
|
+
* What drove this turn — skill, plugin, MCP server, subagent type. Merged
|
|
501
|
+
* across the turn's assistant messages, since a turn can start under a skill
|
|
502
|
+
* and later reach for an MCP tool. Undefined when nothing was attributed.
|
|
503
|
+
*/
|
|
504
|
+
attribution?: MessageAttribution;
|
|
505
|
+
/**
|
|
506
|
+
* Set when this turn was opened without its start record — the parse window
|
|
507
|
+
* began mid-turn. Such a turn is the newer half of a byte-boundary cut and
|
|
508
|
+
* must be stitched onto the previous turn once the older page arrives.
|
|
509
|
+
*/
|
|
510
|
+
isFragment?: boolean;
|
|
321
511
|
}
|
|
322
512
|
export interface SessionStats {
|
|
323
513
|
totalInputTokens: number;
|
|
324
514
|
totalOutputTokens: number;
|
|
325
515
|
totalCacheCreationTokens: number;
|
|
326
516
|
totalCacheReadTokens: number;
|
|
327
|
-
totalCostUSD: number;
|
|
328
517
|
toolCallCounts: Record<string, number>;
|
|
329
518
|
errorCount: number;
|
|
330
519
|
totalDurationMs: number;
|
|
@@ -359,10 +548,11 @@ export interface ParsedSession {
|
|
|
359
548
|
turnIndex?: number | null;
|
|
360
549
|
};
|
|
361
550
|
/**
|
|
362
|
-
* The
|
|
363
|
-
*
|
|
551
|
+
* The agent that produced this session, as determined by the parser from the
|
|
552
|
+
* transcript's own bytes. This is the parser's finding, not the app's source
|
|
553
|
+
* of truth — the session's dirName is (see `shared/session/agents.ts`).
|
|
364
554
|
*/
|
|
365
|
-
agentKind?:
|
|
555
|
+
agentKind?: AgentKind;
|
|
366
556
|
}
|
|
367
557
|
export interface ArchivedToolCall {
|
|
368
558
|
type: "Edit" | "Write";
|
package/package.json
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogpit-memory",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "CLI tool for Claude Code and
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "CLI tool for Claude Code, Codex, and GitHub Copilot CLI session introspection",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/gentritbiba/cogpit.git",
|
|
9
|
+
"directory": "packages/cogpit-memory"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/gentritbiba/cogpit/tree/master/packages/cogpit-memory",
|
|
12
|
+
"bugs": "https://github.com/gentritbiba/cogpit/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"claude-code",
|
|
15
|
+
"codex",
|
|
16
|
+
"github-copilot",
|
|
17
|
+
"session",
|
|
18
|
+
"memory",
|
|
19
|
+
"cli",
|
|
20
|
+
"agent"
|
|
21
|
+
],
|
|
5
22
|
"packageManager": "bun@1.3.14",
|
|
6
23
|
"main": "./dist/index.js",
|
|
7
24
|
"types": "./dist/index.d.ts",
|
|
@@ -13,7 +30,9 @@
|
|
|
13
30
|
},
|
|
14
31
|
"files": [
|
|
15
32
|
"dist/",
|
|
16
|
-
"skill/"
|
|
33
|
+
"skill/",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
17
36
|
],
|
|
18
37
|
"scripts": {
|
|
19
38
|
"test": "bun test",
|
package/skill/SKILL.md
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cogpit-memory
|
|
3
|
-
description: CLI tool for Claude Code and
|
|
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
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
## Step 1 -- Verify the tool works
|
|
12
|
+
## Step 1 -- Use the installed CLI
|
|
15
13
|
|
|
16
14
|
```bash
|
|
17
|
-
|
|
15
|
+
command -v cogpit-memory
|
|
16
|
+
cogpit-memory --help
|
|
18
17
|
```
|
|
19
18
|
|
|
20
|
-
If
|
|
19
|
+
If missing, install it once, wait for installation to finish, then use the installed command:
|
|
21
20
|
|
|
22
21
|
```bash
|
|
23
|
-
|
|
22
|
+
bun install --global cogpit-memory
|
|
23
|
+
cogpit-memory --help
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
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
|
-
|
|
36
|
+
cogpit-memory sessions
|
|
35
37
|
|
|
36
38
|
# Filter by working directory
|
|
37
|
-
|
|
39
|
+
cogpit-memory sessions --cwd /path/to/project
|
|
38
40
|
|
|
39
41
|
# Customize limit and time window
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
122
|
+
cogpit-memory context <SESSION_ID> --turn <TURN_INDEX>
|
|
121
123
|
```
|
|
122
124
|
|
|
123
125
|
Response shape:
|
|
@@ -151,10 +153,10 @@ Response shape:
|
|
|
151
153
|
```
|
|
152
154
|
|
|
153
155
|
Key details:
|
|
154
|
-
- `contentBlocks` kinds: `thinking`, `text`, `tool_calls`, `sub_agent`, `background_agent`, `queued_prompt`, `hook_event`, `plan_mode`, `recap`
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
233
|
-
|
|
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
|
-
|
|
248
|
+
cogpit-memory search "authentication" --session <SESSION_ID>
|
|
237
249
|
|
|
238
250
|
# Search with custom time window and more results
|
|
239
|
-
|
|
251
|
+
cogpit-memory search "authentication" --max-age 30d --limit 50
|
|
240
252
|
|
|
241
253
|
# Case-sensitive search
|
|
242
|
-
|
|
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
|
|
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: `
|
|
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: `
|
|
308
|
-
4. If hit is in a sub-agent, get
|
|
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
|
-
###
|
|
323
|
+
### Search behavior
|
|
311
324
|
|
|
312
|
-
|
|
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
|
|
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
|
-
|
|
333
|
+
cogpit-memory index stats
|
|
324
334
|
|
|
325
335
|
# Rebuild the full index from scratch
|
|
326
|
-
|
|
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 | `
|
|
334
|
-
| Sessions for a directory | `
|
|
335
|
-
| Current session for a directory | `
|
|
336
|
-
| Session overview (always first) | `
|
|
337
|
-
| Turn detail | `
|
|
338
|
-
| Sub-agent overview | `
|
|
339
|
-
| Sub-agent turn detail | `
|
|
340
|
-
| **Search
|
|
341
|
-
| **Search single session** | `
|
|
342
|
-
| Index stats | `
|
|
343
|
-
| 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,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pricing tier constants and model-to-tier resolution.
|
|
3
|
-
*
|
|
4
|
-
* Sources: Claude Code v2.1.172 binary (decompiled JS bundle) for Anthropic
|
|
5
|
-
* models, and the official OpenAI model pricing pages for GPT models.
|
|
6
|
-
* Each model maps to a tier with five price points.
|
|
7
|
-
*
|
|
8
|
-
* Changes vs the old v2.1.53 table:
|
|
9
|
-
* - Extended-context (>200k input) pricing is gone — flat pricing per model.
|
|
10
|
-
* - New frontier tier for Fable 5 / Mythos 5 / Opus 4.8 ($10/$50).
|
|
11
|
-
* - Sonnet 4.5/4.6 dropped to the $3/$15 tier (was $5/$25).
|
|
12
|
-
* - Fast mode (usage.speed === "fast" on Opus 4.6/4.7) bills $30/$150;
|
|
13
|
-
* Opus 4.8 fast bills the same as standard.
|
|
14
|
-
*/
|
|
15
|
-
export interface PricingTier {
|
|
16
|
-
input: number;
|
|
17
|
-
output: number;
|
|
18
|
-
cacheWrite: number;
|
|
19
|
-
cacheRead: number;
|
|
20
|
-
webSearch: number;
|
|
21
|
-
}
|
|
22
|
-
export declare function resolveTier(model: string, speed?: string): PricingTier;
|
|
23
|
-
/**
|
|
24
|
-
* Whether Cogpit has a published USD price for this model.
|
|
25
|
-
*
|
|
26
|
-
* Keep the historical Claude-family fallback for old rollouts whose model is
|
|
27
|
-
* absent or abbreviated, but never price a future/unknown GPT model as if it
|
|
28
|
-
* were Claude. That would create a precise-looking but invented dollar value.
|
|
29
|
-
*/
|
|
30
|
-
export declare function hasKnownPricing(model: string | null | undefined): boolean;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token cost calculation library — single source of truth.
|
|
3
|
-
*
|
|
4
|
-
* Pricing is reverse-engineered from the Claude Code binary (v2.1.53) to match
|
|
5
|
-
* exactly what CC reports. CC calculates cost per API call in the message_delta
|
|
6
|
-
* handler using final usage from the streaming response — but the JSONL only
|
|
7
|
-
* records the message_start placeholder usage (output_tokens is severely
|
|
8
|
-
* undercounted, thinking tokens are omitted entirely). We compensate by
|
|
9
|
-
* estimating output from actual content (≈4 chars/token).
|
|
10
|
-
*/
|
|
11
|
-
import type { Turn, SubAgentMessage } from "./types";
|
|
12
|
-
/** Approximate characters per token for content-based estimation. */
|
|
13
|
-
export declare const CHARS_PER_TOKEN = 4;
|
|
14
|
-
export interface CostInput {
|
|
15
|
-
model: string | null;
|
|
16
|
-
inputTokens: number;
|
|
17
|
-
outputTokens: number;
|
|
18
|
-
cacheWriteTokens: number;
|
|
19
|
-
cacheReadTokens: number;
|
|
20
|
-
webSearchRequests?: number;
|
|
21
|
-
/** Fast-mode flag from usage.speed — "fast" bills a higher tier on Opus 4.6/4.7 */
|
|
22
|
-
speed?: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Calculate the cost of a single API call / turn.
|
|
26
|
-
*
|
|
27
|
-
* This is the single entry point for all cost calculations. All other
|
|
28
|
-
* functions in the codebase should use this instead of computing cost
|
|
29
|
-
* themselves.
|
|
30
|
-
*/
|
|
31
|
-
export declare function calculateCost(c: CostInput): number;
|
|
32
|
-
/**
|
|
33
|
-
* Backward-compatible wrapper. Prefer `calculateCost()` for new code.
|
|
34
|
-
*/
|
|
35
|
-
export declare function calculateTurnCost(model: string | null, inputTokens: number, outputTokens: number, cacheCreationTokens: number, cacheReadTokens: number): number;
|
|
36
|
-
/** Estimate thinking tokens from a turn's thinking blocks. */
|
|
37
|
-
export declare function estimateThinkingTokens(turn: Turn): number;
|
|
38
|
-
/** Estimate non-thinking output tokens (text + tool use JSON). */
|
|
39
|
-
export declare function estimateVisibleOutputTokens(turn: Turn): number;
|
|
40
|
-
/** Estimate total output tokens (thinking + visible). Uses max(estimated, reported). */
|
|
41
|
-
export declare function estimateTotalOutputTokens(turn: Turn): number;
|
|
42
|
-
/** Estimate output tokens for a sub-agent message. */
|
|
43
|
-
export declare function estimateSubAgentOutput(sa: SubAgentMessage): number;
|
|
44
|
-
/** Calculate cost for a turn using estimated output tokens. */
|
|
45
|
-
export declare function calculateTurnCostEstimated(turn: Turn): number;
|
|
46
|
-
/** Calculate cost for a sub-agent message using estimated output tokens. */
|
|
47
|
-
export declare function calculateSubAgentCostEstimated(sa: SubAgentMessage): number;
|
|
48
|
-
export declare function formatCost(usd: number): string;
|