@narumitw/pi-starship 0.59.2 → 0.60.1
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.
- package/README.md +28 -3
- package/dist/chunks/{chunk-MTFSZ63Q.ts → chunk-KZZKGGFW.ts} +327 -42
- package/dist/chunks/chunk-KZZKGGFW.ts.map +7 -0
- package/dist/chunks/{commands-K6T7PNEM.ts → commands-C2VJ6ZBN.ts} +1279 -111
- package/dist/chunks/commands-C2VJ6ZBN.ts.map +7 -0
- package/dist/index.ts +25 -9
- package/dist/index.ts.map +2 -2
- package/package.json +2 -2
- package/skills/configure-pi-starship/SKILL.md +20 -2
- package/skills/configure-pi-starship/references/configuration.md +122 -11
- package/skills/configure-pi-starship/scripts/apply.mjs +87 -33
- package/skills/configure-pi-starship/scripts/backup.mjs +17 -0
- package/skills/configure-pi-starship/scripts/config-path.mjs +63 -3
- package/src/command-commit.ts +169 -0
- package/src/command-configuration.ts +78 -34
- package/src/command-gist.ts +11 -3
- package/src/command-preset-picker.ts +6 -2
- package/src/command-profiles.ts +664 -0
- package/src/commands.ts +223 -77
- package/src/config.ts +112 -14
- package/src/format/formatter.ts +8 -4
- package/src/format/style.ts +54 -15
- package/src/format/terminal-safety.ts +80 -0
- package/src/format/theme-colors.ts +69 -0
- package/src/modules/model.ts +1 -1
- package/src/modules/render.ts +75 -5
- package/src/pi-starship.ts +22 -6
- package/src/profile-store.ts +526 -0
- package/dist/chunks/chunk-MTFSZ63Q.ts.map +0 -7
- package/dist/chunks/commands-K6T7PNEM.ts.map +0 -7
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ The extension parses and renders the footer itself, so it does not need the `sta
|
|
|
16
16
|
- Provides Pi, model, usage, Git, pull request, package, language, environment, deployment, cloud, and execution modules, with usage totals including persisted cache warming.
|
|
17
17
|
- Wraps native multiline layouts to terminal width instead of truncating them.
|
|
18
18
|
- Keeps rendering pure while refreshing filesystem, process, and network-derived data through bounded caches.
|
|
19
|
-
- Uses `/starship` for
|
|
19
|
+
- Uses `/starship` for named TOML profiles, live previews, presets, customization, and recovery history.
|
|
20
20
|
- Shares settings through unlisted GitHub Gists and reviews imported settings before replacement.
|
|
21
21
|
- Bundles the authoritative configuration skill and references for editing `pi-starship.toml` or answering setup questions.
|
|
22
22
|
- Loads a generated split runtime to reduce Pi package startup work.
|
|
@@ -72,7 +72,7 @@ It does not cover general TOML, shell Starship configuration, extension source d
|
|
|
72
72
|
|
|
73
73
|
All routes support TUI and RPC with the exceptions above and reject unknown or trailing arguments.
|
|
74
74
|
Print and JSON modes produce no command output; the footer runs only in TUI mode.
|
|
75
|
-
|
|
75
|
+
Profiles, history, preset selection, module inspection, and Gist sharing and import are menu-only, not extra subcommands.
|
|
76
76
|
Restoring built-in configuration requires an existing settings document to replace; see [Settings](#-settings).
|
|
77
77
|
Effective TOML and settings-document reviews support literal document search in TUI mode: Space opens search, configured search-close exits search, and Back retains its existing meaning. Search does not modify settings.
|
|
78
78
|
|
|
@@ -99,12 +99,37 @@ format = "$model$directory$git_branch"
|
|
|
99
99
|
style = "bold blue"
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
Use `fg:pi:accent` to follow Pi's active theme; see [Pi theme colors](./skills/configure-pi-starship/references/configuration.md#pi-theme-colors).
|
|
102
103
|
Provider, model, and thinking modules also accept ordered exact-match `style_rules`.
|
|
103
104
|
For per-extension status colors, add `[extension_status.styles]` entries using raw Pi status keys (or `namespace:*`); unmatched statuses keep the module style.
|
|
104
105
|
See [Configuration and format](./skills/configure-pi-starship/references/configuration.md) for examples and matching rules.
|
|
105
106
|
Use `/starship` for interactive configuration, preview, diagnostics, presets, and recovery.
|
|
106
107
|
Manual file edits load at the next `session_start`, including `/reload`.
|
|
107
108
|
|
|
109
|
+
## 🗃️ Profiles and history
|
|
110
|
+
|
|
111
|
+
Open `/starship` → **Profiles** to save the current TOML under a name, edit it, duplicate it, rename it, or delete it.
|
|
112
|
+
Moving the selection previews that document in the footer without saving, running commands, or starting network requests.
|
|
113
|
+
Previews use existing runtime data; modules with no available data can be empty.
|
|
114
|
+
Applying a profile requires confirmation and replaces the complete active document.
|
|
115
|
+
Editing can save only the profile or save and apply it; a saved profile remains available if the later application fails.
|
|
116
|
+
|
|
117
|
+
Profiles are independent copies, not live links: editing or deleting a saved profile does not change the current footer.
|
|
118
|
+
Comments and unknown fields are preserved.
|
|
119
|
+
The active file remains `<getAgentDir()>/pi-starship.toml`; named documents are stored under `<getAgentDir()>/pi-starship/profiles/<name>.toml`.
|
|
120
|
+
For the default Pi directory, this is `~/.pi/agent/pi-starship/profiles/`.
|
|
121
|
+
|
|
122
|
+
Open **Configuration** → **History** to review recovery copies, preview and restore a document, save it as a profile, or delete a new history entry after confirmation.
|
|
123
|
+
Managed replacements preserve the previous document before writing the new one; a backup failure blocks replacement.
|
|
124
|
+
New recovery copies use `<getAgentDir()>/pi-starship/history/`; existing timestamped skill backups remain in place and are available read-only.
|
|
125
|
+
History is not automatically pruned and is not a complete record of arbitrary external file edits.
|
|
126
|
+
Ordinary session startup remains read-only.
|
|
127
|
+
|
|
128
|
+
Escape returns one level and Ctrl+C closes the flow; temporary previews are removed without undoing an already confirmed save.
|
|
129
|
+
Profile and history files can contain sensitive settings or local paths; new documents use private file permissions on POSIX.
|
|
130
|
+
Storage serializes in-process work and rejects detected changes during review, but does not lock out external editors.
|
|
131
|
+
See [Configuration and format](./skills/configure-pi-starship/references/configuration.md) for naming, conflicts, and recovery limits.
|
|
132
|
+
|
|
108
133
|
## 🔗 Share and import settings
|
|
109
134
|
|
|
110
135
|
In TUI mode, open `/starship` → **Configuration** and select **Share settings as Gist…** or **Import settings from Gist…**.
|
|
@@ -118,7 +143,7 @@ The result is a shareable Gist URL; existing Gists are never updated.
|
|
|
118
143
|
Import accepts a Gist ID or an `https://gist.github.com/<owner>/<id>` link and reads only `pi-starship.toml`.
|
|
119
144
|
It validates the TOML, shows the full document for review, then previews the footer and asks permission to replace the entire local settings document.
|
|
120
145
|
Review untrusted settings carefully: they can enable command execution and network requests.
|
|
121
|
-
A successful import applies immediately, preserves the imported bytes, and
|
|
146
|
+
A successful import applies immediately, preserves the imported bytes, and retains a recovery copy of the previous document; application failure attempts to restore the previous document and footer.
|
|
122
147
|
Concurrent in-process settings changes or disk changes during review block the import; this is not a cross-process lock.
|
|
123
148
|
|
|
124
149
|
Only github.com Gists are supported, with a 64 KiB document limit, a 512 KiB API response limit, and a 30-second request timeout.
|
|
@@ -15,10 +15,157 @@ function completeStarshipArguments(prefix) {
|
|
|
15
15
|
|
|
16
16
|
// src/config.ts
|
|
17
17
|
import { randomUUID } from "node:crypto";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
closeSync,
|
|
20
|
+
existsSync,
|
|
21
|
+
fsyncSync,
|
|
22
|
+
lstatSync,
|
|
23
|
+
mkdirSync,
|
|
24
|
+
openSync,
|
|
25
|
+
readFileSync,
|
|
26
|
+
renameSync,
|
|
27
|
+
rmSync,
|
|
28
|
+
writeFileSync
|
|
29
|
+
} from "node:fs";
|
|
19
30
|
import { dirname, join } from "node:path";
|
|
20
31
|
import { parse as parseToml } from "smol-toml";
|
|
21
32
|
|
|
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}`;
|
|
61
|
+
}
|
|
62
|
+
offset = closing.end;
|
|
63
|
+
}
|
|
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
|
+
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;
|
|
101
|
+
} catch {
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
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
|
+
|
|
22
169
|
// src/format/style.ts
|
|
23
170
|
function isFillChunk(chunk) {
|
|
24
171
|
return "type" in chunk && chunk.type === "fill";
|
|
@@ -77,7 +224,7 @@ function parseStyleResult(styleString, palette = {}) {
|
|
|
77
224
|
continue;
|
|
78
225
|
}
|
|
79
226
|
const color = parseColor(token, palette);
|
|
80
|
-
if (!foreground && !color) {
|
|
227
|
+
if (!foreground && !color && !token.toLowerCase().startsWith("pi:")) {
|
|
81
228
|
delete style.background;
|
|
82
229
|
continue;
|
|
83
230
|
}
|
|
@@ -91,15 +238,16 @@ function parseStyle(styleString, palette = {}) {
|
|
|
91
238
|
return parseStyleResult(styleString, palette).style;
|
|
92
239
|
}
|
|
93
240
|
function normalizeStyleToken(rawToken) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return { token: token.replace(/^(?:fg:)+/u, ""), foreground: true };
|
|
241
|
+
if (/^fg:/iu.test(rawToken)) {
|
|
242
|
+
return { token: normalizeColorToken(rawToken.replace(/^(?:fg:)+/iu, "")), foreground: true };
|
|
97
243
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
return { token, foreground: false };
|
|
244
|
+
if (/^bg:/iu.test(rawToken)) {
|
|
245
|
+
return { token: normalizeColorToken(rawToken.replace(/^(?:bg:)+/iu, "")), foreground: false };
|
|
101
246
|
}
|
|
102
|
-
return { token, foreground: true };
|
|
247
|
+
return { token: normalizeColorToken(rawToken), foreground: true };
|
|
248
|
+
}
|
|
249
|
+
function normalizeColorToken(token) {
|
|
250
|
+
return /^pi:/iu.test(token) ? `pi:${token.slice(3)}` : token.toLowerCase();
|
|
103
251
|
}
|
|
104
252
|
function applyModifier(style, token) {
|
|
105
253
|
switch (token) {
|
|
@@ -132,8 +280,14 @@ function applyModifier(style, token) {
|
|
|
132
280
|
}
|
|
133
281
|
}
|
|
134
282
|
function parseColor(token, palette = {}) {
|
|
135
|
-
const
|
|
136
|
-
|
|
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
|
+
}
|
|
137
291
|
if (NAMED_COLORS.has(token)) {
|
|
138
292
|
return { kind: "named", name: token };
|
|
139
293
|
}
|
|
@@ -150,20 +304,22 @@ function parseColor(token, palette = {}) {
|
|
|
150
304
|
blue: Number.parseInt(rgb[1].slice(4, 6), 16)
|
|
151
305
|
};
|
|
152
306
|
}
|
|
153
|
-
function renderChunksToAnsi(chunks, trueColor = true) {
|
|
307
|
+
function renderChunksToAnsi(chunks, trueColor = true, themeColors) {
|
|
154
308
|
const runs = [];
|
|
155
309
|
let previous;
|
|
156
310
|
for (const chunk of chunks) {
|
|
157
311
|
if (isFillChunk(chunk)) continue;
|
|
158
312
|
const style = resolveStyle(chunk.style, previous);
|
|
313
|
+
const text = sanitizeFormatText(chunk.text);
|
|
159
314
|
const last = runs.at(-1);
|
|
160
|
-
if (
|
|
161
|
-
else if (
|
|
315
|
+
if (text && last && stylesEqual(last.style, style)) last.text += text;
|
|
316
|
+
else if (text) runs.push({ text, style });
|
|
162
317
|
previous = style;
|
|
163
318
|
}
|
|
164
319
|
return runs.map(({ text, style }) => {
|
|
165
320
|
const codes = ansiCodes(style, trueColor);
|
|
166
|
-
|
|
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;
|
|
167
323
|
}).join("");
|
|
168
324
|
}
|
|
169
325
|
function stylesEqual(left, right) {
|
|
@@ -196,7 +352,13 @@ function ansiCodes(style, trueColor) {
|
|
|
196
352
|
if (style.strikethrough) codes.push("9");
|
|
197
353
|
return codes;
|
|
198
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
|
+
}
|
|
199
360
|
function colorCodes(color, background, trueColor) {
|
|
361
|
+
if (color.kind === "theme") return [];
|
|
200
362
|
if (color.kind === "named") {
|
|
201
363
|
const foreground = FOREGROUND_CODES[color.name];
|
|
202
364
|
return [`${background ? foreground + 10 : foreground}`];
|
|
@@ -382,7 +544,7 @@ function renderNodes(nodes, options, inheritedStyle) {
|
|
|
382
544
|
for (const node of nodes) {
|
|
383
545
|
switch (node.type) {
|
|
384
546
|
case "text":
|
|
385
|
-
chunks.push({ text: node.value, style: inheritedStyle });
|
|
547
|
+
chunks.push({ text: sanitizeFormatText(node.value), style: inheritedStyle });
|
|
386
548
|
break;
|
|
387
549
|
case "variable":
|
|
388
550
|
chunks.push(...chunksForValue(ownValue(options.variables, node.name), inheritedStyle));
|
|
@@ -409,21 +571,22 @@ function ownValue(record, key) {
|
|
|
409
571
|
}
|
|
410
572
|
function chunksForValue(value, inheritedStyle) {
|
|
411
573
|
if (value === void 0) return [];
|
|
412
|
-
if (typeof value === "string") return [{ text: value, style: inheritedStyle }];
|
|
574
|
+
if (typeof value === "string") return [{ text: sanitizeFormatText(value), style: inheritedStyle }];
|
|
413
575
|
return value.map(
|
|
414
576
|
(chunk) => isFillChunk(chunk) ? {
|
|
415
577
|
type: "fill",
|
|
416
578
|
pattern: chunk.pattern.map((part) => ({
|
|
417
579
|
...part,
|
|
580
|
+
text: sanitizeFormatText(part.text),
|
|
418
581
|
style: part.style ?? inheritedStyle
|
|
419
582
|
}))
|
|
420
|
-
} : { ...chunk, style: chunk.style ?? inheritedStyle }
|
|
583
|
+
} : { ...chunk, text: sanitizeFormatText(chunk.text), style: chunk.style ?? inheritedStyle }
|
|
421
584
|
);
|
|
422
585
|
}
|
|
423
586
|
function conditionalVisible(nodes, variables) {
|
|
424
587
|
for (const variable of formatVariables(nodes)) {
|
|
425
588
|
const value = ownValue(variables, variable);
|
|
426
|
-
if (typeof value === "string" ? value.length > 0 : value?.some((chunk) => isFillChunk(chunk) || chunk.text.length > 0)) {
|
|
589
|
+
if (typeof value === "string" ? sanitizeFormatText(value).length > 0 : value?.some((chunk) => isFillChunk(chunk) || sanitizeFormatText(chunk.text).length > 0)) {
|
|
427
590
|
return true;
|
|
428
591
|
}
|
|
429
592
|
}
|
|
@@ -1490,7 +1653,7 @@ function isTruncationDirection(value) {
|
|
|
1490
1653
|
return TRUNCATION_DIRECTIONS.includes(value);
|
|
1491
1654
|
}
|
|
1492
1655
|
function shortenModel(model) {
|
|
1493
|
-
return model.replace(/^claude-/u, "").replace(/-20\d{6}$/u, "").replace(/-latest$/u, "");
|
|
1656
|
+
return sanitizeTerminalText3(model).replace(/^claude-/u, "").replace(/-20\d{6}$/u, "").replace(/-latest$/u, "");
|
|
1494
1657
|
}
|
|
1495
1658
|
|
|
1496
1659
|
// src/modules/package.ts
|
|
@@ -1749,8 +1912,12 @@ function settingsFilePath(agentDir) {
|
|
|
1749
1912
|
}
|
|
1750
1913
|
function loadStarshipConfig(settingsPath) {
|
|
1751
1914
|
let rawDocument;
|
|
1915
|
+
let snapshot;
|
|
1752
1916
|
try {
|
|
1753
|
-
|
|
1917
|
+
const rawBytes = readFileSync(settingsPath);
|
|
1918
|
+
snapshot = readConfigDocumentSnapshot(settingsPath);
|
|
1919
|
+
if (!snapshot.rawBytes?.equals(rawBytes)) throw new Error("Settings changed while being read; retry the operation");
|
|
1920
|
+
rawDocument = rawBytes.toString("utf8");
|
|
1754
1921
|
} catch (error) {
|
|
1755
1922
|
if (error.code === "ENOENT" && !existsSync(settingsPath)) {
|
|
1756
1923
|
return {
|
|
@@ -1769,6 +1936,8 @@ function loadStarshipConfig(settingsPath) {
|
|
|
1769
1936
|
}
|
|
1770
1937
|
let parsed;
|
|
1771
1938
|
try {
|
|
1939
|
+
if (!Buffer.from(rawDocument, "utf8").equals(snapshot.rawBytes ?? Buffer.alloc(0)))
|
|
1940
|
+
throw new Error("Settings are not valid UTF-8");
|
|
1772
1941
|
parsed = parseToml(rawDocument);
|
|
1773
1942
|
} catch (error) {
|
|
1774
1943
|
return {
|
|
@@ -1776,6 +1945,7 @@ function loadStarshipConfig(settingsPath) {
|
|
|
1776
1945
|
source: "built-in",
|
|
1777
1946
|
settingsPath,
|
|
1778
1947
|
rawDocument,
|
|
1948
|
+
...snapshot,
|
|
1779
1949
|
diagnostics: [diagnostic("error", "", `Unable to parse TOML: ${formatError(error)}`)]
|
|
1780
1950
|
};
|
|
1781
1951
|
}
|
|
@@ -1784,9 +1954,33 @@ function loadStarshipConfig(settingsPath) {
|
|
|
1784
1954
|
...normalized,
|
|
1785
1955
|
source: "user",
|
|
1786
1956
|
settingsPath,
|
|
1787
|
-
rawDocument
|
|
1957
|
+
rawDocument,
|
|
1958
|
+
...snapshot
|
|
1788
1959
|
};
|
|
1789
1960
|
}
|
|
1961
|
+
function readConfigDocumentSnapshot(settingsPath) {
|
|
1962
|
+
let info;
|
|
1963
|
+
try {
|
|
1964
|
+
info = lstatSync(settingsPath);
|
|
1965
|
+
} catch (error) {
|
|
1966
|
+
if (error.code === "ENOENT") return {};
|
|
1967
|
+
throw error;
|
|
1968
|
+
}
|
|
1969
|
+
if (!info.isFile() || info.isSymbolicLink()) throw new Error("Settings must be a regular file, not a symbolic link");
|
|
1970
|
+
const rawBytes = readFileSync(settingsPath);
|
|
1971
|
+
const after = lstatSync(settingsPath);
|
|
1972
|
+
if (after.dev !== info.dev || after.ino !== info.ino || !after.isFile()) {
|
|
1973
|
+
throw new Error("Settings changed while being read; retry the operation");
|
|
1974
|
+
}
|
|
1975
|
+
return { rawBytes, fileIdentity: { dev: info.dev, ino: info.ino } };
|
|
1976
|
+
}
|
|
1977
|
+
function assertConfigDocumentUnchanged(settingsPath, expected) {
|
|
1978
|
+
const current = readConfigDocumentSnapshot(settingsPath);
|
|
1979
|
+
if (current.rawBytes === void 0 && expected.rawBytes === void 0) return;
|
|
1980
|
+
if (current.rawBytes?.equals(expected.rawBytes ?? Buffer.alloc(0)) && current.fileIdentity?.dev === expected.fileIdentity?.dev && current.fileIdentity?.ino === expected.fileIdentity?.ino)
|
|
1981
|
+
return;
|
|
1982
|
+
throw new Error("Starship settings changed concurrently; the newer file was preserved. Reopen settings and retry.");
|
|
1983
|
+
}
|
|
1790
1984
|
function normalizeConfig(value) {
|
|
1791
1985
|
const config = cloneBuiltInConfig();
|
|
1792
1986
|
const diagnostics = [];
|
|
@@ -1823,12 +2017,12 @@ function normalizeConfig(value) {
|
|
|
1823
2017
|
}
|
|
1824
2018
|
const palette2 = {};
|
|
1825
2019
|
for (const [name, color] of Object.entries(paletteValue)) {
|
|
1826
|
-
if (typeof color !== "string" || !parseColor(color
|
|
2020
|
+
if (typeof color !== "string" || !parseColor(color)) {
|
|
1827
2021
|
diagnostics.push(
|
|
1828
2022
|
diagnostic(
|
|
1829
2023
|
"warning",
|
|
1830
2024
|
`palettes.${paletteName}.${name}`,
|
|
1831
|
-
"Palette colors must be named, ANSI 0-255, or
|
|
2025
|
+
"Palette colors must be named, ANSI 0-255, #RRGGBB, or pi:<role>"
|
|
1832
2026
|
)
|
|
1833
2027
|
);
|
|
1834
2028
|
continue;
|
|
@@ -2011,6 +2205,8 @@ function normalizeModule(name, value, config, diagnostics) {
|
|
|
2011
2205
|
}
|
|
2012
2206
|
}
|
|
2013
2207
|
function validateConfigDocument(settingsPath, rawDocument) {
|
|
2208
|
+
if (Buffer.from(rawDocument, "utf8").toString("utf8") !== rawDocument)
|
|
2209
|
+
throw new Error("Settings must be lossless UTF-8 text");
|
|
2014
2210
|
let parsed;
|
|
2015
2211
|
try {
|
|
2016
2212
|
parsed = parseToml(rawDocument);
|
|
@@ -2028,16 +2224,24 @@ function validateConfigDocument(settingsPath, rawDocument) {
|
|
|
2028
2224
|
rawDocument
|
|
2029
2225
|
};
|
|
2030
2226
|
}
|
|
2031
|
-
function atomicSaveConfigDocument(settingsPath, rawDocument, overrides = {}) {
|
|
2227
|
+
function atomicSaveConfigDocument(settingsPath, rawDocument, overrides = {}, expected) {
|
|
2032
2228
|
const validated = validateConfigDocument(settingsPath, rawDocument);
|
|
2033
2229
|
return {
|
|
2034
2230
|
...validated,
|
|
2035
|
-
|
|
2231
|
+
rawBytes: Buffer.from(rawDocument),
|
|
2232
|
+
fileIdentity: atomicWriteConfigDocument(settingsPath, rawDocument, overrides, expected)
|
|
2036
2233
|
};
|
|
2037
2234
|
}
|
|
2038
|
-
function atomicRestoreConfigDocument(settingsPath, rawDocument, overrides = {}) {
|
|
2039
|
-
atomicWriteConfigDocument(settingsPath, rawDocument, overrides);
|
|
2235
|
+
function atomicRestoreConfigDocument(settingsPath, rawDocument, overrides = {}, expected) {
|
|
2236
|
+
atomicWriteConfigDocument(settingsPath, rawDocument, overrides, expected);
|
|
2040
2237
|
}
|
|
2238
|
+
var ConfigPublicationError = class extends Error {
|
|
2239
|
+
constructor(message, fileIdentity) {
|
|
2240
|
+
super(message);
|
|
2241
|
+
this.fileIdentity = fileIdentity;
|
|
2242
|
+
}
|
|
2243
|
+
fileIdentity;
|
|
2244
|
+
};
|
|
2041
2245
|
function removeConfigDocumentIfMatches(settingsPath, expectedRawDocument, expectedIdentity, overrides = {}) {
|
|
2042
2246
|
const quarantinePath = join(dirname(settingsPath), `.${CONFIG_FILE_NAME}.${randomUUID()}.rollback`);
|
|
2043
2247
|
const before = lstatSync(settingsPath);
|
|
@@ -2049,6 +2253,14 @@ function removeConfigDocumentIfMatches(settingsPath, expectedRawDocument, expect
|
|
|
2049
2253
|
const quarantinedSavedFile = quarantined.isFile() && !quarantined.isSymbolicLink() && quarantined.dev === expectedIdentity.dev && quarantined.ino === expectedIdentity.ino;
|
|
2050
2254
|
if (quarantinedSavedFile && readFileSync(quarantinePath, "utf8") === expectedRawDocument) {
|
|
2051
2255
|
(overrides.rmSync ?? rmSync)(quarantinePath);
|
|
2256
|
+
if (process.platform !== "win32") {
|
|
2257
|
+
const directory = openSync(dirname(settingsPath), "r");
|
|
2258
|
+
try {
|
|
2259
|
+
fsyncSync(directory);
|
|
2260
|
+
} finally {
|
|
2261
|
+
closeSync(directory);
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2052
2264
|
return;
|
|
2053
2265
|
}
|
|
2054
2266
|
if (quarantinedSavedFile && !pathEntryExists(settingsPath)) {
|
|
@@ -2057,21 +2269,38 @@ function removeConfigDocumentIfMatches(settingsPath, expectedRawDocument, expect
|
|
|
2057
2269
|
} catch {
|
|
2058
2270
|
}
|
|
2059
2271
|
}
|
|
2060
|
-
throw new Error(
|
|
2272
|
+
throw new Error(
|
|
2273
|
+
`Starship settings changed concurrently; the newer file was preserved. Recovery path: ${quarantinePath}`
|
|
2274
|
+
);
|
|
2061
2275
|
}
|
|
2062
|
-
function atomicWriteConfigDocument(settingsPath, rawDocument, overrides) {
|
|
2063
|
-
const fs = { mkdirSync, writeFileSync, renameSync, rmSync, ...overrides };
|
|
2064
|
-
const
|
|
2065
|
-
|
|
2276
|
+
function atomicWriteConfigDocument(settingsPath, rawDocument, overrides, captured) {
|
|
2277
|
+
const fs = { mkdirSync, writeFileSync, renameSync, rmSync, openSync, closeSync, fsyncSync, ...overrides };
|
|
2278
|
+
const expected = captured ?? readConfigDocumentSnapshot(settingsPath);
|
|
2279
|
+
const replaceExisting = expected.rawBytes !== void 0;
|
|
2280
|
+
fs.mkdirSync(dirname(settingsPath), { recursive: true, mode: 448 });
|
|
2066
2281
|
const tempPath = join(dirname(settingsPath), `.${CONFIG_FILE_NAME}.${randomUUID()}.tmp`);
|
|
2282
|
+
let publishedIdentity;
|
|
2067
2283
|
try {
|
|
2068
|
-
fs.writeFileSync(tempPath, rawDocument, { encoding: "utf8", flag: "wx" });
|
|
2284
|
+
fs.writeFileSync(tempPath, rawDocument, { encoding: "utf8", flag: "wx", mode: 384, flush: true });
|
|
2069
2285
|
const info = lstatSync(tempPath);
|
|
2070
2286
|
if (!replaceExisting && pathEntryExists(settingsPath)) {
|
|
2071
2287
|
throw new Error(`${CONFIG_FILE_NAME} was created concurrently; reopen settings and retry.`);
|
|
2072
2288
|
}
|
|
2289
|
+
assertConfigDocumentUnchanged(settingsPath, expected);
|
|
2073
2290
|
fs.renameSync(tempPath, settingsPath);
|
|
2074
|
-
|
|
2291
|
+
publishedIdentity = { dev: info.dev, ino: info.ino };
|
|
2292
|
+
if (process.platform !== "win32") {
|
|
2293
|
+
const directory = fs.openSync(dirname(settingsPath), "r");
|
|
2294
|
+
try {
|
|
2295
|
+
fs.fsyncSync(directory);
|
|
2296
|
+
} finally {
|
|
2297
|
+
fs.closeSync(directory);
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
return publishedIdentity;
|
|
2301
|
+
} catch (error) {
|
|
2302
|
+
if (publishedIdentity) throw new ConfigPublicationError(formatError(error), publishedIdentity);
|
|
2303
|
+
throw error;
|
|
2075
2304
|
} finally {
|
|
2076
2305
|
try {
|
|
2077
2306
|
fs.rmSync(tempPath, { force: true });
|
|
@@ -2310,6 +2539,7 @@ import { stripVTControlCharacters } from "node:util";
|
|
|
2310
2539
|
|
|
2311
2540
|
// src/modules/render.ts
|
|
2312
2541
|
import { visibleWidth as visibleWidth2 } from "@earendil-works/pi-tui";
|
|
2542
|
+
import { sanitizeTerminalText as sanitizeTerminalText5 } from "@narumitw/pi-tui-kit/terminal-text";
|
|
2313
2543
|
|
|
2314
2544
|
// src/modules/style-rules.ts
|
|
2315
2545
|
function resolveStyleRule(rules, selectors, context) {
|
|
@@ -2329,7 +2559,7 @@ function resolveStyleRule(rules, selectors, context) {
|
|
|
2329
2559
|
}
|
|
2330
2560
|
|
|
2331
2561
|
// src/modules/render.ts
|
|
2332
|
-
function renderStatusline(config, runtime, width = 80, trueColor = true) {
|
|
2562
|
+
function renderStatusline(config, runtime, width = 80, trueColor = true, themeColors) {
|
|
2333
2563
|
const palette = activePalette(config);
|
|
2334
2564
|
const modules = {};
|
|
2335
2565
|
const layoutModules = {};
|
|
@@ -2370,20 +2600,72 @@ function renderStatusline(config, runtime, width = 80, trueColor = true) {
|
|
|
2370
2600
|
const layout = renderFormat(config.formatAst, { variables: rootVariables, palette });
|
|
2371
2601
|
const chunks = resolveFillLayout(layout, width);
|
|
2372
2602
|
return {
|
|
2373
|
-
ansi: renderChunksToAnsi(chunks, trueColor),
|
|
2603
|
+
ansi: renderChunksToAnsi(chunks, trueColor, themeColors),
|
|
2374
2604
|
chunks,
|
|
2375
2605
|
modules
|
|
2376
2606
|
};
|
|
2377
2607
|
}
|
|
2378
2608
|
function valueContext(config, name, runtime, palette) {
|
|
2379
2609
|
return {
|
|
2380
|
-
runtime,
|
|
2610
|
+
runtime: runtimeForDisplay(name, runtime),
|
|
2381
2611
|
palette,
|
|
2382
|
-
symbol: config.modules[name].symbol,
|
|
2383
|
-
options:
|
|
2384
|
-
|
|
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
|
+
}
|
|
2385
2626
|
};
|
|
2386
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
|
+
}
|
|
2387
2669
|
function renderModule(module, values, styleVariables2, palette) {
|
|
2388
2670
|
if (module.disabled) return [];
|
|
2389
2671
|
return renderFormat(module.formatAst, {
|
|
@@ -2551,13 +2833,16 @@ export {
|
|
|
2551
2833
|
BUILT_IN_EXAMPLE,
|
|
2552
2834
|
settingsFilePath,
|
|
2553
2835
|
loadStarshipConfig,
|
|
2836
|
+
readConfigDocumentSnapshot,
|
|
2837
|
+
assertConfigDocumentUnchanged,
|
|
2554
2838
|
validateConfigDocument,
|
|
2555
2839
|
atomicSaveConfigDocument,
|
|
2556
2840
|
atomicRestoreConfigDocument,
|
|
2841
|
+
ConfigPublicationError,
|
|
2557
2842
|
removeConfigDocumentIfMatches,
|
|
2558
2843
|
renderStatusline,
|
|
2559
2844
|
reachableModuleRequirements,
|
|
2560
2845
|
inspectStatuslineModules,
|
|
2561
2846
|
inspectUnavailableModules
|
|
2562
2847
|
};
|
|
2563
|
-
//# sourceMappingURL=chunk-
|
|
2848
|
+
//# sourceMappingURL=chunk-KZZKGGFW.ts.map
|