ralphflow-dsh 0.1.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/LICENSE +21 -0
- package/README.md +196 -0
- package/lib/actions.d.ts +37 -0
- package/lib/actions.js +55 -0
- package/lib/check-voting.d.ts +54 -0
- package/lib/check-voting.js +289 -0
- package/lib/check.d.ts +64 -0
- package/lib/check.js +329 -0
- package/lib/client/CommandCard.d.ts +24 -0
- package/lib/client/CommandCard.js +69 -0
- package/lib/client/HeaderAction.d.ts +39 -0
- package/lib/client/HeaderAction.js +509 -0
- package/lib/client/RunCard.d.ts +27 -0
- package/lib/client/RunCard.js +375 -0
- package/lib/client/client.d.ts +3 -0
- package/lib/client/client.js +275 -0
- package/lib/client/definition.d.ts +126 -0
- package/lib/client/definition.js +259 -0
- package/lib/client/hidden-runs.d.ts +6 -0
- package/lib/client/hidden-runs.js +52 -0
- package/lib/client/http-state.d.ts +67 -0
- package/lib/client/http-state.js +81 -0
- package/lib/client/markdown.d.ts +26 -0
- package/lib/client/markdown.js +174 -0
- package/lib/client/notify-watch.d.ts +38 -0
- package/lib/client/notify-watch.js +98 -0
- package/lib/client/notify.d.ts +21 -0
- package/lib/client/notify.js +168 -0
- package/lib/client/snapshots.d.ts +8 -0
- package/lib/client/snapshots.js +101 -0
- package/lib/client.js +2361 -0
- package/lib/commands.d.ts +41 -0
- package/lib/commands.js +223 -0
- package/lib/create.d.ts +14 -0
- package/lib/create.js +98 -0
- package/lib/deps.d.ts +17 -0
- package/lib/deps.js +19 -0
- package/lib/done-detect.d.ts +2 -0
- package/lib/done-detect.js +28 -0
- package/lib/driver.d.ts +32 -0
- package/lib/driver.js +248 -0
- package/lib/engine.d.ts +306 -0
- package/lib/engine.js +2851 -0
- package/lib/events.d.ts +35 -0
- package/lib/events.js +52 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +201 -0
- package/lib/jobs.d.ts +56 -0
- package/lib/jobs.js +355 -0
- package/lib/mutex.d.ts +9 -0
- package/lib/mutex.js +21 -0
- package/lib/session-hygiene.d.ts +25 -0
- package/lib/session-hygiene.js +205 -0
- package/lib/tools.d.ts +24 -0
- package/lib/tools.js +716 -0
- package/lib/voting-progress.d.ts +37 -0
- package/lib/voting-progress.js +89 -0
- package/package.json +73 -0
- package/workflows/loop.yaml +27 -0
- package/workflows/spec.yaml +105 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voting progress persistence (.check-voting-progress.json).
|
|
3
|
+
*
|
|
4
|
+
* Multi-voter CHECK progress must survive across: concurrent voters, infra
|
|
5
|
+
* auto-retry, check_error pause, user continue. These events may happen in
|
|
6
|
+
* different processes/sessions, so progress is persisted per-instance.
|
|
7
|
+
*
|
|
8
|
+
* Lifecycle (design §5.3):
|
|
9
|
+
* - entry with phase="do" → delete (new round, all re-vote)
|
|
10
|
+
* - entry with phase="check" + file → keep; infra_failed reset to pending
|
|
11
|
+
* - entry with phase="check" no file → all re-vote (restart, plugin hook)
|
|
12
|
+
* - aggregate done (pass/fail) → delete
|
|
13
|
+
* - check_error pause → keep
|
|
14
|
+
* - crash recovery / reset/rewind/cancel → delete
|
|
15
|
+
*/
|
|
16
|
+
import type { Engine, CheckVotingEntry } from "./engine.js";
|
|
17
|
+
export type VoterStatus = "pending" | "running" | "passed" | "failed" | "infra_pending" | "infra_failed" | "cancelled";
|
|
18
|
+
export interface VoterProgressEntry {
|
|
19
|
+
index: number;
|
|
20
|
+
check: string;
|
|
21
|
+
model: string | null;
|
|
22
|
+
status: VoterStatus;
|
|
23
|
+
reason: string;
|
|
24
|
+
/** 本次运行开始时刻(ms)——UI 用它显示「该票已跑 Xs」;retry 轮会刷新 */
|
|
25
|
+
startedAt?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface VotingProgress {
|
|
28
|
+
stepId: string;
|
|
29
|
+
workflowName: string;
|
|
30
|
+
entries: VoterProgressEntry[];
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function progressFilePath(engine: Engine, instId: string): string;
|
|
34
|
+
export declare function initVotingProgress(stepId: string, workflowName: string, entries: CheckVotingEntry[]): VotingProgress;
|
|
35
|
+
export declare function readVotingProgress(engine: Engine, instId: string): VotingProgress | null;
|
|
36
|
+
export declare function writeVotingProgress(engine: Engine, instId: string, progress: VotingProgress): void;
|
|
37
|
+
export declare function deleteVotingProgress(engine: Engine, instId: string): void;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voting progress persistence (.check-voting-progress.json).
|
|
3
|
+
*
|
|
4
|
+
* Multi-voter CHECK progress must survive across: concurrent voters, infra
|
|
5
|
+
* auto-retry, check_error pause, user continue. These events may happen in
|
|
6
|
+
* different processes/sessions, so progress is persisted per-instance.
|
|
7
|
+
*
|
|
8
|
+
* Lifecycle (design §5.3):
|
|
9
|
+
* - entry with phase="do" → delete (new round, all re-vote)
|
|
10
|
+
* - entry with phase="check" + file → keep; infra_failed reset to pending
|
|
11
|
+
* - entry with phase="check" no file → all re-vote (restart, plugin hook)
|
|
12
|
+
* - aggregate done (pass/fail) → delete
|
|
13
|
+
* - check_error pause → keep
|
|
14
|
+
* - crash recovery / reset/rewind/cancel → delete
|
|
15
|
+
*/
|
|
16
|
+
import fs from "fs";
|
|
17
|
+
import path from "path";
|
|
18
|
+
import { VOTING_PROGRESS_FILENAME } from "./engine.js";
|
|
19
|
+
export function progressFilePath(engine, instId) {
|
|
20
|
+
return path.join(engine.getInstanceDir(instId), VOTING_PROGRESS_FILENAME);
|
|
21
|
+
}
|
|
22
|
+
export function initVotingProgress(stepId, workflowName, entries) {
|
|
23
|
+
return {
|
|
24
|
+
stepId,
|
|
25
|
+
workflowName,
|
|
26
|
+
entries: entries.map((e, i) => ({
|
|
27
|
+
index: i,
|
|
28
|
+
check: e.check,
|
|
29
|
+
model: typeof e.model === "string" ? e.model : e.model ? `${e.model.providerID ?? ""}/${e.model.modelID ?? ""}` : null,
|
|
30
|
+
status: "pending",
|
|
31
|
+
reason: "",
|
|
32
|
+
})),
|
|
33
|
+
updatedAt: new Date().toISOString(),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function readVotingProgress(engine, instId) {
|
|
37
|
+
try {
|
|
38
|
+
const file = progressFilePath(engine, instId);
|
|
39
|
+
if (!fs.existsSync(file))
|
|
40
|
+
return null;
|
|
41
|
+
const raw = JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
42
|
+
if (!raw || typeof raw !== "object" || !Array.isArray(raw.entries))
|
|
43
|
+
return null;
|
|
44
|
+
const entries = raw.entries
|
|
45
|
+
.filter((e) => e && typeof e === "object" && typeof e.index === "number")
|
|
46
|
+
.map((e) => ({
|
|
47
|
+
index: e.index,
|
|
48
|
+
check: typeof e.check === "string" ? e.check : "",
|
|
49
|
+
model: typeof e.model === "string" ? e.model : null,
|
|
50
|
+
status: ["pending", "running", "passed", "failed", "infra_pending", "infra_failed", "cancelled"].includes(e.status)
|
|
51
|
+
? e.status
|
|
52
|
+
: "pending",
|
|
53
|
+
reason: typeof e.reason === "string" ? e.reason : "",
|
|
54
|
+
// startedAt 透传:check-voting 在 running 时写入,回读时必须保留,
|
|
55
|
+
// 否则「读取→改状态→写回」会把运行时长丢掉
|
|
56
|
+
...(typeof e.startedAt === "number" && e.startedAt > 0 ? { startedAt: e.startedAt } : {}),
|
|
57
|
+
}));
|
|
58
|
+
return {
|
|
59
|
+
stepId: typeof raw.stepId === "string" ? raw.stepId : "",
|
|
60
|
+
workflowName: typeof raw.workflowName === "string" ? raw.workflowName : "",
|
|
61
|
+
entries,
|
|
62
|
+
updatedAt: typeof raw.updatedAt === "string" ? raw.updatedAt : "",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function writeVotingProgress(engine, instId, progress) {
|
|
70
|
+
try {
|
|
71
|
+
// 防复活:cancel 可插在任一在飞 vote 回调之前——实例目录已删时绝不重建,
|
|
72
|
+
// 否则 destroyInstance 后会留下幽灵目录(doctor 持续报缺 state.json)。
|
|
73
|
+
if (!engine.instanceExists(instId))
|
|
74
|
+
return;
|
|
75
|
+
const file = progressFilePath(engine, instId);
|
|
76
|
+
if (!fs.existsSync(path.dirname(file)))
|
|
77
|
+
return;
|
|
78
|
+
const tmp = file + ".tmp." + process.pid;
|
|
79
|
+
fs.writeFileSync(tmp, JSON.stringify({ ...progress, updatedAt: new Date().toISOString() }, null, 2));
|
|
80
|
+
fs.renameSync(tmp, file);
|
|
81
|
+
}
|
|
82
|
+
catch { }
|
|
83
|
+
}
|
|
84
|
+
export function deleteVotingProgress(engine, instId) {
|
|
85
|
+
try {
|
|
86
|
+
fs.unlinkSync(progressFilePath(engine, instId));
|
|
87
|
+
}
|
|
88
|
+
catch { }
|
|
89
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ralphflow-dsh",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Ralph Flow for DeepSeek Harness — opencode 同名的 DO/CHECK 状态机工作流引擎,作为原生 dsh 插件",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./lib/client/client.d.ts",
|
|
15
|
+
"default": "./lib/client.js"
|
|
16
|
+
},
|
|
17
|
+
"./src/*": "./src/*",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
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
|
+
"files": [
|
|
33
|
+
"lib",
|
|
34
|
+
"workflows",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/yj/ralph-flow-dsh.git"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
44
|
+
"@deepseek-ai/dsh-agent": "^0.1.0-rc.7",
|
|
45
|
+
"@deepseek-ai/dsh-llm": "^0.1.0-rc.7",
|
|
46
|
+
"@deepseek-ai/dsh-agent-default-model": "^0.1.0-rc.7",
|
|
47
|
+
"@deepseek-ai/dsh-client-runtime": "^0.1.0-rc.7",
|
|
48
|
+
"@deepseek-ai/dsh-client-ui-conversation": "^0.1.0-rc.7",
|
|
49
|
+
"@deepseek-ai/dsh-client-locale": "^0.1.0-rc.7",
|
|
50
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.7",
|
|
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"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@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"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "npm run build:host && npm run build:client",
|
|
69
|
+
"build:host": "tsc -p tsconfig.json",
|
|
70
|
+
"build:client": "node scripts/build-client.mjs",
|
|
71
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
description: 单步对抗验证循环:实现与验证在同一环节内迭代,直到通过
|
|
2
|
+
|
|
3
|
+
adversarial_check:
|
|
4
|
+
# model: anthropic/claude-sonnet-4-5 # 可选:验证模型("provider/model" 或 {providerID, modelID});不填则用 ralph-check agent 默认模型
|
|
5
|
+
timeout_ms: 3600000 # 60 分钟(上限)
|
|
6
|
+
|
|
7
|
+
steps:
|
|
8
|
+
- id: loop
|
|
9
|
+
desc: 迭代执行任务直到通过对抗验证
|
|
10
|
+
reset: true
|
|
11
|
+
do: |
|
|
12
|
+
完成用户任务。
|
|
13
|
+
|
|
14
|
+
每轮结束前,把执行摘要追加到 summary.md(多轮累积,每轮一节,保持精简):
|
|
15
|
+
- 完成事项(对照任务)
|
|
16
|
+
- 变更文件
|
|
17
|
+
- 验证结果
|
|
18
|
+
- 未完成部分与下一步打算
|
|
19
|
+
input: 用户任务描述
|
|
20
|
+
output: 实现的代码/文件 + summary.md(执行摘要)
|
|
21
|
+
check_voting:
|
|
22
|
+
- check: 用户任务的每一条要求都已落实
|
|
23
|
+
- check: 实现的行为符合预期,真实可用
|
|
24
|
+
- check: 没有遗漏的需求,边界情况已覆盖
|
|
25
|
+
on_pass: done
|
|
26
|
+
on_fail: loop
|
|
27
|
+
max_fail_count: 100
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
description: 基于 OpenSpec 哲学重构的轻量迭代开发工作流——先探索、再提案、逐任务实现、最后归档。不做瀑布式长篇文档。
|
|
2
|
+
|
|
3
|
+
manual_step:
|
|
4
|
+
- propose
|
|
5
|
+
|
|
6
|
+
steps:
|
|
7
|
+
# ── 1. 探索 → 提案草稿 ───────────────────────────────────────────────
|
|
8
|
+
- id: explore
|
|
9
|
+
desc: 需求探索
|
|
10
|
+
do: |
|
|
11
|
+
深入理解用户需求,探索项目现状,给出清晰的方向建议。
|
|
12
|
+
|
|
13
|
+
1. 审视涉及的文件/模块,了解现状
|
|
14
|
+
2. 评估可行方案,给出推荐方向
|
|
15
|
+
3. 输出 `proposal.md`(产物目录下):
|
|
16
|
+
- **为什么做**(问题/动机)
|
|
17
|
+
- **做什么**(变更概述、范围、影响)
|
|
18
|
+
- **怎么做**(技术方向;复杂需求可另写 `design.md`)
|
|
19
|
+
- **验收标准**(可验证的完成条件)
|
|
20
|
+
4. **不要**写长篇规格文档——proposal 控制在 1-2 页
|
|
21
|
+
input: 用户提供的任务描述
|
|
22
|
+
output: proposal.md(+ 可选 design.md)
|
|
23
|
+
check: |
|
|
24
|
+
检查 proposal.md:
|
|
25
|
+
1. 变更动机明确,范围清晰
|
|
26
|
+
2. 验收标准具体、可验证
|
|
27
|
+
3. 技术方向合理,无过度设计
|
|
28
|
+
on_pass: propose
|
|
29
|
+
on_fail: explore
|
|
30
|
+
max_fail_count: 3
|
|
31
|
+
|
|
32
|
+
# ── 2. 提案定稿 + 任务拆解(人工审查门) ─────────────────────────────
|
|
33
|
+
- id: propose
|
|
34
|
+
desc: 提案与任务拆解
|
|
35
|
+
reset: true
|
|
36
|
+
do: |
|
|
37
|
+
基于探索阶段的 proposal.md,最终定稿并拆解可执行任务。
|
|
38
|
+
|
|
39
|
+
1. 读取 explore 阶段产出的 proposal.md(和 design.md,如果存在)
|
|
40
|
+
2. 按用户反馈最终定稿 proposal.md
|
|
41
|
+
3. 输出 `tasks.md`:
|
|
42
|
+
- 按依赖顺序排列的任务清单
|
|
43
|
+
- 使用 `- [ ]` 标记,每项足够小(≤ 50 行代码变动)
|
|
44
|
+
- 任务描述明确产出物
|
|
45
|
+
4. 如果探索阶段没有 design.md 且需求确实复杂:
|
|
46
|
+
先输出 design.md(架构、模块划分、接口设计),再拆 tasks.md
|
|
47
|
+
input: proposal.md(来自 explore 产物目录)+ 用户意向
|
|
48
|
+
output: 最终 proposal.md + tasks.md(+ 可选 design.md)
|
|
49
|
+
check: |
|
|
50
|
+
检查 tasks.md:
|
|
51
|
+
1. 覆盖 proposal 中所有验收标准
|
|
52
|
+
2. 任务颗粒度合理(≤ 50 行/任务),每项可独立验证
|
|
53
|
+
3. 任务顺序正确(前置依赖 → 后置实现)
|
|
54
|
+
4. 无遗漏关键步骤
|
|
55
|
+
on_pass: implement
|
|
56
|
+
on_fail: propose
|
|
57
|
+
max_fail_count: 3
|
|
58
|
+
|
|
59
|
+
# ── 3. 逐任务实现(重置门:干净的上下文开始编码) ────────────────────
|
|
60
|
+
- id: implement
|
|
61
|
+
desc: 逐任务实现
|
|
62
|
+
reset: true
|
|
63
|
+
do: |
|
|
64
|
+
按 tasks.md 逐任务实现。核心循环:
|
|
65
|
+
|
|
66
|
+
for each task in tasks.md:
|
|
67
|
+
1. 理解该任务的目标和产出物
|
|
68
|
+
2. 实现——遵循项目代码风格
|
|
69
|
+
3. 自验——运行 lint/typecheck/test 等验证命令
|
|
70
|
+
4. 通过后在 tasks.md 中将 `- [ ]` 改为 `- [x]`
|
|
71
|
+
5. 取下一个任务
|
|
72
|
+
|
|
73
|
+
实现过程中:
|
|
74
|
+
- 如发现设计遗漏,直接改设计文档
|
|
75
|
+
- 每任务独立提交改动,不攒到一块
|
|
76
|
+
- 不在这一步写新的文档,只写代码
|
|
77
|
+
完成后 tasks.md 应全部 `- [x]`。
|
|
78
|
+
input: "tasks.md(+ 可选 design.md)"
|
|
79
|
+
output: 实现的代码文件 + 全部勾选的 tasks.md
|
|
80
|
+
check: |
|
|
81
|
+
严格审查:
|
|
82
|
+
1. tasks.md 所有 `- [ ]` → `- [x]`
|
|
83
|
+
2. 项目的测试命令全绿
|
|
84
|
+
3. lint/typecheck 无错误
|
|
85
|
+
4. 无 TODO/FIXME/debugger/console.log 残留
|
|
86
|
+
on_pass: archive
|
|
87
|
+
on_fail: implement
|
|
88
|
+
max_fail_count: 5
|
|
89
|
+
|
|
90
|
+
# ── 4. 归档 ──────────────────────────────────────────────────────────
|
|
91
|
+
- id: archive
|
|
92
|
+
desc: 归档总结
|
|
93
|
+
do: |
|
|
94
|
+
1. 确认:tasks.md 全部打勾 + 测试全绿
|
|
95
|
+
2. 输出 `summary.md`(一句话总结 + 变更了多少文件)
|
|
96
|
+
3. 不需要单独验证步骤——验证在 implement 的逐任务循环里已完成
|
|
97
|
+
input: 全部产出 + 实现代码
|
|
98
|
+
output: "summary.md"
|
|
99
|
+
check: |
|
|
100
|
+
1. summary.md 存在且内容完整
|
|
101
|
+
2. tasks.md 全部打勾
|
|
102
|
+
3. 项目测试全绿
|
|
103
|
+
on_pass: done
|
|
104
|
+
on_fail: implement
|
|
105
|
+
max_fail_count: 3
|