principles-disciple 1.5.4 → 1.6.0

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.
Files changed (43) hide show
  1. package/dist/commands/context.d.ts +5 -0
  2. package/dist/commands/context.js +308 -0
  3. package/dist/commands/focus.d.ts +14 -0
  4. package/dist/commands/focus.js +579 -0
  5. package/dist/commands/pain.js +135 -6
  6. package/dist/commands/rollback.d.ts +19 -0
  7. package/dist/commands/rollback.js +119 -0
  8. package/dist/core/config.d.ts +32 -0
  9. package/dist/core/config.js +47 -0
  10. package/dist/core/event-log.d.ts +21 -1
  11. package/dist/core/event-log.js +316 -0
  12. package/dist/core/focus-history.d.ts +65 -0
  13. package/dist/core/focus-history.js +266 -0
  14. package/dist/core/init.js +30 -7
  15. package/dist/core/migration.js +0 -2
  16. package/dist/core/path-resolver.d.ts +3 -0
  17. package/dist/core/path-resolver.js +20 -0
  18. package/dist/hooks/gate.js +203 -1
  19. package/dist/hooks/llm.d.ts +8 -0
  20. package/dist/hooks/llm.js +234 -1
  21. package/dist/hooks/message-sanitize.d.ts +3 -0
  22. package/dist/hooks/message-sanitize.js +37 -0
  23. package/dist/hooks/prompt.d.ts +12 -0
  24. package/dist/hooks/prompt.js +309 -135
  25. package/dist/hooks/subagent.d.ts +9 -2
  26. package/dist/hooks/subagent.js +13 -2
  27. package/dist/i18n/commands.js +32 -20
  28. package/dist/index.js +181 -4
  29. package/dist/service/empathy-observer-manager.d.ts +42 -0
  30. package/dist/service/empathy-observer-manager.js +147 -0
  31. package/dist/service/evolution-worker.d.ts +1 -0
  32. package/dist/service/evolution-worker.js +4 -2
  33. package/dist/tools/deep-reflect.js +80 -0
  34. package/dist/types/event-types.d.ts +77 -2
  35. package/dist/types/event-types.js +33 -0
  36. package/dist/types.d.ts +42 -0
  37. package/dist/types.js +19 -1
  38. package/openclaw.plugin.json +1 -1
  39. package/package.json +3 -3
  40. package/templates/langs/zh/core/HEARTBEAT.md +28 -4
  41. package/templates/pain_settings.json +54 -2
  42. package/templates/workspace/.principles/PROFILE.json +2 -0
  43. package/templates/workspace/okr/CURRENT_FOCUS.md +57 -0
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Event types for structured logging and daily statistics.
3
3
  */
4
- export type EventType = 'tool_call' | 'pain_signal' | 'rule_match' | 'rule_promotion' | 'hook_execution' | 'gate_block' | 'plan_approval' | 'evolution_task' | 'deep_reflection' | 'trust_change' | 'error' | 'warn';
5
- export type EventCategory = 'success' | 'failure' | 'detected' | 'blocked' | 'approved' | 'enqueued' | 'completed' | 'promoted' | 'passed' | 'changed';
4
+ export type EventType = 'tool_call' | 'pain_signal' | 'rule_match' | 'rule_promotion' | 'hook_execution' | 'gate_block' | 'plan_approval' | 'evolution_task' | 'deep_reflection' | 'trust_change' | 'empathy_rollback' | 'error' | 'warn';
5
+ export type EventCategory = 'success' | 'failure' | 'detected' | 'blocked' | 'approved' | 'enqueued' | 'completed' | 'promoted' | 'passed' | 'changed' | 'rolled_back';
6
6
  /**
7
7
  * Base event structure for JSONL logging.
8
8
  */
@@ -42,6 +42,14 @@ export interface PainSignalEventData {
42
42
  source: string;
43
43
  reason?: string;
44
44
  isRisky?: boolean;
45
+ origin?: 'assistant_self_report' | 'user_manual' | 'system_infer';
46
+ severity?: 'mild' | 'moderate' | 'severe';
47
+ confidence?: number;
48
+ detection_mode?: 'structured' | 'legacy_tag';
49
+ deduped?: boolean;
50
+ trigger_text_excerpt?: string;
51
+ raw_score?: number;
52
+ calibrated_score?: number;
45
53
  }
46
54
  export interface RuleMatchEventData {
47
55
  ruleId: string;
@@ -106,6 +114,18 @@ export interface DeepReflectionEventData {
106
114
  /** 发现的风险数量 */
107
115
  risksCount?: number;
108
116
  }
117
+ export interface EmpathyRollbackEventData {
118
+ /** Event ID being rolled back */
119
+ eventId: string;
120
+ /** Original penalty score that was applied */
121
+ originalScore: number;
122
+ /** Session ID where the original event occurred */
123
+ originalSessionId?: string;
124
+ /** Reason for rollback (manual, false_positive, etc.) */
125
+ reason: string;
126
+ /** Who initiated the rollback */
127
+ triggeredBy: 'user_command' | 'natural_language' | 'system';
128
+ }
109
129
  export interface ToolCallStats {
110
130
  total: number;
111
131
  success: number;
@@ -128,6 +148,59 @@ export interface PainStats {
128
148
  avgScore: number;
129
149
  maxScore: number;
130
150
  }
151
+ /**
152
+ * Empathy Engine event statistics for tracking emotional signals.
153
+ * Used for /pd-status empathy card and effectiveness metrics.
154
+ */
155
+ export interface EmpathyEventStats {
156
+ /** Total empathy events detected (excluding deduped) */
157
+ totalEvents: number;
158
+ /** Events that were deduped (not counted in totalEvents) */
159
+ dedupedCount: number;
160
+ /** Dedupe hit rate (dedupedCount / (totalEvents + dedupedCount)) */
161
+ dedupeHitRate: number;
162
+ /** Total penalty score applied */
163
+ totalPenaltyScore: number;
164
+ /** Score rolled back via manual rollback */
165
+ rolledBackScore: number;
166
+ /** Number of rollback operations */
167
+ rollbackCount: number;
168
+ /** Events by severity level */
169
+ bySeverity: {
170
+ mild: number;
171
+ moderate: number;
172
+ severe: number;
173
+ };
174
+ /** Score by severity level */
175
+ scoreBySeverity: {
176
+ mild: number;
177
+ moderate: number;
178
+ severe: number;
179
+ };
180
+ /** Events by detection mode */
181
+ byDetectionMode: {
182
+ structured: number;
183
+ legacy_tag: number;
184
+ };
185
+ /** Events by origin */
186
+ byOrigin: {
187
+ assistant_self_report: number;
188
+ user_manual: number;
189
+ system_infer: number;
190
+ };
191
+ /** Confidence distribution */
192
+ confidenceDistribution: {
193
+ high: number;
194
+ medium: number;
195
+ low: number;
196
+ };
197
+ /** Daily trend (last 7 days) */
198
+ dailyTrend: Array<{
199
+ date: string;
200
+ count: number;
201
+ score: number;
202
+ }>;
203
+ }
131
204
  export interface GfiStats {
132
205
  peak: number;
133
206
  samples: number;
@@ -214,6 +287,8 @@ export interface DailyStats {
214
287
  errors: ErrorStats;
215
288
  /** Pain signal statistics */
216
289
  pain: PainStats;
290
+ /** Empathy Engine event statistics */
291
+ empathy: EmpathyEventStats;
217
292
  /** GFI statistics */
218
293
  gfi: GfiStats;
219
294
  /** Evolution statistics */
@@ -34,6 +34,39 @@ export function createEmptyDailyStats(date) {
34
34
  avgScore: 0,
35
35
  maxScore: 0,
36
36
  },
37
+ empathy: {
38
+ totalEvents: 0,
39
+ dedupedCount: 0,
40
+ dedupeHitRate: 0,
41
+ totalPenaltyScore: 0,
42
+ rolledBackScore: 0,
43
+ rollbackCount: 0,
44
+ bySeverity: {
45
+ mild: 0,
46
+ moderate: 0,
47
+ severe: 0,
48
+ },
49
+ scoreBySeverity: {
50
+ mild: 0,
51
+ moderate: 0,
52
+ severe: 0,
53
+ },
54
+ byDetectionMode: {
55
+ structured: 0,
56
+ legacy_tag: 0,
57
+ },
58
+ byOrigin: {
59
+ assistant_self_report: 0,
60
+ user_manual: 0,
61
+ system_infer: 0,
62
+ },
63
+ confidenceDistribution: {
64
+ high: 0,
65
+ medium: 0,
66
+ low: 0,
67
+ },
68
+ dailyTrend: [],
69
+ },
37
70
  gfi: {
38
71
  peak: 0,
39
72
  samples: 0,
package/dist/types.d.ts CHANGED
@@ -1 +1,43 @@
1
1
  export type { PluginCommandContext, PluginCommandResult } from './openclaw-sdk.js';
2
+ /**
3
+ * Context Injection Configuration
4
+ * Controls what content gets injected into the LLM prompt.
5
+ *
6
+ * NOTE: Core Principles (PRINCIPLES.md) are ALWAYS injected and cannot be disabled.
7
+ * This is by design - principles are the foundation of the agent's behavior.
8
+ */
9
+ export type ProjectFocusMode = 'full' | 'summary' | 'off';
10
+ export interface ContextInjectionConfig {
11
+ /** Thinking OS (mental models) - can be toggled */
12
+ thinkingOs: boolean;
13
+ /** Project context (CURRENT_FOCUS.md) mode */
14
+ projectFocus: ProjectFocusMode;
15
+ /** Reflection log - can be toggled */
16
+ reflectionLog: boolean;
17
+ /** Trust score awareness - can be toggled */
18
+ trustScore: boolean;
19
+ }
20
+ /**
21
+ * Default context injection configuration
22
+ * Based on user requirements:
23
+ * - principles: always on (not configurable)
24
+ * - thinkingOs: true (can be turned off)
25
+ * - projectFocus: 'off' (default closed, user can enable)
26
+ * - reflectionLog: true (default on)
27
+ * - trustScore: true (can be turned off)
28
+ */
29
+ export declare const defaultContextConfig: ContextInjectionConfig;
30
+ /**
31
+ * Reflection log entry structure
32
+ */
33
+ export interface ReflectionLogEntry {
34
+ timestamp: string;
35
+ context: string;
36
+ insights: string;
37
+ modelId?: string;
38
+ depth?: number;
39
+ }
40
+ /**
41
+ * Reflection log retention configuration
42
+ */
43
+ export declare const reflectionLogRetentionDays = 7;
package/dist/types.js CHANGED
@@ -1 +1,19 @@
1
- export {};
1
+ /**
2
+ * Default context injection configuration
3
+ * Based on user requirements:
4
+ * - principles: always on (not configurable)
5
+ * - thinkingOs: true (can be turned off)
6
+ * - projectFocus: 'off' (default closed, user can enable)
7
+ * - reflectionLog: true (default on)
8
+ * - trustScore: true (can be turned off)
9
+ */
10
+ export const defaultContextConfig = {
11
+ thinkingOs: true,
12
+ projectFocus: 'off',
13
+ reflectionLog: true,
14
+ trustScore: true,
15
+ };
16
+ /**
17
+ * Reflection log retention configuration
18
+ */
19
+ export const reflectionLogRetentionDays = 7;
@@ -2,7 +2,7 @@
2
2
  "id": "principles-disciple",
3
3
  "name": "Principles Disciple",
4
4
  "description": "Evolutionary programming agent framework with strategic guardrails and reflection loops.",
5
- "version": "1.5.0",
5
+ "version": "1.6.0",
6
6
  "skills": ["./skills"],
7
7
  "configSchema": {
8
8
  "type": "object",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "principles-disciple",
3
- "version": "1.5.4",
3
+ "version": "1.6.0",
4
4
  "description": "Native OpenClaw plugin for Principles Disciple",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/micromatch": "^4.0.10",
43
- "@types/node": "^20.0.0",
43
+ "@types/node": "^25.5.0",
44
44
  "@types/ws": "^8.5.13",
45
45
  "@vitest/coverage-v8": "^4.1.0",
46
46
  "esbuild": "^0.27.4",
@@ -60,4 +60,4 @@
60
60
  "@sinclair/typebox": "^0.34.48",
61
61
  "micromatch": "^4.0.8"
62
62
  }
63
- }
63
+ }
@@ -18,10 +18,34 @@
18
18
 
19
19
  ## 📋 CURRENT_FOCUS.md 维护(每3次心跳)
20
20
 
21
- - [ ] **检查文件大小**:目标 < 50 行
22
- - [ ] **如 > 50 行**:压缩已完成里程碑到 `MEMORY.md`
23
- - [ ] **验证内容**:无过期日期或已完成任务
24
- - [ ] **只保留**:当前阶段、进行中任务、下一步
21
+ ### 检查与压缩
22
+
23
+ - [ ] **检查文件大小**:目标 < 40 行
24
+ - [ ] **如 > 40 行**:执行压缩流程(见下方)
25
+
26
+ ### 压缩流程
27
+
28
+ 1. **备份当前版本**:复制到 `memory/okr/.history/CURRENT_FOCUS.v{N}.{date}.md`
29
+ 2. **递增版本号**:修改 `**版本**: v{N+1}`
30
+ 3. **更新日期**:修改 `**更新**: {today}`
31
+ 4. **压缩内容**:
32
+ - 移除已完成的 P0/P1 任务(保留 P2)
33
+ - 将重要里程碑移到 `MEMORY.md`
34
+ - 保留:状态快照、当前任务、下一步
35
+ 5. **清理历史**:保留最近 10 个历史版本
36
+
37
+ ### 模板结构(编辑时遵循)
38
+
39
+ ```markdown
40
+ # 🎯 CURRENT_FOCUS
41
+
42
+ > **版本**: v{N} | **状态**: {状态} | **更新**: {日期}
43
+
44
+ ## 📍 状态快照 ← 必须保留
45
+ ## 🔄 当前任务 ← 必须保留
46
+ ## ➡️ 下一步 ← 必须保留(summary 模式优先提取)
47
+ ## 📎 参考 ← 可选
48
+ ```
25
49
 
26
50
  ---
27
51
 
@@ -68,10 +68,62 @@
68
68
  "auto_trigger_conditions": {
69
69
  "min_tool_calls": 5,
70
70
  "error_rate_threshold": 0.3,
71
- "complexity_keywords": ["refactor", "architecture", "design", "optimize", "security", "critical"]
71
+ "complexity_keywords": [
72
+ "refactor",
73
+ "architecture",
74
+ "design",
75
+ "optimize",
76
+ "security",
77
+ "critical"
78
+ ]
72
79
  },
73
80
  "default_model": "T-01",
74
81
  "default_depth": 2,
75
82
  "timeout_ms": 60000
83
+ },
84
+ "empathy_engine": {
85
+ "enabled": true,
86
+ "dedupe_window_ms": 60000,
87
+ "penalties": {
88
+ "mild": 10,
89
+ "moderate": 25,
90
+ "severe": 40
91
+ },
92
+ "rate_limit": {
93
+ "max_per_turn": 40,
94
+ "max_per_hour": 120
95
+ },
96
+ "model_calibration": {}
97
+ },
98
+ "gfi_gate": {
99
+ "enabled": true,
100
+ "thresholds": {
101
+ "low_risk_block": 70,
102
+ "high_risk_block": 40,
103
+ "large_change_block": 50
104
+ },
105
+ "large_change_lines": 50,
106
+ "trust_stage_multipliers": {
107
+ "1": 0.5,
108
+ "2": 0.75,
109
+ "3": 1.0,
110
+ "4": 1.5
111
+ },
112
+ "bash_safe_patterns": [
113
+ "^(ls|dir|pwd|which|where|echo|env|cat|type|head|tail|less|more)\\b",
114
+ "^git\\s+(status|log|diff|branch|show|remote)\\b",
115
+ "^npm\\s+(run|test|build|start)\\b",
116
+ "^(make|gradle|mvn)\\b"
117
+ ],
118
+ "bash_dangerous_patterns": [
119
+ "rm\\s+(-[a-z]*r[a-z]*f|-rf)",
120
+ "del\\s+/s",
121
+ "rmdir\\s+/s",
122
+ "git\\s+(push\\s+.*--force|reset\\s+--hard|clean\\s+-fd)",
123
+ "npm\\s+publish",
124
+ "pip\\s+upload",
125
+ "docker\\s+push",
126
+ "(curl|wget).*\\|\\s*(ba)?sh"
127
+ ]
76
128
  }
77
- }
129
+ }
@@ -6,6 +6,7 @@
6
6
  "IDENTITY.md",
7
7
  "USER.md",
8
8
  "docs/PRINCIPLES.md",
9
+ ".principles/PROFILE.json",
9
10
  "docs/PROFILE.json"
10
11
  ],
11
12
  "gate": {
@@ -22,6 +23,7 @@
22
23
  "IDENTITY.md",
23
24
  "USER.md",
24
25
  "docs/PRINCIPLES.md",
26
+ ".principles/PROFILE.json",
25
27
  "docs/PROFILE.json",
26
28
  "docs/okr/**"
27
29
  ],
@@ -0,0 +1,57 @@
1
+ # 🎯 CURRENT_FOCUS
2
+
3
+ > **版本**: v1 | **状态**: INIT | **更新**: {YYYY-MM-DD}
4
+
5
+ ---
6
+
7
+ ## 📍 状态快照
8
+
9
+ | 维度 | 值 |
10
+ |------|-----|
11
+ | 当前阶段 | 初始化 |
12
+ | 信任分数 | 85/100 |
13
+ | 认知卫生 | ✅ 清爽 |
14
+
15
+ ---
16
+
17
+ ## 🔄 当前任务
18
+
19
+ ### P0(阻塞/紧急)
20
+ <!-- 阻塞项,需要立即处理 -->
21
+ - [ ] 无
22
+
23
+ ### P1(进行中)
24
+ <!-- 当前正在进行的核心任务,最多 3 项 -->
25
+ - [ ] {任务描述} ← 当前
26
+
27
+ ### P2(待办)
28
+ <!-- 优先级较低的待办事项 -->
29
+ - [ ] {任务描述}
30
+
31
+ ---
32
+
33
+ ## ➡️ 下一步
34
+
35
+ <!-- 下一步行动,按优先级排序 -->
36
+ 1. {下一步行动1}
37
+ 2. {下一步行动2}
38
+
39
+ ---
40
+
41
+ ## 📎 参考
42
+
43
+ | 资源 | 路径 |
44
+ |------|------|
45
+ | 详细计划 | `memory/tasks/{任务目录}/PLAN.md` |
46
+ | 历史版本 | `memory/okr/.history/` |
47
+ | 任务列表 | `memory/okr/WEEK_TASKS.json` |
48
+
49
+ ---
50
+
51
+ <!--
52
+ 编辑指南:
53
+ 1. 版本号每次压缩时 +1
54
+ 2. 状态可选:INIT | PLANNING | EXECUTING | BLOCKED | DONE
55
+ 3. 压缩时备份到 .history/CURRENT_FOCUS.v{N}.{date}.md
56
+ 4. 目标:< 40 行,超过时压缩已完成任务到 MEMORY.md
57
+ -->