pi-ptc-meter 1.0.10 → 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 +51 -27
  2. package/README.md +51 -27
  3. package/package.json +1 -1
package/README.en.md CHANGED
@@ -2,15 +2,16 @@
2
2
 
3
3
  > Requires pi >= 0.74 · Node >= 20 · MIT · no runtime dependencies
4
4
 
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.
5
+ ## What it solves
6
+
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.
6
8
 
7
9
  ## Features
8
10
 
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.
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]`.
14
15
 
15
16
  ## Install
16
17
 
@@ -21,41 +22,64 @@ pi install ./pi-ptc-meter
21
22
 
22
23
  ## Configuration
23
24
 
24
- ### File `~/.pi/ptc-meter.json`
25
-
26
- Every key is optional; invalid JSON falls back to defaults.
25
+ ### 1 · Config file `~/.pi/ptc-meter.json`
27
26
 
28
27
  | Key | Type | Default | Description |
29
28
  | --- | --- | --- | --- |
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 |
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 |
32
31
  | `notify` | boolean | `false` | Use UI notifications instead of silent injection |
33
32
 
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
43
-
44
33
  ```json
45
34
  { "threshold": 39, "inject": true, "notify": false }
46
35
  ```
47
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
+
48
72
  ## How it works
49
73
 
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.
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.
53
77
 
54
78
  ## Limitations
55
79
 
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".
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).
59
83
 
60
84
  ## License
61
85
 
package/README.md CHANGED
@@ -2,15 +2,16 @@
2
2
 
3
3
  > 适用 pi ≥ 0.74 · Node ≥ 20 · MIT · 无运行时依赖
4
4
 
5
- 把「一次工具调用 = 一次往返」的浪费变成可见数字:统计每轮调用次数与时长,并在下一轮把数字回灌给模型。
5
+ ## 它解决什么问题
6
+
7
+ 「一次工具调用 = 一次往返」是代理执行里最大的系统性浪费,却不可见。本扩展把每轮调用次数、耗时与偏差变成每轮都会出现的数字,并在超阈值时点明「这一轮有没有可合并的调用」。
6
8
 
7
9
  ## 功能
8
10
 
9
- - 统计每轮工具调用次数、实际耗时、开工前声明的预计次数 / 预计时长。
10
- - 回灌计数、耗时、基线中位与偏差;超阈值时标注「需复核是否有可合并的调用」。
11
- - 数字走对话尾部消息,system 内只留逐字稳定的骨架(保护前缀缓存)。
12
- - 日志 `~/.pi/ptc-meter.jsonl`,每行含轮次、次数、时长、预计值、会话 id。
13
- - 命令 `/ptc [n]`:最近 n 轮的次数、时长、预计、中位、超标情况。
11
+ - 统计每轮调用次数、实际耗时、开工前声明的预计次数 / 时长。
12
+ - 回灌计数、耗时、基线中位与偏差;超阈值(默认 39 次/轮)时标注需复核。
13
+ - 数字走对话尾部消息,system 只留逐字稳定的骨架(保护前缀缓存)。
14
+ - 日志 `~/.pi/ptc-meter.jsonl`;命令 `/ptc [n]`。
14
15
 
15
16
  ## 安装
16
17
 
@@ -21,41 +22,64 @@ pi install ./pi-ptc-meter
21
22
 
22
23
  ## 配置
23
24
 
24
- ### 配置文件 `~/.pi/ptc-meter.json`
25
-
26
- 所有键可省略;非法 JSON 自动回退默认。
25
+ ### 1 · 配置文件 `~/.pi/ptc-meter.json`
27
26
 
28
27
  | 键 | 类型 | 默认 | 说明 |
29
28
  | --- | --- | --- | --- |
30
- | `threshold` | number | `39` | 每轮调用数阈值 **39 次/轮**(> 0;按 p75 实测口径,12 会触发 62% 的轮次) |
29
+ | `threshold` | number | `39` | 每轮调用数阈值 **39 次/轮**(> 0;p75 口径,12 会触发 62% 的轮次) |
31
30
  | `inject` | boolean | `true` | 是否注入回灌消息 |
32
- | `notify` | boolean | `false` | 是否用弹窗提示(默认走静默注入) |
33
-
34
- ### 其他
35
-
36
- | 项 | 默认 | 说明 |
37
- | --- | --- | --- |
38
- | 日志 `~/.pi/ptc-meter.jsonl` | 开 | 超 1 MiB 保留尾部整行 |
39
- | 语言 | 中文 | 注入文本与命令输出 |
40
- | 弹窗 | 关 | 见 `notify` |
41
-
42
- ### 示例
31
+ | `notify` | boolean | `false` | 改用弹窗提示(默认静默注入) |
43
32
 
44
33
  ```json
45
34
  { "threshold": 39, "inject": true, "notify": false }
46
35
  ```
47
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
+
48
72
  ## 机制
49
73
 
50
- - `tool_call` 计数 → `turn_end` 记录 → 下一次 `before_agent_start` 结算并回灌。
51
- - 只有尾部消息变化,system section 每轮字节相同(缓存友好)。
52
- - 预计值从回复文本解析(`预计 Ns` / `预计 Nm` / `预计 N 次`);未声明则只报实际值与同类中位。
74
+ - `tool_call` 计数 → `turn_end` 记录 → 下次 `before_agent_start` 结算注入。
75
+ - 预计值从回复文本解析(`预计 Ns` / `预计 Nm` / `预计 N 次`),取尾部窗口最后一次匹配。
76
+ - 会话切换后计数归零;同 sid 跨重启合并历史。
53
77
 
54
78
  ## 限制
55
79
 
56
- - 计数只反映调用次数,不判断调用是否真的可合并;可并性需人工复核。
57
- - 不拦截、不改输入、不读取对话内容。
58
- - 预计解析是基于文本的启发式,格式不符时视为未声明。
80
+ - 只数次数,不判断可并性。
81
+ - 不拦截、不改输入、不读对话内容。
82
+ - 预计解析是文本启发式;耗时是墙钟时间(含等待与网络)。
59
83
 
60
84
  ## License
61
85
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ptc-meter",
3
- "version": "1.0.10",
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",