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.
Files changed (129) hide show
  1. package/dist/commands/context.js +5 -15
  2. package/dist/commands/evolution-status.js +29 -48
  3. package/dist/commands/export.js +61 -8
  4. package/dist/commands/nocturnal-review.d.ts +24 -0
  5. package/dist/commands/nocturnal-review.js +265 -0
  6. package/dist/commands/nocturnal-rollout.d.ts +27 -0
  7. package/dist/commands/nocturnal-rollout.js +671 -0
  8. package/dist/commands/nocturnal-train.d.ts +25 -0
  9. package/dist/commands/nocturnal-train.js +919 -0
  10. package/dist/commands/pain.js +8 -21
  11. package/dist/config/defaults/runtime.d.ts +40 -0
  12. package/dist/config/defaults/runtime.js +44 -0
  13. package/dist/config/errors.d.ts +84 -0
  14. package/dist/config/errors.js +94 -0
  15. package/dist/config/index.d.ts +7 -0
  16. package/dist/config/index.js +7 -0
  17. package/dist/constants/diagnostician.d.ts +0 -4
  18. package/dist/constants/diagnostician.js +0 -4
  19. package/dist/constants/tools.d.ts +2 -2
  20. package/dist/constants/tools.js +1 -1
  21. package/dist/core/adaptive-thresholds.d.ts +186 -0
  22. package/dist/core/adaptive-thresholds.js +300 -0
  23. package/dist/core/config.d.ts +2 -38
  24. package/dist/core/config.js +6 -61
  25. package/dist/core/control-ui-db.d.ts +27 -0
  26. package/dist/core/control-ui-db.js +18 -0
  27. package/dist/core/event-log.d.ts +1 -2
  28. package/dist/core/event-log.js +0 -3
  29. package/dist/core/evolution-engine.js +1 -21
  30. package/dist/core/evolution-reducer.d.ts +7 -1
  31. package/dist/core/evolution-reducer.js +56 -4
  32. package/dist/core/evolution-types.d.ts +61 -9
  33. package/dist/core/evolution-types.js +31 -9
  34. package/dist/core/external-training-contract.d.ts +276 -0
  35. package/dist/core/external-training-contract.js +269 -0
  36. package/dist/core/local-worker-routing.d.ts +175 -0
  37. package/dist/core/local-worker-routing.js +525 -0
  38. package/dist/core/model-deployment-registry.d.ts +218 -0
  39. package/dist/core/model-deployment-registry.js +503 -0
  40. package/dist/core/model-training-registry.d.ts +295 -0
  41. package/dist/core/model-training-registry.js +475 -0
  42. package/dist/core/nocturnal-arbiter.d.ts +159 -0
  43. package/dist/core/nocturnal-arbiter.js +534 -0
  44. package/dist/core/nocturnal-candidate-scoring.d.ts +137 -0
  45. package/dist/core/nocturnal-candidate-scoring.js +266 -0
  46. package/dist/core/nocturnal-compliance.d.ts +175 -0
  47. package/dist/core/nocturnal-compliance.js +824 -0
  48. package/dist/core/nocturnal-dataset.d.ts +224 -0
  49. package/dist/core/nocturnal-dataset.js +443 -0
  50. package/dist/core/nocturnal-executability.d.ts +85 -0
  51. package/dist/core/nocturnal-executability.js +331 -0
  52. package/dist/core/nocturnal-export.d.ts +124 -0
  53. package/dist/core/nocturnal-export.js +275 -0
  54. package/dist/core/nocturnal-paths.d.ts +124 -0
  55. package/dist/core/nocturnal-paths.js +214 -0
  56. package/dist/core/nocturnal-trajectory-extractor.d.ts +242 -0
  57. package/dist/core/nocturnal-trajectory-extractor.js +307 -0
  58. package/dist/core/nocturnal-trinity.d.ts +311 -0
  59. package/dist/core/nocturnal-trinity.js +880 -0
  60. package/dist/core/path-resolver.js +2 -1
  61. package/dist/core/paths.d.ts +6 -0
  62. package/dist/core/paths.js +6 -0
  63. package/dist/core/principle-training-state.d.ts +121 -0
  64. package/dist/core/principle-training-state.js +321 -0
  65. package/dist/core/promotion-gate.d.ts +238 -0
  66. package/dist/core/promotion-gate.js +529 -0
  67. package/dist/core/session-tracker.d.ts +10 -0
  68. package/dist/core/session-tracker.js +14 -0
  69. package/dist/core/shadow-observation-registry.d.ts +217 -0
  70. package/dist/core/shadow-observation-registry.js +308 -0
  71. package/dist/core/training-program.d.ts +233 -0
  72. package/dist/core/training-program.js +433 -0
  73. package/dist/core/trajectory.d.ts +155 -1
  74. package/dist/core/trajectory.js +292 -8
  75. package/dist/core/workspace-context.d.ts +0 -6
  76. package/dist/core/workspace-context.js +0 -12
  77. package/dist/hooks/bash-risk.d.ts +57 -0
  78. package/dist/hooks/bash-risk.js +137 -0
  79. package/dist/hooks/edit-verification.d.ts +62 -0
  80. package/dist/hooks/edit-verification.js +256 -0
  81. package/dist/hooks/gate-block-helper.d.ts +44 -0
  82. package/dist/hooks/gate-block-helper.js +119 -0
  83. package/dist/hooks/gate.d.ts +18 -0
  84. package/dist/hooks/gate.js +62 -751
  85. package/dist/hooks/gfi-gate.d.ts +40 -0
  86. package/dist/hooks/gfi-gate.js +113 -0
  87. package/dist/hooks/pain.js +6 -9
  88. package/dist/hooks/progressive-trust-gate.d.ts +51 -0
  89. package/dist/hooks/progressive-trust-gate.js +89 -0
  90. package/dist/hooks/prompt.d.ts +11 -11
  91. package/dist/hooks/prompt.js +167 -77
  92. package/dist/hooks/subagent.js +43 -6
  93. package/dist/hooks/thinking-checkpoint.d.ts +37 -0
  94. package/dist/hooks/thinking-checkpoint.js +51 -0
  95. package/dist/http/principles-console-route.js +13 -3
  96. package/dist/i18n/commands.js +8 -8
  97. package/dist/index.js +129 -28
  98. package/dist/service/central-database.js +2 -1
  99. package/dist/service/control-ui-query-service.d.ts +1 -1
  100. package/dist/service/control-ui-query-service.js +3 -3
  101. package/dist/service/evolution-query-service.d.ts +1 -1
  102. package/dist/service/evolution-query-service.js +5 -5
  103. package/dist/service/evolution-worker.d.ts +52 -4
  104. package/dist/service/evolution-worker.js +328 -16
  105. package/dist/service/nocturnal-runtime.d.ts +183 -0
  106. package/dist/service/nocturnal-runtime.js +352 -0
  107. package/dist/service/nocturnal-service.d.ts +163 -0
  108. package/dist/service/nocturnal-service.js +787 -0
  109. package/dist/service/nocturnal-target-selector.d.ts +145 -0
  110. package/dist/service/nocturnal-target-selector.js +315 -0
  111. package/dist/service/phase3-input-filter.d.ts +48 -12
  112. package/dist/service/phase3-input-filter.js +84 -18
  113. package/dist/service/runtime-summary-service.d.ts +34 -10
  114. package/dist/service/runtime-summary-service.js +87 -48
  115. package/dist/tools/deep-reflect.js +2 -1
  116. package/dist/types/event-types.d.ts +4 -10
  117. package/dist/types/runtime-summary.d.ts +47 -0
  118. package/dist/types/runtime-summary.js +1 -0
  119. package/dist/types.d.ts +0 -3
  120. package/dist/types.js +0 -2
  121. package/openclaw.plugin.json +1 -1
  122. package/package.json +1 -1
  123. package/templates/langs/en/skills/pd-mentor/SKILL.md +5 -5
  124. package/templates/langs/zh/skills/pd-mentor/SKILL.md +5 -5
  125. package/templates/pain_settings.json +0 -6
  126. package/dist/commands/trust.d.ts +0 -4
  127. package/dist/commands/trust.js +0 -78
  128. package/dist/core/trust-engine.d.ts +0 -96
  129. package/dist/core/trust-engine.js +0 -286
@@ -0,0 +1,40 @@
1
+ /**
2
+ * GFI Gate Module
3
+ *
4
+ * Handles Fatigue Index (GFI) based tool blocking with TIER 0-3 classification.
5
+ *
6
+ * **Responsibilities:**
7
+ * - Calculate dynamic GFI thresholds based on EP tier and line changes
8
+ * - Apply tier-based tool blocking:
9
+ * - TIER 0: Read-only tools (never blocked)
10
+ * - TIER 1: Low-risk writes (blocked when GFI >= low_risk_block threshold)
11
+ * - TIER 2: High-risk operations (blocked when GFI >= high_risk_block threshold)
12
+ * - TIER 3: Bash commands (content-dependent blocking)
13
+ * - Prevent subagent spawn at critically high GFI (>=90)
14
+ *
15
+ * **Configuration:**
16
+ * - GFI thresholds from config.gfi_gate
17
+ * - EP tier multipliers for dynamic threshold calculation
18
+ * - Large change adjustments
19
+ *
20
+ * **Block Persistence:**
21
+ * - Uses shared `recordGateBlockAndReturn` from gate-block-helper.ts
22
+ * - Ensures single authoritative block persistence path
23
+ */
24
+ import type { WorkspaceContext } from '../core/workspace-context.js';
25
+ import type { PluginHookBeforeToolCallEvent, PluginHookBeforeToolCallResult } from '../openclaw-sdk.js';
26
+ export interface GfiGateConfig {
27
+ enabled?: boolean;
28
+ thresholds?: {
29
+ low_risk_block?: number;
30
+ high_risk_block?: number;
31
+ };
32
+ large_change_lines?: number;
33
+ ep_tier_multipliers?: Record<string, number>;
34
+ bash_safe_patterns?: string[];
35
+ bash_dangerous_patterns?: string[];
36
+ }
37
+ export declare function checkGfiGate(event: PluginHookBeforeToolCallEvent, wctx: WorkspaceContext, sessionId: string | undefined, config: GfiGateConfig, logger?: {
38
+ info?: (message: string) => void;
39
+ warn?: (message: string) => void;
40
+ }): PluginHookBeforeToolCallResult | undefined;
@@ -0,0 +1,113 @@
1
+ /**
2
+ * GFI Gate Module
3
+ *
4
+ * Handles Fatigue Index (GFI) based tool blocking with TIER 0-3 classification.
5
+ *
6
+ * **Responsibilities:**
7
+ * - Calculate dynamic GFI thresholds based on EP tier and line changes
8
+ * - Apply tier-based tool blocking:
9
+ * - TIER 0: Read-only tools (never blocked)
10
+ * - TIER 1: Low-risk writes (blocked when GFI >= low_risk_block threshold)
11
+ * - TIER 2: High-risk operations (blocked when GFI >= high_risk_block threshold)
12
+ * - TIER 3: Bash commands (content-dependent blocking)
13
+ * - Prevent subagent spawn at critically high GFI (>=90)
14
+ *
15
+ * **Configuration:**
16
+ * - GFI thresholds from config.gfi_gate
17
+ * - EP tier multipliers for dynamic threshold calculation
18
+ * - Large change adjustments
19
+ *
20
+ * **Block Persistence:**
21
+ * - Uses shared `recordGateBlockAndReturn` from gate-block-helper.ts
22
+ * - Ensures single authoritative block persistence path
23
+ */
24
+ import { getSession } from '../core/session-tracker.js';
25
+ import { estimateLineChanges } from '../core/risk-calculator.js';
26
+ import { analyzeBashCommand, calculateDynamicThreshold } from './bash-risk.js';
27
+ import { BASH_TOOLS_SET, HIGH_RISK_TOOLS, LOW_RISK_WRITE_TOOLS, AGENT_TOOLS } from '../constants/tools.js';
28
+ import { AGENT_SPAWN_GFI_THRESHOLD } from '../config/index.js';
29
+ import { recordGateBlockAndReturn } from './gate-block-helper.js';
30
+ import { getEvolutionEngine } from '../core/evolution-engine.js';
31
+ /**
32
+ * Internal helper to call the shared block helper with gfi-gate source tag.
33
+ */
34
+ function block(wctx, filePath, reason, toolName, sessionId, logger) {
35
+ return recordGateBlockAndReturn(wctx, {
36
+ filePath,
37
+ reason,
38
+ toolName,
39
+ sessionId,
40
+ blockSource: 'gfi-gate',
41
+ }, logger || { warn: () => { }, error: () => { } });
42
+ }
43
+ export function checkGfiGate(event, wctx, sessionId, config, logger) {
44
+ if (!config || config.enabled === false || !sessionId) {
45
+ return undefined;
46
+ }
47
+ const session = getSession(sessionId);
48
+ const currentGfi = session?.currentGfi || 0;
49
+ const getEpTier = () => {
50
+ return getEvolutionEngine(wctx.workspaceDir).getTier();
51
+ };
52
+ // TIER 3: Bash commands
53
+ if (BASH_TOOLS_SET.has(event.toolName)) {
54
+ const command = String(event.params.command || event.params.args || '');
55
+ const bashRisk = analyzeBashCommand(command, config.bash_safe_patterns || [], config.bash_dangerous_patterns || [], logger);
56
+ if (bashRisk === 'dangerous') {
57
+ logger?.warn?.(`[PD:GFI_GATE] Dangerous bash command blocked: ${command.substring(0, 50)}...`);
58
+ return block(wctx, command.substring(0, 100), `危险命令被拦截。检测到危险命令模式,需要确认执行意图。`, event.toolName, sessionId, logger);
59
+ }
60
+ if (bashRisk === 'safe') {
61
+ return undefined;
62
+ }
63
+ // normal bash - check GFI threshold
64
+ const tier = getEpTier();
65
+ const baseThreshold = config.thresholds?.low_risk_block || 70;
66
+ const dynamicThreshold = calculateDynamicThreshold(baseThreshold, tier, 0, {
67
+ large_change_lines: config.large_change_lines || 50,
68
+ ep_tier_multipliers: config.ep_tier_multipliers || { '1': 0.5, '2': 0.75, '3': 1.0, '4': 1.5, '5': 2.0 },
69
+ });
70
+ if (currentGfi >= dynamicThreshold) {
71
+ logger?.warn?.(`[PD:GFI_GATE] Bash blocked by GFI: ${currentGfi} >= ${dynamicThreshold}`);
72
+ return block(wctx, command.substring(0, 100), `疲劳指数过高 (GFI: ${currentGfi}/${dynamicThreshold})。系统进入保护模式。`, event.toolName, sessionId, logger);
73
+ }
74
+ return undefined;
75
+ }
76
+ // TIER 2: High-risk tools
77
+ if (HIGH_RISK_TOOLS.has(event.toolName)) {
78
+ const tier = getEpTier();
79
+ const baseThreshold = config.thresholds?.high_risk_block || 40;
80
+ const dynamicThreshold = calculateDynamicThreshold(baseThreshold, tier, 0, {
81
+ large_change_lines: config.large_change_lines || 50,
82
+ ep_tier_multipliers: config.ep_tier_multipliers || { '1': 0.5, '2': 0.75, '3': 1.0, '4': 1.5, '5': 2.0 },
83
+ });
84
+ if (currentGfi >= dynamicThreshold) {
85
+ const filePath = event.params.file_path || event.params.path || event.params.file || event.params.target || 'unknown';
86
+ logger?.warn?.(`[PD:GFI_GATE] High-risk tool "${event.toolName}" blocked by GFI: ${currentGfi} >= ${dynamicThreshold}`);
87
+ return block(wctx, filePath, `高风险操作被拦截。GFI: ${currentGfi}/${dynamicThreshold}。高风险工具需要更低的阈值。`, event.toolName, sessionId, logger);
88
+ }
89
+ }
90
+ // TIER 1: Low-risk write tools
91
+ if (LOW_RISK_WRITE_TOOLS.has(event.toolName)) {
92
+ const tier = getEpTier();
93
+ const lineChanges = estimateLineChanges({ toolName: event.toolName, params: event.params });
94
+ const baseThreshold = config.thresholds?.low_risk_block || 70;
95
+ const dynamicThreshold = calculateDynamicThreshold(baseThreshold, tier, lineChanges, {
96
+ large_change_lines: config.large_change_lines || 50,
97
+ ep_tier_multipliers: config.ep_tier_multipliers || { '1': 0.5, '2': 0.75, '3': 1.0, '4': 1.5, '5': 2.0 },
98
+ });
99
+ if (currentGfi >= dynamicThreshold) {
100
+ const filePath = event.params.file_path || event.params.path || event.params.file || event.params.target || 'unknown';
101
+ logger?.warn?.(`[PD:GFI_GATE] Low-risk tool "${event.toolName}" blocked by GFI: ${currentGfi} >= ${dynamicThreshold}`);
102
+ return block(wctx, filePath, `疲劳指数过高 (GFI: ${currentGfi}/${dynamicThreshold})。系统进入保护模式。`, event.toolName, sessionId, logger);
103
+ }
104
+ }
105
+ // AGENT_TOOLS: Block subagent spawn when GFI is critically high
106
+ if (AGENT_TOOLS.has(event.toolName)) {
107
+ if (currentGfi >= AGENT_SPAWN_GFI_THRESHOLD) {
108
+ logger?.warn?.(`[PD:GFI_GATE] Agent tool "${event.toolName}" blocked by GFI: ${currentGfi} >= ${AGENT_SPAWN_GFI_THRESHOLD}`);
109
+ return block(wctx, 'subagent-spawn', `疲劳指数过高,禁止派生子智能体。GFI: ${currentGfi}/${AGENT_SPAWN_GFI_THRESHOLD}`, event.toolName, sessionId, logger);
110
+ }
111
+ }
112
+ return undefined;
113
+ }
@@ -7,6 +7,7 @@ import { denoiseError, computeHash } from '../utils/hashing.js';
7
7
  import { SystemLogger } from '../core/system-logger.js';
8
8
  import { WorkspaceContext } from '../core/workspace-context.js';
9
9
  import { getEvolutionLogger, createTraceId } from '../core/evolution-logger.js';
10
+ import { recordEvolutionSuccess, recordEvolutionFailure } from '../core/evolution-engine.js';
10
11
  const WRITE_TOOLS = ['write', 'edit', 'apply_patch', 'write_file', 'edit_file', 'replace'];
11
12
  function shouldAttributePrincipleToTool(principle, toolName) {
12
13
  return principle.contextTags.includes(toolName) || principle.trigger.includes(toolName);
@@ -30,7 +31,6 @@ export function handleAfterToolCall(event, ctx, api) {
30
31
  const wctx = WorkspaceContext.fromHookContext({ ...ctx, workspaceDir: effectiveWorkspaceDir });
31
32
  const config = wctx.config;
32
33
  const eventLog = wctx.eventLog;
33
- const trust = wctx.trust;
34
34
  const sessionId = ctx.sessionId || 'unknown';
35
35
  const sessionState = ctx.sessionId ? getSession(ctx.sessionId) : undefined;
36
36
  const gfiBefore = sessionState?.currentGfi ?? 0;
@@ -106,11 +106,10 @@ export function handleAfterToolCall(event, ctx, api) {
106
106
  }
107
107
  }
108
108
  const isRisk = isRisky(relPath, profile.risk_paths);
109
- trust.recordFailure(isRisk ? 'risky' : 'tool', {
109
+ recordEvolutionFailure(effectiveWorkspaceDir, event.toolName, {
110
+ filePath: relPath,
111
+ reason: isRisk ? 'risky' : 'tool',
110
112
  sessionId,
111
- api,
112
- toolName: event.toolName,
113
- error: event.error // Pass error for timeout detection
114
113
  });
115
114
  // Record tool call failure event
116
115
  eventLog.recordToolCall(sessionId, {
@@ -147,11 +146,9 @@ export function handleAfterToolCall(event, ctx, api) {
147
146
  else {
148
147
  // ── SUCCESS BRANCH ──
149
148
  const resetState = resetFriction(sessionId, effectiveWorkspaceDir);
150
- // 👈 Record success to reset failure streak and earn minor trust (if constructive)
151
- trust.recordSuccess('tool_success', {
149
+ recordEvolutionSuccess(effectiveWorkspaceDir, event.toolName, {
152
150
  sessionId,
153
- api,
154
- toolName: event.toolName // 👈 NEW: Pass toolName for classification
151
+ reason: 'tool_success',
155
152
  });
156
153
  const injectedProbationIds = getInjectedProbationIds(sessionId, effectiveWorkspaceDir);
157
154
  for (const id of injectedProbationIds) {
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Progressive Gate Module (EP-Only Version)
3
+ *
4
+ * EP (Evolution Points) 是唯一的门控机制。
5
+ *
6
+ * **EP 门控逻辑:**
7
+ * - Seed (0分): 只读 + 基础文档
8
+ * - Sprout (50分): 单文件编辑
9
+ * - Sapling (200分): 多文件 + 测试 + 子智能体
10
+ * - Tree (500分): 重构 + 风险路径
11
+ * - Forest (1000分): 完全自主
12
+ *
13
+ * **风险路径控制:**
14
+ * - 低等级不能修改风险路径
15
+ * - 高等级解锁风险路径权限
16
+ *
17
+ * **不再有:**
18
+ * - Trust Score (30-100) 系统
19
+ * - Stage 1-4 分级
20
+ * - Plan Approval 白名单机制
21
+ * - 基于行数的限制
22
+ */
23
+ import type { PluginHookBeforeToolCallEvent, PluginHookBeforeToolCallResult } from '../openclaw-sdk.js';
24
+ import type { WorkspaceContext } from '../core/workspace-context.js';
25
+ /**
26
+ * Build EP gate rejection reason
27
+ */
28
+ export declare function buildEvolutionGateReason(tier: number, tierName: string, reason: string): string;
29
+ /**
30
+ * Check EP-based gate
31
+ *
32
+ * @param event - The tool call event
33
+ * @param wctx - Workspace context
34
+ * @param relPath - Relative path to target file
35
+ * @param risky - Whether the path is a risk path
36
+ * @param lineChanges - Estimated line changes (kept for interface compatibility, not used for gating)
37
+ * @param logger - Logger instance
38
+ * @param ctx - Hook context
39
+ * @param profile - Gate profile containing risk_paths config
40
+ * @returns PluginHookBeforeToolCallResult to block, or undefined to allow
41
+ */
42
+ export declare function checkProgressiveTrustGate(event: PluginHookBeforeToolCallEvent, wctx: WorkspaceContext, relPath: string, risky: boolean, lineChanges: number, logger: {
43
+ warn?: (message: string) => void;
44
+ error?: (message: string) => void;
45
+ info?: (message: string) => void;
46
+ }, ctx: {
47
+ workspaceDir?: string;
48
+ sessionId?: string;
49
+ }, profile?: {
50
+ risk_paths: string[];
51
+ }): PluginHookBeforeToolCallResult | void;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Progressive Gate Module (EP-Only Version)
3
+ *
4
+ * EP (Evolution Points) 是唯一的门控机制。
5
+ *
6
+ * **EP 门控逻辑:**
7
+ * - Seed (0分): 只读 + 基础文档
8
+ * - Sprout (50分): 单文件编辑
9
+ * - Sapling (200分): 多文件 + 测试 + 子智能体
10
+ * - Tree (500分): 重构 + 风险路径
11
+ * - Forest (1000分): 完全自主
12
+ *
13
+ * **风险路径控制:**
14
+ * - 低等级不能修改风险路径
15
+ * - 高等级解锁风险路径权限
16
+ *
17
+ * **不再有:**
18
+ * - Trust Score (30-100) 系统
19
+ * - Stage 1-4 分级
20
+ * - Plan Approval 白名单机制
21
+ * - 基于行数的限制
22
+ */
23
+ import { checkEvolutionGate } from '../core/evolution-engine.js';
24
+ import { recordGateBlockAndReturn } from './gate-block-helper.js';
25
+ /**
26
+ * Build EP gate rejection reason
27
+ */
28
+ export function buildEvolutionGateReason(tier, tierName, reason) {
29
+ return `[EP Gate] Tier ${tier} (${tierName}): ${reason}`;
30
+ }
31
+ /**
32
+ * Internal helper to call the shared block helper with progressive-trust-gate source tag.
33
+ */
34
+ function block(filePath, reason, wctx, toolName, logger, sessionId) {
35
+ return recordGateBlockAndReturn(wctx, {
36
+ filePath,
37
+ reason,
38
+ toolName,
39
+ sessionId,
40
+ blockSource: 'progressive-trust-gate',
41
+ }, logger);
42
+ }
43
+ /**
44
+ * Check EP-based gate
45
+ *
46
+ * @param event - The tool call event
47
+ * @param wctx - Workspace context
48
+ * @param relPath - Relative path to target file
49
+ * @param risky - Whether the path is a risk path
50
+ * @param lineChanges - Estimated line changes (kept for interface compatibility, not used for gating)
51
+ * @param logger - Logger instance
52
+ * @param ctx - Hook context
53
+ * @param profile - Gate profile containing risk_paths config
54
+ * @returns PluginHookBeforeToolCallResult to block, or undefined to allow
55
+ */
56
+ export function checkProgressiveTrustGate(event, wctx, relPath, risky, lineChanges, logger, ctx, profile) {
57
+ // EP is the only gate now - use actual gate decision
58
+ if (!ctx.workspaceDir) {
59
+ logger.warn?.('[PD_GATE] No workspaceDir, skipping EP gate check');
60
+ return;
61
+ }
62
+ // Call EP gate - this is the actual gate, not simulation
63
+ const epDecision = checkEvolutionGate(ctx.workspaceDir, {
64
+ toolName: event.toolName,
65
+ isRiskPath: risky,
66
+ });
67
+ const currentTier = epDecision.currentTier ?? 1;
68
+ const tierName = getTierName(currentTier);
69
+ logger.info?.(`[PD_GATE] EP Gate: Tier ${currentTier} (${tierName}), Tool: ${event.toolName}, Risk: ${risky}, Allowed: ${epDecision.allowed}`);
70
+ if (!epDecision.allowed) {
71
+ const reason = buildEvolutionGateReason(currentTier, tierName, epDecision.reason ?? 'Unknown restriction');
72
+ return block(relPath, reason, wctx, event.toolName, logger, ctx.sessionId);
73
+ }
74
+ // Gate passed - allow
75
+ return;
76
+ }
77
+ /**
78
+ * Get tier name from tier number
79
+ */
80
+ function getTierName(tier) {
81
+ const names = {
82
+ 1: 'Seed',
83
+ 2: 'Sprout',
84
+ 3: 'Sapling',
85
+ 4: 'Tree',
86
+ 5: 'Forest',
87
+ };
88
+ return names[tier] ?? 'Unknown';
89
+ }
@@ -2,7 +2,7 @@ import type { PluginHookBeforePromptBuildEvent, PluginHookAgentContext, PluginHo
2
2
  import { ContextInjectionConfig } from '../types.js';
3
3
  import { type EmpathyObserverApi } from '../service/empathy-observer-manager.js';
4
4
  /**
5
- * 濞寸媴绲块幃濠冾渶濡鍚囬梺鏉跨Ф閻?
5
+ * Default model configuration for OpenClaw agents
6
6
  */
7
7
  interface AgentsDefaultsConfig {
8
8
  model?: unknown;
@@ -23,22 +23,22 @@ interface PromptHookApi {
23
23
  logger: PluginLogger;
24
24
  }
25
25
  /**
26
- * 濞?OpenClaw 闂佹澘绉堕悿鍡樼▔椤撯寬鎺楀几閹邦劷渚€宕圭€n喒鍋撴径瀣仴
27
- * 闁衡偓椤栨稑鐦?string 闁?{ primary, fallbacks } 闁哄秶鍘х槐?
28
- * @internal 閻庣數鍘ч崵顓熺閸涱剛杩旀繛鏉戭儓閻︻垱鎷呯捄銊︽殢
26
+ * Resolves model configuration for OpenClaw agents, supporting string and object formats
27
+ * @param modelConfig - Model config: string (e.g. "provider/model") or { primary, fallbacks } object
28
+ * @internal Helper for model configuration resolution
29
29
  */
30
30
  export declare function resolveModelFromConfig(modelConfig: unknown, logger?: PluginLogger): string | null;
31
31
  /**
32
- * 闁告梻濮惧ù鍥ㄧ▔婵犱胶鐟撻柡鍌氭处閺佺偤宕楅妷鈺佸赋缂?
33
- * 濞?PROFILE.json 閻犲洩顕цぐ?contextInjection 闂佹澘绉堕悿鍡涙晬鐏炵瓔娲ら柡瀣矆缁楀鈧稒锚濠€顏堝礆濞嗘帞绠查柛銉у仱缁垳鎷嬮妶澶婂赋缂?
34
- * @internal 閻庣數鍘ч崵顓熺瑹濞戞ê寰撳ù鐘崇墬鑶╅柛褎銇炴繛鍥偨?
32
+ * Loads context injection config from .principles/PROFILE.json
33
+ * Parses contextInjection configuration from PROFILE.json for context injection
34
+ * @internal Used by evolution engine for context settings
35
35
  */
36
36
  export declare function loadContextInjectionConfig(workspaceDir: string): ContextInjectionConfig;
37
37
  /**
38
- * 闁兼儳鍢茶ぐ鍥╂嫚婵犲啯鐒介悗娑欏姈濞呫倝鎳楅幋鎺旂Ъ閹煎瓨鏌ф繛鍥偨閵娧勭暠婵☆垪鈧磭鈧?
39
- * 濞村吋锚閸樻稓鐥缁辩殜ubagents.model > 濞戞挾绮啯闁?
40
- * 濠碘€冲€归悘澶愭焾閼恒儳姊鹃柡鍫濐樀閸樸倗绱旈鍡欑闁硅埖绋戦崵顓㈡煥濞嗘帩鍤?
41
- * @internal 閻庣數鍘ч崵顓熺閸涱剛杩旀繛鏉戭儓閻︻垱鎷呯捄銊︽殢
38
+ * Gets the diagnostician model - the model used for AI self-diagnosis and reflection
39
+ * Priority: subagents.model > subagents.model > env.OPENCLAW_MODEL
40
+ * Falls back to main model if no diagnostician model is configured
41
+ * @internal Helper for model configuration resolution
42
42
  */
43
43
  export declare function getDiagnosticianModel(api: PromptHookApi | null, logger?: PluginLogger): string;
44
44
  export declare function handleBeforePromptBuild(event: PluginHookBeforePromptBuildEvent, ctx: PluginHookAgentContext & {