@narumitw/pi-starship 0.60.1 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +67 -9
  2. package/dist/chunks/chunk-63R6R5DH.ts +679 -0
  3. package/dist/chunks/chunk-63R6R5DH.ts.map +7 -0
  4. package/dist/chunks/{chunk-KZZKGGFW.ts → chunk-A65IOGL6.ts} +858 -1007
  5. package/dist/chunks/chunk-A65IOGL6.ts.map +7 -0
  6. package/dist/chunks/chunk-IYDZ3R2T.ts +69 -0
  7. package/dist/chunks/chunk-IYDZ3R2T.ts.map +7 -0
  8. package/dist/chunks/chunk-KP33I6BR.ts +579 -0
  9. package/dist/chunks/chunk-KP33I6BR.ts.map +7 -0
  10. package/dist/chunks/{chunk-PD457PX5.ts → chunk-S2KBLHE2.ts} +75 -10
  11. package/dist/chunks/chunk-S2KBLHE2.ts.map +7 -0
  12. package/dist/chunks/chunk-XQUIQO2G.ts +20 -0
  13. package/dist/chunks/chunk-XQUIQO2G.ts.map +7 -0
  14. package/dist/chunks/{chunk-ADX4CY27.ts → chunk-XTLQ4WUL.ts} +1 -1
  15. package/dist/chunks/chunk-XTLQ4WUL.ts.map +7 -0
  16. package/dist/chunks/chunk-Y24TJYG6.ts +1586 -0
  17. package/dist/chunks/chunk-Y24TJYG6.ts.map +7 -0
  18. package/dist/chunks/{cloud-EPAEV4ZB.ts → cloud-J2ZOE3HE.ts} +6 -2
  19. package/dist/chunks/cloud-J2ZOE3HE.ts.map +7 -0
  20. package/dist/chunks/command-configuration-menu-YOLN2SPR.ts +147 -0
  21. package/dist/chunks/command-configuration-menu-YOLN2SPR.ts.map +7 -0
  22. package/dist/chunks/command-settings-chat-5AHP3JGV.ts +1124 -0
  23. package/dist/chunks/command-settings-chat-5AHP3JGV.ts.map +7 -0
  24. package/dist/chunks/commands-IOG2PL67.ts +1026 -0
  25. package/dist/chunks/commands-IOG2PL67.ts.map +7 -0
  26. package/dist/chunks/{deployment-7J54EHNR.ts → deployment-NOJ2KCLI.ts} +85 -5
  27. package/dist/chunks/deployment-NOJ2KCLI.ts.map +7 -0
  28. package/dist/chunks/{development-IWJAAAEV.ts → development-T3XXVVDP.ts} +67 -15
  29. package/dist/chunks/development-T3XXVVDP.ts.map +7 -0
  30. package/dist/chunks/directory-OX6BWJZA.ts +31 -0
  31. package/dist/chunks/directory-OX6BWJZA.ts.map +7 -0
  32. package/dist/chunks/{execution-P4WZALW2.ts → execution-R2OHIP2L.ts} +8 -4
  33. package/dist/chunks/execution-R2OHIP2L.ts.map +7 -0
  34. package/dist/chunks/jujutsu-XLDYKSX2.ts +174 -0
  35. package/dist/chunks/jujutsu-XLDYKSX2.ts.map +7 -0
  36. package/dist/chunks/languages-CBQNNYXM.ts +262 -0
  37. package/dist/chunks/languages-CBQNNYXM.ts.map +7 -0
  38. package/dist/chunks/{package-H24VJEX3.ts → package-7KVAK3TC.ts} +6 -2
  39. package/dist/chunks/package-7KVAK3TC.ts.map +7 -0
  40. package/dist/chunks/system-574MHB4R.ts +165 -0
  41. package/dist/chunks/system-574MHB4R.ts.map +7 -0
  42. package/dist/index.ts +670 -206
  43. package/dist/index.ts.map +4 -4
  44. package/package.json +5 -1
  45. package/skills/configure-pi-starship/SKILL.md +17 -1
  46. package/skills/configure-pi-starship/references/configuration.md +119 -32
  47. package/skills/configure-pi-starship/references/module-catalog.md +278 -25
  48. package/skills/configure-pi-starship/references/modules.md +213 -36
  49. package/skills/configure-pi-starship/references/runtime-and-security.md +88 -28
  50. package/src/command-commit.ts +41 -7
  51. package/src/command-configuration-menu.ts +155 -0
  52. package/src/command-configuration.ts +15 -94
  53. package/src/command-preview.ts +3 -3
  54. package/src/command-settings-chat.ts +168 -0
  55. package/src/commands.ts +76 -124
  56. package/src/config/module-options.ts +112 -0
  57. package/src/config.ts +23 -59
  58. package/src/effective-config.ts +5 -4
  59. package/src/format/bounded-regex.ts +66 -0
  60. package/src/format/version.ts +24 -0
  61. package/src/modules/catalog.ts +10 -0
  62. package/src/modules/cloud.ts +1 -0
  63. package/src/modules/deployment.ts +8 -0
  64. package/src/modules/development.ts +20 -2
  65. package/src/modules/directory.ts +171 -51
  66. package/src/modules/execution.ts +2 -0
  67. package/src/modules/git/branch.ts +19 -4
  68. package/src/modules/git/commit.ts +9 -2
  69. package/src/modules/git/metrics.ts +9 -4
  70. package/src/modules/git/runtime.ts +122 -33
  71. package/src/modules/git/state.ts +23 -2
  72. package/src/modules/git/status-templates.ts +58 -0
  73. package/src/modules/git/status.ts +96 -30
  74. package/src/modules/jujutsu.ts +225 -0
  75. package/src/modules/languages.ts +26 -2
  76. package/src/modules/package.ts +1 -0
  77. package/src/modules/render.ts +42 -16
  78. package/src/modules/system.ts +54 -0
  79. package/src/modules/time-format.ts +188 -0
  80. package/src/modules/time.ts +11 -5
  81. package/src/modules/types.ts +42 -4
  82. package/src/pi-starship.ts +198 -88
  83. package/src/profile-store.ts +5 -0
  84. package/src/runtime/cloud.ts +3 -0
  85. package/src/runtime/command.ts +1 -1
  86. package/src/runtime/deployment.ts +120 -4
  87. package/src/runtime/development.ts +86 -13
  88. package/src/runtime/directory.ts +33 -0
  89. package/src/runtime/execution.ts +12 -2
  90. package/src/runtime/helpers.ts +57 -8
  91. package/src/runtime/jujutsu.ts +225 -0
  92. package/src/runtime/languages.ts +106 -19
  93. package/src/runtime/package.ts +3 -0
  94. package/src/runtime/system.ts +202 -0
  95. package/src/runtime/types.ts +3 -0
  96. package/src/runtime/version-requirements.ts +30 -0
  97. package/src/runtime/workspace.ts +12 -1
  98. package/src/settings-agent.ts +80 -0
  99. package/src/settings-chat-transcript.ts +192 -0
  100. package/src/settings-chat-ui.ts +526 -0
  101. package/src/settings-draft.ts +260 -0
  102. package/src/settings-snapshots.ts +41 -0
  103. package/dist/chunks/chunk-ADX4CY27.ts.map +0 -7
  104. package/dist/chunks/chunk-KZZKGGFW.ts.map +0 -7
  105. package/dist/chunks/chunk-PD457PX5.ts.map +0 -7
  106. package/dist/chunks/cloud-EPAEV4ZB.ts.map +0 -7
  107. package/dist/chunks/commands-C2VJ6ZBN.ts +0 -3374
  108. package/dist/chunks/commands-C2VJ6ZBN.ts.map +0 -7
  109. package/dist/chunks/deployment-7J54EHNR.ts.map +0 -7
  110. package/dist/chunks/development-IWJAAAEV.ts.map +0 -7
  111. package/dist/chunks/execution-P4WZALW2.ts.map +0 -7
  112. package/dist/chunks/languages-JO6R2PHL.ts +0 -168
  113. package/dist/chunks/languages-JO6R2PHL.ts.map +0 -7
  114. package/dist/chunks/package-H24VJEX3.ts.map +0 -7
  115. package/src/command-inspector.ts +0 -41
@@ -0,0 +1,66 @@
1
+ import { RE2JS } from "re2js";
2
+
3
+ const MAX_PATTERN = 512;
4
+ const MAX_VALUE = 4_096;
5
+ const MAX_OUTPUT = 8_192;
6
+ const CACHE_SIZE = 64;
7
+ const patterns = new Map<string, RE2JS | null>();
8
+
9
+ // RE2 rejects backreferences and lookaround and matches without backtracking.
10
+ // Bound compilation, input, replacement, output, and retained compiled patterns.
11
+ function compile(pattern: string): RE2JS | undefined {
12
+ const sourceLength = pattern.startsWith("^(?:") && pattern.endsWith(")$") ? pattern.length - 6 : pattern.length;
13
+ if (sourceLength > MAX_PATTERN) return undefined;
14
+ if (patterns.has(pattern)) return patterns.get(pattern) ?? undefined;
15
+ let compiled: RE2JS | null;
16
+ try {
17
+ compiled = RE2JS.compile(pattern);
18
+ } catch {
19
+ compiled = null;
20
+ }
21
+ if (patterns.size >= CACHE_SIZE) {
22
+ const oldest = patterns.keys().next().value;
23
+ if (oldest !== undefined) patterns.delete(oldest);
24
+ }
25
+ patterns.set(pattern, compiled);
26
+ return compiled ?? undefined;
27
+ }
28
+
29
+ export function validPattern(pattern: string): boolean {
30
+ return pattern.length <= MAX_PATTERN && compile(pattern) !== undefined;
31
+ }
32
+
33
+ export function matchPattern(pattern: string, value: string, full = true): boolean {
34
+ if (value.length > MAX_VALUE) return false;
35
+ const compiled = compile(pattern);
36
+ if (!compiled) return false;
37
+ const matcher = compiled.matcher(value);
38
+ return full ? matcher.matches() : matcher.find();
39
+ }
40
+
41
+ /** Rust-style replacement fields: $1, $name, ${name}, and $$ for a literal $. */
42
+ export function replacePattern(pattern: string, value: string, replacement: string, all = false): string | undefined {
43
+ if (value.length > MAX_VALUE || replacement.length > MAX_VALUE) return undefined;
44
+ const compiled = compile(pattern);
45
+ if (!compiled) return undefined;
46
+ const matcher = compiled.matcher(value);
47
+ let result = "";
48
+ let end = 0;
49
+ while (matcher.find()) {
50
+ result += value.slice(end, matcher.start());
51
+ result += replacement.replace(/\$(?:\{([A-Za-z_0-9]+)\}|([A-Za-z_0-9]+)|(\$))/gu, (_, braced, plain, dollar) => {
52
+ if (dollar) return "$";
53
+ const field = braced ?? plain;
54
+ try {
55
+ return matcher.group(/^\d+$/u.test(field) ? Number(field) : field) ?? "";
56
+ } catch {
57
+ return "";
58
+ }
59
+ });
60
+ if (result.length > MAX_OUTPUT) return undefined;
61
+ end = matcher.end();
62
+ if (!all) break;
63
+ }
64
+ result += value.slice(end);
65
+ return result.length <= MAX_OUTPUT ? result : undefined;
66
+ }
@@ -0,0 +1,24 @@
1
+ import { parseFormat, renderFormat } from "./formatter.js";
2
+ import { isFillChunk } from "./style.js";
3
+
4
+ /** Use the package format grammar, without applying ANSI styles to the version value. */
5
+ export function formatVersion(raw: string, format: string | undefined): string {
6
+ // Collectors historically pass versions with a leading v. Keep the existing raw value.
7
+ const version = raw.replace(/^v/u, "");
8
+ const fallback = `v${version}`;
9
+ const template = format ?? "v$raw";
10
+ if (template.length > 4_096) return fallback;
11
+ // Only dotted numeric releases and an optional prerelease/build suffix expose components.
12
+ // Missing components stay absent; malformed releases keep only their raw value.
13
+ const release = /^(\d+(?:\.\d+)*)(?:[-+][0-9A-Za-z.+_-]+|[A-Za-z][0-9A-Za-z.+_-]*)?$/u.exec(version)?.[1];
14
+ const parts = release?.split(".").map((part) => part.replace(/^0+(?=\d)/u, ""));
15
+ try {
16
+ return renderFormat(parseFormat(template), {
17
+ variables: { raw: version, major: parts?.[0], minor: parts?.[1], patch: parts?.[2] },
18
+ })
19
+ .map((chunk) => (isFillChunk(chunk) ? "" : chunk.text))
20
+ .join("");
21
+ } catch {
22
+ return fallback;
23
+ }
24
+ }
@@ -17,10 +17,12 @@ import { gitStateModule } from "./git/state.js";
17
17
  import { gitStatusModule } from "./git/status.js";
18
18
  import { gitWorktreeModule } from "./git/worktree.js";
19
19
  import { githubPrModule } from "./github-pr.js";
20
+ import { jujutsuModules } from "./jujutsu.js";
20
21
  import { languageModules } from "./languages.js";
21
22
  import { modelModule } from "./model.js";
22
23
  import { packageModule } from "./package.js";
23
24
  import { providerModule } from "./provider.js";
25
+ import { systemModules } from "./system.js";
24
26
  import { thinkingModule } from "./thinking.js";
25
27
  import { timeModule } from "./time.js";
26
28
  import { tokensModule } from "./tokens.js";
@@ -40,12 +42,14 @@ const MODULE_IMPLEMENTATIONS = [
40
42
  gitStateModule,
41
43
  gitMetricsModule,
42
44
  gitStatusModule,
45
+ ...jujutsuModules,
43
46
  packageModule,
44
47
  ...languageModules,
45
48
  ...developmentModules,
46
49
  ...deploymentModules,
47
50
  ...cloudModules,
48
51
  ...executionModules,
52
+ ...systemModules,
49
53
  activityModule,
50
54
  contextModule,
51
55
  tokensModule,
@@ -64,6 +68,7 @@ const MODULE_DESCRIPTIONS = {
64
68
  activity: "Current Pi activity, extension UI wait, or most recently completed tool.",
65
69
  aws: "Active AWS profile and region.",
66
70
  azure: "Active Azure subscription and optional username.",
71
+ battery: "Local battery charge and charging state on supported platforms.",
67
72
  brand: "pi-starship brand mark.",
68
73
  bun: "Bun version detected in the current workspace.",
69
74
  cache: "Prompt-cache usage and latest cache hit rate.",
@@ -88,7 +93,12 @@ const MODULE_DESCRIPTIONS = {
88
93
  golang: "Go version detected in the current workspace.",
89
94
  guix_shell: "Current Guix shell state.",
90
95
  hostname: "Current host name, normally shown for remote sessions.",
96
+ jj_bookmark: "Closest ancestor bookmark in the current Jujutsu repository.",
97
+ jj_change: "Current Jujutsu change and commit identity.",
98
+ jj_metrics: "Added and deleted lines in the current Jujutsu change.",
99
+ jj_status: "Current Jujutsu change status.",
91
100
  kubernetes: "Active Kubernetes context, namespace, cluster, and user.",
101
+ memory_usage: "Current system memory and available swap usage.",
92
102
  mise: "Current mise configuration health.",
93
103
  model: "Current Pi model.",
94
104
  nix_shell: "Current Nix shell state, name, and nesting level.",
@@ -44,6 +44,7 @@ export const gcloudModule = cloudModule({
44
44
  options: {
45
45
  project_aliases: { kind: "string-map", default: {} },
46
46
  region_aliases: { kind: "string-map", default: {} },
47
+ detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
47
48
  },
48
49
  });
49
50
 
@@ -32,7 +32,15 @@ export const kubernetesModule = defineModule({
32
32
  style: "cyan bold",
33
33
  disabled: false,
34
34
  },
35
+ resolveStyleVariables: ({ runtime, style }) => ({
36
+ style: runtime.workspace?.styleSelectors?.kubernetes ?? style,
37
+ }),
35
38
  options: {
39
+ detect_files: { kind: "string-array", default: [], allowNegative: true },
40
+ detect_extensions: { kind: "string-array", default: [], allowNegative: true },
41
+ detect_folders: { kind: "string-array", default: [], allowNegative: true },
42
+ detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
43
+ contexts: { kind: "context-rules", default: [] },
36
44
  context_aliases: { kind: "string-map", default: {} },
37
45
  namespace_aliases: { kind: "string-map", default: {} },
38
46
  cluster_aliases: { kind: "string-map", default: {} },
@@ -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: directDetection,
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: directDetection,
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({
@@ -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 ModuleOptionValue } from "./types.js";
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
- substitutions: { kind: "string-map", default: {} },
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
- values: ({ runtime, options }) => {
25
- const fullPath = runtime.cwd;
26
- const home = runtime.homeDir;
27
- const repoRoot = runtime.gitRoot;
28
- const homeSymbol = stringOption(options, "home_symbol", "~");
29
- const truncateToRepo = booleanOption(options, "truncate_to_repo", true);
30
- const substitutions = mapOption(options, "substitutions");
31
- const homeContracted = contractPath(fullPath, home, homeSymbol);
32
- const repoContracted =
33
- truncateToRepo && repoRoot && (!home || !samePath(repoRoot, home))
34
- ? contractRepositoryPath(fullPath, repoRoot)
35
- : undefined;
36
- let path = sanitizeTerminalText(repoContracted ?? homeContracted);
37
- let truncated = repoContracted !== undefined;
38
-
39
- for (const [from, to] of Object.entries(substitutions)) {
40
- if (from) path = path.replaceAll(from, to);
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
- const componentResult = truncatePathComponents(path, numberOption(options, "truncation_length", 3));
44
- path = componentResult.value;
45
- truncated ||= componentResult.truncated;
46
-
47
- if (truncated) {
48
- const fishLength = numberOption(options, "fish_style_pwd_dir_length", 0);
49
- if (fishLength > 0 && Object.keys(substitutions).length === 0) {
50
- path = `${fishPrefix(homeContracted, path, fishLength)}${path}`;
51
- } else {
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
- if (booleanOption(options, "use_os_path_sep", true)) path = useNativePathSeparator(path);
57
- const fallback = basename(fullPath) || fullPath;
58
- return {
59
- path: sanitizeTerminalText(path || fallback),
60
- full_path: sanitizeTerminalText(fullPath),
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, ModuleOptionValue>>, name: string, fallback: number): number {
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, ModuleOptionValue>>, name: string, fallback: string): 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, ModuleOptionValue>>, name: string, fallback: boolean): boolean {
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
- }
@@ -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: truncateLeadingGraphemes(name, length, symbol),
27
- remote_name: truncateLeadingGraphemes(branch?.remoteName ?? "", length, symbol),
28
- remote_branch: truncateLeadingGraphemes(branch?.remoteBranch ?? "", length, symbol),
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: commit.tag ? ` 🏷 ${commit.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
- values: ({ runtime }) => {
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
- if (!metrics || (metrics.added === 0 && metrics.deleted === 0)) return undefined;
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
  });