@narumitw/pi-starship 0.43.0 → 0.44.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 @@ A native Pi footer configured with Starship-style TOML. It parses and renders fo
12
12
  - Starship-style root/module formats, conditional groups, `$all`, styles, and palettes.
13
13
  - Pi modules for model, thinking, activity, context, tokens, prompt cache, cost, turn, and extension statuses.
14
14
  - Cached Git branch, commit, operation state, line metrics, detailed status, and linked-worktree identity.
15
+ - Native current-branch GitHub pull request links, checks, review state, and terminal-state retention.
15
16
  - Opt-in package, language, development-shell, deployment, cloud, and execution-context modules.
16
17
  - Width-aware `$fill` alignment for native multiline left/right layouts.
17
18
  - Footer rendering is pure: no subprocess, network, filesystem, timer, or environment work runs from `render()`.
@@ -30,7 +31,7 @@ Try it from a checkout:
30
31
  pi -e ./extensions/pi-starship
31
32
  ```
32
33
 
33
- Do not enable this together with `@narumitw/pi-statusline`: both own Pi's footer. `pi-starship` warns when it detects the conflict.
34
+ Do not enable this together with `@narumitw/pi-statusline`: both own Pi's footer, and Pi does not arbitrate that conflict.
34
35
 
35
36
  ## ⚙️ Configuration
36
37
 
@@ -50,7 +51,7 @@ Open the interactive menu in TUI mode:
50
51
  /starship
51
52
  ```
52
53
 
53
- Choose **Customize footer** to edit the TOML. Closing the editor validates the draft and opens a width-aware preview; saving happens only after a separate confirmation. Confirmed changes are atomically saved and applied immediately. Editor cancellation, preview cancellation, invalid drafts, write failures, and runtime application failures preserve the previous file and effective footer.
54
+ Choose **Customize footer** to edit the TOML. Closing the editor validates the draft and opens a width-aware preview; saving happens only after a separate confirmation. Confirmed changes are atomically saved and applied immediately. Manual TOML edits load on the next `session_start`, including `/reload` and session replacement. Editor cancellation, preview cancellation, invalid drafts, write failures, and runtime application failures preserve the previous file and effective footer.
54
55
 
55
56
  The standard **Advanced** menu is one level deep and contains configuration details plus **Restore
56
57
  built-in**. Standard diagnostics, details, and help are Back-navigable detail screens. Restore still
@@ -59,7 +60,7 @@ shows the specialized width-aware preview and requires explicit overwrite confir
59
60
  ### 📝 Example
60
61
 
61
62
  ```toml
62
- format = "$brand$provider$model$thinking\n$directory$git_branch$git_status\n$activity$context$tokens$cache$cost$time$turn\n$extension_status"
63
+ format = "$brand$provider$model$thinking\n$directory$git_branch$github_pr$git_status\n$activity$context$tokens$cache$cost$time$turn\n$extension_status"
63
64
  palette = "tokyo-night"
64
65
 
65
66
  [palettes.tokyo-night]
@@ -91,7 +92,13 @@ disabled = false
91
92
  format = "[ $symbol \\$$cost( $subscription) ]($style)"
92
93
 
93
94
  [git_branch]
94
- format = "[ $symbol$branch$pr ]($style)"
95
+ format = "[ $symbol $branch ]($style)"
96
+
97
+ [github_pr]
98
+ format = "[ $symbol$link( · $status) ]($style)"
99
+ symbol = "PR "
100
+ style = "fg:git_fg bg:git"
101
+ disabled = false
95
102
 
96
103
  [package]
97
104
  version_format = "v$raw"
@@ -107,7 +114,7 @@ aliases = { "build.example.test" = "builder" }
107
114
 
108
115
  [extension_status]
109
116
  format = "([$statuses ]($style))"
110
- icons = { "github-pr" = "PR", "foo:*" = "🧪", "@narumitw/pi-goal" = "◎", fallback = "•" }
117
+ icons = { "foo:*" = "🧪", "third_party/key" = "◎", fallback = "•" }
111
118
  ```
112
119
 
113
120
  All module tables support `format`, `symbol`, `style`, and `disabled`. Module-specific
@@ -115,17 +122,19 @@ options are catalog-owned, type-checked, and listed below; unknown options warn
115
122
  Version formats replace `$raw`. Detection arrays replace defaults when non-empty and inspect only one
116
123
  listing of the current directory. A leading `!` is supported by language detection arrays and rejects
117
124
  a matching project.
118
- `[extension_status].icons` accepts arbitrary exact Pi status keys, explicit colon namespace
119
- wildcards such as `foo:*`, and installed package IDs; `fallback` controls unmatched statuses. Icon
120
- matching uses exact key, longest `:*` wildcard, unambiguous package alias, leading status emoji,
121
- built-in icon, then `fallback`/`🔌`. An empty icon suppresses only the icon. `foo:*` matches
122
- `foo:server` but not `foo`, `foobar`, or `foo/server`.
123
-
124
- Pi does not expose which package owns a status, so package aliases are best-effort conveniences and
125
- exact raw keys are the reliable third-party contract. Extension authors may adopt
126
- `<extension-id>` or `<extension-id>:<stable-slot>` for interoperability, but pi-starship cannot
127
- require that convention. Canonical built-ins use `sync` and `retry`; compatibility mappings keep
128
- `pisync` and `unknown-error-retry` settings and older producer versions working.
125
+ `[extension_status].icons` accepts arbitrary exact Pi status keys and explicit colon namespace
126
+ wildcards such as `foo:*`; `fallback` controls unmatched statuses. Icon matching uses the exact key,
127
+ the longest `:*` wildcard, a leading status emoji, then `fallback`/`🔌`. An empty configured icon
128
+ suppresses only the icon. `foo:*` matches `foo:server` but not `foo`, `foobar`, or `foo/server`.
129
+
130
+ Pi does not expose which package owns a status, so exact raw keys are the reliable third-party
131
+ contract. pi-starship does not inspect installed packages, infer package aliases, assign icons to
132
+ known extensions, or bridge compatibility keys. Extension authors may adopt `<extension-id>` or
133
+ `<extension-id>:<stable-slot>` for interoperability, but pi-starship does not require that convention.
134
+
135
+ **Icon migration:** configurations that relied on package-ID aliases, built-in known-extension icons,
136
+ or compatibility mappings must use an exact raw status key, an explicit namespace wildcard, a
137
+ leading emoji in the status value, or `fallback`.
129
138
 
130
139
  ## 🧩 Format grammar
131
140
 
@@ -162,7 +171,8 @@ An invalid root format falls back to the built-in root format. An invalid module
162
171
  | `thinking` | `$symbol`, `$level` | Thinking level |
163
172
  | `directory` | `$symbol`, `$path`, `$full_path` | Current working directory |
164
173
  | `git_worktree` | `$symbol`, `$name`, `$path` | Linked worktree name and top-level path |
165
- | `git_branch` | `$symbol`, `$branch`, `$remote_name`, `$remote_branch`, `$pr` | Branch, upstream, and actionable PR state |
174
+ | `git_branch` | `$symbol`, `$branch`, `$remote_name`, `$remote_branch` | Local branch and upstream |
175
+ | `github_pr` | `$symbol`, `$number`, `$link`, `$state`, `$checks`, `$review`, `$status` | Current-branch GitHub pull request |
166
176
  | `git_commit` | `$symbol`, `$hash`, `$tag` | Seven-character HEAD hash and optional exact tag |
167
177
  | `git_state` | `$symbol`, `$state`, `$progress_current`, `$progress_total` | Rebase, merge, revert, cherry-pick, bisect, or mail-apply state |
168
178
  | `git_metrics` | `$symbol`, `$added`, `$deleted` | Added/deleted line totals from the working tree diff |
@@ -248,7 +258,54 @@ truncation-direction setting.
248
258
 
249
259
  `git_commit`, `git_state`, and `git_metrics` are intentionally not present in the built-in root format. Add their variables to `format` to opt in; also set `[git_metrics].disabled = false`, matching Starship's opt-in metrics default. `$tag` resolves only an exact tag on HEAD and is queried only when the configured `git_commit` format references it.
250
260
 
251
- If `$git_branch.$pr` is present in the module format, its selected PR token is removed from `extension_status` to avoid duplication.
261
+ ### 🔎 Native GitHub pull requests
262
+
263
+ `$github_pr` is independent of `pi-github-pr`; installing that extension is not required. It runs one
264
+ bounded GitHub CLI query for the current branch:
265
+
266
+ ```text
267
+ gh pr view --json number,isDraft,url,state,closedAt,mergedAt,reviewDecision,statusCheckRollup
268
+ ```
269
+
270
+ Install and authenticate `gh` first:
271
+
272
+ ```bash
273
+ gh auth login
274
+ ```
275
+
276
+ For GitHub Enterprise Server, authenticate the repository host and keep that host in the repository
277
+ remote, for example `gh auth login --hostname github.example.com`. pi-starship starts `gh` directly
278
+ with child-only environment data that omits ambient `GH_HOST` and `GH_REPO` overrides, so `gh` resolves
279
+ the correct repository and host from the current checkout. It never mutates Pi's environment, calls
280
+ the GitHub API directly, or manages tokens.
281
+
282
+ Variables have these values:
283
+
284
+ - `$number`: digits such as `123`.
285
+ - `$link`: an OSC 8 `#123` link for a safe HTTP(S) URL, otherwise plain `#123`.
286
+ - `$state`: `open`, `draft`, `merged`, or `closed`.
287
+ - `$checks`: `checks passing`, `<n> failing`, `<n> pending`, or `no checks`.
288
+ - `$review`: `approved`, `changes requested`, `review required`, or empty when unknown.
289
+ - `$status`: one compact result selected in this order: merged, closed, draft, failing, changes
290
+ requested, pending, approved, review required, passing, then no checks.
291
+
292
+ The query runs only in TUI sessions when the enabled module is reachable from the root format. It
293
+ refreshes at session start, immediately after a branch change, after each agent run, after accepted
294
+ settings changes, and every 60 seconds. Each query has a 10-second timeout. Branch changes clear the
295
+ old PR before querying the new branch. Closed and merged PRs remain visible for 24 hours, then expire
296
+ without waiting for the next refresh. Missing `gh`, missing authentication, no current PR, timeout,
297
+ malformed or oversized output, and network failures all render an empty module without exposing raw
298
+ errors or credentials.
299
+
300
+ The query sends the repository/current-branch context through authenticated `gh` to the GitHub host
301
+ configured by the repository. It requests only the fields above—never comments, review bodies,
302
+ inline comments, or review threads. Footer rendering and previews read only the immutable cached
303
+ snapshot and perform no network or subprocess work.
304
+
305
+ **Breaking migration:** `$git_branch.$pr` has been removed without a compatibility alias or automatic
306
+ migration. Replace it with root `$github_pr` and an optional `[github_pr]` table. If `pi-github-pr`
307
+ remains installed, its independent `github-pr` status can also appear under `$extension_status`;
308
+ disable or remove that extension when adopting the native module to avoid duplicate information.
252
309
 
253
310
  ### 📦 Package and language modules
254
311
 
@@ -346,19 +403,22 @@ whole-catalog layout is intended. There is no `line_break` module; use literal n
346
403
 
347
404
  ### 🔄 Cached refresh lifecycle
348
405
 
349
- Workspace and Git readers start only in TUI sessions and only for reachable enabled modules. Root
350
- format reachability, `$all`, module `disabled`, and module-format variables determine file and command
351
- requirements. Refreshes run at session start, after accepted settings, branch changes, tool/turn
352
- completion, and a 30-second fallback. One read runs with at most one latest pending refresh; immutable
353
- snapshot equality suppresses redraws, and session/config generations reject stale results. Shutdown,
354
- replacement, and footer disposal stop timers, clear pending work, and prevent late publication.
355
- Execution identity is retained rather than re-read by the periodic fallback. Render and live preview
356
- consume snapshots synchronously and perform zero reads or commands.
406
+ Workspace, Git, and GitHub PR readers start only in TUI sessions and only for reachable enabled
407
+ modules. Root format reachability, `$all`, module `disabled`, and module-format variables determine
408
+ file and command requirements. Workspace/Git refreshes run at session start, after accepted settings,
409
+ branch changes, tool/turn completion, and a 30-second fallback. GitHub PR uses the narrower lifecycle
410
+ and 60-second network refresh described above. One read runs with at most one latest pending refresh;
411
+ immutable snapshot equality suppresses redraws, and session/request generations reject stale results.
412
+ Shutdown, replacement, footer disposal, branch changes, and accepted settings abort active command
413
+ work before starting replacements; disabling `github_pr` also stops its query and timers. Bounded local
414
+ filesystem operations may finish, but stale generations cannot publish them. Execution identity is
415
+ retained rather than re-read by the periodic fallback. Render and live preview consume snapshots
416
+ synchronously and perform zero reads or commands.
357
417
 
358
418
  Missing, unreadable, malformed, oversized, timed-out, or unavailable sources fail to empty values.
359
- Readers cap direct files at 64 KiB, use one bounded current-directory listing, never recurse, and make
360
- no network calls. Package's explicitly documented Cargo lookup is the only ancestor walk and is capped
361
- at eight parents.
419
+ Workspace/Git readers cap direct files at 64 KiB, use one bounded current-directory listing, never
420
+ recurse, and make no network calls. The native GitHub PR query is the documented network exception.
421
+ Package's explicitly documented Cargo lookup is the only ancestor walk and is capped at eight parents.
362
422
 
363
423
  ## 💬 Commands
364
424
 
@@ -393,7 +453,7 @@ modules until separately approved semantics exist.
393
453
 
394
454
  Create `src/modules/<name>.ts` with its format variables, defaults, and runtime value resolver, then register it in display order in `src/modules/catalog.ts`. Configuration names, validation variables, defaults, and `$all` ordering are derived from that catalog. Add the module to the built-in root format when it should be visible by default, then document and test its user-facing values.
395
455
 
396
- Keep `extension_status` last in the catalog so earlier modules can consume extension-owned status values without rendering duplicates.
456
+ Keep `extension_status` last in the catalog so arbitrary third-party statuses follow native module output.
397
457
 
398
458
  ## 🗂️ Package layout
399
459
 
@@ -404,13 +464,15 @@ Keep `extension_status` last in the catalog so earlier modules can consume exten
404
464
  - `src/config.ts` — TOML loading, draft validation, defaults, atomic persistence, and rollback.
405
465
  - `src/format/` — native format/style parser and renderer.
406
466
  - `src/modules/` — domain module definitions, ordered registry, reachability, and width-aware renderer.
407
- - `src/modules/git/` — bounded Git reader plus branch, status, and worktree modules.
467
+ - `src/modules/git/` — bounded local Git reader plus branch, status, and worktree modules.
468
+ - `src/modules/github-pr.ts` — pure native GitHub PR snapshot presentation.
469
+ - `src/runtime/github-pr.ts` — bounded `gh` query, validation, terminal-safe links, and expiry data.
408
470
  - `src/runtime/` — shared refresh controller and bounded package/language/context collectors.
409
471
 
410
472
  ## 🔎 Keywords
411
473
 
412
- Pi Coding Agent, Starship statusline, Starship TOML, terminal footer, native statusline, prompt cache,
413
- cache hit rate, Pi extension
474
+ Pi Coding Agent, Starship statusline, Starship TOML, terminal footer, native statusline, GitHub pull
475
+ request, prompt cache, cache hit rate, Pi extension
414
476
 
415
477
  ## 📄 License
416
478
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-starship",
3
- "version": "0.43.0",
3
+ "version": "0.44.0",
4
4
  "description": "Native Starship-style TOML statusline for the Pi coding agent.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/commands.ts CHANGED
@@ -60,6 +60,11 @@ interface MenuItem extends SelectItem {
60
60
  value: string;
61
61
  }
62
62
 
63
+ interface WorkflowOwner {
64
+ signal: AbortSignal;
65
+ isCurrent(): boolean;
66
+ }
67
+
63
68
  export function registerStarshipCommand(pi: ExtensionAPI, options: StarshipCommandOptions) {
64
69
  pi.registerCommand("starship", {
65
70
  description: "Customize or inspect the native Starship-style footer",
@@ -236,6 +241,8 @@ async function editSettings(
236
241
  ctx: ExtensionCommandContext,
237
242
  options: StarshipCommandOptions,
238
243
  ): Promise<boolean> {
244
+ const owner = workflowOwner(options);
245
+ if (!isCurrentOwner(owner)) return false;
239
246
  if (ctx.mode !== "tui") {
240
247
  if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${options.settingsPath}`, "info");
241
248
  return false;
@@ -243,7 +250,7 @@ async function editSettings(
243
250
  let draft = options.getLoaded().rawDocument ?? BUILT_IN_EXAMPLE;
244
251
  while (true) {
245
252
  const edited = await ctx.ui.editor("Customize footer — close to preview", draft);
246
- if (edited === undefined) return false;
253
+ if (!isCurrentOwner(owner) || edited === undefined) return false;
247
254
  draft = edited;
248
255
  let validated: LoadedStarshipConfig;
249
256
  try {
@@ -259,11 +266,12 @@ async function editSettings(
259
266
  { value: PREVIEW_ACTIONS.cancel, label: "Back" },
260
267
  ],
261
268
  );
269
+ if (!isCurrentOwner(owner)) return false;
262
270
  if (action === PREVIEW_ACTIONS.edit) continue;
263
271
  return false;
264
272
  }
265
273
 
266
- const result = await reviewAndApply(ctx, options, validated, "Footer preview", false);
274
+ const result = await reviewAndApply(ctx, options, validated, "Footer preview", false, owner);
267
275
  if (result === "edit") continue;
268
276
  return result === "applied";
269
277
  }
@@ -273,11 +281,15 @@ async function restoreBuiltIn(
273
281
  ctx: ExtensionCommandContext,
274
282
  options: StarshipCommandOptions,
275
283
  ): Promise<boolean> {
284
+ const owner = workflowOwner(options);
285
+ if (!isCurrentOwner(owner)) return false;
276
286
  const validated = (options.validate ?? validateConfigDocument)(
277
287
  options.settingsPath,
278
288
  BUILT_IN_EXAMPLE,
279
289
  );
280
- return (await reviewAndApply(ctx, options, validated, "Restore preview", true)) === "applied";
290
+ return (
291
+ (await reviewAndApply(ctx, options, validated, "Restore preview", true, owner)) === "applied"
292
+ );
281
293
  }
282
294
 
283
295
  async function reviewAndApply(
@@ -286,6 +298,7 @@ async function reviewAndApply(
286
298
  validated: LoadedStarshipConfig,
287
299
  title: string,
288
300
  restore: boolean,
301
+ owner: WorkflowOwner,
289
302
  ): Promise<"applied" | "edit" | "cancel"> {
290
303
  while (true) {
291
304
  const selection = await showPreviewActionMenu(
@@ -298,6 +311,7 @@ async function reviewAndApply(
298
311
  { value: PREVIEW_ACTIONS.cancel, label: "Cancel" },
299
312
  ],
300
313
  );
314
+ if (!isCurrentOwner(owner)) return "cancel";
301
315
  if (selection === PREVIEW_ACTIONS.edit) return "edit";
302
316
  if (selection !== PREVIEW_ACTIONS.continue) return "cancel";
303
317
 
@@ -307,6 +321,7 @@ async function reviewAndApply(
307
321
  ? `Replace ${options.settingsPath} with the built-in configuration?`
308
322
  : "Save this configuration and apply it immediately?",
309
323
  );
324
+ if (!isCurrentOwner(owner)) return "cancel";
310
325
  if (!confirmed) continue;
311
326
 
312
327
  const save = options.save ?? atomicSaveConfigDocument;
@@ -349,6 +364,16 @@ async function reviewAndApply(
349
364
  }
350
365
  }
351
366
 
367
+ function workflowOwner(options: StarshipCommandOptions): WorkflowOwner {
368
+ if (options.getMenuOwner) return options.getMenuOwner();
369
+ const controller = new AbortController();
370
+ return { signal: controller.signal, isCurrent: () => true };
371
+ }
372
+
373
+ function isCurrentOwner(owner: WorkflowOwner): boolean {
374
+ return !owner.signal.aborted && owner.isCurrent();
375
+ }
376
+
352
377
  function restorePreviousConfiguration(
353
378
  ctx: ExtensionCommandContext,
354
379
  options: StarshipCommandOptions,
package/src/config.ts CHANGED
@@ -77,6 +77,7 @@ $directory\
77
77
  [](fg:directory bg:git)\
78
78
  $git_worktree\
79
79
  $git_branch\
80
+ $github_pr\
80
81
  $git_status\
81
82
  [](fg:git bg:runtime)\
82
83
  $activity\
@@ -16,6 +16,7 @@ import { gitMetricsModule } from "./git/metrics.js";
16
16
  import { gitStateModule } from "./git/state.js";
17
17
  import { gitStatusModule } from "./git/status.js";
18
18
  import { gitWorktreeModule } from "./git/worktree.js";
19
+ import { githubPrModule } from "./github-pr.js";
19
20
  import { languageModules } from "./languages.js";
20
21
  import { modelModule } from "./model.js";
21
22
  import { packageModule } from "./package.js";
@@ -34,6 +35,7 @@ export const MODULE_DEFINITIONS = [
34
35
  directoryModule,
35
36
  gitWorktreeModule,
36
37
  gitBranchModule,
38
+ githubPrModule,
37
39
  gitCommitModule,
38
40
  gitStateModule,
39
41
  gitMetricsModule,
@@ -52,7 +54,7 @@ export const MODULE_DEFINITIONS = [
52
54
  timeModule,
53
55
  turnModule,
54
56
  fillModule,
55
- // Render last so earlier modules can consume extension-owned status values.
57
+ // Keep arbitrary third-party statuses after the native modules.
56
58
  extensionStatusModule,
57
59
  ] as const satisfies readonly ModuleDefinition<string>[];
58
60
 
@@ -1,30 +1,4 @@
1
- import { defineModule, type ExtensionStatusIconAliasMap } from "./types.js";
2
-
3
- const DEFAULT_EXTENSION_STATUS_ICONS: Record<string, string> = {
4
- accounts: "👤",
5
- caffeinate: "💊",
6
- "chrome-devtools": "🌐",
7
- "codex-usage": "📊",
8
- firecrawl: "🔥",
9
- "github-pr": "🔎",
10
- goal: "🎯",
11
- "google-genai": "✨",
12
- lsp: "🧰",
13
- "plan-mode": "📝",
14
- retry: "🔁",
15
- pisync: "🔄",
16
- subagents: "🧑‍🤝‍🧑",
17
- sync: "🔄",
18
- usage: "📊",
19
- "unknown-error-retry": "🔁",
20
- };
21
-
22
- const COMPATIBLE_STATUS_ICON_KEYS: Readonly<Record<string, string>> = {
23
- retry: "unknown-error-retry",
24
- sync: "pisync",
25
- "unknown-error-retry": "retry",
26
- pisync: "sync",
27
- };
1
+ import { defineModule } from "./types.js";
28
2
 
29
3
  export const extensionStatusModule = defineModule({
30
4
  name: "extension_status",
@@ -35,19 +9,10 @@ export const extensionStatusModule = defineModule({
35
9
  style: "fg:extension",
36
10
  disabled: false,
37
11
  },
38
- values: ({ runtime, extensionStatus, hiddenExtensionStatusKeys }) => {
12
+ values: ({ runtime, extensionStatus }) => {
39
13
  const statuses = [...runtime.extensionStatuses.entries()]
40
- .filter(
41
- ([key, value]) => key !== "starship" && !hiddenExtensionStatusKeys.has(key) && value.trim(),
42
- )
43
- .map(([key, value]) =>
44
- formatExtensionStatus(
45
- key,
46
- value,
47
- extensionStatus.icons,
48
- runtime.extensionStatusIconAliases,
49
- ),
50
- )
14
+ .filter(([key, value]) => key !== "starship" && value.trim())
15
+ .map(([key, value]) => formatExtensionStatus(key, value, extensionStatus.icons))
51
16
  .slice(0, extensionStatus.maxStatuses);
52
17
  if (statuses.length === 0) return undefined;
53
18
  return {
@@ -61,10 +26,9 @@ export function formatExtensionStatus(
61
26
  key: string,
62
27
  value: string,
63
28
  configuredIcons: Readonly<Record<string, string>>,
64
- aliases: ExtensionStatusIconAliasMap,
65
29
  ): string {
66
30
  const status = splitExtensionStatusIcon(stripExtensionStatusPrefix(key, value));
67
- const icon = extensionStatusIcon(key, status.icon, configuredIcons, aliases);
31
+ const icon = extensionStatusIcon(key, status.icon, configuredIcons);
68
32
  const text = simplifyExtensionStatusText(status.text);
69
33
  return icon ? `${icon} ${text}` : text;
70
34
  }
@@ -73,25 +37,14 @@ function extensionStatusIcon(
73
37
  key: string,
74
38
  leadingIcon: string | undefined,
75
39
  configuredIcons: Readonly<Record<string, string>>,
76
- aliases: ExtensionStatusIconAliasMap,
77
40
  ): string {
78
41
  if (Object.hasOwn(configuredIcons, key)) return configuredIcons[key] ?? "";
79
42
  const namespaceIcon = configuredNamespaceIcon(key, configuredIcons);
80
43
  if (namespaceIcon !== undefined) return namespaceIcon;
81
- const compatibleKey = COMPATIBLE_STATUS_ICON_KEYS[key];
82
- if (compatibleKey && Object.hasOwn(configuredIcons, compatibleKey)) {
83
- return configuredIcons[compatibleKey] ?? "";
84
- }
85
- for (const alias of extensionStatusAliasesForKey(key, aliases)) {
86
- if (Object.hasOwn(configuredIcons, alias)) return configuredIcons[alias] ?? "";
87
- }
88
- const defaultIcon = Object.hasOwn(DEFAULT_EXTENSION_STATUS_ICONS, key)
89
- ? DEFAULT_EXTENSION_STATUS_ICONS[key]
90
- : undefined;
91
44
  const fallbackIcon = Object.hasOwn(configuredIcons, "fallback")
92
45
  ? configuredIcons.fallback
93
46
  : undefined;
94
- return leadingIcon ?? defaultIcon ?? fallbackIcon ?? "🔌";
47
+ return leadingIcon ?? fallbackIcon ?? "🔌";
95
48
  }
96
49
 
97
50
  function configuredNamespaceIcon(
@@ -108,16 +61,6 @@ function configuredNamespaceIcon(
108
61
  return match?.icon;
109
62
  }
110
63
 
111
- function extensionStatusAliasesForKey(
112
- key: string,
113
- aliases: ExtensionStatusIconAliasMap,
114
- ): readonly string[] {
115
- for (const [base, values] of aliases) {
116
- if (key === base || key.startsWith(`${base}:`) || key.startsWith(`${base}/`)) return values;
117
- }
118
- return [];
119
- }
120
-
121
64
  function splitExtensionStatusIcon(value: string): { icon?: string; text: string } {
122
65
  const trimmed = value.trim();
123
66
  const [first, ...rest] = trimmed.split(/\s+/u);
@@ -148,37 +91,3 @@ function simplifyExtensionStatusText(value: string): string {
148
91
  function escapeRegExp(value: string): string {
149
92
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
150
93
  }
151
-
152
- interface InstalledPackage {
153
- packageName: string;
154
- source?: string;
155
- }
156
-
157
- export function buildExtensionStatusIconAliases(
158
- packages: readonly InstalledPackage[],
159
- ): Map<string, string[]> {
160
- const candidates = new Map<string, Map<string, string[]>>();
161
- for (const installed of packages) {
162
- const base = installed.packageName.slice(installed.packageName.lastIndexOf("/") + 1);
163
- const statusBase = base.startsWith("pi-") ? base.slice(3) : base;
164
- if (!statusBase) continue;
165
- const sourceAliases = installed.source?.startsWith("npm:")
166
- ? [installed.source, `npm:${npmPackageName(installed.source)}`]
167
- : [];
168
- const aliases = [...new Set([...sourceAliases, installed.packageName, base, statusBase])];
169
- const byPackage = candidates.get(statusBase) ?? new Map<string, string[]>();
170
- byPackage.set(installed.packageName, aliases);
171
- candidates.set(statusBase, byPackage);
172
- }
173
- const result = new Map<string, string[]>();
174
- for (const [base, byPackage] of candidates) {
175
- if (byPackage.size === 1) result.set(base, [...byPackage.values()][0] ?? []);
176
- }
177
- return result;
178
- }
179
-
180
- function npmPackageName(source: string): string {
181
- const spec = source.slice("npm:".length);
182
- if (spec.startsWith("@")) return spec.split("@").slice(0, 2).join("@");
183
- return spec.split("@")[0] ?? spec;
184
- }
@@ -2,9 +2,9 @@ import { defineModule } from "../types.js";
2
2
 
3
3
  export const gitBranchModule = defineModule({
4
4
  name: "git_branch",
5
- variables: ["symbol", "branch", "remote_name", "remote_branch", "pr"],
5
+ variables: ["symbol", "branch", "remote_name", "remote_branch"],
6
6
  defaults: {
7
- format: "[ $symbol $branch( $pr) ]($style)",
7
+ format: "[ $symbol $branch ]($style)",
8
8
  symbol: "🌿",
9
9
  style: "fg:git_fg bg:git",
10
10
  disabled: false,
@@ -17,40 +17,6 @@ export const gitBranchModule = defineModule({
17
17
  branch: name,
18
18
  remote_name: branch?.remoteName ?? "",
19
19
  remote_branch: branch?.remoteBranch ?? "",
20
- pr: prContextFromStatuses(runtime.extensionStatuses) ?? "",
21
20
  };
22
21
  },
23
22
  });
24
-
25
- export function prContextFromStatuses(statuses: ReadonlyMap<string, string>): string | undefined {
26
- const value = statuses.get("github-pr");
27
- if (!value) return undefined;
28
- const link = prLink(value);
29
- if (!link) return undefined;
30
- const state = compactPrState(value.replace(link, ""));
31
- return state ? `${link} · ${state}` : undefined;
32
- }
33
-
34
- function prLink(value: string): string | undefined {
35
- const open = value.indexOf("\x1b]8;;");
36
- if (open === -1) return undefined;
37
- const closeMarker = "\x1b]8;;\x07";
38
- const close = value.indexOf(closeMarker, open + 1);
39
- return close === -1 ? undefined : value.slice(open, close + closeMarker.length);
40
- }
41
-
42
- function compactPrState(value: string): string | undefined {
43
- if (/:\s*merged\s*$/u.test(value)) return "merged";
44
- if (/:\s*closed\s*$/u.test(value)) return "closed";
45
- if (/\bdraft\b/u.test(value)) return "draft";
46
- const failing = /\bchecks failing \((\d+)\)/u.exec(value);
47
- if (failing?.[1]) return `${failing[1]} failing`;
48
- if (/\bchanges requested\b/u.test(value)) return "changes requested";
49
- const pending = /\bchecks pending \((\d+)\)/u.exec(value);
50
- if (pending?.[1]) return `${pending[1]} pending`;
51
- if (/\bapproved\b/u.test(value)) return "approved";
52
- if (/\breview required\b/u.test(value)) return "review required";
53
- if (/\bchecks passing\b/u.test(value)) return "checks passing";
54
- if (/\bno checks\b/u.test(value)) return "no checks";
55
- return undefined;
56
- }
@@ -16,6 +16,7 @@ const GIT_TIMEOUT_MS = 3_000;
16
16
  export interface ReadGitSnapshotOptions {
17
17
  includeMetrics: boolean;
18
18
  includeTag: boolean;
19
+ signal?: AbortSignal;
19
20
  }
20
21
 
21
22
  export async function readGitSnapshot(
@@ -33,22 +34,24 @@ export async function readGitSnapshot(
33
34
  "--show-stash",
34
35
  "--untracked-files=normal",
35
36
  ],
36
- { cwd, timeout: GIT_TIMEOUT_MS },
37
+ { cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
37
38
  );
38
39
  const metadataPromise = pi.exec(
39
40
  "git",
40
41
  ["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
41
- { cwd, timeout: GIT_TIMEOUT_MS },
42
+ { cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
42
43
  );
43
44
  const metricsPromise = options.includeMetrics
44
45
  ? pi.exec("git", ["--no-optional-locks", "diff", "--shortstat", "HEAD", "--"], {
45
46
  cwd,
47
+ signal: options.signal,
46
48
  timeout: GIT_TIMEOUT_MS,
47
49
  })
48
50
  : Promise.resolve(undefined);
49
51
  const tagPromise = options.includeTag
50
52
  ? pi.exec("git", ["describe", "--tags", "--exact-match", "HEAD"], {
51
53
  cwd,
54
+ signal: options.signal,
52
55
  timeout: GIT_TIMEOUT_MS,
53
56
  })
54
57
  : Promise.resolve(undefined);
@@ -0,0 +1,24 @@
1
+ import { defineModule } from "./types.js";
2
+
3
+ export const githubPrModule = defineModule({
4
+ name: "github_pr",
5
+ variables: ["symbol", "number", "link", "state", "checks", "review", "status"],
6
+ defaults: {
7
+ format: "[ $symbol$link( · $status) ]($style)",
8
+ symbol: "PR ",
9
+ style: "fg:git_fg bg:git",
10
+ disabled: false,
11
+ },
12
+ values: ({ runtime }) => {
13
+ const snapshot = runtime.githubPr;
14
+ if (!snapshot) return undefined;
15
+ return {
16
+ number: snapshot.number,
17
+ link: snapshot.link,
18
+ state: snapshot.state,
19
+ checks: snapshot.checks,
20
+ review: snapshot.review,
21
+ status: snapshot.status,
22
+ };
23
+ },
24
+ });
@@ -1,16 +1,13 @@
1
1
  export { MODULE_DEFINITIONS, MODULE_NAMES, type ModuleName } from "./catalog.js";
2
- export {
3
- buildExtensionStatusIconAliases,
4
- formatExtensionStatus,
5
- } from "./extension-status.js";
6
- export { prContextFromStatuses } from "./git/branch.js";
2
+ export { formatExtensionStatus } from "./extension-status.js";
7
3
  export { formatCount } from "./helpers.js";
8
4
  export { shortenModel } from "./model.js";
9
5
  export { reachableModuleRequirements, renderStatusline } from "./render.js";
10
6
  export type {
11
- ExtensionStatusIconAliasMap,
12
7
  GitBranchSnapshot,
13
8
  GitCommitSnapshot,
9
+ GithubPrSnapshot,
10
+ GithubPrState,
14
11
  GitMetricsSnapshot,
15
12
  GitSnapshot,
16
13
  GitStateSnapshot,