trybeacon 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +6 -6
  3. package/.next/build-manifest.json +2 -2
  4. package/.next/prerender-manifest.json +3 -3
  5. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  6. package/.next/server/app/_global-error.html +1 -1
  7. package/.next/server/app/_global-error.rsc +1 -1
  8. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  12. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  15. package/.next/server/app/_not-found.html +1 -1
  16. package/.next/server/app/_not-found.rsc +1 -1
  17. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  18. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  19. package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  20. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  21. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  22. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  23. package/.next/server/app/docs/page_client-reference-manifest.js +1 -1
  24. package/.next/server/app/docs.html +1 -1
  25. package/.next/server/app/docs.rsc +1 -1
  26. package/.next/server/app/docs.segments/_full.segment.rsc +1 -1
  27. package/.next/server/app/docs.segments/_head.segment.rsc +1 -1
  28. package/.next/server/app/docs.segments/_index.segment.rsc +1 -1
  29. package/.next/server/app/docs.segments/_tree.segment.rsc +1 -1
  30. package/.next/server/app/docs.segments/docs/__PAGE__.segment.rsc +1 -1
  31. package/.next/server/app/docs.segments/docs.segment.rsc +1 -1
  32. package/.next/server/app/feedback/page_client-reference-manifest.js +1 -1
  33. package/.next/server/app/feedback.html +1 -1
  34. package/.next/server/app/feedback.rsc +1 -1
  35. package/.next/server/app/feedback.segments/_full.segment.rsc +1 -1
  36. package/.next/server/app/feedback.segments/_head.segment.rsc +1 -1
  37. package/.next/server/app/feedback.segments/_index.segment.rsc +1 -1
  38. package/.next/server/app/feedback.segments/_tree.segment.rsc +1 -1
  39. package/.next/server/app/feedback.segments/feedback/__PAGE__.segment.rsc +1 -1
  40. package/.next/server/app/feedback.segments/feedback.segment.rsc +1 -1
  41. package/.next/server/app/help/page_client-reference-manifest.js +1 -1
  42. package/.next/server/app/help.html +1 -1
  43. package/.next/server/app/help.rsc +1 -1
  44. package/.next/server/app/help.segments/_full.segment.rsc +1 -1
  45. package/.next/server/app/help.segments/_head.segment.rsc +1 -1
  46. package/.next/server/app/help.segments/_index.segment.rsc +1 -1
  47. package/.next/server/app/help.segments/_tree.segment.rsc +1 -1
  48. package/.next/server/app/help.segments/help/__PAGE__.segment.rsc +1 -1
  49. package/.next/server/app/help.segments/help.segment.rsc +1 -1
  50. package/.next/server/app/index.html +1 -1
  51. package/.next/server/app/index.rsc +1 -1
  52. package/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  53. package/.next/server/app/index.segments/_full.segment.rsc +1 -1
  54. package/.next/server/app/index.segments/_head.segment.rsc +1 -1
  55. package/.next/server/app/index.segments/_index.segment.rsc +1 -1
  56. package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  57. package/.next/server/app/map/page.js +2 -2
  58. package/.next/server/app/map/page.js.nft.json +1 -1
  59. package/.next/server/app/map/page_client-reference-manifest.js +1 -1
  60. package/.next/server/app/page_client-reference-manifest.js +1 -1
  61. package/.next/server/app/plan/page.js +1 -1
  62. package/.next/server/app/plan/page.js.nft.json +1 -1
  63. package/.next/server/app/plan/page_client-reference-manifest.js +1 -1
  64. package/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  65. package/.next/server/app-paths-manifest.json +6 -6
  66. package/.next/server/chunks/6962.js +1 -0
  67. package/.next/server/middleware-build-manifest.js +1 -1
  68. package/.next/server/pages/404.html +1 -1
  69. package/.next/server/pages/500.html +1 -1
  70. package/.next/server/server-reference-manifest.js +1 -1
  71. package/.next/server/server-reference-manifest.json +1 -1
  72. package/.next/static/chunks/1152-ce3b96f2d3495ed8.js +1 -0
  73. package/.next/static/chunks/app/map/{page-5020db02dba43678.js → page-ed40021c6ab84daf.js} +1 -1
  74. package/.next/static/chunks/app/plan/{page-cd3785902dd95dce.js → page-645f031f5db46170.js} +1 -1
  75. package/.next/trace +37 -37
  76. package/.next/trace-build +1 -1
  77. package/dist/bin/doctor.js +16 -16
  78. package/dist/bin/hook.js +16 -16
  79. package/dist/bin/mcp.js +16 -16
  80. package/dist/bin/plan.js +16 -16
  81. package/dist/bin/uninstall.js +17 -17
  82. package/dist/lib/codex-install.js +242 -0
  83. package/package.json +1 -1
  84. package/.next/server/chunks/1263.js +0 -1
  85. package/.next/static/chunks/6666-31528aed4743588c.js +0 -1
  86. /package/.next/static/{fnj-duECSYw_AlTFP7r7a → O43psSufYlBZeD2MfUpT5}/_buildManifest.js +0 -0
  87. /package/.next/static/{fnj-duECSYw_AlTFP7r7a → O43psSufYlBZeD2MfUpT5}/_ssgManifest.js +0 -0
package/dist/bin/plan.js CHANGED
@@ -206,20 +206,7 @@ ${J}
206
206
  `)?V:`${V}
207
207
  `)}function w(Q,Z){try{return E(Q,"utf8").includes(Z)}catch{return!1}}function h(Q,Z,$){let Y="";try{Y=E(Q,"utf8")}catch{return!1}let J=new RegExp(`${Z}[\\s\\S]*?${$}\\n?`);if(!J.test(Y))return!1;let V=Y.replace(J,"").replace(/\n{3,}/g,`
208
208
 
209
- `).trimStart();return O(Q,V),!0}function S(Q,Z,$){let Y=D(Q,Z);zQ(Y,{recursive:!0});let J=D(Y,"SKILL.md");return O(J,$),J}function g(Q,Z){return IQ(D(Q,Z,"SKILL.md"))}function m(Q,Z){let $=D(Q,Z);if(!IQ($))return!1;return fZ($,{recursive:!0,force:!0}),!0}var XQ=()=>{};import{mkdirSync as bZ,renameSync as IZ,rmSync as AZ,writeFileSync as DZ}from"fs";import{dirname as EZ}from"path";function WQ(Q,Z){bZ(EZ(Q),{recursive:!0});let $=`${Q}.tmp`;try{DZ($,Z),IZ($,Q)}catch(Y){throw AZ($,{force:!0}),Y}}var EQ=()=>{};var mQ={};QQ(mQ,{setupCodexAssets:()=>LZ,removeCodexMcp:()=>SQ,removeCodexArtifacts:()=>hZ,hasCodexMcp:()=>PQ,ensureCodexMcp:()=>hQ,codexMcpProblem:()=>kZ,codexDetected:()=>kQ,auditCodex:()=>_Z,CODEX_HOOKS:()=>a});import{readFileSync as l}from"fs";import{homedir as OZ}from"os";import{join as R}from"path";function OQ(){return process.env.HOME||process.env.USERPROFILE||OZ()}function kQ(){if(process.env.BEACON_CODEX==="1")return!0;if(process.env.BEACON_CODEX==="0")return!1;if(UQ===void 0)UQ=Bun.which("codex")!==null;return UQ}function u(Q){try{return Bun.TOML.parse(Q)}catch{return null}}function PQ(){try{return Boolean(u(l(C(),"utf8"))?.mcp_servers?.beacon)}catch{return!1}}function kZ(){let Q="";try{Q=l(C(),"utf8")}catch{return null}let Z=u(Q);if(!Z)return`~/.codex/config.toml does not parse \u2014 ${F}`;if(Z.mcp_servers?.beacon)return null;if(/^\s*mcp_servers\s*=/m.test(Q))return`mcp_servers is an inline table \u2014 ${F}`;return null}function hQ(){let Q="",Z=!1;try{Q=l(C(),"utf8"),Z=!0}catch{}if(Z){let V=u(Q);if(!V)return{added:!1,error:`~/.codex/config.toml does not parse \u2014 ${F}`};if(V.mcp_servers?.beacon)return{added:!1};if(/^\s*mcp_servers\s*=/m.test(Q))return{added:!1,error:`mcp_servers is an inline table \u2014 ${F}`}}let $=!Q?"":Q.endsWith(`
210
- `)?`
211
- `:`
212
-
213
- `,Y=Q+$+yZ;if(u(Y)?.mcp_servers?.beacon?.command!=="beacon")return{added:!1,error:`could not safely append [mcp_servers.beacon] \u2014 ${F}`};return WQ(C(),Y),{added:!0}}function SQ(){let Q="";try{Q=l(C(),"utf8")}catch{return{removed:!1}}let Z=Q.split(`
214
- `),$=Z.indexOf(LQ);if($===-1)return{removed:!1,skipped:PQ()};let Y=Z.indexOf(_Q,$);if(Y===-1)return{removed:!1,skipped:!0};Z.splice($,Y-$+1);let J=Z.join(`
215
- `).replace(/\n{3,}/g,`
216
-
217
- `).replace(/^\n+/,"");if(u(J)===null)return{removed:!1,skipped:!0};return WQ(C(),J),{removed:!0}}async function LZ(){let{INIT_SKILL:Q,REFRESH_SKILL:Z,PLAN_SKILL:$}=await Promise.resolve().then(() => (VQ(),JQ)),Y={"beacon-init":Q,"beacon-refresh":Z,"beacon-plan":$},J=[];for(let z of j){if(!g(c(),z))J.push(z);S(c(),z,Y[z])}let V=0;for(let z of a)if(y(HQ(),{event:z.event,matcher:z.matcher,command:z.command}))V++;let X=w(p(),d);_(p(),d,yQ,jQ);let q=hQ();return{skillsAdded:J,hooksAdded:V,agentsMdBlockTouched:!X,mcp:q}}function _Z(){let Q={};for(let $ of j)Q[$]=g(c(),$);let Z={};for(let $ of a)Z[$.event]=k(HQ(),{event:$.event,command:$.command});return{detected:kQ(),skills:Q,hooks:Z,agentsMdBlock:w(p(),d),mcp:PQ()}}function hZ(){let Q=[];for(let J of j)if(m(c(),J))Q.push(J);let Z=0;for(let J of a)if(L(HQ(),{event:J.event,command:J.command}))Z++;let $=h(p(),d,yQ),Y=SQ();return{skillsRemoved:Q,hooksRemoved:Z,agentsMdBlockRemoved:$,mcpRemoved:Y.removed,mcpSkipped:Y.skipped}}var BQ=()=>R(OQ(),".codex"),HQ=()=>R(BQ(),"hooks.json"),C=()=>R(BQ(),"config.toml"),p=()=>R(BQ(),"AGENTS.md"),c=()=>R(OQ(),".agents","skills"),d="<!-- beacon:global:start -->",yQ="<!-- beacon:global:end -->",a,UQ,LQ="# beacon:start (managed by Beacon \u2014 `beacon uninstall` removes this block)",_Q="# beacon:end",yZ,F="add it manually: codex mcp add beacon -- beacon mcp";var pQ=N(()=>{XQ();EQ();GQ();a=[{event:"PostToolUse",matcher:"apply_patch",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose, nudge it to present the plan on Beacon's /plan canvas."}];yZ=`${LQ}
218
- [mcp_servers.beacon]
219
- command = "beacon"
220
- args = ["mcp"]
221
- ${_Q}
222
- `});import{existsSync as SZ}from"fs";import{homedir as mZ}from"os";import{join as n}from"path";function pZ(){return process.env.HOME||process.env.USERPROFILE||mZ()}function cZ(Q,Z){return S(xQ(),Q,Z)}function dQ(Q){return g(xQ(),Q)}function dZ(Q){return m(xQ(),Q)}function lZ(Q){return y(KQ(),Q)}function aZ(Q){return k(KQ(),Q)}function nZ(Q){return L(KQ(),Q)}function tZ(Q){_(NQ(),vQ,cQ,Q)}function lQ(){return w(NQ(),vQ)}function sZ(){return h(NQ(),vQ,cQ)}function W1(){let Q={};for(let $ of j)Q[$]=dQ($);let Z={};for(let $ of CQ)Z[$.event]=aZ({event:$.event,command:$.command});return{homeExists:SZ(t()),skills:Q,hooks:Z,claudeMdBlock:lQ()}}async function rZ(){let{INIT_SKILL:Q,REFRESH_SKILL:Z,PLAN_SKILL:$}=await Promise.resolve().then(() => (VQ(),JQ)),Y={"beacon-init":Q,"beacon-refresh":Z,"beacon-plan":$},J=[];for(let q of j){if(!dQ(q))J.push(q);cZ(q,Y[q])}let V=0;for(let q of CQ)if(lZ({event:q.event,matcher:q.matcher,command:q.command}))V++;let X=lQ();return tZ(jQ),{skillsAdded:J,hooksAdded:V,claudeMdBlockTouched:!X}}async function aQ(){let Q;try{Q={ok:!0,...await rZ()}}catch(Z){Q={ok:!1,error:Z instanceof Error?Z.message:String(Z),skillsAdded:[],hooksAdded:0,claudeMdBlockTouched:!1}}try{let Z=await Promise.resolve().then(() => (pQ(),mQ));if(Z.codexDetected())Q.codex={ok:!0,...await Z.setupCodexAssets()}}catch(Z){Q.codex={ok:!1,error:Z instanceof Error?Z.message:String(Z),skillsAdded:[],hooksAdded:0,agentsMdBlockTouched:!1,mcp:{added:!1}}}return Q}function U1(){let Q=[];for(let Y of j)if(dZ(Y))Q.push(Y);let Z=0;for(let Y of CQ)if(nZ(Y))Z++;let $=sZ();return{skillsRemoved:Q,hooksRemoved:Z,claudeMdBlockRemoved:$}}var t=()=>n(pZ(),".claude"),xQ=()=>n(t(),"skills"),KQ=()=>n(t(),"settings.json"),NQ=()=>n(t(),"CLAUDE.md"),vQ="<!-- beacon:global:start -->",cQ="<!-- beacon:global:end -->",j,CQ,jQ=`## Beacon (visual planning panel)
209
+ `).trimStart();return O(Q,V),!0}function S(Q,Z,$){let Y=D(Q,Z);zQ(Y,{recursive:!0});let J=D(Y,"SKILL.md");return O(J,$),J}function g(Q,Z){return IQ(D(Q,Z,"SKILL.md"))}function m(Q,Z){let $=D(Q,Z);if(!IQ($))return!1;return fZ($,{recursive:!0,force:!0}),!0}var XQ=()=>{};import{mkdirSync as bZ,renameSync as IZ,rmSync as AZ,writeFileSync as DZ}from"fs";import{dirname as EZ}from"path";function WQ(Q,Z){bZ(EZ(Q),{recursive:!0});let $=`${Q}.tmp`;try{DZ($,Z),IZ($,Q)}catch(Y){throw AZ($,{force:!0}),Y}}var EQ=()=>{};import{existsSync as OZ}from"fs";import{homedir as yZ}from"os";import{join as p}from"path";function kZ(){return process.env.HOME||process.env.USERPROFILE||yZ()}function LZ(Q,Z){return S(UQ(),Q,Z)}function LQ(Q){return g(UQ(),Q)}function _Z(Q){return m(UQ(),Q)}function hZ(Q){return y(BQ(),Q)}function SZ(Q){return k(BQ(),Q)}function mZ(Q){return L(BQ(),Q)}function pZ(Q){_(HQ(),PQ,kQ,Q)}function _Q(){return w(HQ(),PQ)}function cZ(){return h(HQ(),PQ,kQ)}function Y1(){let Q={};for(let $ of j)Q[$]=LQ($);let Z={};for(let $ of jQ)Z[$.event]=SZ({event:$.event,command:$.command});return{homeExists:OZ(c()),skills:Q,hooks:Z,claudeMdBlock:_Q()}}async function dZ(){let{INIT_SKILL:Q,REFRESH_SKILL:Z,PLAN_SKILL:$}=await Promise.resolve().then(() => (VQ(),JQ)),Y={"beacon-init":Q,"beacon-refresh":Z,"beacon-plan":$},J=[];for(let q of j){if(!LQ(q))J.push(q);LZ(q,Y[q])}let V=0;for(let q of jQ)if(hZ({event:q.event,matcher:q.matcher,command:q.command}))V++;let X=_Q();return pZ(GQ),{skillsAdded:J,hooksAdded:V,claudeMdBlockTouched:!X}}async function hQ(){let Q;try{Q={ok:!0,...await dZ()}}catch(Z){Q={ok:!1,error:Z instanceof Error?Z.message:String(Z),skillsAdded:[],hooksAdded:0,claudeMdBlockTouched:!1}}try{let Z=await Promise.resolve().then(() => (yQ(),OQ));if(Z.codexDetected())Q.codex={ok:!0,...await Z.setupCodexAssets()}}catch(Z){Q.codex={ok:!1,error:Z instanceof Error?Z.message:String(Z),skillsAdded:[],hooksAdded:0,agentsMdBlockTouched:!1,mcp:{added:!1}}}return Q}function J1(){let Q=[];for(let Y of j)if(_Z(Y))Q.push(Y);let Z=0;for(let Y of jQ)if(mZ(Y))Z++;let $=cZ();return{skillsRemoved:Q,hooksRemoved:Z,claudeMdBlockRemoved:$}}var c=()=>p(kZ(),".claude"),UQ=()=>p(c(),"skills"),BQ=()=>p(c(),"settings.json"),HQ=()=>p(c(),"CLAUDE.md"),PQ="<!-- beacon:global:start -->",kQ="<!-- beacon:global:end -->",j,jQ,GQ=`## Beacon (visual planning panel)
223
210
 
224
211
  This machine has Beacon installed \u2014 a local visual planning surface for the terminal-side
225
212
  agent. Beacon proposes feature plans (roadmap features + DB schema + endpoints) via MCP,
@@ -240,11 +227,24 @@ the user reviews on a canvas at /plan, and feedback flows back as the next round
240
227
  Feedback bundles inline annotations on the markdown PLUS any edits the user made directly
241
228
  on the /map and /db boards (added features, attached subtasks, edited columns, new
242
229
  endpoints). Treat board edits as the user's revision intent \u2014 re-propose matching them
243
- verbatim. Do NOT implement until the tool returns approval.`;var GQ=N(()=>{XQ();j=["beacon-init","beacon-refresh","beacon-plan"],CQ=[{event:"PostToolUse",matcher:"Edit|Write|MultiEdit",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"PermissionRequest",matcher:"ExitPlanMode",command:"beacon plan",description:"Pipe the agent's plan markdown into Beacon's /plan canvas for review."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose (instead of presenting it), nudge it to present the plan on Beacon's /plan canvas. Bounded by stop_hook_active \u2014 at most one nudge."}]});var tQ={};QQ(tQ,{provisionDb:()=>X0});import{createClient as oZ}from"@libsql/client";import{drizzle as iZ}from"drizzle-orm/libsql";import{migrate as eZ}from"drizzle-orm/libsql/migrator";import{readMigrationFiles as Q0}from"drizzle-orm/migrator";import{dirname as MQ,join as Z0}from"path";import{fileURLToPath as $0}from"url";async function s(Q,Z){return(await Q.execute({sql:"SELECT 1 FROM sqlite_master WHERE type='table' AND name = ?",args:[Z]})).rows.length>0}async function z0(Q,Z){let $=await Q.execute(`PRAGMA table_info("${Z}")`);return new Set($.rows.map((Y)=>String(Y.name)))}async function nQ(Q){if(!await s(Q,"__drizzle_migrations"))return 0;let Z=await Q.execute('SELECT count(*) AS n FROM "__drizzle_migrations"');return Number(Z.rows[0]?.n??0)}async function q0(Q){for(let[Z,$]of Object.entries(V0)){if(!await s(Q,Z))continue;let Y=await z0(Q,Z);for(let J of $){if(!Y.has(J))continue;await Q.execute(`UPDATE "${Z}" SET "${J}" = CAST((julianday("${J}") - 2440587.5) * 86400000 AS INTEGER) WHERE typeof("${J}") = 'text'`)}}}async function X0(Q,Z=J0){let $=oZ({url:Q});try{await $.execute("PRAGMA journal_mode = WAL;"),await $.execute("PRAGMA foreign_keys = ON;");let Y=await s($,"__drizzle_migrations"),J=await s($,"Node"),V=!1;if(J&&!Y){let q=Q0({migrationsFolder:Z})[0];if(q)await $.execute('CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (id SERIAL PRIMARY KEY, hash text NOT NULL, created_at numeric)'),await $.execute({sql:'INSERT INTO "__drizzle_migrations" ("hash", "created_at") VALUES (?, ?)',args:[q.hash,q.folderMillis]}),V=!0}let X=await nQ($);if(await eZ(iZ($),{migrationsFolder:Z}),await nQ($)>X)V=!0;return await q0($),{migrated:V}}finally{$.close()}}var Y0,J0,V0;var sQ=N(async()=>{Y0=MQ(MQ(MQ($0(import.meta.url)))),J0=process.env.BEACON_MIGRATIONS_DIR||Z0(Y0,"drizzle"),V0={Node:["createdAt","updatedAt"],Note:["createdAt","updatedAt"],DbTable:["createdAt","updatedAt"],Endpoint:["createdAt","updatedAt"],DraftTable:["createdAt"],SyncState:["codeGraphSyncedAt","updatedAt"],AppSetting:["updatedAt"],ProjectMeta:["updatedAt"],CodeFile:["updatedAt"]}});import{AsyncLocalStorage as W0}from"async_hooks";import{spawnSync as U0}from"child_process";import{createHash as B0}from"crypto";import{existsSync as oQ,mkdirSync as r,readFileSync as iQ,writeFileSync as eQ}from"fs";import{homedir as H0}from"os";import{basename as P0,join as M}from"path";function x(){return process.env.BEACON_HOME||M(H0(),".beacon")}function TQ(){return M(x(),"workspaces.json")}function QZ(Q){return B0("sha256").update(Q).digest("hex").slice(0,12)}function g1(Q=process.cwd()){let Z=U0("git",["rev-parse","--show-toplevel"],{cwd:Q,stdio:["ignore","pipe","ignore"]});if(Z.status===0){let $=Z.stdout?.toString().trim();if($)return $}return Q}function wQ(Q){return M(x(),Q)}function j0(Q){return`file:${M(wQ(Q),"db.sqlite")}`}function f(){try{let Q=JSON.parse(iQ(TQ(),"utf8"));return Array.isArray(Q)?Q:[]}catch{return[]}}function gQ(Q){r(x(),{recursive:!0}),eQ(TQ(),JSON.stringify(Q,null,2))}function G0(){return f().sort((Q,Z)=>Z.lastOpenedAt.localeCompare(Q.lastOpenedAt))}function G(Q){return f().find((Z)=>Z.id===Q)??null}function x0(Q,Z,$=new Date().toISOString()){let Y=QZ(Q),J=f(),V=J.find((z)=>z.id===Y),X={id:Y,path:Q,name:Z||V?.name||P0(Q),lastOpenedAt:$},q=[X,...J.filter((z)=>z.id!==Y)];return r(wQ(Y),{recursive:!0}),gQ(q),X}function F1(Q,Z=new Date().toISOString()){let $=f(),Y=$.find((J)=>J.id===Q);if(!Y)return;Y.lastOpenedAt=Z,gQ($)}function u1(Q){if(gQ(f().filter((Z)=>Z.id!==Q)),FQ()===Q)K0(G0()[0]?.id??null)}function ZZ(){return M(x(),"active")}function FQ(){try{return iQ(ZZ(),"utf8").trim()||null}catch{return null}}function K0(Q){r(x(),{recursive:!0}),eQ(ZZ(),Q??"")}function R1(){let Q=FQ();return Q?G(Q):null}function f1(){let Q=v0()??FQ();return Q?G(Q):null}function b1(Q){return G(Q)?.path??null}function I1(){return oQ(TQ())}var $Z="beacon_ws";function YZ(Q,Z){let $=Q.headers.get("cookie");if(!$)return null;for(let Y of $.split(";")){let J=Y.indexOf("=");if(J===-1)continue;if(Y.slice(0,J).trim()===Z)return decodeURIComponent(Y.slice(J+1).trim())}return null}function A1(Q){let Z=Q.headers.get("x-beacon-workspace");if(Z&&G(Z))return Z;let $=YZ(Q,$Z);if($&&G($))return $;return null}var N0="x-beacon-workspace-path";async function D1(Q){let Z=Q.headers.get("x-beacon-workspace");if(Z&&G(Z))return Z;let $=Q.headers.get(N0);if($&&(!Z||QZ($)===Z)){let J=x0($);return await C0(J.id),J.id}let Y=YZ(Q,$Z);if(Y&&G(Y))return Y;return null}var JZ=new W0;function E1(Q,Z){return Q?JZ.run(Q,Z):Z()}function v0(){return JZ.getStore()??null}var rQ=new Set;async function C0(Q){let Z=wQ(Q),$=M(Z,"db.sqlite"),Y=oQ($);if(Y&&rQ.has($))return{ok:!0,created:!1,migrated:!1};try{r(Z,{recursive:!0});let{provisionDb:J}=await sQ().then(() => tQ),V=await J(j0(Q));return rQ.add($),{ok:!0,created:!Y,migrated:Y&&V.migrated}}catch(J){return{ok:!1,created:!1,migrated:!1,error:J instanceof Error?J.message:String(J)}}}GQ();import{execSync as PZ,spawn as F0}from"child_process";import{mkdirSync as u0,openSync as R0,readFileSync as f0,writeFileSync as b0}from"fs";import{homedir as I0,platform as BZ}from"os";import{dirname as A0,join as i}from"path";import{fileURLToPath as D0}from"url";import{createHash as E0}from"crypto";var VZ=1500,zZ=345600000,y1=1800000,k1=3000;import{mkdirSync as S1,readFileSync as T0,writeFileSync as m1}from"fs";import{join as w0}from"path";var M0=["default","acceptEdits","bypassPermissions","auto"];function qZ(Q){return typeof Q==="string"&&M0.includes(Q)}function XZ(Q,Z){let $={behavior:"allow"};if(Q)$.updatedPermissions=[{type:"setMode",mode:Q,destination:"session"}];let Y={hookEventName:"PermissionRequest",decision:$};if(Z?.trim())Y.additionalContext=Z;return{hookSpecificOutput:Y}}function g0(){return w0(x(),"preferences.json")}function WZ(){try{let Q=JSON.parse(T0(g0(),"utf8"));return{planApprovalMode:qZ(Q.planApprovalMode)?Q.planApprovalMode:void 0,planApprovalModeConfigured:Q.planApprovalModeConfigured===!0}}catch{return{}}}function UZ(Q){if(!Q?.length)return"";let Z=Q.map((Y)=>Y.id?` \u2022 ${Y.title} \u2014 id: ${Y.id}`:` \u2022 ${Y.title}`),$=Q.some((Y)=>Y.id);return`
230
+ verbatim. Do NOT implement until the tool returns approval.`;var xQ=N(()=>{XQ();j=["beacon-init","beacon-refresh","beacon-plan"],jQ=[{event:"PostToolUse",matcher:"Edit|Write|MultiEdit",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"PermissionRequest",matcher:"ExitPlanMode",command:"beacon plan",description:"Pipe the agent's plan markdown into Beacon's /plan canvas for review."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose (instead of presenting it), nudge it to present the plan on Beacon's /plan canvas. Bounded by stop_hook_active \u2014 at most one nudge."}]});var OQ={};QQ(OQ,{setupCodexAssets:()=>tZ,removeCodexMcp:()=>aQ,removeCodexArtifacts:()=>rZ,hasCodexMcp:()=>CQ,ensureCodexMcp:()=>lQ,codexMcpProblem:()=>nZ,codexDetected:()=>pQ,auditCodex:()=>sZ,CODEX_HOOKS:()=>t});import{readFileSync as n}from"fs";import{homedir as lZ}from"os";import{join as R}from"path";function SQ(){return process.env.HOME||process.env.USERPROFILE||lZ()}function pQ(){if(process.env.BEACON_CODEX==="1")return!0;if(process.env.BEACON_CODEX==="0")return!1;if(KQ===void 0)KQ=Bun.which("codex")!==null;return KQ}function u(Q){try{return Bun.TOML.parse(Q)}catch{return null}}function CQ(){try{return Boolean(u(n(C(),"utf8"))?.mcp_servers?.beacon)}catch{return!1}}function nZ(){let Q="";try{Q=n(C(),"utf8")}catch{return null}let Z=u(Q);if(!Z)return`~/.codex/config.toml does not parse \u2014 ${F}`;if(Z.mcp_servers?.beacon)return null;if(/^\s*mcp_servers\s*=/m.test(Q))return`mcp_servers is an inline table \u2014 ${F}`;return null}function lQ(){let Q="",Z=!1;try{Q=n(C(),"utf8"),Z=!0}catch{}if(Z){let V=u(Q);if(!V)return{added:!1,error:`~/.codex/config.toml does not parse \u2014 ${F}`};if(V.mcp_servers?.beacon)return{added:!1};if(/^\s*mcp_servers\s*=/m.test(Q))return{added:!1,error:`mcp_servers is an inline table \u2014 ${F}`}}let $=!Q?"":Q.endsWith(`
231
+ `)?`
232
+ `:`
233
+
234
+ `,Y=Q+$+aZ;if(u(Y)?.mcp_servers?.beacon?.command!=="beacon")return{added:!1,error:`could not safely append [mcp_servers.beacon] \u2014 ${F}`};return WQ(C(),Y),{added:!0}}function aQ(){let Q="";try{Q=n(C(),"utf8")}catch{return{removed:!1}}let Z=Q.split(`
235
+ `),$=Z.indexOf(cQ);if($===-1)return{removed:!1,skipped:CQ()};let Y=Z.indexOf(dQ,$);if(Y===-1)return{removed:!1,skipped:!0};Z.splice($,Y-$+1);let J=Z.join(`
236
+ `).replace(/\n{3,}/g,`
237
+
238
+ `).replace(/^\n+/,"");if(u(J)===null)return{removed:!1,skipped:!0};return WQ(C(),J),{removed:!0}}async function tZ(){let{INIT_SKILL:Q,REFRESH_SKILL:Z,PLAN_SKILL:$}=await Promise.resolve().then(() => (VQ(),JQ)),Y={"beacon-init":Q,"beacon-refresh":Z,"beacon-plan":$},J=[];for(let z of j){if(!g(l(),z))J.push(z);S(l(),z,Y[z])}let V=0;for(let z of t)if(y(vQ(),{event:z.event,matcher:z.matcher,command:z.command}))V++;let X=w(d(),a);_(d(),a,mQ,GQ);let q=lQ();return{skillsAdded:J,hooksAdded:V,agentsMdBlockTouched:!X,mcp:q}}function sZ(){let Q={};for(let $ of j)Q[$]=g(l(),$);let Z={};for(let $ of t)Z[$.event]=k(vQ(),{event:$.event,command:$.command});return{detected:pQ(),skills:Q,hooks:Z,agentsMdBlock:w(d(),a),mcp:CQ()}}function rZ(){let Q=[];for(let J of j)if(m(l(),J))Q.push(J);let Z=0;for(let J of t)if(L(vQ(),{event:J.event,command:J.command}))Z++;let $=h(d(),a,mQ),Y=aQ();return{skillsRemoved:Q,hooksRemoved:Z,agentsMdBlockRemoved:$,mcpRemoved:Y.removed,mcpSkipped:Y.skipped}}var NQ=()=>R(SQ(),".codex"),vQ=()=>R(NQ(),"hooks.json"),C=()=>R(NQ(),"config.toml"),d=()=>R(NQ(),"AGENTS.md"),l=()=>R(SQ(),".agents","skills"),a="<!-- beacon:global:start -->",mQ="<!-- beacon:global:end -->",t,KQ,cQ="# beacon:start (managed by Beacon \u2014 `beacon uninstall` removes this block)",dQ="# beacon:end",aZ,F="add it manually: codex mcp add beacon -- beacon mcp";var yQ=N(()=>{XQ();EQ();xQ();t=[{event:"PostToolUse",matcher:"apply_patch",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose, nudge it to present the plan on Beacon's /plan canvas."}];aZ=`${cQ}
239
+ [mcp_servers.beacon]
240
+ command = "beacon"
241
+ args = ["mcp"]
242
+ ${dQ}
243
+ `});var tQ={};QQ(tQ,{provisionDb:()=>X0});import{createClient as oZ}from"@libsql/client";import{drizzle as iZ}from"drizzle-orm/libsql";import{migrate as eZ}from"drizzle-orm/libsql/migrator";import{readMigrationFiles as Q0}from"drizzle-orm/migrator";import{dirname as MQ,join as Z0}from"path";import{fileURLToPath as $0}from"url";async function s(Q,Z){return(await Q.execute({sql:"SELECT 1 FROM sqlite_master WHERE type='table' AND name = ?",args:[Z]})).rows.length>0}async function z0(Q,Z){let $=await Q.execute(`PRAGMA table_info("${Z}")`);return new Set($.rows.map((Y)=>String(Y.name)))}async function nQ(Q){if(!await s(Q,"__drizzle_migrations"))return 0;let Z=await Q.execute('SELECT count(*) AS n FROM "__drizzle_migrations"');return Number(Z.rows[0]?.n??0)}async function q0(Q){for(let[Z,$]of Object.entries(V0)){if(!await s(Q,Z))continue;let Y=await z0(Q,Z);for(let J of $){if(!Y.has(J))continue;await Q.execute(`UPDATE "${Z}" SET "${J}" = CAST((julianday("${J}") - 2440587.5) * 86400000 AS INTEGER) WHERE typeof("${J}") = 'text'`)}}}async function X0(Q,Z=J0){let $=oZ({url:Q});try{await $.execute("PRAGMA journal_mode = WAL;"),await $.execute("PRAGMA foreign_keys = ON;");let Y=await s($,"__drizzle_migrations"),J=await s($,"Node"),V=!1;if(J&&!Y){let q=Q0({migrationsFolder:Z})[0];if(q)await $.execute('CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (id SERIAL PRIMARY KEY, hash text NOT NULL, created_at numeric)'),await $.execute({sql:'INSERT INTO "__drizzle_migrations" ("hash", "created_at") VALUES (?, ?)',args:[q.hash,q.folderMillis]}),V=!0}let X=await nQ($);if(await eZ(iZ($),{migrationsFolder:Z}),await nQ($)>X)V=!0;return await q0($),{migrated:V}}finally{$.close()}}var Y0,J0,V0;var sQ=N(async()=>{Y0=MQ(MQ(MQ($0(import.meta.url)))),J0=process.env.BEACON_MIGRATIONS_DIR||Z0(Y0,"drizzle"),V0={Node:["createdAt","updatedAt"],Note:["createdAt","updatedAt"],DbTable:["createdAt","updatedAt"],Endpoint:["createdAt","updatedAt"],DraftTable:["createdAt"],SyncState:["codeGraphSyncedAt","updatedAt"],AppSetting:["updatedAt"],ProjectMeta:["updatedAt"],CodeFile:["updatedAt"]}});import{AsyncLocalStorage as W0}from"async_hooks";import{spawnSync as U0}from"child_process";import{createHash as B0}from"crypto";import{existsSync as oQ,mkdirSync as r,readFileSync as iQ,writeFileSync as eQ}from"fs";import{homedir as H0}from"os";import{basename as P0,join as M}from"path";function x(){return process.env.BEACON_HOME||M(H0(),".beacon")}function TQ(){return M(x(),"workspaces.json")}function QZ(Q){return B0("sha256").update(Q).digest("hex").slice(0,12)}function g1(Q=process.cwd()){let Z=U0("git",["rev-parse","--show-toplevel"],{cwd:Q,stdio:["ignore","pipe","ignore"]});if(Z.status===0){let $=Z.stdout?.toString().trim();if($)return $}return Q}function wQ(Q){return M(x(),Q)}function j0(Q){return`file:${M(wQ(Q),"db.sqlite")}`}function f(){try{let Q=JSON.parse(iQ(TQ(),"utf8"));return Array.isArray(Q)?Q:[]}catch{return[]}}function gQ(Q){r(x(),{recursive:!0}),eQ(TQ(),JSON.stringify(Q,null,2))}function G0(){return f().sort((Q,Z)=>Z.lastOpenedAt.localeCompare(Q.lastOpenedAt))}function G(Q){return f().find((Z)=>Z.id===Q)??null}function x0(Q,Z,$=new Date().toISOString()){let Y=QZ(Q),J=f(),V=J.find((z)=>z.id===Y),X={id:Y,path:Q,name:Z||V?.name||P0(Q),lastOpenedAt:$},q=[X,...J.filter((z)=>z.id!==Y)];return r(wQ(Y),{recursive:!0}),gQ(q),X}function F1(Q,Z=new Date().toISOString()){let $=f(),Y=$.find((J)=>J.id===Q);if(!Y)return;Y.lastOpenedAt=Z,gQ($)}function u1(Q){if(gQ(f().filter((Z)=>Z.id!==Q)),FQ()===Q)K0(G0()[0]?.id??null)}function ZZ(){return M(x(),"active")}function FQ(){try{return iQ(ZZ(),"utf8").trim()||null}catch{return null}}function K0(Q){r(x(),{recursive:!0}),eQ(ZZ(),Q??"")}function R1(){let Q=FQ();return Q?G(Q):null}function f1(){let Q=v0()??FQ();return Q?G(Q):null}function b1(Q){return G(Q)?.path??null}function I1(){return oQ(TQ())}var $Z="beacon_ws";function YZ(Q,Z){let $=Q.headers.get("cookie");if(!$)return null;for(let Y of $.split(";")){let J=Y.indexOf("=");if(J===-1)continue;if(Y.slice(0,J).trim()===Z)return decodeURIComponent(Y.slice(J+1).trim())}return null}function A1(Q){let Z=Q.headers.get("x-beacon-workspace");if(Z&&G(Z))return Z;let $=YZ(Q,$Z);if($&&G($))return $;return null}var N0="x-beacon-workspace-path";async function D1(Q){let Z=Q.headers.get("x-beacon-workspace");if(Z&&G(Z))return Z;let $=Q.headers.get(N0);if($&&(!Z||QZ($)===Z)){let J=x0($);return await C0(J.id),J.id}let Y=YZ(Q,$Z);if(Y&&G(Y))return Y;return null}var JZ=new W0;function E1(Q,Z){return Q?JZ.run(Q,Z):Z()}function v0(){return JZ.getStore()??null}var rQ=new Set;async function C0(Q){let Z=wQ(Q),$=M(Z,"db.sqlite"),Y=oQ($);if(Y&&rQ.has($))return{ok:!0,created:!1,migrated:!1};try{r(Z,{recursive:!0});let{provisionDb:J}=await sQ().then(() => tQ),V=await J(j0(Q));return rQ.add($),{ok:!0,created:!Y,migrated:Y&&V.migrated}}catch(J){return{ok:!1,created:!1,migrated:!1,error:J instanceof Error?J.message:String(J)}}}xQ();import{execSync as PZ,spawn as F0}from"child_process";import{mkdirSync as u0,openSync as R0,readFileSync as f0,writeFileSync as b0}from"fs";import{homedir as I0,platform as BZ}from"os";import{dirname as A0,join as i}from"path";import{fileURLToPath as D0}from"url";import{createHash as E0}from"crypto";var VZ=1500,zZ=345600000,y1=1800000,k1=3000;import{mkdirSync as S1,readFileSync as T0,writeFileSync as m1}from"fs";import{join as w0}from"path";var M0=["default","acceptEdits","bypassPermissions","auto"];function qZ(Q){return typeof Q==="string"&&M0.includes(Q)}function XZ(Q,Z){let $={behavior:"allow"};if(Q)$.updatedPermissions=[{type:"setMode",mode:Q,destination:"session"}];let Y={hookEventName:"PermissionRequest",decision:$};if(Z?.trim())Y.additionalContext=Z;return{hookSpecificOutput:Y}}function g0(){return w0(x(),"preferences.json")}function WZ(){try{let Q=JSON.parse(T0(g0(),"utf8"));return{planApprovalMode:qZ(Q.planApprovalMode)?Q.planApprovalMode:void 0,planApprovalModeConfigured:Q.planApprovalModeConfigured===!0}}catch{return{}}}function UZ(Q){if(!Q?.length)return"";let Z=Q.map((Y)=>Y.id?` \u2022 ${Y.title} \u2014 id: ${Y.id}`:` \u2022 ${Y.title}`),$=Q.some((Y)=>Y.id);return`
244
244
 
245
245
  This plan created these roadmap feature(s):
246
246
  `+Z.join(`
247
- `)+"\n\nWhen the work ships, register them in ONE call: `beacon_describe_feature` with a "+"`features` array \u2014 one entry per feature"+($?", each keyed by the `id` above (no title-matching needed)":"")+", each with the files you touched + a short markdown summary. Do them all in that single "+"batched call so every feature flips to Done \u2014 do NOT register only the umbrella, and do "+"NOT make one call per feature."}var O0=i(A0(D0(import.meta.url)),".."),RQ=process.env.BEACON_HOME||i(I0(),".beacon"),jZ=i(RQ,"server.json"),HZ=process.env.PORT||"4319";function y0(Q){try{return process.kill(Q,0),!0}catch{return!1}}function k0(Q){try{return JSON.parse(f0(Q,"utf8"))}catch{return null}}async function GZ(Q){try{return(await fetch(Q)).ok}catch{return!1}}async function L0(Q,Z=60){for(let $=0;$<Z;$++){if(await GZ(Q))return!0;await new Promise((Y)=>setTimeout(Y,500))}return!1}function _0(){u0(RQ,{recursive:!0});let Q=R0(i(RQ,"server.log"),"a"),Z={...process.env,PORT:HZ,BEACON_NO_OPEN:"1"};delete Z.BEACON_REPO,delete Z.BEACON_DATA_DIR,delete Z.DATABASE_URL;let $=F0("bun",["run","dev"],{cwd:O0,env:Z,detached:!0,stdio:["ignore",Q,Q]});$.unref();let Y={pid:$.pid??0,port:HZ};return b0(jZ,JSON.stringify(Y)),Y}async function h0(){let Q=k0(jZ);if(Q&&y0(Q.pid)&&await GZ(`http://localhost:${Q.port}/api/workspace`))return Q.port;let{port:Z}=_0();return await L0(`http://localhost:${Z}/api/workspace`),Z}function S0(Q){if(process.env.BEACON_NO_OPEN)return;let Z=BZ()==="darwin"?"open":BZ()==="win32"?"start":"xdg-open";try{PZ(`${Z} "${Q}"`,{stdio:"ignore"})}catch{}}function m0(){try{return PZ("git rev-parse --show-toplevel",{cwd:process.cwd(),stdio:["ignore","pipe","ignore"]}).toString().trim()}catch{return""}}function p0(Q){return E0("sha256").update(Q).digest("hex").slice(0,12)}async function c0(){if(process.stdin.isTTY)return null;let Q=[];for await(let $ of process.stdin)Q.push($);let Z=Buffer.concat(Q).toString("utf8").trim();if(!Z)return null;try{return JSON.parse(Z)}catch{return null}}function uQ(Q,Z){return XZ(Q,Z)}function o(Q){return{hookSpecificOutput:{hookEventName:"PermissionRequest",decision:{behavior:"deny",message:Q}}}}function K(Q){process.stdout.write(JSON.stringify(Q)),process.exit(0)}(async()=>{await aQ();let Z=(await c0())?.tool_input?.plan;if(!Z||!Z.trim())K(uQ());let Y=`http://localhost:${await h0()}`,J=m0()||process.cwd(),V=p0(J);await fetch(`${Y}/api/workspace/activate?id=${V}`).catch(()=>{});let X=Z.split(`
247
+ `)+"\n\nWhen the work ships, register them in ONE call: `beacon_describe_feature` with a "+"`features` array \u2014 one entry per feature"+($?", each keyed by the `id` above (no title-matching needed)":"")+", each with the files you touched + a short markdown summary. Do them all in that single "+"batched call so every feature flips to Done \u2014 do NOT register only the umbrella, and do "+"NOT make one call per feature."}var O0=i(A0(D0(import.meta.url)),".."),RQ=process.env.BEACON_HOME||i(I0(),".beacon"),jZ=i(RQ,"server.json"),HZ=process.env.PORT||"4319";function y0(Q){try{return process.kill(Q,0),!0}catch{return!1}}function k0(Q){try{return JSON.parse(f0(Q,"utf8"))}catch{return null}}async function GZ(Q){try{return(await fetch(Q)).ok}catch{return!1}}async function L0(Q,Z=60){for(let $=0;$<Z;$++){if(await GZ(Q))return!0;await new Promise((Y)=>setTimeout(Y,500))}return!1}function _0(){u0(RQ,{recursive:!0});let Q=R0(i(RQ,"server.log"),"a"),Z={...process.env,PORT:HZ,BEACON_NO_OPEN:"1"};delete Z.BEACON_REPO,delete Z.BEACON_DATA_DIR,delete Z.DATABASE_URL;let $=F0("bun",["run","dev"],{cwd:O0,env:Z,detached:!0,stdio:["ignore",Q,Q]});$.unref();let Y={pid:$.pid??0,port:HZ};return b0(jZ,JSON.stringify(Y)),Y}async function h0(){let Q=k0(jZ);if(Q&&y0(Q.pid)&&await GZ(`http://localhost:${Q.port}/api/workspace`))return Q.port;let{port:Z}=_0();return await L0(`http://localhost:${Z}/api/workspace`),Z}function S0(Q){if(process.env.BEACON_NO_OPEN)return;let Z=BZ()==="darwin"?"open":BZ()==="win32"?"start":"xdg-open";try{PZ(`${Z} "${Q}"`,{stdio:"ignore"})}catch{}}function m0(){try{return PZ("git rev-parse --show-toplevel",{cwd:process.cwd(),stdio:["ignore","pipe","ignore"]}).toString().trim()}catch{return""}}function p0(Q){return E0("sha256").update(Q).digest("hex").slice(0,12)}async function c0(){if(process.stdin.isTTY)return null;let Q=[];for await(let $ of process.stdin)Q.push($);let Z=Buffer.concat(Q).toString("utf8").trim();if(!Z)return null;try{return JSON.parse(Z)}catch{return null}}function uQ(Q,Z){return XZ(Q,Z)}function o(Q){return{hookSpecificOutput:{hookEventName:"PermissionRequest",decision:{behavior:"deny",message:Q}}}}function K(Q){process.stdout.write(JSON.stringify(Q)),process.exit(0)}(async()=>{await hQ();let Z=(await c0())?.tool_input?.plan;if(!Z||!Z.trim())K(uQ());let Y=`http://localhost:${await h0()}`,J=m0()||process.cwd(),V=p0(J);await fetch(`${Y}/api/workspace/activate?id=${V}`).catch(()=>{});let X=Z.split(`
248
248
  `,1)[0]?.replace(/^#+\s*/,"").slice(0,160)||"Plan review",q=await fetch(`${Y}/api/plan`,{method:"POST",headers:{"content-type":"application/json","x-beacon-workspace":V},body:JSON.stringify({description:X,markdown:Z})});if(q.status===422){let B=await q.json().catch(()=>({}));K(o(B.error??"Beacon rejected the plan: every roadmap feature needs a category and a priority. Add them and re-present."))}if(!q.ok)K(uQ());if(!await fetch(`${Y}/api/plan/presence`,{headers:{"x-beacon-workspace":V}}).then((B)=>B.json()).then((B)=>!!B?.live).catch(()=>!1)){let B=encodeURIComponent(`/plan?ws=${V}`);S0(`${Y}/api/workspace/activate?id=${V}&redirect=${B}`)}let U=Date.now()+zZ,T=(B)=>new Promise((e)=>setTimeout(e,B));while(Date.now()<U){await T(VZ);let B=await fetch(`${Y}/api/plan/verdict`,{headers:{"x-beacon-workspace":V}}).then((e)=>e.json()).catch(()=>null);if(!B)continue;if(B.kind==="approved")K(uQ(WZ().planApprovalMode,UZ(B.features)));if(B.kind==="discarded")K(o("The user discarded the plan in Beacon. Ask what they want to adjust before re-presenting."));if(B.kind==="feedback")K(o(`The user left feedback on the plan in Beacon (inline comments and/or edits on the /map and /db boards). Revise the plan based on the feedback below, then re-present (call ExitPlanMode again):
249
249
 
250
250
  `+B.feedback))}K(o("Beacon plan review timed out without a verdict. Re-present the plan and ask the user to review it."))})();
@@ -206,20 +206,7 @@ ${Y}
206
206
  `)?V:`${V}
207
207
  `)}function g(Q,Z){try{return S(Q,"utf8").includes(Z)}catch{return!1}}function n(Q,Z,$){let J="";try{J=S(Q,"utf8")}catch{return!1}let Y=new RegExp(`${Z}[\\s\\S]*?${$}\\n?`);if(!Y.test(J))return!1;let V=J.replace(Y,"").replace(/\n{3,}/g,`
208
208
 
209
- `).trimStart();return p(Q,V),!0}function d(Q,Z,$){let J=h(Q,Z);HQ(J,{recursive:!0});let Y=h(J,"SKILL.md");return p(Y,$),Y}function R(Q,Z){return kQ(h(Q,Z,"SKILL.md"))}function a(Q,Z){let $=h(Q,Z);if(!kQ($))return!1;return gZ($,{recursive:!0,force:!0}),!0}var jQ=()=>{};import{mkdirSync as RZ,renameSync as EZ,rmSync as IZ,writeFileSync as bZ}from"fs";import{dirname as DZ}from"path";function vQ(Q,Z){RZ(DZ(Q),{recursive:!0});let $=`${Q}.tmp`;try{bZ($,Z),EZ($,Q)}catch(J){throw IZ($,{force:!0}),J}}var pQ=()=>{};var sQ={};zQ(sQ,{setupCodexAssets:()=>LZ,removeCodexMcp:()=>aQ,removeCodexArtifacts:()=>CQ,hasCodexMcp:()=>uQ,ensureCodexMcp:()=>dQ,codexMcpProblem:()=>yZ,codexDetected:()=>lQ,auditCodex:()=>KQ,CODEX_HOOKS:()=>T});import{readFileSync as i}from"fs";import{homedir as OZ}from"os";import{join as b}from"path";function mQ(){return process.env.HOME||process.env.USERPROFILE||OZ()}function lQ(){if(process.env.BEACON_CODEX==="1")return!0;if(process.env.BEACON_CODEX==="0")return!1;if(xQ===void 0)xQ=Bun.which("codex")!==null;return xQ}function I(Q){try{return Bun.TOML.parse(Q)}catch{return null}}function uQ(){try{return Boolean(I(i(f(),"utf8"))?.mcp_servers?.beacon)}catch{return!1}}function yZ(){let Q="";try{Q=i(f(),"utf8")}catch{return null}let Z=I(Q);if(!Z)return`~/.codex/config.toml does not parse \u2014 ${E}`;if(Z.mcp_servers?.beacon)return null;if(/^\s*mcp_servers\s*=/m.test(Q))return`mcp_servers is an inline table \u2014 ${E}`;return null}function dQ(){let Q="",Z=!1;try{Q=i(f(),"utf8"),Z=!0}catch{}if(Z){let V=I(Q);if(!V)return{added:!1,error:`~/.codex/config.toml does not parse \u2014 ${E}`};if(V.mcp_servers?.beacon)return{added:!1};if(/^\s*mcp_servers\s*=/m.test(Q))return{added:!1,error:`mcp_servers is an inline table \u2014 ${E}`}}let $=!Q?"":Q.endsWith(`
210
- `)?`
211
- `:`
212
-
213
- `,J=Q+$+AZ;if(I(J)?.mcp_servers?.beacon?.command!=="beacon")return{added:!1,error:`could not safely append [mcp_servers.beacon] \u2014 ${E}`};return vQ(f(),J),{added:!0}}function aQ(){let Q="";try{Q=i(f(),"utf8")}catch{return{removed:!1}}let Z=Q.split(`
214
- `),$=Z.indexOf(tQ);if($===-1)return{removed:!1,skipped:uQ()};let J=Z.indexOf(nQ,$);if(J===-1)return{removed:!1,skipped:!0};Z.splice($,J-$+1);let Y=Z.join(`
215
- `).replace(/\n{3,}/g,`
216
-
217
- `).replace(/^\n+/,"");if(I(Y)===null)return{removed:!1,skipped:!0};return vQ(f(),Y),{removed:!0}}async function LZ(){let{INIT_SKILL:Q,REFRESH_SKILL:Z,PLAN_SKILL:$}=await Promise.resolve().then(() => (k(),WQ)),J={"beacon-init":Q,"beacon-refresh":Z,"beacon-plan":$},Y=[];for(let z of H){if(!R(r(),z))Y.push(z);d(r(),z,J[z])}let V=0;for(let z of T)if(m(GQ(),{event:z.event,matcher:z.matcher,command:z.command}))V++;let X=g(s(),o);t(s(),o,cQ,fQ);let U=dQ();return{skillsAdded:Y,hooksAdded:V,agentsMdBlockTouched:!X,mcp:U}}function KQ(){let Q={};for(let $ of H)Q[$]=R(r(),$);let Z={};for(let $ of T)Z[$.event]=c(GQ(),{event:$.event,command:$.command});return{detected:lQ(),skills:Q,hooks:Z,agentsMdBlock:g(s(),o),mcp:uQ()}}function CQ(){let Q=[];for(let Y of H)if(a(r(),Y))Q.push(Y);let Z=0;for(let Y of T)if(l(GQ(),{event:Y.event,command:Y.command}))Z++;let $=n(s(),o,cQ),J=aQ();return{skillsRemoved:Q,hooksRemoved:Z,agentsMdBlockRemoved:$,mcpRemoved:J.removed,mcpSkipped:J.skipped}}var NQ=()=>b(mQ(),".codex"),GQ=()=>b(NQ(),"hooks.json"),f=()=>b(NQ(),"config.toml"),s=()=>b(NQ(),"AGENTS.md"),r=()=>b(mQ(),".agents","skills"),o="<!-- beacon:global:start -->",cQ="<!-- beacon:global:end -->",T,xQ,tQ="# beacon:start (managed by Beacon \u2014 `beacon uninstall` removes this block)",nQ="# beacon:end",AZ,E="add it manually: codex mcp add beacon -- beacon mcp";var MQ=C(()=>{jQ();pQ();TQ();T=[{event:"PostToolUse",matcher:"apply_patch",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose, nudge it to present the plan on Beacon's /plan canvas."}];AZ=`${tQ}
218
- [mcp_servers.beacon]
219
- command = "beacon"
220
- args = ["mcp"]
221
- ${nQ}
222
- `});import{existsSync as _Z}from"fs";import{homedir as kZ}from"os";import{join as e}from"path";function hZ(){return process.env.HOME||process.env.USERPROFILE||kZ()}function SZ(Q,Z){return d(wQ(),Q,Z)}function oQ(Q){return R(wQ(),Q)}function pZ(Q){return a(wQ(),Q)}function mZ(Q){return m(FQ(),Q)}function cZ(Q){return c(FQ(),Q)}function lZ(Q){return l(FQ(),Q)}function tZ(Q){t(gQ(),RQ,rQ,Q)}function iQ(){return g(gQ(),RQ)}function nZ(){return n(gQ(),RQ,rQ)}function eQ(){let Q={};for(let $ of H)Q[$]=oQ($);let Z={};for(let $ of D)Z[$.event]=cZ({event:$.event,command:$.command});return{homeExists:_Z(QQ()),skills:Q,hooks:Z,claudeMdBlock:iQ()}}async function dZ(){let{INIT_SKILL:Q,REFRESH_SKILL:Z,PLAN_SKILL:$}=await Promise.resolve().then(() => (k(),WQ)),J={"beacon-init":Q,"beacon-refresh":Z,"beacon-plan":$},Y=[];for(let U of H){if(!oQ(U))Y.push(U);SZ(U,J[U])}let V=0;for(let U of D)if(mZ({event:U.event,matcher:U.matcher,command:U.command}))V++;let X=iQ();return tZ(fQ),{skillsAdded:Y,hooksAdded:V,claudeMdBlockTouched:!X}}async function S0(){let Q;try{Q={ok:!0,...await dZ()}}catch(Z){Q={ok:!1,error:Z instanceof Error?Z.message:String(Z),skillsAdded:[],hooksAdded:0,claudeMdBlockTouched:!1}}try{let Z=await Promise.resolve().then(() => (MQ(),sQ));if(Z.codexDetected())Q.codex={ok:!0,...await Z.setupCodexAssets()}}catch(Z){Q.codex={ok:!1,error:Z instanceof Error?Z.message:String(Z),skillsAdded:[],hooksAdded:0,agentsMdBlockTouched:!1,mcp:{added:!1}}}return Q}function QZ(){let Q=[];for(let J of H)if(pZ(J))Q.push(J);let Z=0;for(let J of D)if(lZ(J))Z++;let $=nZ();return{skillsRemoved:Q,hooksRemoved:Z,claudeMdBlockRemoved:$}}var QQ=()=>e(hZ(),".claude"),wQ=()=>e(QQ(),"skills"),FQ=()=>e(QQ(),"settings.json"),gQ=()=>e(QQ(),"CLAUDE.md"),RQ="<!-- beacon:global:start -->",rQ="<!-- beacon:global:end -->",H,D,fQ=`## Beacon (visual planning panel)
209
+ `).trimStart();return p(Q,V),!0}function d(Q,Z,$){let J=h(Q,Z);HQ(J,{recursive:!0});let Y=h(J,"SKILL.md");return p(Y,$),Y}function R(Q,Z){return kQ(h(Q,Z,"SKILL.md"))}function a(Q,Z){let $=h(Q,Z);if(!kQ($))return!1;return gZ($,{recursive:!0,force:!0}),!0}var jQ=()=>{};import{mkdirSync as RZ,renameSync as EZ,rmSync as IZ,writeFileSync as bZ}from"fs";import{dirname as DZ}from"path";function vQ(Q,Z){RZ(DZ(Q),{recursive:!0});let $=`${Q}.tmp`;try{bZ($,Z),EZ($,Q)}catch(J){throw IZ($,{force:!0}),J}}var pQ=()=>{};import{existsSync as OZ}from"fs";import{homedir as AZ}from"os";import{join as s}from"path";function yZ(){return process.env.HOME||process.env.USERPROFILE||AZ()}function LZ(Q,Z){return d(NQ(),Q,Z)}function lQ(Q){return R(NQ(),Q)}function _Z(Q){return a(NQ(),Q)}function kZ(Q){return m(GQ(),Q)}function hZ(Q){return c(GQ(),Q)}function SZ(Q){return l(GQ(),Q)}function pZ(Q){t(uQ(),KQ,cQ,Q)}function tQ(){return g(uQ(),KQ)}function mZ(){return n(uQ(),KQ,cQ)}function nQ(){let Q={};for(let $ of H)Q[$]=lQ($);let Z={};for(let $ of E)Z[$.event]=hZ({event:$.event,command:$.command});return{homeExists:OZ(r()),skills:Q,hooks:Z,claudeMdBlock:tQ()}}async function cZ(){let{INIT_SKILL:Q,REFRESH_SKILL:Z,PLAN_SKILL:$}=await Promise.resolve().then(() => (k(),WQ)),J={"beacon-init":Q,"beacon-refresh":Z,"beacon-plan":$},Y=[];for(let U of H){if(!lQ(U))Y.push(U);LZ(U,J[U])}let V=0;for(let U of E)if(kZ({event:U.event,matcher:U.matcher,command:U.command}))V++;let X=tQ();return pZ(CQ),{skillsAdded:Y,hooksAdded:V,claudeMdBlockTouched:!X}}async function A0(){let Q;try{Q={ok:!0,...await cZ()}}catch(Z){Q={ok:!1,error:Z instanceof Error?Z.message:String(Z),skillsAdded:[],hooksAdded:0,claudeMdBlockTouched:!1}}try{let Z=await Promise.resolve().then(() => (xQ(),mQ));if(Z.codexDetected())Q.codex={ok:!0,...await Z.setupCodexAssets()}}catch(Z){Q.codex={ok:!1,error:Z instanceof Error?Z.message:String(Z),skillsAdded:[],hooksAdded:0,agentsMdBlockTouched:!1,mcp:{added:!1}}}return Q}function dQ(){let Q=[];for(let J of H)if(_Z(J))Q.push(J);let Z=0;for(let J of E)if(SZ(J))Z++;let $=mZ();return{skillsRemoved:Q,hooksRemoved:Z,claudeMdBlockRemoved:$}}var r=()=>s(yZ(),".claude"),NQ=()=>s(r(),"skills"),GQ=()=>s(r(),"settings.json"),uQ=()=>s(r(),"CLAUDE.md"),KQ="<!-- beacon:global:start -->",cQ="<!-- beacon:global:end -->",H,E,CQ=`## Beacon (visual planning panel)
223
210
 
224
211
  This machine has Beacon installed \u2014 a local visual planning surface for the terminal-side
225
212
  agent. Beacon proposes feature plans (roadmap features + DB schema + endpoints) via MCP,
@@ -240,7 +227,20 @@ the user reviews on a canvas at /plan, and feedback flows back as the next round
240
227
  Feedback bundles inline annotations on the markdown PLUS any edits the user made directly
241
228
  on the /map and /db boards (added features, attached subtasks, edited columns, new
242
229
  endpoints). Treat board edits as the user's revision intent \u2014 re-propose matching them
243
- verbatim. Do NOT implement until the tool returns approval.`;var TQ=C(()=>{jQ();H=["beacon-init","beacon-refresh","beacon-plan"],D=[{event:"PostToolUse",matcher:"Edit|Write|MultiEdit",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"PermissionRequest",matcher:"ExitPlanMode",command:"beacon plan",description:"Pipe the agent's plan markdown into Beacon's /plan canvas for review."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose (instead of presenting it), nudge it to present the plan on Beacon's /plan canvas. Bounded by stop_hook_active \u2014 at most one nudge."}]});var $Z={};zQ($Z,{provisionDb:()=>V0});import{createClient as aZ}from"@libsql/client";import{drizzle as sZ}from"drizzle-orm/libsql";import{migrate as rZ}from"drizzle-orm/libsql/migrator";import{readMigrationFiles as oZ}from"drizzle-orm/migrator";import{dirname as EQ,join as iZ}from"path";import{fileURLToPath as eZ}from"url";async function ZQ(Q,Z){return(await Q.execute({sql:"SELECT 1 FROM sqlite_master WHERE type='table' AND name = ?",args:[Z]})).rows.length>0}async function J0(Q,Z){let $=await Q.execute(`PRAGMA table_info("${Z}")`);return new Set($.rows.map((J)=>String(J.name)))}async function ZZ(Q){if(!await ZQ(Q,"__drizzle_migrations"))return 0;let Z=await Q.execute('SELECT count(*) AS n FROM "__drizzle_migrations"');return Number(Z.rows[0]?.n??0)}async function Y0(Q){for(let[Z,$]of Object.entries($0)){if(!await ZQ(Q,Z))continue;let J=await J0(Q,Z);for(let Y of $){if(!J.has(Y))continue;await Q.execute(`UPDATE "${Z}" SET "${Y}" = CAST((julianday("${Y}") - 2440587.5) * 86400000 AS INTEGER) WHERE typeof("${Y}") = 'text'`)}}}async function V0(Q,Z=Z0){let $=aZ({url:Q});try{await $.execute("PRAGMA journal_mode = WAL;"),await $.execute("PRAGMA foreign_keys = ON;");let J=await ZQ($,"__drizzle_migrations"),Y=await ZQ($,"Node"),V=!1;if(Y&&!J){let U=oZ({migrationsFolder:Z})[0];if(U)await $.execute('CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (id SERIAL PRIMARY KEY, hash text NOT NULL, created_at numeric)'),await $.execute({sql:'INSERT INTO "__drizzle_migrations" ("hash", "created_at") VALUES (?, ?)',args:[U.hash,U.folderMillis]}),V=!0}let X=await ZZ($);if(await rZ(sZ($),{migrationsFolder:Z}),await ZZ($)>X)V=!0;return await Y0($),{migrated:V}}finally{$.close()}}var Q0,Z0,$0;var JZ=C(async()=>{Q0=EQ(EQ(EQ(eZ(import.meta.url)))),Z0=process.env.BEACON_MIGRATIONS_DIR||iZ(Q0,"drizzle"),$0={Node:["createdAt","updatedAt"],Note:["createdAt","updatedAt"],DbTable:["createdAt","updatedAt"],Endpoint:["createdAt","updatedAt"],DraftTable:["createdAt"],SyncState:["codeGraphSyncedAt","updatedAt"],AppSetting:["updatedAt"],ProjectMeta:["updatedAt"],CodeFile:["updatedAt"]}});import{AsyncLocalStorage as z0}from"async_hooks";import{spawnSync as q0}from"child_process";import{createHash as X0}from"crypto";import{existsSync as VZ,mkdirSync as $Q,readFileSync as zZ,writeFileSync as qZ}from"fs";import{homedir as U0}from"os";import{basename as P0,join as w}from"path";function G(){return process.env.BEACON_HOME||w(U0(),".beacon")}function IQ(){return w(G(),"workspaces.json")}function XZ(Q){return X0("sha256").update(Q).digest("hex").slice(0,12)}function Q1(Q=process.cwd()){let Z=q0("git",["rev-parse","--show-toplevel"],{cwd:Q,stdio:["ignore","pipe","ignore"]});if(Z.status===0){let $=Z.stdout?.toString().trim();if($)return $}return Q}function bQ(Q){return w(G(),Q)}function W0(Q){return`file:${w(bQ(Q),"db.sqlite")}`}function O(){try{let Q=JSON.parse(zZ(IQ(),"utf8"));return Array.isArray(Q)?Q:[]}catch{return[]}}function DQ(Q){$Q(G(),{recursive:!0}),qZ(IQ(),JSON.stringify(Q,null,2))}function OQ(){return O().sort((Q,Z)=>Z.lastOpenedAt.localeCompare(Q.lastOpenedAt))}function N(Q){return O().find((Z)=>Z.id===Q)??null}function H0(Q,Z,$=new Date().toISOString()){let J=XZ(Q),Y=O(),V=Y.find((z)=>z.id===J),X={id:J,path:Q,name:Z||V?.name||P0(Q),lastOpenedAt:$},U=[X,...Y.filter((z)=>z.id!==J)];return $Q(bQ(J),{recursive:!0}),DQ(U),X}function Z1(Q,Z=new Date().toISOString()){let $=O(),J=$.find((Y)=>Y.id===Q);if(!J)return;J.lastOpenedAt=Z,DQ($)}function $1(Q){if(DQ(O().filter((Z)=>Z.id!==Q)),AQ()===Q)B0(OQ()[0]?.id??null)}function UZ(){return w(G(),"active")}function AQ(){try{return zZ(UZ(),"utf8").trim()||null}catch{return null}}function B0(Q){$Q(G(),{recursive:!0}),qZ(UZ(),Q??"")}function J1(){let Q=AQ();return Q?N(Q):null}function Y1(){let Q=v0()??AQ();return Q?N(Q):null}function V1(Q){return N(Q)?.path??null}function z1(){return VZ(IQ())}var PZ="beacon_ws";function WZ(Q,Z){let $=Q.headers.get("cookie");if(!$)return null;for(let J of $.split(";")){let Y=J.indexOf("=");if(Y===-1)continue;if(J.slice(0,Y).trim()===Z)return decodeURIComponent(J.slice(Y+1).trim())}return null}function q1(Q){let Z=Q.headers.get("x-beacon-workspace");if(Z&&N(Z))return Z;let $=WZ(Q,PZ);if($&&N($))return $;return null}var j0="x-beacon-workspace-path";async function X1(Q){let Z=Q.headers.get("x-beacon-workspace");if(Z&&N(Z))return Z;let $=Q.headers.get(j0);if($&&(!Z||XZ($)===Z)){let Y=H0($);return await x0(Y.id),Y.id}let J=WZ(Q,PZ);if(J&&N(J))return J;return null}var HZ=new z0;function U1(Q,Z){return Q?HZ.run(Q,Z):Z()}function v0(){return HZ.getStore()??null}var YZ=new Set;async function x0(Q){let Z=bQ(Q),$=w(Z,"db.sqlite"),J=VZ($);if(J&&YZ.has($))return{ok:!0,created:!1,migrated:!1};try{$Q(Z,{recursive:!0});let{provisionDb:Y}=await JZ().then(() => $Z),V=await Y(W0(Q));return YZ.add($),{ok:!0,created:!J,migrated:J&&V.migrated}}catch(Y){return{ok:!1,created:!1,migrated:!1,error:Y instanceof Error?Y.message:String(Y)}}}k();MQ();TQ();import{existsSync as JQ,readFileSync as N0,rmSync as G0}from"fs";import{join as u0}from"path";var BZ=process.argv.slice(3),jZ=BZ.includes("--yes")||BZ.includes("-y"),j=(Q)=>`\x1B[32m\u2713\x1B[0m ${Q}`,B=(Q)=>`\x1B[2m${Q}\x1B[0m`,K=(Q)=>`
244
- \x1B[1m${Q}\x1B[0m`,vZ=(Q)=>`\x1B[33m!\x1B[0m ${Q}`,u=G(),A=OQ(),yQ=eQ();console.log(K(jZ?"Beacon \xB7 uninstall":"Beacon \xB7 uninstall (dry run)"));console.log(K("Global"));console.log(` ${JQ(u)?`wipe ${u} (${A.length} workspaces)`:`${B(`${u} \u2014 already gone`)}`}`);for(let Q of H)console.log(` ${yQ.skills[Q]?`remove ~/.claude/skills/${Q}/`:B(`skill ${Q} \u2014 already gone`)}`);for(let Q of D)console.log(` ${yQ.hooks[Q.event]?`remove hook ${Q.event} \u2192 ${Q.command}`:B(`hook ${Q.event} \u2192 ${Q.command} \u2014 already gone`)}`);console.log(` ${yQ.claudeMdBlock?"strip Beacon block from ~/.claude/CLAUDE.md":B("global CLAUDE.md block \u2014 already gone")}`);var YQ=KQ();console.log(K("Codex"));for(let Q of H)console.log(` ${YQ.skills[Q]?`remove ~/.agents/skills/${Q}/`:B(`skill ${Q} \u2014 already gone`)}`);for(let Q of T)console.log(` ${YQ.hooks[Q.event]?`remove hook ${Q.event} \u2192 ${Q.command} from ~/.codex/hooks.json`:B(`hook ${Q.event} \u2192 ${Q.command} \u2014 already gone`)}`);console.log(` ${YQ.agentsMdBlock?"strip Beacon block from ~/.codex/AGENTS.md":B("global ~/.codex/AGENTS.md block \u2014 already gone")}`);console.log(` ${YQ.mcp?"strip [mcp_servers.beacon] from ~/.codex/config.toml (if Beacon wrote it)":B("config.toml beacon entry \u2014 already gone")}`);if(A.length){console.log(K(`Per-repo (${A.length})`));for(let Q of A){if(!JQ(Q.path)){console.log(` ${B(`${Q.path} \u2014 repo no longer on disk, skipping`)}`);continue}console.log(` ${Q.path}`),console.log(` ${B("strip beacon entry from .mcp.json, workflow block from AGENTS.md, skills, CLAUDE.md @-import")}`)}}if(!jZ)console.log(K("Nothing was changed.")),console.log(" Run \x1B[1mbeacon uninstall --yes\x1B[0m to apply."),console.log(` The \x1B[1mbeacon\x1B[0m binary itself (the cloned source + your PATH symlink) is NOT removed by this \u2014 your install script handles that.
245
- `),process.exit(0);console.log(K("Applying\u2026"));var F=QZ();if(F.skillsRemoved.length)console.log(` ${j(`removed skills: ${F.skillsRemoved.join(", ")}`)}`);if(F.hooksRemoved)console.log(` ${j(`removed ${F.hooksRemoved} hook${F.hooksRemoved===1?"":"s"} from ~/.claude/settings.json`)}`);if(F.claudeMdBlockRemoved)console.log(` ${j("stripped Beacon block from ~/.claude/CLAUDE.md")}`);var x=CQ();if(x.skillsRemoved.length)console.log(` ${j(`removed ~/.agents/skills: ${x.skillsRemoved.join(", ")}`)}`);if(x.hooksRemoved)console.log(` ${j(`removed ${x.hooksRemoved} hook${x.hooksRemoved===1?"":"s"} from ~/.codex/hooks.json`)}`);if(x.agentsMdBlockRemoved)console.log(` ${j("stripped Beacon block from ~/.codex/AGENTS.md")}`);if(x.mcpRemoved)console.log(` ${j("stripped [mcp_servers.beacon] from ~/.codex/config.toml")}`);if(x.mcpSkipped)console.log(` ${vZ("left [mcp_servers.beacon] in ~/.codex/config.toml \u2014 it wasn't written by Beacon (remove with: codex mcp remove beacon)")}`);for(let Q of A){if(!JQ(Q.path))continue;let Z=PQ(Q.path),$=[];if(Z.skillsRemoved.length)$.push(`skills(${Z.skillsRemoved.length})`);if(Z.mcpUnregistered)$.push(".mcp.json");if(Z.agentsBlockRemoved)$.push("AGENTS.md");if(Z.claudeImportRemoved)$.push("CLAUDE.md");if($.length)console.log(` ${j(`${Q.path} \u2192 ${$.join(", ")}`)}`)}var K0=u0(u,"server.json");try{let{pid:Q}=JSON.parse(N0(K0,"utf8"));if(Q)try{process.kill(Q),console.log(` ${j(`stopped daemon (pid ${Q})`)}`)}catch{}}catch{}if(JQ(u))G0(u,{recursive:!0,force:!0}),console.log(` ${j(`removed ${u}`)}`);console.log(K("Done."));console.log(` ${vZ("The `beacon` binary on your PATH is still there \u2014 run the matching uninstall step from your installer to remove it.")}
230
+ verbatim. Do NOT implement until the tool returns approval.`;var MQ=C(()=>{jQ();H=["beacon-init","beacon-refresh","beacon-plan"],E=[{event:"PostToolUse",matcher:"Edit|Write|MultiEdit",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"PermissionRequest",matcher:"ExitPlanMode",command:"beacon plan",description:"Pipe the agent's plan markdown into Beacon's /plan canvas for review."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose (instead of presenting it), nudge it to present the plan on Beacon's /plan canvas. Bounded by stop_hook_active \u2014 at most one nudge."}]});var mQ={};zQ(mQ,{setupCodexAssets:()=>dZ,removeCodexMcp:()=>QZ,removeCodexArtifacts:()=>RQ,hasCodexMcp:()=>FQ,ensureCodexMcp:()=>eQ,codexMcpProblem:()=>nZ,codexDetected:()=>rQ,auditCodex:()=>gQ,CODEX_HOOKS:()=>T});import{readFileSync as QQ}from"fs";import{homedir as lZ}from"os";import{join as D}from"path";function aQ(){return process.env.HOME||process.env.USERPROFILE||lZ()}function rQ(){if(process.env.BEACON_CODEX==="1")return!0;if(process.env.BEACON_CODEX==="0")return!1;if(fQ===void 0)fQ=Bun.which("codex")!==null;return fQ}function b(Q){try{return Bun.TOML.parse(Q)}catch{return null}}function FQ(){try{return Boolean(b(QQ(f(),"utf8"))?.mcp_servers?.beacon)}catch{return!1}}function nZ(){let Q="";try{Q=QQ(f(),"utf8")}catch{return null}let Z=b(Q);if(!Z)return`~/.codex/config.toml does not parse \u2014 ${I}`;if(Z.mcp_servers?.beacon)return null;if(/^\s*mcp_servers\s*=/m.test(Q))return`mcp_servers is an inline table \u2014 ${I}`;return null}function eQ(){let Q="",Z=!1;try{Q=QQ(f(),"utf8"),Z=!0}catch{}if(Z){let V=b(Q);if(!V)return{added:!1,error:`~/.codex/config.toml does not parse \u2014 ${I}`};if(V.mcp_servers?.beacon)return{added:!1};if(/^\s*mcp_servers\s*=/m.test(Q))return{added:!1,error:`mcp_servers is an inline table \u2014 ${I}`}}let $=!Q?"":Q.endsWith(`
231
+ `)?`
232
+ `:`
233
+
234
+ `,J=Q+$+tZ;if(b(J)?.mcp_servers?.beacon?.command!=="beacon")return{added:!1,error:`could not safely append [mcp_servers.beacon] \u2014 ${I}`};return vQ(f(),J),{added:!0}}function QZ(){let Q="";try{Q=QQ(f(),"utf8")}catch{return{removed:!1}}let Z=Q.split(`
235
+ `),$=Z.indexOf(oQ);if($===-1)return{removed:!1,skipped:FQ()};let J=Z.indexOf(iQ,$);if(J===-1)return{removed:!1,skipped:!0};Z.splice($,J-$+1);let Y=Z.join(`
236
+ `).replace(/\n{3,}/g,`
237
+
238
+ `).replace(/^\n+/,"");if(b(Y)===null)return{removed:!1,skipped:!0};return vQ(f(),Y),{removed:!0}}async function dZ(){let{INIT_SKILL:Q,REFRESH_SKILL:Z,PLAN_SKILL:$}=await Promise.resolve().then(() => (k(),WQ)),J={"beacon-init":Q,"beacon-refresh":Z,"beacon-plan":$},Y=[];for(let z of H){if(!R(i(),z))Y.push(z);d(i(),z,J[z])}let V=0;for(let z of T)if(m(wQ(),{event:z.event,matcher:z.matcher,command:z.command}))V++;let X=g(o(),e);t(o(),e,sQ,CQ);let U=eQ();return{skillsAdded:Y,hooksAdded:V,agentsMdBlockTouched:!X,mcp:U}}function gQ(){let Q={};for(let $ of H)Q[$]=R(i(),$);let Z={};for(let $ of T)Z[$.event]=c(wQ(),{event:$.event,command:$.command});return{detected:rQ(),skills:Q,hooks:Z,agentsMdBlock:g(o(),e),mcp:FQ()}}function RQ(){let Q=[];for(let Y of H)if(a(i(),Y))Q.push(Y);let Z=0;for(let Y of T)if(l(wQ(),{event:Y.event,command:Y.command}))Z++;let $=n(o(),e,sQ),J=QZ();return{skillsRemoved:Q,hooksRemoved:Z,agentsMdBlockRemoved:$,mcpRemoved:J.removed,mcpSkipped:J.skipped}}var TQ=()=>D(aQ(),".codex"),wQ=()=>D(TQ(),"hooks.json"),f=()=>D(TQ(),"config.toml"),o=()=>D(TQ(),"AGENTS.md"),i=()=>D(aQ(),".agents","skills"),e="<!-- beacon:global:start -->",sQ="<!-- beacon:global:end -->",T,fQ,oQ="# beacon:start (managed by Beacon \u2014 `beacon uninstall` removes this block)",iQ="# beacon:end",tZ,I="add it manually: codex mcp add beacon -- beacon mcp";var xQ=C(()=>{jQ();pQ();MQ();T=[{event:"PostToolUse",matcher:"apply_patch",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose, nudge it to present the plan on Beacon's /plan canvas."}];tZ=`${oQ}
239
+ [mcp_servers.beacon]
240
+ command = "beacon"
241
+ args = ["mcp"]
242
+ ${iQ}
243
+ `});var $Z={};zQ($Z,{provisionDb:()=>V0});import{createClient as aZ}from"@libsql/client";import{drizzle as sZ}from"drizzle-orm/libsql";import{migrate as rZ}from"drizzle-orm/libsql/migrator";import{readMigrationFiles as oZ}from"drizzle-orm/migrator";import{dirname as EQ,join as iZ}from"path";import{fileURLToPath as eZ}from"url";async function ZQ(Q,Z){return(await Q.execute({sql:"SELECT 1 FROM sqlite_master WHERE type='table' AND name = ?",args:[Z]})).rows.length>0}async function J0(Q,Z){let $=await Q.execute(`PRAGMA table_info("${Z}")`);return new Set($.rows.map((J)=>String(J.name)))}async function ZZ(Q){if(!await ZQ(Q,"__drizzle_migrations"))return 0;let Z=await Q.execute('SELECT count(*) AS n FROM "__drizzle_migrations"');return Number(Z.rows[0]?.n??0)}async function Y0(Q){for(let[Z,$]of Object.entries($0)){if(!await ZQ(Q,Z))continue;let J=await J0(Q,Z);for(let Y of $){if(!J.has(Y))continue;await Q.execute(`UPDATE "${Z}" SET "${Y}" = CAST((julianday("${Y}") - 2440587.5) * 86400000 AS INTEGER) WHERE typeof("${Y}") = 'text'`)}}}async function V0(Q,Z=Z0){let $=aZ({url:Q});try{await $.execute("PRAGMA journal_mode = WAL;"),await $.execute("PRAGMA foreign_keys = ON;");let J=await ZQ($,"__drizzle_migrations"),Y=await ZQ($,"Node"),V=!1;if(Y&&!J){let U=oZ({migrationsFolder:Z})[0];if(U)await $.execute('CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (id SERIAL PRIMARY KEY, hash text NOT NULL, created_at numeric)'),await $.execute({sql:'INSERT INTO "__drizzle_migrations" ("hash", "created_at") VALUES (?, ?)',args:[U.hash,U.folderMillis]}),V=!0}let X=await ZZ($);if(await rZ(sZ($),{migrationsFolder:Z}),await ZZ($)>X)V=!0;return await Y0($),{migrated:V}}finally{$.close()}}var Q0,Z0,$0;var JZ=C(async()=>{Q0=EQ(EQ(EQ(eZ(import.meta.url)))),Z0=process.env.BEACON_MIGRATIONS_DIR||iZ(Q0,"drizzle"),$0={Node:["createdAt","updatedAt"],Note:["createdAt","updatedAt"],DbTable:["createdAt","updatedAt"],Endpoint:["createdAt","updatedAt"],DraftTable:["createdAt"],SyncState:["codeGraphSyncedAt","updatedAt"],AppSetting:["updatedAt"],ProjectMeta:["updatedAt"],CodeFile:["updatedAt"]}});import{AsyncLocalStorage as z0}from"async_hooks";import{spawnSync as q0}from"child_process";import{createHash as X0}from"crypto";import{existsSync as VZ,mkdirSync as $Q,readFileSync as zZ,writeFileSync as qZ}from"fs";import{homedir as U0}from"os";import{basename as P0,join as w}from"path";function G(){return process.env.BEACON_HOME||w(U0(),".beacon")}function IQ(){return w(G(),"workspaces.json")}function XZ(Q){return X0("sha256").update(Q).digest("hex").slice(0,12)}function Q1(Q=process.cwd()){let Z=q0("git",["rev-parse","--show-toplevel"],{cwd:Q,stdio:["ignore","pipe","ignore"]});if(Z.status===0){let $=Z.stdout?.toString().trim();if($)return $}return Q}function bQ(Q){return w(G(),Q)}function W0(Q){return`file:${w(bQ(Q),"db.sqlite")}`}function O(){try{let Q=JSON.parse(zZ(IQ(),"utf8"));return Array.isArray(Q)?Q:[]}catch{return[]}}function DQ(Q){$Q(G(),{recursive:!0}),qZ(IQ(),JSON.stringify(Q,null,2))}function OQ(){return O().sort((Q,Z)=>Z.lastOpenedAt.localeCompare(Q.lastOpenedAt))}function N(Q){return O().find((Z)=>Z.id===Q)??null}function H0(Q,Z,$=new Date().toISOString()){let J=XZ(Q),Y=O(),V=Y.find((z)=>z.id===J),X={id:J,path:Q,name:Z||V?.name||P0(Q),lastOpenedAt:$},U=[X,...Y.filter((z)=>z.id!==J)];return $Q(bQ(J),{recursive:!0}),DQ(U),X}function Z1(Q,Z=new Date().toISOString()){let $=O(),J=$.find((Y)=>Y.id===Q);if(!J)return;J.lastOpenedAt=Z,DQ($)}function $1(Q){if(DQ(O().filter((Z)=>Z.id!==Q)),AQ()===Q)B0(OQ()[0]?.id??null)}function UZ(){return w(G(),"active")}function AQ(){try{return zZ(UZ(),"utf8").trim()||null}catch{return null}}function B0(Q){$Q(G(),{recursive:!0}),qZ(UZ(),Q??"")}function J1(){let Q=AQ();return Q?N(Q):null}function Y1(){let Q=v0()??AQ();return Q?N(Q):null}function V1(Q){return N(Q)?.path??null}function z1(){return VZ(IQ())}var PZ="beacon_ws";function WZ(Q,Z){let $=Q.headers.get("cookie");if(!$)return null;for(let J of $.split(";")){let Y=J.indexOf("=");if(Y===-1)continue;if(J.slice(0,Y).trim()===Z)return decodeURIComponent(J.slice(Y+1).trim())}return null}function q1(Q){let Z=Q.headers.get("x-beacon-workspace");if(Z&&N(Z))return Z;let $=WZ(Q,PZ);if($&&N($))return $;return null}var j0="x-beacon-workspace-path";async function X1(Q){let Z=Q.headers.get("x-beacon-workspace");if(Z&&N(Z))return Z;let $=Q.headers.get(j0);if($&&(!Z||XZ($)===Z)){let Y=H0($);return await x0(Y.id),Y.id}let J=WZ(Q,PZ);if(J&&N(J))return J;return null}var HZ=new z0;function U1(Q,Z){return Q?HZ.run(Q,Z):Z()}function v0(){return HZ.getStore()??null}var YZ=new Set;async function x0(Q){let Z=bQ(Q),$=w(Z,"db.sqlite"),J=VZ($);if(J&&YZ.has($))return{ok:!0,created:!1,migrated:!1};try{$Q(Z,{recursive:!0});let{provisionDb:Y}=await JZ().then(() => $Z),V=await Y(W0(Q));return YZ.add($),{ok:!0,created:!J,migrated:J&&V.migrated}}catch(Y){return{ok:!1,created:!1,migrated:!1,error:Y instanceof Error?Y.message:String(Y)}}}k();xQ();MQ();import{existsSync as JQ,readFileSync as N0,rmSync as G0}from"fs";import{join as u0}from"path";var BZ=process.argv.slice(3),jZ=BZ.includes("--yes")||BZ.includes("-y"),j=(Q)=>`\x1B[32m\u2713\x1B[0m ${Q}`,B=(Q)=>`\x1B[2m${Q}\x1B[0m`,K=(Q)=>`
244
+ \x1B[1m${Q}\x1B[0m`,vZ=(Q)=>`\x1B[33m!\x1B[0m ${Q}`,u=G(),A=OQ(),yQ=nQ();console.log(K(jZ?"Beacon \xB7 uninstall":"Beacon \xB7 uninstall (dry run)"));console.log(K("Global"));console.log(` ${JQ(u)?`wipe ${u} (${A.length} workspaces)`:`${B(`${u} \u2014 already gone`)}`}`);for(let Q of H)console.log(` ${yQ.skills[Q]?`remove ~/.claude/skills/${Q}/`:B(`skill ${Q} \u2014 already gone`)}`);for(let Q of E)console.log(` ${yQ.hooks[Q.event]?`remove hook ${Q.event} \u2192 ${Q.command}`:B(`hook ${Q.event} \u2192 ${Q.command} \u2014 already gone`)}`);console.log(` ${yQ.claudeMdBlock?"strip Beacon block from ~/.claude/CLAUDE.md":B("global CLAUDE.md block \u2014 already gone")}`);var YQ=gQ();console.log(K("Codex"));for(let Q of H)console.log(` ${YQ.skills[Q]?`remove ~/.agents/skills/${Q}/`:B(`skill ${Q} \u2014 already gone`)}`);for(let Q of T)console.log(` ${YQ.hooks[Q.event]?`remove hook ${Q.event} \u2192 ${Q.command} from ~/.codex/hooks.json`:B(`hook ${Q.event} \u2192 ${Q.command} \u2014 already gone`)}`);console.log(` ${YQ.agentsMdBlock?"strip Beacon block from ~/.codex/AGENTS.md":B("global ~/.codex/AGENTS.md block \u2014 already gone")}`);console.log(` ${YQ.mcp?"strip [mcp_servers.beacon] from ~/.codex/config.toml (if Beacon wrote it)":B("config.toml beacon entry \u2014 already gone")}`);if(A.length){console.log(K(`Per-repo (${A.length})`));for(let Q of A){if(!JQ(Q.path)){console.log(` ${B(`${Q.path} \u2014 repo no longer on disk, skipping`)}`);continue}console.log(` ${Q.path}`),console.log(` ${B("strip beacon entry from .mcp.json, workflow block from AGENTS.md, skills, CLAUDE.md @-import")}`)}}if(!jZ)console.log(K("Nothing was changed.")),console.log(" Run \x1B[1mbeacon uninstall --yes\x1B[0m to apply."),console.log(` The \x1B[1mbeacon\x1B[0m binary itself (the cloned source + your PATH symlink) is NOT removed by this \u2014 your install script handles that.
245
+ `),process.exit(0);console.log(K("Applying\u2026"));var F=dQ();if(F.skillsRemoved.length)console.log(` ${j(`removed skills: ${F.skillsRemoved.join(", ")}`)}`);if(F.hooksRemoved)console.log(` ${j(`removed ${F.hooksRemoved} hook${F.hooksRemoved===1?"":"s"} from ~/.claude/settings.json`)}`);if(F.claudeMdBlockRemoved)console.log(` ${j("stripped Beacon block from ~/.claude/CLAUDE.md")}`);var x=RQ();if(x.skillsRemoved.length)console.log(` ${j(`removed ~/.agents/skills: ${x.skillsRemoved.join(", ")}`)}`);if(x.hooksRemoved)console.log(` ${j(`removed ${x.hooksRemoved} hook${x.hooksRemoved===1?"":"s"} from ~/.codex/hooks.json`)}`);if(x.agentsMdBlockRemoved)console.log(` ${j("stripped Beacon block from ~/.codex/AGENTS.md")}`);if(x.mcpRemoved)console.log(` ${j("stripped [mcp_servers.beacon] from ~/.codex/config.toml")}`);if(x.mcpSkipped)console.log(` ${vZ("left [mcp_servers.beacon] in ~/.codex/config.toml \u2014 it wasn't written by Beacon (remove with: codex mcp remove beacon)")}`);for(let Q of A){if(!JQ(Q.path))continue;let Z=PQ(Q.path),$=[];if(Z.skillsRemoved.length)$.push(`skills(${Z.skillsRemoved.length})`);if(Z.mcpUnregistered)$.push(".mcp.json");if(Z.agentsBlockRemoved)$.push("AGENTS.md");if(Z.claudeImportRemoved)$.push("CLAUDE.md");if($.length)console.log(` ${j(`${Q.path} \u2192 ${$.join(", ")}`)}`)}var K0=u0(u,"server.json");try{let{pid:Q}=JSON.parse(N0(K0,"utf8"));if(Q)try{process.kill(Q),console.log(` ${j(`stopped daemon (pid ${Q})`)}`)}catch{}}catch{}if(JQ(u))G0(u,{recursive:!0,force:!0}),console.log(` ${j(`removed ${u}`)}`);console.log(K("Done."));console.log(` ${vZ("The `beacon` binary on your PATH is still there \u2014 run the matching uninstall step from your installer to remove it.")}
246
246
  `);
@@ -0,0 +1,242 @@
1
+ // @bun
2
+ var Tq=Object.defineProperty;var Rq=(q)=>q;function Iq(q,z){this[q]=Rq.bind(null,z)}var Pq=(q,z)=>{for(var J in z)Tq(q,J,{get:z[J],enumerable:!0,configurable:!0,set:Iq.bind(z,J)})};var g=(q,z)=>()=>(q&&(z=q(q=0)),z);var d={};Pq(d,{removeRepoAssets:()=>_q,installRefreshSkill:()=>Aq,installPlanSkill:()=>yq,installInitSkill:()=>Eq,installCodexRepoSkills:()=>Dq,ensureWorkflowDoc:()=>hq,ensureMcp:()=>kq,auditRepo:()=>Lq,REFRESH_SKILL:()=>t,PLAN_SKILL:()=>Uq,INIT_SKILL:()=>a});import{existsSync as H,mkdirSync as K,readFileSync as X,rmSync as b,writeFileSync as x}from"fs";import{join as $}from"path";function Eq(q){let z=$(q,".claude","skills","beacon-init");K(z,{recursive:!0});let J=$(z,"SKILL.md");return x(J,a),J}function Aq(q){let z=$(q,".claude","skills","beacon-refresh");K(z,{recursive:!0});let J=$(z,"SKILL.md");return x(J,t),J}function yq(q){let z=$(q,".claude","skills","beacon-plan");K(z,{recursive:!0});let J=$(z,"SKILL.md");return x(J,Uq),J}function Dq(q){let z=[];for(let J of Oq){let Q=$(q,".agents","skills",J.name);K(Q,{recursive:!0});let V=$(Q,"SKILL.md");x(V,J.body()),z.push(V)}return z}function hq(q){let z=$(q,"AGENTS.md"),J="";try{J=X(z,"utf8")}catch{}let Q=new RegExp(`${f}[\\s\\S]*?${c}`);J=Q.test(J)?J.replace(Q,Wq):`${J.trim()}
3
+
4
+ ${Wq}
5
+ `.trimStart(),x(z,J.endsWith(`
6
+ `)?J:`${J}
7
+ `);let V=$(q,"CLAUDE.md"),Y="";try{Y=X(V,"utf8")}catch{}if(!/@AGENTS\.md/.test(Y))x(V,`${Y?`${Y.trim()}
8
+
9
+ `:""}@AGENTS.md
10
+ `)}function kq(q){let z=$(q,".mcp.json"),J={};try{J=JSON.parse(X(z,"utf8"))}catch{}if(J.mcpServers=J.mcpServers??{},J.mcpServers.beacon)return{path:z,added:!1};return J.mcpServers.beacon={command:"beacon",args:["mcp"]},x(z,JSON.stringify(J,null,2)+`
11
+ `),{path:z,added:!0}}function Lq(q){let z=$(q,".mcp.json"),J=!1;try{J=!!JSON.parse(X(z,"utf8")).mcpServers?.beacon}catch{}let Q=!1;try{Q=X($(q,"AGENTS.md"),"utf8").includes(f)}catch{}let V=!1;try{V=/@AGENTS\.md/.test(X($(q,"CLAUDE.md"),"utf8"))}catch{}return{repo:q,mcpRegistered:J,agentsMdBlock:Q,claudeMdImport:V,skills:{"beacon-init":H($(q,".claude","skills","beacon-init","SKILL.md")),"beacon-refresh":H($(q,".claude","skills","beacon-refresh","SKILL.md"))},codexSkills:{"beacon-init":H($(q,".agents","skills","beacon-init","SKILL.md")),"beacon-refresh":H($(q,".agents","skills","beacon-refresh","SKILL.md"))}}}function _q(q){let z=[];for(let Z of["beacon-init","beacon-refresh","beacon-db-design"]){let U=$(q,".claude","skills",Z);if(H(U))b(U,{recursive:!0,force:!0}),z.push(Z)}for(let Z of["beacon-init","beacon-refresh"]){let U=$(q,".agents","skills",Z);if(H(U))b(U,{recursive:!0,force:!0}),z.push(`codex:${Z}`)}let J=!1,Q=$(q,".mcp.json");try{let Z=JSON.parse(X(Q,"utf8"));if(Z.mcpServers?.beacon){if(delete Z.mcpServers.beacon,J=!0,Z.mcpServers&&Object.keys(Z.mcpServers).length===0)delete Z.mcpServers;if(Object.keys(Z).length===0)b(Q,{force:!0});else x(Q,JSON.stringify(Z,null,2)+`
12
+ `)}}catch{}let V=!1,Y=$(q,"AGENTS.md");try{let Z=X(Y,"utf8"),U=new RegExp(`\\n?${f}[\\s\\S]*?${c}\\n?`);if(U.test(Z)){let S=Z.replace(U,`
13
+ `).replace(/\n{3,}/g,`
14
+
15
+ `).trimStart();x(Y,S.endsWith(`
16
+ `)?S:`${S}
17
+ `),V=!0}}catch{}let P=!1,W=$(q,"CLAUDE.md");try{let Z=X(W,"utf8"),U=Z.replace(/^[ \t]*@AGENTS\.md[ \t]*\n?/m,"");if(U!==Z){if(!U.trim())b(W,{force:!0});else x(W,U);P=!0}}catch{}return{skillsRemoved:z,mcpUnregistered:J,agentsBlockRemoved:V,claudeImportRemoved:P}}var a=`---
18
+ name: beacon-init
19
+ description: Read this repository and map its architecture, schema, and roadmap into Beacon (the local visual planning panel). Use when the user runs /beacon-init, asks to "set up Beacon for this repo", or asks to initialize/bootstrap Beacon's map of this codebase.
20
+ ---
21
+
22
+ # Map this repo into Beacon (/beacon-init)
23
+
24
+ The user already has Beacon running. You're going to map this repository's architecture into it \u2014 what used to be \`beacon init\`. **You** do the analysis (your session already has the codebase context); Beacon just persists what you send.
25
+
26
+ ## What you produce
27
+
28
+ A single \`beacon_init_persist\` MCP tool call with:
29
+
30
+ - **components**: 8\u201325 main building blocks of this codebase. NOT every file. Group them by \`domain\` (short UPPERCASE: AUTH, API, DATA, UI, JOBS, INFRA, BILLING, SEARCH, \u2026). For each: a one-line technical \`role\`, a one-sentence plain-language \`plain\`, the few \`files\` that implement it (repo-relative), and \`depends\` listing other component titles it relies on. Use the dependency graph you can see in the source \u2014 files that import each other heavily usually belong together. If you spot a bug or something worth investigating while reading a component's code, add \`bugs: [{ note }]\` to that component \u2014 it renders as a bug flag on the node (attributed to the agent). Only flag what you actually saw in the code; don't speculate.
31
+ - **roadmap**: 3\u20136 BROAD strategic directions. Big-picture themes only \u2014 "Harden auth & security", "Add observability", "Scale the data layer", "Pay down test-coverage debt". NOT detailed tasks. NOT file-level. Each gets a short title and one-line \`why\`.
32
+ - **overview**: one paragraph describing what this project is and its stack. This lands in AGENTS.md as the project intro.
33
+ - **conventions**: 3\u20138 concrete rules a contributor MUST follow \u2014 build/test commands, where code goes, patterns, things easy to get wrong. Infer from actual files, not assumptions.
34
+ - **snapshot** (optional but encouraged): \`{ tables, relations, endpoints }\` for the existing database. If the project uses Prisma, read \`prisma/schema.prisma\`. If SQLAlchemy, read the model files. If Django, read \`models.py\`. If you find no obvious schema source, skip the snapshot \u2014 don't fabricate.
35
+
36
+ ## How to do it
37
+
38
+ 1. **Survey**. Use \`LS\` / \`Glob\` to see the top-level structure. Read \`README.md\` and the manifest (\`package.json\` / \`pyproject.toml\` / \`go.mod\` / \`Cargo.toml\` / \`pom.xml\`).
39
+ 2. **Sample the source.** Read 15\u201330 representative files \u2014 one per cluster you can identify. Don't read everything; pick by name (route files, model files, main entrypoints, key services). The goal is to identify boundaries, not memorize every line.
40
+ 3. **Identify the schema** if any. \`prisma/schema.prisma\` \u2192 translate each model into a \`tables\` entry. \`alembic\`/SQLAlchemy \u2192 read the latest models. Django \u2192 read \`models.py\`. Skip the snapshot if the source-of-truth isn't obvious.
41
+ 4. **Identify endpoints** if any. Look for routes \u2014 Next.js \`app/api/*\` files, FastAPI \`@router.*\` / \`@app.*\`, Express \`app.get\`/etc. For each endpoint try to fill \`uses: [{ table, access }]\` so the canvas can draw which endpoint touches which table.
42
+ 5. **Call \`beacon_init_persist\`** ONCE with the whole analysis. It replaces any prior init-derived map (idempotent) and regenerates \`AGENTS.md\`.
43
+
44
+ ## What you should NOT do
45
+
46
+ - Don't propose detailed tasks in \`roadmap\` \u2014 that's what \`beacon_propose_plan\` is for. Init roadmap is strategic only.
47
+ - Don't list every file as a \`component\`. Aim for ~15. If you have 40, you're listing files, not components.
48
+ - Don't fabricate tables/endpoints. If you can't find the schema source, omit \`snapshot\`.
49
+ - Don't ask the user to confirm before persisting. The user invoked /beacon-init \u2014 that's the confirmation.
50
+
51
+ If \`beacon_init_persist\` isn't available, the Beacon panel isn't running in this repo. Tell the user to run \`beacon\` here first, then re-invoke /beacon-init.
52
+
53
+ After the tool returns, tell the user the counts (components / roadmap / tables / endpoints) and point them at the running Beacon panel.
54
+ `,t=`---
55
+ name: beacon-refresh
56
+ description: Re-survey the repo and update Beacon's architecture / schema / endpoints map after /beacon-init was already run \u2014 picks up new components, removed ones, schema changes, and new routes. Use when the user runs /beacon-refresh or asks to "refresh", "update", "re-sync", or "bring Beacon up to date" with the current code.
57
+ ---
58
+
59
+ # Refresh Beacon's map (/beacon-refresh)
60
+
61
+ Beacon was already initialized in this repo (\`/beacon-init\` ran at some point). The codebase has moved since then \u2014 new modules, removed ones, schema changes, new routes. Your job is to re-survey the current code, show the user what changed, then persist the refreshed map.
62
+
63
+ ## How it differs from /beacon-init
64
+
65
+ - **Init is a cold start** \u2014 no prior map, you survey everything fresh.
66
+ - **Refresh is incremental** \u2014 the map already exists. Read what's there first, then diff against the source so you can tell the user what actually changed. The user gets to see "+ 3 new components, \u2212 1 removed, ~ 2 changed roles" instead of an opaque re-run.
67
+
68
+ ## What gets preserved vs replaced
69
+
70
+ The \`beacon_init_persist\` tool **replaces only init-derived nodes** (\`source=INIT\`). Anything the user added manually on the canvas \u2014 manually-created components, hand-edited tables, custom positions, notes, draft feature plans \u2014 survives the refresh untouched. So you can re-run this freely; nothing the user curated by hand is at risk.
71
+
72
+ The one caveat: if the user manually edited an INIT-source node on the canvas (e.g., renamed it, rewrote its role), that edit IS overwritten when you re-persist. If the user mentions hand-curated INIT nodes, ask whether they want those carried into the new analysis verbatim.
73
+
74
+ ## How to do it
75
+
76
+ 1. **Read the current map.** Call \`beacon_entities\` with \`{ kind: "architecture" }\`, \`{ kind: "roadmap" }\`, \`{ kind: "tables" }\`, \`{ kind: "endpoints" }\`. This is what Beacon has now.
77
+ 2. **Survey the source like init.** Same approach as \`/beacon-init\`: \`LS\` / \`Glob\` for top-level structure, read \`README.md\` and the manifest, sample 15\u201330 representative files. Focus on areas likely to have changed \u2014 diff your memory against what \`beacon_entities\` returned.
78
+ 3. **Build the diff in your head.** For each entity kind:
79
+ - **components**: which titles in the current map no longer match any cluster you'd produce? Which clusters you'd produce don't appear in the current map?
80
+ - **tables**: any added / removed since? Any model files you can see that aren't in the snapshot?
81
+ - **endpoints**: walk the route directories \u2014 any new routes, any deleted ones?
82
+ - **roadmap**: usually stable, but a strategic theme can finish or new ones can emerge.
83
+ 4. **Surface the diff to the user, briefly, BEFORE persisting.** Something like:
84
+ - **+ added**: NEW_COMPONENT_1, NEW_COMPONENT_2 (with one-line reason each)
85
+ - **\u2212 removed**: STALE_COMPONENT (file no longer exists)
86
+ - **~ changed**: COMPONENT_X (role expanded to cover Y)
87
+ - **schema**: + 2 new tables (TableA, TableB); + 3 new endpoints; \u2212 1 deprecated endpoint
88
+ No need to wait for confirmation \u2014 just show the diff so the user sees what's about to land.
89
+ 5. **Call \`beacon_init_persist\`** ONCE with the refreshed full analysis (same shape as init: \`components\`, \`roadmap\`, \`overview\`, \`conventions\`, \`snapshot\`). It replaces all init-source nodes and regenerates \`AGENTS.md\`. Bug flags already on a component survive the refresh (they're carried over by title); add \`bugs: [{ note }]\` for anything NEW you found worth investigating \u2014 identical open flags are not duplicated.
90
+
91
+ ## What you should NOT do
92
+
93
+ - Don't ask "should I refresh?" \u2014 the user invoked /beacon-refresh, that's the answer.
94
+ - Don't preserve stale components for sentimental reasons. If the underlying files are gone or merged into another component, drop it from the new \`components\` list.
95
+ - Don't pad with file-level granularity. Refresh maintains the same ~15-component altitude as init.
96
+ - Don't fabricate changes. If the codebase hasn't materially moved since the last init, say so and persist the current state anyway (re-runs are cheap; it's fine).
97
+
98
+ If \`beacon_entities\` or \`beacon_init_persist\` isn't available, the Beacon panel isn't running in this repo. Tell the user to run \`beacon\` here first, then re-invoke /beacon-refresh.
99
+
100
+ After the tool returns, report the final counts plus a one-line summary of the diff you surfaced.
101
+ `,Uq=`---
102
+ name: beacon-plan
103
+ description: Present your current plan or approach to the user on Beacon's /plan canvas for review \u2014 instead of asking for approval in prose. Use when the user says "present the plan", "show me the plan", "let me see it / the plan", or whenever you are about to end a turn asking whether to proceed with a plan, design, or approach.
104
+ ---
105
+
106
+ # Present a plan on Beacon (/beacon-plan)
107
+
108
+ Beacon reviews plans on a canvas at /plan \u2014 never as a wall of text in the terminal. So do NOT
109
+ end a turn with "here's my plan\u2026 should I proceed?" in prose. Present it through Beacon and let the
110
+ tool BLOCK until the user decides.
111
+
112
+ ## How to present
113
+
114
+ Call the **\`beacon_present_plan\`** MCP tool with your plan as markdown:
115
+
116
+ - \`description\`: a one-line summary shown in the review header.
117
+ - \`markdown\`: the full plan as markdown (headings, lists, code).
118
+ - If the plan proposes DB tables / relations / endpoints or roadmap features, embed ONE fenced
119
+ \`\`\`beacon JSON block in the markdown \u2014 the same shapes \`beacon_propose_plan\` accepts:
120
+
121
+ \`\`\`beacon
122
+ { "tables": [...], "relations": [...], "endpoints": [...], "features": [...] }
123
+ \`\`\`
124
+
125
+ Beacon extracts that block deterministically, strips it from the prose, and renders an editable
126
+ board on /plan. The board is built ONLY from the block \u2014 prose is never parsed \u2014 so mirror EVERY
127
+ table/endpoint/feature you mention in the prose into the block, or that board will be empty.
128
+
129
+ \`beacon_present_plan\` opens /plan and BLOCKS until the user clicks Approve / Discard / submits
130
+ feedback, then returns their verdict. Implement code or migrations ONLY after it returns approval.
131
+ If it returns feedback, revise and call it again.
132
+
133
+ ## Which tool
134
+
135
+ - **Pure schema/feature plan** (tables + endpoints + roadmap features, little prose) \u2192 you may use
136
+ \`beacon_propose_plan\` with the structured fields instead; it's the same review loop.
137
+ - **Anything else** (a code-change plan, a mixed plan, a "how should I approach X") \u2192 use
138
+ \`beacon_present_plan\` with markdown so the full reasoning shows on /plan.
139
+
140
+ If \`beacon_present_plan\` isn't available, the panel isn't wired here \u2014 fall back to ExitPlanMode
141
+ with the same \`\`\`beacon block (Claude Code only; Codex has no ExitPlanMode), or tell the user to
142
+ run \`beacon\` in this repo once.
143
+ `,Oq,f="<!-- beacon:workflow:start -->",c="<!-- beacon:workflow:end -->",Wq;var n=g(()=>{Oq=[{name:"beacon-init",body:()=>a},{name:"beacon-refresh",body:()=>t}];Wq=`${f}
144
+ ## Beacon \u2014 feature workflow
145
+
146
+ This project uses Beacon (a local planning/visualization panel; run \`beacon\` to open it). When you start work on a FEATURE \u2014 whether referenced via an \`@beacon:feature://\u2026\` mention, an \`@beacon:note://\u2026\` note the user wrote in the Notes panel (treat its checkbox \`- [ ]\` todos as subtasks and order features by their dependencies), or just described in chat \u2014 follow these steps in order:
147
+
148
+ ### 1. Load context FIRST \u2014 do NOT Glob/Grep the codebase blind
149
+
150
+ Call \`beacon_context_for_feature({ id | title | query })\` BEFORE reading files. It returns, in one round-trip:
151
+ - the files the feature is attached to,
152
+ - what those files import + what imports them (live code-graph blast radius),
153
+ - endpoints in the feature's domain + the tables each touches + those tables' FK relations,
154
+ - sibling architecture components and the project's conventions.
155
+
156
+ That bundle replaces the discovery phase. Read only the files it returns plus whatever those imports lead you to. If the feature has no files attached yet, the bundle still gives you the domain map \u2014 Glob is a last resort.
157
+
158
+ Mid-feature, when deciding whether a change is safe, call \`beacon_blast_radius({ path })\` for the file you're about to edit \u2014 same code-graph data, file-centric.
159
+
160
+ ### 2. Design the data BEFORE writing code
161
+
162
+ Determine the database tables the feature needs. If any don't exist yet, design the schema and call \`beacon_propose_plan\` (tables + relations + endpoints). This renders an **editable draft on the /plan page** for the user to review. The tool BLOCKS until the user clicks Approve / Discard / submits feedback. Implement migrations + code ONLY after it returns approval.
163
+
164
+ When listing endpoints, give each \`uses: [{ table, access }]\` so the endpoint\u2192table links draw on /db.
165
+
166
+ EVERY feature MUST carry \`category\` (e.g. AUTH | SEARCH | DATA | INTEL | BILLING | \u2026; \`cluster\` is accepted as an alias) and \`priority\` (0 = P0 critical, 1 = P1 high, 2 = P2 medium, 3 = P3 low). Beacon REJECTS a plan whose features omit either \u2014 \`beacon_propose_plan\` returns the list of what's missing, and an ExitPlanMode \`\`\`beacon block is denied \u2014 so set both on every feature instead of relying on defaults.
167
+
168
+ REUSE before you create. Call \`beacon_map\` to see the features + categories that already exist. Beacon HARD-BLOCKS a feature that duplicates an existing one (it returns the existing feature to use instead) and one created without a category \u2014 so don't re-create work that's already on the board, and reuse an existing category rather than a near-synonym. \`category\` is the ONLY domain field. \`front\` (in \`beacon_start_feature\`) nests a feature UNDER an existing parent feature \u2014 it is NOT a domain tag; a \`front\` that matches no real feature is rejected.
169
+
170
+ When listing features, give each \`dependsOn: ["Other feature title", \u2026]\` for any feature that must ship after another in the same plan. Beacon draws these as "depends on" links so the roadmap shows the dependency chain instead of loose, disconnected cards.
171
+
172
+ ### 2b. Presenting a plan in plan mode (ExitPlanMode)
173
+
174
+ In Codex (which has no ExitPlanMode), always present plans via \`beacon_present_plan\` / \`beacon_propose_plan\` instead \u2014 this section applies to Claude Code's plan mode only.
175
+
176
+ When you present a plan via ExitPlanMode (not \`beacon_propose_plan\`) and it proposes DB tables/relations/endpoints or roadmap features, embed ONE fenced \`\`\`beacon code block of JSON in the plan \u2014 the same shapes \`beacon_propose_plan\` accepts:
177
+
178
+ \`\`\`beacon
179
+ { "tables": [...], "relations": [...], "endpoints": [...], "features": [...] }
180
+ \`\`\`
181
+
182
+ Beacon extracts it deterministically and **strips the block from the prose** (it's never shown in the annotation panel), then renders the tables + features as an **editable board** on /plan so the user can edit them and have those edits flow back as feedback. Omit the block for pure code-change plans.
183
+
184
+ **The board is built ONLY from the block \u2014 prose is NOT parsed.** If your plan describes ANY database models/tables/columns in the prose (e.g. "Model \`legal_precedent.py\` \u2014 natural key (court, \u2026)"), you MUST also put them in the block's \`tables\` array (with \`columns\`), or the /db tab will be empty for that plan. Same for endpoints (\`endpoints\` with \`uses:[{table,access}]\`) and features (\`features\`). A plan that lists five tables in prose but ships a block with only \`features\` renders an empty database board \u2014 exactly the "I described models but the DB tab is empty" failure. Mirror every DB entity you mention into the block.
185
+
186
+ ### 3. At the end, register the work \u2014 in ONE call
187
+
188
+ Call \`beacon_describe_feature\` **ONCE** with a \`features\` array \u2014 one entry per feature the plan created \u2014 each with the files you touched and a short markdown description. This flips each one to **Done** \u2014 including its sub-tasks (the cascade completes every PENDING/IN_PROGRESS child; a sub-task you did NOT finish must be set BLOCKED or CANCELLED before registering, so it survives visibly) \u2014 and keeps \`beacon_context_for_feature\` accurate for the next session.
189
+
190
+ Key each entry by its node \`id\`: the ids are handed back to you when the plan is approved (in the approval message / additionalContext), so you don't fuzzy-match titles or pay a disambiguation round-trip. If you don't have an id, \`title\` still works.
191
+
192
+ Register them all in that single batched call. If a plan added five features, that's ONE \`beacon_describe_feature\` call with five entries \u2014 NOT five calls, and NOT just an umbrella ("Harden auth"), which leaves the individual features stuck on **Pending**.
193
+
194
+ If the feature added or materially changed a REAL architectural component (a subsystem \u2014 NOT a file), also pass \`architecture: [{ title, domain, role, \u2026 }]\` so the Architecture map stays accurate. It upserts curated components by title; never list files as components.
195
+
196
+ Pull raw planning data anytime with \`beacon_entities\` (features / architecture / tables / endpoints).
197
+ ${c}`});import{existsSync as xq,mkdirSync as r,readFileSync as M,rmSync as mq,writeFileSync as F}from"fs";import{dirname as Xq,join as C}from"path";function s(q){try{return JSON.parse(M(q,"utf8"))}catch{return{}}}function wq(q,z){r(Xq(q),{recursive:!0}),F(q,JSON.stringify(z,null,2)+`
198
+ `)}function T(q,z){let J=s(q);J.hooks=J.hooks??{},J.hooks[z.event]=J.hooks[z.event]??[];let Q=J.hooks[z.event];if(Q.some((Y)=>Y.matcher===z.matcher&&Y.hooks?.some((P)=>P.command===z.command)))return!1;return Q.push({matcher:z.matcher,hooks:[{type:"command",command:z.command}]}),wq(q,J),!0}function R(q,z){return(s(q).hooks?.[z.event]??[]).some((V)=>V.hooks?.some((Y)=>Y.command===z.command))}function I(q,z){let J=s(q),Q=J.hooks?.[z.event];if(!Q)return!1;let V=!1,Y=Q.map((P)=>{let W=P.hooks?.length??0,Z=(P.hooks??[]).filter((U)=>U.command!==z.command);if(Z.length!==W)V=!0;return{...P,hooks:Z}}).filter((P)=>(P.hooks??[]).length>0);if(!V)return!1;if(Y.length)J.hooks[z.event]=Y;else delete J.hooks[z.event];if(J.hooks&&Object.keys(J.hooks).length===0)delete J.hooks;return wq(q,J),!0}function E(q,z,J,Q){let V=`${z}
199
+ ${Q.trim()}
200
+ ${J}`,Y="";try{Y=M(q,"utf8")}catch{}let P=new RegExp(`${z}[\\s\\S]*?${J}`);Y=P.test(Y)?Y.replace(P,V):Y.trim()?`${Y.trim()}
201
+
202
+ ${V}
203
+ `:`${V}
204
+ `,r(Xq(q),{recursive:!0}),F(q,Y.endsWith(`
205
+ `)?Y:`${Y}
206
+ `)}function j(q,z){try{return M(q,"utf8").includes(z)}catch{return!1}}function A(q,z,J){let Q="";try{Q=M(q,"utf8")}catch{return!1}let V=new RegExp(`${z}[\\s\\S]*?${J}\\n?`);if(!V.test(Q))return!1;let Y=Q.replace(V,"").replace(/\n{3,}/g,`
207
+
208
+ `).trimStart();return F(q,Y),!0}function y(q,z,J){let Q=C(q,z);r(Q,{recursive:!0});let V=C(Q,"SKILL.md");return F(V,J),V}function B(q,z){return xq(C(q,z,"SKILL.md"))}function O(q,z){let J=C(q,z);if(!xq(J))return!1;return mq(J,{recursive:!0,force:!0}),!0}var l=()=>{};import{mkdirSync as pq,renameSync as Sq,rmSync as aq,writeFileSync as tq}from"fs";import{dirname as cq}from"path";function i(q,z){pq(cq(q),{recursive:!0});let J=`${q}.tmp`;try{tq(J,z),Sq(J,q)}catch(Q){throw aq(J,{force:!0}),Q}}var Hq=()=>{};import{existsSync as dq}from"fs";import{homedir as nq}from"os";import{join as D}from"path";function rq(){return process.env.HOME||process.env.USERPROFILE||nq()}function sq(q,z){return y(o(),q,z)}function Bq(q){return B(o(),q)}function lq(q){return O(o(),q)}function iq(q){return T(e(),q)}function oq(q){return R(e(),q)}function eq(q){return I(e(),q)}function qz(q){E(qq(),zq,jq,q)}function uq(){return j(qq(),zq)}function zz(){return A(qq(),zq,jq)}function bz(){let q={};for(let J of w)q[J]=Bq(J);let z={};for(let J of Jq)z[J.event]=oq({event:J.event,command:J.command});return{homeExists:dq(h()),skills:q,hooks:z,claudeMdBlock:uq()}}async function Jz(){let{INIT_SKILL:q,REFRESH_SKILL:z,PLAN_SKILL:J}=await Promise.resolve().then(() => (n(),d)),Q={"beacon-init":q,"beacon-refresh":z,"beacon-plan":J},V=[];for(let W of w){if(!Bq(W))V.push(W);sq(W,Q[W])}let Y=0;for(let W of Jq)if(iq({event:W.event,matcher:W.matcher,command:W.command}))Y++;let P=uq();return qz(Qq),{skillsAdded:V,hooksAdded:Y,claudeMdBlockTouched:!P}}async function Kz(){let q;try{q={ok:!0,...await Jz()}}catch(z){q={ok:!1,error:z instanceof Error?z.message:String(z),skillsAdded:[],hooksAdded:0,claudeMdBlockTouched:!1}}try{let z=await Promise.resolve().then(() => (gq(),vq));if(z.codexDetected())q.codex={ok:!0,...await z.setupCodexAssets()}}catch(z){q.codex={ok:!1,error:z instanceof Error?z.message:String(z),skillsAdded:[],hooksAdded:0,agentsMdBlockTouched:!1,mcp:{added:!1}}}return q}function fz(){let q=[];for(let Q of w)if(lq(Q))q.push(Q);let z=0;for(let Q of Jq)if(eq(Q))z++;let J=zz();return{skillsRemoved:q,hooksRemoved:z,claudeMdBlockRemoved:J}}var h=()=>D(rq(),".claude"),o=()=>D(h(),"skills"),e=()=>D(h(),"settings.json"),qq=()=>D(h(),"CLAUDE.md"),zq="<!-- beacon:global:start -->",jq="<!-- beacon:global:end -->",w,Jq,Qq=`## Beacon (visual planning panel)
209
+
210
+ This machine has Beacon installed \u2014 a local visual planning surface for the terminal-side
211
+ agent. Beacon proposes feature plans (roadmap features + DB schema + endpoints) via MCP,
212
+ the user reviews on a canvas at /plan, and feedback flows back as the next round.
213
+
214
+ **When to invoke**
215
+ - User asks to "plan a feature" / "design a schema" \u2192 if the \`beacon_propose_plan\`
216
+ MCP tool is available, design the plan and call it. If it is NOT available, the panel
217
+ isn't wired in this repo \u2014 run \`beacon\` here once, then retry.
218
+ - User asks to "set up Beacon" / "map this repo" \u2192 invoke the \`beacon-init\` skill.
219
+ - User asks to "refresh Beacon" / "update the map" / "bring Beacon up to date" \u2192 invoke
220
+ the \`beacon-refresh\` skill. Re-surveys the repo and updates init-derived nodes while
221
+ preserving anything the user added by hand.
222
+ - Run \`beacon doctor\` to audit what's wired (global hooks, repo's .mcp.json, AGENTS.md block).
223
+
224
+ **The plan feedback loop**
225
+ \`beacon_propose_plan\` BLOCKS until the user clicks Approve / Discard / submits feedback.
226
+ Feedback bundles inline annotations on the markdown PLUS any edits the user made directly
227
+ on the /map and /db boards (added features, attached subtasks, edited columns, new
228
+ endpoints). Treat board edits as the user's revision intent \u2014 re-propose matching them
229
+ verbatim. Do NOT implement until the tool returns approval.`;var Nq=g(()=>{l();w=["beacon-init","beacon-refresh","beacon-plan"],Jq=[{event:"PostToolUse",matcher:"Edit|Write|MultiEdit",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"PermissionRequest",matcher:"ExitPlanMode",command:"beacon plan",description:"Pipe the agent's plan markdown into Beacon's /plan canvas for review."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose (instead of presenting it), nudge it to present the plan on Beacon's /plan canvas. Bounded by stop_hook_active \u2014 at most one nudge."}]});var vq={};Pq(vq,{setupCodexAssets:()=>Zz,removeCodexMcp:()=>Fq,removeCodexArtifacts:()=>Pz,hasCodexMcp:()=>$q,ensureCodexMcp:()=>Mq,codexMcpProblem:()=>Yz,codexDetected:()=>Kq,auditCodex:()=>$z,CODEX_HOOKS:()=>p});import{readFileSync as m}from"fs";import{homedir as Qz}from"os";import{join as G}from"path";function Gq(){return process.env.HOME||process.env.USERPROFILE||Qz()}function Kq(){if(process.env.BEACON_CODEX==="1")return!0;if(process.env.BEACON_CODEX==="0")return!1;if(Vq===void 0)Vq=Bun.which("codex")!==null;return Vq}function N(q){try{return Bun.TOML.parse(q)}catch{return null}}function $q(){try{return Boolean(N(m(v(),"utf8"))?.mcp_servers?.beacon)}catch{return!1}}function Yz(){let q="";try{q=m(v(),"utf8")}catch{return null}let z=N(q);if(!z)return`~/.codex/config.toml does not parse \u2014 ${u}`;if(z.mcp_servers?.beacon)return null;if(/^\s*mcp_servers\s*=/m.test(q))return`mcp_servers is an inline table \u2014 ${u}`;return null}function Mq(){let q="",z=!1;try{q=m(v(),"utf8"),z=!0}catch{}if(z){let Y=N(q);if(!Y)return{added:!1,error:`~/.codex/config.toml does not parse \u2014 ${u}`};if(Y.mcp_servers?.beacon)return{added:!1};if(/^\s*mcp_servers\s*=/m.test(q))return{added:!1,error:`mcp_servers is an inline table \u2014 ${u}`}}let J=!q?"":q.endsWith(`
230
+ `)?`
231
+ `:`
232
+
233
+ `,Q=q+J+Vz;if(N(Q)?.mcp_servers?.beacon?.command!=="beacon")return{added:!1,error:`could not safely append [mcp_servers.beacon] \u2014 ${u}`};return i(v(),Q),{added:!0}}function Fq(){let q="";try{q=m(v(),"utf8")}catch{return{removed:!1}}let z=q.split(`
234
+ `),J=z.indexOf(fq);if(J===-1)return{removed:!1,skipped:$q()};let Q=z.indexOf(Cq,J);if(Q===-1)return{removed:!1,skipped:!0};z.splice(J,Q-J+1);let V=z.join(`
235
+ `).replace(/\n{3,}/g,`
236
+
237
+ `).replace(/^\n+/,"");if(N(V)===null)return{removed:!1,skipped:!0};return i(v(),V),{removed:!0}}async function Zz(){let{INIT_SKILL:q,REFRESH_SKILL:z,PLAN_SKILL:J}=await Promise.resolve().then(() => (n(),d)),Q={"beacon-init":q,"beacon-refresh":z,"beacon-plan":J},V=[];for(let Z of w){if(!B(L(),Z))V.push(Z);y(L(),Z,Q[Z])}let Y=0;for(let Z of p)if(T(Zq(),{event:Z.event,matcher:Z.matcher,command:Z.command}))Y++;let P=j(k(),_);E(k(),_,bq,Qq);let W=Mq();return{skillsAdded:V,hooksAdded:Y,agentsMdBlockTouched:!P,mcp:W}}function $z(){let q={};for(let J of w)q[J]=B(L(),J);let z={};for(let J of p)z[J.event]=R(Zq(),{event:J.event,command:J.command});return{detected:Kq(),skills:q,hooks:z,agentsMdBlock:j(k(),_),mcp:$q()}}function Pz(){let q=[];for(let V of w)if(O(L(),V))q.push(V);let z=0;for(let V of p)if(I(Zq(),{event:V.event,command:V.command}))z++;let J=A(k(),_,bq),Q=Fq();return{skillsRemoved:q,hooksRemoved:z,agentsMdBlockRemoved:J,mcpRemoved:Q.removed,mcpSkipped:Q.skipped}}var Yq=()=>G(Gq(),".codex"),Zq=()=>G(Yq(),"hooks.json"),v=()=>G(Yq(),"config.toml"),k=()=>G(Yq(),"AGENTS.md"),L=()=>G(Gq(),".agents","skills"),_="<!-- beacon:global:start -->",bq="<!-- beacon:global:end -->",p,Vq,fq="# beacon:start (managed by Beacon \u2014 `beacon uninstall` removes this block)",Cq="# beacon:end",Vz,u="add it manually: codex mcp add beacon -- beacon mcp";var gq=g(()=>{l();Hq();Nq();p=[{event:"PostToolUse",matcher:"apply_patch",command:"beacon hook",description:"Report file edits to Beacon's active feature so the map stays fresh."},{event:"UserPromptSubmit",matcher:"*",command:"beacon prompt",description:"On feature-y prompts in a Beacon-wired repo, remind the agent to run the context\u2192propose\u2192describe loop (no-op otherwise)."},{event:"Stop",matcher:"*",command:"beacon stop-hook",description:"When the agent ends a turn asking for plan approval in prose, nudge it to present the plan on Beacon's /plan canvas."}];Vz=`${fq}
238
+ [mcp_servers.beacon]
239
+ command = "beacon"
240
+ args = ["mcp"]
241
+ ${Cq}
242
+ `});gq();export{Zz as setupCodexAssets,Fq as removeCodexMcp,Pz as removeCodexArtifacts,$q as hasCodexMcp,Mq as ensureCodexMcp,Yz as codexMcpProblem,Kq as codexDetected,$z as auditCodex,p as CODEX_HOOKS};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trybeacon",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "The visual planning surface for the coding agent in your terminal.",
5
5
  "homepage": "https://trybeacon.sh",
6
6
  "bin": {