@agimon-ai/doompi 0.0.1-alpha.121 → 0.0.1-alpha.123

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.
@@ -13,6 +13,46 @@ let _agimon_ai_doompi_config_layeredConfig = require("@agimon-ai/doompi-config/l
13
13
  let yaml = require("yaml");
14
14
  //#region src/builders/hooks/index.ts
15
15
  const HOOK_MODULES_FILE = "hook-modules.json";
16
+ /** Add checkout source names while retaining the admitted generation's artifact mappings. */
17
+ function checkoutHookDescriptor(descriptor, sourceRoot, repoRoot, directory) {
18
+ if (!descriptor || node_path.default.resolve(sourceRoot) === node_path.default.resolve(repoRoot)) return descriptor;
19
+ const value = JSON.parse(node_fs.default.readFileSync(descriptor.file, "utf8"));
20
+ if (!(0, _agimon_ai_doompi_core_runtimeJson.isRecord)(value) || value.version !== 1 || !Array.isArray(value.modules)) throw new Error("invalid hook module descriptor");
21
+ const sources = /* @__PURE__ */ new Set();
22
+ const modules = [];
23
+ for (const entry of value.modules) {
24
+ if (!(0, _agimon_ai_doompi_core_runtimeJson.isRecord)(entry) || typeof entry.source !== "string" || typeof entry.artifact !== "string" || !node_path.default.isAbsolute(entry.source) || !node_path.default.isAbsolute(entry.artifact) || ![
25
+ ".mjs",
26
+ ".js",
27
+ ".cjs"
28
+ ].includes(node_path.default.extname(entry.artifact)) || sources.has(entry.source)) throw new Error("invalid hook module artifact mapping");
29
+ sources.add(entry.source);
30
+ modules.push({
31
+ ...entry,
32
+ source: entry.source,
33
+ artifact: entry.artifact
34
+ });
35
+ }
36
+ const aliases = [];
37
+ for (const entry of modules) {
38
+ const relative = node_path.default.relative(sourceRoot, entry.source);
39
+ if (!relative || relative === ".." || relative.startsWith(`..${node_path.default.sep}`) || node_path.default.isAbsolute(relative)) continue;
40
+ const source = node_path.default.resolve(repoRoot, relative);
41
+ if (sources.has(source)) continue;
42
+ sources.add(source);
43
+ aliases.push({
44
+ ...entry,
45
+ source
46
+ });
47
+ }
48
+ if (aliases.length === 0) return descriptor;
49
+ const file = node_path.default.join(directory, HOOK_MODULES_FILE);
50
+ node_fs.default.writeFileSync(file, `${JSON.stringify({
51
+ ...value,
52
+ modules: [...modules, ...aliases]
53
+ }, null, 2)}\n`, { mode: 384 });
54
+ return { file };
55
+ }
16
56
  /** Core plus the union of every mode's selection. An unset selection admits all. */
17
57
  function requiredHookGroups(config) {
18
58
  const groups = /* @__PURE__ */ new Set();
@@ -111,6 +151,7 @@ async function syncHookModules(options) {
111
151
  }
112
152
  //#endregion
113
153
  exports.HOOK_MODULES_FILE = HOOK_MODULES_FILE;
154
+ exports.checkoutHookDescriptor = checkoutHookDescriptor;
114
155
  exports.requiredHookGroups = requiredHookGroups;
115
156
  exports.syncHookModules = syncHookModules;
116
157
  exports.validateHookModules = validateHookModules;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["doomConfigCandidates","fs","parseYaml","isRecord","optionalPackageEntry","pathToFileURL","path","crypto","compileExtensionModule","extensionModuleManifestPath"],"sources":["../../../../src/builders/hooks/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport { doomConfigCandidates } from '@agimon-ai/doompi-config/layeredConfig';\nimport type { MajorModesConfig } from '@agimon-ai/doompi-config/majorModes';\nimport { optionalPackageEntry } from '@agimon-ai/doompi-core/moduleResolution';\nimport { isRecord } from '@agimon-ai/doompi-core/runtimeJson';\nimport { parse as parseYaml } from 'yaml';\n\nimport { compileExtensionModule, extensionModuleManifestPath } from '../../compiler';\n\nexport const HOOK_MODULES_FILE = 'hook-modules.json';\n\ninterface HookRegistryRow {\n module?: string;\n core: boolean;\n skipInSubagent?: boolean;\n registryId: string;\n groupId: string;\n rowId: string;\n event: string;\n}\n\n/** The optional hook package owns parsing; the CLI only consumes this capability. */\ninterface HookParserModule {\n createHookModules(options: { descriptor?: { file: string } }): {\n validate(rows: readonly HookRegistryRow[]): Promise<void>;\n dispose(): Promise<void>;\n };\n createHookDocumentReader(options: { homeDirectory: string; warn: (message: string) => void }): {\n registry(repoRoot: string): Promise<{\n entries: HookRegistryRow[];\n failure?: { message: string };\n }>;\n };\n}\n\n/** Core plus the union of every mode's selection. An unset selection admits all. */\nexport function requiredHookGroups(config: MajorModesConfig): Set<string> | undefined {\n const groups = new Set<string>();\n for (const mode of Object.values(config.majorMode)) {\n const layers = mode.layers.map((name) => config.layers[name]);\n if (layers.length === 0 || layers.some((layer) => layer?.hookGroups === undefined)) return undefined;\n for (const layer of layers) for (const group of layer.hookGroups ?? []) groups.add(group);\n }\n return groups;\n}\n\nasync function hookParser(options: { repoRoot: string; homeDirectory: string }): Promise<HookParserModule | undefined> {\n const candidates = doomConfigCandidates('hooks.yaml', options.repoRoot, options.homeDirectory);\n // Command-only registries predate module compilation and do not require the package.\n // This is discovery only. The public parser still owns validation and attribution.\n const hasModuleRows = candidates.some((candidate) => {\n if (!fs.existsSync(candidate.filePath)) return false;\n const document: unknown = parseYaml(fs.readFileSync(candidate.filePath, 'utf8'));\n if (!isRecord(document) || !isRecord(document.groups)) return false;\n return Object.values(document.groups).some(\n (group) =>\n isRecord(group) &&\n Array.isArray(group.hooks) &&\n group.hooks.some((row: unknown) => isRecord(row) && isRecord(row.pi) && 'module' in row.pi),\n );\n });\n const parserEntry =\n optionalPackageEntry('@agimon-ai/doompi-hook', pathToFileURL(path.join(options.repoRoot, 'package.json')).href) ??\n optionalPackageEntry('@agimon-ai/doompi-hook', import.meta.url);\n if (hasModuleRows && !parserEntry)\n throw new Error(\n 'Hook module rows require @agimon-ai/doompi-hook. Install it in the repository or select a layer that provides it, then run doompi sync.',\n );\n return hasModuleRows && parserEntry\n ? ((await import(pathToFileURL(parserEntry).href)) as HookParserModule)\n : undefined;\n}\n\n/** Validate the selected compiled hooks without importing repository code. */\nexport async function validateHookModules(options: {\n repoRoot: string;\n homeDirectory: string;\n hookGroups?: readonly string[];\n descriptor?: { file: string };\n isSubagent?: boolean;\n}): Promise<boolean> {\n const parser = await hookParser(options);\n if (!parser) return false;\n const read = await parser\n .createHookDocumentReader({ homeDirectory: options.homeDirectory, warn: () => undefined })\n .registry(options.repoRoot);\n if (read.failure) throw new Error(read.failure.message);\n const allowed = options.hookGroups === undefined ? undefined : new Set(options.hookGroups);\n const rows = read.entries\n .filter((row) => row.core || !allowed || allowed.has(row.groupId))\n .filter((row) => !(options.isSubagent && row.skipInSubagent));\n const modules = parser.createHookModules({ descriptor: options.descriptor });\n try {\n await modules.validate(rows);\n return rows.some((row) => row.module !== undefined);\n } finally {\n await modules.dispose();\n }\n}\n\n/** Bundles hook exports without importing or invoking repository code. */\nexport async function syncHookModules(options: {\n repoRoot: string;\n homeDirectory: string;\n config: MajorModesConfig;\n directory: string;\n sharedCacheDirectory?: string;\n}): Promise<{ file: string }> {\n const parser = await hookParser(options);\n const read = parser\n ? await parser\n .createHookDocumentReader({ homeDirectory: options.homeDirectory, warn: () => undefined })\n .registry(options.repoRoot)\n : { entries: [] };\n if ('failure' in read && read.failure) throw new Error(read.failure.message);\n const groups = requiredHookGroups(options.config);\n const sources = new Map<string, Array<{ registry: string; groupId: string; rowId: string; event: string }>>();\n for (const row of read.entries) {\n if (!row.module || (!row.core && groups && !groups.has(row.groupId))) continue;\n const rows = sources.get(row.module) ?? [];\n rows.push({ registry: row.registryId, groupId: row.groupId, rowId: row.rowId, event: row.event });\n sources.set(row.module, rows);\n }\n const cache = path.join(options.directory, 'cache');\n const outputDirectory = path.join(options.directory, 'dist', 'hooks');\n const modules = [];\n for (const [source, rows] of sources) {\n const compileOptions = {\n repositoryRoot: options.repoRoot,\n outputDirectory,\n outputName: `${crypto.createHash('sha256').update(source).digest('hex')}.mjs`,\n sharedCacheDirectory: options.sharedCacheDirectory,\n };\n try {\n const artifact = await compileExtensionModule(source, cache, compileOptions);\n const receipt = JSON.parse(\n await fs.promises.readFile(extensionModuleManifestPath(source, cache, compileOptions), 'utf8'),\n ) as unknown;\n modules.push({ source, artifact, receipt, rows });\n } catch (cause) {\n const attribution = rows\n .map((row) => `${row.registry}: group ${row.groupId}, row ${row.rowId}, event ${row.event}`)\n .join('; ');\n throw new Error(`Hook module compilation failed (${attribution}): ${source}`, { cause });\n }\n }\n await fs.promises.mkdir(outputDirectory, { recursive: true, mode: 0o700 });\n const file = path.join(outputDirectory, HOOK_MODULES_FILE);\n await fs.promises.writeFile(file, `${JSON.stringify({ version: 1, modules }, null, 2)}\\n`, { mode: 0o600 });\n return { file };\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,oBAAoB;;AA2BjC,SAAgB,mBAAmB,QAAmD;CACpF,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,QAAQ,OAAO,OAAO,OAAO,SAAS,GAAG;EAClD,MAAM,SAAS,KAAK,OAAO,KAAK,SAAS,OAAO,OAAO,KAAK;EAC5D,IAAI,OAAO,WAAW,KAAK,OAAO,MAAM,UAAU,OAAO,eAAe,KAAA,CAAS,GAAG,OAAO,KAAA;EAC3F,KAAK,MAAM,SAAS,QAAQ,KAAK,MAAM,SAAS,MAAM,cAAc,CAAC,GAAG,OAAO,IAAI,KAAK;CAC1F;CACA,OAAO;AACT;AAEA,eAAe,WAAW,SAA6F;CAIrH,MAAM,iBAAA,GAHaA,uCAAAA,qBAAAA,CAAqB,cAAc,QAAQ,UAAU,QAAQ,aAGjD,CAAC,CAAC,MAAM,cAAc;EACnD,IAAI,CAACC,QAAAA,QAAG,WAAW,UAAU,QAAQ,GAAG,OAAO;EAC/C,MAAM,YAAA,GAAoBC,KAAAA,MAAAA,CAAUD,QAAAA,QAAG,aAAa,UAAU,UAAU,MAAM,CAAC;EAC/E,IAAI,EAAA,GAACE,mCAAAA,SAAAA,CAAS,QAAQ,KAAK,EAAA,GAACA,mCAAAA,SAAAA,CAAS,SAAS,MAAM,GAAG,OAAO;EAC9D,OAAO,OAAO,OAAO,SAAS,MAAM,CAAC,CAAC,MACnC,WAAA,GACCA,mCAAAA,SAAAA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O,cAAc;GAC3E,MAAM,UAAU,KAAK,MACnB,MAAMP,QAAAA,QAAG,SAAS,SAASQ,cAAAA,4BAA4B,QAAQ,OAAO,cAAc,GAAG,MAAM,CAC/F;GACA,QAAQ,KAAK;IAAE;IAAQ;IAAU;IAAS;GAAK,CAAC;EAClD,SAAS,OAAO;GACd,MAAM,cAAc,KACjB,KAAK,QAAQ,GAAG,IAAI,SAAS,UAAU,IAAI,QAAQ,QAAQ,IAAI,MAAM,UAAU,IAAI,OAAO,CAAC,CAC3F,KAAK,IAAI;GACZ,MAAM,IAAI,MAAM,mCAAmC,YAAY,KAAK,UAAU,EAAE,MAAM,CAAC;EACzF;CACF;CACA,MAAMR,QAAAA,QAAG,SAAS,MAAM,iBAAiB;EAAE,WAAW;EAAM,MAAM;CAAM,CAAC;CACzE,MAAM,OAAOK,UAAAA,QAAK,KAAK,iBAAiB,iBAAiB;CACzD,MAAML,QAAAA,QAAG,SAAS,UAAU,MAAM,GAAG,KAAK,UAAU;EAAE,SAAS;EAAG;CAAQ,GAAG,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,IAAM,CAAC;CAC1G,OAAO,EAAE,KAAK;AAChB"}
1
+ {"version":3,"file":"index.cjs","names":["path","fs","isRecord","doomConfigCandidates","parseYaml","optionalPackageEntry","pathToFileURL","crypto","compileExtensionModule","extensionModuleManifestPath"],"sources":["../../../../src/builders/hooks/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport { doomConfigCandidates } from '@agimon-ai/doompi-config/layeredConfig';\nimport type { MajorModesConfig } from '@agimon-ai/doompi-config/majorModes';\nimport { optionalPackageEntry } from '@agimon-ai/doompi-core/moduleResolution';\nimport { isRecord } from '@agimon-ai/doompi-core/runtimeJson';\nimport { parse as parseYaml } from 'yaml';\n\nimport { compileExtensionModule, extensionModuleManifestPath } from '../../compiler';\n\nexport const HOOK_MODULES_FILE = 'hook-modules.json';\n\n/** Add checkout source names while retaining the admitted generation's artifact mappings. */\nexport function checkoutHookDescriptor(\n descriptor: { file: string } | undefined,\n sourceRoot: string,\n repoRoot: string,\n directory: string,\n): { file: string } | undefined {\n if (!descriptor || path.resolve(sourceRoot) === path.resolve(repoRoot)) return descriptor;\n const value: unknown = JSON.parse(fs.readFileSync(descriptor.file, 'utf8'));\n if (!isRecord(value) || value.version !== 1 || !Array.isArray(value.modules))\n throw new Error('invalid hook module descriptor');\n const sources = new Set<string>();\n const modules: Array<Record<string, unknown> & { source: string; artifact: string }> = [];\n // Validate all originals first. Never repair an invalid descriptor by dropping entries.\n for (const entry of value.modules) {\n if (\n !isRecord(entry) ||\n typeof entry.source !== 'string' ||\n typeof entry.artifact !== 'string' ||\n !path.isAbsolute(entry.source) ||\n !path.isAbsolute(entry.artifact) ||\n !['.mjs', '.js', '.cjs'].includes(path.extname(entry.artifact)) ||\n sources.has(entry.source)\n )\n throw new Error('invalid hook module artifact mapping');\n sources.add(entry.source);\n modules.push({ ...entry, source: entry.source, artifact: entry.artifact });\n }\n const aliases = [];\n for (const entry of modules) {\n const relative = path.relative(sourceRoot, entry.source);\n if (!relative || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) continue;\n const source = path.resolve(repoRoot, relative);\n if (sources.has(source)) continue;\n sources.add(source);\n aliases.push({ ...entry, source });\n }\n if (aliases.length === 0) return descriptor;\n const file = path.join(directory, HOOK_MODULES_FILE);\n fs.writeFileSync(file, `${JSON.stringify({ ...value, modules: [...modules, ...aliases] }, null, 2)}\\n`, {\n mode: 0o600,\n });\n return { file };\n}\n\ninterface HookRegistryRow {\n module?: string;\n core: boolean;\n skipInSubagent?: boolean;\n registryId: string;\n groupId: string;\n rowId: string;\n event: string;\n}\n\n/** The optional hook package owns parsing; the CLI only consumes this capability. */\ninterface HookParserModule {\n createHookModules(options: { descriptor?: { file: string } }): {\n validate(rows: readonly HookRegistryRow[]): Promise<void>;\n dispose(): Promise<void>;\n };\n createHookDocumentReader(options: { homeDirectory: string; warn: (message: string) => void }): {\n registry(repoRoot: string): Promise<{\n entries: HookRegistryRow[];\n failure?: { message: string };\n }>;\n };\n}\n\n/** Core plus the union of every mode's selection. An unset selection admits all. */\nexport function requiredHookGroups(config: MajorModesConfig): Set<string> | undefined {\n const groups = new Set<string>();\n for (const mode of Object.values(config.majorMode)) {\n const layers = mode.layers.map((name) => config.layers[name]);\n if (layers.length === 0 || layers.some((layer) => layer?.hookGroups === undefined)) return undefined;\n for (const layer of layers) for (const group of layer.hookGroups ?? []) groups.add(group);\n }\n return groups;\n}\n\nasync function hookParser(options: { repoRoot: string; homeDirectory: string }): Promise<HookParserModule | undefined> {\n const candidates = doomConfigCandidates('hooks.yaml', options.repoRoot, options.homeDirectory);\n // Command-only registries predate module compilation and do not require the package.\n // This is discovery only. The public parser still owns validation and attribution.\n const hasModuleRows = candidates.some((candidate) => {\n if (!fs.existsSync(candidate.filePath)) return false;\n const document: unknown = parseYaml(fs.readFileSync(candidate.filePath, 'utf8'));\n if (!isRecord(document) || !isRecord(document.groups)) return false;\n return Object.values(document.groups).some(\n (group) =>\n isRecord(group) &&\n Array.isArray(group.hooks) &&\n group.hooks.some((row: unknown) => isRecord(row) && isRecord(row.pi) && 'module' in row.pi),\n );\n });\n const parserEntry =\n optionalPackageEntry('@agimon-ai/doompi-hook', pathToFileURL(path.join(options.repoRoot, 'package.json')).href) ??\n optionalPackageEntry('@agimon-ai/doompi-hook', import.meta.url);\n if (hasModuleRows && !parserEntry)\n throw new Error(\n 'Hook module rows require @agimon-ai/doompi-hook. Install it in the repository or select a layer that provides it, then run doompi sync.',\n );\n return hasModuleRows && parserEntry\n ? ((await import(pathToFileURL(parserEntry).href)) as HookParserModule)\n : undefined;\n}\n\n/** Validate the selected compiled hooks without importing repository code. */\nexport async function validateHookModules(options: {\n repoRoot: string;\n homeDirectory: string;\n hookGroups?: readonly string[];\n descriptor?: { file: string };\n isSubagent?: boolean;\n}): Promise<boolean> {\n const parser = await hookParser(options);\n if (!parser) return false;\n const read = await parser\n .createHookDocumentReader({ homeDirectory: options.homeDirectory, warn: () => undefined })\n .registry(options.repoRoot);\n if (read.failure) throw new Error(read.failure.message);\n const allowed = options.hookGroups === undefined ? undefined : new Set(options.hookGroups);\n const rows = read.entries\n .filter((row) => row.core || !allowed || allowed.has(row.groupId))\n .filter((row) => !(options.isSubagent && row.skipInSubagent));\n const modules = parser.createHookModules({ descriptor: options.descriptor });\n try {\n await modules.validate(rows);\n return rows.some((row) => row.module !== undefined);\n } finally {\n await modules.dispose();\n }\n}\n\n/** Bundles hook exports without importing or invoking repository code. */\nexport async function syncHookModules(options: {\n repoRoot: string;\n homeDirectory: string;\n config: MajorModesConfig;\n directory: string;\n sharedCacheDirectory?: string;\n}): Promise<{ file: string }> {\n const parser = await hookParser(options);\n const read = parser\n ? await parser\n .createHookDocumentReader({ homeDirectory: options.homeDirectory, warn: () => undefined })\n .registry(options.repoRoot)\n : { entries: [] };\n if ('failure' in read && read.failure) throw new Error(read.failure.message);\n const groups = requiredHookGroups(options.config);\n const sources = new Map<string, Array<{ registry: string; groupId: string; rowId: string; event: string }>>();\n for (const row of read.entries) {\n if (!row.module || (!row.core && groups && !groups.has(row.groupId))) continue;\n const rows = sources.get(row.module) ?? [];\n rows.push({ registry: row.registryId, groupId: row.groupId, rowId: row.rowId, event: row.event });\n sources.set(row.module, rows);\n }\n const cache = path.join(options.directory, 'cache');\n const outputDirectory = path.join(options.directory, 'dist', 'hooks');\n const modules = [];\n for (const [source, rows] of sources) {\n const compileOptions = {\n repositoryRoot: options.repoRoot,\n outputDirectory,\n outputName: `${crypto.createHash('sha256').update(source).digest('hex')}.mjs`,\n sharedCacheDirectory: options.sharedCacheDirectory,\n };\n try {\n const artifact = await compileExtensionModule(source, cache, compileOptions);\n const receipt = JSON.parse(\n await fs.promises.readFile(extensionModuleManifestPath(source, cache, compileOptions), 'utf8'),\n ) as unknown;\n modules.push({ source, artifact, receipt, rows });\n } catch (cause) {\n const attribution = rows\n .map((row) => `${row.registry}: group ${row.groupId}, row ${row.rowId}, event ${row.event}`)\n .join('; ');\n throw new Error(`Hook module compilation failed (${attribution}): ${source}`, { cause });\n }\n }\n await fs.promises.mkdir(outputDirectory, { recursive: true, mode: 0o700 });\n const file = path.join(outputDirectory, HOOK_MODULES_FILE);\n await fs.promises.writeFile(file, `${JSON.stringify({ version: 1, modules }, null, 2)}\\n`, { mode: 0o600 });\n return { file };\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,oBAAoB;;AAGjC,SAAgB,uBACd,YACA,YACA,UACA,WAC8B;CAC9B,IAAI,CAAC,cAAcA,UAAAA,QAAK,QAAQ,UAAU,MAAMA,UAAAA,QAAK,QAAQ,QAAQ,GAAG,OAAO;CAC/E,MAAM,QAAiB,KAAK,MAAMC,QAAAA,QAAG,aAAa,WAAW,MAAM,MAAM,CAAC;CAC1E,IAAI,EAAA,GAACC,mCAAAA,SAAAA,CAAS,KAAK,KAAK,MAAM,YAAY,KAAK,CAAC,MAAM,QAAQ,MAAM,OAAO,GACzE,MAAM,IAAI,MAAM,gCAAgC;CAClD,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,UAAiF,CAAC;CAExF,KAAK,MAAM,SAAS,MAAM,SAAS;EACjC,IACE,EAAA,GAACA,mCAAAA,SAAAA,CAAS,KAAK,KACf,OAAO,MAAM,WAAW,YACxB,OAAO,MAAM,aAAa,YAC1B,CAACF,UAAAA,QAAK,WAAW,MAAM,MAAM,KAC7B,CAACA,UAAAA,QAAK,WAAW,MAAM,QAAQ,KAC/B,CAAC;GAAC;GAAQ;GAAO;EAAM,CAAC,CAAC,SAASA,UAAAA,QAAK,QAAQ,MAAM,QAAQ,CAAC,KAC9D,QAAQ,IAAI,MAAM,MAAM,GAExB,MAAM,IAAI,MAAM,sCAAsC;EACxD,QAAQ,IAAI,MAAM,MAAM;EACxB,QAAQ,KAAK;GAAE,GAAG;GAAO,QAAQ,MAAM;GAAQ,UAAU,MAAM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AAK,KAAK,QAAQ,WAAW,QAAQ,OAAO;CACpE,MAAM,UAAU,CAAC;CACjB,KAAK,MAAM,CAAC,QAAQ,SAAS,SAAS;EACpC,MAAM,iBAAiB;GACrB,gBAAgB,QAAQ;GACxB;GACA,YAAY,GAAGO,YAAAA,QAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO,KAAK,EAAE;GACxE,sBAAsB,QAAQ;EAChC;EACA,IAAI;GACF,MAAM,WAAW,MAAMC,cAAAA,uBAAuB,QAAQ,OAAO,cAAc;GAC3E,MAAM,UAAU,KAAK,MACnB,MAAMP,QAAAA,QAAG,SAAS,SAASQ,cAAAA,4BAA4B,QAAQ,OAAO,cAAc,GAAG,MAAM,CAC/F;GACA,QAAQ,KAAK;IAAE;IAAQ;IAAU;IAAS;GAAK,CAAC;EAClD,SAAS,OAAO;GACd,MAAM,cAAc,KACjB,KAAK,QAAQ,GAAG,IAAI,SAAS,UAAU,IAAI,QAAQ,QAAQ,IAAI,MAAM,UAAU,IAAI,OAAO,CAAC,CAC3F,KAAK,IAAI;GACZ,MAAM,IAAI,MAAM,mCAAmC,YAAY,KAAK,UAAU,EAAE,MAAM,CAAC;EACzF;CACF;CACA,MAAMR,QAAAA,QAAG,SAAS,MAAM,iBAAiB;EAAE,WAAW;EAAM,MAAM;CAAM,CAAC;CACzE,MAAM,OAAOD,UAAAA,QAAK,KAAK,iBAAiB,iBAAiB;CACzD,MAAMC,QAAAA,QAAG,SAAS,UAAU,MAAM,GAAG,KAAK,UAAU;EAAE,SAAS;EAAG;CAAQ,GAAG,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,IAAM,CAAC;CAC1G,OAAO,EAAE,KAAK;AAChB"}
@@ -9,6 +9,46 @@ import { doomConfigCandidates } from "@agimon-ai/doompi-config/layeredConfig";
9
9
  import { parse } from "yaml";
10
10
  //#region src/builders/hooks/index.ts
11
11
  const HOOK_MODULES_FILE = "hook-modules.json";
12
+ /** Add checkout source names while retaining the admitted generation's artifact mappings. */
13
+ function checkoutHookDescriptor(descriptor, sourceRoot, repoRoot, directory) {
14
+ if (!descriptor || path.resolve(sourceRoot) === path.resolve(repoRoot)) return descriptor;
15
+ const value = JSON.parse(fs.readFileSync(descriptor.file, "utf8"));
16
+ if (!isRecord(value) || value.version !== 1 || !Array.isArray(value.modules)) throw new Error("invalid hook module descriptor");
17
+ const sources = /* @__PURE__ */ new Set();
18
+ const modules = [];
19
+ for (const entry of value.modules) {
20
+ if (!isRecord(entry) || typeof entry.source !== "string" || typeof entry.artifact !== "string" || !path.isAbsolute(entry.source) || !path.isAbsolute(entry.artifact) || ![
21
+ ".mjs",
22
+ ".js",
23
+ ".cjs"
24
+ ].includes(path.extname(entry.artifact)) || sources.has(entry.source)) throw new Error("invalid hook module artifact mapping");
25
+ sources.add(entry.source);
26
+ modules.push({
27
+ ...entry,
28
+ source: entry.source,
29
+ artifact: entry.artifact
30
+ });
31
+ }
32
+ const aliases = [];
33
+ for (const entry of modules) {
34
+ const relative = path.relative(sourceRoot, entry.source);
35
+ if (!relative || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) continue;
36
+ const source = path.resolve(repoRoot, relative);
37
+ if (sources.has(source)) continue;
38
+ sources.add(source);
39
+ aliases.push({
40
+ ...entry,
41
+ source
42
+ });
43
+ }
44
+ if (aliases.length === 0) return descriptor;
45
+ const file = path.join(directory, HOOK_MODULES_FILE);
46
+ fs.writeFileSync(file, `${JSON.stringify({
47
+ ...value,
48
+ modules: [...modules, ...aliases]
49
+ }, null, 2)}\n`, { mode: 384 });
50
+ return { file };
51
+ }
12
52
  /** Core plus the union of every mode's selection. An unset selection admits all. */
13
53
  function requiredHookGroups(config) {
14
54
  const groups = /* @__PURE__ */ new Set();
@@ -106,6 +146,6 @@ async function syncHookModules(options) {
106
146
  return { file };
107
147
  }
108
148
  //#endregion
109
- export { HOOK_MODULES_FILE, requiredHookGroups, syncHookModules, validateHookModules };
149
+ export { HOOK_MODULES_FILE, checkoutHookDescriptor, requiredHookGroups, syncHookModules, validateHookModules };
110
150
 
111
151
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["parseYaml"],"sources":["../../../../src/builders/hooks/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport { doomConfigCandidates } from '@agimon-ai/doompi-config/layeredConfig';\nimport type { MajorModesConfig } from '@agimon-ai/doompi-config/majorModes';\nimport { optionalPackageEntry } from '@agimon-ai/doompi-core/moduleResolution';\nimport { isRecord } from '@agimon-ai/doompi-core/runtimeJson';\nimport { parse as parseYaml } from 'yaml';\n\nimport { compileExtensionModule, extensionModuleManifestPath } from '../../compiler';\n\nexport const HOOK_MODULES_FILE = 'hook-modules.json';\n\ninterface HookRegistryRow {\n module?: string;\n core: boolean;\n skipInSubagent?: boolean;\n registryId: string;\n groupId: string;\n rowId: string;\n event: string;\n}\n\n/** The optional hook package owns parsing; the CLI only consumes this capability. */\ninterface HookParserModule {\n createHookModules(options: { descriptor?: { file: string } }): {\n validate(rows: readonly HookRegistryRow[]): Promise<void>;\n dispose(): Promise<void>;\n };\n createHookDocumentReader(options: { homeDirectory: string; warn: (message: string) => void }): {\n registry(repoRoot: string): Promise<{\n entries: HookRegistryRow[];\n failure?: { message: string };\n }>;\n };\n}\n\n/** Core plus the union of every mode's selection. An unset selection admits all. */\nexport function requiredHookGroups(config: MajorModesConfig): Set<string> | undefined {\n const groups = new Set<string>();\n for (const mode of Object.values(config.majorMode)) {\n const layers = mode.layers.map((name) => config.layers[name]);\n if (layers.length === 0 || layers.some((layer) => layer?.hookGroups === undefined)) return undefined;\n for (const layer of layers) for (const group of layer.hookGroups ?? []) groups.add(group);\n }\n return groups;\n}\n\nasync function hookParser(options: { repoRoot: string; homeDirectory: string }): Promise<HookParserModule | undefined> {\n const candidates = doomConfigCandidates('hooks.yaml', options.repoRoot, options.homeDirectory);\n // Command-only registries predate module compilation and do not require the package.\n // This is discovery only. The public parser still owns validation and attribution.\n const hasModuleRows = candidates.some((candidate) => {\n if (!fs.existsSync(candidate.filePath)) return false;\n const document: unknown = parseYaml(fs.readFileSync(candidate.filePath, 'utf8'));\n if (!isRecord(document) || !isRecord(document.groups)) return false;\n return Object.values(document.groups).some(\n (group) =>\n isRecord(group) &&\n Array.isArray(group.hooks) &&\n group.hooks.some((row: unknown) => isRecord(row) && isRecord(row.pi) && 'module' in row.pi),\n );\n });\n const parserEntry =\n optionalPackageEntry('@agimon-ai/doompi-hook', pathToFileURL(path.join(options.repoRoot, 'package.json')).href) ??\n optionalPackageEntry('@agimon-ai/doompi-hook', import.meta.url);\n if (hasModuleRows && !parserEntry)\n throw new Error(\n 'Hook module rows require @agimon-ai/doompi-hook. Install it in the repository or select a layer that provides it, then run doompi sync.',\n );\n return hasModuleRows && parserEntry\n ? ((await import(pathToFileURL(parserEntry).href)) as HookParserModule)\n : undefined;\n}\n\n/** Validate the selected compiled hooks without importing repository code. */\nexport async function validateHookModules(options: {\n repoRoot: string;\n homeDirectory: string;\n hookGroups?: readonly string[];\n descriptor?: { file: string };\n isSubagent?: boolean;\n}): Promise<boolean> {\n const parser = await hookParser(options);\n if (!parser) return false;\n const read = await parser\n .createHookDocumentReader({ homeDirectory: options.homeDirectory, warn: () => undefined })\n .registry(options.repoRoot);\n if (read.failure) throw new Error(read.failure.message);\n const allowed = options.hookGroups === undefined ? undefined : new Set(options.hookGroups);\n const rows = read.entries\n .filter((row) => row.core || !allowed || allowed.has(row.groupId))\n .filter((row) => !(options.isSubagent && row.skipInSubagent));\n const modules = parser.createHookModules({ descriptor: options.descriptor });\n try {\n await modules.validate(rows);\n return rows.some((row) => row.module !== undefined);\n } finally {\n await modules.dispose();\n }\n}\n\n/** Bundles hook exports without importing or invoking repository code. */\nexport async function syncHookModules(options: {\n repoRoot: string;\n homeDirectory: string;\n config: MajorModesConfig;\n directory: string;\n sharedCacheDirectory?: string;\n}): Promise<{ file: string }> {\n const parser = await hookParser(options);\n const read = parser\n ? await parser\n .createHookDocumentReader({ homeDirectory: options.homeDirectory, warn: () => undefined })\n .registry(options.repoRoot)\n : { entries: [] };\n if ('failure' in read && read.failure) throw new Error(read.failure.message);\n const groups = requiredHookGroups(options.config);\n const sources = new Map<string, Array<{ registry: string; groupId: string; rowId: string; event: string }>>();\n for (const row of read.entries) {\n if (!row.module || (!row.core && groups && !groups.has(row.groupId))) continue;\n const rows = sources.get(row.module) ?? [];\n rows.push({ registry: row.registryId, groupId: row.groupId, rowId: row.rowId, event: row.event });\n sources.set(row.module, rows);\n }\n const cache = path.join(options.directory, 'cache');\n const outputDirectory = path.join(options.directory, 'dist', 'hooks');\n const modules = [];\n for (const [source, rows] of sources) {\n const compileOptions = {\n repositoryRoot: options.repoRoot,\n outputDirectory,\n outputName: `${crypto.createHash('sha256').update(source).digest('hex')}.mjs`,\n sharedCacheDirectory: options.sharedCacheDirectory,\n };\n try {\n const artifact = await compileExtensionModule(source, cache, compileOptions);\n const receipt = JSON.parse(\n await fs.promises.readFile(extensionModuleManifestPath(source, cache, compileOptions), 'utf8'),\n ) as unknown;\n modules.push({ source, artifact, receipt, rows });\n } catch (cause) {\n const attribution = rows\n .map((row) => `${row.registry}: group ${row.groupId}, row ${row.rowId}, event ${row.event}`)\n .join('; ');\n throw new Error(`Hook module compilation failed (${attribution}): ${source}`, { cause });\n }\n }\n await fs.promises.mkdir(outputDirectory, { recursive: true, mode: 0o700 });\n const file = path.join(outputDirectory, HOOK_MODULES_FILE);\n await fs.promises.writeFile(file, `${JSON.stringify({ version: 1, modules }, null, 2)}\\n`, { mode: 0o600 });\n return { file };\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAa,oBAAoB;;AA2BjC,SAAgB,mBAAmB,QAAmD;CACpF,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,QAAQ,OAAO,OAAO,OAAO,SAAS,GAAG;EAClD,MAAM,SAAS,KAAK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A,MAAM,QAAQ,KAAK,KAAK,QAAQ,WAAW,OAAO;CAClD,MAAM,kBAAkB,KAAK,KAAK,QAAQ,WAAW,QAAQ,OAAO;CACpE,MAAM,UAAU,CAAC;CACjB,KAAK,MAAM,CAAC,QAAQ,SAAS,SAAS;EACpC,MAAM,iBAAiB;GACrB,gBAAgB,QAAQ;GACxB;GACA,YAAY,GAAG,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO,KAAK,EAAE;GACxE,sBAAsB,QAAQ;EAChC;EACA,IAAI;GACF,MAAM,WAAW,MAAM,uBAAuB,QAAQ,OAAO,cAAc;GAC3E,MAAM,UAAU,KAAK,MACnB,MAAM,GAAG,SAAS,SAAS,4BAA4B,QAAQ,OAAO,cAAc,GAAG,MAAM,CAC/F;GACA,QAAQ,KAAK;IAAE;IAAQ;IAAU;IAAS;GAAK,CAAC;EAClD,SAAS,OAAO;GACd,MAAM,cAAc,KACjB,KAAK,QAAQ,GAAG,IAAI,SAAS,UAAU,IAAI,QAAQ,QAAQ,IAAI,MAAM,UAAU,IAAI,OAAO,CAAC,CAC3F,KAAK,IAAI;GACZ,MAAM,IAAI,MAAM,mCAAmC,YAAY,KAAK,UAAU,EAAE,MAAM,CAAC;EACzF;CACF;CACA,MAAM,GAAG,SAAS,MAAM,iBAAiB;EAAE,WAAW;EAAM,MAAM;CAAM,CAAC;CACzE,MAAM,OAAO,KAAK,KAAK,iBAAiB,iBAAiB;CACzD,MAAM,GAAG,SAAS,UAAU,MAAM,GAAG,KAAK,UAAU;EAAE,SAAS;EAAG;CAAQ,GAAG,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,IAAM,CAAC;CAC1G,OAAO,EAAE,KAAK;AAChB"}
1
+ {"version":3,"file":"index.mjs","names":["parseYaml"],"sources":["../../../../src/builders/hooks/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport { doomConfigCandidates } from '@agimon-ai/doompi-config/layeredConfig';\nimport type { MajorModesConfig } from '@agimon-ai/doompi-config/majorModes';\nimport { optionalPackageEntry } from '@agimon-ai/doompi-core/moduleResolution';\nimport { isRecord } from '@agimon-ai/doompi-core/runtimeJson';\nimport { parse as parseYaml } from 'yaml';\n\nimport { compileExtensionModule, extensionModuleManifestPath } from '../../compiler';\n\nexport const HOOK_MODULES_FILE = 'hook-modules.json';\n\n/** Add checkout source names while retaining the admitted generation's artifact mappings. */\nexport function checkoutHookDescriptor(\n descriptor: { file: string } | undefined,\n sourceRoot: string,\n repoRoot: string,\n directory: string,\n): { file: string } | undefined {\n if (!descriptor || path.resolve(sourceRoot) === path.resolve(repoRoot)) return descriptor;\n const value: unknown = JSON.parse(fs.readFileSync(descriptor.file, 'utf8'));\n if (!isRecord(value) || value.version !== 1 || !Array.isArray(value.modules))\n throw new Error('invalid hook module descriptor');\n const sources = new Set<string>();\n const modules: Array<Record<string, unknown> & { source: string; artifact: string }> = [];\n // Validate all originals first. Never repair an invalid descriptor by dropping entries.\n for (const entry of value.modules) {\n if (\n !isRecord(entry) ||\n typeof entry.source !== 'string' ||\n typeof entry.artifact !== 'string' ||\n !path.isAbsolute(entry.source) ||\n !path.isAbsolute(entry.artifact) ||\n !['.mjs', '.js', '.cjs'].includes(path.extname(entry.artifact)) ||\n sources.has(entry.source)\n )\n throw new Error('invalid hook module artifact mapping');\n sources.add(entry.source);\n modules.push({ ...entry, source: entry.source, artifact: entry.artifact });\n }\n const aliases = [];\n for (const entry of modules) {\n const relative = path.relative(sourceRoot, entry.source);\n if (!relative || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) continue;\n const source = path.resolve(repoRoot, relative);\n if (sources.has(source)) continue;\n sources.add(source);\n aliases.push({ ...entry, source });\n }\n if (aliases.length === 0) return descriptor;\n const file = path.join(directory, HOOK_MODULES_FILE);\n fs.writeFileSync(file, `${JSON.stringify({ ...value, modules: [...modules, ...aliases] }, null, 2)}\\n`, {\n mode: 0o600,\n });\n return { file };\n}\n\ninterface HookRegistryRow {\n module?: string;\n core: boolean;\n skipInSubagent?: boolean;\n registryId: string;\n groupId: string;\n rowId: string;\n event: string;\n}\n\n/** The optional hook package owns parsing; the CLI only consumes this capability. */\ninterface HookParserModule {\n createHookModules(options: { descriptor?: { file: string } }): {\n validate(rows: readonly HookRegistryRow[]): Promise<void>;\n dispose(): Promise<void>;\n };\n createHookDocumentReader(options: { homeDirectory: string; warn: (message: string) => void }): {\n registry(repoRoot: string): Promise<{\n entries: HookRegistryRow[];\n failure?: { message: string };\n }>;\n };\n}\n\n/** Core plus the union of every mode's selection. An unset selection admits all. */\nexport function requiredHookGroups(config: MajorModesConfig): Set<string> | undefined {\n const groups = new Set<string>();\n for (const mode of Object.values(config.majorMode)) {\n const layers = mode.layers.map((name) => config.layers[name]);\n if (layers.length === 0 || layers.some((layer) => layer?.hookGroups === undefined)) return undefined;\n for (const layer of layers) for (const group of layer.hookGroups ?? []) groups.add(group);\n }\n return groups;\n}\n\nasync function hookParser(options: { repoRoot: string; homeDirectory: string }): Promise<HookParserModule | undefined> {\n const candidates = doomConfigCandidates('hooks.yaml', options.repoRoot, options.homeDirectory);\n // Command-only registries predate module compilation and do not require the package.\n // This is discovery only. The public parser still owns validation and attribution.\n const hasModuleRows = candidates.some((candidate) => {\n if (!fs.existsSync(candidate.filePath)) return false;\n const document: unknown = parseYaml(fs.readFileSync(candidate.filePath, 'utf8'));\n if (!isRecord(document) || !isRecord(document.groups)) return false;\n return Object.values(document.groups).some(\n (group) =>\n isRecord(group) &&\n Array.isArray(group.hooks) &&\n group.hooks.some((row: unknown) => isRecord(row) && isRecord(row.pi) && 'module' in row.pi),\n );\n });\n const parserEntry =\n optionalPackageEntry('@agimon-ai/doompi-hook', pathToFileURL(path.join(options.repoRoot, 'package.json')).href) ??\n optionalPackageEntry('@agimon-ai/doompi-hook', import.meta.url);\n if (hasModuleRows && !parserEntry)\n throw new Error(\n 'Hook module rows require @agimon-ai/doompi-hook. Install it in the repository or select a layer that provides it, then run doompi sync.',\n );\n return hasModuleRows && parserEntry\n ? ((await import(pathToFileURL(parserEntry).href)) as HookParserModule)\n : undefined;\n}\n\n/** Validate the selected compiled hooks without importing repository code. */\nexport async function validateHookModules(options: {\n repoRoot: string;\n homeDirectory: string;\n hookGroups?: readonly string[];\n descriptor?: { file: string };\n isSubagent?: boolean;\n}): Promise<boolean> {\n const parser = await hookParser(options);\n if (!parser) return false;\n const read = await parser\n .createHookDocumentReader({ homeDirectory: options.homeDirectory, warn: () => undefined })\n .registry(options.repoRoot);\n if (read.failure) throw new Error(read.failure.message);\n const allowed = options.hookGroups === undefined ? undefined : new Set(options.hookGroups);\n const rows = read.entries\n .filter((row) => row.core || !allowed || allowed.has(row.groupId))\n .filter((row) => !(options.isSubagent && row.skipInSubagent));\n const modules = parser.createHookModules({ descriptor: options.descriptor });\n try {\n await modules.validate(rows);\n return rows.some((row) => row.module !== undefined);\n } finally {\n await modules.dispose();\n }\n}\n\n/** Bundles hook exports without importing or invoking repository code. */\nexport async function syncHookModules(options: {\n repoRoot: string;\n homeDirectory: string;\n config: MajorModesConfig;\n directory: string;\n sharedCacheDirectory?: string;\n}): Promise<{ file: string }> {\n const parser = await hookParser(options);\n const read = parser\n ? await parser\n .createHookDocumentReader({ homeDirectory: options.homeDirectory, warn: () => undefined })\n .registry(options.repoRoot)\n : { entries: [] };\n if ('failure' in read && read.failure) throw new Error(read.failure.message);\n const groups = requiredHookGroups(options.config);\n const sources = new Map<string, Array<{ registry: string; groupId: string; rowId: string; event: string }>>();\n for (const row of read.entries) {\n if (!row.module || (!row.core && groups && !groups.has(row.groupId))) continue;\n const rows = sources.get(row.module) ?? [];\n rows.push({ registry: row.registryId, groupId: row.groupId, rowId: row.rowId, event: row.event });\n sources.set(row.module, rows);\n }\n const cache = path.join(options.directory, 'cache');\n const outputDirectory = path.join(options.directory, 'dist', 'hooks');\n const modules = [];\n for (const [source, rows] of sources) {\n const compileOptions = {\n repositoryRoot: options.repoRoot,\n outputDirectory,\n outputName: `${crypto.createHash('sha256').update(source).digest('hex')}.mjs`,\n sharedCacheDirectory: options.sharedCacheDirectory,\n };\n try {\n const artifact = await compileExtensionModule(source, cache, compileOptions);\n const receipt = JSON.parse(\n await fs.promises.readFile(extensionModuleManifestPath(source, cache, compileOptions), 'utf8'),\n ) as unknown;\n modules.push({ source, artifact, receipt, rows });\n } catch (cause) {\n const attribution = rows\n .map((row) => `${row.registry}: group ${row.groupId}, row ${row.rowId}, event ${row.event}`)\n .join('; ');\n throw new Error(`Hook module compilation failed (${attribution}): ${source}`, { cause });\n }\n }\n await fs.promises.mkdir(outputDirectory, { recursive: true, mode: 0o700 });\n const file = path.join(outputDirectory, HOOK_MODULES_FILE);\n await fs.promises.writeFile(file, `${JSON.stringify({ version: 1, modules }, null, 2)}\\n`, { mode: 0o600 });\n return { file };\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAa,oBAAoB;;AAGjC,SAAgB,uBACd,YACA,YACA,UACA,WAC8B;CAC9B,IAAI,CAAC,cAAc,KAAK,QAAQ,UAAU,MAAM,KAAK,QAAQ,QAAQ,GAAG,OAAO;CAC/E,MAAM,QAAiB,KAAK,MAAM,GAAG,aAAa,WAAW,MAAM,MAAM,CAAC;CAC1E,IAAI,CAAC,SAAS,KAAK,KAAK,MAAM,YAAY,KAAK,CAAC,MAAM,QAAQ,MAAM,OAAO,GACzE,MAAM,IAAI,MAAM,gCAAgC;CAClD,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,UAAiF,CAAC;CAExF,KAAK,MAAM,SAAS,MAAM,SAAS;EACjC,IACE,CAAC,SAAS,KAAK,KACf,OAAO,MAAM,WAAW,YACxB,OAAO,MAAM,aAAa,YAC1B,CAAC,KAAK,WAAW,MAAM,MAAM,KAC7B,CAAC,KAAK,WAAW,MAAM,QAAQ,KAC/B,CAAC;GAAC;GAAQ;GAAO;EAAM,CAAC,CAAC,SAAS,KAAK,QAAQ,MAA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AC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO,KAAK,EAAE;GACxE,sBAAsB,QAAQ;EAChC;EACA,IAAI;GACF,MAAM,WAAW,MAAM,uBAAuB,QAAQ,OAAO,cAAc;GAC3E,MAAM,UAAU,KAAK,MACnB,MAAM,GAAG,SAAS,SAAS,4BAA4B,QAAQ,OAAO,cAAc,GAAG,MAAM,CAC/F;GACA,QAAQ,KAAK;IAAE;IAAQ;IAAU;IAAS;GAAK,CAAC;EAClD,SAAS,OAAO;GACd,MAAM,cAAc,KACjB,KAAK,QAAQ,GAAG,IAAI,SAAS,UAAU,IAAI,QAAQ,QAAQ,IAAI,MAAM,UAAU,IAAI,OAAO,CAAC,CAC3F,KAAK,IAAI;GACZ,MAAM,IAAI,MAAM,mCAAmC,YAAY,KAAK,UAAU,EAAE,MAAM,CAAC;EACzF;CACF;CACA,MAAM,GAAG,SAAS,MAAM,iBAAiB;EAAE,WAAW;EAAM,MAAM;CAAM,CAAC;CACzE,MAAM,OAAO,KAAK,KAAK,iBAAiB,iBAAiB;CACzD,MAAM,GAAG,SAAS,UAAU,MAAM,GAAG,KAAK,UAAU;EAAE,SAAS;EAAG;CAAQ,GAAG,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,IAAM,CAAC;CAC1G,OAAO,EAAE,KAAK;AAChB"}
@@ -538,6 +538,11 @@ async function runServerRuntime(options, runtime) {
538
538
  notice(`Workspace '${workspace.root}' could not be restored: ${error instanceof Error ? error.message : String(error)}`);
539
539
  }
540
540
  }
541
+ const sessionDescriptors = /* @__PURE__ */ new WeakMap();
542
+ const sessionHookModules = (context, registration) => {
543
+ if (!sessionDescriptors.has(context)) sessionDescriptors.set(context, require_index$5.checkoutHookDescriptor(require_index$2.readRegisteredSyncState(registration, homeDirectory).fileState.hookModules, registration.root, context.options.repoRoot, context.resources.temporaryDirectory));
544
+ return sessionDescriptors.get(context);
545
+ };
541
546
  const sessionHostOptions = (context, bundle, mcpBundle, registration, identity, workspace, explicit = { pinned: [] }) => {
542
547
  const policyOptions = context.options;
543
548
  const sessionSelection = {
@@ -550,7 +555,7 @@ async function runServerRuntime(options, runtime) {
550
555
  };
551
556
  const piBootstrap = require_index$3.readRegisteredBootstrapStatus(registration, void 0, homeDirectory);
552
557
  if (!piBootstrap.fresh || piBootstrap.bootstrap === void 0) throw new Error(`The admitted DoomPi bootstrap for generation '${registration.generation}' is unavailable.`);
553
- const hookModules = require_index$2.readRegisteredSyncState(registration, homeDirectory).fileState.hookModules;
558
+ const hookModules = sessionHookModules(context, registration);
554
559
  require_index.updateHarnessState({ hookModules }, context.environment);
555
560
  return {
556
561
  cwd: policyOptions.cwd,
@@ -703,7 +708,7 @@ async function runServerRuntime(options, runtime) {
703
708
  repoRoot: harnessContext.options.repoRoot,
704
709
  homeDirectory,
705
710
  hookGroups: harnessContext.hookGroups,
706
- descriptor: require_index$2.readRegisteredSyncState(initialRegistration, homeDirectory).fileState.hookModules,
711
+ descriptor: sessionHookModules(harnessContext, initialRegistration),
707
712
  isSubagent: Boolean(baseEnvironment.PI_SUBAGENT_CHILD)
708
713
  });
709
714
  const initialBundle = await loadComposition(harnessContext.options.repoRoot, "session", {
@@ -816,7 +821,7 @@ async function runServerRuntime(options, runtime) {
816
821
  repoRoot: childContext.options.repoRoot,
817
822
  homeDirectory,
818
823
  hookGroups: childContext.hookGroups,
819
- descriptor: require_index$2.readRegisteredSyncState(registration, homeDirectory).fileState.hookModules,
824
+ descriptor: sessionHookModules(childContext, registration),
820
825
  isSubagent: Boolean(childEnvironment.PI_SUBAGENT_CHILD)
821
826
  });
822
827
  const bundle = await loadComposition(childContext.options.repoRoot, "session", {