cogpit-memory 0.1.9 → 0.2.1
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 +26 -5
- package/dist/cli.d.ts +30 -0
- package/dist/cli.js +1618 -338
- package/dist/commands/context.d.ts +20 -0
- package/dist/commands/index-cmd.d.ts +15 -0
- package/dist/commands/install-skill.d.ts +4 -0
- package/dist/commands/search.d.ts +39 -0
- package/dist/commands/sessions.d.ts +38 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1659 -386
- package/dist/lib/agentEnvelope.d.ts +24 -0
- package/dist/lib/codex-exec.d.ts +27 -0
- package/dist/lib/codex-patches.d.ts +9 -0
- package/dist/lib/codex-tool-normalization.d.ts +14 -0
- package/dist/lib/codex.d.ts +30 -0
- package/dist/lib/dirs.d.ts +8 -0
- package/dist/lib/helpers.d.ts +25 -0
- package/dist/lib/interactiveState.d.ts +40 -0
- package/dist/lib/messageTypeGuards.d.ts +26 -0
- package/dist/lib/metadata.d.ts +31 -0
- package/dist/lib/parser.d.ts +14 -0
- package/dist/lib/response.d.ts +2 -0
- package/dist/lib/search-index.d.ts +154 -0
- package/dist/lib/sessionStats.d.ts +10 -0
- package/dist/lib/sessionStatus.d.ts +42 -0
- package/dist/lib/token-costs.d.ts +27 -0
- package/dist/lib/turnBuilder.d.ts +38 -0
- package/dist/lib/types.d.ts +553 -0
- package/package.json +32 -8
- package/skill/SKILL.md +4 -4
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
export interface TextBlock {
|
|
2
|
+
type: "text";
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ThinkingBlock {
|
|
6
|
+
type: "thinking";
|
|
7
|
+
thinking: string;
|
|
8
|
+
signature: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ToolUseBlock {
|
|
11
|
+
type: "tool_use";
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
input: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface ToolResultBlock {
|
|
17
|
+
type: "tool_result";
|
|
18
|
+
tool_use_id: string;
|
|
19
|
+
content: string | ContentBlock[];
|
|
20
|
+
is_error?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface Base64MediaSource {
|
|
23
|
+
type: "base64";
|
|
24
|
+
media_type: string;
|
|
25
|
+
data: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ImageBlock {
|
|
28
|
+
type: "image";
|
|
29
|
+
source: Base64MediaSource;
|
|
30
|
+
}
|
|
31
|
+
export interface DocumentBlock {
|
|
32
|
+
type: "document";
|
|
33
|
+
source: Base64MediaSource;
|
|
34
|
+
}
|
|
35
|
+
export interface AudioBlock {
|
|
36
|
+
type: "audio";
|
|
37
|
+
source: Base64MediaSource;
|
|
38
|
+
}
|
|
39
|
+
/** Claude emits this when an API request falls back from one model to another. */
|
|
40
|
+
export interface FallbackBlock {
|
|
41
|
+
type: "fallback";
|
|
42
|
+
from: {
|
|
43
|
+
model: string;
|
|
44
|
+
};
|
|
45
|
+
to: {
|
|
46
|
+
model: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export type ContentBlock = TextBlock | ThinkingBlock | ToolUseBlock | ToolResultBlock | ImageBlock | DocumentBlock | AudioBlock | FallbackBlock;
|
|
50
|
+
export type UserContent = string | ContentBlock[];
|
|
51
|
+
interface BaseMessage {
|
|
52
|
+
type: string;
|
|
53
|
+
[key: string]: unknown;
|
|
54
|
+
parentUuid?: string | null;
|
|
55
|
+
isSidechain?: boolean;
|
|
56
|
+
cwd?: string;
|
|
57
|
+
sessionId?: string;
|
|
58
|
+
version?: string;
|
|
59
|
+
gitBranch?: string;
|
|
60
|
+
uuid?: string;
|
|
61
|
+
timestamp?: string;
|
|
62
|
+
userType?: string;
|
|
63
|
+
slug?: string;
|
|
64
|
+
}
|
|
65
|
+
/** Summary result from an Agent/Task tool call (new format, v2.1.63+) */
|
|
66
|
+
export interface AgentToolUseResult {
|
|
67
|
+
status: string;
|
|
68
|
+
prompt: string;
|
|
69
|
+
agentId: string;
|
|
70
|
+
content: ContentBlock[];
|
|
71
|
+
totalDurationMs?: number;
|
|
72
|
+
totalTokens?: number;
|
|
73
|
+
totalToolUseCount?: number;
|
|
74
|
+
usage?: TokenUsage;
|
|
75
|
+
}
|
|
76
|
+
export interface UserMessage extends BaseMessage {
|
|
77
|
+
type: "user";
|
|
78
|
+
message: {
|
|
79
|
+
role: "user";
|
|
80
|
+
content: UserContent;
|
|
81
|
+
};
|
|
82
|
+
isMeta?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Set on the synthetic user message Claude Code writes after a compaction.
|
|
85
|
+
* Its content is the real compaction summary wrapped in resume boilerplate —
|
|
86
|
+
* `compact_boundary.content` is only ever the fixed string "Conversation
|
|
87
|
+
* compacted", so this message is the sole source of the summary text.
|
|
88
|
+
*/
|
|
89
|
+
isCompactSummary?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Why Claude Code wrote this record. `"task-notification"` marks a
|
|
92
|
+
* background task reporting back, not a prompt the reader typed. Absent on
|
|
93
|
+
* records written before Claude Code added the field (pre-2.1.220).
|
|
94
|
+
*/
|
|
95
|
+
origin?: {
|
|
96
|
+
kind?: string;
|
|
97
|
+
} | null;
|
|
98
|
+
permissionMode?: string;
|
|
99
|
+
thinkingMetadata?: {
|
|
100
|
+
maxThinkingTokens: number;
|
|
101
|
+
};
|
|
102
|
+
toolUseResult?: AgentToolUseResult;
|
|
103
|
+
sourceToolAssistantUUID?: string;
|
|
104
|
+
}
|
|
105
|
+
export interface TokenUsage {
|
|
106
|
+
input_tokens: number;
|
|
107
|
+
output_tokens: number;
|
|
108
|
+
cache_creation_input_tokens?: number;
|
|
109
|
+
cache_read_input_tokens?: number;
|
|
110
|
+
/** "fast" when the turn ran in fast mode (billed at a higher tier on Opus 4.6/4.7) */
|
|
111
|
+
speed?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Claude Code 2.1.19x+ reports the thinking slice of `output_tokens`
|
|
114
|
+
* exactly. Already counted inside output_tokens — never add it to a cost sum.
|
|
115
|
+
*/
|
|
116
|
+
output_tokens_details?: {
|
|
117
|
+
thinking_tokens?: number;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* What drove a response, when Claude Code could attribute it (CC 2.1.17x+).
|
|
122
|
+
* Written as flat `attribution*` fields on the assistant record.
|
|
123
|
+
*/
|
|
124
|
+
export interface MessageAttribution {
|
|
125
|
+
/** Subagent type, e.g. "Explore", "implementer", "workflow-subagent". */
|
|
126
|
+
agent?: string;
|
|
127
|
+
skill?: string;
|
|
128
|
+
plugin?: string;
|
|
129
|
+
mcpServer?: string;
|
|
130
|
+
mcpTool?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface AssistantMessage extends BaseMessage {
|
|
133
|
+
type: "assistant";
|
|
134
|
+
message: {
|
|
135
|
+
model: string;
|
|
136
|
+
id: string;
|
|
137
|
+
role: "assistant";
|
|
138
|
+
content: ContentBlock[];
|
|
139
|
+
stop_reason: string | null;
|
|
140
|
+
usage: TokenUsage;
|
|
141
|
+
};
|
|
142
|
+
requestId?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Reasoning effort this response ran at (CC 2.1.212+): low | medium | high |
|
|
145
|
+
* xhigh | max. Codex spells its own levels differently (e.g. "trivial"), so
|
|
146
|
+
* this stays a plain string rather than a union.
|
|
147
|
+
*/
|
|
148
|
+
effort?: string;
|
|
149
|
+
attributionAgent?: string;
|
|
150
|
+
attributionSkill?: string;
|
|
151
|
+
attributionPlugin?: string;
|
|
152
|
+
attributionMcpServer?: string;
|
|
153
|
+
attributionMcpTool?: string;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @deprecated Claude Code v2.1.63+ no longer emits inline agent_progress messages.
|
|
157
|
+
* Subagent results now come as `toolUseResult` on the tool_result UserMessage.
|
|
158
|
+
* This interface is kept for backward compat with old sessions and for
|
|
159
|
+
* subagentWatcher.ts which synthesizes these for live progress display.
|
|
160
|
+
* New features should use AgentToolUseResult instead.
|
|
161
|
+
*/
|
|
162
|
+
export interface AgentProgressData {
|
|
163
|
+
type: "agent_progress";
|
|
164
|
+
message: {
|
|
165
|
+
type: "user" | "assistant";
|
|
166
|
+
message: {
|
|
167
|
+
role: string;
|
|
168
|
+
content: unknown;
|
|
169
|
+
};
|
|
170
|
+
uuid?: string;
|
|
171
|
+
timestamp?: string;
|
|
172
|
+
};
|
|
173
|
+
prompt: string;
|
|
174
|
+
agentId: string;
|
|
175
|
+
}
|
|
176
|
+
export type HookEventName = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "StopFailure" | "SubagentStop" | "PreCompact" | "PostCompact" | "PermissionDenied" | "TaskCreated" | "WorktreeCreate" | "CwdChanged" | "FileChanged" | "Elicitation" | "ElicitationResult" | "Notification";
|
|
177
|
+
export interface HookProgressData {
|
|
178
|
+
type: "hook_progress";
|
|
179
|
+
/** Event name (newer SDK: hook_event_name; older SDK: hookEvent) */
|
|
180
|
+
hook_event_name?: HookEventName | string;
|
|
181
|
+
/** Older SDK field for event name (e.g. "PostToolUse") */
|
|
182
|
+
hookEvent?: HookEventName | string;
|
|
183
|
+
/** Human-readable hook name like "PostToolUse:Read" (older SDK) */
|
|
184
|
+
hookName?: string;
|
|
185
|
+
/** Source of the hook configuration: "settings" | "plugin" | "skill" */
|
|
186
|
+
source?: string;
|
|
187
|
+
/** Tool call this hook is associated with (for Pre/PostToolUse) */
|
|
188
|
+
tool_use_id?: string;
|
|
189
|
+
/** Tool name (Pre/PostToolUse) */
|
|
190
|
+
tool_name?: string;
|
|
191
|
+
/** Hook command line that ran */
|
|
192
|
+
command?: string;
|
|
193
|
+
/** stdout/stderr from the hook command */
|
|
194
|
+
output?: string;
|
|
195
|
+
stderr?: string;
|
|
196
|
+
/** Exit code */
|
|
197
|
+
exit_code?: number;
|
|
198
|
+
/** Decision returned by hook (allow/deny/block/ask/defer) */
|
|
199
|
+
decision?: string;
|
|
200
|
+
/** Duration in milliseconds (PostToolUse, 2.1.119+) */
|
|
201
|
+
duration_ms?: number;
|
|
202
|
+
/** Hook-specific output (e.g., updatedToolOutput, sessionTitle) */
|
|
203
|
+
hookSpecificOutput?: Record<string, unknown>;
|
|
204
|
+
/** Permits arbitrary additional fields without coupling */
|
|
205
|
+
[key: string]: unknown;
|
|
206
|
+
}
|
|
207
|
+
export interface ParsedHookEvent {
|
|
208
|
+
/** Event name like "PreToolUse" */
|
|
209
|
+
eventName: string;
|
|
210
|
+
/** Source: settings/plugin/skill */
|
|
211
|
+
source?: string;
|
|
212
|
+
/** Tool the hook is gated on (for Pre/PostToolUse) */
|
|
213
|
+
toolName?: string;
|
|
214
|
+
toolUseId?: string;
|
|
215
|
+
/** Command that ran */
|
|
216
|
+
command?: string;
|
|
217
|
+
output?: string;
|
|
218
|
+
stderr?: string;
|
|
219
|
+
exitCode?: number;
|
|
220
|
+
decision?: string;
|
|
221
|
+
/** Duration in ms */
|
|
222
|
+
durationMs?: number;
|
|
223
|
+
/** PostToolUse hooks (2.1.121) can replace tool output via updatedToolOutput */
|
|
224
|
+
updatedToolOutput?: string;
|
|
225
|
+
/** UserPromptSubmit hooks (2.1.94) can set sessionTitle */
|
|
226
|
+
sessionTitle?: string;
|
|
227
|
+
/** WorktreeCreate hooks (2.1.84) return worktreePath */
|
|
228
|
+
worktreePath?: string;
|
|
229
|
+
timestamp: string;
|
|
230
|
+
}
|
|
231
|
+
export interface ProgressMessage extends BaseMessage {
|
|
232
|
+
type: "progress";
|
|
233
|
+
data: AgentProgressData | HookProgressData;
|
|
234
|
+
parentToolUseID?: string;
|
|
235
|
+
toolUseID?: string;
|
|
236
|
+
}
|
|
237
|
+
export interface SystemMessage extends BaseMessage {
|
|
238
|
+
type: "system";
|
|
239
|
+
subtype?: string;
|
|
240
|
+
durationMs?: number;
|
|
241
|
+
isMeta?: boolean;
|
|
242
|
+
content?: string;
|
|
243
|
+
compactMetadata?: CompactionMeta;
|
|
244
|
+
}
|
|
245
|
+
export interface CompactionMeta {
|
|
246
|
+
trigger: "auto" | "manual";
|
|
247
|
+
preTokens: number;
|
|
248
|
+
postTokens?: number;
|
|
249
|
+
}
|
|
250
|
+
export interface FileHistorySnapshotMessage extends BaseMessage {
|
|
251
|
+
type: "file-history-snapshot";
|
|
252
|
+
messageId?: string;
|
|
253
|
+
snapshot?: {
|
|
254
|
+
messageId: string;
|
|
255
|
+
trackedFileBackups: Record<string, unknown>;
|
|
256
|
+
timestamp: string;
|
|
257
|
+
};
|
|
258
|
+
isSnapshotUpdate?: boolean;
|
|
259
|
+
}
|
|
260
|
+
export interface SummaryMessage extends BaseMessage {
|
|
261
|
+
type: "summary";
|
|
262
|
+
leafUuid?: string;
|
|
263
|
+
summary?: string;
|
|
264
|
+
}
|
|
265
|
+
/** Claude Code persists prompts submitted during an active turn as queue operations. */
|
|
266
|
+
export interface QueueOperationMessage extends BaseMessage {
|
|
267
|
+
type: "queue-operation";
|
|
268
|
+
operation: "enqueue" | "dequeue" | "remove" | string;
|
|
269
|
+
content?: string | null;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Claude Code persists the text of a prompt queued mid-turn here, not on the
|
|
273
|
+
* queue-operation record. `commandMode` separates prompts the user typed
|
|
274
|
+
* ("prompt") from Claude's own injected notices ("task-notification").
|
|
275
|
+
*/
|
|
276
|
+
export interface AttachmentMessage extends BaseMessage {
|
|
277
|
+
type: "attachment";
|
|
278
|
+
attachment?: {
|
|
279
|
+
type?: string;
|
|
280
|
+
prompt?: string | ContentBlock[] | null;
|
|
281
|
+
commandMode?: string;
|
|
282
|
+
timestamp?: string;
|
|
283
|
+
/**
|
|
284
|
+
* Who queued this prompt. `"human"` is the reader typing mid-turn;
|
|
285
|
+
* `"peer"` is another agent sending this session a message. `body` is the
|
|
286
|
+
* message with its envelope already stripped, so it beats re-parsing
|
|
287
|
+
* `prompt`. Absent on records written before Claude Code added the field.
|
|
288
|
+
*/
|
|
289
|
+
origin?: {
|
|
290
|
+
kind?: string;
|
|
291
|
+
from?: string;
|
|
292
|
+
name?: string;
|
|
293
|
+
senderTaskId?: string;
|
|
294
|
+
body?: string;
|
|
295
|
+
} | null;
|
|
296
|
+
} | null;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Written when a session enters or leaves a `.claude/worktrees/*` checkout.
|
|
300
|
+
* The record is the session's current worktree state, so a later one supersedes
|
|
301
|
+
* an earlier one, and a null `worktreeSession` means the session left.
|
|
302
|
+
*/
|
|
303
|
+
export interface WorktreeStateMessage extends BaseMessage {
|
|
304
|
+
type: "worktree-state";
|
|
305
|
+
worktreeSession?: {
|
|
306
|
+
originalCwd?: string;
|
|
307
|
+
preEnterOriginalCwd?: string;
|
|
308
|
+
worktreePath?: string;
|
|
309
|
+
worktreeName?: string;
|
|
310
|
+
worktreeBranch?: string;
|
|
311
|
+
originalBranch?: string;
|
|
312
|
+
originalHeadCommit?: string;
|
|
313
|
+
sessionId?: string;
|
|
314
|
+
} | null;
|
|
315
|
+
}
|
|
316
|
+
/** The agent type a session was launched as, e.g. "general-purpose". */
|
|
317
|
+
export interface AgentSettingMessage extends BaseMessage {
|
|
318
|
+
type: "agent-setting";
|
|
319
|
+
agentSetting?: string;
|
|
320
|
+
}
|
|
321
|
+
export type RawMessage = UserMessage | AssistantMessage | ProgressMessage | SystemMessage | FileHistorySnapshotMessage | SummaryMessage | QueueOperationMessage | AttachmentMessage;
|
|
322
|
+
export interface ToolCall {
|
|
323
|
+
id: string;
|
|
324
|
+
name: string;
|
|
325
|
+
input: Record<string, unknown>;
|
|
326
|
+
result: string | null;
|
|
327
|
+
isError: boolean;
|
|
328
|
+
timestamp: string;
|
|
329
|
+
/** Set by parser when a PostToolUse hook replaced this tool's output */
|
|
330
|
+
outputReplacedByHook?: boolean;
|
|
331
|
+
/** Total duration of PostToolUse hooks attached to this call, summed in ms */
|
|
332
|
+
hookDurationMs?: number;
|
|
333
|
+
}
|
|
334
|
+
export interface SubAgentMessage {
|
|
335
|
+
agentId: string;
|
|
336
|
+
/** The Task/Agent tool_use id this agent belongs to (streaming overlay key) */
|
|
337
|
+
parentToolUseId?: string;
|
|
338
|
+
agentName: string | null;
|
|
339
|
+
subagentType: string | null;
|
|
340
|
+
type: "user" | "assistant";
|
|
341
|
+
content: unknown;
|
|
342
|
+
toolCalls: ToolCall[];
|
|
343
|
+
thinking: string[];
|
|
344
|
+
text: string[];
|
|
345
|
+
timestamp: string;
|
|
346
|
+
tokenUsage: TokenUsage | null;
|
|
347
|
+
model: string | null;
|
|
348
|
+
isBackground: boolean;
|
|
349
|
+
/** Summary fields from toolUseResult (new format, v2.1.63+) */
|
|
350
|
+
prompt?: string;
|
|
351
|
+
status?: string;
|
|
352
|
+
durationMs?: number;
|
|
353
|
+
toolUseCount?: number;
|
|
354
|
+
}
|
|
355
|
+
/** Ordered content block within a turn – preserves chronological order */
|
|
356
|
+
export type TurnContentBlock = {
|
|
357
|
+
kind: "thinking";
|
|
358
|
+
blocks: ThinkingBlock[];
|
|
359
|
+
timestamp?: string;
|
|
360
|
+
} | {
|
|
361
|
+
kind: "text";
|
|
362
|
+
text: string[];
|
|
363
|
+
timestamp?: string;
|
|
364
|
+
} | {
|
|
365
|
+
kind: "tool_calls";
|
|
366
|
+
toolCalls: ToolCall[];
|
|
367
|
+
timestamp?: string;
|
|
368
|
+
} | {
|
|
369
|
+
kind: "queued_prompt";
|
|
370
|
+
content: string;
|
|
371
|
+
timestamp?: string;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* A message another agent sent this session mid-turn. Distinct from
|
|
375
|
+
* `queued_prompt`, which is the reader's own text. `reply` is filled by the
|
|
376
|
+
* pairing pass when a later SendMessage answered this sender.
|
|
377
|
+
*
|
|
378
|
+
* Deliberately carries no sender task id. `origin.senderTaskId` on the record
|
|
379
|
+
* identifies the sending agent's *task*, not the message — one agent's
|
|
380
|
+
* question and its later done-report share an id — so it is useless as a
|
|
381
|
+
* per-message key and destructive as a dedup key.
|
|
382
|
+
*/
|
|
383
|
+
| {
|
|
384
|
+
kind: "agent_message";
|
|
385
|
+
sender: string;
|
|
386
|
+
body: string;
|
|
387
|
+
timestamp?: string;
|
|
388
|
+
reply?: {
|
|
389
|
+
summary: string;
|
|
390
|
+
timestamp: string;
|
|
391
|
+
};
|
|
392
|
+
} | {
|
|
393
|
+
kind: "sub_agent";
|
|
394
|
+
messages: SubAgentMessage[];
|
|
395
|
+
timestamp?: string;
|
|
396
|
+
} | {
|
|
397
|
+
kind: "background_agent";
|
|
398
|
+
messages: SubAgentMessage[];
|
|
399
|
+
timestamp?: string;
|
|
400
|
+
} | {
|
|
401
|
+
kind: "hook_event";
|
|
402
|
+
events: ParsedHookEvent[];
|
|
403
|
+
timestamp?: string;
|
|
404
|
+
} | {
|
|
405
|
+
kind: "plan_mode";
|
|
406
|
+
plan: string;
|
|
407
|
+
planFilePath?: string;
|
|
408
|
+
status: "pending" | "approved" | "rejected";
|
|
409
|
+
toolCalls: ToolCall[];
|
|
410
|
+
timestamp?: string;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Away summary / recap block — emitted as a system message with
|
|
414
|
+
* subtype "away_summary" (Claude Code v2.1.108+, observed in production
|
|
415
|
+
* JSONL as of 2026-04). The /recap command produces the same shape.
|
|
416
|
+
* Content is plain text (may be long-form prose, not always markdown).
|
|
417
|
+
*/
|
|
418
|
+
| {
|
|
419
|
+
kind: "recap";
|
|
420
|
+
content: string;
|
|
421
|
+
timestamp?: string;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* A background task reporting back, which resumes the turn that launched it
|
|
425
|
+
* rather than opening one of its own. `content` is the raw record text —
|
|
426
|
+
* one or more `<task-notification>` blocks, possibly inside a
|
|
427
|
+
* `<system-reminder>` envelope (Claude Code 2.1.234+) — left unparsed here
|
|
428
|
+
* for the same reason `queued_prompt` is: the renderers own that grammar.
|
|
429
|
+
*/
|
|
430
|
+
| {
|
|
431
|
+
kind: "task_notification";
|
|
432
|
+
content: string;
|
|
433
|
+
timestamp?: string;
|
|
434
|
+
};
|
|
435
|
+
export interface Turn {
|
|
436
|
+
id: string;
|
|
437
|
+
userMessage: UserContent | null;
|
|
438
|
+
/** Chronologically ordered content blocks for rendering */
|
|
439
|
+
contentBlocks: TurnContentBlock[];
|
|
440
|
+
thinking: ThinkingBlock[];
|
|
441
|
+
assistantText: string[];
|
|
442
|
+
toolCalls: ToolCall[];
|
|
443
|
+
subAgentActivity: SubAgentMessage[];
|
|
444
|
+
timestamp: string;
|
|
445
|
+
durationMs: number | null;
|
|
446
|
+
tokenUsage: TokenUsage | null;
|
|
447
|
+
model: string | null;
|
|
448
|
+
/**
|
|
449
|
+
* Summary of the compaction that happened before this turn, as written by
|
|
450
|
+
* the compacting model. Absent when the transcript records the boundary but
|
|
451
|
+
* not the summary (e.g. the session ended right after compacting).
|
|
452
|
+
*/
|
|
453
|
+
compactionSummary?: string;
|
|
454
|
+
/** Trigger and token counts of the compaction that happened before this turn */
|
|
455
|
+
compactionMeta?: CompactionMeta;
|
|
456
|
+
/**
|
|
457
|
+
* Reasoning effort the turn ran at, when the transcript recorded one.
|
|
458
|
+
* A turn spanning several assistant messages reports the last one, since
|
|
459
|
+
* effort can be changed mid-session.
|
|
460
|
+
*/
|
|
461
|
+
effort?: string;
|
|
462
|
+
/**
|
|
463
|
+
* What drove this turn — skill, plugin, MCP server, subagent type. Merged
|
|
464
|
+
* across the turn's assistant messages, since a turn can start under a skill
|
|
465
|
+
* and later reach for an MCP tool. Undefined when nothing was attributed.
|
|
466
|
+
*/
|
|
467
|
+
attribution?: MessageAttribution;
|
|
468
|
+
/**
|
|
469
|
+
* Set when this turn was opened without its start record — the parse window
|
|
470
|
+
* began mid-turn. Such a turn is the newer half of a byte-boundary cut and
|
|
471
|
+
* must be stitched onto the previous turn once the older page arrives.
|
|
472
|
+
*/
|
|
473
|
+
isFragment?: boolean;
|
|
474
|
+
}
|
|
475
|
+
export interface SessionStats {
|
|
476
|
+
totalInputTokens: number;
|
|
477
|
+
totalOutputTokens: number;
|
|
478
|
+
totalCacheCreationTokens: number;
|
|
479
|
+
totalCacheReadTokens: number;
|
|
480
|
+
toolCallCounts: Record<string, number>;
|
|
481
|
+
errorCount: number;
|
|
482
|
+
totalDurationMs: number;
|
|
483
|
+
turnCount: number;
|
|
484
|
+
}
|
|
485
|
+
export interface ParseSessionOptions {
|
|
486
|
+
/** Skip aggregate cost/token work and raw-message retention for index-only consumers. */
|
|
487
|
+
skipStats?: boolean;
|
|
488
|
+
}
|
|
489
|
+
export interface ParsedSession {
|
|
490
|
+
sessionId: string;
|
|
491
|
+
version: string;
|
|
492
|
+
gitBranch: string;
|
|
493
|
+
cwd: string;
|
|
494
|
+
slug: string;
|
|
495
|
+
/** Session display name set via `--name` CLI flag. */
|
|
496
|
+
name: string;
|
|
497
|
+
model: string;
|
|
498
|
+
turns: Turn[];
|
|
499
|
+
stats: SessionStats;
|
|
500
|
+
/**
|
|
501
|
+
* Raw JSONL message objects. Widened from `RawMessage[]` to support multiple
|
|
502
|
+
* provider formats (Claude Code and Codex) without a discriminated union at
|
|
503
|
+
* every call site. Use `agentKind` to distinguish formats when needed.
|
|
504
|
+
*/
|
|
505
|
+
rawMessages: Array<{
|
|
506
|
+
type: string;
|
|
507
|
+
[key: string]: unknown;
|
|
508
|
+
}>;
|
|
509
|
+
branchedFrom?: {
|
|
510
|
+
sessionId: string;
|
|
511
|
+
turnIndex?: number | null;
|
|
512
|
+
};
|
|
513
|
+
/**
|
|
514
|
+
* The provider that produced this session. Set by the parser when the
|
|
515
|
+
* format is known. Consumers can use this instead of inspecting rawMessages.
|
|
516
|
+
*/
|
|
517
|
+
agentKind?: "claude" | "codex";
|
|
518
|
+
}
|
|
519
|
+
export interface ArchivedToolCall {
|
|
520
|
+
type: "Edit" | "Write";
|
|
521
|
+
filePath: string;
|
|
522
|
+
oldString?: string;
|
|
523
|
+
newString?: string;
|
|
524
|
+
replaceAll?: boolean;
|
|
525
|
+
content?: string;
|
|
526
|
+
}
|
|
527
|
+
export interface ArchivedTurn {
|
|
528
|
+
index: number;
|
|
529
|
+
userMessage: string | null;
|
|
530
|
+
toolCalls: ArchivedToolCall[];
|
|
531
|
+
thinkingBlocks: string[];
|
|
532
|
+
assistantText: string[];
|
|
533
|
+
timestamp: string;
|
|
534
|
+
model: string | null;
|
|
535
|
+
}
|
|
536
|
+
export interface Branch {
|
|
537
|
+
id: string;
|
|
538
|
+
createdAt: string;
|
|
539
|
+
branchPointTurnIndex: number;
|
|
540
|
+
label: string;
|
|
541
|
+
turns: ArchivedTurn[];
|
|
542
|
+
jsonlLines: string[];
|
|
543
|
+
/** Branches that were nested within the archived range, preserved for restore */
|
|
544
|
+
childBranches?: Branch[];
|
|
545
|
+
}
|
|
546
|
+
export interface UndoState {
|
|
547
|
+
sessionId: string;
|
|
548
|
+
currentTurnIndex: number;
|
|
549
|
+
totalTurns: number;
|
|
550
|
+
branches: Branch[];
|
|
551
|
+
activeBranchId: string | null;
|
|
552
|
+
}
|
|
553
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogpit-memory",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "CLI tool for Claude Code
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "CLI tool for Claude Code and Codex 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
|
+
"session",
|
|
17
|
+
"memory",
|
|
18
|
+
"cli",
|
|
19
|
+
"agent"
|
|
20
|
+
],
|
|
21
|
+
"packageManager": "bun@1.3.14",
|
|
5
22
|
"main": "./dist/index.js",
|
|
6
|
-
"types": "./
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
7
24
|
"bin": {
|
|
8
|
-
"cogpit-memory": "
|
|
25
|
+
"cogpit-memory": "dist/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
9
29
|
},
|
|
10
30
|
"files": [
|
|
11
31
|
"dist/",
|
|
12
|
-
"skill/"
|
|
32
|
+
"skill/",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
13
35
|
],
|
|
14
36
|
"scripts": {
|
|
15
37
|
"test": "bun test",
|
|
38
|
+
"test:contracts": "bun run build:npm && node scripts/test-package-contract.mjs",
|
|
16
39
|
"build": "bun build --compile src/cli.ts --outfile cogpit-memory",
|
|
17
|
-
"build:npm": "node scripts/build-npm.mjs",
|
|
18
|
-
"prepublishOnly": "
|
|
40
|
+
"build:npm": "node scripts/build-npm.mjs && tsc --pretty false -p tsconfig.build.json",
|
|
41
|
+
"prepublishOnly": "bun run build:npm"
|
|
19
42
|
},
|
|
20
43
|
"dependencies": {
|
|
21
44
|
"better-sqlite3": "^12.6.2"
|
|
@@ -23,6 +46,7 @@
|
|
|
23
46
|
"devDependencies": {
|
|
24
47
|
"@types/better-sqlite3": "^7.6.13",
|
|
25
48
|
"bun-types": "latest",
|
|
26
|
-
"esbuild": "^0.27.3"
|
|
49
|
+
"esbuild": "^0.27.3",
|
|
50
|
+
"typescript": "~5.6.2"
|
|
27
51
|
}
|
|
28
52
|
}
|
package/skill/SKILL.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cogpit-memory
|
|
3
|
-
description: CLI tool for Claude Code 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 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.
|
|
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 sessions. Retrieve conversation history, tool usage, thinking, and sub-agent activity via a layered command structure.
|
|
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.
|
|
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
|
|
|
@@ -105,7 +105,7 @@ Response shape:
|
|
|
105
105
|
```
|
|
106
106
|
|
|
107
107
|
Key fields:
|
|
108
|
-
- `userMessage` -- the human's full prompt text (`null` for synthetic turns
|
|
108
|
+
- `userMessage` -- the human's full prompt text (`null` for synthetic turns; images, documents, and audio are shown as attachment placeholders)
|
|
109
109
|
- `assistantMessage` -- the AI's full text response (`null` if only tools ran)
|
|
110
110
|
- `toolSummary` -- tool name to count (e.g., `{"Read": 5, "Edit": 2}`)
|
|
111
111
|
- `subAgents` -- summary of sub-agents that ran in this turn. Fields `status`, `durationMs`, `toolUseCount` may be `null` for older sessions
|
|
@@ -151,7 +151,7 @@ Response shape:
|
|
|
151
151
|
```
|
|
152
152
|
|
|
153
153
|
Key details:
|
|
154
|
-
- `contentBlocks` kinds: `thinking`, `text`, `tool_calls`, `sub_agent`, `background_agent`
|
|
154
|
+
- `contentBlocks` kinds: `thinking`, `text`, `tool_calls`, `sub_agent`, `background_agent`, `queued_prompt`, `hook_event`, `plan_mode`, `recap`, `agent_message`
|
|
155
155
|
- Tool call `result` is truncated at 10,000 chars -- check `resultTruncated: true`
|
|
156
156
|
- Tool call `result` may be `null` if the tool hasn't returned yet
|
|
157
157
|
- Sub-agent blocks show prompt + result text. For full sub-agent conversation, use Layer 3
|