principles-disciple 1.5.4 โ 1.7.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.
- package/dist/commands/context.d.ts +5 -0
- package/dist/commands/context.js +312 -0
- package/dist/commands/evolution-status.d.ts +4 -0
- package/dist/commands/evolution-status.js +138 -0
- package/dist/commands/export.d.ts +2 -0
- package/dist/commands/export.js +45 -0
- package/dist/commands/focus.d.ts +14 -0
- package/dist/commands/focus.js +582 -0
- package/dist/commands/pain.js +143 -6
- package/dist/commands/principle-rollback.d.ts +4 -0
- package/dist/commands/principle-rollback.js +22 -0
- package/dist/commands/rollback.d.ts +19 -0
- package/dist/commands/rollback.js +119 -0
- package/dist/commands/samples.d.ts +2 -0
- package/dist/commands/samples.js +55 -0
- package/dist/core/config.d.ts +37 -0
- package/dist/core/config.js +47 -0
- package/dist/core/control-ui-db.d.ts +68 -0
- package/dist/core/control-ui-db.js +274 -0
- package/dist/core/detection-funnel.d.ts +1 -1
- package/dist/core/detection-funnel.js +4 -0
- package/dist/core/dictionary.d.ts +2 -0
- package/dist/core/dictionary.js +13 -0
- package/dist/core/event-log.d.ts +22 -1
- package/dist/core/event-log.js +319 -0
- package/dist/core/evolution-engine.d.ts +5 -5
- package/dist/core/evolution-engine.js +18 -18
- package/dist/core/evolution-migration.d.ts +5 -0
- package/dist/core/evolution-migration.js +65 -0
- package/dist/core/evolution-reducer.d.ts +69 -0
- package/dist/core/evolution-reducer.js +369 -0
- package/dist/core/evolution-types.d.ts +103 -0
- package/dist/core/focus-history.d.ts +65 -0
- package/dist/core/focus-history.js +266 -0
- package/dist/core/init.js +30 -7
- package/dist/core/migration.js +0 -2
- package/dist/core/path-resolver.d.ts +3 -0
- package/dist/core/path-resolver.js +90 -31
- package/dist/core/paths.d.ts +7 -8
- package/dist/core/paths.js +48 -40
- package/dist/core/profile.js +1 -1
- package/dist/core/session-tracker.d.ts +4 -0
- package/dist/core/session-tracker.js +15 -0
- package/dist/core/thinking-models.d.ts +38 -0
- package/dist/core/thinking-models.js +170 -0
- package/dist/core/trajectory.d.ts +184 -0
- package/dist/core/trajectory.js +817 -0
- package/dist/core/trust-engine.d.ts +2 -0
- package/dist/core/trust-engine.js +30 -4
- package/dist/core/workspace-context.d.ts +13 -0
- package/dist/core/workspace-context.js +50 -7
- package/dist/hooks/gate.js +301 -30
- package/dist/hooks/llm.d.ts +8 -0
- package/dist/hooks/llm.js +347 -69
- package/dist/hooks/message-sanitize.d.ts +3 -0
- package/dist/hooks/message-sanitize.js +37 -0
- package/dist/hooks/pain.js +105 -5
- package/dist/hooks/prompt.d.ts +20 -11
- package/dist/hooks/prompt.js +558 -158
- package/dist/hooks/subagent.d.ts +9 -2
- package/dist/hooks/subagent.js +40 -3
- package/dist/http/principles-console-route.d.ts +2 -0
- package/dist/http/principles-console-route.js +257 -0
- package/dist/i18n/commands.js +48 -20
- package/dist/index.js +264 -8
- package/dist/service/control-ui-query-service.d.ts +217 -0
- package/dist/service/control-ui-query-service.js +537 -0
- package/dist/service/empathy-observer-manager.d.ts +42 -0
- package/dist/service/empathy-observer-manager.js +147 -0
- package/dist/service/evolution-worker.d.ts +10 -0
- package/dist/service/evolution-worker.js +156 -24
- package/dist/service/trajectory-service.d.ts +2 -0
- package/dist/service/trajectory-service.js +15 -0
- package/dist/tools/agent-spawn.d.ts +27 -6
- package/dist/tools/agent-spawn.js +339 -87
- package/dist/tools/deep-reflect.d.ts +27 -7
- package/dist/tools/deep-reflect.js +282 -113
- package/dist/types/event-types.d.ts +84 -2
- package/dist/types/event-types.js +33 -0
- package/dist/types.d.ts +52 -0
- package/dist/types.js +24 -1
- package/openclaw.plugin.json +43 -11
- package/package.json +16 -6
- package/templates/langs/zh/core/HEARTBEAT.md +28 -4
- package/templates/langs/zh/skills/pd-daily/SKILL.md +97 -13
- package/templates/pain_settings.json +54 -2
- package/templates/workspace/.principles/PROFILE.json +2 -0
- package/templates/workspace/okr/CURRENT_FOCUS.md +57 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { defaultContextConfig } from '../types.js';
|
|
4
|
+
import { loadContextInjectionConfig } from '../hooks/prompt.js';
|
|
5
|
+
/**
|
|
6
|
+
* Get workspace directory from context
|
|
7
|
+
*/
|
|
8
|
+
function getWorkspaceDir(ctx) {
|
|
9
|
+
const workspaceDir = ctx.config?.workspaceDir || process.cwd();
|
|
10
|
+
if (!workspaceDir) {
|
|
11
|
+
throw new Error('[PD:Context] workspaceDir is required but not provided');
|
|
12
|
+
}
|
|
13
|
+
return workspaceDir;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Save context injection config to PROFILE.json
|
|
17
|
+
*/
|
|
18
|
+
function saveConfig(workspaceDir, config) {
|
|
19
|
+
const profilePath = path.join(workspaceDir, '.principles', 'PROFILE.json');
|
|
20
|
+
try {
|
|
21
|
+
// Ensure directory exists
|
|
22
|
+
const dir = path.dirname(profilePath);
|
|
23
|
+
if (!fs.existsSync(dir)) {
|
|
24
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
// Load existing profile or create new one
|
|
27
|
+
let profile = {};
|
|
28
|
+
if (fs.existsSync(profilePath)) {
|
|
29
|
+
const raw = fs.readFileSync(profilePath, 'utf-8');
|
|
30
|
+
profile = JSON.parse(raw);
|
|
31
|
+
}
|
|
32
|
+
// Update contextInjection
|
|
33
|
+
profile.contextInjection = config;
|
|
34
|
+
// Write back
|
|
35
|
+
fs.writeFileSync(profilePath, JSON.stringify(profile, null, 2), 'utf-8');
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.error(`[PD:Context] Failed to save config: ${String(e)}`);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Format project focus value for display
|
|
45
|
+
*/
|
|
46
|
+
function formatProjectFocus(value, isZh) {
|
|
47
|
+
const labels = {
|
|
48
|
+
full: { zh: '๐ฆ ๅฎๆด', en: '๐ฆ Full' },
|
|
49
|
+
summary: { zh: '๐ ๆ่ฆ', en: '๐ Summary' },
|
|
50
|
+
off: { zh: 'โ ๅ
ณ้ญ', en: 'โ Off' }
|
|
51
|
+
};
|
|
52
|
+
return labels[value][isZh ? 'zh' : 'en'];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Show current context injection status
|
|
56
|
+
*/
|
|
57
|
+
function showStatus(workspaceDir, isZh) {
|
|
58
|
+
const config = loadContextInjectionConfig(workspaceDir);
|
|
59
|
+
if (isZh) {
|
|
60
|
+
return `
|
|
61
|
+
๐ **ไธไธๆๆณจๅ
ฅ็ถๆ**
|
|
62
|
+
|
|
63
|
+
| ๅ
ๅฎน | ็ถๆ | ่ฏดๆ |
|
|
64
|
+
|------|------|------|
|
|
65
|
+
| ๆ ธๅฟๅๅ | โ
ๅง็ปๅผๅฏ | ไธๅฏๅ
ณ้ญ |
|
|
66
|
+
| ๆ็ปดๆจกๅ | ${config.thinkingOs ? 'โ
ๅผๅฏ' : 'โ ๅ
ณ้ญ'} | /pd-context thinking on/off |
|
|
67
|
+
| ไฟกไปปๅๆฐ | ${config.trustScore ? 'โ
ๅผๅฏ' : 'โ ๅ
ณ้ญ'} | /pd-context trust on/off |
|
|
68
|
+
| ๅๆๆฅๅฟ | ${config.reflectionLog ? 'โ
ๅผๅฏ' : 'โ ๅ
ณ้ญ'} | /pd-context reflection on/off |
|
|
69
|
+
| ้กน็ฎไธไธๆ | ${formatProjectFocus(config.projectFocus, isZh)} | /pd-context focus full/summary/off |
|
|
70
|
+
|
|
71
|
+
๐ก ่พๅ
ฅ \`/pd-context help\` ๆฅ็ๆดๅค้้กน
|
|
72
|
+
`.trim();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return `
|
|
76
|
+
๐ **Context Injection Status**
|
|
77
|
+
|
|
78
|
+
| Content | Status | Control |
|
|
79
|
+
|---------|--------|---------|
|
|
80
|
+
| Core Principles | โ
Always ON | Not configurable |
|
|
81
|
+
| Thinking OS | ${config.thinkingOs ? 'โ
ON' : 'โ OFF'} | /pd-context thinking on/off |
|
|
82
|
+
| Trust Score | ${config.trustScore ? 'โ
ON' : 'โ OFF'} | /pd-context trust on/off |
|
|
83
|
+
| Reflection Log | ${config.reflectionLog ? 'โ
ON' : 'โ OFF'} | /pd-context reflection on/off |
|
|
84
|
+
| Project Context | ${formatProjectFocus(config.projectFocus, isZh)} | /pd-context focus full/summary/off |
|
|
85
|
+
|
|
86
|
+
๐ก Type \`/pd-context help\` for more options
|
|
87
|
+
`.trim();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Toggle a boolean setting
|
|
92
|
+
*/
|
|
93
|
+
function toggleSetting(workspaceDir, key, value, isZh) {
|
|
94
|
+
const config = loadContextInjectionConfig(workspaceDir);
|
|
95
|
+
const oldValue = config[key];
|
|
96
|
+
if (value === 'on') {
|
|
97
|
+
config[key] = true;
|
|
98
|
+
}
|
|
99
|
+
else if (value === 'off') {
|
|
100
|
+
config[key] = false;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return isZh
|
|
104
|
+
? `โ ๆ ๆๅผ: "${value}"ใไฝฟ็จ "on" ๆ "off"ใ`
|
|
105
|
+
: `โ Invalid value: "${value}". Use "on" or "off".`;
|
|
106
|
+
}
|
|
107
|
+
const newValue = config[key];
|
|
108
|
+
const keyName = isZh
|
|
109
|
+
? { thinkingOs: 'ๆ็ปดๆจกๅ', trustScore: 'ไฟกไปปๅๆฐ', reflectionLog: 'ๅๆๆฅๅฟ' }[key]
|
|
110
|
+
: key;
|
|
111
|
+
// No change needed
|
|
112
|
+
if (oldValue === newValue) {
|
|
113
|
+
return isZh
|
|
114
|
+
? `โน๏ธ ${keyName} ๅทฒ็ปๆฏ ${newValue ? 'ๅผๅฏ' : 'ๅ
ณ้ญ'} ็ถๆ`
|
|
115
|
+
: `โน๏ธ ${keyName} is already ${newValue ? 'ON' : 'OFF'}`;
|
|
116
|
+
}
|
|
117
|
+
if (saveConfig(workspaceDir, config)) {
|
|
118
|
+
// Verify the save by re-reading
|
|
119
|
+
const verifyConfig = loadContextInjectionConfig(workspaceDir);
|
|
120
|
+
const verifyValue = verifyConfig[key];
|
|
121
|
+
if (verifyValue !== newValue) {
|
|
122
|
+
return isZh
|
|
123
|
+
? `โ ๏ธ ${keyName} ไฟๅญๅ้ช่ฏๅคฑ่ดฅ๏ผ่ฏท้่ฏ`
|
|
124
|
+
: `โ ๏ธ ${keyName} verification failed after save, please retry`;
|
|
125
|
+
}
|
|
126
|
+
const arrow = isZh ? 'โ' : 'โ';
|
|
127
|
+
const oldLabel = oldValue ? (isZh ? 'ๅผๅฏ' : 'ON') : (isZh ? 'ๅ
ณ้ญ' : 'OFF');
|
|
128
|
+
const newLabel = newValue ? (isZh ? 'ๅผๅฏ' : 'ON') : (isZh ? 'ๅ
ณ้ญ' : 'OFF');
|
|
129
|
+
return isZh
|
|
130
|
+
? `โ
${keyName} ๅทฒๆดๆฐ: ${oldLabel} ${arrow} ${newLabel}\n\n๐ก ไธๆฌกๅฏน่ฏๆถ็ๆ`
|
|
131
|
+
: `โ
${keyName} updated: ${oldLabel} ${arrow} ${newLabel}\n\n๐ก Takes effect on next turn`;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
return isZh
|
|
135
|
+
? `โ ไฟๅญ้
็ฝฎๅคฑ่ดฅ`
|
|
136
|
+
: `โ Failed to save configuration`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Set project focus mode
|
|
141
|
+
*/
|
|
142
|
+
function setProjectFocus(workspaceDir, value, isZh) {
|
|
143
|
+
const config = loadContextInjectionConfig(workspaceDir);
|
|
144
|
+
const oldValue = config.projectFocus;
|
|
145
|
+
const validModes = ['full', 'summary', 'off'];
|
|
146
|
+
if (!validModes.includes(value)) {
|
|
147
|
+
return isZh
|
|
148
|
+
? `โ ๆ ๆๅผ: "${value}"ใไฝฟ็จ "full"ใ"summary" ๆ "off"ใ`
|
|
149
|
+
: `โ Invalid value: "${value}". Use "full", "summary", or "off".`;
|
|
150
|
+
}
|
|
151
|
+
const newValue = value;
|
|
152
|
+
config.projectFocus = newValue;
|
|
153
|
+
// No change needed
|
|
154
|
+
if (oldValue === newValue) {
|
|
155
|
+
return isZh
|
|
156
|
+
? `โน๏ธ ้กน็ฎไธไธๆๅทฒ็ปๆฏ ${formatProjectFocus(newValue, isZh)} ็ถๆ`
|
|
157
|
+
: `โน๏ธ Project context is already ${formatProjectFocus(newValue, isZh)}`;
|
|
158
|
+
}
|
|
159
|
+
if (saveConfig(workspaceDir, config)) {
|
|
160
|
+
// Verify the save by re-reading
|
|
161
|
+
const verifyConfig = loadContextInjectionConfig(workspaceDir);
|
|
162
|
+
if (verifyConfig.projectFocus !== newValue) {
|
|
163
|
+
return isZh
|
|
164
|
+
? `โ ๏ธ ้กน็ฎไธไธๆไฟๅญๅ้ช่ฏๅคฑ่ดฅ๏ผ่ฏท้่ฏ`
|
|
165
|
+
: `โ ๏ธ Project context verification failed after save, please retry`;
|
|
166
|
+
}
|
|
167
|
+
const arrow = 'โ';
|
|
168
|
+
return isZh
|
|
169
|
+
? `โ
้กน็ฎไธไธๆๅทฒๆดๆฐ: ${formatProjectFocus(oldValue, isZh)} ${arrow} ${formatProjectFocus(newValue, isZh)}\n\n๐ก ไธๆฌกๅฏน่ฏๆถ็ๆ`
|
|
170
|
+
: `โ
Project context updated: ${formatProjectFocus(oldValue, isZh)} ${arrow} ${formatProjectFocus(newValue, isZh)}\n\n๐ก Takes effect on next turn`;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
return isZh
|
|
174
|
+
? `โ ไฟๅญ้
็ฝฎๅคฑ่ดฅ`
|
|
175
|
+
: `โ Failed to save configuration`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Apply a preset configuration
|
|
180
|
+
*/
|
|
181
|
+
function applyPreset(workspaceDir, preset, isZh) {
|
|
182
|
+
let config;
|
|
183
|
+
switch (preset) {
|
|
184
|
+
case 'minimal':
|
|
185
|
+
config = {
|
|
186
|
+
thinkingOs: false,
|
|
187
|
+
trustScore: true,
|
|
188
|
+
reflectionLog: false,
|
|
189
|
+
projectFocus: 'off',
|
|
190
|
+
evolutionContext: { ...defaultContextConfig.evolutionContext }
|
|
191
|
+
};
|
|
192
|
+
break;
|
|
193
|
+
case 'standard':
|
|
194
|
+
config = {
|
|
195
|
+
thinkingOs: true,
|
|
196
|
+
trustScore: true,
|
|
197
|
+
reflectionLog: false,
|
|
198
|
+
projectFocus: 'off',
|
|
199
|
+
evolutionContext: { ...defaultContextConfig.evolutionContext }
|
|
200
|
+
};
|
|
201
|
+
break;
|
|
202
|
+
case 'full':
|
|
203
|
+
config = {
|
|
204
|
+
thinkingOs: true,
|
|
205
|
+
trustScore: true,
|
|
206
|
+
reflectionLog: true,
|
|
207
|
+
projectFocus: 'summary',
|
|
208
|
+
evolutionContext: { ...defaultContextConfig.evolutionContext }
|
|
209
|
+
};
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
if (saveConfig(workspaceDir, config)) {
|
|
213
|
+
const presetName = isZh
|
|
214
|
+
? { minimal: 'ๆๅฐๆจกๅผ', standard: 'ๆ ๅๆจกๅผ', full: 'ๅฎๆดๆจกๅผ' }[preset]
|
|
215
|
+
: `${preset} mode`;
|
|
216
|
+
return isZh
|
|
217
|
+
? `โ
ๅทฒๅบ็จ้ข่ฎพ: ${presetName}\n\n${showStatus(workspaceDir, isZh)}`
|
|
218
|
+
: `โ
Applied preset: ${presetName}\n\n${showStatus(workspaceDir, isZh)}`;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
return isZh
|
|
222
|
+
? `โ ไฟๅญ้
็ฝฎๅคฑ่ดฅ`
|
|
223
|
+
: `โ Failed to save configuration`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Show help message
|
|
228
|
+
*/
|
|
229
|
+
function showHelp(isZh) {
|
|
230
|
+
if (isZh) {
|
|
231
|
+
return `
|
|
232
|
+
๐ **/pd-context ๅฝไปคๅธฎๅฉ**
|
|
233
|
+
|
|
234
|
+
**ๆฅ็็ถๆ**:
|
|
235
|
+
\`/pd-context status\` - ๆพ็คบๅฝๅไธไธๆๆณจๅ
ฅ็ถๆ
|
|
236
|
+
|
|
237
|
+
**ๅ้กนๆงๅถ**:
|
|
238
|
+
\`/pd-context thinking on/off\` - ๅผๅ
ณๆ็ปดๆจกๅ
|
|
239
|
+
\`/pd-context trust on/off\` - ๅผๅ
ณไฟกไปปๅๆฐ
|
|
240
|
+
\`/pd-context reflection on/off\` - ๅผๅ
ณๅๆๆฅๅฟ
|
|
241
|
+
\`/pd-context focus full/summary/off\` - ่ฎพ็ฝฎ้กน็ฎไธไธๆๆจกๅผ
|
|
242
|
+
|
|
243
|
+
**้ข่ฎพๆจกๅผ**:
|
|
244
|
+
\`/pd-context minimal\` - ๆๅฐๆจกๅผ๏ผไป
ไฟกไปปๅๆฐ๏ผ
|
|
245
|
+
\`/pd-context standard\` - ๆ ๅๆจกๅผ๏ผๅๅ+ๆ็ปดๆจกๅ+ไฟกไปปๅๆฐ๏ผ
|
|
246
|
+
\`/pd-context full\` - ๅฎๆดๆจกๅผ๏ผๅ
จ้จๅผๅฏ๏ผ
|
|
247
|
+
|
|
248
|
+
**ๆณจๆ**: ๆ ธๅฟๅๅๅง็ปๆณจๅ
ฅ๏ผไธๅฏๅ
ณ้ญใ
|
|
249
|
+
`.trim();
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
return `
|
|
253
|
+
๐ **/pd-context Command Help**
|
|
254
|
+
|
|
255
|
+
**View Status**:
|
|
256
|
+
\`/pd-context status\` - Show current context injection status
|
|
257
|
+
|
|
258
|
+
**Individual Control**:
|
|
259
|
+
\`/pd-context thinking on/off\` - Toggle Thinking OS
|
|
260
|
+
\`/pd-context trust on/off\` - Toggle Trust Score
|
|
261
|
+
\`/pd-context reflection on/off\` - Toggle Reflection Log
|
|
262
|
+
\`/pd-context focus full/summary/off\` - Set Project Context mode
|
|
263
|
+
|
|
264
|
+
**Presets**:
|
|
265
|
+
\`/pd-context minimal\` - Minimal mode (trust score only)
|
|
266
|
+
\`/pd-context standard\` - Standard mode (principles + thinking + trust)
|
|
267
|
+
\`/pd-context full\` - Full mode (all enabled)
|
|
268
|
+
|
|
269
|
+
**Note**: Core Principles are always injected and cannot be disabled.
|
|
270
|
+
`.trim();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Main command handler
|
|
275
|
+
*/
|
|
276
|
+
export function handleContextCommand(ctx) {
|
|
277
|
+
const workspaceDir = getWorkspaceDir(ctx);
|
|
278
|
+
const args = (ctx.args || '').trim().split(/\s+/);
|
|
279
|
+
const subCommand = args[0]?.toLowerCase() || 'status';
|
|
280
|
+
const value = args[1]?.toLowerCase() || '';
|
|
281
|
+
// Detect language from context
|
|
282
|
+
const isZh = ctx.config?.language === 'zh';
|
|
283
|
+
let result;
|
|
284
|
+
switch (subCommand) {
|
|
285
|
+
case 'status':
|
|
286
|
+
result = showStatus(workspaceDir, isZh);
|
|
287
|
+
break;
|
|
288
|
+
case 'thinking':
|
|
289
|
+
result = toggleSetting(workspaceDir, 'thinkingOs', value, isZh);
|
|
290
|
+
break;
|
|
291
|
+
case 'trust':
|
|
292
|
+
result = toggleSetting(workspaceDir, 'trustScore', value, isZh);
|
|
293
|
+
break;
|
|
294
|
+
case 'reflection':
|
|
295
|
+
result = toggleSetting(workspaceDir, 'reflectionLog', value, isZh);
|
|
296
|
+
break;
|
|
297
|
+
case 'focus':
|
|
298
|
+
result = setProjectFocus(workspaceDir, value, isZh);
|
|
299
|
+
break;
|
|
300
|
+
case 'minimal':
|
|
301
|
+
case 'standard':
|
|
302
|
+
case 'full':
|
|
303
|
+
result = applyPreset(workspaceDir, subCommand, isZh);
|
|
304
|
+
break;
|
|
305
|
+
case 'help':
|
|
306
|
+
result = showHelp(isZh);
|
|
307
|
+
break;
|
|
308
|
+
default:
|
|
309
|
+
result = showHelp(isZh);
|
|
310
|
+
}
|
|
311
|
+
return { text: result };
|
|
312
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { EvolutionReducerImpl } from '../core/evolution-reducer.js';
|
|
2
|
+
import { normalizeLanguage } from '../i18n/commands.js';
|
|
3
|
+
import { getAgentScorecard } from '../core/trust-engine.js';
|
|
4
|
+
import { EventLogService } from '../core/event-log.js';
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
function getQueueStats(workspaceDir) {
|
|
8
|
+
const stateDir = path.join(workspaceDir, '.state', 'principles');
|
|
9
|
+
const queuePath = path.join(stateDir, 'evolution_queue.json');
|
|
10
|
+
let pending = 0;
|
|
11
|
+
let completed = 0;
|
|
12
|
+
let inProgress = 0;
|
|
13
|
+
try {
|
|
14
|
+
if (fs.existsSync(queuePath)) {
|
|
15
|
+
const queue = JSON.parse(fs.readFileSync(queuePath, 'utf-8'));
|
|
16
|
+
for (const item of queue) {
|
|
17
|
+
if (item.status === 'completed') {
|
|
18
|
+
completed++;
|
|
19
|
+
}
|
|
20
|
+
else if (item.status === 'in_progress') {
|
|
21
|
+
inProgress++;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
pending++;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Ignore errors, return zeros
|
|
31
|
+
}
|
|
32
|
+
return { pending, completed, inProgress };
|
|
33
|
+
}
|
|
34
|
+
function getCurrentPain(workspaceDir) {
|
|
35
|
+
const stateDir = path.join(workspaceDir, '.state', 'principles');
|
|
36
|
+
const painFlagPath = path.join(stateDir, '.pain_flag');
|
|
37
|
+
try {
|
|
38
|
+
if (fs.existsSync(painFlagPath)) {
|
|
39
|
+
const data = JSON.parse(fs.readFileSync(painFlagPath, 'utf-8'));
|
|
40
|
+
return {
|
|
41
|
+
painScore: data.score || 0,
|
|
42
|
+
painSource: data.source || 'none'
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Ignore errors
|
|
48
|
+
}
|
|
49
|
+
return { painScore: 0, painSource: 'none' };
|
|
50
|
+
}
|
|
51
|
+
export function handleEvolutionStatusCommand(ctx) {
|
|
52
|
+
const workspaceDir = ctx.config?.workspaceDir || process.cwd();
|
|
53
|
+
const reducer = new EvolutionReducerImpl({ workspaceDir });
|
|
54
|
+
const stats = reducer.getStats();
|
|
55
|
+
// Get Trust Score
|
|
56
|
+
let trustScore = 0;
|
|
57
|
+
let trustStage = 1;
|
|
58
|
+
try {
|
|
59
|
+
const scorecard = getAgentScorecard(workspaceDir);
|
|
60
|
+
trustScore = scorecard.trust_score ?? 0;
|
|
61
|
+
trustStage = trustScore >= 80 ? 4 : trustScore >= 60 ? 3 : trustScore >= 30 ? 2 : 1;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Ignore errors, use defaults
|
|
65
|
+
}
|
|
66
|
+
// Get EventLog for GFI and Pain stats
|
|
67
|
+
let gfiPeak = 0;
|
|
68
|
+
let painSignals = 0;
|
|
69
|
+
try {
|
|
70
|
+
const stateDir = path.join(workspaceDir, '.state', 'principles');
|
|
71
|
+
const eventLog = EventLogService.get(stateDir);
|
|
72
|
+
const today = new Date().toISOString().split('T')[0];
|
|
73
|
+
const dailyStats = eventLog.getDailyStats(today);
|
|
74
|
+
gfiPeak = dailyStats.gfi?.peak ?? 0;
|
|
75
|
+
painSignals = dailyStats.pain?.signalsDetected ?? 0;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Ignore errors, use defaults
|
|
79
|
+
}
|
|
80
|
+
// Get Queue Stats
|
|
81
|
+
const queueStats = getQueueStats(workspaceDir);
|
|
82
|
+
// Get Current Pain
|
|
83
|
+
const currentPain = getCurrentPain(workspaceDir);
|
|
84
|
+
// Determine language - handle both 'zh' and 'zh-CN' formats
|
|
85
|
+
const rawLang = ctx.config?.language || 'en';
|
|
86
|
+
const lang = normalizeLanguage(rawLang);
|
|
87
|
+
if (lang === 'zh') {
|
|
88
|
+
const lines = [
|
|
89
|
+
'๐ Evolution ็ถๆ',
|
|
90
|
+
'โโโโโโโโโโโโโโโโโโโโโโโโโโโโ',
|
|
91
|
+
'',
|
|
92
|
+
`๐ก๏ธ Trust Score: ${trustScore}/100 (Stage ${trustStage})`,
|
|
93
|
+
`๐ด GFI Peak: ${gfiPeak.toFixed(1)}`,
|
|
94
|
+
`โก Current Pain: ${currentPain.painScore} pts (${currentPain.painSource})`,
|
|
95
|
+
`๐ Pain Signals Today: ${painSignals}`,
|
|
96
|
+
'',
|
|
97
|
+
'๐ Evolution Rules',
|
|
98
|
+
'โโโโโโโโโโโโโโโโโโโโโโโโโโโโ',
|
|
99
|
+
`- ๅ้ๅๅ: ${stats.candidateCount}`,
|
|
100
|
+
`- ่งๅฏๆๅๅ: ${stats.probationCount}`,
|
|
101
|
+
`- ็ๆๅๅ: ${stats.activeCount}`,
|
|
102
|
+
`- ๅทฒๅบๅผๅๅ: ${stats.deprecatedCount}`,
|
|
103
|
+
`- ๆ่ฟๆๅๆถ้ด: ${stats.lastPromotedAt ?? 'ๆ '}`,
|
|
104
|
+
'',
|
|
105
|
+
'๐ Evolution Queue',
|
|
106
|
+
'โโโโโโโโโโโโโโโโโโโโโโโโโโโโ',
|
|
107
|
+
`- ๅพ
ๅค็: ${queueStats.pending} ้กน`,
|
|
108
|
+
`- ่ฟ่กไธญ: ${queueStats.inProgress} ้กน`,
|
|
109
|
+
`- ๅทฒๅฎๆ: ${queueStats.completed} ้กน`,
|
|
110
|
+
];
|
|
111
|
+
return { text: lines.join('\n') };
|
|
112
|
+
}
|
|
113
|
+
// English
|
|
114
|
+
const lines = [
|
|
115
|
+
'๐ Evolution Status',
|
|
116
|
+
'โโโโโโโโโโโโโโโโโโโโโโโโโโโโ',
|
|
117
|
+
'',
|
|
118
|
+
`๐ก๏ธ Trust Score: ${trustScore}/100 (Stage ${trustStage})`,
|
|
119
|
+
`๐ด GFI Peak: ${gfiPeak.toFixed(1)}`,
|
|
120
|
+
`โก Current Pain: ${currentPain.painScore} pts (${currentPain.painSource})`,
|
|
121
|
+
`๐ Pain Signals Today: ${painSignals}`,
|
|
122
|
+
'',
|
|
123
|
+
'๐ Evolution Rules',
|
|
124
|
+
'โโโโโโโโโโโโโโโโโโโโโโโโโโโโ',
|
|
125
|
+
`- candidate principles: ${stats.candidateCount}`,
|
|
126
|
+
`- probation principles: ${stats.probationCount}`,
|
|
127
|
+
`- active principles: ${stats.activeCount}`,
|
|
128
|
+
`- deprecated principles: ${stats.deprecatedCount}`,
|
|
129
|
+
`- last promoted: ${stats.lastPromotedAt ?? 'none'}`,
|
|
130
|
+
'',
|
|
131
|
+
'๐ Evolution Queue',
|
|
132
|
+
'โโโโโโโโโโโโโโโโโโโโโโโโโโโโ',
|
|
133
|
+
`- Pending: ${queueStats.pending}`,
|
|
134
|
+
`- In Progress: ${queueStats.inProgress}`,
|
|
135
|
+
`- Completed: ${queueStats.completed}`,
|
|
136
|
+
];
|
|
137
|
+
return { text: lines.join('\n') };
|
|
138
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { WorkspaceContext } from '../core/workspace-context.js';
|
|
2
|
+
function isZh(ctx) {
|
|
3
|
+
return String(ctx.config?.language || 'en').startsWith('zh');
|
|
4
|
+
}
|
|
5
|
+
export function handleExportCommand(ctx) {
|
|
6
|
+
const workspaceDir = ctx.config?.workspaceDir || process.cwd();
|
|
7
|
+
const zh = isZh(ctx);
|
|
8
|
+
const args = (ctx.args || '').trim();
|
|
9
|
+
const [subcommand = 'corrections'] = args.split(/\s+/).filter(Boolean);
|
|
10
|
+
const wctx = WorkspaceContext.fromHookContext({ workspaceDir, ...ctx.config });
|
|
11
|
+
if (subcommand !== 'analytics' && subcommand !== 'corrections') {
|
|
12
|
+
return {
|
|
13
|
+
text: zh
|
|
14
|
+
? 'ๆ ๆ็ๅฏผๅบ็ฑปๅใ่ฏทไฝฟ็จ `analytics` ๆ `corrections [--redacted]`ใ'
|
|
15
|
+
: 'Invalid export target. Use `analytics` or `corrections [--redacted]`.',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
if (subcommand === 'analytics') {
|
|
20
|
+
const result = wctx.trajectory.exportAnalytics();
|
|
21
|
+
return {
|
|
22
|
+
text: zh
|
|
23
|
+
? `ๅทฒๅฏผๅบ analytics ๅฟซ็
งๅฐ ${result.filePath}๏ผๅ
ฑ ${result.count} ๆก่ๅ่ฎฐๅฝใ`
|
|
24
|
+
: `Exported analytics snapshot to ${result.filePath} (${result.count} aggregated rows).`,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const redacted = args.includes('--redacted');
|
|
28
|
+
const result = wctx.trajectory.exportCorrections({
|
|
29
|
+
mode: redacted ? 'redacted' : 'raw',
|
|
30
|
+
approvedOnly: true,
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
text: zh
|
|
34
|
+
? `ๅทฒๅฏผๅบ็บ ้ๆ ทๆฌๅฐ ${result.filePath}๏ผๆจกๅผ ${result.mode}๏ผๅ
ฑ ${result.count} ๆกใ`
|
|
35
|
+
: `Exported correction samples to ${result.filePath} (mode=${result.mode}, count=${result.count}).`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return {
|
|
40
|
+
text: zh
|
|
41
|
+
? 'ๅฏผๅบๅคฑ่ดฅ๏ผ่ฏทๆฃๆฅๆฅๅฟใ'
|
|
42
|
+
: 'Export failed. Check logs.',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /pd-focus ๅฝไปค - ็ฎก็ CURRENT_FOCUS.md
|
|
3
|
+
*
|
|
4
|
+
* ๅ่ฝ๏ผ
|
|
5
|
+
* - status: ๆฅ็ๅฝๅ็ถๆๅๅๅฒ็ๆฌ
|
|
6
|
+
* - compress: ๆๅจๅ็ผฉๅนถๅคไปฝ
|
|
7
|
+
* - history: ๆฅ็ๅๅฒ็ๆฌๅ่กจ
|
|
8
|
+
* - rollback: ๅๆปๅฐๆๅฎๅๅฒ็ๆฌ
|
|
9
|
+
*/
|
|
10
|
+
import type { PluginCommandContext, PluginCommandResult, OpenClawPluginApi } from '../openclaw-sdk.js';
|
|
11
|
+
/**
|
|
12
|
+
* ๅค็ /pd-focus ๅฝไปค
|
|
13
|
+
*/
|
|
14
|
+
export declare function handleFocusCommand(ctx: PluginCommandContext, api: OpenClawPluginApi): Promise<PluginCommandResult>;
|