@narumitw/pi-starship 0.55.0 → 0.55.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
|
@@ -62,21 +62,15 @@ It does not cover general TOML, shell Starship configuration, extension source d
|
|
|
62
62
|
|
|
63
63
|
| Command | Purpose |
|
|
64
64
|
| --- | --- |
|
|
65
|
-
| `/starship` |
|
|
66
|
-
| `/starship settings` | Edit, preview, and confirm TOML
|
|
67
|
-
| `/starship status` | Show the configuration source, path, and diagnostics
|
|
68
|
-
| `/starship help` | Show command and configuration help
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
The TOML editor, live footer previews, Explain view, module inspector, and configuration reviews use specialized TUI screens.
|
|
76
|
-
Their content and key hints adapt to terminal width and Pi's configured keybindings.
|
|
77
|
-
Escape returns to the previous screen, while Ctrl+C closes the workflow.
|
|
78
|
-
Direct routes reject trailing arguments.
|
|
79
|
-
Print and JSON modes produce no ad hoc output, and footer lifecycle work runs only in TUI mode.
|
|
65
|
+
| `/starship` | Customize the footer, preview presets, inspect modules, or restore built-in configuration; RPC shows help. |
|
|
66
|
+
| `/starship settings` | Edit, preview, and confirm TOML; RPC shows the file path. |
|
|
67
|
+
| `/starship status` | Show the configuration source, path, and diagnostics. |
|
|
68
|
+
| `/starship help` | Show command and configuration help. |
|
|
69
|
+
|
|
70
|
+
All routes support TUI and RPC with the exceptions above and reject unknown or trailing arguments.
|
|
71
|
+
Print and JSON modes produce no command output; the footer runs only in TUI mode.
|
|
72
|
+
Preset selection, module inspection, and recovery are menu-only, not extra subcommands.
|
|
73
|
+
Restoring built-in configuration requires an existing settings document to replace; see [Settings](#-settings).
|
|
80
74
|
|
|
81
75
|
## ⚙️ Settings
|
|
82
76
|
|
|
@@ -123,27 +117,18 @@ Keep `extension_status` last in the catalog so arbitrary third-party statuses fo
|
|
|
123
117
|
|
|
124
118
|
## 🗂️ Package layout
|
|
125
119
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
- `src/command-inspector.ts` — adaptive Explain and searchable read-only module inspection surfaces.
|
|
139
|
-
- `src/command-preview.ts` — adaptive, scrollable, keybinding-aware preview action surface.
|
|
140
|
-
- `src/config.ts` — TOML loading, draft validation, defaults, atomic persistence, and rollback.
|
|
141
|
-
- `src/format/` — native format/style parser and renderer.
|
|
142
|
-
- `src/modules/` — domain module definitions, ordered registry, reachability, and width-aware renderer.
|
|
143
|
-
- `src/modules/git/` — bounded local Git reader plus branch, status, and worktree modules.
|
|
144
|
-
- `src/modules/github-pr.ts` — pure native GitHub PR snapshot presentation.
|
|
145
|
-
- `src/runtime/github-pr.ts` — bounded `gh` query, validation, terminal-safe links, and expiry data.
|
|
146
|
-
- `src/runtime/` — shared refresh controller and requirement-gated, lazily loaded package/language/context collectors.
|
|
120
|
+
```text
|
|
121
|
+
packages/pi-starship/
|
|
122
|
+
├── src/ # Modules, formats, presets, and runtime collectors
|
|
123
|
+
│ ├── index.ts # Thin Pi entrypoint
|
|
124
|
+
│ └── pi-starship.ts # Footer lifecycle and cached refresh
|
|
125
|
+
├── dist/ # Generated Jiti runtime
|
|
126
|
+
├── scripts/build-runtime.mjs # Runtime builder
|
|
127
|
+
├── skills/configuring-pi-starship/ # Authoritative configuration skill and references
|
|
128
|
+
└── test/ # Behavior and lifecycle coverage
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The generated runtime is built from `src/index.ts` and does not import back into `src`.
|
|
147
132
|
|
|
148
133
|
## 🔎 Keywords
|
|
149
134
|
|
package/dist/index.ts
CHANGED
|
@@ -1048,11 +1048,29 @@ function piStarship(pi, options = {}) {
|
|
|
1048
1048
|
requestGithubPr(target);
|
|
1049
1049
|
tui.requestRender();
|
|
1050
1050
|
});
|
|
1051
|
+
let lastRender;
|
|
1051
1052
|
const timer = setInterval(() => {
|
|
1052
1053
|
if (!isActiveTarget(target)) return;
|
|
1053
1054
|
clearDebounce();
|
|
1054
1055
|
requestRefresh(target, "periodic");
|
|
1055
|
-
|
|
1056
|
+
if (!lastRender || !reachableModuleRequirements(lastRender.config).get("time")?.has("time"))
|
|
1057
|
+
return;
|
|
1058
|
+
const now = /* @__PURE__ */ new Date();
|
|
1059
|
+
const previous = lastRender.snapshot.now;
|
|
1060
|
+
if (now.getHours() === previous.getHours() && now.getMinutes() === previous.getMinutes())
|
|
1061
|
+
return;
|
|
1062
|
+
const lines = wrapFormattedStatusline(
|
|
1063
|
+
renderStatusline(
|
|
1064
|
+
lastRender.config,
|
|
1065
|
+
{ ...lastRender.snapshot, now },
|
|
1066
|
+
lastRender.width,
|
|
1067
|
+
getCapabilities2().trueColor
|
|
1068
|
+
).ansi,
|
|
1069
|
+
lastRender.width
|
|
1070
|
+
);
|
|
1071
|
+
const previousLines = lastRender.lines;
|
|
1072
|
+
if (lines.length !== previousLines.length || lines.some((line, index) => line !== previousLines[index]))
|
|
1073
|
+
tui.requestRender();
|
|
1056
1074
|
}, REFRESH_INTERVAL_MS);
|
|
1057
1075
|
let disposed = false;
|
|
1058
1076
|
return {
|
|
@@ -1082,10 +1100,12 @@ function piStarship(pi, options = {}) {
|
|
|
1082
1100
|
const current = previewLoaded ?? loaded;
|
|
1083
1101
|
if (!current) return [];
|
|
1084
1102
|
const snapshot = runtimeSnapshot(ctx, footerData, runtime);
|
|
1085
|
-
|
|
1103
|
+
const lines = wrapFormattedStatusline(
|
|
1086
1104
|
renderStatusline(current.config, snapshot, width, getCapabilities2().trueColor).ansi,
|
|
1087
1105
|
width
|
|
1088
1106
|
);
|
|
1107
|
+
lastRender = { snapshot, lines, config: current.config, width };
|
|
1108
|
+
return lines;
|
|
1089
1109
|
}
|
|
1090
1110
|
};
|
|
1091
1111
|
});
|
package/dist/index.ts.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/pi-starship.ts", "../src/modules/git/runtime.ts", "../src/runtime/command.ts", "../src/runtime/github-pr.ts", "../src/runtime/refresh-controller.ts", "../src/runtime/workspace.ts", "../src/usage.ts"],
|
|
4
|
-
"sourcesContent": ["import { homedir, hostname, userInfo } from \"node:os\";\nimport {\n\ttype ExtensionAPI,\n\ttype ExtensionContext,\n\tgetAgentDir,\n\ttype ReadonlyFooterDataProvider,\n} from \"@earendil-works/pi-coding-agent\";\nimport { getCapabilities, wrapTextWithAnsi } from \"@earendil-works/pi-tui\";\nimport { completeStarshipArguments } from \"./command-contract.js\";\nimport type { StarshipCommandOptions } from \"./commands.js\";\nimport {\n\ttype LoadedStarshipConfig,\n\tloadStarshipConfig,\n\ttype StarshipConfig,\n\tsettingsFilePath,\n} from \"./config.js\";\nimport { gitSnapshotEqual, readGitSnapshot } from \"./modules/git/runtime.js\";\nimport {\n\ttype GithubPrSnapshot,\n\ttype GitSnapshot,\n\tinspectStatuslineModules,\n\treachableModuleRequirements,\n\trenderStatusline,\n\ttype StarshipRuntimeSnapshot,\n\ttype StatuslineInspection,\n\ttype WorkspaceSnapshot,\n} from \"./modules/index.js\";\nimport { execWorkspaceCommand } from \"./runtime/command.js\";\nimport { githubPrSnapshotEqual, queryGithubPr } from \"./runtime/github-pr.js\";\nimport { AsyncRefreshController } from \"./runtime/refresh-controller.js\";\nimport {\n\tcollectWorkspaceSnapshot,\n\ttype WorkspaceExec,\n\ttype WorkspaceRefreshInput,\n\tworkspaceSnapshotEqual,\n} from \"./runtime/workspace.js\";\nimport { summarizeFooterUsage } from \"./usage.js\";\n\nconst REFRESH_INTERVAL_MS = 30_000;\nconst GITHUB_PR_REFRESH_INTERVAL_MS = 60_000;\nconst EVENT_DEBOUNCE_MS = 250;\nconst MAX_TIMER_DELAY_MS = 2_147_483_647;\n\ntype StarshipCommands = typeof import(\"./commands.js\");\nlet starshipCommandsPromise: Promise<StarshipCommands> | undefined;\n\nfunction loadStarshipCommands(): Promise<StarshipCommands> {\n\tif (!starshipCommandsPromise) {\n\t\tstarshipCommandsPromise = import(\"./commands.js\").catch((error) => {\n\t\t\tstarshipCommandsPromise = undefined;\n\t\t\tthrow error;\n\t\t});\n\t}\n\treturn starshipCommandsPromise;\n}\n\ninterface RuntimeState {\n\tactiveTools: Map<string, number>;\n\tisStreaming: boolean;\n\tuiPrompt?: NonNullable<StarshipRuntimeSnapshot[\"uiPrompt\"]>;\n\tthinkingLevel: string;\n\tlastCompletedTool?: string;\n\tgit?: GitSnapshot;\n\tgithubPr?: GithubPrSnapshot;\n\tworkspace?: WorkspaceSnapshot;\n\trequestRender?: () => void;\n\trenderPreview?: (loaded: LoadedStarshipConfig, width: number) => string[];\n\tinspect?: (loaded: LoadedStarshipConfig) => StatuslineInspection;\n\tfooterWidth?: number;\n}\n\ninterface RefreshTarget {\n\tcwd: string;\n\tgeneration: number;\n\tsessionManager: ExtensionContext[\"sessionManager\"];\n}\n\ninterface GitRefreshInput {\n\tcwd: string;\n\tconfig: StarshipConfig;\n}\n\ninterface PiStarshipOptions {\n\tgithubPrExec?: WorkspaceExec;\n}\n\nexport default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions = {}) {\n\tlet loaded: LoadedStarshipConfig | undefined;\n\tlet loadedRevision = 0;\n\tlet previewLoaded: LoadedStarshipConfig | undefined;\n\tconst runtime: RuntimeState = {\n\t\tactiveTools: new Map(),\n\t\tisStreaming: false,\n\t\tthinkingLevel: \"off\",\n\t};\n\tlet sessionGeneration = 0;\n\tlet menuController = new AbortController();\n\tlet sessionOwner: ExtensionContext[\"sessionManager\"] | undefined;\n\tlet activeTarget: RefreshTarget | undefined;\n\tlet eventDebounceTimer: ReturnType<typeof setTimeout> | undefined;\n\tlet githubPrRefreshTimer: ReturnType<typeof setInterval> | undefined;\n\tlet githubPrExpiryTimer: ReturnType<typeof setTimeout> | undefined;\n\tlet githubPrGeneration = 0;\n\n\tconst refresh = () => runtime.requestRender?.();\n\tconst ownsRuntime = (ctx: ExtensionContext) => sessionOwner === ctx.sessionManager;\n\tconst githubPrExec = options.githubPrExec ?? execWorkspaceCommand;\n\tconst gitController = new AsyncRefreshController<GitRefreshInput, GitSnapshot | undefined>({\n\t\tasync read(input, signal) {\n\t\t\tconst requirements = reachableModuleRequirements(input.config);\n\t\t\tconst gitReachable =\n\t\t\t\t[...requirements.keys()].some((name) => name.startsWith(\"git_\")) ||\n\t\t\t\t(requirements.has(\"directory\") &&\n\t\t\t\t\tinput.config.modules.directory.options.truncate_to_repo === true);\n\t\t\tif (!gitReachable) return undefined;\n\t\t\ttry {\n\t\t\t\treturn await readGitSnapshot(pi, input.cwd, {\n\t\t\t\t\tincludeMetrics: requirements.has(\"git_metrics\"),\n\t\t\t\t\tincludeTag: requirements.get(\"git_commit\")?.has(\"tag\") ?? false,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t\tequal: gitSnapshotEqual,\n\t\tpublish(snapshot) {\n\t\t\truntime.git = snapshot;\n\t\t\trefresh();\n\t\t},\n\t});\n\tconst githubPrController = new AsyncRefreshController<\n\t\tPick<RefreshTarget, \"cwd\">,\n\t\tGithubPrSnapshot | undefined\n\t>({\n\t\tread: (input, signal) => queryGithubPr(githubPrExec, input.cwd, signal),\n\t\tequal: githubPrSnapshotEqual,\n\t\tpublish(snapshot) {\n\t\t\truntime.githubPr = snapshot;\n\t\t\tscheduleGithubPrExpiry(snapshot);\n\t\t\trefresh();\n\t\t},\n\t});\n\tconst workspaceController = new AsyncRefreshController<WorkspaceRefreshInput, WorkspaceSnapshot>({\n\t\tasync read(input, signal) {\n\t\t\ttry {\n\t\t\t\treturn await collectWorkspaceSnapshot({ ...input, signal });\n\t\t\t} catch {\n\t\t\t\treturn { modules: {} };\n\t\t\t}\n\t\t},\n\t\tequal: workspaceSnapshotEqual,\n\t\tpublish(snapshot) {\n\t\t\truntime.workspace = snapshot;\n\t\t\trefresh();\n\t\t},\n\t});\n\n\tconst clearDebounce = () => {\n\t\tif (!eventDebounceTimer) return;\n\t\tclearTimeout(eventDebounceTimer);\n\t\teventDebounceTimer = undefined;\n\t};\n\tconst isActiveTarget = (target: RefreshTarget) =>\n\t\tactiveTarget?.cwd === target.cwd &&\n\t\tactiveTarget.generation === target.generation &&\n\t\tactiveTarget.sessionManager === target.sessionManager &&\n\t\ttarget.generation === sessionGeneration;\n\n\tconst requestRefresh = (\n\t\ttarget: RefreshTarget,\n\t\treason: WorkspaceRefreshInput[\"reason\"] = \"event\",\n\t) => {\n\t\tif (!loaded || !isActiveTarget(target)) return;\n\t\tgitController.request({ cwd: target.cwd, config: loaded.config });\n\t\tworkspaceController.request(\n\t\t\tworkspaceInput(target.cwd, loaded.config, reason, runtime.workspace),\n\t\t);\n\t};\n\tconst scheduleRefresh = (ctx: ExtensionContext) => {\n\t\tconst target = activeTarget;\n\t\tif (!target || target.cwd !== ctx.cwd || target.sessionManager !== ctx.sessionManager) {\n\t\t\treturn;\n\t\t}\n\t\tclearDebounce();\n\t\teventDebounceTimer = setTimeout(() => {\n\t\t\teventDebounceTimer = undefined;\n\t\t\trequestRefresh(target);\n\t\t}, EVENT_DEBOUNCE_MS);\n\t};\n\n\tfunction restartLocalControllers(target: RefreshTarget) {\n\t\tif (!isActiveTarget(target)) return;\n\t\tgitController.start(target.generation);\n\t\tworkspaceController.start(target.generation);\n\t}\n\n\tfunction clearGithubPrTimers() {\n\t\tif (githubPrRefreshTimer) clearInterval(githubPrRefreshTimer);\n\t\tif (githubPrExpiryTimer) clearTimeout(githubPrExpiryTimer);\n\t\tgithubPrRefreshTimer = undefined;\n\t\tgithubPrExpiryTimer = undefined;\n\t}\n\n\tfunction stopGithubPr() {\n\t\tclearGithubPrTimers();\n\t\tgithubPrController.stop();\n\t\truntime.githubPr = undefined;\n\t}\n\n\tfunction githubPrReachable(): boolean {\n\t\treturn Boolean(loaded && reachableModuleRequirements(loaded.config).has(\"github_pr\"));\n\t}\n\n\tfunction startGithubPr(target: RefreshTarget): boolean {\n\t\tif (!isActiveTarget(target)) return false;\n\t\tstopGithubPr();\n\t\tif (!githubPrReachable()) return false;\n\t\tgithubPrController.start(++githubPrGeneration);\n\t\tgithubPrRefreshTimer = setInterval(() => {\n\t\t\trequestGithubPr(target);\n\t\t}, GITHUB_PR_REFRESH_INTERVAL_MS);\n\t\tgithubPrRefreshTimer.unref?.();\n\t\treturn true;\n\t}\n\n\tfunction requestGithubPr(target: RefreshTarget) {\n\t\tif (!isActiveTarget(target) || !githubPrReachable()) return;\n\t\tgithubPrController.request({ cwd: target.cwd });\n\t}\n\n\tfunction scheduleGithubPrExpiry(snapshot: GithubPrSnapshot | undefined) {\n\t\tif (githubPrExpiryTimer) clearTimeout(githubPrExpiryTimer);\n\t\tgithubPrExpiryTimer = undefined;\n\t\tif (snapshot?.expiresAt === undefined) return;\n\t\tconst target = activeTarget;\n\t\tif (!target) return;\n\t\tconst delay = snapshot.expiresAt - Date.now();\n\t\tif (delay <= 0) {\n\t\t\truntime.githubPr = undefined;\n\t\t\tgithubPrController.clear();\n\t\t\trefresh();\n\t\t\treturn;\n\t\t}\n\t\tgithubPrExpiryTimer = setTimeout(\n\t\t\t() => {\n\t\t\t\tgithubPrExpiryTimer = undefined;\n\t\t\t\tif (!isActiveTarget(target) || runtime.githubPr !== snapshot) return;\n\t\t\t\tscheduleGithubPrExpiry(snapshot);\n\t\t\t},\n\t\t\tMath.min(delay, MAX_TIMER_DELAY_MS),\n\t\t);\n\t\tgithubPrExpiryTimer.unref?.();\n\t}\n\n\tconst installFooter = (ctx: ExtensionContext) => {\n\t\tconst generation = ++sessionGeneration;\n\t\tsessionOwner = ctx.sessionManager;\n\t\tpreviewLoaded = undefined;\n\t\tmenuController.abort(new DOMException(\"Starship session context replaced\", \"AbortError\"));\n\t\tmenuController = new AbortController();\n\t\tconst target: RefreshTarget = { cwd: ctx.cwd, generation, sessionManager: ctx.sessionManager };\n\t\tclearDebounce();\n\t\tgitController.stop();\n\t\tworkspaceController.stop();\n\t\tstopGithubPr();\n\t\truntime.git = undefined;\n\t\truntime.workspace = undefined;\n\t\truntime.requestRender = undefined;\n\t\truntime.renderPreview = undefined;\n\t\truntime.inspect = undefined;\n\t\truntime.footerWidth = undefined;\n\t\tactiveTarget = ctx.mode === \"tui\" ? target : undefined;\n\t\tctx.ui.setStatus(\"starship\", undefined);\n\t\tif (!activeTarget || !loaded) return;\n\t\tgitController.start(generation);\n\t\tworkspaceController.start(generation);\n\t\tstartGithubPr(target);\n\n\t\tctx.ui.setFooter((tui, _theme, footerData) => {\n\t\t\truntime.requestRender = () => tui.requestRender();\n\t\t\truntime.renderPreview = (preview, width) => {\n\t\t\t\tconst snapshot = runtimeSnapshot(ctx, footerData, runtime);\n\t\t\t\treturn wrapFormattedStatusline(\n\t\t\t\t\trenderStatusline(preview.config, snapshot, width, getCapabilities().trueColor).ansi,\n\t\t\t\t\twidth,\n\t\t\t\t);\n\t\t\t};\n\t\t\truntime.inspect = (current) =>\n\t\t\t\tinspectStatuslineModules(\n\t\t\t\t\tcurrent.config,\n\t\t\t\t\truntimeSnapshot(ctx, footerData, runtime),\n\t\t\t\t\truntime.footerWidth ?? 80,\n\t\t\t\t);\n\t\t\tconst unsubscribe = footerData.onBranchChange(() => {\n\t\t\t\tif (!isActiveTarget(target)) return;\n\t\t\t\truntime.git = undefined;\n\t\t\t\trestartLocalControllers(target);\n\t\t\t\tclearDebounce();\n\t\t\t\tstartGithubPr(target);\n\t\t\t\trequestRefresh(target);\n\t\t\t\trequestGithubPr(target);\n\t\t\t\ttui.requestRender();\n\t\t\t});\n\t\t\tconst timer = setInterval(() => {\n\t\t\t\tif (!isActiveTarget(target)) return;\n\t\t\t\tclearDebounce();\n\t\t\t\trequestRefresh(target, \"periodic\");\n\t\t\t\ttui.requestRender();\n\t\t\t}, REFRESH_INTERVAL_MS);\n\t\t\tlet disposed = false;\n\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\tif (disposed) return;\n\t\t\t\t\tdisposed = true;\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tclearInterval(timer);\n\t\t\t\t\tif (isActiveTarget(target)) {\n\t\t\t\t\t\tactiveTarget = undefined;\n\t\t\t\t\t\tclearDebounce();\n\t\t\t\t\t\tgitController.stop();\n\t\t\t\t\t\tworkspaceController.stop();\n\t\t\t\t\t\tstopGithubPr();\n\t\t\t\t\t\truntime.git = undefined;\n\t\t\t\t\t\truntime.workspace = undefined;\n\t\t\t\t\t\truntime.requestRender = undefined;\n\t\t\t\t\t\truntime.renderPreview = undefined;\n\t\t\t\t\t\truntime.inspect = undefined;\n\t\t\t\t\t\truntime.footerWidth = undefined;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tinvalidate() {},\n\t\t\t\trender(width: number): string[] {\n\t\t\t\t\truntime.footerWidth = width;\n\t\t\t\t\tconst current = previewLoaded ?? loaded;\n\t\t\t\t\tif (!current) return [];\n\t\t\t\t\tconst snapshot = runtimeSnapshot(ctx, footerData, runtime);\n\t\t\t\t\treturn wrapFormattedStatusline(\n\t\t\t\t\t\trenderStatusline(current.config, snapshot, width, getCapabilities().trueColor).ansi,\n\t\t\t\t\t\twidth,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\t\trequestRefresh(target, \"initial\");\n\t\trequestGithubPr(target);\n\t};\n\n\tconst configPath = settingsFilePath(getAgentDir());\n\tconst commandOptions: StarshipCommandOptions = {\n\t\tsettingsPath: configPath,\n\t\tgetLoaded: () => loaded ?? loadStarshipConfig(configPath),\n\t\tgetLoadedRevision: () => loadedRevision,\n\t\tgetInspection: () => {\n\t\t\tconst current = loaded ?? loadStarshipConfig(configPath);\n\t\t\treturn runtime.inspect?.(current);\n\t\t},\n\t\tgetMenuOwner: () => {\n\t\t\tconst generation = sessionGeneration;\n\t\t\treturn {\n\t\t\t\tsignal: menuController.signal,\n\t\t\t\tisCurrent: () => generation === sessionGeneration && !menuController.signal.aborted,\n\t\t\t};\n\t\t},\n\t\tapply(next, ctx) {\n\t\t\tif (sessionOwner !== ctx.sessionManager) {\n\t\t\t\tthrow new Error(\"Starship session context was replaced\");\n\t\t\t}\n\t\t\tpreviewLoaded = undefined;\n\t\t\tloaded = next;\n\t\t\tloadedRevision += 1;\n\t\t\tconst target = activeTarget;\n\t\t\tif (target) {\n\t\t\t\trestartLocalControllers(target);\n\t\t\t\tstartGithubPr(target);\n\t\t\t\trequestRefresh(target);\n\t\t\t\trequestGithubPr(target);\n\t\t\t}\n\t\t\trefresh();\n\t\t},\n\t\tpreview(next, ctx) {\n\t\t\tif (sessionOwner !== ctx.sessionManager) return;\n\t\t\tpreviewLoaded = next;\n\t\t\trefresh();\n\t\t},\n\t\trenderPreview(preview, width) {\n\t\t\treturn (\n\t\t\t\truntime.renderPreview?.(preview, width) ?? [\n\t\t\t\t\t\"Live preview is unavailable until the footer is ready.\",\n\t\t\t\t]\n\t\t\t);\n\t\t},\n\t};\n\tpi.registerCommand(\"starship\", {\n\t\tdescription: \"Customize or inspect the native Starship-style footer\",\n\t\tgetArgumentCompletions: completeStarshipArguments,\n\t\thandler: async (args, ctx) => {\n\t\t\tconst commands = await loadStarshipCommands();\n\t\t\tif (sessionOwner !== ctx.sessionManager) return;\n\t\t\tawait commands.handleStarshipCommand(args, ctx, commandOptions);\n\t\t},\n\t});\n\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\truntime.activeTools.clear();\n\t\truntime.isStreaming = false;\n\t\truntime.uiPrompt = undefined;\n\t\truntime.lastCompletedTool = undefined;\n\t\tloaded = loadStarshipConfig(configPath);\n\t\tloadedRevision += 1;\n\t\tif (loaded.diagnostics.length > 0 && (ctx.mode === \"tui\" || ctx.hasUI)) {\n\t\t\tctx.ui.notify(formatDiagnostics(loaded), \"warning\");\n\t\t}\n\t\truntime.thinkingLevel = pi.getThinkingLevel();\n\t\tinstallFooter(ctx);\n\t});\n\n\tpi.on(\"session_tree\", (_event, ctx) => {\n\t\tinstallFooter(ctx);\n\t\trefresh();\n\t});\n\n\tpi.on(\"session_shutdown\", (_event, ctx) => {\n\t\tif (sessionOwner !== ctx.sessionManager) return;\n\t\tsessionOwner = undefined;\n\t\tpreviewLoaded = undefined;\n\t\tsessionGeneration += 1;\n\t\tmenuController.abort(new DOMException(\"Starship session shut down\", \"AbortError\"));\n\t\tactiveTarget = undefined;\n\t\tclearDebounce();\n\t\tgitController.stop();\n\t\tworkspaceController.stop();\n\t\tstopGithubPr();\n\t\truntime.git = undefined;\n\t\truntime.workspace = undefined;\n\t\truntime.activeTools.clear();\n\t\truntime.isStreaming = false;\n\t\truntime.uiPrompt = undefined;\n\t\truntime.lastCompletedTool = undefined;\n\t\truntime.requestRender = undefined;\n\t\truntime.renderPreview = undefined;\n\t\truntime.inspect = undefined;\n\t\truntime.footerWidth = undefined;\n\t\tctx.ui.setFooter(undefined);\n\t\tctx.ui.setStatus(\"starship\", undefined);\n\t});\n\n\tpi.on(\"model_select\", () => refresh());\n\tpi.on(\"thinking_level_select\", (event) => {\n\t\truntime.thinkingLevel = event.level;\n\t\trefresh();\n\t});\n\tpi.on(\"agent_start\", () => {\n\t\truntime.isStreaming = true;\n\t\trefresh();\n\t});\n\tpi.on(\"agent_end\", (_event, ctx) => {\n\t\truntime.isStreaming = false;\n\t\tscheduleRefresh(ctx);\n\t\tconst target = activeTarget;\n\t\tif (target?.sessionManager === ctx.sessionManager) requestGithubPr(target);\n\t\trefresh();\n\t});\n\tpi.on(\"ui_prompt_start\", (event, ctx) => {\n\t\tif (!ownsRuntime(ctx)) return;\n\t\truntime.uiPrompt = { kind: event.kind, title: event.title };\n\t\trefresh();\n\t});\n\tpi.on(\"ui_prompt_end\", (_event, ctx) => {\n\t\tif (!ownsRuntime(ctx)) return;\n\t\truntime.uiPrompt = undefined;\n\t\trefresh();\n\t});\n\tpi.on(\"turn_start\", () => {\n\t\truntime.isStreaming = true;\n\t\trefresh();\n\t});\n\tpi.on(\"turn_end\", (_event, ctx) => {\n\t\tscheduleRefresh(ctx);\n\t\trefresh();\n\t});\n\tpi.on(\"tool_execution_start\", (event) => {\n\t\truntime.activeTools.set(event.toolName, (runtime.activeTools.get(event.toolName) ?? 0) + 1);\n\t\trefresh();\n\t});\n\tpi.on(\"tool_execution_end\", (event, ctx) => {\n\t\tconst count = runtime.activeTools.get(event.toolName) ?? 0;\n\t\tif (count <= 1) runtime.activeTools.delete(event.toolName);\n\t\telse runtime.activeTools.set(event.toolName, count - 1);\n\t\truntime.lastCompletedTool = event.toolName;\n\t\tscheduleRefresh(ctx);\n\t\trefresh();\n\t});\n}\n\nfunction workspaceInput(\n\tcwd: string,\n\tconfig: StarshipConfig,\n\treason: WorkspaceRefreshInput[\"reason\"],\n\tprevious: WorkspaceSnapshot | undefined,\n): WorkspaceRefreshInput {\n\treturn {\n\t\tcwd,\n\t\tconfig,\n\t\tenvironment: allowlistedEnvironment(config),\n\t\thomeDir: homedir(),\n\t\tplatform: process.platform,\n\t\thostname: hostname(),\n\t\tusername: safeUsername(),\n\t\texec: execWorkspaceCommand,\n\t\treason,\n\t\tprevious,\n\t};\n}\n\nconst ENVIRONMENT_ALLOWLIST = [\n\t\"AWS_CONFIG_FILE\",\n\t\"AWS_DEFAULT_PROFILE\",\n\t\"AWS_DEFAULT_REGION\",\n\t\"AWS_PROFILE\",\n\t\"AWS_REGION\",\n\t\"AZURE_CONFIG_DIR\",\n\t\"CLOUDSDK_ACTIVE_CONFIG_NAME\",\n\t\"CLOUDSDK_CONFIG\",\n\t\"CODESPACES\",\n\t\"CONDA_DEFAULT_ENV\",\n\t\"DOCKER_CONFIG\",\n\t\"DOCKER_CONTEXT\",\n\t\"GUIX_ENVIRONMENT\",\n\t\"IN_NIX_SHELL\",\n\t\"KUBECONFIG\",\n\t\"LOGNAME\",\n\t\"NIX_SHELL_LEVEL\",\n\t\"NIX_SHELL_NAME\",\n\t\"OS_CLIENT_CONFIG_FILE\",\n\t\"OS_CLOUD\",\n\t\"OS_PROJECT_NAME\",\n\t\"PATH\",\n\t\"PIXI_ENVIRONMENT_NAME\",\n\t\"PIXI_PROJECT_NAME\",\n\t\"PYENV_VERSION\",\n\t\"REMOTE_CONTAINERS\",\n\t\"RUSTC\",\n\t\"RUSTUP_TOOLCHAIN\",\n\t\"SSH_CONNECTION\",\n\t\"SSH_TTY\",\n\t\"TF_DATA_DIR\",\n\t\"TF_WORKSPACE\",\n\t\"USER\",\n\t\"USERNAME\",\n\t\"VIRTUAL_ENV\",\n\t\"WSL_DISTRO_NAME\",\n] as const;\n\nfunction allowlistedEnvironment(config: StarshipConfig): Record<string, string | undefined> {\n\tconst result: Record<string, string | undefined> = {};\n\tconst configured = config.modules.username.options.detect_env_vars;\n\tconst names = new Set([\n\t\t...ENVIRONMENT_ALLOWLIST,\n\t\t...(Array.isArray(configured)\n\t\t\t? configured.filter((name): name is string => typeof name === \"string\")\n\t\t\t: []),\n\t]);\n\tfor (const name of names) result[name] = process.env[name];\n\treturn result;\n}\n\nfunction safeUsername(): string {\n\ttry {\n\t\treturn userInfo().username;\n\t} catch {\n\t\treturn process.env.USER ?? process.env.USERNAME ?? \"\";\n\t}\n}\n\nfunction runtimeSnapshot(\n\tctx: ExtensionContext,\n\tfooterData: ReadonlyFooterDataProvider,\n\truntime: RuntimeState,\n): StarshipRuntimeSnapshot {\n\treturn {\n\t\tcwd: ctx.cwd,\n\t\thomeDir: homedir(),\n\t\tgitRoot: runtime.git?.root,\n\t\tmodel: ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined,\n\t\tthinkingLevel: runtime.thinkingLevel,\n\t\tturnCount: userTurnCount(ctx),\n\t\tactiveTools: runtime.activeTools,\n\t\tisStreaming: runtime.isStreaming,\n\t\tuiPrompt: runtime.uiPrompt,\n\t\tlastCompletedTool: runtime.lastCompletedTool,\n\t\tcontextUsage: ctx.getContextUsage() ?? undefined,\n\t\ttokenTotals: summarizeFooterUsage(ctx.sessionManager.getEntries()),\n\t\tusingSubscription: isSubscriptionBacked(ctx),\n\t\tgitBranch: runtime.git?.branch?.name ?? footerData.getGitBranch(),\n\t\tgitBranchDetails: runtime.git?.branch,\n\t\tgitCommit: runtime.git?.commit,\n\t\tgitState: runtime.git?.state,\n\t\tgitMetrics: runtime.git?.metrics,\n\t\tgitStatus: runtime.git?.status,\n\t\tgitWorktree: runtime.git?.worktree,\n\t\tgithubPr: runtime.githubPr,\n\t\tworkspace: runtime.workspace,\n\t\textensionStatuses: footerData.getExtensionStatuses(),\n\t\tnow: new Date(),\n\t};\n}\n\nfunction userTurnCount(ctx: ExtensionContext): number {\n\treturn ctx.sessionManager\n\t\t.getBranch()\n\t\t.filter((entry) => entry.type === \"message\" && entry.message.role === \"user\").length;\n}\n\nfunction isSubscriptionBacked(ctx: ExtensionContext): boolean {\n\tconst model = ctx.model;\n\treturn (\n\t\tmodel !== undefined &&\n\t\t(model.provider === \"kimi-coding\" || ctx.modelRegistry.isUsingOAuth(model))\n\t);\n}\n\nfunction formatDiagnostics(loaded: LoadedStarshipConfig): string {\n\tconst details = loaded.diagnostics.slice(0, 5).map((item) => item.message);\n\tconst remaining = loaded.diagnostics.length - details.length;\n\treturn [\n\t\t`pi-starship settings: ${details.join(\"; \")}`,\n\t\t...(remaining > 0 ? [`+${remaining} more`] : []),\n\t].join(\" \");\n}\n\nexport function wrapFormattedStatusline(format: string, width: number): string[] {\n\tif (width <= 0) return [];\n\treturn wrapTextWithAnsi(format, width);\n}\n\nexport {\n\tparseGitDiffShortstat,\n\tparseGitState,\n\tparseGitStatusPorcelain,\n\tparseGitStatusPorcelainV2,\n\tparseGitWorktree,\n} from \"./modules/git/runtime.js\";\n", "import { existsSync, readFileSync } from \"node:fs\";\nimport { basename, isAbsolute, join, resolve } from \"node:path\";\nimport type { ExtensionAPI } from \"@earendil-works/pi-coding-agent\";\nimport type {\n\tGitBranchSnapshot,\n\tGitCommitSnapshot,\n\tGitMetricsSnapshot,\n\tGitSnapshot,\n\tGitStateSnapshot,\n\tGitStatusSnapshot,\n\tGitWorktreeSnapshot,\n} from \"../types.js\";\n\nconst GIT_TIMEOUT_MS = 3_000;\n\nexport interface ReadGitSnapshotOptions {\n\tincludeMetrics: boolean;\n\tincludeTag: boolean;\n\tsignal?: AbortSignal;\n}\n\nexport async function readGitSnapshot(\n\tpi: ExtensionAPI,\n\tcwd: string,\n\toptions: ReadGitSnapshotOptions,\n): Promise<GitSnapshot | undefined> {\n\tconst statusPromise = pi.exec(\n\t\t\"git\",\n\t\t[\n\t\t\t\"--no-optional-locks\",\n\t\t\t\"status\",\n\t\t\t\"--porcelain=v2\",\n\t\t\t\"--branch\",\n\t\t\t\"--show-stash\",\n\t\t\t\"--untracked-files=normal\",\n\t\t],\n\t\t{ cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },\n\t);\n\tconst metadataPromise = pi.exec(\n\t\t\"git\",\n\t\t[\"rev-parse\", \"--path-format=absolute\", \"--show-toplevel\", \"--git-common-dir\", \"--git-dir\"],\n\t\t{ cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },\n\t);\n\tconst metricsPromise = options.includeMetrics\n\t\t? pi.exec(\"git\", [\"--no-optional-locks\", \"diff\", \"--shortstat\", \"HEAD\", \"--\"], {\n\t\t\t\tcwd,\n\t\t\t\tsignal: options.signal,\n\t\t\t\ttimeout: GIT_TIMEOUT_MS,\n\t\t\t})\n\t\t: Promise.resolve(undefined);\n\tconst tagPromise = options.includeTag\n\t\t? pi.exec(\"git\", [\"describe\", \"--tags\", \"--exact-match\", \"HEAD\"], {\n\t\t\t\tcwd,\n\t\t\t\tsignal: options.signal,\n\t\t\t\ttimeout: GIT_TIMEOUT_MS,\n\t\t\t})\n\t\t: Promise.resolve(undefined);\n\n\tconst [statusResult, metadataResult, metricsResult, tagResult] = await Promise.all([\n\t\tstatusPromise,\n\t\tmetadataPromise,\n\t\tmetricsPromise,\n\t\ttagPromise,\n\t]);\n\tif (statusResult.code !== 0 || statusResult.killed) return undefined;\n\n\tconst parsed = parseGitStatusPorcelainV2(statusResult.stdout);\n\tconst metadata =\n\t\tmetadataResult.code === 0 && !metadataResult.killed\n\t\t\t? parseGitRepositoryMetadata(metadataResult.stdout)\n\t\t\t: undefined;\n\tconst commit = withTag(parsed.commit, tagResult);\n\tconst metrics =\n\t\tmetricsResult && metricsResult.code === 0 && !metricsResult.killed\n\t\t\t? parseGitDiffShortstat(metricsResult.stdout)\n\t\t\t: undefined;\n\n\treturn {\n\t\t...parsed,\n\t\troot: metadata?.root,\n\t\tcommit,\n\t\tstate: metadata ? parseGitState(metadata.gitDirectory) : undefined,\n\t\tmetrics,\n\t\tworktree: metadata?.worktree,\n\t};\n}\n\nexport async function readGitStatus(\n\tpi: ExtensionAPI,\n\tcwd: string,\n): Promise<GitStatusSnapshot | undefined> {\n\tconst result = await pi.exec(\n\t\t\"git\",\n\t\t[\n\t\t\t\"--no-optional-locks\",\n\t\t\t\"status\",\n\t\t\t\"--porcelain=v2\",\n\t\t\t\"--branch\",\n\t\t\t\"--show-stash\",\n\t\t\t\"--untracked-files=normal\",\n\t\t],\n\t\t{ cwd, timeout: GIT_TIMEOUT_MS },\n\t);\n\tif (result.code !== 0 || result.killed) return undefined;\n\treturn parseGitStatusPorcelainV2(result.stdout).status;\n}\n\nexport async function readGitWorktree(\n\tpi: ExtensionAPI,\n\tcwd: string,\n): Promise<GitWorktreeSnapshot | undefined> {\n\tconst result = await pi.exec(\n\t\t\"git\",\n\t\t[\"rev-parse\", \"--path-format=absolute\", \"--show-toplevel\", \"--git-common-dir\", \"--git-dir\"],\n\t\t{ cwd, timeout: GIT_TIMEOUT_MS },\n\t);\n\tif (result.code !== 0 || result.killed) return undefined;\n\treturn parseGitRepositoryMetadata(result.stdout)?.worktree;\n}\n\ninterface ParsedGitStatus {\n\tbranch?: GitBranchSnapshot;\n\tcommit?: GitCommitSnapshot;\n\tstatus: GitStatusSnapshot;\n}\n\nexport function parseGitStatusPorcelainV2(output: string): ParsedGitStatus {\n\tconst status = emptyGitStatus();\n\tlet branchName: string | undefined;\n\tlet commitHash: string | undefined;\n\tlet upstream: string | undefined;\n\n\tfor (const line of output.split(/\\r?\\n/u)) {\n\t\tif (!line) continue;\n\t\tif (line.startsWith(\"# branch.oid \")) {\n\t\t\tconst value = line.slice(\"# branch.oid \".length).trim();\n\t\t\tif (value && value !== \"(initial)\") commitHash = value;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"# branch.head \")) {\n\t\t\tbranchName = line.slice(\"# branch.head \".length).trim();\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"# branch.upstream \")) {\n\t\t\tupstream = line.slice(\"# branch.upstream \".length).trim();\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"# branch.ab \")) {\n\t\t\tconst match = /^# branch\\.ab \\+(\\d+) -(\\d+)$/u.exec(line);\n\t\t\tstatus.ahead = match?.[1] ? Number(match[1]) : 0;\n\t\t\tstatus.behind = match?.[2] ? Number(match[2]) : 0;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"# stash \")) {\n\t\t\tconst count = Number(line.slice(\"# stash \".length));\n\t\t\tstatus.stashed = Number.isSafeInteger(count) && count > 0 ? count : 0;\n\t\t\tcontinue;\n\t\t}\n\t\taddPorcelainV2Status(status, line);\n\t}\n\tfinalizeStatus(status);\n\n\tconst detached = branchName === \"(detached)\";\n\tconst remote = splitUpstream(upstream);\n\tconst branch = branchName\n\t\t? {\n\t\t\t\tname: detached ? \"HEAD\" : branchName,\n\t\t\t\t...remote,\n\t\t\t\tdetached,\n\t\t\t}\n\t\t: undefined;\n\tconst commit = commitHash ? { hash: commitHash, detached } : undefined;\n\treturn { branch, commit, status };\n}\n\nexport function parseGitStatusPorcelain(output: string): GitStatusSnapshot {\n\tconst status = emptyGitStatus();\n\tfor (const line of output.split(/\\r?\\n/u)) {\n\t\tif (!line) continue;\n\t\tif (line.startsWith(\"## \")) {\n\t\t\tconst ahead = /\\bahead (\\d+)/u.exec(line);\n\t\t\tconst behind = /\\bbehind (\\d+)/u.exec(line);\n\t\t\tstatus.ahead = ahead?.[1] ? Number(ahead[1]) : 0;\n\t\t\tstatus.behind = behind?.[1] ? Number(behind[1]) : 0;\n\t\t\tcontinue;\n\t\t}\n\t\tconst indexStatus = line[0] ?? \" \";\n\t\tconst worktreeStatus = line[1] ?? \" \";\n\t\tif (indexStatus === \"?\" && worktreeStatus === \"?\") {\n\t\t\tstatus.untracked += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (isConflict(indexStatus, worktreeStatus)) {\n\t\t\tstatus.conflicted += 1;\n\t\t\tcontinue;\n\t\t}\n\t\taddNormalStatus(status, indexStatus, worktreeStatus);\n\t\tif (indexStatus === \"R\" || indexStatus === \"C\") status.renamed += 1;\n\t}\n\tfinalizeStatus(status);\n\treturn status;\n}\n\nexport function parseGitDiffShortstat(output: string): GitMetricsSnapshot {\n\treturn {\n\t\tadded: parseShortstatMetric(output, \"insertion(+)\", \"insertions(+)\") ?? 0,\n\t\tdeleted: parseShortstatMetric(output, \"deletion(-)\", \"deletions(-)\") ?? 0,\n\t};\n}\n\nfunction parseShortstatMetric(\n\toutput: string,\n\tsingularLabel: string,\n\tpluralLabel: string,\n): number | undefined {\n\tfor (const field of output.split(\",\")) {\n\t\tconst trimmed = field.trim();\n\t\tconst separator = trimmed.indexOf(\" \");\n\t\tif (separator <= 0) continue;\n\t\tconst label = trimmed.slice(separator + 1).trimStart();\n\t\tif (label !== singularLabel && label !== pluralLabel) continue;\n\t\tconst countText = trimmed.slice(0, separator);\n\t\tfor (const character of countText) {\n\t\t\tif (character < \"0\" || character > \"9\") return undefined;\n\t\t}\n\t\tconst count = Number(countText);\n\t\treturn Number.isSafeInteger(count) ? count : undefined;\n\t}\n\treturn undefined;\n}\n\nexport function parseGitState(gitDirectory: string): GitStateSnapshot | undefined {\n\tconst rebaseMerge = join(gitDirectory, \"rebase-merge\");\n\tif (existsSync(rebaseMerge))\n\t\treturn operationWithProgress(\"REBASING\", rebaseMerge, \"msgnum\", \"end\");\n\n\tconst rebaseApply = join(gitDirectory, \"rebase-apply\");\n\tif (existsSync(rebaseApply)) {\n\t\tconst state = existsSync(join(rebaseApply, \"applying\"))\n\t\t\t? \"AM\"\n\t\t\t: existsSync(join(rebaseApply, \"rebasing\"))\n\t\t\t\t? \"REBASING\"\n\t\t\t\t: \"AM/REBASE\";\n\t\treturn operationWithProgress(state, rebaseApply, \"next\", \"last\");\n\t}\n\tif (existsSync(join(gitDirectory, \"MERGE_HEAD\"))) return { state: \"MERGING\" };\n\tif (existsSync(join(gitDirectory, \"REVERT_HEAD\"))) return { state: \"REVERTING\" };\n\tif (existsSync(join(gitDirectory, \"CHERRY_PICK_HEAD\"))) return { state: \"CHERRY-PICKING\" };\n\tif (existsSync(join(gitDirectory, \"BISECT_LOG\"))) return { state: \"BISECTING\" };\n\treturn undefined;\n}\n\ninterface GitRepositoryMetadata {\n\troot: string;\n\tgitDirectory: string;\n\tworktree?: GitWorktreeSnapshot;\n}\n\nfunction parseGitRepositoryMetadata(output: string): GitRepositoryMetadata | undefined {\n\tconst lines = output.trimEnd().split(/\\r?\\n/u);\n\tif (lines.length !== 3) return undefined;\n\tconst [path, commonDir, gitDirectory] = lines;\n\tif (!path || !commonDir || !gitDirectory) return undefined;\n\tif (![path, commonDir, gitDirectory].every(isAbsolute)) return undefined;\n\treturn {\n\t\troot: path,\n\t\tgitDirectory,\n\t\tworktree: samePath(commonDir, gitDirectory)\n\t\t\t? undefined\n\t\t\t: { name: basename(path) || path, path },\n\t};\n}\n\nexport function parseGitWorktree(output: string): GitWorktreeSnapshot | undefined {\n\treturn parseGitRepositoryMetadata(output)?.worktree;\n}\n\nfunction addPorcelainV2Status(status: GitStatusSnapshot, line: string) {\n\tconst kind = line[0];\n\tif (kind === \"?\") {\n\t\tstatus.untracked += 1;\n\t\treturn;\n\t}\n\tif (kind === \"u\") {\n\t\tstatus.conflicted += 1;\n\t\treturn;\n\t}\n\tif (kind !== \"1\" && kind !== \"2\") return;\n\tconst indexStatus = line[2] ?? \".\";\n\tconst worktreeStatus = line[3] ?? \".\";\n\taddNormalStatus(status, indexStatus, worktreeStatus);\n\tif (kind === \"2\") status.renamed += 1;\n}\n\nfunction addNormalStatus(status: GitStatusSnapshot, indexStatus: string, worktreeStatus: string) {\n\tif (indexStatus === \"A\") status.indexAdded += 1;\n\tif (indexStatus === \"D\") status.indexDeleted += 1;\n\tif (indexStatus === \"M\") status.indexModified += 1;\n\tif (indexStatus === \"T\") status.indexTypechanged += 1;\n\tif (worktreeStatus === \"A\") status.worktreeAdded += 1;\n\tif (worktreeStatus === \"D\") status.worktreeDeleted += 1;\n\tif (worktreeStatus === \"M\") status.worktreeModified += 1;\n\tif (worktreeStatus === \"T\") status.worktreeTypechanged += 1;\n}\n\nfunction finalizeStatus(status: GitStatusSnapshot) {\n\tstatus.deleted = status.worktreeDeleted + status.indexDeleted;\n\tstatus.modified = status.worktreeModified + status.worktreeAdded;\n\tstatus.staged = status.indexModified + status.indexAdded + status.indexTypechanged;\n\tstatus.typechanged = status.worktreeTypechanged;\n}\n\nfunction emptyGitStatus(): GitStatusSnapshot {\n\treturn {\n\t\tahead: 0,\n\t\tbehind: 0,\n\t\tstashed: 0,\n\t\tconflicted: 0,\n\t\tdeleted: 0,\n\t\trenamed: 0,\n\t\tmodified: 0,\n\t\tstaged: 0,\n\t\ttypechanged: 0,\n\t\tuntracked: 0,\n\t\tworktreeAdded: 0,\n\t\tworktreeDeleted: 0,\n\t\tworktreeModified: 0,\n\t\tworktreeTypechanged: 0,\n\t\tindexAdded: 0,\n\t\tindexDeleted: 0,\n\t\tindexModified: 0,\n\t\tindexTypechanged: 0,\n\t};\n}\n\nfunction splitUpstream(upstream: string | undefined): {\n\tremoteName?: string;\n\tremoteBranch?: string;\n} {\n\tif (!upstream) return {};\n\tconst separator = upstream.indexOf(\"/\");\n\tif (separator <= 0 || separator === upstream.length - 1) return { remoteBranch: upstream };\n\treturn {\n\t\tremoteName: upstream.slice(0, separator),\n\t\tremoteBranch: upstream.slice(separator + 1),\n\t};\n}\n\nfunction withTag(\n\tcommit: GitCommitSnapshot | undefined,\n\tresult:\n\t\t| {\n\t\t\t\tstdout: string;\n\t\t\t\tcode: number;\n\t\t\t\tkilled: boolean;\n\t\t }\n\t\t| undefined,\n): GitCommitSnapshot | undefined {\n\tif (!commit || !result || result.code !== 0 || result.killed) return commit;\n\tconst tag = result.stdout.trim();\n\treturn tag ? { ...commit, tag: tag.split(/\\r?\\n/u)[0] } : commit;\n}\n\nfunction operationWithProgress(\n\tstate: string,\n\tdirectory: string,\n\tcurrentName: string,\n\ttotalName: string,\n): GitStateSnapshot {\n\tconst progressCurrent = readPositiveInteger(join(directory, currentName));\n\tconst progressTotal = readPositiveInteger(join(directory, totalName));\n\treturn progressCurrent !== undefined && progressTotal !== undefined\n\t\t? { state, progressCurrent, progressTotal }\n\t\t: { state };\n}\n\nfunction readPositiveInteger(path: string): number | undefined {\n\ttry {\n\t\tconst value = Number(readFileSync(path, \"utf8\").trim());\n\t\treturn Number.isSafeInteger(value) && value > 0 ? value : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction samePath(left: string, right: string): boolean {\n\tconst normalizedLeft = resolve(left);\n\tconst normalizedRight = resolve(right);\n\treturn process.platform === \"win32\"\n\t\t? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase()\n\t\t: normalizedLeft === normalizedRight;\n}\n\nfunction isConflict(indexStatus: string, worktreeStatus: string): boolean {\n\treturn (\n\t\t(indexStatus === \"D\" && worktreeStatus === \"D\") ||\n\t\t(indexStatus === \"A\" && worktreeStatus === \"A\") ||\n\t\tindexStatus === \"U\" ||\n\t\tworktreeStatus === \"U\"\n\t);\n}\n\nexport function gitStatusEqual(\n\tleft: GitStatusSnapshot | undefined,\n\tright: GitStatusSnapshot | undefined,\n): boolean {\n\treturn JSON.stringify(left) === JSON.stringify(right);\n}\n\nexport function gitSnapshotEqual(\n\tleft: GitSnapshot | undefined,\n\tright: GitSnapshot | undefined,\n): boolean {\n\treturn JSON.stringify(left) === JSON.stringify(right);\n}\n", "import { spawn } from \"node:child_process\";\nimport type { WorkspaceExec } from \"./types.js\";\n\nconst FORCE_KILL_DELAY_MS = 250;\n\nexport const execWorkspaceCommand: WorkspaceExec = async (command, args, options) =>\n\tnew Promise((resolve) => {\n\t\tif (options.signal?.aborted) {\n\t\t\tresolve({ stdout: \"\", stderr: \"\", code: 1, killed: true });\n\t\t\treturn;\n\t\t}\n\n\t\tlet child: ReturnType<typeof spawn>;\n\t\ttry {\n\t\t\tchild = spawn(command, args, {\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: explicitEnvironment(options.environment),\n\t\t\t\tshell: false,\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t} catch {\n\t\t\tresolve({ stdout: \"\", stderr: \"\", code: 1, killed: false });\n\t\t\treturn;\n\t\t}\n\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet killed = false;\n\t\tlet settled = false;\n\t\tlet forceKillTimer: NodeJS.Timeout | undefined;\n\t\tlet timeoutTimer: NodeJS.Timeout | undefined;\n\n\t\tconst finish = (code: number) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tif (timeoutTimer) clearTimeout(timeoutTimer);\n\t\t\tif (forceKillTimer) clearTimeout(forceKillTimer);\n\t\t\toptions.signal?.removeEventListener(\"abort\", terminate);\n\t\t\tresolve({\n\t\t\t\tstdout: Buffer.concat(stdout).toString(\"utf8\"),\n\t\t\t\tstderr: Buffer.concat(stderr).toString(\"utf8\"),\n\t\t\t\tcode,\n\t\t\t\tkilled,\n\t\t\t});\n\t\t};\n\n\t\tconst signalProcessTree = (signal: NodeJS.Signals) => {\n\t\t\tconst pid = child.pid;\n\t\t\tif (pid === undefined) return;\n\t\t\tif (process.platform !== \"win32\") {\n\t\t\t\ttry {\n\t\t\t\t\tprocess.kill(-pid, signal);\n\t\t\t\t\treturn;\n\t\t\t\t} catch {\n\t\t\t\t\tchild.kill(signal);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst killer = spawn(\"taskkill.exe\", [\"/pid\", String(pid), \"/t\", \"/f\"], {\n\t\t\t\t\tstdio: \"ignore\",\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t});\n\t\t\t\tkiller.once(\"error\", () => child.kill(signal));\n\t\t\t\tkiller.unref();\n\t\t\t} catch {\n\t\t\t\tchild.kill(signal);\n\t\t\t}\n\t\t};\n\n\t\tfunction terminate() {\n\t\t\tif (killed || settled) return;\n\t\t\tkilled = true;\n\t\t\tsignalProcessTree(\"SIGTERM\");\n\t\t\tforceKillTimer = setTimeout(() => {\n\t\t\t\tsignalProcessTree(\"SIGKILL\");\n\t\t\t\tchild.stdout?.destroy();\n\t\t\t\tchild.stderr?.destroy();\n\t\t\t\tfinish(1);\n\t\t\t}, FORCE_KILL_DELAY_MS);\n\t\t}\n\n\t\tconst collect = (target: Buffer[]) => (data: Buffer | string) => {\n\t\t\tconst chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);\n\t\t\tconst remaining = Math.max(0, options.maxOutputBytes - outputBytes);\n\t\t\tif (remaining > 0) target.push(chunk.subarray(0, remaining));\n\t\t\toutputBytes += chunk.byteLength;\n\t\t\tif (outputBytes > options.maxOutputBytes) terminate();\n\t\t};\n\n\t\tchild.stdout?.on(\"data\", collect(stdout));\n\t\tchild.stderr?.on(\"data\", collect(stderr));\n\t\tchild.once(\"error\", () => {\n\t\t\tif (!killed) finish(1);\n\t\t});\n\t\tchild.once(\"close\", (code) => {\n\t\t\tif (!killed) finish(code ?? 1);\n\t\t});\n\t\toptions.signal?.addEventListener(\"abort\", terminate, { once: true });\n\t\tif (options.signal?.aborted) terminate();\n\t\ttimeoutTimer = setTimeout(terminate, options.timeout);\n\t});\n\nfunction explicitEnvironment(\n\tsource: Readonly<Record<string, string | undefined>>,\n): NodeJS.ProcessEnv {\n\tconst result: NodeJS.ProcessEnv = Object.create(null);\n\tfor (const [name, value] of Object.entries(source)) {\n\t\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(name) || value === undefined || value.includes(\"\\0\")) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty(result, name, {\n\t\t\tvalue,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n\treturn result;\n}\n", "import { getCapabilities } from \"@earendil-works/pi-tui\";\nimport type { GithubPrSnapshot, GithubPrState } from \"../modules/types.js\";\nimport type { WorkspaceExec } from \"./types.js\";\n\nconst GH_TIMEOUT_MS = 10_000;\nconst MAX_GH_OUTPUT_BYTES = 128 * 1024;\nconst MAX_URL_LENGTH = 4_096;\nconst MAX_CHECKS = 1_000;\nconst MAX_FIELD_LENGTH = 128;\nconst RFC3339_TIMESTAMP =\n\t/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(?:\\.\\d{1,9})?(?:Z|[+-](\\d{2}):(\\d{2}))$/u;\nexport const TERMINAL_PR_LIFETIME_MS = 24 * 60 * 60 * 1_000;\n\nconst GH_PR_FIELDS = [\n\t\"number\",\n\t\"isDraft\",\n\t\"url\",\n\t\"state\",\n\t\"closedAt\",\n\t\"mergedAt\",\n\t\"reviewDecision\",\n\t\"statusCheckRollup\",\n] as const;\n\ninterface GithubPrQueryOptions {\n\tplatform?: NodeJS.Platform;\n\tenvironment?: Readonly<Record<string, string | undefined>>;\n}\n\ninterface CheckSummary {\n\tfailed: number;\n\tpending: number;\n\ttotal: number;\n}\n\ntype PullRequestState = \"OPEN\" | \"CLOSED\" | \"MERGED\";\ntype ReviewDecision = \"APPROVED\" | \"CHANGES_REQUESTED\" | \"REVIEW_REQUIRED\" | \"\";\n\nexport function ghPrViewInvocation(platform: NodeJS.Platform = process.platform): {\n\tcommand: string;\n\targs: string[];\n} {\n\treturn {\n\t\tcommand: platform === \"win32\" ? \"gh.exe\" : \"gh\",\n\t\targs: [\"pr\", \"view\", \"--json\", GH_PR_FIELDS.join(\",\")],\n\t};\n}\n\nexport function githubPrEnvironment(\n\tsource: Readonly<Record<string, string | undefined>> = process.env,\n): Record<string, string | undefined> {\n\tconst environment: Record<string, string | undefined> = Object.create(null);\n\tfor (const [name, value] of Object.entries(source)) {\n\t\tconst normalized = name.toUpperCase();\n\t\tif (normalized === \"GH_HOST\" || normalized === \"GH_REPO\") continue;\n\t\tObject.defineProperty(environment, name, {\n\t\t\tvalue,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n\treturn environment;\n}\n\nexport async function queryGithubPr(\n\texec: WorkspaceExec,\n\tcwd: string,\n\tsignal?: AbortSignal,\n\tnow = Date.now(),\n\toptions: GithubPrQueryOptions = {},\n): Promise<GithubPrSnapshot | undefined> {\n\tconst invocation = ghPrViewInvocation(options.platform);\n\ttry {\n\t\tconst result = await exec(invocation.command, invocation.args, {\n\t\t\tcwd,\n\t\t\tsignal,\n\t\t\ttimeout: GH_TIMEOUT_MS,\n\t\t\tmaxOutputBytes: MAX_GH_OUTPUT_BYTES,\n\t\t\tenvironment: githubPrEnvironment(options.environment),\n\t\t});\n\t\tif (result.killed || result.code !== 0) return undefined;\n\t\tif (Buffer.byteLength(result.stdout) > MAX_GH_OUTPUT_BYTES) return undefined;\n\t\treturn buildGithubPrSnapshot(JSON.parse(result.stdout), now);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function buildGithubPrSnapshot(\n\tvalue: unknown,\n\tnow = Date.now(),\n): GithubPrSnapshot | undefined {\n\ttry {\n\t\tconst pr = record(value);\n\t\tconst number = positiveInteger(pr.number);\n\t\tconst isDraft = requiredBoolean(pr.isDraft);\n\t\tconst url = requiredBoundedString(pr.url, MAX_URL_LENGTH, true);\n\t\tconst state = pullRequestState(pr.state);\n\t\tconst closedAt = optionalTimestamp(pr.closedAt);\n\t\tconst mergedAt = optionalTimestamp(pr.mergedAt);\n\t\tconst reviewDecision = reviewDecisionValue(pr.reviewDecision);\n\t\tconst checks = summarizeChecks(pr.statusCheckRollup);\n\t\tconst expiresAt = terminalExpiry(state, closedAt, mergedAt);\n\t\tif (state !== \"OPEN\" && (expiresAt === undefined || now >= expiresAt)) return undefined;\n\n\t\tconst presentationState: GithubPrState =\n\t\t\tstate === \"MERGED\" ? \"merged\" : state === \"CLOSED\" ? \"closed\" : isDraft ? \"draft\" : \"open\";\n\t\tconst checksText = formatChecks(checks);\n\t\tconst review = formatReview(reviewDecision);\n\t\tconst status = compactStatus(presentationState, checks, checksText, review);\n\t\tconst snapshot: GithubPrSnapshot = {\n\t\t\tnumber: String(number),\n\t\t\tlink: osc8Link(url, `#${number}`),\n\t\t\tstate: presentationState,\n\t\t\tchecks: checksText,\n\t\t\treview,\n\t\t\tstatus,\n\t\t\t...(expiresAt === undefined ? {} : { expiresAt }),\n\t\t};\n\t\treturn Object.freeze(snapshot);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function githubPrSnapshotEqual(\n\tleft: GithubPrSnapshot | undefined,\n\tright: GithubPrSnapshot | undefined,\n): boolean {\n\treturn JSON.stringify(left) === JSON.stringify(right);\n}\n\nfunction terminalExpiry(\n\tstate: PullRequestState,\n\tclosedAt: number | undefined,\n\tmergedAt: number | undefined,\n): number | undefined {\n\tif (state === \"OPEN\") return undefined;\n\tconst terminalAt = state === \"MERGED\" ? mergedAt : closedAt;\n\treturn terminalAt === undefined ? undefined : terminalAt + TERMINAL_PR_LIFETIME_MS;\n}\n\nfunction summarizeChecks(value: unknown): CheckSummary {\n\tif (!Array.isArray(value) || value.length > MAX_CHECKS) throw new Error(\"Invalid PR checks\");\n\tconst summary: CheckSummary = { failed: 0, pending: 0, total: value.length };\n\tfor (const item of value) {\n\t\tconst check = record(item);\n\t\tconst state = optionalUppercase(check.state);\n\t\tconst status = optionalUppercase(check.status);\n\t\tconst conclusion = optionalUppercase(check.conclusion);\n\t\tif (state === \"SUCCESS\") continue;\n\t\tif (state === \"FAILURE\" || state === \"ERROR\") {\n\t\t\tsummary.failed += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (state === \"PENDING\" || state === \"EXPECTED\") {\n\t\t\tsummary.pending += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (status && status !== \"COMPLETED\") {\n\t\t\tsummary.pending += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (conclusion === \"SUCCESS\" || conclusion === \"SKIPPED\" || conclusion === \"NEUTRAL\") {\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\tconclusion === \"FAILURE\" ||\n\t\t\tconclusion === \"CANCELLED\" ||\n\t\t\tconclusion === \"TIMED_OUT\" ||\n\t\t\tconclusion === \"ACTION_REQUIRED\" ||\n\t\t\tconclusion === \"STARTUP_FAILURE\"\n\t\t) {\n\t\t\tsummary.failed += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tsummary.pending += 1;\n\t}\n\treturn summary;\n}\n\nfunction formatChecks(checks: CheckSummary): string {\n\tif (checks.total === 0) return \"-\";\n\tconst passed = checks.total - checks.failed - checks.pending;\n\treturn [\n\t\tcompactCount(\"\u2713\", passed),\n\t\tcompactCount(\"\u00D7\", checks.failed),\n\t\tcompactCount(\"\u2026\", checks.pending),\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\" \");\n}\n\nfunction compactCount(symbol: string, count: number): string {\n\treturn count > 0 ? `${symbol}${count}` : \"\";\n}\n\nfunction formatReview(review: ReviewDecision): string {\n\tif (review === \"APPROVED\") return \"R\u2713\";\n\tif (review === \"CHANGES_REQUESTED\") return \"R\u00D7\";\n\tif (review === \"REVIEW_REQUIRED\") return \"R?\";\n\treturn \"\";\n}\n\nfunction compactStatus(\n\tstate: GithubPrState,\n\tchecks: CheckSummary,\n\tchecksText: string,\n\treview: string,\n): string {\n\tif (state === \"merged\") return \"M\";\n\tif (state === \"closed\") return \"C\";\n\tif (state === \"draft\") return \"D\";\n\tif (checks.failed > 0) return compactCount(\"\u00D7\", checks.failed);\n\tif (review === \"R\u00D7\") return review;\n\tif (checks.pending > 0) return compactCount(\"\u2026\", checks.pending);\n\tif (review === \"R\u2713\" || review === \"R?\") return review;\n\treturn checksText;\n}\n\nfunction osc8Link(value: string, label: string): string {\n\tif (!getCapabilities().hyperlinks || hasTerminalControls(value)) return label;\n\ttry {\n\t\tconst url = new URL(value);\n\t\tif ((url.protocol !== \"http:\" && url.protocol !== \"https:\") || url.username || url.password) {\n\t\t\treturn label;\n\t\t}\n\t\tconst normalized = url.toString();\n\t\tif (normalized.length > MAX_URL_LENGTH || hasTerminalControls(normalized)) return label;\n\t\treturn `\\u001b]8;;${normalized}\\u0007${label}\\u001b]8;;\\u0007`;\n\t} catch {\n\t\treturn label;\n\t}\n}\n\nfunction hasTerminalControls(value: string): boolean {\n\treturn Array.from(value).some((character) => {\n\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\treturn (\n\t\t\tcodePoint <= 0x1f ||\n\t\t\t(codePoint >= 0x7f && codePoint <= 0x9f) ||\n\t\t\t(codePoint >= 0xd800 && codePoint <= 0xdfff)\n\t\t);\n\t});\n}\n\nfunction record(value: unknown): Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new Error(\"Expected PR object\");\n\t}\n\treturn value as Record<string, unknown>;\n}\n\nfunction positiveInteger(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value <= 0) {\n\t\tthrow new Error(\"Invalid PR number\");\n\t}\n\treturn value;\n}\n\nfunction requiredBoolean(value: unknown): boolean {\n\tif (typeof value !== \"boolean\") throw new Error(\"Invalid PR boolean\");\n\treturn value;\n}\n\nfunction requiredBoundedString(value: unknown, maxLength: number, allowEmpty = false): string {\n\tif (\n\t\ttypeof value !== \"string\" ||\n\t\tvalue.length > maxLength ||\n\t\t(!allowEmpty && value.length === 0)\n\t) {\n\t\tthrow new Error(\"Invalid PR string\");\n\t}\n\treturn value;\n}\n\nfunction optionalUppercase(value: unknown): string | undefined {\n\tif (value === null || value === undefined || value === \"\") return undefined;\n\treturn requiredBoundedString(value, MAX_FIELD_LENGTH).toUpperCase();\n}\n\nfunction optionalTimestamp(value: unknown): number | undefined {\n\tif (value === null || value === undefined || value === \"\") return undefined;\n\tconst text = requiredBoundedString(value, MAX_FIELD_LENGTH);\n\tconst match = RFC3339_TIMESTAMP.exec(text);\n\tif (!match) throw new Error(\"Invalid PR timestamp\");\n\tconst [\n\t\t,\n\t\tyearText,\n\t\tmonthText,\n\t\tdayText,\n\t\thourText,\n\t\tminuteText,\n\t\tsecondText,\n\t\toffsetHourText,\n\t\toffsetMinuteText,\n\t] = match;\n\tconst year = Number(yearText);\n\tconst month = Number(monthText);\n\tconst day = Number(dayText);\n\tconst hour = Number(hourText);\n\tconst minute = Number(minuteText);\n\tconst second = Number(secondText);\n\tconst offsetHour = Number(offsetHourText ?? 0);\n\tconst offsetMinute = Number(offsetMinuteText ?? 0);\n\tif (\n\t\tmonth < 1 ||\n\t\tmonth > 12 ||\n\t\tday < 1 ||\n\t\tday > daysInMonth(year, month) ||\n\t\thour > 23 ||\n\t\tminute > 59 ||\n\t\tsecond > 59 ||\n\t\toffsetHour > 23 ||\n\t\toffsetMinute > 59\n\t) {\n\t\tthrow new Error(\"Invalid PR timestamp\");\n\t}\n\tconst timestamp = Date.parse(text);\n\tif (!Number.isFinite(timestamp)) throw new Error(\"Invalid PR timestamp\");\n\treturn timestamp;\n}\n\nfunction daysInMonth(year: number, month: number): number {\n\tif (month === 2) {\n\t\tconst leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n\t\treturn leapYear ? 29 : 28;\n\t}\n\treturn month === 4 || month === 6 || month === 9 || month === 11 ? 30 : 31;\n}\n\nfunction pullRequestState(value: unknown): PullRequestState {\n\tif (value === \"OPEN\" || value === \"CLOSED\" || value === \"MERGED\") return value;\n\tthrow new Error(\"Invalid PR state\");\n}\n\nfunction reviewDecisionValue(value: unknown): ReviewDecision {\n\tif (value === null || value === undefined || value === \"\" || value === \"UNKNOWN\") return \"\";\n\tif (value === \"APPROVED\" || value === \"CHANGES_REQUESTED\" || value === \"REVIEW_REQUIRED\") {\n\t\treturn value;\n\t}\n\tthrow new Error(\"Invalid PR review decision\");\n}\n", "export interface AsyncRefreshControllerOptions<Input, Snapshot> {\n\tread(input: Input, signal: AbortSignal): Promise<Snapshot>;\n\tequal(left: Snapshot | undefined, right: Snapshot): boolean;\n\tpublish(snapshot: Snapshot): void;\n\tonError?(error: unknown): void;\n}\n\ninterface RefreshRequest<Input> {\n\tgeneration: number;\n\trequestId: number;\n\tinput: Input;\n}\n\ninterface ActiveRefresh<Input> {\n\trequest: RefreshRequest<Input>;\n\tcontroller: AbortController;\n}\n\n/** Coalesces refreshes to one active read plus the latest pending request. */\nexport class AsyncRefreshController<Input, Snapshot> {\n\tprivate generation: number | undefined;\n\tprivate requestId = 0;\n\tprivate active: ActiveRefresh<Input> | undefined;\n\tprivate pending: RefreshRequest<Input> | undefined;\n\tprivate current: Snapshot | undefined;\n\n\tconstructor(private readonly options: AsyncRefreshControllerOptions<Input, Snapshot>) {}\n\n\tstart(generation: number): void {\n\t\tthis.cancelActive(\"Refresh generation replaced\");\n\t\tthis.generation = generation;\n\t\tthis.requestId += 1;\n\t\tthis.pending = undefined;\n\t\tthis.current = undefined;\n\t}\n\n\tclear(): void {\n\t\tthis.current = undefined;\n\t}\n\n\trequest(input: Input): void {\n\t\tif (this.generation === undefined) return;\n\t\tconst request = {\n\t\t\tgeneration: this.generation,\n\t\t\trequestId: ++this.requestId,\n\t\t\tinput,\n\t\t};\n\t\tif (this.active) {\n\t\t\tthis.pending = request;\n\t\t\treturn;\n\t\t}\n\t\tthis.run(request);\n\t}\n\n\tstop(): void {\n\t\tthis.generation = undefined;\n\t\tthis.requestId += 1;\n\t\tthis.pending = undefined;\n\t\tthis.current = undefined;\n\t\tthis.cancelActive(\"Refresh controller stopped\");\n\t}\n\n\tprivate run(request: RefreshRequest<Input>): void {\n\t\tif (!this.isCurrentTarget(request)) return;\n\t\tconst active: ActiveRefresh<Input> = {\n\t\t\trequest,\n\t\t\tcontroller: new AbortController(),\n\t\t};\n\t\tthis.active = active;\n\t\tvoid this.options\n\t\t\t.read(request.input, active.controller.signal)\n\t\t\t.then((snapshot) => {\n\t\t\t\tif (this.active !== active || !this.isCurrentRequest(request)) return;\n\t\t\t\tif (this.options.equal(this.current, snapshot)) return;\n\t\t\t\tthis.current = snapshot;\n\t\t\t\tthis.options.publish(snapshot);\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tif (\n\t\t\t\t\tthis.active === active &&\n\t\t\t\t\tthis.isCurrentRequest(request) &&\n\t\t\t\t\t!active.controller.signal.aborted\n\t\t\t\t) {\n\t\t\t\t\tthis.options.onError?.(error);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tif (this.active !== active) return;\n\t\t\t\tthis.active = undefined;\n\t\t\t\tconst pending = this.pending;\n\t\t\t\tthis.pending = undefined;\n\t\t\t\tif (pending) this.run(pending);\n\t\t\t});\n\t}\n\n\tprivate cancelActive(reason: string): void {\n\t\tthis.active?.controller.abort(new DOMException(reason, \"AbortError\"));\n\t}\n\n\tprivate isCurrentTarget(request: RefreshRequest<Input>): boolean {\n\t\treturn this.generation !== undefined && request.generation === this.generation;\n\t}\n\n\tprivate isCurrentRequest(request: RefreshRequest<Input>): boolean {\n\t\treturn this.isCurrentTarget(request) && request.requestId === this.requestId;\n\t}\n}\n", "import type { ModuleName } from \"../modules/catalog.js\";\nimport { reachableModuleRequirements } from \"../modules/render.js\";\nimport type { WorkspaceSnapshot } from \"../modules/types.js\";\nimport { createFileSystem } from \"./helpers.js\";\nimport {\n\ttype CollectorContext,\n\ttype MutableModuleSnapshot,\n\tPRIVATE_STYLE_SELECTOR,\n\ttype WorkspaceEntry,\n\ttype WorkspaceRefreshInput,\n} from \"./types.js\";\n\nexport type { WorkspaceExec, WorkspaceExecResult, WorkspaceRefreshInput } from \"./types.js\";\n\nexport async function collectWorkspaceSnapshot(\n\tinput: WorkspaceRefreshInput,\n): Promise<WorkspaceSnapshot> {\n\tconst requirements = reachableModuleRequirements(input.config);\n\tif (input.signal?.aborted || !hasWorkspaceRequirement(requirements)) return freezeSnapshot({});\n\tconst fs = createFileSystem(input);\n\tlet listing: Promise<readonly WorkspaceEntry[]> | undefined;\n\tconst context: CollectorContext = {\n\t\tinput,\n\t\tfs,\n\t\trequirements,\n\t\tentries() {\n\t\t\tlisting ??= fs.readDirectory(input.cwd);\n\t\t\treturn listing;\n\t\t},\n\t\toptions(name) {\n\t\t\treturn input.config.modules[name].options;\n\t\t},\n\t\tneeds(name, variable) {\n\t\t\tconst variables = requirements.get(name);\n\t\t\treturn Boolean(variables && (variable === undefined || variables.has(variable)));\n\t\t},\n\t};\n\tconst modules: MutableModuleSnapshot = {};\n\tif (requirements.has(\"package\")) {\n\t\tconst { collectPackage } = await import(\"./package.js\");\n\t\tif (input.signal?.aborted) return freezeSnapshot({});\n\t\tconst packageValues = await collectPackage(context);\n\t\tif (input.signal?.aborted) return freezeSnapshot({});\n\t\tif (packageValues) modules.package = packageValues;\n\t}\n\tfor (const descriptor of COLLECTOR_GROUPS) {\n\t\tif (!descriptor.modules.some((name) => requirements.has(name))) continue;\n\t\tif (input.signal?.aborted) return freezeSnapshot({});\n\t\tconst collector = await descriptor.load();\n\t\tif (input.signal?.aborted) return freezeSnapshot({});\n\t\tmergeModules(modules, await collector(context));\n\t}\n\treturn input.signal?.aborted ? freezeSnapshot({}) : freezeSnapshot(modules);\n}\n\nexport function workspaceSnapshotEqual(\n\tleft: WorkspaceSnapshot | undefined,\n\tright: WorkspaceSnapshot | undefined,\n): boolean {\n\treturn JSON.stringify(left) === JSON.stringify(right);\n}\n\nfunction hasWorkspaceRequirement(\n\trequirements: ReadonlyMap<ModuleName, ReadonlySet<string>>,\n): boolean {\n\treturn [...requirements.keys()].some((name) => !BUILT_IN_ONLY_MODULES.has(name));\n}\n\ntype WorkspaceCollector = (context: CollectorContext) => Promise<MutableModuleSnapshot>;\n\nconst COLLECTOR_GROUPS: readonly {\n\tmodules: readonly ModuleName[];\n\tload(): Promise<WorkspaceCollector>;\n}[] = [\n\t{\n\t\tmodules: [\"nodejs\", \"python\", \"rust\", \"golang\", \"bun\", \"deno\"],\n\t\tload: async () => (await import(\"./languages.js\")).collectLanguages,\n\t},\n\t{\n\t\tmodules: [\"mise\", \"direnv\", \"pixi\", \"conda\", \"nix_shell\", \"guix_shell\"],\n\t\tload: async () => (await import(\"./development.js\")).collectDevelopment,\n\t},\n\t{\n\t\tmodules: [\"docker_context\", \"kubernetes\", \"terraform\"],\n\t\tload: async () => (await import(\"./deployment.js\")).collectDeployment,\n\t},\n\t{\n\t\tmodules: [\"aws\", \"gcloud\", \"azure\", \"openstack\"],\n\t\tload: async () => (await import(\"./cloud.js\")).collectCloud,\n\t},\n\t{\n\t\tmodules: [\"container\", \"hostname\", \"os\", \"username\"],\n\t\tload: async () => (await import(\"./execution.js\")).collectExecution,\n\t},\n];\n\nconst BUILT_IN_ONLY_MODULES = new Set<ModuleName>([\n\t\"brand\",\n\t\"provider\",\n\t\"model\",\n\t\"thinking\",\n\t\"directory\",\n\t\"git_worktree\",\n\t\"git_branch\",\n\t\"github_pr\",\n\t\"git_commit\",\n\t\"git_state\",\n\t\"git_metrics\",\n\t\"git_status\",\n\t\"activity\",\n\t\"context\",\n\t\"tokens\",\n\t\"cost\",\n\t\"time\",\n\t\"turn\",\n\t\"fill\",\n\t\"extension_status\",\n]);\n\nfunction mergeModules(target: MutableModuleSnapshot, source: MutableModuleSnapshot): void {\n\tfor (const [name, values] of Object.entries(source)) {\n\t\tObject.defineProperty(target, name, {\n\t\t\tvalue: values,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n}\n\nfunction freezeSnapshot(modules: MutableModuleSnapshot): WorkspaceSnapshot {\n\tconst styleSelectors: Record<string, string> = {};\n\tfor (const [name, values] of Object.entries(modules)) {\n\t\tconst selector = Object.hasOwn(values, PRIVATE_STYLE_SELECTOR)\n\t\t\t? values[PRIVATE_STYLE_SELECTOR]\n\t\t\t: undefined;\n\t\tdelete values[PRIVATE_STYLE_SELECTOR];\n\t\tif (selector !== undefined) styleSelectors[name] = selector;\n\t\tObject.freeze(values);\n\t}\n\treturn Object.freeze({\n\t\tmodules: Object.freeze(modules),\n\t\t...(Object.keys(styleSelectors).length > 0\n\t\t\t? { styleSelectors: Object.freeze(styleSelectors) }\n\t\t\t: {}),\n\t});\n}\n", "import type { SessionEntry } from \"@earendil-works/pi-coding-agent\";\n\ninterface UsageLike {\n\tinput?: number;\n\toutput?: number;\n\tcacheRead?: number;\n\tcacheWrite?: number;\n\tcost?: { total?: number };\n}\n\nexport interface FooterUsageSummary {\n\tinput: number;\n\toutput: number;\n\tcacheRead: number;\n\tcacheWrite: number;\n\tcost: number;\n\tlatestCacheHitRate?: number;\n}\n\nexport function summarizeFooterUsage(entries: readonly SessionEntry[]): FooterUsageSummary {\n\tconst totals: FooterUsageSummary = {\n\t\tinput: 0,\n\t\toutput: 0,\n\t\tcacheRead: 0,\n\t\tcacheWrite: 0,\n\t\tcost: 0,\n\t};\n\n\tfor (const entry of entries) {\n\t\tlet usage: UsageLike | undefined;\n\t\tif (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\tusage = entry.message.usage;\n\t\t\tconst input = usage.input ?? 0;\n\t\t\tconst cacheRead = usage.cacheRead ?? 0;\n\t\t\tconst cacheWrite = usage.cacheWrite ?? 0;\n\t\t\tconst promptTokens = input + cacheRead + cacheWrite;\n\t\t\ttotals.latestCacheHitRate = promptTokens > 0 ? (cacheRead / promptTokens) * 100 : undefined;\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"toolResult\") {\n\t\t\tusage = entry.message.usage;\n\t\t} else if (entry.type === \"compaction\" || entry.type === \"branch_summary\") {\n\t\t\tusage = entry.usage;\n\t\t}\n\t\tif (!usage) continue;\n\n\t\ttotals.input += usage.input ?? 0;\n\t\ttotals.output += usage.output ?? 0;\n\t\ttotals.cacheRead += usage.cacheRead ?? 0;\n\t\ttotals.cacheWrite += usage.cacheWrite ?? 0;\n\t\ttotals.cost += usage.cost?.total ?? 0;\n\t}\n\n\treturn totals;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,UAAU,gBAAgB;AAC5C;AAAA,EAGC;AAAA,OAEM;AACP,SAAS,mBAAAA,kBAAiB,wBAAwB;;;ACPlD,SAAS,YAAY,oBAAoB;AACzC,SAAS,UAAU,YAAY,MAAM,eAAe;AAYpD,IAAM,iBAAiB;AAQvB,eAAsB,gBACrB,IACA,KACA,SACmC;AACnC,QAAM,gBAAgB,GAAG;AAAA,IACxB;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA,EAAE,KAAK,QAAQ,QAAQ,QAAQ,SAAS,eAAe;AAAA,EACxD;AACA,QAAM,kBAAkB,GAAG;AAAA,IAC1B;AAAA,IACA,CAAC,aAAa,0BAA0B,mBAAmB,oBAAoB,WAAW;AAAA,IAC1F,EAAE,KAAK,QAAQ,QAAQ,QAAQ,SAAS,eAAe;AAAA,EACxD;AACA,QAAM,iBAAiB,QAAQ,iBAC5B,GAAG,KAAK,OAAO,CAAC,uBAAuB,QAAQ,eAAe,QAAQ,IAAI,GAAG;AAAA,IAC7E;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB,SAAS;AAAA,EACV,CAAC,IACA,QAAQ,QAAQ,MAAS;AAC5B,QAAM,aAAa,QAAQ,aACxB,GAAG,KAAK,OAAO,CAAC,YAAY,UAAU,iBAAiB,MAAM,GAAG;AAAA,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FooterDataProvider,\n} from \"@earendil-works/pi-coding-agent\";\nimport { getCapabilities, wrapTextWithAnsi } from \"@earendil-works/pi-tui\";\nimport { completeStarshipArguments } from \"./command-contract.js\";\nimport type { StarshipCommandOptions } from \"./commands.js\";\nimport {\n\ttype LoadedStarshipConfig,\n\tloadStarshipConfig,\n\ttype StarshipConfig,\n\tsettingsFilePath,\n} from \"./config.js\";\nimport { gitSnapshotEqual, readGitSnapshot } from \"./modules/git/runtime.js\";\nimport {\n\ttype GithubPrSnapshot,\n\ttype GitSnapshot,\n\tinspectStatuslineModules,\n\treachableModuleRequirements,\n\trenderStatusline,\n\ttype StarshipRuntimeSnapshot,\n\ttype StatuslineInspection,\n\ttype WorkspaceSnapshot,\n} from \"./modules/index.js\";\nimport { execWorkspaceCommand } from \"./runtime/command.js\";\nimport { githubPrSnapshotEqual, queryGithubPr } from \"./runtime/github-pr.js\";\nimport { AsyncRefreshController } from \"./runtime/refresh-controller.js\";\nimport {\n\tcollectWorkspaceSnapshot,\n\ttype WorkspaceExec,\n\ttype WorkspaceRefreshInput,\n\tworkspaceSnapshotEqual,\n} from \"./runtime/workspace.js\";\nimport { summarizeFooterUsage } from \"./usage.js\";\n\nconst REFRESH_INTERVAL_MS = 30_000;\nconst GITHUB_PR_REFRESH_INTERVAL_MS = 60_000;\nconst EVENT_DEBOUNCE_MS = 250;\nconst MAX_TIMER_DELAY_MS = 2_147_483_647;\n\ntype StarshipCommands = typeof import(\"./commands.js\");\nlet starshipCommandsPromise: Promise<StarshipCommands> | undefined;\n\nfunction loadStarshipCommands(): Promise<StarshipCommands> {\n\tif (!starshipCommandsPromise) {\n\t\tstarshipCommandsPromise = import(\"./commands.js\").catch((error) => {\n\t\t\tstarshipCommandsPromise = undefined;\n\t\t\tthrow error;\n\t\t});\n\t}\n\treturn starshipCommandsPromise;\n}\n\ninterface RuntimeState {\n\tactiveTools: Map<string, number>;\n\tisStreaming: boolean;\n\tuiPrompt?: NonNullable<StarshipRuntimeSnapshot[\"uiPrompt\"]>;\n\tthinkingLevel: string;\n\tlastCompletedTool?: string;\n\tgit?: GitSnapshot;\n\tgithubPr?: GithubPrSnapshot;\n\tworkspace?: WorkspaceSnapshot;\n\trequestRender?: () => void;\n\trenderPreview?: (loaded: LoadedStarshipConfig, width: number) => string[];\n\tinspect?: (loaded: LoadedStarshipConfig) => StatuslineInspection;\n\tfooterWidth?: number;\n}\n\ninterface RefreshTarget {\n\tcwd: string;\n\tgeneration: number;\n\tsessionManager: ExtensionContext[\"sessionManager\"];\n}\n\ninterface GitRefreshInput {\n\tcwd: string;\n\tconfig: StarshipConfig;\n}\n\ninterface PiStarshipOptions {\n\tgithubPrExec?: WorkspaceExec;\n}\n\nexport default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions = {}) {\n\tlet loaded: LoadedStarshipConfig | undefined;\n\tlet loadedRevision = 0;\n\tlet previewLoaded: LoadedStarshipConfig | undefined;\n\tconst runtime: RuntimeState = {\n\t\tactiveTools: new Map(),\n\t\tisStreaming: false,\n\t\tthinkingLevel: \"off\",\n\t};\n\tlet sessionGeneration = 0;\n\tlet menuController = new AbortController();\n\tlet sessionOwner: ExtensionContext[\"sessionManager\"] | undefined;\n\tlet activeTarget: RefreshTarget | undefined;\n\tlet eventDebounceTimer: ReturnType<typeof setTimeout> | undefined;\n\tlet githubPrRefreshTimer: ReturnType<typeof setInterval> | undefined;\n\tlet githubPrExpiryTimer: ReturnType<typeof setTimeout> | undefined;\n\tlet githubPrGeneration = 0;\n\n\tconst refresh = () => runtime.requestRender?.();\n\tconst ownsRuntime = (ctx: ExtensionContext) => sessionOwner === ctx.sessionManager;\n\tconst githubPrExec = options.githubPrExec ?? execWorkspaceCommand;\n\tconst gitController = new AsyncRefreshController<GitRefreshInput, GitSnapshot | undefined>({\n\t\tasync read(input, signal) {\n\t\t\tconst requirements = reachableModuleRequirements(input.config);\n\t\t\tconst gitReachable =\n\t\t\t\t[...requirements.keys()].some((name) => name.startsWith(\"git_\")) ||\n\t\t\t\t(requirements.has(\"directory\") &&\n\t\t\t\t\tinput.config.modules.directory.options.truncate_to_repo === true);\n\t\t\tif (!gitReachable) return undefined;\n\t\t\ttry {\n\t\t\t\treturn await readGitSnapshot(pi, input.cwd, {\n\t\t\t\t\tincludeMetrics: requirements.has(\"git_metrics\"),\n\t\t\t\t\tincludeTag: requirements.get(\"git_commit\")?.has(\"tag\") ?? false,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t\tequal: gitSnapshotEqual,\n\t\tpublish(snapshot) {\n\t\t\truntime.git = snapshot;\n\t\t\trefresh();\n\t\t},\n\t});\n\tconst githubPrController = new AsyncRefreshController<\n\t\tPick<RefreshTarget, \"cwd\">,\n\t\tGithubPrSnapshot | undefined\n\t>({\n\t\tread: (input, signal) => queryGithubPr(githubPrExec, input.cwd, signal),\n\t\tequal: githubPrSnapshotEqual,\n\t\tpublish(snapshot) {\n\t\t\truntime.githubPr = snapshot;\n\t\t\tscheduleGithubPrExpiry(snapshot);\n\t\t\trefresh();\n\t\t},\n\t});\n\tconst workspaceController = new AsyncRefreshController<WorkspaceRefreshInput, WorkspaceSnapshot>({\n\t\tasync read(input, signal) {\n\t\t\ttry {\n\t\t\t\treturn await collectWorkspaceSnapshot({ ...input, signal });\n\t\t\t} catch {\n\t\t\t\treturn { modules: {} };\n\t\t\t}\n\t\t},\n\t\tequal: workspaceSnapshotEqual,\n\t\tpublish(snapshot) {\n\t\t\truntime.workspace = snapshot;\n\t\t\trefresh();\n\t\t},\n\t});\n\n\tconst clearDebounce = () => {\n\t\tif (!eventDebounceTimer) return;\n\t\tclearTimeout(eventDebounceTimer);\n\t\teventDebounceTimer = undefined;\n\t};\n\tconst isActiveTarget = (target: RefreshTarget) =>\n\t\tactiveTarget?.cwd === target.cwd &&\n\t\tactiveTarget.generation === target.generation &&\n\t\tactiveTarget.sessionManager === target.sessionManager &&\n\t\ttarget.generation === sessionGeneration;\n\n\tconst requestRefresh = (\n\t\ttarget: RefreshTarget,\n\t\treason: WorkspaceRefreshInput[\"reason\"] = \"event\",\n\t) => {\n\t\tif (!loaded || !isActiveTarget(target)) return;\n\t\tgitController.request({ cwd: target.cwd, config: loaded.config });\n\t\tworkspaceController.request(\n\t\t\tworkspaceInput(target.cwd, loaded.config, reason, runtime.workspace),\n\t\t);\n\t};\n\tconst scheduleRefresh = (ctx: ExtensionContext) => {\n\t\tconst target = activeTarget;\n\t\tif (!target || target.cwd !== ctx.cwd || target.sessionManager !== ctx.sessionManager) {\n\t\t\treturn;\n\t\t}\n\t\tclearDebounce();\n\t\teventDebounceTimer = setTimeout(() => {\n\t\t\teventDebounceTimer = undefined;\n\t\t\trequestRefresh(target);\n\t\t}, EVENT_DEBOUNCE_MS);\n\t};\n\n\tfunction restartLocalControllers(target: RefreshTarget) {\n\t\tif (!isActiveTarget(target)) return;\n\t\tgitController.start(target.generation);\n\t\tworkspaceController.start(target.generation);\n\t}\n\n\tfunction clearGithubPrTimers() {\n\t\tif (githubPrRefreshTimer) clearInterval(githubPrRefreshTimer);\n\t\tif (githubPrExpiryTimer) clearTimeout(githubPrExpiryTimer);\n\t\tgithubPrRefreshTimer = undefined;\n\t\tgithubPrExpiryTimer = undefined;\n\t}\n\n\tfunction stopGithubPr() {\n\t\tclearGithubPrTimers();\n\t\tgithubPrController.stop();\n\t\truntime.githubPr = undefined;\n\t}\n\n\tfunction githubPrReachable(): boolean {\n\t\treturn Boolean(loaded && reachableModuleRequirements(loaded.config).has(\"github_pr\"));\n\t}\n\n\tfunction startGithubPr(target: RefreshTarget): boolean {\n\t\tif (!isActiveTarget(target)) return false;\n\t\tstopGithubPr();\n\t\tif (!githubPrReachable()) return false;\n\t\tgithubPrController.start(++githubPrGeneration);\n\t\tgithubPrRefreshTimer = setInterval(() => {\n\t\t\trequestGithubPr(target);\n\t\t}, GITHUB_PR_REFRESH_INTERVAL_MS);\n\t\tgithubPrRefreshTimer.unref?.();\n\t\treturn true;\n\t}\n\n\tfunction requestGithubPr(target: RefreshTarget) {\n\t\tif (!isActiveTarget(target) || !githubPrReachable()) return;\n\t\tgithubPrController.request({ cwd: target.cwd });\n\t}\n\n\tfunction scheduleGithubPrExpiry(snapshot: GithubPrSnapshot | undefined) {\n\t\tif (githubPrExpiryTimer) clearTimeout(githubPrExpiryTimer);\n\t\tgithubPrExpiryTimer = undefined;\n\t\tif (snapshot?.expiresAt === undefined) return;\n\t\tconst target = activeTarget;\n\t\tif (!target) return;\n\t\tconst delay = snapshot.expiresAt - Date.now();\n\t\tif (delay <= 0) {\n\t\t\truntime.githubPr = undefined;\n\t\t\tgithubPrController.clear();\n\t\t\trefresh();\n\t\t\treturn;\n\t\t}\n\t\tgithubPrExpiryTimer = setTimeout(\n\t\t\t() => {\n\t\t\t\tgithubPrExpiryTimer = undefined;\n\t\t\t\tif (!isActiveTarget(target) || runtime.githubPr !== snapshot) return;\n\t\t\t\tscheduleGithubPrExpiry(snapshot);\n\t\t\t},\n\t\t\tMath.min(delay, MAX_TIMER_DELAY_MS),\n\t\t);\n\t\tgithubPrExpiryTimer.unref?.();\n\t}\n\n\tconst installFooter = (ctx: ExtensionContext) => {\n\t\tconst generation = ++sessionGeneration;\n\t\tsessionOwner = ctx.sessionManager;\n\t\tpreviewLoaded = undefined;\n\t\tmenuController.abort(new DOMException(\"Starship session context replaced\", \"AbortError\"));\n\t\tmenuController = new AbortController();\n\t\tconst target: RefreshTarget = { cwd: ctx.cwd, generation, sessionManager: ctx.sessionManager };\n\t\tclearDebounce();\n\t\tgitController.stop();\n\t\tworkspaceController.stop();\n\t\tstopGithubPr();\n\t\truntime.git = undefined;\n\t\truntime.workspace = undefined;\n\t\truntime.requestRender = undefined;\n\t\truntime.renderPreview = undefined;\n\t\truntime.inspect = undefined;\n\t\truntime.footerWidth = undefined;\n\t\tactiveTarget = ctx.mode === \"tui\" ? target : undefined;\n\t\tctx.ui.setStatus(\"starship\", undefined);\n\t\tif (!activeTarget || !loaded) return;\n\t\tgitController.start(generation);\n\t\tworkspaceController.start(generation);\n\t\tstartGithubPr(target);\n\n\t\tctx.ui.setFooter((tui, _theme, footerData) => {\n\t\t\truntime.requestRender = () => tui.requestRender();\n\t\t\truntime.renderPreview = (preview, width) => {\n\t\t\t\tconst snapshot = runtimeSnapshot(ctx, footerData, runtime);\n\t\t\t\treturn wrapFormattedStatusline(\n\t\t\t\t\trenderStatusline(preview.config, snapshot, width, getCapabilities().trueColor).ansi,\n\t\t\t\t\twidth,\n\t\t\t\t);\n\t\t\t};\n\t\t\truntime.inspect = (current) =>\n\t\t\t\tinspectStatuslineModules(\n\t\t\t\t\tcurrent.config,\n\t\t\t\t\truntimeSnapshot(ctx, footerData, runtime),\n\t\t\t\t\truntime.footerWidth ?? 80,\n\t\t\t\t);\n\t\t\tconst unsubscribe = footerData.onBranchChange(() => {\n\t\t\t\tif (!isActiveTarget(target)) return;\n\t\t\t\truntime.git = undefined;\n\t\t\t\trestartLocalControllers(target);\n\t\t\t\tclearDebounce();\n\t\t\t\tstartGithubPr(target);\n\t\t\t\trequestRefresh(target);\n\t\t\t\trequestGithubPr(target);\n\t\t\t\ttui.requestRender();\n\t\t\t});\n\t\t\tlet lastRender:\n\t\t\t\t| {\n\t\t\t\t\t\tsnapshot: StarshipRuntimeSnapshot;\n\t\t\t\t\t\tlines: string[];\n\t\t\t\t\t\tconfig: StarshipConfig;\n\t\t\t\t\t\twidth: number;\n\t\t\t\t }\n\t\t\t\t| undefined;\n\t\t\tconst timer = setInterval(() => {\n\t\t\t\tif (!isActiveTarget(target)) return;\n\t\t\t\tclearDebounce();\n\t\t\t\trequestRefresh(target, \"periodic\");\n\t\t\t\t// Collectors publish only changed snapshots. The clock is the sole value\n\t\t\t\t// that changes without publication; reuse the last render's session data.\n\t\t\t\tif (!lastRender || !reachableModuleRequirements(lastRender.config).get(\"time\")?.has(\"time\"))\n\t\t\t\t\treturn;\n\t\t\t\tconst now = new Date();\n\t\t\t\tconst previous = lastRender.snapshot.now;\n\t\t\t\tif (now.getHours() === previous.getHours() && now.getMinutes() === previous.getMinutes())\n\t\t\t\t\treturn;\n\t\t\t\tconst lines = wrapFormattedStatusline(\n\t\t\t\t\trenderStatusline(\n\t\t\t\t\t\tlastRender.config,\n\t\t\t\t\t\t{ ...lastRender.snapshot, now },\n\t\t\t\t\t\tlastRender.width,\n\t\t\t\t\t\tgetCapabilities().trueColor,\n\t\t\t\t\t).ansi,\n\t\t\t\t\tlastRender.width,\n\t\t\t\t);\n\t\t\t\tconst previousLines = lastRender.lines;\n\t\t\t\tif (\n\t\t\t\t\tlines.length !== previousLines.length ||\n\t\t\t\t\tlines.some((line, index) => line !== previousLines[index])\n\t\t\t\t)\n\t\t\t\t\ttui.requestRender();\n\t\t\t}, REFRESH_INTERVAL_MS);\n\t\t\tlet disposed = false;\n\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\tif (disposed) return;\n\t\t\t\t\tdisposed = true;\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tclearInterval(timer);\n\t\t\t\t\tif (isActiveTarget(target)) {\n\t\t\t\t\t\tactiveTarget = undefined;\n\t\t\t\t\t\tclearDebounce();\n\t\t\t\t\t\tgitController.stop();\n\t\t\t\t\t\tworkspaceController.stop();\n\t\t\t\t\t\tstopGithubPr();\n\t\t\t\t\t\truntime.git = undefined;\n\t\t\t\t\t\truntime.workspace = undefined;\n\t\t\t\t\t\truntime.requestRender = undefined;\n\t\t\t\t\t\truntime.renderPreview = undefined;\n\t\t\t\t\t\truntime.inspect = undefined;\n\t\t\t\t\t\truntime.footerWidth = undefined;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tinvalidate() {},\n\t\t\t\trender(width: number): string[] {\n\t\t\t\t\truntime.footerWidth = width;\n\t\t\t\t\tconst current = previewLoaded ?? loaded;\n\t\t\t\t\tif (!current) return [];\n\t\t\t\t\tconst snapshot = runtimeSnapshot(ctx, footerData, runtime);\n\t\t\t\t\tconst lines = wrapFormattedStatusline(\n\t\t\t\t\t\trenderStatusline(current.config, snapshot, width, getCapabilities().trueColor).ansi,\n\t\t\t\t\t\twidth,\n\t\t\t\t\t);\n\t\t\t\t\tlastRender = { snapshot, lines, config: current.config, width };\n\t\t\t\t\treturn lines;\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\t\trequestRefresh(target, \"initial\");\n\t\trequestGithubPr(target);\n\t};\n\n\tconst configPath = settingsFilePath(getAgentDir());\n\tconst commandOptions: StarshipCommandOptions = {\n\t\tsettingsPath: configPath,\n\t\tgetLoaded: () => loaded ?? loadStarshipConfig(configPath),\n\t\tgetLoadedRevision: () => loadedRevision,\n\t\tgetInspection: () => {\n\t\t\tconst current = loaded ?? loadStarshipConfig(configPath);\n\t\t\treturn runtime.inspect?.(current);\n\t\t},\n\t\tgetMenuOwner: () => {\n\t\t\tconst generation = sessionGeneration;\n\t\t\treturn {\n\t\t\t\tsignal: menuController.signal,\n\t\t\t\tisCurrent: () => generation === sessionGeneration && !menuController.signal.aborted,\n\t\t\t};\n\t\t},\n\t\tapply(next, ctx) {\n\t\t\tif (sessionOwner !== ctx.sessionManager) {\n\t\t\t\tthrow new Error(\"Starship session context was replaced\");\n\t\t\t}\n\t\t\tpreviewLoaded = undefined;\n\t\t\tloaded = next;\n\t\t\tloadedRevision += 1;\n\t\t\tconst target = activeTarget;\n\t\t\tif (target) {\n\t\t\t\trestartLocalControllers(target);\n\t\t\t\tstartGithubPr(target);\n\t\t\t\trequestRefresh(target);\n\t\t\t\trequestGithubPr(target);\n\t\t\t}\n\t\t\trefresh();\n\t\t},\n\t\tpreview(next, ctx) {\n\t\t\tif (sessionOwner !== ctx.sessionManager) return;\n\t\t\tpreviewLoaded = next;\n\t\t\trefresh();\n\t\t},\n\t\trenderPreview(preview, width) {\n\t\t\treturn (\n\t\t\t\truntime.renderPreview?.(preview, width) ?? [\n\t\t\t\t\t\"Live preview is unavailable until the footer is ready.\",\n\t\t\t\t]\n\t\t\t);\n\t\t},\n\t};\n\tpi.registerCommand(\"starship\", {\n\t\tdescription: \"Customize or inspect the native Starship-style footer\",\n\t\tgetArgumentCompletions: completeStarshipArguments,\n\t\thandler: async (args, ctx) => {\n\t\t\tconst commands = await loadStarshipCommands();\n\t\t\tif (sessionOwner !== ctx.sessionManager) return;\n\t\t\tawait commands.handleStarshipCommand(args, ctx, commandOptions);\n\t\t},\n\t});\n\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\truntime.activeTools.clear();\n\t\truntime.isStreaming = false;\n\t\truntime.uiPrompt = undefined;\n\t\truntime.lastCompletedTool = undefined;\n\t\tloaded = loadStarshipConfig(configPath);\n\t\tloadedRevision += 1;\n\t\tif (loaded.diagnostics.length > 0 && (ctx.mode === \"tui\" || ctx.hasUI)) {\n\t\t\tctx.ui.notify(formatDiagnostics(loaded), \"warning\");\n\t\t}\n\t\truntime.thinkingLevel = pi.getThinkingLevel();\n\t\tinstallFooter(ctx);\n\t});\n\n\tpi.on(\"session_tree\", (_event, ctx) => {\n\t\tinstallFooter(ctx);\n\t\trefresh();\n\t});\n\n\tpi.on(\"session_shutdown\", (_event, ctx) => {\n\t\tif (sessionOwner !== ctx.sessionManager) return;\n\t\tsessionOwner = undefined;\n\t\tpreviewLoaded = undefined;\n\t\tsessionGeneration += 1;\n\t\tmenuController.abort(new DOMException(\"Starship session shut down\", \"AbortError\"));\n\t\tactiveTarget = undefined;\n\t\tclearDebounce();\n\t\tgitController.stop();\n\t\tworkspaceController.stop();\n\t\tstopGithubPr();\n\t\truntime.git = undefined;\n\t\truntime.workspace = undefined;\n\t\truntime.activeTools.clear();\n\t\truntime.isStreaming = false;\n\t\truntime.uiPrompt = undefined;\n\t\truntime.lastCompletedTool = undefined;\n\t\truntime.requestRender = undefined;\n\t\truntime.renderPreview = undefined;\n\t\truntime.inspect = undefined;\n\t\truntime.footerWidth = undefined;\n\t\tctx.ui.setFooter(undefined);\n\t\tctx.ui.setStatus(\"starship\", undefined);\n\t});\n\n\tpi.on(\"model_select\", () => refresh());\n\tpi.on(\"thinking_level_select\", (event) => {\n\t\truntime.thinkingLevel = event.level;\n\t\trefresh();\n\t});\n\tpi.on(\"agent_start\", () => {\n\t\truntime.isStreaming = true;\n\t\trefresh();\n\t});\n\tpi.on(\"agent_end\", (_event, ctx) => {\n\t\truntime.isStreaming = false;\n\t\tscheduleRefresh(ctx);\n\t\tconst target = activeTarget;\n\t\tif (target?.sessionManager === ctx.sessionManager) requestGithubPr(target);\n\t\trefresh();\n\t});\n\tpi.on(\"ui_prompt_start\", (event, ctx) => {\n\t\tif (!ownsRuntime(ctx)) return;\n\t\truntime.uiPrompt = { kind: event.kind, title: event.title };\n\t\trefresh();\n\t});\n\tpi.on(\"ui_prompt_end\", (_event, ctx) => {\n\t\tif (!ownsRuntime(ctx)) return;\n\t\truntime.uiPrompt = undefined;\n\t\trefresh();\n\t});\n\tpi.on(\"turn_start\", () => {\n\t\truntime.isStreaming = true;\n\t\trefresh();\n\t});\n\tpi.on(\"turn_end\", (_event, ctx) => {\n\t\tscheduleRefresh(ctx);\n\t\trefresh();\n\t});\n\tpi.on(\"tool_execution_start\", (event) => {\n\t\truntime.activeTools.set(event.toolName, (runtime.activeTools.get(event.toolName) ?? 0) + 1);\n\t\trefresh();\n\t});\n\tpi.on(\"tool_execution_end\", (event, ctx) => {\n\t\tconst count = runtime.activeTools.get(event.toolName) ?? 0;\n\t\tif (count <= 1) runtime.activeTools.delete(event.toolName);\n\t\telse runtime.activeTools.set(event.toolName, count - 1);\n\t\truntime.lastCompletedTool = event.toolName;\n\t\tscheduleRefresh(ctx);\n\t\trefresh();\n\t});\n}\n\nfunction workspaceInput(\n\tcwd: string,\n\tconfig: StarshipConfig,\n\treason: WorkspaceRefreshInput[\"reason\"],\n\tprevious: WorkspaceSnapshot | undefined,\n): WorkspaceRefreshInput {\n\treturn {\n\t\tcwd,\n\t\tconfig,\n\t\tenvironment: allowlistedEnvironment(config),\n\t\thomeDir: homedir(),\n\t\tplatform: process.platform,\n\t\thostname: hostname(),\n\t\tusername: safeUsername(),\n\t\texec: execWorkspaceCommand,\n\t\treason,\n\t\tprevious,\n\t};\n}\n\nconst ENVIRONMENT_ALLOWLIST = [\n\t\"AWS_CONFIG_FILE\",\n\t\"AWS_DEFAULT_PROFILE\",\n\t\"AWS_DEFAULT_REGION\",\n\t\"AWS_PROFILE\",\n\t\"AWS_REGION\",\n\t\"AZURE_CONFIG_DIR\",\n\t\"CLOUDSDK_ACTIVE_CONFIG_NAME\",\n\t\"CLOUDSDK_CONFIG\",\n\t\"CODESPACES\",\n\t\"CONDA_DEFAULT_ENV\",\n\t\"DOCKER_CONFIG\",\n\t\"DOCKER_CONTEXT\",\n\t\"GUIX_ENVIRONMENT\",\n\t\"IN_NIX_SHELL\",\n\t\"KUBECONFIG\",\n\t\"LOGNAME\",\n\t\"NIX_SHELL_LEVEL\",\n\t\"NIX_SHELL_NAME\",\n\t\"OS_CLIENT_CONFIG_FILE\",\n\t\"OS_CLOUD\",\n\t\"OS_PROJECT_NAME\",\n\t\"PATH\",\n\t\"PIXI_ENVIRONMENT_NAME\",\n\t\"PIXI_PROJECT_NAME\",\n\t\"PYENV_VERSION\",\n\t\"REMOTE_CONTAINERS\",\n\t\"RUSTC\",\n\t\"RUSTUP_TOOLCHAIN\",\n\t\"SSH_CONNECTION\",\n\t\"SSH_TTY\",\n\t\"TF_DATA_DIR\",\n\t\"TF_WORKSPACE\",\n\t\"USER\",\n\t\"USERNAME\",\n\t\"VIRTUAL_ENV\",\n\t\"WSL_DISTRO_NAME\",\n] as const;\n\nfunction allowlistedEnvironment(config: StarshipConfig): Record<string, string | undefined> {\n\tconst result: Record<string, string | undefined> = {};\n\tconst configured = config.modules.username.options.detect_env_vars;\n\tconst names = new Set([\n\t\t...ENVIRONMENT_ALLOWLIST,\n\t\t...(Array.isArray(configured)\n\t\t\t? configured.filter((name): name is string => typeof name === \"string\")\n\t\t\t: []),\n\t]);\n\tfor (const name of names) result[name] = process.env[name];\n\treturn result;\n}\n\nfunction safeUsername(): string {\n\ttry {\n\t\treturn userInfo().username;\n\t} catch {\n\t\treturn process.env.USER ?? process.env.USERNAME ?? \"\";\n\t}\n}\n\nfunction runtimeSnapshot(\n\tctx: ExtensionContext,\n\tfooterData: ReadonlyFooterDataProvider,\n\truntime: RuntimeState,\n): StarshipRuntimeSnapshot {\n\treturn {\n\t\tcwd: ctx.cwd,\n\t\thomeDir: homedir(),\n\t\tgitRoot: runtime.git?.root,\n\t\tmodel: ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined,\n\t\tthinkingLevel: runtime.thinkingLevel,\n\t\tturnCount: userTurnCount(ctx),\n\t\tactiveTools: runtime.activeTools,\n\t\tisStreaming: runtime.isStreaming,\n\t\tuiPrompt: runtime.uiPrompt,\n\t\tlastCompletedTool: runtime.lastCompletedTool,\n\t\tcontextUsage: ctx.getContextUsage() ?? undefined,\n\t\ttokenTotals: summarizeFooterUsage(ctx.sessionManager.getEntries()),\n\t\tusingSubscription: isSubscriptionBacked(ctx),\n\t\tgitBranch: runtime.git?.branch?.name ?? footerData.getGitBranch(),\n\t\tgitBranchDetails: runtime.git?.branch,\n\t\tgitCommit: runtime.git?.commit,\n\t\tgitState: runtime.git?.state,\n\t\tgitMetrics: runtime.git?.metrics,\n\t\tgitStatus: runtime.git?.status,\n\t\tgitWorktree: runtime.git?.worktree,\n\t\tgithubPr: runtime.githubPr,\n\t\tworkspace: runtime.workspace,\n\t\textensionStatuses: footerData.getExtensionStatuses(),\n\t\tnow: new Date(),\n\t};\n}\n\nfunction userTurnCount(ctx: ExtensionContext): number {\n\treturn ctx.sessionManager\n\t\t.getBranch()\n\t\t.filter((entry) => entry.type === \"message\" && entry.message.role === \"user\").length;\n}\n\nfunction isSubscriptionBacked(ctx: ExtensionContext): boolean {\n\tconst model = ctx.model;\n\treturn (\n\t\tmodel !== undefined &&\n\t\t(model.provider === \"kimi-coding\" || ctx.modelRegistry.isUsingOAuth(model))\n\t);\n}\n\nfunction formatDiagnostics(loaded: LoadedStarshipConfig): string {\n\tconst details = loaded.diagnostics.slice(0, 5).map((item) => item.message);\n\tconst remaining = loaded.diagnostics.length - details.length;\n\treturn [\n\t\t`pi-starship settings: ${details.join(\"; \")}`,\n\t\t...(remaining > 0 ? [`+${remaining} more`] : []),\n\t].join(\" \");\n}\n\nexport function wrapFormattedStatusline(format: string, width: number): string[] {\n\tif (width <= 0) return [];\n\treturn wrapTextWithAnsi(format, width);\n}\n\nexport {\n\tparseGitDiffShortstat,\n\tparseGitState,\n\tparseGitStatusPorcelain,\n\tparseGitStatusPorcelainV2,\n\tparseGitWorktree,\n} from \"./modules/git/runtime.js\";\n", "import { existsSync, readFileSync } from \"node:fs\";\nimport { basename, isAbsolute, join, resolve } from \"node:path\";\nimport type { ExtensionAPI } from \"@earendil-works/pi-coding-agent\";\nimport type {\n\tGitBranchSnapshot,\n\tGitCommitSnapshot,\n\tGitMetricsSnapshot,\n\tGitSnapshot,\n\tGitStateSnapshot,\n\tGitStatusSnapshot,\n\tGitWorktreeSnapshot,\n} from \"../types.js\";\n\nconst GIT_TIMEOUT_MS = 3_000;\n\nexport interface ReadGitSnapshotOptions {\n\tincludeMetrics: boolean;\n\tincludeTag: boolean;\n\tsignal?: AbortSignal;\n}\n\nexport async function readGitSnapshot(\n\tpi: ExtensionAPI,\n\tcwd: string,\n\toptions: ReadGitSnapshotOptions,\n): Promise<GitSnapshot | undefined> {\n\tconst statusPromise = pi.exec(\n\t\t\"git\",\n\t\t[\n\t\t\t\"--no-optional-locks\",\n\t\t\t\"status\",\n\t\t\t\"--porcelain=v2\",\n\t\t\t\"--branch\",\n\t\t\t\"--show-stash\",\n\t\t\t\"--untracked-files=normal\",\n\t\t],\n\t\t{ cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },\n\t);\n\tconst metadataPromise = pi.exec(\n\t\t\"git\",\n\t\t[\"rev-parse\", \"--path-format=absolute\", \"--show-toplevel\", \"--git-common-dir\", \"--git-dir\"],\n\t\t{ cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },\n\t);\n\tconst metricsPromise = options.includeMetrics\n\t\t? pi.exec(\"git\", [\"--no-optional-locks\", \"diff\", \"--shortstat\", \"HEAD\", \"--\"], {\n\t\t\t\tcwd,\n\t\t\t\tsignal: options.signal,\n\t\t\t\ttimeout: GIT_TIMEOUT_MS,\n\t\t\t})\n\t\t: Promise.resolve(undefined);\n\tconst tagPromise = options.includeTag\n\t\t? pi.exec(\"git\", [\"describe\", \"--tags\", \"--exact-match\", \"HEAD\"], {\n\t\t\t\tcwd,\n\t\t\t\tsignal: options.signal,\n\t\t\t\ttimeout: GIT_TIMEOUT_MS,\n\t\t\t})\n\t\t: Promise.resolve(undefined);\n\n\tconst [statusResult, metadataResult, metricsResult, tagResult] = await Promise.all([\n\t\tstatusPromise,\n\t\tmetadataPromise,\n\t\tmetricsPromise,\n\t\ttagPromise,\n\t]);\n\tif (statusResult.code !== 0 || statusResult.killed) return undefined;\n\n\tconst parsed = parseGitStatusPorcelainV2(statusResult.stdout);\n\tconst metadata =\n\t\tmetadataResult.code === 0 && !metadataResult.killed\n\t\t\t? parseGitRepositoryMetadata(metadataResult.stdout)\n\t\t\t: undefined;\n\tconst commit = withTag(parsed.commit, tagResult);\n\tconst metrics =\n\t\tmetricsResult && metricsResult.code === 0 && !metricsResult.killed\n\t\t\t? parseGitDiffShortstat(metricsResult.stdout)\n\t\t\t: undefined;\n\n\treturn {\n\t\t...parsed,\n\t\troot: metadata?.root,\n\t\tcommit,\n\t\tstate: metadata ? parseGitState(metadata.gitDirectory) : undefined,\n\t\tmetrics,\n\t\tworktree: metadata?.worktree,\n\t};\n}\n\nexport async function readGitStatus(\n\tpi: ExtensionAPI,\n\tcwd: string,\n): Promise<GitStatusSnapshot | undefined> {\n\tconst result = await pi.exec(\n\t\t\"git\",\n\t\t[\n\t\t\t\"--no-optional-locks\",\n\t\t\t\"status\",\n\t\t\t\"--porcelain=v2\",\n\t\t\t\"--branch\",\n\t\t\t\"--show-stash\",\n\t\t\t\"--untracked-files=normal\",\n\t\t],\n\t\t{ cwd, timeout: GIT_TIMEOUT_MS },\n\t);\n\tif (result.code !== 0 || result.killed) return undefined;\n\treturn parseGitStatusPorcelainV2(result.stdout).status;\n}\n\nexport async function readGitWorktree(\n\tpi: ExtensionAPI,\n\tcwd: string,\n): Promise<GitWorktreeSnapshot | undefined> {\n\tconst result = await pi.exec(\n\t\t\"git\",\n\t\t[\"rev-parse\", \"--path-format=absolute\", \"--show-toplevel\", \"--git-common-dir\", \"--git-dir\"],\n\t\t{ cwd, timeout: GIT_TIMEOUT_MS },\n\t);\n\tif (result.code !== 0 || result.killed) return undefined;\n\treturn parseGitRepositoryMetadata(result.stdout)?.worktree;\n}\n\ninterface ParsedGitStatus {\n\tbranch?: GitBranchSnapshot;\n\tcommit?: GitCommitSnapshot;\n\tstatus: GitStatusSnapshot;\n}\n\nexport function parseGitStatusPorcelainV2(output: string): ParsedGitStatus {\n\tconst status = emptyGitStatus();\n\tlet branchName: string | undefined;\n\tlet commitHash: string | undefined;\n\tlet upstream: string | undefined;\n\n\tfor (const line of output.split(/\\r?\\n/u)) {\n\t\tif (!line) continue;\n\t\tif (line.startsWith(\"# branch.oid \")) {\n\t\t\tconst value = line.slice(\"# branch.oid \".length).trim();\n\t\t\tif (value && value !== \"(initial)\") commitHash = value;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"# branch.head \")) {\n\t\t\tbranchName = line.slice(\"# branch.head \".length).trim();\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"# branch.upstream \")) {\n\t\t\tupstream = line.slice(\"# branch.upstream \".length).trim();\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"# branch.ab \")) {\n\t\t\tconst match = /^# branch\\.ab \\+(\\d+) -(\\d+)$/u.exec(line);\n\t\t\tstatus.ahead = match?.[1] ? Number(match[1]) : 0;\n\t\t\tstatus.behind = match?.[2] ? Number(match[2]) : 0;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"# stash \")) {\n\t\t\tconst count = Number(line.slice(\"# stash \".length));\n\t\t\tstatus.stashed = Number.isSafeInteger(count) && count > 0 ? count : 0;\n\t\t\tcontinue;\n\t\t}\n\t\taddPorcelainV2Status(status, line);\n\t}\n\tfinalizeStatus(status);\n\n\tconst detached = branchName === \"(detached)\";\n\tconst remote = splitUpstream(upstream);\n\tconst branch = branchName\n\t\t? {\n\t\t\t\tname: detached ? \"HEAD\" : branchName,\n\t\t\t\t...remote,\n\t\t\t\tdetached,\n\t\t\t}\n\t\t: undefined;\n\tconst commit = commitHash ? { hash: commitHash, detached } : undefined;\n\treturn { branch, commit, status };\n}\n\nexport function parseGitStatusPorcelain(output: string): GitStatusSnapshot {\n\tconst status = emptyGitStatus();\n\tfor (const line of output.split(/\\r?\\n/u)) {\n\t\tif (!line) continue;\n\t\tif (line.startsWith(\"## \")) {\n\t\t\tconst ahead = /\\bahead (\\d+)/u.exec(line);\n\t\t\tconst behind = /\\bbehind (\\d+)/u.exec(line);\n\t\t\tstatus.ahead = ahead?.[1] ? Number(ahead[1]) : 0;\n\t\t\tstatus.behind = behind?.[1] ? Number(behind[1]) : 0;\n\t\t\tcontinue;\n\t\t}\n\t\tconst indexStatus = line[0] ?? \" \";\n\t\tconst worktreeStatus = line[1] ?? \" \";\n\t\tif (indexStatus === \"?\" && worktreeStatus === \"?\") {\n\t\t\tstatus.untracked += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (isConflict(indexStatus, worktreeStatus)) {\n\t\t\tstatus.conflicted += 1;\n\t\t\tcontinue;\n\t\t}\n\t\taddNormalStatus(status, indexStatus, worktreeStatus);\n\t\tif (indexStatus === \"R\" || indexStatus === \"C\") status.renamed += 1;\n\t}\n\tfinalizeStatus(status);\n\treturn status;\n}\n\nexport function parseGitDiffShortstat(output: string): GitMetricsSnapshot {\n\treturn {\n\t\tadded: parseShortstatMetric(output, \"insertion(+)\", \"insertions(+)\") ?? 0,\n\t\tdeleted: parseShortstatMetric(output, \"deletion(-)\", \"deletions(-)\") ?? 0,\n\t};\n}\n\nfunction parseShortstatMetric(\n\toutput: string,\n\tsingularLabel: string,\n\tpluralLabel: string,\n): number | undefined {\n\tfor (const field of output.split(\",\")) {\n\t\tconst trimmed = field.trim();\n\t\tconst separator = trimmed.indexOf(\" \");\n\t\tif (separator <= 0) continue;\n\t\tconst label = trimmed.slice(separator + 1).trimStart();\n\t\tif (label !== singularLabel && label !== pluralLabel) continue;\n\t\tconst countText = trimmed.slice(0, separator);\n\t\tfor (const character of countText) {\n\t\t\tif (character < \"0\" || character > \"9\") return undefined;\n\t\t}\n\t\tconst count = Number(countText);\n\t\treturn Number.isSafeInteger(count) ? count : undefined;\n\t}\n\treturn undefined;\n}\n\nexport function parseGitState(gitDirectory: string): GitStateSnapshot | undefined {\n\tconst rebaseMerge = join(gitDirectory, \"rebase-merge\");\n\tif (existsSync(rebaseMerge))\n\t\treturn operationWithProgress(\"REBASING\", rebaseMerge, \"msgnum\", \"end\");\n\n\tconst rebaseApply = join(gitDirectory, \"rebase-apply\");\n\tif (existsSync(rebaseApply)) {\n\t\tconst state = existsSync(join(rebaseApply, \"applying\"))\n\t\t\t? \"AM\"\n\t\t\t: existsSync(join(rebaseApply, \"rebasing\"))\n\t\t\t\t? \"REBASING\"\n\t\t\t\t: \"AM/REBASE\";\n\t\treturn operationWithProgress(state, rebaseApply, \"next\", \"last\");\n\t}\n\tif (existsSync(join(gitDirectory, \"MERGE_HEAD\"))) return { state: \"MERGING\" };\n\tif (existsSync(join(gitDirectory, \"REVERT_HEAD\"))) return { state: \"REVERTING\" };\n\tif (existsSync(join(gitDirectory, \"CHERRY_PICK_HEAD\"))) return { state: \"CHERRY-PICKING\" };\n\tif (existsSync(join(gitDirectory, \"BISECT_LOG\"))) return { state: \"BISECTING\" };\n\treturn undefined;\n}\n\ninterface GitRepositoryMetadata {\n\troot: string;\n\tgitDirectory: string;\n\tworktree?: GitWorktreeSnapshot;\n}\n\nfunction parseGitRepositoryMetadata(output: string): GitRepositoryMetadata | undefined {\n\tconst lines = output.trimEnd().split(/\\r?\\n/u);\n\tif (lines.length !== 3) return undefined;\n\tconst [path, commonDir, gitDirectory] = lines;\n\tif (!path || !commonDir || !gitDirectory) return undefined;\n\tif (![path, commonDir, gitDirectory].every(isAbsolute)) return undefined;\n\treturn {\n\t\troot: path,\n\t\tgitDirectory,\n\t\tworktree: samePath(commonDir, gitDirectory)\n\t\t\t? undefined\n\t\t\t: { name: basename(path) || path, path },\n\t};\n}\n\nexport function parseGitWorktree(output: string): GitWorktreeSnapshot | undefined {\n\treturn parseGitRepositoryMetadata(output)?.worktree;\n}\n\nfunction addPorcelainV2Status(status: GitStatusSnapshot, line: string) {\n\tconst kind = line[0];\n\tif (kind === \"?\") {\n\t\tstatus.untracked += 1;\n\t\treturn;\n\t}\n\tif (kind === \"u\") {\n\t\tstatus.conflicted += 1;\n\t\treturn;\n\t}\n\tif (kind !== \"1\" && kind !== \"2\") return;\n\tconst indexStatus = line[2] ?? \".\";\n\tconst worktreeStatus = line[3] ?? \".\";\n\taddNormalStatus(status, indexStatus, worktreeStatus);\n\tif (kind === \"2\") status.renamed += 1;\n}\n\nfunction addNormalStatus(status: GitStatusSnapshot, indexStatus: string, worktreeStatus: string) {\n\tif (indexStatus === \"A\") status.indexAdded += 1;\n\tif (indexStatus === \"D\") status.indexDeleted += 1;\n\tif (indexStatus === \"M\") status.indexModified += 1;\n\tif (indexStatus === \"T\") status.indexTypechanged += 1;\n\tif (worktreeStatus === \"A\") status.worktreeAdded += 1;\n\tif (worktreeStatus === \"D\") status.worktreeDeleted += 1;\n\tif (worktreeStatus === \"M\") status.worktreeModified += 1;\n\tif (worktreeStatus === \"T\") status.worktreeTypechanged += 1;\n}\n\nfunction finalizeStatus(status: GitStatusSnapshot) {\n\tstatus.deleted = status.worktreeDeleted + status.indexDeleted;\n\tstatus.modified = status.worktreeModified + status.worktreeAdded;\n\tstatus.staged = status.indexModified + status.indexAdded + status.indexTypechanged;\n\tstatus.typechanged = status.worktreeTypechanged;\n}\n\nfunction emptyGitStatus(): GitStatusSnapshot {\n\treturn {\n\t\tahead: 0,\n\t\tbehind: 0,\n\t\tstashed: 0,\n\t\tconflicted: 0,\n\t\tdeleted: 0,\n\t\trenamed: 0,\n\t\tmodified: 0,\n\t\tstaged: 0,\n\t\ttypechanged: 0,\n\t\tuntracked: 0,\n\t\tworktreeAdded: 0,\n\t\tworktreeDeleted: 0,\n\t\tworktreeModified: 0,\n\t\tworktreeTypechanged: 0,\n\t\tindexAdded: 0,\n\t\tindexDeleted: 0,\n\t\tindexModified: 0,\n\t\tindexTypechanged: 0,\n\t};\n}\n\nfunction splitUpstream(upstream: string | undefined): {\n\tremoteName?: string;\n\tremoteBranch?: string;\n} {\n\tif (!upstream) return {};\n\tconst separator = upstream.indexOf(\"/\");\n\tif (separator <= 0 || separator === upstream.length - 1) return { remoteBranch: upstream };\n\treturn {\n\t\tremoteName: upstream.slice(0, separator),\n\t\tremoteBranch: upstream.slice(separator + 1),\n\t};\n}\n\nfunction withTag(\n\tcommit: GitCommitSnapshot | undefined,\n\tresult:\n\t\t| {\n\t\t\t\tstdout: string;\n\t\t\t\tcode: number;\n\t\t\t\tkilled: boolean;\n\t\t }\n\t\t| undefined,\n): GitCommitSnapshot | undefined {\n\tif (!commit || !result || result.code !== 0 || result.killed) return commit;\n\tconst tag = result.stdout.trim();\n\treturn tag ? { ...commit, tag: tag.split(/\\r?\\n/u)[0] } : commit;\n}\n\nfunction operationWithProgress(\n\tstate: string,\n\tdirectory: string,\n\tcurrentName: string,\n\ttotalName: string,\n): GitStateSnapshot {\n\tconst progressCurrent = readPositiveInteger(join(directory, currentName));\n\tconst progressTotal = readPositiveInteger(join(directory, totalName));\n\treturn progressCurrent !== undefined && progressTotal !== undefined\n\t\t? { state, progressCurrent, progressTotal }\n\t\t: { state };\n}\n\nfunction readPositiveInteger(path: string): number | undefined {\n\ttry {\n\t\tconst value = Number(readFileSync(path, \"utf8\").trim());\n\t\treturn Number.isSafeInteger(value) && value > 0 ? value : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction samePath(left: string, right: string): boolean {\n\tconst normalizedLeft = resolve(left);\n\tconst normalizedRight = resolve(right);\n\treturn process.platform === \"win32\"\n\t\t? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase()\n\t\t: normalizedLeft === normalizedRight;\n}\n\nfunction isConflict(indexStatus: string, worktreeStatus: string): boolean {\n\treturn (\n\t\t(indexStatus === \"D\" && worktreeStatus === \"D\") ||\n\t\t(indexStatus === \"A\" && worktreeStatus === \"A\") ||\n\t\tindexStatus === \"U\" ||\n\t\tworktreeStatus === \"U\"\n\t);\n}\n\nexport function gitStatusEqual(\n\tleft: GitStatusSnapshot | undefined,\n\tright: GitStatusSnapshot | undefined,\n): boolean {\n\treturn JSON.stringify(left) === JSON.stringify(right);\n}\n\nexport function gitSnapshotEqual(\n\tleft: GitSnapshot | undefined,\n\tright: GitSnapshot | undefined,\n): boolean {\n\treturn JSON.stringify(left) === JSON.stringify(right);\n}\n", "import { spawn } from \"node:child_process\";\nimport type { WorkspaceExec } from \"./types.js\";\n\nconst FORCE_KILL_DELAY_MS = 250;\n\nexport const execWorkspaceCommand: WorkspaceExec = async (command, args, options) =>\n\tnew Promise((resolve) => {\n\t\tif (options.signal?.aborted) {\n\t\t\tresolve({ stdout: \"\", stderr: \"\", code: 1, killed: true });\n\t\t\treturn;\n\t\t}\n\n\t\tlet child: ReturnType<typeof spawn>;\n\t\ttry {\n\t\t\tchild = spawn(command, args, {\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: explicitEnvironment(options.environment),\n\t\t\t\tshell: false,\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t} catch {\n\t\t\tresolve({ stdout: \"\", stderr: \"\", code: 1, killed: false });\n\t\t\treturn;\n\t\t}\n\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet killed = false;\n\t\tlet settled = false;\n\t\tlet forceKillTimer: NodeJS.Timeout | undefined;\n\t\tlet timeoutTimer: NodeJS.Timeout | undefined;\n\n\t\tconst finish = (code: number) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tif (timeoutTimer) clearTimeout(timeoutTimer);\n\t\t\tif (forceKillTimer) clearTimeout(forceKillTimer);\n\t\t\toptions.signal?.removeEventListener(\"abort\", terminate);\n\t\t\tresolve({\n\t\t\t\tstdout: Buffer.concat(stdout).toString(\"utf8\"),\n\t\t\t\tstderr: Buffer.concat(stderr).toString(\"utf8\"),\n\t\t\t\tcode,\n\t\t\t\tkilled,\n\t\t\t});\n\t\t};\n\n\t\tconst signalProcessTree = (signal: NodeJS.Signals) => {\n\t\t\tconst pid = child.pid;\n\t\t\tif (pid === undefined) return;\n\t\t\tif (process.platform !== \"win32\") {\n\t\t\t\ttry {\n\t\t\t\t\tprocess.kill(-pid, signal);\n\t\t\t\t\treturn;\n\t\t\t\t} catch {\n\t\t\t\t\tchild.kill(signal);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst killer = spawn(\"taskkill.exe\", [\"/pid\", String(pid), \"/t\", \"/f\"], {\n\t\t\t\t\tstdio: \"ignore\",\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t});\n\t\t\t\tkiller.once(\"error\", () => child.kill(signal));\n\t\t\t\tkiller.unref();\n\t\t\t} catch {\n\t\t\t\tchild.kill(signal);\n\t\t\t}\n\t\t};\n\n\t\tfunction terminate() {\n\t\t\tif (killed || settled) return;\n\t\t\tkilled = true;\n\t\t\tsignalProcessTree(\"SIGTERM\");\n\t\t\tforceKillTimer = setTimeout(() => {\n\t\t\t\tsignalProcessTree(\"SIGKILL\");\n\t\t\t\tchild.stdout?.destroy();\n\t\t\t\tchild.stderr?.destroy();\n\t\t\t\tfinish(1);\n\t\t\t}, FORCE_KILL_DELAY_MS);\n\t\t}\n\n\t\tconst collect = (target: Buffer[]) => (data: Buffer | string) => {\n\t\t\tconst chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);\n\t\t\tconst remaining = Math.max(0, options.maxOutputBytes - outputBytes);\n\t\t\tif (remaining > 0) target.push(chunk.subarray(0, remaining));\n\t\t\toutputBytes += chunk.byteLength;\n\t\t\tif (outputBytes > options.maxOutputBytes) terminate();\n\t\t};\n\n\t\tchild.stdout?.on(\"data\", collect(stdout));\n\t\tchild.stderr?.on(\"data\", collect(stderr));\n\t\tchild.once(\"error\", () => {\n\t\t\tif (!killed) finish(1);\n\t\t});\n\t\tchild.once(\"close\", (code) => {\n\t\t\tif (!killed) finish(code ?? 1);\n\t\t});\n\t\toptions.signal?.addEventListener(\"abort\", terminate, { once: true });\n\t\tif (options.signal?.aborted) terminate();\n\t\ttimeoutTimer = setTimeout(terminate, options.timeout);\n\t});\n\nfunction explicitEnvironment(\n\tsource: Readonly<Record<string, string | undefined>>,\n): NodeJS.ProcessEnv {\n\tconst result: NodeJS.ProcessEnv = Object.create(null);\n\tfor (const [name, value] of Object.entries(source)) {\n\t\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(name) || value === undefined || value.includes(\"\\0\")) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty(result, name, {\n\t\t\tvalue,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n\treturn result;\n}\n", "import { getCapabilities } from \"@earendil-works/pi-tui\";\nimport type { GithubPrSnapshot, GithubPrState } from \"../modules/types.js\";\nimport type { WorkspaceExec } from \"./types.js\";\n\nconst GH_TIMEOUT_MS = 10_000;\nconst MAX_GH_OUTPUT_BYTES = 128 * 1024;\nconst MAX_URL_LENGTH = 4_096;\nconst MAX_CHECKS = 1_000;\nconst MAX_FIELD_LENGTH = 128;\nconst RFC3339_TIMESTAMP =\n\t/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(?:\\.\\d{1,9})?(?:Z|[+-](\\d{2}):(\\d{2}))$/u;\nexport const TERMINAL_PR_LIFETIME_MS = 24 * 60 * 60 * 1_000;\n\nconst GH_PR_FIELDS = [\n\t\"number\",\n\t\"isDraft\",\n\t\"url\",\n\t\"state\",\n\t\"closedAt\",\n\t\"mergedAt\",\n\t\"reviewDecision\",\n\t\"statusCheckRollup\",\n] as const;\n\ninterface GithubPrQueryOptions {\n\tplatform?: NodeJS.Platform;\n\tenvironment?: Readonly<Record<string, string | undefined>>;\n}\n\ninterface CheckSummary {\n\tfailed: number;\n\tpending: number;\n\ttotal: number;\n}\n\ntype PullRequestState = \"OPEN\" | \"CLOSED\" | \"MERGED\";\ntype ReviewDecision = \"APPROVED\" | \"CHANGES_REQUESTED\" | \"REVIEW_REQUIRED\" | \"\";\n\nexport function ghPrViewInvocation(platform: NodeJS.Platform = process.platform): {\n\tcommand: string;\n\targs: string[];\n} {\n\treturn {\n\t\tcommand: platform === \"win32\" ? \"gh.exe\" : \"gh\",\n\t\targs: [\"pr\", \"view\", \"--json\", GH_PR_FIELDS.join(\",\")],\n\t};\n}\n\nexport function githubPrEnvironment(\n\tsource: Readonly<Record<string, string | undefined>> = process.env,\n): Record<string, string | undefined> {\n\tconst environment: Record<string, string | undefined> = Object.create(null);\n\tfor (const [name, value] of Object.entries(source)) {\n\t\tconst normalized = name.toUpperCase();\n\t\tif (normalized === \"GH_HOST\" || normalized === \"GH_REPO\") continue;\n\t\tObject.defineProperty(environment, name, {\n\t\t\tvalue,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n\treturn environment;\n}\n\nexport async function queryGithubPr(\n\texec: WorkspaceExec,\n\tcwd: string,\n\tsignal?: AbortSignal,\n\tnow = Date.now(),\n\toptions: GithubPrQueryOptions = {},\n): Promise<GithubPrSnapshot | undefined> {\n\tconst invocation = ghPrViewInvocation(options.platform);\n\ttry {\n\t\tconst result = await exec(invocation.command, invocation.args, {\n\t\t\tcwd,\n\t\t\tsignal,\n\t\t\ttimeout: GH_TIMEOUT_MS,\n\t\t\tmaxOutputBytes: MAX_GH_OUTPUT_BYTES,\n\t\t\tenvironment: githubPrEnvironment(options.environment),\n\t\t});\n\t\tif (result.killed || result.code !== 0) return undefined;\n\t\tif (Buffer.byteLength(result.stdout) > MAX_GH_OUTPUT_BYTES) return undefined;\n\t\treturn buildGithubPrSnapshot(JSON.parse(result.stdout), now);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function buildGithubPrSnapshot(\n\tvalue: unknown,\n\tnow = Date.now(),\n): GithubPrSnapshot | undefined {\n\ttry {\n\t\tconst pr = record(value);\n\t\tconst number = positiveInteger(pr.number);\n\t\tconst isDraft = requiredBoolean(pr.isDraft);\n\t\tconst url = requiredBoundedString(pr.url, MAX_URL_LENGTH, true);\n\t\tconst state = pullRequestState(pr.state);\n\t\tconst closedAt = optionalTimestamp(pr.closedAt);\n\t\tconst mergedAt = optionalTimestamp(pr.mergedAt);\n\t\tconst reviewDecision = reviewDecisionValue(pr.reviewDecision);\n\t\tconst checks = summarizeChecks(pr.statusCheckRollup);\n\t\tconst expiresAt = terminalExpiry(state, closedAt, mergedAt);\n\t\tif (state !== \"OPEN\" && (expiresAt === undefined || now >= expiresAt)) return undefined;\n\n\t\tconst presentationState: GithubPrState =\n\t\t\tstate === \"MERGED\" ? \"merged\" : state === \"CLOSED\" ? \"closed\" : isDraft ? \"draft\" : \"open\";\n\t\tconst checksText = formatChecks(checks);\n\t\tconst review = formatReview(reviewDecision);\n\t\tconst status = compactStatus(presentationState, checks, checksText, review);\n\t\tconst snapshot: GithubPrSnapshot = {\n\t\t\tnumber: String(number),\n\t\t\tlink: osc8Link(url, `#${number}`),\n\t\t\tstate: presentationState,\n\t\t\tchecks: checksText,\n\t\t\treview,\n\t\t\tstatus,\n\t\t\t...(expiresAt === undefined ? {} : { expiresAt }),\n\t\t};\n\t\treturn Object.freeze(snapshot);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function githubPrSnapshotEqual(\n\tleft: GithubPrSnapshot | undefined,\n\tright: GithubPrSnapshot | undefined,\n): boolean {\n\treturn JSON.stringify(left) === JSON.stringify(right);\n}\n\nfunction terminalExpiry(\n\tstate: PullRequestState,\n\tclosedAt: number | undefined,\n\tmergedAt: number | undefined,\n): number | undefined {\n\tif (state === \"OPEN\") return undefined;\n\tconst terminalAt = state === \"MERGED\" ? mergedAt : closedAt;\n\treturn terminalAt === undefined ? undefined : terminalAt + TERMINAL_PR_LIFETIME_MS;\n}\n\nfunction summarizeChecks(value: unknown): CheckSummary {\n\tif (!Array.isArray(value) || value.length > MAX_CHECKS) throw new Error(\"Invalid PR checks\");\n\tconst summary: CheckSummary = { failed: 0, pending: 0, total: value.length };\n\tfor (const item of value) {\n\t\tconst check = record(item);\n\t\tconst state = optionalUppercase(check.state);\n\t\tconst status = optionalUppercase(check.status);\n\t\tconst conclusion = optionalUppercase(check.conclusion);\n\t\tif (state === \"SUCCESS\") continue;\n\t\tif (state === \"FAILURE\" || state === \"ERROR\") {\n\t\t\tsummary.failed += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (state === \"PENDING\" || state === \"EXPECTED\") {\n\t\t\tsummary.pending += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (status && status !== \"COMPLETED\") {\n\t\t\tsummary.pending += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (conclusion === \"SUCCESS\" || conclusion === \"SKIPPED\" || conclusion === \"NEUTRAL\") {\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\tconclusion === \"FAILURE\" ||\n\t\t\tconclusion === \"CANCELLED\" ||\n\t\t\tconclusion === \"TIMED_OUT\" ||\n\t\t\tconclusion === \"ACTION_REQUIRED\" ||\n\t\t\tconclusion === \"STARTUP_FAILURE\"\n\t\t) {\n\t\t\tsummary.failed += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tsummary.pending += 1;\n\t}\n\treturn summary;\n}\n\nfunction formatChecks(checks: CheckSummary): string {\n\tif (checks.total === 0) return \"-\";\n\tconst passed = checks.total - checks.failed - checks.pending;\n\treturn [\n\t\tcompactCount(\"\u2713\", passed),\n\t\tcompactCount(\"\u00D7\", checks.failed),\n\t\tcompactCount(\"\u2026\", checks.pending),\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\" \");\n}\n\nfunction compactCount(symbol: string, count: number): string {\n\treturn count > 0 ? `${symbol}${count}` : \"\";\n}\n\nfunction formatReview(review: ReviewDecision): string {\n\tif (review === \"APPROVED\") return \"R\u2713\";\n\tif (review === \"CHANGES_REQUESTED\") return \"R\u00D7\";\n\tif (review === \"REVIEW_REQUIRED\") return \"R?\";\n\treturn \"\";\n}\n\nfunction compactStatus(\n\tstate: GithubPrState,\n\tchecks: CheckSummary,\n\tchecksText: string,\n\treview: string,\n): string {\n\tif (state === \"merged\") return \"M\";\n\tif (state === \"closed\") return \"C\";\n\tif (state === \"draft\") return \"D\";\n\tif (checks.failed > 0) return compactCount(\"\u00D7\", checks.failed);\n\tif (review === \"R\u00D7\") return review;\n\tif (checks.pending > 0) return compactCount(\"\u2026\", checks.pending);\n\tif (review === \"R\u2713\" || review === \"R?\") return review;\n\treturn checksText;\n}\n\nfunction osc8Link(value: string, label: string): string {\n\tif (!getCapabilities().hyperlinks || hasTerminalControls(value)) return label;\n\ttry {\n\t\tconst url = new URL(value);\n\t\tif ((url.protocol !== \"http:\" && url.protocol !== \"https:\") || url.username || url.password) {\n\t\t\treturn label;\n\t\t}\n\t\tconst normalized = url.toString();\n\t\tif (normalized.length > MAX_URL_LENGTH || hasTerminalControls(normalized)) return label;\n\t\treturn `\\u001b]8;;${normalized}\\u0007${label}\\u001b]8;;\\u0007`;\n\t} catch {\n\t\treturn label;\n\t}\n}\n\nfunction hasTerminalControls(value: string): boolean {\n\treturn Array.from(value).some((character) => {\n\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\treturn (\n\t\t\tcodePoint <= 0x1f ||\n\t\t\t(codePoint >= 0x7f && codePoint <= 0x9f) ||\n\t\t\t(codePoint >= 0xd800 && codePoint <= 0xdfff)\n\t\t);\n\t});\n}\n\nfunction record(value: unknown): Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new Error(\"Expected PR object\");\n\t}\n\treturn value as Record<string, unknown>;\n}\n\nfunction positiveInteger(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value <= 0) {\n\t\tthrow new Error(\"Invalid PR number\");\n\t}\n\treturn value;\n}\n\nfunction requiredBoolean(value: unknown): boolean {\n\tif (typeof value !== \"boolean\") throw new Error(\"Invalid PR boolean\");\n\treturn value;\n}\n\nfunction requiredBoundedString(value: unknown, maxLength: number, allowEmpty = false): string {\n\tif (\n\t\ttypeof value !== \"string\" ||\n\t\tvalue.length > maxLength ||\n\t\t(!allowEmpty && value.length === 0)\n\t) {\n\t\tthrow new Error(\"Invalid PR string\");\n\t}\n\treturn value;\n}\n\nfunction optionalUppercase(value: unknown): string | undefined {\n\tif (value === null || value === undefined || value === \"\") return undefined;\n\treturn requiredBoundedString(value, MAX_FIELD_LENGTH).toUpperCase();\n}\n\nfunction optionalTimestamp(value: unknown): number | undefined {\n\tif (value === null || value === undefined || value === \"\") return undefined;\n\tconst text = requiredBoundedString(value, MAX_FIELD_LENGTH);\n\tconst match = RFC3339_TIMESTAMP.exec(text);\n\tif (!match) throw new Error(\"Invalid PR timestamp\");\n\tconst [\n\t\t,\n\t\tyearText,\n\t\tmonthText,\n\t\tdayText,\n\t\thourText,\n\t\tminuteText,\n\t\tsecondText,\n\t\toffsetHourText,\n\t\toffsetMinuteText,\n\t] = match;\n\tconst year = Number(yearText);\n\tconst month = Number(monthText);\n\tconst day = Number(dayText);\n\tconst hour = Number(hourText);\n\tconst minute = Number(minuteText);\n\tconst second = Number(secondText);\n\tconst offsetHour = Number(offsetHourText ?? 0);\n\tconst offsetMinute = Number(offsetMinuteText ?? 0);\n\tif (\n\t\tmonth < 1 ||\n\t\tmonth > 12 ||\n\t\tday < 1 ||\n\t\tday > daysInMonth(year, month) ||\n\t\thour > 23 ||\n\t\tminute > 59 ||\n\t\tsecond > 59 ||\n\t\toffsetHour > 23 ||\n\t\toffsetMinute > 59\n\t) {\n\t\tthrow new Error(\"Invalid PR timestamp\");\n\t}\n\tconst timestamp = Date.parse(text);\n\tif (!Number.isFinite(timestamp)) throw new Error(\"Invalid PR timestamp\");\n\treturn timestamp;\n}\n\nfunction daysInMonth(year: number, month: number): number {\n\tif (month === 2) {\n\t\tconst leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n\t\treturn leapYear ? 29 : 28;\n\t}\n\treturn month === 4 || month === 6 || month === 9 || month === 11 ? 30 : 31;\n}\n\nfunction pullRequestState(value: unknown): PullRequestState {\n\tif (value === \"OPEN\" || value === \"CLOSED\" || value === \"MERGED\") return value;\n\tthrow new Error(\"Invalid PR state\");\n}\n\nfunction reviewDecisionValue(value: unknown): ReviewDecision {\n\tif (value === null || value === undefined || value === \"\" || value === \"UNKNOWN\") return \"\";\n\tif (value === \"APPROVED\" || value === \"CHANGES_REQUESTED\" || value === \"REVIEW_REQUIRED\") {\n\t\treturn value;\n\t}\n\tthrow new Error(\"Invalid PR review decision\");\n}\n", "export interface AsyncRefreshControllerOptions<Input, Snapshot> {\n\tread(input: Input, signal: AbortSignal): Promise<Snapshot>;\n\tequal(left: Snapshot | undefined, right: Snapshot): boolean;\n\tpublish(snapshot: Snapshot): void;\n\tonError?(error: unknown): void;\n}\n\ninterface RefreshRequest<Input> {\n\tgeneration: number;\n\trequestId: number;\n\tinput: Input;\n}\n\ninterface ActiveRefresh<Input> {\n\trequest: RefreshRequest<Input>;\n\tcontroller: AbortController;\n}\n\n/** Coalesces refreshes to one active read plus the latest pending request. */\nexport class AsyncRefreshController<Input, Snapshot> {\n\tprivate generation: number | undefined;\n\tprivate requestId = 0;\n\tprivate active: ActiveRefresh<Input> | undefined;\n\tprivate pending: RefreshRequest<Input> | undefined;\n\tprivate current: Snapshot | undefined;\n\n\tconstructor(private readonly options: AsyncRefreshControllerOptions<Input, Snapshot>) {}\n\n\tstart(generation: number): void {\n\t\tthis.cancelActive(\"Refresh generation replaced\");\n\t\tthis.generation = generation;\n\t\tthis.requestId += 1;\n\t\tthis.pending = undefined;\n\t\tthis.current = undefined;\n\t}\n\n\tclear(): void {\n\t\tthis.current = undefined;\n\t}\n\n\trequest(input: Input): void {\n\t\tif (this.generation === undefined) return;\n\t\tconst request = {\n\t\t\tgeneration: this.generation,\n\t\t\trequestId: ++this.requestId,\n\t\t\tinput,\n\t\t};\n\t\tif (this.active) {\n\t\t\tthis.pending = request;\n\t\t\treturn;\n\t\t}\n\t\tthis.run(request);\n\t}\n\n\tstop(): void {\n\t\tthis.generation = undefined;\n\t\tthis.requestId += 1;\n\t\tthis.pending = undefined;\n\t\tthis.current = undefined;\n\t\tthis.cancelActive(\"Refresh controller stopped\");\n\t}\n\n\tprivate run(request: RefreshRequest<Input>): void {\n\t\tif (!this.isCurrentTarget(request)) return;\n\t\tconst active: ActiveRefresh<Input> = {\n\t\t\trequest,\n\t\t\tcontroller: new AbortController(),\n\t\t};\n\t\tthis.active = active;\n\t\tvoid this.options\n\t\t\t.read(request.input, active.controller.signal)\n\t\t\t.then((snapshot) => {\n\t\t\t\tif (this.active !== active || !this.isCurrentRequest(request)) return;\n\t\t\t\tif (this.options.equal(this.current, snapshot)) return;\n\t\t\t\tthis.current = snapshot;\n\t\t\t\tthis.options.publish(snapshot);\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tif (\n\t\t\t\t\tthis.active === active &&\n\t\t\t\t\tthis.isCurrentRequest(request) &&\n\t\t\t\t\t!active.controller.signal.aborted\n\t\t\t\t) {\n\t\t\t\t\tthis.options.onError?.(error);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tif (this.active !== active) return;\n\t\t\t\tthis.active = undefined;\n\t\t\t\tconst pending = this.pending;\n\t\t\t\tthis.pending = undefined;\n\t\t\t\tif (pending) this.run(pending);\n\t\t\t});\n\t}\n\n\tprivate cancelActive(reason: string): void {\n\t\tthis.active?.controller.abort(new DOMException(reason, \"AbortError\"));\n\t}\n\n\tprivate isCurrentTarget(request: RefreshRequest<Input>): boolean {\n\t\treturn this.generation !== undefined && request.generation === this.generation;\n\t}\n\n\tprivate isCurrentRequest(request: RefreshRequest<Input>): boolean {\n\t\treturn this.isCurrentTarget(request) && request.requestId === this.requestId;\n\t}\n}\n", "import type { ModuleName } from \"../modules/catalog.js\";\nimport { reachableModuleRequirements } from \"../modules/render.js\";\nimport type { WorkspaceSnapshot } from \"../modules/types.js\";\nimport { createFileSystem } from \"./helpers.js\";\nimport {\n\ttype CollectorContext,\n\ttype MutableModuleSnapshot,\n\tPRIVATE_STYLE_SELECTOR,\n\ttype WorkspaceEntry,\n\ttype WorkspaceRefreshInput,\n} from \"./types.js\";\n\nexport type { WorkspaceExec, WorkspaceExecResult, WorkspaceRefreshInput } from \"./types.js\";\n\nexport async function collectWorkspaceSnapshot(\n\tinput: WorkspaceRefreshInput,\n): Promise<WorkspaceSnapshot> {\n\tconst requirements = reachableModuleRequirements(input.config);\n\tif (input.signal?.aborted || !hasWorkspaceRequirement(requirements)) return freezeSnapshot({});\n\tconst fs = createFileSystem(input);\n\tlet listing: Promise<readonly WorkspaceEntry[]> | undefined;\n\tconst context: CollectorContext = {\n\t\tinput,\n\t\tfs,\n\t\trequirements,\n\t\tentries() {\n\t\t\tlisting ??= fs.readDirectory(input.cwd);\n\t\t\treturn listing;\n\t\t},\n\t\toptions(name) {\n\t\t\treturn input.config.modules[name].options;\n\t\t},\n\t\tneeds(name, variable) {\n\t\t\tconst variables = requirements.get(name);\n\t\t\treturn Boolean(variables && (variable === undefined || variables.has(variable)));\n\t\t},\n\t};\n\tconst modules: MutableModuleSnapshot = {};\n\tif (requirements.has(\"package\")) {\n\t\tconst { collectPackage } = await import(\"./package.js\");\n\t\tif (input.signal?.aborted) return freezeSnapshot({});\n\t\tconst packageValues = await collectPackage(context);\n\t\tif (input.signal?.aborted) return freezeSnapshot({});\n\t\tif (packageValues) modules.package = packageValues;\n\t}\n\tfor (const descriptor of COLLECTOR_GROUPS) {\n\t\tif (!descriptor.modules.some((name) => requirements.has(name))) continue;\n\t\tif (input.signal?.aborted) return freezeSnapshot({});\n\t\tconst collector = await descriptor.load();\n\t\tif (input.signal?.aborted) return freezeSnapshot({});\n\t\tmergeModules(modules, await collector(context));\n\t}\n\treturn input.signal?.aborted ? freezeSnapshot({}) : freezeSnapshot(modules);\n}\n\nexport function workspaceSnapshotEqual(\n\tleft: WorkspaceSnapshot | undefined,\n\tright: WorkspaceSnapshot | undefined,\n): boolean {\n\treturn JSON.stringify(left) === JSON.stringify(right);\n}\n\nfunction hasWorkspaceRequirement(\n\trequirements: ReadonlyMap<ModuleName, ReadonlySet<string>>,\n): boolean {\n\treturn [...requirements.keys()].some((name) => !BUILT_IN_ONLY_MODULES.has(name));\n}\n\ntype WorkspaceCollector = (context: CollectorContext) => Promise<MutableModuleSnapshot>;\n\nconst COLLECTOR_GROUPS: readonly {\n\tmodules: readonly ModuleName[];\n\tload(): Promise<WorkspaceCollector>;\n}[] = [\n\t{\n\t\tmodules: [\"nodejs\", \"python\", \"rust\", \"golang\", \"bun\", \"deno\"],\n\t\tload: async () => (await import(\"./languages.js\")).collectLanguages,\n\t},\n\t{\n\t\tmodules: [\"mise\", \"direnv\", \"pixi\", \"conda\", \"nix_shell\", \"guix_shell\"],\n\t\tload: async () => (await import(\"./development.js\")).collectDevelopment,\n\t},\n\t{\n\t\tmodules: [\"docker_context\", \"kubernetes\", \"terraform\"],\n\t\tload: async () => (await import(\"./deployment.js\")).collectDeployment,\n\t},\n\t{\n\t\tmodules: [\"aws\", \"gcloud\", \"azure\", \"openstack\"],\n\t\tload: async () => (await import(\"./cloud.js\")).collectCloud,\n\t},\n\t{\n\t\tmodules: [\"container\", \"hostname\", \"os\", \"username\"],\n\t\tload: async () => (await import(\"./execution.js\")).collectExecution,\n\t},\n];\n\nconst BUILT_IN_ONLY_MODULES = new Set<ModuleName>([\n\t\"brand\",\n\t\"provider\",\n\t\"model\",\n\t\"thinking\",\n\t\"directory\",\n\t\"git_worktree\",\n\t\"git_branch\",\n\t\"github_pr\",\n\t\"git_commit\",\n\t\"git_state\",\n\t\"git_metrics\",\n\t\"git_status\",\n\t\"activity\",\n\t\"context\",\n\t\"tokens\",\n\t\"cost\",\n\t\"time\",\n\t\"turn\",\n\t\"fill\",\n\t\"extension_status\",\n]);\n\nfunction mergeModules(target: MutableModuleSnapshot, source: MutableModuleSnapshot): void {\n\tfor (const [name, values] of Object.entries(source)) {\n\t\tObject.defineProperty(target, name, {\n\t\t\tvalue: values,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n}\n\nfunction freezeSnapshot(modules: MutableModuleSnapshot): WorkspaceSnapshot {\n\tconst styleSelectors: Record<string, string> = {};\n\tfor (const [name, values] of Object.entries(modules)) {\n\t\tconst selector = Object.hasOwn(values, PRIVATE_STYLE_SELECTOR)\n\t\t\t? values[PRIVATE_STYLE_SELECTOR]\n\t\t\t: undefined;\n\t\tdelete values[PRIVATE_STYLE_SELECTOR];\n\t\tif (selector !== undefined) styleSelectors[name] = selector;\n\t\tObject.freeze(values);\n\t}\n\treturn Object.freeze({\n\t\tmodules: Object.freeze(modules),\n\t\t...(Object.keys(styleSelectors).length > 0\n\t\t\t? { styleSelectors: Object.freeze(styleSelectors) }\n\t\t\t: {}),\n\t});\n}\n", "import type { SessionEntry } from \"@earendil-works/pi-coding-agent\";\n\ninterface UsageLike {\n\tinput?: number;\n\toutput?: number;\n\tcacheRead?: number;\n\tcacheWrite?: number;\n\tcost?: { total?: number };\n}\n\nexport interface FooterUsageSummary {\n\tinput: number;\n\toutput: number;\n\tcacheRead: number;\n\tcacheWrite: number;\n\tcost: number;\n\tlatestCacheHitRate?: number;\n}\n\nexport function summarizeFooterUsage(entries: readonly SessionEntry[]): FooterUsageSummary {\n\tconst totals: FooterUsageSummary = {\n\t\tinput: 0,\n\t\toutput: 0,\n\t\tcacheRead: 0,\n\t\tcacheWrite: 0,\n\t\tcost: 0,\n\t};\n\n\tfor (const entry of entries) {\n\t\tlet usage: UsageLike | undefined;\n\t\tif (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\tusage = entry.message.usage;\n\t\t\tconst input = usage.input ?? 0;\n\t\t\tconst cacheRead = usage.cacheRead ?? 0;\n\t\t\tconst cacheWrite = usage.cacheWrite ?? 0;\n\t\t\tconst promptTokens = input + cacheRead + cacheWrite;\n\t\t\ttotals.latestCacheHitRate = promptTokens > 0 ? (cacheRead / promptTokens) * 100 : undefined;\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"toolResult\") {\n\t\t\tusage = entry.message.usage;\n\t\t} else if (entry.type === \"compaction\" || entry.type === \"branch_summary\") {\n\t\t\tusage = entry.usage;\n\t\t}\n\t\tif (!usage) continue;\n\n\t\ttotals.input += usage.input ?? 0;\n\t\ttotals.output += usage.output ?? 0;\n\t\ttotals.cacheRead += usage.cacheRead ?? 0;\n\t\ttotals.cacheWrite += usage.cacheWrite ?? 0;\n\t\ttotals.cost += usage.cost?.total ?? 0;\n\t}\n\n\treturn totals;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,UAAU,gBAAgB;AAC5C;AAAA,EAGC;AAAA,OAEM;AACP,SAAS,mBAAAA,kBAAiB,wBAAwB;;;ACPlD,SAAS,YAAY,oBAAoB;AACzC,SAAS,UAAU,YAAY,MAAM,eAAe;AAYpD,IAAM,iBAAiB;AAQvB,eAAsB,gBACrB,IACA,KACA,SACmC;AACnC,QAAM,gBAAgB,GAAG;AAAA,IACxB;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,M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.55.
|
|
3
|
+
"version": "0.55.1",
|
|
4
4
|
"description": "Native Starship-style TOML statusline and configuration skill for Pi.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@biomejs/biome": "2.5.11",
|
|
52
52
|
"@earendil-works/pi-coding-agent": "0.85.0",
|
|
53
53
|
"@earendil-works/pi-tui": "0.85.0",
|
|
54
|
-
"@types/node": "26.4.
|
|
54
|
+
"@types/node": "26.4.1",
|
|
55
55
|
"esbuild": "0.28.2",
|
|
56
56
|
"typescript": "7.0.2"
|
|
57
57
|
},
|
|
@@ -194,7 +194,11 @@ Root format reachability, `$all`, module `disabled`, and module-format variables
|
|
|
194
194
|
Workspace/Git refreshes run at session start, after accepted settings, branch changes, tool/turn completion, and a 30-second fallback.
|
|
195
195
|
GitHub PR uses the narrower lifecycle and 60-second network refresh described above.
|
|
196
196
|
One read runs with at most one latest pending refresh.
|
|
197
|
-
Immutable snapshot equality suppresses redraws, and session or request generations reject stale results.
|
|
197
|
+
Immutable snapshot equality suppresses collector-driven redraws, and session or request generations reject stale results.
|
|
198
|
+
The 30-second fallback does not request a redraw for unchanged snapshots.
|
|
199
|
+
When the effective format displays the clock, the fallback also checks for changed clock output using the last rendered snapshot, without re-reading session history.
|
|
200
|
+
Clock text changes still request a redraw; unrelated Pi events can also redraw the footer.
|
|
201
|
+
Background collection continues even when a terminal pane is not visible.
|
|
198
202
|
Shutdown, replacement, footer disposal, branch changes, and accepted settings abort active command work before starting replacements; disabling `github_pr` also stops its query and timers.
|
|
199
203
|
Bounded local filesystem operations may finish, but stale generations cannot publish them.
|
|
200
204
|
Execution identity is retained rather than re-read by the periodic fallback.
|
package/src/pi-starship.ts
CHANGED
|
@@ -302,11 +302,41 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
302
302
|
requestGithubPr(target);
|
|
303
303
|
tui.requestRender();
|
|
304
304
|
});
|
|
305
|
+
let lastRender:
|
|
306
|
+
| {
|
|
307
|
+
snapshot: StarshipRuntimeSnapshot;
|
|
308
|
+
lines: string[];
|
|
309
|
+
config: StarshipConfig;
|
|
310
|
+
width: number;
|
|
311
|
+
}
|
|
312
|
+
| undefined;
|
|
305
313
|
const timer = setInterval(() => {
|
|
306
314
|
if (!isActiveTarget(target)) return;
|
|
307
315
|
clearDebounce();
|
|
308
316
|
requestRefresh(target, "periodic");
|
|
309
|
-
|
|
317
|
+
// Collectors publish only changed snapshots. The clock is the sole value
|
|
318
|
+
// that changes without publication; reuse the last render's session data.
|
|
319
|
+
if (!lastRender || !reachableModuleRequirements(lastRender.config).get("time")?.has("time"))
|
|
320
|
+
return;
|
|
321
|
+
const now = new Date();
|
|
322
|
+
const previous = lastRender.snapshot.now;
|
|
323
|
+
if (now.getHours() === previous.getHours() && now.getMinutes() === previous.getMinutes())
|
|
324
|
+
return;
|
|
325
|
+
const lines = wrapFormattedStatusline(
|
|
326
|
+
renderStatusline(
|
|
327
|
+
lastRender.config,
|
|
328
|
+
{ ...lastRender.snapshot, now },
|
|
329
|
+
lastRender.width,
|
|
330
|
+
getCapabilities().trueColor,
|
|
331
|
+
).ansi,
|
|
332
|
+
lastRender.width,
|
|
333
|
+
);
|
|
334
|
+
const previousLines = lastRender.lines;
|
|
335
|
+
if (
|
|
336
|
+
lines.length !== previousLines.length ||
|
|
337
|
+
lines.some((line, index) => line !== previousLines[index])
|
|
338
|
+
)
|
|
339
|
+
tui.requestRender();
|
|
310
340
|
}, REFRESH_INTERVAL_MS);
|
|
311
341
|
let disposed = false;
|
|
312
342
|
|
|
@@ -336,10 +366,12 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
336
366
|
const current = previewLoaded ?? loaded;
|
|
337
367
|
if (!current) return [];
|
|
338
368
|
const snapshot = runtimeSnapshot(ctx, footerData, runtime);
|
|
339
|
-
|
|
369
|
+
const lines = wrapFormattedStatusline(
|
|
340
370
|
renderStatusline(current.config, snapshot, width, getCapabilities().trueColor).ansi,
|
|
341
371
|
width,
|
|
342
372
|
);
|
|
373
|
+
lastRender = { snapshot, lines, config: current.config, width };
|
|
374
|
+
return lines;
|
|
343
375
|
},
|
|
344
376
|
};
|
|
345
377
|
});
|