Agents: reuse shared subagent hook runner type

This commit is contained in:
Gustavo Madeira Santana
2026-03-29 20:04:55 -04:00
parent 6e1f00dc86
commit cc04153d01
4 changed files with 9 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
import { vi, type Mock } from "vitest";
import type { SubagentLifecycleHookRunner } from "../plugins/hooks.js";
import {
__testing as subagentAnnounceDeliveryTesting,
resolveRequesterStoreKey,
@@ -11,7 +12,6 @@ import {
} from "./subagent-announce.js";
import { __testing as subagentRegistryTesting } from "./subagent-registry.js";
import { __testing as subagentSpawnTesting } from "./subagent-spawn.js";
import type { SubagentLifecycleHookRunner } from "./subagent-spawn.js";
type SessionsSpawnTestConfig = ReturnType<(typeof import("../config/config.js"))["loadConfig"]>;
type SessionsSpawnHookRunner = SubagentLifecycleHookRunner | null;

View File

@@ -1,5 +1,6 @@
import os from "node:os";
import { expect, vi } from "vitest";
import type { SubagentLifecycleHookRunner } from "../plugins/hooks.js";
type MockFn = (...args: unknown[]) => unknown;
type MockImplementationTarget = {
@@ -7,10 +8,7 @@ type MockImplementationTarget = {
};
type SessionStore = Record<string, Record<string, unknown>>;
type SessionStoreMutator = (store: SessionStore) => unknown;
type HookRunner = {
hasHooks: (name?: string) => boolean;
runSubagentSpawning?: (...args: unknown[]) => Promise<unknown>;
};
type HookRunner = Pick<SubagentLifecycleHookRunner, "hasHooks" | "runSubagentSpawning">;
export function createSubagentSpawnTestConfig(
workspaceDir = os.tmpdir(),

View File

@@ -10,6 +10,7 @@ import {
resolveGatewaySessionStoreTarget,
} from "../gateway/session-utils.js";
import { getGlobalHookRunner } from "../plugins/hook-runner-global.js";
import type { SubagentLifecycleHookRunner } from "../plugins/hooks.js";
import {
isValidAgentId,
isCronSessionKey,
@@ -57,11 +58,6 @@ type SubagentSpawnDeps = {
updateSessionStore: typeof updateSessionStore;
};
export type SubagentLifecycleHookRunner = Pick<
NonNullable<ReturnType<typeof getGlobalHookRunner>>,
"hasHooks" | "runSubagentSpawning" | "runSubagentSpawned" | "runSubagentEnded"
>;
const defaultSubagentSpawnDeps: SubagentSpawnDeps = {
callGateway,
getGlobalHookRunner,