mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-30 11:50:23 +08:00
删除tests
This commit is contained in:
1 parent
f6d671763e
commit
6fe5d5dc01
7 files changed
+53
-220
No files matched your search
@@ -368,28 +368,33 @@ The **Rules** card appears on the dsh web settings page. Switch **Light / Ink**.
|
|||||||
|
|
||||||
```
|
```
|
||||||
dsh-purge/
|
dsh-purge/
|
||||||
├── lib/
|
|
||||||
│ ├── core.js # path detect, patches, backup/restore, shim, override file
|
|
||||||
│ ├── hide-console.js # Windows hide-console pin into bin.js
|
|
||||||
│ ├── identity.js # fold inject into persona-prefix; no identity card
|
|
||||||
│ ├── index.js # plugin: commands, tools, systemPrompt, HTTP
|
|
||||||
│ ├── rules.js
|
|
||||||
│ ├── restart-web.js
|
|
||||||
│ ├── uninstall.js # uninstall: restore patches, then remove the plugin
|
|
||||||
│ └── default-prompt-inject.md
|
|
||||||
├── client.js # settings UI
|
|
||||||
├── bin/dsh-purge.js
|
├── bin/dsh-purge.js
|
||||||
├── docs/
|
├── client.js
|
||||||
│ ├── banner.svg
|
|
||||||
│ ├── appreciate.png
|
|
||||||
│ └── preview/
|
|
||||||
│ ├── settings.png
|
|
||||||
│ └── rules.png
|
|
||||||
├── cordis.patch.yml
|
├── cordis.patch.yml
|
||||||
|
├── docs/
|
||||||
|
│ ├── appreciate.png
|
||||||
|
│ ├── banner.svg
|
||||||
|
│ └── preview/
|
||||||
|
│ ├── rules.png
|
||||||
|
│ └── settings.png
|
||||||
|
├── lib/
|
||||||
|
│ ├── child-process-hide.mjs
|
||||||
|
│ ├── core.js
|
||||||
|
│ ├── default-prompt-inject.md
|
||||||
|
│ ├── hide-console.js
|
||||||
|
│ ├── identity.js
|
||||||
|
│ ├── index.js
|
||||||
|
│ ├── restart-web.js
|
||||||
|
│ ├── rewind.js
|
||||||
|
│ ├── rules.js
|
||||||
|
│ ├── uninstall-restart.js
|
||||||
|
│ ├── uninstall.js
|
||||||
|
│ └── update.js
|
||||||
├── package.json
|
├── package.json
|
||||||
|
├── screenshots.json
|
||||||
|
├── LICENSE
|
||||||
├── README.md
|
├── README.md
|
||||||
├── README.zh-CN.md
|
└── README.zh-CN.md
|
||||||
└── LICENSE
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Runtime user files: `$DSH_HOME/prompt-inject.md`, `$DSH_HOME/rules/`. If `DSH_HOME` is unset, the launcher-adjacent `.dsh` wins over `~/.dsh`.
|
Runtime user files: `$DSH_HOME/prompt-inject.md`, `$DSH_HOME/rules/`. If `DSH_HOME` is unset, the launcher-adjacent `.dsh` wins over `~/.dsh`.
|
||||||
@@ -413,9 +418,10 @@ Runtime user files: `$DSH_HOME/prompt-inject.md`, `$DSH_HOME/rules/`. If `DSH_HO
|
|||||||
dsh-purge --status
|
dsh-purge --status
|
||||||
dsh-purge --apply
|
dsh-purge --apply
|
||||||
dsh-purge --revert
|
dsh-purge --revert
|
||||||
|
dsh-purge --uninstall
|
||||||
dsh-purge --edit
|
dsh-purge --edit
|
||||||
|
|
||||||
/purge status | apply | revert | edit | help
|
/purge status | apply | revert | uninstall | edit | help
|
||||||
/rules list | use <id> | create <id> | delete <id> | reset | help
|
/rules list | use <id> | create <id> | delete <id> | reset | help
|
||||||
/rewind
|
/rewind
|
||||||
|
|
||||||
|
|||||||
+26
-20
@@ -369,28 +369,33 @@ dsh-purge --uninstall
|
|||||||
|
|
||||||
```
|
```
|
||||||
dsh-purge/
|
dsh-purge/
|
||||||
├── lib/
|
├── bin/dsh-purge.js
|
||||||
│ ├── core.js # 路径探测、补丁、备份还原、shim、覆盖文件
|
├── client.js
|
||||||
│ ├── hide-console.js # Windows 隐藏子进程控制台(写入 bin.js)
|
|
||||||
│ ├── identity.js # 把 inject 折进 persona-prefix,不另写身份卡
|
|
||||||
│ ├── index.js # 插件入口:命令、工具、systemPrompt、HTTP
|
|
||||||
│ ├── rules.js # 规则集
|
|
||||||
│ ├── restart-web.js # Web 配置下的重启
|
|
||||||
│ ├── uninstall.js # 卸载:还原补丁并清除插件
|
|
||||||
│ └── default-prompt-inject.md
|
|
||||||
├── client.js # 设置页
|
|
||||||
├── bin/dsh-purge.js # CLI
|
|
||||||
├── docs/
|
|
||||||
│ ├── banner.svg
|
|
||||||
│ ├── appreciate.png
|
|
||||||
│ └── preview/
|
|
||||||
│ ├── settings.png
|
|
||||||
│ └── rules.png
|
|
||||||
├── cordis.patch.yml
|
├── cordis.patch.yml
|
||||||
|
├── docs/
|
||||||
|
│ ├── appreciate.png
|
||||||
|
│ ├── banner.svg
|
||||||
|
│ └── preview/
|
||||||
|
│ ├── rules.png
|
||||||
|
│ └── settings.png
|
||||||
|
├── lib/
|
||||||
|
│ ├── child-process-hide.mjs
|
||||||
|
│ ├── core.js
|
||||||
|
│ ├── default-prompt-inject.md
|
||||||
|
│ ├── hide-console.js
|
||||||
|
│ ├── identity.js
|
||||||
|
│ ├── index.js
|
||||||
|
│ ├── restart-web.js
|
||||||
|
│ ├── rewind.js
|
||||||
|
│ ├── rules.js
|
||||||
|
│ ├── uninstall-restart.js
|
||||||
|
│ ├── uninstall.js
|
||||||
|
│ └── update.js
|
||||||
├── package.json
|
├── package.json
|
||||||
|
├── screenshots.json
|
||||||
|
├── LICENSE
|
||||||
├── README.md
|
├── README.md
|
||||||
├── README.zh-CN.md
|
└── README.zh-CN.md
|
||||||
└── LICENSE
|
|
||||||
```
|
```
|
||||||
|
|
||||||
运行时用户文件:`$DSH_HOME/prompt-inject.md`、`$DSH_HOME/rules/`。未设 `DSH_HOME` 时,优先用 dsh 安装目录旁边的 `.dsh`,再退回 `~/.dsh`。
|
运行时用户文件:`$DSH_HOME/prompt-inject.md`、`$DSH_HOME/rules/`。未设 `DSH_HOME` 时,优先用 dsh 安装目录旁边的 `.dsh`,再退回 `~/.dsh`。
|
||||||
@@ -415,10 +420,11 @@ dsh-purge/
|
|||||||
dsh-purge --status
|
dsh-purge --status
|
||||||
dsh-purge --apply
|
dsh-purge --apply
|
||||||
dsh-purge --revert
|
dsh-purge --revert
|
||||||
|
dsh-purge --uninstall
|
||||||
dsh-purge --edit
|
dsh-purge --edit
|
||||||
|
|
||||||
# 聊天
|
# 聊天
|
||||||
/purge status | apply | revert | edit | help
|
/purge status | apply | revert | uninstall | edit | help
|
||||||
/rules list | use <id> | create <id> | delete <id> | reset | help
|
/rules list | use <id> | create <id> | delete <id> | reset | help
|
||||||
/rewind
|
/rewind
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const COPY_NAMES = [
|
|||||||
"docs",
|
"docs",
|
||||||
"client.js",
|
"client.js",
|
||||||
"cordis.patch.yml",
|
"cordis.patch.yml",
|
||||||
|
"screenshots.json",
|
||||||
"package.json",
|
"package.json",
|
||||||
"README.md",
|
"README.md",
|
||||||
"README.zh-CN.md",
|
"README.zh-CN.md",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
"docs",
|
"docs",
|
||||||
"client.js",
|
"client.js",
|
||||||
"cordis.patch.yml",
|
"cordis.patch.yml",
|
||||||
|
"screenshots.json",
|
||||||
"README.md",
|
"README.md",
|
||||||
"README.zh-CN.md",
|
"README.zh-CN.md",
|
||||||
"LICENSE"
|
"LICENSE"
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
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");
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
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");
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import assert from "node:assert/strict";
|
|
||||||
import fs from "node:fs";
|
|
||||||
import os from "node:os";
|
|
||||||
import path from "node:path";
|
|
||||||
import {
|
|
||||||
stripPluginFromPackage,
|
|
||||||
shouldDeletePluginTree,
|
|
||||||
wasApplied,
|
|
||||||
} from "../lib/uninstall.js";
|
|
||||||
import { revertHideConsoleFromBin } from "../lib/hide-console.js";
|
|
||||||
|
|
||||||
assert.equal(wasApplied({ has_backup: true, patches_applied: 0 }), true);
|
|
||||||
assert.equal(wasApplied({ has_backup: false, patches_applied: 3 }), true);
|
|
||||||
assert.equal(wasApplied({ has_backup: false, patches_applied: 0, shim_cmd: "patched" }), true);
|
|
||||||
assert.equal(wasApplied({ has_backup: false, patches_applied: 0, shim_cmd: "original" }), false);
|
|
||||||
|
|
||||||
const pkg = {
|
|
||||||
dependencies: { "dsh-purge": "github:YuJunZhiXue/dsh-purge", other: "1.0.0" },
|
|
||||||
bundles: ["dsh-purge", "dsh-mnemon"],
|
|
||||||
plugins: [{ id: "dsh-purge" }, { id: "keep-me" }],
|
|
||||||
};
|
|
||||||
assert.equal(stripPluginFromPackage(pkg), true);
|
|
||||||
assert.equal(pkg.dependencies["dsh-purge"], undefined);
|
|
||||||
assert.equal(pkg.dependencies.other, "1.0.0");
|
|
||||||
assert.deepEqual(pkg.bundles, ["dsh-mnemon"]);
|
|
||||||
assert.deepEqual(pkg.plugins, [{ id: "keep-me" }]);
|
|
||||||
assert.equal(stripPluginFromPackage(pkg), false);
|
|
||||||
|
|
||||||
const home = path.join(os.tmpdir(), "dsh-home-fake");
|
|
||||||
assert.equal(
|
|
||||||
shouldDeletePluginTree(path.join(home, "profiles", "web", "node_modules", "dsh-purge"), home),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
assert.equal(shouldDeletePluginTree(path.join(os.tmpdir(), "vendor", "dsh-purge"), home), false);
|
|
||||||
|
|
||||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-hide-"));
|
|
||||||
const binRoot = path.join(tmp, "dsh");
|
|
||||||
const libDir = path.join(binRoot, "lib");
|
|
||||||
fs.mkdirSync(libDir, { recursive: true });
|
|
||||||
const binJs = path.join(libDir, "bin.js");
|
|
||||||
fs.writeFileSync(
|
|
||||||
binJs,
|
|
||||||
'import "./dsh-purge-hide-console.js"; // [dsh-purge] hide-console\nconsole.log("ok");\n',
|
|
||||||
"utf8",
|
|
||||||
);
|
|
||||||
fs.writeFileSync(path.join(libDir, "dsh-purge-hide-console.js"), "// side\n", "utf8");
|
|
||||||
fs.writeFileSync(path.join(libDir, "dsh-purge-child-process-hide.mjs"), "// facade\n", "utf8");
|
|
||||||
assert.equal(revertHideConsoleFromBin(binRoot, { fs, path }), "reverted");
|
|
||||||
assert.equal(fs.readFileSync(binJs, "utf8"), 'console.log("ok");\n');
|
|
||||||
assert.equal(fs.existsSync(path.join(libDir, "dsh-purge-hide-console.js")), false);
|
|
||||||
assert.equal(revertHideConsoleFromBin(binRoot, { fs, path }), "absent");
|
|
||||||
fs.rmSync(tmp, { recursive: true, force: true });
|
|
||||||
|
|
||||||
console.log("uninstall.test.js ok");
|
|
||||||
Reference in new issue
Block a user