mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-30 08:50:22 +08:00
feat: 发布 1.1.8,默认提示词内置进插件,源 md 不进仓库
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a0aaaac6a4
commit
b88706a537
11 files changed
+994
-58
No files matched your search
+123
-10
@@ -12,6 +12,7 @@ import {
|
||||
shouldInjectPrompt,
|
||||
} from "./identity.js";
|
||||
import * as rewind from "./rewind.js";
|
||||
import * as continueRetry from "./continue-retry.js";
|
||||
import * as uninstaller from "./uninstall.js";
|
||||
|
||||
export const name = "dsh-purge";
|
||||
@@ -28,6 +29,11 @@ const DEFAULTS = {
|
||||
postPrompt: "",
|
||||
postPromptOrder: 5100,
|
||||
verbose: false,
|
||||
autoRetry: true,
|
||||
retryMax: 3,
|
||||
autoContinue: true,
|
||||
continueMax: 3,
|
||||
continueText: "继续",
|
||||
};
|
||||
|
||||
const log = (config, ...args) => {
|
||||
@@ -35,6 +41,33 @@ const log = (config, ...args) => {
|
||||
};
|
||||
|
||||
let webTreeReady = false;
|
||||
let continueRuntime = null;
|
||||
let savedContinueSettings = {};
|
||||
let continuePluginCfg = { ...DEFAULTS };
|
||||
|
||||
function currentContinueConfig() {
|
||||
return continueRetry.mergeConfig(continuePluginCfg, savedContinueSettings);
|
||||
}
|
||||
|
||||
function continueStatusPayload(ctx, sessionId) {
|
||||
const cfg = currentContinueConfig();
|
||||
const agent = sessionId ? continueRetry.resolveAgent(ctx, sessionId) : null;
|
||||
if (agent && continueRuntime) return continueRuntime.status(agent);
|
||||
return {
|
||||
ok: true,
|
||||
sessionId: sessionId || "",
|
||||
canContinue: false,
|
||||
reason: "",
|
||||
userAbort: false,
|
||||
retryUsed: 0,
|
||||
continueUsed: 0,
|
||||
retryMax: cfg.retryMax,
|
||||
continueMax: cfg.continueMax,
|
||||
autoRetry: cfg.autoRetry,
|
||||
autoContinue: cfg.autoContinue,
|
||||
continueText: cfg.continueText,
|
||||
};
|
||||
}
|
||||
|
||||
function watchWebTreeReady(ctx) {
|
||||
// 必须挂在 connection 上再 await,与官方打印 URL 同一时刻。
|
||||
@@ -531,6 +564,12 @@ export function apply(ctx, config) {
|
||||
const injectFile = core.findOverrideFile(core.findDshHome());
|
||||
registerPromptSections(ctx, cfg, injectFile);
|
||||
|
||||
// 继续/重试先关掉,需要时再打开下面这段。
|
||||
// continuePluginCfg = cfg;
|
||||
// savedContinueSettings = continueRetry.loadSettings(core.findDshHome());
|
||||
// try { continueRuntime?.dispose?.(); } catch { /* ignore */ }
|
||||
// continueRuntime = continueRetry.installContinueRetry(ctx, { getConfig: currentContinueConfig });
|
||||
|
||||
const commands = ctx.get?.("commands");
|
||||
if (commands) {
|
||||
commands.register({
|
||||
@@ -570,6 +609,19 @@ export function apply(ctx, config) {
|
||||
};
|
||||
},
|
||||
});
|
||||
// commands.register({
|
||||
// name: "continue",
|
||||
// description: "异常停止或中断后发送继续(计入继续次数)",
|
||||
// input: { hint: "继续当前异常停止的会话" },
|
||||
// handler: async (invocation) => {
|
||||
// const sessionId = rewind.invocationSessionId(invocation);
|
||||
// const agent = continueRetry.resolveAgent(ctx, sessionId);
|
||||
// if (!agent || !continueRuntime) return { kind: "error", text: "当前会话不能继续" };
|
||||
// const result = continueRuntime.continueNow(agent);
|
||||
// if (!result.ok) return { kind: "error", text: result.error };
|
||||
// return { kind: "success", text: `已发送继续(${result.used}/${result.max})` };
|
||||
// },
|
||||
// });
|
||||
}
|
||||
|
||||
if (ctx.tools) {
|
||||
@@ -784,6 +836,73 @@ function installWebServer(ctx, cfg) {
|
||||
response.end();
|
||||
},
|
||||
}, "dsh-purge: rewind");
|
||||
// host.webServer.register({
|
||||
// kind: "exact",
|
||||
// path: "/dsh-purge/continue",
|
||||
// handler: async (request, response) => {
|
||||
// if (request.method === "GET") {
|
||||
// try {
|
||||
// const url = new URL(request.url, "http://127.0.0.1");
|
||||
// const sessionId = String(url.searchParams.get("sessionId") || "").trim();
|
||||
// sendJson(response, 200, continueStatusPayload(ctx, sessionId));
|
||||
// } catch (e) {
|
||||
// sendJson(response, 500, { ok: false, error: String(e) });
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// if (request.method === "POST") {
|
||||
// try {
|
||||
// const body = await readJsonBody(request);
|
||||
// const sessionId = String(body?.sessionId || "").trim();
|
||||
// if (!sessionId) {
|
||||
// sendJson(response, 400, { ok: false, error: "需要 sessionId" });
|
||||
// return;
|
||||
// }
|
||||
// const agent = continueRetry.resolveAgent(ctx, sessionId);
|
||||
// if (!agent || !continueRuntime) {
|
||||
// sendJson(response, 409, { ok: false, error: "当前会话不能继续" });
|
||||
// return;
|
||||
// }
|
||||
// const result = continueRuntime.continueNow(agent, { force: Boolean(body?.force) });
|
||||
// sendJson(response, result.ok ? 200 : 409, result);
|
||||
// } catch (e) {
|
||||
// sendJson(response, 500, { ok: false, error: String(e) });
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// response.writeHead(405, { allow: "GET, POST" });
|
||||
// response.end();
|
||||
// },
|
||||
// }, "dsh-purge: continue");
|
||||
// host.webServer.register({
|
||||
// kind: "exact",
|
||||
// path: "/dsh-purge/continue/settings",
|
||||
// handler: async (request, response) => {
|
||||
// if (request.method === "GET") {
|
||||
// try {
|
||||
// sendJson(response, 200, { ok: true, ...currentContinueConfig() });
|
||||
// } catch (e) {
|
||||
// sendJson(response, 500, { ok: false, error: String(e) });
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// if (request.method === "POST") {
|
||||
// try {
|
||||
// const body = await readJsonBody(request);
|
||||
// savedContinueSettings = await continueRetry.saveSettings(core.findDshHome(), {
|
||||
// ...currentContinueConfig(),
|
||||
// ...body,
|
||||
// });
|
||||
// sendJson(response, 200, { ok: true, ...currentContinueConfig() });
|
||||
// } catch (e) {
|
||||
// sendJson(response, 500, { ok: false, error: String(e) });
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// response.writeHead(405, { allow: "GET, POST" });
|
||||
// response.end();
|
||||
// },
|
||||
// }, "dsh-purge: continue settings");
|
||||
host.webServer.register({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/update",
|
||||
@@ -919,11 +1038,8 @@ function installWebServer(ctx, cfg) {
|
||||
handler: async (request, response) => {
|
||||
if (request.method === "GET") {
|
||||
try {
|
||||
const dshHome = core.findDshHome();
|
||||
const fp = core.findOverrideFile(dshHome);
|
||||
let content = "";
|
||||
if (fs.existsSync(fp)) content = await fsp.readFile(fp, "utf8");
|
||||
sendJson(response, 200, { ok: true, exists: fs.existsSync(fp), content, path: fp });
|
||||
const ui = await core.ensureOverrideContent(core.findDshHome(), false);
|
||||
sendJson(response, 200, { ok: true, ...ui });
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
}
|
||||
@@ -937,11 +1053,8 @@ function installWebServer(ctx, cfg) {
|
||||
sendJson(response, 400, { ok: false, error: "content must be a string" });
|
||||
return;
|
||||
}
|
||||
const dshHome = core.findDshHome();
|
||||
const fp = core.findOverrideFile(dshHome);
|
||||
await fsp.mkdir(dshHome, { recursive: true });
|
||||
await fsp.writeFile(fp, content, "utf8");
|
||||
sendJson(response, 200, { ok: true, path: fp });
|
||||
const saved = await core.saveOverrideContent(core.findDshHome(), content);
|
||||
sendJson(response, 200, { ok: true, ...saved });
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user