@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
|
@@ -36,7 +36,11 @@ export const miseModule = developmentModule({
|
|
|
36
36
|
format: "via [$symbol$health]($style) ",
|
|
37
37
|
symbol: "mise ",
|
|
38
38
|
style: "bold purple",
|
|
39
|
-
options:
|
|
39
|
+
options: {
|
|
40
|
+
...directDetection,
|
|
41
|
+
healthy_symbol: { kind: "string", default: "healthy" },
|
|
42
|
+
unhealthy_symbol: { kind: "string", default: "issues" },
|
|
43
|
+
},
|
|
40
44
|
});
|
|
41
45
|
|
|
42
46
|
export const direnvModule = developmentModule({
|
|
@@ -45,7 +49,15 @@ export const direnvModule = developmentModule({
|
|
|
45
49
|
format: "[$symbol$loaded]($style) ",
|
|
46
50
|
symbol: "direnv ",
|
|
47
51
|
style: "bold bright-yellow",
|
|
48
|
-
options:
|
|
52
|
+
options: {
|
|
53
|
+
...directDetection,
|
|
54
|
+
detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
|
|
55
|
+
allowed_msg: { kind: "string", default: "allowed" },
|
|
56
|
+
not_allowed_msg: { kind: "string", default: "not allowed" },
|
|
57
|
+
denied_msg: { kind: "string", default: "denied" },
|
|
58
|
+
loaded_msg: { kind: "string", default: "loaded" },
|
|
59
|
+
unloaded_msg: { kind: "string", default: "not loaded" },
|
|
60
|
+
},
|
|
49
61
|
});
|
|
50
62
|
|
|
51
63
|
export const condaModule = defineModule({
|
|
@@ -59,6 +71,7 @@ export const condaModule = defineModule({
|
|
|
59
71
|
},
|
|
60
72
|
options: {
|
|
61
73
|
ignore_base: { kind: "boolean", default: true },
|
|
74
|
+
detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
|
|
62
75
|
truncation_length: { kind: "integer", default: 1, minimum: 0, maximum: 1_000_000 },
|
|
63
76
|
},
|
|
64
77
|
values: (context) => {
|
|
@@ -91,6 +104,11 @@ export const nixShellModule = developmentModule({
|
|
|
91
104
|
format: "via [$symbol$state( \\($name\\))]($style) ",
|
|
92
105
|
symbol: " ",
|
|
93
106
|
style: "bold blue",
|
|
107
|
+
// No unknown_msg: unknown shells require unsupported heuristic discovery from PATH.
|
|
108
|
+
options: {
|
|
109
|
+
pure_msg: { kind: "string", default: "pure" },
|
|
110
|
+
impure_msg: { kind: "string", default: "impure" },
|
|
111
|
+
},
|
|
94
112
|
});
|
|
95
113
|
|
|
96
114
|
export const guixShellModule = developmentModule({
|
package/src/modules/directory.ts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { basename, isAbsolute, relative, sep } from "node:path";
|
|
2
2
|
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
3
|
+
import { replacePattern } from "../format/bounded-regex.js";
|
|
3
4
|
import { graphemes, toSlashPath, truncatePathComponents, useNativePathSeparator } from "./truncation.js";
|
|
4
|
-
import { defineModule, type
|
|
5
|
+
import { defineModule, type ModuleValueContext } from "./types.js";
|
|
6
|
+
|
|
7
|
+
export const DIRECTORY_REPO_ROOT_FORMAT =
|
|
8
|
+
"[ $symbol ]($style)[$before_root_path]($before_repo_root_style)[$repo_root]($repo_root_style)[$path ]($style)[$read_only]($read_only_style)";
|
|
9
|
+
const MAX_SUBSTITUTED_PATH_LENGTH = 16_384;
|
|
10
|
+
const MAX_SUBSTITUTIONS = 64;
|
|
5
11
|
|
|
6
12
|
export const directoryModule = defineModule({
|
|
7
13
|
name: "directory",
|
|
8
|
-
variables: ["symbol", "path", "full_path"],
|
|
14
|
+
variables: ["symbol", "path", "full_path", "before_root_path", "repo_root", "read_only"],
|
|
9
15
|
defaults: {
|
|
10
16
|
format: "[ $symbol $path ]($style)",
|
|
11
17
|
symbol: "📁",
|
|
12
18
|
style: "cyan bold",
|
|
13
19
|
disabled: false,
|
|
14
20
|
},
|
|
21
|
+
fallbackStyle: true,
|
|
22
|
+
styleDefaults: { repo_root_style: "", before_repo_root_style: "", read_only_style: "red" },
|
|
23
|
+
styleVariables: ["style", "repo_root_style", "before_repo_root_style", "read_only_style"],
|
|
24
|
+
resolveStyleVariables: ({ style, styles }) => ({
|
|
25
|
+
style,
|
|
26
|
+
repo_root_style: styles.repo_root_style || style,
|
|
27
|
+
before_repo_root_style: styles.before_repo_root_style || style,
|
|
28
|
+
read_only_style: styles.read_only_style ?? "red",
|
|
29
|
+
}),
|
|
15
30
|
options: {
|
|
16
31
|
truncation_length: { kind: "integer", default: 3, minimum: 0, maximum: 1_000_000 },
|
|
17
32
|
truncate_to_repo: { kind: "boolean", default: true },
|
|
@@ -19,48 +34,161 @@ export const directoryModule = defineModule({
|
|
|
19
34
|
truncation_symbol: { kind: "string", default: "" },
|
|
20
35
|
home_symbol: { kind: "string", default: "~" },
|
|
21
36
|
use_os_path_sep: { kind: "boolean", default: true },
|
|
22
|
-
|
|
37
|
+
use_logical_path: { kind: "boolean", default: true },
|
|
38
|
+
// Empty is an inheritance sentinel, not an implicit second active format.
|
|
39
|
+
repo_root_format: { kind: "string", default: "", allowEmpty: true },
|
|
40
|
+
read_only: { kind: "string", default: "🔒", allowEmpty: true },
|
|
41
|
+
substitutions: { kind: "substitutions", default: {} },
|
|
23
42
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
resolveFormat: (context, values) =>
|
|
44
|
+
values.repo_root ? directoryAlternateFormat(context.options, context.styles) : undefined,
|
|
45
|
+
values: directoryValues,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** A second format is reachable only after an explicit format or root style. */
|
|
49
|
+
export function directoryAlternateFormat(
|
|
50
|
+
options: Readonly<Record<string, unknown>>,
|
|
51
|
+
styles: Readonly<Record<string, string>> = {},
|
|
52
|
+
): string | undefined {
|
|
53
|
+
return (
|
|
54
|
+
stringOption(options, "repo_root_format", "") || (styles.repo_root_style ? DIRECTORY_REPO_ROOT_FORMAT : undefined)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function directoryValues({ runtime, options, styles }: ModuleValueContext): Record<string, string> {
|
|
59
|
+
const metadata = runtime.workspace?.modules.directory;
|
|
60
|
+
// Pi exposes one cwd. Logical mode preserves it; physical mode consumes only
|
|
61
|
+
// cached runtime metadata, with the original cwd as the failure fallback.
|
|
62
|
+
const fullPath = sanitizeTerminalText(
|
|
63
|
+
booleanOption(options, "use_logical_path", true) ? runtime.cwd : metadata?.physical_path || runtime.cwd,
|
|
64
|
+
);
|
|
65
|
+
const home = runtime.homeDir === undefined ? undefined : sanitizeTerminalText(runtime.homeDir);
|
|
66
|
+
const repoRoot = runtime.gitRoot === undefined ? undefined : sanitizeTerminalText(runtime.gitRoot);
|
|
67
|
+
const homeSymbol = sanitizeTerminalText(stringOption(options, "home_symbol", "~"));
|
|
68
|
+
const truncateToRepo = booleanOption(options, "truncate_to_repo", true);
|
|
69
|
+
const substitutions = substitutionsOption(options);
|
|
70
|
+
const homeContracted = contractPath(fullPath, home, homeSymbol);
|
|
71
|
+
const repoPath = repoRoot ? contractRepositoryPath(fullPath, repoRoot) : undefined;
|
|
72
|
+
const repoContracted = truncateToRepo && repoRoot && (!home || !samePath(repoRoot, home)) ? repoPath : undefined;
|
|
73
|
+
const contracted = repoContracted ?? homeContracted;
|
|
74
|
+
const substituted = substitutePath(contracted, substitutions);
|
|
75
|
+
const componentResult = truncatePathComponents(substituted, numberOption(options, "truncation_length", 3));
|
|
76
|
+
let path = componentResult.value;
|
|
77
|
+
let prefix = "";
|
|
78
|
+
if (repoContracted !== undefined || componentResult.truncated) {
|
|
79
|
+
const fishLength = numberOption(options, "fish_style_pwd_dir_length", 0);
|
|
80
|
+
prefix =
|
|
81
|
+
fishLength > 0 && substitutions.length === 0
|
|
82
|
+
? fishPrefix(homeContracted, path, fishLength)
|
|
83
|
+
: sanitizeTerminalText(stringOption(options, "truncation_symbol", ""));
|
|
84
|
+
}
|
|
42
85
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
path = `${stringOption(options, "truncation_symbol", "")}${path}`;
|
|
53
|
-
}
|
|
86
|
+
let beforeRoot = "";
|
|
87
|
+
let root = "";
|
|
88
|
+
if (directoryAlternateFormat(options, styles) && repoPath !== undefined && repoRoot) {
|
|
89
|
+
const split = splitRepositoryPath(contracted, substituted, path, repoPath, repoRoot, substitutions);
|
|
90
|
+
if (split) {
|
|
91
|
+
beforeRoot = prefix + split.before;
|
|
92
|
+
root = split.root;
|
|
93
|
+
path = split.after;
|
|
94
|
+
prefix = "";
|
|
54
95
|
}
|
|
96
|
+
}
|
|
97
|
+
if (!root) path = prefix + path;
|
|
98
|
+
const fallback = basename(fullPath) || fullPath;
|
|
99
|
+
const native = booleanOption(options, "use_os_path_sep", true);
|
|
100
|
+
return {
|
|
101
|
+
path: sanitizeTerminalText(
|
|
102
|
+
native ? useNativePathSeparator(path || (root ? "" : fallback)) : path || (root ? "" : fallback),
|
|
103
|
+
),
|
|
104
|
+
before_root_path: sanitizeTerminalText(native ? useNativePathSeparator(beforeRoot) : beforeRoot),
|
|
105
|
+
repo_root: sanitizeTerminalText(native ? useNativePathSeparator(root) : root),
|
|
106
|
+
full_path: fullPath,
|
|
107
|
+
read_only: metadata?.read_only === "true" ? sanitizeTerminalText(stringOption(options, "read_only", "🔒")) : "",
|
|
108
|
+
};
|
|
109
|
+
}
|
|
55
110
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
111
|
+
interface Substitution {
|
|
112
|
+
readonly from: string;
|
|
113
|
+
readonly to: string;
|
|
114
|
+
readonly regex?: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function substitutionsOption(options: Readonly<Record<string, unknown>>): readonly Substitution[] {
|
|
118
|
+
const value = options.substitutions;
|
|
119
|
+
if (!value || typeof value !== "object") return [];
|
|
120
|
+
if (Array.isArray(value)) {
|
|
121
|
+
return value.flatMap((item: unknown) => {
|
|
122
|
+
if (!item || typeof item !== "object" || !("from" in item) || !("to" in item)) return [];
|
|
123
|
+
if (typeof item.from !== "string" || typeof item.to !== "string") return [];
|
|
124
|
+
return [
|
|
125
|
+
{
|
|
126
|
+
from: sanitizeTerminalText(item.from),
|
|
127
|
+
to: sanitizeTerminalText(item.to),
|
|
128
|
+
regex: "regex" in item && item.regex === true,
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return Object.entries(value).flatMap(([from, to]) =>
|
|
134
|
+
typeof to === "string" ? [{ from: sanitizeTerminalText(from), to: sanitizeTerminalText(to) }] : [],
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function substitutePath(path: string, substitutions: readonly Substitution[]): string {
|
|
139
|
+
if (path.length > MAX_SUBSTITUTED_PATH_LENGTH || substitutions.length > MAX_SUBSTITUTIONS) return path;
|
|
140
|
+
let result = path;
|
|
141
|
+
for (const { from, to, regex } of substitutions) {
|
|
142
|
+
// Preserve the existing Pi behavior for empty literal keys. Regex empty
|
|
143
|
+
// matches are handled by the bounded matcher instead.
|
|
144
|
+
if (!from && !regex) continue;
|
|
145
|
+
const next = regex ? replacePattern(from, result, to) : replaceLiteral(from, result, to);
|
|
146
|
+
// Like upstream's invalid-regex branch, a failed substitution discards the
|
|
147
|
+
// complete substitution sequence, not just its failing row.
|
|
148
|
+
if (next === undefined || next.length > MAX_SUBSTITUTED_PATH_LENGTH) return path;
|
|
149
|
+
result = next;
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function replaceLiteral(from: string, value: string, to: string): string | undefined {
|
|
155
|
+
const parts: string[] = [];
|
|
156
|
+
let offset = 0;
|
|
157
|
+
let length = 0;
|
|
158
|
+
while (true) {
|
|
159
|
+
const match = value.indexOf(from, offset);
|
|
160
|
+
const end = match === -1 ? value.length : match;
|
|
161
|
+
const part = value.slice(offset, end);
|
|
162
|
+
length += part.length + (match === -1 ? 0 : to.length);
|
|
163
|
+
if (length > MAX_SUBSTITUTED_PATH_LENGTH) return undefined;
|
|
164
|
+
parts.push(part);
|
|
165
|
+
if (match === -1) return parts.join("");
|
|
166
|
+
parts.push(to);
|
|
167
|
+
offset = match + from.length;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function splitRepositoryPath(
|
|
172
|
+
contracted: string,
|
|
173
|
+
substituted: string,
|
|
174
|
+
displayed: string,
|
|
175
|
+
repoPath: string,
|
|
176
|
+
repoRoot: string,
|
|
177
|
+
substitutions: readonly Substitution[],
|
|
178
|
+
): { before: string; root: string; after: string } | undefined {
|
|
179
|
+
if (!contracted.endsWith(repoPath) || !substituted.endsWith(displayed)) return undefined;
|
|
180
|
+
const rootName = basename(repoRoot) || toSlashPath(repoRoot);
|
|
181
|
+
const start = contracted.length - repoPath.length;
|
|
182
|
+
const before = substitutePath(contracted.slice(0, start), substitutions);
|
|
183
|
+
const root = substitutePath(rootName, substitutions);
|
|
184
|
+
const after = substitutePath(repoPath.slice(rootName.length), substitutions);
|
|
185
|
+
// A replacement spanning a style boundary has no unambiguous split. Preserve
|
|
186
|
+
// its exact path output through the normal format instead of dropping text.
|
|
187
|
+
if (!root || before + root + after !== substituted) return undefined;
|
|
188
|
+
const omitted = substituted.length - displayed.length;
|
|
189
|
+
if (before.length < omitted) return undefined;
|
|
190
|
+
return { before: before.slice(omitted), root, after };
|
|
191
|
+
}
|
|
64
192
|
|
|
65
193
|
function contractPath(path: string, root: string | undefined, replacement: string): string {
|
|
66
194
|
if (!root) return toSlashPath(path);
|
|
@@ -103,25 +231,17 @@ function abbreviateComponent(component: string, length: number): string {
|
|
|
103
231
|
return component.startsWith(".") ? parts.slice(0, length + 1).join("") : parts.slice(0, length).join("");
|
|
104
232
|
}
|
|
105
233
|
|
|
106
|
-
function numberOption(options: Readonly<Record<string,
|
|
234
|
+
function numberOption(options: Readonly<Record<string, unknown>>, name: string, fallback: number): number {
|
|
107
235
|
const value = options[name];
|
|
108
236
|
return typeof value === "number" ? value : fallback;
|
|
109
237
|
}
|
|
110
238
|
|
|
111
|
-
function stringOption(options: Readonly<Record<string,
|
|
239
|
+
function stringOption(options: Readonly<Record<string, unknown>>, name: string, fallback: string): string {
|
|
112
240
|
const value = options[name];
|
|
113
241
|
return typeof value === "string" ? value : fallback;
|
|
114
242
|
}
|
|
115
243
|
|
|
116
|
-
function booleanOption(options: Readonly<Record<string,
|
|
244
|
+
function booleanOption(options: Readonly<Record<string, unknown>>, name: string, fallback: boolean): boolean {
|
|
117
245
|
const value = options[name];
|
|
118
246
|
return typeof value === "boolean" ? value : fallback;
|
|
119
247
|
}
|
|
120
|
-
|
|
121
|
-
function mapOption(
|
|
122
|
-
options: Readonly<Record<string, ModuleOptionValue>>,
|
|
123
|
-
name: string,
|
|
124
|
-
): Readonly<Record<string, string>> {
|
|
125
|
-
const value = options[name];
|
|
126
|
-
return value && typeof value === "object" && !Array.isArray(value) ? (value as Readonly<Record<string, string>>) : {};
|
|
127
|
-
}
|
package/src/modules/execution.ts
CHANGED
|
@@ -42,6 +42,8 @@ export const hostnameModule = defineModule({
|
|
|
42
42
|
},
|
|
43
43
|
options: {
|
|
44
44
|
ssh_only: { kind: "boolean", default: true },
|
|
45
|
+
ssh_symbol: { kind: "string", default: "🌐 " },
|
|
46
|
+
detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
|
|
45
47
|
trim_at: { kind: "string", default: "." },
|
|
46
48
|
aliases: { kind: "string-map", default: {} },
|
|
47
49
|
},
|
|
@@ -15,17 +15,32 @@ export const gitBranchModule = defineModule({
|
|
|
15
15
|
// equivalent stable TOML representation in pi-starship's bounded integer schema.
|
|
16
16
|
truncation_length: { kind: "integer", default: 0, minimum: 0, maximum: 1_000_000 },
|
|
17
17
|
truncation_symbol: { kind: "string", default: "…" },
|
|
18
|
+
only_attached: { kind: "boolean", default: false },
|
|
19
|
+
// Pi formats historically expose both remote fields even for equal branches.
|
|
20
|
+
always_show_remote: { kind: "boolean", default: true },
|
|
21
|
+
ignore_branches: { kind: "string-array", default: [] },
|
|
22
|
+
ignore_remotes: { kind: "string-array", default: [] },
|
|
23
|
+
// The existing status collector does not expose bare repositories.
|
|
24
|
+
ignore_bare_repo: { kind: "boolean", default: true },
|
|
18
25
|
},
|
|
19
26
|
values: ({ runtime, options }) => {
|
|
20
27
|
const branch = runtime.gitBranchDetails;
|
|
21
28
|
const name = branch?.name ?? runtime.gitBranch;
|
|
22
|
-
if (!name) return undefined;
|
|
29
|
+
if (!name || (options.only_attached === true && branch?.detached)) return undefined;
|
|
30
|
+
if (options.ignore_bare_repo !== false && branch?.bare) return undefined;
|
|
31
|
+
if (Array.isArray(options.ignore_branches) && options.ignore_branches.includes(name)) return undefined;
|
|
23
32
|
const length = typeof options.truncation_length === "number" ? options.truncation_length : 0;
|
|
24
33
|
const symbol = typeof options.truncation_symbol === "string" ? options.truncation_symbol : "…";
|
|
34
|
+
const truncatedName = truncateLeadingGraphemes(name, length, symbol);
|
|
35
|
+
const remoteBranch = truncateLeadingGraphemes(branch?.remoteBranch ?? "", length, symbol);
|
|
36
|
+
const showRemote = options.always_show_remote !== false || (remoteBranch !== "" && remoteBranch !== truncatedName);
|
|
37
|
+
const ignoreRemote =
|
|
38
|
+
Array.isArray(options.ignore_remotes) && options.ignore_remotes.includes(branch?.remoteName ?? "");
|
|
25
39
|
return {
|
|
26
|
-
branch:
|
|
27
|
-
remote_name:
|
|
28
|
-
|
|
40
|
+
branch: truncatedName,
|
|
41
|
+
remote_name:
|
|
42
|
+
showRemote && !ignoreRemote ? truncateLeadingGraphemes(branch?.remoteName ?? "", length, symbol) : "",
|
|
43
|
+
remote_branch: showRemote ? remoteBranch : "",
|
|
29
44
|
};
|
|
30
45
|
},
|
|
31
46
|
});
|
|
@@ -13,15 +13,22 @@ export const gitCommitModule = defineModule({
|
|
|
13
13
|
},
|
|
14
14
|
options: {
|
|
15
15
|
commit_hash_length: { kind: "integer", default: DEFAULT_HASH_LENGTH, minimum: 0, maximum: 64 },
|
|
16
|
+
only_detached: { kind: "boolean", default: false },
|
|
17
|
+
tag_symbol: { kind: "string", default: " 🏷 " },
|
|
18
|
+
tag_disabled: { kind: "boolean", default: false },
|
|
19
|
+
tag_max_candidates: { kind: "integer", default: 0, minimum: 0, maximum: 100 },
|
|
16
20
|
},
|
|
17
21
|
values: ({ runtime, options }) => {
|
|
18
22
|
const commit = runtime.gitCommit;
|
|
19
|
-
if (!commit) return undefined;
|
|
23
|
+
if (!commit || (options.only_detached === true && !commit.detached)) return undefined;
|
|
20
24
|
const hashLength =
|
|
21
25
|
typeof options.commit_hash_length === "number" ? options.commit_hash_length : DEFAULT_HASH_LENGTH;
|
|
22
26
|
return {
|
|
23
27
|
hash: commit.hash.slice(0, hashLength),
|
|
24
|
-
tag:
|
|
28
|
+
tag:
|
|
29
|
+
commit.tag && options.tag_disabled !== true
|
|
30
|
+
? `${typeof options.tag_symbol === "string" ? options.tag_symbol : " 🏷 "}${commit.tag}`
|
|
31
|
+
: "",
|
|
25
32
|
};
|
|
26
33
|
},
|
|
27
34
|
});
|
|
@@ -15,12 +15,17 @@ export const gitMetricsModule = defineModule({
|
|
|
15
15
|
},
|
|
16
16
|
styleVariables: ["added_style", "deleted_style"],
|
|
17
17
|
resolveStyleVariables: ({ styles }) => styles,
|
|
18
|
-
|
|
18
|
+
options: {
|
|
19
|
+
only_nonzero_diffs: { kind: "boolean", default: true },
|
|
20
|
+
ignore_submodules: { kind: "boolean", default: false },
|
|
21
|
+
},
|
|
22
|
+
values: ({ runtime, options }) => {
|
|
19
23
|
const metrics = runtime.gitMetrics;
|
|
20
|
-
|
|
24
|
+
const onlyNonzero = options.only_nonzero_diffs !== false;
|
|
25
|
+
if (!metrics || (onlyNonzero && metrics.added === 0 && metrics.deleted === 0)) return undefined;
|
|
21
26
|
return {
|
|
22
|
-
added: metrics.added > 0 ? metrics.added.toString() : "",
|
|
23
|
-
deleted: metrics.deleted > 0 ? metrics.deleted.toString() : "",
|
|
27
|
+
added: !onlyNonzero || metrics.added > 0 ? metrics.added.toString() : "",
|
|
28
|
+
deleted: !onlyNonzero || metrics.deleted > 0 ? metrics.deleted.toString() : "",
|
|
24
29
|
};
|
|
25
30
|
},
|
|
26
31
|
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
3
3
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { execWorkspaceCommand } from "../../runtime/command.js";
|
|
5
|
+
import { MAX_COMMAND_OUTPUT_BYTES } from "../../runtime/helpers.js";
|
|
6
|
+
import type { WorkspaceExec } from "../../runtime/types.js";
|
|
4
7
|
import type {
|
|
5
8
|
GitBranchSnapshot,
|
|
6
9
|
GitCommitSnapshot,
|
|
@@ -16,6 +19,11 @@ const GIT_TIMEOUT_MS = 3_000;
|
|
|
16
19
|
export interface ReadGitSnapshotOptions {
|
|
17
20
|
includeMetrics: boolean;
|
|
18
21
|
includeTag: boolean;
|
|
22
|
+
statusIgnoreSubmodules?: boolean;
|
|
23
|
+
metricsIgnoreSubmodules?: boolean;
|
|
24
|
+
tagMaxCandidates?: number;
|
|
25
|
+
inspectBare?: boolean;
|
|
26
|
+
exec?: WorkspaceExec;
|
|
19
27
|
signal?: AbortSignal;
|
|
20
28
|
}
|
|
21
29
|
|
|
@@ -24,30 +32,36 @@ export async function readGitSnapshot(
|
|
|
24
32
|
cwd: string,
|
|
25
33
|
options: ReadGitSnapshotOptions,
|
|
26
34
|
): Promise<GitSnapshot | undefined> {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
if (options.signal?.aborted) return undefined;
|
|
36
|
+
const run = (args: string[]) => runGit(pi, cwd, args, options);
|
|
37
|
+
const statusArgs = [
|
|
38
|
+
"--no-optional-locks",
|
|
39
|
+
"status",
|
|
40
|
+
"--porcelain=v2",
|
|
41
|
+
"--branch",
|
|
42
|
+
"--show-stash",
|
|
43
|
+
"--untracked-files=normal",
|
|
44
|
+
];
|
|
45
|
+
// Upstream's status control ignores dirt inside submodules, not changed gitlinks.
|
|
46
|
+
if (options.statusIgnoreSubmodules) statusArgs.push("--ignore-submodules=dirty");
|
|
47
|
+
const statusPromise = run(statusArgs);
|
|
48
|
+
const metadataPromise = run([
|
|
49
|
+
"rev-parse",
|
|
50
|
+
"--path-format=absolute",
|
|
51
|
+
"--show-toplevel",
|
|
52
|
+
"--git-common-dir",
|
|
53
|
+
"--git-dir",
|
|
54
|
+
]);
|
|
55
|
+
const metricsArgs = ["--no-optional-locks", "diff", "--shortstat"];
|
|
56
|
+
if (options.metricsIgnoreSubmodules) metricsArgs.push("--ignore-submodules=all", "--no-ext-diff", "--no-textconv");
|
|
57
|
+
metricsArgs.push("HEAD", "--");
|
|
58
|
+
const metricsPromise = options.includeMetrics ? run(metricsArgs) : Promise.resolve(undefined);
|
|
59
|
+
const candidates = options.tagMaxCandidates;
|
|
60
|
+
const tagArgs =
|
|
61
|
+
Number.isSafeInteger(candidates) && (candidates ?? 0) > 0 && (candidates ?? 0) <= 100
|
|
62
|
+
? ["describe", "--tags", "--first-parent", "--abbrev=0", `--candidates=${candidates}`, "HEAD"]
|
|
63
|
+
: ["describe", "--tags", "--exact-match", "HEAD"];
|
|
64
|
+
const tagPromise = options.includeTag ? run(tagArgs) : Promise.resolve(undefined);
|
|
51
65
|
|
|
52
66
|
const [statusResult, metadataResult, metricsResult, tagResult] = await Promise.all([
|
|
53
67
|
statusPromise,
|
|
@@ -55,7 +69,10 @@ export async function readGitSnapshot(
|
|
|
55
69
|
metricsPromise,
|
|
56
70
|
tagPromise,
|
|
57
71
|
]);
|
|
58
|
-
if (
|
|
72
|
+
if (options.signal?.aborted || statusResult.killed) return undefined;
|
|
73
|
+
if (statusResult.code !== 0) {
|
|
74
|
+
return options.inspectBare ? readBareSnapshot(pi, cwd, options, tagResult) : undefined;
|
|
75
|
+
}
|
|
59
76
|
|
|
60
77
|
const parsed = parseGitStatusPorcelainV2(statusResult.stdout);
|
|
61
78
|
const metadata =
|
|
@@ -76,21 +93,88 @@ export async function readGitSnapshot(
|
|
|
76
93
|
};
|
|
77
94
|
}
|
|
78
95
|
|
|
96
|
+
type GitCommandResult = Awaited<ReturnType<ExtensionAPI["exec"]>>;
|
|
97
|
+
|
|
98
|
+
async function runGit(
|
|
99
|
+
pi: ExtensionAPI,
|
|
100
|
+
cwd: string,
|
|
101
|
+
args: string[],
|
|
102
|
+
options: Pick<ReadGitSnapshotOptions, "signal" | "exec">,
|
|
103
|
+
): Promise<GitCommandResult> {
|
|
104
|
+
const failed = { stdout: "", stderr: "", code: 1, killed: options.signal?.aborted ?? false };
|
|
105
|
+
if (options.signal?.aborted) return failed;
|
|
106
|
+
try {
|
|
107
|
+
const result = options.exec
|
|
108
|
+
? await options.exec("git", args, {
|
|
109
|
+
cwd,
|
|
110
|
+
timeout: GIT_TIMEOUT_MS,
|
|
111
|
+
maxOutputBytes: MAX_COMMAND_OUTPUT_BYTES,
|
|
112
|
+
signal: options.signal,
|
|
113
|
+
environment: process.env,
|
|
114
|
+
})
|
|
115
|
+
: await pi.exec("git", args, { cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS });
|
|
116
|
+
if (options.signal?.aborted) return { ...failed, killed: true };
|
|
117
|
+
if (Buffer.byteLength(result.stdout) + Buffer.byteLength(result.stderr) > MAX_COMMAND_OUTPUT_BYTES) {
|
|
118
|
+
return { ...failed, killed: true };
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
} catch {
|
|
122
|
+
return failed;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function readBareSnapshot(
|
|
127
|
+
pi: ExtensionAPI,
|
|
128
|
+
cwd: string,
|
|
129
|
+
options: ReadGitSnapshotOptions,
|
|
130
|
+
tagResult: GitCommandResult | undefined,
|
|
131
|
+
): Promise<GitSnapshot | undefined> {
|
|
132
|
+
const boundedOptions = { ...options, exec: options.exec ?? execWorkspaceCommand };
|
|
133
|
+
const run = (args: string[]) => runGit(pi, cwd, args, boundedOptions);
|
|
134
|
+
const bare = await run(["rev-parse", "--is-bare-repository"]);
|
|
135
|
+
if (options.signal?.aborted || bare.killed || bare.code !== 0 || bare.stdout.trim() !== "true") return undefined;
|
|
136
|
+
const [head, hash] = await Promise.all([
|
|
137
|
+
run(["symbolic-ref", "--short", "HEAD"]),
|
|
138
|
+
run(["rev-parse", "--verify", "HEAD"]),
|
|
139
|
+
]);
|
|
140
|
+
if (options.signal?.aborted || head.killed || hash.killed) return undefined;
|
|
141
|
+
const name = head.code === 0 ? head.stdout.trim() : "";
|
|
142
|
+
const commitHash = hash.code === 0 ? hash.stdout.trim() : "";
|
|
143
|
+
const validHash = /^[a-fA-F0-9]{4,64}$/u.test(commitHash);
|
|
144
|
+
if (!name && !validHash) return undefined;
|
|
145
|
+
const detached = name === "";
|
|
146
|
+
const reference = `refs/heads/${name}`;
|
|
147
|
+
const upstreamResult = name
|
|
148
|
+
? await run(["for-each-ref", "--count=1", "--format=%(refname)%00%(upstream:short)", reference])
|
|
149
|
+
: undefined;
|
|
150
|
+
if (options.signal?.aborted) return undefined;
|
|
151
|
+
const upstreamFields =
|
|
152
|
+
upstreamResult?.code === 0 && !upstreamResult.killed ? upstreamResult.stdout.trimEnd().split("\0") : [];
|
|
153
|
+
const remote = upstreamFields[0] === reference ? splitUpstream(upstreamFields[1]) : {};
|
|
154
|
+
return {
|
|
155
|
+
branch: { name: name || "HEAD", detached, bare: true, ...remote },
|
|
156
|
+
commit: validHash ? withTag({ hash: commitHash, detached }, tagResult) : undefined,
|
|
157
|
+
status: emptyGitStatus(),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
79
161
|
export async function readGitStatus(pi: ExtensionAPI, cwd: string): Promise<GitStatusSnapshot | undefined> {
|
|
80
|
-
const result = await
|
|
81
|
-
|
|
162
|
+
const result = await runGit(
|
|
163
|
+
pi,
|
|
164
|
+
cwd,
|
|
82
165
|
["--no-optional-locks", "status", "--porcelain=v2", "--branch", "--show-stash", "--untracked-files=normal"],
|
|
83
|
-
{
|
|
166
|
+
{},
|
|
84
167
|
);
|
|
85
168
|
if (result.code !== 0 || result.killed) return undefined;
|
|
86
169
|
return parseGitStatusPorcelainV2(result.stdout).status;
|
|
87
170
|
}
|
|
88
171
|
|
|
89
172
|
export async function readGitWorktree(pi: ExtensionAPI, cwd: string): Promise<GitWorktreeSnapshot | undefined> {
|
|
90
|
-
const result = await
|
|
91
|
-
|
|
173
|
+
const result = await runGit(
|
|
174
|
+
pi,
|
|
175
|
+
cwd,
|
|
92
176
|
["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
|
|
93
|
-
{
|
|
177
|
+
{},
|
|
94
178
|
);
|
|
95
179
|
if (result.code !== 0 || result.killed) return undefined;
|
|
96
180
|
return parseGitRepositoryMetadata(result.stdout)?.worktree;
|
|
@@ -125,8 +209,13 @@ export function parseGitStatusPorcelainV2(output: string): ParsedGitStatus {
|
|
|
125
209
|
}
|
|
126
210
|
if (line.startsWith("# branch.ab ")) {
|
|
127
211
|
const match = /^# branch\.ab \+(\d+) -(\d+)$/u.exec(line);
|
|
128
|
-
|
|
129
|
-
|
|
212
|
+
const ahead = Number(match?.[1]);
|
|
213
|
+
const behind = Number(match?.[2]);
|
|
214
|
+
const valid = Number.isSafeInteger(ahead) && Number.isSafeInteger(behind);
|
|
215
|
+
status.ahead = valid ? ahead : 0;
|
|
216
|
+
status.behind = valid ? behind : 0;
|
|
217
|
+
if (valid && ahead === 0 && behind === 0) status.upToDate = true;
|
|
218
|
+
else delete status.upToDate;
|
|
130
219
|
continue;
|
|
131
220
|
}
|
|
132
221
|
if (line.startsWith("# stash ")) {
|
package/src/modules/git/state.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { defineModule } from "../types.js";
|
|
2
2
|
|
|
3
|
+
const STATE_OPTIONS: Readonly<Record<string, string>> = {
|
|
4
|
+
REBASING: "rebase",
|
|
5
|
+
MERGING: "merge",
|
|
6
|
+
REVERTING: "revert",
|
|
7
|
+
"CHERRY-PICKING": "cherry_pick",
|
|
8
|
+
BISECTING: "bisect",
|
|
9
|
+
AM: "am",
|
|
10
|
+
"AM/REBASE": "am_or_rebase",
|
|
11
|
+
};
|
|
12
|
+
|
|
3
13
|
export const gitStateModule = defineModule({
|
|
4
14
|
name: "git_state",
|
|
5
15
|
variables: ["symbol", "state", "progress_current", "progress_total"],
|
|
@@ -9,11 +19,22 @@ export const gitStateModule = defineModule({
|
|
|
9
19
|
style: "bold yellow",
|
|
10
20
|
disabled: false,
|
|
11
21
|
},
|
|
12
|
-
|
|
22
|
+
options: {
|
|
23
|
+
rebase: { kind: "string", default: "REBASING" },
|
|
24
|
+
merge: { kind: "string", default: "MERGING" },
|
|
25
|
+
revert: { kind: "string", default: "REVERTING" },
|
|
26
|
+
cherry_pick: { kind: "string", default: "CHERRY-PICKING" },
|
|
27
|
+
bisect: { kind: "string", default: "BISECTING" },
|
|
28
|
+
am: { kind: "string", default: "AM" },
|
|
29
|
+
am_or_rebase: { kind: "string", default: "AM/REBASE" },
|
|
30
|
+
},
|
|
31
|
+
values: ({ runtime, options }) => {
|
|
13
32
|
const state = runtime.gitState;
|
|
14
33
|
if (!state) return undefined;
|
|
34
|
+
const key = STATE_OPTIONS[state.state];
|
|
35
|
+
const label = typeof key === "string" ? options[key] : undefined;
|
|
15
36
|
return {
|
|
16
|
-
state: state.state,
|
|
37
|
+
state: typeof label === "string" ? label : state.state,
|
|
17
38
|
progress_current: state.progressCurrent?.toString() ?? "",
|
|
18
39
|
progress_total: state.progressTotal?.toString() ?? "",
|
|
19
40
|
};
|