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
@@ -0,0 +1,126 @@
1
+ import { VERIFIER_PERSONA, VERIFIER_PRESET_ID } from "./verify.js";
2
+ /**
3
+ * 验证者 preset 的完整声明。
4
+ *
5
+ * 行 id 固定(persona/tool-fs/tool-fs-search/bash/pwsh/compaction),方便在
6
+ * 宿主 preset 编辑器中辨认;preset id 由 verify.ts 的 `VERIFIER_PRESET_ID` 唯一来源。
7
+ */
8
+ export function verifierPresetDefinition() {
9
+ const windows = process.platform === "win32";
10
+ return {
11
+ id: VERIFIER_PRESET_ID,
12
+ name: "Ralph Flow Verifier",
13
+ description: "Ralph Flow 的独立只读验证者:只读工具 + 对抗性取证纪律,不写交付物。",
14
+ order: 90,
15
+ plugins: [
16
+ {
17
+ id: "persona",
18
+ name: "@deepseek-ai/dsh-persona",
19
+ config: { prefix: VERIFIER_PERSONA },
20
+ },
21
+ {
22
+ id: "tool-fs",
23
+ name: "@deepseek-ai/dsh-tool-fs",
24
+ config: { read: true, readImage: true, write: false, edit: false },
25
+ },
26
+ {
27
+ id: "tool-fs-search",
28
+ name: "@deepseek-ai/dsh-tool-fs-search",
29
+ config: { sampleOverCapGlobResults: false },
30
+ },
31
+ {
32
+ id: "tool-bash",
33
+ name: "@deepseek-ai/dsh-tool-bash",
34
+ disabled: windows,
35
+ },
36
+ {
37
+ id: "tool-pwsh",
38
+ name: "@deepseek-ai/dsh-tool-pwsh",
39
+ disabled: !windows,
40
+ },
41
+ {
42
+ id: "compaction",
43
+ name: "cordis:group",
44
+ group: true,
45
+ isolate: { compaction: true },
46
+ config: [
47
+ { id: "compaction-basic", name: "@deepseek-ai/dsh-compaction-basic" },
48
+ { id: "command-compact", name: "@deepseek-ai/dsh-command-compact" },
49
+ ],
50
+ },
51
+ ],
52
+ };
53
+ }
54
+ function registryOf(ctx) {
55
+ try {
56
+ const registry = ctx.get?.("agentPresets");
57
+ return registry && typeof registry.register === "function" ? registry : undefined;
58
+ }
59
+ catch {
60
+ return undefined;
61
+ }
62
+ }
63
+ function logRegisterFailure(ctx, message) {
64
+ try {
65
+ ctx.logger?.warn?.(`[ralphflow] 验证者 preset 注册失败:${message}`);
66
+ }
67
+ catch { }
68
+ }
69
+ /** 每个宿主 registry 只注册一次:验证并发时不重复注册同一 id。 */
70
+ const registrations = new WeakMap();
71
+ /** 缺少 agentPresets 的宿主只尝试一次等待,避免每轮验证都挂一个新的 inject effect。 */
72
+ const attemptedWithoutRegistry = new WeakSet();
73
+ function registerWith(ctx, registry) {
74
+ return registry.register(verifierPresetDefinition())
75
+ .then((dispose) => {
76
+ // HMR/卸载时注销 preset,避免旧 persona/工具面在进程里滞留。
77
+ try {
78
+ const effect = ctx.effect;
79
+ if (typeof effect === "function")
80
+ effect(() => dispose, "ralphflow-verifier-preset");
81
+ }
82
+ catch { }
83
+ return true;
84
+ })
85
+ .catch((error) => {
86
+ const message = error instanceof Error ? error.message : String(error);
87
+ // 插件热重载/重复 apply 会再次注册:同一个 preset 已存在视为就绪。
88
+ if (/Duplicate agent preset/i.test(message))
89
+ return true;
90
+ logRegisterFailure(ctx, message);
91
+ return false;
92
+ });
93
+ }
94
+ /**
95
+ * 注册验证者 preset(best-effort、幂等)。
96
+ *
97
+ * 宿主若尚未激活 `agentPresets` 服务,会等它出现后再注册;始终不激活时不会注册,
98
+ * 验证调用随后 fail-closed。返回值只表示**本次**是否已经发起注册,便于诊断;
99
+ * 调用方不需要等待它(preset 注册与首次验证之间隔着用户的启动/交卷动作)。
100
+ */
101
+ export function registerVerifierPreset(ctx) {
102
+ const registry = registryOf(ctx);
103
+ if (registry) {
104
+ const existing = registrations.get(registry);
105
+ if (existing)
106
+ return existing;
107
+ const ready = registerWith(ctx, registry);
108
+ registrations.set(registry, ready);
109
+ return ready;
110
+ }
111
+ // 最小测试上下文(没有 Cordis 的 get())不代管 preset:调用方自会提供替身。
112
+ if (typeof ctx.get !== "function")
113
+ return Promise.resolve(true);
114
+ if (attemptedWithoutRegistry.has(ctx))
115
+ return Promise.resolve(false);
116
+ attemptedWithoutRegistry.add(ctx);
117
+ try {
118
+ ctx.inject?.(["agentPresets"], (child) => {
119
+ const late = registryOf(child);
120
+ if (late && !registrations.has(late))
121
+ registrations.set(late, registerWith(ctx, late));
122
+ });
123
+ }
124
+ catch { }
125
+ return Promise.resolve(false);
126
+ }
package/lib/verify.d.ts CHANGED
@@ -5,19 +5,23 @@
5
5
  * - 委派只从引擎发出(主会话没有任何路径影响这里的 prompt 构造或判定解析)。
6
6
  * - 验证者是全新独立会话:只见任务 + 检查依据 +(可读的工作区),
7
7
  * 永远看不到主会话对话历史,也**看不到执行者的交卷摘要**(T1 硬规则)。
8
- * - 验证者身份是 Ralphflow 的**内部定义**(`VERIFIER_PERSONA`,单一来源),经 DSH 原生
9
- * 子代理 `persona` 通道传入;后端**按能力**选择(全新上下文 + persona/toolFilter),
10
- * 工作流不再有任何入口影响它。
8
+ * - 验证者身份是 Ralphflow 的**内部定义**(`VERIFIER_PERSONA`,单一来源):在 dsh
9
+ * 0.2.1-rc.2+ 经 Agent Preset 的 persona 行与插件行传入;0.2.0/0.2.1-alpha 经
10
+ * 子代理请求的 `persona` / `toolFilter` 传入。后端**按能力**选择(全新上下文),
11
+ * 工作流没有任何入口影响它。
11
12
  * - 判定 fail-closed:结构化输出优先,文本标签兜底,两者都解析不出 → infra(不计失败)。
12
13
  * - 只有读工具(含 bash 供取证跑测试);bash 内的间接写是与其它版本对齐的有意接受的弱点。
13
14
  */
14
15
  import type { Context } from "@deepseek-ai/cordis";
15
16
  import type { Verdict, VerifyRequest } from "./engine.js";
17
+ /** 验证者 preset id:与 verifier-preset.ts 的声明共用同一常量。 */
18
+ export declare const VERIFIER_PRESET_ID = "ralphflow-verifier";
16
19
  /**
17
20
  * 验证者角色说明 —— Ralphflow 的**内部定义,单一来源**。
18
21
  *
19
- * 它不再是被拼进任务消息正文的「system prompt」,而是通过 DSH 原生的子代理 `persona`
20
- * 传入(在子代理 scope 注册 `deployment:persona-prefix` 系统提示段,是角色说明的正确通道)。
22
+ * 它不再是被拼进任务消息正文的「system prompt」:0.2.1-rc.2+ 经 `ralphflow-verifier`
23
+ * Agent Preset 的 persona 行(`@deepseek-ai/dsh-persona`)传入;旧版宿主经子代理请求的
24
+ * `persona` 参数传入。两条通道都落在子代理 scope 的 `deployment:persona-prefix` 系统提示段。
21
25
  *
22
26
  * **切分线**:persona 只承载「你是谁、你的纪律」(独立性、只读取证、不采信自述);本次任务的
23
27
  * 事实与**按 `wantStructured` 分支的判定提交方式**(`structured_output` 工具 /
@@ -27,31 +31,96 @@ import type { Verdict, VerifyRequest } from "./engine.js";
27
31
  export declare const VERIFIER_PERSONA = "\u4F60\u662F\u72EC\u7ACB\u9A8C\u8BC1\u8005\uFF1A\u6309\u672C\u6B21\u68C0\u67E5\u4F9D\u636E\u53D6\u8BC1\u540E\u5224\u5B9A\uFF0C\u4EA7\u51FA\u4F9B\u6267\u884C\u8005\u4FEE\u590D\u3001\u4F9B\u7528\u6237\u590D\u6838\u7684\u7ED3\u8BBA\u3002\n\n\u7EAA\u5F8B\uFF1A\n- \u4F60\u6709\u5168\u65B0\u4E0A\u4E0B\u6587\uFF0C\u770B\u4E0D\u5230\u6267\u884C\u8005\u5BF9\u8BDD\u6216\u4EA4\u5377\u6458\u8981\u3002\u4EE5\u4EFB\u52A1\u6D88\u606F\u4E2D\u7684\u4EFB\u52A1\u3001\u4EA4\u4ED8\u7269\u4E0E\u672C\u7968\u68C0\u67E5\u4F9D\u636E\u786E\u5B9A\u9A8C\u6536\u8303\u56F4\uFF1B\u5176\u4E2D\u7684 DO \u662F\u88AB\u9A8C\u6536\u5DE5\u4F5C\u7684\u8BF4\u660E\uFF0C\u4E0D\u662F\u8981\u6C42\u4F60\u518D\u505A\u4E00\u904D\u3002\n- \u7528\u5DE5\u5177\u8BFB\u53D6\u5B9E\u9645\u4EA7\u51FA\u3001\u641C\u7D22\u76F8\u5173\u5B9E\u73B0\u3001\u8FD0\u884C\u5FC5\u8981\u7684\u9A8C\u8BC1\u547D\u4EE4\u3002\u53EA\u8BFB\u53D6\u8BC1\uFF1A\u4FDD\u6301\u88AB\u9A8C\u6536\u7684\u6E90\u7801\u3001\u6587\u6863\u4E0E\u914D\u7F6E\u4E0D\u53D8\uFF1B\u9A8C\u8BC1\u547D\u4EE4\u82E5\u4F1A\u6539\u5199\u4EA4\u4ED8\u7269\uFF0C\u9009\u62E9\u4E0D\u4F1A\u6539\u5199\u7684\u68C0\u67E5\u65B9\u5F0F\u5E76\u8BF4\u660E\u53D6\u8BC1\u9650\u5236\u3002\n- \u53EA\u770B\u7ED3\u679C\uFF1A\u4E0D\u91C7\u4FE1\u4EFB\u4F55\u6267\u884C\u8005\u81EA\u8FF0\u6216\u5B9E\u73B0\u603B\u7ED3\u4F5C\u4E3A\u5B8C\u6210\u8BC1\u636E\u3002\u6587\u6863\u672C\u8EAB\u662F\u4EA4\u4ED8\u7269\u65F6\u6838\u5BF9\u5176\u5185\u5BB9\uFF1B\u6E05\u5355\u52FE\u9009\u4E0E\u6458\u8981\u4E2D\u7684\u58F0\u660E\u987B\u7528\u5B9E\u9645\u4EA7\u51FA\u4EA4\u53C9\u9A8C\u8BC1\u3002\n- \u9ED8\u8BA4\u4E0D\u901A\u8FC7\uFF0C\u53EA\u6709\u68C0\u67E5\u4F9D\u636E\u9010\u9879\u6709\u4E8B\u5B9E\u652F\u6301\u624D\u901A\u8FC7\u3002\u9A8C\u6536\u8303\u56F4\u6765\u81EA\u65E2\u5B9A\u8981\u6C42\uFF0C\u4E0D\u989D\u5916\u53D1\u660E\u529F\u80FD\u3001\u5DE5\u5177\u94FE\u6216\u4EE3\u7801\u98CE\u683C\u8981\u6C42\u3002\u53D6\u8BC1\u53D7\u9650\u65F6\u5177\u4F53\u8BF4\u660E\u7F3A\u5C11\u4EC0\u4E48\u8BC1\u636E\u3002\n- \u6309\u4EFB\u52A1\u6D88\u606F\u672B\u5C3E\u7ED9\u51FA\u7684\u65B9\u5F0F\u63D0\u4EA4\u5224\u5B9A\u7ED3\u679C\u3002";
28
32
  export interface VerifyDeps {
29
33
  ctx: Context;
34
+ /**
35
+ * 0.2.1-rc.2+:验证者 preset 的注册就绪检查(由插件装配传入)。
36
+ * 未提供(例如直接调用 runVerifier 的单元测试替身)时跳过检查。
37
+ */
38
+ ensurePreset?: () => Promise<boolean>;
39
+ /**
40
+ * 验证者后端名:来自插件配置键 {@link VERIFIER_PROVIDER_CONFIG_KEY},默认
41
+ * {@link DEFAULT_VERIFIER_PROVIDER}。测试替身可直接传入。
42
+ */
43
+ providerName?: string;
30
44
  }
45
+ /** 插件配置键:验证者使用哪个 `ctx.subagents` provider。 */
46
+ export declare const VERIFIER_PROVIDER_CONFIG_KEY = "verifierProvider";
47
+ /** 默认验证者后端:dsh 0.2.2 的 `spawn`(全新上下文 + Agent Preset)。 */
48
+ export declare const DEFAULT_VERIFIER_PROVIDER = "spawn";
31
49
  export interface BackendSelection {
32
50
  name?: string;
51
+ /** preset = 0.2.1-rc.2+;legacy = 旧版 persona/toolFilter 通道。 */
52
+ mode?: "preset" | "legacy";
33
53
  reason?: string;
34
54
  }
35
55
  /**
36
- * 选择独立验证者后端 —— **按能力判定,不按名字判定**。
56
+ * 选择独立验证者后端 —— **按配置名解析,按能力校验**。
37
57
  *
38
- * - 只考虑 `inheritsParentContext === false` 的 provider(全新上下文)。**绝不**回退到
58
+ * - provider 名来自插件配置(`verifierProvider`,默认 `spawn`)。dsh 0.2.2-rc.3 的
59
+ * `SubagentRuntime` 已删除 `list()`:宿主自己的委派插件也按配置名 + `getProvider()`
60
+ * 解析,不认识的名字等 `subagent/provider-added`(有上限)。
61
+ * - 只接受 `inheritsParentContext === false` 的 provider(全新上下文)。**绝不**回退到
39
62
  * `true` 的 provider:`fork` 会继承主会话历史,T1 会静默失效。未声明该字段的 provider
40
63
  * 同样不选(无法证明是全新上下文 → fail-closed)。
41
- * - 候选里优先 `capabilities.persona && capabilities.toolFilter` 都支持的:这两项是
42
- * 「独立 + 有纪律的只读裁判」的前置条件,缺失时 `start()` 本就会抛
43
- * `UNSUPPORTED_CAPABILITY`,所以直接选支持的那个,不等到抛错。
44
- * - provider 名可配置(`providerName`),**名字不参与判定**。
64
+ * - 优先 `capabilities.agentPreset === true`(0.2.1-rc.2+:persona 与只读工具面
65
+ * 只能经 Agent Preset 声明);为兼容仍声明 `persona && toolFilter` 的旧版后端,
66
+ * 在缺少 preset 能力时使用 legacy 通道。两者都没有 → fail-closed。
45
67
  * - 没有可用后端时返回 `reason`,由调用方转成 infra 判定 —— 绝不生成通过判定。
68
+ *
69
+ * @param ctx - 插件上下文(`ctx.subagents` + 事件面)。
70
+ * @param providerName - 期望的 provider 名;缺省为 `spawn`。
71
+ * @param waitMs - 等待 `subagent/provider-added` 的上限;测试可缩短。
46
72
  */
47
- export declare function selectBackend(ctx: Context): BackendSelection;
73
+ export declare function selectBackend(ctx: Context, providerName?: string, waitMs?: number): Promise<BackendSelection>;
48
74
  /** CHECK 提示词构造(导出供测试直接断言 §1.3 的 desc/交付物/产出目录) */
49
75
  export declare function buildCheckPrompt(req: VerifyRequest, wantStructured: boolean): string;
76
+ /**
77
+ * Graph CHECK 提示词:任务/节点 DO、冻结产物、声明输入、工作区变更与逐条判据。
78
+ * 与 Flow 的差异只在**事实形状**;角色纪律仍在 VERIFIER_PERSONA,判定通道仍是同一条
79
+ * `runVerifier`(T1)。执行者自述不进来。
80
+ */
81
+ export declare function buildGraphCheckPrompt(req: VerifyRequest, wantStructured: boolean): string;
82
+ export declare const GRAPH_VERIFIER_OUTPUT_SCHEMA: {
83
+ readonly type: "object";
84
+ readonly properties: {
85
+ readonly passed: {
86
+ readonly type: "boolean";
87
+ };
88
+ readonly reason: {
89
+ readonly type: "string";
90
+ };
91
+ readonly evidence: {
92
+ readonly type: "array";
93
+ readonly items: {
94
+ readonly type: "object";
95
+ readonly properties: {
96
+ readonly criterion: {
97
+ readonly type: "string";
98
+ };
99
+ readonly passed: {
100
+ readonly type: "boolean";
101
+ };
102
+ readonly evidence: {
103
+ readonly type: "string";
104
+ };
105
+ };
106
+ readonly required: readonly ["criterion", "passed", "evidence"];
107
+ readonly additionalProperties: false;
108
+ };
109
+ };
110
+ };
111
+ readonly required: readonly ["passed", "reason", "evidence"];
112
+ readonly additionalProperties: false;
113
+ };
114
+ /** Graph 结构化判定的机械校验:逐条证据齐全、顺序/原文一致、总判定与单项一致。 */
115
+ export declare function parseGraphVerdict(raw: {
116
+ structured?: unknown;
117
+ output?: unknown;
118
+ stopReason?: string;
119
+ }, req: VerifyRequest, checkIndex: number): Verdict;
50
120
  /** 验证者判定解析:结构化优先,文本标签兜底,解析不出 → infra(fail-closed) */
51
121
  export declare function parseVerdict(raw: {
52
122
  structured?: unknown;
53
123
  output?: unknown;
54
124
  stopReason?: string;
55
125
  }, stepId: string, checkIndex: number): Verdict;
56
- /** 委派一个独立验证者并返回判定(T1 的唯一入口,由引擎调用) */
57
126
  export declare function runVerifier(deps: VerifyDeps, req: VerifyRequest): Promise<Verdict>;