pi-ptc-meter 1.0.8 → 1.0.10

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.
Files changed (3) hide show
  1. package/README.en.md +41 -27
  2. package/README.md +37 -23
  3. package/package.json +5 -1
package/README.en.md CHANGED
@@ -1,28 +1,16 @@
1
- # pi-ptc-meter — per-turn tool-call metering (pi extension)
1
+ # pi-ptc-meter — per-turn tool-call metering and feedback (pi extension)
2
2
 
3
- Turns "one tool call = one round trip" into visible numbers, and feeds them back to the model when a turn runs long.
3
+ > Requires pi >= 0.74 · Node >= 20 · MIT · no runtime dependencies
4
4
 
5
- ## Features
6
-
7
- - Counts tool calls, wall time and the predicted count declared before the turn.
8
- - Flags turns above the threshold (default 39) for a merge review.
9
- - Numbers travel in a tail message; the system section stays byte-identical (prefix cache safe).
10
- - Log: `~/.pi/ptc-meter.jsonl`, one JSON line per turn.
11
- - `/ptc [n]` shows the last n turns: calls, time, prediction, median, over-threshold.
12
-
13
- ## Defaults
14
-
15
- | Item | Default | Note |
16
- | --- | --- | --- |
17
- | Threshold | 39 calls/turn | `threshold` in `~/.pi/ptc-meter.json` |
18
- | Injection | on | `inject: false` disables |
19
- | Popup | off | `notify: true` enables (silent by default) |
20
- | Log | `~/.pi/ptc-meter.jsonl` | keeps whole trailing lines over 1 MiB |
21
- | Language | Chinese | injected text and command output |
5
+ Turns "one tool call = one round trip" into a visible number: counts tool calls and elapsed time each turn, then feeds the figures back to the model on the next turn.
22
6
 
23
- ## Credits
7
+ ## Features
24
8
 
25
- Original work; no upstream implementation. The "PTC (parallel tool calls)" discipline comes from the author's working rules; this package is its metering and feedback implementation.
9
+ - Tracks tool calls per turn, actual elapsed time, and the estimated calls / duration declared up front.
10
+ - Feeds back counts, duration, baseline median and deviation; flags turns above the threshold for a merge review.
11
+ - Numbers travel as trailing messages; the system section keeps a byte-stable skeleton (prefix-cache friendly).
12
+ - Log at `~/.pi/ptc-meter.jsonl` — turn, calls, duration, estimates, session id per line.
13
+ - Command `/ptc [n]`: last n turns with counts, duration, estimates, median and over-threshold flags.
26
14
 
27
15
  ## Install
28
16
 
@@ -31,7 +19,27 @@ pi install npm:pi-ptc-meter
31
19
  pi install ./pi-ptc-meter
32
20
  ```
33
21
 
34
- ## Config
22
+ ## Configuration
23
+
24
+ ### File `~/.pi/ptc-meter.json`
25
+
26
+ Every key is optional; invalid JSON falls back to defaults.
27
+
28
+ | Key | Type | Default | Description |
29
+ | --- | --- | --- | --- |
30
+ | `threshold` | number | `39` | Per-turn call threshold, **39 calls/turn** (must be > 0; p75 calibration — 12 would fire on 62% of turns) |
31
+ | `inject` | boolean | `true` | Enable the feedback message |
32
+ | `notify` | boolean | `false` | Use UI notifications instead of silent injection |
33
+
34
+ ### Other
35
+
36
+ | Item | Default | Description |
37
+ | --- | --- | --- |
38
+ | Log `~/.pi/ptc-meter.jsonl` | on | Tail-preserving truncation at 1 MiB |
39
+ | Language | Chinese | Feedback text and command output |
40
+ | UI notifications | off | See `notify` |
41
+
42
+ ### Example
35
43
 
36
44
  ```json
37
45
  { "threshold": 39, "inject": true, "notify": false }
@@ -39,10 +47,16 @@ pi install ./pi-ptc-meter
39
47
 
40
48
  ## How it works
41
49
 
42
- - `tool_call` counts → `turn_end` records → next `before_agent_start` settles and feeds back.
43
- - Only the tail message changes; the section is stable.
50
+ - `tool_call` increments the counter; `turn_end` records the turn; the next `before_agent_start` settles and injects.
51
+ - Only trailing messages change, so the system section is byte-identical each turn (cache friendly).
52
+ - Estimates are parsed from the reply text (`预计 Ns` / `预计 Nm` / `预计 N 次`); when absent it reports only the actual value and the peer median.
53
+
54
+ ## Limitations
55
+
56
+ - Counts reflect call volume only; whether calls could actually be merged still needs human review.
57
+ - It does not intercept, rewrite input, or read conversation content.
58
+ - Estimate parsing is text heuristics; non-matching formats count as "not declared".
44
59
 
45
- ## Limits
60
+ ## License
46
61
 
47
- - Counts calls only; whether they could be merged still needs a human check.
48
- - Does not intercept input or read conversation content.
62
+ MIT
package/README.md CHANGED
@@ -1,28 +1,16 @@
1
- # pi-ptc-meter — 每轮工具调用计量与回灌(pi 扩展)
1
+ # pi-ptc-meter —— 每轮工具调用计量与回灌(pi 扩展)
2
2
 
3
- 把「一次工具调用 = 一次往返」的浪费变成可见数字:统计每轮调用次数与时长,每轮把数字回灌给模型(超阈值时单独标注)。
3
+ > 适用 pi ≥ 0.74 · Node ≥ 20 · MIT · 无运行时依赖
4
4
 
5
- ## 来源与借鉴
6
-
7
- 原创,无上游实现。「PTC(执行合并)」纪律出自作者的个人工作手册,本包是该纪律的计量与回灌实现。
5
+ 把「一次工具调用 = 一次往返」的浪费变成可见数字:统计每轮调用次数与时长,并在下一轮把数字回灌给模型。
8
6
 
9
7
  ## 功能
10
8
 
11
- - 统计每轮工具调用次数、实际耗时、开工前声明的预计值。
12
- - 每轮回灌计数、耗时与基线;超阈值(默认 39 次/轮)时标注需复核「是否有可合并的调用」。
13
- - 数字走对话尾部消息回灌,system 内只留逐字稳定的骨架(保护前缀缓存)。
14
- - 日志 `~/.pi/ptc-meter.jsonl`,每行含轮次、次数、时长、预计次数、预计耗时、会话 id。
15
- - 命令 `/ptc [n]`:最近 n 轮的次数、时长、预计、中位、超标。
16
-
17
- ## 默认配置
18
-
19
- | 项 | 默认 | 说明 |
20
- | --- | --- | --- |
21
- | 阈值 | 39 次/轮 | `~/.pi/ptc-meter.json` 的 `threshold` |
22
- | 注入回灌 | 开 | `inject: false` 关闭 |
23
- | 弹窗提示 | 关 | `notify: true` 开启(默认走静默注入) |
24
- | 日志 | `~/.pi/ptc-meter.jsonl` | 超过 1 MiB 保留尾部整行 |
25
- | 语言 | 中文 | 注入文本与命令输出 |
9
+ - 统计每轮工具调用次数、实际耗时、开工前声明的预计次数 / 预计时长。
10
+ - 回灌计数、耗时、基线中位与偏差;超阈值时标注「需复核是否有可合并的调用」。
11
+ - 数字走对话尾部消息,system 内只留逐字稳定的骨架(保护前缀缓存)。
12
+ - 日志 `~/.pi/ptc-meter.jsonl`,每行含轮次、次数、时长、预计值、会话 id。
13
+ - 命令 `/ptc [n]`:最近 n 轮的次数、时长、预计、中位、超标情况。
26
14
 
27
15
  ## 安装
28
16
 
@@ -33,16 +21,42 @@ pi install ./pi-ptc-meter
33
21
 
34
22
  ## 配置
35
23
 
24
+ ### 配置文件 `~/.pi/ptc-meter.json`
25
+
26
+ 所有键可省略;非法 JSON 自动回退默认。
27
+
28
+ | 键 | 类型 | 默认 | 说明 |
29
+ | --- | --- | --- | --- |
30
+ | `threshold` | number | `39` | 每轮调用数阈值 **39 次/轮**(> 0;按 p75 实测口径,12 会触发 62% 的轮次) |
31
+ | `inject` | boolean | `true` | 是否注入回灌消息 |
32
+ | `notify` | boolean | `false` | 是否用弹窗提示(默认走静默注入) |
33
+
34
+ ### 其他
35
+
36
+ | 项 | 默认 | 说明 |
37
+ | --- | --- | --- |
38
+ | 日志 `~/.pi/ptc-meter.jsonl` | 开 | 超 1 MiB 保留尾部整行 |
39
+ | 语言 | 中文 | 注入文本与命令输出 |
40
+ | 弹窗 | 关 | 见 `notify` |
41
+
42
+ ### 示例
43
+
36
44
  ```json
37
45
  { "threshold": 39, "inject": true, "notify": false }
38
46
  ```
39
47
 
40
48
  ## 机制
41
49
 
42
- - `tool_call` 计数 → `turn_end` 记录 → 下轮 `before_agent_start` 结算并回灌。
43
- - 只在尾部消息里变化,system section 每轮字节相同。
50
+ - `tool_call` 计数 → `turn_end` 记录 → 下一次 `before_agent_start` 结算并回灌。
51
+ - 只有尾部消息变化,system section 每轮字节相同(缓存友好)。
52
+ - 预计值从回复文本解析(`预计 Ns` / `预计 Nm` / `预计 N 次`);未声明则只报实际值与同类中位。
44
53
 
45
54
  ## 限制
46
55
 
47
- - 计数只反映调用次数,不判断调用是否真的可合并;可并性需要自行复核。
56
+ - 计数只反映调用次数,不判断调用是否真的可合并;可并性需人工复核。
48
57
  - 不拦截、不改输入、不读取对话内容。
58
+ - 预计解析是基于文本的启发式,格式不符时视为未声明。
59
+
60
+ ## License
61
+
62
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ptc-meter",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
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",
@@ -25,6 +25,10 @@
25
25
  "@earendil-works/pi-coding-agent": "*"
26
26
  },
27
27
  "author": "15066212pp",
28
+ "homepage": "https://github.com/op15066212/pi-plugins-publish/tree/main/pi-ptc-meter",
29
+ "bugs": {
30
+ "url": "https://github.com/op15066212/pi-plugins-publish/issues"
31
+ },
28
32
  "repository": {
29
33
  "type": "git",
30
34
  "url": "git+https://github.com/op15066212/pi-plugins-publish.git",