pi-ptc-meter 1.0.9 → 1.0.11

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 +64 -26
  2. package/README.md +61 -23
  3. package/package.json +1 -1
package/README.en.md CHANGED
@@ -1,28 +1,17 @@
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
5
+ ## What it solves
14
6
 
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 |
7
+ "One tool call = one round trip" is the biggest systematic waste in agent execution, and it is invisible. This extension turns call counts, duration and deviation into a number that appears every turn, and flags turns above the threshold for a merge review.
22
8
 
23
- ## Credits
9
+ ## Features
24
10
 
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.
11
+ - Tracks calls per turn, actual duration, and declared estimates.
12
+ - Feeds back counts, duration, baseline median and deviation; flags over-threshold turns (default 39 calls/turn).
13
+ - Numbers travel as trailing messages; the system section keeps a byte-stable skeleton.
14
+ - Log `~/.pi/ptc-meter.jsonl`; command `/ptc [n]`.
26
15
 
27
16
  ## Install
28
17
 
@@ -31,18 +20,67 @@ pi install npm:pi-ptc-meter
31
20
  pi install ./pi-ptc-meter
32
21
  ```
33
22
 
34
- ## Config
23
+ ## Configuration
24
+
25
+ ### 1 · Config file `~/.pi/ptc-meter.json`
26
+
27
+ | Key | Type | Default | Description |
28
+ | --- | --- | --- | --- |
29
+ | `threshold` | number | `39` | Per-turn threshold, **39 calls/turn** (p75 calibration; 12 would fire on 62% of turns) |
30
+ | `inject` | boolean | `true` | Enable feedback message |
31
+ | `notify` | boolean | `false` | Use UI notifications instead of silent injection |
35
32
 
36
33
  ```json
37
34
  { "threshold": 39, "inject": true, "notify": false }
38
35
  ```
39
36
 
37
+ ### 2 · Environment
38
+
39
+ None.
40
+
41
+ ### 3 · Commands
42
+
43
+ | Command | Purpose |
44
+ | --- | --- |
45
+ | `/ptc` / `/ptc <n>` | Last n turns: counts, duration, estimates, median, over-threshold |
46
+
47
+ ### 4 · Log
48
+
49
+ | Path | Content |
50
+ | --- | --- |
51
+ | `~/.pi/ptc-meter.jsonl` | turn, calls, duration, estimated calls/duration, session id; tail-preserving at 1 MiB |
52
+
53
+ ## Where it acts (execution path, not thinking)
54
+
55
+ | Stage | Does |
56
+ | --- | --- |
57
+ | `tool_call` | Increments the counter (counts only; never intercepts) |
58
+ | `turn_end` | Records counts and duration (no disk write) |
59
+ | `agent_end` | Writes one log line per run |
60
+
61
+ ## Feedback path
62
+
63
+ | Item | Path | Why |
64
+ | --- | --- | --- |
65
+ | Previous calls / duration / deviation | Trailing message, `nextTurn`, `display:false` | Changing numbers in the system prompt invalidate the conversation's prefix cache |
66
+ | `ptc_meter` section | Byte-identical skeleton only | Stable bytes keep the cache intact |
67
+ | Baseline median / systematic bias | "recent N turns median +x% -> report ~k times" | An executable multiplier, not "be more precise" |
68
+ | No estimate declared | Actual value + peer median | The mechanism must not depend on declarations |
69
+
70
+ **Boundary**: it reports how many calls were used, not whether they could be merged.
71
+
40
72
  ## How it works
41
73
 
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.
74
+ - `tool_call` increments; `turn_end` records; the next `before_agent_start` settles and injects.
75
+ - Estimates parse from reply text (`预计 Ns` / `预计 Nm` / `预计 N 次`), last match in a trailing window.
76
+ - Counters reset on session change; history for the same sid is merged across restarts.
77
+
78
+ ## Limitations
79
+
80
+ - Counts only; no mergeability judgement.
81
+ - Never intercepts, rewrites input, or reads content.
82
+ - Estimate parsing is heuristic; duration is wall-clock (includes waiting and network).
44
83
 
45
- ## Limits
84
+ ## License
46
85
 
47
- - Counts calls only; whether they could be merged still needs a human check.
48
- - Does not intercept input or read conversation content.
86
+ MIT
package/README.md CHANGED
@@ -1,28 +1,17 @@
1
- # pi-ptc-meter — 每轮工具调用计量与回灌(pi 扩展)
1
+ # pi-ptc-meter —— 每轮工具调用计量与回灌(pi 扩展)
2
2
 
3
- 把「一次工具调用 = 一次往返」的浪费变成可见数字:统计每轮调用次数与时长,每轮把数字回灌给模型(超阈值时单独标注)。
3
+ > 适用 pi ≥ 0.74 · Node ≥ 20 · MIT · 无运行时依赖
4
4
 
5
- ## 来源与借鉴
5
+ ## 它解决什么问题
6
6
 
7
- 原创,无上游实现。「PTC(执行合并)」纪律出自作者的个人工作手册,本包是该纪律的计量与回灌实现。
7
+ 「一次工具调用 = 一次往返」是代理执行里最大的系统性浪费,却不可见。本扩展把每轮调用次数、耗时与偏差变成每轮都会出现的数字,并在超阈值时点明「这一轮有没有可合并的调用」。
8
8
 
9
9
  ## 功能
10
10
 
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
- | 语言 | 中文 | 注入文本与命令输出 |
11
+ - 统计每轮调用次数、实际耗时、开工前声明的预计次数 / 时长。
12
+ - 回灌计数、耗时、基线中位与偏差;超阈值(默认 39 次/轮)时标注需复核。
13
+ - 数字走对话尾部消息,system 只留逐字稳定的骨架(保护前缀缓存)。
14
+ - 日志 `~/.pi/ptc-meter.jsonl`;命令 `/ptc [n]`。
26
15
 
27
16
  ## 安装
28
17
 
@@ -33,16 +22,65 @@ pi install ./pi-ptc-meter
33
22
 
34
23
  ## 配置
35
24
 
25
+ ### 1 · 配置文件 `~/.pi/ptc-meter.json`
26
+
27
+ | 键 | 类型 | 默认 | 说明 |
28
+ | --- | --- | --- | --- |
29
+ | `threshold` | number | `39` | 每轮调用数阈值 **39 次/轮**(> 0;p75 口径,12 会触发 62% 的轮次) |
30
+ | `inject` | boolean | `true` | 是否注入回灌消息 |
31
+ | `notify` | boolean | `false` | 改用弹窗提示(默认静默注入) |
32
+
36
33
  ```json
37
34
  { "threshold": 39, "inject": true, "notify": false }
38
35
  ```
39
36
 
37
+ ### 2 · 环境变量
38
+
39
+ 无(不读环境变量)。
40
+
41
+ ### 3 · 命令
42
+
43
+ | 命令 | 作用 |
44
+ | --- | --- |
45
+ | `/ptc` / `/ptc <n>` | 最近 n 轮:次数、时长、预计、中位、超标 |
46
+
47
+ ### 4 · 日志
48
+
49
+ | 路径 | 内容 |
50
+ | --- | --- |
51
+ | `~/.pi/ptc-meter.jsonl` | 轮次、调用数、时长、预计次数、预计耗时、会话 id;超 1 MiB 保留尾部整行 |
52
+
53
+ ## 作用点(执行通路,不碰 thinking)
54
+
55
+ | 阶段 | 做什么 |
56
+ | --- | --- |
57
+ | `tool_call` | 计数 +1(只数,不拦截、不改调用) |
58
+ | `turn_end` | 记录本轮次数与耗时(不落盘) |
59
+ | `agent_end` | 每 run 落盘一行日志 |
60
+
61
+ ## 回灌(反馈回到模型的通路)
62
+
63
+ | 项 | 通路 | 设计理由 |
64
+ | --- | --- | --- |
65
+ | 上轮调用数 / 耗时 / 偏差 | 尾部消息,`nextTurn`,`display:false` | 变化数字进 system → 整段对话前缀缓存失效 |
66
+ | `ptc_meter` section | 只放逐字不变的骨架(阈值口径 + 工程自问索引) | 字节稳定才不毁缓存 |
67
+ | 基线中位 / 系统性偏差 | 附「近 N 轮中位 +x% → 本轮按约 k 倍报」 | 给可执行的倍数,而非抽象的「注意精度」 |
68
+ | 未声明预计 | 只报实际 + 同类中位 | 机制不依赖模型是否声明 |
69
+
70
+ **边界**:只报「上一轮用了多少次」,不判断调用是否真能合并——可并性需人工复核。
71
+
40
72
  ## 机制
41
73
 
42
- - `tool_call` 计数 → `turn_end` 记录 → 下轮 `before_agent_start` 结算并回灌。
43
- - 只在尾部消息里变化,system section 每轮字节相同。
74
+ - `tool_call` 计数 → `turn_end` 记录 → 下次 `before_agent_start` 结算注入。
75
+ - 预计值从回复文本解析(`预计 Ns` / `预计 Nm` / `预计 N 次`),取尾部窗口最后一次匹配。
76
+ - 会话切换后计数归零;同 sid 跨重启合并历史。
44
77
 
45
78
  ## 限制
46
79
 
47
- - 计数只反映调用次数,不判断调用是否真的可合并;可并性需要自行复核。
48
- - 不拦截、不改输入、不读取对话内容。
80
+ - 只数次数,不判断可并性。
81
+ - 不拦截、不改输入、不读对话内容。
82
+ - 预计解析是文本启发式;耗时是墙钟时间(含等待与网络)。
83
+
84
+ ## License
85
+
86
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ptc-meter",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
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",