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.
- package/README.md +88 -68
- package/dist/domain/entities/task.js +4 -4
- package/dist/error-handler.js +4 -9
- package/dist/index.js +253 -1219
- package/dist/infrastructure/config/product-context.js +7 -6
- package/dist/infrastructure/hooks/claude-sdk-hook.js +335 -63
- package/dist/infrastructure/observability/execution-tracer.js +11 -6
- package/dist/infrastructure/orchestration/agent-adapter.js +13 -0
- package/dist/infrastructure/orchestration/agent-installer.js +101 -0
- package/dist/infrastructure/orchestration/agents-config-seed.js +56 -0
- package/dist/infrastructure/orchestration/aider-adapter.js +319 -0
- package/dist/infrastructure/orchestration/artifacts-extractor.js +175 -0
- package/dist/infrastructure/orchestration/claude-code-adapter.js +352 -0
- package/dist/infrastructure/orchestration/codex-adapter.js +310 -0
- package/dist/infrastructure/orchestration/generic-cli-adapter.js +553 -0
- package/dist/infrastructure/orchestration/opencode-adapter.js +275 -0
- package/dist/infrastructure/orchestration/progress-aggregator.js +189 -0
- package/dist/infrastructure/orchestration/readiness.js +106 -0
- package/dist/infrastructure/orchestration/session-manager.js +272 -0
- package/dist/infrastructure/orchestration/session-persistence.js +109 -0
- package/dist/infrastructure/protocols/mcp-helpers.js +10 -30
- package/dist/infrastructure/protocols/mcp-server-impl.js +359 -21
- package/dist/infrastructure/protocols/ui-page.js +1827 -0
- package/dist/infrastructure/security/file-collection.js +115 -0
- package/dist/infrastructure/security/trust-scorer.js +301 -56
- package/dist/infrastructure/storage/task-repository.js +8 -7
- package/dist/monitoring.js +10 -49
- package/dist/presentation/cli/commands/help-command.js +96 -139
- package/dist/presentation/cli/commands/hook-command.js +17 -24
- package/dist/presentation/cli/commands/report-command.js +59 -72
- package/dist/presentation/cli/commands/setup-command.js +4 -4
- package/dist/presentation/cli/commands/status-command.js +334 -43
- package/dist/presentation/cli/commands/trust-command.js +115 -99
- package/dist/presentation/cli/error-display.js +17 -21
- package/dist/ui.js +17 -12
- package/package.json +35 -67
- package/dist/agents/base.js +0 -101
- package/dist/agents/orchestrator-model-driven.js +0 -141
- package/dist/agents/react-orchestrator-agent.js +0 -54
- package/dist/application/agents/execution-agent.js +0 -508
- package/dist/application/agents/multi-agent-orchestrator.js +0 -295
- package/dist/application/agents/planning-agent.js +0 -433
- package/dist/application/agents/validation-agent.js +0 -317
- package/dist/application/architectures/plan-and-act.js +0 -242
- package/dist/application/index.js +0 -12
- package/dist/application/services/agent-factory.js +0 -28
- package/dist/application/services/dependency-container.js +0 -596
- package/dist/application/services/git-context-service.js +0 -83
- package/dist/application/services/intelligent-router.js +0 -934
- package/dist/application/services/tool-executor-service.js +0 -94
- package/dist/application/use-cases/ask-question-use-case.js +0 -338
- package/dist/application/use-cases/edit-file-use-case.js +0 -830
- package/dist/application/use-cases/explain-file-use-case.js +0 -50
- package/dist/application/use-cases/index-codebase-use-case.js +0 -113
- package/dist/application/use-cases/planning-use-case.js +0 -276
- package/dist/application/use-cases/react-orchestration-use-case.js +0 -329
- package/dist/application/use-cases/reflexion-use-case.js +0 -30
- package/dist/application/workflows/deterministic-workflows.js +0 -189
- package/dist/ast-parser.js +0 -331
- package/dist/cache.js +0 -180
- package/dist/chat.js +0 -251
- package/dist/code-analysis.js +0 -327
- package/dist/context.js +0 -187
- package/dist/docs.js +0 -146
- package/dist/domain/entities/code-chunk.js +0 -6
- package/dist/domain/entities/decision.js +0 -9
- package/dist/domain/entities/edit.js +0 -6
- package/dist/domain/entities/knowledge-node.js +0 -9
- package/dist/domain/entities/knowledge-preservation.js +0 -10
- package/dist/domain/entities/memory.js +0 -6
- package/dist/domain/entities/pattern.js +0 -7
- package/dist/domain/entities/plan.js +0 -6
- package/dist/domain/entities/query.js +0 -6
- package/dist/domain/errors/embeddings-not-found-error.js +0 -13
- package/dist/domain/index.js +0 -19
- package/dist/domain/interfaces/ai-service.interface.js +0 -6
- package/dist/domain/interfaces/code-analyzer.interface.js +0 -6
- package/dist/domain/interfaces/decision-repository.interface.js +0 -9
- package/dist/domain/interfaces/embedding-repository.interface.js +0 -6
- package/dist/domain/interfaces/knowledge-graph-repository.interface.js +0 -9
- package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +0 -8
- package/dist/domain/interfaces/memory-repository.interface.js +0 -6
- package/dist/domain/interfaces/pattern-repository.interface.js +0 -6
- package/dist/domain/interfaces/verification-service.interface.js +0 -6
- package/dist/domain/services/cross-team-pattern-sharing.js +0 -125
- package/dist/domain/services/decision-recorder.js +0 -223
- package/dist/domain/services/decision-retriever.js +0 -133
- package/dist/domain/services/environment-mode-manager.js +0 -22
- package/dist/domain/services/graded-memory-activation.js +0 -69
- package/dist/domain/services/knowledge-access.js +0 -132
- package/dist/domain/services/knowledge-extractor.js +0 -247
- package/dist/domain/services/knowledge-graph-builder.js +0 -268
- package/dist/domain/services/knowledge-graph-query.js +0 -187
- package/dist/domain/services/memory-retriever.js +0 -82
- package/dist/domain/services/memory-synthesizer.js +0 -91
- package/dist/domain/services/pattern-extractor.js +0 -442
- package/dist/domain/services/query-intent-classifier.js +0 -140
- package/dist/domain/services/react-loop.js +0 -186
- package/dist/domain/services/risk-tier-detector.js +0 -78
- package/dist/edit.js +0 -319
- package/dist/embed.js +0 -459
- package/dist/formatter.js +0 -168
- package/dist/git.js +0 -198
- package/dist/infrastructure/ai/cohere-ai-service.js +0 -607
- package/dist/infrastructure/ai/command-r-evaluation.js +0 -206
- package/dist/infrastructure/ai/model-config.js +0 -84
- package/dist/infrastructure/ai/provider-ai-service.js +0 -477
- package/dist/infrastructure/cache/embedding-cache.js +0 -175
- package/dist/infrastructure/cache/query-result-cache.js +0 -66
- package/dist/infrastructure/cache/response-cache.js +0 -48
- package/dist/infrastructure/cache/security-scan-cache.js +0 -47
- package/dist/infrastructure/chunking/ast-code-chunker.js +0 -19
- package/dist/infrastructure/chunking/code-aware-chunker.js +0 -397
- package/dist/infrastructure/context/context-compressor.js +0 -329
- package/dist/infrastructure/context/conversation-context.js +0 -128
- package/dist/infrastructure/context/session-manager.js +0 -94
- package/dist/infrastructure/cost/cost-tracker.js +0 -360
- package/dist/infrastructure/file-scanner/file-scanner.js +0 -106
- package/dist/infrastructure/governance/nist-ai-rmf.js +0 -292
- package/dist/infrastructure/governance/policy-as-code.js +0 -258
- package/dist/infrastructure/governance/prompt-to-code-lineage.js +0 -239
- package/dist/infrastructure/index.js +0 -7
- package/dist/infrastructure/observability/prompt-versioner.js +0 -145
- package/dist/infrastructure/protocols/a2a-metadata.js +0 -137
- package/dist/infrastructure/protocols/a2a-protocol.js +0 -314
- package/dist/infrastructure/protocols/mcp-oauth.js +0 -184
- package/dist/infrastructure/protocols/mcp-server.js +0 -333
- package/dist/infrastructure/protocols/streaming-handler.js +0 -103
- package/dist/infrastructure/providers/cohere-provider.js +0 -444
- package/dist/infrastructure/providers/fake-provider.js +0 -130
- package/dist/infrastructure/providers/local-llm-provider.js +0 -330
- package/dist/infrastructure/providers/model-config.types.js +0 -9
- package/dist/infrastructure/providers/model-provider.interface.js +0 -8
- package/dist/infrastructure/providers/openai-provider.js +0 -413
- package/dist/infrastructure/providers/openrouter-provider.js +0 -399
- package/dist/infrastructure/providers/operation-provider-resolver.js +0 -105
- package/dist/infrastructure/providers/provider-config-loader.js +0 -120
- package/dist/infrastructure/providers/provider-registry.js +0 -88
- package/dist/infrastructure/safety/pattern-detector.js +0 -133
- package/dist/infrastructure/security/ai-sast-scanner.js +0 -290
- package/dist/infrastructure/security/docker-sandbox.js +0 -178
- package/dist/infrastructure/security/enhanced-security-gate.js +0 -151
- package/dist/infrastructure/security/license-scanner.js +0 -167
- package/dist/infrastructure/security/provider-bias-detector.js +0 -164
- package/dist/infrastructure/security/sandbox-executor.js +0 -64
- package/dist/infrastructure/serialization/toon-serializer.js +0 -119
- package/dist/infrastructure/storage/memory-stream-service.js +0 -204
- package/dist/infrastructure/storage/plan-repository.js +0 -96
- package/dist/infrastructure/storage/sqlite-decision-repository.js +0 -232
- package/dist/infrastructure/storage/sqlite-embedding-repository.js +0 -311
- package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +0 -417
- package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +0 -230
- package/dist/infrastructure/storage/sqlite-memory-repository.js +0 -229
- package/dist/infrastructure/storage/sqlite-pattern-repository.js +0 -249
- package/dist/infrastructure/storage/task-helpers.js +0 -197
- package/dist/infrastructure/telemetry/telemetry-service.js +0 -167
- package/dist/infrastructure/ux/appropriate-friction.js +0 -213
- package/dist/infrastructure/ux/bi-directional-learning.js +0 -337
- package/dist/infrastructure/ux/capability-boundaries.js +0 -42
- package/dist/infrastructure/ux/comprehensive-formatter.js +0 -117
- package/dist/infrastructure/ux/contextual-feature-discovery.js +0 -10
- package/dist/infrastructure/ux/expectation-management.js +0 -327
- package/dist/infrastructure/ux/feature-discovery.js +0 -14
- package/dist/infrastructure/ux/feedback-prompt.js +0 -45
- package/dist/infrastructure/ux/hitl-validation.js +0 -297
- package/dist/infrastructure/ux/progress-indicator.js +0 -116
- package/dist/infrastructure/ux/progressive-disclosure.js +0 -236
- package/dist/infrastructure/ux/review-checkpoint.js +0 -72
- package/dist/infrastructure/ux/staged-feature-intro.js +0 -24
- package/dist/infrastructure/ux/stream-markdown.js +0 -151
- package/dist/infrastructure/ux/syntax-highlighter.js +0 -91
- package/dist/infrastructure/ux/team-standards.js +0 -196
- package/dist/infrastructure/ux/transparency.js +0 -71
- package/dist/infrastructure/validation/agent-feedback.js +0 -55
- package/dist/infrastructure/validation/agent-validation-helper.js +0 -137
- package/dist/infrastructure/validation/review-handler.js +0 -40
- package/dist/infrastructure/validation/summary-aggregator.js +0 -70
- package/dist/infrastructure/validation/summary-extractor.js +0 -45
- package/dist/infrastructure/validation/trace-summary.js +0 -52
- package/dist/infrastructure/verification/verification-service.js +0 -47
- package/dist/infrastructure/xai/attention-visualizer.js +0 -172
- package/dist/infrastructure/xai/cot-visualizer.js +0 -283
- package/dist/infrastructure/xai/decision-tree-log.js +0 -212
- package/dist/infrastructure/xai/interactive-xai.js +0 -260
- package/dist/infrastructure/xai/uncertainty-quantifier.js +0 -198
- package/dist/intelligent-retrieval.js +0 -272
- package/dist/intent/classifier.js +0 -2
- package/dist/intent/context.js +0 -2
- package/dist/iterative-refinement.js +0 -189
- package/dist/learning.js +0 -232
- package/dist/log.js +0 -31
- package/dist/migrate.js +0 -133
- package/dist/parallel-processor.js +0 -530
- package/dist/planner.js +0 -198
- package/dist/policy.js +0 -26
- package/dist/presentation/cli/commands/ask-command.js +0 -314
- package/dist/presentation/cli/commands/cost-command.js +0 -191
- package/dist/presentation/cli/commands/decision-command.js +0 -207
- package/dist/presentation/cli/commands/docs-command.js +0 -25
- package/dist/presentation/cli/commands/fix-command.js +0 -53
- package/dist/presentation/cli/commands/knowledge-command.js +0 -129
- package/dist/presentation/cli/commands/learning-dashboard-command.js +0 -183
- package/dist/presentation/cli/commands/models-command.js +0 -194
- package/dist/presentation/cli/commands/orchestrate-command.js +0 -207
- package/dist/presentation/cli/commands/plan-command.js +0 -246
- package/dist/presentation/cli/commands/product-command.js +0 -199
- package/dist/presentation/cli/commands/react-command.js +0 -181
- package/dist/presentation/cli/commands/review-command.js +0 -154
- package/dist/presentation/cli/commands/run-command.js +0 -188
- package/dist/presentation/cli/commands/smart-command.js +0 -395
- package/dist/presentation/cli/commands/suggest-command.js +0 -138
- package/dist/presentation/cli/commands/trace-command.js +0 -129
- package/dist/presentation/cli/commands/undo-command.js +0 -150
- package/dist/query-optimizer.js +0 -205
- package/dist/refactor.js +0 -116
- package/dist/review.js +0 -206
- package/dist/search.js +0 -163
- package/dist/session.js +0 -652
- package/dist/task-verification.js +0 -336
- package/dist/testgen.js +0 -166
- package/dist/token-optimizer.js +0 -277
- package/dist/tools/bash.js +0 -213
- package/dist/tools/edit.js +0 -235
- package/dist/tools/executor.js +0 -153
- package/dist/tools/git-tool.js +0 -292
- package/dist/tools/parser.js +0 -158
- package/dist/tools/registry.js +0 -302
- package/dist/tools/search.js +0 -100
- package/dist/types.js +0 -2
- package/dist/utils/check-api-status.js +0 -100
- package/dist/utils/diff-parser.js +0 -162
- package/dist/verification/backup.js +0 -259
- package/dist/verification/compiler.js +0 -264
- package/dist/verification/index.js +0 -273
- 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
|