principles-disciple 1.66.0 → 1.67.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.
@@ -1,100 +1 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import type { OpenClawPluginApi } from '../openclaw-sdk.js';
4
- import { WorkspaceContext } from '../core/workspace-context.js';
5
-
6
- // 安全日志函数
7
- function safeLog(
8
- api: OpenClawPluginApi | undefined,
9
- level: 'info' | 'debug' | 'warn' | 'error',
10
- message: string
11
- ): void {
12
- try {
13
- if (api?.logger && typeof api.logger[level] === 'function') {
14
- api.logger[level](message);
15
- }
16
- } catch {
17
- // Ignore logging errors
18
- }
19
- }
20
-
21
- /**
22
- * 默认消息
23
- */
24
- const DEFAULT_MESSAGE = '(暂无扩展思维模型)';
25
-
26
- /**
27
- * 索引文件最大大小(字节)
28
- */
29
- const MAX_INDEX_SIZE = 50 * 1024; // 50KB
30
-
31
- /**
32
- * 加载自定义配置
33
- */
34
- function loadCustomConfig(wctx: WorkspaceContext): { modelsDir?: string } | undefined {
35
- try {
36
- const {config} = wctx;
37
- const modelsDir = config.get('deep_reflection.modelsDir');
38
- if (typeof modelsDir === 'string' && modelsDir.trim()) {
39
- return { modelsDir: modelsDir.trim() };
40
- }
41
- } catch {
42
- // Ignore config errors
43
- }
44
- return undefined;
45
- }
46
-
47
- /**
48
- * 加载模型索引并返回格式化后的字符串
49
- *
50
- * @param workspaceDir 工作区目录
51
- * @param api OpenClaw 插件 API
52
- * @returns 格式化后的模型索引内容或默认消息
53
- */
54
- export function loadModelIndex(
55
- workspaceDir: string,
56
- api?: OpenClawPluginApi
57
- ): string {
58
- if (!workspaceDir) return DEFAULT_MESSAGE;
59
-
60
- try {
61
- const wctx = WorkspaceContext.fromHookContext({ workspaceDir });
62
- const customConfig = loadCustomConfig(wctx);
63
-
64
-
65
-
66
- let modelsDir: string;
67
- if (customConfig?.modelsDir) {
68
- modelsDir = path.isAbsolute(customConfig.modelsDir)
69
- ? customConfig.modelsDir
70
- : path.join(workspaceDir, customConfig.modelsDir);
71
-
72
- // 👈 关键修复:显式输出测试用例期待的 debug 日志
73
- safeLog(api, 'debug', `[DeepReflect] Using custom models dir: ${modelsDir}`);
74
- } else {
75
- modelsDir = wctx.resolve('MODELS_DIR');
76
- }
77
-
78
- const indexPath = path.join(modelsDir, '_INDEX.md');
79
-
80
- if (!fs.existsSync(indexPath)) {
81
- if (fs.existsSync(modelsDir)) {
82
- safeLog(api, 'warn', `[DeepReflect] _INDEX.md not found but ${modelsDir.replace(workspaceDir, '')} exists. Please create an index file.`);
83
- }
84
- return DEFAULT_MESSAGE;
85
- }
86
-
87
- const stats = fs.statSync(indexPath);
88
- if (stats.size > MAX_INDEX_SIZE) {
89
- safeLog(api, 'warn', `[DeepReflect] Index file too large (${stats.size} bytes). Max is ${MAX_INDEX_SIZE}.`);
90
- return DEFAULT_MESSAGE;
91
- }
92
-
93
- const content = fs.readFileSync(indexPath, 'utf-8');
94
- return content.trim() || DEFAULT_MESSAGE;
95
-
96
- } catch (err) {
97
- safeLog(api, 'warn', `[DeepReflect] Failed to load model index: ${String(err)}`);
98
- return DEFAULT_MESSAGE;
99
- }
100
- }
1
+ export {};
@@ -13,7 +13,6 @@ import type {
13
13
  GateBypassEventData,
14
14
  PlanApprovalEventData,
15
15
  EvolutionTaskEventData,
16
- DeepReflectionEventData,
17
16
  EmpathyRollbackEventData,
18
17
  EventCategory,
19
18
  } from './event-types.js';
@@ -28,7 +27,6 @@ export type EventLogEntry =
28
27
  | { ts: string; date: string; type: 'gate_bypass'; category: EventCategory; sessionId?: string; workspaceDir?: string; data: GateBypassEventData }
29
28
  | { ts: string; date: string; type: 'plan_approval'; category: EventCategory; sessionId?: string; workspaceDir?: string; data: PlanApprovalEventData }
30
29
  | { ts: string; date: string; type: 'evolution_task'; category: EventCategory; sessionId?: string; workspaceDir?: string; data: EvolutionTaskEventData }
31
- | { ts: string; date: string; type: 'deep_reflection'; category: EventCategory; sessionId?: string; workspaceDir?: string; data: DeepReflectionEventData }
32
30
  | { ts: string; date: string; type: 'empathy_rollback'; category: EventCategory; sessionId?: string; workspaceDir?: string; data: EmpathyRollbackEventData }
33
31
  | { ts: string; date: string; type: 'error'; category: EventCategory; sessionId?: string; workspaceDir?: string; data: Record<string, unknown> }
34
32
  | { ts: string; date: string; type: 'warn'; category: EventCategory; sessionId?: string; workspaceDir?: string; data: Record<string, unknown> };
@@ -71,10 +69,6 @@ export function isEvolutionTaskEventEntry(entry: EventLogEntry): entry is Extrac
71
69
  return entry.type === 'evolution_task';
72
70
  }
73
71
 
74
- export function isDeepReflectionEventEntry(entry: EventLogEntry): entry is Extract<EventLogEntry, { type: 'deep_reflection' }> {
75
- return entry.type === 'deep_reflection';
76
- }
77
-
78
72
  export function isEmpathyRollbackEventEntry(entry: EventLogEntry): entry is Extract<EventLogEntry, { type: 'empathy_rollback' }> {
79
73
  return entry.type === 'empathy_rollback';
80
74
  }
@@ -14,7 +14,6 @@ export type EventType =
14
14
  | 'gate_bypass'
15
15
  | 'plan_approval'
16
16
  | 'evolution_task'
17
- | 'deep_reflection'
18
17
  | 'empathy_rollback'
19
18
  | 'error'
20
19
  | 'warn'
@@ -154,35 +153,6 @@ export interface EvolutionTaskEventData {
154
153
  reason: string;
155
154
  }
156
155
 
157
- export interface DeepReflectionEventData {
158
- /** 思维模型 ID (T-01 到 T-09),向后兼容 */
159
- modelId: string;
160
- /** 模型选择模式:'manual' = 用户指定 model_id,'auto' = 子智能体自动选择 */
161
- modelSelectionMode: 'manual' | 'auto';
162
- /** 反思深度 (1-3) */
163
- depth: number;
164
- /** 上下文摘要(前 200 字符) */
165
- contextPreview: string;
166
- /** 反思结果摘要 */
167
- resultPreview?: string;
168
- /** 执行耗时 (ms) */
169
- durationMs: number;
170
- /** 是否通过(未发现显著问题) */
171
- passed: boolean;
172
- /** 是否超时 */
173
- timeout: boolean;
174
- /** 错误信息 */
175
- error?: string;
176
- /** 输出长度 */
177
- outputLength?: number;
178
- /** 置信度(从输出中提取) */
179
- confidence?: 'LOW' | 'MEDIUM' | 'HIGH';
180
- /** 发现的盲点数量 */
181
- blindSpotsCount?: number;
182
- /** 发现的风险数量 */
183
- risksCount?: number;
184
- }
185
-
186
156
  export interface EmpathyRollbackEventData {
187
157
  /** Event ID being rolled back */
188
158
  eventId: string;
@@ -438,42 +408,6 @@ export interface HookStats {
438
408
  totalDurationMs: number;
439
409
  }
440
410
 
441
- export interface DeepReflectionStats {
442
- /** 总调用次数 */
443
- totalCalls: number;
444
- /** 通过次数(未发现问题) */
445
- passedCount: number;
446
- /** 发现问题的次数 */
447
- issuesFoundCount: number;
448
- /** 超时次数 */
449
- timeoutCount: number;
450
- /** 错误次数 */
451
- errorCount: number;
452
- /** 按模型选择模式统计 */
453
- bySelectionMode: {
454
- manual: { count: number; avgDurationMs: number; passedCount: number };
455
- auto: { count: number; avgDurationMs: number; passedCount: number };
456
- };
457
- /** 按模型统计(向后兼容,仅记录手动指定的 model_id) */
458
- byModel: Record<string, {
459
- count: number;
460
- avgDurationMs: number;
461
- passedCount: number;
462
- }>;
463
- /** 按深度统计 */
464
- byDepth: Record<number, number>;
465
- /** 总耗时 */
466
- totalDurationMs: number;
467
- /** 平均耗时 */
468
- avgDurationMs: number;
469
- /** 发现的总盲点数 */
470
- totalBlindSpots: number;
471
- /** 发现的总风险数 */
472
- totalRisks: number;
473
- /** 置信度分布 */
474
- confidenceDistribution: { LOW: number; MEDIUM: number; HIGH: number };
475
- }
476
-
477
411
  /**
478
412
  * Daily aggregated statistics.
479
413
  */
@@ -504,8 +438,6 @@ export interface DailyStats {
504
438
  evolution: EvolutionStats;
505
439
  /** Hook execution statistics */
506
440
  hooks: HookStats;
507
- /** Deep Reflection statistics */
508
- deepReflection: DeepReflectionStats;
509
441
  }
510
442
 
511
443
  /**
@@ -611,23 +543,5 @@ export function createEmptyDailyStats(date: string): DailyStats {
611
543
  errors: 0,
612
544
  totalDurationMs: 0,
613
545
  },
614
- deepReflection: {
615
- totalCalls: 0,
616
- passedCount: 0,
617
- issuesFoundCount: 0,
618
- timeoutCount: 0,
619
- errorCount: 0,
620
- bySelectionMode: {
621
- manual: { count: 0, avgDurationMs: 0, passedCount: 0 },
622
- auto: { count: 0, avgDurationMs: 0, passedCount: 0 },
623
- },
624
- byModel: {},
625
- byDepth: {},
626
- totalDurationMs: 0,
627
- avgDurationMs: 0,
628
- totalBlindSpots: 0,
629
- totalRisks: 0,
630
- confidenceDistribution: { LOW: 0, MEDIUM: 0, HIGH: 0 },
631
- },
632
546
  };
633
547
  }
package/src/types.ts CHANGED
@@ -31,9 +31,6 @@ export interface ContextInjectionConfig {
31
31
  /** Project context (CURRENT_FOCUS.md) mode */
32
32
  projectFocus: ProjectFocusMode;
33
33
 
34
- /** Reflection log - can be toggled */
35
- reflectionLog: boolean;
36
-
37
34
  /** Evolution task context injection settings */
38
35
  evolutionContext: EvolutionContextConfig;
39
36
  }
@@ -44,31 +41,13 @@ export interface ContextInjectionConfig {
44
41
  * - principles: always on (not configurable)
45
42
  * - thinkingOs: true (can be turned off)
46
43
  * - projectFocus: 'off' (default closed, user can enable)
47
- * - reflectionLog: true (default on)
48
44
  */
49
45
  export const defaultContextConfig: ContextInjectionConfig = {
50
46
  thinkingOs: true,
51
47
  projectFocus: 'off',
52
- reflectionLog: true,
53
48
  evolutionContext: {
54
49
  enabled: true,
55
50
  maxMessages: 4,
56
51
  maxCharsPerMessage: 200,
57
52
  },
58
53
  };
59
-
60
- /**
61
- * Reflection log entry structure
62
- */
63
- export interface ReflectionLogEntry {
64
- timestamp: string;
65
- context: string;
66
- insights: string;
67
- modelId?: string;
68
- depth?: number;
69
- }
70
-
71
- /**
72
- * Reflection log retention configuration
73
- */
74
- export const reflectionLogRetentionDays = 7;
@@ -6,49 +6,6 @@
6
6
  - **Tool Preference**: Prefer `rg` (ripgrep) for high-performance search. Never blindly traverse.
7
7
 
8
8
 
9
- ## 3. Deep Reflection Tool
10
- `deep_reflect` is a **Cognitive Analysis Tool** — Performs critical analysis before executing complex tasks to identify blind spots, risks, and alternatives.
11
-
12
- ### When to Call
13
- - **Complex Tasks**: Planning, design, decision-making, analysis requiring deep thinking
14
- - **Insufficient Information**: Vague requirements, unclear constraints, missing key information
15
- - **High-Stakes Decisions**: Important decisions, irreversible actions, broad impact
16
- - **Uncertainty**: Unsure about the best approach, need multiple perspectives
17
-
18
- ### Use Case Examples
19
- - Marketing strategy design: Analyze target audience, channel selection, risk mitigation
20
- - Product feature planning: Evaluate user needs, technical feasibility, resource investment
21
- - Architecture decisions: Weigh pros and cons, identify potential risks
22
- - Problem diagnosis: Multi-angle root cause analysis, avoid missing key factors
23
-
24
- ### How to Call
25
- ```
26
- deep_reflect(
27
- model_id: "T-01" | "T-02" | ... | "T-09", // T-01 for planning, T-05 for risk analysis
28
- context: "Describe your plan and concerns...",
29
- depth: 1 | 2 | 3 // 1=quick, 2=balanced, 3=exhaustive
30
- )
31
- ```
32
-
33
- ### Thinking Model Selection
34
- | Model | Name | Best For |
35
- |-------|------|----------|
36
- | T-01 | Map Before Territory | Planning, design, understanding systems |
37
- | T-05 | Negation Before Affirmation | Risk analysis, finding flaws |
38
- | T-07 | Systems Over Components | Architecture decisions, integration issues |
39
-
40
- ### Output Structure
41
- Tool returns: Blind Spots → Risk Warnings → Alternative Approaches → Recommendations → Confidence Level
42
-
43
- **Note**: This is critical feedback. You make the final decision. Consider suggestions seriously, but don't follow blindly.
44
-
45
- ### Benefits
46
- - Identifies blind spots and missing information
47
- - Surfaces potential risks and failure modes
48
- - Provides alternative approaches with trade-off analysis
49
- - Applies structured thinking models for deeper insight
50
-
51
- ---
52
9
 
53
10
  ## 4. Agent Routing Clarification
54
11
 
@@ -6,49 +6,6 @@
6
6
  - **工具偏好**:优先使用 `rg` (ripgrep) 进行高性能检索,严禁盲目遍历。
7
7
 
8
8
 
9
- ## 3. 深度反思工具 (Deep Reflection)
10
- `deep_reflect` 是**认知分析工具**——在执行复杂任务前,进行批判性分析,识别盲点、风险和替代方案。
11
-
12
- ### 何时应该调用
13
- - **复杂任务**:规划、设计、决策、分析等需要深思熟虑的场景
14
- - **信息不足**:需求模糊、约束不明确、缺少关键信息
15
- - **高风险决策**:重要决策、不可逆操作、影响范围大
16
- - **不确定时**:对最佳方案存疑,需要多角度思考
17
-
18
- ### 使用场景示例
19
- - 营销方案设计:分析目标受众、渠道选择、风险预案
20
- - 产品功能规划:评估用户需求、技术可行性、资源投入
21
- - 架构设计决策:权衡方案优劣、识别潜在风险
22
- - 问题分析诊断:多角度分析根因、避免遗漏关键因素
23
-
24
- ### 带来的好处
25
- - 识别可能遗漏的盲点
26
- - 发现潜在风险和失败模式
27
- - 提供替代方案及权衡分析
28
- - 应用结构化思维模型深化洞察
29
-
30
- ### 如何调用
31
- ```
32
- deep_reflect(
33
- model_id: "T-01" | "T-02" | ... | "T-09", // 推荐 T-01 或 T-05
34
- context: "描述你的计划和担忧...",
35
- depth: 1 | 2 | 3 // 1=快速, 2=平衡, 3=详尽
36
- )
37
- ```
38
-
39
- ### 思维模型选择
40
- | 模型 | 名称 | 适用场景 |
41
- |------|------|----------|
42
- | T-01 | 地图先于领土 | 规划、设计、理解系统 |
43
- | T-05 | 否定优于肯定 | 风险分析、找漏洞 |
44
- | T-07 | 系统优于组件 | 架构决策、集成问题 |
45
-
46
- ### 输出结构
47
- 工具返回:盲点分析 → 风险警告 → 替代方案 → 建议 → 置信度
48
-
49
- **注意**:这是批判性反馈,最终决策权在你。认真考虑建议,但不必盲目遵循。
50
-
51
- ---
52
9
 
53
10
  ## 4. 智能体路由澄清
54
11
 
@@ -60,27 +60,6 @@
60
60
  "stage_3_max_lines": 300
61
61
  }
62
62
  },
63
- "deep_reflection": {
64
- "enabled": true,
65
- "mode": "auto",
66
- "force_checkpoint": true,
67
- "checkpoint_message": "Before responding, quick self-check: 1. Task complexity (simple/medium/complex) 2. Information sufficiency (sufficient/need more) 3. If complex or insufficient info, call deep_reflect tool",
68
- "auto_trigger_conditions": {
69
- "min_tool_calls": 5,
70
- "error_rate_threshold": 0.3,
71
- "complexity_keywords": [
72
- "refactor",
73
- "architecture",
74
- "design",
75
- "optimize",
76
- "security",
77
- "critical"
78
- ]
79
- },
80
- "default_model": "T-01",
81
- "default_depth": 2,
82
- "timeout_ms": 60000
83
- },
84
63
  "empathy_engine": {
85
64
  "enabled": true,
86
65
  "dedupe_window_ms": 60000,