@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
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 STMicroelectronics and others.
|
|
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 { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
|
|
18
|
+
let disableJSDOM = enableJSDOM();
|
|
19
|
+
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
20
|
+
FrontendApplicationConfigProvider.set({});
|
|
21
|
+
|
|
22
|
+
import { expect } from 'chai';
|
|
23
|
+
import { ILogger, OS, PreferenceService } from '@theia/core';
|
|
24
|
+
import { URI } from '@theia/core/lib/common/uri';
|
|
25
|
+
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
|
26
|
+
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
27
|
+
import { Container } from '@theia/core/shared/inversify';
|
|
28
|
+
import { AiConfigurationService } from '@theia/ai-core';
|
|
29
|
+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
30
|
+
import { FileSearchService } from '@theia/file-search/lib/common/file-search-service';
|
|
31
|
+
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
|
|
32
|
+
import { SearchInWorkspaceService, SearchInWorkspaceCallbacks } from '@theia/search-in-workspace/lib/browser/search-in-workspace-service';
|
|
33
|
+
import { SearchInWorkspaceResult } from '@theia/search-in-workspace/lib/common/search-in-workspace-interface';
|
|
34
|
+
import { ShellExecutionRequest, ShellExecutionServer } from '@theia/ai-terminal/lib/common/shell-execution-server';
|
|
35
|
+
import { ShellExecutionTool } from '@theia/ai-terminal/lib/browser/shell-execution-tool';
|
|
36
|
+
import { ShellCommandPermissionService } from '@theia/ai-terminal/lib/browser/shell-command-permission-service';
|
|
37
|
+
import { Minimatch } from 'minimatch';
|
|
38
|
+
import { FindFilesByPattern, GetWorkspaceFileList, WorkspaceFunctionScope } from './workspace-functions';
|
|
39
|
+
import { WorkspaceSearchProvider } from './workspace-search-provider';
|
|
40
|
+
|
|
41
|
+
disableJSDOM();
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Regression tests for https://github.com/eclipse-theia/theia/issues/17612: in a multi-root workspace,
|
|
45
|
+
* paths that one tool or variable emits must be accepted by the others and refer to the same file.
|
|
46
|
+
*
|
|
47
|
+
* The workspace roots, in workspace order:
|
|
48
|
+
* - `/ws/theia` and `/ws/other`: plain roots;
|
|
49
|
+
* - `/y/app` and `/x/app`: roots sharing a basename, listed so that workspace order differs from URI sort order;
|
|
50
|
+
* - `/ws/theia/packages/nested`: a root nested in `/ws/theia`.
|
|
51
|
+
*
|
|
52
|
+
* The `/ws/theia/other` folder is named like the `/ws/other` root.
|
|
53
|
+
*
|
|
54
|
+
* Where a fix may change how paths are displayed (e.g. `x/app/...` for a duplicate basename), the tests check
|
|
55
|
+
* that the output resolves back to the right file rather than asserting a particular string.
|
|
56
|
+
*/
|
|
57
|
+
describe('Multi-root path consistency (#17612)', () => {
|
|
58
|
+
|
|
59
|
+
const ROOTS = [
|
|
60
|
+
'file:///ws/theia',
|
|
61
|
+
'file:///ws/other',
|
|
62
|
+
'file:///y/app',
|
|
63
|
+
'file:///x/app',
|
|
64
|
+
'file:///ws/theia/packages/nested'
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
/** The files that exist, as found by a search in each root. */
|
|
68
|
+
const FILES = [
|
|
69
|
+
'file:///ws/theia/packages/core/a.ts',
|
|
70
|
+
'file:///ws/theia/other/c.md',
|
|
71
|
+
'file:///ws/theia/packages/nested/n.ts',
|
|
72
|
+
'file:///ws/other/b.ts',
|
|
73
|
+
'file:///x/app/shared.ts',
|
|
74
|
+
'file:///y/app/shared.ts',
|
|
75
|
+
'file:///y/app/only-here.ts'
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
let container: Container;
|
|
79
|
+
let workspaceService: WorkspaceService;
|
|
80
|
+
let workspaceScope: WorkspaceFunctionScope;
|
|
81
|
+
|
|
82
|
+
let originalIsWindows: boolean;
|
|
83
|
+
before(() => {
|
|
84
|
+
disableJSDOM = enableJSDOM();
|
|
85
|
+
});
|
|
86
|
+
after(() => {
|
|
87
|
+
disableJSDOM();
|
|
88
|
+
});
|
|
89
|
+
beforeEach(() => {
|
|
90
|
+
// Paths are rendered with `Path.fsPath()`, which branches on the backend OS.
|
|
91
|
+
originalIsWindows = OS.backend.isWindows;
|
|
92
|
+
OS.backend.isWindows = false;
|
|
93
|
+
});
|
|
94
|
+
afterEach(() => {
|
|
95
|
+
OS.backend.isWindows = originalIsWindows;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/** Mimics ripgrep: the files under the requested root that match the include and not the exclude globs, relative to that root. */
|
|
99
|
+
const makeFileSearchService = (files = FILES): FileSearchService => ({
|
|
100
|
+
find: async (_searchPattern: string, options: FileSearchService.Options) => {
|
|
101
|
+
const rootUri = new URI(options.rootUris![0]);
|
|
102
|
+
const includes = (options.includePatterns ?? []).map(pattern => new Minimatch(pattern, { dot: true }));
|
|
103
|
+
const excludes = (options.excludePatterns ?? []).map(pattern => new Minimatch(pattern, { dot: true }));
|
|
104
|
+
return files.filter(file => {
|
|
105
|
+
const relativePath = rootUri.relative(new URI(file))?.toString();
|
|
106
|
+
return relativePath !== undefined
|
|
107
|
+
&& (includes.length === 0 || includes.some(matcher => matcher.match(relativePath)))
|
|
108
|
+
&& !excludes.some(matcher => matcher.match(relativePath));
|
|
109
|
+
}).slice(0, options.limit);
|
|
110
|
+
}
|
|
111
|
+
} as unknown as FileSearchService);
|
|
112
|
+
|
|
113
|
+
/** Reports a match in every file under the searched roots. */
|
|
114
|
+
const makeSearchInWorkspaceService = (searchedRoots: string[][]): SearchInWorkspaceService => ({
|
|
115
|
+
searchWithCallback: async (_query: string, rootUris: string[], callbacks: SearchInWorkspaceCallbacks) => {
|
|
116
|
+
searchedRoots.push(rootUris);
|
|
117
|
+
const searchId = 1;
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
for (const file of FILES) {
|
|
120
|
+
if (rootUris.some(root => new URI(root).isEqualOrParent(new URI(file)))) {
|
|
121
|
+
const result: SearchInWorkspaceResult = { root: '', fileUri: file, matches: [{ line: 1, character: 1, length: 1, lineText: 'match' }] };
|
|
122
|
+
callbacks.onResult(searchId, result);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
callbacks.onDone(searchId);
|
|
126
|
+
});
|
|
127
|
+
return searchId;
|
|
128
|
+
},
|
|
129
|
+
cancel: () => { }
|
|
130
|
+
} as unknown as SearchInWorkspaceService);
|
|
131
|
+
|
|
132
|
+
beforeEach(() => {
|
|
133
|
+
container = new Container();
|
|
134
|
+
|
|
135
|
+
// A real `WorkspaceService` prototype, so that `getRootPrefixedPath` (used by the chat variables) is the production code.
|
|
136
|
+
workspaceService = Object.create(WorkspaceService.prototype, {
|
|
137
|
+
tryGetRoots: { value: () => ROOTS.map(root => ({ resource: new URI(root), isDirectory: true })) },
|
|
138
|
+
onWorkspaceChanged: { value: () => ({ dispose: () => { } }) }
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const fileService = {
|
|
142
|
+
exists: async (uri: URI) => FILES.includes(uri.toString()) || ROOTS.includes(uri.toString()),
|
|
143
|
+
resolve: async (uri: URI) => ({ isDirectory: !FILES.includes(uri.toString()), children: [], resource: uri })
|
|
144
|
+
} as unknown as FileService;
|
|
145
|
+
|
|
146
|
+
const aiConfigurationService = {
|
|
147
|
+
get: <T>(_name: string, fallback?: T) => fallback,
|
|
148
|
+
ready: Promise.resolve(),
|
|
149
|
+
onDidChangeTrust: () => ({ dispose: () => { } })
|
|
150
|
+
} as unknown as AiConfigurationService;
|
|
151
|
+
|
|
152
|
+
const envVariablesServer = {
|
|
153
|
+
getHomeDirUri: async () => 'file:///home/test'
|
|
154
|
+
} as unknown as EnvVariablesServer;
|
|
155
|
+
|
|
156
|
+
container.bind(ILogger).to(MockLogger);
|
|
157
|
+
container.bind(WorkspaceService).toConstantValue(workspaceService);
|
|
158
|
+
container.bind(FileService).toConstantValue(fileService);
|
|
159
|
+
container.bind(PreferenceService).toConstantValue({ get: <T>(_path: string, defaultValue: T) => defaultValue });
|
|
160
|
+
container.bind(AiConfigurationService).toConstantValue(aiConfigurationService);
|
|
161
|
+
container.bind(EnvVariablesServer).toConstantValue(envVariablesServer);
|
|
162
|
+
container.bind(FileSearchService).toConstantValue(makeFileSearchService());
|
|
163
|
+
container.bind(WorkspaceFunctionScope).toSelf().inSingletonScope();
|
|
164
|
+
container.bind(FindFilesByPattern).toSelf();
|
|
165
|
+
container.bind(GetWorkspaceFileList).toSelf();
|
|
166
|
+
|
|
167
|
+
workspaceScope = container.get(WorkspaceFunctionScope);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const resolve = async (path: string): Promise<string> => (await workspaceScope.resolveAccessiblePath(path)).toString();
|
|
171
|
+
|
|
172
|
+
const findFiles = async (args: object): Promise<{ files?: string[]; truncated?: boolean; error?: string }> =>
|
|
173
|
+
JSON.parse(await container.get(FindFilesByPattern).getTool().handler(JSON.stringify(args), undefined) as string);
|
|
174
|
+
|
|
175
|
+
describe('findFilesByPattern', () => {
|
|
176
|
+
|
|
177
|
+
it('accepts a root-prefixed glob, as returned in its own results (B1)', async () => {
|
|
178
|
+
const result = await findFiles({ pattern: 'theia/packages/core/**/*.ts' });
|
|
179
|
+
expect(result.files).to.have.length(1);
|
|
180
|
+
expect(await resolve(result.files![0])).to.equal('file:///ws/theia/packages/core/a.ts');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('finds a file that exists only in the second root of a duplicate basename (A1)', async () => {
|
|
184
|
+
const result = await findFiles({ pattern: '**/only-here.ts' });
|
|
185
|
+
expect(result.files).to.have.length(1);
|
|
186
|
+
expect(await resolve(result.files![0])).to.equal('file:///y/app/only-here.ts');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('returns paths that resolve to distinct files for roots sharing a basename (A1, A2)', async () => {
|
|
190
|
+
const result = await findFiles({ pattern: '**/shared.ts' });
|
|
191
|
+
const resolved = await Promise.all((result.files ?? []).map(resolve));
|
|
192
|
+
expect(resolved).to.have.members(['file:///x/app/shared.ts', 'file:///y/app/shared.ts']);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('returns paths that resolve back to the file when searchRoot is in the workspace (B2)', async () => {
|
|
196
|
+
const result = await findFiles({ pattern: '**/*.ts', searchRoot: 'theia/packages/core' });
|
|
197
|
+
expect(result.error).to.be.undefined;
|
|
198
|
+
expect(result.files).to.have.length(1);
|
|
199
|
+
expect(await resolve(result.files![0])).to.equal('file:///ws/theia/packages/core/a.ts');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('applies a root-prefixed exclude to that root only', async () => {
|
|
203
|
+
const result = await findFiles({ pattern: '**/shared.ts', exclude: ['x/app/**'] });
|
|
204
|
+
const resolved = await Promise.all((result.files ?? []).map(resolve));
|
|
205
|
+
expect(resolved).to.deep.equal(['file:///y/app/shared.ts']);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('includes files of a nested root when searching the outer root only', async () => {
|
|
209
|
+
const result = await findFiles({ pattern: 'theia/packages/**/*.ts' });
|
|
210
|
+
const resolved = await Promise.all((result.files ?? []).map(resolve));
|
|
211
|
+
expect(resolved).to.have.members(['file:///ws/theia/packages/core/a.ts', 'file:///ws/theia/packages/nested/n.ts']);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('searches a folder named like a root in every root', async () => {
|
|
215
|
+
const result = await findFiles({ pattern: 'other/**/*.md' });
|
|
216
|
+
const resolved = await Promise.all((result.files ?? []).map(resolve));
|
|
217
|
+
expect(resolved).to.deep.equal(['file:///ws/theia/other/c.md']);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('excludes a folder named like a root in every root', async () => {
|
|
221
|
+
const result = await findFiles({ pattern: '**/*.md', exclude: ['other/**'] });
|
|
222
|
+
expect(result.files).to.deep.equal([]);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('keeps the escapes of a root-prefixed glob', async () => {
|
|
226
|
+
const result = await findFiles({ pattern: 'theia/packages/core/\\*.ts' });
|
|
227
|
+
expect(result.files).to.deep.equal([]);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('reports a file in a nested root only once (C1)', async () => {
|
|
231
|
+
const result = await findFiles({ pattern: '**/n.ts' });
|
|
232
|
+
expect(result.files).to.have.length(1);
|
|
233
|
+
expect(await resolve(result.files![0])).to.equal('file:///ws/theia/packages/nested/n.ts');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('reports a file in a nested root that only the glob relative to the outer root matches', async () => {
|
|
237
|
+
const result = await findFiles({ pattern: 'packages/*/n.ts' });
|
|
238
|
+
const resolved = await Promise.all((result.files ?? []).map(resolve));
|
|
239
|
+
expect(resolved).to.deep.equal(['file:///ws/theia/packages/nested/n.ts']);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('reports truncated results when files of a nested root fill the limit of the outer root', async () => {
|
|
243
|
+
const nestedFiles = Array.from({ length: 250 }, (_, i) => `file:///ws/theia/packages/nested/f${i}.ts`);
|
|
244
|
+
container.rebind(FileSearchService).toConstantValue(makeFileSearchService([...nestedFiles, ...FILES]));
|
|
245
|
+
const result = await findFiles({ pattern: 'packages/**/*.ts' });
|
|
246
|
+
expect(result.files).to.have.length(200);
|
|
247
|
+
expect(result.truncated).to.be.true;
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('reports the files of a nested root once without truncating the results', async () => {
|
|
251
|
+
const nestedFiles = Array.from({ length: 150 }, (_, i) => `file:///ws/theia/packages/nested/f${i}.ts`);
|
|
252
|
+
container.rebind(FileSearchService).toConstantValue(makeFileSearchService([...nestedFiles, ...FILES]));
|
|
253
|
+
const result = await findFiles({ pattern: '**/*.ts' });
|
|
254
|
+
expect(result.files).to.have.length(nestedFiles.length + FILES.filter(file => file.endsWith('.ts')).length);
|
|
255
|
+
expect(new Set(result.files).size).to.equal(result.files!.length);
|
|
256
|
+
expect(result.truncated).to.be.undefined;
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe('getWorkspaceFileList', () => {
|
|
261
|
+
|
|
262
|
+
it('lists every workspace root at the top level (A1)', async () => {
|
|
263
|
+
const tool = container.get(GetWorkspaceFileList).getTool();
|
|
264
|
+
const result: Record<string, string> = JSON.parse(await tool.handler(JSON.stringify({ path: '' }), undefined) as string);
|
|
265
|
+
expect(Object.keys(result)).to.have.length(ROOTS.length);
|
|
266
|
+
const resolved = await Promise.all(Object.keys(result).map(resolve));
|
|
267
|
+
expect(resolved).to.have.members(ROOTS);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('searchInWorkspace', () => {
|
|
272
|
+
|
|
273
|
+
let searchedRoots: string[][];
|
|
274
|
+
|
|
275
|
+
beforeEach(() => {
|
|
276
|
+
searchedRoots = [];
|
|
277
|
+
container.bind(SearchInWorkspaceService).toConstantValue(makeSearchInWorkspaceService(searchedRoots));
|
|
278
|
+
container.bind(WorkspaceSearchProvider).toSelf();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('searches every workspace root (A1)', async () => {
|
|
282
|
+
const tool = container.get(WorkspaceSearchProvider).getTool();
|
|
283
|
+
const result: Array<{ file: string }> = JSON.parse(await tool.handler(JSON.stringify({ query: 'match', useRegExp: false }), undefined) as string);
|
|
284
|
+
|
|
285
|
+
expect(searchedRoots.flat()).to.include('file:///y/app');
|
|
286
|
+
const resolved = await Promise.all(result.map(entry => resolve(entry.file)));
|
|
287
|
+
expect(resolved).to.include('file:///y/app/only-here.ts');
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe('chat variable paths', () => {
|
|
292
|
+
|
|
293
|
+
it('resolve to the same file in the workspace tools, for every root (A2)', async () => {
|
|
294
|
+
// `getRootPrefixedPath` renders the paths of `#file`, `#openEditors`, `#changeSetSummary` and `#editorContext`.
|
|
295
|
+
for (const file of FILES) {
|
|
296
|
+
const displayed = workspaceService.getRootPrefixedPath(new URI(file));
|
|
297
|
+
expect(await resolve(displayed), `'${displayed}' for ${file}`).to.equal(file);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
describe('shellExecute', () => {
|
|
303
|
+
|
|
304
|
+
let executed: ShellExecutionRequest[];
|
|
305
|
+
|
|
306
|
+
beforeEach(() => {
|
|
307
|
+
executed = [];
|
|
308
|
+
const shellServer = {
|
|
309
|
+
execute: async (request: ShellExecutionRequest) => {
|
|
310
|
+
executed.push(request);
|
|
311
|
+
return { success: true, exitCode: 0, stdout: '', stderr: '', duration: 0, resolvedCwd: request.cwd };
|
|
312
|
+
},
|
|
313
|
+
cancel: async () => true
|
|
314
|
+
} as unknown as ShellExecutionServer;
|
|
315
|
+
container.bind(ShellExecutionServer).toConstantValue(shellServer);
|
|
316
|
+
container.bind(ShellCommandPermissionService).toConstantValue({} as ShellCommandPermissionService);
|
|
317
|
+
container.bind(ShellExecutionTool).toSelf();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const cwdFor = async (cwd: string): Promise<string | undefined> => {
|
|
321
|
+
await container.get(ShellExecutionTool).getTool().handler(JSON.stringify({ command: 'pwd', description: 'Print the working directory', cwd }), undefined);
|
|
322
|
+
return executed[executed.length - 1]?.cwd;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
it('resolves each root name to the same directory as the workspace tools (A3)', async () => {
|
|
326
|
+
for (const name of workspaceScope.getRootMapping().keys()) {
|
|
327
|
+
const expected = new URI(await resolve(name)).path.fsPath();
|
|
328
|
+
expect(await cwdFor(name), `cwd '${name}'`).to.equal(expected);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('accepts the directory forms that the workspace tools accept (D3)', async () => {
|
|
333
|
+
// Root-prefixed, parent-qualified (the only relative form that reaches a shadowed duplicate root) and URI.
|
|
334
|
+
for (const cwd of ['theia/packages', 'y/app', 'file:///ws/other']) {
|
|
335
|
+
const expected = new URI(await resolve(cwd)).path.fsPath();
|
|
336
|
+
expect(await cwdFor(cwd), `cwd '${cwd}'`).to.equal(expected);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
});
|
|
@@ -18,7 +18,7 @@ import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
|
18
18
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
19
|
import { PromptService } from '@theia/ai-core/lib/common';
|
|
20
20
|
import { nls } from '@theia/core';
|
|
21
|
-
import { AGENT_DELEGATION_FUNCTION_ID } from '@theia/ai-core';
|
|
21
|
+
import { AGENT_DELEGATION_FUNCTION_ID, AGENTS_MD_FILE_NAME } from '@theia/ai-core';
|
|
22
22
|
import { ArchitectAgentId } from './architect-agent';
|
|
23
23
|
import { CoderAgentId } from './coder-agent';
|
|
24
24
|
|
|
@@ -26,8 +26,8 @@ import { CoderAgentId } from './coder-agent';
|
|
|
26
26
|
* Contribution that registers the `/remember` slash command for AI chat agents.
|
|
27
27
|
*
|
|
28
28
|
* This command allows Architect and Coder agents to extract important topics
|
|
29
|
-
* from the current conversation and delegate to the
|
|
30
|
-
* the
|
|
29
|
+
* from the current conversation and delegate to the AgentsMd agent to update
|
|
30
|
+
* the workspace's `AGENTS.md`.
|
|
31
31
|
*/
|
|
32
32
|
@injectable()
|
|
33
33
|
export class RememberCommandContribution implements FrontendApplicationContribution {
|
|
@@ -89,9 +89,9 @@ export class RememberCommandContribution implements FrontendApplicationContribut
|
|
|
89
89
|
- What the user corrected or clarified
|
|
90
90
|
- Why your initial understanding was incomplete
|
|
91
91
|
- The specific project context that was provided
|
|
92
|
-
3. **Delegate to
|
|
93
|
-
- Agent ID: '
|
|
94
|
-
- Prompt: Ask the
|
|
92
|
+
3. **Delegate to the AgentsMd agent**: Use the ~{${AGENT_DELEGATION_FUNCTION_ID}} tool to send the extracted information to the AgentsMd agent:
|
|
93
|
+
- Agent ID: 'AgentsMd'
|
|
94
|
+
- Prompt: Ask the AgentsMd agent to review the extracted information and update the project context file
|
|
95
95
|
|
|
96
96
|
## Example Delegation
|
|
97
97
|
\`\`\`
|
|
@@ -99,7 +99,7 @@ export class RememberCommandContribution implements FrontendApplicationContribut
|
|
|
99
99
|
|
|
100
100
|
[Your extracted corrections and user-provided context here]
|
|
101
101
|
|
|
102
|
-
Update
|
|
102
|
+
Update ${AGENTS_MD_FILE_NAME} by adding this information to the appropriate sections. Focus on information that prevents future misunderstandings.
|
|
103
103
|
\`\`\`
|
|
104
104
|
|
|
105
105
|
Remember: Only extract information that prevents future AI agents from making the same mistakes or assumptions you made that were corrected by the user.`;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
16
|
// *****************************************************************************
|
|
17
17
|
|
|
18
|
-
import { BasePromptFragment } from '@theia/ai-core/lib/common';
|
|
18
|
+
import { AGENTS_MD_FILE_NAME, AGENTS_MD_PROMPT_FRAGMENT_ID, BasePromptFragment } from '@theia/ai-core/lib/common';
|
|
19
19
|
import { CONTEXT_FILES_VARIABLE_ID, TASK_CONTEXT_SUMMARY_VARIABLE_ID } from '../../common/context-variables';
|
|
20
20
|
import {
|
|
21
21
|
FILE_CONTENT_FUNCTION_ID,
|
|
@@ -246,7 +246,7 @@ Review with both goals in mind.
|
|
|
246
246
|
**Second, surface issues (this drives the Findings):**
|
|
247
247
|
- **Correctness:** Does the code do what it claims?
|
|
248
248
|
- **Style consistency:** Does it follow existing patterns from the exploration findings (Phase 5)?
|
|
249
|
-
- **Project guidelines:** Does it adhere to rules
|
|
249
|
+
- **Project guidelines:** Does it adhere to the rules in the project's \`${AGENTS_MD_FILE_NAME}\`, if the Project Context section lists one (e.g., coding conventions, preferred APIs, DI patterns)?
|
|
250
250
|
- **Potential bugs:** Race conditions, edge cases, error handling
|
|
251
251
|
- **Missing tests:** Are behavior changes covered by tests?
|
|
252
252
|
- **Security:** Any vulnerabilities introduced?
|
|
@@ -493,7 +493,7 @@ Where a Mermaid diagram is genuinely useful, use one, for example to explain arc
|
|
|
493
493
|
|
|
494
494
|
{{${CONTEXT_FILES_VARIABLE_ID}}}
|
|
495
495
|
|
|
496
|
-
{{prompt
|
|
496
|
+
{{prompt:${AGENTS_MD_PROMPT_FRAGMENT_ID}}}
|
|
497
497
|
|
|
498
498
|
{{${TASK_CONTEXT_SUMMARY_VARIABLE_ID}}}
|
|
499
499
|
`
|
|
@@ -1720,6 +1720,21 @@ button.agent-chip:focus-visible {
|
|
|
1720
1720
|
margin-left: auto;
|
|
1721
1721
|
}
|
|
1722
1722
|
|
|
1723
|
+
/* A second action sits right next to the first instead of splitting the free space with it. */
|
|
1724
|
+
.ai-agent-section-header .ai-agent-section-header-action + .ai-configuration-icon-button {
|
|
1725
|
+
margin-left: 0;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
/* The chat input's capabilities tree, embedded in the agent detail; capped so an expanded tree scrolls
|
|
1729
|
+
within the section instead of pushing the rest of the page away. */
|
|
1730
|
+
.ai-agent-generic-capabilities-editor .theia-GenericCapabilities-Tree-Content {
|
|
1731
|
+
max-height: 300px;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
.ai-agent-generic-capabilities-editor {
|
|
1735
|
+
margin-bottom: var(--theia-ui-padding);
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1723
1738
|
.ai-agent-description {
|
|
1724
1739
|
margin-bottom: calc(var(--theia-ui-padding) * 2);
|
|
1725
1740
|
color: var(--theia-descriptionForeground);
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 Safi Seid-Ahmad, K2view and others.
|
|
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 { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
|
|
18
|
+
const disableJSDOM = enableJSDOM();
|
|
19
|
+
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
20
|
+
FrontendApplicationConfigProvider.set({});
|
|
21
|
+
import { expect } from 'chai';
|
|
22
|
+
import { Container } from '@theia/core/shared/inversify';
|
|
23
|
+
import { Disposable, Event, ILogger, PreferenceService, URI } from '@theia/core';
|
|
24
|
+
import { OpenerService } from '@theia/core/lib/browser';
|
|
25
|
+
import { BinaryBuffer } from '@theia/core/lib/common/buffer';
|
|
26
|
+
import { AIVariableResourceResolver } from '@theia/ai-core';
|
|
27
|
+
import { InMemoryTaskContextStorage } from '@theia/ai-chat/lib/browser/task-context-storage-service';
|
|
28
|
+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
29
|
+
import { WorkspaceService } from '@theia/workspace/lib/browser';
|
|
30
|
+
import { TaskContextFileStorageService } from './task-context-file-storage-service';
|
|
31
|
+
disableJSDOM();
|
|
32
|
+
|
|
33
|
+
const workspaceRoot = new URI('file:///workspace');
|
|
34
|
+
const storageLocation = workspaceRoot.resolve('.prompts/task-contexts');
|
|
35
|
+
|
|
36
|
+
describe('TaskContextFileStorageService', () => {
|
|
37
|
+
|
|
38
|
+
let files: Map<string, string>;
|
|
39
|
+
let container: Container;
|
|
40
|
+
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
files = new Map();
|
|
43
|
+
container = new Container();
|
|
44
|
+
container.bind(FileService).toConstantValue({
|
|
45
|
+
watch: () => Disposable.NULL,
|
|
46
|
+
onDidFilesChange: () => Disposable.NULL,
|
|
47
|
+
resolve: async (uri: URI) => ({
|
|
48
|
+
children: [...files.keys()].map(key => new URI(key)).filter(resource => uri.isEqualOrParent(resource)).map(resource => ({ resource }))
|
|
49
|
+
}),
|
|
50
|
+
read: async (uri: URI) => {
|
|
51
|
+
const value = files.get(uri.toString());
|
|
52
|
+
if (value === undefined) {
|
|
53
|
+
throw new Error(`No file at ${uri}`);
|
|
54
|
+
}
|
|
55
|
+
return { value };
|
|
56
|
+
},
|
|
57
|
+
writeFile: async (uri: URI, content: BinaryBuffer) => {
|
|
58
|
+
files.set(uri.toString(), content.toString());
|
|
59
|
+
}
|
|
60
|
+
} as unknown as FileService);
|
|
61
|
+
container.bind(WorkspaceService).toConstantValue({
|
|
62
|
+
opened: true,
|
|
63
|
+
ready: Promise.resolve(),
|
|
64
|
+
tryGetRoots: () => [{ resource: workspaceRoot }]
|
|
65
|
+
} as unknown as WorkspaceService);
|
|
66
|
+
container.bind(PreferenceService).toConstantValue({
|
|
67
|
+
ready: Promise.resolve(),
|
|
68
|
+
inspect: () => ({ defaultValue: '.prompts/task-contexts' }),
|
|
69
|
+
onPreferenceChanged: () => Disposable.NULL
|
|
70
|
+
} as unknown as PreferenceService);
|
|
71
|
+
container.bind(ILogger).toConstantValue({ error: () => { } } as unknown as ILogger);
|
|
72
|
+
container.bind(OpenerService).toConstantValue({} as OpenerService);
|
|
73
|
+
container.bind(AIVariableResourceResolver).toConstantValue({} as AIVariableResourceResolver);
|
|
74
|
+
container.bind(InMemoryTaskContextStorage).toSelf().inSingletonScope();
|
|
75
|
+
container.bind(TaskContextFileStorageService).toSelf().inSingletonScope();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/** Creates the service and waits for its startup scan to load the files already in the storage location. */
|
|
79
|
+
const loadStoredFiles = async (): Promise<TaskContextFileStorageService> => {
|
|
80
|
+
const service = container.get(TaskContextFileStorageService);
|
|
81
|
+
await Event.toPromise(service.onDidChange);
|
|
82
|
+
return service;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
it('writes the metadata as standard frontmatter', async () => {
|
|
86
|
+
const service = container.get(TaskContextFileStorageService);
|
|
87
|
+
await service.store({ id: 'task-1', sessionId: 'session-1', label: 'Fix the build', summary: '# Plan\n\nDo it.' });
|
|
88
|
+
|
|
89
|
+
const content = files.get(storageLocation.resolve('Fix-the-build.md').toString());
|
|
90
|
+
expect(content).to.not.be.undefined;
|
|
91
|
+
const lines = content!.split('\n');
|
|
92
|
+
expect(lines[0]).to.equal('---');
|
|
93
|
+
expect(lines).to.include.members(['id: task-1', 'sessionId: session-1', 'label: Fix the build']);
|
|
94
|
+
expect(content).to.match(/\n---\n# Plan\n\nDo it\.$/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('reads back the body without the frontmatter', async () => {
|
|
98
|
+
const service = container.get(TaskContextFileStorageService);
|
|
99
|
+
await service.store({ id: 'task-1', label: 'Fix the build', summary: '# Plan\n\nDo it.' });
|
|
100
|
+
|
|
101
|
+
const summary = await service.get('task-1');
|
|
102
|
+
expect(summary?.summary).to.equal('# Plan\n\nDo it.');
|
|
103
|
+
expect(summary?.label).to.equal('Fix the build');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('still reads files written without the opening separator', async () => {
|
|
107
|
+
files.set(storageLocation.resolve('legacy.md').toString(), 'id: legacy-task\nlabel: Legacy task\n---\n# Legacy plan');
|
|
108
|
+
|
|
109
|
+
const service = await loadStoredFiles();
|
|
110
|
+
|
|
111
|
+
const summary = await service.get('legacy-task');
|
|
112
|
+
expect(summary?.label).to.equal('Legacy task');
|
|
113
|
+
expect(summary?.summary).to.equal('# Legacy plan');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('still reads files written without the opening separator and with CRLF line endings', async () => {
|
|
117
|
+
files.set(storageLocation.resolve('legacy.md').toString(), 'id: legacy-task\r\nlabel: Legacy task\r\n---\r\n# Legacy plan\r\n\r\nDo it.');
|
|
118
|
+
|
|
119
|
+
const service = await loadStoredFiles();
|
|
120
|
+
|
|
121
|
+
const summary = await service.get('legacy-task');
|
|
122
|
+
expect(summary?.label).to.equal('Legacy task');
|
|
123
|
+
expect(summary?.summary).to.equal('# Legacy plan\r\n\r\nDo it.');
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
|
|
17
17
|
import { Summary, SummaryMetadata, TaskContextStorageService } from '@theia/ai-chat/lib/browser/task-context-service';
|
|
18
18
|
import { InMemoryTaskContextStorage } from '@theia/ai-chat/lib/browser/task-context-storage-service';
|
|
19
|
-
import { parseFrontmatter } from '@theia/ai-core/lib/common/frontmatter';
|
|
19
|
+
import { parseFrontmatter, serializeFrontmatter } from '@theia/ai-core/lib/common/frontmatter';
|
|
20
20
|
import { inject, injectable, postConstruct, named } from '@theia/core/shared/inversify';
|
|
21
|
-
import { DisposableCollection,
|
|
21
|
+
import { DisposableCollection, Emitter, ILogger, Path, PreferenceService, URI, unreachable } from '@theia/core';
|
|
22
22
|
import { OpenerService, open } from '@theia/core/lib/browser';
|
|
23
23
|
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
24
24
|
import { WorkspaceService } from '@theia/workspace/lib/browser';
|
|
25
|
-
import * as yaml from 'js-yaml';
|
|
26
25
|
import { FileChange, FileChangeType } from '@theia/filesystem/lib/common/files';
|
|
27
26
|
import { TASK_CONTEXT_STORAGE_DIRECTORY_PREF } from '../common/workspace-preferences';
|
|
28
27
|
import { BinaryBuffer } from '@theia/core/lib/common/buffer';
|
|
@@ -160,7 +159,7 @@ export class TaskContextFileStorageService implements TaskContextStorageService
|
|
|
160
159
|
};
|
|
161
160
|
const derivedName = label.trim().replace(/[^\p{L}\p{N}]/ug, '-').replace(/^-+|-+$/g, '');
|
|
162
161
|
const filename = (derivedName.length > 32 ? derivedName.slice(0, derivedName.indexOf('-', 32)) : derivedName) + '.md';
|
|
163
|
-
const content =
|
|
162
|
+
const content = serializeFrontmatter(frontmatter, summary.summary);
|
|
164
163
|
const uri = storageLocation.resolve(filename);
|
|
165
164
|
summary.uri = uri;
|
|
166
165
|
await this.fileService.writeFile(uri, BinaryBuffer.fromString(content));
|
|
@@ -77,7 +77,7 @@ describe('UserInteractionTool', () => {
|
|
|
77
77
|
container.bind(ILogger).to(MockLogger).inSingletonScope();
|
|
78
78
|
|
|
79
79
|
mockWorkspaceScope = {
|
|
80
|
-
|
|
80
|
+
resolveAccessiblePath: sinon.stub().callsFake(async (path: string) => workspaceRoot.resolve(path)),
|
|
81
81
|
getContainingRoot: sinon.stub().returns(workspaceRoot)
|
|
82
82
|
};
|
|
83
83
|
|
|
@@ -617,6 +617,23 @@ describe('UserInteractionTool', () => {
|
|
|
617
617
|
expect(leftUri.query).to.contain('abc123');
|
|
618
618
|
});
|
|
619
619
|
|
|
620
|
+
it('should show the not-found content when a file link path cannot be resolved', async () => {
|
|
621
|
+
(mockWorkspaceScope.resolveAccessiblePath as sinon.SinonStub).rejects(new Error('Could not resolve path'));
|
|
622
|
+
|
|
623
|
+
await tool.openLink({ ref: 'src/file.ts' });
|
|
624
|
+
|
|
625
|
+
expect((mockEditorManager.open as sinon.SinonStub).called).to.be.false;
|
|
626
|
+
const openedUri = (mockOpenerService.getOpener as sinon.SinonStub).getCall(0).args[0] as URI;
|
|
627
|
+
expect(openedUri.scheme).to.equal(MEMORY_TEXT_READONLY);
|
|
628
|
+
expect(openedUri.query).to.contain('does not exist');
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
it('should resolve link paths with the same parsing as the workspace tools', async () => {
|
|
632
|
+
await tool.openLink({ ref: '/abs/src/file.ts' });
|
|
633
|
+
|
|
634
|
+
expect((mockWorkspaceScope.resolveAccessiblePath as sinon.SinonStub).calledWith('/abs/src/file.ts')).to.be.true;
|
|
635
|
+
});
|
|
636
|
+
|
|
620
637
|
it('should not open anything when single link ref is EmptyContentRef', async () => {
|
|
621
638
|
await tool.openLink({ ref: { empty: true } });
|
|
622
639
|
|