@agimon-ai/po-hook 0.0.0-alpha.1 → 0.0.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,7 +34,7 @@ groups:
34
34
 
35
35
  Each `pi` binding declares exactly one of `command` or `module`. Module paths resolve relative to the declaring repository root or personal `~/.po` root, not the directory containing `hooks.yaml`. Personal configuration is `~/.po/hooks.yaml`; repository configuration is `<repo>/.po/hooks.yaml`. A repository group replaces the personal group of the same ID completely.
36
36
 
37
- The distribution activates this package by default through the `default.packages` list written by `po init` or `dpi init`. Keep it there, or declare it in a selected layer. Layers only declare the `hookGroups` to select; they do not define hook implementations:
37
+ The distribution activates this package by default through the `default.packages` list written by `po init`. Keep it there, or declare it in a selected layer. Layers only declare the `hookGroups` to select; they do not define hook implementations:
38
38
 
39
39
  ```yaml
40
40
  # .po/modes.yaml
@@ -52,9 +52,9 @@ layers:
52
52
  Use the dependency-free public authoring subpath, not the extension/runtime entry:
53
53
 
54
54
  ```ts
55
- import { defineDoomHook } from '@agimon-ai/po-hook/authoring';
55
+ import { definePoHook } from '@agimon-ai/po-hook/authoring';
56
56
 
57
- export default defineDoomHook({
57
+ export default definePoHook({
58
58
  setup(ctx) {
59
59
  let calls = 0;
60
60
  return {
@@ -72,7 +72,7 @@ export default defineDoomHook({
72
72
  });
73
73
  ```
74
74
 
75
- `defineDoomHook` checks the contract while preserving inference. The default export must have `setup(ctx)`, returning handlers synchronously or asynchronously. Only handlers selected by registry rows run:
75
+ `definePoHook` checks the contract while preserving inference. The default export must have `setup(ctx)`, returning handlers synchronously or asynchronously. Only handlers selected by registry rows run:
76
76
 
77
77
  | Registry event | Native module handler | Result |
78
78
  | -------------- | --------------------------- | ------------------------------------------------ |
@@ -134,7 +134,7 @@ Native children run only `PreToolUse` and `PostToolUse`. Registry and plugin too
134
134
 
135
135
  After changing a module or its imports, registry, or mode selection:
136
136
 
137
- 1. Run `po sync` (or `dpi sync`). Sync compiles core modules plus the union of mode-selected groups; if any mode leaves selection unset, it compiles all groups.
137
+ 1. Run `po sync` (or `po sync`). Sync compiles core modules plus the union of mode-selected groups; if any mode leaves selection unset, it compiles all groups.
138
138
  2. Run `po sync --check` to check drift.
139
139
  3. Reopen headless sessions to adopt the published generation, then exercise the intended events.
140
140
 
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/services/hookAuthoring/index.ts
3
3
  /** Preserve the author's inferred module type while checking the hook contract. */
4
- function defineDoomHook(module) {
4
+ function definePoHook(module) {
5
5
  return module;
6
6
  }
7
7
  //#endregion
8
- exports.defineDoomHook = defineDoomHook;
8
+ exports.definePoHook = definePoHook;
9
9
 
10
10
  //# sourceMappingURL=authoring.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"authoring.cjs","names":[],"sources":["../src/services/hookAuthoring/index.ts"],"sourcesContent":["import type { HookModule } from '../../types/hookModule';\n\n/** Preserve the author's inferred module type while checking the hook contract. */\nexport function defineDoomHook<T extends HookModule>(module: T): T {\n return module;\n}\n"],"mappings":";;;AAGA,SAAgB,eAAqC,QAAc;CACjE,OAAO;AACT"}
1
+ {"version":3,"file":"authoring.cjs","names":[],"sources":["../src/services/hookAuthoring/index.ts"],"sourcesContent":["import type { HookModule } from '../../types/hookModule';\n\n/** Preserve the author's inferred module type while checking the hook contract. */\nexport function definePoHook<T extends HookModule>(module: T): T {\n return module;\n}\n"],"mappings":";;;AAGA,SAAgB,aAAmC,QAAc;CAC/D,OAAO;AACT"}
@@ -1,7 +1,7 @@
1
1
  import { a as HookModule, i as HookHandlers, l as JsonValue, n as Awaitable, o as HookModuleDescriptor, r as HookContext, t as AgentSettledEvent } from "./hookModule-f-HwSbmi.mjs";
2
2
  //#region src/services/hookAuthoring/index.d.ts
3
3
  /** Preserve the author's inferred module type while checking the hook contract. */
4
- export declare function defineDoomHook<T extends HookModule>(module: T): T;
4
+ export declare function definePoHook<T extends HookModule>(module: T): T;
5
5
  //#endregion
6
6
  export type { AgentSettledEvent, Awaitable, HookContext, HookHandlers, HookModule, HookModuleDescriptor, JsonValue };
7
7
  //# sourceMappingURL=authoring.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authoring.d.mts","names":[],"sources":["../src/services/hookAuthoring/index.ts"],"mappings":";;;wBAGgB,eAAe,UAAU,YAAY,QAAQ,IAAI"}
1
+ {"version":3,"file":"authoring.d.mts","names":[],"sources":["../src/services/hookAuthoring/index.ts"],"mappings":";;;wBAGgB,aAAa,UAAU,YAAY,QAAQ,IAAI"}
@@ -1,9 +1,9 @@
1
1
  //#region src/services/hookAuthoring/index.ts
2
2
  /** Preserve the author's inferred module type while checking the hook contract. */
3
- function defineDoomHook(module) {
3
+ function definePoHook(module) {
4
4
  return module;
5
5
  }
6
6
  //#endregion
7
- export { defineDoomHook };
7
+ export { definePoHook };
8
8
 
9
9
  //# sourceMappingURL=authoring.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"authoring.mjs","names":[],"sources":["../src/services/hookAuthoring/index.ts"],"sourcesContent":["import type { HookModule } from '../../types/hookModule';\n\n/** Preserve the author's inferred module type while checking the hook contract. */\nexport function defineDoomHook<T extends HookModule>(module: T): T {\n return module;\n}\n"],"mappings":";;AAGA,SAAgB,eAAqC,QAAc;CACjE,OAAO;AACT"}
1
+ {"version":3,"file":"authoring.mjs","names":[],"sources":["../src/services/hookAuthoring/index.ts"],"sourcesContent":["import type { HookModule } from '../../types/hookModule';\n\n/** Preserve the author's inferred module type while checking the hook contract. */\nexport function definePoHook<T extends HookModule>(module: T): T {\n return module;\n}\n"],"mappings":";;AAGA,SAAgB,aAAmC,QAAc;CAC/D,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.cjs","names":["defineMcpSkill","readPackageResource","defineMcpPlugin","skillPoAuthorHook"],"sources":["../../src/extensions/workspaces/sessions/(backend)/skill/po-author-hook.mcp.ts","../../generated/mcp.ts"],"sourcesContent":["import { defineMcpSkill } from '@agimon-ai/po-core/mcpFacet';\nimport { readPackageResource } from '@agimon-ai/po-core/serverFacet';\n\nexport default defineMcpSkill({\n name: 'po-author-hook',\n description:\n 'Author Po repository or plugin hooks. Use when creating or changing .po/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to Po.',\n read: () => readPackageResource(import.meta.url, 'src/prompts/po-author-hook/SKILL.md'),\n});\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineMcpPlugin, type DoomMcpSessionPlugin } from '@agimon-ai/po-core/mcpFacet';\n\nimport skillPoAuthorHook from '../src/extensions/workspaces/sessions/(backend)/skill/po-author-hook.mcp';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\n\nexport const mcp = defineMcpPlugin({\n name: '@agimon-ai/po-hook',\n session: (context) => ({\n get skills(): DoomMcpSessionPlugin['skills'] { return [at(skillPoAuthorHook, context)]; },\n }) satisfies DoomMcpSessionPlugin,\n});\n\nexport default mcp;\n"],"mappings":";;;;;;;AAGA,IAAA,8BAAA,GAAeA,4BAAAA,eAAAA,CAAe;CAC5B,MAAM;CACN,aACE;CACF,aAAA,GAAYC,+BAAAA,oBAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,MAAqC,qCAAqC;AACxF,CAAC;;;ACFD,MAAM,MAAY,OAA0B,YAC1C,OAAO,UAAU,aAAc,MAAwB,OAAO,IAAI;AAEpE,MAAa,OAAA,GAAMC,4BAAAA,gBAAAA,CAAgB;CACjC,MAAM;CACN,UAAU,aAAa,EACrB,IAAI,SAAyC;EAAE,OAAO,CAAC,GAAGC,4BAAmB,OAAO,CAAC;CAAG,EAC1F;AACF,CAAC"}
1
+ {"version":3,"file":"mcp.cjs","names":["defineMcpSkill","readPackageResource","defineMcpPlugin","skillPoAuthorHook"],"sources":["../../src/extensions/workspaces/sessions/(backend)/skill/po-author-hook.mcp.ts","../../generated/mcp.ts"],"sourcesContent":["import { defineMcpSkill } from '@agimon-ai/po-core/mcpFacet';\nimport { readPackageResource } from '@agimon-ai/po-core/serverFacet';\n\nexport default defineMcpSkill({\n name: 'po-author-hook',\n description:\n 'Author Po repository or plugin hooks. Use when creating or changing .po/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to Po.',\n read: () => readPackageResource(import.meta.url, 'src/prompts/po-author-hook/SKILL.md'),\n});\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineMcpPlugin, type PoMcpSessionPlugin } from '@agimon-ai/po-core/mcpFacet';\n\nimport skillPoAuthorHook from '../src/extensions/workspaces/sessions/(backend)/skill/po-author-hook.mcp';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\n\nexport const mcp = defineMcpPlugin({\n name: '@agimon-ai/po-hook',\n session: (context) => ({\n get skills(): PoMcpSessionPlugin['skills'] { return [at(skillPoAuthorHook, context)]; },\n }) satisfies PoMcpSessionPlugin,\n});\n\nexport default mcp;\n"],"mappings":";;;;;;;AAGA,IAAA,8BAAA,GAAeA,4BAAAA,eAAAA,CAAe;CAC5B,MAAM;CACN,aACE;CACF,aAAA,GAAYC,+BAAAA,oBAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,MAAqC,qCAAqC;AACxF,CAAC;;;ACFD,MAAM,MAAY,OAA0B,YAC1C,OAAO,UAAU,aAAc,MAAwB,OAAO,IAAI;AAEpE,MAAa,OAAA,GAAMC,4BAAAA,gBAAAA,CAAgB;CACjC,MAAM;CACN,UAAU,aAAa,EACrB,IAAI,SAAuC;EAAE,OAAO,CAAC,GAAGC,4BAAmB,OAAO,CAAC;CAAG,EACxF;AACF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  //#region generated/mcp.d.ts
2
- export declare const mcp: import("@agimon-ai/po-core/mcpFacet").DoomMcpPluginDefinition;
2
+ export declare const mcp: import("@agimon-ai/po-core/mcpFacet").PoMcpPluginDefinition;
3
3
  //#endregion
4
4
  export { mcp as default };
5
5
  //# sourceMappingURL=mcp.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.mjs","names":["skillPoAuthorHook"],"sources":["../../src/extensions/workspaces/sessions/(backend)/skill/po-author-hook.mcp.ts","../../generated/mcp.ts"],"sourcesContent":["import { defineMcpSkill } from '@agimon-ai/po-core/mcpFacet';\nimport { readPackageResource } from '@agimon-ai/po-core/serverFacet';\n\nexport default defineMcpSkill({\n name: 'po-author-hook',\n description:\n 'Author Po repository or plugin hooks. Use when creating or changing .po/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to Po.',\n read: () => readPackageResource(import.meta.url, 'src/prompts/po-author-hook/SKILL.md'),\n});\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineMcpPlugin, type DoomMcpSessionPlugin } from '@agimon-ai/po-core/mcpFacet';\n\nimport skillPoAuthorHook from '../src/extensions/workspaces/sessions/(backend)/skill/po-author-hook.mcp';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\n\nexport const mcp = defineMcpPlugin({\n name: '@agimon-ai/po-hook',\n session: (context) => ({\n get skills(): DoomMcpSessionPlugin['skills'] { return [at(skillPoAuthorHook, context)]; },\n }) satisfies DoomMcpSessionPlugin,\n});\n\nexport default mcp;\n"],"mappings":";;;AAGA,IAAA,6BAAe,eAAe;CAC5B,MAAM;CACN,aACE;CACF,YAAY,oBAAoB,YAAY,KAAK,qCAAqC;AACxF,CAAC;;;ACFD,MAAM,MAAY,OAA0B,YAC1C,OAAO,UAAU,aAAc,MAAwB,OAAO,IAAI;AAEpE,MAAa,MAAM,gBAAgB;CACjC,MAAM;CACN,UAAU,aAAa,EACrB,IAAI,SAAyC;EAAE,OAAO,CAAC,GAAGA,4BAAmB,OAAO,CAAC;CAAG,EAC1F;AACF,CAAC"}
1
+ {"version":3,"file":"mcp.mjs","names":["skillPoAuthorHook"],"sources":["../../src/extensions/workspaces/sessions/(backend)/skill/po-author-hook.mcp.ts","../../generated/mcp.ts"],"sourcesContent":["import { defineMcpSkill } from '@agimon-ai/po-core/mcpFacet';\nimport { readPackageResource } from '@agimon-ai/po-core/serverFacet';\n\nexport default defineMcpSkill({\n name: 'po-author-hook',\n description:\n 'Author Po repository or plugin hooks. Use when creating or changing .po/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to Po.',\n read: () => readPackageResource(import.meta.url, 'src/prompts/po-author-hook/SKILL.md'),\n});\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineMcpPlugin, type PoMcpSessionPlugin } from '@agimon-ai/po-core/mcpFacet';\n\nimport skillPoAuthorHook from '../src/extensions/workspaces/sessions/(backend)/skill/po-author-hook.mcp';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\n\nexport const mcp = defineMcpPlugin({\n name: '@agimon-ai/po-hook',\n session: (context) => ({\n get skills(): PoMcpSessionPlugin['skills'] { return [at(skillPoAuthorHook, context)]; },\n }) satisfies PoMcpSessionPlugin,\n});\n\nexport default mcp;\n"],"mappings":";;;AAGA,IAAA,6BAAe,eAAe;CAC5B,MAAM;CACN,aACE;CACF,YAAY,oBAAoB,YAAY,KAAK,qCAAqC;AACxF,CAAC;;;ACFD,MAAM,MAAY,OAA0B,YAC1C,OAAO,UAAU,aAAc,MAAwB,OAAO,IAAI;AAEpE,MAAa,MAAM,gBAAgB;CACjC,MAAM;CACN,UAAU,aAAa,EACrB,IAAI,SAAuC;EAAE,OAAO,CAAC,GAAGA,4BAAmB,OAAO,CAAC;CAAG,EACxF;AACF,CAAC"}
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_hookModules = require("../hookModules-DSheklXp.cjs");
5
+ const require_hookModules = require("../hookModules-BCecT6-e.cjs");
6
6
  let _agimon_ai_po_core_serverFacet = require("@agimon-ai/po-core/serverFacet");
7
7
  let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
8
8
  let _agimon_ai_po_core_headless = require("@agimon-ai/po-core/headless");
@@ -165,7 +165,7 @@ async function dispatchHooks(session, scope, request) {
165
165
  }
166
166
  //#endregion
167
167
  //#region src/services/hookRuntime/type.ts
168
- const DOOM_HOOK_SESSION_SERVICE = "doom/hook-session";
168
+ const PO_HOOK_SESSION_SERVICE = "po/hook-session";
169
169
  //#endregion
170
170
  //#region src/services/hookRuntime/index.ts
171
171
  function createHookSession(config, options, signal) {
@@ -275,7 +275,7 @@ function createHookRuntime(cordis, options, parentContext, lifetimeSignal) {
275
275
  const controller = new AbortController();
276
276
  const signal = lifetimeSignal ? AbortSignal.any([controller.signal, lifetimeSignal]) : controller.signal;
277
277
  const session = {
278
- ...createHookSession(() => (0, _agimon_ai_po_config_piContext.requireDoomConfigContext)(cordis), options, signal),
278
+ ...createHookSession(() => (0, _agimon_ai_po_config_piContext.requirePoConfigContext)(cordis), options, signal),
279
279
  parentContext
280
280
  };
281
281
  let disposal;
@@ -296,11 +296,11 @@ function createHookBinding(options, parentContext, lifetimeSignal) {
296
296
  let runtime;
297
297
  return {
298
298
  plugin(cordis) {
299
- cordis.inject([_agimon_ai_po_core_config.DOOM_CONFIG_SERVICE], (configContext) => {
299
+ cordis.inject([_agimon_ai_po_core_config.PO_CONFIG_SERVICE], (configContext) => {
300
300
  const binding = createHookRuntime(configContext, options, parentContext, lifetimeSignal);
301
301
  runtime = binding;
302
- configContext.provide(_agimon_ai_po_core_childSession.DOOM_CHILD_SESSION_HOOKS_SERVICE, binding.childHooks);
303
- configContext.provide(DOOM_HOOK_SESSION_SERVICE, binding);
302
+ configContext.provide(_agimon_ai_po_core_childSession.PO_CHILD_SESSION_HOOKS_SERVICE, binding.childHooks);
303
+ configContext.provide(PO_HOOK_SESSION_SERVICE, binding);
304
304
  return async () => {
305
305
  if (runtime === binding) runtime = void 0;
306
306
  await binding.dispose();
@@ -329,7 +329,7 @@ function scopeFor(runtime, execution) {
329
329
  signal: runtime.session.signal,
330
330
  operationSignal: execution.signal,
331
331
  async sendMessage(text, delivery) {
332
- if (!execution.session.admitPrompt) throw new _agimon_ai_po_core_headless.DoomHeadlessPromptAdmissionError("The session cannot admit a hook prompt.");
332
+ if (!execution.session.admitPrompt) throw new _agimon_ai_po_core_headless.PoHeadlessPromptAdmissionError("The session cannot admit a hook prompt.");
333
333
  await execution.session.admitPrompt(text, delivery);
334
334
  },
335
335
  appendCustomEntry: (type, data) => execution.session.appendCustomEntry(type, data)
@@ -420,7 +420,7 @@ function createServerHooks(resolveRuntime) {
420
420
  async handle(event, execution) {
421
421
  const runtime = resolveRuntime();
422
422
  if (runtime?.isCurrent()) await start(runtime, execution);
423
- await execution.session.appendCustomEntry("doom-hook", hookEntry(event));
423
+ await execution.session.appendCustomEntry("po-hook", hookEntry(event));
424
424
  }
425
425
  },
426
426
  toolCall: {
@@ -457,7 +457,7 @@ function createServerHooks(resolveRuntime) {
457
457
  toolResult: {
458
458
  event: "tool_result",
459
459
  async handle(event, execution) {
460
- await execution.session.appendCustomEntry("doom-hook", hookEntry(event));
460
+ await execution.session.appendCustomEntry("po-hook", hookEntry(event));
461
461
  const runtime = resolveRuntime();
462
462
  if (!runtime?.isCurrent()) return;
463
463
  await start(runtime, execution);
@@ -484,7 +484,7 @@ function createServerHooks(resolveRuntime) {
484
484
  },
485
485
  agentSettled: {
486
486
  event: "agent_settled",
487
- handle: (event, execution) => execution.session.appendCustomEntry("doom-hook", hookEntry(event))
487
+ handle: (event, execution) => execution.session.appendCustomEntry("po-hook", hookEntry(event))
488
488
  },
489
489
  sessionShutdown: {
490
490
  event: "session_shutdown",
@@ -498,7 +498,7 @@ function createServerHooks(resolveRuntime) {
498
498
  }
499
499
  await shutdown;
500
500
  }
501
- execution.client.setStatus("doom-hook", void 0);
501
+ execution.client.setStatus("po-hook", void 0);
502
502
  }
503
503
  }
504
504
  };
@@ -517,7 +517,7 @@ const createHookServerRoot = ({ agent, signal }) => {
517
517
  return execution.model;
518
518
  },
519
519
  async sendMessage(text, delivery) {
520
- if (!execution.session.admitPrompt) throw new _agimon_ai_po_core_headless.DoomHeadlessPromptAdmissionError("The session cannot admit a hook prompt.");
520
+ if (!execution.session.admitPrompt) throw new _agimon_ai_po_core_headless.PoHeadlessPromptAdmissionError("The session cannot admit a hook prompt.");
521
521
  await execution.session.admitPrompt(text, delivery);
522
522
  },
523
523
  appendCustomEntry: (type, data) => execution.session.appendCustomEntry(type, data)
@@ -556,7 +556,7 @@ var tool_result_server_default = (0, _agimon_ai_po_core_extensionFile.defineHook
556
556
  var po_author_hook_server_default = (0, _agimon_ai_po_core_extensionFile.defineResource)({
557
557
  name: "po-author-hook",
558
558
  description: "Author Po repository or plugin hooks. Use when creating or changing .po/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to Po.",
559
- when: _agimon_ai_po_core_help.DOOM_HELP_WHEN,
559
+ when: _agimon_ai_po_core_help.PO_HELP_WHEN,
560
560
  kind: "skill",
561
561
  path: (0, _agimon_ai_po_core_serverFacet.packageResourcePath)(require("url").pathToFileURL(__filename).href, "src/prompts/po-author-hook/SKILL.md"),
562
562
  read: async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"server.cjs","names":["HOOK_EVENT","selectRegistryHooks","selectPluginHooks","toolHookPayload","sessionHookPayload","toolResultMessages","isDenied","decisionReason","additionalContextsFrom","hookFailureMessage","createHookTelemetry","createHookModules","createHookDocumentReader","createBashHookRunner","HOOK_EVENT","hookFailureMessage","requireDoomConfigContext","DOOM_CONFIG_SERVICE","DOOM_CHILD_SESSION_HOOKS_SERVICE","DoomHeadlessPromptAdmissionError","HOOK_EVENT","hookFailureMessage","additionalContextsFrom","decisionReason","isDenied","DoomHeadlessPromptAdmissionError","defineRoot","defineHook","defineHook","defineHook","defineHook","defineHook","defineHook","defineHook","defineResource","DOOM_HELP_WHEN","packageResourcePath","readPackageResource","defineServerPlugin","composeServerProviderOverrides","rootSession","composeRootHooks","hookAgentEnd","hookAgentSettled","hookBeforeAgentStart","hookSessionShutdown","hookSessionStart","hookToolCall","hookToolResult","resourcePoAuthorHook"],"sources":["../../src/constants/hookHandlers.ts","../../src/services/hookDispatch/index.ts","../../src/services/hookRuntime/type.ts","../../src/services/hookRuntime/index.ts","../../src/services/serverHooks/index.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/serverRoot.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/agent-end.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/agent-settled.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/session-shutdown.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/session-start.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/tool-call.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/tool-result.server.ts","../../src/constants/hook.ts","../../src/extensions/workspaces/sessions/(backend)/resource/po-author-hook.server.ts","../../generated/server.ts"],"sourcesContent":["export const STATUS_PREFIX = 'repository-hooks';\nexport const FAILURE_MESSAGE_TYPE = 'repository-hook-failure';\nexport const CONTEXT_MESSAGE_TYPE = 'repository-hook-context';\n/** A Stop hook refused the stop; its reason sends the agent back to work. */\nexport const STOP_BLOCK_MESSAGE_TYPE = 'repository-hook-stop-block';\nexport const STEER = { deliverAs: 'steer' } as const;\n/** Starts a new turn on a settled agent, so a refused stop is not a silent one. */\nexport const FOLLOW_UP_TURN = { deliverAs: 'followUp', triggerTurn: true } as const;\n/** Adds a message to a settled agent's conversation without starting a turn. */\nexport const NO_TURN = { triggerTurn: false } as const;\n/**\n * How many stops in a row a Stop hook may refuse before the agent is left to\n * stop. A hook that never lets go would otherwise send it back forever.\n */\nexport const MAX_STOP_REFUSALS = 5;\n/** Claude's Stop hook input field: true when the agent is already continuing because of a Stop hook. */\nexport const STOP_HOOK_ACTIVE_FIELD = 'stop_hook_active';\nexport const BLOCKED_BY_HOOK = 'Blocked by repository hook';\nexport const SUBAGENT_ENVIRONMENT_FLAG = 'PI_SUBAGENT_CHILD';\nexport const CONTEXT_SEPARATOR = '\\n\\n';\n","import type { ToolResultEvent } from '@earendil-works/pi-coding-agent';\n\nimport { BLOCKED_BY_HOOK, CONTEXT_SEPARATOR } from '../../constants/hookHandlers';\nimport { HOOK_EVENT } from '../../constants/hooks';\nimport type { HookFailure, HookToolEvent, ResolvedHook } from '../../types/hooks';\nimport {\n additionalContextsFrom,\n decisionReason,\n hookFailureMessage,\n isDenied,\n toolResultMessages,\n} from '../hookDecisions';\nimport { sessionHookPayload, toolHookPayload } from '../hookPayload';\nimport { selectRegistryHooks } from '../hookRegistry';\nimport type { HookSession } from '../hookRuntime/type';\nimport { selectPluginHooks } from '../pluginHooks';\nimport type { HookDispatchRequest, HookDispatchResult, HookDispatchScope } from './type';\n\nfunction isJson(value: unknown, ancestors = new Set<object>()): boolean {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return true;\n if (typeof value === 'number') return Number.isFinite(value);\n if (typeof value !== 'object' || ancestors.has(value)) return false;\n ancestors.add(value);\n const valid =\n (Array.isArray(value) || Object.getPrototypeOf(value) === Object.prototype) &&\n Object.values(value).every((entry) => isJson(entry, ancestors));\n ancestors.delete(value);\n return valid;\n}\n\nfunction commandFailure(row: ResolvedHook, error: unknown): HookFailure {\n return {\n command: row.hook.command ?? row.hook.module,\n message: error instanceof Error ? error.message : String(error),\n reason: 'hook_execution',\n };\n}\n\n/** Registry rows interleave command and module bindings, followed by plugin commands. */\nexport async function dispatchHooks(\n session: HookSession,\n scope: HookDispatchScope,\n request: HookDispatchRequest,\n): Promise<HookDispatchResult> {\n const signal = scope.operationSignal ? AbortSignal.any([scope.signal, scope.operationSignal]) : scope.signal;\n signal.throwIfAborted();\n const harness = session.config().harness;\n const plugins = await session.documents.plugins(harness.pluginHooks);\n const registry =\n request.eventName === HOOK_EVENT.sessionEnd\n ? { entries: [], failure: undefined }\n : await session.documents.registry(scope.repoRoot);\n signal.throwIfAborted();\n const event = request.event;\n const toolName = event && 'toolName' in event ? event.toolName : undefined;\n const hooks = [\n ...selectRegistryHooks(registry.entries, {\n event: request.eventName,\n toolName,\n allowedGroups: harness.hookGroups,\n inSubagent: scope.isSubagent,\n }),\n ...selectPluginHooks(plugins.documents, request.eventName, toolName),\n ];\n const decisions: HookDispatchResult['decisions'] = [];\n const failures = [...(registry.failure ? [registry.failure] : []), ...plugins.failures];\n let toolCall: HookDispatchResult['toolCall'];\n let patchedResult = false;\n for (const [index, row] of hooks.entries()) {\n signal.throwIfAborted();\n request.progress?.(index, hooks.length);\n if (row.hook.command === undefined) {\n if (!event) continue;\n let proposed: typeof event;\n try {\n proposed = structuredClone(event);\n } catch (error) {\n failures.push(commandFailure(row, error));\n continue;\n }\n const outcome = await session.modules.invoke(row, proposed, scope, scope.operationSignal);\n signal.throwIfAborted();\n if (outcome.failure) {\n failures.push(outcome.failure);\n continue;\n }\n // A failed or late invocation cannot mutate live tool input or output.\n try {\n if (event.type === 'tool_call' && proposed.type === 'tool_call') {\n if (\n typeof proposed.input !== 'object' ||\n proposed.input === null ||\n Array.isArray(proposed.input) ||\n !isJson(proposed.input)\n ) {\n throw new Error('Hook tool input must be a JSON object.');\n }\n const input = structuredClone(proposed.input);\n for (const key of Object.keys(event.input)) delete (event.input as Record<string, unknown>)[key];\n Object.assign(event.input, input);\n if (outcome.result && 'block' in outcome.result && outcome.result.block) {\n toolCall = { block: true, reason: outcome.result.reason ?? BLOCKED_BY_HOOK };\n break;\n }\n } else if (event.type === 'tool_result' && outcome.result) {\n const patch = structuredClone(outcome.result);\n if ('content' in patch && patch.content !== undefined) event.content = patch.content;\n if ('details' in patch) event.details = patch.details;\n if ('isError' in patch && patch.isError !== undefined) event.isError = patch.isError;\n patchedResult = true;\n }\n } catch (error) {\n failures.push(commandFailure(row, error));\n }\n continue;\n }\n const payload =\n event && 'toolName' in event\n ? toolHookPayload(event as HookToolEvent, request.eventName, scope.repoRoot, scope.sessionId, {\n parentSessionId: scope.parentSessionId,\n agent: scope.agent,\n })\n : sessionHookPayload(scope.sessionId, scope.repoRoot);\n // The catch covers hook execution only. Readiness, host effects and abort errors propagate.\n let outcome;\n try {\n outcome = await session.runner.run(\n row.hook,\n { ...payload, ...request.extraPayload },\n {\n repoRoot: scope.repoRoot,\n pluginRoot: row.root,\n },\n );\n } catch (error) {\n failures.push(commandFailure(row, error));\n continue;\n }\n signal.throwIfAborted();\n if (outcome.failure) failures.push(outcome.failure);\n if (!outcome.decision) continue;\n decisions.push(outcome.decision);\n if (event?.type === 'tool_result') {\n const messages = toolResultMessages([outcome.decision]);\n if (messages.length > 0)\n event.content = [...event.content, { type: 'text', text: messages.join(CONTEXT_SEPARATOR) }];\n if (isDenied(outcome.decision)) event.isError = true;\n patchedResult ||= messages.length > 0 || isDenied(outcome.decision);\n }\n if (isDenied(outcome.decision)) {\n if (event?.type === 'tool_call')\n toolCall = {\n block: true,\n reason: decisionReason(outcome.decision) ?? BLOCKED_BY_HOOK,\n };\n break;\n }\n }\n if (event?.type === 'tool_call' && !toolCall) {\n const context = additionalContextsFrom(decisions).join(CONTEXT_SEPARATOR);\n if (context) toolCall = { block: true, reason: context };\n }\n if (event?.type === 'tool_result' && failures.length > 0) {\n event.content = [...event.content, { type: 'text', text: hookFailureMessage(failures) }];\n patchedResult = true;\n }\n return {\n decisions,\n failures,\n ...(toolCall ? { toolCall } : {}),\n ...(event?.type === 'tool_result' && patchedResult\n ? {\n toolResult: {\n content: (event as ToolResultEvent).content,\n details: (event as ToolResultEvent).details,\n isError: event.isError,\n },\n }\n : {}),\n };\n}\n","import type { DoomConfigContext } from '@agimon-ai/po-config/types';\nimport type { DoomChildSessionHooks } from '@agimon-ai/po-core/childSession';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { HookContext } from '../../types/hookModule';\nimport type { HookDocumentReader, HookRunner } from '../../types/hooks';\nimport type { HookTelemetry } from '../../types/telemetry';\nimport type { HookModules } from '../hookModules/type';\n\nexport const DOOM_HOOK_SESSION_SERVICE = 'doom/hook-session';\nexport interface HookExtensionOptions {\n telemetry?: HookTelemetry;\n runner?: HookRunner;\n documents?: HookDocumentReader;\n}\n\n/** One host session owns its module registry and lifetime; children borrow only immutable config. */\nexport interface HookSession {\n config(): DoomConfigContext;\n prepare(isSubagent?: boolean): Promise<void>;\n readonly runner: HookRunner;\n readonly documents: HookDocumentReader;\n readonly modules: HookModules;\n readonly signal: AbortSignal;\n readonly parentContext?: Omit<HookContext, 'signal'>;\n}\n\n/** One dependency-complete Hook runtime owned by a reactive Cordis fiber. */\nexport interface HookRuntime {\n readonly session: HookSession;\n readonly childHooks: DoomChildSessionHooks;\n isCurrent(): boolean;\n}\n\nexport type HookRuntimeResolver = () => HookRuntime | undefined;\n\nexport interface HookRuntimeBinding extends HookRuntime {\n dispose(): Promise<void>;\n}\nexport interface HookBinding {\n readonly plugin: (this: void, context: Context) => void;\n readonly runtime: HookRuntimeResolver;\n}\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'doom/hook-session': HookRuntime;\n }\n}\n","import { requireDoomConfigContext } from '@agimon-ai/po-config/piContext';\nimport type { DoomConfigContext } from '@agimon-ai/po-config/types';\nimport { DOOM_CHILD_SESSION_HOOKS_SERVICE, type DoomChildSessionHooks } from '@agimon-ai/po-core/childSession';\nimport { DOOM_CONFIG_SERVICE } from '@agimon-ai/po-core/config';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ToolCallEvent, ToolResultEvent } from '@earendil-works/pi-coding-agent';\n\nimport { HOOK_EVENT } from '../../constants/hooks';\nimport type { HookContext, JsonValue } from '../../types/hookModule';\nimport type { HookTelemetry } from '../../types/telemetry';\nimport { hookFailureMessage } from '../hookDecisions';\nimport { dispatchHooks } from '../hookDispatch';\nimport { createHookDocumentReader } from '../hookDocuments';\nimport { createHookModules } from '../hookModules';\nimport { createBashHookRunner } from '../hookRunner';\nimport { createHookTelemetry } from '../hookTelemetry';\nimport { DOOM_HOOK_SESSION_SERVICE, type HookSession } from './type';\nimport type { HookBinding, HookExtensionOptions, HookRuntimeBinding } from './type';\n\nexport function createHookSession(\n config: () => DoomConfigContext,\n options: HookExtensionOptions,\n signal: AbortSignal,\n): HookSession {\n // The log sink is only built if something actually reports to it, so a fully\n // stubbed session never touches the telemetry backend.\n let telemetry = options.telemetry;\n const requireTelemetry = (): HookTelemetry => (telemetry ??= createHookTelemetry());\n const modules = createHookModules({ descriptor: config().harness.hookModules });\n const documents = options.documents ?? createHookDocumentReader({ telemetry: requireTelemetry() });\n let preparation: Promise<void> | undefined;\n return {\n config,\n signal,\n modules,\n prepare(isSubagent = false) {\n preparation ??= (async () => {\n const harness = config().harness;\n if (harness.hooks === false) return;\n const registry = await documents.registry(harness.root ?? process.cwd());\n // Registry read failures keep their existing advisory dispatch policy.\n if (registry.failure) return;\n const allowed = harness.hookGroups === undefined ? undefined : new Set(harness.hookGroups);\n const rows = registry.entries\n .filter((row) => row.core || !allowed || allowed.has(row.groupId))\n .filter((row) => !(isSubagent && row.skipInSubagent));\n await modules.validate(rows);\n })();\n return preparation;\n },\n runner: options.runner ?? createBashHookRunner({ telemetry: requireTelemetry() }),\n documents,\n };\n}\n\nfunction childHooksFor(parent: HookSession): DoomChildSessionHooks {\n return {\n bind(scope) {\n // Children retain their launch selection and artifacts, even if the parent reloads.\n const config = structuredClone(parent.config());\n const controller = new AbortController();\n const signal = AbortSignal.any([controller.signal, scope.signal]);\n const session = createHookSession(() => config, { runner: parent.runner, documents: parent.documents }, signal);\n let disposal: Promise<void> | undefined;\n const context = (): HookContext => {\n const sessionId = scope.sessionId();\n if (!sessionId) throw new Error('Child hook identity is unavailable before runtime startup.');\n return {\n sessionId,\n parentSessionId: scope.request.parentSessionId,\n agent: scope.request.agent,\n isSubagent: true,\n cwd: scope.request.cwd,\n repoRoot: config.harness.root ?? scope.request.cwd,\n signal,\n sendMessage: (text, delivery) => scope.sendMessage(text, delivery),\n appendCustomEntry: (type, data) => scope.appendCustomEntry(type, data),\n };\n };\n return {\n async beforeTool(event, execution) {\n await session.prepare(true);\n const native = {\n type: 'tool_call',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: event.args,\n } as ToolCallEvent;\n const result = await dispatchHooks(\n session,\n { ...context(), operationSignal: execution.abortSignal },\n {\n eventName: HOOK_EVENT.preToolUse,\n event: native,\n },\n );\n if (result.failures.length > 0) await scope.sendMessage(hookFailureMessage(result.failures), 'steer');\n return result.toolCall?.block\n ? { block: { reason: result.toolCall.reason ?? 'Blocked by repository hook' } }\n : { args: native.input as Record<string, JsonValue> };\n },\n async afterTool(event, execution) {\n const native = {\n type: 'tool_result',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: event.args,\n content: event.content,\n details: event.details,\n isError: event.isError,\n } as ToolResultEvent;\n const result = await dispatchHooks(\n session,\n { ...context(), operationSignal: execution.abortSignal },\n {\n eventName: HOOK_EVENT.postToolUse,\n event: native,\n },\n );\n return result.toolResult\n ? {\n content: result.toolResult.content,\n details: result.toolResult.details as JsonValue | undefined,\n isError: result.toolResult.isError,\n }\n : undefined;\n },\n dispose() {\n disposal ??= (async () => {\n controller.abort();\n await session.modules.dispose();\n })();\n return disposal;\n },\n };\n },\n };\n}\n\nexport function createHookRuntime(\n cordis: Context,\n options: HookExtensionOptions,\n parentContext?: Omit<HookContext, 'signal'>,\n lifetimeSignal?: AbortSignal,\n): HookRuntimeBinding {\n const controller = new AbortController();\n const signal = lifetimeSignal ? AbortSignal.any([controller.signal, lifetimeSignal]) : controller.signal;\n const session: HookSession = {\n ...createHookSession(() => requireDoomConfigContext(cordis), options, signal),\n parentContext,\n };\n let disposal: Promise<void> | undefined;\n let active = true;\n return {\n session,\n childHooks: childHooksFor(session),\n isCurrent: () => active && !signal.aborted,\n dispose() {\n active = false;\n controller.abort();\n disposal ??= session.modules.dispose();\n return disposal;\n },\n };\n}\n\nexport function createHookBinding(\n options: HookExtensionOptions,\n parentContext?: Omit<HookContext, 'signal'>,\n lifetimeSignal?: AbortSignal,\n): HookBinding {\n let runtime: HookRuntimeBinding | undefined;\n return {\n plugin(cordis) {\n cordis.inject([DOOM_CONFIG_SERVICE], (configContext) => {\n const binding = createHookRuntime(configContext, options, parentContext, lifetimeSignal);\n runtime = binding;\n configContext.provide(DOOM_CHILD_SESSION_HOOKS_SERVICE, binding.childHooks);\n configContext.provide(DOOM_HOOK_SESSION_SERVICE, binding);\n return async () => {\n if (runtime === binding) runtime = undefined;\n await binding.dispose();\n };\n });\n },\n runtime: () => runtime,\n };\n}\n","import {\n DoomHeadlessPromptAdmissionError,\n type DoomHeadlessExecutionContext,\n type DoomHeadlessHook,\n} from '@agimon-ai/po-core/headless';\nimport type { ToolCallEvent, ToolResultEvent } from '@earendil-works/pi-coding-agent';\n\nimport {\n BLOCKED_BY_HOOK,\n STATUS_PREFIX,\n SUBAGENT_ENVIRONMENT_FLAG,\n CONTEXT_SEPARATOR,\n FAILURE_MESSAGE_TYPE,\n MAX_STOP_REFUSALS,\n STOP_HOOK_ACTIVE_FIELD,\n} from '../../constants/hookHandlers';\nimport { HOOK_EVENT } from '../../constants/hooks';\nimport type { HookNativeEvent } from '../../types/hookModule';\nimport { additionalContextsFrom, decisionReason, hookFailureMessage, isDenied } from '../hookDecisions';\nimport { dispatchHooks } from '../hookDispatch';\nimport type { HookDispatchScope } from '../hookDispatch/type';\nimport type { HookRuntime, HookRuntimeResolver } from '../hookRuntime/type';\n\nfunction hookEntry(event: Readonly<Record<string, unknown>>): Record<string, unknown> {\n return { version: 1, event: typeof event.type === 'string' ? event.type : 'headless-hook', data: event };\n}\n\nfunction scopeFor(runtime: HookRuntime, execution: DoomHeadlessExecutionContext): HookDispatchScope {\n return {\n sessionId: execution.sessionId,\n isSubagent: Boolean(execution.environment[SUBAGENT_ENVIRONMENT_FLAG]),\n cwd: execution.cwd,\n repoRoot: execution.repoRoot,\n model: execution.model,\n signal: runtime.session.signal,\n operationSignal: execution.signal,\n async sendMessage(text, delivery) {\n if (!execution.session.admitPrompt)\n throw new DoomHeadlessPromptAdmissionError('The session cannot admit a hook prompt.');\n await execution.session.admitPrompt(text, delivery);\n },\n appendCustomEntry: (type, data) => execution.session.appendCustomEntry(type, data),\n };\n}\n\n/** One native owner dispatches lifecycle and tool rows for this session. */\nexport function createServerHooks(resolveRuntime: HookRuntimeResolver) {\n const startups = new WeakMap<HookRuntime, Promise<void>>();\n const shutdowns = new WeakMap<HookRuntime, Promise<void>>();\n const refusals = new WeakMap<HookRuntime, number>();\n async function runLifecycle(\n runtime: HookRuntime,\n execution: DoomHeadlessExecutionContext,\n eventName: string,\n event?: Readonly<Record<string, unknown>>,\n extraPayload?: Record<string, unknown>,\n ) {\n const key = `${STATUS_PREFIX}:${execution.sessionId}:${eventName}`;\n try {\n return await dispatchHooks(runtime.session, scopeFor(runtime, execution), {\n eventName,\n event: event as HookNativeEvent | undefined,\n extraPayload,\n progress: (index, total) =>\n execution.client.setStatus(key, `Running ${eventName} hooks (${index + 1}/${total})...`),\n });\n } finally {\n execution.client.setStatus(key, undefined);\n }\n }\n function start(\n runtime: HookRuntime,\n execution: DoomHeadlessExecutionContext,\n event: Readonly<Record<string, unknown>> = { type: 'session_start' },\n ) {\n let startup = startups.get(runtime);\n if (!startup) {\n startup = (async () => {\n const scope = scopeFor(runtime, execution);\n await runtime.session.prepare(scope.isSubagent);\n if (scope.isSubagent) return;\n const result = await runLifecycle(runtime, execution, HOOK_EVENT.sessionStart, {\n ...event,\n type: 'session_start',\n });\n if (!runtime.isCurrent()) return;\n if (result.failures.length) await scope.sendMessage(hookFailureMessage(result.failures), 'steer');\n const context = additionalContextsFrom(result.decisions).join(CONTEXT_SEPARATOR);\n if (context) await scope.sendMessage(context, 'steer');\n })();\n startups.set(runtime, startup);\n }\n return startup;\n }\n const sessionStart: DoomHeadlessHook<'session_start'> = {\n event: 'session_start',\n async handle(event, execution) {\n const runtime = resolveRuntime();\n if (runtime?.isCurrent()) await start(runtime, execution, event);\n },\n };\n const agentEnd: DoomHeadlessHook<'agent_end'> = {\n event: 'agent_end',\n async handle(event, execution) {\n const runtime = resolveRuntime();\n if (!runtime?.isCurrent() || scopeFor(runtime, execution).isSubagent) return;\n await start(runtime, execution);\n const count = refusals.get(runtime) ?? 0;\n const result = await runLifecycle(\n runtime,\n execution,\n HOOK_EVENT.stop,\n { ...event, type: 'agent_settled' },\n { [STOP_HOOK_ACTIVE_FIELD]: count > 0 },\n );\n if (!runtime.isCurrent()) return;\n const appendFailure = async (text: string) => {\n if (!execution.session.appendMessage) throw new Error('The session cannot append hook diagnostics.');\n await execution.session.appendMessage({ type: FAILURE_MESSAGE_TYPE, text });\n };\n if (result.failures.length) await appendFailure(hookFailureMessage(result.failures));\n const reason = decisionReason(result.decisions.find(isDenied));\n if (!reason) {\n refusals.set(runtime, 0);\n return;\n }\n if (count >= MAX_STOP_REFUSALS) {\n refusals.set(runtime, 0);\n await appendFailure(\n `A Stop hook refused ${String(MAX_STOP_REFUSALS)} stops in a row, so the agent stops here. Its last reason: ${reason}`,\n );\n return;\n }\n // Advance only after successful admission. Admission does not await the successor turn.\n await scopeFor(runtime, execution).sendMessage(reason, 'followUp');\n refusals.set(runtime, count + 1);\n },\n };\n const beforeAgentStart: DoomHeadlessHook<'before_agent_start'> = {\n event: 'before_agent_start',\n async handle(event, execution) {\n const runtime = resolveRuntime();\n if (runtime?.isCurrent()) await start(runtime, execution);\n await execution.session.appendCustomEntry('doom-hook', hookEntry(event));\n },\n };\n const toolCall: DoomHeadlessHook<'tool_call'> = {\n event: 'tool_call',\n async handle(event, execution) {\n const runtime = resolveRuntime();\n if (!runtime?.isCurrent()) return;\n const scope = scopeFor(runtime, execution);\n try {\n await start(runtime, execution);\n } catch (error) {\n return { block: { reason: error instanceof Error ? error.message : String(error) } };\n }\n const native = {\n type: 'tool_call',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: event.args,\n } as ToolCallEvent;\n const key = `${STATUS_PREFIX}:${native.toolCallId}:pre`;\n try {\n const result = await dispatchHooks(runtime.session, scope, {\n eventName: HOOK_EVENT.preToolUse,\n event: native,\n progress: (index, total) =>\n execution.client.setStatus(key, `Running pre-tool hooks for ${native.toolName} (${index + 1}/${total})...`),\n });\n if (result.failures.length > 0) await scope.sendMessage(hookFailureMessage(result.failures), 'steer');\n return result.toolCall?.block\n ? { block: { reason: result.toolCall.reason ?? BLOCKED_BY_HOOK } }\n : { args: native.input };\n } finally {\n execution.client.setStatus(key, undefined);\n }\n },\n };\n const toolResult: DoomHeadlessHook<'tool_result'> = {\n event: 'tool_result',\n async handle(event, execution) {\n await execution.session.appendCustomEntry('doom-hook', hookEntry(event));\n const runtime = resolveRuntime();\n if (!runtime?.isCurrent()) return;\n await start(runtime, execution);\n const native = {\n type: 'tool_result',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: event.args,\n content: event.content,\n details: event.details,\n isError: event.isError,\n } as ToolResultEvent;\n const key = `${STATUS_PREFIX}:${native.toolCallId}:post`;\n try {\n const result = await dispatchHooks(runtime.session, scopeFor(runtime, execution), {\n eventName: HOOK_EVENT.postToolUse,\n event: native,\n progress: (index, total) =>\n execution.client.setStatus(\n key,\n `Running post-tool hooks for ${native.toolName} (${index + 1}/${total})...`,\n ),\n });\n return result.toolResult;\n } finally {\n execution.client.setStatus(key, undefined);\n }\n },\n };\n const agentSettled: DoomHeadlessHook<'agent_settled'> = {\n event: 'agent_settled',\n handle: (event, execution) => execution.session.appendCustomEntry('doom-hook', hookEntry(event)),\n };\n const sessionShutdown: DoomHeadlessHook<'session_shutdown'> = {\n event: 'session_shutdown',\n async handle(_event, execution) {\n const runtime = resolveRuntime();\n if (runtime?.isCurrent() && !scopeFor(runtime, execution).isSubagent) {\n let shutdown = shutdowns.get(runtime);\n if (!shutdown) {\n shutdown = runLifecycle(runtime, execution, HOOK_EVENT.sessionEnd).then(() => undefined);\n shutdowns.set(runtime, shutdown);\n }\n await shutdown;\n }\n execution.client.setStatus('doom-hook', undefined);\n },\n };\n return { sessionStart, agentEnd, beforeAgentStart, toolCall, toolResult, agentSettled, sessionShutdown };\n}\n","import { DoomHeadlessPromptAdmissionError } from '@agimon-ai/po-core/headless';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport { SUBAGENT_ENVIRONMENT_FLAG } from '../../../../../constants/hookHandlers';\nimport { createHookBinding } from '../../../../../services/hookRuntime';\nimport { createServerHooks } from '../../../../../services/serverHooks';\n\nexport const createHookServerRoot = ({ agent, signal }: DoomServerPluginContext) => {\n if (!agent) throw new Error('Hook session requires the headless host.');\n const execution = agent.context;\n const binding = createHookBinding(\n {},\n {\n sessionId: execution.sessionId,\n isSubagent: Boolean(execution.environment[SUBAGENT_ENVIRONMENT_FLAG]),\n cwd: execution.cwd,\n repoRoot: execution.repoRoot,\n get model() {\n return execution.model;\n },\n async sendMessage(text, delivery) {\n if (!execution.session.admitPrompt)\n throw new DoomHeadlessPromptAdmissionError('The session cannot admit a hook prompt.');\n await execution.session.admitPrompt(text, delivery);\n },\n appendCustomEntry: (type, data) => execution.session.appendCustomEntry(type, data),\n },\n signal,\n );\n return { value: createServerHooks(binding.runtime), services: [binding.plugin] };\n};\n\nexport type HookServerScope = Awaited<ReturnType<typeof createHookServerRoot>>['value'];\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\n\nimport { createHookServerRoot } from './_lib/serverRoot';\n\nexport default defineRoot(createHookServerRoot);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<DoomServerPluginContext, HookServerScope>) => root.agentEnd);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<DoomServerPluginContext, HookServerScope>) => root.agentSettled);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<DoomServerPluginContext, HookServerScope>) => root.beforeAgentStart);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<DoomServerPluginContext, HookServerScope>) => root.sessionShutdown);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<DoomServerPluginContext, HookServerScope>) => root.sessionStart);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<DoomServerPluginContext, HookServerScope>) => root.toolCall);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<DoomServerPluginContext, HookServerScope>) => root.toolResult);\n","export const PACKAGE_SOURCE = '@agimon-ai/po-hook';\nexport const HOOK_HELP_SKILL = {\n name: 'po-author-hook',\n description:\n 'Author Po repository or plugin hooks. Use when creating or changing .po/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to Po.',\n};\n","import { defineResource } from '@agimon-ai/po-core/extensionFile';\nimport { DOOM_HELP_WHEN } from '@agimon-ai/po-core/help';\nimport { packageResourcePath, readPackageResource } from '@agimon-ai/po-core/serverFacet';\n\nimport { HOOK_HELP_SKILL } from '../../../../../constants/hook';\n\nexport default defineResource({\n ...HOOK_HELP_SKILL,\n when: DOOM_HELP_WHEN,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, 'src/prompts/po-author-hook/SKILL.md'),\n read: async () => {\n const text = await readPackageResource(import.meta.url, 'src/prompts/po-author-hook/SKILL.md');\n if (!text.trim()) throw new Error('The installed hook-authoring skill is missing or unreadable.');\n return text;\n },\n});\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type DoomServerSessionPlugin } from '@agimon-ai/po-core/serverFacet';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverFacet';\nimport { composeRootHooks } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport hookAgentEnd from '../src/extensions/workspaces/sessions/(backend)/hook/agent-end.server';\nimport hookAgentSettled from '../src/extensions/workspaces/sessions/(backend)/hook/agent-settled.server';\nimport hookBeforeAgentStart from '../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server';\nimport hookSessionShutdown from '../src/extensions/workspaces/sessions/(backend)/hook/session-shutdown.server';\nimport hookSessionStart from '../src/extensions/workspaces/sessions/(backend)/hook/session-start.server';\nimport hookToolCall from '../src/extensions/workspaces/sessions/(backend)/hook/tool-call.server';\nimport hookToolResult from '../src/extensions/workspaces/sessions/(backend)/hook/tool-result.server';\nimport resourcePoAuthorHook from '../src/extensions/workspaces/sessions/(backend)/resource/po-author-hook.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const facet = defineServerPlugin({\n name: '@agimon-ai/po-hook',\n providerOverrides: composeServerProviderOverrides(rootSession),\n session: async (context) => {\n const scopeSession = await rootSession(context);\n const contextSession = { ...context, root: scopeSession.value };\n return {\n ...composeRootHooks(scopeSession),\n get hooks(): DoomServerSessionPlugin['hooks'] { return [via({ event: 'agent_end' }, at(hookAgentEnd, contextSession)), via({ event: 'agent_settled' }, at(hookAgentSettled, contextSession)), via({ event: 'before_agent_start' }, at(hookBeforeAgentStart, contextSession)), via({ event: 'session_shutdown' }, at(hookSessionShutdown, contextSession)), via({ event: 'session_start' }, at(hookSessionStart, contextSession)), via({ event: 'tool_call' }, at(hookToolCall, contextSession)), via({ event: 'tool_result' }, at(hookToolResult, contextSession))]; },\n get resources(): DoomServerSessionPlugin['resources'] { return [at(resourcePoAuthorHook, contextSession)]; },\n services: [...(scopeSession.services ?? [])],\n get activities(): DoomServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default facet;\n"],"mappings":";;;;;;;;;;;;;AAAA,MAAa,gBAAgB;AAC7B,MAAa,uBAAuB;;AAepC,MAAa,yBAAyB;AAEtC,MAAa,4BAA4B;;;ACAzC,SAAS,OAAO,OAAgB,4BAAY,IAAI,IAAY,GAAY;CACtE,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW,OAAO;CACtF,IAAI,OAAO,UAAU,UAAU,OAAO,OAAO,SAAS,KAAK;CAC3D,IAAI,OAAO,UAAU,YAAY,UAAU,IAAI,KAAK,GAAG,OAAO;CAC9D,UAAU,IAAI,KAAK;CACnB,MAAM,SACH,MAAM,QAA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AQC,+BAAAA,mBAAAA,CAAmB;CACtC,MAAM;CACN,oBAAA,GAAmBC,+BAAAA,+BAAAA,CAA+BC,mBAAW;CAC7D,SAAS,OAAO,YAAY;EAC1B,MAAM,eAAe,MAAMA,oBAAY,OAAO;EAC9C,MAAM,iBAAiB;GAAE,GAAG;GAAS,MAAM,aAAa;EAAM;EAC9D,OAAO;GACL,IAAA,GAAGC,iCAAAA,iBAAAA,CAAiB,YAAY;GAChC,IAAI,QAA0C;IAAE,OAAO;KAAC,IAAI,EAAE,OAAO,YAAY,GAAG,GAAGC,0BAAc,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,gBAAgB,GAAG,GAAGC,8BAAkB,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,qBAAqB,GAAG,GAAGC,mCAAsB,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,mBAAmB,GAAG,GAAGC,iCAAqB,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,gBAAgB,GAAG,GAAGC,8BAAkB,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,YAAY,GAAG,GAAGC,0BAAc,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,cAAc,GAAG,GAAGC,4BAAgB,cAAc,CAAC;IAAC;GAAG;GACriB,IAAI,YAAkD;IAAE,OAAO,CAAC,GAAGC,+BAAsB,cAAc,CAAC;GAAG;GAC3G,UAAU,CAAC,GAAI,aAAa,YAAY,CAAC,CAAE;GAC3C,IAAI,aAAoD;IAAE,OAAO,CAAC,GAAI,aAAa,cAAc,CAAC,CAAE;GAAG;EACzG;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"server.cjs","names":["HOOK_EVENT","selectRegistryHooks","selectPluginHooks","toolHookPayload","sessionHookPayload","toolResultMessages","isDenied","decisionReason","additionalContextsFrom","hookFailureMessage","createHookTelemetry","createHookModules","createHookDocumentReader","createBashHookRunner","HOOK_EVENT","hookFailureMessage","requirePoConfigContext","PO_CONFIG_SERVICE","PO_CHILD_SESSION_HOOKS_SERVICE","PoHeadlessPromptAdmissionError","HOOK_EVENT","hookFailureMessage","additionalContextsFrom","decisionReason","isDenied","PoHeadlessPromptAdmissionError","defineRoot","defineHook","defineHook","defineHook","defineHook","defineHook","defineHook","defineHook","defineResource","PO_HELP_WHEN","packageResourcePath","readPackageResource","defineServerPlugin","composeServerProviderOverrides","rootSession","composeRootHooks","hookAgentEnd","hookAgentSettled","hookBeforeAgentStart","hookSessionShutdown","hookSessionStart","hookToolCall","hookToolResult","resourcePoAuthorHook"],"sources":["../../src/constants/hookHandlers.ts","../../src/services/hookDispatch/index.ts","../../src/services/hookRuntime/type.ts","../../src/services/hookRuntime/index.ts","../../src/services/serverHooks/index.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/serverRoot.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/agent-end.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/agent-settled.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/session-shutdown.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/session-start.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/tool-call.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/tool-result.server.ts","../../src/constants/hook.ts","../../src/extensions/workspaces/sessions/(backend)/resource/po-author-hook.server.ts","../../generated/server.ts"],"sourcesContent":["export const STATUS_PREFIX = 'repository-hooks';\nexport const FAILURE_MESSAGE_TYPE = 'repository-hook-failure';\nexport const CONTEXT_MESSAGE_TYPE = 'repository-hook-context';\n/** A Stop hook refused the stop; its reason sends the agent back to work. */\nexport const STOP_BLOCK_MESSAGE_TYPE = 'repository-hook-stop-block';\nexport const STEER = { deliverAs: 'steer' } as const;\n/** Starts a new turn on a settled agent, so a refused stop is not a silent one. */\nexport const FOLLOW_UP_TURN = { deliverAs: 'followUp', triggerTurn: true } as const;\n/** Adds a message to a settled agent's conversation without starting a turn. */\nexport const NO_TURN = { triggerTurn: false } as const;\n/**\n * How many stops in a row a Stop hook may refuse before the agent is left to\n * stop. A hook that never lets go would otherwise send it back forever.\n */\nexport const MAX_STOP_REFUSALS = 5;\n/** Claude's Stop hook input field: true when the agent is already continuing because of a Stop hook. */\nexport const STOP_HOOK_ACTIVE_FIELD = 'stop_hook_active';\nexport const BLOCKED_BY_HOOK = 'Blocked by repository hook';\nexport const SUBAGENT_ENVIRONMENT_FLAG = 'PI_SUBAGENT_CHILD';\nexport const CONTEXT_SEPARATOR = '\\n\\n';\n","import type { ToolResultEvent } from '@earendil-works/pi-coding-agent';\n\nimport { BLOCKED_BY_HOOK, CONTEXT_SEPARATOR } from '../../constants/hookHandlers';\nimport { HOOK_EVENT } from '../../constants/hooks';\nimport type { HookFailure, HookToolEvent, ResolvedHook } from '../../types/hooks';\nimport {\n additionalContextsFrom,\n decisionReason,\n hookFailureMessage,\n isDenied,\n toolResultMessages,\n} from '../hookDecisions';\nimport { sessionHookPayload, toolHookPayload } from '../hookPayload';\nimport { selectRegistryHooks } from '../hookRegistry';\nimport type { HookSession } from '../hookRuntime/type';\nimport { selectPluginHooks } from '../pluginHooks';\nimport type { HookDispatchRequest, HookDispatchResult, HookDispatchScope } from './type';\n\nfunction isJson(value: unknown, ancestors = new Set<object>()): boolean {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return true;\n if (typeof value === 'number') return Number.isFinite(value);\n if (typeof value !== 'object' || ancestors.has(value)) return false;\n ancestors.add(value);\n const valid =\n (Array.isArray(value) || Object.getPrototypeOf(value) === Object.prototype) &&\n Object.values(value).every((entry) => isJson(entry, ancestors));\n ancestors.delete(value);\n return valid;\n}\n\nfunction commandFailure(row: ResolvedHook, error: unknown): HookFailure {\n return {\n command: row.hook.command ?? row.hook.module,\n message: error instanceof Error ? error.message : String(error),\n reason: 'hook_execution',\n };\n}\n\n/** Registry rows interleave command and module bindings, followed by plugin commands. */\nexport async function dispatchHooks(\n session: HookSession,\n scope: HookDispatchScope,\n request: HookDispatchRequest,\n): Promise<HookDispatchResult> {\n const signal = scope.operationSignal ? AbortSignal.any([scope.signal, scope.operationSignal]) : scope.signal;\n signal.throwIfAborted();\n const harness = session.config().harness;\n const plugins = await session.documents.plugins(harness.pluginHooks);\n const registry =\n request.eventName === HOOK_EVENT.sessionEnd\n ? { entries: [], failure: undefined }\n : await session.documents.registry(scope.repoRoot);\n signal.throwIfAborted();\n const event = request.event;\n const toolName = event && 'toolName' in event ? event.toolName : undefined;\n const hooks = [\n ...selectRegistryHooks(registry.entries, {\n event: request.eventName,\n toolName,\n allowedGroups: harness.hookGroups,\n inSubagent: scope.isSubagent,\n }),\n ...selectPluginHooks(plugins.documents, request.eventName, toolName),\n ];\n const decisions: HookDispatchResult['decisions'] = [];\n const failures = [...(registry.failure ? [registry.failure] : []), ...plugins.failures];\n let toolCall: HookDispatchResult['toolCall'];\n let patchedResult = false;\n for (const [index, row] of hooks.entries()) {\n signal.throwIfAborted();\n request.progress?.(index, hooks.length);\n if (row.hook.command === undefined) {\n if (!event) continue;\n let proposed: typeof event;\n try {\n proposed = structuredClone(event);\n } catch (error) {\n failures.push(commandFailure(row, error));\n continue;\n }\n const outcome = await session.modules.invoke(row, proposed, scope, scope.operationSignal);\n signal.throwIfAborted();\n if (outcome.failure) {\n failures.push(outcome.failure);\n continue;\n }\n // A failed or late invocation cannot mutate live tool input or output.\n try {\n if (event.type === 'tool_call' && proposed.type === 'tool_call') {\n if (\n typeof proposed.input !== 'object' ||\n proposed.input === null ||\n Array.isArray(proposed.input) ||\n !isJson(proposed.input)\n ) {\n throw new Error('Hook tool input must be a JSON object.');\n }\n const input = structuredClone(proposed.input);\n for (const key of Object.keys(event.input)) delete (event.input as Record<string, unknown>)[key];\n Object.assign(event.input, input);\n if (outcome.result && 'block' in outcome.result && outcome.result.block) {\n toolCall = { block: true, reason: outcome.result.reason ?? BLOCKED_BY_HOOK };\n break;\n }\n } else if (event.type === 'tool_result' && outcome.result) {\n const patch = structuredClone(outcome.result);\n if ('content' in patch && patch.content !== undefined) event.content = patch.content;\n if ('details' in patch) event.details = patch.details;\n if ('isError' in patch && patch.isError !== undefined) event.isError = patch.isError;\n patchedResult = true;\n }\n } catch (error) {\n failures.push(commandFailure(row, error));\n }\n continue;\n }\n const payload =\n event && 'toolName' in event\n ? toolHookPayload(event as HookToolEvent, request.eventName, scope.repoRoot, scope.sessionId, {\n parentSessionId: scope.parentSessionId,\n agent: scope.agent,\n })\n : sessionHookPayload(scope.sessionId, scope.repoRoot);\n // The catch covers hook execution only. Readiness, host effects and abort errors propagate.\n let outcome;\n try {\n outcome = await session.runner.run(\n row.hook,\n { ...payload, ...request.extraPayload },\n {\n repoRoot: scope.repoRoot,\n pluginRoot: row.root,\n },\n );\n } catch (error) {\n failures.push(commandFailure(row, error));\n continue;\n }\n signal.throwIfAborted();\n if (outcome.failure) failures.push(outcome.failure);\n if (!outcome.decision) continue;\n decisions.push(outcome.decision);\n if (event?.type === 'tool_result') {\n const messages = toolResultMessages([outcome.decision]);\n if (messages.length > 0)\n event.content = [...event.content, { type: 'text', text: messages.join(CONTEXT_SEPARATOR) }];\n if (isDenied(outcome.decision)) event.isError = true;\n patchedResult ||= messages.length > 0 || isDenied(outcome.decision);\n }\n if (isDenied(outcome.decision)) {\n if (event?.type === 'tool_call')\n toolCall = {\n block: true,\n reason: decisionReason(outcome.decision) ?? BLOCKED_BY_HOOK,\n };\n break;\n }\n }\n if (event?.type === 'tool_call' && !toolCall) {\n const context = additionalContextsFrom(decisions).join(CONTEXT_SEPARATOR);\n if (context) toolCall = { block: true, reason: context };\n }\n if (event?.type === 'tool_result' && failures.length > 0) {\n event.content = [...event.content, { type: 'text', text: hookFailureMessage(failures) }];\n patchedResult = true;\n }\n return {\n decisions,\n failures,\n ...(toolCall ? { toolCall } : {}),\n ...(event?.type === 'tool_result' && patchedResult\n ? {\n toolResult: {\n content: (event as ToolResultEvent).content,\n details: (event as ToolResultEvent).details,\n isError: event.isError,\n },\n }\n : {}),\n };\n}\n","import type { PoConfigContext } from '@agimon-ai/po-config/types';\nimport type { PoChildSessionHooks } from '@agimon-ai/po-core/childSession';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { HookContext } from '../../types/hookModule';\nimport type { HookDocumentReader, HookRunner } from '../../types/hooks';\nimport type { HookTelemetry } from '../../types/telemetry';\nimport type { HookModules } from '../hookModules/type';\n\nexport const PO_HOOK_SESSION_SERVICE = 'po/hook-session';\nexport interface HookExtensionOptions {\n telemetry?: HookTelemetry;\n runner?: HookRunner;\n documents?: HookDocumentReader;\n}\n\n/** One host session owns its module registry and lifetime; children borrow only immutable config. */\nexport interface HookSession {\n config(): PoConfigContext;\n prepare(isSubagent?: boolean): Promise<void>;\n readonly runner: HookRunner;\n readonly documents: HookDocumentReader;\n readonly modules: HookModules;\n readonly signal: AbortSignal;\n readonly parentContext?: Omit<HookContext, 'signal'>;\n}\n\n/** One dependency-complete Hook runtime owned by a reactive Cordis fiber. */\nexport interface HookRuntime {\n readonly session: HookSession;\n readonly childHooks: PoChildSessionHooks;\n isCurrent(): boolean;\n}\n\nexport type HookRuntimeResolver = () => HookRuntime | undefined;\n\nexport interface HookRuntimeBinding extends HookRuntime {\n dispose(): Promise<void>;\n}\nexport interface HookBinding {\n readonly plugin: (this: void, context: Context) => void;\n readonly runtime: HookRuntimeResolver;\n}\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/hook-session': HookRuntime;\n }\n}\n","import { requirePoConfigContext } from '@agimon-ai/po-config/piContext';\nimport type { PoConfigContext } from '@agimon-ai/po-config/types';\nimport { PO_CHILD_SESSION_HOOKS_SERVICE, type PoChildSessionHooks } from '@agimon-ai/po-core/childSession';\nimport { PO_CONFIG_SERVICE } from '@agimon-ai/po-core/config';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ToolCallEvent, ToolResultEvent } from '@earendil-works/pi-coding-agent';\n\nimport { HOOK_EVENT } from '../../constants/hooks';\nimport type { HookContext, JsonValue } from '../../types/hookModule';\nimport type { HookTelemetry } from '../../types/telemetry';\nimport { hookFailureMessage } from '../hookDecisions';\nimport { dispatchHooks } from '../hookDispatch';\nimport { createHookDocumentReader } from '../hookDocuments';\nimport { createHookModules } from '../hookModules';\nimport { createBashHookRunner } from '../hookRunner';\nimport { createHookTelemetry } from '../hookTelemetry';\nimport { PO_HOOK_SESSION_SERVICE, type HookSession } from './type';\nimport type { HookBinding, HookExtensionOptions, HookRuntimeBinding } from './type';\n\nexport function createHookSession(\n config: () => PoConfigContext,\n options: HookExtensionOptions,\n signal: AbortSignal,\n): HookSession {\n // The log sink is only built if something actually reports to it, so a fully\n // stubbed session never touches the telemetry backend.\n let telemetry = options.telemetry;\n const requireTelemetry = (): HookTelemetry => (telemetry ??= createHookTelemetry());\n const modules = createHookModules({ descriptor: config().harness.hookModules });\n const documents = options.documents ?? createHookDocumentReader({ telemetry: requireTelemetry() });\n let preparation: Promise<void> | undefined;\n return {\n config,\n signal,\n modules,\n prepare(isSubagent = false) {\n preparation ??= (async () => {\n const harness = config().harness;\n if (harness.hooks === false) return;\n const registry = await documents.registry(harness.root ?? process.cwd());\n // Registry read failures keep their existing advisory dispatch policy.\n if (registry.failure) return;\n const allowed = harness.hookGroups === undefined ? undefined : new Set(harness.hookGroups);\n const rows = registry.entries\n .filter((row) => row.core || !allowed || allowed.has(row.groupId))\n .filter((row) => !(isSubagent && row.skipInSubagent));\n await modules.validate(rows);\n })();\n return preparation;\n },\n runner: options.runner ?? createBashHookRunner({ telemetry: requireTelemetry() }),\n documents,\n };\n}\n\nfunction childHooksFor(parent: HookSession): PoChildSessionHooks {\n return {\n bind(scope) {\n // Children retain their launch selection and artifacts, even if the parent reloads.\n const config = structuredClone(parent.config());\n const controller = new AbortController();\n const signal = AbortSignal.any([controller.signal, scope.signal]);\n const session = createHookSession(() => config, { runner: parent.runner, documents: parent.documents }, signal);\n let disposal: Promise<void> | undefined;\n const context = (): HookContext => {\n const sessionId = scope.sessionId();\n if (!sessionId) throw new Error('Child hook identity is unavailable before runtime startup.');\n return {\n sessionId,\n parentSessionId: scope.request.parentSessionId,\n agent: scope.request.agent,\n isSubagent: true,\n cwd: scope.request.cwd,\n repoRoot: config.harness.root ?? scope.request.cwd,\n signal,\n sendMessage: (text, delivery) => scope.sendMessage(text, delivery),\n appendCustomEntry: (type, data) => scope.appendCustomEntry(type, data),\n };\n };\n return {\n async beforeTool(event, execution) {\n await session.prepare(true);\n const native = {\n type: 'tool_call',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: event.args,\n } as ToolCallEvent;\n const result = await dispatchHooks(\n session,\n { ...context(), operationSignal: execution.abortSignal },\n {\n eventName: HOOK_EVENT.preToolUse,\n event: native,\n },\n );\n if (result.failures.length > 0) await scope.sendMessage(hookFailureMessage(result.failures), 'steer');\n return result.toolCall?.block\n ? { block: { reason: result.toolCall.reason ?? 'Blocked by repository hook' } }\n : { args: native.input as Record<string, JsonValue> };\n },\n async afterTool(event, execution) {\n const native = {\n type: 'tool_result',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: event.args,\n content: event.content,\n details: event.details,\n isError: event.isError,\n } as ToolResultEvent;\n const result = await dispatchHooks(\n session,\n { ...context(), operationSignal: execution.abortSignal },\n {\n eventName: HOOK_EVENT.postToolUse,\n event: native,\n },\n );\n return result.toolResult\n ? {\n content: result.toolResult.content,\n details: result.toolResult.details as JsonValue | undefined,\n isError: result.toolResult.isError,\n }\n : undefined;\n },\n dispose() {\n disposal ??= (async () => {\n controller.abort();\n await session.modules.dispose();\n })();\n return disposal;\n },\n };\n },\n };\n}\n\nexport function createHookRuntime(\n cordis: Context,\n options: HookExtensionOptions,\n parentContext?: Omit<HookContext, 'signal'>,\n lifetimeSignal?: AbortSignal,\n): HookRuntimeBinding {\n const controller = new AbortController();\n const signal = lifetimeSignal ? AbortSignal.any([controller.signal, lifetimeSignal]) : controller.signal;\n const session: HookSession = {\n ...createHookSession(() => requirePoConfigContext(cordis), options, signal),\n parentContext,\n };\n let disposal: Promise<void> | undefined;\n let active = true;\n return {\n session,\n childHooks: childHooksFor(session),\n isCurrent: () => active && !signal.aborted,\n dispose() {\n active = false;\n controller.abort();\n disposal ??= session.modules.dispose();\n return disposal;\n },\n };\n}\n\nexport function createHookBinding(\n options: HookExtensionOptions,\n parentContext?: Omit<HookContext, 'signal'>,\n lifetimeSignal?: AbortSignal,\n): HookBinding {\n let runtime: HookRuntimeBinding | undefined;\n return {\n plugin(cordis) {\n cordis.inject([PO_CONFIG_SERVICE], (configContext) => {\n const binding = createHookRuntime(configContext, options, parentContext, lifetimeSignal);\n runtime = binding;\n configContext.provide(PO_CHILD_SESSION_HOOKS_SERVICE, binding.childHooks);\n configContext.provide(PO_HOOK_SESSION_SERVICE, binding);\n return async () => {\n if (runtime === binding) runtime = undefined;\n await binding.dispose();\n };\n });\n },\n runtime: () => runtime,\n };\n}\n","import {\n PoHeadlessPromptAdmissionError,\n type PoHeadlessExecutionContext,\n type PoHeadlessHook,\n} from '@agimon-ai/po-core/headless';\nimport type { ToolCallEvent, ToolResultEvent } from '@earendil-works/pi-coding-agent';\n\nimport {\n BLOCKED_BY_HOOK,\n STATUS_PREFIX,\n SUBAGENT_ENVIRONMENT_FLAG,\n CONTEXT_SEPARATOR,\n FAILURE_MESSAGE_TYPE,\n MAX_STOP_REFUSALS,\n STOP_HOOK_ACTIVE_FIELD,\n} from '../../constants/hookHandlers';\nimport { HOOK_EVENT } from '../../constants/hooks';\nimport type { HookNativeEvent } from '../../types/hookModule';\nimport { additionalContextsFrom, decisionReason, hookFailureMessage, isDenied } from '../hookDecisions';\nimport { dispatchHooks } from '../hookDispatch';\nimport type { HookDispatchScope } from '../hookDispatch/type';\nimport type { HookRuntime, HookRuntimeResolver } from '../hookRuntime/type';\n\nfunction hookEntry(event: Readonly<Record<string, unknown>>): Record<string, unknown> {\n return { version: 1, event: typeof event.type === 'string' ? event.type : 'headless-hook', data: event };\n}\n\nfunction scopeFor(runtime: HookRuntime, execution: PoHeadlessExecutionContext): HookDispatchScope {\n return {\n sessionId: execution.sessionId,\n isSubagent: Boolean(execution.environment[SUBAGENT_ENVIRONMENT_FLAG]),\n cwd: execution.cwd,\n repoRoot: execution.repoRoot,\n model: execution.model,\n signal: runtime.session.signal,\n operationSignal: execution.signal,\n async sendMessage(text, delivery) {\n if (!execution.session.admitPrompt)\n throw new PoHeadlessPromptAdmissionError('The session cannot admit a hook prompt.');\n await execution.session.admitPrompt(text, delivery);\n },\n appendCustomEntry: (type, data) => execution.session.appendCustomEntry(type, data),\n };\n}\n\n/** One native owner dispatches lifecycle and tool rows for this session. */\nexport function createServerHooks(resolveRuntime: HookRuntimeResolver) {\n const startups = new WeakMap<HookRuntime, Promise<void>>();\n const shutdowns = new WeakMap<HookRuntime, Promise<void>>();\n const refusals = new WeakMap<HookRuntime, number>();\n async function runLifecycle(\n runtime: HookRuntime,\n execution: PoHeadlessExecutionContext,\n eventName: string,\n event?: Readonly<Record<string, unknown>>,\n extraPayload?: Record<string, unknown>,\n ) {\n const key = `${STATUS_PREFIX}:${execution.sessionId}:${eventName}`;\n try {\n return await dispatchHooks(runtime.session, scopeFor(runtime, execution), {\n eventName,\n event: event as HookNativeEvent | undefined,\n extraPayload,\n progress: (index, total) =>\n execution.client.setStatus(key, `Running ${eventName} hooks (${index + 1}/${total})...`),\n });\n } finally {\n execution.client.setStatus(key, undefined);\n }\n }\n function start(\n runtime: HookRuntime,\n execution: PoHeadlessExecutionContext,\n event: Readonly<Record<string, unknown>> = { type: 'session_start' },\n ) {\n let startup = startups.get(runtime);\n if (!startup) {\n startup = (async () => {\n const scope = scopeFor(runtime, execution);\n await runtime.session.prepare(scope.isSubagent);\n if (scope.isSubagent) return;\n const result = await runLifecycle(runtime, execution, HOOK_EVENT.sessionStart, {\n ...event,\n type: 'session_start',\n });\n if (!runtime.isCurrent()) return;\n if (result.failures.length) await scope.sendMessage(hookFailureMessage(result.failures), 'steer');\n const context = additionalContextsFrom(result.decisions).join(CONTEXT_SEPARATOR);\n if (context) await scope.sendMessage(context, 'steer');\n })();\n startups.set(runtime, startup);\n }\n return startup;\n }\n const sessionStart: PoHeadlessHook<'session_start'> = {\n event: 'session_start',\n async handle(event, execution) {\n const runtime = resolveRuntime();\n if (runtime?.isCurrent()) await start(runtime, execution, event);\n },\n };\n const agentEnd: PoHeadlessHook<'agent_end'> = {\n event: 'agent_end',\n async handle(event, execution) {\n const runtime = resolveRuntime();\n if (!runtime?.isCurrent() || scopeFor(runtime, execution).isSubagent) return;\n await start(runtime, execution);\n const count = refusals.get(runtime) ?? 0;\n const result = await runLifecycle(\n runtime,\n execution,\n HOOK_EVENT.stop,\n { ...event, type: 'agent_settled' },\n { [STOP_HOOK_ACTIVE_FIELD]: count > 0 },\n );\n if (!runtime.isCurrent()) return;\n const appendFailure = async (text: string) => {\n if (!execution.session.appendMessage) throw new Error('The session cannot append hook diagnostics.');\n await execution.session.appendMessage({ type: FAILURE_MESSAGE_TYPE, text });\n };\n if (result.failures.length) await appendFailure(hookFailureMessage(result.failures));\n const reason = decisionReason(result.decisions.find(isDenied));\n if (!reason) {\n refusals.set(runtime, 0);\n return;\n }\n if (count >= MAX_STOP_REFUSALS) {\n refusals.set(runtime, 0);\n await appendFailure(\n `A Stop hook refused ${String(MAX_STOP_REFUSALS)} stops in a row, so the agent stops here. Its last reason: ${reason}`,\n );\n return;\n }\n // Advance only after successful admission. Admission does not await the successor turn.\n await scopeFor(runtime, execution).sendMessage(reason, 'followUp');\n refusals.set(runtime, count + 1);\n },\n };\n const beforeAgentStart: PoHeadlessHook<'before_agent_start'> = {\n event: 'before_agent_start',\n async handle(event, execution) {\n const runtime = resolveRuntime();\n if (runtime?.isCurrent()) await start(runtime, execution);\n await execution.session.appendCustomEntry('po-hook', hookEntry(event));\n },\n };\n const toolCall: PoHeadlessHook<'tool_call'> = {\n event: 'tool_call',\n async handle(event, execution) {\n const runtime = resolveRuntime();\n if (!runtime?.isCurrent()) return;\n const scope = scopeFor(runtime, execution);\n try {\n await start(runtime, execution);\n } catch (error) {\n return { block: { reason: error instanceof Error ? error.message : String(error) } };\n }\n const native = {\n type: 'tool_call',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: event.args,\n } as ToolCallEvent;\n const key = `${STATUS_PREFIX}:${native.toolCallId}:pre`;\n try {\n const result = await dispatchHooks(runtime.session, scope, {\n eventName: HOOK_EVENT.preToolUse,\n event: native,\n progress: (index, total) =>\n execution.client.setStatus(key, `Running pre-tool hooks for ${native.toolName} (${index + 1}/${total})...`),\n });\n if (result.failures.length > 0) await scope.sendMessage(hookFailureMessage(result.failures), 'steer');\n return result.toolCall?.block\n ? { block: { reason: result.toolCall.reason ?? BLOCKED_BY_HOOK } }\n : { args: native.input };\n } finally {\n execution.client.setStatus(key, undefined);\n }\n },\n };\n const toolResult: PoHeadlessHook<'tool_result'> = {\n event: 'tool_result',\n async handle(event, execution) {\n await execution.session.appendCustomEntry('po-hook', hookEntry(event));\n const runtime = resolveRuntime();\n if (!runtime?.isCurrent()) return;\n await start(runtime, execution);\n const native = {\n type: 'tool_result',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: event.args,\n content: event.content,\n details: event.details,\n isError: event.isError,\n } as ToolResultEvent;\n const key = `${STATUS_PREFIX}:${native.toolCallId}:post`;\n try {\n const result = await dispatchHooks(runtime.session, scopeFor(runtime, execution), {\n eventName: HOOK_EVENT.postToolUse,\n event: native,\n progress: (index, total) =>\n execution.client.setStatus(\n key,\n `Running post-tool hooks for ${native.toolName} (${index + 1}/${total})...`,\n ),\n });\n return result.toolResult;\n } finally {\n execution.client.setStatus(key, undefined);\n }\n },\n };\n const agentSettled: PoHeadlessHook<'agent_settled'> = {\n event: 'agent_settled',\n handle: (event, execution) => execution.session.appendCustomEntry('po-hook', hookEntry(event)),\n };\n const sessionShutdown: PoHeadlessHook<'session_shutdown'> = {\n event: 'session_shutdown',\n async handle(_event, execution) {\n const runtime = resolveRuntime();\n if (runtime?.isCurrent() && !scopeFor(runtime, execution).isSubagent) {\n let shutdown = shutdowns.get(runtime);\n if (!shutdown) {\n shutdown = runLifecycle(runtime, execution, HOOK_EVENT.sessionEnd).then(() => undefined);\n shutdowns.set(runtime, shutdown);\n }\n await shutdown;\n }\n execution.client.setStatus('po-hook', undefined);\n },\n };\n return { sessionStart, agentEnd, beforeAgentStart, toolCall, toolResult, agentSettled, sessionShutdown };\n}\n","import { PoHeadlessPromptAdmissionError } from '@agimon-ai/po-core/headless';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport { SUBAGENT_ENVIRONMENT_FLAG } from '../../../../../constants/hookHandlers';\nimport { createHookBinding } from '../../../../../services/hookRuntime';\nimport { createServerHooks } from '../../../../../services/serverHooks';\n\nexport const createHookServerRoot = ({ agent, signal }: PoServerPluginContext) => {\n if (!agent) throw new Error('Hook session requires the headless host.');\n const execution = agent.context;\n const binding = createHookBinding(\n {},\n {\n sessionId: execution.sessionId,\n isSubagent: Boolean(execution.environment[SUBAGENT_ENVIRONMENT_FLAG]),\n cwd: execution.cwd,\n repoRoot: execution.repoRoot,\n get model() {\n return execution.model;\n },\n async sendMessage(text, delivery) {\n if (!execution.session.admitPrompt)\n throw new PoHeadlessPromptAdmissionError('The session cannot admit a hook prompt.');\n await execution.session.admitPrompt(text, delivery);\n },\n appendCustomEntry: (type, data) => execution.session.appendCustomEntry(type, data),\n },\n signal,\n );\n return { value: createServerHooks(binding.runtime), services: [binding.plugin] };\n};\n\nexport type HookServerScope = Awaited<ReturnType<typeof createHookServerRoot>>['value'];\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\n\nimport { createHookServerRoot } from './_lib/serverRoot';\n\nexport default defineRoot(createHookServerRoot);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<PoServerPluginContext, HookServerScope>) => root.agentEnd);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<PoServerPluginContext, HookServerScope>) => root.agentSettled);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<PoServerPluginContext, HookServerScope>) => root.beforeAgentStart);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<PoServerPluginContext, HookServerScope>) => root.sessionShutdown);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<PoServerPluginContext, HookServerScope>) => root.sessionStart);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<PoServerPluginContext, HookServerScope>) => root.toolCall);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { HookServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(({ root }: WithRoot<PoServerPluginContext, HookServerScope>) => root.toolResult);\n","export const PACKAGE_SOURCE = '@agimon-ai/po-hook';\nexport const HOOK_HELP_SKILL = {\n name: 'po-author-hook',\n description:\n 'Author Po repository or plugin hooks. Use when creating or changing .po/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to Po.',\n};\n","import { defineResource } from '@agimon-ai/po-core/extensionFile';\nimport { PO_HELP_WHEN } from '@agimon-ai/po-core/help';\nimport { packageResourcePath, readPackageResource } from '@agimon-ai/po-core/serverFacet';\n\nimport { HOOK_HELP_SKILL } from '../../../../../constants/hook';\n\nexport default defineResource({\n ...HOOK_HELP_SKILL,\n when: PO_HELP_WHEN,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, 'src/prompts/po-author-hook/SKILL.md'),\n read: async () => {\n const text = await readPackageResource(import.meta.url, 'src/prompts/po-author-hook/SKILL.md');\n if (!text.trim()) throw new Error('The installed hook-authoring skill is missing or unreadable.');\n return text;\n },\n});\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type PoServerSessionPlugin } from '@agimon-ai/po-core/serverFacet';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverFacet';\nimport { composeRootHooks } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport hookAgentEnd from '../src/extensions/workspaces/sessions/(backend)/hook/agent-end.server';\nimport hookAgentSettled from '../src/extensions/workspaces/sessions/(backend)/hook/agent-settled.server';\nimport hookBeforeAgentStart from '../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server';\nimport hookSessionShutdown from '../src/extensions/workspaces/sessions/(backend)/hook/session-shutdown.server';\nimport hookSessionStart from '../src/extensions/workspaces/sessions/(backend)/hook/session-start.server';\nimport hookToolCall from '../src/extensions/workspaces/sessions/(backend)/hook/tool-call.server';\nimport hookToolResult from '../src/extensions/workspaces/sessions/(backend)/hook/tool-result.server';\nimport resourcePoAuthorHook from '../src/extensions/workspaces/sessions/(backend)/resource/po-author-hook.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const facet = defineServerPlugin({\n name: '@agimon-ai/po-hook',\n providerOverrides: composeServerProviderOverrides(rootSession),\n session: async (context) => {\n const scopeSession = await rootSession(context);\n const contextSession = { ...context, root: scopeSession.value };\n return {\n ...composeRootHooks(scopeSession),\n get hooks(): PoServerSessionPlugin['hooks'] { return [via({ event: 'agent_end' }, at(hookAgentEnd, contextSession)), via({ event: 'agent_settled' }, at(hookAgentSettled, contextSession)), via({ event: 'before_agent_start' }, at(hookBeforeAgentStart, contextSession)), via({ event: 'session_shutdown' }, at(hookSessionShutdown, contextSession)), via({ event: 'session_start' }, at(hookSessionStart, contextSession)), via({ event: 'tool_call' }, at(hookToolCall, contextSession)), via({ event: 'tool_result' }, at(hookToolResult, contextSession))]; },\n get resources(): PoServerSessionPlugin['resources'] { return [at(resourcePoAuthorHook, contextSession)]; },\n services: [...(scopeSession.services ?? [])],\n get activities(): PoServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default facet;\n"],"mappings":";;;;;;;;;;;;;AAAA,MAAa,gBAAgB;AAC7B,MAAa,uBAAuB;;AAepC,MAAa,yBAAyB;AAEtC,MAAa,4BAA4B;;;ACAzC,SAAS,OAAO,OAAgB,4BAAY,IAAI,IAAY,GAAY;CACtE,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW,OAAO;CACtF,IAAI,OAAO,UAAU,UAAU,OAAO,OAAO,SAAS,KAAK;CAC3D,IAAI,OAAO,UAAU,YAAY,UAAU,IAAI,KAAK,GAAG,OAAO;CAC9D,UAAU,IAAI,KAAK;CACnB,MAAM,SACH,MAAM,QAAQ,KAAK,KAAK,OAAO,eAAe,KAAK,MAAM,OAAO,cACjE,OAAO,OAAO,KAAK,CAAC,CAAC,OAAO,UAAU,OAAO,OAAO,SAAS,CAAC;CAChE,UAAU,OAAO,KAAK;CACtB,OAAO;AACT;AAEA,SA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AM,iBAAiB;GAAE,GAAG;GAAS,MAAM,aAAa;EAAM;EAC9D,OAAO;GACL,IAAA,GAAGC,iCAAAA,iBAAAA,CAAiB,YAAY;GAChC,IAAI,QAAwC;IAAE,OAAO;KAAC,IAAI,EAAE,OAAO,YAAY,GAAG,GAAGC,0BAAc,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,gBAAgB,GAAG,GAAGC,8BAAkB,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,qBAAqB,GAAG,GAAGC,mCAAsB,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,mBAAmB,GAAG,GAAGC,iCAAqB,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,gBAAgB,GAAG,GAAGC,8BAAkB,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,YAAY,GAAG,GAAGC,0BAAc,cAAc,CAAC;KAAG,IAAI,EAAE,OAAO,cAAc,GAAG,GAAGC,4BAAgB,cAAc,CAAC;IAAC;GAAG;GACniB,IAAI,YAAgD;IAAE,OAAO,CAAC,GAAGC,+BAAsB,cAAc,CAAC;GAAG;GACzG,UAAU,CAAC,GAAI,aAAa,YAAY,CAAC,CAAE;GAC3C,IAAI,aAAkD;IAAE,OAAO,CAAC,GAAI,aAAa,cAAc,CAAC,CAAE;GAAG;EACvG;CACF;AACF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  //#region generated/server.d.ts
2
- export declare const facet: import("@agimon-ai/po-core/serverFacet").DoomServerFacet;
2
+ export declare const facet: import("@agimon-ai/po-core/serverFacet").PoServerFacet;
3
3
  //#endregion
4
4
  export { facet as default };
5
5
  //# sourceMappingURL=server.d.mts.map
@@ -1,11 +1,11 @@
1
- import { a as createBashHookRunner, b as isDenied, c as createHookDocumentReader, d as selectRegistryHooks, g as decisionReason, h as additionalContextsFrom, i as createHookTelemetry, n as HOOK_EVENT, o as sessionHookPayload, r as selectPluginHooks, s as toolHookPayload, t as createHookModules, x as toolResultMessages, y as hookFailureMessage } from "../hookModules-GoRDG8mg.mjs";
1
+ import { a as createBashHookRunner, b as isDenied, c as createHookDocumentReader, d as selectRegistryHooks, g as decisionReason, h as additionalContextsFrom, i as createHookTelemetry, n as HOOK_EVENT, o as sessionHookPayload, r as selectPluginHooks, s as toolHookPayload, t as createHookModules, x as toolResultMessages, y as hookFailureMessage } from "../hookModules-ClLNr9FP.mjs";
2
2
  import { composeServerProviderOverrides, defineServerPlugin, packageResourcePath, readPackageResource } from "@agimon-ai/po-core/serverFacet";
3
3
  import { composeRootHooks, defineHook, defineResource, defineRoot } from "@agimon-ai/po-core/extensionFile";
4
- import { DoomHeadlessPromptAdmissionError } from "@agimon-ai/po-core/headless";
5
- import { requireDoomConfigContext } from "@agimon-ai/po-config/piContext";
6
- import { DOOM_CHILD_SESSION_HOOKS_SERVICE } from "@agimon-ai/po-core/childSession";
7
- import { DOOM_CONFIG_SERVICE } from "@agimon-ai/po-core/config";
8
- import { DOOM_HELP_WHEN } from "@agimon-ai/po-core/help";
4
+ import { PoHeadlessPromptAdmissionError } from "@agimon-ai/po-core/headless";
5
+ import { requirePoConfigContext } from "@agimon-ai/po-config/piContext";
6
+ import { PO_CHILD_SESSION_HOOKS_SERVICE } from "@agimon-ai/po-core/childSession";
7
+ import { PO_CONFIG_SERVICE } from "@agimon-ai/po-core/config";
8
+ import { PO_HELP_WHEN } from "@agimon-ai/po-core/help";
9
9
  //#region src/constants/hookHandlers.ts
10
10
  const STATUS_PREFIX = "repository-hooks";
11
11
  const FAILURE_MESSAGE_TYPE = "repository-hook-failure";
@@ -161,7 +161,7 @@ async function dispatchHooks(session, scope, request) {
161
161
  }
162
162
  //#endregion
163
163
  //#region src/services/hookRuntime/type.ts
164
- const DOOM_HOOK_SESSION_SERVICE = "doom/hook-session";
164
+ const PO_HOOK_SESSION_SERVICE = "po/hook-session";
165
165
  //#endregion
166
166
  //#region src/services/hookRuntime/index.ts
167
167
  function createHookSession(config, options, signal) {
@@ -271,7 +271,7 @@ function createHookRuntime(cordis, options, parentContext, lifetimeSignal) {
271
271
  const controller = new AbortController();
272
272
  const signal = lifetimeSignal ? AbortSignal.any([controller.signal, lifetimeSignal]) : controller.signal;
273
273
  const session = {
274
- ...createHookSession(() => requireDoomConfigContext(cordis), options, signal),
274
+ ...createHookSession(() => requirePoConfigContext(cordis), options, signal),
275
275
  parentContext
276
276
  };
277
277
  let disposal;
@@ -292,11 +292,11 @@ function createHookBinding(options, parentContext, lifetimeSignal) {
292
292
  let runtime;
293
293
  return {
294
294
  plugin(cordis) {
295
- cordis.inject([DOOM_CONFIG_SERVICE], (configContext) => {
295
+ cordis.inject([PO_CONFIG_SERVICE], (configContext) => {
296
296
  const binding = createHookRuntime(configContext, options, parentContext, lifetimeSignal);
297
297
  runtime = binding;
298
- configContext.provide(DOOM_CHILD_SESSION_HOOKS_SERVICE, binding.childHooks);
299
- configContext.provide(DOOM_HOOK_SESSION_SERVICE, binding);
298
+ configContext.provide(PO_CHILD_SESSION_HOOKS_SERVICE, binding.childHooks);
299
+ configContext.provide(PO_HOOK_SESSION_SERVICE, binding);
300
300
  return async () => {
301
301
  if (runtime === binding) runtime = void 0;
302
302
  await binding.dispose();
@@ -325,7 +325,7 @@ function scopeFor(runtime, execution) {
325
325
  signal: runtime.session.signal,
326
326
  operationSignal: execution.signal,
327
327
  async sendMessage(text, delivery) {
328
- if (!execution.session.admitPrompt) throw new DoomHeadlessPromptAdmissionError("The session cannot admit a hook prompt.");
328
+ if (!execution.session.admitPrompt) throw new PoHeadlessPromptAdmissionError("The session cannot admit a hook prompt.");
329
329
  await execution.session.admitPrompt(text, delivery);
330
330
  },
331
331
  appendCustomEntry: (type, data) => execution.session.appendCustomEntry(type, data)
@@ -416,7 +416,7 @@ function createServerHooks(resolveRuntime) {
416
416
  async handle(event, execution) {
417
417
  const runtime = resolveRuntime();
418
418
  if (runtime?.isCurrent()) await start(runtime, execution);
419
- await execution.session.appendCustomEntry("doom-hook", hookEntry(event));
419
+ await execution.session.appendCustomEntry("po-hook", hookEntry(event));
420
420
  }
421
421
  },
422
422
  toolCall: {
@@ -453,7 +453,7 @@ function createServerHooks(resolveRuntime) {
453
453
  toolResult: {
454
454
  event: "tool_result",
455
455
  async handle(event, execution) {
456
- await execution.session.appendCustomEntry("doom-hook", hookEntry(event));
456
+ await execution.session.appendCustomEntry("po-hook", hookEntry(event));
457
457
  const runtime = resolveRuntime();
458
458
  if (!runtime?.isCurrent()) return;
459
459
  await start(runtime, execution);
@@ -480,7 +480,7 @@ function createServerHooks(resolveRuntime) {
480
480
  },
481
481
  agentSettled: {
482
482
  event: "agent_settled",
483
- handle: (event, execution) => execution.session.appendCustomEntry("doom-hook", hookEntry(event))
483
+ handle: (event, execution) => execution.session.appendCustomEntry("po-hook", hookEntry(event))
484
484
  },
485
485
  sessionShutdown: {
486
486
  event: "session_shutdown",
@@ -494,7 +494,7 @@ function createServerHooks(resolveRuntime) {
494
494
  }
495
495
  await shutdown;
496
496
  }
497
- execution.client.setStatus("doom-hook", void 0);
497
+ execution.client.setStatus("po-hook", void 0);
498
498
  }
499
499
  }
500
500
  };
@@ -513,7 +513,7 @@ const createHookServerRoot = ({ agent, signal }) => {
513
513
  return execution.model;
514
514
  },
515
515
  async sendMessage(text, delivery) {
516
- if (!execution.session.admitPrompt) throw new DoomHeadlessPromptAdmissionError("The session cannot admit a hook prompt.");
516
+ if (!execution.session.admitPrompt) throw new PoHeadlessPromptAdmissionError("The session cannot admit a hook prompt.");
517
517
  await execution.session.admitPrompt(text, delivery);
518
518
  },
519
519
  appendCustomEntry: (type, data) => execution.session.appendCustomEntry(type, data)
@@ -552,7 +552,7 @@ var tool_result_server_default = defineHook(({ root }) => root.toolResult);
552
552
  var po_author_hook_server_default = defineResource({
553
553
  name: "po-author-hook",
554
554
  description: "Author Po repository or plugin hooks. Use when creating or changing .po/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to Po.",
555
- when: DOOM_HELP_WHEN,
555
+ when: PO_HELP_WHEN,
556
556
  kind: "skill",
557
557
  path: packageResourcePath(import.meta.url, "src/prompts/po-author-hook/SKILL.md"),
558
558
  read: async () => {