pi-ptc-meter 1.0.23 → 1.0.25
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.en.md +4 -35
- package/README.md +18 -2
- package/index.ts +2 -2
- package/package.json +14 -4
package/README.en.md
CHANGED
|
@@ -1,40 +1,9 @@
|
|
|
1
1
|
# pi-ptc-meter
|
|
2
2
|
|
|
3
|
-
Per-turn tool-call metering
|
|
3
|
+
Per-turn tool-call metering, fed back to the model in a tail message.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**English documentation:** [open the English section](README.md#english) · **中文文档:** [中文](README.md#zh)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
pi install npm:pi-ptc-meter
|
|
9
|
-
```
|
|
7
|
+
pi install npm:pi-ptc-meter
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Config file `~/.pi/ptc-meter.json` (optional; invalid JSON falls back):
|
|
14
|
-
|
|
15
|
-
| Key | Default | Description |
|
|
16
|
-
| --- | --- | --- |
|
|
17
|
-
| `threshold` | `39` | Per-turn call threshold (> 0) |
|
|
18
|
-
| `inject` | `true` | Enable the feedback message |
|
|
19
|
-
| `notify` | `false` | Use UI notifications instead |
|
|
20
|
-
|
|
21
|
-
Also: log `~/.pi/ptc-meter.jsonl` (1 MiB truncation, tail-preserving); no environment variables.
|
|
22
|
-
|
|
23
|
-
## Commands
|
|
24
|
-
|
|
25
|
-
| Command | Purpose |
|
|
26
|
-
| --- | --- |
|
|
27
|
-
| `/ptc [n]` | Last n turns: counts, duration, estimates, median, over-threshold |
|
|
28
|
-
|
|
29
|
-
## What it does (source facts)
|
|
30
|
-
|
|
31
|
-
- `tool_call`: increments a counter (never intercepts or rewrites).
|
|
32
|
-
- `turn_end`: records calls and duration (no disk write).
|
|
33
|
-
- `agent_end`: writes one log line per run.
|
|
34
|
-
- `before_agent_start`: settles the previous turn and feeds back counts, duration, deviation and the baseline median as a `nextTurn` trailing message.
|
|
35
|
-
- `session_start`: resets module-level counters.
|
|
36
|
-
- The `ptc_meter` system section holds only a byte-stable skeleton.
|
|
37
|
-
|
|
38
|
-
## License
|
|
39
|
-
|
|
40
|
-
MIT
|
|
9
|
+
Source: https://github.com/op15066212/pi-plugins-publish
|
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
# pi-ptc-meter
|
|
9
9
|
|
|
10
|
+
> 适用 pi ≥ 0.74 · Node ≥ 20 · MIT · 无运行时依赖(仅 peer: @earendil-works/pi-coding-agent)
|
|
11
|
+
|
|
10
12
|
每轮工具调用计量:记录调用次数与耗时,与开工前声明的估算对比后,把实际值与偏差回灌给模型。
|
|
11
13
|
|
|
12
14
|
## 快速事实
|
|
@@ -57,7 +59,14 @@ pi install npm:pi-ptc-meter
|
|
|
57
59
|
- `tool_call`:计数 +1(不拦截、不改调用)。
|
|
58
60
|
- `turn_end`:记录本轮次数与耗时(不落盘)。
|
|
59
61
|
- `agent_end`:每 run 落盘一行日志。
|
|
60
|
-
- `before_agent_start`:结算上一轮并以 `nextTurn`
|
|
62
|
+
- `before_agent_start`:结算上一轮并以 `nextTurn` 尾部消息回灌——计数、耗时、偏差、基线中位、**缓存命中率**(仅当该轮有 usage 数据时出现;< 90% 标「低」)——(`display: false`)。
|
|
63
|
+
|
|
64
|
+
**注入样例(示意,字段可能随版本增删)**
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
PTC 计量:上一轮 9 次工具调用 · 实际 34s · 命中 92% · 预计 8 次 / 实际 9 次(偏差 +13%)
|
|
68
|
+
· 会话中位 25 · 阈值 50 · 判据 = 本轮计数不超阈值且无同类调用可并
|
|
69
|
+
```
|
|
61
70
|
- `session_start`:模块级计量归零。
|
|
62
71
|
- system 内 section `ptc_meter` 只含逐字不变的骨架。
|
|
63
72
|
|
|
@@ -146,7 +155,14 @@ Also: log `~/.pi/ptc-meter.jsonl` (1 MiB truncation, tail-preserving); no enviro
|
|
|
146
155
|
- `tool_call`: increments a counter (never intercepts or rewrites).
|
|
147
156
|
- `turn_end`: records calls and duration (no disk write).
|
|
148
157
|
- `agent_end`: writes one log line per run.
|
|
149
|
-
- `before_agent_start`: settles the previous turn and feeds back counts, duration, deviation
|
|
158
|
+
- `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`).
|
|
159
|
+
|
|
160
|
+
**Sample injection (illustrative; fields may change between versions)**
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
PTC metering: last turn 9 tool calls · 34s actual · 92% cache hit · estimated 8 / actual 9 (+13%)
|
|
164
|
+
· session median 25 · threshold 50 · verdict: under threshold, no obvious merge candidates
|
|
165
|
+
```
|
|
150
166
|
- `session_start`: resets module-level counters.
|
|
151
167
|
- The `ptc_meter` system section holds only a byte-stable skeleton.
|
|
152
168
|
|
package/index.ts
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
*
|
|
31
31
|
* ## 配置
|
|
32
32
|
* `~/.pi/ptc-meter.json`:{ "threshold": 39, "notify": false, "inject": true }
|
|
33
|
-
* threshold 超标线 · **notify 超标时弹窗(默认关**——反馈走 section 注入,弹窗只在你想被打扰时才开)· inject
|
|
33
|
+
* threshold 超标线 · **notify 超标时弹窗(默认关**——反馈走 section 注入,弹窗只在你想被打扰时才开)· inject 是否注入尾部回灌消息(关掉就退回纯计量)
|
|
34
34
|
*/
|
|
35
35
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
36
36
|
import { appendFileSync, closeSync, existsSync, openSync, readFileSync, readSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -103,7 +103,7 @@ function sidOf(ctx: ExtensionContext): string {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
|
|
106
|
-
type Row = { calls: number; ms: number; est: number | null; estCalls
|
|
106
|
+
type Row = { calls: number; ms: number; est: number | null; estCalls: number | null };
|
|
107
107
|
|
|
108
108
|
/** 只读文件尾部至多 maxBytes 字节并按行切分;起点不在文件头时丢弃首行残片。 */
|
|
109
109
|
function tailText(file: string, maxBytes: number): string {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ptc-meter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"description": "Measures tool-call batching per turn and feeds the numbers back to the model.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,11 @@
|
|
|
8
8
|
"pi",
|
|
9
9
|
"pi-extension",
|
|
10
10
|
"pi-coding-agent",
|
|
11
|
-
"pi-package"
|
|
11
|
+
"pi-package",
|
|
12
|
+
"metrics",
|
|
13
|
+
"tool-calls",
|
|
14
|
+
"observability",
|
|
15
|
+
"benchmarking"
|
|
12
16
|
],
|
|
13
17
|
"pi": {
|
|
14
18
|
"extensions": [
|
|
@@ -24,8 +28,11 @@
|
|
|
24
28
|
"peerDependencies": {
|
|
25
29
|
"@earendil-works/pi-coding-agent": "*"
|
|
26
30
|
},
|
|
27
|
-
"author":
|
|
28
|
-
|
|
31
|
+
"author": {
|
|
32
|
+
"name": "15066212pp",
|
|
33
|
+
"url": "https://github.com/op15066212"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/op15066212/pi-plugins-publish/tree/main/pi-ptc-meter#readme",
|
|
29
36
|
"bugs": {
|
|
30
37
|
"url": "https://github.com/op15066212/pi-plugins-publish/issues"
|
|
31
38
|
},
|
|
@@ -36,5 +43,8 @@
|
|
|
36
43
|
},
|
|
37
44
|
"scripts": {
|
|
38
45
|
"prepublishOnly": "node ../publish-check.mjs"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=20"
|
|
39
49
|
}
|
|
40
50
|
}
|