#!/usr/bin/env bun
// @bun
import{execSync as X}from"child_process";import{existsSync as Y,readFileSync as Z}from"fs";import{join as $}from"path";function D(){process.exit(0)}function f(q){let G=q;try{G=X("git rev-parse --show-toplevel",{cwd:q,stdio:["ignore","pipe","ignore"]}).toString().trim()||q}catch{}for(let Q of new Set([G,q])){let H=$(Q,".mcp.json");try{if(Y(H)&&Z(H,"utf8").includes("beacon"))return!0}catch{}}return!1}var g=/@beacon:feature/i,j=/\b(feature|sub-?tasks?)\b/i,B=/\b(implement|build|add|create|design|develop|work on|wire up|ship|refactor)\b/i,J="";try{for await(let q of process.stdin)J+=q}catch{D()}var z="",P=process.cwd();try{let q=JSON.parse(J||"{}");if(typeof q.prompt==="string")z=q.prompt;if(typeof q.cwd==="string"&&q.cwd)P=q.cwd}catch{D()}var C=g.test(z)||j.test(z)&&B.test(z);if(!z||!C||!f(P))D();var I=["[Beacon] This looks like feature work. Follow Beacon's loop IN ORDER \u2014 do not start blind codebase searches:","1. Call beacon_context_for_feature({ id | title | query }) FIRST. It returns the attached files, 1-hop import blast radius, the domain's endpoints + tables + FK relations, sibling components, and conventions \u2014 and marks the feature active. That replaces the discovery phase.","2. Design data before code: if the feature needs tables that don't exist yet, call beacon_propose_plan (tables + relations + endpoints) and WAIT for approval on /plan before writing migrations or code.","3. When done, call beacon_describe_feature with the files you touched + a short markdown summary so the map and AGENTS.md stay accurate."].join(`
`);process.stdout.write(JSON.stringify({hookSpecificOutput:{hookEventName:"UserPromptSubmit",additionalContext:I}}));process.exit(0);
