pi-think-anchor 1.0.16 → 1.0.18

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.md +28 -2
  2. package/index.ts +1 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -35,7 +35,7 @@ pi install npm:pi-think-anchor
35
35
  | `lexicon.positive/negative/neutral` | 内置中文词表(专注 28 词 / 发散 18 词) | 词表覆盖 |
36
36
  | `bands.spec/react` | `1.2 / 0.5` | 旧版兼容(无 `score` 时生效) |
37
37
 
38
- 其他:环境变量 `THINK_ANCHOR=0` 硬关闭;日志 `~/.pi/think-anchor.jsonl`(1 MiB 截断,保留尾部整行)。
38
+ 其他:日志 `~/.pi/think-anchor.jsonl`(1 MiB 截断,保留尾部整行)。
39
39
 
40
40
  ## 命令
41
41
 
@@ -51,6 +51,19 @@ pi install npm:pi-think-anchor
51
51
  - 无效不升级:上次 `eff >= 0` 时 L2 降为 L1。
52
52
  - `session_start`:重置状态机,仅保留最近 3 条与 pending(跨会话结算)。
53
53
 
54
+ ```mermaid
55
+ flowchart TD
56
+ A[turn_end<br/>读 assistant thinking] --> B[词频指纹 pos/neg/neu]
57
+ B --> C{本轮命中 >= minHits?}
58
+ C -->|否| Z[只推进窗口<br/>不评分不干预]
59
+ C -->|是| D[滑窗聚合 + alpha 平滑比率]
60
+ D --> E{波段}
61
+ E -->|spec| F[healthy 静默]
62
+ E -->|mixed| G[watch]
63
+ E -->|react| H[状态机<br/>L1 / L2 干预]
64
+ H -->|nextTurn 尾部消息| A
65
+ ```
66
+
54
67
  ## 借鉴
55
68
 
56
69
  蒸馏自 DSH 插件 [`dsh-anchored-monitor`](https://dsh-plugin.org/zh/plugins/aik358/dsh-anchored-monitor) 0.3.1:机制思想来源,非代码移植(本实现为回合级,无独立进程)。
@@ -93,7 +106,7 @@ Config file `~/.pi/think-anchor.json` (optional; defaults apply, invalid JSON fa
93
106
  | `lexicon.positive/negative/neutral` | built-in Chinese lexicon (28 focus / 18 drift) | Lexicon override |
94
107
  | `bands.spec/react` | `1.2 / 0.5` | Legacy keys (used when `score` is absent) |
95
108
 
96
- Also: `THINK_ANCHOR=0` hard off; log `~/.pi/think-anchor.jsonl` (1 MiB truncation, tail-preserving).
109
+ Also: log `~/.pi/think-anchor.jsonl` (1 MiB truncation, tail-preserving).
97
110
 
98
111
  ## Commands
99
112
 
@@ -109,6 +122,19 @@ Also: `THINK_ANCHOR=0` hard off; log `~/.pi/think-anchor.jsonl` (1 MiB truncatio
109
122
  - No escalation: when the previous `eff >= 0`, L2 degrades to L1.
110
123
  - `session_start`: resets state, keeping only the last 3 samples and pending (cross-session settlement).
111
124
 
125
+ ```mermaid
126
+ flowchart TD
127
+ A[turn_end<br/>read assistant thinking] --> B[word fingerprint pos/neg/neu]
128
+ B --> C{hits >= minHits?}
129
+ C -->|no| Z[advance window only<br/>no score, no nudge]
130
+ C -->|yes| D[sliding window + alpha-smoothed ratio]
131
+ D --> E{band}
132
+ E -->|spec| F[healthy: silent]
133
+ E -->|mixed| G[watch]
134
+ E -->|react| H[state machine<br/>L1 / L2 nudge]
135
+ H -->|nextTurn message| A
136
+ ```
137
+
112
138
  ## Credits
113
139
 
114
140
  Distilled from the DSH plugin [`dsh-anchored-monitor`](https://dsh-plugin.org/zh/plugins/aik358/dsh-anchored-monitor) 0.3.1: the mechanism is upstream, the code is not (turn-level, no separate process).
package/index.ts CHANGED
@@ -263,7 +263,7 @@ export default function thinkAnchor(pi: ExtensionAPI): void {
263
263
 
264
264
  pi.on("turn_end", async (event, ctx) => {
265
265
  try {
266
- if (process.env.THINK_ANCHOR === "0" || !st.cfg.enabled) return;
266
+ if (!st.cfg.enabled) return;
267
267
  void ctx;
268
268
  const msg = (event as { message?: { role?: string; content?: unknown } } | undefined)?.message;
269
269
  if (!msg || msg.role !== "assistant") return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-think-anchor",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Monitors thinking focus drift and nudges the model back on track.",
5
5
  "type": "module",
6
6
  "license": "MIT",