citadel_cli 1.4.0 → 1.4.1

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.
@@ -0,0 +1,479 @@
1
+ (function(g,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom/client"],c):(g=typeof globalThis<"u"?globalThis:g||self,c(g.Citadel={},g.jsxRuntime,g.React,g.client))})(this,function(g,c,a,Me){"use strict";var ut=Object.defineProperty;var pt=(g,c,a)=>c in g?ut(g,c,{enumerable:!0,configurable:!0,writable:!0,value:a}):g[c]=a;var C=(g,c,a)=>pt(g,typeof c!="symbol"?c+"":c,a);var j=(t=>(t.Pending="pending",t.Success="success",t.Failure="failure",t.Timeout="timeout",t))(j||{});class _{constructor(e=Date.now()){C(this,"_status","pending");this.timestamp=e}get status(){return this._status}markSuccess(){this._status="success"}markFailure(){this._status="failure"}markTimeout(){this._status="timeout"}}class oe extends _{constructor(e,n){super(n),this.data=e}render(){return c.jsx("pre",{className:"citadel-result-json",children:JSON.stringify(this.data,null,2)})}}class q extends _{constructor(e,n){super(n),this.text=e}render(){return c.jsx("div",{className:"citadel-result-text",children:this.text})}}class ie extends _{constructor(e,n="true",s="false",r){super(r),this.value=e,this.trueText=n,this.falseText=s}render(){return c.jsx("div",{className:"citadel-result-text citadel-result-boolean",children:this.value?this.trueText:this.falseText})}}class Z extends _{constructor(e,n){super(n),this.error=e,this.markFailure()}render(){return c.jsx("div",{className:"citadel-result-error",children:this.error})}}class le extends _{render(){return c.jsx("div",{className:"citadel-result-pending",children:"..."})}}class ce extends _{constructor(e,n="",s){super(s),this.imageUrl=e,this.altText=n}render(){return c.jsx("div",{className:"citadel-result-image-wrap",children:c.jsx("img",{src:this.imageUrl,alt:this.altText,className:"citadel-result-image"})})}}const Pe=t=>async function(){const n=t.commands.filter(s=>s.fullPath[0]!=="help").map(s=>{const i=`${s.segments.map(d=>d.type==="argument"?`<${d.name}>`:d.name).join(" ")} - ${s.description}`,o=s.segments.filter(d=>d.type==="argument"&&d.description).map(d=>` <${d.name}>: ${d.description}`);return{commandLine:i,argumentLines:o}}).sort((s,r)=>s.commandLine.localeCompare(r.commandLine)).flatMap(s=>[s.commandLine,...s.argumentLines]);return n.length===0?new q("No commands available yet. Add some commands to get started!"):(n.push("help - Show available commands"),new q(`Available Commands:
2
+ `+n.join(`
3
+ `)))};var R=(t=>(t[t.NONE=0]="NONE",t[t.ERROR=1]="ERROR",t[t.WARN=2]="WARN",t[t.INFO=3]="INFO",t[t.DEBUG=4]="DEBUG",t[t.TRACE=5]="TRACE",t))(R||{});const de=!0;class x{static configure(e){this.level=e.level,this.prefix=e.prefix||"[Citadel]"}static trace(...e){this.level>=5&&!de&&console.trace(this.prefix,...e)}static debug(...e){this.level>=4&&!de&&console.debug(this.prefix,...e)}static info(...e){this.level>=3&&console.info(this.prefix,...e)}static warn(...e){this.level>=2&&console.warn(this.prefix,...e)}static error(...e){this.level>=1&&console.error(this.prefix,...e)}}C(x,"level",0),C(x,"prefix","");const k={commandTimeoutMs:1e4,cursorColor:"var(--cursor-color, #fff)",cursorSpeed:530,cursorType:"blink",includeHelpCommand:!0,fontFamily:"monospace",fontSize:"0.875rem",initialHeight:"50vh",logLevel:R.ERROR,maxHeight:"80vh",minHeight:"200",outputFontSize:"0.875rem",resetStateOnHide:!1,closeOnEscape:!0,showCitadelKey:".",showOnLoad:!1,displayMode:"panel",storage:{type:"localStorage",maxCommands:100}},me=async()=>new q("");class ee{constructor(e,n,s){this.type=e,this.name=n,this.description=s}toString(){return this.name}}class te extends ee{constructor(){super("null",">null<","Empty segment")}}class ue extends ee{constructor(e,n){super("word",e,n)}}class U extends ee{constructor(e,n,s,r){super("argument",e,n),this.value=s,this.valid=r}}const He=t=>{if(t.type==="word")return new ue(t.name,t.description);if(t.type==="argument"){const e=t;return new U(e.name,e.description,e.value,e.valid)}return new te},H=t=>t.map(e=>He(e));class _e{constructor(e,n,s=me){C(this,"_segments");C(this,"_description");C(this,"_handler");this._segments=e,this._description=n,this._handler=s}get segments(){return this._segments}get description(){return this._description}get handler(){return this._handler}get hasArguments(){return this.segments.some(e=>e.type==="argument")}get fullPath(){return this.segments.map(e=>e.name)}get fullPath_s(){return this.fullPath.join(" ")}equals(e){return this.fullPath.join(" ")===e.fullPath.join(" ")}}class K{constructor(){C(this,"_commands",[])}get commands(){return this._commands}addCommand(e,n,s=me){if(e===void 0||e.length===0)throw new Error("Command path cannot be empty");const r=new _e(e,n,s),i=this._commands.find(o=>{const d=o.segments.map(u=>u.type==="argument"?"*":u.name).join(" "),l=e.map(u=>u.type==="argument"?"*":u.name).join(" ");return d===l});if(i)throw new Error(`Duplicate commands: '${i.fullPath_s}' and '${r.fullPath_s}'`);this._commands.push(r)}removeCommand(e){const n=e.join(" "),s=this._commands.findIndex(r=>r.fullPath.join(" ")===n);return s===-1?!1:(this._commands.splice(s,1),!0)}getCommand(e){return this._commands.find(n=>{const s=n.fullPath.join(" "),r=e.join(" ");if(s===r)return!0;const o=n.segments.filter(d=>d.type==="word").map(d=>d.name);return o.length===e.length&&o.join(" ")===r})}commandExistsForPath(e){const n=this._commands.map(r=>r.segments.map(i=>i.type==="argument"?"*":i.name).join(" ")),s=e.map((r,i)=>this._commands.some(d=>{var l;return((l=d.segments[i])==null?void 0:l.type)==="argument"})?"*":r).join(" ");return n.includes(s)}getCompletionNames(e){return this.getCompletions(e).map(n=>n.name)}getMatchingCompletions(e,n){const s=n.trim().toLowerCase(),r=this.getCompletions(e);return s?r.filter(i=>i.name.toLowerCase().startsWith(s)):r}getUniqueCompletion(e,n){const s=this.getMatchingCompletions(e,n);if(s.length===1)return s[0]}getCompletions(e){if(x.debug("[getCompletions] path: ",e),!e.length){const i=this._commands.map(l=>l.segments[0]),o=(l,u)=>l.type===u.type&&l.name===u.name;return i.filter((l,u,y)=>u===y.findIndex(p=>o(p,l)))}const n=e.length;return this._commands.filter(i=>{const o=i.segments;if(o.length<=n-1)return!1;for(let d=0;d<n;d++){const l=e[d],u=o[d];if(!(l==="*"&&u.type==="argument")&&l!==u.name)return!1}return!0}).filter(i=>i.segments.length>n).map(i=>{const o=i.segments[n],d=o.type==="argument"?U:ue;return new d(o.name,o.description)}).filter((i,o,d)=>o===d.findIndex(l=>l.type===i.type&&l.name===i.name))}hasNextSegment(e){return this.getCompletions(e).length>0}}class pe{constructor(e){C(this,"config");this.config={type:"localStorage",maxCommands:100,...e}}async addStoredCommand(e){const n=await this.getStoredCommands();for(n.push(e);n.length>this.config.maxCommands;)n.shift();await this.saveCommands(n)}}class Te extends pe{constructor(n){super(n);C(this,"storageKey","citadel_command_history")}async getStoredCommands(){try{const n=window.localStorage.getItem(this.storageKey);return n?JSON.parse(n).map(r=>({commandSegments:Array.isArray(r.commandSegments)?H(r.commandSegments):[],timestamp:r.timestamp})):[]}catch(n){return console.warn("Failed to load commands from localStorage:",n),[]}}async clear(){try{window.localStorage.removeItem(this.storageKey)}catch(n){console.warn("Failed to clear localStorage:",n)}}async saveCommands(n){try{const s=n.map(r=>({commandSegments:Array.isArray(r.commandSegments)?H(r.commandSegments).map(i=>({type:i.type,name:i.name,description:i.description,...i instanceof U?{value:i.value}:{}})):[],timestamp:r.timestamp}));window.localStorage.setItem(this.storageKey,JSON.stringify(s))}catch(s){throw console.warn("Failed to save commands to localStorage:",s),s}}}class he extends pe{constructor(n){super(n);C(this,"storedCommands",[])}async getStoredCommands(){return this.storedCommands.map(n=>({commandSegments:Array.isArray(n.commandSegments)?H(n.commandSegments):[],timestamp:n.timestamp}))}async clear(){this.storedCommands=[]}async saveCommands(n){this.storedCommands=n.map(s=>({commandSegments:Array.isArray(s.commandSegments)?H(s.commandSegments):[],timestamp:s.timestamp}))}}const z=class z{constructor(){C(this,"currentStorage")}static reset(){z.instance=void 0}static getInstance(){return z.instance||(z.instance=new z),z.instance}initializeStorage(e){try{e.type==="memory"?this.currentStorage=new he(e):this.currentStorage=new Te(e)}catch(n){console.warn("Failed to create storage, falling back to memory storage:",n),this.currentStorage=new he(e)}}getStorage(){if(!this.currentStorage)throw new Error("Storage not initialized. Call initializeStorage first.");return this.currentStorage}};C(z,"instance");let Y=z;class ge{constructor(){C(this,"segments",[]);C(this,"nullSegment",new te);C(this,"observers",[])}subscribe(e){this.observers.push(e)}unsubscribe(e){this.observers=this.observers.filter(n=>n!==e)}notifyObservers(){this.observers.forEach(e=>e.update())}clear(){this.segments=[],this.notifyObservers()}push(e){this.segments.push(e),this.notifyObservers()}pushAll(e){e.forEach(n=>this.push(n))}pop(){const e=this.segments.pop()||this.nullSegment;return this.notifyObservers(),e}peek(){return this.segments[this.segments.length-1]||this.nullSegment}size(){return this.segments.length}isEmpty(){return this.segments.length===0}get hasArguments(){return this.segments.some(e=>e.type==="argument")}get arguments(){return this.segments.filter(e=>e.type==="argument")}path(){return this.segments.map(e=>e.name)}toArray(){return[...this.segments]}}const ze={config:k,commands:new K,segmentStack:new ge},W=a.createContext(ze),De=({config:t=k,commandRegistry:e,children:n})=>{const[s,r]=a.useState(),[i]=a.useState(()=>new ge),o=a.useMemo(()=>({...k,...t,storage:{...k.storage,...t.storage},cursorType:t.cursorType??k.cursorType,cursorColor:t.cursorColor??k.cursorColor,cursorSpeed:t.cursorSpeed??k.cursorSpeed,closeOnEscape:t.closeOnEscape??k.closeOnEscape,showCitadelKey:t.showCitadelKey??k.showCitadelKey,showOnLoad:t.showOnLoad??k.showOnLoad}),[t]);a.useEffect(()=>{Y.getInstance().initializeStorage(o.storage??k.storage),r(Y.getInstance().getStorage())},[o.storage]),a.useEffect(()=>{if(e){if(o.includeHelpCommand){if(!e.commandExistsForPath(["help"])){const l=Pe(e);e.addCommand([{type:"word",name:"help"}],"Show available commands",l)}return}e.removeCommand(["help"])}},[e,o.includeHelpCommand]);const d=a.useMemo(()=>({config:o,commands:e||new K,storage:s,segmentStack:i}),[o,e,s,i]);return c.jsx(W.Provider,{value:d,children:n})},T=()=>{const t=a.useContext(W);if(t===void 0)throw new Error("useCitadelConfig must be used within a CitadelConfigProvider");return t.config},J=()=>{const t=a.useContext(W);if(t===void 0)throw new Error("useCitadelCommands must be used within a CitadelConfigProvider");return t.commands},fe=()=>{const t=a.useContext(W);if(t===void 0)throw new Error("useCitadelStorage must be used within a CitadelConfigProvider");return t.storage},B=()=>{const t=a.useContext(W);if(t===void 0)throw new Error("useSegmentStack must be used within a CitadelConfigProvider");return t.segmentStack},X=class X{constructor(e,n){C(this,"id");C(this,"timestamp");C(this,"command");C(this,"result");this.id=`output-${Date.now()}-${X.idCounter++}`,this.command=e.toArray().map(s=>s.type==="argument"?s.value||"":s.name),this.timestamp=Date.now(),this.result=n??new le}};C(X,"idCounter",0);let G=X;function Oe(t){return{commandSegments:H(t),timestamp:Date.now()}}function ye(){const t=fe(),[e,n]=a.useState({storedCommands:[],position:null}),s=a.useCallback(async d=>{if(t)try{const l=Oe(d);await t.addStoredCommand(l),n(u=>({...u,storedCommands:[...u.storedCommands,{...l,commandSegments:H(l.commandSegments)}],position:null}))}catch(l){console.warn("Failed to save command to history:",l)}},[t]),r=a.useCallback(async()=>t?(await t.getStoredCommands()).map(l=>({...l,commandSegments:H(l.commandSegments)})):[],[t]);a.useEffect(()=>{if(!t)return;(async()=>{try{const u=(await t.getStoredCommands()).map(y=>({...y,commandSegments:H(y.commandSegments)}));return n(y=>({...y,storedCommands:u})),u}catch(l){console.warn("Failed to load command history:",l)}})()},[t]);const i=a.useCallback(async d=>{const l=await r();if(l.length===0)return n(p=>({...p,storedCommands:[],position:null})),{segments:null,position:null};let u=null;if(d==="up"?e.position===null?u=l.length-1:e.position>0?u=e.position-1:u=0:e.position===null||e.position>=l.length-1?u=null:u=e.position+1,n(p=>({...p,storedCommands:l.map(f=>({...f,commandSegments:H(f.commandSegments)})),position:u})),u===null)return{segments:[],position:null};const y=l[u];return y?{segments:H(y.commandSegments),position:u}:{segments:[],position:null}},[e.position,r]),o=a.useCallback(async()=>{try{if(!t)return;await t.clear(),n({storedCommands:[],position:null})}catch(d){console.warn("Failed to clear command history:",d)}},[t]);return{history:e,addStoredCommand:s,getStoredCommands:r,navigateHistory:i,clear:o}}const ne=()=>{const t=T(),e=J(),n=ye(),s=B(),r=fe(),[i,o]=a.useState({currentInput:"",isEnteringArg:!1,output:[],history:{commands:[],position:null,storage:r}});a.useEffect(()=>{},[r]),a.useEffect(()=>{o(l=>({...l,history:{commands:n.history.storedCommands,position:n.history.position,storage:r}}))},[n.history,r]);const d={setCurrentInput:a.useCallback(l=>{x.debug("[CitadelActions] setCurrentInput: ",l),o(u=>({...u,currentInput:l}))},[]),setIsEnteringArg:a.useCallback(l=>{x.debug("[CitadelActions] setIsEnteringArg: ",l),o(u=>({...u,isEnteringArg:l}))},[]),addOutput:a.useCallback(l=>{x.debug("[CitadelActions]addOutput: ",l),o(u=>({...u,output:[...u.output,l]}))},[]),executeCommand:a.useCallback(async()=>{const l=s.path(),u=e.getCommand(l);if(!u){console.error("[CitadelActions][executeCommand] Cannot execute command because no command was found for the given path: ",l);return}const y=new G(s);o(p=>({...p,output:[...p.output,y]}));try{const p=new Promise((v,E)=>{setTimeout(()=>{E(new Error("Request timed out"))},t.commandTimeoutMs)}),f=s.arguments.map(v=>v.value||""),b=await Promise.race([u.handler(f),p]);if(!(b instanceof _))throw new Error(`The ${l.join(".")} command returned an invalid result type. Commands must return an instance of a CommandResult.
4
+ For example:
5
+ return new JsonCommandResult({ text: "Hello World" });
6
+ Check the definition of the ${l.join(".")} command and update the return type for its handler.`);b.markSuccess(),o(v=>({...v,output:v.output.map(E=>E.id===y.id?{...E,result:b}:E)}))}catch(p){const f=new Z(p instanceof Error?p.message:"Unknown error");f.markFailure(),o(b=>({...b,output:b.output.map(v=>v.id===y.id?{...v,result:f}:v)}))}},[e,t.commandTimeoutMs,s]),clearHistory:a.useCallback(async()=>{try{await n.clear()}catch(l){console.warn("Failed to clear history:",l)}},[n])};return{state:i,actions:d}},Fe=({onOpen:t,onClose:e,isVisible:n,showCitadelKey:s,closeOnEscape:r})=>{a.useEffect(()=>{const i=o=>{var d,l;!n&&o.key===s&&!["input","textarea"].includes(((l=(d=o.target)==null?void 0:d.tagName)==null?void 0:l.toLowerCase())||"")&&(o.preventDefault(),t()),r&&n&&o.key==="Escape"&&(o.preventDefault(),e())};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[t,e,n,s,r])},Le=200,je=t=>{const{isVisible:e,isClosing:n,onAnimationComplete:s}=t,r=a.useMemo(()=>e?n?"citadel_slideDown":"citadel_slideUp":"",[e,n]);return a.useEffect(()=>{if(!n||!s)return;if(window.matchMedia("(prefers-reduced-motion: reduce)").matches){s();return}const o=setTimeout(()=>{s()},Le);return()=>clearTimeout(o)},[n,s]),{animationClass:r}},Ue=()=>c.jsx("div",{"data-testid":"spinner",className:"citadel-spinner"}),Ce=t=>{const e=t==null?void 0:t.trim();return e||void 0},$e=t=>{const e=Ce(t);return e?{style:{fontSize:e}}:{}},Q=(t,e)=>{const n=Ce(t),r={...$e(e).style};return n&&(r.fontFamily=n),{style:Object.keys(r).length>0?r:void 0}},qe=({command:t,timestamp:e,status:n,fontFamily:s,fontSize:r})=>{const i=a.useMemo(()=>Q(s,r??"0.875rem"),[s,r]);return c.jsxs("div",{className:"citadel-output-line",style:i.style,children:[c.jsxs("span",{className:"citadel-output-command",children:["> ",t.split(" ").map((o,d)=>{const l=o.startsWith("<")&&o.endsWith(">");return c.jsxs("span",{className:l?"citadel-output-command-arg":"citadel-output-command-word",children:[d>0?" ":"",o]},d)})]}),c.jsx("span",{className:"citadel-output-separator",children:"·"}),c.jsx("span",{className:"citadel-output-timestamp",children:e}),n===j.Pending&&c.jsx(Ue,{}),n===j.Success&&c.jsx("div",{"data-testid":"success-indicator",className:"citadel-status-dot citadel-status-dot-success"}),(n===j.Timeout||n===j.Failure)&&c.jsx("div",{"data-testid":"success-indicator",className:"citadel-status-dot citadel-status-dot-failure"})]})},Ke=({output:t,outputRef:e})=>{const n=T(),s=a.useMemo(()=>Q(n.fontFamily,n.outputFontSize??n.fontSize),[n.fontFamily,n.fontSize,n.outputFontSize]),r=a.useCallback(()=>{if(e.current){const i=e.current;requestAnimationFrame(()=>{i.scrollTop=i.scrollHeight})}},[e]);return a.useEffect(()=>{if(r(),e.current){const i=e.current.getElementsByTagName("img"),o=i[i.length-1];if(o&&!o.complete)return o.addEventListener("load",r),()=>o.removeEventListener("load",r)}},[t,r,e]),c.jsx("div",{ref:e,className:"citadel-output","data-testid":"citadel-command-output",children:t.map(i=>c.jsxs("div",{className:"citadel-output-item",children:[c.jsx(qe,{command:i.command.join(" "),timestamp:new Date(i.timestamp).toLocaleTimeString(),status:i.result.status,fontFamily:n.fontFamily,fontSize:n.fontSize}),c.jsx("div",{className:"citadel-output-content",style:s.style,children:i.result.render()})]},i.id))})},we={blink:{character:"▋",speed:530,color:"#fff"},spin:{character:"⠋",speed:120,color:"#fff"},solid:{character:"▋",speed:0,color:"#fff"},bbs:{character:"|",speed:120,color:"#fff"}},ve=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],Se=["|","/","-","\\"],We=({style:t={type:"blink"},isValid:e=!0,errorMessage:n})=>{const s=a.useMemo(()=>({...we[t.type],...t}),[t]),[r,i]=a.useState(!0),[o,d]=a.useState(0);a.useEffect(()=>{if(s.speed===0)return;const y=setInterval(()=>{s.type==="blink"?i(p=>!p):["spin","bbs"].includes(s.type)&&d(p=>(p+1)%(s.type==="bbs"?Se.length:ve.length))},s.speed);return()=>clearInterval(y)},[s.type,s.speed]);const l=a.useMemo(()=>({color:e?s.color:"#ff4444",transition:"color 0.15s ease-in-out"}),[e,s.color]),u=()=>!e&&n?"✗":["spin","bbs"].includes(s.type)?(s.type==="bbs"?Se:ve)[o]:s.type==="solid"||r?s.character:" ";return c.jsx("div",{className:"citadel-cursor-wrapper",children:c.jsx("span",{className:`command-cursor ${e?"":"animate-shake"}`,style:l,title:n,children:u()})})};function Be(t,e){switch(e.type){case"set":return x.debug(`[inputStateReducer] InputState changing from ${t} to ${e.state}`),e.state;default:return t}}const Ve=()=>{const{state:t}=ne(),e=J(),n=ye(),s=B(),[r,i]=a.useReducer(Be,"idle"),o=m=>{i({type:"set",state:m})},d=a.useCallback(()=>{const h=e.getCompletions(s.path())[0]||s.nullSegment;return x.debug("[getNextExpectedSegment] ",h),h},[e,s]),l=a.useCallback(()=>e.getCompletionNames(s.path()).map(h=>e.getCommand([...s.path(),h])).filter(h=>h!==void 0),[e,s]),u=a.useCallback((m,h)=>{if(!m)return h;const w=s.path().length;return h.filter(D=>{const S=D.segments[w];return!S||S.type!=="word"?!1:S.name.toLowerCase().startsWith(m.toLowerCase())})},[s]),y=a.useCallback(m=>{const h=e.getUniqueCompletion(s.path(),m);return h&&h.type==="word"?h:s.nullSegment},[e,s]),p=a.useCallback(m=>{const h=s.path(),w=e.getCompletions(h);return w.length===0&&m?!1:w.some(S=>S.type==="argument")?!0:e.getMatchingCompletions(h,m).some(S=>S.type==="word")},[e,s]),f=a.useCallback(m=>{x.debug("[tryAutoComplete] input: ",m);const h=y(m);return!h||h.type==="null"?new te:(x.debug("[tryAutoComplete] result: ",h),h)},[y]),b=a.useCallback((m,h)=>{if(t.history.position!==null)return;h.setCurrentInput(m),x.debug("[useCommandParser][handleInputChange] newValue: ",m);const w=d();if(w.type==="argument"||r==="entering_argument"){const A=be(m);if(A.isQuoted)if(A.isComplete){if(!(w instanceof U))return;w.value=m.trim()||"",x.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",w),s.push(w),h.setCurrentInput(""),o("idle");return}else return;else if(A.isComplete){if(!(w instanceof U))return;w.value=m.trim()||"",x.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",w),s.push(w),h.setCurrentInput(""),o("idle");return}else return}if(m.endsWith(" ")){const A=m.trim().toLowerCase(),P=e.getCompletions(s.path()).filter(N=>N.type==="word"&&N.name.toLowerCase()===A);if(P.length===1){s.push(P[0]),h.setCurrentInput(""),o("idle");return}}const S=f(m);if(S.type==="word"){x.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",S),s.push(S),h.setCurrentInput(""),o("idle");return}},[f,t,d,r,s,e]),v=a.useCallback(m=>{m.setCurrentInput(""),m.setIsEnteringArg(!1),s.clear(),o("idle")},[s]),E=a.useCallback((m,h,w)=>{if(!(m.key==="Backspace"||m.key==="Enter"||m.key==="ArrowUp"||m.key==="ArrowDown"||m.key==="ArrowLeft"||m.key==="ArrowRight"||m.key==="Escape"||m.key==="Delete"||m.key==="Home"||m.key==="End"||m.key.length===1))return!0;const{currentInput:S,isEnteringArg:A}=h,P=be(S);switch(m.key){case"Backspace":return S===""&&(m.preventDefault(),s.size()>0&&s.pop(),o("idle")),!0;case"Enter":{if(m.preventDefault(),P.isQuoted&&!P.isComplete)return!0;if(r==="entering_argument"||A&&S.trim()){const F=d();F instanceof U&&(F.value=S,x.debug("[handleKeyDown][Enter]['entering_argument'] pushing: ",F),s.push(F))}const N=s.path(),V=e.getCommand(N);if(!V)return!1;const O=V.segments.filter(F=>F.type==="argument"),$=s.arguments;return O.length>$.length?!1:(x.debug("[handleKeyDown][Enter] calling actions.executeCommand. segmentStack: ",s),w.executeCommand(),n.addStoredCommand(s.toArray()),v(w),!0)}case"ArrowUp":return m.preventDefault(),(async()=>{const N=await n.navigateHistory("up");return N.segments&&(s.clear(),s.pushAll(N.segments),w.setCurrentInput("")),!0})();case"ArrowDown":return m.preventDefault(),(async()=>{const N=await n.navigateHistory("down");return N.segments&&(s.clear(),s.pushAll(N.segments),w.setCurrentInput("")),!0})();default:{if(!A&&m.key.length===1){const N=S+m.key;if(!p(N))return m.preventDefault(),!1}return!0}}},[r,p,d,n,v,e,s]);return{handleInputChange:b,handleKeyDown:E,inputState:r,setInputStateWithLogging:o,findMatchingCommands:u,getAutocompleteSuggestion:y,getAvailableNodes:l,getNextExpectedSegment:d,isValidCommandInput:p}};function be(t){const e=[];let n="",s=!1,r;for(let i=0;i<t.length;i++){const o=t[i];(o==='"'||o==="'")&&(!s||o===r)?s?(e.push(n),n="",s=!1,r=void 0):(n&&(e.push(n),n=""),s=!0,r=o):!s&&o===" "?n&&(e.push(n),n=""):n+=o}return{words:e,currentWord:n,isQuoted:s,quoteChar:r,isComplete:!s&&!n}}const Ye=()=>{const t=B(),[e,n]=a.useState(0);return a.useEffect(()=>{const s={update:()=>{n(r=>r+1)}};return t.subscribe(s),()=>{t.unsubscribe(s)}},[t]),e},Je=({state:t,actions:e})=>{const n=a.useRef(null),s=J(),r=B(),{handleKeyDown:i,handleInputChange:o,inputState:d,setInputStateWithLogging:l,getNextExpectedSegment:u}=Ve(),[y,p]=a.useState(!1),f=T(),b=Ye(),v=a.useRef(null),[E,m]=a.useState(0),h=a.useMemo(()=>Q(f.fontFamily,f.fontSize),[f.fontFamily,f.fontSize]),w=a.useCallback(async I=>{const M=i(I,t,e);await Promise.resolve(M)===!1&&(p(!0),setTimeout(()=>p(!1),500))},[e,i,t]),D=a.useCallback(I=>{o(I.target.value,e)},[e,o]),S=a.useCallback(I=>{I.preventDefault();const M=I.clipboardData.getData("text");o(M,e)},[e,o]);a.useEffect(()=>{n.current&&n.current.focus(),d!=="entering_command"&&l("entering_command")},[d,l]),a.useEffect(()=>{if(d!=="idle")return;const I=u();let M="idle";switch(I.type){case"word":M="entering_command",e.setIsEnteringArg(!1);break;case"argument":M="entering_argument",e.setIsEnteringArg(!0);break}l(M)},[b,d,u,l,e]);const A=a.useMemo(()=>{const I=[],M=r.toArray().map((L,re)=>{I.push(L.name);const Ae=s.hasNextSegment(I);if(L.type==="argument"){const ae=L;return c.jsxs(a.Fragment,{children:[c.jsx("span",{className:"citadel-input-segment-arg",children:ae.value}),re<r.size()&&Ae&&c.jsx("span",{className:"citadel-input-segment-space",children:" "})]},"arg-"+ae.name+ae.value)}return c.jsxs(a.Fragment,{children:[c.jsx("span",{className:"citadel-input-segment-word",children:L.name}),re<r.size()&&Ae&&c.jsx("span",{className:"citadel-input-segment-space citadel-input-segment-space-command",children:" "})]},"word-"+L.name)});return[c.jsx("div",{className:"citadel-input-segments","data-testid":"user-input-area",children:M},b)]},[b,s,r]),[P,N]=a.useState("");a.useEffect(()=>{const I=u();I.type==="argument"?N(I.name):N("")},[b,u]);const O=!t.isEnteringArg?"is-command-mode":"is-argument-mode",$=a.useMemo(()=>({left:`${E}px`,transition:"left 0.05s ease-out"}),[E]),F=a.useMemo(()=>({type:f.cursorType??k.cursorType,color:f.cursorColor||k.cursorColor,speed:f.cursorSpeed||k.cursorSpeed}),[f.cursorColor,f.cursorSpeed,f.cursorType]);return a.useLayoutEffect(()=>{const I=v.current,M=n.current;if(!I||!M){m(0);return}const L=I.getBoundingClientRect().width;m(Math.max(0,L-M.scrollLeft))},[t.currentInput,O,h.style]),c.jsx("div",{className:"citadel-input-shell",children:c.jsxs("div",{className:"citadel-input-line",style:h.style,children:[c.jsx("div",{className:"citadel-input-prompt",children:">"}),c.jsxs("div",{className:"citadel-input-row",children:[A,c.jsxs("div",{className:"citadel-input-control",children:[c.jsx("span",{ref:v,className:`citadel-input-measure ${O}`.trim(),"aria-hidden":"true",children:t.currentInput}),c.jsx("input",{ref:n,type:"text",role:"textbox",value:t.currentInput,onChange:D,onKeyDown:w,onPaste:S,"data-testid":"citadel-command-input",className:`citadel-input-field ${O} ${y?"invalid-input-animation":""}`.trim(),spellCheck:!1,autoComplete:"off",placeholder:P}),c.jsx("div",{className:"citadel-input-cursor",style:$,children:c.jsx(We,{style:F})})]})]})]})})},Ge=({currentInput:t=""})=>{const e=J(),n=T(),s=B(),r=a.useMemo(()=>Q(n.fontFamily,n.fontSize),[n.fontFamily,n.fontSize]),i=t.trim().toLowerCase(),o=e.getMatchingCompletions(s.path(),i);x.debug("[AvailableCommands] nextCommandSegments: ",o);const d=a.useMemo(()=>{const p=[...o],f=m=>m.name.toLowerCase()==="help",b=p.filter(f);return[...p.filter(m=>!f(m)).sort((m,h)=>m.name.localeCompare(h.name,void 0,{sensitivity:"base"})),...b]},[o]),l=a.useMemo(()=>{const p=new Map;for(const f of d){const b=d.reduce((v,E)=>{if(E===f)return v;let m=0;for(;m<f.name.length&&m<E.name.length&&f.name[m].toLowerCase()===E.name[m].toLowerCase();)m++;return Math.max(v,m+1)},1);p.set(f.name,b)}return p},[d]),u=o.some(p=>p.type==="argument"),y=o[0];return c.jsx("div",{className:"citadel-available-commands","data-testid":"available-commands",children:c.jsx("div",{className:"citadel-available-commands-content",style:r.style,children:u?o.length>0?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"citadel-available-next-arg",children:y.name}),y.description&&c.jsxs("span",{className:"citadel-available-next-desc",children:["- ",y.description]})]}):null:c.jsx("div",{className:"citadel-available-chip-list",children:d==null?void 0:d.map(p=>{const f=l.get(p.name)??1;return c.jsx("div",{"data-testid":"available-command-chip",className:"citadel-available-chip",children:c.jsxs("span",{className:"citadel-available-chip-text",children:[c.jsx("strong",{className:"citadel-available-chip-prefix",children:p.name.slice(0,f)}),p.name.slice(f)]})},p.name)})})})})},xe=({state:t,actions:e,outputRef:n})=>{const r=T().displayMode==="inline",i=a.useMemo(()=>r?{overflow:"hidden"}:void 0,[r]);return c.jsxs("div",{className:"innerContainer citadel-tty",children:[c.jsx("div",{className:"citadel-tty-output-pane","data-testid":"citadel-output-pane",style:i,children:c.jsx(Ke,{output:t.output,outputRef:n})}),c.jsxs("div",{className:"citadel-tty-input-region",children:[c.jsx(Je,{state:t,actions:e}),c.jsx(Ge,{currentInput:t.isEnteringArg?"":t.currentInput})]})]})},Qe=()=>{const t=T(),[e,n]=a.useState(()=>t.showOnLoad??!1),[s,r]=a.useState(!1),[i,o]=a.useState(()=>t.initialHeight||null),d=a.useRef(null),l=a.useRef(null),u=a.useRef(!1),y=a.useRef(0),p=a.useRef(0),{state:f,actions:b}=ne(),v=a.useCallback(()=>{r(!1),n(!0)},[]),E=a.useCallback(()=>{r(!0)},[]);Fe({onOpen:v,onClose:E,isVisible:e&&!s,showCitadelKey:t.showCitadelKey||".",closeOnEscape:t.closeOnEscape??!0});const m=a.useCallback(P=>{var $;if(!u.current)return;const N=P.clientY-y.current,V=($=t.maxHeight)!=null&&$.endsWith("vh")?window.innerHeight*parseInt(t.maxHeight,10)/100:parseInt(t.maxHeight||"80vh",10),O=Math.min(Math.max(p.current-N,parseInt(t.minHeight||"200",10)),V);l.current&&(l.current.style.height=`${O}px`,l.current.style.bottom="0",o(`${O}px`))},[t.maxHeight,t.minHeight]),h=a.useCallback(()=>{u.current=!1,document.documentElement.style.userSelect="",document.documentElement.style.webkitUserSelect="",document.documentElement.style.mozUserSelect="",document.documentElement.style.msUserSelect="",document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",h)},[m]),w=a.useCallback(P=>{l.current&&(u.current=!0,y.current=P.clientY,p.current=l.current.offsetHeight,document.documentElement.style.userSelect="none",document.documentElement.style.webkitUserSelect="none",document.documentElement.style.mozUserSelect="none",document.documentElement.style.msUserSelect="none",document.addEventListener("mousemove",m),document.addEventListener("mouseup",h))},[m,h]);a.useEffect(()=>()=>{document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",h)},[m,h]);const D=a.useCallback(()=>{s&&(n(!1),r(!1))},[s]),{animationClass:S}=je({isVisible:e,isClosing:s,onAnimationComplete:D}),A=a.useMemo(()=>({...i?{height:i}:{},maxHeight:t.maxHeight}),[t.maxHeight,i]);return e?c.jsxs("div",{ref:l,className:`panelContainer ${S}`.trim(),style:A,children:[c.jsx("div",{className:"resizeHandle",onMouseDown:w}),c.jsx(xe,{state:f,actions:b,outputRef:d})]}):null},se=t=>{if(!t)return;const e=t.trim();if(e)return/^\d+(\.\d+)?$/.test(e)?`${e}px`:e},Xe=()=>{const{state:t,actions:e}=ne(),n=T(),s=a.useRef(null),r=a.useMemo(()=>({height:se(n.initialHeight),maxHeight:se(n.maxHeight),minHeight:se(n.minHeight)}),[n.initialHeight,n.maxHeight,n.minHeight]);return c.jsx("div",{className:"inlineContainer","data-testid":"citadel-inline-container",style:r,children:c.jsx(xe,{state:t,actions:e,outputRef:s})})},ke=`:host {
7
+ --citadel-bg: oklch(20.8% 0.042 265.8);
8
+ --citadel-surface: oklch(27.9% 0.041 260);
9
+ --citadel-border: oklch(37.2% 0.044 257.3);
10
+ --citadel-text: oklch(92.8% 0.006 264.5);
11
+ --citadel-muted: oklch(70.7% 0.022 261.3);
12
+ --citadel-subtle: oklch(55.1% 0.023 264.4);
13
+ --citadel-word: oklch(70.7% 0.165 254.6);
14
+ --citadel-arg: oklch(72.3% 0.219 149.6);
15
+ --citadel-error: oklch(70.4% 0.191 22.2);
16
+ --citadel-success: oklch(72.3% 0.219 149.6);
17
+ --citadel-min-height: 200px;
18
+ --citadel-max-height: 80vh;
19
+ --citadel-default-height: 35vh;
20
+ --citadel-panel-enter-duration: 200ms;
21
+ --citadel-panel-exit-duration: 200ms;
22
+ --citadel-panel-enter-easing: cubic-bezier(0.16, 1, 0.3, 1);
23
+ --citadel-panel-exit-easing: cubic-bezier(0.4, 0, 1, 1);
24
+
25
+ display: block;
26
+ pointer-events: auto;
27
+ color: var(--citadel-text);
28
+ font-synthesis: none;
29
+ text-rendering: optimizeLegibility;
30
+ -webkit-font-smoothing: antialiased;
31
+ -moz-osx-font-smoothing: grayscale;
32
+ }
33
+
34
+ :host([data-display-mode='panel']) {
35
+ position: fixed;
36
+ bottom: 0;
37
+ left: 0;
38
+ right: 0;
39
+ width: 100%;
40
+ height: var(--citadel-default-height);
41
+ max-height: var(--citadel-max-height);
42
+ min-height: var(--citadel-min-height);
43
+ z-index: 2147483647;
44
+ overflow: hidden;
45
+ }
46
+
47
+ :host([data-display-mode='inline']) {
48
+ position: relative;
49
+ bottom: auto;
50
+ left: auto;
51
+ right: auto;
52
+ z-index: auto;
53
+ width: 100%;
54
+ height: 100%;
55
+ max-height: none;
56
+ min-height: 0;
57
+ overflow: hidden;
58
+ }
59
+
60
+ #citadel-root {
61
+ width: 100%;
62
+ height: 100%;
63
+ }
64
+
65
+ #citadel-root,
66
+ #citadel-root * {
67
+ box-sizing: border-box;
68
+ }
69
+
70
+ .panelContainer {
71
+ position: fixed;
72
+ bottom: 0;
73
+ left: 0;
74
+ right: 0;
75
+ width: 100%;
76
+ height: var(--citadel-default-height);
77
+ min-height: var(--citadel-min-height);
78
+ max-height: var(--citadel-max-height);
79
+ margin: 0;
80
+ padding: 0;
81
+ background-color: var(--citadel-bg);
82
+ overflow: hidden;
83
+ transform: translateY(0);
84
+ will-change: transform;
85
+ }
86
+
87
+ .innerContainer {
88
+ width: 100%;
89
+ height: 100%;
90
+ margin: 0;
91
+ padding: 0;
92
+ display: flex;
93
+ flex: 1;
94
+ flex-direction: column;
95
+ }
96
+
97
+ .citadel-tty {
98
+ background: var(--citadel-bg);
99
+ }
100
+
101
+ .citadel-tty-output-pane {
102
+ display: flex;
103
+ flex: 1 1 auto;
104
+ min-height: 0;
105
+ padding: 0.75rem 1rem 0;
106
+ }
107
+
108
+ .citadel-tty-input-region {
109
+ flex-shrink: 0;
110
+ }
111
+
112
+ .resizeHandle {
113
+ position: absolute;
114
+ top: -3px;
115
+ left: 0;
116
+ right: 0;
117
+ z-index: 10;
118
+ width: 100%;
119
+ height: 6px;
120
+ background: transparent;
121
+ cursor: ns-resize;
122
+ user-select: none;
123
+ -webkit-user-select: none;
124
+ pointer-events: all;
125
+ }
126
+
127
+ .resizeHandle:hover {
128
+ background: color-mix(in oklch, var(--citadel-text) 10%, transparent);
129
+ }
130
+
131
+ @keyframes citadel_slideUp {
132
+ from {
133
+ transform: translateY(100%);
134
+ }
135
+
136
+ to {
137
+ transform: translateY(0);
138
+ }
139
+ }
140
+
141
+ @keyframes citadel_slideDown {
142
+ from {
143
+ transform: translateY(0);
144
+ }
145
+
146
+ to {
147
+ transform: translateY(100%);
148
+ }
149
+ }
150
+
151
+ .citadel_slideUp {
152
+ animation: citadel_slideUp var(--citadel-panel-enter-duration) var(--citadel-panel-enter-easing) forwards;
153
+ }
154
+
155
+ .citadel_slideDown {
156
+ animation: citadel_slideDown var(--citadel-panel-exit-duration) var(--citadel-panel-exit-easing) forwards;
157
+ }
158
+
159
+ @media (prefers-reduced-motion: reduce) {
160
+ :host {
161
+ --citadel-panel-enter-duration: 1ms;
162
+ --citadel-panel-exit-duration: 1ms;
163
+ }
164
+ }
165
+
166
+ .inlineContainer {
167
+ position: relative;
168
+ width: 100%;
169
+ height: 100%;
170
+ display: flex;
171
+ flex-direction: column;
172
+ background-color: var(--citadel-bg);
173
+ overflow: hidden;
174
+ }
175
+
176
+ .citadel-output {
177
+ width: 100%;
178
+ height: 100%;
179
+ overflow-y: auto;
180
+ padding: 0.75rem;
181
+ border: 1px solid var(--citadel-border);
182
+ border-radius: 0.5rem;
183
+ background: color-mix(in oklch, var(--citadel-bg) 75%, black);
184
+ text-align: left;
185
+ }
186
+
187
+ .citadel-output-item {
188
+ margin-bottom: 1rem;
189
+ }
190
+
191
+ .citadel-output-item:last-child {
192
+ margin-bottom: 0;
193
+ }
194
+
195
+ .citadel-output-content {
196
+ margin-top: 0.35rem;
197
+ color: var(--citadel-text);
198
+ }
199
+
200
+ .citadel-output-content > :first-child {
201
+ margin-top: 0;
202
+ }
203
+
204
+ .citadel-output-content > :last-child {
205
+ margin-bottom: 0;
206
+ }
207
+
208
+ .citadel-output-line {
209
+ display: flex;
210
+ flex-wrap: wrap;
211
+ align-items: center;
212
+ gap: 0.5rem;
213
+ }
214
+
215
+ .citadel-output-command,
216
+ .citadel-output-command-word {
217
+ color: var(--citadel-text);
218
+ }
219
+
220
+ .citadel-output-command-arg {
221
+ color: var(--citadel-arg);
222
+ }
223
+
224
+ .citadel-output-separator {
225
+ color: var(--citadel-muted);
226
+ }
227
+
228
+ .citadel-output-timestamp {
229
+ color: var(--citadel-subtle);
230
+ }
231
+
232
+ .citadel-status-dot {
233
+ width: 1rem;
234
+ height: 1rem;
235
+ border-radius: 999px;
236
+ }
237
+
238
+ .citadel-status-dot-success {
239
+ background: var(--citadel-success);
240
+ }
241
+
242
+ .citadel-status-dot-failure {
243
+ background: var(--citadel-error);
244
+ }
245
+
246
+ .citadel-spinner {
247
+ width: 1rem;
248
+ height: 1rem;
249
+ border: 2px solid color-mix(in oklch, var(--citadel-text) 60%, transparent);
250
+ border-top-color: color-mix(in oklch, var(--citadel-muted) 80%, black);
251
+ border-radius: 999px;
252
+ animation: citadel-spin 0.9s linear infinite;
253
+ }
254
+
255
+ @keyframes citadel-spin {
256
+ to {
257
+ transform: rotate(360deg);
258
+ }
259
+ }
260
+
261
+ .citadel-input-shell {
262
+ width: 100%;
263
+ padding: 1rem;
264
+ border-radius: 0.5rem;
265
+ background-color: var(--citadel-bg);
266
+ }
267
+
268
+ .citadel-input-line {
269
+ display: flex;
270
+ align-items: center;
271
+ gap: 0.5rem;
272
+ }
273
+
274
+ .citadel-input-prompt {
275
+ color: var(--citadel-muted);
276
+ }
277
+
278
+ .citadel-input-row {
279
+ display: flex;
280
+ align-items: center;
281
+ flex: 1 1 auto;
282
+ min-width: 0;
283
+ }
284
+
285
+ .citadel-input-segments {
286
+ display: flex;
287
+ align-items: center;
288
+ gap: 0.25rem;
289
+ }
290
+
291
+ .citadel-input-segment-arg {
292
+ color: var(--citadel-text);
293
+ white-space: pre;
294
+ }
295
+
296
+ .citadel-input-segment-word {
297
+ color: var(--citadel-word);
298
+ white-space: pre;
299
+ }
300
+
301
+ .citadel-input-segment-space {
302
+ color: var(--citadel-text);
303
+ white-space: pre;
304
+ }
305
+
306
+ .citadel-input-segment-space-command {
307
+ color: var(--citadel-word);
308
+ }
309
+
310
+ .citadel-input-control {
311
+ position: relative;
312
+ flex: 1 1 auto;
313
+ min-width: 0;
314
+ }
315
+
316
+ .citadel-input-measure {
317
+ position: absolute;
318
+ top: 0;
319
+ left: 0;
320
+ visibility: hidden;
321
+ pointer-events: none;
322
+ white-space: pre;
323
+ font: inherit;
324
+ letter-spacing: inherit;
325
+ }
326
+
327
+ .citadel-input-field {
328
+ width: 100%;
329
+ margin: 0;
330
+ padding: 0;
331
+ border: 0;
332
+ border-radius: 0;
333
+ outline: none;
334
+ background: transparent;
335
+ font: inherit;
336
+ line-height: inherit;
337
+ letter-spacing: inherit;
338
+ appearance: none;
339
+ -webkit-appearance: none;
340
+ caret-color: transparent;
341
+ }
342
+
343
+ .citadel-input-field::placeholder {
344
+ color: var(--citadel-subtle);
345
+ opacity: 1;
346
+ }
347
+
348
+ .citadel-input-field.is-command-mode {
349
+ color: var(--citadel-word);
350
+ }
351
+
352
+ .citadel-input-field.is-argument-mode {
353
+ color: var(--citadel-text);
354
+ }
355
+
356
+ .citadel-input-cursor {
357
+ position: absolute;
358
+ top: 0;
359
+ pointer-events: none;
360
+ }
361
+
362
+ @keyframes citadel-invalid-glow {
363
+ 0%,
364
+ 100% {
365
+ box-shadow: 0 0 0 color-mix(in oklch, var(--citadel-error) 0%, transparent);
366
+ }
367
+
368
+ 50% {
369
+ box-shadow: 0 0 8px color-mix(in oklch, var(--citadel-error) 70%, transparent);
370
+ }
371
+ }
372
+
373
+ .invalid-input-animation {
374
+ animation: citadel-invalid-glow 0.4s ease-in-out;
375
+ }
376
+
377
+ .citadel-cursor-wrapper {
378
+ position: relative;
379
+ display: inline-block;
380
+ }
381
+
382
+ .command-cursor {
383
+ display: inline-block;
384
+ white-space: pre;
385
+ }
386
+
387
+ @keyframes citadel-shake {
388
+ 0%,
389
+ 100% {
390
+ transform: translateX(0);
391
+ }
392
+
393
+ 25% {
394
+ transform: translateX(-4px);
395
+ }
396
+
397
+ 75% {
398
+ transform: translateX(4px);
399
+ }
400
+ }
401
+
402
+ .animate-shake {
403
+ animation: citadel-shake 0.2s ease-in-out;
404
+ }
405
+
406
+ .citadel-available-commands {
407
+ margin-top: 0.5rem;
408
+ padding: 0.5rem 1rem;
409
+ border-top: 1px solid var(--citadel-border);
410
+ }
411
+
412
+ .citadel-available-commands-content {
413
+ color: var(--citadel-muted);
414
+ }
415
+
416
+ .citadel-available-chip-list {
417
+ display: flex;
418
+ flex-wrap: wrap;
419
+ gap: 0.5rem;
420
+ }
421
+
422
+ .citadel-available-chip {
423
+ padding: 0.25rem 0.5rem;
424
+ border-radius: 0.375rem;
425
+ background: var(--citadel-surface);
426
+ }
427
+
428
+ .citadel-available-chip-text {
429
+ color: white;
430
+ }
431
+
432
+ .citadel-available-chip-prefix {
433
+ text-decoration: underline;
434
+ }
435
+
436
+ .citadel-available-next-arg {
437
+ color: var(--citadel-word);
438
+ }
439
+
440
+ .citadel-available-next-desc {
441
+ margin-left: 0.5rem;
442
+ color: var(--citadel-muted);
443
+ }
444
+
445
+ .citadel-result-json,
446
+ .citadel-result-text {
447
+ color: var(--citadel-text);
448
+ }
449
+
450
+ .citadel-result-json {
451
+ margin: 0;
452
+ }
453
+
454
+ .citadel-result-text {
455
+ white-space: pre;
456
+ }
457
+
458
+ .citadel-result-error {
459
+ margin-top: 0.25rem;
460
+ color: var(--citadel-error);
461
+ }
462
+
463
+ .citadel-result-pending {
464
+ color: var(--citadel-muted);
465
+ }
466
+
467
+ .citadel-result-image-wrap {
468
+ margin-block: 0.5rem;
469
+ }
470
+
471
+ .citadel-result-image {
472
+ max-width: 400px;
473
+ max-height: 300px;
474
+ height: auto;
475
+ object-fit: contain;
476
+ border-radius: 0.5rem;
477
+ }
478
+ `,Ze=({config:t=k,commandRegistry:e,containerId:n=null})=>{const s=a.useRef(new K),r=e??s.current,i=a.useRef(null),o=a.useMemo(()=>({width:"100%",height:"100%"}),[]),d=t.displayMode??k.displayMode??"panel";return a.useEffect(()=>{x.configure({level:t.logLevel||k.logLevel||R.ERROR,prefix:"[Citadel]"});const l=new Ee(r,t),u=d==="inline"&&!n,y=u?i.current:n?document.getElementById(n):document.body;if(y)y.appendChild(l);else{if(u){console.warn("[Citadel] No host available for inline mode; skipping mount.");return}console.warn(`Container with id "${n}" not found, falling back to body`),document.body.appendChild(l)}return()=>{var p;(p=l.parentElement)==null||p.removeChild(l)}},[r,n,t,d]),d==="inline"&&!n?c.jsx("div",{ref:i,style:o}):null};class Ee extends HTMLElement{constructor(n,s){var i;super();C(this,"shadow");C(this,"root",null);C(this,"commandRegistry");C(this,"config");this.shadow=this.attachShadow({mode:"open"}),this.commandRegistry=n,this.config=s;const r=((i=this.config)==null?void 0:i.displayMode)??"panel";this.setAttribute("data-display-mode",r)}connectedCallback(){try{const s=[ke].map(r=>{const i=new CSSStyleSheet;return i.replaceSync(r),i});this.shadow.adoptedStyleSheets=[...s]}catch{const s=[ke].join(`
479
+ `),r=document.createElement("style");r.textContent=s,this.shadow.appendChild(r)}const n=document.createElement("div");n.id="citadel-root",n.style.width="100%",n.style.height="100%",this.shadow.appendChild(n),this.root=Me.createRoot(n),this.root.render(c.jsx(De,{config:this.config||k,commandRegistry:this.commandRegistry,children:c.jsx(Re,{})}))}disconnectedCallback(){const n=this.root;if(this.root=null,!n){this.shadow.replaceChildren();return}queueMicrotask(()=>{n.unmount(),this.shadow.replaceChildren()})}}typeof window<"u"&&window.customElements&&!window.customElements.get("citadel-element")&&window.customElements.define("citadel-element",Ee);const Re=()=>(T().displayMode??"panel")==="inline"?c.jsx(Xe,{}):c.jsx(Qe,{});class et{constructor(){C(this,"_description")}describe(e){return this._description=e,this}get description(){return this._description}}class tt{constructor(e){C(this,"state");this.state={path:e,description:"",segments:nt(e)}}describe(e){return this.state.description=e,this}details(e){return this.state.details=e,this}arg(e,n){const s=new et;return n==null||n(s),this.state.segments.push({type:"argument",name:e,description:s.description}),this}handle(e){return{path:this.state.path,description:this.state.description,details:this.state.details,segments:[...this.state.segments],handler:e}}}function nt(t){const e=t.trim();if(!e)throw new Error("Command path cannot be empty");const n=e.split(".");if(n.some(s=>s.trim()===""))throw new Error(`Invalid command path "${t}". Empty segments are not allowed.`);if(n.some(s=>s.includes(" ")))throw new Error(`Invalid command path "${t}". Use dot-delimited words (e.g. "user.show").`);return n.map(s=>({type:"word",name:s}))}function st(t){return t.flatMap(e=>e.type==="argument"?[e.name]:[])}function rt(t){const e=st(t.segments);return async n=>{const s=e.reduce((r,i,o)=>(r[i]=n[o],r),{});return Promise.resolve(t.handler({rawArgs:n,namedArgs:s,commandPath:t.path}))}}function at(t){return new tt(t)}function Ne(t,e){t.addCommand(e.segments,e.description,rt(e))}function Ie(t,e){return e.forEach(n=>Ne(t,n)),t}function ot(t){const e=new K;return Ie(e,t)}function it(t){return new q(t)}function lt(t,e="true",n="false"){return new ie(t,e,n)}function ct(t){return new oe(t)}function dt(t,e=""){return new ce(t,e)}function mt(t){return new Z(t)}g.BooleanCommandResult=ie,g.Citadel=Ze,g.CommandRegistry=K,g.CommandResult=_,g.CommandStatus=j,g.DEFAULT_CURSOR_CONFIGS=we,g.ErrorCommandResult=Z,g.ImageCommandResult=ce,g.JsonCommandResult=oe,g.OutputItem=G,g.PendingCommandResult=le,g.TextCommandResult=q,g.bool=lt,g.command=at,g.createCommandRegistry=ot,g.error=mt,g.image=dt,g.json=ct,g.registerCommand=Ne,g.registerCommands=Ie,g.text=it,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});