feat(omo-codex): batch 79 (8 files)

This commit is contained in:
YeonGyu-Kim
2026-05-30 19:12:13 +09:00
parent a6193606ad
commit 08e0a989ea
8 changed files with 509 additions and 0 deletions
@@ -0,0 +1,49 @@
import {
createPluginPostHog,
getPostHogDistinctId,
type PostHogActivityReason,
type PostHogClient,
} from "./posthog.js";
export type CodexSessionStartInput = {
session_id: string;
transcript_path: string | null;
cwd: string;
hook_event_name: "SessionStart";
model: string;
permission_mode: string;
source: "startup" | "resume" | "clear";
};
export type CodexTelemetryHookOptions = {
createClient?: () => PostHogClient | Promise<PostHogClient>;
getDistinctId?: () => string;
};
const SESSION_START_REASON: PostHogActivityReason = "session_start";
export async function runSessionStartHook(
_input: CodexSessionStartInput,
options: CodexTelemetryHookOptions = {},
): Promise<string> {
const createClient = options.createClient ?? createPluginPostHog;
const getDistinctId = options.getDistinctId ?? getPostHogDistinctId;
const client = await createClient();
try {
client.trackActive(getDistinctId(), SESSION_START_REASON);
} catch {
await safeShutdown(client);
return "";
}
await safeShutdown(client);
return "";
}
async function safeShutdown(client: PostHogClient): Promise<void> {
try {
await client.shutdown();
} catch {
return;
}
}