@theia/ai-ide 1.77.0-next.7 → 1.77.0-next.71
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/lib/browser/{project-info-agent.d.ts → agents-md-agent.d.ts} +2 -2
- package/lib/browser/agents-md-agent.d.ts.map +1 -0
- package/lib/browser/{project-info-agent.js → agents-md-agent.js} +16 -15
- package/lib/browser/agents-md-agent.js.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-label-provider-contribution.js +1 -1
- package/lib/browser/ai-configuration/ai-configuration-label-provider-contribution.js.map +1 -1
- package/lib/browser/ai-configuration/ai-configuration-resource.js +2 -1
- package/lib/browser/ai-configuration/ai-configuration-resource.js.map +1 -1
- package/lib/browser/ai-configuration/ai-configuration-search-widget.js +1 -1
- package/lib/browser/ai-configuration/ai-configuration-search-widget.js.map +1 -1
- package/lib/browser/ai-configuration/categories/agent-capabilities-settings.d.ts +11 -3
- package/lib/browser/ai-configuration/categories/agent-capabilities-settings.d.ts.map +1 -1
- package/lib/browser/ai-configuration/categories/agent-capabilities-settings.js +64 -29
- package/lib/browser/ai-configuration/categories/agent-capabilities-settings.js.map +1 -1
- package/lib/browser/ai-configuration/categories/agent-capabilities-settings.spec.js +480 -1
- package/lib/browser/ai-configuration/categories/agent-capabilities-settings.spec.js.map +1 -1
- package/lib/browser/ai-configuration/categories/agent-detail-model.d.ts +10 -0
- package/lib/browser/ai-configuration/categories/agent-detail-model.d.ts.map +1 -1
- package/lib/browser/ai-configuration/categories/agent-detail-model.js +8 -0
- package/lib/browser/ai-configuration/categories/agent-detail-model.js.map +1 -1
- package/lib/browser/ai-configuration/categories/agent-detail-model.spec.d.ts +2 -0
- package/lib/browser/ai-configuration/categories/agent-detail-model.spec.d.ts.map +1 -0
- package/lib/browser/ai-configuration/categories/agent-detail-model.spec.js +74 -0
- package/lib/browser/ai-configuration/categories/agent-detail-model.spec.js.map +1 -0
- package/lib/browser/ai-configuration/categories/agent-detail-view.d.ts.map +1 -1
- package/lib/browser/ai-configuration/categories/agent-detail-view.js +3 -2
- package/lib/browser/ai-configuration/categories/agent-detail-view.js.map +1 -1
- package/lib/browser/ai-configuration/categories/agents-configuration-category.d.ts +6 -1
- package/lib/browser/ai-configuration/categories/agents-configuration-category.d.ts.map +1 -1
- package/lib/browser/ai-configuration/categories/agents-configuration-category.js +20 -2
- package/lib/browser/ai-configuration/categories/agents-configuration-category.js.map +1 -1
- package/lib/browser/ai-configuration/categories/provider-model-discovery-section.js +5 -4
- package/lib/browser/ai-configuration/categories/provider-model-discovery-section.js.map +1 -1
- package/lib/browser/ai-configuration/categories/provider-model-discovery-section.spec.js +2 -1
- package/lib/browser/ai-configuration/categories/provider-model-discovery-section.spec.js.map +1 -1
- package/lib/browser/ai-configuration/categories/token-usage-configuration-category.js +2 -2
- package/lib/browser/ai-configuration/categories/token-usage-configuration-category.js.map +1 -1
- package/lib/browser/ai-configuration/categories/tools-configuration-category.js +1 -1
- package/lib/browser/ai-configuration/categories/tools-configuration-category.js.map +1 -1
- package/lib/browser/ai-configuration/categories/variables-configuration-category.js +1 -1
- package/lib/browser/ai-configuration/categories/variables-configuration-category.js.map +1 -1
- package/lib/browser/ai-configuration/language-model-renderer.d.ts.map +1 -1
- package/lib/browser/ai-configuration/language-model-renderer.js +8 -15
- package/lib/browser/ai-configuration/language-model-renderer.js.map +1 -1
- package/lib/browser/ai-configuration/language-model-renderer.spec.js +40 -1
- package/lib/browser/ai-configuration/language-model-renderer.spec.js.map +1 -1
- package/lib/browser/ai-sessions-widget.js +1 -1
- package/lib/browser/ai-sessions-widget.js.map +1 -1
- package/lib/browser/app-tester-prompt-template.d.ts.map +1 -1
- package/lib/browser/app-tester-prompt-template.js +4 -6
- package/lib/browser/app-tester-prompt-template.js.map +1 -1
- package/lib/browser/architect-prompt-template.d.ts.map +1 -1
- package/lib/browser/architect-prompt-template.js +20 -3
- package/lib/browser/architect-prompt-template.js.map +1 -1
- package/lib/browser/chat-session-item.js +2 -1
- package/lib/browser/chat-session-item.js.map +1 -1
- package/lib/browser/chat-sessions-welcome-message-provider.js +1 -1
- package/lib/browser/chat-sessions-welcome-message-provider.js.map +1 -1
- package/lib/browser/code-reviewer-prompt-template.d.ts.map +1 -1
- package/lib/browser/code-reviewer-prompt-template.js +2 -1
- package/lib/browser/code-reviewer-prompt-template.js.map +1 -1
- package/lib/browser/commit-message-agent.spec.js +2 -1
- package/lib/browser/commit-message-agent.spec.js.map +1 -1
- package/lib/browser/commit-message-runner.spec.js +2 -1
- package/lib/browser/commit-message-runner.spec.js.map +1 -1
- package/lib/browser/context-file-validation-service-impl.spec.js +2 -1
- package/lib/browser/context-file-validation-service-impl.spec.js.map +1 -1
- package/lib/browser/explore-prompt-template.d.ts.map +1 -1
- package/lib/browser/explore-prompt-template.js +2 -1
- package/lib/browser/explore-prompt-template.js.map +1 -1
- package/lib/browser/file-changeset-functions.d.ts +3 -1
- package/lib/browser/file-changeset-functions.d.ts.map +1 -1
- package/lib/browser/file-changeset-functions.js +60 -6
- package/lib/browser/file-changeset-functions.js.map +1 -1
- package/lib/browser/file-changeset-functions.spec.js +73 -9
- package/lib/browser/file-changeset-functions.spec.js.map +1 -1
- package/lib/browser/frontend-module.js +4 -4
- package/lib/browser/frontend-module.js.map +1 -1
- package/lib/browser/git-changes-tool.d.ts +3 -3
- package/lib/browser/git-changes-tool.d.ts.map +1 -1
- package/lib/browser/git-changes-tool.js +7 -11
- package/lib/browser/git-changes-tool.js.map +1 -1
- package/lib/browser/git-changes-tool.spec.js +16 -3
- package/lib/browser/git-changes-tool.spec.js.map +1 -1
- package/lib/browser/multi-root-paths.spec.d.ts +2 -0
- package/lib/browser/multi-root-paths.spec.d.ts.map +1 -0
- package/lib/browser/multi-root-paths.spec.js +293 -0
- package/lib/browser/multi-root-paths.spec.js.map +1 -0
- package/lib/browser/remember-command-contribution.d.ts +2 -2
- package/lib/browser/remember-command-contribution.js +6 -6
- package/lib/browser/remember-command-contribution.js.map +1 -1
- package/lib/browser/review/pr-review-prompt-template.d.ts.map +1 -1
- package/lib/browser/review/pr-review-prompt-template.js +3 -2
- package/lib/browser/review/pr-review-prompt-template.js.map +1 -1
- package/lib/browser/task-context-file-storage-service.d.ts.map +1 -1
- package/lib/browser/task-context-file-storage-service.js +1 -2
- package/lib/browser/task-context-file-storage-service.js.map +1 -1
- package/lib/browser/task-context-file-storage-service.spec.d.ts +2 -0
- package/lib/browser/task-context-file-storage-service.spec.d.ts.map +1 -0
- package/lib/browser/task-context-file-storage-service.spec.js +111 -0
- package/lib/browser/task-context-file-storage-service.spec.js.map +1 -0
- package/lib/browser/user-interaction-tool-renderer.js +1 -1
- package/lib/browser/user-interaction-tool-renderer.js.map +1 -1
- package/lib/browser/user-interaction-tool.d.ts +12 -1
- package/lib/browser/user-interaction-tool.d.ts.map +1 -1
- package/lib/browser/user-interaction-tool.js +35 -9
- package/lib/browser/user-interaction-tool.js.map +1 -1
- package/lib/browser/user-interaction-tool.spec.js +15 -2
- package/lib/browser/user-interaction-tool.spec.js.map +1 -1
- package/lib/browser/workspace-functions.d.ts +20 -17
- package/lib/browser/workspace-functions.d.ts.map +1 -1
- package/lib/browser/workspace-functions.js +77 -115
- package/lib/browser/workspace-functions.js.map +1 -1
- package/lib/browser/workspace-functions.spec.js +54 -60
- package/lib/browser/workspace-functions.spec.js.map +1 -1
- package/lib/browser/workspace-launch-provider.js +1 -1
- package/lib/browser/workspace-launch-provider.js.map +1 -1
- package/lib/browser/workspace-launch-provider.spec.js +5 -3
- package/lib/browser/workspace-launch-provider.spec.js.map +1 -1
- package/lib/browser/workspace-search-provider.spec.js +2 -1
- package/lib/browser/workspace-search-provider.spec.js.map +1 -1
- package/lib/browser/workspace-task-provider.js +1 -1
- package/lib/browser/workspace-task-provider.js.map +1 -1
- package/lib/browser/workspace-task-provider.spec.js +6 -4
- package/lib/browser/workspace-task-provider.spec.js.map +1 -1
- package/lib/common/agents-md-prompt-template.d.ts +6 -0
- package/lib/common/agents-md-prompt-template.d.ts.map +1 -0
- package/lib/common/agents-md-prompt-template.js +165 -0
- package/lib/common/agents-md-prompt-template.js.map +1 -0
- package/lib/common/coder-replace-prompt-template.d.ts.map +1 -1
- package/lib/common/coder-replace-prompt-template.js +4 -6
- package/lib/common/coder-replace-prompt-template.js.map +1 -1
- package/lib/common/command-prompt-template.js +1 -1
- package/lib/common/command-prompt-template.js.map +1 -1
- package/lib/common/orchestrator-prompt-template.js +1 -1
- package/lib/common/orchestrator-prompt-template.js.map +1 -1
- package/lib/common/universal-prompt-template.js +1 -1
- package/lib/common/universal-prompt-template.js.map +1 -1
- package/lib/common/workspace-preferences.d.ts +1 -0
- package/lib/common/workspace-preferences.d.ts.map +1 -1
- package/lib/common/workspace-preferences.js +10 -1
- package/lib/common/workspace-preferences.js.map +1 -1
- package/lib/package.spec.js +1 -0
- package/lib/package.spec.js.map +1 -1
- package/package.json +27 -28
- package/src/browser/{project-info-agent.ts → agents-md-agent.ts} +11 -10
- package/src/browser/ai-configuration/categories/agent-capabilities-settings.spec.ts +508 -2
- package/src/browser/ai-configuration/categories/agent-capabilities-settings.tsx +92 -33
- package/src/browser/ai-configuration/categories/agent-detail-model.spec.ts +78 -0
- package/src/browser/ai-configuration/categories/agent-detail-model.ts +18 -0
- package/src/browser/ai-configuration/categories/agent-detail-view.tsx +15 -12
- package/src/browser/ai-configuration/categories/agents-configuration-category.tsx +18 -3
- package/src/browser/ai-configuration/categories/provider-model-discovery-section.tsx +3 -3
- package/src/browser/ai-configuration/categories/token-usage-configuration-category.tsx +2 -2
- package/src/browser/ai-configuration/language-model-renderer.spec.ts +38 -0
- package/src/browser/ai-configuration/language-model-renderer.tsx +6 -15
- package/src/browser/app-tester-prompt-template.ts +4 -7
- package/src/browser/architect-prompt-template.ts +4 -4
- package/src/browser/code-reviewer-prompt-template.ts +2 -2
- package/src/browser/context-file-validation-service-impl.spec.ts +2 -1
- package/src/browser/explore-prompt-template.ts +2 -2
- package/src/browser/file-changeset-functions.spec.ts +91 -9
- package/src/browser/file-changeset-functions.ts +62 -7
- package/src/browser/frontend-module.ts +4 -4
- package/src/browser/git-changes-tool.spec.ts +16 -1
- package/src/browser/git-changes-tool.ts +6 -10
- package/src/browser/multi-root-paths.spec.ts +340 -0
- package/src/browser/remember-command-contribution.ts +7 -7
- package/src/browser/review/pr-review-prompt-template.ts +3 -3
- package/src/browser/style/index.css +15 -0
- package/src/browser/task-context-file-storage-service.spec.ts +125 -0
- package/src/browser/task-context-file-storage-service.ts +3 -4
- package/src/browser/user-interaction-tool.spec.ts +18 -1
- package/src/browser/user-interaction-tool.ts +34 -9
- package/src/browser/workspace-functions.spec.ts +54 -60
- package/src/browser/workspace-functions.ts +80 -125
- package/src/browser/workspace-launch-provider.spec.ts +3 -2
- package/src/browser/workspace-task-provider.spec.ts +4 -3
- package/src/common/{project-info-prompt-template.ts → agents-md-prompt-template.ts} +54 -46
- package/src/common/coder-replace-prompt-template.ts +5 -7
- package/src/common/command-prompt-template.ts +1 -1
- package/src/common/orchestrator-prompt-template.ts +1 -1
- package/src/common/universal-prompt-template.ts +1 -1
- package/src/common/workspace-preferences.ts +10 -0
- package/lib/browser/project-info-agent.d.ts.map +0 -1
- package/lib/browser/project-info-agent.js.map +0 -1
- package/lib/common/project-info-prompt-template.d.ts +0 -6
- package/lib/common/project-info-prompt-template.d.ts.map +0 -1
- package/lib/common/project-info-prompt-template.js +0 -146
- package/lib/common/project-info-prompt-template.js.map +0 -1
|
@@ -31,6 +31,7 @@ import { WorkspaceFunctionScope } from './workspace-functions';
|
|
|
31
31
|
import { AiConfigurationService } from '@theia/ai-core';
|
|
32
32
|
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
33
33
|
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
|
34
|
+
import { withWorkspaceServiceDefaults } from '@theia/workspace/lib/browser/test/with-workspace-service-defaults';
|
|
34
35
|
|
|
35
36
|
disableJSDOM();
|
|
36
37
|
|
|
@@ -112,7 +113,7 @@ describe('ContextFileValidationService', () => {
|
|
|
112
113
|
} as unknown as PreferenceService;
|
|
113
114
|
|
|
114
115
|
container.bind(FileService).toConstantValue(mockFileService);
|
|
115
|
-
container.bind(WorkspaceService).toConstantValue(mockWorkspaceService);
|
|
116
|
+
container.bind(WorkspaceService).toConstantValue(withWorkspaceServiceDefaults(mockWorkspaceService));
|
|
116
117
|
container.bind(PreferenceService).toConstantValue(mockPreferenceService);
|
|
117
118
|
container.bind(AiConfigurationService).toConstantValue({
|
|
118
119
|
get: <T>(_name: string, fallback?: T) => fallback,
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import { BasePromptFragment } from '@theia/ai-core/lib/common';
|
|
17
|
+
import { AGENTS_MD_PROMPT_FRAGMENT_ID, BasePromptFragment } from '@theia/ai-core/lib/common';
|
|
18
18
|
|
|
19
19
|
export const EXPLORE_SYSTEM_PROMPT_ID = 'explore-system';
|
|
20
20
|
|
|
@@ -116,6 +116,6 @@ For each file, include ONLY what is needed for the task:
|
|
|
116
116
|
|
|
117
117
|
{{contextFiles}}
|
|
118
118
|
|
|
119
|
-
{{prompt
|
|
119
|
+
{{prompt:${AGENTS_MD_PROMPT_FRAGMENT_ID}}}
|
|
120
120
|
`
|
|
121
121
|
};
|
|
@@ -47,6 +47,8 @@ import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
|
47
47
|
import { ChangeSetElementArgs, ChangeSetFileElementFactory, ChangeSetFileElement } from '@theia/ai-chat/lib/browser/change-set-file-element';
|
|
48
48
|
import { URI } from '@theia/core/lib/common/uri';
|
|
49
49
|
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
|
50
|
+
import { withWorkspaceServiceDefaults } from '@theia/workspace/lib/browser/test/with-workspace-service-defaults';
|
|
51
|
+
import { WRITE_CONTENT_MAX_SIZE_KB_PREF } from '../common/workspace-preferences';
|
|
50
52
|
|
|
51
53
|
disableJSDOM();
|
|
52
54
|
|
|
@@ -54,6 +56,8 @@ describe('File Changeset Functions Cancellation Tests', () => {
|
|
|
54
56
|
let cancellationTokenSource: CancellationTokenSource;
|
|
55
57
|
let mockCtx: ChatToolContext;
|
|
56
58
|
let container: Container;
|
|
59
|
+
let preferenceValues: Record<string, unknown>;
|
|
60
|
+
let createdElements: ChangeSetElementArgs[];
|
|
57
61
|
before(() => {
|
|
58
62
|
disableJSDOM = enableJSDOM();
|
|
59
63
|
});
|
|
@@ -63,6 +67,8 @@ describe('File Changeset Functions Cancellation Tests', () => {
|
|
|
63
67
|
});
|
|
64
68
|
beforeEach(() => {
|
|
65
69
|
cancellationTokenSource = new CancellationTokenSource();
|
|
70
|
+
preferenceValues = {};
|
|
71
|
+
createdElements = [];
|
|
66
72
|
|
|
67
73
|
// Create a mock change set that doesn't do anything
|
|
68
74
|
const mockChangeSet: Partial<ChangeSet> = {
|
|
@@ -99,17 +105,23 @@ describe('File Changeset Functions Cancellation Tests', () => {
|
|
|
99
105
|
read: async () => ({ value: { toString: () => 'test content' } })
|
|
100
106
|
} as unknown as FileService;
|
|
101
107
|
|
|
102
|
-
const mockFileChangeFactory: ChangeSetFileElementFactory = () =>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
const mockFileChangeFactory: ChangeSetFileElementFactory = (elementArgs: ChangeSetElementArgs) => {
|
|
109
|
+
createdElements.push(elementArgs);
|
|
110
|
+
return {
|
|
111
|
+
uri: new URI('file:///workspace/test.txt'),
|
|
112
|
+
type: 'modify',
|
|
113
|
+
state: 'pending',
|
|
114
|
+
targetState: 'new content',
|
|
115
|
+
apply: async () => { },
|
|
116
|
+
} as ChangeSetFileElement;
|
|
117
|
+
};
|
|
109
118
|
|
|
110
119
|
// Register mocks in the container
|
|
111
120
|
container.bind(WorkspaceFunctionScope).toConstantValue(mockWorkspaceScope);
|
|
112
121
|
container.bind(ILogger).to(MockLogger).inSingletonScope();
|
|
122
|
+
container.bind(PreferenceService).toConstantValue({
|
|
123
|
+
get: <T>(preferenceName: string, defaultValue: T) => (preferenceValues[preferenceName] ?? defaultValue) as T
|
|
124
|
+
} as unknown as PreferenceService);
|
|
113
125
|
container.bind(FileService).toConstantValue(mockFileService);
|
|
114
126
|
container.bind(ChangeSetFileElementFactory).toConstantValue(mockFileChangeFactory);
|
|
115
127
|
container.bind(FileChangeSetTitleProvider).to(DefaultFileChangeSetTitleProvider).inSingletonScope();
|
|
@@ -315,6 +327,76 @@ describe('File Changeset Functions Cancellation Tests', () => {
|
|
|
315
327
|
expect(result).to.equal('Successfully wrote content to file test.txt.');
|
|
316
328
|
});
|
|
317
329
|
});
|
|
330
|
+
|
|
331
|
+
describe('write content size guard', () => {
|
|
332
|
+
it('WriteFileContent rejects content exceeding the maximum write size', async () => {
|
|
333
|
+
preferenceValues[WRITE_CONTENT_MAX_SIZE_KB_PREF] = 1;
|
|
334
|
+
const handler = container.get(WriteFileContent).getTool().handler;
|
|
335
|
+
|
|
336
|
+
const result = await handler(JSON.stringify({ path: 'test.txt', content: 'x'.repeat(2048) }), mockCtx);
|
|
337
|
+
|
|
338
|
+
const jsonResponse = typeof result === 'string' ? JSON.parse(result) : result;
|
|
339
|
+
expect(jsonResponse.error).to.match(/maximum write size/);
|
|
340
|
+
expect(jsonResponse.error).to.include('writeFileReplacements');
|
|
341
|
+
expect(createdElements).to.be.empty;
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('SuggestFileContent rejects content exceeding the maximum write size', async () => {
|
|
345
|
+
preferenceValues[WRITE_CONTENT_MAX_SIZE_KB_PREF] = 1;
|
|
346
|
+
const handler = container.get(SuggestFileContent).getTool().handler;
|
|
347
|
+
|
|
348
|
+
const result = await handler(JSON.stringify({ path: 'test.txt', content: 'x'.repeat(2048) }), mockCtx);
|
|
349
|
+
|
|
350
|
+
const jsonResponse = typeof result === 'string' ? JSON.parse(result) : result;
|
|
351
|
+
expect(jsonResponse.error).to.match(/maximum write size/);
|
|
352
|
+
expect(jsonResponse.error).to.include('suggestFileReplacements');
|
|
353
|
+
expect(createdElements).to.be.empty;
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('WriteFileContent steers an oversized new file to creating it smaller first', async () => {
|
|
357
|
+
preferenceValues[WRITE_CONTENT_MAX_SIZE_KB_PREF] = 1;
|
|
358
|
+
container.rebind(FileService).toConstantValue({ exists: async () => false } as unknown as FileService);
|
|
359
|
+
const handler = container.get(WriteFileContent).getTool().handler;
|
|
360
|
+
|
|
361
|
+
const result = await handler(JSON.stringify({ path: 'test.txt', content: 'x'.repeat(2048) }), mockCtx);
|
|
362
|
+
|
|
363
|
+
const jsonResponse = typeof result === 'string' ? JSON.parse(result) : result;
|
|
364
|
+
expect(jsonResponse.error).to.include('Create the file with a smaller initial part, then add the rest with writeFileReplacements');
|
|
365
|
+
expect(createdElements).to.be.empty;
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('tool descriptions state the current maximum write size', () => {
|
|
369
|
+
const writeTool = container.get(WriteFileContent).getTool();
|
|
370
|
+
const suggestTool = container.get(SuggestFileContent).getTool();
|
|
371
|
+
expect(writeTool.description).to.include('larger than 256KB');
|
|
372
|
+
|
|
373
|
+
preferenceValues[WRITE_CONTENT_MAX_SIZE_KB_PREF] = 64;
|
|
374
|
+
|
|
375
|
+
expect(writeTool.description).to.include('larger than 64KB');
|
|
376
|
+
expect(suggestTool.description).to.include('larger than 64KB');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('WriteFileContent accepts content within the limit', async () => {
|
|
380
|
+
preferenceValues[WRITE_CONTENT_MAX_SIZE_KB_PREF] = 1;
|
|
381
|
+
const handler = container.get(WriteFileContent).getTool().handler;
|
|
382
|
+
|
|
383
|
+
const result = await handler(JSON.stringify({ path: 'test.txt', content: 'small content' }), mockCtx);
|
|
384
|
+
|
|
385
|
+
expect(result).to.equal('Successfully wrote content to file test.txt.');
|
|
386
|
+
expect(createdElements).to.have.length(1);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('WriteFileContent still allows deleting a file (empty content)', async () => {
|
|
390
|
+
preferenceValues[WRITE_CONTENT_MAX_SIZE_KB_PREF] = 1;
|
|
391
|
+
const handler = container.get(WriteFileContent).getTool().handler;
|
|
392
|
+
|
|
393
|
+
const result = await handler(JSON.stringify({ path: 'test.txt', content: '' }), mockCtx);
|
|
394
|
+
|
|
395
|
+
expect(result).to.equal('Successfully wrote content to file test.txt.');
|
|
396
|
+
expect(createdElements).to.have.length(1);
|
|
397
|
+
expect(createdElements[0].type).to.equal('delete');
|
|
398
|
+
});
|
|
399
|
+
});
|
|
318
400
|
});
|
|
319
401
|
|
|
320
402
|
describe('File Changeset Functions access control', () => {
|
|
@@ -346,11 +428,11 @@ describe('File Changeset Functions access control', () => {
|
|
|
346
428
|
|
|
347
429
|
container = new Container();
|
|
348
430
|
container.bind(ILogger).to(MockLogger).inSingletonScope();
|
|
349
|
-
container.bind(WorkspaceService).toConstantValue({
|
|
431
|
+
container.bind(WorkspaceService).toConstantValue(withWorkspaceServiceDefaults({
|
|
350
432
|
roots: [{ resource: new URI('file:///workspace') }],
|
|
351
433
|
tryGetRoots: () => [{ resource: new URI('file:///workspace') }],
|
|
352
434
|
onWorkspaceChanged: () => ({ dispose: () => { } })
|
|
353
|
-
} as unknown as WorkspaceService);
|
|
435
|
+
} as unknown as WorkspaceService));
|
|
354
436
|
container.bind(FileService).toConstantValue({
|
|
355
437
|
exists: async () => true,
|
|
356
438
|
read: async () => ({ value: { toString: () => 'old content' } }),
|
|
@@ -24,7 +24,7 @@ import { inject, injectable, named, optional } from '@theia/core/shared/inversif
|
|
|
24
24
|
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
25
25
|
import { WorkspaceFunctionScope } from './workspace-functions';
|
|
26
26
|
|
|
27
|
-
import { nls, ILogger } from '@theia/core';
|
|
27
|
+
import { nls, ILogger, PreferenceService } from '@theia/core';
|
|
28
28
|
import { extractJsonStringField } from '@theia/ai-chat-ui/lib/browser/chat-response-renderer/toolcall-utils';
|
|
29
29
|
import {
|
|
30
30
|
CLEAR_FILE_CHANGES_ID,
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
SUGGEST_FILE_REPLACEMENTS_SIMPLE_ID,
|
|
37
37
|
WRITE_FILE_REPLACEMENTS_SIMPLE_ID
|
|
38
38
|
} from '../common/file-changeset-function-ids';
|
|
39
|
+
import { WRITE_CONTENT_MAX_SIZE_KB_PREF } from '../common/workspace-preferences';
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Description of the `path` parameter shared by all file changeset tools, so that they advertise the
|
|
@@ -62,6 +63,34 @@ function staleFileError(path: string): string {
|
|
|
62
63
|
return `File ${path} changed since you last read it. Read it again before overwriting it, so that the changes made in the meantime are not lost.`;
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
const DEFAULT_WRITE_CONTENT_MAX_SIZE_KB = 256;
|
|
67
|
+
|
|
68
|
+
function getWriteContentMaxSizeKB(preferenceService: PreferenceService): number {
|
|
69
|
+
return preferenceService.get<number>(WRITE_CONTENT_MAX_SIZE_KB_PREF, DEFAULT_WRITE_CONTENT_MAX_SIZE_KB);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Whole-file writes require the model to re-emit the entire content as tool arguments, so their cost grows
|
|
74
|
+
* with file size; mirror the read-side limit and steer oversized writes to the replacement-based tools.
|
|
75
|
+
* The check only runs once the arguments have been generated, so it blocks the write and steers retries;
|
|
76
|
+
* stating the limit in the tool description is what lets the model avoid the oversized call up front.
|
|
77
|
+
*
|
|
78
|
+
* @returns the error to report, or `undefined` if the content is within the limit.
|
|
79
|
+
*/
|
|
80
|
+
function writeContentSizeError(content: string, maxSizeKB: number, fileExists: boolean, replacementsToolId: string): string | undefined {
|
|
81
|
+
const sizeKB = Math.round(Buffer.byteLength(content, 'utf8') / 1024);
|
|
82
|
+
if (sizeKB <= maxSizeKB) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
// The replacement tools edit existing content, so a new file has to be created small first.
|
|
86
|
+
const hint = fileExists
|
|
87
|
+
? `Use ${replacementsToolId} for targeted edits`
|
|
88
|
+
: `Create the file with a smaller initial part, then add the rest with ${replacementsToolId}`;
|
|
89
|
+
return `The provided content is ${sizeKB}KB, but the maximum write size is ${maxSizeKB}KB ` +
|
|
90
|
+
`(preference "${WRITE_CONTENT_MAX_SIZE_KB_PREF}"). ${hint}, ` +
|
|
91
|
+
'or avoid embedding large data in the file and reference it by path instead.';
|
|
92
|
+
}
|
|
93
|
+
|
|
65
94
|
export const FileChangeSetTitleProvider = Symbol('FileChangeSetTitleProvider');
|
|
66
95
|
|
|
67
96
|
export interface FileChangeSetTitleProvider {
|
|
@@ -88,16 +117,24 @@ export class SuggestFileContent implements ToolProvider {
|
|
|
88
117
|
@inject(FileReadTracker) @optional()
|
|
89
118
|
protected readonly fileReadTracker: FileReadTracker | undefined;
|
|
90
119
|
|
|
120
|
+
@inject(PreferenceService)
|
|
121
|
+
protected readonly preferenceService: PreferenceService;
|
|
122
|
+
|
|
91
123
|
getTool(): ToolRequest {
|
|
124
|
+
const preferenceService = this.preferenceService;
|
|
92
125
|
return {
|
|
93
126
|
id: SuggestFileContent.ID,
|
|
94
127
|
name: SuggestFileContent.ID,
|
|
95
|
-
|
|
128
|
+
// A getter, because the registry keeps the tool from startup while the limit is a live preference.
|
|
129
|
+
get description(): string {
|
|
130
|
+
return `Proposes writing complete content to a file for user review. If the file exists, it will be overwritten with the provided content.
|
|
96
131
|
If the file does not exist, it will be created. This tool will automatically create any directories needed to write the file.
|
|
97
132
|
If the new content is empty, the file will be deleted. To move a file, delete it and re-create it at the new location.
|
|
98
133
|
The proposed changes will be applied when the user accepts. If called again for the same file, previously proposed changes will be overridden.
|
|
99
134
|
Use this for creating new files or when you need to rewrite an entire file.
|
|
100
|
-
For targeted edits to existing files, prefer suggestFileReplacements instead - it's more efficient and shows clearer diffs
|
|
135
|
+
For targeted edits to existing files, prefer suggestFileReplacements instead - it's more efficient and shows clearer diffs.
|
|
136
|
+
Content larger than ${getWriteContentMaxSizeKB(preferenceService)}KB is rejected.`;
|
|
137
|
+
},
|
|
101
138
|
parameters: {
|
|
102
139
|
type: 'object',
|
|
103
140
|
properties: {
|
|
@@ -129,11 +166,16 @@ export class SuggestFileContent implements ToolProvider {
|
|
|
129
166
|
if (await this.fileReadTracker?.isStale(chatSessionId, uri)) {
|
|
130
167
|
return JSON.stringify({ error: staleFileError(path) });
|
|
131
168
|
}
|
|
169
|
+
const exists = await this.fileService.exists(uri);
|
|
170
|
+
const sizeError = writeContentSizeError(content, getWriteContentMaxSizeKB(this.preferenceService), exists, SUGGEST_FILE_REPLACEMENTS_ID);
|
|
171
|
+
if (sizeError) {
|
|
172
|
+
return JSON.stringify({ error: sizeError });
|
|
173
|
+
}
|
|
132
174
|
let type: ChangeSetElementArgs['type'] = 'modify';
|
|
133
175
|
if (content === '') {
|
|
134
176
|
type = 'delete';
|
|
135
177
|
}
|
|
136
|
-
if (!
|
|
178
|
+
if (!exists) {
|
|
137
179
|
type = 'add';
|
|
138
180
|
}
|
|
139
181
|
ctx.request.session.changeSet.addElements(
|
|
@@ -175,17 +217,25 @@ export class WriteFileContent implements ToolProvider {
|
|
|
175
217
|
@inject(FileReadTracker) @optional()
|
|
176
218
|
protected readonly fileReadTracker: FileReadTracker | undefined;
|
|
177
219
|
|
|
220
|
+
@inject(PreferenceService)
|
|
221
|
+
protected readonly preferenceService: PreferenceService;
|
|
222
|
+
|
|
178
223
|
getTool(): ToolRequest {
|
|
224
|
+
const preferenceService = this.preferenceService;
|
|
179
225
|
return {
|
|
180
226
|
id: WriteFileContent.ID,
|
|
181
227
|
name: WriteFileContent.ID,
|
|
182
|
-
|
|
228
|
+
// A getter, because the registry keeps the tool from startup while the limit is a live preference.
|
|
229
|
+
get description(): string {
|
|
230
|
+
return `Immediately writes complete content to a file WITHOUT user confirmation. If the file exists, it will be overwritten.
|
|
183
231
|
If the file does not exist, it will be created. This tool will automatically create any directories needed to write the file.
|
|
184
232
|
If the new content is empty, the file will be deleted. To move a file, delete it and re-create it at the new location.
|
|
185
233
|
Use this for creating new files or complete file rewrites in agent mode.
|
|
186
234
|
For targeted edits, prefer writeFileReplacements - it's more efficient and less error-prone.
|
|
187
235
|
Never write to the same file in parallel tool calls.
|
|
188
|
-
|
|
236
|
+
Content larger than ${getWriteContentMaxSizeKB(preferenceService)}KB is rejected.
|
|
237
|
+
CAUTION: Changes are applied immediately and cannot be undone through the chat interface.`;
|
|
238
|
+
},
|
|
189
239
|
parameters: {
|
|
190
240
|
type: 'object',
|
|
191
241
|
properties: {
|
|
@@ -217,11 +267,16 @@ export class WriteFileContent implements ToolProvider {
|
|
|
217
267
|
if (await this.fileReadTracker?.isStale(chatSessionId, uri)) {
|
|
218
268
|
return JSON.stringify({ error: staleFileError(path) });
|
|
219
269
|
}
|
|
270
|
+
const exists = await this.fileService.exists(uri);
|
|
271
|
+
const sizeError = writeContentSizeError(content, getWriteContentMaxSizeKB(this.preferenceService), exists, WRITE_FILE_REPLACEMENTS_ID);
|
|
272
|
+
if (sizeError) {
|
|
273
|
+
return JSON.stringify({ error: sizeError });
|
|
274
|
+
}
|
|
220
275
|
let type = 'modify';
|
|
221
276
|
if (content === '') {
|
|
222
277
|
type = 'delete';
|
|
223
278
|
}
|
|
224
|
-
if (!
|
|
279
|
+
if (!exists) {
|
|
225
280
|
type = 'add';
|
|
226
281
|
}
|
|
227
282
|
|
|
@@ -121,7 +121,7 @@ import { AiConfigurationPreferences } from '../common/ai-configuration-preferenc
|
|
|
121
121
|
import { WorkspaceRestrictionContribution } from '@theia/workspace/lib/browser/workspace-trust-service';
|
|
122
122
|
import { AIWorkspaceRestrictionContribution } from './ai-workspace-restriction-contribution';
|
|
123
123
|
|
|
124
|
-
import {
|
|
124
|
+
import { AgentsMdAgent } from './agents-md-agent';
|
|
125
125
|
import { CreateSkillAgent } from './create-skill-agent';
|
|
126
126
|
import { SuggestTerminalCommand } from './ai-terminal-functions';
|
|
127
127
|
import { TodoWriteTool } from './todo-tool';
|
|
@@ -181,9 +181,9 @@ export default new ContainerModule((bind, _unbind, _isBound, rebind) => {
|
|
|
181
181
|
bind(Agent).toService(CoderAgent);
|
|
182
182
|
bind(ChatAgent).toService(CoderAgent);
|
|
183
183
|
|
|
184
|
-
bind(
|
|
185
|
-
bind(Agent).toService(
|
|
186
|
-
bind(ChatAgent).toService(
|
|
184
|
+
bind(AgentsMdAgent).toSelf().inSingletonScope();
|
|
185
|
+
bind(Agent).toService(AgentsMdAgent);
|
|
186
|
+
bind(ChatAgent).toService(AgentsMdAgent);
|
|
187
187
|
|
|
188
188
|
bind(CreateSkillAgent).toSelf().inSingletonScope();
|
|
189
189
|
bind(Agent).toService(CreateSkillAgent);
|
|
@@ -28,6 +28,7 @@ import { ScmRepository } from '@theia/scm/lib/browser/scm-repository';
|
|
|
28
28
|
import { ScmService } from '@theia/scm/lib/browser/scm-service';
|
|
29
29
|
import { ShellExecutionRequest, ShellExecutionResult, ShellExecutionServer } from '@theia/ai-terminal/lib/common/shell-execution-server';
|
|
30
30
|
import { GET_GIT_CHANGES_FUNCTION_ID, GetGitChangesTool, GitChangesRepositoryError } from './git-changes-tool';
|
|
31
|
+
import { withWorkspaceServiceDefaults } from '@theia/workspace/lib/browser/test/with-workspace-service-defaults';
|
|
31
32
|
|
|
32
33
|
disableJSDOM();
|
|
33
34
|
|
|
@@ -73,7 +74,7 @@ describe('GetGitChangesTool', () => {
|
|
|
73
74
|
};
|
|
74
75
|
container.bind(ShellExecutionServer).toConstantValue(shellServer as unknown as ShellExecutionServer);
|
|
75
76
|
container.bind(ScmService).toConstantValue(scmService as unknown as ScmService);
|
|
76
|
-
container.bind(WorkspaceService).toConstantValue(workspaceService as WorkspaceService);
|
|
77
|
+
container.bind(WorkspaceService).toConstantValue(withWorkspaceServiceDefaults(workspaceService as WorkspaceService));
|
|
77
78
|
container.bind(GetGitChangesTool).toSelf();
|
|
78
79
|
tool = container.get(GetGitChangesTool);
|
|
79
80
|
});
|
|
@@ -142,6 +143,20 @@ describe('GetGitChangesTool', () => {
|
|
|
142
143
|
expect(cwdOfCall()).to.equal('/work/frontend/vendor/lib');
|
|
143
144
|
});
|
|
144
145
|
|
|
146
|
+
it('labels the repositories of workspace roots sharing a folder name by their unique root names', async () => {
|
|
147
|
+
const aliceApp = makeRepo('file:///alice/app');
|
|
148
|
+
const bobApp = makeRepo('file:///bob/app');
|
|
149
|
+
workspaceRoots = [new URI('file:///alice/app'), new URI('file:///bob/app')];
|
|
150
|
+
scmService.repositories = [aliceApp, bobApp];
|
|
151
|
+
|
|
152
|
+
const result = await tool.getTool().handler(JSON.stringify({ repository: 'app' })) as GitChangesRepositoryError;
|
|
153
|
+
expect(result.error).to.contain('ambiguous');
|
|
154
|
+
expect(result.availableRepositories).to.deep.equal(['alice/app', 'bob/app']);
|
|
155
|
+
|
|
156
|
+
await tool.getTool().handler(JSON.stringify({ repository: 'bob/app' }));
|
|
157
|
+
expect(cwdOfCall()).to.equal('/bob/app');
|
|
158
|
+
});
|
|
159
|
+
|
|
145
160
|
it('prefers an exact label match over a folder name shared with a nested repository', async () => {
|
|
146
161
|
const nestedBackend = makeRepo('file:///work/frontend/backend');
|
|
147
162
|
scmService.repositories = [backend, frontend, nestedBackend];
|
|
@@ -216,20 +216,16 @@ export class GetGitChangesTool extends PredefinedShellTool {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
|
-
* Identifies a repository by the path of its root relative to the workspace,
|
|
220
|
-
* is usable as the `repository`
|
|
221
|
-
*
|
|
219
|
+
* Identifies a repository by the path of its root relative to the workspace, in the format of the
|
|
220
|
+
* workspace tools (`<rootName>/<relativePath>`), so that the label is usable as the `repository`
|
|
221
|
+
* argument of a follow-up call. Root names are unique, also for roots sharing a folder name.
|
|
222
222
|
*/
|
|
223
223
|
protected repositoryLabel(repository: ScmRepository): string {
|
|
224
224
|
const root = new URI(repository.provider.rootUri);
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
const relative = workspaceRoot.resource.relative(root)?.toString();
|
|
230
|
-
return relative ? `${workspaceRoot.resource.path.base}/${relative}` : workspaceRoot.resource.path.base;
|
|
225
|
+
if (!this.workspaceService.getWorkspaceRootUri(root)) {
|
|
226
|
+
return root.path.base;
|
|
231
227
|
}
|
|
232
|
-
return
|
|
228
|
+
return this.workspaceService.getRootPrefixedPath(root);
|
|
233
229
|
}
|
|
234
230
|
|
|
235
231
|
/** Path separators and case differ across platforms and between user phrasings. */
|