@caupulican/pi-adaptative 0.80.59 → 0.80.61

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 (48) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/core/agent-session.d.ts +6 -0
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +42 -6
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/extension-metadata.d.ts +20 -0
  7. package/dist/core/extension-metadata.d.ts.map +1 -0
  8. package/dist/core/extension-metadata.js +115 -0
  9. package/dist/core/extension-metadata.js.map +1 -0
  10. package/dist/core/extensions/runner.d.ts +1 -0
  11. package/dist/core/extensions/runner.d.ts.map +1 -1
  12. package/dist/core/extensions/runner.js +3 -0
  13. package/dist/core/extensions/runner.js.map +1 -1
  14. package/dist/core/memory/providers/transcript-recall.d.ts +27 -0
  15. package/dist/core/memory/providers/transcript-recall.d.ts.map +1 -0
  16. package/dist/core/memory/providers/transcript-recall.js +154 -0
  17. package/dist/core/memory/providers/transcript-recall.js.map +1 -0
  18. package/dist/core/memory/transcript-index.d.ts +22 -0
  19. package/dist/core/memory/transcript-index.d.ts.map +1 -0
  20. package/dist/core/memory/transcript-index.js +85 -0
  21. package/dist/core/memory/transcript-index.js.map +1 -0
  22. package/dist/core/resource-loader.d.ts +26 -0
  23. package/dist/core/resource-loader.d.ts.map +1 -1
  24. package/dist/core/resource-loader.js +53 -14
  25. package/dist/core/resource-loader.js.map +1 -1
  26. package/dist/core/system-prompt.d.ts +3 -0
  27. package/dist/core/system-prompt.d.ts.map +1 -1
  28. package/dist/core/system-prompt.js +54 -7
  29. package/dist/core/system-prompt.js.map +1 -1
  30. package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
  31. package/dist/modes/interactive/components/profile-resource-editor.js +6 -2
  32. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  33. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  34. package/dist/modes/interactive/interactive-mode.js +6 -3
  35. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  36. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  37. package/dist/modes/rpc/rpc-mode.js +1 -1
  38. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  39. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  40. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  41. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  42. package/examples/extensions/sandbox/package-lock.json +2 -2
  43. package/examples/extensions/sandbox/package.json +1 -1
  44. package/examples/extensions/with-deps/package-lock.json +2 -2
  45. package/examples/extensions/with-deps/package.json +1 -1
  46. package/examples/sdk/12-full-control.ts +3 -0
  47. package/npm-shrinkwrap.json +12 -12
  48. package/package.json +4 -4
@@ -0,0 +1,85 @@
1
+ import { tokenize } from "../tools/skill-audit.js";
2
+ export class TranscriptIndex {
3
+ indexedDocs = [];
4
+ constructor(docs) {
5
+ this.indexedDocs = docs.map((doc) => ({
6
+ doc,
7
+ tokens: tokenize(doc.text),
8
+ }));
9
+ }
10
+ query(queryText, opts) {
11
+ const k = opts?.k ?? 5;
12
+ const minScore = opts?.minScore ?? 0.34;
13
+ const maxSnippetChars = opts?.maxSnippetChars ?? 600;
14
+ const qTokens = tokenize(queryText);
15
+ if (qTokens.length === 0 || this.indexedDocs.length === 0) {
16
+ return [];
17
+ }
18
+ const qSet = new Set(qTokens);
19
+ const hits = [];
20
+ for (const { doc, tokens } of this.indexedDocs) {
21
+ const dSet = new Set(tokens);
22
+ let intersection = 0;
23
+ for (const token of qSet) {
24
+ if (dSet.has(token)) {
25
+ intersection++;
26
+ }
27
+ }
28
+ const score = intersection / qSet.size;
29
+ if (score <= minScore) {
30
+ continue;
31
+ }
32
+ // Find matching indices of query tokens in the document text (case-insensitive)
33
+ const lowerText = doc.text.toLowerCase();
34
+ const matchIndices = [];
35
+ for (const token of qTokens) {
36
+ let pos = lowerText.indexOf(token);
37
+ while (pos !== -1) {
38
+ matchIndices.push(pos);
39
+ pos = lowerText.indexOf(token, pos + 1);
40
+ }
41
+ }
42
+ let bestStart = 0;
43
+ let bestEnd = Math.min(doc.text.length, maxSnippetChars);
44
+ if (matchIndices.length > 0) {
45
+ matchIndices.sort((a, b) => a - b);
46
+ let maxMatchesInWindow = 0;
47
+ for (const center of matchIndices) {
48
+ let start = Math.max(0, center - Math.floor(maxSnippetChars / 2));
49
+ const end = Math.min(doc.text.length, start + maxSnippetChars);
50
+ if (end - start < maxSnippetChars && start > 0) {
51
+ start = Math.max(0, end - maxSnippetChars);
52
+ }
53
+ let matches = 0;
54
+ for (const idx of matchIndices) {
55
+ if (idx >= start && idx < end) {
56
+ matches++;
57
+ }
58
+ }
59
+ if (matches > maxMatchesInWindow) {
60
+ maxMatchesInWindow = matches;
61
+ bestStart = start;
62
+ bestEnd = end;
63
+ }
64
+ }
65
+ }
66
+ const rawSnippet = doc.text.slice(bestStart, bestEnd);
67
+ const prefix = bestStart > 0 ? "..." : "";
68
+ const suffix = bestEnd < doc.text.length ? "..." : "";
69
+ const snippet = prefix + rawSnippet + suffix;
70
+ hits.push({
71
+ sessionId: doc.sessionId,
72
+ score,
73
+ snippet,
74
+ timestamp: doc.timestamp,
75
+ });
76
+ }
77
+ // Sort by score desc
78
+ hits.sort((a, b) => b.score - a.score);
79
+ return hits.slice(0, k);
80
+ }
81
+ get size() {
82
+ return this.indexedDocs.length;
83
+ }
84
+ }
85
+ //# sourceMappingURL=transcript-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript-index.js","sourceRoot":"","sources":["../../../src/core/memory/transcript-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAoBnD,MAAM,OAAO,eAAe;IACnB,WAAW,GAAiB,EAAE,CAAC;IAEvC,YAAY,IAAqB,EAAE;QAClC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CA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E,CAAC;wBAChC,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;4BAC/B,OAAO,EAAE,CAAC;wBACX,CAAC;oBACF,CAAC;oBAED,IAAI,OAAO,GAAG,kBAAkB,EAAE,CAAC;wBAClC,kBAAkB,GAAG,OAAO,CAAC;wBAC7B,SAAS,GAAG,KAAK,CAAC;wBAClB,OAAO,GAAG,GAAG,CAAC;oBACf,CAAC;gBACF,CAAC;YACF,CAAC;YAED,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACtD,MAAM,MAAM,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1C,MAAM,MAAM,GAAG,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACtD,MAAM,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;YAE7C,IAAI,CAAC,IAAI,CAAC;gBACT,SAAS,EAAE,GAAG,CAAC,SAAS;gBACxB,KAAK;gBACL,OAAO;gBACP,SAAS,EAAE,GAAG,CAAC,SAAS;aACxB,CAAC,CAAC;QACJ,CAAC;QAED,qBAAqB;QACrB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QAEvC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAAA,CACxB;IAED,IAAI,IAAI,GAAW;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;IAAA,CAC/B;CACD","sourcesContent":["import { tokenize } from \"../tools/skill-audit.ts\";\n\nexport interface RecallHit {\n\tsessionId: string;\n\tscore: number;\n\tsnippet: string;\n\ttimestamp?: string;\n}\n\nexport interface TranscriptDoc {\n\tsessionId: string;\n\ttimestamp?: string;\n\ttext: string;\n}\n\ninterface IndexedDoc {\n\tdoc: TranscriptDoc;\n\ttokens: string[];\n}\n\nexport class TranscriptIndex {\n\tprivate indexedDocs: IndexedDoc[] = [];\n\n\tconstructor(docs: TranscriptDoc[]) {\n\t\tthis.indexedDocs = docs.map((doc) => ({\n\t\t\tdoc,\n\t\t\ttokens: tokenize(doc.text),\n\t\t}));\n\t}\n\n\tquery(queryText: string, opts?: { k?: number; minScore?: number; maxSnippetChars?: number }): RecallHit[] {\n\t\tconst k = opts?.k ?? 5;\n\t\tconst minScore = opts?.minScore ?? 0.34;\n\t\tconst maxSnippetChars = opts?.maxSnippetChars ?? 600;\n\n\t\tconst qTokens = tokenize(queryText);\n\t\tif (qTokens.length === 0 || this.indexedDocs.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst qSet = new Set(qTokens);\n\t\tconst hits: RecallHit[] = [];\n\n\t\tfor (const { doc, tokens } of this.indexedDocs) {\n\t\t\tconst dSet = new Set(tokens);\n\t\t\tlet intersection = 0;\n\t\t\tfor (const token of qSet) {\n\t\t\t\tif (dSet.has(token)) {\n\t\t\t\t\tintersection++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst score = intersection / qSet.size;\n\t\t\tif (score <= minScore) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Find matching indices of query tokens in the document text (case-insensitive)\n\t\t\tconst lowerText = doc.text.toLowerCase();\n\t\t\tconst matchIndices: number[] = [];\n\t\t\tfor (const token of qTokens) {\n\t\t\t\tlet pos = lowerText.indexOf(token);\n\t\t\t\twhile (pos !== -1) {\n\t\t\t\t\tmatchIndices.push(pos);\n\t\t\t\t\tpos = lowerText.indexOf(token, pos + 1);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet bestStart = 0;\n\t\t\tlet bestEnd = Math.min(doc.text.length, maxSnippetChars);\n\n\t\t\tif (matchIndices.length > 0) {\n\t\t\t\tmatchIndices.sort((a, b) => a - b);\n\t\t\t\tlet maxMatchesInWindow = 0;\n\n\t\t\t\tfor (const center of matchIndices) {\n\t\t\t\t\tlet start = Math.max(0, center - Math.floor(maxSnippetChars / 2));\n\t\t\t\t\tconst end = Math.min(doc.text.length, start + maxSnippetChars);\n\t\t\t\t\tif (end - start < maxSnippetChars && start > 0) {\n\t\t\t\t\t\tstart = Math.max(0, end - maxSnippetChars);\n\t\t\t\t\t}\n\n\t\t\t\t\tlet matches = 0;\n\t\t\t\t\tfor (const idx of matchIndices) {\n\t\t\t\t\t\tif (idx >= start && idx < end) {\n\t\t\t\t\t\t\tmatches++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (matches > maxMatchesInWindow) {\n\t\t\t\t\t\tmaxMatchesInWindow = matches;\n\t\t\t\t\t\tbestStart = start;\n\t\t\t\t\t\tbestEnd = end;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst rawSnippet = doc.text.slice(bestStart, bestEnd);\n\t\t\tconst prefix = bestStart > 0 ? \"...\" : \"\";\n\t\t\tconst suffix = bestEnd < doc.text.length ? \"...\" : \"\";\n\t\t\tconst snippet = prefix + rawSnippet + suffix;\n\n\t\t\thits.push({\n\t\t\t\tsessionId: doc.sessionId,\n\t\t\t\tscore,\n\t\t\t\tsnippet,\n\t\t\t\ttimestamp: doc.timestamp,\n\t\t\t});\n\t\t}\n\n\t\t// Sort by score desc\n\t\thits.sort((a, b) => b.score - a.score);\n\n\t\treturn hits.slice(0, k);\n\t}\n\n\tget size(): number {\n\t\treturn this.indexedDocs.length;\n\t}\n}\n"]}
@@ -33,14 +33,20 @@ export interface ResourceLoader {
33
33
  skills: Skill[];
34
34
  diagnostics: ResourceDiagnostic[];
35
35
  };
36
+ /** Skills allowed by the currently active resource profile — use for selection/invocation/agent-visibility. */
37
+ getActiveSkills(): Skill[];
36
38
  getPrompts(): {
37
39
  prompts: PromptTemplate[];
38
40
  diagnostics: ResourceDiagnostic[];
39
41
  };
42
+ /** Prompt templates allowed by the currently active resource profile — use for selection/invocation/agent-visibility. */
43
+ getActivePrompts(): PromptTemplate[];
40
44
  getThemes(): {
41
45
  themes: Theme[];
42
46
  diagnostics: ResourceDiagnostic[];
43
47
  };
48
+ /** Themes allowed by the currently active resource profile. */
49
+ getActiveThemes(): Theme[];
44
50
  getAgentsFiles(): {
45
51
  agentsFiles: Array<{
46
52
  path: string;
@@ -172,14 +178,34 @@ export declare class DefaultResourceLoader implements ResourceLoader {
172
178
  skills: Skill[];
173
179
  diagnostics: ResourceDiagnostic[];
174
180
  };
181
+ /**
182
+ * Skills permitted by the CURRENTLY active resource profile (the loaded set intersected with the
183
+ * live profile filter). Use this everywhere a skill can be SELECTED, INVOKED, or shown to the
184
+ * agent — so neither the user (autocomplete / typed `/skill:`) nor the agent (system prompt /
185
+ * expansion / command API / RPC) can use a skill the active profile blocks, including after a
186
+ * runtime profile switch (router-managed / `/profile`). The full loaded set (`getSkills`) is
187
+ * reserved for the profile editor and resource listings, which must show blockable skills.
188
+ */
189
+ getActiveSkills(): Skill[];
175
190
  getPrompts(): {
176
191
  prompts: PromptTemplate[];
177
192
  diagnostics: ResourceDiagnostic[];
178
193
  };
194
+ /**
195
+ * Prompt templates permitted by the CURRENTLY active resource profile (the loaded set intersected with the
196
+ * live profile filter). Use this everywhere a prompt template can be SELECTED, INVOKED, or shown to the
197
+ * agent — so neither the user (autocomplete / typed slash command) nor the agent can use a prompt template
198
+ * the active profile blocks. The full loaded set (`getPrompts`) is reserved for the profile editor.
199
+ */
200
+ getActivePrompts(): PromptTemplate[];
179
201
  getThemes(): {
180
202
  themes: Theme[];
181
203
  diagnostics: ResourceDiagnostic[];
182
204
  };
205
+ /**
206
+ * Themes permitted by the CURRENTLY active resource profile.
207
+ */
208
+ getActiveThemes(): Theme[];
183
209
  getAgentsFiles(): {
184
210
  agentsFiles: Array<{
185
211
  path: string;
@@ -1 +1 @@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7B,OAAO,CAAC,wBAAwB;IAchC,OAAO,CAAC,qBAAqB;IA8C7B,OAAO,CAAC,2BAA2B;IA6CnC,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,UAAU;IA0ClB,OAAO,CAAC,iBAAiB;IA8BzB,OAAO,CAAC,iBAAiB;YASX,sBAAsB;IAqBpC,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,YAAY;IA2BpB,OAAO,CAAC,wBAAwB;IAchC,OAAO,CAAC,8BAA8B;IActC,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,wBAAwB;CAqChC","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { join, resolve, sep } from \"node:path\";\nimport chalk from \"chalk\";\nimport { CONFIG_DIR_NAME, getBundledPromptsDir, getBundledSkillsDir } from \"../config.ts\";\nimport { loadThemeFromPath, type Theme } from \"../modes/interactive/theme/theme.ts\";\nimport type { ResourceDiagnostic } from \"./diagnostics.ts\";\n\nexport type { ResourceCollision, ResourceDiagnostic } from \"./diagnostics.ts\";\n\nimport { canonicalizePath, isLocalPath, resolvePath } from \"../utils/paths.ts\";\nimport { createEventBus, type EventBus } from \"./event-bus.ts\";\nimport {\n\tcreateExtensionRuntime,\n\tdisposeExtensionEventSubscriptions,\n\tloadExtension,\n\tloadExtensionFromFactory,\n\tloadExtensions,\n} from \"./extensions/loader.ts\";\nimport type { Extension, ExtensionFactory, ExtensionRuntime, LoadExtensionsResult } from \"./extensions/types.ts\";\nimport { DefaultPackageManager, type PathMetadata } from \"./package-manager.ts\";\nimport type { PromptTemplate } from \"./prompt-templates.ts\";\nimport { loadPromptTemplates } from \"./prompt-templates.ts\";\nimport {\n\tmergeResourceProfileMap,\n\tparseResourceProfileBlocks,\n\tstripResourceProfileBlocks,\n} from \"./resource-profile-blocks.ts\";\nimport {\n\tmatchesResourceProfilePattern,\n\ttype ResourceProfileKind,\n\ttype ResourceProfileSettings,\n\tSettingsManager,\n} from \"./settings-manager.ts\";\nimport type { Skill } from \"./skills.ts\";\nimport { loadSkills } from \"./skills.ts\";\nimport { createSourceInfo, type SourceInfo } from \"./source-info.ts\";\n\nexport interface ResourceExtensionPaths {\n\tskillPaths?: Array<{ path: string; metadata: PathMetadata }>;\n\tpromptPaths?: Array<{ path: string; metadata: PathMetadata }>;\n\tthemePaths?: Array<{ path: string; metadata: PathMetadata }>;\n}\n\nexport interface ResourceReloadOptions {\n\t/** Throw instead of accepting a hot reload that produced extension load/conflict errors. */\n\tfailOnExtensionErrors?: boolean;\n\t/** Keep the previous extension generation alive until commitReload()/rollbackReload(). */\n\tdeferExtensionDispose?: boolean;\n}\n\nexport interface ResourceLoader {\n\tgetExtensions(): LoadExtensionsResult;\n\tgetSkills(): { skills: Skill[]; diagnostics: ResourceDiagnostic[] };\n\tgetPrompts(): { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] };\n\tgetThemes(): { themes: Theme[]; diagnostics: ResourceDiagnostic[] };\n\tgetAgentsFiles(): { agentsFiles: Array<{ path: string; content?: string }> };\n\tgetSystemPrompt(): string | undefined;\n\tgetAppendSystemPrompt(): string[];\n\tgetLoadedExtension(path: string): Extension | undefined;\n\tremoveLoadedExtension(path: string): Extension | undefined;\n\tloadSingleExtension(path: string): Promise<{ extension: Extension | null; error: string | null }>;\n\textendResources(paths: ResourceExtensionPaths): void;\n\treload(options?: ResourceReloadOptions): Promise<void>;\n\tcommitReload?(): void;\n\trollbackReload?(): void;\n\t/** Get all discoverable extension paths (enabled and disabled) */\n\tgetDiscoverableExtensionPaths(): Promise<string[]>;\n}\n\ninterface ResourceLoaderSnapshot {\n\textensionsResult: LoadExtensionsResult;\n\tskills: Skill[];\n\tskillDiagnostics: ResourceDiagnostic[];\n\tprompts: PromptTemplate[];\n\tpromptDiagnostics: ResourceDiagnostic[];\n\tthemes: Theme[];\n\tthemeDiagnostics: ResourceDiagnostic[];\n\tagentsFiles: Array<{ path: string; content?: string }>;\n\tsystemPrompt?: string;\n\tappendSystemPrompt: string[];\n\tlastSkillPaths: string[];\n\textensionSkillSourceInfos: Map<string, SourceInfo>;\n\textensionPromptSourceInfos: Map<string, SourceInfo>;\n\textensionThemeSourceInfos: Map<string, SourceInfo>;\n\tlastPromptPaths: string[];\n\tlastThemePaths: string[];\n}\n\nfunction resolvePromptInput(input: string | undefined, description: string): string | undefined {\n\tif (!input) {\n\t\treturn undefined;\n\t}\n\n\tif (existsSync(input)) {\n\t\ttry {\n\t\t\treturn readFileSync(input, \"utf-8\");\n\t\t} catch (error) {\n\t\t\tconsole.error(chalk.yellow(`Warning: Could not read ${description} file ${input}: ${error}`));\n\t\t\treturn input;\n\t\t}\n\t}\n\n\treturn input;\n}\n\nconst CONTEXT_THREAT_PATTERNS: Array<{ label: string; pattern: RegExp }> = [\n\t{\n\t\tlabel: \"instruction override\",\n\t\tpattern:\n\t\t\t/\\b(?:ignore|disregard|override|bypass)\\b.{0,80}\\b(?:previous|prior|above|system|developer|agent)\\b.{0,80}\\binstructions?\\b/i,\n\t},\n\t{\n\t\tlabel: \"secret exfiltration\",\n\t\tpattern:\n\t\t\t/\\b(?:reveal|print|dump|exfiltrate|send|upload)\\b.{0,80}\\b(?:secrets?|tokens?|api[_ -]?keys?|credentials?|environment variables?|\\.env)\\b/i,\n\t},\n\t{\n\t\tlabel: \"hidden instruction\",\n\t\tpattern: /\\b(?:do not tell|don't tell|hide this from)\\b.{0,80}\\b(?:user|operator|developer)\\b/i,\n\t},\n];\n\nexport function scanContextFileThreats(content: string): string[] {\n\treturn CONTEXT_THREAT_PATTERNS.filter(({ pattern }) => pattern.test(content)).map(({ label }) => label);\n}\n\nfunction sanitizeContextFileContent(filePath: string, content: string): string {\n\tconst profileFreeContent = stripResourceProfileBlocks(content);\n\tconst findings = scanContextFileThreats(profileFreeContent);\n\tif (findings.length === 0) return profileFreeContent;\n\tconsole.error(chalk.yellow(`Warning: Blocked context file ${filePath}: ${findings.join(\", \")}`));\n\treturn `[BLOCKED: ${filePath} contained potential prompt injection (${findings.join(\", \")}). Content not loaded.]`;\n}\n\nfunction loadContextFilesFromDir(dir: string): Array<{ path: string; content: string }> {\n\tconst candidates = [\"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\", \"GEMINI.md\", \"GEMINI.MD\"];\n\tconst files: Array<{ path: string; content: string }> = [];\n\tfor (const filename of candidates) {\n\t\tconst filePath = join(dir, filename);\n\t\tif (existsSync(filePath)) {\n\t\t\ttry {\n\t\t\t\tconst content = readFileSync(filePath, \"utf-8\");\n\t\t\t\tfiles.push({\n\t\t\t\t\tpath: filePath,\n\t\t\t\t\tcontent: sanitizeContextFileContent(filePath, content),\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(chalk.yellow(`Warning: Could not read ${filePath}: ${error}`));\n\t\t\t}\n\t\t}\n\t}\n\treturn files;\n}\n\nexport function loadProjectContextFiles(options: {\n\tcwd: string;\n\tagentDir: string;\n\tprojectTrusted?: boolean;\n}): Array<{ path: string; content?: string }> {\n\tconst resolvedCwd = resolvePath(options.cwd);\n\tconst resolvedAgentDir = resolvePath(options.agentDir);\n\n\tconst contextFiles: Array<{ path: string; content?: string }> = [];\n\tconst seenPaths = new Set<string>();\n\n\tfor (const globalContext of loadContextFilesFromDir(resolvedAgentDir)) {\n\t\tcontextFiles.push(globalContext);\n\t\tseenPaths.add(globalContext.path);\n\t}\n\n\tif (options.projectTrusted !== false) {\n\t\tconst ancestorContextFiles: Array<{ path: string; content?: string }> = [];\n\n\t\tlet currentDir = resolvedCwd;\n\t\tconst root = resolve(\"/\");\n\n\t\twhile (true) {\n\t\t\tconst contextFilesInDir = loadContextFilesFromDir(currentDir).filter(\n\t\t\t\t(contextFile) => !seenPaths.has(contextFile.path),\n\t\t\t);\n\t\t\tif (contextFilesInDir.length > 0) {\n\t\t\t\tancestorContextFiles.unshift(...contextFilesInDir);\n\t\t\t\tfor (const contextFile of contextFilesInDir) {\n\t\t\t\t\tseenPaths.add(contextFile.path);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentDir === root) break;\n\n\t\t\tconst parentDir = resolve(currentDir, \"..\");\n\t\t\tif (parentDir === currentDir) break;\n\t\t\tcurrentDir = parentDir;\n\t\t}\n\n\t\tcontextFiles.push(...ancestorContextFiles);\n\t}\n\n\treturn contextFiles;\n}\n\nexport interface DefaultResourceLoaderOptions {\n\tcwd: string;\n\tagentDir: string;\n\tsettingsManager?: SettingsManager;\n\teventBus?: EventBus;\n\tadditionalExtensionPaths?: string[];\n\tadditionalSkillPaths?: string[];\n\tadditionalPromptTemplatePaths?: string[];\n\tadditionalThemePaths?: string[];\n\textensionFactories?: ExtensionFactory[];\n\tnoExtensions?: boolean;\n\tnoSkills?: boolean;\n\tnoPromptTemplates?: boolean;\n\tnoThemes?: boolean;\n\tnoContextFiles?: boolean;\n\tsystemPrompt?: string;\n\tappendSystemPrompt?: string[];\n\textensionsOverride?: (base: LoadExtensionsResult) => LoadExtensionsResult;\n\tskillsOverride?: (base: { skills: Skill[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tskills: Skill[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tpromptsOverride?: (base: { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tprompts: PromptTemplate[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tthemesOverride?: (base: { themes: Theme[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tthemes: Theme[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tagentsFilesOverride?: (base: { agentsFiles: Array<{ path: string; content?: string }> }) => {\n\t\tagentsFiles: Array<{ path: string; content?: string }>;\n\t};\n\tsystemPromptOverride?: (base: string | undefined) => string | undefined;\n\tappendSystemPromptOverride?: (base: string[]) => string[];\n}\n\nexport class DefaultResourceLoader implements ResourceLoader {\n\tprivate cwd: string;\n\tprivate agentDir: string;\n\tprivate settingsManager: SettingsManager;\n\tprivate eventBus: EventBus;\n\tprivate packageManager: DefaultPackageManager;\n\tprivate additionalExtensionPaths: string[];\n\tprivate additionalSkillPaths: string[];\n\tprivate additionalPromptTemplatePaths: string[];\n\tprivate additionalThemePaths: string[];\n\tprivate extensionFactories: ExtensionFactory[];\n\tprivate noExtensions: boolean;\n\tprivate noSkills: boolean;\n\tprivate noPromptTemplates: boolean;\n\tprivate noThemes: boolean;\n\tprivate noContextFiles: boolean;\n\tprivate systemPromptSource?: string;\n\tprivate appendSystemPromptSource?: string[];\n\tprivate extensionsOverride?: (base: LoadExtensionsResult) => LoadExtensionsResult;\n\tprivate skillsOverride?: (base: { skills: Skill[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tskills: Skill[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tprivate promptsOverride?: (base: { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tprompts: PromptTemplate[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tprivate themesOverride?: (base: { themes: Theme[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tthemes: Theme[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tprivate agentsFilesOverride?: (base: { agentsFiles: Array<{ path: string; content?: string }> }) => {\n\t\tagentsFiles: Array<{ path: string; content?: string }>;\n\t};\n\tprivate systemPromptOverride?: (base: string | undefined) => string | undefined;\n\tprivate appendSystemPromptOverride?: (base: string[]) => string[];\n\n\tprivate extensionsResult: LoadExtensionsResult;\n\tprivate skills: Skill[];\n\tprivate skillDiagnostics: ResourceDiagnostic[];\n\tprivate prompts: PromptTemplate[];\n\tprivate promptDiagnostics: ResourceDiagnostic[];\n\tprivate themes: Theme[];\n\tprivate themeDiagnostics: ResourceDiagnostic[];\n\tprivate agentsFiles: Array<{ path: string; content?: string }>;\n\tprivate systemPrompt?: string;\n\tprivate appendSystemPrompt: string[];\n\tprivate lastSkillPaths: string[];\n\tprivate extensionSkillSourceInfos: Map<string, SourceInfo>;\n\tprivate extensionPromptSourceInfos: Map<string, SourceInfo>;\n\tprivate extensionThemeSourceInfos: Map<string, SourceInfo>;\n\tprivate lastPromptPaths: string[];\n\tprivate lastThemePaths: string[];\n\tprivate pendingReloadSnapshot: ResourceLoaderSnapshot | undefined;\n\n\tconstructor(options: DefaultResourceLoaderOptions) {\n\t\tthis.cwd = resolvePath(options.cwd);\n\t\tthis.agentDir = resolvePath(options.agentDir);\n\t\tthis.settingsManager = options.settingsManager ?? SettingsManager.create(this.cwd, this.agentDir);\n\t\tthis.eventBus = options.eventBus ?? createEventBus();\n\t\tthis.packageManager = new DefaultPackageManager({\n\t\t\tcwd: this.cwd,\n\t\t\tagentDir: this.agentDir,\n\t\t\tsettingsManager: this.settingsManager,\n\t\t});\n\t\tthis.additionalExtensionPaths = options.additionalExtensionPaths ?? [];\n\t\tthis.additionalSkillPaths = options.additionalSkillPaths ?? [];\n\t\tthis.additionalPromptTemplatePaths = options.additionalPromptTemplatePaths ?? [];\n\t\tthis.additionalThemePaths = options.additionalThemePaths ?? [];\n\t\tthis.noExtensions = options.noExtensions ?? false;\n\t\tthis.extensionFactories = options.extensionFactories ?? [];\n\t\tthis.noSkills = options.noSkills ?? false;\n\t\tthis.noPromptTemplates = options.noPromptTemplates ?? false;\n\t\tthis.noThemes = options.noThemes ?? false;\n\t\tthis.noContextFiles = options.noContextFiles ?? false;\n\t\tthis.systemPromptSource = options.systemPrompt;\n\t\tthis.appendSystemPromptSource = options.appendSystemPrompt;\n\t\tthis.extensionsOverride = options.extensionsOverride;\n\t\tthis.skillsOverride = options.skillsOverride;\n\t\tthis.promptsOverride = options.promptsOverride;\n\t\tthis.themesOverride = options.themesOverride;\n\t\tthis.agentsFilesOverride = options.agentsFilesOverride;\n\t\tthis.systemPromptOverride = options.systemPromptOverride;\n\t\tthis.appendSystemPromptOverride = options.appendSystemPromptOverride;\n\n\t\tthis.extensionsResult = { extensions: [], errors: [], runtime: createExtensionRuntime() };\n\t\tthis.skills = [];\n\t\tthis.skillDiagnostics = [];\n\t\tthis.prompts = [];\n\t\tthis.promptDiagnostics = [];\n\t\tthis.themes = [];\n\t\tthis.themeDiagnostics = [];\n\t\tthis.agentsFiles = [];\n\t\tthis.appendSystemPrompt = [];\n\t\tthis.lastSkillPaths = [];\n\t\tthis.extensionSkillSourceInfos = new Map();\n\t\tthis.extensionPromptSourceInfos = new Map();\n\t\tthis.extensionThemeSourceInfos = new Map();\n\t\tthis.lastPromptPaths = [];\n\t\tthis.lastThemePaths = [];\n\t}\n\n\tgetExtensions(): LoadExtensionsResult {\n\t\treturn this.extensionsResult;\n\t}\n\n\tgetSkills(): { skills: Skill[]; diagnostics: ResourceDiagnostic[] } {\n\t\treturn { skills: this.skills, diagnostics: this.skillDiagnostics };\n\t}\n\n\tgetPrompts(): { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] } {\n\t\treturn { prompts: this.prompts, diagnostics: this.promptDiagnostics };\n\t}\n\n\tgetThemes(): { themes: Theme[]; diagnostics: ResourceDiagnostic[] } {\n\t\treturn { themes: this.themes, diagnostics: this.themeDiagnostics };\n\t}\n\n\tgetAgentsFiles(): { agentsFiles: Array<{ path: string; content?: string }> } {\n\t\treturn { agentsFiles: this.agentsFiles };\n\t}\n\n\tgetSystemPrompt(): string | undefined {\n\t\treturn this.systemPrompt;\n\t}\n\n\tgetAppendSystemPrompt(): string[] {\n\t\treturn this.appendSystemPrompt;\n\t}\n\n\t/**\n\t * Get all discoverable extension paths (enabled and disabled).\n\t * Used for profile resource filtering to show the full universe of available extensions.\n\t */\n\tasync getDiscoverableExtensionPaths(): Promise<string[]> {\n\t\tawait this.settingsManager.reload();\n\t\tconst resolvedPaths = await this.packageManager.resolve();\n\t\tconst cliExtensionPaths = await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths, {\n\t\t\ttemporary: true,\n\t\t});\n\t\t// Return all paths (enabled and disabled) from both resolved and CLI sources\n\t\tconst allPaths = new Set<string>();\n\t\tfor (const resource of resolvedPaths.extensions) {\n\t\t\tallPaths.add(resource.path);\n\t\t}\n\t\tfor (const resource of cliExtensionPaths.extensions) {\n\t\t\tallPaths.add(resource.path);\n\t\t}\n\t\treturn Array.from(allPaths);\n\t}\n\n\t/**\n\t * Get a loaded extension by path.\n\t * Matches by path or resolvedPath.\n\t */\n\tgetLoadedExtension(extensionPath: string): Extension | undefined {\n\t\treturn this.extensionsResult.extensions.find(\n\t\t\t(ext) => ext.path === extensionPath || ext.resolvedPath === extensionPath,\n\t\t);\n\t}\n\n\t/**\n\t * Remove and return a loaded extension from the extensions array.\n\t */\n\tremoveLoadedExtension(extensionPath: string): Extension | undefined {\n\t\tconst index = this.extensionsResult.extensions.findIndex(\n\t\t\t(ext) => ext.path === extensionPath || ext.resolvedPath === extensionPath,\n\t\t);\n\t\tif (index === -1) return undefined;\n\t\tconst [ext] = this.extensionsResult.extensions.splice(index, 1);\n\t\treturn ext;\n\t}\n\n\t/**\n\t * Load a single extension with fresh import, reusing the shared runtime.\n\t * Returns the loaded extension or null with error details.\n\t */\n\tasync loadSingleExtension(extensionPath: string): Promise<{ extension: Extension | null; error: string | null }> {\n\t\tconst result = await loadExtension(extensionPath, this.cwd, this.eventBus, this.extensionsResult.runtime, {\n\t\t\tfresh: true,\n\t\t});\n\t\tif (result.extension && !result.error) {\n\t\t\tconst loaded = result.extension;\n\t\t\t// Drop any stale generation at the same path, then register the freshly loaded one so\n\t\t\t// _buildRuntime() aggregates it.\n\t\t\tthis.extensionsResult.extensions = this.extensionsResult.extensions.filter(\n\t\t\t\t(e) => e.path !== loaded.path && e.resolvedPath !== loaded.resolvedPath,\n\t\t\t);\n\t\t\tthis.extensionsResult.extensions.push(loaded);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Apply the active resource-profile allow/block to a list of discovered resource paths.\n\t * Used for every source that does NOT pass through the package manager's\n\t * resolve/applyResourceProfileFilters pipeline (external roots, bundled defaults, and\n\t * extension-contributed resources) so no source bypasses the active profile.\n\t */\n\tprivate filterPathsByProfile(paths: string[], kind: ResourceProfileKind): string[] {\n\t\tconst filter = this.settingsManager.getResourceProfileFilter(kind);\n\t\tif (filter.allow.length === 0 && filter.block.length === 0) return paths;\n\t\treturn paths.filter((p) => {\n\t\t\tconst allowed = filter.allow.length === 0 || matchesResourceProfilePattern(p, filter.allow, this.cwd);\n\t\t\tconst blocked = matchesResourceProfilePattern(p, filter.block, this.cwd);\n\t\t\treturn allowed && !blocked;\n\t\t});\n\t}\n\n\textendResources(paths: ResourceExtensionPaths): void {\n\t\t// Extension-contributed resources (via the resources_discover event) must respect the\n\t\t// active resource profile too — otherwise an allowed extension can re-introduce skills/\n\t\t// prompts/themes the profile blocks.\n\t\tconst allowPath = (entry: { path: string }, kind: ResourceProfileKind): boolean =>\n\t\t\tthis.filterPathsByProfile([entry.path], kind).length > 0;\n\t\tconst skillPaths = this.normalizeExtensionPaths(paths.skillPaths ?? []).filter((e) => allowPath(e, \"skills\"));\n\t\tconst promptPaths = this.normalizeExtensionPaths(paths.promptPaths ?? []).filter((e) => allowPath(e, \"prompts\"));\n\t\tconst themePaths = this.normalizeExtensionPaths(paths.themePaths ?? []).filter((e) => allowPath(e, \"themes\"));\n\n\t\tfor (const entry of skillPaths) {\n\t\t\tthis.extensionSkillSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));\n\t\t}\n\t\tfor (const entry of promptPaths) {\n\t\t\tthis.extensionPromptSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));\n\t\t}\n\t\tfor (const entry of themePaths) {\n\t\t\tthis.extensionThemeSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));\n\t\t}\n\n\t\tif (skillPaths.length > 0) {\n\t\t\tthis.lastSkillPaths = this.mergePaths(\n\t\t\t\tthis.lastSkillPaths,\n\t\t\t\tskillPaths.map((entry) => entry.path),\n\t\t\t);\n\t\t\tthis.updateSkillsFromPaths(this.lastSkillPaths);\n\t\t}\n\n\t\tif (promptPaths.length > 0) {\n\t\t\tthis.lastPromptPaths = this.mergePaths(\n\t\t\t\tthis.lastPromptPaths,\n\t\t\t\tpromptPaths.map((entry) => entry.path),\n\t\t\t);\n\t\t\tthis.updatePromptsFromPaths(this.lastPromptPaths);\n\t\t}\n\n\t\tif (themePaths.length > 0) {\n\t\t\tthis.lastThemePaths = this.mergePaths(\n\t\t\t\tthis.lastThemePaths,\n\t\t\t\tthemePaths.map((entry) => entry.path),\n\t\t\t);\n\t\t\tthis.updateThemesFromPaths(this.lastThemePaths);\n\t\t}\n\t}\n\n\tprivate createSnapshot(): ResourceLoaderSnapshot {\n\t\treturn {\n\t\t\textensionsResult: this.extensionsResult,\n\t\t\tskills: this.skills,\n\t\t\tskillDiagnostics: this.skillDiagnostics,\n\t\t\tprompts: this.prompts,\n\t\t\tpromptDiagnostics: this.promptDiagnostics,\n\t\t\tthemes: this.themes,\n\t\t\tthemeDiagnostics: this.themeDiagnostics,\n\t\t\tagentsFiles: this.agentsFiles,\n\t\t\tsystemPrompt: this.systemPrompt,\n\t\t\tappendSystemPrompt: this.appendSystemPrompt,\n\t\t\tlastSkillPaths: this.lastSkillPaths,\n\t\t\textensionSkillSourceInfos: this.extensionSkillSourceInfos,\n\t\t\textensionPromptSourceInfos: this.extensionPromptSourceInfos,\n\t\t\textensionThemeSourceInfos: this.extensionThemeSourceInfos,\n\t\t\tlastPromptPaths: this.lastPromptPaths,\n\t\t\tlastThemePaths: this.lastThemePaths,\n\t\t};\n\t}\n\n\tprivate restoreSnapshot(snapshot: ResourceLoaderSnapshot): void {\n\t\tthis.extensionsResult = snapshot.extensionsResult;\n\t\tthis.skills = snapshot.skills;\n\t\tthis.skillDiagnostics = snapshot.skillDiagnostics;\n\t\tthis.prompts = snapshot.prompts;\n\t\tthis.promptDiagnostics = snapshot.promptDiagnostics;\n\t\tthis.themes = snapshot.themes;\n\t\tthis.themeDiagnostics = snapshot.themeDiagnostics;\n\t\tthis.agentsFiles = snapshot.agentsFiles;\n\t\tthis.systemPrompt = snapshot.systemPrompt;\n\t\tthis.appendSystemPrompt = snapshot.appendSystemPrompt;\n\t\tthis.lastSkillPaths = snapshot.lastSkillPaths;\n\t\tthis.extensionSkillSourceInfos = snapshot.extensionSkillSourceInfos;\n\t\tthis.extensionPromptSourceInfos = snapshot.extensionPromptSourceInfos;\n\t\tthis.extensionThemeSourceInfos = snapshot.extensionThemeSourceInfos;\n\t\tthis.lastPromptPaths = snapshot.lastPromptPaths;\n\t\tthis.lastThemePaths = snapshot.lastThemePaths;\n\t}\n\n\tasync commitReload(): Promise<void> {\n\t\tif (!this.pendingReloadSnapshot) return;\n\t\tawait disposeExtensionEventSubscriptions(this.pendingReloadSnapshot.extensionsResult.extensions);\n\t\tthis.pendingReloadSnapshot = undefined;\n\t}\n\n\tasync rollbackReload(): Promise<void> {\n\t\tif (!this.pendingReloadSnapshot) return;\n\t\tawait disposeExtensionEventSubscriptions(this.extensionsResult.extensions);\n\t\tthis.restoreSnapshot(this.pendingReloadSnapshot);\n\t\tthis.pendingReloadSnapshot = undefined;\n\t}\n\n\tasync reload(options: ResourceReloadOptions = {}): Promise<void> {\n\t\tconst snapshot = this.createSnapshot();\n\t\tthis.pendingReloadSnapshot = undefined;\n\t\ttry {\n\t\t\tawait this.settingsManager.reload();\n\t\t\tconst resolvedPaths = await this.packageManager.resolve();\n\t\t\tconst cliExtensionPaths = await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths, {\n\t\t\t\ttemporary: true,\n\t\t\t});\n\t\t\tconst metadataByPath = new Map<string, PathMetadata>();\n\n\t\t\tthis.extensionSkillSourceInfos = new Map();\n\t\t\tthis.extensionPromptSourceInfos = new Map();\n\t\t\tthis.extensionThemeSourceInfos = new Map();\n\n\t\t\t// Helper to extract enabled paths and store metadata\n\t\t\tconst getEnabledResources = (\n\t\t\t\tresources: Array<{ path: string; enabled: boolean; metadata: PathMetadata }>,\n\t\t\t): Array<{ path: string; enabled: boolean; metadata: PathMetadata }> => {\n\t\t\t\tfor (const r of resources) {\n\t\t\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\t\t\tmetadataByPath.set(r.path, r.metadata);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn resources.filter((r) => r.enabled);\n\t\t\t};\n\n\t\t\tconst getEnabledPaths = (\n\t\t\t\tresources: Array<{ path: string; enabled: boolean; metadata: PathMetadata }>,\n\t\t\t): string[] => getEnabledResources(resources).map((r) => r.path);\n\t\t\tconst enabledExtensions = getEnabledPaths(resolvedPaths.extensions);\n\t\t\tconst enabledSkillResources = getEnabledResources(resolvedPaths.skills);\n\t\t\tconst enabledPrompts = getEnabledPaths(resolvedPaths.prompts);\n\t\t\tconst enabledThemes = getEnabledPaths(resolvedPaths.themes);\n\n\t\t\tconst mapSkillPath = (resource: { path: string; metadata: PathMetadata }): string => {\n\t\t\t\tif (resource.metadata.source !== \"auto\" && resource.metadata.origin !== \"package\") {\n\t\t\t\t\treturn resource.path;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(resource.path);\n\t\t\t\t\tif (!stats.isDirectory()) {\n\t\t\t\t\t\treturn resource.path;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\treturn resource.path;\n\t\t\t\t}\n\t\t\t\tconst skillFile = join(resource.path, \"SKILL.md\");\n\t\t\t\tif (existsSync(skillFile)) {\n\t\t\t\t\tif (!metadataByPath.has(skillFile)) {\n\t\t\t\t\t\tmetadataByPath.set(skillFile, resource.metadata);\n\t\t\t\t\t}\n\t\t\t\t\treturn skillFile;\n\t\t\t\t}\n\t\t\t\treturn resource.path;\n\t\t\t};\n\n\t\t\tconst enabledSkills = enabledSkillResources.map(mapSkillPath);\n\n\t\t\t// Add CLI paths metadata\n\t\t\tfor (const r of cliExtensionPaths.extensions) {\n\t\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\t\tmetadataByPath.set(r.path, { source: \"cli\", scope: \"temporary\", origin: \"top-level\" });\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const r of cliExtensionPaths.skills) {\n\t\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\t\tmetadataByPath.set(r.path, { source: \"cli\", scope: \"temporary\", origin: \"top-level\" });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst cliEnabledExtensions = getEnabledPaths(cliExtensionPaths.extensions);\n\t\t\tconst cliEnabledSkills = getEnabledPaths(cliExtensionPaths.skills);\n\t\t\tconst cliEnabledPrompts = getEnabledPaths(cliExtensionPaths.prompts);\n\t\t\tconst cliEnabledThemes = getEnabledPaths(cliExtensionPaths.themes);\n\n\t\t\t// Gather effective external resource roots\n\t\t\tconst effectiveRoots = this.settingsManager.getEffectiveExternalResourceRoots();\n\n\t\t\tconst filterPathsByProfile = (paths: string[], kind: ResourceProfileKind): string[] =>\n\t\t\t\tthis.filterPathsByProfile(paths, kind);\n\n\t\t\t// Discover external extensions\n\t\t\tconst externalExtensions: string[] = [];\n\t\t\tfor (const root of effectiveRoots) {\n\t\t\t\tconst extDir = join(root, \"extensions\");\n\t\t\t\tif (existsSync(extDir)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst entries = readdirSync(extDir, { withFileTypes: true });\n\t\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\t\tlet isDir = entry.isDirectory();\n\t\t\t\t\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst stats = statSync(join(extDir, entry.name));\n\t\t\t\t\t\t\t\t\tisDir = stats.isDirectory();\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (isDir) {\n\t\t\t\t\t\t\t\tconst entryPath = join(extDir, entry.name);\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\texistsSync(join(entryPath, \"index.ts\")) ||\n\t\t\t\t\t\t\t\t\texistsSync(join(entryPath, \"index.js\")) ||\n\t\t\t\t\t\t\t\t\texistsSync(join(entryPath, \"package.json\"))\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\texternalExtensions.push(entryPath);\n\t\t\t\t\t\t\t\t\tmetadataByPath.set(entryPath, { source: \"external\", scope: \"user\", origin: \"top-level\" });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// silent\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst extensionPaths = this.noExtensions\n\t\t\t\t? cliEnabledExtensions\n\t\t\t\t: this.mergePaths(cliEnabledExtensions, [\n\t\t\t\t\t\t...enabledExtensions,\n\t\t\t\t\t\t...filterPathsByProfile(externalExtensions, \"extensions\"),\n\t\t\t\t\t]);\n\n\t\t\tconst extensionsResult = await loadExtensions(extensionPaths, this.cwd, this.eventBus);\n\t\t\tconst inlineExtensions = await this.loadExtensionFactories(extensionsResult.runtime);\n\t\t\textensionsResult.extensions.push(...inlineExtensions.extensions);\n\t\t\textensionsResult.errors.push(...inlineExtensions.errors);\n\n\t\t\t// Detect extension conflicts (tools, commands, flags with same names from different extensions)\n\t\t\t// Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.\n\t\t\tconst conflicts = this.detectExtensionConflicts(extensionsResult.extensions);\n\t\t\tfor (const conflict of conflicts) {\n\t\t\t\textensionsResult.errors.push({ path: conflict.path, error: conflict.message });\n\t\t\t}\n\n\t\t\tfor (const p of this.additionalExtensionPaths) {\n\t\t\t\tif (isLocalPath(p)) {\n\t\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\t\tif (!existsSync(resolved)) {\n\t\t\t\t\t\textensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst resolvedExtensionsResult = this.extensionsOverride\n\t\t\t\t? this.extensionsOverride(extensionsResult)\n\t\t\t\t: extensionsResult;\n\t\t\tif (options.failOnExtensionErrors && resolvedExtensionsResult.errors.length > 0) {\n\t\t\t\tconst summary = resolvedExtensionsResult.errors\n\t\t\t\t\t.slice(0, 6)\n\t\t\t\t\t.map((error) => `${error.path}: ${error.error}`)\n\t\t\t\t\t.join(\"; \");\n\t\t\t\tthrow new Error(`Extension reload failed preflight: ${summary}`);\n\t\t\t}\n\t\t\tthis.extensionsResult = resolvedExtensionsResult;\n\t\t\tthis.applyExtensionSourceInfo(this.extensionsResult.extensions, metadataByPath);\n\n\t\t\t// Discover external skills\n\t\t\tconst externalSkills: string[] = [];\n\t\t\tfor (const root of effectiveRoots) {\n\t\t\t\tconst skillsDir = join(root, \"skills\");\n\t\t\t\tif (existsSync(skillsDir)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst entries = readdirSync(skillsDir, { withFileTypes: true });\n\t\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\t\tlet isDir = entry.isDirectory();\n\t\t\t\t\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst stats = statSync(join(skillsDir, entry.name));\n\t\t\t\t\t\t\t\t\tisDir = stats.isDirectory();\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (isDir) {\n\t\t\t\t\t\t\t\tconst entryPath = join(skillsDir, entry.name);\n\t\t\t\t\t\t\t\tconst skillFile = join(entryPath, \"SKILL.md\");\n\t\t\t\t\t\t\t\tconst targetPath = existsSync(skillFile) ? skillFile : entryPath;\n\t\t\t\t\t\t\t\texternalSkills.push(targetPath);\n\t\t\t\t\t\t\t\tmetadataByPath.set(targetPath, { source: \"external\", scope: \"user\", origin: \"top-level\" });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// silent\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Build skill paths with precedence: CLI > user/project > bundled > additional.\n\t\t\t// Bundled skills are expanded into individual SKILL.md paths so they pass through the\n\t\t\t// resource-profile filter exactly like user/external skills (no source bypasses the profile).\n\t\t\tconst bundledSkillsDir = getBundledSkillsDir();\n\t\t\tconst bundledSkillPaths: string[] = [];\n\t\t\tif (existsSync(bundledSkillsDir)) {\n\t\t\t\ttry {\n\t\t\t\t\tfor (const entry of readdirSync(bundledSkillsDir, { withFileTypes: true })) {\n\t\t\t\t\t\tif (!entry.isDirectory()) continue;\n\t\t\t\t\t\tconst entryPath = join(bundledSkillsDir, entry.name);\n\t\t\t\t\t\tconst skillFile = join(entryPath, \"SKILL.md\");\n\t\t\t\t\t\tbundledSkillPaths.push(existsSync(skillFile) ? skillFile : entryPath);\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// silent\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst skillPaths = this.noSkills\n\t\t\t\t? this.mergePaths([...cliEnabledSkills], this.additionalSkillPaths)\n\t\t\t\t: this.mergePaths(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t...cliEnabledSkills,\n\t\t\t\t\t\t\t...enabledSkills,\n\t\t\t\t\t\t\t...filterPathsByProfile(externalSkills, \"skills\"),\n\t\t\t\t\t\t\t...filterPathsByProfile(bundledSkillPaths, \"skills\"),\n\t\t\t\t\t\t],\n\t\t\t\t\t\tthis.additionalSkillPaths,\n\t\t\t\t\t);\n\n\t\t\tthis.lastSkillPaths = skillPaths;\n\t\t\tthis.updateSkillsFromPaths(skillPaths, metadataByPath);\n\t\t\tfor (const p of this.additionalSkillPaths) {\n\t\t\t\tif (isLocalPath(p)) {\n\t\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\t\tif (!existsSync(resolved) && !this.skillDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\t\tthis.skillDiagnostics.push({ type: \"error\", message: \"Skill path does not exist\", path: resolved });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Discover external prompts\n\t\t\tconst externalPrompts: string[] = [];\n\t\t\tfor (const root of effectiveRoots) {\n\t\t\t\tconst promptsDir = join(root, \"prompts\");\n\t\t\t\tif (existsSync(promptsDir)) {\n\t\t\t\t\tconst files = collectFilesRecursively(promptsDir, /\\.md$/);\n\t\t\t\t\tfor (const f of files) {\n\t\t\t\t\t\texternalPrompts.push(f);\n\t\t\t\t\t\tmetadataByPath.set(f, { source: \"external\", scope: \"user\", origin: \"top-level\" });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Bundled prompts expanded into individual files so they pass through the profile filter too.\n\t\t\tconst bundledPromptsDir = getBundledPromptsDir();\n\t\t\tconst bundledPromptPaths = existsSync(bundledPromptsDir)\n\t\t\t\t? collectFilesRecursively(bundledPromptsDir, /\\.md$/)\n\t\t\t\t: [];\n\t\t\tconst promptPaths = this.noPromptTemplates\n\t\t\t\t? this.mergePaths(cliEnabledPrompts, this.additionalPromptTemplatePaths)\n\t\t\t\t: this.mergePaths(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t...cliEnabledPrompts,\n\t\t\t\t\t\t\t...enabledPrompts,\n\t\t\t\t\t\t\t...filterPathsByProfile(externalPrompts, \"prompts\"),\n\t\t\t\t\t\t\t...filterPathsByProfile(bundledPromptPaths, \"prompts\"),\n\t\t\t\t\t\t],\n\t\t\t\t\t\tthis.additionalPromptTemplatePaths,\n\t\t\t\t\t);\n\n\t\t\tthis.lastPromptPaths = promptPaths;\n\t\t\tthis.updatePromptsFromPaths(promptPaths, metadataByPath);\n\t\t\tfor (const p of this.additionalPromptTemplatePaths) {\n\t\t\t\tif (isLocalPath(p)) {\n\t\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\t\tif (!existsSync(resolved) && !this.promptDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\t\tthis.promptDiagnostics.push({\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tmessage: \"Prompt template path does not exist\",\n\t\t\t\t\t\t\tpath: resolved,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Discover external themes\n\t\t\tconst externalThemes: string[] = [];\n\t\t\tfor (const root of effectiveRoots) {\n\t\t\t\tconst themesDir = join(root, \"themes\");\n\t\t\t\tif (existsSync(themesDir)) {\n\t\t\t\t\tconst files = collectFilesRecursively(themesDir, /\\.json$/);\n\t\t\t\t\tfor (const f of files) {\n\t\t\t\t\t\texternalThemes.push(f);\n\t\t\t\t\t\tmetadataByPath.set(f, { source: \"external\", scope: \"user\", origin: \"top-level\" });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst themePaths = this.noThemes\n\t\t\t\t? this.mergePaths(cliEnabledThemes, this.additionalThemePaths)\n\t\t\t\t: this.mergePaths(\n\t\t\t\t\t\t[...cliEnabledThemes, ...enabledThemes, ...filterPathsByProfile(externalThemes, \"themes\")],\n\t\t\t\t\t\tthis.additionalThemePaths,\n\t\t\t\t\t);\n\n\t\t\tthis.lastThemePaths = themePaths;\n\t\t\tthis.updateThemesFromPaths(themePaths, metadataByPath);\n\t\t\tfor (const p of this.additionalThemePaths) {\n\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\tif (!existsSync(resolved) && !this.themeDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\tthis.themeDiagnostics.push({ type: \"error\", message: \"Theme path does not exist\", path: resolved });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst rawAgentsFiles = this.noContextFiles\n\t\t\t\t? []\n\t\t\t\t: loadProjectContextFiles({\n\t\t\t\t\t\tcwd: this.cwd,\n\t\t\t\t\t\tagentDir: this.agentDir,\n\t\t\t\t\t\tprojectTrusted: this.settingsManager.isProjectTrusted(),\n\t\t\t\t\t});\n\t\t\tconst agentEmbeddedProfiles: Record<string, ResourceProfileSettings> = {};\n\t\t\tconst activeProfileNames = this.settingsManager.getActiveResourceProfileNames();\n\t\t\tfor (const file of rawAgentsFiles) {\n\t\t\t\ttry {\n\t\t\t\t\tconst rawContent = readFileSync(file.path, \"utf-8\");\n\t\t\t\t\tconst { profiles } = parseResourceProfileBlocks(rawContent, { profileNames: activeProfileNames });\n\t\t\t\t\tObject.assign(agentEmbeddedProfiles, mergeResourceProfileMap(agentEmbeddedProfiles, profiles));\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t\tthis.settingsManager.addDiscoveredResourceProfileDefinitions(agentEmbeddedProfiles);\n\t\t\tconst agentProfileFilter = this.settingsManager.getResourceProfileFilter(\"agents\");\n\t\t\tconst agentsFiles = {\n\t\t\t\tagentsFiles: rawAgentsFiles\n\t\t\t\t\t.filter((file) => {\n\t\t\t\t\t\tconst allowed =\n\t\t\t\t\t\t\tagentProfileFilter.allow.length === 0 ||\n\t\t\t\t\t\t\tmatchesResourceProfilePattern(file.path, agentProfileFilter.allow, this.cwd);\n\t\t\t\t\t\tconst blocked = matchesResourceProfilePattern(file.path, agentProfileFilter.block, this.cwd);\n\t\t\t\t\t\treturn allowed && !blocked;\n\t\t\t\t\t})\n\t\t\t\t\t.map((file) => ({\n\t\t\t\t\t\t...file,\n\t\t\t\t\t\tcontent: file.content ? stripResourceProfileBlocks(file.content) : file.content,\n\t\t\t\t\t})),\n\t\t\t};\n\t\t\tconst resolvedAgentsFiles = this.agentsFilesOverride ? this.agentsFilesOverride(agentsFiles) : agentsFiles;\n\t\t\tthis.agentsFiles = resolvedAgentsFiles.agentsFiles;\n\n\t\t\tconst baseSystemPrompt = resolvePromptInput(\n\t\t\t\tthis.systemPromptSource ?? this.discoverSystemPromptFile(),\n\t\t\t\t\"system prompt\",\n\t\t\t);\n\t\t\tthis.systemPrompt = this.systemPromptOverride ? this.systemPromptOverride(baseSystemPrompt) : baseSystemPrompt;\n\n\t\t\tconst appendSources =\n\t\t\t\tthis.appendSystemPromptSource ??\n\t\t\t\t(this.discoverAppendSystemPromptFile() ? [this.discoverAppendSystemPromptFile()!] : []);\n\t\t\tconst baseAppend = appendSources\n\t\t\t\t.map((s) => resolvePromptInput(s, \"append system prompt\"))\n\t\t\t\t.filter((s): s is string => s !== undefined);\n\t\t\tthis.appendSystemPrompt = this.appendSystemPromptOverride\n\t\t\t\t? this.appendSystemPromptOverride(baseAppend)\n\t\t\t\t: baseAppend;\n\t\t\tif (options.deferExtensionDispose) {\n\t\t\t\tthis.pendingReloadSnapshot = snapshot;\n\t\t\t} else {\n\t\t\t\tawait disposeExtensionEventSubscriptions(snapshot.extensionsResult.extensions);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (this.extensionsResult !== snapshot.extensionsResult) {\n\t\t\t\tawait disposeExtensionEventSubscriptions(this.extensionsResult.extensions);\n\t\t\t}\n\t\t\tthis.restoreSnapshot(snapshot);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate normalizeExtensionPaths(\n\t\tentries: Array<{ path: string; metadata: PathMetadata }>,\n\t): Array<{ path: string; metadata: PathMetadata }> {\n\t\treturn entries.map((entry) => {\n\t\t\tconst metadata = entry.metadata.baseDir\n\t\t\t\t? { ...entry.metadata, baseDir: this.resolveResourcePath(entry.metadata.baseDir) }\n\t\t\t\t: entry.metadata;\n\t\t\treturn {\n\t\t\t\tpath: this.resolveResourcePath(entry.path),\n\t\t\t\tmetadata,\n\t\t\t};\n\t\t});\n\t}\n\n\tprivate updateSkillsFromPaths(skillPaths: string[], metadataByPath?: Map<string, PathMetadata>): void {\n\t\tlet skillsResult: { skills: Skill[]; diagnostics: ResourceDiagnostic[] };\n\t\tif (this.noSkills && skillPaths.length === 0) {\n\t\t\tskillsResult = { skills: [], diagnostics: [] };\n\t\t} else {\n\t\t\tskillsResult = loadSkills({\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tagentDir: this.agentDir,\n\t\t\t\tskillPaths,\n\t\t\t\tincludeDefaults: false,\n\t\t\t});\n\t\t}\n\t\tconst resolvedSkills = this.skillsOverride ? this.skillsOverride(skillsResult) : skillsResult;\n\t\tthis.skills = resolvedSkills.skills.map((skill) => ({\n\t\t\t...skill,\n\t\t\tsourceInfo:\n\t\t\t\tthis.findSourceInfoForPath(skill.filePath, this.extensionSkillSourceInfos, metadataByPath) ??\n\t\t\t\tskill.sourceInfo ??\n\t\t\t\tthis.getDefaultSourceInfoForPath(skill.filePath),\n\t\t}));\n\t\tthis.skillDiagnostics = resolvedSkills.diagnostics;\n\t}\n\n\tprivate updatePromptsFromPaths(promptPaths: string[], metadataByPath?: Map<string, PathMetadata>): void {\n\t\tlet promptsResult: { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] };\n\t\tif (this.noPromptTemplates && promptPaths.length === 0) {\n\t\t\tpromptsResult = { prompts: [], diagnostics: [] };\n\t\t} else {\n\t\t\tconst allPrompts = loadPromptTemplates({\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tagentDir: this.agentDir,\n\t\t\t\tpromptPaths,\n\t\t\t\tincludeDefaults: false,\n\t\t\t});\n\t\t\tpromptsResult = this.dedupePrompts(allPrompts);\n\t\t}\n\t\tconst resolvedPrompts = this.promptsOverride ? this.promptsOverride(promptsResult) : promptsResult;\n\t\tthis.prompts = resolvedPrompts.prompts.map((prompt) => ({\n\t\t\t...prompt,\n\t\t\tsourceInfo:\n\t\t\t\tthis.findSourceInfoForPath(prompt.filePath, this.extensionPromptSourceInfos, metadataByPath) ??\n\t\t\t\tprompt.sourceInfo ??\n\t\t\t\tthis.getDefaultSourceInfoForPath(prompt.filePath),\n\t\t}));\n\t\tthis.promptDiagnostics = resolvedPrompts.diagnostics;\n\t}\n\n\tprivate updateThemesFromPaths(themePaths: string[], metadataByPath?: Map<string, PathMetadata>): void {\n\t\tlet themesResult: { themes: Theme[]; diagnostics: ResourceDiagnostic[] };\n\t\tif (this.noThemes && themePaths.length === 0) {\n\t\t\tthemesResult = { themes: [], diagnostics: [] };\n\t\t} else {\n\t\t\tconst loaded = this.loadThemes(themePaths, false);\n\t\t\tconst deduped = this.dedupeThemes(loaded.themes);\n\t\t\tthemesResult = { themes: deduped.themes, diagnostics: [...loaded.diagnostics, ...deduped.diagnostics] };\n\t\t}\n\t\tconst resolvedThemes = this.themesOverride ? this.themesOverride(themesResult) : themesResult;\n\t\tthis.themes = resolvedThemes.themes.map((theme) => {\n\t\t\tconst sourcePath = theme.sourcePath;\n\t\t\ttheme.sourceInfo = sourcePath\n\t\t\t\t? (this.findSourceInfoForPath(sourcePath, this.extensionThemeSourceInfos, metadataByPath) ??\n\t\t\t\t\ttheme.sourceInfo ??\n\t\t\t\t\tthis.getDefaultSourceInfoForPath(sourcePath))\n\t\t\t\t: theme.sourceInfo;\n\t\t\treturn theme;\n\t\t});\n\t\tthis.themeDiagnostics = resolvedThemes.diagnostics;\n\t}\n\n\tprivate applyExtensionSourceInfo(extensions: Extension[], metadataByPath: Map<string, PathMetadata>): void {\n\t\tfor (const extension of extensions) {\n\t\t\textension.sourceInfo =\n\t\t\t\tthis.findSourceInfoForPath(extension.path, undefined, metadataByPath) ??\n\t\t\t\tthis.getDefaultSourceInfoForPath(extension.path);\n\t\t\tfor (const command of extension.commands.values()) {\n\t\t\t\tcommand.sourceInfo = extension.sourceInfo;\n\t\t\t}\n\t\t\tfor (const tool of extension.tools.values()) {\n\t\t\t\ttool.sourceInfo = extension.sourceInfo;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate findSourceInfoForPath(\n\t\tresourcePath: string,\n\t\textraSourceInfos?: Map<string, SourceInfo>,\n\t\tmetadataByPath?: Map<string, PathMetadata>,\n\t): SourceInfo | undefined {\n\t\tif (!resourcePath) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (resourcePath.startsWith(\"<\")) {\n\t\t\treturn this.getDefaultSourceInfoForPath(resourcePath);\n\t\t}\n\n\t\tconst normalizedResourcePath = resolve(resourcePath);\n\t\tif (extraSourceInfos) {\n\t\t\tfor (const [sourcePath, sourceInfo] of extraSourceInfos.entries()) {\n\t\t\t\tconst normalizedSourcePath = resolve(sourcePath);\n\t\t\t\tif (\n\t\t\t\t\tnormalizedResourcePath === normalizedSourcePath ||\n\t\t\t\t\tnormalizedResourcePath.startsWith(`${normalizedSourcePath}${sep}`)\n\t\t\t\t) {\n\t\t\t\t\treturn { ...sourceInfo, path: resourcePath };\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (metadataByPath) {\n\t\t\tconst exact = metadataByPath.get(normalizedResourcePath) ?? metadataByPath.get(resourcePath);\n\t\t\tif (exact) {\n\t\t\t\treturn createSourceInfo(resourcePath, exact);\n\t\t\t}\n\n\t\t\tfor (const [sourcePath, metadata] of metadataByPath.entries()) {\n\t\t\t\tconst normalizedSourcePath = resolve(sourcePath);\n\t\t\t\tif (\n\t\t\t\t\tnormalizedResourcePath === normalizedSourcePath ||\n\t\t\t\t\tnormalizedResourcePath.startsWith(`${normalizedSourcePath}${sep}`)\n\t\t\t\t) {\n\t\t\t\t\treturn createSourceInfo(resourcePath, metadata);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tprivate getDefaultSourceInfoForPath(filePath: string): SourceInfo {\n\t\tif (filePath.startsWith(\"<\") && filePath.endsWith(\">\")) {\n\t\t\treturn {\n\t\t\t\tpath: filePath,\n\t\t\t\tsource: filePath.slice(1, -1).split(\":\")[0] || \"temporary\",\n\t\t\t\tscope: \"temporary\",\n\t\t\t\torigin: \"top-level\",\n\t\t\t};\n\t\t}\n\n\t\tconst normalizedPath = resolve(filePath);\n\t\tconst agentRoots = [\n\t\t\tjoin(this.agentDir, \"skills\"),\n\t\t\tjoin(this.agentDir, \"prompts\"),\n\t\t\tjoin(this.agentDir, \"themes\"),\n\t\t\tjoin(this.agentDir, \"extensions\"),\n\t\t];\n\t\tconst projectRoots = [\n\t\t\tjoin(this.cwd, CONFIG_DIR_NAME, \"skills\"),\n\t\t\tjoin(this.cwd, CONFIG_DIR_NAME, \"prompts\"),\n\t\t\tjoin(this.cwd, CONFIG_DIR_NAME, \"themes\"),\n\t\t\tjoin(this.cwd, CONFIG_DIR_NAME, \"extensions\"),\n\t\t];\n\n\t\tfor (const root of agentRoots) {\n\t\t\tif (this.isUnderPath(normalizedPath, root)) {\n\t\t\t\treturn { path: filePath, source: \"local\", scope: \"user\", origin: \"top-level\", baseDir: root };\n\t\t\t}\n\t\t}\n\n\t\tfor (const root of projectRoots) {\n\t\t\tif (this.isUnderPath(normalizedPath, root)) {\n\t\t\t\treturn { path: filePath, source: \"local\", scope: \"project\", origin: \"top-level\", baseDir: root };\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tpath: filePath,\n\t\t\tsource: \"local\",\n\t\t\tscope: \"temporary\",\n\t\t\torigin: \"top-level\",\n\t\t\tbaseDir: statSync(normalizedPath).isDirectory() ? normalizedPath : resolve(normalizedPath, \"..\"),\n\t\t};\n\t}\n\n\tprivate mergePaths(primary: string[], additional: string[]): string[] {\n\t\tconst merged: string[] = [];\n\t\tconst seen = new Set<string>();\n\n\t\tfor (const p of [...primary, ...additional]) {\n\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\tconst canonicalPath = canonicalizePath(resolved);\n\t\t\tif (seen.has(canonicalPath)) continue;\n\t\t\tseen.add(canonicalPath);\n\t\t\tmerged.push(resolved);\n\t\t}\n\n\t\treturn merged;\n\t}\n\n\tprivate resolveResourcePath(p: string): string {\n\t\treturn resolvePath(p, this.cwd, { trim: true });\n\t}\n\n\tprivate loadThemes(\n\t\tpaths: string[],\n\t\tincludeDefaults: boolean = true,\n\t): {\n\t\tthemes: Theme[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t} {\n\t\tconst themes: Theme[] = [];\n\t\tconst diagnostics: ResourceDiagnostic[] = [];\n\t\tif (includeDefaults) {\n\t\t\tconst defaultDirs = [join(this.agentDir, \"themes\"), join(this.cwd, CONFIG_DIR_NAME, \"themes\")];\n\n\t\t\tfor (const dir of defaultDirs) {\n\t\t\t\tthis.loadThemesFromDir(dir, themes, diagnostics);\n\t\t\t}\n\t\t}\n\n\t\tfor (const p of paths) {\n\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\tif (!existsSync(resolved)) {\n\t\t\t\tdiagnostics.push({ type: \"warning\", message: \"theme path does not exist\", path: resolved });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst stats = statSync(resolved);\n\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\tthis.loadThemesFromDir(resolved, themes, diagnostics);\n\t\t\t\t} else if (stats.isFile() && resolved.endsWith(\".json\")) {\n\t\t\t\t\tthis.loadThemeFromFile(resolved, themes, diagnostics);\n\t\t\t\t} else {\n\t\t\t\t\tdiagnostics.push({ type: \"warning\", message: \"theme path is not a json file\", path: resolved });\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"failed to read theme path\";\n\t\t\t\tdiagnostics.push({ type: \"warning\", message, path: resolved });\n\t\t\t}\n\t\t}\n\n\t\treturn { themes, diagnostics };\n\t}\n\n\tprivate loadThemesFromDir(dir: string, themes: Theme[], diagnostics: ResourceDiagnostic[]): void {\n\t\tif (!existsSync(dir)) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\t\t\tfor (const entry of entries) {\n\t\t\t\tlet isFile = entry.isFile();\n\t\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tisFile = statSync(join(dir, entry.name)).isFile();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!isFile) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!entry.name.endsWith(\".json\")) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthis.loadThemeFromFile(join(dir, entry.name), themes, diagnostics);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read theme directory\";\n\t\t\tdiagnostics.push({ type: \"warning\", message, path: dir });\n\t\t}\n\t}\n\n\tprivate loadThemeFromFile(filePath: string, themes: Theme[], diagnostics: ResourceDiagnostic[]): void {\n\t\ttry {\n\t\t\tthemes.push(loadThemeFromPath(filePath));\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to load theme\";\n\t\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\t}\n\t}\n\n\tprivate async loadExtensionFactories(runtime: ExtensionRuntime): Promise<{\n\t\textensions: Extension[];\n\t\terrors: Array<{ path: string; error: string }>;\n\t}> {\n\t\tconst extensions: Extension[] = [];\n\t\tconst errors: Array<{ path: string; error: string }> = [];\n\n\t\tfor (const [index, factory] of this.extensionFactories.entries()) {\n\t\t\tconst extensionPath = `<inline:${index + 1}>`;\n\t\t\ttry {\n\t\t\t\tconst extension = await loadExtensionFromFactory(factory, this.cwd, this.eventBus, runtime, extensionPath);\n\t\t\t\textensions.push(extension);\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"failed to load extension\";\n\t\t\t\terrors.push({ path: extensionPath, error: message });\n\t\t\t}\n\t\t}\n\n\t\treturn { extensions, errors };\n\t}\n\n\tprivate dedupePrompts(prompts: PromptTemplate[]): { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] } {\n\t\tconst seen = new Map<string, PromptTemplate>();\n\t\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\t\tfor (const prompt of prompts) {\n\t\t\tconst existing = seen.get(prompt.name);\n\t\t\tif (existing) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"/${prompt.name}\" collision`,\n\t\t\t\t\tpath: prompt.filePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"prompt\",\n\t\t\t\t\t\tname: prompt.name,\n\t\t\t\t\t\twinnerPath: existing.filePath,\n\t\t\t\t\t\tloserPath: prompt.filePath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tseen.set(prompt.name, prompt);\n\t\t\t}\n\t\t}\n\n\t\treturn { prompts: Array.from(seen.values()), diagnostics };\n\t}\n\n\tprivate dedupeThemes(themes: Theme[]): { themes: Theme[]; diagnostics: ResourceDiagnostic[] } {\n\t\tconst seen = new Map<string, Theme>();\n\t\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\t\tfor (const t of themes) {\n\t\t\tconst name = t.name ?? \"unnamed\";\n\t\t\tconst existing = seen.get(name);\n\t\t\tif (existing) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"${name}\" collision`,\n\t\t\t\t\tpath: t.sourcePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"theme\",\n\t\t\t\t\t\tname,\n\t\t\t\t\t\twinnerPath: existing.sourcePath ?? \"<builtin>\",\n\t\t\t\t\t\tloserPath: t.sourcePath ?? \"<builtin>\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tseen.set(name, t);\n\t\t\t}\n\t\t}\n\n\t\treturn { themes: Array.from(seen.values()), diagnostics };\n\t}\n\n\tprivate discoverSystemPromptFile(): string | undefined {\n\t\tconst projectPath = join(this.cwd, CONFIG_DIR_NAME, \"SYSTEM.md\");\n\t\tif (this.settingsManager.isProjectTrusted() && existsSync(projectPath)) {\n\t\t\treturn projectPath;\n\t\t}\n\n\t\tconst globalPath = join(this.agentDir, \"SYSTEM.md\");\n\t\tif (existsSync(globalPath)) {\n\t\t\treturn globalPath;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tprivate discoverAppendSystemPromptFile(): string | undefined {\n\t\tconst projectPath = join(this.cwd, CONFIG_DIR_NAME, \"APPEND_SYSTEM.md\");\n\t\tif (this.settingsManager.isProjectTrusted() && existsSync(projectPath)) {\n\t\t\treturn projectPath;\n\t\t}\n\n\t\tconst globalPath = join(this.agentDir, \"APPEND_SYSTEM.md\");\n\t\tif (existsSync(globalPath)) {\n\t\t\treturn globalPath;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tprivate isUnderPath(target: string, root: string): boolean {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t}\n\n\tprivate detectExtensionConflicts(extensions: Extension[]): Array<{ path: string; message: string }> {\n\t\tconst conflicts: Array<{ path: string; message: string }> = [];\n\n\t\t// Track which extension registered each tool and flag\n\t\tconst toolOwners = new Map<string, string>();\n\t\tconst flagOwners = new Map<string, string>();\n\n\t\tfor (const ext of extensions) {\n\t\t\t// Check tools\n\t\t\tfor (const toolName of ext.tools.keys()) {\n\t\t\t\tconst existingOwner = toolOwners.get(toolName);\n\t\t\t\tif (existingOwner && existingOwner !== ext.path) {\n\t\t\t\t\tconflicts.push({\n\t\t\t\t\t\tpath: ext.path,\n\t\t\t\t\t\tmessage: `Tool \"${toolName}\" conflicts with ${existingOwner}`,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\ttoolOwners.set(toolName, ext.path);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Check flags\n\t\t\tfor (const flagName of ext.flags.keys()) {\n\t\t\t\tconst existingOwner = flagOwners.get(flagName);\n\t\t\t\tif (existingOwner && existingOwner !== ext.path) {\n\t\t\t\t\tconflicts.push({\n\t\t\t\t\t\tpath: ext.path,\n\t\t\t\t\t\tmessage: `Flag \"--${flagName}\" conflicts with ${existingOwner}`,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tflagOwners.set(flagName, ext.path);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn conflicts;\n\t}\n}\n\nfunction collectFilesRecursively(dir: string, pattern: RegExp): string[] {\n\tconst files: string[] = [];\n\tif (!existsSync(dir)) return files;\n\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name.startsWith(\".\")) continue;\n\t\t\tif (entry.name === \"node_modules\") continue;\n\n\t\t\tconst fullPath = join(dir, entry.name);\n\t\t\tlet isDir = entry.isDirectory();\n\t\t\tlet isFile = entry.isFile();\n\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisDir = stats.isDirectory();\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isDir) {\n\t\t\t\tfiles.push(...collectFilesRecursively(fullPath, pattern));\n\t\t\t} else if (isFile && pattern.test(entry.name)) {\n\t\t\t\tfiles.push(fullPath);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// silent\n\t}\n\treturn files;\n}\n"]}
1
+ {"version":3,"file":"resource-loader.d.ts","sourceRoot":"","sources":["../../src/core/resource-loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAqB,KAAK,KAAK,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG9E,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAQ/D,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAoB,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACjH,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB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C,iBAAiB;YASX,sBAAsB;IAqBpC,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,YAAY;IA2BpB,OAAO,CAAC,wBAAwB;IAchC,OAAO,CAAC,8BAA8B;IActC,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,wBAAwB;CAqChC","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { join, resolve, sep } from \"node:path\";\nimport chalk from \"chalk\";\nimport { CONFIG_DIR_NAME, getBundledPromptsDir, getBundledSkillsDir } from \"../config.ts\";\nimport { loadThemeFromPath, type Theme } from \"../modes/interactive/theme/theme.ts\";\nimport type { ResourceDiagnostic } from \"./diagnostics.ts\";\n\nexport type { ResourceCollision, ResourceDiagnostic } from \"./diagnostics.ts\";\n\nimport { canonicalizePath, isLocalPath, resolvePath } from \"../utils/paths.ts\";\nimport { createEventBus, type EventBus } from \"./event-bus.ts\";\nimport {\n\tcreateExtensionRuntime,\n\tdisposeExtensionEventSubscriptions,\n\tloadExtension,\n\tloadExtensionFromFactory,\n\tloadExtensions,\n} from \"./extensions/loader.ts\";\nimport type { Extension, ExtensionFactory, ExtensionRuntime, LoadExtensionsResult } from \"./extensions/types.ts\";\nimport { DefaultPackageManager, type PathMetadata } from \"./package-manager.ts\";\nimport type { PromptTemplate } from \"./prompt-templates.ts\";\nimport { loadPromptTemplates } from \"./prompt-templates.ts\";\nimport {\n\tmergeResourceProfileMap,\n\tparseResourceProfileBlocks,\n\tstripResourceProfileBlocks,\n} from \"./resource-profile-blocks.ts\";\nimport {\n\tmatchesResourceProfilePattern,\n\ttype ResourceProfileKind,\n\ttype ResourceProfileSettings,\n\tSettingsManager,\n} from \"./settings-manager.ts\";\nimport type { Skill } from \"./skills.ts\";\nimport { loadSkills } from \"./skills.ts\";\nimport { createSourceInfo, type SourceInfo } from \"./source-info.ts\";\n\nexport interface ResourceExtensionPaths {\n\tskillPaths?: Array<{ path: string; metadata: PathMetadata }>;\n\tpromptPaths?: Array<{ path: string; metadata: PathMetadata }>;\n\tthemePaths?: Array<{ path: string; metadata: PathMetadata }>;\n}\n\nexport interface ResourceReloadOptions {\n\t/** Throw instead of accepting a hot reload that produced extension load/conflict errors. */\n\tfailOnExtensionErrors?: boolean;\n\t/** Keep the previous extension generation alive until commitReload()/rollbackReload(). */\n\tdeferExtensionDispose?: boolean;\n}\n\nexport interface ResourceLoader {\n\tgetExtensions(): LoadExtensionsResult;\n\tgetSkills(): { skills: Skill[]; diagnostics: ResourceDiagnostic[] };\n\t/** Skills allowed by the currently active resource profile — use for selection/invocation/agent-visibility. */\n\tgetActiveSkills(): Skill[];\n\tgetPrompts(): { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] };\n\t/** Prompt templates allowed by the currently active resource profile — use for selection/invocation/agent-visibility. */\n\tgetActivePrompts(): PromptTemplate[];\n\tgetThemes(): { themes: Theme[]; diagnostics: ResourceDiagnostic[] };\n\t/** Themes allowed by the currently active resource profile. */\n\tgetActiveThemes(): Theme[];\n\tgetAgentsFiles(): { agentsFiles: Array<{ path: string; content?: string }> };\n\tgetSystemPrompt(): string | undefined;\n\tgetAppendSystemPrompt(): string[];\n\tgetLoadedExtension(path: string): Extension | undefined;\n\tremoveLoadedExtension(path: string): Extension | undefined;\n\tloadSingleExtension(path: string): Promise<{ extension: Extension | null; error: string | null }>;\n\textendResources(paths: ResourceExtensionPaths): void;\n\treload(options?: ResourceReloadOptions): Promise<void>;\n\tcommitReload?(): void;\n\trollbackReload?(): void;\n\t/** Get all discoverable extension paths (enabled and disabled) */\n\tgetDiscoverableExtensionPaths(): Promise<string[]>;\n}\n\ninterface ResourceLoaderSnapshot {\n\textensionsResult: LoadExtensionsResult;\n\tskills: Skill[];\n\tskillDiagnostics: ResourceDiagnostic[];\n\tprompts: PromptTemplate[];\n\tpromptDiagnostics: ResourceDiagnostic[];\n\tthemes: Theme[];\n\tthemeDiagnostics: ResourceDiagnostic[];\n\tagentsFiles: Array<{ path: string; content?: string }>;\n\tsystemPrompt?: string;\n\tappendSystemPrompt: string[];\n\tlastSkillPaths: string[];\n\textensionSkillSourceInfos: Map<string, SourceInfo>;\n\textensionPromptSourceInfos: Map<string, SourceInfo>;\n\textensionThemeSourceInfos: Map<string, SourceInfo>;\n\tlastPromptPaths: string[];\n\tlastThemePaths: string[];\n}\n\nfunction resolvePromptInput(input: string | undefined, description: string): string | undefined {\n\tif (!input) {\n\t\treturn undefined;\n\t}\n\n\tif (existsSync(input)) {\n\t\ttry {\n\t\t\treturn readFileSync(input, \"utf-8\");\n\t\t} catch (error) {\n\t\t\tconsole.error(chalk.yellow(`Warning: Could not read ${description} file ${input}: ${error}`));\n\t\t\treturn input;\n\t\t}\n\t}\n\n\treturn input;\n}\n\nconst CONTEXT_THREAT_PATTERNS: Array<{ label: string; pattern: RegExp }> = [\n\t{\n\t\tlabel: \"instruction override\",\n\t\tpattern:\n\t\t\t/\\b(?:ignore|disregard|override|bypass)\\b.{0,80}\\b(?:previous|prior|above|system|developer|agent)\\b.{0,80}\\binstructions?\\b/i,\n\t},\n\t{\n\t\tlabel: \"secret exfiltration\",\n\t\tpattern:\n\t\t\t/\\b(?:reveal|print|dump|exfiltrate|send|upload)\\b.{0,80}\\b(?:secrets?|tokens?|api[_ -]?keys?|credentials?|environment variables?|\\.env)\\b/i,\n\t},\n\t{\n\t\tlabel: \"hidden instruction\",\n\t\tpattern: /\\b(?:do not tell|don't tell|hide this from)\\b.{0,80}\\b(?:user|operator|developer)\\b/i,\n\t},\n];\n\nexport function scanContextFileThreats(content: string): string[] {\n\treturn CONTEXT_THREAT_PATTERNS.filter(({ pattern }) => pattern.test(content)).map(({ label }) => label);\n}\n\nfunction sanitizeContextFileContent(filePath: string, content: string): string {\n\tconst profileFreeContent = stripResourceProfileBlocks(content);\n\tconst findings = scanContextFileThreats(profileFreeContent);\n\tif (findings.length === 0) return profileFreeContent;\n\tconsole.error(chalk.yellow(`Warning: Blocked context file ${filePath}: ${findings.join(\", \")}`));\n\treturn `[BLOCKED: ${filePath} contained potential prompt injection (${findings.join(\", \")}). Content not loaded.]`;\n}\n\nfunction loadContextFilesFromDir(dir: string): Array<{ path: string; content: string }> {\n\tconst candidates = [\"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\", \"GEMINI.md\", \"GEMINI.MD\"];\n\tconst files: Array<{ path: string; content: string }> = [];\n\tfor (const filename of candidates) {\n\t\tconst filePath = join(dir, filename);\n\t\tif (existsSync(filePath)) {\n\t\t\ttry {\n\t\t\t\tconst content = readFileSync(filePath, \"utf-8\");\n\t\t\t\tfiles.push({\n\t\t\t\t\tpath: filePath,\n\t\t\t\t\tcontent: sanitizeContextFileContent(filePath, content),\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(chalk.yellow(`Warning: Could not read ${filePath}: ${error}`));\n\t\t\t}\n\t\t}\n\t}\n\treturn files;\n}\n\nexport function loadProjectContextFiles(options: {\n\tcwd: string;\n\tagentDir: string;\n\tprojectTrusted?: boolean;\n}): Array<{ path: string; content?: string }> {\n\tconst resolvedCwd = resolvePath(options.cwd);\n\tconst resolvedAgentDir = resolvePath(options.agentDir);\n\n\tconst contextFiles: Array<{ path: string; content?: string }> = [];\n\tconst seenPaths = new Set<string>();\n\n\tfor (const globalContext of loadContextFilesFromDir(resolvedAgentDir)) {\n\t\tcontextFiles.push(globalContext);\n\t\tseenPaths.add(globalContext.path);\n\t}\n\n\tif (options.projectTrusted !== false) {\n\t\tconst ancestorContextFiles: Array<{ path: string; content?: string }> = [];\n\n\t\tlet currentDir = resolvedCwd;\n\t\tconst root = resolve(\"/\");\n\n\t\twhile (true) {\n\t\t\tconst contextFilesInDir = loadContextFilesFromDir(currentDir).filter(\n\t\t\t\t(contextFile) => !seenPaths.has(contextFile.path),\n\t\t\t);\n\t\t\tif (contextFilesInDir.length > 0) {\n\t\t\t\tancestorContextFiles.unshift(...contextFilesInDir);\n\t\t\t\tfor (const contextFile of contextFilesInDir) {\n\t\t\t\t\tseenPaths.add(contextFile.path);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentDir === root) break;\n\n\t\t\tconst parentDir = resolve(currentDir, \"..\");\n\t\t\tif (parentDir === currentDir) break;\n\t\t\tcurrentDir = parentDir;\n\t\t}\n\n\t\tcontextFiles.push(...ancestorContextFiles);\n\t}\n\n\treturn contextFiles;\n}\n\nexport interface DefaultResourceLoaderOptions {\n\tcwd: string;\n\tagentDir: string;\n\tsettingsManager?: SettingsManager;\n\teventBus?: EventBus;\n\tadditionalExtensionPaths?: string[];\n\tadditionalSkillPaths?: string[];\n\tadditionalPromptTemplatePaths?: string[];\n\tadditionalThemePaths?: string[];\n\textensionFactories?: ExtensionFactory[];\n\tnoExtensions?: boolean;\n\tnoSkills?: boolean;\n\tnoPromptTemplates?: boolean;\n\tnoThemes?: boolean;\n\tnoContextFiles?: boolean;\n\tsystemPrompt?: string;\n\tappendSystemPrompt?: string[];\n\textensionsOverride?: (base: LoadExtensionsResult) => LoadExtensionsResult;\n\tskillsOverride?: (base: { skills: Skill[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tskills: Skill[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tpromptsOverride?: (base: { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tprompts: PromptTemplate[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tthemesOverride?: (base: { themes: Theme[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tthemes: Theme[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tagentsFilesOverride?: (base: { agentsFiles: Array<{ path: string; content?: string }> }) => {\n\t\tagentsFiles: Array<{ path: string; content?: string }>;\n\t};\n\tsystemPromptOverride?: (base: string | undefined) => string | undefined;\n\tappendSystemPromptOverride?: (base: string[]) => string[];\n}\n\nexport class DefaultResourceLoader implements ResourceLoader {\n\tprivate cwd: string;\n\tprivate agentDir: string;\n\tprivate settingsManager: SettingsManager;\n\tprivate eventBus: EventBus;\n\tprivate packageManager: DefaultPackageManager;\n\tprivate additionalExtensionPaths: string[];\n\tprivate additionalSkillPaths: string[];\n\tprivate additionalPromptTemplatePaths: string[];\n\tprivate additionalThemePaths: string[];\n\tprivate extensionFactories: ExtensionFactory[];\n\tprivate noExtensions: boolean;\n\tprivate noSkills: boolean;\n\tprivate noPromptTemplates: boolean;\n\tprivate noThemes: boolean;\n\tprivate noContextFiles: boolean;\n\tprivate systemPromptSource?: string;\n\tprivate appendSystemPromptSource?: string[];\n\tprivate extensionsOverride?: (base: LoadExtensionsResult) => LoadExtensionsResult;\n\tprivate skillsOverride?: (base: { skills: Skill[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tskills: Skill[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tprivate promptsOverride?: (base: { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tprompts: PromptTemplate[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tprivate themesOverride?: (base: { themes: Theme[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tthemes: Theme[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tprivate agentsFilesOverride?: (base: { agentsFiles: Array<{ path: string; content?: string }> }) => {\n\t\tagentsFiles: Array<{ path: string; content?: string }>;\n\t};\n\tprivate systemPromptOverride?: (base: string | undefined) => string | undefined;\n\tprivate appendSystemPromptOverride?: (base: string[]) => string[];\n\n\tprivate extensionsResult: LoadExtensionsResult;\n\tprivate skills: Skill[];\n\tprivate skillDiagnostics: ResourceDiagnostic[];\n\tprivate prompts: PromptTemplate[];\n\tprivate promptDiagnostics: ResourceDiagnostic[];\n\tprivate themes: Theme[];\n\tprivate themeDiagnostics: ResourceDiagnostic[];\n\tprivate agentsFiles: Array<{ path: string; content?: string }>;\n\tprivate systemPrompt?: string;\n\tprivate appendSystemPrompt: string[];\n\tprivate lastSkillPaths: string[];\n\tprivate extensionSkillSourceInfos: Map<string, SourceInfo>;\n\tprivate extensionPromptSourceInfos: Map<string, SourceInfo>;\n\tprivate extensionThemeSourceInfos: Map<string, SourceInfo>;\n\tprivate lastPromptPaths: string[];\n\tprivate lastThemePaths: string[];\n\tprivate pendingReloadSnapshot: ResourceLoaderSnapshot | undefined;\n\n\tconstructor(options: DefaultResourceLoaderOptions) {\n\t\tthis.cwd = resolvePath(options.cwd);\n\t\tthis.agentDir = resolvePath(options.agentDir);\n\t\tthis.settingsManager = options.settingsManager ?? SettingsManager.create(this.cwd, this.agentDir);\n\t\tthis.eventBus = options.eventBus ?? createEventBus();\n\t\tthis.packageManager = new DefaultPackageManager({\n\t\t\tcwd: this.cwd,\n\t\t\tagentDir: this.agentDir,\n\t\t\tsettingsManager: this.settingsManager,\n\t\t});\n\t\tthis.additionalExtensionPaths = options.additionalExtensionPaths ?? [];\n\t\tthis.additionalSkillPaths = options.additionalSkillPaths ?? [];\n\t\tthis.additionalPromptTemplatePaths = options.additionalPromptTemplatePaths ?? [];\n\t\tthis.additionalThemePaths = options.additionalThemePaths ?? [];\n\t\tthis.noExtensions = options.noExtensions ?? false;\n\t\tthis.extensionFactories = options.extensionFactories ?? [];\n\t\tthis.noSkills = options.noSkills ?? false;\n\t\tthis.noPromptTemplates = options.noPromptTemplates ?? false;\n\t\tthis.noThemes = options.noThemes ?? false;\n\t\tthis.noContextFiles = options.noContextFiles ?? false;\n\t\tthis.systemPromptSource = options.systemPrompt;\n\t\tthis.appendSystemPromptSource = options.appendSystemPrompt;\n\t\tthis.extensionsOverride = options.extensionsOverride;\n\t\tthis.skillsOverride = options.skillsOverride;\n\t\tthis.promptsOverride = options.promptsOverride;\n\t\tthis.themesOverride = options.themesOverride;\n\t\tthis.agentsFilesOverride = options.agentsFilesOverride;\n\t\tthis.systemPromptOverride = options.systemPromptOverride;\n\t\tthis.appendSystemPromptOverride = options.appendSystemPromptOverride;\n\n\t\tthis.extensionsResult = { extensions: [], errors: [], runtime: createExtensionRuntime() };\n\t\tthis.skills = [];\n\t\tthis.skillDiagnostics = [];\n\t\tthis.prompts = [];\n\t\tthis.promptDiagnostics = [];\n\t\tthis.themes = [];\n\t\tthis.themeDiagnostics = [];\n\t\tthis.agentsFiles = [];\n\t\tthis.appendSystemPrompt = [];\n\t\tthis.lastSkillPaths = [];\n\t\tthis.extensionSkillSourceInfos = new Map();\n\t\tthis.extensionPromptSourceInfos = new Map();\n\t\tthis.extensionThemeSourceInfos = new Map();\n\t\tthis.lastPromptPaths = [];\n\t\tthis.lastThemePaths = [];\n\t}\n\n\tgetExtensions(): LoadExtensionsResult {\n\t\treturn this.extensionsResult;\n\t}\n\n\tgetSkills(): { skills: Skill[]; diagnostics: ResourceDiagnostic[] } {\n\t\treturn { skills: this.skills, diagnostics: this.skillDiagnostics };\n\t}\n\n\t/**\n\t * Skills permitted by the CURRENTLY active resource profile (the loaded set intersected with the\n\t * live profile filter). Use this everywhere a skill can be SELECTED, INVOKED, or shown to the\n\t * agent — so neither the user (autocomplete / typed `/skill:`) nor the agent (system prompt /\n\t * expansion / command API / RPC) can use a skill the active profile blocks, including after a\n\t * runtime profile switch (router-managed / `/profile`). The full loaded set (`getSkills`) is\n\t * reserved for the profile editor and resource listings, which must show blockable skills.\n\t */\n\tgetActiveSkills(): Skill[] {\n\t\tconst filter = this.settingsManager.getResourceProfileFilter(\"skills\");\n\t\tif (filter.allow.length === 0 && filter.block.length === 0) return this.skills;\n\t\treturn this.skills.filter((s) => {\n\t\t\tconst allowed = filter.allow.length === 0 || matchesResourceProfilePattern(s.filePath, filter.allow, this.cwd);\n\t\t\tconst blocked = matchesResourceProfilePattern(s.filePath, filter.block, this.cwd);\n\t\t\treturn allowed && !blocked;\n\t\t});\n\t}\n\n\tgetPrompts(): { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] } {\n\t\treturn { prompts: this.prompts, diagnostics: this.promptDiagnostics };\n\t}\n\n\t/**\n\t * Prompt templates permitted by the CURRENTLY active resource profile (the loaded set intersected with the\n\t * live profile filter). Use this everywhere a prompt template can be SELECTED, INVOKED, or shown to the\n\t * agent — so neither the user (autocomplete / typed slash command) nor the agent can use a prompt template\n\t * the active profile blocks. The full loaded set (`getPrompts`) is reserved for the profile editor.\n\t */\n\tgetActivePrompts(): PromptTemplate[] {\n\t\tconst filter = this.settingsManager.getResourceProfileFilter(\"prompts\");\n\t\tif (filter.allow.length === 0 && filter.block.length === 0) return this.prompts;\n\t\treturn this.prompts.filter((p) => {\n\t\t\tconst allowed = filter.allow.length === 0 || matchesResourceProfilePattern(p.filePath, filter.allow, this.cwd);\n\t\t\tconst blocked = matchesResourceProfilePattern(p.filePath, filter.block, this.cwd);\n\t\t\treturn allowed && !blocked;\n\t\t});\n\t}\n\n\tgetThemes(): { themes: Theme[]; diagnostics: ResourceDiagnostic[] } {\n\t\treturn { themes: this.themes, diagnostics: this.themeDiagnostics };\n\t}\n\n\t/**\n\t * Themes permitted by the CURRENTLY active resource profile.\n\t */\n\tgetActiveThemes(): Theme[] {\n\t\tconst filter = this.settingsManager.getResourceProfileFilter(\"themes\");\n\t\tif (filter.allow.length === 0 && filter.block.length === 0) return this.themes;\n\t\treturn this.themes.filter((t) => {\n\t\t\tif (!t.sourcePath) return true;\n\t\t\tconst allowed =\n\t\t\t\tfilter.allow.length === 0 || matchesResourceProfilePattern(t.sourcePath, filter.allow, this.cwd);\n\t\t\tconst blocked = matchesResourceProfilePattern(t.sourcePath, filter.block, this.cwd);\n\t\t\treturn allowed && !blocked;\n\t\t});\n\t}\n\n\tgetAgentsFiles(): { agentsFiles: Array<{ path: string; content?: string }> } {\n\t\treturn { agentsFiles: this.agentsFiles };\n\t}\n\n\tgetSystemPrompt(): string | undefined {\n\t\treturn this.systemPrompt;\n\t}\n\n\tgetAppendSystemPrompt(): string[] {\n\t\treturn this.appendSystemPrompt;\n\t}\n\n\t/**\n\t * Get all discoverable extension paths (enabled and disabled).\n\t * Used for profile resource filtering to show the full universe of available extensions.\n\t */\n\tasync getDiscoverableExtensionPaths(): Promise<string[]> {\n\t\tawait this.settingsManager.reload();\n\t\tconst resolvedPaths = await this.packageManager.resolve();\n\t\tconst cliExtensionPaths = await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths, {\n\t\t\ttemporary: true,\n\t\t});\n\t\t// Return all paths (enabled and disabled) from both resolved and CLI sources\n\t\tconst allPaths = new Set<string>();\n\t\tfor (const resource of resolvedPaths.extensions) {\n\t\t\tallPaths.add(resource.path);\n\t\t}\n\t\tfor (const resource of cliExtensionPaths.extensions) {\n\t\t\tallPaths.add(resource.path);\n\t\t}\n\t\treturn Array.from(allPaths);\n\t}\n\n\t/**\n\t * Get a loaded extension by path.\n\t * Matches by path or resolvedPath.\n\t */\n\tgetLoadedExtension(extensionPath: string): Extension | undefined {\n\t\treturn this.extensionsResult.extensions.find(\n\t\t\t(ext) => ext.path === extensionPath || ext.resolvedPath === extensionPath,\n\t\t);\n\t}\n\n\t/**\n\t * Remove and return a loaded extension from the extensions array.\n\t */\n\tremoveLoadedExtension(extensionPath: string): Extension | undefined {\n\t\tconst index = this.extensionsResult.extensions.findIndex(\n\t\t\t(ext) => ext.path === extensionPath || ext.resolvedPath === extensionPath,\n\t\t);\n\t\tif (index === -1) return undefined;\n\t\tconst [ext] = this.extensionsResult.extensions.splice(index, 1);\n\t\treturn ext;\n\t}\n\n\t/**\n\t * Load a single extension with fresh import, reusing the shared runtime.\n\t * Returns the loaded extension or null with error details.\n\t */\n\tasync loadSingleExtension(extensionPath: string): Promise<{ extension: Extension | null; error: string | null }> {\n\t\tconst result = await loadExtension(extensionPath, this.cwd, this.eventBus, this.extensionsResult.runtime, {\n\t\t\tfresh: true,\n\t\t});\n\t\tif (result.extension && !result.error) {\n\t\t\tconst loaded = result.extension;\n\t\t\t// Drop any stale generation at the same path, then register the freshly loaded one so\n\t\t\t// _buildRuntime() aggregates it.\n\t\t\tthis.extensionsResult.extensions = this.extensionsResult.extensions.filter(\n\t\t\t\t(e) => e.path !== loaded.path && e.resolvedPath !== loaded.resolvedPath,\n\t\t\t);\n\t\t\tthis.extensionsResult.extensions.push(loaded);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Apply the active resource-profile allow/block to a list of discovered resource paths.\n\t * Used for every source that does NOT pass through the package manager's\n\t * resolve/applyResourceProfileFilters pipeline (external roots, bundled defaults, and\n\t * extension-contributed resources) so no source bypasses the active profile.\n\t */\n\tprivate filterPathsByProfile(paths: string[], kind: ResourceProfileKind): string[] {\n\t\tconst filter = this.settingsManager.getResourceProfileFilter(kind);\n\t\tif (filter.allow.length === 0 && filter.block.length === 0) return paths;\n\t\treturn paths.filter((p) => {\n\t\t\tconst allowed = filter.allow.length === 0 || matchesResourceProfilePattern(p, filter.allow, this.cwd);\n\t\t\tconst blocked = matchesResourceProfilePattern(p, filter.block, this.cwd);\n\t\t\treturn allowed && !blocked;\n\t\t});\n\t}\n\n\textendResources(paths: ResourceExtensionPaths): void {\n\t\t// Extension-contributed resources (via the resources_discover event) must respect the\n\t\t// active resource profile too — otherwise an allowed extension can re-introduce skills/\n\t\t// prompts/themes the profile blocks.\n\t\tconst allowPath = (entry: { path: string }, kind: ResourceProfileKind): boolean =>\n\t\t\tthis.filterPathsByProfile([entry.path], kind).length > 0;\n\t\tconst skillPaths = this.normalizeExtensionPaths(paths.skillPaths ?? []).filter((e) => allowPath(e, \"skills\"));\n\t\tconst promptPaths = this.normalizeExtensionPaths(paths.promptPaths ?? []).filter((e) => allowPath(e, \"prompts\"));\n\t\tconst themePaths = this.normalizeExtensionPaths(paths.themePaths ?? []).filter((e) => allowPath(e, \"themes\"));\n\n\t\tfor (const entry of skillPaths) {\n\t\t\tthis.extensionSkillSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));\n\t\t}\n\t\tfor (const entry of promptPaths) {\n\t\t\tthis.extensionPromptSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));\n\t\t}\n\t\tfor (const entry of themePaths) {\n\t\t\tthis.extensionThemeSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));\n\t\t}\n\n\t\tif (skillPaths.length > 0) {\n\t\t\tthis.lastSkillPaths = this.mergePaths(\n\t\t\t\tthis.lastSkillPaths,\n\t\t\t\tskillPaths.map((entry) => entry.path),\n\t\t\t);\n\t\t\tthis.updateSkillsFromPaths(this.lastSkillPaths);\n\t\t}\n\n\t\tif (promptPaths.length > 0) {\n\t\t\tthis.lastPromptPaths = this.mergePaths(\n\t\t\t\tthis.lastPromptPaths,\n\t\t\t\tpromptPaths.map((entry) => entry.path),\n\t\t\t);\n\t\t\tthis.updatePromptsFromPaths(this.lastPromptPaths);\n\t\t}\n\n\t\tif (themePaths.length > 0) {\n\t\t\tthis.lastThemePaths = this.mergePaths(\n\t\t\t\tthis.lastThemePaths,\n\t\t\t\tthemePaths.map((entry) => entry.path),\n\t\t\t);\n\t\t\tthis.updateThemesFromPaths(this.lastThemePaths);\n\t\t}\n\t}\n\n\tprivate createSnapshot(): ResourceLoaderSnapshot {\n\t\treturn {\n\t\t\textensionsResult: this.extensionsResult,\n\t\t\tskills: this.skills,\n\t\t\tskillDiagnostics: this.skillDiagnostics,\n\t\t\tprompts: this.prompts,\n\t\t\tpromptDiagnostics: this.promptDiagnostics,\n\t\t\tthemes: this.themes,\n\t\t\tthemeDiagnostics: this.themeDiagnostics,\n\t\t\tagentsFiles: this.agentsFiles,\n\t\t\tsystemPrompt: this.systemPrompt,\n\t\t\tappendSystemPrompt: this.appendSystemPrompt,\n\t\t\tlastSkillPaths: this.lastSkillPaths,\n\t\t\textensionSkillSourceInfos: this.extensionSkillSourceInfos,\n\t\t\textensionPromptSourceInfos: this.extensionPromptSourceInfos,\n\t\t\textensionThemeSourceInfos: this.extensionThemeSourceInfos,\n\t\t\tlastPromptPaths: this.lastPromptPaths,\n\t\t\tlastThemePaths: this.lastThemePaths,\n\t\t};\n\t}\n\n\tprivate restoreSnapshot(snapshot: ResourceLoaderSnapshot): void {\n\t\tthis.extensionsResult = snapshot.extensionsResult;\n\t\tthis.skills = snapshot.skills;\n\t\tthis.skillDiagnostics = snapshot.skillDiagnostics;\n\t\tthis.prompts = snapshot.prompts;\n\t\tthis.promptDiagnostics = snapshot.promptDiagnostics;\n\t\tthis.themes = snapshot.themes;\n\t\tthis.themeDiagnostics = snapshot.themeDiagnostics;\n\t\tthis.agentsFiles = snapshot.agentsFiles;\n\t\tthis.systemPrompt = snapshot.systemPrompt;\n\t\tthis.appendSystemPrompt = snapshot.appendSystemPrompt;\n\t\tthis.lastSkillPaths = snapshot.lastSkillPaths;\n\t\tthis.extensionSkillSourceInfos = snapshot.extensionSkillSourceInfos;\n\t\tthis.extensionPromptSourceInfos = snapshot.extensionPromptSourceInfos;\n\t\tthis.extensionThemeSourceInfos = snapshot.extensionThemeSourceInfos;\n\t\tthis.lastPromptPaths = snapshot.lastPromptPaths;\n\t\tthis.lastThemePaths = snapshot.lastThemePaths;\n\t}\n\n\tasync commitReload(): Promise<void> {\n\t\tif (!this.pendingReloadSnapshot) return;\n\t\tawait disposeExtensionEventSubscriptions(this.pendingReloadSnapshot.extensionsResult.extensions);\n\t\tthis.pendingReloadSnapshot = undefined;\n\t}\n\n\tasync rollbackReload(): Promise<void> {\n\t\tif (!this.pendingReloadSnapshot) return;\n\t\tawait disposeExtensionEventSubscriptions(this.extensionsResult.extensions);\n\t\tthis.restoreSnapshot(this.pendingReloadSnapshot);\n\t\tthis.pendingReloadSnapshot = undefined;\n\t}\n\n\tasync reload(options: ResourceReloadOptions = {}): Promise<void> {\n\t\tconst snapshot = this.createSnapshot();\n\t\tthis.pendingReloadSnapshot = undefined;\n\t\ttry {\n\t\t\tawait this.settingsManager.reload();\n\t\t\tconst resolvedPaths = await this.packageManager.resolve();\n\t\t\tconst cliExtensionPaths = await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths, {\n\t\t\t\ttemporary: true,\n\t\t\t});\n\t\t\tconst metadataByPath = new Map<string, PathMetadata>();\n\n\t\t\tthis.extensionSkillSourceInfos = new Map();\n\t\t\tthis.extensionPromptSourceInfos = new Map();\n\t\t\tthis.extensionThemeSourceInfos = new Map();\n\n\t\t\t// Helper to extract enabled paths and store metadata\n\t\t\tconst getEnabledResources = (\n\t\t\t\tresources: Array<{ path: string; enabled: boolean; metadata: PathMetadata }>,\n\t\t\t): Array<{ path: string; enabled: boolean; metadata: PathMetadata }> => {\n\t\t\t\tfor (const r of resources) {\n\t\t\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\t\t\tmetadataByPath.set(r.path, r.metadata);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn resources.filter((r) => r.enabled);\n\t\t\t};\n\n\t\t\tconst getEnabledPaths = (\n\t\t\t\tresources: Array<{ path: string; enabled: boolean; metadata: PathMetadata }>,\n\t\t\t): string[] => getEnabledResources(resources).map((r) => r.path);\n\n\t\t\tconst enabledExtensions = getEnabledPaths(resolvedPaths.extensions);\n\t\t\tconst enabledSkillResources = getEnabledResources(resolvedPaths.skills);\n\t\t\tconst enabledPrompts = getEnabledPaths(resolvedPaths.prompts);\n\t\t\tconst enabledThemes = getEnabledPaths(resolvedPaths.themes);\n\n\t\t\tconst mapSkillPath = (resource: { path: string; metadata: PathMetadata }): string => {\n\t\t\t\tif (resource.metadata.source !== \"auto\" && resource.metadata.origin !== \"package\") {\n\t\t\t\t\treturn resource.path;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(resource.path);\n\t\t\t\t\tif (!stats.isDirectory()) {\n\t\t\t\t\t\treturn resource.path;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\treturn resource.path;\n\t\t\t\t}\n\t\t\t\tconst skillFile = join(resource.path, \"SKILL.md\");\n\t\t\t\tif (existsSync(skillFile)) {\n\t\t\t\t\tif (!metadataByPath.has(skillFile)) {\n\t\t\t\t\t\tmetadataByPath.set(skillFile, resource.metadata);\n\t\t\t\t\t}\n\t\t\t\t\treturn skillFile;\n\t\t\t\t}\n\t\t\t\treturn resource.path;\n\t\t\t};\n\n\t\t\tconst enabledSkills = enabledSkillResources.map(mapSkillPath);\n\n\t\t\t// Add CLI paths metadata\n\t\t\tfor (const r of cliExtensionPaths.extensions) {\n\t\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\t\tmetadataByPath.set(r.path, { source: \"cli\", scope: \"temporary\", origin: \"top-level\" });\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const r of cliExtensionPaths.skills) {\n\t\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\t\tmetadataByPath.set(r.path, { source: \"cli\", scope: \"temporary\", origin: \"top-level\" });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst cliEnabledExtensions = getEnabledPaths(cliExtensionPaths.extensions);\n\t\t\tconst cliEnabledSkills = getEnabledPaths(cliExtensionPaths.skills);\n\t\t\tconst cliEnabledPrompts = getEnabledPaths(cliExtensionPaths.prompts);\n\t\t\tconst cliEnabledThemes = getEnabledPaths(cliExtensionPaths.themes);\n\n\t\t\t// Gather effective external resource roots\n\t\t\tconst effectiveRoots = this.settingsManager.getEffectiveExternalResourceRoots();\n\n\t\t\tconst filterPathsByProfile = (paths: string[], kind: ResourceProfileKind): string[] =>\n\t\t\t\tthis.filterPathsByProfile(paths, kind);\n\n\t\t\t// Discover external extensions\n\t\t\tconst externalExtensions: string[] = [];\n\t\t\tfor (const root of effectiveRoots) {\n\t\t\t\tconst extDir = join(root, \"extensions\");\n\t\t\t\tif (existsSync(extDir)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst entries = readdirSync(extDir, { withFileTypes: true });\n\t\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\t\tlet isDir = entry.isDirectory();\n\t\t\t\t\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst stats = statSync(join(extDir, entry.name));\n\t\t\t\t\t\t\t\t\tisDir = stats.isDirectory();\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (isDir) {\n\t\t\t\t\t\t\t\tconst entryPath = join(extDir, entry.name);\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\texistsSync(join(entryPath, \"index.ts\")) ||\n\t\t\t\t\t\t\t\t\texistsSync(join(entryPath, \"index.js\")) ||\n\t\t\t\t\t\t\t\t\texistsSync(join(entryPath, \"package.json\"))\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\texternalExtensions.push(entryPath);\n\t\t\t\t\t\t\t\t\tmetadataByPath.set(entryPath, { source: \"external\", scope: \"user\", origin: \"top-level\" });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// silent\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst extensionPaths = this.noExtensions\n\t\t\t\t? cliEnabledExtensions\n\t\t\t\t: this.mergePaths(cliEnabledExtensions, [\n\t\t\t\t\t\t...filterPathsByProfile(enabledExtensions, \"extensions\"),\n\t\t\t\t\t\t...filterPathsByProfile(externalExtensions, \"extensions\"),\n\t\t\t\t\t]);\n\n\t\t\tconst extensionsResult = await loadExtensions(extensionPaths, this.cwd, this.eventBus);\n\t\t\tconst inlineExtensions = await this.loadExtensionFactories(extensionsResult.runtime);\n\t\t\textensionsResult.extensions.push(...inlineExtensions.extensions);\n\t\t\textensionsResult.errors.push(...inlineExtensions.errors);\n\n\t\t\t// Detect extension conflicts (tools, commands, flags with same names from different extensions)\n\t\t\t// Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.\n\t\t\tconst conflicts = this.detectExtensionConflicts(extensionsResult.extensions);\n\t\t\tfor (const conflict of conflicts) {\n\t\t\t\textensionsResult.errors.push({ path: conflict.path, error: conflict.message });\n\t\t\t}\n\n\t\t\tfor (const p of this.additionalExtensionPaths) {\n\t\t\t\tif (isLocalPath(p)) {\n\t\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\t\tif (!existsSync(resolved)) {\n\t\t\t\t\t\textensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst resolvedExtensionsResult = this.extensionsOverride\n\t\t\t\t? this.extensionsOverride(extensionsResult)\n\t\t\t\t: extensionsResult;\n\t\t\tif (options.failOnExtensionErrors && resolvedExtensionsResult.errors.length > 0) {\n\t\t\t\tconst summary = resolvedExtensionsResult.errors\n\t\t\t\t\t.slice(0, 6)\n\t\t\t\t\t.map((error) => `${error.path}: ${error.error}`)\n\t\t\t\t\t.join(\"; \");\n\t\t\t\tthrow new Error(`Extension reload failed preflight: ${summary}`);\n\t\t\t}\n\t\t\tthis.extensionsResult = resolvedExtensionsResult;\n\t\t\tthis.applyExtensionSourceInfo(this.extensionsResult.extensions, metadataByPath);\n\n\t\t\t// Discover external skills\n\t\t\tconst externalSkills: string[] = [];\n\t\t\tfor (const root of effectiveRoots) {\n\t\t\t\tconst skillsDir = join(root, \"skills\");\n\t\t\t\tif (existsSync(skillsDir)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst entries = readdirSync(skillsDir, { withFileTypes: true });\n\t\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\t\tlet isDir = entry.isDirectory();\n\t\t\t\t\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst stats = statSync(join(skillsDir, entry.name));\n\t\t\t\t\t\t\t\t\tisDir = stats.isDirectory();\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (isDir) {\n\t\t\t\t\t\t\t\tconst entryPath = join(skillsDir, entry.name);\n\t\t\t\t\t\t\t\tconst skillFile = join(entryPath, \"SKILL.md\");\n\t\t\t\t\t\t\t\tconst targetPath = existsSync(skillFile) ? skillFile : entryPath;\n\t\t\t\t\t\t\t\texternalSkills.push(targetPath);\n\t\t\t\t\t\t\t\tmetadataByPath.set(targetPath, { source: \"external\", scope: \"user\", origin: \"top-level\" });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// silent\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Build skill paths with precedence: CLI > user/project > bundled > additional.\n\t\t\t// Bundled skills are expanded into individual SKILL.md paths so they pass through the\n\t\t\t// resource-profile filter exactly like user/external skills (no source bypasses the profile).\n\t\t\tconst bundledSkillsDir = getBundledSkillsDir();\n\t\t\tconst bundledSkillPaths: string[] = [];\n\t\t\tif (existsSync(bundledSkillsDir)) {\n\t\t\t\ttry {\n\t\t\t\t\tfor (const entry of readdirSync(bundledSkillsDir, { withFileTypes: true })) {\n\t\t\t\t\t\tif (!entry.isDirectory()) continue;\n\t\t\t\t\t\tconst entryPath = join(bundledSkillsDir, entry.name);\n\t\t\t\t\t\tconst skillFile = join(entryPath, \"SKILL.md\");\n\t\t\t\t\t\tbundledSkillPaths.push(existsSync(skillFile) ? skillFile : entryPath);\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// silent\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst skillPaths = this.noSkills\n\t\t\t\t? this.mergePaths([...cliEnabledSkills], this.additionalSkillPaths)\n\t\t\t\t: this.mergePaths(\n\t\t\t\t\t\t[...cliEnabledSkills, ...enabledSkills, ...externalSkills, ...bundledSkillPaths],\n\t\t\t\t\t\tthis.additionalSkillPaths,\n\t\t\t\t\t);\n\n\t\t\tthis.lastSkillPaths = skillPaths;\n\t\t\tthis.updateSkillsFromPaths(skillPaths, metadataByPath);\n\t\t\tfor (const p of this.additionalSkillPaths) {\n\t\t\t\tif (isLocalPath(p)) {\n\t\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\t\tif (!existsSync(resolved) && !this.skillDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\t\tthis.skillDiagnostics.push({ type: \"error\", message: \"Skill path does not exist\", path: resolved });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Discover external prompts\n\t\t\tconst externalPrompts: string[] = [];\n\t\t\tfor (const root of effectiveRoots) {\n\t\t\t\tconst promptsDir = join(root, \"prompts\");\n\t\t\t\tif (existsSync(promptsDir)) {\n\t\t\t\t\tconst files = collectFilesRecursively(promptsDir, /\\.md$/);\n\t\t\t\t\tfor (const f of files) {\n\t\t\t\t\t\texternalPrompts.push(f);\n\t\t\t\t\t\tmetadataByPath.set(f, { source: \"external\", scope: \"user\", origin: \"top-level\" });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Bundled prompts expanded into individual files so they pass through the profile filter too.\n\t\t\tconst bundledPromptsDir = getBundledPromptsDir();\n\t\t\tconst bundledPromptPaths = existsSync(bundledPromptsDir)\n\t\t\t\t? collectFilesRecursively(bundledPromptsDir, /\\.md$/)\n\t\t\t\t: [];\n\t\t\tconst promptPaths = this.noPromptTemplates\n\t\t\t\t? this.mergePaths(cliEnabledPrompts, this.additionalPromptTemplatePaths)\n\t\t\t\t: this.mergePaths(\n\t\t\t\t\t\t[...cliEnabledPrompts, ...enabledPrompts, ...externalPrompts, ...bundledPromptPaths],\n\t\t\t\t\t\tthis.additionalPromptTemplatePaths,\n\t\t\t\t\t);\n\n\t\t\tthis.lastPromptPaths = promptPaths;\n\t\t\tthis.updatePromptsFromPaths(promptPaths, metadataByPath);\n\t\t\tfor (const p of this.additionalPromptTemplatePaths) {\n\t\t\t\tif (isLocalPath(p)) {\n\t\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\t\tif (!existsSync(resolved) && !this.promptDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\t\tthis.promptDiagnostics.push({\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tmessage: \"Prompt template path does not exist\",\n\t\t\t\t\t\t\tpath: resolved,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Discover external themes\n\t\t\tconst externalThemes: string[] = [];\n\t\t\tfor (const root of effectiveRoots) {\n\t\t\t\tconst themesDir = join(root, \"themes\");\n\t\t\t\tif (existsSync(themesDir)) {\n\t\t\t\t\tconst files = collectFilesRecursively(themesDir, /\\.json$/);\n\t\t\t\t\tfor (const f of files) {\n\t\t\t\t\t\texternalThemes.push(f);\n\t\t\t\t\t\tmetadataByPath.set(f, { source: \"external\", scope: \"user\", origin: \"top-level\" });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst themePaths = this.noThemes\n\t\t\t\t? this.mergePaths(cliEnabledThemes, this.additionalThemePaths)\n\t\t\t\t: this.mergePaths([...cliEnabledThemes, ...enabledThemes, ...externalThemes], this.additionalThemePaths);\n\n\t\t\tthis.lastThemePaths = themePaths;\n\t\t\tthis.updateThemesFromPaths(themePaths, metadataByPath);\n\t\t\tfor (const p of this.additionalThemePaths) {\n\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\tif (!existsSync(resolved) && !this.themeDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\tthis.themeDiagnostics.push({ type: \"error\", message: \"Theme path does not exist\", path: resolved });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst rawAgentsFiles = this.noContextFiles\n\t\t\t\t? []\n\t\t\t\t: loadProjectContextFiles({\n\t\t\t\t\t\tcwd: this.cwd,\n\t\t\t\t\t\tagentDir: this.agentDir,\n\t\t\t\t\t\tprojectTrusted: this.settingsManager.isProjectTrusted(),\n\t\t\t\t\t});\n\t\t\tconst agentEmbeddedProfiles: Record<string, ResourceProfileSettings> = {};\n\t\t\tconst activeProfileNames = this.settingsManager.getActiveResourceProfileNames();\n\t\t\tfor (const file of rawAgentsFiles) {\n\t\t\t\ttry {\n\t\t\t\t\tconst rawContent = readFileSync(file.path, \"utf-8\");\n\t\t\t\t\tconst { profiles } = parseResourceProfileBlocks(rawContent, { profileNames: activeProfileNames });\n\t\t\t\t\tObject.assign(agentEmbeddedProfiles, mergeResourceProfileMap(agentEmbeddedProfiles, profiles));\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t\tthis.settingsManager.addDiscoveredResourceProfileDefinitions(agentEmbeddedProfiles);\n\t\t\tconst agentProfileFilter = this.settingsManager.getResourceProfileFilter(\"agents\");\n\t\t\tconst agentsFiles = {\n\t\t\t\tagentsFiles: rawAgentsFiles\n\t\t\t\t\t.filter((file) => {\n\t\t\t\t\t\tconst allowed =\n\t\t\t\t\t\t\tagentProfileFilter.allow.length === 0 ||\n\t\t\t\t\t\t\tmatchesResourceProfilePattern(file.path, agentProfileFilter.allow, this.cwd);\n\t\t\t\t\t\tconst blocked = matchesResourceProfilePattern(file.path, agentProfileFilter.block, this.cwd);\n\t\t\t\t\t\treturn allowed && !blocked;\n\t\t\t\t\t})\n\t\t\t\t\t.map((file) => ({\n\t\t\t\t\t\t...file,\n\t\t\t\t\t\tcontent: file.content ? stripResourceProfileBlocks(file.content) : file.content,\n\t\t\t\t\t})),\n\t\t\t};\n\t\t\tconst resolvedAgentsFiles = this.agentsFilesOverride ? this.agentsFilesOverride(agentsFiles) : agentsFiles;\n\t\t\tthis.agentsFiles = resolvedAgentsFiles.agentsFiles;\n\n\t\t\tconst baseSystemPrompt = resolvePromptInput(\n\t\t\t\tthis.systemPromptSource ?? this.discoverSystemPromptFile(),\n\t\t\t\t\"system prompt\",\n\t\t\t);\n\t\t\tthis.systemPrompt = this.systemPromptOverride ? this.systemPromptOverride(baseSystemPrompt) : baseSystemPrompt;\n\n\t\t\tconst appendSources =\n\t\t\t\tthis.appendSystemPromptSource ??\n\t\t\t\t(this.discoverAppendSystemPromptFile() ? [this.discoverAppendSystemPromptFile()!] : []);\n\t\t\tconst baseAppend = appendSources\n\t\t\t\t.map((s) => resolvePromptInput(s, \"append system prompt\"))\n\t\t\t\t.filter((s): s is string => s !== undefined);\n\t\t\tthis.appendSystemPrompt = this.appendSystemPromptOverride\n\t\t\t\t? this.appendSystemPromptOverride(baseAppend)\n\t\t\t\t: baseAppend;\n\t\t\tif (options.deferExtensionDispose) {\n\t\t\t\tthis.pendingReloadSnapshot = snapshot;\n\t\t\t} else {\n\t\t\t\tawait disposeExtensionEventSubscriptions(snapshot.extensionsResult.extensions);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (this.extensionsResult !== snapshot.extensionsResult) {\n\t\t\t\tawait disposeExtensionEventSubscriptions(this.extensionsResult.extensions);\n\t\t\t}\n\t\t\tthis.restoreSnapshot(snapshot);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate normalizeExtensionPaths(\n\t\tentries: Array<{ path: string; metadata: PathMetadata }>,\n\t): Array<{ path: string; metadata: PathMetadata }> {\n\t\treturn entries.map((entry) => {\n\t\t\tconst metadata = entry.metadata.baseDir\n\t\t\t\t? { ...entry.metadata, baseDir: this.resolveResourcePath(entry.metadata.baseDir) }\n\t\t\t\t: entry.metadata;\n\t\t\treturn {\n\t\t\t\tpath: this.resolveResourcePath(entry.path),\n\t\t\t\tmetadata,\n\t\t\t};\n\t\t});\n\t}\n\n\tprivate updateSkillsFromPaths(skillPaths: string[], metadataByPath?: Map<string, PathMetadata>): void {\n\t\tlet skillsResult: { skills: Skill[]; diagnostics: ResourceDiagnostic[] };\n\t\tif (this.noSkills && skillPaths.length === 0) {\n\t\t\tskillsResult = { skills: [], diagnostics: [] };\n\t\t} else {\n\t\t\tskillsResult = loadSkills({\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tagentDir: this.agentDir,\n\t\t\t\tskillPaths,\n\t\t\t\tincludeDefaults: false,\n\t\t\t});\n\t\t}\n\t\tconst resolvedSkills = this.skillsOverride ? this.skillsOverride(skillsResult) : skillsResult;\n\t\tthis.skills = resolvedSkills.skills.map((skill) => ({\n\t\t\t...skill,\n\t\t\tsourceInfo:\n\t\t\t\tthis.findSourceInfoForPath(skill.filePath, this.extensionSkillSourceInfos, metadataByPath) ??\n\t\t\t\tskill.sourceInfo ??\n\t\t\t\tthis.getDefaultSourceInfoForPath(skill.filePath),\n\t\t}));\n\t\tthis.skillDiagnostics = resolvedSkills.diagnostics;\n\t}\n\n\tprivate updatePromptsFromPaths(promptPaths: string[], metadataByPath?: Map<string, PathMetadata>): void {\n\t\tlet promptsResult: { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] };\n\t\tif (this.noPromptTemplates && promptPaths.length === 0) {\n\t\t\tpromptsResult = { prompts: [], diagnostics: [] };\n\t\t} else {\n\t\t\tconst allPrompts = loadPromptTemplates({\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tagentDir: this.agentDir,\n\t\t\t\tpromptPaths,\n\t\t\t\tincludeDefaults: false,\n\t\t\t});\n\t\t\tpromptsResult = this.dedupePrompts(allPrompts);\n\t\t}\n\t\tconst resolvedPrompts = this.promptsOverride ? this.promptsOverride(promptsResult) : promptsResult;\n\t\tthis.prompts = resolvedPrompts.prompts.map((prompt) => ({\n\t\t\t...prompt,\n\t\t\tsourceInfo:\n\t\t\t\tthis.findSourceInfoForPath(prompt.filePath, this.extensionPromptSourceInfos, metadataByPath) ??\n\t\t\t\tprompt.sourceInfo ??\n\t\t\t\tthis.getDefaultSourceInfoForPath(prompt.filePath),\n\t\t}));\n\t\tthis.promptDiagnostics = resolvedPrompts.diagnostics;\n\t}\n\n\tprivate updateThemesFromPaths(themePaths: string[], metadataByPath?: Map<string, PathMetadata>): void {\n\t\tlet themesResult: { themes: Theme[]; diagnostics: ResourceDiagnostic[] };\n\t\tif (this.noThemes && themePaths.length === 0) {\n\t\t\tthemesResult = { themes: [], diagnostics: [] };\n\t\t} else {\n\t\t\tconst loaded = this.loadThemes(themePaths, false);\n\t\t\tconst deduped = this.dedupeThemes(loaded.themes);\n\t\t\tthemesResult = { themes: deduped.themes, diagnostics: [...loaded.diagnostics, ...deduped.diagnostics] };\n\t\t}\n\t\tconst resolvedThemes = this.themesOverride ? this.themesOverride(themesResult) : themesResult;\n\t\tthis.themes = resolvedThemes.themes.map((theme) => {\n\t\t\tconst sourcePath = theme.sourcePath;\n\t\t\ttheme.sourceInfo = sourcePath\n\t\t\t\t? (this.findSourceInfoForPath(sourcePath, this.extensionThemeSourceInfos, metadataByPath) ??\n\t\t\t\t\ttheme.sourceInfo ??\n\t\t\t\t\tthis.getDefaultSourceInfoForPath(sourcePath))\n\t\t\t\t: theme.sourceInfo;\n\t\t\treturn theme;\n\t\t});\n\t\tthis.themeDiagnostics = resolvedThemes.diagnostics;\n\t}\n\n\tprivate applyExtensionSourceInfo(extensions: Extension[], metadataByPath: Map<string, PathMetadata>): void {\n\t\tfor (const extension of extensions) {\n\t\t\textension.sourceInfo =\n\t\t\t\tthis.findSourceInfoForPath(extension.path, undefined, metadataByPath) ??\n\t\t\t\tthis.getDefaultSourceInfoForPath(extension.path);\n\t\t\tfor (const command of extension.commands.values()) {\n\t\t\t\tcommand.sourceInfo = extension.sourceInfo;\n\t\t\t}\n\t\t\tfor (const tool of extension.tools.values()) {\n\t\t\t\ttool.sourceInfo = extension.sourceInfo;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate findSourceInfoForPath(\n\t\tresourcePath: string,\n\t\textraSourceInfos?: Map<string, SourceInfo>,\n\t\tmetadataByPath?: Map<string, PathMetadata>,\n\t): SourceInfo | undefined {\n\t\tif (!resourcePath) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (resourcePath.startsWith(\"<\")) {\n\t\t\treturn this.getDefaultSourceInfoForPath(resourcePath);\n\t\t}\n\n\t\tconst normalizedResourcePath = resolve(resourcePath);\n\t\tif (extraSourceInfos) {\n\t\t\tfor (const [sourcePath, sourceInfo] of extraSourceInfos.entries()) {\n\t\t\t\tconst normalizedSourcePath = resolve(sourcePath);\n\t\t\t\tif (\n\t\t\t\t\tnormalizedResourcePath === normalizedSourcePath ||\n\t\t\t\t\tnormalizedResourcePath.startsWith(`${normalizedSourcePath}${sep}`)\n\t\t\t\t) {\n\t\t\t\t\treturn { ...sourceInfo, path: resourcePath };\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (metadataByPath) {\n\t\t\tconst exact = metadataByPath.get(normalizedResourcePath) ?? metadataByPath.get(resourcePath);\n\t\t\tif (exact) {\n\t\t\t\treturn createSourceInfo(resourcePath, exact);\n\t\t\t}\n\n\t\t\tfor (const [sourcePath, metadata] of metadataByPath.entries()) {\n\t\t\t\tconst normalizedSourcePath = resolve(sourcePath);\n\t\t\t\tif (\n\t\t\t\t\tnormalizedResourcePath === normalizedSourcePath ||\n\t\t\t\t\tnormalizedResourcePath.startsWith(`${normalizedSourcePath}${sep}`)\n\t\t\t\t) {\n\t\t\t\t\treturn createSourceInfo(resourcePath, metadata);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tprivate getDefaultSourceInfoForPath(filePath: string): SourceInfo {\n\t\tif (filePath.startsWith(\"<\") && filePath.endsWith(\">\")) {\n\t\t\treturn {\n\t\t\t\tpath: filePath,\n\t\t\t\tsource: filePath.slice(1, -1).split(\":\")[0] || \"temporary\",\n\t\t\t\tscope: \"temporary\",\n\t\t\t\torigin: \"top-level\",\n\t\t\t};\n\t\t}\n\n\t\tconst normalizedPath = resolve(filePath);\n\t\tconst agentRoots = [\n\t\t\tjoin(this.agentDir, \"skills\"),\n\t\t\tjoin(this.agentDir, \"prompts\"),\n\t\t\tjoin(this.agentDir, \"themes\"),\n\t\t\tjoin(this.agentDir, \"extensions\"),\n\t\t];\n\t\tconst projectRoots = [\n\t\t\tjoin(this.cwd, CONFIG_DIR_NAME, \"skills\"),\n\t\t\tjoin(this.cwd, CONFIG_DIR_NAME, \"prompts\"),\n\t\t\tjoin(this.cwd, CONFIG_DIR_NAME, \"themes\"),\n\t\t\tjoin(this.cwd, CONFIG_DIR_NAME, \"extensions\"),\n\t\t];\n\n\t\tfor (const root of agentRoots) {\n\t\t\tif (this.isUnderPath(normalizedPath, root)) {\n\t\t\t\treturn { path: filePath, source: \"local\", scope: \"user\", origin: \"top-level\", baseDir: root };\n\t\t\t}\n\t\t}\n\n\t\tfor (const root of projectRoots) {\n\t\t\tif (this.isUnderPath(normalizedPath, root)) {\n\t\t\t\treturn { path: filePath, source: \"local\", scope: \"project\", origin: \"top-level\", baseDir: root };\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tpath: filePath,\n\t\t\tsource: \"local\",\n\t\t\tscope: \"temporary\",\n\t\t\torigin: \"top-level\",\n\t\t\tbaseDir: statSync(normalizedPath).isDirectory() ? normalizedPath : resolve(normalizedPath, \"..\"),\n\t\t};\n\t}\n\n\tprivate mergePaths(primary: string[], additional: string[]): string[] {\n\t\tconst merged: string[] = [];\n\t\tconst seen = new Set<string>();\n\n\t\tfor (const p of [...primary, ...additional]) {\n\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\tconst canonicalPath = canonicalizePath(resolved);\n\t\t\tif (seen.has(canonicalPath)) continue;\n\t\t\tseen.add(canonicalPath);\n\t\t\tmerged.push(resolved);\n\t\t}\n\n\t\treturn merged;\n\t}\n\n\tprivate resolveResourcePath(p: string): string {\n\t\treturn resolvePath(p, this.cwd, { trim: true });\n\t}\n\n\tprivate loadThemes(\n\t\tpaths: string[],\n\t\tincludeDefaults: boolean = true,\n\t): {\n\t\tthemes: Theme[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t} {\n\t\tconst themes: Theme[] = [];\n\t\tconst diagnostics: ResourceDiagnostic[] = [];\n\t\tif (includeDefaults) {\n\t\t\tconst defaultDirs = [join(this.agentDir, \"themes\"), join(this.cwd, CONFIG_DIR_NAME, \"themes\")];\n\n\t\t\tfor (const dir of defaultDirs) {\n\t\t\t\tthis.loadThemesFromDir(dir, themes, diagnostics);\n\t\t\t}\n\t\t}\n\n\t\tfor (const p of paths) {\n\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\tif (!existsSync(resolved)) {\n\t\t\t\tdiagnostics.push({ type: \"warning\", message: \"theme path does not exist\", path: resolved });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst stats = statSync(resolved);\n\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\tthis.loadThemesFromDir(resolved, themes, diagnostics);\n\t\t\t\t} else if (stats.isFile() && resolved.endsWith(\".json\")) {\n\t\t\t\t\tthis.loadThemeFromFile(resolved, themes, diagnostics);\n\t\t\t\t} else {\n\t\t\t\t\tdiagnostics.push({ type: \"warning\", message: \"theme path is not a json file\", path: resolved });\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"failed to read theme path\";\n\t\t\t\tdiagnostics.push({ type: \"warning\", message, path: resolved });\n\t\t\t}\n\t\t}\n\n\t\treturn { themes, diagnostics };\n\t}\n\n\tprivate loadThemesFromDir(dir: string, themes: Theme[], diagnostics: ResourceDiagnostic[]): void {\n\t\tif (!existsSync(dir)) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\t\t\tfor (const entry of entries) {\n\t\t\t\tlet isFile = entry.isFile();\n\t\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tisFile = statSync(join(dir, entry.name)).isFile();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!isFile) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!entry.name.endsWith(\".json\")) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthis.loadThemeFromFile(join(dir, entry.name), themes, diagnostics);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read theme directory\";\n\t\t\tdiagnostics.push({ type: \"warning\", message, path: dir });\n\t\t}\n\t}\n\n\tprivate loadThemeFromFile(filePath: string, themes: Theme[], diagnostics: ResourceDiagnostic[]): void {\n\t\ttry {\n\t\t\tthemes.push(loadThemeFromPath(filePath));\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to load theme\";\n\t\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\t}\n\t}\n\n\tprivate async loadExtensionFactories(runtime: ExtensionRuntime): Promise<{\n\t\textensions: Extension[];\n\t\terrors: Array<{ path: string; error: string }>;\n\t}> {\n\t\tconst extensions: Extension[] = [];\n\t\tconst errors: Array<{ path: string; error: string }> = [];\n\n\t\tfor (const [index, factory] of this.extensionFactories.entries()) {\n\t\t\tconst extensionPath = `<inline:${index + 1}>`;\n\t\t\ttry {\n\t\t\t\tconst extension = await loadExtensionFromFactory(factory, this.cwd, this.eventBus, runtime, extensionPath);\n\t\t\t\textensions.push(extension);\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"failed to load extension\";\n\t\t\t\terrors.push({ path: extensionPath, error: message });\n\t\t\t}\n\t\t}\n\n\t\treturn { extensions, errors };\n\t}\n\n\tprivate dedupePrompts(prompts: PromptTemplate[]): { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] } {\n\t\tconst seen = new Map<string, PromptTemplate>();\n\t\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\t\tfor (const prompt of prompts) {\n\t\t\tconst existing = seen.get(prompt.name);\n\t\t\tif (existing) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"/${prompt.name}\" collision`,\n\t\t\t\t\tpath: prompt.filePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"prompt\",\n\t\t\t\t\t\tname: prompt.name,\n\t\t\t\t\t\twinnerPath: existing.filePath,\n\t\t\t\t\t\tloserPath: prompt.filePath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tseen.set(prompt.name, prompt);\n\t\t\t}\n\t\t}\n\n\t\treturn { prompts: Array.from(seen.values()), diagnostics };\n\t}\n\n\tprivate dedupeThemes(themes: Theme[]): { themes: Theme[]; diagnostics: ResourceDiagnostic[] } {\n\t\tconst seen = new Map<string, Theme>();\n\t\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\t\tfor (const t of themes) {\n\t\t\tconst name = t.name ?? \"unnamed\";\n\t\t\tconst existing = seen.get(name);\n\t\t\tif (existing) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"${name}\" collision`,\n\t\t\t\t\tpath: t.sourcePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"theme\",\n\t\t\t\t\t\tname,\n\t\t\t\t\t\twinnerPath: existing.sourcePath ?? \"<builtin>\",\n\t\t\t\t\t\tloserPath: t.sourcePath ?? \"<builtin>\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tseen.set(name, t);\n\t\t\t}\n\t\t}\n\n\t\treturn { themes: Array.from(seen.values()), diagnostics };\n\t}\n\n\tprivate discoverSystemPromptFile(): string | undefined {\n\t\tconst projectPath = join(this.cwd, CONFIG_DIR_NAME, \"SYSTEM.md\");\n\t\tif (this.settingsManager.isProjectTrusted() && existsSync(projectPath)) {\n\t\t\treturn projectPath;\n\t\t}\n\n\t\tconst globalPath = join(this.agentDir, \"SYSTEM.md\");\n\t\tif (existsSync(globalPath)) {\n\t\t\treturn globalPath;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tprivate discoverAppendSystemPromptFile(): string | undefined {\n\t\tconst projectPath = join(this.cwd, CONFIG_DIR_NAME, \"APPEND_SYSTEM.md\");\n\t\tif (this.settingsManager.isProjectTrusted() && existsSync(projectPath)) {\n\t\t\treturn projectPath;\n\t\t}\n\n\t\tconst globalPath = join(this.agentDir, \"APPEND_SYSTEM.md\");\n\t\tif (existsSync(globalPath)) {\n\t\t\treturn globalPath;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tprivate isUnderPath(target: string, root: string): boolean {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t}\n\n\tprivate detectExtensionConflicts(extensions: Extension[]): Array<{ path: string; message: string }> {\n\t\tconst conflicts: Array<{ path: string; message: string }> = [];\n\n\t\t// Track which extension registered each tool and flag\n\t\tconst toolOwners = new Map<string, string>();\n\t\tconst flagOwners = new Map<string, string>();\n\n\t\tfor (const ext of extensions) {\n\t\t\t// Check tools\n\t\t\tfor (const toolName of ext.tools.keys()) {\n\t\t\t\tconst existingOwner = toolOwners.get(toolName);\n\t\t\t\tif (existingOwner && existingOwner !== ext.path) {\n\t\t\t\t\tconflicts.push({\n\t\t\t\t\t\tpath: ext.path,\n\t\t\t\t\t\tmessage: `Tool \"${toolName}\" conflicts with ${existingOwner}`,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\ttoolOwners.set(toolName, ext.path);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Check flags\n\t\t\tfor (const flagName of ext.flags.keys()) {\n\t\t\t\tconst existingOwner = flagOwners.get(flagName);\n\t\t\t\tif (existingOwner && existingOwner !== ext.path) {\n\t\t\t\t\tconflicts.push({\n\t\t\t\t\t\tpath: ext.path,\n\t\t\t\t\t\tmessage: `Flag \"--${flagName}\" conflicts with ${existingOwner}`,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tflagOwners.set(flagName, ext.path);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn conflicts;\n\t}\n}\n\nfunction collectFilesRecursively(dir: string, pattern: RegExp): string[] {\n\tconst files: string[] = [];\n\tif (!existsSync(dir)) return files;\n\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name.startsWith(\".\")) continue;\n\t\t\tif (entry.name === \"node_modules\") continue;\n\n\t\t\tconst fullPath = join(dir, entry.name);\n\t\t\tlet isDir = entry.isDirectory();\n\t\t\tlet isFile = entry.isFile();\n\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisDir = stats.isDirectory();\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isDir) {\n\t\t\t\tfiles.push(...collectFilesRecursively(fullPath, pattern));\n\t\t\t} else if (isFile && pattern.test(entry.name)) {\n\t\t\t\tfiles.push(fullPath);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// silent\n\t}\n\treturn files;\n}\n"]}
@@ -197,12 +197,61 @@ export class DefaultResourceLoader {
197
197
  getSkills() {
198
198
  return { skills: this.skills, diagnostics: this.skillDiagnostics };
199
199
  }
200
+ /**
201
+ * Skills permitted by the CURRENTLY active resource profile (the loaded set intersected with the
202
+ * live profile filter). Use this everywhere a skill can be SELECTED, INVOKED, or shown to the
203
+ * agent — so neither the user (autocomplete / typed `/skill:`) nor the agent (system prompt /
204
+ * expansion / command API / RPC) can use a skill the active profile blocks, including after a
205
+ * runtime profile switch (router-managed / `/profile`). The full loaded set (`getSkills`) is
206
+ * reserved for the profile editor and resource listings, which must show blockable skills.
207
+ */
208
+ getActiveSkills() {
209
+ const filter = this.settingsManager.getResourceProfileFilter("skills");
210
+ if (filter.allow.length === 0 && filter.block.length === 0)
211
+ return this.skills;
212
+ return this.skills.filter((s) => {
213
+ const allowed = filter.allow.length === 0 || matchesResourceProfilePattern(s.filePath, filter.allow, this.cwd);
214
+ const blocked = matchesResourceProfilePattern(s.filePath, filter.block, this.cwd);
215
+ return allowed && !blocked;
216
+ });
217
+ }
200
218
  getPrompts() {
201
219
  return { prompts: this.prompts, diagnostics: this.promptDiagnostics };
202
220
  }
221
+ /**
222
+ * Prompt templates permitted by the CURRENTLY active resource profile (the loaded set intersected with the
223
+ * live profile filter). Use this everywhere a prompt template can be SELECTED, INVOKED, or shown to the
224
+ * agent — so neither the user (autocomplete / typed slash command) nor the agent can use a prompt template
225
+ * the active profile blocks. The full loaded set (`getPrompts`) is reserved for the profile editor.
226
+ */
227
+ getActivePrompts() {
228
+ const filter = this.settingsManager.getResourceProfileFilter("prompts");
229
+ if (filter.allow.length === 0 && filter.block.length === 0)
230
+ return this.prompts;
231
+ return this.prompts.filter((p) => {
232
+ const allowed = filter.allow.length === 0 || matchesResourceProfilePattern(p.filePath, filter.allow, this.cwd);
233
+ const blocked = matchesResourceProfilePattern(p.filePath, filter.block, this.cwd);
234
+ return allowed && !blocked;
235
+ });
236
+ }
203
237
  getThemes() {
204
238
  return { themes: this.themes, diagnostics: this.themeDiagnostics };
205
239
  }
240
+ /**
241
+ * Themes permitted by the CURRENTLY active resource profile.
242
+ */
243
+ getActiveThemes() {
244
+ const filter = this.settingsManager.getResourceProfileFilter("themes");
245
+ if (filter.allow.length === 0 && filter.block.length === 0)
246
+ return this.themes;
247
+ return this.themes.filter((t) => {
248
+ if (!t.sourcePath)
249
+ return true;
250
+ const allowed = filter.allow.length === 0 || matchesResourceProfilePattern(t.sourcePath, filter.allow, this.cwd);
251
+ const blocked = matchesResourceProfilePattern(t.sourcePath, filter.block, this.cwd);
252
+ return allowed && !blocked;
253
+ });
254
+ }
206
255
  getAgentsFiles() {
207
256
  return { agentsFiles: this.agentsFiles };
208
257
  }
@@ -468,7 +517,7 @@ export class DefaultResourceLoader {
468
517
  const extensionPaths = this.noExtensions
469
518
  ? cliEnabledExtensions
470
519
  : this.mergePaths(cliEnabledExtensions, [
471
- ...enabledExtensions,
520
+ ...filterPathsByProfile(enabledExtensions, "extensions"),
472
521
  ...filterPathsByProfile(externalExtensions, "extensions"),
473
522
  ]);
474
523
  const extensionsResult = await loadExtensions(extensionPaths, this.cwd, this.eventBus);
@@ -554,12 +603,7 @@ export class DefaultResourceLoader {
554
603
  }
555
604
  const skillPaths = this.noSkills
556
605
  ? this.mergePaths([...cliEnabledSkills], this.additionalSkillPaths)
557
- : this.mergePaths([
558
- ...cliEnabledSkills,
559
- ...enabledSkills,
560
- ...filterPathsByProfile(externalSkills, "skills"),
561
- ...filterPathsByProfile(bundledSkillPaths, "skills"),
562
- ], this.additionalSkillPaths);
606
+ : this.mergePaths([...cliEnabledSkills, ...enabledSkills, ...externalSkills, ...bundledSkillPaths], this.additionalSkillPaths);
563
607
  this.lastSkillPaths = skillPaths;
564
608
  this.updateSkillsFromPaths(skillPaths, metadataByPath);
565
609
  for (const p of this.additionalSkillPaths) {
@@ -589,12 +633,7 @@ export class DefaultResourceLoader {
589
633
  : [];
590
634
  const promptPaths = this.noPromptTemplates
591
635
  ? this.mergePaths(cliEnabledPrompts, this.additionalPromptTemplatePaths)
592
- : this.mergePaths([
593
- ...cliEnabledPrompts,
594
- ...enabledPrompts,
595
- ...filterPathsByProfile(externalPrompts, "prompts"),
596
- ...filterPathsByProfile(bundledPromptPaths, "prompts"),
597
- ], this.additionalPromptTemplatePaths);
636
+ : this.mergePaths([...cliEnabledPrompts, ...enabledPrompts, ...externalPrompts, ...bundledPromptPaths], this.additionalPromptTemplatePaths);
598
637
  this.lastPromptPaths = promptPaths;
599
638
  this.updatePromptsFromPaths(promptPaths, metadataByPath);
600
639
  for (const p of this.additionalPromptTemplatePaths) {
@@ -623,7 +662,7 @@ export class DefaultResourceLoader {
623
662
  }
624
663
  const themePaths = this.noThemes
625
664
  ? this.mergePaths(cliEnabledThemes, this.additionalThemePaths)
626
- : this.mergePaths([...cliEnabledThemes, ...enabledThemes, ...filterPathsByProfile(externalThemes, "themes")], this.additionalThemePaths);
665
+ : this.mergePaths([...cliEnabledThemes, ...enabledThemes, ...externalThemes], this.additionalThemePaths);
627
666
  this.lastThemePaths = themePaths;
628
667
  this.updateThemesFromPaths(themePaths, metadataByPath);
629
668
  for (const p of this.additionalThemePaths) {