@narumitw/pi-starship 0.55.2 → 0.56.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 CHANGED
@@ -12,6 +12,7 @@ The extension parses and renders the footer itself, so it does not need the `sta
12
12
 
13
13
  - Starts with a readable built-in footer and offers Starship presets plus a Pi-native Minimal preset.
14
14
  - Supports root and module formats, conditional groups, `$all`, styles, palettes, and width-aware `$fill` alignment.
15
+ - Selects provider, model, and thinking styles from exact runtime values with ordered module rules.
15
16
  - Provides Pi, model, usage, Git, pull request, package, language, environment, deployment, cloud, and execution modules.
16
17
  - Wraps native multiline layouts to terminal width instead of truncating them.
17
18
  - Keeps rendering pure while refreshing filesystem, process, and network-derived data through bounded caches.
@@ -95,6 +96,7 @@ format = "$model$directory$git_branch"
95
96
  style = "bold blue"
96
97
  ```
97
98
 
99
+ Provider, model, and thinking modules also accept ordered exact-match `style_rules`; see [Configuration and format](./skills/configuring-pi-starship/references/configuration.md).
98
100
  Use `/starship` for interactive configuration, preview, diagnostics, presets, and recovery.
99
101
  Manual file edits load at the next `session_start`, including `/reload`.
100
102
 
@@ -1432,6 +1432,10 @@ var modelModule = defineModule({
1432
1432
  style: "bold blue",
1433
1433
  disabled: false
1434
1434
  },
1435
+ styleRuleSelectors: {
1436
+ provider: ({ runtime }) => runtime.model?.provider,
1437
+ model: ({ runtime }) => runtime.model?.id
1438
+ },
1435
1439
  options: {
1436
1440
  truncation_length: { kind: "integer", default: 0, minimum: 0, maximum: 1e3 },
1437
1441
  truncation_symbol: { kind: "string", default: "\u2026" },
@@ -1509,6 +1513,9 @@ var providerModule = defineModule({
1509
1513
  style: "bold blue",
1510
1514
  disabled: false
1511
1515
  },
1516
+ styleRuleSelectors: {
1517
+ provider: ({ runtime }) => runtime.model?.provider
1518
+ },
1512
1519
  options: {
1513
1520
  [PROVIDER_ALIASES_KEY]: { kind: "string-map", default: {} }
1514
1521
  },
@@ -1546,6 +1553,10 @@ var thinkingModule = defineModule({
1546
1553
  styleDefaults: Object.fromEntries(THINKING_LEVELS.map((level) => [`style_${level}`, ""])),
1547
1554
  fallbackStyle: true,
1548
1555
  styleVariables: ["style"],
1556
+ styleRuleSelectors: {
1557
+ provider: ({ runtime }) => runtime.model?.provider,
1558
+ level: ({ runtime }) => runtime.thinkingLevel
1559
+ },
1549
1560
  resolveStyleVariables: ({ runtime, styles, style }) => {
1550
1561
  const level = thinkingLevelOf(runtime.thinkingLevel);
1551
1562
  return { style: level && styles[`style_${level}`] || style };
@@ -1706,6 +1717,7 @@ var BUILT_IN_MODULES = Object.fromEntries(
1706
1717
  ...defaults,
1707
1718
  formatAst: parseFormat(defaults.format),
1708
1719
  styles: { ...styleDefaults },
1720
+ styleRules: [],
1709
1721
  display: structuredClone(displayDefaults ?? []),
1710
1722
  options: Object.fromEntries(
1711
1723
  Object.entries(options ?? {}).map(([key, schema]) => [key, cloneOptionValue(schema.default)])
@@ -1881,6 +1893,7 @@ function normalizeModule(name, value, config, diagnostics) {
1881
1893
  for (const field of Object.keys(definition.styleDefaults)) known.add(field);
1882
1894
  } else if (!definition.displayDefaults) known.add("style");
1883
1895
  if (definition.displayDefaults) known.add("display");
1896
+ if (definition.styleRuleSelectors) known.add("style_rules");
1884
1897
  if (name === "extension_status") {
1885
1898
  known.add("separator");
1886
1899
  known.add("max_statuses");
@@ -1934,6 +1947,15 @@ function normalizeModule(name, value, config, diagnostics) {
1934
1947
  diagnostics
1935
1948
  );
1936
1949
  }
1950
+ if (definition.styleRuleSelectors && value.style_rules !== void 0) {
1951
+ module.styleRules = normalizeStyleRules(
1952
+ name,
1953
+ value.style_rules,
1954
+ new Set(Object.keys(definition.styleRuleSelectors)),
1955
+ activePalette(config),
1956
+ diagnostics
1957
+ );
1958
+ }
1937
1959
  if (value.disabled !== void 0) {
1938
1960
  if (typeof value.disabled !== "boolean") {
1939
1961
  diagnostics.push(typeDiagnostic(`${name}.disabled`, "boolean"));
@@ -2054,6 +2076,7 @@ function cloneBuiltInConfig() {
2054
2076
  ...BUILT_IN_CONFIG.modules[name],
2055
2077
  formatAst: structuredClone(BUILT_IN_CONFIG.modules[name].formatAst),
2056
2078
  styles: { ...BUILT_IN_CONFIG.modules[name].styles },
2079
+ styleRules: structuredClone(BUILT_IN_CONFIG.modules[name].styleRules),
2057
2080
  display: structuredClone(BUILT_IN_CONFIG.modules[name].display),
2058
2081
  options: structuredClone(BUILT_IN_CONFIG.modules[name].options)
2059
2082
  }
@@ -2093,6 +2116,41 @@ function validateModuleStyleField(name, field, module, palette, diagnostics) {
2093
2116
  if (fallback !== void 0) module.styles[field] = fallback;
2094
2117
  }
2095
2118
  }
2119
+ function normalizeStyleRules(name, value, allowedSelectors, palette, diagnostics) {
2120
+ if (!Array.isArray(value)) {
2121
+ diagnostics.push(typeDiagnostic(`${name}.style_rules`, "array of tables"));
2122
+ return [];
2123
+ }
2124
+ const result = [];
2125
+ for (const [index, entry] of value.entries()) {
2126
+ const path = `${name}.style_rules.${index}`;
2127
+ if (!isRecord(entry)) {
2128
+ diagnostics.push(diagnostic("warning", path, "Expected a table; rule ignored"));
2129
+ continue;
2130
+ }
2131
+ let valid = true;
2132
+ for (const field of Object.keys(entry)) {
2133
+ if (field !== "style" && !allowedSelectors.has(field)) {
2134
+ diagnostics.push(diagnostic("warning", `${path}.${field}`, "Unknown style-rule field; rule ignored"));
2135
+ valid = false;
2136
+ }
2137
+ }
2138
+ if (typeof entry.style !== "string" || !isValidStyle(entry.style, palette)) {
2139
+ diagnostics.push(diagnostic("warning", `${path}.style`, "Expected a valid Starship style string; rule ignored"));
2140
+ valid = false;
2141
+ }
2142
+ const selectors = {};
2143
+ for (const selector of allowedSelectors) {
2144
+ if (entry[selector] === void 0) continue;
2145
+ if (typeof entry[selector] !== "string") {
2146
+ diagnostics.push(diagnostic("warning", `${path}.${selector}`, "Expected string; rule ignored"));
2147
+ valid = false;
2148
+ } else setOwn(selectors, selector, entry[selector]);
2149
+ }
2150
+ if (valid) result.push({ style: entry.style, selectors });
2151
+ }
2152
+ return result;
2153
+ }
2096
2154
  function normalizeDisplay(name, value, defaults, palette, diagnostics) {
2097
2155
  if (!Array.isArray(value)) {
2098
2156
  diagnostics.push(typeDiagnostic(`${name}.display`, "array of tables"));
@@ -2234,6 +2292,25 @@ import { stripVTControlCharacters } from "node:util";
2234
2292
 
2235
2293
  // src/modules/render.ts
2236
2294
  import { visibleWidth as visibleWidth2 } from "@earendil-works/pi-tui";
2295
+
2296
+ // src/modules/style-rules.ts
2297
+ function resolveStyleRule(rules, selectors, context) {
2298
+ for (const rule of rules) {
2299
+ let matches = true;
2300
+ for (const name in rule.selectors) {
2301
+ if (!Object.hasOwn(rule.selectors, name)) continue;
2302
+ const selector = Object.hasOwn(selectors, name) ? selectors[name] : void 0;
2303
+ if (!selector || selector(context) !== rule.selectors[name]) {
2304
+ matches = false;
2305
+ break;
2306
+ }
2307
+ }
2308
+ if (matches) return rule.style;
2309
+ }
2310
+ return void 0;
2311
+ }
2312
+
2313
+ // src/modules/render.ts
2237
2314
  function renderStatusline(config, runtime, width = 80, trueColor = true) {
2238
2315
  const palette = activePalette(config);
2239
2316
  const modules = {};
@@ -2247,14 +2324,17 @@ function renderStatusline(config, runtime, width = 80, trueColor = true) {
2247
2324
  const module = config.modules[name];
2248
2325
  const values = definition.values(valueContext(config, name, runtime));
2249
2326
  if (!values) continue;
2250
- const styleVariables2 = definition.resolveStyleVariables ? definition.resolveStyleVariables({
2327
+ const styleContext = {
2251
2328
  runtime,
2252
2329
  values,
2253
2330
  style: module.style,
2254
2331
  styles: module.styles,
2255
2332
  display: module.display
2256
- }) : { style: module.style };
2257
- if (!styleVariables2) continue;
2333
+ };
2334
+ const baseStyleVariables = definition.resolveStyleVariables ? definition.resolveStyleVariables(styleContext) : { style: module.style };
2335
+ if (!baseStyleVariables) continue;
2336
+ const ruleStyle = definition.styleRuleSelectors ? resolveStyleRule(module.styleRules, definition.styleRuleSelectors, styleContext) : void 0;
2337
+ const styleVariables2 = ruleStyle === void 0 ? baseStyleVariables : { ...baseStyleVariables, style: ruleStyle };
2258
2338
  const contentValues = Object.fromEntries(
2259
2339
  definition.variables.flatMap(
2260
2340
  (variable) => variable !== "symbol" && Object.hasOwn(values, variable) ? [[variable, values[variable]]] : []
@@ -2414,6 +2494,8 @@ function moduleInspection(config, definition, state, preview, rootReferenced, re
2414
2494
  preview,
2415
2495
  variables: [...definition.variables],
2416
2496
  styleFields: ["style", ...Object.keys(module.styles)],
2497
+ styleRuleSelectors: Object.keys(definition.styleRuleSelectors ?? {}),
2498
+ styleRuleCount: module.styleRules.length,
2417
2499
  displayRules: module.display.map(
2418
2500
  (rule) => `${rule.threshold}: ${rule.hidden ? "hidden" : rule.style || "unstyled"}`
2419
2501
  ),
@@ -2460,4 +2542,4 @@ export {
2460
2542
  inspectStatuslineModules,
2461
2543
  inspectUnavailableModules
2462
2544
  };
2463
- //# sourceMappingURL=chunk-JO5PH6FN.js.map
2545
+ //# sourceMappingURL=chunk-SD7TUSSU.js.map