#!/usr/bin/env node
import {f as f$1,a,d,e}from'./chunk-WR6D3SC6.js';import {c,d as d$1,e as e$1}from'./chunk-DOCDDDTD.js';import'./chunk-JQKKVAAN.js';import'./chunk-XHJ27CER.js';import*as t from'fs';import*as f from'path';import c$1 from'chalk';async function P(){let r=process.cwd();f$1("\u{1F440} Paradigm Watch"),a("");let e$2=f.join(r,".paradigm");(!t.existsSync(e$2)||!t.statSync(e$2).isDirectory())&&(d("No .paradigm/ directory found."),e("   Run `paradigm init` first.\n"),process.exit(1));let o=c(r).detected||"cursor";e(`Watching for changes...
`),e("  [config] .paradigm/config.yaml"),e("  [specs]  .paradigm/specs/*.md"),e(`  [target] ${o}
`),e(`Press Ctrl+C to stop.
`);let n={lastConfigMtime:0,lastSpecsMtime:0},s=f.join(e$2,"config.yaml"),g=f.join(e$2,"specs");t.existsSync(s)&&(n.lastConfigMtime=t.statSync(s).mtime.getTime()),t.existsSync(g)&&(n.lastSpecsMtime=y(g));let D=setInterval(()=>{let p=false,l="";if(t.existsSync(s)){let i=t.statSync(s).mtime.getTime();i>n.lastConfigMtime&&(n.lastConfigMtime=i,p=true,l="config");}if(t.existsSync(g)){let i=y(g);i>n.lastSpecsMtime&&(n.lastSpecsMtime=i,p=true,l=l?"config+specs":"specs");}if(p){let i=new Date().toLocaleTimeString("en-US",{hour12:false});a(c$1.cyan(`${i}`)+c$1.gray(` [${l}]`)+" Changed \u2192 syncing...");let u=d$1(r);if(u){let d=e$1(r,o,u,true);d.success?a(c$1.green(`${i}`)+c$1.gray(" [sync]")+` ${d.outputPath} updated`):a(c$1.red(`${i}`)+c$1.gray(" [sync]")+` Failed: ${d.message}`);}else a(c$1.red(`${i}`)+c$1.gray(" [error]")+" Failed to load .paradigm/ files");}},1e3);process.on("SIGINT",()=>{clearInterval(D),e(`

Stopped watching.
`),process.exit(0);}),await new Promise(()=>{});}function y(r){let e=0;try{let h=t.readdirSync(r,{withFileTypes:!0});for(let o of h){let n=f.join(r,o.name);if(o.isFile()){let s=t.statSync(n).mtime.getTime();s>e&&(e=s);}else if(o.isDirectory()){let s=y(n);s>e&&(e=s);}}}catch{}return e}export{P as watchCommand};