citadel_cli 1.1.6 → 1.1.7

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,9 +1,9 @@
1
- (function(w,a){typeof exports=="object"&&typeof module<"u"?a(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"],a):(w=typeof globalThis<"u"?globalThis:w||self,a(w.Citadel={},w.jsxRuntime,w.React,w.client))})(this,function(w,a,s,pe){"use strict";var $e=Object.defineProperty;var Ke=(w,a,s)=>a in w?$e(w,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):w[a]=s;var x=(w,a,s)=>Ke(w,typeof a!="symbol"?a+"":a,s);var D=(r=>(r.Pending="pending",r.Success="success",r.Failure="failure",r.Timeout="timeout",r))(D||{});class P{constructor(e=Date.now()){x(this,"_status","pending");this.timestamp=e}get status(){return this._status}markSuccess(){this._status="success"}markFailure(){this._status="failure"}markTimeout(){this._status="timeout"}}class he extends P{constructor(e,n){super(n),this.data=e}render(){return a.jsx("pre",{className:"text-gray-200",children:JSON.stringify(this.data,null,2)})}}class V extends P{constructor(e,n){super(n),this.text=e}render(){return a.jsx("div",{className:"text-gray-200 whitespace-pre font-mono",children:this.text})}}class G extends P{constructor(e,n){super(n),this.error=e,this.markFailure()}render(){return a.jsx("div",{className:"mt-1 text-red-400",children:this.error})}}class J extends P{render(){return a.jsx("div",{className:"text-gray-400",children:"..."})}}class ge extends P{constructor(e,n="",t){super(t),this.imageUrl=e,this.altText=n}render(){return a.jsx("div",{className:"my-2",children:a.jsx("img",{src:this.imageUrl,alt:this.altText,className:"max-w-[400px] max-h-[300px] h-auto rounded-lg object-contain"})})}}const fe=r=>async function(){const e=r.commands.filter(n=>n.fullPath[0]!=="help").map(n=>`${n.segments.map(o=>o.type==="argument"?`<${o.name}>`:o.name).join(" ")} - ${n.description}`).sort();return e.push("help - Show available commands"),new V(e.length>0?`Available Commands:
1
+ (function(y,a){typeof exports=="object"&&typeof module<"u"?a(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"],a):(y=typeof globalThis<"u"?globalThis:y||self,a(y.Citadel={},y.jsxRuntime,y.React,y.client))})(this,function(y,a,s,ge){"use strict";var Ke=Object.defineProperty;var qe=(y,a,s)=>a in y?Ke(y,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):y[a]=s;var x=(y,a,s)=>qe(y,typeof a!="symbol"?a+"":a,s);var H=(r=>(r.Pending="pending",r.Success="success",r.Failure="failure",r.Timeout="timeout",r))(H||{});class P{constructor(e=Date.now()){x(this,"_status","pending");this.timestamp=e}get status(){return this._status}markSuccess(){this._status="success"}markFailure(){this._status="failure"}markTimeout(){this._status="timeout"}}class fe extends P{constructor(e,n){super(n),this.data=e}render(){return a.jsx("pre",{className:"text-gray-200",children:JSON.stringify(this.data,null,2)})}}class O extends P{constructor(e,n){super(n),this.text=e}render(){return a.jsx("div",{className:"text-gray-200 whitespace-pre font-mono",children:this.text})}}class J extends P{constructor(e,n){super(n),this.error=e,this.markFailure()}render(){return a.jsx("div",{className:"mt-1 text-red-400",children:this.error})}}class Q extends P{render(){return a.jsx("div",{className:"text-gray-400",children:"..."})}}class we extends P{constructor(e,n="",t){super(t),this.imageUrl=e,this.altText=n}render(){return a.jsx("div",{className:"my-2",children:a.jsx("img",{src:this.imageUrl,alt:this.altText,className:"max-w-[400px] max-h-[300px] h-auto rounded-lg object-contain"})})}}const be=r=>async function(){const e=r.commands.filter(n=>n.fullPath[0]!=="help").map(n=>`${n.segments.map(o=>o.type==="argument"?`<${o.name}>`:o.name).join(" ")} - ${n.description}`).sort();return e.length===0?new O("No commands available yet. Add some commands to get started!"):(e.push("help - Show available commands"),new O(`Available Commands:
2
2
  `+e.join(`
3
- `):"No commands available yet. Add some commands to get started!")};var F=(r=>(r[r.NONE=0]="NONE",r[r.ERROR=1]="ERROR",r[r.WARN=2]="WARN",r[r.INFO=3]="INFO",r[r.DEBUG=4]="DEBUG",r[r.TRACE=5]="TRACE",r))(F||{});class E{static configure(e){this.level=e.level,this.prefix=e.prefix||"[Citadel]"}static trace(...e){this.level>=5&&process.env.NODE_ENV!=="production"&&console.trace(this.prefix,...e)}static debug(...e){this.level>=4&&process.env.NODE_ENV!=="production"&&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)}}x(E,"level",0),x(E,"prefix","");const A={commandTimeoutMs:1e4,cursorColor:"var(--cursor-color, #fff)",cursorSpeed:530,cursorType:"blink",includeHelpCommand:!0,initialHeight:"40vh",logLevel:process.env.NODE_ENV==="production"?F.ERROR:F.DEBUG,maxHeight:"80vh",minHeight:"200",outputFontSize:"0.875rem",resetStateOnHide:!1,showCitadelKey:".",displayMode:"panel",storage:{type:"localStorage",maxCommands:100}};class Q{constructor(e){x(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 we extends Q{constructor(n){super(n);x(this,"storageKey","citadel_command_history")}async getStoredCommands(){try{const n=window.localStorage.getItem(this.storageKey);return n?JSON.parse(n).map(o=>({commandSegments: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 t=n.map(o=>({commandSegments:Array.isArray(o.commandSegments)?[...o.commandSegments]:[],timestamp:o.timestamp}));window.localStorage.setItem(this.storageKey,JSON.stringify(t))}catch(t){throw console.warn("Failed to save commands to localStorage:",t),t}}}class be extends Q{constructor(n){super(n);x(this,"storedCommands",[])}async getStoredCommands(){return this.storedCommands.map(n=>({commandSegments:Array.isArray(n.commandSegments)?[...n.commandSegments]:[],timestamp:n.timestamp}))}async clear(){this.storedCommands=[]}async saveCommands(n){this.storedCommands=n.map(t=>({commandSegments:Array.isArray(t.commandSegments)?[...t.commandSegments]:[],timestamp:t.timestamp}))}}const H=class H{constructor(){x(this,"currentStorage")}static getInstance(){return H.instance||(H.instance=new H),H.instance}initializeStorage(e){if(!this.currentStorage)try{this.currentStorage=new we(e)}catch(n){console.warn("Failed to create storage, falling back to memory storage:",n),this.currentStorage=new be(e)}}getStorage(){if(!this.currentStorage)throw new Error("Storage not initialized. Call initializeStorage first.");return this.currentStorage}};x(H,"instance");let O=H;const X=async()=>new V("");class W{constructor(e,n,t){this.type=e,this.name=n,this.description=t}toString(){return this.name}}class Z extends W{constructor(){super("null",">null<","Empty segment")}}class ye extends W{constructor(e,n){super("word",e,n)}}class xe extends W{constructor(e,n,t,o){super("argument",e,n),this.value=t,this.valid=o}}class Ce{constructor(e,n,t=X){x(this,"_segments");x(this,"_description");x(this,"_handler");this._segments=e,this._description=n,this._handler=t}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 L{constructor(){x(this,"_commands",[])}get commands(){return this._commands}addCommand(e,n,t=X){if(e===void 0||e.length===0)throw new Error("Command path cannot be empty");const o=new Ce(e,n,t),i=this._commands.find(l=>{const m=l.segments.map(d=>d.type==="argument"?"*":d.name).join(" "),u=e.map(d=>d.type==="argument"?"*":d.name).join(" ");return m===u});if(i)throw new Error(`Duplicate commands: '${i.fullPath_s}' and '${o.fullPath_s}'`);this._commands.push(o)}removeCommand(e){const n=e.join(" "),t=this._commands.findIndex(o=>o.fullPath.join(" ")===n);return t===-1?!1:(this._commands.splice(t,1),!0)}getCommand(e){return this._commands.find(n=>{const t=n.fullPath.join(" "),o=e.join(" ");if(t===o)return!0;const l=n.segments.filter(m=>m.type==="word").map(m=>m.name);return l.length===e.length&&l.join(" ")===o})}commandExistsForPath(e){const n=this._commands.map(o=>o.segments.map(i=>i.type==="argument"?"*":i.name).join(" ")),t=e.map((o,i)=>this._commands.some(m=>{var u;return((u=m.segments[i])==null?void 0:u.type)==="argument"})?"*":o).join(" ");return n.includes(t)}getCompletions_s(e){return this.getCompletions(e).map(n=>n.name)}getCompletions(e){if(E.debug("[getCompletions] path: ",e),!e.length){const i=this._commands.map(u=>u.segments[0]),l=(u,d)=>u.type===d.type&&u.name===d.name;return i.filter((u,d,p)=>d===p.findIndex(g=>l(g,u)))}const n=e.length;return this._commands.filter(i=>{const l=i.segments;if(l.length<=n-1)return!1;for(let m=0;m<n;m++){const u=e[m],d=l[m];if(!(u==="*"&&d.type==="argument")&&u!==d.name)return!1}return!0}).filter(i=>i.segments.length>n).map(i=>{const l=i.segments[n],m=l.type==="argument"?xe:ye;return new m(l.name,l.description)}).filter((i,l,m)=>l===m.findIndex(u=>u.type===i.type&&u.name===i.name))}hasNextSegment(e){return this.getCompletions(e).length>0}}class R{constructor(){x(this,"segments",[]);x(this,"nullSegment",new Z);x(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 ve={config:A,commands:new L,segmentStack:new R},U=s.createContext(ve),Se=({config:r=A,commandRegistry:e,children:n})=>{const[t,o]=s.useState(),i={...A,...r,storage:{...A.storage,...r.storage},cursorType:r.cursorType??A.cursorType,cursorColor:r.cursorColor??A.cursorColor,cursorSpeed:r.cursorSpeed??A.cursorSpeed,showCitadelKey:r.showCitadelKey||"."};s.useEffect(()=>{O.getInstance().initializeStorage(i.storage??A.storage),o(O.getInstance().getStorage())},[]),s.useEffect(()=>{if(e){if(i.includeHelpCommand){if(!e.commandExistsForPath(["help"])){const m=fe(e);e.addCommand([{type:"word",name:"help"}],"Show available commands",m)}return}e.removeCommand(["help"])}},[e,i.includeHelpCommand]);const l={config:i,commands:e||new L,storage:t,segmentStack:new R};return a.jsx(U.Provider,{value:l,children:n})},M=()=>{const r=s.useContext(U);if(r===void 0)throw new Error("useCitadelConfig must be used within a CitadelConfigProvider");return r.config},$=()=>{const r=s.useContext(U);if(r===void 0)throw new Error("useCitadelCommands must be used within a CitadelConfigProvider");return r.commands},ee=()=>{const r=s.useContext(U);if(r===void 0)throw new Error("useCitadelStorage must be used within a CitadelConfigProvider");return r.storage},j=()=>{const r=s.useContext(U);if(r===void 0)throw new Error("useSegmentStack must be used within a CitadelConfigProvider");return r.segmentStack};class ne{constructor(e,n){x(this,"timestamp");x(this,"command");x(this,"result");this.command=e.toArray().map(t=>t.type==="argument"?t.value||"":t.name),this.timestamp=Date.now(),this.result=n??new J}}function ke(r){return{commandSegments:r,timestamp:Date.now()}}function te(){const r=ee(),[e,n]=s.useState({storedCommands:[],position:null}),t=s.useCallback(async m=>{if(r)try{const u=ke(m);await r.addStoredCommand(u),n(d=>({...d,storedCommands:[...d.storedCommands,u],position:null}))}catch(u){console.warn("Failed to save command to history:",u)}},[r]),o=s.useCallback(async()=>r?await r.getStoredCommands():[],[r]);s.useEffect(()=>{if(!r)return;(async()=>{try{const u=await r.getStoredCommands();return n(d=>({...d,storedCommands:u})),u}catch(u){console.warn("Failed to load command history:",u)}})()},[r]);const i=s.useCallback(async m=>{if((await o()).length===0)return{segments:null,position:null};let d=null;return m==="up"?e.position===null?d=e.storedCommands.length-1:e.position>0?d=e.position-1:d=0:e.position===null||e.position>=e.storedCommands.length-1?d=null:d=e.position+1,n(g=>({...g,position:d})),d===null?{segments:[],position:null}:{segments:d!==null?e.storedCommands[d].commandSegments:null,position:d}},[e,o]),l=s.useCallback(async()=>{try{if(!r)return;await r.clear(),n({storedCommands:[],position:null})}catch(m){console.warn("Failed to clear command history:",m)}},[r]);return{history:e,addStoredCommand:t,getStoredCommands:o,navigateHistory:i,clear:l}}const Y=()=>{const r=M(),e=$(),n=te(),t=j(),o=ee(),[i,l]=s.useState({currentInput:"",isEnteringArg:!1,output:[],history:{commands:[],position:null,storage:o}});s.useEffect(()=>{},[o]),s.useEffect(()=>{l(p=>({...p,history:{commands:n.history.storedCommands,position:n.history.position,storage:o}}))},[n.history,o]);const m={setCurrentInput:s.useCallback(p=>{E.debug("[CitadelActions] setCurrentInput: ",p),l(g=>({...g,currentInput:p}))},[]),setIsEnteringArg:s.useCallback(p=>{E.debug("[CitadelActions] setIsEnteringArg: ",p),l(g=>({...g,isEnteringArg:p}))},[]),addOutput:s.useCallback(p=>{E.debug("[CitadelActions]addOutput: ",p),l(g=>({...g,output:[...g.output,p]}))},[]),executeCommand:s.useCallback(async()=>{const p=t.path(),g=e.getCommand(p);if(!g){console.error("[CitadelActions][executeCommand] Cannot execute command because no command was found for the given path: ",p);return}const S=new ne(t);l(b=>({...b,output:[...b.output,S]}));try{const b=new Promise((c,h)=>{setTimeout(()=>{h(new Error("Request timed out"))},r.commandTimeoutMs)}),C=t.arguments.map(c=>c.value||""),_=await Promise.race([g.handler(C),b]);if(!(_ instanceof P))throw new Error(`The ${p.join(".")} command returned an invalid result type. Commands must return an instance of a CommandResult.
3
+ `)))};var Y=(r=>(r[r.NONE=0]="NONE",r[r.ERROR=1]="ERROR",r[r.WARN=2]="WARN",r[r.INFO=3]="INFO",r[r.DEBUG=4]="DEBUG",r[r.TRACE=5]="TRACE",r))(Y||{});const X=!0;class S{static configure(e){this.level=e.level,this.prefix=e.prefix||"[Citadel]"}static trace(...e){this.level>=5&&!X&&console.trace(this.prefix,...e)}static debug(...e){this.level>=4&&!X&&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)}}x(S,"level",0),x(S,"prefix","");const N={commandTimeoutMs:1e4,cursorColor:"var(--cursor-color, #fff)",cursorSpeed:530,cursorType:"blink",includeHelpCommand:!0,initialHeight:"40vh",logLevel:Y.ERROR,maxHeight:"80vh",minHeight:"200",outputFontSize:"0.875rem",resetStateOnHide:!1,showCitadelKey:".",displayMode:"panel",storage:{type:"localStorage",maxCommands:100}};class Z{constructor(e){x(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 ye extends Z{constructor(n){super(n);x(this,"storageKey","citadel_command_history")}async getStoredCommands(){try{const n=window.localStorage.getItem(this.storageKey);return n?JSON.parse(n).map(o=>({commandSegments: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 t=n.map(o=>({commandSegments:Array.isArray(o.commandSegments)?[...o.commandSegments]:[],timestamp:o.timestamp}));window.localStorage.setItem(this.storageKey,JSON.stringify(t))}catch(t){throw console.warn("Failed to save commands to localStorage:",t),t}}}class R extends Z{constructor(n){super(n);x(this,"storedCommands",[])}async getStoredCommands(){return this.storedCommands.map(n=>({commandSegments:Array.isArray(n.commandSegments)?[...n.commandSegments]:[],timestamp:n.timestamp}))}async clear(){this.storedCommands=[]}async saveCommands(n){this.storedCommands=n.map(t=>({commandSegments:Array.isArray(t.commandSegments)?[...t.commandSegments]:[],timestamp:t.timestamp}))}}const z=class z{constructor(){x(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 R(e):this.currentStorage=new ye(e)}catch(n){console.warn("Failed to create storage, falling back to memory storage:",n),this.currentStorage=new R(e)}}getStorage(){if(!this.currentStorage)throw new Error("Storage not initialized. Call initializeStorage first.");return this.currentStorage}};x(z,"instance");let L=z;const ee=async()=>new O("");class B{constructor(e,n,t){this.type=e,this.name=n,this.description=t}toString(){return this.name}}class ne extends B{constructor(){super("null",">null<","Empty segment")}}class xe extends B{constructor(e,n){super("word",e,n)}}class $ extends B{constructor(e,n,t,o){super("argument",e,n),this.value=t,this.valid=o}}class Ce{constructor(e,n,t=ee){x(this,"_segments");x(this,"_description");x(this,"_handler");this._segments=e,this._description=n,this._handler=t}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(){x(this,"_commands",[])}get commands(){return this._commands}addCommand(e,n,t=ee){if(e===void 0||e.length===0)throw new Error("Command path cannot be empty");const o=new Ce(e,n,t),l=this._commands.find(d=>{const m=d.segments.map(c=>c.type==="argument"?"*":c.name).join(" "),i=e.map(c=>c.type==="argument"?"*":c.name).join(" ");return m===i});if(l)throw new Error(`Duplicate commands: '${l.fullPath_s}' and '${o.fullPath_s}'`);this._commands.push(o)}removeCommand(e){const n=e.join(" "),t=this._commands.findIndex(o=>o.fullPath.join(" ")===n);return t===-1?!1:(this._commands.splice(t,1),!0)}getCommand(e){return this._commands.find(n=>{const t=n.fullPath.join(" "),o=e.join(" ");if(t===o)return!0;const d=n.segments.filter(m=>m.type==="word").map(m=>m.name);return d.length===e.length&&d.join(" ")===o})}commandExistsForPath(e){const n=this._commands.map(o=>o.segments.map(l=>l.type==="argument"?"*":l.name).join(" ")),t=e.map((o,l)=>this._commands.some(m=>{var i;return((i=m.segments[l])==null?void 0:i.type)==="argument"})?"*":o).join(" ");return n.includes(t)}getCompletionNames(e){return this.getCompletions(e).map(n=>n.name)}getCompletions(e){if(S.debug("[getCompletions] path: ",e),!e.length){const l=this._commands.map(i=>i.segments[0]),d=(i,c)=>i.type===c.type&&i.name===c.name;return l.filter((i,c,p)=>c===p.findIndex(g=>d(g,i)))}const n=e.length;return this._commands.filter(l=>{const d=l.segments;if(d.length<=n-1)return!1;for(let m=0;m<n;m++){const i=e[m],c=d[m];if(!(i==="*"&&c.type==="argument")&&i!==c.name)return!1}return!0}).filter(l=>l.segments.length>n).map(l=>{const d=l.segments[n],m=d.type==="argument"?$:xe;return new m(d.name,d.description)}).filter((l,d,m)=>d===m.findIndex(i=>i.type===l.type&&i.name===l.name))}hasNextSegment(e){return this.getCompletions(e).length>0}}class te{constructor(){x(this,"segments",[]);x(this,"nullSegment",new ne);x(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 ve={config:N,commands:new K,segmentStack:new te},D=s.createContext(ve),Se=({config:r=N,commandRegistry:e,children:n})=>{const[t,o]=s.useState(),[l]=s.useState(()=>new te),d={...N,...r,storage:{...N.storage,...r.storage},cursorType:r.cursorType??N.cursorType,cursorColor:r.cursorColor??N.cursorColor,cursorSpeed:r.cursorSpeed??N.cursorSpeed,showCitadelKey:r.showCitadelKey||"."};s.useEffect(()=>{L.getInstance().initializeStorage(d.storage??N.storage),o(L.getInstance().getStorage())},[]),s.useEffect(()=>{if(e){if(d.includeHelpCommand){if(!e.commandExistsForPath(["help"])){const i=be(e);e.addCommand([{type:"word",name:"help"}],"Show available commands",i)}return}e.removeCommand(["help"])}},[e,d.includeHelpCommand]);const m=s.useMemo(()=>({config:d,commands:e||new K,storage:t,segmentStack:l}),[d,e,t,l]);return a.jsx(D.Provider,{value:m,children:n})},T=()=>{const r=s.useContext(D);if(r===void 0)throw new Error("useCitadelConfig must be used within a CitadelConfigProvider");return r.config},q=()=>{const r=s.useContext(D);if(r===void 0)throw new Error("useCitadelCommands must be used within a CitadelConfigProvider");return r.commands},re=()=>{const r=s.useContext(D);if(r===void 0)throw new Error("useCitadelStorage must be used within a CitadelConfigProvider");return r.storage},U=()=>{const r=s.useContext(D);if(r===void 0)throw new Error("useSegmentStack must be used within a CitadelConfigProvider");return r.segmentStack},V=class V{constructor(e,n){x(this,"id");x(this,"timestamp");x(this,"command");x(this,"result");this.id=`output-${Date.now()}-${V.idCounter++}`,this.command=e.toArray().map(t=>t.type==="argument"?t.value||"":t.name),this.timestamp=Date.now(),this.result=n??new Q}};x(V,"idCounter",0);let W=V;function ke(r){return{commandSegments:r,timestamp:Date.now()}}function oe(){const r=re(),[e,n]=s.useState({storedCommands:[],position:null}),t=s.useCallback(async m=>{if(r)try{const i=ke(m);await r.addStoredCommand(i),n(c=>({...c,storedCommands:[...c.storedCommands,i],position:null}))}catch(i){console.warn("Failed to save command to history:",i)}},[r]),o=s.useCallback(async()=>r?await r.getStoredCommands():[],[r]);s.useEffect(()=>{if(!r)return;(async()=>{try{const i=await r.getStoredCommands();return n(c=>({...c,storedCommands:i})),i}catch(i){console.warn("Failed to load command history:",i)}})()},[r]);const l=s.useCallback(async m=>{const i=await o();if(i.length===0)return n(g=>({...g,storedCommands:[],position:null})),{segments:null,position:null};let c=null;if(m==="up"?e.position===null?c=i.length-1:e.position>0?c=e.position-1:c=0:e.position===null||e.position>=i.length-1?c=null:c=e.position+1,n(g=>({...g,storedCommands:i,position:c})),c===null)return{segments:[],position:null};const p=i[c];return p?{segments:p.commandSegments,position:c}:{segments:[],position:null}},[e.position,o]),d=s.useCallback(async()=>{try{if(!r)return;await r.clear(),n({storedCommands:[],position:null})}catch(m){console.warn("Failed to clear command history:",m)}},[r]);return{history:e,addStoredCommand:t,getStoredCommands:o,navigateHistory:l,clear:d}}const G=()=>{const r=T(),e=q(),n=oe(),t=U(),o=re(),[l,d]=s.useState({currentInput:"",isEnteringArg:!1,output:[],history:{commands:[],position:null,storage:o}});s.useEffect(()=>{},[o]),s.useEffect(()=>{d(i=>({...i,history:{commands:n.history.storedCommands,position:n.history.position,storage:o}}))},[n.history,o]);const m={setCurrentInput:s.useCallback(i=>{S.debug("[CitadelActions] setCurrentInput: ",i),d(c=>({...c,currentInput:i}))},[]),setIsEnteringArg:s.useCallback(i=>{S.debug("[CitadelActions] setIsEnteringArg: ",i),d(c=>({...c,isEnteringArg:i}))},[]),addOutput:s.useCallback(i=>{S.debug("[CitadelActions]addOutput: ",i),d(c=>({...c,output:[...c.output,i]}))},[]),executeCommand:s.useCallback(async()=>{const i=t.path(),c=e.getCommand(i);if(!c){console.error("[CitadelActions][executeCommand] Cannot execute command because no command was found for the given path: ",i);return}const p=new W(t);d(g=>({...g,output:[...g.output,p]}));try{const g=new Promise((h,E)=>{setTimeout(()=>{E(new Error("Request timed out"))},r.commandTimeoutMs)}),k=t.arguments.map(h=>h.value||""),v=await Promise.race([c.handler(k),g]);if(!(v instanceof P))throw new Error(`The ${i.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 ${p.join(".")} command and update the return type for its handler.`);_.markSuccess(),l(c=>({...c,output:c.output.map(h=>h.timestamp===S.timestamp?{...h,result:_}:h)}))}catch(b){const C=new G(b instanceof Error?b.message:"Unknown error");C.markFailure(),l(_=>({..._,output:_.output.map(c=>c.timestamp===S.timestamp?{...c,result:C}:c)}))}},[e,r.commandTimeoutMs,t]),clearHistory:s.useCallback(async()=>{try{await n.clear()}catch(p){console.warn("Failed to clear history:",p)}},[n])},u=s.useCallback(()=>e.getCompletions_s(t.path()),[t,e]),d=s.useCallback(()=>e.getCompletions(t.path()),[t,e]);return{state:i,actions:m,getAvailableCommands_s:u,getAvailableCommandSegments:d}},Ee=({onOpen:r,onClose:e,isVisible:n,showCitadelKey:t})=>{s.useEffect(()=>{const o=i=>{var l,m;!n&&i.key===t&&!["input","textarea"].includes(((m=(l=i.target)==null?void 0:l.tagName)==null?void 0:m.toLowerCase())||"")&&(i.preventDefault(),r()),n&&i.key==="Escape"&&(i.preventDefault(),e())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[r,e,n,t])},re={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"},_e=r=>{const{isVisible:e,isClosing:n,onAnimationComplete:t}=r,o=s.useMemo(()=>e?n?re.slideDown:re.slideUp:"",[e,n]);return s.useEffect(()=>{if(t){const l=setTimeout(()=>{t()},200);return()=>clearTimeout(l)}},[n,t]),{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}},Ne=()=>a.jsx("div",{"data-testid":"spinner",className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-gray-600"}),Ae=({command:r,timestamp:e,status:n})=>a.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm",children:[a.jsxs("span",{className:"text-gray-200",children:["> ",r.split(" ").map((t,o)=>{const i=t.startsWith("<")&&t.endsWith(">");return a.jsxs("span",{className:i?"text-green-400":"text-gray-200",children:[o>0?" ":"",t]},o)})]}),a.jsx("span",{className:"text-gray-400",children:"·"}),a.jsx("span",{className:"text-gray-500",children:e}),n===D.Pending&&a.jsx(Ne,{}),n===D.Success&&a.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-green-500"}),(n===D.Timeout||n===D.Failure)&&a.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-red-500"})]}),ze=({output:r,outputRef:e})=>{const n=M(),t=s.useCallback(()=>{if(e.current){const o=e.current;requestAnimationFrame(()=>{o.scrollTop=o.scrollHeight})}},[e]);return s.useEffect(()=>{if(t(),e.current){const o=e.current.getElementsByTagName("img"),i=o[o.length-1];if(i&&!i.complete)return i.addEventListener("load",t),()=>i.removeEventListener("load",t)}},[r,t,e]),a.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:r.map((o,i)=>a.jsxs("div",{className:"mb-4 last:mb-0",children:[a.jsx(Ae,{command:o.command.join(" "),timestamp:new Date(o.timestamp).toLocaleTimeString(),status:o.result.status}),a.jsx("pre",{className:`text-gray-200 whitespace-pre font-mono ${n.outputFontSize}`,children:o.result.render()})]},i))})},oe={blink:{character:"▋",speed:530,color:"#fff"},spin:{character:"⠋",speed:120,color:"#fff"},solid:{character:"▋",speed:0,color:"#fff"},bbs:{character:"|",speed:120,color:"#fff"}},se=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],ae=["|","/","-","\\"],Ie=({style:r={type:"blink"},isValid:e=!0,errorMessage:n})=>{const t=s.useMemo(()=>({...oe[r.type],...r}),[r]),[o,i]=s.useState(!0),[l,m]=s.useState(0);s.useEffect(()=>{if(t.speed===0)return;const p=setInterval(()=>{t.type==="blink"?i(g=>!g):["spin","bbs"].includes(t.type)&&m(g=>(g+1)%(t.type==="bbs"?ae.length:se.length))},t.speed);return()=>clearInterval(p)},[t.type,t.speed]);const u=s.useMemo(()=>({color:e?t.color:"#ff4444",transition:"color 0.15s ease-in-out"}),[e,t.color]),d=()=>!e&&n?"✗":["spin","bbs"].includes(t.type)?(t.type==="bbs"?ae:se)[l]:t.type==="solid"||o?t.character:" ";return a.jsx("div",{className:"relative inline-block",children:a.jsx("span",{className:`command-cursor ${e?"":"animate-shake"}`,style:u,title:n,children:d()})})};function Pe(r,e){switch(e.type){case"set":return E.debug(`[inputStateReducer] InputState changing from ${r} to ${e.state}`),e.state;default:return r}}const He=()=>{const{state:r}=Y(),e=$(),n=te(),t=j(),[o,i]=s.useReducer(Pe,"idle"),l=c=>{i({type:"set",state:c})},m=s.useCallback(()=>{const h=e.getCompletions(t.path())[0]||t.nullSegment;return E.debug("[getNextExpectedSegment] ",h),h},[e,t]),u=s.useCallback(()=>e.getCompletions_s(t.path()).map(h=>e.getCommand([...t.path(),h])).filter(h=>h!==void 0),[e,t]),d=s.useCallback((c,h)=>{if(!c)return h;const f=h.reduce((y,v)=>{const k=m();return(k==null?void 0:k.type)==="word"&&y.set(k.name,v),y},new Map);return Array.from(f.values()).filter(()=>{const y=m();return y.type!=="word"?!1:y.name.toLowerCase().startsWith(c.toLowerCase())})},[m]),p=s.useCallback(c=>{const f=e.getCompletions(t.path()).filter(N=>N.type==="word").filter(N=>N.name.toLowerCase().startsWith(c.toLowerCase()));return f.length===1?f[0]:t.nullSegment},[e,t]),g=s.useCallback(c=>{const h=t.path(),f=e.getCompletions(h);return f.length===0&&c?!1:f.some(y=>y.type==="argument")?!0:f.some(y=>y.type==="word"&&y.name.toLowerCase().startsWith(c.toLowerCase()))},[e,t]),S=s.useCallback(c=>{E.debug("[tryAutoComplete] input: ",c);const h=p(c);return!h||h.name===c?new Z:(E.debug("[tryAutoComplete] result: ",h),h)},[p]),b=s.useCallback((c,h)=>{if(r.history.position===null){if(h.setCurrentInput(c),E.debug("[useCommandParser][handleInputChange] newValue: ",c),o==="entering_argument"){const f=ie(c);if(f.isQuoted)if(f.isComplete){const N=m();if(N.type==="argument"){const y=N;y.value=c.trim()||"",E.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",y),t.push(y),h.setCurrentInput(""),l("idle");return}}else return;else if(f.isComplete){const N=m();N.value=c.trim()||"",E.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",N),t.push(N),h.setCurrentInput(""),l("idle");return}else return}if(o=="entering_command"){const f=S(c);if(f.type==="word"){E.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",f),t.push(f),h.setCurrentInput(""),l("idle");return}}}},[S,r,m,o,t]),C=s.useCallback(c=>{c.setCurrentInput(""),c.setIsEnteringArg(!1),t.clear(),l("idle")},[t]),_=s.useCallback((c,h,f)=>{if(!(c.key==="Backspace"||c.key==="Enter"||c.key==="ArrowUp"||c.key==="ArrowDown"||c.key==="ArrowLeft"||c.key==="ArrowRight"||c.key==="Escape"||c.key==="Delete"||c.key==="Home"||c.key==="End"||c.key.length===1))return!0;const{currentInput:y,isEnteringArg:v}=h,k=ie(y);switch(c.key){case"Backspace":return y===""&&(c.preventDefault(),t.size()>0&&t.pop(),l("idle")),!0;case"Enter":{if(c.preventDefault(),k.isQuoted&&!k.isComplete)return!0;if(o==="entering_argument"||v&&y.trim()){const B=m();B.value=y,E.debug("[handleKeyDown][Enter]['entering_argument'] pushing: ",B),t.push(B)}const z=t.path(),I=e.getCommand(z);if(!I)return!1;const K=I.segments.filter(T=>T.type==="argument"),q=t.arguments;return K.length>q.length?!1:(E.debug("[handleKeyDown][Enter] calling actions.executeCommand. segmentStack: ",t),f.executeCommand(),n.addStoredCommand(t.toArray()),C(f),!0)}case"ArrowUp":return c.preventDefault(),(async()=>{const z=await n.navigateHistory("up",t.toArray());return z.segments&&(t.clear(),t.pushAll(z.segments),f.setCurrentInput("")),!0})();case"ArrowDown":return c.preventDefault(),(async()=>{const z=await n.navigateHistory("down",t.toArray());return z.segments&&(t.clear(),t.pushAll(z.segments),f.setCurrentInput("")),!0})();default:{if(!v&&c.key.length===1){const z=y+c.key;if(!g(z))return c.preventDefault(),!1}return!0}}},[o,g,m,n,C,e,t]);return{handleInputChange:b,handleKeyDown:_,inputState:o,setInputStateWithLogging:l,findMatchingCommands:d,getAutocompleteSuggestion:p,getAvailableNodes:u,getNextExpectedSegment:m,isValidCommandInput:g}};function ie(r){const e=[];let n="",t=!1,o;for(let i=0;i<r.length;i++){const l=r[i];(l==='"'||l==="'")&&(!t||l===o)?t?(e.push(n),n="",t=!1,o=void 0):(n&&(e.push(n),n=""),t=!0,o=l):!t&&l===" "?n&&(e.push(n),n=""):n+=l}return{words:e,currentWord:n,isQuoted:t,quoteChar:o,isComplete:!t&&!n}}const De=()=>{const r=j(),[e,n]=s.useState(0);return s.useEffect(()=>{const t={update:()=>{n(o=>o+1)}};return r.subscribe(t),()=>{r.unsubscribe(t)}},[r]),e},Me=({state:r,actions:e})=>{const n=s.useRef(null),t=$(),o=j(),{handleKeyDown:i,handleInputChange:l,inputState:m,setInputStateWithLogging:u,getNextExpectedSegment:d}=He(),[p,g]=s.useState(!1),S=M(),b=De(),C=async v=>{const k=i(v,r,e);await Promise.resolve(k)===!1&&(g(!0),setTimeout(()=>g(!1),500))},_=v=>{l(v.target.value,e)},c=v=>{v.preventDefault();const k=v.clipboardData.getData("text");l(k,e)};s.useEffect(()=>{n.current&&n.current.focus(),m!=="entering_command"&&u("entering_command")},[m,u]),s.useEffect(()=>{if(m!=="idle")return;const v=d();let k="idle";switch(v.type){case"word":k="entering_command",e.setIsEnteringArg(!1);break;case"argument":k="entering_argument",e.setIsEnteringArg(!0);break}u(k)},[b,m,d,u,e]);const[h,f]=s.useState([]);s.useEffect(()=>{const v=[],k=o.toArray().map((I,K)=>{v.push(I.name);const q=t.hasNextSegment(v);if(I.type==="argument"){const T=I;return a.jsxs(s.Fragment,{children:[a.jsx("span",{className:"text-gray-200 whitespace-pre",children:T.value}),K<o.size()&&q&&a.jsx("span",{className:"text-gray-200 whitespace-pre",children:" "})]},"arg-"+T.name+T.value)}return a.jsxs(s.Fragment,{children:[a.jsx("span",{className:"text-blue-400 whitespace-pre",children:I.name}),K<o.size()&&q&&a.jsx("span",{className:"text-blue-400 whitespace-pre",children:" "})]},"word-"+I.name)});f([a.jsx("div",{className:"flex items-center gap-1","data-testid":"user-input-area",children:k},"{segmentStackVersion}")])},[b,t,o]);const[N,y]=s.useState("");return s.useEffect(()=>{const v=d();v.type==="argument"?y(v.name):y("")},[b,d]),a.jsxs("div",{className:"flex flex-col w-full bg-gray-900 rounded-lg p-4",children:[a.jsx("style",{children:`
6
+ Check the definition of the ${i.join(".")} command and update the return type for its handler.`);v.markSuccess(),d(h=>({...h,output:h.output.map(E=>E.id===p.id?{...E,result:v}:E)}))}catch(g){const k=new J(g instanceof Error?g.message:"Unknown error");k.markFailure(),d(v=>({...v,output:v.output.map(h=>h.id===p.id?{...h,result:k}:h)}))}},[e,r.commandTimeoutMs,t]),clearHistory:s.useCallback(async()=>{try{await n.clear()}catch(i){console.warn("Failed to clear history:",i)}},[n])};return{state:l,actions:m}},Ee=({onOpen:r,onClose:e,isVisible:n,showCitadelKey:t})=>{s.useEffect(()=>{const o=l=>{var d,m;!n&&l.key===t&&!["input","textarea"].includes(((m=(d=l.target)==null?void 0:d.tagName)==null?void 0:m.toLowerCase())||"")&&(l.preventDefault(),r()),n&&l.key==="Escape"&&(l.preventDefault(),e())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[r,e,n,t])},se={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"},Ne=r=>{const{isVisible:e,isClosing:n,onAnimationComplete:t}=r,o=s.useMemo(()=>e?n?se.slideDown:se.slideUp:"",[e,n]);return s.useEffect(()=>{if(t){const d=setTimeout(()=>{t()},200);return()=>clearTimeout(d)}},[n,t]),{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}},_e=()=>a.jsx("div",{"data-testid":"spinner",className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-gray-600"}),Ae=({command:r,timestamp:e,status:n})=>a.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm",children:[a.jsxs("span",{className:"text-gray-200",children:["> ",r.split(" ").map((t,o)=>{const l=t.startsWith("<")&&t.endsWith(">");return a.jsxs("span",{className:l?"text-green-400":"text-gray-200",children:[o>0?" ":"",t]},o)})]}),a.jsx("span",{className:"text-gray-400",children:"·"}),a.jsx("span",{className:"text-gray-500",children:e}),n===H.Pending&&a.jsx(_e,{}),n===H.Success&&a.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-green-500"}),(n===H.Timeout||n===H.Failure)&&a.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-red-500"})]}),Ie=({output:r,outputRef:e})=>{const n=T(),t=s.useCallback(()=>{if(e.current){const o=e.current;requestAnimationFrame(()=>{o.scrollTop=o.scrollHeight})}},[e]);return s.useEffect(()=>{if(t(),e.current){const o=e.current.getElementsByTagName("img"),l=o[o.length-1];if(l&&!l.complete)return l.addEventListener("load",t),()=>l.removeEventListener("load",t)}},[r,t,e]),a.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:r.map(o=>a.jsxs("div",{className:"mb-4 last:mb-0",children:[a.jsx(Ae,{command:o.command.join(" "),timestamp:new Date(o.timestamp).toLocaleTimeString(),status:o.result.status}),a.jsx("pre",{className:`text-gray-200 whitespace-pre font-mono ${n.outputFontSize}`,children:o.result.render()})]},o.id))})},ae={blink:{character:"▋",speed:530,color:"#fff"},spin:{character:"⠋",speed:120,color:"#fff"},solid:{character:"▋",speed:0,color:"#fff"},bbs:{character:"|",speed:120,color:"#fff"}},ie=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],le=["|","/","-","\\"],ze=({style:r={type:"blink"},isValid:e=!0,errorMessage:n})=>{const t=s.useMemo(()=>({...ae[r.type],...r}),[r]),[o,l]=s.useState(!0),[d,m]=s.useState(0);s.useEffect(()=>{if(t.speed===0)return;const p=setInterval(()=>{t.type==="blink"?l(g=>!g):["spin","bbs"].includes(t.type)&&m(g=>(g+1)%(t.type==="bbs"?le.length:ie.length))},t.speed);return()=>clearInterval(p)},[t.type,t.speed]);const i=s.useMemo(()=>({color:e?t.color:"#ff4444",transition:"color 0.15s ease-in-out"}),[e,t.color]),c=()=>!e&&n?"✗":["spin","bbs"].includes(t.type)?(t.type==="bbs"?le:ie)[d]:t.type==="solid"||o?t.character:" ";return a.jsx("div",{className:"relative inline-block",children:a.jsx("span",{className:`command-cursor ${e?"":"animate-shake"}`,style:i,title:n,children:c()})})};function Pe(r,e){switch(e.type){case"set":return S.debug(`[inputStateReducer] InputState changing from ${r} to ${e.state}`),e.state;default:return r}}const He=()=>{const{state:r}=G(),e=q(),n=oe(),t=U(),[o,l]=s.useReducer(Pe,"idle"),d=u=>{l({type:"set",state:u})},m=s.useCallback(()=>{const w=e.getCompletions(t.path())[0]||t.nullSegment;return S.debug("[getNextExpectedSegment] ",w),w},[e,t]),i=s.useCallback(()=>e.getCompletionNames(t.path()).map(w=>e.getCommand([...t.path(),w])).filter(w=>w!==void 0),[e,t]),c=s.useCallback((u,w)=>{if(!u)return w;const b=t.path().length;return w.filter(C=>{const f=C.segments[b];return!f||f.type!=="word"?!1:f.name.toLowerCase().startsWith(u.toLowerCase())})},[t]),p=s.useCallback(u=>{const b=e.getCompletions(t.path()).filter(C=>C.type==="word").filter(C=>C.name.toLowerCase().startsWith(u.toLowerCase()));return b.length===1?b[0]:t.nullSegment},[e,t]),g=s.useCallback(u=>{const w=t.path(),b=e.getCompletions(w);return b.length===0&&u?!1:b.some(f=>f.type==="argument")?!0:b.some(f=>f.type==="word"&&f.name.toLowerCase().startsWith(u.toLowerCase()))},[e,t]),k=s.useCallback(u=>{S.debug("[tryAutoComplete] input: ",u);const w=p(u);return!w||w.name===u?new ne:(S.debug("[tryAutoComplete] result: ",w),w)},[p]),v=s.useCallback((u,w)=>{if(r.history.position===null){if(w.setCurrentInput(u),S.debug("[useCommandParser][handleInputChange] newValue: ",u),o==="entering_argument"){const b=ce(u);if(b.isQuoted)if(b.isComplete){const C=m();if(!(C instanceof $))return;C.value=u.trim()||"",S.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",C),t.push(C),w.setCurrentInput(""),d("idle");return}else return;else if(b.isComplete){const C=m();if(!(C instanceof $))return;C.value=u.trim()||"",S.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",C),t.push(C),w.setCurrentInput(""),d("idle");return}else return}if(o==="entering_command"){const b=k(u);if(b.type==="word"){S.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",b),t.push(b),w.setCurrentInput(""),d("idle");return}}}},[k,r,m,o,t]),h=s.useCallback(u=>{u.setCurrentInput(""),u.setIsEnteringArg(!1),t.clear(),d("idle")},[t]),E=s.useCallback((u,w,b)=>{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:f,isEnteringArg:_}=w,I=ce(f);switch(u.key){case"Backspace":return f===""&&(u.preventDefault(),t.size()>0&&t.pop(),d("idle")),!0;case"Enter":{if(u.preventDefault(),I.isQuoted&&!I.isComplete)return!0;if(o==="entering_argument"||_&&f.trim()){const M=m();M instanceof $&&(M.value=f,S.debug("[handleKeyDown][Enter]['entering_argument'] pushing: ",M),t.push(M))}const A=t.path(),j=e.getCommand(A);if(!j)return!1;const F=j.segments.filter(M=>M.type==="argument"),$e=t.arguments;return F.length>$e.length?!1:(S.debug("[handleKeyDown][Enter] calling actions.executeCommand. segmentStack: ",t),b.executeCommand(),n.addStoredCommand(t.toArray()),h(b),!0)}case"ArrowUp":return u.preventDefault(),(async()=>{const A=await n.navigateHistory("up");return A.segments&&(t.clear(),t.pushAll(A.segments),b.setCurrentInput("")),!0})();case"ArrowDown":return u.preventDefault(),(async()=>{const A=await n.navigateHistory("down");return A.segments&&(t.clear(),t.pushAll(A.segments),b.setCurrentInput("")),!0})();default:{if(!_&&u.key.length===1){const A=f+u.key;if(!g(A))return u.preventDefault(),!1}return!0}}},[o,g,m,n,h,e,t]);return{handleInputChange:v,handleKeyDown:E,inputState:o,setInputStateWithLogging:d,findMatchingCommands:c,getAutocompleteSuggestion:p,getAvailableNodes:i,getNextExpectedSegment:m,isValidCommandInput:g}};function ce(r){const e=[];let n="",t=!1,o;for(let l=0;l<r.length;l++){const d=r[l];(d==='"'||d==="'")&&(!t||d===o)?t?(e.push(n),n="",t=!1,o=void 0):(n&&(e.push(n),n=""),t=!0,o=d):!t&&d===" "?n&&(e.push(n),n=""):n+=d}return{words:e,currentWord:n,isQuoted:t,quoteChar:o,isComplete:!t&&!n}}const Me=()=>{const r=U(),[e,n]=s.useState(0);return s.useEffect(()=>{const t={update:()=>{n(o=>o+1)}};return r.subscribe(t),()=>{r.unsubscribe(t)}},[r]),e},De=({state:r,actions:e})=>{const n=s.useRef(null),t=q(),o=U(),{handleKeyDown:l,handleInputChange:d,inputState:m,setInputStateWithLogging:i,getNextExpectedSegment:c}=He(),[p,g]=s.useState(!1),k=T(),v=Me(),h=async f=>{const _=l(f,r,e);await Promise.resolve(_)===!1&&(g(!0),setTimeout(()=>g(!1),500))},E=f=>{d(f.target.value,e)},u=f=>{f.preventDefault();const _=f.clipboardData.getData("text");d(_,e)};s.useEffect(()=>{n.current&&n.current.focus(),m!=="entering_command"&&i("entering_command")},[m,i]),s.useEffect(()=>{if(m!=="idle")return;const f=c();let _="idle";switch(f.type){case"word":_="entering_command",e.setIsEnteringArg(!1);break;case"argument":_="entering_argument",e.setIsEnteringArg(!0);break}i(_)},[v,m,c,i,e]);const w=s.useMemo(()=>{const f=[],_=o.toArray().map((I,A)=>{f.push(I.name);const j=t.hasNextSegment(f);if(I.type==="argument"){const F=I;return a.jsxs(s.Fragment,{children:[a.jsx("span",{className:"text-gray-200 whitespace-pre",children:F.value}),A<o.size()&&j&&a.jsx("span",{className:"text-gray-200 whitespace-pre",children:" "})]},"arg-"+F.name+F.value)}return a.jsxs(s.Fragment,{children:[a.jsx("span",{className:"text-blue-400 whitespace-pre",children:I.name}),A<o.size()&&j&&a.jsx("span",{className:"text-blue-400 whitespace-pre",children:" "})]},"word-"+I.name)});return[a.jsx("div",{className:"flex items-center gap-1","data-testid":"user-input-area",children:_},"{segmentStackVersion}")]},[v,t,o]),[b,C]=s.useState("");return s.useEffect(()=>{const f=c();f.type==="argument"?C(f.name):C("")},[v,c]),a.jsxs("div",{className:"flex flex-col w-full bg-gray-900 rounded-lg p-4",children:[a.jsx("style",{children:`
7
7
  @keyframes subtleGlow {
8
8
  0%, 100% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
9
9
  50% { box-shadow: 0 0 8px rgba(239, 68, 68, 0.6); }
@@ -11,7 +11,7 @@ Check the definition of the ${p.join(".")} command and update the return type fo
11
11
  .invalid-input-animation {
12
12
  animation: subtleGlow 0.4s ease-in-out;
13
13
  }
14
- `}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"text-gray-400 font-mono",children:">"}),a.jsxs("div",{className:"flex-1 font-mono flex items-center",children:[h,a.jsxs("div",{className:"relative flex-1",children:[a.jsx("input",{ref:n,type:"text",role:"textbox",value:r.currentInput,onChange:_,onKeyDown:C,onPaste:c,"data-testid":"citadel-command-input",className:`w-full bg-transparent outline-none text-gray-200 caret-transparent ${p?"invalid-input-animation":""}`,spellCheck:!1,autoComplete:"off",placeholder:N}),a.jsx("div",{className:"absolute top-0 pointer-events-none",style:{left:`${r.currentInput.length}ch`,transition:"left 0.05s ease-out"},children:a.jsx(Ie,{style:{type:S.cursorType??A.cursorType,color:S.cursorColor||A.cursorColor,speed:S.cursorSpeed||A.cursorSpeed}})})]})]})]})]})},Te=()=>{const r=$(),e=M(),n=j(),t="mt-2 border-t border-gray-700 px-4 py-2",o="text-gray-300",i=r.getCompletions(n.path());E.debug("[AvailableCommands] nextCommandSegments: ",i);const l=s.useMemo(()=>{const d=[...i],p=C=>C.name.toLowerCase()==="help",S=d.filter(C=>!p(C)).sort((C,_)=>C.name.localeCompare(_.name,void 0,{sensitivity:"base"}));if(!e.includeHelpCommand)return S;const b=d.find(p);return b?[...S,b]:S},[i,e.includeHelpCommand]),m=i.some(d=>d.type==="argument"),u=i[0];return a.jsx("div",{className:t,"data-testid":"available-commands",children:a.jsx("div",{className:o,children:m?i.length>0?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"text-blue-400",children:u.name}),u.description&&a.jsxs("span",{className:"text-gray-400 ml-2",children:["- ",u.description]})]}):null:a.jsx("div",{className:"flex flex-wrap gap-2",children:l==null?void 0:l.map(d=>{const p=l==null?void 0:l.reduce((g,S)=>{if(S===d)return g;let b=0;for(;b<d.name.length&&b<S.name.length&&d.name[b].toLowerCase()===S.name[b].toLowerCase();)b++;return Math.max(g,b+1)},1);return a.jsx("div",{className:"px-2 py-1 rounded bg-gray-800 mr-2 last:mr-0",children:a.jsxs("span",{className:"font-mono text-white",children:[a.jsx("strong",{className:"underline",children:d.name.slice(0,p)}),d.name.slice(p)]})},d.name)})})})})},le=({state:r,actions:e,outputRef:n})=>a.jsxs("div",{className:"innerContainer",children:[a.jsx("div",{className:"flex-1 min-h-0 pt-3 px-4",children:a.jsx(ze,{output:r.output,outputRef:n})}),a.jsxs("div",{children:[a.jsx(Me,{state:r,actions:e}),a.jsx(Te,{})]})]}),Ue=()=>{const[r,e]=s.useState(!1),[n,t]=s.useState(!1),o=M(),[i,l]=s.useState(()=>o.initialHeight||null),m=s.useRef(null),u=s.useRef(null),d=s.useRef(!1),p=s.useRef(0),g=s.useRef(0),{state:S,actions:b}=Y();Ee({onOpen:()=>e(!0),onClose:()=>t(!0),isVisible:r,showCitadelKey:o.showCitadelKey||"."});const C=s.useCallback(f=>{var k;if(!d.current)return;const N=f.clientY-p.current,y=(k=o.maxHeight)!=null&&k.endsWith("vh")?window.innerHeight*parseInt(o.maxHeight,10)/100:parseInt(o.maxHeight||"80vh",10),v=Math.min(Math.max(g.current-N,parseInt(o.minHeight||"200",10)),y);u.current&&(u.current.style.height=`${v}px`,u.current.style.bottom="0",l(`${v}px`))},[o.maxHeight,o.minHeight]),_=s.useCallback(()=>{d.current=!1,document.documentElement.style.userSelect="",document.documentElement.style.webkitUserSelect="",document.documentElement.style.mozUserSelect="",document.documentElement.style.msUserSelect="",document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",_)},[C]),c=s.useCallback(f=>{u.current&&(d.current=!0,p.current=f.clientY,g.current=u.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",C),document.addEventListener("mouseup",_))},[C,_]);s.useEffect(()=>()=>{document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",_)},[C,_]);const h=s.useCallback(()=>{n&&(e(!1),t(!1))},[n]);return _e({isVisible:r,isClosing:n,onAnimationComplete:h}),r?a.jsxs("div",{ref:u,className:`panelContainer ${r?"citadel_slideUp":""} ${n?"citadel_slideDown":""}`,style:{...i?{height:i}:void 0,maxHeight:o.maxHeight},children:[a.jsx("div",{className:"resizeHandle",onMouseDown:c}),a.jsx(le,{state:S,actions:b,outputRef:m})]}):null},je=()=>{const{state:r,actions:e}=Y(),n=s.useRef(null);return a.jsx("div",{className:"inlineContainer","data-testid":"citadel-inline-container",children:a.jsx(le,{state:r,actions:e,outputRef:n})})},ce=`:host {
14
+ `}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"text-gray-400 font-mono",children:">"}),a.jsxs("div",{className:"flex-1 font-mono flex items-center",children:[w,a.jsxs("div",{className:"relative flex-1",children:[a.jsx("input",{ref:n,type:"text",role:"textbox",value:r.currentInput,onChange:E,onKeyDown:h,onPaste:u,"data-testid":"citadel-command-input",className:`w-full bg-transparent outline-none text-gray-200 caret-transparent ${p?"invalid-input-animation":""}`,spellCheck:!1,autoComplete:"off",placeholder:b}),a.jsx("div",{className:"absolute top-0 pointer-events-none",style:{left:`${r.currentInput.length}ch`,transition:"left 0.05s ease-out"},children:a.jsx(ze,{style:{type:k.cursorType??N.cursorType,color:k.cursorColor||N.cursorColor,speed:k.cursorSpeed||N.cursorSpeed}})})]})]})]})]})},Te=()=>{const r=q(),e=U(),n="mt-2 border-t border-gray-700 px-4 py-2",t="text-gray-300",o=r.getCompletions(e.path());S.debug("[AvailableCommands] nextCommandSegments: ",o);const l=s.useMemo(()=>{const c=[...o],p=h=>h.name.toLowerCase()==="help",g=c.filter(p);return[...c.filter(h=>!p(h)).sort((h,E)=>h.name.localeCompare(E.name,void 0,{sensitivity:"base"})),...g]},[o]),d=s.useMemo(()=>{const c=new Map;for(const p of l){const g=l.reduce((k,v)=>{if(v===p)return k;let h=0;for(;h<p.name.length&&h<v.name.length&&p.name[h].toLowerCase()===v.name[h].toLowerCase();)h++;return Math.max(k,h+1)},1);c.set(p.name,g)}return c},[l]),m=o.some(c=>c.type==="argument"),i=o[0];return a.jsx("div",{className:n,"data-testid":"available-commands",children:a.jsx("div",{className:t,children:m?o.length>0?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"text-blue-400",children:i.name}),i.description&&a.jsxs("span",{className:"text-gray-400 ml-2",children:["- ",i.description]})]}):null:a.jsx("div",{className:"flex flex-wrap gap-2",children:l==null?void 0:l.map(c=>{const p=d.get(c.name)??1;return a.jsx("div",{className:"px-2 py-1 rounded bg-gray-800 mr-2 last:mr-0",children:a.jsxs("span",{className:"font-mono text-white",children:[a.jsx("strong",{className:"underline",children:c.name.slice(0,p)}),c.name.slice(p)]})},c.name)})})})})},de=({state:r,actions:e,outputRef:n})=>a.jsxs("div",{className:"innerContainer",children:[a.jsx("div",{className:"flex-1 min-h-0 pt-3 px-4",children:a.jsx(Ie,{output:r.output,outputRef:n})}),a.jsxs("div",{children:[a.jsx(De,{state:r,actions:e}),a.jsx(Te,{})]})]}),Ue=()=>{const[r,e]=s.useState(!1),[n,t]=s.useState(!1),o=T(),[l,d]=s.useState(()=>o.initialHeight||null),m=s.useRef(null),i=s.useRef(null),c=s.useRef(!1),p=s.useRef(0),g=s.useRef(0),{state:k,actions:v}=G();Ee({onOpen:()=>e(!0),onClose:()=>t(!0),isVisible:r,showCitadelKey:o.showCitadelKey||"."});const h=s.useCallback(b=>{var I;if(!c.current)return;const C=b.clientY-p.current,f=(I=o.maxHeight)!=null&&I.endsWith("vh")?window.innerHeight*parseInt(o.maxHeight,10)/100:parseInt(o.maxHeight||"80vh",10),_=Math.min(Math.max(g.current-C,parseInt(o.minHeight||"200",10)),f);i.current&&(i.current.style.height=`${_}px`,i.current.style.bottom="0",d(`${_}px`))},[o.maxHeight,o.minHeight]),E=s.useCallback(()=>{c.current=!1,document.documentElement.style.userSelect="",document.documentElement.style.webkitUserSelect="",document.documentElement.style.mozUserSelect="",document.documentElement.style.msUserSelect="",document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",E)},[h]),u=s.useCallback(b=>{i.current&&(c.current=!0,p.current=b.clientY,g.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",h),document.addEventListener("mouseup",E))},[h,E]);s.useEffect(()=>()=>{document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",E)},[h,E]);const w=s.useCallback(()=>{n&&(e(!1),t(!1))},[n]);return Ne({isVisible:r,isClosing:n,onAnimationComplete:w}),r?a.jsxs("div",{ref:i,className:`panelContainer ${r?"citadel_slideUp":""} ${n?"citadel_slideDown":""}`,style:{...l?{height:l}:void 0,maxHeight:o.maxHeight},children:[a.jsx("div",{className:"resizeHandle",onMouseDown:u}),a.jsx(de,{state:k,actions:v,outputRef:m})]}):null},je=()=>{const{state:r,actions:e}=G(),n=s.useRef(null);return a.jsx("div",{className:"inlineContainer","data-testid":"citadel-inline-container",children:a.jsx(de,{state:r,actions:e,outputRef:n})})},me=`:host {
15
15
  --citadel-bg: rgb(17, 24, 39);
16
16
  --citadel-text: rgba(255, 255, 255, 0.87);
17
17
  --citadel-border: rgb(55, 65, 81);
@@ -115,7 +115,7 @@ a:hover {
115
115
  .text-left {
116
116
  text-align: left;
117
117
  }
118
- `,de=`/* Keep only component-specific styles here */
118
+ `,ue=`/* Keep only component-specific styles here */
119
119
 
120
120
  .panelContainer {
121
121
  position: fixed;
@@ -197,7 +197,7 @@ a:hover {
197
197
  overflow: hidden;
198
198
  box-sizing: border-box;
199
199
  }
200
- `,me=`@tailwind base;
200
+ `,he=`@tailwind base;
201
201
  @tailwind components;
202
202
  @tailwind utilities;
203
203
  `,Fe=`*, ::before, ::after {
@@ -1017,5 +1017,5 @@ video {
1017
1017
  .last\\:mr-0:last-child {
1018
1018
  margin-right: 0px;
1019
1019
  }
1020
- `,Oe=({config:r=A,commandRegistry:e=new L,containerId:n=null})=>{const t=s.useRef(null),o=r.displayMode??A.displayMode??"panel";return s.useEffect(()=>{E.configure({level:r.logLevel||A.logLevel||F.ERROR,prefix:"[Citadel]"});const i=new ue(e,r),l=o==="inline"&&!n,m=l?t.current:n?document.getElementById(n):document.body;if(m)m.appendChild(i);else{if(l){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(i)}return()=>{var u;(u=i.parentElement)==null||u.removeChild(i)}},[e,n,r,o]),o==="inline"&&!n?a.jsx("div",{ref:t,style:{width:"100%",height:"100%"}}):null};class ue extends HTMLElement{constructor(n,t){var i;super();x(this,"shadow");x(this,"root",null);x(this,"commandRegistry");x(this,"config");this.shadow=this.attachShadow({mode:"open"}),this.commandRegistry=n,this.config=t;const o=((i=this.config)==null?void 0:i.displayMode)??"panel";this.setAttribute("data-display-mode",o)}connectedCallback(){try{const t=[ce,de,me,Fe].map(o=>{const i=new CSSStyleSheet;return i.replaceSync(o),i});this.shadow.adoptedStyleSheets=[...t]}catch{const t=[ce,de,me].join(`
1021
- `),o=document.createElement("style");o.textContent=t,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=pe.createRoot(n),this.root.render(a.jsx(Se,{config:this.config||A,commandRegistry:this.commandRegistry,children:a.jsx(Le,{})}))}}customElements.define("citadel-element",ue);const Le=()=>(M().displayMode??"panel")==="inline"?a.jsx(je,{}):a.jsx(Ue,{});w.Citadel=Oe,w.CommandRegistry=L,w.CommandResult=P,w.CommandStatus=D,w.DEFAULT_CURSOR_CONFIGS=oe,w.ErrorCommandResult=G,w.ImageCommandResult=ge,w.JsonCommandResult=he,w.OutputItem=ne,w.PendingCommandResult=J,w.TextCommandResult=V,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
1020
+ `,Oe=({config:r=N,commandRegistry:e=new K,containerId:n=null})=>{const t=s.useRef(null),o=r.displayMode??N.displayMode??"panel";return s.useEffect(()=>{S.configure({level:r.logLevel||N.logLevel||Y.ERROR,prefix:"[Citadel]"});const l=new pe(e,r),d=o==="inline"&&!n,m=d?t.current:n?document.getElementById(n):document.body;if(m)m.appendChild(l);else{if(d){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 i;(i=l.parentElement)==null||i.removeChild(l)}},[e,n,r,o]),o==="inline"&&!n?a.jsx("div",{ref:t,style:{width:"100%",height:"100%"}}):null};class pe extends HTMLElement{constructor(n,t){var l;super();x(this,"shadow");x(this,"root",null);x(this,"commandRegistry");x(this,"config");this.shadow=this.attachShadow({mode:"open"}),this.commandRegistry=n,this.config=t;const o=((l=this.config)==null?void 0:l.displayMode)??"panel";this.setAttribute("data-display-mode",o)}connectedCallback(){try{const t=[me,ue,he,Fe].map(o=>{const l=new CSSStyleSheet;return l.replaceSync(o),l});this.shadow.adoptedStyleSheets=[...t]}catch{const t=[me,ue,he].join(`
1021
+ `),o=document.createElement("style");o.textContent=t,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=ge.createRoot(n),this.root.render(a.jsx(Se,{config:this.config||N,commandRegistry:this.commandRegistry,children:a.jsx(Le,{})}))}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",pe);const Le=()=>(T().displayMode??"panel")==="inline"?a.jsx(je,{}):a.jsx(Ue,{});y.Citadel=Oe,y.CommandRegistry=K,y.CommandResult=P,y.CommandStatus=H,y.DEFAULT_CURSOR_CONFIGS=ae,y.ErrorCommandResult=J,y.ImageCommandResult=we,y.JsonCommandResult=fe,y.OutputItem=W,y.PendingCommandResult=Q,y.TextCommandResult=O,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
@@ -24,5 +24,6 @@ export declare class CitadelElement extends HTMLElement {
24
24
  private config?;
25
25
  constructor(commandRegistry: CommandRegistry, config?: CitadelConfig);
26
26
  connectedCallback(): void;
27
+ disconnectedCallback(): void;
27
28
  }
28
29
  export {};
@@ -23,7 +23,7 @@ export interface CitadelConfig {
23
23
  */
24
24
  cursorType?: CursorType;
25
25
  /**
26
- * Whether to include the default help command in the command regsitry.
26
+ * Whether to include the default help command in the command registry.
27
27
  */
28
28
  includeHelpCommand?: boolean;
29
29
  /**
@@ -2,6 +2,4 @@ import { CitadelState, CitadelActions } from '../types/state';
2
2
  export declare const useCitadelState: () => {
3
3
  state: CitadelState;
4
4
  actions: CitadelActions;
5
- getAvailableCommands_s: () => string[];
6
- getAvailableCommandSegments: () => import('../types/command-registry').CommandSegment[];
7
5
  };
@@ -7,7 +7,7 @@ export interface CommandHistory {
7
7
  export interface CommandHistoryActions {
8
8
  addStoredCommand: (segments: CommandSegment[]) => Promise<void>;
9
9
  getStoredCommands: () => Promise<StoredCommand[]>;
10
- navigateHistory: (direction: 'up' | 'down', currentSegments: CommandSegment[]) => Promise<{
10
+ navigateHistory: (direction: 'up' | 'down') => Promise<{
11
11
  segments: CommandSegment[] | null;
12
12
  position: number | null;
13
13
  }>;
@@ -18,7 +18,7 @@ export interface CommandHistoryHook {
18
18
  history: CommandHistory;
19
19
  addStoredCommand: (segments: CommandSegment[]) => Promise<void>;
20
20
  getStoredCommands: () => Promise<StoredCommand[]>;
21
- navigateHistory: (direction: 'up' | 'down', currentSegments: CommandSegment[]) => Promise<{
21
+ navigateHistory: (direction: 'up' | 'down') => Promise<{
22
22
  segments: CommandSegment[] | null;
23
23
  position: number | null;
24
24
  }>;
@@ -3,6 +3,7 @@ export declare class StorageFactory {
3
3
  private static instance;
4
4
  private currentStorage?;
5
5
  private constructor();
6
+ static reset(): void;
6
7
  static getInstance(): StorageFactory;
7
8
  initializeStorage(config: StorageConfig): void;
8
9
  getStorage(): CommandStorage;
@@ -87,7 +87,7 @@ export declare class CommandRegistry {
87
87
  * @param path The path to get completions for.
88
88
  * @returns An array of completion strings.
89
89
  */
90
- getCompletions_s(path: string[]): string[];
90
+ getCompletionNames(path: string[]): string[];
91
91
  /**
92
92
  * Gets an array of segments reachable from a given path
93
93
  *
@@ -19,6 +19,8 @@ export interface CitadelActions {
19
19
  clearHistory: () => Promise<void>;
20
20
  }
21
21
  export declare class OutputItem {
22
+ private static idCounter;
23
+ readonly id: string;
22
24
  readonly timestamp: number;
23
25
  readonly command: string[];
24
26
  result: CommandResult;
@@ -0,0 +1,12 @@
1
+ import { CommandRegistry } from '../components/Citadel/types/command-registry';
2
+ import { CursorType } from '../components/Citadel/types/cursor';
3
+ export type DisplayMode = 'panel' | 'inline';
4
+ export declare const RUNTIME_CONFIG_CURSOR_TYPES: readonly CursorType[];
5
+ export interface RuntimeConfigControls {
6
+ setCursorType: (type: CursorType) => void;
7
+ setCursorColor: (color: string) => void;
8
+ setDisplayMode: (mode: DisplayMode) => void;
9
+ setIncludeHelpCommand: (enabled: boolean) => void;
10
+ resetConfig: () => void;
11
+ }
12
+ export declare function registerRuntimeConfigCommands(registry: CommandRegistry, controls: RuntimeConfigControls): void;
@@ -0,0 +1,13 @@
1
+ import { CitadelConfig } from '../components/Citadel/config/types';
2
+ import { CommandRegistry } from '../components/Citadel/types/command-registry';
3
+ import { DisplayMode } from './runtimeConfigCommands';
4
+ interface UseRuntimeConfigDemoResult {
5
+ commandRegistry: CommandRegistry;
6
+ config: CitadelConfig;
7
+ mode: DisplayMode;
8
+ }
9
+ export declare const useRuntimeConfigDemo: (options?: {
10
+ initialMode?: DisplayMode;
11
+ initialIncludeHelp?: boolean;
12
+ }) => UseRuntimeConfigDemoResult;
13
+ export {};
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "type": "git",
18
18
  "url": "git+https://github.com/jchilders/citadel_cli.git"
19
19
  },
20
- "version": "1.1.6",
20
+ "version": "1.1.7",
21
21
  "type": "module",
22
22
  "scripts": {
23
23
  "build": "tsc && vite build",