@agimon-ai/doompi 0.0.1-alpha.114 → 0.0.1-alpha.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/extensions/terminalChildSession.cjs +1 -0
  2. package/dist/extensions/terminalChildSession.cjs.map +1 -1
  3. package/dist/extensions/terminalChildSession.d.mts.map +1 -1
  4. package/dist/extensions/terminalChildSession.mjs +2 -1
  5. package/dist/extensions/terminalChildSession.mjs.map +1 -1
  6. package/dist/src/builders/hooks/index.cjs +95 -0
  7. package/dist/src/builders/hooks/index.cjs.map +1 -0
  8. package/dist/src/builders/hooks/index.mjs +89 -0
  9. package/dist/src/builders/hooks/index.mjs.map +1 -0
  10. package/dist/src/builders/server/runtime.cjs +3 -1
  11. package/dist/src/builders/server/runtime.cjs.map +1 -1
  12. package/dist/src/builders/server/runtime.mjs +4 -2
  13. package/dist/src/builders/server/runtime.mjs.map +1 -1
  14. package/dist/src/cli/commands/sync/index.cjs +13 -4
  15. package/dist/src/cli/commands/sync/index.cjs.map +1 -1
  16. package/dist/src/cli/commands/sync/index.d.mts.map +1 -1
  17. package/dist/src/cli/commands/sync/index.mjs +9 -0
  18. package/dist/src/cli/commands/sync/index.mjs.map +1 -1
  19. package/dist/src/cli/commands/sync/inspection.cjs +1 -0
  20. package/dist/src/cli/commands/sync/inspection.cjs.map +1 -1
  21. package/dist/src/cli/commands/sync/inspection.d.mts.map +1 -1
  22. package/dist/src/cli/commands/sync/inspection.mjs +1 -0
  23. package/dist/src/cli/commands/sync/inspection.mjs.map +1 -1
  24. package/dist/src/compiler/index.cjs +13 -0
  25. package/dist/src/compiler/index.cjs.map +1 -1
  26. package/dist/src/compiler/index.mjs +13 -0
  27. package/dist/src/compiler/index.mjs.map +1 -1
  28. package/dist/src/composition/harnessState/index.d.mts.map +1 -1
  29. package/dist/src/composition/syncDrift/index.cjs +27 -0
  30. package/dist/src/composition/syncDrift/index.cjs.map +1 -1
  31. package/dist/src/composition/syncDrift/index.d.mts.map +1 -1
  32. package/dist/src/composition/syncDrift/index.mjs +27 -1
  33. package/dist/src/composition/syncDrift/index.mjs.map +1 -1
  34. package/dist/src/composition/syncState/index.cjs +2 -1
  35. package/dist/src/composition/syncState/index.cjs.map +1 -1
  36. package/dist/src/composition/syncState/index.d.mts +1 -1
  37. package/dist/src/composition/syncState/index.d.mts.map +1 -1
  38. package/dist/src/composition/syncState/index.mjs +2 -1
  39. package/dist/src/composition/syncState/index.mjs.map +1 -1
  40. package/package.json +29 -29
@@ -45,6 +45,7 @@ function terminalChildSessionPlugin(cordis, models, sessionsRoot) {
45
45
  subscribeMcpTool: (listener) => sessionContext.on("internal/service", (name) => {
46
46
  if (name === _agimon_ai_doompi_core_childSession.DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) listener();
47
47
  }),
48
+ hooks: () => sessionContext.get(_agimon_ai_doompi_core_childSession.DOOM_CHILD_SESSION_HOOKS_SERVICE),
48
49
  mcpTool: () => sessionContext.get(_agimon_ai_doompi_core_childSession.DOOM_CHILD_SESSION_MCP_TOOL_SERVICE)
49
50
  });
50
51
  sessionContext.provide(_agimon_ai_doompi_core_childSession.DOOM_CHILD_SESSION_SERVICE, childSessions.get());
@@ -1 +1 @@
1
- {"version":3,"file":"terminalChildSession.cjs","names":["DOOM_CORDIS_SESSION_SERVICE","createTerminalPiChildSessionServiceProvider","readSessionFastMode","DOOM_CHILD_SESSION_MCP_TOOL_SERVICE","DOOM_CHILD_SESSION_SERVICE","getAgentDir","ModelRuntime","path","connectDoomCordisHost"],"sources":["../../src/extensions/terminalChildSession.ts"],"sourcesContent":["import path from 'node:path';\n\nimport {\n DOOM_CHILD_SESSION_SERVICE,\n DOOM_CHILD_SESSION_MCP_TOOL_SERVICE,\n type DoomChildSessionMcpTool,\n} from '@agimon-ai/doompi-core/childSession';\nimport {\n connectDoomCordisHost,\n DOOM_CORDIS_SESSION_SERVICE,\n type DoomCordisSessionService,\n} from '@agimon-ai/doompi-core/cordisHost';\nimport { createTerminalPiChildSessionServiceProvider } from '@agimon-ai/doompi-core/terminalPiChildSessionService';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { Provider } from '@earendil-works/pi-ai';\nimport { getAgentDir, ModelRuntime, type ExtensionAPI, type ModelRegistry } from '@earendil-works/pi-coding-agent';\n\nimport { readSessionFastMode } from './fast';\n\nconst PACKAGE_SOURCE = '@agimon-ai/doompi/terminal-child-session';\n\n/**\n * Collect the providers registered in this process by Pi extensions.\n *\n * The child ModelRuntime is built from auth.json and models.json, so it only\n * knows providers that exist on disk. A custom provider contributed through\n * `pi.registerProvider()` lives solely in the host registry, and its stream\n * closures cannot be reconstructed from a file. Reading the live registry per\n * spawn keeps late registrations visible.\n */\nfunction registeredProviders(registry: ModelRegistry): readonly Provider[] {\n const providers: Provider[] = [];\n for (const id of registry.getRegisteredProviderIds()) {\n const provider = registry.getRegisteredNativeProvider(id) ?? registry.getProvider(id);\n if (provider !== undefined) providers.push(provider);\n }\n return providers;\n}\n\nfunction terminalChildSessionPlugin(cordis: Context, models: ModelRuntime, sessionsRoot: string): void {\n cordis.inject([DOOM_CORDIS_SESSION_SERVICE], (sessionContext) => {\n const session = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n const extensionContext = session.context;\n const childSessions = createTerminalPiChildSessionServiceProvider({\n cwd: extensionContext.cwd,\n sessionsRoot,\n models,\n providers: () => registeredProviders(extensionContext.modelRegistry),\n defaultModel: () => extensionContext.model,\n parentFastMode: () => {\n const currentSession = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n return readSessionFastMode(currentSession.context.sessionManager);\n },\n subscribeMcpTool: (listener) =>\n sessionContext.on('internal/service', (name) => {\n if (name === DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) listener();\n }),\n mcpTool: () => sessionContext.get(DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) as DoomChildSessionMcpTool | undefined,\n });\n sessionContext.provide(DOOM_CHILD_SESSION_SERVICE, childSessions.get());\n sessionContext.effect(() => () => childSessions.close(), `${PACKAGE_SOURCE}/lifetime`);\n });\n}\n\n/** Bind terminal Pi child ownership inside the core Cordis composition, before feature packages consume it. */\nexport async function terminalChildSessionExtension(pi: ExtensionAPI): Promise<void> {\n const agentDir = getAgentDir();\n const models = await ModelRuntime.create({\n authPath: path.join(agentDir, 'auth.json'),\n modelsPath: path.join(agentDir, 'models.json'),\n refreshOnCreate: false,\n });\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const sessionsRoot = path.join(agentDir, 'sessions');\n const fiber = connection.root.plugin((cordis) => terminalChildSessionPlugin(cordis, models, sessionsRoot));\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n try {\n await fiber;\n } catch (error) {\n await fiber.dispose();\n await connection.dispose();\n throw error;\n }\n}\n\nexport default terminalChildSessionExtension;\n"],"mappings":";;;;;;;;;;;;;AAmBA,MAAM,iBAAiB;;;;;;;;;;AAWvB,SAAS,oBAAoB,UAA8C;CACzE,MAAM,YAAwB,CAAC;CAC/B,KAAK,MAAM,MAAM,SAAS,yBAAyB,GAAG;EACpD,MAAM,WAAW,SAAS,4BAA4B,EAAE,KAAK,SAAS,YAAY,EAAE;EACpF,IAAI,aAAa,KAAA,GAAW,UAAU,KAAK,QAAQ;CACrD;CACA,OAAO;AACT;AAEA,SAAS,2BAA2B,QAAiB,QAAsB,cAA4B;CACrG,OAAO,OAAO,CAACA,kCAAAA,2BAA2B,IAAI,mBAAmB;EAE/D,MAAM,mBADU,eAAe,IAAIA,kCAAAA,2BACJ,CAAC,CAAC;EACjC,MAAM,iBAAA,GAAgBC,qDAAAA,4CAAAA,CAA4C;GAChE,KAAK,iBAAiB;GACtB;GACA;GACA,iBAAiB,oBAAoB,iBAAiB,aAAa;GACnE,oBAAoB,iBAAiB;GACrC,sBAAsB;IACpB,MAAM,iBAAiB,eAAe,IAAID,kCAAAA,2BAA2B;IACrE,OAAOE,wBAAAA,oBAAoB,eAAe,QAAQ,cAAc;GAClE;GACA,mBAAmB,aACjB,eAAe,GAAG,qBAAqB,SAAS;IAC9C,IAAI,SAASC,oCAAAA,qCAAqC,SAAS;GAC7D,CAAC;GACH,eAAe,eAAe,IAAIA,oCAAAA,mCAAmC;EACvE,CAAC;EACD,eAAe,QAAQC,oCAAAA,4BAA4B,cAAc,IAAI,CAAC;EACtE,eAAe,mBAAmB,cAAc,MAAM,GAAG,GAAG,eAAe,UAAU;CACvF,CAAC;AACH;;AAGA,eAAsB,8BAA8B,IAAiC;CACnF,MAAM,YAAA,GAAWC,gCAAAA,YAAAA,CAAY;CAC7B,MAAM,SAAS,MAAMC,gCAAAA,aAAa,OAAO;EACvC,UAAUC,UAAAA,QAAK,KAAK,UAAU,WAAW;EACzC,YAAYA,UAAAA,QAAK,KAAK,UAAU,aAAa;EAC7C,iBAAiB;CACnB,CAAC;CACD,MAAM,aAAa,OAAA,GAAMC,kCAAAA,sBAAAA,CAAsB,IAAI,cAAc;CACjE,MAAM,eAAeD,UAAAA,QAAK,KAAK,UAAU,UAAU;CACnD,MAAM,QAAQ,WAAW,KAAK,QAAQ,WAAW,2BAA2B,QAAQ,QAAQ,YAAY,CAAC;CACzG,IAAI;CACJ,GAAG,GACD,0BAEG,cAAc,YAAY;EACzB,IAAI;GACF,MAAM,MAAM,QAAQ;EACtB,UAAU;GACR,MAAM,WAAW,QAAQ;EAC3B;CACF,EAAA,CAAG,CACP;CACA,IAAI;EACF,MAAM;CACR,SAAS,OAAO;EACd,MAAM,MAAM,QAAQ;EACpB,MAAM,WAAW,QAAQ;EACzB,MAAM;CACR;AACF"}
1
+ {"version":3,"file":"terminalChildSession.cjs","names":["DOOM_CORDIS_SESSION_SERVICE","createTerminalPiChildSessionServiceProvider","readSessionFastMode","DOOM_CHILD_SESSION_MCP_TOOL_SERVICE","DOOM_CHILD_SESSION_HOOKS_SERVICE","DOOM_CHILD_SESSION_SERVICE","getAgentDir","ModelRuntime","path","connectDoomCordisHost"],"sources":["../../src/extensions/terminalChildSession.ts"],"sourcesContent":["import path from 'node:path';\n\nimport {\n DOOM_CHILD_SESSION_SERVICE,\n DOOM_CHILD_SESSION_MCP_TOOL_SERVICE,\n DOOM_CHILD_SESSION_HOOKS_SERVICE,\n type DoomChildSessionHooks,\n type DoomChildSessionMcpTool,\n} from '@agimon-ai/doompi-core/childSession';\nimport {\n connectDoomCordisHost,\n DOOM_CORDIS_SESSION_SERVICE,\n type DoomCordisSessionService,\n} from '@agimon-ai/doompi-core/cordisHost';\nimport { createTerminalPiChildSessionServiceProvider } from '@agimon-ai/doompi-core/terminalPiChildSessionService';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { Provider } from '@earendil-works/pi-ai';\nimport { getAgentDir, ModelRuntime, type ExtensionAPI, type ModelRegistry } from '@earendil-works/pi-coding-agent';\n\nimport { readSessionFastMode } from './fast';\n\nconst PACKAGE_SOURCE = '@agimon-ai/doompi/terminal-child-session';\n\n/**\n * Collect the providers registered in this process by Pi extensions.\n *\n * The child ModelRuntime is built from auth.json and models.json, so it only\n * knows providers that exist on disk. A custom provider contributed through\n * `pi.registerProvider()` lives solely in the host registry, and its stream\n * closures cannot be reconstructed from a file. Reading the live registry per\n * spawn keeps late registrations visible.\n */\nfunction registeredProviders(registry: ModelRegistry): readonly Provider[] {\n const providers: Provider[] = [];\n for (const id of registry.getRegisteredProviderIds()) {\n const provider = registry.getRegisteredNativeProvider(id) ?? registry.getProvider(id);\n if (provider !== undefined) providers.push(provider);\n }\n return providers;\n}\n\nfunction terminalChildSessionPlugin(cordis: Context, models: ModelRuntime, sessionsRoot: string): void {\n cordis.inject([DOOM_CORDIS_SESSION_SERVICE], (sessionContext) => {\n const session = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n const extensionContext = session.context;\n const childSessions = createTerminalPiChildSessionServiceProvider({\n cwd: extensionContext.cwd,\n sessionsRoot,\n models,\n providers: () => registeredProviders(extensionContext.modelRegistry),\n defaultModel: () => extensionContext.model,\n parentFastMode: () => {\n const currentSession = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n return readSessionFastMode(currentSession.context.sessionManager);\n },\n subscribeMcpTool: (listener) =>\n sessionContext.on('internal/service', (name) => {\n if (name === DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) listener();\n }),\n hooks: () => sessionContext.get(DOOM_CHILD_SESSION_HOOKS_SERVICE) as DoomChildSessionHooks | undefined,\n mcpTool: () => sessionContext.get(DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) as DoomChildSessionMcpTool | undefined,\n });\n sessionContext.provide(DOOM_CHILD_SESSION_SERVICE, childSessions.get());\n sessionContext.effect(() => () => childSessions.close(), `${PACKAGE_SOURCE}/lifetime`);\n });\n}\n\n/** Bind terminal Pi child ownership inside the core Cordis composition, before feature packages consume it. */\nexport async function terminalChildSessionExtension(pi: ExtensionAPI): Promise<void> {\n const agentDir = getAgentDir();\n const models = await ModelRuntime.create({\n authPath: path.join(agentDir, 'auth.json'),\n modelsPath: path.join(agentDir, 'models.json'),\n refreshOnCreate: false,\n });\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const sessionsRoot = path.join(agentDir, 'sessions');\n const fiber = connection.root.plugin((cordis) => terminalChildSessionPlugin(cordis, models, sessionsRoot));\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n try {\n await fiber;\n } catch (error) {\n await fiber.dispose();\n await connection.dispose();\n throw error;\n }\n}\n\nexport default terminalChildSessionExtension;\n"],"mappings":";;;;;;;;;;;;;AAqBA,MAAM,iBAAiB;;;;;;;;;;AAWvB,SAAS,oBAAoB,UAA8C;CACzE,MAAM,YAAwB,CAAC;CAC/B,KAA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D,UAAAA,QAAK,KAAK,UAAU,UAAU;CACnD,MAAM,QAAQ,WAAW,KAAK,QAAQ,WAAW,2BAA2B,QAAQ,QAAQ,YAAY,CAAC;CACzG,IAAI;CACJ,GAAG,GACD,0BAEG,cAAc,YAAY;EACzB,IAAI;GACF,MAAM,MAAM,QAAQ;EACtB,UAAU;GACR,MAAM,WAAW,QAAQ;EAC3B;CACF,EAAA,CAAG,CACP;CACA,IAAI;EACF,MAAM;CACR,SAAS,OAAO;EACd,MAAM,MAAM,QAAQ;EACpB,MAAM,WAAW,QAAQ;EACzB,MAAM;CACR;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"terminalChildSession.d.mts","names":[],"sources":["../../src/extensions/terminalChildSession.ts"],"mappings":";;;wBAiEsB,8BAA8B,IAAI,eAAe"}
1
+ {"version":3,"file":"terminalChildSession.d.mts","names":[],"sources":["../../src/extensions/terminalChildSession.ts"],"mappings":";;;wBAoEsB,8BAA8B,IAAI,eAAe"}
@@ -2,7 +2,7 @@ import { readSessionFastMode } from "./fast.mjs";
2
2
  import path from "node:path";
3
3
  import { ModelRuntime, getAgentDir } from "@earendil-works/pi-coding-agent";
4
4
  import { DOOM_CORDIS_SESSION_SERVICE, connectDoomCordisHost } from "@agimon-ai/doompi-core/cordisHost";
5
- import { DOOM_CHILD_SESSION_MCP_TOOL_SERVICE, DOOM_CHILD_SESSION_SERVICE } from "@agimon-ai/doompi-core/childSession";
5
+ import { DOOM_CHILD_SESSION_HOOKS_SERVICE, DOOM_CHILD_SESSION_MCP_TOOL_SERVICE, DOOM_CHILD_SESSION_SERVICE } from "@agimon-ai/doompi-core/childSession";
6
6
  import { createTerminalPiChildSessionServiceProvider } from "@agimon-ai/doompi-core/terminalPiChildSessionService";
7
7
  //#region src/extensions/terminalChildSession.ts
8
8
  const PACKAGE_SOURCE = "@agimon-ai/doompi/terminal-child-session";
@@ -39,6 +39,7 @@ function terminalChildSessionPlugin(cordis, models, sessionsRoot) {
39
39
  subscribeMcpTool: (listener) => sessionContext.on("internal/service", (name) => {
40
40
  if (name === DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) listener();
41
41
  }),
42
+ hooks: () => sessionContext.get(DOOM_CHILD_SESSION_HOOKS_SERVICE),
42
43
  mcpTool: () => sessionContext.get(DOOM_CHILD_SESSION_MCP_TOOL_SERVICE)
43
44
  });
44
45
  sessionContext.provide(DOOM_CHILD_SESSION_SERVICE, childSessions.get());
@@ -1 +1 @@
1
- {"version":3,"file":"terminalChildSession.mjs","names":[],"sources":["../../src/extensions/terminalChildSession.ts"],"sourcesContent":["import path from 'node:path';\n\nimport {\n DOOM_CHILD_SESSION_SERVICE,\n DOOM_CHILD_SESSION_MCP_TOOL_SERVICE,\n type DoomChildSessionMcpTool,\n} from '@agimon-ai/doompi-core/childSession';\nimport {\n connectDoomCordisHost,\n DOOM_CORDIS_SESSION_SERVICE,\n type DoomCordisSessionService,\n} from '@agimon-ai/doompi-core/cordisHost';\nimport { createTerminalPiChildSessionServiceProvider } from '@agimon-ai/doompi-core/terminalPiChildSessionService';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { Provider } from '@earendil-works/pi-ai';\nimport { getAgentDir, ModelRuntime, type ExtensionAPI, type ModelRegistry } from '@earendil-works/pi-coding-agent';\n\nimport { readSessionFastMode } from './fast';\n\nconst PACKAGE_SOURCE = '@agimon-ai/doompi/terminal-child-session';\n\n/**\n * Collect the providers registered in this process by Pi extensions.\n *\n * The child ModelRuntime is built from auth.json and models.json, so it only\n * knows providers that exist on disk. A custom provider contributed through\n * `pi.registerProvider()` lives solely in the host registry, and its stream\n * closures cannot be reconstructed from a file. Reading the live registry per\n * spawn keeps late registrations visible.\n */\nfunction registeredProviders(registry: ModelRegistry): readonly Provider[] {\n const providers: Provider[] = [];\n for (const id of registry.getRegisteredProviderIds()) {\n const provider = registry.getRegisteredNativeProvider(id) ?? registry.getProvider(id);\n if (provider !== undefined) providers.push(provider);\n }\n return providers;\n}\n\nfunction terminalChildSessionPlugin(cordis: Context, models: ModelRuntime, sessionsRoot: string): void {\n cordis.inject([DOOM_CORDIS_SESSION_SERVICE], (sessionContext) => {\n const session = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n const extensionContext = session.context;\n const childSessions = createTerminalPiChildSessionServiceProvider({\n cwd: extensionContext.cwd,\n sessionsRoot,\n models,\n providers: () => registeredProviders(extensionContext.modelRegistry),\n defaultModel: () => extensionContext.model,\n parentFastMode: () => {\n const currentSession = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n return readSessionFastMode(currentSession.context.sessionManager);\n },\n subscribeMcpTool: (listener) =>\n sessionContext.on('internal/service', (name) => {\n if (name === DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) listener();\n }),\n mcpTool: () => sessionContext.get(DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) as DoomChildSessionMcpTool | undefined,\n });\n sessionContext.provide(DOOM_CHILD_SESSION_SERVICE, childSessions.get());\n sessionContext.effect(() => () => childSessions.close(), `${PACKAGE_SOURCE}/lifetime`);\n });\n}\n\n/** Bind terminal Pi child ownership inside the core Cordis composition, before feature packages consume it. */\nexport async function terminalChildSessionExtension(pi: ExtensionAPI): Promise<void> {\n const agentDir = getAgentDir();\n const models = await ModelRuntime.create({\n authPath: path.join(agentDir, 'auth.json'),\n modelsPath: path.join(agentDir, 'models.json'),\n refreshOnCreate: false,\n });\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const sessionsRoot = path.join(agentDir, 'sessions');\n const fiber = connection.root.plugin((cordis) => terminalChildSessionPlugin(cordis, models, sessionsRoot));\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n try {\n await fiber;\n } catch (error) {\n await fiber.dispose();\n await connection.dispose();\n throw error;\n }\n}\n\nexport default terminalChildSessionExtension;\n"],"mappings":";;;;;;;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AC;CACzG,IAAI;CACJ,GAAG,GACD,0BAEG,cAAc,YAAY;EACzB,IAAI;GACF,MAAM,MAAM,QAAQ;EACtB,UAAU;GACR,MAAM,WAAW,QAAQ;EAC3B;CACF,EAAA,CAAG,CACP;CACA,IAAI;EACF,MAAM;CACR,SAAS,OAAO;EACd,MAAM,MAAM,QAAQ;EACpB,MAAM,WAAW,QAAQ;EACzB,MAAM;CACR;AACF"}
1
+ {"version":3,"file":"terminalChildSession.mjs","names":[],"sources":["../../src/extensions/terminalChildSession.ts"],"sourcesContent":["import path from 'node:path';\n\nimport {\n DOOM_CHILD_SESSION_SERVICE,\n DOOM_CHILD_SESSION_MCP_TOOL_SERVICE,\n DOOM_CHILD_SESSION_HOOKS_SERVICE,\n type DoomChildSessionHooks,\n type DoomChildSessionMcpTool,\n} from '@agimon-ai/doompi-core/childSession';\nimport {\n connectDoomCordisHost,\n DOOM_CORDIS_SESSION_SERVICE,\n type DoomCordisSessionService,\n} from '@agimon-ai/doompi-core/cordisHost';\nimport { createTerminalPiChildSessionServiceProvider } from '@agimon-ai/doompi-core/terminalPiChildSessionService';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { Provider } from '@earendil-works/pi-ai';\nimport { getAgentDir, ModelRuntime, type ExtensionAPI, type ModelRegistry } from '@earendil-works/pi-coding-agent';\n\nimport { readSessionFastMode } from './fast';\n\nconst PACKAGE_SOURCE = '@agimon-ai/doompi/terminal-child-session';\n\n/**\n * Collect the providers registered in this process by Pi extensions.\n *\n * The child ModelRuntime is built from auth.json and models.json, so it only\n * knows providers that exist on disk. A custom provider contributed through\n * `pi.registerProvider()` lives solely in the host registry, and its stream\n * closures cannot be reconstructed from a file. Reading the live registry per\n * spawn keeps late registrations visible.\n */\nfunction registeredProviders(registry: ModelRegistry): readonly Provider[] {\n const providers: Provider[] = [];\n for (const id of registry.getRegisteredProviderIds()) {\n const provider = registry.getRegisteredNativeProvider(id) ?? registry.getProvider(id);\n if (provider !== undefined) providers.push(provider);\n }\n return providers;\n}\n\nfunction terminalChildSessionPlugin(cordis: Context, models: ModelRuntime, sessionsRoot: string): void {\n cordis.inject([DOOM_CORDIS_SESSION_SERVICE], (sessionContext) => {\n const session = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n const extensionContext = session.context;\n const childSessions = createTerminalPiChildSessionServiceProvider({\n cwd: extensionContext.cwd,\n sessionsRoot,\n models,\n providers: () => registeredProviders(extensionContext.modelRegistry),\n defaultModel: () => extensionContext.model,\n parentFastMode: () => {\n const currentSession = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n return readSessionFastMode(currentSession.context.sessionManager);\n },\n subscribeMcpTool: (listener) =>\n sessionContext.on('internal/service', (name) => {\n if (name === DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) listener();\n }),\n hooks: () => sessionContext.get(DOOM_CHILD_SESSION_HOOKS_SERVICE) as DoomChildSessionHooks | undefined,\n mcpTool: () => sessionContext.get(DOOM_CHILD_SESSION_MCP_TOOL_SERVICE) as DoomChildSessionMcpTool | undefined,\n });\n sessionContext.provide(DOOM_CHILD_SESSION_SERVICE, childSessions.get());\n sessionContext.effect(() => () => childSessions.close(), `${PACKAGE_SOURCE}/lifetime`);\n });\n}\n\n/** Bind terminal Pi child ownership inside the core Cordis composition, before feature packages consume it. */\nexport async function terminalChildSessionExtension(pi: ExtensionAPI): Promise<void> {\n const agentDir = getAgentDir();\n const models = await ModelRuntime.create({\n authPath: path.join(agentDir, 'auth.json'),\n modelsPath: path.join(agentDir, 'models.json'),\n refreshOnCreate: false,\n });\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const sessionsRoot = path.join(agentDir, 'sessions');\n const fiber = connection.root.plugin((cordis) => terminalChildSessionPlugin(cordis, models, sessionsRoot));\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n try {\n await fiber;\n } catch (error) {\n await fiber.dispose();\n await connection.dispose();\n throw error;\n }\n}\n\nexport default terminalChildSessionExtension;\n"],"mappings":";;;;;;;AAqBA,MAAM,iBAAiB;;;;;;;;;;AAWvB,SAAS,oBAAoB,UAA8C;CACzE,MAAM,YAAwB,CAAC;CAC/B,KAAK,MAAM,MAAM,SAAS,yBAAyB,GAAG;EACpD,MAAM,WAAW,SAAS,4BAA4B,EAAE,KAAK,SAAS,YAAY,EAAE;EACpF,IAAI,aAAa,KAAA,GAAW,UAAU,KAAK,QAAQ;CACrD;CACA,OAAO;AACT;AAEA,SAAS,2BAA2B,QAAiB,QAAsB,cAA4B;CACrG,OAAO,OAAO,CAAC,2BAA2B,IAAI,mBAAmB;EAE/D,MAAM,mBADU,eAAe,IAAI,2BACJ,CAAC,CAAC;EACjC,MAAM,gBAAgB,4CAA4C;GAChE,KAAK,iBAAiB;GACtB;GACA;GACA,iBAAiB,oBAAoB,iBAAiB,aAAa;GACnE,oBAAoB,iBAAiB;GACrC,sBAAsB;IACpB,MAAM,iBAAiB,eAAe,IAAI,2BAA2B;IACrE,OAAO,oBAAoB,eAAe,QAAQ,cAAc;GAClE;GACA,mBAAmB,aACjB,eAAe,GAAG,qBAAqB,SAAS;IAC9C,IAAI,SAAS,qCAAqC,SAAS;GAC7D,CAAC;GACH,aAAa,eAAe,IAAI,gCAAgC;GAChE,eAAe,eAAe,IAAI,mCAAmC;EACvE,CAAC;EACD,eAAe,QAAQ,4BAA4B,cAAc,IAAI,CAAC;EACtE,eAAe,mBAAmB,cAAc,MAAM,GAAG,GAAG,eAAe,UAAU;CACvF,CAAC;AACH;;AAGA,eAAsB,8BAA8B,IAAiC;CACnF,MAAM,WAAW,YAAY;CAC7B,MAAM,SAAS,MAAM,aAAa,OAAO;EACvC,UAAU,KAAK,KAAK,UAAU,WAAW;EACzC,YAAY,KAAK,KAAK,UAAU,aAAa;EAC7C,iBAAiB;CACnB,CAAC;CACD,MAAM,aAAa,MAAM,sBAAsB,IAAI,cAAc;CACjE,MAAM,eAAe,KAAK,KAAK,UAAU,UAAU;CACnD,MAAM,QAAQ,WAAW,KAAK,QAAQ,WAAW,2BAA2B,QAAQ,QAAQ,YAAY,CAAC;CACzG,IAAI;CACJ,GAAG,GACD,0BAEG,cAAc,YAAY;EACzB,IAAI;GACF,MAAM,MAAM,QAAQ;EACtB,UAAU;GACR,MAAM,WAAW,QAAQ;EAC3B;CACF,EAAA,CAAG,CACP;CACA,IAAI;EACF,MAAM;CACR,SAAS,OAAO;EACd,MAAM,MAAM,QAAQ;EACpB,MAAM,WAAW,QAAQ;EACzB,MAAM;CACR;AACF"}
@@ -0,0 +1,95 @@
1
+ const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
2
+ const require_index = require("../../compiler/index.cjs");
3
+ let node_fs = require("node:fs");
4
+ node_fs = require_runtime.__toESM(node_fs, 1);
5
+ let node_path = require("node:path");
6
+ node_path = require_runtime.__toESM(node_path, 1);
7
+ let _agimon_ai_doompi_core_runtimeJson = require("@agimon-ai/doompi-core/runtimeJson");
8
+ let _agimon_ai_doompi_core_moduleResolution = require("@agimon-ai/doompi-core/moduleResolution");
9
+ let node_url = require("node:url");
10
+ let node_crypto = require("node:crypto");
11
+ node_crypto = require_runtime.__toESM(node_crypto, 1);
12
+ let _agimon_ai_doompi_config_layeredConfig = require("@agimon-ai/doompi-config/layeredConfig");
13
+ let yaml = require("yaml");
14
+ //#region src/builders/hooks/index.ts
15
+ const HOOK_MODULES_FILE = "hook-modules.json";
16
+ /** Core plus the union of every mode's selection. An unset selection admits all. */
17
+ function requiredHookGroups(config) {
18
+ const groups = /* @__PURE__ */ new Set();
19
+ for (const mode of Object.values(config.majorMode)) {
20
+ const layers = mode.layers.map((name) => config.layers[name]);
21
+ if (layers.length === 0 || layers.some((layer) => layer?.hookGroups === void 0)) return void 0;
22
+ for (const layer of layers) for (const group of layer.hookGroups ?? []) groups.add(group);
23
+ }
24
+ return groups;
25
+ }
26
+ /** Bundles hook exports without importing or invoking repository code. */
27
+ async function syncHookModules(options) {
28
+ const hasModuleRows = (0, _agimon_ai_doompi_config_layeredConfig.doomConfigCandidates)("hooks.yaml", options.repoRoot, options.homeDirectory).some((candidate) => {
29
+ if (!node_fs.default.existsSync(candidate.filePath)) return false;
30
+ const document = (0, yaml.parse)(node_fs.default.readFileSync(candidate.filePath, "utf8"));
31
+ if (!(0, _agimon_ai_doompi_core_runtimeJson.isRecord)(document) || !(0, _agimon_ai_doompi_core_runtimeJson.isRecord)(document.groups)) return false;
32
+ return Object.values(document.groups).some((group) => (0, _agimon_ai_doompi_core_runtimeJson.isRecord)(group) && Array.isArray(group.hooks) && group.hooks.some((row) => (0, _agimon_ai_doompi_core_runtimeJson.isRecord)(row) && (0, _agimon_ai_doompi_core_runtimeJson.isRecord)(row.pi) && "module" in row.pi));
33
+ });
34
+ const parserEntry = (0, _agimon_ai_doompi_core_moduleResolution.optionalPackageEntry)("@agimon-ai/doompi-hook", (0, node_url.pathToFileURL)(node_path.default.join(options.repoRoot, "package.json")).href) ?? (0, _agimon_ai_doompi_core_moduleResolution.optionalPackageEntry)("@agimon-ai/doompi-hook", require("url").pathToFileURL(__filename).href);
35
+ if (hasModuleRows && !parserEntry) throw new Error("Hook module rows require @agimon-ai/doompi-hook. Install it in the repository or select a layer that provides it, then run doompi sync.");
36
+ const parser = hasModuleRows && parserEntry ? await import((0, node_url.pathToFileURL)(parserEntry).href) : void 0;
37
+ const read = hasModuleRows && parser ? await parser.createHookDocumentReader({
38
+ homeDirectory: options.homeDirectory,
39
+ warn: () => void 0
40
+ }).registry(options.repoRoot) : { entries: [] };
41
+ if ("failure" in read && read.failure) throw new Error(read.failure.message);
42
+ const groups = requiredHookGroups(options.config);
43
+ const sources = /* @__PURE__ */ new Map();
44
+ for (const row of read.entries) {
45
+ if (!row.module || !row.core && groups && !groups.has(row.groupId)) continue;
46
+ const rows = sources.get(row.module) ?? [];
47
+ rows.push({
48
+ registry: row.registryId,
49
+ groupId: row.groupId,
50
+ rowId: row.rowId,
51
+ event: row.event
52
+ });
53
+ sources.set(row.module, rows);
54
+ }
55
+ const cache = node_path.default.join(options.directory, "cache");
56
+ const outputDirectory = node_path.default.join(options.directory, "dist", "hooks");
57
+ const modules = [];
58
+ for (const [source, rows] of sources) {
59
+ const compileOptions = {
60
+ repositoryRoot: options.repoRoot,
61
+ outputDirectory,
62
+ outputName: `${node_crypto.default.createHash("sha256").update(source).digest("hex")}.mjs`,
63
+ sharedCacheDirectory: options.sharedCacheDirectory
64
+ };
65
+ try {
66
+ const artifact = await require_index.compileExtensionModule(source, cache, compileOptions);
67
+ const receipt = JSON.parse(await node_fs.default.promises.readFile(require_index.extensionModuleManifestPath(source, cache, compileOptions), "utf8"));
68
+ modules.push({
69
+ source,
70
+ artifact,
71
+ receipt,
72
+ rows
73
+ });
74
+ } catch (cause) {
75
+ const attribution = rows.map((row) => `${row.registry}: group ${row.groupId}, row ${row.rowId}, event ${row.event}`).join("; ");
76
+ throw new Error(`Hook module compilation failed (${attribution}): ${source}`, { cause });
77
+ }
78
+ }
79
+ await node_fs.default.promises.mkdir(outputDirectory, {
80
+ recursive: true,
81
+ mode: 448
82
+ });
83
+ const file = node_path.default.join(outputDirectory, HOOK_MODULES_FILE);
84
+ await node_fs.default.promises.writeFile(file, `${JSON.stringify({
85
+ version: 1,
86
+ modules
87
+ }, null, 2)}\n`, { mode: 384 });
88
+ return { file };
89
+ }
90
+ //#endregion
91
+ exports.HOOK_MODULES_FILE = HOOK_MODULES_FILE;
92
+ exports.requiredHookGroups = requiredHookGroups;
93
+ exports.syncHookModules = syncHookModules;
94
+
95
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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\n/** The optional hook package owns parsing; the CLI only consumes this capability. */\ninterface HookParserModule {\n createHookDocumentReader(options: { homeDirectory: string; warn: (message: string) => void }): {\n registry(repoRoot: string): Promise<{\n entries: Array<{\n module?: string;\n core: boolean;\n registryId: string;\n groupId: string;\n rowId: string;\n event: string;\n }>;\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\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 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 const parser =\n hasModuleRows && parserEntry ? ((await import(pathToFileURL(parserEntry).href)) as HookParserModule) : undefined;\n const read =\n hasModuleRows && 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;;AAoBjC,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;;AAGA,eAAsB,gBAAgB,SAMR;CAI5B,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,CAAS,KAAK,KACd,MAAM,QAAQ,MAAM,KAAK,KACzB,MAAM,MAAM,MAAM,SAAA,GAAiBA,mCAAAA,SAAAA,CAAS,GAAG,MAAA,GAAKA,mCAAAA,SAAAA,CAAS,IAAI,EAAE,KA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,CAAC;CACjB,KAAK,MAAM,CAAC,QAAQ,SAAS,SAAS;EACpC,MAAM,iBAAiB;GACrB,gBAAgB,QAAQ;GACxB;GACA,YAAY,GAAGC,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,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"}
@@ -0,0 +1,89 @@
1
+ import { compileExtensionModule, extensionModuleManifestPath } from "../../compiler/index.mjs";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { isRecord } from "@agimon-ai/doompi-core/runtimeJson";
5
+ import { optionalPackageEntry } from "@agimon-ai/doompi-core/moduleResolution";
6
+ import { pathToFileURL } from "node:url";
7
+ import crypto from "node:crypto";
8
+ import { doomConfigCandidates } from "@agimon-ai/doompi-config/layeredConfig";
9
+ import { parse } from "yaml";
10
+ //#region src/builders/hooks/index.ts
11
+ const HOOK_MODULES_FILE = "hook-modules.json";
12
+ /** Core plus the union of every mode's selection. An unset selection admits all. */
13
+ function requiredHookGroups(config) {
14
+ const groups = /* @__PURE__ */ new Set();
15
+ for (const mode of Object.values(config.majorMode)) {
16
+ const layers = mode.layers.map((name) => config.layers[name]);
17
+ if (layers.length === 0 || layers.some((layer) => layer?.hookGroups === void 0)) return void 0;
18
+ for (const layer of layers) for (const group of layer.hookGroups ?? []) groups.add(group);
19
+ }
20
+ return groups;
21
+ }
22
+ /** Bundles hook exports without importing or invoking repository code. */
23
+ async function syncHookModules(options) {
24
+ const hasModuleRows = doomConfigCandidates("hooks.yaml", options.repoRoot, options.homeDirectory).some((candidate) => {
25
+ if (!fs.existsSync(candidate.filePath)) return false;
26
+ const document = parse(fs.readFileSync(candidate.filePath, "utf8"));
27
+ if (!isRecord(document) || !isRecord(document.groups)) return false;
28
+ return Object.values(document.groups).some((group) => isRecord(group) && Array.isArray(group.hooks) && group.hooks.some((row) => isRecord(row) && isRecord(row.pi) && "module" in row.pi));
29
+ });
30
+ const parserEntry = optionalPackageEntry("@agimon-ai/doompi-hook", pathToFileURL(path.join(options.repoRoot, "package.json")).href) ?? optionalPackageEntry("@agimon-ai/doompi-hook", import.meta.url);
31
+ if (hasModuleRows && !parserEntry) throw new Error("Hook module rows require @agimon-ai/doompi-hook. Install it in the repository or select a layer that provides it, then run doompi sync.");
32
+ const parser = hasModuleRows && parserEntry ? await import(pathToFileURL(parserEntry).href) : void 0;
33
+ const read = hasModuleRows && parser ? await parser.createHookDocumentReader({
34
+ homeDirectory: options.homeDirectory,
35
+ warn: () => void 0
36
+ }).registry(options.repoRoot) : { entries: [] };
37
+ if ("failure" in read && read.failure) throw new Error(read.failure.message);
38
+ const groups = requiredHookGroups(options.config);
39
+ const sources = /* @__PURE__ */ new Map();
40
+ for (const row of read.entries) {
41
+ if (!row.module || !row.core && groups && !groups.has(row.groupId)) continue;
42
+ const rows = sources.get(row.module) ?? [];
43
+ rows.push({
44
+ registry: row.registryId,
45
+ groupId: row.groupId,
46
+ rowId: row.rowId,
47
+ event: row.event
48
+ });
49
+ sources.set(row.module, rows);
50
+ }
51
+ const cache = path.join(options.directory, "cache");
52
+ const outputDirectory = path.join(options.directory, "dist", "hooks");
53
+ const modules = [];
54
+ for (const [source, rows] of sources) {
55
+ const compileOptions = {
56
+ repositoryRoot: options.repoRoot,
57
+ outputDirectory,
58
+ outputName: `${crypto.createHash("sha256").update(source).digest("hex")}.mjs`,
59
+ sharedCacheDirectory: options.sharedCacheDirectory
60
+ };
61
+ try {
62
+ const artifact = await compileExtensionModule(source, cache, compileOptions);
63
+ const receipt = JSON.parse(await fs.promises.readFile(extensionModuleManifestPath(source, cache, compileOptions), "utf8"));
64
+ modules.push({
65
+ source,
66
+ artifact,
67
+ receipt,
68
+ rows
69
+ });
70
+ } catch (cause) {
71
+ const attribution = rows.map((row) => `${row.registry}: group ${row.groupId}, row ${row.rowId}, event ${row.event}`).join("; ");
72
+ throw new Error(`Hook module compilation failed (${attribution}): ${source}`, { cause });
73
+ }
74
+ }
75
+ await fs.promises.mkdir(outputDirectory, {
76
+ recursive: true,
77
+ mode: 448
78
+ });
79
+ const file = path.join(outputDirectory, HOOK_MODULES_FILE);
80
+ await fs.promises.writeFile(file, `${JSON.stringify({
81
+ version: 1,
82
+ modules
83
+ }, null, 2)}\n`, { mode: 384 });
84
+ return { file };
85
+ }
86
+ //#endregion
87
+ export { HOOK_MODULES_FILE, requiredHookGroups, syncHookModules };
88
+
89
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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\n/** The optional hook package owns parsing; the CLI only consumes this capability. */\ninterface HookParserModule {\n createHookDocumentReader(options: { homeDirectory: string; warn: (message: string) => void }): {\n registry(repoRoot: string): Promise<{\n entries: Array<{\n module?: string;\n core: boolean;\n registryId: string;\n groupId: string;\n rowId: string;\n event: string;\n }>;\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\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 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 const parser =\n hasModuleRows && parserEntry ? ((await import(pathToFileURL(parserEntry).href)) as HookParserModule) : undefined;\n const read =\n hasModuleRows && 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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,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,5 +1,5 @@
1
1
  const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
2
- require("../../composition/harnessState/index.cjs");
2
+ const require_index = require("../../composition/harnessState/index.cjs");
3
3
  const require_index$1 = require("../../composition/repository/index.cjs");
4
4
  const require_index$2 = require("../../composition/syncState/index.cjs");
5
5
  const require_index$3 = require("../cli/bootstrapLocator/index.cjs");
@@ -547,6 +547,8 @@ async function runServerRuntime(options, runtime) {
547
547
  };
548
548
  const piBootstrap = require_index$3.readRegisteredBootstrapStatus(registration, void 0, homeDirectory);
549
549
  if (!piBootstrap.fresh || piBootstrap.bootstrap === void 0) throw new Error(`The admitted DoomPi bootstrap for generation '${registration.generation}' is unavailable.`);
550
+ const hookModules = require_index$2.readRegisteredSyncState(registration, homeDirectory).fileState.hookModules;
551
+ require_index.updateHarnessState({ hookModules }, context.environment);
550
552
  return {
551
553
  cwd: policyOptions.cwd,
552
554
  repoRoot: policyOptions.repoRoot,