ralphflow-dsh 0.1.1 → 2.0.1
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/README.md +220 -167
- package/cordis.patch.yml +11 -0
- package/lib/create.d.ts +7 -11
- package/lib/create.js +132 -83
- package/lib/engine.d.ts +667 -262
- package/lib/engine.js +3583 -2579
- package/lib/index.d.ts +3 -4
- package/lib/index.js +222 -163
- package/lib/message-source.d.ts +25 -0
- package/lib/message-source.js +2 -0
- package/lib/reset.d.ts +40 -0
- package/lib/reset.js +147 -0
- package/lib/tools.d.ts +31 -14
- package/lib/tools.js +407 -684
- package/lib/verify.d.ts +57 -0
- package/lib/verify.js +326 -0
- package/lib/voting.d.ts +63 -0
- package/lib/voting.js +131 -0
- package/package.json +25 -44
- package/workflows/loop.yaml +21 -6
- package/workflows/spec.yaml +51 -46
- package/lib/actions.d.ts +0 -37
- package/lib/actions.js +0 -55
- package/lib/check-voting.d.ts +0 -54
- package/lib/check-voting.js +0 -289
- package/lib/check.d.ts +0 -64
- package/lib/check.js +0 -329
- package/lib/client/CommandCard.d.ts +0 -24
- package/lib/client/CommandCard.js +0 -69
- package/lib/client/HeaderAction.d.ts +0 -39
- package/lib/client/HeaderAction.js +0 -509
- package/lib/client/RunCard.d.ts +0 -27
- package/lib/client/RunCard.js +0 -375
- package/lib/client/client.d.ts +0 -3
- package/lib/client/client.js +0 -275
- package/lib/client/definition.d.ts +0 -126
- package/lib/client/definition.js +0 -259
- package/lib/client/hidden-runs.d.ts +0 -6
- package/lib/client/hidden-runs.js +0 -52
- package/lib/client/http-state.d.ts +0 -67
- package/lib/client/http-state.js +0 -81
- package/lib/client/markdown.d.ts +0 -26
- package/lib/client/markdown.js +0 -174
- package/lib/client/notify-watch.d.ts +0 -38
- package/lib/client/notify-watch.js +0 -98
- package/lib/client/notify.d.ts +0 -21
- package/lib/client/notify.js +0 -168
- package/lib/client/snapshots.d.ts +0 -8
- package/lib/client/snapshots.js +0 -101
- package/lib/client.js +0 -2361
- package/lib/commands.d.ts +0 -41
- package/lib/commands.js +0 -223
- package/lib/deps.d.ts +0 -17
- package/lib/deps.js +0 -19
- package/lib/done-detect.d.ts +0 -2
- package/lib/done-detect.js +0 -28
- package/lib/driver.d.ts +0 -32
- package/lib/driver.js +0 -248
- package/lib/events.d.ts +0 -35
- package/lib/events.js +0 -52
- package/lib/jobs.d.ts +0 -56
- package/lib/jobs.js +0 -355
- package/lib/mutex.d.ts +0 -9
- package/lib/mutex.js +0 -21
- package/lib/session-hygiene.d.ts +0 -25
- package/lib/session-hygiene.js +0 -205
- package/lib/voting-progress.d.ts +0 -37
- package/lib/voting-progress.js +0 -89
package/lib/check.js
DELETED
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — CHECK 验证者调度(dsh 子代理实现)
|
|
3
|
-
*
|
|
4
|
-
* 移植自 opencode 版 check.ts:验证者从 opencode SDK 会话改为 dsh 子代理
|
|
5
|
-
* (ctx.subagents.start,in-process spawn provider)。验证者硬约束三保险:
|
|
6
|
-
* 1. toolFilter 只放行只读/验证工具(read/bash/grep/glob),写入类工具不可见;
|
|
7
|
-
* 2. 验证者 system prompt 沿用 DEFAULT_ADVERSARIAL_SYSTEM_PROMPT(edit 硬拒铁律);
|
|
8
|
-
* 3. 子代理会话 sandbox 目标 read-only(依赖 provider 继承配置,见 README 说明)。
|
|
9
|
-
* 语义与 opencode 版字节级对齐:超时/基础设施故障/extra_dirs 校验/结果解析/事件记录。
|
|
10
|
-
*/
|
|
11
|
-
import fs from "fs";
|
|
12
|
-
import { DEFAULT_ADVERSARIAL_SYSTEM_PROMPT, DEFAULT_ADVERSARIAL_TIMEOUT_MS, resolveCheckModel } from "./engine.js";
|
|
13
|
-
// ─── 实例级取消信号注册表 ─────────────────────────────────────────────────────
|
|
14
|
-
//
|
|
15
|
-
// 每个 runCheckAndAdvance 互斥段通过 registerInstanceSignal 取得一个可 abort 的
|
|
16
|
-
// signal;cancel/destroyInstance 调 abortInstanceChecks 统一中止该实例所有在飞
|
|
17
|
-
// 验证者子代理(不再白烧 token 到超时)。
|
|
18
|
-
const activeControllers = new Map();
|
|
19
|
-
export function registerInstanceSignal(instId) {
|
|
20
|
-
const controller = new AbortController();
|
|
21
|
-
let set = activeControllers.get(instId);
|
|
22
|
-
if (!set) {
|
|
23
|
-
set = new Set();
|
|
24
|
-
activeControllers.set(instId, set);
|
|
25
|
-
}
|
|
26
|
-
set.add(controller);
|
|
27
|
-
return {
|
|
28
|
-
signal: controller.signal,
|
|
29
|
-
dispose: () => {
|
|
30
|
-
const cur = activeControllers.get(instId);
|
|
31
|
-
if (!cur)
|
|
32
|
-
return;
|
|
33
|
-
cur.delete(controller);
|
|
34
|
-
if (cur.size === 0)
|
|
35
|
-
activeControllers.delete(instId);
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/** 中止某实例的全部在飞验证(cancel / destroyInstance 时调用)。 */
|
|
40
|
-
export function abortInstanceChecks(instId) {
|
|
41
|
-
const set = activeControllers.get(instId);
|
|
42
|
-
if (!set)
|
|
43
|
-
return;
|
|
44
|
-
for (const c of set) {
|
|
45
|
-
try {
|
|
46
|
-
c.abort();
|
|
47
|
-
}
|
|
48
|
-
catch { }
|
|
49
|
-
}
|
|
50
|
-
activeControllers.delete(instId);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* 「还有验证者在飞吗」的统一入口:先清理孤儿登记(进程 kill -9 后 finally 不
|
|
54
|
-
* 执行留下的 live 文件,否则 continue/status 会永远死等),再返回剩余数量。
|
|
55
|
-
*/
|
|
56
|
-
export function liveVerifierCount(engine, instId) {
|
|
57
|
-
try {
|
|
58
|
-
engine.pruneStaleAdversarialSessions(instId);
|
|
59
|
-
}
|
|
60
|
-
catch { }
|
|
61
|
-
return engine.readAdversarialSessions(instId).length;
|
|
62
|
-
}
|
|
63
|
-
export function abortActiveCheck(deps, instId) {
|
|
64
|
-
// dsh 子代理取消走 AbortSignal;实例级取消由 job 层统一处理
|
|
65
|
-
deps.engine.logEvent(instId, "warn", "adversarial_check_abort_requested", {});
|
|
66
|
-
}
|
|
67
|
-
export function isCheckSession(_sessionId) {
|
|
68
|
-
return false; // dsh 子代理会话由 subagent 运行时管理,无需本插件跟踪
|
|
69
|
-
}
|
|
70
|
-
/** 验证者工具白名单:只读 + 验证命令,无任何写工具 */
|
|
71
|
-
/**
|
|
72
|
-
* 验证者工具白名单的期望集合(opencode 同名语义:只读 + 验证命令)。
|
|
73
|
-
* 注意:dsh 的 tools.restrict 对未知工具名直接抛错——不同部署的全局工具集
|
|
74
|
-
* 不同(本仓库验证环境只有 bash/str_replace_editor/ralphflow_*),硬编码
|
|
75
|
-
* 会让验证者在启动瞬间全灭(restrict 抛错 → 全部 infra → 工作流假性暂停)。
|
|
76
|
-
* 因此运行时与宿主实际工具集求交集,交集为空时退化为「排除写类工具」启发式。
|
|
77
|
-
*/
|
|
78
|
-
export const VERIFIER_TOOL_ALLOW = ["read", "bash", "grep", "glob", "read_image"];
|
|
79
|
-
/** 与宿主实际全局工具集求交集后的验证者白名单(每次调用实时解析) */
|
|
80
|
-
export function resolveVerifierToolAllow(ctx) {
|
|
81
|
-
const preferred = [...VERIFIER_TOOL_ALLOW];
|
|
82
|
-
try {
|
|
83
|
-
const tools = ctx.tools;
|
|
84
|
-
const get = tools?.get?.bind(tools);
|
|
85
|
-
if (typeof get !== "function")
|
|
86
|
-
return preferred;
|
|
87
|
-
// 用 get() 逐个试探(文档确认的存在性语义),而不是 schemas()——后者在
|
|
88
|
-
// 插件上下文的无参调用不保证枚举全局工具。
|
|
89
|
-
const intersect = preferred.filter((n) => {
|
|
90
|
-
try {
|
|
91
|
-
return !!get(n);
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
if (intersect.length > 0)
|
|
98
|
-
return intersect;
|
|
99
|
-
// 工具命名体系不同(如 dsh 用 str_replace_editor 而非 read/edit):
|
|
100
|
-
// 退化为排除明显写类工具——验证者的独立性主要靠独立会话 + 对抗 prompt,
|
|
101
|
-
// 工具限制是纵深防御而非唯一防线。
|
|
102
|
-
const common = ["bash", "read", "view", "grep", "glob", "search", "web"];
|
|
103
|
-
const fallback = common.filter((n) => {
|
|
104
|
-
try {
|
|
105
|
-
return !!get(n);
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
return fallback.length > 0 ? fallback : ["bash"];
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
114
|
-
return preferred;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* 模型解析:workflow 显式 → agent 配置 → 工作会话当前模型 → 全局默认。
|
|
119
|
-
* dsh 版简化为:workflow 显式 → 工作会话当前模型(从 parent agent options 读取)→ 全局默认。
|
|
120
|
-
*/
|
|
121
|
-
function resolveModelForVerify(ctx, parent, adversarialConfig) {
|
|
122
|
-
const fromWorkflow = resolveCheckModel(adversarialConfig?.model);
|
|
123
|
-
if (fromWorkflow)
|
|
124
|
-
return { model: `${fromWorkflow.providerID}/${fromWorkflow.modelID}`, source: "workflow" };
|
|
125
|
-
// 优先组合 provider/model(splitModel 依赖 "provider/model" 形态才能完整拆分,
|
|
126
|
-
// 单独给 model 会丢失 provider,subagent 请求可能路由到错误 provider)。
|
|
127
|
-
const opts = parent?.options;
|
|
128
|
-
const p = opts?.provider;
|
|
129
|
-
const m = opts?.model;
|
|
130
|
-
if (p && m)
|
|
131
|
-
return { model: `${p}/${m}`, source: "owner-session" };
|
|
132
|
-
if (m)
|
|
133
|
-
return { model: m, source: "owner-session" };
|
|
134
|
-
if (p)
|
|
135
|
-
return { model: p, source: "owner-session" };
|
|
136
|
-
return { model: undefined, source: "global-default" };
|
|
137
|
-
}
|
|
138
|
-
/** 解析验证者最终文本中的通过标记与失败理由 */
|
|
139
|
-
export function parseVerdict(engine, text) {
|
|
140
|
-
const passed = engine.parseCheckResult(text);
|
|
141
|
-
const reason = engine.getAdversarialCheckReason(text);
|
|
142
|
-
return { passed, reason };
|
|
143
|
-
}
|
|
144
|
-
/** 把 "provider/model" 拆成 dsh 的 AgentOptions(provider + model 分字段) */
|
|
145
|
-
function splitModel(ref) {
|
|
146
|
-
const idx = ref.indexOf("/");
|
|
147
|
-
if (idx > 0) {
|
|
148
|
-
return { provider: ref.slice(0, idx), model: ref.slice(idx + 1) };
|
|
149
|
-
}
|
|
150
|
-
return { model: ref };
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* 运行一个独立验证者子代理。被单验证者路径(adversarialCheck)与投票路径
|
|
154
|
-
* (check-voting.ts)共用。
|
|
155
|
-
*
|
|
156
|
-
* 会话登记:启动时把验证者 id 写入 .adversarial-session(多票共存),结束/
|
|
157
|
-
* 失败/取消时移除——jobs 与 continue/rewind 以此判定「有验证正在进行」,
|
|
158
|
-
* 防止并发双重推进与误判崩溃恢复。
|
|
159
|
-
*/
|
|
160
|
-
export async function runSingleVoter(deps, ownerSessionId, parent, instId, step, checkPrompt, userTask, adversarialConfig, voter) {
|
|
161
|
-
const systemPrompt = adversarialConfig?.system_prompt || DEFAULT_ADVERSARIAL_SYSTEM_PROMPT;
|
|
162
|
-
const timeout = adversarialConfig?.timeout_ms || DEFAULT_ADVERSARIAL_TIMEOUT_MS;
|
|
163
|
-
const { model, source } = resolveModelForVerify(deps.ctx, parent, adversarialConfig);
|
|
164
|
-
const voterTag = voter && voter.count && voter.count > 1 ? ` [${voter.index}/${voter.count}]` : "";
|
|
165
|
-
if (!deps.engine.instanceExists(instId)) {
|
|
166
|
-
return { passed: false, reason: "工作流实例已被取消。" };
|
|
167
|
-
}
|
|
168
|
-
// 复用 extra_dirs 运行时校验:目录被删 → infra 错误,不计失败。
|
|
169
|
-
const extraDirs = deps.engine.readExtraDirs(instId);
|
|
170
|
-
const missingDirs = extraDirs.filter((d) => {
|
|
171
|
-
try {
|
|
172
|
-
return !fs.statSync(d).isDirectory();
|
|
173
|
-
}
|
|
174
|
-
catch {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
if (missingDirs.length > 0) {
|
|
179
|
-
return { passed: false, infra: true, reason: `启动时通过 extra_dirs 声明的目录已不存在:${missingDirs.map((d) => `\`${d}\``).join("、")}。恢复该目录后运行 /ralphflow-continue 重新验证。` };
|
|
180
|
-
}
|
|
181
|
-
deps.engine.logEvent(instId, "info", "adversarial_check_start", {
|
|
182
|
-
stepId: step.id, model: model ?? "agent-default", model_source: source, timeout_ms: timeout, extra_dirs: extraDirs, voter_index: voter?.index,
|
|
183
|
-
});
|
|
184
|
-
const truncate = (t) => (t.length > 3000 ? t.substring(0, 3000) + "…(截断)" : t);
|
|
185
|
-
deps.engine.logEvent(instId, "info", "adversarial_check_prompt", { stepId: step.id, systemPrompt: truncate(systemPrompt), checkPrompt: truncate(checkPrompt), voter_index: voter?.index });
|
|
186
|
-
const startTime = Date.now();
|
|
187
|
-
const keepalive = setInterval(() => {
|
|
188
|
-
deps.engine.logEvent(instId, "info", "adversarial_check_keepalive", { stepId: step.id, elapsed_ms: Date.now() - startTime, voter_index: voter?.index });
|
|
189
|
-
}, 60_000);
|
|
190
|
-
// 登记验证者会话(防并发推进的「验证进行中」标记)
|
|
191
|
-
const verifierId = `v-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}${voter?.index != null ? `-i${voter.index}` : ""}`;
|
|
192
|
-
deps.engine.writeAdversarialSession(verifierId, instId);
|
|
193
|
-
try {
|
|
194
|
-
const subagentName = adversarialConfig?.agent || "spawn";
|
|
195
|
-
let resultText = "";
|
|
196
|
-
let responseError = null;
|
|
197
|
-
let timedOut = false;
|
|
198
|
-
let timeoutHandle;
|
|
199
|
-
// voter 级取消:超时/异常时中止本验证者子代理(不拖到自然结束白烧 token)
|
|
200
|
-
const localAbort = new AbortController();
|
|
201
|
-
const onOuterAbort = () => { try {
|
|
202
|
-
localAbort.abort();
|
|
203
|
-
}
|
|
204
|
-
catch { } };
|
|
205
|
-
if (deps.signal.aborted)
|
|
206
|
-
onOuterAbort();
|
|
207
|
-
else
|
|
208
|
-
deps.signal.addEventListener("abort", onOuterAbort, { once: true });
|
|
209
|
-
try {
|
|
210
|
-
const runPromise = deps.ctx.subagents.start(subagentName, {
|
|
211
|
-
label: `Ralph Check: ${step.id}${voterTag} ${(userTask || "").substring(0, 50)}`,
|
|
212
|
-
prompt: [
|
|
213
|
-
{ type: "text", text: `${systemPrompt}\n\n---\n\n${checkPrompt}` },
|
|
214
|
-
],
|
|
215
|
-
...(parent ? { parent } : {}),
|
|
216
|
-
signal: localAbort.signal,
|
|
217
|
-
...(model ? { agentOptions: splitModel(model) } : {}),
|
|
218
|
-
// 验证者工具白名单:只有读与验证命令,写入类工具不可见(edit 硬拒)。
|
|
219
|
-
// 与宿主实际工具集求交集——restrict 对未知名直接抛错,硬编码名单会让
|
|
220
|
-
// 验证者在工具命名不同的部署上全灭。
|
|
221
|
-
toolFilter: { allow: resolveVerifierToolAllow(deps.ctx) },
|
|
222
|
-
});
|
|
223
|
-
// 败者链兜底:timer 先胜出后,runPromise 衍生链若随后 reject 无人处理
|
|
224
|
-
// 会成为 unhandled rejection 拖垮宿主进程——挂一个空 catch 吞掉。
|
|
225
|
-
runPromise.catch(() => { });
|
|
226
|
-
// 超时竞争(与 opencode 版一致);timer 用完即清,不悬挂到 timeout_ms
|
|
227
|
-
const outcome = await Promise.race([
|
|
228
|
-
runPromise.then(async (run) => {
|
|
229
|
-
const result = await run.result;
|
|
230
|
-
return { run, result };
|
|
231
|
-
}),
|
|
232
|
-
new Promise((_, reject) => {
|
|
233
|
-
timeoutHandle = setTimeout(() => reject(new Error("Adversarial check timeout")), timeout);
|
|
234
|
-
void timeoutHandle.unref?.();
|
|
235
|
-
}),
|
|
236
|
-
]);
|
|
237
|
-
clearTimeout(timeoutHandle);
|
|
238
|
-
const settled = outcome.result;
|
|
239
|
-
if (settled.output && Array.isArray(settled.output)) {
|
|
240
|
-
// SubagentResult.output 是 ContentBlock[]({type:'text', text}),拼接文本块
|
|
241
|
-
const blocks = settled.output;
|
|
242
|
-
const texts = blocks
|
|
243
|
-
.filter((b) => !!b && typeof b === "object" && b.type === "text" && typeof b.text === "string")
|
|
244
|
-
.map((b) => b.text);
|
|
245
|
-
if (texts.length > 0) {
|
|
246
|
-
resultText = texts.join("\n");
|
|
247
|
-
}
|
|
248
|
-
else if (blocks.length > 0) {
|
|
249
|
-
const last = blocks[blocks.length - 1];
|
|
250
|
-
resultText = typeof last === "string" ? last : JSON.stringify(last);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
else if (settled.output && typeof settled.output === "object") {
|
|
254
|
-
resultText = JSON.stringify(settled.output);
|
|
255
|
-
}
|
|
256
|
-
if (settled.stopReason === "refused" || settled.stopReason === "aborted") {
|
|
257
|
-
responseError = `子代理验证未完成(${settled.stopReason})。`;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
catch (err) {
|
|
261
|
-
clearTimeout(timeoutHandle);
|
|
262
|
-
// 超时/请求异常:中止本验证者子代理,不让它在后台跑到自然结束
|
|
263
|
-
try {
|
|
264
|
-
localAbort.abort();
|
|
265
|
-
}
|
|
266
|
-
catch { }
|
|
267
|
-
if (deps.signal.aborted || !deps.engine.instanceExists(instId)) {
|
|
268
|
-
return { passed: false, infra: true, reason: "工作流实例已被取消。" };
|
|
269
|
-
}
|
|
270
|
-
if (String(err.message).includes("timeout")) {
|
|
271
|
-
timedOut = true;
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
responseError = err.message || String(err);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
finally {
|
|
278
|
-
deps.signal.removeEventListener("abort", onOuterAbort);
|
|
279
|
-
}
|
|
280
|
-
if (timedOut) {
|
|
281
|
-
deps.engine.logEvent(instId, "warn", "adversarial_check_timeout", { stepId: step.id, voter_index: voter?.index });
|
|
282
|
-
const sourceLabel = source === "workflow" ? "工作流配置" : source === "owner-session" ? "当前会话模型" : "全局默认模型";
|
|
283
|
-
const reason = `检查阶段超时(${Math.round(timeout / 60000)} 分钟)。验证耗时过长。\n\n验证者模型:\`${model ?? "agent-default"}\`(来源:${sourceLabel})。\n\n可能原因:\n1. 验证任务本身需要更长时间——在工作流配置中增加 \`timeout_ms\`;\n2. 模型服务限流/排队——稍后重试即可;\n3. 模型指向了不可用或过慢的服务。\n\n建议:1. \`/ralphflow-status\` 查看状态;2. \`/ralphflow-continue\` 重试(不计失败);3. \`/ralphflow-cancel\` 取消。`;
|
|
284
|
-
emitVerdictSafe(deps, instId, step, voter, model, "infra", reason);
|
|
285
|
-
return { passed: false, infra: true, reason };
|
|
286
|
-
}
|
|
287
|
-
if (responseError) {
|
|
288
|
-
deps.engine.logEvent(instId, "error", "adversarial_check_request_failed", { stepId: step.id, error: responseError, voter_index: voter?.index });
|
|
289
|
-
const sourceLabel = source === "workflow" ? "工作流配置" : source === "owner-session" ? "当前会话模型" : "全局默认模型";
|
|
290
|
-
const reason = `验证请求失败:${responseError}\n\n验证者模型:\`${model ?? "agent-default"}\`(来源:${sourceLabel})。\n\n这是验证基础设施的问题(额度/API/网络/配置),不是你工作成果的问题——本次不计入失败次数,已完成的工作保持原样。\n\n建议:\n- 确认模型服务可用后运行 \`/ralphflow-continue\` 直接重新验证(无需重做任务);\n- 若反复失败,检查工作流 \`adversarial_check.model\` 或会话模型配置;\n- 或 \`/ralphflow-cancel\` 放弃。`;
|
|
291
|
-
emitVerdictSafe(deps, instId, step, voter, model, "infra", reason);
|
|
292
|
-
return { passed: false, infra: true, reason };
|
|
293
|
-
}
|
|
294
|
-
const responseText = (resultText ?? "").trim();
|
|
295
|
-
if (!responseText) {
|
|
296
|
-
const reason = "验证返回空响应。";
|
|
297
|
-
emitVerdictSafe(deps, instId, step, voter, model, "infra", reason);
|
|
298
|
-
return { passed: false, infra: true, reason };
|
|
299
|
-
}
|
|
300
|
-
const { passed, reason } = parseVerdict(deps.engine, responseText);
|
|
301
|
-
deps.engine.logEvent(instId, "info", "adversarial_check_result", { stepId: step.id, passed, len: responseText.length, reason: reason.substring(0, 160), voter_index: voter?.index });
|
|
302
|
-
emitVerdictSafe(deps, instId, step, voter, model, passed ? "pass" : "fail", reason);
|
|
303
|
-
return { passed, reason };
|
|
304
|
-
}
|
|
305
|
-
finally {
|
|
306
|
-
clearInterval(keepalive);
|
|
307
|
-
deps.engine.removeAdversarialSession(verifierId, instId);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
/** 发射逐票 verdict 帧(三值 status);实例已销毁时静默跳过 */
|
|
311
|
-
function emitVerdictSafe(deps, instId, step, voter, model, status, reasoning) {
|
|
312
|
-
if (!deps.engine.instanceExists(instId))
|
|
313
|
-
return;
|
|
314
|
-
deps.emit(instId, "tool-ralphflow/check-verdict", {
|
|
315
|
-
runId: instId, step: step.id, voter: voter?.index ?? 1, count: voter?.count ?? 1,
|
|
316
|
-
model: model ?? "agent-default", status, reasoning,
|
|
317
|
-
// 到达时刻:UI 用它减 voter-start 的 startedAt 得出该票用时
|
|
318
|
-
arrivedAt: Date.now(),
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
/** 单验证者路径(与 opencode 版 adversarialCheck 同签名语义) */
|
|
322
|
-
export async function adversarialCheck(deps, ownerSessionId, parent, instId, step, checkPrompt, userTask, adversarialConfig) {
|
|
323
|
-
return runSingleVoter(deps, ownerSessionId, parent, instId, step, checkPrompt, userTask, adversarialConfig);
|
|
324
|
-
}
|
|
325
|
-
/** 从 dsh 上下文解析验证者 agent 的模型(默认链兜底) */
|
|
326
|
-
export async function readOwnerSessionModel(ctx, _ownerSessionId) {
|
|
327
|
-
// dsh 中模型解析链由 resolveModelForVerify 处理;此处保留签名兼容
|
|
328
|
-
return undefined;
|
|
329
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — 命令结果卡(/ralphflow-* 输出的 opencode 式呈现)
|
|
3
|
-
*
|
|
4
|
-
* 注册进 conversation.chat.node(keyed kind 'ralphflow-command')。数据来自
|
|
5
|
-
* 折叠官方 command/run + command/done 事件(宿主自动为每条命令追加,属于官方
|
|
6
|
-
* 词汇表,持久化安全)——取代旧版 plugin 自定义帧 append(那会砖掉会话)。
|
|
7
|
-
* command/run 到达即建卡(执行中),command/done 到达补结果文本。
|
|
8
|
-
* 全部消费 dsh 官方主题 token。
|
|
9
|
-
*/
|
|
10
|
-
import * as React from "react";
|
|
11
|
-
export interface RalphCommandCardProps {
|
|
12
|
-
/** chat.node 槽组件签名:数据在 node.data(与官方 ChatNodeView 一致) */
|
|
13
|
-
node?: {
|
|
14
|
-
data?: {
|
|
15
|
-
command?: string;
|
|
16
|
-
text?: string;
|
|
17
|
-
running?: boolean;
|
|
18
|
-
error?: boolean;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
/** locale 翻译函数(slot locale 注入;可能缺省,缺省用内置中文兜底) */
|
|
22
|
-
t?: (key: string, params?: Record<string, unknown>) => string;
|
|
23
|
-
}
|
|
24
|
-
export declare function RalphCommandCard({ node, t }: RalphCommandCardProps): React.JSX.Element | null;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
const STYLE = {
|
|
3
|
-
root: {
|
|
4
|
-
border: "1px solid var(--dsw-alias-border-l2)",
|
|
5
|
-
borderRadius: "10px",
|
|
6
|
-
background: "var(--dsw-alias-bg-layer-1)",
|
|
7
|
-
padding: "12px 14px",
|
|
8
|
-
margin: "6px 0",
|
|
9
|
-
fontSize: "13.5px",
|
|
10
|
-
lineHeight: 1.6,
|
|
11
|
-
},
|
|
12
|
-
head: {
|
|
13
|
-
display: "flex",
|
|
14
|
-
alignItems: "center",
|
|
15
|
-
gap: "8px",
|
|
16
|
-
marginBottom: "8px",
|
|
17
|
-
},
|
|
18
|
-
commandName: {
|
|
19
|
-
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
20
|
-
fontSize: "12.5px",
|
|
21
|
-
color: "var(--dsw-alias-label-secondary)",
|
|
22
|
-
},
|
|
23
|
-
body: {
|
|
24
|
-
whiteSpace: "pre-wrap",
|
|
25
|
-
wordBreak: "break-word",
|
|
26
|
-
maxHeight: "320px",
|
|
27
|
-
overflowY: "auto",
|
|
28
|
-
fontSize: "13px",
|
|
29
|
-
color: "var(--dsw-alias-label-primary)",
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
const badgeStyle = (error, running) => ({
|
|
33
|
-
fontSize: "11px",
|
|
34
|
-
padding: "2px 8px",
|
|
35
|
-
borderRadius: "999px",
|
|
36
|
-
background: error
|
|
37
|
-
? "var(--dsw-alias-state-error-secondary)"
|
|
38
|
-
: running
|
|
39
|
-
? "var(--dsw-alias-state-warn-tertiary)"
|
|
40
|
-
: "var(--dsw-alias-state-business-tertiary)",
|
|
41
|
-
color: error
|
|
42
|
-
? "var(--dsw-alias-state-error-primary)"
|
|
43
|
-
: running
|
|
44
|
-
? "var(--dsw-alias-state-warn-primary)"
|
|
45
|
-
: "var(--dsw-alias-state-business-primary)",
|
|
46
|
-
fontWeight: 600,
|
|
47
|
-
flexShrink: 0,
|
|
48
|
-
whiteSpace: "nowrap",
|
|
49
|
-
});
|
|
50
|
-
function tr(t, key, fallback) {
|
|
51
|
-
try {
|
|
52
|
-
const v = t?.(key);
|
|
53
|
-
return typeof v === "string" && v ? v : fallback;
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return fallback;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export function RalphCommandCard({ node, t }) {
|
|
60
|
-
const data = node?.data;
|
|
61
|
-
if (!data || (!data.command && !data.text))
|
|
62
|
-
return null;
|
|
63
|
-
const isError = !!data.error;
|
|
64
|
-
const isRunning = !!data.running;
|
|
65
|
-
// 显示名去 ralphflow- 前缀(/list、/start…),与 opencode 版 TUI 一致;
|
|
66
|
-
// 快捷命令(/loop /spec)原名显示。
|
|
67
|
-
const disp = String(data.command ?? "").replace(/^ralphflow-/, "");
|
|
68
|
-
return (_jsxs("div", { style: isError ? { ...STYLE.root, borderColor: "var(--dsw-alias-state-error-secondary)" } : STYLE.root, children: [_jsxs("div", { style: STYLE.head, children: [_jsx("span", { style: badgeStyle(isError, isRunning), children: "Ralph Flow" }), _jsx("span", { style: { ...STYLE.commandName, minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: `/${disp}` }), isError ? _jsxs("span", { style: { marginLeft: "auto", fontSize: "11px", color: "var(--dsw-alias-state-error-primary)", flexShrink: 0 }, children: ["\u26A0 ", tr(t, "command.error", "出错")] }) : null, isRunning ? _jsxs("span", { style: { marginLeft: "auto", fontSize: "11px", color: "var(--dsw-alias-state-warn-primary)", flexShrink: 0 }, children: ["\u23F3 ", tr(t, "command.running", "执行中…")] }) : null] }), _jsx("div", { style: STYLE.body, children: data.text ?? "" })] }));
|
|
69
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — 页头入口 + 控制中心抽屉
|
|
3
|
-
*
|
|
4
|
-
* 注册进 conversation.session.header.actions(list 槽)。三层结构:
|
|
5
|
-
* 1) trigger:状态点 + 活跃计数 + 当前活跃 run 的「步骤 · 阶段」微缩——
|
|
6
|
-
* 不点开也能瞄到跑到哪了(mini pipeline 的页头形态);
|
|
7
|
-
* 2) 抽屉「进行中」区:每个 run 一行(pipeline 步骤条 desc 版 + 状态),
|
|
8
|
-
* 点击滚动定位到对话里的卡,旁有 status 按钮;
|
|
9
|
-
* 3) 抽屉「已结束」区:本会话 done/cancelled 的历史(可回看定位)。
|
|
10
|
-
* 无任务时保留冷启动上手卡。样式全部消费 dsh 官方主题 token。
|
|
11
|
-
*/
|
|
12
|
-
import * as React from "react";
|
|
13
|
-
export interface HeaderActionProps {
|
|
14
|
-
sessionId?: string;
|
|
15
|
-
/** 当前会话 chat store 的 hook(conversation 槽框架注入;官方 StatsLine 同款) */
|
|
16
|
-
useSession?: (selector: (state: any) => any, eq?: (a: any, b: any) => boolean) => any;
|
|
17
|
-
/** 旧参数名保留兼容(早期误用会话列表 store——其 state 无 chat 字段,collectRuns 恒空) */
|
|
18
|
-
useSessions?: (selector: (state: any) => any, eq?: (a: any, b: any) => boolean) => any;
|
|
19
|
-
/** locale 翻译函数(slot locale 注入;可能缺省,缺省用内置中文兜底) */
|
|
20
|
-
t?: (key: string, params?: Record<string, unknown>) => string;
|
|
21
|
-
}
|
|
22
|
-
/** 状态 → 语义色 token(全插件统一:卡片徽标/页头/步骤条同一套) */
|
|
23
|
-
export declare function statusColorOf(s: string): string;
|
|
24
|
-
/**
|
|
25
|
-
* 动作直连通道:POST → host 的 /ralphflow/instances 动作端点(webServer 路由,
|
|
26
|
-
* 与状态轮询同源同通道)。不再依赖「往输入框填命令 + 合成 Enter」的脆弱链路:
|
|
27
|
-
* 通过/打回/恢复都可从抽屉一键直达,host 侧按白名单动作 + sessionId 解析 agent
|
|
28
|
-
* 执行工具并(需要时)followup 注入模型。POST 失败时调用方回退到命令注入。
|
|
29
|
-
*/
|
|
30
|
-
export declare function postAction(sessionId: string | undefined, payload: {
|
|
31
|
-
action: string;
|
|
32
|
-
runId?: string;
|
|
33
|
-
reason?: string;
|
|
34
|
-
}): Promise<{
|
|
35
|
-
ok: boolean;
|
|
36
|
-
text: string;
|
|
37
|
-
}>;
|
|
38
|
-
export declare function HeaderAction({ sessionId, useSession, useSessions, t }: HeaderActionProps): React.JSX.Element;
|
|
39
|
-
export default HeaderAction;
|