principles-disciple 1.5.4

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 (189) hide show
  1. package/dist/commands/capabilities.d.ts +3 -0
  2. package/dist/commands/capabilities.js +73 -0
  3. package/dist/commands/evolver.d.ts +9 -0
  4. package/dist/commands/evolver.js +26 -0
  5. package/dist/commands/pain.d.ts +5 -0
  6. package/dist/commands/pain.js +114 -0
  7. package/dist/commands/strategy.d.ts +3 -0
  8. package/dist/commands/strategy.js +29 -0
  9. package/dist/commands/thinking-os.d.ts +2 -0
  10. package/dist/commands/thinking-os.js +162 -0
  11. package/dist/commands/trust.d.ts +4 -0
  12. package/dist/commands/trust.js +95 -0
  13. package/dist/core/agent-loader.d.ts +44 -0
  14. package/dist/core/agent-loader.js +147 -0
  15. package/dist/core/config-service.d.ts +15 -0
  16. package/dist/core/config-service.js +26 -0
  17. package/dist/core/config.d.ts +103 -0
  18. package/dist/core/config.js +186 -0
  19. package/dist/core/detection-funnel.d.ts +33 -0
  20. package/dist/core/detection-funnel.js +100 -0
  21. package/dist/core/detection-service.d.ts +15 -0
  22. package/dist/core/detection-service.js +28 -0
  23. package/dist/core/dictionary-service.d.ts +15 -0
  24. package/dist/core/dictionary-service.js +26 -0
  25. package/dist/core/dictionary.d.ts +36 -0
  26. package/dist/core/dictionary.js +136 -0
  27. package/dist/core/event-log.d.ts +53 -0
  28. package/dist/core/event-log.js +196 -0
  29. package/dist/core/evolution-engine.d.ts +119 -0
  30. package/dist/core/evolution-engine.js +542 -0
  31. package/dist/core/evolution-types.d.ts +126 -0
  32. package/dist/core/evolution-types.js +56 -0
  33. package/dist/core/hygiene/tracker.d.ts +22 -0
  34. package/dist/core/hygiene/tracker.js +106 -0
  35. package/dist/core/init.d.ts +12 -0
  36. package/dist/core/init.js +117 -0
  37. package/dist/core/migration.d.ts +6 -0
  38. package/dist/core/migration.js +90 -0
  39. package/dist/core/pain.d.ts +4 -0
  40. package/dist/core/pain.js +70 -0
  41. package/dist/core/path-resolver.d.ts +43 -0
  42. package/dist/core/path-resolver.js +259 -0
  43. package/dist/core/paths.d.ts +60 -0
  44. package/dist/core/paths.js +67 -0
  45. package/dist/core/profile.d.ts +62 -0
  46. package/dist/core/profile.js +210 -0
  47. package/dist/core/risk-calculator.d.ts +7 -0
  48. package/dist/core/risk-calculator.js +39 -0
  49. package/dist/core/session-tracker.d.ts +76 -0
  50. package/dist/core/session-tracker.js +286 -0
  51. package/dist/core/system-logger.d.ts +8 -0
  52. package/dist/core/system-logger.js +31 -0
  53. package/dist/core/trust-engine.d.ts +91 -0
  54. package/dist/core/trust-engine.js +284 -0
  55. package/dist/core/workspace-context.d.ts +64 -0
  56. package/dist/core/workspace-context.js +134 -0
  57. package/dist/hooks/gate.d.ts +6 -0
  58. package/dist/hooks/gate.js +487 -0
  59. package/dist/hooks/lifecycle.d.ts +5 -0
  60. package/dist/hooks/lifecycle.js +180 -0
  61. package/dist/hooks/llm.d.ts +4 -0
  62. package/dist/hooks/llm.js +153 -0
  63. package/dist/hooks/pain.d.ts +5 -0
  64. package/dist/hooks/pain.js +173 -0
  65. package/dist/hooks/prompt.d.ts +38 -0
  66. package/dist/hooks/prompt.js +285 -0
  67. package/dist/hooks/subagent.d.ts +2 -0
  68. package/dist/hooks/subagent.js +70 -0
  69. package/dist/i18n/commands.d.ts +26 -0
  70. package/dist/i18n/commands.js +88 -0
  71. package/dist/index.d.ts +7 -0
  72. package/dist/index.js +204 -0
  73. package/dist/service/evolution-worker.d.ts +17 -0
  74. package/dist/service/evolution-worker.js +293 -0
  75. package/dist/tools/agent-spawn.d.ts +33 -0
  76. package/dist/tools/agent-spawn.js +170 -0
  77. package/dist/tools/critique-prompt.d.ts +14 -0
  78. package/dist/tools/critique-prompt.js +81 -0
  79. package/dist/tools/deep-reflect.d.ts +19 -0
  80. package/dist/tools/deep-reflect.js +174 -0
  81. package/dist/tools/model-index.d.ts +9 -0
  82. package/dist/tools/model-index.js +82 -0
  83. package/dist/types/event-types.d.ts +229 -0
  84. package/dist/types/event-types.js +73 -0
  85. package/dist/types/hygiene-types.d.ts +20 -0
  86. package/dist/types/hygiene-types.js +12 -0
  87. package/dist/types.d.ts +1 -0
  88. package/dist/types.js +1 -0
  89. package/dist/utils/file-lock.d.ts +64 -0
  90. package/dist/utils/file-lock.js +270 -0
  91. package/dist/utils/glob-match.d.ts +28 -0
  92. package/dist/utils/glob-match.js +49 -0
  93. package/dist/utils/hashing.d.ts +9 -0
  94. package/dist/utils/hashing.js +25 -0
  95. package/dist/utils/io.d.ts +6 -0
  96. package/dist/utils/io.js +106 -0
  97. package/dist/utils/nlp.d.ts +9 -0
  98. package/dist/utils/nlp.js +59 -0
  99. package/dist/utils/plugin-logger.d.ts +39 -0
  100. package/dist/utils/plugin-logger.js +70 -0
  101. package/openclaw.plugin.json +46 -0
  102. package/package.json +63 -0
  103. package/templates/langs/en/core/AGENTS.md +206 -0
  104. package/templates/langs/en/core/BOOT.md +60 -0
  105. package/templates/langs/en/core/BOOTSTRAP.md +250 -0
  106. package/templates/langs/en/core/HEARTBEAT.md +74 -0
  107. package/templates/langs/en/core/IDENTITY.md +8 -0
  108. package/templates/langs/en/core/PRINCIPLES.md +10 -0
  109. package/templates/langs/en/core/SOUL.md +76 -0
  110. package/templates/langs/en/core/TOOLS.md +53 -0
  111. package/templates/langs/en/core/USER.md +10 -0
  112. package/templates/langs/en/pain/00_seed_samples.md +23 -0
  113. package/templates/langs/en/pain_dictionary.json +22 -0
  114. package/templates/langs/en/skills/admin/SKILL.md +40 -0
  115. package/templates/langs/en/skills/bootstrap-tools/SKILL.md +53 -0
  116. package/templates/langs/en/skills/deductive-audit/SKILL.md +36 -0
  117. package/templates/langs/en/skills/evolution-framework-update/SKILL.md +31 -0
  118. package/templates/langs/en/skills/evolve-system/SKILL.md +46 -0
  119. package/templates/langs/en/skills/evolve-task/SKILL.md +83 -0
  120. package/templates/langs/en/skills/feedback/SKILL.md +51 -0
  121. package/templates/langs/en/skills/init-strategy/SKILL.md +54 -0
  122. package/templates/langs/en/skills/inject-rule/SKILL.md +19 -0
  123. package/templates/langs/en/skills/manage-okr/SKILL.md +96 -0
  124. package/templates/langs/en/skills/pain/SKILL.md +19 -0
  125. package/templates/langs/en/skills/pd-daily/SKILL.md +199 -0
  126. package/templates/langs/en/skills/pd-grooming/SKILL.md +46 -0
  127. package/templates/langs/en/skills/pd-mentor/SKILL.md +230 -0
  128. package/templates/langs/en/skills/plan-script/SKILL.md +32 -0
  129. package/templates/langs/en/skills/profile/SKILL.md +24 -0
  130. package/templates/langs/en/skills/reflection/SKILL.md +40 -0
  131. package/templates/langs/en/skills/reflection-log/SKILL.md +37 -0
  132. package/templates/langs/en/skills/report/SKILL.md +13 -0
  133. package/templates/langs/en/skills/root-cause/SKILL.md +33 -0
  134. package/templates/langs/en/skills/triage/SKILL.md +29 -0
  135. package/templates/langs/en/skills/watch-evolution/SKILL.md +33 -0
  136. package/templates/langs/zh/core/AGENTS.md +207 -0
  137. package/templates/langs/zh/core/BOOT.md +60 -0
  138. package/templates/langs/zh/core/BOOTSTRAP.md +250 -0
  139. package/templates/langs/zh/core/HEARTBEAT.md +74 -0
  140. package/templates/langs/zh/core/IDENTITY.md +8 -0
  141. package/templates/langs/zh/core/SOUL.md +76 -0
  142. package/templates/langs/zh/core/TOOLS.md +53 -0
  143. package/templates/langs/zh/core/USER.md +10 -0
  144. package/templates/langs/zh/pain/00_seed_samples.md +24 -0
  145. package/templates/langs/zh/pain_dictionary.json +18 -0
  146. package/templates/langs/zh/skills/admin/SKILL.md +42 -0
  147. package/templates/langs/zh/skills/bootstrap-tools/SKILL.md +52 -0
  148. package/templates/langs/zh/skills/deductive-audit/SKILL.md +36 -0
  149. package/templates/langs/zh/skills/evolution-framework-update/SKILL.md +31 -0
  150. package/templates/langs/zh/skills/evolve-system/SKILL.md +46 -0
  151. package/templates/langs/zh/skills/evolve-task/SKILL.md +83 -0
  152. package/templates/langs/zh/skills/feedback/SKILL.md +53 -0
  153. package/templates/langs/zh/skills/init-strategy/SKILL.md +54 -0
  154. package/templates/langs/zh/skills/inject-rule/SKILL.md +19 -0
  155. package/templates/langs/zh/skills/manage-okr/SKILL.md +109 -0
  156. package/templates/langs/zh/skills/pain/SKILL.md +19 -0
  157. package/templates/langs/zh/skills/pd-daily/SKILL.md +199 -0
  158. package/templates/langs/zh/skills/pd-grooming/SKILL.md +46 -0
  159. package/templates/langs/zh/skills/pd-mentor/SKILL.md +230 -0
  160. package/templates/langs/zh/skills/plan-script/SKILL.md +32 -0
  161. package/templates/langs/zh/skills/profile/SKILL.md +24 -0
  162. package/templates/langs/zh/skills/reflection/SKILL.md +40 -0
  163. package/templates/langs/zh/skills/reflection-log/SKILL.md +37 -0
  164. package/templates/langs/zh/skills/report/SKILL.md +13 -0
  165. package/templates/langs/zh/skills/root-cause/SKILL.md +33 -0
  166. package/templates/langs/zh/skills/triage/SKILL.md +29 -0
  167. package/templates/langs/zh/skills/watch-evolution/SKILL.md +33 -0
  168. package/templates/pain_dictionary.json +36 -0
  169. package/templates/pain_settings.json +77 -0
  170. package/templates/workspace/.principles/00-kernel.md +51 -0
  171. package/templates/workspace/.principles/DECISION_POLICY.json +44 -0
  172. package/templates/workspace/.principles/PRINCIPLES.md +20 -0
  173. package/templates/workspace/.principles/PROFILE.json +52 -0
  174. package/templates/workspace/.principles/PROFILE.schema.json +56 -0
  175. package/templates/workspace/.principles/THINKING_OS.md +64 -0
  176. package/templates/workspace/.principles/THINKING_OS_ARCHIVE.md +7 -0
  177. package/templates/workspace/.principles/THINKING_OS_CANDIDATES.md +9 -0
  178. package/templates/workspace/.principles/models/_INDEX.md +27 -0
  179. package/templates/workspace/.principles/models/first_principles.md +62 -0
  180. package/templates/workspace/.principles/models/marketing_4p.md +52 -0
  181. package/templates/workspace/.principles/models/porter_five.md +63 -0
  182. package/templates/workspace/.principles/models/swot.md +60 -0
  183. package/templates/workspace/.principles/models/user_story_map.md +63 -0
  184. package/templates/workspace/.state/WORKBOARD.json +4 -0
  185. package/templates/workspace/AUDIT.md +15 -0
  186. package/templates/workspace/PLAN.md +2 -0
  187. package/templates/workspace/okr/RECOVERY_PROTOCOL.md +56 -0
  188. package/templates/workspace/okr/TASK_CHANGES.jsonl +6 -0
  189. package/templates/workspace/okr/WEEK_TASKS.json +6 -0
@@ -0,0 +1,259 @@
1
+ import * as path from 'path';
2
+ import * as os from 'os';
3
+ import * as fs from 'fs';
4
+ const DEFAULT_WORKSPACE_SUBPATH = '.openclaw/workspace';
5
+ export const PD_ENV_VARS = {
6
+ WORKSPACE_DIR: 'PD_WORKSPACE_DIR',
7
+ STATE_DIR: 'PD_STATE_DIR',
8
+ DEBUG: 'DEBUG',
9
+ };
10
+ export const PD_ENV_DESCRIPTIONS = {
11
+ WORKSPACE_DIR: {
12
+ desc: 'Override the default workspace directory',
13
+ example: 'PD_WORKSPACE_DIR=/home/user/my-workspace',
14
+ },
15
+ STATE_DIR: {
16
+ desc: 'Override the default state directory (.state)',
17
+ example: 'PD_STATE_DIR=/home/user/my-workspace/.state',
18
+ },
19
+ DEBUG: {
20
+ desc: 'Enable debug logging for path resolution',
21
+ example: 'DEBUG=true',
22
+ },
23
+ };
24
+ export function printEnvVarHelp() {
25
+ console.log('\n📁 Principles Disciple - Environment Variables\n');
26
+ console.log('You can customize directory paths using environment variables:\n');
27
+ for (const [key, varName] of Object.entries(PD_ENV_VARS)) {
28
+ const info = PD_ENV_DESCRIPTIONS[key];
29
+ console.log(` ${varName}`);
30
+ console.log(` Description: ${info.desc}`);
31
+ console.log(` Example: ${info.example}`);
32
+ console.log();
33
+ }
34
+ console.log('💡 Tips:');
35
+ console.log(' - These can be set in your shell profile (~/.bashrc, ~/.zshrc)');
36
+ console.log(' - Or passed when starting OpenClaw gateway');
37
+ console.log(' - Example: PD_WORKSPACE_DIR=/custom/path openclaw-gateway start\n');
38
+ }
39
+ const PD_CONFIG_FILE = 'principles-disciple.json';
40
+ const PD_CONFIG_LOCATIONS = [
41
+ path.join(process.cwd(), PD_CONFIG_FILE),
42
+ path.join(os.homedir(), '.openclaw', PD_CONFIG_FILE),
43
+ path.join(os.homedir(), '.principles', PD_CONFIG_FILE),
44
+ ];
45
+ function findConfigFile() {
46
+ for (const loc of PD_CONFIG_LOCATIONS) {
47
+ if (fs.existsSync(loc)) {
48
+ return loc;
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ function loadConfigFromFile() {
54
+ const configPath = findConfigFile();
55
+ if (!configPath) {
56
+ return null;
57
+ }
58
+ try {
59
+ const content = fs.readFileSync(configPath, 'utf8');
60
+ const config = JSON.parse(content);
61
+ console.log(`[PD:PathResolver] Loaded config from: ${configPath}`);
62
+ return config;
63
+ }
64
+ catch (e) {
65
+ console.warn(`[PD:PathResolver] Failed to load config from ${configPath}: ${String(e)}`);
66
+ return null;
67
+ }
68
+ }
69
+ export class PathResolver {
70
+ workspaceDir = null;
71
+ stateDir = null;
72
+ logger;
73
+ normalizeWorkspace;
74
+ initialized = false;
75
+ constructor(options = {}) {
76
+ this.logger = options.logger;
77
+ this.normalizeWorkspace = options.normalizeWorkspace ?? true;
78
+ if (options.workspaceDir) {
79
+ this.workspaceDir = options.workspaceDir;
80
+ }
81
+ }
82
+ log(level, msg) {
83
+ const prefix = '[PD:PathResolver]';
84
+ const fullMsg = `${prefix} ${msg}`;
85
+ if (process.env.DEBUG === 'true') {
86
+ console.debug(fullMsg);
87
+ }
88
+ switch (level) {
89
+ case 'debug':
90
+ this.logger?.debug?.(fullMsg);
91
+ break;
92
+ case 'info':
93
+ this.logger?.info?.(fullMsg) || console.log(fullMsg);
94
+ break;
95
+ case 'warn':
96
+ this.logger?.warn?.(fullMsg) || console.warn(fullMsg);
97
+ break;
98
+ case 'error':
99
+ this.logger?.error?.(fullMsg) || console.error(fullMsg);
100
+ break;
101
+ }
102
+ }
103
+ detectWorkspaceDir() {
104
+ const envWorkspace = process.env.PD_WORKSPACE_DIR;
105
+ if (envWorkspace && envWorkspace.trim()) {
106
+ this.log('info', `Using workspace from PD_WORKSPACE_DIR: ${envWorkspace}`);
107
+ return envWorkspace.trim();
108
+ }
109
+ const envOpenclaw = process.env.OPENCLAW_WORKSPACE;
110
+ if (envOpenclaw && envOpenclaw.trim()) {
111
+ this.log('info', `Using workspace from OPENCLAW_WORKSPACE: ${envOpenclaw}`);
112
+ return envOpenclaw.trim();
113
+ }
114
+ const fileConfig = loadConfigFromFile();
115
+ if (fileConfig?.workspace) {
116
+ this.log('info', `Using workspace from config file: ${fileConfig.workspace}`);
117
+ return fileConfig.workspace;
118
+ }
119
+ const homeDir = os.homedir();
120
+ const defaultWorkspace = path.join(homeDir, DEFAULT_WORKSPACE_SUBPATH);
121
+ this.log('info', `Using default workspace: ${defaultWorkspace}`);
122
+ return defaultWorkspace;
123
+ }
124
+ normalizePath(inputPath) {
125
+ let normalized = path.resolve(inputPath);
126
+ if (this.normalizeWorkspace) {
127
+ const problematicSuffixes = ['/memory', '/docs'];
128
+ for (const suffix of problematicSuffixes) {
129
+ if (normalized.endsWith(suffix)) {
130
+ const parent = path.dirname(normalized);
131
+ this.log('warn', `Detected subdirectory suffix '${suffix}' in path. Normalized to parent: ${parent}`);
132
+ normalized = parent;
133
+ break;
134
+ }
135
+ }
136
+ }
137
+ return normalized;
138
+ }
139
+ normalizeWorkspacePath(inputPath) {
140
+ return this.normalizePath(inputPath);
141
+ }
142
+ getWorkspaceDir() {
143
+ if (this.initialized && this.workspaceDir) {
144
+ return this.workspaceDir;
145
+ }
146
+ let dir = this.detectWorkspaceDir();
147
+ if (this.normalizeWorkspace) {
148
+ const originalDir = dir;
149
+ dir = this.normalizePath(dir);
150
+ if (originalDir !== dir) {
151
+ this.log('info', `Workspace path normalized: ${originalDir} -> ${dir}`);
152
+ }
153
+ }
154
+ this.workspaceDir = dir;
155
+ this.initialized = true;
156
+ this.log('debug', `Final workspace directory: ${this.workspaceDir}`);
157
+ return this.workspaceDir;
158
+ }
159
+ getStateDir() {
160
+ if (this.stateDir) {
161
+ return this.stateDir;
162
+ }
163
+ const envStateDir = process.env.PD_STATE_DIR;
164
+ if (envStateDir && envStateDir.trim()) {
165
+ this.stateDir = envStateDir.trim();
166
+ this.log('info', `Using state directory from PD_STATE_DIR: ${this.stateDir}`);
167
+ return this.stateDir;
168
+ }
169
+ const fileConfig = loadConfigFromFile();
170
+ if (fileConfig?.state) {
171
+ this.stateDir = fileConfig.state;
172
+ this.log('info', `Using state directory from config file: ${this.stateDir}`);
173
+ return this.stateDir;
174
+ }
175
+ this.stateDir = path.join(this.getWorkspaceDir(), '.state');
176
+ this.log('debug', `Computed state directory: ${this.stateDir}`);
177
+ return this.stateDir;
178
+ }
179
+ resolve(key) {
180
+ const workspace = this.getWorkspaceDir();
181
+ const state = this.getStateDir();
182
+ const memory = path.join(workspace, 'memory');
183
+ const pathMap = {
184
+ 'PROFILE': path.join(workspace, '.principles', 'PROFILE.json'),
185
+ 'PRINCIPLES': path.join(workspace, '.principles', 'PRINCIPLES.md'),
186
+ 'THINKING_OS': path.join(workspace, '.principles', 'THINKING_OS.md'),
187
+ 'KERNEL': path.join(workspace, '.principles', '00-kernel.md'),
188
+ 'DECISION_POLICY': path.join(workspace, '.principles', 'DECISION_POLICY.json'),
189
+ 'MODELS_DIR': path.join(workspace, '.principles', 'models'),
190
+ 'PLAN': path.join(workspace, 'PLAN.md'),
191
+ 'AGENT_SCORECARD': path.join(state, 'AGENT_SCORECARD.json'),
192
+ 'PAIN_FLAG': path.join(state, '.pain_flag'),
193
+ 'EVOLUTION_QUEUE': path.join(state, 'evolution_queue.json'),
194
+ 'EVOLUTION_DIRECTIVE': path.join(state, 'evolution_directive.json'),
195
+ 'WORKBOARD': path.join(state, 'WORKBOARD.json'),
196
+ 'SYSTEM_CAPABILITIES': path.join(state, 'SYSTEM_CAPABILITIES.json'),
197
+ 'PAIN_SETTINGS': path.join(state, 'pain_settings.json'),
198
+ 'PAIN_CANDIDATES': path.join(state, 'pain_candidates.json'),
199
+ 'THINKING_OS_USAGE': path.join(state, 'thinking_os_usage.json'),
200
+ 'DICTIONARY': path.join(state, 'pain_dictionary.json'),
201
+ 'STATE_DIR': state,
202
+ 'LOGS': path.join(memory, 'logs'),
203
+ 'SYSTEM_LOG': path.join(memory, 'logs', 'SYSTEM.log'),
204
+ 'REFLECTION_LOG': path.join(memory, 'reflection-log.md'),
205
+ 'USER_CONTEXT': path.join(memory, 'USER_CONTEXT.md'),
206
+ 'OKR_DIR': path.join(memory, 'okr'),
207
+ 'CURRENT_FOCUS': path.join(memory, 'okr', 'CURRENT_FOCUS.md'),
208
+ 'WEEK_STATE': path.join(memory, 'okr', 'WEEK_STATE.json'),
209
+ 'THINKING_OS_CANDIDATES': path.join(memory, 'THINKING_OS_CANDIDATES.md'),
210
+ 'MEMORY': memory,
211
+ };
212
+ const resolved = pathMap[key];
213
+ if (!resolved) {
214
+ this.log('warn', `Unknown path key: ${key}`);
215
+ throw new Error(`Unknown path key: ${key}`);
216
+ }
217
+ this.log('debug', `Resolved path for '${key}': ${resolved}`);
218
+ return resolved;
219
+ }
220
+ ensureStateDir() {
221
+ const stateDir = this.getStateDir();
222
+ if (!fs.existsSync(stateDir)) {
223
+ this.log('info', `Creating state directory: ${stateDir}`);
224
+ fs.mkdirSync(stateDir, { recursive: true });
225
+ }
226
+ }
227
+ static createFromHookContext(ctx) {
228
+ const resolver = new PathResolver();
229
+ if (ctx?.workspaceDir) {
230
+ let workspaceDir = ctx.workspaceDir;
231
+ if (resolver.normalizeWorkspace) {
232
+ workspaceDir = resolver.normalizePath(workspaceDir);
233
+ }
234
+ resolver.workspaceDir = workspaceDir;
235
+ resolver.initialized = true;
236
+ resolver.log('info', `Created from hook context with workspace: ${workspaceDir}`);
237
+ }
238
+ if (ctx?.stateDir) {
239
+ resolver.stateDir = ctx.stateDir;
240
+ }
241
+ return resolver;
242
+ }
243
+ }
244
+ export function createDefaultConfig(targetPath) {
245
+ const defaultConfig = {
246
+ workspace: path.join(os.homedir(), '.openclaw', 'workspace'),
247
+ state: path.join(os.homedir(), '.openclaw', 'workspace', '.state'),
248
+ debug: false,
249
+ };
250
+ const target = targetPath || path.join(os.homedir(), '.openclaw', PD_CONFIG_FILE);
251
+ const dir = path.dirname(target);
252
+ if (!fs.existsSync(dir)) {
253
+ fs.mkdirSync(dir, { recursive: true });
254
+ }
255
+ fs.writeFileSync(target, JSON.stringify(defaultConfig, null, 2), 'utf8');
256
+ console.log(`✅ Created default config at: ${target}`);
257
+ console.log(` You can edit this file to customize paths.`);
258
+ return target;
259
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Principles Disciple Directory Constants
3
+ * Establishing a logical separation between Identity, State, and Memory.
4
+ */
5
+ export declare const PD_DIRS: {
6
+ /** 🧬 Core configuration, identity, and kernel rules (hidden) */
7
+ IDENTITY: string;
8
+ /** 🧠 Deep Reflection mental models */
9
+ MODELS: string;
10
+ /** ⚡ Volatile operational data, queues, and task status (hidden) */
11
+ STATE: string;
12
+ /** 💾 Historical records, logs, and long-term memory */
13
+ MEMORY: string;
14
+ /** 🎯 Strategic objectives and focus areas */
15
+ OKR: string;
16
+ /** 📁 Internal logs directory */
17
+ LOGS: string;
18
+ /** 🧠 Session persistence directory */
19
+ SESSIONS: string;
20
+ /** 🩹 Semantic pain samples for L3 retrieval */
21
+ PAIN_SAMPLES: string;
22
+ };
23
+ /**
24
+ * Standard File Path Mappings
25
+ */
26
+ export declare const PD_FILES: {
27
+ PROFILE: string;
28
+ PRINCIPLES: string;
29
+ THINKING_OS: string;
30
+ KERNEL: string;
31
+ DECISION_POLICY: string;
32
+ MODELS_DIR: string;
33
+ STATE_DIR: string;
34
+ EVOLUTION_QUEUE: string;
35
+ EVOLUTION_DIRECTIVE: string;
36
+ WORKBOARD: string;
37
+ AGENT_SCORECARD: string;
38
+ PAIN_FLAG: string;
39
+ SYSTEM_CAPABILITIES: string;
40
+ PAIN_SETTINGS: string;
41
+ PAIN_CANDIDATES: string;
42
+ THINKING_OS_USAGE: string;
43
+ SESSION_DIR: string;
44
+ DICTIONARY: string;
45
+ PLAN: string;
46
+ MEMORY_MD: string;
47
+ HEARTBEAT: string;
48
+ SYSTEM_LOG: string;
49
+ REFLECTION_LOG: string;
50
+ USER_CONTEXT: string;
51
+ OKR_DIR: string;
52
+ CURRENT_FOCUS: string;
53
+ WEEK_STATE: string;
54
+ THINKING_OS_CANDIDATES: string;
55
+ SEMANTIC_PAIN: string;
56
+ };
57
+ /**
58
+ * Resolves a PD file path within a given workspace.
59
+ */
60
+ export declare function resolvePdPath(workspaceDir: string, fileKey: keyof typeof PD_FILES): string;
@@ -0,0 +1,67 @@
1
+ import * as path from 'path';
2
+ /**
3
+ * Principles Disciple Directory Constants
4
+ * Establishing a logical separation between Identity, State, and Memory.
5
+ */
6
+ export const PD_DIRS = {
7
+ /** 🧬 Core configuration, identity, and kernel rules (hidden) */
8
+ IDENTITY: '.principles',
9
+ /** 🧠 Deep Reflection mental models */
10
+ MODELS: path.join('.principles', 'models'),
11
+ /** ⚡ Volatile operational data, queues, and task status (hidden) */
12
+ STATE: '.state',
13
+ /** 💾 Historical records, logs, and long-term memory */
14
+ MEMORY: 'memory',
15
+ /** 🎯 Strategic objectives and focus areas */
16
+ OKR: path.join('memory', 'okr'),
17
+ /** 📁 Internal logs directory */
18
+ LOGS: path.join('memory', 'logs'),
19
+ /** 🧠 Session persistence directory */
20
+ SESSIONS: path.join('.state', 'sessions'),
21
+ /** 🩹 Semantic pain samples for L3 retrieval */
22
+ PAIN_SAMPLES: path.join('memory', 'pain'),
23
+ };
24
+ /**
25
+ * Standard File Path Mappings
26
+ */
27
+ export const PD_FILES = {
28
+ // Identity Layer
29
+ PROFILE: path.join(PD_DIRS.IDENTITY, 'PROFILE.json'),
30
+ PRINCIPLES: path.join(PD_DIRS.IDENTITY, 'PRINCIPLES.md'),
31
+ THINKING_OS: path.join(PD_DIRS.IDENTITY, 'THINKING_OS.md'),
32
+ KERNEL: path.join(PD_DIRS.IDENTITY, '00-kernel.md'),
33
+ DECISION_POLICY: path.join(PD_DIRS.IDENTITY, 'DECISION_POLICY.json'),
34
+ MODELS_DIR: PD_DIRS.MODELS,
35
+ // State Layer
36
+ STATE_DIR: PD_DIRS.STATE,
37
+ EVOLUTION_QUEUE: path.join(PD_DIRS.STATE, 'evolution_queue.json'),
38
+ EVOLUTION_DIRECTIVE: path.join(PD_DIRS.STATE, 'evolution_directive.json'),
39
+ WORKBOARD: path.join(PD_DIRS.STATE, 'WORKBOARD.json'),
40
+ AGENT_SCORECARD: path.join(PD_DIRS.STATE, 'AGENT_SCORECARD.json'),
41
+ PAIN_FLAG: path.join(PD_DIRS.STATE, '.pain_flag'),
42
+ SYSTEM_CAPABILITIES: path.join(PD_DIRS.STATE, 'SYSTEM_CAPABILITIES.json'),
43
+ PAIN_SETTINGS: path.join(PD_DIRS.STATE, 'pain_settings.json'),
44
+ PAIN_CANDIDATES: path.join(PD_DIRS.STATE, 'pain_candidates.json'),
45
+ THINKING_OS_USAGE: path.join(PD_DIRS.STATE, 'thinking_os_usage.json'),
46
+ SESSION_DIR: PD_DIRS.SESSIONS,
47
+ DICTIONARY: path.join(PD_DIRS.STATE, 'pain_dictionary.json'),
48
+ // Workflow Layer (Project Root)
49
+ PLAN: 'PLAN.md',
50
+ MEMORY_MD: 'MEMORY.md',
51
+ HEARTBEAT: 'HEARTBEAT.md',
52
+ // Memory Layer
53
+ SYSTEM_LOG: path.join(PD_DIRS.LOGS, 'SYSTEM.log'),
54
+ REFLECTION_LOG: path.join(PD_DIRS.MEMORY, 'reflection-log.md'),
55
+ USER_CONTEXT: path.join(PD_DIRS.MEMORY, 'USER_CONTEXT.md'),
56
+ OKR_DIR: PD_DIRS.OKR,
57
+ CURRENT_FOCUS: path.join(PD_DIRS.OKR, 'CURRENT_FOCUS.md'),
58
+ WEEK_STATE: path.join(PD_DIRS.OKR, 'WEEK_STATE.json'),
59
+ THINKING_OS_CANDIDATES: path.join(PD_DIRS.MEMORY, 'THINKING_OS_CANDIDATES.md'),
60
+ SEMANTIC_PAIN: path.join(PD_DIRS.PAIN_SAMPLES, 'confusion_samples.md'),
61
+ };
62
+ /**
63
+ * Resolves a PD file path within a given workspace.
64
+ */
65
+ export function resolvePdPath(workspaceDir, fileKey) {
66
+ return path.join(workspaceDir, PD_FILES[fileKey]);
67
+ }
@@ -0,0 +1,62 @@
1
+ export declare const PROFILE_AUDIT_LEVELS: Set<string>;
2
+ export declare const PROFILE_EVOLUTION_MODES: Set<string>;
3
+ export declare const PROFILE_TEST_LEVELS: Set<string>;
4
+ export declare const PROFILE_DEFAULTS: {
5
+ audit_level: string;
6
+ risk_paths: string[];
7
+ evolution_mode: string;
8
+ gate: {
9
+ require_plan_for_risk_paths: boolean;
10
+ require_audit_before_write: boolean;
11
+ require_reviewer_after_write: boolean;
12
+ };
13
+ tests: {
14
+ on_change: string;
15
+ on_risk_change: string;
16
+ commands: Record<string, string>;
17
+ };
18
+ pain: {
19
+ soft_capture_threshold: number;
20
+ adaptive: {
21
+ enabled: boolean;
22
+ spiral_boost: number;
23
+ min_threshold: number;
24
+ max_threshold: number;
25
+ backlog_trigger: number;
26
+ hard_failure_trigger: number;
27
+ low_recent_success_boost: number;
28
+ high_recent_pain_boost: number;
29
+ };
30
+ };
31
+ lifecycle: {
32
+ enabled: boolean;
33
+ heartbeat_stale_hours: number;
34
+ };
35
+ progressive_gate: {
36
+ enabled: boolean;
37
+ plan_approvals: {
38
+ enabled: boolean;
39
+ max_lines_override: number;
40
+ allowed_patterns: string[];
41
+ allowed_operations: string[];
42
+ };
43
+ };
44
+ edit_verification: {
45
+ enabled: boolean;
46
+ max_file_size_bytes: number;
47
+ fuzzy_match_enabled: boolean;
48
+ fuzzy_match_threshold: number;
49
+ skip_large_file_action: "warn" | "block";
50
+ };
51
+ thinking_checkpoint: {
52
+ enabled: boolean;
53
+ window_ms: number;
54
+ high_risk_tools: string[];
55
+ };
56
+ custom_guards: Array<{
57
+ pattern: string;
58
+ message: string;
59
+ severity: string;
60
+ }>;
61
+ };
62
+ export declare function normalizeProfile(rawProfile: any): any;
@@ -0,0 +1,210 @@
1
+ export const PROFILE_AUDIT_LEVELS = new Set(["low", "medium", "high"]);
2
+ export const PROFILE_EVOLUTION_MODES = new Set(["realtime", "async"]);
3
+ export const PROFILE_TEST_LEVELS = new Set(["smoke", "unit", "full"]);
4
+ export const PROFILE_DEFAULTS = {
5
+ audit_level: "medium",
6
+ risk_paths: [],
7
+ evolution_mode: "realtime",
8
+ gate: {
9
+ require_plan_for_risk_paths: true,
10
+ require_audit_before_write: true,
11
+ require_reviewer_after_write: true,
12
+ },
13
+ tests: {
14
+ on_change: "smoke",
15
+ on_risk_change: "unit",
16
+ commands: {},
17
+ },
18
+ pain: {
19
+ soft_capture_threshold: 30,
20
+ adaptive: {
21
+ enabled: true,
22
+ spiral_boost: 20,
23
+ min_threshold: 15,
24
+ max_threshold: 70,
25
+ backlog_trigger: 6,
26
+ hard_failure_trigger: 1,
27
+ low_recent_success_boost: 15,
28
+ high_recent_pain_boost: 10,
29
+ },
30
+ },
31
+ lifecycle: {
32
+ enabled: true,
33
+ heartbeat_stale_hours: 72,
34
+ },
35
+ progressive_gate: {
36
+ enabled: true,
37
+ plan_approvals: {
38
+ enabled: false,
39
+ max_lines_override: -1,
40
+ allowed_patterns: [],
41
+ allowed_operations: [],
42
+ },
43
+ },
44
+ edit_verification: {
45
+ enabled: true,
46
+ max_file_size_bytes: 10 * 1024 * 1024, // 10MB
47
+ fuzzy_match_enabled: true,
48
+ fuzzy_match_threshold: 0.8,
49
+ skip_large_file_action: "warn", // "warn" or "block"
50
+ },
51
+ thinking_checkpoint: {
52
+ enabled: false, // Default OFF to avoid blocking new users
53
+ window_ms: 5 * 60 * 1000, // 5 minute window
54
+ high_risk_tools: ['run_shell_command', 'delete_file', 'move_file', 'pd_spawn_agent'],
55
+ },
56
+ custom_guards: [],
57
+ };
58
+ export function normalizeProfile(rawProfile) {
59
+ const defaults = JSON.parse(JSON.stringify(PROFILE_DEFAULTS));
60
+ const warnings = [];
61
+ const normalized = { ...defaults };
62
+ let invalid = false;
63
+ if (!rawProfile || typeof rawProfile !== "object" || Array.isArray(rawProfile)) {
64
+ warnings.push("PROFILE root must be an object; defaults applied.");
65
+ invalid = true;
66
+ }
67
+ else {
68
+ // Merge known fields (Support both snake_case and camelCase)
69
+ const auditLevel = rawProfile.audit_level ?? rawProfile.auditLevel;
70
+ if (PROFILE_AUDIT_LEVELS.has(auditLevel)) {
71
+ normalized.audit_level = auditLevel;
72
+ }
73
+ else if (auditLevel !== undefined) {
74
+ warnings.push(`Invalid audit_level '${auditLevel}'`);
75
+ }
76
+ const evolutionMode = rawProfile.evolution_mode ?? rawProfile.evolutionMode;
77
+ if (PROFILE_EVOLUTION_MODES.has(evolutionMode)) {
78
+ normalized.evolution_mode = evolutionMode;
79
+ }
80
+ else if (evolutionMode !== undefined) {
81
+ warnings.push(`Invalid evolution_mode '${evolutionMode}'`);
82
+ }
83
+ const riskPaths = rawProfile.risk_paths ?? rawProfile.riskPaths;
84
+ if (Array.isArray(riskPaths)) {
85
+ normalized.risk_paths = riskPaths.filter((p) => typeof p === 'string');
86
+ }
87
+ else if (typeof riskPaths === 'string') {
88
+ normalized.risk_paths = [riskPaths];
89
+ }
90
+ else if (riskPaths !== undefined) {
91
+ warnings.push("risk_paths must be an array of strings");
92
+ }
93
+ // Gate settings
94
+ if (rawProfile.gate && typeof rawProfile.gate === 'object') {
95
+ const g = rawProfile.gate;
96
+ normalized.gate.require_plan_for_risk_paths = g.require_plan_for_risk_paths ?? g.requirePlanForRiskPaths ?? defaults.gate.require_plan_for_risk_paths;
97
+ normalized.gate.require_audit_before_write = g.require_audit_before_write ?? g.requireAuditBeforeWrite ?? defaults.gate.require_audit_before_write;
98
+ normalized.gate.require_reviewer_after_write = g.require_reviewer_after_write ?? g.requireReviewerAfterWrite ?? defaults.gate.require_reviewer_after_write;
99
+ }
100
+ // Progressive Gate
101
+ if (rawProfile.progressive_gate && typeof rawProfile.progressive_gate === 'object') {
102
+ const pg = rawProfile.progressive_gate;
103
+ normalized.progressive_gate.enabled = pg.enabled ?? pg.enabled ?? defaults.progressive_gate.enabled;
104
+ // Plan approvals configuration
105
+ if (pg.plan_approvals && typeof pg.plan_approvals === 'object') {
106
+ const pa = pg.plan_approvals;
107
+ normalized.progressive_gate.plan_approvals.enabled = pa.enabled ?? pa.planApprovals ?? defaults.progressive_gate.plan_approvals.enabled;
108
+ const maxLines = pa.max_lines_override ?? pa.maxLinesOverride;
109
+ if (typeof maxLines === 'number' && maxLines >= -1) {
110
+ normalized.progressive_gate.plan_approvals.max_lines_override = maxLines;
111
+ }
112
+ if (Array.isArray(pa.allowed_patterns)) {
113
+ normalized.progressive_gate.plan_approvals.allowed_patterns = pa.allowed_patterns.filter((p) => typeof p === 'string');
114
+ }
115
+ if (Array.isArray(pa.allowed_operations)) {
116
+ normalized.progressive_gate.plan_approvals.allowed_operations = pa.allowed_operations.filter((o) => typeof o === 'string');
117
+ }
118
+ }
119
+ }
120
+ else if (rawProfile.progressiveGate && typeof rawProfile.progressiveGate === 'object') {
121
+ const pg = rawProfile.progressiveGate;
122
+ normalized.progressive_gate.enabled = pg.enabled ?? defaults.progressive_gate.enabled;
123
+ // Plan approvals configuration (camelCase)
124
+ if (pg.planApprovals && typeof pg.planApprovals === 'object') {
125
+ const pa = pg.planApprovals;
126
+ normalized.progressive_gate.plan_approvals.enabled = pa.enabled ?? defaults.progressive_gate.plan_approvals.enabled;
127
+ const maxLines = pa.maxLinesOverride;
128
+ if (typeof maxLines === 'number' && maxLines >= -1) {
129
+ normalized.progressive_gate.plan_approvals.max_lines_override = maxLines;
130
+ }
131
+ if (Array.isArray(pa.allowedPatterns)) {
132
+ normalized.progressive_gate.plan_approvals.allowed_patterns = pa.allowedPatterns.filter((p) => typeof p === 'string');
133
+ }
134
+ if (Array.isArray(pa.allowedOperations)) {
135
+ normalized.progressive_gate.plan_approvals.allowed_operations = pa.allowedOperations.filter((o) => typeof o === 'string');
136
+ }
137
+ }
138
+ }
139
+ // Edit verification settings (P-03)
140
+ const evRaw = rawProfile.edit_verification ?? rawProfile.editVerification;
141
+ if (evRaw && typeof evRaw === 'object') {
142
+ normalized.edit_verification.enabled = evRaw.enabled ?? defaults.edit_verification.enabled;
143
+ const maxSize = evRaw.max_file_size_bytes ?? evRaw.maxFileSizeBytes;
144
+ if (typeof maxSize === 'number' && maxSize >= 0) {
145
+ normalized.edit_verification.max_file_size_bytes = maxSize;
146
+ }
147
+ normalized.edit_verification.fuzzy_match_enabled = evRaw.fuzzy_match_enabled ?? evRaw.fuzzyMatchEnabled ?? defaults.edit_verification.fuzzy_match_enabled;
148
+ const threshold = evRaw.fuzzy_match_threshold ?? evRaw.fuzzyMatchThreshold;
149
+ if (typeof threshold === 'number' && threshold > 0 && threshold <= 1) {
150
+ normalized.edit_verification.fuzzy_match_threshold = threshold;
151
+ }
152
+ const action = evRaw.skip_large_file_action ?? evRaw.skipLargeFileAction;
153
+ if (typeof action === 'string' && ['warn', 'block'].includes(action)) {
154
+ normalized.edit_verification.skip_large_file_action = action;
155
+ }
156
+ }
157
+ // Test settings
158
+ if (rawProfile.tests && typeof rawProfile.tests === 'object') {
159
+ const t = rawProfile.tests;
160
+ const onChange = t.on_change ?? t.onChange;
161
+ if (PROFILE_TEST_LEVELS.has(onChange)) {
162
+ normalized.tests.on_change = onChange;
163
+ }
164
+ const onRiskChange = t.on_risk_change ?? t.onRiskChange;
165
+ if (PROFILE_TEST_LEVELS.has(onRiskChange)) {
166
+ normalized.tests.on_risk_change = onRiskChange;
167
+ }
168
+ if (t.commands && typeof t.commands === 'object') {
169
+ normalized.tests.commands = { ...defaults.tests.commands, ...t.commands };
170
+ }
171
+ }
172
+ // Pain settings
173
+ if (rawProfile.pain && typeof rawProfile.pain === 'object') {
174
+ const p = rawProfile.pain;
175
+ normalized.pain.soft_capture_threshold = p.soft_capture_threshold ?? p.softCaptureThreshold ?? defaults.pain.soft_capture_threshold;
176
+ if (p.adaptive && typeof p.adaptive === 'object') {
177
+ normalized.pain.adaptive = { ...defaults.pain.adaptive, ...p.adaptive };
178
+ }
179
+ }
180
+ // Thinking OS Checkpoint settings (P-10)
181
+ const tcRaw = rawProfile.thinking_checkpoint ?? rawProfile.thinkingCheckpoint;
182
+ if (tcRaw && typeof tcRaw === 'object') {
183
+ normalized.thinking_checkpoint.enabled = tcRaw.enabled ?? defaults.thinking_checkpoint.enabled;
184
+ const windowMs = tcRaw.window_ms ?? tcRaw.windowMs;
185
+ if (typeof windowMs === 'number' && windowMs > 0) {
186
+ normalized.thinking_checkpoint.window_ms = windowMs;
187
+ }
188
+ if (Array.isArray(tcRaw.high_risk_tools ?? tcRaw.highRiskTools)) {
189
+ normalized.thinking_checkpoint.high_risk_tools = (tcRaw.high_risk_tools ?? tcRaw.highRiskTools).filter((t) => typeof t === 'string');
190
+ }
191
+ }
192
+ if (Array.isArray(rawProfile.custom_guards)) {
193
+ normalized.custom_guards = rawProfile.custom_guards.map((item) => {
194
+ let severity = "error";
195
+ const itemSeverity = item.severity;
196
+ if (itemSeverity && ["info", "warning", "error", "fatal"].includes(String(itemSeverity).toLowerCase())) {
197
+ severity = String(itemSeverity).toLowerCase();
198
+ }
199
+ return {
200
+ pattern: String(item.pattern || ""),
201
+ message: String(item.message || "Custom guard triggered"),
202
+ severity,
203
+ };
204
+ }).filter((item) => item.pattern);
205
+ }
206
+ }
207
+ normalized._profile_invalid = invalid;
208
+ normalized._profile_warnings = warnings;
209
+ return normalized;
210
+ }
@@ -0,0 +1,7 @@
1
+ export type RiskLevel = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
2
+ export interface FileModification {
3
+ toolName: string;
4
+ params: any;
5
+ }
6
+ export declare function estimateLineChanges(modification: FileModification): number;
7
+ export declare function assessRiskLevel(filePath: string, modification: FileModification, riskPaths: string[]): RiskLevel;