@narumitw/pi-starship 0.60.0 → 0.62.0

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 (115) hide show
  1. package/README.md +63 -6
  2. package/dist/chunks/chunk-43VIENBN.ts +1586 -0
  3. package/dist/chunks/chunk-43VIENBN.ts.map +7 -0
  4. package/dist/chunks/chunk-HPZTMIZS.ts +646 -0
  5. package/dist/chunks/chunk-HPZTMIZS.ts.map +7 -0
  6. package/dist/chunks/chunk-IYDZ3R2T.ts +69 -0
  7. package/dist/chunks/chunk-IYDZ3R2T.ts.map +7 -0
  8. package/dist/chunks/chunk-KP33I6BR.ts +579 -0
  9. package/dist/chunks/chunk-KP33I6BR.ts.map +7 -0
  10. package/dist/chunks/{chunk-KZZKGGFW.ts → chunk-PWTSHSP3.ts} +853 -1001
  11. package/dist/chunks/chunk-PWTSHSP3.ts.map +7 -0
  12. package/dist/chunks/{chunk-PD457PX5.ts → chunk-S2KBLHE2.ts} +75 -10
  13. package/dist/chunks/chunk-S2KBLHE2.ts.map +7 -0
  14. package/dist/chunks/chunk-XQUIQO2G.ts +20 -0
  15. package/dist/chunks/chunk-XQUIQO2G.ts.map +7 -0
  16. package/dist/chunks/{chunk-ADX4CY27.ts → chunk-XTLQ4WUL.ts} +1 -1
  17. package/dist/chunks/chunk-XTLQ4WUL.ts.map +7 -0
  18. package/dist/chunks/{cloud-EPAEV4ZB.ts → cloud-J2ZOE3HE.ts} +6 -2
  19. package/dist/chunks/cloud-J2ZOE3HE.ts.map +7 -0
  20. package/dist/chunks/command-configuration-menu-S2LXCOJG.ts +147 -0
  21. package/dist/chunks/command-configuration-menu-S2LXCOJG.ts.map +7 -0
  22. package/dist/chunks/command-settings-chat-O34BEU4X.ts +1041 -0
  23. package/dist/chunks/command-settings-chat-O34BEU4X.ts.map +7 -0
  24. package/dist/chunks/commands-ZYIJVIEJ.ts +1022 -0
  25. package/dist/chunks/commands-ZYIJVIEJ.ts.map +7 -0
  26. package/dist/chunks/{deployment-7J54EHNR.ts → deployment-NOJ2KCLI.ts} +85 -5
  27. package/dist/chunks/deployment-NOJ2KCLI.ts.map +7 -0
  28. package/dist/chunks/{development-IWJAAAEV.ts → development-T3XXVVDP.ts} +67 -15
  29. package/dist/chunks/development-T3XXVVDP.ts.map +7 -0
  30. package/dist/chunks/directory-OX6BWJZA.ts +31 -0
  31. package/dist/chunks/directory-OX6BWJZA.ts.map +7 -0
  32. package/dist/chunks/{execution-P4WZALW2.ts → execution-R2OHIP2L.ts} +8 -4
  33. package/dist/chunks/execution-R2OHIP2L.ts.map +7 -0
  34. package/dist/chunks/jujutsu-XLDYKSX2.ts +174 -0
  35. package/dist/chunks/jujutsu-XLDYKSX2.ts.map +7 -0
  36. package/dist/chunks/languages-CBQNNYXM.ts +262 -0
  37. package/dist/chunks/languages-CBQNNYXM.ts.map +7 -0
  38. package/dist/chunks/{package-H24VJEX3.ts → package-7KVAK3TC.ts} +6 -2
  39. package/dist/chunks/package-7KVAK3TC.ts.map +7 -0
  40. package/dist/chunks/system-574MHB4R.ts +165 -0
  41. package/dist/chunks/system-574MHB4R.ts.map +7 -0
  42. package/dist/index.ts +558 -150
  43. package/dist/index.ts.map +4 -4
  44. package/package.json +5 -1
  45. package/skills/configure-pi-starship/SKILL.md +29 -1
  46. package/skills/configure-pi-starship/references/configuration.md +109 -24
  47. package/skills/configure-pi-starship/references/module-catalog.md +278 -25
  48. package/skills/configure-pi-starship/references/modules.md +213 -36
  49. package/skills/configure-pi-starship/references/runtime-and-security.md +88 -28
  50. package/skills/configure-pi-starship/scripts/config-path.mjs +63 -3
  51. package/src/command-configuration-menu.ts +155 -0
  52. package/src/command-configuration.ts +9 -84
  53. package/src/command-preview.ts +3 -3
  54. package/src/command-settings-chat.ts +210 -0
  55. package/src/commands.ts +54 -98
  56. package/src/config/module-options.ts +112 -0
  57. package/src/config.ts +17 -53
  58. package/src/effective-config.ts +5 -4
  59. package/src/format/bounded-regex.ts +66 -0
  60. package/src/format/version.ts +24 -0
  61. package/src/modules/catalog.ts +10 -0
  62. package/src/modules/cloud.ts +1 -0
  63. package/src/modules/deployment.ts +8 -0
  64. package/src/modules/development.ts +20 -2
  65. package/src/modules/directory.ts +171 -51
  66. package/src/modules/execution.ts +2 -0
  67. package/src/modules/git/branch.ts +19 -4
  68. package/src/modules/git/commit.ts +9 -2
  69. package/src/modules/git/metrics.ts +9 -4
  70. package/src/modules/git/runtime.ts +122 -33
  71. package/src/modules/git/state.ts +23 -2
  72. package/src/modules/git/status-templates.ts +58 -0
  73. package/src/modules/git/status.ts +96 -30
  74. package/src/modules/jujutsu.ts +225 -0
  75. package/src/modules/languages.ts +26 -2
  76. package/src/modules/package.ts +1 -0
  77. package/src/modules/render.ts +42 -16
  78. package/src/modules/system.ts +54 -0
  79. package/src/modules/time-format.ts +188 -0
  80. package/src/modules/time.ts +11 -5
  81. package/src/modules/types.ts +42 -4
  82. package/src/pi-starship.ts +56 -12
  83. package/src/profile-store.ts +5 -0
  84. package/src/runtime/cloud.ts +3 -0
  85. package/src/runtime/command.ts +1 -1
  86. package/src/runtime/deployment.ts +120 -4
  87. package/src/runtime/development.ts +86 -13
  88. package/src/runtime/directory.ts +33 -0
  89. package/src/runtime/execution.ts +12 -2
  90. package/src/runtime/helpers.ts +57 -8
  91. package/src/runtime/jujutsu.ts +225 -0
  92. package/src/runtime/languages.ts +106 -19
  93. package/src/runtime/package.ts +3 -0
  94. package/src/runtime/system.ts +202 -0
  95. package/src/runtime/types.ts +3 -0
  96. package/src/runtime/version-requirements.ts +30 -0
  97. package/src/runtime/workspace.ts +12 -1
  98. package/src/settings-agent.ts +80 -0
  99. package/src/settings-chat-transcript.ts +140 -0
  100. package/src/settings-chat-ui.ts +426 -0
  101. package/src/settings-draft.ts +260 -0
  102. package/src/settings-snapshots.ts +41 -0
  103. package/dist/chunks/chunk-ADX4CY27.ts.map +0 -7
  104. package/dist/chunks/chunk-KZZKGGFW.ts.map +0 -7
  105. package/dist/chunks/chunk-PD457PX5.ts.map +0 -7
  106. package/dist/chunks/cloud-EPAEV4ZB.ts.map +0 -7
  107. package/dist/chunks/commands-C2VJ6ZBN.ts +0 -3374
  108. package/dist/chunks/commands-C2VJ6ZBN.ts.map +0 -7
  109. package/dist/chunks/deployment-7J54EHNR.ts.map +0 -7
  110. package/dist/chunks/development-IWJAAAEV.ts.map +0 -7
  111. package/dist/chunks/execution-P4WZALW2.ts.map +0 -7
  112. package/dist/chunks/languages-JO6R2PHL.ts +0 -168
  113. package/dist/chunks/languages-JO6R2PHL.ts.map +0 -7
  114. package/dist/chunks/package-H24VJEX3.ts.map +0 -7
  115. package/src/command-inspector.ts +0 -41
@@ -1,17 +1,19 @@
1
1
  // @generated by scripts/build-runtime.mjs; do not edit.
2
2
  // @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
3
-
4
- // src/command-contract.ts
5
- var STARSHIP_SUBCOMMANDS = [
6
- { value: "settings", label: "settings", description: "Customize the footer TOML" },
7
- { value: "status", label: "status", description: "Show configuration health and source" },
8
- { value: "help", label: "help", description: "Show configuration help" }
9
- ];
10
- function completeStarshipArguments(prefix) {
11
- const normalized = prefix.trim().toLowerCase();
12
- const matches = STARSHIP_SUBCOMMANDS.filter((item) => item.value.startsWith(normalized));
13
- return matches.length > 0 ? [...matches] : null;
14
- }
3
+ import {
4
+ replacePattern,
5
+ validPattern
6
+ } from "./chunk-IYDZ3R2T.ts";
7
+ import {
8
+ formatVariables,
9
+ isFillChunk,
10
+ isValidStyle,
11
+ parseColor,
12
+ parseFormat,
13
+ parseStyle,
14
+ renderFormat,
15
+ styleVariables
16
+ } from "./chunk-KP33I6BR.ts";
15
17
 
16
18
  // src/config.ts
17
19
  import { randomUUID } from "node:crypto";
@@ -30,572 +32,121 @@ import {
30
32
  import { dirname, join } from "node:path";
31
33
  import { parse as parseToml } from "smol-toml";
32
34
 
33
- // src/format/style.ts
34
- import { backgroundAnsi, foregroundAnsi } from "@earendil-works/pi-tui";
35
-
36
- // src/format/terminal-safety.ts
37
- import { sanitizeTerminalDocument } from "@narumitw/pi-tui-kit/terminal-document";
38
- var PREFIX = "\x1B]8;;";
39
- var BEL = "\x07";
40
- var ST = "\x1B\\";
41
- function sanitizeFormatText(value) {
42
- let output = "";
43
- let offset = 0;
44
- let cursor = 0;
45
- while (cursor < value.length) {
46
- const start = value.indexOf(PREFIX, cursor);
47
- if (start < 0) break;
48
- const opening = findTerminator(value, start + PREFIX.length);
49
- if (!opening) break;
50
- const closing = findLinkEnd(value, opening.end);
51
- if (!closing) break;
52
- cursor = closing.end;
53
- const url = safeHyperlinkUrl(value.slice(start + PREFIX.length, opening.start));
54
- if (!url) continue;
55
- output += sanitizePlainText(value.slice(offset, start));
56
- const label = sanitizePlainText(value.slice(opening.end, closing.start));
57
- if (label) {
58
- const openTerminator = value.slice(opening.start, opening.end);
59
- const closeTerminator = value.slice(closing.start + PREFIX.length, closing.end);
60
- output += `${PREFIX}${url}${openTerminator}${label}${PREFIX}${closeTerminator}`;
35
+ // src/modules/git/status-templates.ts
36
+ import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
37
+ var MAX_TEMPLATE_LENGTH = 4096;
38
+ var MAX_TEMPLATE_DEPTH = 16;
39
+ function renderStatusTemplate(template, variables, palette) {
40
+ const nodes = parseStatusTemplate(template, Object.keys(variables));
41
+ return nodes ? renderFormat(nodes, { variables, palette }).filter(
42
+ (chunk) => !isFillChunk(chunk) && chunk.text.length > 0
43
+ ) : [];
44
+ }
45
+ function validStatusTemplate(template, variables) {
46
+ return parseStatusTemplate(template, variables) !== void 0;
47
+ }
48
+ function parseStatusTemplate(template, variables) {
49
+ if (template.length > MAX_TEMPLATE_LENGTH) return void 0;
50
+ const safe = sanitizeTerminalText(template);
51
+ let depth = 0;
52
+ for (let index = 0; index < safe.length; index += 1) {
53
+ const character = safe[index];
54
+ if (character === "\\") {
55
+ index += 1;
56
+ } else if (character === "[" || character === "(") {
57
+ if (++depth > MAX_TEMPLATE_DEPTH) return void 0;
58
+ } else if (character === "]" || character === ")") {
59
+ depth -= 1;
61
60
  }
62
- offset = closing.end;
63
61
  }
64
- return output + sanitizePlainText(value.slice(offset));
65
- }
66
- function sanitizePlainText(value) {
67
- return sanitizeTerminalDocument(value).replace(/\t/gu, " ");
68
- }
69
- function terminatorEnd(value, start) {
70
- if (value.startsWith(BEL, start)) return start + BEL.length;
71
- if (value.startsWith(ST, start)) return start + ST.length;
72
- return void 0;
73
- }
74
- function findTerminator(value, start) {
75
- for (let index = start; index < value.length; index += 1) {
76
- const end = terminatorEnd(value, index);
77
- if (end !== void 0) return { start: index, end };
78
- }
79
- return void 0;
80
- }
81
- function findLinkEnd(value, start) {
82
- let index = value.indexOf(PREFIX, start);
83
- while (index >= 0) {
84
- const end = terminatorEnd(value, index + PREFIX.length);
85
- if (end !== void 0) return { start: index, end };
86
- index = value.indexOf(PREFIX, index + PREFIX.length);
87
- }
88
- return void 0;
89
- }
90
- function safeHyperlinkUrl(value) {
91
- if (value.length > 4096 || Array.from(value).some((character) => {
92
- const code = character.codePointAt(0) ?? 0;
93
- return code <= 31 || code >= 127 && code <= 159 || code >= 55296 && code <= 57343;
94
- }))
95
- return void 0;
96
62
  try {
97
- const url = new URL(value);
98
- if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password) return void 0;
99
- const normalized = url.toString();
100
- return normalized.length <= 4096 ? normalized : void 0;
63
+ const nodes = parseFormat(safe);
64
+ if ([...formatVariables(nodes)].some((variable) => !variables.includes(variable))) return void 0;
65
+ if (styleVariables(nodes).size > 0) return void 0;
66
+ return nodes;
101
67
  } catch {
102
68
  return void 0;
103
69
  }
104
70
  }
105
-
106
- // src/format/theme-colors.ts
107
- var THEME_ROLES = {
108
- accent: true,
109
- border: true,
110
- borderAccent: true,
111
- borderMuted: true,
112
- success: true,
113
- error: true,
114
- warning: true,
115
- muted: true,
116
- dim: true,
117
- text: true,
118
- thinkingText: true,
119
- scrollbarTrack: true,
120
- scrollbarThumb: true,
121
- selectedBg: true,
122
- searchMatchBg: true,
123
- searchMatchText: true,
124
- userMessageBg: true,
125
- userMessageText: true,
126
- customMessageBg: true,
127
- customMessageText: true,
128
- customMessageLabel: true,
129
- toolPendingBg: true,
130
- toolSuccessBg: true,
131
- toolErrorBg: true,
132
- toolTitle: true,
133
- toolOutput: true,
134
- mdHeading: true,
135
- mdLink: true,
136
- mdLinkUrl: true,
137
- mdCode: true,
138
- mdCodeBlock: true,
139
- mdCodeBlockBorder: true,
140
- mdQuote: true,
141
- mdQuoteBorder: true,
142
- mdHr: true,
143
- mdListBullet: true,
144
- toolDiffAdded: true,
145
- toolDiffRemoved: true,
146
- toolDiffContext: true,
147
- syntaxComment: true,
148
- syntaxKeyword: true,
149
- syntaxFunction: true,
150
- syntaxVariable: true,
151
- syntaxString: true,
152
- syntaxNumber: true,
153
- syntaxType: true,
154
- syntaxOperator: true,
155
- syntaxPunctuation: true,
156
- thinkingOff: true,
157
- thinkingMinimal: true,
158
- thinkingLow: true,
159
- thinkingMedium: true,
160
- thinkingHigh: true,
161
- thinkingXhigh: true,
162
- thinkingMax: true,
163
- bashMode: true
164
- };
165
- function isThemeRole(role) {
166
- return Object.hasOwn(THEME_ROLES, role);
167
- }
168
-
169
- // src/format/style.ts
170
- function isFillChunk(chunk) {
171
- return "type" in chunk && chunk.type === "fill";
172
- }
173
- var NAMED_COLORS = /* @__PURE__ */ new Set([
174
- "black",
175
- "red",
176
- "green",
177
- "yellow",
178
- "blue",
179
- "purple",
180
- "cyan",
181
- "white",
182
- "bright-black",
183
- "bright-red",
184
- "bright-green",
185
- "bright-yellow",
186
- "bright-blue",
187
- "bright-purple",
188
- "bright-cyan",
189
- "bright-white"
190
- ]);
191
- var FOREGROUND_CODES = {
192
- black: 30,
193
- red: 31,
194
- green: 32,
195
- yellow: 33,
196
- blue: 34,
197
- purple: 35,
198
- cyan: 36,
199
- white: 37,
200
- "bright-black": 90,
201
- "bright-red": 91,
202
- "bright-green": 92,
203
- "bright-yellow": 93,
204
- "bright-blue": 94,
205
- "bright-purple": 95,
206
- "bright-cyan": 96,
207
- "bright-white": 97
208
- };
209
- function isValidStyle(styleString, palette = {}) {
210
- return parseStyleResult(styleString, palette).valid;
211
- }
212
- function parseStyleResult(styleString, palette = {}) {
213
- const tokens = styleString.split(/\s+/u).filter(Boolean).map(normalizeStyleToken);
214
- if (tokens.some(({ token, foreground }) => foreground && token === "none")) {
215
- return { valid: true, style: void 0 };
216
- }
217
- const style = {};
218
- for (const { token, foreground } of tokens) {
219
- if (applyModifier(style, token)) continue;
220
- if (token === "prev_fg" || token === "prev_bg") {
221
- const source = token === "prev_fg" ? "foreground" : "background";
222
- if (foreground) style.foregroundPrevious = source;
223
- else style.backgroundPrevious = source;
224
- continue;
225
- }
226
- const color = parseColor(token, palette);
227
- if (!foreground && !color && !token.toLowerCase().startsWith("pi:")) {
228
- delete style.background;
229
- continue;
230
- }
231
- if (!color) return { valid: false, style: void 0 };
232
- if (foreground) style.foreground = color;
233
- else style.background = color;
234
- }
235
- return { valid: true, style };
236
- }
237
- function parseStyle(styleString, palette = {}) {
238
- return parseStyleResult(styleString, palette).style;
239
- }
240
- function normalizeStyleToken(rawToken) {
241
- if (/^fg:/iu.test(rawToken)) {
242
- return { token: normalizeColorToken(rawToken.replace(/^(?:fg:)+/iu, "")), foreground: true };
243
- }
244
- if (/^bg:/iu.test(rawToken)) {
245
- return { token: normalizeColorToken(rawToken.replace(/^(?:bg:)+/iu, "")), foreground: false };
246
- }
247
- return { token: normalizeColorToken(rawToken), foreground: true };
248
- }
249
- function normalizeColorToken(token) {
250
- return /^pi:/iu.test(token) ? `pi:${token.slice(3)}` : token.toLowerCase();
251
- }
252
- function applyModifier(style, token) {
253
- switch (token) {
254
- case "bold":
255
- style.bold = true;
256
- return true;
257
- case "italic":
258
- style.italic = true;
259
- return true;
260
- case "underline":
261
- style.underline = true;
262
- return true;
263
- case "dimmed":
264
- style.dimmed = true;
265
- return true;
266
- case "inverted":
267
- style.inverted = true;
268
- return true;
269
- case "blink":
270
- style.blink = true;
271
- return true;
272
- case "hidden":
273
- style.hidden = true;
274
- return true;
275
- case "strikethrough":
276
- style.strikethrough = true;
277
- return true;
278
- default:
279
- return false;
280
- }
281
- }
282
- function parseColor(token, palette = {}) {
283
- const paletteKey = token.toLowerCase();
284
- const paletteValue = Object.hasOwn(palette, paletteKey) ? palette[paletteKey] : void 0;
285
- if (paletteValue !== void 0) return parseColor(normalizeColorToken(paletteValue), {});
286
- token = normalizeColorToken(token);
287
- if (token.startsWith("pi:")) {
288
- const role = token.slice(3);
289
- return isThemeRole(role) ? { kind: "theme", role } : void 0;
290
- }
291
- if (NAMED_COLORS.has(token)) {
292
- return { kind: "named", name: token };
293
- }
294
- if (/^\d{1,3}$/u.test(token)) {
295
- const value = Number(token);
296
- return value <= 255 ? { kind: "fixed", value } : void 0;
297
- }
298
- const rgb = /^#([0-9a-f]{6})$/iu.exec(token);
299
- if (!rgb?.[1]) return void 0;
300
- return {
301
- kind: "rgb",
302
- red: Number.parseInt(rgb[1].slice(0, 2), 16),
303
- green: Number.parseInt(rgb[1].slice(2, 4), 16),
304
- blue: Number.parseInt(rgb[1].slice(4, 6), 16)
305
- };
306
- }
307
- function renderChunksToAnsi(chunks, trueColor = true, themeColors) {
308
- const runs = [];
309
- let previous;
310
- for (const chunk of chunks) {
311
- if (isFillChunk(chunk)) continue;
312
- const style = resolveStyle(chunk.style, previous);
313
- const text = sanitizeFormatText(chunk.text);
314
- const last = runs.at(-1);
315
- if (text && last && stylesEqual(last.style, style)) last.text += text;
316
- else if (text) runs.push({ text, style });
317
- previous = style;
318
- }
319
- return runs.map(({ text, style }) => {
320
- const codes = ansiCodes(style, trueColor);
321
- const prefix = themeColorAnsi(style.foreground, false, trueColor, themeColors) + themeColorAnsi(style.background, true, trueColor, themeColors) + (codes.length > 0 ? `\x1B[${codes.join(";")}m` : "");
322
- return prefix ? `${prefix}${text}\x1B[0m` : text;
323
- }).join("");
324
- }
325
- function stylesEqual(left, right) {
326
- return JSON.stringify(left) === JSON.stringify(right);
327
- }
328
- function resolveStyle(style, previous) {
329
- if (!style) return {};
330
- const { foregroundPrevious, backgroundPrevious, ...resolved } = style;
331
- return {
332
- ...resolved,
333
- foreground: resolveColor(style.foreground, foregroundPrevious, previous),
334
- background: resolveColor(style.background, backgroundPrevious, previous)
335
- };
336
- }
337
- function resolveColor(fallback, source, previous) {
338
- if (!source || !previous) return fallback;
339
- return source === "foreground" ? previous.foreground : previous.background;
340
- }
341
- function ansiCodes(style, trueColor) {
342
- const codes = [];
343
- if (style.foreground) codes.push(...colorCodes(style.foreground, false, trueColor));
344
- if (style.background) codes.push(...colorCodes(style.background, true, trueColor));
345
- if (style.bold) codes.push("1");
346
- if (style.dimmed) codes.push("2");
347
- if (style.italic) codes.push("3");
348
- if (style.underline) codes.push("4");
349
- if (style.blink) codes.push("5");
350
- if (style.inverted) codes.push("7");
351
- if (style.hidden) codes.push("8");
352
- if (style.strikethrough) codes.push("9");
353
- return codes;
354
- }
355
- function themeColorAnsi(color, background, trueColor, themeColors) {
356
- if (color?.kind !== "theme" || !themeColors) return "";
357
- const mode = trueColor ? "truecolor" : "256color";
358
- return (background ? backgroundAnsi : foregroundAnsi)(themeColors[color.role], mode);
359
- }
360
- function colorCodes(color, background, trueColor) {
361
- if (color.kind === "theme") return [];
362
- if (color.kind === "named") {
363
- const foreground = FOREGROUND_CODES[color.name];
364
- return [`${background ? foreground + 10 : foreground}`];
365
- }
366
- if (color.kind === "fixed") return [background ? "48" : "38", "5", `${color.value}`];
367
- if (!trueColor) {
368
- return [background ? "48" : "38", "5", `${rgbToAnsi256(color.red, color.green, color.blue)}`];
369
- }
370
- return [background ? "48" : "38", "2", `${color.red}`, `${color.green}`, `${color.blue}`];
371
- }
372
- function rgbToAnsi256(red, green, blue) {
373
- const channels = [red, green, blue].map((value) => Math.round(value / 255 * 5));
374
- return 16 + 36 * (channels[0] ?? 0) + 6 * (channels[1] ?? 0) + (channels[2] ?? 0);
71
+ function joinStatusTemplates(values) {
72
+ const result = [];
73
+ for (const value of values) {
74
+ if (value.length === 0) continue;
75
+ if (result.length > 0) result.push({ text: " " });
76
+ result.push(...value);
77
+ }
78
+ return result;
375
79
  }
376
80
 
377
- // src/format/formatter.ts
378
- var FormatSyntaxError = class extends Error {
379
- offset;
380
- constructor(message, offset) {
381
- super(`${message} at offset ${offset}`);
382
- this.name = "FormatSyntaxError";
383
- this.offset = offset;
384
- }
385
- };
386
- var FUNCTIONAL = /* @__PURE__ */ new Set(["[", "]", "(", ")", "\\", "$"]);
387
- function parseFormat(format) {
388
- const parser = new FormatParser(format);
389
- const nodes = parser.parseNodes();
390
- if (!parser.done()) throw new FormatSyntaxError("Unexpected character", parser.offset());
391
- return nodes;
392
- }
393
- var FormatParser = class {
394
- constructor(input) {
395
- this.input = input;
396
- }
397
- input;
398
- index = 0;
399
- offset() {
400
- return this.index;
401
- }
402
- done() {
403
- return this.index === this.input.length;
404
- }
405
- parseNodes(end) {
406
- const nodes = [];
407
- let text = "";
408
- const flushText = () => {
409
- if (!text) return;
410
- nodes.push({ type: "text", value: text });
411
- text = "";
412
- };
413
- while (!this.done()) {
414
- const current = this.input[this.index];
415
- if (current === end) {
416
- flushText();
417
- this.index += 1;
418
- return nodes;
419
- }
420
- if (current === "\\") {
421
- const escaped = this.input[this.index + 1];
422
- if (!escaped || !FUNCTIONAL.has(escaped)) {
423
- throw new FormatSyntaxError("Invalid escape", this.index);
424
- }
425
- text += escaped;
426
- this.index += 2;
427
- continue;
428
- }
429
- if (current === "$") {
430
- flushText();
431
- nodes.push({ type: "variable", name: this.parseVariable() });
432
- continue;
433
- }
434
- if (current === "[") {
435
- flushText();
436
- this.index += 1;
437
- const children = this.parseNodes("]");
438
- if (this.input[this.index] !== "(") {
439
- throw new FormatSyntaxError("Text group requires a style", this.index);
440
- }
441
- this.index += 1;
442
- nodes.push({ type: "group", children, style: this.parseStyleNodes() });
443
- continue;
444
- }
445
- if (current === "(") {
446
- flushText();
447
- this.index += 1;
448
- nodes.push({ type: "conditional", children: this.parseNodes(")") });
449
- continue;
450
- }
451
- if (current === "]" || current === ")") {
452
- throw new FormatSyntaxError(`Unexpected ${current}`, this.index);
453
- }
454
- text += current;
455
- this.index += 1;
456
- }
457
- if (end) throw new FormatSyntaxError(`Missing ${end}`, this.index);
458
- flushText();
459
- return nodes;
460
- }
461
- parseVariable() {
462
- const start = this.index;
463
- this.index += 1;
464
- if (this.input[this.index] === "{") {
465
- this.index += 1;
466
- const nameStart = this.index;
467
- while (!this.done() && this.input[this.index] !== "}") {
468
- const current = this.input[this.index];
469
- if (!current || FUNCTIONAL.has(current) || current === "{") {
470
- throw new FormatSyntaxError("Invalid scoped variable", this.index);
471
- }
472
- this.index += 1;
473
- }
474
- if (this.done() || this.index === nameStart) {
475
- throw new FormatSyntaxError("Unclosed scoped variable", start);
476
- }
477
- const name = this.input.slice(nameStart, this.index);
478
- this.index += 1;
479
- return name;
480
- }
481
- const match = /^[A-Za-z_][A-Za-z0-9_]*/u.exec(this.input.slice(this.index));
482
- if (!match) throw new FormatSyntaxError("Invalid variable", start);
483
- this.index += match[0].length;
484
- return match[0];
485
- }
486
- parseStyleNodes() {
487
- const nodes = [];
488
- let text = "";
489
- const flushText = () => {
490
- if (!text) return;
491
- nodes.push({ type: "text", value: text });
492
- text = "";
493
- };
494
- while (!this.done()) {
495
- const current = this.input[this.index];
496
- if (current === ")") {
497
- flushText();
498
- this.index += 1;
499
- return nodes;
500
- }
501
- if (current === "$") {
502
- flushText();
503
- nodes.push({ type: "variable", name: this.parseVariable() });
504
- continue;
505
- }
506
- if (current === "(" || current === "[" || current === "]" || current === "\\") {
507
- throw new FormatSyntaxError("Invalid style character", this.index);
81
+ // src/config/module-options.ts
82
+ var invalid = (expected) => ({ ok: false, message: `Expected ${expected}; using the default value` });
83
+ var record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
84
+ var text = (value, max = 4096) => typeof value === "string" && value.length <= max;
85
+ function normalizeModuleOption(value, schema, palette = {}) {
86
+ switch (schema.kind) {
87
+ case "string": {
88
+ if (typeof value !== "string" || schema.allowEmpty === false && value.length === 0) return invalid("a string");
89
+ if (schema.templateVariables && !validStatusTemplate(value, schema.templateVariables)) {
90
+ return invalid("a bounded template with only the documented variables");
508
91
  }
509
- text += current;
510
- this.index += 1;
92
+ return { ok: true, value };
511
93
  }
512
- throw new FormatSyntaxError("Missing )", this.index);
513
- }
514
- };
515
- function formatVariables(nodes) {
516
- const variables = /* @__PURE__ */ new Set();
517
- for (const node of nodes) {
518
- if (node.type === "variable") variables.add(node.name);
519
- else if (node.type === "group" || node.type === "conditional") {
520
- for (const variable of formatVariables(node.children)) variables.add(variable);
94
+ case "string-enum":
95
+ return typeof value === "string" && schema.values.includes(value) ? { ok: true, value } : invalid(`one of: ${schema.values.join(", ")}`);
96
+ case "boolean":
97
+ return typeof value === "boolean" ? { ok: true, value } : invalid("boolean");
98
+ case "integer":
99
+ case "number":
100
+ return typeof value === "number" && Number.isFinite(value) && (schema.kind !== "integer" || Number.isInteger(value)) && value >= schema.minimum && value <= schema.maximum ? { ok: true, value } : invalid(`${schema.kind} from ${schema.minimum} through ${schema.maximum}`);
101
+ case "string-array":
102
+ return Array.isArray(value) && value.every(
103
+ (item) => typeof item === "string" && item.length > 0 && (schema.allowNegative || !item.startsWith("!"))
104
+ ) ? { ok: true, value: [...value] } : invalid("an array of valid strings");
105
+ case "string-map":
106
+ return stringMap(value);
107
+ case "command-alternatives": {
108
+ if (typeof value === "string") value = [value];
109
+ const argument = (item) => text(item, 1024) && item.length > 0 && ![...item].some((character) => {
110
+ const code = character.codePointAt(0) ?? 0;
111
+ return code < 32 || code >= 127 && code <= 159;
112
+ });
113
+ if (!Array.isArray(value) || value.length > 16 || !value.every(
114
+ (item) => argument(item) || Array.isArray(item) && item.length > 0 && item.length <= 16 && item.every(argument)
115
+ ))
116
+ return invalid("at most 16 command names or argv arrays without terminal controls");
117
+ return { ok: true, value: structuredClone(value) };
521
118
  }
522
- }
523
- return variables;
524
- }
525
- function styleVariables(nodes) {
526
- const variables = /* @__PURE__ */ new Set();
527
- for (const node of nodes) {
528
- if (node.type === "group") {
529
- for (const part of node.style) {
530
- if (part.type === "variable") variables.add(part.name);
119
+ case "context-rules": {
120
+ if (!Array.isArray(value) || value.length > 64) return invalid("at most 64 context rules");
121
+ const keys = /* @__PURE__ */ new Set(["context_pattern", "user_pattern", "symbol", "style", "context_alias", "user_alias"]);
122
+ for (const rule of value) {
123
+ if (!record(rule) || !text(rule.context_pattern, 512) || !validPattern(rule.context_pattern) || Object.entries(rule).some(
124
+ ([key, item]) => !keys.has(key) || !text(item) || (key === "context_pattern" || key === "user_pattern") && (!text(item, 512) || !validPattern(item)) || key === "style" && !isValidStyle(item, palette)
125
+ ))
126
+ return invalid("context rules with valid bounded patterns, strings, and styles");
531
127
  }
128
+ return { ok: true, value: structuredClone(value) };
532
129
  }
533
- if (node.type === "group" || node.type === "conditional") {
534
- for (const variable of styleVariables(node.children)) variables.add(variable);
535
- }
536
- }
537
- return variables;
538
- }
539
- function renderFormat(nodes, options) {
540
- return renderNodes(nodes, options, void 0);
541
- }
542
- function renderNodes(nodes, options, inheritedStyle) {
543
- const chunks = [];
544
- for (const node of nodes) {
545
- switch (node.type) {
546
- case "text":
547
- chunks.push({ text: sanitizeFormatText(node.value), style: inheritedStyle });
548
- break;
549
- case "variable":
550
- chunks.push(...chunksForValue(ownValue(options.variables, node.name), inheritedStyle));
551
- break;
552
- case "conditional":
553
- if (conditionalVisible(node.children, options.variables)) {
554
- chunks.push(...renderNodes(node.children, options, inheritedStyle));
555
- }
556
- break;
557
- case "group": {
558
- const styleString = node.style.map((part) => part.type === "text" ? part.value : ownValue(options.styleVariables, part.name) ?? "").join("");
559
- const style = parseStyle(styleString, options.palette);
560
- const rendered = renderNodes(node.children, options, style);
561
- if (node.children.length === 0) chunks.push({ text: "", style });
562
- else chunks.push(...rendered);
563
- break;
130
+ case "substitutions": {
131
+ if (!Array.isArray(value)) return stringMap(value);
132
+ if (value.length > 64) return invalid("at most 64 substitutions");
133
+ for (const substitution of value) {
134
+ if (!record(substitution) || !text(substitution.from, 512) || !text(substitution.to) || Object.keys(substitution).some((key) => key !== "from" && key !== "to" && key !== "regex") || substitution.regex !== void 0 && typeof substitution.regex !== "boolean" || substitution.regex === true && !validPattern(substitution.from))
135
+ return invalid("bounded from/to substitutions with an optional regex boolean");
564
136
  }
137
+ return { ok: true, value: structuredClone(value) };
565
138
  }
566
139
  }
567
- return chunks;
568
- }
569
- function ownValue(record, key) {
570
- return record && Object.hasOwn(record, key) ? record[key] : void 0;
571
- }
572
- function chunksForValue(value, inheritedStyle) {
573
- if (value === void 0) return [];
574
- if (typeof value === "string") return [{ text: sanitizeFormatText(value), style: inheritedStyle }];
575
- return value.map(
576
- (chunk) => isFillChunk(chunk) ? {
577
- type: "fill",
578
- pattern: chunk.pattern.map((part) => ({
579
- ...part,
580
- text: sanitizeFormatText(part.text),
581
- style: part.style ?? inheritedStyle
582
- }))
583
- } : { ...chunk, text: sanitizeFormatText(chunk.text), style: chunk.style ?? inheritedStyle }
584
- );
585
140
  }
586
- function conditionalVisible(nodes, variables) {
587
- for (const variable of formatVariables(nodes)) {
588
- const value = ownValue(variables, variable);
589
- if (typeof value === "string" ? sanitizeFormatText(value).length > 0 : value?.some((chunk) => isFillChunk(chunk) || sanitizeFormatText(chunk.text).length > 0)) {
590
- return true;
591
- }
592
- }
593
- return false;
141
+ function stringMap(value) {
142
+ if (!record(value) || Object.values(value).some((item) => typeof item !== "string"))
143
+ return invalid("a table of strings");
144
+ return { ok: true, value: Object.fromEntries(Object.entries(value)) };
594
145
  }
595
146
 
596
147
  // src/modules/activity.ts
597
148
  import { sliceByColumn, visibleWidth } from "@earendil-works/pi-tui";
598
- import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
149
+ import { sanitizeTerminalText as sanitizeTerminalText2 } from "@narumitw/pi-tui-kit/terminal-text";
599
150
 
600
151
  // src/modules/types.ts
601
152
  function defineModule(definition) {
@@ -619,7 +170,7 @@ function boundUIPromptTitleLength(title) {
619
170
  return end < title.length ? `${title.slice(0, ellipsisEnd)}\u2026` : title;
620
171
  }
621
172
  function formatUIPromptTitle(title) {
622
- const safeTitle = title ? sanitizeTerminalText(title).trim() : "";
173
+ const safeTitle = title ? sanitizeTerminalText2(title).trim() : "";
623
174
  const boundedTitle = boundUIPromptTitleLength(safeTitle);
624
175
  if (visibleWidth(boundedTitle) <= MAX_UI_PROMPT_TITLE_WIDTH) return boundedTitle;
625
176
  return `${sliceByColumn(boundedTitle, 0, MAX_UI_PROMPT_TITLE_WIDTH - 1, true)}\u2026`;
@@ -648,13 +199,13 @@ var activityModule = defineModule({
648
199
  }
649
200
  const active = [...runtime.activeTools.entries()];
650
201
  if (active.length > 0) {
651
- const [tool = "tool", count2 = 1] = active[0] ?? [];
652
- const suffix = count2 > 1 ? `\xD7${count2}` : "";
202
+ const [tool = "tool", count = 1] = active[0] ?? [];
203
+ const suffix = count > 1 ? `\xD7${count}` : "";
653
204
  const more = active.length > 1 ? `+${active.length - 1}` : "";
654
205
  return {
655
206
  state: "active",
656
207
  tool,
657
- count: `${count2}`,
208
+ count: `${count}`,
658
209
  ...EMPTY_PROMPT_VALUES,
659
210
  text: `${symbol} ${tool}${suffix}${more}`
660
211
  };
@@ -770,7 +321,8 @@ var gcloudModule = cloudModule({
770
321
  style: "bold blue",
771
322
  options: {
772
323
  project_aliases: { kind: "string-map", default: {} },
773
- region_aliases: { kind: "string-map", default: {} }
324
+ region_aliases: { kind: "string-map", default: {} },
325
+ detect_env_vars: { kind: "string-array", default: [], allowNegative: true }
774
326
  }
775
327
  });
776
328
  var azureModule = cloudModule({
@@ -898,7 +450,15 @@ var kubernetesModule = defineModule({
898
450
  style: "cyan bold",
899
451
  disabled: false
900
452
  },
453
+ resolveStyleVariables: ({ runtime, style }) => ({
454
+ style: runtime.workspace?.styleSelectors?.kubernetes ?? style
455
+ }),
901
456
  options: {
457
+ detect_files: { kind: "string-array", default: [], allowNegative: true },
458
+ detect_extensions: { kind: "string-array", default: [], allowNegative: true },
459
+ detect_folders: { kind: "string-array", default: [], allowNegative: true },
460
+ detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
461
+ contexts: { kind: "context-rules", default: [] },
902
462
  context_aliases: { kind: "string-map", default: {} },
903
463
  namespace_aliases: { kind: "string-map", default: {} },
904
464
  cluster_aliases: { kind: "string-map", default: {} },
@@ -979,7 +539,11 @@ var miseModule = developmentModule({
979
539
  format: "via [$symbol$health]($style) ",
980
540
  symbol: "mise ",
981
541
  style: "bold purple",
982
- options: directDetection2
542
+ options: {
543
+ ...directDetection2,
544
+ healthy_symbol: { kind: "string", default: "healthy" },
545
+ unhealthy_symbol: { kind: "string", default: "issues" }
546
+ }
983
547
  });
984
548
  var direnvModule = developmentModule({
985
549
  name: "direnv",
@@ -987,7 +551,15 @@ var direnvModule = developmentModule({
987
551
  format: "[$symbol$loaded]($style) ",
988
552
  symbol: "direnv ",
989
553
  style: "bold bright-yellow",
990
- options: directDetection2
554
+ options: {
555
+ ...directDetection2,
556
+ detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
557
+ allowed_msg: { kind: "string", default: "allowed" },
558
+ not_allowed_msg: { kind: "string", default: "not allowed" },
559
+ denied_msg: { kind: "string", default: "denied" },
560
+ loaded_msg: { kind: "string", default: "loaded" },
561
+ unloaded_msg: { kind: "string", default: "not loaded" }
562
+ }
991
563
  });
992
564
  var condaModule = defineModule({
993
565
  name: "conda",
@@ -1000,6 +572,7 @@ var condaModule = defineModule({
1000
572
  },
1001
573
  options: {
1002
574
  ignore_base: { kind: "boolean", default: true },
575
+ detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
1003
576
  truncation_length: { kind: "integer", default: 1, minimum: 0, maximum: 1e6 }
1004
577
  },
1005
578
  values: (context) => {
@@ -1029,7 +602,12 @@ var nixShellModule = developmentModule({
1029
602
  variables: ["state", "name", "level"],
1030
603
  format: "via [$symbol$state( \\($name\\))]($style) ",
1031
604
  symbol: "\uF313 ",
1032
- style: "bold blue"
605
+ style: "bold blue",
606
+ // No unknown_msg: unknown shells require unsupported heuristic discovery from PATH.
607
+ options: {
608
+ pure_msg: { kind: "string", default: "pure" },
609
+ impure_msg: { kind: "string", default: "impure" }
610
+ }
1033
611
  });
1034
612
  var guixShellModule = developmentModule({
1035
613
  name: "guix_shell",
@@ -1049,16 +627,28 @@ var developmentModules = [
1049
627
 
1050
628
  // src/modules/directory.ts
1051
629
  import { basename, isAbsolute, relative, sep as sep2 } from "node:path";
1052
- import { sanitizeTerminalText as sanitizeTerminalText2 } from "@narumitw/pi-tui-kit/terminal-text";
630
+ import { sanitizeTerminalText as sanitizeTerminalText3 } from "@narumitw/pi-tui-kit/terminal-text";
631
+ var DIRECTORY_REPO_ROOT_FORMAT = "[ $symbol ]($style)[$before_root_path]($before_repo_root_style)[$repo_root]($repo_root_style)[$path ]($style)[$read_only]($read_only_style)";
632
+ var MAX_SUBSTITUTED_PATH_LENGTH = 16384;
633
+ var MAX_SUBSTITUTIONS = 64;
1053
634
  var directoryModule = defineModule({
1054
635
  name: "directory",
1055
- variables: ["symbol", "path", "full_path"],
636
+ variables: ["symbol", "path", "full_path", "before_root_path", "repo_root", "read_only"],
1056
637
  defaults: {
1057
638
  format: "[ $symbol $path ]($style)",
1058
639
  symbol: "\u{1F4C1}",
1059
640
  style: "cyan bold",
1060
641
  disabled: false
1061
642
  },
643
+ fallbackStyle: true,
644
+ styleDefaults: { repo_root_style: "", before_repo_root_style: "", read_only_style: "red" },
645
+ styleVariables: ["style", "repo_root_style", "before_repo_root_style", "read_only_style"],
646
+ resolveStyleVariables: ({ style, styles }) => ({
647
+ style,
648
+ repo_root_style: styles.repo_root_style || style,
649
+ before_repo_root_style: styles.before_repo_root_style || style,
650
+ read_only_style: styles.read_only_style ?? "red"
651
+ }),
1062
652
  options: {
1063
653
  truncation_length: { kind: "integer", default: 3, minimum: 0, maximum: 1e6 },
1064
654
  truncate_to_repo: { kind: "boolean", default: true },
@@ -1066,41 +656,123 @@ var directoryModule = defineModule({
1066
656
  truncation_symbol: { kind: "string", default: "" },
1067
657
  home_symbol: { kind: "string", default: "~" },
1068
658
  use_os_path_sep: { kind: "boolean", default: true },
1069
- substitutions: { kind: "string-map", default: {} }
659
+ use_logical_path: { kind: "boolean", default: true },
660
+ // Empty is an inheritance sentinel, not an implicit second active format.
661
+ repo_root_format: { kind: "string", default: "", allowEmpty: true },
662
+ read_only: { kind: "string", default: "\u{1F512}", allowEmpty: true },
663
+ substitutions: { kind: "substitutions", default: {} }
1070
664
  },
1071
- values: ({ runtime, options }) => {
1072
- const fullPath = runtime.cwd;
1073
- const home = runtime.homeDir;
1074
- const repoRoot = runtime.gitRoot;
1075
- const homeSymbol = stringOption(options, "home_symbol", "~");
1076
- const truncateToRepo = booleanOption(options, "truncate_to_repo", true);
1077
- const substitutions = mapOption(options, "substitutions");
1078
- const homeContracted = contractPath(fullPath, home, homeSymbol);
1079
- const repoContracted = truncateToRepo && repoRoot && (!home || !samePath(repoRoot, home)) ? contractRepositoryPath(fullPath, repoRoot) : void 0;
1080
- let path = sanitizeTerminalText2(repoContracted ?? homeContracted);
1081
- let truncated = repoContracted !== void 0;
1082
- for (const [from, to] of Object.entries(substitutions)) {
1083
- if (from) path = path.replaceAll(from, to);
1084
- }
1085
- const componentResult = truncatePathComponents(path, numberOption(options, "truncation_length", 3));
1086
- path = componentResult.value;
1087
- truncated ||= componentResult.truncated;
1088
- if (truncated) {
1089
- const fishLength = numberOption(options, "fish_style_pwd_dir_length", 0);
1090
- if (fishLength > 0 && Object.keys(substitutions).length === 0) {
1091
- path = `${fishPrefix(homeContracted, path, fishLength)}${path}`;
1092
- } else {
1093
- path = `${stringOption(options, "truncation_symbol", "")}${path}`;
1094
- }
665
+ resolveFormat: (context, values) => values.repo_root ? directoryAlternateFormat(context.options, context.styles) : void 0,
666
+ values: directoryValues
667
+ });
668
+ function directoryAlternateFormat(options, styles = {}) {
669
+ return stringOption(options, "repo_root_format", "") || (styles.repo_root_style ? DIRECTORY_REPO_ROOT_FORMAT : void 0);
670
+ }
671
+ function directoryValues({ runtime, options, styles }) {
672
+ const metadata = runtime.workspace?.modules.directory;
673
+ const fullPath = sanitizeTerminalText3(
674
+ booleanOption(options, "use_logical_path", true) ? runtime.cwd : metadata?.physical_path || runtime.cwd
675
+ );
676
+ const home = runtime.homeDir === void 0 ? void 0 : sanitizeTerminalText3(runtime.homeDir);
677
+ const repoRoot = runtime.gitRoot === void 0 ? void 0 : sanitizeTerminalText3(runtime.gitRoot);
678
+ const homeSymbol = sanitizeTerminalText3(stringOption(options, "home_symbol", "~"));
679
+ const truncateToRepo = booleanOption(options, "truncate_to_repo", true);
680
+ const substitutions = substitutionsOption(options);
681
+ const homeContracted = contractPath(fullPath, home, homeSymbol);
682
+ const repoPath = repoRoot ? contractRepositoryPath(fullPath, repoRoot) : void 0;
683
+ const repoContracted = truncateToRepo && repoRoot && (!home || !samePath(repoRoot, home)) ? repoPath : void 0;
684
+ const contracted = repoContracted ?? homeContracted;
685
+ const substituted = substitutePath(contracted, substitutions);
686
+ const componentResult = truncatePathComponents(substituted, numberOption(options, "truncation_length", 3));
687
+ let path = componentResult.value;
688
+ let prefix = "";
689
+ if (repoContracted !== void 0 || componentResult.truncated) {
690
+ const fishLength = numberOption(options, "fish_style_pwd_dir_length", 0);
691
+ prefix = fishLength > 0 && substitutions.length === 0 ? fishPrefix(homeContracted, path, fishLength) : sanitizeTerminalText3(stringOption(options, "truncation_symbol", ""));
692
+ }
693
+ let beforeRoot = "";
694
+ let root = "";
695
+ if (directoryAlternateFormat(options, styles) && repoPath !== void 0 && repoRoot) {
696
+ const split = splitRepositoryPath(contracted, substituted, path, repoPath, repoRoot, substitutions);
697
+ if (split) {
698
+ beforeRoot = prefix + split.before;
699
+ root = split.root;
700
+ path = split.after;
701
+ prefix = "";
1095
702
  }
1096
- if (booleanOption(options, "use_os_path_sep", true)) path = useNativePathSeparator(path);
1097
- const fallback = basename(fullPath) || fullPath;
1098
- return {
1099
- path: sanitizeTerminalText2(path || fallback),
1100
- full_path: sanitizeTerminalText2(fullPath)
1101
- };
1102
703
  }
1103
- });
704
+ if (!root) path = prefix + path;
705
+ const fallback = basename(fullPath) || fullPath;
706
+ const native = booleanOption(options, "use_os_path_sep", true);
707
+ return {
708
+ path: sanitizeTerminalText3(
709
+ native ? useNativePathSeparator(path || (root ? "" : fallback)) : path || (root ? "" : fallback)
710
+ ),
711
+ before_root_path: sanitizeTerminalText3(native ? useNativePathSeparator(beforeRoot) : beforeRoot),
712
+ repo_root: sanitizeTerminalText3(native ? useNativePathSeparator(root) : root),
713
+ full_path: fullPath,
714
+ read_only: metadata?.read_only === "true" ? sanitizeTerminalText3(stringOption(options, "read_only", "\u{1F512}")) : ""
715
+ };
716
+ }
717
+ function substitutionsOption(options) {
718
+ const value = options.substitutions;
719
+ if (!value || typeof value !== "object") return [];
720
+ if (Array.isArray(value)) {
721
+ return value.flatMap((item) => {
722
+ if (!item || typeof item !== "object" || !("from" in item) || !("to" in item)) return [];
723
+ if (typeof item.from !== "string" || typeof item.to !== "string") return [];
724
+ return [
725
+ {
726
+ from: sanitizeTerminalText3(item.from),
727
+ to: sanitizeTerminalText3(item.to),
728
+ regex: "regex" in item && item.regex === true
729
+ }
730
+ ];
731
+ });
732
+ }
733
+ return Object.entries(value).flatMap(
734
+ ([from, to]) => typeof to === "string" ? [{ from: sanitizeTerminalText3(from), to: sanitizeTerminalText3(to) }] : []
735
+ );
736
+ }
737
+ function substitutePath(path, substitutions) {
738
+ if (path.length > MAX_SUBSTITUTED_PATH_LENGTH || substitutions.length > MAX_SUBSTITUTIONS) return path;
739
+ let result = path;
740
+ for (const { from, to, regex } of substitutions) {
741
+ if (!from && !regex) continue;
742
+ const next = regex ? replacePattern(from, result, to) : replaceLiteral(from, result, to);
743
+ if (next === void 0 || next.length > MAX_SUBSTITUTED_PATH_LENGTH) return path;
744
+ result = next;
745
+ }
746
+ return result;
747
+ }
748
+ function replaceLiteral(from, value, to) {
749
+ const parts = [];
750
+ let offset = 0;
751
+ let length = 0;
752
+ while (true) {
753
+ const match = value.indexOf(from, offset);
754
+ const end = match === -1 ? value.length : match;
755
+ const part = value.slice(offset, end);
756
+ length += part.length + (match === -1 ? 0 : to.length);
757
+ if (length > MAX_SUBSTITUTED_PATH_LENGTH) return void 0;
758
+ parts.push(part);
759
+ if (match === -1) return parts.join("");
760
+ parts.push(to);
761
+ offset = match + from.length;
762
+ }
763
+ }
764
+ function splitRepositoryPath(contracted, substituted, displayed, repoPath, repoRoot, substitutions) {
765
+ if (!contracted.endsWith(repoPath) || !substituted.endsWith(displayed)) return void 0;
766
+ const rootName = basename(repoRoot) || toSlashPath(repoRoot);
767
+ const start = contracted.length - repoPath.length;
768
+ const before = substitutePath(contracted.slice(0, start), substitutions);
769
+ const root = substitutePath(rootName, substitutions);
770
+ const after = substitutePath(repoPath.slice(rootName.length), substitutions);
771
+ if (!root || before + root + after !== substituted) return void 0;
772
+ const omitted = substituted.length - displayed.length;
773
+ if (before.length < omitted) return void 0;
774
+ return { before: before.slice(omitted), root, after };
775
+ }
1104
776
  function contractPath(path, root, replacement) {
1105
777
  if (!root) return toSlashPath(path);
1106
778
  const child = relativeWithin(path, root);
@@ -1145,10 +817,6 @@ function booleanOption(options, name, fallback) {
1145
817
  const value = options[name];
1146
818
  return typeof value === "boolean" ? value : fallback;
1147
819
  }
1148
- function mapOption(options, name) {
1149
- const value = options[name];
1150
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
1151
- }
1152
820
 
1153
821
  // src/modules/execution.ts
1154
822
  var osModule = defineModule({
@@ -1190,6 +858,8 @@ var hostnameModule = defineModule({
1190
858
  },
1191
859
  options: {
1192
860
  ssh_only: { kind: "boolean", default: true },
861
+ ssh_symbol: { kind: "string", default: "\u{1F310} " },
862
+ detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
1193
863
  trim_at: { kind: "string", default: "." },
1194
864
  aliases: { kind: "string-map", default: {} }
1195
865
  },
@@ -1235,12 +905,12 @@ var extensionStatusModule = defineModule({
1235
905
  const statuses = [...runtime.extensionStatuses.entries()].filter(([key, value]) => key !== "starship" && value.trim()).slice(0, extensionStatus.maxStatuses).map(([key, value]) => ({ key, text: formatExtensionStatus(key, value, extensionStatus.icons) }));
1236
906
  if (statuses.length === 0) return void 0;
1237
907
  const { separator, styles } = extensionStatus;
1238
- const content = Object.keys(styles).length === 0 ? statuses.map(({ text }) => text).join(separator) : statuses.flatMap(({ key, text }, index) => {
908
+ const content = Object.keys(styles).length === 0 ? statuses.map(({ text: text2 }) => text2).join(separator) : statuses.flatMap(({ key, text: text2 }, index) => {
1239
909
  const configured = configuredStatusValue(key, styles);
1240
910
  const style = configured ?? (Object.hasOwn(styles, "fallback") ? styles.fallback : void 0);
1241
911
  return [
1242
912
  ...index > 0 ? [{ text: separator }] : [],
1243
- { text, style: style === void 0 ? void 0 : parseStyle(style, palette) ?? {} }
913
+ { text: text2, style: style === void 0 ? void 0 : parseStyle(style, palette) ?? {} }
1244
914
  ];
1245
915
  });
1246
916
  return { statuses: content, count: `${statuses.length}` };
@@ -1249,8 +919,8 @@ var extensionStatusModule = defineModule({
1249
919
  function formatExtensionStatus(key, value, configuredIcons) {
1250
920
  const status = splitExtensionStatusIcon(stripExtensionStatusPrefix(key, value));
1251
921
  const icon = extensionStatusIcon(key, status.icon, configuredIcons);
1252
- const text = simplifyExtensionStatusText(status.text);
1253
- return icon ? `${icon} ${text}` : text;
922
+ const text2 = simplifyExtensionStatusText(status.text);
923
+ return icon ? `${icon} ${text2}` : text2;
1254
924
  }
1255
925
  function extensionStatusIcon(key, leadingIcon, configuredIcons) {
1256
926
  const configured = configuredStatusValue(key, configuredIcons);
@@ -1318,18 +988,31 @@ var gitBranchModule = defineModule({
1318
988
  // Starship uses i64::MAX as its effective no-truncation default. Zero is the
1319
989
  // equivalent stable TOML representation in pi-starship's bounded integer schema.
1320
990
  truncation_length: { kind: "integer", default: 0, minimum: 0, maximum: 1e6 },
1321
- truncation_symbol: { kind: "string", default: "\u2026" }
991
+ truncation_symbol: { kind: "string", default: "\u2026" },
992
+ only_attached: { kind: "boolean", default: false },
993
+ // Pi formats historically expose both remote fields even for equal branches.
994
+ always_show_remote: { kind: "boolean", default: true },
995
+ ignore_branches: { kind: "string-array", default: [] },
996
+ ignore_remotes: { kind: "string-array", default: [] },
997
+ // The existing status collector does not expose bare repositories.
998
+ ignore_bare_repo: { kind: "boolean", default: true }
1322
999
  },
1323
1000
  values: ({ runtime, options }) => {
1324
1001
  const branch = runtime.gitBranchDetails;
1325
1002
  const name = branch?.name ?? runtime.gitBranch;
1326
- if (!name) return void 0;
1003
+ if (!name || options.only_attached === true && branch?.detached) return void 0;
1004
+ if (options.ignore_bare_repo !== false && branch?.bare) return void 0;
1005
+ if (Array.isArray(options.ignore_branches) && options.ignore_branches.includes(name)) return void 0;
1327
1006
  const length = typeof options.truncation_length === "number" ? options.truncation_length : 0;
1328
1007
  const symbol = typeof options.truncation_symbol === "string" ? options.truncation_symbol : "\u2026";
1008
+ const truncatedName = truncateLeadingGraphemes(name, length, symbol);
1009
+ const remoteBranch = truncateLeadingGraphemes(branch?.remoteBranch ?? "", length, symbol);
1010
+ const showRemote = options.always_show_remote !== false || remoteBranch !== "" && remoteBranch !== truncatedName;
1011
+ const ignoreRemote = Array.isArray(options.ignore_remotes) && options.ignore_remotes.includes(branch?.remoteName ?? "");
1329
1012
  return {
1330
- branch: truncateLeadingGraphemes(name, length, symbol),
1331
- remote_name: truncateLeadingGraphemes(branch?.remoteName ?? "", length, symbol),
1332
- remote_branch: truncateLeadingGraphemes(branch?.remoteBranch ?? "", length, symbol)
1013
+ branch: truncatedName,
1014
+ remote_name: showRemote && !ignoreRemote ? truncateLeadingGraphemes(branch?.remoteName ?? "", length, symbol) : "",
1015
+ remote_branch: showRemote ? remoteBranch : ""
1333
1016
  };
1334
1017
  }
1335
1018
  });
@@ -1346,15 +1029,19 @@ var gitCommitModule = defineModule({
1346
1029
  disabled: false
1347
1030
  },
1348
1031
  options: {
1349
- commit_hash_length: { kind: "integer", default: DEFAULT_HASH_LENGTH, minimum: 0, maximum: 64 }
1032
+ commit_hash_length: { kind: "integer", default: DEFAULT_HASH_LENGTH, minimum: 0, maximum: 64 },
1033
+ only_detached: { kind: "boolean", default: false },
1034
+ tag_symbol: { kind: "string", default: " \u{1F3F7} " },
1035
+ tag_disabled: { kind: "boolean", default: false },
1036
+ tag_max_candidates: { kind: "integer", default: 0, minimum: 0, maximum: 100 }
1350
1037
  },
1351
1038
  values: ({ runtime, options }) => {
1352
1039
  const commit = runtime.gitCommit;
1353
- if (!commit) return void 0;
1040
+ if (!commit || options.only_detached === true && !commit.detached) return void 0;
1354
1041
  const hashLength = typeof options.commit_hash_length === "number" ? options.commit_hash_length : DEFAULT_HASH_LENGTH;
1355
1042
  return {
1356
1043
  hash: commit.hash.slice(0, hashLength),
1357
- tag: commit.tag ? ` \u{1F3F7} ${commit.tag}` : ""
1044
+ tag: commit.tag && options.tag_disabled !== true ? `${typeof options.tag_symbol === "string" ? options.tag_symbol : " \u{1F3F7} "}${commit.tag}` : ""
1358
1045
  };
1359
1046
  }
1360
1047
  });
@@ -1375,17 +1062,31 @@ var gitMetricsModule = defineModule({
1375
1062
  },
1376
1063
  styleVariables: ["added_style", "deleted_style"],
1377
1064
  resolveStyleVariables: ({ styles }) => styles,
1378
- values: ({ runtime }) => {
1065
+ options: {
1066
+ only_nonzero_diffs: { kind: "boolean", default: true },
1067
+ ignore_submodules: { kind: "boolean", default: false }
1068
+ },
1069
+ values: ({ runtime, options }) => {
1379
1070
  const metrics = runtime.gitMetrics;
1380
- if (!metrics || metrics.added === 0 && metrics.deleted === 0) return void 0;
1071
+ const onlyNonzero = options.only_nonzero_diffs !== false;
1072
+ if (!metrics || onlyNonzero && metrics.added === 0 && metrics.deleted === 0) return void 0;
1381
1073
  return {
1382
- added: metrics.added > 0 ? metrics.added.toString() : "",
1383
- deleted: metrics.deleted > 0 ? metrics.deleted.toString() : ""
1074
+ added: !onlyNonzero || metrics.added > 0 ? metrics.added.toString() : "",
1075
+ deleted: !onlyNonzero || metrics.deleted > 0 ? metrics.deleted.toString() : ""
1384
1076
  };
1385
1077
  }
1386
1078
  });
1387
1079
 
1388
1080
  // src/modules/git/state.ts
1081
+ var STATE_OPTIONS = {
1082
+ REBASING: "rebase",
1083
+ MERGING: "merge",
1084
+ REVERTING: "revert",
1085
+ "CHERRY-PICKING": "cherry_pick",
1086
+ BISECTING: "bisect",
1087
+ AM: "am",
1088
+ "AM/REBASE": "am_or_rebase"
1089
+ };
1389
1090
  var gitStateModule = defineModule({
1390
1091
  name: "git_state",
1391
1092
  variables: ["symbol", "state", "progress_current", "progress_total"],
@@ -1395,11 +1096,22 @@ var gitStateModule = defineModule({
1395
1096
  style: "bold yellow",
1396
1097
  disabled: false
1397
1098
  },
1398
- values: ({ runtime }) => {
1099
+ options: {
1100
+ rebase: { kind: "string", default: "REBASING" },
1101
+ merge: { kind: "string", default: "MERGING" },
1102
+ revert: { kind: "string", default: "REVERTING" },
1103
+ cherry_pick: { kind: "string", default: "CHERRY-PICKING" },
1104
+ bisect: { kind: "string", default: "BISECTING" },
1105
+ am: { kind: "string", default: "AM" },
1106
+ am_or_rebase: { kind: "string", default: "AM/REBASE" }
1107
+ },
1108
+ values: ({ runtime, options }) => {
1399
1109
  const state = runtime.gitState;
1400
1110
  if (!state) return void 0;
1111
+ const key = STATE_OPTIONS[state.state];
1112
+ const label = typeof key === "string" ? options[key] : void 0;
1401
1113
  return {
1402
- state: state.state,
1114
+ state: typeof label === "string" ? label : state.state,
1403
1115
  progress_current: state.progressCurrent?.toString() ?? "",
1404
1116
  progress_total: state.progressTotal?.toString() ?? ""
1405
1117
  };
@@ -1407,6 +1119,29 @@ var gitStateModule = defineModule({
1407
1119
  });
1408
1120
 
1409
1121
  // src/modules/git/status.ts
1122
+ var COUNT_VARIABLES = ["count"];
1123
+ var DEFAULT_TEMPLATES = {
1124
+ ahead: "\u21E1$count",
1125
+ behind: "\u21E3$count",
1126
+ up_to_date: "",
1127
+ diverged: "\u21D5\u21E1$ahead_count\u21E3$behind_count",
1128
+ conflicted: "=$count",
1129
+ stashed: "\\$$count",
1130
+ deleted: "\u2718$count",
1131
+ renamed: "\xBB$count",
1132
+ modified: "!$count",
1133
+ typechanged: "T$count",
1134
+ staged: "+$count",
1135
+ untracked: "?$count",
1136
+ worktree_added: "A$count",
1137
+ worktree_deleted: "D$count",
1138
+ worktree_modified: "M$count",
1139
+ worktree_typechanged: "T$count",
1140
+ index_added: "A$count",
1141
+ index_deleted: "D$count",
1142
+ index_modified: "M$count",
1143
+ index_typechanged: "T$count"
1144
+ };
1410
1145
  var gitStatusModule = defineModule({
1411
1146
  name: "git_status",
1412
1147
  variables: [
@@ -1440,36 +1175,54 @@ var gitStatusModule = defineModule({
1440
1175
  style: "red bold",
1441
1176
  disabled: false
1442
1177
  },
1443
- values: ({ runtime }) => {
1178
+ options: {
1179
+ ...Object.fromEntries(
1180
+ Object.entries(DEFAULT_TEMPLATES).map(([name, template]) => [
1181
+ name,
1182
+ {
1183
+ kind: "string",
1184
+ default: template,
1185
+ templateVariables: name === "diverged" ? ["ahead_count", "behind_count"] : name === "up_to_date" ? [] : COUNT_VARIABLES
1186
+ }
1187
+ ])
1188
+ ),
1189
+ ignore_submodules: { kind: "boolean", default: false }
1190
+ },
1191
+ values: ({ runtime, options, palette, requestedVariables }) => {
1444
1192
  if (!runtime.gitBranch || !runtime.gitStatus) return void 0;
1445
1193
  const status = runtime.gitStatus;
1446
- const ahead = count("\u21E1", status.ahead);
1447
- const behind = count("\u21E3", status.behind);
1448
- const diverged = status.ahead > 0 && status.behind > 0 ? `\u21D5\u21E1${formatCount(status.ahead)}\u21E3${formatCount(status.behind)}` : "";
1194
+ const hasAhead = Number.isSafeInteger(status.ahead) && status.ahead > 0;
1195
+ const hasBehind = Number.isSafeInteger(status.behind) && status.behind > 0;
1196
+ const template = (name, variables) => renderStatusTemplate(templateOption(options, name), variables, palette);
1197
+ const count = (name, value) => countTemplate(options, name, value, palette);
1198
+ const ahead = count("ahead", status.ahead);
1199
+ const behind = count("behind", status.behind);
1200
+ const diverged = hasAhead && hasBehind ? template("diverged", { ahead_count: formatCount(status.ahead), behind_count: formatCount(status.behind) }) : [];
1201
+ const upToDate = status.upToDate && status.ahead === 0 && status.behind === 0 ? template("up_to_date", {}) : [];
1449
1202
  const values = {
1450
1203
  ahead,
1451
1204
  behind,
1452
- up_to_date: "",
1205
+ up_to_date: upToDate,
1453
1206
  diverged,
1454
- ahead_behind: diverged || ahead || behind,
1455
- conflicted: count("=", status.conflicted),
1456
- stashed: count("$", status.stashed),
1457
- deleted: count("\u2718", status.deleted),
1458
- renamed: count("\xBB", status.renamed),
1459
- modified: count("!", status.modified),
1460
- typechanged: count("T", status.typechanged),
1461
- staged: count("+", status.staged),
1462
- untracked: count("?", status.untracked),
1463
- worktree_added: count("A", status.worktreeAdded),
1464
- worktree_deleted: count("D", status.worktreeDeleted),
1465
- worktree_modified: count("M", status.worktreeModified),
1466
- worktree_typechanged: count("T", status.worktreeTypechanged),
1467
- index_added: count("A", status.indexAdded),
1468
- index_deleted: count("D", status.indexDeleted),
1469
- index_modified: count("M", status.indexModified),
1470
- index_typechanged: count("T", status.indexTypechanged)
1207
+ ahead_behind: hasAhead && hasBehind ? diverged : hasAhead ? ahead : hasBehind ? behind : upToDate,
1208
+ conflicted: count("conflicted", status.conflicted),
1209
+ stashed: count("stashed", status.stashed),
1210
+ deleted: count("deleted", status.deleted),
1211
+ renamed: count("renamed", status.renamed),
1212
+ modified: count("modified", status.modified),
1213
+ typechanged: count("typechanged", status.typechanged),
1214
+ staged: count("staged", status.staged),
1215
+ untracked: count("untracked", status.untracked),
1216
+ worktree_added: count("worktree_added", status.worktreeAdded),
1217
+ worktree_deleted: count("worktree_deleted", status.worktreeDeleted),
1218
+ worktree_modified: count("worktree_modified", status.worktreeModified),
1219
+ worktree_typechanged: count("worktree_typechanged", status.worktreeTypechanged),
1220
+ index_added: count("index_added", status.indexAdded),
1221
+ index_deleted: count("index_deleted", status.indexDeleted),
1222
+ index_modified: count("index_modified", status.indexModified),
1223
+ index_typechanged: count("index_typechanged", status.indexTypechanged)
1471
1224
  };
1472
- const allStatus = [
1225
+ const allStatus = joinStatusTemplates([
1473
1226
  values.conflicted,
1474
1227
  values.stashed,
1475
1228
  values.deleted,
@@ -1478,12 +1231,19 @@ var gitStatusModule = defineModule({
1478
1231
  values.typechanged,
1479
1232
  values.staged,
1480
1233
  values.untracked
1481
- ].filter(Boolean).join(" ");
1482
- return allStatus || values.ahead_behind ? { ...values, all_status: allStatus } : void 0;
1234
+ ]);
1235
+ const available = { ...values, all_status: allStatus };
1236
+ const requested = [...requestedVariables ?? []].filter((name) => Object.hasOwn(available, name));
1237
+ const visible = requested.length > 0 ? requested.map((name) => available[name]) : [allStatus, values.ahead_behind];
1238
+ return visible.some((value) => value.length > 0) ? available : void 0;
1483
1239
  }
1484
1240
  });
1485
- function count(symbol, value) {
1486
- return value > 0 ? `${symbol}${formatCount(value)}` : "";
1241
+ function templateOption(options, name) {
1242
+ const option = options[name];
1243
+ return typeof option === "string" ? option : DEFAULT_TEMPLATES[name];
1244
+ }
1245
+ function countTemplate(options, name, value, palette) {
1246
+ return Number.isSafeInteger(value) && value > 0 ? renderStatusTemplate(templateOption(options, name), { count: formatCount(value) }, palette) : [];
1487
1247
  }
1488
1248
 
1489
1249
  // src/modules/git/worktree.ts
@@ -1523,6 +1283,198 @@ var githubPrModule = defineModule({
1523
1283
  }
1524
1284
  });
1525
1285
 
1286
+ // src/modules/jujutsu.ts
1287
+ import { sanitizeTerminalText as sanitizeTerminalText4 } from "@narumitw/pi-tui-kit/terminal-text";
1288
+ var jjBookmarkModule = defineModule({
1289
+ name: "jj_bookmark",
1290
+ variables: ["symbol", "bookmark", "remote", "diverged", "overflow_count"],
1291
+ defaults: {
1292
+ format: "on [$symbol$bookmark(@$remote)$diverged( \\(+$overflow_count others\\))]($style) ",
1293
+ symbol: "\uE0A0 ",
1294
+ style: "bold purple",
1295
+ disabled: true
1296
+ },
1297
+ options: {
1298
+ truncation_length: { kind: "integer", default: 65535, minimum: 0, maximum: 65535 },
1299
+ truncation_symbol: { kind: "string", default: "\u2026", allowEmpty: true },
1300
+ diverged_symbol: { kind: "string", default: "*", allowEmpty: true },
1301
+ ignore_names: { kind: "string-array", default: [] },
1302
+ ignore_remotes: { kind: "string-array", default: [] }
1303
+ },
1304
+ values(context) {
1305
+ const values = workspaceModuleValues("jj_bookmark", context);
1306
+ if (!values?.bookmarks) return void 0;
1307
+ let raw;
1308
+ try {
1309
+ raw = JSON.parse(values.bookmarks);
1310
+ } catch {
1311
+ return void 0;
1312
+ }
1313
+ if (!Array.isArray(raw)) return void 0;
1314
+ const parsed = raw.map(parseBookmark);
1315
+ if (parsed.some((bookmark2) => bookmark2 === void 0)) return void 0;
1316
+ const ignoredNames = stringList(context, "ignore_names");
1317
+ const ignoredRemotes = stringList(context, "ignore_remotes");
1318
+ const bookmarks = parsed.filter((bookmark2) => bookmark2 !== void 0).filter(
1319
+ ({ name, remote }) => !ignoredNames.includes(name) && (remote === void 0 || !ignoredRemotes.includes(remote))
1320
+ );
1321
+ const bookmark = bookmarks[0];
1322
+ if (!bookmark) return void 0;
1323
+ const length = integerOption(context, "truncation_length", 65535);
1324
+ const symbol = stringOption2(context, "truncation_symbol", "\u2026");
1325
+ const truncate = (value) => truncateLeadingGraphemes(value, length, symbol);
1326
+ return {
1327
+ bookmark: truncate(bookmark.name),
1328
+ remote: bookmark.remote === void 0 ? "" : truncate(bookmark.remote),
1329
+ diverged: bookmark.diverged ? stringOption2(context, "diverged_symbol", "*") : "",
1330
+ overflow_count: bookmarks.length > 1 ? String(bookmarks.length - 1) : ""
1331
+ };
1332
+ }
1333
+ });
1334
+ var jjChangeModule = defineModule({
1335
+ name: "jj_change",
1336
+ variables: ["change", "commit", "change_prefix", "change_suffix", "change_offset", "commit_prefix", "commit_suffix"],
1337
+ defaults: { format: "$change ", symbol: "", style: "none", disabled: true },
1338
+ styleDefaults: { prefix_style: "green bold", suffix_style: "dimmed", change_offset_style: "bold" },
1339
+ styleVariables: ["prefix_style", "suffix_style", "change_offset_style"],
1340
+ resolveStyleVariables: ({ styles }) => styles,
1341
+ options: {
1342
+ change_hash_length: { kind: "integer", default: 7, minimum: 0, maximum: 255 },
1343
+ commit_hash_length: { kind: "integer", default: 7, minimum: 0, maximum: 255 }
1344
+ },
1345
+ values(context) {
1346
+ const values = workspaceModuleValues("jj_change", context);
1347
+ if (!values) return void 0;
1348
+ const change = idParts(
1349
+ values.change_id ?? "",
1350
+ Number(values.change_prefix_len),
1351
+ integerOption(context, "change_hash_length", 7)
1352
+ );
1353
+ const commit = idParts(
1354
+ values.commit_id ?? "",
1355
+ Number(values.commit_prefix_len),
1356
+ integerOption(context, "commit_hash_length", 7)
1357
+ );
1358
+ const styled = (text2, role) => ({
1359
+ text: text2,
1360
+ style: parseStyle(context.styles?.[role] ?? "", context.palette)
1361
+ });
1362
+ const changeChunks = [styled(change.prefix, "prefix_style"), styled(change.suffix, "suffix_style")];
1363
+ if (values.change_offset !== void 0)
1364
+ changeChunks.push(styled(`/${values.change_offset}`, "change_offset_style"));
1365
+ return {
1366
+ change: changeChunks,
1367
+ commit: [styled(commit.prefix, "prefix_style"), styled(commit.suffix, "suffix_style")],
1368
+ change_prefix: change.prefix,
1369
+ change_suffix: change.suffix,
1370
+ change_offset: values.change_offset ?? "",
1371
+ commit_prefix: commit.prefix,
1372
+ commit_suffix: commit.suffix
1373
+ };
1374
+ }
1375
+ });
1376
+ var jjMetricsModule = defineModule({
1377
+ name: "jj_metrics",
1378
+ variables: ["added", "deleted"],
1379
+ defaults: {
1380
+ format: "([+$added]($added_style) )([-$deleted]($deleted_style) )",
1381
+ symbol: "",
1382
+ style: "none",
1383
+ disabled: true
1384
+ },
1385
+ styleDefaults: { added_style: "bold green", deleted_style: "bold red" },
1386
+ styleVariables: ["added_style", "deleted_style"],
1387
+ resolveStyleVariables: ({ styles }) => styles,
1388
+ options: { only_nonzero_diffs: { kind: "boolean", default: true } },
1389
+ values(context) {
1390
+ const values = workspaceModuleValues("jj_metrics", context);
1391
+ if (!values) return void 0;
1392
+ if (context.options.only_nonzero_diffs === false) return values;
1393
+ return { added: values.added === "0" ? "" : values.added, deleted: values.deleted === "0" ? "" : values.deleted };
1394
+ }
1395
+ });
1396
+ var statusTemplates = {
1397
+ conflicted: "!",
1398
+ description_empty: "\u25CC",
1399
+ description_present: "",
1400
+ hidden: "",
1401
+ immutable: "\u25C6",
1402
+ added: "+",
1403
+ copied: "=",
1404
+ deleted: "\u2718",
1405
+ modified: "~",
1406
+ renamed: "\xBB"
1407
+ };
1408
+ var jjStatusModule = defineModule({
1409
+ name: "jj_status",
1410
+ variables: [
1411
+ "all",
1412
+ "conflicted",
1413
+ "description",
1414
+ "hidden",
1415
+ "immutable",
1416
+ "added",
1417
+ "copied",
1418
+ "deleted",
1419
+ "modified",
1420
+ "renamed"
1421
+ ],
1422
+ defaults: { format: "([\\[$all\\]]($style) )", symbol: "", style: "bold red", disabled: true },
1423
+ options: Object.fromEntries(
1424
+ Object.entries(statusTemplates).map(([key, value]) => [
1425
+ key,
1426
+ {
1427
+ kind: "string",
1428
+ default: value,
1429
+ allowEmpty: true,
1430
+ templateVariables: ["added", "copied", "deleted", "modified", "renamed"].includes(key) ? ["count"] : []
1431
+ }
1432
+ ])
1433
+ ),
1434
+ values(context) {
1435
+ const snapshot = workspaceModuleValues("jj_status", context);
1436
+ if (!snapshot) return void 0;
1437
+ const values = {};
1438
+ const symbol = (name, active = true, count) => active ? statusValue(stringOption2(context, name, statusTemplates[name]), count, context) : [];
1439
+ values.conflicted = symbol("conflicted", snapshot.conflicted === "true");
1440
+ values.description = symbol(snapshot.has_description === "true" ? "description_present" : "description_empty");
1441
+ values.hidden = symbol("hidden", snapshot.hidden === "true");
1442
+ values.immutable = symbol("immutable", snapshot.immutable === "true");
1443
+ for (const name of ["added", "copied", "deleted", "modified", "renamed"]) {
1444
+ values[name] = symbol(name, Number(snapshot[name]) > 0, snapshot[name]);
1445
+ }
1446
+ values.all = Object.values(values).flatMap((value) => Array.isArray(value) ? value : []);
1447
+ return values;
1448
+ }
1449
+ });
1450
+ var jujutsuModules = [jjBookmarkModule, jjChangeModule, jjMetricsModule, jjStatusModule];
1451
+ function parseBookmark(raw) {
1452
+ if (!raw || typeof raw !== "object" || !("name" in raw) || !("remote" in raw) || !("diverged" in raw) || typeof raw.name !== "string" || typeof raw.remote !== "string" || typeof raw.diverged !== "boolean")
1453
+ return void 0;
1454
+ const remote = sanitizeTerminalText4(raw.remote);
1455
+ return { name: sanitizeTerminalText4(raw.name), remote: remote || void 0, diverged: raw.diverged };
1456
+ }
1457
+ function idParts(id, prefixLength, hashLength) {
1458
+ const text2 = sanitizeTerminalText4(id);
1459
+ const start = Math.min(text2.length, Number.isFinite(prefixLength) ? Math.max(0, prefixLength) : 0);
1460
+ return { prefix: text2.slice(0, start), suffix: text2.slice(start, Math.max(start, hashLength)) };
1461
+ }
1462
+ function stringOption2(context, key, fallback) {
1463
+ const value = context.options[key];
1464
+ return typeof value === "string" ? sanitizeTerminalText4(value) : fallback;
1465
+ }
1466
+ function integerOption(context, key, fallback) {
1467
+ const value = context.options[key];
1468
+ return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : fallback;
1469
+ }
1470
+ function stringList(context, key) {
1471
+ const value = context.options[key];
1472
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string").map(sanitizeTerminalText4) : [];
1473
+ }
1474
+ function statusValue(template, count, context) {
1475
+ return renderStatusTemplate(template, count === void 0 ? {} : { count }, context.palette);
1476
+ }
1477
+
1526
1478
  // src/modules/languages.ts
1527
1479
  var detectionOptions = {
1528
1480
  version_format: { kind: "string", default: "v$raw" },
@@ -1540,7 +1492,15 @@ function languageModule(definition) {
1540
1492
  style: definition.style,
1541
1493
  disabled: false
1542
1494
  },
1543
- options: detectionOptions,
1495
+ ...definition.requirementStyle ? {
1496
+ // Opt in to requirement styling without changing existing output or symbol-only work.
1497
+ styleDefaults: { not_capable_style: "none" },
1498
+ fallbackStyle: true,
1499
+ resolveStyleVariables: ({ runtime, style, styles }) => ({
1500
+ style: runtime.workspace?.styleSelectors?.[definition.name] === "not_capable" ? styles.not_capable_style ?? style : style
1501
+ })
1502
+ } : {},
1503
+ options: { ...detectionOptions, ...definition.options },
1544
1504
  values: (context) => workspaceModuleValues(definition.name, context)
1545
1505
  });
1546
1506
  }
@@ -1549,14 +1509,22 @@ var nodejsModule = languageModule({
1549
1509
  variables: ["version", "engines_version"],
1550
1510
  format: "via [$symbol($version )]($style)",
1551
1511
  symbol: "\uE718 ",
1552
- style: "bold green"
1512
+ style: "bold green",
1513
+ requirementStyle: true
1553
1514
  });
1554
1515
  var pythonModule = languageModule({
1555
1516
  name: "python",
1556
1517
  variables: ["version", "virtualenv", "pyenv_prefix"],
1557
1518
  format: "via [$symbol$pyenv_prefix($version )(\\($virtualenv\\) )]($style)",
1558
1519
  symbol: "\uE235 ",
1559
- style: "yellow bold"
1520
+ style: "yellow bold",
1521
+ options: {
1522
+ pyenv_version_name: { kind: "boolean", default: false },
1523
+ pyenv_prefix: { kind: "string", default: "pyenv " },
1524
+ python_binary: { kind: "command-alternatives", default: [] },
1525
+ detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
1526
+ generic_venv_names: { kind: "string-array", default: [] }
1527
+ }
1560
1528
  });
1561
1529
  var rustModule = languageModule({
1562
1530
  name: "rust",
@@ -1570,7 +1538,8 @@ var golangModule = languageModule({
1570
1538
  variables: ["version", "mod_version"],
1571
1539
  format: "via [$symbol($version )]($style)",
1572
1540
  symbol: "\uE627 ",
1573
- style: "bold cyan"
1541
+ style: "bold cyan",
1542
+ requirementStyle: true
1574
1543
  });
1575
1544
  var bunModule = languageModule({
1576
1545
  name: "bun",
@@ -1589,7 +1558,7 @@ var denoModule = languageModule({
1589
1558
  var languageModules = [nodejsModule, pythonModule, rustModule, golangModule, bunModule, denoModule];
1590
1559
 
1591
1560
  // src/modules/model.ts
1592
- import { sanitizeTerminalText as sanitizeTerminalText3 } from "@narumitw/pi-tui-kit/terminal-text";
1561
+ import { sanitizeTerminalText as sanitizeTerminalText5 } from "@narumitw/pi-tui-kit/terminal-text";
1593
1562
  var TRUNCATION_DIRECTIONS = ["start", "middle", "end"];
1594
1563
  var graphemeSegmenter2 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
1595
1564
  var modelModule = defineModule({
@@ -1631,11 +1600,11 @@ var modelModule = defineModule({
1631
1600
  }
1632
1601
  });
1633
1602
  function truncateModel(model, length, symbol, direction) {
1634
- const safeModel = sanitizeTerminalText3(model);
1603
+ const safeModel = sanitizeTerminalText5(model);
1635
1604
  if (length === 0) return safeModel;
1636
1605
  const graphemes2 = [...graphemeSegmenter2.segment(safeModel)].map(({ segment }) => segment);
1637
1606
  if (graphemes2.length <= length) return safeModel;
1638
- const safeSymbol = sanitizeTerminalText3(symbol);
1607
+ const safeSymbol = sanitizeTerminalText5(symbol);
1639
1608
  switch (direction) {
1640
1609
  case "start":
1641
1610
  return `${safeSymbol}${graphemes2.slice(-length).join("")}`;
@@ -1653,7 +1622,7 @@ function isTruncationDirection(value) {
1653
1622
  return TRUNCATION_DIRECTIONS.includes(value);
1654
1623
  }
1655
1624
  function shortenModel(model) {
1656
- return sanitizeTerminalText3(model).replace(/^claude-/u, "").replace(/-20\d{6}$/u, "").replace(/-latest$/u, "");
1625
+ return sanitizeTerminalText5(model).replace(/^claude-/u, "").replace(/-20\d{6}$/u, "").replace(/-latest$/u, "");
1657
1626
  }
1658
1627
 
1659
1628
  // src/modules/package.ts
@@ -1667,13 +1636,14 @@ var packageModule = defineModule({
1667
1636
  disabled: false
1668
1637
  },
1669
1638
  options: {
1670
- version_format: { kind: "string", default: "v$raw" }
1639
+ version_format: { kind: "string", default: "v$raw" },
1640
+ display_private: { kind: "boolean", default: true }
1671
1641
  },
1672
1642
  values: (context) => workspaceModuleValues("package", context)
1673
1643
  });
1674
1644
 
1675
1645
  // src/modules/provider.ts
1676
- import { sanitizeTerminalText as sanitizeTerminalText4 } from "@narumitw/pi-tui-kit/terminal-text";
1646
+ import { sanitizeTerminalText as sanitizeTerminalText6 } from "@narumitw/pi-tui-kit/terminal-text";
1677
1647
  var PROVIDER_ALIASES_KEY = "provider_aliases";
1678
1648
  var providerModule = defineModule({
1679
1649
  name: "provider",
@@ -1695,9 +1665,58 @@ var providerModule = defineModule({
1695
1665
  const aliases = options[PROVIDER_ALIASES_KEY];
1696
1666
  const aliasMap = aliases && typeof aliases === "object" && !Array.isArray(aliases) ? aliases : void 0;
1697
1667
  const alias = aliasMap && Object.hasOwn(aliasMap, runtime.model.provider) ? aliasMap[runtime.model.provider] : void 0;
1698
- return { provider: sanitizeTerminalText4(alias ?? runtime.model.provider) };
1668
+ return { provider: sanitizeTerminalText6(alias ?? runtime.model.provider) };
1669
+ }
1670
+ });
1671
+
1672
+ // src/modules/system.ts
1673
+ import { sanitizeTerminalText as sanitizeTerminalText7 } from "@narumitw/pi-tui-kit/terminal-text";
1674
+ var memoryUsageModule = defineModule({
1675
+ name: "memory_usage",
1676
+ variables: ["symbol", "ram", "ram_pct", "swap", "swap_pct"],
1677
+ defaults: {
1678
+ format: "via $symbol[$ram( | $swap)]($style) ",
1679
+ symbol: "\u{1F40F} ",
1680
+ style: "white bold dimmed",
1681
+ disabled: true
1682
+ },
1683
+ options: { threshold: { kind: "number", default: 75, minimum: -100, maximum: 1e4 } },
1684
+ values: (context) => workspaceModuleValues("memory_usage", context)
1685
+ });
1686
+ var batteryModule = defineModule({
1687
+ name: "battery",
1688
+ variables: ["symbol", "percentage"],
1689
+ defaults: { format: "[$symbol$percentage]($style) ", symbol: "", style: "none", disabled: true },
1690
+ displayDefaults: [{ threshold: 10, style: "red bold", hidden: false }],
1691
+ styleVariables: ["style"],
1692
+ resolveStyleVariables: ({ runtime, display }) => {
1693
+ const raw = runtime.workspace?.modules.battery?.percentage_raw;
1694
+ if (raw === void 0) return void 0;
1695
+ const percentage = Number(raw);
1696
+ if (!Number.isFinite(percentage)) return void 0;
1697
+ const selected = display.reduce(
1698
+ (best, rule) => percentage <= rule.threshold && (best === void 0 || rule.threshold < best.threshold) ? rule : best,
1699
+ void 0
1700
+ );
1701
+ return selected && !selected.hidden ? { style: selected.style } : void 0;
1702
+ },
1703
+ options: {
1704
+ full_symbol: { kind: "string", default: "\u{F0079} ", allowEmpty: true },
1705
+ charging_symbol: { kind: "string", default: "\u{F0084} ", allowEmpty: true },
1706
+ discharging_symbol: { kind: "string", default: "\u{F0083} ", allowEmpty: true },
1707
+ unknown_symbol: { kind: "string", default: "\u{F0091} ", allowEmpty: true },
1708
+ empty_symbol: { kind: "string", default: "\u{F008E} ", allowEmpty: true }
1709
+ },
1710
+ values(context) {
1711
+ const values = workspaceModuleValues("battery", context);
1712
+ if (!values) return void 0;
1713
+ const state = values.state;
1714
+ const key = `${state === "full" || state === "charging" || state === "discharging" || state === "empty" ? state : "unknown"}_symbol`;
1715
+ const symbol = context.options[key];
1716
+ return { percentage: values.percentage, symbol: typeof symbol === "string" ? sanitizeTerminalText7(symbol) : "" };
1699
1717
  }
1700
1718
  });
1719
+ var systemModules = [memoryUsageModule, batteryModule];
1701
1720
 
1702
1721
  // src/modules/thinking.ts
1703
1722
  var THINKING_LEVELS = [
@@ -1735,6 +1754,146 @@ var thinkingModule = defineModule({
1735
1754
  values: ({ runtime }) => ({ level: runtime.thinkingLevel })
1736
1755
  });
1737
1756
 
1757
+ // src/modules/time-format.ts
1758
+ var MAX_TIME_FORMAT_LENGTH = 256;
1759
+ var MAX_TIME_ZONE_LENGTH = 128;
1760
+ var MAX_TIME_RANGE_LENGTH = 64;
1761
+ var FORMAT_TOKEN = /%%|%:z|%[HIMSpPRTrYmdFz]/gu;
1762
+ var cachedZone;
1763
+ function formatClockTime(now, options) {
1764
+ if (!Number.isFinite(now.getTime())) return void 0;
1765
+ if (!isInsideTimeRange(now, options.time_range)) return void 0;
1766
+ const fallback = options.use_12hr === true ? "%I:%M %p" : "%H:%M";
1767
+ const format = validTimeFormat(options.time_format) ? options.time_format : fallback;
1768
+ const parts = clockParts(now, options.utc_time_offset);
1769
+ const hour12 = parts.hour % 12 || 12;
1770
+ const period = parts.hour < 12 ? "AM" : "PM";
1771
+ const hours = pad(parts.hour);
1772
+ const minutes = pad(parts.minute);
1773
+ const seconds = pad(parts.second);
1774
+ const date = `${parts.year.toString().padStart(4, "0")}-${pad(parts.month)}-${pad(parts.day)}`;
1775
+ const tokens = {
1776
+ "%%": "%",
1777
+ "%H": hours,
1778
+ "%I": pad(hour12),
1779
+ "%M": minutes,
1780
+ "%S": seconds,
1781
+ "%p": period,
1782
+ "%P": period.toLowerCase(),
1783
+ "%R": `${hours}:${minutes}`,
1784
+ "%T": `${hours}:${minutes}:${seconds}`,
1785
+ // Jiff's %r uses an unpadded 12-hour value.
1786
+ "%r": `${hour12}:${minutes}:${seconds} ${period}`,
1787
+ "%Y": parts.year.toString().padStart(4, "0"),
1788
+ "%m": pad(parts.month),
1789
+ "%d": pad(parts.day),
1790
+ "%F": date,
1791
+ "%z": offsetText(parts.offsetSeconds, ""),
1792
+ "%:z": offsetText(parts.offsetSeconds, ":")
1793
+ };
1794
+ return format.replace(FORMAT_TOKEN, (token) => tokens[token] ?? token);
1795
+ }
1796
+ function validTimeFormat(format) {
1797
+ return typeof format === "string" && format.length > 0 && format.length <= MAX_TIME_FORMAT_LENGTH && !format.replace(FORMAT_TOKEN, "").includes("%");
1798
+ }
1799
+ function isInsideTimeRange(now, range) {
1800
+ if (typeof range !== "string" || range.length > MAX_TIME_RANGE_LENGTH) return true;
1801
+ const endpoints = range.split("-");
1802
+ if (endpoints.length !== 2) return true;
1803
+ const start = parseRangeEndpoint(endpoints[0] ?? "");
1804
+ const end = parseRangeEndpoint(endpoints[1] ?? "");
1805
+ const current = ((now.getHours() * 60 + now.getMinutes()) * 60 + now.getSeconds()) * 1e3 + now.getMilliseconds();
1806
+ if (start === void 0 && end === void 0) return true;
1807
+ if (start === void 0) return current < end;
1808
+ if (end === void 0) return current > start;
1809
+ return start < end ? current > start && current < end : current > start || current < end;
1810
+ }
1811
+ function parseRangeEndpoint(value) {
1812
+ const match = /^(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?$/u.exec(value);
1813
+ if (!match) return void 0;
1814
+ const hour = Number(match[1]);
1815
+ const minute = Number(match[2]);
1816
+ const second = Number(match[3] ?? 0);
1817
+ if (hour > 23 || minute > 59 || second > 59) return void 0;
1818
+ return ((hour * 60 + minute) * 60 + second) * 1e3 + Number((match[4] ?? "").padEnd(3, "0"));
1819
+ }
1820
+ function clockParts(now, zone) {
1821
+ if (typeof zone !== "string" || zone === "local" || zone.length > MAX_TIME_ZONE_LENGTH) return localParts(now);
1822
+ if (/^[+-]?\d{1,2}(?:\.\d{1,6})?$/u.test(zone)) {
1823
+ const hours = Number(zone);
1824
+ if (hours > -24 && hours < 24) {
1825
+ const offsetSeconds = Math.trunc(hours * 3600);
1826
+ const shifted = new Date(now.getTime() + offsetSeconds * 1e3);
1827
+ return {
1828
+ year: shifted.getUTCFullYear(),
1829
+ month: shifted.getUTCMonth() + 1,
1830
+ day: shifted.getUTCDate(),
1831
+ hour: shifted.getUTCHours(),
1832
+ minute: shifted.getUTCMinutes(),
1833
+ second: shifted.getUTCSeconds(),
1834
+ offsetSeconds
1835
+ };
1836
+ }
1837
+ return localParts(now);
1838
+ }
1839
+ if (!/^(?:UTC|[A-Za-z_]+(?:\/[A-Za-z0-9_+.-]+)+)$/u.test(zone)) return localParts(now);
1840
+ try {
1841
+ if (cachedZone?.name !== zone) {
1842
+ cachedZone = {
1843
+ name: zone,
1844
+ formatter: new Intl.DateTimeFormat("en-US", {
1845
+ timeZone: zone,
1846
+ calendar: "iso8601",
1847
+ numberingSystem: "latn",
1848
+ year: "numeric",
1849
+ month: "2-digit",
1850
+ day: "2-digit",
1851
+ hour: "2-digit",
1852
+ minute: "2-digit",
1853
+ second: "2-digit",
1854
+ hourCycle: "h23"
1855
+ })
1856
+ };
1857
+ }
1858
+ const values = Object.fromEntries(cachedZone.formatter.formatToParts(now).map(({ type, value }) => [type, value]));
1859
+ const parts = {
1860
+ year: Number(values.year),
1861
+ month: Number(values.month),
1862
+ day: Number(values.day),
1863
+ hour: Number(values.hour),
1864
+ minute: Number(values.minute),
1865
+ second: Number(values.second)
1866
+ };
1867
+ const wallTime = /* @__PURE__ */ new Date(0);
1868
+ wallTime.setUTCFullYear(parts.year, parts.month - 1, parts.day);
1869
+ wallTime.setUTCHours(parts.hour, parts.minute, parts.second, 0);
1870
+ return {
1871
+ ...parts,
1872
+ offsetSeconds: (wallTime.getTime() - Math.floor(now.getTime() / 1e3) * 1e3) / 1e3
1873
+ };
1874
+ } catch {
1875
+ return localParts(now);
1876
+ }
1877
+ }
1878
+ function localParts(now) {
1879
+ return {
1880
+ year: now.getFullYear(),
1881
+ month: now.getMonth() + 1,
1882
+ day: now.getDate(),
1883
+ hour: now.getHours(),
1884
+ minute: now.getMinutes(),
1885
+ second: now.getSeconds(),
1886
+ offsetSeconds: -now.getTimezoneOffset() * 60
1887
+ };
1888
+ }
1889
+ function pad(value) {
1890
+ return value.toString().padStart(2, "0");
1891
+ }
1892
+ function offsetText(seconds, separator) {
1893
+ const absolute = Math.abs(seconds);
1894
+ return `${seconds < 0 ? "-" : "+"}${pad(Math.floor(absolute / 3600))}${separator}${pad(Math.floor(absolute % 3600 / 60))}`;
1895
+ }
1896
+
1738
1897
  // src/modules/time.ts
1739
1898
  var timeModule = defineModule({
1740
1899
  name: "time",
@@ -1745,11 +1904,17 @@ var timeModule = defineModule({
1745
1904
  style: "bold yellow",
1746
1905
  disabled: false
1747
1906
  },
1748
- values: ({ runtime }) => ({ time: formatTime(runtime.now) })
1907
+ options: {
1908
+ use_12hr: { kind: "boolean", default: false },
1909
+ time_format: { kind: "string", default: "", allowEmpty: true },
1910
+ utc_time_offset: { kind: "string", default: "local" },
1911
+ time_range: { kind: "string", default: "-", allowEmpty: true }
1912
+ },
1913
+ values: ({ runtime, options }) => {
1914
+ const time = formatClockTime(runtime.now, options);
1915
+ return time === void 0 ? void 0 : { time };
1916
+ }
1749
1917
  });
1750
- function formatTime(now) {
1751
- return `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}`;
1752
- }
1753
1918
 
1754
1919
  // src/modules/tokens.ts
1755
1920
  var tokensModule = defineModule({
@@ -1795,12 +1960,14 @@ var MODULE_IMPLEMENTATIONS = [
1795
1960
  gitStateModule,
1796
1961
  gitMetricsModule,
1797
1962
  gitStatusModule,
1963
+ ...jujutsuModules,
1798
1964
  packageModule,
1799
1965
  ...languageModules,
1800
1966
  ...developmentModules,
1801
1967
  ...deploymentModules,
1802
1968
  ...cloudModules,
1803
1969
  ...executionModules,
1970
+ ...systemModules,
1804
1971
  activityModule,
1805
1972
  contextModule,
1806
1973
  tokensModule,
@@ -1816,6 +1983,7 @@ var MODULE_DESCRIPTIONS = {
1816
1983
  activity: "Current Pi activity, extension UI wait, or most recently completed tool.",
1817
1984
  aws: "Active AWS profile and region.",
1818
1985
  azure: "Active Azure subscription and optional username.",
1986
+ battery: "Local battery charge and charging state on supported platforms.",
1819
1987
  brand: "pi-starship brand mark.",
1820
1988
  bun: "Bun version detected in the current workspace.",
1821
1989
  cache: "Prompt-cache usage and latest cache hit rate.",
@@ -1840,7 +2008,12 @@ var MODULE_DESCRIPTIONS = {
1840
2008
  golang: "Go version detected in the current workspace.",
1841
2009
  guix_shell: "Current Guix shell state.",
1842
2010
  hostname: "Current host name, normally shown for remote sessions.",
2011
+ jj_bookmark: "Closest ancestor bookmark in the current Jujutsu repository.",
2012
+ jj_change: "Current Jujutsu change and commit identity.",
2013
+ jj_metrics: "Added and deleted lines in the current Jujutsu change.",
2014
+ jj_status: "Current Jujutsu change status.",
1843
2015
  kubernetes: "Active Kubernetes context, namespace, cluster, and user.",
2016
+ memory_usage: "Current system memory and available swap usage.",
1844
2017
  mise: "Current mise configuration health.",
1845
2018
  model: "Current Pi model.",
1846
2019
  nix_shell: "Current Nix shell state, name, and nesting level.",
@@ -2160,7 +2333,18 @@ function normalizeModule(name, value, config, diagnostics) {
2160
2333
  }
2161
2334
  for (const [key, schema] of Object.entries(optionSchemas)) {
2162
2335
  if (value[key] === void 0) continue;
2163
- const normalized = normalizeModuleOption(value[key], schema);
2336
+ const normalized = normalizeModuleOption(value[key], schema, activePalette(config));
2337
+ if (normalized.ok && name === "directory" && key === "repo_root_format" && typeof normalized.value === "string") {
2338
+ try {
2339
+ const ast = parseFormat(normalized.value);
2340
+ if (normalized.value.length > 4096 || [...formatVariables(ast)].some((variable) => !definition.variables.includes(variable)) || [...styleVariables(ast)].some((variable) => !definition.styleVariables?.includes(variable)))
2341
+ throw new Error("Unknown format variable");
2342
+ validateLiteralStyles(ast, activePalette(config), `${name}.${key}`, diagnostics);
2343
+ } catch {
2344
+ diagnostics.push(diagnostic("warning", `${name}.${key}`, "Invalid repository-root format; using the default"));
2345
+ continue;
2346
+ }
2347
+ }
2164
2348
  if (normalized.ok) module.options[key] = normalized.value;
2165
2349
  else diagnostics.push(diagnostic("warning", `${name}.${key}`, normalized.message));
2166
2350
  }
@@ -2455,48 +2639,11 @@ function validateLiteralStyles(ast, palette, path, diagnostics) {
2455
2639
  }
2456
2640
  }
2457
2641
  }
2458
- function normalizeModuleOption(value, schema) {
2459
- switch (schema.kind) {
2460
- case "string":
2461
- return typeof value === "string" && (schema.allowEmpty !== false || value.length > 0) ? { ok: true, value } : { ok: false, message: "Expected a non-empty string; using the default value" };
2462
- case "string-enum":
2463
- return typeof value === "string" && schema.values.includes(value) ? { ok: true, value } : {
2464
- ok: false,
2465
- message: `Expected one of: ${schema.values.join(", ")}; using the default value`
2466
- };
2467
- case "boolean":
2468
- return typeof value === "boolean" ? { ok: true, value } : { ok: false, message: "Expected boolean; using the default value" };
2469
- case "integer":
2470
- return typeof value === "number" && Number.isInteger(value) && value >= schema.minimum && value <= schema.maximum ? { ok: true, value } : {
2471
- ok: false,
2472
- message: `Expected an integer from ${schema.minimum} through ${schema.maximum}; using the default value`
2473
- };
2474
- case "string-array": {
2475
- if (!Array.isArray(value) || value.some(
2476
- (item) => typeof item !== "string" || item.length === 0 || !schema.allowNegative && item.startsWith("!")
2477
- )) {
2478
- return {
2479
- ok: false,
2480
- message: "Expected an array of valid strings; using the default value"
2481
- };
2482
- }
2483
- return { ok: true, value: [...value] };
2484
- }
2485
- case "string-map": {
2486
- if (!isRecord(value) || Object.values(value).some((item) => typeof item !== "string")) {
2487
- return { ok: false, message: "Expected a table of strings; using the default value" };
2488
- }
2489
- const result = {};
2490
- for (const [key, item] of Object.entries(value)) setOwn(result, key, item);
2491
- return { ok: true, value: result };
2492
- }
2493
- }
2494
- }
2495
2642
  function cloneOptionValue(value) {
2496
2643
  return typeof value === "object" ? structuredClone(value) : value;
2497
2644
  }
2498
- function setOwn(record, key, value) {
2499
- Object.defineProperty(record, key, {
2645
+ function setOwn(record2, key, value) {
2646
+ Object.defineProperty(record2, key, {
2500
2647
  value,
2501
2648
  writable: true,
2502
2649
  enumerable: true,
@@ -2534,302 +2681,10 @@ function ownPalette(palettes, name) {
2534
2681
  return name !== void 0 && Object.hasOwn(palettes, name) ? palettes[name] : void 0;
2535
2682
  }
2536
2683
 
2537
- // src/modules/inspection.ts
2538
- import { stripVTControlCharacters } from "node:util";
2539
-
2540
- // src/modules/render.ts
2541
- import { visibleWidth as visibleWidth2 } from "@earendil-works/pi-tui";
2542
- import { sanitizeTerminalText as sanitizeTerminalText5 } from "@narumitw/pi-tui-kit/terminal-text";
2543
-
2544
- // src/modules/style-rules.ts
2545
- function resolveStyleRule(rules, selectors, context) {
2546
- for (const rule of rules) {
2547
- let matches = true;
2548
- for (const name in rule.selectors) {
2549
- if (!Object.hasOwn(rule.selectors, name)) continue;
2550
- const selector = Object.hasOwn(selectors, name) ? selectors[name] : void 0;
2551
- if (!selector || selector(context) !== rule.selectors[name]) {
2552
- matches = false;
2553
- break;
2554
- }
2555
- }
2556
- if (matches) return rule.style;
2557
- }
2558
- return void 0;
2559
- }
2560
-
2561
- // src/modules/render.ts
2562
- function renderStatusline(config, runtime, width = 80, trueColor = true, themeColors) {
2563
- const palette = activePalette(config);
2564
- const modules = {};
2565
- const layoutModules = {};
2566
- for (const name of MODULE_NAMES) {
2567
- modules[name] = [];
2568
- layoutModules[name] = [];
2569
- }
2570
- for (const definition of MODULE_DEFINITIONS) {
2571
- const name = definition.name;
2572
- const module = config.modules[name];
2573
- const values = definition.values(valueContext(config, name, runtime, palette));
2574
- if (!values) continue;
2575
- const styleContext = {
2576
- runtime,
2577
- style: module.style,
2578
- styles: module.styles,
2579
- display: module.display
2580
- };
2581
- const baseStyleVariables = definition.resolveStyleVariables ? definition.resolveStyleVariables(styleContext) : { style: module.style };
2582
- if (!baseStyleVariables) continue;
2583
- const ruleStyle = definition.styleRuleSelectors ? resolveStyleRule(module.styleRules, definition.styleRuleSelectors, styleContext) : void 0;
2584
- const styleVariables2 = ruleStyle === void 0 ? baseStyleVariables : { ...baseStyleVariables, style: ruleStyle };
2585
- const contentValues = Object.fromEntries(
2586
- definition.variables.flatMap(
2587
- (variable) => variable !== "symbol" && Object.hasOwn(values, variable) ? [[variable, values[variable]]] : []
2588
- )
2589
- );
2590
- const rendered = renderModule(module, contentValues, styleVariables2, palette);
2591
- modules[name] = rendered;
2592
- layoutModules[name] = definition.layout === "fill" && !module.disabled ? [{ type: "fill", pattern: rendered }] : rendered;
2593
- }
2594
- const explicitModules = formatVariables(config.formatAst);
2595
- const all = MODULE_NAMES.flatMap(
2596
- (name) => explicitModules.has(name) || config.modules[name].disabled ? [] : layoutModules[name]
2597
- );
2598
- const rootVariables = { all };
2599
- for (const name of MODULE_NAMES) rootVariables[name] = layoutModules[name];
2600
- const layout = renderFormat(config.formatAst, { variables: rootVariables, palette });
2601
- const chunks = resolveFillLayout(layout, width);
2602
- return {
2603
- ansi: renderChunksToAnsi(chunks, trueColor, themeColors),
2604
- chunks,
2605
- modules
2606
- };
2607
- }
2608
- function valueContext(config, name, runtime, palette) {
2609
- return {
2610
- runtime: runtimeForDisplay(name, runtime),
2611
- palette,
2612
- symbol: sanitizeFormatText(config.modules[name].symbol),
2613
- options: Object.fromEntries(
2614
- Object.entries(config.modules[name].options).map(([key, value]) => [
2615
- key,
2616
- typeof value === "string" ? sanitizeTerminalText5(value) : Array.isArray(value) ? value.map(sanitizeTerminalText5) : value && typeof value === "object" ? sanitizeFields(value) : value
2617
- ])
2618
- ),
2619
- extensionStatus: {
2620
- ...config.extensionStatus,
2621
- separator: sanitizeFormatText(config.extensionStatus.separator),
2622
- icons: Object.fromEntries(
2623
- Object.entries(config.extensionStatus.icons).map(([key, value]) => [key, sanitizeFormatText(value)])
2624
- )
2625
- }
2626
- };
2627
- }
2628
- function sanitizeFields(value) {
2629
- return Object.fromEntries(
2630
- Object.entries(value).map(([key, item]) => [key, typeof item === "string" ? sanitizeTerminalText5(item) : item])
2631
- );
2632
- }
2633
- function runtimeForDisplay(name, runtime) {
2634
- switch (name) {
2635
- case "directory":
2636
- return {
2637
- ...runtime,
2638
- ...sanitizeFields({ cwd: runtime.cwd, homeDir: runtime.homeDir, gitRoot: runtime.gitRoot })
2639
- };
2640
- case "git_branch":
2641
- return {
2642
- ...runtime,
2643
- gitBranch: runtime.gitBranch === null ? null : sanitizeTerminalText5(runtime.gitBranch),
2644
- gitBranchDetails: runtime.gitBranchDetails ? sanitizeFields(runtime.gitBranchDetails) : void 0
2645
- };
2646
- case "git_commit":
2647
- return { ...runtime, gitCommit: runtime.gitCommit ? sanitizeFields(runtime.gitCommit) : void 0 };
2648
- case "conda": {
2649
- const values = runtime.workspace?.modules.conda;
2650
- return values && runtime.workspace ? {
2651
- ...runtime,
2652
- workspace: {
2653
- ...runtime.workspace,
2654
- modules: { ...runtime.workspace.modules, conda: sanitizeFields(values) }
2655
- }
2656
- } : runtime;
2657
- }
2658
- case "extension_status":
2659
- return {
2660
- ...runtime,
2661
- extensionStatuses: new Map(
2662
- [...runtime.extensionStatuses].map(([key, value]) => [key, sanitizeTerminalText5(value)])
2663
- )
2664
- };
2665
- default:
2666
- return runtime;
2667
- }
2668
- }
2669
- function renderModule(module, values, styleVariables2, palette) {
2670
- if (module.disabled) return [];
2671
- return renderFormat(module.formatAst, {
2672
- variables: { symbol: module.symbol, ...values },
2673
- styleVariables: styleVariables2,
2674
- palette
2675
- }).filter((chunk) => !isFillChunk(chunk));
2676
- }
2677
- function reachableModuleRequirements(config) {
2678
- const rootVariables = formatVariables(config.formatAst);
2679
- const includeAll = rootVariables.has("all");
2680
- const requirements = /* @__PURE__ */ new Map();
2681
- for (const definition of MODULE_DEFINITIONS) {
2682
- if (config.modules[definition.name].disabled) continue;
2683
- if (!includeAll && !rootVariables.has(definition.name)) continue;
2684
- requirements.set(definition.name, formatVariables(config.modules[definition.name].formatAst));
2685
- }
2686
- return requirements;
2687
- }
2688
- function resolveFillLayout(layout, width) {
2689
- const lines = splitLogicalLines(layout);
2690
- const resolved = [];
2691
- for (const [lineIndex, line] of lines.entries()) {
2692
- const fills = line.filter(isFillChunk);
2693
- const fixedWidth = line.reduce(
2694
- (total, chunk) => total + (isFillChunk(chunk) ? 0 : visibleWidth2(renderChunksToAnsi([chunk]))),
2695
- 0
2696
- );
2697
- const remaining = Math.max(0, width - fixedWidth);
2698
- const base = fills.length > 0 ? Math.floor(remaining / fills.length) : 0;
2699
- let remainder = fills.length > 0 ? remaining % fills.length : 0;
2700
- for (const chunk of line) {
2701
- if (!isFillChunk(chunk)) {
2702
- resolved.push(chunk);
2703
- continue;
2704
- }
2705
- const allocation = base + (remainder > 0 ? 1 : 0);
2706
- if (remainder > 0) remainder -= 1;
2707
- resolved.push(...expandFill(chunk.pattern, allocation));
2708
- }
2709
- if (lineIndex < lines.length - 1) resolved.push({ text: "\n" });
2710
- }
2711
- return resolved;
2712
- }
2713
- function splitLogicalLines(layout) {
2714
- const lines = [[]];
2715
- for (const chunk of layout) {
2716
- if (isFillChunk(chunk)) {
2717
- lines.at(-1)?.push(chunk);
2718
- continue;
2719
- }
2720
- const parts = chunk.text.split("\n");
2721
- for (const [index, text] of parts.entries()) {
2722
- if (text) lines.at(-1)?.push({ ...chunk, text });
2723
- if (index < parts.length - 1) lines.push([]);
2724
- }
2725
- }
2726
- return lines;
2727
- }
2728
- function expandFill(pattern, width) {
2729
- if (width <= 0) return [];
2730
- const patternWidth = visibleWidth2(renderChunksToAnsi(pattern));
2731
- if (patternWidth <= 0) return [{ text: " ".repeat(width), style: pattern[0]?.style }];
2732
- const repetitions = Math.floor(width / patternWidth);
2733
- const result = [];
2734
- for (let index = 0; index < repetitions; index += 1) {
2735
- result.push(...pattern.map((chunk) => ({ ...chunk })));
2736
- }
2737
- const remainder = width - repetitions * patternWidth;
2738
- if (remainder > 0) result.push({ text: " ".repeat(remainder), style: pattern.at(-1)?.style });
2739
- return result;
2740
- }
2741
-
2742
- // src/modules/inspection.ts
2743
- function inspectStatuslineModules(config, runtime, width = 80) {
2744
- const rendered = renderStatusline(config, runtime, width);
2745
- const requirements = reachableModuleRequirements(config);
2746
- const rootVariables = formatVariables(config.formatAst);
2747
- const includeAll = rootVariables.has("all");
2748
- const modules = MODULE_DEFINITIONS.map((definition) => {
2749
- const module = config.modules[definition.name];
2750
- const reachable = requirements.has(definition.name);
2751
- const preview = plainPreview(rendered.modules[definition.name].map((chunk) => chunk.text).join(""));
2752
- const state = module.disabled ? "Disabled" : !reachable ? "Not in format" : preview.length > 0 ? "Showing" : "Empty";
2753
- return moduleInspection(
2754
- config,
2755
- definition,
2756
- state,
2757
- preview,
2758
- includeAll || rootVariables.has(definition.name),
2759
- reachable
2760
- );
2761
- });
2762
- return {
2763
- modules,
2764
- showing: modules.filter((module) => module.state === "Showing")
2765
- };
2766
- }
2767
- function inspectUnavailableModules(config) {
2768
- const requirements = reachableModuleRequirements(config);
2769
- const rootVariables = formatVariables(config.formatAst);
2770
- const includeAll = rootVariables.has("all");
2771
- return {
2772
- modules: MODULE_DEFINITIONS.map((definition) => {
2773
- const module = config.modules[definition.name];
2774
- const reachable = requirements.has(definition.name);
2775
- const state = module.disabled ? "Disabled" : reachable ? "Unavailable" : "Not in format";
2776
- return moduleInspection(
2777
- config,
2778
- definition,
2779
- state,
2780
- "",
2781
- includeAll || rootVariables.has(definition.name),
2782
- reachable
2783
- );
2784
- }),
2785
- showing: []
2786
- };
2787
- }
2788
- function moduleInspection(config, definition, state, preview, rootReferenced, reachable) {
2789
- const module = config.modules[definition.name];
2790
- return {
2791
- name: definition.name,
2792
- description: definition.description,
2793
- state,
2794
- preview,
2795
- variables: [...definition.variables],
2796
- styleFields: ["style", ...Object.keys(module.styles)],
2797
- styleRuleSelectors: Object.keys(definition.styleRuleSelectors ?? {}),
2798
- styleRuleCount: module.styleRules.length,
2799
- displayRules: module.display.map(
2800
- (rule) => `${rule.threshold}: ${rule.hidden ? "hidden" : rule.style || "unstyled"}`
2801
- ),
2802
- rootReferenced,
2803
- reachable,
2804
- reason: inspectionReason(state)
2805
- };
2806
- }
2807
- function inspectionReason(state) {
2808
- switch (state) {
2809
- case "Showing":
2810
- return "Rendered in the current footer.";
2811
- case "Empty":
2812
- return "Referenced by the root format, but the current snapshot produced no output.";
2813
- case "Disabled":
2814
- return "Disabled by this module's configuration.";
2815
- case "Not in format":
2816
- return "Not referenced by the root format or $all.";
2817
- case "Unavailable":
2818
- return "Current footer inspection is unavailable; no collector failure was inferred.";
2819
- }
2820
- }
2821
- function plainPreview(value) {
2822
- return Array.from(stripVTControlCharacters(value), (character) => {
2823
- const codePoint = character.codePointAt(0) ?? 0;
2824
- if (character === "\n") return character;
2825
- return codePoint <= 31 || codePoint >= 127 && codePoint <= 159 ? " " : character;
2826
- }).join("");
2827
- }
2828
-
2829
2684
  export {
2830
- STARSHIP_SUBCOMMANDS,
2831
- completeStarshipArguments,
2685
+ directoryAlternateFormat,
2832
2686
  MODULE_DEFINITIONS,
2687
+ MODULE_NAMES,
2833
2688
  BUILT_IN_EXAMPLE,
2834
2689
  settingsFilePath,
2835
2690
  loadStarshipConfig,
@@ -2840,9 +2695,6 @@ export {
2840
2695
  atomicRestoreConfigDocument,
2841
2696
  ConfigPublicationError,
2842
2697
  removeConfigDocumentIfMatches,
2843
- renderStatusline,
2844
- reachableModuleRequirements,
2845
- inspectStatuslineModules,
2846
- inspectUnavailableModules
2698
+ activePalette
2847
2699
  };
2848
- //# sourceMappingURL=chunk-KZZKGGFW.ts.map
2700
+ //# sourceMappingURL=chunk-PWTSHSP3.ts.map