@chenmk/superflow 0.3.0 → 0.5.0

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 (261) hide show
  1. package/INSTALL.en.md +54 -12
  2. package/INSTALL.md +59 -33
  3. package/README.md +192 -49
  4. package/README.zh-CN.md +166 -46
  5. package/assets/brand/managed-review-loop.png +0 -0
  6. package/assets/manifest.json +15 -9
  7. package/assets/prompts/superflow-design.md +3 -0
  8. package/assets/prompts/superflow-docs.md +4 -1
  9. package/assets/scripts/superflow-coding-ready.mjs +135 -0
  10. package/assets/scripts/superflow-dependency-update-hook.sh +81 -8
  11. package/assets/scripts/superflow-document-audit.mjs +240 -0
  12. package/assets/scripts/superflow-environment-preflight.mjs +398 -0
  13. package/assets/scripts/superflow-hook-guard.sh +40 -1
  14. package/assets/scripts/superflow-managed-command-guard.py +309 -0
  15. package/assets/scripts/superflow-managed-executor-preflight.mjs +421 -0
  16. package/assets/scripts/superflow-managed-owner-verification.sh +117 -0
  17. package/assets/scripts/superflow-managed-work-check.mjs +455 -0
  18. package/assets/scripts/superflow-managed-work-guard.sh +17 -0
  19. package/assets/skills/openspec-propose/SKILL.md +11 -0
  20. package/assets/skills/superflow-clarify/SKILL.md +14 -0
  21. package/assets/skills/superflow-design/SKILL.md +46 -12
  22. package/assets/skills/superflow-docs/SKILL.md +109 -2
  23. package/assets/skills/superflow-pipeline/SKILL.md +205 -2
  24. package/assets/skills/superflow-pipeline/references/batch-prompt-template.md +17 -9
  25. package/assets/skills/superflow-pipeline/references/document-readiness.md +157 -0
  26. package/assets/skills/superflow-pipeline/references/document-templates.md +17 -5
  27. package/assets/skills/superflow-pipeline/references/feature-gated-workflow.md +14 -0
  28. package/assets/skills/superflow-pipeline/references/implementation-prompt-template.md +20 -11
  29. package/assets/skills/superflow-pipeline/references/managed-work.md +166 -0
  30. package/assets/skills/superflow-pipeline/references/orchestration.md +2 -2
  31. package/assets/skills/superflow-pipeline/references/p0-baseline-template.md +3 -2
  32. package/assets/skills/superflow-pipeline/references/quality-gate.md +8 -5
  33. package/assets/skills/superflow-pipeline/references/reviewer-checklist.md +7 -0
  34. package/assets/skills/superflow-pipeline/references/superpower-technical-design-template.md +10 -0
  35. package/assets/skills/superflow-pipeline/scripts/superflow-archive.sh +1 -1
  36. package/assets/skills/superflow-pipeline/scripts/superflow-guard.sh +282 -16
  37. package/assets/skills/superflow-pipeline/scripts/superflow-handoff.sh +7 -4
  38. package/assets/skills/superflow-requirement-review/SKILL.md +178 -0
  39. package/assets/skills/superflow-requirement-review/agents/openai.yaml +4 -0
  40. package/assets/skills-en/openspec-propose/SKILL.md +14 -0
  41. package/assets/skills-en/superflow-clarify/SKILL.md +17 -0
  42. package/assets/skills-en/superflow-design/SKILL.md +40 -11
  43. package/assets/skills-en/superflow-docs/SKILL.md +115 -0
  44. package/assets/skills-en/superflow-pipeline/SKILL.md +202 -0
  45. package/assets/skills-en/superflow-pipeline/references/batch-prompt-template.md +4 -0
  46. package/assets/skills-en/superflow-pipeline/references/document-readiness.md +125 -0
  47. package/assets/skills-en/superflow-pipeline/references/document-templates.md +15 -0
  48. package/assets/skills-en/superflow-pipeline/references/feature-gated-workflow.md +7 -0
  49. package/assets/skills-en/superflow-pipeline/references/implementation-prompt-template.md +7 -0
  50. package/assets/skills-en/superflow-pipeline/references/managed-work.md +184 -0
  51. package/assets/skills-en/superflow-pipeline/references/quality-gate.md +20 -0
  52. package/assets/skills-en/superflow-pipeline/references/reviewer-checklist.md +7 -0
  53. package/assets/skills-en/superflow-pipeline/references/superpower-technical-design-template.md +11 -0
  54. package/assets/skills-en/superflow-pipeline/scripts/superflow-archive.sh +1 -1
  55. package/assets/skills-en/superflow-pipeline/scripts/superflow-guard.sh +279 -14
  56. package/assets/skills-en/superflow-pipeline/scripts/superflow-handoff.sh +7 -4
  57. package/assets/skills-en/superflow-requirement-review/SKILL.md +99 -0
  58. package/assets/skills-en/superflow-requirement-review/agents/openai.yaml +4 -0
  59. package/dist/app/cli.js +176 -103
  60. package/dist/app/cli.js.map +1 -1
  61. package/dist/app/commands/change-guard.js +19 -2
  62. package/dist/app/commands/change-guard.js.map +1 -1
  63. package/dist/app/commands/check.js +107 -45
  64. package/dist/app/commands/check.js.map +1 -1
  65. package/dist/app/commands/docs.js +7 -3
  66. package/dist/app/commands/docs.js.map +1 -1
  67. package/dist/app/commands/doctor.js +174 -198
  68. package/dist/app/commands/doctor.js.map +1 -1
  69. package/dist/app/commands/eval.js +64 -0
  70. package/dist/app/commands/eval.js.map +1 -0
  71. package/dist/app/commands/implement.js +7 -3
  72. package/dist/app/commands/implement.js.map +1 -1
  73. package/dist/app/commands/init.js +16 -24
  74. package/dist/app/commands/init.js.map +1 -1
  75. package/dist/app/commands/managed-service.js +5 -0
  76. package/dist/app/commands/managed-service.js.map +1 -0
  77. package/dist/app/commands/mcp.js +167 -0
  78. package/dist/app/commands/mcp.js.map +1 -0
  79. package/dist/app/commands/pipeline.js +757 -3
  80. package/dist/app/commands/pipeline.js.map +1 -1
  81. package/dist/app/commands/requirement-review.js +6 -0
  82. package/dist/app/commands/requirement-review.js.map +1 -0
  83. package/dist/app/commands/status.js +262 -77
  84. package/dist/app/commands/status.js.map +1 -1
  85. package/dist/app/commands/uninstall.js +8 -5
  86. package/dist/app/commands/uninstall.js.map +1 -1
  87. package/dist/app/commands/update.js +114 -15
  88. package/dist/app/commands/update.js.map +1 -1
  89. package/dist/domains/agent.js +3 -11
  90. package/dist/domains/agent.js.map +1 -1
  91. package/dist/domains/config/cli-help.js +145 -73
  92. package/dist/domains/config/cli-help.js.map +1 -1
  93. package/dist/domains/config/i18n.js +6 -8
  94. package/dist/domains/config/i18n.js.map +1 -1
  95. package/dist/domains/config/manifest.js +0 -3
  96. package/dist/domains/config/manifest.js.map +1 -1
  97. package/dist/domains/deps.js +70 -8
  98. package/dist/domains/deps.js.map +1 -1
  99. package/dist/domains/hook.js +71 -38
  100. package/dist/domains/hook.js.map +1 -1
  101. package/dist/domains/managed-work/completion-policy.js +174 -0
  102. package/dist/domains/managed-work/completion-policy.js.map +1 -0
  103. package/dist/domains/managed-work/context-manifest.js +208 -0
  104. package/dist/domains/managed-work/context-manifest.js.map +1 -0
  105. package/dist/domains/managed-work/contract.js +349 -0
  106. package/dist/domains/managed-work/contract.js.map +1 -0
  107. package/dist/domains/managed-work/control-signals.js +34 -0
  108. package/dist/domains/managed-work/control-signals.js.map +1 -0
  109. package/dist/domains/managed-work/control.js +628 -0
  110. package/dist/domains/managed-work/control.js.map +1 -0
  111. package/dist/domains/managed-work/evaluation.js +497 -0
  112. package/dist/domains/managed-work/evaluation.js.map +1 -0
  113. package/dist/domains/managed-work/evidence-path.js +14 -0
  114. package/dist/domains/managed-work/evidence-path.js.map +1 -0
  115. package/dist/domains/managed-work/execution-contract.js +167 -0
  116. package/dist/domains/managed-work/execution-contract.js.map +1 -0
  117. package/dist/domains/managed-work/executor-policy.js +65 -0
  118. package/dist/domains/managed-work/executor-policy.js.map +1 -0
  119. package/dist/domains/managed-work/failure.js +65 -0
  120. package/dist/domains/managed-work/failure.js.map +1 -0
  121. package/dist/domains/managed-work/host-review.js +77 -0
  122. package/dist/domains/managed-work/host-review.js.map +1 -0
  123. package/dist/domains/managed-work/human-messages.js +31 -0
  124. package/dist/domains/managed-work/human-messages.js.map +1 -0
  125. package/dist/domains/managed-work/i18n.js +12 -0
  126. package/dist/domains/managed-work/i18n.js.map +1 -0
  127. package/dist/domains/managed-work/input.js +137 -0
  128. package/dist/domains/managed-work/input.js.map +1 -0
  129. package/dist/domains/managed-work/journal.js +196 -0
  130. package/dist/domains/managed-work/journal.js.map +1 -0
  131. package/dist/domains/managed-work/lock.js +106 -0
  132. package/dist/domains/managed-work/lock.js.map +1 -0
  133. package/dist/domains/managed-work/notifications.js +38 -0
  134. package/dist/domains/managed-work/notifications.js.map +1 -0
  135. package/dist/domains/managed-work/pair-admission.js +108 -0
  136. package/dist/domains/managed-work/pair-admission.js.map +1 -0
  137. package/dist/domains/managed-work/paths.js +18 -0
  138. package/dist/domains/managed-work/paths.js.map +1 -0
  139. package/dist/domains/managed-work/prompts.js +453 -0
  140. package/dist/domains/managed-work/prompts.js.map +1 -0
  141. package/dist/domains/managed-work/redaction.js +90 -0
  142. package/dist/domains/managed-work/redaction.js.map +1 -0
  143. package/dist/domains/managed-work/review-convergence.js +41 -0
  144. package/dist/domains/managed-work/review-convergence.js.map +1 -0
  145. package/dist/domains/managed-work/review-facts.js +181 -0
  146. package/dist/domains/managed-work/review-facts.js.map +1 -0
  147. package/dist/domains/managed-work/rule-selection.js +84 -0
  148. package/dist/domains/managed-work/rule-selection.js.map +1 -0
  149. package/dist/domains/managed-work/runner.js +2418 -0
  150. package/dist/domains/managed-work/runner.js.map +1 -0
  151. package/dist/domains/managed-work/schemas.js +155 -0
  152. package/dist/domains/managed-work/schemas.js.map +1 -0
  153. package/dist/domains/managed-work/service.js +190 -0
  154. package/dist/domains/managed-work/service.js.map +1 -0
  155. package/dist/domains/managed-work/state.js +280 -0
  156. package/dist/domains/managed-work/state.js.map +1 -0
  157. package/dist/domains/managed-work/storage.js +223 -0
  158. package/dist/domains/managed-work/storage.js.map +1 -0
  159. package/dist/domains/managed-work/types.js +19 -0
  160. package/dist/domains/managed-work/types.js.map +1 -0
  161. package/dist/domains/managed-work/verification-categories.js +39 -0
  162. package/dist/domains/managed-work/verification-categories.js.map +1 -0
  163. package/dist/domains/managed-work/verification-policy.js +116 -0
  164. package/dist/domains/managed-work/verification-policy.js.map +1 -0
  165. package/dist/domains/managed-work/wait.js +58 -0
  166. package/dist/domains/managed-work/wait.js.map +1 -0
  167. package/dist/domains/managed-work/workspace-binding.js +133 -0
  168. package/dist/domains/managed-work/workspace-binding.js.map +1 -0
  169. package/dist/domains/sdd-readiness.js +44 -0
  170. package/dist/domains/sdd-readiness.js.map +1 -0
  171. package/dist/domains/skill/deploy.js +0 -6
  172. package/dist/domains/skill/deploy.js.map +1 -1
  173. package/dist/domains/skill/scripts.js +0 -8
  174. package/dist/domains/skill/scripts.js.map +1 -1
  175. package/dist/domains/state.js +1 -2
  176. package/dist/domains/state.js.map +1 -1
  177. package/dist/mcp/runtime-identity.js +21 -0
  178. package/dist/mcp/runtime-identity.js.map +1 -0
  179. package/dist/mcp/server.js +369 -0
  180. package/dist/mcp/server.js.map +1 -0
  181. package/dist/platform/agent-process.js +769 -0
  182. package/dist/platform/agent-process.js.map +1 -0
  183. package/dist/platform/executable.js +28 -0
  184. package/dist/platform/executable.js.map +1 -0
  185. package/dist/platform/paths.js +1 -17
  186. package/dist/platform/paths.js.map +1 -1
  187. package/dist/platform/process-liveness.js +10 -0
  188. package/dist/platform/process-liveness.js.map +1 -0
  189. package/dist/platform/process-tree.js +44 -0
  190. package/dist/platform/process-tree.js.map +1 -0
  191. package/dist/platform/process.js +1 -1
  192. package/dist/platform/process.js.map +1 -1
  193. package/dist/platform/version-check.js +30 -9
  194. package/dist/platform/version-check.js.map +1 -1
  195. package/package.json +16 -7
  196. package/scripts/check-design-principles.mjs +107 -0
  197. package/scripts/check-managed-work-design.mjs +507 -0
  198. package/scripts/clean-dist.js +9 -0
  199. package/scripts/ensure-bin-modes.js +11 -0
  200. package/dist/cli/index.js +0 -193
  201. package/dist/cli/index.js.map +0 -1
  202. package/dist/commands/archive.js +0 -6
  203. package/dist/commands/archive.js.map +0 -1
  204. package/dist/commands/clarify.js +0 -6
  205. package/dist/commands/clarify.js.map +0 -1
  206. package/dist/commands/design.js +0 -28
  207. package/dist/commands/design.js.map +0 -1
  208. package/dist/commands/docs.js +0 -6
  209. package/dist/commands/docs.js.map +0 -1
  210. package/dist/commands/doctor.js +0 -494
  211. package/dist/commands/doctor.js.map +0 -1
  212. package/dist/commands/implement.js +0 -6
  213. package/dist/commands/implement.js.map +0 -1
  214. package/dist/commands/init.js +0 -520
  215. package/dist/commands/init.js.map +0 -1
  216. package/dist/commands/pipeline.js +0 -6
  217. package/dist/commands/pipeline.js.map +0 -1
  218. package/dist/commands/scan.js +0 -63
  219. package/dist/commands/scan.js.map +0 -1
  220. package/dist/commands/status.js +0 -173
  221. package/dist/commands/status.js.map +0 -1
  222. package/dist/commands/uninstall.js +0 -214
  223. package/dist/commands/uninstall.js.map +0 -1
  224. package/dist/commands/update.js +0 -193
  225. package/dist/commands/update.js.map +0 -1
  226. package/dist/commands/verify.js +0 -6
  227. package/dist/commands/verify.js.map +0 -1
  228. package/dist/core/assets.js +0 -27
  229. package/dist/core/assets.js.map +0 -1
  230. package/dist/core/cli-help.js +0 -98
  231. package/dist/core/cli-help.js.map +0 -1
  232. package/dist/core/context.js +0 -123
  233. package/dist/core/context.js.map +0 -1
  234. package/dist/core/dependencies.js +0 -146
  235. package/dist/core/dependencies.js.map +0 -1
  236. package/dist/core/detect.js +0 -64
  237. package/dist/core/detect.js.map +0 -1
  238. package/dist/core/i18n.js +0 -105
  239. package/dist/core/i18n.js.map +0 -1
  240. package/dist/core/integrity.js +0 -46
  241. package/dist/core/integrity.js.map +0 -1
  242. package/dist/core/manifest.js +0 -21
  243. package/dist/core/manifest.js.map +0 -1
  244. package/dist/core/prompts.js +0 -20
  245. package/dist/core/prompts.js.map +0 -1
  246. package/dist/core/registry.js +0 -134
  247. package/dist/core/registry.js.map +0 -1
  248. package/dist/core/rules.js +0 -17
  249. package/dist/core/rules.js.map +0 -1
  250. package/dist/core/scripts.js +0 -48
  251. package/dist/core/scripts.js.map +0 -1
  252. package/dist/core/skill-check.js +0 -32
  253. package/dist/core/skill-check.js.map +0 -1
  254. package/dist/core/skills.js +0 -62
  255. package/dist/core/skills.js.map +0 -1
  256. package/dist/core/state.js +0 -54
  257. package/dist/core/state.js.map +0 -1
  258. package/dist/utils/path.js +0 -11
  259. package/dist/utils/path.js.map +0 -1
  260. package/dist/utils/shell.js +0 -29
  261. package/dist/utils/shell.js.map +0 -1
@@ -0,0 +1,167 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from "fs";
2
+ import path from "path";
3
+ import { managedTaskDir } from "./paths.js";
4
+ import { categoriesForCommand } from "./verification-categories.js";
5
+ export function artifactLevelFor(contract) {
6
+ if ((contract.taskPrompt && contract.taskPrompt.origin !== "generated_standard") ||
7
+ contract.source !== "direct_prompt") {
8
+ return "full";
9
+ }
10
+ if (["engineering", "sdd"].includes(contract.profile))
11
+ return "standard";
12
+ return "minimal";
13
+ }
14
+ export function writeManagedExecutionContract(contract) {
15
+ const artifactLevel = artifactLevelFor(contract);
16
+ const canonicalTasksPath = findCanonicalTasks(contract);
17
+ const execution = {
18
+ schemaVersion: 1,
19
+ taskId: contract.taskId,
20
+ artifactLevel,
21
+ canonicalTasksPath,
22
+ tasks: canonicalTasksPath ? [] : defaultTasks(contract, artifactLevel),
23
+ };
24
+ const taskDir = managedTaskDir(contract.projectRoot, contract.taskId);
25
+ writeJsonAtomic(path.join(taskDir, "execution-contract.json"), execution);
26
+ writeFileSync(path.join(taskDir, "execution-contract.md"), renderExecutionContract(execution, contract), "utf-8");
27
+ return execution;
28
+ }
29
+ export function readManagedExecutionContract(contract) {
30
+ const file = path.join(managedTaskDir(contract.projectRoot, contract.taskId), "execution-contract.json");
31
+ if (!existsSync(file))
32
+ return writeManagedExecutionContract(contract);
33
+ return JSON.parse(readFileSync(file, "utf-8"));
34
+ }
35
+ export function deriveExecutionTaskCompletion(task, result) {
36
+ if (!result)
37
+ return false;
38
+ if (task.requiresChangedFiles && result.changedFiles.length === 0)
39
+ return false;
40
+ const successful = result.commands.filter(isAcceptedEvidenceCommand);
41
+ const categories = new Set(successful.flatMap(categoriesForCommand));
42
+ return task.requiredCategories.every((category) => categories.has(category));
43
+ }
44
+ /**
45
+ * Accept deterministic command evidence only. A non-zero inspection is valid
46
+ * when it unambiguously proves absence; it is not a general expected-failure
47
+ * escape hatch for build, test, or business commands.
48
+ */
49
+ export function isAcceptedEvidenceCommand(command) {
50
+ if (command.exitCode === 0)
51
+ return true;
52
+ if (command.exitCode !== 1 && command.exitCode !== 2)
53
+ return false;
54
+ const inspection = /^(?:\s*)(?:grep|rg|pgrep|lsof|ss|netstat|find|git\s+(?:status|diff)\b|ps\b[^|]*(?:\|\s*(?:grep|rg)\b)?|ls\b[^|]*(?:\|\s*(?:grep|rg)\b|$))/i;
55
+ if (!inspection.test(command.command))
56
+ return false;
57
+ return /(?:none|empty|no\b.{0,48}\b(?:orphan(?:s)?|process(?:es)?|listener(?:s)?|container(?:s)?|residue|match(?:es)?|output|change(?:s)?)|no[- ]?residue|not found|does not exist|无匹配|无残留|未发现|没有|不存在|空)/i.test(command.result);
58
+ }
59
+ function defaultTasks(contract, level) {
60
+ const tasks = [
61
+ {
62
+ taskId: "E01",
63
+ text: contract.language === "en"
64
+ ? "Implement the requested outcome in the approved repositories"
65
+ : "在授权仓库内实现请求目标",
66
+ requiredCategories: [],
67
+ requiresChangedFiles: requiresSourceChanges(contract),
68
+ },
69
+ {
70
+ taskId: "E02",
71
+ text: contract.language === "en"
72
+ ? "Run affected build or automated tests and retain evidence"
73
+ : "执行受影响构建或自动化测试并保留证据",
74
+ requiredCategories: ["test"],
75
+ requiresChangedFiles: false,
76
+ },
77
+ ];
78
+ if (level !== "minimal" && requiresRuntimeAcceptance(contract)) {
79
+ const databaseOnly = requiresDatabaseRuntimeAcceptance(contract);
80
+ tasks.push({
81
+ taskId: "E03",
82
+ text: databaseOnly
83
+ ? contract.language === "en"
84
+ ? "Complete task-level real database acceptance"
85
+ : "完成任务级真实数据库验收"
86
+ : contract.language === "en"
87
+ ? "Complete task-level real startup and invocation acceptance"
88
+ : "完成任务级真实启动与调用验收",
89
+ requiredCategories: databaseOnly ? ["runtime"] : ["startup", "invocation"],
90
+ requiresChangedFiles: false,
91
+ }, {
92
+ taskId: "E04",
93
+ text: contract.language === "en"
94
+ ? "Prove cleanup and final zero residue for task-owned resources"
95
+ : "证明任务资源清理完成且最终零残留",
96
+ requiredCategories: ["runtime"],
97
+ requiresChangedFiles: false,
98
+ });
99
+ }
100
+ return tasks;
101
+ }
102
+ export function requiresRuntimeAcceptance(contract) {
103
+ const taskText = [contract.request, contract.objective]
104
+ .join("\n")
105
+ .toLowerCase();
106
+ return /(?:\bapi\b|\bhttp\b|\be2e\b|\bsql\b|\bmysql\b|\bdatabase\b|\bdocker\b|\bbrowser\b|\bfrontend\b|\bbackend\b|\bserver\b|\bservice\b|\bstartup\b|\bintegration\b|接口|启动|数据库|浏览器|前端|后端|服务|容器|端到端|集成测试)/i.test(taskText);
107
+ }
108
+ function requiresDatabaseRuntimeAcceptance(contract) {
109
+ const taskText = [contract.request, contract.objective]
110
+ .join("\n")
111
+ .toLowerCase();
112
+ const database = /(?:\bsql\b|\bmysql\b|\bdatabase\b|数据库)/i.test(taskText);
113
+ const application = /(?:\bapi\b|\bhttp\b|\be2e\b|\bbrowser\b|\bfrontend\b|\bbackend\b|\bserver\b|\bservice\b|\bstartup\b|接口|启动|浏览器|前端|后端|服务|端到端)/i.test(taskText);
114
+ return database && !application;
115
+ }
116
+ function requiresSourceChanges(contract) {
117
+ if (contract.profile === "monitor")
118
+ return false;
119
+ const taskText = `${contract.request}\n${contract.objective}`.toLowerCase();
120
+ return /(?:\bimplement\b|\badd\b|\bchange\b|\bmodify\b|\bupdate\b|\bfix\b|\brefactor\b|\bcreate\b|\bdelete\b|\bcrud\b|\bcode\b|新增|实现|修改|调整|更新|修复|重构|创建|删除|开发|代码)/i.test(taskText);
121
+ }
122
+ function renderExecutionContract(execution, contract) {
123
+ const title = contract.language === "en"
124
+ ? "# Managed Execution Contract"
125
+ : "# 托管执行合同";
126
+ const level = contract.language === "en" ? "Artifact level" : "文档等级";
127
+ const source = execution.canonicalTasksPath
128
+ ? contract.language === "en"
129
+ ? `Canonical tasks: ${execution.canonicalTasksPath}`
130
+ : `权威任务清单:${execution.canonicalTasksPath}`
131
+ : contract.language === "en"
132
+ ? "The tasks below are a minimal machine execution plan, not invented business clarification."
133
+ : "以下任务是最小机器执行计划,不代表凭空补充业务澄清结论。";
134
+ return [
135
+ title,
136
+ "",
137
+ `${level}: ${execution.artifactLevel}`,
138
+ source,
139
+ "",
140
+ ...execution.tasks.map((task) => `- [ ] ${task.taskId} ${task.text}`),
141
+ "",
142
+ ].join("\n");
143
+ }
144
+ function findCanonicalTasks(contract) {
145
+ if (!contract.taskPrompt || contract.taskPrompt.origin === "generated_standard") {
146
+ return null;
147
+ }
148
+ let current = path.dirname(contract.taskPrompt.originalPath);
149
+ const roots = [contract.projectRoot, ...contract.relatedProjectRoots].map((root) => path.resolve(root));
150
+ while (roots.some((root) => current === root || current.startsWith(`${root}${path.sep}`))) {
151
+ const file = path.join(current, "tasks.md");
152
+ if (existsSync(file))
153
+ return file;
154
+ const parent = path.dirname(current);
155
+ if (parent === current)
156
+ break;
157
+ current = parent;
158
+ }
159
+ return null;
160
+ }
161
+ function writeJsonAtomic(file, value) {
162
+ mkdirSync(path.dirname(file), { recursive: true });
163
+ const temp = `${file}.tmp-${process.pid}-${Date.now()}`;
164
+ writeFileSync(temp, `${JSON.stringify(value, null, 2)}\n`, "utf-8");
165
+ renameSync(temp, file);
166
+ }
167
+ //# sourceMappingURL=execution-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-contract.js","sourceRoot":"","sources":["../../../src/domains/managed-work/execution-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,aAAa,GACd,MAAM,IAAI,CAAC;AACZ,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAmBpE,MAAM,UAAU,gBAAgB,CAC9B,QAA6B;IAE7B,IACE,CAAC,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,KAAK,oBAAoB,CAAC;QAC5E,QAAQ,CAAC,MAAM,KAAK,eAAe,EACnC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,aAAa,EAAE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QAC9B,OAAO,GAAG,MAAM,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,eAAe,CAAC,IAAY,EAAE,KAAc;IACnD,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,GAAG,IAAI,QAAQ,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IACxD,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,65 @@
1
+ import { createHash } from "crypto";
2
+ const STABLE_POLICY_LINES = [
3
+ "# Superflow Managed Executor Policy",
4
+ "",
5
+ "Read the frozen task prompt, context manifest, handoff, selected project rules, and current workspace before acting.",
6
+ "# Compact Instructions",
7
+ "When the Agent compacts this session, preserve the task ID, frozen prompt path and hash, all unfinished requirements and findings, changed files, active process/resource ownership, successful validation evidence, failed attempts that still need repair, and cleanup obligations. Re-read the frozen prompt and current handoff after compaction before continuing.",
8
+ "This executor invocation has no Superflow max-turn limit. Keep working in this process until all locally executable work is complete, then return one structured result to notify the Host.",
9
+ "Complete every locally executable item in one work batch, then build, test, start applications, call real HTTP endpoints, and run required browser E2E.",
10
+ "Use three verification levels: change-scoped checks, task-level real acceptance, and framework certification. Generic non-owner, PID-reuse, forged-state, and signal-escalation disaster tests belong to framework certification and must not be rebuilt for every business task.",
11
+ "When real runtime infrastructure is required, create and use a repository-owned, portable, repeatable, failure-safe one-command acceptance entry in this first invocation. It must own preflight, setup, build, startup, real calls, assertions, and cleanup from a clean state, including the success path and one representative setup/verification failure cleanup with final zero residue.",
12
+ "Reuse the certified owner-verification helper named in the task context. A wrapper may bind task nonce, signatures, ports, and resource names, but must not copy or rewrite identity, kill, or delete primitives. The helper does not decide business deletion safety; the Host still reviews that semantically.",
13
+ "Persist verbose build/framework/database logs in task-owned files and print only bounded stage summaries plus bounded failure tails. Never stream unbounded DEBUG output through the Agent tool channel; reference full log paths as evidence and keep those paths readable after cleanup removes nonce/runtime directories.",
14
+ "In managed non-interactive mode, do not probe tool availability or repeatedly retry denied shell variants. Use declared project commands directly as standalone commands without pipes, semicolons, or echo wrappers; run Superflow/OpenSpec gates through installed scripts when required.",
15
+ "If a passing automated test already starts the real application process and performs real TCP HTTP requests, reuse that evidence instead of launching a duplicate server or curl probe.",
16
+ "Local curl commands must target http://127.0.0.1 or http://localhost. Permission denials are already preserved in the raw transcript and telemetry: never put denied/non-zero attempts into the commands array of ready_for_review. That array is successful gate evidence only. Use an allowed equivalent, or return blocked when no equivalent can satisfy the requirement.",
17
+ "Before returning, perform one delivery self-check: include only successful evidence from this invocation. Superflow automatically merges valid evidence from earlier invocations, so do not rerun or manually copy prior startup, HTTP, build, or test commands.",
18
+ "During a repair invocation, map each finding to the evidence invalidated by its current diff. Run affected checks first. Rerun the complete acceptance chain only when production runtime behavior, SQL, configuration, authorization, public contracts, or the acceptance entry changed, or when the finding explicitly requires that chain.",
19
+ "For multi-repository work, verify each affected repository's build/runtime contract and the cross-repository real path when the requirement spans services. Evidence from one repository never substitutes for another.",
20
+ "For absence checks where grep, rg, pgrep, lsof, find, or similar tools correctly return exit 1 or 2, set assertion to negative and record the expected absence in result. Never mark an unexpected failure as a negative assertion.",
21
+ "Expected-failure tests must be wrapped by a parent acceptance command that asserts the child command failed as expected and itself exits 0. Keep the raw child failure in logs, never in the ready_for_review commands array.",
22
+ "Run the exact deterministic preflight command from the task context before StructuredOutput and repair every failure in the same session. Do not return ready_for_review unless it exits 0.",
23
+ "Treat managed assets by class: runtime resources and workspace-temporary files are cleaned by the Executor; delivery artifacts remain for Host review; protected contracts stay readable and are never deleted. Immutable protected inputs are read-only, while retained progress/report files may be updated but not removed.",
24
+ "Never use pkill, killall, a bare kill, port/name-only cleanup, or an unverified rm -rf. Use the certified owner helper for task-owned processes, containers, and runtime directories; ordinary build caches may be removed only inside the repository.",
25
+ "Do not commit, push, deploy, publish, write production data, bypass permissions, or edit .superflow task state.",
26
+ "Use only real evidence. Never replace a named MySQL, browser, or service gate with H2, mocks, or static inspection.",
27
+ "You own cleanup of every process you start.",
28
+ ];
29
+ export function stableExecutorPolicy() {
30
+ return `${STABLE_POLICY_LINES.join("\n")}\n`;
31
+ }
32
+ export function stableExecutorPolicyHash() {
33
+ return createHash("sha256").update(stableExecutorPolicy()).digest("hex");
34
+ }
35
+ export function buildExecutorPolicy(context) {
36
+ const dynamic = [
37
+ "# Task-specific context",
38
+ `Stable policy SHA-256: ${stableExecutorPolicyHash()}`,
39
+ `Selected rule scenarios: ${context.ruleSelection.scenarios.join(", ") || "none"}`,
40
+ "Read these exact applicable project rule files:",
41
+ ...(context.ruleSelection.files.length > 0
42
+ ? context.ruleSelection.files.map((file) => `- ${file}`)
43
+ : ["- none"]),
44
+ ...context.toolchainFacts,
45
+ `Certified owner-verification helper: ${context.ownerTemplate}`,
46
+ `Deterministic preflight command: ${context.preflightCommand}`,
47
+ ...(context.compatibilityContinuation
48
+ ? [
49
+ "Continue from the current workspace after the recorded compatibility interruption. Do not restart broad exploration.",
50
+ ]
51
+ : []),
52
+ ...(context.freshRecovery
53
+ ? [
54
+ "The previous session ended without useful workspace progress. Use the frozen prompt and Handoff, implement pending work immediately, then verify and clean up.",
55
+ ]
56
+ : []),
57
+ ...(context.deliveryProtocolRecovery
58
+ ? [
59
+ "The previous executor session returned no parseable delivery JSON. This is the one bounded protocol-recovery session: read the current workspace and handoff, preserve valid historical evidence, complete only remaining affected work, then return schema-valid structured delivery. Do not redo completed work merely to restate JSON.",
60
+ ]
61
+ : []),
62
+ ];
63
+ return `${stableExecutorPolicy()}${dynamic.join("\n")}\n`;
64
+ }
65
+ //# sourceMappingURL=executor-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor-policy.js","sourceRoot":"","sources":["../../../src/domains/managed-work/executor-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGpC,MAAM,mBAAmB,GAAG;IAC1B,qCAAqC;IACrC,EAAE;IACF,sHAAsH;IACtH,wBAAwB;IACxB,yWAAyW;IACzW,6LAA6L;IAC7L,yJAAyJ;IACzJ,mRAAmR;IACnR,gYAAgY;IAChY,kTAAkT;IAClT,8TAA8T;IAC9T,6RAA6R;IAC7R,yLAAyL;IACzL,+WAA+W;IAC/W,kQAAkQ;IAClQ,+UAA+U;IAC/U,yNAAyN;IACzN,qOAAqO;IACrO,+NAA+N;IAC/N,6LAA6L;IAC7L,gUAAgU;IAChU,wPAAwP;IACxP,iHAAiH;IACjH,qHAAqH;IACrH,6CAA6C;CACrC,CAAC;AAYX,MAAM,UAAU,oBAAoB;IAClC,OAAO,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAA8B;IAChE,MAAM,OAAO,GAAG;QACd,yBAAyB;QACzB,0BAA0B,wBAAwB,EAAE,EAAE;QACtD,4BAA4B,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,EAAE;QAClF,iDAAiD;QACjD,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;YACxC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;YACxD,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QACf,GAAG,OAAO,CAAC,cAAc;QACzB,wCAAwC,OAAO,CAAC,aAAa,EAAE;QAC/D,oCAAoC,OAAO,CAAC,gBAAgB,EAAE;QAC9D,GAAG,CAAC,OAAO,CAAC,yBAAyB;YACnC,CAAC,CAAC;gBACE,sHAAsH;aACvH;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,aAAa;YACvB,CAAC,CAAC;gBACE,gKAAgK;aACjK;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,wBAAwB;YAClC,CAAC,CAAC;gBACE,2UAA2U;aAC5U;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;IACF,OAAO,GAAG,oBAAoB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,65 @@
1
+ export class ManagedWorkspaceClaimError extends Error {
2
+ reason;
3
+ constructor(reason, message) {
4
+ super(message);
5
+ this.reason = reason;
6
+ }
7
+ }
8
+ /**
9
+ * Marks failures before an Executor process is dispatched. Runner uses this
10
+ * typed boundary instead of inferring local-environment failures from arbitrary
11
+ * Agent stdout/stderr.
12
+ */
13
+ export class ManagedEnvironmentPreparationError extends Error {
14
+ stage;
15
+ constructor(message, stage = "unknown") {
16
+ super(message);
17
+ this.stage = stage;
18
+ }
19
+ }
20
+ export function classifyManagedFailure(contract, error) {
21
+ const summary = error instanceof Error ? error.message : String(error);
22
+ const reason = failureReason(summary, error);
23
+ if (!reason)
24
+ return null;
25
+ return {
26
+ reason,
27
+ summary,
28
+ remediation: remediation(contract, reason),
29
+ recordedAt: new Date().toISOString(),
30
+ };
31
+ }
32
+ function failureReason(_summary, error) {
33
+ if (error instanceof ManagedWorkspaceClaimError)
34
+ return error.reason;
35
+ if (error instanceof ManagedEnvironmentPreparationError) {
36
+ return "environment_prepare_failed";
37
+ }
38
+ if (/Executor (?:final )?delivery|执行结果.*(?:校验|协议)|preflight failed/i.test(_summary)) {
39
+ return "executor_delivery_invalid";
40
+ }
41
+ return null;
42
+ }
43
+ function remediation(contract, reason) {
44
+ const zh = contract.language !== "en";
45
+ const messages = {
46
+ environment_prepare_failed: [
47
+ "检查工作区目录、磁盘空间、权限和本地 CLI/MCP 配置后重试;不要把此问题归因到模型供应商。",
48
+ "Check workspace path, disk space, permissions, and local CLI/MCP configuration before retrying; do not attribute it to the model provider.",
49
+ ],
50
+ workspace_busy_timeout: [
51
+ "等待另一项托管任务结束,或暂停/取消其任务后再恢复;系统没有启动第二个写入者。",
52
+ "Wait for the other managed task to finish, or pause/cancel it before resuming; no second writer was started.",
53
+ ],
54
+ workspace_ownership_unverified: [
55
+ "不要删除该 claim 文件;核对任务目录和 workspace binding 后,由任务 owner 人工处理。",
56
+ "Do not delete the claim file; verify the task directory and workspace binding, then let the task owner resolve it.",
57
+ ],
58
+ executor_delivery_invalid: [
59
+ "检查交付 JSON、证据路径和最终门禁输出后重新提交;不应通过修改状态文件绕过校验。",
60
+ "Check delivery JSON, evidence paths, and final-gate output before resubmitting; do not bypass validation by editing state files.",
61
+ ],
62
+ };
63
+ return messages[reason][zh ? 0 : 1];
64
+ }
65
+ //# sourceMappingURL=failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure.js","sourceRoot":"","sources":["../../../src/domains/managed-work/failure.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAExC;IADX,YACW,MAE2B,EACpC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QALN,WAAM,GAAN,MAAM,CAEqB;IAItC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,kCAAmC,SAAQ,KAAK;IAGhD;IAFX,YACE,OAAe,EACN,QAAQ,SAAS;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,UAAK,GAAL,KAAK,CAAY;IA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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { existsSync, unlinkSync } from "fs";
2
+ import path from "path";
3
+ import { managedText } from "./i18n.js";
4
+ import { managedRunDir } from "./paths.js";
5
+ import { validateReviewResult } from "./runner.js";
6
+ import { computeScopedWorkspaceFingerprint, computeWorkspaceFingerprintForRoots, } from "./state.js";
7
+ import { saveManagedRun, saveManagedTask, upsertRegistryEntry, writeJsonAtomic, } from "./storage.js";
8
+ export function submitExternalHostReviewResult(contract, state, result, language = "zh", env = process.env) {
9
+ result.protocolVersion = "superflow.review.v2";
10
+ result.messageType = "host_review";
11
+ if (state.status !== "waiting_for_host_review" ||
12
+ state.currentStep !== "external_supervisor_review_required" ||
13
+ !state.pendingExternalReview) {
14
+ throw new Error(managedText(language, "当前任务没有等待 Host Agent 评审", "The current task is not waiting for a host Agent review"));
15
+ }
16
+ const roots = [contract.projectRoot, ...contract.relatedProjectRoots];
17
+ const hasScopedWorkspacePaths = state.pendingExternalReview.workspacePaths !== undefined;
18
+ const scope = state.pendingExternalReview.workspacePaths ?? [];
19
+ const currentFingerprint = hasScopedWorkspacePaths
20
+ ? computeScopedWorkspaceFingerprint(roots, scope)
21
+ : computeWorkspaceFingerprintForRoots(roots);
22
+ if (currentFingerprint !== state.pendingExternalReview.workspaceFingerprint) {
23
+ throw new Error(managedText(language, "Host 评审期间工作区已变化,必须重新生成评审请求", "The workspace changed during host review; generate a new review request"));
24
+ }
25
+ validateReviewResult(result, language);
26
+ if (contract.source === "sdd" &&
27
+ !result.verificationCommands?.some((item) => item.exitCode === 0 &&
28
+ /openspec\s+instructions\s+apply/i.test(item.command))) {
29
+ throw new Error(managedText(language, "SDD 主 Agent 评审缺少真实 openspec instructions apply 命令证据", "SDD host review is missing a successful openspec instructions apply command"));
30
+ }
31
+ const resultPath = path.join(managedRunDir(state.projectRoot, state.taskId, state.runId), `review-result-${state.pendingExternalReview.round}.json`);
32
+ const previousState = structuredClone(state);
33
+ const previousContract = structuredClone(contract);
34
+ writeJsonAtomic(resultPath, result);
35
+ try {
36
+ upsertRegistryEntry(registryEntry(contract, state, "queued"), env);
37
+ state.lastReviewResult = resultPath;
38
+ state.pendingExternalReview = null;
39
+ state.status = "queued";
40
+ state.currentStep = "external_review_received";
41
+ state.blocker = null;
42
+ state.activeSince = null;
43
+ contract.status = "queued";
44
+ saveManagedRun(state);
45
+ saveManagedTask(contract);
46
+ }
47
+ catch (error) {
48
+ Object.assign(state, previousState);
49
+ Object.assign(contract, previousContract);
50
+ try {
51
+ saveManagedRun(previousState);
52
+ saveManagedTask(previousContract);
53
+ upsertRegistryEntry(registryEntry(previousContract, previousState, previousState.status), env);
54
+ }
55
+ catch {
56
+ // Preserve the original failure; recovery can use the unchanged local state.
57
+ }
58
+ if (existsSync(resultPath))
59
+ unlinkSync(resultPath);
60
+ throw error;
61
+ }
62
+ return resultPath;
63
+ }
64
+ function registryEntry(contract, state, status) {
65
+ return {
66
+ taskId: contract.taskId,
67
+ projectRoot: contract.projectRoot,
68
+ status,
69
+ profile: contract.profile,
70
+ language: contract.language,
71
+ activeRunId: state.runId,
72
+ createdAt: contract.createdAt,
73
+ updatedAt: new Date().toISOString(),
74
+ servicePid: state.servicePid,
75
+ };
76
+ }
77
+ //# sourceMappingURL=host-review.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-review.js","sourceRoot":"","sources":["../../../src/domains/managed-work/host-review.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACL,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,YA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AM,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QAC1C,IAAI,CAAC;YACH,cAAc,CAAC,aAAa,CAAC,CAAC;YAC9B,eAAe,CAAC,gBAAgB,CAAC,CAAC;YAClC,mBAAmB,CACjB,aAAa,CAAC,gBAAgB,EAAE,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,EACpE,GAAG,CACJ,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,6EAA6E;QAC/E,CAAC;QACD,IAAI,UAAU,CAAC,UAAU,CAAC;YAAE,UAAU,CAAC,UAAU,CAAC,CAAC;QACnD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,aAAa,CACpB,QAA6B,EAC7B,KAAsB,EACtB,MAAiC;IAEjC,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,MAAM;QACN,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,WAAW,EAAE,KAAK,CAAC,KAAK;QACxB,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,UAAU,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { randomUUID } from "crypto";
2
+ import { appendFileSync, existsSync, readFileSync } from "fs";
3
+ import path from "path";
4
+ import { managedTaskDir } from "./paths.js";
5
+ function humanMessagesPath(contract) {
6
+ return path.join(managedTaskDir(contract.projectRoot, contract.taskId), "human-messages.jsonl");
7
+ }
8
+ export function appendManagedHumanMessage(contract, content, actor = "user") {
9
+ const normalized = content.trim();
10
+ if (!normalized) {
11
+ throw new Error("Human guidance cannot be empty");
12
+ }
13
+ const message = {
14
+ messageId: randomUUID(),
15
+ timestamp: new Date().toISOString(),
16
+ actor: actor.trim() || "user",
17
+ content: normalized,
18
+ };
19
+ appendFileSync(humanMessagesPath(contract), `${JSON.stringify(message)}\n`, "utf-8");
20
+ return message;
21
+ }
22
+ export function readManagedHumanMessages(contract) {
23
+ const file = humanMessagesPath(contract);
24
+ if (!existsSync(file))
25
+ return [];
26
+ return readFileSync(file, "utf-8")
27
+ .split(/\r?\n/)
28
+ .filter(Boolean)
29
+ .map((line) => JSON.parse(line));
30
+ }
31
+ //# sourceMappingURL=human-messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"human-messages.js","sourceRoot":"","sources":["../../../src/domains/managed-work/human-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,SAAS,iBAAiB,CAAC,QAA6B;IACtD,OAAO,IAAI,CAAC,IAAI,CACd,cAAc,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,EACrD,sBAAsB,CACvB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,QAA6B,EAC7B,OAAe,EACf,KAAK,GAAG,MAAM;IAEd,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAClC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,OAAO,GAAwB;QACnC,SAAS,EAAE,UAAU,EAAE;QACvB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,MAAM;QAC7B,OAAO,EAAE,UAAU;KACpB,CAAC;IACF,cAAc,CACZ,iBAAiB,CAAC,QAAQ,CAAC,EAC3B,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAC9B,OAAO,CACR,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,QAA6B;IAE7B,MAAM,IAAI,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACzC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,OAAO,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC;SAC/B,KAAK,CAAC,OAAO,CAAC;SACd,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAwB,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,12 @@
1
+ export function managedLanguage(language) {
2
+ return language === "en" ? "en" : "zh";
3
+ }
4
+ export function managedText(language, zh, en) {
5
+ return managedLanguage(language) === "en" ? en : zh;
6
+ }
7
+ export function managedList(language, values, emptyZh = "无", emptyEn = "none") {
8
+ if (values.length === 0)
9
+ return managedText(language, emptyZh, emptyEn);
10
+ return values.join(managedText(language, "、", ", "));
11
+ }
12
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../../src/domains/managed-work/i18n.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,QAAmB;IACjD,OAAO,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,QAA8B,EAC9B,EAAU,EACV,EAAU;IAEV,OAAO,eAAe,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,QAA8B,EAC9B,MAAgB,EAChB,OAAO,GAAG,GAAG,EACb,OAAO,GAAG,MAAM;IAEhB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC"}
@@ -0,0 +1,137 @@
1
+ import { execFileSync } from "child_process";
2
+ import { existsSync, readFileSync, realpathSync, statSync } from "fs";
3
+ import path from "path";
4
+ import { managedText } from "./i18n.js";
5
+ export function resolveManagedInput(rawInput, options = {}) {
6
+ const request = rawInput.trim();
7
+ if (!request) {
8
+ throw new Error(managedText(options.language, "托管任务内容不能为空", "Managed task cannot be empty"));
9
+ }
10
+ const configuredRoot = canonicalRoot(options.projectRoot ?? process.cwd());
11
+ const embeddedPath = extractExistingPromptPath(request, configuredRoot, options.language);
12
+ const candidate = embeddedPath ?? path.resolve(configuredRoot, request);
13
+ if (!existsSync(candidate)) {
14
+ return {
15
+ request,
16
+ projectRoot: configuredRoot,
17
+ relatedProjectRoots: normalizeRoots(options.relatedProjectRoots),
18
+ profile: options.profile,
19
+ source: "direct_prompt",
20
+ };
21
+ }
22
+ const resolved = realpathSync(candidate);
23
+ const promptPath = statSync(resolved).isDirectory()
24
+ ? promptFromChangeDirectory(resolved, options.language)
25
+ : resolved;
26
+ rejectSddTasksChecklist(promptPath, options.language);
27
+ const projectRoot = options.projectRoot
28
+ ? configuredRoot
29
+ : (gitProjectRoot(path.dirname(promptPath)) ?? configuredRoot);
30
+ const relatedProjectRoots = normalizeRoots(options.relatedProjectRoots);
31
+ assertPromptInsideAllowedRoots(promptPath, [projectRoot, ...relatedProjectRoots], options.language);
32
+ const isSdd = isSddPrompt(promptPath);
33
+ return {
34
+ request: promptPath,
35
+ projectRoot,
36
+ relatedProjectRoots,
37
+ profile: options.profile && options.profile !== "auto"
38
+ ? options.profile
39
+ : isSdd
40
+ ? "sdd"
41
+ : "engineering",
42
+ source: isSdd ? "sdd" : "task_file",
43
+ taskPromptPath: promptPath,
44
+ };
45
+ }
46
+ function extractExistingPromptPath(request, projectRoot, language) {
47
+ const candidates = new Set();
48
+ const markdownLinks = request.matchAll(/\[[^\]]*\]\(([^)]+)\)/g);
49
+ for (const match of markdownLinks)
50
+ candidates.add(match[1].trim());
51
+ const quoted = request.matchAll(/["'“‘`]([^"'”’`]+)["'”’`]/g);
52
+ for (const match of quoted)
53
+ candidates.add(match[1].trim());
54
+ const absolute = request.matchAll(/(?:^|\s)(\/(?:[^\s,。;;]+))/g);
55
+ for (const match of absolute)
56
+ candidates.add(match[1].trim());
57
+ const existing = [...candidates]
58
+ .map((candidate) => candidate.replace(/[,。;;::]+$/, ""))
59
+ .map((candidate) => path.isAbsolute(candidate)
60
+ ? candidate
61
+ : path.resolve(projectRoot, candidate))
62
+ .filter((candidate) => existsSync(candidate));
63
+ if (existing.length === 0)
64
+ return null;
65
+ if (existing.length > 1) {
66
+ throw new Error(managedText(language, `托管请求中检测到多个有效路径,请明确指定唯一任务 Prompt:${existing.join("、")}`, `Multiple valid paths were detected; specify exactly one task prompt: ${existing.join(", ")}`));
67
+ }
68
+ return existing[0];
69
+ }
70
+ function promptFromChangeDirectory(changeDir, language) {
71
+ const stateFile = path.join(changeDir, ".sdd", "state.yaml");
72
+ if (!existsSync(stateFile)) {
73
+ throw new Error(managedText(language, "目录缺少 .sdd/state.yaml,无法定位 implementation_prompt", "Directory is missing .sdd/state.yaml; cannot locate implementation_prompt"));
74
+ }
75
+ const state = readFileSync(stateFile, "utf-8");
76
+ const match = state.match(/^implementation_prompt:\s*(.+?)\s*$/m);
77
+ const configured = match ? unquote(match[1]) : "";
78
+ if (!configured || configured === "null") {
79
+ throw new Error(managedText(language, ".sdd/state.yaml 尚未记录可执行的 implementation_prompt", ".sdd/state.yaml does not contain an executable implementation_prompt"));
80
+ }
81
+ const promptPath = realpathIfExists(path.resolve(changeDir, configured));
82
+ if (!promptPath || !statSync(promptPath).isFile()) {
83
+ throw new Error(managedText(language, `implementation_prompt 文件不存在:${configured}`, `implementation_prompt file does not exist: ${configured}`));
84
+ }
85
+ return promptPath;
86
+ }
87
+ function rejectSddTasksChecklist(promptPath, language) {
88
+ const normalized = promptPath.replaceAll("\\", "/");
89
+ if (path.basename(promptPath).toLowerCase() === "tasks.md" &&
90
+ normalized.includes("/openspec/changes/")) {
91
+ throw new Error(managedText(language, "tasks.md 是任务清单,不是 Agent 执行 Prompt;请提供 prompt/*.md 或 change 目录", "tasks.md is a checklist, not an Agent execution prompt; provide prompt/*.md or a change directory"));
92
+ }
93
+ }
94
+ function assertPromptInsideAllowedRoots(promptPath, roots, language) {
95
+ if (roots.some((root) => isInside(promptPath, root)))
96
+ return;
97
+ throw new Error(managedText(language, "任务 Prompt 不在项目目录或允许的关联仓库内", "Task prompt is outside the project and allowed related repositories"));
98
+ }
99
+ function isInside(file, root) {
100
+ const relative = path.relative(canonicalRoot(root), canonicalRoot(file));
101
+ return (relative === "" ||
102
+ (!relative.startsWith("..") && !path.isAbsolute(relative)));
103
+ }
104
+ function normalizeRoots(roots = []) {
105
+ return [...new Set(roots.map(canonicalRoot))].sort();
106
+ }
107
+ function canonicalRoot(value) {
108
+ const resolved = path.resolve(value);
109
+ return existsSync(resolved) ? realpathSync(resolved) : resolved;
110
+ }
111
+ function gitProjectRoot(directory) {
112
+ try {
113
+ return execFileSync("git", ["rev-parse", "--show-toplevel"], {
114
+ cwd: directory,
115
+ encoding: "utf-8",
116
+ stdio: ["ignore", "pipe", "ignore"],
117
+ }).trim();
118
+ }
119
+ catch {
120
+ return null;
121
+ }
122
+ }
123
+ function isSddPrompt(promptPath) {
124
+ return promptPath.replaceAll("\\", "/").includes("/openspec/changes/");
125
+ }
126
+ function realpathIfExists(value) {
127
+ return existsSync(value) ? realpathSync(value) : null;
128
+ }
129
+ function unquote(value) {
130
+ const trimmed = value.trim();
131
+ if ((trimmed.startsWith('"') && trimmed.endsWith('"')) ||
132
+ (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
133
+ return trimmed.slice(1, -1);
134
+ }
135
+ return trimmed;
136
+ }
137
+ //# sourceMappingURL=input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/domains/managed-work/input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACtE,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAkBxC,MAAM,UAAU,mBAAmB,CACjC,QAAgB,EAChB,UAAsC,EAAE;IAExC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,WAAW,CACT,OAAO,CAAC,QAAQ,EAChB,YAAY,EACZ,8BAA8B,CAC/B,CACF,CAAC;IACJ,CAAC;IACD,MAAM,cAAc,GAAG,aAAa,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3E,MAAM,YAAY,GAAG,yBAAyB,CAC5C,OAAO,EACP,cAAc,EACd,OAAO,CAAC,QAAQ,CACjB,CAAC;IACF,MAAM,SAAS,GAAG,YAAY,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACxE,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3B,OAAO;YACL,OAAO;YACP,WAAW,EAAE,cAAc;YAC3B,mBAAmB,EAAE,cAAc,CAAC,OAAO,CAAC,mBAAmB,CAAC;YAChE,OAAO,EAAE,OAAO,CAAC,OAAO;Y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