pi-ptc-meter 1.0.23 → 1.0.24

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 CHANGED
@@ -1,40 +1,9 @@
1
1
  # pi-ptc-meter
2
2
 
3
- Per-turn tool-call metering: counts calls and duration, then feeds the numbers back to the model.
3
+ Per-turn tool-call metering, fed back to the model in a tail message.
4
4
 
5
- ## Install
5
+ **English documentation:** [open the English section](README.md#english) · **中文文档:** [中文](README.md#zh)
6
6
 
7
- ```bash
8
- pi install npm:pi-ptc-meter
9
- ```
7
+ pi install npm:pi-ptc-meter
10
8
 
11
- ## Configuration
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 and the baseline median as a `nextTurn` trailing message.
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 是否写 section(关掉就退回纯计量)
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?: number | null };
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.23",
3
+ "version": "1.0.24",
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": [
@@ -25,7 +29,7 @@
25
29
  "@earendil-works/pi-coding-agent": "*"
26
30
  },
27
31
  "author": "15066212pp",
28
- "homepage": "https://github.com/op15066212/pi-plugins-publish/tree/main/pi-ptc-meter",
32
+ "homepage": "https://github.com/op15066212/pi-plugins-publish/tree/main/pi-ptc-meter#readme",
29
33
  "bugs": {
30
34
  "url": "https://github.com/op15066212/pi-plugins-publish/issues"
31
35
  },
@@ -36,5 +40,8 @@
36
40
  },
37
41
  "scripts": {
38
42
  "prepublishOnly": "node ../publish-check.mjs"
43
+ },
44
+ "engines": {
45
+ "node": ">=20"
39
46
  }
40
47
  }