pi-ptc-meter 1.0.33 → 1.0.35
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.md +23 -14
- package/index.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,34 +52,39 @@ pi install npm:pi-ptc-meter
|
|
|
52
52
|
|
|
53
53
|
| 命令 | 作用 |
|
|
54
54
|
| --- | --- |
|
|
55
|
-
| `/ptc [n]` | 最近
|
|
55
|
+
| `/ptc [n]` | 状态(阈值 / inject / notify)+ 最近 8 轮明细(次数 · 时长)+ 统计(中位 / 超标轮次) |
|
|
56
56
|
|
|
57
57
|
## 模拟测试
|
|
58
58
|
|
|
59
59
|
pi-ptc-meter 的改动在**隔离副本**上做回放验证后才发版;当前版本通过 **10,011 条断言**。
|
|
60
60
|
|
|
61
|
-
| 测试面 | 规模 |
|
|
62
|
-
| --- | --- |
|
|
63
|
-
| 真实日志回放 | 4,349 轮 |
|
|
64
|
-
| 随机状态 | 10,000 条 |
|
|
65
|
-
| 统计函数边界 | 11 项 |
|
|
61
|
+
| 测试面 | 规模 | 结果 |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| 真实日志回放 | 4,349 轮 | 🟢 |
|
|
64
|
+
| 随机状态 | 10,000 条 | 🟢 |
|
|
65
|
+
| 统计函数边界 | 11 项 | 🟢 |
|
|
66
|
+
|
|
67
|
+
🟢 **结论**:预估功能已删除——412 个声明点上 6 种预测器全部落在 71–94% 误差,预估恰好在它被需要的那一刻不可预测。
|
|
66
68
|
|
|
67
69
|
改动:删调用数预估 + 耗时预估。依据:预估在声明点不可预测:412 个声明点上 6 种预测器全部 71–94% 误差;耗时中位误差 199%。
|
|
70
|
+
|
|
68
71
|
## 作用(源码事实)
|
|
69
72
|
|
|
70
73
|
- `tool_call`:顶层调用计数 +1(codemode 内层调用不另计;不拦截、不改调用)。
|
|
71
74
|
- `turn_end`:记录本轮次数与耗时(不落盘);超阈值时每 run 提示一次(goal 自动续轮共享同一 run 时 `agent_end` 可能整段不触发,避免回路失效)。
|
|
72
75
|
- `agent_end`:每 run 落盘一行日志。
|
|
73
76
|
- `before_agent_start`:结算上一轮并以 `nextTurn` 尾部消息回灌——计数、耗时、**缓存命中率**(仅当该轮有 usage 数据时出现;< 90% 标「低」)、会话中位、阈值判定(`display: false`)。
|
|
74
|
-
- **1.0.32
|
|
77
|
+
- **1.0.32 起不回灌「预计 / 实际 / 偏差」**:412 个声明点上 6 种预测器全部 71–94% 误差(耗时 199%),预估不可用。
|
|
75
78
|
|
|
76
79
|
**注入样例(示意,字段可能随版本增删)**
|
|
77
80
|
|
|
78
81
|
```text
|
|
79
82
|
PTC 计量:上一轮 9 次工具调用 · 实际 34s · 命中 92% · 会话中位 25 · 阈值 50 · 判据 = 本轮计数不超阈值且无同类调用可并
|
|
80
83
|
```
|
|
84
|
+
- 耗时预估仍写入日志并在 `/ptc` 中显示(历史值),但不再回灌给模型。
|
|
81
85
|
- `session_start`:模块级计量归零。
|
|
82
86
|
- system 内 section `ptc_meter` 只含逐字不变的骨架。
|
|
87
|
+
- 只写自己的 section,**永不返回 `systemPrompt`**(返回即覆盖式替换,会静默丢弃其它扩展的 section 修改)。
|
|
83
88
|
## 原理(专业)
|
|
84
89
|
|
|
85
90
|
```text
|
|
@@ -162,34 +167,38 @@ Also: log `~/.pi/ptc-meter.jsonl` (1 MiB truncation, tail-preserving); no enviro
|
|
|
162
167
|
|
|
163
168
|
| Command | Purpose |
|
|
164
169
|
| --- | --- |
|
|
165
|
-
| `/ptc [n]` |
|
|
170
|
+
| `/ptc [n]` | State (threshold / inject / notify) + last 8 turns (calls · duration) + stats (median / over-threshold) |
|
|
166
171
|
|
|
167
172
|
## Verification
|
|
168
173
|
|
|
169
174
|
Changes to pi-ptc-meter were verified on an isolated copy before release; the current version passes **10,011 assertions**.
|
|
170
175
|
|
|
171
|
-
| Surface | Scale |
|
|
172
|
-
| --- | --- |
|
|
173
|
-
| Real log replay | 4,349 turns |
|
|
174
|
-
| Random states | 10,000 |
|
|
175
|
-
| Statistic edges | 11 |
|
|
176
|
+
| Surface | Scale | Result |
|
|
177
|
+
| --- | --- | --- |
|
|
178
|
+
| Real log replay | 4,349 turns | 🟢 |
|
|
179
|
+
| Random states | 10,000 | 🟢 |
|
|
180
|
+
| Statistic edges | 11 | 🟢 |
|
|
176
181
|
|
|
182
|
+
🟢 **Result**: both estimates removed - on 412 declaration points all six predictors landed at 71-94% error, so estimating is unpredictable exactly when it is needed.
|
|
177
183
|
Change: both estimates removed. Why: estimates are unpredictable at declaration points: six predictors all landed at 71-94% error; duration median error 199%.
|
|
184
|
+
|
|
178
185
|
## What it does (source facts)
|
|
179
186
|
|
|
180
187
|
- `tool_call`: increments the counter for top-level calls only (nested codemode calls are not counted separately; never intercepts or rewrites).
|
|
181
188
|
- `turn_end`: records calls and duration (no disk write); when goal auto-continuation shares one run and `agent_end` never fires, it warns once above threshold (once per run).
|
|
182
189
|
- `agent_end`: writes one log line per run.
|
|
183
190
|
- `before_agent_start`: settles the previous turn and feeds back counts, duration, the **cache hit rate** (only when that turn reported usage; flagged low below 90%), the session median and the threshold verdict as a `nextTurn` trailing message (`display: false`).
|
|
184
|
-
- **1.0.32
|
|
191
|
+
- **1.0.32 drops estimate feedback**: on 412 declaration points all six predictors landed at 71-94% error (duration 199%) - estimating is not viable.
|
|
185
192
|
|
|
186
193
|
**Sample injection (illustrative; fields may change between versions)**
|
|
187
194
|
|
|
188
195
|
```text
|
|
189
196
|
PTC metering: last turn 9 tool calls · 34s actual · 92% cache hit · session median 25 · threshold 50 · verdict: under threshold, no obvious merge candidates
|
|
190
197
|
```
|
|
198
|
+
- The duration estimate is still logged and shown by `/ptc` as a historical value, but is no longer fed back to the model.
|
|
191
199
|
- `session_start`: resets module-level counters.
|
|
192
200
|
- The `ptc_meter` system section holds only a byte-stable skeleton.
|
|
201
|
+
- Writes only its own section and **never returns `systemPrompt`** (a returned prompt replaces everything and silently drops other extensions' sections).
|
|
193
202
|
## How it works (technical)
|
|
194
203
|
|
|
195
204
|
```text
|
package/index.ts
CHANGED
|
@@ -166,7 +166,7 @@ const EST_RE = /(?:预计|预估|eta)[^0-9\n]{0,8}(\d+(?:\.\d+)?)\s*(秒|s(?!\w)
|
|
|
166
166
|
/** 从我的回复文本里解析预计耗时(秒);无声明或非法值返回 null。 */
|
|
167
167
|
function parseEstimate(text: string): number | null {
|
|
168
168
|
try {
|
|
169
|
-
// 扫**尾部窗口**:声明写在回复末尾;前 6000 字符从未覆盖到它(实测 est
|
|
169
|
+
// 扫**尾部窗口**:声明写在回复末尾;前 6000 字符从未覆盖到它(实测 est 填充率 9.7%,2026-10-18 全量 4373 轮)
|
|
170
170
|
// 取最后一个匹配 = 末尾的声明(同时谈格式时,正文中部的不算,因窗口在尾部)
|
|
171
171
|
const m = [...text.slice(-15000).matchAll(new RegExp(EST_RE.source, "gi"))].pop();
|
|
172
172
|
if (!m) return null;
|