@narumitw/pi-starship 0.65.1 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +328 -0
- package/README.md +8 -0
- package/dist/chunks/{chunk-S2KBLHE2.ts → chunk-3XLWHJ5Y.ts} +5 -5
- package/dist/chunks/chunk-3XLWHJ5Y.ts.map +7 -0
- package/dist/chunks/{chunk-D2YWQMYT.ts → chunk-BOMYDCT7.ts} +3 -3
- package/dist/chunks/{chunk-I22B7QPQ.ts → chunk-CUXPMKBQ.ts} +19 -3
- package/dist/chunks/chunk-CUXPMKBQ.ts.map +7 -0
- package/dist/chunks/{chunk-XTLQ4WUL.ts → chunk-QGB3NNTM.ts} +1 -1
- package/dist/chunks/chunk-QGB3NNTM.ts.map +7 -0
- package/dist/chunks/{chunk-YK4S4RRM.ts → chunk-UZJIMIWL.ts} +3 -2
- package/dist/chunks/chunk-UZJIMIWL.ts.map +7 -0
- package/dist/chunks/{cloud-J2ZOE3HE.ts → cloud-CNNWXSQ3.ts} +2 -2
- package/dist/chunks/{command-configuration-menu-BJYQXV2U.ts → command-configuration-menu-N3SP6R3I.ts} +6 -3
- package/dist/chunks/command-configuration-menu-N3SP6R3I.ts.map +7 -0
- package/dist/chunks/{command-settings-chat-42OTC7NJ.ts → command-settings-chat-4NLO3RDC.ts} +4 -4
- package/dist/chunks/{commands-ZL36J5TX.ts → commands-MSJ67CTR.ts} +6 -6
- package/dist/chunks/{deployment-NOJ2KCLI.ts → deployment-KNUSQSJ5.ts} +3 -3
- package/dist/chunks/{development-T3XXVVDP.ts → development-TJNVM4H2.ts} +2 -2
- package/dist/chunks/{execution-R2OHIP2L.ts → execution-OFQXHFAH.ts} +3 -3
- package/dist/chunks/{jujutsu-XLDYKSX2.ts → jujutsu-T2LTPHSY.ts} +2 -2
- package/dist/chunks/{languages-CBQNNYXM.ts → languages-VWXTVJ45.ts} +3 -3
- package/dist/chunks/{package-7KVAK3TC.ts → package-JA4CJ5DR.ts} +2 -2
- package/dist/chunks/{system-574MHB4R.ts → system-CDTPAQZX.ts} +2 -2
- package/dist/index.ts +74 -40
- package/dist/index.ts.map +2 -2
- package/package.json +6 -5
- package/skills/configure-pi-starship/references/module-catalog.md +19 -3
- package/skills/configure-pi-starship/references/modules.md +37 -2
- package/src/command-configuration-menu.ts +3 -0
- package/src/command-preview.ts +1 -0
- package/src/modules/catalog.ts +5 -1
- package/src/modules/cost.ts +2 -1
- package/src/modules/git/runtime.ts +33 -25
- package/src/modules/tokens-per-second.ts +14 -0
- package/src/modules/types.ts +2 -0
- package/src/pi-starship.ts +4 -7
- package/src/runtime/command.ts +8 -3
- package/src/runtime/github-pr.ts +5 -2
- package/src/runtime/helpers.ts +5 -4
- package/src/runtime/types.ts +1 -0
- package/src/usage.ts +42 -4
- package/dist/chunks/chunk-I22B7QPQ.ts.map +0 -7
- package/dist/chunks/chunk-S2KBLHE2.ts.map +0 -7
- package/dist/chunks/chunk-XTLQ4WUL.ts.map +0 -7
- package/dist/chunks/chunk-YK4S4RRM.ts.map +0 -7
- package/dist/chunks/command-configuration-menu-BJYQXV2U.ts.map +0 -7
- /package/dist/chunks/{chunk-D2YWQMYT.ts.map → chunk-BOMYDCT7.ts.map} +0 -0
- /package/dist/chunks/{cloud-J2ZOE3HE.ts.map → cloud-CNNWXSQ3.ts.map} +0 -0
- /package/dist/chunks/{command-settings-chat-42OTC7NJ.ts.map → command-settings-chat-4NLO3RDC.ts.map} +0 -0
- /package/dist/chunks/{commands-ZL36J5TX.ts.map → commands-MSJ67CTR.ts.map} +0 -0
- /package/dist/chunks/{deployment-NOJ2KCLI.ts.map → deployment-KNUSQSJ5.ts.map} +0 -0
- /package/dist/chunks/{development-T3XXVVDP.ts.map → development-TJNVM4H2.ts.map} +0 -0
- /package/dist/chunks/{execution-R2OHIP2L.ts.map → execution-OFQXHFAH.ts.map} +0 -0
- /package/dist/chunks/{jujutsu-XLDYKSX2.ts.map → jujutsu-T2LTPHSY.ts.map} +0 -0
- /package/dist/chunks/{languages-CBQNNYXM.ts.map → languages-VWXTVJ45.ts.map} +0 -0
- /package/dist/chunks/{package-7KVAK3TC.ts.map → package-JA4CJ5DR.ts.map} +0 -0
- /package/dist/chunks/{system-574MHB4R.ts.map → system-CDTPAQZX.ts.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-starship",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.66.0",
|
|
4
4
|
"description": "Native Starship-style TOML statusline and configuration skill for Pi.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"dist",
|
|
21
21
|
"skills",
|
|
22
22
|
"README.md",
|
|
23
|
+
"CHANGELOG.md",
|
|
23
24
|
"LICENSE",
|
|
24
25
|
"NOTICES.md"
|
|
25
26
|
],
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"typecheck": "tsc --noEmit"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@narumitw/pi-tui-kit": "^0.
|
|
43
|
+
"@narumitw/pi-tui-kit": "^0.69.0",
|
|
43
44
|
"re2js": "^2.9.0",
|
|
44
45
|
"semver": "^7.8.5",
|
|
45
46
|
"smol-toml": "^1.9.1",
|
|
@@ -51,9 +52,9 @@
|
|
|
51
52
|
"@earendil-works/pi-tui": "*"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@earendil-works/pi-agent-core": "1.
|
|
55
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
56
|
-
"@earendil-works/pi-tui": "1.
|
|
55
|
+
"@earendil-works/pi-agent-core": "1.5.0",
|
|
56
|
+
"@earendil-works/pi-coding-agent": "1.5.0",
|
|
57
|
+
"@earendil-works/pi-tui": "1.5.0",
|
|
57
58
|
"@types/node": "26.6.5",
|
|
58
59
|
"esbuild": "0.28.2",
|
|
59
60
|
"typescript": "7.0.2"
|
|
@@ -27,7 +27,7 @@ All enum values are case-sensitive.
|
|
|
27
27
|
|
|
28
28
|
## Catalog order
|
|
29
29
|
|
|
30
|
-
`brand` → `provider` → `model` → `thinking` → `directory` → `git_worktree` → `git_branch` → `github_pr` → `git_commit` → `git_state` → `git_metrics` → `git_status` → `jj_bookmark` → `jj_change` → `jj_metrics` → `jj_status` → `package` → `nodejs` → `python` → `rust` → `golang` → `bun` → `deno` → `mise` → `direnv` → `conda` → `pixi` → `nix_shell` → `guix_shell` → `docker_context` → `kubernetes` → `terraform` → `aws` → `gcloud` → `azure` → `openstack` → `os` → `container` → `hostname` → `username` → `memory_usage` → `battery` → `activity` → `context` → `tokens` → `cache` → `cost` → `time` → `turn` → `fill` → `extension_status`
|
|
30
|
+
`brand` → `provider` → `model` → `thinking` → `directory` → `git_worktree` → `git_branch` → `github_pr` → `git_commit` → `git_state` → `git_metrics` → `git_status` → `jj_bookmark` → `jj_change` → `jj_metrics` → `jj_status` → `package` → `nodejs` → `python` → `rust` → `golang` → `bun` → `deno` → `mise` → `direnv` → `conda` → `pixi` → `nix_shell` → `guix_shell` → `docker_context` → `kubernetes` → `terraform` → `aws` → `gcloud` → `azure` → `openstack` → `os` → `container` → `hostname` → `username` → `memory_usage` → `battery` → `activity` → `context` → `tokens` → `tokens_per_second` → `cache` → `cost` → `time` → `turn` → `fill` → `extension_status`
|
|
31
31
|
|
|
32
32
|
## Module schemas
|
|
33
33
|
|
|
@@ -1139,6 +1139,22 @@ Accepted style fields:
|
|
|
1139
1139
|
| --- | --- |
|
|
1140
1140
|
| `style` | `"bold cyan"` |
|
|
1141
1141
|
|
|
1142
|
+
### `tokens_per_second`
|
|
1143
|
+
|
|
1144
|
+
Average output tokens per second for the latest completed assistant response on the active branch.
|
|
1145
|
+
|
|
1146
|
+
- Format variables: `$symbol`, `$rate`.
|
|
1147
|
+
- Style variables in `format`: `$style`.
|
|
1148
|
+
- Default `format`: `"[$rate tok/s ]($style)"`.
|
|
1149
|
+
- Default `symbol`: `""`.
|
|
1150
|
+
- Default `disabled`: `true`.
|
|
1151
|
+
|
|
1152
|
+
Accepted style fields:
|
|
1153
|
+
|
|
1154
|
+
| Field | Default |
|
|
1155
|
+
| --- | --- |
|
|
1156
|
+
| `style` | `"bold cyan"` |
|
|
1157
|
+
|
|
1142
1158
|
### `cache`
|
|
1143
1159
|
|
|
1144
1160
|
Prompt-cache usage and latest cache hit rate.
|
|
@@ -1157,9 +1173,9 @@ Accepted style fields:
|
|
|
1157
1173
|
|
|
1158
1174
|
### `cost`
|
|
1159
1175
|
|
|
1160
|
-
|
|
1176
|
+
Session cost, provider-total provenance, and subscription state.
|
|
1161
1177
|
|
|
1162
|
-
- Format variables: `$symbol`, `$cost`, `$subscription`.
|
|
1178
|
+
- Format variables: `$symbol`, `$cost`, `$subscription`, `$source`.
|
|
1163
1179
|
- Style variables in `format`: `$style`.
|
|
1164
1180
|
- Default `format`: `"[ $symbol \\$$cost( $subscription) ]($style)"`.
|
|
1165
1181
|
- Default `symbol`: `"💸"`.
|
|
@@ -27,8 +27,9 @@ Use this authoritative public reference whenever a question or change involves a
|
|
|
27
27
|
| `activity` | `$symbol`, `$state`, `$tool`, `$count`, `$kind`, `$title`, `$text` | Extension UI waits, active tools, streaming, completion, or idle |
|
|
28
28
|
| `context` | `$symbol`, `$percentage`, `$tokens`, `$window` | Context-window use |
|
|
29
29
|
| `tokens` | `$symbol`, `$input`, `$output`, `$total` | Token totals |
|
|
30
|
+
| `tokens_per_second` | `$symbol`, `$rate` | Latest completed assistant response's average output rate on the active branch; disabled by default |
|
|
30
31
|
| `cache` | `$symbol`, `$rate`, `$read`, `$write` | Prompt-cache reads, writes, and latest hit rate; disabled by default |
|
|
31
|
-
| `cost` | `$symbol`, `$cost`, `$subscription` | Session cost and optional `(sub)` marker |
|
|
32
|
+
| `cost` | `$symbol`, `$cost`, `$subscription`, `$source` | Session cost, provider-total provenance, and optional `(sub)` marker |
|
|
32
33
|
| `time` | `$symbol`, `$time` | Formatted clock; local `HH:mm` by default |
|
|
33
34
|
| `turn` | `$symbol`, `$count` | User turn count |
|
|
34
35
|
| `package` | `$symbol`, `$version`, `$source` | Direct project manifest version |
|
|
@@ -208,7 +209,7 @@ These are inert labels, not evidence of cluster access or valid credentials.
|
|
|
208
209
|
- Prompt waiting takes precedence without losing the underlying tool, streaming, completed, or idle state, which returns when the prompt closes.
|
|
209
210
|
- Active and completed tool names in `$tool` and `$text` are single-line display text: line separators become spaces, and terminal and direction controls are removed. Raw tool identities remain unchanged.
|
|
210
211
|
- `tokens`, `cache`, and `cost` total every usage-bearing session entry, matching Pi's native footer.
|
|
211
|
-
This includes assistant messages, nested-LLM tool results, compactions,
|
|
212
|
+
This includes assistant messages, nested-LLM tool results, compactions, branch summaries, and standalone usage such as persisted cache warming, including abandoned branches retained in the session.
|
|
212
213
|
- Cache `$read` and `$write` are cumulative.
|
|
213
214
|
`$rate` uses only the latest assistant prompt with `cacheRead / (input + cacheRead + cacheWrite) * 100`.
|
|
214
215
|
The module is empty when Pi has reported no cache reads or writes.
|
|
@@ -218,9 +219,43 @@ These are inert labels, not evidence of cluster access or valid credentials.
|
|
|
218
219
|
Its default display hides values below 30%.
|
|
219
220
|
Customize `[[context.display]]` when lower values should remain visible.
|
|
220
221
|
The module name remains `context`, not `context_usage`.
|
|
222
|
+
- Cost `$source` is `provider` only for a nonempty, finite total when every included usage record has a finite nonnegative `cost.total` and `cost.totalFromProvider === true`.
|
|
223
|
+
It is `unconfirmed` for catalog estimates, mixed provenance, older sessions, empty sessions, or missing totals.
|
|
224
|
+
Records without usage do not contribute.
|
|
225
|
+
- `$cost` sums Pi's best available `cost.total` values, not estimated component costs.
|
|
226
|
+
Components remain catalog estimates and can differ from a provider total; these values do not establish exact prompt-cache savings.
|
|
227
|
+
Session-response costs are separate from account/key quotas and balances.
|
|
228
|
+
- The default cost format and thresholds are unchanged.
|
|
229
|
+
To show provenance, set `[cost].format` to `'$cost $source( $subscription)'`.
|
|
221
230
|
- Subscription-backed OAuth models and `kimi-coding` set cost `$subscription` to `(sub)`.
|
|
222
231
|
The dollar value is usage cost, not proof of an amount billed under a subscription.
|
|
223
232
|
|
|
233
|
+
### Tokens per second
|
|
234
|
+
|
|
235
|
+
`tokens_per_second` shows the latest completed assistant response on the active branch, not cumulative session throughput.
|
|
236
|
+
Enable it explicitly and include it in the root format, or use `$all` after enabling it:
|
|
237
|
+
|
|
238
|
+
```toml
|
|
239
|
+
format = "$model$tokens$tokens_per_second"
|
|
240
|
+
|
|
241
|
+
[tokens_per_second]
|
|
242
|
+
disabled = false
|
|
243
|
+
format = "[$rate tok/s ]($style)"
|
|
244
|
+
style = "bold cyan"
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
`$rate` is `usage.output / (durationMs / 1000)`, formatted to one decimal place; 85 output tokens over 2 seconds displays `42.5 tok/s`.
|
|
248
|
+
The duration is Pi's recorded full-response duration, including request latency and thinking time, but not subsequent tool execution or time between responses.
|
|
249
|
+
Output tokens use the provider's accounting, which can include reasoning tokens; this is not a visible-text estimate or a decode-only speed measurement.
|
|
250
|
+
Responses ending with `stop`, `length`, or `toolUse` can supply a rate, including tool-calling responses before their tools finish.
|
|
251
|
+
|
|
252
|
+
The latest completed response remains visible while a new response is streaming; partial usage is not estimated.
|
|
253
|
+
A latest failed, aborted, pending, deferred, or untimed response hides the module instead of showing an older response's rate.
|
|
254
|
+
Missing, nonfinite, or negative output counts, nonpositive or nonfinite durations, and nonfinite calculated rates also hide the module; valid zero output shows `0.0 tok/s`.
|
|
255
|
+
Older sessions and some deferred results have no recorded duration.
|
|
256
|
+
Resume, reload, fork, and tree navigation derive the value from the active branch, so abandoned-branch responses, tool results, compactions, branch summaries, and cache-warming usage do not supply the rate.
|
|
257
|
+
This module does not change the cumulative accounting used by `tokens`, `cache`, or `cost`.
|
|
258
|
+
|
|
224
259
|
### Directory, Git, and environment contraction
|
|
225
260
|
|
|
226
261
|
These modules keep their display policy local. Existing Pi defaults remain unchanged:
|
package/src/command-preview.ts
CHANGED
|
@@ -48,6 +48,7 @@ export async function showPreviewActionMenu<Value extends string>(
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
return {
|
|
51
|
+
capturesViewportInput: true,
|
|
51
52
|
render(width: number): string[] {
|
|
52
53
|
const safeWidth = Math.max(1, width);
|
|
53
54
|
const terminalRows = Number.isFinite(tui.terminal.rows) ? Math.floor(tui.terminal.rows) : 24;
|
package/src/modules/catalog.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { systemModules } from "./system.js";
|
|
|
26
26
|
import { thinkingModule } from "./thinking.js";
|
|
27
27
|
import { timeModule } from "./time.js";
|
|
28
28
|
import { tokensModule } from "./tokens.js";
|
|
29
|
+
import { tokensPerSecondModule } from "./tokens-per-second.js";
|
|
29
30
|
import { turnModule } from "./turn.js";
|
|
30
31
|
import type { ModuleDefinition } from "./types.js";
|
|
31
32
|
|
|
@@ -53,6 +54,7 @@ const MODULE_IMPLEMENTATIONS = [
|
|
|
53
54
|
activityModule,
|
|
54
55
|
contextModule,
|
|
55
56
|
tokensModule,
|
|
57
|
+
tokensPerSecondModule,
|
|
56
58
|
cacheModule,
|
|
57
59
|
costModule,
|
|
58
60
|
timeModule,
|
|
@@ -75,7 +77,7 @@ const MODULE_DESCRIPTIONS = {
|
|
|
75
77
|
conda: "Active Conda environment.",
|
|
76
78
|
container: "Current container or remote development environment.",
|
|
77
79
|
context: "Current model context-window usage.",
|
|
78
|
-
cost: "
|
|
80
|
+
cost: "Session cost, provider-total provenance, and subscription state.",
|
|
79
81
|
deno: "Deno version detected in the current workspace.",
|
|
80
82
|
directory: "Current working directory.",
|
|
81
83
|
direnv: "Current direnv loading and permission state.",
|
|
@@ -114,6 +116,8 @@ const MODULE_DESCRIPTIONS = {
|
|
|
114
116
|
thinking: "Current Pi thinking level or streaming state.",
|
|
115
117
|
time: "Current local time.",
|
|
116
118
|
tokens: "Session input and output token totals.",
|
|
119
|
+
tokens_per_second:
|
|
120
|
+
"Average output tokens per second for the latest completed assistant response on the active branch.",
|
|
117
121
|
turn: "Current user-turn count.",
|
|
118
122
|
username: "Current user identity when configured to display.",
|
|
119
123
|
} as const satisfies Record<ModuleName, string>;
|
package/src/modules/cost.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { defineModule } from "./types.js";
|
|
|
3
3
|
|
|
4
4
|
export const costModule = defineModule({
|
|
5
5
|
name: "cost",
|
|
6
|
-
variables: ["symbol", "cost", "subscription"],
|
|
6
|
+
variables: ["symbol", "cost", "subscription", "source"],
|
|
7
7
|
defaults: {
|
|
8
8
|
format: "[ $symbol \\$$cost( $subscription) ]($style)",
|
|
9
9
|
symbol: "💸",
|
|
@@ -22,6 +22,7 @@ export const costModule = defineModule({
|
|
|
22
22
|
},
|
|
23
23
|
values: ({ runtime }) => ({
|
|
24
24
|
cost: formatCost(runtime.tokenTotals.cost),
|
|
25
|
+
source: runtime.tokenTotals.costTotalFromProvider === true ? "provider" : "unconfirmed",
|
|
25
26
|
subscription: runtime.usingSubscription ? "(sub)" : "",
|
|
26
27
|
}),
|
|
27
28
|
});
|
|
@@ -2,8 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
3
3
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { execWorkspaceCommand } from "../../runtime/command.js";
|
|
5
|
-
import {
|
|
6
|
-
import type { WorkspaceExec } from "../../runtime/types.js";
|
|
5
|
+
import type { WorkspaceExec, WorkspaceExecResult } from "../../runtime/types.js";
|
|
7
6
|
import type {
|
|
8
7
|
GitBranchSnapshot,
|
|
9
8
|
GitCommitSnapshot,
|
|
@@ -15,6 +14,8 @@ import type {
|
|
|
15
14
|
} from "../types.js";
|
|
16
15
|
|
|
17
16
|
const GIT_TIMEOUT_MS = 3_000;
|
|
17
|
+
// Bound complete porcelain records and repository metadata; omit larger footer replies in full.
|
|
18
|
+
const MAX_GIT_OUTPUT_BYTES = 64 * 1024;
|
|
18
19
|
|
|
19
20
|
export interface ReadGitSnapshotOptions {
|
|
20
21
|
includeMetrics: boolean;
|
|
@@ -69,17 +70,19 @@ export async function readGitSnapshot(
|
|
|
69
70
|
metricsPromise,
|
|
70
71
|
tagPromise,
|
|
71
72
|
]);
|
|
72
|
-
if (options.signal?.aborted || statusResult.killed) return undefined;
|
|
73
|
+
if (statusResult.truncated || options.signal?.aborted || statusResult.killed) return undefined;
|
|
73
74
|
if (statusResult.code !== 0) {
|
|
74
75
|
return options.inspectBare ? readBareSnapshot(pi, cwd, options, tagResult) : undefined;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
const parsed = parseGitStatusPorcelainV2(statusResult.stdout);
|
|
78
79
|
const metadata =
|
|
79
|
-
metadataResult.code === 0 && !metadataResult.killed
|
|
80
|
+
!metadataResult.truncated && metadataResult.code === 0 && !metadataResult.killed
|
|
81
|
+
? parseGitRepositoryMetadata(metadataResult.stdout)
|
|
82
|
+
: undefined;
|
|
80
83
|
const commit = withTag(parsed.commit, tagResult);
|
|
81
84
|
const metrics =
|
|
82
|
-
metricsResult && metricsResult.code === 0 && !metricsResult.killed
|
|
85
|
+
metricsResult && !metricsResult.truncated && metricsResult.code === 0 && !metricsResult.killed
|
|
83
86
|
? parseGitDiffShortstat(metricsResult.stdout)
|
|
84
87
|
: undefined;
|
|
85
88
|
|
|
@@ -93,7 +96,7 @@ export async function readGitSnapshot(
|
|
|
93
96
|
};
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
type GitCommandResult =
|
|
99
|
+
type GitCommandResult = WorkspaceExecResult;
|
|
97
100
|
|
|
98
101
|
async function runGit(
|
|
99
102
|
pi: ExtensionAPI,
|
|
@@ -101,22 +104,30 @@ async function runGit(
|
|
|
101
104
|
args: string[],
|
|
102
105
|
options: Pick<ReadGitSnapshotOptions, "signal" | "exec">,
|
|
103
106
|
): Promise<GitCommandResult> {
|
|
104
|
-
const failed = { stdout: "", stderr: "", code: 1, killed: options.signal?.aborted ?? false };
|
|
107
|
+
const failed = { stdout: "", stderr: "", code: 1, killed: options.signal?.aborted ?? false, truncated: false };
|
|
105
108
|
if (options.signal?.aborted) return failed;
|
|
106
109
|
try {
|
|
107
110
|
const result = options.exec
|
|
108
111
|
? await options.exec("git", args, {
|
|
109
112
|
cwd,
|
|
110
113
|
timeout: GIT_TIMEOUT_MS,
|
|
111
|
-
maxOutputBytes:
|
|
114
|
+
maxOutputBytes: MAX_GIT_OUTPUT_BYTES,
|
|
112
115
|
signal: options.signal,
|
|
113
116
|
environment: process.env,
|
|
114
117
|
})
|
|
115
|
-
: await pi.exec("git", args, {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
: await pi.exec("git", args, {
|
|
119
|
+
cwd,
|
|
120
|
+
signal: options.signal,
|
|
121
|
+
timeout: GIT_TIMEOUT_MS,
|
|
122
|
+
maxBuffer: MAX_GIT_OUTPUT_BYTES,
|
|
123
|
+
});
|
|
124
|
+
if (
|
|
125
|
+
result.truncated ||
|
|
126
|
+
Buffer.byteLength(result.stdout) + Buffer.byteLength(result.stderr) > MAX_GIT_OUTPUT_BYTES
|
|
127
|
+
) {
|
|
128
|
+
return { ...failed, killed: result.killed, truncated: true };
|
|
119
129
|
}
|
|
130
|
+
if (options.signal?.aborted) return { ...failed, killed: true };
|
|
120
131
|
return result;
|
|
121
132
|
} catch {
|
|
122
133
|
return failed;
|
|
@@ -132,12 +143,13 @@ async function readBareSnapshot(
|
|
|
132
143
|
const boundedOptions = { ...options, exec: options.exec ?? execWorkspaceCommand };
|
|
133
144
|
const run = (args: string[]) => runGit(pi, cwd, args, boundedOptions);
|
|
134
145
|
const bare = await run(["rev-parse", "--is-bare-repository"]);
|
|
135
|
-
if (options.signal?.aborted || bare.killed || bare.code !== 0 || bare.stdout.trim() !== "true")
|
|
146
|
+
if (bare.truncated || options.signal?.aborted || bare.killed || bare.code !== 0 || bare.stdout.trim() !== "true")
|
|
147
|
+
return undefined;
|
|
136
148
|
const [head, hash] = await Promise.all([
|
|
137
149
|
run(["symbolic-ref", "--short", "HEAD"]),
|
|
138
150
|
run(["rev-parse", "--verify", "HEAD"]),
|
|
139
151
|
]);
|
|
140
|
-
if (options.signal?.aborted || head.killed || hash.killed) return undefined;
|
|
152
|
+
if (head.truncated || hash.truncated || options.signal?.aborted || head.killed || hash.killed) return undefined;
|
|
141
153
|
const name = head.code === 0 ? head.stdout.trim() : "";
|
|
142
154
|
const commitHash = hash.code === 0 ? hash.stdout.trim() : "";
|
|
143
155
|
const validHash = /^[a-fA-F0-9]{4,64}$/u.test(commitHash);
|
|
@@ -149,7 +161,9 @@ async function readBareSnapshot(
|
|
|
149
161
|
: undefined;
|
|
150
162
|
if (options.signal?.aborted) return undefined;
|
|
151
163
|
const upstreamFields =
|
|
152
|
-
upstreamResult
|
|
164
|
+
upstreamResult && !upstreamResult.truncated && upstreamResult.code === 0 && !upstreamResult.killed
|
|
165
|
+
? upstreamResult.stdout.trimEnd().split("\0")
|
|
166
|
+
: [];
|
|
153
167
|
const remote = upstreamFields[0] === reference ? splitUpstream(upstreamFields[1]) : {};
|
|
154
168
|
return {
|
|
155
169
|
branch: { name: name || "HEAD", detached, bare: true, ...remote },
|
|
@@ -165,7 +179,7 @@ export async function readGitStatus(pi: ExtensionAPI, cwd: string): Promise<GitS
|
|
|
165
179
|
["--no-optional-locks", "status", "--porcelain=v2", "--branch", "--show-stash", "--untracked-files=normal"],
|
|
166
180
|
{},
|
|
167
181
|
);
|
|
168
|
-
if (result.code !== 0 || result.killed) return undefined;
|
|
182
|
+
if (result.truncated || result.code !== 0 || result.killed) return undefined;
|
|
169
183
|
return parseGitStatusPorcelainV2(result.stdout).status;
|
|
170
184
|
}
|
|
171
185
|
|
|
@@ -176,7 +190,7 @@ export async function readGitWorktree(pi: ExtensionAPI, cwd: string): Promise<Gi
|
|
|
176
190
|
["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
|
|
177
191
|
{},
|
|
178
192
|
);
|
|
179
|
-
if (result.code !== 0 || result.killed) return undefined;
|
|
193
|
+
if (result.truncated || result.code !== 0 || result.killed) return undefined;
|
|
180
194
|
return parseGitRepositoryMetadata(result.stdout)?.worktree;
|
|
181
195
|
}
|
|
182
196
|
|
|
@@ -408,15 +422,9 @@ function splitUpstream(upstream: string | undefined): {
|
|
|
408
422
|
|
|
409
423
|
function withTag(
|
|
410
424
|
commit: GitCommitSnapshot | undefined,
|
|
411
|
-
result:
|
|
412
|
-
| {
|
|
413
|
-
stdout: string;
|
|
414
|
-
code: number;
|
|
415
|
-
killed: boolean;
|
|
416
|
-
}
|
|
417
|
-
| undefined,
|
|
425
|
+
result: GitCommandResult | undefined,
|
|
418
426
|
): GitCommitSnapshot | undefined {
|
|
419
|
-
if (!commit || !result || result.code !== 0 || result.killed) return commit;
|
|
427
|
+
if (!commit || !result || result.truncated || result.code !== 0 || result.killed) return commit;
|
|
420
428
|
const tag = result.stdout.trim();
|
|
421
429
|
return tag ? { ...commit, tag: tag.split(/\r?\n/u)[0] } : commit;
|
|
422
430
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineModule } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export const tokensPerSecondModule = defineModule({
|
|
4
|
+
name: "tokens_per_second",
|
|
5
|
+
variables: ["symbol", "rate"],
|
|
6
|
+
defaults: {
|
|
7
|
+
format: "[$rate tok/s ]($style)",
|
|
8
|
+
symbol: "",
|
|
9
|
+
style: "bold cyan",
|
|
10
|
+
disabled: true,
|
|
11
|
+
},
|
|
12
|
+
values: ({ runtime }) =>
|
|
13
|
+
runtime.tokensPerSecond === undefined ? undefined : { rate: runtime.tokensPerSecond.toFixed(1) },
|
|
14
|
+
});
|
package/src/modules/types.ts
CHANGED
|
@@ -109,8 +109,10 @@ export interface StarshipRuntimeSnapshot {
|
|
|
109
109
|
cacheRead: number;
|
|
110
110
|
cacheWrite: number;
|
|
111
111
|
cost: number;
|
|
112
|
+
costTotalFromProvider?: boolean;
|
|
112
113
|
latestCacheHitRate?: number;
|
|
113
114
|
};
|
|
115
|
+
tokensPerSecond?: number;
|
|
114
116
|
usingSubscription: boolean;
|
|
115
117
|
gitBranch: string | null;
|
|
116
118
|
gitBranchDetails?: GitBranchSnapshot;
|
package/src/pi-starship.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
type WorkspaceRefreshInput,
|
|
30
30
|
workspaceSnapshotEqual,
|
|
31
31
|
} from "./runtime/workspace.js";
|
|
32
|
-
import { summarizeFooterUsage } from "./usage.js";
|
|
32
|
+
import { latestTokensPerSecond, summarizeFooterUsage } from "./usage.js";
|
|
33
33
|
|
|
34
34
|
const REFRESH_INTERVAL_MS = 30_000;
|
|
35
35
|
const GITHUB_PR_REFRESH_INTERVAL_MS = 60_000;
|
|
@@ -711,19 +711,21 @@ function runtimeSnapshot(
|
|
|
711
711
|
footerData: Pick<ReadonlyFooterDataProvider, "getGitBranch" | "getExtensionStatuses">,
|
|
712
712
|
runtime: RuntimeState,
|
|
713
713
|
): StarshipRuntimeSnapshot {
|
|
714
|
+
const branch = ctx.sessionManager.getBranch();
|
|
714
715
|
return {
|
|
715
716
|
cwd: ctx.cwd,
|
|
716
717
|
homeDir: homedir(),
|
|
717
718
|
gitRoot: runtime.git?.root,
|
|
718
719
|
model: ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined,
|
|
719
720
|
thinkingLevel: runtime.thinkingLevel,
|
|
720
|
-
turnCount:
|
|
721
|
+
turnCount: branch.filter((entry) => entry.type === "message" && entry.message.role === "user").length,
|
|
721
722
|
activeTools: runtime.activeTools,
|
|
722
723
|
isStreaming: runtime.isStreaming,
|
|
723
724
|
uiPrompt: runtime.uiPrompt,
|
|
724
725
|
lastCompletedTool: runtime.lastCompletedTool,
|
|
725
726
|
contextUsage: ctx.getContextUsage() ?? undefined,
|
|
726
727
|
tokenTotals: summarizeFooterUsage(ctx.sessionManager.getEntries()),
|
|
728
|
+
tokensPerSecond: latestTokensPerSecond(branch),
|
|
727
729
|
usingSubscription: isSubscriptionBacked(ctx),
|
|
728
730
|
gitBranch: runtime.git?.branch?.name ?? footerData.getGitBranch(),
|
|
729
731
|
gitBranchDetails: runtime.git?.branch,
|
|
@@ -739,11 +741,6 @@ function runtimeSnapshot(
|
|
|
739
741
|
};
|
|
740
742
|
}
|
|
741
743
|
|
|
742
|
-
function userTurnCount(ctx: ExtensionContext): number {
|
|
743
|
-
return ctx.sessionManager.getBranch().filter((entry) => entry.type === "message" && entry.message.role === "user")
|
|
744
|
-
.length;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
744
|
function isSubscriptionBacked(ctx: ExtensionContext): boolean {
|
|
748
745
|
const model = ctx.model;
|
|
749
746
|
return model !== undefined && (model.provider === "kimi-coding" || ctx.modelRegistry.isUsingOAuth(model));
|
package/src/runtime/command.ts
CHANGED
|
@@ -6,7 +6,7 @@ const FORCE_KILL_DELAY_MS = 250;
|
|
|
6
6
|
export const execWorkspaceCommand: WorkspaceExec = async (command, args, options) =>
|
|
7
7
|
new Promise((resolve) => {
|
|
8
8
|
if (options.signal?.aborted) {
|
|
9
|
-
resolve({ stdout: "", stderr: "", code: 1, killed: true });
|
|
9
|
+
resolve({ stdout: "", stderr: "", code: 1, killed: true, truncated: false });
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -21,13 +21,14 @@ export const execWorkspaceCommand: WorkspaceExec = async (command, args, options
|
|
|
21
21
|
windowsHide: true,
|
|
22
22
|
});
|
|
23
23
|
} catch {
|
|
24
|
-
resolve({ stdout: "", stderr: "", code: 1, killed: false });
|
|
24
|
+
resolve({ stdout: "", stderr: "", code: 1, killed: false, truncated: false });
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const stdout: Buffer[] = [];
|
|
29
29
|
const stderr: Buffer[] = [];
|
|
30
30
|
let outputBytes = 0;
|
|
31
|
+
let truncated = false;
|
|
31
32
|
let killed = false;
|
|
32
33
|
let settled = false;
|
|
33
34
|
let forceKillTimer: NodeJS.Timeout | undefined;
|
|
@@ -44,6 +45,7 @@ export const execWorkspaceCommand: WorkspaceExec = async (command, args, options
|
|
|
44
45
|
stderr: Buffer.concat(stderr).toString("utf8"),
|
|
45
46
|
code,
|
|
46
47
|
killed,
|
|
48
|
+
truncated,
|
|
47
49
|
});
|
|
48
50
|
};
|
|
49
51
|
|
|
@@ -88,7 +90,10 @@ export const execWorkspaceCommand: WorkspaceExec = async (command, args, options
|
|
|
88
90
|
const remaining = Math.max(0, options.maxOutputBytes - outputBytes);
|
|
89
91
|
if (remaining > 0) target.push(chunk.subarray(0, remaining));
|
|
90
92
|
outputBytes += chunk.byteLength;
|
|
91
|
-
if (outputBytes > options.maxOutputBytes)
|
|
93
|
+
if (outputBytes > options.maxOutputBytes) {
|
|
94
|
+
truncated = true;
|
|
95
|
+
terminate();
|
|
96
|
+
}
|
|
92
97
|
};
|
|
93
98
|
|
|
94
99
|
child.stdout?.on("data", collect(stdout));
|
package/src/runtime/github-pr.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { GithubPrSnapshot, GithubPrState } from "../modules/types.js";
|
|
|
3
3
|
import type { WorkspaceExec } from "./types.js";
|
|
4
4
|
|
|
5
5
|
const GH_TIMEOUT_MS = 10_000;
|
|
6
|
+
// One PR's selected fields and check summaries; omit larger replies instead of parsing partial JSON.
|
|
6
7
|
const MAX_GH_OUTPUT_BYTES = 128 * 1024;
|
|
7
8
|
const MAX_URL_LENGTH = 4_096;
|
|
8
9
|
const MAX_CHECKS = 1_000;
|
|
@@ -69,6 +70,7 @@ export async function queryGithubPr(
|
|
|
69
70
|
now = Date.now(),
|
|
70
71
|
options: GithubPrQueryOptions = {},
|
|
71
72
|
): Promise<GithubPrSnapshot | undefined> {
|
|
73
|
+
if (signal?.aborted) return undefined;
|
|
72
74
|
const invocation = ghPrViewInvocation(options.platform);
|
|
73
75
|
try {
|
|
74
76
|
const result = await exec(invocation.command, invocation.args, {
|
|
@@ -78,8 +80,9 @@ export async function queryGithubPr(
|
|
|
78
80
|
maxOutputBytes: MAX_GH_OUTPUT_BYTES,
|
|
79
81
|
environment: githubPrEnvironment(options.environment),
|
|
80
82
|
});
|
|
81
|
-
if (result.
|
|
82
|
-
if (
|
|
83
|
+
if (result.truncated) return undefined;
|
|
84
|
+
if (signal?.aborted || result.killed || result.code !== 0) return undefined;
|
|
85
|
+
if (Buffer.byteLength(result.stdout) + Buffer.byteLength(result.stderr) > MAX_GH_OUTPUT_BYTES) return undefined;
|
|
83
86
|
return buildGithubPrSnapshot(JSON.parse(result.stdout), now);
|
|
84
87
|
} catch {
|
|
85
88
|
return undefined;
|
package/src/runtime/helpers.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { formatVersion } from "../format/version.js";
|
|
|
7
7
|
|
|
8
8
|
export const MAX_METADATA_FILE_BYTES = 64 * 1024;
|
|
9
9
|
export const COMMAND_TIMEOUT_MS = 2_000;
|
|
10
|
+
// Footer probes need only version, health, or local metadata; omit larger replies in full.
|
|
10
11
|
export const MAX_COMMAND_OUTPUT_BYTES = 64 * 1024;
|
|
11
12
|
const MAX_DIRECTORY_ENTRIES = 2_048;
|
|
12
13
|
const MAX_LABEL_LENGTH = 160;
|
|
@@ -206,11 +207,11 @@ export async function runBounded(
|
|
|
206
207
|
signal: context.input.signal,
|
|
207
208
|
environment: context.input.environment,
|
|
208
209
|
});
|
|
210
|
+
if (result.truncated) return undefined;
|
|
209
211
|
if (context.input.signal?.aborted || result.code !== 0 || result.killed) return undefined;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return output.toString("utf8");
|
|
212
|
+
if (Buffer.byteLength(result.stdout) + Buffer.byteLength(result.stderr) > MAX_COMMAND_OUTPUT_BYTES)
|
|
213
|
+
return undefined;
|
|
214
|
+
return result.stdout || result.stderr;
|
|
214
215
|
} catch {
|
|
215
216
|
return undefined;
|
|
216
217
|
}
|
package/src/runtime/types.ts
CHANGED
package/src/usage.ts
CHANGED
|
@@ -5,7 +5,7 @@ interface UsageLike {
|
|
|
5
5
|
output?: number;
|
|
6
6
|
cacheRead?: number;
|
|
7
7
|
cacheWrite?: number;
|
|
8
|
-
cost?: { total?: number };
|
|
8
|
+
cost?: { total?: number; totalFromProvider?: boolean };
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface FooterUsageSummary {
|
|
@@ -14,9 +14,35 @@ export interface FooterUsageSummary {
|
|
|
14
14
|
cacheRead: number;
|
|
15
15
|
cacheWrite: number;
|
|
16
16
|
cost: number;
|
|
17
|
+
costTotalFromProvider: boolean;
|
|
17
18
|
latestCacheHitRate?: number;
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
/** Use the latest assistant only: an untimed or incomplete response must not expose an older rate. */
|
|
22
|
+
export function latestTokensPerSecond(branch: readonly SessionEntry[]): number | undefined {
|
|
23
|
+
for (let index = branch.length - 1; index >= 0; index -= 1) {
|
|
24
|
+
const entry = branch[index];
|
|
25
|
+
if (entry?.type !== "message" || entry.message.role !== "assistant") continue;
|
|
26
|
+
const { stopReason, durationMs, usage } = entry.message;
|
|
27
|
+
if (stopReason !== "stop" && stopReason !== "length" && stopReason !== "toolUse") return undefined;
|
|
28
|
+
const output = usage?.output;
|
|
29
|
+
if (
|
|
30
|
+
typeof durationMs !== "number" ||
|
|
31
|
+
!Number.isFinite(durationMs) ||
|
|
32
|
+
durationMs <= 0 ||
|
|
33
|
+
typeof output !== "number" ||
|
|
34
|
+
!Number.isFinite(output) ||
|
|
35
|
+
output < 0
|
|
36
|
+
) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
// Pi times the complete response, including request latency, not just streamed text.
|
|
40
|
+
const rate = output / (durationMs / 1000);
|
|
41
|
+
return Number.isFinite(rate) ? rate : undefined;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
20
46
|
export function summarizeFooterUsage(entries: readonly SessionEntry[]): FooterUsageSummary {
|
|
21
47
|
const totals: FooterUsageSummary = {
|
|
22
48
|
input: 0,
|
|
@@ -24,15 +50,18 @@ export function summarizeFooterUsage(entries: readonly SessionEntry[]): FooterUs
|
|
|
24
50
|
cacheRead: 0,
|
|
25
51
|
cacheWrite: 0,
|
|
26
52
|
cost: 0,
|
|
53
|
+
costTotalFromProvider: false,
|
|
27
54
|
};
|
|
55
|
+
let hasUsage = false;
|
|
56
|
+
let allTotalsFromProvider = true;
|
|
28
57
|
|
|
29
58
|
for (const entry of entries) {
|
|
30
59
|
let usage: UsageLike | undefined;
|
|
31
60
|
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
32
61
|
usage = entry.message.usage;
|
|
33
|
-
const input = usage
|
|
34
|
-
const cacheRead = usage
|
|
35
|
-
const cacheWrite = usage
|
|
62
|
+
const input = usage?.input ?? 0;
|
|
63
|
+
const cacheRead = usage?.cacheRead ?? 0;
|
|
64
|
+
const cacheWrite = usage?.cacheWrite ?? 0;
|
|
36
65
|
const promptTokens = input + cacheRead + cacheWrite;
|
|
37
66
|
totals.latestCacheHitRate = promptTokens > 0 ? (cacheRead / promptTokens) * 100 : undefined;
|
|
38
67
|
} else if (entry.type === "message" && entry.message.role === "toolResult") {
|
|
@@ -47,7 +76,16 @@ export function summarizeFooterUsage(entries: readonly SessionEntry[]): FooterUs
|
|
|
47
76
|
totals.cacheRead += usage.cacheRead ?? 0;
|
|
48
77
|
totals.cacheWrite += usage.cacheWrite ?? 0;
|
|
49
78
|
totals.cost += usage.cost?.total ?? 0;
|
|
79
|
+
hasUsage = true;
|
|
80
|
+
const cost = usage.cost;
|
|
81
|
+
allTotalsFromProvider &&=
|
|
82
|
+
cost?.totalFromProvider === true &&
|
|
83
|
+
typeof cost.total === "number" &&
|
|
84
|
+
Number.isFinite(cost.total) &&
|
|
85
|
+
cost.total >= 0;
|
|
50
86
|
}
|
|
51
87
|
|
|
88
|
+
// Empty or incomplete accounting cannot establish a provider-reported total.
|
|
89
|
+
totals.costTotalFromProvider = hasUsage && allTotalsFromProvider && Number.isFinite(totals.cost);
|
|
52
90
|
return totals;
|
|
53
91
|
}
|