@aws/lsp-codewhisperer 0.0.75 → 0.0.76

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 (60) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/out/client/token/bearer-token-service.json +15 -0
  3. package/out/language-server/agenticChat/agenticChatController.d.ts +13 -2
  4. package/out/language-server/agenticChat/agenticChatController.js +162 -37
  5. package/out/language-server/agenticChat/agenticChatController.js.map +1 -1
  6. package/out/language-server/agenticChat/constants/modelSelection.d.ts +10 -2
  7. package/out/language-server/agenticChat/constants/modelSelection.js +11 -8
  8. package/out/language-server/agenticChat/constants/modelSelection.js.map +1 -1
  9. package/out/language-server/agenticChat/errors.d.ts +1 -1
  10. package/out/language-server/agenticChat/errors.js.map +1 -1
  11. package/out/language-server/agenticChat/tools/chatDb/chatDb.d.ts +10 -1
  12. package/out/language-server/agenticChat/tools/chatDb/chatDb.js +44 -0
  13. package/out/language-server/agenticChat/tools/chatDb/chatDb.js.map +1 -1
  14. package/out/language-server/agenticChat/tools/chatDb/util.d.ts +5 -1
  15. package/out/language-server/agenticChat/tools/chatDb/util.js +7 -0
  16. package/out/language-server/agenticChat/tools/chatDb/util.js.map +1 -1
  17. package/out/language-server/agenticChat/tools/mcp/mcpEventHandler.d.ts +1 -0
  18. package/out/language-server/agenticChat/tools/mcp/mcpEventHandler.js +50 -30
  19. package/out/language-server/agenticChat/tools/mcp/mcpEventHandler.js.map +1 -1
  20. package/out/language-server/agenticChat/tools/mcp/mcpManager.d.ts +4 -0
  21. package/out/language-server/agenticChat/tools/mcp/mcpManager.js +98 -52
  22. package/out/language-server/agenticChat/tools/mcp/mcpManager.js.map +1 -1
  23. package/out/language-server/agenticChat/tools/mcp/mcpOauthClient.d.ts +53 -0
  24. package/out/language-server/agenticChat/tools/mcp/mcpOauthClient.js +422 -0
  25. package/out/language-server/agenticChat/tools/mcp/mcpOauthClient.js.map +1 -0
  26. package/out/language-server/agenticChat/tools/mcp/mcpUtils.d.ts +4 -0
  27. package/out/language-server/agenticChat/tools/mcp/mcpUtils.js +89 -69
  28. package/out/language-server/agenticChat/tools/mcp/mcpUtils.js.map +1 -1
  29. package/out/language-server/agenticChat/tools/qCodeAnalysis/codeReview.js +15 -1
  30. package/out/language-server/agenticChat/tools/qCodeAnalysis/codeReview.js.map +1 -1
  31. package/out/language-server/agenticChat/tools/qCodeAnalysis/codeReviewSchemas.d.ts +4 -4
  32. package/out/language-server/agenticChat/tools/qCodeAnalysis/codeReviewTypes.d.ts +2 -1
  33. package/out/language-server/agenticChat/tools/qCodeAnalysis/codeReviewTypes.js +1 -0
  34. package/out/language-server/agenticChat/tools/qCodeAnalysis/codeReviewTypes.js.map +1 -1
  35. package/out/language-server/agenticChat/tools/qCodeAnalysis/displayFindingsSchemas.d.ts +16 -16
  36. package/out/language-server/inline-completion/codeWhispererServer.js +5 -5
  37. package/out/language-server/inline-completion/codeWhispererServer.js.map +1 -1
  38. package/out/language-server/inline-completion/editCompletionHandler.d.ts +1 -0
  39. package/out/language-server/inline-completion/editCompletionHandler.js +6 -3
  40. package/out/language-server/inline-completion/editCompletionHandler.js.map +1 -1
  41. package/out/language-server/inline-completion/session/sessionManager.d.ts +0 -2
  42. package/out/language-server/inline-completion/session/sessionManager.js +0 -13
  43. package/out/language-server/inline-completion/session/sessionManager.js.map +1 -1
  44. package/out/language-server/inline-completion/tracker/streakTracker.d.ts +21 -0
  45. package/out/language-server/inline-completion/tracker/streakTracker.js +43 -0
  46. package/out/language-server/inline-completion/tracker/streakTracker.js.map +1 -0
  47. package/out/shared/amazonQServiceManager/AmazonQTokenServiceManager.js +3 -0
  48. package/out/shared/amazonQServiceManager/AmazonQTokenServiceManager.js.map +1 -1
  49. package/out/shared/codeWhispererService.d.ts +4 -0
  50. package/out/shared/codeWhispererService.js +6 -0
  51. package/out/shared/codeWhispererService.js.map +1 -1
  52. package/out/shared/constants.d.ts +1 -0
  53. package/out/shared/constants.js +2 -1
  54. package/out/shared/constants.js.map +1 -1
  55. package/out/shared/supplementalContextUtil/crossFileContextUtil.js +10 -1
  56. package/out/shared/supplementalContextUtil/crossFileContextUtil.js.map +1 -1
  57. package/package.json +2 -2
  58. package/out/language-server/agenticChat/utils/agenticChatControllerHelper.d.ts +0 -8
  59. package/out/language-server/agenticChat/utils/agenticChatControllerHelper.js +0 -15
  60. package/out/language-server/agenticChat/utils/agenticChatControllerHelper.js.map +0 -1
@@ -0,0 +1,422 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright Amazon.com, Inc. or its affiliates.
4
+ * All Rights Reserved. SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.OAuthClient = void 0;
8
+ const crypto = require("crypto");
9
+ const path = require("path");
10
+ const url_1 = require("url");
11
+ const http = require("http");
12
+ const os = require("os");
13
+ class OAuthClient {
14
+ static logger;
15
+ static workspace;
16
+ static lsp;
17
+ static initialize(ws, logger, lsp) {
18
+ this.workspace = ws;
19
+ this.logger = logger;
20
+ this.lsp = lsp;
21
+ }
22
+ /**
23
+ * Return a valid Bearer token, reusing cache or refresh-token if possible,
24
+ * otherwise (when interactive) driving one PKCE flow that may launch a browser.
25
+ */
26
+ static async getValidAccessToken(mcpBase, opts = { interactive: false }) {
27
+ const interactive = opts?.interactive === true;
28
+ const key = this.computeKey(mcpBase);
29
+ const regPath = path.join(this.cacheDir, `${key}.registration.json`);
30
+ const tokPath = path.join(this.cacheDir, `${key}.token.json`);
31
+ // ===== Silent branch: try cached token, then refresh, never opens a browser =====
32
+ if (!interactive) {
33
+ // 1) cached access token
34
+ const cachedTok = await this.read(tokPath);
35
+ if (cachedTok) {
36
+ const expiry = cachedTok.obtained_at + cachedTok.expires_in * 1000;
37
+ if (Date.now() < expiry) {
38
+ this.logger.info(`OAuth: using still-valid cached token (silent)`);
39
+ return cachedTok.access_token;
40
+ }
41
+ this.logger.info(`OAuth: cached token expired → try refresh (silent)`);
42
+ }
43
+ // 2) refresh-token grant (if we have registration and refresh token)
44
+ const savedReg = await this.read(regPath);
45
+ if (cachedTok?.refresh_token && savedReg) {
46
+ try {
47
+ const meta = await this.discoverAS(mcpBase);
48
+ const refreshed = await this.refreshGrant(meta, savedReg, mcpBase, cachedTok.refresh_token);
49
+ if (refreshed) {
50
+ await this.write(tokPath, refreshed);
51
+ this.logger.info(`OAuth: refresh grant succeeded (silent)`);
52
+ return refreshed.access_token;
53
+ }
54
+ this.logger.info(`OAuth: refresh grant did not succeed (silent)`);
55
+ }
56
+ catch (e) {
57
+ this.logger.warn(`OAuth: silent refresh failed — ${e instanceof Error ? e.message : String(e)}`);
58
+ }
59
+ }
60
+ // 3) no token in silent mode → caller should surface auth-required UI
61
+ return undefined;
62
+ }
63
+ // ===== Interactive branch: may open a browser (PKCE) =====
64
+ // 1) Spin up (or reuse) loopback server + redirect URI
65
+ let server = null;
66
+ let redirectUri;
67
+ const savedReg = await this.read(regPath);
68
+ if (savedReg) {
69
+ const port = Number(new url_1.URL(savedReg.redirect_uri).port);
70
+ const normalized = `http://127.0.0.1:${port}`;
71
+ server = http.createServer();
72
+ try {
73
+ await this.listen(server, port, '127.0.0.1');
74
+ redirectUri = normalized;
75
+ this.logger.info(`OAuth: reusing redirect URI ${redirectUri}`);
76
+ }
77
+ catch (e) {
78
+ if (e.code === 'EADDRINUSE') {
79
+ try {
80
+ server.close();
81
+ }
82
+ catch {
83
+ /* ignore */
84
+ }
85
+ this.logger.warn(`Port ${port} in use; falling back to new random port`);
86
+ ({ server, redirectUri } = await this.buildCallbackServer());
87
+ this.logger.info(`OAuth: new redirect URI ${redirectUri}`);
88
+ await this.workspace.fs.rm(regPath);
89
+ }
90
+ else {
91
+ throw e;
92
+ }
93
+ }
94
+ }
95
+ else {
96
+ const created = await this.buildCallbackServer();
97
+ server = created.server;
98
+ redirectUri = created.redirectUri;
99
+ this.logger.info(`OAuth: new redirect URI ${redirectUri}`);
100
+ }
101
+ try {
102
+ // 2) Try still-valid cached access_token
103
+ const cached = await this.read(tokPath);
104
+ if (cached) {
105
+ const expiry = cached.obtained_at + cached.expires_in * 1000;
106
+ if (Date.now() < expiry) {
107
+ this.logger.info(`OAuth: using still-valid cached token`);
108
+ return cached.access_token;
109
+ }
110
+ this.logger.info(`OAuth: cached token expired → try refresh`);
111
+ }
112
+ // 3) Discover AS metadata
113
+ let meta;
114
+ try {
115
+ meta = await this.discoverAS(mcpBase);
116
+ }
117
+ catch (e) {
118
+ throw new Error(`OAuth discovery failed: ${e?.message ?? String(e)}`);
119
+ }
120
+ // 4) Register (or reuse) a dynamic client
121
+ const scopes = ['openid', 'offline_access'];
122
+ let reg;
123
+ try {
124
+ reg = await this.obtainClient(meta, regPath, scopes, redirectUri);
125
+ }
126
+ catch (e) {
127
+ throw new Error(`OAuth client registration failed: ${e?.message ?? String(e)}`);
128
+ }
129
+ // 5) Refresh-token grant (one shot)
130
+ const attemptedRefresh = !!cached?.refresh_token;
131
+ if (cached?.refresh_token) {
132
+ const refreshed = await this.refreshGrant(meta, reg, mcpBase, cached.refresh_token);
133
+ if (refreshed) {
134
+ await this.write(tokPath, refreshed);
135
+ this.logger.info(`OAuth: refresh grant succeeded`);
136
+ return refreshed.access_token;
137
+ }
138
+ this.logger.info(`OAuth: refresh grant failed`);
139
+ }
140
+ // 6) PKCE interactive flow
141
+ try {
142
+ const fresh = await this.pkceGrant(meta, reg, mcpBase, scopes, redirectUri, server);
143
+ await this.write(tokPath, fresh);
144
+ return fresh.access_token;
145
+ }
146
+ catch (e) {
147
+ const suffix = attemptedRefresh ? ' after refresh attempt' : '';
148
+ throw new Error(`OAuth authorization (PKCE) failed${suffix}: ${e?.message ?? String(e)}`);
149
+ }
150
+ }
151
+ finally {
152
+ if (server) {
153
+ await new Promise(res => server.close(() => res()));
154
+ }
155
+ }
156
+ }
157
+ /** Spin up a one‑time HTTP listener on localhost:randomPort */
158
+ static async buildCallbackServer() {
159
+ const server = http.createServer();
160
+ await this.listen(server, 0, '127.0.0.1');
161
+ const port = server.address().port;
162
+ return { server, redirectUri: `http://127.0.0.1:${port}` };
163
+ }
164
+ /** Discover OAuth endpoints by HEAD/WWW‑Authenticate, well‑known, or fallback */
165
+ static async discoverAS(rs) {
166
+ // a) HEAD → WWW‑Authenticate → resource_metadata
167
+ try {
168
+ this.logger.info('MCP OAuth: attempting discovery via WWW-Authenticate header');
169
+ const h = await this.fetchCompat(rs.toString(), { method: 'HEAD' });
170
+ const header = h.headers.get('www-authenticate') || '';
171
+ const m = /resource_metadata=(?:"([^"]+)"|([^,\s]+))/i.exec(header);
172
+ if (m) {
173
+ const metaUrl = new url_1.URL(m[1] || m[2], rs).toString();
174
+ this.logger.info(`OAuth: resource_metadata → ${metaUrl}`);
175
+ const raw = await this.json(metaUrl);
176
+ return await this.fetchASFromResourceMeta(raw, metaUrl);
177
+ }
178
+ }
179
+ catch {
180
+ this.logger.info('MCP OAuth: no resource_metadata found in WWW-Authenticate header');
181
+ }
182
+ // b) well‑known on resource host
183
+ this.logger.info('MCP OAuth: attempting discovery via well-known endpoints');
184
+ const probes = [
185
+ new url_1.URL('.well-known/oauth-authorization-server', rs).toString(),
186
+ new url_1.URL('.well-known/openid-configuration', rs).toString(),
187
+ `${rs.origin}/.well-known/oauth-authorization-server`,
188
+ `${rs.origin}/.well-known/openid-configuration`,
189
+ ];
190
+ for (const url of probes) {
191
+ try {
192
+ this.logger.info(`MCP OAuth: probing well-known endpoint → ${url}`);
193
+ return await this.json(url);
194
+ }
195
+ catch (error) {
196
+ this.logger.info(`OAuth: well-known endpoint probe failed for ${url}`);
197
+ }
198
+ }
199
+ // c) fallback to static OAuth2 endpoints
200
+ const base = (rs.origin + rs.pathname).replace(/\/+$/, '');
201
+ this.logger.warn(`OAuth: all discovery attempts failed, synthesizing endpoints from ${base}`);
202
+ return {
203
+ authorization_endpoint: `${base}/authorize`,
204
+ token_endpoint: `${base}/access_token`,
205
+ };
206
+ }
207
+ /** Follow `authorization_server(s)` in resource_metadata JSON */
208
+ static async fetchASFromResourceMeta(raw, metaUrl) {
209
+ let asBase = raw.authorization_server;
210
+ if (!asBase && Array.isArray(raw.authorization_servers)) {
211
+ asBase = raw.authorization_servers[0];
212
+ }
213
+ if (!asBase) {
214
+ throw new Error(`resource_metadata at ${metaUrl} lacked authorization_server(s)`);
215
+ }
216
+ // Attempt both OAuth‑AS and OIDC well‑known
217
+ for (const p of ['.well-known/oauth-authorization-server', '.well-known/openid-configuration']) {
218
+ try {
219
+ return await this.json(new url_1.URL(p, asBase).toString());
220
+ }
221
+ catch {
222
+ // next
223
+ }
224
+ }
225
+ // fallback to static OAuth2 endpoints
226
+ this.logger.warn(`OAuth: no well-known on ${asBase}, falling back to static endpoints`);
227
+ return {
228
+ authorization_endpoint: `${asBase}/authorize`,
229
+ token_endpoint: `${asBase}/access_token`,
230
+ };
231
+ }
232
+ /** DCR: POST client metadata → client_id; cache to disk */
233
+ static async obtainClient(meta, file, scopes, redirectUri) {
234
+ const existing = await this.read(file);
235
+ if (existing && (!existing.expires_at || existing.expires_at * 1000 > Date.now())) {
236
+ this.logger.info(`OAuth: reusing client_id ${existing.client_id}`);
237
+ return existing;
238
+ }
239
+ if (!meta.registration_endpoint) {
240
+ throw new Error('OAuth: AS does not support dynamic registration');
241
+ }
242
+ const body = {
243
+ client_name: 'AWS MCP LSP',
244
+ grant_types: ['authorization_code', 'refresh_token'],
245
+ response_types: ['code'],
246
+ token_endpoint_auth_method: 'none',
247
+ scope: scopes.join(' '),
248
+ redirect_uris: [redirectUri],
249
+ };
250
+ const resp = await this.json(meta.registration_endpoint, {
251
+ method: 'POST',
252
+ headers: { 'content-type': 'application/json' },
253
+ body: JSON.stringify(body),
254
+ });
255
+ const reg = {
256
+ client_id: resp.client_id,
257
+ client_secret: resp.client_secret,
258
+ expires_at: resp.client_secret_expires_at,
259
+ redirect_uri: redirectUri,
260
+ };
261
+ await this.write(file, reg);
262
+ return reg;
263
+ }
264
+ /** Try one refresh_token grant; returns new Token or `undefined` */
265
+ static async refreshGrant(meta, reg, rs, refresh) {
266
+ const form = new url_1.URLSearchParams({
267
+ grant_type: 'refresh_token',
268
+ refresh_token: refresh,
269
+ client_id: reg.client_id,
270
+ resource: rs.toString(),
271
+ });
272
+ const res = await this.fetchCompat(meta.token_endpoint, {
273
+ method: 'POST',
274
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
275
+ body: form,
276
+ });
277
+ if (!res.ok) {
278
+ const msg = await res.text().catch(() => '');
279
+ this.logger.warn(`OAuth: refresh grant HTTP ${res.status} — ${msg?.slice(0, 300)}`);
280
+ return undefined;
281
+ }
282
+ const tokenResponse = (await res.json());
283
+ return { ...tokenResponse, obtained_at: Date.now() };
284
+ }
285
+ /** One PKCE flow: browser + loopback → code → token */
286
+ static async pkceGrant(meta, reg, rs, scopes, redirectUri, server) {
287
+ const DEFAULT_PKCE_TIMEOUT_MS = 90_000;
288
+ // a) generate PKCE params
289
+ const verifier = this.b64url(crypto.randomBytes(32));
290
+ const challenge = this.b64url(crypto.createHash('sha256').update(verifier).digest());
291
+ const state = this.b64url(crypto.randomBytes(16));
292
+ // b) build authorize URL + launch browser
293
+ const authz = new url_1.URL(meta.authorization_endpoint);
294
+ authz.search = new url_1.URLSearchParams({
295
+ client_id: reg.client_id,
296
+ response_type: 'code',
297
+ code_challenge: challenge,
298
+ code_challenge_method: 'S256',
299
+ resource: rs.toString(),
300
+ scope: scopes.join(' '),
301
+ redirect_uri: redirectUri,
302
+ state: state,
303
+ }).toString();
304
+ await this.lsp.window.showDocument({ uri: authz.toString(), external: true });
305
+ // c) wait for code on our loopback
306
+ const waitForFlow = new Promise(resolve => {
307
+ server.on('request', (req, res) => {
308
+ const u = new url_1.URL(req.url || '/', redirectUri);
309
+ const c = u.searchParams.get('code') || '';
310
+ const s = u.searchParams.get('state') || '';
311
+ const e = u.searchParams.get('error') || undefined;
312
+ const ed = u.searchParams.get('error_description') || undefined;
313
+ res.writeHead(200, { 'content-type': 'text/html' }).end('<h2>You may close this tab.</h2>');
314
+ resolve({ code: c, rxState: s, err: e, errDesc: ed });
315
+ });
316
+ });
317
+ const { code, rxState, err, errDesc } = await Promise.race([
318
+ waitForFlow,
319
+ new Promise((_, reject) => setTimeout(() => reject(new Error('authorization_timed_out')), DEFAULT_PKCE_TIMEOUT_MS)),
320
+ ]);
321
+ if (err) {
322
+ throw new Error(`Authorization error: ${err}${errDesc ? ` - ${errDesc}` : ''}`);
323
+ }
324
+ if (!code || rxState !== state)
325
+ throw new Error('Invalid authorization response (state mismatch)');
326
+ // d) exchange code for token
327
+ const form2 = new url_1.URLSearchParams({
328
+ grant_type: 'authorization_code',
329
+ code,
330
+ code_verifier: verifier,
331
+ client_id: reg.client_id,
332
+ redirect_uri: redirectUri,
333
+ resource: rs.toString(),
334
+ });
335
+ const res2 = await this.fetchCompat(meta.token_endpoint, {
336
+ method: 'POST',
337
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
338
+ body: form2,
339
+ });
340
+ if (!res2.ok) {
341
+ const txt = await res2.text().catch(() => '');
342
+ throw new Error(`Token exchange failed (HTTP ${res2.status}): ${txt?.slice(0, 300)}`);
343
+ }
344
+ const tk = (await res2.json());
345
+ return { ...tk, obtained_at: Date.now() };
346
+ }
347
+ /** Fetch + error‑check + parse JSON */
348
+ static async json(url, init) {
349
+ const r = await this.fetchCompat(url, init);
350
+ if (!r.ok) {
351
+ const txt = await r.text().catch(() => '');
352
+ throw new Error(`HTTP ${r.status}@${url} — ${txt}`);
353
+ }
354
+ return (await r.json());
355
+ }
356
+ /** Read & parse JSON file via workspace.fs */
357
+ static async read(file) {
358
+ try {
359
+ if (!(await this.workspace.fs.exists(file)))
360
+ return undefined;
361
+ const buf = await this.workspace.fs.readFile(file);
362
+ return JSON.parse(buf.toString());
363
+ }
364
+ catch {
365
+ return undefined;
366
+ }
367
+ }
368
+ /** Write JSON, then clamp file perms to 0600 (owner read/write) */
369
+ static async write(file, obj) {
370
+ const dir = path.dirname(file);
371
+ await this.workspace.fs.mkdir(dir, { recursive: true });
372
+ await this.workspace.fs.writeFile(file, JSON.stringify(obj, null, 2), { mode: 0o600 });
373
+ }
374
+ /** SHA‑256 of resourceServer URL → hex key */
375
+ static computeKey(rs) {
376
+ return crypto
377
+ .createHash('sha256')
378
+ .update(rs.origin + rs.pathname)
379
+ .digest('hex');
380
+ }
381
+ /** RFC‑7636 base64url without padding */
382
+ static b64url(buf) {
383
+ return buf.toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
384
+ }
385
+ /** Directory for caching registration + tokens */
386
+ static cacheDir = path.join(os.homedir(), '.aws', 'sso', 'cache');
387
+ /**
388
+ * Await server.listen() but reject if it emits 'error' (eg EADDRINUSE),
389
+ * so callers can handle it immediately instead of hanging.
390
+ */
391
+ static listen(server, port, host = '127.0.0.1') {
392
+ return new Promise((resolve, reject) => {
393
+ const onListening = () => {
394
+ server.off('error', onError);
395
+ resolve();
396
+ };
397
+ const onError = (err) => {
398
+ server.off('listening', onListening);
399
+ reject(err);
400
+ };
401
+ server.once('listening', onListening);
402
+ server.once('error', onError);
403
+ server.listen(port, host);
404
+ });
405
+ }
406
+ /**
407
+ * Fetch compatibility: use global fetch on Node >= 18, otherwise dynamically import('node-fetch').
408
+ * Using Function('return import(...)') avoids downleveling to require() in CJS builds.
409
+ */
410
+ static async fetchCompat(url, init) {
411
+ const globalObj = globalThis;
412
+ if (typeof globalObj.fetch === 'function') {
413
+ return globalObj.fetch(url, init);
414
+ }
415
+ // Dynamic import of ESM node-fetch (only when global fetch is unavailable)
416
+ const mod = await Function('return import("node-fetch")')();
417
+ const f = mod.default ?? mod;
418
+ return f(url, init);
419
+ }
420
+ }
421
+ exports.OAuthClient = OAuthClient;
422
+ //# sourceMappingURL=mcpOauthClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcpOauthClient.js","sourceRoot":"","sources":["../../../../../src/language-server/agenticChat/tools/mcp/mcpOauthClient.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,iCAAgC;AAChC,6BAA4B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AAO,EAAE,MAAM,EAAE,EAAE;YACnC,MAAM,WAAW,GAAG,GAAG,EAAE;gBACrB,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;gBAC5B,OAAO,EAAE,CAAA;YACb,CAAC,CAAA;YACD,MAAM,OAAO,GAAG,CAAC,GAA0B,EAAE,EAAE;gBAC3C,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;gBACpC,MAAM,CAAC,GAAG,CAAC,CAAA;YACf,CAAC,CAAA;YACD,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;YACrC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;IACN,CAAC;IAED;;;OAGG;IACK,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,GAAW,EAAE,IAAkB;QAC5D,MAAM,SAAS,GAAG,UAAiB,CAAA;QACnC,IAAI,OAAO,SAAS,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YACxC,OAAO,SAAS,CAAC,KAAK,CAAC,GAAU,EAAE,IAAW,CAAC,CAAA;QACnD,CAAC;QACD,2EAA2E;QAC3E,MAAM,GAAG,GAAG,MAAO,QAAQ,CAAC,6BAA6B,CAAC,EAAmB,CAAA;QAC7E,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAA;QAC5B,OAAO,CAAC,CAAC,GAAU,EAAE,IAAW,CAAC,CAAA;IACrC,CAAC;;AAhcL,kCAicC"}
@@ -74,6 +74,10 @@ export declare function normalizePathFromUri(path: string, logging?: Logger): st
74
74
  */
75
75
  export declare function migrateToAgentConfig(workspace: Workspace, logging: Logger, agent: Agent): Promise<void>;
76
76
  export declare function saveAgentConfig(workspace: Workspace, logging: Logger, config: AgentConfig, configPath: string): Promise<void>;
77
+ /**
78
+ * Save only server-specific changes to agent config file
79
+ */
80
+ export declare function saveServerSpecificAgentConfig(workspace: Workspace, logging: Logger, serverName: string, serverConfig: any, serverTools: string[], serverAllowedTools: string[], configPath: string): Promise<void>;
77
81
  export declare const MAX_TOOL_NAME_LENGTH = 64;
78
82
  /**
79
83
  * Create a namespaced tool name from server and tool names.
@@ -21,6 +21,7 @@ exports.sanitizeName = sanitizeName;
21
21
  exports.normalizePathFromUri = normalizePathFromUri;
22
22
  exports.migrateToAgentConfig = migrateToAgentConfig;
23
23
  exports.saveAgentConfig = saveAgentConfig;
24
+ exports.saveServerSpecificAgentConfig = saveServerSpecificAgentConfig;
24
25
  exports.createNamespacedToolName = createNamespacedToolName;
25
26
  const vscode_uri_1 = require("vscode-uri");
26
27
  const mcpTypes_1 = require("./mcpTypes");
@@ -168,7 +169,9 @@ const DEFAULT_AGENT_RAW = `{
168
169
  "README.md",
169
170
  ".amazonq/rules/**/*.md"
170
171
  ],
171
- "resources": []
172
+ "resources": [],
173
+ "createHooks": [],
174
+ "promptHooks": []
172
175
  }`;
173
176
  const DEFAULT_PERSONA_RAW = `{
174
177
  "mcpServers": [
@@ -725,43 +728,35 @@ async function migrateConfigToAgent(workspace, logging, configPath, personaPath,
725
728
  const normalizedConfigPath = normalizePathFromUri(configPath, logging);
726
729
  const normalizedPersonaPath = normalizePathFromUri(personaPath, logging);
727
730
  agentPath = normalizePathFromUri(agentPath);
728
- // Check if agent config exists
731
+ // Check if config and agent files exist
732
+ const configExists = await workspace.fs.exists(normalizedConfigPath).catch(() => false);
729
733
  const agentExists = await workspace.fs.exists(agentPath).catch(() => false);
730
- // Load existing agent config if it exists
731
- let existingAgentConfig;
734
+ // Only migrate if agent file does not exist
735
+ // If config exists, migrate from it; if not, create default agent config
732
736
  if (agentExists) {
733
- try {
734
- const raw = (await workspace.fs.readFile(agentPath)).toString().trim();
735
- existingAgentConfig = raw ? JSON.parse(raw) : undefined;
736
- }
737
- catch (err) {
738
- logging.warn(`Failed to read existing agent config at ${agentPath}: ${err}`);
739
- }
737
+ return;
740
738
  }
741
739
  // Read MCP server configs directly from file
742
740
  const serverConfigs = {};
743
741
  try {
744
- const configExists = await workspace.fs.exists(normalizedConfigPath);
745
- if (configExists) {
746
- const raw = (await workspace.fs.readFile(normalizedConfigPath)).toString().trim();
747
- if (raw) {
748
- const config = JSON.parse(raw);
749
- if (config.mcpServers && typeof config.mcpServers === 'object') {
750
- // Add each server to the serverConfigs
751
- for (const [name, serverConfig] of Object.entries(config.mcpServers)) {
752
- serverConfigs[name] = {
753
- command: serverConfig.command,
754
- args: Array.isArray(serverConfig.args) ? serverConfig.args : undefined,
755
- env: typeof serverConfig.env === 'object' ? serverConfig.env : undefined,
756
- initializationTimeout: typeof serverConfig.initializationTimeout === 'number'
757
- ? serverConfig.initializationTimeout
758
- : undefined,
759
- timeout: typeof serverConfig.timeout === 'number'
760
- ? serverConfig.timeout
761
- : undefined,
762
- };
763
- logging.info(`Added server ${name} to serverConfigs`);
764
- }
742
+ const raw = (await workspace.fs.readFile(normalizedConfigPath)).toString().trim();
743
+ if (raw) {
744
+ const config = JSON.parse(raw);
745
+ if (config.mcpServers && typeof config.mcpServers === 'object') {
746
+ // Add each server to the serverConfigs
747
+ for (const [name, serverConfig] of Object.entries(config.mcpServers)) {
748
+ serverConfigs[name] = {
749
+ command: serverConfig.command,
750
+ args: Array.isArray(serverConfig.args) ? serverConfig.args : undefined,
751
+ env: typeof serverConfig.env === 'object' ? serverConfig.env : undefined,
752
+ initializationTimeout: typeof serverConfig.initializationTimeout === 'number'
753
+ ? serverConfig.initializationTimeout
754
+ : undefined,
755
+ timeout: typeof serverConfig.timeout === 'number'
756
+ ? serverConfig.timeout
757
+ : undefined,
758
+ };
759
+ logging.info(`Added server ${name} to serverConfigs`);
765
760
  }
766
761
  }
767
762
  }
@@ -787,45 +782,21 @@ async function migrateConfigToAgent(workspace, logging, configPath, personaPath,
787
782
  logging.warn(`Failed to read persona config at ${normalizedPersonaPath}: ${err}`);
788
783
  }
789
784
  // Convert to agent config
790
- const newAgentConfig = convertPersonaToAgent(personaConfig, serverConfigs, agent);
791
- newAgentConfig.includedFiles = ['AmazonQ.md', 'README.md', '.amazonq/rules/**/*.md'];
792
- newAgentConfig.resources = []; // Initialize with empty array
793
- // Merge with existing config if available
794
- let finalAgentConfig;
795
- if (existingAgentConfig) {
796
- // Keep existing metadata
797
- finalAgentConfig = {
798
- ...existingAgentConfig,
799
- // Merge MCP servers, keeping existing ones if they exist
800
- mcpServers: {
801
- ...newAgentConfig.mcpServers,
802
- ...existingAgentConfig.mcpServers,
803
- },
804
- // Merge tools lists without duplicates
805
- tools: [...new Set([...existingAgentConfig.tools, ...newAgentConfig.tools])],
806
- allowedTools: [...new Set([...existingAgentConfig.allowedTools, ...newAgentConfig.allowedTools])],
807
- // Merge tool settings, preferring existing ones
808
- toolsSettings: {
809
- ...newAgentConfig.toolsSettings,
810
- ...existingAgentConfig.toolsSettings,
811
- },
812
- // Keep other properties from existing config
813
- includedFiles: existingAgentConfig.includedFiles || newAgentConfig.includedFiles,
814
- createHooks: existingAgentConfig.createHooks || newAgentConfig.createHooks,
815
- promptHooks: [
816
- ...new Set([...(existingAgentConfig.promptHooks || []), ...(newAgentConfig.promptHooks || [])]),
817
- ],
818
- resources: [...new Set([...(existingAgentConfig.resources || []), ...(newAgentConfig.resources || [])])],
819
- };
820
- }
821
- else {
822
- finalAgentConfig = newAgentConfig;
823
- logging.info(`Using new config (no existing config to merge)`);
824
- }
785
+ const agentConfig = convertPersonaToAgent(personaConfig, serverConfigs, agent);
786
+ // Parse default values from DEFAULT_AGENT_RAW
787
+ const defaultAgent = JSON.parse(DEFAULT_AGENT_RAW);
788
+ // Add complete agent format sections using default values
789
+ agentConfig.name = defaultAgent.name;
790
+ agentConfig.description = defaultAgent.description;
791
+ agentConfig.version = defaultAgent.version;
792
+ agentConfig.includedFiles = defaultAgent.includedFiles;
793
+ agentConfig.resources = defaultAgent.resources;
794
+ agentConfig.createHooks = defaultAgent.createHooks;
795
+ agentConfig.promptHooks = defaultAgent.promptHooks;
825
796
  // Save agent config
826
797
  try {
827
- await saveAgentConfig(workspace, logging, finalAgentConfig, agentPath);
828
- logging.info(`Successfully ${existingAgentConfig ? 'updated' : 'created'} agent config at ${agentPath}`);
798
+ await saveAgentConfig(workspace, logging, agentConfig, agentPath);
799
+ logging.info(`Successfully created agent config at ${agentPath}`);
829
800
  }
830
801
  catch (err) {
831
802
  logging.error(`Failed to save agent config to ${agentPath}: ${err}`);
@@ -844,6 +815,55 @@ async function saveAgentConfig(workspace, logging, config, configPath) {
844
815
  throw err;
845
816
  }
846
817
  }
818
+ /**
819
+ * Save only server-specific changes to agent config file
820
+ */
821
+ async function saveServerSpecificAgentConfig(workspace, logging, serverName, serverConfig, serverTools, serverAllowedTools, configPath) {
822
+ try {
823
+ await workspace.fs.mkdir(path.dirname(configPath), { recursive: true });
824
+ // Read existing config
825
+ let existingConfig;
826
+ try {
827
+ const raw = await workspace.fs.readFile(configPath);
828
+ existingConfig = JSON.parse(raw.toString());
829
+ }
830
+ catch {
831
+ // If file doesn't exist, create minimal config
832
+ existingConfig = {
833
+ name: 'default-agent',
834
+ version: '1.0.0',
835
+ description: 'Agent configuration',
836
+ mcpServers: {},
837
+ tools: [],
838
+ allowedTools: [],
839
+ toolsSettings: {},
840
+ includedFiles: [],
841
+ resources: [],
842
+ };
843
+ }
844
+ // Remove existing server tools from arrays
845
+ const serverPrefix = `@${serverName}`;
846
+ existingConfig.tools = existingConfig.tools.filter(tool => tool !== serverPrefix && !tool.startsWith(`${serverPrefix}/`));
847
+ existingConfig.allowedTools = existingConfig.allowedTools.filter(tool => tool !== serverPrefix && !tool.startsWith(`${serverPrefix}/`));
848
+ if (serverConfig === null) {
849
+ // Remove server entirely
850
+ delete existingConfig.mcpServers[serverName];
851
+ }
852
+ else {
853
+ // Update or add server
854
+ existingConfig.mcpServers[serverName] = serverConfig;
855
+ // Add new server tools
856
+ existingConfig.tools.push(...serverTools);
857
+ existingConfig.allowedTools.push(...serverAllowedTools);
858
+ }
859
+ await workspace.fs.writeFile(configPath, JSON.stringify(existingConfig, null, 2));
860
+ logging.info(`Saved server-specific agent config for ${serverName} to ${configPath}`);
861
+ }
862
+ catch (err) {
863
+ logging.error(`Failed to save server-specific agent config to ${configPath}: ${err.message}`);
864
+ throw err;
865
+ }
866
+ }
847
867
  exports.MAX_TOOL_NAME_LENGTH = 64;
848
868
  /**
849
869
  * Create a namespaced tool name from server and tool names.