@narumitw/pi-starship 0.65.0 → 0.65.2

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +3 -0
  3. package/dist/chunks/{chunk-S2KBLHE2.ts → chunk-3XLWHJ5Y.ts} +5 -5
  4. package/dist/chunks/chunk-3XLWHJ5Y.ts.map +7 -0
  5. package/dist/chunks/{chunk-I22B7QPQ.ts → chunk-5YA3XF7S.ts} +4 -3
  6. package/dist/chunks/chunk-5YA3XF7S.ts.map +7 -0
  7. package/dist/chunks/{chunk-D2YWQMYT.ts → chunk-PZWT7OTP.ts} +3 -3
  8. package/dist/chunks/{chunk-XTLQ4WUL.ts → chunk-QGB3NNTM.ts} +1 -1
  9. package/dist/chunks/chunk-QGB3NNTM.ts.map +7 -0
  10. package/dist/chunks/{chunk-YK4S4RRM.ts → chunk-RQY2AYI2.ts} +3 -2
  11. package/dist/chunks/chunk-RQY2AYI2.ts.map +7 -0
  12. package/dist/chunks/{cloud-J2ZOE3HE.ts → cloud-CNNWXSQ3.ts} +2 -2
  13. package/dist/chunks/{command-configuration-menu-BJYQXV2U.ts → command-configuration-menu-JHKQ5SDW.ts} +6 -3
  14. package/dist/chunks/command-configuration-menu-JHKQ5SDW.ts.map +7 -0
  15. package/dist/chunks/{command-settings-chat-42OTC7NJ.ts → command-settings-chat-RN2GDMF5.ts} +4 -4
  16. package/dist/chunks/{commands-ZL36J5TX.ts → commands-XIRYGV7S.ts} +6 -6
  17. package/dist/chunks/{deployment-NOJ2KCLI.ts → deployment-KNUSQSJ5.ts} +3 -3
  18. package/dist/chunks/{development-T3XXVVDP.ts → development-TJNVM4H2.ts} +2 -2
  19. package/dist/chunks/{execution-R2OHIP2L.ts → execution-OFQXHFAH.ts} +3 -3
  20. package/dist/chunks/{jujutsu-XLDYKSX2.ts → jujutsu-T2LTPHSY.ts} +2 -2
  21. package/dist/chunks/{languages-CBQNNYXM.ts → languages-VWXTVJ45.ts} +3 -3
  22. package/dist/chunks/{package-7KVAK3TC.ts → package-JA4CJ5DR.ts} +2 -2
  23. package/dist/chunks/{system-574MHB4R.ts → system-CDTPAQZX.ts} +2 -2
  24. package/dist/index.ts +58 -36
  25. package/dist/index.ts.map +2 -2
  26. package/package.json +6 -5
  27. package/skills/configure-pi-starship/references/module-catalog.md +2 -2
  28. package/skills/configure-pi-starship/references/modules.md +10 -2
  29. package/src/command-configuration-menu.ts +3 -0
  30. package/src/command-preview.ts +1 -0
  31. package/src/modules/catalog.ts +1 -1
  32. package/src/modules/cost.ts +2 -1
  33. package/src/modules/git/runtime.ts +33 -25
  34. package/src/modules/types.ts +1 -0
  35. package/src/pi-starship.ts +2 -0
  36. package/src/runtime/command.ts +8 -3
  37. package/src/runtime/github-pr.ts +5 -2
  38. package/src/runtime/helpers.ts +5 -4
  39. package/src/runtime/types.ts +1 -0
  40. package/src/usage.ts +17 -4
  41. package/dist/chunks/chunk-I22B7QPQ.ts.map +0 -7
  42. package/dist/chunks/chunk-S2KBLHE2.ts.map +0 -7
  43. package/dist/chunks/chunk-XTLQ4WUL.ts.map +0 -7
  44. package/dist/chunks/chunk-YK4S4RRM.ts.map +0 -7
  45. package/dist/chunks/command-configuration-menu-BJYQXV2U.ts.map +0 -7
  46. /package/dist/chunks/{chunk-D2YWQMYT.ts.map → chunk-PZWT7OTP.ts.map} +0 -0
  47. /package/dist/chunks/{cloud-J2ZOE3HE.ts.map → cloud-CNNWXSQ3.ts.map} +0 -0
  48. /package/dist/chunks/{command-settings-chat-42OTC7NJ.ts.map → command-settings-chat-RN2GDMF5.ts.map} +0 -0
  49. /package/dist/chunks/{commands-ZL36J5TX.ts.map → commands-XIRYGV7S.ts.map} +0 -0
  50. /package/dist/chunks/{deployment-NOJ2KCLI.ts.map → deployment-KNUSQSJ5.ts.map} +0 -0
  51. /package/dist/chunks/{development-T3XXVVDP.ts.map → development-TJNVM4H2.ts.map} +0 -0
  52. /package/dist/chunks/{execution-R2OHIP2L.ts.map → execution-OFQXHFAH.ts.map} +0 -0
  53. /package/dist/chunks/{jujutsu-XLDYKSX2.ts.map → jujutsu-T2LTPHSY.ts.map} +0 -0
  54. /package/dist/chunks/{languages-CBQNNYXM.ts.map → languages-VWXTVJ45.ts.map} +0 -0
  55. /package/dist/chunks/{package-7KVAK3TC.ts.map → package-JA4CJ5DR.ts.map} +0 -0
  56. /package/dist/chunks/{system-574MHB4R.ts.map → system-CDTPAQZX.ts.map} +0 -0
package/dist/index.ts CHANGED
@@ -10,15 +10,14 @@ import {
10
10
  directoryAlternateFormat,
11
11
  loadStarshipConfig,
12
12
  settingsFilePath
13
- } from "./chunks/chunk-I22B7QPQ.ts";
13
+ } from "./chunks/chunk-5YA3XF7S.ts";
14
14
  import "./chunks/chunk-IYDZ3R2T.ts";
15
15
  import {
16
16
  PRIVATE_STYLE_SELECTOR
17
- } from "./chunks/chunk-XTLQ4WUL.ts";
17
+ } from "./chunks/chunk-QGB3NNTM.ts";
18
18
  import {
19
- MAX_COMMAND_OUTPUT_BYTES,
20
19
  createFileSystem
21
- } from "./chunks/chunk-S2KBLHE2.ts";
20
+ } from "./chunks/chunk-3XLWHJ5Y.ts";
22
21
  import {
23
22
  formatVariables,
24
23
  isFillChunk,
@@ -44,7 +43,7 @@ import { spawn } from "node:child_process";
44
43
  var FORCE_KILL_DELAY_MS = 250;
45
44
  var execWorkspaceCommand = async (command, args, options) => new Promise((resolve2) => {
46
45
  if (options.signal?.aborted) {
47
- resolve2({ stdout: "", stderr: "", code: 1, killed: true });
46
+ resolve2({ stdout: "", stderr: "", code: 1, killed: true, truncated: false });
48
47
  return;
49
48
  }
50
49
  let child;
@@ -58,12 +57,13 @@ var execWorkspaceCommand = async (command, args, options) => new Promise((resolv
58
57
  windowsHide: true
59
58
  });
60
59
  } catch {
61
- resolve2({ stdout: "", stderr: "", code: 1, killed: false });
60
+ resolve2({ stdout: "", stderr: "", code: 1, killed: false, truncated: false });
62
61
  return;
63
62
  }
64
63
  const stdout = [];
65
64
  const stderr = [];
66
65
  let outputBytes = 0;
66
+ let truncated = false;
67
67
  let killed = false;
68
68
  let settled = false;
69
69
  let forceKillTimer;
@@ -78,7 +78,8 @@ var execWorkspaceCommand = async (command, args, options) => new Promise((resolv
78
78
  stdout: Buffer.concat(stdout).toString("utf8"),
79
79
  stderr: Buffer.concat(stderr).toString("utf8"),
80
80
  code,
81
- killed
81
+ killed,
82
+ truncated
82
83
  });
83
84
  };
84
85
  const signalProcessTree = (signal) => {
@@ -120,7 +121,10 @@ var execWorkspaceCommand = async (command, args, options) => new Promise((resolv
120
121
  const remaining = Math.max(0, options.maxOutputBytes - outputBytes);
121
122
  if (remaining > 0) target.push(chunk.subarray(0, remaining));
122
123
  outputBytes += chunk.byteLength;
123
- if (outputBytes > options.maxOutputBytes) terminate();
124
+ if (outputBytes > options.maxOutputBytes) {
125
+ truncated = true;
126
+ terminate();
127
+ }
124
128
  };
125
129
  child.stdout?.on("data", collect(stdout));
126
130
  child.stderr?.on("data", collect(stderr));
@@ -152,6 +156,7 @@ function explicitEnvironment(source) {
152
156
 
153
157
  // src/modules/git/runtime.ts
154
158
  var GIT_TIMEOUT_MS = 3e3;
159
+ var MAX_GIT_OUTPUT_BYTES = 64 * 1024;
155
160
  async function readGitSnapshot(pi, cwd, options) {
156
161
  if (options.signal?.aborted) return void 0;
157
162
  const run = (args) => runGit(pi, cwd, args, options);
@@ -185,14 +190,14 @@ async function readGitSnapshot(pi, cwd, options) {
185
190
  metricsPromise,
186
191
  tagPromise
187
192
  ]);
188
- if (options.signal?.aborted || statusResult.killed) return void 0;
193
+ if (statusResult.truncated || options.signal?.aborted || statusResult.killed) return void 0;
189
194
  if (statusResult.code !== 0) {
190
195
  return options.inspectBare ? readBareSnapshot(pi, cwd, options, tagResult) : void 0;
191
196
  }
192
197
  const parsed = parseGitStatusPorcelainV2(statusResult.stdout);
193
- const metadata = metadataResult.code === 0 && !metadataResult.killed ? parseGitRepositoryMetadata(metadataResult.stdout) : void 0;
198
+ const metadata = !metadataResult.truncated && metadataResult.code === 0 && !metadataResult.killed ? parseGitRepositoryMetadata(metadataResult.stdout) : void 0;
194
199
  const commit = withTag(parsed.commit, tagResult);
195
- const metrics = metricsResult && metricsResult.code === 0 && !metricsResult.killed ? parseGitDiffShortstat(metricsResult.stdout) : void 0;
200
+ const metrics = metricsResult && !metricsResult.truncated && metricsResult.code === 0 && !metricsResult.killed ? parseGitDiffShortstat(metricsResult.stdout) : void 0;
196
201
  return {
197
202
  ...parsed,
198
203
  root: metadata?.root,
@@ -203,20 +208,25 @@ async function readGitSnapshot(pi, cwd, options) {
203
208
  };
204
209
  }
205
210
  async function runGit(pi, cwd, args, options) {
206
- const failed = { stdout: "", stderr: "", code: 1, killed: options.signal?.aborted ?? false };
211
+ const failed = { stdout: "", stderr: "", code: 1, killed: options.signal?.aborted ?? false, truncated: false };
207
212
  if (options.signal?.aborted) return failed;
208
213
  try {
209
214
  const result = options.exec ? await options.exec("git", args, {
210
215
  cwd,
211
216
  timeout: GIT_TIMEOUT_MS,
212
- maxOutputBytes: MAX_COMMAND_OUTPUT_BYTES,
217
+ maxOutputBytes: MAX_GIT_OUTPUT_BYTES,
213
218
  signal: options.signal,
214
219
  environment: process.env
215
- }) : await pi.exec("git", args, { cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS });
216
- if (options.signal?.aborted) return { ...failed, killed: true };
217
- if (Buffer.byteLength(result.stdout) + Buffer.byteLength(result.stderr) > MAX_COMMAND_OUTPUT_BYTES) {
218
- return { ...failed, killed: true };
220
+ }) : await pi.exec("git", args, {
221
+ cwd,
222
+ signal: options.signal,
223
+ timeout: GIT_TIMEOUT_MS,
224
+ maxBuffer: MAX_GIT_OUTPUT_BYTES
225
+ });
226
+ if (result.truncated || Buffer.byteLength(result.stdout) + Buffer.byteLength(result.stderr) > MAX_GIT_OUTPUT_BYTES) {
227
+ return { ...failed, killed: result.killed, truncated: true };
219
228
  }
229
+ if (options.signal?.aborted) return { ...failed, killed: true };
220
230
  return result;
221
231
  } catch {
222
232
  return failed;
@@ -226,12 +236,13 @@ async function readBareSnapshot(pi, cwd, options, tagResult) {
226
236
  const boundedOptions = { ...options, exec: options.exec ?? execWorkspaceCommand };
227
237
  const run = (args) => runGit(pi, cwd, args, boundedOptions);
228
238
  const bare = await run(["rev-parse", "--is-bare-repository"]);
229
- if (options.signal?.aborted || bare.killed || bare.code !== 0 || bare.stdout.trim() !== "true") return void 0;
239
+ if (bare.truncated || options.signal?.aborted || bare.killed || bare.code !== 0 || bare.stdout.trim() !== "true")
240
+ return void 0;
230
241
  const [head, hash] = await Promise.all([
231
242
  run(["symbolic-ref", "--short", "HEAD"]),
232
243
  run(["rev-parse", "--verify", "HEAD"])
233
244
  ]);
234
- if (options.signal?.aborted || head.killed || hash.killed) return void 0;
245
+ if (head.truncated || hash.truncated || options.signal?.aborted || head.killed || hash.killed) return void 0;
235
246
  const name = head.code === 0 ? head.stdout.trim() : "";
236
247
  const commitHash = hash.code === 0 ? hash.stdout.trim() : "";
237
248
  const validHash = /^[a-fA-F0-9]{4,64}$/u.test(commitHash);
@@ -240,7 +251,7 @@ async function readBareSnapshot(pi, cwd, options, tagResult) {
240
251
  const reference = `refs/heads/${name}`;
241
252
  const upstreamResult = name ? await run(["for-each-ref", "--count=1", "--format=%(refname)%00%(upstream:short)", reference]) : void 0;
242
253
  if (options.signal?.aborted) return void 0;
243
- const upstreamFields = upstreamResult?.code === 0 && !upstreamResult.killed ? upstreamResult.stdout.trimEnd().split("\0") : [];
254
+ const upstreamFields = upstreamResult && !upstreamResult.truncated && upstreamResult.code === 0 && !upstreamResult.killed ? upstreamResult.stdout.trimEnd().split("\0") : [];
244
255
  const remote = upstreamFields[0] === reference ? splitUpstream(upstreamFields[1]) : {};
245
256
  return {
246
257
  branch: { name: name || "HEAD", detached, bare: true, ...remote },
@@ -409,7 +420,7 @@ function splitUpstream(upstream) {
409
420
  };
410
421
  }
411
422
  function withTag(commit, result) {
412
- if (!commit || !result || result.code !== 0 || result.killed) return commit;
423
+ if (!commit || !result || result.truncated || result.code !== 0 || result.killed) return commit;
413
424
  const tag = result.stdout.trim();
414
425
  return tag ? { ...commit, tag: tag.split(/\r?\n/u)[0] } : commit;
415
426
  }
@@ -770,6 +781,7 @@ function githubPrEnvironment(source = process.env) {
770
781
  return environment;
771
782
  }
772
783
  async function queryGithubPr(exec, cwd, signal, now = Date.now(), options = {}) {
784
+ if (signal?.aborted) return void 0;
773
785
  const invocation = ghPrViewInvocation(options.platform);
774
786
  try {
775
787
  const result = await exec(invocation.command, invocation.args, {
@@ -779,8 +791,9 @@ async function queryGithubPr(exec, cwd, signal, now = Date.now(), options = {})
779
791
  maxOutputBytes: MAX_GH_OUTPUT_BYTES,
780
792
  environment: githubPrEnvironment(options.environment)
781
793
  });
782
- if (result.killed || result.code !== 0) return void 0;
783
- if (Buffer.byteLength(result.stdout) > MAX_GH_OUTPUT_BYTES) return void 0;
794
+ if (result.truncated) return void 0;
795
+ if (signal?.aborted || result.killed || result.code !== 0) return void 0;
796
+ if (Buffer.byteLength(result.stdout) + Buffer.byteLength(result.stderr) > MAX_GH_OUTPUT_BYTES) return void 0;
784
797
  return buildGithubPrSnapshot(JSON.parse(result.stdout), now);
785
798
  } catch {
786
799
  return void 0;
@@ -1067,7 +1080,7 @@ async function collectWorkspaceSnapshot(input) {
1067
1080
  };
1068
1081
  const modules = {};
1069
1082
  if (requirements.has("package")) {
1070
- const { collectPackage } = await import("./chunks/package-7KVAK3TC.ts");
1083
+ const { collectPackage } = await import("./chunks/package-JA4CJ5DR.ts");
1071
1084
  if (input.signal?.aborted) return freezeSnapshot({});
1072
1085
  const packageValues = await collectPackage(context);
1073
1086
  if (input.signal?.aborted) return freezeSnapshot({});
@@ -1095,31 +1108,31 @@ var COLLECTOR_GROUPS = [
1095
1108
  },
1096
1109
  {
1097
1110
  modules: ["jj_bookmark", "jj_change", "jj_metrics", "jj_status"],
1098
- load: async () => (await import("./chunks/jujutsu-XLDYKSX2.ts")).collectJujutsu
1111
+ load: async () => (await import("./chunks/jujutsu-T2LTPHSY.ts")).collectJujutsu
1099
1112
  },
1100
1113
  {
1101
1114
  modules: ["memory_usage", "battery"],
1102
- load: async () => (await import("./chunks/system-574MHB4R.ts")).collectSystem
1115
+ load: async () => (await import("./chunks/system-CDTPAQZX.ts")).collectSystem
1103
1116
  },
1104
1117
  {
1105
1118
  modules: ["nodejs", "python", "rust", "golang", "bun", "deno"],
1106
- load: async () => (await import("./chunks/languages-CBQNNYXM.ts")).collectLanguages
1119
+ load: async () => (await import("./chunks/languages-VWXTVJ45.ts")).collectLanguages
1107
1120
  },
1108
1121
  {
1109
1122
  modules: ["mise", "direnv", "pixi", "conda", "nix_shell", "guix_shell"],
1110
- load: async () => (await import("./chunks/development-T3XXVVDP.ts")).collectDevelopment
1123
+ load: async () => (await import("./chunks/development-TJNVM4H2.ts")).collectDevelopment
1111
1124
  },
1112
1125
  {
1113
1126
  modules: ["docker_context", "kubernetes", "terraform"],
1114
- load: async () => (await import("./chunks/deployment-NOJ2KCLI.ts")).collectDeployment
1127
+ load: async () => (await import("./chunks/deployment-KNUSQSJ5.ts")).collectDeployment
1115
1128
  },
1116
1129
  {
1117
1130
  modules: ["aws", "gcloud", "azure", "openstack"],
1118
- load: async () => (await import("./chunks/cloud-J2ZOE3HE.ts")).collectCloud
1131
+ load: async () => (await import("./chunks/cloud-CNNWXSQ3.ts")).collectCloud
1119
1132
  },
1120
1133
  {
1121
1134
  modules: ["container", "hostname", "os", "username"],
1122
- load: async () => (await import("./chunks/execution-R2OHIP2L.ts")).collectExecution
1135
+ load: async () => (await import("./chunks/execution-OFQXHFAH.ts")).collectExecution
1123
1136
  }
1124
1137
  ];
1125
1138
  var BUILT_IN_ONLY_MODULES = /* @__PURE__ */ new Set([
@@ -1174,15 +1187,18 @@ function summarizeFooterUsage(entries) {
1174
1187
  output: 0,
1175
1188
  cacheRead: 0,
1176
1189
  cacheWrite: 0,
1177
- cost: 0
1190
+ cost: 0,
1191
+ costTotalFromProvider: false
1178
1192
  };
1193
+ let hasUsage = false;
1194
+ let allTotalsFromProvider = true;
1179
1195
  for (const entry of entries) {
1180
1196
  let usage;
1181
1197
  if (entry.type === "message" && entry.message.role === "assistant") {
1182
1198
  usage = entry.message.usage;
1183
- const input = usage.input ?? 0;
1184
- const cacheRead = usage.cacheRead ?? 0;
1185
- const cacheWrite = usage.cacheWrite ?? 0;
1199
+ const input = usage?.input ?? 0;
1200
+ const cacheRead = usage?.cacheRead ?? 0;
1201
+ const cacheWrite = usage?.cacheWrite ?? 0;
1186
1202
  const promptTokens = input + cacheRead + cacheWrite;
1187
1203
  totals.latestCacheHitRate = promptTokens > 0 ? cacheRead / promptTokens * 100 : void 0;
1188
1204
  } else if (entry.type === "message" && entry.message.role === "toolResult") {
@@ -1196,7 +1212,11 @@ function summarizeFooterUsage(entries) {
1196
1212
  totals.cacheRead += usage.cacheRead ?? 0;
1197
1213
  totals.cacheWrite += usage.cacheWrite ?? 0;
1198
1214
  totals.cost += usage.cost?.total ?? 0;
1215
+ hasUsage = true;
1216
+ const cost = usage.cost;
1217
+ allTotalsFromProvider &&= cost?.totalFromProvider === true && typeof cost.total === "number" && Number.isFinite(cost.total) && cost.total >= 0;
1199
1218
  }
1219
+ totals.costTotalFromProvider = hasUsage && allTotalsFromProvider && Number.isFinite(totals.cost);
1200
1220
  return totals;
1201
1221
  }
1202
1222
 
@@ -1208,7 +1228,7 @@ var MAX_TIMER_DELAY_MS = 2147483647;
1208
1228
  var starshipCommandsPromise;
1209
1229
  function loadStarshipCommands() {
1210
1230
  if (!starshipCommandsPromise) {
1211
- starshipCommandsPromise = import("./chunks/commands-ZL36J5TX.ts").catch((error) => {
1231
+ starshipCommandsPromise = import("./chunks/commands-XIRYGV7S.ts").catch((error) => {
1212
1232
  starshipCommandsPromise = void 0;
1213
1233
  throw error;
1214
1234
  });
@@ -1310,6 +1330,7 @@ function piStarship(pi, options = {}) {
1310
1330
  eventDebounceTimer = void 0;
1311
1331
  requestRefresh(target);
1312
1332
  }, EVENT_DEBOUNCE_MS);
1333
+ eventDebounceTimer.unref();
1313
1334
  };
1314
1335
  function restartLocalControllers(target) {
1315
1336
  if (!loaded || isNativeFooter(loaded) || !isActiveTarget(target)) return;
@@ -1461,6 +1482,7 @@ function piStarship(pi, options = {}) {
1461
1482
  if (lines.length !== previousLines.length || lines.some((line, index) => line !== previousLines[index]))
1462
1483
  tui.requestRender();
1463
1484
  }, REFRESH_INTERVAL_MS) : void 0;
1485
+ timer?.unref();
1464
1486
  let disposed = false;
1465
1487
  const dispose = () => {
1466
1488
  if (disposed) return;