skill-auto-loader-hook-paperfly777 0.1.4 → 0.1.5
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/index.ts +26 -11
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -129,20 +129,40 @@ function extractLatestUserText(event: unknown): string {
|
|
|
129
129
|
}
|
|
130
130
|
const content = extractTextFromContent(msgObj.content);
|
|
131
131
|
if (content.trim()) {
|
|
132
|
-
return content.trim();
|
|
132
|
+
return sanitizeUserText(content.trim());
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
const fallbackPrompt = safeString(eventObj.userPrompt);
|
|
137
|
-
return fallbackPrompt.trim();
|
|
137
|
+
return sanitizeUserText(fallbackPrompt.trim());
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
//
|
|
141
|
-
|
|
140
|
+
// 清洗“最新用户消息”中的历史插件注入内容。
|
|
141
|
+
// 目标:只保留用户本次真实输入,不把旧注入块再次带进来。
|
|
142
|
+
function sanitizeUserText(text: string): string {
|
|
142
143
|
if (!text) {
|
|
143
|
-
return
|
|
144
|
+
return "";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let cleaned = text;
|
|
148
|
+
const markerIndex = cleaned.indexOf(INJECTION_MARKER);
|
|
149
|
+
if (markerIndex >= 0) {
|
|
150
|
+
cleaned = cleaned.slice(0, markerIndex);
|
|
144
151
|
}
|
|
145
|
-
|
|
152
|
+
|
|
153
|
+
cleaned = cleaned.replace(/\[?[A-Z][a-z]{2}\s+\d{4}-\d{2}-\d{2}.*?\]\s*/g, "");
|
|
154
|
+
|
|
155
|
+
const lines = cleaned
|
|
156
|
+
.split(/\r?\n/)
|
|
157
|
+
.map((line) => line.trim())
|
|
158
|
+
.filter(Boolean)
|
|
159
|
+
.filter((line) => !line.includes(INJECTION_MARKER));
|
|
160
|
+
|
|
161
|
+
if (lines.length === 0) {
|
|
162
|
+
return "";
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return lines[lines.length - 1];
|
|
146
166
|
}
|
|
147
167
|
|
|
148
168
|
// 从 openclaw.json 读取插件级配置(plugins.entries.<id>.config)
|
|
@@ -456,11 +476,6 @@ export default definePluginEntry({
|
|
|
456
476
|
if (!userText) {
|
|
457
477
|
return undefined;
|
|
458
478
|
}
|
|
459
|
-
// 若本轮文本已包含插件注入标记,直接跳过,避免循环注入。
|
|
460
|
-
if (isSelfInjectedText(userText)) {
|
|
461
|
-
api.logger?.debug?.("skill-auto-loader-hook: skip self-injected input");
|
|
462
|
-
return undefined;
|
|
463
|
-
}
|
|
464
479
|
|
|
465
480
|
// 步骤 3:扫描并收集可用 skill
|
|
466
481
|
const scanDirs =
|
package/package.json
CHANGED