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.
Files changed (87) hide show
  1. package/README.md +48 -22
  2. package/graphs/codewiki/format.md +362 -0
  3. package/graphs/codewiki/graph.yaml +39 -0
  4. package/graphs/codewiki/nodes/assemble.md +24 -0
  5. package/graphs/codewiki/nodes/core-pages.md +17 -0
  6. package/graphs/codewiki/nodes/module-pages.md +18 -0
  7. package/graphs/codewiki/nodes/operations-pages.md +18 -0
  8. package/graphs/codewiki/nodes/survey.md +22 -0
  9. package/lib/asset-path.d.ts +59 -0
  10. package/lib/asset-path.js +181 -0
  11. package/lib/assets.d.ts +42 -0
  12. package/lib/assets.js +86 -0
  13. package/lib/client/phase.d.ts +29 -0
  14. package/lib/client/phase.js +86 -0
  15. package/lib/client/selection.d.ts +28 -0
  16. package/lib/client/selection.js +9 -0
  17. package/lib/client/status-source.d.ts +3 -1
  18. package/lib/client/status-source.js +3 -2
  19. package/lib/client/status.js +49 -13
  20. package/lib/client/viewer.d.ts +18 -0
  21. package/lib/client/viewer.js +540 -0
  22. package/lib/client.js +1159 -64
  23. package/lib/engine.d.ts +111 -47
  24. package/lib/engine.js +473 -320
  25. package/lib/facade.d.ts +175 -0
  26. package/lib/facade.js +553 -0
  27. package/lib/graph/agent-registry.d.ts +4 -0
  28. package/lib/graph/agent-registry.js +20 -0
  29. package/lib/graph/asset.d.ts +47 -0
  30. package/lib/graph/asset.js +276 -0
  31. package/lib/graph/assets.d.ts +47 -0
  32. package/lib/graph/assets.js +224 -0
  33. package/lib/graph/branches.d.ts +9 -0
  34. package/lib/graph/branches.js +13 -0
  35. package/lib/graph/check.d.ts +23 -0
  36. package/lib/graph/check.js +46 -0
  37. package/lib/graph/engine.d.ts +55 -0
  38. package/lib/graph/engine.js +2002 -0
  39. package/lib/graph/report.d.ts +9 -0
  40. package/lib/graph/report.js +117 -0
  41. package/lib/graph/state.d.ts +244 -0
  42. package/lib/graph/state.js +358 -0
  43. package/lib/graph/workspace.d.ts +68 -0
  44. package/lib/graph/workspace.js +262 -0
  45. package/lib/index.d.ts +11 -1
  46. package/lib/index.js +156 -49
  47. package/lib/owner.d.ts +34 -0
  48. package/lib/owner.js +49 -0
  49. package/lib/paths.d.ts +12 -0
  50. package/lib/paths.js +44 -0
  51. package/lib/pause.d.ts +12 -0
  52. package/lib/pause.js +19 -0
  53. package/lib/skills.d.ts +17 -30
  54. package/lib/skills.js +85 -21
  55. package/lib/status-contract.d.ts +114 -1
  56. package/lib/status-contract.js +106 -4
  57. package/lib/status-service.d.ts +5 -1
  58. package/lib/status-service.js +8 -1
  59. package/lib/tools.d.ts +14 -6
  60. package/lib/tools.js +88 -60
  61. package/lib/unfinished.d.ts +11 -0
  62. package/lib/unfinished.js +18 -0
  63. package/lib/verifier-preset.d.ts +40 -0
  64. package/lib/verifier-preset.js +126 -0
  65. package/lib/verify.d.ts +82 -13
  66. package/lib/verify.js +382 -95
  67. package/package.json +50 -38
  68. package/skills/ralphflow-create/SKILL.md +32 -0
  69. package/skills/ralphflow-create/graph-authoring.md +85 -0
  70. package/skills/ralphflow-create/matt/LICENSE +21 -0
  71. package/skills/ralphflow-create/matt/SHA256SUMS +6 -0
  72. package/skills/ralphflow-create/matt/SKILL-MECHANICS.md +22 -0
  73. package/skills/ralphflow-create/matt/SOURCE.md +12 -0
  74. package/skills/ralphflow-create/matt/grilling.md +30 -0
  75. package/skills/ralphflow-create/matt/to-spec.md +75 -0
  76. package/skills/ralphflow-create/matt/to-tickets.md +105 -0
  77. package/skills/ralphflow-create/matt/writing-for-agents.md +81 -0
  78. package/skills/ralphflow-create/ralphflow-authoring.md +31 -0
  79. package/skills/ralphflow-create/testing-workflow.md +60 -0
  80. package/{references → skills/ralphflow-create}/workflow-authoring.md +25 -5
  81. package/workflows/create-graph/steps/graph.md +17 -0
  82. package/workflows/create-graph/workflow.yaml +77 -0
  83. package/workflows/loop/workflow.yaml +23 -0
  84. package/lib/create.d.ts +0 -2
  85. package/lib/create.js +0 -17
  86. package/workflows/loop.yaml +0 -45
  87. /package/workflows/{spec.yaml → spec/workflow.yaml} +0 -0
@@ -29,30 +29,132 @@ function choice(value, values) {
29
29
  throw new TypeError("unknown status variant");
30
30
  return value;
31
31
  }
32
+ function nullableString(value) {
33
+ return value === null || value === undefined ? null : string(value);
34
+ }
35
+ function parseGraphStatus(value) {
36
+ const view = record(value);
37
+ const counts = record(view.counts);
38
+ const currentRaw = view.current;
39
+ const nextRaw = view.nextAction;
40
+ const integrationRaw = view.integration;
41
+ const delivery = record(view.delivery);
42
+ return {
43
+ phase: string(view.phase),
44
+ status: string(view.status),
45
+ counts: {
46
+ total: count(counts.total), completed: count(counts.completed), running: count(counts.running),
47
+ waiting: count(counts.waiting), pending: count(counts.pending), blocked: count(counts.blocked),
48
+ },
49
+ current: currentRaw === null || currentRaw === undefined ? null : (() => {
50
+ const item = record(currentRaw);
51
+ return { nodeId: string(item.nodeId), name: string(item.name), status: string(item.status) };
52
+ })(),
53
+ nextAction: nextRaw === null || nextRaw === undefined ? null : (() => {
54
+ const item = record(nextRaw);
55
+ return {
56
+ kind: string(item.kind), label: string(item.label), message: string(item.message),
57
+ ...(item.todoId === undefined ? {} : { todoId: string(item.todoId) }),
58
+ ...(item.nodeId === undefined ? {} : { nodeId: string(item.nodeId) }),
59
+ };
60
+ })(),
61
+ nodes: array(view.nodes, (node) => {
62
+ const item = record(node);
63
+ const artifact = item.artifact;
64
+ const check = record(item.check);
65
+ return {
66
+ id: string(item.id), name: string(item.name), status: string(item.status), label: string(item.label),
67
+ dependsOn: array(item.dependsOn, string), attempts: count(item.attempts), current: bool(item.current),
68
+ execution: choice(item.execution, ["background", "main"]),
69
+ artifact: artifact === null || artifact === undefined ? null : (() => {
70
+ const a = record(artifact);
71
+ return { path: string(a.path), sha256: string(a.sha256) };
72
+ })(),
73
+ check: { mode: string(check.mode), status: string(check.status), reason: string(check.reason), reworks: count(check.reworks) },
74
+ manual: string(item.manual), integration: string(item.integration),
75
+ integrationCommit: nullableString(item.integrationCommit), todoId: nullableString(item.todoId),
76
+ };
77
+ }),
78
+ integration: integrationRaw === null || integrationRaw === undefined ? null : (() => {
79
+ const item = record(integrationRaw);
80
+ return { branch: string(item.branch), currentCommit: string(item.currentCommit), accepted: count(item.accepted) };
81
+ })(),
82
+ delivery: {
83
+ success: bool(delivery.success), outcome: string(delivery.outcome),
84
+ delivered: count(delivery.delivered), unaccepted: count(delivery.unaccepted),
85
+ unverified: count(delivery.unverified), unfinished: count(delivery.unfinished),
86
+ ...(delivery.reason === undefined ? {} : { reason: string(delivery.reason) }),
87
+ },
88
+ };
89
+ }
90
+ function parseViewerAsset(value) {
91
+ const asset = record(value);
92
+ const kind = choice(asset.kind, ["flow", "graph"]);
93
+ return {
94
+ name: string(asset.name),
95
+ kind,
96
+ description: string(asset.description),
97
+ invalid: bool(asset.invalid),
98
+ problems: array(asset.problems, string),
99
+ steps: array(asset.steps, (step) => {
100
+ const item = record(step);
101
+ return {
102
+ id: string(item.id), description: string(item.description), do: string(item.do),
103
+ checks: array(item.checks, string), input: string(item.input), output: string(item.output),
104
+ onPass: string(item.onPass), onFail: string(item.onFail), manual: bool(item.manual),
105
+ };
106
+ }),
107
+ nodes: array(asset.nodes, (node) => {
108
+ const item = record(node);
109
+ return {
110
+ id: string(item.id), name: string(item.name), do: string(item.do), artifact: string(item.artifact),
111
+ dependsOn: array(item.dependsOn, string),
112
+ inputs: array(item.inputs, (input) => { const x = record(input); return { fromNode: string(x.fromNode), artifact: string(x.artifact) }; }),
113
+ execution: choice(item.execution, ["background", "main"]),
114
+ check: string(item.check),
115
+ checkMode: item.checkMode === undefined ? "custom" : choice(item.checkMode, ["custom", "disabled"]),
116
+ manual: bool(item.manual),
117
+ };
118
+ }),
119
+ };
120
+ }
32
121
  export function parseStatusFrame(value) {
33
122
  const frame = record(value);
34
123
  let status = null;
35
124
  if (frame.status !== null) {
36
125
  const s = record(frame.status);
126
+ const kind = s.kind === "graph" ? "graph" : "flow";
37
127
  status = {
38
- id: string(s.id), workflow: string(s.workflow), task: string(s.task), step: string(s.step),
39
- stage: choice(s.stage, ["executing", "verifying", "gate", "paused", "switching", "done", "cancelled", "unavailable"]),
128
+ id: string(s.id), kind, workflow: string(s.workflow), task: string(s.task), step: string(s.step),
129
+ stage: choice(s.stage, ["executing", "verifying", "gate", "paused", "switching", "done", "cancelled", "failed", "unavailable"]),
40
130
  hint: string(s.hint), failures: count(s.failures), maxFailures: count(s.maxFailures), updatedAt: string(s.updatedAt),
41
131
  report: s.report === null ? null : string(s.report),
42
132
  steps: array(s.steps, (v) => { const x = record(v); return { id: string(x.id), description: string(x.description), current: bool(x.current), failures: count(x.failures) }; }),
43
- votes: array(s.votes, (v) => { const x = record(v); return { index: count(x.index), status: choice(x.status, ["pending", "running", "passed", "failed", "infra"]), reason: string(x.reason) }; }),
133
+ votes: array(s.votes, (v) => { const x = record(v); return { index: count(x.index), status: choice(x.status, ["pending", "running", "passed", "failed", "infra"]), reason: string(x.reason), ...(x.check === undefined ? {} : { check: string(x.check) }) }; }),
44
134
  recent: array(s.recent, (v) => { const x = record(v); return { step: string(x.step), event: string(x.event), detail: string(x.detail) }; }),
135
+ ...(kind === "graph" || s.graph !== undefined ? { graph: parseGraphStatus(s.graph) } : {}),
45
136
  };
46
137
  }
47
138
  return { kind: choice(frame.kind, ["snapshot", "update"]), sessionId: string(frame.sessionId), status,
48
- error: frame.error === null ? null : string(frame.error) };
139
+ error: frame.error === null ? null : string(frame.error),
140
+ catalog: frame.catalog === undefined ? [] : array(frame.catalog, parseViewerAsset) };
141
+ }
142
+ export function parsePauseResult(value) {
143
+ const result = record(value);
144
+ return { ok: bool(result.ok), text: string(result.text) };
49
145
  }
50
146
  const sessionCodec = { mode: "strict", typeSymbol: "@deepseek-ai/dsh-session/types#SessionId", create: () => ({ parse: string }) };
51
147
  const frameCodec = { mode: "strict", typeSymbol: "ralphflow-dsh#StatusFrame", create: () => ({ parse: parseStatusFrame }) };
148
+ const pauseCodec = { mode: "strict", typeSymbol: "ralphflow-dsh#PauseResult", create: () => ({ parse: parsePauseResult }) };
52
149
  export const statusDescriptors = [{
53
150
  id: "ralphflow-dsh#ralphflowStatus/watch", service: "ralphflowStatus", namespace: "ralphflowStatus", method: "watch",
54
151
  mode: "stream", invocation: { kind: "direct" },
55
152
  parameters: [{ name: "session", wire: "sessionId", source: "lookup", lookup: "session", codec: sessionCodec }],
56
153
  cancellation: { parameter: "signal" }, result: frameCodec,
154
+ }, {
155
+ id: "ralphflow-dsh#ralphflowStatus/pause", service: "ralphflowStatus", namespace: "ralphflowStatus", method: "pause",
156
+ invocation: { kind: "direct" },
157
+ parameters: [{ name: "session", wire: "sessionId", source: "lookup", lookup: "session", codec: sessionCodec }],
158
+ result: pauseCodec,
57
159
  }];
58
160
  export const statusRemote = { package: "ralphflow-dsh", descriptors: statusDescriptors };
@@ -1,12 +1,14 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
2
  import type { Session } from "@deepseek-ai/dsh-session";
3
3
  import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
4
- import type { StatusFrame, WorkflowStatus } from "./status-contract.js";
4
+ import type { PauseResult, StatusFrame, ViewerAsset, WorkflowStatus } from "./status-contract.js";
5
5
  export interface StatusReader {
6
6
  read(session: Session): Promise<{
7
7
  status: WorkflowStatus | null;
8
8
  error: string | null;
9
+ catalog: ViewerAsset[];
9
10
  }>;
11
+ pause(session: Session): Promise<PauseResult> | PauseResult;
10
12
  subscribe(listener: () => void): () => void;
11
13
  }
12
14
  /** The existing session lookup owns admission/resume. This face only observes that Session. */
@@ -14,5 +16,7 @@ export declare class WorkflowStatusService extends TypertRemoteService {
14
16
  private readonly reader;
15
17
  private readonly lifetime;
16
18
  constructor(ctx: Context, reader: StatusReader);
19
+ /** 用户主动暂停:状态面按钮走这里,不依赖主会话是否有在飞的回合。 */
20
+ pause(session: Session): Promise<PauseResult>;
17
21
  watch(session: Session, signal: AbortSignal): AsyncGenerator<StatusFrame>;
18
22
  }
@@ -37,11 +37,14 @@ import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
37
37
  let WorkflowStatusService = (() => {
38
38
  let _classSuper = TypertRemoteService;
39
39
  let _instanceExtraInitializers = [];
40
+ let _pause_decorators;
40
41
  let _watch_decorators;
41
42
  return class WorkflowStatusService extends _classSuper {
42
43
  static {
43
44
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
45
+ _pause_decorators = [Remote("pause")];
44
46
  _watch_decorators = [Remote({ mode: "stream" })];
47
+ __esDecorate(this, null, _pause_decorators, { kind: "method", name: "pause", static: false, private: false, access: { has: obj => "pause" in obj, get: obj => obj.pause }, metadata: _metadata }, null, _instanceExtraInitializers);
45
48
  __esDecorate(this, null, _watch_decorators, { kind: "method", name: "watch", static: false, private: false, access: { has: obj => "watch" in obj, get: obj => obj.watch }, metadata: _metadata }, null, _instanceExtraInitializers);
46
49
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
47
50
  }
@@ -52,6 +55,10 @@ let WorkflowStatusService = (() => {
52
55
  this.reader = reader;
53
56
  ctx.effect(() => () => this.lifetime.abort(), "ralphflow status stream lifetime");
54
57
  }
58
+ /** 用户主动暂停:状态面按钮走这里,不依赖主会话是否有在飞的回合。 */
59
+ async pause(session) {
60
+ return this.reader.pause(session);
61
+ }
55
62
  async *watch(session, signal) {
56
63
  signal = AbortSignal.any([signal, this.lifetime.signal]);
57
64
  let pending = true;
@@ -72,7 +79,7 @@ let WorkflowStatusService = (() => {
72
79
  const next = await this.reader.read(session);
73
80
  if (signal.aborted)
74
81
  return;
75
- yield { kind: first ? "snapshot" : "update", sessionId: session.id, ...next };
82
+ yield { kind: first ? "snapshot" : "update", sessionId: session.id, ...next, catalog: next.catalog ?? [] };
76
83
  first = false;
77
84
  }
78
85
  }
package/lib/tools.d.ts CHANGED
@@ -27,15 +27,15 @@
27
27
  */
28
28
  import type { Context } from "@deepseek-ai/cordis";
29
29
  import type { Agent } from "@deepseek-ai/dsh-agent";
30
- import type { Engine } from "./engine.js";
30
+ import type { Facade } from "./facade.js";
31
31
  export interface ToolContext {
32
32
  ctx: Context;
33
33
  /**
34
- * 按工作区取引擎(**一个工作区一个引擎**,见 index.ts 的 engineFor);缺省用进程工作区。
35
- * 第二个参数是发起会话 id(可选):引擎创建时会把该工作区的工作流补登记成快捷技能,
34
+ * 按项目根取引擎(**一个项目根一个引擎**,见 index.ts 的 engineFor);缺省用插件加载目录。
35
+ * 第二个参数是发起会话 id(可选):引擎创建时会把该项目根的工作流补登记成快捷技能,
36
36
  * 名字不合语法的工作流要**当场说清原因**给这个会话听(见 src/skills.ts)。
37
37
  */
38
- engineFor: (workspace?: string, sessionId?: string) => Engine;
38
+ engineFor: (workspace?: string, sessionId?: string) => Facade;
39
39
  /**
40
40
  * **指令**投递(唤醒)。命令语义 = 触发词:`/ralphflow-*` 的每一条投递都是「要模型接着干活」
41
41
  * (调工具、用自然语言转达或追问),因此本文件**只有指令**,没有播报 —— 播报全部由引擎
@@ -43,10 +43,18 @@ export interface ToolContext {
43
43
  * 分类审计见 `docs/v2/delivery-classification.md` 与 `scripts/delivery-classification-test.mjs`。
44
44
  */
45
45
  deliverDirective: (sessionId: string, text: string) => boolean;
46
- /** 解析发起会话的工作区(实例资产落点) */
46
+ /** 解析发起会话的项目根(实例资产落点) */
47
47
  workspaceOfSession?: (sessionId: string) => string;
48
48
  }
49
- export type ToolHandler = (args: any, agent: Agent | undefined) => Promise<string> | string;
49
+ export type ToolHandler = (args: any, agent: Agent | undefined) => Promise<string | {
50
+ text: string;
51
+ conclude?: boolean;
52
+ }> | string | {
53
+ text: string;
54
+ conclude?: boolean;
55
+ };
56
+ /** 交卷工具名:注册处与「交卷不算干活」的判定共用同一处,改名不会漏。 */
57
+ export declare const SUBMIT_TOOL_NAME = "ralphflow_submit";
50
58
  export declare function registerTools(deps: ToolContext): Map<string, ToolHandler>;
51
59
  /**
52
60
  * 注册命令面。
package/lib/tools.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineTool } from "@deepseek-ai/dsh-tools";
2
- import { CREATE_GUIDE } from "./create.js";
2
+ import { graphAgentWorkspace } from "./graph/agent-registry.js";
3
3
  /**
4
4
  * 可用**命令**清单 —— 单一事实源:命令被拒绝时给模型转达的「还能用什么」与兜底回执共用同一份,
5
5
  * 避免两处各写一遍后走样。
@@ -7,11 +7,13 @@ import { CREATE_GUIDE } from "./create.js";
7
7
  * `/ralphflow-start` 与 `/ralphflow-<工作流>` **不在**这里:它们是技能(人敲同一串字,但落成
8
8
  * 普通 `user/message` + 宿主注入技能正文),不是命令。把它们写进「可用命令」会指错面。
9
9
  */
10
- const AVAILABLE_COMMANDS = "`/ralphflow-list`、`/ralphflow-status`、`/ralphflow-continue`、`/ralphflow-reset`、`/ralphflow-rewind`、`/ralphflow-cancel`、`/ralphflow-create`、`/ralphflow-doctor`";
10
+ const AVAILABLE_COMMANDS = "`/ralphflow-list`、`/ralphflow-status`、`/ralphflow-continue`、`/ralphflow-reset`、`/ralphflow-rewind`、`/ralphflow-cancel`、`/ralphflow-doctor`、`/ralphflow-cleanup`";
11
11
  function sessionIdOf(agent) {
12
12
  return agent?.session?.id ?? null;
13
13
  }
14
14
  // ─── 工具注册 ────────────────────────────────────────────────────────────────
15
+ /** 交卷工具名:注册处与「交卷不算干活」的判定共用同一处,改名不会漏。 */
16
+ export const SUBMIT_TOOL_NAME = "ralphflow_submit";
15
17
  export function registerTools(deps) {
16
18
  const { ctx } = deps;
17
19
  const handlers = new Map();
@@ -19,26 +21,33 @@ export function registerTools(deps) {
19
21
  /**
20
22
  * 会话 → 它所在工作区的引擎。**这是所有「发现面」的唯一入口。**
21
23
  *
22
- * 引擎的根就是会话工作区,所以列表、历史、doctor、自定义工作流查找天然落在对的地方。
23
- * 以前这里是「一个引擎 + 全局索引」:引擎根是 dsh 进程的 cwd,而实例资产落在会话
24
- * 工作区——真实 GUI 里两者必然不同(`dsh web` cwd = /home/yj,会话工作区 = 仓库),
25
- * 于是自定义工作流加载不到、历史列表永远空、doctor 看不见残留。
24
+ * 引擎的根就是项目根(会话目录按原生规则归一),所以列表、历史、doctor、自定义
25
+ * 工作流查找天然落在对的地方。以前这里是「一个引擎 + 全局索引」:引擎根是 dsh 进程的
26
+ * cwd,而实例资产落在会话目录——真实 GUI 里两者必然不同(`dsh web` 从任意目录启动,
27
+ * 会话的项目根是另一个仓库),于是自定义工作流加载不到、历史列表永远空、doctor 看不见残留。
26
28
  */
27
29
  const engineOf = (agent) => {
28
30
  const sid = sessionIdOf(agent);
29
- return deps.engineFor(sid ? deps.workspaceOfSession?.(sid) : undefined, sid ?? undefined);
31
+ const agentId = agent?.id;
32
+ // Graph 节点 agent 的 cwd 是 worktree;必须用登记表回到发起实例的项目根,
33
+ // 否则工具调用会按子会话 cwd 新建第二个引擎(绑定/状态/报告全部分叉)。
34
+ const ownerWorkspace = graphAgentWorkspace(agentId);
35
+ const workspace = ownerWorkspace ?? (sid ? deps.workspaceOfSession?.(sid) : undefined);
36
+ return deps.engineFor(workspace, sid ?? undefined);
30
37
  };
31
- const startHandler = (args, agent) => {
38
+ const startHandler = async (args, agent) => {
32
39
  const sessionId = sessionIdOf(agent);
33
40
  if (!sessionId)
34
41
  return "找不到当前会话,无法启动工作流。";
35
- return engineOf(agent).start(String(args?.workflow ?? ""), String(args?.task ?? ""), sessionId).text;
42
+ const result = await engineOf(agent).start(String(args?.workflow ?? ""), String(args?.task ?? ""), sessionId);
43
+ return result.text;
36
44
  };
37
- const continueHandler = (args, agent) => {
45
+ const continueHandler = async (args, agent) => {
38
46
  const sessionId = sessionIdOf(agent);
39
47
  if (!sessionId)
40
48
  return "找不到当前会话。";
41
- return engineOf(agent).continueInstance(sessionId, args?.instance ? String(args.instance) : undefined).text;
49
+ const result = await engineOf(agent).continueInstance(sessionId, args?.instance ? String(args.instance) : undefined);
50
+ return result.text;
42
51
  };
43
52
  const statusHandler = (args, agent) => {
44
53
  const sessionId = sessionIdOf(agent);
@@ -47,55 +56,58 @@ export function registerTools(deps) {
47
56
  return engineOf(agent).statusOf(sessionId, args?.instance ? String(args.instance) : undefined).text;
48
57
  };
49
58
  const listHandler = (_args, agent) => engineOf(agent).listAll().text;
50
- const cancelHandler = (args, agent) => {
59
+ const cancelHandler = async (args, agent) => {
51
60
  const sessionId = sessionIdOf(agent);
52
61
  if (!sessionId)
53
62
  return "找不到当前会话。";
54
- return engineOf(agent).cancelInstance(sessionId, args?.instance ? String(args.instance) : undefined, args?.reason ? String(args.reason) : undefined).text;
63
+ const result = await engineOf(agent).cancelInstance(sessionId, args?.instance ? String(args.instance) : undefined, args?.reason ? String(args.reason) : undefined);
64
+ return result.text;
55
65
  };
56
- const createHandler = (args, agent) => {
57
- const idea = args?.idea ? String(args.idea).trim() : "";
58
- // 写意图:把工作流目录建好,模型随后才写得进 <workspace>/.dsh/ralph-flow/workflows/
59
- try {
60
- engineOf(agent).ensureLayout();
61
- }
62
- catch { }
63
- return idea ? `你要创建的工作流:**${idea}**\n\n---\n\n${CREATE_GUIDE}` : CREATE_GUIDE;
66
+ const doctorHandler = (args, agent) => {
67
+ const target = typeof args?.workflow === "string" && args.workflow.trim() ? args.workflow.trim() : undefined;
68
+ return engineOf(agent).diagnose(target).text;
64
69
  };
65
- const doctorHandler = (_args, agent) => engineOf(agent).diagnose().text;
66
70
  /**
67
71
  * DO 阶段交卷(dsh 原生方式:工具调用即事实,不靠正则扫自由文本)。
68
72
  * `concludeTurn` 由注册处调用,让本次工具结果结束当前回合。
69
73
  */
70
- const submitHandler = (args, agent) => {
74
+ const submitHandler = async (args, agent) => {
71
75
  const sessionId = sessionIdOf(agent);
72
76
  if (!sessionId)
73
77
  return "找不到当前会话,无法交卷。";
74
78
  const summary = args?.summary !== undefined ? String(args.summary) : undefined;
75
- return engineOf(agent).onSubmit(sessionId, summary).text;
79
+ const unfinished = Array.isArray(args?.unfinished)
80
+ ? args.unfinished.map((item) => String(item ?? "").trim()).filter((item) => item.length > 0)
81
+ : [];
82
+ const result = await engineOf(agent).onSubmit(agent, summary, unfinished);
83
+ return { text: result.text, conclude: result.ok };
76
84
  };
77
85
  const toolDefs = [
78
86
  {
79
87
  name: "ralphflow_start",
80
- description: "启动用户要求的工作流,返回当前 DO。有 `check` / `check_voting` 才独立取证判定;没有 `check` / `check_voting` 则跳过对抗性验证。",
88
+ description: "启动 Flow 或 Graph 工作流;返回当前步骤的 DO。Graph 需要 Git 隔离,缺少时按工具返回的步骤处理。",
81
89
  params: {
82
- workflow: { type: "string", required: true, description: "工作流名(loop / spec,或自定义 YAML 名)。" },
83
- task: { type: "string", required: true, description: "要完成的任务描述。" },
90
+ workflow: { type: "string", required: true, description: "工作流名(Flow:loop / spec / create-graph;Graph:codewiki;或自定义 YAML 名)。" },
91
+ task: { type: "string", description: "任务描述(Flow 必填;Graph 可选,作为任务上下文)。" },
84
92
  },
85
93
  handler: startHandler,
86
94
  },
87
95
  {
88
- name: "ralphflow_submit",
89
- description: "【DO 阶段交卷】本步完成并自查后调用,结束当前回合。有 `check` / `check_voting` 才独立取证判定;没有 `check` / `check_voting` 则跳过对抗性验证。按定义自动推进或停在审查门。",
96
+ name: SUBMIT_TOOL_NAME,
97
+ description: "【交卷】Flow 主会话交卷,或 Graph 节点 agent 提交本 attempt 的产物。`unfinished` 列出本轮结束时还没完成的事项;本轮清单做完就留空。`ralphflow_submit` 没有次数上限;被拒绝时不结束本轮。交卷结束本轮。",
90
98
  params: {
91
99
  summary: { type: "string", description: "可选:简述本步做了什么。**验证者看不到它**(T1:验证请求不含执行者自述),它仅供审查门重交去重,不是验证证据,也不作持久交接;跨步信息应写入过程文档。" },
100
+ unfinished: {
101
+ type: "array", items: { type: "string" }, required: true,
102
+ description: "本轮结束时还没完成的事项,每条一句话。本轮清单做完就留空;确实被阻塞时逐条写(引擎把清单还给你接着做)。",
103
+ },
92
104
  },
93
105
  handler: submitHandler,
94
106
  concludeTurn: true,
95
107
  },
96
108
  {
97
109
  name: "ralphflow_continue",
98
- description: "按用户明确指令放行审查门、解除暂停或接管实例。普通步骤自动推进。只在无属主时自动接管;有属主的实例必须显式给 `instance`。",
110
+ description: "按用户明确指令放行审查门、解除暂停或接管实例;接管有属主的实例时显式给 `instance`。",
99
111
  params: {
100
112
  instance: { type: "string", description: "要接管/推进的实例 ID(可前缀)。按用户指定填写;有属主的实例必须显式指定,参数本身不替代用户授权。" },
101
113
  },
@@ -117,7 +129,7 @@ export function registerTools(deps) {
117
129
  },
118
130
  {
119
131
  name: "ralphflow_cancel",
120
- description: "取消当前会话(或指定)的活跃实例:中止在飞验证者、归档报告到精确路径并销毁实例目录(报告归档失败时保留不销毁)。",
132
+ description: "取消当前会话(或指定)的活跃实例:归档报告到精确路径并销毁实例目录,产出目录保留。",
121
133
  params: {
122
134
  instance: { type: "string", description: "实例 ID(可前缀)。" },
123
135
  reason: { type: "string", description: "取消原因(可选)。" },
@@ -125,17 +137,11 @@ export function registerTools(deps) {
125
137
  handler: cancelHandler,
126
138
  },
127
139
  {
128
- name: "ralphflow_create",
129
- description: "获取自定义工作流的交互式设计指引(按需澄清 → 步骤图 → 写 YAML → doctor 校验目标定义)。",
140
+ name: "ralphflow_doctor",
141
+ description: "诊断工作流定义与实例状态:坏文件说人话、列出阻塞项。可只诊断一个工作流名或工作区资产路径。",
130
142
  params: {
131
- idea: { type: "string", description: "用户想自动化的流程想法(可选,有则附在指引前)。" },
143
+ workflow: { type: "string", description: "可选:只诊断这个工作流名或工作区资产路径(Flow / Graph);省略则诊断全部资产与实例。" },
132
144
  },
133
- handler: createHandler,
134
- },
135
- {
136
- name: "ralphflow_doctor",
137
- description: "诊断工作流定义与实例状态:坏文件说人话、列出阻塞项,修完重跑直到全部 ✅。",
138
- params: {},
139
145
  handler: doctorHandler,
140
146
  },
141
147
  ];
@@ -148,22 +154,24 @@ export function registerTools(deps) {
148
154
  output: { schema: { type: "string" }, render: (_args, value) => [{ type: "text", text: value }] },
149
155
  async execute(args, exec) {
150
156
  const out = await def.handler(args ?? {}, exec?.agent);
151
- // 交卷工具用宿主原生的 concludeTurn 结束本回合
152
- // (与 dsh-subagent-in-process-driver 的 structured_output 同款机制)。
153
- if (def.concludeTurn && typeof exec?.concludeTurn === "function") {
157
+ const text = typeof out === "string" ? out : out.text;
158
+ const conclude = typeof out === "string" ? def.concludeTurn === true : out.conclude ?? def.concludeTurn === true;
159
+ // 交卷工具用宿主原生的 concludeTurn 结束本回合(交卷被拒绝时**不**结束回合:
160
+ // 节点要留在原地补产物,而不是被机器判成 missing_submission)。
161
+ if (conclude && typeof exec?.concludeTurn === "function") {
154
162
  try {
155
163
  exec.concludeTurn();
156
164
  }
157
165
  catch { }
158
166
  }
159
- return out;
167
+ return text;
160
168
  },
161
169
  }));
162
170
  }
163
171
  // `/ralphflow-rewind` 与 `/ralphflow-reset` 一样**不注册为工具**:注册了就等于给模型一个
164
172
  // 可调用、会返回内容的实现,与「命令面固定 + 不给模型可调用的修复入口」的边界冲突
165
173
  // (design §10.10)。两者的机械动作都由命令处理器直接驱动引擎完成,见下面的 `run` 分支。
166
- // 「未实现」的占位处理函数因此不再需要:命令面从今日起没有任何「只声明不实现」的命令。
174
+ // 命令面每条都有实际处理器,没有「只声明不实现」的占位。
167
175
  return handlers;
168
176
  }
169
177
  // ─── 命令注册 ────────────────────────────────────────────────────────────────
@@ -204,7 +212,7 @@ export function registerCommands(deps) {
204
212
  const instance = parts[0] ? `,instance = \`${parts[0]}\`` : "";
205
213
  return {
206
214
  kind: "directive",
207
- text: `用户执行了 /ralphflow-status,想了解工作流进度。请调用 \`ralphflow_status\` 工具${instance}(不带参数时若本会话无实例,应显示项目里所有活跃实例的概览)。然后向用户清晰说明:工作流与当前步骤、状态(执行中/验证中/待放行/暂停及原因)、失败次数,以及**属主会话**——属于其他或已关闭会话的实例可通过 \`/ralphflow-continue <实例ID>\` 接管。若工具说该实例**已结束并销毁**,就把报告路径给用户(历史在报告里,不要在列表里找)。`,
215
+ text: `用户执行了 /ralphflow-status,想了解工作流进度。请调用 \`ralphflow_status\` 工具${instance}(不带参数时若本会话无实例,应显示项目里所有活跃实例的概览)。然后向用户清晰说明:工作流与当前步骤、状态(执行中/验证中/待放行/暂停及原因)、返工次数,以及**属主会话**——属于其他或已关闭会话的实例可通过 \`/ralphflow-continue <实例ID>\` 接管。若工具说该实例**已结束并销毁**,就把报告路径给用户(历史在报告里,不要在列表里找)。`,
208
216
  };
209
217
  },
210
218
  },
@@ -213,12 +221,12 @@ export function registerCommands(deps) {
213
221
  description: "列出可用工作流与活跃实例。示例:/ralphflow-list",
214
222
  shim: () => ({
215
223
  kind: "directive",
216
- text: "用户执行了 /ralphflow-list。请调用 `ralphflow_list` 工具获取数据,然后把「可用工作流」整理成**表格**(列:工作流 | 用途描述),把「活跃实例」按工具返回的字段简要列给用户(实例 id、工作流、任务、步骤、状态、属主),并转达工具给的「已结束的运行」报告目录。数据以工具返回为准,不要编造;没有就直说。工作流解析顺序:工作区自定义 `.dsh/ralph-flow/workflows/` > 全局 `~/.dsh/ralph-flow/workflows/` > 插件内置。",
224
+ text: "用户执行了 /ralphflow-list。请调用 `ralphflow_list` 工具获取数据,然后把「可用工作流」整理成**表格**(列:工作流 | 用途描述),把「活跃实例」按工具返回的字段简要列给用户(实例 id、工作流、任务、步骤、状态、属主),并转达工具给的「已结束的运行」报告目录。数据以工具返回为准,不要编造;没有就直说。工作流解析顺序:项目根(从当前目录向上最近的含 `.git` 的祖先目录)自定义 `.dsh/ralph-flow/workflows/` > 用户级 > 插件内置。",
217
225
  }),
218
226
  },
219
227
  {
220
228
  name: "ralphflow-cancel",
221
- description: "取消活跃实例:归档报告并销毁实例目录。示例:/ralphflow-cancel",
229
+ description: "取消活跃实例:Flow 归档报告并销毁实例目录;Graph 归档报告并保留状态/产物/worktree 供复核。示例:/ralphflow-cancel",
222
230
  input: { hint: "[实例ID] [原因]" },
223
231
  shim: (inv) => {
224
232
  const parts = inv.rawInput.trim().split(/\s+/).filter(Boolean);
@@ -231,21 +239,31 @@ export function registerCommands(deps) {
231
239
  },
232
240
  },
233
241
  {
234
- name: "ralphflow-create",
235
- description: "交互式创建自定义工作流(模型引导设计 → 写 YAML → doctor 校验)。示例:/ralphflow-create 把 C 代码迁移到 Rust",
236
- input: { hint: "[流程想法]" },
242
+ name: "ralphflow-doctor",
243
+ description: "诊断工作流定义与实例状态。示例:/ralphflow-doctor",
237
244
  shim: (inv) => ({
238
245
  kind: "directive",
239
- text: `用户想${inv.rawInput.trim() ? `创建一个工作流:${inv.rawInput.trim()}` : "创建自定义 Ralph Flow 工作流"}。请调用 \`ralphflow_create\` 工具,按它返回的创建步骤与按需参考完成定义,交接运行方式。`,
246
+ text: `用户执行了 /ralphflow-doctor${inv.rawInput.trim() ? `(目标:${inv.rawInput.trim()})` : ""},想诊断工作流与实例。请调用 \`ralphflow_doctor\` 工具${inv.rawInput.trim() ? `,workflow = \`${inv.rawInput.trim()}\`` : ""},然后把诊断为 ❌ 的每一项用通俗语言向用户说明原因与修复建议;同时转达告警;仅在无 ❌ 且无告警时说检查通过。修复动作以用户授权范围为准。`,
240
247
  }),
241
248
  },
242
249
  {
243
- name: "ralphflow-doctor",
244
- description: "诊断工作流定义与实例状态。示例:/ralphflow-doctor",
245
- shim: () => ({
246
- kind: "directive",
247
- text: "用户执行了 /ralphflow-doctor,想诊断工作流与实例。请调用 `ralphflow_doctor` 工具,然后把诊断为 ❌ 的每一项用通俗语言向用户说明原因与修复建议;同时转达告警;仅在无 ❌ 且无告警时说检查通过。修复动作以用户授权范围为准。",
248
- }),
250
+ name: "ralphflow-cleanup",
251
+ description: "清理 Graph 实例自己产生且干净的节点 worktree;不动 state、artifacts、reports。示例:/ralphflow-cleanup [实例ID](Graph only)",
252
+ input: { hint: "[实例ID]" },
253
+ run: async (inv) => {
254
+ const sid = messageSessionId(inv.agent);
255
+ if (!sid)
256
+ return { kind: "error", text: "当前会话已离线,无法清理。" };
257
+ const parts = inv.rawInput.trim().split(/\s+/).filter(Boolean);
258
+ const facade = deps.engineFor(deps.workspaceOfSession?.(sid));
259
+ if (facade.activeKindsOfSession(sid).flow && !facade.activeKindsOfSession(sid).graph) {
260
+ deps.deliverDirective(sid, "[ralphflow] 当前是 Flow 实例:Flow 没有 worktree,cleanup 不适用。**不要调用任何工具**。");
261
+ return { kind: "success" };
262
+ }
263
+ const result = await facade.cleanupInstance(parts[0]);
264
+ deps.deliverDirective(sid, `[ralphflow] /ralphflow-cleanup:${result.text}\n\n请用自然语言如实转达。`);
265
+ return { kind: "success" };
266
+ },
249
267
  },
250
268
  {
251
269
  name: "ralphflow-reset",
@@ -254,9 +272,14 @@ export function registerCommands(deps) {
254
272
  const sid = messageSessionId(inv.agent);
255
273
  if (!sid)
256
274
  return { kind: "error", text: "当前会话已离线,无法重置上下文。请刷新后重试。" };
275
+ const facade = deps.engineFor(deps.workspaceOfSession?.(sid));
276
+ if (facade.activeKindsOfSession(sid).graph) {
277
+ deps.deliverDirective(sid, "[ralphflow] 用户执行了 /ralphflow-reset,但当前是 **Graph 实例**:Graph 没有步骤上下文可重置。用 `/ralphflow-status` 看节点,必要时 `/ralphflow-continue` 恢复暂停/中断,或 `/ralphflow-cancel` 结束。**不要调用任何工具**。");
278
+ return { kind: "success" };
279
+ }
257
280
  // 机械动作在**命令处理器**里完成(不经过模型调工具):重置是程序的职责,
258
281
  // 「不赦免失败」也只有在程序手里才守得住。失败绝不抛,如实回。
259
- const res = deps.engineFor(deps.workspaceOfSession?.(sid)).resetCurrent(sid);
282
+ const res = facade.resetCurrent(sid);
260
283
  if (res.ok) {
261
284
  // 成功:引擎已在**空闲窗口**排入整段替换,并会把当前步 DO 重投 + 发一条可见告知。
262
285
  // 不给程序化卡片(命令语义 = 触发词,回复由模型/引擎消息承担)。
@@ -275,6 +298,11 @@ export function registerCommands(deps) {
275
298
  const sid = messageSessionId(inv.agent);
276
299
  if (!sid)
277
300
  return { kind: "error", text: "当前会话已离线,无法回退。请刷新后重试。" };
301
+ const facade = deps.engineFor(deps.workspaceOfSession?.(sid));
302
+ if (facade.activeKindsOfSession(sid).graph) {
303
+ deps.deliverDirective(sid, "[ralphflow] 用户执行了 /ralphflow-rewind,但当前是 **Graph 实例**:Graph 是无环 DAG,不支持回退到前序步骤;节点局部返工由 CHECK 与人工门驱动。需要换方向时取消实例并新建。用 `/ralphflow-status` 向用户说明。**不要调用任何工具**。");
304
+ return { kind: "success" };
305
+ }
278
306
  // 参数解析:`<步骤> <原因>` 两个都必填;原因是自由文本(可含空格),所以第一段是步骤、
279
307
  // 其余整段是原因。
280
308
  const parts = inv.rawInput.trim().split(/\s+/).filter(Boolean);
@@ -289,7 +317,7 @@ export function registerCommands(deps) {
289
317
  const reasonText = parts.slice(1).join(" ");
290
318
  // 机械动作在**命令处理器**里完成(不经过模型调工具):状态机倒退 + 清暂停/失败计数
291
319
  // + 强制整段替换上下文 + 重投目标步 DO,必须与机械程序的决定原子发生,不能要求模型记得去调。
292
- const res = deps.engineFor(deps.workspaceOfSession?.(sid)).rewindTo(sid, stepId, reasonText);
320
+ const res = facade.rewindTo(sid, stepId, reasonText);
293
321
  if (res.ok) {
294
322
  // 成功:引擎已在**空闲窗口**排入整段替换,并会把目标步 DO(带着原因)+ 可见告知投出。
295
323
  // 不给程序化卡片(命令语义 = 触发词,回复由模型/引擎消息承担)。
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 未完成项归一化(两个引擎共用,纯函数)。
3
+ *
4
+ * 这是**模型自述**,只决定「要不要启动验证」,不参与任何判定(T1)。
5
+ * 限条数与单条长度只为一件事:别让一段失控的自述把 `state.json` 与通知面撑爆。
6
+ * 单条 800 字符:提醒会把清单原文带回模型,200 实测会把英文技术条目(230–509
7
+ * 字符)截成半句;20 条上限仍在,体积可控。
8
+ */
9
+ export declare const UNFINISHED_MAX_ITEMS = 20;
10
+ export declare const UNFINISHED_MAX_LENGTH = 800;
11
+ export declare function normalizeUnfinished(unfinished: unknown): string[];
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 未完成项归一化(两个引擎共用,纯函数)。
3
+ *
4
+ * 这是**模型自述**,只决定「要不要启动验证」,不参与任何判定(T1)。
5
+ * 限条数与单条长度只为一件事:别让一段失控的自述把 `state.json` 与通知面撑爆。
6
+ * 单条 800 字符:提醒会把清单原文带回模型,200 实测会把英文技术条目(230–509
7
+ * 字符)截成半句;20 条上限仍在,体积可控。
8
+ */
9
+ export const UNFINISHED_MAX_ITEMS = 20;
10
+ export const UNFINISHED_MAX_LENGTH = 800;
11
+ export function normalizeUnfinished(unfinished) {
12
+ if (!Array.isArray(unfinished))
13
+ return [];
14
+ return unfinished
15
+ .map((item) => String(item ?? "").trim().slice(0, UNFINISHED_MAX_LENGTH))
16
+ .filter((item) => item.length > 0)
17
+ .slice(0, UNFINISHED_MAX_ITEMS);
18
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Ralph Flow for dsh v2 — 验证者 Agent Preset(0.2.1-rc.2+)
3
+ *
4
+ * 0.2.1-rc.2 起 DSH 删除了子代理 start() 的 `persona` / `toolFilter` 入口:
5
+ * 这两个能力只能通过 Agent Preset 声明。验证者的「独立 + 有纪律的只读裁判」身份
6
+ * 因此从逐次请求参数下沉为一份**注册到宿主的 preset**:
7
+ *
8
+ * - persona 行:`@deepseek-ai/dsh-persona`,正文来自 `VERIFIER_PERSONA`(仍单一来源);
9
+ * - 工具面:只挂 read / read_image / grep / glob / bash(含 Windows 的 pwsh 分支),
10
+ * 不挂 write / edit —— 验证者拿不到写工具,而不是靠提示词自律;
11
+ * - compaction:长取证不因上下文膨胀而中断(与宿主 standard preset 同款)。
12
+ *
13
+ * preset 在插件 apply 时注册到 `agentPresets` 服务;验证调用带 `agentPreset` 选择它。
14
+ * 服务不存在(如 headless 组合未装 preset registry)时注册不会发生,验证调用会在
15
+ * `start()` 处失败并落到 infra 判定 —— 仍然 fail-closed,绝不生成通过判定。
16
+ */
17
+ import type { Context } from "@deepseek-ai/cordis";
18
+ /** 验证者 preset 的声明形状(与 `@deepseek-ai/dsh-agent-preset` 的 Config 对齐)。 */
19
+ export interface VerifierPresetDefinition {
20
+ id: string;
21
+ name: string;
22
+ description: string;
23
+ order: number;
24
+ plugins: unknown[];
25
+ }
26
+ /**
27
+ * 验证者 preset 的完整声明。
28
+ *
29
+ * 行 id 固定(persona/tool-fs/tool-fs-search/bash/pwsh/compaction),方便在
30
+ * 宿主 preset 编辑器中辨认;preset id 由 verify.ts 的 `VERIFIER_PRESET_ID` 唯一来源。
31
+ */
32
+ export declare function verifierPresetDefinition(): VerifierPresetDefinition;
33
+ /**
34
+ * 注册验证者 preset(best-effort、幂等)。
35
+ *
36
+ * 宿主若尚未激活 `agentPresets` 服务,会等它出现后再注册;始终不激活时不会注册,
37
+ * 验证调用随后 fail-closed。返回值只表示**本次**是否已经发起注册,便于诊断;
38
+ * 调用方不需要等待它(preset 注册与首次验证之间隔着用户的启动/交卷动作)。
39
+ */
40
+ export declare function registerVerifierPreset(ctx: Context): Promise<boolean>;