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.
Files changed (68) hide show
  1. package/README.md +220 -167
  2. package/cordis.patch.yml +11 -0
  3. package/lib/create.d.ts +7 -11
  4. package/lib/create.js +132 -83
  5. package/lib/engine.d.ts +667 -262
  6. package/lib/engine.js +3583 -2579
  7. package/lib/index.d.ts +3 -4
  8. package/lib/index.js +222 -163
  9. package/lib/message-source.d.ts +25 -0
  10. package/lib/message-source.js +2 -0
  11. package/lib/reset.d.ts +40 -0
  12. package/lib/reset.js +147 -0
  13. package/lib/tools.d.ts +31 -14
  14. package/lib/tools.js +407 -684
  15. package/lib/verify.d.ts +57 -0
  16. package/lib/verify.js +326 -0
  17. package/lib/voting.d.ts +63 -0
  18. package/lib/voting.js +131 -0
  19. package/package.json +25 -44
  20. package/workflows/loop.yaml +21 -6
  21. package/workflows/spec.yaml +51 -46
  22. package/lib/actions.d.ts +0 -37
  23. package/lib/actions.js +0 -55
  24. package/lib/check-voting.d.ts +0 -54
  25. package/lib/check-voting.js +0 -289
  26. package/lib/check.d.ts +0 -64
  27. package/lib/check.js +0 -329
  28. package/lib/client/CommandCard.d.ts +0 -24
  29. package/lib/client/CommandCard.js +0 -69
  30. package/lib/client/HeaderAction.d.ts +0 -39
  31. package/lib/client/HeaderAction.js +0 -509
  32. package/lib/client/RunCard.d.ts +0 -27
  33. package/lib/client/RunCard.js +0 -375
  34. package/lib/client/client.d.ts +0 -3
  35. package/lib/client/client.js +0 -275
  36. package/lib/client/definition.d.ts +0 -126
  37. package/lib/client/definition.js +0 -259
  38. package/lib/client/hidden-runs.d.ts +0 -6
  39. package/lib/client/hidden-runs.js +0 -52
  40. package/lib/client/http-state.d.ts +0 -67
  41. package/lib/client/http-state.js +0 -81
  42. package/lib/client/markdown.d.ts +0 -26
  43. package/lib/client/markdown.js +0 -174
  44. package/lib/client/notify-watch.d.ts +0 -38
  45. package/lib/client/notify-watch.js +0 -98
  46. package/lib/client/notify.d.ts +0 -21
  47. package/lib/client/notify.js +0 -168
  48. package/lib/client/snapshots.d.ts +0 -8
  49. package/lib/client/snapshots.js +0 -101
  50. package/lib/client.js +0 -2361
  51. package/lib/commands.d.ts +0 -41
  52. package/lib/commands.js +0 -223
  53. package/lib/deps.d.ts +0 -17
  54. package/lib/deps.js +0 -19
  55. package/lib/done-detect.d.ts +0 -2
  56. package/lib/done-detect.js +0 -28
  57. package/lib/driver.d.ts +0 -32
  58. package/lib/driver.js +0 -248
  59. package/lib/events.d.ts +0 -35
  60. package/lib/events.js +0 -52
  61. package/lib/jobs.d.ts +0 -56
  62. package/lib/jobs.js +0 -355
  63. package/lib/mutex.d.ts +0 -9
  64. package/lib/mutex.js +0 -21
  65. package/lib/session-hygiene.d.ts +0 -25
  66. package/lib/session-hygiene.js +0 -205
  67. package/lib/voting-progress.d.ts +0 -37
  68. 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.1.1",
4
- "description": "Ralph Flow for DeepSeek Harness — opencode 同名的 DO/CHECK 状态机工作流引擎,作为原生 dsh 插件",
3
+ "version": "2.0.1",
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,30 +10,19 @@
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",
18
+ "cordis.patch.yml",
35
19
  "README.md"
36
20
  ],
21
+ "dsh": {
22
+ "bundle": {
23
+ "patch": "./cordis.patch.yml"
24
+ }
25
+ },
37
26
  "license": "MIT",
38
27
  "repository": {
39
28
  "type": "git",
@@ -43,35 +32,27 @@
43
32
  "bugs": {
44
33
  "url": "https://github.com/534529531/ralph-flow-dsh/issues"
45
34
  },
35
+ "dependencies": {
36
+ "js-yaml": "^4.1.1"
37
+ },
46
38
  "peerDependencies": {
47
- "@deepseek-ai/cordis": "^4.0.1",
48
- "@deepseek-ai/dsh-agent": "^0.1.0-rc.7",
49
- "@deepseek-ai/dsh-llm": "^0.1.0-rc.7",
50
- "@deepseek-ai/dsh-agent-default-model": "^0.1.0-rc.7",
51
- "@deepseek-ai/dsh-client-runtime": "^0.1.0-rc.7",
52
- "@deepseek-ai/dsh-client-ui-conversation": "^0.1.0-rc.7",
53
- "@deepseek-ai/dsh-client-locale": "^0.1.0-rc.7",
54
- "@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.7",
55
- "@deepseek-ai/dsh-client-ui-slots": "^0.1.0-rc.7",
56
- "@deepseek-ai/dsh-commands": "^0.1.0-rc.7",
57
- "@deepseek-ai/dsh-jobs": "^0.1.0-rc.7",
58
- "@deepseek-ai/dsh-sandbox": "^0.1.0-rc.7",
59
- "@deepseek-ai/dsh-session": "^0.1.0-rc.7",
60
- "@deepseek-ai/dsh-subagent": "^0.1.0-rc.7",
61
- "@deepseek-ai/dsh-tools": "^0.1.0-rc.7",
62
- "react": "^18.2.0"
39
+ "@deepseek-ai/cordis": ">=4.0.4",
40
+ "@deepseek-ai/dsh-agent": ">=0.2.0-rc.2",
41
+ "@deepseek-ai/dsh-llm": ">=0.2.0-rc.2",
42
+ "@deepseek-ai/dsh-tools": ">=0.2.0-rc.2",
43
+ "@deepseek-ai/dsh-subagent": ">=0.2.0-rc.2",
44
+ "@deepseek-ai/dsh-session": ">=0.2.0-rc.2",
45
+ "@deepseek-ai/dsh-compaction": ">=0.2.0-rc.2",
46
+ "@deepseek-ai/dsh-commands": ">=0.2.0-rc.2"
63
47
  },
64
48
  "devDependencies": {
65
49
  "@types/js-yaml": "^4.0.9",
66
- "@types/node": "^22.20.1",
67
- "@types/react": "^18.3.31",
68
- "esbuild": "^0.28.2",
69
- "typescript": "^5.9.3"
50
+ "@types/node": "^22.20.1"
70
51
  },
71
52
  "scripts": {
72
- "build": "npm run build:host && npm run build:client",
73
- "build:host": "tsc -p tsconfig.json",
74
- "build:client": "node scripts/build-client.mjs",
75
- "typecheck": "tsc --noEmit -p tsconfig.json"
53
+ "build": "tsc -p tsconfig.json",
54
+ "typecheck": "tsc --noEmit -p tsconfig.json",
55
+ "verify": "node scripts/verify-all.mjs",
56
+ "prepublishOnly": "npm run build && npm run typecheck && npm run verify"
76
57
  }
77
- }
58
+ }
@@ -1,27 +1,42 @@
1
1
  description: 单步对抗验证循环:实现与验证在同一环节内迭代,直到通过
2
2
 
3
- adversarial_check:
4
- # model: anthropic/claude-sonnet-4-5 # 可选:验证模型("provider/model" 或 {providerID, modelID});不填则用 ralph-check agent 默认模型
5
- timeout_ms: 3600000 # 60 分钟(上限)
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
- 每轮结束前,把执行摘要追加到 summary.md(多轮累积,每轮一节,保持精简):
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
@@ -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. **不要**写长篇规格文档——proposal 控制在 1-2 页
31
+ 4. 全文控制在 1-2 页:规格细节留到 propose 或确实需要时再展开
21
32
  input: 用户提供的任务描述
22
33
  output: proposal.md(+ 可选 design.md)
23
34
  check: |
24
- 检查 proposal.md:
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
- 基于探索阶段的 proposal.md,最终定稿并拆解可执行任务。
48
+ 把 proposal.md 定稿,并拆成可逐项执行、逐项验证的 tasks.md。
38
49
 
39
- 1. 读取 explore 阶段产出的 proposal.md(和 design.md,如果存在)
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
- 检查 tasks.md:
51
- 1. 覆盖 proposal 中所有验收标准
52
- 2. 任务颗粒度合理(≤ 50 行/任务),每项可独立验证
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. 自验——运行 lint/typecheck/test 等验证命令
70
- 4. 通过后在 tasks.md 中将 `- [ ]` 改为 `- [x]`
71
- 5. 取下一个任务
75
+ 3. 自验——跑 lint/typecheck/test
76
+ 4. 通过后把 tasks.md 里该行的 `- [ ]` 改成 `- [x]`
72
77
 
73
78
  实现过程中:
74
- - 如发现设计遗漏,直接改设计文档
75
- - 每任务独立提交改动,不攒到一块
76
- - 不在这一步写新的文档,只写代码
77
- 完成后 tasks.md 应全部 `- [x]`。
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. tasks.md 所有 `- [ ]` → `- [x]`
83
- 2. 项目的测试命令全绿
84
- 3. lint/typecheck 无错误
85
- 4. 无 TODO/FIXME/debugger/console.log 残留
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. 确认:tasks.md 全部打勾 + 测试全绿
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
- 1. summary.md 存在且内容完整
101
- 2. tasks.md 全部打勾
102
- 3. 项目测试全绿
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
- }
@@ -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;