@principles/host-runtime 0.7.0 → 0.7.2
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.
|
@@ -8,8 +8,10 @@ type Degradation = {
|
|
|
8
8
|
reason: string;
|
|
9
9
|
nextAction: string;
|
|
10
10
|
};
|
|
11
|
-
/**
|
|
11
|
+
/** seed/owner_promoted 词进入高精度 deterministic path 的权重阈值 */
|
|
12
12
|
export declare const HIGH_PRECISION_LEARNED_WEIGHT = 0.7;
|
|
13
|
+
/** PRI-788 G3: llm 学习词 earned precision 的 TP 门槛(且要求零 FP) */
|
|
14
|
+
export declare const EARNED_PRECISION_MIN_TP = 3;
|
|
13
15
|
/** 高精度纠正短语 overlay(已验证的确定性 STRONG 路径,不属于 learner seed 集) */
|
|
14
16
|
export declare const HIGH_PRECISION_CORRECTION_OVERLAY: readonly (readonly [string, number])[];
|
|
15
17
|
/** empathy seed overlay(检测行为不变) */
|
|
@@ -63,13 +63,21 @@ function rowField(row, key) {
|
|
|
63
63
|
}
|
|
64
64
|
// ─── Shared correction keyword store (host-neutral extraction) ──────────────
|
|
65
65
|
const KEYWORD_STORE_FILE = 'correction_keywords.json';
|
|
66
|
-
/**
|
|
66
|
+
/** seed/owner_promoted 词进入高精度 deterministic path 的权重阈值 */
|
|
67
67
|
export const HIGH_PRECISION_LEARNED_WEIGHT = 0.7;
|
|
68
|
+
/** PRI-788 G3: llm 学习词 earned precision 的 TP 门槛(且要求零 FP) */
|
|
69
|
+
export const EARNED_PRECISION_MIN_TP = 3;
|
|
68
70
|
/** 高精度纠正短语 overlay(已验证的确定性 STRONG 路径,不属于 learner seed 集) */
|
|
69
71
|
export const HIGH_PRECISION_CORRECTION_OVERLAY = [
|
|
70
72
|
['这是错的', 0.9],
|
|
71
73
|
['不要自作主张', 0.9],
|
|
72
74
|
['不应该这么做', 0.9],
|
|
75
|
+
// PRI-788 G3(Owner 批准清单):中文高精度纠正句式
|
|
76
|
+
['我说的是', 0.9],
|
|
77
|
+
['不是让你', 0.85],
|
|
78
|
+
['谁让你', 0.85],
|
|
79
|
+
['又搞错', 0.8],
|
|
80
|
+
['都说了', 0.8],
|
|
73
81
|
];
|
|
74
82
|
/** empathy seed overlay(检测行为不变) */
|
|
75
83
|
export const EMPATHY_SEED_OVERLAY = [
|
|
@@ -83,6 +91,14 @@ function isValidLearnedKeyword(v) {
|
|
|
83
91
|
return false;
|
|
84
92
|
if (typeof k.weight !== 'number' || !Number.isFinite(k.weight))
|
|
85
93
|
return false;
|
|
94
|
+
// earned precision 的计数是安全门(tp >= 3 才升 high),必须先约束数值形状:
|
|
95
|
+
// `correction_keywords.json` 里被篡改/损坏的 `truePositiveCount: 3.1` 若放行,
|
|
96
|
+
// 会让只有 3 条样本(甚至根本没有样本)的词项挤进 high 确定性路径。
|
|
97
|
+
// 缺失按可选字段语义放行,存在则必须是【非负安全整数】。
|
|
98
|
+
const isCount = (value) => value === undefined ||
|
|
99
|
+
(typeof value === 'number' && Number.isSafeInteger(value) && value >= 0);
|
|
100
|
+
if (!isCount(k.truePositiveCount) || !isCount(k.falsePositiveCount))
|
|
101
|
+
return false;
|
|
86
102
|
return k.source === 'seed' || k.source === 'llm' || k.source === 'user';
|
|
87
103
|
}
|
|
88
104
|
function mapLearnedSource(source) {
|
|
@@ -92,9 +108,18 @@ function mapLearnedSource(source) {
|
|
|
92
108
|
return 'owner_promoted';
|
|
93
109
|
return 'seed';
|
|
94
110
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
/**
|
|
112
|
+
* PRI-788 G3 earned precision:llm 学习词不再恒为 ambiguous——确认证据达标
|
|
113
|
+
* (TP ≥ 3 且零 FP)时升 high,出现任一 FP 即降回 ambiguous。安全姿态不变:
|
|
114
|
+
* LLM 单次建议无法自升 STRONG,必须积累 LLM 确认的正例。owner_promoted 仍按
|
|
115
|
+
* 权重判定(Owner 显式决策不受证据门槛约束)。
|
|
116
|
+
*/
|
|
117
|
+
function precisionFor(source, weight, stats) {
|
|
118
|
+
if (source === 'llm') {
|
|
119
|
+
const tp = stats?.truePositiveCount ?? 0;
|
|
120
|
+
const fp = stats?.falsePositiveCount ?? 0;
|
|
121
|
+
return tp >= EARNED_PRECISION_MIN_TP && fp === 0 ? 'high' : 'ambiguous';
|
|
122
|
+
}
|
|
98
123
|
return weight >= HIGH_PRECISION_LEARNED_WEIGHT ? 'high' : 'ambiguous';
|
|
99
124
|
}
|
|
100
125
|
function projectLearnedStore(raw) {
|
|
@@ -116,7 +141,7 @@ function projectLearnedStore(raw) {
|
|
|
116
141
|
term,
|
|
117
142
|
category: 'correction',
|
|
118
143
|
weight,
|
|
119
|
-
precision: precisionFor(kw.source, weight),
|
|
144
|
+
precision: precisionFor(kw.source, weight, kw),
|
|
120
145
|
source: mapLearnedSource(kw.source),
|
|
121
146
|
};
|
|
122
147
|
if (kw.source === 'llm')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/host-runtime",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@types/node": "^26.4.1",
|
|
32
32
|
"@types/js-yaml": "^4.0.9",
|
|
33
33
|
"typescript": "^7.0.2",
|
|
34
|
-
"vite": "^8.
|
|
34
|
+
"vite": "^8.3.0",
|
|
35
35
|
"vitest": "^5.0.0"
|
|
36
36
|
},
|
|
37
37
|
"repository": {
|