principles-disciple 1.7.5 → 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 +29 -48
- 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/config/defaults/runtime.d.ts +40 -0
- package/dist/config/defaults/runtime.js +44 -0
- package/dist/config/errors.d.ts +84 -0
- package/dist/config/errors.js +94 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.js +7 -0
- package/dist/constants/diagnostician.d.ts +0 -4
- package/dist/constants/diagnostician.js +0 -4
- 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/control-ui-db.d.ts +27 -0
- package/dist/core/control-ui-db.js +18 -0
- 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/path-resolver.js +2 -1
- 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 +155 -1
- package/dist/core/trajectory.js +292 -8
- package/dist/core/workspace-context.d.ts +0 -6
- package/dist/core/workspace-context.js +0 -12
- package/dist/hooks/bash-risk.d.ts +57 -0
- package/dist/hooks/bash-risk.js +137 -0
- package/dist/hooks/edit-verification.d.ts +62 -0
- package/dist/hooks/edit-verification.js +256 -0
- package/dist/hooks/gate-block-helper.d.ts +44 -0
- package/dist/hooks/gate-block-helper.js +119 -0
- package/dist/hooks/gate.d.ts +18 -0
- package/dist/hooks/gate.js +62 -751
- package/dist/hooks/gfi-gate.d.ts +40 -0
- package/dist/hooks/gfi-gate.js +113 -0
- package/dist/hooks/pain.js +6 -9
- package/dist/hooks/progressive-trust-gate.d.ts +51 -0
- package/dist/hooks/progressive-trust-gate.js +89 -0
- package/dist/hooks/prompt.d.ts +11 -11
- package/dist/hooks/prompt.js +167 -77
- package/dist/hooks/subagent.js +43 -6
- package/dist/hooks/thinking-checkpoint.d.ts +37 -0
- package/dist/hooks/thinking-checkpoint.js +51 -0
- package/dist/http/principles-console-route.js +13 -3
- package/dist/i18n/commands.js +8 -8
- package/dist/index.js +129 -28
- package/dist/service/central-database.js +2 -1
- package/dist/service/control-ui-query-service.d.ts +1 -1
- package/dist/service/control-ui-query-service.js +3 -3
- package/dist/service/evolution-query-service.d.ts +1 -1
- package/dist/service/evolution-query-service.js +5 -5
- package/dist/service/evolution-worker.d.ts +52 -4
- package/dist/service/evolution-worker.js +328 -16
- 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 +48 -12
- package/dist/service/phase3-input-filter.js +84 -18
- package/dist/service/runtime-summary-service.d.ts +34 -10
- package/dist/service/runtime-summary-service.js +87 -48
- package/dist/tools/deep-reflect.js +2 -1
- package/dist/types/event-types.d.ts +4 -10
- package/dist/types/runtime-summary.d.ts +47 -0
- package/dist/types/runtime-summary.js +1 -0
- 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;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Runtime Defaults
|
|
3
|
+
*
|
|
4
|
+
* All runtime-related constants that were previously scattered across modules.
|
|
5
|
+
* Centralizing these makes it easier to tune behavior and understand limits.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Trajectory gate block retry settings
|
|
9
|
+
* Used when trajectory recording fails and needs to retry
|
|
10
|
+
*/
|
|
11
|
+
export declare const TRAJECTORY_GATE_BLOCK_RETRY_DELAY_MS = 250;
|
|
12
|
+
export declare const TRAJECTORY_GATE_BLOCK_MAX_RETRIES = 3;
|
|
13
|
+
/**
|
|
14
|
+
* Thinking checkpoint defaults (P-10)
|
|
15
|
+
*/
|
|
16
|
+
export declare const THINKING_CHECKPOINT_WINDOW_MS: number;
|
|
17
|
+
export declare const THINKING_CHECKPOINT_DEFAULT_HIGH_RISK_TOOLS: readonly ["run_shell_command", "delete_file", "move_file"];
|
|
18
|
+
/**
|
|
19
|
+
* Large change threshold for GFI gate adjustments
|
|
20
|
+
*/
|
|
21
|
+
export declare const GFI_LARGE_CHANGE_LINES = 50;
|
|
22
|
+
/**
|
|
23
|
+
* Agent spawn GFI threshold (critically high = no spawn)
|
|
24
|
+
*/
|
|
25
|
+
export declare const AGENT_SPAWN_GFI_THRESHOLD = 90;
|
|
26
|
+
/**
|
|
27
|
+
* Evolution worker polling intervals
|
|
28
|
+
*/
|
|
29
|
+
export declare const EVOLUTION_WORKER_POLL_INTERVAL_MS: number;
|
|
30
|
+
export declare const EVOLUTION_QUEUE_BATCH_SIZE = 10;
|
|
31
|
+
/**
|
|
32
|
+
* Session tracker settings
|
|
33
|
+
*/
|
|
34
|
+
export declare const SESSION_TOKEN_WARNING_THRESHOLD = 8000;
|
|
35
|
+
export declare const SESSION_MAX_IDLE_MS: number;
|
|
36
|
+
/**
|
|
37
|
+
* Event log buffer settings
|
|
38
|
+
*/
|
|
39
|
+
export declare const EVENT_LOG_BUFFER_SIZE = 20;
|
|
40
|
+
export declare const EVENT_LOG_FLUSH_INTERVAL_MS: number;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Runtime Defaults
|
|
3
|
+
*
|
|
4
|
+
* All runtime-related constants that were previously scattered across modules.
|
|
5
|
+
* Centralizing these makes it easier to tune behavior and understand limits.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Trajectory gate block retry settings
|
|
9
|
+
* Used when trajectory recording fails and needs to retry
|
|
10
|
+
*/
|
|
11
|
+
export const TRAJECTORY_GATE_BLOCK_RETRY_DELAY_MS = 250;
|
|
12
|
+
export const TRAJECTORY_GATE_BLOCK_MAX_RETRIES = 3;
|
|
13
|
+
/**
|
|
14
|
+
* Thinking checkpoint defaults (P-10)
|
|
15
|
+
*/
|
|
16
|
+
export const THINKING_CHECKPOINT_WINDOW_MS = 5 * 60 * 1000; // 5 minutes
|
|
17
|
+
export const THINKING_CHECKPOINT_DEFAULT_HIGH_RISK_TOOLS = [
|
|
18
|
+
'run_shell_command',
|
|
19
|
+
'delete_file',
|
|
20
|
+
'move_file',
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Large change threshold for GFI gate adjustments
|
|
24
|
+
*/
|
|
25
|
+
export const GFI_LARGE_CHANGE_LINES = 50;
|
|
26
|
+
/**
|
|
27
|
+
* Agent spawn GFI threshold (critically high = no spawn)
|
|
28
|
+
*/
|
|
29
|
+
export const AGENT_SPAWN_GFI_THRESHOLD = 90;
|
|
30
|
+
/**
|
|
31
|
+
* Evolution worker polling intervals
|
|
32
|
+
*/
|
|
33
|
+
export const EVOLUTION_WORKER_POLL_INTERVAL_MS = 15 * 60 * 1000; // 15 minutes
|
|
34
|
+
export const EVOLUTION_QUEUE_BATCH_SIZE = 10;
|
|
35
|
+
/**
|
|
36
|
+
* Session tracker settings
|
|
37
|
+
*/
|
|
38
|
+
export const SESSION_TOKEN_WARNING_THRESHOLD = 8000;
|
|
39
|
+
export const SESSION_MAX_IDLE_MS = 30 * 60 * 1000; // 30 minutes
|
|
40
|
+
/**
|
|
41
|
+
* Event log buffer settings
|
|
42
|
+
*/
|
|
43
|
+
export const EVENT_LOG_BUFFER_SIZE = 20;
|
|
44
|
+
export const EVENT_LOG_FLUSH_INTERVAL_MS = 30 * 1000; // 30 seconds
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain-Specific Errors for Principles Disciple
|
|
3
|
+
*
|
|
4
|
+
* These errors provide semantic meaning to failure modes,
|
|
5
|
+
* making it easier to distinguish between:
|
|
6
|
+
* - Lock contention (resource busy)
|
|
7
|
+
* - Parse/validation failures
|
|
8
|
+
* - Derived state mismatches
|
|
9
|
+
* - Configuration issues
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Base class for all Principles Disciple errors
|
|
13
|
+
*/
|
|
14
|
+
export declare class PdError extends Error {
|
|
15
|
+
readonly code: string;
|
|
16
|
+
constructor(message: string, code: string, options?: {
|
|
17
|
+
cause?: unknown;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Thrown when a resource lock cannot be acquired
|
|
22
|
+
* (e.g., queue, trajectory, evolution file)
|
|
23
|
+
*/
|
|
24
|
+
export declare class LockUnavailableError extends PdError {
|
|
25
|
+
constructor(resource: string, scope: string, options?: {
|
|
26
|
+
cause?: unknown;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when a path key cannot be resolved
|
|
31
|
+
*/
|
|
32
|
+
export declare class PathResolutionError extends PdError {
|
|
33
|
+
constructor(key: string, options?: {
|
|
34
|
+
cause?: unknown;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when a workspace cannot be found
|
|
39
|
+
*/
|
|
40
|
+
export declare class WorkspaceNotFoundError extends PdError {
|
|
41
|
+
constructor(workspace: string, options?: {
|
|
42
|
+
cause?: unknown;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Thrown when a required sample cannot be found
|
|
47
|
+
*/
|
|
48
|
+
export declare class SampleNotFoundError extends PdError {
|
|
49
|
+
constructor(sampleId: string, options?: {
|
|
50
|
+
cause?: unknown;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Thrown when configuration is invalid or missing required fields
|
|
55
|
+
*/
|
|
56
|
+
export declare class ConfigurationError extends PdError {
|
|
57
|
+
constructor(message: string, options?: {
|
|
58
|
+
cause?: unknown;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Thrown when prompt/logger dependencies are unavailable
|
|
63
|
+
*/
|
|
64
|
+
export declare class DependencyError extends PdError {
|
|
65
|
+
constructor(component: string, message: string, options?: {
|
|
66
|
+
cause?: unknown;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Thrown when evolution worker encounters a processing error
|
|
71
|
+
*/
|
|
72
|
+
export declare class EvolutionProcessingError extends PdError {
|
|
73
|
+
constructor(message: string, options?: {
|
|
74
|
+
cause?: unknown;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Thrown when trajectory operations fail
|
|
79
|
+
*/
|
|
80
|
+
export declare class TrajectoryError extends PdError {
|
|
81
|
+
constructor(message: string, options?: {
|
|
82
|
+
cause?: unknown;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain-Specific Errors for Principles Disciple
|
|
3
|
+
*
|
|
4
|
+
* These errors provide semantic meaning to failure modes,
|
|
5
|
+
* making it easier to distinguish between:
|
|
6
|
+
* - Lock contention (resource busy)
|
|
7
|
+
* - Parse/validation failures
|
|
8
|
+
* - Derived state mismatches
|
|
9
|
+
* - Configuration issues
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Base class for all Principles Disciple errors
|
|
13
|
+
*/
|
|
14
|
+
export class PdError extends Error {
|
|
15
|
+
code;
|
|
16
|
+
constructor(message, code, options) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.name = 'PdError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Thrown when a resource lock cannot be acquired
|
|
24
|
+
* (e.g., queue, trajectory, evolution file)
|
|
25
|
+
*/
|
|
26
|
+
export class LockUnavailableError extends PdError {
|
|
27
|
+
constructor(resource, scope, options) {
|
|
28
|
+
super(`[PD:Lock] ${scope}: queue lock unavailable for ${resource}`, 'LOCK_UNAVAILABLE', options);
|
|
29
|
+
this.name = 'LockUnavailableError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Thrown when a path key cannot be resolved
|
|
34
|
+
*/
|
|
35
|
+
export class PathResolutionError extends PdError {
|
|
36
|
+
constructor(key, options) {
|
|
37
|
+
super(`[PD:Path] Unknown path key: ${key}`, 'PATH_RESOLUTION_ERROR', options);
|
|
38
|
+
this.name = 'PathResolutionError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Thrown when a workspace cannot be found
|
|
43
|
+
*/
|
|
44
|
+
export class WorkspaceNotFoundError extends PdError {
|
|
45
|
+
constructor(workspace, options) {
|
|
46
|
+
super(`[PD:Workspace] Workspace not found: ${workspace}`, 'WORKSPACE_NOT_FOUND', options);
|
|
47
|
+
this.name = 'WorkspaceNotFoundError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Thrown when a required sample cannot be found
|
|
52
|
+
*/
|
|
53
|
+
export class SampleNotFoundError extends PdError {
|
|
54
|
+
constructor(sampleId, options) {
|
|
55
|
+
super(`[PD:Sample] Correction sample not found: ${sampleId}`, 'SAMPLE_NOT_FOUND', options);
|
|
56
|
+
this.name = 'SampleNotFoundError';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Thrown when configuration is invalid or missing required fields
|
|
61
|
+
*/
|
|
62
|
+
export class ConfigurationError extends PdError {
|
|
63
|
+
constructor(message, options) {
|
|
64
|
+
super(`[PD:Config] ${message}`, 'CONFIGURATION_ERROR', options);
|
|
65
|
+
this.name = 'ConfigurationError';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Thrown when prompt/logger dependencies are unavailable
|
|
70
|
+
*/
|
|
71
|
+
export class DependencyError extends PdError {
|
|
72
|
+
constructor(component, message, options) {
|
|
73
|
+
super(`[PD:${component}] ${message}`, 'DEPENDENCY_ERROR', options);
|
|
74
|
+
this.name = 'DependencyError';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Thrown when evolution worker encounters a processing error
|
|
79
|
+
*/
|
|
80
|
+
export class EvolutionProcessingError extends PdError {
|
|
81
|
+
constructor(message, options) {
|
|
82
|
+
super(`[PD:Evolution] ${message}`, 'EVOLUTION_PROCESSING_ERROR', options);
|
|
83
|
+
this.name = 'EvolutionProcessingError';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Thrown when trajectory operations fail
|
|
88
|
+
*/
|
|
89
|
+
export class TrajectoryError extends PdError {
|
|
90
|
+
constructor(message, options) {
|
|
91
|
+
super(`[PD:Trajectory] ${message}`, 'TRAJECTORY_ERROR', options);
|
|
92
|
+
this.name = 'TrajectoryError';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -10,7 +10,3 @@
|
|
|
10
10
|
* 完整版见: templates/langs/zh/skills/pd-diagnostician/SKILL.md
|
|
11
11
|
*/
|
|
12
12
|
export declare const DIAGNOSTICIAN_PROTOCOL_SUMMARY = "## Diagnostic Protocol (5 Whys)\n\n**Phase 1 - Evidence Gathering**:\n- Read logs: .state/logs/events.jsonl, SYSTEM.log\n- Search code for error patterns from Reason field\n- Record evidence sources\n\n**Phase 2 - Causal Chain**:\n- Each Why must have evidence support\n- Maximum 5 layers\n- Stop when reaching actionable root cause\n\n**Phase 3 - Root Cause Classification**:\nClassify into one of:\n- **People**: Human error, missing knowledge, communication gap\n- **Design**: Architecture flaw, missing validation, poor abstraction\n- **Assumption**: Invalid assumption, outdated context, edge case\n- **Tooling**: Tool limitation, environment issue, dependency problem\n\n**Phase 4 - Principle Extraction**:\nExtract protection principle with:\n- **trigger_pattern**: When this situation occurs\n- **action**: What to do differently\n\n**Output Format**:\n```json\n{\n \"diagnosis_report\": {\n \"task_id\": \"pain-xxx\",\n \"summary\": \"One-line root cause\",\n \"causal_chain\": [\n { \"why\": 1, \"answer\": \"...\", \"evidence\": \"...\" }\n ],\n \"root_cause\": {\n \"category\": \"Design|People|Assumption|Tooling\",\n \"description\": \"...\"\n },\n \"principle\": {\n \"trigger_pattern\": \"...\",\n \"action\": \"...\"\n }\n }\n}\n```\n";
|
|
13
|
-
/**
|
|
14
|
-
* 完整诊断协议文件路径(相对于插件根目录)
|
|
15
|
-
*/
|
|
16
|
-
export declare const DIAGNOSTICIAN_SKILL_PATH = "templates/langs/zh/skills/pd-diagnostician/SKILL.md";
|
|
@@ -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;
|