linkshell-cli 0.5.16 → 0.5.17

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.
@@ -108,4 +108,5 @@ export declare class AgentWorkspaceProxy {
108
108
  private cancelPendingPermissions;
109
109
  private extractSessionId;
110
110
  private extractTurnId;
111
+ private sendUsageReport;
111
112
  }
@@ -1419,6 +1419,7 @@ export class AgentWorkspaceProxy {
1419
1419
  case "agent.v2.capabilities.request":
1420
1420
  await this.initialize();
1421
1421
  this.sendCapabilities();
1422
+ this.sendUsageReport();
1422
1423
  break;
1423
1424
  case "agent.v2.conversation.open": {
1424
1425
  const payload = parseTypedPayload("agent.v2.conversation.open", envelope.payload);
@@ -1485,23 +1486,7 @@ export class AgentWorkspaceProxy {
1485
1486
  break;
1486
1487
  }
1487
1488
  case "agent.v2.usage.request": {
1488
- // Aggregate ALL on-disk transcripts (decoupled from live turns). The
1489
- // scan is synchronous (~3s over a large corpus); acceptable for an
1490
- // explicit, on-demand dashboard open. Errors must never break the
1491
- // session, so swallow + send an empty report.
1492
- try {
1493
- const report = aggregateUsage();
1494
- this.input.send(createEnvelope({
1495
- type: "agent.v2.usage.report",
1496
- sessionId: this.input.sessionId,
1497
- payload: report,
1498
- }));
1499
- }
1500
- catch (error) {
1501
- if (this.input.verbose) {
1502
- process.stderr.write(`[agent:v2] usage aggregation failed: ${error instanceof Error ? error.message : String(error)}\n`);
1503
- }
1504
- }
1489
+ this.sendUsageReport();
1505
1490
  break;
1506
1491
  }
1507
1492
  case "agent.v2.prompt": {
@@ -3788,6 +3773,27 @@ export class AgentWorkspaceProxy {
3788
3773
  }
3789
3774
  return firstString(raw, ["turnId", "id"]);
3790
3775
  }
3776
+ // Fire-and-forget usage report — sent on init so the session list page shows
3777
+ // summary cards without anyone clicking a button. First call scans disk (~3s)
3778
+ // so it's deferred off the handler's critical path; cached (60s TTL)
3779
+ // thereafter. Errors silently swallowed (best-effort, never blocks).
3780
+ sendUsageReport() {
3781
+ setTimeout(() => {
3782
+ try {
3783
+ const report = aggregateUsage();
3784
+ this.input.send(createEnvelope({
3785
+ type: "agent.v2.usage.report",
3786
+ sessionId: this.input.sessionId,
3787
+ payload: report,
3788
+ }));
3789
+ }
3790
+ catch (error) {
3791
+ if (this.input.verbose) {
3792
+ process.stderr.write(`[agent:v2] usage aggregation failed: ${error instanceof Error ? error.message : String(error)}\n`);
3793
+ }
3794
+ }
3795
+ }, 0);
3796
+ }
3791
3797
  }
3792
3798
  function parsePermissionOptions(value) {
3793
3799
  if (!Array.isArray(value)) {