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/README.md +34 -25
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +3261 -1726
- package/dist/commands/search.d.ts +1 -1
- package/dist/commands/sessions.d.ts +2 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +2762 -1300
- package/dist/lib/agent-descriptors.d.ts +387 -0
- package/dist/lib/agents.d.ts +112 -0
- package/dist/lib/claude.d.ts +49 -0
- package/dist/lib/codex-exec.d.ts +12 -0
- package/dist/lib/codex-tool-normalization.d.ts +25 -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 -20
- package/dist/lib/interactiveState.d.ts +9 -0
- 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 +2 -1
- package/dist/lib/sessionStatus.d.ts +11 -32
- package/dist/lib/stores.d.ts +47 -0
- package/dist/lib/turnBuilder.d.ts +22 -0
- package/dist/lib/turnContent.d.ts +2 -0
- package/dist/lib/types.d.ts +41 -3
- package/package.json +3 -2
- package/skill/SKILL.md +58 -48
- package/dist/lib/token-costs.d.ts +0 -27
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ParseSessionOptions, ParsedSession, RawRecord, SessionStatusInfo } from "./types";
|
|
2
|
+
interface CopilotMetadata {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
version: string;
|
|
5
|
+
gitBranch: string;
|
|
6
|
+
cwd: string;
|
|
7
|
+
model: string;
|
|
8
|
+
slug: string;
|
|
9
|
+
name: string;
|
|
10
|
+
firstUserMessage: string;
|
|
11
|
+
lastUserMessage: string;
|
|
12
|
+
timestamp: string;
|
|
13
|
+
lastTimestamp: string;
|
|
14
|
+
turnCount: number;
|
|
15
|
+
isSubagent: false;
|
|
16
|
+
parentSessionId: null;
|
|
17
|
+
}
|
|
18
|
+
export declare function isCopilotSessionText(jsonlText: string): boolean;
|
|
19
|
+
/** True when already-parsed raw records came from this CLI. */
|
|
20
|
+
export declare function isCopilotRawRecords(records: readonly {
|
|
21
|
+
type?: unknown;
|
|
22
|
+
}[]): boolean;
|
|
23
|
+
export declare function extractCopilotMetadataFromLines(lines: string[]): CopilotMetadata;
|
|
24
|
+
export declare function parseCopilotSession(jsonlText: string, options?: ParseSessionOptions): ParsedSession;
|
|
25
|
+
/**
|
|
26
|
+
* Incrementally extend a parsed session with newly written lines.
|
|
27
|
+
*
|
|
28
|
+
* Copilot's durable events carry cross-turn state (permission requests, usage
|
|
29
|
+
* roll-ups, sub-agent lifecycles), so the whole transcript is re-parsed rather
|
|
30
|
+
* than only its tail.
|
|
31
|
+
*/
|
|
32
|
+
export declare function appendCopilotSession(existing: ParsedSession, newJsonlText: string): ParsedSession;
|
|
33
|
+
/** True when a record `type` belongs to this CLI's durable event stream. */
|
|
34
|
+
export declare function isCopilotEventType(type: unknown): type is string;
|
|
35
|
+
/** Derive status from Copilot CLI's durable session events. */
|
|
36
|
+
export declare function deriveCopilotSessionStatus(rawMessages: readonly RawRecord[]): SessionStatusInfo;
|
|
37
|
+
/**
|
|
38
|
+
* Copilot branches through its own fork RPC (`capabilities.nativeFork`), so a
|
|
39
|
+
* copied-and-cut transcript is never made and there is no header shape to
|
|
40
|
+
* invent for one.
|
|
41
|
+
*/
|
|
42
|
+
export declare function brandCopilotBranch(): never;
|
|
43
|
+
/**
|
|
44
|
+
* Indexes of the `user.message` events that open a turn.
|
|
45
|
+
*
|
|
46
|
+
* Sub-agent events carry an `agentId` and belong to the turn already in
|
|
47
|
+
* flight. An event with no durable `id` cannot be addressed by the CLI's fork
|
|
48
|
+
* and rewind RPCs, so it cannot be a boundary either.
|
|
49
|
+
*/
|
|
50
|
+
export declare function copilotTurnBoundaries(records: readonly Record<string, unknown>[]): number[];
|
|
51
|
+
export {};
|
package/dist/lib/dirs.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
import { type AgentKind } from "./agent-descriptors";
|
|
2
|
+
/**
|
|
3
|
+
* Where each agent CLI keeps its state, honouring the environment variable it
|
|
4
|
+
* publishes for that. `$CODEX_HOME` used to be ignored here while
|
|
5
|
+
* `$COPILOT_HOME` was honoured, so a redirected Codex install was invisible to
|
|
6
|
+
* the whole package.
|
|
7
|
+
*/
|
|
8
|
+
export declare function agentHomeDir(kind: AgentKind, env?: NodeJS.ProcessEnv, homeDirectory?: string): string;
|
|
1
9
|
export declare const dirs: {
|
|
2
10
|
PROJECTS_DIR: string;
|
|
3
11
|
TEAMS_DIR: string;
|
|
4
12
|
TASKS_DIR: string;
|
|
5
13
|
CODEX_SESSIONS_DIR: string;
|
|
14
|
+
COPILOT_SESSIONS_DIR: string;
|
|
6
15
|
};
|
|
7
16
|
/** Default database path for the FTS5 search index. */
|
|
8
17
|
export declare const DEFAULT_DB_PATH: string;
|
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
|
-
/** Find the JSONL file path for a session by searching all project directories. */
|
|
2
|
-
export declare function findJsonlPath(sessionId: string): Promise<string | null>;
|
|
3
1
|
export declare function matchSubagentToMember(leadSessionId: string, subagentFileName: string, members: Array<{
|
|
4
2
|
name: string;
|
|
5
3
|
agentType: string;
|
|
6
4
|
prompt?: string;
|
|
7
5
|
}>): Promise<string | null>;
|
|
8
|
-
/**
|
|
9
|
-
* Encode a cwd using Claude Code's project-directory naming convention: every
|
|
10
|
-
* character outside `[A-Za-z0-9]` becomes `-`, so both `/Users/x/proj` and
|
|
11
|
-
* `C:\Users\x\proj` collapse into a flat directory name under
|
|
12
|
-
* `~/.claude/projects`. Mirrors `shared/providers/claude.ts`; this package is
|
|
13
|
-
* published standalone and cannot import outside its own `src` root.
|
|
14
|
-
*/
|
|
15
|
-
export declare function encodeClaudeDirName(cwd: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Best-effort inverse of {@link encodeClaudeDirName}. The encoding is lossy —
|
|
18
|
-
* a literal `-` is indistinguishable from a separator — so callers that can
|
|
19
|
-
* read a session's recorded `cwd` should always prefer that.
|
|
20
|
-
*/
|
|
21
|
-
export declare function decodeClaudeDirName(dirName: string): string;
|
|
22
|
-
export declare function projectDirToReadableName(dirName: string): {
|
|
23
|
-
path: string;
|
|
24
|
-
shortName: string;
|
|
25
|
-
};
|
|
@@ -8,6 +8,12 @@ export interface PlanApprovalState {
|
|
|
8
8
|
tool: string;
|
|
9
9
|
prompt: string;
|
|
10
10
|
}>;
|
|
11
|
+
provider?: "copilot";
|
|
12
|
+
requestId?: string;
|
|
13
|
+
summary?: string;
|
|
14
|
+
planContent?: string;
|
|
15
|
+
actions?: string[];
|
|
16
|
+
recommendedAction?: string;
|
|
11
17
|
}
|
|
12
18
|
export interface UserQuestionState {
|
|
13
19
|
type: "question";
|
|
@@ -36,5 +42,8 @@ export declare function isStuckInteractiveLoop(turns: Turn[], toolName: string):
|
|
|
36
42
|
/**
|
|
37
43
|
* Detect if the session is waiting for user interaction (plan approval or
|
|
38
44
|
* AskUserQuestion). Returns the interaction state or null.
|
|
45
|
+
*
|
|
46
|
+
* A blocking prompt wins over an async question asked earlier in the same turn:
|
|
47
|
+
* it is the one holding the agent up.
|
|
39
48
|
*/
|
|
40
49
|
export declare function detectPendingInteraction(session: ParsedSession): PendingInteraction;
|
package/dist/lib/metadata.d.ts
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import { type SessionStatusInfo } from "./sessionStatus";
|
|
2
|
+
/**
|
|
3
|
+
* Header metadata for one transcript, whichever agent wrote it.
|
|
4
|
+
*
|
|
5
|
+
* Which agent that is comes from the shared format registry, in its own
|
|
6
|
+
* detection order — the same code the app and the parser use, rather than a
|
|
7
|
+
* hand-rolled sniff that recognised a narrower set of Codex records.
|
|
8
|
+
*/
|
|
2
9
|
export declare function getSessionMeta(filePath: string): Promise<{
|
|
10
|
+
lineCount: number;
|
|
11
|
+
branchedFrom: {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
turnIndex?: number | null;
|
|
14
|
+
} | undefined;
|
|
15
|
+
firstUserMessage: string;
|
|
16
|
+
lastUserMessage: string;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
turnCount: number;
|
|
3
19
|
sessionId: string;
|
|
4
20
|
version: string;
|
|
5
21
|
gitBranch: string;
|
|
6
22
|
model: string;
|
|
7
23
|
slug: string;
|
|
8
24
|
cwd: string;
|
|
9
|
-
firstUserMessage: string;
|
|
10
|
-
lastUserMessage: string;
|
|
11
|
-
timestamp: string;
|
|
12
|
-
turnCount: number;
|
|
13
|
-
lineCount: number;
|
|
14
|
-
branchedFrom: {
|
|
15
|
-
sessionId: string;
|
|
16
|
-
turnIndex?: number | null;
|
|
17
|
-
} | undefined;
|
|
18
25
|
}>;
|
|
19
26
|
/**
|
|
20
27
|
* Read backward through a session JSONL to derive agent status.
|
|
@@ -24,8 +31,3 @@ export declare function getSessionMeta(filePath: string): Promise<{
|
|
|
24
31
|
* deriveSessionStatus() function as the client side.
|
|
25
32
|
*/
|
|
26
33
|
export declare function getSessionStatus(filePath: string): Promise<SessionStatusInfo>;
|
|
27
|
-
/**
|
|
28
|
-
* Search all user messages in a session file for a query string.
|
|
29
|
-
* Returns the first matching message snippet, or null if no match.
|
|
30
|
-
*/
|
|
31
|
-
export declare function searchSessionMessages(filePath: string, query: string): Promise<string | null>;
|
package/dist/lib/parser.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ImageBlock, ParseSessionOptions, ParsedSession, UserContent } from "./types";
|
|
2
2
|
export type { PendingInteraction } from "./interactiveState";
|
|
3
3
|
export type { ParseSessionOptions } from "./types";
|
|
4
4
|
export { detectPendingInteraction } from "./interactiveState";
|
|
5
5
|
export declare function parseSession(jsonlText: string, options?: ParseSessionOptions): ParsedSession;
|
|
6
6
|
/**
|
|
7
7
|
* Incrementally append new JSONL lines to an existing parsed session.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
*
|
|
9
|
+
* Dispatch is on raw-record shape, never on `existing.agentKind`: that field is
|
|
10
|
+
* optional on `ParsedSession` and this is the append hot path. When the records
|
|
11
|
+
* carry no discriminator — an empty window, or one paged in above the loaded
|
|
12
|
+
* range — the newly arrived text decides instead.
|
|
10
13
|
*/
|
|
11
14
|
export declare function parseSessionAppend(existing: ParsedSession, newJsonlText: string): ParsedSession;
|
|
12
15
|
export declare function getUserMessageText(content: UserContent | null): string;
|
|
13
16
|
export declare function getUserMessageImages(content: UserContent | null): ImageBlock[];
|
|
14
|
-
export declare function getToolColor(toolName: string): string;
|
|
@@ -6,7 +6,6 @@ export interface IndexStats {
|
|
|
6
6
|
indexedSessions: number;
|
|
7
7
|
indexedSubagents: number;
|
|
8
8
|
totalRows: number;
|
|
9
|
-
watcherRunning: boolean;
|
|
10
9
|
lastFullBuild: string | null;
|
|
11
10
|
lastUpdate: string | null;
|
|
12
11
|
}
|
|
@@ -20,12 +19,8 @@ export interface SearchHit {
|
|
|
20
19
|
export declare class SearchIndex {
|
|
21
20
|
private db;
|
|
22
21
|
private dbPath;
|
|
23
|
-
projectsDir: string | null;
|
|
24
|
-
private _watcherRunning;
|
|
25
22
|
private _lastFullBuild;
|
|
26
23
|
private _lastUpdate;
|
|
27
|
-
private watcher;
|
|
28
|
-
private debounceTimers;
|
|
29
24
|
constructor(dbPath: string);
|
|
30
25
|
private initSchema;
|
|
31
26
|
getStats(): IndexStats;
|
|
@@ -45,6 +40,7 @@ export declare class SearchIndex {
|
|
|
45
40
|
isSubagent?: boolean;
|
|
46
41
|
parentSessionId?: string | null;
|
|
47
42
|
}): void;
|
|
43
|
+
pruneMissingFiles(): number;
|
|
48
44
|
/**
|
|
49
45
|
* Query the FTS5 index and return structured search results.
|
|
50
46
|
*
|
|
@@ -59,6 +55,7 @@ export declare class SearchIndex {
|
|
|
59
55
|
search(query: string, opts?: {
|
|
60
56
|
limit?: number;
|
|
61
57
|
sessionId?: string;
|
|
58
|
+
excludeSessionId?: string;
|
|
62
59
|
maxAgeMs?: number;
|
|
63
60
|
caseSensitive?: boolean;
|
|
64
61
|
}): SearchHit[];
|
|
@@ -68,32 +65,20 @@ export declare class SearchIndex {
|
|
|
68
65
|
*/
|
|
69
66
|
countMatches(query: string, opts?: {
|
|
70
67
|
sessionId?: string;
|
|
68
|
+
excludeSessionId?: string;
|
|
71
69
|
maxAgeMs?: number;
|
|
72
70
|
}): {
|
|
73
71
|
totalHits: number;
|
|
74
72
|
sessionsSearched: number;
|
|
75
73
|
};
|
|
76
74
|
/**
|
|
77
|
-
* Clear all indexed data and re-index every
|
|
78
|
-
* Structure: projectsDir/{projectName}/{sessionId}.jsonl
|
|
79
|
-
* Subagents: projectsDir/{projectName}/{sessionId}/subagents/agent-{id}.jsonl
|
|
75
|
+
* Clear all indexed data and re-index every transcript, from every agent.
|
|
80
76
|
*
|
|
81
77
|
* Optimized: discovers all files first, then processes them in a single
|
|
82
78
|
* SQLite transaction with pre-prepared statements. This avoids the overhead
|
|
83
79
|
* of 3000+ individual transactions (each forcing a disk sync).
|
|
84
|
-
*
|
|
85
|
-
* Stores `projectsDir` as a class field so `rebuild()` can reuse it.
|
|
86
80
|
*/
|
|
87
|
-
buildFull(
|
|
88
|
-
/**
|
|
89
|
-
* Incrementally re-index only files whose mtime has changed since last index.
|
|
90
|
-
* New files (not in indexed_files) are always indexed.
|
|
91
|
-
*
|
|
92
|
-
* WARNING: This walks ALL files under projectsDir and stats each one.
|
|
93
|
-
* On large session stores (3000+ files) this can take minutes.
|
|
94
|
-
* Prefer `updateRecent()` for CLI search paths.
|
|
95
|
-
*/
|
|
96
|
-
updateStale(projectsDir: string): void;
|
|
81
|
+
buildFull(): void;
|
|
97
82
|
/**
|
|
98
83
|
* Lightweight incremental update for CLI search paths.
|
|
99
84
|
*
|
|
@@ -102,53 +87,8 @@ export declare class SearchIndex {
|
|
|
102
87
|
* Caps re-indexing to `maxFiles` to prevent blocking on large backlogs
|
|
103
88
|
* (run `index rebuild` for a full catch-up).
|
|
104
89
|
*/
|
|
105
|
-
updateRecent(
|
|
106
|
-
/**
|
|
107
|
-
* Re-run buildFull using the previously stored projectsDir.
|
|
108
|
-
* No-op if projectsDir was never set.
|
|
109
|
-
*/
|
|
110
|
-
rebuild(): void;
|
|
111
|
-
/**
|
|
112
|
-
* Walk the projects directory tree and invoke `callback` for every JSONL file.
|
|
113
|
-
*
|
|
114
|
-
* Directory structure:
|
|
115
|
-
* projectsDir/
|
|
116
|
-
* {projectName}/
|
|
117
|
-
* {sessionId}.jsonl <- session file
|
|
118
|
-
* {sessionId}/subagents/
|
|
119
|
-
* agent-{agentId}.jsonl <- subagent file (recursive)
|
|
120
|
-
*
|
|
121
|
-
* Skips the "memory" directory.
|
|
122
|
-
*/
|
|
90
|
+
updateRecent(maxFiles?: number): void;
|
|
91
|
+
/** Every transcript from every agent, tagged with the session it belongs to. */
|
|
123
92
|
private discoverFiles;
|
|
124
|
-
/**
|
|
125
|
-
* Recursively discover subagent JSONL files under the subagents directory
|
|
126
|
-
* that corresponds to `parentPath`.
|
|
127
|
-
*
|
|
128
|
-
* For a parent at `/path/to/session-1.jsonl`, looks for subagents at
|
|
129
|
-
* `/path/to/session-1/subagents/agent-*.jsonl`.
|
|
130
|
-
*
|
|
131
|
-
* Recurses up to `maxDepth` levels (default 4).
|
|
132
|
-
*/
|
|
133
|
-
private discoverSubagents;
|
|
134
|
-
/**
|
|
135
|
-
* Start watching `projectsDir` for JSONL file changes.
|
|
136
|
-
* Runs `updateStale()` immediately for an initial sync, then sets up
|
|
137
|
-
* `fs.watch` with `{ recursive: true }` (macOS-compatible) to detect
|
|
138
|
-
* subsequent file changes and trigger debounced re-indexing.
|
|
139
|
-
*/
|
|
140
|
-
startWatching(projectsDir: string): void;
|
|
141
|
-
/**
|
|
142
|
-
* Stop the file watcher and clear any pending debounce timers.
|
|
143
|
-
* Safe to call even when not watching (no-op).
|
|
144
|
-
*/
|
|
145
|
-
stopWatching(): void;
|
|
146
|
-
/**
|
|
147
|
-
* Private helper: debounce re-indexing of a single file.
|
|
148
|
-
* Waits 2 seconds after the last change event for a given file path
|
|
149
|
-
* before actually calling `indexFile()`. This coalesces rapid writes
|
|
150
|
-
* (e.g. streaming JSONL appends) into a single index operation.
|
|
151
|
-
*/
|
|
152
|
-
private debouncedReindex;
|
|
153
93
|
close(): void;
|
|
154
94
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* computed here: pricing needs the live LiteLLM rate table, which callers
|
|
6
6
|
* apply via shared/usageCost/pricing.ts.
|
|
7
7
|
*/
|
|
8
|
-
import type { Turn, SessionStats } from "./types";
|
|
8
|
+
import type { Turn, SessionStats, TokenUsage } from "./types";
|
|
9
9
|
export declare function createEmptySessionStats(turnCount: number): SessionStats;
|
|
10
10
|
export declare function computeStats(turns: Turn[]): SessionStats;
|
|
11
|
+
export declare function mergeTokenUsage(existing: TokenUsage | null, incoming: TokenUsage): TokenUsage;
|
|
@@ -1,42 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Walks backward from the last message to determine if the agent
|
|
4
|
-
* is idle, thinking, calling tools, etc.
|
|
2
|
+
* Session status: what the agent is doing right now, and how to label it.
|
|
5
3
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Status is always derived from raw transcript records, never stored as app
|
|
5
|
+
* state. Each format derives its own — this file only routes to the format the
|
|
6
|
+
* records were written in, and holds the presentation labels.
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
export
|
|
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
|
-
type RawMsg = {
|
|
24
|
-
type: string;
|
|
25
|
-
[key: string]: unknown;
|
|
26
|
-
};
|
|
8
|
+
import type { RawRecord, SessionStatus, SessionStatusInfo } from "./types";
|
|
9
|
+
export type { SessionStatus, SessionStatusInfo } from "./types";
|
|
27
10
|
/**
|
|
28
|
-
* Derive session status from raw JSONL
|
|
11
|
+
* Derive session status from raw JSONL record objects.
|
|
29
12
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* to `deriveCodexSessionStatus`. All other sessions are treated as Claude Code
|
|
34
|
-
* format. If a third provider is added, add a detection branch here and in
|
|
35
|
-
* `src/lib/providers/registry.ts`.
|
|
13
|
+
* The format is resolved from the records themselves, in `AGENT_KINDS` order,
|
|
14
|
+
* so a transcript that carries no positive discriminator lands on the terminal
|
|
15
|
+
* format — the same fallback the parser uses.
|
|
36
16
|
*/
|
|
37
|
-
export declare function deriveSessionStatus(rawMessages:
|
|
17
|
+
export declare function deriveSessionStatus(rawMessages: RawRecord[]): SessionStatusInfo;
|
|
38
18
|
/** Human-readable label for terminal_reason values from Claude Code. */
|
|
39
19
|
export declare function getTerminalReasonLabel(reason: string): string;
|
|
40
20
|
/** Human-readable label for a session status. Returns null for "idle". */
|
|
41
21
|
export declare function getStatusLabel(status: SessionStatus | undefined, toolName?: string, terminalReason?: string, pendingAgents?: number): string | null;
|
|
42
|
-
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type AgentDescriptor, type AgentKind } from "./agent-descriptors";
|
|
2
|
+
/** One transcript on disk, plus what an index needs to file it under. */
|
|
3
|
+
export interface SessionFile {
|
|
4
|
+
path: string;
|
|
5
|
+
mtimeMs: number;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
isSubagent: boolean;
|
|
8
|
+
parentSessionId: string | null;
|
|
9
|
+
}
|
|
10
|
+
/** Where a transcript belongs, without reading it. */
|
|
11
|
+
export type SessionFileIdentity = Omit<SessionFile, "path" | "mtimeMs">;
|
|
12
|
+
export interface AgentSessionStore {
|
|
13
|
+
readonly kind: AgentKind;
|
|
14
|
+
readonly descriptor: AgentDescriptor;
|
|
15
|
+
/** Absolute root this agent's transcripts live under. */
|
|
16
|
+
root(): string;
|
|
17
|
+
/** True when an absolute path is inside this agent's root. */
|
|
18
|
+
ownsPath(filePath: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Which session a transcript belongs to. Never `basename(file, ".jsonl")`:
|
|
21
|
+
* that is Copilot's literal `events`, and it loses a sub-agent's parent.
|
|
22
|
+
*/
|
|
23
|
+
identify(filePath: string, root?: string): SessionFileIdentity;
|
|
24
|
+
/** Transcripts modified at or after `cutoffMs`. */
|
|
25
|
+
list(cutoffMs: number, root?: string): SessionFile[];
|
|
26
|
+
/** Locate a session by id, or null when this agent does not have it. */
|
|
27
|
+
find(sessionId: string): string | null;
|
|
28
|
+
}
|
|
29
|
+
export declare function storeFor(kind: AgentKind): AgentSessionStore;
|
|
30
|
+
/** The store a path under no known root is read with: the agent that owns every unprefixed project. */
|
|
31
|
+
export declare function defaultStore(): AgentSessionStore;
|
|
32
|
+
/** Every store, in registry order. */
|
|
33
|
+
export declare function allStores(): readonly AgentSessionStore[];
|
|
34
|
+
/** The store whose root contains `filePath`, or null when none does. */
|
|
35
|
+
export declare function storeForPath(filePath: string): AgentSessionStore | null;
|
|
36
|
+
/**
|
|
37
|
+
* Transcripts from every agent, newest first. One walk per root, so no caller
|
|
38
|
+
* can accidentally cover a different set of agents from its neighbours.
|
|
39
|
+
*/
|
|
40
|
+
export declare function listAllSessionFiles(cutoffMs: number): SessionFile[];
|
|
41
|
+
/**
|
|
42
|
+
* Absolute path of a session's transcript, searched across every agent.
|
|
43
|
+
*
|
|
44
|
+
* The id arrives from a CLI argument and is joined straight onto a root, so it
|
|
45
|
+
* is rejected outright unless it is a single path segment.
|
|
46
|
+
*/
|
|
47
|
+
export declare function findSessionFile(sessionId: string): Promise<string | null>;
|
|
@@ -33,6 +33,28 @@ export declare function pairAgentMessageReplies(turns: readonly Turn[]): Turn[];
|
|
|
33
33
|
*
|
|
34
34
|
* Mirrors the turn-creation rule of `buildTurns` below — a parser test asserts
|
|
35
35
|
* the two agree, so keep them in lockstep.
|
|
36
|
+
*
|
|
37
|
+
* This is a cheap forward scan on the append hot path, which is the only reason
|
|
38
|
+
* it restates the rule instead of calling `buildTurnsWithStarts`. It is
|
|
39
|
+
* deliberately NOT used to cut a transcript: undo and branching go through
|
|
40
|
+
* `AgentFormat.turnBoundaries`, which is derived from the real turn walk,
|
|
41
|
+
* because a boundary that disagrees with the parser truncates history. Widen
|
|
42
|
+
* this only alongside `buildTurns`, never on its own.
|
|
36
43
|
*/
|
|
37
44
|
export declare function findTurnStartIndices(messages: RawMessage[]): number[];
|
|
45
|
+
export interface BuiltTurns {
|
|
46
|
+
turns: Turn[];
|
|
47
|
+
/** Index, into `messages`, of the record that opened each turn. */
|
|
48
|
+
turnStartIndices: number[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build turns and report where each one started.
|
|
52
|
+
*
|
|
53
|
+
* Turn boundaries used to be derived by a separate predicate that restated this
|
|
54
|
+
* function's turn rule; the two drifted, and because boundaries decide where a
|
|
55
|
+
* transcript gets physically cut, the disagreement silently truncated history.
|
|
56
|
+
* Both now come from this one walk.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildTurnsWithStarts(messages: RawMessage[]): BuiltTurns;
|
|
59
|
+
/** Turns only — the common case. */
|
|
38
60
|
export declare function buildTurns(messages: RawMessage[]): Turn[];
|
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;
|
|
@@ -324,8 +351,18 @@ export interface ToolCall {
|
|
|
324
351
|
name: string;
|
|
325
352
|
input: Record<string, unknown>;
|
|
326
353
|
result: string | null;
|
|
354
|
+
/** Binary images returned by a tool, when the provider persists them. */
|
|
355
|
+
resultImages?: ImageBlock[];
|
|
327
356
|
isError: boolean;
|
|
328
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;
|
|
329
366
|
/** Set by parser when a PostToolUse hook replaced this tool's output */
|
|
330
367
|
outputReplacedByHook?: boolean;
|
|
331
368
|
/** Total duration of PostToolUse hooks attached to this call, summed in ms */
|
|
@@ -511,10 +548,11 @@ export interface ParsedSession {
|
|
|
511
548
|
turnIndex?: number | null;
|
|
512
549
|
};
|
|
513
550
|
/**
|
|
514
|
-
* The
|
|
515
|
-
*
|
|
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`).
|
|
516
554
|
*/
|
|
517
|
-
agentKind?:
|
|
555
|
+
agentKind?: AgentKind;
|
|
518
556
|
}
|
|
519
557
|
export interface ArchivedToolCall {
|
|
520
558
|
type: "Edit" | "Write";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"keywords": [
|
|
14
14
|
"claude-code",
|
|
15
15
|
"codex",
|
|
16
|
+
"github-copilot",
|
|
16
17
|
"session",
|
|
17
18
|
"memory",
|
|
18
19
|
"cli",
|