@kuafucloud/repo-kit 0.0.0-stage → 0.2.2-alpha.4

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 (212) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +6 -2
  3. package/assets/git-hooks/check-push.cjs +21 -0
  4. package/assets/git-hooks/pre-push +7 -0
  5. package/assets/git-hooks/prepare-commit-msg +5 -0
  6. package/assets/verification/heavy-test-admission-core.d.mts +1 -0
  7. package/assets/verification/heavy-test-admission-core.mjs +10 -0
  8. package/assets/verification/host-process-lock.d.mts +24 -0
  9. package/assets/verification/host-process-lock.mjs +140 -0
  10. package/assets/verification/test-heavy-admission.d.mts +4 -0
  11. package/assets/verification/test-heavy-admission.mjs +34 -0
  12. package/bin/kuafu-guard.mjs +3 -0
  13. package/bin/kuafu-verify.mjs +3 -0
  14. package/dist/cli/guard.d.ts +1 -0
  15. package/dist/cli/guard.js +59 -0
  16. package/dist/cli/verify.d.ts +1 -0
  17. package/dist/cli/verify.js +58 -0
  18. package/dist/guard/core/config.d.ts +7 -0
  19. package/dist/guard/core/config.js +159 -0
  20. package/dist/guard/core/engine.d.ts +2 -0
  21. package/dist/guard/core/engine.js +151 -0
  22. package/dist/guard/core/formatters/sarif-rules.d.ts +2 -0
  23. package/dist/guard/core/formatters/sarif-rules.js +67 -0
  24. package/dist/guard/core/formatters/sarif.d.ts +2 -0
  25. package/dist/guard/core/formatters/sarif.js +3 -0
  26. package/dist/guard/core/formatters/text.d.ts +2 -0
  27. package/dist/guard/core/formatters/text.js +22 -0
  28. package/dist/guard/core/index.d.ts +5 -0
  29. package/dist/guard/core/index.js +5 -0
  30. package/dist/guard/core/types.d.ts +94 -0
  31. package/dist/guard/core/types.js +1 -0
  32. package/dist/guard/hooks/install-rules.d.ts +2 -0
  33. package/dist/guard/hooks/install-rules.js +5 -0
  34. package/dist/guard/hooks/install.d.ts +36 -0
  35. package/dist/guard/hooks/install.js +212 -0
  36. package/dist/guard/hooks/push.d.ts +1 -0
  37. package/dist/guard/hooks/push.js +5 -0
  38. package/dist/guard/index.d.ts +16 -0
  39. package/dist/guard/index.js +16 -0
  40. package/dist/guard/product-roots.d.ts +12 -0
  41. package/dist/guard/product-roots.js +37 -0
  42. package/dist/guard/repo-args.d.ts +8 -0
  43. package/dist/guard/repo-args.js +75 -0
  44. package/dist/guard/repo-output-rules.d.ts +12 -0
  45. package/dist/guard/repo-output-rules.js +44 -0
  46. package/dist/guard/repo.d.ts +21 -0
  47. package/dist/guard/repo.js +74 -0
  48. package/dist/guard/rules/external/api/collect-orphan-tests.d.ts +2 -0
  49. package/dist/guard/rules/external/api/collect-orphan-tests.js +34 -0
  50. package/dist/guard/rules/external/api/collect.d.ts +2 -0
  51. package/dist/guard/rules/external/api/collect.js +419 -0
  52. package/dist/guard/rules/external/api/validate-orphan-tests.d.ts +2 -0
  53. package/dist/guard/rules/external/api/validate-orphan-tests.js +10 -0
  54. package/dist/guard/rules/external/api/validate.d.ts +2 -0
  55. package/dist/guard/rules/external/api/validate.js +278 -0
  56. package/dist/guard/rules/external/app/native-source-rules.d.ts +6 -0
  57. package/dist/guard/rules/external/app/native-source-rules.js +164 -0
  58. package/dist/guard/rules/external/app/validate-native-source-boundary.d.ts +2 -0
  59. package/dist/guard/rules/external/app/validate-native-source-boundary.js +187 -0
  60. package/dist/guard/rules/external/boundary/check.d.ts +4 -0
  61. package/dist/guard/rules/external/boundary/check.js +198 -0
  62. package/dist/guard/rules/external/extension/collect.d.ts +1 -0
  63. package/dist/guard/rules/external/extension/collect.js +1 -0
  64. package/dist/guard/rules/external/extension/electron-boundary-rules.d.ts +6 -0
  65. package/dist/guard/rules/external/extension/electron-boundary-rules.js +10 -0
  66. package/dist/guard/rules/external/extension/index.d.ts +6 -0
  67. package/dist/guard/rules/external/extension/index.js +29 -0
  68. package/dist/guard/rules/external/extension/manual-cross-call-rules.d.ts +19 -0
  69. package/dist/guard/rules/external/extension/manual-cross-call-rules.js +19 -0
  70. package/dist/guard/rules/external/extension/resolve-import.d.ts +1 -0
  71. package/dist/guard/rules/external/extension/resolve-import.js +43 -0
  72. package/dist/guard/rules/external/extension/scan-relative-dependencies.d.ts +5 -0
  73. package/dist/guard/rules/external/extension/scan-relative-dependencies.js +53 -0
  74. package/dist/guard/rules/external/extension/scan-source.d.ts +11 -0
  75. package/dist/guard/rules/external/extension/scan-source.js +25 -0
  76. package/dist/guard/rules/external/extension/source-import-boundary-rules.d.ts +26 -0
  77. package/dist/guard/rules/external/extension/source-import-boundary-rules.js +40 -0
  78. package/dist/guard/rules/external/extension/test-layer-import-rules.d.ts +1 -0
  79. package/dist/guard/rules/external/extension/test-layer-import-rules.js +16 -0
  80. package/dist/guard/rules/external/extension/types.d.ts +51 -0
  81. package/dist/guard/rules/external/extension/types.js +1 -0
  82. package/dist/guard/rules/external/extension/unused-export-rules.d.ts +23 -0
  83. package/dist/guard/rules/external/extension/unused-export-rules.js +119 -0
  84. package/dist/guard/rules/external/extension/unused-module-rules.d.ts +6 -0
  85. package/dist/guard/rules/external/extension/unused-module-rules.js +90 -0
  86. package/dist/guard/rules/external/extension/validate-admin.d.ts +8 -0
  87. package/dist/guard/rules/external/extension/validate-admin.js +73 -0
  88. package/dist/guard/rules/external/extension/validate-database.d.ts +3 -0
  89. package/dist/guard/rules/external/extension/validate-database.js +4 -0
  90. package/dist/guard/rules/external/extension/validate-electron-boundary.d.ts +2 -0
  91. package/dist/guard/rules/external/extension/validate-electron-boundary.js +18 -0
  92. package/dist/guard/rules/external/extension/validate-empty-dirs.d.ts +9 -0
  93. package/dist/guard/rules/external/extension/validate-empty-dirs.js +44 -0
  94. package/dist/guard/rules/external/extension/validate-extension-kit-server-boundary.d.ts +2 -0
  95. package/dist/guard/rules/external/extension/validate-extension-kit-server-boundary.js +116 -0
  96. package/dist/guard/rules/external/extension/validate-features.d.ts +7 -0
  97. package/dist/guard/rules/external/extension/validate-features.js +27 -0
  98. package/dist/guard/rules/external/extension/validate-manual-cross-extension-call.d.ts +2 -0
  99. package/dist/guard/rules/external/extension/validate-manual-cross-extension-call.js +131 -0
  100. package/dist/guard/rules/external/extension/validate-peer-extension-import.d.ts +2 -0
  101. package/dist/guard/rules/external/extension/validate-peer-extension-import.js +41 -0
  102. package/dist/guard/rules/external/extension/validate-server-cross-domain-import.d.ts +2 -0
  103. package/dist/guard/rules/external/extension/validate-server-cross-domain-import.js +48 -0
  104. package/dist/guard/rules/external/extension/validate-server-index-api-entry-satisfies.d.ts +1 -0
  105. package/dist/guard/rules/external/extension/validate-server-index-api-entry-satisfies.js +1 -0
  106. package/dist/guard/rules/external/extension/validate-shared-import-boundary.d.ts +2 -0
  107. package/dist/guard/rules/external/extension/validate-shared-import-boundary.js +40 -0
  108. package/dist/guard/rules/external/extension/validate-shared.d.ts +1 -0
  109. package/dist/guard/rules/external/extension/validate-shared.js +1 -0
  110. package/dist/guard/rules/external/extension/validate-test-layer-boundary.d.ts +8 -0
  111. package/dist/guard/rules/external/extension/validate-test-layer-boundary.js +59 -0
  112. package/dist/guard/rules/external/extension/validate-test-mirror.d.ts +4 -0
  113. package/dist/guard/rules/external/extension/validate-test-mirror.js +32 -0
  114. package/dist/guard/rules/external/extension/validate-top-level.d.ts +7 -0
  115. package/dist/guard/rules/external/extension/validate-top-level.js +76 -0
  116. package/dist/guard/rules/external/extension/validate-unused-export.d.ts +2 -0
  117. package/dist/guard/rules/external/extension/validate-unused-export.js +187 -0
  118. package/dist/guard/rules/external/extension/validate-unused-module.d.ts +2 -0
  119. package/dist/guard/rules/external/extension/validate-unused-module.js +38 -0
  120. package/dist/guard/rules/external/index.d.ts +1 -0
  121. package/dist/guard/rules/external/index.js +1 -0
  122. package/dist/guard/rules/external/npm-dependency-policy.d.ts +14 -0
  123. package/dist/guard/rules/external/npm-dependency-policy.js +216 -0
  124. package/dist/guard/rules/external/rules.d.ts +2 -0
  125. package/dist/guard/rules/external/rules.js +222 -0
  126. package/dist/guard/rules/external/shared/config.d.ts +3 -0
  127. package/dist/guard/rules/external/shared/config.js +14 -0
  128. package/dist/guard/rules/external/shared/diagnostic.d.ts +4 -0
  129. package/dist/guard/rules/external/shared/diagnostic.js +12 -0
  130. package/dist/guard/rules/external/shared/records.d.ts +4 -0
  131. package/dist/guard/rules/external/shared/records.js +46 -0
  132. package/dist/guard/rules/external/shared/ts-ast.d.ts +8 -0
  133. package/dist/guard/rules/external/shared/ts-ast.js +103 -0
  134. package/dist/guard/rules/external/shared/types.d.ts +159 -0
  135. package/dist/guard/rules/external/shared/types.js +1 -0
  136. package/dist/guard/rules/external/shared/validate-layer-key.d.ts +2 -0
  137. package/dist/guard/rules/external/shared/validate-layer-key.js +35 -0
  138. package/dist/guard/rules/external/story-rules.d.ts +15 -0
  139. package/dist/guard/rules/external/story-rules.js +59 -0
  140. package/dist/guard/rules/shared/extension/api-entry-tuple-rules.d.ts +7 -0
  141. package/dist/guard/rules/shared/extension/api-entry-tuple-rules.js +6 -0
  142. package/dist/guard/rules/shared/extension/collect.d.ts +5 -0
  143. package/dist/guard/rules/shared/extension/collect.js +231 -0
  144. package/dist/guard/rules/shared/extension/database-reference-rules.d.ts +4 -0
  145. package/dist/guard/rules/shared/extension/database-reference-rules.js +5 -0
  146. package/dist/guard/rules/shared/extension/database-source-rules.d.ts +17 -0
  147. package/dist/guard/rules/shared/extension/database-source-rules.js +595 -0
  148. package/dist/guard/rules/shared/extension/database-structure-rules.d.ts +3 -0
  149. package/dist/guard/rules/shared/extension/database-structure-rules.js +63 -0
  150. package/dist/guard/rules/shared/extension/server-index-source-rules.d.ts +2 -0
  151. package/dist/guard/rules/shared/extension/server-index-source-rules.js +91 -0
  152. package/dist/guard/rules/shared/extension/shared-consumer-rules.d.ts +23 -0
  153. package/dist/guard/rules/shared/extension/shared-consumer-rules.js +158 -0
  154. package/dist/guard/rules/shared/extension/shared-structure-rules.d.ts +6 -0
  155. package/dist/guard/rules/shared/extension/shared-structure-rules.js +27 -0
  156. package/dist/guard/rules/shared/extension/validate-database.d.ts +4 -0
  157. package/dist/guard/rules/shared/extension/validate-database.js +15 -0
  158. package/dist/guard/rules/shared/extension/validate-server-index-api-entry-satisfies.d.ts +2 -0
  159. package/dist/guard/rules/shared/extension/validate-server-index-api-entry-satisfies.js +9 -0
  160. package/dist/guard/rules/shared/extension/validate-shared.d.ts +18 -0
  161. package/dist/guard/rules/shared/extension/validate-shared.js +149 -0
  162. package/dist/host-protocol.d.ts +2 -0
  163. package/dist/host-protocol.js +2 -0
  164. package/dist/index.d.ts +3 -0
  165. package/dist/index.js +3 -0
  166. package/dist/verify/artifact-recovery-rules.d.ts +39 -0
  167. package/dist/verify/artifact-recovery-rules.js +48 -0
  168. package/dist/verify/artifact-session.d.ts +91 -0
  169. package/dist/verify/artifact-session.js +443 -0
  170. package/dist/verify/checkout-environment-rules.d.ts +2 -0
  171. package/dist/verify/checkout-environment-rules.js +25 -0
  172. package/dist/verify/checkout-environment.d.ts +8 -0
  173. package/dist/verify/checkout-environment.js +24 -0
  174. package/dist/verify/commit-candidate-rules.d.ts +3 -0
  175. package/dist/verify/commit-candidate-rules.js +33 -0
  176. package/dist/verify/commit-gate.d.ts +64 -0
  177. package/dist/verify/commit-gate.js +144 -0
  178. package/dist/verify/delivery-verification.d.ts +3 -0
  179. package/dist/verify/delivery-verification.js +21 -0
  180. package/dist/verify/e2e-registry-rules.d.ts +21 -0
  181. package/dist/verify/e2e-registry-rules.js +33 -0
  182. package/dist/verify/e2e-registry.d.ts +2 -0
  183. package/dist/verify/e2e-registry.js +45 -0
  184. package/dist/verify/full-command.d.ts +35 -0
  185. package/dist/verify/full-command.js +124 -0
  186. package/dist/verify/impact-plan-rules.d.ts +61 -0
  187. package/dist/verify/impact-plan-rules.js +185 -0
  188. package/dist/verify/impact-plan.d.ts +10 -0
  189. package/dist/verify/impact-plan.js +151 -0
  190. package/dist/verify/index.d.ts +22 -0
  191. package/dist/verify/index.js +22 -0
  192. package/dist/verify/repository-recipe-rules.d.ts +31 -0
  193. package/dist/verify/repository-recipe-rules.js +60 -0
  194. package/dist/verify/repository-recipe.d.ts +3 -0
  195. package/dist/verify/repository-recipe.js +58 -0
  196. package/dist/verify/static-validation-rules.d.ts +7 -0
  197. package/dist/verify/static-validation-rules.js +36 -0
  198. package/dist/verify/story-selection-rules.d.ts +57 -0
  199. package/dist/verify/story-selection-rules.js +125 -0
  200. package/dist/verify/types.d.ts +63 -0
  201. package/dist/verify/types.js +18 -0
  202. package/dist/verify/verification-candidate.d.ts +1 -0
  203. package/dist/verify/verification-candidate.js +20 -0
  204. package/dist/verify/verification-identity.d.ts +6 -0
  205. package/dist/verify/verification-identity.js +26 -0
  206. package/dist/verify/verification-proof-rules.d.ts +35 -0
  207. package/dist/verify/verification-proof-rules.js +45 -0
  208. package/dist/verify/verify-full-command-rules.d.ts +18 -0
  209. package/dist/verify/verify-full-command-rules.js +77 -0
  210. package/dist/verify/verify-full-runner.d.ts +32 -0
  211. package/dist/verify/verify-full-runner.js +251 -0
  212. package/package.json +115 -4
@@ -0,0 +1,125 @@
1
+ const DOC_OR_UNIT_ONLY_PATTERNS = [
2
+ /^docs\//u,
3
+ /\.md$/u,
4
+ /^\.agents\/skills\//u,
5
+ /^\.kuafu\/skills\//u,
6
+ /\/test\/unit\//u,
7
+ ];
8
+ const ALL_STORY_ESCALATION_PATTERNS = [
9
+ [/^(?:package\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml|nx\.json|tsconfig(?:\.[^/]+)?\.json|eslint\.config\.[^/]+)$/u, "root_config_or_lockfile_changed"],
10
+ [/^packages\/product-runtime\//u, "simulator_runtime_changed"],
11
+ [/^packages\/product-story\//u, "product_story_changed"],
12
+ [/^packages\/development-ui\//u, "preview_shell_changed"],
13
+ [/^packages\/development-service\//u, "story_service_changed"],
14
+ [/^packages\/playground-runtimes\//u, "simulation_runtime_changed"],
15
+ [/^packages\/product-build\//u, "product_build_changed"],
16
+ ];
17
+ /**
18
+ * 方案 19 §7.6 fail-closed 受影响故事选择规则:
19
+ * 1. 仅文档 / 技能 / 纯单测 → mode = "none";
20
+ * 2. 公共预览链路、锁文件、根配置、或无法归类的改动 → mode = "all"(fail-closed);
21
+ * 3. 受影响产品集合取所有故事 `product` 与 `frontends[*].product` 的并集命中。
22
+ */
23
+ export function selectAffectedStories(input) {
24
+ const allIds = [...input.catalog].map(s => s.id).sort();
25
+ if (input.forceAll) {
26
+ return { mode: "all", storyIds: allIds, affectedProducts: [], reasons: ["forced_full_scope"] };
27
+ }
28
+ if (input.changedPaths.length === 0) {
29
+ return { mode: "none", storyIds: [], affectedProducts: [], reasons: ["no_changed_paths"] };
30
+ }
31
+ const reasons = [];
32
+ let onlyDocsOrUnit = true;
33
+ const directProducts = new Set(input.affectedProductsFromGraph);
34
+ for (const rawPath of input.changedPaths) {
35
+ const file = rawPath.replace(/\\/gu, "/").replace(/^\.\//u, "");
36
+ const isDocOrUnit = DOC_OR_UNIT_ONLY_PATTERNS.some(pattern => pattern.test(file));
37
+ if (isDocOrUnit)
38
+ continue;
39
+ onlyDocsOrUnit = false;
40
+ for (const [pattern, reason] of ALL_STORY_ESCALATION_PATTERNS) {
41
+ if (pattern.test(file)) {
42
+ reasons.push(`${reason}:${file}`);
43
+ return { mode: "all", storyIds: allIds, affectedProducts: [], reasons };
44
+ }
45
+ }
46
+ const productMatch = /^products\/([^/]+)\//u.exec(file);
47
+ if (productMatch) {
48
+ directProducts.add(productMatch[1]);
49
+ continue;
50
+ }
51
+ if (file.startsWith("packages/")) {
52
+ // 若 Nx 图未能映射出受影响产品,则 fail-closed 跑全部故事。
53
+ if (input.affectedProductsFromGraph.length === 0) {
54
+ reasons.push(`unclassified_package_change:${file}`);
55
+ return { mode: "all", storyIds: allIds, affectedProducts: [], reasons };
56
+ }
57
+ continue;
58
+ }
59
+ reasons.push(`unclassified_path:${file}`);
60
+ return { mode: "all", storyIds: allIds, affectedProducts: [], reasons };
61
+ }
62
+ if (onlyDocsOrUnit) {
63
+ return { mode: "none", storyIds: [], affectedProducts: [], reasons: ["docs_skills_or_unit_only"] };
64
+ }
65
+ const productSet = directProducts;
66
+ const matched = input.catalog
67
+ .filter(story => {
68
+ if (productSet.has(story.product))
69
+ return true;
70
+ return Object.values(story.frontends).some(fe => productSet.has(fe.product));
71
+ })
72
+ .map(story => story.id)
73
+ .sort();
74
+ return {
75
+ mode: "affected",
76
+ storyIds: matched,
77
+ affectedProducts: [...productSet].sort(),
78
+ reasons: [`matched_products:${[...productSet].sort().join(",")}`],
79
+ };
80
+ }
81
+ /** 校验工作区本地数据后端:故事与交付只支持 DO SQLite,Postgres 后端直接拒绝。 */
82
+ export function assertStoryLocalBackendAllowed(backend) {
83
+ if (backend && backend !== "do") {
84
+ throw new Error(`本地模拟后端「${backend}」不支持故事验证(仅支持 DO SQLite),拒绝提交/交付。`);
85
+ }
86
+ }
87
+ /** 校验交付/提交时的故事验证证明是否完整、匹配当前暂存树且无跳过或超限。 */
88
+ export function validateStoryVerificationProof(proof, expected) {
89
+ if (!proof || proof.schemaVersion !== 1) {
90
+ return { ok: false, reason: "缺少有效的故事验证证明(schemaVersion=1)。" };
91
+ }
92
+ if (proof.treeHash !== expected.treeHash) {
93
+ return { ok: false, reason: "故事验证证明与当前暂存树 treeHash 不匹配,请重新执行 verify staged。" };
94
+ }
95
+ if (expected.expectedStoryIds.length === 0 && proof.mode === "none") {
96
+ return { ok: true };
97
+ }
98
+ if (proof.driver !== "cdp") {
99
+ return { ok: false, reason: "故事验证证明必须由 CLI(CDP 驱动)产出,不接受菜单/远程运行结果。" };
100
+ }
101
+ if (proof.source !== "staged" && proof.source !== "push") {
102
+ return { ok: false, reason: "故事验证证明来源必须是 staged 或 push。" };
103
+ }
104
+ if ((proof.failed ?? 1) > 0) {
105
+ return { ok: false, reason: `存在 ${proof.failed} 个失败故事。` };
106
+ }
107
+ if ((proof.skipped ?? 1) > 0) {
108
+ return { ok: false, reason: `存在 ${proof.skipped} 个被跳过故事(提交证明要求 skipped = 0)。` };
109
+ }
110
+ if ((proof.budgetExceeded ?? 0) > 0) {
111
+ return { ok: false, reason: `存在 ${proof.budgetExceeded} 项步骤耗时超出 maxDuration 预算。` };
112
+ }
113
+ if (expected.catalogDigest && proof.catalogDigest !== expected.catalogDigest) {
114
+ return { ok: false, reason: "故事目录摘要已变更,请重新执行验证。" };
115
+ }
116
+ if (expected.baselineKey && proof.baselineKey !== expected.baselineKey) {
117
+ return { ok: false, reason: "故事基线已变更,请重新执行验证。" };
118
+ }
119
+ const executed = new Set(proof.executedStoryIds ?? []);
120
+ const missing = expected.expectedStoryIds.filter(id => !executed.has(id));
121
+ if (missing.length > 0) {
122
+ return { ok: false, reason: `缺少受影响故事的验证记录:${missing.join(", ")}` };
123
+ }
124
+ return { ok: true };
125
+ }
@@ -0,0 +1,63 @@
1
+ export declare const DEV_WORKSPACE_STATUSES: readonly ["draft", "preparing", "active", "completed"];
2
+ export type DevWorkspaceStatus = typeof DEV_WORKSPACE_STATUSES[number];
3
+ export type DevWorkspaceExecutionMode = "desktop" | "dev-worktree";
4
+ export declare function isDevKey(value: string): boolean;
5
+ export declare function isTestTaskKey(value: string): boolean;
6
+ export declare function isTemporaryTaskKey(value: string): boolean;
7
+ export declare function isTestTask(value: Pick<DevWorkspaceRow, "taskTypeTags">): boolean;
8
+ export type DevWorkspaceRow = {
9
+ id: number;
10
+ branch: string;
11
+ status: DevWorkspaceStatus;
12
+ priority: number;
13
+ title: string | null;
14
+ /** 关联的 Task 文档编号;没有 Task 文档时为空,不能当 execution identity。 */
15
+ taskKey: string;
16
+ /** 执行工作区编号。聊天、预览、worktree、验证和 commit gate 绑定它。 */
17
+ devKey: string;
18
+ /** 仅历史测试工作区可能使用;正式 Task 文档编号不属于 DevWorkspace。 */
19
+ docNumber: number | null;
20
+ /** DevWorkspace 执行拓扑:当前 workspace 或独立 DEV worktree。 */
21
+ executionMode: DevWorkspaceExecutionMode;
22
+ /** 工作区关联标签;Task 文档标签以文档 metadata 为准。 */
23
+ taskTypeTags: string[];
24
+ /** 产品/库标签,如 developer / devmanager / runtime。 */
25
+ productTags: string[];
26
+ /** 可选 Task 文档路径;文档不反向决定 DevWorkspace 身份。 */
27
+ docPath: string | null;
28
+ worktreePath: string;
29
+ runtimeInfo: RuntimeInfo | null;
30
+ /** 当前活跃的 agent session ID。 */
31
+ currentSessionId: string | null;
32
+ createdAt: number;
33
+ updatedAt: number;
34
+ mergedAt: number | null;
35
+ destroyedAt: number | null;
36
+ };
37
+ export type TaskCreateInput = {
38
+ title: string;
39
+ content: string;
40
+ desktop?: boolean;
41
+ devKey?: string;
42
+ test?: boolean;
43
+ taskTypeTags?: string[];
44
+ productTags?: string[];
45
+ branch?: string;
46
+ priority?: number;
47
+ };
48
+ export type RuntimeInfo = {
49
+ conflict?: {
50
+ level: "none" | "high";
51
+ assessedAt: number;
52
+ blockedBy: Array<{
53
+ taskId: number;
54
+ title: string;
55
+ reason: string;
56
+ affectedPackages: string[];
57
+ }>;
58
+ };
59
+ workspace?: {
60
+ baseSha: string;
61
+ lastUsedAt: number;
62
+ };
63
+ };
@@ -0,0 +1,18 @@
1
+ export const DEV_WORKSPACE_STATUSES = [
2
+ "draft",
3
+ "preparing",
4
+ "active",
5
+ "completed",
6
+ ];
7
+ export function isDevKey(value) {
8
+ return /^DEV\d{6}$/u.test(value.trim().toUpperCase());
9
+ }
10
+ export function isTestTaskKey(value) {
11
+ return /^TEST\d{2,}$/u.test(value.trim().toUpperCase());
12
+ }
13
+ export function isTemporaryTaskKey(value) {
14
+ return isDevKey(value);
15
+ }
16
+ export function isTestTask(value) {
17
+ return value.taskTypeTags.some((tag) => tag.trim().toLowerCase() === "test");
18
+ }
@@ -0,0 +1 @@
1
+ export declare function assertVerificationCandidateIsIsolated(workspaceRoot: string): Promise<void>;
@@ -0,0 +1,20 @@
1
+ import { execFile } from "node:child_process";
2
+ export async function assertVerificationCandidateIsIsolated(workspaceRoot) {
3
+ const [unstaged, untracked] = await Promise.all([
4
+ readGitPathList(workspaceRoot, ["diff", "--name-only", "-z"]),
5
+ readGitPathList(workspaceRoot, ["ls-files", "--others", "--exclude-standard", "-z"]),
6
+ ]);
7
+ const dirty = [...new Set([...unstaged, ...untracked])].sort();
8
+ if (dirty.length > 0) {
9
+ throw new Error([
10
+ "verification.staged_candidate_dirty: verification must run from an isolated staged candidate",
11
+ ...dirty.slice(0, 20).map((file) => `- ${file}`),
12
+ ...(dirty.length > 20 ? [`- ... ${dirty.length - 20} more`] : []),
13
+ ].join("\n"));
14
+ }
15
+ }
16
+ async function readGitPathList(cwd, args) {
17
+ return (await new Promise((resolve, reject) => {
18
+ execFile("git", args, { cwd, encoding: "utf8" }, (error, stdout) => error ? reject(error) : resolve(stdout));
19
+ })).split("\0").filter(Boolean);
20
+ }
@@ -0,0 +1,6 @@
1
+ export type VerificationWorkspaceIdentity = {
2
+ workspaceId?: string;
3
+ devKey?: string;
4
+ };
5
+ /** 固定工作区必须显式绑定 UUID;旧本地入口仅在未声明 UUID 时保留旧身份。 */
6
+ export declare function normalizeVerificationWorkspaceIdentity(input: VerificationWorkspaceIdentity): VerificationWorkspaceIdentity;
@@ -0,0 +1,26 @@
1
+ import { normalizeWorkspaceId } from "@kuafucloud/product-runtime-protocol";
2
+ /** 固定工作区必须显式绑定 UUID;旧本地入口仅在未声明 UUID 时保留旧身份。 */
3
+ export function normalizeVerificationWorkspaceIdentity(input) {
4
+ if (input.workspaceId !== undefined) {
5
+ if (input.devKey !== undefined)
6
+ throw new Error("验证身份不能同时声明 workspaceId 和 DEV/manager。");
7
+ return { workspaceId: normalizeWorkspaceId(input.workspaceId) };
8
+ }
9
+ return { devKey: normalizeGateIdentity(input.devKey ?? "") };
10
+ }
11
+ function normalizeGateIdentity(value) {
12
+ const ref = value.trim().toUpperCase();
13
+ if (!ref) {
14
+ return "manager";
15
+ }
16
+ if (/^\d+$/u.test(ref)) {
17
+ throw new Error("commit gate identity must be manager or DEVMMDDNN; numeric taskId is not supported.");
18
+ }
19
+ if (ref === "MANAGER") {
20
+ return "manager";
21
+ }
22
+ if (/^DEV\d{6}$/u.test(ref)) {
23
+ return ref;
24
+ }
25
+ throw new Error("commit gate identity must be manager or DEVMMDDNN.");
26
+ }
@@ -0,0 +1,35 @@
1
+ export type VerificationRuntimeFacts = {
2
+ node: string;
3
+ pnpm: string;
4
+ hostToolchain: string | null;
5
+ };
6
+ /** 只判当前证明与已采样候选/工具事实,不采样Git、环境或文件。 */
7
+ export declare function matchesVerificationProofIdentity(proof: Record<string, unknown>, input: {
8
+ workspaceId?: string;
9
+ devKey?: string;
10
+ candidateTree: string | null;
11
+ stagedChangesHash: string;
12
+ headSha: string;
13
+ runtime: VerificationRuntimeFacts;
14
+ }): boolean;
15
+ export type VerificationPlanFacts = {
16
+ repositoryRecipe?: {
17
+ kind: string;
18
+ tool: string;
19
+ };
20
+ classifierVersion: string;
21
+ nxGraphDigest: string;
22
+ planDigest: string;
23
+ targetsByProject: Record<string, string[]>;
24
+ e2eTargets: string[];
25
+ alwaysRunChecks: string[];
26
+ resolvedMode: string;
27
+ };
28
+ /** 完整目标/命令记录与本次plan绑定;不接受自报passed代替执行闭包。 */
29
+ export declare function matchesVerificationProofCoverage(proof: Record<string, unknown>, proofPlan: VerificationPlanFacts, autoPlan: VerificationPlanFacts): boolean;
30
+ export declare function createVerificationProofCommandRecords(plan: Pick<VerificationPlanFacts, "alwaysRunChecks" | "targetsByProject" | "e2eTargets">, durationMs: number): {
31
+ id: string;
32
+ cwd: string;
33
+ result: "passed";
34
+ durationMs: number;
35
+ }[];
@@ -0,0 +1,45 @@
1
+ /** 只判当前证明与已采样候选/工具事实,不采样Git、环境或文件。 */
2
+ export function matchesVerificationProofIdentity(proof, input) {
3
+ const { headSha, runtime } = input;
4
+ const proofRuntime = proof.runtime;
5
+ return !((input.workspaceId
6
+ ? proof.schemaVersion !== 3 || proof.workspaceId !== input.workspaceId || Object.hasOwn(proof, "devKey")
7
+ || proof.candidateTree !== input.candidateTree
8
+ : proof.schemaVersion !== 2 || proof.devKey !== input.devKey || Object.hasOwn(proof, "workspaceId"))
9
+ || proof.stagedChangesHash !== input.stagedChangesHash
10
+ || proof.headSha !== headSha
11
+ || proof.result !== "passed"
12
+ || !proofRuntime || Object.entries(runtime).some(([key, value]) => proofRuntime[key] !== value));
13
+ }
14
+ /** 完整目标/命令记录与本次plan绑定;不接受自报passed代替执行闭包。 */
15
+ export function matchesVerificationProofCoverage(proof, proofPlan, autoPlan) {
16
+ const proofTargets = proof.targetsByProject && typeof proof.targetsByProject === "object" ? proof.targetsByProject : null;
17
+ const canonicalMatch = proof.classifierVersion === proofPlan.classifierVersion
18
+ && JSON.stringify(proof.repositoryRecipe) === JSON.stringify(proofPlan.repositoryRecipe)
19
+ && proof.nxGraphDigest === proofPlan.nxGraphDigest
20
+ && proof.planDigest === proofPlan.planDigest
21
+ && JSON.stringify(proofTargets) === JSON.stringify(proofPlan.targetsByProject)
22
+ && JSON.stringify(proof.e2eTargets) === JSON.stringify(proofPlan.e2eTargets)
23
+ && JSON.stringify(proof.alwaysRunChecks) === JSON.stringify(proofPlan.alwaysRunChecks);
24
+ const expectedCommandIds = new Set([
25
+ ...proofPlan.alwaysRunChecks,
26
+ ...Object.entries(proofPlan.targetsByProject).flatMap(([project, targets]) => (targets.map((target) => `project:${project}:${target}`))),
27
+ ...proofPlan.e2eTargets.map((suite) => `e2e:${suite}`),
28
+ ]);
29
+ const proofCommands = Array.isArray(proof.commands) ? proof.commands : [];
30
+ const passedCommandIds = new Set(proofCommands
31
+ .filter((command) => command?.result === "passed")
32
+ .map((command) => command.id)
33
+ .filter((id) => typeof id === "string"));
34
+ const commandCoverageMatches = passedCommandIds.size === expectedCommandIds.size
35
+ && [...expectedCommandIds].every((id) => passedCommandIds.has(id));
36
+ const sufficientMode = proof.resolvedMode === "full"
37
+ || (autoPlan.resolvedMode === "affected"
38
+ && proof.resolvedMode === "affected"
39
+ && proofPlan.planDigest === autoPlan.planDigest);
40
+ return canonicalMatch && sufficientMode && commandCoverageMatches;
41
+ }
42
+ export function createVerificationProofCommandRecords(plan, durationMs) {
43
+ const ids = [...plan.alwaysRunChecks, ...Object.entries(plan.targetsByProject).flatMap(([project, targets]) => targets.map(target => `project:${project}:${target}`)), ...plan.e2eTargets.map(suite => `e2e:${suite}`)];
44
+ return [...new Set(ids)].sort().map(id => ({ id, cwd: ".", result: "passed", durationMs }));
45
+ }
@@ -0,0 +1,18 @@
1
+ import type { VerificationImpactPlanV1 } from "./impact-plan-rules.js";
2
+ export type TaskVerifyFullDatabaseBackend = "do" | "postgres";
3
+ export declare const DEFAULT_TASK_VERIFY_FULL_COMMAND: string;
4
+ /** own-script 由正式分类计划选择;不能用 caller 的任意命令替换它。 */
5
+ export declare function selectTaskVerificationCommand(input: {
6
+ plan: VerificationImpactPlanV1;
7
+ command?: string;
8
+ databaseBackend?: string | null;
9
+ repositoryGuardCommand?: string;
10
+ repositoryBuildCommand?: string;
11
+ }): string;
12
+ export declare function createTaskVerifyFullCommand(input?: {
13
+ databaseBackend?: string | null;
14
+ repositoryGuardCommand?: string;
15
+ repositoryBuildCommand?: string;
16
+ }): string;
17
+ export declare function normalizeTaskVerifyFullDatabaseBackend(value: string | null | undefined): TaskVerifyFullDatabaseBackend | undefined;
18
+ export declare function createAffectedVerifyCommand(plan: Pick<VerificationImpactPlanV1, "targetsByProject" | "e2eTargets">, repositoryGuardCommand?: string): string;
@@ -0,0 +1,77 @@
1
+ import { createDefaultVerifyFullCommand, createHostArtifactSessionCommand, BROWSER_TEST_COMMAND, WORKSPACE_CORE_BROWSER_COMMAND } from "./full-command.js";
2
+ import { resolveVerificationE2ESuites } from "./e2e-registry-rules.js";
3
+ export const DEFAULT_TASK_VERIFY_FULL_COMMAND = createTaskVerifyFullCommand();
4
+ /** own-script 由正式分类计划选择;不能用 caller 的任意命令替换它。 */
5
+ export function selectTaskVerificationCommand(input) {
6
+ if (input.plan.repositoryRecipe) {
7
+ if (input.command?.trim())
8
+ throw new Error("verification.native_tool_command_override: 工具仓必须执行正式自有 verify 配方。");
9
+ return "pnpm run verify";
10
+ }
11
+ return input.command?.trim() || (input.plan.resolvedMode === "full"
12
+ ? createTaskVerifyFullCommand(input) : createAffectedVerifyCommand(input.plan, input.repositoryGuardCommand));
13
+ }
14
+ export function createTaskVerifyFullCommand(input) {
15
+ return createDefaultVerifyFullCommand({
16
+ databaseBackend: normalizeTaskVerifyFullDatabaseBackend(input?.databaseBackend) ?? "do",
17
+ repositoryGuardCommand: input?.repositoryGuardCommand,
18
+ repositoryBuildCommand: input?.repositoryBuildCommand,
19
+ });
20
+ }
21
+ export function normalizeTaskVerifyFullDatabaseBackend(value) {
22
+ const normalized = value?.trim().toLowerCase();
23
+ if (!normalized) {
24
+ return undefined;
25
+ }
26
+ if (normalized === "do" || normalized === "postgres") {
27
+ return normalized;
28
+ }
29
+ throw new Error(`Unsupported database backend: ${value}. Use "do" or "postgres".`);
30
+ }
31
+ export function createAffectedVerifyCommand(plan, repositoryGuardCommand) {
32
+ const commands = [
33
+ "export NX_DAEMON=false NX_NO_NETWORK_REQUESTS=true NX_TUI=false",
34
+ repositoryGuardCommand ?? "./agent-tool guard repo",
35
+ "if [ -f packages/platform-tool/package.json ]; then node packages/host-tooling/scripts/verify-architecture.mjs; fi",
36
+ "node node_modules/@kuafucloud/product-build/bin/product-build.mjs facades --cwd . --check",
37
+ "./agent-tool verify story --affected",
38
+ ];
39
+ const runtimeCommands = [];
40
+ for (const target of ["check-types", "lint", "build", "test"]) {
41
+ const projects = Object.entries(plan.targetsByProject)
42
+ .filter(([, targets]) => targets.includes(target))
43
+ .map(([project]) => project);
44
+ if (projects.length > 0) {
45
+ (target === "test" ? runtimeCommands : commands).push(`pnpm exec nx run-many --target=${target} --projects=${projects.map(shellQuote).join(",")} --parallel=1`);
46
+ }
47
+ }
48
+ const suites = resolveVerificationE2ESuites(plan.e2eTargets);
49
+ const hasWorkspaceCore = suites.some(suite => suite.id === "developer-workspace-core");
50
+ const browserSuites = suites.filter((suite) => suite.surface !== "electron" && suite.id !== "developer-workspace-core");
51
+ if (browserSuites.length > 0) {
52
+ const selectors = [...new Set(browserSuites.flatMap((suite) => suite.tests)
53
+ .map((selector) => selector.replace(/\/\*\*\/\*\.test\.ts$/u, "")))]
54
+ .map(shellQuote)
55
+ .join(" ");
56
+ const standaloneProductId = browserSuites.length === 1 ? browserSuites[0].standaloneProductId : undefined;
57
+ const productSelection = standaloneProductId
58
+ ? `PLATFORM_E2E_PRODUCT_ID=${shellQuote(standaloneProductId)} `
59
+ : "";
60
+ runtimeCommands.push(`${productSelection}${BROWSER_TEST_COMMAND} --project=host-local ${selectors}`);
61
+ }
62
+ if (hasWorkspaceCore) {
63
+ runtimeCommands.push(WORKSPACE_CORE_BROWSER_COMMAND);
64
+ }
65
+ if (suites.some((suite) => suite.surface === "electron")) {
66
+ runtimeCommands.push("pnpm --dir products/host run package:candidate");
67
+ runtimeCommands.push("PLATFORM_E2E_PREBUILT=1 pnpm --dir products/host run test:electron");
68
+ }
69
+ const needsHostInput = browserSuites.length > 0 || hasWorkspaceCore
70
+ || ["host", "developer"].some(project => plan.targetsByProject[project]?.includes("test"));
71
+ if (runtimeCommands.length)
72
+ commands.push(...(needsHostInput ? [createHostArtifactSessionCommand(runtimeCommands)] : runtimeCommands));
73
+ return commands.join(" && ");
74
+ }
75
+ function shellQuote(value) {
76
+ return `'${value.replaceAll("'", "'\\''")}'`;
77
+ }
@@ -0,0 +1,32 @@
1
+ export * from "./verify-full-command-rules.js";
2
+ import { type VerificationImpactPlanV1, type VerificationScope } from "./impact-plan.js";
3
+ export type TaskVerifyFullRunnerResult = {
4
+ ok: boolean;
5
+ devKey?: string;
6
+ workspaceId?: string;
7
+ stagedChangesHash: string;
8
+ proofPath: string | null;
9
+ command: string;
10
+ exitCode: number | null;
11
+ error: string | null;
12
+ plan: VerificationImpactPlanV1 | null;
13
+ logPath?: string;
14
+ };
15
+ export declare function runTaskVerifyFull(input: {
16
+ workspaceRoot: string;
17
+ devKey?: string;
18
+ workspaceId?: string;
19
+ command?: string;
20
+ databaseBackend?: string | null;
21
+ }): Promise<TaskVerifyFullRunnerResult>;
22
+ export declare function runTaskVerification(input: {
23
+ workspaceRoot: string;
24
+ devKey?: string;
25
+ workspaceId?: string;
26
+ command?: string;
27
+ databaseBackend?: string | null;
28
+ repositoryGuardCommand?: string;
29
+ repositoryBuildCommand?: string;
30
+ requestedScope: VerificationScope;
31
+ planOnly?: boolean;
32
+ }): Promise<TaskVerifyFullRunnerResult>;