principles-disciple 1.7.4 → 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.
Files changed (78) hide show
  1. package/dist/commands/evolution-status.js +32 -44
  2. package/dist/commands/focus.js +30 -155
  3. package/dist/config/defaults/runtime.d.ts +40 -0
  4. package/dist/config/defaults/runtime.js +44 -0
  5. package/dist/config/errors.d.ts +84 -0
  6. package/dist/config/errors.js +94 -0
  7. package/dist/config/index.d.ts +7 -0
  8. package/dist/config/index.js +7 -0
  9. package/dist/constants/diagnostician.d.ts +12 -0
  10. package/dist/constants/diagnostician.js +56 -0
  11. package/dist/constants/tools.d.ts +2 -2
  12. package/dist/constants/tools.js +1 -1
  13. package/dist/core/config.d.ts +12 -0
  14. package/dist/core/config.js +7 -0
  15. package/dist/core/control-ui-db.d.ts +27 -0
  16. package/dist/core/control-ui-db.js +18 -0
  17. package/dist/core/evolution-engine.js +1 -1
  18. package/dist/core/focus-history.d.ts +92 -0
  19. package/dist/core/focus-history.js +490 -0
  20. package/dist/core/init.js +2 -2
  21. package/dist/core/path-resolver.js +2 -1
  22. package/dist/core/profile.js +1 -1
  23. package/dist/core/trajectory.d.ts +60 -0
  24. package/dist/core/trajectory.js +72 -2
  25. package/dist/hooks/bash-risk.d.ts +57 -0
  26. package/dist/hooks/bash-risk.js +137 -0
  27. package/dist/hooks/edit-verification.d.ts +62 -0
  28. package/dist/hooks/edit-verification.js +256 -0
  29. package/dist/hooks/gate-block-helper.d.ts +44 -0
  30. package/dist/hooks/gate-block-helper.js +119 -0
  31. package/dist/hooks/gate.d.ts +18 -0
  32. package/dist/hooks/gate.js +63 -752
  33. package/dist/hooks/gfi-gate.d.ts +40 -0
  34. package/dist/hooks/gfi-gate.js +112 -0
  35. package/dist/hooks/progressive-trust-gate.d.ts +79 -0
  36. package/dist/hooks/progressive-trust-gate.js +242 -0
  37. package/dist/hooks/prompt.js +83 -28
  38. package/dist/hooks/subagent.js +1 -2
  39. package/dist/hooks/thinking-checkpoint.d.ts +37 -0
  40. package/dist/hooks/thinking-checkpoint.js +51 -0
  41. package/dist/http/principles-console-route.d.ts +7 -0
  42. package/dist/http/principles-console-route.js +255 -3
  43. package/dist/index.js +0 -2
  44. package/dist/service/central-database.d.ts +104 -0
  45. package/dist/service/central-database.js +649 -0
  46. package/dist/service/control-ui-query-service.d.ts +1 -1
  47. package/dist/service/control-ui-query-service.js +3 -3
  48. package/dist/service/evolution-query-service.d.ts +1 -1
  49. package/dist/service/evolution-query-service.js +5 -5
  50. package/dist/service/evolution-worker.d.ts +10 -0
  51. package/dist/service/evolution-worker.js +10 -6
  52. package/dist/service/phase3-input-filter.d.ts +57 -0
  53. package/dist/service/phase3-input-filter.js +93 -3
  54. package/dist/service/runtime-summary-service.d.ts +34 -0
  55. package/dist/service/runtime-summary-service.js +93 -1
  56. package/dist/tools/deep-reflect.js +1 -2
  57. package/dist/types/event-types.d.ts +2 -0
  58. package/dist/types/runtime-summary.d.ts +54 -0
  59. package/dist/types/runtime-summary.js +1 -0
  60. package/dist/utils/subagent-probe.d.ts +11 -0
  61. package/dist/utils/subagent-probe.js +46 -1
  62. package/openclaw.plugin.json +1 -1
  63. package/package.json +2 -1
  64. package/templates/langs/en/core/AGENTS.md +1 -1
  65. package/templates/langs/en/core/TOOLS.md +1 -1
  66. package/templates/langs/zh/core/AGENTS.md +1 -1
  67. package/templates/langs/zh/core/TOOLS.md +1 -1
  68. package/{agents/auditor.md → templates/langs/zh/skills/pd-auditor/SKILL.md} +3 -3
  69. package/{agents/diagnostician.md → templates/langs/zh/skills/pd-diagnostician/SKILL.md} +39 -29
  70. package/{agents/explorer.md → templates/langs/zh/skills/pd-explorer/SKILL.md} +3 -3
  71. package/{agents/implementer.md → templates/langs/zh/skills/pd-implementer/SKILL.md} +3 -3
  72. package/{agents/planner.md → templates/langs/zh/skills/pd-planner/SKILL.md} +3 -3
  73. package/{agents/reporter.md → templates/langs/zh/skills/pd-reporter/SKILL.md} +3 -3
  74. package/{agents/reviewer.md → templates/langs/zh/skills/pd-reviewer/SKILL.md} +3 -3
  75. package/dist/core/agent-loader.d.ts +0 -44
  76. package/dist/core/agent-loader.js +0 -147
  77. package/dist/tools/agent-spawn.d.ts +0 -54
  78. package/dist/tools/agent-spawn.js +0 -456
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Diagnostician 协议常量
3
+ *
4
+ * 用于 evolution-worker.ts(后台心跳)和 prompt.ts(实时路径)
5
+ * 与 templates/langs/zh/skills/pd-diagnostician/SKILL.md 保持一致
6
+ */
7
+ /**
8
+ * 诊断协议摘要(用于 HEARTBEAT.md 注入)
9
+ *
10
+ * 完整版见: templates/langs/zh/skills/pd-diagnostician/SKILL.md
11
+ */
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";
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Diagnostician 协议常量
3
+ *
4
+ * 用于 evolution-worker.ts(后台心跳)和 prompt.ts(实时路径)
5
+ * 与 templates/langs/zh/skills/pd-diagnostician/SKILL.md 保持一致
6
+ */
7
+ /**
8
+ * 诊断协议摘要(用于 HEARTBEAT.md 注入)
9
+ *
10
+ * 完整版见: templates/langs/zh/skills/pd-diagnostician/SKILL.md
11
+ */
12
+ export const DIAGNOSTICIAN_PROTOCOL_SUMMARY = `## Diagnostic Protocol (5 Whys)
13
+
14
+ **Phase 1 - Evidence Gathering**:
15
+ - Read logs: .state/logs/events.jsonl, SYSTEM.log
16
+ - Search code for error patterns from Reason field
17
+ - Record evidence sources
18
+
19
+ **Phase 2 - Causal Chain**:
20
+ - Each Why must have evidence support
21
+ - Maximum 5 layers
22
+ - Stop when reaching actionable root cause
23
+
24
+ **Phase 3 - Root Cause Classification**:
25
+ Classify into one of:
26
+ - **People**: Human error, missing knowledge, communication gap
27
+ - **Design**: Architecture flaw, missing validation, poor abstraction
28
+ - **Assumption**: Invalid assumption, outdated context, edge case
29
+ - **Tooling**: Tool limitation, environment issue, dependency problem
30
+
31
+ **Phase 4 - Principle Extraction**:
32
+ Extract protection principle with:
33
+ - **trigger_pattern**: When this situation occurs
34
+ - **action**: What to do differently
35
+
36
+ **Output Format**:
37
+ \`\`\`json
38
+ {
39
+ "diagnosis_report": {
40
+ "task_id": "pain-xxx",
41
+ "summary": "One-line root cause",
42
+ "causal_chain": [
43
+ { "why": 1, "answer": "...", "evidence": "..." }
44
+ ],
45
+ "root_cause": {
46
+ "category": "Design|People|Assumption|Tooling",
47
+ "description": "..."
48
+ },
49
+ "principle": {
50
+ "trigger_pattern": "...",
51
+ "action": "..."
52
+ }
53
+ }
54
+ }
55
+ \`\`\`
56
+ `;
@@ -2,9 +2,9 @@ export declare const READ_ONLY_TOOL_NAMES: readonly ["read", "read_file", "read_
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
- export declare const AGENT_TOOL_NAMES: readonly ["pd_run_worker", "sessions_spawn"];
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
- 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", "pd_run_worker", "sessions_spawn", "evolve-task", "init-strategy"];
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
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", "trust", "report"];
9
9
  export declare const READ_ONLY_TOOLS: Set<string>;
10
10
  export declare const LOW_RISK_WRITE_TOOLS: Set<string>;
@@ -23,7 +23,7 @@ export const HIGH_RISK_TOOL_NAMES = [
23
23
  ...BASH_TOOL_NAMES,
24
24
  ];
25
25
  export const AGENT_TOOL_NAMES = [
26
- 'pd_run_worker', 'sessions_spawn',
26
+ 'sessions_spawn',
27
27
  ];
28
28
  export const CONTENT_LIMITED_TOOL_NAMES = [
29
29
  ...LOW_RISK_WRITE_TOOL_NAMES,
@@ -127,6 +127,18 @@ export interface PainSettings {
127
127
  model_calibration?: Record<string, number>;
128
128
  };
129
129
  gfi_gate?: GfiGateSettings;
130
+ compression?: {
131
+ /** 触发自动压缩的行数阈值 */
132
+ line_threshold?: number;
133
+ /** 触发自动压缩的字节阈值 */
134
+ size_threshold_kb?: number;
135
+ /** 自动压缩间隔(小时) */
136
+ interval_hours?: number;
137
+ /** 保留的已完成任务数 */
138
+ keep_completed_tasks?: number;
139
+ /** Working Memory 最大条数 */
140
+ max_working_memory_artifacts?: number;
141
+ };
130
142
  }
131
143
  export declare const DEFAULT_SETTINGS: PainSettings;
132
144
  export declare class PainConfig {
@@ -146,6 +146,13 @@ export const DEFAULT_SETTINGS = {
146
146
  'docker\\s+push',
147
147
  '(curl|wget).*\\|\\s*(ba)?sh',
148
148
  ],
149
+ },
150
+ compression: {
151
+ line_threshold: 100, // 超过 100 行触发压缩
152
+ size_threshold_kb: 15, // 超过 15KB 触发压缩
153
+ interval_hours: 24, // 每 24 小时最多压缩一次
154
+ keep_completed_tasks: 3, // 保留最近 3 个已完成任务
155
+ max_working_memory_artifacts: 10, // Working Memory 最多 10 条
149
156
  }
150
157
  };
151
158
  export class PainConfig {
@@ -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
  }
@@ -174,7 +174,7 @@ export class EvolutionEngine {
174
174
  };
175
175
  }
176
176
  // 子智能体检查
177
- if ((context.toolName === 'pd_run_worker' || context.toolName === 'sessions_spawn') && !perms.allowSubagentSpawn) {
177
+ if (context.toolName === 'sessions_spawn' && !perms.allowSubagentSpawn) {
178
178
  return {
179
179
  allowed: false,
180
180
  reason: `Tier ${this.scorecard.currentTier} (${tierDef.name}) 未解锁子智能体权限`,
@@ -116,3 +116,95 @@ export declare function mergeWorkingMemory(content: string, snapshot: WorkingMem
116
116
  * 生成工作记忆注入字符串(用于 prompt 注入)
117
117
  */
118
118
  export declare function workingMemoryToInjection(snapshot: WorkingMemorySnapshot | null): string;
119
+ /**
120
+ * 压缩配置接口
121
+ */
122
+ interface CompressionConfig {
123
+ lineThreshold: number;
124
+ sizeThreshold: number;
125
+ intervalMs: number;
126
+ keepCompletedTasks: number;
127
+ maxWorkingMemoryArtifacts: number;
128
+ }
129
+ /**
130
+ * 提取已完成任务作为里程碑
131
+ */
132
+ export declare function extractMilestones(content: string): {
133
+ completedTasks: string[];
134
+ fileArtifacts: string[];
135
+ };
136
+ /**
137
+ * 归档里程碑到 daily memory 文件
138
+ */
139
+ export declare function archiveMilestonesToDaily(workspaceDir: string, milestones: {
140
+ completedTasks: string[];
141
+ fileArtifacts: string[];
142
+ }, version: string): string | null;
143
+ /**
144
+ * 清理过期信息和验证文件引用
145
+ */
146
+ export declare function cleanupStaleInfo(content: string, workspaceDir?: string, config?: CompressionConfig): string;
147
+ /**
148
+ * 自动压缩 CURRENT_FOCUS.md
149
+ *
150
+ * @param focusPath CURRENT_FOCUS.md 的完整路径
151
+ * @param workspaceDir 工作区目录(可选,用于验证文件引用)
152
+ * @param stateDir state 目录路径(可选,用于频率限制)
153
+ * @returns 压缩结果信息,如果不需要压缩则返回 null
154
+ */
155
+ export declare function autoCompressFocus(focusPath: string, workspaceDir?: string, stateDir?: string): {
156
+ compressed: boolean;
157
+ oldLines: number;
158
+ newLines: number;
159
+ milestonesArchived: boolean;
160
+ backupPath: string | null;
161
+ reason: string;
162
+ };
163
+ /**
164
+ * 检查是否需要自动压缩
165
+ */
166
+ export declare function needsAutoCompression(focusPath: string, stateDir?: string): boolean;
167
+ /**
168
+ * 验证 CURRENT_FOCUS.md 格式
169
+ *
170
+ * 仅校验会导致程序崩溃的核心问题,不过度校验
171
+ *
172
+ * @param content 文件内容
173
+ * @returns 验证结果
174
+ */
175
+ export declare function validateCurrentFocus(content: string): {
176
+ valid: boolean;
177
+ errors: string[];
178
+ warnings: string[];
179
+ };
180
+ /**
181
+ * 从模板恢复 CURRENT_FOCUS.md
182
+ *
183
+ * @param focusPath CURRENT_FOCUS.md 路径
184
+ * @param extensionRoot 插件根目录
185
+ * @returns 恢复是否成功
186
+ */
187
+ export declare function recoverFromTemplate(focusPath: string, extensionRoot: string): {
188
+ success: boolean;
189
+ error?: string;
190
+ templatePath?: string;
191
+ };
192
+ /**
193
+ * 安全读取 CURRENT_FOCUS.md(自动验证 + 恢复)
194
+ *
195
+ * 仅在文件为空或损坏时才恢复,其他情况正常使用
196
+ *
197
+ * @param focusPath CURRENT_FOCUS.md 路径
198
+ * @param extensionRoot 插件根目录
199
+ * @param logger 日志记录器
200
+ * @returns 文件内容和恢复状态
201
+ */
202
+ export declare function safeReadCurrentFocus(focusPath: string, extensionRoot: string, logger?: {
203
+ warn?: (msg: string) => void;
204
+ info?: (msg: string) => void;
205
+ }): {
206
+ content: string;
207
+ recovered: boolean;
208
+ validationErrors: string[];
209
+ };
210
+ export {};