pi-think-anchor 1.0.18 → 1.0.20

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 (2) hide show
  1. package/README.md +85 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -9,6 +9,26 @@
9
9
 
10
10
  思维链锚定监测:读取 thinking 的词频指纹,判定专注 / 过渡 / 发散,发散时分级提示。
11
11
 
12
+ ## 快速事实
13
+
14
+ | 项 | 说明 |
15
+ | --- | --- |
16
+ | 配置文件 | ~/.pi/think-anchor.json(可省略) |
17
+ | 命令行 | /think-anchor [on|off|reset|stats] |
18
+ | 调用方式 | **全自动**:turn_end 评估 + 条件注入;命令可手动开关/重置 |
19
+
20
+ 完整配置(全部键与默认值):
21
+
22
+ ```json
23
+ {
24
+ "enabled": true,
25
+ "score": { "minHits": 3, "spec": 1.2, "react": 0.5, "alpha": 1 },
26
+ "windowSize": 5,
27
+ "weights": { "beta": 0.4, "eps": 0.5 },
28
+ "intervention": { "l1CooldownMin": 10, "l2CooldownMin": 15, "maxL2": 2 }
29
+ }
30
+ ```
31
+
12
32
  ## 安装
13
33
 
14
34
  ```bash
@@ -51,6 +71,8 @@ pi install npm:pi-think-anchor
51
71
  - 无效不升级:上次 `eff >= 0` 时 L2 降为 L1。
52
72
  - `session_start`:重置状态机,仅保留最近 3 条与 pending(跨会话结算)。
53
73
 
74
+ ## 原理(专业)
75
+
54
76
  ```mermaid
55
77
  flowchart TD
56
78
  A[turn_end<br/>读 assistant thinking] --> B[词频指纹 pos/neg/neu]
@@ -64,6 +86,22 @@ flowchart TD
64
86
  H -->|nextTurn 尾部消息| A
65
87
  ```
66
88
 
89
+ ## 原理(小白)
90
+
91
+ 像一个跑步教练:看你说话的用词判断此刻是专注还是走神;一直走神就轻轻提醒一句,恢复专注就不打扰。
92
+
93
+ ```mermaid
94
+ flowchart LR
95
+ A[你说的话] --> B[教练看用词]
96
+ B --> C{清晰吗}
97
+ C -->|清晰| D[不打扰]
98
+ C -->|有点散| E[轻提醒一句]
99
+ C -->|一直散| F[认真提醒]
100
+ E --> A
101
+ F --> A
102
+ ```
103
+
104
+
67
105
  ## 借鉴
68
106
 
69
107
  蒸馏自 DSH 插件 [`dsh-anchored-monitor`](https://dsh-plugin.org/zh/plugins/aik358/dsh-anchored-monitor) 0.3.1:机制思想来源,非代码移植(本实现为回合级,无独立进程)。
@@ -80,6 +118,26 @@ MIT
80
118
 
81
119
  Chain-of-thought drift monitor: reads a word-frequency fingerprint from thinking, classifies focused / mixed / reactive, and nudges when drifting.
82
120
 
121
+ ## At a glance
122
+
123
+ | Item | Description |
124
+ | --- | --- |
125
+ | Config file | ~/.pi/think-anchor.json (optional) |
126
+ | Commands | /think-anchor [on|off|reset|stats] |
127
+ | Automation | **Fully automatic**: evaluated on turn_end, injects only when needed; commands toggle/reset |
128
+
129
+ Full config (all keys and defaults):
130
+
131
+ ```json
132
+ {
133
+ "enabled": true,
134
+ "score": { "minHits": 3, "spec": 1.2, "react": 0.5, "alpha": 1 },
135
+ "windowSize": 5,
136
+ "weights": { "beta": 0.4, "eps": 0.5 },
137
+ "intervention": { "l1CooldownMin": 10, "l2CooldownMin": 15, "maxL2": 2 }
138
+ }
139
+ ```
140
+
83
141
  ## Install
84
142
 
85
143
  ```bash
@@ -122,7 +180,34 @@ Also: log `~/.pi/think-anchor.jsonl` (1 MiB truncation, tail-preserving).
122
180
  - No escalation: when the previous `eff >= 0`, L2 degrades to L1.
123
181
  - `session_start`: resets state, keeping only the last 3 samples and pending (cross-session settlement).
124
182
 
183
+ ## How it works (technical)
184
+
125
185
  ```mermaid
186
+ flowchart TD
187
+ A[turn_end<br/>read assistant thinking] --> B[word fingerprint pos/neg/neu]
188
+ B --> C{hits >= minHits?}
189
+ C -->|no| Z[advance window only<br/>no score, no nudge]
190
+ C -->|yes| D[sliding window + alpha-smoothed ratio]
191
+ D --> E{band}
192
+ E -->|spec| F[healthy: silent]
193
+ E -->|mixed| G[watch]
194
+ E -->|react| H[state machine<br/>L1 / L2 nudge]
195
+ H -->|nextTurn message| A
196
+
197
+ ## How it works (plain words)
198
+
199
+ Like a running coach: reads your words to judge whether you are focused or drifting; a mild nudge when you drift, silence when you recover.
200
+
201
+ ```mermaid
202
+ flowchart LR
203
+ A[what you say] --> B[coach reads the wording]
204
+ B --> C{focused?}
205
+ C -->|yes| D[no interruption]
206
+ C -->|slightly off| E[one gentle nudge]
207
+ C -->|drifting| F[stronger nudge]
208
+ E --> A
209
+ F --> A
210
+ ```
126
211
  flowchart TD
127
212
  A[turn_end<br/>read assistant thinking] --> B[word fingerprint pos/neg/neu]
128
213
  B --> C{hits >= minHits?}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-think-anchor",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "Monitors thinking focus drift and nudges the model back on track.",
5
5
  "type": "module",
6
6
  "license": "MIT",