citadel_cli 1.1.5 → 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,11 +1,11 @@
1
- var ge = Object.defineProperty;
2
- var fe = (r, e, n) => e in r ? ge(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
3
- var b = (r, e, n) => fe(r, typeof e != "symbol" ? e + "" : e, n);
4
- import { jsx as m, jsxs as _, Fragment as we } from "react/jsx-runtime";
5
- import L, { createContext as be, useEffect as A, useContext as Y, useState as R, useCallback as w, useMemo as V, useReducer as ye, useRef as H } from "react";
6
- import { createRoot as xe } from "react-dom/client";
7
- var T = /* @__PURE__ */ ((r) => (r.Pending = "pending", r.Success = "success", r.Failure = "failure", r.Timeout = "timeout", r))(T || {});
8
- class U {
1
+ var ye = Object.defineProperty;
2
+ var xe = (r, e, n) => e in r ? ye(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
3
+ var b = (r, e, n) => xe(r, typeof e != "symbol" ? e + "" : e, n);
4
+ import { jsx as m, jsxs as N, Fragment as ve } from "react/jsx-runtime";
5
+ import O, { createContext as Ce, useState as R, useEffect as A, useMemo as D, useContext as Y, useCallback as y, useReducer as Se, useRef as H } from "react";
6
+ import { createRoot as ke } from "react-dom/client";
7
+ var F = /* @__PURE__ */ ((r) => (r.Pending = "pending", r.Success = "success", r.Failure = "failure", r.Timeout = "timeout", r))(F || {});
8
+ class T {
9
9
  constructor(e = Date.now()) {
10
10
  b(this, "_status", "pending");
11
11
  this.timestamp = e;
@@ -23,7 +23,7 @@ class U {
23
23
  this._status = "timeout";
24
24
  }
25
25
  }
26
- class an extends U {
26
+ class ln extends T {
27
27
  constructor(e, n) {
28
28
  super(n), this.data = e;
29
29
  }
@@ -31,7 +31,7 @@ class an extends U {
31
31
  return /* @__PURE__ */ m("pre", { className: "text-gray-200", children: JSON.stringify(this.data, null, 2) });
32
32
  }
33
33
  }
34
- class ae extends U {
34
+ class G extends T {
35
35
  constructor(e, n) {
36
36
  super(n), this.text = e;
37
37
  }
@@ -39,7 +39,7 @@ class ae extends U {
39
39
  return /* @__PURE__ */ m("div", { className: "text-gray-200 whitespace-pre font-mono", children: this.text });
40
40
  }
41
41
  }
42
- class ve extends U {
42
+ class Ne extends T {
43
43
  constructor(e, n) {
44
44
  super(n), this.error = e, this.markFailure();
45
45
  }
@@ -47,12 +47,12 @@ class ve extends U {
47
47
  return /* @__PURE__ */ m("div", { className: "mt-1 text-red-400", children: this.error });
48
48
  }
49
49
  }
50
- class Ce extends U {
50
+ class Ee extends T {
51
51
  render() {
52
52
  return /* @__PURE__ */ m("div", { className: "text-gray-400", children: "..." });
53
53
  }
54
54
  }
55
- class ln extends U {
55
+ class cn extends T {
56
56
  constructor(e, n = "", t) {
57
57
  super(t), this.imageUrl = e, this.altText = n;
58
58
  }
@@ -67,24 +67,27 @@ class ln extends U {
67
67
  ) });
68
68
  }
69
69
  }
70
- const Se = (r) => async function() {
70
+ const _e = (r) => async function() {
71
71
  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();
72
- return e.push("help - Show available commands"), new ae(
73
- e.length > 0 ? `Available Commands:
72
+ return e.length === 0 ? new G(
73
+ "No commands available yet. Add some commands to get started!"
74
+ ) : (e.push("help - Show available commands"), new G(
75
+ `Available Commands:
74
76
  ` + e.join(`
75
- `) : "No commands available yet. Add some commands to get started!"
76
- );
77
+ `)
78
+ ));
77
79
  };
78
- var W = /* @__PURE__ */ ((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))(W || {});
80
+ var Q = /* @__PURE__ */ ((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))(Q || {});
81
+ const ne = !0;
79
82
  class C {
80
83
  static configure(e) {
81
84
  this.level = e.level, this.prefix = e.prefix || "[Citadel]";
82
85
  }
83
86
  static trace(...e) {
84
- this.level >= 5 && process.env.NODE_ENV !== "production" && console.trace(this.prefix, ...e);
87
+ this.level >= 5 && !ne && console.trace(this.prefix, ...e);
85
88
  }
86
89
  static debug(...e) {
87
- this.level >= 4 && process.env.NODE_ENV !== "production" && console.debug(this.prefix, ...e);
90
+ this.level >= 4 && !ne && console.debug(this.prefix, ...e);
88
91
  }
89
92
  static info(...e) {
90
93
  this.level >= 3 && console.info(this.prefix, ...e);
@@ -97,14 +100,14 @@ class C {
97
100
  }
98
101
  }
99
102
  b(C, "level", 0), b(C, "prefix", "");
100
- const z = {
103
+ const _ = {
101
104
  commandTimeoutMs: 1e4,
102
105
  cursorColor: "var(--cursor-color, #fff)",
103
106
  cursorSpeed: 530,
104
107
  cursorType: "blink",
105
108
  includeHelpCommand: !0,
106
109
  initialHeight: "40vh",
107
- logLevel: process.env.NODE_ENV === "production" ? W.ERROR : W.DEBUG,
110
+ logLevel: Q.ERROR,
108
111
  maxHeight: "80vh",
109
112
  minHeight: "200",
110
113
  outputFontSize: "0.875rem",
@@ -116,7 +119,7 @@ const z = {
116
119
  maxCommands: 100
117
120
  }
118
121
  };
119
- class ie {
122
+ class de {
120
123
  constructor(e) {
121
124
  b(this, "config");
122
125
  this.config = {
@@ -135,7 +138,7 @@ class ie {
135
138
  await this.saveCommands(n);
136
139
  }
137
140
  }
138
- class ke extends ie {
141
+ class Ae extends de {
139
142
  constructor(n) {
140
143
  super(n);
141
144
  b(this, "storageKey", "citadel_command_history");
@@ -170,7 +173,7 @@ class ke extends ie {
170
173
  }
171
174
  }
172
175
  }
173
- class Ee extends ie {
176
+ class te extends de {
174
177
  constructor(n) {
175
178
  super(n);
176
179
  b(this, "storedCommands", []);
@@ -191,20 +194,22 @@ class Ee extends ie {
191
194
  }));
192
195
  }
193
196
  }
194
- const D = class D {
197
+ const P = class P {
195
198
  constructor() {
196
199
  b(this, "currentStorage");
197
200
  }
201
+ static reset() {
202
+ P.instance = void 0;
203
+ }
198
204
  static getInstance() {
199
- return D.instance || (D.instance = new D()), D.instance;
205
+ return P.instance || (P.instance = new P()), P.instance;
200
206
  }
201
207
  initializeStorage(e) {
202
- if (!this.currentStorage)
203
- try {
204
- this.currentStorage = new ke(e);
205
- } catch (n) {
206
- console.warn("Failed to create storage, falling back to memory storage:", n), this.currentStorage = new Ee(e);
207
- }
208
+ try {
209
+ e.type === "memory" ? this.currentStorage = new te(e) : this.currentStorage = new Ae(e);
210
+ } catch (n) {
211
+ console.warn("Failed to create storage, falling back to memory storage:", n), this.currentStorage = new te(e);
212
+ }
208
213
  }
209
214
  getStorage() {
210
215
  if (!this.currentStorage)
@@ -212,10 +217,10 @@ const D = class D {
212
217
  return this.currentStorage;
213
218
  }
214
219
  };
215
- b(D, "instance");
216
- let q = D;
217
- const le = async () => new ae("");
218
- class J {
220
+ b(P, "instance");
221
+ let q = P;
222
+ const me = async () => new G("");
223
+ class X {
219
224
  constructor(e, n, t) {
220
225
  this.type = e, this.name = n, this.description = t;
221
226
  }
@@ -223,23 +228,23 @@ class J {
223
228
  return this.name;
224
229
  }
225
230
  }
226
- class ce extends J {
231
+ class ue extends X {
227
232
  constructor() {
228
233
  super("null", ">null<", "Empty segment");
229
234
  }
230
235
  }
231
- class Ne extends J {
236
+ class ze extends X {
232
237
  constructor(e, n) {
233
238
  super("word", e, n);
234
239
  }
235
240
  }
236
- class _e extends J {
241
+ class W extends X {
237
242
  constructor(e, n, t, o) {
238
243
  super("argument", e, n), this.value = t, this.valid = o;
239
244
  }
240
245
  }
241
- class Ae {
242
- constructor(e, n, t = le) {
246
+ class Ie {
247
+ constructor(e, n, t = me) {
243
248
  b(this, "_segments");
244
249
  b(this, "_description");
245
250
  // Used by `Help` command, etc.
@@ -268,7 +273,7 @@ class Ae {
268
273
  return this.fullPath.join(" ") === e.fullPath.join(" ");
269
274
  }
270
275
  }
271
- class Q {
276
+ class Z {
272
277
  constructor() {
273
278
  b(this, "_commands", []);
274
279
  }
@@ -286,21 +291,31 @@ class Q {
286
291
  * @param handler Async handler executed when the command is submitted; defaults to `NoopHandler`.
287
292
  * @throws {Error} If the segment list is empty or the path collides with an existing command.
288
293
  */
289
- addCommand(e, n, t = le) {
294
+ addCommand(e, n, t = me) {
290
295
  if (e === void 0 || e.length === 0)
291
296
  throw new Error("Command path cannot be empty");
292
- const o = new Ae(e, n, t), s = this._commands.find((a) => {
293
- const l = a.segments.map(
294
- (c) => c.type === "argument" ? "*" : c.name
295
- ).join(" "), d = e.map(
296
- (c) => c.type === "argument" ? "*" : c.name
297
+ const o = new Ie(e, n, t), a = this._commands.find((i) => {
298
+ const c = i.segments.map(
299
+ (l) => l.type === "argument" ? "*" : l.name
300
+ ).join(" "), s = e.map(
301
+ (l) => l.type === "argument" ? "*" : l.name
297
302
  ).join(" ");
298
- return l === d;
303
+ return c === s;
299
304
  });
300
- if (s)
301
- throw new Error(`Duplicate commands: '${s.fullPath_s}' and '${o.fullPath_s}'`);
305
+ if (a)
306
+ throw new Error(`Duplicate commands: '${a.fullPath_s}' and '${o.fullPath_s}'`);
302
307
  this._commands.push(o);
303
308
  }
309
+ /**
310
+ * Removes a command that exactly matches the provided path.
311
+ *
312
+ * @param path The command path to remove.
313
+ * @returns True if a command was removed; otherwise false.
314
+ */
315
+ removeCommand(e) {
316
+ const n = e.join(" "), t = this._commands.findIndex((o) => o.fullPath.join(" ") === n);
317
+ return t === -1 ? !1 : (this._commands.splice(t, 1), !0);
318
+ }
304
319
  /**
305
320
  * Retrieves a command from the registry for the given path.
306
321
  *
@@ -312,19 +327,19 @@ class Q {
312
327
  const t = n.fullPath.join(" "), o = e.join(" ");
313
328
  if (t === o)
314
329
  return !0;
315
- const a = n.segments.filter((l) => l.type === "word").map((l) => l.name);
316
- return a.length === e.length && a.join(" ") === o;
330
+ const i = n.segments.filter((c) => c.type === "word").map((c) => c.name);
331
+ return i.length === e.length && i.join(" ") === o;
317
332
  });
318
333
  }
319
334
  commandExistsForPath(e) {
320
335
  const n = this._commands.map(
321
336
  (o) => o.segments.map(
322
- (s) => s.type === "argument" ? "*" : s.name
337
+ (a) => a.type === "argument" ? "*" : a.name
323
338
  ).join(" ")
324
- ), t = e.map((o, s) => this._commands.some(
325
- (l) => {
326
- var d;
327
- return ((d = l.segments[s]) == null ? void 0 : d.type) === "argument";
339
+ ), t = e.map((o, a) => this._commands.some(
340
+ (c) => {
341
+ var s;
342
+ return ((s = c.segments[a]) == null ? void 0 : s.type) === "argument";
328
343
  }
329
344
  ) ? "*" : o).join(" ");
330
345
  return n.includes(t);
@@ -335,8 +350,7 @@ class Q {
335
350
  * @param path The path to get completions for.
336
351
  * @returns An array of completion strings.
337
352
  */
338
- // used by AvailableCommands
339
- getCompletions_s(e) {
353
+ getCompletionNames(e) {
340
354
  return this.getCompletions(e).map((n) => n.name);
341
355
  }
342
356
  /**
@@ -347,28 +361,28 @@ class Q {
347
361
  */
348
362
  getCompletions(e) {
349
363
  if (C.debug("[getCompletions] path: ", e), !e.length) {
350
- const s = this._commands.map((d) => d.segments[0]), a = (d, c) => d.type === c.type && d.name === c.name;
351
- return s.filter(
352
- (d, c, u) => c === u.findIndex((p) => a(p, d))
364
+ const a = this._commands.map((s) => s.segments[0]), i = (s, l) => s.type === l.type && s.name === l.name;
365
+ return a.filter(
366
+ (s, l, h) => l === h.findIndex((p) => i(p, s))
353
367
  );
354
368
  }
355
369
  const n = e.length;
356
- return this._commands.filter((s) => {
357
- const a = s.segments;
358
- if (a.length <= n - 1)
370
+ return this._commands.filter((a) => {
371
+ const i = a.segments;
372
+ if (i.length <= n - 1)
359
373
  return !1;
360
- for (let l = 0; l < n; l++) {
361
- const d = e[l], c = a[l];
362
- if (!(d === "*" && c.type === "argument") && d !== c.name)
374
+ for (let c = 0; c < n; c++) {
375
+ const s = e[c], l = i[c];
376
+ if (!(s === "*" && l.type === "argument") && s !== l.name)
363
377
  return !1;
364
378
  }
365
379
  return !0;
366
- }).filter((s) => s.segments.length > n).map((s) => {
367
- const a = s.segments[n], l = a.type === "argument" ? _e : Ne;
368
- return new l(a.name, a.description);
380
+ }).filter((a) => a.segments.length > n).map((a) => {
381
+ const i = a.segments[n], c = i.type === "argument" ? W : ze;
382
+ return new c(i.name, i.description);
369
383
  }).filter(
370
- (s, a, l) => a === l.findIndex(
371
- (d) => d.type === s.type && d.name === s.name
384
+ (a, i, c) => i === c.findIndex(
385
+ (s) => s.type === a.type && s.name === a.name
372
386
  )
373
387
  );
374
388
  }
@@ -376,10 +390,10 @@ class Q {
376
390
  return this.getCompletions(e).length > 0;
377
391
  }
378
392
  }
379
- class de {
393
+ class he {
380
394
  constructor() {
381
395
  b(this, "segments", []);
382
- b(this, "nullSegment", new ce());
396
+ b(this, "nullSegment", new ue());
383
397
  b(this, "observers", []);
384
398
  }
385
399
  subscribe(e) {
@@ -463,147 +477,167 @@ class de {
463
477
  return [...this.segments];
464
478
  }
465
479
  }
466
- const ze = {
467
- config: z,
468
- commands: new Q(),
469
- segmentStack: new de()
470
- }, j = be(ze), Ie = ({ config: r = z, commandRegistry: e, children: n }) => {
471
- const [t, o] = L.useState(), s = {
472
- ...z,
480
+ const Re = {
481
+ config: _,
482
+ commands: new Z(),
483
+ segmentStack: new he()
484
+ }, L = Ce(Re), Pe = ({ config: r = _, commandRegistry: e, children: n }) => {
485
+ const [t, o] = O.useState(), [a] = R(() => new he()), i = {
486
+ ..._,
473
487
  ...r,
474
488
  // Ensure nested objects are properly merged
475
489
  storage: {
476
- ...z.storage,
490
+ ..._.storage,
477
491
  ...r.storage
478
492
  },
479
493
  // Ensure explicit values from config take precedence
480
- cursorType: r.cursorType ?? z.cursorType,
481
- cursorColor: r.cursorColor ?? z.cursorColor,
482
- cursorSpeed: r.cursorSpeed ?? z.cursorSpeed,
494
+ cursorType: r.cursorType ?? _.cursorType,
495
+ cursorColor: r.cursorColor ?? _.cursorColor,
496
+ cursorSpeed: r.cursorSpeed ?? _.cursorSpeed,
483
497
  showCitadelKey: r.showCitadelKey || "."
484
498
  };
485
499
  A(() => {
486
500
  q.getInstance().initializeStorage(
487
- s.storage ?? z.storage
501
+ i.storage ?? _.storage
488
502
  ), o(q.getInstance().getStorage());
489
503
  }, []), A(() => {
490
- if (e && s.includeHelpCommand && !e.commandExistsForPath(["help"])) {
491
- const l = Se(e);
492
- e.addCommand(
493
- [{ type: "word", name: "help" }],
494
- "Show available commands",
495
- l
496
- );
504
+ if (e) {
505
+ if (i.includeHelpCommand) {
506
+ if (!e.commandExistsForPath(["help"])) {
507
+ const s = _e(e);
508
+ e.addCommand(
509
+ [{ type: "word", name: "help" }],
510
+ "Show available commands",
511
+ s
512
+ );
513
+ }
514
+ return;
515
+ }
516
+ e.removeCommand(["help"]);
497
517
  }
498
- }, [e, s.includeHelpCommand]);
499
- const a = {
500
- config: s,
501
- commands: e || new Q(),
518
+ }, [e, i.includeHelpCommand]);
519
+ const c = D(() => ({
520
+ config: i,
521
+ commands: e || new Z(),
502
522
  storage: t,
503
- segmentStack: new de()
504
- };
505
- return /* @__PURE__ */ m(j.Provider, { value: a, children: n });
506
- }, F = () => {
507
- const r = Y(j);
523
+ segmentStack: a
524
+ }), [i, e, t, a]);
525
+ return /* @__PURE__ */ m(L.Provider, { value: c, children: n });
526
+ }, $ = () => {
527
+ const r = Y(L);
508
528
  if (r === void 0)
509
529
  throw new Error("useCitadelConfig must be used within a CitadelConfigProvider");
510
530
  return r.config;
511
531
  }, B = () => {
512
- const r = Y(j);
532
+ const r = Y(L);
513
533
  if (r === void 0)
514
534
  throw new Error("useCitadelCommands must be used within a CitadelConfigProvider");
515
535
  return r.commands;
516
- }, me = () => {
517
- const r = Y(j);
536
+ }, pe = () => {
537
+ const r = Y(L);
518
538
  if (r === void 0)
519
539
  throw new Error("useCitadelStorage must be used within a CitadelConfigProvider");
520
540
  return r.storage;
521
- }, O = () => {
522
- const r = Y(j);
541
+ }, K = () => {
542
+ const r = Y(L);
523
543
  if (r === void 0)
524
544
  throw new Error("useSegmentStack must be used within a CitadelConfigProvider");
525
545
  return r.segmentStack;
526
- };
527
- class Re {
546
+ }, V = class V {
528
547
  constructor(e, n) {
548
+ b(this, "id");
529
549
  b(this, "timestamp");
530
550
  b(this, "command");
531
551
  b(this, "result");
532
- this.command = e.toArray().map((t) => t.type === "argument" ? t.value || "" : t.name), this.timestamp = Date.now(), this.result = n ?? new Ce();
552
+ 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 Ee();
533
553
  }
534
- }
535
- function Pe(r) {
554
+ };
555
+ b(V, "idCounter", 0);
556
+ let J = V;
557
+ function He(r) {
536
558
  return {
537
559
  commandSegments: r,
538
560
  timestamp: Date.now()
539
561
  };
540
562
  }
541
- function ue() {
542
- const r = me(), [e, n] = R({
563
+ function ge() {
564
+ const r = pe(), [e, n] = R({
543
565
  storedCommands: [],
544
566
  position: null
545
- }), t = w(async (l) => {
567
+ }), t = y(async (c) => {
546
568
  if (r)
547
569
  try {
548
- const d = Pe(l);
549
- await r.addStoredCommand(d), n((c) => ({
550
- ...c,
551
- storedCommands: [...c.storedCommands, d],
570
+ const s = He(c);
571
+ await r.addStoredCommand(s), n((l) => ({
572
+ ...l,
573
+ storedCommands: [...l.storedCommands, s],
552
574
  position: null
553
575
  }));
554
- } catch (d) {
555
- console.warn("Failed to save command to history:", d);
576
+ } catch (s) {
577
+ console.warn("Failed to save command to history:", s);
556
578
  }
557
- }, [r]), o = w(async () => r ? await r.getStoredCommands() : [], [r]);
579
+ }, [r]), o = y(async () => r ? await r.getStoredCommands() : [], [r]);
558
580
  A(() => {
559
581
  if (!r) return;
560
582
  (async () => {
561
583
  try {
562
- const d = await r.getStoredCommands();
563
- return n((c) => ({
564
- ...c,
565
- storedCommands: d
566
- })), d;
567
- } catch (d) {
568
- console.warn("Failed to load command history:", d);
584
+ const s = await r.getStoredCommands();
585
+ return n((l) => ({
586
+ ...l,
587
+ storedCommands: s
588
+ })), s;
589
+ } catch (s) {
590
+ console.warn("Failed to load command history:", s);
569
591
  }
570
592
  })();
571
593
  }, [r]);
572
- const s = w(async (l) => {
573
- if ((await o()).length === 0)
574
- return { segments: null, position: null };
575
- let c = null;
576
- return l === "up" ? e.position === null ? c = e.storedCommands.length - 1 : e.position > 0 ? c = e.position - 1 : c = 0 : e.position === null || e.position >= e.storedCommands.length - 1 ? c = null : c = e.position + 1, n((p) => ({
594
+ const a = y(async (c) => {
595
+ const s = await o();
596
+ if (s.length === 0)
597
+ return n((p) => ({
598
+ ...p,
599
+ storedCommands: [],
600
+ position: null
601
+ })), { segments: null, position: null };
602
+ let l = null;
603
+ if (c === "up" ? e.position === null ? l = s.length - 1 : e.position > 0 ? l = e.position - 1 : l = 0 : e.position === null || e.position >= s.length - 1 ? l = null : l = e.position + 1, n((p) => ({
577
604
  ...p,
578
- position: c
579
- })), c === null ? {
605
+ storedCommands: s,
606
+ position: l
607
+ })), l === null)
608
+ return {
609
+ segments: [],
610
+ position: null
611
+ };
612
+ const h = s[l];
613
+ return h ? {
614
+ segments: h.commandSegments,
615
+ position: l
616
+ } : {
580
617
  segments: [],
581
618
  position: null
582
- } : {
583
- segments: c !== null ? e.storedCommands[c].commandSegments : null,
584
- position: c
585
619
  };
586
- }, [e, o]), a = w(async () => {
620
+ }, [e.position, o]), i = y(async () => {
587
621
  try {
588
622
  if (!r) return;
589
623
  await r.clear(), n({
590
624
  storedCommands: [],
591
625
  position: null
592
626
  });
593
- } catch (l) {
594
- console.warn("Failed to clear command history:", l);
627
+ } catch (c) {
628
+ console.warn("Failed to clear command history:", c);
595
629
  }
596
630
  }, [r]);
597
631
  return {
598
632
  history: e,
599
633
  addStoredCommand: t,
600
634
  getStoredCommands: o,
601
- navigateHistory: s,
602
- clear: a
635
+ navigateHistory: a,
636
+ clear: i
603
637
  };
604
638
  }
605
- const X = () => {
606
- const r = F(), e = B(), n = ue(), t = O(), o = me(), [s, a] = R({
639
+ const ee = () => {
640
+ const r = $(), e = B(), n = ge(), t = K(), o = pe(), [a, i] = R({
607
641
  currentInput: "",
608
642
  isEnteringArg: !1,
609
643
  output: [],
@@ -615,8 +649,8 @@ const X = () => {
615
649
  });
616
650
  A(() => {
617
651
  }, [o]), A(() => {
618
- a((u) => ({
619
- ...u,
652
+ i((s) => ({
653
+ ...s,
620
654
  history: {
621
655
  commands: n.history.storedCommands,
622
656
  position: n.history.position,
@@ -624,105 +658,100 @@ const X = () => {
624
658
  }
625
659
  }));
626
660
  }, [n.history, o]);
627
- const l = {
628
- setCurrentInput: w((u) => {
629
- C.debug("[CitadelActions] setCurrentInput: ", u), a((p) => ({ ...p, currentInput: u }));
661
+ const c = {
662
+ setCurrentInput: y((s) => {
663
+ C.debug("[CitadelActions] setCurrentInput: ", s), i((l) => ({ ...l, currentInput: s }));
630
664
  }, []),
631
- setIsEnteringArg: w((u) => {
632
- C.debug("[CitadelActions] setIsEnteringArg: ", u), a((p) => ({ ...p, isEnteringArg: u }));
665
+ setIsEnteringArg: y((s) => {
666
+ C.debug("[CitadelActions] setIsEnteringArg: ", s), i((l) => ({ ...l, isEnteringArg: s }));
633
667
  }, []),
634
- addOutput: w((u) => {
635
- C.debug("[CitadelActions]addOutput: ", u), a((p) => ({
636
- ...p,
637
- output: [...p.output, u]
668
+ addOutput: y((s) => {
669
+ C.debug("[CitadelActions]addOutput: ", s), i((l) => ({
670
+ ...l,
671
+ output: [...l.output, s]
638
672
  }));
639
673
  }, []),
640
- executeCommand: w(async () => {
641
- const u = t.path(), p = e.getCommand(u);
642
- if (!p) {
643
- console.error("[CitadelActions][executeCommand] Cannot execute command because no command was found for the given path: ", u);
674
+ executeCommand: y(async () => {
675
+ const s = t.path(), l = e.getCommand(s);
676
+ if (!l) {
677
+ console.error("[CitadelActions][executeCommand] Cannot execute command because no command was found for the given path: ", s);
644
678
  return;
645
679
  }
646
- const k = new Re(t);
647
- a((y) => ({
648
- ...y,
649
- output: [...y.output, k]
680
+ const h = new J(t);
681
+ i((p) => ({
682
+ ...p,
683
+ output: [...p.output, h]
650
684
  }));
651
685
  try {
652
- const y = new Promise((i, h) => {
686
+ const p = new Promise((u, k) => {
653
687
  setTimeout(() => {
654
- h(new Error("Request timed out"));
688
+ k(new Error("Request timed out"));
655
689
  }, r.commandTimeoutMs);
656
- }), E = t.arguments.map((i) => i.value || ""), N = await Promise.race([
657
- p.handler(E),
658
- y
690
+ }), S = t.arguments.map((u) => u.value || ""), v = await Promise.race([
691
+ l.handler(S),
692
+ p
659
693
  ]);
660
- if (!(N instanceof U))
694
+ if (!(v instanceof T))
661
695
  throw new Error(
662
- `The ${u.join(".")} command returned an invalid result type. Commands must return an instance of a CommandResult.
696
+ `The ${s.join(".")} command returned an invalid result type. Commands must return an instance of a CommandResult.
663
697
  For example:
664
698
  return new JsonCommandResult({ text: "Hello World" });
665
- Check the definition of the ${u.join(".")} command and update the return type for its handler.`
699
+ Check the definition of the ${s.join(".")} command and update the return type for its handler.`
666
700
  );
667
- N.markSuccess(), a((i) => ({
668
- ...i,
669
- output: i.output.map(
670
- (h) => h.timestamp === k.timestamp ? { ...h, result: N } : h
701
+ v.markSuccess(), i((u) => ({
702
+ ...u,
703
+ output: u.output.map(
704
+ (k) => k.id === h.id ? { ...k, result: v } : k
671
705
  )
672
706
  }));
673
- } catch (y) {
674
- const E = new ve(
675
- y instanceof Error ? y.message : "Unknown error"
707
+ } catch (p) {
708
+ const S = new Ne(
709
+ p instanceof Error ? p.message : "Unknown error"
676
710
  );
677
- E.markFailure(), a((N) => ({
678
- ...N,
679
- output: N.output.map(
680
- (i) => i.timestamp === k.timestamp ? { ...i, result: E } : i
711
+ S.markFailure(), i((v) => ({
712
+ ...v,
713
+ output: v.output.map(
714
+ (u) => u.id === h.id ? { ...u, result: S } : u
681
715
  )
682
716
  }));
683
717
  }
684
718
  }, [e, r.commandTimeoutMs, t]),
685
- clearHistory: w(async () => {
719
+ clearHistory: y(async () => {
686
720
  try {
687
721
  await n.clear();
688
- } catch (u) {
689
- console.warn("Failed to clear history:", u);
722
+ } catch (s) {
723
+ console.warn("Failed to clear history:", s);
690
724
  }
691
725
  }, [n])
692
- }, d = w(() => e.getCompletions_s(t.path()), [t, e]), c = w(() => e.getCompletions(t.path()), [t, e]);
693
- return {
694
- state: s,
695
- actions: l,
696
- getAvailableCommands_s: d,
697
- getAvailableCommandSegments: c
698
726
  };
699
- }, He = ({ onOpen: r, onClose: e, isVisible: n, showCitadelKey: t }) => {
727
+ return { state: a, actions: c };
728
+ }, Me = ({ onOpen: r, onClose: e, isVisible: n, showCitadelKey: t }) => {
700
729
  A(() => {
701
- const o = (s) => {
702
- var a, l;
703
- !n && s.key === t && !["input", "textarea"].includes(((l = (a = s.target) == null ? void 0 : a.tagName) == null ? void 0 : l.toLowerCase()) || "") && (s.preventDefault(), r()), n && s.key === "Escape" && (s.preventDefault(), e());
730
+ const o = (a) => {
731
+ var i, c;
732
+ !n && a.key === t && !["input", "textarea"].includes(((c = (i = a.target) == null ? void 0 : i.tagName) == null ? void 0 : c.toLowerCase()) || "") && (a.preventDefault(), r()), n && a.key === "Escape" && (a.preventDefault(), e());
704
733
  };
705
734
  return document.addEventListener("keydown", o), () => document.removeEventListener("keydown", o);
706
735
  }, [r, e, n, t]);
707
- }, De = "_panelContainer_1pav9_3", Me = "_innerContainer_1pav9_19", Ue = "_inputSection_1pav9_29", Fe = "_resizeHandle_1pav9_36", Te = "_citadel_slideUp_1pav9_65", je = "_citadel_slideDown_1pav9_69", Oe = "_inlineContainer_1pav9_73", Z = {
736
+ }, De = "_panelContainer_1pav9_3", Te = "_innerContainer_1pav9_19", Ue = "_inputSection_1pav9_29", je = "_resizeHandle_1pav9_36", Fe = "_citadel_slideUp_1pav9_65", Oe = "_citadel_slideDown_1pav9_69", Le = "_inlineContainer_1pav9_73", re = {
708
737
  panelContainer: De,
709
- innerContainer: Me,
738
+ innerContainer: Te,
710
739
  inputSection: Ue,
711
- resizeHandle: Fe,
712
- citadel_slideUp: Te,
713
- citadel_slideDown: je,
714
- inlineContainer: Oe
740
+ resizeHandle: je,
741
+ citadel_slideUp: Fe,
742
+ citadel_slideDown: Oe,
743
+ inlineContainer: Le
715
744
  }, $e = (r) => {
716
- const { isVisible: e, isClosing: n, onAnimationComplete: t } = r, o = V(() => e ? n ? Z.slideDown : Z.slideUp : "", [e, n]);
745
+ const { isVisible: e, isClosing: n, onAnimationComplete: t } = r, o = D(() => e ? n ? re.slideDown : re.slideUp : "", [e, n]);
717
746
  return A(() => {
718
747
  if (t) {
719
- const a = setTimeout(() => {
748
+ const i = setTimeout(() => {
720
749
  t();
721
750
  }, 200);
722
- return () => clearTimeout(a);
751
+ return () => clearTimeout(i);
723
752
  }
724
753
  }, [n, t]), {
725
- style: V(() => ({
754
+ style: D(() => ({
726
755
  opacity: e ? 1 : 0,
727
756
  transform: e ? "translateY(0)" : n ? "translateY(100%)" : "translateY(-100%)",
728
757
  transition: "opacity 200ms ease-in-out, transform 200ms ease-in-out"
@@ -735,19 +764,19 @@ Check the definition of the ${u.join(".")} command and update the return type fo
735
764
  "data-testid": "spinner",
736
765
  className: "animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-gray-600"
737
766
  }
738
- ), Le = ({
767
+ ), We = ({
739
768
  command: r,
740
769
  timestamp: e,
741
770
  status: n
742
- }) => /* @__PURE__ */ _("div", { className: "flex items-center gap-2 font-mono text-sm", children: [
743
- /* @__PURE__ */ _("span", { className: "text-gray-200", children: [
771
+ }) => /* @__PURE__ */ N("div", { className: "flex items-center gap-2 font-mono text-sm", children: [
772
+ /* @__PURE__ */ N("span", { className: "text-gray-200", children: [
744
773
  "> ",
745
774
  r.split(" ").map((t, o) => {
746
- const s = t.startsWith("<") && t.endsWith(">");
747
- return /* @__PURE__ */ _(
775
+ const a = t.startsWith("<") && t.endsWith(">");
776
+ return /* @__PURE__ */ N(
748
777
  "span",
749
778
  {
750
- className: s ? "text-green-400" : "text-gray-200",
779
+ className: a ? "text-green-400" : "text-gray-200",
751
780
  children: [
752
781
  o > 0 ? " " : "",
753
782
  t
@@ -759,23 +788,23 @@ Check the definition of the ${u.join(".")} command and update the return type fo
759
788
  ] }),
760
789
  /* @__PURE__ */ m("span", { className: "text-gray-400", children: "·" }),
761
790
  /* @__PURE__ */ m("span", { className: "text-gray-500", children: e }),
762
- n === T.Pending && /* @__PURE__ */ m(Ke, {}),
763
- n === T.Success && /* @__PURE__ */ m(
791
+ n === F.Pending && /* @__PURE__ */ m(Ke, {}),
792
+ n === F.Success && /* @__PURE__ */ m(
764
793
  "div",
765
794
  {
766
795
  "data-testid": "success-indicator",
767
796
  className: "w-4 h-4 rounded-full bg-green-500"
768
797
  }
769
798
  ),
770
- (n === T.Timeout || n === T.Failure) && /* @__PURE__ */ m(
799
+ (n === F.Timeout || n === F.Failure) && /* @__PURE__ */ m(
771
800
  "div",
772
801
  {
773
802
  "data-testid": "success-indicator",
774
803
  className: "w-4 h-4 rounded-full bg-red-500"
775
804
  }
776
805
  )
777
- ] }), Ve = ({ output: r, outputRef: e }) => {
778
- const n = F(), t = w(() => {
806
+ ] }), qe = ({ output: r, outputRef: e }) => {
807
+ const n = $(), t = y(() => {
779
808
  if (e.current) {
780
809
  const o = e.current;
781
810
  requestAnimationFrame(() => {
@@ -785,9 +814,9 @@ Check the definition of the ${u.join(".")} command and update the return type fo
785
814
  }, [e]);
786
815
  return A(() => {
787
816
  if (t(), e.current) {
788
- const o = e.current.getElementsByTagName("img"), s = o[o.length - 1];
789
- if (s && !s.complete)
790
- return s.addEventListener("load", t), () => s.removeEventListener("load", t);
817
+ const o = e.current.getElementsByTagName("img"), a = o[o.length - 1];
818
+ if (a && !a.complete)
819
+ return a.addEventListener("load", t), () => a.removeEventListener("load", t);
791
820
  }
792
821
  }, [r, t, e]), /* @__PURE__ */ m(
793
822
  "div",
@@ -795,9 +824,9 @@ Check the definition of the ${u.join(".")} command and update the return type fo
795
824
  ref: e,
796
825
  className: "h-full overflow-y-auto border border-gray-700 rounded-lg p-3 text-left",
797
826
  "data-testid": "citadel-command-output",
798
- children: r.map((o, s) => /* @__PURE__ */ _("div", { className: "mb-4 last:mb-0", children: [
827
+ children: r.map((o) => /* @__PURE__ */ N("div", { className: "mb-4 last:mb-0", children: [
799
828
  /* @__PURE__ */ m(
800
- Le,
829
+ We,
801
830
  {
802
831
  command: o.command.join(" "),
803
832
  timestamp: new Date(o.timestamp).toLocaleTimeString(),
@@ -805,10 +834,10 @@ Check the definition of the ${u.join(".")} command and update the return type fo
805
834
  }
806
835
  ),
807
836
  /* @__PURE__ */ m("pre", { className: `text-gray-200 whitespace-pre font-mono ${n.outputFontSize}`, children: o.result.render() })
808
- ] }, s))
837
+ ] }, o.id))
809
838
  }
810
839
  );
811
- }, We = {
840
+ }, Ve = {
812
841
  blink: {
813
842
  character: "▋",
814
843
  speed: 530,
@@ -829,23 +858,23 @@ Check the definition of the ${u.join(".")} command and update the return type fo
829
858
  speed: 120,
830
859
  color: "#fff"
831
860
  }
832
- }, ee = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"], ne = ["|", "/", "-", "\\"], qe = ({
861
+ }, oe = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"], se = ["|", "/", "-", "\\"], Ye = ({
833
862
  style: r = { type: "blink" },
834
863
  isValid: e = !0,
835
864
  errorMessage: n
836
865
  }) => {
837
- const t = V(() => ({
838
- ...We[r.type],
866
+ const t = D(() => ({
867
+ ...Ve[r.type],
839
868
  ...r
840
- }), [r]), [o, s] = R(!0), [a, l] = R(0);
869
+ }), [r]), [o, a] = R(!0), [i, c] = R(0);
841
870
  A(() => {
842
871
  if (t.speed === 0) return;
843
- const u = setInterval(() => {
844
- t.type === "blink" ? s((p) => !p) : ["spin", "bbs"].includes(t.type) && l((p) => (p + 1) % (t.type === "bbs" ? ne.length : ee.length));
872
+ const h = setInterval(() => {
873
+ t.type === "blink" ? a((p) => !p) : ["spin", "bbs"].includes(t.type) && c((p) => (p + 1) % (t.type === "bbs" ? se.length : oe.length));
845
874
  }, t.speed);
846
- return () => clearInterval(u);
875
+ return () => clearInterval(h);
847
876
  }, [t.type, t.speed]);
848
- const d = V(() => ({
877
+ const s = D(() => ({
849
878
  color: e ? t.color : "#ff4444",
850
879
  transition: "color 0.15s ease-in-out"
851
880
  }), [e, t.color]);
@@ -853,13 +882,13 @@ Check the definition of the ${u.join(".")} command and update the return type fo
853
882
  "span",
854
883
  {
855
884
  className: `command-cursor ${e ? "" : "animate-shake"}`,
856
- style: d,
885
+ style: s,
857
886
  title: n,
858
- children: !e && n ? "✗" : ["spin", "bbs"].includes(t.type) ? (t.type === "bbs" ? ne : ee)[a] : t.type === "solid" || o ? t.character : " "
887
+ children: !e && n ? "✗" : ["spin", "bbs"].includes(t.type) ? (t.type === "bbs" ? se : oe)[i] : t.type === "solid" || o ? t.character : " "
859
888
  }
860
889
  ) });
861
890
  };
862
- function Ye(r, e) {
891
+ function Be(r, e) {
863
892
  switch (e.type) {
864
893
  case "set":
865
894
  return C.debug(`[inputStateReducer] InputState changing from ${r} to ${e.state}`), e.state;
@@ -867,102 +896,98 @@ function Ye(r, e) {
867
896
  return r;
868
897
  }
869
898
  }
870
- const Be = () => {
871
- const { state: r } = X(), e = B(), n = ue(), t = O(), [o, s] = ye(Ye, "idle"), a = (i) => {
872
- s({ type: "set", state: i });
873
- }, l = w(() => {
874
- const h = e.getCompletions(t.path())[0] || t.nullSegment;
875
- return C.debug("[getNextExpectedSegment] ", h), h;
876
- }, [e, t]), d = w(() => e.getCompletions_s(t.path()).map((h) => e.getCommand([...t.path(), h])).filter((h) => h !== void 0), [e, t]), c = w((i, h) => {
877
- if (!i) return h;
878
- const g = h.reduce((f, x) => {
879
- const v = l();
880
- return (v == null ? void 0 : v.type) === "word" && f.set(v.name, x), f;
881
- }, /* @__PURE__ */ new Map());
882
- return Array.from(g.values()).filter(() => {
883
- const f = l();
884
- return f.type !== "word" ? !1 : f.name.toLowerCase().startsWith(i.toLowerCase());
899
+ const Ge = () => {
900
+ const { state: r } = ee(), e = B(), n = ge(), t = K(), [o, a] = Se(Be, "idle"), i = (d) => {
901
+ a({ type: "set", state: d });
902
+ }, c = y(() => {
903
+ const f = e.getCompletions(t.path())[0] || t.nullSegment;
904
+ return C.debug("[getNextExpectedSegment] ", f), f;
905
+ }, [e, t]), s = y(() => e.getCompletionNames(t.path()).map((f) => e.getCommand([...t.path(), f])).filter((f) => f !== void 0), [e, t]), l = y((d, f) => {
906
+ if (!d) return f;
907
+ const w = t.path().length;
908
+ return f.filter((x) => {
909
+ const g = x.segments[w];
910
+ return !g || g.type !== "word" ? !1 : g.name.toLowerCase().startsWith(d.toLowerCase());
885
911
  });
886
- }, [l]), u = w((i) => {
887
- const g = e.getCompletions(t.path()).filter((S) => S.type === "word").filter(
888
- (S) => S.name.toLowerCase().startsWith(i.toLowerCase())
912
+ }, [t]), h = y((d) => {
913
+ const w = e.getCompletions(t.path()).filter((x) => x.type === "word").filter(
914
+ (x) => x.name.toLowerCase().startsWith(d.toLowerCase())
889
915
  );
890
- return g.length === 1 ? g[0] : t.nullSegment;
891
- }, [e, t]), p = w((i) => {
892
- const h = t.path(), g = e.getCompletions(h);
893
- return g.length === 0 && i ? !1 : g.some((f) => f.type === "argument") ? !0 : g.some(
894
- (f) => f.type === "word" && f.name.toLowerCase().startsWith(i.toLowerCase())
916
+ return w.length === 1 ? w[0] : t.nullSegment;
917
+ }, [e, t]), p = y((d) => {
918
+ const f = t.path(), w = e.getCompletions(f);
919
+ return w.length === 0 && d ? !1 : w.some((g) => g.type === "argument") ? !0 : w.some(
920
+ (g) => g.type === "word" && g.name.toLowerCase().startsWith(d.toLowerCase())
895
921
  );
896
- }, [e, t]), k = w((i) => {
897
- C.debug("[tryAutoComplete] input: ", i);
898
- const h = u(i);
899
- return !h || h.name === i ? new ce() : (C.debug("[tryAutoComplete] result: ", h), h);
900
- }, [u]), y = w((i, h) => {
922
+ }, [e, t]), S = y((d) => {
923
+ C.debug("[tryAutoComplete] input: ", d);
924
+ const f = h(d);
925
+ return !f || f.name === d ? new ue() : (C.debug("[tryAutoComplete] result: ", f), f);
926
+ }, [h]), v = y((d, f) => {
901
927
  if (r.history.position === null) {
902
- if (h.setCurrentInput(i), C.debug("[useCommandParser][handleInputChange] newValue: ", i), o === "entering_argument") {
903
- const g = te(i);
904
- if (g.isQuoted)
905
- if (g.isComplete) {
906
- const S = l();
907
- if (S.type === "argument") {
908
- const f = S;
909
- f.value = i.trim() || "", C.debug("[useCommandParser][handleInputChange][entering_command] pushing: ", f), t.push(f), h.setCurrentInput(""), a("idle");
910
- return;
911
- }
928
+ if (f.setCurrentInput(d), C.debug("[useCommandParser][handleInputChange] newValue: ", d), o === "entering_argument") {
929
+ const w = ae(d);
930
+ if (w.isQuoted)
931
+ if (w.isComplete) {
932
+ const x = c();
933
+ if (!(x instanceof W)) return;
934
+ x.value = d.trim() || "", C.debug("[useCommandParser][handleInputChange][entering_command] pushing: ", x), t.push(x), f.setCurrentInput(""), i("idle");
935
+ return;
912
936
  } else
913
937
  return;
914
- else if (g.isComplete) {
915
- const S = l();
916
- S.value = i.trim() || "", C.debug("[useCommandParser][handleInputChange][entering_command] pushing: ", S), t.push(S), h.setCurrentInput(""), a("idle");
938
+ else if (w.isComplete) {
939
+ const x = c();
940
+ if (!(x instanceof W)) return;
941
+ x.value = d.trim() || "", C.debug("[useCommandParser][handleInputChange][entering_command] pushing: ", x), t.push(x), f.setCurrentInput(""), i("idle");
917
942
  return;
918
943
  } else
919
944
  return;
920
945
  }
921
- if (o == "entering_command") {
922
- const g = k(i);
923
- if (g.type === "word") {
924
- C.debug("[useCommandParser][handleInputChange][entering_command] pushing: ", g), t.push(g), h.setCurrentInput(""), a("idle");
946
+ if (o === "entering_command") {
947
+ const w = S(d);
948
+ if (w.type === "word") {
949
+ C.debug("[useCommandParser][handleInputChange][entering_command] pushing: ", w), t.push(w), f.setCurrentInput(""), i("idle");
925
950
  return;
926
951
  }
927
952
  }
928
953
  }
929
- }, [k, r, l, o, t]), E = w((i) => {
930
- i.setCurrentInput(""), i.setIsEnteringArg(!1), t.clear(), a("idle");
931
- }, [t]), N = w((i, h, g) => {
932
- if (!(i.key === "Backspace" || i.key === "Enter" || i.key === "ArrowUp" || i.key === "ArrowDown" || i.key === "ArrowLeft" || i.key === "ArrowRight" || i.key === "Escape" || i.key === "Delete" || i.key === "Home" || i.key === "End" || i.key.length === 1))
954
+ }, [S, r, c, o, t]), u = y((d) => {
955
+ d.setCurrentInput(""), d.setIsEnteringArg(!1), t.clear(), i("idle");
956
+ }, [t]), k = y((d, f, w) => {
957
+ if (!(d.key === "Backspace" || d.key === "Enter" || d.key === "ArrowUp" || d.key === "ArrowDown" || d.key === "ArrowLeft" || d.key === "ArrowRight" || d.key === "Escape" || d.key === "Delete" || d.key === "Home" || d.key === "End" || d.key.length === 1))
933
958
  return !0;
934
- const { currentInput: f, isEnteringArg: x } = h, v = te(f);
935
- switch (i.key) {
959
+ const { currentInput: g, isEnteringArg: E } = f, I = ae(g);
960
+ switch (d.key) {
936
961
  case "Backspace":
937
- return f === "" && (i.preventDefault(), t.size() > 0 && t.pop(), a("idle")), !0;
962
+ return g === "" && (d.preventDefault(), t.size() > 0 && t.pop(), i("idle")), !0;
938
963
  case "Enter": {
939
- if (i.preventDefault(), v.isQuoted && !v.isComplete)
964
+ if (d.preventDefault(), I.isQuoted && !I.isComplete)
940
965
  return !0;
941
- if (o === "entering_argument" || x && f.trim()) {
942
- const G = l();
943
- G.value = f, C.debug("[handleKeyDown][Enter]['entering_argument'] pushing: ", G), t.push(G);
966
+ if (o === "entering_argument" || E && g.trim()) {
967
+ const M = c();
968
+ M instanceof W && (M.value = g, C.debug("[handleKeyDown][Enter]['entering_argument'] pushing: ", M), t.push(M));
944
969
  }
945
- const I = t.path(), P = e.getCommand(I);
946
- if (!P)
970
+ const z = t.path(), U = e.getCommand(z);
971
+ if (!U)
947
972
  return !1;
948
- const $ = P.segments.filter((M) => M.type === "argument"), K = t.arguments;
949
- return $.length > K.length ? !1 : (C.debug("[handleKeyDown][Enter] calling actions.executeCommand. segmentStack: ", t), g.executeCommand(), n.addStoredCommand(t.toArray()), E(g), !0);
973
+ const j = U.segments.filter((M) => M.type === "argument"), be = t.arguments;
974
+ return j.length > be.length ? !1 : (C.debug("[handleKeyDown][Enter] calling actions.executeCommand. segmentStack: ", t), w.executeCommand(), n.addStoredCommand(t.toArray()), u(w), !0);
950
975
  }
951
976
  case "ArrowUp":
952
- return i.preventDefault(), (async () => {
953
- const I = await n.navigateHistory("up", t.toArray());
954
- return I.segments && (t.clear(), t.pushAll(I.segments), g.setCurrentInput("")), !0;
977
+ return d.preventDefault(), (async () => {
978
+ const z = await n.navigateHistory("up");
979
+ return z.segments && (t.clear(), t.pushAll(z.segments), w.setCurrentInput("")), !0;
955
980
  })();
956
981
  case "ArrowDown":
957
- return i.preventDefault(), (async () => {
958
- const I = await n.navigateHistory("down", t.toArray());
959
- return I.segments && (t.clear(), t.pushAll(I.segments), g.setCurrentInput("")), !0;
982
+ return d.preventDefault(), (async () => {
983
+ const z = await n.navigateHistory("down");
984
+ return z.segments && (t.clear(), t.pushAll(z.segments), w.setCurrentInput("")), !0;
960
985
  })();
961
986
  default: {
962
- if (!x && i.key.length === 1) {
963
- const I = f + i.key;
964
- if (!p(I))
965
- return i.preventDefault(), !1;
987
+ if (!E && d.key.length === 1) {
988
+ const z = g + d.key;
989
+ if (!p(z))
990
+ return d.preventDefault(), !1;
966
991
  }
967
992
  return !0;
968
993
  }
@@ -970,31 +995,31 @@ const Be = () => {
970
995
  }, [
971
996
  o,
972
997
  p,
973
- l,
998
+ c,
974
999
  n,
975
- E,
1000
+ u,
976
1001
  e,
977
1002
  t
978
1003
  ]);
979
1004
  return {
980
- handleInputChange: y,
981
- handleKeyDown: N,
1005
+ handleInputChange: v,
1006
+ handleKeyDown: k,
982
1007
  inputState: o,
983
- setInputStateWithLogging: a,
1008
+ setInputStateWithLogging: i,
984
1009
  // Expose internal functions for testing
985
- findMatchingCommands: c,
986
- getAutocompleteSuggestion: u,
987
- getAvailableNodes: d,
988
- getNextExpectedSegment: l,
1010
+ findMatchingCommands: l,
1011
+ getAutocompleteSuggestion: h,
1012
+ getAvailableNodes: s,
1013
+ getNextExpectedSegment: c,
989
1014
  isValidCommandInput: p
990
1015
  };
991
1016
  };
992
- function te(r) {
1017
+ function ae(r) {
993
1018
  const e = [];
994
1019
  let n = "", t = !1, o;
995
- for (let s = 0; s < r.length; s++) {
996
- const a = r[s];
997
- (a === '"' || a === "'") && (!t || a === o) ? t ? (e.push(n), n = "", t = !1, o = void 0) : (n && (e.push(n), n = ""), t = !0, o = a) : !t && a === " " ? n && (e.push(n), n = "") : n += a;
1020
+ for (let a = 0; a < r.length; a++) {
1021
+ const i = r[a];
1022
+ (i === '"' || i === "'") && (!t || i === o) ? t ? (e.push(n), n = "", t = !1, o = void 0) : (n && (e.push(n), n = ""), t = !0, o = i) : !t && i === " " ? n && (e.push(n), n = "") : n += i;
998
1023
  }
999
1024
  return {
1000
1025
  words: e,
@@ -1004,8 +1029,8 @@ function te(r) {
1004
1029
  isComplete: !t && !n
1005
1030
  };
1006
1031
  }
1007
- const Ge = () => {
1008
- const r = O(), [e, n] = R(0);
1032
+ const Je = () => {
1033
+ const r = K(), [e, n] = R(0);
1009
1034
  return A(() => {
1010
1035
  const t = {
1011
1036
  update: () => {
@@ -1016,66 +1041,64 @@ const Ge = () => {
1016
1041
  r.unsubscribe(t);
1017
1042
  };
1018
1043
  }, [r]), e;
1019
- }, Je = ({
1044
+ }, Qe = ({
1020
1045
  state: r,
1021
1046
  actions: e
1022
1047
  }) => {
1023
- const n = H(null), t = B(), o = O(), {
1024
- handleKeyDown: s,
1025
- handleInputChange: a,
1026
- inputState: l,
1027
- setInputStateWithLogging: d,
1028
- getNextExpectedSegment: c
1029
- } = Be(), [u, p] = R(!1), k = F(), y = Ge(), E = async (x) => {
1030
- const v = s(x, r, e);
1031
- await Promise.resolve(v) === !1 && (p(!0), setTimeout(() => p(!1), 500));
1032
- }, N = (x) => {
1033
- a(x.target.value, e);
1034
- }, i = (x) => {
1035
- x.preventDefault();
1036
- const v = x.clipboardData.getData("text");
1037
- a(v, e);
1048
+ const n = H(null), t = B(), o = K(), {
1049
+ handleKeyDown: a,
1050
+ handleInputChange: i,
1051
+ inputState: c,
1052
+ setInputStateWithLogging: s,
1053
+ getNextExpectedSegment: l
1054
+ } = Ge(), [h, p] = R(!1), S = $(), v = Je(), u = async (g) => {
1055
+ const E = a(g, r, e);
1056
+ await Promise.resolve(E) === !1 && (p(!0), setTimeout(() => p(!1), 500));
1057
+ }, k = (g) => {
1058
+ i(g.target.value, e);
1059
+ }, d = (g) => {
1060
+ g.preventDefault();
1061
+ const E = g.clipboardData.getData("text");
1062
+ i(E, e);
1038
1063
  };
1039
1064
  A(() => {
1040
- n.current && n.current.focus(), l !== "entering_command" && d("entering_command");
1041
- }, [l, d]), A(() => {
1042
- if (l !== "idle") return;
1043
- const x = c();
1044
- let v = "idle";
1045
- switch (x.type) {
1065
+ n.current && n.current.focus(), c !== "entering_command" && s("entering_command");
1066
+ }, [c, s]), A(() => {
1067
+ if (c !== "idle") return;
1068
+ const g = l();
1069
+ let E = "idle";
1070
+ switch (g.type) {
1046
1071
  case "word":
1047
- v = "entering_command", e.setIsEnteringArg(!1);
1072
+ E = "entering_command", e.setIsEnteringArg(!1);
1048
1073
  break;
1049
1074
  case "argument":
1050
- v = "entering_argument", e.setIsEnteringArg(!0);
1075
+ E = "entering_argument", e.setIsEnteringArg(!0);
1051
1076
  break;
1052
1077
  }
1053
- d(v);
1054
- }, [y, l, c, d, e]);
1055
- const [h, g] = R([]);
1056
- A(() => {
1057
- const x = [], v = o.toArray().map((P, $) => {
1058
- x.push(P.name);
1059
- const K = t.hasNextSegment(x);
1060
- if (P.type === "argument") {
1061
- const M = P;
1062
- return /* @__PURE__ */ _(L.Fragment, { children: [
1063
- /* @__PURE__ */ m("span", { className: "text-gray-200 whitespace-pre", children: M.value }),
1064
- $ < o.size() && K && /* @__PURE__ */ m("span", { className: "text-gray-200 whitespace-pre", children: " " })
1065
- ] }, "arg-" + M.name + M.value);
1078
+ s(E);
1079
+ }, [v, c, l, s, e]);
1080
+ const f = D(() => {
1081
+ const g = [], E = o.toArray().map((I, z) => {
1082
+ g.push(I.name);
1083
+ const U = t.hasNextSegment(g);
1084
+ if (I.type === "argument") {
1085
+ const j = I;
1086
+ return /* @__PURE__ */ N(O.Fragment, { children: [
1087
+ /* @__PURE__ */ m("span", { className: "text-gray-200 whitespace-pre", children: j.value }),
1088
+ z < o.size() && U && /* @__PURE__ */ m("span", { className: "text-gray-200 whitespace-pre", children: " " })
1089
+ ] }, "arg-" + j.name + j.value);
1066
1090
  }
1067
- return /* @__PURE__ */ _(L.Fragment, { children: [
1068
- /* @__PURE__ */ m("span", { className: "text-blue-400 whitespace-pre", children: P.name }),
1069
- $ < o.size() && K && /* @__PURE__ */ m("span", { className: "text-blue-400 whitespace-pre", children: " " })
1070
- ] }, "word-" + P.name);
1091
+ return /* @__PURE__ */ N(O.Fragment, { children: [
1092
+ /* @__PURE__ */ m("span", { className: "text-blue-400 whitespace-pre", children: I.name }),
1093
+ z < o.size() && U && /* @__PURE__ */ m("span", { className: "text-blue-400 whitespace-pre", children: " " })
1094
+ ] }, "word-" + I.name);
1071
1095
  });
1072
- g([/* @__PURE__ */ m("div", { className: "flex items-center gap-1", "data-testid": "user-input-area", children: v }, "{segmentStackVersion}")]);
1073
- }, [y, t, o]);
1074
- const [S, f] = R("");
1096
+ return [/* @__PURE__ */ m("div", { className: "flex items-center gap-1", "data-testid": "user-input-area", children: E }, "{segmentStackVersion}")];
1097
+ }, [v, t, o]), [w, x] = R("");
1075
1098
  return A(() => {
1076
- const x = c();
1077
- x.type === "argument" ? f(x.name) : f("");
1078
- }, [y, c]), /* @__PURE__ */ _("div", { className: "flex flex-col w-full bg-gray-900 rounded-lg p-4", children: [
1099
+ const g = l();
1100
+ g.type === "argument" ? x(g.name) : x("");
1101
+ }, [v, l]), /* @__PURE__ */ N("div", { className: "flex flex-col w-full bg-gray-900 rounded-lg p-4", children: [
1079
1102
  /* @__PURE__ */ m("style", { children: `
1080
1103
  @keyframes subtleGlow {
1081
1104
  0%, 100% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
@@ -1085,11 +1108,11 @@ const Ge = () => {
1085
1108
  animation: subtleGlow 0.4s ease-in-out;
1086
1109
  }
1087
1110
  ` }),
1088
- /* @__PURE__ */ _("div", { className: "flex items-center gap-2", children: [
1111
+ /* @__PURE__ */ N("div", { className: "flex items-center gap-2", children: [
1089
1112
  /* @__PURE__ */ m("div", { className: "text-gray-400 font-mono", children: ">" }),
1090
- /* @__PURE__ */ _("div", { className: "flex-1 font-mono flex items-center", children: [
1091
- h,
1092
- /* @__PURE__ */ _("div", { className: "relative flex-1", children: [
1113
+ /* @__PURE__ */ N("div", { className: "flex-1 font-mono flex items-center", children: [
1114
+ f,
1115
+ /* @__PURE__ */ N("div", { className: "relative flex-1", children: [
1093
1116
  /* @__PURE__ */ m(
1094
1117
  "input",
1095
1118
  {
@@ -1097,14 +1120,14 @@ const Ge = () => {
1097
1120
  type: "text",
1098
1121
  role: "textbox",
1099
1122
  value: r.currentInput,
1100
- onChange: N,
1101
- onKeyDown: E,
1102
- onPaste: i,
1123
+ onChange: k,
1124
+ onKeyDown: u,
1125
+ onPaste: d,
1103
1126
  "data-testid": "citadel-command-input",
1104
- className: `w-full bg-transparent outline-none text-gray-200 caret-transparent ${u ? "invalid-input-animation" : ""}`,
1127
+ className: `w-full bg-transparent outline-none text-gray-200 caret-transparent ${h ? "invalid-input-animation" : ""}`,
1105
1128
  spellCheck: !1,
1106
1129
  autoComplete: "off",
1107
- placeholder: S
1130
+ placeholder: w
1108
1131
  }
1109
1132
  ),
1110
1133
  /* @__PURE__ */ m(
@@ -1116,12 +1139,12 @@ const Ge = () => {
1116
1139
  transition: "left 0.05s ease-out"
1117
1140
  },
1118
1141
  children: /* @__PURE__ */ m(
1119
- qe,
1142
+ Ye,
1120
1143
  {
1121
1144
  style: {
1122
- type: k.cursorType ?? z.cursorType,
1123
- color: k.cursorColor || z.cursorColor,
1124
- speed: k.cursorSpeed || z.cursorSpeed
1145
+ type: S.cursorType ?? _.cursorType,
1146
+ color: S.cursorColor || _.cursorColor,
1147
+ speed: S.cursorSpeed || _.cursorSpeed
1125
1148
  }
1126
1149
  }
1127
1150
  )
@@ -1131,114 +1154,120 @@ const Ge = () => {
1131
1154
  ] })
1132
1155
  ] })
1133
1156
  ] });
1134
- }, Qe = () => {
1135
- const r = B(), e = F(), n = O(), t = "h-12 mt-2 border-t border-gray-700 px-4", o = "text-gray-300 pt-2", s = r.getCompletions(n.path());
1136
- C.debug("[AvailableCommands] nextCommandSegments: ", s);
1137
- const a = L.useMemo(() => {
1138
- if (e.includeHelpCommand) {
1139
- const c = s.filter((p) => p.name !== "help"), u = s.find((p) => p.name === "help");
1140
- return [...c, ...u ? [u] : []];
1157
+ }, Xe = () => {
1158
+ const r = B(), e = K(), n = "mt-2 border-t border-gray-700 px-4 py-2", t = "text-gray-300", o = r.getCompletions(e.path());
1159
+ C.debug("[AvailableCommands] nextCommandSegments: ", o);
1160
+ const a = O.useMemo(() => {
1161
+ const l = [...o], h = (u) => u.name.toLowerCase() === "help", p = l.filter(h);
1162
+ return [...l.filter((u) => !h(u)).sort(
1163
+ (u, k) => u.name.localeCompare(k.name, void 0, { sensitivity: "base" })
1164
+ ), ...p];
1165
+ }, [o]), i = O.useMemo(() => {
1166
+ const l = /* @__PURE__ */ new Map();
1167
+ for (const h of a) {
1168
+ const p = a.reduce((S, v) => {
1169
+ if (v === h) return S;
1170
+ let u = 0;
1171
+ for (; u < h.name.length && u < v.name.length && h.name[u].toLowerCase() === v.name[u].toLowerCase(); )
1172
+ u++;
1173
+ return Math.max(S, u + 1);
1174
+ }, 1);
1175
+ l.set(h.name, p);
1141
1176
  }
1142
- return s;
1143
- }, [s, e.includeHelpCommand]), l = s.some((c) => c.type === "argument"), d = s[0];
1144
- return /* @__PURE__ */ m("div", { className: t, "data-testid": "available-commands", children: /* @__PURE__ */ m("div", { className: o, children: l ? s.length > 0 ? /* @__PURE__ */ _(we, { children: [
1145
- /* @__PURE__ */ m("span", { className: "text-blue-400", children: d.name }),
1146
- d.description && /* @__PURE__ */ _("span", { className: "text-gray-400 ml-2", children: [
1177
+ return l;
1178
+ }, [a]), c = o.some((l) => l.type === "argument"), s = o[0];
1179
+ return /* @__PURE__ */ m("div", { className: n, "data-testid": "available-commands", children: /* @__PURE__ */ m("div", { className: t, children: c ? o.length > 0 ? /* @__PURE__ */ N(ve, { children: [
1180
+ /* @__PURE__ */ m("span", { className: "text-blue-400", children: s.name }),
1181
+ s.description && /* @__PURE__ */ N("span", { className: "text-gray-400 ml-2", children: [
1147
1182
  "- ",
1148
- d.description
1183
+ s.description
1149
1184
  ] })
1150
- ] }) : null : /* @__PURE__ */ m("div", { className: "flex flex-wrap gap-2", children: a == null ? void 0 : a.map((c) => {
1151
- const u = a == null ? void 0 : a.reduce((p, k) => {
1152
- if (k === c) return p;
1153
- let y = 0;
1154
- for (; y < c.name.length && y < k.name.length && c.name[y].toLowerCase() === k.name[y].toLowerCase(); )
1155
- y++;
1156
- return Math.max(p, y + 1);
1157
- }, 1);
1185
+ ] }) : null : /* @__PURE__ */ m("div", { className: "flex flex-wrap gap-2", children: a == null ? void 0 : a.map((l) => {
1186
+ const h = i.get(l.name) ?? 1;
1158
1187
  return /* @__PURE__ */ m(
1159
1188
  "div",
1160
1189
  {
1161
1190
  className: "px-2 py-1 rounded bg-gray-800 mr-2 last:mr-0",
1162
- children: /* @__PURE__ */ _("span", { className: "font-mono text-white", children: [
1163
- /* @__PURE__ */ m("strong", { className: "underline", children: c.name.slice(0, u) }),
1164
- c.name.slice(u)
1191
+ children: /* @__PURE__ */ N("span", { className: "font-mono text-white", children: [
1192
+ /* @__PURE__ */ m("strong", { className: "underline", children: l.name.slice(0, h) }),
1193
+ l.name.slice(h)
1165
1194
  ] })
1166
1195
  },
1167
- c.name
1196
+ l.name
1168
1197
  );
1169
1198
  }) }) }) });
1170
- }, pe = ({
1199
+ }, fe = ({
1171
1200
  state: r,
1172
1201
  actions: e,
1173
1202
  outputRef: n
1174
- }) => /* @__PURE__ */ _("div", { className: "innerContainer", children: [
1175
- /* @__PURE__ */ m("div", { className: "flex-1 min-h-0 pt-3 px-4", children: /* @__PURE__ */ m(Ve, { output: r.output, outputRef: n }) }),
1176
- /* @__PURE__ */ _("div", { children: [
1177
- /* @__PURE__ */ m(Je, { state: r, actions: e }),
1178
- /* @__PURE__ */ m(Qe, {})
1203
+ }) => /* @__PURE__ */ N("div", { className: "innerContainer", children: [
1204
+ /* @__PURE__ */ m("div", { className: "flex-1 min-h-0 pt-3 px-4", children: /* @__PURE__ */ m(qe, { output: r.output, outputRef: n }) }),
1205
+ /* @__PURE__ */ N("div", { children: [
1206
+ /* @__PURE__ */ m(Qe, { state: r, actions: e }),
1207
+ /* @__PURE__ */ m(Xe, {})
1179
1208
  ] })
1180
- ] }), Xe = () => {
1181
- const [r, e] = R(!1), [n, t] = R(!1), o = F(), [s, a] = R(() => o.initialHeight || null), l = H(null), d = H(null), c = H(!1), u = H(0), p = H(0), { state: k, actions: y } = X();
1182
- He({
1209
+ ] }), Ze = () => {
1210
+ const [r, e] = R(!1), [n, t] = R(!1), o = $(), [a, i] = R(() => o.initialHeight || null), c = H(null), s = H(null), l = H(!1), h = H(0), p = H(0), { state: S, actions: v } = ee();
1211
+ Me({
1183
1212
  onOpen: () => e(!0),
1184
1213
  onClose: () => t(!0),
1185
1214
  isVisible: r,
1186
1215
  showCitadelKey: o.showCitadelKey || "."
1187
1216
  });
1188
- const E = w((g) => {
1189
- var v;
1190
- if (!c.current) return;
1191
- const S = g.clientY - u.current, f = (v = o.maxHeight) != null && v.endsWith("vh") ? window.innerHeight * parseInt(o.maxHeight, 10) / 100 : parseInt(o.maxHeight || "80vh", 10), x = Math.min(
1192
- Math.max(p.current - S, parseInt(o.minHeight || "200", 10)),
1193
- f
1217
+ const u = y((w) => {
1218
+ var I;
1219
+ if (!l.current) return;
1220
+ const x = w.clientY - h.current, g = (I = o.maxHeight) != null && I.endsWith("vh") ? window.innerHeight * parseInt(o.maxHeight, 10) / 100 : parseInt(o.maxHeight || "80vh", 10), E = Math.min(
1221
+ Math.max(p.current - x, parseInt(o.minHeight || "200", 10)),
1222
+ g
1194
1223
  );
1195
- d.current && (d.current.style.height = `${x}px`, d.current.style.bottom = "0", a(`${x}px`));
1196
- }, [o.maxHeight, o.minHeight]), N = w(() => {
1197
- c.current = !1, document.documentElement.style.userSelect = "", document.documentElement.style.webkitUserSelect = "", document.documentElement.style.mozUserSelect = "", document.documentElement.style.msUserSelect = "", document.removeEventListener("mousemove", E), document.removeEventListener("mouseup", N);
1198
- }, [E]), i = w((g) => {
1199
- d.current && (c.current = !0, u.current = g.clientY, p.current = d.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", E), document.addEventListener("mouseup", N));
1200
- }, [E, N]);
1224
+ s.current && (s.current.style.height = `${E}px`, s.current.style.bottom = "0", i(`${E}px`));
1225
+ }, [o.maxHeight, o.minHeight]), k = y(() => {
1226
+ l.current = !1, document.documentElement.style.userSelect = "", document.documentElement.style.webkitUserSelect = "", document.documentElement.style.mozUserSelect = "", document.documentElement.style.msUserSelect = "", document.removeEventListener("mousemove", u), document.removeEventListener("mouseup", k);
1227
+ }, [u]), d = y((w) => {
1228
+ s.current && (l.current = !0, h.current = w.clientY, p.current = s.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", u), document.addEventListener("mouseup", k));
1229
+ }, [u, k]);
1201
1230
  A(() => () => {
1202
- document.removeEventListener("mousemove", E), document.removeEventListener("mouseup", N);
1203
- }, [E, N]);
1204
- const h = w(() => {
1231
+ document.removeEventListener("mousemove", u), document.removeEventListener("mouseup", k);
1232
+ }, [u, k]);
1233
+ const f = y(() => {
1205
1234
  n && (e(!1), t(!1));
1206
1235
  }, [n]);
1207
1236
  return $e({
1208
1237
  isVisible: r,
1209
1238
  isClosing: n,
1210
- onAnimationComplete: h
1211
- }), r ? /* @__PURE__ */ _(
1239
+ onAnimationComplete: f
1240
+ }), r ? /* @__PURE__ */ N(
1212
1241
  "div",
1213
1242
  {
1214
- ref: d,
1243
+ ref: s,
1215
1244
  className: `panelContainer ${r ? "citadel_slideUp" : ""} ${n ? "citadel_slideDown" : ""}`,
1216
1245
  style: {
1217
- ...s ? { height: s } : void 0,
1246
+ ...a ? { height: a } : void 0,
1218
1247
  maxHeight: o.maxHeight
1219
1248
  },
1220
1249
  children: [
1221
- /* @__PURE__ */ m("div", { className: "resizeHandle", onMouseDown: i }),
1250
+ /* @__PURE__ */ m("div", { className: "resizeHandle", onMouseDown: d }),
1222
1251
  /* @__PURE__ */ m(
1223
- pe,
1252
+ fe,
1224
1253
  {
1225
- state: k,
1226
- actions: y,
1227
- outputRef: l
1254
+ state: S,
1255
+ actions: v,
1256
+ outputRef: c
1228
1257
  }
1229
1258
  )
1230
1259
  ]
1231
1260
  }
1232
1261
  ) : null;
1233
- }, Ze = () => {
1234
- const { state: r, actions: e } = X(), n = H(null);
1262
+ }, en = () => {
1263
+ const { state: r, actions: e } = ee(), n = H(null);
1235
1264
  return /* @__PURE__ */ m(
1236
1265
  "div",
1237
1266
  {
1238
1267
  className: "inlineContainer",
1239
1268
  "data-testid": "citadel-inline-container",
1240
1269
  children: /* @__PURE__ */ m(
1241
- pe,
1270
+ fe,
1242
1271
  {
1243
1272
  state: r,
1244
1273
  actions: e,
@@ -1247,7 +1276,7 @@ const Ge = () => {
1247
1276
  )
1248
1277
  }
1249
1278
  );
1250
- }, re = `:host {
1279
+ }, ie = `:host {
1251
1280
  --citadel-bg: rgb(17, 24, 39);
1252
1281
  --citadel-text: rgba(255, 255, 255, 0.87);
1253
1282
  --citadel-border: rgb(55, 65, 81);
@@ -1351,7 +1380,7 @@ a:hover {
1351
1380
  .text-left {
1352
1381
  text-align: left;
1353
1382
  }
1354
- `, oe = `/* Keep only component-specific styles here */
1383
+ `, le = `/* Keep only component-specific styles here */
1355
1384
 
1356
1385
  .panelContainer {
1357
1386
  position: fixed;
@@ -1433,10 +1462,10 @@ a:hover {
1433
1462
  overflow: hidden;
1434
1463
  box-sizing: border-box;
1435
1464
  }
1436
- `, se = `@tailwind base;
1465
+ `, ce = `@tailwind base;
1437
1466
  @tailwind components;
1438
1467
  @tailwind utilities;
1439
- `, en = `*, ::before, ::after {
1468
+ `, nn = `*, ::before, ::after {
1440
1469
  --tw-border-spacing-x: 0;
1441
1470
  --tw-border-spacing-y: 0;
1442
1471
  --tw-translate-x: 0;
@@ -2253,75 +2282,85 @@ video {
2253
2282
  .last\\:mr-0:last-child {
2254
2283
  margin-right: 0px;
2255
2284
  }
2256
- `, cn = ({
2257
- config: r = z,
2258
- commandRegistry: e = new Q(),
2285
+ `, dn = ({
2286
+ config: r = _,
2287
+ commandRegistry: e = new Z(),
2259
2288
  containerId: n = null
2260
2289
  }) => {
2261
- const t = H(null), o = r.displayMode ?? z.displayMode ?? "panel";
2290
+ const t = H(null), o = r.displayMode ?? _.displayMode ?? "panel";
2262
2291
  return A(() => {
2263
2292
  C.configure({
2264
- level: r.logLevel || z.logLevel || W.ERROR,
2293
+ level: r.logLevel || _.logLevel || Q.ERROR,
2265
2294
  prefix: "[Citadel]"
2266
2295
  });
2267
- const s = new he(e, r), a = o === "inline" && !n, l = a ? t.current : n ? document.getElementById(n) : document.body;
2268
- if (l)
2269
- l.appendChild(s);
2296
+ const a = new we(e, r), i = o === "inline" && !n, c = i ? t.current : n ? document.getElementById(n) : document.body;
2297
+ if (c)
2298
+ c.appendChild(a);
2270
2299
  else {
2271
- if (a) {
2300
+ if (i) {
2272
2301
  console.warn("[Citadel] No host available for inline mode; skipping mount.");
2273
2302
  return;
2274
2303
  }
2275
- console.warn(`Container with id "${n}" not found, falling back to body`), document.body.appendChild(s);
2304
+ console.warn(`Container with id "${n}" not found, falling back to body`), document.body.appendChild(a);
2276
2305
  }
2277
2306
  return () => {
2278
- var d;
2279
- (d = s.parentElement) == null || d.removeChild(s);
2307
+ var s;
2308
+ (s = a.parentElement) == null || s.removeChild(a);
2280
2309
  };
2281
2310
  }, [e, n, r, o]), o === "inline" && !n ? /* @__PURE__ */ m("div", { ref: t, style: { width: "100%", height: "100%" } }) : null;
2282
2311
  };
2283
- class he extends HTMLElement {
2312
+ class we extends HTMLElement {
2284
2313
  constructor(n, t) {
2285
- var s;
2314
+ var a;
2286
2315
  super();
2287
2316
  b(this, "shadow");
2288
2317
  b(this, "root", null);
2289
2318
  b(this, "commandRegistry");
2290
2319
  b(this, "config");
2291
2320
  this.shadow = this.attachShadow({ mode: "open" }), this.commandRegistry = n, this.config = t;
2292
- const o = ((s = this.config) == null ? void 0 : s.displayMode) ?? "panel";
2321
+ const o = ((a = this.config) == null ? void 0 : a.displayMode) ?? "panel";
2293
2322
  this.setAttribute("data-display-mode", o);
2294
2323
  }
2295
2324
  connectedCallback() {
2296
2325
  try {
2297
- const t = [re, oe, se, en].map((o) => {
2298
- const s = new CSSStyleSheet();
2299
- return s.replaceSync(o), s;
2326
+ const t = [ie, le, ce, nn].map((o) => {
2327
+ const a = new CSSStyleSheet();
2328
+ return a.replaceSync(o), a;
2300
2329
  });
2301
2330
  this.shadow.adoptedStyleSheets = [...t];
2302
2331
  } catch {
2303
- const t = [re, oe, se].join(`
2332
+ const t = [ie, le, ce].join(`
2304
2333
  `), o = document.createElement("style");
2305
2334
  o.textContent = t, this.shadow.appendChild(o);
2306
2335
  }
2307
2336
  const n = document.createElement("div");
2308
- n.id = "citadel-root", n.style.width = "100%", n.style.height = "100%", this.shadow.appendChild(n), this.root = xe(n), this.root.render(
2309
- /* @__PURE__ */ m(Ie, { config: this.config || z, commandRegistry: this.commandRegistry, children: /* @__PURE__ */ m(nn, {}) })
2337
+ n.id = "citadel-root", n.style.width = "100%", n.style.height = "100%", this.shadow.appendChild(n), this.root = ke(n), this.root.render(
2338
+ /* @__PURE__ */ m(Pe, { config: this.config || _, commandRegistry: this.commandRegistry, children: /* @__PURE__ */ m(tn, {}) })
2310
2339
  );
2311
2340
  }
2341
+ disconnectedCallback() {
2342
+ const n = this.root;
2343
+ if (this.root = null, !n) {
2344
+ this.shadow.replaceChildren();
2345
+ return;
2346
+ }
2347
+ queueMicrotask(() => {
2348
+ n.unmount(), this.shadow.replaceChildren();
2349
+ });
2350
+ }
2312
2351
  }
2313
- customElements.define("citadel-element", he);
2314
- const nn = () => (F().displayMode ?? "panel") === "inline" ? /* @__PURE__ */ m(Ze, {}) : /* @__PURE__ */ m(Xe, {});
2352
+ typeof window < "u" && window.customElements && !window.customElements.get("citadel-element") && window.customElements.define("citadel-element", we);
2353
+ const tn = () => ($().displayMode ?? "panel") === "inline" ? /* @__PURE__ */ m(en, {}) : /* @__PURE__ */ m(Ze, {});
2315
2354
  export {
2316
- cn as Citadel,
2317
- Q as CommandRegistry,
2318
- U as CommandResult,
2319
- T as CommandStatus,
2320
- We as DEFAULT_CURSOR_CONFIGS,
2321
- ve as ErrorCommandResult,
2322
- ln as ImageCommandResult,
2323
- an as JsonCommandResult,
2324
- Re as OutputItem,
2325
- Ce as PendingCommandResult,
2326
- ae as TextCommandResult
2355
+ dn as Citadel,
2356
+ Z as CommandRegistry,
2357
+ T as CommandResult,
2358
+ F as CommandStatus,
2359
+ Ve as DEFAULT_CURSOR_CONFIGS,
2360
+ Ne as ErrorCommandResult,
2361
+ cn as ImageCommandResult,
2362
+ ln as JsonCommandResult,
2363
+ J as OutputItem,
2364
+ Ee as PendingCommandResult,
2365
+ G as TextCommandResult
2327
2366
  };