principles-disciple 1.7.5 → 1.7.6
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/evolution-status.js +32 -44
- 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/core/control-ui-db.d.ts +27 -0
- package/dist/core/control-ui-db.js +18 -0
- package/dist/core/path-resolver.js +2 -1
- package/dist/core/trajectory.d.ts +60 -0
- package/dist/core/trajectory.js +72 -2
- 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 +112 -0
- package/dist/hooks/progressive-trust-gate.d.ts +79 -0
- package/dist/hooks/progressive-trust-gate.js +242 -0
- package/dist/hooks/prompt.js +10 -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/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 +10 -0
- package/dist/service/evolution-worker.js +7 -3
- package/dist/service/phase3-input-filter.d.ts +57 -0
- package/dist/service/phase3-input-filter.js +93 -3
- package/dist/service/runtime-summary-service.d.ts +34 -0
- package/dist/service/runtime-summary-service.js +93 -1
- package/dist/types/event-types.d.ts +2 -0
- package/dist/types/runtime-summary.d.ts +54 -0
- package/dist/types/runtime-summary.js +1 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
import { EvolutionReducerImpl } from '../core/evolution-reducer.js';
|
|
2
2
|
import { normalizeLanguage } from '../i18n/commands.js';
|
|
3
3
|
import { RuntimeSummaryService } from '../service/runtime-summary-service.js';
|
|
4
|
-
function formatAge(ageSeconds, lang) {
|
|
5
|
-
if (ageSeconds === null) {
|
|
6
|
-
return '--';
|
|
7
|
-
}
|
|
8
|
-
if (ageSeconds < 60) {
|
|
9
|
-
return lang === 'zh' ? `${ageSeconds} \u79d2` : `${ageSeconds}s`;
|
|
10
|
-
}
|
|
11
|
-
const minutes = Math.floor(ageSeconds / 60);
|
|
12
|
-
if (minutes < 60) {
|
|
13
|
-
return lang === 'zh' ? `${minutes} \u5206\u949f` : `${minutes}m`;
|
|
14
|
-
}
|
|
15
|
-
const hours = Math.floor(minutes / 60);
|
|
16
|
-
if (hours < 24) {
|
|
17
|
-
return lang === 'zh' ? `${hours} \u5c0f\u65f6` : `${hours}h`;
|
|
18
|
-
}
|
|
19
|
-
const days = Math.floor(hours / 24);
|
|
20
|
-
return lang === 'zh' ? `${days} \u5929` : `${days}d`;
|
|
21
|
-
}
|
|
22
4
|
function formatNumber(value) {
|
|
23
5
|
if (value === null || Number.isNaN(value)) {
|
|
24
6
|
return '--';
|
|
@@ -45,6 +27,7 @@ function buildEnglishOutput(workspaceDir, sessionId, warnings, stats, summary) {
|
|
|
45
27
|
'',
|
|
46
28
|
'Control Plane',
|
|
47
29
|
`- Legacy Trust: ${formatNumber(summary.legacyTrust.score)}/100 (stage ${formatStage(summary.legacyTrust.stage)}, legacy/frozen, ${summary.legacyTrust.rewardPolicy})`,
|
|
30
|
+
`- Runtime Trust Truth: score ${formatNumber(summary.runtime.currentTrustScore)}, classification ${summary.runtime.workspaceState.trustClassification}, frozen ${summary.runtime.workspaceState.frozen === null ? '--' : String(summary.runtime.workspaceState.frozen)}`,
|
|
48
31
|
`- Session GFI: current ${formatNumber(summary.gfi.current)}, peak ${formatNumber(summary.gfi.peak)} (${summary.gfi.dataQuality})`,
|
|
49
32
|
`- GFI Sources: ${formatSources(summary.gfi.sources)}`,
|
|
50
33
|
`- Pain Flag: ${summary.pain.activeFlag ? 'active' : 'inactive'}${summary.pain.activeFlagSource ? ` (${summary.pain.activeFlagSource})` : ''}`,
|
|
@@ -53,9 +36,11 @@ function buildEnglishOutput(workspaceDir, sessionId, warnings, stats, summary) {
|
|
|
53
36
|
'',
|
|
54
37
|
'Evolution',
|
|
55
38
|
`- Queue: pending ${summary.evolution.queue.pending}, in_progress ${summary.evolution.queue.inProgress}, completed ${summary.evolution.queue.completed} (${summary.evolution.dataQuality})`,
|
|
56
|
-
`- Directive
|
|
57
|
-
`-
|
|
58
|
-
`-
|
|
39
|
+
`- Legacy Directive File: ${summary.phase3.legacyDirectiveFilePresent ? 'present' : 'missing'} (compatibility-only display artifact)`,
|
|
40
|
+
`- Note: Legacy directive file is NOT a truth source for Phase 3 eligibility. Queue is the only authoritative execution truth source.`,
|
|
41
|
+
`- Active Evolution Task: ${summary.evolution.directive.taskPreview ?? '--'}`,
|
|
42
|
+
`- Phase 3: ready ${summary.phase3.phase3ShadowEligible ? 'yes' : 'no'}, queueTruthReady ${summary.phase3.queueTruthReady ? 'yes' : 'no'}, trustInputReady ${summary.phase3.trustInputReady ? 'yes' : 'no'}, eligible ${summary.phase3.evolutionEligible}, reference_only ${summary.phase3.evolutionReferenceOnly}, rejected ${summary.phase3.evolutionRejected}${summary.phase3.evolutionReferenceOnlyReasons.length > 0 ? ` (reference ${summary.phase3.evolutionReferenceOnlyReasons.slice(0, 2).join(', ')})` : ''}${summary.phase3.evolutionRejectedReasons.length > 0 ? ` (${summary.phase3.evolutionRejectedReasons.slice(0, 3).join(', ')})` : ''}${summary.phase3.trustRejectedReasons.length > 0 ? `; trust ${summary.phase3.trustRejectedReasons.slice(0, 2).join(', ')}` : ''}`,
|
|
43
|
+
`- Phase 3 Legacy Directive File: ${summary.phase3.directiveStatus} (${summary.phase3.directiveIgnoredReason})`,
|
|
59
44
|
'',
|
|
60
45
|
'Principles',
|
|
61
46
|
`- candidate principles: ${stats.candidateCount}`,
|
|
@@ -79,34 +64,37 @@ function buildEnglishOutput(workspaceDir, sessionId, warnings, stats, summary) {
|
|
|
79
64
|
}
|
|
80
65
|
function buildChineseOutput(workspaceDir, sessionId, warnings, stats, summary) {
|
|
81
66
|
const lines = [
|
|
82
|
-
'
|
|
67
|
+
'进化状态',
|
|
83
68
|
'================',
|
|
84
69
|
'',
|
|
85
|
-
'
|
|
86
|
-
`- Legacy Trust: ${formatNumber(summary.legacyTrust.score)}/100
|
|
87
|
-
`-
|
|
88
|
-
`- GFI
|
|
89
|
-
`-
|
|
90
|
-
`-
|
|
91
|
-
`-
|
|
70
|
+
'控制面',
|
|
71
|
+
`- Legacy Trust: ${formatNumber(summary.legacyTrust.score)}/100(阶段 ${formatStage(summary.legacyTrust.stage)},legacy/frozen,${summary.legacyTrust.rewardPolicy})`,
|
|
72
|
+
`- Runtime Trust Truth: score ${formatNumber(summary.runtime.currentTrustScore)},classification ${summary.runtime.workspaceState.trustClassification},frozen ${summary.runtime.workspaceState.frozen === null ? '--' : String(summary.runtime.workspaceState.frozen)}`,
|
|
73
|
+
`- 会话 GFI: 当前 ${formatNumber(summary.gfi.current)},峰值 ${formatNumber(summary.gfi.peak)}(${summary.gfi.dataQuality})`,
|
|
74
|
+
`- GFI 来源: ${formatSources(summary.gfi.sources)}`,
|
|
75
|
+
`- Pain Flag: ${summary.pain.activeFlag ? 'active' : 'inactive'}${summary.pain.activeFlagSource ? `(${summary.pain.activeFlagSource})` : ''}`,
|
|
76
|
+
`- 最近 Pain 信号: ${summary.pain.lastSignal ? `${summary.pain.lastSignal.source}${summary.pain.lastSignal.reason ? ` - ${summary.pain.lastSignal.reason}` : ''}` : '--'}`,
|
|
77
|
+
`- Gate 事件: block ${formatNumber(summary.gate.recentBlocks)},bypass ${formatNumber(summary.gate.recentBypasses)}(${summary.gate.dataQuality})`,
|
|
92
78
|
'',
|
|
93
|
-
'
|
|
94
|
-
`-
|
|
95
|
-
`- Directive
|
|
96
|
-
`-
|
|
97
|
-
`-
|
|
79
|
+
'进化',
|
|
80
|
+
`- 队列: pending ${summary.evolution.queue.pending},in_progress ${summary.evolution.queue.inProgress},completed ${summary.evolution.queue.completed}(${summary.evolution.dataQuality})`,
|
|
81
|
+
`- Legacy Directive File: ${summary.phase3.legacyDirectiveFilePresent ? 'present' : 'missing'} (兼容仅显示产物)`,
|
|
82
|
+
`- 注:Legacy directive file 不是 Phase 3 合格性的真实源。队列是唯一权威的执行真实源。`,
|
|
83
|
+
`- Active Evolution Task: ${summary.evolution.directive.taskPreview ?? '--'}`,
|
|
84
|
+
`- Phase 3: ready ${summary.phase3.phase3ShadowEligible ? 'yes' : 'no'},queueTruthReady ${summary.phase3.queueTruthReady ? 'yes' : 'no'},trustInputReady ${summary.phase3.trustInputReady ? 'yes' : 'no'},eligible ${summary.phase3.evolutionEligible},reference_only ${summary.phase3.evolutionReferenceOnly},rejected ${summary.phase3.evolutionRejected}${summary.phase3.evolutionReferenceOnlyReasons.length > 0 ? `(reference ${summary.phase3.evolutionReferenceOnlyReasons.slice(0, 2).join(', ')})` : ''}${summary.phase3.evolutionRejectedReasons.length > 0 ? `(${summary.phase3.evolutionRejectedReasons.slice(0, 3).join(', ')})` : ''}${summary.phase3.trustRejectedReasons.length > 0 ? `;trust ${summary.phase3.trustRejectedReasons.slice(0, 2).join(', ')}` : ''}`,
|
|
85
|
+
`- Phase 3 Legacy Directive File: ${summary.phase3.directiveStatus} (${summary.phase3.directiveIgnoredReason})`,
|
|
98
86
|
'',
|
|
99
|
-
'
|
|
100
|
-
`-
|
|
101
|
-
`-
|
|
102
|
-
`-
|
|
103
|
-
`-
|
|
104
|
-
`-
|
|
87
|
+
'原则统计',
|
|
88
|
+
`- 候选原则: ${stats.candidateCount}`,
|
|
89
|
+
`- 观察期原则: ${stats.probationCount}`,
|
|
90
|
+
`- 生效原则: ${stats.activeCount}`,
|
|
91
|
+
`- 已废弃原则: ${stats.deprecatedCount}`,
|
|
92
|
+
`- 最近晋升: ${stats.lastPromotedAt ?? '无'}`,
|
|
105
93
|
'',
|
|
106
|
-
'
|
|
107
|
-
`-
|
|
108
|
-
`- Session: ${sessionId ?? '--'}
|
|
109
|
-
`-
|
|
94
|
+
'元数据',
|
|
95
|
+
`- 工作区: ${workspaceDir}`,
|
|
96
|
+
`- Session: ${sessionId ?? '--'}(${summary.metadata.selectedSessionReason})`,
|
|
97
|
+
`- 生成时间: ${summary.metadata.generatedAt}`,
|
|
110
98
|
];
|
|
111
99
|
if (warnings.length > 0) {
|
|
112
100
|
lines.push('', '警告');
|
|
@@ -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,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Control UI database stores ANALYTICS READ MODELS.
|
|
3
|
+
*
|
|
4
|
+
* PURPOSE: Aggregated data for dashboard visualization and historical insights.
|
|
5
|
+
* USAGE: Control UI queries and dashboard displays.
|
|
6
|
+
* NOT FOR: Control decisions, Phase 3 eligibility, or real-time operations.
|
|
7
|
+
*
|
|
8
|
+
* Runtime truth comes from: queue state, workspace trust scorecard, active sessions
|
|
9
|
+
*/
|
|
1
10
|
export interface ThinkingModelEventInput {
|
|
2
11
|
sessionId: string;
|
|
3
12
|
runId: string;
|
|
@@ -59,8 +68,26 @@ export declare class ControlUiDatabase {
|
|
|
59
68
|
constructor(opts: ControlUiDatabaseOptions);
|
|
60
69
|
dispose(): void;
|
|
61
70
|
recordThinkingModelEvent(input: ThinkingModelEventInput): number;
|
|
71
|
+
/**
|
|
72
|
+
* Get recent thinking context for a session.
|
|
73
|
+
*
|
|
74
|
+
* Returns: Analytics data (read model) aggregated from trajectory database.
|
|
75
|
+
* Not: Runtime truth or real-time queue state.
|
|
76
|
+
*/
|
|
62
77
|
getRecentThinkingContext(sessionId: string, beforeCreatedAt: string, limit?: number): RecentThinkingContext;
|
|
78
|
+
/**
|
|
79
|
+
* Execute SQL query and return all rows.
|
|
80
|
+
*
|
|
81
|
+
* Returns: Analytics data (read model) aggregated from trajectory database.
|
|
82
|
+
* Not: Runtime truth or real-time queue state.
|
|
83
|
+
*/
|
|
63
84
|
all<T>(sql: string, ...params: unknown[]): T[];
|
|
85
|
+
/**
|
|
86
|
+
* Execute SQL query and return first row.
|
|
87
|
+
*
|
|
88
|
+
* Returns: Analytics data (read model) aggregated from trajectory database.
|
|
89
|
+
* Not: Runtime truth or real-time queue state.
|
|
90
|
+
*/
|
|
64
91
|
get<T>(sql: string, ...params: unknown[]): T | undefined;
|
|
65
92
|
restoreRawText(inlineText?: string | null, blobRef?: string | null): string;
|
|
66
93
|
private initSchema;
|
|
@@ -39,6 +39,12 @@ export class ControlUiDatabase {
|
|
|
39
39
|
return Number(result.lastInsertRowid);
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Get recent thinking context for a session.
|
|
44
|
+
*
|
|
45
|
+
* Returns: Analytics data (read model) aggregated from trajectory database.
|
|
46
|
+
* Not: Runtime truth or real-time queue state.
|
|
47
|
+
*/
|
|
42
48
|
getRecentThinkingContext(sessionId, beforeCreatedAt, limit = 5) {
|
|
43
49
|
return {
|
|
44
50
|
toolCalls: this.all(`
|
|
@@ -107,9 +113,21 @@ export class ControlUiDatabase {
|
|
|
107
113
|
})),
|
|
108
114
|
};
|
|
109
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Execute SQL query and return all rows.
|
|
118
|
+
*
|
|
119
|
+
* Returns: Analytics data (read model) aggregated from trajectory database.
|
|
120
|
+
* Not: Runtime truth or real-time queue state.
|
|
121
|
+
*/
|
|
110
122
|
all(sql, ...params) {
|
|
111
123
|
return this.db.prepare(sql).all(...params);
|
|
112
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Execute SQL query and return first row.
|
|
127
|
+
*
|
|
128
|
+
* Returns: Analytics data (read model) aggregated from trajectory database.
|
|
129
|
+
* Not: Runtime truth or real-time queue state.
|
|
130
|
+
*/
|
|
113
131
|
get(sql, ...params) {
|
|
114
132
|
return this.db.prepare(sql).get(...params);
|
|
115
133
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as os from 'os';
|
|
3
3
|
import * as fs from 'fs';
|
|
4
|
+
import { PathResolutionError } from '../config/index.js';
|
|
4
5
|
const DEFAULT_WORKSPACE_SUBPATH = '.openclaw/workspace';
|
|
5
6
|
export const PD_ENV_VARS = {
|
|
6
7
|
WORKSPACE_DIR: 'PD_WORKSPACE_DIR',
|
|
@@ -271,7 +272,7 @@ export class PathResolver {
|
|
|
271
272
|
const resolved = pathMap[key];
|
|
272
273
|
if (!resolved) {
|
|
273
274
|
this.log('warn', `Unknown path key: ${key}`);
|
|
274
|
-
throw new
|
|
275
|
+
throw new PathResolutionError(key);
|
|
275
276
|
}
|
|
276
277
|
this.log('debug', `Resolved path for '${key}': ${resolved}`);
|
|
277
278
|
return resolved;
|
|
@@ -205,12 +205,36 @@ export declare class TrajectoryDatabase {
|
|
|
205
205
|
recordEvolutionTask(input: EvolutionTaskInput): void;
|
|
206
206
|
updateEvolutionTask(taskId: string, updates: Partial<Omit<EvolutionTaskInput, 'taskId' | 'traceId' | 'source'>>): void;
|
|
207
207
|
recordEvolutionEvent(input: EvolutionEventInput): void;
|
|
208
|
+
/**
|
|
209
|
+
* List evolution tasks with optional filtering.
|
|
210
|
+
*
|
|
211
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
212
|
+
* Not: Runtime truth or real-time queue state.
|
|
213
|
+
*/
|
|
208
214
|
listEvolutionTasks(filters?: EvolutionTaskFilters): EvolutionTaskRecord[];
|
|
215
|
+
/**
|
|
216
|
+
* List evolution events for a trace or globally.
|
|
217
|
+
*
|
|
218
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
219
|
+
* Not: Runtime truth or real-time queue state.
|
|
220
|
+
*/
|
|
209
221
|
listEvolutionEvents(traceId?: string, filters?: {
|
|
210
222
|
limit?: number;
|
|
211
223
|
offset?: number;
|
|
212
224
|
}): EvolutionEventRecord[];
|
|
225
|
+
/**
|
|
226
|
+
* Get evolution task by trace ID.
|
|
227
|
+
*
|
|
228
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
229
|
+
* Not: Runtime truth or real-time queue state.
|
|
230
|
+
*/
|
|
213
231
|
getEvolutionTaskByTraceId(traceId: string): EvolutionTaskRecord | null;
|
|
232
|
+
/**
|
|
233
|
+
* Get evolution task statistics.
|
|
234
|
+
*
|
|
235
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
236
|
+
* Not: Runtime truth or real-time queue state.
|
|
237
|
+
*/
|
|
214
238
|
getEvolutionStats(): {
|
|
215
239
|
total: number;
|
|
216
240
|
pending: number;
|
|
@@ -218,14 +242,44 @@ export declare class TrajectoryDatabase {
|
|
|
218
242
|
completed: number;
|
|
219
243
|
failed: number;
|
|
220
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* List assistant turns for a session.
|
|
247
|
+
*
|
|
248
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
249
|
+
* Not: Runtime truth or real-time queue state.
|
|
250
|
+
*/
|
|
221
251
|
listAssistantTurns(sessionId: string): AssistantTurnRecord[];
|
|
252
|
+
/**
|
|
253
|
+
* List correction samples with optional review status filter.
|
|
254
|
+
*
|
|
255
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
256
|
+
* Not: Runtime truth or real-time queue state.
|
|
257
|
+
*/
|
|
222
258
|
listCorrectionSamples(status?: CorrectionSampleReviewStatus): CorrectionSampleRecord[];
|
|
223
259
|
reviewCorrectionSample(sampleId: string, status: Exclude<CorrectionSampleReviewStatus, 'pending'>, note?: string): CorrectionSampleRecord;
|
|
260
|
+
/**
|
|
261
|
+
* Export correction samples to JSONL file.
|
|
262
|
+
*
|
|
263
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
264
|
+
* Not: Runtime truth or real-time queue state.
|
|
265
|
+
*/
|
|
224
266
|
exportCorrections(opts: {
|
|
225
267
|
mode: CorrectionExportMode;
|
|
226
268
|
approvedOnly: boolean;
|
|
227
269
|
}): TrajectoryExportResult;
|
|
270
|
+
/**
|
|
271
|
+
* Export analytics data to JSON file.
|
|
272
|
+
*
|
|
273
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
274
|
+
* Not: Runtime truth or real-time queue state.
|
|
275
|
+
*/
|
|
228
276
|
exportAnalytics(): TrajectoryExportResult;
|
|
277
|
+
/**
|
|
278
|
+
* Get trajectory database statistics.
|
|
279
|
+
*
|
|
280
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
281
|
+
* Not: Runtime truth or real-time queue state.
|
|
282
|
+
*/
|
|
229
283
|
getDataStats(): TrajectoryDataStats;
|
|
230
284
|
cleanupBlobStorage(): {
|
|
231
285
|
removedFiles: number;
|
|
@@ -234,6 +288,12 @@ export declare class TrajectoryDatabase {
|
|
|
234
288
|
private initSchema;
|
|
235
289
|
private importLegacyArtifacts;
|
|
236
290
|
private migrateSchema;
|
|
291
|
+
/**
|
|
292
|
+
* Get daily metrics for analytics.
|
|
293
|
+
*
|
|
294
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
295
|
+
* Not: Runtime truth or real-time queue state.
|
|
296
|
+
*/
|
|
237
297
|
private dailyMetrics;
|
|
238
298
|
private importLegacySessions;
|
|
239
299
|
private importLegacyEvents;
|