ralphflow-dsh 2.3.1 → 2.4.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 +48 -22
- package/graphs/codewiki/format.md +362 -0
- package/graphs/codewiki/graph.yaml +39 -0
- package/graphs/codewiki/nodes/assemble.md +24 -0
- package/graphs/codewiki/nodes/core-pages.md +17 -0
- package/graphs/codewiki/nodes/module-pages.md +18 -0
- package/graphs/codewiki/nodes/operations-pages.md +18 -0
- package/graphs/codewiki/nodes/survey.md +22 -0
- package/lib/asset-path.d.ts +59 -0
- package/lib/asset-path.js +181 -0
- package/lib/assets.d.ts +42 -0
- package/lib/assets.js +86 -0
- package/lib/client/phase.d.ts +29 -0
- package/lib/client/phase.js +86 -0
- package/lib/client/selection.d.ts +28 -0
- package/lib/client/selection.js +9 -0
- package/lib/client/status-source.d.ts +3 -1
- package/lib/client/status-source.js +3 -2
- package/lib/client/status.js +49 -13
- package/lib/client/viewer.d.ts +18 -0
- package/lib/client/viewer.js +540 -0
- package/lib/client.js +1159 -64
- package/lib/engine.d.ts +111 -47
- package/lib/engine.js +473 -320
- package/lib/facade.d.ts +175 -0
- package/lib/facade.js +553 -0
- package/lib/graph/agent-registry.d.ts +4 -0
- package/lib/graph/agent-registry.js +20 -0
- package/lib/graph/asset.d.ts +47 -0
- package/lib/graph/asset.js +276 -0
- package/lib/graph/assets.d.ts +47 -0
- package/lib/graph/assets.js +224 -0
- package/lib/graph/branches.d.ts +9 -0
- package/lib/graph/branches.js +13 -0
- package/lib/graph/check.d.ts +23 -0
- package/lib/graph/check.js +46 -0
- package/lib/graph/engine.d.ts +55 -0
- package/lib/graph/engine.js +2002 -0
- package/lib/graph/report.d.ts +9 -0
- package/lib/graph/report.js +117 -0
- package/lib/graph/state.d.ts +244 -0
- package/lib/graph/state.js +358 -0
- package/lib/graph/workspace.d.ts +68 -0
- package/lib/graph/workspace.js +262 -0
- package/lib/index.d.ts +11 -1
- package/lib/index.js +156 -49
- package/lib/owner.d.ts +34 -0
- package/lib/owner.js +49 -0
- package/lib/paths.d.ts +12 -0
- package/lib/paths.js +44 -0
- package/lib/pause.d.ts +12 -0
- package/lib/pause.js +19 -0
- package/lib/skills.d.ts +17 -30
- package/lib/skills.js +85 -21
- package/lib/status-contract.d.ts +114 -1
- package/lib/status-contract.js +106 -4
- package/lib/status-service.d.ts +5 -1
- package/lib/status-service.js +8 -1
- package/lib/tools.d.ts +14 -6
- package/lib/tools.js +88 -60
- package/lib/unfinished.d.ts +11 -0
- package/lib/unfinished.js +18 -0
- package/lib/verifier-preset.d.ts +40 -0
- package/lib/verifier-preset.js +126 -0
- package/lib/verify.d.ts +82 -13
- package/lib/verify.js +382 -95
- package/package.json +50 -38
- package/skills/ralphflow-create/SKILL.md +32 -0
- package/skills/ralphflow-create/graph-authoring.md +85 -0
- package/skills/ralphflow-create/matt/LICENSE +21 -0
- package/skills/ralphflow-create/matt/SHA256SUMS +6 -0
- package/skills/ralphflow-create/matt/SKILL-MECHANICS.md +22 -0
- package/skills/ralphflow-create/matt/SOURCE.md +12 -0
- package/skills/ralphflow-create/matt/grilling.md +30 -0
- package/skills/ralphflow-create/matt/to-spec.md +75 -0
- package/skills/ralphflow-create/matt/to-tickets.md +105 -0
- package/skills/ralphflow-create/matt/writing-for-agents.md +81 -0
- package/skills/ralphflow-create/ralphflow-authoring.md +31 -0
- package/skills/ralphflow-create/testing-workflow.md +60 -0
- package/{references → skills/ralphflow-create}/workflow-authoring.md +25 -5
- package/workflows/create-graph/steps/graph.md +17 -0
- package/workflows/create-graph/workflow.yaml +77 -0
- package/workflows/loop/workflow.yaml +23 -0
- package/lib/create.d.ts +0 -2
- package/lib/create.js +0 -17
- package/workflows/loop.yaml +0 -45
- /package/workflows/{spec.yaml → spec/workflow.yaml} +0 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph 实例状态:只存**主事实**(attempt / submission / verdict / acceptance / todo /
|
|
3
|
+
* integration / worktree),不存 `node.status` / `waitReason` / `currentStage` 这类派生投影
|
|
4
|
+
* (design §3.2 / §10.4)。节点状态、当前节点、等待原因全部由本模块的纯函数现算。
|
|
5
|
+
*
|
|
6
|
+
* 一个实例一份 `state.json`,与 Flow 共用 `.dsh/ralph-flow/instances/<id>/`;原子写
|
|
7
|
+
* (临时文件 + rename)与 Flow 同款。Graph 实例完成后**保留**状态(design §3.3)。
|
|
8
|
+
*/
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { RALPH_FLOW_DIR } from "../engine.js";
|
|
12
|
+
import { pauseLabel } from "../pause.js";
|
|
13
|
+
import { nodeBranchFor } from "./branches.js";
|
|
14
|
+
export const GRAPH_ACTIVE_STATUSES = ["running", "paused", "waiting", "interrupted"];
|
|
15
|
+
export function isGraphTerminal(status) {
|
|
16
|
+
return status === "completed" || status === "failed" || status === "cancelled";
|
|
17
|
+
}
|
|
18
|
+
export function graphRootOf(workspace) {
|
|
19
|
+
return path.join(workspace, RALPH_FLOW_DIR);
|
|
20
|
+
}
|
|
21
|
+
export function graphInstancesDirOf(workspace) {
|
|
22
|
+
return path.join(graphRootOf(workspace), "instances");
|
|
23
|
+
}
|
|
24
|
+
export function graphReportsDirOf(workspace) {
|
|
25
|
+
return path.join(graphRootOf(workspace), "reports");
|
|
26
|
+
}
|
|
27
|
+
export function graphInstanceDirOf(workspace, instId) {
|
|
28
|
+
return path.join(graphInstancesDirOf(workspace), instId);
|
|
29
|
+
}
|
|
30
|
+
export function graphStatePathOf(workspace, instId) {
|
|
31
|
+
return path.join(graphInstanceDirOf(workspace, instId), "state.json");
|
|
32
|
+
}
|
|
33
|
+
export function graphArtifactsRootOf(workspace) {
|
|
34
|
+
return path.join(graphRootOf(workspace), "artifacts");
|
|
35
|
+
}
|
|
36
|
+
export function graphArtifactsDirOf(workspace, state) {
|
|
37
|
+
return path.join(graphArtifactsRootOf(workspace), state.artifacts_dir_name);
|
|
38
|
+
}
|
|
39
|
+
export function graphNodeArtifactDirOf(workspace, state, nodeId, attemptId) {
|
|
40
|
+
return path.join(graphArtifactsDirOf(workspace, state), "nodes", nodeId, attemptId);
|
|
41
|
+
}
|
|
42
|
+
export function readGraphState(workspace, instId) {
|
|
43
|
+
try {
|
|
44
|
+
const raw = fs.readFileSync(graphStatePathOf(workspace, instId), "utf-8");
|
|
45
|
+
const parsed = JSON.parse(raw);
|
|
46
|
+
if (!parsed || parsed.kind !== "graph" || !parsed.graph || !parsed.graph.asset)
|
|
47
|
+
return null;
|
|
48
|
+
// 宿主重开时宁可忽略一份损坏的保留实例,也不能让 restore/status 把 DSH 带崩。
|
|
49
|
+
const graph = parsed.graph;
|
|
50
|
+
if (!Array.isArray(graph.asset?.nodes))
|
|
51
|
+
return null;
|
|
52
|
+
// 主事实的位置是固定的:attempt/verdict/acceptance/todo/worktree 在 graph 下,
|
|
53
|
+
// history 在实例顶层。缺一个就拒绝,避免读到半份状态后让引擎在半路抛错。
|
|
54
|
+
for (const key of ["attempts", "verdicts", "acceptances", "human_todos", "worktrees"]) {
|
|
55
|
+
if (!Array.isArray(graph[key]))
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (!Array.isArray(parsed.history))
|
|
59
|
+
return null;
|
|
60
|
+
if (typeof graph.status !== "string")
|
|
61
|
+
return null;
|
|
62
|
+
// 读取时补齐旧状态缺的字段:集成分支名与节点 worktree 的 branch。
|
|
63
|
+
// 两者都只补名字,历史提交仍在对象库里;恢复 attempt 时 ensureNodeWorktree 把工作树切到该分支。
|
|
64
|
+
const integration = graph.integration;
|
|
65
|
+
if (integration && typeof integration.branch !== "string")
|
|
66
|
+
integration.branch = `ralphflow/${instId}`;
|
|
67
|
+
const worktrees = graph.worktrees;
|
|
68
|
+
for (const worktree of worktrees) {
|
|
69
|
+
if (typeof worktree.node_id === "string" && typeof worktree.branch !== "string") {
|
|
70
|
+
worktree.branch = nodeBranchFor(instId, worktree.node_id);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const retries = graph.integration_retries;
|
|
74
|
+
if (!retries || typeof retries !== "object")
|
|
75
|
+
graph.integration_retries = {};
|
|
76
|
+
if (typeof parsed.started_at !== "string" || typeof parsed.updated_at !== "string")
|
|
77
|
+
return null;
|
|
78
|
+
if (typeof graph.asset.id !== "string")
|
|
79
|
+
return null;
|
|
80
|
+
return parsed;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export function writeGraphState(workspace, state, instId) {
|
|
87
|
+
state.updated_at = new Date().toISOString();
|
|
88
|
+
const dir = graphInstanceDirOf(workspace, instId);
|
|
89
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
90
|
+
const target = path.join(dir, "state.json");
|
|
91
|
+
const tmp = path.join(dir, `.state.${process.pid}.tmp`);
|
|
92
|
+
fs.writeFileSync(tmp, `${JSON.stringify(state, null, 2)}\n`, "utf-8");
|
|
93
|
+
fs.renameSync(tmp, target);
|
|
94
|
+
}
|
|
95
|
+
/** 扫描本工作区所有 Graph 实例状态(包含已结束但保留的实例)。 */
|
|
96
|
+
export function listGraphStates(workspace) {
|
|
97
|
+
const dir = graphInstancesDirOf(workspace);
|
|
98
|
+
let entries = [];
|
|
99
|
+
try {
|
|
100
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const out = [];
|
|
106
|
+
for (const entry of entries) {
|
|
107
|
+
if (!entry.isDirectory())
|
|
108
|
+
continue;
|
|
109
|
+
const state = readGraphState(workspace, entry.name);
|
|
110
|
+
if (state)
|
|
111
|
+
out.push({ id: entry.name, state });
|
|
112
|
+
}
|
|
113
|
+
return out.sort((left, right) => left.state.started_at.localeCompare(right.state.started_at));
|
|
114
|
+
}
|
|
115
|
+
export function pushGraphHistory(state, event, detail, nodeId) {
|
|
116
|
+
const entry = {
|
|
117
|
+
ts: new Date().toISOString(),
|
|
118
|
+
event,
|
|
119
|
+
...(detail ? { detail } : {}),
|
|
120
|
+
...(nodeId ? { step: nodeId } : {}),
|
|
121
|
+
};
|
|
122
|
+
state.history.push(entry);
|
|
123
|
+
if (state.history.length > 200)
|
|
124
|
+
state.history.splice(0, state.history.length - 200);
|
|
125
|
+
}
|
|
126
|
+
export function attemptsOfNode(state, nodeId) {
|
|
127
|
+
return state.graph.attempts.filter((attempt) => attempt.node_id === nodeId).sort((left, right) => left.seq - right.seq);
|
|
128
|
+
}
|
|
129
|
+
export function latestAttemptOfNode(state, nodeId) {
|
|
130
|
+
return attemptsOfNode(state, nodeId).at(-1);
|
|
131
|
+
}
|
|
132
|
+
export function verdictOfAttempt(state, attemptId) {
|
|
133
|
+
return state.graph.verdicts.filter((verdict) => verdict.attempt_id === attemptId).at(-1);
|
|
134
|
+
}
|
|
135
|
+
export function acceptanceOfNode(state, nodeId) {
|
|
136
|
+
return state.graph.acceptances.filter((acceptance) => acceptance.node_id === nodeId).at(-1);
|
|
137
|
+
}
|
|
138
|
+
export function waitingTodoOfNode(state, nodeId) {
|
|
139
|
+
return state.graph.human_todos.find((todo) => todo.node_id === nodeId && todo.status === "waiting");
|
|
140
|
+
}
|
|
141
|
+
/** 节点是否已经释放下游(Flow 的「完成」等价物;Git 还要完成合入接纳)。 */
|
|
142
|
+
export function nodeReleased(state, node) {
|
|
143
|
+
const acceptance = acceptanceOfNode(state, node.id);
|
|
144
|
+
if (!acceptance)
|
|
145
|
+
return false;
|
|
146
|
+
return !state.graph.project.root || node.execution === "main" || Boolean(acceptance.integration);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 派生节点状态。**纯函数**:不读写状态、不推进,只把主事实翻译成投影。
|
|
150
|
+
* 顺序即语义:已接纳 > 已取消 > 等待人工 > 在飞 > 已交卷待验证/合入 > 待重做/失败 > 依赖阻塞 > 待开始。
|
|
151
|
+
*/
|
|
152
|
+
export function nodeStatusOf(state, node) {
|
|
153
|
+
if (acceptanceOfNode(state, node.id))
|
|
154
|
+
return "completed";
|
|
155
|
+
if (state.graph.status === "cancelled")
|
|
156
|
+
return "cancelled";
|
|
157
|
+
const attempt = latestAttemptOfNode(state, node.id);
|
|
158
|
+
const todo = waitingTodoOfNode(state, node.id);
|
|
159
|
+
if (todo)
|
|
160
|
+
return "waiting_review";
|
|
161
|
+
if (attempt?.status === "running")
|
|
162
|
+
return "running";
|
|
163
|
+
if (attempt?.status === "interrupted")
|
|
164
|
+
return "interrupted";
|
|
165
|
+
if (attempt?.status === "failed")
|
|
166
|
+
return "failed";
|
|
167
|
+
if (attempt?.status === "submitted") {
|
|
168
|
+
if (node.check && !verdictOfAttempt(state, attempt.id))
|
|
169
|
+
return "verifying";
|
|
170
|
+
if (node.check && verdictOfAttempt(state, attempt.id)?.status === "failed") {
|
|
171
|
+
const count = state.graph.rework_counts[node.id] ?? 0;
|
|
172
|
+
return count >= 2 ? "waiting" : "reworking";
|
|
173
|
+
}
|
|
174
|
+
if (node.check && verdictOfAttempt(state, attempt.id)?.status === "infra")
|
|
175
|
+
return "waiting";
|
|
176
|
+
return "integrating";
|
|
177
|
+
return "accepting";
|
|
178
|
+
}
|
|
179
|
+
if (attempt?.status === "rejected")
|
|
180
|
+
return "reworking";
|
|
181
|
+
const pending = state.graph.asset.nodes.filter((candidate) => candidate.id !== node.id);
|
|
182
|
+
const blocked = node.dependsOn.some((dependency) => {
|
|
183
|
+
const source = pending.find((candidate) => candidate.id === dependency);
|
|
184
|
+
return source ? !nodeReleased(state, source) : true;
|
|
185
|
+
});
|
|
186
|
+
return blocked ? "blocked" : "pending";
|
|
187
|
+
}
|
|
188
|
+
export const NODE_STATUS_LABELS = {
|
|
189
|
+
pending: "待开始",
|
|
190
|
+
blocked: "等待依赖",
|
|
191
|
+
running: "执行中",
|
|
192
|
+
verifying: "验证中",
|
|
193
|
+
reworking: "等待返工",
|
|
194
|
+
waiting_review: "等待你放行",
|
|
195
|
+
waiting: "等待处理",
|
|
196
|
+
integrating: "合入中",
|
|
197
|
+
accepting: "接纳中",
|
|
198
|
+
completed: "已完成",
|
|
199
|
+
failed: "失败",
|
|
200
|
+
cancelled: "已取消",
|
|
201
|
+
interrupted: "已中断",
|
|
202
|
+
};
|
|
203
|
+
export function nodeNameOf(state, node) {
|
|
204
|
+
return node.name ?? node.id;
|
|
205
|
+
}
|
|
206
|
+
function manualStatusOf(state, node) {
|
|
207
|
+
if (!state.graph.asset.manual_step.includes(node.id))
|
|
208
|
+
return "not_required";
|
|
209
|
+
const todos = state.graph.human_todos.filter((todo) => todo.node_id === node.id);
|
|
210
|
+
const latest = todos.at(-1);
|
|
211
|
+
if (!latest)
|
|
212
|
+
return "pending";
|
|
213
|
+
if (latest.status === "approved")
|
|
214
|
+
return "approved";
|
|
215
|
+
if (latest.status === "revise")
|
|
216
|
+
return "revise";
|
|
217
|
+
if (latest.status === "stale")
|
|
218
|
+
return "stale";
|
|
219
|
+
if (latest.status === "cancelled")
|
|
220
|
+
return "cancelled";
|
|
221
|
+
return "waiting";
|
|
222
|
+
}
|
|
223
|
+
function checkProjection(state, node) {
|
|
224
|
+
const attempt = latestAttemptOfNode(state, node.id);
|
|
225
|
+
const verdict = attempt ? verdictOfAttempt(state, attempt.id) : undefined;
|
|
226
|
+
const mode = node.check ? node.check.mode : "disabled";
|
|
227
|
+
if (!node.check)
|
|
228
|
+
return { mode, status: "skipped", reason: "本节点显式关闭独立 CHECK(check: null)。", reworks: state.graph.rework_counts[node.id] ?? 0 };
|
|
229
|
+
if (!verdict)
|
|
230
|
+
return { mode, status: "pending", reason: "", reworks: state.graph.rework_counts[node.id] ?? 0 };
|
|
231
|
+
return { mode, status: verdict.status, reason: verdict.reason, reworks: state.graph.rework_counts[node.id] ?? 0 };
|
|
232
|
+
}
|
|
233
|
+
export function projectionOf(state, id) {
|
|
234
|
+
const nodes = state.graph.asset.nodes.map((node) => {
|
|
235
|
+
const status = nodeStatusOf(state, node);
|
|
236
|
+
const attempt = latestAttemptOfNode(state, node.id);
|
|
237
|
+
const todo = waitingTodoOfNode(state, node.id);
|
|
238
|
+
const check = checkProjection(state, node);
|
|
239
|
+
const acceptance = acceptanceOfNode(state, node.id);
|
|
240
|
+
return {
|
|
241
|
+
id: node.id,
|
|
242
|
+
name: nodeNameOf(state, node),
|
|
243
|
+
status,
|
|
244
|
+
label: NODE_STATUS_LABELS[status],
|
|
245
|
+
dependsOn: [...node.dependsOn],
|
|
246
|
+
attempts: attemptsOfNode(state, node.id).length,
|
|
247
|
+
artifact: attempt?.artifact
|
|
248
|
+
? { path: attempt.artifact.rel ?? attempt.artifact.path, sha256: attempt.artifact.sha256, size: attempt.artifact.size }
|
|
249
|
+
: null,
|
|
250
|
+
check,
|
|
251
|
+
manual: manualStatusOf(state, node),
|
|
252
|
+
integration: !state.graph.project.root ? "not_required" : acceptance?.integration ? "accepted" : "pending",
|
|
253
|
+
integrationCommit: acceptance?.integration?.commit ?? null,
|
|
254
|
+
workspace: attempt?.workspace?.path ?? null,
|
|
255
|
+
todoId: todo?.id ?? null,
|
|
256
|
+
current: false,
|
|
257
|
+
execution: node.execution,
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
const counts = {
|
|
261
|
+
total: nodes.length,
|
|
262
|
+
completed: nodes.filter((node) => node.status === "completed").length,
|
|
263
|
+
running: nodes.filter((node) => node.status === "running" || node.status === "verifying" || node.status === "integrating" || node.status === "accepting").length,
|
|
264
|
+
waiting: nodes.filter((node) => node.status === "waiting" || node.status === "waiting_review" || node.status === "reworking").length,
|
|
265
|
+
pending: nodes.filter((node) => node.status === "pending").length,
|
|
266
|
+
blocked: nodes.filter((node) => node.status === "blocked").length,
|
|
267
|
+
};
|
|
268
|
+
const currentNode = nodes.find((node) => node.status === "running" || node.status === "verifying" || node.status === "integrating" || node.status === "accepting")
|
|
269
|
+
?? nodes.find((node) => node.status === "waiting_review" || node.status === "waiting")
|
|
270
|
+
?? nodes.find((node) => node.status === "pending" || node.status === "blocked")
|
|
271
|
+
?? null;
|
|
272
|
+
if (currentNode)
|
|
273
|
+
currentNode.current = true;
|
|
274
|
+
const waitingTodo = state.graph.human_todos.find((todo) => todo.status === "waiting");
|
|
275
|
+
const nodeWithRework = nodes.find((node) => node.status === "waiting" && (state.graph.rework_counts[node.id] ?? 0) >= 2);
|
|
276
|
+
const nextAction = waitingTodo
|
|
277
|
+
? {
|
|
278
|
+
kind: "manual_review",
|
|
279
|
+
label: "等待你放行",
|
|
280
|
+
message: `节点「${nodeNameOf(state, state.graph.asset.nodes.find((node) => node.id === waitingTodo.node_id))}」已通过独立 CHECK,等待你审查产物后明确放行或要求改稿。`,
|
|
281
|
+
todoId: waitingTodo.id,
|
|
282
|
+
nodeId: waitingTodo.node_id,
|
|
283
|
+
}
|
|
284
|
+
: state.graph.status === "paused" || state.graph.status === "interrupted" || state.graph.status === "waiting"
|
|
285
|
+
? {
|
|
286
|
+
kind: "resume",
|
|
287
|
+
label: "等待你继续",
|
|
288
|
+
message: nodeWithRework
|
|
289
|
+
? "独立 CHECK 的返工次数已达到上限;检查资产或产物后用 /ralphflow-continue 显式重试。"
|
|
290
|
+
: state.graph.status === "interrupted"
|
|
291
|
+
? "运行已中断(属主运行时已失联),用 /ralphflow-continue 继续。"
|
|
292
|
+
: state.graph.status === "waiting"
|
|
293
|
+
? "运行在等待人工处理,用 ralphflow_respond 或 /ralphflow-continue 继续。"
|
|
294
|
+
: `运行已暂停(${pauseLabel(state.graph.pause_reason ?? "paused")}),用 /ralphflow-continue 继续。`,
|
|
295
|
+
...(currentNode ? { nodeId: currentNode.id } : {}),
|
|
296
|
+
}
|
|
297
|
+
: null;
|
|
298
|
+
const delivered = nodes.filter((node) => node.status === "completed").length;
|
|
299
|
+
const unaccepted = state.graph.attempts.filter((attempt) => attempt.artifact && !attempt.artifact.accepted).length;
|
|
300
|
+
const unverified = state.graph.attempts.filter((attempt) => {
|
|
301
|
+
const node = state.graph.asset.nodes.find((candidate) => candidate.id === attempt.node_id);
|
|
302
|
+
if (!node?.check || attempt.status !== "submitted")
|
|
303
|
+
return false;
|
|
304
|
+
return !verdictOfAttempt(state, attempt.id);
|
|
305
|
+
}).length;
|
|
306
|
+
const unfinished = nodes.length - delivered;
|
|
307
|
+
const success = state.graph.status === "completed" && unfinished === 0;
|
|
308
|
+
const outcome = success ? "completed"
|
|
309
|
+
: state.graph.status === "completed" ? "incomplete"
|
|
310
|
+
: state.graph.status;
|
|
311
|
+
const phase = success ? "已完成"
|
|
312
|
+
: state.graph.status === "cancelled" ? "已取消"
|
|
313
|
+
: state.graph.status === "interrupted" ? "已中断"
|
|
314
|
+
: state.graph.status === "failed" ? "失败"
|
|
315
|
+
: state.graph.status === "paused" ? "已暂停"
|
|
316
|
+
: waitingTodo ? "等待你放行"
|
|
317
|
+
: counts.running > 0 ? "执行中"
|
|
318
|
+
: state.graph.status === "waiting" ? "等待处理" : "执行中";
|
|
319
|
+
return {
|
|
320
|
+
kind: "graph",
|
|
321
|
+
id,
|
|
322
|
+
workflow: state.workflow_name,
|
|
323
|
+
task: state.user_task,
|
|
324
|
+
status: state.graph.status,
|
|
325
|
+
phase,
|
|
326
|
+
counts,
|
|
327
|
+
current: currentNode ? { nodeId: currentNode.id, name: currentNode.name, status: currentNode.status } : null,
|
|
328
|
+
nextAction,
|
|
329
|
+
nodes,
|
|
330
|
+
integration: state.graph.integration
|
|
331
|
+
? {
|
|
332
|
+
branch: state.graph.integration.branch,
|
|
333
|
+
currentCommit: state.graph.integration.current_commit,
|
|
334
|
+
accepted: state.graph.acceptances.filter((acceptance) => acceptance.integration).length,
|
|
335
|
+
}
|
|
336
|
+
: null,
|
|
337
|
+
delivery: {
|
|
338
|
+
success,
|
|
339
|
+
outcome,
|
|
340
|
+
delivered,
|
|
341
|
+
unaccepted,
|
|
342
|
+
unverified,
|
|
343
|
+
unfinished,
|
|
344
|
+
...(success ? {} : { reason: nextAction?.message ?? `运行状态:${state.graph.status}` }),
|
|
345
|
+
},
|
|
346
|
+
startedAt: state.started_at,
|
|
347
|
+
updatedAt: state.updated_at,
|
|
348
|
+
report: isGraphTerminal(state.graph.status) ? `${RALPH_FLOW_DIR}/reports/${id}.md` : null,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/** 运行输入与提示词共用的安全路径:只接受相对路径,拒绝逃出工作区。 */
|
|
352
|
+
export function resolveInside(root, relative) {
|
|
353
|
+
const resolved = path.resolve(root, relative);
|
|
354
|
+
const rel = path.relative(path.resolve(root), resolved);
|
|
355
|
+
if (!rel || rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel))
|
|
356
|
+
return null;
|
|
357
|
+
return resolved;
|
|
358
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { INTEGRATION_BRANCH_PREFIX, NODE_BRANCH_PREFIX, integrationBranchFor, nodeBranchFor } from "./branches.js";
|
|
2
|
+
export { INTEGRATION_BRANCH_PREFIX, NODE_BRANCH_PREFIX, integrationBranchFor, nodeBranchFor };
|
|
3
|
+
export declare const WORKTREES_DIRNAME = "worktrees";
|
|
4
|
+
export declare function git(cwd: string, ...args: string[]): Promise<string>;
|
|
5
|
+
export declare function gitSafe(cwd: string, ...args: string[]): Promise<string | null>;
|
|
6
|
+
export interface ProjectSnapshot {
|
|
7
|
+
root: string;
|
|
8
|
+
baseline: string;
|
|
9
|
+
clean: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** 工作区必须是 Git 仓库且有可用 HEAD;不要求工作树干净(只记录事实)。 */
|
|
12
|
+
export declare function resolveProject(workspace: string): Promise<ProjectSnapshot>;
|
|
13
|
+
/** 集成分支从基线切出;实例被恢复时沿用它当前的分支头。 */
|
|
14
|
+
export declare function ensureIntegrationBranch(root: string, branch: string, baseline: string): Promise<string>;
|
|
15
|
+
export declare function branchTip(root: string, branch: string): Promise<string | null>;
|
|
16
|
+
/** 快进集成分支。调用方先证明节点分支包含 previous,这里只做引用前进。 */
|
|
17
|
+
export declare function advanceIntegration(root: string, branch: string, previous: string, commit: string): Promise<void>;
|
|
18
|
+
export declare function containsCommit(cwd: string, ancestor: string, descendant: string): Promise<boolean>;
|
|
19
|
+
export declare function worktreeRootOf(workspace: string, instId: string): string;
|
|
20
|
+
export declare function nodeWorktreePathOf(workspace: string, instId: string, nodeId: string): string;
|
|
21
|
+
/** 节点 worktree 建在节点自己的分支上:`git worktree add -b <branch> <path> <起点>`。 */
|
|
22
|
+
export declare function ensureNodeWorktree(root: string, workspacePath: string, branch: string, startPoint: string): Promise<{
|
|
23
|
+
path: string;
|
|
24
|
+
created: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
export type NodeReadiness = {
|
|
27
|
+
ok: true;
|
|
28
|
+
head: string;
|
|
29
|
+
aligned: boolean;
|
|
30
|
+
} | {
|
|
31
|
+
ok: false;
|
|
32
|
+
reason: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* 节点交卷后的 Git 事实:worktree 的 HEAD 在**节点分支**上、工作树没有未提交的跟踪改动,
|
|
36
|
+
* 且节点分支已经包含集成分支的最新提交。验收看的是状态里记录的节点分支,不是 worktree 的
|
|
37
|
+
* 游离 HEAD —— 在 detached HEAD 上提交再合集成线,改动没有落在节点分支上,合入时接不住。
|
|
38
|
+
*
|
|
39
|
+
* 不成立就是「合入集成分支」这一步没做——退回节点自己处理,不另起 agent 解冲突。
|
|
40
|
+
* 例外只有一个:节点没有任何提交(只交产物),它的节点分支还停在基线。这时没有内容要合,
|
|
41
|
+
* 但分支仍要跟上集成 tip(一次 `merge --ff-only`),否则“节点分支包含集成 tip”不成立,
|
|
42
|
+
* 后面节点的合入链也会断在一条旧分支上。
|
|
43
|
+
*/
|
|
44
|
+
export declare function nodeReadyForIntegration(input: {
|
|
45
|
+
worktreePath: string;
|
|
46
|
+
nodeBranch: string;
|
|
47
|
+
baseline: string;
|
|
48
|
+
integrationBranch: string;
|
|
49
|
+
integrationTip: string;
|
|
50
|
+
}): Promise<NodeReadiness>;
|
|
51
|
+
export interface WorkspaceChanges {
|
|
52
|
+
path: string;
|
|
53
|
+
sha256: string;
|
|
54
|
+
files: string[];
|
|
55
|
+
head: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 捕获节点工作区相对基线的变更快照(含节点自己的提交),供独立验证者取证。
|
|
59
|
+
* 写入 `<artifactDir>/workspace-changes.json`;内容不可信,只作证据。
|
|
60
|
+
*/
|
|
61
|
+
export declare function captureWorkspaceChanges(worktreePath: string, baseline: string, artifactDir: string): Promise<WorkspaceChanges>;
|
|
62
|
+
/** cleanup:移除干净且已登记的节点 worktree;节点提交留在它自己的分支上。 */
|
|
63
|
+
export declare function removeCleanWorktree(root: string, worktreePath: string): Promise<{
|
|
64
|
+
removed: boolean;
|
|
65
|
+
reason?: string;
|
|
66
|
+
}>;
|
|
67
|
+
/** 用户可见的相对路径(正斜杠);工作区外返回 null。 */
|
|
68
|
+
export declare function workspaceRelative(workspace: string, absolute: string): string | null;
|