Path: blob/main/extensions/copilot/src/extension/chatSessions/copilotcli/node/todoSqlQuery.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { join } from 'path';6import { WorkerWithRpcProxy, type RpcProxy } from '../../../../util/node/worker';7import type { TodoItem, TodoSqlWorkerApi } from './copilotCLITodoWorker';89const DATABASE_FILENAME = 'session.db';1011/**12* Queries the session SQLite database for todo items using a worker thread13* to avoid blocking the extension host with synchronous I/O.14*15* The worker is created lazily on first use and reused for subsequent queries.16* Call {@link dispose} to terminate the worker when no longer needed.17*/18export class TodoSqlQuery {19private _worker: WorkerWithRpcProxy<TodoSqlWorkerApi> | undefined;20private _proxy: RpcProxy<TodoSqlWorkerApi> | undefined;2122private ensureWorker(): RpcProxy<TodoSqlWorkerApi> {23if (!this._proxy) {24this._worker = new WorkerWithRpcProxy<TodoSqlWorkerApi>(25join(__dirname, 'copilotCLITodoWorker.js')26);27this._proxy = this._worker.proxy;28}29return this._proxy;30}3132/**33* Query todos from the session database.34* @param sessionDir - The session state directory (e.g. ~/.copilot/session-state/{session-id})35* @returns Array of todo items, or empty array if database or table doesn't exist36*/37async queryTodos(sessionDir: string): Promise<TodoItem[]> {38const dbPath = join(sessionDir, DATABASE_FILENAME);39const proxy = this.ensureWorker();40return proxy.queryTodos(dbPath);41}4243dispose(): void {44this._worker?.terminate();45this._worker = undefined;46this._proxy = undefined;47}48}4950export type { TodoItem };515253