mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 10:10:22 +08:00
feat: 发布 1.1.3,提示词只注入一次并修复插件加载
This commit is contained in:
1 parent
8f860d4a53
commit
238b39b8ff
10 files changed
+434
-61
No files matched your search
@@ -0,0 +1,98 @@
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
existingSystemPrompt,
|
||||
isFirstConversationTurn,
|
||||
isMnemonPluginMessage,
|
||||
promptAlreadyInjected,
|
||||
rewritePromptAssembly,
|
||||
shouldInjectPrompt,
|
||||
} from "../lib/identity.js";
|
||||
|
||||
const inject = "You are Little Code Sauce. This is the operator prompt.";
|
||||
|
||||
assert.equal(isFirstConversationTurn({ messages: [{ role: "user", text: "hi" }] }), true);
|
||||
assert.equal(
|
||||
isFirstConversationTurn({
|
||||
messages: [
|
||||
{ role: "user", text: "hi" },
|
||||
{ role: "assistant", text: "ok" },
|
||||
{ role: "user", text: "again" },
|
||||
],
|
||||
}),
|
||||
false,
|
||||
);
|
||||
assert.equal(isFirstConversationTurn({ agent: { session: { events: [] } } }), true);
|
||||
assert.equal(
|
||||
isFirstConversationTurn({
|
||||
agent: { session: { events: [{ type: "turn/end", data: { turn: 1 } }] } },
|
||||
}),
|
||||
false,
|
||||
);
|
||||
assert.equal(shouldInjectPrompt({ turn: 1 }, true, inject), true);
|
||||
assert.equal(
|
||||
shouldInjectPrompt(
|
||||
{
|
||||
agent: {
|
||||
session: {
|
||||
events: [
|
||||
{ type: "system/message", data: { message: { content: [{ type: "text", text: inject }] } } },
|
||||
{ type: "turn/end", data: { turn: 1 } },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
true,
|
||||
inject,
|
||||
),
|
||||
false,
|
||||
);
|
||||
assert.equal(shouldInjectPrompt({ turn: 2 }, false, inject), true);
|
||||
assert.equal(promptAlreadyInjected(inject + "\nWorking directory: x", inject), true);
|
||||
|
||||
const session = {
|
||||
events: [
|
||||
{ type: "system/message", data: { message: { content: [{ type: "text", text: "old" }] } } },
|
||||
{ type: "system/message", data: { message: { content: [{ type: "text", text: inject }] } } },
|
||||
],
|
||||
};
|
||||
assert.equal(existingSystemPrompt({ agent: { session } }), inject);
|
||||
assert.equal(
|
||||
isMnemonPluginMessage({ source: { kind: "plugin", plugin: "dsh-mnemon" } }),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
isMnemonPluginMessage({ source: { kind: "plugin", plugin: "@deepseek-ai/dsh-system-prompt" } }),
|
||||
false,
|
||||
);
|
||||
|
||||
const first = rewritePromptAssembly(
|
||||
{
|
||||
sections: [
|
||||
{ name: "deployment:persona-prefix", text: "Working directory: {{cwd}}." },
|
||||
{ name: "dsh-purge", text: inject },
|
||||
{ name: "dsh-purge:rules", text: "extra rule" },
|
||||
{ name: "dsh-mnemon", text: "old memory dump" },
|
||||
{ name: "mnemon:routing", text: "use memory tools" },
|
||||
],
|
||||
},
|
||||
{ fallbackInject: inject, dropMnemon: true, dropPurgeAfterFold: true },
|
||||
);
|
||||
const names = first.sections.map((s) => s.name);
|
||||
assert.equal(names.includes("dsh-purge"), false);
|
||||
assert.equal(names.some((n) => String(n).includes("mnemon")), false);
|
||||
assert.equal(first.sections.filter((s) => String(s.text || "").includes("Little Code Sauce")).length, 1);
|
||||
assert.equal(first.sections.some((s) => s.name === "dsh-purge:rules"), true);
|
||||
|
||||
const later = rewritePromptAssembly(
|
||||
{
|
||||
sections: [
|
||||
{ name: "deployment:persona-prefix", text: "Working directory: {{cwd}}." },
|
||||
{ name: "dsh-purge", text: inject },
|
||||
{ name: "dsh-mnemon", text: "old memory dump" },
|
||||
],
|
||||
},
|
||||
{ fallbackInject: "", dropMnemon: true, dropPurgeAfterFold: true, pinPersonaText: inject },
|
||||
);
|
||||
assert.deepEqual(later.sections, [{ name: "deployment:persona-prefix", text: inject }]);
|
||||
|
||||
console.log("identity-inject-once ok");
|
||||
@@ -0,0 +1,29 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { lastHumanUserText } from "../lib/rewind.js";
|
||||
|
||||
const events = [
|
||||
{ type: "turn/start", seq: 1 },
|
||||
{
|
||||
type: "user/message",
|
||||
seq: 2,
|
||||
data: { content: [{ type: "text", text: "first" }], source: { kind: "user" } },
|
||||
},
|
||||
{ type: "turn/end", seq: 3 },
|
||||
{ type: "turn/start", seq: 4 },
|
||||
{
|
||||
type: "user/message",
|
||||
seq: 5,
|
||||
data: { content: [{ type: "text", text: "second" }], source: { kind: "user" } },
|
||||
},
|
||||
{
|
||||
type: "user/message",
|
||||
seq: 6,
|
||||
data: { content: [{ type: "text", text: "[MNEMON] skip" }], source: { kind: "plugin", plugin: "dsh-mnemon" } },
|
||||
},
|
||||
];
|
||||
|
||||
assert.equal(lastHumanUserText(events), "second");
|
||||
assert.equal(lastHumanUserText([]), "");
|
||||
assert.equal(lastHumanUserText(null), "");
|
||||
|
||||
console.log("rewind-last-user ok");
|
||||
Reference in new issue
Block a user