claude-scope 0.8.39 → 0.8.41

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.
@@ -2956,16 +2956,17 @@ var init_cache_metrics_widget = __esm({
2956
2956
  */
2957
2957
  async update(data) {
2958
2958
  await super.update(data);
2959
- const sessionChanged = this.lastSessionId && this.lastSessionId !== data.session_id;
2959
+ const sessionId = data.session_id;
2960
+ const sessionChanged = this.lastSessionId && this.lastSessionId !== sessionId;
2960
2961
  if (sessionChanged) {
2961
2962
  this.renderData = void 0;
2962
2963
  }
2963
- this.lastSessionId = data.session_id;
2964
+ this.lastSessionId = sessionId;
2964
2965
  const usage = data.context_window?.current_usage;
2965
- if (usage && !sessionChanged) {
2966
+ if (usage && !sessionChanged && sessionId) {
2966
2967
  const hasAnyTokens = (usage.input_tokens ?? 0) > 0 || (usage.output_tokens ?? 0) > 0 || (usage.cache_creation_input_tokens ?? 0) > 0 || (usage.cache_read_input_tokens ?? 0) > 0;
2967
2968
  if (hasAnyTokens) {
2968
- this.cacheManager.setCachedUsage(data.session_id, {
2969
+ this.cacheManager.setCachedUsage(sessionId, {
2969
2970
  input_tokens: usage.input_tokens,
2970
2971
  output_tokens: usage.output_tokens,
2971
2972
  cache_creation_input_tokens: usage.cache_creation_input_tokens,
@@ -2974,12 +2975,17 @@ var init_cache_metrics_widget = __esm({
2974
2975
  }
2975
2976
  }
2976
2977
  const hasRealUsage = usage && ((usage.input_tokens ?? 0) > 0 || (usage.output_tokens ?? 0) > 0 || (usage.cache_read_input_tokens ?? 0) > 0 || (usage.cache_creation_input_tokens ?? 0) > 0);
2978
+ const transcriptPath = data.transcript_path;
2977
2979
  if (!usage || !hasRealUsage) {
2978
- this.cachedUsage = await this.usageParser.parseLastUsage(data.transcript_path);
2980
+ if (transcriptPath) {
2981
+ this.cachedUsage = await this.usageParser.parseLastUsage(transcriptPath);
2982
+ }
2979
2983
  } else {
2980
2984
  this.cachedUsage = void 0;
2981
2985
  }
2982
- this.cachedCumulativeCache = await this.usageParser.parseCumulativeCache(data.transcript_path);
2986
+ if (transcriptPath) {
2987
+ this.cachedCumulativeCache = await this.usageParser.parseCumulativeCache(transcriptPath);
2988
+ }
2983
2989
  }
2984
2990
  /**
2985
2991
  * Render the cache metrics display
@@ -2990,14 +2996,14 @@ var init_cache_metrics_widget = __esm({
2990
2996
  if ((!usage || !hasRealUsage) && this.cachedUsage) {
2991
2997
  usage = this.cachedUsage;
2992
2998
  }
2993
- if (!usage) {
2999
+ if (!usage && data.session_id) {
2994
3000
  const cached = this.cacheManager.getCachedUsage(data.session_id);
2995
3001
  if (cached) {
2996
3002
  usage = cached.usage;
2997
3003
  }
2998
3004
  }
2999
3005
  const cumulativeCacheToUse = this.cachedCumulativeCache;
3000
- const metrics = this.calculateMetrics(usage, cumulativeCacheToUse);
3006
+ const metrics = this.calculateMetrics(usage || null, cumulativeCacheToUse || null);
3001
3007
  if (!metrics) {
3002
3008
  return null;
3003
3009
  }
@@ -3534,13 +3540,18 @@ var init_context_widget = __esm({
3534
3540
  */
3535
3541
  async update(data) {
3536
3542
  await super.update(data);
3537
- const sessionChanged = this.lastSessionId && this.lastSessionId !== data.session_id;
3538
- this.lastSessionId = data.session_id;
3539
- const { current_usage } = data.context_window;
3540
- if (current_usage && !sessionChanged) {
3543
+ const contextWindow = data.context_window;
3544
+ if (!contextWindow) {
3545
+ return;
3546
+ }
3547
+ const sessionId = data.session_id;
3548
+ const sessionChanged = this.lastSessionId && this.lastSessionId !== sessionId;
3549
+ this.lastSessionId = sessionId;
3550
+ const { current_usage } = contextWindow;
3551
+ if (current_usage && !sessionChanged && sessionId) {
3541
3552
  const hasAnyTokens = (current_usage.input_tokens ?? 0) > 0 || (current_usage.output_tokens ?? 0) > 0 || (current_usage.cache_creation_input_tokens ?? 0) > 0 || (current_usage.cache_read_input_tokens ?? 0) > 0;
3542
3553
  if (hasAnyTokens) {
3543
- this.cacheManager.setCachedUsage(data.session_id, {
3554
+ this.cacheManager.setCachedUsage(sessionId, {
3544
3555
  input_tokens: current_usage.input_tokens,
3545
3556
  output_tokens: current_usage.output_tokens,
3546
3557
  cache_creation_input_tokens: current_usage.cache_creation_input_tokens,
@@ -3550,37 +3561,53 @@ var init_context_widget = __esm({
3550
3561
  }
3551
3562
  const hasRealUsage = current_usage && ((current_usage.input_tokens ?? 0) > 0 || (current_usage.output_tokens ?? 0) > 0 || (current_usage.cache_read_input_tokens ?? 0) > 0 || (current_usage.cache_creation_input_tokens ?? 0) > 0);
3552
3563
  if (!current_usage || !hasRealUsage) {
3553
- this.cachedUsage = await this.usageParser.parseLastUsage(data.transcript_path);
3564
+ const transcriptPath = data.transcript_path;
3565
+ if (transcriptPath) {
3566
+ this.cachedUsage = await this.usageParser.parseLastUsage(transcriptPath);
3567
+ }
3554
3568
  } else {
3555
3569
  this.cachedUsage = void 0;
3556
3570
  }
3557
3571
  }
3558
3572
  renderWithData(data, _context) {
3559
- const { current_usage, context_window_size } = data.context_window;
3573
+ const contextWindow = data.context_window || {};
3574
+ const current_usage = contextWindow.current_usage;
3575
+ const context_window_size = contextWindow.context_window_size;
3576
+ const used_percentage = contextWindow.used_percentage;
3577
+ if (used_percentage !== void 0) {
3578
+ const renderData2 = {
3579
+ used: 0,
3580
+ // Will be calculated from percentage
3581
+ contextWindowSize: context_window_size || 2e5,
3582
+ percent: Math.round(used_percentage)
3583
+ };
3584
+ return this.styleFn(renderData2, this.colors.context);
3585
+ }
3560
3586
  let usage = current_usage;
3561
3587
  const hasRealUsage = usage && ((usage.input_tokens ?? 0) > 0 || (usage.output_tokens ?? 0) > 0 || (usage.cache_read_input_tokens ?? 0) > 0 || (usage.cache_creation_input_tokens ?? 0) > 0);
3562
3588
  if ((!usage || !hasRealUsage) && this.cachedUsage) {
3563
3589
  usage = this.cachedUsage;
3564
3590
  }
3565
- if (!usage) {
3591
+ if (!usage && data.session_id) {
3566
3592
  const cached = this.cacheManager.getCachedUsage(data.session_id);
3567
3593
  if (cached) {
3568
3594
  usage = cached.usage;
3569
3595
  }
3570
3596
  }
3597
+ const ctxSize = context_window_size || 2e5;
3571
3598
  if (!usage) {
3572
3599
  const renderData2 = {
3573
3600
  used: 0,
3574
- contextWindowSize: context_window_size,
3601
+ contextWindowSize: ctxSize,
3575
3602
  percent: 0
3576
3603
  };
3577
3604
  return this.styleFn(renderData2, this.colors.context);
3578
3605
  }
3579
- const used = usage.input_tokens + usage.cache_creation_input_tokens + usage.cache_read_input_tokens;
3580
- const percent = Math.round(used / context_window_size * 100);
3606
+ const used = (usage.input_tokens || 0) + (usage.cache_creation_input_tokens || 0) + (usage.cache_read_input_tokens || 0);
3607
+ const percent = Math.round(used / ctxSize * 100);
3581
3608
  const renderData = {
3582
3609
  used,
3583
- contextWindowSize: context_window_size,
3610
+ contextWindowSize: ctxSize,
3584
3611
  percent
3585
3612
  };
3586
3613
  return this.styleFn(renderData, this.colors.context);
@@ -3940,7 +3967,7 @@ var init_dev_server_widget = __esm({
3940
3967
  * @param data - Stdin data from Claude Code
3941
3968
  */
3942
3969
  async update(data) {
3943
- this.cwd = data.cwd;
3970
+ this.cwd = data.cwd || null;
3944
3971
  }
3945
3972
  /**
3946
3973
  * Check if widget is enabled
@@ -4468,7 +4495,7 @@ var init_git_tag_widget = __esm({
4468
4495
  }
4469
4496
  }
4470
4497
  async update(data) {
4471
- if (data.cwd !== this.cwd) {
4498
+ if (data.cwd && data.cwd !== this.cwd) {
4472
4499
  this.cwd = data.cwd;
4473
4500
  this.git = this.gitFactory(data.cwd);
4474
4501
  }
@@ -4662,7 +4689,7 @@ var init_git_widget = __esm({
4662
4689
  }
4663
4690
  }
4664
4691
  async update(data) {
4665
- if (data.cwd !== this.cwd) {
4692
+ if (data.cwd && data.cwd !== this.cwd) {
4666
4693
  this.cwd = data.cwd;
4667
4694
  this.git = this.gitFactory(data.cwd);
4668
4695
  }
@@ -4870,6 +4897,9 @@ var init_model_widget = __esm({
4870
4897
  return this._lineOverride ?? this.metadata.line ?? 0;
4871
4898
  }
4872
4899
  renderWithData(data, _context) {
4900
+ if (!data.model) {
4901
+ return null;
4902
+ }
4873
4903
  const renderData = {
4874
4904
  displayName: data.model.display_name,
4875
4905
  id: data.model.id
@@ -4915,7 +4945,9 @@ function createDemoData() {
4915
4945
  output_tokens: DEMO_DATA.CURRENT_OUTPUT_TOKENS,
4916
4946
  cache_creation_input_tokens: DEMO_DATA.CACHE_CREATION_TOKENS,
4917
4947
  cache_read_input_tokens: DEMO_DATA.CACHE_READ_TOKENS
4918
- }
4948
+ },
4949
+ used_percentage: 37.5,
4950
+ remaining_percentage: 62.5
4919
4951
  }
4920
4952
  };
4921
4953
  }
@@ -27746,6 +27778,15 @@ var ContextUsageSchema = object({
27746
27778
  cache_creation_input_tokens: number(),
27747
27779
  cache_read_input_tokens: number()
27748
27780
  });
27781
+ var ContextWindowSchema = object({
27782
+ total_input_tokens: optional(number()),
27783
+ total_output_tokens: optional(number()),
27784
+ context_window_size: optional(number()),
27785
+ current_usage: nullable(ContextUsageSchema),
27786
+ // Pre-calculated percentages from Claude Code (available in newer versions)
27787
+ used_percentage: optional(number()),
27788
+ remaining_percentage: optional(number())
27789
+ });
27749
27790
  var CostInfoSchema = object({
27750
27791
  total_cost_usd: optional(number()),
27751
27792
  total_duration_ms: optional(number()),
@@ -27753,12 +27794,6 @@ var CostInfoSchema = object({
27753
27794
  total_lines_added: optional(number()),
27754
27795
  total_lines_removed: optional(number())
27755
27796
  });
27756
- var ContextWindowSchema = object({
27757
- total_input_tokens: number(),
27758
- total_output_tokens: number(),
27759
- context_window_size: number(),
27760
- current_usage: nullable(ContextUsageSchema)
27761
- });
27762
27797
  var ModelInfoSchema = object({
27763
27798
  id: string(),
27764
27799
  display_name: string()
@@ -27772,15 +27807,15 @@ var OutputStyleSchema = object({
27772
27807
  });
27773
27808
  var StdinDataSchema = object({
27774
27809
  hook_event_name: optional(literal("Status")),
27775
- session_id: string(),
27776
- transcript_path: string(),
27777
- cwd: string(),
27778
- model: ModelInfoSchema,
27779
- workspace: WorkspaceSchema,
27780
- version: string(),
27781
- output_style: OutputStyleSchema,
27810
+ session_id: optional(string()),
27811
+ transcript_path: optional(string()),
27812
+ cwd: optional(string()),
27813
+ model: optional(ModelInfoSchema),
27814
+ workspace: optional(WorkspaceSchema),
27815
+ version: optional(string()),
27816
+ output_style: optional(OutputStyleSchema),
27782
27817
  cost: optional(CostInfoSchema),
27783
- context_window: ContextWindowSchema
27818
+ context_window: optional(ContextWindowSchema)
27784
27819
  });
27785
27820
 
27786
27821
  // src/data/stdin-provider.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-scope",
3
- "version": "0.8.39",
3
+ "version": "0.8.41",
4
4
  "description": "Claude Code plugin for session status and analytics",
5
5
  "license": "MIT",
6
6
  "type": "module",