@ynhcj/xiaoyi-channel 0.0.206-next → 0.0.207-next
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/index.js +40 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14,6 +14,17 @@ import { registerCLIHook } from "./src/tools/hmos-cli.js";
|
|
|
14
14
|
import { writeSkillUsage } from "./src/utils/skills-logger.js";
|
|
15
15
|
import { getSteerQueue } from "./src/steer-queue.js";
|
|
16
16
|
import { logger } from "./src/utils/logger.js";
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
// Diagnostic: write marker file to confirm hook fires
|
|
20
|
+
function touchHookMarker(label) {
|
|
21
|
+
try {
|
|
22
|
+
const dir = "/tmp/xy-steer-diag";
|
|
23
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
24
|
+
fs.writeFileSync(path.join(dir, `${Date.now()}_${label}.txt`), `${new Date().toISOString()} ${label}\n`);
|
|
25
|
+
}
|
|
26
|
+
catch { }
|
|
27
|
+
}
|
|
17
28
|
/**
|
|
18
29
|
* Parse a file path string to detect if it refers to a SKILL.md file within
|
|
19
30
|
* a skills directory. Returns the skill name (parent directory) if so.
|
|
@@ -217,35 +228,41 @@ function registerFullHooks(api) {
|
|
|
217
228
|
envFilePath: "~/.openclaw/.xiaoyienv",
|
|
218
229
|
timeoutMs: pluginConfig.skillRetrieverTimeoutMs ?? 1000,
|
|
219
230
|
});
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
//
|
|
232
|
-
// appendContext places the steer after the current prompt context, so the
|
|
233
|
-
// model sees: [original context]\n\n用户追加诉求:<steer text>
|
|
234
|
-
//
|
|
235
|
-
// Key is deleted BEFORE splice to avoid a race.
|
|
236
|
-
api.on("before_prompt_build", async (_event, ctx) => {
|
|
231
|
+
const baseBeforePromptBuildHandler = createBeforePromptBuildHandler(skillRetrieverConfig);
|
|
232
|
+
// STEER INJECTION: merged into the before_prompt_build handler so it runs
|
|
233
|
+
// in the same hook registration call that we know already works (skill-retriever).
|
|
234
|
+
// This avoids any issues with separate api.on() registrations not being
|
|
235
|
+
// picked up by the global hook runner.
|
|
236
|
+
touchHookMarker("register_hook");
|
|
237
|
+
api.on("before_prompt_build", async (event, ctx) => {
|
|
238
|
+
touchHookMarker(`hook_fired_sessionId=${ctx.sessionId || "undefined"}`);
|
|
239
|
+
// Run skill-retriever first
|
|
240
|
+
const baseResult = await baseBeforePromptBuildHandler(event, ctx);
|
|
241
|
+
// Check for pending steer messages queued by bot.ts
|
|
237
242
|
const sessionId = ctx.sessionId;
|
|
238
243
|
if (!sessionId)
|
|
239
|
-
return;
|
|
244
|
+
return baseResult;
|
|
240
245
|
const queue = getSteerQueue();
|
|
241
246
|
const pending = queue.get(sessionId);
|
|
242
247
|
if (!pending || pending.length === 0)
|
|
243
|
-
return;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
return baseResult;
|
|
249
|
+
// Drain pending steer messages
|
|
250
|
+
queue.delete(sessionId);
|
|
251
|
+
const steerText = pending.splice(0).join("\n\n");
|
|
252
|
+
const steerAppend = `\n用户追加诉求:${steerText}`;
|
|
253
|
+
logger.log(`[STEER-HOOK] Injecting steer: sessionId=${sessionId} textLen=${steerText.length}`);
|
|
254
|
+
touchHookMarker(`steer_injected_sessionId=${sessionId}_len=${steerText.length}`);
|
|
255
|
+
// Merge steer appendContext with skill-retriever's result
|
|
256
|
+
const merged = { ...(baseResult ?? {}) };
|
|
257
|
+
if (merged.appendContext) {
|
|
258
|
+
merged.appendContext = `${merged.appendContext}\n\n${steerAppend}`;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
merged.appendContext = steerAppend;
|
|
262
|
+
}
|
|
263
|
+
return merged;
|
|
248
264
|
});
|
|
265
|
+
registerSelfEvolutionToolResultNudge(api);
|
|
249
266
|
}
|
|
250
267
|
const pluginEntry = definePluginEntry({
|
|
251
268
|
id: "xiaoyi-channel",
|