@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
@@ -0,0 +1,1022 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ captureCommitExpectation,
5
+ commitActiveDocument,
6
+ commitOwnerCurrent,
7
+ saveAsProfile,
8
+ showHistory,
9
+ showProfiles
10
+ } from "./chunk-HPZTMIZS.ts";
11
+ import {
12
+ STARSHIP_PRESETS,
13
+ configurationPresentation,
14
+ getStarshipPreset,
15
+ presetForDocument,
16
+ reloadConfiguration,
17
+ showPreviewActionMenu
18
+ } from "./chunk-43VIENBN.ts";
19
+ import {
20
+ STARSHIP_SUBCOMMANDS,
21
+ completeStarshipArguments
22
+ } from "./chunk-XQUIQO2G.ts";
23
+ import {
24
+ BUILT_IN_EXAMPLE,
25
+ atomicSaveConfigDocument,
26
+ loadStarshipConfig,
27
+ readConfigDocumentSnapshot,
28
+ validateConfigDocument
29
+ } from "./chunk-PWTSHSP3.ts";
30
+ import "./chunk-IYDZ3R2T.ts";
31
+ import "./chunk-KP33I6BR.ts";
32
+
33
+ // src/commands.ts
34
+ import { isKeyRelease, Key, matchesKey } from "@earendil-works/pi-tui";
35
+ import { defineMenu as defineMenu2, runMenu as runMenu2 } from "@narumitw/pi-tui-kit";
36
+
37
+ // src/command-gist.ts
38
+ import { defineMenu, runMenu, runTask } from "@narumitw/pi-tui-kit";
39
+ import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
40
+
41
+ // src/gist.ts
42
+ import { spawn } from "node:child_process";
43
+ var GIST_FILENAME = "pi-starship.toml";
44
+ var MAX_GIST_DOCUMENT_BYTES = 64 * 1024;
45
+ var MAX_RESPONSE_BYTES = 512 * 1024;
46
+ var REQUEST_TIMEOUT_MS = 3e4;
47
+ function gistId(value) {
48
+ const text = value.trim();
49
+ if (/^[a-f\d]{5,64}$/iu.test(text)) return text;
50
+ try {
51
+ const url = new URL(text);
52
+ const match = /^\/(?:[\w-]+\/)?([a-f\d]{5,64})\/?$/iu.exec(url.pathname);
53
+ if (url.protocol === "https:" && url.hostname === "gist.github.com" && !url.port && !url.username && !url.password && !url.search && match?.[1])
54
+ return match[1];
55
+ } catch {
56
+ }
57
+ throw new Error("Enter a github.com Gist ID or https://gist.github.com/<owner>/<id> URL.");
58
+ }
59
+ function checkGistDocument(rawDocument) {
60
+ if (!rawDocument.trim()) throw new Error("The Gist settings document is empty.");
61
+ if (Buffer.byteLength(rawDocument, "utf8") > MAX_GIST_DOCUMENT_BYTES) {
62
+ throw new Error("The Gist settings document exceeds 64 KiB.");
63
+ }
64
+ }
65
+ async function createSettingsGist(rawDocument, signal, api = executeGhApi) {
66
+ checkGistDocument(rawDocument);
67
+ const response = JSON.parse(
68
+ await api(
69
+ ["/gists", "--method", "POST", "--input", "-"],
70
+ JSON.stringify({
71
+ description: "pi-starship footer settings",
72
+ public: false,
73
+ files: { [GIST_FILENAME]: { content: rawDocument } }
74
+ }),
75
+ signal
76
+ )
77
+ );
78
+ signal.throwIfAborted();
79
+ if (!isRecord(response) || response.public !== false || typeof response.html_url !== "string") {
80
+ throw new Error("GitHub returned an invalid Gist response. Check your Gists before retrying.");
81
+ }
82
+ return `https://gist.github.com/${gistId(response.html_url)}`;
83
+ }
84
+ async function fetchSettingsGist(value, signal, api = executeGhApi) {
85
+ const id = gistId(value);
86
+ const response = JSON.parse(await api([`/gists/${id}`, "--method", "GET"], void 0, signal));
87
+ signal.throwIfAborted();
88
+ const file = isRecord(response) && isRecord(response.files) ? response.files[GIST_FILENAME] : void 0;
89
+ if (!isRecord(file) || typeof file.content !== "string" || file.truncated !== false) {
90
+ throw new Error(`The Gist must contain a complete ${GIST_FILENAME} file. Truncated files are not supported.`);
91
+ }
92
+ checkGistDocument(file.content);
93
+ return file.content;
94
+ }
95
+ function isRecord(value) {
96
+ return value !== null && typeof value === "object" && !Array.isArray(value);
97
+ }
98
+ var executeGhApi = (args, input, signal) => {
99
+ signal.throwIfAborted();
100
+ return new Promise((resolve, reject) => {
101
+ const child = spawn(process.platform === "win32" ? "gh.exe" : "gh", ["api", "--hostname", "github.com", ...args], {
102
+ env: { ...process.env, GH_PROMPT_DISABLED: "1", GH_PAGER: "", GH_DEBUG: "" },
103
+ stdio: ["pipe", "pipe", "ignore"],
104
+ windowsHide: true
105
+ });
106
+ const chunks = [];
107
+ let bytes = 0;
108
+ let failure;
109
+ const stop = (error) => {
110
+ failure ??= error;
111
+ child.kill("SIGKILL");
112
+ };
113
+ const onAbort = () => stop(new Error("Gist request cancelled."));
114
+ const timer = setTimeout(
115
+ () => stop(new Error("Gist request timed out. Check GitHub before retrying an upload.")),
116
+ REQUEST_TIMEOUT_MS
117
+ );
118
+ timer.unref();
119
+ signal.addEventListener("abort", onAbort, { once: true });
120
+ child.stdout.on("data", (chunk) => {
121
+ bytes += chunk.length;
122
+ if (bytes > MAX_RESPONSE_BYTES) stop(new Error("GitHub Gist response exceeds 512 KiB."));
123
+ else chunks.push(chunk);
124
+ });
125
+ child.stdin.on("error", () => {
126
+ stop(new Error("Unable to send settings to gh."));
127
+ });
128
+ child.on("error", () => {
129
+ failure ??= new Error("Unable to start gh. Install GitHub CLI and run gh auth login with Gist access.");
130
+ });
131
+ child.on("close", (code) => {
132
+ clearTimeout(timer);
133
+ signal.removeEventListener("abort", onAbort);
134
+ if (failure) reject(failure);
135
+ else if (code !== 0)
136
+ reject(
137
+ new Error(
138
+ "Gist request failed. Check gh auth status, Gist access, and connectivity. An upload may already exist."
139
+ )
140
+ );
141
+ else resolve(Buffer.concat(chunks).toString("utf8"));
142
+ });
143
+ if (signal.aborted) onAbort();
144
+ child.stdin.end(input);
145
+ });
146
+ };
147
+
148
+ // src/command-gist.ts
149
+ async function shareSettingsGist(ctx, options, owner, api) {
150
+ if (ctx.mode !== "tui" || !current(owner)) return "cancel";
151
+ const loaded = options.getLoaded();
152
+ if (loaded.diagnostics.some((item) => item.severity === "error")) {
153
+ ctx.ui.notify("Fix configuration errors before sharing settings.", "warning");
154
+ return "cancel";
155
+ }
156
+ const raw = loaded.rawDocument ?? BUILT_IN_EXAMPLE;
157
+ try {
158
+ checkGistDocument(raw);
159
+ } catch (error) {
160
+ ctx.ui.notify(safeError(error), "error");
161
+ return "cancel";
162
+ }
163
+ const review = await reviewDocument(
164
+ ctx,
165
+ owner,
166
+ "Share settings as Gist",
167
+ raw,
168
+ [
169
+ "Review the entire loaded document, including comments and unknown fields, for secrets and local paths.",
170
+ "No settings file is created when sharing built-in defaults."
171
+ ],
172
+ "Share unlisted Gist\u2026"
173
+ );
174
+ if (!current(owner)) return "cancel";
175
+ if (!review) return "close";
176
+ const confirmed = await ctx.ui.confirm(
177
+ "Upload settings to GitHub?",
178
+ [
179
+ "Send the reviewed pi-starship.toml to github.com as a new unlisted Gist?",
180
+ "Unlisted is not private: anyone with the link can read it. Comments and unknown fields are included.",
181
+ "Cancellation or a network error cannot undo an upload already accepted by GitHub; check your Gists before retrying."
182
+ ].join("\n"),
183
+ { signal: owner.signal }
184
+ );
185
+ if (!current(owner) || !confirmed) return "cancel";
186
+ const result = await runTask(ctx, {
187
+ label: "Sharing settings with GitHub\u2026",
188
+ signal: owner.signal,
189
+ isCurrent: owner.isCurrent,
190
+ task: ({ signal }) => createSettingsGist(raw, signal, api),
191
+ onError: () => ctx.ui.notify(
192
+ "Gist upload failed. Check gh auth status, Gist access, connectivity, and your Gists before retrying. The upload may already exist.",
193
+ "error"
194
+ )
195
+ });
196
+ if (!current(owner)) return "cancel";
197
+ if (result.kind === "completed") {
198
+ ctx.ui.notify(`Settings Gist: ${result.value}`, "info");
199
+ return "cancel";
200
+ }
201
+ return result.kind === "error" ? "cancel" : "close";
202
+ }
203
+ async function importSettingsGist(ctx, options, owner, reviewImport, api) {
204
+ if (ctx.mode !== "tui" || !current(owner)) return "cancel";
205
+ const previous = options.getLoaded();
206
+ const revision = options.getLoadedRevision?.();
207
+ const disk = diskSnapshot(options);
208
+ const initialDisk = readConfigDocumentSnapshot(options.settingsPath);
209
+ const guardedOwner = {
210
+ signal: owner.signal,
211
+ isSessionCurrent: () => owner.isSessionCurrent?.() ?? owner.isCurrent(),
212
+ isCurrent: () => current(owner) && options.getLoadedRevision?.() === revision && options.getLoaded().rawDocument === previous.rawDocument && options.getLoaded().source === previous.source
213
+ };
214
+ const value = await ctx.ui.input("Import pi-starship settings from Gist", "https://gist.github.com/<owner>/<id>", {
215
+ signal: owner.signal
216
+ });
217
+ if (!current(guardedOwner) || value === void 0) return "cancel";
218
+ let id;
219
+ try {
220
+ id = gistId(value);
221
+ } catch (error) {
222
+ ctx.ui.notify(safeError(error), "error");
223
+ return "cancel";
224
+ }
225
+ const result = await runTask(ctx, {
226
+ label: "Reading settings from GitHub\u2026",
227
+ signal: owner.signal,
228
+ isCurrent: guardedOwner.isCurrent,
229
+ task: ({ signal }) => fetchSettingsGist(id, signal, api),
230
+ onError: () => ctx.ui.notify(
231
+ "Gist import failed. Check the Gist ID, gh auth status, connectivity, and a complete pi-starship.toml file (up to 64 KiB).",
232
+ "error"
233
+ )
234
+ });
235
+ if (!current(guardedOwner)) return "cancel";
236
+ if (result.kind !== "completed") return result.kind === "error" ? "cancel" : "close";
237
+ let validated;
238
+ try {
239
+ validated = (options.validate ?? validateConfigDocument)(options.settingsPath, result.value);
240
+ } catch (error) {
241
+ ctx.ui.notify(`Gist settings are invalid: ${safeError(error)}`, "error");
242
+ return "cancel";
243
+ }
244
+ const reviewed = await reviewDocument(
245
+ ctx,
246
+ guardedOwner,
247
+ "Review Gist settings",
248
+ result.value,
249
+ [
250
+ `Source: https://gist.github.com/${id}`,
251
+ "Untrusted settings can enable local commands and network requests. Review the complete TOML before applying.",
252
+ "Import replaces the entire local document, including comments and unknown fields; its previous bytes will be kept in History."
253
+ ],
254
+ "Preview imported footer\u2026"
255
+ );
256
+ if (!current(guardedOwner)) return "cancel";
257
+ if (!reviewed) return "close";
258
+ return reviewImport(
259
+ validated,
260
+ {
261
+ ...options,
262
+ save(path, raw) {
263
+ if (!current(guardedOwner) || diskSnapshot(options) !== disk) {
264
+ throw new Error("Settings changed during import. Start a new import to review the latest state.");
265
+ }
266
+ return options.save ? options.save(path, raw) : atomicSaveConfigDocument(path, raw, {}, initialDisk);
267
+ }
268
+ },
269
+ guardedOwner
270
+ );
271
+ }
272
+ async function reviewDocument(ctx, owner, title, content, lines, label) {
273
+ let approved = false;
274
+ const menu = defineMenu({
275
+ start: "document",
276
+ screens: {
277
+ document: () => ({
278
+ kind: "review",
279
+ title,
280
+ lines,
281
+ content,
282
+ format: { kind: "code", language: "toml" },
283
+ viewportSize: "adaptive",
284
+ enableSearch: true,
285
+ confirm: { id: "continue", label, action: "continue" },
286
+ hint: "close"
287
+ })
288
+ },
289
+ actions: {
290
+ continue: () => {
291
+ approved = true;
292
+ return { kind: "close" };
293
+ }
294
+ }
295
+ });
296
+ await runMenu(ctx, menu, { getState: () => void 0, signal: owner.signal, isCurrent: owner.isCurrent });
297
+ return current(owner) && approved;
298
+ }
299
+ function diskSnapshot(options) {
300
+ const loaded = (options.read ?? loadStarshipConfig)(options.settingsPath);
301
+ return JSON.stringify([
302
+ loaded.rawDocument,
303
+ loaded.source,
304
+ loaded.diagnostics,
305
+ readConfigDocumentSnapshot(options.settingsPath)
306
+ ]);
307
+ }
308
+ function current(owner) {
309
+ return !owner.signal.aborted && owner.isCurrent();
310
+ }
311
+ function safeError(error) {
312
+ return sanitizeTerminalText(error instanceof Error ? error.message : String(error));
313
+ }
314
+
315
+ // src/command-preset-picker.ts
316
+ import { runLiveChoice } from "@narumitw/pi-tui-kit";
317
+ async function showPresetPicker(ctx, options) {
318
+ const current2 = options.presets.find((preset) => preset.id === options.activePresetId)?.label ?? "Custom configuration";
319
+ const result = await runLiveChoice(ctx, {
320
+ title: `Presets \xB7 current: ${current2}`,
321
+ items: options.presets.map((preset) => ({
322
+ id: preset.id,
323
+ label: preset.label,
324
+ description: preset.id === options.activePresetId ? `Currently applied \xB7 ${preset.description}` : preset.description,
325
+ details: [`Selected: ${preset.label} \xB7 ${preset.requiresNerdFont ? "requires Nerd Font" : "font-safe"}`],
326
+ confirmationDisabled: preset.id === options.activePresetId,
327
+ confirmationDisabledReason: "Already applied; press e to customize"
328
+ })),
329
+ currentItemId: options.activePresetId,
330
+ initialItemId: options.initialPresetId ?? options.activePresetId,
331
+ viewportSize: Math.min(options.presets.length, 10),
332
+ hint: "back",
333
+ navigationLabel: "live preview",
334
+ confirmLabel: "apply",
335
+ shortcuts: [
336
+ { id: "customize", keys: ["e", "shift+e"], label: "customize" },
337
+ { id: "save-profile", keys: ["s", "shift+s"], label: "save as profile" }
338
+ ],
339
+ onSelectionChange: ({ item }) => {
340
+ const preset = options.presets.find((candidate) => candidate.id === item.id);
341
+ if (preset) options.preview(preset);
342
+ },
343
+ signal: options.signal,
344
+ isCurrent: options.isCurrent
345
+ });
346
+ if (result.kind === "selected") return { kind: "apply", presetId: result.itemId };
347
+ if (result.kind === "shortcut") {
348
+ return { kind: result.shortcutId === "save-profile" ? "save-profile" : "customize", presetId: result.itemId };
349
+ }
350
+ if (result.kind === "closed" && result.reason === "back") return { kind: "back" };
351
+ return { kind: "close" };
352
+ }
353
+
354
+ // src/commands.ts
355
+ var MAIN_ACTIONS = {
356
+ presets: "presets",
357
+ configuration: "configuration",
358
+ help: "help",
359
+ restore: "restore",
360
+ profiles: "profiles",
361
+ chat: "settings-chat"
362
+ };
363
+ var PREVIEW_ACTIONS = {
364
+ continue: "continue",
365
+ edit: "edit",
366
+ cancel: "cancel",
367
+ saveProfile: "save-profile"
368
+ };
369
+ function registerStarshipCommand(pi, options) {
370
+ pi.registerCommand("starship", {
371
+ description: "Configure the footer with agent, presets, profiles, and recovery",
372
+ getArgumentCompletions: completeStarshipArguments,
373
+ handler: (args, ctx) => handleStarshipCommand(args, ctx, options)
374
+ });
375
+ }
376
+ async function handleStarshipCommand(args, ctx, options) {
377
+ if (ctx.mode !== "tui") return runStarshipCommand(args, ctx, options);
378
+ const base = workflowOwner(options);
379
+ if (!isCurrentOwner(base)) return;
380
+ const controller = new AbortController();
381
+ const signal = AbortSignal.any([base.signal, controller.signal]);
382
+ const owner = {
383
+ signal,
384
+ isCurrent: () => !signal.aborted && base.isCurrent(),
385
+ isSessionCurrent: () => base.isSessionCurrent?.() ?? base.isCurrent()
386
+ };
387
+ const unsubscribe = ctx.ui.onTerminalInput((data) => {
388
+ if (!isKeyRelease(data) && matchesKey(data, Key.ctrl("c"))) {
389
+ queueMicrotask(() => controller.abort());
390
+ }
391
+ return void 0;
392
+ });
393
+ let listening = true;
394
+ const release = () => {
395
+ if (!listening) return;
396
+ listening = false;
397
+ unsubscribe();
398
+ };
399
+ signal.addEventListener("abort", release, { once: true });
400
+ try {
401
+ return await runStarshipCommand(args, ctx, { ...options, getMenuOwner: () => owner });
402
+ } finally {
403
+ signal.removeEventListener("abort", release);
404
+ release();
405
+ controller.abort();
406
+ }
407
+ }
408
+ async function runStarshipCommand(args, ctx, options) {
409
+ const normalized = args.trim();
410
+ if (!normalized) {
411
+ if (ctx.mode === "tui") await showMainMenu(ctx, options);
412
+ else showHelp(ctx, options.settingsPath);
413
+ return;
414
+ }
415
+ const [subcommand = "", ...trailing] = normalized.split(/\s+/u);
416
+ const route = subcommand.toLowerCase();
417
+ if (trailing.length > 0 || !STARSHIP_SUBCOMMANDS.some((item) => item.value === route)) {
418
+ if (canNotify(ctx)) {
419
+ const reason = trailing.length > 0 ? `Unexpected arguments for /starship ${safeText(route)}.` : `Unknown /starship subcommand: ${safeText(route)}.`;
420
+ ctx.ui.notify(`${reason} Usage: /starship [settings|status|help]`, "warning");
421
+ }
422
+ return;
423
+ }
424
+ switch (route) {
425
+ case "settings":
426
+ await editSettings(ctx, options);
427
+ return;
428
+ case "status":
429
+ showStatus(ctx, options);
430
+ return;
431
+ case "help":
432
+ showHelp(ctx, options.settingsPath);
433
+ return;
434
+ }
435
+ }
436
+ async function showMainMenu(ctx, options) {
437
+ const fallbackController = new AbortController();
438
+ const owner = options.getMenuOwner?.() ?? {
439
+ signal: fallbackController.signal,
440
+ isCurrent: () => !fallbackController.signal.aborted
441
+ };
442
+ const menu = defineMenu2({
443
+ start: "main",
444
+ screens: {
445
+ main: () => {
446
+ const loaded = options.getLoaded();
447
+ const presentation = configurationPresentation(loaded);
448
+ return {
449
+ kind: "actions",
450
+ title: "pi-starship",
451
+ lines: [
452
+ `${presentation.state} \xB7 ${presentation.health}`,
453
+ "Configure with agent for edits, module questions, and footer explanations."
454
+ ],
455
+ items: [
456
+ {
457
+ id: MAIN_ACTIONS.chat,
458
+ label: "Configure with agent",
459
+ description: "Separate conversation \xB7 draft tools \xB7 live preview only until you save",
460
+ action: "settings-chat"
461
+ },
462
+ {
463
+ id: MAIN_ACTIONS.presets,
464
+ label: "Presets",
465
+ description: "Browse and live-preview bundled footer starting points",
466
+ action: "presets"
467
+ },
468
+ {
469
+ id: MAIN_ACTIONS.profiles,
470
+ label: "Profiles",
471
+ description: "Save, edit, manage, and live-preview named TOML documents",
472
+ action: "profiles"
473
+ },
474
+ {
475
+ id: MAIN_ACTIONS.configuration,
476
+ label: "Configuration",
477
+ description: presentation.health,
478
+ action: "configuration"
479
+ },
480
+ {
481
+ id: MAIN_ACTIONS.restore,
482
+ label: "Restore built-in\u2026",
483
+ description: presentation.restoreDescription,
484
+ disabled: presentation.restoreDisabled,
485
+ action: "restore"
486
+ },
487
+ {
488
+ id: MAIN_ACTIONS.help,
489
+ label: "Help",
490
+ description: "Settings, modules, and commands",
491
+ to: "help"
492
+ }
493
+ ],
494
+ hint: "close"
495
+ };
496
+ },
497
+ help: () => ({
498
+ kind: "detail",
499
+ title: "pi-starship help",
500
+ lines: [
501
+ "/starship settings retains the TOML editor with preview and confirmation.",
502
+ "Configure with agent opens a separate skill-backed chat; edits preview only until you explicitly save.",
503
+ "Presets live-previews the cursor in the footer; Enter confirms apply, e customizes, and s saves a profile when available.",
504
+ "Profiles manages named TOML copies; selecting a document previews it without saving.",
505
+ "Configuration History reviews and restores recovery copies; external edits are not fully tracked.",
506
+ "Ask Configure with agent about active settings and module states captured when the chat opens.",
507
+ "Configuration includes disk reload plus unlisted Gist sharing and reviewed Gist import through gh.",
508
+ `Settings: ${safeText(options.settingsPath)}`,
509
+ "Docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship"
510
+ ],
511
+ hint: "back"
512
+ })
513
+ },
514
+ actions: {
515
+ "settings-chat": async () => {
516
+ const { showSettingsAgentChat } = await import("./command-settings-chat-O34BEU4X.ts");
517
+ if (!isCurrentOwner(owner)) return { kind: "close" };
518
+ await showSettingsAgentChat(ctx, options, owner);
519
+ return { kind: "close" };
520
+ },
521
+ configuration: async () => {
522
+ const { showConfigurationMenu } = await import("./command-configuration-menu-S2LXCOJG.ts");
523
+ if (!isCurrentOwner(owner)) return { kind: "close" };
524
+ let selected;
525
+ while (isCurrentOwner(owner)) {
526
+ const result = await showConfigurationMenu(ctx, options, owner, selected);
527
+ if (!isCurrentOwner(owner) || result.kind !== "completed") return { kind: "close" };
528
+ if (result.value === "back") return { kind: "stay" };
529
+ if (result.value === "close") return { kind: "close" };
530
+ selected = result.value;
531
+ const transition = await menu.actions[result.value]({
532
+ ctx,
533
+ state: void 0,
534
+ signal: owner.signal,
535
+ itemId: result.value
536
+ });
537
+ if (!isCurrentOwner(owner) || transition?.kind === "close") return { kind: "close" };
538
+ }
539
+ return { kind: "close" };
540
+ },
541
+ presets: async () => {
542
+ const result = await choosePreset(ctx, options, owner);
543
+ return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
544
+ },
545
+ profiles: async () => {
546
+ const result = await showProfiles(ctx, options, owner, async (loaded, guardedOwner, checkCandidate, name) => {
547
+ const applied = await reviewAndApply(
548
+ ctx,
549
+ options,
550
+ loaded,
551
+ { kind: "profile", name },
552
+ guardedOwner,
553
+ false,
554
+ checkCandidate
555
+ );
556
+ return applied === "applied" ? "applied" : applied === "close" ? "close" : "stay";
557
+ });
558
+ return result === "close" ? { kind: "close" } : { kind: "stay" };
559
+ },
560
+ history: async () => {
561
+ const result = await showHistory(ctx, options, owner, async (loaded, guardedOwner, checkCandidate, name) => {
562
+ const applied = await reviewAndApply(
563
+ ctx,
564
+ options,
565
+ loaded,
566
+ { kind: "history", name },
567
+ guardedOwner,
568
+ false,
569
+ checkCandidate
570
+ );
571
+ return applied === "applied" ? "applied" : applied === "close" ? "close" : "stay";
572
+ });
573
+ return result === "close" ? { kind: "close" } : { kind: "stay" };
574
+ },
575
+ "gist-share": async () => {
576
+ const result = await shareSettingsGist(ctx, options, owner, options.gistApi);
577
+ return result === "close" ? { kind: "close" } : { kind: "stay" };
578
+ },
579
+ "gist-import": async () => {
580
+ const result = await importSettingsGist(
581
+ ctx,
582
+ options,
583
+ owner,
584
+ async (loaded, guardedOptions, guardedOwner) => {
585
+ const applied = await reviewAndApply(ctx, guardedOptions, loaded, { kind: "import" }, guardedOwner);
586
+ return applied === "edit" ? "cancel" : applied;
587
+ },
588
+ options.gistApi
589
+ );
590
+ return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
591
+ },
592
+ "configuration-reload": async () => {
593
+ const result = await reloadConfiguration(ctx, options, owner);
594
+ return result === "close" ? { kind: "close" } : { kind: "stay" };
595
+ },
596
+ restore: async () => {
597
+ const presentation = configurationPresentation(options.getLoaded());
598
+ if (presentation.restoreDisabled) {
599
+ ctx.ui.notify(presentation.restoreDescription, "info");
600
+ return { kind: "stay" };
601
+ }
602
+ const result = await restoreBuiltIn(ctx, options);
603
+ return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
604
+ }
605
+ }
606
+ });
607
+ try {
608
+ await runMenu2(ctx, menu, {
609
+ getState: () => void 0,
610
+ signal: owner.signal,
611
+ isCurrent: owner.isCurrent
612
+ });
613
+ } finally {
614
+ fallbackController.abort(new DOMException("Starship menu closed", "AbortError"));
615
+ }
616
+ }
617
+ async function editSettings(ctx, options) {
618
+ const owner = workflowOwner(options);
619
+ if (!isCurrentOwner(owner)) return "cancel";
620
+ if (ctx.mode !== "tui") {
621
+ if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${options.settingsPath}`, "info");
622
+ return "cancel";
623
+ }
624
+ const expected = captureExpectation(ctx, options);
625
+ if (!expected) return "cancel";
626
+ let draft = expected.previous.rawDocument ?? BUILT_IN_EXAMPLE;
627
+ while (true) {
628
+ const edited = await ctx.ui.editor("Customize footer \u2014 close to preview", draft);
629
+ if (!commitOwnerCurrent(options, owner, expected) || edited === void 0) return "cancel";
630
+ draft = edited;
631
+ let validated;
632
+ try {
633
+ validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
634
+ } catch (error) {
635
+ ctx.ui.notify(`Footer draft is invalid: ${safeText(formatError(error))}`, "error");
636
+ const action = await showPreviewActionMenu(
637
+ ctx,
638
+ "Configuration needs attention",
639
+ () => [safeText(formatError(error)), "The current footer has not changed."],
640
+ [
641
+ { value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
642
+ { value: PREVIEW_ACTIONS.cancel, label: "Discard draft" }
643
+ ],
644
+ owner.signal,
645
+ owner.isCurrent
646
+ );
647
+ if (!commitOwnerCurrent(options, owner, expected)) return "cancel";
648
+ if (action?.kind === "closed") return "close";
649
+ if (selectedPreviewAction(action) === PREVIEW_ACTIONS.edit) continue;
650
+ return "cancel";
651
+ }
652
+ const result = await reviewAndApply(
653
+ ctx,
654
+ options,
655
+ validated,
656
+ { kind: "customize" },
657
+ owner,
658
+ false,
659
+ void 0,
660
+ expected
661
+ );
662
+ if (result === "edit") continue;
663
+ return result;
664
+ }
665
+ }
666
+ async function choosePreset(ctx, options, owner) {
667
+ const expected = captureExpectation(ctx, options);
668
+ if (!expected) return "cancel";
669
+ const activePreset = presetForDocument(expected.previous.rawDocument);
670
+ const selection = await showPresetPicker(ctx, {
671
+ presets: STARSHIP_PRESETS,
672
+ activePresetId: activePreset?.id,
673
+ initialPresetId: activePreset?.id ?? STARSHIP_PRESETS[0]?.id,
674
+ signal: owner.signal,
675
+ isCurrent: owner.isCurrent,
676
+ preview(preset2) {
677
+ const loaded = (options.validate ?? validateConfigDocument)(options.settingsPath, preset2.rawDocument);
678
+ options.preview?.(loaded, ctx);
679
+ }
680
+ });
681
+ if (!commitOwnerCurrent(options, owner, expected)) {
682
+ clearSessionPreview(ctx, options, owner);
683
+ return "cancel";
684
+ }
685
+ if (selection.kind === "back" || selection.kind === "close") {
686
+ clearSessionPreview(ctx, options, owner);
687
+ return selection.kind === "close" ? "close" : "cancel";
688
+ }
689
+ const preset = getStarshipPreset(selection.presetId);
690
+ try {
691
+ if (selection.kind === "save-profile") {
692
+ const saved = await saveAsProfile(ctx, options, owner, preset.rawDocument);
693
+ return saved === "close" ? "close" : "cancel";
694
+ }
695
+ return await applyPreset(
696
+ ctx,
697
+ options,
698
+ preset,
699
+ selection.kind === "customize" ? "customize" : "confirm",
700
+ expected,
701
+ owner
702
+ );
703
+ } finally {
704
+ clearSessionPreview(ctx, options, owner);
705
+ }
706
+ }
707
+ async function applyPreset(ctx, options, preset, start = "review", captured, capturedOwner) {
708
+ const owner = capturedOwner ?? workflowOwner(options);
709
+ if (!isCurrentOwner(owner)) return "cancel";
710
+ const expected = captured ?? captureExpectation(ctx, options);
711
+ if (!expected) return "cancel";
712
+ let draft = preset.rawDocument;
713
+ if (start === "customize") {
714
+ const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
715
+ if (!commitOwnerCurrent(options, owner, expected) || edited === void 0) return "cancel";
716
+ draft = edited;
717
+ }
718
+ while (true) {
719
+ let validated;
720
+ try {
721
+ validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
722
+ } catch (error) {
723
+ ctx.ui.notify(`Preset draft is invalid: ${safeText(formatError(error))}`, "error");
724
+ const action = await showPreviewActionMenu(
725
+ ctx,
726
+ "Preset needs attention",
727
+ () => [safeText(formatError(error)), "The current footer has not changed."],
728
+ [
729
+ { value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
730
+ { value: PREVIEW_ACTIONS.cancel, label: "Choose another preset" }
731
+ ],
732
+ owner.signal,
733
+ owner.isCurrent
734
+ );
735
+ if (!commitOwnerCurrent(options, owner, expected)) return "cancel";
736
+ if (action?.kind === "closed") return "close";
737
+ if (selectedPreviewAction(action) !== PREVIEW_ACTIONS.edit) return "cancel";
738
+ const edited2 = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
739
+ if (!commitOwnerCurrent(options, owner, expected) || edited2 === void 0) return "cancel";
740
+ draft = edited2;
741
+ continue;
742
+ }
743
+ const result = await reviewAndApply(
744
+ ctx,
745
+ options,
746
+ validated,
747
+ { kind: "preset", preset },
748
+ owner,
749
+ start === "confirm",
750
+ void 0,
751
+ expected
752
+ );
753
+ if (result !== "edit") return result;
754
+ const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
755
+ if (!commitOwnerCurrent(options, owner, expected) || edited === void 0) return "cancel";
756
+ draft = edited;
757
+ }
758
+ }
759
+ async function restoreBuiltIn(ctx, options) {
760
+ const owner = workflowOwner(options);
761
+ if (!isCurrentOwner(owner)) return "cancel";
762
+ const validated = (options.validate ?? validateConfigDocument)(options.settingsPath, BUILT_IN_EXAMPLE);
763
+ const result = await reviewAndApply(ctx, options, validated, { kind: "restore" }, owner);
764
+ return result === "edit" ? "cancel" : result;
765
+ }
766
+ async function reviewAndApply(ctx, options, validated, intent, owner, skipReview = false, checkCandidate, captured) {
767
+ if (ctx.mode !== "tui" || !isCurrentOwner(owner)) return "cancel";
768
+ const expected = captured ?? captureExpectation(ctx, options);
769
+ if (!expected) return "cancel";
770
+ let reviewRequired = !skipReview;
771
+ while (true) {
772
+ const directAttempt = !reviewRequired;
773
+ if (reviewRequired) {
774
+ const selection = await showPreviewActionMenu(
775
+ ctx,
776
+ reviewTitle(intent),
777
+ (width) => reviewPreviewBody(ctx, options, validated, width, intent),
778
+ [
779
+ { value: PREVIEW_ACTIONS.continue, label: continueLabel(intent) },
780
+ ...intent.kind !== "customize" && intent.kind !== "preset" ? [] : [
781
+ {
782
+ value: PREVIEW_ACTIONS.edit,
783
+ label: intent.kind === "preset" ? "Customize before applying" : "Continue editing"
784
+ }
785
+ ],
786
+ {
787
+ value: PREVIEW_ACTIONS.cancel,
788
+ label: intent.kind === "restore" ? "Cancel" : intent.kind === "preset" ? "Choose another preset" : "Discard draft"
789
+ },
790
+ ...intent.kind === "customize" || intent.kind === "preset" || intent.kind === "import" ? [{ value: PREVIEW_ACTIONS.saveProfile, label: "Save as profile\u2026" }] : []
791
+ ],
792
+ owner.signal,
793
+ owner.isCurrent
794
+ );
795
+ if (!commitOwnerCurrent(options, owner, expected)) return "cancel";
796
+ if (selection?.kind === "closed") return "close";
797
+ const selected = selectedPreviewAction(selection);
798
+ if (selected === PREVIEW_ACTIONS.edit) return "edit";
799
+ if (selected === PREVIEW_ACTIONS.saveProfile) {
800
+ const saved = await saveAsProfile(ctx, options, owner, validated.rawDocument ?? BUILT_IN_EXAMPLE);
801
+ if (saved === "close") return "close";
802
+ if (!commitOwnerCurrent(options, owner, expected)) return "cancel";
803
+ continue;
804
+ }
805
+ if (selected !== PREVIEW_ACTIONS.continue) return "cancel";
806
+ }
807
+ reviewRequired = true;
808
+ const confirmed = await ctx.ui.confirm(
809
+ confirmationTitle(intent),
810
+ confirmationMessage(options.settingsPath, intent, expected.previous),
811
+ { signal: owner.signal }
812
+ );
813
+ if (!commitOwnerCurrent(options, owner, expected)) return "cancel";
814
+ if (!confirmed) {
815
+ if (directAttempt) return "cancel";
816
+ continue;
817
+ }
818
+ try {
819
+ const result = await commitActiveDocument(
820
+ ctx,
821
+ options,
822
+ validated,
823
+ owner,
824
+ expected,
825
+ intent.kind === "restore" || intent.kind === "history" || intent.kind === "customize",
826
+ checkCandidate
827
+ );
828
+ if (!isSessionOwnerCurrent(owner) || result === "cancel") return "cancel";
829
+ } catch (error) {
830
+ if (!isSessionOwnerCurrent(owner)) return "cancel";
831
+ ctx.ui.notify(safeText(formatError(error)), "error");
832
+ if (directAttempt) return "cancel";
833
+ continue;
834
+ }
835
+ const warningSuffix = validated.diagnostics.length > 0 ? ` (${validated.diagnostics.length} warning${validated.diagnostics.length === 1 ? "" : "s"})` : "";
836
+ ctx.ui.notify(`${successMessage(intent)}${warningSuffix}.`, "info");
837
+ return "applied";
838
+ }
839
+ }
840
+ function reviewTitle(intent) {
841
+ switch (intent.kind) {
842
+ case "customize":
843
+ return "Footer preview";
844
+ case "restore":
845
+ return "Restore preview";
846
+ case "import":
847
+ return "Gist footer preview";
848
+ case "profile":
849
+ return `${safeText(intent.name)} profile preview`;
850
+ case "history":
851
+ return "History recovery preview";
852
+ case "preset":
853
+ return `${intent.preset.label} preset preview`;
854
+ }
855
+ }
856
+ function continueLabel(intent) {
857
+ switch (intent.kind) {
858
+ case "customize":
859
+ return "Apply changes\u2026";
860
+ case "restore":
861
+ return "Replace with built-in\u2026";
862
+ case "import":
863
+ return "Replace with Gist settings\u2026";
864
+ case "profile":
865
+ return `Apply ${safeText(intent.name)} profile\u2026`;
866
+ case "history":
867
+ return "Restore history document\u2026";
868
+ case "preset":
869
+ return `Apply ${intent.preset.label} preset\u2026`;
870
+ }
871
+ }
872
+ function confirmationTitle(intent) {
873
+ switch (intent.kind) {
874
+ case "customize":
875
+ return "Apply footer changes?";
876
+ case "restore":
877
+ return "Restore built-in footer?";
878
+ case "import":
879
+ return "Replace settings with Gist?";
880
+ case "profile":
881
+ return `Apply ${safeText(intent.name)} profile?`;
882
+ case "history":
883
+ return "Restore settings from history?";
884
+ case "preset":
885
+ return `Apply ${intent.preset.label} preset?`;
886
+ }
887
+ }
888
+ function confirmationMessage(settingsPath, intent, previous) {
889
+ if (previous.diagnostics.some((item) => item.severity === "error")) {
890
+ return `Explicit recovery: replace the invalid settings file ${safeText(settingsPath)} entirely with the reviewed document? Its exact original bytes will be kept in History before replacement.`;
891
+ }
892
+ if (intent.kind === "customize")
893
+ return "Replace the entire settings document and apply it immediately? Its previous bytes will be kept in History.";
894
+ const replacement = intent.kind === "restore" ? "the built-in configuration" : intent.kind === "import" ? "the reviewed Gist settings" : intent.kind === "profile" ? `the ${safeText(intent.name)} profile` : intent.kind === "history" ? "the reviewed history document" : `the ${intent.preset.label} preset`;
895
+ return `Replace ${safeText(settingsPath)} entirely with ${replacement}? All custom settings, unknown fields, and comments will be replaced. The previous document will be kept in History.`;
896
+ }
897
+ function successMessage(intent) {
898
+ switch (intent.kind) {
899
+ case "customize":
900
+ return "Footer settings saved and applied";
901
+ case "restore":
902
+ return "Built-in footer restored and applied";
903
+ case "import":
904
+ return "Gist settings saved and applied";
905
+ case "profile":
906
+ return `${safeText(intent.name)} profile applied`;
907
+ case "history":
908
+ return "History document restored and applied";
909
+ case "preset":
910
+ return `${intent.preset.label} preset saved and applied`;
911
+ }
912
+ }
913
+ function workflowOwner(options) {
914
+ if (options.getMenuOwner) return options.getMenuOwner();
915
+ const controller = new AbortController();
916
+ return { signal: controller.signal, isCurrent: () => true };
917
+ }
918
+ function isCurrentOwner(owner) {
919
+ return !owner.signal.aborted && owner.isCurrent();
920
+ }
921
+ function isSessionOwnerCurrent(owner) {
922
+ return !owner.signal.aborted && (owner.isSessionCurrent?.() ?? owner.isCurrent());
923
+ }
924
+ function clearSessionPreview(ctx, options, owner) {
925
+ if (owner.isSessionCurrent?.() ?? owner.isCurrent()) options.preview?.(void 0, ctx);
926
+ }
927
+ function captureExpectation(ctx, options) {
928
+ try {
929
+ return captureCommitExpectation(options);
930
+ } catch (error) {
931
+ ctx.ui.notify(`Footer settings were not saved: ${safeText(formatError(error))}`, "error");
932
+ return void 0;
933
+ }
934
+ }
935
+ function reviewPreviewBody(ctx, options, loaded, width, intent) {
936
+ if (intent.kind === "restore") return restorePreviewBody(ctx, options, loaded, width);
937
+ if (intent.kind !== "preset") return previewBody(ctx, options, loaded, width);
938
+ const current2 = configurationPresentation(options.getLoaded());
939
+ return [
940
+ `Preset: ${intent.preset.label}`,
941
+ `Requirement: ${intent.preset.requiresNerdFont ? "Nerd Font" : "No special font"}`,
942
+ `Current: ${current2.state}`,
943
+ `Path: ${safeText(options.settingsPath)}`,
944
+ "Applying replaces the entire settings document, including custom settings, unknown fields, and comments.",
945
+ "The previous document will be kept in History before replacement.",
946
+ "",
947
+ ...previewBody(ctx, options, loaded, width)
948
+ ];
949
+ }
950
+ function restorePreviewBody(ctx, options, loaded, width) {
951
+ const current2 = configurationPresentation(options.getLoaded());
952
+ return [
953
+ `Current: ${current2.state}`,
954
+ `Path: ${safeText(options.settingsPath)}`,
955
+ "The entire settings document will be replaced, including custom settings, unknown fields, and comments.",
956
+ "The previous document will be kept in History before replacement.",
957
+ "",
958
+ ...previewBody(ctx, options, loaded, width)
959
+ ];
960
+ }
961
+ function previewBody(ctx, options, loaded, width) {
962
+ let lines;
963
+ try {
964
+ lines = options.renderPreview?.(loaded, width, ctx) ?? [
965
+ "Live preview is unavailable until the footer is ready.",
966
+ "The draft is valid and can still be applied."
967
+ ];
968
+ } catch (error) {
969
+ lines = [`Preview unavailable: ${safeText(formatError(error))}`];
970
+ }
971
+ const warning = loaded.diagnostics.length === 0 ? "Draft validation: Healthy" : `Draft validation: ${loaded.diagnostics.length} warning${loaded.diagnostics.length === 1 ? "" : "s"}`;
972
+ return [...lines, "", warning];
973
+ }
974
+ function selectedPreviewAction(result) {
975
+ return result?.kind === "selected" ? result.value : null;
976
+ }
977
+ function showStatus(ctx, options) {
978
+ if (!canNotify(ctx)) return;
979
+ const loaded = options.getLoaded();
980
+ const diagnostics = loaded.diagnostics.slice(0, 5).map((item) => `${safeText(item.path || "root")}: ${safeText(item.message)}`).join("; ");
981
+ ctx.ui.notify(
982
+ [
983
+ `pi-starship source: ${loaded.source}`,
984
+ `path: ${options.settingsPath}`,
985
+ diagnostics ? `warnings: ${diagnostics}` : "warnings: none"
986
+ ].join("\n"),
987
+ loaded.diagnostics.length > 0 ? "warning" : "info"
988
+ );
989
+ }
990
+ function showHelp(ctx, settingsPath) {
991
+ if (!canNotify(ctx)) return;
992
+ ctx.ui.notify(
993
+ [
994
+ "/starship \u2014 configure with agent, manage profiles, preview presets, or recover settings in TUI mode",
995
+ "/starship settings \u2014 customize, preview, and apply TOML",
996
+ "/starship status \u2014 show source, path, and warnings",
997
+ "/starship help \u2014 show this help",
998
+ `Settings: ${settingsPath}`,
999
+ "Format/module docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship"
1000
+ ].join("\n"),
1001
+ "info"
1002
+ );
1003
+ }
1004
+ function canNotify(ctx) {
1005
+ return ctx.mode === "tui" || ctx.hasUI;
1006
+ }
1007
+ function safeText(value) {
1008
+ return Array.from(value, (character) => {
1009
+ const codePoint = character.codePointAt(0) ?? 0;
1010
+ const unsafe = codePoint <= 8 || codePoint >= 11 && codePoint <= 31 || codePoint >= 127 && codePoint <= 159;
1011
+ return unsafe ? `\\u${codePoint.toString(16).padStart(4, "0")}` : character;
1012
+ }).join("");
1013
+ }
1014
+ function formatError(error) {
1015
+ return error instanceof Error ? error.message : String(error);
1016
+ }
1017
+ export {
1018
+ handleStarshipCommand,
1019
+ registerStarshipCommand,
1020
+ reviewAndApply
1021
+ };
1022
+ //# sourceMappingURL=commands-ZYIJVIEJ.ts.map