@hoilab/ada-cli 0.84.16 → 0.84.18

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.
@@ -0,0 +1,274 @@
1
+ /**
2
+ * Ada Secure Vault — encrypted secret storage.
3
+ *
4
+ * - Project vault: AES-256-GCM encrypted at rest under
5
+ * <agentDir>/vault/<project-hash>/vault.json; the key is derived from the
6
+ * user passphrase with scrypt (never stored).
7
+ * - Session vault: per-conversation secrets kept ONLY in process memory
8
+ * (never written to disk).
9
+ * - Values are exposed to the LLM only through @vault:<name> expansion in
10
+ * the user's prompt, and the persisted session file stores the redacted
11
+ * form (the expansion is stripped before persistence).
12
+ *
13
+ * Zero native dependencies: node:crypto works on Node and Bun.
14
+ */
15
+ import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from "node:crypto";
16
+ import { readFile, writeFile, mkdir } from "node:fs/promises";
17
+ import { existsSync } from "node:fs";
18
+ import { dirname, join } from "node:path";
19
+ const KDF_N = 32768;
20
+ const KDF_R = 8;
21
+ const KDF_P = 1;
22
+ const KEY_LENGTH = 32;
23
+ function deriveKey(passphrase, salt, N = KDF_N, r = KDF_R, p = KDF_P) {
24
+ return scryptSync(passphrase, salt, KEY_LENGTH, { N, r, p, maxmem: 128 * 1024 * 1024 });
25
+ }
26
+ function encryptPayload(payload, key) {
27
+ const iv = randomBytes(12);
28
+ const cipher = createCipheriv("aes-256-gcm", key, iv);
29
+ const data = Buffer.concat([cipher.update(JSON.stringify(payload), "utf-8"), cipher.final()]);
30
+ const tag = cipher.getAuthTag();
31
+ return { iv, tag, data };
32
+ }
33
+ function decryptPayload(file, key) {
34
+ const decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(file.iv, "base64"));
35
+ decipher.setAuthTag(Buffer.from(file.tag, "base64"));
36
+ const plain = Buffer.concat([
37
+ decipher.update(Buffer.from(file.data, "base64")),
38
+ decipher.final(), // throws on wrong passphrase (auth failure)
39
+ ]);
40
+ return JSON.parse(plain.toString("utf-8"));
41
+ }
42
+ /** Reference syntax in user prompts: @vault:<name>. */
43
+ export const VAULT_REF_PATTERN = /@vault:([A-Za-z0-9_.-]+)/g;
44
+ /**
45
+ * Expand @vault:<name> references in a prompt. The returned text is what the
46
+ * LLM receives; the ORIGINAL input (redacted) is what gets persisted.
47
+ */
48
+ export function expandVaultRefs(text, vault) {
49
+ const expanded = [];
50
+ const missing = [];
51
+ if (!vault) {
52
+ for (const match of text.matchAll(VAULT_REF_PATTERN)) {
53
+ missing.push(match[1]);
54
+ }
55
+ return { text, expanded, missing };
56
+ }
57
+ const out = text.replace(VAULT_REF_PATTERN, (_full, name) => {
58
+ const value = vault.getSecret(name);
59
+ if (value !== null) {
60
+ expanded.push(name);
61
+ return value;
62
+ }
63
+ missing.push(name);
64
+ return _full; // leave the reference intact so the user sees it failed
65
+ });
66
+ return { text: out, expanded, missing };
67
+ }
68
+ export class SessionVault {
69
+ entries = new Map();
70
+ add(name, value) {
71
+ this.entries.set(name, value);
72
+ }
73
+ get(name) {
74
+ return this.entries.get(name) ?? null;
75
+ }
76
+ remove(name) {
77
+ return this.entries.delete(name);
78
+ }
79
+ has(name) {
80
+ return this.entries.has(name);
81
+ }
82
+ list() {
83
+ return [...this.entries.keys()].sort();
84
+ }
85
+ clear() {
86
+ this.entries.clear();
87
+ }
88
+ }
89
+ export class ProjectVault {
90
+ secrets;
91
+ key;
92
+ constructor(key, secrets) {
93
+ this.key = key;
94
+ this.secrets = secrets;
95
+ }
96
+ /** Create a new empty project vault (writes the encrypted file). */
97
+ static async create(filePath, passphrase) {
98
+ const salt = randomBytes(16);
99
+ const key = deriveKey(passphrase, salt);
100
+ const vault = new ProjectVault(key, new Map());
101
+ await vault.save(filePath, salt);
102
+ return vault;
103
+ }
104
+ /** Open an existing vault. Throws on wrong passphrase. */
105
+ static async open(filePath, passphrase) {
106
+ const raw = await readFile(filePath, "utf-8");
107
+ const file = JSON.parse(raw);
108
+ const key = deriveKey(passphrase, Buffer.from(file.salt, "base64"), file.N, file.r, file.p);
109
+ const secrets = decryptPayload(file, key);
110
+ return new ProjectVault(key, new Map(secrets.map((s) => [s.name, s])));
111
+ }
112
+ add(name, value, note) {
113
+ const now = new Date().toISOString();
114
+ this.secrets.set(name, { name, value, note, created: now, updated: now });
115
+ }
116
+ update(name, value, note) {
117
+ const existing = this.secrets.get(name);
118
+ if (!existing)
119
+ return false;
120
+ const now = new Date().toISOString();
121
+ this.secrets.set(name, {
122
+ ...existing,
123
+ value,
124
+ note: note ?? existing.note,
125
+ updated: now,
126
+ });
127
+ return true;
128
+ }
129
+ get(name) {
130
+ return this.secrets.get(name)?.value ?? null;
131
+ }
132
+ remove(name) {
133
+ return this.secrets.delete(name);
134
+ }
135
+ has(name) {
136
+ return this.secrets.has(name);
137
+ }
138
+ list() {
139
+ return [...this.secrets.values()]
140
+ .map((s) => ({
141
+ name: s.name,
142
+ note: s.note,
143
+ created: s.created,
144
+ updated: s.updated,
145
+ source: "project",
146
+ }))
147
+ .sort((a, b) => a.name.localeCompare(b.name));
148
+ }
149
+ get entryCount() {
150
+ return this.secrets.size;
151
+ }
152
+ async save(filePath, salt) {
153
+ const { iv, tag, data } = encryptPayload([...this.secrets.values()], this.key);
154
+ const payload = {
155
+ version: 1,
156
+ kdf: "scrypt",
157
+ N: KDF_N,
158
+ r: KDF_R,
159
+ p: KDF_P,
160
+ salt: (salt ?? randomBytes(16)).toString("base64"),
161
+ iv: iv.toString("base64"),
162
+ tag: tag.toString("base64"),
163
+ data: data.toString("base64"),
164
+ };
165
+ await mkdir(dirname(filePath), { recursive: true });
166
+ await writeFile(filePath, JSON.stringify(payload, null, 1), "utf-8");
167
+ }
168
+ }
169
+ export class VaultManager {
170
+ projectVault = null;
171
+ sessionVault = new SessionVault();
172
+ vaultDir;
173
+ projectHash;
174
+ constructor(agentDir, projectHash) {
175
+ this.vaultDir = join(agentDir, "vault");
176
+ this.projectHash = projectHash ?? "global";
177
+ }
178
+ get vaultPath() {
179
+ return join(this.vaultDir, this.projectHash, "vault.json");
180
+ }
181
+ get isUnlocked() {
182
+ return this.projectVault !== null;
183
+ }
184
+ /** True when a project vault file already exists. */
185
+ exists() {
186
+ return existsSync(this.vaultPath);
187
+ }
188
+ /**
189
+ * Unlock (or create) the project vault with the user passphrase.
190
+ * Returns false on wrong passphrase.
191
+ */
192
+ async unlock(passphrase) {
193
+ try {
194
+ if (this.exists()) {
195
+ this.projectVault = await ProjectVault.open(this.vaultPath, passphrase);
196
+ }
197
+ else {
198
+ this.projectVault = await ProjectVault.create(this.vaultPath, passphrase);
199
+ }
200
+ return true;
201
+ }
202
+ catch {
203
+ this.projectVault = null;
204
+ return false;
205
+ }
206
+ }
207
+ lock() {
208
+ this.projectVault = null;
209
+ }
210
+ // ─── Project vault operations (require unlock) ───
211
+ add(name, value, note) {
212
+ if (!this.projectVault || !name.trim() || !value)
213
+ return false;
214
+ this.projectVault.add(name.trim(), value, note);
215
+ void this.projectVault.save(this.vaultPath).catch(() => { });
216
+ return true;
217
+ }
218
+ update(name, value, note) {
219
+ if (!this.projectVault)
220
+ return false;
221
+ const ok = this.projectVault.update(name, value, note);
222
+ if (ok)
223
+ void this.projectVault.save(this.vaultPath).catch(() => { });
224
+ return ok;
225
+ }
226
+ remove(name) {
227
+ if (!this.projectVault)
228
+ return false;
229
+ const ok = this.projectVault.remove(name);
230
+ if (ok)
231
+ void this.projectVault.save(this.vaultPath).catch(() => { });
232
+ return ok;
233
+ }
234
+ // ─── Lookup (project first, then session) ───
235
+ getSecret(name) {
236
+ const fromProject = this.projectVault?.get(name) ?? null;
237
+ if (fromProject !== null)
238
+ return fromProject;
239
+ return this.sessionVault.get(name);
240
+ }
241
+ // ─── Session vault (memory only) ───
242
+ sessionAdd(name, value) {
243
+ this.sessionVault.add(name, value);
244
+ }
245
+ sessionRemove(name) {
246
+ return this.sessionVault.remove(name);
247
+ }
248
+ // ─── Listing ───
249
+ list() {
250
+ const entries = [];
251
+ if (this.projectVault)
252
+ entries.push(...this.projectVault.list());
253
+ for (const name of this.sessionVault.list()) {
254
+ entries.push({
255
+ name,
256
+ created: "",
257
+ updated: "",
258
+ source: "session",
259
+ });
260
+ }
261
+ return entries.sort((a, b) => a.name.localeCompare(b.name));
262
+ }
263
+ status() {
264
+ return {
265
+ unlocked: this.isUnlocked,
266
+ vaultPath: this.vaultPath,
267
+ exists: this.exists(),
268
+ projectCount: this.projectVault?.entryCount ?? 0,
269
+ sessionCount: this.sessionVault.list().length,
270
+ };
271
+ }
272
+ }
273
+ export { existsSync };
274
+ //# sourceMappingURL=vault.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault.js","sourceRoot":"","sources":["../../../src/core/memory-engine/vault.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAkB1C,MAAM,KAAK,GAAG,KAAK,CAAC;AACpB,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,UAAU,GAAG,EAAE,CAAC;AActB,SAAS,SAAS,CAAC,UAAkB,EAAE,IAAY,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAAU;IAC7F,OAAO,UAAU,CAAC,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC;AAAA,CACxF;AAED,SAAS,cAAc,CAAC,OAAsB,EAAE,GAAW,EAA6C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,EAAE,SAAS;aACjB,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAAA,CAC5D;IAED,MAAM,GAMJ;QACD,OAAO;YACN,QAAQ,EAAE,IAAI,CAAC,UAAU;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;YACrB,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,IAAI,CAAC;YAChD,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM;SAC7C,CAAC;IAAA,CACF;CACD;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["/**\n * Ada Secure Vault — encrypted secret storage.\n *\n * - Project vault: AES-256-GCM encrypted at rest under\n * <agentDir>/vault/<project-hash>/vault.json; the key is derived from the\n * user passphrase with scrypt (never stored).\n * - Session vault: per-conversation secrets kept ONLY in process memory\n * (never written to disk).\n * - Values are exposed to the LLM only through @vault:<name> expansion in\n * the user's prompt, and the persisted session file stores the redacted\n * form (the expansion is stripped before persistence).\n *\n * Zero native dependencies: node:crypto works on Node and Bun.\n */\n\nimport { createCipheriv, createDecipheriv, randomBytes, scryptSync } from \"node:crypto\";\nimport { readFile, writeFile, mkdir } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\nexport interface VaultSecret {\n\tname: string;\n\tvalue: string;\n\tnote?: string;\n\tcreated: string;\n\tupdated: string;\n}\n\nexport interface VaultListEntry {\n\tname: string;\n\tnote?: string;\n\tcreated: string;\n\tupdated: string;\n\tsource: \"project\" | \"session\";\n}\n\nconst KDF_N = 32768;\nconst KDF_R = 8;\nconst KDF_P = 1;\nconst KEY_LENGTH = 32;\n\ninterface VaultFilePayload {\n\tversion: 1;\n\tkdf: \"scrypt\";\n\tN: number;\n\tr: number;\n\tp: number;\n\tsalt: string; // base64\n\tiv: string; // base64\n\ttag: string; // base64 (GCM auth tag)\n\tdata: string; // base64 (AES-256-GCM ciphertext of the JSON entries)\n}\n\nfunction deriveKey(passphrase: string, salt: Buffer, N = KDF_N, r = KDF_R, p = KDF_P): Buffer {\n\treturn scryptSync(passphrase, salt, KEY_LENGTH, { N, r, p, maxmem: 128 * 1024 * 1024 });\n}\n\nfunction encryptPayload(payload: VaultSecret[], key: Buffer): { iv: Buffer; tag: Buffer; data: Buffer } {\n\tconst iv = randomBytes(12);\n\tconst cipher = createCipheriv(\"aes-256-gcm\", key, iv);\n\tconst data = Buffer.concat([cipher.update(JSON.stringify(payload), \"utf-8\"), cipher.final()]);\n\tconst tag = cipher.getAuthTag();\n\treturn { iv, tag, data };\n}\n\nfunction decryptPayload(file: VaultFilePayload, key: Buffer): VaultSecret[] {\n\tconst decipher = createDecipheriv(\"aes-256-gcm\", key, Buffer.from(file.iv, \"base64\"));\n\tdecipher.setAuthTag(Buffer.from(file.tag, \"base64\"));\n\tconst plain = Buffer.concat([\n\t\tdecipher.update(Buffer.from(file.data, \"base64\")),\n\t\tdecipher.final(), // throws on wrong passphrase (auth failure)\n\t]);\n\treturn JSON.parse(plain.toString(\"utf-8\")) as VaultSecret[];\n}\n\n/** Reference syntax in user prompts: @vault:<name>. */\nexport const VAULT_REF_PATTERN = /@vault:([A-Za-z0-9_.-]+)/g;\n\nexport interface VaultExpansion {\n\ttext: string;\n\t/** Names that were expanded (empty when none). */\n\texpanded: string[];\n\t/** Names referenced but missing (not expanded). */\n\tmissing: string[];\n}\n\n/**\n * Expand @vault:<name> references in a prompt. The returned text is what the\n * LLM receives; the ORIGINAL input (redacted) is what gets persisted.\n */\nexport function expandVaultRefs(text: string, vault: VaultManager | null): VaultExpansion {\n\tconst expanded: string[] = [];\n\tconst missing: string[] = [];\n\tif (!vault) {\n\t\tfor (const match of text.matchAll(VAULT_REF_PATTERN)) {\n\t\t\tmissing.push(match[1]);\n\t\t}\n\t\treturn { text, expanded, missing };\n\t}\n\tconst out = text.replace(VAULT_REF_PATTERN, (_full, name: string) => {\n\t\tconst value = vault.getSecret(name);\n\t\tif (value !== null) {\n\t\t\texpanded.push(name);\n\t\t\treturn value;\n\t\t}\n\t\tmissing.push(name);\n\t\treturn _full; // leave the reference intact so the user sees it failed\n\t});\n\treturn { text: out, expanded, missing };\n}\n\nexport class SessionVault {\n\tprivate entries = new Map<string, string>();\n\n\tadd(name: string, value: string): void {\n\t\tthis.entries.set(name, value);\n\t}\n\n\tget(name: string): string | null {\n\t\treturn this.entries.get(name) ?? null;\n\t}\n\n\tremove(name: string): boolean {\n\t\treturn this.entries.delete(name);\n\t}\n\n\thas(name: string): boolean {\n\t\treturn this.entries.has(name);\n\t}\n\n\tlist(): string[] {\n\t\treturn [...this.entries.keys()].sort();\n\t}\n\n\tclear(): void {\n\t\tthis.entries.clear();\n\t}\n}\n\nexport class ProjectVault {\n\tprivate secrets: Map<string, VaultSecret>;\n\tprivate key: Buffer;\n\n\tprivate constructor(key: Buffer, secrets: Map<string, VaultSecret>) {\n\t\tthis.key = key;\n\t\tthis.secrets = secrets;\n\t}\n\n\t/** Create a new empty project vault (writes the encrypted file). */\n\tstatic async create(filePath: string, passphrase: string): Promise<ProjectVault> {\n\t\tconst salt = randomBytes(16);\n\t\tconst key = deriveKey(passphrase, salt);\n\t\tconst vault = new ProjectVault(key, new Map());\n\t\tawait vault.save(filePath, salt);\n\t\treturn vault;\n\t}\n\n\t/** Open an existing vault. Throws on wrong passphrase. */\n\tstatic async open(filePath: string, passphrase: string): Promise<ProjectVault> {\n\t\tconst raw = await readFile(filePath, \"utf-8\");\n\t\tconst file = JSON.parse(raw) as VaultFilePayload;\n\t\tconst key = deriveKey(passphrase, Buffer.from(file.salt, \"base64\"), file.N, file.r, file.p);\n\t\tconst secrets = decryptPayload(file, key);\n\t\treturn new ProjectVault(\n\t\t\tkey,\n\t\t\tnew Map(secrets.map((s) => [s.name, s])),\n\t\t);\n\t}\n\n\tadd(name: string, value: string, note?: string): void {\n\t\tconst now = new Date().toISOString();\n\t\tthis.secrets.set(name, { name, value, note, created: now, updated: now });\n\t}\n\n\tupdate(name: string, value: string, note?: string): boolean {\n\t\tconst existing = this.secrets.get(name);\n\t\tif (!existing) return false;\n\t\tconst now = new Date().toISOString();\n\t\tthis.secrets.set(name, {\n\t\t\t...existing,\n\t\t\tvalue,\n\t\t\tnote: note ?? existing.note,\n\t\t\tupdated: now,\n\t\t});\n\t\treturn true;\n\t}\n\n\tget(name: string): string | null {\n\t\treturn this.secrets.get(name)?.value ?? null;\n\t}\n\n\tremove(name: string): boolean {\n\t\treturn this.secrets.delete(name);\n\t}\n\n\thas(name: string): boolean {\n\t\treturn this.secrets.has(name);\n\t}\n\n\tlist(): VaultListEntry[] {\n\t\treturn [...this.secrets.values()]\n\t\t\t.map((s) => ({\n\t\t\t\tname: s.name,\n\t\t\t\tnote: s.note,\n\t\t\t\tcreated: s.created,\n\t\t\t\tupdated: s.updated,\n\t\t\t\tsource: \"project\" as const,\n\t\t\t}))\n\t\t\t.sort((a, b) => a.name.localeCompare(b.name));\n\t}\n\n\tget entryCount(): number {\n\t\treturn this.secrets.size;\n\t}\n\n\tasync save(filePath: string, salt?: Buffer): Promise<void> {\n\t\tconst { iv, tag, data } = encryptPayload([...this.secrets.values()], this.key);\n\t\tconst payload: VaultFilePayload = {\n\t\t\tversion: 1,\n\t\t\tkdf: \"scrypt\",\n\t\t\tN: KDF_N,\n\t\t\tr: KDF_R,\n\t\t\tp: KDF_P,\n\t\t\tsalt: (salt ?? randomBytes(16)).toString(\"base64\"),\n\t\t\tiv: iv.toString(\"base64\"),\n\t\t\ttag: tag.toString(\"base64\"),\n\t\t\tdata: data.toString(\"base64\"),\n\t\t};\n\t\tawait mkdir(dirname(filePath), { recursive: true });\n\t\tawait writeFile(filePath, JSON.stringify(payload, null, 1), \"utf-8\");\n\t}\n}\n\nexport class VaultManager {\n\tprivate projectVault: ProjectVault | null = null;\n\treadonly sessionVault = new SessionVault();\n\tprivate vaultDir: string;\n\tprivate projectHash: string;\n\n\tconstructor(agentDir: string, projectHash: string | null) {\n\t\tthis.vaultDir = join(agentDir, \"vault\");\n\t\tthis.projectHash = projectHash ?? \"global\";\n\t}\n\n\tget vaultPath(): string {\n\t\treturn join(this.vaultDir, this.projectHash, \"vault.json\");\n\t}\n\n\tget isUnlocked(): boolean {\n\t\treturn this.projectVault !== null;\n\t}\n\n\t/** True when a project vault file already exists. */\n\texists(): boolean {\n\t\treturn existsSync(this.vaultPath);\n\t}\n\n\t/**\n\t * Unlock (or create) the project vault with the user passphrase.\n\t * Returns false on wrong passphrase.\n\t */\n\tasync unlock(passphrase: string): Promise<boolean> {\n\t\ttry {\n\t\t\tif (this.exists()) {\n\t\t\t\tthis.projectVault = await ProjectVault.open(this.vaultPath, passphrase);\n\t\t\t} else {\n\t\t\t\tthis.projectVault = await ProjectVault.create(this.vaultPath, passphrase);\n\t\t\t}\n\t\t\treturn true;\n\t\t} catch {\n\t\t\tthis.projectVault = null;\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tlock(): void {\n\t\tthis.projectVault = null;\n\t}\n\n\t// ─── Project vault operations (require unlock) ───\n\n\tadd(name: string, value: string, note?: string): boolean {\n\t\tif (!this.projectVault || !name.trim() || !value) return false;\n\t\tthis.projectVault.add(name.trim(), value, note);\n\t\tvoid this.projectVault.save(this.vaultPath).catch(() => {});\n\t\treturn true;\n\t}\n\n\tupdate(name: string, value: string, note?: string): boolean {\n\t\tif (!this.projectVault) return false;\n\t\tconst ok = this.projectVault.update(name, value, note);\n\t\tif (ok) void this.projectVault.save(this.vaultPath).catch(() => {});\n\t\treturn ok;\n\t}\n\n\tremove(name: string): boolean {\n\t\tif (!this.projectVault) return false;\n\t\tconst ok = this.projectVault.remove(name);\n\t\tif (ok) void this.projectVault.save(this.vaultPath).catch(() => {});\n\t\treturn ok;\n\t}\n\n\t// ─── Lookup (project first, then session) ───\n\n\tgetSecret(name: string): string | null {\n\t\tconst fromProject = this.projectVault?.get(name) ?? null;\n\t\tif (fromProject !== null) return fromProject;\n\t\treturn this.sessionVault.get(name);\n\t}\n\n\t// ─── Session vault (memory only) ───\n\n\tsessionAdd(name: string, value: string): void {\n\t\tthis.sessionVault.add(name, value);\n\t}\n\n\tsessionRemove(name: string): boolean {\n\t\treturn this.sessionVault.remove(name);\n\t}\n\n\t// ─── Listing ───\n\n\tlist(): VaultListEntry[] {\n\t\tconst entries: VaultListEntry[] = [];\n\t\tif (this.projectVault) entries.push(...this.projectVault.list());\n\t\tfor (const name of this.sessionVault.list()) {\n\t\t\tentries.push({\n\t\t\t\tname,\n\t\t\t\tcreated: \"\",\n\t\t\t\tupdated: \"\",\n\t\t\t\tsource: \"session\",\n\t\t\t});\n\t\t}\n\t\treturn entries.sort((a, b) => a.name.localeCompare(b.name));\n\t}\n\n\tstatus(): {\n\t\tunlocked: boolean;\n\t\tvaultPath: string;\n\t\texists: boolean;\n\t\tprojectCount: number;\n\t\tsessionCount: number;\n\t} {\n\t\treturn {\n\t\t\tunlocked: this.isUnlocked,\n\t\t\tvaultPath: this.vaultPath,\n\t\t\texists: this.exists(),\n\t\t\tprojectCount: this.projectVault?.entryCount ?? 0,\n\t\t\tsessionCount: this.sessionVault.list().length,\n\t\t};\n\t}\n}\n\nexport { existsSync };\n"]}
@@ -50,6 +50,7 @@ export interface ResourceLoader {
50
50
  };
51
51
  getSystemPrompt(): string | undefined;
52
52
  getMemoryEngine(): import("./memory-engine/engine.ts").MemoryEngine | null;
53
+ getVaultManager(): import("./memory-engine/vault.ts").VaultManager | null;
53
54
  getSystemPromptSource(): {
54
55
  path: string;
55
56
  } | undefined;
@@ -141,6 +142,7 @@ export declare class DefaultResourceLoader implements ResourceLoader {
141
142
  private noThemes;
142
143
  private noContextFiles;
143
144
  private memoryEngine;
145
+ private vaultManager;
144
146
  private systemPromptSource?;
145
147
  private appendSystemPromptSource?;
146
148
  private extensionsOverride?;
@@ -191,6 +193,7 @@ export declare class DefaultResourceLoader implements ResourceLoader {
191
193
  }>;
192
194
  };
193
195
  getMemoryEngine(): import("./memory-engine/engine.ts").MemoryEngine | null;
196
+ getVaultManager(): import("./memory-engine/vault.ts").VaultManager | null;
194
197
  getSystemPrompt(): string | undefined;
195
198
  getSystemPromptSource(): {
196
199
  path: string;
@@ -1 +1 @@
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;AAO/D,OAAO,KAAK,EAA+B,eAAe,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAEhH,OAAO,EAAyB,KAAK,YAAY,EAAyB,MAAM,sBAAsB,CAAC;AAGvG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAKzC,MAAM,WAAW,sBAAsB;IACtC,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,YAAY,CAAA;KAAE,CAAC,CAAC;IAC7D,WAAW,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,YAAY,CAAA;KAAE,CAAC,CAAC;IAC9D,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,YAA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B7B,OAAO,CAAC,sBAAsB;IAwB9B,OAAO,CAAC,qBAAqB;IAsB7B,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;IAwBpC,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 { basename, dirname, join, resolve, sep } from \"node:path\";\nimport chalk from \"chalk\";\nimport { CONFIG_DIR_NAME } 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\tclearExtensionCache,\n\tcreateExtensionRuntime,\n\tloadExtensionFromFactory,\n\tloadExtensionsCached,\n} from \"./extensions/loader.ts\";\nimport type { Extension, ExtensionRuntime, InlineExtension, LoadExtensionsResult } from \"./extensions/types.ts\";\nimport { findGitPaths } from \"./footer-data-provider.ts\";\nimport { DefaultPackageManager, type PathMetadata, type ResolvedResource } from \"./package-manager.ts\";\nimport { loadProjectMemorySync } from \"./project-memory.ts\";\nimport { MemoryEngine } from \"./memory-engine/engine.ts\";\nimport type { PromptTemplate } from \"./prompt-templates.ts\";\nimport { loadPromptTemplates } from \"./prompt-templates.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport type { Skill } from \"./skills.ts\";\nimport { loadSkills } from \"./skills.ts\";\nimport { createSourceInfo, type SourceInfo } from \"./source-info.ts\";\nimport { resetTimings } from \"./timings.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 ResourceLoaderReloadOptions {\n\tresolveProjectTrust?: (input: { extensionsResult: LoadExtensionsResult }) => Promise<boolean>;\n}\n\nexport interface ResourceLoader {\n\tgetCwd(): string;\n\tgetAgentDir(): string;\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\tgetMemoryEngine(): import(\"./memory-engine/engine.ts\").MemoryEngine | null;\n\tgetSystemPromptSource(): { path: string } | undefined;\n\tgetAppendSystemPrompt(): string[];\n\tgetAppendSystemPromptSources(): Array<{ path: string }>;\n\textendResources(paths: ResourceExtensionPaths): void;\n\treload(options?: ResourceLoaderReloadOptions): Promise<void>;\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\nfunction loadContextFileFromDir(dir: string): { path: string; content: string } | null {\n\tconst candidates = [\"AGENTS.override.md\", \"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\"];\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\tif (!statSync(filePath).isFile()) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tpath: filePath,\n\t\t\t\t\tcontent: readFileSync(filePath, \"utf-8\"),\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 null;\n}\n\n/**\n * The main repo's context file that a nested linked worktree's own copy shadows: both\n * occupy the same logical repository scope, so loading both applies that context twice. Returns\n * undefined when nothing is shadowed, leaving normal ancestor inheritance alone.\n *\n * Returned canonicalized (realpath), because `git worktree add` writes the `.git`\n * file's `gitdir:` target in realpath form while cwd may still be symlinked\n * (macOS `/tmp` -> `/private/tmp`).\n */\nfunction findShadowedContextFile(cwd: string): string | undefined {\n\tconst gitPaths = findGitPaths(cwd);\n\tif (!gitPaths) return undefined;\n\tconst commonGitDir = canonicalizePath(gitPaths.commonGitDir);\n\tconst worktreeRoot = canonicalizePath(gitPaths.repoDir);\n\tconst mainRepoRoot = dirname(commonGitDir);\n\t// False for an ordinary repo, where the two are the same dir, and for a sibling\n\t// worktree (`git worktree add ../feat`), whose main repo is not an ancestor.\n\tif (!worktreeRoot.startsWith(`${mainRepoRoot}${sep}`)) return undefined;\n\t// dirname of the common git dir is the main worktree root only when that dir is\n\t// itself checked out from the same repo. In a bare layout (`proj/.bare` +\n\t// `proj/main`) it is just the directory holding `.bare`, which tracks nothing; a\n\t// submodule's gitdir has no `commondir`, so it lands under `.git/modules`.\n\tif (canonicalizePath(join(mainRepoRoot, \".git\")) !== commonGitDir) return undefined;\n\tconst worktreeContextFile = loadContextFileFromDir(worktreeRoot);\n\treturn worktreeContextFile ? join(mainRepoRoot, basename(worktreeContextFile.path)) : undefined;\n}\n\nexport function loadProjectContextFiles(options: {\n\tcwd: string;\n\tagentDir: string;\n\tprojectMemoryEnabled?: boolean;\n\tmemoryEngine?: import(\"./memory-engine/engine.ts\").MemoryEngine | null;\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\tconst globalContext = loadContextFileFromDir(resolvedAgentDir);\n\tif (globalContext) {\n\t\tcontextFiles.push(globalContext);\n\t\tseenPaths.add(globalContext.path);\n\t}\n\n\tconst ancestorContextFiles: Array<{ path: string; content: string }> = [];\n\n\tconst shadowedContextFile = findShadowedContextFile(resolvedCwd);\n\tlet currentDir = resolvedCwd;\n\n\twhile (true) {\n\t\tconst contextFile = loadContextFileFromDir(currentDir);\n\t\tconst isShadowed =\n\t\t\tshadowedContextFile !== undefined && canonicalizePath(contextFile?.path ?? \"\") === shadowedContextFile;\n\t\tif (contextFile && !isShadowed && !seenPaths.has(contextFile.path)) {\n\t\t\tancestorContextFiles.unshift(contextFile);\n\t\t\tseenPaths.add(contextFile.path);\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) break;\n\t\tcurrentDir = parentDir;\n\t}\n\n\tcontextFiles.push(...ancestorContextFiles);\n\n\t// Shared project memory: the Ada Memory Engine block (policy or inject\n\t// mode). Falls back to the legacy project-memory file when the engine is\n\t// unavailable or disabled. Included last so it reads as the freshest\n\t// project context.\n\tconst memoryBlock = options.memoryEngine?.getPromptBlockSync() ?? \"\";\n\tif (memoryBlock) {\n\t\tcontextFiles.push({ path: \"<ada-memory>\", content: memoryBlock });\n\t} else {\n\t\tconst memoryFile = (options.projectMemoryEnabled ?? true)\n\t\t\t? loadProjectMemorySync(resolvedCwd, resolvedAgentDir)\n\t\t\t: null;\n\t\tif (memoryFile) {\n\t\t\tcontextFiles.push(memoryFile);\n\t\t}\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?: InlineExtension[];\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\n\tgetCwd(): string {\n\t\treturn this.cwd;\n\t}\n\n\tgetAgentDir(): string {\n\t\treturn this.agentDir;\n\t}\n\tprivate eventBus: EventBus;\n\tprivate packageManager: DefaultPackageManager;\tprivate additionalExtensionPaths: string[];\n\tprivate additionalSkillPaths: string[];\n\tprivate additionalPromptTemplatePaths: string[];\n\tprivate additionalThemePaths: string[];\n\tprivate extensionFactories: InlineExtension[];\n\tprivate noExtensions: boolean;\n\tprivate noSkills: boolean;\n\tprivate noPromptTemplates: boolean;\n\tprivate noThemes: boolean;\n\tprivate noContextFiles: boolean;\n\tprivate memoryEngine: import(\"./memory-engine/engine.ts\").MemoryEngine | null = null;\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 systemPromptSourcePath?: string;\n\tprivate appendSystemPrompt: string[];\n\tprivate appendSystemPromptSourcePaths: 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 resourceMetadataByPath: Map<string, PathMetadata>;\n\tprivate lastPromptPaths: string[];\n\tprivate lastThemePaths: string[];\n\tprivate loaded: boolean;\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\t// Ada Memory Engine — shared across CLI and desktop; lazy-initialized.\n\t\tthis.memoryEngine = new MemoryEngine({\n\t\t\tagentDir: this.agentDir,\n\t\t\tcwd: this.cwd,\n\t\t\tgetConfig: () => this.settingsManager.getMemoryEngineConfig(),\n\t\t});\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.extensionFactories = options.extensionFactories ?? [];\n\t\tthis.noExtensions = options.noExtensions ?? false;\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.appendSystemPromptSourcePaths = [];\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.resourceMetadataByPath = new Map();\n\t\tthis.lastPromptPaths = [];\n\t\tthis.lastThemePaths = [];\n\t\tthis.loaded = false;\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\tgetMemoryEngine(): import(\"./memory-engine/engine.ts\").MemoryEngine | null {\n\t\treturn this.memoryEngine;\n\t}\n\n\tgetSystemPrompt(): string | undefined {\n\t\treturn this.systemPrompt;\n\t}\n\n\tgetSystemPromptSource(): { path: string } | undefined {\n\t\treturn this.systemPromptSourcePath ? { path: this.systemPromptSourcePath } : undefined;\n\t}\n\n\tgetAppendSystemPrompt(): string[] {\n\t\treturn this.appendSystemPrompt;\n\t}\n\n\tgetAppendSystemPromptSources(): Array<{ path: string }> {\n\t\treturn this.appendSystemPromptSourcePaths.map((path) => ({ path }));\n\t}\n\n\textendResources(paths: ResourceExtensionPaths): void {\n\t\tconst skillPaths = this.normalizeExtensionPaths(paths.skillPaths ?? []);\n\t\tconst promptPaths = this.normalizeExtensionPaths(paths.promptPaths ?? []);\n\t\tconst themePaths = this.normalizeExtensionPaths(paths.themePaths ?? []);\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, this.resourceMetadataByPath);\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, this.resourceMetadataByPath);\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, this.resourceMetadataByPath);\n\t\t}\n\t}\n\n\tasync loadProjectTrustExtensions(): Promise<LoadExtensionsResult> {\n\t\t// Force untrusted project settings for the bootstrap pass. This keeps project-local\n\t\t// extensions/packages out while still loading user/global and temporary CLI extensions.\n\t\tthis.settingsManager.setProjectTrusted(false);\n\t\tawait this.settingsManager.reload();\n\t\treturn this.loadCurrentExtensionSet({ includeInlineFactories: true });\n\t}\n\n\tasync reload(options?: ResourceLoaderReloadOptions): Promise<void> {\n\t\tresetTimings(\"extensions\");\n\n\t\tif (this.loaded) {\n\t\t\tclearExtensionCache();\n\t\t}\n\n\t\tlet preTrustExtensions: LoadExtensionsResult | undefined;\n\t\tif (options?.resolveProjectTrust) {\n\t\t\tpreTrustExtensions = await this.loadProjectTrustExtensions();\n\t\t\tconst projectTrusted = await options.resolveProjectTrust({ extensionsResult: preTrustExtensions });\n\t\t\tthis.settingsManager.setProjectTrusted(projectTrusted);\n\t\t}\n\n\t\t// reload() preserves SettingsManager.projectTrusted and reloads settings for that trust state.\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// Kept on the instance so post-reload passes (extendResources) can still resolve package metadata.\n\t\tthis.resourceMetadataByPath = new Map();\n\t\tconst metadataByPath = this.resourceMetadataByPath;\n\n\t\tthis.extensionSkillSourceInfos = new Map();\n\t\tthis.extensionPromptSourceInfos = new Map();\n\t\tthis.extensionThemeSourceInfos = new Map();\n\n\t\t// Helper to extract enabled paths and store metadata\n\t\tconst getEnabledResources = (resources: ResolvedResource[]): ResolvedResource[] => {\n\t\t\tfor (const r of resources) {\n\t\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\t\tmetadataByPath.set(r.path, r.metadata);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn resources.filter((r) => r.enabled);\n\t\t};\n\n\t\tconst getEnabledPaths = (resources: ResolvedResource[]): string[] =>\n\t\t\tgetEnabledResources(resources).map((r) => r.path);\n\t\tconst enabledExtensions = getEnabledPaths(resolvedPaths.extensions);\n\t\tconst enabledSkillResources = getEnabledResources(resolvedPaths.skills);\n\t\tconst enabledPrompts = getEnabledPaths(resolvedPaths.prompts);\n\t\tconst enabledThemes = getEnabledPaths(resolvedPaths.themes);\n\n\t\tconst enabledSkills = enabledSkillResources.map((resource) => this.mapSkillPath(resource, metadataByPath));\n\n\t\t// Add CLI paths metadata\n\t\tfor (const r of cliExtensionPaths.extensions) {\n\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\tmetadataByPath.set(r.path, { source: \"cli\", scope: \"temporary\", origin: \"top-level\" });\n\t\t\t}\n\t\t}\n\t\tfor (const r of cliExtensionPaths.skills) {\n\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\tmetadataByPath.set(r.path, { source: \"cli\", scope: \"temporary\", origin: \"top-level\" });\n\t\t\t}\n\t\t}\n\n\t\tconst cliEnabledExtensions = getEnabledPaths(cliExtensionPaths.extensions);\n\t\tconst cliEnabledSkills = getEnabledPaths(cliExtensionPaths.skills);\n\t\tconst cliEnabledPrompts = getEnabledPaths(cliExtensionPaths.prompts);\n\t\tconst cliEnabledThemes = getEnabledPaths(cliExtensionPaths.themes);\n\n\t\tconst extensionPaths = this.noExtensions\n\t\t\t? cliEnabledExtensions\n\t\t\t: this.mergePaths(cliEnabledExtensions, enabledExtensions);\n\n\t\tconst extensionsResult = await this.loadFinalExtensionSet(extensionPaths, preTrustExtensions);\n\t\tfor (const p of this.additionalExtensionPaths) {\n\t\t\tif (isLocalPath(p)) {\n\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\tif (!existsSync(resolved)) {\n\t\t\t\t\textensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.extensionsResult = this.extensionsOverride ? this.extensionsOverride(extensionsResult) : extensionsResult;\n\t\tthis.applyExtensionSourceInfo(this.extensionsResult.extensions, metadataByPath);\n\n\t\tconst skillPaths = this.noSkills\n\t\t\t? this.mergePaths(cliEnabledSkills, this.additionalSkillPaths)\n\t\t\t: this.mergePaths([...cliEnabledSkills, ...enabledSkills], this.additionalSkillPaths);\n\n\t\tthis.lastSkillPaths = skillPaths;\n\t\tthis.updateSkillsFromPaths(skillPaths, metadataByPath);\n\t\tfor (const p of this.additionalSkillPaths) {\n\t\t\tif (isLocalPath(p)) {\n\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\tif (!existsSync(resolved) && !this.skillDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\tthis.skillDiagnostics.push({ type: \"error\", message: \"Skill path does not exist\", path: resolved });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst promptPaths = this.noPromptTemplates\n\t\t\t? this.mergePaths(cliEnabledPrompts, this.additionalPromptTemplatePaths)\n\t\t\t: this.mergePaths([...cliEnabledPrompts, ...enabledPrompts], this.additionalPromptTemplatePaths);\n\n\t\tthis.lastPromptPaths = promptPaths;\n\t\tthis.updatePromptsFromPaths(promptPaths, metadataByPath);\n\t\tfor (const p of this.additionalPromptTemplatePaths) {\n\t\t\tif (isLocalPath(p)) {\n\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\tif (!existsSync(resolved) && !this.promptDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\tthis.promptDiagnostics.push({\n\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\tmessage: \"Prompt template path does not exist\",\n\t\t\t\t\t\tpath: resolved,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst themePaths = this.noThemes\n\t\t\t? this.mergePaths(cliEnabledThemes, this.additionalThemePaths)\n\t\t\t: this.mergePaths([...cliEnabledThemes, ...enabledThemes], this.additionalThemePaths);\n\n\t\tthis.lastThemePaths = themePaths;\n\t\tthis.updateThemesFromPaths(themePaths, metadataByPath);\n\t\tfor (const p of this.additionalThemePaths) {\n\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\tif (!existsSync(resolved) && !this.themeDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\tthis.themeDiagnostics.push({ type: \"error\", message: \"Theme path does not exist\", path: resolved });\n\t\t\t}\n\t\t}\n\n\t\tconst agentsFiles = {\n\t\t\tagentsFiles: 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\tprojectMemoryEnabled: this.settingsManager.getProjectMemoryEnabled(),\n\t\t\t\t\t\tmemoryEngine: this.memoryEngine,\n\t\t\t\t\t}),\n\t\t};\n\t\tconst resolvedAgentsFiles = this.agentsFilesOverride ? this.agentsFilesOverride(agentsFiles) : agentsFiles;\n\t\tthis.agentsFiles = resolvedAgentsFiles.agentsFiles;\n\n\t\tconst systemPromptSource = this.systemPromptSource ?? this.discoverSystemPromptFile();\n\t\tconst baseSystemPrompt = resolvePromptInput(systemPromptSource, \"system prompt\");\n\t\tthis.systemPrompt = this.systemPromptOverride ? this.systemPromptOverride(baseSystemPrompt) : baseSystemPrompt;\n\t\tthis.systemPromptSourcePath =\n\t\t\tsystemPromptSource && existsSync(systemPromptSource) ? resolvePath(systemPromptSource) : undefined;\n\n\t\tlet appendSources = this.appendSystemPromptSource;\n\t\tif (!appendSources) {\n\t\t\tconst discoveredAppendSystemPromptFile = this.discoverAppendSystemPromptFile();\n\t\t\tappendSources = discoveredAppendSystemPromptFile ? [discoveredAppendSystemPromptFile] : [];\n\t\t}\n\t\tconst baseAppend = appendSources\n\t\t\t.map((s) => resolvePromptInput(s, \"append system prompt\"))\n\t\t\t.filter((s): s is string => s !== undefined);\n\t\tthis.appendSystemPrompt = this.appendSystemPromptOverride\n\t\t\t? this.appendSystemPromptOverride(baseAppend)\n\t\t\t: baseAppend;\n\t\tthis.appendSystemPromptSourcePaths = appendSources\n\t\t\t.filter((source) => existsSync(source))\n\t\t\t.map((source) => resolvePath(source));\n\t\tthis.loaded = true;\n\t}\n\n\tprivate async loadCurrentExtensionSet(options: { includeInlineFactories: boolean }): Promise<LoadExtensionsResult> {\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\tconst enabledExtensions = resolvedPaths.extensions.filter((r) => r.enabled).map((r) => r.path);\n\t\tconst cliEnabledExtensions = cliExtensionPaths.extensions.filter((r) => r.enabled).map((r) => r.path);\n\t\tconst extensionPaths = this.noExtensions\n\t\t\t? cliEnabledExtensions\n\t\t\t: this.mergePaths(cliEnabledExtensions, enabledExtensions);\n\t\tconst extensionsResult = await loadExtensionsCached(extensionPaths, this.cwd, this.eventBus);\n\t\tif (!options.includeInlineFactories) {\n\t\t\treturn extensionsResult;\n\t\t}\n\n\t\tconst inlineExtensions = await this.loadExtensionFactories(extensionsResult.runtime);\n\t\textensionsResult.extensions.push(...inlineExtensions.extensions);\n\t\textensionsResult.errors.push(...inlineExtensions.errors);\n\t\treturn extensionsResult;\n\t}\n\n\tprivate resolveExtensionLoadPath(path: string): string {\n\t\treturn resolvePath(path, this.cwd, { normalizeUnicodeSpaces: true });\n\t}\n\n\tprivate async loadFinalExtensionSet(\n\t\textensionPaths: string[],\n\t\tpreTrustExtensions: LoadExtensionsResult | undefined,\n\t): Promise<LoadExtensionsResult> {\n\t\tif (!preTrustExtensions) {\n\t\t\tconst extensionsResult = await loadExtensionsCached(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\t\t\tthis.addExtensionConflictDiagnostics(extensionsResult);\n\t\t\treturn extensionsResult;\n\t\t}\n\n\t\tconst preloadedByPath = new Map(\n\t\t\tpreTrustExtensions.extensions\n\t\t\t\t.filter((extension) => !extension.path.startsWith(\"<inline:\"))\n\t\t\t\t.map((extension) => [extension.resolvedPath, extension]),\n\t\t);\n\t\tconst failedPreloadPaths = new Set(\n\t\t\tpreTrustExtensions.errors.map((error) => this.resolveExtensionLoadPath(error.path)),\n\t\t);\n\t\tconst remainingPaths = extensionPaths.filter((path) => {\n\t\t\tconst resolvedPath = this.resolveExtensionLoadPath(path);\n\t\t\treturn !preloadedByPath.has(resolvedPath) && !failedPreloadPaths.has(resolvedPath);\n\t\t});\n\t\tconst remainingExtensions = await loadExtensionsCached(\n\t\t\tremainingPaths,\n\t\t\tthis.cwd,\n\t\t\tthis.eventBus,\n\t\t\tpreTrustExtensions.runtime,\n\t\t);\n\t\tconst loadedByPath = new Map(preloadedByPath);\n\t\tfor (const extension of remainingExtensions.extensions) {\n\t\t\tloadedByPath.set(extension.resolvedPath, extension);\n\t\t}\n\n\t\tconst inlineExtensions = preTrustExtensions.extensions.filter((extension) =>\n\t\t\textension.path.startsWith(\"<inline:\"),\n\t\t);\n\t\tconst orderedExtensions = extensionPaths\n\t\t\t.map((path) => loadedByPath.get(this.resolveExtensionLoadPath(path)))\n\t\t\t.filter((extension): extension is Extension => extension !== undefined);\n\t\torderedExtensions.push(...inlineExtensions);\n\n\t\tconst extensionsResult: LoadExtensionsResult = {\n\t\t\textensions: orderedExtensions,\n\t\t\terrors: [...preTrustExtensions.errors, ...remainingExtensions.errors],\n\t\t\truntime: preTrustExtensions.runtime,\n\t\t};\n\t\tthis.addExtensionConflictDiagnostics(extensionsResult);\n\t\treturn extensionsResult;\n\t}\n\n\tprivate addExtensionConflictDiagnostics(extensionsResult: LoadExtensionsResult): void {\n\t\t// Detect extension conflicts (tools, commands, flags with same names from different extensions)\n\t\t// Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.\n\t\tconst conflicts = this.detectExtensionConflicts(extensionsResult.extensions);\n\t\tfor (const conflict of conflicts) {\n\t\t\textensionsResult.errors.push({ path: conflict.path, error: conflict.message });\n\t\t}\n\t}\n\n\tprivate mapSkillPath(resource: ResolvedResource, metadataByPath: Map<string, PathMetadata>): string {\n\t\tif (resource.metadata.source !== \"auto\" && resource.metadata.origin !== \"package\") {\n\t\t\treturn resource.path;\n\t\t}\n\t\ttry {\n\t\t\tconst stats = statSync(resource.path);\n\t\t\tif (!stats.isDirectory()) {\n\t\t\t\treturn resource.path;\n\t\t\t}\n\t\t} catch {\n\t\t\treturn resource.path;\n\t\t}\n\t\tconst skillFile = join(resource.path, \"SKILL.md\");\n\t\tif (existsSync(skillFile)) {\n\t\t\tif (!metadataByPath.has(skillFile)) {\n\t\t\t\tmetadataByPath.set(skillFile, resource.metadata);\n\t\t\t}\n\t\t\treturn skillFile;\n\t\t}\n\t\treturn resource.path;\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, input] of this.extensionFactories.entries()) {\n\t\t\tconst isNamed = typeof input !== \"function\";\n\t\t\tconst factory = isNamed ? input.factory : input;\n\t\t\tconst extensionPath = `<inline:${isNamed ? input.name : 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\textension.hidden = isNamed && input.hidden;\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 conflic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chC,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;IAwBpC,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 { basename, dirname, join, resolve, sep } from \"node:path\";\nimport chalk from \"chalk\";\nimport { CONFIG_DIR_NAME } 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\tclearExtensionCache,\n\tcreateExtensionRuntime,\n\tloadExtensionFromFactory,\n\tloadExtensionsCached,\n} from \"./extensions/loader.ts\";\nimport type { Extension, ExtensionRuntime, InlineExtension, LoadExtensionsResult } from \"./extensions/types.ts\";\nimport { findGitPaths } from \"./footer-data-provider.ts\";\nimport { DefaultPackageManager, type PathMetadata, type ResolvedResource } from \"./package-manager.ts\";\nimport { loadProjectMemorySync } from \"./project-memory.ts\";\nimport { MemoryEngine } from \"./memory-engine/engine.ts\";\nimport { VaultManager } from \"./memory-engine/vault.ts\";\nimport type { PromptTemplate } from \"./prompt-templates.ts\";\nimport { loadPromptTemplates } from \"./prompt-templates.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport type { Skill } from \"./skills.ts\";\nimport { loadSkills } from \"./skills.ts\";\nimport { createSourceInfo, type SourceInfo } from \"./source-info.ts\";\nimport { resetTimings } from \"./timings.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 ResourceLoaderReloadOptions {\n\tresolveProjectTrust?: (input: { extensionsResult: LoadExtensionsResult }) => Promise<boolean>;\n}\n\nexport interface ResourceLoader {\n\tgetCwd(): string;\n\tgetAgentDir(): string;\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\tgetMemoryEngine(): import(\"./memory-engine/engine.ts\").MemoryEngine | null;\n\tgetVaultManager(): import(\"./memory-engine/vault.ts\").VaultManager | null;\n\tgetSystemPromptSource(): { path: string } | undefined;\n\tgetAppendSystemPrompt(): string[];\n\tgetAppendSystemPromptSources(): Array<{ path: string }>;\n\textendResources(paths: ResourceExtensionPaths): void;\n\treload(options?: ResourceLoaderReloadOptions): Promise<void>;\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\nfunction loadContextFileFromDir(dir: string): { path: string; content: string } | null {\n\tconst candidates = [\"AGENTS.override.md\", \"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\"];\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\tif (!statSync(filePath).isFile()) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tpath: filePath,\n\t\t\t\t\tcontent: readFileSync(filePath, \"utf-8\"),\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 null;\n}\n\n/**\n * The main repo's context file that a nested linked worktree's own copy shadows: both\n * occupy the same logical repository scope, so loading both applies that context twice. Returns\n * undefined when nothing is shadowed, leaving normal ancestor inheritance alone.\n *\n * Returned canonicalized (realpath), because `git worktree add` writes the `.git`\n * file's `gitdir:` target in realpath form while cwd may still be symlinked\n * (macOS `/tmp` -> `/private/tmp`).\n */\nfunction findShadowedContextFile(cwd: string): string | undefined {\n\tconst gitPaths = findGitPaths(cwd);\n\tif (!gitPaths) return undefined;\n\tconst commonGitDir = canonicalizePath(gitPaths.commonGitDir);\n\tconst worktreeRoot = canonicalizePath(gitPaths.repoDir);\n\tconst mainRepoRoot = dirname(commonGitDir);\n\t// False for an ordinary repo, where the two are the same dir, and for a sibling\n\t// worktree (`git worktree add ../feat`), whose main repo is not an ancestor.\n\tif (!worktreeRoot.startsWith(`${mainRepoRoot}${sep}`)) return undefined;\n\t// dirname of the common git dir is the main worktree root only when that dir is\n\t// itself checked out from the same repo. In a bare layout (`proj/.bare` +\n\t// `proj/main`) it is just the directory holding `.bare`, which tracks nothing; a\n\t// submodule's gitdir has no `commondir`, so it lands under `.git/modules`.\n\tif (canonicalizePath(join(mainRepoRoot, \".git\")) !== commonGitDir) return undefined;\n\tconst worktreeContextFile = loadContextFileFromDir(worktreeRoot);\n\treturn worktreeContextFile ? join(mainRepoRoot, basename(worktreeContextFile.path)) : undefined;\n}\n\nexport function loadProjectContextFiles(options: {\n\tcwd: string;\n\tagentDir: string;\n\tprojectMemoryEnabled?: boolean;\n\tmemoryEngine?: import(\"./memory-engine/engine.ts\").MemoryEngine | null;\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\tconst globalContext = loadContextFileFromDir(resolvedAgentDir);\n\tif (globalContext) {\n\t\tcontextFiles.push(globalContext);\n\t\tseenPaths.add(globalContext.path);\n\t}\n\n\tconst ancestorContextFiles: Array<{ path: string; content: string }> = [];\n\n\tconst shadowedContextFile = findShadowedContextFile(resolvedCwd);\n\tlet currentDir = resolvedCwd;\n\n\twhile (true) {\n\t\tconst contextFile = loadContextFileFromDir(currentDir);\n\t\tconst isShadowed =\n\t\t\tshadowedContextFile !== undefined && canonicalizePath(contextFile?.path ?? \"\") === shadowedContextFile;\n\t\tif (contextFile && !isShadowed && !seenPaths.has(contextFile.path)) {\n\t\t\tancestorContextFiles.unshift(contextFile);\n\t\t\tseenPaths.add(contextFile.path);\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) break;\n\t\tcurrentDir = parentDir;\n\t}\n\n\tcontextFiles.push(...ancestorContextFiles);\n\n\t// Shared project memory: the Ada Memory Engine block (policy or inject\n\t// mode). Falls back to the legacy project-memory file when the engine is\n\t// unavailable or disabled. Included last so it reads as the freshest\n\t// project context.\n\tconst memoryBlock = options.memoryEngine?.getPromptBlockSync() ?? \"\";\n\tif (memoryBlock) {\n\t\tcontextFiles.push({ path: \"<ada-memory>\", content: memoryBlock });\n\t} else {\n\t\tconst memoryFile = (options.projectMemoryEnabled ?? true)\n\t\t\t? loadProjectMemorySync(resolvedCwd, resolvedAgentDir)\n\t\t\t: null;\n\t\tif (memoryFile) {\n\t\t\tcontextFiles.push(memoryFile);\n\t\t}\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?: InlineExtension[];\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\n\tgetCwd(): string {\n\t\treturn this.cwd;\n\t}\n\n\tgetAgentDir(): string {\n\t\treturn this.agentDir;\n\t}\n\tprivate eventBus: EventBus;\n\tprivate packageManager: DefaultPackageManager;\tprivate additionalExtensionPaths: string[];\n\tprivate additionalSkillPaths: string[];\n\tprivate additionalPromptTemplatePaths: string[];\n\tprivate additionalThemePaths: string[];\n\tprivate extensionFactories: InlineExtension[];\n\tprivate noExtensions: boolean;\n\tprivate noSkills: boolean;\n\tprivate noPromptTemplates: boolean;\n\tprivate noThemes: boolean;\n\tprivate noContextFiles: boolean;\n\tprivate memoryEngine: import(\"./memory-engine/engine.ts\").MemoryEngine | null = null;\n\tprivate vaultManager: import(\"./memory-engine/vault.ts\").VaultManager | null = null;\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 systemPromptSourcePath?: string;\n\tprivate appendSystemPrompt: string[];\n\tprivate appendSystemPromptSourcePaths: 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 resourceMetadataByPath: Map<string, PathMetadata>;\n\tprivate lastPromptPaths: string[];\n\tprivate lastThemePaths: string[];\n\tprivate loaded: boolean;\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\t// Ada Memory Engine — shared across CLI and desktop; lazy-initialized.\n\t\tthis.memoryEngine = new MemoryEngine({\n\t\t\tagentDir: this.agentDir,\n\t\t\tcwd: this.cwd,\n\t\t\tgetConfig: () => this.settingsManager.getMemoryEngineConfig(),\n\t\t});\n\t\t// Ada Secure Vault — encrypted secrets (project + session scopes).\n\t\tthis.vaultManager = new VaultManager(this.agentDir, this.memoryEngine.projectHash);\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.extensionFactories = options.extensionFactories ?? [];\n\t\tthis.noExtensions = options.noExtensions ?? false;\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.appendSystemPromptSourcePaths = [];\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.resourceMetadataByPath = new Map();\n\t\tthis.lastPromptPaths = [];\n\t\tthis.lastThemePaths = [];\n\t\tthis.loaded = false;\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\tgetMemoryEngine(): import(\"./memory-engine/engine.ts\").MemoryEngine | null {\n\t\treturn this.memoryEngine;\n\t}\n\n\tgetVaultManager(): import(\"./memory-engine/vault.ts\").VaultManager | null {\n\t\treturn this.vaultManager;\n\t}\n\n\tgetSystemPrompt(): string | undefined {\n\t\treturn this.systemPrompt;\n\t}\n\n\tgetSystemPromptSource(): { path: string } | undefined {\n\t\treturn this.systemPromptSourcePath ? { path: this.systemPromptSourcePath } : undefined;\n\t}\n\n\tgetAppendSystemPrompt(): string[] {\n\t\treturn this.appendSystemPrompt;\n\t}\n\n\tgetAppendSystemPromptSources(): Array<{ path: string }> {\n\t\treturn this.appendSystemPromptSourcePaths.map((path) => ({ path }));\n\t}\n\n\textendResources(paths: ResourceExtensionPaths): void {\n\t\tconst skillPaths = this.normalizeExtensionPaths(paths.skillPaths ?? []);\n\t\tconst promptPaths = this.normalizeExtensionPaths(paths.promptPaths ?? []);\n\t\tconst themePaths = this.normalizeExtensionPaths(paths.themePaths ?? []);\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, this.resourceMetadataByPath);\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, this.resourceMetadataByPath);\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, this.resourceMetadataByPath);\n\t\t}\n\t}\n\n\tasync loadProjectTrustExtensions(): Promise<LoadExtensionsResult> {\n\t\t// Force untrusted project settings for the bootstrap pass. This keeps project-local\n\t\t// extensions/packages out while still loading user/global and temporary CLI extensions.\n\t\tthis.settingsManager.setProjectTrusted(false);\n\t\tawait this.settingsManager.reload();\n\t\treturn this.loadCurrentExtensionSet({ includeInlineFactories: true });\n\t}\n\n\tasync reload(options?: ResourceLoaderReloadOptions): Promise<void> {\n\t\tresetTimings(\"extensions\");\n\n\t\tif (this.loaded) {\n\t\t\tclearExtensionCache();\n\t\t}\n\n\t\tlet preTrustExtensions: LoadExtensionsResult | undefined;\n\t\tif (options?.resolveProjectTrust) {\n\t\t\tpreTrustExtensions = await this.loadProjectTrustExtensions();\n\t\t\tconst projectTrusted = await options.resolveProjectTrust({ extensionsResult: preTrustExtensions });\n\t\t\tthis.settingsManager.setProjectTrusted(projectTrusted);\n\t\t}\n\n\t\t// reload() preserves SettingsManager.projectTrusted and reloads settings for that trust state.\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// Kept on the instance so post-reload passes (extendResources) can still resolve package metadata.\n\t\tthis.resourceMetadataByPath = new Map();\n\t\tconst metadataByPath = this.resourceMetadataByPath;\n\n\t\tthis.extensionSkillSourceInfos = new Map();\n\t\tthis.extensionPromptSourceInfos = new Map();\n\t\tthis.extensionThemeSourceInfos = new Map();\n\n\t\t// Helper to extract enabled paths and store metadata\n\t\tconst getEnabledResources = (resources: ResolvedResource[]): ResolvedResource[] => {\n\t\t\tfor (const r of resources) {\n\t\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\t\tmetadataByPath.set(r.path, r.metadata);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn resources.filter((r) => r.enabled);\n\t\t};\n\n\t\tconst getEnabledPaths = (resources: ResolvedResource[]): string[] =>\n\t\t\tgetEnabledResources(resources).map((r) => r.path);\n\t\tconst enabledExtensions = getEnabledPaths(resolvedPaths.extensions);\n\t\tconst enabledSkillResources = getEnabledResources(resolvedPaths.skills);\n\t\tconst enabledPrompts = getEnabledPaths(resolvedPaths.prompts);\n\t\tconst enabledThemes = getEnabledPaths(resolvedPaths.themes);\n\n\t\tconst enabledSkills = enabledSkillResources.map((resource) => this.mapSkillPath(resource, metadataByPath));\n\n\t\t// Add CLI paths metadata\n\t\tfor (const r of cliExtensionPaths.extensions) {\n\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\tmetadataByPath.set(r.path, { source: \"cli\", scope: \"temporary\", origin: \"top-level\" });\n\t\t\t}\n\t\t}\n\t\tfor (const r of cliExtensionPaths.skills) {\n\t\t\tif (!metadataByPath.has(r.path)) {\n\t\t\t\tmetadataByPath.set(r.path, { source: \"cli\", scope: \"temporary\", origin: \"top-level\" });\n\t\t\t}\n\t\t}\n\n\t\tconst cliEnabledExtensions = getEnabledPaths(cliExtensionPaths.extensions);\n\t\tconst cliEnabledSkills = getEnabledPaths(cliExtensionPaths.skills);\n\t\tconst cliEnabledPrompts = getEnabledPaths(cliExtensionPaths.prompts);\n\t\tconst cliEnabledThemes = getEnabledPaths(cliExtensionPaths.themes);\n\n\t\tconst extensionPaths = this.noExtensions\n\t\t\t? cliEnabledExtensions\n\t\t\t: this.mergePaths(cliEnabledExtensions, enabledExtensions);\n\n\t\tconst extensionsResult = await this.loadFinalExtensionSet(extensionPaths, preTrustExtensions);\n\t\tfor (const p of this.additionalExtensionPaths) {\n\t\t\tif (isLocalPath(p)) {\n\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\tif (!existsSync(resolved)) {\n\t\t\t\t\textensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.extensionsResult = this.extensionsOverride ? this.extensionsOverride(extensionsResult) : extensionsResult;\n\t\tthis.applyExtensionSourceInfo(this.extensionsResult.extensions, metadataByPath);\n\n\t\tconst skillPaths = this.noSkills\n\t\t\t? this.mergePaths(cliEnabledSkills, this.additionalSkillPaths)\n\t\t\t: this.mergePaths([...cliEnabledSkills, ...enabledSkills], this.additionalSkillPaths);\n\n\t\tthis.lastSkillPaths = skillPaths;\n\t\tthis.updateSkillsFromPaths(skillPaths, metadataByPath);\n\t\tfor (const p of this.additionalSkillPaths) {\n\t\t\tif (isLocalPath(p)) {\n\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\tif (!existsSync(resolved) && !this.skillDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\tthis.skillDiagnostics.push({ type: \"error\", message: \"Skill path does not exist\", path: resolved });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst promptPaths = this.noPromptTemplates\n\t\t\t? this.mergePaths(cliEnabledPrompts, this.additionalPromptTemplatePaths)\n\t\t\t: this.mergePaths([...cliEnabledPrompts, ...enabledPrompts], this.additionalPromptTemplatePaths);\n\n\t\tthis.lastPromptPaths = promptPaths;\n\t\tthis.updatePromptsFromPaths(promptPaths, metadataByPath);\n\t\tfor (const p of this.additionalPromptTemplatePaths) {\n\t\t\tif (isLocalPath(p)) {\n\t\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\t\tif (!existsSync(resolved) && !this.promptDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\t\tthis.promptDiagnostics.push({\n\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\tmessage: \"Prompt template path does not exist\",\n\t\t\t\t\t\tpath: resolved,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst themePaths = this.noThemes\n\t\t\t? this.mergePaths(cliEnabledThemes, this.additionalThemePaths)\n\t\t\t: this.mergePaths([...cliEnabledThemes, ...enabledThemes], this.additionalThemePaths);\n\n\t\tthis.lastThemePaths = themePaths;\n\t\tthis.updateThemesFromPaths(themePaths, metadataByPath);\n\t\tfor (const p of this.additionalThemePaths) {\n\t\t\tconst resolved = this.resolveResourcePath(p);\n\t\t\tif (!existsSync(resolved) && !this.themeDiagnostics.some((d) => d.path === resolved)) {\n\t\t\t\tthis.themeDiagnostics.push({ type: \"error\", message: \"Theme path does not exist\", path: resolved });\n\t\t\t}\n\t\t}\n\n\t\tconst agentsFiles = {\n\t\t\tagentsFiles: 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\tprojectMemoryEnabled: this.settingsManager.getProjectMemoryEnabled(),\n\t\t\t\t\t\tmemoryEngine: this.memoryEngine,\n\t\t\t\t\t}),\n\t\t};\n\t\tconst resolvedAgentsFiles = this.agentsFilesOverride ? this.agentsFilesOverride(agentsFiles) : agentsFiles;\n\t\tthis.agentsFiles = resolvedAgentsFiles.agentsFiles;\n\n\t\tconst systemPromptSource = this.systemPromptSource ?? this.discoverSystemPromptFile();\n\t\tconst baseSystemPrompt = resolvePromptInput(systemPromptSource, \"system prompt\");\n\t\tthis.systemPrompt = this.systemPromptOverride ? this.systemPromptOverride(baseSystemPrompt) : baseSystemPrompt;\n\t\tthis.systemPromptSourcePath =\n\t\t\tsystemPromptSource && existsSync(systemPromptSource) ? resolvePath(systemPromptSource) : undefined;\n\n\t\tlet appendSources = this.appendSystemPromptSource;\n\t\tif (!appendSources) {\n\t\t\tconst discoveredAppendSystemPromptFile = this.discoverAppendSystemPromptFile();\n\t\t\tappendSources = discoveredAppendSystemPromptFile ? [discoveredAppendSystemPromptFile] : [];\n\t\t}\n\t\tconst baseAppend = appendSources\n\t\t\t.map((s) => resolvePromptInput(s, \"append system prompt\"))\n\t\t\t.filter((s): s is string => s !== undefined);\n\t\tthis.appendSystemPrompt = this.appendSystemPromptOverride\n\t\t\t? this.appendSystemPromptOverride(baseAppend)\n\t\t\t: baseAppend;\n\t\tthis.appendSystemPromptSourcePaths = appendSources\n\t\t\t.filter((source) => existsSync(source))\n\t\t\t.map((source) => resolvePath(source));\n\t\tthis.loaded = true;\n\t}\n\n\tprivate async loadCurrentExtensionSet(options: { includeInlineFactories: boolean }): Promise<LoadExtensionsResult> {\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\tconst enabledExtensions = resolvedPaths.extensions.filter((r) => r.enabled).map((r) => r.path);\n\t\tconst cliEnabledExtensions = cliExtensionPaths.extensions.filter((r) => r.enabled).map((r) => r.path);\n\t\tconst extensionPaths = this.noExtensions\n\t\t\t? cliEnabledExtensions\n\t\t\t: this.mergePaths(cliEnabledExtensions, enabledExtensions);\n\t\tconst extensionsResult = await loadExtensionsCached(extensionPaths, this.cwd, this.eventBus);\n\t\tif (!options.includeInlineFactories) {\n\t\t\treturn extensionsResult;\n\t\t}\n\n\t\tconst inlineExtensions = await this.loadExtensionFactories(extensionsResult.runtime);\n\t\textensionsResult.extensions.push(...inlineExtensions.extensions);\n\t\textensionsResult.errors.push(...inlineExtensions.errors);\n\t\treturn extensionsResult;\n\t}\n\n\tprivate resolveExtensionLoadPath(path: string): string {\n\t\treturn resolvePath(path, this.cwd, { normalizeUnicodeSpaces: true });\n\t}\n\n\tprivate async loadFinalExtensionSet(\n\t\textensionPaths: string[],\n\t\tpreTrustExtensions: LoadExtensionsResult | undefined,\n\t): Promise<LoadExtensionsResult> {\n\t\tif (!preTrustExtensions) {\n\t\t\tconst extensionsResult = await loadExtensionsCached(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\t\t\tthis.addExtensionConflictDiagnostics(extensionsResult);\n\t\t\treturn extensionsResult;\n\t\t}\n\n\t\tconst preloadedByPath = new Map(\n\t\t\tpreTrustExtensions.extensions\n\t\t\t\t.filter((extension) => !extension.path.startsWith(\"<inline:\"))\n\t\t\t\t.map((extension) => [extension.resolvedPath, extension]),\n\t\t);\n\t\tconst failedPreloadPaths = new Set(\n\t\t\tpreTrustExtensions.errors.map((error) => this.resolveExtensionLoadPath(error.path)),\n\t\t);\n\t\tconst remainingPaths = extensionPaths.filter((path) => {\n\t\t\tconst resolvedPath = this.resolveExtensionLoadPath(path);\n\t\t\treturn !preloadedByPath.has(resolvedPath) && !failedPreloadPaths.has(resolvedPath);\n\t\t});\n\t\tconst remainingExtensions = await loadExtensionsCached(\n\t\t\tremainingPaths,\n\t\t\tthis.cwd,\n\t\t\tthis.eventBus,\n\t\t\tpreTrustExtensions.runtime,\n\t\t);\n\t\tconst loadedByPath = new Map(preloadedByPath);\n\t\tfor (const extension of remainingExtensions.extensions) {\n\t\t\tloadedByPath.set(extension.resolvedPath, extension);\n\t\t}\n\n\t\tconst inlineExtensions = preTrustExtensions.extensions.filter((extension) =>\n\t\t\textension.path.startsWith(\"<inline:\"),\n\t\t);\n\t\tconst orderedExtensions = extensionPaths\n\t\t\t.map((path) => loadedByPath.get(this.resolveExtensionLoadPath(path)))\n\t\t\t.filter((extension): extension is Extension => extension !== undefined);\n\t\torderedExtensions.push(...inlineExtensions);\n\n\t\tconst extensionsResult: LoadExtensionsResult = {\n\t\t\textensions: orderedExtensions,\n\t\t\terrors: [...preTrustExtensions.errors, ...remainingExtensions.errors],\n\t\t\truntime: preTrustExtensions.runtime,\n\t\t};\n\t\tthis.addExtensionConflictDiagnostics(extensionsResult);\n\t\treturn extensionsResult;\n\t}\n\n\tprivate addExtensionConflictDiagnostics(extensionsResult: LoadExtensionsResult): void {\n\t\t// Detect extension conflicts (tools, commands, flags with same names from different extensions)\n\t\t// Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.\n\t\tconst conflicts = this.detectExtensionConflicts(extensionsResult.extensions);\n\t\tfor (const conflict of conflicts) {\n\t\t\textensionsResult.errors.push({ path: conflict.path, error: conflict.message });\n\t\t}\n\t}\n\n\tprivate mapSkillPath(resource: ResolvedResource, metadataByPath: Map<string, PathMetadata>): string {\n\t\tif (resource.metadata.source !== \"auto\" && resource.metadata.origin !== \"package\") {\n\t\t\treturn resource.path;\n\t\t}\n\t\ttry {\n\t\t\tconst stats = statSync(resource.path);\n\t\t\tif (!stats.isDirectory()) {\n\t\t\t\treturn resource.path;\n\t\t\t}\n\t\t} catch {\n\t\t\treturn resource.path;\n\t\t}\n\t\tconst skillFile = join(resource.path, \"SKILL.md\");\n\t\tif (existsSync(skillFile)) {\n\t\t\tif (!metadataByPath.has(skillFile)) {\n\t\t\t\tmetadataByPath.set(skillFile, resource.metadata);\n\t\t\t}\n\t\t\treturn skillFile;\n\t\t}\n\t\treturn resource.path;\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, input] of this.extensionFactories.entries()) {\n\t\t\tconst isNamed = typeof input !== \"function\";\n\t\t\tconst factory = isNamed ? input.factory : input;\n\t\t\tconst extensionPath = `<inline:${isNamed ? input.name : 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\textension.hidden = isNamed && input.hidden;\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"]}
@@ -10,6 +10,7 @@ import { findGitPaths } from "./footer-data-provider.js";
10
10
  import { DefaultPackageManager } from "./package-manager.js";
11
11
  import { loadProjectMemorySync } from "./project-memory.js";
12
12
  import { MemoryEngine } from "./memory-engine/engine.js";
13
+ import { VaultManager } from "./memory-engine/vault.js";
13
14
  import { loadPromptTemplates } from "./prompt-templates.js";
14
15
  import { SettingsManager } from "./settings-manager.js";
15
16
  import { loadSkills } from "./skills.js";
@@ -147,6 +148,7 @@ export class DefaultResourceLoader {
147
148
  noThemes;
148
149
  noContextFiles;
149
150
  memoryEngine = null;
151
+ vaultManager = null;
150
152
  systemPromptSource;
151
153
  appendSystemPromptSource;
152
154
  extensionsOverride;
@@ -186,6 +188,8 @@ export class DefaultResourceLoader {
186
188
  cwd: this.cwd,
187
189
  getConfig: () => this.settingsManager.getMemoryEngineConfig(),
188
190
  });
191
+ // Ada Secure Vault — encrypted secrets (project + session scopes).
192
+ this.vaultManager = new VaultManager(this.agentDir, this.memoryEngine.projectHash);
189
193
  this.eventBus = options.eventBus ?? createEventBus();
190
194
  this.packageManager = new DefaultPackageManager({
191
195
  cwd: this.cwd,
@@ -248,6 +252,9 @@ export class DefaultResourceLoader {
248
252
  getMemoryEngine() {
249
253
  return this.memoryEngine;
250
254
  }
255
+ getVaultManager() {
256
+ return this.vaultManager;
257
+ }
251
258
  getSystemPrompt() {
252
259
  return this.systemPrompt;
253
260
  }