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

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/assets/git-hooks/check-push.cjs +21 -0
  3. package/assets/git-hooks/pre-push +7 -0
  4. package/assets/git-hooks/prepare-commit-msg +5 -0
  5. package/assets/verification/heavy-test-admission-core.d.mts +1 -0
  6. package/assets/verification/heavy-test-admission-core.mjs +10 -0
  7. package/assets/verification/host-process-lock.d.mts +24 -0
  8. package/assets/verification/host-process-lock.mjs +140 -0
  9. package/assets/verification/test-heavy-admission.d.mts +4 -0
  10. package/assets/verification/test-heavy-admission.mjs +34 -0
  11. package/bin/kuafu-guard.mjs +3 -0
  12. package/bin/kuafu-verify.mjs +3 -0
  13. package/dist/cli/guard.d.ts +1 -0
  14. package/dist/cli/guard.js +59 -0
  15. package/dist/cli/verify.d.ts +1 -0
  16. package/dist/cli/verify.js +58 -0
  17. package/dist/guard/core/config.d.ts +7 -0
  18. package/dist/guard/core/config.js +159 -0
  19. package/dist/guard/core/engine.d.ts +2 -0
  20. package/dist/guard/core/engine.js +151 -0
  21. package/dist/guard/core/formatters/sarif-rules.d.ts +2 -0
  22. package/dist/guard/core/formatters/sarif-rules.js +67 -0
  23. package/dist/guard/core/formatters/sarif.d.ts +2 -0
  24. package/dist/guard/core/formatters/sarif.js +3 -0
  25. package/dist/guard/core/formatters/text.d.ts +2 -0
  26. package/dist/guard/core/formatters/text.js +22 -0
  27. package/dist/guard/core/index.d.ts +5 -0
  28. package/dist/guard/core/index.js +5 -0
  29. package/dist/guard/core/types.d.ts +94 -0
  30. package/dist/guard/core/types.js +1 -0
  31. package/dist/guard/hooks/install-rules.d.ts +2 -0
  32. package/dist/guard/hooks/install-rules.js +5 -0
  33. package/dist/guard/hooks/install.d.ts +36 -0
  34. package/dist/guard/hooks/install.js +212 -0
  35. package/dist/guard/hooks/push.d.ts +1 -0
  36. package/dist/guard/hooks/push.js +5 -0
  37. package/dist/guard/index.d.ts +16 -0
  38. package/dist/guard/index.js +16 -0
  39. package/dist/guard/product-roots.d.ts +12 -0
  40. package/dist/guard/product-roots.js +37 -0
  41. package/dist/guard/repo-args.d.ts +8 -0
  42. package/dist/guard/repo-args.js +75 -0
  43. package/dist/guard/repo-output-rules.d.ts +12 -0
  44. package/dist/guard/repo-output-rules.js +44 -0
  45. package/dist/guard/repo.d.ts +21 -0
  46. package/dist/guard/repo.js +74 -0
  47. package/dist/guard/rules/external/api/collect-orphan-tests.d.ts +2 -0
  48. package/dist/guard/rules/external/api/collect-orphan-tests.js +34 -0
  49. package/dist/guard/rules/external/api/collect.d.ts +2 -0
  50. package/dist/guard/rules/external/api/collect.js +419 -0
  51. package/dist/guard/rules/external/api/validate-orphan-tests.d.ts +2 -0
  52. package/dist/guard/rules/external/api/validate-orphan-tests.js +10 -0
  53. package/dist/guard/rules/external/api/validate.d.ts +2 -0
  54. package/dist/guard/rules/external/api/validate.js +278 -0
  55. package/dist/guard/rules/external/app/native-source-rules.d.ts +6 -0
  56. package/dist/guard/rules/external/app/native-source-rules.js +164 -0
  57. package/dist/guard/rules/external/app/validate-native-source-boundary.d.ts +2 -0
  58. package/dist/guard/rules/external/app/validate-native-source-boundary.js +187 -0
  59. package/dist/guard/rules/external/boundary/check.d.ts +4 -0
  60. package/dist/guard/rules/external/boundary/check.js +198 -0
  61. package/dist/guard/rules/external/extension/collect.d.ts +1 -0
  62. package/dist/guard/rules/external/extension/collect.js +1 -0
  63. package/dist/guard/rules/external/extension/electron-boundary-rules.d.ts +6 -0
  64. package/dist/guard/rules/external/extension/electron-boundary-rules.js +10 -0
  65. package/dist/guard/rules/external/extension/index.d.ts +6 -0
  66. package/dist/guard/rules/external/extension/index.js +29 -0
  67. package/dist/guard/rules/external/extension/manual-cross-call-rules.d.ts +19 -0
  68. package/dist/guard/rules/external/extension/manual-cross-call-rules.js +19 -0
  69. package/dist/guard/rules/external/extension/resolve-import.d.ts +1 -0
  70. package/dist/guard/rules/external/extension/resolve-import.js +43 -0
  71. package/dist/guard/rules/external/extension/scan-relative-dependencies.d.ts +5 -0
  72. package/dist/guard/rules/external/extension/scan-relative-dependencies.js +53 -0
  73. package/dist/guard/rules/external/extension/scan-source.d.ts +11 -0
  74. package/dist/guard/rules/external/extension/scan-source.js +25 -0
  75. package/dist/guard/rules/external/extension/source-import-boundary-rules.d.ts +26 -0
  76. package/dist/guard/rules/external/extension/source-import-boundary-rules.js +40 -0
  77. package/dist/guard/rules/external/extension/test-layer-import-rules.d.ts +1 -0
  78. package/dist/guard/rules/external/extension/test-layer-import-rules.js +16 -0
  79. package/dist/guard/rules/external/extension/types.d.ts +51 -0
  80. package/dist/guard/rules/external/extension/types.js +1 -0
  81. package/dist/guard/rules/external/extension/unused-export-rules.d.ts +23 -0
  82. package/dist/guard/rules/external/extension/unused-export-rules.js +119 -0
  83. package/dist/guard/rules/external/extension/unused-module-rules.d.ts +6 -0
  84. package/dist/guard/rules/external/extension/unused-module-rules.js +90 -0
  85. package/dist/guard/rules/external/extension/validate-admin.d.ts +8 -0
  86. package/dist/guard/rules/external/extension/validate-admin.js +73 -0
  87. package/dist/guard/rules/external/extension/validate-database.d.ts +3 -0
  88. package/dist/guard/rules/external/extension/validate-database.js +4 -0
  89. package/dist/guard/rules/external/extension/validate-electron-boundary.d.ts +2 -0
  90. package/dist/guard/rules/external/extension/validate-electron-boundary.js +18 -0
  91. package/dist/guard/rules/external/extension/validate-empty-dirs.d.ts +9 -0
  92. package/dist/guard/rules/external/extension/validate-empty-dirs.js +44 -0
  93. package/dist/guard/rules/external/extension/validate-extension-kit-server-boundary.d.ts +2 -0
  94. package/dist/guard/rules/external/extension/validate-extension-kit-server-boundary.js +116 -0
  95. package/dist/guard/rules/external/extension/validate-features.d.ts +7 -0
  96. package/dist/guard/rules/external/extension/validate-features.js +27 -0
  97. package/dist/guard/rules/external/extension/validate-manual-cross-extension-call.d.ts +2 -0
  98. package/dist/guard/rules/external/extension/validate-manual-cross-extension-call.js +131 -0
  99. package/dist/guard/rules/external/extension/validate-peer-extension-import.d.ts +2 -0
  100. package/dist/guard/rules/external/extension/validate-peer-extension-import.js +41 -0
  101. package/dist/guard/rules/external/extension/validate-server-cross-domain-import.d.ts +2 -0
  102. package/dist/guard/rules/external/extension/validate-server-cross-domain-import.js +48 -0
  103. package/dist/guard/rules/external/extension/validate-server-index-api-entry-satisfies.d.ts +1 -0
  104. package/dist/guard/rules/external/extension/validate-server-index-api-entry-satisfies.js +1 -0
  105. package/dist/guard/rules/external/extension/validate-shared-import-boundary.d.ts +2 -0
  106. package/dist/guard/rules/external/extension/validate-shared-import-boundary.js +40 -0
  107. package/dist/guard/rules/external/extension/validate-shared.d.ts +1 -0
  108. package/dist/guard/rules/external/extension/validate-shared.js +1 -0
  109. package/dist/guard/rules/external/extension/validate-test-layer-boundary.d.ts +8 -0
  110. package/dist/guard/rules/external/extension/validate-test-layer-boundary.js +59 -0
  111. package/dist/guard/rules/external/extension/validate-test-mirror.d.ts +4 -0
  112. package/dist/guard/rules/external/extension/validate-test-mirror.js +32 -0
  113. package/dist/guard/rules/external/extension/validate-top-level.d.ts +7 -0
  114. package/dist/guard/rules/external/extension/validate-top-level.js +76 -0
  115. package/dist/guard/rules/external/extension/validate-unused-export.d.ts +2 -0
  116. package/dist/guard/rules/external/extension/validate-unused-export.js +187 -0
  117. package/dist/guard/rules/external/extension/validate-unused-module.d.ts +2 -0
  118. package/dist/guard/rules/external/extension/validate-unused-module.js +38 -0
  119. package/dist/guard/rules/external/index.d.ts +1 -0
  120. package/dist/guard/rules/external/index.js +1 -0
  121. package/dist/guard/rules/external/npm-dependency-policy.d.ts +22 -0
  122. package/dist/guard/rules/external/npm-dependency-policy.js +294 -0
  123. package/dist/guard/rules/external/rules.d.ts +2 -0
  124. package/dist/guard/rules/external/rules.js +231 -0
  125. package/dist/guard/rules/external/shared/config.d.ts +3 -0
  126. package/dist/guard/rules/external/shared/config.js +14 -0
  127. package/dist/guard/rules/external/shared/diagnostic.d.ts +4 -0
  128. package/dist/guard/rules/external/shared/diagnostic.js +12 -0
  129. package/dist/guard/rules/external/shared/records.d.ts +4 -0
  130. package/dist/guard/rules/external/shared/records.js +46 -0
  131. package/dist/guard/rules/external/shared/ts-ast.d.ts +8 -0
  132. package/dist/guard/rules/external/shared/ts-ast.js +103 -0
  133. package/dist/guard/rules/external/shared/types.d.ts +159 -0
  134. package/dist/guard/rules/external/shared/types.js +1 -0
  135. package/dist/guard/rules/external/shared/validate-layer-key.d.ts +2 -0
  136. package/dist/guard/rules/external/shared/validate-layer-key.js +35 -0
  137. package/dist/guard/rules/external/story-rules.d.ts +15 -0
  138. package/dist/guard/rules/external/story-rules.js +59 -0
  139. package/dist/guard/rules/shared/extension/api-entry-tuple-rules.d.ts +7 -0
  140. package/dist/guard/rules/shared/extension/api-entry-tuple-rules.js +6 -0
  141. package/dist/guard/rules/shared/extension/collect.d.ts +5 -0
  142. package/dist/guard/rules/shared/extension/collect.js +231 -0
  143. package/dist/guard/rules/shared/extension/database-reference-rules.d.ts +4 -0
  144. package/dist/guard/rules/shared/extension/database-reference-rules.js +5 -0
  145. package/dist/guard/rules/shared/extension/database-source-rules.d.ts +17 -0
  146. package/dist/guard/rules/shared/extension/database-source-rules.js +595 -0
  147. package/dist/guard/rules/shared/extension/database-structure-rules.d.ts +3 -0
  148. package/dist/guard/rules/shared/extension/database-structure-rules.js +63 -0
  149. package/dist/guard/rules/shared/extension/server-index-source-rules.d.ts +2 -0
  150. package/dist/guard/rules/shared/extension/server-index-source-rules.js +91 -0
  151. package/dist/guard/rules/shared/extension/shared-consumer-rules.d.ts +23 -0
  152. package/dist/guard/rules/shared/extension/shared-consumer-rules.js +158 -0
  153. package/dist/guard/rules/shared/extension/shared-structure-rules.d.ts +6 -0
  154. package/dist/guard/rules/shared/extension/shared-structure-rules.js +27 -0
  155. package/dist/guard/rules/shared/extension/validate-database.d.ts +4 -0
  156. package/dist/guard/rules/shared/extension/validate-database.js +15 -0
  157. package/dist/guard/rules/shared/extension/validate-server-index-api-entry-satisfies.d.ts +2 -0
  158. package/dist/guard/rules/shared/extension/validate-server-index-api-entry-satisfies.js +9 -0
  159. package/dist/guard/rules/shared/extension/validate-shared.d.ts +18 -0
  160. package/dist/guard/rules/shared/extension/validate-shared.js +149 -0
  161. package/dist/host-protocol.d.ts +2 -0
  162. package/dist/host-protocol.js +2 -0
  163. package/dist/index.d.ts +3 -0
  164. package/dist/index.js +3 -0
  165. package/dist/verify/artifact-recovery-rules.d.ts +39 -0
  166. package/dist/verify/artifact-recovery-rules.js +48 -0
  167. package/dist/verify/artifact-session.d.ts +91 -0
  168. package/dist/verify/artifact-session.js +443 -0
  169. package/dist/verify/checkout-environment-rules.d.ts +2 -0
  170. package/dist/verify/checkout-environment-rules.js +25 -0
  171. package/dist/verify/checkout-environment.d.ts +8 -0
  172. package/dist/verify/checkout-environment.js +24 -0
  173. package/dist/verify/commit-candidate-rules.d.ts +3 -0
  174. package/dist/verify/commit-candidate-rules.js +33 -0
  175. package/dist/verify/commit-gate.d.ts +64 -0
  176. package/dist/verify/commit-gate.js +207 -0
  177. package/dist/verify/delivery-verification.d.ts +3 -0
  178. package/dist/verify/delivery-verification.js +21 -0
  179. package/dist/verify/e2e-registry-rules.d.ts +21 -0
  180. package/dist/verify/e2e-registry-rules.js +33 -0
  181. package/dist/verify/e2e-registry.d.ts +2 -0
  182. package/dist/verify/e2e-registry.js +45 -0
  183. package/dist/verify/full-command.d.ts +35 -0
  184. package/dist/verify/full-command.js +138 -0
  185. package/dist/verify/impact-plan-rules.d.ts +61 -0
  186. package/dist/verify/impact-plan-rules.js +185 -0
  187. package/dist/verify/impact-plan.d.ts +10 -0
  188. package/dist/verify/impact-plan.js +151 -0
  189. package/dist/verify/index.d.ts +22 -0
  190. package/dist/verify/index.js +22 -0
  191. package/dist/verify/repository-recipe-rules.d.ts +31 -0
  192. package/dist/verify/repository-recipe-rules.js +60 -0
  193. package/dist/verify/repository-recipe.d.ts +3 -0
  194. package/dist/verify/repository-recipe.js +58 -0
  195. package/dist/verify/static-validation-rules.d.ts +7 -0
  196. package/dist/verify/static-validation-rules.js +36 -0
  197. package/dist/verify/story-selection-rules.d.ts +57 -0
  198. package/dist/verify/story-selection-rules.js +125 -0
  199. package/dist/verify/types.d.ts +63 -0
  200. package/dist/verify/types.js +18 -0
  201. package/dist/verify/verification-candidate.d.ts +1 -0
  202. package/dist/verify/verification-candidate.js +20 -0
  203. package/dist/verify/verification-identity.d.ts +6 -0
  204. package/dist/verify/verification-identity.js +26 -0
  205. package/dist/verify/verification-proof-rules.d.ts +35 -0
  206. package/dist/verify/verification-proof-rules.js +45 -0
  207. package/dist/verify/verify-full-command-rules.d.ts +18 -0
  208. package/dist/verify/verify-full-command-rules.js +77 -0
  209. package/dist/verify/verify-full-runner.d.ts +32 -0
  210. package/dist/verify/verify-full-runner.js +251 -0
  211. package/package.json +115 -4
  212. package/README.md +0 -3
@@ -0,0 +1,251 @@
1
+ import { createHash } from "node:crypto";
2
+ import { assertVerificationCandidateIsIsolated } from "./verification-candidate.js";
3
+ import { withHeavyTestAdmission } from "#test-heavy-admission";
4
+ import { spawn } from "node:child_process";
5
+ import { closeSync, openSync, writeSync, existsSync } from "node:fs";
6
+ import { mkdir, rename, writeFile, realpath, readFile } from "node:fs/promises";
7
+ import path from "node:path";
8
+ import { selectTaskVerificationCommand } from "./verify-full-command-rules.js";
9
+ import { createVerificationProofCommandRecords } from "./verification-proof-rules.js";
10
+ import { assertNativeToolVerificationRuntime } from "./repository-recipe-rules.js";
11
+ export * from "./verify-full-command-rules.js";
12
+ import { createCheckoutVerificationEnvironment, readCheckoutVerificationRuntime } from "./checkout-environment.js";
13
+ import { computeStagedChangesHash, resolveVerifyProofPath, runTaskCommitGate, normalizeVerificationWorkspaceIdentity, resolveVerificationStateRoot, } from "./commit-gate.js";
14
+ import { createVerificationImpactPlan, } from "./impact-plan.js";
15
+ import { assertVerificationE2EClosure } from "./e2e-registry.js";
16
+ import { readVerificationArtifactSession, releaseVerificationArtifactSession } from "./artifact-session.js";
17
+ export async function runTaskVerifyFull(input) {
18
+ return await runTaskVerification({ ...input, requestedScope: "full" });
19
+ }
20
+ export async function runTaskVerification(input) {
21
+ await assertVerificationCandidateIsIsolated(input.workspaceRoot);
22
+ const identity = normalizeVerificationWorkspaceIdentity(input);
23
+ const plan = await createVerificationImpactPlan({
24
+ workspaceRoot: input.workspaceRoot,
25
+ requestedScope: input.requestedScope,
26
+ });
27
+ await assertVerificationE2EClosure(input.workspaceRoot, plan.e2eTargets);
28
+ const command = selectTaskVerificationCommand({ ...input, plan });
29
+ const beforeStagedChangesHash = await computeStagedChangesHash(input.workspaceRoot);
30
+ const candidateTree = (await readGitValue(input.workspaceRoot, ["write-tree"])).trim();
31
+ if (input.planOnly) {
32
+ return {
33
+ ok: true,
34
+ ...identity,
35
+ stagedChangesHash: beforeStagedChangesHash,
36
+ proofPath: null,
37
+ command,
38
+ exitCode: null,
39
+ error: null,
40
+ plan,
41
+ };
42
+ }
43
+ // 已提交候选的空索引没有待提交 Task;结果仍在结束时绑定 HEAD、tree 和运行时。
44
+ const committed = input.requestedScope === "full" && candidateTree === (await readGitValue(input.workspaceRoot, ["rev-parse", "HEAD^{tree}"])).trim();
45
+ const preflight = committed ? null : await runTaskCommitGate({
46
+ workspaceRoot: input.workspaceRoot,
47
+ ...identity,
48
+ requireVerifyProof: false,
49
+ });
50
+ if (preflight && !preflight.ok) {
51
+ return {
52
+ ok: false,
53
+ ...identity,
54
+ stagedChangesHash: beforeStagedChangesHash,
55
+ proofPath: null,
56
+ command,
57
+ exitCode: null,
58
+ error: `fast commit gate failed: ${preflight.errors.map((error) => error.message).join(" ")}`,
59
+ plan,
60
+ };
61
+ }
62
+ // 外层持有准入直到候选复核、目录回收和 proof 发布完成;子命令只借用。
63
+ return await withHeavyTestAdmission({ workspaceRoot: input.workspaceRoot }, async (environment) => {
64
+ const logDirectory = path.join(resolveVerificationStateRoot(input.workspaceRoot, identity), "logs");
65
+ await mkdir(logDirectory, { recursive: true });
66
+ const logPath = path.join(logDirectory, `${beforeStagedChangesHash}-${Date.now()}.log`);
67
+ const artifactSessionPath = `${logPath}.artifact-session.json`;
68
+ const runtimeBefore = await readCheckoutVerificationRuntime(input.workspaceRoot);
69
+ assertNativeToolVerificationRuntime(plan.repositoryRecipe, runtimeBefore);
70
+ const checkpointInputs = committed && !input.command && existsSync(path.join(input.workspaceRoot, "packages/platform-tool/package.json"))
71
+ ? await Promise.all(["node_modules/.kuafu-local-development-install.json", "node_modules/.modules.yaml"].map(async (file) => await readFile(path.join(input.workspaceRoot, file), "utf8").catch((error) => { if (error.code === "ENOENT")
72
+ return null; throw error; }))) : null;
73
+ const checkpoint = checkpointInputs ? createHash("sha256").update(JSON.stringify([identity, plan.headSha, candidateTree, plan.planDigest,
74
+ command, runtimeBefore, checkpointInputs, Object.entries(createCheckoutVerificationEnvironment(input.workspaceRoot, process.env))
75
+ .filter(([key]) => !["KUAFU_HEAVY_TEST_ADMISSION", "KUAFU_VERIFY_ARTIFACT_SESSION_RECORD", "KUAFU_VERIFY_COMMITTED_CANDIDATE", "_"].includes(key))
76
+ .sort(([a], [b]) => a.localeCompare(b))])).digest("hex") : "";
77
+ const verifyResult = await runShellCommand({
78
+ cwd: input.workspaceRoot,
79
+ command,
80
+ logPath,
81
+ artifactSessionPath,
82
+ environment: { ...environment, KUAFU_VERIFY_COMMITTED_CANDIDATE: checkpoint ? plan.headSha + ":" + checkpoint : "" },
83
+ });
84
+ if (verifyResult.exitCode !== 0) {
85
+ return {
86
+ ok: false,
87
+ ...identity,
88
+ stagedChangesHash: beforeStagedChangesHash,
89
+ proofPath: null,
90
+ command,
91
+ exitCode: verifyResult.exitCode,
92
+ error: `verify command failed with exit=${verifyResult.exitCode ?? "null"}; log=${logPath}`,
93
+ logPath,
94
+ plan,
95
+ };
96
+ }
97
+ const artifactSession = await readVerificationArtifactSession(input.workspaceRoot, artifactSessionPath);
98
+ if (!artifactSession && command.includes("node --import tsx products/host/scripts/test-artifact-session.mjs")
99
+ && existsSync(path.join(input.workspaceRoot, "packages/platform-tool/package.json"))) {
100
+ return { ok: false, ...identity, stagedChangesHash: beforeStagedChangesHash,
101
+ proofPath: null, command, exitCode: verifyResult.exitCode, error: "Full verification did not produce its artifact session record", plan };
102
+ }
103
+ // 消费者已完成,先由原 owner 回收大目录。候选漂移、工具检查或 proof 写入失败也能结清。
104
+ if (artifactSession) {
105
+ try {
106
+ await releaseVerificationArtifactSession(input.workspaceRoot, artifactSessionPath, artifactSession);
107
+ }
108
+ catch (error) {
109
+ return { ok: false, ...identity, stagedChangesHash: beforeStagedChangesHash,
110
+ proofPath: null, command, exitCode: verifyResult.exitCode,
111
+ error: `Verification artifact cleanup failed: ${error instanceof Error ? error.message : String(error)}`, logPath, plan };
112
+ }
113
+ }
114
+ const afterStagedChangesHash = await computeStagedChangesHash(input.workspaceRoot);
115
+ await assertVerificationCandidateIsIsolated(input.workspaceRoot);
116
+ const headChanged = (await readGitValue(input.workspaceRoot, ["rev-parse", "HEAD"])).trim() !== plan.headSha;
117
+ const treeChanged = (await readGitValue(input.workspaceRoot, ["write-tree"])).trim() !== candidateTree;
118
+ if (afterStagedChangesHash !== beforeStagedChangesHash || headChanged || treeChanged) {
119
+ return {
120
+ ok: false,
121
+ ...identity,
122
+ stagedChangesHash: afterStagedChangesHash,
123
+ proofPath: null,
124
+ command,
125
+ exitCode: verifyResult.exitCode,
126
+ error: headChanged ? "HEAD changed during verify; rerun verify full against the current base"
127
+ : "staged source changed during verify; rerun verify full after staging is stable",
128
+ plan,
129
+ };
130
+ }
131
+ const proofPath = resolveVerifyProofPath({
132
+ workspaceRoot: input.workspaceRoot,
133
+ ...identity,
134
+ });
135
+ await mkdir(path.dirname(proofPath), { recursive: true });
136
+ const nx = await readCheckoutNxVersion(input.workspaceRoot);
137
+ const runtime = await readCheckoutVerificationRuntime(input.workspaceRoot);
138
+ if (JSON.stringify(runtime) !== JSON.stringify(runtimeBefore)) {
139
+ return { ok: false, ...identity, stagedChangesHash: beforeStagedChangesHash,
140
+ proofPath: null, command, exitCode: verifyResult.exitCode, error: "Execution tools changed during verification; rerun with the current tools", plan };
141
+ }
142
+ const proof = {
143
+ schemaVersion: identity.workspaceId ? 3 : 2,
144
+ ...(identity.workspaceId ? { candidateTree } : {}),
145
+ ...identity,
146
+ requestedScope: input.requestedScope,
147
+ resolvedMode: plan.resolvedMode,
148
+ headSha: plan.headSha,
149
+ stagedChangesHash: beforeStagedChangesHash,
150
+ classifierVersion: plan.classifierVersion,
151
+ nxGraphDigest: plan.nxGraphDigest,
152
+ planDigest: plan.planDigest,
153
+ changedPaths: plan.changedPaths,
154
+ directProjects: plan.directProjects,
155
+ affectedProjects: plan.affectedProjects,
156
+ affectedProducts: plan.affectedProducts,
157
+ targetsByProject: plan.targetsByProject,
158
+ e2eTargets: plan.e2eTargets,
159
+ alwaysRunChecks: plan.alwaysRunChecks,
160
+ ...(plan.repositoryRecipe ? { repositoryRecipe: plan.repositoryRecipe } : {}),
161
+ escalationReasons: plan.escalationReasons,
162
+ commands: createVerificationProofCommandRecords(plan, verifyResult.durationMs),
163
+ ...(artifactSession ? { artifactSession: { id: artifactSession.id, receiptSha256: artifactSession.receiptSha256,
164
+ sourceDigest: artifactSession.sourceDigest, stages: artifactSession.stages } } : {}),
165
+ result: "passed",
166
+ verifiedAt: new Date().toISOString(),
167
+ runtime: {
168
+ ...runtime,
169
+ nx,
170
+ },
171
+ };
172
+ // 版本读取也经过子进程,完成后再绑定最终基线与候选,不能发布已过期的成功事实。
173
+ await assertVerificationCandidateIsIsolated(input.workspaceRoot);
174
+ if ((await readGitValue(input.workspaceRoot, ["rev-parse", "HEAD"])).trim() !== plan.headSha
175
+ || (await readGitValue(input.workspaceRoot, ["write-tree"])).trim() !== candidateTree
176
+ || await computeStagedChangesHash(input.workspaceRoot) !== beforeStagedChangesHash) {
177
+ return { ok: false, ...identity, stagedChangesHash: await computeStagedChangesHash(input.workspaceRoot),
178
+ proofPath: null, command, exitCode: verifyResult.exitCode, error: "HEAD or staged source changed while reading verification metadata", plan };
179
+ }
180
+ const temporaryProofPath = `${proofPath}.${process.pid}.tmp`;
181
+ await writeFile(temporaryProofPath, JSON.stringify(proof, null, 2), "utf-8");
182
+ await rename(temporaryProofPath, proofPath);
183
+ return {
184
+ ok: true,
185
+ ...identity,
186
+ stagedChangesHash: beforeStagedChangesHash,
187
+ proofPath,
188
+ command,
189
+ exitCode: verifyResult.exitCode,
190
+ error: null,
191
+ plan,
192
+ };
193
+ });
194
+ }
195
+ function readGitValue(cwd, args) {
196
+ return new Promise((resolve, reject) => {
197
+ const child = spawn("git", args, { cwd, stdio: ["ignore", "pipe", "pipe"], env: process.env });
198
+ const chunks = [];
199
+ let errorOutput = "";
200
+ child.stdout.on("data", (chunk) => chunks.push(chunk));
201
+ child.stderr.setEncoding("utf8");
202
+ child.stderr.on("data", (chunk) => { errorOutput += chunk; });
203
+ child.once("error", reject);
204
+ child.once("exit", (code) => {
205
+ if (code !== 0)
206
+ return reject(new Error(`verification.classification_failed: git candidate inspection failed: ${errorOutput.trim()}`));
207
+ resolve(Buffer.concat(chunks).toString("utf8"));
208
+ });
209
+ });
210
+ }
211
+ function runShellCommand(input) {
212
+ return new Promise((resolve, reject) => {
213
+ const startedAt = Date.now();
214
+ const log = openSync(input.logPath, "wx", 0o600);
215
+ const child = spawn(input.command, {
216
+ cwd: input.cwd,
217
+ shell: true,
218
+ stdio: ["inherit", "pipe", "pipe"],
219
+ env: {
220
+ ...createCheckoutVerificationEnvironment(input.cwd, input.environment),
221
+ NX_DAEMON: process.env.NX_DAEMON ?? "false",
222
+ NX_NO_NETWORK_REQUESTS: process.env.NX_NO_NETWORK_REQUESTS ?? "true",
223
+ NX_TUI: process.env.NX_TUI ?? "false",
224
+ KUAFU_VERIFY_ARTIFACT_SESSION_RECORD: input.artifactSessionPath,
225
+ },
226
+ });
227
+ child.stdout.on("data", (chunk) => { writeSync(log, chunk); process.stdout.write(chunk); });
228
+ child.stderr.on("data", (chunk) => { writeSync(log, chunk); process.stderr.write(chunk); });
229
+ // close 等待两条输出流结束,失败日志保留到最后一行;没有改变门禁或 proof 条件。
230
+ child.once("error", reject);
231
+ child.once("close", (code) => {
232
+ closeSync(log);
233
+ resolve({ exitCode: code, durationMs: Date.now() - startedAt });
234
+ });
235
+ });
236
+ }
237
+ async function readCheckoutNxVersion(workspaceRoot) {
238
+ if (!existsSync(path.join(workspaceRoot, "nx.json")))
239
+ return "not-used";
240
+ const root = await realpath(workspaceRoot);
241
+ const manifestPath = await realpath(path.join(root, "node_modules", "nx", "package.json"));
242
+ const relative = path.relative(root, manifestPath);
243
+ if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
244
+ throw new Error("验证使用的 Nx 必须来自本工作区冻结依赖。");
245
+ }
246
+ const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
247
+ if (manifest.name !== "nx" || typeof manifest.version !== "string" || !manifest.version.trim()) {
248
+ throw new Error("本工作区 Nx 版本清单无效。");
249
+ }
250
+ return manifest.version;
251
+ }
package/package.json CHANGED
@@ -1,6 +1,117 @@
1
1
  {
2
2
  "name": "@kuafucloud/repo-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.2-alpha.3",
4
+ "private": false,
5
+ "license": "SEE LICENSE IN LICENSE.md",
6
+ "type": "module",
7
+ "kuafu": {
8
+ "hostProtocol": 1
9
+ },
10
+ "bin": {
11
+ "kuafu-guard": "./bin/kuafu-guard.mjs",
12
+ "kuafu-verify": "./bin/kuafu-verify.mjs"
13
+ },
14
+ "files": [
15
+ "bin",
16
+ "dist",
17
+ "assets",
18
+ "LICENSE.md",
19
+ "README.md",
20
+ "!dist/**/*.map"
21
+ ],
22
+ "imports": {
23
+ "#test-heavy-admission": "./assets/verification/test-heavy-admission.mjs"
24
+ },
25
+ "exports": {
26
+ "./package.json": "./package.json",
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ },
31
+ "./guard": {
32
+ "types": "./dist/guard/index.d.ts",
33
+ "import": "./dist/guard/index.js"
34
+ },
35
+ "./guard/repo": {
36
+ "types": "./dist/guard/repo.d.ts",
37
+ "import": "./dist/guard/repo.js"
38
+ },
39
+ "./guard/hooks": {
40
+ "types": "./dist/guard/hooks/install.d.ts",
41
+ "import": "./dist/guard/hooks/install.js"
42
+ },
43
+ "./verify": {
44
+ "types": "./dist/verify/index.d.ts",
45
+ "import": "./dist/verify/index.js"
46
+ },
47
+ "./verify/full-command": {
48
+ "types": "./dist/verify/full-command.d.ts",
49
+ "import": "./dist/verify/full-command.js"
50
+ },
51
+ "./verify/static-validation-rules": {
52
+ "types": "./dist/verify/static-validation-rules.d.ts",
53
+ "import": "./dist/verify/static-validation-rules.js"
54
+ },
55
+ "./verify/commit-gate": {
56
+ "types": "./dist/verify/commit-gate.d.ts",
57
+ "import": "./dist/verify/commit-gate.js"
58
+ },
59
+ "./verify/verify-full-runner": {
60
+ "types": "./dist/verify/verify-full-runner.d.ts",
61
+ "import": "./dist/verify/verify-full-runner.js"
62
+ },
63
+ "./verify/verification-identity": {
64
+ "types": "./dist/verify/verification-identity.d.ts",
65
+ "import": "./dist/verify/verification-identity.js"
66
+ },
67
+ "./verify/story-selection": {
68
+ "types": "./dist/verify/story-selection-rules.d.ts",
69
+ "import": "./dist/verify/story-selection-rules.js"
70
+ },
71
+ "./guard/story-rules": {
72
+ "types": "./dist/guard/rules/external/story-rules.d.ts",
73
+ "import": "./dist/guard/rules/external/story-rules.js"
74
+ },
75
+ "./verify/artifact-session": {
76
+ "types": "./dist/verify/artifact-session.d.ts",
77
+ "import": "./dist/verify/artifact-session.js"
78
+ },
79
+ "./host-protocol": {
80
+ "types": "./dist/host-protocol.d.ts",
81
+ "import": "./dist/host-protocol.js"
82
+ },
83
+ "./guard/hooks/push": {
84
+ "types": "./dist/guard/hooks/push.d.ts",
85
+ "import": "./dist/guard/hooks/push.js"
86
+ }
87
+ },
88
+ "scripts": {
89
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
90
+ "check-types": "tsc -p tsconfig.json --noEmit",
91
+ "lint": "eslint src/",
92
+ "test": "pnpm run test:unit",
93
+ "test:unit": "node --import tsx ../testing-infrastructure/test-source-unit.mjs"
94
+ },
95
+ "dependencies": {
96
+ "@kuafucloud/product-build": "0.2.2-alpha.4",
97
+ "typescript": "5.9.3",
98
+ "yaml": "2.9.0",
99
+ "zod": "^3.25.76",
100
+ "@kuafucloud/product-runtime-protocol": "0.2.2-alpha.2"
101
+ },
102
+ "devDependencies": {
103
+ "@types/node": "^25.5.2",
104
+ "vitest": "^3.0.0"
105
+ },
106
+ "kuafucloud": {
107
+ "classification": "publishable"
108
+ },
109
+ "publishConfig": {
110
+ "access": "public",
111
+ "registry": "https://registry.npmjs.org/"
112
+ },
113
+ "repository": {
114
+ "type": "git",
115
+ "url": "git+https://github.com/kuafucloud/kuafu-npm-publisher.git"
116
+ }
117
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.