citadel_cli 1.3.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.
@@ -1,36 +1,37 @@
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,s,Ne){"use strict";var dn=Object.defineProperty;var mn=(g,c,s)=>c in g?dn(g,c,{enumerable:!0,configurable:!0,writable:!0,value:s}):g[c]=s;var C=(g,c,s)=>mn(g,typeof c!="symbol"?c+"":c,s);var U=(t=>(t.Pending="pending",t.Success="success",t.Failure="failure",t.Timeout="timeout",t))(U||{});class D{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 te extends D{constructor(e,n){super(n),this.data=e}render(){return c.jsx("pre",{className:"text-gray-200",children:JSON.stringify(this.data,null,2)})}}class L extends D{constructor(e,n){super(n),this.text=e}render(){return c.jsx("div",{className:"text-gray-200 whitespace-pre",children:this.text})}}class J extends D{constructor(e,n){super(n),this.error=e,this.markFailure()}render(){return c.jsx("div",{className:"mt-1 text-red-400",children:this.error})}}class re extends D{render(){return c.jsx("div",{className:"text-gray-400",children:"..."})}}class oe extends D{constructor(e,n="",r){super(r),this.imageUrl=e,this.altText=n}render(){return c.jsx("div",{className:"my-2",children:c.jsx("img",{src:this.imageUrl,alt:this.altText,className:"max-w-[400px] max-h-[300px] h-auto rounded-lg object-contain"})})}}const ze=t=>async function(){const n=t.commands.filter(r=>r.fullPath[0]!=="help").map(r=>{const a=`${r.segments.map(d=>d.type==="argument"?`<${d.name}>`:d.name).join(" ")} - ${r.description}`,l=r.segments.filter(d=>d.type==="argument"&&d.description).map(d=>` <${d.name}>: ${d.description}`);return{commandLine:a,argumentLines:l}}).sort((r,o)=>r.commandLine.localeCompare(o.commandLine)).flatMap(r=>[r.commandLine,...r.argumentLines]);return n.length===0?new L("No commands available yet. Add some commands to get started!"):(n.push("help - Show available commands"),new L(`Available Commands:
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
2
  `+n.join(`
3
- `)))};var X=(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))(X||{});const se=!0;class E{static configure(e){this.level=e.level,this.prefix=e.prefix||"[Citadel]"}static trace(...e){this.level>=5&&!se&&console.trace(this.prefix,...e)}static debug(...e){this.level>=4&&!se&&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(E,"level",0),C(E,"prefix","");const N={commandTimeoutMs:1e4,cursorColor:"var(--cursor-color, #fff)",cursorSpeed:530,cursorType:"blink",includeHelpCommand:!0,fontFamily:"monospace",fontSize:"0.875rem",initialHeight:"40vh",logLevel:X.ERROR,maxHeight:"80vh",minHeight:"200",outputFontSize:"0.875rem",resetStateOnHide:!1,showCitadelKey:".",displayMode:"panel",storage:{type:"localStorage",maxCommands:100}},ae=async()=>new L("");class Q{constructor(e,n,r){this.type=e,this.name=n,this.description=r}toString(){return this.name}}class Z extends Q{constructor(){super("null",">null<","Empty segment")}}class ie extends Q{constructor(e,n){super("word",e,n)}}class j extends Q{constructor(e,n,r,o){super("argument",e,n),this.value=r,this.valid=o}}const _e=t=>{if(t.type==="word")return new ie(t.name,t.description);if(t.type==="argument"){const e=t;return new j(e.name,e.description,e.value,e.valid)}return new Z},A=t=>t.map(e=>_e(e));class Ae{constructor(e,n,r=ae){C(this,"_segments");C(this,"_description");C(this,"_handler");this._segments=e,this._description=n,this._handler=r}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 O{constructor(){C(this,"_commands",[])}get commands(){return this._commands}addCommand(e,n,r=ae){if(e===void 0||e.length===0)throw new Error("Command path cannot be empty");const o=new Ae(e,n,r),a=this._commands.find(l=>{const d=l.segments.map(m=>m.type==="argument"?"*":m.name).join(" "),i=e.map(m=>m.type==="argument"?"*":m.name).join(" ");return d===i});if(a)throw new Error(`Duplicate commands: '${a.fullPath_s}' and '${o.fullPath_s}'`);this._commands.push(o)}removeCommand(e){const n=e.join(" "),r=this._commands.findIndex(o=>o.fullPath.join(" ")===n);return r===-1?!1:(this._commands.splice(r,1),!0)}getCommand(e){return this._commands.find(n=>{const r=n.fullPath.join(" "),o=e.join(" ");if(r===o)return!0;const l=n.segments.filter(d=>d.type==="word").map(d=>d.name);return l.length===e.length&&l.join(" ")===o})}commandExistsForPath(e){const n=this._commands.map(o=>o.segments.map(a=>a.type==="argument"?"*":a.name).join(" ")),r=e.map((o,a)=>this._commands.some(d=>{var i;return((i=d.segments[a])==null?void 0:i.type)==="argument"})?"*":o).join(" ");return n.includes(r)}getCompletionNames(e){return this.getCompletions(e).map(n=>n.name)}getMatchingCompletions(e,n){const r=n.trim().toLowerCase(),o=this.getCompletions(e);return r?o.filter(a=>a.name.toLowerCase().startsWith(r)):o}getUniqueCompletion(e,n){const r=this.getMatchingCompletions(e,n);if(r.length===1)return r[0]}getCompletions(e){if(E.debug("[getCompletions] path: ",e),!e.length){const a=this._commands.map(i=>i.segments[0]),l=(i,m)=>i.type===m.type&&i.name===m.name;return a.filter((i,m,w)=>m===w.findIndex(b=>l(b,i)))}const n=e.length;return this._commands.filter(a=>{const l=a.segments;if(l.length<=n-1)return!1;for(let d=0;d<n;d++){const i=e[d],m=l[d];if(!(i==="*"&&m.type==="argument")&&i!==m.name)return!1}return!0}).filter(a=>a.segments.length>n).map(a=>{const l=a.segments[n],d=l.type==="argument"?j:ie;return new d(l.name,l.description)}).filter((a,l,d)=>l===d.findIndex(i=>i.type===a.type&&i.name===a.name))}hasNextSegment(e){return this.getCompletions(e).length>0}}class le{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 Ie extends le{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(o=>({commandSegments:Array.isArray(o.commandSegments)?A(o.commandSegments):[],timestamp:o.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 r=n.map(o=>({commandSegments:Array.isArray(o.commandSegments)?A(o.commandSegments).map(a=>({type:a.type,name:a.name,description:a.description,...a instanceof j?{value:a.value}:{}})):[],timestamp:o.timestamp}));window.localStorage.setItem(this.storageKey,JSON.stringify(r))}catch(r){throw console.warn("Failed to save commands to localStorage:",r),r}}}class ce extends le{constructor(n){super(n);C(this,"storedCommands",[])}async getStoredCommands(){return this.storedCommands.map(n=>({commandSegments:Array.isArray(n.commandSegments)?A(n.commandSegments):[],timestamp:n.timestamp}))}async clear(){this.storedCommands=[]}async saveCommands(n){this.storedCommands=n.map(r=>({commandSegments:Array.isArray(r.commandSegments)?A(r.commandSegments):[],timestamp:r.timestamp}))}}const T=class T{constructor(){C(this,"currentStorage")}static reset(){T.instance=void 0}static getInstance(){return T.instance||(T.instance=new T),T.instance}initializeStorage(e){try{e.type==="memory"?this.currentStorage=new ce(e):this.currentStorage=new Ie(e)}catch(n){console.warn("Failed to create storage, falling back to memory storage:",n),this.currentStorage=new ce(e)}}getStorage(){if(!this.currentStorage)throw new Error("Storage not initialized. Call initializeStorage first.");return this.currentStorage}};C(T,"instance");let W=T;class de{constructor(){C(this,"segments",[]);C(this,"nullSegment",new Z);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 Me={config:N,commands:new O,segmentStack:new de},$=s.createContext(Me),Pe=({config:t=N,commandRegistry:e,children:n})=>{const[r,o]=s.useState(),[a]=s.useState(()=>new de),l=s.useMemo(()=>({...N,...t,storage:{...N.storage,...t.storage},cursorType:t.cursorType??N.cursorType,cursorColor:t.cursorColor??N.cursorColor,cursorSpeed:t.cursorSpeed??N.cursorSpeed,showCitadelKey:t.showCitadelKey||"."}),[t]);s.useEffect(()=>{W.getInstance().initializeStorage(l.storage??N.storage),o(W.getInstance().getStorage())},[l.storage]),s.useEffect(()=>{if(e){if(l.includeHelpCommand){if(!e.commandExistsForPath(["help"])){const i=ze(e);e.addCommand([{type:"word",name:"help"}],"Show available commands",i)}return}e.removeCommand(["help"])}},[e,l.includeHelpCommand]);const d=s.useMemo(()=>({config:l,commands:e||new O,storage:r,segmentStack:a}),[l,e,r,a]);return c.jsx($.Provider,{value:d,children:n})},H=()=>{const t=s.useContext($);if(t===void 0)throw new Error("useCitadelConfig must be used within a CitadelConfigProvider");return t.config},B=()=>{const t=s.useContext($);if(t===void 0)throw new Error("useCitadelCommands must be used within a CitadelConfigProvider");return t.commands},me=()=>{const t=s.useContext($);if(t===void 0)throw new Error("useCitadelStorage must be used within a CitadelConfigProvider");return t.storage},q=()=>{const t=s.useContext($);if(t===void 0)throw new Error("useSegmentStack must be used within a CitadelConfigProvider");return t.segmentStack},G=class G{constructor(e,n){C(this,"id");C(this,"timestamp");C(this,"command");C(this,"result");this.id=`output-${Date.now()}-${G.idCounter++}`,this.command=e.toArray().map(r=>r.type==="argument"?r.value||"":r.name),this.timestamp=Date.now(),this.result=n??new re}};C(G,"idCounter",0);let Y=G;function He(t){return{commandSegments:A(t),timestamp:Date.now()}}function ue(){const t=me(),[e,n]=s.useState({storedCommands:[],position:null}),r=s.useCallback(async d=>{if(t)try{const i=He(d);await t.addStoredCommand(i),n(m=>({...m,storedCommands:[...m.storedCommands,{...i,commandSegments:A(i.commandSegments)}],position:null}))}catch(i){console.warn("Failed to save command to history:",i)}},[t]),o=s.useCallback(async()=>t?(await t.getStoredCommands()).map(i=>({...i,commandSegments:A(i.commandSegments)})):[],[t]);s.useEffect(()=>{if(!t)return;(async()=>{try{const m=(await t.getStoredCommands()).map(w=>({...w,commandSegments:A(w.commandSegments)}));return n(w=>({...w,storedCommands:m})),m}catch(i){console.warn("Failed to load command history:",i)}})()},[t]);const a=s.useCallback(async d=>{const i=await o();if(i.length===0)return n(b=>({...b,storedCommands:[],position:null})),{segments:null,position:null};let m=null;if(d==="up"?e.position===null?m=i.length-1:e.position>0?m=e.position-1:m=0:e.position===null||e.position>=i.length-1?m=null:m=e.position+1,n(b=>({...b,storedCommands:i.map(v=>({...v,commandSegments:A(v.commandSegments)})),position:m})),m===null)return{segments:[],position:null};const w=i[m];return w?{segments:A(w.commandSegments),position:m}:{segments:[],position:null}},[e.position,o]),l=s.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:r,getStoredCommands:o,navigateHistory:a,clear:l}}const R=()=>{const t=H(),e=B(),n=ue(),r=q(),o=me(),[a,l]=s.useState({currentInput:"",isEnteringArg:!1,output:[],history:{commands:[],position:null,storage:o}});s.useEffect(()=>{},[o]),s.useEffect(()=>{l(i=>({...i,history:{commands:n.history.storedCommands,position:n.history.position,storage:o}}))},[n.history,o]);const d={setCurrentInput:s.useCallback(i=>{E.debug("[CitadelActions] setCurrentInput: ",i),l(m=>({...m,currentInput:i}))},[]),setIsEnteringArg:s.useCallback(i=>{E.debug("[CitadelActions] setIsEnteringArg: ",i),l(m=>({...m,isEnteringArg:i}))},[]),addOutput:s.useCallback(i=>{E.debug("[CitadelActions]addOutput: ",i),l(m=>({...m,output:[...m.output,i]}))},[]),executeCommand:s.useCallback(async()=>{const i=r.path(),m=e.getCommand(i);if(!m){console.error("[CitadelActions][executeCommand] Cannot execute command because no command was found for the given path: ",i);return}const w=new Y(r);l(b=>({...b,output:[...b.output,w]}));try{const b=new Promise((f,k)=>{setTimeout(()=>{k(new Error("Request timed out"))},t.commandTimeoutMs)}),v=r.arguments.map(f=>f.value||""),y=await Promise.race([m.handler(v),b]);if(!(y instanceof D))throw new Error(`The ${i.join(".")} command returned an invalid result type. Commands must return an instance of a CommandResult.
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
4
  For example:
5
5
  return new JsonCommandResult({ text: "Hello World" });
6
- Check the definition of the ${i.join(".")} command and update the return type for its handler.`);y.markSuccess(),l(f=>({...f,output:f.output.map(k=>k.id===w.id?{...k,result:y}:k)}))}catch(b){const v=new J(b instanceof Error?b.message:"Unknown error");v.markFailure(),l(y=>({...y,output:y.output.map(f=>f.id===w.id?{...f,result:v}:f)}))}},[e,t.commandTimeoutMs,r]),clearHistory:s.useCallback(async()=>{try{await n.clear()}catch(i){console.warn("Failed to clear history:",i)}},[n])};return{state:a,actions:d}},Te=({onOpen:t,onClose:e,isVisible:n,showCitadelKey:r})=>{s.useEffect(()=>{const o=a=>{var l,d;!n&&a.key===r&&!["input","textarea"].includes(((d=(l=a.target)==null?void 0:l.tagName)==null?void 0:d.toLowerCase())||"")&&(a.preventDefault(),t()),n&&a.key==="Escape"&&(a.preventDefault(),e())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[t,e,n,r])},pe={panelContainer:"_panelContainer_1pav9_3",innerContainer:"_innerContainer_1pav9_19",inputSection:"_inputSection_1pav9_29",resizeHandle:"_resizeHandle_1pav9_36",citadel_slideUp:"_citadel_slideUp_1pav9_65",citadel_slideDown:"_citadel_slideDown_1pav9_69",inlineContainer:"_inlineContainer_1pav9_73"},Fe=t=>{const{isVisible:e,isClosing:n,onAnimationComplete:r}=t,o=s.useMemo(()=>e?n?pe.slideDown:pe.slideUp:"",[e,n]);return s.useEffect(()=>{if(r){const l=setTimeout(()=>{r()},200);return()=>clearTimeout(l)}},[n,r]),{style:s.useMemo(()=>({opacity:e?1:0,transform:e?"translateY(0)":n?"translateY(100%)":"translateY(-100%)",transition:"opacity 200ms ease-in-out, transform 200ms ease-in-out"}),[e,n]),animationClass:o}},De=()=>c.jsx("div",{"data-testid":"spinner",className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-gray-600"}),Ue=/^text-(xs|sm|base|lg|xl|[2-9]xl|\[[^\]]+\])$/,he=t=>{const e=t==null?void 0:t.trim();return e||void 0},je=t=>{const e=he(t);return e?Ue.test(e)?{className:e}:{style:{fontSize:e}}:{}},V=(t,e)=>{const n=he(t),r=je(e),o={...r.style};return n&&(o.fontFamily=n),{className:r.className,style:Object.keys(o).length>0?o:void 0}},Le=({command:t,timestamp:e,status:n,fontFamily:r,fontSize:o})=>{const a=s.useMemo(()=>V(r,o??"text-sm"),[r,o]);return c.jsxs("div",{className:`flex items-center gap-2 ${a.className??""}`.trim(),style:a.style,children:[c.jsxs("span",{className:"text-gray-200",children:["> ",t.split(" ").map((l,d)=>{const i=l.startsWith("<")&&l.endsWith(">");return c.jsxs("span",{className:i?"text-green-400":"text-gray-200",children:[d>0?" ":"",l]},d)})]}),c.jsx("span",{className:"text-gray-400",children:"·"}),c.jsx("span",{className:"text-gray-500",children:e}),n===U.Pending&&c.jsx(De,{}),n===U.Success&&c.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-green-500"}),(n===U.Timeout||n===U.Failure)&&c.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-red-500"})]})},Oe=({output:t,outputRef:e})=>{const n=H(),r=s.useMemo(()=>V(n.fontFamily,n.outputFontSize??n.fontSize),[n.fontFamily,n.fontSize,n.outputFontSize]),o=s.useCallback(()=>{if(e.current){const a=e.current;requestAnimationFrame(()=>{a.scrollTop=a.scrollHeight})}},[e]);return s.useEffect(()=>{if(o(),e.current){const a=e.current.getElementsByTagName("img"),l=a[a.length-1];if(l&&!l.complete)return l.addEventListener("load",o),()=>l.removeEventListener("load",o)}},[t,o,e]),c.jsx("div",{ref:e,className:"h-full overflow-y-auto border border-gray-700 rounded-lg p-3 text-left","data-testid":"citadel-command-output",children:t.map(a=>c.jsxs("div",{className:"mb-4 last:mb-0",children:[c.jsx(Le,{command:a.command.join(" "),timestamp:new Date(a.timestamp).toLocaleTimeString(),status:a.result.status,fontFamily:n.fontFamily,fontSize:n.fontSize}),c.jsx("pre",{className:`text-gray-200 whitespace-pre ${r.className??""}`.trim(),style:r.style,children:a.result.render()})]},a.id))})},ge={blink:{character:"▋",speed:530,color:"#fff"},spin:{character:"⠋",speed:120,color:"#fff"},solid:{character:"▋",speed:0,color:"#fff"},bbs:{character:"|",speed:120,color:"#fff"}},fe=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],we=["|","/","-","\\"],$e=({style:t={type:"blink"},isValid:e=!0,errorMessage:n})=>{const r=s.useMemo(()=>({...ge[t.type],...t}),[t]),[o,a]=s.useState(!0),[l,d]=s.useState(0);s.useEffect(()=>{if(r.speed===0)return;const w=setInterval(()=>{r.type==="blink"?a(b=>!b):["spin","bbs"].includes(r.type)&&d(b=>(b+1)%(r.type==="bbs"?we.length:fe.length))},r.speed);return()=>clearInterval(w)},[r.type,r.speed]);const i=s.useMemo(()=>({color:e?r.color:"#ff4444",transition:"color 0.15s ease-in-out"}),[e,r.color]),m=()=>!e&&n?"✗":["spin","bbs"].includes(r.type)?(r.type==="bbs"?we:fe)[l]:r.type==="solid"||o?r.character:" ";return c.jsx("div",{className:"relative inline-block",children:c.jsx("span",{className:`command-cursor ${e?"":"animate-shake"}`,style:i,title:n,children:m()})})};function qe(t,e){switch(e.type){case"set":return E.debug(`[inputStateReducer] InputState changing from ${t} to ${e.state}`),e.state;default:return t}}const Ke=()=>{const{state:t}=R(),e=B(),n=ue(),r=q(),[o,a]=s.useReducer(qe,"idle"),l=u=>{a({type:"set",state:u})},d=s.useCallback(()=>{const p=e.getCompletions(r.path())[0]||r.nullSegment;return E.debug("[getNextExpectedSegment] ",p),p},[e,r]),i=s.useCallback(()=>e.getCompletionNames(r.path()).map(p=>e.getCommand([...r.path(),p])).filter(p=>p!==void 0),[e,r]),m=s.useCallback((u,p)=>{if(!u)return p;const h=r.path().length;return p.filter(I=>{const S=I.segments[h];return!S||S.type!=="word"?!1:S.name.toLowerCase().startsWith(u.toLowerCase())})},[r]),w=s.useCallback(u=>{const p=e.getUniqueCompletion(r.path(),u);return p&&p.type==="word"?p:r.nullSegment},[e,r]),b=s.useCallback(u=>{const p=r.path(),h=e.getCompletions(p);return h.length===0&&u?!1:h.some(S=>S.type==="argument")?!0:e.getMatchingCompletions(p,u).some(S=>S.type==="word")},[e,r]),v=s.useCallback(u=>{E.debug("[tryAutoComplete] input: ",u);const p=w(u);return!p||p.type==="null"?new Z:(E.debug("[tryAutoComplete] result: ",p),p)},[w]),y=s.useCallback((u,p)=>{if(t.history.position!==null)return;p.setCurrentInput(u),E.debug("[useCommandParser][handleInputChange] newValue: ",u);const h=d();if(h.type==="argument"||o==="entering_argument"){const z=be(u);if(z.isQuoted)if(z.isComplete){if(!(h instanceof j))return;h.value=u.trim()||"",E.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",h),r.push(h),p.setCurrentInput(""),l("idle");return}else return;else if(z.isComplete){if(!(h instanceof j))return;h.value=u.trim()||"",E.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",h),r.push(h),p.setCurrentInput(""),l("idle");return}else return}if(u.endsWith(" ")){const z=u.trim().toLowerCase(),M=e.getCompletions(r.path()).filter(x=>x.type==="word"&&x.name.toLowerCase()===z);if(M.length===1){r.push(M[0]),p.setCurrentInput(""),l("idle");return}}const S=v(u);if(S.type==="word"){E.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",S),r.push(S),p.setCurrentInput(""),l("idle");return}},[v,t,d,o,r,e]),f=s.useCallback(u=>{u.setCurrentInput(""),u.setIsEnteringArg(!1),r.clear(),l("idle")},[r]),k=s.useCallback((u,p,h)=>{if(!(u.key==="Backspace"||u.key==="Enter"||u.key==="ArrowUp"||u.key==="ArrowDown"||u.key==="ArrowLeft"||u.key==="ArrowRight"||u.key==="Escape"||u.key==="Delete"||u.key==="Home"||u.key==="End"||u.key.length===1))return!0;const{currentInput:S,isEnteringArg:z}=p,M=be(S);switch(u.key){case"Backspace":return S===""&&(u.preventDefault(),r.size()>0&&r.pop(),l("idle")),!0;case"Enter":{if(u.preventDefault(),M.isQuoted&&!M.isComplete)return!0;if(o==="entering_argument"||z&&S.trim()){const P=d();P instanceof j&&(P.value=S,E.debug("[handleKeyDown][Enter]['entering_argument'] pushing: ",P),r.push(P))}const x=r.path(),_=e.getCommand(x);if(!_)return!1;const F=_.segments.filter(P=>P.type==="argument"),K=r.arguments;return F.length>K.length?!1:(E.debug("[handleKeyDown][Enter] calling actions.executeCommand. segmentStack: ",r),h.executeCommand(),n.addStoredCommand(r.toArray()),f(h),!0)}case"ArrowUp":return u.preventDefault(),(async()=>{const x=await n.navigateHistory("up");return x.segments&&(r.clear(),r.pushAll(x.segments),h.setCurrentInput("")),!0})();case"ArrowDown":return u.preventDefault(),(async()=>{const x=await n.navigateHistory("down");return x.segments&&(r.clear(),r.pushAll(x.segments),h.setCurrentInput("")),!0})();default:{if(!z&&u.key.length===1){const x=S+u.key;if(!b(x))return u.preventDefault(),!1}return!0}}},[o,b,d,n,f,e,r]);return{handleInputChange:y,handleKeyDown:k,inputState:o,setInputStateWithLogging:l,findMatchingCommands:m,getAutocompleteSuggestion:w,getAvailableNodes:i,getNextExpectedSegment:d,isValidCommandInput:b}};function be(t){const e=[];let n="",r=!1,o;for(let a=0;a<t.length;a++){const l=t[a];(l==='"'||l==="'")&&(!r||l===o)?r?(e.push(n),n="",r=!1,o=void 0):(n&&(e.push(n),n=""),r=!0,o=l):!r&&l===" "?n&&(e.push(n),n=""):n+=l}return{words:e,currentWord:n,isQuoted:r,quoteChar:o,isComplete:!r&&!n}}const We=()=>{const t=q(),[e,n]=s.useState(0);return s.useEffect(()=>{const r={update:()=>{n(o=>o+1)}};return t.subscribe(r),()=>{t.unsubscribe(r)}},[t]),e},Be=({state:t,actions:e})=>{const n=s.useRef(null),r=B(),o=q(),{handleKeyDown:a,handleInputChange:l,inputState:d,setInputStateWithLogging:i,getNextExpectedSegment:m}=Ke(),[w,b]=s.useState(!1),v=H(),y=We(),f=s.useMemo(()=>V(v.fontFamily,v.fontSize),[v.fontFamily,v.fontSize]),k=async x=>{const _=a(x,t,e);await Promise.resolve(_)===!1&&(b(!0),setTimeout(()=>b(!1),500))},u=x=>{l(x.target.value,e)},p=x=>{x.preventDefault();const _=x.clipboardData.getData("text");l(_,e)};s.useEffect(()=>{n.current&&n.current.focus(),d!=="entering_command"&&i("entering_command")},[d,i]),s.useEffect(()=>{if(d!=="idle")return;const x=m();let _="idle";switch(x.type){case"word":_="entering_command",e.setIsEnteringArg(!1);break;case"argument":_="entering_argument",e.setIsEnteringArg(!0);break}i(_)},[y,d,m,i,e]);const h=s.useMemo(()=>{const x=[],_=o.toArray().map((F,K)=>{x.push(F.name);const P=r.hasNextSegment(x);if(F.type==="argument"){const ne=F;return c.jsxs(s.Fragment,{children:[c.jsx("span",{className:"text-gray-200 whitespace-pre",children:ne.value}),K<o.size()&&P&&c.jsx("span",{className:"text-gray-200 whitespace-pre",children:" "})]},"arg-"+ne.name+ne.value)}return c.jsxs(s.Fragment,{children:[c.jsx("span",{className:"text-blue-400 whitespace-pre",children:F.name}),K<o.size()&&P&&c.jsx("span",{className:"text-blue-400 whitespace-pre",children:" "})]},"word-"+F.name)});return[c.jsx("div",{className:"flex items-center gap-1","data-testid":"user-input-area",children:_},y)]},[y,r,o]),[I,S]=s.useState("");s.useEffect(()=>{const x=m();x.type==="argument"?S(x.name):S("")},[y,m]);const z=!t.isEnteringArg,M=t.currentInput.length;return c.jsxs("div",{className:"flex flex-col w-full bg-gray-900 rounded-lg p-4",children:[c.jsx("style",{children:`
7
- @keyframes subtleGlow {
8
- 0%, 100% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
9
- 50% { box-shadow: 0 0 8px rgba(239, 68, 68, 0.6); }
10
- }
11
- .invalid-input-animation {
12
- animation: subtleGlow 0.4s ease-in-out;
13
- }
14
- `}),c.jsxs("div",{className:`flex items-center gap-2 ${f.className??""}`.trim(),style:f.style,children:[c.jsx("div",{className:"text-gray-400",children:">"}),c.jsxs("div",{className:"flex-1 flex items-center",children:[h,c.jsxs("div",{className:"relative flex-1",children:[c.jsx("input",{ref:n,type:"text",role:"textbox",value:t.currentInput,onChange:u,onKeyDown:k,onPaste:p,"data-testid":"citadel-command-input",className:`w-full bg-transparent outline-none caret-transparent ${z?"text-blue-400":"text-gray-200"} ${w?"invalid-input-animation":""}`,spellCheck:!1,autoComplete:"off",placeholder:I}),c.jsx("div",{className:"absolute top-0 pointer-events-none",style:{left:`${M}ch`,transition:"left 0.05s ease-out"},children:c.jsx($e,{style:{type:v.cursorType??N.cursorType,color:v.cursorColor||N.cursorColor,speed:v.cursorSpeed||N.cursorSpeed}})})]})]})]})]})},Ye=({currentInput:t=""})=>{const e=B(),n=H(),r=q(),o=s.useMemo(()=>V(n.fontFamily,n.fontSize),[n.fontFamily,n.fontSize]),a="mt-2 border-t border-gray-700 px-4 py-2",l=`text-gray-300 ${o.className??""}`.trim(),d=t.trim().toLowerCase(),i=e.getMatchingCompletions(r.path(),d);E.debug("[AvailableCommands] nextCommandSegments: ",i);const m=s.useMemo(()=>{const y=[...i],f=h=>h.name.toLowerCase()==="help",k=y.filter(f);return[...y.filter(h=>!f(h)).sort((h,I)=>h.name.localeCompare(I.name,void 0,{sensitivity:"base"})),...k]},[i]),w=s.useMemo(()=>{const y=new Map;for(const f of m){const k=m.reduce((u,p)=>{if(p===f)return u;let h=0;for(;h<f.name.length&&h<p.name.length&&f.name[h].toLowerCase()===p.name[h].toLowerCase();)h++;return Math.max(u,h+1)},1);y.set(f.name,k)}return y},[m]),b=i.some(y=>y.type==="argument"),v=i[0];return c.jsx("div",{className:a,"data-testid":"available-commands",children:c.jsx("div",{className:l,style:o.style,children:b?i.length>0?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-blue-400",children:v.name}),v.description&&c.jsxs("span",{className:"text-gray-400 ml-2",children:["- ",v.description]})]}):null:c.jsx("div",{className:"flex flex-wrap gap-2",children:m==null?void 0:m.map(y=>{const f=w.get(y.name)??1;return c.jsx("div",{"data-testid":"available-command-chip",className:"px-2 py-1 rounded bg-gray-800 mr-2 last:mr-0",children:c.jsxs("span",{className:"text-white",children:[c.jsx("strong",{className:"underline",children:y.name.slice(0,f)}),y.name.slice(f)]})},y.name)})})})})},ye=({state:t,actions:e,outputRef:n})=>{const o=H().displayMode==="inline";return c.jsxs("div",{className:"innerContainer",children:[c.jsx("div",{className:"flex-1 min-h-0 pt-3 px-4","data-testid":"citadel-output-pane",style:o?{overflow:"hidden"}:void 0,children:c.jsx(Oe,{output:t.output,outputRef:n})}),c.jsxs("div",{className:"shrink-0",children:[c.jsx(Be,{state:t,actions:e}),c.jsx(Ye,{currentInput:t.isEnteringArg?"":t.currentInput})]})]})},Ve=()=>{const[t,e]=s.useState(!1),[n,r]=s.useState(!1),o=H(),[a,l]=s.useState(()=>o.initialHeight||null),d=s.useRef(null),i=s.useRef(null),m=s.useRef(!1),w=s.useRef(0),b=s.useRef(0),{state:v,actions:y}=R();Te({onOpen:()=>e(!0),onClose:()=>r(!0),isVisible:t,showCitadelKey:o.showCitadelKey||"."});const f=s.useCallback(h=>{var M;if(!m.current)return;const I=h.clientY-w.current,S=(M=o.maxHeight)!=null&&M.endsWith("vh")?window.innerHeight*parseInt(o.maxHeight,10)/100:parseInt(o.maxHeight||"80vh",10),z=Math.min(Math.max(b.current-I,parseInt(o.minHeight||"200",10)),S);i.current&&(i.current.style.height=`${z}px`,i.current.style.bottom="0",l(`${z}px`))},[o.maxHeight,o.minHeight]),k=s.useCallback(()=>{m.current=!1,document.documentElement.style.userSelect="",document.documentElement.style.webkitUserSelect="",document.documentElement.style.mozUserSelect="",document.documentElement.style.msUserSelect="",document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",k)},[f]),u=s.useCallback(h=>{i.current&&(m.current=!0,w.current=h.clientY,b.current=i.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",f),document.addEventListener("mouseup",k))},[f,k]);s.useEffect(()=>()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",k)},[f,k]);const p=s.useCallback(()=>{n&&(e(!1),r(!1))},[n]);return Fe({isVisible:t,isClosing:n,onAnimationComplete:p}),t?c.jsxs("div",{ref:i,className:`panelContainer ${t?"citadel_slideUp":""} ${n?"citadel_slideDown":""}`,style:{...a?{height:a}:void 0,maxHeight:o.maxHeight},children:[c.jsx("div",{className:"resizeHandle",onMouseDown:u}),c.jsx(ye,{state:v,actions:y,outputRef:d})]}):null},ee=t=>{if(!t)return;const e=t.trim();if(e)return/^\d+(\.\d+)?$/.test(e)?`${e}px`:e},Ge=()=>{const{state:t,actions:e}=R(),n=H(),r=s.useRef(null);return c.jsx("div",{className:"inlineContainer","data-testid":"citadel-inline-container",style:{height:ee(n.initialHeight),maxHeight:ee(n.maxHeight),minHeight:ee(n.minHeight)},children:c.jsx(ye,{state:t,actions:e,outputRef:r})})},xe=`:host {
15
- --citadel-bg: rgb(17, 24, 39);
16
- --citadel-text: rgba(255, 255, 255, 0.87);
17
- --citadel-border: rgb(55, 65, 81);
18
- --citadel-accent: #646cff;
19
- --citadel-accent-hover: #535bf2;
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);
20
17
  --citadel-min-height: 200px;
21
18
  --citadel-max-height: 80vh;
22
19
  --citadel-default-height: 35vh;
23
- --citadel-error: rgb(239, 68, 68);
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
24
 
25
25
  display: block;
26
26
  pointer-events: auto;
27
+ color: var(--citadel-text);
27
28
  font-synthesis: none;
28
29
  text-rendering: optimizeLegibility;
29
30
  -webkit-font-smoothing: antialiased;
30
31
  -moz-osx-font-smoothing: grayscale;
31
32
  }
32
33
 
33
- :host([data-display-mode="panel"]) {
34
+ :host([data-display-mode='panel']) {
34
35
  position: fixed;
35
36
  bottom: 0;
36
37
  left: 0;
@@ -39,11 +40,11 @@ Check the definition of the ${i.join(".")} command and update the return type fo
39
40
  height: var(--citadel-default-height);
40
41
  max-height: var(--citadel-max-height);
41
42
  min-height: var(--citadel-min-height);
42
- z-index: 2147483647; /* Maximum z-index value */
43
+ z-index: 2147483647;
43
44
  overflow: hidden;
44
45
  }
45
46
 
46
- :host([data-display-mode="inline"]) {
47
+ :host([data-display-mode='inline']) {
47
48
  position: relative;
48
49
  bottom: auto;
49
50
  left: auto;
@@ -56,135 +57,110 @@ Check the definition of the ${i.join(".")} command and update the return type fo
56
57
  overflow: hidden;
57
58
  }
58
59
 
59
- button {
60
- border-radius: 8px;
61
- border: 1px solid transparent;
62
- padding: 0.6em 1.2em;
63
- font-size: 1em;
64
- font-weight: 500;
65
- font-family: inherit;
66
- background-color: #1a1a1a;
67
- cursor: pointer;
68
- transition: border-color 0.25s;
69
- }
70
-
71
- button:hover {
72
- border-color: var(--citadel-accent);
73
- }
74
-
75
- button:focus,
76
- button:focus-visible {
77
- outline: 4px auto -webkit-focus-ring-color;
78
- }
79
-
80
- a {
81
- font-weight: 500;
82
- color: var(--citadel-accent);
83
- text-decoration: inherit;
84
- }
85
-
86
- a:hover {
87
- color: var(--citadel-accent-hover);
88
- }
89
-
90
- .flex-1 { flex: 1 1 0%; }
91
- .flex-shrink-0 { flex-shrink: 0; }
92
- .min-h-0 { min-height: 0px; }
93
- .pt-3 { padding-top: 0.75rem; }
94
- .px-4 { padding-left: 1rem; padding-right: 1rem; }
95
-
96
- .h-full {
60
+ #citadel-root {
61
+ width: 100%;
97
62
  height: 100%;
98
63
  }
99
- .overflow-y-auto {
100
- overflow-y: auto;
101
- }
102
- .border {
103
- border-width: 1px;
104
- }
105
- .border-gray-700 {
106
- --tw-border-opacity: 1;
107
- border-color: rgb(55 65 81 / var(--tw-border-opacity, 1));
108
- }
109
- .rounded-lg {
110
- border-radius: 0.5rem;
111
- }
112
- .p-3 {
113
- padding: 0.75rem;
114
- }
115
- .text-left {
116
- text-align: left;
64
+
65
+ #citadel-root,
66
+ #citadel-root * {
67
+ box-sizing: border-box;
117
68
  }
118
- `,Ce=`/* Keep only component-specific styles here */
119
69
 
120
70
  .panelContainer {
121
71
  position: fixed;
72
+ bottom: 0;
73
+ left: 0;
74
+ right: 0;
75
+ width: 100%;
122
76
  height: var(--citadel-default-height);
123
77
  min-height: var(--citadel-min-height);
124
78
  max-height: var(--citadel-max-height);
125
- background-color: var(--citadel-bg);
126
- overflow: hidden;
127
- width: 100%;
128
- box-sizing: border-box;
129
79
  margin: 0;
130
80
  padding: 0;
131
- bottom: 0;
132
- left: 0;
133
- right: 0;
81
+ background-color: var(--citadel-bg);
82
+ overflow: hidden;
83
+ transform: translateY(0);
84
+ will-change: transform;
134
85
  }
135
86
 
136
87
  .innerContainer {
137
- height: 100%;
138
- flex: 1;
139
88
  width: 100%;
140
- display: flex;
141
- flex-direction: column;
89
+ height: 100%;
142
90
  margin: 0;
143
91
  padding: 0;
92
+ display: flex;
93
+ flex: 1;
94
+ flex-direction: column;
144
95
  }
145
96
 
146
- .inputSection {
147
- border-top: 1px solid var(--citadel-border);
148
- padding: 1rem;
149
- margin: 0;
150
- box-sizing: border-box;
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;
151
110
  }
152
111
 
153
112
  .resizeHandle {
154
- width: 100%;
155
- height: 6px;
156
- background: transparent;
157
- cursor: ns-resize;
158
113
  position: absolute;
159
114
  top: -3px;
160
115
  left: 0;
161
116
  right: 0;
162
117
  z-index: 10;
118
+ width: 100%;
119
+ height: 6px;
120
+ background: transparent;
121
+ cursor: ns-resize;
163
122
  user-select: none;
164
123
  -webkit-user-select: none;
165
124
  pointer-events: all;
166
125
  }
167
126
 
168
127
  .resizeHandle:hover {
169
- background: rgba(255, 255, 255, 0.1);
128
+ background: color-mix(in oklch, var(--citadel-text) 10%, transparent);
170
129
  }
171
130
 
172
131
  @keyframes citadel_slideUp {
173
- from { transform: translateY(100%); }
174
- to { transform: translateY(0); }
132
+ from {
133
+ transform: translateY(100%);
134
+ }
135
+
136
+ to {
137
+ transform: translateY(0);
138
+ }
175
139
  }
176
140
 
177
141
  @keyframes citadel_slideDown {
178
- from { transform: translateY(0); }
179
- to { transform: translateY(100%); }
142
+ from {
143
+ transform: translateY(0);
144
+ }
145
+
146
+ to {
147
+ transform: translateY(100%);
148
+ }
180
149
  }
181
150
 
182
151
  .citadel_slideUp {
183
- animation: citadel_slideUp 0.2s ease-out forwards;
152
+ animation: citadel_slideUp var(--citadel-panel-enter-duration) var(--citadel-panel-enter-easing) forwards;
184
153
  }
185
154
 
186
155
  .citadel_slideDown {
187
- animation: citadel_slideDown 0.2s ease-out forwards;
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
+ }
188
164
  }
189
165
 
190
166
  .inlineContainer {
@@ -195,827 +171,309 @@ a:hover {
195
171
  flex-direction: column;
196
172
  background-color: var(--citadel-bg);
197
173
  overflow: hidden;
198
- box-sizing: border-box;
199
- }
200
- `,ve=`@tailwind base;
201
- @tailwind components;
202
- @tailwind utilities;
203
- `,Je=`*, ::before, ::after {
204
- --tw-border-spacing-x: 0;
205
- --tw-border-spacing-y: 0;
206
- --tw-translate-x: 0;
207
- --tw-translate-y: 0;
208
- --tw-rotate: 0;
209
- --tw-skew-x: 0;
210
- --tw-skew-y: 0;
211
- --tw-scale-x: 1;
212
- --tw-scale-y: 1;
213
- --tw-pan-x: ;
214
- --tw-pan-y: ;
215
- --tw-pinch-zoom: ;
216
- --tw-scroll-snap-strictness: proximity;
217
- --tw-gradient-from-position: ;
218
- --tw-gradient-via-position: ;
219
- --tw-gradient-to-position: ;
220
- --tw-ordinal: ;
221
- --tw-slashed-zero: ;
222
- --tw-numeric-figure: ;
223
- --tw-numeric-spacing: ;
224
- --tw-numeric-fraction: ;
225
- --tw-ring-inset: ;
226
- --tw-ring-offset-width: 0px;
227
- --tw-ring-offset-color: #fff;
228
- --tw-ring-color: rgb(59 130 246 / 0.5);
229
- --tw-ring-offset-shadow: 0 0 #0000;
230
- --tw-ring-shadow: 0 0 #0000;
231
- --tw-shadow: 0 0 #0000;
232
- --tw-shadow-colored: 0 0 #0000;
233
- --tw-blur: ;
234
- --tw-brightness: ;
235
- --tw-contrast: ;
236
- --tw-grayscale: ;
237
- --tw-hue-rotate: ;
238
- --tw-invert: ;
239
- --tw-saturate: ;
240
- --tw-sepia: ;
241
- --tw-drop-shadow: ;
242
- --tw-backdrop-blur: ;
243
- --tw-backdrop-brightness: ;
244
- --tw-backdrop-contrast: ;
245
- --tw-backdrop-grayscale: ;
246
- --tw-backdrop-hue-rotate: ;
247
- --tw-backdrop-invert: ;
248
- --tw-backdrop-opacity: ;
249
- --tw-backdrop-saturate: ;
250
- --tw-backdrop-sepia: ;
251
- --tw-contain-size: ;
252
- --tw-contain-layout: ;
253
- --tw-contain-paint: ;
254
- --tw-contain-style: ;
255
- }
256
-
257
- ::backdrop {
258
- --tw-border-spacing-x: 0;
259
- --tw-border-spacing-y: 0;
260
- --tw-translate-x: 0;
261
- --tw-translate-y: 0;
262
- --tw-rotate: 0;
263
- --tw-skew-x: 0;
264
- --tw-skew-y: 0;
265
- --tw-scale-x: 1;
266
- --tw-scale-y: 1;
267
- --tw-pan-x: ;
268
- --tw-pan-y: ;
269
- --tw-pinch-zoom: ;
270
- --tw-scroll-snap-strictness: proximity;
271
- --tw-gradient-from-position: ;
272
- --tw-gradient-via-position: ;
273
- --tw-gradient-to-position: ;
274
- --tw-ordinal: ;
275
- --tw-slashed-zero: ;
276
- --tw-numeric-figure: ;
277
- --tw-numeric-spacing: ;
278
- --tw-numeric-fraction: ;
279
- --tw-ring-inset: ;
280
- --tw-ring-offset-width: 0px;
281
- --tw-ring-offset-color: #fff;
282
- --tw-ring-color: rgb(59 130 246 / 0.5);
283
- --tw-ring-offset-shadow: 0 0 #0000;
284
- --tw-ring-shadow: 0 0 #0000;
285
- --tw-shadow: 0 0 #0000;
286
- --tw-shadow-colored: 0 0 #0000;
287
- --tw-blur: ;
288
- --tw-brightness: ;
289
- --tw-contrast: ;
290
- --tw-grayscale: ;
291
- --tw-hue-rotate: ;
292
- --tw-invert: ;
293
- --tw-saturate: ;
294
- --tw-sepia: ;
295
- --tw-drop-shadow: ;
296
- --tw-backdrop-blur: ;
297
- --tw-backdrop-brightness: ;
298
- --tw-backdrop-contrast: ;
299
- --tw-backdrop-grayscale: ;
300
- --tw-backdrop-hue-rotate: ;
301
- --tw-backdrop-invert: ;
302
- --tw-backdrop-opacity: ;
303
- --tw-backdrop-saturate: ;
304
- --tw-backdrop-sepia: ;
305
- --tw-contain-size: ;
306
- --tw-contain-layout: ;
307
- --tw-contain-paint: ;
308
- --tw-contain-style: ;
309
- }/*
310
- ! tailwindcss v3.4.15 | MIT License | https://tailwindcss.com
311
- *//*
312
- 1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
313
- 2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
314
- */
315
-
316
- *,
317
- ::before,
318
- ::after {
319
- box-sizing: border-box; /* 1 */
320
- border-width: 0; /* 2 */
321
- border-style: solid; /* 2 */
322
- border-color: #e5e7eb; /* 2 */
323
- }
324
-
325
- ::before,
326
- ::after {
327
- --tw-content: '';
328
- }
329
-
330
- /*
331
- 1. Use a consistent sensible line-height in all browsers.
332
- 2. Prevent adjustments of font size after orientation changes in iOS.
333
- 3. Use a more readable tab size.
334
- 4. Use the user's configured \`sans\` font-family by default.
335
- 5. Use the user's configured \`sans\` font-feature-settings by default.
336
- 6. Use the user's configured \`sans\` font-variation-settings by default.
337
- 7. Disable tap highlights on iOS
338
- */
339
-
340
- html,
341
- :host {
342
- line-height: 1.5; /* 1 */
343
- -webkit-text-size-adjust: 100%; /* 2 */
344
- -moz-tab-size: 4; /* 3 */
345
- -o-tab-size: 4;
346
- tab-size: 4; /* 3 */
347
- font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; /* 4 */
348
- font-feature-settings: normal; /* 5 */
349
- font-variation-settings: normal; /* 6 */
350
- -webkit-tap-highlight-color: transparent; /* 7 */
351
- }
352
-
353
- /*
354
- 1. Remove the margin in all browsers.
355
- 2. Inherit line-height from \`html\` so users can set them as a class directly on the \`html\` element.
356
- */
357
-
358
- body {
359
- margin: 0; /* 1 */
360
- line-height: inherit; /* 2 */
361
- }
362
-
363
- /*
364
- 1. Add the correct height in Firefox.
365
- 2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
366
- 3. Ensure horizontal rules are visible by default.
367
- */
368
-
369
- hr {
370
- height: 0; /* 1 */
371
- color: inherit; /* 2 */
372
- border-top-width: 1px; /* 3 */
373
- }
374
-
375
- /*
376
- Add the correct text decoration in Chrome, Edge, and Safari.
377
- */
378
-
379
- abbr:where([title]) {
380
- -webkit-text-decoration: underline dotted;
381
- text-decoration: underline dotted;
382
- }
383
-
384
- /*
385
- Remove the default font size and weight for headings.
386
- */
387
-
388
- h1,
389
- h2,
390
- h3,
391
- h4,
392
- h5,
393
- h6 {
394
- font-size: inherit;
395
- font-weight: inherit;
396
- }
397
-
398
- /*
399
- Reset links to optimize for opt-in styling instead of opt-out.
400
- */
401
-
402
- a {
403
- color: inherit;
404
- text-decoration: inherit;
405
- }
406
-
407
- /*
408
- Add the correct font weight in Edge and Safari.
409
- */
410
-
411
- b,
412
- strong {
413
- font-weight: bolder;
414
174
  }
415
175
 
416
- /*
417
- 1. Use the user's configured \`mono\` font-family by default.
418
- 2. Use the user's configured \`mono\` font-feature-settings by default.
419
- 3. Use the user's configured \`mono\` font-variation-settings by default.
420
- 4. Correct the odd \`em\` font sizing in all browsers.
421
- */
422
-
423
- code,
424
- kbd,
425
- samp,
426
- pre {
427
- font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; /* 1 */
428
- font-feature-settings: normal; /* 2 */
429
- font-variation-settings: normal; /* 3 */
430
- font-size: 1em; /* 4 */
431
- }
432
-
433
- /*
434
- Add the correct font size in all browsers.
435
- */
436
-
437
- small {
438
- font-size: 80%;
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;
439
185
  }
440
186
 
441
- /*
442
- Prevent \`sub\` and \`sup\` elements from affecting the line height in all browsers.
443
- */
444
-
445
- sub,
446
- sup {
447
- font-size: 75%;
448
- line-height: 0;
449
- position: relative;
450
- vertical-align: baseline;
187
+ .citadel-output-item {
188
+ margin-bottom: 1rem;
451
189
  }
452
190
 
453
- sub {
454
- bottom: -0.25em;
191
+ .citadel-output-item:last-child {
192
+ margin-bottom: 0;
455
193
  }
456
194
 
457
- sup {
458
- top: -0.5em;
195
+ .citadel-output-content {
196
+ margin-top: 0.35rem;
197
+ color: var(--citadel-text);
459
198
  }
460
199
 
461
- /*
462
- 1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
463
- 2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
464
- 3. Remove gaps between table borders by default.
465
- */
466
-
467
- table {
468
- text-indent: 0; /* 1 */
469
- border-color: inherit; /* 2 */
470
- border-collapse: collapse; /* 3 */
200
+ .citadel-output-content > :first-child {
201
+ margin-top: 0;
471
202
  }
472
203
 
473
- /*
474
- 1. Change the font styles in all browsers.
475
- 2. Remove the margin in Firefox and Safari.
476
- 3. Remove default padding in all browsers.
477
- */
478
-
479
- button,
480
- input,
481
- optgroup,
482
- select,
483
- textarea {
484
- font-family: inherit; /* 1 */
485
- font-feature-settings: inherit; /* 1 */
486
- font-variation-settings: inherit; /* 1 */
487
- font-size: 100%; /* 1 */
488
- font-weight: inherit; /* 1 */
489
- line-height: inherit; /* 1 */
490
- letter-spacing: inherit; /* 1 */
491
- color: inherit; /* 1 */
492
- margin: 0; /* 2 */
493
- padding: 0; /* 3 */
204
+ .citadel-output-content > :last-child {
205
+ margin-bottom: 0;
494
206
  }
495
207
 
496
- /*
497
- Remove the inheritance of text transform in Edge and Firefox.
498
- */
499
-
500
- button,
501
- select {
502
- text-transform: none;
208
+ .citadel-output-line {
209
+ display: flex;
210
+ flex-wrap: wrap;
211
+ align-items: center;
212
+ gap: 0.5rem;
503
213
  }
504
214
 
505
- /*
506
- 1. Correct the inability to style clickable types in iOS and Safari.
507
- 2. Remove default button styles.
508
- */
509
-
510
- button,
511
- input:where([type='button']),
512
- input:where([type='reset']),
513
- input:where([type='submit']) {
514
- -webkit-appearance: button; /* 1 */
515
- background-color: transparent; /* 2 */
516
- background-image: none; /* 2 */
215
+ .citadel-output-command,
216
+ .citadel-output-command-word {
217
+ color: var(--citadel-text);
517
218
  }
518
219
 
519
- /*
520
- Use the modern Firefox focus style for all focusable elements.
521
- */
522
-
523
- :-moz-focusring {
524
- outline: auto;
220
+ .citadel-output-command-arg {
221
+ color: var(--citadel-arg);
525
222
  }
526
223
 
527
- /*
528
- Remove the additional \`:invalid\` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737)
529
- */
224
+ .citadel-output-separator {
225
+ color: var(--citadel-muted);
226
+ }
530
227
 
531
- :-moz-ui-invalid {
532
- box-shadow: none;
228
+ .citadel-output-timestamp {
229
+ color: var(--citadel-subtle);
533
230
  }
534
231
 
535
- /*
536
- Add the correct vertical alignment in Chrome and Firefox.
537
- */
232
+ .citadel-status-dot {
233
+ width: 1rem;
234
+ height: 1rem;
235
+ border-radius: 999px;
236
+ }
538
237
 
539
- progress {
540
- vertical-align: baseline;
238
+ .citadel-status-dot-success {
239
+ background: var(--citadel-success);
541
240
  }
542
241
 
543
- /*
544
- Correct the cursor style of increment and decrement buttons in Safari.
545
- */
242
+ .citadel-status-dot-failure {
243
+ background: var(--citadel-error);
244
+ }
546
245
 
547
- ::-webkit-inner-spin-button,
548
- ::-webkit-outer-spin-button {
549
- height: auto;
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;
550
253
  }
551
254
 
552
- /*
553
- 1. Correct the odd appearance in Chrome and Safari.
554
- 2. Correct the outline style in Safari.
555
- */
255
+ @keyframes citadel-spin {
256
+ to {
257
+ transform: rotate(360deg);
258
+ }
259
+ }
556
260
 
557
- [type='search'] {
558
- -webkit-appearance: textfield; /* 1 */
559
- outline-offset: -2px; /* 2 */
261
+ .citadel-input-shell {
262
+ width: 100%;
263
+ padding: 1rem;
264
+ border-radius: 0.5rem;
265
+ background-color: var(--citadel-bg);
560
266
  }
561
267
 
562
- /*
563
- Remove the inner padding in Chrome and Safari on macOS.
564
- */
268
+ .citadel-input-line {
269
+ display: flex;
270
+ align-items: center;
271
+ gap: 0.5rem;
272
+ }
565
273
 
566
- ::-webkit-search-decoration {
567
- -webkit-appearance: none;
274
+ .citadel-input-prompt {
275
+ color: var(--citadel-muted);
568
276
  }
569
277
 
570
- /*
571
- 1. Correct the inability to style clickable types in iOS and Safari.
572
- 2. Change font properties to \`inherit\` in Safari.
573
- */
278
+ .citadel-input-row {
279
+ display: flex;
280
+ align-items: center;
281
+ flex: 1 1 auto;
282
+ min-width: 0;
283
+ }
574
284
 
575
- ::-webkit-file-upload-button {
576
- -webkit-appearance: button; /* 1 */
577
- font: inherit; /* 2 */
285
+ .citadel-input-segments {
286
+ display: flex;
287
+ align-items: center;
288
+ gap: 0.25rem;
578
289
  }
579
290
 
580
- /*
581
- Add the correct display in Chrome and Safari.
582
- */
291
+ .citadel-input-segment-arg {
292
+ color: var(--citadel-text);
293
+ white-space: pre;
294
+ }
583
295
 
584
- summary {
585
- display: list-item;
296
+ .citadel-input-segment-word {
297
+ color: var(--citadel-word);
298
+ white-space: pre;
586
299
  }
587
300
 
588
- /*
589
- Removes the default spacing and border for appropriate elements.
590
- */
301
+ .citadel-input-segment-space {
302
+ color: var(--citadel-text);
303
+ white-space: pre;
304
+ }
591
305
 
592
- blockquote,
593
- dl,
594
- dd,
595
- h1,
596
- h2,
597
- h3,
598
- h4,
599
- h5,
600
- h6,
601
- hr,
602
- figure,
603
- p,
604
- pre {
605
- margin: 0;
306
+ .citadel-input-segment-space-command {
307
+ color: var(--citadel-word);
606
308
  }
607
309
 
608
- fieldset {
609
- margin: 0;
610
- padding: 0;
310
+ .citadel-input-control {
311
+ position: relative;
312
+ flex: 1 1 auto;
313
+ min-width: 0;
611
314
  }
612
315
 
613
- legend {
614
- padding: 0;
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;
615
325
  }
616
326
 
617
- ol,
618
- ul,
619
- menu {
620
- list-style: none;
327
+ .citadel-input-field {
328
+ width: 100%;
621
329
  margin: 0;
622
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;
623
341
  }
624
342
 
625
- /*
626
- Reset default styling for dialogs.
627
- */
628
- dialog {
629
- padding: 0;
343
+ .citadel-input-field::placeholder {
344
+ color: var(--citadel-subtle);
345
+ opacity: 1;
630
346
  }
631
347
 
632
- /*
633
- Prevent resizing textareas horizontally by default.
634
- */
635
-
636
- textarea {
637
- resize: vertical;
348
+ .citadel-input-field.is-command-mode {
349
+ color: var(--citadel-word);
638
350
  }
639
351
 
640
- /*
641
- 1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300)
642
- 2. Set the default placeholder color to the user's configured gray 400 color.
643
- */
644
-
645
- input::-moz-placeholder, textarea::-moz-placeholder {
646
- opacity: 1; /* 1 */
647
- color: #9ca3af; /* 2 */
352
+ .citadel-input-field.is-argument-mode {
353
+ color: var(--citadel-text);
648
354
  }
649
355
 
650
- input::placeholder,
651
- textarea::placeholder {
652
- opacity: 1; /* 1 */
653
- color: #9ca3af; /* 2 */
356
+ .citadel-input-cursor {
357
+ position: absolute;
358
+ top: 0;
359
+ pointer-events: none;
654
360
  }
655
361
 
656
- /*
657
- Set the default cursor for buttons.
658
- */
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
+ }
659
367
 
660
- button,
661
- [role="button"] {
662
- cursor: pointer;
368
+ 50% {
369
+ box-shadow: 0 0 8px color-mix(in oklch, var(--citadel-error) 70%, transparent);
370
+ }
663
371
  }
664
372
 
665
- /*
666
- Make sure disabled buttons don't get the pointer cursor.
667
- */
668
- :disabled {
669
- cursor: default;
373
+ .invalid-input-animation {
374
+ animation: citadel-invalid-glow 0.4s ease-in-out;
670
375
  }
671
376
 
672
- /*
673
- 1. Make replaced elements \`display: block\` by default. (https://github.com/mozdevs/cssremedy/issues/14)
674
- 2. Add \`vertical-align: middle\` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
675
- This can trigger a poorly considered lint error in some tools but is included by design.
676
- */
377
+ .citadel-cursor-wrapper {
378
+ position: relative;
379
+ display: inline-block;
380
+ }
677
381
 
678
- img,
679
- svg,
680
- video,
681
- canvas,
682
- audio,
683
- iframe,
684
- embed,
685
- object {
686
- display: block; /* 1 */
687
- vertical-align: middle; /* 2 */
382
+ .command-cursor {
383
+ display: inline-block;
384
+ white-space: pre;
688
385
  }
689
386
 
690
- /*
691
- Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14)
692
- */
387
+ @keyframes citadel-shake {
388
+ 0%,
389
+ 100% {
390
+ transform: translateX(0);
391
+ }
693
392
 
694
- img,
695
- video {
696
- max-width: 100%;
697
- height: auto;
698
- }
393
+ 25% {
394
+ transform: translateX(-4px);
395
+ }
699
396
 
700
- /* Make elements with the HTML hidden attribute stay hidden by default */
701
- [hidden]:where(:not([hidden="until-found"])) {
702
- display: none;
703
- }
704
- .container {
705
- width: 100%;
706
- }
707
- .pointer-events-none {
708
- pointer-events: none;
709
- }
710
- .visible {
711
- visibility: visible;
712
- }
713
- .static {
714
- position: static;
715
- }
716
- .fixed {
717
- position: fixed;
718
- }
719
- .absolute {
720
- position: absolute;
721
- }
722
- .relative {
723
- position: relative;
724
- }
725
- .top-0 {
726
- top: 0px;
727
- }
728
- .my-2 {
729
- margin-top: 0.5rem;
730
- margin-bottom: 0.5rem;
731
- }
732
- .mb-4 {
733
- margin-bottom: 1rem;
734
- }
735
- .ml-2 {
736
- margin-left: 0.5rem;
737
- }
738
- .mr-2 {
739
- margin-right: 0.5rem;
397
+ 75% {
398
+ transform: translateX(4px);
399
+ }
740
400
  }
741
- .mt-1 {
742
- margin-top: 0.25rem;
401
+
402
+ .animate-shake {
403
+ animation: citadel-shake 0.2s ease-in-out;
743
404
  }
744
- .mt-2 {
405
+
406
+ .citadel-available-commands {
745
407
  margin-top: 0.5rem;
408
+ padding: 0.5rem 1rem;
409
+ border-top: 1px solid var(--citadel-border);
746
410
  }
747
- .block {
748
- display: block;
749
- }
750
- .inline-block {
751
- display: inline-block;
752
- }
753
- .flex {
754
- display: flex;
755
- }
756
- .hidden {
757
- display: none;
758
- }
759
- .h-12 {
760
- height: 3rem;
761
- }
762
- .h-4 {
763
- height: 1rem;
764
- }
765
- .h-auto {
766
- height: auto;
767
- }
768
- .h-full {
769
- height: 100%;
770
- }
771
- .max-h-\\[300px\\] {
772
- max-height: 300px;
773
- }
774
- .min-h-0 {
775
- min-height: 0px;
776
- }
777
- .min-h-screen {
778
- min-height: 100vh;
779
- }
780
- .w-4 {
781
- width: 1rem;
782
- }
783
- .w-full {
784
- width: 100%;
785
- }
786
- .max-w-\\[400px\\] {
787
- max-width: 400px;
788
- }
789
- .flex-1 {
790
- flex: 1 1 0%;
791
- }
792
- .flex-shrink-0 {
793
- flex-shrink: 0;
794
- }
795
- .transform {
796
- transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
797
- }
798
- @keyframes spin {
799
411
 
800
- to {
801
- transform: rotate(360deg);
802
- }
412
+ .citadel-available-commands-content {
413
+ color: var(--citadel-muted);
803
414
  }
804
- .animate-spin {
805
- animation: spin 1s linear infinite;
806
- }
807
- .flex-col {
808
- flex-direction: column;
809
- }
810
- .flex-wrap {
415
+
416
+ .citadel-available-chip-list {
417
+ display: flex;
811
418
  flex-wrap: wrap;
812
- }
813
- .items-center {
814
- align-items: center;
815
- }
816
- .justify-center {
817
- justify-content: center;
818
- }
819
- .gap-2 {
820
419
  gap: 0.5rem;
821
420
  }
822
- .overflow-y-auto {
823
- overflow-y: auto;
824
- }
825
- .whitespace-pre {
826
- white-space: pre;
827
- }
828
- .rounded {
829
- border-radius: 0.25rem;
830
- }
831
- .rounded-full {
832
- border-radius: 9999px;
833
- }
834
- .rounded-lg {
835
- border-radius: 0.5rem;
836
- }
837
- .border {
838
- border-width: 1px;
839
- }
840
- .border-2 {
841
- border-width: 2px;
842
- }
843
- .border-t {
844
- border-top-width: 1px;
845
- }
846
- .border-gray-300 {
847
- --tw-border-opacity: 1;
848
- border-color: rgb(209 213 219 / var(--tw-border-opacity, 1));
849
- }
850
- .border-gray-700 {
851
- --tw-border-opacity: 1;
852
- border-color: rgb(55 65 81 / var(--tw-border-opacity, 1));
853
- }
854
- .border-t-gray-600 {
855
- --tw-border-opacity: 1;
856
- border-top-color: rgb(75 85 99 / var(--tw-border-opacity, 1));
857
- }
858
- .bg-gray-100 {
859
- --tw-bg-opacity: 1;
860
- background-color: rgb(243 244 246 / var(--tw-bg-opacity, 1));
861
- }
862
- .bg-gray-800 {
863
- --tw-bg-opacity: 1;
864
- background-color: rgb(31 41 55 / var(--tw-bg-opacity, 1));
865
- }
866
- .bg-gray-900 {
867
- --tw-bg-opacity: 1;
868
- background-color: rgb(17 24 39 / var(--tw-bg-opacity, 1));
869
- }
870
- .bg-green-500 {
871
- --tw-bg-opacity: 1;
872
- background-color: rgb(34 197 94 / var(--tw-bg-opacity, 1));
873
- }
874
- .bg-red-500 {
875
- --tw-bg-opacity: 1;
876
- background-color: rgb(239 68 68 / var(--tw-bg-opacity, 1));
877
- }
878
- .bg-transparent {
879
- background-color: transparent;
880
- }
881
- .bg-white {
882
- --tw-bg-opacity: 1;
883
- background-color: rgb(255 255 255 / var(--tw-bg-opacity, 1));
884
- }
885
- .object-contain {
886
- -o-object-fit: contain;
887
- object-fit: contain;
888
- }
889
- .p-3 {
890
- padding: 0.75rem;
891
- }
892
- .p-4 {
893
- padding: 1rem;
894
- }
895
- .p-6 {
896
- padding: 1.5rem;
897
- }
898
- .px-2 {
899
- padding-left: 0.5rem;
900
- padding-right: 0.5rem;
901
- }
902
- .px-4 {
903
- padding-left: 1rem;
904
- padding-right: 1rem;
905
- }
906
- .py-1 {
907
- padding-top: 0.25rem;
908
- padding-bottom: 0.25rem;
909
- }
910
- .pt-2 {
911
- padding-top: 0.5rem;
912
- }
913
- .pt-3 {
914
- padding-top: 0.75rem;
915
- }
916
- .text-left {
917
- text-align: left;
918
- }
919
- .font-mono {
920
- font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
921
- }
922
- .text-base {
923
- font-size: 1rem;
924
- line-height: 1.5rem;
925
- }
926
- .text-lg {
927
- font-size: 1.125rem;
928
- line-height: 1.75rem;
929
- }
930
- .text-sm {
931
- font-size: 0.875rem;
932
- line-height: 1.25rem;
933
- }
934
- .text-xs {
935
- font-size: 0.75rem;
936
- line-height: 1rem;
937
- }
938
- .text-blue-400 {
939
- --tw-text-opacity: 1;
940
- color: rgb(96 165 250 / var(--tw-text-opacity, 1));
941
- }
942
- .text-gray-200 {
943
- --tw-text-opacity: 1;
944
- color: rgb(229 231 235 / var(--tw-text-opacity, 1));
945
- }
946
- .text-gray-300 {
947
- --tw-text-opacity: 1;
948
- color: rgb(209 213 219 / var(--tw-text-opacity, 1));
949
- }
950
- .text-gray-400 {
951
- --tw-text-opacity: 1;
952
- color: rgb(156 163 175 / var(--tw-text-opacity, 1));
953
- }
954
- .text-gray-500 {
955
- --tw-text-opacity: 1;
956
- color: rgb(107 114 128 / var(--tw-text-opacity, 1));
957
- }
958
- .text-gray-700 {
959
- --tw-text-opacity: 1;
960
- color: rgb(55 65 81 / var(--tw-text-opacity, 1));
961
- }
962
- .text-green-500 {
963
- --tw-text-opacity: 1;
964
- color: rgb(34 197 94 / var(--tw-text-opacity, 1));
965
- }
966
- .text-red-400 {
967
- --tw-text-opacity: 1;
968
- color: rgb(248 113 113 / var(--tw-text-opacity, 1));
969
- }
970
- .text-red-500 {
971
- --tw-text-opacity: 1;
972
- color: rgb(239 68 68 / var(--tw-text-opacity, 1));
973
- }
974
- .text-white {
975
- --tw-text-opacity: 1;
976
- color: rgb(255 255 255 / var(--tw-text-opacity, 1));
421
+
422
+ .citadel-available-chip {
423
+ padding: 0.25rem 0.5rem;
424
+ border-radius: 0.375rem;
425
+ background: var(--citadel-surface);
977
426
  }
978
- .underline {
979
- text-decoration-line: underline;
427
+
428
+ .citadel-available-chip-text {
429
+ color: white;
980
430
  }
981
- .caret-transparent {
982
- caret-color: transparent;
431
+
432
+ .citadel-available-chip-prefix {
433
+ text-decoration: underline;
983
434
  }
984
- .shadow {
985
- --tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
986
- --tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);
987
- box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
435
+
436
+ .citadel-available-next-arg {
437
+ color: var(--citadel-word);
988
438
  }
989
- .shadow-lg {
990
- --tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
991
- --tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);
992
- box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
439
+
440
+ .citadel-available-next-desc {
441
+ margin-left: 0.5rem;
442
+ color: var(--citadel-muted);
993
443
  }
994
- .outline-none {
995
- outline: 2px solid transparent;
996
- outline-offset: 2px;
444
+
445
+ .citadel-result-json,
446
+ .citadel-result-text {
447
+ color: var(--citadel-text);
997
448
  }
998
- .filter {
999
- filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
449
+
450
+ .citadel-result-json {
451
+ margin: 0;
1000
452
  }
1001
- .transition {
1002
- transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, -webkit-backdrop-filter;
1003
- transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
1004
- transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter, -webkit-backdrop-filter;
1005
- transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
1006
- transition-duration: 150ms;
453
+
454
+ .citadel-result-text {
455
+ white-space: pre;
1007
456
  }
1008
- .ease-in-out {
1009
- transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
457
+
458
+ .citadel-result-error {
459
+ margin-top: 0.25rem;
460
+ color: var(--citadel-error);
1010
461
  }
1011
- .ease-out {
1012
- transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
462
+
463
+ .citadel-result-pending {
464
+ color: var(--citadel-muted);
1013
465
  }
1014
- .last\\:mb-0:last-child {
1015
- margin-bottom: 0px;
466
+
467
+ .citadel-result-image-wrap {
468
+ margin-block: 0.5rem;
1016
469
  }
1017
- .last\\:mr-0:last-child {
1018
- margin-right: 0px;
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;
1019
477
  }
1020
- `,Xe=({config:t=N,commandRegistry:e,containerId:n=null})=>{const r=s.useRef(new O),o=e??r.current,a=s.useRef(null),l=t.displayMode??N.displayMode??"panel";return s.useEffect(()=>{E.configure({level:t.logLevel||N.logLevel||X.ERROR,prefix:"[Citadel]"});const d=new Se(o,t),i=l==="inline"&&!n,m=i?a.current:n?document.getElementById(n):document.body;if(m)m.appendChild(d);else{if(i){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(d)}return()=>{var w;(w=d.parentElement)==null||w.removeChild(d)}},[o,n,t,l]),l==="inline"&&!n?c.jsx("div",{ref:a,style:{width:"100%",height:"100%"}}):null};class Se extends HTMLElement{constructor(n,r){var a;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=r;const o=((a=this.config)==null?void 0:a.displayMode)??"panel";this.setAttribute("data-display-mode",o)}connectedCallback(){try{const r=[xe,Ce,ve,Je].map(o=>{const a=new CSSStyleSheet;return a.replaceSync(o),a});this.shadow.adoptedStyleSheets=[...r]}catch{const r=[xe,Ce,ve].join(`
1021
- `),o=document.createElement("style");o.textContent=r,this.shadow.appendChild(o)}const n=document.createElement("div");n.id="citadel-root",n.style.width="100%",n.style.height="100%",this.shadow.appendChild(n),this.root=Ne.createRoot(n),this.root.render(c.jsx(Pe,{config:this.config||N,commandRegistry:this.commandRegistry,children:c.jsx(Qe,{})}))}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",Se);const Qe=()=>(H().displayMode??"panel")==="inline"?c.jsx(Ge,{}):c.jsx(Ve,{});class Ze{constructor(){C(this,"_description")}describe(e){return this._description=e,this}get description(){return this._description}}class Re{constructor(e){C(this,"state");this.state={path:e,description:"",segments:en(e)}}describe(e){return this.state.description=e,this}details(e){return this.state.details=e,this}arg(e,n){const r=new Ze;return n==null||n(r),this.state.segments.push({type:"argument",name:e,description:r.description}),this}handle(e){return{path:this.state.path,description:this.state.description,details:this.state.details,segments:[...this.state.segments],handler:e}}}function en(t){const e=t.trim();if(!e)throw new Error("Command path cannot be empty");const n=e.split(".");if(n.some(r=>r.trim()===""))throw new Error(`Invalid command path "${t}". Empty segments are not allowed.`);if(n.some(r=>r.includes(" ")))throw new Error(`Invalid command path "${t}". Use dot-delimited words (e.g. "user.show").`);return n.map(r=>({type:"word",name:r}))}function nn(t){return t.flatMap(e=>e.type==="argument"?[e.name]:[])}function tn(t){const e=nn(t.segments);return async n=>{const r=e.reduce((o,a,l)=>(o[a]=n[l],o),{});return Promise.resolve(t.handler({rawArgs:n,namedArgs:r,commandPath:t.path}))}}function rn(t){return new Re(t)}function ke(t,e){t.addCommand(e.segments,e.description,tn(e))}function Ee(t,e){return e.forEach(n=>ke(t,n)),t}function on(t){const e=new O;return Ee(e,t)}function sn(t){return new L(t)}function an(t){return new te(t)}function ln(t,e=""){return new oe(t,e)}function cn(t){return new J(t)}g.Citadel=Xe,g.CommandRegistry=O,g.CommandResult=D,g.CommandStatus=U,g.DEFAULT_CURSOR_CONFIGS=ge,g.ErrorCommandResult=J,g.ImageCommandResult=oe,g.JsonCommandResult=te,g.OutputItem=Y,g.PendingCommandResult=re,g.TextCommandResult=L,g.command=rn,g.createCommandRegistry=on,g.error=cn,g.image=ln,g.json=an,g.registerCommand=ke,g.registerCommands=Ee,g.text=sn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
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"})});