@narumitw/pi-starship 0.60.1 → 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.
- package/README.md +63 -6
- package/dist/chunks/chunk-43VIENBN.ts +1586 -0
- package/dist/chunks/chunk-43VIENBN.ts.map +7 -0
- package/dist/chunks/chunk-HPZTMIZS.ts +646 -0
- package/dist/chunks/chunk-HPZTMIZS.ts.map +7 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts +69 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts.map +7 -0
- package/dist/chunks/chunk-KP33I6BR.ts +579 -0
- package/dist/chunks/chunk-KP33I6BR.ts.map +7 -0
- package/dist/chunks/{chunk-KZZKGGFW.ts → chunk-PWTSHSP3.ts} +853 -1001
- package/dist/chunks/chunk-PWTSHSP3.ts.map +7 -0
- package/dist/chunks/{chunk-PD457PX5.ts → chunk-S2KBLHE2.ts} +75 -10
- package/dist/chunks/chunk-S2KBLHE2.ts.map +7 -0
- package/dist/chunks/chunk-XQUIQO2G.ts +20 -0
- package/dist/chunks/chunk-XQUIQO2G.ts.map +7 -0
- package/dist/chunks/{chunk-ADX4CY27.ts → chunk-XTLQ4WUL.ts} +1 -1
- package/dist/chunks/chunk-XTLQ4WUL.ts.map +7 -0
- package/dist/chunks/{cloud-EPAEV4ZB.ts → cloud-J2ZOE3HE.ts} +6 -2
- package/dist/chunks/cloud-J2ZOE3HE.ts.map +7 -0
- package/dist/chunks/command-configuration-menu-S2LXCOJG.ts +147 -0
- package/dist/chunks/command-configuration-menu-S2LXCOJG.ts.map +7 -0
- package/dist/chunks/command-settings-chat-O34BEU4X.ts +1041 -0
- package/dist/chunks/command-settings-chat-O34BEU4X.ts.map +7 -0
- package/dist/chunks/commands-ZYIJVIEJ.ts +1022 -0
- package/dist/chunks/commands-ZYIJVIEJ.ts.map +7 -0
- package/dist/chunks/{deployment-7J54EHNR.ts → deployment-NOJ2KCLI.ts} +85 -5
- package/dist/chunks/deployment-NOJ2KCLI.ts.map +7 -0
- package/dist/chunks/{development-IWJAAAEV.ts → development-T3XXVVDP.ts} +67 -15
- package/dist/chunks/development-T3XXVVDP.ts.map +7 -0
- package/dist/chunks/directory-OX6BWJZA.ts +31 -0
- package/dist/chunks/directory-OX6BWJZA.ts.map +7 -0
- package/dist/chunks/{execution-P4WZALW2.ts → execution-R2OHIP2L.ts} +8 -4
- package/dist/chunks/execution-R2OHIP2L.ts.map +7 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts +174 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts.map +7 -0
- package/dist/chunks/languages-CBQNNYXM.ts +262 -0
- package/dist/chunks/languages-CBQNNYXM.ts.map +7 -0
- package/dist/chunks/{package-H24VJEX3.ts → package-7KVAK3TC.ts} +6 -2
- package/dist/chunks/package-7KVAK3TC.ts.map +7 -0
- package/dist/chunks/system-574MHB4R.ts +165 -0
- package/dist/chunks/system-574MHB4R.ts.map +7 -0
- package/dist/index.ts +558 -150
- package/dist/index.ts.map +4 -4
- package/package.json +5 -1
- package/skills/configure-pi-starship/SKILL.md +14 -0
- package/skills/configure-pi-starship/references/configuration.md +109 -24
- package/skills/configure-pi-starship/references/module-catalog.md +278 -25
- package/skills/configure-pi-starship/references/modules.md +213 -36
- package/skills/configure-pi-starship/references/runtime-and-security.md +88 -28
- package/src/command-configuration-menu.ts +155 -0
- package/src/command-configuration.ts +9 -84
- package/src/command-preview.ts +3 -3
- package/src/command-settings-chat.ts +210 -0
- package/src/commands.ts +54 -98
- package/src/config/module-options.ts +112 -0
- package/src/config.ts +17 -53
- package/src/effective-config.ts +5 -4
- package/src/format/bounded-regex.ts +66 -0
- package/src/format/version.ts +24 -0
- package/src/modules/catalog.ts +10 -0
- package/src/modules/cloud.ts +1 -0
- package/src/modules/deployment.ts +8 -0
- package/src/modules/development.ts +20 -2
- package/src/modules/directory.ts +171 -51
- package/src/modules/execution.ts +2 -0
- package/src/modules/git/branch.ts +19 -4
- package/src/modules/git/commit.ts +9 -2
- package/src/modules/git/metrics.ts +9 -4
- package/src/modules/git/runtime.ts +122 -33
- package/src/modules/git/state.ts +23 -2
- package/src/modules/git/status-templates.ts +58 -0
- package/src/modules/git/status.ts +96 -30
- package/src/modules/jujutsu.ts +225 -0
- package/src/modules/languages.ts +26 -2
- package/src/modules/package.ts +1 -0
- package/src/modules/render.ts +42 -16
- package/src/modules/system.ts +54 -0
- package/src/modules/time-format.ts +188 -0
- package/src/modules/time.ts +11 -5
- package/src/modules/types.ts +42 -4
- package/src/pi-starship.ts +56 -12
- package/src/profile-store.ts +5 -0
- package/src/runtime/cloud.ts +3 -0
- package/src/runtime/command.ts +1 -1
- package/src/runtime/deployment.ts +120 -4
- package/src/runtime/development.ts +86 -13
- package/src/runtime/directory.ts +33 -0
- package/src/runtime/execution.ts +12 -2
- package/src/runtime/helpers.ts +57 -8
- package/src/runtime/jujutsu.ts +225 -0
- package/src/runtime/languages.ts +106 -19
- package/src/runtime/package.ts +3 -0
- package/src/runtime/system.ts +202 -0
- package/src/runtime/types.ts +3 -0
- package/src/runtime/version-requirements.ts +30 -0
- package/src/runtime/workspace.ts +12 -1
- package/src/settings-agent.ts +80 -0
- package/src/settings-chat-transcript.ts +140 -0
- package/src/settings-chat-ui.ts +426 -0
- package/src/settings-draft.ts +260 -0
- package/src/settings-snapshots.ts +41 -0
- package/dist/chunks/chunk-ADX4CY27.ts.map +0 -7
- package/dist/chunks/chunk-KZZKGGFW.ts.map +0 -7
- package/dist/chunks/chunk-PD457PX5.ts.map +0 -7
- package/dist/chunks/cloud-EPAEV4ZB.ts.map +0 -7
- package/dist/chunks/commands-C2VJ6ZBN.ts +0 -3374
- package/dist/chunks/commands-C2VJ6ZBN.ts.map +0 -7
- package/dist/chunks/deployment-7J54EHNR.ts.map +0 -7
- package/dist/chunks/development-IWJAAAEV.ts.map +0 -7
- package/dist/chunks/execution-P4WZALW2.ts.map +0 -7
- package/dist/chunks/languages-JO6R2PHL.ts +0 -168
- package/dist/chunks/languages-JO6R2PHL.ts.map +0 -7
- package/dist/chunks/package-H24VJEX3.ts.map +0 -7
- package/src/command-inspector.ts +0 -41
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
2
|
+
import { defineModule } from "./types.js";
|
|
3
|
+
import { workspaceModuleValues } from "./workspace-helpers.js";
|
|
4
|
+
|
|
5
|
+
export const memoryUsageModule = defineModule({
|
|
6
|
+
name: "memory_usage",
|
|
7
|
+
variables: ["symbol", "ram", "ram_pct", "swap", "swap_pct"],
|
|
8
|
+
defaults: {
|
|
9
|
+
format: "via $symbol[$ram( | $swap)]($style) ",
|
|
10
|
+
symbol: "🐏 ",
|
|
11
|
+
style: "white bold dimmed",
|
|
12
|
+
disabled: true,
|
|
13
|
+
},
|
|
14
|
+
options: { threshold: { kind: "number", default: 75, minimum: -100, maximum: 10_000 } },
|
|
15
|
+
values: (context) => workspaceModuleValues("memory_usage", context),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const batteryModule = defineModule({
|
|
19
|
+
name: "battery",
|
|
20
|
+
variables: ["symbol", "percentage"],
|
|
21
|
+
defaults: { format: "[$symbol$percentage]($style) ", symbol: "", style: "none", disabled: true },
|
|
22
|
+
displayDefaults: [{ threshold: 10, style: "red bold", hidden: false }],
|
|
23
|
+
styleVariables: ["style"],
|
|
24
|
+
resolveStyleVariables: ({ runtime, display }) => {
|
|
25
|
+
const raw = runtime.workspace?.modules.battery?.percentage_raw;
|
|
26
|
+
if (raw === undefined) return undefined;
|
|
27
|
+
const percentage = Number(raw);
|
|
28
|
+
if (!Number.isFinite(percentage)) return undefined;
|
|
29
|
+
// Battery thresholds are upper bounds, unlike context-usage display rules.
|
|
30
|
+
const selected = display.reduce<(typeof display)[number] | undefined>(
|
|
31
|
+
(best, rule) =>
|
|
32
|
+
percentage <= rule.threshold && (best === undefined || rule.threshold < best.threshold) ? rule : best,
|
|
33
|
+
undefined,
|
|
34
|
+
);
|
|
35
|
+
return selected && !selected.hidden ? { style: selected.style } : undefined;
|
|
36
|
+
},
|
|
37
|
+
options: {
|
|
38
|
+
full_symbol: { kind: "string", default: " ", allowEmpty: true },
|
|
39
|
+
charging_symbol: { kind: "string", default: " ", allowEmpty: true },
|
|
40
|
+
discharging_symbol: { kind: "string", default: " ", allowEmpty: true },
|
|
41
|
+
unknown_symbol: { kind: "string", default: " ", allowEmpty: true },
|
|
42
|
+
empty_symbol: { kind: "string", default: " ", allowEmpty: true },
|
|
43
|
+
},
|
|
44
|
+
values(context) {
|
|
45
|
+
const values = workspaceModuleValues("battery", context);
|
|
46
|
+
if (!values) return undefined;
|
|
47
|
+
const state = values.state;
|
|
48
|
+
const key = `${state === "full" || state === "charging" || state === "discharging" || state === "empty" ? state : "unknown"}_symbol`;
|
|
49
|
+
const symbol = context.options[key];
|
|
50
|
+
return { percentage: values.percentage, symbol: typeof symbol === "string" ? sanitizeTerminalText(symbol) : "" };
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export const systemModules = [memoryUsageModule, batteryModule] as const;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
const MAX_TIME_FORMAT_LENGTH = 256;
|
|
2
|
+
const MAX_TIME_ZONE_LENGTH = 128;
|
|
3
|
+
const MAX_TIME_RANGE_LENGTH = 64;
|
|
4
|
+
const FORMAT_TOKEN = /%%|%:z|%[HIMSpPRTrYmdFz]/gu;
|
|
5
|
+
|
|
6
|
+
interface ClockParts {
|
|
7
|
+
year: number;
|
|
8
|
+
month: number;
|
|
9
|
+
day: number;
|
|
10
|
+
hour: number;
|
|
11
|
+
minute: number;
|
|
12
|
+
second: number;
|
|
13
|
+
offsetSeconds: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface TimeOptions {
|
|
17
|
+
use_12hr?: unknown;
|
|
18
|
+
time_format?: unknown;
|
|
19
|
+
utc_time_offset?: unknown;
|
|
20
|
+
time_range?: unknown;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Only the latest configured zone is retained. The default local clock does not
|
|
24
|
+
// construct an Intl formatter, and no timer or filesystem operation is used here.
|
|
25
|
+
let cachedZone: { name: string; formatter: Intl.DateTimeFormat } | undefined;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Supported strftime tokens: %% %H %I %M %S %p %P %R %T %r %Y %m %d %F %z %:z.
|
|
29
|
+
* Other directives, flags, and formats over 256 characters fall back to the
|
|
30
|
+
* minutes-only Pi default. An empty format selects that default as well.
|
|
31
|
+
*/
|
|
32
|
+
export function formatClockTime(now: Date, options: TimeOptions): string | undefined {
|
|
33
|
+
if (!Number.isFinite(now.getTime())) return undefined;
|
|
34
|
+
// Starship gates visibility against local wall time, not the output zone.
|
|
35
|
+
if (!isInsideTimeRange(now, options.time_range)) return undefined;
|
|
36
|
+
const fallback = options.use_12hr === true ? "%I:%M %p" : "%H:%M";
|
|
37
|
+
const format = validTimeFormat(options.time_format) ? options.time_format : fallback;
|
|
38
|
+
const parts = clockParts(now, options.utc_time_offset);
|
|
39
|
+
const hour12 = parts.hour % 12 || 12;
|
|
40
|
+
const period = parts.hour < 12 ? "AM" : "PM";
|
|
41
|
+
const hours = pad(parts.hour);
|
|
42
|
+
const minutes = pad(parts.minute);
|
|
43
|
+
const seconds = pad(parts.second);
|
|
44
|
+
const date = `${parts.year.toString().padStart(4, "0")}-${pad(parts.month)}-${pad(parts.day)}`;
|
|
45
|
+
const tokens: Readonly<Record<string, string>> = {
|
|
46
|
+
"%%": "%",
|
|
47
|
+
"%H": hours,
|
|
48
|
+
"%I": pad(hour12),
|
|
49
|
+
"%M": minutes,
|
|
50
|
+
"%S": seconds,
|
|
51
|
+
"%p": period,
|
|
52
|
+
"%P": period.toLowerCase(),
|
|
53
|
+
"%R": `${hours}:${minutes}`,
|
|
54
|
+
"%T": `${hours}:${minutes}:${seconds}`,
|
|
55
|
+
// Jiff's %r uses an unpadded 12-hour value.
|
|
56
|
+
"%r": `${hour12}:${minutes}:${seconds} ${period}`,
|
|
57
|
+
"%Y": parts.year.toString().padStart(4, "0"),
|
|
58
|
+
"%m": pad(parts.month),
|
|
59
|
+
"%d": pad(parts.day),
|
|
60
|
+
"%F": date,
|
|
61
|
+
"%z": offsetText(parts.offsetSeconds, ""),
|
|
62
|
+
"%:z": offsetText(parts.offsetSeconds, ":"),
|
|
63
|
+
};
|
|
64
|
+
return format.replace(FORMAT_TOKEN, (token) => tokens[token] ?? token);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function validTimeFormat(format: unknown): format is string {
|
|
68
|
+
return (
|
|
69
|
+
typeof format === "string" &&
|
|
70
|
+
format.length > 0 &&
|
|
71
|
+
format.length <= MAX_TIME_FORMAT_LENGTH &&
|
|
72
|
+
!format.replace(FORMAT_TOKEN, "").includes("%")
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Range endpoints use HH:MM, HH:MM:SS, or HH:MM:SS.sss (1–3 fractional
|
|
78
|
+
* digits). Each endpoint is optional. Invalid endpoints are ignored separately;
|
|
79
|
+
* a missing or repeated hyphen disables the gate. Endpoints are exclusive,
|
|
80
|
+
* including equal endpoints, which exclude only that exact local wall time.
|
|
81
|
+
* Inputs over 64 characters disable the gate.
|
|
82
|
+
*/
|
|
83
|
+
export function isInsideTimeRange(now: Date, range: unknown): boolean {
|
|
84
|
+
if (typeof range !== "string" || range.length > MAX_TIME_RANGE_LENGTH) return true;
|
|
85
|
+
const endpoints = range.split("-");
|
|
86
|
+
if (endpoints.length !== 2) return true;
|
|
87
|
+
const start = parseRangeEndpoint(endpoints[0] ?? "");
|
|
88
|
+
const end = parseRangeEndpoint(endpoints[1] ?? "");
|
|
89
|
+
const current = ((now.getHours() * 60 + now.getMinutes()) * 60 + now.getSeconds()) * 1_000 + now.getMilliseconds();
|
|
90
|
+
if (start === undefined && end === undefined) return true;
|
|
91
|
+
if (start === undefined) return current < (end as number);
|
|
92
|
+
if (end === undefined) return current > start;
|
|
93
|
+
return start < end ? current > start && current < end : current > start || current < end;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function parseRangeEndpoint(value: string): number | undefined {
|
|
97
|
+
const match = /^(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?$/u.exec(value);
|
|
98
|
+
if (!match) return undefined;
|
|
99
|
+
const hour = Number(match[1]);
|
|
100
|
+
const minute = Number(match[2]);
|
|
101
|
+
const second = Number(match[3] ?? 0);
|
|
102
|
+
if (hour > 23 || minute > 59 || second > 59) return undefined;
|
|
103
|
+
return ((hour * 60 + minute) * 60 + second) * 1_000 + Number((match[4] ?? "").padEnd(3, "0"));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Zones are local, UTC, or an Intl-supported Area/Zone identifier. Numeric
|
|
107
|
+
// offsets allow an optional sign, 1–2 integer digits, and an optional 1–6 digit
|
|
108
|
+
// fraction, strictly between -24 and 24, truncated to seconds. Inputs over 128 characters
|
|
109
|
+
// and all other syntax fall back to local time.
|
|
110
|
+
function clockParts(now: Date, zone: unknown): ClockParts {
|
|
111
|
+
if (typeof zone !== "string" || zone === "local" || zone.length > MAX_TIME_ZONE_LENGTH) return localParts(now);
|
|
112
|
+
if (/^[+-]?\d{1,2}(?:\.\d{1,6})?$/u.test(zone)) {
|
|
113
|
+
const hours = Number(zone);
|
|
114
|
+
if (hours > -24 && hours < 24) {
|
|
115
|
+
const offsetSeconds = Math.trunc(hours * 3_600);
|
|
116
|
+
const shifted = new Date(now.getTime() + offsetSeconds * 1_000);
|
|
117
|
+
return {
|
|
118
|
+
year: shifted.getUTCFullYear(),
|
|
119
|
+
month: shifted.getUTCMonth() + 1,
|
|
120
|
+
day: shifted.getUTCDate(),
|
|
121
|
+
hour: shifted.getUTCHours(),
|
|
122
|
+
minute: shifted.getUTCMinutes(),
|
|
123
|
+
second: shifted.getUTCSeconds(),
|
|
124
|
+
offsetSeconds,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return localParts(now);
|
|
128
|
+
}
|
|
129
|
+
if (!/^(?:UTC|[A-Za-z_]+(?:\/[A-Za-z0-9_+.-]+)+)$/u.test(zone)) return localParts(now);
|
|
130
|
+
try {
|
|
131
|
+
if (cachedZone?.name !== zone) {
|
|
132
|
+
cachedZone = {
|
|
133
|
+
name: zone,
|
|
134
|
+
formatter: new Intl.DateTimeFormat("en-US", {
|
|
135
|
+
timeZone: zone,
|
|
136
|
+
calendar: "iso8601",
|
|
137
|
+
numberingSystem: "latn",
|
|
138
|
+
year: "numeric",
|
|
139
|
+
month: "2-digit",
|
|
140
|
+
day: "2-digit",
|
|
141
|
+
hour: "2-digit",
|
|
142
|
+
minute: "2-digit",
|
|
143
|
+
second: "2-digit",
|
|
144
|
+
hourCycle: "h23",
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const values = Object.fromEntries(cachedZone.formatter.formatToParts(now).map(({ type, value }) => [type, value]));
|
|
149
|
+
const parts = {
|
|
150
|
+
year: Number(values.year),
|
|
151
|
+
month: Number(values.month),
|
|
152
|
+
day: Number(values.day),
|
|
153
|
+
hour: Number(values.hour),
|
|
154
|
+
minute: Number(values.minute),
|
|
155
|
+
second: Number(values.second),
|
|
156
|
+
};
|
|
157
|
+
const wallTime = new Date(0);
|
|
158
|
+
wallTime.setUTCFullYear(parts.year, parts.month - 1, parts.day);
|
|
159
|
+
wallTime.setUTCHours(parts.hour, parts.minute, parts.second, 0);
|
|
160
|
+
return {
|
|
161
|
+
...parts,
|
|
162
|
+
offsetSeconds: (wallTime.getTime() - Math.floor(now.getTime() / 1_000) * 1_000) / 1_000,
|
|
163
|
+
};
|
|
164
|
+
} catch {
|
|
165
|
+
return localParts(now);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function localParts(now: Date): ClockParts {
|
|
170
|
+
return {
|
|
171
|
+
year: now.getFullYear(),
|
|
172
|
+
month: now.getMonth() + 1,
|
|
173
|
+
day: now.getDate(),
|
|
174
|
+
hour: now.getHours(),
|
|
175
|
+
minute: now.getMinutes(),
|
|
176
|
+
second: now.getSeconds(),
|
|
177
|
+
offsetSeconds: -now.getTimezoneOffset() * 60,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function pad(value: number): string {
|
|
182
|
+
return value.toString().padStart(2, "0");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function offsetText(seconds: number, separator: string): string {
|
|
186
|
+
const absolute = Math.abs(seconds);
|
|
187
|
+
return `${seconds < 0 ? "-" : "+"}${pad(Math.floor(absolute / 3_600))}${separator}${pad(Math.floor((absolute % 3_600) / 60))}`;
|
|
188
|
+
}
|
package/src/modules/time.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatClockTime } from "./time-format.js";
|
|
1
2
|
import { defineModule } from "./types.js";
|
|
2
3
|
|
|
3
4
|
export const timeModule = defineModule({
|
|
@@ -9,9 +10,14 @@ export const timeModule = defineModule({
|
|
|
9
10
|
style: "bold yellow",
|
|
10
11
|
disabled: false,
|
|
11
12
|
},
|
|
12
|
-
|
|
13
|
+
options: {
|
|
14
|
+
use_12hr: { kind: "boolean", default: false },
|
|
15
|
+
time_format: { kind: "string", default: "", allowEmpty: true },
|
|
16
|
+
utc_time_offset: { kind: "string", default: "local" },
|
|
17
|
+
time_range: { kind: "string", default: "-", allowEmpty: true },
|
|
18
|
+
},
|
|
19
|
+
values: ({ runtime, options }) => {
|
|
20
|
+
const time = formatClockTime(runtime.now, options);
|
|
21
|
+
return time === undefined ? undefined : { time };
|
|
22
|
+
},
|
|
13
23
|
});
|
|
14
|
-
|
|
15
|
-
function formatTime(now: Date): string {
|
|
16
|
-
return `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}`;
|
|
17
|
-
}
|
package/src/modules/types.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface GitBranchSnapshot {
|
|
|
7
7
|
remoteName?: string;
|
|
8
8
|
remoteBranch?: string;
|
|
9
9
|
detached: boolean;
|
|
10
|
+
bare?: boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface GitCommitSnapshot {
|
|
@@ -27,6 +28,7 @@ export interface GitMetricsSnapshot {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export interface GitStatusSnapshot {
|
|
31
|
+
upToDate?: boolean;
|
|
30
32
|
ahead: number;
|
|
31
33
|
behind: number;
|
|
32
34
|
stashed: number;
|
|
@@ -74,6 +76,12 @@ export interface GitSnapshot {
|
|
|
74
76
|
worktree?: GitWorktreeSnapshot;
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
export interface JujutsuBookmark {
|
|
80
|
+
readonly name: string;
|
|
81
|
+
readonly remote: string;
|
|
82
|
+
readonly diverged: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
export interface WorkspaceSnapshot {
|
|
78
86
|
modules: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
79
87
|
styleSelectors?: Readonly<Record<string, string>>;
|
|
@@ -124,23 +132,51 @@ export interface ExtensionStatusPresentation {
|
|
|
124
132
|
styles: Readonly<Record<string, string>>;
|
|
125
133
|
}
|
|
126
134
|
|
|
127
|
-
export
|
|
135
|
+
export interface ModuleContextRule {
|
|
136
|
+
readonly context_pattern: string;
|
|
137
|
+
readonly user_pattern?: string;
|
|
138
|
+
readonly symbol?: string;
|
|
139
|
+
readonly style?: string;
|
|
140
|
+
readonly context_alias?: string;
|
|
141
|
+
readonly user_alias?: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface ModuleSubstitution {
|
|
145
|
+
readonly from: string;
|
|
146
|
+
readonly to: string;
|
|
147
|
+
readonly regex?: boolean;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type ModuleOptionValue =
|
|
151
|
+
| string
|
|
152
|
+
| boolean
|
|
153
|
+
| number
|
|
154
|
+
| readonly string[]
|
|
155
|
+
| Readonly<Record<string, string>>
|
|
156
|
+
| readonly ModuleContextRule[]
|
|
157
|
+
| readonly ModuleSubstitution[]
|
|
158
|
+
| readonly (string | readonly string[])[];
|
|
128
159
|
|
|
129
160
|
export interface ModuleValueContext {
|
|
130
161
|
runtime: StarshipRuntimeSnapshot;
|
|
131
162
|
palette: ColorPalette;
|
|
132
163
|
symbol: string;
|
|
164
|
+
styles?: Readonly<Record<string, string>>;
|
|
165
|
+
requestedVariables?: ReadonlySet<string>;
|
|
133
166
|
options: Readonly<Record<string, ModuleOptionValue>>;
|
|
134
167
|
extensionStatus: ExtensionStatusPresentation;
|
|
135
168
|
}
|
|
136
169
|
|
|
137
170
|
export type ModuleOptionSchema =
|
|
138
|
-
| { kind: "string"; default: string; allowEmpty?: boolean }
|
|
171
|
+
| { kind: "string"; default: string; allowEmpty?: boolean; templateVariables?: readonly string[] }
|
|
139
172
|
| { kind: "string-enum"; default: string; values: readonly string[] }
|
|
140
173
|
| { kind: "boolean"; default: boolean }
|
|
141
|
-
| { kind: "integer"; default: number; minimum: number; maximum: number }
|
|
174
|
+
| { kind: "integer" | "number"; default: number; minimum: number; maximum: number }
|
|
142
175
|
| { kind: "string-array"; default: readonly string[]; allowNegative?: boolean }
|
|
143
|
-
| { kind: "string-map"; default: Readonly<Record<string, string>> }
|
|
176
|
+
| { kind: "string-map"; default: Readonly<Record<string, string>> }
|
|
177
|
+
| { kind: "command-alternatives"; default: readonly (string | readonly string[])[] }
|
|
178
|
+
| { kind: "context-rules"; default: readonly ModuleContextRule[] }
|
|
179
|
+
| { kind: "substitutions"; default: Readonly<Record<string, string>> | readonly ModuleSubstitution[] };
|
|
144
180
|
|
|
145
181
|
export interface ModuleDisplayConfig {
|
|
146
182
|
threshold: number;
|
|
@@ -165,6 +201,7 @@ export interface ModuleStyleContext {
|
|
|
165
201
|
style: string;
|
|
166
202
|
styles: Readonly<Record<string, string>>;
|
|
167
203
|
display: readonly ModuleDisplayConfig[];
|
|
204
|
+
options: Readonly<Record<string, ModuleOptionValue>>;
|
|
168
205
|
}
|
|
169
206
|
|
|
170
207
|
export type ModuleStyleSelector = (context: ModuleStyleContext) => string | undefined;
|
|
@@ -181,6 +218,7 @@ export interface ModuleDefinition<Name extends string> {
|
|
|
181
218
|
resolveStyleVariables?(context: ModuleStyleContext): Readonly<Record<string, string>> | undefined;
|
|
182
219
|
options?: Readonly<Record<string, ModuleOptionSchema>>;
|
|
183
220
|
layout?: "fill";
|
|
221
|
+
resolveFormat?(context: ModuleValueContext, values: Readonly<Record<string, FormatValue>>): string | undefined;
|
|
184
222
|
values(context: ModuleValueContext): Record<string, FormatValue> | undefined;
|
|
185
223
|
}
|
|
186
224
|
|
package/src/pi-starship.ts
CHANGED
|
@@ -76,6 +76,7 @@ interface GitRefreshInput {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
interface PiStarshipOptions {
|
|
79
|
+
gitExec?: WorkspaceExec;
|
|
79
80
|
githubPrExec?: WorkspaceExec;
|
|
80
81
|
}
|
|
81
82
|
|
|
@@ -91,6 +92,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
91
92
|
let sessionGeneration = 0;
|
|
92
93
|
let menuController = new AbortController();
|
|
93
94
|
let commandInFlight: object | undefined;
|
|
95
|
+
let chatCleanup: (() => Promise<void>) | undefined;
|
|
94
96
|
let sessionOwner: ExtensionContext["sessionManager"] | undefined;
|
|
95
97
|
let activeTarget: RefreshTarget | undefined;
|
|
96
98
|
let eventDebounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -106,12 +108,23 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
106
108
|
const requirements = reachableModuleRequirements(input.config);
|
|
107
109
|
const gitReachable =
|
|
108
110
|
[...requirements.keys()].some((name) => name.startsWith("git_")) ||
|
|
109
|
-
(requirements.has("directory") &&
|
|
111
|
+
(requirements.has("directory") &&
|
|
112
|
+
(input.config.modules.directory.options.truncate_to_repo === true ||
|
|
113
|
+
Boolean(input.config.modules.directory.options.repo_root_format) ||
|
|
114
|
+
Boolean(input.config.modules.directory.styles.repo_root_style)));
|
|
110
115
|
if (!gitReachable) return undefined;
|
|
111
116
|
try {
|
|
112
117
|
return await readGitSnapshot(pi, input.cwd, {
|
|
113
118
|
includeMetrics: requirements.has("git_metrics"),
|
|
114
|
-
includeTag:
|
|
119
|
+
includeTag:
|
|
120
|
+
(requirements.get("git_commit")?.has("tag") ?? false) &&
|
|
121
|
+
input.config.modules.git_commit.options.tag_disabled !== true,
|
|
122
|
+
statusIgnoreSubmodules: input.config.modules.git_status.options.ignore_submodules === true,
|
|
123
|
+
metricsIgnoreSubmodules: input.config.modules.git_metrics.options.ignore_submodules === true,
|
|
124
|
+
tagMaxCandidates: input.config.modules.git_commit.options.tag_max_candidates as number,
|
|
125
|
+
inspectBare:
|
|
126
|
+
requirements.has("git_branch") && input.config.modules.git_branch.options.ignore_bare_repo === false,
|
|
127
|
+
exec: options.gitExec ?? execWorkspaceCommand,
|
|
115
128
|
signal,
|
|
116
129
|
});
|
|
117
130
|
} catch {
|
|
@@ -300,10 +313,20 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
300
313
|
requestRefresh(target, "periodic");
|
|
301
314
|
// Collectors publish only changed snapshots. The clock is the sole value
|
|
302
315
|
// that changes without publication; reuse the last render's session data.
|
|
303
|
-
if (!lastRender
|
|
316
|
+
if (!lastRender) return;
|
|
317
|
+
const clock = reachableModuleRequirements(lastRender.config).get("time");
|
|
318
|
+
const range = lastRender.config.modules.time.options.time_range;
|
|
319
|
+
if (!clock || (!clock.has("time") && (!range || range === "-"))) return;
|
|
304
320
|
const now = new Date();
|
|
305
321
|
const previous = lastRender.snapshot.now;
|
|
306
|
-
if (
|
|
322
|
+
if (
|
|
323
|
+
!lastRender.config.modules.time.options.time_format &&
|
|
324
|
+
lastRender.config.modules.time.options.utc_time_offset === "local" &&
|
|
325
|
+
(!range || range === "-") &&
|
|
326
|
+
now.getHours() === previous.getHours() &&
|
|
327
|
+
now.getMinutes() === previous.getMinutes()
|
|
328
|
+
)
|
|
329
|
+
return;
|
|
307
330
|
const lines = wrapFormattedStatusline(
|
|
308
331
|
renderStatusline(
|
|
309
332
|
lastRender.config,
|
|
@@ -362,6 +385,12 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
362
385
|
const configPath = settingsFilePath(getAgentDir());
|
|
363
386
|
const commandOptions: StarshipCommandOptions = {
|
|
364
387
|
settingsPath: configPath,
|
|
388
|
+
registerChatCleanup(cleanup) {
|
|
389
|
+
chatCleanup = cleanup;
|
|
390
|
+
return () => {
|
|
391
|
+
if (chatCleanup === cleanup) chatCleanup = undefined;
|
|
392
|
+
};
|
|
393
|
+
},
|
|
365
394
|
getLoaded: () => loaded ?? loadStarshipConfig(configPath),
|
|
366
395
|
getLoadedRevision: () => loadedRevision,
|
|
367
396
|
getInspection: () => {
|
|
@@ -401,7 +430,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
401
430
|
},
|
|
402
431
|
};
|
|
403
432
|
pi.registerCommand("starship", {
|
|
404
|
-
description: "
|
|
433
|
+
description: "Configure the footer with agent, presets, profiles, and recovery",
|
|
405
434
|
getArgumentCompletions: completeStarshipArguments,
|
|
406
435
|
handler: async (args, ctx) => {
|
|
407
436
|
const interactive = ctx.mode === "tui" && (!args.trim() || args.trim().toLowerCase() === "settings");
|
|
@@ -441,7 +470,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
441
470
|
refresh();
|
|
442
471
|
});
|
|
443
472
|
|
|
444
|
-
pi.on("session_shutdown", (_event, ctx) => {
|
|
473
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
445
474
|
if (sessionOwner !== ctx.sessionManager) return;
|
|
446
475
|
sessionOwner = undefined;
|
|
447
476
|
commandInFlight = undefined;
|
|
@@ -465,6 +494,9 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
465
494
|
runtime.footerWidth = undefined;
|
|
466
495
|
ctx.ui.setFooter(undefined);
|
|
467
496
|
ctx.ui.setStatus("starship", undefined);
|
|
497
|
+
const cleanup = chatCleanup;
|
|
498
|
+
chatCleanup = undefined;
|
|
499
|
+
await cleanup?.();
|
|
468
500
|
});
|
|
469
501
|
|
|
470
502
|
pi.on("model_select", () => refresh());
|
|
@@ -576,12 +608,24 @@ const ENVIRONMENT_ALLOWLIST = [
|
|
|
576
608
|
|
|
577
609
|
function allowlistedEnvironment(config: StarshipConfig): Record<string, string | undefined> {
|
|
578
610
|
const result: Record<string, string | undefined> = {};
|
|
579
|
-
const configured = config.modules
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
611
|
+
const configured = Object.values(config.modules)
|
|
612
|
+
.flatMap((module) => {
|
|
613
|
+
const names = module.options.detect_env_vars;
|
|
614
|
+
return Array.isArray(names) ? names.filter((name): name is string => typeof name === "string") : [];
|
|
615
|
+
})
|
|
616
|
+
.map((name) => name.replace(/^!/u, ""))
|
|
617
|
+
.filter((name) => /^[A-Za-z_][A-Za-z0-9_]*$/u.test(name));
|
|
618
|
+
const names = new Set([...ENVIRONMENT_ALLOWLIST, ...configured]);
|
|
619
|
+
for (const name of names) {
|
|
620
|
+
const value =
|
|
621
|
+
Object.hasOwn(process.env, name) && typeof process.env[name] === "string" ? process.env[name] : undefined;
|
|
622
|
+
Object.defineProperty(result, name, {
|
|
623
|
+
value,
|
|
624
|
+
enumerable: true,
|
|
625
|
+
configurable: true,
|
|
626
|
+
writable: true,
|
|
627
|
+
});
|
|
628
|
+
}
|
|
585
629
|
return result;
|
|
586
630
|
}
|
|
587
631
|
|
package/src/profile-store.ts
CHANGED
|
@@ -213,6 +213,11 @@ export function readProfile(settingsPath: string, name: string): ProfileDocument
|
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
/** Reject a removed, replaced, or edited profile before applying its reviewed snapshot. */
|
|
217
|
+
export function assertProfileUnchanged(settingsPath: string, expected: ProfileDocument): void {
|
|
218
|
+
assertExpected(readProfile(settingsPath, expected.name), expected);
|
|
219
|
+
}
|
|
220
|
+
|
|
216
221
|
export function listProfiles(settingsPath: string): ProfileDocument[] {
|
|
217
222
|
const directory = profileDirectory(settingsPath);
|
|
218
223
|
if (!checkedDirectory(directory)) return [];
|
package/src/runtime/cloud.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { parse as parseYaml } from "yaml";
|
|
3
3
|
import {
|
|
4
|
+
detectEnvironment,
|
|
4
5
|
exactAlias,
|
|
5
6
|
isRecord,
|
|
6
7
|
joinHome,
|
|
7
8
|
MAX_METADATA_FILE_BYTES,
|
|
8
9
|
optionBoolean,
|
|
9
10
|
optionMap,
|
|
11
|
+
optionStrings,
|
|
10
12
|
parseIni,
|
|
11
13
|
safeMetadata,
|
|
12
14
|
} from "./helpers.js";
|
|
@@ -55,6 +57,7 @@ async function collectAws(context: CollectorContext): Promise<Record<string, str
|
|
|
55
57
|
|
|
56
58
|
async function collectGcloud(context: CollectorContext): Promise<Record<string, string> | undefined> {
|
|
57
59
|
const env = context.input.environment;
|
|
60
|
+
if (!detectEnvironment(env, optionStrings(context, "gcloud", "detect_env_vars"))) return undefined;
|
|
58
61
|
const directory = safeMetadata(env.CLOUDSDK_CONFIG, 1_024) ?? joinHome(context.input, ".config", "gcloud");
|
|
59
62
|
const active =
|
|
60
63
|
safeMetadata(env.CLOUDSDK_ACTIVE_CONFIG_NAME) ??
|
package/src/runtime/command.ts
CHANGED
|
@@ -107,7 +107,7 @@ export const execWorkspaceCommand: WorkspaceExec = async (command, args, options
|
|
|
107
107
|
function explicitEnvironment(source: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv {
|
|
108
108
|
const result: NodeJS.ProcessEnv = Object.create(null);
|
|
109
109
|
for (const [name, value] of Object.entries(source)) {
|
|
110
|
-
if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(name) || value
|
|
110
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(name) || typeof value !== "string" || value.includes("\0")) {
|
|
111
111
|
continue;
|
|
112
112
|
}
|
|
113
113
|
Object.defineProperty(result, name, {
|