@caupulican/pi-adaptative 0.80.23 → 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 +17 -0
- package/README.md +16 -2
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +14 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +4 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +22 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +7 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +126 -20
- 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/package-manager.d.ts +3 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +58 -0
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +3 -1
- package/dist/core/prompt-templates.js.map +1 -1
- 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 +235 -134
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/resource-profile-blocks.d.ts +16 -0
- package/dist/core/resource-profile-blocks.d.ts.map +1 -0
- package/dist/core/resource-profile-blocks.js +120 -0
- package/dist/core/resource-profile-blocks.js.map +1 -0
- package/dist/core/sdk.d.ts +9 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +17 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +45 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +218 -10
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +3 -0
- package/dist/core/skills.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +17 -0
- package/dist/main.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/docs/extensions.md +18 -1
- package/docs/prompt-templates.md +1 -0
- package/docs/settings.md +43 -1
- package/docs/skills.md +12 -0
- 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
|
@@ -8,7 +8,8 @@ import { createEventBus } from "./event-bus.js";
|
|
|
8
8
|
import { createExtensionRuntime, disposeExtensionEventSubscriptions, loadExtensionFromFactory, loadExtensions, } from "./extensions/loader.js";
|
|
9
9
|
import { DefaultPackageManager } from "./package-manager.js";
|
|
10
10
|
import { loadPromptTemplates } from "./prompt-templates.js";
|
|
11
|
-
import {
|
|
11
|
+
import { mergeResourceProfileMap, parseResourceProfileBlocks, stripResourceProfileBlocks, } from "./resource-profile-blocks.js";
|
|
12
|
+
import { matchesResourceProfilePattern, SettingsManager } from "./settings-manager.js";
|
|
12
13
|
import { loadSkills } from "./skills.js";
|
|
13
14
|
import { createSourceInfo } from "./source-info.js";
|
|
14
15
|
function resolvePromptInput(input, description) {
|
|
@@ -44,9 +45,10 @@ export function scanContextFileThreats(content) {
|
|
|
44
45
|
return CONTEXT_THREAT_PATTERNS.filter(({ pattern }) => pattern.test(content)).map(({ label }) => label);
|
|
45
46
|
}
|
|
46
47
|
function sanitizeContextFileContent(filePath, content) {
|
|
47
|
-
const
|
|
48
|
+
const profileFreeContent = stripResourceProfileBlocks(content);
|
|
49
|
+
const findings = scanContextFileThreats(profileFreeContent);
|
|
48
50
|
if (findings.length === 0)
|
|
49
|
-
return
|
|
51
|
+
return profileFreeContent;
|
|
50
52
|
console.error(chalk.yellow(`Warning: Blocked context file ${filePath}: ${findings.join(", ")}`));
|
|
51
53
|
return `[BLOCKED: ${filePath} contained potential prompt injection (${findings.join(", ")}). Content not loaded.]`;
|
|
52
54
|
}
|
|
@@ -143,6 +145,7 @@ export class DefaultResourceLoader {
|
|
|
143
145
|
extensionThemeSourceInfos;
|
|
144
146
|
lastPromptPaths;
|
|
145
147
|
lastThemePaths;
|
|
148
|
+
pendingReloadSnapshot;
|
|
146
149
|
constructor(options) {
|
|
147
150
|
this.cwd = resolvePath(options.cwd);
|
|
148
151
|
this.agentDir = resolvePath(options.agentDir);
|
|
@@ -157,8 +160,8 @@ export class DefaultResourceLoader {
|
|
|
157
160
|
this.additionalSkillPaths = options.additionalSkillPaths ?? [];
|
|
158
161
|
this.additionalPromptTemplatePaths = options.additionalPromptTemplatePaths ?? [];
|
|
159
162
|
this.additionalThemePaths = options.additionalThemePaths ?? [];
|
|
160
|
-
this.extensionFactories = options.extensionFactories ?? [];
|
|
161
163
|
this.noExtensions = options.noExtensions ?? false;
|
|
164
|
+
this.extensionFactories = options.extensionFactories ?? [];
|
|
162
165
|
this.noSkills = options.noSkills ?? false;
|
|
163
166
|
this.noPromptTemplates = options.noPromptTemplates ?? false;
|
|
164
167
|
this.noThemes = options.noThemes ?? false;
|
|
@@ -235,156 +238,254 @@ export class DefaultResourceLoader {
|
|
|
235
238
|
this.updateThemesFromPaths(this.lastThemePaths);
|
|
236
239
|
}
|
|
237
240
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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;
|
|
241
288
|
disposeExtensionEventSubscriptions(this.extensionsResult.extensions);
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
+
}
|
|
256
311
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (resource.metadata.source !== "auto" && resource.metadata.origin !== "package") {
|
|
267
|
-
return resource.path;
|
|
268
|
-
}
|
|
269
|
-
try {
|
|
270
|
-
const stats = statSync(resource.path);
|
|
271
|
-
if (!stats.isDirectory()) {
|
|
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") {
|
|
272
321
|
return resource.path;
|
|
273
322
|
}
|
|
274
|
-
|
|
275
|
-
|
|
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;
|
|
338
|
+
}
|
|
276
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
|
+
}
|
|
277
347
|
}
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
metadataByPath.set(skillFile, resource.metadata);
|
|
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" });
|
|
282
351
|
}
|
|
283
|
-
return skillFile;
|
|
284
352
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
extensionsResult.extensions.push(...inlineExtensions.extensions);
|
|
309
|
-
extensionsResult.errors.push(...inlineExtensions.errors);
|
|
310
|
-
// Detect extension conflicts (tools, commands, flags with same names from different extensions)
|
|
311
|
-
// Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.
|
|
312
|
-
const conflicts = this.detectExtensionConflicts(extensionsResult.extensions);
|
|
313
|
-
for (const conflict of conflicts) {
|
|
314
|
-
extensionsResult.errors.push({ path: conflict.path, error: conflict.message });
|
|
315
|
-
}
|
|
316
|
-
for (const p of this.additionalExtensionPaths) {
|
|
317
|
-
if (isLocalPath(p)) {
|
|
318
|
-
const resolved = this.resolveResourcePath(p);
|
|
319
|
-
if (!existsSync(resolved)) {
|
|
320
|
-
extensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });
|
|
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
|
+
}
|
|
321
376
|
}
|
|
322
377
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
+
}
|
|
336
401
|
}
|
|
337
402
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
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
|
+
}
|
|
353
418
|
}
|
|
354
419
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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) {
|
|
426
|
+
const resolved = this.resolveResourcePath(p);
|
|
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 });
|
|
429
|
+
}
|
|
365
430
|
}
|
|
366
|
-
|
|
367
|
-
const agentsFiles = {
|
|
368
|
-
agentsFiles: this.noContextFiles
|
|
431
|
+
const rawAgentsFiles = this.noContextFiles
|
|
369
432
|
? []
|
|
370
433
|
: loadProjectContextFiles({
|
|
371
434
|
cwd: this.cwd,
|
|
372
435
|
agentDir: this.agentDir,
|
|
373
436
|
projectTrusted: this.settingsManager.isProjectTrusted(),
|
|
374
|
-
})
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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));
|
|
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);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
if (this.extensionsResult !== snapshot.extensionsResult) {
|
|
484
|
+
disposeExtensionEventSubscriptions(this.extensionsResult.extensions);
|
|
485
|
+
}
|
|
486
|
+
this.restoreSnapshot(snapshot);
|
|
487
|
+
throw error;
|
|
488
|
+
}
|
|
388
489
|
}
|
|
389
490
|
normalizeExtensionPaths(entries) {
|
|
390
491
|
return entries.map((entry) => {
|