33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import type { ModelProvider , Session , SessionManager , internal } from '@github/copilot/sdk' ;
6+ import type { internal , ModelProvider , Session , SessionManager } from '@github/copilot/sdk' ;
77import { ChatCompletionMessageParam } from 'openai/resources/chat/completions' ;
88import type { CancellationToken , ChatRequest } from 'vscode' ;
9+ import { INativeEnvService } from '../../../../platform/env/common/envService' ;
10+ import { IFileSystemService } from '../../../../platform/filesystem/common/fileSystemService' ;
11+ import { RelativePattern } from '../../../../platform/filesystem/common/fileTypes' ;
912import { ILogService } from '../../../../platform/log/common/logService' ;
1013import { createServiceIdentifier } from '../../../../util/common/services' ;
1114import { coalesce } from '../../../../util/vs/base/common/arrays' ;
1215import { raceCancellationError } from '../../../../util/vs/base/common/async' ;
1316import { Emitter , Event } from '../../../../util/vs/base/common/event' ;
1417import { Lazy } from '../../../../util/vs/base/common/lazy' ;
1518import { Disposable , DisposableMap , DisposableStore , IDisposable , toDisposable } from '../../../../util/vs/base/common/lifecycle' ;
19+ import { joinPath } from '../../../../util/vs/base/common/resources' ;
1620import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation' ;
1721import { ChatSessionStatus } from '../../../../vscodeTypes' ;
1822import { ICopilotCLISDK } from './copilotCli' ;
@@ -63,10 +67,12 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
6367 constructor (
6468 @ILogService private readonly logService : ILogService ,
6569 @ICopilotCLISDK private readonly copilotCLISDK : ICopilotCLISDK ,
66- @IInstantiationService private readonly instantiationService : IInstantiationService
70+ @IInstantiationService private readonly instantiationService : IInstantiationService ,
71+ @INativeEnvService private readonly nativeEnv : INativeEnvService ,
72+ @IFileSystemService private readonly fileSystem : IFileSystemService ,
6773 ) {
6874 super ( ) ;
69-
75+ this . monitorSessionFiles ( ) ;
7076 this . _sessionManager = new Lazy < Promise < internal . CLISessionManager > > ( async ( ) => {
7177 const { internal } = await this . copilotCLISDK . getPackage ( ) ;
7278 return new internal . CLISessionManager ( {
@@ -75,6 +81,15 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
7581 } ) ;
7682 }
7783
84+ private monitorSessionFiles ( ) {
85+ try {
86+ const sessionDir = joinPath ( this . nativeEnv . userHome , '.copilot' , 'session-state' ) ;
87+ const watcher = this . _register ( this . fileSystem . createFileSystemWatcher ( new RelativePattern ( sessionDir , '*.jsonl' ) ) ) ;
88+ this . _register ( watcher . onDidCreate ( ( ) => this . _onDidChangeSessions . fire ( ) ) ) ;
89+ } catch ( error ) {
90+ this . logService . error ( `Failed to monitor Copilot CLI session files: ${ error } ` ) ;
91+ }
92+ }
7893 async getSessionManager ( ) {
7994 return this . _sessionManager . value ;
8095 }
0 commit comments