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,18 @@
1
+ # operations-pages
2
+
3
+ ## 做什么
4
+
5
+ 以资产目录 `format.md` 的 §页面契约 与 §manifest.json 契约为准;repository、outputDir、language 以 plan 为准。
6
+
7
+ 1. 从 plan.pages 取出 owner 为 operations-pages 的页面。完成条件:恰好是 interfaces.md 与 operations.md。
8
+ 2. 阅读接口、配置、构建、测试、CI/CD、部署、可观测性、安全、性能相关文件与命令。完成条件:每个接口、命令和配置都有来源;无法验证的内容列入「未覆盖与假设」;N/A 项写明检查过的路径。
9
+ 3. 按 §页面契约 写两页。完成条件:两页通过 §页面验收清单;每个命令与仓库文件一致。
10
+ 4. 用原生 write 写页面,用 ralphflow_artifact_write 写 `.ralphflow-codewiki/manifests/operations.json`。完成条件:符合 §manifest.json 契约,files 与实际文件一致。
11
+ 5. 完成自检。完成条件:按 §页面验收清单 自查,逐条给出证据。
12
+
13
+ ## 验收
14
+
15
+ 1. 按资产目录 `format.md` 的 §页面验收清单 逐条核对并给出证据。
16
+ 2. manifest 符合 §manifest.json 契约;files 恰好是 owner 为 operations-pages 的页面,字段与实际文件一致。
17
+ 3. 页面集合恰好是 interfaces.md 与 operations.md。
18
+ 4. N/A 项写明检查过的路径。
@@ -0,0 +1,22 @@
1
+ # survey
2
+
3
+ ## 做什么
4
+
5
+ 以资产目录 `format.md` 为准(输出树、页面契约、模块树规则与 schema)。任务未指定时 repository 用 `.`、outputDir 用 `docs/codewiki`、language 用 `zh-CN`;确定后写进 plan,后续只读。
6
+
7
+ 1. 检查路径与输出安全。完成条件:repository、outputDir 是工作区内相对路径;outputDir 是目录或不存在,不等于 repository 根与 `.ralphflow-codewiki`,且为空或本工作流先前生成的目录(§输出树)。用原生 bash 清空并重建 `.ralphflow-codewiki/`;plan、manifests、delivery 由 ralphflow_artifact_write 写入 artifact store。
8
+ 2. 处理先前输出。完成条件:只删除 §输出树 记录的旧文件与 metadata.json、index.md,再删空目录,outputDir 为空。冲突时(outputDir 是文件、含计划外文件、记录有越界路径)把 plan.status 设为 blocked、blocked_reason 写明冲突路径,跳到第 7 步,冲突文件保持原样。
9
+ 3. 扫描 repository。完成条件:记录语言、源根、入口点、包清单、构建/测试/lint/CI 配置与模块导入边,每项带路径来源;排除范围见 §模块树规则。
10
+ 4. 建立模块树。完成条件:按 §模块树规则 生成 modules;每个未排除源文件属于一个模块或 coverage.uncovered;模块按 slug 字典序。
11
+ 5. 制定页面计划并写 format 快照。完成条件:pages 覆盖 §输出树 的全部页面,字段齐全(§页面契约),owner 按固定映射,模块页与 modules 一一对应;plan.format 与 §页面契约 逐字一致。
12
+ 6. 用 ralphflow_artifact_write 写 `.ralphflow-codewiki/plan.json`。完成条件:符合 §plan.json 契约;source.commit 与 dirty 来自 git 事实;commands 含 build、test、lint;无法确认的项写入 assumptions。
13
+ 7. 完成自检。完成条件:ready 时所有 source_paths 在 repository 下存在;blocked 时 blocked_reason 与冲突一致;文件不含 TODO、TBD 或占位符。
14
+
15
+ ## 验收
16
+
17
+ 1. plan.json 符合资产目录 `format.md` 的 §plan.json 契约,status 为 ready,source.repository、source.outputDir、format.language 与任务文本或默认值一致。
18
+ 2. pages 覆盖 §输出树 的全部页面,字段齐全(§页面契约),owner 符合固定映射,模块页与 modules 一一对应,路径无重复;plan.format 与 §页面契约 逐字一致。
19
+ 3. modules 满足 §模块树规则:数量上限、slug 唯一、other 聚合与覆盖要求成立;每个 source_paths 在 repository 下存在。
20
+ 4. source.source_roots 与 commands 的来源路径都在 repository 下存在;languages 由实际文件统计得出;无法确认的项在 assumptions 中说明。
21
+ 5. 输出目录安全:ready 时没有删除或覆盖计划外文件的证据;blocked 时 blocked_reason 与实际冲突一致。
22
+ 6. plan.json 可解析,generated_at 是有效 ISO 8601 时间,不含 TODO、TBD 或占位符。
@@ -0,0 +1,59 @@
1
+ /** 目录形态的 Flow 入口文件名。 */
2
+ export declare const FLOW_ENTRY_FILE = "workflow.yaml";
3
+ /** 目录形态的 Graph 入口文件名。 */
4
+ export declare const GRAPH_ENTRY_FILE = "graph.yaml";
5
+ /** 一个资产在某个目录里的候选入口:目录形态优先,其次是兼容的单文件形态。 */
6
+ export declare function assetCandidates(dir: string, name: string, entryFile: string): string[];
7
+ /** 某个目录里该资产的入口文件(目录形态优先);没有就 undefined。 */
8
+ export declare function assetFileIn(dir: string, name: string, entryFile: string): string | undefined;
9
+ /** 参考根:入口文件所在目录。没有加载到资产时没有根。 */
10
+ export declare function assetRootOf(entryPath: string | undefined): string | undefined;
11
+ /**
12
+ * 从入口路径推导资产名:目录形态取父目录名,单文件形态取文件名去掉扩展名。
13
+ *
14
+ * 目录形态的判据只有一条:入口文件位于**资产根**(`workflows/` / `graphs/`)下一层,
15
+ * 即 `workflows/<name>/workflow.yaml`、`graphs/<name>/graph.yaml`。不在这一层里的
16
+ * `workflow.yaml` / `graph.yaml` 是兼容形态的**单文件资产**(名为 `workflow` / `graph`),
17
+ * 不能因为扩展名前缀恰好撞上固定入口名就被读成目录形态。
18
+ *
19
+ * 名字规则只写在路径层:doctor 的路径参数与以后任何「拿一个入口路径问名字」的调用都走这里,
20
+ * 不在调用方各自 `path.basename(...).replace(...)`。
21
+ */
22
+ export declare function assetNameOf(entryPath: string): string;
23
+ export interface AssetEntry {
24
+ /** 入口文件路径。 */
25
+ file: string;
26
+ /** 资产名(目录形态取目录名,单文件形态取文件名)。 */
27
+ name: string;
28
+ }
29
+ /**
30
+ * 把一个路径解析成资产入口:入口文件本身,或包含 `workflow.yaml` / `graph.yaml` 的资产目录。
31
+ *
32
+ * 只接受真实存在的文件或目录;解析不出来返回 undefined,由调用方说清合法形态。
33
+ */
34
+ export declare function assetEntryAt(target: string): AssetEntry | undefined;
35
+ /**
36
+ * 列出一个目录里的全部资产入口(名字 → 入口文件)。
37
+ *
38
+ * 目录形态优先:同名时以 `<name>/<entryFile>` 为准。不读内容、不建目录。
39
+ *
40
+ * 用 `statSync` 判断类型(跟随符号链接),与 `loadWorkflow` 的 `statSync` 口径一致:
41
+ * 软链到目录或 YAML 的资产同样能被 list / doctor / 动态技能发现,不在发现面与加载面分叉。
42
+ */
43
+ export declare function discoverAssetsIn(dir: string, entryFile: string): Map<string, string>;
44
+ /**
45
+ * DO 与 CHECK 提示词里同一段「资产目录」说明(没有资产路径时返回 undefined)。
46
+ *
47
+ * 与 dsh 注入 Skill 资源根的两句同构(名词不同):模型在 Skill 里见过同一个形状,迁过来没有
48
+ * 新概念。**只在这里写一次** —— Flow/Graph × 执行者/验证者四处注入点都引用它。
49
+ *
50
+ * 这一节只说**资产资源**的参考根;过程记录与交付物的落点由 {@link placementSection} 说。
51
+ */
52
+ export declare function assetReferenceSection(root: string | undefined): string | undefined;
53
+ /**
54
+ * 过程记录 / 交付物 的落点段。DO 与 CHECK 共用这一份文案。
55
+ *
56
+ * 判据是**概念**(过程记录 vs 交付物),不是路径写法:过程记录一律落 `rel`,交付物落工作
57
+ * 目录或 `output` 写明的路径。`rel` 由调用方传入(现有 `artifactsRelDir`)。
58
+ */
59
+ export declare function placementSection(rel: string, forVerifier?: boolean): string;
@@ -0,0 +1,181 @@
1
+ /**
2
+ * 资产形态:**一个目录 + 固定入口文件**,或兼容的**单文件**。
3
+ *
4
+ * ```text
5
+ * workflows/<name>/workflow.yaml ← 目录形态(推荐)
6
+ * workflows/<name>.yaml ← 单文件形态(兼容)
7
+ * graphs/<name>/graph.yaml
8
+ * graphs/<name>.yaml
9
+ * ```
10
+ *
11
+ * 两种形态的**参考根都是入口文件所在目录** —— 与 dsh 的 Skill 完全同构
12
+ * (`<name>/SKILL.md` 的根是那个目录,`<name>.md` 的根是它所在的目录)。DO/CHECK 里引用的
13
+ * **资产资源**(页面契约、模板、校验清单)用相对路径按它解析,资产因此可以把这些材料放在
14
+ * 自己旁边,而不是把它们复制进每一步的提示词。要写出的交付物按 `output` / 产出目录的落点
15
+ * —— 资产资源与产出物是两条并行的落点规则。
16
+ *
17
+ * 这里只做路径拼装与推导:不读内容、不建目录、不校验资产。
18
+ */
19
+ import fs from "node:fs";
20
+ import path from "node:path";
21
+ /** 目录形态的 Flow 入口文件名。 */
22
+ export const FLOW_ENTRY_FILE = "workflow.yaml";
23
+ /** 目录形态的 Graph 入口文件名。 */
24
+ export const GRAPH_ENTRY_FILE = "graph.yaml";
25
+ /** Flow 资产根目录名:目录形态的入口在 `workflows/<name>/` 下一层。 */
26
+ const FLOW_ROOT_DIRNAME = "workflows";
27
+ /** Graph 资产根目录名:目录形态的入口在 `graphs/<name>/` 下一层。 */
28
+ const GRAPH_ROOT_DIRNAME = "graphs";
29
+ /** 一个资产在某个目录里的候选入口:目录形态优先,其次是兼容的单文件形态。 */
30
+ export function assetCandidates(dir, name, entryFile) {
31
+ return [path.join(dir, name, entryFile), path.join(dir, `${name}.yaml`), path.join(dir, `${name}.yml`)];
32
+ }
33
+ /** 某个目录里该资产的入口文件(目录形态优先);没有就 undefined。 */
34
+ export function assetFileIn(dir, name, entryFile) {
35
+ return assetCandidates(dir, name, entryFile).find(isFile);
36
+ }
37
+ /** 参考根:入口文件所在目录。没有加载到资产时没有根。 */
38
+ export function assetRootOf(entryPath) {
39
+ return entryPath ? path.dirname(entryPath) : undefined;
40
+ }
41
+ /**
42
+ * 从入口路径推导资产名:目录形态取父目录名,单文件形态取文件名去掉扩展名。
43
+ *
44
+ * 目录形态的判据只有一条:入口文件位于**资产根**(`workflows/` / `graphs/`)下一层,
45
+ * 即 `workflows/<name>/workflow.yaml`、`graphs/<name>/graph.yaml`。不在这一层里的
46
+ * `workflow.yaml` / `graph.yaml` 是兼容形态的**单文件资产**(名为 `workflow` / `graph`),
47
+ * 不能因为扩展名前缀恰好撞上固定入口名就被读成目录形态。
48
+ *
49
+ * 名字规则只写在路径层:doctor 的路径参数与以后任何「拿一个入口路径问名字」的调用都走这里,
50
+ * 不在调用方各自 `path.basename(...).replace(...)`。
51
+ */
52
+ export function assetNameOf(entryPath) {
53
+ const base = path.basename(entryPath);
54
+ const parentDir = path.dirname(entryPath);
55
+ const rootDirName = path.basename(path.dirname(parentDir));
56
+ const expectedRoot = base === FLOW_ENTRY_FILE
57
+ ? FLOW_ROOT_DIRNAME
58
+ : base === GRAPH_ENTRY_FILE
59
+ ? GRAPH_ROOT_DIRNAME
60
+ : undefined;
61
+ return expectedRoot && rootDirName === expectedRoot
62
+ ? path.basename(parentDir)
63
+ : assetNameFromFile(entryPath);
64
+ }
65
+ /** 单文件形态的名字:文件名去掉 `.yaml` / `.yml`。 */
66
+ function assetNameFromFile(file) {
67
+ return path.basename(file).replace(/\.ya?ml$/i, "");
68
+ }
69
+ /**
70
+ * 把一个路径解析成资产入口:入口文件本身,或包含 `workflow.yaml` / `graph.yaml` 的资产目录。
71
+ *
72
+ * 只接受真实存在的文件或目录;解析不出来返回 undefined,由调用方说清合法形态。
73
+ */
74
+ export function assetEntryAt(target) {
75
+ let stat;
76
+ try {
77
+ stat = fs.statSync(target);
78
+ }
79
+ catch {
80
+ return undefined;
81
+ }
82
+ if (stat.isDirectory()) {
83
+ const name = path.basename(target);
84
+ for (const entryFile of [FLOW_ENTRY_FILE, GRAPH_ENTRY_FILE]) {
85
+ const file = path.join(target, entryFile);
86
+ if (isFile(file))
87
+ return { file, name };
88
+ }
89
+ return undefined;
90
+ }
91
+ if (!stat.isFile())
92
+ return undefined;
93
+ return { file: target, name: assetNameOf(target) };
94
+ }
95
+ function isFile(file) {
96
+ try {
97
+ return fs.statSync(file).isFile();
98
+ }
99
+ catch {
100
+ return false;
101
+ }
102
+ }
103
+ /**
104
+ * 列出一个目录里的全部资产入口(名字 → 入口文件)。
105
+ *
106
+ * 目录形态优先:同名时以 `<name>/<entryFile>` 为准。不读内容、不建目录。
107
+ *
108
+ * 用 `statSync` 判断类型(跟随符号链接),与 `loadWorkflow` 的 `statSync` 口径一致:
109
+ * 软链到目录或 YAML 的资产同样能被 list / doctor / 动态技能发现,不在发现面与加载面分叉。
110
+ */
111
+ export function discoverAssetsIn(dir, entryFile) {
112
+ const found = new Map();
113
+ let names;
114
+ try {
115
+ names = fs.readdirSync(dir);
116
+ }
117
+ catch {
118
+ return found;
119
+ }
120
+ for (const name of names) {
121
+ const entry = path.join(dir, name);
122
+ if (!isDirectory(entry))
123
+ continue;
124
+ const file = path.join(entry, entryFile);
125
+ if (isFile(file))
126
+ found.set(name, file);
127
+ }
128
+ for (const name of names) {
129
+ if (!/\.ya?ml$/i.test(name))
130
+ continue;
131
+ const assetName = assetNameFromFile(name);
132
+ if (found.has(assetName))
133
+ continue;
134
+ const file = path.join(dir, name);
135
+ if (isFile(file))
136
+ found.set(assetName, file);
137
+ }
138
+ return found;
139
+ }
140
+ function isDirectory(target) {
141
+ try {
142
+ return fs.statSync(target).isDirectory();
143
+ }
144
+ catch {
145
+ return false;
146
+ }
147
+ }
148
+ /**
149
+ * DO 与 CHECK 提示词里同一段「资产目录」说明(没有资产路径时返回 undefined)。
150
+ *
151
+ * 与 dsh 注入 Skill 资源根的两句同构(名词不同):模型在 Skill 里见过同一个形状,迁过来没有
152
+ * 新概念。**只在这里写一次** —— Flow/Graph × 执行者/验证者四处注入点都引用它。
153
+ *
154
+ * 这一节只说**资产资源**的参考根;过程记录与交付物的落点由 {@link placementSection} 说。
155
+ */
156
+ export function assetReferenceSection(root) {
157
+ if (!root)
158
+ return undefined;
159
+ return `## 资产目录\n\`${root}\` —— 本资产资源的基准目录:本资产引用的契约、模板、校验清单按它解析,需要时再读。`;
160
+ }
161
+ /**
162
+ * 过程记录 / 交付物 的落点段。DO 与 CHECK 共用这一份文案。
163
+ *
164
+ * 判据是**概念**(过程记录 vs 交付物),不是路径写法:过程记录一律落 `rel`,交付物落工作
165
+ * 目录或 `output` 写明的路径。`rel` 由调用方传入(现有 `artifactsRelDir`)。
166
+ */
167
+ export function placementSection(rel, forVerifier) {
168
+ if (forVerifier) {
169
+ return [
170
+ "## 落点",
171
+ `过程记录(清单、方案、报告、摘要、草稿)在 \`${rel}/\` 里,用文件名即可读到。`,
172
+ "交付物(代码、文档产品、可执行文件)在工作目录;`output` 里写了明确路径的,按那个路径。",
173
+ "判定只认落点上的那份:同一份过程记录在工作目录里的副本,不算满足。",
174
+ ].join("\n");
175
+ }
176
+ return [
177
+ "## 落点",
178
+ `过程记录(清单、方案、报告、摘要、草稿)写进 \`${rel}/\`:只写文件名,不写路径。`,
179
+ "交付物(代码、文档产品、可执行文件)落工作目录;`output` 里写了明确路径的,按那个路径。",
180
+ ].join("\n");
181
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * 统一资产发现:Flow(`workflows/`)与 Graph(`graphs/`)两类并列。
3
+ *
4
+ * 这个模块只做**只读枚举与合并**,不校验、不执行、不建目录。完整校验由各自的引擎负责
5
+ * (Flow `listWorkflows()` / Graph `listGraphWorkflows()`),门面把它们合并给 `list`、
6
+ * `doctor`、状态面与动态技能。跨类别同名在这里就能被发现:`ralphflow_start <name>`
7
+ * 只能解析出一个资产,绝不能“先找到哪个算哪个”。
8
+ */
9
+ import { type WorkflowEntry } from "./engine.js";
10
+ import { type GraphWorkflowEntry } from "./graph/assets.js";
11
+ export type AssetKind = "flow" | "graph";
12
+ export interface AssetSummary {
13
+ name: string;
14
+ desc: string;
15
+ kind: AssetKind;
16
+ /** 步骤数(Flow)或节点数(Graph) */
17
+ count: number;
18
+ }
19
+ export interface UnifiedAssetEntry {
20
+ name: string;
21
+ kind: AssetKind;
22
+ desc: string;
23
+ invalid: boolean;
24
+ problems: string[];
25
+ warnings: string[];
26
+ count: number;
27
+ source: "workspace" | "global" | "builtin" | "flow";
28
+ path?: string;
29
+ /** 跨类别同名:Flow 与 Graph 同时存在。 */
30
+ conflict?: boolean;
31
+ }
32
+ /** 只读清单(给动态技能用;不校验内容,避免会话创建时读整棵目录)。 */
33
+ export declare function discoverAssetsIn(workspace: string): AssetSummary[];
34
+ /**
35
+ * 把 Flow 引擎的完整校验结果与 Graph 发现结果合并。
36
+ * 跨类别同名时两条都标 `conflict`,`list`/`doctor` 必须报错,`start` 拒绝。
37
+ */
38
+ export declare function mergeAssets(flowEntries: readonly WorkflowEntry[], graphEntries: readonly GraphWorkflowEntry[]): UnifiedAssetEntry[];
39
+ /** 名字 → 唯一条目;跨类别同名返回 conflict 而不是任选一个。 */
40
+ export declare function findAssetByName(entries: readonly UnifiedAssetEntry[], name: string): UnifiedAssetEntry | undefined;
41
+ export declare function kindLabel(kind: AssetKind): string;
42
+ export type { WorkflowEntry, GraphWorkflowEntry };
package/lib/assets.js ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * 统一资产发现:Flow(`workflows/`)与 Graph(`graphs/`)两类并列。
3
+ *
4
+ * 这个模块只做**只读枚举与合并**,不校验、不执行、不建目录。完整校验由各自的引擎负责
5
+ * (Flow `listWorkflows()` / Graph `listGraphWorkflows()`),门面把它们合并给 `list`、
6
+ * `doctor`、状态面与动态技能。跨类别同名在这里就能被发现:`ralphflow_start <name>`
7
+ * 只能解析出一个资产,绝不能“先找到哪个算哪个”。
8
+ */
9
+ import { listWorkflowsIn } from "./engine.js";
10
+ import { listGraphWorkflows } from "./graph/assets.js";
11
+ /** 只读清单(给动态技能用;不校验内容,避免会话创建时读整棵目录)。 */
12
+ export function discoverAssetsIn(workspace) {
13
+ const out = [];
14
+ const seen = new Set();
15
+ for (const workflow of listWorkflowsIn(workspace)) {
16
+ out.push({ name: workflow.name, desc: workflow.desc, kind: "flow", count: 0 });
17
+ seen.add(workflow.name);
18
+ }
19
+ for (const graph of listGraphWorkflows(workspace)) {
20
+ if (seen.has(graph.name))
21
+ continue;
22
+ out.push({ name: graph.name, desc: graph.desc, kind: "graph", count: graph.nodes });
23
+ }
24
+ return out.sort((left, right) => left.name.localeCompare(right.name));
25
+ }
26
+ /**
27
+ * 把 Flow 引擎的完整校验结果与 Graph 发现结果合并。
28
+ * 跨类别同名时两条都标 `conflict`,`list`/`doctor` 必须报错,`start` 拒绝。
29
+ */
30
+ export function mergeAssets(flowEntries, graphEntries) {
31
+ const flowNames = new Set(flowEntries.map((entry) => entry.name));
32
+ const graphNames = new Set(graphEntries.map((entry) => entry.name));
33
+ const merged = [
34
+ ...flowEntries.map((entry) => {
35
+ const conflict = graphNames.has(entry.name);
36
+ return {
37
+ name: entry.name,
38
+ kind: "flow",
39
+ desc: entry.desc,
40
+ invalid: entry.invalid || conflict,
41
+ problems: conflict ? [`名字 \`${entry.name}\` 同时出现在 workflows/ 与 graphs/:跨类别同名是冲突,必须改名。`] : entry.problems,
42
+ warnings: entry.warnings,
43
+ count: entry.steps ?? 0,
44
+ source: "flow",
45
+ ...(conflict ? { conflict: true } : {}),
46
+ };
47
+ }),
48
+ ...graphEntries.map((entry) => {
49
+ const conflict = flowNames.has(entry.name);
50
+ return {
51
+ name: entry.name,
52
+ kind: "graph",
53
+ desc: entry.desc,
54
+ invalid: entry.invalid || conflict,
55
+ problems: conflict ? [`名字 \`${entry.name}\` 同时出现在 workflows/ 与 graphs/:跨类别同名是冲突,必须改名。`] : entry.problems,
56
+ warnings: entry.warnings,
57
+ count: entry.nodes,
58
+ source: entry.source,
59
+ ...(entry.path ? { path: entry.path } : {}),
60
+ ...(conflict ? { conflict: true } : {}),
61
+ };
62
+ }),
63
+ ];
64
+ return merged.sort((left, right) => left.name.localeCompare(right.name) || left.kind.localeCompare(right.kind));
65
+ }
66
+ /** 名字 → 唯一条目;跨类别同名返回 conflict 而不是任选一个。 */
67
+ export function findAssetByName(entries, name) {
68
+ const matches = entries.filter((entry) => entry.name === name);
69
+ if (matches.length > 1) {
70
+ return {
71
+ name,
72
+ kind: matches[0].kind,
73
+ desc: "",
74
+ invalid: true,
75
+ problems: [`名字 \`${name}\` 同时出现在 workflows/ 与 graphs/:跨类别同名是冲突,必须改名后才能启动。`],
76
+ warnings: [],
77
+ count: 0,
78
+ source: "flow",
79
+ conflict: true,
80
+ };
81
+ }
82
+ return matches[0];
83
+ }
84
+ export function kindLabel(kind) {
85
+ return kind === "graph" ? "Graph" : "Flow";
86
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 阶段投影(纯函数):把状态面的事实翻译成查看器卡片上的芯片。
3
+ *
4
+ * 为什么单独一层:Flow 步骤卡过去不论 DO 还是 CHECK 都写「执行中」,光看工作图分不出
5
+ * 当前在哪个阶段;Graph 节点的「执行中 / 验证中」又共用同一种颜色。这里把「哪个阶段、
6
+ * 什么状态、什么语气」集中成一份映射,界面只负责画。
7
+ *
8
+ * 语气只有五种,语义固定:run = 在飞、done = 已通过、wait = 等你或等依赖、
9
+ * fault = 失败、off = 未开始。在飞用业务色(有彩色),不是品牌色 —— 品牌色是黑白中性色,
10
+ * 夜间模式下整张工作图会退化成纯黑白。
11
+ *
12
+ * 边界:不读实例状态、不碰时间、不产生副作用;没有运行状态时只说结构,不猜进度。
13
+ */
14
+ import type { GraphStatusNode, ViewerAssetNode, WorkflowStatus } from "../status-contract.js";
15
+ export type PhaseTone = "run" | "done" | "wait" | "fault" | "off";
16
+ export interface PhaseChip {
17
+ label: string;
18
+ tone: PhaseTone;
19
+ }
20
+ /** 状态枚举 → 语气。未知状态按「未开始」处理,不猜。 */
21
+ export declare function statusToneOf(status: string): PhaseTone;
22
+ /** Flow 当前步:先 DO 后 CHECK,一眼看出引擎在哪个阶段。 */
23
+ export declare function flowPhaseChips(flow: WorkflowStatus): PhaseChip[];
24
+ /** Graph 节点:先 DO 后 CHECK;节点投影里的 label 是事实,原样带上。 */
25
+ export declare function graphPhaseChips(node: GraphStatusNode): PhaseChip[];
26
+ /** 没有运行状态时只描述结构:静态属性一律中性,别跟运行状态抢注意力。 */
27
+ export declare function graphAssetChips(node: ViewerAssetNode): PhaseChip[];
28
+ /** 步骤详情顶部状态条:把 Flow 阶段翻成查看器的状态枚举,别让详情永远显示「在飞」。 */
29
+ export declare function flowPanelStatus(flow: WorkflowStatus | null, current: boolean): string;
@@ -0,0 +1,86 @@
1
+ const DO_RUNNING = { label: "DO · 执行中", tone: "run" };
2
+ const DO_SUBMITTED = { label: "DO · 已交卷", tone: "done" };
3
+ const CHECK_IDLE = { label: "CHECK · 待验证", tone: "off" };
4
+ const CHECK_OFF = { label: "CHECK · 关闭", tone: "off" };
5
+ const CHECK_CUSTOM = { label: "CHECK · 自定义", tone: "off" };
6
+ const CHECK_RUNNING = { label: "CHECK · 验证中", tone: "run" };
7
+ const CHECK_PASSED = { label: "CHECK · 已通过", tone: "done" };
8
+ const CHECK_FAILED = { label: "CHECK · 未通过", tone: "fault" };
9
+ /** 状态枚举 → 语气。未知状态按「未开始」处理,不猜。 */
10
+ export function statusToneOf(status) {
11
+ if (status === "completed" || status === "done" || status === "passed")
12
+ return "done";
13
+ if (["running", "verifying", "reworking", "integrating", "accepting", "switching"].includes(status))
14
+ return "run";
15
+ if (["waiting", "waiting_review", "gate", "paused"].includes(status))
16
+ return "wait";
17
+ if (["failed", "cancelled", "interrupted", "infra"].includes(status))
18
+ return "fault";
19
+ return "off";
20
+ }
21
+ /** Flow 当前步:先 DO 后 CHECK,一眼看出引擎在哪个阶段。 */
22
+ export function flowPhaseChips(flow) {
23
+ const total = flow.votes.length;
24
+ const returned = flow.votes.filter((vote) => vote.status === "passed" || vote.status === "failed" || vote.status === "infra").length;
25
+ switch (flow.stage) {
26
+ case "executing":
27
+ return total > 0 ? [DO_RUNNING, CHECK_IDLE] : [DO_RUNNING];
28
+ case "verifying":
29
+ return [DO_SUBMITTED, total > 1 ? { ...CHECK_RUNNING, label: `CHECK · 验证中 ${returned}/${total}` } : CHECK_RUNNING];
30
+ case "gate":
31
+ return total > 0 ? [DO_SUBMITTED, CHECK_PASSED, { label: "等待你放行", tone: "wait" }] : [DO_SUBMITTED, { label: "等待你放行", tone: "wait" }];
32
+ // switching 既可能是「本步刚拿到 DO 投递」,也可能是「判定齐了正在推进」:
33
+ // 只有票已存在才敢说 DO 已交卷,否则只说切换中。
34
+ case "switching":
35
+ return total > 0 ? [DO_SUBMITTED, CHECK_PASSED] : [{ label: "切换步骤中", tone: "run" }];
36
+ case "paused":
37
+ return [{ label: "已暂停", tone: "wait" }];
38
+ case "done":
39
+ return [{ label: "已完成", tone: "done" }];
40
+ case "cancelled":
41
+ return [{ label: "已取消", tone: "off" }];
42
+ case "failed":
43
+ return [{ label: "失败", tone: "fault" }];
44
+ default:
45
+ return [{ label: "状态不可用", tone: "off" }];
46
+ }
47
+ }
48
+ /** Graph 节点:先 DO 后 CHECK;节点投影里的 label 是事实,原样带上。 */
49
+ export function graphPhaseChips(node) {
50
+ const check = node.check.mode === "disabled" ? CHECK_OFF : null;
51
+ switch (node.status) {
52
+ case "running":
53
+ return [DO_RUNNING, check ?? CHECK_IDLE];
54
+ case "verifying":
55
+ return [DO_SUBMITTED, CHECK_RUNNING];
56
+ case "reworking":
57
+ return [DO_SUBMITTED, CHECK_FAILED, { label: node.label, tone: "wait" }];
58
+ case "waiting_review":
59
+ return [DO_SUBMITTED, CHECK_PASSED, { label: node.label, tone: "wait" }];
60
+ case "integrating":
61
+ case "accepting":
62
+ return [CHECK_PASSED, { label: node.label, tone: "run" }];
63
+ case "completed":
64
+ return check ? [{ label: node.label, tone: "done" }] : [{ label: node.label, tone: "done" }, CHECK_PASSED];
65
+ default:
66
+ return [{ label: node.label, tone: statusToneOf(node.status) }];
67
+ }
68
+ }
69
+ /** 没有运行状态时只描述结构:静态属性一律中性,别跟运行状态抢注意力。 */
70
+ export function graphAssetChips(node) {
71
+ return [{ label: "待开始", tone: "off" }, node.checkMode === "disabled" ? CHECK_OFF : CHECK_CUSTOM];
72
+ }
73
+ /** 步骤详情顶部状态条:把 Flow 阶段翻成查看器的状态枚举,别让详情永远显示「在飞」。 */
74
+ export function flowPanelStatus(flow, current) {
75
+ if (!current || !flow)
76
+ return "pending";
77
+ switch (flow.stage) {
78
+ case "verifying": return "verifying";
79
+ case "gate":
80
+ case "paused": return "waiting";
81
+ case "done": return "completed";
82
+ case "failed": return "failed";
83
+ case "cancelled": return "cancelled";
84
+ default: return "running";
85
+ }
86
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 打开工作图时先看哪一个资产(纯函数)。
3
+ *
4
+ * 优先级:
5
+ * 1. 本次打开里用户手动选过的资产 —— 显式选择最高;
6
+ * 2. 当前会话正在跑的工作流 —— 「工作流在跑,一打开工作图就是它」;
7
+ * 3. 上次记住的浏览偏好(localStorage,跨会话);
8
+ * 4. 目录里的第一个。
9
+ *
10
+ * 运行中的工作流换了身份(新一轮开始、换成另一个工作流、跑完状态消失)时,调用方作废
11
+ * 显式选择并重新跟随运行 —— 否则「上次浏览过哪个」会盖住「现在在跑哪个」。
12
+ *
13
+ * 边界:只做名字选择,不读 localStorage、不碰实例状态;未知名字一律当没写。
14
+ */
15
+ import type { ViewerAsset } from "../status-contract.js";
16
+ type PickInput = {
17
+ catalogNames: readonly string[];
18
+ /** 当前会话正在跑的工作流;没有就是 null。 */
19
+ running: string | null;
20
+ /** 本次打开里手动选过的资产。 */
21
+ chosen: string | null;
22
+ /** 上次记住的浏览偏好。 */
23
+ pinned: string | null;
24
+ };
25
+ export declare function pickAssetName(input: PickInput): string;
26
+ /** 工作流选择器的一行:步骤/节点数 + 定义无效标记 + 运行中标记。 */
27
+ export declare function assetMenuLabel(asset: ViewerAsset, running: string | null): string;
28
+ export {};
@@ -0,0 +1,9 @@
1
+ export function pickAssetName(input) {
2
+ const known = (name) => (name !== null && input.catalogNames.includes(name) ? name : null);
3
+ return known(input.chosen) ?? known(input.running) ?? known(input.pinned) ?? input.catalogNames[0] ?? "";
4
+ }
5
+ /** 工作流选择器的一行:步骤/节点数 + 定义无效标记 + 运行中标记。 */
6
+ export function assetMenuLabel(asset, running) {
7
+ const size = asset.kind === "flow" ? `${asset.steps.length} 步` : `${asset.nodes.length} 节点`;
8
+ return `${asset.name} · ${size}${asset.invalid ? "(定义无效)" : ""}${asset.name === running ? " · 运行中" : ""}`;
9
+ }
@@ -1,13 +1,15 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
- import { type WorkflowStatus } from "../status-contract.js";
2
+ import { type PauseResult, type ViewerAsset, type WorkflowStatus } from "../status-contract.js";
3
3
  export interface ClientStatus {
4
4
  status: WorkflowStatus | null;
5
5
  connection: "connecting" | "live" | "offline";
6
6
  error: string | null;
7
+ catalog: ViewerAsset[];
7
8
  }
8
9
  /** One lazy stream per Session, shared by the header and dock. Last unsubscribe releases it. */
9
10
  export declare function createStatusSource(ctx: Context, sessionId: string): {
10
11
  getSnapshot: () => ClientStatus;
12
+ pause: () => Promise<PauseResult>;
11
13
  subscribe(listener: () => void): () => void;
12
14
  dispose(): void;
13
15
  };
@@ -2,7 +2,7 @@ import { RemoteSnapshotStream } from "@deepseek-ai/dsh-api-gateway/client";
2
2
  import { parseStatusFrame } from "../status-contract.js";
3
3
  /** One lazy stream per Session, shared by the header and dock. Last unsubscribe releases it. */
4
4
  export function createStatusSource(ctx, sessionId) {
5
- let snapshot = { status: null, connection: "connecting", error: null };
5
+ let snapshot = { status: null, connection: "connecting", error: null, catalog: [] };
6
6
  const listeners = new Set();
7
7
  let stream;
8
8
  let token = 0;
@@ -26,7 +26,7 @@ export function createStatusSource(ctx, sessionId) {
26
26
  const frame = parseStatusFrame(raw);
27
27
  if (frame.sessionId !== sessionId)
28
28
  throw new Error("status stream crossed Session binding");
29
- publish({ status: frame.status, connection: "live", error: frame.error });
29
+ publish({ status: frame.status, connection: "live", error: frame.error, catalog: frame.catalog });
30
30
  };
31
31
  const carrier = ctx.remote.$stream({
32
32
  name: `ralphflow status ${sessionId}`,
@@ -48,6 +48,7 @@ export function createStatusSource(ctx, sessionId) {
48
48
  };
49
49
  return {
50
50
  getSnapshot: () => snapshot,
51
+ pause: () => ctx.remote.ralphflowStatus.pause(sessionId),
51
52
  subscribe(listener) {
52
53
  listeners.add(listener);
53
54
  if (listeners.size === 1)