@dreb/coding-agent 2.15.2 → 2.16.0

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.
@@ -13,6 +13,7 @@
13
13
  * Modes use this class and add their own I/O layer on top.
14
14
  */
15
15
  import { copyFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
16
+ import { tmpdir } from "node:os";
16
17
  import { basename, dirname, join, resolve } from "node:path";
17
18
  import { isContextOverflow, modelsAreEqual, resetApiProviders, supportsXhigh } from "@dreb/ai";
18
19
  import { getDocsPath } from "../config.js";
@@ -26,6 +27,7 @@ import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
26
27
  import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
27
28
  import { checkScriptContent, extractScriptPaths, isForbiddenCommand } from "./forbidden-commands.js";
28
29
  import { getGitRepoState } from "./git-repo-state.js";
30
+ import { PerformanceTracker } from "./performance-tracker.js";
29
31
  import { expandPromptTemplate } from "./prompt-templates.js";
30
32
  import { scrubSecrets } from "./secret-scrubber.js";
31
33
  import { isSensitivePath } from "./sensitive-paths.js";
@@ -57,6 +59,7 @@ export function parseSkillBlock(text) {
57
59
  const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high"];
58
60
  /** Thinking levels including xhigh (for supported models) */
59
61
  const THINKING_LEVELS_WITH_XHIGH = ["off", "minimal", "low", "medium", "high", "xhigh"];
62
+ const MIN_PERFORMANCE_DURATION_MS = 10;
60
63
  // ============================================================================
61
64
  // AgentSession Class
62
65
  // ============================================================================
@@ -125,12 +128,27 @@ export class AgentSession {
125
128
  // Base system prompt (without extension appends) - used to apply fresh appends each turn
126
129
  _baseSystemPrompt = "";
127
130
  _uiType;
131
+ performanceTracker;
132
+ _ownsPerformanceTracker;
128
133
  // Git repo state captured once at session start
129
134
  _gitRepoState;
130
135
  constructor(config) {
131
136
  this.agent = config.agent;
132
137
  this.sessionManager = config.sessionManager;
133
138
  this.settingsManager = config.settingsManager;
139
+ if (config.performanceTracker !== undefined) {
140
+ this.performanceTracker = config.performanceTracker;
141
+ this._ownsPerformanceTracker = false;
142
+ }
143
+ else if (process.env.VITEST) {
144
+ // In tests, use an isolated temp log to avoid polluting the real performance log
145
+ this.performanceTracker = new PerformanceTracker(join(tmpdir(), `dreb-perf-${Date.now()}-${Math.random().toString(36).slice(2)}.jsonl`));
146
+ this._ownsPerformanceTracker = true;
147
+ }
148
+ else {
149
+ this.performanceTracker = new PerformanceTracker();
150
+ this._ownsPerformanceTracker = true;
151
+ }
134
152
  this._scopedModels = config.scopedModels ?? [];
135
153
  this._resourceLoader = config.resourceLoader;
136
154
  this._customTools = config.customTools ?? [];
@@ -156,6 +174,10 @@ export class AgentSession {
156
174
  get modelRegistry() {
157
175
  return this._modelRegistry;
158
176
  }
177
+ /** Performance tracker for recording and querying model throughput */
178
+ getPerformanceTracker() {
179
+ return this.performanceTracker;
180
+ }
159
181
  /**
160
182
  * Install tool hooks once on the Agent instance.
161
183
  *
@@ -607,6 +629,21 @@ export class AgentSession {
607
629
  });
608
630
  this._retryAttempt = 0;
609
631
  }
632
+ const durationMs = assistantMsg.durationMs ?? 0;
633
+ if (assistantMsg.stopReason !== "error" &&
634
+ assistantMsg.stopReason !== "aborted" &&
635
+ assistantMsg.usage.output > 0 &&
636
+ durationMs >= MIN_PERFORMANCE_DURATION_MS) {
637
+ this.performanceTracker.record({
638
+ timestamp: new Date().toISOString(),
639
+ sessionId: this.sessionId,
640
+ provider: assistantMsg.provider,
641
+ modelId: assistantMsg.model,
642
+ outputTokens: assistantMsg.usage.output,
643
+ durationMs,
644
+ tps: (assistantMsg.usage.output * 1000) / durationMs,
645
+ });
646
+ }
610
647
  }
611
648
  }
612
649
  // Check auto-retry and auto-compaction after agent completes
@@ -782,6 +819,9 @@ export class AgentSession {
782
819
  */
783
820
  dispose() {
784
821
  this._disconnectFromAgent();
822
+ if (this._ownsPerformanceTracker) {
823
+ this.performanceTracker.dispose();
824
+ }
785
825
  this._eventListeners = [];
786
826
  }
787
827
  // =========================================================================