privateer-agent 0.15.5 → 0.15.6

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.
Files changed (214) hide show
  1. package/README.md +11 -0
  2. package/bin/boot-bundle.d.mts +2 -0
  3. package/bin/boot-bundle.mjs +44 -0
  4. package/bin/privateer-launch.mjs +14 -2
  5. package/bin/privateer-verify.mjs +12 -0
  6. package/dist-boot/boot.mjs +3 -0
  7. package/dist-boot/c-27JKSMWL.mjs +1460 -0
  8. package/dist-boot/c-2BMRFV24.mjs +269 -0
  9. package/dist-boot/c-2CTF6JA3.mjs +166 -0
  10. package/dist-boot/c-2G3BBHRJ.mjs +84 -0
  11. package/dist-boot/c-2IDLKXX6.mjs +250 -0
  12. package/dist-boot/c-2NJD5VYM.mjs +8 -0
  13. package/dist-boot/c-2S5EEQPW.mjs +1602 -0
  14. package/dist-boot/c-2WRDCUVI.mjs +25 -0
  15. package/dist-boot/c-2YN3M256.mjs +14 -0
  16. package/dist-boot/c-37GM3GMU.mjs +187 -0
  17. package/dist-boot/c-3STKRSVO.mjs +2480 -0
  18. package/dist-boot/c-3TPV6TQQ.mjs +2320 -0
  19. package/dist-boot/c-3UVHLQDJ.mjs +225 -0
  20. package/dist-boot/c-42PUUZYC.mjs +697 -0
  21. package/dist-boot/c-4D5UMWVW.mjs +683 -0
  22. package/dist-boot/c-4ETZRMTA.mjs +46 -0
  23. package/dist-boot/c-4QT25BD5.mjs +1482 -0
  24. package/dist-boot/c-4WVR32AP.mjs +2579 -0
  25. package/dist-boot/c-5EMM567G.mjs +152 -0
  26. package/dist-boot/c-5FA4CV63.mjs +145 -0
  27. package/dist-boot/c-5GV3X3RB.mjs +14 -0
  28. package/dist-boot/c-5JCEPRIY.mjs +52 -0
  29. package/dist-boot/c-5NDKIIWT.mjs +16 -0
  30. package/dist-boot/c-5QL3AR26.mjs +4665 -0
  31. package/dist-boot/c-5XY6MFKN.mjs +5142 -0
  32. package/dist-boot/c-65UZIZC7.mjs +2897 -0
  33. package/dist-boot/c-6FUXKHOK.mjs +1969 -0
  34. package/dist-boot/c-6JHWQE4V.mjs +18242 -0
  35. package/dist-boot/c-6LOBR4I6.mjs +5280 -0
  36. package/dist-boot/c-6QHOZXKQ.mjs +14394 -0
  37. package/dist-boot/c-6ZO2SADQ.mjs +178 -0
  38. package/dist-boot/c-6ZORVVZP.mjs +1449 -0
  39. package/dist-boot/c-76QH4UCP.mjs +2441 -0
  40. package/dist-boot/c-77GO5L5Y.mjs +20982 -0
  41. package/dist-boot/c-7M23XFTN.mjs +5052 -0
  42. package/dist-boot/c-7TC367E2.mjs +32 -0
  43. package/dist-boot/c-7UOG7POX.mjs +1524 -0
  44. package/dist-boot/c-7VHP3FLN.mjs +376 -0
  45. package/dist-boot/c-A73JHZP2.mjs +13207 -0
  46. package/dist-boot/c-ABXULAFL.mjs +71 -0
  47. package/dist-boot/c-ANDD2AQO.mjs +74 -0
  48. package/dist-boot/c-AOY77AZL.mjs +1430 -0
  49. package/dist-boot/c-AXEPZ22I.mjs +108 -0
  50. package/dist-boot/c-B2Y7VNHU.mjs +427 -0
  51. package/dist-boot/c-B7VJUH73.mjs +77 -0
  52. package/dist-boot/c-BFW6CDVL.mjs +24 -0
  53. package/dist-boot/c-BHNIF2AR.mjs +188 -0
  54. package/dist-boot/c-BKF2O6BL.mjs +23 -0
  55. package/dist-boot/c-BOZXFTZN.mjs +8 -0
  56. package/dist-boot/c-BRNYJWZL.mjs +28 -0
  57. package/dist-boot/c-C3N4Z2HO.mjs +93 -0
  58. package/dist-boot/c-C4IV7ZFG.mjs +717 -0
  59. package/dist-boot/c-C5NK6UYV.mjs +793 -0
  60. package/dist-boot/c-C67644MB.mjs +1659 -0
  61. package/dist-boot/c-C6S2YB53.mjs +620 -0
  62. package/dist-boot/c-CDBEJSBF.mjs +37 -0
  63. package/dist-boot/c-CG47HBKU.mjs +435 -0
  64. package/dist-boot/c-CKCTWCT5.mjs +51 -0
  65. package/dist-boot/c-CN77DCGF.mjs +60 -0
  66. package/dist-boot/c-CRBXNKFO.mjs +1795 -0
  67. package/dist-boot/c-CRIHASQ6.mjs +973 -0
  68. package/dist-boot/c-CU4NGAUO.mjs +3786 -0
  69. package/dist-boot/c-CWRFLGQU.mjs +1883 -0
  70. package/dist-boot/c-CYQB2USO.mjs +32 -0
  71. package/dist-boot/c-DEE67DJO.mjs +379 -0
  72. package/dist-boot/c-DIFDBYOP.mjs +1258 -0
  73. package/dist-boot/c-DOSGVXDZ.mjs +34879 -0
  74. package/dist-boot/c-DR7XQI32.mjs +381 -0
  75. package/dist-boot/c-DTGPSB46.mjs +14666 -0
  76. package/dist-boot/c-DTHDNA4P.mjs +320 -0
  77. package/dist-boot/c-E4Z3Y5B5.mjs +3864 -0
  78. package/dist-boot/c-E66Z2TI7.mjs +203 -0
  79. package/dist-boot/c-EBU6RLRV.mjs +1527 -0
  80. package/dist-boot/c-EBZZNGSF.mjs +432 -0
  81. package/dist-boot/c-EC3LJ2KF.mjs +1032 -0
  82. package/dist-boot/c-EQBKXWNX.mjs +15829 -0
  83. package/dist-boot/c-EUEPIW4S.mjs +574 -0
  84. package/dist-boot/c-EX4YVWAT.mjs +378 -0
  85. package/dist-boot/c-EYZGSAJU.mjs +98 -0
  86. package/dist-boot/c-F75VRKY4.mjs +172 -0
  87. package/dist-boot/c-FH4NXKHV.mjs +177 -0
  88. package/dist-boot/c-FHNUCTEM.mjs +140 -0
  89. package/dist-boot/c-FJ5T42DS.mjs +5349 -0
  90. package/dist-boot/c-FPCNRL7G.mjs +1728 -0
  91. package/dist-boot/c-G4DLN7Q4.mjs +8 -0
  92. package/dist-boot/c-G56GYQFZ.mjs +2507 -0
  93. package/dist-boot/c-GLIOERDQ.mjs +1200 -0
  94. package/dist-boot/c-GMJ5HUBM.mjs +14 -0
  95. package/dist-boot/c-H3HSGMAQ.mjs +461 -0
  96. package/dist-boot/c-HIKTO6P7.mjs +275 -0
  97. package/dist-boot/c-I2MCJ34O.mjs +464 -0
  98. package/dist-boot/c-I3C6LBW4.mjs +765 -0
  99. package/dist-boot/c-I54OKQHW.mjs +387 -0
  100. package/dist-boot/c-IFSP3R4D.mjs +80 -0
  101. package/dist-boot/c-IZK77VB7.mjs +171 -0
  102. package/dist-boot/c-J3Y25UGE.mjs +54 -0
  103. package/dist-boot/c-J5IESS7W.mjs +27750 -0
  104. package/dist-boot/c-JJWZBY7L.mjs +254 -0
  105. package/dist-boot/c-JKTFXTGF.mjs +463 -0
  106. package/dist-boot/c-JN57AXQ4.mjs +77 -0
  107. package/dist-boot/c-KFIO6LUW.mjs +1096 -0
  108. package/dist-boot/c-KIEMEFWW.mjs +478 -0
  109. package/dist-boot/c-KIVXWBYD.mjs +28 -0
  110. package/dist-boot/c-KP6CRIP4.mjs +580 -0
  111. package/dist-boot/c-L26VOJX4.mjs +11558 -0
  112. package/dist-boot/c-L5GHWG5G.mjs +5988 -0
  113. package/dist-boot/c-M7NSQAKK.mjs +353 -0
  114. package/dist-boot/c-MCEWOPBW.mjs +56 -0
  115. package/dist-boot/c-MGPIEG7I.mjs +20 -0
  116. package/dist-boot/c-NREXJV3M.mjs +393 -0
  117. package/dist-boot/c-O5PP6CTX.mjs +162 -0
  118. package/dist-boot/c-OBQDHSXM.mjs +1774 -0
  119. package/dist-boot/c-OLQHHDD4.mjs +21 -0
  120. package/dist-boot/c-OXW4JQQH.mjs +319 -0
  121. package/dist-boot/c-P3D7ZUWN.mjs +1288 -0
  122. package/dist-boot/c-P4PQZVV5.mjs +948 -0
  123. package/dist-boot/c-P63T3XL2.mjs +26373 -0
  124. package/dist-boot/c-P6N5DQGZ.mjs +194 -0
  125. package/dist-boot/c-P7MLKQFC.mjs +58 -0
  126. package/dist-boot/c-PB3PZJL5.mjs +1276 -0
  127. package/dist-boot/c-PTN4S6G2.mjs +1259 -0
  128. package/dist-boot/c-PYCE5J7U.mjs +1083 -0
  129. package/dist-boot/c-Q4HYCRLB.mjs +19410 -0
  130. package/dist-boot/c-QUXMETGG.mjs +68 -0
  131. package/dist-boot/c-RDMJZCOX.mjs +356 -0
  132. package/dist-boot/c-ROGJK76M.mjs +17 -0
  133. package/dist-boot/c-RQJJ26T4.mjs +708 -0
  134. package/dist-boot/c-RSKCUPJF.mjs +7559 -0
  135. package/dist-boot/c-RVJU4O6P.mjs +37 -0
  136. package/dist-boot/c-S2RVHR3M.mjs +165 -0
  137. package/dist-boot/c-SKMK3PEE.mjs +91120 -0
  138. package/dist-boot/c-TI7SM4EG.mjs +20 -0
  139. package/dist-boot/c-TILJ6GXD.mjs +1235 -0
  140. package/dist-boot/c-TT6BCUJD.mjs +114 -0
  141. package/dist-boot/c-U4ITOXAN.mjs +2107 -0
  142. package/dist-boot/c-UGERXVO2.mjs +7120 -0
  143. package/dist-boot/c-UPBH5AXY.mjs +1363 -0
  144. package/dist-boot/c-US2PUNZL.mjs +597 -0
  145. package/dist-boot/c-UU4WZPPE.mjs +20 -0
  146. package/dist-boot/c-UWVIYPQS.mjs +39 -0
  147. package/dist-boot/c-V4RHQBPQ.mjs +17683 -0
  148. package/dist-boot/c-V5MRVK47.mjs +351 -0
  149. package/dist-boot/c-V6CL266R.mjs +1755 -0
  150. package/dist-boot/c-VJTMFKYE.mjs +14975 -0
  151. package/dist-boot/c-VJTRUKIB.mjs +773 -0
  152. package/dist-boot/c-W4IFSHPW.mjs +43 -0
  153. package/dist-boot/c-WETGB2CF.mjs +113 -0
  154. package/dist-boot/c-WO3QSZUU.mjs +1337 -0
  155. package/dist-boot/c-WQLH73TY.mjs +242 -0
  156. package/dist-boot/c-XL735JW5.mjs +500 -0
  157. package/dist-boot/c-Y7HADL5B.mjs +1107 -0
  158. package/dist-boot/c-YGQHSVSK.mjs +41 -0
  159. package/dist-boot/c-YMP2AMEB.mjs +10350 -0
  160. package/dist-boot/c-YRDO2WEF.mjs +12012 -0
  161. package/dist-boot/c-YUSTRATJ.mjs +8 -0
  162. package/dist-boot/c-Z2262R22.mjs +2697 -0
  163. package/dist-boot/c-Z4ALQMJC.mjs +709 -0
  164. package/dist-boot/c-Z5ZUQVUY.mjs +62 -0
  165. package/dist-boot/c-ZDZUKXF7.mjs +874 -0
  166. package/dist-boot/c-ZJYLGIC3.mjs +32 -0
  167. package/dist-boot/c-ZNA5CDMI.mjs +77 -0
  168. package/dist-boot/c-ZSO6DI3M.mjs +204 -0
  169. package/dist-boot/c-ZWUVHKMK.mjs +100 -0
  170. package/dist-boot/c-ZY4MESEW.mjs +832 -0
  171. package/dist-boot/c-ZZ5REI4L.mjs +329 -0
  172. package/dist-boot/cli.mjs +51 -0
  173. package/dist-boot/ext-anthropic-attribution.mjs +207 -0
  174. package/dist-boot/ext-pi-background-tasks.mjs +7234 -0
  175. package/dist-boot/ext-pi-subagents.mjs +37 -0
  176. package/dist-boot/ext-privateer-account.mjs +4426 -0
  177. package/dist-boot/ext-privateer-brand.mjs +5274 -0
  178. package/dist-boot/ext-privateer-codemode.mjs +37 -0
  179. package/dist-boot/ext-privateer-computer.mjs +626 -0
  180. package/dist-boot/ext-privateer-connect.mjs +1862 -0
  181. package/dist-boot/ext-privateer-context.mjs +323 -0
  182. package/dist-boot/ext-privateer-desktop.mjs +92 -0
  183. package/dist-boot/ext-privateer-final-audit.mjs +48 -0
  184. package/dist-boot/ext-privateer-fresh.mjs +81 -0
  185. package/dist-boot/ext-privateer-gate.mjs +5959 -0
  186. package/dist-boot/ext-privateer-hints.mjs +236 -0
  187. package/dist-boot/ext-privateer-media.mjs +2626 -0
  188. package/dist-boot/ext-privateer-models.mjs +3397 -0
  189. package/dist-boot/ext-privateer-posture.mjs +3006 -0
  190. package/dist-boot/ext-privateer-privacy.mjs +4578 -0
  191. package/dist-boot/ext-privateer-recovery.mjs +287 -0
  192. package/dist-boot/ext-privateer-speak.mjs +4754 -0
  193. package/dist-boot/ext-privateer-terminals.mjs +725 -0
  194. package/dist-boot/ext-privateer-tools.mjs +528 -0
  195. package/dist-boot/ext-privateer-truncation.mjs +74 -0
  196. package/dist-boot/ext-privateer-update.mjs +210 -0
  197. package/dist-boot/ext-privateer-vision.mjs +148 -0
  198. package/dist-boot/ext-privateer-web.mjs +543 -0
  199. package/dist-boot/ext-rpiv-ask-user-question.mjs +710 -0
  200. package/dist-boot/manifest.json +9 -0
  201. package/extensions/privateer-brand.ts +3 -1
  202. package/extensions/privateer-context.ts +4 -2
  203. package/extensions/privateer-final-audit.ts +17 -0
  204. package/extensions/privateer-gate.ts +41 -8
  205. package/extensions/privateer-web.ts +4 -4
  206. package/package.json +3 -1
  207. package/patches/@earendil-works+pi-coding-agent+1.3.0.patch +110 -2
  208. package/patches/pi-background-tasks+2.6.10.patch +91 -7
  209. package/src/config/moatManifest.json +1 -0
  210. package/src/config/whatsNew.json +2 -2
  211. package/src/context.ts +33 -5
  212. package/src/engine/finalAudit.ts +38 -0
  213. package/src/engine/stallWatchdog.ts +8 -1
  214. package/src/providers/account.ts +34 -3
@@ -0,0 +1,1795 @@
1
+ import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
2
+ import {
3
+ source_default
4
+ } from "./c-KP6CRIP4.mjs";
5
+ import {
6
+ require_bash,
7
+ require_c,
8
+ require_core,
9
+ require_cpp,
10
+ require_csharp,
11
+ require_dart,
12
+ require_go,
13
+ require_groovy,
14
+ require_java,
15
+ require_javascript,
16
+ require_json,
17
+ require_kotlin,
18
+ require_lua,
19
+ require_nix,
20
+ require_perl,
21
+ require_php,
22
+ require_python,
23
+ require_ruby,
24
+ require_rust,
25
+ require_scala,
26
+ require_swift,
27
+ require_typescript
28
+ } from "./c-RSKCUPJF.mjs";
29
+ import {
30
+ getCustomThemesDir,
31
+ getThemesDir,
32
+ stripBom
33
+ } from "./c-PTN4S6G2.mjs";
34
+ import {
35
+ backgroundAnsi,
36
+ colorToHex,
37
+ colorToOkhsl,
38
+ colorToOklch,
39
+ colorToRgb,
40
+ foregroundAnsi,
41
+ getKeybindings,
42
+ getTerminalColorMode,
43
+ indexedColor,
44
+ mixColors,
45
+ okhslColor,
46
+ oklabToOkhslLightness,
47
+ oklchColor,
48
+ parseColor,
49
+ rgbColor,
50
+ styleTextWithAnsi
51
+ } from "./c-EQBKXWNX.mjs";
52
+ import {
53
+ __name,
54
+ __toESM
55
+ } from "./c-CN77DCGF.mjs";
56
+
57
+ // node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js
58
+ import * as fs from "node:fs";
59
+ import * as path from "node:path";
60
+
61
+ // node_modules/@earendil-works/pi-coding-agent/dist/utils/fs-watch.js
62
+ import { watch } from "node:fs";
63
+ var FS_WATCH_RETRY_DELAY_MS = 5e3;
64
+ function closeWatcher(watcher) {
65
+ if (!watcher) {
66
+ return;
67
+ }
68
+ try {
69
+ watcher.close();
70
+ } catch {
71
+ }
72
+ }
73
+ __name(closeWatcher, "closeWatcher");
74
+ function watchWithErrorHandler(path2, listener, onError) {
75
+ try {
76
+ const watcher = watch(path2, listener);
77
+ watcher.on("error", onError);
78
+ return watcher;
79
+ } catch {
80
+ onError();
81
+ return null;
82
+ }
83
+ }
84
+ __name(watchWithErrorHandler, "watchWithErrorHandler");
85
+
86
+ // node_modules/@earendil-works/pi-coding-agent/dist/utils/syntax-highlight.js
87
+ var import_core = __toESM(require_core(), 1);
88
+ var import_bash = __toESM(require_bash(), 1);
89
+ var import_c = __toESM(require_c(), 1);
90
+ var import_cpp = __toESM(require_cpp(), 1);
91
+ var import_csharp = __toESM(require_csharp(), 1);
92
+ var import_dart = __toESM(require_dart(), 1);
93
+ var import_go = __toESM(require_go(), 1);
94
+ var import_groovy = __toESM(require_groovy(), 1);
95
+ var import_java = __toESM(require_java(), 1);
96
+ var import_javascript = __toESM(require_javascript(), 1);
97
+ var import_json = __toESM(require_json(), 1);
98
+ var import_kotlin = __toESM(require_kotlin(), 1);
99
+ var import_lua = __toESM(require_lua(), 1);
100
+ var import_nix = __toESM(require_nix(), 1);
101
+ var import_perl = __toESM(require_perl(), 1);
102
+ var import_php = __toESM(require_php(), 1);
103
+ var import_python = __toESM(require_python(), 1);
104
+ var import_ruby = __toESM(require_ruby(), 1);
105
+ var import_rust = __toESM(require_rust(), 1);
106
+ var import_scala = __toESM(require_scala(), 1);
107
+ var import_swift = __toESM(require_swift(), 1);
108
+ var import_typescript = __toESM(require_typescript(), 1);
109
+
110
+ // node_modules/@earendil-works/pi-coding-agent/dist/utils/html.js
111
+ function decodeCodePoint(codePoint) {
112
+ if (!Number.isInteger(codePoint) || codePoint < 0 || codePoint > 1114111) {
113
+ return void 0;
114
+ }
115
+ return String.fromCodePoint(codePoint);
116
+ }
117
+ __name(decodeCodePoint, "decodeCodePoint");
118
+ function decodeHtmlEntity(entity) {
119
+ switch (entity) {
120
+ case "amp":
121
+ return "&";
122
+ case "lt":
123
+ return "<";
124
+ case "gt":
125
+ return ">";
126
+ case "quot":
127
+ return '"';
128
+ case "apos":
129
+ return "'";
130
+ }
131
+ if (entity.startsWith("#x") || entity.startsWith("#X")) {
132
+ return decodeCodePoint(Number.parseInt(entity.slice(2), 16));
133
+ }
134
+ if (entity.startsWith("#")) {
135
+ return decodeCodePoint(Number.parseInt(entity.slice(1), 10));
136
+ }
137
+ return void 0;
138
+ }
139
+ __name(decodeHtmlEntity, "decodeHtmlEntity");
140
+ function decodeHtmlEntityAt(html, index) {
141
+ const semicolonIndex = html.indexOf(";", index + 1);
142
+ if (semicolonIndex === -1 || semicolonIndex - index > 16) {
143
+ return void 0;
144
+ }
145
+ const entity = html.slice(index + 1, semicolonIndex);
146
+ const decoded = decodeHtmlEntity(entity);
147
+ if (decoded === void 0) {
148
+ return void 0;
149
+ }
150
+ return { text: decoded, length: semicolonIndex - index + 1 };
151
+ }
152
+ __name(decodeHtmlEntityAt, "decodeHtmlEntityAt");
153
+
154
+ // node_modules/@earendil-works/pi-coding-agent/dist/utils/syntax-highlight.js
155
+ var eagerLanguages = {
156
+ python: import_python.default,
157
+ java: import_java.default,
158
+ go: import_go.default,
159
+ javascript: import_javascript.default,
160
+ json: import_json.default,
161
+ cpp: import_cpp.default,
162
+ typescript: import_typescript.default,
163
+ php: import_php.default,
164
+ ruby: import_ruby.default,
165
+ c: import_c.default,
166
+ csharp: import_csharp.default,
167
+ nix: import_nix.default,
168
+ bash: import_bash.default,
169
+ rust: import_rust.default,
170
+ scala: import_scala.default,
171
+ kotlin: import_kotlin.default,
172
+ swift: import_swift.default,
173
+ dart: import_dart.default,
174
+ groovy: import_groovy.default,
175
+ perl: import_perl.default,
176
+ lua: import_lua.default
177
+ };
178
+ for (const [name, language] of Object.entries(eagerLanguages)) {
179
+ import_core.default.registerLanguage(name, language);
180
+ }
181
+ var allLanguagesPromise;
182
+ function loadAllHighlightLanguages() {
183
+ if (!allLanguagesPromise) {
184
+ allLanguagesPromise = new Promise((resolve) => {
185
+ setImmediate(() => {
186
+ void import("./c-J5IESS7W.mjs").then(() => resolve(), () => {
187
+ resolve();
188
+ });
189
+ });
190
+ });
191
+ }
192
+ return allLanguagesPromise;
193
+ }
194
+ __name(loadAllHighlightLanguages, "loadAllHighlightLanguages");
195
+ var SPAN_CLOSE = "</span>";
196
+ var HIGHLIGHT_CLASS_PREFIX = "hljs-";
197
+ function getScopeFromSpanTag(tag) {
198
+ const match = /\sclass\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(tag);
199
+ const classValue = match?.[1] ?? match?.[2];
200
+ if (!classValue) {
201
+ return void 0;
202
+ }
203
+ for (const className of classValue.split(/\s+/)) {
204
+ if (className.startsWith(HIGHLIGHT_CLASS_PREFIX)) {
205
+ return className.slice(HIGHLIGHT_CLASS_PREFIX.length);
206
+ }
207
+ }
208
+ return void 0;
209
+ }
210
+ __name(getScopeFromSpanTag, "getScopeFromSpanTag");
211
+ function getScopeFormatter(scope, theme2) {
212
+ const exact = theme2[scope];
213
+ if (exact) {
214
+ return exact;
215
+ }
216
+ const dotIndex = scope.indexOf(".");
217
+ if (dotIndex !== -1) {
218
+ const prefixFormatter = theme2[scope.slice(0, dotIndex)];
219
+ if (prefixFormatter) {
220
+ return prefixFormatter;
221
+ }
222
+ }
223
+ const dashIndex = scope.indexOf("-");
224
+ if (dashIndex !== -1) {
225
+ const prefixFormatter = theme2[scope.slice(0, dashIndex)];
226
+ if (prefixFormatter) {
227
+ return prefixFormatter;
228
+ }
229
+ }
230
+ return void 0;
231
+ }
232
+ __name(getScopeFormatter, "getScopeFormatter");
233
+ function getActiveFormatter(scopes, theme2) {
234
+ for (let i = scopes.length - 1; i >= 0; i--) {
235
+ const scope = scopes[i];
236
+ if (!scope) {
237
+ continue;
238
+ }
239
+ const formatter = getScopeFormatter(scope, theme2);
240
+ if (formatter) {
241
+ return formatter;
242
+ }
243
+ }
244
+ return theme2.default;
245
+ }
246
+ __name(getActiveFormatter, "getActiveFormatter");
247
+ function isSpanOpenTagStart(html, index) {
248
+ if (!html.startsWith("<span", index)) {
249
+ return false;
250
+ }
251
+ const nextChar = html[index + "<span".length];
252
+ return nextChar === ">" || nextChar === " " || nextChar === " " || nextChar === "\n" || nextChar === "\r";
253
+ }
254
+ __name(isSpanOpenTagStart, "isSpanOpenTagStart");
255
+ function renderHighlightedHtml(html, theme2 = {}) {
256
+ let output = "";
257
+ let textBuffer = "";
258
+ const scopes = [];
259
+ const flushText = /* @__PURE__ */ __name(() => {
260
+ if (!textBuffer) {
261
+ return;
262
+ }
263
+ const formatter = getActiveFormatter(scopes, theme2);
264
+ output += formatter ? textBuffer.split("\n").map((line) => line ? formatter(line) : line).join("\n") : textBuffer;
265
+ textBuffer = "";
266
+ }, "flushText");
267
+ let index = 0;
268
+ while (index < html.length) {
269
+ if (isSpanOpenTagStart(html, index)) {
270
+ const tagEndIndex = html.indexOf(">", index + 5);
271
+ if (tagEndIndex !== -1) {
272
+ flushText();
273
+ const tag = html.slice(index, tagEndIndex + 1);
274
+ const scope = getScopeFromSpanTag(tag);
275
+ scopes.push(scope);
276
+ index = tagEndIndex + 1;
277
+ continue;
278
+ }
279
+ }
280
+ if (html.startsWith(SPAN_CLOSE, index)) {
281
+ flushText();
282
+ if (scopes.length > 0) {
283
+ scopes.pop();
284
+ }
285
+ index += SPAN_CLOSE.length;
286
+ continue;
287
+ }
288
+ if (html[index] === "&") {
289
+ const decoded = decodeHtmlEntityAt(html, index);
290
+ if (decoded) {
291
+ textBuffer += decoded.text;
292
+ index += decoded.length;
293
+ continue;
294
+ }
295
+ }
296
+ textBuffer += html[index];
297
+ index++;
298
+ }
299
+ flushText();
300
+ return output;
301
+ }
302
+ __name(renderHighlightedHtml, "renderHighlightedHtml");
303
+ function highlight(code, options = {}) {
304
+ const html = options.language ? import_core.default.highlight(code, {
305
+ language: options.language,
306
+ ignoreIllegals: options.ignoreIllegals
307
+ }).value : import_core.default.highlightAuto(code, options.languageSubset).value;
308
+ return renderHighlightedHtml(html, options.theme);
309
+ }
310
+ __name(highlight, "highlight");
311
+ function supportsLanguage(name) {
312
+ return import_core.default.getLanguage(name) !== void 0;
313
+ }
314
+ __name(supportsLanguage, "supportsLanguage");
315
+
316
+ // node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/system-theme.js
317
+ var SYSTEM_THEME_NAME = "system";
318
+ var FAMILIES = {
319
+ neutral: { hue: 231.49, saturation: { min: 0.02, max: 0.08 }, slot: 8 },
320
+ blue: { hue: 231.49, saturation: { min: 0.1, max: 0.68 }, slot: 4 },
321
+ green: { hue: 158.68, saturation: { min: 0.1, max: 0.76 }, slot: 2 },
322
+ red: { hue: 20, saturation: { min: 0.1, max: 0.92 }, slot: 1 },
323
+ yellow: { hue: 82.36, saturation: { min: 0.5, max: 1 }, slot: 3 },
324
+ orange: { hue: 52, saturation: { min: 0.12, max: 0.85 }, slot: 3 },
325
+ violet: { hue: 295, saturation: { min: 0.2, max: 0.6 }, slot: 5 },
326
+ calamine: { hue: 202.43, saturation: { min: 0.1, max: 0.74 }, slot: 6 },
327
+ thinkingSlate: { hue: 231.49, saturation: { min: 0.08, max: 0.2 }, slot: 4 },
328
+ thinkingBlue: { hue: 231.49, saturation: { min: 0.2, max: 0.45 }, slot: 4 },
329
+ thinkingPeriwinkle: { hue: 263.25, saturation: { min: 0.3, max: 0.6 }, slot: 6 },
330
+ thinkingViolet: { hue: 295, saturation: { min: 0.4, max: 0.75 }, slot: 5 },
331
+ thinkingMagenta: { hue: 337.5, saturation: { min: 0.5, max: 0.85 }, slot: 13 },
332
+ thinkingRed: { hue: 20, saturation: { min: 0.95, max: 1 }, slot: 1 }
333
+ };
334
+ var TOKEN_FAMILIES = {
335
+ selectedBg: "blue",
336
+ searchMatchBg: "orange",
337
+ userMessageBg: "blue",
338
+ customMessageBg: "violet",
339
+ toolPendingBg: "neutral",
340
+ toolSuccessBg: "green",
341
+ toolErrorBg: "red",
342
+ text: "neutral",
343
+ userMessageText: "neutral",
344
+ customMessageText: "neutral",
345
+ toolTitle: "neutral",
346
+ syntaxOperator: "neutral",
347
+ syntaxPunctuation: "neutral",
348
+ muted: "neutral",
349
+ dim: "neutral",
350
+ thinkingText: "neutral",
351
+ toolOutput: "neutral",
352
+ mdLinkUrl: "neutral",
353
+ mdQuote: "neutral",
354
+ mdQuoteBorder: "neutral",
355
+ mdHr: "neutral",
356
+ mdCodeBlockBorder: "neutral",
357
+ toolDiffContext: "neutral",
358
+ syntaxComment: "neutral",
359
+ scrollbarTrack: "neutral",
360
+ scrollbarThumb: "neutral",
361
+ searchMatchText: "neutral",
362
+ borderMuted: "neutral",
363
+ accent: "violet",
364
+ borderAccent: "violet",
365
+ customMessageLabel: "violet",
366
+ mdCode: "violet",
367
+ mdListBullet: "violet",
368
+ syntaxType: "violet",
369
+ border: "blue",
370
+ mdLink: "blue",
371
+ syntaxKeyword: "blue",
372
+ syntaxVariable: "calamine",
373
+ success: "green",
374
+ mdCodeBlock: "green",
375
+ toolDiffAdded: "green",
376
+ bashMode: "green",
377
+ syntaxNumber: "green",
378
+ error: "red",
379
+ toolDiffRemoved: "red",
380
+ warning: "yellow",
381
+ mdHeading: "yellow",
382
+ syntaxFunction: "yellow",
383
+ syntaxString: "orange",
384
+ thinkingOff: "neutral",
385
+ thinkingMinimal: "thinkingSlate",
386
+ thinkingLow: "thinkingBlue",
387
+ thinkingMedium: "thinkingPeriwinkle",
388
+ thinkingHigh: "thinkingViolet",
389
+ thinkingXhigh: "thinkingMagenta",
390
+ thinkingMax: "thinkingRed"
391
+ };
392
+ var TOKEN_SLOTS = { syntaxString: 2, syntaxNumber: 5, searchMatchBg: 3 };
393
+ var LEVELS = {
394
+ panel: {
395
+ dark: { coefficients: [0.29131, -0.39746, 2.33185, -0.85524, -1.2076, 0.86276], reachable: [0, 0.979] },
396
+ light: { coefficients: [-3.74073, 27.94549, -78.44258, 112.6798, -79.60015, 22.11277], reachable: [0.348, 1] }
397
+ },
398
+ track: {
399
+ dark: { coefficients: [0.39028, -0.23015, 0.83573, 2.43829, -4.38292, 2.01582], reachable: [0, 0.946] },
400
+ light: { coefficients: [-5.24921, 38.37322, -107.28833, 152.10005, -106.17127, 29.18061], reachable: [0.368, 1] }
401
+ },
402
+ thinking0: {
403
+ dark: { coefficients: [0.52988, -0.05809, -0.30924, 4.63567, -6.52933, 2.89108], reachable: [0, 0.873] },
404
+ light: {
405
+ coefficients: [-28.27749, 182.85284, -469.62416, 603.15916, -384.59976, 97.35147],
406
+ reachable: [0.51, 1]
407
+ }
408
+ },
409
+ thinking1: {
410
+ dark: { coefficients: [0.55278, -0.03667, -0.45659, 4.95347, -6.90265, 3.0706], reachable: [0, 0.858] },
411
+ light: {
412
+ coefficients: [-37.10484, 235.86282, -596.62344, 754.3633, -474.00763, 118.3551],
413
+ reachable: [0.535, 1]
414
+ }
415
+ },
416
+ thinking2: {
417
+ dark: { coefficients: [0.57486, -0.01765, -0.58987, 5.25227, -7.27175, 3.25532], reachable: [0, 0.842] },
418
+ light: {
419
+ coefficients: [-59.89653, 377.05024, -945.07843, 1182.03145, -734.96375, 181.68658],
420
+ reachable: [0.556, 1]
421
+ }
422
+ },
423
+ thinking3: {
424
+ dark: { coefficients: [0.59621, -62e-5, -0.71148, 5.53588, -7.6392, 3.44606], reachable: [0, 0.827] },
425
+ light: {
426
+ coefficients: [-72.07122, 445.84082, -1099.57352, 1353.88793, -829.53392, 202.26164],
427
+ reachable: [0.58, 1]
428
+ }
429
+ },
430
+ thinking4: {
431
+ dark: { coefficients: [0.61691, 0.01462, -0.82288, 5.80651, -8.00641, 3.64333], reachable: [0, 0.811] },
432
+ light: {
433
+ coefficients: [-110.14338, 674.21488, -1645.75941, 2004.32367, -1215.15899, 293.3183],
434
+ reachable: [0.6, 1]
435
+ }
436
+ },
437
+ thinking5: {
438
+ dark: { coefficients: [0.63702, 0.02826, -0.92498, 6.06465, -8.37246, 3.84651], reachable: [0, 0.795] },
439
+ light: {
440
+ coefficients: [-175.47701, 1063.54495, -2570.70594, 3098.80776, -1860.15527, 444.76392],
441
+ reachable: [0.62, 1]
442
+ }
443
+ },
444
+ thinking6: {
445
+ dark: { coefficients: [0.65658, 0.04044, -1.01835, 6.30989, -8.73529, 4.05439], reachable: [0, 0.779] },
446
+ light: {
447
+ coefficients: [-183.81712, 1094.70055, -2602.68539, 3088.71276, -1826.91131, 430.75931],
448
+ reachable: [0.643, 1]
449
+ }
450
+ },
451
+ subtle: {
452
+ dark: { coefficients: [0.56762, -0.02475, -0.5383, 5.12628, -7.10931, 3.17324], reachable: [0, 0.848] },
453
+ light: {
454
+ coefficients: [-232.85459, 1376.54473, -3249.11801, 3827.91186, -2248.29472, 526.55751],
455
+ reachable: [0.657, 1]
456
+ }
457
+ },
458
+ thumb: {
459
+ dark: { coefficients: [0.60323, 278e-5, -0.73328, 5.57157, -7.68067, 3.46933], reachable: [0, 0.823] },
460
+ light: {
461
+ coefficients: [-82.89897, 511.01355, -1255.98095, 1540.76821, -940.68087, 228.58523],
462
+ reachable: [0.586, 1]
463
+ }
464
+ },
465
+ readable: {
466
+ dark: { coefficients: [0.66937, 0.04704, -1.06871, 6.43941, -8.9332, 4.17229], reachable: [0, 0.77] },
467
+ light: {
468
+ coefficients: [-1554.52576, 8733.56817, -19604.93507, 21977.72696, -12300.99599, 2749.81288],
469
+ reachable: [0.751, 1]
470
+ }
471
+ },
472
+ emphasis: {
473
+ dark: { coefficients: [0.7303, 0.07695, -1.31626, 7.1681, -10.14436, 4.92846], reachable: [0, 0.712] },
474
+ light: {
475
+ coefficients: [-4948.31942, 26870.91986, -58334.48399, 63280.17197, -34298.01053, 7430.30146],
476
+ reachable: [0.811, 1]
477
+ }
478
+ },
479
+ textOnPanel: {
480
+ dark: { coefficients: [0.86713, 0.05232, -0.89428, 4.79014, -5.5432, 1.75023], reachable: [0, 0.542] },
481
+ light: {
482
+ coefficients: [-8570.89457, 43954.60805, -90084.00702, 92220.6791, -47152.15802, 9632.27113],
483
+ reachable: [0.867, 1]
484
+ }
485
+ },
486
+ text: {
487
+ dark: { coefficients: [0.89242, 0.02311, -0.44862, 2.34417, -0.06084, -2.63844], reachable: [0, 0.5] },
488
+ light: {
489
+ coefficients: [-2004.67048, 6664.47299, -6060.70202, -1792.61209, 5133.82359, -1939.85583],
490
+ reachable: [0.894, 1]
491
+ }
492
+ }
493
+ };
494
+ var TOOL_PANELS = ["toolPendingBg", "toolSuccessBg", "toolErrorBg"];
495
+ var MESSAGE_PANELS = ["userMessageBg", "customMessageBg"];
496
+ var PANELS = [
497
+ "userMessageBg",
498
+ "toolPendingBg",
499
+ "toolSuccessBg",
500
+ "toolErrorBg",
501
+ "selectedBg",
502
+ "searchMatchBg",
503
+ "customMessageBg"
504
+ ];
505
+ var THINKING = [
506
+ "thinkingOff",
507
+ "thinkingMinimal",
508
+ "thinkingLow",
509
+ "thinkingMedium",
510
+ "thinkingHigh",
511
+ "thinkingXhigh",
512
+ "thinkingMax"
513
+ ];
514
+ var THINKING_LEVELS = [
515
+ "thinking0",
516
+ "thinking1",
517
+ "thinking2",
518
+ "thinking3",
519
+ "thinking4",
520
+ "thinking5",
521
+ "thinking6"
522
+ ];
523
+ var each = /* @__PURE__ */ __name((tokens, on, level) => tokens.map((token) => ({ token, on, level })), "each");
524
+ var RULES = [
525
+ ...each(PANELS, ["background"], "panel"),
526
+ { token: "text", on: ["background"], level: "text" },
527
+ { token: "text", on: ["selectedBg"], level: "textOnPanel" },
528
+ { token: "userMessageText", on: ["userMessageBg"], level: "textOnPanel" },
529
+ { token: "toolTitle", on: TOOL_PANELS, level: "textOnPanel" },
530
+ ...each(["accent", "success", "error", "warning"], ["background", "selectedBg", ...TOOL_PANELS], "readable"),
531
+ { token: "muted", on: ["background", "selectedBg", "customMessageBg", ...TOOL_PANELS], level: "readable" },
532
+ { token: "dim", on: ["background", "selectedBg", "customMessageBg", ...TOOL_PANELS], level: "subtle" },
533
+ { token: "thinkingText", on: ["background"], level: "readable" },
534
+ { token: "customMessageText", on: ["customMessageBg", ...TOOL_PANELS], level: "readable" },
535
+ {
536
+ token: "customMessageLabel",
537
+ on: ["background", "customMessageBg", "selectedBg", ...TOOL_PANELS],
538
+ level: "readable"
539
+ },
540
+ { token: "toolOutput", on: ["background", ...TOOL_PANELS], level: "readable" },
541
+ ...each(["mdHeading", "mdLink", "mdLinkUrl", "mdCode", "mdQuote", "mdCodeBlockBorder", "mdListBullet"], ["background", ...MESSAGE_PANELS], "readable"),
542
+ { token: "mdCodeBlock", on: ["background", ...MESSAGE_PANELS, ...TOOL_PANELS], level: "readable" },
543
+ ...each(["toolDiffAdded", "toolDiffRemoved", "toolDiffContext"], ["background", ...TOOL_PANELS], "readable"),
544
+ ...each([
545
+ "syntaxComment",
546
+ "syntaxKeyword",
547
+ "syntaxFunction",
548
+ "syntaxVariable",
549
+ "syntaxString",
550
+ "syntaxNumber",
551
+ "syntaxType",
552
+ "syntaxOperator",
553
+ "syntaxPunctuation"
554
+ ], ["background", ...MESSAGE_PANELS, ...TOOL_PANELS], "readable"),
555
+ { token: "searchMatchText", on: ["searchMatchBg"], level: "readable" },
556
+ ...each(["bashMode", "border", "borderAccent"], ["background"], "readable"),
557
+ { token: "borderMuted", on: ["background"], level: "subtle" },
558
+ ...each(["mdQuoteBorder", "mdHr"], ["background", ...MESSAGE_PANELS, ...TOOL_PANELS], "readable"),
559
+ { token: "scrollbarTrack", on: ["background"], level: "track" },
560
+ { token: "scrollbarThumb", on: ["scrollbarTrack"], level: "thumb" },
561
+ ...THINKING.map((token, index) => ({ token, on: ["background"], level: THINKING_LEVELS[index] }))
562
+ ];
563
+ var READABLE_FLOOR = { dark: "readable", light: "subtle" };
564
+ var FOREGROUND_LEVEL = "emphasis";
565
+ var FOREGROUND_TOKENS = ["text", "userMessageText", "toolTitle"];
566
+ var TEXT_MINIMUM_WCAG_CONTRAST = 4.5;
567
+ var SOLVE_ORDER = (() => {
568
+ const order = [];
569
+ const visit = /* @__PURE__ */ __name((token) => {
570
+ if (order.includes(token))
571
+ return;
572
+ for (const rule of RULES) {
573
+ if (rule.token !== token)
574
+ continue;
575
+ for (const surface of rule.on)
576
+ if (surface !== "background")
577
+ visit(surface);
578
+ }
579
+ order.push(token);
580
+ }, "visit");
581
+ for (const rule of RULES)
582
+ visit(rule.token);
583
+ return order;
584
+ })();
585
+ function oklabLightness(color) {
586
+ return colorToOklch(rgbColor(color.r, color.g, color.b)).l;
587
+ }
588
+ __name(oklabLightness, "oklabLightness");
589
+ function relativeLuminance({ r, g, b }) {
590
+ const linear = /* @__PURE__ */ __name((channel) => {
591
+ const value = channel / 255;
592
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
593
+ }, "linear");
594
+ return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);
595
+ }
596
+ __name(relativeLuminance, "relativeLuminance");
597
+ function wcagContrast(first, second) {
598
+ const a = relativeLuminance(first);
599
+ const b = relativeLuminance(second);
600
+ return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
601
+ }
602
+ __name(wcagContrast, "wcagContrast");
603
+ function terminalAppearance(background, foreground) {
604
+ const white = { r: 255, g: 255, b: 255 };
605
+ const black = { r: 0, g: 0, b: 0 };
606
+ const whiteContrast = wcagContrast(white, background);
607
+ const blackContrast = wcagContrast(black, background);
608
+ if (foreground) {
609
+ const foregroundL = oklabLightness(foreground);
610
+ const backgroundL = oklabLightness(background);
611
+ if (Math.abs(foregroundL - backgroundL) > 0.05) {
612
+ const appearance = foregroundL > backgroundL ? "dark" : "light";
613
+ const best = appearance === "dark" ? whiteContrast : blackContrast;
614
+ if (best >= TEXT_MINIMUM_WCAG_CONTRAST)
615
+ return appearance;
616
+ }
617
+ }
618
+ return whiteContrast >= blackContrast ? "dark" : "light";
619
+ }
620
+ __name(terminalAppearance, "terminalAppearance");
621
+ var clamp = /* @__PURE__ */ __name((value, min, max) => Math.min(max, Math.max(min, value)), "clamp");
622
+ function hexOf({ r, g, b }) {
623
+ return `#${[r, g, b].map((channel) => Math.round(channel).toString(16).padStart(2, "0")).join("")}`;
624
+ }
625
+ __name(hexOf, "hexOf");
626
+ function bellWeight(lightness) {
627
+ const gaussian = /* @__PURE__ */ __name((x) => Math.exp(-((x - 0.5) ** 2) / (2 * 0.25 ** 2)), "gaussian");
628
+ return (gaussian(lightness) - gaussian(0)) / (1 - gaussian(0));
629
+ }
630
+ __name(bellWeight, "bellWeight");
631
+ function saturationCurve({ saturation: { min, max } }, lightness) {
632
+ const floor = max > 0 ? min / max : 1;
633
+ return floor + (1 - floor) * bellWeight(lightness);
634
+ }
635
+ __name(saturationCurve, "saturationCurve");
636
+ function levelTarget(level, appearance, surfaceL) {
637
+ const curve = LEVELS[level][appearance];
638
+ if (surfaceL < curve.reachable[0] || surfaceL > curve.reachable[1])
639
+ return void 0;
640
+ return curve.coefficients.reduce((sum, coefficient, power) => sum + coefficient * surfaceL ** power, 0);
641
+ }
642
+ __name(levelTarget, "levelTarget");
643
+ function generateSystemThemeColors(input) {
644
+ const saturation = clamp(input.saturation ?? 1, 0, 1);
645
+ const { background, foreground } = input;
646
+ if (!background)
647
+ return indexedColors(saturation, input.appearanceHint);
648
+ const palette = input.palette?.length === 16 ? input.palette.map(sourceOf) : void 0;
649
+ const appearance = terminalAppearance(background, foreground);
650
+ const lighter = appearance === "dark";
651
+ const extreme = lighter ? 1 : 0;
652
+ const backgroundL = oklabLightness(background);
653
+ const paint = /* @__PURE__ */ __name((token, oklabL) => {
654
+ const lightness = oklabToOkhslLightness(oklabL);
655
+ const family = FAMILIES[TOKEN_FAMILIES[token]];
656
+ if (!palette) {
657
+ const { min, max } = family.saturation;
658
+ return okhslColor(family.hue, (min + (max - min) * bellWeight(lightness)) * saturation, lightness);
659
+ }
660
+ return anchored(palette[TOKEN_SLOTS[token] ?? family.slot], family, lightness, saturation);
661
+ }, "paint");
662
+ const target = /* @__PURE__ */ __name((level, surfaceL, t) => {
663
+ const reached = levelTarget(level, appearance, surfaceL);
664
+ if (reached === void 0 && t === 0)
665
+ return void 0;
666
+ const distance = (reached ?? extreme) - surfaceL;
667
+ const floor = (levelTarget(READABLE_FLOOR[appearance], appearance, surfaceL) ?? extreme) - surfaceL;
668
+ const compressed = Math.abs(distance) > Math.abs(floor) ? distance - (distance - floor) * Math.min(t, 1) : distance;
669
+ return surfaceL + compressed * (1 - Math.max(0, t - 1));
670
+ }, "target");
671
+ const extremeText = lighter ? { r: 255, g: 255, b: 255 } : { r: 0, g: 0, b: 0 };
672
+ const readable = /* @__PURE__ */ __name((color) => wcagContrast(extremeText, color) >= TEXT_MINIMUM_WCAG_CONTRAST, "readable");
673
+ const limitPanel = /* @__PURE__ */ __name((token, l) => {
674
+ const color = paint(token, l);
675
+ if (readable(color))
676
+ return color;
677
+ let [low, high] = [backgroundL, l];
678
+ for (let index = 0; index < 20; index++) {
679
+ const middle = (low + high) / 2;
680
+ if (readable(paint(token, middle)))
681
+ low = middle;
682
+ else
683
+ high = middle;
684
+ }
685
+ return paint(token, low);
686
+ }, "limitPanel");
687
+ const solve = /* @__PURE__ */ __name((t) => {
688
+ const colors2 = /* @__PURE__ */ new Map([["background", background]]);
689
+ for (const token of SOLVE_ORDER) {
690
+ const targets = [];
691
+ for (const rule of RULES) {
692
+ if (rule.token !== token)
693
+ continue;
694
+ for (const surface of rule.on) {
695
+ const value = target(rule.level, oklabLightness(colors2.get(surface) ?? background), t);
696
+ if (value === void 0 || value < 0 || value > 1)
697
+ return void 0;
698
+ targets.push(value);
699
+ }
700
+ }
701
+ const l = lighter ? Math.max(...targets) : Math.min(...targets);
702
+ colors2.set(token, PANELS.includes(token) ? limitPanel(token, l) : paint(token, l));
703
+ }
704
+ return colors2;
705
+ }, "solve");
706
+ let relaxation = 0;
707
+ let colors = solve(0);
708
+ if (!colors) {
709
+ let [low, high] = [0, 2];
710
+ colors = solve(high);
711
+ for (let index = 0; index < 20; index++) {
712
+ const middle = (low + high) / 2;
713
+ const attempt = solve(middle);
714
+ if (attempt)
715
+ [high, colors] = [middle, attempt];
716
+ else
717
+ low = middle;
718
+ }
719
+ relaxation = high;
720
+ }
721
+ const solved = colors ?? /* @__PURE__ */ new Map();
722
+ const surfacesOf = /* @__PURE__ */ __name((token) => RULES.filter((rule) => rule.token === token).flatMap((rule) => rule.on.map((surface) => solved.get(surface) ?? background)), "surfacesOf");
723
+ const result = {};
724
+ for (const token of Object.keys(TOKEN_FAMILIES)) {
725
+ const color = solved.get(token);
726
+ result[token] = color ? hexOf(color) : "";
727
+ }
728
+ for (const token of FOREGROUND_TOKENS) {
729
+ const surfaces = surfacesOf(token);
730
+ let text = solved.get(token);
731
+ if (foreground) {
732
+ const targets = surfaces.map((surface) => target(FOREGROUND_LEVEL, oklabLightness(surface), relaxation));
733
+ if (targets.every((value) => value !== void 0 && value >= 0 && value <= 1)) {
734
+ const needed = lighter ? Math.max(...targets) : Math.min(...targets);
735
+ const foregroundL = oklabLightness(foreground);
736
+ if (lighter ? foregroundL >= needed : foregroundL <= needed) {
737
+ result[token] = "";
738
+ continue;
739
+ }
740
+ text = anchored(sourceOf(foreground), FAMILIES.neutral, oklabToOkhslLightness(needed), saturation);
741
+ }
742
+ }
743
+ if (text)
744
+ result[token] = hexOf(withTextContrast(text, surfaces, lighter));
745
+ }
746
+ return { colors: result, dim: [], appearance };
747
+ }
748
+ __name(generateSystemThemeColors, "generateSystemThemeColors");
749
+ function okhslOf({ r, g, b }) {
750
+ return colorToOkhsl(rgbColor(r, g, b));
751
+ }
752
+ __name(okhslOf, "okhslOf");
753
+ function sourceOf(color) {
754
+ return { ...okhslOf(color), chroma: colorToOklch(rgbColor(color.r, color.g, color.b)).c };
755
+ }
756
+ __name(sourceOf, "sourceOf");
757
+ function anchored(source, family, lightness, saturation) {
758
+ const anchor = saturationCurve(family, source.l);
759
+ const falloff = anchor > 0 ? Math.min(1, saturationCurve(family, lightness) / anchor) : 1;
760
+ const color = okhslColor(source.h, source.s * falloff * saturation, lightness);
761
+ const cap = source.chroma * falloff * saturation;
762
+ const { l, c: c2 } = colorToOklch(color);
763
+ return c2 <= cap ? color : colorToRgb(oklchColor(l, cap, source.h));
764
+ }
765
+ __name(anchored, "anchored");
766
+ function withTextContrast(color, surfaces, lighter) {
767
+ const meets = /* @__PURE__ */ __name((candidate) => surfaces.every((surface) => wcagContrast(candidate, surface) >= TEXT_MINIMUM_WCAG_CONTRAST), "meets");
768
+ if (meets(color))
769
+ return color;
770
+ const { h, s, l } = okhslOf(color);
771
+ const at = /* @__PURE__ */ __name((lightness) => okhslColor(h, s, lightness), "at");
772
+ const extreme = lighter ? 1 : 0;
773
+ if (!meets(at(extreme)))
774
+ return at(extreme);
775
+ let [low, high] = [l, extreme];
776
+ for (let index = 0; index < 20; index++) {
777
+ const middle = (low + high) / 2;
778
+ if (meets(at(middle)))
779
+ high = middle;
780
+ else
781
+ low = middle;
782
+ }
783
+ return at(high);
784
+ }
785
+ __name(withTextContrast, "withTextContrast");
786
+ function indexedColors(saturation, appearance) {
787
+ const colors = {};
788
+ const dim = [];
789
+ for (const [token, familyName] of Object.entries(TOKEN_FAMILIES)) {
790
+ if (PANELS.includes(token)) {
791
+ colors[token] = "";
792
+ continue;
793
+ }
794
+ const neutral = familyName === "neutral";
795
+ colors[token] = !neutral && saturation > 0 ? TOKEN_SLOTS[token] ?? FAMILIES[familyName].slot : "";
796
+ if (neutral && !FOREGROUND_TOKENS.includes(token))
797
+ dim.push(token);
798
+ }
799
+ return { colors, dim, appearance };
800
+ }
801
+ __name(indexedColors, "indexedColors");
802
+
803
+ // node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme-tokens.js
804
+ function defineThemeTokens(tokens) {
805
+ for (const [name, descriptor] of Object.entries(tokens)) {
806
+ if (descriptor.fallback === void 0)
807
+ continue;
808
+ const fallback = tokens[descriptor.fallback];
809
+ if (fallback === void 0) {
810
+ throw new Error(`Theme token ${name} has unknown fallback ${descriptor.fallback}`);
811
+ }
812
+ if (fallback.slot !== descriptor.slot) {
813
+ throw new Error(`Theme token ${name} has fallback ${descriptor.fallback} in a different color slot`);
814
+ }
815
+ }
816
+ return tokens;
817
+ }
818
+ __name(defineThemeTokens, "defineThemeTokens");
819
+ var THEME_TOKENS = defineThemeTokens({
820
+ accent: { slot: "foreground", description: "Primary accent color (logo, selected items, cursor)" },
821
+ border: { slot: "foreground", description: "Normal borders" },
822
+ borderAccent: { slot: "foreground", description: "Highlighted borders" },
823
+ borderMuted: { slot: "foreground", description: "Subtle borders" },
824
+ success: { slot: "foreground", description: "Success states" },
825
+ error: { slot: "foreground", description: "Error states" },
826
+ warning: { slot: "foreground", description: "Warning states" },
827
+ muted: { slot: "foreground", description: "Secondary/dimmed text" },
828
+ dim: { slot: "foreground", description: "Very dimmed text (more subtle than muted)" },
829
+ text: { slot: "foreground", description: "Default text color (usually empty string)" },
830
+ thinkingText: { slot: "foreground", description: "Thinking block text color" },
831
+ scrollbarTrack: {
832
+ slot: "foreground",
833
+ description: "Fullscreen scrollbar track foreground (falls back to muted when omitted)",
834
+ fallback: "muted"
835
+ },
836
+ scrollbarThumb: {
837
+ slot: "foreground",
838
+ description: "Fullscreen scrollbar thumb foreground (falls back to text when omitted)",
839
+ fallback: "text"
840
+ },
841
+ selectedBg: { slot: "background", description: "Selected item background" },
842
+ searchMatchBg: {
843
+ slot: "background",
844
+ description: "Transcript search match background and current-match text (falls back to selectedBg when omitted)",
845
+ fallback: "selectedBg"
846
+ },
847
+ searchMatchText: {
848
+ slot: "foreground",
849
+ description: "Transcript search match text and current-match background (falls back to text when omitted)",
850
+ fallback: "text"
851
+ },
852
+ userMessageBg: { slot: "background", description: "User message background" },
853
+ userMessageText: { slot: "foreground", description: "User message text color" },
854
+ customMessageBg: { slot: "background", description: "Custom message background (hook-injected messages)" },
855
+ customMessageText: { slot: "foreground", description: "Custom message text color" },
856
+ customMessageLabel: { slot: "foreground", description: "Custom message type label color" },
857
+ toolPendingBg: { slot: "background", description: "Tool execution box (pending state)" },
858
+ toolSuccessBg: { slot: "background", description: "Tool execution box (success state)" },
859
+ toolErrorBg: { slot: "background", description: "Tool execution box (error state)" },
860
+ toolTitle: { slot: "foreground", description: "Tool execution box title color" },
861
+ toolOutput: { slot: "foreground", description: "Tool execution box output text color" },
862
+ mdHeading: { slot: "foreground", description: "Markdown heading text" },
863
+ mdLink: { slot: "foreground", description: "Markdown link text" },
864
+ mdLinkUrl: { slot: "foreground", description: "Markdown link URL" },
865
+ mdCode: { slot: "foreground", description: "Markdown inline code" },
866
+ mdCodeBlock: { slot: "foreground", description: "Markdown code block content" },
867
+ mdCodeBlockBorder: { slot: "foreground", description: "Markdown code block fences" },
868
+ mdQuote: { slot: "foreground", description: "Markdown blockquote text" },
869
+ mdQuoteBorder: { slot: "foreground", description: "Markdown blockquote border" },
870
+ mdHr: { slot: "foreground", description: "Markdown horizontal rule" },
871
+ mdListBullet: { slot: "foreground", description: "Markdown list bullets/numbers" },
872
+ toolDiffAdded: { slot: "foreground", description: "Added lines in tool diffs" },
873
+ toolDiffRemoved: { slot: "foreground", description: "Removed lines in tool diffs" },
874
+ toolDiffContext: { slot: "foreground", description: "Context lines in tool diffs" },
875
+ syntaxComment: { slot: "foreground", description: "Syntax highlighting: comments" },
876
+ syntaxKeyword: { slot: "foreground", description: "Syntax highlighting: keywords" },
877
+ syntaxFunction: { slot: "foreground", description: "Syntax highlighting: function names" },
878
+ syntaxVariable: { slot: "foreground", description: "Syntax highlighting: variable names" },
879
+ syntaxString: { slot: "foreground", description: "Syntax highlighting: string literals" },
880
+ syntaxNumber: { slot: "foreground", description: "Syntax highlighting: number literals" },
881
+ syntaxType: { slot: "foreground", description: "Syntax highlighting: type names" },
882
+ syntaxOperator: { slot: "foreground", description: "Syntax highlighting: operators" },
883
+ syntaxPunctuation: { slot: "foreground", description: "Syntax highlighting: punctuation" },
884
+ thinkingOff: { slot: "foreground", description: "Thinking level border: off" },
885
+ thinkingMinimal: { slot: "foreground", description: "Thinking level border: minimal" },
886
+ thinkingLow: { slot: "foreground", description: "Thinking level border: low" },
887
+ thinkingMedium: { slot: "foreground", description: "Thinking level border: medium" },
888
+ thinkingHigh: { slot: "foreground", description: "Thinking level border: high" },
889
+ thinkingXhigh: { slot: "foreground", description: "Thinking level border: xhigh" },
890
+ thinkingMax: {
891
+ slot: "foreground",
892
+ description: "Thinking level border: max (falls back to thinkingXhigh when omitted)",
893
+ fallback: "thinkingXhigh"
894
+ },
895
+ bashMode: { slot: "foreground", description: "Editor border color in bash mode" }
896
+ });
897
+
898
+ // node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js
899
+ var themeJsonValidator;
900
+ function setThemeJsonValidator(validator) {
901
+ themeJsonValidator = validator;
902
+ }
903
+ __name(setThemeJsonValidator, "setThemeJsonValidator");
904
+ function resolveVarRefs(value, vars, visited = /* @__PURE__ */ new Set()) {
905
+ if (typeof value === "number" || value === "" || value.startsWith("#") || /^ok(lch|hsl)\(/i.test(value)) {
906
+ return value;
907
+ }
908
+ if (visited.has(value)) {
909
+ throw new Error(`Circular variable reference detected: ${value}`);
910
+ }
911
+ if (!(value in vars)) {
912
+ throw new Error(`Variable reference not found: ${value}`);
913
+ }
914
+ visited.add(value);
915
+ return resolveVarRefs(vars[value], vars, visited);
916
+ }
917
+ __name(resolveVarRefs, "resolveVarRefs");
918
+ function resolveThemeColors(colors, vars = {}) {
919
+ const resolved = {};
920
+ for (const [key, value] of Object.entries(colors)) {
921
+ resolved[key] = resolveVarRefs(value, vars);
922
+ }
923
+ return resolved;
924
+ }
925
+ __name(resolveThemeColors, "resolveThemeColors");
926
+ function withThemeTokenFallbacks(values) {
927
+ const resolved = { ...values };
928
+ for (const [rawName, descriptor] of Object.entries(THEME_TOKENS)) {
929
+ if (!("fallback" in descriptor))
930
+ continue;
931
+ const name = rawName;
932
+ if (resolved[name] !== void 0)
933
+ continue;
934
+ const fallback = descriptor.fallback;
935
+ const fallbackValue = resolved[fallback];
936
+ if (fallbackValue === void 0) {
937
+ throw new Error(`Theme token ${rawName} has unresolved fallback ${descriptor.fallback}`);
938
+ }
939
+ resolved[name] = fallbackValue;
940
+ }
941
+ return resolved;
942
+ }
943
+ __name(withThemeTokenFallbacks, "withThemeTokenFallbacks");
944
+ var terminalColors = {};
945
+ var terminalColorsPending = false;
946
+ var terminalColorScheme;
947
+ function setTerminalColors(colors) {
948
+ terminalColors = { ...colors };
949
+ terminalColorsPending = false;
950
+ }
951
+ __name(setTerminalColors, "setTerminalColors");
952
+ function setTerminalColorScheme(scheme) {
953
+ terminalColorScheme = scheme;
954
+ }
955
+ __name(setTerminalColorScheme, "setTerminalColorScheme");
956
+ function markTerminalColorsPending() {
957
+ terminalColorsPending = true;
958
+ }
959
+ __name(markTerminalColorsPending, "markTerminalColorsPending");
960
+ var GUESSED_DEFAULT_COLORS = {
961
+ dark: { foreground: parseColor("#e5e5e7"), background: parseColor("#000000") },
962
+ light: { foreground: parseColor("#000000"), background: parseColor("#ffffff") }
963
+ };
964
+ function averageLightness(colors) {
965
+ const fixed = colors.filter((color) => color.kind !== "indexed" || color.index >= 16);
966
+ if (fixed.length === 0)
967
+ return void 0;
968
+ return fixed.reduce((sum, color) => sum + colorToOklch(color).l, 0) / fixed.length;
969
+ }
970
+ __name(averageLightness, "averageLightness");
971
+ function detectAppearance(foregrounds, backgrounds) {
972
+ const fg = averageLightness(foregrounds);
973
+ const bg = averageLightness(backgrounds);
974
+ if (fg !== void 0 && bg !== void 0)
975
+ return bg < fg ? "dark" : "light";
976
+ if (bg !== void 0)
977
+ return bg < 0.5 ? "dark" : "light";
978
+ if (fg !== void 0)
979
+ return fg > 0.5 ? "dark" : "light";
980
+ return void 0;
981
+ }
982
+ __name(detectAppearance, "detectAppearance");
983
+ var Theme = class {
984
+ static {
985
+ __name(this, "Theme");
986
+ }
987
+ name;
988
+ sourcePath;
989
+ sourceInfo;
990
+ mode;
991
+ // Precomputed escape sequences keep fg()/bg() on the render hot path to a lookup and concat.
992
+ fgAnsi = /* @__PURE__ */ new Map();
993
+ bgAnsi = /* @__PURE__ */ new Map();
994
+ // Tokens set to "" have no color of their own; `colors` fills them from the terminal defaults.
995
+ concreteColors = {};
996
+ defaultForegroundTokens = [];
997
+ defaultBackgroundTokens = [];
998
+ // Foreground tokens rendered faint (SGR 2) on top of their color.
999
+ dimTokens;
1000
+ ownAppearance;
1001
+ resolvedColors;
1002
+ constructor(fgColors, bgColors, mode, options = {}) {
1003
+ this.name = options.name;
1004
+ this.sourcePath = options.sourcePath;
1005
+ this.sourceInfo = options.sourceInfo;
1006
+ this.mode = mode;
1007
+ this.dimTokens = new Set(options.dim);
1008
+ const { fgColors: foregrounds, bgColors: backgrounds } = splitThemeColors(withThemeTokenFallbacks({ ...fgColors, ...bgColors }));
1009
+ const concreteForegrounds = [];
1010
+ const concreteBackgrounds = [];
1011
+ const addToken = /* @__PURE__ */ __name((token, value, isBackground) => {
1012
+ if (value === "") {
1013
+ (isBackground ? this.defaultBackgroundTokens : this.defaultForegroundTokens).push(token);
1014
+ return isBackground ? "\x1B[49m" : "\x1B[39m";
1015
+ }
1016
+ const color = parseColor(value);
1017
+ this.concreteColors[token] = color;
1018
+ (isBackground ? concreteBackgrounds : concreteForegrounds).push(color);
1019
+ return isBackground ? backgroundAnsi(color, mode) : foregroundAnsi(color, mode);
1020
+ }, "addToken");
1021
+ for (const [token, value] of Object.entries(foregrounds)) {
1022
+ this.fgAnsi.set(token, addToken(token, value, false));
1023
+ }
1024
+ for (const [token, value] of Object.entries(backgrounds)) {
1025
+ this.bgAnsi.set(token, addToken(token, value, true));
1026
+ }
1027
+ this.ownAppearance = options.appearance ?? detectAppearance(concreteForegrounds, concreteBackgrounds);
1028
+ }
1029
+ /**
1030
+ * The background the theme is designed for: declared in the theme JSON, detected from its colors,
1031
+ * or, for themes without usable colors, the terminal's appearance.
1032
+ */
1033
+ get appearance() {
1034
+ return this.ownAppearance ?? getTerminalTheme();
1035
+ }
1036
+ /**
1037
+ * Concrete colors for all tokens. Tokens set to "" (terminal default) use the terminal's reported
1038
+ * default colors, or a guess based on `appearance` when the terminal did not report them. Faint
1039
+ * tokens are approximated by mixing their color toward the background.
1040
+ */
1041
+ get colors() {
1042
+ const terminal = terminalColors;
1043
+ if (this.resolvedColors?.terminal !== terminal) {
1044
+ const guess = GUESSED_DEFAULT_COLORS[this.appearance];
1045
+ const toColor = /* @__PURE__ */ __name((rgb, fallback) => rgb ? rgbColor(rgb.r, rgb.g, rgb.b) : fallback, "toColor");
1046
+ const foreground = toColor(terminal.foreground, guess.foreground);
1047
+ const background = toColor(terminal.background, guess.background);
1048
+ const colors = { ...this.concreteColors };
1049
+ for (const token of this.defaultForegroundTokens)
1050
+ colors[token] = foreground;
1051
+ for (const token of this.defaultBackgroundTokens)
1052
+ colors[token] = background;
1053
+ for (const token of this.dimTokens) {
1054
+ const color = colors[token];
1055
+ if (color)
1056
+ colors[token] = mixColors(color, background, 0.4);
1057
+ }
1058
+ this.resolvedColors = { terminal, colors: Object.freeze(colors) };
1059
+ }
1060
+ return this.resolvedColors.colors;
1061
+ }
1062
+ style(text, options) {
1063
+ const { fg, bg } = options;
1064
+ if (typeof fg === "string" && this.dimTokens.has(fg))
1065
+ options = { ...options, dim: true };
1066
+ return styleTextWithAnsi(text, fg === void 0 ? void 0 : typeof fg === "string" ? this.tokenAnsi(this.fgAnsi, fg) : foregroundAnsi(fg, this.mode), bg === void 0 ? void 0 : typeof bg === "string" ? this.tokenAnsi(this.bgAnsi, bg) : backgroundAnsi(bg, this.mode), options);
1067
+ }
1068
+ fg(color, text) {
1069
+ const ansi = this.tokenAnsi(this.fgAnsi, color);
1070
+ if (this.dimTokens.has(color))
1071
+ return `${ansi}\x1B[2m${text}\x1B[22;39m`;
1072
+ return `${ansi}${text}\x1B[39m`;
1073
+ }
1074
+ bg(color, text) {
1075
+ const ansi = this.tokenAnsi(this.bgAnsi, color);
1076
+ return `${ansi}${text}\x1B[49m`;
1077
+ }
1078
+ tokenAnsi(ansi, token) {
1079
+ const value = ansi.get(token);
1080
+ if (value === void 0)
1081
+ throw new Error(`Unknown theme color: ${token}`);
1082
+ return value;
1083
+ }
1084
+ bold(text) {
1085
+ return source_default.bold(text);
1086
+ }
1087
+ italic(text) {
1088
+ return source_default.italic(text);
1089
+ }
1090
+ underline(text) {
1091
+ return source_default.underline(text);
1092
+ }
1093
+ inverse(text) {
1094
+ return source_default.inverse(text);
1095
+ }
1096
+ strikethrough(text) {
1097
+ return source_default.strikethrough(text);
1098
+ }
1099
+ /** Opening escape sequence for a foreground token. Faint tokens include SGR 2, which `\x1b[22m` closes. */
1100
+ getFgAnsi(color) {
1101
+ const ansi = this.tokenAnsi(this.fgAnsi, color);
1102
+ return this.dimTokens.has(color) ? `${ansi}\x1B[2m` : ansi;
1103
+ }
1104
+ getBgAnsi(color) {
1105
+ return this.tokenAnsi(this.bgAnsi, color);
1106
+ }
1107
+ getColorMode() {
1108
+ return this.mode;
1109
+ }
1110
+ getThinkingBorderColor(level) {
1111
+ switch (level) {
1112
+ case "off":
1113
+ return (str) => this.fg("thinkingOff", str);
1114
+ case "minimal":
1115
+ return (str) => this.fg("thinkingMinimal", str);
1116
+ case "low":
1117
+ return (str) => this.fg("thinkingLow", str);
1118
+ case "medium":
1119
+ return (str) => this.fg("thinkingMedium", str);
1120
+ case "high":
1121
+ return (str) => this.fg("thinkingHigh", str);
1122
+ case "xhigh":
1123
+ return (str) => this.fg("thinkingXhigh", str);
1124
+ case "max":
1125
+ return (str) => this.fg("thinkingMax", str);
1126
+ default:
1127
+ return (str) => this.fg("thinkingOff", str);
1128
+ }
1129
+ }
1130
+ getBashModeBorderColor() {
1131
+ return (str) => this.fg("bashMode", str);
1132
+ }
1133
+ };
1134
+ var BUILTIN_THEMES;
1135
+ function getBuiltinThemes() {
1136
+ if (!BUILTIN_THEMES) {
1137
+ const themesDir = getThemesDir();
1138
+ const darkPath = path.join(themesDir, "dark.json");
1139
+ const lightPath = path.join(themesDir, "light.json");
1140
+ BUILTIN_THEMES = {
1141
+ dark: JSON.parse(stripBom(fs.readFileSync(darkPath, "utf-8"))),
1142
+ light: JSON.parse(stripBom(fs.readFileSync(lightPath, "utf-8")))
1143
+ };
1144
+ }
1145
+ return BUILTIN_THEMES;
1146
+ }
1147
+ __name(getBuiltinThemes, "getBuiltinThemes");
1148
+ function getAvailableThemes() {
1149
+ return getAvailableThemesWithPaths().map(({ name }) => name);
1150
+ }
1151
+ __name(getAvailableThemes, "getAvailableThemes");
1152
+ function getAvailableThemesWithPaths() {
1153
+ const themesDir = getThemesDir();
1154
+ const result = [];
1155
+ const seen = /* @__PURE__ */ new Set();
1156
+ const addTheme = /* @__PURE__ */ __name((themeInfo) => {
1157
+ if (seen.has(themeInfo.name)) {
1158
+ return;
1159
+ }
1160
+ seen.add(themeInfo.name);
1161
+ result.push(themeInfo);
1162
+ }, "addTheme");
1163
+ addTheme({ name: SYSTEM_THEME_NAME, path: void 0 });
1164
+ for (const name of Object.keys(getBuiltinThemes())) {
1165
+ addTheme({ name, path: path.join(themesDir, `${name}.json`) });
1166
+ }
1167
+ for (const themeInfo of getCustomThemeInfos()) {
1168
+ addTheme(themeInfo);
1169
+ }
1170
+ for (const [name, theme2] of registeredThemes.entries()) {
1171
+ addTheme({ name, path: theme2.sourcePath });
1172
+ }
1173
+ return result.sort((a, b) => a.name === SYSTEM_THEME_NAME ? -1 : b.name === SYSTEM_THEME_NAME ? 1 : a.name.localeCompare(b.name));
1174
+ }
1175
+ __name(getAvailableThemesWithPaths, "getAvailableThemesWithPaths");
1176
+ function getCustomThemeInfos() {
1177
+ const customThemesDir = getCustomThemesDir();
1178
+ const result = [];
1179
+ if (!fs.existsSync(customThemesDir)) {
1180
+ return result;
1181
+ }
1182
+ for (const file of fs.readdirSync(customThemesDir)) {
1183
+ if (!file.endsWith(".json")) {
1184
+ continue;
1185
+ }
1186
+ const themePath = path.join(customThemesDir, file);
1187
+ try {
1188
+ const customTheme = loadThemeFromPath(themePath);
1189
+ if (customTheme.name) {
1190
+ result.push({ name: customTheme.name, path: themePath });
1191
+ }
1192
+ } catch {
1193
+ }
1194
+ }
1195
+ return result;
1196
+ }
1197
+ __name(getCustomThemeInfos, "getCustomThemeInfos");
1198
+ function assertThemeNameIsValid(name) {
1199
+ if (name.includes("/")) {
1200
+ throw new Error(`Invalid theme name "${name}": theme names cannot contain "/" because it is reserved for automatic light/dark theme settings.`);
1201
+ }
1202
+ }
1203
+ __name(assertThemeNameIsValid, "assertThemeNameIsValid");
1204
+ function parseThemeJson(label, json2) {
1205
+ if (themeJsonValidator)
1206
+ return themeJsonValidator(label, json2);
1207
+ if (typeof json2 !== "object" || json2 === null || !("colors" in json2)) {
1208
+ throw new Error(`Invalid theme "${label}": expected an object with a "colors" map.`);
1209
+ }
1210
+ return json2;
1211
+ }
1212
+ __name(parseThemeJson, "parseThemeJson");
1213
+ function parseThemeJsonContent(label, content) {
1214
+ let json2;
1215
+ try {
1216
+ json2 = JSON.parse(stripBom(content));
1217
+ } catch (error) {
1218
+ throw new Error(`Failed to parse theme ${label}: ${error}`);
1219
+ }
1220
+ return parseThemeJson(label, json2);
1221
+ }
1222
+ __name(parseThemeJsonContent, "parseThemeJsonContent");
1223
+ function loadThemeJson(name) {
1224
+ const builtinThemes = getBuiltinThemes();
1225
+ if (name in builtinThemes) {
1226
+ return builtinThemes[name];
1227
+ }
1228
+ const registeredTheme = registeredThemes.get(name);
1229
+ if (registeredTheme?.sourcePath) {
1230
+ const content2 = fs.readFileSync(registeredTheme.sourcePath, "utf-8");
1231
+ return parseThemeJsonContent(registeredTheme.sourcePath, content2);
1232
+ }
1233
+ if (registeredTheme) {
1234
+ throw new Error(`Theme "${name}" does not have a source path for export`);
1235
+ }
1236
+ const customThemesDir = getCustomThemesDir();
1237
+ const themePath = path.join(customThemesDir, `${name}.json`);
1238
+ if (!fs.existsSync(themePath)) {
1239
+ throw new Error(`Theme not found: ${name}`);
1240
+ }
1241
+ const content = fs.readFileSync(themePath, "utf-8");
1242
+ return parseThemeJsonContent(name, content);
1243
+ }
1244
+ __name(loadThemeJson, "loadThemeJson");
1245
+ function splitThemeColors(colors) {
1246
+ const fgColors = {};
1247
+ const bgColors = {};
1248
+ for (const [key, value] of Object.entries(colors)) {
1249
+ if (THEME_TOKENS[key].slot === "background") {
1250
+ bgColors[key] = value;
1251
+ } else {
1252
+ fgColors[key] = value;
1253
+ }
1254
+ }
1255
+ return { fgColors, bgColors };
1256
+ }
1257
+ __name(splitThemeColors, "splitThemeColors");
1258
+ function createTheme(themeJson, mode, sourcePath) {
1259
+ const colorMode = mode ?? getTerminalColorMode();
1260
+ const resolvedColors = withThemeTokenFallbacks(resolveThemeColors(themeJson.colors, themeJson.vars));
1261
+ const { fgColors, bgColors } = splitThemeColors(resolvedColors);
1262
+ return new Theme(fgColors, bgColors, colorMode, {
1263
+ name: themeJson.name,
1264
+ sourcePath,
1265
+ appearance: themeJson.appearance
1266
+ });
1267
+ }
1268
+ __name(createTheme, "createTheme");
1269
+ function createSystemTheme(mode) {
1270
+ const generated = generateSystemThemeColors({
1271
+ ...terminalColors,
1272
+ saturation: terminalColorsPending ? 0 : 1,
1273
+ appearanceHint: getTerminalTheme()
1274
+ });
1275
+ for (const token of ["toolPendingBg", "toolSuccessBg", "toolErrorBg"])
1276
+ generated.colors[token] = "";
1277
+ const { fgColors, bgColors } = splitThemeColors(withThemeTokenFallbacks(generated.colors));
1278
+ return new Theme(fgColors, bgColors, mode ?? getTerminalColorMode(), {
1279
+ name: SYSTEM_THEME_NAME,
1280
+ appearance: generated.appearance,
1281
+ dim: generated.dim
1282
+ });
1283
+ }
1284
+ __name(createSystemTheme, "createSystemTheme");
1285
+ function loadThemeFromPath(themePath, mode) {
1286
+ const content = fs.readFileSync(themePath, "utf-8");
1287
+ const themeJson = parseThemeJsonContent(themePath, content);
1288
+ return createTheme(themeJson, mode, themePath);
1289
+ }
1290
+ __name(loadThemeFromPath, "loadThemeFromPath");
1291
+ function loadTheme(name, mode) {
1292
+ if (name === SYSTEM_THEME_NAME)
1293
+ return createSystemTheme(mode);
1294
+ const registeredTheme = registeredThemes.get(name);
1295
+ if (registeredTheme) {
1296
+ return registeredTheme;
1297
+ }
1298
+ const themeJson = loadThemeJson(name);
1299
+ return createTheme(themeJson, mode);
1300
+ }
1301
+ __name(loadTheme, "loadTheme");
1302
+ function getThemeByName(name) {
1303
+ try {
1304
+ return loadTheme(name);
1305
+ } catch {
1306
+ return void 0;
1307
+ }
1308
+ }
1309
+ __name(getThemeByName, "getThemeByName");
1310
+ function parseAutoThemeSetting(themeSetting) {
1311
+ if (!themeSetting)
1312
+ return void 0;
1313
+ const slashIndex = themeSetting.indexOf("/");
1314
+ if (slashIndex === -1 || themeSetting.indexOf("/", slashIndex + 1) !== -1) {
1315
+ return void 0;
1316
+ }
1317
+ const lightTheme = themeSetting.slice(0, slashIndex).trim();
1318
+ const darkTheme = themeSetting.slice(slashIndex + 1).trim();
1319
+ if (!lightTheme || !darkTheme) {
1320
+ return void 0;
1321
+ }
1322
+ return { lightTheme, darkTheme };
1323
+ }
1324
+ __name(parseAutoThemeSetting, "parseAutoThemeSetting");
1325
+ function resolveThemeSetting(themeSetting, terminalTheme) {
1326
+ const autoTheme = parseAutoThemeSetting(themeSetting);
1327
+ if (autoTheme) {
1328
+ return terminalTheme === "light" ? autoTheme.lightTheme : autoTheme.darkTheme;
1329
+ }
1330
+ if (themeSetting?.includes("/"))
1331
+ return void 0;
1332
+ if (typeof themeSetting === "string")
1333
+ return themeSetting;
1334
+ return void 0;
1335
+ }
1336
+ __name(resolveThemeSetting, "resolveThemeSetting");
1337
+ function detectColorFgBgTheme(env = process.env) {
1338
+ const bg = env.COLORFGBG?.split(";").at(-1)?.trim();
1339
+ if (!bg || !/^\d{1,2}$/.test(bg))
1340
+ return void 0;
1341
+ const index = Number(bg);
1342
+ if (index > 15)
1343
+ return void 0;
1344
+ return index <= 6 || index === 8 ? "dark" : "light";
1345
+ }
1346
+ __name(detectColorFgBgTheme, "detectColorFgBgTheme");
1347
+ function detectTerminalTheme(colors = {}, reportedScheme, env = process.env) {
1348
+ const { background, foreground } = colors;
1349
+ if (background)
1350
+ return terminalAppearance(background, foreground);
1351
+ return reportedScheme ?? detectColorFgBgTheme(env) ?? "dark";
1352
+ }
1353
+ __name(detectTerminalTheme, "detectTerminalTheme");
1354
+ function getTerminalTheme() {
1355
+ return detectTerminalTheme(terminalColors, terminalColorScheme);
1356
+ }
1357
+ __name(getTerminalTheme, "getTerminalTheme");
1358
+ var THEME_KEY = /* @__PURE__ */ Symbol.for("@earendil-works/pi-coding-agent:theme");
1359
+ var THEME_KEY_OLD = /* @__PURE__ */ Symbol.for("@mariozechner/pi-coding-agent:theme");
1360
+ var theme = new Proxy({}, {
1361
+ get(_target, prop) {
1362
+ const t = globalThis[THEME_KEY];
1363
+ if (!t)
1364
+ throw new Error("Theme not initialized. Call initTheme() first.");
1365
+ return t[prop];
1366
+ }
1367
+ });
1368
+ function setGlobalTheme(t) {
1369
+ globalThis[THEME_KEY] = t;
1370
+ globalThis[THEME_KEY_OLD] = t;
1371
+ }
1372
+ __name(setGlobalTheme, "setGlobalTheme");
1373
+ var currentThemeName;
1374
+ var themeWatcher;
1375
+ var themeReloadTimer;
1376
+ var onThemeChangeCallback;
1377
+ var registeredThemes = /* @__PURE__ */ new Map();
1378
+ function setRegisteredThemes(themes) {
1379
+ registeredThemes.clear();
1380
+ for (const theme2 of themes) {
1381
+ if (theme2.name) {
1382
+ assertThemeNameIsValid(theme2.name);
1383
+ registeredThemes.set(theme2.name, theme2);
1384
+ }
1385
+ }
1386
+ }
1387
+ __name(setRegisteredThemes, "setRegisteredThemes");
1388
+ function initTheme(themeName, enableWatcher = false) {
1389
+ const name = themeName ?? SYSTEM_THEME_NAME;
1390
+ currentThemeName = name;
1391
+ try {
1392
+ setGlobalTheme(loadTheme(name));
1393
+ if (enableWatcher) {
1394
+ startThemeWatcher();
1395
+ }
1396
+ } catch (_error) {
1397
+ currentThemeName = SYSTEM_THEME_NAME;
1398
+ setGlobalTheme(loadTheme(SYSTEM_THEME_NAME));
1399
+ }
1400
+ }
1401
+ __name(initTheme, "initTheme");
1402
+ function setTheme(name, enableWatcher = false) {
1403
+ currentThemeName = name;
1404
+ try {
1405
+ setGlobalTheme(loadTheme(name));
1406
+ if (enableWatcher) {
1407
+ startThemeWatcher();
1408
+ }
1409
+ if (onThemeChangeCallback) {
1410
+ onThemeChangeCallback();
1411
+ }
1412
+ return { success: true };
1413
+ } catch (error) {
1414
+ currentThemeName = SYSTEM_THEME_NAME;
1415
+ setGlobalTheme(loadTheme(SYSTEM_THEME_NAME));
1416
+ return {
1417
+ success: false,
1418
+ error: error instanceof Error ? error.message : String(error)
1419
+ };
1420
+ }
1421
+ }
1422
+ __name(setTheme, "setTheme");
1423
+ function setThemeInstance(themeInstance) {
1424
+ setGlobalTheme(themeInstance);
1425
+ currentThemeName = "<in-memory>";
1426
+ stopThemeWatcher();
1427
+ if (onThemeChangeCallback) {
1428
+ onThemeChangeCallback();
1429
+ }
1430
+ }
1431
+ __name(setThemeInstance, "setThemeInstance");
1432
+ function onThemeChange(callback) {
1433
+ onThemeChangeCallback = callback;
1434
+ }
1435
+ __name(onThemeChange, "onThemeChange");
1436
+ function startThemeWatcher() {
1437
+ stopThemeWatcher();
1438
+ if (!currentThemeName || currentThemeName === "dark" || currentThemeName === "light" || currentThemeName === SYSTEM_THEME_NAME) {
1439
+ return;
1440
+ }
1441
+ const customThemesDir = getCustomThemesDir();
1442
+ const watchedThemeName = currentThemeName;
1443
+ const watchedFileName = `${watchedThemeName}.json`;
1444
+ const themeFile = path.join(customThemesDir, watchedFileName);
1445
+ if (!fs.existsSync(themeFile)) {
1446
+ return;
1447
+ }
1448
+ const scheduleReload = /* @__PURE__ */ __name(() => {
1449
+ if (themeReloadTimer) {
1450
+ clearTimeout(themeReloadTimer);
1451
+ }
1452
+ themeReloadTimer = setTimeout(() => {
1453
+ themeReloadTimer = void 0;
1454
+ if (currentThemeName !== watchedThemeName) {
1455
+ return;
1456
+ }
1457
+ if (!fs.existsSync(themeFile)) {
1458
+ return;
1459
+ }
1460
+ try {
1461
+ const reloadedTheme = loadThemeFromPath(themeFile);
1462
+ registeredThemes.set(watchedThemeName, reloadedTheme);
1463
+ setGlobalTheme(reloadedTheme);
1464
+ if (onThemeChangeCallback) {
1465
+ onThemeChangeCallback();
1466
+ }
1467
+ } catch (_error) {
1468
+ }
1469
+ }, 100);
1470
+ }, "scheduleReload");
1471
+ themeWatcher = watchWithErrorHandler(customThemesDir, (_eventType, filename) => {
1472
+ if (currentThemeName !== watchedThemeName) {
1473
+ return;
1474
+ }
1475
+ if (!filename) {
1476
+ scheduleReload();
1477
+ return;
1478
+ }
1479
+ if (filename !== watchedFileName) {
1480
+ return;
1481
+ }
1482
+ scheduleReload();
1483
+ }, () => {
1484
+ closeWatcher(themeWatcher);
1485
+ themeWatcher = void 0;
1486
+ }) ?? void 0;
1487
+ }
1488
+ __name(startThemeWatcher, "startThemeWatcher");
1489
+ function stopThemeWatcher() {
1490
+ if (themeReloadTimer) {
1491
+ clearTimeout(themeReloadTimer);
1492
+ themeReloadTimer = void 0;
1493
+ }
1494
+ closeWatcher(themeWatcher);
1495
+ themeWatcher = void 0;
1496
+ }
1497
+ __name(stopThemeWatcher, "stopThemeWatcher");
1498
+ function getResolvedThemeColors(themeName) {
1499
+ const colors = loadTheme(themeName ?? currentThemeName ?? SYSTEM_THEME_NAME).colors;
1500
+ return Object.fromEntries(Object.entries(colors).map(([token, color]) => [token, colorToHex(color)]));
1501
+ }
1502
+ __name(getResolvedThemeColors, "getResolvedThemeColors");
1503
+ function getThemeExportColors(themeName) {
1504
+ const name = themeName ?? currentThemeName ?? SYSTEM_THEME_NAME;
1505
+ if (name === SYSTEM_THEME_NAME)
1506
+ return {};
1507
+ try {
1508
+ const themeJson = loadThemeJson(name);
1509
+ const exportSection = themeJson.export;
1510
+ if (!exportSection)
1511
+ return {};
1512
+ const vars = themeJson.vars ?? {};
1513
+ const resolve = /* @__PURE__ */ __name((value) => {
1514
+ if (value === void 0)
1515
+ return void 0;
1516
+ const resolved = resolveVarRefs(value, vars);
1517
+ if (typeof resolved === "number")
1518
+ return colorToHex(indexedColor(resolved));
1519
+ if (resolved === "")
1520
+ return void 0;
1521
+ if (/^okhsl\(/i.test(resolved))
1522
+ return colorToHex(parseColor(resolved));
1523
+ return resolved;
1524
+ }, "resolve");
1525
+ return {
1526
+ pageBg: resolve(exportSection.pageBg),
1527
+ cardBg: resolve(exportSection.cardBg),
1528
+ infoBg: resolve(exportSection.infoBg)
1529
+ };
1530
+ } catch {
1531
+ return {};
1532
+ }
1533
+ }
1534
+ __name(getThemeExportColors, "getThemeExportColors");
1535
+ var cachedHighlightThemeFor;
1536
+ var cachedCliHighlightTheme;
1537
+ function buildCliHighlightTheme(t) {
1538
+ return {
1539
+ keyword: /* @__PURE__ */ __name((s) => t.fg("syntaxKeyword", s), "keyword"),
1540
+ built_in: /* @__PURE__ */ __name((s) => t.fg("syntaxType", s), "built_in"),
1541
+ literal: /* @__PURE__ */ __name((s) => t.fg("syntaxNumber", s), "literal"),
1542
+ number: /* @__PURE__ */ __name((s) => t.fg("syntaxNumber", s), "number"),
1543
+ regexp: /* @__PURE__ */ __name((s) => t.fg("syntaxString", s), "regexp"),
1544
+ string: /* @__PURE__ */ __name((s) => t.fg("syntaxString", s), "string"),
1545
+ subst: /* @__PURE__ */ __name((s) => t.fg("text", s), "subst"),
1546
+ comment: /* @__PURE__ */ __name((s) => t.fg("syntaxComment", s), "comment"),
1547
+ doctag: /* @__PURE__ */ __name((s) => t.fg("syntaxComment", s), "doctag"),
1548
+ meta: /* @__PURE__ */ __name((s) => t.fg("muted", s), "meta"),
1549
+ function: /* @__PURE__ */ __name((s) => t.fg("syntaxFunction", s), "function"),
1550
+ title: /* @__PURE__ */ __name((s) => t.fg("syntaxFunction", s), "title"),
1551
+ class: /* @__PURE__ */ __name((s) => t.fg("syntaxType", s), "class"),
1552
+ type: /* @__PURE__ */ __name((s) => t.fg("syntaxType", s), "type"),
1553
+ tag: /* @__PURE__ */ __name((s) => t.fg("syntaxPunctuation", s), "tag"),
1554
+ name: /* @__PURE__ */ __name((s) => t.fg("syntaxKeyword", s), "name"),
1555
+ attr: /* @__PURE__ */ __name((s) => t.fg("syntaxVariable", s), "attr"),
1556
+ variable: /* @__PURE__ */ __name((s) => t.fg("syntaxVariable", s), "variable"),
1557
+ params: /* @__PURE__ */ __name((s) => t.fg("syntaxVariable", s), "params"),
1558
+ operator: /* @__PURE__ */ __name((s) => t.fg("syntaxOperator", s), "operator"),
1559
+ punctuation: /* @__PURE__ */ __name((s) => t.fg("syntaxPunctuation", s), "punctuation"),
1560
+ emphasis: /* @__PURE__ */ __name((s) => t.italic(s), "emphasis"),
1561
+ strong: /* @__PURE__ */ __name((s) => t.bold(s), "strong"),
1562
+ link: /* @__PURE__ */ __name((s) => t.underline(s), "link"),
1563
+ addition: /* @__PURE__ */ __name((s) => t.fg("toolDiffAdded", s), "addition"),
1564
+ deletion: /* @__PURE__ */ __name((s) => t.fg("toolDiffRemoved", s), "deletion")
1565
+ };
1566
+ }
1567
+ __name(buildCliHighlightTheme, "buildCliHighlightTheme");
1568
+ function getCliHighlightTheme(t) {
1569
+ if (cachedHighlightThemeFor !== t || !cachedCliHighlightTheme) {
1570
+ cachedHighlightThemeFor = t;
1571
+ cachedCliHighlightTheme = buildCliHighlightTheme(t);
1572
+ }
1573
+ return cachedCliHighlightTheme;
1574
+ }
1575
+ __name(getCliHighlightTheme, "getCliHighlightTheme");
1576
+ function highlightCode(code, lang) {
1577
+ const validLang = lang && supportsLanguage(lang) ? lang : void 0;
1578
+ if (!validLang) {
1579
+ return code.split("\n").map((line) => theme.fg("mdCodeBlock", line));
1580
+ }
1581
+ const opts = {
1582
+ language: validLang,
1583
+ ignoreIllegals: true,
1584
+ theme: getCliHighlightTheme(theme)
1585
+ };
1586
+ try {
1587
+ return highlight(code, opts).split("\n");
1588
+ } catch {
1589
+ return code.split("\n");
1590
+ }
1591
+ }
1592
+ __name(highlightCode, "highlightCode");
1593
+ function getLanguageFromPath(filePath) {
1594
+ const ext = filePath.split(".").pop()?.toLowerCase();
1595
+ if (!ext)
1596
+ return void 0;
1597
+ const extToLang = {
1598
+ ts: "typescript",
1599
+ tsx: "typescript",
1600
+ js: "javascript",
1601
+ jsx: "javascript",
1602
+ mjs: "javascript",
1603
+ cjs: "javascript",
1604
+ py: "python",
1605
+ rb: "ruby",
1606
+ rs: "rust",
1607
+ go: "go",
1608
+ java: "java",
1609
+ kt: "kotlin",
1610
+ swift: "swift",
1611
+ c: "c",
1612
+ h: "c",
1613
+ cpp: "cpp",
1614
+ cc: "cpp",
1615
+ cxx: "cpp",
1616
+ hpp: "cpp",
1617
+ cs: "csharp",
1618
+ php: "php",
1619
+ sh: "bash",
1620
+ bash: "bash",
1621
+ zsh: "bash",
1622
+ fish: "fish",
1623
+ ps1: "powershell",
1624
+ sql: "sql",
1625
+ html: "html",
1626
+ htm: "html",
1627
+ css: "css",
1628
+ scss: "scss",
1629
+ sass: "sass",
1630
+ less: "less",
1631
+ json: "json",
1632
+ yaml: "yaml",
1633
+ yml: "yaml",
1634
+ toml: "toml",
1635
+ xml: "xml",
1636
+ md: "markdown",
1637
+ markdown: "markdown",
1638
+ dockerfile: "dockerfile",
1639
+ makefile: "makefile",
1640
+ cmake: "cmake",
1641
+ lua: "lua",
1642
+ perl: "perl",
1643
+ r: "r",
1644
+ scala: "scala",
1645
+ clj: "clojure",
1646
+ ex: "elixir",
1647
+ exs: "elixir",
1648
+ erl: "erlang",
1649
+ hs: "haskell",
1650
+ ml: "ocaml",
1651
+ vim: "vim",
1652
+ graphql: "graphql",
1653
+ proto: "protobuf",
1654
+ tf: "hcl",
1655
+ hcl: "hcl"
1656
+ };
1657
+ return extToLang[ext];
1658
+ }
1659
+ __name(getLanguageFromPath, "getLanguageFromPath");
1660
+ function getMarkdownTheme() {
1661
+ return {
1662
+ heading: /* @__PURE__ */ __name((text) => theme.fg("mdHeading", text), "heading"),
1663
+ link: /* @__PURE__ */ __name((text) => theme.fg("mdLink", text), "link"),
1664
+ linkUrl: /* @__PURE__ */ __name((text) => theme.fg("mdLinkUrl", text), "linkUrl"),
1665
+ code: /* @__PURE__ */ __name((text) => theme.fg("mdCode", text), "code"),
1666
+ codeBlock: /* @__PURE__ */ __name((text) => theme.fg("mdCodeBlock", text), "codeBlock"),
1667
+ codeBlockBorder: /* @__PURE__ */ __name((text) => theme.fg("mdCodeBlockBorder", text), "codeBlockBorder"),
1668
+ quote: /* @__PURE__ */ __name((text) => theme.fg("mdQuote", text), "quote"),
1669
+ quoteBorder: /* @__PURE__ */ __name((text) => theme.fg("mdQuoteBorder", text), "quoteBorder"),
1670
+ hr: /* @__PURE__ */ __name((text) => theme.fg("mdHr", text), "hr"),
1671
+ listBullet: /* @__PURE__ */ __name((text) => theme.fg("mdListBullet", text), "listBullet"),
1672
+ bold: /* @__PURE__ */ __name((text) => theme.bold(text), "bold"),
1673
+ italic: /* @__PURE__ */ __name((text) => theme.italic(text), "italic"),
1674
+ underline: /* @__PURE__ */ __name((text) => theme.underline(text), "underline"),
1675
+ strikethrough: /* @__PURE__ */ __name((text) => theme.strikethrough(text), "strikethrough"),
1676
+ highlightCode: /* @__PURE__ */ __name((code, lang) => {
1677
+ const validLang = lang && supportsLanguage(lang) ? lang : void 0;
1678
+ if (!validLang) {
1679
+ return code.split("\n").map((line) => theme.fg("mdCodeBlock", line));
1680
+ }
1681
+ const opts = {
1682
+ language: validLang,
1683
+ ignoreIllegals: true,
1684
+ theme: getCliHighlightTheme(theme)
1685
+ };
1686
+ try {
1687
+ return highlight(code, opts).split("\n");
1688
+ } catch {
1689
+ return code.split("\n").map((line) => theme.fg("mdCodeBlock", line));
1690
+ }
1691
+ }, "highlightCode")
1692
+ };
1693
+ }
1694
+ __name(getMarkdownTheme, "getMarkdownTheme");
1695
+ function getSelectListTheme() {
1696
+ return {
1697
+ selectedPrefix: /* @__PURE__ */ __name((text) => theme.fg("accent", text), "selectedPrefix"),
1698
+ selectedText: /* @__PURE__ */ __name((text) => theme.fg("accent", text), "selectedText"),
1699
+ description: /* @__PURE__ */ __name((text) => theme.fg("muted", text), "description"),
1700
+ scrollInfo: /* @__PURE__ */ __name((text) => theme.fg("muted", text), "scrollInfo"),
1701
+ noMatch: /* @__PURE__ */ __name((text) => theme.fg("muted", text), "noMatch")
1702
+ };
1703
+ }
1704
+ __name(getSelectListTheme, "getSelectListTheme");
1705
+ function getEditorTheme() {
1706
+ return {
1707
+ borderColor: /* @__PURE__ */ __name((text) => theme.fg("borderMuted", text), "borderColor"),
1708
+ selectList: getSelectListTheme()
1709
+ };
1710
+ }
1711
+ __name(getEditorTheme, "getEditorTheme");
1712
+ function getSettingsListTheme() {
1713
+ return {
1714
+ label: /* @__PURE__ */ __name((text, selected) => selected ? theme.fg("accent", text) : text, "label"),
1715
+ value: /* @__PURE__ */ __name((text, selected) => selected ? theme.fg("accent", text) : theme.fg("muted", text), "value"),
1716
+ description: /* @__PURE__ */ __name((text) => theme.fg("dim", text), "description"),
1717
+ cursor: theme.fg("accent", "\u2192 "),
1718
+ hint: /* @__PURE__ */ __name((text) => theme.fg("dim", text), "hint")
1719
+ };
1720
+ }
1721
+ __name(getSettingsListTheme, "getSettingsListTheme");
1722
+
1723
+ // node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/keybinding-hints.js
1724
+ function formatKeyPart(part, options) {
1725
+ const displayPart = process.platform === "darwin" && part.toLowerCase() === "alt" ? "option" : part;
1726
+ return options.capitalize ? displayPart.charAt(0).toUpperCase() + displayPart.slice(1) : displayPart;
1727
+ }
1728
+ __name(formatKeyPart, "formatKeyPart");
1729
+ function formatKeyText(key, options = {}) {
1730
+ return key.split("/").map((k) => k.split("+").map((part) => formatKeyPart(part, options)).join("+")).join("/");
1731
+ }
1732
+ __name(formatKeyText, "formatKeyText");
1733
+ function formatKeys(keys, options = {}) {
1734
+ if (keys.length === 0)
1735
+ return "";
1736
+ return formatKeyText(keys.join("/"), options);
1737
+ }
1738
+ __name(formatKeys, "formatKeys");
1739
+ function keyText(keybinding) {
1740
+ return formatKeys(getKeybindings().getKeys(keybinding));
1741
+ }
1742
+ __name(keyText, "keyText");
1743
+ function keyDisplayText(keybinding) {
1744
+ return formatKeys(getKeybindings().getKeys(keybinding), { capitalize: true });
1745
+ }
1746
+ __name(keyDisplayText, "keyDisplayText");
1747
+ function keyHint(keybinding, description) {
1748
+ return theme.fg("dim", keyText(keybinding)) + theme.fg("muted", ` ${description}`);
1749
+ }
1750
+ __name(keyHint, "keyHint");
1751
+ function rawKeyHint(key, description) {
1752
+ return theme.fg("dim", formatKeyText(key)) + theme.fg("muted", ` ${description}`);
1753
+ }
1754
+ __name(rawKeyHint, "rawKeyHint");
1755
+
1756
+ export {
1757
+ FS_WATCH_RETRY_DELAY_MS,
1758
+ closeWatcher,
1759
+ watchWithErrorHandler,
1760
+ loadAllHighlightLanguages,
1761
+ SYSTEM_THEME_NAME,
1762
+ THEME_TOKENS,
1763
+ setThemeJsonValidator,
1764
+ setTerminalColors,
1765
+ setTerminalColorScheme,
1766
+ markTerminalColorsPending,
1767
+ Theme,
1768
+ getAvailableThemes,
1769
+ getAvailableThemesWithPaths,
1770
+ loadThemeFromPath,
1771
+ getThemeByName,
1772
+ parseAutoThemeSetting,
1773
+ resolveThemeSetting,
1774
+ getTerminalTheme,
1775
+ theme,
1776
+ setRegisteredThemes,
1777
+ initTheme,
1778
+ setTheme,
1779
+ setThemeInstance,
1780
+ onThemeChange,
1781
+ stopThemeWatcher,
1782
+ getResolvedThemeColors,
1783
+ getThemeExportColors,
1784
+ highlightCode,
1785
+ getLanguageFromPath,
1786
+ getMarkdownTheme,
1787
+ getSelectListTheme,
1788
+ getEditorTheme,
1789
+ getSettingsListTheme,
1790
+ formatKeyText,
1791
+ keyText,
1792
+ keyDisplayText,
1793
+ keyHint,
1794
+ rawKeyHint
1795
+ };