@fieldwangai/agentflow 0.1.25

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 (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -0
  3. package/README.zh-CN.md +201 -0
  4. package/agents/agentflow-node-executor-code.md +32 -0
  5. package/agents/agentflow-node-executor-planning.md +32 -0
  6. package/agents/agentflow-node-executor-requirement.md +32 -0
  7. package/agents/agentflow-node-executor-test.md +32 -0
  8. package/agents/agentflow-node-executor-ui.md +32 -0
  9. package/agents/agentflow-node-executor.md +32 -0
  10. package/agents/agents.json +8 -0
  11. package/agents/en/agentflow-node-executor.md +32 -0
  12. package/agents/zh/agentflow-node-executor.md +32 -0
  13. package/bin/agentflow.mjs +52 -0
  14. package/bin/ensure-workspace-reference.mjs +35 -0
  15. package/bin/lib/agent-runners.mjs +1199 -0
  16. package/bin/lib/agents-path.mjs +61 -0
  17. package/bin/lib/api-runner.mjs +361 -0
  18. package/bin/lib/apply.mjs +852 -0
  19. package/bin/lib/catalog-agents.mjs +300 -0
  20. package/bin/lib/catalog-flows.mjs +532 -0
  21. package/bin/lib/composer-agent.mjs +884 -0
  22. package/bin/lib/composer-flow-instances.mjs +68 -0
  23. package/bin/lib/composer-flow-skeleton.mjs +334 -0
  24. package/bin/lib/composer-flow-validate.mjs +47 -0
  25. package/bin/lib/composer-log.mjs +197 -0
  26. package/bin/lib/composer-model-router.mjs +160 -0
  27. package/bin/lib/composer-node-schema.mjs +299 -0
  28. package/bin/lib/composer-planner.mjs +749 -0
  29. package/bin/lib/composer-script-ops.mjs +233 -0
  30. package/bin/lib/composer-skill-router.mjs +384 -0
  31. package/bin/lib/flow-import.mjs +305 -0
  32. package/bin/lib/flow-normalize.mjs +71 -0
  33. package/bin/lib/flow-write.mjs +395 -0
  34. package/bin/lib/help.mjs +139 -0
  35. package/bin/lib/hub-login.mjs +54 -0
  36. package/bin/lib/hub-publish.mjs +159 -0
  37. package/bin/lib/hub-remote.mjs +189 -0
  38. package/bin/lib/hub.mjs +299 -0
  39. package/bin/lib/i18n.mjs +233 -0
  40. package/bin/lib/locales/en.json +344 -0
  41. package/bin/lib/locales/zh.json +344 -0
  42. package/bin/lib/log.mjs +37 -0
  43. package/bin/lib/main.mjs +611 -0
  44. package/bin/lib/model-config.mjs +118 -0
  45. package/bin/lib/model-lists.mjs +188 -0
  46. package/bin/lib/node-exec-context.mjs +336 -0
  47. package/bin/lib/node-execute.mjs +513 -0
  48. package/bin/lib/normalize-node-tool-command.mjs +97 -0
  49. package/bin/lib/paths.mjs +216 -0
  50. package/bin/lib/pipeline-scripts.mjs +41 -0
  51. package/bin/lib/recent-runs.mjs +173 -0
  52. package/bin/lib/run-apply-active-lock.mjs +82 -0
  53. package/bin/lib/run-events.mjs +85 -0
  54. package/bin/lib/run-node-statuses-from-disk.mjs +85 -0
  55. package/bin/lib/schedule-config.mjs +227 -0
  56. package/bin/lib/scheduler.mjs +312 -0
  57. package/bin/lib/table.mjs +4 -0
  58. package/bin/lib/terminal.mjs +42 -0
  59. package/bin/lib/ui-print.mjs +94 -0
  60. package/bin/lib/ui-server.mjs +2113 -0
  61. package/bin/lib/workspace-tree.mjs +266 -0
  62. package/bin/lib/workspace.mjs +180 -0
  63. package/bin/pipeline/build-node-prompt.mjs +179 -0
  64. package/bin/pipeline/check-cache.mjs +191 -0
  65. package/bin/pipeline/check-flow.mjs +543 -0
  66. package/bin/pipeline/collect-nodes.mjs +212 -0
  67. package/bin/pipeline/compute-cache-md5.mjs +177 -0
  68. package/bin/pipeline/ensure-run-dir.mjs +71 -0
  69. package/bin/pipeline/extract-thinking.mjs +308 -0
  70. package/bin/pipeline/gc.mjs +129 -0
  71. package/bin/pipeline/get-env.mjs +83 -0
  72. package/bin/pipeline/get-exec-id.mjs +145 -0
  73. package/bin/pipeline/get-ready-nodes.mjs +435 -0
  74. package/bin/pipeline/get-resolved-values.mjs +337 -0
  75. package/bin/pipeline/load-key.mjs +62 -0
  76. package/bin/pipeline/parse-bool.mjs +33 -0
  77. package/bin/pipeline/parse-flow.mjs +698 -0
  78. package/bin/pipeline/post-process-control-if.mjs +23 -0
  79. package/bin/pipeline/post-process-node.mjs +490 -0
  80. package/bin/pipeline/pre-process-node.mjs +449 -0
  81. package/bin/pipeline/resolve-inputs.mjs +201 -0
  82. package/bin/pipeline/run-log.mjs +34 -0
  83. package/bin/pipeline/run-tool-nodejs.mjs +160 -0
  84. package/bin/pipeline/save-key.mjs +93 -0
  85. package/bin/pipeline/snapshot-prior-round.mjs +70 -0
  86. package/bin/pipeline/validate-flow.mjs +825 -0
  87. package/bin/pipeline/validate-for-ui.mjs +226 -0
  88. package/bin/pipeline/validate-script-output.mjs +130 -0
  89. package/bin/pipeline/write-result.mjs +182 -0
  90. package/builtin/nodes/agent_subAgent.md +14 -0
  91. package/builtin/nodes/control_agent_toBool.md +20 -0
  92. package/builtin/nodes/control_anyOne.md +17 -0
  93. package/builtin/nodes/control_end.md +11 -0
  94. package/builtin/nodes/control_if.md +20 -0
  95. package/builtin/nodes/control_start.md +11 -0
  96. package/builtin/nodes/control_toBool.md +21 -0
  97. package/builtin/nodes/provide_file.md +11 -0
  98. package/builtin/nodes/provide_str.md +11 -0
  99. package/builtin/nodes/tool_get_env.md +14 -0
  100. package/builtin/nodes/tool_load_key.md +20 -0
  101. package/builtin/nodes/tool_nodejs.md +40 -0
  102. package/builtin/nodes/tool_print.md +14 -0
  103. package/builtin/nodes/tool_save_key.md +20 -0
  104. package/builtin/nodes/tool_user_ask.md +23 -0
  105. package/builtin/nodes/tool_user_check.md +22 -0
  106. package/builtin/pipelines/module-migrate/flow.yaml +819 -0
  107. package/builtin/pipelines/module-migrate/scripts/check_imports.mjs +700 -0
  108. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Makefile +362 -0
  109. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/.deps/Release/obj.target/node_modules/node-addon-api/node_addon_api_except.stamp.d +1 -0
  110. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/.deps/Release/obj.target/tree_sitter_kotlin_binding/bindings/node/binding.o.d +17 -0
  111. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/.deps/Release/obj.target/tree_sitter_kotlin_binding/src/parser.o.d +5 -0
  112. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/.deps/Release/obj.target/tree_sitter_kotlin_binding/src/scanner.o.d +8 -0
  113. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/.deps/Release/tree_sitter_kotlin_binding.node.d +1 -0
  114. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/obj.target/node_modules/node-addon-api/node_addon_api_except.stamp +0 -0
  115. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/obj.target/tree_sitter_kotlin_binding/bindings/node/binding.o +0 -0
  116. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/obj.target/tree_sitter_kotlin_binding/src/parser.o +0 -0
  117. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/obj.target/tree_sitter_kotlin_binding/src/scanner.o +0 -0
  118. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/Release/tree_sitter_kotlin_binding.node +0 -0
  119. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/binding.Makefile +6 -0
  120. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/gyp-mac-tool +768 -0
  121. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/node_modules/node-addon-api/node_addon_api.Makefile +6 -0
  122. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/node_modules/node-addon-api/node_addon_api.target.mk +122 -0
  123. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/node_modules/node-addon-api/node_addon_api_except.target.mk +126 -0
  124. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/node_modules/node-addon-api/node_addon_api_maybe.target.mk +122 -0
  125. package/builtin/pipelines/module-migrate/scripts/node_modules/tree-sitter-kotlin/build/tree_sitter_kotlin_binding.target.mk +203 -0
  126. package/builtin/pipelines/new/flow.yaml +545 -0
  127. package/builtin/pipelines/new/scripts/check-flow.mjs +9 -0
  128. package/builtin/pipelines/new/scripts/collect-nodes.mjs +211 -0
  129. package/builtin/pipelines/scripts/adjust-node-positions.mjs +113 -0
  130. package/builtin/web-ui/dist/agentflow-icon.svg +23 -0
  131. package/builtin/web-ui/dist/assets/index-CZkUPcXE.css +1 -0
  132. package/builtin/web-ui/dist/assets/index-DkkhNESc.js +190 -0
  133. package/builtin/web-ui/dist/index.html +24 -0
  134. package/package.json +67 -0
  135. package/reference/flow-control-capabilities.md +274 -0
  136. package/reference/flow-layout.md +84 -0
  137. package/reference/flow-prompt-handler-check.md +12 -0
  138. package/reference/flow-result-semantics.md +14 -0
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * get-ready-nodes 前执行:对 status 为 success 且存在 .cache.json 的节点重算 MD5,
4
+ * 若与 .cache.json 中记录不一致则将该节点 result 改为 cache_not_met,使其重新进入待执行。
5
+ * result/cache 使用固定路径(不含 _execId)。
6
+ * 用法:node check-cache.mjs <workspaceRoot> <flowName> <uuid>
7
+ * 输出(stdout JSON):{ "ok": true };失败时 { "ok": false, "error": "..." }
8
+ */
9
+
10
+ import fs from "fs";
11
+ import path from "path";
12
+
13
+ import { getRunDir } from "../lib/paths.mjs";
14
+ import { computeCacheMd5 } from "./compute-cache-md5.mjs";
15
+ import { writeResult } from "./write-result.mjs";
16
+ import { intermediateResultBasename, intermediateCacheBasename, loadExecId } from "./get-exec-id.mjs";
17
+ import { logToRunTag } from "./run-log.mjs";
18
+ import { snapshotPriorRoundIfNeeded } from "./snapshot-prior-round.mjs";
19
+
20
+ function parseResultStatus(filePath) {
21
+ try {
22
+ const raw = fs.readFileSync(filePath, "utf-8");
23
+ const m = raw.match(/^\s*status:\s*["']?(\w+)["']?/m);
24
+ return m ? m[1] : null;
25
+ } catch {
26
+ return null;
27
+ }
28
+ }
29
+
30
+ const PRE_CACHE_JSON = ".pre.cache.json";
31
+ const NOW_CACHE_JSON = ".now.cache.json";
32
+
33
+ /** 从 intermediate/<instanceId>/<instanceId>.cache.json 读取 cacheMd5(固定路径) */
34
+ function readCacheFromSidecar(intermediateDir, instanceId) {
35
+ const basename = intermediateCacheBasename(instanceId, 1);
36
+ const p = path.join(intermediateDir, instanceId, basename);
37
+ if (!fs.existsSync(p)) return { cacheMd5: null };
38
+ try {
39
+ const raw = fs.readFileSync(p, "utf-8");
40
+ const o = JSON.parse(raw);
41
+ return { cacheMd5: o.cacheMd5 ?? null };
42
+ } catch {
43
+ return { cacheMd5: null };
44
+ }
45
+ }
46
+
47
+ /** 将当时的 .cache.json 存为 .pre.cache.json,当前重算结果存为 .now.cache.json,便于排查 */
48
+ function savePreAndNowCache(intermediateDir, instanceId, current) {
49
+ const nodeDir = path.join(intermediateDir, instanceId);
50
+ const prePath = path.join(nodeDir, intermediateCacheBasename(instanceId, 1));
51
+ const preSavePath = path.join(nodeDir, `${instanceId}${PRE_CACHE_JSON}`);
52
+ const nowSavePath = path.join(nodeDir, `${instanceId}${NOW_CACHE_JSON}`);
53
+ if (fs.existsSync(prePath)) {
54
+ try {
55
+ fs.copyFileSync(prePath, preSavePath);
56
+ } catch (_) {}
57
+ }
58
+ try {
59
+ const nowObj = { cacheMd5: current.cacheMd5, cacheInputInfo: current.cacheInputInfo ?? "" };
60
+ if (current.payload !== undefined) nowObj.payload = current.payload;
61
+ if (current.execId !== undefined) nowObj.execId = current.execId;
62
+ if (current.inputHandlerExecIds != null && Object.keys(current.inputHandlerExecIds).length > 0) {
63
+ nowObj.inputHandlerExecIds = current.inputHandlerExecIds;
64
+ }
65
+ fs.writeFileSync(nowSavePath, JSON.stringify(nowObj, null, 2), "utf-8");
66
+ } catch (_) {}
67
+ }
68
+
69
+ function main() {
70
+ const args = process.argv.slice(2);
71
+ if (args.length < 3) {
72
+ console.error(
73
+ JSON.stringify({
74
+ ok: false,
75
+ error: "Usage: node check-cache.mjs <workspaceRoot> <flowName> <uuid>",
76
+ })
77
+ );
78
+ process.exit(1);
79
+ }
80
+
81
+ const [root, flowName, uuid] = args;
82
+ const workspaceRoot = path.resolve(root);
83
+ const runDir = getRunDir(workspaceRoot, flowName, uuid);
84
+ const flowJsonPath = path.join(runDir, "intermediate", "flow.json");
85
+
86
+ if (!fs.existsSync(flowJsonPath)) {
87
+ console.log(JSON.stringify({ ok: true }));
88
+ return;
89
+ }
90
+
91
+ let flow;
92
+ try {
93
+ flow = JSON.parse(fs.readFileSync(flowJsonPath, "utf-8"));
94
+ } catch (e) {
95
+ console.error(JSON.stringify({ ok: false, error: e.message }));
96
+ process.exit(1);
97
+ }
98
+ if (!flow.ok || !Array.isArray(flow.order)) {
99
+ console.log(JSON.stringify({ ok: true }));
100
+ return;
101
+ }
102
+
103
+ const order = flow.order;
104
+ const edges = flow.edges || [];
105
+ const nodeDefinitions = flow.nodeDefinitions || {};
106
+ const outputSlotTypes = flow.outputSlotTypes || {};
107
+ const inputSlotTypes = flow.inputSlotTypes || {};
108
+ const intermediateDir = path.join(runDir, "intermediate");
109
+
110
+ /** 仅对 pendingInstances 及其向后边能到达的节点做缓存校验,与 get-ready-nodes 候选集一致 */
111
+ const isNodeEdge = (e) => {
112
+ const outTypes = outputSlotTypes[e.source];
113
+ const inTypes = inputSlotTypes[e.target];
114
+ if (!outTypes || !inTypes) return false;
115
+ const outNames = Object.keys(outTypes);
116
+ const inNames = Object.keys(inTypes);
117
+ const oidx = parseInt(String(e.sourceHandle || "output-0").replace("output-", ""), 10) || 0;
118
+ const iidx = parseInt(String(e.targetHandle || "input-0").replace("input-", ""), 10) || 0;
119
+ const outType = outNames[oidx] != null ? outTypes[outNames[oidx]] : null;
120
+ const inType = inNames[iidx] != null ? inTypes[inNames[iidx]] : null;
121
+ return (outType === "节点" || outType === "node") && (inType === "节点" || inType === "node");
122
+ };
123
+ const successors = {};
124
+ for (const e of edges) {
125
+ if (!e.source || e.target == null) continue;
126
+ if (!isNodeEdge(e)) continue;
127
+ if (!successors[e.source]) successors[e.source] = [];
128
+ successors[e.source].push(e.target);
129
+ }
130
+ const starts = order.filter((id) => nodeDefinitions[id] === "control_start");
131
+ const pendingInstances = Array.isArray(flow.pendingInstances) ? flow.pendingInstances : starts;
132
+ const candidateSet = new Set();
133
+ const candQueue = [...pendingInstances];
134
+ while (candQueue.length) {
135
+ const id = candQueue.shift();
136
+ if (candidateSet.has(id)) continue;
137
+ candidateSet.add(id);
138
+ for (const next of successors[id] || []) {
139
+ if (!candidateSet.has(next)) candQueue.push(next);
140
+ }
141
+ }
142
+
143
+ logToRunTag(workspaceRoot, flowName, uuid, "check-cache", {
144
+ event: "start",
145
+ candidateSet: [...candidateSet],
146
+ });
147
+
148
+ for (const instanceId of candidateSet) {
149
+ const resultBasename = intermediateResultBasename(instanceId, 1);
150
+ const resultPath = path.join(intermediateDir, instanceId, resultBasename);
151
+ if (!fs.existsSync(resultPath)) continue;
152
+
153
+ const status = parseResultStatus(resultPath);
154
+ const { cacheMd5: storedMd5 } = readCacheFromSidecar(intermediateDir, instanceId);
155
+ if (status !== "success" || !storedMd5) continue;
156
+
157
+ const current = computeCacheMd5(workspaceRoot, flowName, uuid, instanceId, 1);
158
+ if (!current.ok) continue;
159
+
160
+ if (current.cacheMd5 !== storedMd5) {
161
+ savePreAndNowCache(intermediateDir, instanceId, current);
162
+ const reason = `storedMd5=${storedMd5} currentMd5=${current.cacheMd5}`;
163
+ logToRunTag(workspaceRoot, flowName, uuid, "check-cache", {
164
+ event: "cache_not_met",
165
+ instanceId,
166
+ storedMd5,
167
+ currentMd5: current.cacheMd5,
168
+ reason,
169
+ });
170
+ // 覆写 result.md 为 cache_not_met 之前,先把上一轮的真实结果(success/failed)snapshot 到 _<priorExecId>
171
+ // 否则下一轮 pre-process 的 snapshot 备份下来的只是 cache_not_met 占位,UI 永远看不到实际执行产物。
172
+ const priorExecId = loadExecId(workspaceRoot, flowName, uuid, instanceId);
173
+ snapshotPriorRoundIfNeeded(runDir, instanceId, priorExecId);
174
+ try {
175
+ writeResult(workspaceRoot, flowName, uuid, instanceId, {
176
+ status: "cache_not_met",
177
+ message: "缓存失效(prompt/input 已变更)",
178
+ cacheNotMetReason: reason,
179
+ }, { preserveBody: true });
180
+ } catch (err) {
181
+ console.error(JSON.stringify({ ok: false, error: err.message }));
182
+ process.exit(1);
183
+ }
184
+ }
185
+ }
186
+
187
+ logToRunTag(workspaceRoot, flowName, uuid, "check-cache", { event: "done" });
188
+ console.log(JSON.stringify({ ok: true }));
189
+ }
190
+
191
+ main();