@neurcode-ai/cli 0.10.0 → 0.12.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 (189) hide show
  1. package/.telemetry-bundle/dist/__tests__/harvest-verify.test.d.ts +1 -0
  2. package/.telemetry-bundle/dist/__tests__/harvest-verify.test.js +86 -0
  3. package/.telemetry-bundle/dist/contracts.d.ts +58 -0
  4. package/.telemetry-bundle/dist/contracts.js +8 -0
  5. package/.telemetry-bundle/dist/harvest-verify.d.ts +9 -0
  6. package/.telemetry-bundle/dist/harvest-verify.js +128 -0
  7. package/.telemetry-bundle/dist/index.d.ts +10 -0
  8. package/.telemetry-bundle/dist/index.js +22 -0
  9. package/.telemetry-bundle/dist/precision/leaderboards.d.ts +20 -0
  10. package/.telemetry-bundle/dist/precision/leaderboards.js +72 -0
  11. package/.telemetry-bundle/dist/reader.d.ts +5 -0
  12. package/.telemetry-bundle/dist/reader.js +46 -0
  13. package/.telemetry-bundle/dist/stable-json.d.ts +5 -0
  14. package/.telemetry-bundle/dist/stable-json.js +24 -0
  15. package/.telemetry-bundle/dist/store.d.ts +10 -0
  16. package/.telemetry-bundle/dist/store.js +52 -0
  17. package/.telemetry-bundle/dist/trust-scoring.d.ts +20 -0
  18. package/.telemetry-bundle/dist/trust-scoring.js +58 -0
  19. package/.telemetry-bundle/package.json +8 -0
  20. package/README.md +74 -25
  21. package/dist/commands/remediate-export.js +1 -1
  22. package/dist/commands/replay.d.ts.map +1 -1
  23. package/dist/commands/replay.js +36 -0
  24. package/dist/commands/replay.js.map +1 -1
  25. package/dist/commands/verify-output.d.ts.map +1 -1
  26. package/dist/commands/verify-output.js +66 -4
  27. package/dist/commands/verify-output.js.map +1 -1
  28. package/dist/commands/verify.d.ts +22 -1
  29. package/dist/commands/verify.d.ts.map +1 -1
  30. package/dist/commands/verify.js +446 -34
  31. package/dist/commands/verify.js.map +1 -1
  32. package/dist/daemon/server.d.ts.map +1 -1
  33. package/dist/daemon/server.js +4 -0
  34. package/dist/daemon/server.js.map +1 -1
  35. package/dist/governance/intent/drift-detector.d.ts +100 -0
  36. package/dist/governance/intent/drift-detector.d.ts.map +1 -0
  37. package/dist/governance/intent/drift-detector.js +275 -0
  38. package/dist/governance/intent/drift-detector.js.map +1 -0
  39. package/dist/governance/intent/glob-match.d.ts +43 -0
  40. package/dist/governance/intent/glob-match.d.ts.map +1 -0
  41. package/dist/governance/intent/glob-match.js +108 -0
  42. package/dist/governance/intent/glob-match.js.map +1 -0
  43. package/dist/governance/intent/import-graph.d.ts +56 -0
  44. package/dist/governance/intent/import-graph.d.ts.map +1 -0
  45. package/dist/governance/intent/import-graph.js +133 -0
  46. package/dist/governance/intent/import-graph.js.map +1 -0
  47. package/dist/governance/intent/index.d.ts +23 -0
  48. package/dist/governance/intent/index.d.ts.map +1 -0
  49. package/dist/governance/intent/index.js +48 -0
  50. package/dist/governance/intent/index.js.map +1 -0
  51. package/dist/governance/intent/intelligence-boundaries.d.ts +69 -0
  52. package/dist/governance/intent/intelligence-boundaries.d.ts.map +1 -0
  53. package/dist/governance/intent/intelligence-boundaries.js +163 -0
  54. package/dist/governance/intent/intelligence-boundaries.js.map +1 -0
  55. package/dist/governance/intent/intent-contract.d.ts +76 -0
  56. package/dist/governance/intent/intent-contract.d.ts.map +1 -0
  57. package/dist/governance/intent/intent-contract.js +397 -0
  58. package/dist/governance/intent/intent-contract.js.map +1 -0
  59. package/dist/governance/intent/intent-graph.d.ts +135 -0
  60. package/dist/governance/intent/intent-graph.d.ts.map +1 -0
  61. package/dist/governance/intent/intent-graph.js +67 -0
  62. package/dist/governance/intent/intent-graph.js.map +1 -0
  63. package/dist/governance/pipeline/computation-trace.d.ts +52 -0
  64. package/dist/governance/pipeline/computation-trace.d.ts.map +1 -0
  65. package/dist/governance/pipeline/computation-trace.js +79 -0
  66. package/dist/governance/pipeline/computation-trace.js.map +1 -0
  67. package/dist/governance/pipeline/envelope-assembly.d.ts +132 -0
  68. package/dist/governance/pipeline/envelope-assembly.d.ts.map +1 -0
  69. package/dist/governance/pipeline/envelope-assembly.js +140 -0
  70. package/dist/governance/pipeline/envelope-assembly.js.map +1 -0
  71. package/dist/governance/pipeline/fingerprint.d.ts +34 -0
  72. package/dist/governance/pipeline/fingerprint.d.ts.map +1 -0
  73. package/dist/governance/pipeline/fingerprint.js +78 -0
  74. package/dist/governance/pipeline/fingerprint.js.map +1 -0
  75. package/dist/governance/pipeline/helpers.d.ts +74 -0
  76. package/dist/governance/pipeline/helpers.d.ts.map +1 -0
  77. package/dist/governance/pipeline/helpers.js +112 -0
  78. package/dist/governance/pipeline/helpers.js.map +1 -0
  79. package/dist/governance/pipeline/index.d.ts +27 -0
  80. package/dist/governance/pipeline/index.d.ts.map +1 -0
  81. package/dist/governance/pipeline/index.js +63 -0
  82. package/dist/governance/pipeline/index.js.map +1 -0
  83. package/dist/governance/pipeline/lineage.d.ts +26 -0
  84. package/dist/governance/pipeline/lineage.d.ts.map +1 -0
  85. package/dist/governance/pipeline/lineage.js +51 -0
  86. package/dist/governance/pipeline/lineage.js.map +1 -0
  87. package/dist/governance/pipeline/orchestration/advisory-mode-contract.d.ts +15 -0
  88. package/dist/governance/pipeline/orchestration/advisory-mode-contract.d.ts.map +1 -0
  89. package/dist/governance/pipeline/orchestration/advisory-mode-contract.js +44 -0
  90. package/dist/governance/pipeline/orchestration/advisory-mode-contract.js.map +1 -0
  91. package/dist/governance/pipeline/orchestration/advisory-mode.d.ts +102 -0
  92. package/dist/governance/pipeline/orchestration/advisory-mode.d.ts.map +1 -0
  93. package/dist/governance/pipeline/orchestration/advisory-mode.js +170 -0
  94. package/dist/governance/pipeline/orchestration/advisory-mode.js.map +1 -0
  95. package/dist/governance/pipeline/orchestration/evidence-lifecycle.d.ts +133 -0
  96. package/dist/governance/pipeline/orchestration/evidence-lifecycle.d.ts.map +1 -0
  97. package/dist/governance/pipeline/orchestration/evidence-lifecycle.js +125 -0
  98. package/dist/governance/pipeline/orchestration/evidence-lifecycle.js.map +1 -0
  99. package/dist/governance/pipeline/orchestration/index.d.ts +16 -0
  100. package/dist/governance/pipeline/orchestration/index.d.ts.map +1 -0
  101. package/dist/governance/pipeline/orchestration/index.js +30 -0
  102. package/dist/governance/pipeline/orchestration/index.js.map +1 -0
  103. package/dist/governance/pipeline/orchestration/intent-drift-orchestration.d.ts +65 -0
  104. package/dist/governance/pipeline/orchestration/intent-drift-orchestration.d.ts.map +1 -0
  105. package/dist/governance/pipeline/orchestration/intent-drift-orchestration.js +102 -0
  106. package/dist/governance/pipeline/orchestration/intent-drift-orchestration.js.map +1 -0
  107. package/dist/governance/pipeline/orchestration/plan-structural-analysis.d.ts +41 -0
  108. package/dist/governance/pipeline/orchestration/plan-structural-analysis.d.ts.map +1 -0
  109. package/dist/governance/pipeline/orchestration/plan-structural-analysis.js +74 -0
  110. package/dist/governance/pipeline/orchestration/plan-structural-analysis.js.map +1 -0
  111. package/dist/governance/pipeline/orchestration/policy-evaluation-summaries.d.ts +165 -0
  112. package/dist/governance/pipeline/orchestration/policy-evaluation-summaries.d.ts.map +1 -0
  113. package/dist/governance/pipeline/orchestration/policy-evaluation-summaries.js +160 -0
  114. package/dist/governance/pipeline/orchestration/policy-evaluation-summaries.js.map +1 -0
  115. package/dist/governance/pipeline/orchestration/scope-guard-orchestration.d.ts +152 -0
  116. package/dist/governance/pipeline/orchestration/scope-guard-orchestration.d.ts.map +1 -0
  117. package/dist/governance/pipeline/orchestration/scope-guard-orchestration.js +188 -0
  118. package/dist/governance/pipeline/orchestration/scope-guard-orchestration.js.map +1 -0
  119. package/dist/governance/pipeline/runtime.d.ts +70 -0
  120. package/dist/governance/pipeline/runtime.d.ts.map +1 -0
  121. package/dist/governance/pipeline/runtime.js +223 -0
  122. package/dist/governance/pipeline/runtime.js.map +1 -0
  123. package/dist/governance/pipeline/shared-types.d.ts +7 -0
  124. package/dist/governance/pipeline/shared-types.d.ts.map +1 -0
  125. package/dist/governance/pipeline/shared-types.js +7 -0
  126. package/dist/governance/pipeline/shared-types.js.map +1 -0
  127. package/dist/governance/pipeline/stages/compiled-policy-stage.d.ts +28 -0
  128. package/dist/governance/pipeline/stages/compiled-policy-stage.d.ts.map +1 -0
  129. package/dist/governance/pipeline/stages/compiled-policy-stage.js +53 -0
  130. package/dist/governance/pipeline/stages/compiled-policy-stage.js.map +1 -0
  131. package/dist/governance/pipeline/stages/diff-normalization-stage.d.ts +63 -0
  132. package/dist/governance/pipeline/stages/diff-normalization-stage.d.ts.map +1 -0
  133. package/dist/governance/pipeline/stages/diff-normalization-stage.js +140 -0
  134. package/dist/governance/pipeline/stages/diff-normalization-stage.js.map +1 -0
  135. package/dist/governance/pipeline/stages/governance-synthesis-stage.d.ts +53 -0
  136. package/dist/governance/pipeline/stages/governance-synthesis-stage.d.ts.map +1 -0
  137. package/dist/governance/pipeline/stages/governance-synthesis-stage.js +129 -0
  138. package/dist/governance/pipeline/stages/governance-synthesis-stage.js.map +1 -0
  139. package/dist/governance/pipeline/stages/index.d.ts +29 -0
  140. package/dist/governance/pipeline/stages/index.d.ts.map +1 -0
  141. package/dist/governance/pipeline/stages/index.js +40 -0
  142. package/dist/governance/pipeline/stages/index.js.map +1 -0
  143. package/dist/governance/pipeline/stages/policy-lock-stage.d.ts +31 -0
  144. package/dist/governance/pipeline/stages/policy-lock-stage.d.ts.map +1 -0
  145. package/dist/governance/pipeline/stages/policy-lock-stage.js +71 -0
  146. package/dist/governance/pipeline/stages/policy-lock-stage.js.map +1 -0
  147. package/dist/governance/pipeline/stages/runtime-guard-stage.d.ts +29 -0
  148. package/dist/governance/pipeline/stages/runtime-guard-stage.d.ts.map +1 -0
  149. package/dist/governance/pipeline/stages/runtime-guard-stage.js +65 -0
  150. package/dist/governance/pipeline/stages/runtime-guard-stage.js.map +1 -0
  151. package/dist/governance/pipeline/stages/structural-analysis-stage.d.ts +24 -0
  152. package/dist/governance/pipeline/stages/structural-analysis-stage.d.ts.map +1 -0
  153. package/dist/governance/pipeline/stages/structural-analysis-stage.js +58 -0
  154. package/dist/governance/pipeline/stages/structural-analysis-stage.js.map +1 -0
  155. package/dist/governance/pipeline/summary.d.ts +14 -0
  156. package/dist/governance/pipeline/summary.d.ts.map +1 -0
  157. package/dist/governance/pipeline/summary.js +50 -0
  158. package/dist/governance/pipeline/summary.js.map +1 -0
  159. package/dist/governance/pipeline/types.d.ts +69 -0
  160. package/dist/governance/pipeline/types.d.ts.map +1 -0
  161. package/dist/governance/pipeline/types.js +30 -0
  162. package/dist/governance/pipeline/types.js.map +1 -0
  163. package/dist/index.js +29 -0
  164. package/dist/index.js.map +1 -1
  165. package/dist/utils/active-engineering-context.d.ts +16 -0
  166. package/dist/utils/active-engineering-context.d.ts.map +1 -1
  167. package/dist/utils/active-engineering-context.js +302 -0
  168. package/dist/utils/active-engineering-context.js.map +1 -1
  169. package/dist/utils/import-edge-classifier.d.ts +76 -0
  170. package/dist/utils/import-edge-classifier.d.ts.map +1 -0
  171. package/dist/utils/import-edge-classifier.js +308 -0
  172. package/dist/utils/import-edge-classifier.js.map +1 -0
  173. package/dist/utils/import-edge-extractor.d.ts +52 -0
  174. package/dist/utils/import-edge-extractor.d.ts.map +1 -0
  175. package/dist/utils/import-edge-extractor.js +223 -0
  176. package/dist/utils/import-edge-extractor.js.map +1 -0
  177. package/dist/utils/import-edge-governance.d.ts +37 -0
  178. package/dist/utils/import-edge-governance.d.ts.map +1 -0
  179. package/dist/utils/import-edge-governance.js +56 -0
  180. package/dist/utils/import-edge-governance.js.map +1 -0
  181. package/dist/utils/path-boundary-classifier.d.ts +42 -0
  182. package/dist/utils/path-boundary-classifier.d.ts.map +1 -0
  183. package/dist/utils/path-boundary-classifier.js +143 -0
  184. package/dist/utils/path-boundary-classifier.js.map +1 -0
  185. package/dist/utils/replay-html-report.d.ts +29 -0
  186. package/dist/utils/replay-html-report.d.ts.map +1 -0
  187. package/dist/utils/replay-html-report.js +309 -0
  188. package/dist/utils/replay-html-report.js.map +1 -0
  189. package/package.json +6 -5
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Shared types used across pipeline modules. Kept narrow to avoid a circular
3
+ * dependency between envelope-assembly and verify.ts.
4
+ */
5
+ /** Mirror of `PolicyOnlySource` declared inside verify.ts. */
6
+ export type PolicyOnlySource = 'explicit' | 'fallback_missing_plan' | 'ci';
7
+ //# sourceMappingURL=shared-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-types.d.ts","sourceRoot":"","sources":["../../../src/governance/pipeline/shared-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,8DAA8D;AAC9D,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,uBAAuB,GAAG,IAAI,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Shared types used across pipeline modules. Kept narrow to avoid a circular
4
+ * dependency between envelope-assembly and verify.ts.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=shared-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-types.js","sourceRoot":"","sources":["../../../src/governance/pipeline/shared-types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Compiled Policy Stage
3
+ * ---------------------
4
+ * Loads the compiled policy artifact (signed JSON) from disk, exposes its
5
+ * fingerprint, and reports load/parse failures via stage status. Pure wrapper
6
+ * around `readCompiledPolicyArtifact` from `utils/policy-compiler`.
7
+ *
8
+ * SEMANTIC PRESERVATION:
9
+ * The returned `artifact` and `error` fields are byte-identical to what
10
+ * `readCompiledPolicyArtifact` returns inline. Signature verification and
11
+ * strict-artifact-mode policy live in verify.ts — this stage only loads.
12
+ */
13
+ import { type CompiledPolicyArtifact } from '../../../utils/policy-compiler';
14
+ import type { GovernancePipelineStage } from '../types';
15
+ export interface CompiledPolicyInput {
16
+ projectRoot: string;
17
+ /** Optional override path for the compiled artifact (CLI flag). */
18
+ compiledPolicyPath?: string;
19
+ }
20
+ export interface CompiledPolicyOutput {
21
+ path: string;
22
+ exists: boolean;
23
+ artifact: CompiledPolicyArtifact | null;
24
+ error?: string;
25
+ fingerprint: string | null;
26
+ }
27
+ export declare const compiledPolicyStage: GovernancePipelineStage<CompiledPolicyInput, CompiledPolicyOutput>;
28
+ //# sourceMappingURL=compiled-policy-stage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiled-policy-stage.d.ts","sourceRoot":"","sources":["../../../../src/governance/pipeline/stages/compiled-policy-stage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAGxD,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,sBAAsB,GAAG,IAAI,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,eAAO,MAAM,mBAAmB,EAAE,uBAAuB,CACvD,mBAAmB,EACnB,oBAAoB,CAuCrB,CAAC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * Compiled Policy Stage
4
+ * ---------------------
5
+ * Loads the compiled policy artifact (signed JSON) from disk, exposes its
6
+ * fingerprint, and reports load/parse failures via stage status. Pure wrapper
7
+ * around `readCompiledPolicyArtifact` from `utils/policy-compiler`.
8
+ *
9
+ * SEMANTIC PRESERVATION:
10
+ * The returned `artifact` and `error` fields are byte-identical to what
11
+ * `readCompiledPolicyArtifact` returns inline. Signature verification and
12
+ * strict-artifact-mode policy live in verify.ts — this stage only loads.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.compiledPolicyStage = void 0;
16
+ const policy_compiler_1 = require("../../../utils/policy-compiler");
17
+ const fingerprint_1 = require("../fingerprint");
18
+ exports.compiledPolicyStage = {
19
+ id: 'compiled-policy',
20
+ determinism: 'deterministic-structural',
21
+ boundary: {
22
+ isolateFailure: true, // loading the compiled artifact is best-effort; verify.ts handles strict mode
23
+ required: false,
24
+ dependencies: [],
25
+ },
26
+ description: 'Load compiled policy artifact and expose its fingerprint for replay lineage.',
27
+ execute(input) {
28
+ const result = (0, policy_compiler_1.readCompiledPolicyArtifact)(input.projectRoot, input.compiledPolicyPath);
29
+ return {
30
+ path: result.path,
31
+ exists: result.exists,
32
+ artifact: result.artifact ?? null,
33
+ error: result.error,
34
+ fingerprint: result.artifact?.fingerprint ?? null,
35
+ };
36
+ },
37
+ fingerprintInput(input) {
38
+ return (0, fingerprint_1.fingerprintStageSignal)({
39
+ compiledPolicyPath: input.compiledPolicyPath ?? null,
40
+ });
41
+ },
42
+ fingerprintOutput(output) {
43
+ return (0, fingerprint_1.fingerprintStageSignal)({
44
+ exists: output.exists,
45
+ fingerprint: output.fingerprint,
46
+ hasError: Boolean(output.error),
47
+ });
48
+ },
49
+ outputItemCount(output) {
50
+ return output.artifact?.compilation?.deterministicRules?.length ?? 0;
51
+ },
52
+ };
53
+ //# sourceMappingURL=compiled-policy-stage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiled-policy-stage.js","sourceRoot":"","sources":["../../../../src/governance/pipeline/stages/compiled-policy-stage.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAGH,oEAGwC;AACxC,gDAAwD;AAkB3C,QAAA,mBAAmB,GAG5B;IACF,EAAE,EAAE,iBAAiB;IACrB,WAAW,EAAE,0BAAuD;IACpE,QAAQ,EAAE;QACR,cAAc,EAAE,IAAI,EAAE,8EAA8E;QACpG,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,EAAE;KACjB;IACD,WAAW,EAAE,8EAA8E;IAE3F,OAAO,CAAC,KAA0B;QAChC,MAAM,MAAM,GAAG,IAAA,4CAA0B,EAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACvF,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,IAAI;YACjC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,WAAW,EAAE,MAAM,CAAC,QAAQ,EAAE,WAAW,IAAI,IAAI;SAClD,CAAC;IACJ,CAAC;IAED,gBAAgB,CAAC,KAA0B;QACzC,OAAO,IAAA,oCAAsB,EAAC;YAC5B,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,IAAI,IAAI;SACrD,CAAC,CAAC;IACL,CAAC;IAED,iBAAiB,CAAC,MAA4B;QAC5C,OAAO,IAAA,oCAAsB,EAAC;YAC5B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;SAChC,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,MAA4B;QAC1C,OAAO,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAC,CAAC;IACvE,CAAC;CACF,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Diff Normalization Stage
3
+ * ------------------------
4
+ * Canonical stage that resolves the diff context, parses tracked/staged diff,
5
+ * merges untracked files, and applies the project-wide exclusion filter.
6
+ *
7
+ * SEMANTIC PRESERVATION:
8
+ * This stage is a structural wrapper around the pre-existing diff loading
9
+ * logic in `verify.ts`. The order of operations, the helper functions
10
+ * invoked, and the returned `diffFiles` set are byte-identical to the
11
+ * inline implementation. The stage adds nothing but lineage and metrics.
12
+ *
13
+ * Specifically, this stage MUST produce the same DiffFile[] that
14
+ * `verify.ts` line ~3580 produces — every downstream pipeline step
15
+ * depends on that identity.
16
+ */
17
+ import { type DiffFile } from '@neurcode-ai/diff-parser';
18
+ import type { GovernancePipelineStage } from '../types';
19
+ export type DiffMode = 'staged' | 'base' | 'head' | 'auto';
20
+ export interface DiffNormalizationInput {
21
+ /** Absolute project root, used for resolving default diff context. */
22
+ projectRoot: string;
23
+ /** Requested diff mode. 'auto' resolves origin/main → origin/master → staged. */
24
+ mode: DiffMode;
25
+ /** Explicit base ref when mode === 'base'. */
26
+ baseRef?: string;
27
+ /**
28
+ * Function to source untracked files. Injected so we can:
29
+ * - reuse verify.ts's pre-existing `getUntrackedDiffFiles` without
30
+ * duplicating its excluded-file rules
31
+ * - test the stage with deterministic fixtures
32
+ */
33
+ getUntrackedDiffFiles: (projectRoot: string) => DiffFile[];
34
+ /**
35
+ * Function to test whether a path should be excluded from analysis.
36
+ * Injected for the same reason as `getUntrackedDiffFiles`.
37
+ */
38
+ isExcludedFile: (filePath: string) => boolean;
39
+ }
40
+ export interface DiffNormalizationOutput {
41
+ /** Raw `git diff` text. */
42
+ diffText: string;
43
+ /** Human-readable label, e.g. "working tree vs origin/main". */
44
+ diffContextLabel: string;
45
+ /** Diff files after parsing and untracked merge, BEFORE exclusion filter. */
46
+ allDiffFiles: DiffFile[];
47
+ /** Diff files after exclusion filtering — canonical input to downstream stages. */
48
+ diffFiles: DiffFile[];
49
+ /** True when no tracked or untracked changes are present. */
50
+ emptyDiff: boolean;
51
+ /** Count of files removed by the exclusion filter. */
52
+ excludedFileCount: number;
53
+ }
54
+ /**
55
+ * Stage definition. Use with `runStage(diffNormalizationStage, input, ctx)`.
56
+ */
57
+ export declare const diffNormalizationStage: GovernancePipelineStage<DiffNormalizationInput, DiffNormalizationOutput>;
58
+ /**
59
+ * Pure helper for direct invocation (used both by the stage and by tests).
60
+ * Mirrors the semantics of the verify.ts inline implementation.
61
+ */
62
+ export declare function computeDiffNormalization(input: DiffNormalizationInput): DiffNormalizationOutput;
63
+ //# sourceMappingURL=diff-normalization-stage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff-normalization-stage.d.ts","sourceRoot":"","sources":["../../../../src/governance/pipeline/stages/diff-normalization-stage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAIpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAKxD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAE3D,MAAM,WAAW,sBAAsB;IACrC,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,IAAI,EAAE,QAAQ,CAAC;IACf,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,qBAAqB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,QAAQ,EAAE,CAAC;IAC3D;;;OAGG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CAC/C;AAED,MAAM,WAAW,uBAAuB;IACtC,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,gBAAgB,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,YAAY,EAAE,QAAQ,EAAE,CAAC;IACzB,mFAAmF;IACnF,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,6DAA6D;IAC7D,SAAS,EAAE,OAAO,CAAC;IACnB,sDAAsD;IACtD,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,uBAAuB,CAC1D,sBAAsB,EACtB,uBAAuB,CA4CxB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,sBAAsB,GAC5B,uBAAuB,CAqEzB"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ /**
3
+ * Diff Normalization Stage
4
+ * ------------------------
5
+ * Canonical stage that resolves the diff context, parses tracked/staged diff,
6
+ * merges untracked files, and applies the project-wide exclusion filter.
7
+ *
8
+ * SEMANTIC PRESERVATION:
9
+ * This stage is a structural wrapper around the pre-existing diff loading
10
+ * logic in `verify.ts`. The order of operations, the helper functions
11
+ * invoked, and the returned `diffFiles` set are byte-identical to the
12
+ * inline implementation. The stage adds nothing but lineage and metrics.
13
+ *
14
+ * Specifically, this stage MUST produce the same DiffFile[] that
15
+ * `verify.ts` line ~3580 produces — every downstream pipeline step
16
+ * depends on that identity.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.diffNormalizationStage = void 0;
20
+ exports.computeDiffNormalization = computeDiffNormalization;
21
+ const child_process_1 = require("child_process");
22
+ const diff_parser_1 = require("@neurcode-ai/diff-parser");
23
+ const git_1 = require("../../../utils/git");
24
+ const fingerprint_1 = require("../fingerprint");
25
+ const types_1 = require("../types");
26
+ const GIT_DIFF_MAX_BUFFER = 1024 * 1024 * 1024;
27
+ /**
28
+ * Stage definition. Use with `runStage(diffNormalizationStage, input, ctx)`.
29
+ */
30
+ exports.diffNormalizationStage = {
31
+ id: 'diff-normalization',
32
+ determinism: 'deterministic-structural',
33
+ boundary: types_1.STRICT_REQUIRED_BOUNDARY,
34
+ description: 'Resolve diff context, parse tracked/staged diff, merge untracked files, apply exclusion filter.',
35
+ execute(input) {
36
+ return computeDiffNormalization(input);
37
+ },
38
+ fingerprintInput(input) {
39
+ return (0, fingerprint_1.fingerprintStageSignal)({
40
+ mode: input.mode,
41
+ baseRef: input.baseRef ?? null,
42
+ // projectRoot is intentionally excluded: identical diffs on different
43
+ // checkout paths must produce the same fingerprint.
44
+ });
45
+ },
46
+ fingerprintOutput(output) {
47
+ // Fingerprint is the set of analyzed file paths. Diff content fingerprinting
48
+ // belongs in a downstream content-hash stage; here we only commit to the shape.
49
+ return (0, fingerprint_1.fingerprintStageSignal)({
50
+ diffContextLabel: output.diffContextLabel,
51
+ files: output.diffFiles.map(f => ({
52
+ path: f.path,
53
+ oldPath: f.oldPath ?? null,
54
+ changeType: f.changeType,
55
+ addedLines: f.addedLines ?? 0,
56
+ removedLines: f.removedLines ?? 0,
57
+ })).sort((a, b) => (a.path < b.path ? -1 : 1)),
58
+ emptyDiff: output.emptyDiff,
59
+ });
60
+ },
61
+ inputItemCount(input) {
62
+ // Stable input "item count": untracked-diff resolver is the only enumerable.
63
+ return input.getUntrackedDiffFiles(input.projectRoot).length;
64
+ },
65
+ outputItemCount(output) {
66
+ return output.diffFiles.length;
67
+ },
68
+ };
69
+ /**
70
+ * Pure helper for direct invocation (used both by the stage and by tests).
71
+ * Mirrors the semantics of the verify.ts inline implementation.
72
+ */
73
+ function computeDiffNormalization(input) {
74
+ const { projectRoot, mode, baseRef, getUntrackedDiffFiles, isExcludedFile } = input;
75
+ let diffText;
76
+ let diffContextLabel = '';
77
+ if (mode === 'staged') {
78
+ diffText = (0, child_process_1.execSync)('git diff --cached', {
79
+ maxBuffer: GIT_DIFF_MAX_BUFFER,
80
+ encoding: 'utf-8',
81
+ });
82
+ diffContextLabel = 'staged changes';
83
+ }
84
+ else if (mode === 'base' && baseRef) {
85
+ diffText = (0, git_1.getDiffFromBase)(baseRef);
86
+ diffContextLabel = `working tree vs ${baseRef}`;
87
+ }
88
+ else if (mode === 'head') {
89
+ diffText = (0, child_process_1.execSync)('git diff HEAD', {
90
+ maxBuffer: GIT_DIFF_MAX_BUFFER,
91
+ encoding: 'utf-8',
92
+ });
93
+ diffContextLabel = 'working tree vs HEAD';
94
+ }
95
+ else {
96
+ // 'auto'
97
+ const defaultContext = (0, git_1.resolveDefaultDiffContext)(projectRoot);
98
+ if (defaultContext.mode === 'base' && defaultContext.baseRef) {
99
+ diffText = (0, git_1.getDiffFromBase)(defaultContext.baseRef);
100
+ diffContextLabel = defaultContext.currentBranch
101
+ ? `${defaultContext.currentBranch} vs ${defaultContext.baseRef}`
102
+ : `working tree vs ${defaultContext.baseRef}`;
103
+ }
104
+ else {
105
+ diffText = (0, child_process_1.execSync)('git diff --cached', {
106
+ maxBuffer: GIT_DIFF_MAX_BUFFER,
107
+ encoding: 'utf-8',
108
+ });
109
+ diffContextLabel = 'staged changes (fallback)';
110
+ }
111
+ }
112
+ const untrackedDiffFiles = getUntrackedDiffFiles(projectRoot);
113
+ const parsedDiffFiles = diffText.trim() ? (0, diff_parser_1.parseDiff)(diffText) : [];
114
+ const allDiffFiles = [...parsedDiffFiles];
115
+ if (untrackedDiffFiles.length > 0) {
116
+ const existing = new Set(allDiffFiles.map(f => f.path));
117
+ for (const file of untrackedDiffFiles) {
118
+ if (!existing.has(file.path)) {
119
+ allDiffFiles.push(file);
120
+ }
121
+ }
122
+ }
123
+ // Filter out internal/system files before analysis.
124
+ const diffFiles = allDiffFiles.filter(file => {
125
+ const excludePath = isExcludedFile(file.path);
126
+ const excludeOldPath = file.oldPath ? isExcludedFile(file.oldPath) : false;
127
+ return !excludePath && !excludeOldPath;
128
+ });
129
+ const emptyDiff = !diffText.trim() && untrackedDiffFiles.length === 0;
130
+ const excludedFileCount = allDiffFiles.length - diffFiles.length;
131
+ return {
132
+ diffText,
133
+ diffContextLabel,
134
+ allDiffFiles,
135
+ diffFiles,
136
+ emptyDiff,
137
+ excludedFileCount,
138
+ };
139
+ }
140
+ //# sourceMappingURL=diff-normalization-stage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff-normalization-stage.js","sourceRoot":"","sources":["../../../../src/governance/pipeline/stages/diff-normalization-stage.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAyGH,4DAuEC;AA9KD,iDAAyC;AACzC,0DAAoE;AAEpE,4CAAgF;AAChF,gDAAwD;AAExD,oCAAoD;AAEpD,MAAM,mBAAmB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAwC/C;;GAEG;AACU,QA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O,CAAC,WAAW,IAAI,CAAC,cAAc,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,CAAC;IACtE,MAAM,iBAAiB,GAAG,YAAY,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAEjE,OAAO;QACL,QAAQ;QACR,gBAAgB;QAChB,YAAY;QACZ,SAAS;QACT,SAAS;QACT,iBAAiB;KAClB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Governance Synthesis Stage
3
+ * --------------------------
4
+ * Wraps `attachCanonicalGovernance` — the single canonical pipeline entry point
5
+ * that converts heterogeneous raw violations into the deterministic
6
+ * `GovernanceVerificationEnvelope`. After attachment, each finding is stamped
7
+ * with its computation-graph stage of origin (inferred from `sourceSystem`).
8
+ *
9
+ * SEMANTIC PRESERVATION:
10
+ * - The envelope structure, finding IDs, replay checksum, and ordering
11
+ * produced by `attachCanonicalGovernance` are preserved BYTE-FOR-BYTE.
12
+ * - Lineage stamping writes ONLY into `provenanceMetadata.producedByStage`,
13
+ * which is excluded from the canonical finding identity and from the
14
+ * replay-checksum input. Verified in `canonical-invariants.ts`.
15
+ *
16
+ * This stage is therefore observability-additive: removing the stamp call
17
+ * restores byte-for-byte identical output.
18
+ */
19
+ import type { GovernanceFinding, GovernanceStageResult, GovernanceVerificationEnvelope } from '@neurcode-ai/contracts';
20
+ import { stampFindingLineage } from '../lineage';
21
+ import type { GovernancePipelineStage } from '../types';
22
+ export interface GovernanceSynthesisInput {
23
+ /** Verify payload with raw violations already attached (structuralViolations, policyViolations, intentIssues, ...). */
24
+ payload: Record<string, unknown>;
25
+ }
26
+ export interface GovernanceSynthesisOutput {
27
+ payload: Record<string, unknown>;
28
+ envelope: GovernanceVerificationEnvelope;
29
+ findings: GovernanceFinding[];
30
+ }
31
+ export declare const governanceSynthesisStage: GovernancePipelineStage<GovernanceSynthesisInput, GovernanceSynthesisOutput>;
32
+ /**
33
+ * Pure helper: synthesize the canonical governance envelope from a verify
34
+ * payload, then stamp computation-graph lineage onto every finding.
35
+ *
36
+ * Identical to `governanceSynthesisStage.execute({ payload })` but callable
37
+ * without a pipeline context. Use this from verify.ts code paths that emit
38
+ * canonical JSON directly (early-exit branches, etc.).
39
+ *
40
+ * Guarantee: this function preserves the byte identity of the canonical
41
+ * envelope produced by `attachCanonicalGovernance`. Lineage stamping only
42
+ * writes to `provenanceMetadata.producedByStage`, which is excluded from
43
+ * the finding identity and from `replayChecksum`.
44
+ */
45
+ export declare function synthesizeGovernance(payload: Record<string, unknown>, options?: {
46
+ pipelineLedger?: readonly GovernanceStageResult[];
47
+ }): GovernanceSynthesisOutput;
48
+ /**
49
+ * Re-export for callers that want to stamp lineage on findings they
50
+ * manufactured outside this stage.
51
+ */
52
+ export { stampFindingLineage };
53
+ //# sourceMappingURL=governance-synthesis-stage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"governance-synthesis-stage.d.ts","sourceRoot":"","sources":["../../../../src/governance/pipeline/stages/governance-synthesis-stage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EACV,iBAAiB,EAEjB,qBAAqB,EACrB,8BAA8B,EAC/B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAGxD,MAAM,WAAW,wBAAwB;IACvC,uHAAuH;IACvH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,QAAQ,EAAE,8BAA8B,CAAC;IACzC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AA8BD,eAAO,MAAM,wBAAwB,EAAE,uBAAuB,CAC5D,wBAAwB,EACxB,yBAAyB,CAqC1B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAA;CAAO,GAClE,yBAAyB,CA+B3B;AAED;;;GAGG;AACH,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ /**
3
+ * Governance Synthesis Stage
4
+ * --------------------------
5
+ * Wraps `attachCanonicalGovernance` — the single canonical pipeline entry point
6
+ * that converts heterogeneous raw violations into the deterministic
7
+ * `GovernanceVerificationEnvelope`. After attachment, each finding is stamped
8
+ * with its computation-graph stage of origin (inferred from `sourceSystem`).
9
+ *
10
+ * SEMANTIC PRESERVATION:
11
+ * - The envelope structure, finding IDs, replay checksum, and ordering
12
+ * produced by `attachCanonicalGovernance` are preserved BYTE-FOR-BYTE.
13
+ * - Lineage stamping writes ONLY into `provenanceMetadata.producedByStage`,
14
+ * which is excluded from the canonical finding identity and from the
15
+ * replay-checksum input. Verified in `canonical-invariants.ts`.
16
+ *
17
+ * This stage is therefore observability-additive: removing the stamp call
18
+ * restores byte-for-byte identical output.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.stampFindingLineage = exports.governanceSynthesisStage = void 0;
22
+ exports.synthesizeGovernance = synthesizeGovernance;
23
+ const canonical_pipeline_1 = require("../../canonical-pipeline");
24
+ const fingerprint_1 = require("../fingerprint");
25
+ const lineage_1 = require("../lineage");
26
+ Object.defineProperty(exports, "stampFindingLineage", { enumerable: true, get: function () { return lineage_1.stampFindingLineage; } });
27
+ const summary_1 = require("../summary");
28
+ const types_1 = require("../types");
29
+ /**
30
+ * Map a canonical sourceSystem to the stage in the pipeline that emitted it.
31
+ * Used for inferring lineage when stages did not stamp directly.
32
+ */
33
+ function inferStageFromSourceSystem(source) {
34
+ switch (source) {
35
+ case 'structural-rules':
36
+ return 'structural-analysis';
37
+ case 'policy-engine':
38
+ return 'policy-evaluation';
39
+ case 'intent-engine':
40
+ return 'intent-evaluation';
41
+ case 'governance-runtime':
42
+ return 'runtime-guard';
43
+ case 'replay-runtime':
44
+ return 'replay-integrity';
45
+ case 'semantic-index':
46
+ return 'semantic-analysis';
47
+ case 'ci-adapter':
48
+ return 'ci-shaping';
49
+ case 'pilot-metrics':
50
+ return 'telemetry-harvest';
51
+ case 'workspace-federation':
52
+ default:
53
+ return 'governance-synthesis';
54
+ }
55
+ }
56
+ exports.governanceSynthesisStage = {
57
+ id: 'governance-synthesis',
58
+ determinism: 'deterministic-structural',
59
+ boundary: {
60
+ ...types_1.STRICT_REQUIRED_BOUNDARY,
61
+ dependencies: ['structural-analysis'],
62
+ },
63
+ description: 'Build canonical GovernanceVerificationEnvelope from raw violations; stamp findings with computation-graph lineage.',
64
+ execute(input) {
65
+ return synthesizeGovernance(input.payload);
66
+ },
67
+ fingerprintInput(input) {
68
+ const p = input.payload;
69
+ return (0, fingerprint_1.fingerprintStageSignal)({
70
+ structuralCount: Array.isArray(p.structuralViolations) ? p.structuralViolations.length : 0,
71
+ policyCount: Array.isArray(p.violations) ? p.violations.length : 0,
72
+ intentCount: Array.isArray(p.intentIssues) ? p.intentIssues.length : 0,
73
+ flowCount: Array.isArray(p.flowIssues) ? p.flowIssues.length : 0,
74
+ regressionCount: Array.isArray(p.regressions) ? p.regressions.length : 0,
75
+ planId: typeof p.planId === 'string' ? p.planId : null,
76
+ });
77
+ },
78
+ fingerprintOutput(output) {
79
+ // Output fingerprint is the envelope's replay checksum (already deterministic
80
+ // and computed from canonical sorted findings). This keeps the stage's
81
+ // replay fingerprint and the envelope's checksum in lockstep.
82
+ return output.envelope.replayChecksum;
83
+ },
84
+ outputItemCount(output) {
85
+ return output.findings.length;
86
+ },
87
+ };
88
+ /**
89
+ * Pure helper: synthesize the canonical governance envelope from a verify
90
+ * payload, then stamp computation-graph lineage onto every finding.
91
+ *
92
+ * Identical to `governanceSynthesisStage.execute({ payload })` but callable
93
+ * without a pipeline context. Use this from verify.ts code paths that emit
94
+ * canonical JSON directly (early-exit branches, etc.).
95
+ *
96
+ * Guarantee: this function preserves the byte identity of the canonical
97
+ * envelope produced by `attachCanonicalGovernance`. Lineage stamping only
98
+ * writes to `provenanceMetadata.producedByStage`, which is excluded from
99
+ * the finding identity and from `replayChecksum`.
100
+ */
101
+ function synthesizeGovernance(payload, options = {}) {
102
+ const enriched = (0, canonical_pipeline_1.attachCanonicalGovernance)(payload);
103
+ const envelope = enriched.governanceVerification;
104
+ if (!envelope) {
105
+ throw new Error('governance-synthesis invariant violated: attachCanonicalGovernance did not attach an envelope');
106
+ }
107
+ for (const f of envelope.findings) {
108
+ const inferred = inferStageFromSourceSystem(f.sourceSystem);
109
+ if (!f.provenanceMetadata) {
110
+ f.provenanceMetadata = { producedByStage: inferred };
111
+ }
112
+ else if (!f.provenanceMetadata.producedByStage) {
113
+ f.provenanceMetadata.producedByStage = inferred;
114
+ }
115
+ }
116
+ // Optional: attach pipeline-summary observability to the envelope. This
117
+ // additive surface is excluded from finding identity and from replayChecksum
118
+ // by design (see canonical-finding.ts and canonical-invariants.ts), so it
119
+ // cannot perturb replay drift detection.
120
+ if (options.pipelineLedger && options.pipelineLedger.length > 0) {
121
+ envelope.pipelineSummary = (0, summary_1.buildPipelineSummary)(options.pipelineLedger);
122
+ }
123
+ return {
124
+ payload: enriched,
125
+ envelope,
126
+ findings: envelope.findings,
127
+ };
128
+ }
129
+ //# sourceMappingURL=governance-synthesis-stage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"governance-synthesis-stage.js","sourceRoot":"","sources":["../../../../src/governance/pipeline/stages/governance-synthesis-stage.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AA4GH,oDAkCC;AAtID,iEAAqE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AG,0BAA0B,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAC5D,IAAI,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC;YAC1B,CAAC,CAAC,kBAAkB,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC;QACvD,CAAC;aAAM,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,eAAe,EAAE,CAAC;YACjD,CAAC,CAAC,kBAAkB,CAAC,eAAe,GAAG,QAAQ,CAAC;QAClD,CAAC;IACH,CAAC;IAED,wEAAwE;IACxE,6EAA6E;IAC7E,0EAA0E;IAC1E,yCAAyC;IACzC,IAAI,OAAO,CAAC,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChE,QAAQ,CAAC,eAAe,GAAG,IAAA,8BAAoB,EAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO;QACL,OAAO,EAAE,QAAQ;QACjB,QAAQ;QACR,QAAQ,EAAE,QAAQ,CAAC,QAAQ;KAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Pipeline stage definitions — public re-exports.
3
+ *
4
+ * Each stage is a behavior-preserving wrapper around an existing verify.ts
5
+ * code region. The wrappers add stage lineage, deterministic fingerprinting,
6
+ * timing metrics, dependency declarations, and failure-isolation policy.
7
+ *
8
+ * STAGE-EXTRACTION STATUS (this phase):
9
+ * - diff-normalization ✓ wrapper + wired in verify.ts
10
+ * - policy-lock ✓ wrapper (wire-in deferred to next phase)
11
+ * - compiled-policy ✓ wrapper (wire-in deferred to next phase)
12
+ * - structural-analysis ✓ wrapper (wire-in deferred to next phase)
13
+ * - runtime-guard ✓ wrapper (wire-in deferred to next phase)
14
+ * - governance-synthesis ✓ wrapper + wired in verify.ts
15
+ *
16
+ * REMAINING STAGES (designed but not yet implemented):
17
+ * plan-sync, policy-exceptions, intent-evaluation, semantic-analysis,
18
+ * policy-evaluation, suppression-evaluation, advisory-signals,
19
+ * change-contract, ai-debt-budget, provenance-generation,
20
+ * replay-integrity, remediation-export-preparation, evidence-generation,
21
+ * telemetry-harvest, ci-shaping, output-rendering.
22
+ */
23
+ export { compiledPolicyStage, type CompiledPolicyInput, type CompiledPolicyOutput, } from './compiled-policy-stage';
24
+ export { diffNormalizationStage, computeDiffNormalization, type DiffMode, type DiffNormalizationInput, type DiffNormalizationOutput, } from './diff-normalization-stage';
25
+ export { governanceSynthesisStage, synthesizeGovernance, type GovernanceSynthesisInput, type GovernanceSynthesisOutput, } from './governance-synthesis-stage';
26
+ export { policyLockStage, type PolicyLockInput, type PolicyLockOutput, } from './policy-lock-stage';
27
+ export { runtimeGuardStage, type RuntimeGuardInput, type RuntimeGuardOutput, } from './runtime-guard-stage';
28
+ export { structuralAnalysisStage, type StructuralAnalysisInput, type StructuralAnalysisOutput, } from './structural-analysis-stage';
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/governance/pipeline/stages/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uBAAuB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,GAC9B,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * Pipeline stage definitions — public re-exports.
4
+ *
5
+ * Each stage is a behavior-preserving wrapper around an existing verify.ts
6
+ * code region. The wrappers add stage lineage, deterministic fingerprinting,
7
+ * timing metrics, dependency declarations, and failure-isolation policy.
8
+ *
9
+ * STAGE-EXTRACTION STATUS (this phase):
10
+ * - diff-normalization ✓ wrapper + wired in verify.ts
11
+ * - policy-lock ✓ wrapper (wire-in deferred to next phase)
12
+ * - compiled-policy ✓ wrapper (wire-in deferred to next phase)
13
+ * - structural-analysis ✓ wrapper (wire-in deferred to next phase)
14
+ * - runtime-guard ✓ wrapper (wire-in deferred to next phase)
15
+ * - governance-synthesis ✓ wrapper + wired in verify.ts
16
+ *
17
+ * REMAINING STAGES (designed but not yet implemented):
18
+ * plan-sync, policy-exceptions, intent-evaluation, semantic-analysis,
19
+ * policy-evaluation, suppression-evaluation, advisory-signals,
20
+ * change-contract, ai-debt-budget, provenance-generation,
21
+ * replay-integrity, remediation-export-preparation, evidence-generation,
22
+ * telemetry-harvest, ci-shaping, output-rendering.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.structuralAnalysisStage = exports.runtimeGuardStage = exports.policyLockStage = exports.synthesizeGovernance = exports.governanceSynthesisStage = exports.computeDiffNormalization = exports.diffNormalizationStage = exports.compiledPolicyStage = void 0;
26
+ var compiled_policy_stage_1 = require("./compiled-policy-stage");
27
+ Object.defineProperty(exports, "compiledPolicyStage", { enumerable: true, get: function () { return compiled_policy_stage_1.compiledPolicyStage; } });
28
+ var diff_normalization_stage_1 = require("./diff-normalization-stage");
29
+ Object.defineProperty(exports, "diffNormalizationStage", { enumerable: true, get: function () { return diff_normalization_stage_1.diffNormalizationStage; } });
30
+ Object.defineProperty(exports, "computeDiffNormalization", { enumerable: true, get: function () { return diff_normalization_stage_1.computeDiffNormalization; } });
31
+ var governance_synthesis_stage_1 = require("./governance-synthesis-stage");
32
+ Object.defineProperty(exports, "governanceSynthesisStage", { enumerable: true, get: function () { return governance_synthesis_stage_1.governanceSynthesisStage; } });
33
+ Object.defineProperty(exports, "synthesizeGovernance", { enumerable: true, get: function () { return governance_synthesis_stage_1.synthesizeGovernance; } });
34
+ var policy_lock_stage_1 = require("./policy-lock-stage");
35
+ Object.defineProperty(exports, "policyLockStage", { enumerable: true, get: function () { return policy_lock_stage_1.policyLockStage; } });
36
+ var runtime_guard_stage_1 = require("./runtime-guard-stage");
37
+ Object.defineProperty(exports, "runtimeGuardStage", { enumerable: true, get: function () { return runtime_guard_stage_1.runtimeGuardStage; } });
38
+ var structural_analysis_stage_1 = require("./structural-analysis-stage");
39
+ Object.defineProperty(exports, "structuralAnalysisStage", { enumerable: true, get: function () { return structural_analysis_stage_1.structuralAnalysisStage; } });
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/governance/pipeline/stages/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,iEAIiC;AAH/B,4HAAA,mBAAmB,OAAA;AAIrB,uEAMoC;AALlC,kIAAA,sBAAsB,OAAA;AACtB,oIAAA,wBAAwB,OAAA;AAK1B,2EAKsC;AAJpC,sIAAA,wBAAwB,OAAA;AACxB,kIAAA,oBAAoB,OAAA;AAItB,yDAI6B;AAH3B,oHAAA,eAAe,OAAA;AAIjB,6DAI+B;AAH7B,wHAAA,iBAAiB,OAAA;AAInB,yEAIqC;AAHnC,oIAAA,uBAAuB,OAAA"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Policy Lock Stage
3
+ * -----------------
4
+ * Verifies the policy lock fingerprint against the currently-resolved policy
5
+ * snapshot. This is a thin wrapper around `evaluatePolicyLock` from
6
+ * `utils/policy-packs` — it preserves all existing semantics and only adds
7
+ * stage lineage, fingerprinting, and replay receipts.
8
+ *
9
+ * SEMANTIC PRESERVATION:
10
+ * The output `enforced`, `matched`, `lockPresent`, `lockPath`, and
11
+ * `mismatches[]` fields are produced by `evaluatePolicyLock` directly —
12
+ * they MUST be identical to the values verify.ts records inline.
13
+ */
14
+ import { type PolicyLockMismatch, type PolicyStateSnapshot } from '../../../utils/policy-packs';
15
+ import type { GovernancePipelineStage } from '../types';
16
+ export interface PolicyLockInput {
17
+ projectRoot: string;
18
+ currentSnapshot: PolicyStateSnapshot;
19
+ requireLock: boolean;
20
+ skipLock: boolean;
21
+ }
22
+ export interface PolicyLockOutput {
23
+ enforced: boolean;
24
+ matched: boolean;
25
+ lockPresent: boolean;
26
+ lockPath: string;
27
+ mismatches: PolicyLockMismatch[];
28
+ skipped: boolean;
29
+ }
30
+ export declare const policyLockStage: GovernancePipelineStage<PolicyLockInput, PolicyLockOutput>;
31
+ //# sourceMappingURL=policy-lock-stage.d.ts.map