fix(codex): harden lsp post tool hook

This commit is contained in:
YeonGyu-Kim
2026-05-31 05:41:23 +09:00
parent 19f1c3418f
commit 0f5a796739
5 changed files with 75 additions and 36 deletions
@@ -0,0 +1,33 @@
import { stdin as processStdin } from "node:process";
import { disposeDefaultLspManager } from "@code-yeongyu/lsp-tools-mcp/dist/lsp/manager.js";
import { isRecord, runLspPostToolUseHook } from "./codex-hook.js";
export async function runPostToolUseHookCli(stdin: NodeJS.ReadStream = processStdin): Promise<void> {
try {
const raw = await readStdin(stdin);
if (!raw.trim()) return;
let parsed: unknown;
try {
parsed = JSON.parse(raw);
} catch (error) {
if (error instanceof SyntaxError) return;
throw error;
}
const input = isRecord(parsed) ? parsed : {};
const output = await runLspPostToolUseHook(input);
if (output) process.stdout.write(output);
} finally {
await disposeDefaultLspManager();
}
}
async function readStdin(stdin: NodeJS.ReadStream): Promise<string> {
stdin.setEncoding("utf8");
let raw = "";
for await (const chunk of stdin) {
raw += chunk;
}
return raw;
}