codehere 0.2.1 → 0.3.0-rc.1

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 (235) hide show
  1. package/README.md +88 -68
  2. package/dist/domain/entities/task.js +4 -4
  3. package/dist/error-handler.js +4 -9
  4. package/dist/index.js +253 -1219
  5. package/dist/infrastructure/config/product-context.js +7 -6
  6. package/dist/infrastructure/hooks/claude-sdk-hook.js +335 -63
  7. package/dist/infrastructure/observability/execution-tracer.js +11 -6
  8. package/dist/infrastructure/orchestration/agent-adapter.js +13 -0
  9. package/dist/infrastructure/orchestration/agent-installer.js +101 -0
  10. package/dist/infrastructure/orchestration/agents-config-seed.js +56 -0
  11. package/dist/infrastructure/orchestration/aider-adapter.js +319 -0
  12. package/dist/infrastructure/orchestration/artifacts-extractor.js +175 -0
  13. package/dist/infrastructure/orchestration/claude-code-adapter.js +352 -0
  14. package/dist/infrastructure/orchestration/codex-adapter.js +310 -0
  15. package/dist/infrastructure/orchestration/generic-cli-adapter.js +553 -0
  16. package/dist/infrastructure/orchestration/opencode-adapter.js +275 -0
  17. package/dist/infrastructure/orchestration/progress-aggregator.js +189 -0
  18. package/dist/infrastructure/orchestration/readiness.js +106 -0
  19. package/dist/infrastructure/orchestration/session-manager.js +272 -0
  20. package/dist/infrastructure/orchestration/session-persistence.js +109 -0
  21. package/dist/infrastructure/protocols/mcp-helpers.js +10 -30
  22. package/dist/infrastructure/protocols/mcp-server-impl.js +359 -21
  23. package/dist/infrastructure/protocols/ui-page.js +1827 -0
  24. package/dist/infrastructure/security/file-collection.js +115 -0
  25. package/dist/infrastructure/security/trust-scorer.js +301 -56
  26. package/dist/infrastructure/storage/task-repository.js +8 -7
  27. package/dist/monitoring.js +10 -49
  28. package/dist/presentation/cli/commands/help-command.js +96 -139
  29. package/dist/presentation/cli/commands/hook-command.js +17 -24
  30. package/dist/presentation/cli/commands/report-command.js +59 -72
  31. package/dist/presentation/cli/commands/setup-command.js +4 -4
  32. package/dist/presentation/cli/commands/status-command.js +334 -43
  33. package/dist/presentation/cli/commands/trust-command.js +115 -99
  34. package/dist/presentation/cli/error-display.js +17 -21
  35. package/dist/ui.js +17 -12
  36. package/package.json +35 -67
  37. package/dist/agents/base.js +0 -101
  38. package/dist/agents/orchestrator-model-driven.js +0 -141
  39. package/dist/agents/react-orchestrator-agent.js +0 -54
  40. package/dist/application/agents/execution-agent.js +0 -508
  41. package/dist/application/agents/multi-agent-orchestrator.js +0 -295
  42. package/dist/application/agents/planning-agent.js +0 -433
  43. package/dist/application/agents/validation-agent.js +0 -317
  44. package/dist/application/architectures/plan-and-act.js +0 -242
  45. package/dist/application/index.js +0 -12
  46. package/dist/application/services/agent-factory.js +0 -28
  47. package/dist/application/services/dependency-container.js +0 -596
  48. package/dist/application/services/git-context-service.js +0 -83
  49. package/dist/application/services/intelligent-router.js +0 -934
  50. package/dist/application/services/tool-executor-service.js +0 -94
  51. package/dist/application/use-cases/ask-question-use-case.js +0 -338
  52. package/dist/application/use-cases/edit-file-use-case.js +0 -830
  53. package/dist/application/use-cases/explain-file-use-case.js +0 -50
  54. package/dist/application/use-cases/index-codebase-use-case.js +0 -113
  55. package/dist/application/use-cases/planning-use-case.js +0 -276
  56. package/dist/application/use-cases/react-orchestration-use-case.js +0 -329
  57. package/dist/application/use-cases/reflexion-use-case.js +0 -30
  58. package/dist/application/workflows/deterministic-workflows.js +0 -189
  59. package/dist/ast-parser.js +0 -331
  60. package/dist/cache.js +0 -180
  61. package/dist/chat.js +0 -251
  62. package/dist/code-analysis.js +0 -327
  63. package/dist/context.js +0 -187
  64. package/dist/docs.js +0 -146
  65. package/dist/domain/entities/code-chunk.js +0 -6
  66. package/dist/domain/entities/decision.js +0 -9
  67. package/dist/domain/entities/edit.js +0 -6
  68. package/dist/domain/entities/knowledge-node.js +0 -9
  69. package/dist/domain/entities/knowledge-preservation.js +0 -10
  70. package/dist/domain/entities/memory.js +0 -6
  71. package/dist/domain/entities/pattern.js +0 -7
  72. package/dist/domain/entities/plan.js +0 -6
  73. package/dist/domain/entities/query.js +0 -6
  74. package/dist/domain/errors/embeddings-not-found-error.js +0 -13
  75. package/dist/domain/index.js +0 -19
  76. package/dist/domain/interfaces/ai-service.interface.js +0 -6
  77. package/dist/domain/interfaces/code-analyzer.interface.js +0 -6
  78. package/dist/domain/interfaces/decision-repository.interface.js +0 -9
  79. package/dist/domain/interfaces/embedding-repository.interface.js +0 -6
  80. package/dist/domain/interfaces/knowledge-graph-repository.interface.js +0 -9
  81. package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +0 -8
  82. package/dist/domain/interfaces/memory-repository.interface.js +0 -6
  83. package/dist/domain/interfaces/pattern-repository.interface.js +0 -6
  84. package/dist/domain/interfaces/verification-service.interface.js +0 -6
  85. package/dist/domain/services/cross-team-pattern-sharing.js +0 -125
  86. package/dist/domain/services/decision-recorder.js +0 -223
  87. package/dist/domain/services/decision-retriever.js +0 -133
  88. package/dist/domain/services/environment-mode-manager.js +0 -22
  89. package/dist/domain/services/graded-memory-activation.js +0 -69
  90. package/dist/domain/services/knowledge-access.js +0 -132
  91. package/dist/domain/services/knowledge-extractor.js +0 -247
  92. package/dist/domain/services/knowledge-graph-builder.js +0 -268
  93. package/dist/domain/services/knowledge-graph-query.js +0 -187
  94. package/dist/domain/services/memory-retriever.js +0 -82
  95. package/dist/domain/services/memory-synthesizer.js +0 -91
  96. package/dist/domain/services/pattern-extractor.js +0 -442
  97. package/dist/domain/services/query-intent-classifier.js +0 -140
  98. package/dist/domain/services/react-loop.js +0 -186
  99. package/dist/domain/services/risk-tier-detector.js +0 -78
  100. package/dist/edit.js +0 -319
  101. package/dist/embed.js +0 -459
  102. package/dist/formatter.js +0 -168
  103. package/dist/git.js +0 -198
  104. package/dist/infrastructure/ai/cohere-ai-service.js +0 -607
  105. package/dist/infrastructure/ai/command-r-evaluation.js +0 -206
  106. package/dist/infrastructure/ai/model-config.js +0 -84
  107. package/dist/infrastructure/ai/provider-ai-service.js +0 -477
  108. package/dist/infrastructure/cache/embedding-cache.js +0 -175
  109. package/dist/infrastructure/cache/query-result-cache.js +0 -66
  110. package/dist/infrastructure/cache/response-cache.js +0 -48
  111. package/dist/infrastructure/cache/security-scan-cache.js +0 -47
  112. package/dist/infrastructure/chunking/ast-code-chunker.js +0 -19
  113. package/dist/infrastructure/chunking/code-aware-chunker.js +0 -397
  114. package/dist/infrastructure/context/context-compressor.js +0 -329
  115. package/dist/infrastructure/context/conversation-context.js +0 -128
  116. package/dist/infrastructure/context/session-manager.js +0 -94
  117. package/dist/infrastructure/cost/cost-tracker.js +0 -360
  118. package/dist/infrastructure/file-scanner/file-scanner.js +0 -106
  119. package/dist/infrastructure/governance/nist-ai-rmf.js +0 -292
  120. package/dist/infrastructure/governance/policy-as-code.js +0 -258
  121. package/dist/infrastructure/governance/prompt-to-code-lineage.js +0 -239
  122. package/dist/infrastructure/index.js +0 -7
  123. package/dist/infrastructure/observability/prompt-versioner.js +0 -145
  124. package/dist/infrastructure/protocols/a2a-metadata.js +0 -137
  125. package/dist/infrastructure/protocols/a2a-protocol.js +0 -314
  126. package/dist/infrastructure/protocols/mcp-oauth.js +0 -184
  127. package/dist/infrastructure/protocols/mcp-server.js +0 -333
  128. package/dist/infrastructure/protocols/streaming-handler.js +0 -103
  129. package/dist/infrastructure/providers/cohere-provider.js +0 -444
  130. package/dist/infrastructure/providers/fake-provider.js +0 -130
  131. package/dist/infrastructure/providers/local-llm-provider.js +0 -330
  132. package/dist/infrastructure/providers/model-config.types.js +0 -9
  133. package/dist/infrastructure/providers/model-provider.interface.js +0 -8
  134. package/dist/infrastructure/providers/openai-provider.js +0 -413
  135. package/dist/infrastructure/providers/openrouter-provider.js +0 -399
  136. package/dist/infrastructure/providers/operation-provider-resolver.js +0 -105
  137. package/dist/infrastructure/providers/provider-config-loader.js +0 -120
  138. package/dist/infrastructure/providers/provider-registry.js +0 -88
  139. package/dist/infrastructure/safety/pattern-detector.js +0 -133
  140. package/dist/infrastructure/security/ai-sast-scanner.js +0 -290
  141. package/dist/infrastructure/security/docker-sandbox.js +0 -178
  142. package/dist/infrastructure/security/enhanced-security-gate.js +0 -151
  143. package/dist/infrastructure/security/license-scanner.js +0 -167
  144. package/dist/infrastructure/security/provider-bias-detector.js +0 -164
  145. package/dist/infrastructure/security/sandbox-executor.js +0 -64
  146. package/dist/infrastructure/serialization/toon-serializer.js +0 -119
  147. package/dist/infrastructure/storage/memory-stream-service.js +0 -204
  148. package/dist/infrastructure/storage/plan-repository.js +0 -96
  149. package/dist/infrastructure/storage/sqlite-decision-repository.js +0 -232
  150. package/dist/infrastructure/storage/sqlite-embedding-repository.js +0 -311
  151. package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +0 -417
  152. package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +0 -230
  153. package/dist/infrastructure/storage/sqlite-memory-repository.js +0 -229
  154. package/dist/infrastructure/storage/sqlite-pattern-repository.js +0 -249
  155. package/dist/infrastructure/storage/task-helpers.js +0 -197
  156. package/dist/infrastructure/telemetry/telemetry-service.js +0 -167
  157. package/dist/infrastructure/ux/appropriate-friction.js +0 -213
  158. package/dist/infrastructure/ux/bi-directional-learning.js +0 -337
  159. package/dist/infrastructure/ux/capability-boundaries.js +0 -42
  160. package/dist/infrastructure/ux/comprehensive-formatter.js +0 -117
  161. package/dist/infrastructure/ux/contextual-feature-discovery.js +0 -10
  162. package/dist/infrastructure/ux/expectation-management.js +0 -327
  163. package/dist/infrastructure/ux/feature-discovery.js +0 -14
  164. package/dist/infrastructure/ux/feedback-prompt.js +0 -45
  165. package/dist/infrastructure/ux/hitl-validation.js +0 -297
  166. package/dist/infrastructure/ux/progress-indicator.js +0 -116
  167. package/dist/infrastructure/ux/progressive-disclosure.js +0 -236
  168. package/dist/infrastructure/ux/review-checkpoint.js +0 -72
  169. package/dist/infrastructure/ux/staged-feature-intro.js +0 -24
  170. package/dist/infrastructure/ux/stream-markdown.js +0 -151
  171. package/dist/infrastructure/ux/syntax-highlighter.js +0 -91
  172. package/dist/infrastructure/ux/team-standards.js +0 -196
  173. package/dist/infrastructure/ux/transparency.js +0 -71
  174. package/dist/infrastructure/validation/agent-feedback.js +0 -55
  175. package/dist/infrastructure/validation/agent-validation-helper.js +0 -137
  176. package/dist/infrastructure/validation/review-handler.js +0 -40
  177. package/dist/infrastructure/validation/summary-aggregator.js +0 -70
  178. package/dist/infrastructure/validation/summary-extractor.js +0 -45
  179. package/dist/infrastructure/validation/trace-summary.js +0 -52
  180. package/dist/infrastructure/verification/verification-service.js +0 -47
  181. package/dist/infrastructure/xai/attention-visualizer.js +0 -172
  182. package/dist/infrastructure/xai/cot-visualizer.js +0 -283
  183. package/dist/infrastructure/xai/decision-tree-log.js +0 -212
  184. package/dist/infrastructure/xai/interactive-xai.js +0 -260
  185. package/dist/infrastructure/xai/uncertainty-quantifier.js +0 -198
  186. package/dist/intelligent-retrieval.js +0 -272
  187. package/dist/intent/classifier.js +0 -2
  188. package/dist/intent/context.js +0 -2
  189. package/dist/iterative-refinement.js +0 -189
  190. package/dist/learning.js +0 -232
  191. package/dist/log.js +0 -31
  192. package/dist/migrate.js +0 -133
  193. package/dist/parallel-processor.js +0 -530
  194. package/dist/planner.js +0 -198
  195. package/dist/policy.js +0 -26
  196. package/dist/presentation/cli/commands/ask-command.js +0 -314
  197. package/dist/presentation/cli/commands/cost-command.js +0 -191
  198. package/dist/presentation/cli/commands/decision-command.js +0 -207
  199. package/dist/presentation/cli/commands/docs-command.js +0 -25
  200. package/dist/presentation/cli/commands/fix-command.js +0 -53
  201. package/dist/presentation/cli/commands/knowledge-command.js +0 -129
  202. package/dist/presentation/cli/commands/learning-dashboard-command.js +0 -183
  203. package/dist/presentation/cli/commands/models-command.js +0 -194
  204. package/dist/presentation/cli/commands/orchestrate-command.js +0 -207
  205. package/dist/presentation/cli/commands/plan-command.js +0 -246
  206. package/dist/presentation/cli/commands/product-command.js +0 -199
  207. package/dist/presentation/cli/commands/react-command.js +0 -181
  208. package/dist/presentation/cli/commands/review-command.js +0 -154
  209. package/dist/presentation/cli/commands/run-command.js +0 -188
  210. package/dist/presentation/cli/commands/smart-command.js +0 -395
  211. package/dist/presentation/cli/commands/suggest-command.js +0 -138
  212. package/dist/presentation/cli/commands/trace-command.js +0 -129
  213. package/dist/presentation/cli/commands/undo-command.js +0 -150
  214. package/dist/query-optimizer.js +0 -205
  215. package/dist/refactor.js +0 -116
  216. package/dist/review.js +0 -206
  217. package/dist/search.js +0 -163
  218. package/dist/session.js +0 -652
  219. package/dist/task-verification.js +0 -336
  220. package/dist/testgen.js +0 -166
  221. package/dist/token-optimizer.js +0 -277
  222. package/dist/tools/bash.js +0 -213
  223. package/dist/tools/edit.js +0 -235
  224. package/dist/tools/executor.js +0 -153
  225. package/dist/tools/git-tool.js +0 -292
  226. package/dist/tools/parser.js +0 -158
  227. package/dist/tools/registry.js +0 -302
  228. package/dist/tools/search.js +0 -100
  229. package/dist/types.js +0 -2
  230. package/dist/utils/check-api-status.js +0 -100
  231. package/dist/utils/diff-parser.js +0 -162
  232. package/dist/verification/backup.js +0 -259
  233. package/dist/verification/compiler.js +0 -264
  234. package/dist/verification/index.js +0 -273
  235. package/dist/verification/test-runner.js +0 -379
@@ -1,292 +0,0 @@
1
- /**
2
- * INTERNAL ONLY — infrastructure helper, not a user-facing feature.
3
- *
4
- * NIST AI Risk Management Framework (AI RMF) - Infrastructure-only, not yet exposed as user-facing feature.
5
- * Planned for 0.5.x (Teams & Governance). Not guaranteed to be stable.
6
- *
7
- * Do not rely on this directly.
8
- *
9
- * @internal
10
- */
11
- /**
12
- * NIST AI RMF Framework
13
- * Implements 4 core functions for enterprise AI governance
14
- */
15
- export class NISTAIRMF {
16
- decisions = [];
17
- /**
18
- * GOVERN Function: Risk culture, accountability, lifecycle management
19
- * Establishes organizational context for AI risk management
20
- */
21
- async govern(context) {
22
- const decisionId = `govern-${Date.now()}`;
23
- // Govern: Risk culture assessment
24
- const riskCulture = this.assessRiskCulture(context);
25
- // Govern: Accountability assignment
26
- const accountability = this.assignAccountability(context);
27
- // Govern: Lifecycle management planning
28
- const lifecycle = this.planLifecycle(context);
29
- const decision = {
30
- decisionId,
31
- timestamp: Date.now(),
32
- function: 'govern',
33
- decision: `Risk culture: ${riskCulture.level}, Accountability: ${accountability.role}, Lifecycle: ${lifecycle.phase}`,
34
- rationale: `Governed ${context.contextType} operation with ${context.riskLevel} risk level`,
35
- outcome: riskCulture.level === 'critical' ? 'requires_review' : 'allowed',
36
- };
37
- this.decisions.push(decision);
38
- return decision;
39
- }
40
- /**
41
- * MAP Function: Context framing, risk identification
42
- * Identifies and characterizes risks in specific contexts
43
- */
44
- async map(context, existingRiskProfile) {
45
- const decisionId = `map-${Date.now()}`;
46
- // Map: Context framing
47
- const contextFrame = this.frameContext(context);
48
- // Map: Risk identification
49
- const riskProfile = existingRiskProfile || {
50
- security: {
51
- vulnerabilities: 0,
52
- licenseConflicts: 0,
53
- providerBias: false,
54
- uncertainty: 0.5,
55
- },
56
- compliance: {
57
- gdprRelevant: context.regulatoryRelevant,
58
- hipaaRelevant: context.targetDomain === 'healthcare',
59
- },
60
- operational: {
61
- complexity: context.riskLevel === 'critical' ? 0.9 : 0.5,
62
- dependencies: 0,
63
- },
64
- };
65
- // Map: Risk characterization
66
- const risks = this.characterizeRisks(riskProfile, context);
67
- const decision = {
68
- decisionId,
69
- timestamp: Date.now(),
70
- function: 'map',
71
- decision: `Mapped ${risks.length} risks in ${context.contextType} context`,
72
- rationale: risks.map(r => r.description).join('; '),
73
- riskProfile,
74
- outcome: risks.some(r => r.severity === 'critical') ? 'requires_review' : 'allowed',
75
- };
76
- this.decisions.push(decision);
77
- return { decision, riskProfile };
78
- }
79
- /**
80
- * MEASURE Function: SAST/SCA mandatory, security density tracking
81
- * Quantifies and monitors AI risks and performance
82
- */
83
- async measure(riskProfile, metrics) {
84
- const decisionId = `measure-${Date.now()}`;
85
- // Measure: SAST/SCA metrics (mandatory)
86
- const securityMetrics = {
87
- vulnerabilities: metrics.sastFindings || 0,
88
- licenseConflicts: metrics.licenseFindings || 0,
89
- providerBias: (metrics.providerBiasFindings || 0) > 0,
90
- uncertainty: metrics.uncertaintyScore || riskProfile.security.uncertainty,
91
- };
92
- // Measure: Security density tracking (language-specific thresholds)
93
- const securityDensity = metrics.securityDensity || 0;
94
- const densityThreshold = this.getSecurityDensityThreshold(riskProfile);
95
- // Measure: Test coverage tracking
96
- const testCoverage = metrics.testCoverage || riskProfile.operational.testCoverage || 0;
97
- const updatedRiskProfile = {
98
- ...riskProfile,
99
- security: securityMetrics,
100
- operational: {
101
- ...riskProfile.operational,
102
- testCoverage,
103
- },
104
- };
105
- const decision = {
106
- decisionId,
107
- timestamp: Date.now(),
108
- function: 'measure',
109
- decision: `Measured: ${securityMetrics.vulnerabilities} vulnerabilities, ${securityMetrics.licenseConflicts} license conflicts, security density: ${securityDensity.toFixed(2)}, test coverage: ${testCoverage.toFixed(1)}%`,
110
- rationale: `SAST/SCA metrics collected. Security density ${securityDensity > densityThreshold ? 'EXCEEDS' : 'within'} threshold (${densityThreshold}). Test coverage ${testCoverage < 80 ? 'BELOW' : 'meets'} target (80%)`,
111
- riskProfile: updatedRiskProfile,
112
- outcome: securityMetrics.vulnerabilities > 0 || securityMetrics.licenseConflicts > 0 || testCoverage < 50 ? 'requires_review' : 'allowed',
113
- };
114
- this.decisions.push(decision);
115
- return decision;
116
- }
117
- /**
118
- * MANAGE Function: Incident response, continuous updates
119
- * Responds to and manages AI risks over time
120
- */
121
- async manage(incident, action) {
122
- const decisionId = `manage-${Date.now()}`;
123
- // Manage: Incident response
124
- const response = this.respondToIncident(incident, action);
125
- // Manage: Continuous update planning
126
- const updates = this.planContinuousUpdates(incident);
127
- const decision = {
128
- decisionId,
129
- timestamp: Date.now(),
130
- function: 'manage',
131
- decision: `${action.toUpperCase()}: ${incident.type} incident (${incident.severity})`,
132
- rationale: `${response.description}. Continuous updates: ${updates.map(u => u.action).join(', ')}`,
133
- outcome: action === 'accept' || action === 'transfer' ? 'allowed' : action === 'avoid' ? 'blocked' : 'requires_review',
134
- };
135
- this.decisions.push(decision);
136
- return decision;
137
- }
138
- /**
139
- * Get governance history for audit
140
- */
141
- getGovernanceHistory(filter) {
142
- let filtered = [...this.decisions];
143
- if (filter?.function) {
144
- filtered = filtered.filter(d => d.function === filter.function);
145
- }
146
- if (filter?.outcome) {
147
- filtered = filtered.filter(d => d.outcome === filter.outcome);
148
- }
149
- if (filter?.startTime) {
150
- filtered = filtered.filter(d => d.timestamp >= filter.startTime);
151
- }
152
- if (filter?.endTime) {
153
- filtered = filtered.filter(d => d.timestamp <= filter.endTime);
154
- }
155
- return filtered.sort((a, b) => b.timestamp - a.timestamp);
156
- }
157
- // Private helper methods
158
- assessRiskCulture(context) {
159
- const factors = [];
160
- let level = 'low';
161
- if (context.riskLevel === 'critical') {
162
- level = 'critical';
163
- factors.push('Critical risk level detected');
164
- }
165
- else if (context.regulatoryRelevant) {
166
- level = 'high';
167
- factors.push('Regulatory relevance (GDPR/HIPAA)');
168
- }
169
- else if (context.riskLevel === 'high') {
170
- level = 'high';
171
- factors.push('High risk level');
172
- }
173
- else {
174
- level = context.riskLevel;
175
- }
176
- return { level, factors };
177
- }
178
- assignAccountability(context) {
179
- // Accountability assignment based on risk level
180
- if (context.riskLevel === 'critical') {
181
- return { role: 'senior_engineer_review', responsible: 'Senior Engineer + Security Team' };
182
- }
183
- else if (context.riskLevel === 'high') {
184
- return { role: 'engineer_review', responsible: 'Engineering Lead' };
185
- }
186
- else {
187
- return { role: 'automated', responsible: 'AI System' };
188
- }
189
- }
190
- planLifecycle(context) {
191
- const stages = ['Development', 'Testing', 'Deployment', 'Monitoring', 'Retirement'];
192
- return {
193
- phase: 'Development',
194
- stages,
195
- };
196
- }
197
- frameContext(context) {
198
- const constraints = [];
199
- if (context.regulatoryRelevant) {
200
- constraints.push('Regulatory compliance required');
201
- }
202
- if (context.riskLevel === 'critical') {
203
- constraints.push('Critical risk - human review mandatory');
204
- }
205
- return {
206
- domain: context.targetDomain,
207
- constraints,
208
- };
209
- }
210
- characterizeRisks(riskProfile, context) {
211
- const risks = [];
212
- if (riskProfile.security.vulnerabilities > 0) {
213
- risks.push({
214
- type: 'security',
215
- severity: riskProfile.security.vulnerabilities > 5 ? 'critical' : 'high',
216
- description: `${riskProfile.security.vulnerabilities} security vulnerabilities detected`,
217
- });
218
- }
219
- if (riskProfile.security.licenseConflicts > 0) {
220
- risks.push({
221
- type: 'compliance',
222
- severity: 'critical',
223
- description: `${riskProfile.security.licenseConflicts} license conflicts detected (35% contamination risk)`,
224
- });
225
- }
226
- if (riskProfile.security.providerBias) {
227
- risks.push({
228
- type: 'operational',
229
- severity: 'medium',
230
- description: 'Provider bias detected - vendor lock-in risk',
231
- });
232
- }
233
- if (riskProfile.security.uncertainty > 0.7) {
234
- risks.push({
235
- type: 'reliability',
236
- severity: 'high',
237
- description: `High epistemic uncertainty (${(riskProfile.security.uncertainty * 100).toFixed(1)}%) - hallucination risk`,
238
- });
239
- }
240
- if (riskProfile.compliance.gdprRelevant || riskProfile.compliance.hipaaRelevant) {
241
- risks.push({
242
- type: 'compliance',
243
- severity: 'high',
244
- description: 'Regulatory compliance requirements (GDPR/HIPAA)',
245
- });
246
- }
247
- return risks;
248
- }
249
- getSecurityDensityThreshold(riskProfile) {
250
- // Language-specific thresholds (LOC per CWE)
251
- // Research: Security density tracking with language-specific thresholds
252
- return 1000; // Default: 1 CWE per 1000 LOC
253
- }
254
- respondToIncident(incident, action) {
255
- const steps = [];
256
- if (action === 'mitigate') {
257
- steps.push('Identify root cause');
258
- steps.push('Implement fix');
259
- steps.push('Verify resolution');
260
- steps.push('Update risk profile');
261
- }
262
- else if (action === 'accept') {
263
- steps.push('Document acceptance rationale');
264
- steps.push('Monitor for escalation');
265
- }
266
- else if (action === 'avoid') {
267
- steps.push('Block operation');
268
- steps.push('Notify stakeholders');
269
- }
270
- else if (action === 'transfer') {
271
- steps.push('Assign to responsible party');
272
- steps.push('Track resolution');
273
- }
274
- return {
275
- description: `${action.toUpperCase()} action for ${incident.severity} ${incident.type} incident`,
276
- steps,
277
- };
278
- }
279
- planContinuousUpdates(incident) {
280
- const updates = [];
281
- if (incident.severity === 'critical') {
282
- updates.push({ action: 'Update risk models', priority: 'high' });
283
- updates.push({ action: 'Enhance detection rules', priority: 'high' });
284
- }
285
- else {
286
- updates.push({ action: 'Monitor similar incidents', priority: 'medium' });
287
- }
288
- updates.push({ action: 'Review governance policies', priority: 'low' });
289
- return updates;
290
- }
291
- }
292
- //# sourceMappingURL=nist-ai-rmf.js.map
@@ -1,258 +0,0 @@
1
- /**
2
- * INTERNAL ONLY — infrastructure helper, not a user-facing feature.
3
- *
4
- * Policy-as-Code (PaC) Framework - Infrastructure-only, not yet exposed as user-facing feature.
5
- * Planned for 0.5.x (Teams & Governance). Not guaranteed to be stable.
6
- *
7
- * Do not rely on this directly.
8
- *
9
- * @internal
10
- */
11
- /**
12
- * Policy-as-Code Framework
13
- * Enforces policies automatically based on code-defined rules
14
- */
15
- export class PolicyAsCode {
16
- policies = new Map();
17
- defaultPolicies = [];
18
- constructor() {
19
- this.initializeDefaultPolicies();
20
- }
21
- /**
22
- * Load policy from code definition
23
- */
24
- loadPolicy(rule) {
25
- this.policies.set(rule.id, rule);
26
- this.defaultPolicies.push(rule);
27
- }
28
- /**
29
- * Evaluate policies against context
30
- */
31
- async evaluate(context) {
32
- const results = [];
33
- const blockingRules = [];
34
- // Evaluate all enabled policies
35
- for (const [ruleId, rule] of this.policies.entries()) {
36
- if (!rule.enabled)
37
- continue;
38
- const result = await this.evaluateRule(rule, context);
39
- results.push(result);
40
- if (!result.passed && (result.action === 'block' || result.action === 'require_review')) {
41
- blockingRules.push(result);
42
- }
43
- }
44
- const passed = blockingRules.length === 0;
45
- return {
46
- passed,
47
- results,
48
- blockingRules,
49
- };
50
- }
51
- /**
52
- * Get all policies
53
- */
54
- getPolicies() {
55
- return Array.from(this.policies.values());
56
- }
57
- /**
58
- * Enable/disable policy
59
- */
60
- setPolicyEnabled(ruleId, enabled) {
61
- const rule = this.policies.get(ruleId);
62
- if (!rule)
63
- return false;
64
- rule.enabled = enabled;
65
- rule.updatedAt = Date.now();
66
- return true;
67
- }
68
- /**
69
- * Update policy
70
- */
71
- updatePolicy(ruleId, updates) {
72
- const rule = this.policies.get(ruleId);
73
- if (!rule)
74
- return false;
75
- Object.assign(rule, updates);
76
- rule.updatedAt = Date.now();
77
- rule.version = this.incrementVersion(rule.version);
78
- return true;
79
- }
80
- // Private methods
81
- async evaluateRule(rule, context) {
82
- // Evaluate all conditions (AND logic - all must pass)
83
- let passed = true;
84
- const evidence = {};
85
- for (const condition of rule.conditions) {
86
- const conditionResult = this.evaluateCondition(condition, context);
87
- // Debug logging
88
- if (process.env.CODEHERE_DEBUG === '1')
89
- console.log(`[PolicyAsCode] Evaluating condition: ${condition.type} ${condition.operator} ${condition.value}, actual: ${conditionResult.actual}, condition met: ${conditionResult.passed}`);
90
- // CRITICAL FIX: Policy conditions are "blocking conditions"
91
- // If condition is met (passed = true), it means we SHOULD block → policy FAILS
92
- // If condition is NOT met (passed = false), it means we should NOT block → policy PASSES
93
- // So: conditionResult.passed = true → should block → policy fails
94
- // conditionResult.passed = false → should not block → policy passes
95
- if (conditionResult.passed) {
96
- passed = false; // Condition met → should block → policy fails
97
- }
98
- evidence[condition.field] = {
99
- expected: condition.value,
100
- actual: conditionResult.actual,
101
- passed: conditionResult.passed,
102
- note: conditionResult.passed ? 'Condition met - blocking' : 'Condition not met - allowing',
103
- };
104
- }
105
- return {
106
- ruleId: rule.id,
107
- ruleName: rule.name,
108
- passed,
109
- severity: rule.severity,
110
- action: rule.action,
111
- message: passed
112
- ? `Policy "${rule.name}" passed`
113
- : `Policy "${rule.name}" failed: ${rule.description}`,
114
- evidence,
115
- };
116
- }
117
- evaluateCondition(condition, context) {
118
- let actual;
119
- // Get actual value from context based on condition type
120
- switch (condition.type) {
121
- case 'security':
122
- // Only count critical and high severity findings for policy evaluation
123
- // This reduces false positives from medium/low severity findings
124
- const securityFindings = context.securityFindings || [];
125
- actual = securityFindings.filter((f) => f.severity === 'critical' || f.severity === 'high').length;
126
- break;
127
- case 'license':
128
- actual = context.licenseFindings?.length || 0;
129
- break;
130
- case 'provider_bias':
131
- actual = (context.providerBiasFindings?.length || 0) > 0;
132
- break;
133
- case 'uncertainty':
134
- actual = context.uncertainty?.epistemic?.value || 0;
135
- break;
136
- case 'test_coverage':
137
- actual = context.testCoverage || 0;
138
- break;
139
- default:
140
- actual = context.metadata?.[condition.field] || null;
141
- }
142
- // Evaluate condition based on operator
143
- let passed = false;
144
- switch (condition.operator) {
145
- case 'equals':
146
- passed = actual === condition.value;
147
- break;
148
- case 'greater_than':
149
- passed = actual > condition.value;
150
- break;
151
- case 'less_than':
152
- passed = actual < condition.value;
153
- break;
154
- case 'contains':
155
- passed = String(actual).includes(String(condition.value));
156
- break;
157
- case 'not_contains':
158
- passed = !String(actual).includes(String(condition.value));
159
- break;
160
- case 'exists':
161
- passed = actual !== null && actual !== undefined;
162
- break;
163
- }
164
- return { passed, actual };
165
- }
166
- initializeDefaultPolicies() {
167
- // Default Policy 1: Block critical security vulnerabilities
168
- // Policy semantics: Block if critical vulnerabilities > 0
169
- // Condition: greater_than with value 0 means "if actual > 0, block"
170
- // So: actual = 0 → 0 > 0 = false → condition NOT met → should NOT block → policy PASSES
171
- // actual > 0 → actual > 0 = true → condition met → should block → policy FAILS
172
- this.loadPolicy({
173
- id: 'security-critical-block',
174
- name: 'Block Critical Security Vulnerabilities',
175
- description: 'Block code with critical security vulnerabilities',
176
- severity: 'critical',
177
- action: 'block',
178
- enabled: true,
179
- conditions: [
180
- {
181
- type: 'security',
182
- operator: 'greater_than',
183
- field: 'critical_vulnerabilities',
184
- value: 0,
185
- },
186
- ],
187
- version: '1.0.0',
188
- createdAt: Date.now(),
189
- updatedAt: Date.now(),
190
- });
191
- // Default Policy 2: Block license conflicts
192
- this.loadPolicy({
193
- id: 'license-conflict-block',
194
- name: 'Block License Conflicts',
195
- description: 'Block code with license conflicts (GPL/MIT contamination)',
196
- severity: 'critical',
197
- action: 'block',
198
- enabled: true,
199
- conditions: [
200
- {
201
- type: 'license',
202
- operator: 'greater_than',
203
- field: 'license_conflicts',
204
- value: 0,
205
- },
206
- ],
207
- version: '1.0.0',
208
- createdAt: Date.now(),
209
- updatedAt: Date.now(),
210
- });
211
- // Default Policy 3: Warn on high uncertainty
212
- this.loadPolicy({
213
- id: 'uncertainty-high-warn',
214
- name: 'Warn on High Uncertainty',
215
- description: 'Warn when epistemic uncertainty exceeds threshold (hallucination risk)',
216
- severity: 'high',
217
- action: 'warn',
218
- enabled: true,
219
- conditions: [
220
- {
221
- type: 'uncertainty',
222
- operator: 'greater_than',
223
- field: 'epistemic_uncertainty',
224
- value: 0.7,
225
- },
226
- ],
227
- version: '1.0.0',
228
- createdAt: Date.now(),
229
- updatedAt: Date.now(),
230
- });
231
- // Default Policy 4: Require review for provider bias
232
- this.loadPolicy({
233
- id: 'provider-bias-review',
234
- name: 'Review Provider Bias',
235
- description: 'Require review when provider bias is detected (vendor lock-in risk)',
236
- severity: 'medium',
237
- action: 'require_review',
238
- enabled: true,
239
- conditions: [
240
- {
241
- type: 'provider_bias',
242
- operator: 'equals',
243
- field: 'has_provider_bias',
244
- value: true,
245
- },
246
- ],
247
- version: '1.0.0',
248
- createdAt: Date.now(),
249
- updatedAt: Date.now(),
250
- });
251
- }
252
- incrementVersion(version) {
253
- const parts = version.split('.');
254
- const patch = parseInt(parts[2] || '0', 10) + 1;
255
- return `${parts[0]}.${parts[1]}.${patch}`;
256
- }
257
- }
258
- //# sourceMappingURL=policy-as-code.js.map