Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

Commit e80aed0

Browse files
authored
sessionLogDir not set for new chats (#4416)
* sessionLogDir not set for new chats * fix test
1 parent 0fe5774 commit e80aed0

5 files changed

Lines changed: 28 additions & 7 deletions

File tree

src/extension/chat/vscode-node/chatDebugFileLoggerService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ export class ChatDebugFileLoggerService extends Disposable implements IChatDebug
143143
super.dispose();
144144
}
145145

146+
public get debugLogsDir(): URI | undefined {
147+
return this._getDebugLogsDir();
148+
}
149+
146150
private _getDebugLogsDir(): URI | undefined {
147151
if (this._debugLogsDirUri) {
148152
return this._debugLogsDirUri;

src/extension/prompts/node/panel/promptFile.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { PromptVariable } from '../../../prompt/common/chatVariablesCollection';
1616
import { IPromptVariablesService } from '../../../prompt/node/promptVariablesService';
1717
import { EmbeddedInsideUserMessage } from '../base/promptElement';
1818
import { Tag } from '../base/tag';
19+
import { joinPath } from '../../../../util/vs/base/common/resources';
1920

2021
export interface PromptFileProps extends BasePromptElementProps, EmbeddedInsideUserMessage {
2122
readonly variable: PromptVariable;
@@ -81,9 +82,10 @@ export class PromptFile extends PromptElement<PromptFileProps, void> {
8182
if (fileUri.scheme === 'copilot-skill' && fileUri.path.includes('/troubleshoot/') && bodyContent.includes('{{CURRENT_SESSION_LOG}}')) {
8283
const chatSessionId = getCurrentCapturingToken()?.chatSessionId;
8384
if (chatSessionId) {
84-
const logDir = this.chatDebugFileLoggerService.getSessionDir(chatSessionId);
85+
const logDir = this.chatDebugFileLoggerService.debugLogsDir;
8586
if (logDir) {
86-
bodyContent = bodyContent.replaceAll('{{CURRENT_SESSION_LOG}}', logDir.toString());
87+
const sessionLogDir = joinPath(logDir, chatSessionId);
88+
bodyContent = bodyContent.replaceAll('{{CURRENT_SESSION_LOG}}', () => this.promptPathRepresentationService.getFilePath(sessionLogDir));
8789
}
8890
}
8991
}

src/extension/tools/node/readFileTool.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as l10n from '@vscode/l10n';
66
import { BasePromptElementProps, PromptElement, PromptElementProps, PromptReference } from '@vscode/prompt-tsx';
77
import type * as vscode from 'vscode';
8-
import { IChatDebugFileLoggerService } from '../../../platform/chat/common/chatDebugFileLoggerService';
8+
import { IChatDebugFileLoggerService, sessionResourceToId } from '../../../platform/chat/common/chatDebugFileLoggerService';
99
import { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService';
1010
import { ObjectJsonSchema } from '../../../platform/configuration/common/jsonSchema';
1111
import { ICustomInstructionsService } from '../../../platform/customInstructions/common/customInstructionsService';
@@ -21,7 +21,7 @@ import { ITelemetryService } from '../../../platform/telemetry/common/telemetry'
2121
import { IWorkspaceService } from '../../../platform/workspace/common/workspaceService';
2222
import { getCachedSha256Hash } from '../../../util/common/crypto';
2323
import { clamp } from '../../../util/vs/base/common/numbers';
24-
import { dirname, extUriBiasedIgnorePathCase } from '../../../util/vs/base/common/resources';
24+
import { dirname, extUriBiasedIgnorePathCase, joinPath } from '../../../util/vs/base/common/resources';
2525
import { URI } from '../../../util/vs/base/common/uri';
2626
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
2727
import { LanguageModelPromptTsxPart, LanguageModelToolResult, Location, MarkdownString, Range } from '../../../vscodeTypes';
@@ -333,9 +333,11 @@ export class ReadFileTool implements ICopilotTool<ReadFileParams> {
333333
if (uri.scheme === 'copilot-skill' && uri.path.includes('/troubleshoot/')) {
334334
const sessionResource = this._promptContext?.request?.sessionResource;
335335
if (sessionResource) {
336-
const logDir = this.chatDebugFileLoggerService.getSessionDirForResource(URI.from(sessionResource));
336+
const chatSessionId = sessionResourceToId(sessionResource);
337+
const logDir = this.chatDebugFileLoggerService.debugLogsDir;
337338
if (logDir) {
338-
const replaced = snapshot.getText().replaceAll('{{CURRENT_SESSION_LOG}}', logDir.toString());
339+
const sessionLogDir = joinPath(logDir, chatSessionId);
340+
const replaced = snapshot.getText().replaceAll('{{CURRENT_SESSION_LOG}}', () => this.promptPathRepresentationService.getFilePath(sessionLogDir));
339341
return TextDocumentSnapshot.fromNewText(replaced, snapshot);
340342
}
341343
}

src/extension/tools/node/test/readFile.spec.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import { IChatDebugFileLoggerService } from '../../../../platform/chat/common/ch
88
import { ICustomInstructionsService } from '../../../../platform/customInstructions/common/customInstructionsService';
99
import { IFileSystemService } from '../../../../platform/filesystem/common/fileSystemService';
1010
import { MockFileSystemService } from '../../../../platform/filesystem/node/test/mockFileSystemService';
11+
import { IPromptPathRepresentationService } from '../../../../platform/prompts/common/promptPathRepresentationService';
1112
import { MockCustomInstructionsService } from '../../../../platform/test/common/testCustomInstructionsService';
1213
import { ITestingServicesAccessor } from '../../../../platform/test/node/services';
1314
import { TestWorkspaceService } from '../../../../platform/test/node/testWorkspaceService';
1415
import { IWorkspaceService } from '../../../../platform/workspace/common/workspaceService';
1516
import { createTextDocumentData } from '../../../../util/common/test/shims/textDocument';
1617
import { CancellationToken } from '../../../../util/vs/base/common/cancellation';
18+
import { dirname } from '../../../../util/vs/base/common/resources';
1719
import { URI } from '../../../../util/vs/base/common/uri';
1820
import { SyncDescriptor } from '../../../../util/vs/platform/instantiation/common/descriptors';
1921
import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';
@@ -734,10 +736,12 @@ suite('ReadFile', () => {
734736
getActiveSessionIds: () => [],
735737
isDebugLogUri: () => false,
736738
getSessionDirForResource: () => expectedLogDir,
739+
debugLogsDir: dirname(expectedLogDir),
737740
} satisfies IChatDebugFileLoggerService);
738741

739742
const testAccessor = services.createTestingAccessor();
740743
const readFileTool = testAccessor.get(IInstantiationService).createInstance(ReadFileTool);
744+
const promptPathRepresentationService = testAccessor.get(IPromptPathRepresentationService);
741745

742746
// Set up prompt context with a sessionResource
743747
await readFileTool.resolveInput(
@@ -752,7 +756,7 @@ suite('ReadFile', () => {
752756
);
753757

754758
const text = await toolResultToString(testAccessor, result);
755-
expect(text).toContain(expectedLogDir.toString());
759+
expect(text).toContain(promptPathRepresentationService.getFilePath(expectedLogDir));
756760
expect(text).not.toContain('{{CURRENT_SESSION_LOG}}');
757761

758762
testAccessor.dispose();
@@ -804,6 +808,7 @@ suite('ReadFile', () => {
804808
getActiveSessionIds: () => [],
805809
isDebugLogUri: () => false,
806810
getSessionDirForResource: () => URI.file('/should/not/appear'),
811+
debugLogsDir: URI.file('/should/not/appear'),
807812
} satisfies IChatDebugFileLoggerService);
808813

809814
const testAccessor = services.createTestingAccessor();

src/platform/chat/common/chatDebugFileLoggerService.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export interface IChatDebugFileLoggerService {
5454
*/
5555
flush(sessionId: string): Promise<void>;
5656

57+
/**
58+
* Get the URI of the debug logs directory, or undefined if it cannot be
59+
* determined (e.g. no workspace, or an error occurs). The directory may
60+
* not actually exist on disk yet if no sessions have been started.
61+
*/
62+
readonly debugLogsDir: URI | undefined;
63+
5764
/**
5865
* Get the URI of the debug log file for a session, or undefined if the
5966
* session has not been started.
@@ -99,4 +106,5 @@ export class NullChatDebugFileLoggerService implements IChatDebugFileLoggerServi
99106
getActiveSessionIds(): string[] { return []; }
100107
isDebugLogUri(): boolean { return false; }
101108
getSessionDirForResource(): URI | undefined { return undefined; }
109+
readonly debugLogsDir: URI | undefined = undefined;
102110
}

0 commit comments

Comments
 (0)