@caupulican/pi-adaptative 0.80.25 → 0.80.26
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/CHANGELOG.md +2 -0
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +104 -18
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/builtin.d.ts +3 -0
- package/dist/core/extensions/builtin.d.ts.map +1 -0
- package/dist/core/extensions/builtin.js +247 -0
- package/dist/core/extensions/builtin.js.map +1 -0
- package/dist/core/resource-loader.d.ts +15 -2
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +231 -155
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +20 -20
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -145,6 +145,7 @@ export class DefaultResourceLoader {
|
|
|
145
145
|
extensionThemeSourceInfos;
|
|
146
146
|
lastPromptPaths;
|
|
147
147
|
lastThemePaths;
|
|
148
|
+
pendingReloadSnapshot;
|
|
148
149
|
constructor(options) {
|
|
149
150
|
this.cwd = resolvePath(options.cwd);
|
|
150
151
|
this.agentDir = resolvePath(options.agentDir);
|
|
@@ -159,8 +160,8 @@ export class DefaultResourceLoader {
|
|
|
159
160
|
this.additionalSkillPaths = options.additionalSkillPaths ?? [];
|
|
160
161
|
this.additionalPromptTemplatePaths = options.additionalPromptTemplatePaths ?? [];
|
|
161
162
|
this.additionalThemePaths = options.additionalThemePaths ?? [];
|
|
162
|
-
this.extensionFactories = options.extensionFactories ?? [];
|
|
163
163
|
this.noExtensions = options.noExtensions ?? false;
|
|
164
|
+
this.extensionFactories = options.extensionFactories ?? [];
|
|
164
165
|
this.noSkills = options.noSkills ?? false;
|
|
165
166
|
this.noPromptTemplates = options.noPromptTemplates ?? false;
|
|
166
167
|
this.noThemes = options.noThemes ?? false;
|
|
@@ -237,179 +238,254 @@ export class DefaultResourceLoader {
|
|
|
237
238
|
this.updateThemesFromPaths(this.lastThemePaths);
|
|
238
239
|
}
|
|
239
240
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
createSnapshot() {
|
|
242
|
+
return {
|
|
243
|
+
extensionsResult: this.extensionsResult,
|
|
244
|
+
skills: this.skills,
|
|
245
|
+
skillDiagnostics: this.skillDiagnostics,
|
|
246
|
+
prompts: this.prompts,
|
|
247
|
+
promptDiagnostics: this.promptDiagnostics,
|
|
248
|
+
themes: this.themes,
|
|
249
|
+
themeDiagnostics: this.themeDiagnostics,
|
|
250
|
+
agentsFiles: this.agentsFiles,
|
|
251
|
+
systemPrompt: this.systemPrompt,
|
|
252
|
+
appendSystemPrompt: this.appendSystemPrompt,
|
|
253
|
+
lastSkillPaths: this.lastSkillPaths,
|
|
254
|
+
extensionSkillSourceInfos: this.extensionSkillSourceInfos,
|
|
255
|
+
extensionPromptSourceInfos: this.extensionPromptSourceInfos,
|
|
256
|
+
extensionThemeSourceInfos: this.extensionThemeSourceInfos,
|
|
257
|
+
lastPromptPaths: this.lastPromptPaths,
|
|
258
|
+
lastThemePaths: this.lastThemePaths,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
restoreSnapshot(snapshot) {
|
|
262
|
+
this.extensionsResult = snapshot.extensionsResult;
|
|
263
|
+
this.skills = snapshot.skills;
|
|
264
|
+
this.skillDiagnostics = snapshot.skillDiagnostics;
|
|
265
|
+
this.prompts = snapshot.prompts;
|
|
266
|
+
this.promptDiagnostics = snapshot.promptDiagnostics;
|
|
267
|
+
this.themes = snapshot.themes;
|
|
268
|
+
this.themeDiagnostics = snapshot.themeDiagnostics;
|
|
269
|
+
this.agentsFiles = snapshot.agentsFiles;
|
|
270
|
+
this.systemPrompt = snapshot.systemPrompt;
|
|
271
|
+
this.appendSystemPrompt = snapshot.appendSystemPrompt;
|
|
272
|
+
this.lastSkillPaths = snapshot.lastSkillPaths;
|
|
273
|
+
this.extensionSkillSourceInfos = snapshot.extensionSkillSourceInfos;
|
|
274
|
+
this.extensionPromptSourceInfos = snapshot.extensionPromptSourceInfos;
|
|
275
|
+
this.extensionThemeSourceInfos = snapshot.extensionThemeSourceInfos;
|
|
276
|
+
this.lastPromptPaths = snapshot.lastPromptPaths;
|
|
277
|
+
this.lastThemePaths = snapshot.lastThemePaths;
|
|
278
|
+
}
|
|
279
|
+
commitReload() {
|
|
280
|
+
if (!this.pendingReloadSnapshot)
|
|
281
|
+
return;
|
|
282
|
+
disposeExtensionEventSubscriptions(this.pendingReloadSnapshot.extensionsResult.extensions);
|
|
283
|
+
this.pendingReloadSnapshot = undefined;
|
|
284
|
+
}
|
|
285
|
+
rollbackReload() {
|
|
286
|
+
if (!this.pendingReloadSnapshot)
|
|
287
|
+
return;
|
|
243
288
|
disposeExtensionEventSubscriptions(this.extensionsResult.extensions);
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
289
|
+
this.restoreSnapshot(this.pendingReloadSnapshot);
|
|
290
|
+
this.pendingReloadSnapshot = undefined;
|
|
291
|
+
}
|
|
292
|
+
async reload(options = {}) {
|
|
293
|
+
const snapshot = this.createSnapshot();
|
|
294
|
+
this.pendingReloadSnapshot = undefined;
|
|
295
|
+
try {
|
|
296
|
+
await this.settingsManager.reload();
|
|
297
|
+
const resolvedPaths = await this.packageManager.resolve();
|
|
298
|
+
const cliExtensionPaths = await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths, {
|
|
299
|
+
temporary: true,
|
|
300
|
+
});
|
|
301
|
+
const metadataByPath = new Map();
|
|
302
|
+
this.extensionSkillSourceInfos = new Map();
|
|
303
|
+
this.extensionPromptSourceInfos = new Map();
|
|
304
|
+
this.extensionThemeSourceInfos = new Map();
|
|
305
|
+
// Helper to extract enabled paths and store metadata
|
|
306
|
+
const getEnabledResources = (resources) => {
|
|
307
|
+
for (const r of resources) {
|
|
308
|
+
if (!metadataByPath.has(r.path)) {
|
|
309
|
+
metadataByPath.set(r.path, r.metadata);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return resources.filter((r) => r.enabled);
|
|
313
|
+
};
|
|
314
|
+
const getEnabledPaths = (resources) => getEnabledResources(resources).map((r) => r.path);
|
|
315
|
+
const enabledExtensions = getEnabledPaths(resolvedPaths.extensions);
|
|
316
|
+
const enabledSkillResources = getEnabledResources(resolvedPaths.skills);
|
|
317
|
+
const enabledPrompts = getEnabledPaths(resolvedPaths.prompts);
|
|
318
|
+
const enabledThemes = getEnabledPaths(resolvedPaths.themes);
|
|
319
|
+
const mapSkillPath = (resource) => {
|
|
320
|
+
if (resource.metadata.source !== "auto" && resource.metadata.origin !== "package") {
|
|
321
|
+
return resource.path;
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
const stats = statSync(resource.path);
|
|
325
|
+
if (!stats.isDirectory()) {
|
|
326
|
+
return resource.path;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
return resource.path;
|
|
331
|
+
}
|
|
332
|
+
const skillFile = join(resource.path, "SKILL.md");
|
|
333
|
+
if (existsSync(skillFile)) {
|
|
334
|
+
if (!metadataByPath.has(skillFile)) {
|
|
335
|
+
metadataByPath.set(skillFile, resource.metadata);
|
|
336
|
+
}
|
|
337
|
+
return skillFile;
|
|
258
338
|
}
|
|
259
|
-
}
|
|
260
|
-
return resources.filter((r) => r.enabled);
|
|
261
|
-
};
|
|
262
|
-
const getEnabledPaths = (resources) => getEnabledResources(resources).map((r) => r.path);
|
|
263
|
-
const enabledExtensions = getEnabledPaths(resolvedPaths.extensions);
|
|
264
|
-
const enabledSkillResources = getEnabledResources(resolvedPaths.skills);
|
|
265
|
-
const enabledPrompts = getEnabledPaths(resolvedPaths.prompts);
|
|
266
|
-
const enabledThemes = getEnabledPaths(resolvedPaths.themes);
|
|
267
|
-
const mapSkillPath = (resource) => {
|
|
268
|
-
if (resource.metadata.source !== "auto" && resource.metadata.origin !== "package") {
|
|
269
339
|
return resource.path;
|
|
340
|
+
};
|
|
341
|
+
const enabledSkills = enabledSkillResources.map(mapSkillPath);
|
|
342
|
+
// Add CLI paths metadata
|
|
343
|
+
for (const r of cliExtensionPaths.extensions) {
|
|
344
|
+
if (!metadataByPath.has(r.path)) {
|
|
345
|
+
metadataByPath.set(r.path, { source: "cli", scope: "temporary", origin: "top-level" });
|
|
346
|
+
}
|
|
270
347
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
return resource.path;
|
|
348
|
+
for (const r of cliExtensionPaths.skills) {
|
|
349
|
+
if (!metadataByPath.has(r.path)) {
|
|
350
|
+
metadataByPath.set(r.path, { source: "cli", scope: "temporary", origin: "top-level" });
|
|
275
351
|
}
|
|
276
352
|
}
|
|
277
|
-
|
|
278
|
-
|
|
353
|
+
const cliEnabledExtensions = getEnabledPaths(cliExtensionPaths.extensions);
|
|
354
|
+
const cliEnabledSkills = getEnabledPaths(cliExtensionPaths.skills);
|
|
355
|
+
const cliEnabledPrompts = getEnabledPaths(cliExtensionPaths.prompts);
|
|
356
|
+
const cliEnabledThemes = getEnabledPaths(cliExtensionPaths.themes);
|
|
357
|
+
const extensionPaths = this.noExtensions
|
|
358
|
+
? cliEnabledExtensions
|
|
359
|
+
: this.mergePaths(cliEnabledExtensions, enabledExtensions);
|
|
360
|
+
const extensionsResult = await loadExtensions(extensionPaths, this.cwd, this.eventBus);
|
|
361
|
+
const inlineExtensions = await this.loadExtensionFactories(extensionsResult.runtime);
|
|
362
|
+
extensionsResult.extensions.push(...inlineExtensions.extensions);
|
|
363
|
+
extensionsResult.errors.push(...inlineExtensions.errors);
|
|
364
|
+
// Detect extension conflicts (tools, commands, flags with same names from different extensions)
|
|
365
|
+
// Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.
|
|
366
|
+
const conflicts = this.detectExtensionConflicts(extensionsResult.extensions);
|
|
367
|
+
for (const conflict of conflicts) {
|
|
368
|
+
extensionsResult.errors.push({ path: conflict.path, error: conflict.message });
|
|
369
|
+
}
|
|
370
|
+
for (const p of this.additionalExtensionPaths) {
|
|
371
|
+
if (isLocalPath(p)) {
|
|
372
|
+
const resolved = this.resolveResourcePath(p);
|
|
373
|
+
if (!existsSync(resolved)) {
|
|
374
|
+
extensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
279
377
|
}
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
378
|
+
const resolvedExtensionsResult = this.extensionsOverride
|
|
379
|
+
? this.extensionsOverride(extensionsResult)
|
|
380
|
+
: extensionsResult;
|
|
381
|
+
if (options.failOnExtensionErrors && resolvedExtensionsResult.errors.length > 0) {
|
|
382
|
+
const summary = resolvedExtensionsResult.errors
|
|
383
|
+
.slice(0, 6)
|
|
384
|
+
.map((error) => `${error.path}: ${error.error}`)
|
|
385
|
+
.join("; ");
|
|
386
|
+
throw new Error(`Extension reload failed preflight: ${summary}`);
|
|
387
|
+
}
|
|
388
|
+
this.extensionsResult = resolvedExtensionsResult;
|
|
389
|
+
this.applyExtensionSourceInfo(this.extensionsResult.extensions, metadataByPath);
|
|
390
|
+
const skillPaths = this.noSkills
|
|
391
|
+
? this.mergePaths(cliEnabledSkills, this.additionalSkillPaths)
|
|
392
|
+
: this.mergePaths([...cliEnabledSkills, ...enabledSkills], this.additionalSkillPaths);
|
|
393
|
+
this.lastSkillPaths = skillPaths;
|
|
394
|
+
this.updateSkillsFromPaths(skillPaths, metadataByPath);
|
|
395
|
+
for (const p of this.additionalSkillPaths) {
|
|
396
|
+
if (isLocalPath(p)) {
|
|
397
|
+
const resolved = this.resolveResourcePath(p);
|
|
398
|
+
if (!existsSync(resolved) && !this.skillDiagnostics.some((d) => d.path === resolved)) {
|
|
399
|
+
this.skillDiagnostics.push({ type: "error", message: "Skill path does not exist", path: resolved });
|
|
400
|
+
}
|
|
284
401
|
}
|
|
285
|
-
return skillFile;
|
|
286
402
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const cliEnabledSkills = getEnabledPaths(cliExtensionPaths.skills);
|
|
303
|
-
const cliEnabledPrompts = getEnabledPaths(cliExtensionPaths.prompts);
|
|
304
|
-
const cliEnabledThemes = getEnabledPaths(cliExtensionPaths.themes);
|
|
305
|
-
const extensionPaths = this.noExtensions
|
|
306
|
-
? cliEnabledExtensions
|
|
307
|
-
: this.mergePaths(cliEnabledExtensions, enabledExtensions);
|
|
308
|
-
const extensionsResult = await loadExtensions(extensionPaths, this.cwd, this.eventBus);
|
|
309
|
-
const inlineExtensions = await this.loadExtensionFactories(extensionsResult.runtime);
|
|
310
|
-
extensionsResult.extensions.push(...inlineExtensions.extensions);
|
|
311
|
-
extensionsResult.errors.push(...inlineExtensions.errors);
|
|
312
|
-
// Detect extension conflicts (tools, commands, flags with same names from different extensions)
|
|
313
|
-
// Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.
|
|
314
|
-
const conflicts = this.detectExtensionConflicts(extensionsResult.extensions);
|
|
315
|
-
for (const conflict of conflicts) {
|
|
316
|
-
extensionsResult.errors.push({ path: conflict.path, error: conflict.message });
|
|
317
|
-
}
|
|
318
|
-
for (const p of this.additionalExtensionPaths) {
|
|
319
|
-
if (isLocalPath(p)) {
|
|
320
|
-
const resolved = this.resolveResourcePath(p);
|
|
321
|
-
if (!existsSync(resolved)) {
|
|
322
|
-
extensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });
|
|
403
|
+
const promptPaths = this.noPromptTemplates
|
|
404
|
+
? this.mergePaths(cliEnabledPrompts, this.additionalPromptTemplatePaths)
|
|
405
|
+
: this.mergePaths([...cliEnabledPrompts, ...enabledPrompts], this.additionalPromptTemplatePaths);
|
|
406
|
+
this.lastPromptPaths = promptPaths;
|
|
407
|
+
this.updatePromptsFromPaths(promptPaths, metadataByPath);
|
|
408
|
+
for (const p of this.additionalPromptTemplatePaths) {
|
|
409
|
+
if (isLocalPath(p)) {
|
|
410
|
+
const resolved = this.resolveResourcePath(p);
|
|
411
|
+
if (!existsSync(resolved) && !this.promptDiagnostics.some((d) => d.path === resolved)) {
|
|
412
|
+
this.promptDiagnostics.push({
|
|
413
|
+
type: "error",
|
|
414
|
+
message: "Prompt template path does not exist",
|
|
415
|
+
path: resolved,
|
|
416
|
+
});
|
|
417
|
+
}
|
|
323
418
|
}
|
|
324
419
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
this.lastSkillPaths = skillPaths;
|
|
332
|
-
this.updateSkillsFromPaths(skillPaths, metadataByPath);
|
|
333
|
-
for (const p of this.additionalSkillPaths) {
|
|
334
|
-
if (isLocalPath(p)) {
|
|
420
|
+
const themePaths = this.noThemes
|
|
421
|
+
? this.mergePaths(cliEnabledThemes, this.additionalThemePaths)
|
|
422
|
+
: this.mergePaths([...cliEnabledThemes, ...enabledThemes], this.additionalThemePaths);
|
|
423
|
+
this.lastThemePaths = themePaths;
|
|
424
|
+
this.updateThemesFromPaths(themePaths, metadataByPath);
|
|
425
|
+
for (const p of this.additionalThemePaths) {
|
|
335
426
|
const resolved = this.resolveResourcePath(p);
|
|
336
|
-
if (!existsSync(resolved) && !this.
|
|
337
|
-
this.
|
|
427
|
+
if (!existsSync(resolved) && !this.themeDiagnostics.some((d) => d.path === resolved)) {
|
|
428
|
+
this.themeDiagnostics.push({ type: "error", message: "Theme path does not exist", path: resolved });
|
|
338
429
|
}
|
|
339
430
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
});
|
|
431
|
+
const rawAgentsFiles = this.noContextFiles
|
|
432
|
+
? []
|
|
433
|
+
: loadProjectContextFiles({
|
|
434
|
+
cwd: this.cwd,
|
|
435
|
+
agentDir: this.agentDir,
|
|
436
|
+
projectTrusted: this.settingsManager.isProjectTrusted(),
|
|
437
|
+
});
|
|
438
|
+
const agentEmbeddedProfiles = {};
|
|
439
|
+
const activeProfileNames = this.settingsManager.getActiveResourceProfileNames();
|
|
440
|
+
for (const file of rawAgentsFiles) {
|
|
441
|
+
try {
|
|
442
|
+
const rawContent = readFileSync(file.path, "utf-8");
|
|
443
|
+
const { profiles } = parseResourceProfileBlocks(rawContent, { profileNames: activeProfileNames });
|
|
444
|
+
Object.assign(agentEmbeddedProfiles, mergeResourceProfileMap(agentEmbeddedProfiles, profiles));
|
|
355
445
|
}
|
|
446
|
+
catch { }
|
|
447
|
+
}
|
|
448
|
+
this.settingsManager.addDiscoveredResourceProfileDefinitions(agentEmbeddedProfiles);
|
|
449
|
+
const agentProfileFilter = this.settingsManager.getResourceProfileFilter("agents");
|
|
450
|
+
const agentsFiles = {
|
|
451
|
+
agentsFiles: rawAgentsFiles
|
|
452
|
+
.filter((file) => {
|
|
453
|
+
const allowed = agentProfileFilter.allow.length === 0 ||
|
|
454
|
+
matchesResourceProfilePattern(file.path, agentProfileFilter.allow, this.cwd);
|
|
455
|
+
const blocked = matchesResourceProfilePattern(file.path, agentProfileFilter.block, this.cwd);
|
|
456
|
+
return allowed && !blocked;
|
|
457
|
+
})
|
|
458
|
+
.map((file) => ({
|
|
459
|
+
...file,
|
|
460
|
+
content: file.content ? stripResourceProfileBlocks(file.content) : file.content,
|
|
461
|
+
})),
|
|
462
|
+
};
|
|
463
|
+
const resolvedAgentsFiles = this.agentsFilesOverride ? this.agentsFilesOverride(agentsFiles) : agentsFiles;
|
|
464
|
+
this.agentsFiles = resolvedAgentsFiles.agentsFiles;
|
|
465
|
+
const baseSystemPrompt = resolvePromptInput(this.systemPromptSource ?? this.discoverSystemPromptFile(), "system prompt");
|
|
466
|
+
this.systemPrompt = this.systemPromptOverride ? this.systemPromptOverride(baseSystemPrompt) : baseSystemPrompt;
|
|
467
|
+
const appendSources = this.appendSystemPromptSource ??
|
|
468
|
+
(this.discoverAppendSystemPromptFile() ? [this.discoverAppendSystemPromptFile()] : []);
|
|
469
|
+
const baseAppend = appendSources
|
|
470
|
+
.map((s) => resolvePromptInput(s, "append system prompt"))
|
|
471
|
+
.filter((s) => s !== undefined);
|
|
472
|
+
this.appendSystemPrompt = this.appendSystemPromptOverride
|
|
473
|
+
? this.appendSystemPromptOverride(baseAppend)
|
|
474
|
+
: baseAppend;
|
|
475
|
+
if (options.deferExtensionDispose) {
|
|
476
|
+
this.pendingReloadSnapshot = snapshot;
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
disposeExtensionEventSubscriptions(snapshot.extensionsResult.extensions);
|
|
356
480
|
}
|
|
357
481
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
this.lastThemePaths = themePaths;
|
|
362
|
-
this.updateThemesFromPaths(themePaths, metadataByPath);
|
|
363
|
-
for (const p of this.additionalThemePaths) {
|
|
364
|
-
const resolved = this.resolveResourcePath(p);
|
|
365
|
-
if (!existsSync(resolved) && !this.themeDiagnostics.some((d) => d.path === resolved)) {
|
|
366
|
-
this.themeDiagnostics.push({ type: "error", message: "Theme path does not exist", path: resolved });
|
|
482
|
+
catch (error) {
|
|
483
|
+
if (this.extensionsResult !== snapshot.extensionsResult) {
|
|
484
|
+
disposeExtensionEventSubscriptions(this.extensionsResult.extensions);
|
|
367
485
|
}
|
|
486
|
+
this.restoreSnapshot(snapshot);
|
|
487
|
+
throw error;
|
|
368
488
|
}
|
|
369
|
-
const rawAgentsFiles = this.noContextFiles
|
|
370
|
-
? []
|
|
371
|
-
: loadProjectContextFiles({
|
|
372
|
-
cwd: this.cwd,
|
|
373
|
-
agentDir: this.agentDir,
|
|
374
|
-
projectTrusted: this.settingsManager.isProjectTrusted(),
|
|
375
|
-
});
|
|
376
|
-
const agentEmbeddedProfiles = {};
|
|
377
|
-
const activeProfileNames = this.settingsManager.getActiveResourceProfileNames();
|
|
378
|
-
for (const file of rawAgentsFiles) {
|
|
379
|
-
try {
|
|
380
|
-
const rawContent = readFileSync(file.path, "utf-8");
|
|
381
|
-
const { profiles } = parseResourceProfileBlocks(rawContent, { profileNames: activeProfileNames });
|
|
382
|
-
Object.assign(agentEmbeddedProfiles, mergeResourceProfileMap(agentEmbeddedProfiles, profiles));
|
|
383
|
-
}
|
|
384
|
-
catch { }
|
|
385
|
-
}
|
|
386
|
-
this.settingsManager.addDiscoveredResourceProfileDefinitions(agentEmbeddedProfiles);
|
|
387
|
-
const agentProfileFilter = this.settingsManager.getResourceProfileFilter("agents");
|
|
388
|
-
const agentsFiles = {
|
|
389
|
-
agentsFiles: rawAgentsFiles
|
|
390
|
-
.filter((file) => {
|
|
391
|
-
const allowed = agentProfileFilter.allow.length === 0 ||
|
|
392
|
-
matchesResourceProfilePattern(file.path, agentProfileFilter.allow, this.cwd);
|
|
393
|
-
const blocked = matchesResourceProfilePattern(file.path, agentProfileFilter.block, this.cwd);
|
|
394
|
-
return allowed && !blocked;
|
|
395
|
-
})
|
|
396
|
-
.map((file) => ({
|
|
397
|
-
...file,
|
|
398
|
-
content: file.content ? stripResourceProfileBlocks(file.content) : file.content,
|
|
399
|
-
})),
|
|
400
|
-
};
|
|
401
|
-
const resolvedAgentsFiles = this.agentsFilesOverride ? this.agentsFilesOverride(agentsFiles) : agentsFiles;
|
|
402
|
-
this.agentsFiles = resolvedAgentsFiles.agentsFiles;
|
|
403
|
-
const baseSystemPrompt = resolvePromptInput(this.systemPromptSource ?? this.discoverSystemPromptFile(), "system prompt");
|
|
404
|
-
this.systemPrompt = this.systemPromptOverride ? this.systemPromptOverride(baseSystemPrompt) : baseSystemPrompt;
|
|
405
|
-
const appendSources = this.appendSystemPromptSource ??
|
|
406
|
-
(this.discoverAppendSystemPromptFile() ? [this.discoverAppendSystemPromptFile()] : []);
|
|
407
|
-
const baseAppend = appendSources
|
|
408
|
-
.map((s) => resolvePromptInput(s, "append system prompt"))
|
|
409
|
-
.filter((s) => s !== undefined);
|
|
410
|
-
this.appendSystemPrompt = this.appendSystemPromptOverride
|
|
411
|
-
? this.appendSystemPromptOverride(baseAppend)
|
|
412
|
-
: baseAppend;
|
|
413
489
|
}
|
|
414
490
|
normalizeExtensionPaths(entries) {
|
|
415
491
|
return entries.map((entry) => {
|