@agimon-ai/po-hook 0.0.0-alpha.0
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/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/apiContracts.cjs +17 -0
- package/dist/apiContracts.cjs.map +1 -0
- package/dist/apiContracts.d.mts +53 -0
- package/dist/apiContracts.d.mts.map +1 -0
- package/dist/apiContracts.mjs +13 -0
- package/dist/apiContracts.mjs.map +1 -0
- package/dist/authoring.cjs +10 -0
- package/dist/authoring.cjs.map +1 -0
- package/dist/authoring.d.mts +7 -0
- package/dist/authoring.d.mts.map +1 -0
- package/dist/authoring.mjs +9 -0
- package/dist/authoring.mjs.map +1 -0
- package/dist/extensions/mcp.cjs +26 -0
- package/dist/extensions/mcp.cjs.map +1 -0
- package/dist/extensions/mcp.d.mts +5 -0
- package/dist/extensions/mcp.d.mts.map +1 -0
- package/dist/extensions/mcp.mjs +21 -0
- package/dist/extensions/mcp.mjs.map +1 -0
- package/dist/extensions/server.cjs +611 -0
- package/dist/extensions/server.cjs.map +1 -0
- package/dist/extensions/server.d.mts +5 -0
- package/dist/extensions/server.d.mts.map +1 -0
- package/dist/extensions/server.mjs +606 -0
- package/dist/extensions/server.mjs.map +1 -0
- package/dist/hookModule-f-HwSbmi.d.mts +54 -0
- package/dist/hookModule-f-HwSbmi.d.mts.map +1 -0
- package/dist/hookModules-DSheklXp.cjs +899 -0
- package/dist/hookModules-DSheklXp.cjs.map +1 -0
- package/dist/hookModules-GoRDG8mg.mjs +749 -0
- package/dist/hookModules-GoRDG8mg.mjs.map +1 -0
- package/dist/index.cjs +23 -0
- package/dist/index.d.mts +362 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/llms.txt +11 -0
- package/package.json +122 -0
- package/src/prompts/po-author-hook/SKILL.md +128 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hookModules-GoRDG8mg.mjs","names":["parseYaml","spawn","spawnProcess","fs"],"sources":["../src/constants/hookDecisions.ts","../src/services/hookDecisions/index.ts","../src/constants/hookDocuments.ts","../src/constants/telemetry.ts","../src/services/toolNames/index.ts","../src/services/hookRegistry/index.ts","../src/services/hookDocuments/index.ts","../src/constants/hookPayload.ts","../src/services/hookPayload/index.ts","../src/constants/hookRunner.ts","../src/services/hookRunner/index.ts","../src/constants/hookTelemetry.ts","../src/services/hookTelemetry/index.ts","../src/services/pluginHooks/index.ts","../src/constants/hooks.ts","../src/services/hookModules/index.ts"],"sourcesContent":["export const BLOCK_DECISION = 'block';\nexport const DENY_PERMISSION = 'deny';\n","import { BLOCK_DECISION, DENY_PERMISSION } from '../../constants/hookDecisions';\nimport type { HookDecision, HookFailure, HookOutcome } from '../../types/hooks';\n\nexport function decisionsFrom(outcomes: ReadonlyArray<HookOutcome>): HookDecision[] {\n return outcomes.flatMap((outcome) => (outcome.decision ? [outcome.decision] : []));\n}\n\nexport function failuresFrom(outcomes: ReadonlyArray<HookOutcome>): HookFailure[] {\n return outcomes.flatMap((outcome) => (outcome.failure ? [outcome.failure] : []));\n}\n\n/** Both spellings a hook may use to refuse the call it observed. */\nexport function isDenied(decision: HookDecision | undefined): boolean {\n return decision?.decision === BLOCK_DECISION || decision?.hookSpecificOutput?.permissionDecision === DENY_PERMISSION;\n}\n\nexport function decisionReason(decision: HookDecision | undefined): string | undefined {\n return decision?.reason ?? decision?.hookSpecificOutput?.reason;\n}\n\n/** Context a hook wants added to the conversation rather than used to block. */\nexport function additionalContextsFrom(decisions: ReadonlyArray<HookDecision>): string[] {\n return decisions\n .map((decision) => decision.hookSpecificOutput?.additionalContext)\n .filter((value): value is string => Boolean(value));\n}\n\n/** What a post-tool hook has to say, whichever field it said it in. */\nexport function toolResultMessages(decisions: ReadonlyArray<HookDecision>): string[] {\n return decisions\n .map((decision) => decision.hookSpecificOutput?.additionalContext ?? decisionReason(decision))\n .filter((value): value is string => Boolean(value));\n}\n\n/**\n * A guardrail that never ran looks exactly like one that passed, so the agent is\n * told which checks were missed and what its options are.\n */\nexport function hookFailureMessage(failures: ReadonlyArray<HookFailure>): string {\n return [\n 'One or more repository hooks did not complete, so their checks were not applied:',\n ...failures.map((failure) => `- ${failure.command}: ${failure.message}`),\n 'Options:',\n '- Inspect the hook command or configuration and rerun after correcting it.',\n '- Continue only if the missed advisory check is acceptable.',\n '- Ask the user before bypassing a hook that may enforce a guardrail.',\n ].join('\\n');\n}\n","export const HOOKS_FILE = 'hooks.yaml';\nexport const FILE_ENCODING = 'utf8';\nexport const FILE_NOT_FOUND_ERROR = 'ENOENT';\nexport const REGISTRY_SOURCE_ATTRIBUTE = 'repository';\n","export const HOOK_TELEMETRY_EVENT = {\n hookFailed: 'doom_pi_hook.failed',\n hookRegistryReadFailed: 'doom_pi_hook.registry_read_failed',\n} as const;\n","/**\n * Pi's tool names translated into the Claude names hook matchers are written\n * against.\n *\n * Hook authors write `matcher: Bash`, and Pi reports `bash`, so a matcher would\n * never fire without this. Only this direction belongs here: rewriting Claude\n * names for Pi is an agent-definition concern the harness owns.\n */\nconst PI_TO_CLAUDE = new Map([\n ['read', 'Read'],\n ['edit', 'Edit'],\n ['write', 'Write'],\n ['bash', 'Bash'],\n ['find', 'Glob'],\n ['grep', 'Grep'],\n ['subagent', 'Agent'],\n]);\n\n/** The Claude name a hook matcher expects for a tool Pi just ran. */\nexport function toClaudeToolName(tool: string): string {\n return PI_TO_CLAUDE.get(tool) ?? tool;\n}\n\n/** Whether a matcher, if the row declares one, accepts the tool that fired. */\nexport function matchesTool(matcher: string | undefined, toolName: string | undefined): boolean {\n if (!toolName || !matcher) return true;\n return new RegExp(matcher).test(toClaudeToolName(toolName));\n}\n","import path from 'node:path';\n\nimport type { HookDocumentSource, ParsedRegistrySource, RegistryEntry, ResolvedHook } from '../../types/hooks';\nimport { matchesTool } from '../toolNames';\n\n/** Which rows a dispatch keeps, once the session's selection is known. */\nexport interface RegistrySelection {\n event: string;\n toolName?: string;\n /** Selected group ids, or undefined for \"every group\", the standalone default. */\n allowedGroups?: readonly string[];\n inSubagent: boolean;\n}\n\n/**\n * Identity of a set of registry sources, for callers that cache the parse.\n *\n * Keyed on contents rather than mtime, so it stays correct for an in-place\n * rewrite and needs no invalidation hook. Reading both files is cheap; parsing\n * is what a cache built on this skips.\n */\nexport function registryCacheKey(sources: ReadonlyArray<HookDocumentSource>): string {\n return sources.map((source) => `${source.registryId ?? source.baseDirectory} ${source.text}`).join(' ');\n}\n\n/**\n * Flattens parsed registry documents into sorted rows, keeping only bindings\n * that declare a `pi` frontend.\n *\n * A later source replaces the group of the same id outright rather than merging\n * into it, so a repository that redefines a group owns it completely.\n */\nexport function registryEntries(sources: ReadonlyArray<ParsedRegistrySource>): RegistryEntry[] {\n const groups = new Map<string, RegistryEntry[]>();\n let position = 0;\n for (const source of sources) {\n for (const [groupId, group] of Object.entries(source.document.groups ?? {})) {\n const entries: RegistryEntry[] = [];\n for (const [rowIndex, hook] of (group.hooks ?? []).entries()) {\n // Every declared hook advances the position, whether or not it is kept,\n // so the sort tiebreaker stays the order the file declares them in.\n position += 1;\n if (!hook.pi) continue;\n const registryId = source.registryId ?? path.join(source.baseDirectory, '.po/hooks.yaml');\n const rowId = String(rowIndex);\n const attribution = `${registryId}: group ${groupId}, row ${rowId}, event ${hook.event}`;\n const binding = hook.pi;\n const hasCommand = binding.command !== undefined;\n const hasModule = binding.module !== undefined;\n if (hasCommand === hasModule) throw new Error(`${attribution}: declare exactly one of command or module`);\n const target = hasCommand ? binding.command : binding.module;\n if (typeof target !== 'string' || !target.trim() || target.includes('\\0')) {\n throw new Error(`${attribution}: command or module must be a nonempty string without NUL`);\n }\n if (binding.timeout !== undefined && (!Number.isFinite(binding.timeout) || binding.timeout <= 0)) {\n throw new Error(`${attribution}: timeout must be a positive finite number`);\n }\n if (hasModule && !['SessionStart', 'PreToolUse', 'PostToolUse', 'Stop'].includes(hook.event)) {\n throw new Error(`${attribution}: unsupported module event`);\n }\n entries.push({\n matcher: binding.matcher,\n timeout: binding.timeout,\n skipInSubagent: binding.skipInSubagent,\n ...(hasModule ? { module: path.resolve(source.baseDirectory, target) } : { command: target }),\n registryId,\n rowId,\n event: hook.event,\n order: hook.pi.order ?? 0,\n position,\n groupId,\n core: group.core === true,\n baseDirectory: source.baseDirectory,\n });\n }\n groups.set(groupId, entries);\n }\n }\n\n const entries = [...groups.values()].flat();\n entries.sort((left, right) => left.order - right.order || left.position - right.position);\n return entries;\n}\n\n/**\n * The rows one dispatch runs.\n *\n * Group selection changes when /mode switches mid-session, so inclusion is\n * applied per call rather than being baked into a cached parse. Core groups\n * always load; the rest are gated by the layers the harness resolved.\n */\nexport function selectRegistryHooks(\n entries: ReadonlyArray<RegistryEntry>,\n selection: RegistrySelection,\n): ResolvedHook[] {\n const allowed = selection.allowedGroups === undefined ? undefined : new Set(selection.allowedGroups);\n return entries\n .filter((entry) => entry.core || !allowed || allowed.has(entry.groupId))\n .filter((entry) => entry.event === selection.event)\n .filter((entry) => !(entry.skipInSubagent && selection.inSubagent))\n .filter((entry) => matchesTool(entry.matcher, selection.toolName))\n .map((entry) => ({\n hook:\n entry.module === undefined\n ? { command: entry.command, timeout: entry.timeout }\n : { module: entry.module, timeout: entry.timeout },\n registryId: entry.registryId,\n groupId: entry.groupId,\n rowId: entry.rowId,\n event: entry.event,\n // The declaring config's root, so a global hook can reach its own scripts\n // through CLAUDE_PLUGIN_ROOT while still running against this repository.\n root: entry.baseDirectory,\n }));\n}\n","import fs from 'node:fs';\n\nimport { doomConfigCandidates } from '@agimon-ai/po-config/layeredConfig';\nimport { parse as parseYaml } from 'yaml';\n\nimport {\n HOOKS_FILE,\n FILE_ENCODING,\n FILE_NOT_FOUND_ERROR,\n REGISTRY_SOURCE_ATTRIBUTE,\n} from '../../constants/hookDocuments';\nimport { HOOK_TELEMETRY_EVENT } from '../../constants/telemetry';\nimport type {\n HookDocumentReader,\n HookDocumentSource,\n PluginDocumentRead,\n PluginHookConfig,\n PluginHookDocument,\n PluginHookSourceRef,\n RegistryDocument,\n RegistryEntry,\n RegistryRead,\n} from '../../types/hooks';\nimport { type HookTelemetry } from '../../types/telemetry';\nimport { registryCacheKey, registryEntries } from '../hookRegistry';\n\nexport interface HookDocumentReaderOptions {\n telemetry?: HookTelemetry;\n /** Where the global `.po` directory lives. Defaults to the user's home. */\n homeDirectory?: string;\n readFile?: (filePath: string) => Promise<string>;\n warn?: (message: string) => void;\n}\n\nfunction reason(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction isMissingFile(error: unknown): boolean {\n return (error as NodeJS.ErrnoException | undefined)?.code === FILE_NOT_FOUND_ERROR;\n}\n\n/**\n * Reads `.po/hooks.yaml` from the global config directory and the repository,\n * and the plugin hook configs the harness resolved.\n *\n * Every file is re-read on every dispatch: it costs almost nothing and keeps an\n * in-place rewrite visible, which an mtime check would miss when two writes land\n * inside the same filesystem timestamp granularity. Both caches are keyed on\n * contents instead, so parsing — the expensive half — is what they skip.\n */\nexport function createHookDocumentReader(options: HookDocumentReaderOptions = {}): HookDocumentReader {\n const readFile = options.readFile ?? ((filePath: string) => fs.promises.readFile(filePath, FILE_ENCODING));\n const telemetry = options.telemetry;\n const warn = options.warn ?? ((message: string) => void process.stderr.write(message));\n let cachedRegistryKey: string | undefined;\n let cachedRegistryEntries: RegistryEntry[] = [];\n const pluginConfigCache = new Map<string, { source: string; config: PluginHookConfig }>();\n\n const readSource = async (candidate: {\n filePath: string;\n baseDirectory: string;\n }): Promise<HookDocumentSource | undefined> => {\n try {\n return {\n registryId: candidate.filePath,\n baseDirectory: candidate.baseDirectory,\n text: await readFile(candidate.filePath),\n };\n } catch (error) {\n if (isMissingFile(error)) return undefined;\n throw error;\n }\n };\n\n const parseSources = (sources: ReadonlyArray<HookDocumentSource>): RegistryEntry[] => {\n const key = registryCacheKey(sources);\n if (cachedRegistryKey === key) return cachedRegistryEntries;\n cachedRegistryEntries = registryEntries(\n sources.map((source) => ({\n registryId: source.registryId,\n baseDirectory: source.baseDirectory,\n document: (parseYaml(source.text) ?? {}) as RegistryDocument,\n })),\n );\n cachedRegistryKey = key;\n return cachedRegistryEntries;\n };\n\n return {\n async registry(repoRoot: string): Promise<RegistryRead> {\n const candidates = doomConfigCandidates(HOOKS_FILE, repoRoot, options.homeDirectory);\n // Named for the error path only. A registry absent from both locations is\n // a repository with no hooks, not a failure, so only a file that exists\n // and cannot be read or parsed reaches the catch below.\n const registryPath = candidates.map((candidate) => candidate.filePath).join(' and ');\n try {\n const sources = (await Promise.all(candidates.map(readSource))).filter(\n (source): source is HookDocumentSource => source !== undefined,\n );\n return { entries: parseSources(sources) };\n } catch (error) {\n // This empties the registry for the whole dispatch, so every repository\n // hook silently stops running rather than any one of them failing.\n void telemetry?.recordError(HOOK_TELEMETRY_EVENT.hookRegistryReadFailed, error, {\n 'hook.registry.source': REGISTRY_SOURCE_ATTRIBUTE,\n });\n warn(`[pi-hook] could not read ${registryPath}: ${reason(error)}\\n`);\n return { entries: [], failure: { command: registryPath, message: reason(error), reason: 'registry_read' } };\n }\n },\n\n async plugins(sources: readonly PluginHookSourceRef[]): Promise<PluginDocumentRead> {\n const documents: PluginHookDocument[] = [];\n const failures: PluginDocumentRead['failures'] = [];\n for (const source of sources) {\n try {\n const text = await readFile(source.configPath);\n const cached = pluginConfigCache.get(source.configPath);\n const config = cached?.source === text ? cached.config : (JSON.parse(text) as PluginHookConfig);\n pluginConfigCache.set(source.configPath, { source: text, config });\n documents.push({ pluginRoot: source.pluginRoot, config });\n } catch (error) {\n failures.push({ command: source.configPath, message: reason(error), reason: 'plugin_config' });\n }\n }\n return { documents, failures };\n },\n };\n}\n","export const TOOL_RESULT_EVENT = 'tool_result';\n","import { TOOL_RESULT_EVENT } from '../../constants/hookPayload';\nimport type { HookPayload, HookToolEvent } from '../../types/hooks';\nimport { toClaudeToolName } from '../toolNames';\n\n/** The payload shape a Claude Code session hook is written against. */\nexport function toolHookPayload(\n event: HookToolEvent,\n hookEventName: string,\n repoRoot: string,\n sessionId: string,\n identity: { parentSessionId?: string; agent?: string } = {},\n): HookPayload {\n return {\n session_id: sessionId,\n transcript_path: '',\n cwd: repoRoot,\n hook_event_name: hookEventName,\n tool_name: toClaudeToolName(event.toolName),\n tool_input: event.input,\n ...(event.type === TOOL_RESULT_EVENT ? { tool_response: { success: !event.isError, content: event.content } } : {}),\n ...(identity.parentSessionId === undefined ? {} : { parent_session_id: identity.parentSessionId }),\n ...(identity.agent === undefined ? {} : { agent_type: identity.agent }),\n };\n}\n\n/** Session lifecycle hooks observe no tool, so they only need where and who. */\nexport function sessionHookPayload(sessionId: string, repoRoot: string): HookPayload {\n return { session_id: sessionId, cwd: repoRoot };\n}\n","export const HOOK_SHELL = '/bin/bash';\nexport const HOOK_SHELL_COMMAND_FLAG = '-c';\nexport const HOOK_TERMINATION_GRACE_MS = 2_000;\nexport const DEFAULT_HOOK_TIMEOUT_SECONDS = 10;\nexport const MILLISECONDS_PER_SECOND = 1_000;\nexport const PROCESS_NOT_FOUND_ERROR = 'ESRCH';\nexport const BROKEN_PIPE_ERROR = 'EPIPE';\nexport const WINDOWS_PLATFORM = 'win32';\nexport const UNKNOWN_EXIT_CODE = -1;\nexport const JSON_LINE_START = '{';\nexport const LINE_BREAK = /\\r?\\n/;\n","import { spawn as spawnProcess } from 'node:child_process';\n\nimport {\n HOOK_SHELL,\n HOOK_SHELL_COMMAND_FLAG,\n HOOK_TERMINATION_GRACE_MS,\n DEFAULT_HOOK_TIMEOUT_SECONDS,\n MILLISECONDS_PER_SECOND,\n PROCESS_NOT_FOUND_ERROR,\n BROKEN_PIPE_ERROR,\n WINDOWS_PLATFORM,\n UNKNOWN_EXIT_CODE,\n JSON_LINE_START,\n LINE_BREAK,\n} from '../../constants/hookRunner';\nimport { HOOK_TELEMETRY_EVENT } from '../../constants/telemetry';\nimport type {\n HookCommand,\n HookDecision,\n HookOutcome,\n HookPayload,\n HookRunOptions,\n HookRunner,\n} from '../../types/hooks';\nimport { type HookTelemetry } from '../../types/telemetry';\n\nexport interface BashHookRunnerOptions {\n telemetry?: HookTelemetry;\n env?: NodeJS.ProcessEnv;\n platform?: NodeJS.Platform;\n spawn?: typeof spawnProcess;\n warn?: (message: string) => void;\n}\n\nfunction errorCode(error: unknown): string | undefined {\n return error instanceof Error && 'code' in error ? String(error.code) : undefined;\n}\n\n/**\n * Runs advisory hook commands through bash and reports what each one decided.\n *\n * A hook is a command the repository owns, so it is spawned in its own process\n * group and terminated as one: a hook that starts a server and stalls should\n * not leave the server behind when the timeout fires.\n */\nexport function createBashHookRunner(options: BashHookRunnerOptions = {}): HookRunner {\n const spawn = options.spawn ?? spawnProcess;\n const telemetry = options.telemetry;\n const warn = options.warn ?? ((message: string) => void process.stderr.write(message));\n const useProcessGroup = (options.platform ?? process.platform) !== WINDOWS_PLATFORM;\n\n const signalOwnedProcess = (\n pid: number | undefined,\n kill: (signal: NodeJS.Signals) => void,\n ): ((signal: NodeJS.Signals) => void) => {\n return (signal) => {\n try {\n if (useProcessGroup && pid !== undefined) {\n process.kill(-pid, signal);\n return;\n }\n kill(signal);\n } catch (error) {\n if (errorCode(error) !== PROCESS_NOT_FOUND_ERROR) {\n process.emitWarning(`Could not signal repository hook process: ${String(error)}`);\n }\n }\n };\n };\n\n return {\n run(hook: HookCommand, payload: HookPayload, runOptions: HookRunOptions): Promise<HookOutcome> {\n const timeoutSeconds = hook.timeout ?? DEFAULT_HOOK_TIMEOUT_SECONDS;\n const environment = options.env ?? process.env;\n return new Promise((resolve) => {\n // -c, not -lc. Hooks run on every tool call, and a login shell would\n // source the developer's profile each time: per-call latency plus hook\n // behavior that varies with their dotfiles. The child inherits the\n // environment below, so it keeps the PATH the launcher started with.\n const child = spawn(HOOK_SHELL, [HOOK_SHELL_COMMAND_FLAG, hook.command], {\n cwd: runOptions.repoRoot,\n env: {\n ...environment,\n CLAUDE_PROJECT_DIR: runOptions.repoRoot,\n CODEX_REPO_ROOT: runOptions.repoRoot,\n ORIGINAL_REPO_PATH: environment.ORIGINAL_REPO_PATH ?? runOptions.repoRoot,\n ...(runOptions.pluginRoot ? { CLAUDE_PLUGIN_ROOT: runOptions.pluginRoot } : {}),\n },\n stdio: ['pipe', 'pipe', 'pipe'],\n detached: useProcessGroup,\n });\n let stdout = '';\n let stderr = '';\n let settled = false;\n let timedOut = false;\n let childExited = false;\n let timeoutExitCode: number | null = null;\n let stdinError: Error | undefined;\n let escalationTimer: NodeJS.Timeout | undefined;\n\n const signal = signalOwnedProcess(child.pid, (value) => child.kill(value));\n\n const ownedProcessIsAlive = (): boolean => {\n if (!useProcessGroup || child.pid === undefined) return !childExited;\n try {\n process.kill(-child.pid, 0);\n return true;\n } catch (error) {\n return errorCode(error) !== PROCESS_NOT_FOUND_ERROR;\n }\n };\n\n const finish = (outcome: HookOutcome = {}): void => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n if (escalationTimer) clearTimeout(escalationTimer);\n resolve(outcome);\n };\n\n const finishTimeout = (): void => {\n const message = `Hook timed out after ${timeoutSeconds} seconds.`;\n void telemetry?.recordWarning(HOOK_TELEMETRY_EVENT.hookFailed, message, {\n 'hook.reason': 'timeout',\n 'hook.exit_code': timeoutExitCode ?? UNKNOWN_EXIT_CODE,\n });\n warn(`[pi-hook] advisory hook timed out: ${hook.command}\\n${stderr}`);\n finish({ failure: { command: hook.command, message, reason: 'timeout' } });\n };\n\n const timer = setTimeout(() => {\n timedOut = true;\n signal('SIGTERM');\n escalationTimer = setTimeout(() => {\n if (ownedProcessIsAlive()) signal('SIGKILL');\n finishTimeout();\n }, HOOK_TERMINATION_GRACE_MS);\n }, timeoutSeconds * MILLISECONDS_PER_SECOND);\n\n child.stdin?.on('error', (error: Error) => {\n // Hooks may exit or close stdin without consuming the entire payload.\n // Keep this listener through settlement: a pending write can fail later.\n if (settled || timedOut || errorCode(error) === BROKEN_PIPE_ERROR) return;\n stdinError = error;\n });\n child.stdout?.on('data', (chunk: Buffer) => {\n stdout += chunk.toString();\n });\n child.stderr?.on('data', (chunk: Buffer) => {\n stderr += chunk.toString();\n });\n child.once('error', (error: Error) => {\n if (timedOut) return;\n // A guardrail that never ran is indistinguishable from one that\n // passed, which is the whole reason these are worth reporting.\n void telemetry?.recordError(HOOK_TELEMETRY_EVENT.hookFailed, error, { 'hook.reason': 'spawn_failed' });\n warn(`[pi-hook] advisory hook failed: ${error.message}\\n`);\n finish({ failure: { command: hook.command, message: error.message, reason: 'spawn_failed' } });\n });\n child.once('exit', (code: number | null) => {\n childExited = true;\n timeoutExitCode = code;\n if (timedOut) return;\n if (code !== 0) {\n const message = stderr.trim() || `Advisory hook exited with code ${code ?? 'unknown'}`;\n void telemetry?.recordWarning(HOOK_TELEMETRY_EVENT.hookFailed, message, {\n 'hook.reason': 'non_zero_exit',\n 'hook.exit_code': code ?? UNKNOWN_EXIT_CODE,\n });\n warn(`[pi-hook] advisory hook failed (${code}): ${hook.command}\\n${stderr}`);\n finish({ failure: { command: hook.command, message, reason: 'non_zero_exit' } });\n return;\n }\n if (stdinError) {\n void telemetry?.recordError(HOOK_TELEMETRY_EVENT.hookFailed, stdinError, { 'hook.reason': 'stdin_failed' });\n warn(`[pi-hook] advisory hook could not write stdin: ${stdinError.message}\\n`);\n finish({ failure: { command: hook.command, message: stdinError.message, reason: 'stdin_failed' } });\n return;\n }\n const jsonLine = stdout\n .trim()\n .split(LINE_BREAK)\n .reverse()\n .find((line) => line.startsWith(JSON_LINE_START));\n if (!jsonLine) {\n finish();\n return;\n }\n try {\n finish({ decision: JSON.parse(jsonLine) as HookDecision });\n } catch (error) {\n // The hook ran and had an opinion, and it was dropped.\n void telemetry?.recordWarning(HOOK_TELEMETRY_EVENT.hookFailed, error, { 'hook.reason': 'invalid_json' });\n warn(`[pi-hook] advisory hook returned invalid JSON: ${hook.command}\\n`);\n finish({\n failure: {\n command: hook.command,\n message: error instanceof Error ? error.message : String(error),\n reason: 'invalid_json',\n },\n });\n }\n });\n child.stdin?.end(JSON.stringify(payload));\n });\n },\n };\n}\n","export const SERVICE_NAME = 'po-hook';\nexport const PACKAGE_NAME = '@agimon-ai/po-hook';\n","import { createDoomTelemetry, type DoomTelemetry, type DoomTelemetryOptions } from '@agimon-ai/po-telemetry';\n\nimport { SERVICE_NAME, PACKAGE_NAME } from '../../constants/hookTelemetry';\nimport type { HookTelemetry } from '../../types/telemetry';\n\nexport interface HookTelemetryOptions {\n cwd?: string;\n workspaceRoot?: string;\n env?: NodeJS.ProcessEnv;\n telemetryFactory?: NonNullable<DoomTelemetryOptions['telemetryFactory']>;\n warn?: (message: string) => void;\n}\n\nexport function createHookTelemetry(options: HookTelemetryOptions = {}): HookTelemetry {\n const telemetry: DoomTelemetry = createDoomTelemetry({\n serviceName: SERVICE_NAME,\n packageName: PACKAGE_NAME,\n cwd: options.cwd,\n workspaceRoot: options.workspaceRoot,\n env: options.env,\n telemetryFactory: options.telemetryFactory,\n warn: options.warn,\n enableLogs: true,\n enableTraces: true,\n });\n return {\n recordError: (event, error, attributes) => telemetry.recordError(event, error, attributes),\n recordWarning: (event, error, attributes) => telemetry.recordWarning(event, error, attributes),\n };\n}\n","import type { PluginHookDocument, ResolvedHook } from '../../types/hooks';\nimport { matchesTool } from '../toolNames';\n\n/**\n * The plugin hooks one dispatch runs.\n *\n * Plugin configs are the Claude Code `hooks.json` shape verbatim: an event name\n * maps to groups, each with an optional matcher and a list of commands. Order\n * follows the declaration order of the plugins the harness resolved.\n */\nexport function selectPluginHooks(\n documents: ReadonlyArray<PluginHookDocument>,\n eventName: string,\n toolName?: string,\n): ResolvedHook[] {\n const matches: ResolvedHook[] = [];\n for (const document of documents) {\n for (const group of document.config.hooks?.[eventName] ?? []) {\n if (!matchesTool(group.matcher, toolName)) continue;\n for (const hook of group.hooks ?? []) matches.push({ hook, root: document.pluginRoot });\n }\n }\n return matches;\n}\n","export const HOOK_EVENT = {\n sessionStart: 'SessionStart',\n preToolUse: 'PreToolUse',\n postToolUse: 'PostToolUse',\n stop: 'Stop',\n sessionEnd: 'SessionEnd',\n} as const;\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport { DEFAULT_HOOK_TIMEOUT_SECONDS } from '../../constants/hookRunner';\nimport type {\n HookContext,\n HookHandlers,\n HookModule,\n HookModuleDescriptor,\n HookModuleResult,\n} from '../../types/hookModule';\nimport type { HookModuleOutcome, HookModules, HookModulesOptions } from './type';\n\ninterface Instance {\n lifetime: AbortController;\n queue: Promise<unknown>;\n handlers?: HookHandlers;\n quarantined: boolean;\n settled: boolean;\n disposed: boolean;\n hostEffectFailure?: { error: unknown };\n}\nfunction assertHostEffects(instance: Instance): void {\n if (instance.hostEffectFailure) throw instance.hostEffectFailure.error;\n}\nconst HANDLER_NAMES = ['tool_call', 'tool_result', 'session_start', 'agent_settled', 'dispose'] as const;\nfunction object(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\nfunction validateHandlers(value: unknown): asserts value is HookHandlers {\n if (\n !object(value) ||\n Object.entries(value).some(\n ([key, handler]) =>\n !HANDLER_NAMES.includes(key as (typeof HANDLER_NAMES)[number]) || typeof handler !== 'function',\n )\n ) {\n throw new Error('setup must return hook handlers');\n }\n}\nfunction jsonValue(value: unknown, ancestors = new Set<unknown>()): 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 if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype) return false;\n ancestors.add(value);\n const valid = Object.values(value).every((item) => jsonValue(item, ancestors));\n ancestors.delete(value);\n return valid;\n}\nfunction validResult(event: string, value: unknown): boolean {\n if (value === undefined) return true;\n if (!object(value)) return false;\n if (event === 'tool_call')\n return (\n Object.keys(value).every((key) => ['block', 'reason'].includes(key)) &&\n (value.block === undefined || typeof value.block === 'boolean') &&\n (value.reason === undefined || typeof value.reason === 'string')\n );\n if (event !== 'tool_result') return false;\n return (\n Object.keys(value).every((key) => ['content', 'details', 'isError'].includes(key)) &&\n (value.isError === undefined || typeof value.isError === 'boolean') &&\n (value.details === undefined || jsonValue(value.details)) &&\n (value.content === undefined ||\n (Array.isArray(value.content) &&\n value.content.every(\n (part) =>\n object(part) &&\n ((part.type === 'text' && typeof part.text === 'string') ||\n (part.type === 'image' && typeof part.data === 'string' && typeof part.mimeType === 'string')),\n )))\n );\n}\n\n/** One registry belongs to one session binding, never to the process. */\nexport function createHookModules(options: HookModulesOptions = {}): HookModules {\n const instances = new Map<string, Instance>();\n let descriptor: Promise<Map<string, string>> | undefined;\n let closed = false;\n let disposal: Promise<void> | undefined;\n function artifacts(): Promise<Map<string, string>> {\n descriptor ??= (async () => {\n if (!options.descriptor) return new Map<string, string>();\n const value: unknown = JSON.parse(await fs.readFile(options.descriptor.file, 'utf8'));\n if (!object(value) || value.version !== 1 || !Array.isArray(value.modules))\n throw new Error('invalid hook module descriptor');\n const result = new Map<string, string>();\n for (const entry of value.modules as HookModuleDescriptor['modules']) {\n if (\n !object(entry) ||\n typeof entry.source !== 'string' ||\n typeof entry.artifact !== 'string' ||\n !path.isAbsolute(entry.source) ||\n !path.isAbsolute(entry.artifact) ||\n !['.mjs', '.js', '.cjs'].includes(path.extname(entry.artifact)) ||\n result.has(entry.source)\n ) {\n throw new Error('invalid hook module artifact mapping');\n }\n result.set(entry.source, entry.artifact);\n }\n return result;\n })();\n return descriptor;\n }\n async function disposeInstance(instance: Instance): Promise<void> {\n if (!instance.handlers || instance.disposed) return;\n instance.disposed = true;\n await instance.handlers.dispose?.();\n }\n function contextFor(context: HookContext, instance: Instance, signal: AbortSignal): HookContext {\n function assertActive(message: boolean): void {\n if (closed || signal.aborted || instance.lifetime.signal.aborted) throw new Error('hook context revoked');\n if (message && instance.settled) throw new Error('agent_settled cannot send messages');\n }\n return {\n ...context,\n signal,\n async sendMessage(text, delivery) {\n assertActive(true);\n await context.sendMessage(text, delivery);\n },\n async appendCustomEntry(type, data) {\n assertActive(false);\n await context.appendCustomEntry(type, data);\n },\n };\n }\n return {\n async validate(rows): Promise<void> {\n for (const row of rows) {\n if (!row.module) continue;\n try {\n const artifact = (await artifacts()).get(row.module);\n if (!artifact) throw new Error('module missing from descriptor');\n const stat = await fs.stat(artifact);\n if (!stat.isFile()) throw new Error(`hook artifact is not a file: ${artifact}`);\n } catch (cause) {\n throw new Error(\n `${row.registryId ?? ''}: group ${row.groupId ?? ''}, row ${row.rowId ?? ''}, event ${row.event ?? ''}, module ${row.module}: ${cause instanceof Error ? cause.message : String(cause)}. Fix the hook module, then restart or reopen this session.`,\n { cause },\n );\n }\n }\n },\n async invoke(row, event, context, operationSignal): Promise<HookModuleOutcome> {\n const source = 'module' in row.hook ? row.hook.module : undefined;\n const failure = (error: unknown, timeout = false): HookModuleOutcome => ({\n failure: {\n command: source ?? '',\n reason: timeout ? 'timeout' : 'module_failed',\n message: `${row.registryId ?? ''}: group ${row.groupId ?? ''}, row ${row.rowId ?? ''}, event ${row.event ?? event.type}, module ${source ?? ''}: ${error instanceof Error ? error.message : String(error)}`,\n },\n });\n if (!source) return failure(new Error('not a module row'));\n if (closed || context.signal.aborted) return failure(new Error('hook session disposed'));\n const key = `${context.sessionId}\\0${source}`;\n let instance = instances.get(key);\n if (!instance) {\n instance = {\n lifetime: new AbortController(),\n queue: Promise.resolve(),\n quarantined: false,\n settled: false,\n disposed: false,\n };\n instances.set(key, instance);\n }\n const current = instance;\n const hostContext: HookContext = {\n ...context,\n async sendMessage(text, delivery) {\n try {\n await context.sendMessage(text, delivery);\n } catch (error) {\n current.hostEffectFailure = { error };\n throw error;\n }\n },\n async appendCustomEntry(type, data) {\n try {\n await context.appendCustomEntry(type, data);\n } catch (error) {\n current.hostEffectFailure = { error };\n throw error;\n }\n },\n };\n const run = async (): Promise<HookModuleOutcome> => {\n if (closed || current.quarantined || current.lifetime.signal.aborted)\n return failure(new Error('module quarantined or disposed'));\n current.hostEffectFailure = undefined;\n current.settled = event.type === 'agent_settled';\n const controller = new AbortController();\n const signal = AbortSignal.any([\n context.signal,\n current.lifetime.signal,\n controller.signal,\n ...(operationSignal ? [operationSignal] : []),\n ]);\n let timer: ReturnType<typeof setTimeout> | undefined;\n let setup = !current.handlers;\n let timedOut = false;\n const operation = (async () => {\n if (!current.handlers) {\n const artifact = (await artifacts()).get(source);\n if (!artifact) throw new Error('sync required: module missing from descriptor');\n const imported: { default?: unknown } = await import(pathToFileURL(artifact).href);\n if (signal.aborted) throw new Error('hook context aborted');\n if (!object(imported.default) || typeof imported.default.setup !== 'function')\n throw new Error('module default export must declare setup');\n const handlers = await (imported.default as unknown as HookModule).setup(\n contextFor(hostContext, current, AbortSignal.any([context.signal, current.lifetime.signal])),\n );\n validateHandlers(handlers);\n current.handlers = handlers;\n if (closed || current.quarantined || signal.aborted) {\n await disposeInstance(current);\n return undefined;\n }\n }\n setup = false;\n const ctx = contextFor(hostContext, current, signal);\n switch (event.type) {\n case 'tool_call':\n return current.handlers.tool_call?.(event, ctx);\n case 'tool_result':\n return current.handlers.tool_result?.(event, ctx);\n case 'session_start':\n return current.handlers.session_start?.(event, ctx);\n case 'agent_settled':\n return current.handlers.agent_settled?.(event, ctx);\n }\n })();\n try {\n const aborted = new Promise<never>((_, reject) => {\n const abort = () => reject(new Error(timedOut ? 'hook module timed out' : 'hook context aborted'));\n signal.addEventListener('abort', abort, { once: true });\n operation.finally(() => signal.removeEventListener('abort', abort)).catch(() => undefined);\n if (signal.aborted) abort();\n timer = setTimeout(\n () => {\n timedOut = true;\n controller.abort();\n },\n (row.hook.timeout ?? DEFAULT_HOOK_TIMEOUT_SECONDS) * 1000,\n );\n });\n const result = await Promise.race([operation, aborted]);\n assertHostEffects(current);\n if (!validResult(event.type, result))\n return { failure: { ...failure(new Error('invalid hook result')).failure!, reason: 'invalid_result' } };\n return result === undefined ? {} : { result: result as HookModuleResult };\n } catch (error) {\n assertHostEffects(current);\n if (setup || timedOut || signal.aborted) {\n current.quarantined = true;\n current.lifetime.abort();\n }\n return failure(error, timedOut);\n } finally {\n clearTimeout(timer);\n controller.abort();\n current.settled = false;\n }\n };\n const invocation = current.queue.then(run);\n // Admission failures still reject the caller, but must not poison serialization.\n current.queue = invocation.catch(() => undefined);\n return invocation;\n },\n dispose(): Promise<void> {\n disposal ??= (async () => {\n closed = true;\n for (const instance of instances.values()) instance.lifetime.abort();\n await Promise.all(\n [...instances.values()].map(async (instance) => {\n await instance.queue;\n await disposeInstance(instance);\n }),\n );\n })();\n return disposal;\n },\n };\n}\n"],"mappings":";;;;;;;;;;ACGA,SAAgB,cAAc,UAAsD;CAClF,OAAO,SAAS,SAAS,YAAa,QAAQ,WAAW,CAAC,QAAQ,QAAQ,IAAI,CAAC,CAAE;AACnF;AAEA,SAAgB,aAAa,UAAqD;CAChF,OAAO,SAAS,SAAS,YAAa,QAAQ,UAAU,CAAC,QAAQ,OAAO,IAAI,CAAC,CAAE;AACjF;;AAGA,SAAgB,SAAS,UAA6C;CACpE,OAAO,UAAU,aAAA,WAA+B,UAAU,oBAAoB,uBAAA;AAChF;AAEA,SAAgB,eAAe,UAAwD;CACrF,OAAO,UAAU,UAAU,UAAU,oBAAoB;AAC3D;;AAGA,SAAgB,uBAAuB,WAAkD;CACvF,OAAO,UACJ,KAAK,aAAa,SAAS,oBAAoB,iBAAiB,CAAC,CACjE,QAAQ,UAA2B,QAAQ,KAAK,CAAC;AACtD;;AAGA,SAAgB,mBAAmB,WAAkD;CACnF,OAAO,UACJ,KAAK,aAAa,SAAS,oBAAoB,qBAAqB,eAAe,QAAQ,CAAC,CAAC,CAC7F,QAAQ,UAA2B,QAAQ,KAAK,CAAC;AACtD;;;;;AAMA,SAAgB,mBAAmB,UAA8C;CAC/E,OAAO;EACL;EACA,GAAG,SAAS,KAAK,YAAY,KAAK,QAAQ,QAAQ,IAAI,QAAQ,SAAS;EACvE;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI;AACb;;;AC/CA,MAAa,aAAa;AAE1B,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;;;ACHzC,MAAa,uBAAuB;CAClC,Y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AU;IACpB;GACF;GACA,MAAM,aAAa,QAAQ,MAAM,KAAK,GAAG;GAEzC,QAAQ,QAAQ,WAAW,YAAY,KAAA,CAAS;GAChD,OAAO;EACT;EACA,UAAyB;GACvB,cAAc,YAAY;IACxB,SAAS;IACT,KAAK,MAAM,YAAY,UAAU,OAAO,GAAG,SAAS,SAAS,MAAM;IACnE,MAAM,QAAQ,IACZ,CAAC,GAAG,UAAU,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,aAAa;KAC9C,MAAM,SAAS;KACf,MAAM,gBAAgB,QAAQ;IAChC,CAAC,CACH;GACF,EAAA,CAAG;GACH,OAAO;EACT;CACF;AACF"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_hookModules = require("./hookModules-DSheklXp.cjs");
|
|
3
|
+
exports.HOOK_EVENT = require_hookModules.HOOK_EVENT;
|
|
4
|
+
exports.HOOK_TELEMETRY_EVENT = require_hookModules.HOOK_TELEMETRY_EVENT;
|
|
5
|
+
exports.additionalContextsFrom = require_hookModules.additionalContextsFrom;
|
|
6
|
+
exports.createBashHookRunner = require_hookModules.createBashHookRunner;
|
|
7
|
+
exports.createHookDocumentReader = require_hookModules.createHookDocumentReader;
|
|
8
|
+
exports.createHookModules = require_hookModules.createHookModules;
|
|
9
|
+
exports.createHookTelemetry = require_hookModules.createHookTelemetry;
|
|
10
|
+
exports.decisionReason = require_hookModules.decisionReason;
|
|
11
|
+
exports.decisionsFrom = require_hookModules.decisionsFrom;
|
|
12
|
+
exports.failuresFrom = require_hookModules.failuresFrom;
|
|
13
|
+
exports.hookFailureMessage = require_hookModules.hookFailureMessage;
|
|
14
|
+
exports.isDenied = require_hookModules.isDenied;
|
|
15
|
+
exports.matchesTool = require_hookModules.matchesTool;
|
|
16
|
+
exports.registryCacheKey = require_hookModules.registryCacheKey;
|
|
17
|
+
exports.registryEntries = require_hookModules.registryEntries;
|
|
18
|
+
exports.selectPluginHooks = require_hookModules.selectPluginHooks;
|
|
19
|
+
exports.selectRegistryHooks = require_hookModules.selectRegistryHooks;
|
|
20
|
+
exports.sessionHookPayload = require_hookModules.sessionHookPayload;
|
|
21
|
+
exports.toClaudeToolName = require_hookModules.toClaudeToolName;
|
|
22
|
+
exports.toolHookPayload = require_hookModules.toolHookPayload;
|
|
23
|
+
exports.toolResultMessages = require_hookModules.toolResultMessages;
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { c as HookNativeEvent, o as HookModuleDescriptor, r as HookContext, s as HookModuleResult } from "./hookModule-f-HwSbmi.mjs";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { DoomTelemetryOptions } from "@agimon-ai/po-telemetry";
|
|
4
|
+
import { DoomChildSessionHooks } from "@agimon-ai/po-core/childSession";
|
|
5
|
+
import { DoomConfigContext } from "@agimon-ai/po-config/types";
|
|
6
|
+
import "@deepseek-ai/cordis";
|
|
7
|
+
//#region src/constants/hooks.d.ts
|
|
8
|
+
export declare const HOOK_EVENT: {
|
|
9
|
+
readonly sessionStart: 'SessionStart';
|
|
10
|
+
readonly preToolUse: 'PreToolUse';
|
|
11
|
+
readonly postToolUse: 'PostToolUse';
|
|
12
|
+
readonly stop: 'Stop';
|
|
13
|
+
readonly sessionEnd: 'SessionEnd';
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/types/hooks.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* The hook document contract and the ports that run it.
|
|
19
|
+
*
|
|
20
|
+
* Every name here is written in Claude Code's vocabulary, because that is what
|
|
21
|
+
* `.po/hooks.yaml` and plugin `hooks.json` files are authored against. The
|
|
22
|
+
* translation onto Pi's lifecycle happens at the adapter boundary.
|
|
23
|
+
*/
|
|
24
|
+
/** Registry event names. Each is used twice per dispatch, so drift would be silent. */
|
|
25
|
+
type HookEventName = (typeof HOOK_EVENT)[keyof typeof HOOK_EVENT];
|
|
26
|
+
interface HookCommand {
|
|
27
|
+
command: string;
|
|
28
|
+
/** Seconds before the hook is terminated. Defaults to DEFAULT_HOOK_TIMEOUT_SECONDS. */
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
/** What one registry row declares for the `pi` frontend. */
|
|
32
|
+
interface RegistryBindingOptions {
|
|
33
|
+
matcher?: string;
|
|
34
|
+
timeout?: number;
|
|
35
|
+
skipInSubagent?: boolean;
|
|
36
|
+
order?: number;
|
|
37
|
+
}
|
|
38
|
+
type RegistryBinding = RegistryBindingOptions & ({
|
|
39
|
+
command: string;
|
|
40
|
+
module?: never;
|
|
41
|
+
} | {
|
|
42
|
+
module: string;
|
|
43
|
+
command?: never;
|
|
44
|
+
});
|
|
45
|
+
/** A registry row plus the group membership used to include or drop it. */
|
|
46
|
+
type RegistryEntry = RegistryBinding & {
|
|
47
|
+
registryId: string;
|
|
48
|
+
rowId: string;
|
|
49
|
+
event: string;
|
|
50
|
+
order: number;
|
|
51
|
+
/** Declaration order across every source, used as the sort tiebreaker. */
|
|
52
|
+
position: number;
|
|
53
|
+
groupId: string;
|
|
54
|
+
core: boolean;
|
|
55
|
+
/** Root of the config that declared the group, exported as CLAUDE_PLUGIN_ROOT. */
|
|
56
|
+
baseDirectory: string;
|
|
57
|
+
};
|
|
58
|
+
interface RegistryGroup {
|
|
59
|
+
core?: boolean;
|
|
60
|
+
hooks?: Array<{
|
|
61
|
+
event: string;
|
|
62
|
+
pi?: RegistryBinding;
|
|
63
|
+
}>;
|
|
64
|
+
}
|
|
65
|
+
interface RegistryDocument {
|
|
66
|
+
groups?: Record<string, RegistryGroup>;
|
|
67
|
+
}
|
|
68
|
+
/** One `.po/hooks.yaml` as read from disk, before it is parsed. */
|
|
69
|
+
interface HookDocumentSource {
|
|
70
|
+
baseDirectory: string;
|
|
71
|
+
registryId?: string;
|
|
72
|
+
text: string;
|
|
73
|
+
}
|
|
74
|
+
/** One `.po/hooks.yaml` after parsing, tagged with the root that declared it. */
|
|
75
|
+
interface ParsedRegistrySource {
|
|
76
|
+
baseDirectory: string;
|
|
77
|
+
registryId?: string;
|
|
78
|
+
document: RegistryDocument;
|
|
79
|
+
}
|
|
80
|
+
interface PluginHookGroup {
|
|
81
|
+
matcher?: string;
|
|
82
|
+
hooks?: HookCommand[];
|
|
83
|
+
}
|
|
84
|
+
interface PluginHookConfig {
|
|
85
|
+
hooks?: Record<string, PluginHookGroup[]>;
|
|
86
|
+
}
|
|
87
|
+
/** A parsed plugin config plus the root exported to its commands. */
|
|
88
|
+
interface PluginHookDocument {
|
|
89
|
+
pluginRoot: string;
|
|
90
|
+
config: PluginHookConfig;
|
|
91
|
+
}
|
|
92
|
+
/** A hook command paired with the config root it runs against. */
|
|
93
|
+
interface ResolvedHook {
|
|
94
|
+
hook: HookCommand | {
|
|
95
|
+
module: string;
|
|
96
|
+
command?: never;
|
|
97
|
+
timeout?: number;
|
|
98
|
+
};
|
|
99
|
+
registryId?: string;
|
|
100
|
+
groupId?: string;
|
|
101
|
+
rowId?: string;
|
|
102
|
+
event?: string;
|
|
103
|
+
root: string;
|
|
104
|
+
}
|
|
105
|
+
/** The JSON a hook may write on stdout to steer or block the call it observed. */
|
|
106
|
+
interface HookDecision {
|
|
107
|
+
decision?: string;
|
|
108
|
+
reason?: string;
|
|
109
|
+
hookSpecificOutput?: {
|
|
110
|
+
permissionDecision?: string;
|
|
111
|
+
reason?: string;
|
|
112
|
+
additionalContext?: string;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
type HookFailureReason = 'spawn_failed' | 'stdin_failed' | 'non_zero_exit' | 'timeout' | 'invalid_json' | 'registry_read' | 'plugin_config' | 'hook_execution' | 'module_failed' | 'invalid_result';
|
|
116
|
+
interface HookFailure {
|
|
117
|
+
command: string;
|
|
118
|
+
message: string;
|
|
119
|
+
reason: HookFailureReason;
|
|
120
|
+
}
|
|
121
|
+
interface HookOutcome {
|
|
122
|
+
decision?: HookDecision;
|
|
123
|
+
failure?: HookFailure;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The tool fields a payload is built from, named without importing Pi.
|
|
127
|
+
*
|
|
128
|
+
* Pi's ToolCallEvent and ToolResultEvent both satisfy this structurally, so the
|
|
129
|
+
* adapter forwards them unchanged and the payload builder stays host-neutral.
|
|
130
|
+
*/
|
|
131
|
+
interface HookToolEvent {
|
|
132
|
+
readonly type: string;
|
|
133
|
+
readonly toolName: string;
|
|
134
|
+
readonly input: unknown;
|
|
135
|
+
readonly content?: readonly unknown[];
|
|
136
|
+
readonly isError?: boolean;
|
|
137
|
+
}
|
|
138
|
+
/** The JSON document handed to a hook on stdin. */
|
|
139
|
+
type HookPayload = Record<string, unknown>;
|
|
140
|
+
interface HookRunOptions {
|
|
141
|
+
repoRoot: string;
|
|
142
|
+
/** Exported as CLAUDE_PLUGIN_ROOT so a hook can reach its own scripts. */
|
|
143
|
+
pluginRoot?: string;
|
|
144
|
+
}
|
|
145
|
+
/** Runs one hook command and reports what it decided or how it failed. */
|
|
146
|
+
interface HookRunner {
|
|
147
|
+
run(hook: HookCommand, payload: HookPayload, options: HookRunOptions): Promise<HookOutcome>;
|
|
148
|
+
}
|
|
149
|
+
/** Registry rows for this repository, or the failure that emptied them. */
|
|
150
|
+
interface RegistryRead {
|
|
151
|
+
entries: RegistryEntry[];
|
|
152
|
+
failure?: HookFailure;
|
|
153
|
+
}
|
|
154
|
+
/** Plugin configs that could be read, and one failure per config that could not. */
|
|
155
|
+
interface PluginDocumentRead {
|
|
156
|
+
documents: PluginHookDocument[];
|
|
157
|
+
failures: HookFailure[];
|
|
158
|
+
}
|
|
159
|
+
/** Where a plugin declares its hooks. Mirrors the harness state entry. */
|
|
160
|
+
interface PluginHookSourceRef {
|
|
161
|
+
readonly pluginRoot: string;
|
|
162
|
+
readonly configPath: string;
|
|
163
|
+
}
|
|
164
|
+
/** Reads the hook documents a session runs from. */
|
|
165
|
+
interface HookDocumentReader {
|
|
166
|
+
registry(repoRoot: string): Promise<RegistryRead>;
|
|
167
|
+
plugins(sources: readonly PluginHookSourceRef[]): Promise<PluginDocumentRead>;
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/services/hookDecisions/index.d.ts
|
|
171
|
+
export declare function decisionsFrom(outcomes: ReadonlyArray<HookOutcome>): HookDecision[];
|
|
172
|
+
export declare function failuresFrom(outcomes: ReadonlyArray<HookOutcome>): HookFailure[];
|
|
173
|
+
/** Both spellings a hook may use to refuse the call it observed. */
|
|
174
|
+
export declare function isDenied(decision: HookDecision | undefined): boolean;
|
|
175
|
+
export declare function decisionReason(decision: HookDecision | undefined): string | undefined;
|
|
176
|
+
/** Context a hook wants added to the conversation rather than used to block. */
|
|
177
|
+
export declare function additionalContextsFrom(decisions: ReadonlyArray<HookDecision>): string[];
|
|
178
|
+
/** What a post-tool hook has to say, whichever field it said it in. */
|
|
179
|
+
export declare function toolResultMessages(decisions: ReadonlyArray<HookDecision>): string[];
|
|
180
|
+
/**
|
|
181
|
+
* A guardrail that never ran looks exactly like one that passed, so the agent is
|
|
182
|
+
* told which checks were missed and what its options are.
|
|
183
|
+
*/
|
|
184
|
+
export declare function hookFailureMessage(failures: ReadonlyArray<HookFailure>): string;
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/constants/telemetry.d.ts
|
|
187
|
+
export declare const HOOK_TELEMETRY_EVENT: {
|
|
188
|
+
readonly hookFailed: 'doom_pi_hook.failed';
|
|
189
|
+
readonly hookRegistryReadFailed: 'doom_pi_hook.registry_read_failed';
|
|
190
|
+
};
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/types/telemetry.d.ts
|
|
193
|
+
/** Telemetry events this package reports, and the port that records them. */
|
|
194
|
+
type HookTelemetryEventName = (typeof HOOK_TELEMETRY_EVENT)[keyof typeof HOOK_TELEMETRY_EVENT];
|
|
195
|
+
type HookTelemetryAttributes = Record<string, string | number | boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* A hook that never ran is indistinguishable from one that passed, which is why
|
|
198
|
+
* both a failed run and an unreadable registry are worth reporting rather than
|
|
199
|
+
* swallowing.
|
|
200
|
+
*/
|
|
201
|
+
interface HookTelemetry {
|
|
202
|
+
recordError(event: HookTelemetryEventName, error: unknown, attributes?: HookTelemetryAttributes): Promise<void>;
|
|
203
|
+
recordWarning(event: HookTelemetryEventName, error: unknown, attributes?: HookTelemetryAttributes): Promise<void>;
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/services/hookDocuments/index.d.ts
|
|
207
|
+
interface HookDocumentReaderOptions {
|
|
208
|
+
telemetry?: HookTelemetry;
|
|
209
|
+
/** Where the global `.po` directory lives. Defaults to the user's home. */
|
|
210
|
+
homeDirectory?: string;
|
|
211
|
+
readFile?: (filePath: string) => Promise<string>;
|
|
212
|
+
warn?: (message: string) => void;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Reads `.po/hooks.yaml` from the global config directory and the repository,
|
|
216
|
+
* and the plugin hook configs the harness resolved.
|
|
217
|
+
*
|
|
218
|
+
* Every file is re-read on every dispatch: it costs almost nothing and keeps an
|
|
219
|
+
* in-place rewrite visible, which an mtime check would miss when two writes land
|
|
220
|
+
* inside the same filesystem timestamp granularity. Both caches are keyed on
|
|
221
|
+
* contents instead, so parsing — the expensive half — is what they skip.
|
|
222
|
+
*/
|
|
223
|
+
export declare function createHookDocumentReader(options?: HookDocumentReaderOptions): HookDocumentReader;
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/services/hookPayload/index.d.ts
|
|
226
|
+
/** The payload shape a Claude Code session hook is written against. */
|
|
227
|
+
export declare function toolHookPayload(event: HookToolEvent, hookEventName: string, repoRoot: string, sessionId: string, identity?: {
|
|
228
|
+
parentSessionId?: string;
|
|
229
|
+
agent?: string;
|
|
230
|
+
}): HookPayload;
|
|
231
|
+
/** Session lifecycle hooks observe no tool, so they only need where and who. */
|
|
232
|
+
export declare function sessionHookPayload(sessionId: string, repoRoot: string): HookPayload;
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/services/hookRegistry/index.d.ts
|
|
235
|
+
/** Which rows a dispatch keeps, once the session's selection is known. */
|
|
236
|
+
interface RegistrySelection {
|
|
237
|
+
event: string;
|
|
238
|
+
toolName?: string;
|
|
239
|
+
/** Selected group ids, or undefined for "every group", the standalone default. */
|
|
240
|
+
allowedGroups?: readonly string[];
|
|
241
|
+
inSubagent: boolean;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Identity of a set of registry sources, for callers that cache the parse.
|
|
245
|
+
*
|
|
246
|
+
* Keyed on contents rather than mtime, so it stays correct for an in-place
|
|
247
|
+
* rewrite and needs no invalidation hook. Reading both files is cheap; parsing
|
|
248
|
+
* is what a cache built on this skips.
|
|
249
|
+
*/
|
|
250
|
+
export declare function registryCacheKey(sources: ReadonlyArray<HookDocumentSource>): string;
|
|
251
|
+
/**
|
|
252
|
+
* Flattens parsed registry documents into sorted rows, keeping only bindings
|
|
253
|
+
* that declare a `pi` frontend.
|
|
254
|
+
*
|
|
255
|
+
* A later source replaces the group of the same id outright rather than merging
|
|
256
|
+
* into it, so a repository that redefines a group owns it completely.
|
|
257
|
+
*/
|
|
258
|
+
export declare function registryEntries(sources: ReadonlyArray<ParsedRegistrySource>): RegistryEntry[];
|
|
259
|
+
/**
|
|
260
|
+
* The rows one dispatch runs.
|
|
261
|
+
*
|
|
262
|
+
* Group selection changes when /mode switches mid-session, so inclusion is
|
|
263
|
+
* applied per call rather than being baked into a cached parse. Core groups
|
|
264
|
+
* always load; the rest are gated by the layers the harness resolved.
|
|
265
|
+
*/
|
|
266
|
+
export declare function selectRegistryHooks(entries: ReadonlyArray<RegistryEntry>, selection: RegistrySelection): ResolvedHook[];
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/services/hookRunner/index.d.ts
|
|
269
|
+
interface BashHookRunnerOptions {
|
|
270
|
+
telemetry?: HookTelemetry;
|
|
271
|
+
env?: NodeJS.ProcessEnv;
|
|
272
|
+
platform?: NodeJS.Platform;
|
|
273
|
+
spawn?: typeof spawn;
|
|
274
|
+
warn?: (message: string) => void;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Runs advisory hook commands through bash and reports what each one decided.
|
|
278
|
+
*
|
|
279
|
+
* A hook is a command the repository owns, so it is spawned in its own process
|
|
280
|
+
* group and terminated as one: a hook that starts a server and stalls should
|
|
281
|
+
* not leave the server behind when the timeout fires.
|
|
282
|
+
*/
|
|
283
|
+
export declare function createBashHookRunner(options?: BashHookRunnerOptions): HookRunner;
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/services/hookModules/type.d.ts
|
|
286
|
+
interface HookModulesOptions {
|
|
287
|
+
descriptor?: {
|
|
288
|
+
file: string;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
interface HookModuleOutcome {
|
|
292
|
+
result?: HookModuleResult;
|
|
293
|
+
failure?: HookFailure;
|
|
294
|
+
}
|
|
295
|
+
interface HookModules {
|
|
296
|
+
validate(rows: readonly (Pick<ResolvedHook, 'registryId' | 'groupId' | 'rowId' | 'event'> & {
|
|
297
|
+
module?: string;
|
|
298
|
+
})[]): Promise<void>;
|
|
299
|
+
invoke(row: ResolvedHook, event: HookNativeEvent, context: HookContext, operationSignal?: AbortSignal): Promise<HookModuleOutcome>;
|
|
300
|
+
dispose(): Promise<void>;
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/services/hookRuntime/type.d.ts
|
|
304
|
+
interface HookExtensionOptions {
|
|
305
|
+
telemetry?: HookTelemetry;
|
|
306
|
+
runner?: HookRunner;
|
|
307
|
+
documents?: HookDocumentReader;
|
|
308
|
+
}
|
|
309
|
+
/** One host session owns its module registry and lifetime; children borrow only immutable config. */
|
|
310
|
+
interface HookSession {
|
|
311
|
+
config(): DoomConfigContext;
|
|
312
|
+
prepare(isSubagent?: boolean): Promise<void>;
|
|
313
|
+
readonly runner: HookRunner;
|
|
314
|
+
readonly documents: HookDocumentReader;
|
|
315
|
+
readonly modules: HookModules;
|
|
316
|
+
readonly signal: AbortSignal;
|
|
317
|
+
readonly parentContext?: Omit<HookContext, 'signal'>;
|
|
318
|
+
}
|
|
319
|
+
/** One dependency-complete Hook runtime owned by a reactive Cordis fiber. */
|
|
320
|
+
interface HookRuntime {
|
|
321
|
+
readonly session: HookSession;
|
|
322
|
+
readonly childHooks: DoomChildSessionHooks;
|
|
323
|
+
isCurrent(): boolean;
|
|
324
|
+
}
|
|
325
|
+
declare module '@deepseek-ai/cordis' {
|
|
326
|
+
interface Context {
|
|
327
|
+
'doom/hook-session': HookRuntime;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/services/hookTelemetry/index.d.ts
|
|
332
|
+
interface HookTelemetryOptions {
|
|
333
|
+
cwd?: string;
|
|
334
|
+
workspaceRoot?: string;
|
|
335
|
+
env?: NodeJS.ProcessEnv;
|
|
336
|
+
telemetryFactory?: NonNullable<DoomTelemetryOptions['telemetryFactory']>;
|
|
337
|
+
warn?: (message: string) => void;
|
|
338
|
+
}
|
|
339
|
+
export declare function createHookTelemetry(options?: HookTelemetryOptions): HookTelemetry;
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/services/pluginHooks/index.d.ts
|
|
342
|
+
/**
|
|
343
|
+
* The plugin hooks one dispatch runs.
|
|
344
|
+
*
|
|
345
|
+
* Plugin configs are the Claude Code `hooks.json` shape verbatim: an event name
|
|
346
|
+
* maps to groups, each with an optional matcher and a list of commands. Order
|
|
347
|
+
* follows the declaration order of the plugins the harness resolved.
|
|
348
|
+
*/
|
|
349
|
+
export declare function selectPluginHooks(documents: ReadonlyArray<PluginHookDocument>, eventName: string, toolName?: string): ResolvedHook[];
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/services/toolNames/index.d.ts
|
|
352
|
+
/** The Claude name a hook matcher expects for a tool Pi just ran. */
|
|
353
|
+
export declare function toClaudeToolName(tool: string): string;
|
|
354
|
+
/** Whether a matcher, if the row declares one, accepts the tool that fired. */
|
|
355
|
+
export declare function matchesTool(matcher: string | undefined, toolName: string | undefined): boolean;
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/services/hookModules/index.d.ts
|
|
358
|
+
/** One registry belongs to one session binding, never to the process. */
|
|
359
|
+
export declare function createHookModules(options?: HookModulesOptions): HookModules;
|
|
360
|
+
//#endregion
|
|
361
|
+
export type { BashHookRunnerOptions, HookCommand, HookContext, HookDecision, HookDocumentReader, HookDocumentReaderOptions, HookDocumentSource, HookEventName, HookExtensionOptions, HookFailure, HookFailureReason, HookModuleDescriptor, HookModuleOutcome, HookModuleResult, HookModules, HookModulesOptions, HookNativeEvent, HookOutcome, HookPayload, HookRunOptions, HookRunner, HookTelemetry, HookTelemetryAttributes, HookTelemetryEventName, HookTelemetryOptions, HookToolEvent, ParsedRegistrySource, PluginDocumentRead, PluginHookConfig, PluginHookDocument, PluginHookGroup, PluginHookSourceRef, RegistryBinding, RegistryDocument, RegistryEntry, RegistryGroup, RegistryRead, RegistrySelection, ResolvedHook };
|
|
362
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["spawnProcess"],"sources":["../src/constants/hooks.ts","../src/types/hooks.ts","../src/services/hookDecisions/index.ts","../src/constants/telemetry.ts","../src/types/telemetry.ts","../src/services/hookDocuments/index.ts","../src/services/hookPayload/index.ts","../src/services/hookRegistry/index.ts","../src/services/hookRunner/index.ts","../src/services/hookModules/type.ts","../src/services/hookRuntime/type.ts","../src/services/hookTelemetry/index.ts","../src/services/pluginHooks/index.ts","../src/services/toolNames/index.ts","../src/services/hookModules/index.ts"],"mappings":";;;;;;;qBAAa;WACX;WACA;WACA;WACA;WACA;;;;;;;;;;;;KCMU,wBAAwB,yBAAyB;UAE5C;EACf;;EAEA;;;UAIe;EACf;EACA;EACA;EACA;;KAGU,kBAAkB;EACzB;EAAiB;;EAAqB;EAA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,uBACA,kBACA,mBACA;EAAY;EAA0B;IACrC;;wBAea,mBAAmB,mBAAmB,mBAAmB;;;;UCpBxD;EACf;EACA;;EAEA;EACA;;;;;;;;;wBAUc,iBAAiB,SAAS,cAAc;;;;;;;;wBAWxC,gBAAgB,SAAS,cAAc,wBAAwB;;;;;;;;wBA2D/D,oBACd,SAAS,cAAc,gBACvB,WAAW,oBACV;;;UCpEc;EACf,YAAY;EACZ,MAAM,OAAO;EACb,WAAW,OAAO;EAClB,eAAeA;EACf,QAAQ;;;;;;;;;wBAcM,qBAAqB,UAAS,wBAA6B;;;UC1C1D;EACf;IAAe;;;UAEA;EACf,SAAS;EACT,UAAU;;UAEK;EACf,SACE,gBAAgB,KAAK;IAAgE;SACpF;EACH,OACE,KAAK,cACL,OAAO,iBACP,SAAS,aACT,kBAAkB,cACjB,QAAQ;EACX,WAAW;;;;UCVI;EACf,YAAY;EACZ,SAAS;EACT,YAAY;;;UAIG;EACf,UAAU;EACV,QAAQ,uBAAuB;WACtB,QAAQ;WACR,WAAW;WACX,SAAS;WACT,QAAQ;WACR,gBAAgB,KAAK;;;UAIf;WACN,SAAS;WACT,YAAY;EACrB;;;YAcU;IACR,qBAAqB;;;;;UCzCR;EACf;EACA;EACA,MAAM,OAAO;EACb,mBAAmB,YAAY;EAC/B,QAAQ;;wBAGM,oBAAoB,UAAS,uBAA4B;;;;;;;;;;wBCHzD,kBACd,WAAW,cAAc,qBACzB,mBACA,oBACC;;;;wBCKa,iBAAiB;;wBAKjB,YAAY,6BAA6B;;;;wBCqDzC,kBAAkB,UAAS,qBAA0B"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as decisionsFrom, a as createBashHookRunner, b as isDenied, c as createHookDocumentReader, d as selectRegistryHooks, f as matchesTool, g as decisionReason, h as additionalContextsFrom, i as createHookTelemetry, l as registryCacheKey, m as HOOK_TELEMETRY_EVENT, n as HOOK_EVENT, o as sessionHookPayload, p as toClaudeToolName, r as selectPluginHooks, s as toolHookPayload, t as createHookModules, u as registryEntries, v as failuresFrom, x as toolResultMessages, y as hookFailureMessage } from "./hookModules-GoRDG8mg.mjs";
|
|
2
|
+
export { HOOK_EVENT, HOOK_TELEMETRY_EVENT, additionalContextsFrom, createBashHookRunner, createHookDocumentReader, createHookModules, createHookTelemetry, decisionReason, decisionsFrom, failuresFrom, hookFailureMessage, isDenied, matchesTool, registryCacheKey, registryEntries, selectPluginHooks, selectRegistryHooks, sessionHookPayload, toClaudeToolName, toolHookPayload, toolResultMessages };
|
package/llms.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Doom Pi Hook
|
|
2
|
+
|
|
3
|
+
Compiled TypeScript modules and Claude-compatible command hooks for Po sessions.
|
|
4
|
+
|
|
5
|
+
## How to author
|
|
6
|
+
|
|
7
|
+
- [Author Po hooks](./src/prompts/po-author-hook/SKILL.md): Create `.doom/hooks.yaml` groups, compiled TypeScript modules, and Claude-compatible command hooks.
|
|
8
|
+
|
|
9
|
+
## Package reference
|
|
10
|
+
|
|
11
|
+
- [Package README](./README.md): The hook registry, group selection, event mapping, decisions, and failure handling.
|