import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  EventBuffer
} from "../../chunk-HIN3UVOG.js";
import {
  readStdin
} from "../../chunk-CQ4RKK67.js";
import {
  DaemonClient
} from "../../chunk-CPVXNRGW.js";
import "../../chunk-CK24O5YQ.js";
import {
  resolveVaultDir
} from "../../chunk-N33KUCFP.js";
import "../../chunk-RNWALAFP.js";
import {
  TOOL_OUTPUT_PREVIEW_CHARS
} from "../../chunk-WBLTISAK.js";
import "../../chunk-PZUWP5VK.js";

// src/hooks/post-tool-use.ts
import fs from "fs";
import path from "path";
async function main() {
  const VAULT_DIR = resolveVaultDir();
  if (!fs.existsSync(path.join(VAULT_DIR, "myco.yaml"))) return;
  try {
    const input = JSON.parse(await readStdin());
    const sessionId = input.session_id ?? process.env.MYCO_SESSION_ID ?? `s-${Date.now()}`;
    const client = new DaemonClient(VAULT_DIR);
    const result = await client.post("/events", {
      type: "tool_use",
      tool_name: input.tool_name,
      tool_input: input.tool_input,
      output_preview: typeof input.tool_output === "string" ? input.tool_output.slice(0, TOOL_OUTPUT_PREVIEW_CHARS) : void 0,
      session_id: sessionId
    });
    if (!result.ok) {
      const buffer = new EventBuffer(path.join(VAULT_DIR, "buffer"), sessionId);
      buffer.append({
        type: "tool_use",
        tool: input.tool_name,
        input: input.tool_input,
        output_preview: typeof input.tool_output === "string" ? input.tool_output.slice(0, TOOL_OUTPUT_PREVIEW_CHARS) : void 0
      });
    }
  } catch (error) {
    process.stderr.write(`[myco] post-tool-use error: ${error.message}
`);
  }
}
main();
//# sourceMappingURL=post-tool-use.js.map