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/core/config.js
CHANGED
|
@@ -46,46 +46,6 @@ export const DEFAULT_SETTINGS = {
|
|
|
46
46
|
initial_delay_ms: 5000,
|
|
47
47
|
task_timeout_ms: 60 * 60 * 1000 // 1 hour, matching evolution-worker.ts default
|
|
48
48
|
},
|
|
49
|
-
trust: {
|
|
50
|
-
stages: {
|
|
51
|
-
stage_1_observer: 30,
|
|
52
|
-
stage_2_editor: 60,
|
|
53
|
-
stage_3_developer: 80,
|
|
54
|
-
},
|
|
55
|
-
cold_start: {
|
|
56
|
-
// 🚀 The most important change: Start at 85 (Developer level)
|
|
57
|
-
// This allows the AI to perform medium-sized edits right out of the box
|
|
58
|
-
// without needing to beg for a PLAN.md on every single change.
|
|
59
|
-
initial_trust: 85,
|
|
60
|
-
grace_failures: 5, // Give the AI 5 free mistakes before deducting any trust points
|
|
61
|
-
cold_start_period_ms: 24 * 60 * 60 * 1000,
|
|
62
|
-
},
|
|
63
|
-
penalties: {
|
|
64
|
-
// 🛡️ Forgiving penalties for exploration
|
|
65
|
-
tool_failure_base: -2, // Was -8. A simple 'ls' typo shouldn't cost 8 points.
|
|
66
|
-
risky_failure_base: -10, // Was -15.
|
|
67
|
-
gate_bypass_attempt: -5,
|
|
68
|
-
failure_streak_multiplier: -2,
|
|
69
|
-
max_penalty: -20,
|
|
70
|
-
},
|
|
71
|
-
rewards: {
|
|
72
|
-
success_base: 2, // Was 1. Faster recovery
|
|
73
|
-
subagent_success: 5, // Was 3.
|
|
74
|
-
tool_success_reward: 0.2, // 👈 Minor reward for tool success, but resets streak!
|
|
75
|
-
streak_bonus_threshold: 3, // Was 5. Easier to get bonuses
|
|
76
|
-
streak_bonus: 5,
|
|
77
|
-
recovery_boost: 5, // Was 3. If trust drops low, it's easier to climb back up
|
|
78
|
-
max_reward: 15,
|
|
79
|
-
},
|
|
80
|
-
limits: {
|
|
81
|
-
stage_2_max_lines: 50, // Was 10. 10 lines is barely enough to fix a function signature.
|
|
82
|
-
stage_3_max_lines: 300, // Was 100. Allow substantial feature implementation.
|
|
83
|
-
stage_2_max_percentage: 10, // Percentage-based threshold for Stage 2
|
|
84
|
-
stage_3_max_percentage: 15, // Percentage-based threshold for Stage 3
|
|
85
|
-
min_lines_fallback: 20, // Minimum threshold even for small files
|
|
86
|
-
},
|
|
87
|
-
history_limit: 50
|
|
88
|
-
},
|
|
89
49
|
deep_reflection: {
|
|
90
50
|
enabled: true,
|
|
91
51
|
mode: 'auto',
|
|
@@ -122,11 +82,12 @@ export const DEFAULT_SETTINGS = {
|
|
|
122
82
|
large_change_block: 50, // 大规模修改警告阈值
|
|
123
83
|
},
|
|
124
84
|
large_change_lines: 50,
|
|
125
|
-
|
|
126
|
-
'1': 0.5, //
|
|
127
|
-
'2': 0.75, //
|
|
128
|
-
'3': 1.0, //
|
|
129
|
-
'4': 1.5, //
|
|
85
|
+
ep_tier_multipliers: {
|
|
86
|
+
'1': 0.5, // Seed: 更严格,阈值减半
|
|
87
|
+
'2': 0.75, // Sprout: 阈值降低 25%
|
|
88
|
+
'3': 1.0, // Sapling: 标准阈值
|
|
89
|
+
'4': 1.5, // Tree: 更宽松
|
|
90
|
+
'5': 2.0, // Forest: 最宽松
|
|
130
91
|
},
|
|
131
92
|
bash_safe_patterns: [
|
|
132
93
|
'^(ls|dir|pwd|which|where|echo|env|cat|type|head|tail|less|more)\\b',
|
|
@@ -216,25 +177,9 @@ export class PainConfig {
|
|
|
216
177
|
* Basic validation for critical settings
|
|
217
178
|
*/
|
|
218
179
|
validate(settings) {
|
|
219
|
-
// Ensure trust scores stay within 0-100 logical range
|
|
220
|
-
const s = settings.trust.stages;
|
|
221
|
-
if (s.stage_1_observer < 0 || s.stage_1_observer > 100)
|
|
222
|
-
s.stage_1_observer = 30;
|
|
223
|
-
if (s.stage_2_editor < 0 || s.stage_2_editor > 100)
|
|
224
|
-
s.stage_2_editor = 60;
|
|
225
|
-
if (s.stage_3_developer < 0 || s.stage_3_developer > 100)
|
|
226
|
-
s.stage_3_developer = 80;
|
|
227
180
|
// Ensure intervals are positive
|
|
228
181
|
if (settings.intervals.worker_poll_ms < 1000)
|
|
229
182
|
settings.intervals.worker_poll_ms = 15 * 60 * 1000;
|
|
230
|
-
// Ensure percentage limits are in valid range [0, 100]
|
|
231
|
-
const l = settings.trust.limits;
|
|
232
|
-
if (l.stage_2_max_percentage < 0 || l.stage_2_max_percentage > 100)
|
|
233
|
-
l.stage_2_max_percentage = 10;
|
|
234
|
-
if (l.stage_3_max_percentage < 0 || l.stage_3_max_percentage > 100)
|
|
235
|
-
l.stage_3_max_percentage = 15;
|
|
236
|
-
if (l.min_lines_fallback < 1)
|
|
237
|
-
l.min_lines_fallback = 20;
|
|
238
183
|
}
|
|
239
184
|
/**
|
|
240
185
|
* Gets a value using dot notation (e.g. 'thresholds.pain_trigger')
|
package/dist/core/event-log.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EventLogEntry, DailyStats, EmpathyEventStats, ToolCallEventData, PainSignalEventData, RuleMatchEventData, RulePromotionEventData, HookExecutionEventData, GateBlockEventData, GateBypassEventData, PlanApprovalEventData, EvolutionTaskEventData, DeepReflectionEventData,
|
|
1
|
+
import type { EventLogEntry, DailyStats, EmpathyEventStats, ToolCallEventData, PainSignalEventData, RuleMatchEventData, RulePromotionEventData, HookExecutionEventData, GateBlockEventData, GateBypassEventData, PlanApprovalEventData, EvolutionTaskEventData, DeepReflectionEventData, EmpathyRollbackEventData } from '../types/event-types.js';
|
|
2
2
|
import type { PluginLogger } from '../openclaw-sdk.js';
|
|
3
3
|
/**
|
|
4
4
|
* EventLog - Structured event logging with daily statistics aggregation.
|
|
@@ -23,7 +23,6 @@ export declare class EventLog {
|
|
|
23
23
|
recordPlanApproval(sessionId: string | undefined, data: PlanApprovalEventData): void;
|
|
24
24
|
recordEvolutionTask(data: EvolutionTaskEventData): void;
|
|
25
25
|
recordDeepReflection(sessionId: string | undefined, data: DeepReflectionEventData): void;
|
|
26
|
-
recordTrustChange(sessionId: string | undefined, data: TrustChangeEventData): void;
|
|
27
26
|
recordEmpathyRollback(sessionId: string | undefined, data: EmpathyRollbackEventData): void;
|
|
28
27
|
recordError(sessionId: string | undefined, message: string, context?: Record<string, unknown>): void;
|
|
29
28
|
recordWarn(sessionId: string | undefined, message: string, context?: Record<string, unknown>): void;
|
package/dist/core/event-log.js
CHANGED
|
@@ -57,9 +57,6 @@ export class EventLog {
|
|
|
57
57
|
const category = data.passed ? 'passed' : data.timeout ? 'failure' : 'completed';
|
|
58
58
|
this.record('deep_reflection', category, sessionId, data);
|
|
59
59
|
}
|
|
60
|
-
recordTrustChange(sessionId, data) {
|
|
61
|
-
this.record('trust_change', 'changed', sessionId, data);
|
|
62
|
-
}
|
|
63
60
|
recordEmpathyRollback(sessionId, data) {
|
|
64
61
|
this.record('empathy_rollback', 'rolled_back', sessionId, data);
|
|
65
62
|
}
|
|
@@ -14,7 +14,7 @@ import * as fs from 'fs';
|
|
|
14
14
|
import * as path from 'path';
|
|
15
15
|
import { resolvePdPath } from './paths.js';
|
|
16
16
|
import { withLock } from '../utils/file-lock.js';
|
|
17
|
-
import { CONSTRUCTIVE_TOOLS,
|
|
17
|
+
import { CONSTRUCTIVE_TOOLS, EXPLORATORY_TOOLS, HIGH_RISK_TOOLS, } from '../constants/tools.js';
|
|
18
18
|
import { EvolutionTier, DEFAULT_EVOLUTION_CONFIG, TIER_DEFINITIONS, TASK_DIFFICULTY_CONFIG, getTierDefinition, getTierByPoints, } from './evolution-types.js';
|
|
19
19
|
// ===== 主引擎 =====
|
|
20
20
|
export class EvolutionEngine {
|
|
@@ -137,26 +137,6 @@ export class EvolutionEngine {
|
|
|
137
137
|
beforeToolCall(context) {
|
|
138
138
|
const tierDef = this.getTierDefinition();
|
|
139
139
|
const perms = tierDef.permissions;
|
|
140
|
-
// 行数检查(仅针对写操作工具)
|
|
141
|
-
if (CONTENT_LIMITED_TOOLS.has(context.toolName)) {
|
|
142
|
-
if (context.content) {
|
|
143
|
-
const lineCount = context.content.split('\n').length;
|
|
144
|
-
if (lineCount > perms.maxLinesPerWrite) {
|
|
145
|
-
return {
|
|
146
|
-
allowed: false,
|
|
147
|
-
reason: `Tier ${this.scorecard.currentTier} (${tierDef.name}) 限制: 最多 ${perms.maxLinesPerWrite} 行,当前 ${lineCount} 行`,
|
|
148
|
-
currentTier: this.scorecard.currentTier,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (context.lineCount && context.lineCount > perms.maxLinesPerWrite) {
|
|
153
|
-
return {
|
|
154
|
-
allowed: false,
|
|
155
|
-
reason: `Tier ${this.scorecard.currentTier} (${tierDef.name}) 限制: 最多 ${perms.maxLinesPerWrite} 行`,
|
|
156
|
-
currentTier: this.scorecard.currentTier,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
140
|
// 风险路径检查
|
|
161
141
|
if (context.isRiskPath && !perms.allowRiskPath) {
|
|
162
142
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EvolutionLoopEvent, Principle } from './evolution-types.js';
|
|
1
|
+
import type { EvolutionLoopEvent, Principle, PrincipleDetectorSpec, PrincipleEvaluatorLevel } from './evolution-types.js';
|
|
2
2
|
export interface EvolutionReducer {
|
|
3
3
|
emit(event: EvolutionLoopEvent): void;
|
|
4
4
|
emitSync(event: EvolutionLoopEvent): void;
|
|
@@ -21,6 +21,10 @@ export interface EvolutionReducer {
|
|
|
21
21
|
triggerPattern: string;
|
|
22
22
|
action: string;
|
|
23
23
|
source: string;
|
|
24
|
+
/** Evaluability level — defaults to 'manual_only' if omitted */
|
|
25
|
+
evaluability?: PrincipleEvaluatorLevel;
|
|
26
|
+
/** Detector metadata — absent or malformed = 'manual_only' evaluability */
|
|
27
|
+
detectorMetadata?: PrincipleDetectorSpec;
|
|
24
28
|
}): string | null;
|
|
25
29
|
getStats(): {
|
|
26
30
|
candidateCount: number;
|
|
@@ -65,6 +69,8 @@ export declare class EvolutionReducerImpl implements EvolutionReducer {
|
|
|
65
69
|
triggerPattern: string;
|
|
66
70
|
action: string;
|
|
67
71
|
source: string;
|
|
72
|
+
evaluability?: PrincipleEvaluatorLevel;
|
|
73
|
+
detectorMetadata?: PrincipleDetectorSpec;
|
|
68
74
|
}): string | null;
|
|
69
75
|
getStats(): {
|
|
70
76
|
candidateCount: number;
|
|
@@ -6,6 +6,7 @@ import { PathResolver } from './path-resolver.js';
|
|
|
6
6
|
import { SystemLogger } from './system-logger.js';
|
|
7
7
|
import { shouldIgnorePainProtocolText } from './dictionary.js';
|
|
8
8
|
import { TrajectoryRegistry } from './trajectory.js';
|
|
9
|
+
import { isCompleteDetectorMetadata } from './evolution-types.js';
|
|
9
10
|
const PROBATION_SUCCESS_THRESHOLD = 3;
|
|
10
11
|
const CIRCUIT_BREAKER_THRESHOLD = 3;
|
|
11
12
|
const PROBATION_MAX_AGE_DAYS = 30;
|
|
@@ -147,15 +148,45 @@ export class EvolutionReducerImpl {
|
|
|
147
148
|
SystemLogger.log(this.workspaceDir, 'PRINCIPLE_BLACKLISTED', `Principle creation blocked by blacklist for trigger: "${params.triggerPattern.slice(0, 50)}..."`);
|
|
148
149
|
return null;
|
|
149
150
|
}
|
|
151
|
+
// Evaluability defaults to 'manual_only' — the only way to get auto-trainable
|
|
152
|
+
// is to explicitly provide valid detectorMetadata.
|
|
153
|
+
// Enforce: deterministic/weak_heuristic requires complete detectorMetadata to be present.
|
|
154
|
+
let evaluability = params.evaluability ?? 'manual_only';
|
|
155
|
+
if (evaluability !== 'manual_only' && !isCompleteDetectorMetadata(params.detectorMetadata)) {
|
|
156
|
+
SystemLogger.log(this.workspaceDir, 'EVALUABILITY_DOWNGRADED', `Principle for painId "${params.painId}" requested evaluability="${evaluability}" without detectorMetadata — downgrading to "manual_only". Provide valid detectorMetadata to enable auto-training.`);
|
|
157
|
+
evaluability = 'manual_only';
|
|
158
|
+
}
|
|
150
159
|
// Check if a principle already exists for this painId
|
|
151
160
|
const existingPrinciple = [...this.principles.values()].find(p => p.source.painId === params.painId);
|
|
152
161
|
if (existingPrinciple) {
|
|
153
|
-
// Update existing principle instead of creating new one
|
|
162
|
+
// Update existing principle instead of creating new one.
|
|
163
|
+
// Apply the same evaluability normalization as new creation:
|
|
164
|
+
// deterministic/weak_heuristic without detectorMetadata → downgraded to manual_only.
|
|
154
165
|
existingPrinciple.trigger = params.triggerPattern;
|
|
155
166
|
existingPrinciple.action = params.action;
|
|
156
167
|
existingPrinciple.text = `When ${params.triggerPattern}, then ${params.action}.`;
|
|
157
168
|
existingPrinciple.version += 1;
|
|
158
|
-
|
|
169
|
+
if (params.evaluability !== undefined) {
|
|
170
|
+
// Apply normalization (params.evaluability may be invalid without complete metadata)
|
|
171
|
+
const normalizedEvaluability = (() => {
|
|
172
|
+
if (params.evaluability === 'manual_only' || isCompleteDetectorMetadata(params.detectorMetadata)) {
|
|
173
|
+
return params.evaluability;
|
|
174
|
+
}
|
|
175
|
+
SystemLogger.log(this.workspaceDir, 'EVALUABILITY_DOWNGRADED', `Principle update for painId "${params.painId}" requested evaluability="${params.evaluability}" without detectorMetadata — downgrading to "manual_only".`);
|
|
176
|
+
return 'manual_only';
|
|
177
|
+
})();
|
|
178
|
+
existingPrinciple.evaluability = normalizedEvaluability;
|
|
179
|
+
}
|
|
180
|
+
// Preserve detectorMetadata unless explicitly provided in this call.
|
|
181
|
+
// Accept only if complete (defense in depth — subagent should already filter).
|
|
182
|
+
if (isCompleteDetectorMetadata(params.detectorMetadata)) {
|
|
183
|
+
existingPrinciple.detectorMetadata = structuredClone(params.detectorMetadata);
|
|
184
|
+
}
|
|
185
|
+
else if (params.detectorMetadata !== undefined) {
|
|
186
|
+
// Malformed metadata provided — clear any existing metadata
|
|
187
|
+
existingPrinciple.detectorMetadata = undefined;
|
|
188
|
+
}
|
|
189
|
+
SystemLogger.log(this.workspaceDir, 'PRINCIPLE_UPDATED', `Principle ${existingPrinciple.id} updated from diagnostician: "${params.triggerPattern.slice(0, 50)}..." [evaluability: ${existingPrinciple.evaluability}]`);
|
|
159
190
|
return existingPrinciple.id;
|
|
160
191
|
}
|
|
161
192
|
// Create new principle with generalized content
|
|
@@ -178,6 +209,10 @@ export class EvolutionReducerImpl {
|
|
|
178
209
|
feedbackScore: 0,
|
|
179
210
|
usageCount: 0,
|
|
180
211
|
createdAt: now,
|
|
212
|
+
evaluability,
|
|
213
|
+
detectorMetadata: isCompleteDetectorMetadata(params.detectorMetadata)
|
|
214
|
+
? structuredClone(params.detectorMetadata)
|
|
215
|
+
: undefined,
|
|
181
216
|
};
|
|
182
217
|
this.principles.set(principleId, principle);
|
|
183
218
|
this.emitSync({
|
|
@@ -185,15 +220,20 @@ export class EvolutionReducerImpl {
|
|
|
185
220
|
type: 'candidate_created',
|
|
186
221
|
data: {
|
|
187
222
|
painId: principle.source.painId,
|
|
223
|
+
painType: params.painType,
|
|
188
224
|
principleId,
|
|
189
225
|
trigger: params.triggerPattern,
|
|
190
226
|
action: params.action,
|
|
191
227
|
status: 'candidate',
|
|
228
|
+
evaluability,
|
|
229
|
+
detectorMetadata: isCompleteDetectorMetadata(params.detectorMetadata)
|
|
230
|
+
? structuredClone(params.detectorMetadata)
|
|
231
|
+
: undefined,
|
|
192
232
|
},
|
|
193
233
|
});
|
|
194
234
|
// Auto-promote since it's already generalized
|
|
195
235
|
this.promote(principleId, 'diagnostician_generalized');
|
|
196
|
-
SystemLogger.log(this.workspaceDir, 'PRINCIPLE_CREATED', `Principle ${principleId} created from diagnostician: "${params.triggerPattern.slice(0, 50)}..."`);
|
|
236
|
+
SystemLogger.log(this.workspaceDir, 'PRINCIPLE_CREATED', `Principle ${principleId} created from diagnostician: "${params.triggerPattern.slice(0, 50)}..." [evaluability: ${evaluability}]`);
|
|
197
237
|
return principleId;
|
|
198
238
|
}
|
|
199
239
|
getStats() {
|
|
@@ -260,6 +300,13 @@ export class EvolutionReducerImpl {
|
|
|
260
300
|
const existing = this.principles.get(data.principleId);
|
|
261
301
|
if (existing) {
|
|
262
302
|
existing.status = 'candidate';
|
|
303
|
+
// Apply evaluability from event if present (supports event replay)
|
|
304
|
+
if (data.evaluability) {
|
|
305
|
+
existing.evaluability = data.evaluability;
|
|
306
|
+
}
|
|
307
|
+
if (data.detectorMetadata) {
|
|
308
|
+
existing.detectorMetadata = structuredClone(data.detectorMetadata);
|
|
309
|
+
}
|
|
263
310
|
return;
|
|
264
311
|
}
|
|
265
312
|
const principle = {
|
|
@@ -268,7 +315,7 @@ export class EvolutionReducerImpl {
|
|
|
268
315
|
text: `When ${data.trigger}, then ${data.action}.`,
|
|
269
316
|
source: {
|
|
270
317
|
painId: data.painId,
|
|
271
|
-
painType: 'tool_failure',
|
|
318
|
+
painType: data.painType ?? 'tool_failure',
|
|
272
319
|
timestamp: ts,
|
|
273
320
|
},
|
|
274
321
|
trigger: data.trigger,
|
|
@@ -279,6 +326,11 @@ export class EvolutionReducerImpl {
|
|
|
279
326
|
feedbackScore: 0,
|
|
280
327
|
usageCount: 0,
|
|
281
328
|
createdAt: ts,
|
|
329
|
+
// Evaluability defaults to 'manual_only' for replayed events without the field
|
|
330
|
+
evaluability: data.evaluability ?? 'manual_only',
|
|
331
|
+
detectorMetadata: data.detectorMetadata
|
|
332
|
+
? structuredClone(data.detectorMetadata)
|
|
333
|
+
: undefined,
|
|
282
334
|
};
|
|
283
335
|
this.principles.set(principle.id, principle);
|
|
284
336
|
}
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* - 5级成长路径:Seed → Forest
|
|
9
9
|
*/
|
|
10
10
|
export declare enum EvolutionTier {
|
|
11
|
-
Seed = 1,//
|
|
12
|
-
Sprout = 2,//
|
|
13
|
-
Sapling = 3,//
|
|
14
|
-
Tree = 4,//
|
|
11
|
+
Seed = 1,// 起步:150行 + 3文件 + 子智能体(现代 AI 能力已足够强)
|
|
12
|
+
Sprout = 2,// 成长:300行 + 5文件
|
|
13
|
+
Sapling = 3,// 独当:500行 + 10文件 + 风险路径
|
|
14
|
+
Tree = 4,// 专家:1000行 + 20文件
|
|
15
15
|
Forest = 5
|
|
16
16
|
}
|
|
17
17
|
export interface TierPermissions {
|
|
@@ -91,11 +91,6 @@ export interface EvolutionConfig {
|
|
|
91
91
|
tier5Trivial: number;
|
|
92
92
|
tier5Normal: number;
|
|
93
93
|
};
|
|
94
|
-
/** 信任分系统双轨运行时的配置 */
|
|
95
|
-
dualTrack: {
|
|
96
|
-
enabled: boolean;
|
|
97
|
-
primarySystem: 'trust' | 'evolution';
|
|
98
|
-
};
|
|
99
94
|
}
|
|
100
95
|
export declare const DEFAULT_EVOLUTION_CONFIG: EvolutionConfig;
|
|
101
96
|
export interface ArchivedEventStats {
|
|
@@ -125,6 +120,45 @@ export interface TierPromotionEvent {
|
|
|
125
120
|
newPermissions: TierPermissions;
|
|
126
121
|
}
|
|
127
122
|
export type PrincipleStatus = 'candidate' | 'probation' | 'active' | 'deprecated';
|
|
123
|
+
/**
|
|
124
|
+
* Evaluability classification — determines whether a P_xxx principle can enter
|
|
125
|
+
* automatic nocturnal targeting.
|
|
126
|
+
*
|
|
127
|
+
* - deterministic: Machine-checkable via deterministic rules/tool detectors
|
|
128
|
+
* - weak_heuristic: Checkable via heuristic signals, may have false positives
|
|
129
|
+
* - manual_only: No machine-checkable detector — stays in prompts only
|
|
130
|
+
*/
|
|
131
|
+
export type PrincipleEvaluatorLevel = 'deterministic' | 'weak_heuristic' | 'manual_only';
|
|
132
|
+
/**
|
|
133
|
+
* Shared alias for PrincipleEvaluatorLevel — used by modules that reference
|
|
134
|
+
* the same evaluability classification without direct coupling to evolution-types.
|
|
135
|
+
* @deprecated Use PrincipleEvaluatorLevel directly. This alias exists for
|
|
136
|
+
* backwards compatibility with principle-training-state.ts.
|
|
137
|
+
*/
|
|
138
|
+
export type Evaluability = PrincipleEvaluatorLevel;
|
|
139
|
+
/**
|
|
140
|
+
* Structured detector metadata for P_xxx principles.
|
|
141
|
+
* Allows the principle to enter automatic nocturnal targeting.
|
|
142
|
+
*
|
|
143
|
+
* If any required field is missing, the principle defaults to 'manual_only'.
|
|
144
|
+
*/
|
|
145
|
+
export interface PrincipleDetectorSpec {
|
|
146
|
+
/** Topic/scenario tags where this detector applies */
|
|
147
|
+
applicabilityTags: string[];
|
|
148
|
+
/** Evidence that the principle was followed */
|
|
149
|
+
positiveSignals: string[];
|
|
150
|
+
/** Evidence that the principle was violated */
|
|
151
|
+
negativeSignals: string[];
|
|
152
|
+
/** Tool call sequences that indicate the principle is relevant */
|
|
153
|
+
toolSequenceHints: string[][];
|
|
154
|
+
/** Confidence in the detector's signal quality */
|
|
155
|
+
confidence: 'high' | 'medium' | 'low';
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Validates that a detector metadata object has all required fields with non-empty values.
|
|
159
|
+
* Used as defense-in-depth before accepting detectorMetadata for auto-trainable principles.
|
|
160
|
+
*/
|
|
161
|
+
export declare function isCompleteDetectorMetadata(meta: unknown): meta is PrincipleDetectorSpec;
|
|
128
162
|
export interface Principle {
|
|
129
163
|
id: string;
|
|
130
164
|
version: number;
|
|
@@ -148,6 +182,18 @@ export interface Principle {
|
|
|
148
182
|
createdAt: string;
|
|
149
183
|
activatedAt?: string;
|
|
150
184
|
deprecatedAt?: string;
|
|
185
|
+
/**
|
|
186
|
+
* Evaluability classification. Defaults to 'manual_only' if not set.
|
|
187
|
+
* Principles with 'manual_only' evaluability cannot enter automatic
|
|
188
|
+
* nocturnal targeting.
|
|
189
|
+
*/
|
|
190
|
+
evaluability: PrincipleEvaluatorLevel;
|
|
191
|
+
/**
|
|
192
|
+
* Structured detector metadata. If present and valid, the principle
|
|
193
|
+
* may be auto-trainable (deterministic / weak_heuristic).
|
|
194
|
+
* Absent or malformed = 'manual_only' evaluability.
|
|
195
|
+
*/
|
|
196
|
+
detectorMetadata?: PrincipleDetectorSpec;
|
|
151
197
|
}
|
|
152
198
|
export type EvolutionLoopEventType = 'pain_detected' | 'candidate_created' | 'principle_promoted' | 'principle_deprecated' | 'principle_rolled_back' | 'circuit_breaker_opened' | 'legacy_import';
|
|
153
199
|
export interface PainDetectedData {
|
|
@@ -167,6 +213,12 @@ export interface CandidateCreatedData {
|
|
|
167
213
|
trigger: string;
|
|
168
214
|
action: string;
|
|
169
215
|
status: 'candidate';
|
|
216
|
+
/** Pain type that generated this candidate — preserved on replay */
|
|
217
|
+
painType?: 'tool_failure' | 'subagent_error' | 'user_frustration';
|
|
218
|
+
/** Optional evaluability — defaults to 'manual_only' if omitted */
|
|
219
|
+
evaluability?: PrincipleEvaluatorLevel;
|
|
220
|
+
/** Optional detector metadata — absent = manual_only */
|
|
221
|
+
detectorMetadata?: PrincipleDetectorSpec;
|
|
170
222
|
}
|
|
171
223
|
export interface PrinciplePromotedData {
|
|
172
224
|
principleId: string;
|
|
@@ -14,13 +14,19 @@ export var EvolutionTier;
|
|
|
14
14
|
EvolutionTier[EvolutionTier["Sprout"] = 2] = "Sprout";
|
|
15
15
|
EvolutionTier[EvolutionTier["Sapling"] = 3] = "Sapling";
|
|
16
16
|
EvolutionTier[EvolutionTier["Tree"] = 4] = "Tree";
|
|
17
|
-
EvolutionTier[EvolutionTier["Forest"] = 5] = "Forest"; //
|
|
17
|
+
EvolutionTier[EvolutionTier["Forest"] = 5] = "Forest"; // 大师:完全自主
|
|
18
18
|
})(EvolutionTier || (EvolutionTier = {}));
|
|
19
19
|
export const TIER_DEFINITIONS = [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{ tier: EvolutionTier.
|
|
23
|
-
|
|
20
|
+
// 2026-03-28: 大幅放宽限制,现代 AI 能力已很强
|
|
21
|
+
// Seed: 从 20 行提升到 150 行,允许 3 文件,允许子智能体
|
|
22
|
+
{ tier: EvolutionTier.Seed, name: 'Seed', requiredPoints: 0, permissions: { maxLinesPerWrite: 150, maxFilesPerTask: 3, allowRiskPath: false, allowSubagentSpawn: true } },
|
|
23
|
+
// Sprout: 中等规模开发
|
|
24
|
+
{ tier: EvolutionTier.Sprout, name: 'Sprout', requiredPoints: 50, permissions: { maxLinesPerWrite: 300, maxFilesPerTask: 5, allowRiskPath: false, allowSubagentSpawn: true } },
|
|
25
|
+
// Sapling: 较大规模开发,可访问风险路径(需 PLAN)
|
|
26
|
+
{ tier: EvolutionTier.Sapling, name: 'Sapling', requiredPoints: 200, permissions: { maxLinesPerWrite: 500, maxFilesPerTask: 10, allowRiskPath: true, allowSubagentSpawn: true } },
|
|
27
|
+
// Tree: 大型重构
|
|
28
|
+
{ tier: EvolutionTier.Tree, name: 'Tree', requiredPoints: 500, permissions: { maxLinesPerWrite: 1000, maxFilesPerTask: 20, allowRiskPath: true, allowSubagentSpawn: true } },
|
|
29
|
+
// Forest: 完全自主
|
|
24
30
|
{ tier: EvolutionTier.Forest, name: 'Forest', requiredPoints: 1000, permissions: { maxLinesPerWrite: Infinity, maxFilesPerTask: Infinity, allowRiskPath: true, allowSubagentSpawn: true } },
|
|
25
31
|
];
|
|
26
32
|
export function getTierDefinition(tier) {
|
|
@@ -49,8 +55,24 @@ export const DEFAULT_EVOLUTION_CONFIG = {
|
|
|
49
55
|
tier5Trivial: 0.1,
|
|
50
56
|
tier5Normal: 0.5,
|
|
51
57
|
},
|
|
52
|
-
dualTrack: {
|
|
53
|
-
enabled: true,
|
|
54
|
-
primarySystem: 'evolution',
|
|
55
|
-
},
|
|
56
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* Validates that a detector metadata object has all required fields with non-empty values.
|
|
61
|
+
* Used as defense-in-depth before accepting detectorMetadata for auto-trainable principles.
|
|
62
|
+
*/
|
|
63
|
+
export function isCompleteDetectorMetadata(meta) {
|
|
64
|
+
if (!meta || typeof meta !== 'object')
|
|
65
|
+
return false;
|
|
66
|
+
const m = meta;
|
|
67
|
+
const VALID_CONFIDENCE = ['high', 'medium', 'low'];
|
|
68
|
+
if (typeof m.confidence !== 'string' ||
|
|
69
|
+
!VALID_CONFIDENCE.includes(m.confidence)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const nonEmptyStringArray = (arr) => Array.isArray(arr) &&
|
|
73
|
+
arr.length > 0 &&
|
|
74
|
+
arr.every((s) => typeof s === 'string' && s.length > 0);
|
|
75
|
+
return (nonEmptyStringArray(m.applicabilityTags) &&
|
|
76
|
+
nonEmptyStringArray(m.positiveSignals) &&
|
|
77
|
+
nonEmptyStringArray(m.negativeSignals));
|
|
78
|
+
}
|