Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/chronicle/common/sessionStore.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { createServiceIdentifier } from '../../../util/common/services';
7
8
// ── Service identifier ──────────────────────────────────────────────────────────
9
10
export const ISessionStore = createServiceIdentifier<ISessionStore>('ISessionStore');
11
12
// ── Row types (same as copilot-agent-runtime SessionStore) ──────────────────────
13
14
/**
15
* Metadata for a session row.
16
*/
17
export interface SessionRow {
18
id: string;
19
cwd?: string;
20
repository?: string;
21
host_type?: string;
22
branch?: string;
23
summary?: string;
24
agent_name?: string;
25
agent_description?: string;
26
created_at?: string;
27
updated_at?: string;
28
}
29
30
/**
31
* A conversation turn (user→assistant pair).
32
*/
33
export interface TurnRow {
34
session_id: string;
35
turn_index: number;
36
user_message?: string;
37
assistant_response?: string;
38
timestamp?: string;
39
}
40
41
/**
42
* A compaction checkpoint broken into sections.
43
*/
44
export interface CheckpointRow {
45
session_id: string;
46
checkpoint_number: number;
47
title?: string;
48
overview?: string;
49
history?: string;
50
work_done?: string;
51
technical_details?: string;
52
important_files?: string;
53
next_steps?: string;
54
created_at?: string;
55
}
56
57
/**
58
* A file touched during a session.
59
*/
60
export interface FileRow {
61
session_id: string;
62
file_path: string;
63
tool_name?: string;
64
turn_index?: number;
65
first_seen_at?: string;
66
}
67
68
/**
69
* A reference linking a session to an external entity.
70
*/
71
export interface RefRow {
72
session_id: string;
73
ref_type: 'commit' | 'pr' | 'issue';
74
ref_value: string;
75
turn_index?: number;
76
created_at?: string;
77
}
78
79
/**
80
* A single FTS5 search result.
81
*/
82
export interface SearchResult {
83
session_id: string;
84
source_type: string;
85
content: string;
86
rank: number;
87
}
88
89
// ── Service interface ───────────────────────────────────────────────────────────
90
91
export interface ISessionStore {
92
readonly _serviceBrand: undefined;
93
94
/** Get the path to the database file. */
95
getPath(): string;
96
97
// ── CRUD ────────────────────────────────────────────────────────────
98
99
/** Insert or update a session's metadata. */
100
upsertSession(session: SessionRow): void;
101
102
/** Insert a conversation turn and index it for full-text search. */
103
insertTurn(turn: TurnRow): void;
104
105
/** Insert a compaction checkpoint and index its sections for full-text search. */
106
insertCheckpoint(checkpoint: CheckpointRow): void;
107
108
/** Record a file touched during a session. First occurrence wins. */
109
insertFile(file: FileRow): void;
110
111
/** Record a reference (commit, PR, issue) for a session. */
112
insertRef(ref: RefRow): void;
113
114
/** Index a workspace artifact for full-text search. Upserts by file path. */
115
indexWorkspaceArtifact(sessionId: string, filePath: string, content: string): void;
116
117
// ── Queries ─────────────────────────────────────────────────────────
118
119
/** Full-text search across all indexed content. */
120
search(query: string, limit?: number): SearchResult[];
121
122
/** Get a session by ID. */
123
getSession(sessionId: string): SessionRow | undefined;
124
125
/** Get all turns for a session, ordered by turn index. */
126
getTurns(sessionId: string): TurnRow[];
127
128
/** Get all files touched in a session. */
129
getFiles(sessionId: string): FileRow[];
130
131
/** Get all refs for a session. */
132
getRefs(sessionId: string): RefRow[];
133
134
/** Get the highest turn_index for a session, or -1 if none. */
135
getMaxTurnIndex(sessionId: string): number;
136
137
/** Get basic stats about the store. */
138
getStats(): { sessions: number; turns: number; checkpoints: number; files: number; refs: number };
139
140
/** Execute a raw read-only SQL query (enforced via SQLite authorizer). */
141
executeReadOnly(sql: string): Record<string, unknown>[];
142
143
/**
144
* Execute a read-only SQL query without authorizer enforcement.
145
* Used as a fallback when the authorizer API is unavailable (Node.js < 24.2).
146
* Callers MUST validate SQL safety before calling this method.
147
*/
148
executeReadOnlyFallback(sql: string): Record<string, unknown>[];
149
150
/** Run a function inside a SQLite transaction. */
151
runInTransaction(fn: () => void): void;
152
153
/** Close the database connection. */
154
close(): void;
155
}
156
157