ralphflow-dsh 0.1.0 → 2.0.0
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 +227 -158
- 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 +24 -45
- 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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ralphflow-dsh",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Ralph Flow for DeepSeek Harness —
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Ralph Flow for DeepSeek Harness — 执行者/验证者模式的具象化:主会话执行,独立验证者对抗检查,推进权在机械程序(v2 原生重做)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -10,25 +10,8 @@
|
|
|
10
10
|
"types": "./lib/index.d.ts",
|
|
11
11
|
"default": "./lib/index.js"
|
|
12
12
|
},
|
|
13
|
-
"./client": {
|
|
14
|
-
"types": "./lib/client/client.d.ts",
|
|
15
|
-
"default": "./lib/client.js"
|
|
16
|
-
},
|
|
17
|
-
"./src/*": "./src/*",
|
|
18
13
|
"./package.json": "./package.json"
|
|
19
14
|
},
|
|
20
|
-
"dsh": {
|
|
21
|
-
"client": {
|
|
22
|
-
"inject": [
|
|
23
|
-
"@deepseek-ai/dsh-client-locale",
|
|
24
|
-
"@deepseek-ai/dsh-client-runtime",
|
|
25
|
-
"@deepseek-ai/dsh-client-ui-conversation",
|
|
26
|
-
"@deepseek-ai/dsh-client-ui-primitives",
|
|
27
|
-
"@deepseek-ai/dsh-client-ui-slots"
|
|
28
|
-
],
|
|
29
|
-
"platform": "web"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
15
|
"files": [
|
|
33
16
|
"lib",
|
|
34
17
|
"workflows",
|
|
@@ -37,37 +20,33 @@
|
|
|
37
20
|
"license": "MIT",
|
|
38
21
|
"repository": {
|
|
39
22
|
"type": "git",
|
|
40
|
-
"url": "https://github.com/
|
|
23
|
+
"url": "git+https://github.com/534529531/ralph-flow-dsh.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/534529531/ralph-flow-dsh#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/534529531/ralph-flow-dsh/issues"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"js-yaml": "^4.1.1"
|
|
41
31
|
},
|
|
42
32
|
"peerDependencies": {
|
|
43
|
-
"@deepseek-ai/cordis": "
|
|
44
|
-
"@deepseek-ai/dsh-agent": "
|
|
45
|
-
"@deepseek-ai/dsh-llm": "
|
|
46
|
-
"@deepseek-ai/dsh-
|
|
47
|
-
"@deepseek-ai/dsh-
|
|
48
|
-
"@deepseek-ai/dsh-
|
|
49
|
-
"@deepseek-ai/dsh-
|
|
50
|
-
"@deepseek-ai/dsh-
|
|
51
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.1.0-rc.7",
|
|
52
|
-
"@deepseek-ai/dsh-commands": "^0.1.0-rc.7",
|
|
53
|
-
"@deepseek-ai/dsh-jobs": "^0.1.0-rc.7",
|
|
54
|
-
"@deepseek-ai/dsh-sandbox": "^0.1.0-rc.7",
|
|
55
|
-
"@deepseek-ai/dsh-session": "^0.1.0-rc.7",
|
|
56
|
-
"@deepseek-ai/dsh-subagent": "^0.1.0-rc.7",
|
|
57
|
-
"@deepseek-ai/dsh-tools": "^0.1.0-rc.7",
|
|
58
|
-
"react": "^18.2.0"
|
|
33
|
+
"@deepseek-ai/cordis": ">=4.0.4",
|
|
34
|
+
"@deepseek-ai/dsh-agent": ">=0.2.0-rc.2",
|
|
35
|
+
"@deepseek-ai/dsh-llm": ">=0.2.0-rc.2",
|
|
36
|
+
"@deepseek-ai/dsh-tools": ">=0.2.0-rc.2",
|
|
37
|
+
"@deepseek-ai/dsh-subagent": ">=0.2.0-rc.2",
|
|
38
|
+
"@deepseek-ai/dsh-session": ">=0.2.0-rc.2",
|
|
39
|
+
"@deepseek-ai/dsh-compaction": ">=0.2.0-rc.2",
|
|
40
|
+
"@deepseek-ai/dsh-commands": ">=0.2.0-rc.2"
|
|
59
41
|
},
|
|
60
42
|
"devDependencies": {
|
|
61
43
|
"@types/js-yaml": "^4.0.9",
|
|
62
|
-
"@types/node": "^22.20.1"
|
|
63
|
-
"@types/react": "^18.3.31",
|
|
64
|
-
"esbuild": "^0.28.2",
|
|
65
|
-
"typescript": "^5.9.3"
|
|
44
|
+
"@types/node": "^22.20.1"
|
|
66
45
|
},
|
|
67
46
|
"scripts": {
|
|
68
|
-
"build": "
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
47
|
+
"build": "tsc -p tsconfig.json",
|
|
48
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
49
|
+
"verify": "node scripts/verify-all.mjs",
|
|
50
|
+
"prepublishOnly": "npm run build && npm run typecheck && npm run verify"
|
|
72
51
|
}
|
|
73
|
-
}
|
|
52
|
+
}
|
package/workflows/loop.yaml
CHANGED
|
@@ -1,27 +1,42 @@
|
|
|
1
1
|
description: 单步对抗验证循环:实现与验证在同一环节内迭代,直到通过
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
# 验证者模型可选("provider/model" 或 {providerID, modelID});不填沿用发起会话当前模型。
|
|
4
|
+
# 验证超时不在 ralphflow 里设置:委派生命周期跟随宿主 dsh 的原生能力
|
|
5
|
+
# (宿主自带的请求级空闲看门狗负责卡死保护)。
|
|
6
|
+
# ← 与 opencode 版 loop.yaml 的差异(刻意,不上移):它在下面这个块里写 `timeout_ms`
|
|
7
|
+
# (验证超时上限);本引擎已把 `timeout_ms` 从公开契约中删除 —— 写了只会得到加载期
|
|
8
|
+
# 告警并忽略,所以这里不抄,超时仍归宿主原生看门狗。
|
|
9
|
+
# adversarial_check:
|
|
10
|
+
# model: deepseek/deepseek-chat
|
|
6
11
|
|
|
7
12
|
steps:
|
|
8
13
|
- id: loop
|
|
9
14
|
desc: 迭代执行任务直到通过对抗验证
|
|
15
|
+
# `reset: true` 与 opencode 一致 —— 它在这一步的注释原文是「单步轻量循环:失败重试频繁」。
|
|
16
|
+
# 两种进入方式的行为(与 opencode 同构):
|
|
17
|
+
# · **重试** → 返工走的是空闲窗口,**每轮都重置**(本步最多 100 轮)。这才是 loop 标 reset 的目的。
|
|
18
|
+
# · **首步初次进入** → 结构上无法重置:首步 DO 是 `ralphflow_start` 工具的返回值,替换会落在
|
|
19
|
+
# 工具调用内部(孤儿 tool/result,静默损坏会话)。opencode 的 start 路径同样不检查 reset。
|
|
20
|
+
# 标了会在启动回执里如实说明,绝不假装做过。
|
|
10
21
|
reset: true
|
|
11
22
|
do: |
|
|
12
|
-
|
|
23
|
+
把任务做到位:它的每一条要求都成立。
|
|
13
24
|
|
|
14
|
-
|
|
15
|
-
-
|
|
25
|
+
每轮交卷前,把本轮摘要**追加**到 summary.md(一轮一节,保持精简):
|
|
26
|
+
- 完成事项(逐条对照任务要求)
|
|
16
27
|
- 变更文件
|
|
17
28
|
- 验证结果
|
|
18
29
|
- 未完成部分与下一步打算
|
|
19
30
|
input: 用户任务描述
|
|
20
31
|
output: 实现的代码/文件 + summary.md(执行摘要)
|
|
21
32
|
check_voting:
|
|
33
|
+
# 前三条逐字照抄 opencode 版 loop.yaml 的三票(各自只查一条)
|
|
22
34
|
- check: 用户任务的每一条要求都已落实
|
|
23
35
|
- check: 实现的行为符合预期,真实可用
|
|
24
36
|
- check: 没有遗漏的需求,边界情况已覆盖
|
|
37
|
+
# 第 4 票是本仓库自己的口径(opencode 版没有这一票)。
|
|
38
|
+
# 只写判断、不写取证动作:内置工作流要对任意项目通用,不能假定项目有测试套件或 git 基线。
|
|
39
|
+
- check: 修改不影响原有功能,不破坏需求以外的边界
|
|
25
40
|
on_pass: done
|
|
26
41
|
on_fail: loop
|
|
27
42
|
max_fail_count: 100
|
package/workflows/spec.yaml
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
|
+
# Ralph Flow 内置工作流(与 claude/opencode 版共享方言,可自由编辑)
|
|
2
|
+
#
|
|
3
|
+
# 本文件与 opencode 版的 spec.yaml 同源(4 步:探索 → 提案 → 逐任务实现 → 归档)。
|
|
4
|
+
# 与 opencode 一致:propose / implement 标了 `reset: true`(重置门)——进入这两步前,
|
|
5
|
+
# 属主会话可见面被整段替换成一条「交接稿」,模型收到的 messages = 系统提示 + 交接稿 + 本步 DO。
|
|
6
|
+
# 载体与硬约束见 docs/v2/reset-feasibility.md 与 src/reset.ts。
|
|
7
|
+
#
|
|
8
|
+
# 注意:重置门只在**步骤边界的空闲窗口**生效,所以工作流**首步**(explore)无法重置——
|
|
9
|
+
# 首步的 DO 是 ralphflow_start 工具的返回值,在工具调用内部替换会静默损坏会话。
|
|
10
|
+
# 首步标 `reset: true` 时启动回执会如实说明(这里首步不标)。
|
|
11
|
+
|
|
1
12
|
description: 基于 OpenSpec 哲学重构的轻量迭代开发工作流——先探索、再提案、逐任务实现、最后归档。不做瀑布式长篇文档。
|
|
2
13
|
|
|
3
14
|
manual_step:
|
|
4
|
-
- propose
|
|
15
|
+
- propose # 审查门:propose 通过独立验证后停下等你放行
|
|
5
16
|
|
|
6
17
|
steps:
|
|
7
18
|
# ── 1. 探索 → 提案草稿 ───────────────────────────────────────────────
|
|
8
19
|
- id: explore
|
|
9
20
|
desc: 需求探索
|
|
10
21
|
do: |
|
|
11
|
-
|
|
22
|
+
摸清需求与项目现状,产出一份能直接拍板的 proposal.md。
|
|
12
23
|
|
|
13
|
-
1.
|
|
14
|
-
2.
|
|
15
|
-
3. 输出 `proposal.md
|
|
24
|
+
1. 审视涉及的文件/模块,写清现状
|
|
25
|
+
2. 评估可行方案并给出推荐方向(并列方案说明取舍)
|
|
26
|
+
3. 输出 `proposal.md`(产物目录下),只写四节:
|
|
16
27
|
- **为什么做**(问题/动机)
|
|
17
28
|
- **做什么**(变更概述、范围、影响)
|
|
18
29
|
- **怎么做**(技术方向;复杂需求可另写 `design.md`)
|
|
19
30
|
- **验收标准**(可验证的完成条件)
|
|
20
|
-
4.
|
|
31
|
+
4. 全文控制在 1-2 页:规格细节留到 propose 或确实需要时再展开
|
|
21
32
|
input: 用户提供的任务描述
|
|
22
33
|
output: proposal.md(+ 可选 design.md)
|
|
23
34
|
check: |
|
|
24
|
-
|
|
25
|
-
1.
|
|
26
|
-
2.
|
|
27
|
-
3.
|
|
35
|
+
打开 proposal.md 逐条核对:
|
|
36
|
+
1. 动机与范围明确:能说出要改哪些文件/模块
|
|
37
|
+
2. 每条验收标准都能由一个命令或一次检查判定真假
|
|
38
|
+
3. 技术方向与需求规模相称
|
|
28
39
|
on_pass: propose
|
|
29
40
|
on_fail: explore
|
|
30
41
|
max_fail_count: 3
|
|
@@ -32,57 +43,51 @@ steps:
|
|
|
32
43
|
# ── 2. 提案定稿 + 任务拆解(人工审查门) ─────────────────────────────
|
|
33
44
|
- id: propose
|
|
34
45
|
desc: 提案与任务拆解
|
|
35
|
-
reset: true
|
|
46
|
+
reset: true # ← 进入本步前换入干净上下文(交接稿 = 系统提示之后唯一的内容);载体见 src/reset.ts
|
|
36
47
|
do: |
|
|
37
|
-
|
|
48
|
+
把 proposal.md 定稿,并拆成可逐项执行、逐项验证的 tasks.md。
|
|
38
49
|
|
|
39
|
-
1.
|
|
50
|
+
1. 读 explore 阶段产出的 proposal.md(有 design.md 一并读)
|
|
40
51
|
2. 按用户反馈最终定稿 proposal.md
|
|
41
|
-
3. 输出 `tasks.md
|
|
42
|
-
|
|
43
|
-
- 使用 `- [ ]` 标记,每项足够小(≤ 50 行代码变动)
|
|
44
|
-
- 任务描述明确产出物
|
|
45
|
-
4. 如果探索阶段没有 design.md 且需求确实复杂:
|
|
46
|
-
先输出 design.md(架构、模块划分、接口设计),再拆 tasks.md
|
|
52
|
+
3. 输出 `tasks.md`:按依赖顺序排列的 `- [ ]` 清单,每项 ≤ 50 行代码变动,且写明产出物
|
|
53
|
+
4. 需求确实复杂而还没有 design.md 时:先补 `design.md`(架构、模块划分、接口设计),再拆 tasks.md
|
|
47
54
|
input: proposal.md(来自 explore 产物目录)+ 用户意向
|
|
48
55
|
output: 最终 proposal.md + tasks.md(+ 可选 design.md)
|
|
49
56
|
check: |
|
|
50
|
-
|
|
51
|
-
1.
|
|
52
|
-
2.
|
|
53
|
-
3.
|
|
54
|
-
4. 无遗漏关键步骤
|
|
57
|
+
打开 tasks.md 与 proposal.md 交叉核对:
|
|
58
|
+
1. proposal 的每条验收标准都有任务承接(逐条点名)
|
|
59
|
+
2. 每项 ≤ 50 行代码变动、写明产出物,且单独一项就能判定完成
|
|
60
|
+
3. 顺序满足前置依赖(前置在前、后置在后)
|
|
55
61
|
on_pass: implement
|
|
56
62
|
on_fail: propose
|
|
57
63
|
max_fail_count: 3
|
|
58
64
|
|
|
59
|
-
# ── 3.
|
|
65
|
+
# ── 3. 逐任务实现(opencode 在此有重置门:干净的上下文开始编码)─────
|
|
60
66
|
- id: implement
|
|
61
67
|
desc: 逐任务实现
|
|
62
|
-
reset: true
|
|
68
|
+
reset: true # ← 干净的上下文开始编码(交接稿 = 系统提示之后唯一的内容);载体见 src/reset.ts
|
|
63
69
|
do: |
|
|
64
|
-
按 tasks.md
|
|
70
|
+
按 tasks.md 逐任务实现,每完成一项就勾掉一项。
|
|
65
71
|
|
|
66
72
|
for each task in tasks.md:
|
|
67
|
-
1.
|
|
73
|
+
1. 读该任务的目标与产出物
|
|
68
74
|
2. 实现——遵循项目代码风格
|
|
69
|
-
3.
|
|
70
|
-
4.
|
|
71
|
-
5. 取下一个任务
|
|
75
|
+
3. 自验——跑 lint/typecheck/test
|
|
76
|
+
4. 通过后把 tasks.md 里该行的 `- [ ]` 改成 `- [x]`
|
|
72
77
|
|
|
73
78
|
实现过程中:
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
|
|
79
|
+
- 发现设计遗漏就直接改设计文档
|
|
80
|
+
- 每任务单独一个提交
|
|
81
|
+
- 这一步只改代码:新文档留给 propose 与 archive
|
|
82
|
+
全部完成时 tasks.md 的每一项都是 `- [x]`。
|
|
78
83
|
input: "tasks.md(+ 可选 design.md)"
|
|
79
84
|
output: 实现的代码文件 + 全部勾选的 tasks.md
|
|
80
85
|
check: |
|
|
81
|
-
|
|
82
|
-
1.
|
|
83
|
-
2.
|
|
84
|
-
3. lint/typecheck
|
|
85
|
-
4.
|
|
86
|
+
打开 tasks.md 与仓库逐条取证:
|
|
87
|
+
1. 每一项都是 `- [x]`(出现 `- [ ]` 即不通过)
|
|
88
|
+
2. 真跑项目的测试命令,输出全绿
|
|
89
|
+
3. 真跑 lint/typecheck,零错误
|
|
90
|
+
4. 在改动过的源码里搜不到 TODO / FIXME / debugger / console.log
|
|
86
91
|
on_pass: archive
|
|
87
92
|
on_fail: implement
|
|
88
93
|
max_fail_count: 5
|
|
@@ -91,15 +96,15 @@ steps:
|
|
|
91
96
|
- id: archive
|
|
92
97
|
desc: 归档总结
|
|
93
98
|
do: |
|
|
94
|
-
1.
|
|
95
|
-
2. 输出 `summary.md
|
|
96
|
-
3. 不需要单独验证步骤——验证在 implement 的逐任务循环里已完成
|
|
99
|
+
1. 确认 tasks.md 全部打勾、项目测试全绿
|
|
100
|
+
2. 输出 `summary.md`:一句话总结 + 变更了多少文件 + 遗留问题
|
|
97
101
|
input: 全部产出 + 实现代码
|
|
98
102
|
output: "summary.md"
|
|
99
103
|
check: |
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
打开 summary.md 与 tasks.md 核对:
|
|
105
|
+
1. summary.md 存在,含一句话总结、变更文件数与遗留问题(没有遗留就写「无」)
|
|
106
|
+
2. tasks.md 每一项都是 `- [x]`
|
|
107
|
+
3. 真跑项目的测试命令,输出全绿
|
|
103
108
|
on_pass: done
|
|
104
109
|
on_fail: implement
|
|
105
110
|
max_fail_count: 3
|
package/lib/actions.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — 抽屉动作分发(POST 动作端点的心智,独立可单测)
|
|
3
|
-
*
|
|
4
|
-
* 页头抽屉的「通过 / 继续 / 打回 / 取消」按钮 → POST /ralphflow/instances →
|
|
5
|
-
* 本模块按白名单动作执行对应工具并(需要时)followup 注入模型。与 index.ts
|
|
6
|
-
* 的 HTTP 壳解耦:纯逻辑可用 e2e 单测覆盖(工具执行/超时/注入/日志四件事)。
|
|
7
|
-
*
|
|
8
|
-
* 语义:
|
|
9
|
-
* - approve:人工门/check_error/archive_failed 恢复——验证由后台 subagent 跑,
|
|
10
|
-
* 模型无需介入,fire 后台推进(不阻塞 HTTP 响应);
|
|
11
|
-
* - resume:暂停恢复——DO 提示需要模型接管,await 后 followup;
|
|
12
|
-
* - return:打回——意见必填,reset 带意见后 followup;
|
|
13
|
-
* - cancel:取消实例(先归档)——快路径,await 返回结果文本。
|
|
14
|
-
*/
|
|
15
|
-
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
16
|
-
import type { Engine } from "./engine.js";
|
|
17
|
-
import type { ToolHandlers } from "./tools.js";
|
|
18
|
-
export interface ActionRequest {
|
|
19
|
-
action: string;
|
|
20
|
-
sessionId?: string;
|
|
21
|
-
runId?: string;
|
|
22
|
-
reason?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface ActionDeps {
|
|
25
|
-
engine: Engine;
|
|
26
|
-
handlers: ToolHandlers;
|
|
27
|
-
getAgent: (sessionId: string) => Agent | undefined;
|
|
28
|
-
deliverToModel: (agent: Agent | undefined, command: string, text: string, warn?: (m: string, e: unknown) => void) => void;
|
|
29
|
-
warn?: (m: string, e: unknown) => void;
|
|
30
|
-
}
|
|
31
|
-
export interface ActionResult {
|
|
32
|
-
ok: boolean;
|
|
33
|
-
text: string;
|
|
34
|
-
/** approve 的后台推进(调用方 void 掉并追加 catch,不阻塞响应) */
|
|
35
|
-
fire?: Promise<string>;
|
|
36
|
-
}
|
|
37
|
-
export declare function dispatchAction(deps: ActionDeps, req: ActionRequest): Promise<ActionResult>;
|
package/lib/actions.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export async function dispatchAction(deps, req) {
|
|
2
|
-
const action = String(req?.action ?? "");
|
|
3
|
-
const sessionId = String(req?.sessionId ?? "");
|
|
4
|
-
const runId = typeof req?.runId === "string" && req.runId ? String(req.runId) : undefined;
|
|
5
|
-
const reason = typeof req?.reason === "string" && req.reason.trim()
|
|
6
|
-
? String(req.reason).trim().slice(0, 4000)
|
|
7
|
-
: undefined;
|
|
8
|
-
const agent = sessionId ? deps.getAgent(sessionId) : undefined;
|
|
9
|
-
if (!agent)
|
|
10
|
-
return { ok: false, text: "会话 agent 不可用(sessionId 无效或会话已结束)。" };
|
|
11
|
-
const run = (name, args) => {
|
|
12
|
-
const h = deps.handlers.get(name);
|
|
13
|
-
if (!h)
|
|
14
|
-
return Promise.resolve(`工具 ${name} 未注册。`);
|
|
15
|
-
return Promise.resolve(h(args, agent));
|
|
16
|
-
};
|
|
17
|
-
const withTimeout = (p, ms) => Promise.race([
|
|
18
|
-
p,
|
|
19
|
-
new Promise((_, rej) => {
|
|
20
|
-
const t = setTimeout(() => rej(new Error("处理超时(可能因实例互斥锁排队),请稍后查看状态。")), ms);
|
|
21
|
-
void t.unref?.();
|
|
22
|
-
}),
|
|
23
|
-
]);
|
|
24
|
-
switch (action) {
|
|
25
|
-
case "approve": {
|
|
26
|
-
deps.engine.logEvent("", "info", "action_approve", { runId, sessionId });
|
|
27
|
-
const fire = run("ralphflow_continue", runId ? { instance: runId } : {}).catch((e) => {
|
|
28
|
-
deps.engine.logEvent("", "error", "action_approve_failed", { runId, error: e instanceof Error ? e.message : String(e) });
|
|
29
|
-
return "";
|
|
30
|
-
});
|
|
31
|
-
return { ok: true, text: "已提交审批:验证即将在后台运行,进度在页头任务列表实时更新。", fire };
|
|
32
|
-
}
|
|
33
|
-
case "resume": {
|
|
34
|
-
deps.engine.logEvent("", "info", "action_resume", { runId, sessionId });
|
|
35
|
-
const text = await withTimeout(run("ralphflow_continue", runId ? { instance: runId } : {}), 10_000).catch((e) => String(e?.message ?? e));
|
|
36
|
-
deps.deliverToModel(agent, "continue", text, deps.warn);
|
|
37
|
-
return { ok: true, text: "已恢复并让模型继续执行。" };
|
|
38
|
-
}
|
|
39
|
-
case "return": {
|
|
40
|
-
if (!reason)
|
|
41
|
-
return { ok: false, text: "打回需要填写修改意见。" };
|
|
42
|
-
deps.engine.logEvent("", "info", "action_return", { runId, sessionId });
|
|
43
|
-
const text = await withTimeout(run("ralphflow_reset", { ...(runId ? { instance: runId } : {}), reason }), 10_000).catch((e) => String(e?.message ?? e));
|
|
44
|
-
deps.deliverToModel(agent, "reset", text, deps.warn);
|
|
45
|
-
return { ok: true, text: "已打回并让模型按意见返工。" };
|
|
46
|
-
}
|
|
47
|
-
case "cancel": {
|
|
48
|
-
deps.engine.logEvent("", "info", "action_cancel", { runId, sessionId });
|
|
49
|
-
const text = await withTimeout(run("ralphflow_cancel", runId ? { instance: runId } : {}), 10_000).catch((e) => String(e?.message ?? e));
|
|
50
|
-
return { ok: true, text };
|
|
51
|
-
}
|
|
52
|
-
default:
|
|
53
|
-
return { ok: false, text: `未知动作:${action}` };
|
|
54
|
-
}
|
|
55
|
-
}
|
package/lib/check-voting.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Multi-voter CHECK (check_voting) — parallel voting + aggregation + infra retry.
|
|
3
|
-
*
|
|
4
|
-
* Semantics (design §4.3/§4.4/§5.3):
|
|
5
|
-
* - Aggregation priority: cancelled > failed > infra > all-pass.
|
|
6
|
-
* - All must pass. failed beats infra (a known work problem is never masked
|
|
7
|
-
* by infra votes; the infra vote re-runs on the next cross-round anyway).
|
|
8
|
-
* - infra auto-retry: at most 1 retry per pause-session; a vote that is still
|
|
9
|
-
* infra after retry → check_error pause (progress file kept, vote marked
|
|
10
|
-
* infra_failed). User continue resets infra_failed → pending (new pardon).
|
|
11
|
-
* - Progress is persisted per-instance via voting-progress.ts; any single
|
|
12
|
-
* vote completion updates the file. The state machine is only touched by
|
|
13
|
-
* the driver after this function returns.
|
|
14
|
-
*/
|
|
15
|
-
import { type CheckDeps } from "./check.js";
|
|
16
|
-
import type { Engine, CheckVotingEntry, NormalStepDef, AdversarialCheckConfig } from "./engine.js";
|
|
17
|
-
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
18
|
-
import { type VotingProgress, type VoterStatus } from "./voting-progress.js";
|
|
19
|
-
export interface VoterVerdict {
|
|
20
|
-
index: number;
|
|
21
|
-
status: "passed" | "failed" | "infra" | "cancelled";
|
|
22
|
-
reason: string;
|
|
23
|
-
}
|
|
24
|
-
export interface VotingOutcome {
|
|
25
|
-
kind: "passed" | "failed" | "infra_pause" | "cancelled";
|
|
26
|
-
reason: string;
|
|
27
|
-
verdicts: VoterVerdict[];
|
|
28
|
-
/** true when the progress file must be kept (infra_pause). */
|
|
29
|
-
keepProgress: boolean;
|
|
30
|
-
}
|
|
31
|
-
export interface RunVotingCheckOptions {
|
|
32
|
-
/** Entry phase: "do" = fresh round (delete progress), "check" = resume. */
|
|
33
|
-
phase: string;
|
|
34
|
-
workflowName: string;
|
|
35
|
-
/** Current persisted progress (null when none). */
|
|
36
|
-
progress: VotingProgress | null;
|
|
37
|
-
/** Per-vote completion callback — the driver uses it to push live progress
|
|
38
|
-
* to the user (design: 投票进度推送). Fired in completion order. */
|
|
39
|
-
onVoteProgress?: (message: string) => void;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Run the full voting flow for a step: decide which votes to run (fresh vs
|
|
43
|
-
* resume), run them concurrently, auto-retry infra once, aggregate.
|
|
44
|
-
* Never touches the state machine; returns an outcome for the driver.
|
|
45
|
-
*/
|
|
46
|
-
export declare function runVotingCheck(deps: CheckDeps, engine: Engine, instId: string, ownerSessionId: string | null, parent: Agent | undefined, step: NormalStepDef, userTask: string | undefined, entries: CheckVotingEntry[], effective: AdversarialCheckConfig | undefined, opts: RunVotingCheckOptions): Promise<VotingOutcome>;
|
|
47
|
-
/** Aggregate failure feedback for DO (design §4.5). */
|
|
48
|
-
export declare function formatVotingFailureReason(verdicts: VoterVerdict[], entries: CheckVotingEntry[]): string;
|
|
49
|
-
/** Aggregate pass feedback (design §4.6). */
|
|
50
|
-
export declare function formatVotingPassReason(verdicts: VoterVerdict[], entries: CheckVotingEntry[]): string;
|
|
51
|
-
/** Infra pause reason for the user (design §9 scenario 3). */
|
|
52
|
-
export declare function formatVotingInfraReason(infraVotes: VoterVerdict[], entries: CheckVotingEntry[]): string;
|
|
53
|
-
/** Status letter for TUI/status summaries. */
|
|
54
|
-
export declare function voterStatusLabel(status: VoterStatus): string;
|