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,44 @@
1
+ /**
2
+ * Gate Block Helper - Single Authoritative Block Persistence
3
+ *
4
+ * PURPOSE: Provide ONE authoritative implementation for gate block persistence.
5
+ *
6
+ * All gate modules (progressive-trust-gate, gfi-gate, etc.) must use this
7
+ * helper to ensure consistent block tracking, event logging, and retry behavior.
8
+ *
9
+ * This eliminates the "multi-truth source" problem where different modules
10
+ * had their own block persistence implementations.
11
+ */
12
+ import type { WorkspaceContext } from '../core/workspace-context.js';
13
+ import type { PluginHookBeforeToolCallResult } from '../openclaw-sdk.js';
14
+ /**
15
+ * Block context containing all information needed for block persistence
16
+ */
17
+ export interface BlockContext {
18
+ filePath: string;
19
+ reason: string;
20
+ toolName: string;
21
+ sessionId?: string;
22
+ /** Source module that triggered the block (for audit trail) */
23
+ blockSource?: string;
24
+ }
25
+ /**
26
+ * Single authoritative block helper.
27
+ *
28
+ * Responsibilities:
29
+ * 1. Call trackBlock() for session-level GFI tracking
30
+ * 2. Record to EventLog for operator visibility
31
+ * 3. Record to trajectory for analytics
32
+ * 4. Handle retry logic for trajectory persistence failures
33
+ * 5. Generate consistent operator-facing block message
34
+ *
35
+ * @param wctx - Workspace context
36
+ * @param blockCtx - Block context with file, reason, tool info
37
+ * @param logger - Logger instance
38
+ * @returns PluginHookBeforeToolCallResult with block=true
39
+ */
40
+ export declare function recordGateBlockAndReturn(wctx: WorkspaceContext, blockCtx: BlockContext, logger: {
41
+ warn?: (message: string) => void;
42
+ error?: (message: string) => void;
43
+ info?: (message: string) => void;
44
+ }): PluginHookBeforeToolCallResult;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Gate Block Helper - Single Authoritative Block Persistence
3
+ *
4
+ * PURPOSE: Provide ONE authoritative implementation for gate block persistence.
5
+ *
6
+ * All gate modules (progressive-trust-gate, gfi-gate, etc.) must use this
7
+ * helper to ensure consistent block tracking, event logging, and retry behavior.
8
+ *
9
+ * This eliminates the "multi-truth source" problem where different modules
10
+ * had their own block persistence implementations.
11
+ */
12
+ import { trackBlock } from '../core/session-tracker.js';
13
+ import { TRAJECTORY_GATE_BLOCK_RETRY_DELAY_MS, TRAJECTORY_GATE_BLOCK_MAX_RETRIES } from '../config/index.js';
14
+ /**
15
+ * Single authoritative block helper.
16
+ *
17
+ * Responsibilities:
18
+ * 1. Call trackBlock() for session-level GFI tracking
19
+ * 2. Record to EventLog for operator visibility
20
+ * 3. Record to trajectory for analytics
21
+ * 4. Handle retry logic for trajectory persistence failures
22
+ * 5. Generate consistent operator-facing block message
23
+ *
24
+ * @param wctx - Workspace context
25
+ * @param blockCtx - Block context with file, reason, tool info
26
+ * @param logger - Logger instance
27
+ * @returns PluginHookBeforeToolCallResult with block=true
28
+ */
29
+ export function recordGateBlockAndReturn(wctx, blockCtx, logger) {
30
+ const { filePath, reason, toolName, sessionId, blockSource } = blockCtx;
31
+ // Default logger if not provided
32
+ const logWarn = logger.warn?.bind(logger) ?? ((msg) => console.warn(msg));
33
+ const logError = logger.error?.bind(logger) ?? ((msg) => console.error(msg));
34
+ // Log the block event
35
+ const sourceTag = blockSource ? `[${blockSource}]` : '';
36
+ logError(`[PD_GATE]${sourceTag} BLOCKED: ${filePath}. Reason: ${reason}`);
37
+ // 1. Track block for session-level GFI calculation
38
+ if (sessionId) {
39
+ trackBlock(sessionId);
40
+ }
41
+ // 2. Prepare trajectory payload
42
+ const trajectoryPayload = {
43
+ sessionId: sessionId ?? null,
44
+ toolName,
45
+ filePath,
46
+ reason,
47
+ blockSource: blockSource ?? 'gate',
48
+ };
49
+ // 3. Record to EventLog (primary persistence)
50
+ try {
51
+ wctx.eventLog.recordGateBlock(sessionId, {
52
+ toolName,
53
+ filePath,
54
+ reason,
55
+ blockSource: blockSource ?? 'gate',
56
+ });
57
+ }
58
+ catch (error) {
59
+ logWarn(`[PD_GATE] Failed to record gate block event: ${String(error)}`);
60
+ }
61
+ // 4. Record to trajectory (secondary persistence with retry)
62
+ try {
63
+ wctx.trajectory?.recordGateBlock?.(trajectoryPayload);
64
+ }
65
+ catch (error) {
66
+ logWarn(`[PD_GATE] Failed to record trajectory gate block: ${String(error)}`);
67
+ scheduleTrajectoryGateBlockRetry(wctx, trajectoryPayload, 1, logWarn, logError);
68
+ }
69
+ // 5. Return consistent block result with operator guidance
70
+ return {
71
+ block: true,
72
+ blockReason: `[Principles Disciple] Security Gate Blocked this action.
73
+ File: ${filePath}
74
+ Reason: ${reason}
75
+
76
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
77
+ 📋 How to unblock this operation:
78
+
79
+ 1. Use the plan-script skill to create a PLAN.md:
80
+ → Invoke: skill:plan-script
81
+
82
+ 2. Fill in the plan with:
83
+ - Target Files: ${filePath}
84
+ - Steps: What you want to do (be specific)
85
+ - Metrics: How to verify success
86
+ - Active Mental Models: Select 2 relevant models from .principles/THINKING_OS.md
87
+ - Rollback: How to restore if it fails
88
+
89
+ 3. After completing the plan, set STATUS: READY in PLAN.md
90
+
91
+ 4. Retry the operation
92
+
93
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
94
+ This is a mandatory security gate. The operation was blocked because the modification exceeds the allowed threshold for your current trust stage.
95
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`,
96
+ };
97
+ }
98
+ /**
99
+ * Schedule retry for trajectory gate block persistence.
100
+ *
101
+ * Uses exponential backoff with max retries.
102
+ * Failures are logged but do not affect the runtime block decision.
103
+ */
104
+ function scheduleTrajectoryGateBlockRetry(wctx, payload, attempt, logWarn, logError) {
105
+ if (attempt > TRAJECTORY_GATE_BLOCK_MAX_RETRIES) {
106
+ logError(`[PD_GATE] Failed to persist trajectory gate block after ${TRAJECTORY_GATE_BLOCK_MAX_RETRIES} retries: ${payload.toolName} ${payload.filePath}`);
107
+ return;
108
+ }
109
+ setTimeout(() => {
110
+ try {
111
+ wctx.trajectory?.recordGateBlock?.(payload);
112
+ logWarn(`[PD_GATE] Trajectory gate block persisted on retry ${attempt}`);
113
+ }
114
+ catch (error) {
115
+ logWarn(`[PD_GATE] Retrying trajectory gate block persistence (attempt ${attempt + 1}): ${String(error)}`);
116
+ scheduleTrajectoryGateBlockRetry(wctx, payload, attempt + 1, logWarn, logError);
117
+ }
118
+ }, TRAJECTORY_GATE_BLOCK_RETRY_DELAY_MS * attempt);
119
+ }
@@ -1,3 +1,21 @@
1
+ /**
2
+ * Security Gate Hook - Orchestration Layer
3
+ *
4
+ * HOOK CHAIN PRIORITY (short-circuits on first block):
5
+ *
6
+ * 1. Early Return: Skip if not write/bash/agent tool or no workspace
7
+ * 2. Thinking OS Checkpoint (P-10): Deep reflection enforcement
8
+ * 3. GFI Gate: Fatigue index-based blocking
9
+ * 4. Bash Mutation Detection: Heuristic for bash file modifications
10
+ * 5. Progressive Trust Gate: Stage 1-4 access control
11
+ * 6. Edit Verification (P-03): Exact/fuzzy match for edit operations
12
+ *
13
+ * IMPORTANT: This is the SINGLE AUTHORITATIVE orchestration path.
14
+ * All policy modules (gfi-gate, progressive-trust-gate) use the shared
15
+ * `recordGateBlockAndReturn` helper to ensure consistent block persistence.
16
+ *
17
+ * Zero-width character detection is handled in bash-risk.ts.
18
+ */
1
19
  import type { PluginHookBeforeToolCallEvent, PluginHookToolContext, PluginHookBeforeToolCallResult } from '../openclaw-sdk.js';
2
20
  export declare function handleBeforeToolCall(event: PluginHookBeforeToolCallEvent, ctx: PluginHookToolContext & {
3
21
  workspaceDir?: string;