@narumitw/pi-starship 0.55.2 → 0.56.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md 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
 
@@ -16,8 +16,8 @@ function completeStarshipArguments(prefix) {
16
16
  // src/config.ts
17
17
  import { randomUUID } from "node:crypto";
18
18
  import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
19
- import { createRequire } from "node:module";
20
19
  import { dirname, join } from "node:path";
20
+ import { parse as parseToml } from "smol-toml";
21
21
 
22
22
  // src/format/style.ts
23
23
  function isFillChunk(chunk) {
@@ -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)])
@@ -1724,12 +1736,6 @@ var BUILT_IN_CONFIG = {
1724
1736
  var BUILT_IN_EXAMPLE = `# Native Pi modules with Starship-compatible format and style syntax.
1725
1737
  ${BUILT_IN_FORMAT_DOCUMENT}
1726
1738
  `;
1727
- var require2 = createRequire(import.meta.url);
1728
- var parseTomlImplementation;
1729
- function parseToml(document) {
1730
- parseTomlImplementation ??= require2("smol-toml").parse;
1731
- return parseTomlImplementation(document);
1732
- }
1733
1739
  function settingsFilePath(agentDir) {
1734
1740
  return join(agentDir, CONFIG_FILE_NAME);
1735
1741
  }
@@ -1881,6 +1887,7 @@ function normalizeModule(name, value, config, diagnostics) {
1881
1887
  for (const field of Object.keys(definition.styleDefaults)) known.add(field);
1882
1888
  } else if (!definition.displayDefaults) known.add("style");
1883
1889
  if (definition.displayDefaults) known.add("display");
1890
+ if (definition.styleRuleSelectors) known.add("style_rules");
1884
1891
  if (name === "extension_status") {
1885
1892
  known.add("separator");
1886
1893
  known.add("max_statuses");
@@ -1934,6 +1941,15 @@ function normalizeModule(name, value, config, diagnostics) {
1934
1941
  diagnostics
1935
1942
  );
1936
1943
  }
1944
+ if (definition.styleRuleSelectors && value.style_rules !== void 0) {
1945
+ module.styleRules = normalizeStyleRules(
1946
+ name,
1947
+ value.style_rules,
1948
+ new Set(Object.keys(definition.styleRuleSelectors)),
1949
+ activePalette(config),
1950
+ diagnostics
1951
+ );
1952
+ }
1937
1953
  if (value.disabled !== void 0) {
1938
1954
  if (typeof value.disabled !== "boolean") {
1939
1955
  diagnostics.push(typeDiagnostic(`${name}.disabled`, "boolean"));
@@ -2054,6 +2070,7 @@ function cloneBuiltInConfig() {
2054
2070
  ...BUILT_IN_CONFIG.modules[name],
2055
2071
  formatAst: structuredClone(BUILT_IN_CONFIG.modules[name].formatAst),
2056
2072
  styles: { ...BUILT_IN_CONFIG.modules[name].styles },
2073
+ styleRules: structuredClone(BUILT_IN_CONFIG.modules[name].styleRules),
2057
2074
  display: structuredClone(BUILT_IN_CONFIG.modules[name].display),
2058
2075
  options: structuredClone(BUILT_IN_CONFIG.modules[name].options)
2059
2076
  }
@@ -2093,6 +2110,41 @@ function validateModuleStyleField(name, field, module, palette, diagnostics) {
2093
2110
  if (fallback !== void 0) module.styles[field] = fallback;
2094
2111
  }
2095
2112
  }
2113
+ function normalizeStyleRules(name, value, allowedSelectors, palette, diagnostics) {
2114
+ if (!Array.isArray(value)) {
2115
+ diagnostics.push(typeDiagnostic(`${name}.style_rules`, "array of tables"));
2116
+ return [];
2117
+ }
2118
+ const result = [];
2119
+ for (const [index, entry] of value.entries()) {
2120
+ const path = `${name}.style_rules.${index}`;
2121
+ if (!isRecord(entry)) {
2122
+ diagnostics.push(diagnostic("warning", path, "Expected a table; rule ignored"));
2123
+ continue;
2124
+ }
2125
+ let valid = true;
2126
+ for (const field of Object.keys(entry)) {
2127
+ if (field !== "style" && !allowedSelectors.has(field)) {
2128
+ diagnostics.push(diagnostic("warning", `${path}.${field}`, "Unknown style-rule field; rule ignored"));
2129
+ valid = false;
2130
+ }
2131
+ }
2132
+ if (typeof entry.style !== "string" || !isValidStyle(entry.style, palette)) {
2133
+ diagnostics.push(diagnostic("warning", `${path}.style`, "Expected a valid Starship style string; rule ignored"));
2134
+ valid = false;
2135
+ }
2136
+ const selectors = {};
2137
+ for (const selector of allowedSelectors) {
2138
+ if (entry[selector] === void 0) continue;
2139
+ if (typeof entry[selector] !== "string") {
2140
+ diagnostics.push(diagnostic("warning", `${path}.${selector}`, "Expected string; rule ignored"));
2141
+ valid = false;
2142
+ } else setOwn(selectors, selector, entry[selector]);
2143
+ }
2144
+ if (valid) result.push({ style: entry.style, selectors });
2145
+ }
2146
+ return result;
2147
+ }
2096
2148
  function normalizeDisplay(name, value, defaults, palette, diagnostics) {
2097
2149
  if (!Array.isArray(value)) {
2098
2150
  diagnostics.push(typeDiagnostic(`${name}.display`, "array of tables"));
@@ -2234,6 +2286,25 @@ import { stripVTControlCharacters } from "node:util";
2234
2286
 
2235
2287
  // src/modules/render.ts
2236
2288
  import { visibleWidth as visibleWidth2 } from "@earendil-works/pi-tui";
2289
+
2290
+ // src/modules/style-rules.ts
2291
+ function resolveStyleRule(rules, selectors, context) {
2292
+ for (const rule of rules) {
2293
+ let matches = true;
2294
+ for (const name in rule.selectors) {
2295
+ if (!Object.hasOwn(rule.selectors, name)) continue;
2296
+ const selector = Object.hasOwn(selectors, name) ? selectors[name] : void 0;
2297
+ if (!selector || selector(context) !== rule.selectors[name]) {
2298
+ matches = false;
2299
+ break;
2300
+ }
2301
+ }
2302
+ if (matches) return rule.style;
2303
+ }
2304
+ return void 0;
2305
+ }
2306
+
2307
+ // src/modules/render.ts
2237
2308
  function renderStatusline(config, runtime, width = 80, trueColor = true) {
2238
2309
  const palette = activePalette(config);
2239
2310
  const modules = {};
@@ -2247,14 +2318,17 @@ function renderStatusline(config, runtime, width = 80, trueColor = true) {
2247
2318
  const module = config.modules[name];
2248
2319
  const values = definition.values(valueContext(config, name, runtime));
2249
2320
  if (!values) continue;
2250
- const styleVariables2 = definition.resolveStyleVariables ? definition.resolveStyleVariables({
2321
+ const styleContext = {
2251
2322
  runtime,
2252
2323
  values,
2253
2324
  style: module.style,
2254
2325
  styles: module.styles,
2255
2326
  display: module.display
2256
- }) : { style: module.style };
2257
- if (!styleVariables2) continue;
2327
+ };
2328
+ const baseStyleVariables = definition.resolveStyleVariables ? definition.resolveStyleVariables(styleContext) : { style: module.style };
2329
+ if (!baseStyleVariables) continue;
2330
+ const ruleStyle = definition.styleRuleSelectors ? resolveStyleRule(module.styleRules, definition.styleRuleSelectors, styleContext) : void 0;
2331
+ const styleVariables2 = ruleStyle === void 0 ? baseStyleVariables : { ...baseStyleVariables, style: ruleStyle };
2258
2332
  const contentValues = Object.fromEntries(
2259
2333
  definition.variables.flatMap(
2260
2334
  (variable) => variable !== "symbol" && Object.hasOwn(values, variable) ? [[variable, values[variable]]] : []
@@ -2414,6 +2488,8 @@ function moduleInspection(config, definition, state, preview, rootReferenced, re
2414
2488
  preview,
2415
2489
  variables: [...definition.variables],
2416
2490
  styleFields: ["style", ...Object.keys(module.styles)],
2491
+ styleRuleSelectors: Object.keys(definition.styleRuleSelectors ?? {}),
2492
+ styleRuleCount: module.styleRules.length,
2417
2493
  displayRules: module.display.map(
2418
2494
  (rule) => `${rule.threshold}: ${rule.hidden ? "hidden" : rule.style || "unstyled"}`
2419
2495
  ),
@@ -2460,4 +2536,4 @@ export {
2460
2536
  inspectStatuslineModules,
2461
2537
  inspectUnavailableModules
2462
2538
  };
2463
- //# sourceMappingURL=chunk-JO5PH6FN.js.map
2539
+ //# sourceMappingURL=chunk-G2QRDLEN.js.map