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 "../../chunk-WBLTISAK.js";
import "../../chunk-PZUWP5VK.js";

// src/hooks/user-prompt-submit.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 prompt = input.prompt ?? "";
    const sessionId = input.session_id ?? `s-${Date.now()}`;
    const client = new DaemonClient(VAULT_DIR);
    if (!await client.isHealthy()) {
      client.spawnDaemon();
    }
    const eventResult = await client.post("/events", {
      type: "user_prompt",
      prompt,
      session_id: sessionId
    });
    if (!eventResult.ok) {
      const buffer = new EventBuffer(path.join(VAULT_DIR, "buffer"), sessionId);
      buffer.append({ type: "user_prompt", prompt });
    }
    const contextResult = await client.post("/context/prompt", {
      prompt,
      session_id: sessionId
    });
    const sessionLine = `Session:: \`${sessionId}\``;
    const contextText = contextResult.ok && contextResult.data?.text ? `${contextResult.data.text}
${sessionLine}` : sessionLine;
    process.stdout.write(contextText);
  } catch (error) {
    process.stderr.write(`[myco] user-prompt-submit error: ${error.message}
`);
  }
}
main();
//# sourceMappingURL=user-prompt-submit.js.map