skill-auto-loader-hook-paperfly777 0.1.5 → 0.1.7

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 (2) hide show
  1. package/index.ts +37 -9
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -5,7 +5,7 @@ import { definePluginEntry } from "openclaw/plugin-sdk/core";
5
5
 
6
6
  // 插件固定 ID:对应 openclaw.json 里的 plugins.entries.<id>
7
7
  const PLUGIN_ID = "skill-auto-loader-hook";
8
- const INJECTION_MARKER = "Skill Auto Loader Hook";
8
+ const XML_BLOCK_TAG = "skill-auto-loader-hook";
9
9
 
10
10
  type RoutingRule = {
11
11
  id: string;
@@ -129,7 +129,10 @@ function extractLatestUserText(event: unknown): string {
129
129
  }
130
130
  const content = extractTextFromContent(msgObj.content);
131
131
  if (content.trim()) {
132
- return sanitizeUserText(content.trim());
132
+ const sanitized = sanitizeUserText(content.trim());
133
+ if (sanitized) {
134
+ return sanitized;
135
+ }
133
136
  }
134
137
  }
135
138
 
@@ -137,6 +140,15 @@ function extractLatestUserText(event: unknown): string {
137
140
  return sanitizeUserText(fallbackPrompt.trim());
138
141
  }
139
142
 
143
+ // 删除历史插件注入的 XML 块,避免下轮继续把旧内容带进来。
144
+ function stripInjectedXmlBlocks(text: string): string {
145
+ if (!text) {
146
+ return "";
147
+ }
148
+ const blockPattern = new RegExp(`<${XML_BLOCK_TAG}>[\\s\\S]*?<\\/${XML_BLOCK_TAG}>`, "gi");
149
+ return text.replace(blockPattern, "").trim();
150
+ }
151
+
140
152
  // 清洗“最新用户消息”中的历史插件注入内容。
141
153
  // 目标:只保留用户本次真实输入,不把旧注入块再次带进来。
142
154
  function sanitizeUserText(text: string): string {
@@ -144,19 +156,23 @@ function sanitizeUserText(text: string): string {
144
156
  return "";
145
157
  }
146
158
 
147
- let cleaned = text;
148
- const markerIndex = cleaned.indexOf(INJECTION_MARKER);
149
- if (markerIndex >= 0) {
150
- cleaned = cleaned.slice(0, markerIndex);
151
- }
159
+ let cleaned = stripInjectedXmlBlocks(text);
152
160
 
161
+ // 去掉常见的 UI 时间包装。
153
162
  cleaned = cleaned.replace(/\[?[A-Z][a-z]{2}\s+\d{4}-\d{2}-\d{2}.*?\]\s*/g, "");
154
163
 
164
+ // 去掉插件固定说明段的高频前缀,避免它们继续污染本轮输入。
165
+ cleaned = cleaned.replace(/当前 OpenClaw 默认模型:.*$/gm, "");
166
+ cleaned = cleaned.replace(/本轮用户消息:.*$/gm, "");
167
+ cleaned = cleaned.replace(/请结合以下信息判断本轮是否需要优先使用某个 skill。*$/gm, "");
168
+ cleaned = cleaned.replace(/一、候选 skill(已过滤)[\s\S]*$/m, "");
169
+
155
170
  const lines = cleaned
156
171
  .split(/\r?\n/)
157
172
  .map((line) => line.trim())
158
173
  .filter(Boolean)
159
- .filter((line) => !line.includes(INJECTION_MARKER));
174
+ .filter((line) => !line.includes(`<${XML_BLOCK_TAG}>`))
175
+ .filter((line) => !line.includes(`</${XML_BLOCK_TAG}>`));
160
176
 
161
177
  if (lines.length === 0) {
162
178
  return "";
@@ -203,7 +219,17 @@ function getDefaultModelInfo(openclawConfigPath: string): string {
203
219
  const root = cfg as Record<string, unknown>;
204
220
  const directModel = safeString(root.model);
205
221
  const channelsModel = safeString((root.channels as Record<string, unknown> | undefined)?.model);
206
-
222
+ const agentsPrimaryModel = safeString(
223
+ ((root.agents as Record<string, unknown> | undefined)?.defaults as Record<string, unknown> | undefined)?.model &&
224
+ (((root.agents as Record<string, unknown> | undefined)?.defaults as Record<string, unknown> | undefined)?.model as Record<
225
+ string,
226
+ unknown
227
+ >)?.primary,
228
+ );
229
+
230
+ if (agentsPrimaryModel) {
231
+ return agentsPrimaryModel;
232
+ }
207
233
  if (directModel) {
208
234
  return directModel;
209
235
  }
@@ -427,6 +453,7 @@ function buildRoutingPrompt(
427
453
  routerCfg: RouterFileConfig,
428
454
  ): string {
429
455
  const lines: string[] = [];
456
+ lines.push(`<${XML_BLOCK_TAG}>`);
430
457
  lines.push("【Skill Auto Loader Hook】请在正式回答前,先完成本轮 skill 路由判断。");
431
458
  lines.push(`当前 OpenClaw 默认模型:${defaultModel}`);
432
459
  lines.push(`本轮用户消息:${userText}`);
@@ -448,6 +475,7 @@ function buildRoutingPrompt(
448
475
  lines.push("");
449
476
  lines.push("四、执行方式");
450
477
  lines.push("请把路由判断体现在你后续的实际执行中:若需要 skill,则优先按判断结果使用;若不需要,则正常回答。");
478
+ lines.push(`</${XML_BLOCK_TAG}>`);
451
479
  return lines.join("\n");
452
480
  }
453
481
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skill-auto-loader-hook-paperfly777",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "OpenClaw hook plugin that routes each user message to the most relevant installed skill.",
5
5
  "license": "MIT",
6
6
  "type": "module",