pi-ptc-meter 1.0.26 → 1.0.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.
- package/README.md +4 -4
- package/index.ts +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ pi install npm:pi-ptc-meter
|
|
|
56
56
|
|
|
57
57
|
## 作用(源码事实)
|
|
58
58
|
|
|
59
|
-
- `tool_call
|
|
59
|
+
- `tool_call`:顶层调用计数 +1(codemode 内层调用不另计;不拦截、不改调用)。
|
|
60
60
|
- `turn_end`:记录本轮次数与耗时(不落盘)。
|
|
61
61
|
- `agent_end`:每 run 落盘一行日志。
|
|
62
62
|
- `before_agent_start`:结算上一轮并以 `nextTurn` 尾部消息回灌——计数、耗时、偏差、基线中位、**缓存命中率**(仅当该轮有 usage 数据时出现;< 90% 标「低」)——(`display: false`)。
|
|
@@ -75,7 +75,7 @@ PTC 计量:上一轮 9 次工具调用 · 实际 34s · 命中 92% · 预计 8
|
|
|
75
75
|
```text
|
|
76
76
|
本轮开工前 ─ 声明「预计 N 次 / 预计 Ns」
|
|
77
77
|
↓
|
|
78
|
-
tool_call ─
|
|
78
|
+
tool_call ─ 仅顶层调用计数 +1
|
|
79
79
|
↓
|
|
80
80
|
turn_end ─ 记录实际次数与耗时 + 解析预计值
|
|
81
81
|
↓
|
|
@@ -163,7 +163,7 @@ Also: log `~/.pi/ptc-meter.jsonl` (1 MiB truncation, tail-preserving); no enviro
|
|
|
163
163
|
|
|
164
164
|
## What it does (source facts)
|
|
165
165
|
|
|
166
|
-
- `tool_call`: increments
|
|
166
|
+
- `tool_call`: increments the counter for top-level calls only (nested codemode calls are not counted separately; never intercepts or rewrites).
|
|
167
167
|
- `turn_end`: records calls and duration (no disk write).
|
|
168
168
|
- `agent_end`: writes one log line per run.
|
|
169
169
|
- `before_agent_start`: settles the previous turn and feeds back counts, duration, deviation, the baseline median and the **cache hit rate** (only when that turn reported usage; flagged low below 90%) as a `nextTurn` trailing message (`display: false`).
|
|
@@ -182,7 +182,7 @@ PTC metering: last turn 9 tool calls · 34s actual · 92% cache hit · estimated
|
|
|
182
182
|
```text
|
|
183
183
|
before the turn ─ declare: about N calls / Ns
|
|
184
184
|
↓
|
|
185
|
-
tool_call ─ counter +1
|
|
185
|
+
tool_call ─ top-level call: counter +1
|
|
186
186
|
↓
|
|
187
187
|
turn_end ─ record actual calls and duration + parse estimate
|
|
188
188
|
↓
|
package/index.ts
CHANGED
|
@@ -268,9 +268,13 @@ export default function ptcMeter(pi: ExtensionAPI) {
|
|
|
268
268
|
turns = 0;
|
|
269
269
|
turnStartedAt = Date.now();
|
|
270
270
|
});
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
271
|
+
// 计数:只计**顶层**调用 —— codemode 的内层 tools.X 也走本 hook(pi 的 _executeNestedToolCall
|
|
272
|
+
// 显式带 parentToolCallId),计进去会把一次往返记成 N 次(实测 21 次顶层被记成 53)。
|
|
273
|
+
pi.on("tool_call", async (event) => {
|
|
274
|
+
try {
|
|
275
|
+
if ((event as { parentToolCallId?: string } | undefined)?.parentToolCallId) return undefined;
|
|
276
|
+
callsThisTurn++;
|
|
277
|
+
} catch { /* 静默:计量不该影响调用 */ }
|
|
274
278
|
return undefined;
|
|
275
279
|
});
|
|
276
280
|
|