claude-scope 0.8.26 → 0.8.27

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.
@@ -1633,6 +1633,8 @@ var init_renderer = __esm({
1633
1633
  * on separate lines. Widgets that throw errors are logged (via onError
1634
1634
  * callback) and skipped, allowing other widgets to continue rendering.
1635
1635
  *
1636
+ * Empty lines are preserved to maintain correct line positioning.
1637
+ *
1636
1638
  * @param widgets - Array of widgets to render
1637
1639
  * @param context - Render context with width and timestamp
1638
1640
  * @returns Array of rendered lines (one per line number)
@@ -1649,9 +1651,9 @@ var init_renderer = __esm({
1649
1651
  }
1650
1652
  lineMap.get(line)?.push(widget);
1651
1653
  }
1652
- const lines = [];
1654
+ const lineOutputs = /* @__PURE__ */ new Map();
1653
1655
  const sortedLines = Array.from(lineMap.entries()).sort((a, b) => a[0] - b[0]);
1654
- for (const [, widgetsForLine] of sortedLines) {
1656
+ for (const [lineNum, widgetsForLine] of sortedLines) {
1655
1657
  const outputs = [];
1656
1658
  for (const widget of widgetsForLine) {
1657
1659
  try {
@@ -1667,10 +1669,10 @@ var init_renderer = __esm({
1667
1669
  }
1668
1670
  }
1669
1671
  const line = outputs.join(this.separator);
1670
- if (outputs.length > 0) {
1671
- lines.push(line);
1672
- }
1672
+ lineOutputs.set(lineNum, line);
1673
1673
  }
1674
+ const sortedEntries = Array.from(lineOutputs.entries()).sort((a, b) => a[0] - b[0]);
1675
+ const lines = sortedEntries.map(([, output]) => output);
1674
1676
  return lines;
1675
1677
  }
1676
1678
  /**
@@ -26242,6 +26244,40 @@ init_model_widget();
26242
26244
 
26243
26245
  // src/widgets/sysmon-widget.ts
26244
26246
  init_widget_types();
26247
+
26248
+ // src/providers/metrics-cache.ts
26249
+ var MetricsCache = class {
26250
+ cached = null;
26251
+ cacheTime = 0;
26252
+ ttlMs;
26253
+ constructor(ttlMs = 1e3) {
26254
+ this.ttlMs = ttlMs;
26255
+ }
26256
+ /**
26257
+ * Get cached metrics or fetch fresh if cache expired
26258
+ * @param fetcher - Function to fetch fresh metrics
26259
+ * @returns Cached or fresh metrics, or null if fetcher returns null
26260
+ */
26261
+ async get(fetcher) {
26262
+ const now = Date.now();
26263
+ if (this.cached && now - this.cacheTime < this.ttlMs) {
26264
+ return this.cached;
26265
+ }
26266
+ const fresh = await fetcher();
26267
+ this.cached = fresh;
26268
+ this.cacheTime = now;
26269
+ return fresh;
26270
+ }
26271
+ /**
26272
+ * Clear the cache
26273
+ */
26274
+ clear() {
26275
+ this.cached = null;
26276
+ this.cacheTime = 0;
26277
+ }
26278
+ };
26279
+
26280
+ // src/widgets/sysmon-widget.ts
26245
26281
  init_theme();
26246
26282
 
26247
26283
  // src/widgets/sysmon/styles.ts
@@ -26313,29 +26349,27 @@ var SysmonWidget = class {
26313
26349
  provider;
26314
26350
  _lineOverride;
26315
26351
  styleFn = sysmonStyles.balanced;
26316
- currentMetrics = null;
26317
- updateIntervalMs = 2500;
26318
- // 2.5 seconds
26352
+ cache;
26353
+ cacheTtlMs = 1e3;
26354
+ // 1 second cache
26319
26355
  enabled = true;
26320
26356
  constructor(colors2, provider) {
26321
26357
  this.colors = colors2 ?? DEFAULT_THEME;
26322
26358
  this.provider = provider ?? null;
26359
+ this.cache = new MetricsCache(this.cacheTtlMs);
26323
26360
  }
26324
26361
  async initialize(context) {
26325
26362
  this.enabled = context.config?.enabled !== false;
26326
- if (!this.provider || !this.enabled) {
26327
- return;
26328
- }
26329
- this.currentMetrics = await this.provider.getMetrics();
26330
- this.provider.startUpdate(this.updateIntervalMs, (metrics) => {
26331
- this.currentMetrics = metrics;
26332
- });
26333
26363
  }
26334
26364
  async render(_context) {
26335
- if (!this.currentMetrics || !this.isEnabled()) {
26365
+ if (!this.provider || !this.isEnabled()) {
26336
26366
  return null;
26337
26367
  }
26338
- return this.styleFn(this.currentMetrics, this.colors.sysmon);
26368
+ const metrics = await this.cache.get(() => this.provider.getMetrics());
26369
+ if (!metrics) {
26370
+ return null;
26371
+ }
26372
+ return this.styleFn(metrics, this.colors.sysmon);
26339
26373
  }
26340
26374
  async update(_data) {
26341
26375
  }
@@ -26343,7 +26377,7 @@ var SysmonWidget = class {
26343
26377
  return this.enabled && this.provider !== null;
26344
26378
  }
26345
26379
  async cleanup() {
26346
- this.provider?.stopUpdate();
26380
+ this.cache.clear();
26347
26381
  }
26348
26382
  setStyle(style = "balanced") {
26349
26383
  const fn = sysmonStyles[style];
@@ -26533,6 +26567,9 @@ var SystemProvider = class {
26533
26567
  this.logError(error);
26534
26568
  });
26535
26569
  }, intervalMs);
26570
+ if (this.intervalId && typeof this.intervalId.unref === "function") {
26571
+ this.intervalId.unref();
26572
+ }
26536
26573
  }
26537
26574
  stopUpdate() {
26538
26575
  if (this.intervalId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-scope",
3
- "version": "0.8.26",
3
+ "version": "0.8.27",
4
4
  "description": "Claude Code plugin for session status and analytics",
5
5
  "license": "MIT",
6
6
  "type": "module",