feat: add prompt based hooks (#795)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
jnjpng
2026-02-05 17:55:00 -08:00
committed by GitHub
parent bbe02e90e8
commit ee28095ebc
11 changed files with 967 additions and 42 deletions

View File

@@ -2,7 +2,19 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { CommandHookConfig, HookCommand } from "../hooks/types";
import { settingsManager } from "../settings-manager";
// Type-safe helper to extract command from a hook (tests only use command hooks)
function asCommand(
hook: HookCommand | undefined,
): CommandHookConfig | undefined {
if (hook && hook.type === "command") {
return hook as CommandHookConfig;
}
return undefined;
}
import {
deleteSecureTokens,
isKeychainAvailable,
@@ -558,7 +570,7 @@ describe("Settings Manager - Hooks", () => {
const settings = settingsManager.getSettings();
expect(settings.hooks?.PreToolUse).toHaveLength(1);
expect(settings.hooks?.PreToolUse?.[0]?.hooks[0]?.command).toBe(
expect(asCommand(settings.hooks?.PreToolUse?.[0]?.hooks[0])?.command).toBe(
"echo persisted",
);
expect(settings.hooks?.SessionStart).toHaveLength(1);
@@ -631,7 +643,9 @@ describe("Settings Manager - Hooks", () => {
expect(reloaded.hooks?.Stop).toHaveLength(1);
// Simple event hooks are in SimpleHookMatcher format with hooks array
expect(reloaded.hooks?.Stop?.[0]?.hooks[0]?.command).toBe("echo stop-hook");
expect(asCommand(reloaded.hooks?.Stop?.[0]?.hooks[0])?.command).toBe(
"echo stop-hook",
);
});
test("All 11 hook event types can be configured", async () => {