principles-disciple 1.7.6 → 1.7.8
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/dist/commands/context.js +5 -15
- package/dist/commands/evolution-status.js +2 -9
- package/dist/commands/export.js +61 -8
- package/dist/commands/nocturnal-review.d.ts +24 -0
- package/dist/commands/nocturnal-review.js +265 -0
- package/dist/commands/nocturnal-rollout.d.ts +27 -0
- package/dist/commands/nocturnal-rollout.js +671 -0
- package/dist/commands/nocturnal-train.d.ts +25 -0
- package/dist/commands/nocturnal-train.js +919 -0
- package/dist/commands/pain.js +8 -21
- package/dist/constants/tools.d.ts +2 -2
- package/dist/constants/tools.js +1 -1
- package/dist/core/adaptive-thresholds.d.ts +186 -0
- package/dist/core/adaptive-thresholds.js +300 -0
- package/dist/core/config.d.ts +2 -38
- package/dist/core/config.js +6 -61
- package/dist/core/event-log.d.ts +1 -2
- package/dist/core/event-log.js +0 -3
- package/dist/core/evolution-engine.js +1 -21
- package/dist/core/evolution-reducer.d.ts +7 -1
- package/dist/core/evolution-reducer.js +56 -4
- package/dist/core/evolution-types.d.ts +61 -9
- package/dist/core/evolution-types.js +31 -9
- package/dist/core/external-training-contract.d.ts +276 -0
- package/dist/core/external-training-contract.js +269 -0
- package/dist/core/local-worker-routing.d.ts +175 -0
- package/dist/core/local-worker-routing.js +525 -0
- package/dist/core/model-deployment-registry.d.ts +218 -0
- package/dist/core/model-deployment-registry.js +503 -0
- package/dist/core/model-training-registry.d.ts +295 -0
- package/dist/core/model-training-registry.js +475 -0
- package/dist/core/nocturnal-arbiter.d.ts +159 -0
- package/dist/core/nocturnal-arbiter.js +534 -0
- package/dist/core/nocturnal-candidate-scoring.d.ts +137 -0
- package/dist/core/nocturnal-candidate-scoring.js +266 -0
- package/dist/core/nocturnal-compliance.d.ts +175 -0
- package/dist/core/nocturnal-compliance.js +824 -0
- package/dist/core/nocturnal-dataset.d.ts +224 -0
- package/dist/core/nocturnal-dataset.js +443 -0
- package/dist/core/nocturnal-executability.d.ts +85 -0
- package/dist/core/nocturnal-executability.js +331 -0
- package/dist/core/nocturnal-export.d.ts +124 -0
- package/dist/core/nocturnal-export.js +275 -0
- package/dist/core/nocturnal-paths.d.ts +124 -0
- package/dist/core/nocturnal-paths.js +214 -0
- package/dist/core/nocturnal-trajectory-extractor.d.ts +242 -0
- package/dist/core/nocturnal-trajectory-extractor.js +307 -0
- package/dist/core/nocturnal-trinity.d.ts +311 -0
- package/dist/core/nocturnal-trinity.js +880 -0
- package/dist/core/paths.d.ts +6 -0
- package/dist/core/paths.js +6 -0
- package/dist/core/principle-training-state.d.ts +121 -0
- package/dist/core/principle-training-state.js +321 -0
- package/dist/core/promotion-gate.d.ts +238 -0
- package/dist/core/promotion-gate.js +529 -0
- package/dist/core/session-tracker.d.ts +10 -0
- package/dist/core/session-tracker.js +14 -0
- package/dist/core/shadow-observation-registry.d.ts +217 -0
- package/dist/core/shadow-observation-registry.js +308 -0
- package/dist/core/training-program.d.ts +233 -0
- package/dist/core/training-program.js +433 -0
- package/dist/core/trajectory.d.ts +95 -1
- package/dist/core/trajectory.js +220 -6
- package/dist/core/workspace-context.d.ts +0 -6
- package/dist/core/workspace-context.js +0 -12
- package/dist/hooks/bash-risk.d.ts +6 -6
- package/dist/hooks/bash-risk.js +8 -8
- package/dist/hooks/gate-block-helper.js +1 -1
- package/dist/hooks/gate.d.ts +1 -1
- package/dist/hooks/gate.js +2 -2
- package/dist/hooks/gfi-gate.d.ts +3 -3
- package/dist/hooks/gfi-gate.js +15 -14
- package/dist/hooks/pain.js +6 -9
- package/dist/hooks/progressive-trust-gate.d.ts +21 -49
- package/dist/hooks/progressive-trust-gate.js +51 -204
- package/dist/hooks/prompt.d.ts +11 -11
- package/dist/hooks/prompt.js +158 -72
- package/dist/hooks/subagent.js +43 -6
- package/dist/i18n/commands.js +8 -8
- package/dist/index.js +129 -28
- package/dist/service/evolution-worker.d.ts +42 -4
- package/dist/service/evolution-worker.js +321 -13
- package/dist/service/nocturnal-runtime.d.ts +183 -0
- package/dist/service/nocturnal-runtime.js +352 -0
- package/dist/service/nocturnal-service.d.ts +163 -0
- package/dist/service/nocturnal-service.js +787 -0
- package/dist/service/nocturnal-target-selector.d.ts +145 -0
- package/dist/service/nocturnal-target-selector.js +315 -0
- package/dist/service/phase3-input-filter.d.ts +2 -23
- package/dist/service/phase3-input-filter.js +3 -27
- package/dist/service/runtime-summary-service.d.ts +0 -10
- package/dist/service/runtime-summary-service.js +1 -54
- package/dist/tools/deep-reflect.js +2 -1
- package/dist/types/event-types.d.ts +2 -10
- package/dist/types/runtime-summary.d.ts +1 -8
- package/dist/types.d.ts +0 -3
- package/dist/types.js +0 -2
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/templates/langs/en/skills/pd-mentor/SKILL.md +5 -5
- package/templates/langs/zh/skills/pd-mentor/SKILL.md +5 -5
- package/templates/pain_settings.json +0 -6
- package/dist/commands/trust.d.ts +0 -4
- package/dist/commands/trust.js +0 -78
- package/dist/core/trust-engine.d.ts +0 -96
- package/dist/core/trust-engine.js +0 -286
package/dist/commands/pain.js
CHANGED
|
@@ -88,11 +88,6 @@ export function handlePainCommand(ctx) {
|
|
|
88
88
|
}
|
|
89
89
|
return { text: isZh ? `❌ 无法识别当前会话。` : `❌ Session ID not found. Use /pd-status reset in a chat session.` };
|
|
90
90
|
}
|
|
91
|
-
if (args === 'trust-reset') {
|
|
92
|
-
wctx.trust.resetTrust();
|
|
93
|
-
const newScore = wctx.trust.getScore();
|
|
94
|
-
return { text: isZh ? `✅ 智能体信任分已重置为初始值 (${newScore})。` : `✅ Agent trust score has been reset to initial value (${newScore}).` };
|
|
95
|
-
}
|
|
96
91
|
if (args === 'data') {
|
|
97
92
|
const stats = wctx.trajectory.getDataStats();
|
|
98
93
|
return {
|
|
@@ -106,11 +101,7 @@ export function handlePainCommand(ctx) {
|
|
|
106
101
|
const gfi = session ? session.currentGfi : 0;
|
|
107
102
|
const dictionary = wctx.dictionary;
|
|
108
103
|
const stats = dictionary.getStats();
|
|
109
|
-
const trust = wctx.trust;
|
|
110
|
-
const trustScore = trust.getScore();
|
|
111
|
-
const trustStage = trust.getStage();
|
|
112
104
|
const gfiBar = createProgressBar(gfi, 100, 15);
|
|
113
|
-
const trustBar = createProgressBar(trustScore, 100, 15);
|
|
114
105
|
// Determine Mental Mode (aligned with prompt.ts logic)
|
|
115
106
|
let mentalMode = '';
|
|
116
107
|
if (isZh) {
|
|
@@ -133,14 +124,13 @@ export function handlePainCommand(ctx) {
|
|
|
133
124
|
let healthLabel = 'Healthy';
|
|
134
125
|
let suggestionText = '';
|
|
135
126
|
if (isZh) {
|
|
136
|
-
if (gfi > 80
|
|
137
|
-
healthLabel =
|
|
127
|
+
if (gfi > 80) {
|
|
128
|
+
healthLabel = '极度疲劳 🔴';
|
|
138
129
|
suggestionText = `
|
|
139
130
|
💡 **建议 (系统检测到您当前遇到较大阻力)**:
|
|
140
131
|
1. 执行 \`/pd-status reset\` 清零疲劳值。
|
|
141
|
-
2.
|
|
142
|
-
3.
|
|
143
|
-
4. 如果当前上下文太乱,考虑使用 \`/clear\` 开启新会话。`;
|
|
132
|
+
2. 让 AI 调用 \`deep_reflect\` 工具进行深度反思。
|
|
133
|
+
3. 如果当前上下文太乱,考虑使用 \`/clear\` 开启新会话。`;
|
|
144
134
|
}
|
|
145
135
|
else if (gfi > 50)
|
|
146
136
|
healthLabel = '遇到阻力 🟡';
|
|
@@ -150,13 +140,12 @@ export function handlePainCommand(ctx) {
|
|
|
150
140
|
healthLabel = '运转良好 🟢';
|
|
151
141
|
}
|
|
152
142
|
else {
|
|
153
|
-
if (gfi > 80
|
|
154
|
-
healthLabel =
|
|
143
|
+
if (gfi > 80) {
|
|
144
|
+
healthLabel = 'Critical 🔴';
|
|
155
145
|
suggestionText = `
|
|
156
|
-
💡 **Suggestion (High friction
|
|
146
|
+
💡 **Suggestion (High friction detected)**:
|
|
157
147
|
1. Run \`/pd-status reset\` to clear friction.
|
|
158
|
-
2.
|
|
159
|
-
3. Ask the AI to use the \`deep_reflect\` tool.
|
|
148
|
+
2. Ask the AI to use the \`deep_reflect\` tool.
|
|
160
149
|
4. Consider starting a new session with \`/clear\`.`;
|
|
161
150
|
}
|
|
162
151
|
else if (gfi > 50)
|
|
@@ -178,7 +167,6 @@ export function handlePainCommand(ctx) {
|
|
|
178
167
|
let text = `📊 **Principles Disciple - 系统健康度监控**\n`;
|
|
179
168
|
text += `━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n`;
|
|
180
169
|
text += `💊 **当前疲劳指数 (GFI)**: ${gfiBar} ${gfi}/100\n`;
|
|
181
|
-
text += `💰 **当前信任积分 (Trust)**: ${trustBar} ${trustScore}/100 (Stage ${trustStage})\n`;
|
|
182
170
|
text += `🧠 **当前心智模式**: ${mentalMode}\n`;
|
|
183
171
|
text += ` ↳ 状态诊断: ${healthLabel}\n`;
|
|
184
172
|
text += empathyInline;
|
|
@@ -197,7 +185,6 @@ export function handlePainCommand(ctx) {
|
|
|
197
185
|
let text = `📊 **Principles Disciple - System Health Monitor**\n`;
|
|
198
186
|
text += `━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n`;
|
|
199
187
|
text += `💊 **Current Friction (GFI)**: ${gfiBar} ${gfi}/100\n`;
|
|
200
|
-
text += `💰 **Current Trust Score**: ${trustBar} ${trustScore}/100 (Stage ${trustStage})\n`;
|
|
201
188
|
text += `🧠 **Current Mental Mode**: ${mentalMode}\n`;
|
|
202
189
|
text += ` ↳ Diagnosis: ${healthLabel}\n`;
|
|
203
190
|
text += empathyInline;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export declare const READ_ONLY_TOOL_NAMES: readonly ["read", "read_file", "read_many_files", "image_read", "search_file_content", "grep", "grep_search", "list_directory", "ls", "glob", "lsp_hover", "lsp_goto_definition", "lsp_find_references", "web_fetch", "web_search", "ref_search_documentation", "ref_read_url", "resolve-library-id", "get-library-docs", "memory_recall", "save_memory", "todo_read", "todo_write", "ask_user", "ask_user_question", "deep_reflect", "pd-status", "
|
|
1
|
+
export declare const READ_ONLY_TOOL_NAMES: readonly ["read", "read_file", "read_many_files", "image_read", "search_file_content", "grep", "grep_search", "list_directory", "ls", "glob", "lsp_hover", "lsp_goto_definition", "lsp_find_references", "web_fetch", "web_search", "ref_search_documentation", "ref_read_url", "resolve-library-id", "get-library-docs", "memory_recall", "save_memory", "todo_read", "todo_write", "ask_user", "ask_user_question", "deep_reflect", "pd-status", "report"];
|
|
2
2
|
export declare const LOW_RISK_WRITE_TOOL_NAMES: readonly ["write", "write_file", "edit", "edit_file", "replace", "apply_patch", "insert", "patch"];
|
|
3
3
|
export declare const BASH_TOOL_NAMES: readonly ["bash", "run_shell_command", "exec", "execute", "shell", "cmd"];
|
|
4
4
|
export declare const HIGH_RISK_TOOL_NAMES: readonly ["delete_file", "move_file", "bash", "run_shell_command", "exec", "execute", "shell", "cmd"];
|
|
5
5
|
export declare const AGENT_TOOL_NAMES: readonly ["sessions_spawn"];
|
|
6
6
|
export declare const CONTENT_LIMITED_TOOL_NAMES: readonly ["write", "write_file", "edit", "edit_file", "replace", "apply_patch", "insert", "patch"];
|
|
7
7
|
export declare const CONSTRUCTIVE_TOOL_NAMES: readonly ["write", "write_file", "edit", "edit_file", "replace", "apply_patch", "insert", "patch", "delete_file", "move_file", "bash", "run_shell_command", "exec", "execute", "shell", "cmd", "sessions_spawn", "evolve-task", "init-strategy"];
|
|
8
|
-
export declare const EXPLORATORY_TOOL_NAMES: readonly ["read", "read_file", "read_many_files", "image_read", "search_file_content", "grep", "grep_search", "list_directory", "ls", "glob", "lsp_hover", "lsp_goto_definition", "lsp_find_references", "web_fetch", "web_search", "ref_search_documentation", "ref_read_url", "resolve-library-id", "get-library-docs", "memory_recall", "save_memory", "todo_read", "todo_write", "ask_user", "ask_user_question", "deep_reflect", "pd-status", "
|
|
8
|
+
export declare const EXPLORATORY_TOOL_NAMES: readonly ["read", "read_file", "read_many_files", "image_read", "search_file_content", "grep", "grep_search", "list_directory", "ls", "glob", "lsp_hover", "lsp_goto_definition", "lsp_find_references", "web_fetch", "web_search", "ref_search_documentation", "ref_read_url", "resolve-library-id", "get-library-docs", "memory_recall", "save_memory", "todo_read", "todo_write", "ask_user", "ask_user_question", "deep_reflect", "pd-status", "report"];
|
|
9
9
|
export declare const READ_ONLY_TOOLS: Set<string>;
|
|
10
10
|
export declare const LOW_RISK_WRITE_TOOLS: Set<string>;
|
|
11
11
|
export declare const HIGH_RISK_TOOLS: Set<string>;
|
package/dist/constants/tools.js
CHANGED
|
@@ -7,7 +7,7 @@ export const READ_ONLY_TOOL_NAMES = [
|
|
|
7
7
|
'memory_recall', 'save_memory', 'todo_read', 'todo_write',
|
|
8
8
|
'ask_user', 'ask_user_question',
|
|
9
9
|
'deep_reflect',
|
|
10
|
-
'pd-status', '
|
|
10
|
+
'pd-status', 'report',
|
|
11
11
|
];
|
|
12
12
|
export const LOW_RISK_WRITE_TOOL_NAMES = [
|
|
13
13
|
'write', 'write_file',
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adaptive Thresholds — Bounded Threshold State Management
|
|
3
|
+
* ========================================================
|
|
4
|
+
*
|
|
5
|
+
* PURPOSE: Manage adaptive thresholds for Trinity candidate scoring with
|
|
6
|
+
* bounded, observable, and reproducible threshold changes.
|
|
7
|
+
*
|
|
8
|
+
* DESIGN CONSTRAINTS:
|
|
9
|
+
* - Thresholds only move within bounded ranges (min/max)
|
|
10
|
+
* - Changes depend on explicit observable signals only
|
|
11
|
+
* - No hidden learning loops
|
|
12
|
+
* - Threshold state is persisted and can be rolled back
|
|
13
|
+
* - Corruption or missing state falls back to safe defaults
|
|
14
|
+
*
|
|
15
|
+
* OBSERVABLE SIGNALS:
|
|
16
|
+
* - recent malformed rate (arbiter/executability failures)
|
|
17
|
+
* - recent arbiter reject rate
|
|
18
|
+
* - recent executability reject rate
|
|
19
|
+
* - reviewed subset quality delta
|
|
20
|
+
*
|
|
21
|
+
* PHASE 6 ONLY — No real training, no automatic deployment
|
|
22
|
+
*/
|
|
23
|
+
/** File name for threshold state */
|
|
24
|
+
export declare const THRESHOLD_STATE_FILE = "nocturnal-threshold-state.json";
|
|
25
|
+
/** Default threshold values */
|
|
26
|
+
export declare const DEFAULT_THRESHOLDS: {
|
|
27
|
+
/** Minimum score to pass arbiter validation */
|
|
28
|
+
readonly schemaCompletenessMin: 0.6;
|
|
29
|
+
/** Minimum principle alignment score */
|
|
30
|
+
readonly principleAlignmentMin: 0.7;
|
|
31
|
+
/** Minimum executability score */
|
|
32
|
+
readonly executabilityMin: 0.65;
|
|
33
|
+
/** Minimum boundedness score */
|
|
34
|
+
readonly boundednessMin: 0.5;
|
|
35
|
+
/** Minimum confidence/consistency score */
|
|
36
|
+
readonly confidenceMin: 0.6;
|
|
37
|
+
/** Minimum aggregate score to be tournament-eligible */
|
|
38
|
+
readonly aggregateMin: 0.65;
|
|
39
|
+
};
|
|
40
|
+
/** Minimum threshold value (safety bound) */
|
|
41
|
+
export declare const THRESHOLD_MIN = 0;
|
|
42
|
+
/** Maximum threshold value (safety bound) */
|
|
43
|
+
export declare const THRESHOLD_MAX = 1;
|
|
44
|
+
/** Maximum adjustment per update (bounded step size) */
|
|
45
|
+
export declare const MAX_ADJUSTMENT_PER_STEP = 0.05;
|
|
46
|
+
/** Minimum adjustment to trigger a change */
|
|
47
|
+
export declare const MIN_ADJUSTMENT_TO_RECORD = 0.01;
|
|
48
|
+
/**
|
|
49
|
+
* All threshold names that can be adaptively adjusted.
|
|
50
|
+
*/
|
|
51
|
+
export type ThresholdName = keyof typeof DEFAULT_THRESHOLDS;
|
|
52
|
+
/**
|
|
53
|
+
* Current threshold values.
|
|
54
|
+
*/
|
|
55
|
+
export interface ThresholdValues {
|
|
56
|
+
schemaCompletenessMin: number;
|
|
57
|
+
principleAlignmentMin: number;
|
|
58
|
+
executabilityMin: number;
|
|
59
|
+
boundednessMin: number;
|
|
60
|
+
confidenceMin: number;
|
|
61
|
+
aggregateMin: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Threshold state for one threshold.
|
|
65
|
+
*/
|
|
66
|
+
export interface ThresholdState {
|
|
67
|
+
/** Current value */
|
|
68
|
+
currentValue: number;
|
|
69
|
+
/** Minimum bound */
|
|
70
|
+
minValue: number;
|
|
71
|
+
/** Maximum bound */
|
|
72
|
+
maxValue: number;
|
|
73
|
+
/** Last updated timestamp (ISO string) */
|
|
74
|
+
lastUpdatedAt: string;
|
|
75
|
+
/** Reason for last adjustment */
|
|
76
|
+
adjustmentReason?: string;
|
|
77
|
+
/** Number of adjustments made */
|
|
78
|
+
adjustmentCount: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Complete threshold state persisted to disk.
|
|
82
|
+
*/
|
|
83
|
+
export interface ThresholdPersistenceState {
|
|
84
|
+
/** Individual threshold states */
|
|
85
|
+
thresholds: Record<ThresholdName, ThresholdState>;
|
|
86
|
+
/** When the state was last updated (any threshold) */
|
|
87
|
+
lastUpdatedAt: string;
|
|
88
|
+
/** Version for migration support */
|
|
89
|
+
version: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Observable signals used to adjust thresholds.
|
|
93
|
+
*/
|
|
94
|
+
export interface ThresholdSignals {
|
|
95
|
+
/** Rate of malformed outputs (0-1) */
|
|
96
|
+
malformedRate: number;
|
|
97
|
+
/** Rate of arbiter rejections (0-1) */
|
|
98
|
+
arbiterRejectRate: number;
|
|
99
|
+
/** Rate of executability rejections (0-1) */
|
|
100
|
+
executabilityRejectRate: number;
|
|
101
|
+
/** Quality delta from reviewed subset comparison (positive = improvement) */
|
|
102
|
+
qualityDelta: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Result of loading threshold state.
|
|
106
|
+
*/
|
|
107
|
+
export interface LoadThresholdResult {
|
|
108
|
+
/** Whether loading succeeded */
|
|
109
|
+
success: boolean;
|
|
110
|
+
/** Current threshold values */
|
|
111
|
+
thresholds: ThresholdValues;
|
|
112
|
+
/** Whether fallback to defaults was used */
|
|
113
|
+
usedDefaults: boolean;
|
|
114
|
+
/** Error message if failed */
|
|
115
|
+
error?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Result of updating a threshold.
|
|
119
|
+
*/
|
|
120
|
+
export interface UpdateThresholdResult {
|
|
121
|
+
/** Whether update succeeded */
|
|
122
|
+
success: boolean;
|
|
123
|
+
/** The updated threshold values */
|
|
124
|
+
thresholds: ThresholdValues;
|
|
125
|
+
/** Whether a change actually occurred */
|
|
126
|
+
changed: boolean;
|
|
127
|
+
/** The name of the changed threshold */
|
|
128
|
+
changedThreshold?: ThresholdName;
|
|
129
|
+
/** The old value */
|
|
130
|
+
oldValue?: number;
|
|
131
|
+
/** The new value */
|
|
132
|
+
newValue?: number;
|
|
133
|
+
/** Reason for the change */
|
|
134
|
+
reason?: string;
|
|
135
|
+
/** Error message if failed */
|
|
136
|
+
error?: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Load threshold values with fallback to defaults on corruption.
|
|
140
|
+
*
|
|
141
|
+
* @param stateDir - State directory
|
|
142
|
+
* @returns LoadThresholdResult with current values and status
|
|
143
|
+
*/
|
|
144
|
+
export declare function loadThresholdState(stateDir: string): LoadThresholdResult;
|
|
145
|
+
/**
|
|
146
|
+
* Get effective threshold values (alias for loadThresholdState).
|
|
147
|
+
*
|
|
148
|
+
* @param stateDir - State directory
|
|
149
|
+
* @returns Current threshold values
|
|
150
|
+
*/
|
|
151
|
+
export declare function getEffectiveThresholds(stateDir: string): ThresholdValues;
|
|
152
|
+
/**
|
|
153
|
+
* Update a single threshold with bounded step size.
|
|
154
|
+
*
|
|
155
|
+
* @param stateDir - State directory
|
|
156
|
+
* @param thresholdName - Name of threshold to update
|
|
157
|
+
* @param newValue - New value (will be clamped to bounds)
|
|
158
|
+
* @param reason - Reason for the adjustment (required for tracking)
|
|
159
|
+
* @returns UpdateThresholdResult
|
|
160
|
+
*/
|
|
161
|
+
export declare function updateThresholdState(stateDir: string, thresholdName: ThresholdName, newValue: number, reason: string): UpdateThresholdResult;
|
|
162
|
+
/**
|
|
163
|
+
* Reset all thresholds to defaults.
|
|
164
|
+
*
|
|
165
|
+
* @param stateDir - State directory
|
|
166
|
+
*/
|
|
167
|
+
export declare function resetThresholdState(stateDir: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* Get detailed threshold state for debugging/inspection.
|
|
170
|
+
*
|
|
171
|
+
* @param stateDir - State directory
|
|
172
|
+
* @returns Detailed threshold state or null if corrupted
|
|
173
|
+
*/
|
|
174
|
+
export declare function getDetailedThresholdState(stateDir: string): ThresholdPersistenceState | null;
|
|
175
|
+
/**
|
|
176
|
+
* Adjust thresholds based on observable signals.
|
|
177
|
+
*
|
|
178
|
+
* This is a simple proportional controller that adjusts thresholds
|
|
179
|
+
* based on observed rejection rates. The adjustment is bounded
|
|
180
|
+
* and requires a minimum signal magnitude to trigger.
|
|
181
|
+
*
|
|
182
|
+
* @param stateDir - State directory
|
|
183
|
+
* @param signals - Observable signals
|
|
184
|
+
* @returns UpdateThresholdResult describing the most significant change
|
|
185
|
+
*/
|
|
186
|
+
export declare function adjustThresholdsFromSignals(stateDir: string, signals: ThresholdSignals): UpdateThresholdResult;
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adaptive Thresholds — Bounded Threshold State Management
|
|
3
|
+
* ========================================================
|
|
4
|
+
*
|
|
5
|
+
* PURPOSE: Manage adaptive thresholds for Trinity candidate scoring with
|
|
6
|
+
* bounded, observable, and reproducible threshold changes.
|
|
7
|
+
*
|
|
8
|
+
* DESIGN CONSTRAINTS:
|
|
9
|
+
* - Thresholds only move within bounded ranges (min/max)
|
|
10
|
+
* - Changes depend on explicit observable signals only
|
|
11
|
+
* - No hidden learning loops
|
|
12
|
+
* - Threshold state is persisted and can be rolled back
|
|
13
|
+
* - Corruption or missing state falls back to safe defaults
|
|
14
|
+
*
|
|
15
|
+
* OBSERVABLE SIGNALS:
|
|
16
|
+
* - recent malformed rate (arbiter/executability failures)
|
|
17
|
+
* - recent arbiter reject rate
|
|
18
|
+
* - recent executability reject rate
|
|
19
|
+
* - reviewed subset quality delta
|
|
20
|
+
*
|
|
21
|
+
* PHASE 6 ONLY — No real training, no automatic deployment
|
|
22
|
+
*/
|
|
23
|
+
import * as fs from 'fs';
|
|
24
|
+
import * as path from 'path';
|
|
25
|
+
import { withLock } from '../utils/file-lock.js';
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Constants
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
/** File name for threshold state */
|
|
30
|
+
export const THRESHOLD_STATE_FILE = 'nocturnal-threshold-state.json';
|
|
31
|
+
/** Default threshold values */
|
|
32
|
+
export const DEFAULT_THRESHOLDS = {
|
|
33
|
+
/** Minimum score to pass arbiter validation */
|
|
34
|
+
schemaCompletenessMin: 0.6,
|
|
35
|
+
/** Minimum principle alignment score */
|
|
36
|
+
principleAlignmentMin: 0.7,
|
|
37
|
+
/** Minimum executability score */
|
|
38
|
+
executabilityMin: 0.65,
|
|
39
|
+
/** Minimum boundedness score */
|
|
40
|
+
boundednessMin: 0.5,
|
|
41
|
+
/** Minimum confidence/consistency score */
|
|
42
|
+
confidenceMin: 0.6,
|
|
43
|
+
/** Minimum aggregate score to be tournament-eligible */
|
|
44
|
+
aggregateMin: 0.65,
|
|
45
|
+
};
|
|
46
|
+
/** Minimum threshold value (safety bound) */
|
|
47
|
+
export const THRESHOLD_MIN = 0.0;
|
|
48
|
+
/** Maximum threshold value (safety bound) */
|
|
49
|
+
export const THRESHOLD_MAX = 1.0;
|
|
50
|
+
/** Maximum adjustment per update (bounded step size) */
|
|
51
|
+
export const MAX_ADJUSTMENT_PER_STEP = 0.05;
|
|
52
|
+
/** Minimum adjustment to trigger a change */
|
|
53
|
+
export const MIN_ADJUSTMENT_TO_RECORD = 0.01;
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
// State Persistence
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
/**
|
|
58
|
+
* Get the threshold state file path.
|
|
59
|
+
*/
|
|
60
|
+
function getStatePath(stateDir) {
|
|
61
|
+
return path.join(stateDir, THRESHOLD_STATE_FILE);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create default threshold persistence state.
|
|
65
|
+
*/
|
|
66
|
+
function createDefaultState() {
|
|
67
|
+
const now = new Date().toISOString();
|
|
68
|
+
const thresholds = {};
|
|
69
|
+
for (const [name, defaultValue] of Object.entries(DEFAULT_THRESHOLDS)) {
|
|
70
|
+
thresholds[name] = {
|
|
71
|
+
currentValue: defaultValue,
|
|
72
|
+
minValue: THRESHOLD_MIN,
|
|
73
|
+
maxValue: THRESHOLD_MAX,
|
|
74
|
+
lastUpdatedAt: now,
|
|
75
|
+
adjustmentCount: 0,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
thresholds,
|
|
80
|
+
lastUpdatedAt: now,
|
|
81
|
+
version: 1,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Read threshold state from disk (with locking).
|
|
86
|
+
*/
|
|
87
|
+
function readState(stateDir) {
|
|
88
|
+
const statePath = getStatePath(stateDir);
|
|
89
|
+
if (!fs.existsSync(statePath)) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const content = fs.readFileSync(statePath, 'utf-8');
|
|
94
|
+
const parsed = JSON.parse(content);
|
|
95
|
+
return parsed;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Corrupted — return null to trigger default fallback
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Write threshold state to disk (with locking).
|
|
104
|
+
*/
|
|
105
|
+
function writeState(stateDir, state) {
|
|
106
|
+
const statePath = getStatePath(stateDir);
|
|
107
|
+
const stateDirPath = path.dirname(statePath);
|
|
108
|
+
if (!fs.existsSync(stateDirPath)) {
|
|
109
|
+
fs.mkdirSync(stateDirPath, { recursive: true });
|
|
110
|
+
}
|
|
111
|
+
withLock(statePath, () => {
|
|
112
|
+
const tmpPath = `${statePath}.tmp`;
|
|
113
|
+
fs.writeFileSync(tmpPath, JSON.stringify(state, null, 2), 'utf-8');
|
|
114
|
+
fs.renameSync(tmpPath, statePath);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
// Core Threshold Operations
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
/**
|
|
121
|
+
* Load threshold values with fallback to defaults on corruption.
|
|
122
|
+
*
|
|
123
|
+
* @param stateDir - State directory
|
|
124
|
+
* @returns LoadThresholdResult with current values and status
|
|
125
|
+
*/
|
|
126
|
+
export function loadThresholdState(stateDir) {
|
|
127
|
+
const rawState = readState(stateDir);
|
|
128
|
+
if (!rawState) {
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
thresholds: { ...DEFAULT_THRESHOLDS },
|
|
132
|
+
usedDefaults: true,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// Validate and reconstruct threshold values
|
|
136
|
+
const thresholds = { ...DEFAULT_THRESHOLDS };
|
|
137
|
+
let usedDefaults = false;
|
|
138
|
+
for (const [name, defaultValue] of Object.entries(DEFAULT_THRESHOLDS)) {
|
|
139
|
+
const key = name;
|
|
140
|
+
const state = rawState.thresholds[key];
|
|
141
|
+
if (state && typeof state.currentValue === 'number') {
|
|
142
|
+
// Clamp to bounds (defensive)
|
|
143
|
+
thresholds[key] = Math.max(state.minValue, Math.min(state.maxValue, state.currentValue));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
thresholds[key] = defaultValue;
|
|
147
|
+
usedDefaults = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
success: true,
|
|
152
|
+
thresholds: thresholds,
|
|
153
|
+
usedDefaults,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get effective threshold values (alias for loadThresholdState).
|
|
158
|
+
*
|
|
159
|
+
* @param stateDir - State directory
|
|
160
|
+
* @returns Current threshold values
|
|
161
|
+
*/
|
|
162
|
+
export function getEffectiveThresholds(stateDir) {
|
|
163
|
+
const result = loadThresholdState(stateDir);
|
|
164
|
+
return result.thresholds;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Update a single threshold with bounded step size.
|
|
168
|
+
*
|
|
169
|
+
* @param stateDir - State directory
|
|
170
|
+
* @param thresholdName - Name of threshold to update
|
|
171
|
+
* @param newValue - New value (will be clamped to bounds)
|
|
172
|
+
* @param reason - Reason for the adjustment (required for tracking)
|
|
173
|
+
* @returns UpdateThresholdResult
|
|
174
|
+
*/
|
|
175
|
+
export function updateThresholdState(stateDir, thresholdName, newValue, reason) {
|
|
176
|
+
// Read current state
|
|
177
|
+
let rawState = readState(stateDir);
|
|
178
|
+
if (!rawState) {
|
|
179
|
+
rawState = createDefaultState();
|
|
180
|
+
}
|
|
181
|
+
const currentState = rawState.thresholds[thresholdName];
|
|
182
|
+
if (!currentState) {
|
|
183
|
+
return {
|
|
184
|
+
success: false,
|
|
185
|
+
thresholds: { ...DEFAULT_THRESHOLDS },
|
|
186
|
+
changed: false,
|
|
187
|
+
error: `Unknown threshold: ${thresholdName}`,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// Calculate bounded new value
|
|
191
|
+
const clampedValue = Math.max(currentState.minValue, Math.min(currentState.maxValue, newValue));
|
|
192
|
+
// Check if change is meaningful
|
|
193
|
+
const delta = Math.abs(clampedValue - currentState.currentValue);
|
|
194
|
+
if (delta < MIN_ADJUSTMENT_TO_RECORD) {
|
|
195
|
+
return {
|
|
196
|
+
success: true,
|
|
197
|
+
thresholds: getEffectiveThresholds(stateDir),
|
|
198
|
+
changed: false,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
// Enforce maximum step size for bounded, safe threshold adjustments
|
|
202
|
+
let finalValue = clampedValue;
|
|
203
|
+
if (delta > MAX_ADJUSTMENT_PER_STEP) {
|
|
204
|
+
const direction = clampedValue > currentState.currentValue ? 1 : -1;
|
|
205
|
+
finalValue = currentState.currentValue + direction * MAX_ADJUSTMENT_PER_STEP;
|
|
206
|
+
}
|
|
207
|
+
// Update state
|
|
208
|
+
const now = new Date().toISOString();
|
|
209
|
+
rawState.thresholds[thresholdName] = {
|
|
210
|
+
...currentState,
|
|
211
|
+
currentValue: finalValue,
|
|
212
|
+
lastUpdatedAt: now,
|
|
213
|
+
adjustmentReason: reason,
|
|
214
|
+
adjustmentCount: currentState.adjustmentCount + 1,
|
|
215
|
+
};
|
|
216
|
+
rawState.lastUpdatedAt = now;
|
|
217
|
+
writeState(stateDir, rawState);
|
|
218
|
+
return {
|
|
219
|
+
success: true,
|
|
220
|
+
thresholds: getEffectiveThresholds(stateDir),
|
|
221
|
+
changed: true,
|
|
222
|
+
changedThreshold: thresholdName,
|
|
223
|
+
oldValue: currentState.currentValue,
|
|
224
|
+
newValue: finalValue,
|
|
225
|
+
reason,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Reset all thresholds to defaults.
|
|
230
|
+
*
|
|
231
|
+
* @param stateDir - State directory
|
|
232
|
+
*/
|
|
233
|
+
export function resetThresholdState(stateDir) {
|
|
234
|
+
const defaultState = createDefaultState();
|
|
235
|
+
writeState(stateDir, defaultState);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get detailed threshold state for debugging/inspection.
|
|
239
|
+
*
|
|
240
|
+
* @param stateDir - State directory
|
|
241
|
+
* @returns Detailed threshold state or null if corrupted
|
|
242
|
+
*/
|
|
243
|
+
export function getDetailedThresholdState(stateDir) {
|
|
244
|
+
return readState(stateDir);
|
|
245
|
+
}
|
|
246
|
+
// ---------------------------------------------------------------------------
|
|
247
|
+
// Signal-Based Threshold Adjustment
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
/**
|
|
250
|
+
* Adjust thresholds based on observable signals.
|
|
251
|
+
*
|
|
252
|
+
* This is a simple proportional controller that adjusts thresholds
|
|
253
|
+
* based on observed rejection rates. The adjustment is bounded
|
|
254
|
+
* and requires a minimum signal magnitude to trigger.
|
|
255
|
+
*
|
|
256
|
+
* @param stateDir - State directory
|
|
257
|
+
* @param signals - Observable signals
|
|
258
|
+
* @returns UpdateThresholdResult describing the most significant change
|
|
259
|
+
*/
|
|
260
|
+
export function adjustThresholdsFromSignals(stateDir, signals) {
|
|
261
|
+
const currentThresholds = getEffectiveThresholds(stateDir);
|
|
262
|
+
let bestResult = {
|
|
263
|
+
success: true,
|
|
264
|
+
thresholds: currentThresholds,
|
|
265
|
+
changed: false,
|
|
266
|
+
};
|
|
267
|
+
// High malformed rate → tighten schema completeness threshold
|
|
268
|
+
if (signals.malformedRate > 0.3) {
|
|
269
|
+
const adjustment = signals.malformedRate * 0.1;
|
|
270
|
+
const newValue = currentThresholds.schemaCompletenessMin + adjustment;
|
|
271
|
+
const result = updateThresholdState(stateDir, 'schemaCompletenessMin', newValue, `High malformed rate (${signals.malformedRate.toFixed(2)}) → tightening schema threshold`);
|
|
272
|
+
if (result.changed)
|
|
273
|
+
bestResult = result;
|
|
274
|
+
}
|
|
275
|
+
// High arbiter reject rate → tighten principle alignment threshold
|
|
276
|
+
if (signals.arbiterRejectRate > 0.25) {
|
|
277
|
+
const adjustment = signals.arbiterRejectRate * 0.08;
|
|
278
|
+
const result = updateThresholdState(stateDir, 'principleAlignmentMin', currentThresholds.principleAlignmentMin + adjustment, `High arbiter reject rate (${signals.arbiterRejectRate.toFixed(2)}) → tightening alignment threshold`);
|
|
279
|
+
if (result.changed && (!bestResult.changed || (result.newValue - result.oldValue) > 0)) {
|
|
280
|
+
bestResult = result;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
// High executability reject rate → tighten executability threshold
|
|
284
|
+
if (signals.executabilityRejectRate > 0.3) {
|
|
285
|
+
const adjustment = signals.executabilityRejectRate * 0.1;
|
|
286
|
+
const result = updateThresholdState(stateDir, 'executabilityMin', currentThresholds.executabilityMin + adjustment, `High executability reject rate (${signals.executabilityRejectRate.toFixed(2)}) → tightening executability threshold`);
|
|
287
|
+
if (result.changed && (!bestResult.changed || (result.newValue - result.oldValue) > 0)) {
|
|
288
|
+
bestResult = result;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// Good quality delta → slightly loosen thresholds (reward good performance)
|
|
292
|
+
if (signals.qualityDelta > 0.1) {
|
|
293
|
+
const reward = Math.min(signals.qualityDelta * 0.05, MAX_ADJUSTMENT_PER_STEP);
|
|
294
|
+
const result = updateThresholdState(stateDir, 'aggregateMin', Math.max(currentThresholds.aggregateMin - reward, THRESHOLD_MIN), `Positive quality delta (${signals.qualityDelta.toFixed(2)}) → rewarding with slightly lower aggregate threshold`);
|
|
295
|
+
if (result.changed && (!bestResult.changed || (result.oldValue - result.newValue) > 0)) {
|
|
296
|
+
bestResult = result;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return bestResult;
|
|
300
|
+
}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -21,51 +21,16 @@ export interface GfiGateSettings {
|
|
|
21
21
|
large_change_block: number;
|
|
22
22
|
};
|
|
23
23
|
large_change_lines: number;
|
|
24
|
-
|
|
24
|
+
ep_tier_multipliers: {
|
|
25
25
|
'1': number;
|
|
26
26
|
'2': number;
|
|
27
27
|
'3': number;
|
|
28
28
|
'4': number;
|
|
29
|
+
'5': number;
|
|
29
30
|
};
|
|
30
31
|
bash_safe_patterns: string[];
|
|
31
32
|
bash_dangerous_patterns: string[];
|
|
32
33
|
}
|
|
33
|
-
export interface TrustSettings {
|
|
34
|
-
stages: {
|
|
35
|
-
stage_1_observer: number;
|
|
36
|
-
stage_2_editor: number;
|
|
37
|
-
stage_3_developer: number;
|
|
38
|
-
};
|
|
39
|
-
cold_start: {
|
|
40
|
-
initial_trust: number;
|
|
41
|
-
grace_failures: number;
|
|
42
|
-
cold_start_period_ms: number;
|
|
43
|
-
};
|
|
44
|
-
penalties: {
|
|
45
|
-
tool_failure_base: number;
|
|
46
|
-
risky_failure_base: number;
|
|
47
|
-
gate_bypass_attempt: number;
|
|
48
|
-
failure_streak_multiplier: number;
|
|
49
|
-
max_penalty: number;
|
|
50
|
-
};
|
|
51
|
-
rewards: {
|
|
52
|
-
success_base: number;
|
|
53
|
-
subagent_success: number;
|
|
54
|
-
tool_success_reward: number;
|
|
55
|
-
streak_bonus_threshold: number;
|
|
56
|
-
streak_bonus: number;
|
|
57
|
-
recovery_boost: number;
|
|
58
|
-
max_reward: number;
|
|
59
|
-
};
|
|
60
|
-
limits: {
|
|
61
|
-
stage_2_max_lines: number;
|
|
62
|
-
stage_3_max_lines: number;
|
|
63
|
-
stage_2_max_percentage: number;
|
|
64
|
-
stage_3_max_percentage: number;
|
|
65
|
-
min_lines_fallback: number;
|
|
66
|
-
};
|
|
67
|
-
history_limit?: number;
|
|
68
|
-
}
|
|
69
34
|
export interface DiagnosticianSettings {
|
|
70
35
|
context: {
|
|
71
36
|
time_window_minutes: number;
|
|
@@ -110,7 +75,6 @@ export interface PainSettings {
|
|
|
110
75
|
initial_delay_ms: number;
|
|
111
76
|
task_timeout_ms: number;
|
|
112
77
|
};
|
|
113
|
-
trust: TrustSettings;
|
|
114
78
|
deep_reflection?: DeepReflectionSettings;
|
|
115
79
|
empathy_engine?: {
|
|
116
80
|
enabled?: boolean;
|