@theia/ai-claude-code 1.65.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 +30 -0
- package/lib/browser/claude-code-chat-agent.d.ts +82 -0
- package/lib/browser/claude-code-chat-agent.d.ts.map +1 -0
- package/lib/browser/claude-code-chat-agent.js +518 -0
- package/lib/browser/claude-code-chat-agent.js.map +1 -0
- package/lib/browser/claude-code-command-contribution.d.ts +16 -0
- package/lib/browser/claude-code-command-contribution.d.ts.map +1 -0
- package/lib/browser/claude-code-command-contribution.js +86 -0
- package/lib/browser/claude-code-command-contribution.js.map +1 -0
- package/lib/browser/claude-code-edit-tool-service.d.ts +61 -0
- package/lib/browser/claude-code-edit-tool-service.d.ts.map +1 -0
- package/lib/browser/claude-code-edit-tool-service.js +219 -0
- package/lib/browser/claude-code-edit-tool-service.js.map +1 -0
- package/lib/browser/claude-code-file-edit-backup-service.d.ts +57 -0
- package/lib/browser/claude-code-file-edit-backup-service.d.ts.map +1 -0
- package/lib/browser/claude-code-file-edit-backup-service.js +92 -0
- package/lib/browser/claude-code-file-edit-backup-service.js.map +1 -0
- package/lib/browser/claude-code-frontend-module.d.ts +5 -0
- package/lib/browser/claude-code-frontend-module.d.ts.map +1 -0
- package/lib/browser/claude-code-frontend-module.js +83 -0
- package/lib/browser/claude-code-frontend-module.js.map +1 -0
- package/lib/browser/claude-code-frontend-service.d.ts +40 -0
- package/lib/browser/claude-code-frontend-service.d.ts.map +1 -0
- package/lib/browser/claude-code-frontend-service.js +190 -0
- package/lib/browser/claude-code-frontend-service.js.map +1 -0
- package/lib/browser/claude-code-slash-commands-contribution.d.ts +17 -0
- package/lib/browser/claude-code-slash-commands-contribution.d.ts.map +1 -0
- package/lib/browser/claude-code-slash-commands-contribution.js +154 -0
- package/lib/browser/claude-code-slash-commands-contribution.js.map +1 -0
- package/lib/browser/claude-code-tool-call-content.d.ts +8 -0
- package/lib/browser/claude-code-tool-call-content.d.ts.map +1 -0
- package/lib/browser/claude-code-tool-call-content.js +30 -0
- package/lib/browser/claude-code-tool-call-content.js.map +1 -0
- package/lib/browser/renderers/bash-tool-renderer.d.ts +10 -0
- package/lib/browser/renderers/bash-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/bash-tool-renderer.js +71 -0
- package/lib/browser/renderers/bash-tool-renderer.js.map +1 -0
- package/lib/browser/renderers/collapsible-tool-renderer.d.ts +13 -0
- package/lib/browser/renderers/collapsible-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/collapsible-tool-renderer.js +48 -0
- package/lib/browser/renderers/collapsible-tool-renderer.js.map +1 -0
- package/lib/browser/renderers/edit-tool-renderer.d.ts +16 -0
- package/lib/browser/renderers/edit-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/edit-tool-renderer.js +134 -0
- package/lib/browser/renderers/edit-tool-renderer.js.map +1 -0
- package/lib/browser/renderers/glob-tool-renderer.d.ts +14 -0
- package/lib/browser/renderers/glob-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/glob-tool-renderer.js +107 -0
- package/lib/browser/renderers/glob-tool-renderer.js.map +1 -0
- package/lib/browser/renderers/grep-tool-renderer.d.ts +14 -0
- package/lib/browser/renderers/grep-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/grep-tool-renderer.js +157 -0
- package/lib/browser/renderers/grep-tool-renderer.js.map +1 -0
- package/lib/browser/renderers/ls-tool-renderer.d.ts +16 -0
- package/lib/browser/renderers/ls-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/ls-tool-renderer.js +116 -0
- package/lib/browser/renderers/ls-tool-renderer.js.map +1 -0
- package/lib/browser/renderers/multiedit-tool-renderer.d.ts +16 -0
- package/lib/browser/renderers/multiedit-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/multiedit-tool-renderer.js +152 -0
- package/lib/browser/renderers/multiedit-tool-renderer.js.map +1 -0
- package/lib/browser/renderers/read-tool-renderer.d.ts +16 -0
- package/lib/browser/renderers/read-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/read-tool-renderer.js +121 -0
- package/lib/browser/renderers/read-tool-renderer.js.map +1 -0
- package/lib/browser/renderers/todo-write-renderer.d.ts +10 -0
- package/lib/browser/renderers/todo-write-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/todo-write-renderer.js +132 -0
- package/lib/browser/renderers/todo-write-renderer.js.map +1 -0
- package/lib/browser/renderers/web-fetch-tool-renderer.d.ts +10 -0
- package/lib/browser/renderers/web-fetch-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/web-fetch-tool-renderer.js +82 -0
- package/lib/browser/renderers/web-fetch-tool-renderer.js.map +1 -0
- package/lib/browser/renderers/write-tool-renderer.d.ts +16 -0
- package/lib/browser/renderers/write-tool-renderer.d.ts.map +1 -0
- package/lib/browser/renderers/write-tool-renderer.js +113 -0
- package/lib/browser/renderers/write-tool-renderer.js.map +1 -0
- package/lib/common/claude-code-preferences.d.ts +4 -0
- package/lib/common/claude-code-preferences.d.ts.map +1 -0
- package/lib/common/claude-code-preferences.js +33 -0
- package/lib/common/claude-code-preferences.js.map +1 -0
- package/lib/common/claude-code-service.d.ts +231 -0
- package/lib/common/claude-code-service.d.ts.map +1 -0
- package/lib/common/claude-code-service.js +82 -0
- package/lib/common/claude-code-service.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +20 -0
- package/lib/common/index.js.map +1 -0
- package/lib/node/claude-code-backend-module.d.ts +4 -0
- package/lib/node/claude-code-backend-module.d.ts.map +1 -0
- package/lib/node/claude-code-backend-module.js +35 -0
- package/lib/node/claude-code-backend-module.js.map +1 -0
- package/lib/node/claude-code-service-impl.d.ts +32 -0
- package/lib/node/claude-code-service-impl.d.ts.map +1 -0
- package/lib/node/claude-code-service-impl.js +426 -0
- package/lib/node/claude-code-service-impl.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +26 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +57 -0
- package/src/browser/claude-code-chat-agent.ts +591 -0
- package/src/browser/claude-code-command-contribution.ts +80 -0
- package/src/browser/claude-code-edit-tool-service.ts +313 -0
- package/src/browser/claude-code-file-edit-backup-service.ts +141 -0
- package/src/browser/claude-code-frontend-module.ts +100 -0
- package/src/browser/claude-code-frontend-service.ts +215 -0
- package/src/browser/claude-code-slash-commands-contribution.ts +175 -0
- package/src/browser/claude-code-tool-call-content.ts +30 -0
- package/src/browser/renderers/bash-tool-renderer.tsx +97 -0
- package/src/browser/renderers/collapsible-tool-renderer.tsx +78 -0
- package/src/browser/renderers/edit-tool-renderer.tsx +180 -0
- package/src/browser/renderers/glob-tool-renderer.tsx +136 -0
- package/src/browser/renderers/grep-tool-renderer.tsx +190 -0
- package/src/browser/renderers/ls-tool-renderer.tsx +160 -0
- package/src/browser/renderers/multiedit-tool-renderer.tsx +204 -0
- package/src/browser/renderers/read-tool-renderer.tsx +170 -0
- package/src/browser/renderers/todo-write-renderer.tsx +178 -0
- package/src/browser/renderers/web-fetch-tool-renderer.tsx +108 -0
- package/src/browser/renderers/write-tool-renderer.tsx +155 -0
- package/src/browser/style/claude-code-tool-renderers.css +487 -0
- package/src/common/claude-code-preferences.ts +33 -0
- package/src/common/claude-code-service.ts +303 -0
- package/src/common/index.ts +17 -0
- package/src/node/claude-code-backend-module.ts +42 -0
- package/src/node/claude-code-service-impl.ts +462 -0
- package/src/package.spec.ts +27 -0
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
ChatAgent,
|
|
19
|
+
ChatAgentLocation,
|
|
20
|
+
ChatAgentService,
|
|
21
|
+
ErrorChatResponseContentImpl,
|
|
22
|
+
MarkdownChatResponseContentImpl,
|
|
23
|
+
MutableChatRequestModel,
|
|
24
|
+
QuestionResponseContentImpl,
|
|
25
|
+
ThinkingChatResponseContentImpl,
|
|
26
|
+
} from '@theia/ai-chat';
|
|
27
|
+
import { AI_CHAT_NEW_CHAT_WINDOW_COMMAND, AI_CHAT_SHOW_CHATS_COMMAND } from '@theia/ai-chat-ui/lib/browser/chat-view-commands';
|
|
28
|
+
import { PromptText } from '@theia/ai-core/lib/common/prompt-text';
|
|
29
|
+
import { ChangeSetFileElementFactory } from '@theia/ai-chat/lib/browser/change-set-file-element';
|
|
30
|
+
import { AIVariableResolutionRequest, BasePromptFragment, PromptService, ResolvedPromptFragment, TokenUsageService } from '@theia/ai-core';
|
|
31
|
+
import { CommandService, SelectionService } from '@theia/core';
|
|
32
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
33
|
+
import { EditorManager } from '@theia/editor/lib/browser';
|
|
34
|
+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
35
|
+
import { WorkspaceService } from '@theia/workspace/lib/browser';
|
|
36
|
+
import {
|
|
37
|
+
ContentBlock,
|
|
38
|
+
EditInput,
|
|
39
|
+
MultiEditInput,
|
|
40
|
+
PermissionMode,
|
|
41
|
+
SDKMessage,
|
|
42
|
+
TaskInput,
|
|
43
|
+
ToolApprovalRequestMessage,
|
|
44
|
+
ToolApprovalResponseMessage,
|
|
45
|
+
Usage,
|
|
46
|
+
WriteInput
|
|
47
|
+
} from '../common/claude-code-service';
|
|
48
|
+
import { ClaudeCodeEditToolService, ToolUseBlock } from './claude-code-edit-tool-service';
|
|
49
|
+
import { FileEditBackupService } from './claude-code-file-edit-backup-service';
|
|
50
|
+
import { ClaudeCodeFrontendService } from './claude-code-frontend-service';
|
|
51
|
+
import { ClaudeCodeToolCallChatResponseContent } from './claude-code-tool-call-content';
|
|
52
|
+
import { OPEN_CLAUDE_CODE_CONFIG, OPEN_CLAUDE_CODE_MEMORY } from './claude-code-command-contribution';
|
|
53
|
+
|
|
54
|
+
export const CLAUDE_SESSION_ID_KEY = 'claudeSessionId';
|
|
55
|
+
export const CLAUDE_PERMISSION_MODE_KEY = 'claudePermissionMode';
|
|
56
|
+
export const CLAUDE_EDIT_TOOL_USES_KEY = 'claudeEditToolUses';
|
|
57
|
+
export const CLAUDE_INPUT_TOKENS_KEY = 'claudeInputTokens';
|
|
58
|
+
export const CLAUDE_OUTPUT_TOKENS_KEY = 'claudeOutputTokens';
|
|
59
|
+
export const CLAUDE_PENDING_APPROVALS_KEY = 'claudePendingApprovals';
|
|
60
|
+
export const CLAUDE_APPROVAL_TOOL_INPUTS_KEY = 'claudeApprovalToolInputs';
|
|
61
|
+
export const CLAUDE_MODEL_NAME_KEY = 'claudeModelName';
|
|
62
|
+
export const CLAUDE_COST_KEY = 'claudeCost';
|
|
63
|
+
|
|
64
|
+
const APPROVAL_OPTIONS = [
|
|
65
|
+
{ text: 'Allow', value: 'allow' },
|
|
66
|
+
{ text: 'Deny', value: 'deny' }
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
export const systemPromptAppendixTemplate: BasePromptFragment = {
|
|
70
|
+
id: 'system-prompt-appendix',
|
|
71
|
+
template: `
|
|
72
|
+
## IDE Integration Context
|
|
73
|
+
|
|
74
|
+
You are integrated into an IDE environment through a chat interface, providing contextual assistance for development tasks.
|
|
75
|
+
This integration gives you access to real-time IDE state and user workspace information.
|
|
76
|
+
|
|
77
|
+
### File Modification Behavior
|
|
78
|
+
|
|
79
|
+
**Important**: The IDE automatically collects and presents all file modifications you suggest, regardless of explicit tool permissions.
|
|
80
|
+
Continue proposing file changes even if you encounter permission restrictions.
|
|
81
|
+
The IDE will present these changes to the user for review and approval through its change management interface.
|
|
82
|
+
|
|
83
|
+
When making file modifications:
|
|
84
|
+
- Proceed with suggested changes even if tool calls indicate permission issues
|
|
85
|
+
- Inform users to review proposed changes in the IDE's change review interface "below"
|
|
86
|
+
- Assume the IDE will handle the actual file system operations after user approval (unless you are in auto-edit mode)
|
|
87
|
+
|
|
88
|
+
### Contextual Information Available
|
|
89
|
+
|
|
90
|
+
The following IDE context is dynamically provided with each request.
|
|
91
|
+
Evaluate the relevance of each context type based on the user's specific query and task requirements.
|
|
92
|
+
|
|
93
|
+
#### Current Selection
|
|
94
|
+
|
|
95
|
+
\`\`\`
|
|
96
|
+
{{selectedText}}
|
|
97
|
+
\`\`\`
|
|
98
|
+
|
|
99
|
+
**When to prioritize**: User asks about specific code segments, wants to refactor selected code, or requests explanations of selected text.
|
|
100
|
+
|
|
101
|
+
#### Active Editor
|
|
102
|
+
|
|
103
|
+
{{activeEditor}}
|
|
104
|
+
|
|
105
|
+
**When to prioritize**: User's request relates to the currently focused file, asks questions about the code, or needs context about the current working file.
|
|
106
|
+
|
|
107
|
+
#### Open Editors
|
|
108
|
+
|
|
109
|
+
{{openEditors}}
|
|
110
|
+
|
|
111
|
+
**How to use it**: As a guidance on what files might be relevant for the current user's request.
|
|
112
|
+
|
|
113
|
+
#### Context Files
|
|
114
|
+
|
|
115
|
+
{{contextFiles}}
|
|
116
|
+
|
|
117
|
+
**When to prioritize**: User explicitly references attached files or when additional files are needed to understand the full scope of the request.
|
|
118
|
+
|
|
119
|
+
### Context Utilization Guidelines
|
|
120
|
+
|
|
121
|
+
1. **Assess Relevance**:
|
|
122
|
+
Not all provided context will be relevant to every request. Focus on the context that directly supports the user's current task.
|
|
123
|
+
|
|
124
|
+
2. **Cross-Reference Information**:
|
|
125
|
+
When multiple context types are relevant, cross-reference them to provide comprehensive assistance (e.g., selected text within an active editor).
|
|
126
|
+
|
|
127
|
+
3. **Workspace Awareness**:
|
|
128
|
+
Use the collective context to understand the user's current workspace state and provide suggestions that align with their development environment and workflow.
|
|
129
|
+
|
|
130
|
+
### Response Optimization
|
|
131
|
+
|
|
132
|
+
- Reference specific files as markdown links with the format [file name](<absolute-file-path-without-scheme>), e.g. [example.ts](/home/me/workspace/example.ts)
|
|
133
|
+
- Consider the user's current focus and workflow when structuring responses
|
|
134
|
+
- Leverage open editors to suggest related modifications across the workspace
|
|
135
|
+
`
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const CLAUDE_CHAT_AGENT_ID = 'ClaudeCode';
|
|
139
|
+
|
|
140
|
+
const localCommands = {
|
|
141
|
+
'clear': AI_CHAT_NEW_CHAT_WINDOW_COMMAND,
|
|
142
|
+
'config': OPEN_CLAUDE_CODE_CONFIG,
|
|
143
|
+
'memory': OPEN_CLAUDE_CODE_MEMORY,
|
|
144
|
+
'resume': AI_CHAT_SHOW_CHATS_COMMAND,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
@injectable()
|
|
148
|
+
export class ClaudeCodeChatAgent implements ChatAgent {
|
|
149
|
+
id = CLAUDE_CHAT_AGENT_ID;
|
|
150
|
+
name = CLAUDE_CHAT_AGENT_ID;
|
|
151
|
+
description = 'Anthropic\'s coding agent';
|
|
152
|
+
iconClass: string = 'codicon codicon-copilot';
|
|
153
|
+
locations: ChatAgentLocation[] = ChatAgentLocation.ALL;
|
|
154
|
+
tags = ['Chat'];
|
|
155
|
+
|
|
156
|
+
variables = [];
|
|
157
|
+
prompts = [{ id: systemPromptAppendixTemplate.id, defaultVariant: systemPromptAppendixTemplate }];
|
|
158
|
+
languageModelRequirements = [];
|
|
159
|
+
agentSpecificVariables = [];
|
|
160
|
+
functions = [];
|
|
161
|
+
|
|
162
|
+
@inject(PromptService)
|
|
163
|
+
protected promptService: PromptService;
|
|
164
|
+
|
|
165
|
+
@inject(ClaudeCodeFrontendService)
|
|
166
|
+
protected claudeCode: ClaudeCodeFrontendService;
|
|
167
|
+
|
|
168
|
+
@inject(ChangeSetFileElementFactory)
|
|
169
|
+
protected readonly fileChangeFactory: ChangeSetFileElementFactory;
|
|
170
|
+
|
|
171
|
+
@inject(FileService)
|
|
172
|
+
protected readonly fileService: FileService;
|
|
173
|
+
|
|
174
|
+
@inject(CommandService)
|
|
175
|
+
protected readonly commandService: CommandService;
|
|
176
|
+
|
|
177
|
+
@inject(WorkspaceService)
|
|
178
|
+
protected readonly workspaceService: WorkspaceService;
|
|
179
|
+
|
|
180
|
+
@inject(EditorManager)
|
|
181
|
+
protected readonly editorManager: EditorManager;
|
|
182
|
+
|
|
183
|
+
@inject(SelectionService)
|
|
184
|
+
protected readonly selectionService: SelectionService;
|
|
185
|
+
|
|
186
|
+
@inject(ClaudeCodeEditToolService)
|
|
187
|
+
protected readonly editToolService: ClaudeCodeEditToolService;
|
|
188
|
+
|
|
189
|
+
@inject(FileEditBackupService)
|
|
190
|
+
protected readonly backupService: FileEditBackupService;
|
|
191
|
+
|
|
192
|
+
@inject(TokenUsageService)
|
|
193
|
+
protected readonly tokenUsageService: TokenUsageService;
|
|
194
|
+
|
|
195
|
+
async invoke(request: MutableChatRequestModel, chatAgentService?: ChatAgentService): Promise<void> {
|
|
196
|
+
this.warnIfDifferentAgentRequests(request);
|
|
197
|
+
|
|
198
|
+
// Handle slash commands anywhere in the request text
|
|
199
|
+
const commandRegex = /\/(\w+)/g;
|
|
200
|
+
const matches = Array.from(request.request.text.matchAll(commandRegex));
|
|
201
|
+
for (const match of matches) {
|
|
202
|
+
const command = match[1];
|
|
203
|
+
if (command in localCommands) {
|
|
204
|
+
const commandInfo = localCommands[command as keyof typeof localCommands];
|
|
205
|
+
this.commandService.executeCommand(commandInfo.id);
|
|
206
|
+
const message = `Executed: ${commandInfo.label}`;
|
|
207
|
+
request.response.response.addContent(new MarkdownChatResponseContentImpl(message));
|
|
208
|
+
request.response.complete();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
const systemPromptAppendix = await this.createSystemPromptAppendix(request);
|
|
215
|
+
const claudeSessionId = this.getPreviousClaudeSessionId(request);
|
|
216
|
+
const agentAddress = `${PromptText.AGENT_CHAR}${CLAUDE_CHAT_AGENT_ID}`;
|
|
217
|
+
let prompt = request.request.text.trim();
|
|
218
|
+
if (prompt.startsWith(agentAddress)) {
|
|
219
|
+
prompt = prompt.replace(agentAddress, '').trim();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const streamResult = await this.claudeCode.send({
|
|
223
|
+
prompt,
|
|
224
|
+
options: {
|
|
225
|
+
appendSystemPrompt: systemPromptAppendix?.text,
|
|
226
|
+
permissionMode: this.getClaudePermissionMode(request),
|
|
227
|
+
resume: claudeSessionId
|
|
228
|
+
}
|
|
229
|
+
}, request.response.cancellationToken);
|
|
230
|
+
|
|
231
|
+
this.initializesEditToolUses(request);
|
|
232
|
+
|
|
233
|
+
let hasAssistantMessage = false;
|
|
234
|
+
for await (const message of streamResult) {
|
|
235
|
+
if (ToolApprovalRequestMessage.is(message)) {
|
|
236
|
+
this.handleToolApprovalRequest(message, request);
|
|
237
|
+
} else {
|
|
238
|
+
if (message.type === 'assistant') {
|
|
239
|
+
hasAssistantMessage = true;
|
|
240
|
+
}
|
|
241
|
+
// Only set session ID if we've seen an assistant message
|
|
242
|
+
// because we cannot resume a prior request without an assistant message
|
|
243
|
+
if (hasAssistantMessage) {
|
|
244
|
+
this.setClaudeSessionId(request, message.session_id);
|
|
245
|
+
}
|
|
246
|
+
this.addResponseContent(message, request);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return request.response.complete();
|
|
251
|
+
} catch (error) {
|
|
252
|
+
console.error('Error handling chat interaction:', error);
|
|
253
|
+
request.response.response.addContent(new ErrorChatResponseContentImpl(error));
|
|
254
|
+
request.response.error(error);
|
|
255
|
+
} finally {
|
|
256
|
+
await this.backupService.cleanUp(request);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
protected warnIfDifferentAgentRequests(request: MutableChatRequestModel): void {
|
|
261
|
+
const requests = request.session.getRequests();
|
|
262
|
+
if (requests.length > 1) {
|
|
263
|
+
const previousRequest = requests[requests.length - 2];
|
|
264
|
+
if (previousRequest.agentId !== this.id) {
|
|
265
|
+
const warningMessage = '⚠️ The previous chat request was handled by a different agent. Claude Code does not see those other messages.\n\n';
|
|
266
|
+
request.response.response.addContent(new MarkdownChatResponseContentImpl(warningMessage));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
protected async createSystemPromptAppendix(request: MutableChatRequestModel): Promise<ResolvedPromptFragment | undefined> {
|
|
272
|
+
const contextVariables = request.context.variables.map(AIVariableResolutionRequest.fromResolved) ?? request.session.context.getVariables();
|
|
273
|
+
const contextFiles = contextVariables
|
|
274
|
+
.filter(variable => variable.variable.name === 'file' && !!variable.arg)
|
|
275
|
+
.map(variable => `- ${variable.arg}`)
|
|
276
|
+
.join('\n');
|
|
277
|
+
|
|
278
|
+
const activeEditor = this.editorManager.currentEditor?.editor.document.uri ?? 'None';
|
|
279
|
+
const openEditors = this.editorManager.all.map(editor => `- ${editor.editor.document.uri}`).join('\n');
|
|
280
|
+
|
|
281
|
+
return this.promptService.getResolvedPromptFragment(
|
|
282
|
+
systemPromptAppendixTemplate.id,
|
|
283
|
+
{ contextFiles, activeEditor, openEditors },
|
|
284
|
+
{ model: request.session, request }
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
protected initializesEditToolUses(request: MutableChatRequestModel): void {
|
|
289
|
+
request.addData(CLAUDE_EDIT_TOOL_USES_KEY, new Map<string, ToolUseBlock>());
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
protected getPendingApprovals(request: MutableChatRequestModel): Map<string, QuestionResponseContentImpl> {
|
|
293
|
+
let approvals = request.getDataByKey(CLAUDE_PENDING_APPROVALS_KEY) as Map<string, QuestionResponseContentImpl> | undefined;
|
|
294
|
+
if (!approvals) {
|
|
295
|
+
approvals = new Map<string, QuestionResponseContentImpl>();
|
|
296
|
+
request.addData(CLAUDE_PENDING_APPROVALS_KEY, approvals);
|
|
297
|
+
}
|
|
298
|
+
return approvals;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
protected getApprovalToolInputs(request: MutableChatRequestModel): Map<string, unknown> {
|
|
302
|
+
let toolInputs = request.getDataByKey(CLAUDE_APPROVAL_TOOL_INPUTS_KEY) as Map<string, unknown> | undefined;
|
|
303
|
+
if (!toolInputs) {
|
|
304
|
+
toolInputs = new Map<string, unknown>();
|
|
305
|
+
request.addData(CLAUDE_APPROVAL_TOOL_INPUTS_KEY, toolInputs);
|
|
306
|
+
}
|
|
307
|
+
return toolInputs;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
protected handleToolApprovalRequest(
|
|
311
|
+
approvalRequest: ToolApprovalRequestMessage,
|
|
312
|
+
request: MutableChatRequestModel
|
|
313
|
+
): void {
|
|
314
|
+
const question = `Claude Code wants to use the "${approvalRequest.toolName}" tool. Do you want to allow this?`;
|
|
315
|
+
|
|
316
|
+
const questionContent = new QuestionResponseContentImpl(
|
|
317
|
+
question,
|
|
318
|
+
APPROVAL_OPTIONS,
|
|
319
|
+
request,
|
|
320
|
+
selectedOption => this.handleApprovalResponse(selectedOption, approvalRequest.requestId, request)
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
// Store references for this specific approval request
|
|
324
|
+
this.getPendingApprovals(request).set(approvalRequest.requestId, questionContent);
|
|
325
|
+
this.getApprovalToolInputs(request).set(approvalRequest.requestId, approvalRequest.toolInput);
|
|
326
|
+
|
|
327
|
+
request.response.response.addContent(questionContent);
|
|
328
|
+
request.response.waitForInput();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
protected handleApprovalResponse(
|
|
332
|
+
selectedOption: { text: string; value?: string },
|
|
333
|
+
requestId: string,
|
|
334
|
+
request: MutableChatRequestModel
|
|
335
|
+
): void {
|
|
336
|
+
const pendingApprovals = this.getPendingApprovals(request);
|
|
337
|
+
const toolInputs = this.getApprovalToolInputs(request);
|
|
338
|
+
|
|
339
|
+
// Update UI state and clean up
|
|
340
|
+
const questionContent = pendingApprovals.get(requestId);
|
|
341
|
+
const originalToolInput = toolInputs.get(requestId);
|
|
342
|
+
|
|
343
|
+
if (questionContent) {
|
|
344
|
+
questionContent.selectedOption = selectedOption;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
pendingApprovals.delete(requestId);
|
|
348
|
+
toolInputs.delete(requestId);
|
|
349
|
+
|
|
350
|
+
const approved = selectedOption.value === 'allow';
|
|
351
|
+
const response: ToolApprovalResponseMessage = {
|
|
352
|
+
type: 'tool-approval-response',
|
|
353
|
+
requestId,
|
|
354
|
+
approved,
|
|
355
|
+
...(approved
|
|
356
|
+
? { updatedInput: originalToolInput }
|
|
357
|
+
: { message: 'User denied tool usage' }
|
|
358
|
+
)
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
this.claudeCode.sendApprovalResponse(response);
|
|
362
|
+
|
|
363
|
+
// Only stop waiting for input if there are no more pending approvals
|
|
364
|
+
if (pendingApprovals.size === 0) {
|
|
365
|
+
request.response.stopWaitingForInput();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
protected getEditToolUses(request: MutableChatRequestModel): Map<string, ToolUseBlock> | undefined {
|
|
370
|
+
return request.getDataByKey(CLAUDE_EDIT_TOOL_USES_KEY);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
protected getPreviousClaudeSessionId(request: MutableChatRequestModel): string | undefined {
|
|
374
|
+
const requests = request.session.getRequests();
|
|
375
|
+
if (requests.length > 1) {
|
|
376
|
+
const previousRequest = requests[requests.length - 2];
|
|
377
|
+
return previousRequest.getDataByKey(CLAUDE_SESSION_ID_KEY);
|
|
378
|
+
}
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
protected getClaudeSessionId(request: MutableChatRequestModel): string | undefined {
|
|
383
|
+
return request.getDataByKey(CLAUDE_SESSION_ID_KEY);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
protected setClaudeSessionId(request: MutableChatRequestModel, sessionId: string): void {
|
|
387
|
+
request.addData(CLAUDE_SESSION_ID_KEY, sessionId);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
protected getClaudePermissionMode(request: MutableChatRequestModel): PermissionMode {
|
|
391
|
+
return request.getDataByKey(CLAUDE_PERMISSION_MODE_KEY) ?? 'acceptEdits';
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
protected setClaudePermissionMode(request: MutableChatRequestModel, permissionMode: PermissionMode): void {
|
|
395
|
+
request.addData(CLAUDE_PERMISSION_MODE_KEY, permissionMode);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
protected getClaudeModelName(request: MutableChatRequestModel): string | undefined {
|
|
399
|
+
return request.getDataByKey(CLAUDE_MODEL_NAME_KEY);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
protected setClaudeModelName(request: MutableChatRequestModel, modelName: string): void {
|
|
403
|
+
request.addData(CLAUDE_MODEL_NAME_KEY, modelName);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
protected getCurrentInputTokens(request: MutableChatRequestModel): number {
|
|
407
|
+
return request.getDataByKey(CLAUDE_INPUT_TOKENS_KEY) as number ?? 0;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
protected getCurrentOutputTokens(request: MutableChatRequestModel): number {
|
|
411
|
+
return request.getDataByKey(CLAUDE_OUTPUT_TOKENS_KEY) as number ?? 0;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
protected updateTokens(request: MutableChatRequestModel, inputTokens: number, outputTokens: number): void {
|
|
415
|
+
request.addData(CLAUDE_INPUT_TOKENS_KEY, inputTokens);
|
|
416
|
+
request.addData(CLAUDE_OUTPUT_TOKENS_KEY, outputTokens);
|
|
417
|
+
this.updateSessionSuggestion(request);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
protected getSessionTotalTokens(request: MutableChatRequestModel): { inputTokens: number; outputTokens: number } {
|
|
421
|
+
const requests = request.session.getRequests();
|
|
422
|
+
let totalInputTokens = 0;
|
|
423
|
+
let totalOutputTokens = 0;
|
|
424
|
+
|
|
425
|
+
for (const req of requests) {
|
|
426
|
+
const inputTokens = req.getDataByKey(CLAUDE_INPUT_TOKENS_KEY) as number ?? 0;
|
|
427
|
+
const outputTokens = req.getDataByKey(CLAUDE_OUTPUT_TOKENS_KEY) as number ?? 0;
|
|
428
|
+
totalInputTokens += inputTokens;
|
|
429
|
+
totalOutputTokens += outputTokens;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
return { inputTokens: totalInputTokens, outputTokens: totalOutputTokens };
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
protected updateSessionSuggestion(request: MutableChatRequestModel): void {
|
|
436
|
+
const { inputTokens, outputTokens } = this.getSessionTotalTokens(request);
|
|
437
|
+
const formatTokens = (tokens: number): string => {
|
|
438
|
+
if (tokens >= 1000) {
|
|
439
|
+
return `${(tokens / 1000).toFixed(1)}K`;
|
|
440
|
+
}
|
|
441
|
+
return tokens.toString();
|
|
442
|
+
};
|
|
443
|
+
const suggestion = `↑ ${formatTokens(inputTokens)} | ↓ ${formatTokens(outputTokens)}`;
|
|
444
|
+
request.session.setSuggestions([suggestion]);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
protected isEditMode(request: MutableChatRequestModel): boolean {
|
|
448
|
+
const permissionMode = this.getClaudePermissionMode(request);
|
|
449
|
+
return permissionMode === 'acceptEdits' || permissionMode === 'bypassPermissions';
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
protected async reportTokenUsage(
|
|
453
|
+
request: MutableChatRequestModel,
|
|
454
|
+
inputTokens: number,
|
|
455
|
+
outputTokens: number,
|
|
456
|
+
cachedInputTokens?: number,
|
|
457
|
+
readCachedInputTokens?: number
|
|
458
|
+
): Promise<void> {
|
|
459
|
+
const modelName = this.getClaudeModelName(request);
|
|
460
|
+
if (!modelName) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const prefixedModelName = `anthropic/claude-code/${modelName}`;
|
|
465
|
+
const sessionId = this.getClaudeSessionId(request);
|
|
466
|
+
const requestId = sessionId || request.id;
|
|
467
|
+
|
|
468
|
+
try {
|
|
469
|
+
await this.tokenUsageService.recordTokenUsage(prefixedModelName, {
|
|
470
|
+
inputTokens,
|
|
471
|
+
outputTokens,
|
|
472
|
+
cachedInputTokens,
|
|
473
|
+
readCachedInputTokens,
|
|
474
|
+
requestId
|
|
475
|
+
});
|
|
476
|
+
} catch (error) {
|
|
477
|
+
console.error('Failed to report token usage:', error);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
protected async addResponseContent(message: SDKMessage, request: MutableChatRequestModel): Promise<void> {
|
|
482
|
+
// Extract model name from system init message
|
|
483
|
+
if (message.type === 'system' && message.subtype === 'init' && message.model) {
|
|
484
|
+
this.setClaudeModelName(request, message.model);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// Handle result messages with final usage
|
|
488
|
+
if (message.type === 'assistant' && message.message.usage) {
|
|
489
|
+
await this.handleTokenMetrics(message.message.usage, request);
|
|
490
|
+
}
|
|
491
|
+
if (message.type === 'result' && message.usage) {
|
|
492
|
+
request.addData(CLAUDE_COST_KEY, message.total_cost_usd);
|
|
493
|
+
await this.handleTokenMetrics(message.usage, request);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Handle user messages for local-command-stdout extraction
|
|
497
|
+
if (message.type === 'user') {
|
|
498
|
+
const extractedContent = this.extractLocalCommandStdout(message.message.content);
|
|
499
|
+
if (extractedContent) {
|
|
500
|
+
request.response.response.addContent(new MarkdownChatResponseContentImpl(extractedContent));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (message.type === 'assistant' || message.type === 'user') {
|
|
505
|
+
if (!Array.isArray(message.message.content)) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
for (const block of message.message.content) {
|
|
510
|
+
switch (block.type) {
|
|
511
|
+
case 'text':
|
|
512
|
+
request.response.response.addContent(new MarkdownChatResponseContentImpl(block.text));
|
|
513
|
+
break;
|
|
514
|
+
case 'tool_use':
|
|
515
|
+
case 'server_tool_use':
|
|
516
|
+
if (block.name === 'Task' && TaskInput.is(block.input)) {
|
|
517
|
+
request.response.response.addContent(new MarkdownChatResponseContentImpl(`\n\n### Task: ${block.input.description}\n\n${block.input.prompt}`));
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// Track file edits
|
|
521
|
+
if ((block.name === 'Edit' && EditInput.is(block.input)) ||
|
|
522
|
+
(block.name === 'MultiEdit' && MultiEditInput.is(block.input)) ||
|
|
523
|
+
(block.name === 'Write' && WriteInput.is(block.input))) {
|
|
524
|
+
const toolUse: ToolUseBlock = {
|
|
525
|
+
name: block.name,
|
|
526
|
+
input: block.input
|
|
527
|
+
};
|
|
528
|
+
this.getEditToolUses(request)?.set(block.id, toolUse);
|
|
529
|
+
}
|
|
530
|
+
request.response.response.addContent(new ClaudeCodeToolCallChatResponseContent(block.id, block.name, JSON.stringify(block.input)));
|
|
531
|
+
break;
|
|
532
|
+
case 'tool_result':
|
|
533
|
+
if (this.getEditToolUses(request)?.has(block.tool_use_id)) {
|
|
534
|
+
const toolUse = this.getEditToolUses(request)?.get(block.tool_use_id);
|
|
535
|
+
if (toolUse) {
|
|
536
|
+
await this.editToolService.handleEditTool(toolUse, request, {
|
|
537
|
+
sessionId: this.getClaudeSessionId(request),
|
|
538
|
+
isEditMode: this.isEditMode(request)
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
request.response.response.addContent(new ClaudeCodeToolCallChatResponseContent(block.tool_use_id, '', '', true, JSON.stringify(block.content)));
|
|
543
|
+
break;
|
|
544
|
+
case 'thinking':
|
|
545
|
+
request.response.response.addContent(new ThinkingChatResponseContentImpl(block.thinking.trim(), block.signature?.trim() || ''));
|
|
546
|
+
break;
|
|
547
|
+
case 'redacted_thinking':
|
|
548
|
+
request.response.response.addContent(new ThinkingChatResponseContentImpl(block.data.trim(), ''));
|
|
549
|
+
break;
|
|
550
|
+
case 'web_search_tool_result':
|
|
551
|
+
if (Array.isArray(block.content)) {
|
|
552
|
+
const result = block.content.map(value => value.title + ':' + value.url).join(', ');
|
|
553
|
+
request.response.response.addContent(new ClaudeCodeToolCallChatResponseContent(block.tool_use_id, '', '', true, result));
|
|
554
|
+
}
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
protected async handleTokenMetrics(usage: Usage, request: MutableChatRequestModel): Promise<void> {
|
|
562
|
+
const allInputTokens = (usage.input_tokens ?? 0) + (usage.cache_creation_input_tokens ?? 0);
|
|
563
|
+
this.updateTokens(request, allInputTokens, (usage.output_tokens ?? 0));
|
|
564
|
+
await this.reportTokenUsage(request, allInputTokens, (usage.output_tokens ?? 0),
|
|
565
|
+
(usage.cache_creation_input_tokens ?? 0), (usage.cache_read_input_tokens ?? 0));
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
private extractLocalCommandStdout(content: string | ContentBlock[]): string | undefined {
|
|
569
|
+
const regex = /<local-command-stdout>([\s\S]*?)<\/local-command-stdout>/g;
|
|
570
|
+
let extractedContent = '';
|
|
571
|
+
let match;
|
|
572
|
+
|
|
573
|
+
if (typeof content === 'string') {
|
|
574
|
+
// eslint-disable-next-line no-null/no-null
|
|
575
|
+
while ((match = regex.exec(content)) !== null) {
|
|
576
|
+
extractedContent += match[1];
|
|
577
|
+
}
|
|
578
|
+
} else {
|
|
579
|
+
for (const block of content) {
|
|
580
|
+
if (block.type === 'text') {
|
|
581
|
+
// eslint-disable-next-line no-null/no-null
|
|
582
|
+
while ((match = regex.exec(block.text)) !== null) {
|
|
583
|
+
extractedContent += match[1];
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return extractedContent || undefined;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { Command, CommandContribution, CommandRegistry } from '@theia/core';
|
|
18
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { codicon } from '@theia/core/lib/browser';
|
|
20
|
+
import { EditorManager } from '@theia/editor/lib/browser';
|
|
21
|
+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
22
|
+
import { WorkspaceService } from '@theia/workspace/lib/browser';
|
|
23
|
+
import { ChatCommands } from '@theia/ai-chat-ui/lib/browser/chat-view-commands';
|
|
24
|
+
import { AIActivationService } from '@theia/ai-core/lib/browser';
|
|
25
|
+
|
|
26
|
+
export const OPEN_CLAUDE_CODE_CONFIG = Command.toLocalizedCommand({
|
|
27
|
+
id: 'chat:open-claude-code-config',
|
|
28
|
+
category: 'Chat',
|
|
29
|
+
iconClass: codicon('bracket'),
|
|
30
|
+
label: 'Open Claude Code Configuration'
|
|
31
|
+
}, 'theia/ai-claude-code/open-config', ChatCommands.CHAT_CATEGORY);
|
|
32
|
+
|
|
33
|
+
export const OPEN_CLAUDE_CODE_MEMORY = Command.toLocalizedCommand({
|
|
34
|
+
id: 'chat:open-claude-code-memory',
|
|
35
|
+
category: 'Chat',
|
|
36
|
+
iconClass: codicon('bracket'),
|
|
37
|
+
label: 'Open Claude Code Memory (CLAUDE.MD)'
|
|
38
|
+
}, 'theia/ai-claude-code/open-memory', ChatCommands.CHAT_CATEGORY);
|
|
39
|
+
|
|
40
|
+
@injectable()
|
|
41
|
+
export class ClaudeCodeCommandContribution implements CommandContribution {
|
|
42
|
+
|
|
43
|
+
@inject(WorkspaceService)
|
|
44
|
+
protected readonly workspaceService: WorkspaceService;
|
|
45
|
+
|
|
46
|
+
@inject(FileService)
|
|
47
|
+
protected readonly fileService: FileService;
|
|
48
|
+
|
|
49
|
+
@inject(EditorManager)
|
|
50
|
+
protected readonly editorManager: EditorManager;
|
|
51
|
+
|
|
52
|
+
@inject(AIActivationService)
|
|
53
|
+
protected readonly activationService: AIActivationService;
|
|
54
|
+
|
|
55
|
+
registerCommands(commands: CommandRegistry): void {
|
|
56
|
+
commands.registerCommand(OPEN_CLAUDE_CODE_CONFIG, {
|
|
57
|
+
execute: async () => await this.openFileInWorkspace('.claude/settings.json', JSON.stringify({}, undefined, 2)),
|
|
58
|
+
isVisible: () => this.activationService.isActive,
|
|
59
|
+
isEnabled: () => this.activationService.isActive
|
|
60
|
+
});
|
|
61
|
+
commands.registerCommand(OPEN_CLAUDE_CODE_MEMORY, {
|
|
62
|
+
execute: async () => await this.openFileInWorkspace('.claude/CLAUDE.md', ''),
|
|
63
|
+
isVisible: () => this.activationService.isActive,
|
|
64
|
+
isEnabled: () => this.activationService.isActive
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected async openFileInWorkspace(file: string, initialContent: string): Promise<void> {
|
|
69
|
+
const roots = this.workspaceService.tryGetRoots();
|
|
70
|
+
if (roots.length < 1) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const uri = roots[0].resource;
|
|
74
|
+
const claudeSettingsUri = uri.resolve(file);
|
|
75
|
+
if (! await this.fileService.exists(claudeSettingsUri)) {
|
|
76
|
+
await this.fileService.write(claudeSettingsUri, initialContent, { encoding: 'utf8' });
|
|
77
|
+
}
|
|
78
|
+
this.editorManager.open(claudeSettingsUri);
|
|
79
|
+
}
|
|
80
|
+
}
|