@neurcode-ai/cli 0.9.65 → 0.9.66

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 (99) hide show
  1. package/dist/commands/bootstrap-policy.d.ts +29 -0
  2. package/dist/commands/bootstrap-policy.d.ts.map +1 -0
  3. package/dist/commands/bootstrap-policy.js +334 -0
  4. package/dist/commands/bootstrap-policy.js.map +1 -0
  5. package/dist/commands/doctor.d.ts.map +1 -1
  6. package/dist/commands/doctor.js +82 -0
  7. package/dist/commands/doctor.js.map +1 -1
  8. package/dist/commands/quickstart.d.ts +21 -0
  9. package/dist/commands/quickstart.d.ts.map +1 -0
  10. package/dist/commands/quickstart.js +178 -0
  11. package/dist/commands/quickstart.js.map +1 -0
  12. package/dist/commands/remediate-export.d.ts +31 -0
  13. package/dist/commands/remediate-export.d.ts.map +1 -0
  14. package/dist/commands/remediate-export.js +283 -0
  15. package/dist/commands/remediate-export.js.map +1 -0
  16. package/dist/commands/verify.d.ts.map +1 -1
  17. package/dist/commands/verify.js +106 -10
  18. package/dist/commands/verify.js.map +1 -1
  19. package/dist/governance/canonical-invariants.d.ts +88 -0
  20. package/dist/governance/canonical-invariants.d.ts.map +1 -0
  21. package/dist/governance/canonical-invariants.js +197 -0
  22. package/dist/governance/canonical-invariants.js.map +1 -0
  23. package/dist/governance/canonical-ordering.d.ts +76 -0
  24. package/dist/governance/canonical-ordering.d.ts.map +1 -0
  25. package/dist/governance/canonical-ordering.js +189 -0
  26. package/dist/governance/canonical-ordering.js.map +1 -0
  27. package/dist/governance/canonical-pipeline.d.ts +7 -0
  28. package/dist/governance/canonical-pipeline.d.ts.map +1 -1
  29. package/dist/governance/canonical-pipeline.js +184 -16
  30. package/dist/governance/canonical-pipeline.js.map +1 -1
  31. package/dist/governance/diff-line-provenance.d.ts +59 -0
  32. package/dist/governance/diff-line-provenance.d.ts.map +1 -0
  33. package/dist/governance/diff-line-provenance.js +118 -0
  34. package/dist/governance/diff-line-provenance.js.map +1 -0
  35. package/dist/governance/pilot-readiness.d.ts +34 -0
  36. package/dist/governance/pilot-readiness.d.ts.map +1 -0
  37. package/dist/governance/pilot-readiness.js +226 -0
  38. package/dist/governance/pilot-readiness.js.map +1 -0
  39. package/dist/governance/policy-parity-validator.d.ts +62 -0
  40. package/dist/governance/policy-parity-validator.d.ts.map +1 -0
  41. package/dist/governance/policy-parity-validator.js +137 -0
  42. package/dist/governance/policy-parity-validator.js.map +1 -0
  43. package/dist/governance/remediation-boundary.d.ts +55 -0
  44. package/dist/governance/remediation-boundary.d.ts.map +1 -0
  45. package/dist/governance/remediation-boundary.js +120 -0
  46. package/dist/governance/remediation-boundary.js.map +1 -0
  47. package/dist/governance/structural-cache.d.ts +103 -0
  48. package/dist/governance/structural-cache.d.ts.map +1 -0
  49. package/dist/governance/structural-cache.js +240 -0
  50. package/dist/governance/structural-cache.js.map +1 -0
  51. package/dist/governance/structural-on-diff.d.ts +22 -2
  52. package/dist/governance/structural-on-diff.d.ts.map +1 -1
  53. package/dist/governance/structural-on-diff.js +36 -4
  54. package/dist/governance/structural-on-diff.js.map +1 -1
  55. package/dist/governance/structural-policy-merge.d.ts +8 -0
  56. package/dist/governance/structural-policy-merge.d.ts.map +1 -1
  57. package/dist/governance/structural-policy-merge.js +7 -0
  58. package/dist/governance/structural-policy-merge.js.map +1 -1
  59. package/dist/governance/verify-runtime-guard.d.ts +99 -0
  60. package/dist/governance/verify-runtime-guard.d.ts.map +1 -0
  61. package/dist/governance/verify-runtime-guard.js +129 -0
  62. package/dist/governance/verify-runtime-guard.js.map +1 -0
  63. package/dist/index.js +50 -14
  64. package/dist/index.js.map +1 -1
  65. package/dist/intent-engine/repo-classifier.d.ts +64 -0
  66. package/dist/intent-engine/repo-classifier.d.ts.map +1 -0
  67. package/dist/intent-engine/repo-classifier.js +178 -0
  68. package/dist/intent-engine/repo-classifier.js.map +1 -0
  69. package/dist/structural-rules/index.d.ts +4 -0
  70. package/dist/structural-rules/index.d.ts.map +1 -1
  71. package/dist/structural-rules/index.js +18 -1
  72. package/dist/structural-rules/index.js.map +1 -1
  73. package/dist/structural-rules/python/PY003-broad-except-clause.d.ts +21 -0
  74. package/dist/structural-rules/python/PY003-broad-except-clause.d.ts.map +1 -1
  75. package/dist/structural-rules/python/PY003-broad-except-clause.js +212 -21
  76. package/dist/structural-rules/python/PY003-broad-except-clause.js.map +1 -1
  77. package/dist/structural-rules/python/PY011-thread-lifecycle.d.ts +11 -0
  78. package/dist/structural-rules/python/PY011-thread-lifecycle.d.ts.map +1 -0
  79. package/dist/structural-rules/python/PY011-thread-lifecycle.js +97 -0
  80. package/dist/structural-rules/python/PY011-thread-lifecycle.js.map +1 -0
  81. package/dist/structural-rules/python/PY012-asyncio-run-misuse.d.ts +11 -0
  82. package/dist/structural-rules/python/PY012-asyncio-run-misuse.d.ts.map +1 -0
  83. package/dist/structural-rules/python/PY012-asyncio-run-misuse.js +83 -0
  84. package/dist/structural-rules/python/PY012-asyncio-run-misuse.js.map +1 -0
  85. package/dist/structural-rules/python/PY013-mutable-default-arg.d.ts +11 -0
  86. package/dist/structural-rules/python/PY013-mutable-default-arg.d.ts.map +1 -0
  87. package/dist/structural-rules/python/PY013-mutable-default-arg.js +73 -0
  88. package/dist/structural-rules/python/PY013-mutable-default-arg.js.map +1 -0
  89. package/dist/structural-rules/python/PY014-fixed-sleep-retry.d.ts +11 -0
  90. package/dist/structural-rules/python/PY014-fixed-sleep-retry.d.ts.map +1 -0
  91. package/dist/structural-rules/python/PY014-fixed-sleep-retry.js +115 -0
  92. package/dist/structural-rules/python/PY014-fixed-sleep-retry.js.map +1 -0
  93. package/dist/structural-rules/types.d.ts +12 -0
  94. package/dist/structural-rules/types.d.ts.map +1 -1
  95. package/dist/utils/verify-runtime-stability.d.ts +142 -0
  96. package/dist/utils/verify-runtime-stability.d.ts.map +1 -0
  97. package/dist/utils/verify-runtime-stability.js +230 -0
  98. package/dist/utils/verify-runtime-stability.js.map +1 -0
  99. package/package.json +1 -1
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Canonical Finding Invariants (Phase 1 + Phase 3)
3
+ *
4
+ * Two responsibilities:
5
+ *
6
+ * 1. Architectural invariant enforcement (Phase 1):
7
+ * - Assert that policyViolations never contain structural:* rows
8
+ * - If violated, emit a deterministic console warning (never throw)
9
+ * - This guards against regressions where future code re-introduces the merge
10
+ *
11
+ * 2. Replay determinism (Phase 3):
12
+ * - computeCanonicalFindingChecksum(): deterministic SHA-256 over finding set
13
+ * - sortFindingsDeterministically(): canonical sort order for stable checksums
14
+ *
15
+ * Both functions are pure and dependency-free (only Node 'crypto').
16
+ */
17
+ import type { GovernanceFinding } from '@neurcode-ai/contracts';
18
+ import type { RuleViolation } from '@neurcode-ai/policy-engine';
19
+ /**
20
+ * Assert that the policyViolations array contains no structural:* prefixed rows.
21
+ *
22
+ * Structural violations MUST flow only through `payload.structuralViolations`
23
+ * into the canonical pipeline. Structural rows in policyViolations cause
24
+ * cross-source duplicate GovernanceFinding objects.
25
+ *
26
+ * This guard emits a console.warn if violated — it NEVER throws. The intention
27
+ * is observability and regression detection, not hard failure. The pipeline's
28
+ * stripStructuralPolicyRows() provides the actual cleanup.
29
+ *
30
+ * @param violations The policyViolations array before it reaches the pipeline
31
+ * @param context Caller label for the warning message (e.g. 'verify:policy-only')
32
+ * @returns Count of structural rows found (0 = invariant holds)
33
+ */
34
+ export declare function assertNoStructuralPolicyRows(violations: RuleViolation[], context: string): number;
35
+ /**
36
+ * Sort findings into a canonical deterministic order.
37
+ *
38
+ * Sort key (descending priority):
39
+ * 1. determinismClassification rank (descending — structural first)
40
+ * 2. severity rank (descending — BLOCKING first)
41
+ * 3. filePath (ascending — lexicographic)
42
+ * 4. line number (ascending)
43
+ * 5. id (ascending — stable tiebreaker)
44
+ *
45
+ * This order is stable across multiple runs on the same input, enabling
46
+ * reliable replay checksum comparison.
47
+ *
48
+ * NEVER mutates the input array — returns a new sorted array.
49
+ */
50
+ export declare function sortFindingsDeterministically(findings: GovernanceFinding[]): GovernanceFinding[];
51
+ /**
52
+ * Compute a deterministic SHA-256 checksum over the canonical finding set.
53
+ *
54
+ * Checksum input is built from sorted findings:
55
+ * for each finding (in canonical sort order):
56
+ * id + '\x1e' + severity + '\x1e' + determinismClassification +
57
+ * '\x1e' + filePath + '\x1e' + line
58
+ * joined with '\x00'
59
+ *
60
+ * This checksum:
61
+ * - Changes if any finding is added, removed, or has severity/determinism changed
62
+ * - Changes if canonical ordering changes (sort key must be stable)
63
+ * - Is stable across process restarts on the same input
64
+ * - Is used to detect replay drift (same commit + diff + rules → same checksum)
65
+ *
66
+ * @param findings Raw findings from the canonical pipeline (NOT pre-sorted)
67
+ * @returns hex SHA-256 string (64 chars)
68
+ */
69
+ export declare function computeCanonicalFindingChecksum(findings: GovernanceFinding[]): string;
70
+ /**
71
+ * Compare two sets of findings for replay equivalence.
72
+ *
73
+ * Returns a structured comparison result:
74
+ * - 'exact': checksums match — identical governance output
75
+ * - 'drift-detected': checksums differ — replay divergence
76
+ *
77
+ * @param baseline Findings from the baseline (e.g. cached) run
78
+ * @param replay Findings from the current run
79
+ */
80
+ export declare function compareForReplayEquivalence(baseline: GovernanceFinding[], replay: GovernanceFinding[]): {
81
+ status: 'exact' | 'drift-detected';
82
+ baselineChecksum: string;
83
+ replayChecksum: string;
84
+ baselineCount: number;
85
+ replayCount: number;
86
+ driftDetails?: string;
87
+ };
88
+ //# sourceMappingURL=canonical-invariants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-invariants.d.ts","sourceRoot":"","sources":["../../src/governance/canonical-invariants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAIhE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,aAAa,EAAE,EAC3B,OAAO,EAAE,MAAM,GACd,MAAM,CAYR;AA4BD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,iBAAiB,EAAE,CAyBhG;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAgBrF;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,MAAM,EAAE,iBAAiB,EAAE,GAC1B;IACD,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAAC;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CA2CA"}
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /**
3
+ * Canonical Finding Invariants (Phase 1 + Phase 3)
4
+ *
5
+ * Two responsibilities:
6
+ *
7
+ * 1. Architectural invariant enforcement (Phase 1):
8
+ * - Assert that policyViolations never contain structural:* rows
9
+ * - If violated, emit a deterministic console warning (never throw)
10
+ * - This guards against regressions where future code re-introduces the merge
11
+ *
12
+ * 2. Replay determinism (Phase 3):
13
+ * - computeCanonicalFindingChecksum(): deterministic SHA-256 over finding set
14
+ * - sortFindingsDeterministically(): canonical sort order for stable checksums
15
+ *
16
+ * Both functions are pure and dependency-free (only Node 'crypto').
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.assertNoStructuralPolicyRows = assertNoStructuralPolicyRows;
20
+ exports.sortFindingsDeterministically = sortFindingsDeterministically;
21
+ exports.computeCanonicalFindingChecksum = computeCanonicalFindingChecksum;
22
+ exports.compareForReplayEquivalence = compareForReplayEquivalence;
23
+ const crypto_1 = require("crypto");
24
+ // ── Phase 1: Architectural invariant guard ────────────────────────────────────
25
+ /**
26
+ * Assert that the policyViolations array contains no structural:* prefixed rows.
27
+ *
28
+ * Structural violations MUST flow only through `payload.structuralViolations`
29
+ * into the canonical pipeline. Structural rows in policyViolations cause
30
+ * cross-source duplicate GovernanceFinding objects.
31
+ *
32
+ * This guard emits a console.warn if violated — it NEVER throws. The intention
33
+ * is observability and regression detection, not hard failure. The pipeline's
34
+ * stripStructuralPolicyRows() provides the actual cleanup.
35
+ *
36
+ * @param violations The policyViolations array before it reaches the pipeline
37
+ * @param context Caller label for the warning message (e.g. 'verify:policy-only')
38
+ * @returns Count of structural rows found (0 = invariant holds)
39
+ */
40
+ function assertNoStructuralPolicyRows(violations, context) {
41
+ const leaked = violations.filter(v => String(v.rule ?? '').startsWith('structural:'));
42
+ if (leaked.length > 0) {
43
+ console.warn(`[neurcode/canonical-invariant] VIOLATION in ${context}: ` +
44
+ `${leaked.length} structural:* row(s) found in policyViolations. ` +
45
+ `These should flow exclusively through payload.structuralViolations. ` +
46
+ `Rows: ${leaked.map(v => v.rule).join(', ')}. ` +
47
+ `The canonical pipeline will strip them, but this represents a source-level duplication bug.`);
48
+ }
49
+ return leaked.length;
50
+ }
51
+ // ── Phase 3: Replay determinism ───────────────────────────────────────────────
52
+ /**
53
+ * Determinism rank for sorting (higher = more deterministic = sorted first).
54
+ * Identical to rankDeterminism in canonical-pipeline.ts — kept separate to
55
+ * avoid circular import.
56
+ */
57
+ function rankDeterminism(d) {
58
+ switch (d) {
59
+ case 'deterministic-structural': return 4;
60
+ case 'deterministic-semantic': return 3;
61
+ case 'heuristic-advisory': return 2;
62
+ case 'llm-assisted-planning': return 1;
63
+ default: return 0;
64
+ }
65
+ }
66
+ function rankSeverity(s) {
67
+ switch (s) {
68
+ case 'BLOCKING': return 3;
69
+ case 'ADVISORY': return 2;
70
+ case 'INFO': return 1;
71
+ default: return 0;
72
+ }
73
+ }
74
+ /**
75
+ * Sort findings into a canonical deterministic order.
76
+ *
77
+ * Sort key (descending priority):
78
+ * 1. determinismClassification rank (descending — structural first)
79
+ * 2. severity rank (descending — BLOCKING first)
80
+ * 3. filePath (ascending — lexicographic)
81
+ * 4. line number (ascending)
82
+ * 5. id (ascending — stable tiebreaker)
83
+ *
84
+ * This order is stable across multiple runs on the same input, enabling
85
+ * reliable replay checksum comparison.
86
+ *
87
+ * NEVER mutates the input array — returns a new sorted array.
88
+ */
89
+ function sortFindingsDeterministically(findings) {
90
+ return [...findings].sort((a, b) => {
91
+ // 1. Determinism rank descending
92
+ const dA = rankDeterminism(a.determinismClassification);
93
+ const dB = rankDeterminism(b.determinismClassification);
94
+ if (dA !== dB)
95
+ return dB - dA;
96
+ // 2. Severity descending
97
+ const sA = rankSeverity(a.severity);
98
+ const sB = rankSeverity(b.severity);
99
+ if (sA !== sB)
100
+ return sB - sA;
101
+ // 3. File path ascending
102
+ const fA = a.evidence?.filePath ?? '';
103
+ const fB = b.evidence?.filePath ?? '';
104
+ if (fA !== fB)
105
+ return fA < fB ? -1 : 1;
106
+ // 4. Line number ascending
107
+ const lA = a.evidence?.line ?? 0;
108
+ const lB = b.evidence?.line ?? 0;
109
+ if (lA !== lB)
110
+ return lA - lB;
111
+ // 5. ID ascending (stable tiebreaker)
112
+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
113
+ });
114
+ }
115
+ /**
116
+ * Compute a deterministic SHA-256 checksum over the canonical finding set.
117
+ *
118
+ * Checksum input is built from sorted findings:
119
+ * for each finding (in canonical sort order):
120
+ * id + '\x1e' + severity + '\x1e' + determinismClassification +
121
+ * '\x1e' + filePath + '\x1e' + line
122
+ * joined with '\x00'
123
+ *
124
+ * This checksum:
125
+ * - Changes if any finding is added, removed, or has severity/determinism changed
126
+ * - Changes if canonical ordering changes (sort key must be stable)
127
+ * - Is stable across process restarts on the same input
128
+ * - Is used to detect replay drift (same commit + diff + rules → same checksum)
129
+ *
130
+ * @param findings Raw findings from the canonical pipeline (NOT pre-sorted)
131
+ * @returns hex SHA-256 string (64 chars)
132
+ */
133
+ function computeCanonicalFindingChecksum(findings) {
134
+ const sorted = sortFindingsDeterministically(findings);
135
+ const input = sorted
136
+ .map(f => [
137
+ f.id,
138
+ f.severity,
139
+ f.determinismClassification,
140
+ f.evidence?.filePath ?? '',
141
+ String(f.evidence?.line ?? 0),
142
+ ].join('\x1e'))
143
+ .join('\x00');
144
+ return (0, crypto_1.createHash)('sha256').update(input, 'utf-8').digest('hex');
145
+ }
146
+ /**
147
+ * Compare two sets of findings for replay equivalence.
148
+ *
149
+ * Returns a structured comparison result:
150
+ * - 'exact': checksums match — identical governance output
151
+ * - 'drift-detected': checksums differ — replay divergence
152
+ *
153
+ * @param baseline Findings from the baseline (e.g. cached) run
154
+ * @param replay Findings from the current run
155
+ */
156
+ function compareForReplayEquivalence(baseline, replay) {
157
+ const baselineChecksum = computeCanonicalFindingChecksum(baseline);
158
+ const replayChecksum = computeCanonicalFindingChecksum(replay);
159
+ if (baselineChecksum === replayChecksum) {
160
+ return {
161
+ status: 'exact',
162
+ baselineChecksum,
163
+ replayChecksum,
164
+ baselineCount: baseline.length,
165
+ replayCount: replay.length,
166
+ };
167
+ }
168
+ // Drift detected — build detailed explanation
169
+ const baselineIds = new Set(baseline.map(f => f.id));
170
+ const replayIds = new Set(replay.map(f => f.id));
171
+ const added = replay.filter(f => !baselineIds.has(f.id)).map(f => f.id);
172
+ const removed = baseline.filter(f => !replayIds.has(f.id)).map(f => f.id);
173
+ // Findings present in both but with changed severity or determinism
174
+ const changed = [];
175
+ for (const bf of baseline) {
176
+ const rf = replay.find(f => f.id === bf.id);
177
+ if (rf && (rf.severity !== bf.severity || rf.determinismClassification !== bf.determinismClassification)) {
178
+ changed.push(`${bf.id}(sev:${bf.severity}→${rf.severity},det:${bf.determinismClassification}→${rf.determinismClassification})`);
179
+ }
180
+ }
181
+ const parts = [];
182
+ if (added.length > 0)
183
+ parts.push(`added=${added.length}[${added.slice(0, 3).join(',')}${added.length > 3 ? '...' : ''}]`);
184
+ if (removed.length > 0)
185
+ parts.push(`removed=${removed.length}[${removed.slice(0, 3).join(',')}${removed.length > 3 ? '...' : ''}]`);
186
+ if (changed.length > 0)
187
+ parts.push(`changed=${changed.length}[${changed.slice(0, 3).join(',')}${changed.length > 3 ? '...' : ''}]`);
188
+ return {
189
+ status: 'drift-detected',
190
+ baselineChecksum,
191
+ replayChecksum,
192
+ baselineCount: baseline.length,
193
+ replayCount: replay.length,
194
+ driftDetails: parts.join('; ') || 'checksum mismatch (unknown cause)',
195
+ };
196
+ }
197
+ //# sourceMappingURL=canonical-invariants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-invariants.js","sourceRoot":"","sources":["../../src/governance/canonical-invariants.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAuBH,oEAeC;AA2CD,sEAyBC;AAoBD,0EAgBC;AAYD,kEAqDC;AA7MD,mCAAoC;AAIpC,iFAAiF;AAEjF;;;;;;;;;;;;;;GAcG;AACH,SAAgB,4BAA4B,CAC1C,UAA2B,EAC3B,OAAe;IAEf,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;IACtF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CACV,+CAA+C,OAAO,IAAI;YAC1D,GAAG,MAAM,CAAC,MAAM,kDAAkD;YAClE,sEAAsE;YACtE,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC/C,6FAA6F,CAC9F,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AAED,iFAAiF;AAEjF;;;;GAIG;AACH,SAAS,eAAe,CAAC,CA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AC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAEpI,OAAO;QACL,MAAM,EAAE,gBAAgB;QACxB,gBAAgB;QAChB,cAAc;QACd,aAAa,EAAE,QAAQ,CAAC,MAAM;QAC9B,WAAW,EAAE,MAAM,CAAC,MAAM;QAC1B,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,mCAAmC;KACtE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Canonical Deterministic Ordering (Phase 1 — Canonical Deterministic Ordering)
3
+ *
4
+ * Single source of truth for finding sort order across:
5
+ * - replayChecksum generation
6
+ * - provenance serialization
7
+ * - governance envelope emission
8
+ * - telemetry harvesting
9
+ *
10
+ * INVARIANT:
11
+ * Any two invocations on the same logical finding set MUST produce
12
+ * the same ordered array, regardless of:
13
+ * - filesystem traversal order
14
+ * - async execution timing
15
+ * - insertion order
16
+ * - Map iteration order
17
+ * - Object.keys() order
18
+ *
19
+ * Canonical sort key (evaluated in priority order):
20
+ * 1. severity (BLOCKING > ADVISORY > INFO > unknown)
21
+ * 2. determinismClassification (deterministic-structural > deterministic-semantic
22
+ * > heuristic-advisory > llm-assisted-planning > unknown)
23
+ * 3. ruleId (ascending lexicographic)
24
+ * 4. filePath (ascending lexicographic, normalized to forward slashes)
25
+ * 5. line (ascending numeric, missing = 0)
26
+ * 6. column (ascending numeric, missing = 0)
27
+ * 7. findingId (ascending lexicographic — stable tiebreaker, always unique)
28
+ *
29
+ * These rules ensure a total order: no two distinct findings can be equal on
30
+ * all 7 keys simultaneously (findingId is always unique by construction).
31
+ */
32
+ import type { GovernanceFinding } from '@neurcode-ai/contracts';
33
+ /**
34
+ * Compute the canonical ordering key for a single finding.
35
+ *
36
+ * Returns a tuple whose elements, compared left-to-right, produce the
37
+ * canonical ordering defined above. Useful for inspection and testing.
38
+ *
39
+ * Format: [severityRank, determinismRank, ruleId, filePath, line, column, id]
40
+ */
41
+ export declare function canonicalFindingOrderingKey(f: GovernanceFinding): readonly [
42
+ number,
43
+ number,
44
+ string,
45
+ string,
46
+ number,
47
+ number,
48
+ string
49
+ ];
50
+ /**
51
+ * Sort findings into the canonical deterministic order.
52
+ *
53
+ * Properties:
54
+ * - Pure function — NEVER mutates the input array
55
+ * - Stable across process restarts for identical inputs
56
+ * - Independent of insertion order, Map iteration, filesystem traversal
57
+ * - Total order — no two distinct findings can compare as equal
58
+ *
59
+ * @param findings Any array of GovernanceFinding (may be in any order)
60
+ * @returns New sorted array (input is not mutated)
61
+ */
62
+ export declare function sortCanonicalFindingsStable(findings: GovernanceFinding[]): GovernanceFinding[];
63
+ /**
64
+ * Validate that a finding array is already in canonical order.
65
+ *
66
+ * Returns the index of the first out-of-order finding pair, or -1 if
67
+ * the array is already sorted. Used for invariant checking.
68
+ *
69
+ * Emits a console.warn if ordering drift is detected.
70
+ *
71
+ * @param findings Array to validate (not mutated)
72
+ * @param context Caller label for the warning (e.g. 'envelope-emit')
73
+ * @returns Index of first violation, or -1 if canonical
74
+ */
75
+ export declare function validateCanonicalOrder(findings: GovernanceFinding[], context: string): number;
76
+ //# sourceMappingURL=canonical-ordering.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-ordering.d.ts","sourceRoot":"","sources":["../../src/governance/canonical-ordering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAsChE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,iBAAiB,GAAG,SAAS;IAC1E,MAAM;IAAE,MAAM;IAAE,MAAM;IAAE,MAAM;IAAE,MAAM;IAAE,MAAM;IAAE,MAAM;CACvD,CAUA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,iBAAiB,EAAE,CAmC9F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,OAAO,EAAE,MAAM,GACd,MAAM,CA2CR"}
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ /**
3
+ * Canonical Deterministic Ordering (Phase 1 — Canonical Deterministic Ordering)
4
+ *
5
+ * Single source of truth for finding sort order across:
6
+ * - replayChecksum generation
7
+ * - provenance serialization
8
+ * - governance envelope emission
9
+ * - telemetry harvesting
10
+ *
11
+ * INVARIANT:
12
+ * Any two invocations on the same logical finding set MUST produce
13
+ * the same ordered array, regardless of:
14
+ * - filesystem traversal order
15
+ * - async execution timing
16
+ * - insertion order
17
+ * - Map iteration order
18
+ * - Object.keys() order
19
+ *
20
+ * Canonical sort key (evaluated in priority order):
21
+ * 1. severity (BLOCKING > ADVISORY > INFO > unknown)
22
+ * 2. determinismClassification (deterministic-structural > deterministic-semantic
23
+ * > heuristic-advisory > llm-assisted-planning > unknown)
24
+ * 3. ruleId (ascending lexicographic)
25
+ * 4. filePath (ascending lexicographic, normalized to forward slashes)
26
+ * 5. line (ascending numeric, missing = 0)
27
+ * 6. column (ascending numeric, missing = 0)
28
+ * 7. findingId (ascending lexicographic — stable tiebreaker, always unique)
29
+ *
30
+ * These rules ensure a total order: no two distinct findings can be equal on
31
+ * all 7 keys simultaneously (findingId is always unique by construction).
32
+ */
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.canonicalFindingOrderingKey = canonicalFindingOrderingKey;
35
+ exports.sortCanonicalFindingsStable = sortCanonicalFindingsStable;
36
+ exports.validateCanonicalOrder = validateCanonicalOrder;
37
+ // ── Rank tables ───────────────────────────────────────────────────────────────
38
+ /**
39
+ * Severity rank — higher number = sorted first (BLOCKING first).
40
+ * Deterministic: closed set, no dynamic lookup.
41
+ */
42
+ function rankSeverity(s) {
43
+ switch (s) {
44
+ case 'BLOCKING': return 3;
45
+ case 'ADVISORY': return 2;
46
+ case 'INFO': return 1;
47
+ default: return 0;
48
+ }
49
+ }
50
+ /**
51
+ * Determinism classification rank — higher = sorted first (structural first).
52
+ * Deterministic: closed set, no dynamic lookup.
53
+ */
54
+ function rankDeterminism(d) {
55
+ switch (d) {
56
+ case 'deterministic-structural': return 4;
57
+ case 'deterministic-semantic': return 3;
58
+ case 'heuristic-advisory': return 2;
59
+ case 'llm-assisted-planning': return 1;
60
+ default: return 0;
61
+ }
62
+ }
63
+ /** Normalize a file path to use forward slashes for cross-platform stability. */
64
+ function normalizePath(p) {
65
+ return p.replace(/\\/g, '/');
66
+ }
67
+ // ── Public API ────────────────────────────────────────────────────────────────
68
+ /**
69
+ * Compute the canonical ordering key for a single finding.
70
+ *
71
+ * Returns a tuple whose elements, compared left-to-right, produce the
72
+ * canonical ordering defined above. Useful for inspection and testing.
73
+ *
74
+ * Format: [severityRank, determinismRank, ruleId, filePath, line, column, id]
75
+ */
76
+ function canonicalFindingOrderingKey(f) {
77
+ return [
78
+ rankSeverity(f.severity),
79
+ rankDeterminism(f.determinismClassification),
80
+ f.structuralMetadata?.ruleId ?? '',
81
+ normalizePath(f.evidence?.filePath ?? ''),
82
+ f.evidence?.line ?? 0,
83
+ f.evidence?.column ?? 0,
84
+ f.id,
85
+ ];
86
+ }
87
+ /**
88
+ * Sort findings into the canonical deterministic order.
89
+ *
90
+ * Properties:
91
+ * - Pure function — NEVER mutates the input array
92
+ * - Stable across process restarts for identical inputs
93
+ * - Independent of insertion order, Map iteration, filesystem traversal
94
+ * - Total order — no two distinct findings can compare as equal
95
+ *
96
+ * @param findings Any array of GovernanceFinding (may be in any order)
97
+ * @returns New sorted array (input is not mutated)
98
+ */
99
+ function sortCanonicalFindingsStable(findings) {
100
+ return [...findings].sort((a, b) => {
101
+ // 1. Severity descending (BLOCKING first)
102
+ const sA = rankSeverity(a.severity);
103
+ const sB = rankSeverity(b.severity);
104
+ if (sA !== sB)
105
+ return sB - sA;
106
+ // 2. Determinism classification descending (structural first)
107
+ const dA = rankDeterminism(a.determinismClassification);
108
+ const dB = rankDeterminism(b.determinismClassification);
109
+ if (dA !== dB)
110
+ return dB - dA;
111
+ // 3. Rule ID ascending
112
+ const rA = a.structuralMetadata?.ruleId ?? '';
113
+ const rB = b.structuralMetadata?.ruleId ?? '';
114
+ if (rA !== rB)
115
+ return rA < rB ? -1 : 1;
116
+ // 4. File path ascending (normalized)
117
+ const fA = normalizePath(a.evidence?.filePath ?? '');
118
+ const fB = normalizePath(b.evidence?.filePath ?? '');
119
+ if (fA !== fB)
120
+ return fA < fB ? -1 : 1;
121
+ // 5. Line number ascending (missing = 0)
122
+ const lA = a.evidence?.line ?? 0;
123
+ const lB = b.evidence?.line ?? 0;
124
+ if (lA !== lB)
125
+ return lA - lB;
126
+ // 6. Column number ascending (missing = 0)
127
+ const cA = a.evidence?.column ?? 0;
128
+ const cB = b.evidence?.column ?? 0;
129
+ if (cA !== cB)
130
+ return cA - cB;
131
+ // 7. Finding ID ascending — guaranteed unique tiebreaker
132
+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
133
+ });
134
+ }
135
+ /**
136
+ * Validate that a finding array is already in canonical order.
137
+ *
138
+ * Returns the index of the first out-of-order finding pair, or -1 if
139
+ * the array is already sorted. Used for invariant checking.
140
+ *
141
+ * Emits a console.warn if ordering drift is detected.
142
+ *
143
+ * @param findings Array to validate (not mutated)
144
+ * @param context Caller label for the warning (e.g. 'envelope-emit')
145
+ * @returns Index of first violation, or -1 if canonical
146
+ */
147
+ function validateCanonicalOrder(findings, context) {
148
+ for (let i = 1; i < findings.length; i++) {
149
+ const prev = findings[i - 1];
150
+ const curr = findings[i];
151
+ const kPrev = canonicalFindingOrderingKey(prev);
152
+ const kCurr = canonicalFindingOrderingKey(curr);
153
+ // Compare tuple element by element
154
+ for (let k = 0; k < kPrev.length; k++) {
155
+ const pv = kPrev[k];
156
+ const cv = kCurr[k];
157
+ if (typeof pv === 'number' && typeof cv === 'number') {
158
+ if (pv > cv) {
159
+ console.warn(`[neurcode/canonical-ordering] ORDERING DRIFT at index ${i} in ${context}. ` +
160
+ `Finding "${prev.id}" (key[${k}]=${pv}) appears before "${curr.id}" (key[${k}]=${cv}) ` +
161
+ `but canonical order requires ascending value at position ${k}. ` +
162
+ `Run sortCanonicalFindingsStable() before serialization.`);
163
+ return i;
164
+ }
165
+ if (pv < cv)
166
+ break; // correct order for this pair
167
+ }
168
+ else if (typeof pv === 'string' && typeof cv === 'string') {
169
+ // Numeric keys are descending (rank), string keys are ascending
170
+ // Keys 0 and 1 are ranks (descending means higher rank first = larger number first)
171
+ if (k <= 1) {
172
+ // These are rank values stored as numbers — already handled above
173
+ break;
174
+ }
175
+ if (pv > cv) {
176
+ console.warn(`[neurcode/canonical-ordering] ORDERING DRIFT at index ${i} in ${context}. ` +
177
+ `Finding "${prev.id}" (key[${k}]="${pv}") appears before "${curr.id}" ` +
178
+ `(key[${k}]="${cv}") but canonical order requires ascending string at position ${k}. ` +
179
+ `Run sortCanonicalFindingsStable() before serialization.`);
180
+ return i;
181
+ }
182
+ if (pv < cv)
183
+ break; // correct order for this pair
184
+ }
185
+ }
186
+ }
187
+ return -1;
188
+ }
189
+ //# sourceMappingURL=canonical-ordering.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-ordering.js","sourceRoot":"","sources":["../../src/governance/canonical-ordering.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;AAgDH,kEAYC;AAcD,kEAmCC;AAcD,wDA8CC;AArKD,iFAAiF;AAEjF;;;GAGG;AACH,SAAS,YAAY,CAAC,CAAS;IAC7B,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC;QAC1B,KAAK,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC;QAC1B,KAAK,MAAM,CAAC,CAAK,OA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,OAAO,IAAI;wBAC5E,YAAY,IAAI,CAAC,EAAE,UAAU,CAAC,KAAK,EAAE,qBAAqB,IAAI,CAAC,EAAE,UAAU,CAAC,KAAK,EAAE,IAAI;wBACvF,4DAA4D,CAAC,IAAI;wBACjE,yDAAyD,CAC1D,CAAC;oBACF,OAAO,CAAC,CAAC;gBACX,CAAC;gBACD,IAAI,EAAE,GAAG,EAAE;oBAAE,MAAM,CAAC,8BAA8B;YACpD,CAAC;iBAAM,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;gBAC5D,gEAAgE;gBAChE,oFAAoF;gBACpF,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;oBACX,kEAAkE;oBAClE,MAAM;gBACR,CAAC;gBACD,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;oBACZ,OAAO,CAAC,IAAI,CACV,yDAAyD,CAAC,OAAO,OAAO,IAAI;wBAC5E,YAAY,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,EAAE,sBAAsB,IAAI,CAAC,EAAE,IAAI;wBACvE,QAAQ,CAAC,MAAM,EAAE,gEAAgE,CAAC,IAAI;wBACtF,yDAAyD,CAC1D,CAAC;oBACF,OAAO,CAAC,CAAC;gBACX,CAAC;gBACD,IAAI,EAAE,GAAG,EAAE;oBAAE,MAAM,CAAC,8BAA8B;YACpD,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC"}
@@ -4,6 +4,13 @@ import type { IntentIssue } from '../intent-engine/matcher';
4
4
  import type { FlowIssue } from '../intent-engine/flow-validator';
5
5
  import type { RegressionIssue } from '../intent-engine/regression';
6
6
  import type { RuleViolation } from '@neurcode-ai/policy-engine';
7
+ /**
8
+ * Strip structural:* prefixed violations from the policy-engine row list.
9
+ * These are already represented in structuralViolations — keeping them in
10
+ * policyViolations causes cross-source duplicate GovernanceFinding objects.
11
+ * Called by attachCanonicalGovernance before building the envelope.
12
+ */
13
+ export declare function stripStructuralPolicyRows(violations: RuleViolation[]): RuleViolation[];
7
14
  export declare function findingFromStructural(v: StructuralViolation): GovernanceFinding;
8
15
  export declare function findingFromPolicyEngine(v: RuleViolation): GovernanceFinding;
9
16
  export declare function findingFromIntentIssue(i: IntentIssue): GovernanceFinding;
@@ -1 +1 @@
1
- {"version":3,"file":"canonical-pipeline.d.ts","sourceRoot":"","sources":["../../src/governance/canonical-pipeline.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,iBAAiB,EACjB,yBAAyB,EAEzB,8BAA8B,EAC/B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAoChE,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,mBAAmB,GAAG,iBAAiB,CAkC/E;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,aAAa,GAAG,iBAAiB,CAyB3E;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,WAAW,GAAG,iBAAiB,CAgBxE;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,SAAS,GAAG,iBAAiB,CAepE;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,eAAe,GAAG,iBAAiB,CAc3E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAcjF;AAED,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAcpG;AAmGD,wBAAgB,mCAAmC,CAC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