@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.
Files changed (190) hide show
  1. package/lib/browser/{project-info-agent.d.ts → agents-md-agent.d.ts} +2 -2
  2. package/lib/browser/agents-md-agent.d.ts.map +1 -0
  3. package/lib/browser/{project-info-agent.js → agents-md-agent.js} +16 -15
  4. package/lib/browser/agents-md-agent.js.map +1 -0
  5. package/lib/browser/ai-configuration/ai-configuration-label-provider-contribution.js +1 -1
  6. package/lib/browser/ai-configuration/ai-configuration-label-provider-contribution.js.map +1 -1
  7. package/lib/browser/ai-configuration/ai-configuration-resource.js +2 -1
  8. package/lib/browser/ai-configuration/ai-configuration-resource.js.map +1 -1
  9. package/lib/browser/ai-configuration/ai-configuration-search-widget.js +1 -1
  10. package/lib/browser/ai-configuration/ai-configuration-search-widget.js.map +1 -1
  11. package/lib/browser/ai-configuration/categories/agent-capabilities-settings.d.ts +11 -3
  12. package/lib/browser/ai-configuration/categories/agent-capabilities-settings.d.ts.map +1 -1
  13. package/lib/browser/ai-configuration/categories/agent-capabilities-settings.js +64 -29
  14. package/lib/browser/ai-configuration/categories/agent-capabilities-settings.js.map +1 -1
  15. package/lib/browser/ai-configuration/categories/agent-capabilities-settings.spec.js +480 -1
  16. package/lib/browser/ai-configuration/categories/agent-capabilities-settings.spec.js.map +1 -1
  17. package/lib/browser/ai-configuration/categories/agent-detail-model.d.ts +10 -0
  18. package/lib/browser/ai-configuration/categories/agent-detail-model.d.ts.map +1 -1
  19. package/lib/browser/ai-configuration/categories/agent-detail-model.js +8 -0
  20. package/lib/browser/ai-configuration/categories/agent-detail-model.js.map +1 -1
  21. package/lib/browser/ai-configuration/categories/agent-detail-model.spec.d.ts +2 -0
  22. package/lib/browser/ai-configuration/categories/agent-detail-model.spec.d.ts.map +1 -0
  23. package/lib/browser/ai-configuration/categories/agent-detail-model.spec.js +74 -0
  24. package/lib/browser/ai-configuration/categories/agent-detail-model.spec.js.map +1 -0
  25. package/lib/browser/ai-configuration/categories/agent-detail-view.d.ts.map +1 -1
  26. package/lib/browser/ai-configuration/categories/agent-detail-view.js +3 -2
  27. package/lib/browser/ai-configuration/categories/agent-detail-view.js.map +1 -1
  28. package/lib/browser/ai-configuration/categories/agents-configuration-category.d.ts +6 -1
  29. package/lib/browser/ai-configuration/categories/agents-configuration-category.d.ts.map +1 -1
  30. package/lib/browser/ai-configuration/categories/agents-configuration-category.js +20 -2
  31. package/lib/browser/ai-configuration/categories/agents-configuration-category.js.map +1 -1
  32. package/lib/browser/ai-configuration/categories/provider-model-discovery-section.js +5 -4
  33. package/lib/browser/ai-configuration/categories/provider-model-discovery-section.js.map +1 -1
  34. package/lib/browser/ai-configuration/categories/provider-model-discovery-section.spec.js +2 -1
  35. package/lib/browser/ai-configuration/categories/provider-model-discovery-section.spec.js.map +1 -1
  36. package/lib/browser/ai-configuration/categories/token-usage-configuration-category.js +2 -2
  37. package/lib/browser/ai-configuration/categories/token-usage-configuration-category.js.map +1 -1
  38. package/lib/browser/ai-configuration/categories/tools-configuration-category.js +1 -1
  39. package/lib/browser/ai-configuration/categories/tools-configuration-category.js.map +1 -1
  40. package/lib/browser/ai-configuration/categories/variables-configuration-category.js +1 -1
  41. package/lib/browser/ai-configuration/categories/variables-configuration-category.js.map +1 -1
  42. package/lib/browser/ai-configuration/language-model-renderer.d.ts.map +1 -1
  43. package/lib/browser/ai-configuration/language-model-renderer.js +8 -15
  44. package/lib/browser/ai-configuration/language-model-renderer.js.map +1 -1
  45. package/lib/browser/ai-configuration/language-model-renderer.spec.js +40 -1
  46. package/lib/browser/ai-configuration/language-model-renderer.spec.js.map +1 -1
  47. package/lib/browser/ai-sessions-widget.js +1 -1
  48. package/lib/browser/ai-sessions-widget.js.map +1 -1
  49. package/lib/browser/app-tester-prompt-template.d.ts.map +1 -1
  50. package/lib/browser/app-tester-prompt-template.js +4 -6
  51. package/lib/browser/app-tester-prompt-template.js.map +1 -1
  52. package/lib/browser/architect-prompt-template.d.ts.map +1 -1
  53. package/lib/browser/architect-prompt-template.js +20 -3
  54. package/lib/browser/architect-prompt-template.js.map +1 -1
  55. package/lib/browser/chat-session-item.js +2 -1
  56. package/lib/browser/chat-session-item.js.map +1 -1
  57. package/lib/browser/chat-sessions-welcome-message-provider.js +1 -1
  58. package/lib/browser/chat-sessions-welcome-message-provider.js.map +1 -1
  59. package/lib/browser/code-reviewer-prompt-template.d.ts.map +1 -1
  60. package/lib/browser/code-reviewer-prompt-template.js +2 -1
  61. package/lib/browser/code-reviewer-prompt-template.js.map +1 -1
  62. package/lib/browser/commit-message-agent.spec.js +2 -1
  63. package/lib/browser/commit-message-agent.spec.js.map +1 -1
  64. package/lib/browser/commit-message-runner.spec.js +2 -1
  65. package/lib/browser/commit-message-runner.spec.js.map +1 -1
  66. package/lib/browser/context-file-validation-service-impl.spec.js +2 -1
  67. package/lib/browser/context-file-validation-service-impl.spec.js.map +1 -1
  68. package/lib/browser/explore-prompt-template.d.ts.map +1 -1
  69. package/lib/browser/explore-prompt-template.js +2 -1
  70. package/lib/browser/explore-prompt-template.js.map +1 -1
  71. package/lib/browser/file-changeset-functions.d.ts +3 -1
  72. package/lib/browser/file-changeset-functions.d.ts.map +1 -1
  73. package/lib/browser/file-changeset-functions.js +60 -6
  74. package/lib/browser/file-changeset-functions.js.map +1 -1
  75. package/lib/browser/file-changeset-functions.spec.js +73 -9
  76. package/lib/browser/file-changeset-functions.spec.js.map +1 -1
  77. package/lib/browser/frontend-module.js +4 -4
  78. package/lib/browser/frontend-module.js.map +1 -1
  79. package/lib/browser/git-changes-tool.d.ts +3 -3
  80. package/lib/browser/git-changes-tool.d.ts.map +1 -1
  81. package/lib/browser/git-changes-tool.js +7 -11
  82. package/lib/browser/git-changes-tool.js.map +1 -1
  83. package/lib/browser/git-changes-tool.spec.js +16 -3
  84. package/lib/browser/git-changes-tool.spec.js.map +1 -1
  85. package/lib/browser/multi-root-paths.spec.d.ts +2 -0
  86. package/lib/browser/multi-root-paths.spec.d.ts.map +1 -0
  87. package/lib/browser/multi-root-paths.spec.js +293 -0
  88. package/lib/browser/multi-root-paths.spec.js.map +1 -0
  89. package/lib/browser/remember-command-contribution.d.ts +2 -2
  90. package/lib/browser/remember-command-contribution.js +6 -6
  91. package/lib/browser/remember-command-contribution.js.map +1 -1
  92. package/lib/browser/review/pr-review-prompt-template.d.ts.map +1 -1
  93. package/lib/browser/review/pr-review-prompt-template.js +3 -2
  94. package/lib/browser/review/pr-review-prompt-template.js.map +1 -1
  95. package/lib/browser/task-context-file-storage-service.d.ts.map +1 -1
  96. package/lib/browser/task-context-file-storage-service.js +1 -2
  97. package/lib/browser/task-context-file-storage-service.js.map +1 -1
  98. package/lib/browser/task-context-file-storage-service.spec.d.ts +2 -0
  99. package/lib/browser/task-context-file-storage-service.spec.d.ts.map +1 -0
  100. package/lib/browser/task-context-file-storage-service.spec.js +111 -0
  101. package/lib/browser/task-context-file-storage-service.spec.js.map +1 -0
  102. package/lib/browser/user-interaction-tool-renderer.js +1 -1
  103. package/lib/browser/user-interaction-tool-renderer.js.map +1 -1
  104. package/lib/browser/user-interaction-tool.d.ts +12 -1
  105. package/lib/browser/user-interaction-tool.d.ts.map +1 -1
  106. package/lib/browser/user-interaction-tool.js +35 -9
  107. package/lib/browser/user-interaction-tool.js.map +1 -1
  108. package/lib/browser/user-interaction-tool.spec.js +15 -2
  109. package/lib/browser/user-interaction-tool.spec.js.map +1 -1
  110. package/lib/browser/workspace-functions.d.ts +20 -17
  111. package/lib/browser/workspace-functions.d.ts.map +1 -1
  112. package/lib/browser/workspace-functions.js +77 -115
  113. package/lib/browser/workspace-functions.js.map +1 -1
  114. package/lib/browser/workspace-functions.spec.js +54 -60
  115. package/lib/browser/workspace-functions.spec.js.map +1 -1
  116. package/lib/browser/workspace-launch-provider.js +1 -1
  117. package/lib/browser/workspace-launch-provider.js.map +1 -1
  118. package/lib/browser/workspace-launch-provider.spec.js +5 -3
  119. package/lib/browser/workspace-launch-provider.spec.js.map +1 -1
  120. package/lib/browser/workspace-search-provider.spec.js +2 -1
  121. package/lib/browser/workspace-search-provider.spec.js.map +1 -1
  122. package/lib/browser/workspace-task-provider.js +1 -1
  123. package/lib/browser/workspace-task-provider.js.map +1 -1
  124. package/lib/browser/workspace-task-provider.spec.js +6 -4
  125. package/lib/browser/workspace-task-provider.spec.js.map +1 -1
  126. package/lib/common/agents-md-prompt-template.d.ts +6 -0
  127. package/lib/common/agents-md-prompt-template.d.ts.map +1 -0
  128. package/lib/common/agents-md-prompt-template.js +165 -0
  129. package/lib/common/agents-md-prompt-template.js.map +1 -0
  130. package/lib/common/coder-replace-prompt-template.d.ts.map +1 -1
  131. package/lib/common/coder-replace-prompt-template.js +4 -6
  132. package/lib/common/coder-replace-prompt-template.js.map +1 -1
  133. package/lib/common/command-prompt-template.js +1 -1
  134. package/lib/common/command-prompt-template.js.map +1 -1
  135. package/lib/common/orchestrator-prompt-template.js +1 -1
  136. package/lib/common/orchestrator-prompt-template.js.map +1 -1
  137. package/lib/common/universal-prompt-template.js +1 -1
  138. package/lib/common/universal-prompt-template.js.map +1 -1
  139. package/lib/common/workspace-preferences.d.ts +1 -0
  140. package/lib/common/workspace-preferences.d.ts.map +1 -1
  141. package/lib/common/workspace-preferences.js +10 -1
  142. package/lib/common/workspace-preferences.js.map +1 -1
  143. package/lib/package.spec.js +1 -0
  144. package/lib/package.spec.js.map +1 -1
  145. package/package.json +27 -28
  146. package/src/browser/{project-info-agent.ts → agents-md-agent.ts} +11 -10
  147. package/src/browser/ai-configuration/categories/agent-capabilities-settings.spec.ts +508 -2
  148. package/src/browser/ai-configuration/categories/agent-capabilities-settings.tsx +92 -33
  149. package/src/browser/ai-configuration/categories/agent-detail-model.spec.ts +78 -0
  150. package/src/browser/ai-configuration/categories/agent-detail-model.ts +18 -0
  151. package/src/browser/ai-configuration/categories/agent-detail-view.tsx +15 -12
  152. package/src/browser/ai-configuration/categories/agents-configuration-category.tsx +18 -3
  153. package/src/browser/ai-configuration/categories/provider-model-discovery-section.tsx +3 -3
  154. package/src/browser/ai-configuration/categories/token-usage-configuration-category.tsx +2 -2
  155. package/src/browser/ai-configuration/language-model-renderer.spec.ts +38 -0
  156. package/src/browser/ai-configuration/language-model-renderer.tsx +6 -15
  157. package/src/browser/app-tester-prompt-template.ts +4 -7
  158. package/src/browser/architect-prompt-template.ts +4 -4
  159. package/src/browser/code-reviewer-prompt-template.ts +2 -2
  160. package/src/browser/context-file-validation-service-impl.spec.ts +2 -1
  161. package/src/browser/explore-prompt-template.ts +2 -2
  162. package/src/browser/file-changeset-functions.spec.ts +91 -9
  163. package/src/browser/file-changeset-functions.ts +62 -7
  164. package/src/browser/frontend-module.ts +4 -4
  165. package/src/browser/git-changes-tool.spec.ts +16 -1
  166. package/src/browser/git-changes-tool.ts +6 -10
  167. package/src/browser/multi-root-paths.spec.ts +340 -0
  168. package/src/browser/remember-command-contribution.ts +7 -7
  169. package/src/browser/review/pr-review-prompt-template.ts +3 -3
  170. package/src/browser/style/index.css +15 -0
  171. package/src/browser/task-context-file-storage-service.spec.ts +125 -0
  172. package/src/browser/task-context-file-storage-service.ts +3 -4
  173. package/src/browser/user-interaction-tool.spec.ts +18 -1
  174. package/src/browser/user-interaction-tool.ts +34 -9
  175. package/src/browser/workspace-functions.spec.ts +54 -60
  176. package/src/browser/workspace-functions.ts +80 -125
  177. package/src/browser/workspace-launch-provider.spec.ts +3 -2
  178. package/src/browser/workspace-task-provider.spec.ts +4 -3
  179. package/src/common/{project-info-prompt-template.ts → agents-md-prompt-template.ts} +54 -46
  180. package/src/common/coder-replace-prompt-template.ts +5 -7
  181. package/src/common/command-prompt-template.ts +1 -1
  182. package/src/common/orchestrator-prompt-template.ts +1 -1
  183. package/src/common/universal-prompt-template.ts +1 -1
  184. package/src/common/workspace-preferences.ts +10 -0
  185. package/lib/browser/project-info-agent.d.ts.map +0 -1
  186. package/lib/browser/project-info-agent.js.map +0 -1
  187. package/lib/common/project-info-prompt-template.d.ts +0 -6
  188. package/lib/common/project-info-prompt-template.d.ts.map +0 -1
  189. package/lib/common/project-info-prompt-template.js +0 -146
  190. 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:project-info}}
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
- uri: new URI('file:///workspace/test.txt'),
104
- type: 'modify',
105
- state: 'pending',
106
- targetState: 'new content',
107
- apply: async () => { },
108
- } as ChangeSetFileElement);
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
- description: `Proposes writing complete content to a file for user review. If the file exists, it will be overwritten with the provided content.
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 (!(await this.fileService.exists(uri))) {
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
- description: `Immediately writes complete content to a file WITHOUT user confirmation. If the file exists, it will be overwritten.
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
- CAUTION: Changes are applied immediately and cannot be undone through the chat interface.`,
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 (!(await this.fileService.exists(uri))) {
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 { ProjectInfoAgent } from './project-info-agent';
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(ProjectInfoAgent).toSelf().inSingletonScope();
185
- bind(Agent).toService(ProjectInfoAgent);
186
- bind(ChatAgent).toService(ProjectInfoAgent);
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, so that the label
220
- * is usable as the `repository` argument of a follow-up call. Workspace roots sharing a folder
221
- * name produce identical labels, which {@link findRepositories} reports as ambiguous.
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
- for (const workspaceRoot of this.workspaceService.tryGetRoots()) {
226
- if (!workspaceRoot.resource.isEqualOrParent(root)) {
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 root.path.base;
228
+ return this.workspaceService.getRootPrefixedPath(root);
233
229
  }
234
230
 
235
231
  /** Path separators and case differ across platforms and between user phrasings. */