feat: 发布 1.1.1,回退上一句并清掉待发送队列

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-09-18 00:27:33 +08:00
1 parent c0e6a13bc4
commit 7642678a27
7 files changed
+986 -25

No files matched your search

+85
View File
@@ -10,6 +10,7 @@ import {
GLOBAL_PROMPT_ORDER,
rewritePromptAssembly,
} from "./identity.js";
import * as rewind from "./rewind.js";
export const name = "dsh-purge";
@@ -500,6 +501,31 @@ export function apply(ctx, config) {
input: { hint: "list | use <id> | create <id> [别名] [目标] | delete <id> | reset | help" },
handler: async (invocation) => handleRulesCommand(invocation.rawInput ?? ""),
});
commands.register({
name: "rewind",
description: "回退:子代理直接回退一次;主代理 /rewind once 或 /rewind round",
input: { hint: "once | round" },
handler: async (invocation) => {
const sessionId = rewind.invocationSessionId(invocation);
const arg = String(invocation.rawInput || "").trim().split(/\s+/)[0]?.toLowerCase() || "";
const info = await rewind.analyzeRewind(ctx, sessionId);
if (info.ok && info.kind === "main" && arg !== "once" && arg !== "round") {
return {
kind: "success",
text: "主代理请选择:/rewind once 回退一次,/rewind round 回退上一轮(含本轮子代理)。",
};
}
const mode = arg === "round" ? "round" : "once";
const result = await rewind.applyRewind(ctx, sessionId, mode);
if (!result.ok) return { kind: "error", text: result.error };
return {
kind: "success",
text: mode === "round"
? "已回退上一轮。正在打开新的主会话,上一句已填回输入框。"
: "已回退一次。正在打开新会话,上一句已填回输入框。",
};
},
});
}
if (ctx.tools) {
@@ -681,6 +707,7 @@ function installWebServer(ctx, cfg) {
ai_base: state.ai_base,
patches_applied: state.patches_applied,
patches_pending: state.patches_pending,
patches_skipped: state.patches_skipped || 0,
patches_total: core.ALL_PATCHES.length,
patch_status: state.patch_status,
patch_names,
@@ -699,6 +726,64 @@ function installWebServer(ctx, cfg) {
}
},
}, "dsh-purge: status");
host.webServer.register({
kind: "exact",
path: "/dsh-purge/rewind/options",
handler: async (request, response) => {
if (request.method !== "GET") {
response.writeHead(405, { allow: "GET" });
response.end();
return;
}
try {
const url = new URL(request.url, "http://127.0.0.1");
const sessionId = String(url.searchParams.get("sessionId") || "").trim();
sendJson(response, 200, await rewind.analyzeRewind(ctx, sessionId));
} catch (e) {
sendJson(response, 500, { ok: false, error: String(e) });
}
},
}, "dsh-purge: rewind options");
host.webServer.register({
kind: "exact",
path: "/dsh-purge/rewind",
handler: async (request, response) => {
if (request.method === "GET") {
try {
const url = new URL(request.url, "http://127.0.0.1");
const sessionId = url.searchParams.get("sessionId");
if (sessionId) {
const draft = rewind.takeDraft(sessionId);
sendJson(response, 200, { ok: true, ...(draft || {}) });
return;
}
const pending = rewind.getPending();
sendJson(response, 200, { ok: true, ...(pending || {}) });
} 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 mode = body?.mode === "round" ? "round" : "once";
const result = await rewind.applyRewind(ctx, sessionId, mode);
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: rewind");
host.webServer.register({
kind: "exact",
path: "/dsh-purge/update",