ccstatusline-zh 2.2.32 → 2.2.34

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.
@@ -1,21 +1,25 @@
1
1
  // src/utils/powerline-theme-index.ts
2
- function countPowerlineThemeSlots(entries) {
2
+ function assignPowerlineThemeSlots(widgets, startSlot = 0, isShown = () => true) {
3
3
  let previousVisibleWidget = null;
4
- let slotCount = 0;
5
- for (const entry of entries) {
6
- if (entry.widget.type === "separator" || entry.widget.type === "flex-separator") {
4
+ let nextSlot = startSlot;
5
+ const slots = widgets.map((widget, index) => {
6
+ if (widget.type === "separator" || widget.type === "flex-separator") {
7
7
  previousVisibleWidget = null;
8
- continue;
8
+ return null;
9
9
  }
10
- if (!entry.content) {
11
- continue;
10
+ if (!isShown(index)) {
11
+ return null;
12
12
  }
13
13
  if (!previousVisibleWidget?.merge) {
14
- slotCount++;
14
+ nextSlot++;
15
15
  }
16
- previousVisibleWidget = entry.widget;
17
- }
18
- return slotCount;
16
+ previousVisibleWidget = widget;
17
+ return nextSlot - 1;
18
+ });
19
+ return { slots, nextSlot };
20
+ }
21
+ function countPowerlineThemeSlots(entries) {
22
+ return assignPowerlineThemeSlots(entries.map((entry) => entry.widget), 0, (index) => Boolean(entries[index]?.content)).nextSlot;
19
23
  }
20
24
  function advanceGlobalPowerlineThemeIndex(currentIndex, entries) {
21
25
  return currentIndex + countPowerlineThemeSlots(entries);
@@ -60,4 +64,4 @@ function advanceGlobalSeparatorIndex(currentIndex, widgets, preRenderedWidgets)
60
64
  return currentIndex + countSeparatorSlots(widgets, preRenderedWidgets);
61
65
  }
62
66
 
63
- export { advanceGlobalPowerlineThemeIndex, advanceGlobalSeparatorIndex };
67
+ export { assignPowerlineThemeSlots, advanceGlobalPowerlineThemeIndex, advanceGlobalSeparatorIndex };
@@ -13,6 +13,8 @@ import {
13
13
  ZERO_COMPACTION_STATS,
14
14
  getPackageVersion,
15
15
  getTerminalWidth,
16
+ resolveExecutable,
17
+ sanitizeTerminalText,
16
18
  GIT_REVIEW_REFRESH_FLAG,
17
19
  refreshGitReviewCacheFromCli,
18
20
  buildConfigWarningBadge,
@@ -30,11 +32,11 @@ import {
30
32
  initConfigPath,
31
33
  loadSettings,
32
34
  saveSettings
33
- } from "./ccstatusline-xsgtxzjt.js";
35
+ } from "./ccstatusline-jp52tswn.js";
34
36
  import {
35
37
  advanceGlobalPowerlineThemeIndex,
36
38
  advanceGlobalSeparatorIndex
37
- } from "./ccstatusline-s1q4ap7d.js";
39
+ } from "./ccstatusline-rdsx5ab1.js";
38
40
 
39
41
  // src/types/StatusJSON.ts
40
42
  var CoercedNumberSchema = preprocess((value) => {
@@ -52,6 +54,11 @@ var RateLimitPeriodSchema = object({
52
54
  used_percentage: CoercedNumberSchema.nullable().optional(),
53
55
  resets_at: CoercedNumberSchema.nullable().optional()
54
56
  });
57
+ var SpendLimitSchema = RateLimitPeriodSchema.extend({
58
+ used_usd: CoercedNumberSchema.nullable().optional(),
59
+ limit_usd: CoercedNumberSchema.nullable().optional(),
60
+ period: string().nullable().optional()
61
+ });
55
62
  var StatusJSONSchema = looseObject({
56
63
  hook_event_name: string().optional(),
57
64
  session_id: string().optional(),
@@ -67,9 +74,9 @@ var StatusJSONSchema = looseObject({
67
74
  workspace: object({
68
75
  current_dir: string().optional(),
69
76
  project_dir: string().optional()
70
- }).optional(),
71
- version: string().optional(),
72
- output_style: object({ name: string().optional() }).optional(),
77
+ }).nullable().optional(),
78
+ version: string().nullable().optional(),
79
+ output_style: object({ name: string().optional() }).nullable().optional(),
73
80
  effort: object({ level: string().nullable().optional() }).nullable().optional(),
74
81
  cost: object({
75
82
  total_cost_usd: CoercedNumberSchema.optional(),
@@ -77,7 +84,7 @@ var StatusJSONSchema = looseObject({
77
84
  total_api_duration_ms: CoercedNumberSchema.optional(),
78
85
  total_lines_added: CoercedNumberSchema.optional(),
79
86
  total_lines_removed: CoercedNumberSchema.optional()
80
- }).optional(),
87
+ }).nullable().optional(),
81
88
  context_window: object({
82
89
  context_window_size: CoercedNumberSchema.nullable().optional(),
83
90
  total_input_tokens: CoercedNumberSchema.nullable().optional(),
@@ -106,7 +113,8 @@ var StatusJSONSchema = looseObject({
106
113
  five_hour: RateLimitPeriodSchema.optional(),
107
114
  seven_day: RateLimitPeriodSchema.optional(),
108
115
  seven_day_sonnet: RateLimitPeriodSchema.nullable().optional(),
109
- seven_day_opus: RateLimitPeriodSchema.nullable().optional()
116
+ seven_day_opus: RateLimitPeriodSchema.nullable().optional(),
117
+ spend_limit: SpendLimitSchema.nullable().optional()
110
118
  }).nullable().optional()
111
119
  });
112
120
 
@@ -122,12 +130,16 @@ var EMPTY = { totalInvocations: 0, uniqueSkills: [], lastSkill: null };
122
130
  function getSkillsDir() {
123
131
  return path.join(os.homedir(), ".cache", "ccstatusline", "skills");
124
132
  }
133
+ var SAFE_SESSION_ID = /^[A-Za-z0-9_-]+$/;
125
134
  function getSkillsFilePath(sessionId) {
135
+ if (!SAFE_SESSION_ID.test(sessionId)) {
136
+ return null;
137
+ }
126
138
  return path.join(getSkillsDir(), `skills-${sessionId}.jsonl`);
127
139
  }
128
140
  function getSkillsMetrics(sessionId) {
129
141
  const filePath = getSkillsFilePath(sessionId);
130
- if (!fs.existsSync(filePath)) {
142
+ if (!filePath || !fs.existsSync(filePath)) {
131
143
  return EMPTY;
132
144
  }
133
145
  try {
@@ -185,6 +197,9 @@ function handleHookInput(input) {
185
197
  return;
186
198
  }
187
199
  const filePath = getSkillsFilePath(sessionId);
200
+ if (!filePath) {
201
+ return;
202
+ }
188
203
  fs2.mkdirSync(path2.dirname(filePath), { recursive: true });
189
204
  const entry = JSON.stringify({
190
205
  timestamp: new Date().toISOString(),
@@ -206,7 +221,10 @@ var BASE_USAGE_WIDGET_TYPES = [
206
221
  "weekly-reset-timer",
207
222
  "extra-usage-utilization",
208
223
  "extra-usage-remaining",
209
- "extra-usage-used"
224
+ "extra-usage-used",
225
+ "extra-usage-daily-budget",
226
+ "spend-limit-usage",
227
+ "spend-limit-amount"
210
228
  ];
211
229
  var USAGE_WIDGET_TYPES = new Set([
212
230
  ...BASE_USAGE_WIDGET_TYPES,
@@ -218,6 +236,9 @@ var USAGE_DATA_FIELDS = [
218
236
  "weeklyUsage",
219
237
  "weeklyResetAt",
220
238
  ...WEEKLY_MODEL_USAGE_BUCKETS.flatMap((bucket) => [bucket.usageField, bucket.resetField]),
239
+ "spendLimitUsage",
240
+ "spendLimitUsedUsd",
241
+ "spendLimitLimitUsd",
221
242
  "extraUsageEnabled",
222
243
  "extraUsageLimit",
223
244
  "extraUsageUsed",
@@ -244,6 +265,11 @@ var USAGE_WIDGET_REQUIREMENTS = {
244
265
  "extra-usage-used": [
245
266
  { field: "extraUsageEnabled" },
246
267
  { field: "extraUsageUsed" }
268
+ ],
269
+ "extra-usage-daily-budget": [
270
+ { field: "extraUsageEnabled" },
271
+ { field: "extraUsageLimit" },
272
+ { field: "extraUsageUsed" }
247
273
  ]
248
274
  };
249
275
  var USAGE_CURSOR_REQUIREMENTS = {
@@ -333,7 +359,10 @@ function extractUsageDataFromRateLimits(rateLimits) {
333
359
  sessionUsage: rateLimits.five_hour?.used_percentage ?? undefined,
334
360
  sessionResetAt: epochSecondsToIsoString(rateLimits.five_hour?.resets_at),
335
361
  weeklyUsage: rateLimits.seven_day?.used_percentage ?? undefined,
336
- weeklyResetAt: epochSecondsToIsoString(rateLimits.seven_day?.resets_at)
362
+ weeklyResetAt: epochSecondsToIsoString(rateLimits.seven_day?.resets_at),
363
+ spendLimitUsage: rateLimits.spend_limit?.used_percentage ?? undefined,
364
+ spendLimitUsedUsd: rateLimits.spend_limit?.used_usd ?? undefined,
365
+ spendLimitLimitUsd: rateLimits.spend_limit?.limit_usd ?? undefined
337
366
  };
338
367
  for (const bucket of WEEKLY_MODEL_USAGE_BUCKETS) {
339
368
  if (!bucket.apiBucketKey) {
@@ -363,6 +392,17 @@ async function prefetchUsageDataIfNeeded(lines, data) {
363
392
  return mergeUsageData(rateLimitsData, apiData);
364
393
  }
365
394
 
395
+ // src/utils/windows-code-page.ts
396
+ import { execFileSync } from "node:child_process";
397
+ function ensureWindowsUtf8CodePage(platform = process.platform) {
398
+ if (platform !== "win32") {
399
+ return;
400
+ }
401
+ try {
402
+ execFileSync(resolveExecutable("chcp.com"), ["65001"], { stdio: "ignore", windowsHide: true });
403
+ } catch {}
404
+ }
405
+
366
406
  // src/ccstatusline.ts
367
407
  function hasSessionDurationInStatusJson(data) {
368
408
  const durationMs = data.cost?.total_duration_ms;
@@ -390,15 +430,6 @@ async function readStdin() {
390
430
  return null;
391
431
  }
392
432
  }
393
- async function ensureWindowsUtf8CodePage() {
394
- if (process.platform !== "win32") {
395
- return;
396
- }
397
- try {
398
- const { execFileSync } = await import("node:child_process");
399
- execFileSync("chcp.com", ["65001"], { stdio: "ignore", windowsHide: true });
400
- } catch {}
401
- }
402
433
  async function renderMultipleLines(data) {
403
434
  const settings = await loadSettings();
404
435
  const configError = getConfigLoadError();
@@ -489,7 +520,7 @@ async function renderMultipleLines(data) {
489
520
  line = `${buildConfigWarningBadge(settings.colorLevel)} | ${line}`;
490
521
  configBadgePrepended = true;
491
522
  }
492
- let outputLine = line.replace(/ /g, " ");
523
+ let outputLine = sanitizeTerminalText(line).replace(/ /g, " ");
493
524
  outputLine = "\x1B[0m" + outputLine;
494
525
  console.log(outputLine);
495
526
  globalSeparatorIndex = advanceGlobalSeparatorIndex(globalSeparatorIndex, lineItems, preRenderedWidgets);
@@ -506,7 +537,7 @@ async function renderMultipleLines(data) {
506
537
  console.log("\x1B[0m" + buildConfigWarningBadge(settings.colorLevel).replace(/ /g, " "));
507
538
  }
508
539
  if (settings.updatemessage?.message && settings.updatemessage.message.trim() !== "" && settings.updatemessage.remaining && settings.updatemessage.remaining > 0) {
509
- console.log(settings.updatemessage.message);
540
+ console.log(sanitizeTerminalText(settings.updatemessage.message));
510
541
  const newRemaining = settings.updatemessage.remaining - 1;
511
542
  if (newRemaining <= 0) {
512
543
  const { updatemessage, ...newSettings } = settings;
@@ -566,7 +597,7 @@ async function main() {
566
597
  return;
567
598
  }
568
599
  if (!process.stdin.isTTY) {
569
- await ensureWindowsUtf8CodePage();
600
+ ensureWindowsUtf8CodePage();
570
601
  const input = await readStdin();
571
602
  if (input && input.trim() !== "") {
572
603
  try {
@@ -590,7 +621,7 @@ async function main() {
590
621
  const { updatemessage, ...newSettings } = settings;
591
622
  await saveSettings(newSettings);
592
623
  }
593
- const { runTUI } = await import("./index-3881ds5x.js");
624
+ const { runTUI } = await import("./index-pzts8765.js");
594
625
  runTUI();
595
626
  }
596
627
  }