@oculum/scanner 1.0.9 → 1.0.11
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/dist/baseline/diff.d.ts +32 -0
- package/dist/baseline/diff.d.ts.map +1 -0
- package/dist/baseline/diff.js +119 -0
- package/dist/baseline/diff.js.map +1 -0
- package/dist/baseline/index.d.ts +9 -0
- package/dist/baseline/index.d.ts.map +1 -0
- package/dist/baseline/index.js +19 -0
- package/dist/baseline/index.js.map +1 -0
- package/dist/baseline/manager.d.ts +67 -0
- package/dist/baseline/manager.d.ts.map +1 -0
- package/dist/baseline/manager.js +180 -0
- package/dist/baseline/manager.js.map +1 -0
- package/dist/baseline/types.d.ts +91 -0
- package/dist/baseline/types.d.ts.map +1 -0
- package/dist/baseline/types.js +12 -0
- package/dist/baseline/types.js.map +1 -0
- package/dist/formatters/cli-terminal.d.ts +38 -0
- package/dist/formatters/cli-terminal.d.ts.map +1 -1
- package/dist/formatters/cli-terminal.js +365 -42
- package/dist/formatters/cli-terminal.js.map +1 -1
- package/dist/formatters/github-comment.d.ts +1 -1
- package/dist/formatters/github-comment.d.ts.map +1 -1
- package/dist/formatters/github-comment.js +75 -11
- package/dist/formatters/github-comment.js.map +1 -1
- package/dist/formatters/index.d.ts +1 -1
- package/dist/formatters/index.d.ts.map +1 -1
- package/dist/formatters/index.js +4 -1
- package/dist/formatters/index.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +155 -16
- package/dist/index.js.map +1 -1
- package/dist/layer1/config-audit.d.ts.map +1 -1
- package/dist/layer1/config-audit.js +20 -3
- package/dist/layer1/config-audit.js.map +1 -1
- package/dist/layer1/config-mcp-audit.d.ts +20 -0
- package/dist/layer1/config-mcp-audit.d.ts.map +1 -0
- package/dist/layer1/config-mcp-audit.js +239 -0
- package/dist/layer1/config-mcp-audit.js.map +1 -0
- package/dist/layer1/index.d.ts +1 -0
- package/dist/layer1/index.d.ts.map +1 -1
- package/dist/layer1/index.js +9 -1
- package/dist/layer1/index.js.map +1 -1
- package/dist/layer2/ai-agent-tools.d.ts.map +1 -1
- package/dist/layer2/ai-agent-tools.js +303 -0
- package/dist/layer2/ai-agent-tools.js.map +1 -1
- package/dist/layer2/ai-endpoint-protection.d.ts.map +1 -1
- package/dist/layer2/ai-endpoint-protection.js +17 -3
- package/dist/layer2/ai-endpoint-protection.js.map +1 -1
- package/dist/layer2/ai-execution-sinks.d.ts.map +1 -1
- package/dist/layer2/ai-execution-sinks.js +462 -12
- package/dist/layer2/ai-execution-sinks.js.map +1 -1
- package/dist/layer2/ai-fingerprinting.d.ts.map +1 -1
- package/dist/layer2/ai-fingerprinting.js +3 -0
- package/dist/layer2/ai-fingerprinting.js.map +1 -1
- package/dist/layer2/ai-mcp-security.d.ts +17 -0
- package/dist/layer2/ai-mcp-security.d.ts.map +1 -0
- package/dist/layer2/ai-mcp-security.js +679 -0
- package/dist/layer2/ai-mcp-security.js.map +1 -0
- package/dist/layer2/ai-package-hallucination.d.ts +19 -0
- package/dist/layer2/ai-package-hallucination.d.ts.map +1 -0
- package/dist/layer2/ai-package-hallucination.js +696 -0
- package/dist/layer2/ai-package-hallucination.js.map +1 -0
- package/dist/layer2/ai-prompt-hygiene.d.ts.map +1 -1
- package/dist/layer2/ai-prompt-hygiene.js +495 -9
- package/dist/layer2/ai-prompt-hygiene.js.map +1 -1
- package/dist/layer2/ai-rag-safety.d.ts.map +1 -1
- package/dist/layer2/ai-rag-safety.js +372 -1
- package/dist/layer2/ai-rag-safety.js.map +1 -1
- package/dist/layer2/auth-antipatterns.d.ts.map +1 -1
- package/dist/layer2/auth-antipatterns.js +4 -0
- package/dist/layer2/auth-antipatterns.js.map +1 -1
- package/dist/layer2/byok-patterns.d.ts.map +1 -1
- package/dist/layer2/byok-patterns.js +3 -0
- package/dist/layer2/byok-patterns.js.map +1 -1
- package/dist/layer2/dangerous-functions/child-process.d.ts +16 -0
- package/dist/layer2/dangerous-functions/child-process.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/child-process.js +74 -0
- package/dist/layer2/dangerous-functions/child-process.js.map +1 -0
- package/dist/layer2/dangerous-functions/dom-xss.d.ts +29 -0
- package/dist/layer2/dangerous-functions/dom-xss.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/dom-xss.js +179 -0
- package/dist/layer2/dangerous-functions/dom-xss.js.map +1 -0
- package/dist/layer2/dangerous-functions/index.d.ts +13 -0
- package/dist/layer2/dangerous-functions/index.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/index.js +621 -0
- package/dist/layer2/dangerous-functions/index.js.map +1 -0
- package/dist/layer2/dangerous-functions/json-parse.d.ts +31 -0
- package/dist/layer2/dangerous-functions/json-parse.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/json-parse.js +319 -0
- package/dist/layer2/dangerous-functions/json-parse.js.map +1 -0
- package/dist/layer2/dangerous-functions/math-random.d.ts +61 -0
- package/dist/layer2/dangerous-functions/math-random.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/math-random.js +459 -0
- package/dist/layer2/dangerous-functions/math-random.js.map +1 -0
- package/dist/layer2/dangerous-functions/patterns.d.ts +21 -0
- package/dist/layer2/dangerous-functions/patterns.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/patterns.js +161 -0
- package/dist/layer2/dangerous-functions/patterns.js.map +1 -0
- package/dist/layer2/dangerous-functions/request-validation.d.ts +13 -0
- package/dist/layer2/dangerous-functions/request-validation.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/request-validation.js +119 -0
- package/dist/layer2/dangerous-functions/request-validation.js.map +1 -0
- package/dist/layer2/dangerous-functions/utils/control-flow.d.ts +23 -0
- package/dist/layer2/dangerous-functions/utils/control-flow.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/utils/control-flow.js +149 -0
- package/dist/layer2/dangerous-functions/utils/control-flow.js.map +1 -0
- package/dist/layer2/dangerous-functions/utils/helpers.d.ts +31 -0
- package/dist/layer2/dangerous-functions/utils/helpers.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/utils/helpers.js +124 -0
- package/dist/layer2/dangerous-functions/utils/helpers.js.map +1 -0
- package/dist/layer2/dangerous-functions/utils/index.d.ts +9 -0
- package/dist/layer2/dangerous-functions/utils/index.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/utils/index.js +23 -0
- package/dist/layer2/dangerous-functions/utils/index.js.map +1 -0
- package/dist/layer2/dangerous-functions/utils/schema-validation.d.ts +22 -0
- package/dist/layer2/dangerous-functions/utils/schema-validation.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/utils/schema-validation.js +89 -0
- package/dist/layer2/dangerous-functions/utils/schema-validation.js.map +1 -0
- package/dist/layer2/data-exposure.d.ts.map +1 -1
- package/dist/layer2/data-exposure.js +3 -0
- package/dist/layer2/data-exposure.js.map +1 -1
- package/dist/layer2/framework-checks.d.ts.map +1 -1
- package/dist/layer2/framework-checks.js +3 -0
- package/dist/layer2/framework-checks.js.map +1 -1
- package/dist/layer2/index.d.ts +3 -0
- package/dist/layer2/index.d.ts.map +1 -1
- package/dist/layer2/index.js +61 -2
- package/dist/layer2/index.js.map +1 -1
- package/dist/layer2/logic-gates.d.ts.map +1 -1
- package/dist/layer2/logic-gates.js +4 -0
- package/dist/layer2/logic-gates.js.map +1 -1
- package/dist/layer2/model-supply-chain.d.ts +20 -0
- package/dist/layer2/model-supply-chain.d.ts.map +1 -0
- package/dist/layer2/model-supply-chain.js +376 -0
- package/dist/layer2/model-supply-chain.js.map +1 -0
- package/dist/layer2/risky-imports.d.ts.map +1 -1
- package/dist/layer2/risky-imports.js +4 -0
- package/dist/layer2/risky-imports.js.map +1 -1
- package/dist/layer2/variables.d.ts.map +1 -1
- package/dist/layer2/variables.js +4 -0
- package/dist/layer2/variables.js.map +1 -1
- package/dist/layer3/anthropic/auto-dismiss.d.ts +24 -0
- package/dist/layer3/anthropic/auto-dismiss.d.ts.map +1 -0
- package/dist/layer3/anthropic/auto-dismiss.js +188 -0
- package/dist/layer3/anthropic/auto-dismiss.js.map +1 -0
- package/dist/layer3/anthropic/clients.d.ts +44 -0
- package/dist/layer3/anthropic/clients.d.ts.map +1 -0
- package/dist/layer3/anthropic/clients.js +81 -0
- package/dist/layer3/anthropic/clients.js.map +1 -0
- package/dist/layer3/anthropic/index.d.ts +41 -0
- package/dist/layer3/anthropic/index.d.ts.map +1 -0
- package/dist/layer3/anthropic/index.js +141 -0
- package/dist/layer3/anthropic/index.js.map +1 -0
- package/dist/layer3/anthropic/prompts/index.d.ts +8 -0
- package/dist/layer3/anthropic/prompts/index.d.ts.map +1 -0
- package/dist/layer3/anthropic/prompts/index.js +14 -0
- package/dist/layer3/anthropic/prompts/index.js.map +1 -0
- package/dist/layer3/anthropic/prompts/semantic-analysis.d.ts +15 -0
- package/dist/layer3/anthropic/prompts/semantic-analysis.d.ts.map +1 -0
- package/dist/layer3/anthropic/prompts/semantic-analysis.js +169 -0
- package/dist/layer3/anthropic/prompts/semantic-analysis.js.map +1 -0
- package/dist/layer3/anthropic/prompts/validation.d.ts +12 -0
- package/dist/layer3/anthropic/prompts/validation.d.ts.map +1 -0
- package/dist/layer3/anthropic/prompts/validation.js +421 -0
- package/dist/layer3/anthropic/prompts/validation.js.map +1 -0
- package/dist/layer3/anthropic/providers/anthropic.d.ts +21 -0
- package/dist/layer3/anthropic/providers/anthropic.d.ts.map +1 -0
- package/dist/layer3/anthropic/providers/anthropic.js +266 -0
- package/dist/layer3/anthropic/providers/anthropic.js.map +1 -0
- package/dist/layer3/anthropic/providers/index.d.ts +8 -0
- package/dist/layer3/anthropic/providers/index.d.ts.map +1 -0
- package/dist/layer3/anthropic/providers/index.js +15 -0
- package/dist/layer3/anthropic/providers/index.js.map +1 -0
- package/dist/layer3/anthropic/providers/openai.d.ts +18 -0
- package/dist/layer3/anthropic/providers/openai.d.ts.map +1 -0
- package/dist/layer3/anthropic/providers/openai.js +340 -0
- package/dist/layer3/anthropic/providers/openai.js.map +1 -0
- package/dist/layer3/anthropic/request-builder.d.ts +20 -0
- package/dist/layer3/anthropic/request-builder.d.ts.map +1 -0
- package/dist/layer3/anthropic/request-builder.js +134 -0
- package/dist/layer3/anthropic/request-builder.js.map +1 -0
- package/dist/layer3/anthropic/types.d.ts +88 -0
- package/dist/layer3/anthropic/types.d.ts.map +1 -0
- package/dist/layer3/anthropic/types.js +38 -0
- package/dist/layer3/anthropic/types.js.map +1 -0
- package/dist/layer3/anthropic/utils/index.d.ts +9 -0
- package/dist/layer3/anthropic/utils/index.d.ts.map +1 -0
- package/dist/layer3/anthropic/utils/index.js +24 -0
- package/dist/layer3/anthropic/utils/index.js.map +1 -0
- package/dist/layer3/anthropic/utils/path-helpers.d.ts +21 -0
- package/dist/layer3/anthropic/utils/path-helpers.d.ts.map +1 -0
- package/dist/layer3/anthropic/utils/path-helpers.js +69 -0
- package/dist/layer3/anthropic/utils/path-helpers.js.map +1 -0
- package/dist/layer3/anthropic/utils/response-parser.d.ts +40 -0
- package/dist/layer3/anthropic/utils/response-parser.d.ts.map +1 -0
- package/dist/layer3/anthropic/utils/response-parser.js +285 -0
- package/dist/layer3/anthropic/utils/response-parser.js.map +1 -0
- package/dist/layer3/anthropic/utils/retry.d.ts +15 -0
- package/dist/layer3/anthropic/utils/retry.d.ts.map +1 -0
- package/dist/layer3/anthropic/utils/retry.js +62 -0
- package/dist/layer3/anthropic/utils/retry.js.map +1 -0
- package/dist/layer3/index.d.ts +1 -0
- package/dist/layer3/index.d.ts.map +1 -1
- package/dist/layer3/index.js +16 -6
- package/dist/layer3/index.js.map +1 -1
- package/dist/layer3/osv-check.d.ts +75 -0
- package/dist/layer3/osv-check.d.ts.map +1 -0
- package/dist/layer3/osv-check.js +308 -0
- package/dist/layer3/osv-check.js.map +1 -0
- package/dist/rules/framework-fixes.d.ts +48 -0
- package/dist/rules/framework-fixes.d.ts.map +1 -0
- package/dist/rules/framework-fixes.js +439 -0
- package/dist/rules/framework-fixes.js.map +1 -0
- package/dist/rules/index.d.ts +8 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +18 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/metadata.d.ts +43 -0
- package/dist/rules/metadata.d.ts.map +1 -0
- package/dist/rules/metadata.js +734 -0
- package/dist/rules/metadata.js.map +1 -0
- package/dist/suppression/config-loader.d.ts +74 -0
- package/dist/suppression/config-loader.d.ts.map +1 -0
- package/dist/suppression/config-loader.js +424 -0
- package/dist/suppression/config-loader.js.map +1 -0
- package/dist/suppression/hash.d.ts +48 -0
- package/dist/suppression/hash.d.ts.map +1 -0
- package/dist/suppression/hash.js +88 -0
- package/dist/suppression/hash.js.map +1 -0
- package/dist/suppression/index.d.ts +11 -0
- package/dist/suppression/index.d.ts.map +1 -0
- package/dist/suppression/index.js +39 -0
- package/dist/suppression/index.js.map +1 -0
- package/dist/suppression/inline-parser.d.ts +39 -0
- package/dist/suppression/inline-parser.d.ts.map +1 -0
- package/dist/suppression/inline-parser.js +218 -0
- package/dist/suppression/inline-parser.js.map +1 -0
- package/dist/suppression/manager.d.ts +94 -0
- package/dist/suppression/manager.d.ts.map +1 -0
- package/dist/suppression/manager.js +292 -0
- package/dist/suppression/manager.js.map +1 -0
- package/dist/suppression/types.d.ts +151 -0
- package/dist/suppression/types.d.ts.map +1 -0
- package/dist/suppression/types.js +28 -0
- package/dist/suppression/types.js.map +1 -0
- package/dist/tiers.d.ts +1 -1
- package/dist/tiers.d.ts.map +1 -1
- package/dist/tiers.js +27 -0
- package/dist/tiers.js.map +1 -1
- package/dist/types.d.ts +62 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/context-helpers.d.ts +4 -0
- package/dist/utils/context-helpers.d.ts.map +1 -1
- package/dist/utils/context-helpers.js +13 -9
- package/dist/utils/context-helpers.js.map +1 -1
- package/package.json +4 -2
- package/src/__tests__/benchmark/fixtures/layer1/mcp-config-audit.json +31 -0
- package/src/__tests__/benchmark/fixtures/layer2/ai-execution-sinks.ts +1489 -82
- package/src/__tests__/benchmark/fixtures/layer2/ai-mcp-security.ts +495 -0
- package/src/__tests__/benchmark/fixtures/layer2/ai-package-hallucination.ts +255 -0
- package/src/__tests__/benchmark/fixtures/layer2/ai-prompt-hygiene.ts +300 -1
- package/src/__tests__/benchmark/fixtures/layer2/ai-rag-safety.ts +139 -0
- package/src/__tests__/benchmark/fixtures/layer2/byok-patterns.ts +7 -0
- package/src/__tests__/benchmark/fixtures/layer2/data-exposure.ts +63 -0
- package/src/__tests__/benchmark/fixtures/layer2/excessive-agency.ts +221 -0
- package/src/__tests__/benchmark/fixtures/layer2/index.ts +18 -0
- package/src/__tests__/benchmark/fixtures/layer2/model-supply-chain.ts +204 -0
- package/src/__tests__/benchmark/fixtures/layer2/phase1-enhancements.ts +157 -0
- package/src/__tests__/snapshots/__snapshots__/anthropic-validation-refactor.test.ts.snap +758 -0
- package/src/__tests__/snapshots/__snapshots__/dangerous-functions-refactor.test.ts.snap +503 -0
- package/src/__tests__/snapshots/anthropic-validation-refactor.test.ts +321 -0
- package/src/__tests__/snapshots/dangerous-functions-refactor.test.ts +439 -0
- package/src/baseline/__tests__/diff.test.ts +261 -0
- package/src/baseline/__tests__/manager.test.ts +225 -0
- package/src/baseline/diff.ts +135 -0
- package/src/baseline/index.ts +29 -0
- package/src/baseline/manager.ts +230 -0
- package/src/baseline/types.ts +97 -0
- package/src/formatters/cli-terminal.ts +444 -41
- package/src/formatters/github-comment.ts +79 -11
- package/src/formatters/index.ts +4 -0
- package/src/index.ts +197 -14
- package/src/layer1/config-audit.ts +24 -3
- package/src/layer1/config-mcp-audit.ts +276 -0
- package/src/layer1/index.ts +16 -6
- package/src/layer2/ai-agent-tools.ts +336 -0
- package/src/layer2/ai-endpoint-protection.ts +16 -3
- package/src/layer2/ai-execution-sinks.ts +516 -12
- package/src/layer2/ai-fingerprinting.ts +5 -1
- package/src/layer2/ai-mcp-security.ts +730 -0
- package/src/layer2/ai-package-hallucination.ts +791 -0
- package/src/layer2/ai-prompt-hygiene.ts +547 -9
- package/src/layer2/ai-rag-safety.ts +382 -3
- package/src/layer2/auth-antipatterns.ts +5 -0
- package/src/layer2/byok-patterns.ts +5 -1
- package/src/layer2/dangerous-functions/child-process.ts +98 -0
- package/src/layer2/dangerous-functions/dom-xss.ts +220 -0
- package/src/layer2/dangerous-functions/index.ts +949 -0
- package/src/layer2/dangerous-functions/json-parse.ts +385 -0
- package/src/layer2/dangerous-functions/math-random.ts +537 -0
- package/src/layer2/dangerous-functions/patterns.ts +174 -0
- package/src/layer2/dangerous-functions/request-validation.ts +145 -0
- package/src/layer2/dangerous-functions/utils/control-flow.ts +162 -0
- package/src/layer2/dangerous-functions/utils/helpers.ts +170 -0
- package/src/layer2/dangerous-functions/utils/index.ts +25 -0
- package/src/layer2/dangerous-functions/utils/schema-validation.ts +91 -0
- package/src/layer2/data-exposure.ts +5 -1
- package/src/layer2/framework-checks.ts +5 -0
- package/src/layer2/index.ts +63 -1
- package/src/layer2/logic-gates.ts +5 -0
- package/src/layer2/model-supply-chain.ts +456 -0
- package/src/layer2/risky-imports.ts +5 -0
- package/src/layer2/variables.ts +5 -0
- package/src/layer3/__tests__/osv-check.test.ts +384 -0
- package/src/layer3/anthropic/auto-dismiss.ts +212 -0
- package/src/layer3/anthropic/clients.ts +84 -0
- package/src/layer3/anthropic/index.ts +170 -0
- package/src/layer3/anthropic/prompts/index.ts +14 -0
- package/src/layer3/anthropic/prompts/semantic-analysis.ts +173 -0
- package/src/layer3/anthropic/prompts/validation.ts +419 -0
- package/src/layer3/anthropic/providers/anthropic.ts +310 -0
- package/src/layer3/anthropic/providers/index.ts +8 -0
- package/src/layer3/anthropic/providers/openai.ts +384 -0
- package/src/layer3/anthropic/request-builder.ts +150 -0
- package/src/layer3/anthropic/types.ts +148 -0
- package/src/layer3/anthropic/utils/index.ts +26 -0
- package/src/layer3/anthropic/utils/path-helpers.ts +68 -0
- package/src/layer3/anthropic/utils/response-parser.ts +322 -0
- package/src/layer3/anthropic/utils/retry.ts +75 -0
- package/src/layer3/index.ts +18 -5
- package/src/layer3/osv-check.ts +420 -0
- package/src/rules/__tests__/framework-fixes.test.ts +689 -0
- package/src/rules/__tests__/metadata.test.ts +218 -0
- package/src/rules/framework-fixes.ts +470 -0
- package/src/rules/index.ts +21 -0
- package/src/rules/metadata.ts +831 -0
- package/src/suppression/__tests__/config-loader.test.ts +382 -0
- package/src/suppression/__tests__/hash.test.ts +166 -0
- package/src/suppression/__tests__/inline-parser.test.ts +212 -0
- package/src/suppression/__tests__/manager.test.ts +415 -0
- package/src/suppression/config-loader.ts +462 -0
- package/src/suppression/hash.ts +95 -0
- package/src/suppression/index.ts +51 -0
- package/src/suppression/inline-parser.ts +273 -0
- package/src/suppression/manager.ts +379 -0
- package/src/suppression/types.ts +174 -0
- package/src/tiers.ts +36 -0
- package/src/types.ts +90 -0
- package/src/utils/context-helpers.ts +13 -9
- package/dist/layer2/dangerous-functions.d.ts +0 -7
- package/dist/layer2/dangerous-functions.d.ts.map +0 -1
- package/dist/layer2/dangerous-functions.js +0 -1701
- package/dist/layer2/dangerous-functions.js.map +0 -1
- package/dist/layer3/anthropic.d.ts +0 -87
- package/dist/layer3/anthropic.d.ts.map +0 -1
- package/dist/layer3/anthropic.js +0 -1948
- package/dist/layer3/anthropic.js.map +0 -1
- package/dist/layer3/openai.d.ts +0 -25
- package/dist/layer3/openai.d.ts.map +0 -1
- package/dist/layer3/openai.js +0 -238
- package/dist/layer3/openai.js.map +0 -1
- package/src/layer2/dangerous-functions.ts +0 -1940
- package/src/layer3/anthropic.ts +0 -2257
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Type definitions for AI validation module
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createStatsAccumulator = createStatsAccumulator;
|
|
7
|
+
exports.createInitialStats = createInitialStats;
|
|
8
|
+
function createStatsAccumulator() {
|
|
9
|
+
return {
|
|
10
|
+
apiCalls: 0,
|
|
11
|
+
estimatedInputTokens: 0,
|
|
12
|
+
estimatedOutputTokens: 0,
|
|
13
|
+
cacheReadTokens: 0,
|
|
14
|
+
estimatedCost: 0,
|
|
15
|
+
validatedFindings: 0,
|
|
16
|
+
confirmedFindings: 0,
|
|
17
|
+
dismissedFindings: 0,
|
|
18
|
+
downgradedFindings: 0,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function createInitialStats(totalFindings) {
|
|
22
|
+
return {
|
|
23
|
+
totalFindings,
|
|
24
|
+
validatedFindings: 0,
|
|
25
|
+
confirmedFindings: 0,
|
|
26
|
+
dismissedFindings: 0,
|
|
27
|
+
downgradedFindings: 0,
|
|
28
|
+
autoDismissedFindings: 0,
|
|
29
|
+
estimatedInputTokens: 0,
|
|
30
|
+
estimatedOutputTokens: 0,
|
|
31
|
+
estimatedCost: 0,
|
|
32
|
+
apiCalls: 0,
|
|
33
|
+
cacheCreationTokens: 0,
|
|
34
|
+
cacheReadTokens: 0,
|
|
35
|
+
cacheHitRate: 0,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/layer3/anthropic/types.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAmHH,wDAYC;AAED,gDAgBC;AA9BD,SAAgB,sBAAsB;IACpC,OAAO;QACL,QAAQ,EAAE,CAAC;QACX,oBAAoB,EAAE,CAAC;QACvB,qBAAqB,EAAE,CAAC;QACxB,eAAe,EAAE,CAAC;QAClB,aAAa,EAAE,CAAC;QAChB,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,kBAAkB,EAAE,CAAC;KACtB,CAAA;AACH,CAAC;AAED,SAAgB,kBAAkB,CAAC,aAAqB;IACtD,OAAO;QACL,aAAa;QACb,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,kBAAkB,EAAE,CAAC;QACrB,qBAAqB,EAAE,CAAC;QACxB,oBAAoB,EAAE,CAAC;QACvB,qBAAqB,EAAE,CAAC;QACxB,aAAa,EAAE,CAAC;QAChB,QAAQ,EAAE,CAAC;QACX,mBAAmB,EAAE,CAAC;QACtB,eAAe,EAAE,CAAC;QAClB,YAAY,EAAE,CAAC;KAChB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility Functions Index
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all utility functions from the anthropic module.
|
|
5
|
+
*/
|
|
6
|
+
export { normalizePathForComparison, findMatchingFilePath, getLanguageFromPath, } from './path-helpers';
|
|
7
|
+
export { makeAnthropicRequestWithRetry, makeOpenAIRequestWithRetry, } from './retry';
|
|
8
|
+
export { parseAIResponse, parseValidationResponse, parseMultiFileValidationResponse, applyValidationResults, validateSeverity, validateCategory, getLineContent, } from './response-parser';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/layer3/anthropic/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,SAAS,CAAA;AAEhB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,gCAAgC,EAChC,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility Functions Index
|
|
4
|
+
*
|
|
5
|
+
* Re-exports all utility functions from the anthropic module.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getLineContent = exports.validateCategory = exports.validateSeverity = exports.applyValidationResults = exports.parseMultiFileValidationResponse = exports.parseValidationResponse = exports.parseAIResponse = exports.makeOpenAIRequestWithRetry = exports.makeAnthropicRequestWithRetry = exports.getLanguageFromPath = exports.findMatchingFilePath = exports.normalizePathForComparison = void 0;
|
|
9
|
+
var path_helpers_1 = require("./path-helpers");
|
|
10
|
+
Object.defineProperty(exports, "normalizePathForComparison", { enumerable: true, get: function () { return path_helpers_1.normalizePathForComparison; } });
|
|
11
|
+
Object.defineProperty(exports, "findMatchingFilePath", { enumerable: true, get: function () { return path_helpers_1.findMatchingFilePath; } });
|
|
12
|
+
Object.defineProperty(exports, "getLanguageFromPath", { enumerable: true, get: function () { return path_helpers_1.getLanguageFromPath; } });
|
|
13
|
+
var retry_1 = require("./retry");
|
|
14
|
+
Object.defineProperty(exports, "makeAnthropicRequestWithRetry", { enumerable: true, get: function () { return retry_1.makeAnthropicRequestWithRetry; } });
|
|
15
|
+
Object.defineProperty(exports, "makeOpenAIRequestWithRetry", { enumerable: true, get: function () { return retry_1.makeOpenAIRequestWithRetry; } });
|
|
16
|
+
var response_parser_1 = require("./response-parser");
|
|
17
|
+
Object.defineProperty(exports, "parseAIResponse", { enumerable: true, get: function () { return response_parser_1.parseAIResponse; } });
|
|
18
|
+
Object.defineProperty(exports, "parseValidationResponse", { enumerable: true, get: function () { return response_parser_1.parseValidationResponse; } });
|
|
19
|
+
Object.defineProperty(exports, "parseMultiFileValidationResponse", { enumerable: true, get: function () { return response_parser_1.parseMultiFileValidationResponse; } });
|
|
20
|
+
Object.defineProperty(exports, "applyValidationResults", { enumerable: true, get: function () { return response_parser_1.applyValidationResults; } });
|
|
21
|
+
Object.defineProperty(exports, "validateSeverity", { enumerable: true, get: function () { return response_parser_1.validateSeverity; } });
|
|
22
|
+
Object.defineProperty(exports, "validateCategory", { enumerable: true, get: function () { return response_parser_1.validateCategory; } });
|
|
23
|
+
Object.defineProperty(exports, "getLineContent", { enumerable: true, get: function () { return response_parser_1.getLineContent; } });
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layer3/anthropic/utils/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,+CAIuB;AAHrB,0HAAA,0BAA0B,OAAA;AAC1B,oHAAA,oBAAoB,OAAA;AACpB,mHAAA,mBAAmB,OAAA;AAGrB,iCAGgB;AAFd,sHAAA,6BAA6B,OAAA;AAC7B,mHAAA,0BAA0B,OAAA;AAG5B,qDAQ0B;AAPxB,kHAAA,eAAe,OAAA;AACf,0HAAA,uBAAuB,OAAA;AACvB,mIAAA,gCAAgC,OAAA;AAChC,yHAAA,sBAAsB,OAAA;AACtB,mHAAA,gBAAgB,OAAA;AAChB,mHAAA,gBAAgB,OAAA;AAChB,iHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path Normalization Helpers
|
|
3
|
+
*
|
|
4
|
+
* Functions for normalizing and matching file paths in AI responses.
|
|
5
|
+
* AI models may return paths in different formats than expected.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Normalize a file path for comparison purposes.
|
|
9
|
+
* Handles common variations: ./src/file.ts, src/file.ts, /src/file.ts
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizePathForComparison(path: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Find a matching file path from expected paths, handling path format variations.
|
|
14
|
+
* AI responses may use different path formats than what we sent.
|
|
15
|
+
*/
|
|
16
|
+
export declare function findMatchingFilePath(responsePath: string, expectedPaths: string[]): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Get language identifier from file path extension
|
|
19
|
+
*/
|
|
20
|
+
export declare function getLanguageFromPath(path: string): string;
|
|
21
|
+
//# sourceMappingURL=path-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-helpers.d.ts","sourceRoot":"","sources":["../../../../src/layer3/anthropic/utils/path-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAsBjG;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkBxD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Path Normalization Helpers
|
|
4
|
+
*
|
|
5
|
+
* Functions for normalizing and matching file paths in AI responses.
|
|
6
|
+
* AI models may return paths in different formats than expected.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.normalizePathForComparison = normalizePathForComparison;
|
|
10
|
+
exports.findMatchingFilePath = findMatchingFilePath;
|
|
11
|
+
exports.getLanguageFromPath = getLanguageFromPath;
|
|
12
|
+
/**
|
|
13
|
+
* Normalize a file path for comparison purposes.
|
|
14
|
+
* Handles common variations: ./src/file.ts, src/file.ts, /src/file.ts
|
|
15
|
+
*/
|
|
16
|
+
function normalizePathForComparison(path) {
|
|
17
|
+
return path
|
|
18
|
+
.replace(/^\.\//, '') // Remove leading ./
|
|
19
|
+
.replace(/^\//, '') // Remove leading /
|
|
20
|
+
.replace(/\\/g, '/'); // Normalize Windows backslashes
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Find a matching file path from expected paths, handling path format variations.
|
|
24
|
+
* AI responses may use different path formats than what we sent.
|
|
25
|
+
*/
|
|
26
|
+
function findMatchingFilePath(responsePath, expectedPaths) {
|
|
27
|
+
// Exact match first
|
|
28
|
+
if (expectedPaths.includes(responsePath))
|
|
29
|
+
return responsePath;
|
|
30
|
+
// Normalized match
|
|
31
|
+
const normalized = normalizePathForComparison(responsePath);
|
|
32
|
+
for (const expected of expectedPaths) {
|
|
33
|
+
if (normalizePathForComparison(expected) === normalized) {
|
|
34
|
+
console.log(`[AI Validation] Path fuzzy matched: "${responsePath}" -> "${expected}"`);
|
|
35
|
+
return expected;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Basename match (only if unique) - handles cases like "file.ts" matching "src/api/file.ts"
|
|
39
|
+
const basename = responsePath.split('/').pop() || responsePath;
|
|
40
|
+
const matches = expectedPaths.filter(p => (p.split('/').pop() || p) === basename);
|
|
41
|
+
if (matches.length === 1) {
|
|
42
|
+
console.log(`[AI Validation] Path basename matched: "${responsePath}" -> "${matches[0]}"`);
|
|
43
|
+
return matches[0];
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get language identifier from file path extension
|
|
49
|
+
*/
|
|
50
|
+
function getLanguageFromPath(path) {
|
|
51
|
+
const ext = path.split('.').pop()?.toLowerCase();
|
|
52
|
+
const langMap = {
|
|
53
|
+
ts: 'typescript',
|
|
54
|
+
tsx: 'tsx',
|
|
55
|
+
js: 'javascript',
|
|
56
|
+
jsx: 'jsx',
|
|
57
|
+
py: 'python',
|
|
58
|
+
rb: 'ruby',
|
|
59
|
+
go: 'go',
|
|
60
|
+
java: 'java',
|
|
61
|
+
php: 'php',
|
|
62
|
+
cs: 'csharp',
|
|
63
|
+
json: 'json',
|
|
64
|
+
yaml: 'yaml',
|
|
65
|
+
yml: 'yaml',
|
|
66
|
+
};
|
|
67
|
+
return langMap[ext || ''] || ext || 'text';
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=path-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|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AG,CAAC,2CAA2C,YAAY,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QAC1F,OAAO,OAAO,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,CAAA;IAChD,MAAM,OAAO,GAA2B;QACtC,EAAE,EAAE,YAAY;QAChB,GAAG,EAAE,KAAK;QACV,EAAE,EAAE,YAAY;QAChB,GAAG,EAAE,KAAK;QACV,EAAE,EAAE,QAAQ;QACZ,EAAE,EAAE,MAAM;QACV,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,EAAE,EAAE,QAAQ;QACZ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,MAAM;KACZ,CAAA;IACD,OAAO,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,GAAG,IAAI,MAAM,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Response Parsing Utilities
|
|
3
|
+
*
|
|
4
|
+
* Functions for parsing validation responses from AI models.
|
|
5
|
+
*/
|
|
6
|
+
import type { VulnerabilitySeverity, VulnerabilityCategory, Vulnerability } from '../../../types';
|
|
7
|
+
import type { ValidationResult, AIFinding } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Parse AI response for single file validation
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseAIResponse(response: string): AIFinding[];
|
|
12
|
+
/**
|
|
13
|
+
* Parse single-file validation response
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseValidationResponse(response: string): ValidationResult[];
|
|
16
|
+
/**
|
|
17
|
+
* Parse multi-file validation response (Phase 2)
|
|
18
|
+
* Returns a map of file path -> validation results
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseMultiFileValidationResponse(response: string, expectedFiles: string[]): Map<string, ValidationResult[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Apply validation results to findings
|
|
23
|
+
*/
|
|
24
|
+
export declare function applyValidationResults(findings: Vulnerability[], validationResults: ValidationResult[]): {
|
|
25
|
+
processed: Vulnerability[];
|
|
26
|
+
dismissedCount: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Validate severity value from AI response
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateSeverity(severity: string): VulnerabilitySeverity;
|
|
32
|
+
/**
|
|
33
|
+
* Validate category value from AI response
|
|
34
|
+
*/
|
|
35
|
+
export declare function validateCategory(category: string): VulnerabilityCategory;
|
|
36
|
+
/**
|
|
37
|
+
* Get line content from file content by line number
|
|
38
|
+
*/
|
|
39
|
+
export declare function getLineContent(content: string, lineNumber: number): string;
|
|
40
|
+
//# sourceMappingURL=response-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-parser.d.ts","sourceRoot":"","sources":["../../../../src/layer3/anthropic/utils/response-parser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,aAAa,EAAoB,MAAM,gBAAgB,CAAA;AACnH,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAwD3D;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,CAiC7D;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAkC5E;AAED;;;GAGG;AACH,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,GACtB,GAAG,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAqEjC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,aAAa,EAAE,EACzB,iBAAiB,EAAE,gBAAgB,EAAE,GACpC;IAAE,SAAS,EAAE,aAAa,EAAE,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CA8DxD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,qBAAqB,CAKxE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,qBAAqB,CAYxE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAG1E"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AI Response Parsing Utilities
|
|
4
|
+
*
|
|
5
|
+
* Functions for parsing validation responses from AI models.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.parseAIResponse = parseAIResponse;
|
|
9
|
+
exports.parseValidationResponse = parseValidationResponse;
|
|
10
|
+
exports.parseMultiFileValidationResponse = parseMultiFileValidationResponse;
|
|
11
|
+
exports.applyValidationResults = applyValidationResults;
|
|
12
|
+
exports.validateSeverity = validateSeverity;
|
|
13
|
+
exports.validateCategory = validateCategory;
|
|
14
|
+
exports.getLineContent = getLineContent;
|
|
15
|
+
const path_helpers_1 = require("./path-helpers");
|
|
16
|
+
/**
|
|
17
|
+
* Extract the first top-level JSON array from text.
|
|
18
|
+
* The model may include prose before/after the JSON.
|
|
19
|
+
*/
|
|
20
|
+
function extractTopLevelArray(text) {
|
|
21
|
+
const startIndex = text.indexOf('[');
|
|
22
|
+
if (startIndex === -1)
|
|
23
|
+
return null;
|
|
24
|
+
let depth = 0;
|
|
25
|
+
let inString = false;
|
|
26
|
+
let stringChar = null;
|
|
27
|
+
let escape = false;
|
|
28
|
+
for (let i = startIndex; i < text.length; i++) {
|
|
29
|
+
const ch = text[i];
|
|
30
|
+
if (inString) {
|
|
31
|
+
if (escape) {
|
|
32
|
+
escape = false;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (ch === '\\') {
|
|
36
|
+
escape = true;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (stringChar && ch === stringChar) {
|
|
40
|
+
inString = false;
|
|
41
|
+
stringChar = null;
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (ch === '"' || ch === "'") {
|
|
46
|
+
inString = true;
|
|
47
|
+
stringChar = ch;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (ch === '[') {
|
|
51
|
+
depth++;
|
|
52
|
+
}
|
|
53
|
+
else if (ch === ']') {
|
|
54
|
+
depth--;
|
|
55
|
+
if (depth === 0) {
|
|
56
|
+
return text.slice(startIndex, i + 1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Parse AI response for single file validation
|
|
64
|
+
*/
|
|
65
|
+
function parseAIResponse(response) {
|
|
66
|
+
try {
|
|
67
|
+
// Try to extract JSON from the response
|
|
68
|
+
const jsonMatch = response.match(/\[[\s\S]*\]/);
|
|
69
|
+
if (!jsonMatch) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
73
|
+
// Validate the structure
|
|
74
|
+
if (!Array.isArray(parsed)) {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
return parsed.filter(item => typeof item.lineNumber === 'number' &&
|
|
78
|
+
typeof item.severity === 'string' &&
|
|
79
|
+
typeof item.category === 'string' &&
|
|
80
|
+
typeof item.title === 'string' &&
|
|
81
|
+
typeof item.description === 'string').map(item => ({
|
|
82
|
+
lineNumber: item.lineNumber,
|
|
83
|
+
severity: validateSeverity(item.severity),
|
|
84
|
+
category: validateCategory(item.category),
|
|
85
|
+
title: item.title,
|
|
86
|
+
description: item.description,
|
|
87
|
+
suggestedFix: item.suggestedFix || 'Review and fix the security issue',
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error('Failed to parse AI response:', error);
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parse single-file validation response
|
|
97
|
+
*/
|
|
98
|
+
function parseValidationResponse(response) {
|
|
99
|
+
try {
|
|
100
|
+
const jsonSlice = extractTopLevelArray(response);
|
|
101
|
+
if (!jsonSlice)
|
|
102
|
+
return [];
|
|
103
|
+
const parsed = JSON.parse(jsonSlice);
|
|
104
|
+
if (!Array.isArray(parsed))
|
|
105
|
+
return [];
|
|
106
|
+
return parsed
|
|
107
|
+
.filter(item => typeof item.index === 'number' &&
|
|
108
|
+
typeof item.keep === 'boolean')
|
|
109
|
+
.map(item => {
|
|
110
|
+
// Normalize notes field: prefer new 'notes', fallback to legacy 'reason' or 'validationNotes'
|
|
111
|
+
const notes = item.notes || item.validationNotes || item.reason || undefined;
|
|
112
|
+
return {
|
|
113
|
+
index: item.index,
|
|
114
|
+
keep: item.keep,
|
|
115
|
+
notes,
|
|
116
|
+
adjustedSeverity: item.adjustedSeverity || null,
|
|
117
|
+
// Keep legacy fields for backward compatibility
|
|
118
|
+
reason: item.reason,
|
|
119
|
+
validationNotes: item.validationNotes,
|
|
120
|
+
// Actionable output fields (PRO-82)
|
|
121
|
+
impact: item.impact || undefined,
|
|
122
|
+
fixSuggestion: item.fixSuggestion || undefined,
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error('Failed to parse validation response:', error);
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Parse multi-file validation response (Phase 2)
|
|
133
|
+
* Returns a map of file path -> validation results
|
|
134
|
+
*/
|
|
135
|
+
function parseMultiFileValidationResponse(response, expectedFiles) {
|
|
136
|
+
const resultMap = new Map();
|
|
137
|
+
try {
|
|
138
|
+
const jsonSlice = extractTopLevelArray(response);
|
|
139
|
+
if (!jsonSlice) {
|
|
140
|
+
console.error('[AI Validation] Multi-file: No JSON array found in response');
|
|
141
|
+
return resultMap;
|
|
142
|
+
}
|
|
143
|
+
const parsed = JSON.parse(jsonSlice);
|
|
144
|
+
if (!Array.isArray(parsed)) {
|
|
145
|
+
console.error('[AI Validation] Multi-file: Parsed result is not an array');
|
|
146
|
+
return resultMap;
|
|
147
|
+
}
|
|
148
|
+
// Process each file's results
|
|
149
|
+
for (const fileResult of parsed) {
|
|
150
|
+
if (!fileResult.file || !Array.isArray(fileResult.validations)) {
|
|
151
|
+
console.warn('[AI Validation] Multi-file: Invalid file result structure, skipping');
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
// Use path normalization to match AI response paths to expected paths
|
|
155
|
+
const responsePath = fileResult.file;
|
|
156
|
+
const matchedPath = (0, path_helpers_1.findMatchingFilePath)(responsePath, expectedFiles);
|
|
157
|
+
if (!matchedPath) {
|
|
158
|
+
console.warn(`[AI Validation] Multi-file: Could not match path "${responsePath}" to any expected file`);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const validations = fileResult.validations
|
|
162
|
+
.filter((item) => typeof item.index === 'number' &&
|
|
163
|
+
typeof item.keep === 'boolean')
|
|
164
|
+
.map((item) => {
|
|
165
|
+
// Normalize notes field: prefer new 'notes', fallback to legacy 'reason' or 'validationNotes'
|
|
166
|
+
const notes = item.notes || item.validationNotes || item.reason || undefined;
|
|
167
|
+
return {
|
|
168
|
+
index: item.index,
|
|
169
|
+
keep: item.keep,
|
|
170
|
+
notes,
|
|
171
|
+
adjustedSeverity: item.adjustedSeverity || null,
|
|
172
|
+
// Keep legacy fields for backward compatibility
|
|
173
|
+
reason: item.reason,
|
|
174
|
+
validationNotes: item.validationNotes,
|
|
175
|
+
// Actionable output fields (PRO-82)
|
|
176
|
+
impact: item.impact || undefined,
|
|
177
|
+
fixSuggestion: item.fixSuggestion || undefined,
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
resultMap.set(matchedPath, validations);
|
|
181
|
+
}
|
|
182
|
+
// Log any files that weren't in the response (these will be REJECTED by default)
|
|
183
|
+
const missingFiles = expectedFiles.filter(f => !resultMap.has(f));
|
|
184
|
+
if (missingFiles.length > 0) {
|
|
185
|
+
console.warn(`[AI Validation] Multi-file: Missing ${missingFiles.length} files from response: ${missingFiles.join(', ')}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
console.error('[AI Validation] Multi-file: Failed to parse response:', error);
|
|
190
|
+
}
|
|
191
|
+
return resultMap;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Apply validation results to findings
|
|
195
|
+
*/
|
|
196
|
+
function applyValidationResults(findings, validationResults) {
|
|
197
|
+
const processed = [];
|
|
198
|
+
let dismissedCount = 0;
|
|
199
|
+
for (let i = 0; i < findings.length; i++) {
|
|
200
|
+
const finding = findings[i];
|
|
201
|
+
const validation = validationResults.find(v => v.index === i);
|
|
202
|
+
if (!validation) {
|
|
203
|
+
// No validation result - REJECT by default (conservative approach)
|
|
204
|
+
// If AI doesn't explicitly validate a finding, assume it's a false positive
|
|
205
|
+
console.warn(`[AI Validation] No result for finding ${i}: ${finding.title} - REJECTING`);
|
|
206
|
+
dismissedCount++;
|
|
207
|
+
continue; // Don't add to processed - finding is removed
|
|
208
|
+
}
|
|
209
|
+
if (validation.keep) {
|
|
210
|
+
// Keep the finding
|
|
211
|
+
const adjustedFinding = {
|
|
212
|
+
...finding,
|
|
213
|
+
validatedByAI: true,
|
|
214
|
+
confidence: 'high',
|
|
215
|
+
};
|
|
216
|
+
// Extract notes from optimized or legacy format
|
|
217
|
+
const validationNotes = validation.notes || validation.validationNotes || validation.reason || undefined;
|
|
218
|
+
if (validation.adjustedSeverity && validation.adjustedSeverity !== finding.severity) {
|
|
219
|
+
// Severity was adjusted
|
|
220
|
+
adjustedFinding.originalSeverity = finding.severity;
|
|
221
|
+
adjustedFinding.severity = validation.adjustedSeverity;
|
|
222
|
+
adjustedFinding.validationStatus = 'downgraded';
|
|
223
|
+
adjustedFinding.validationNotes = validationNotes || 'Severity adjusted by AI validation';
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
// Confirmed at original severity
|
|
227
|
+
adjustedFinding.validationStatus = 'confirmed';
|
|
228
|
+
adjustedFinding.validationNotes = validationNotes;
|
|
229
|
+
}
|
|
230
|
+
// Apply AI-generated actionable fields (PRO-82)
|
|
231
|
+
if (validation.impact) {
|
|
232
|
+
adjustedFinding.impact = validation.impact;
|
|
233
|
+
adjustedFinding.aiEnhanced = true;
|
|
234
|
+
}
|
|
235
|
+
if (validation.fixSuggestion) {
|
|
236
|
+
// AI-generated fix becomes the primary fix step
|
|
237
|
+
adjustedFinding.fixSteps = [validation.fixSuggestion];
|
|
238
|
+
adjustedFinding.aiEnhanced = true;
|
|
239
|
+
}
|
|
240
|
+
processed.push(adjustedFinding);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
// Finding was dismissed - only log in debug mode to reduce noise
|
|
244
|
+
if (process.env.DEBUG || process.env.OCULUM_DEBUG) {
|
|
245
|
+
console.log(`[AI Validation] Rejected: ${finding.title} at ${finding.filePath}:${finding.lineNumber}`);
|
|
246
|
+
}
|
|
247
|
+
dismissedCount++;
|
|
248
|
+
// Don't add to processed - finding is removed
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return { processed, dismissedCount };
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Validate severity value from AI response
|
|
255
|
+
*/
|
|
256
|
+
function validateSeverity(severity) {
|
|
257
|
+
const valid = ['critical', 'high', 'medium', 'low', 'info'];
|
|
258
|
+
return valid.includes(severity)
|
|
259
|
+
? severity
|
|
260
|
+
: 'medium';
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Validate category value from AI response
|
|
264
|
+
*/
|
|
265
|
+
function validateCategory(category) {
|
|
266
|
+
const valid = [
|
|
267
|
+
'sql_injection', 'xss', 'command_injection', 'missing_auth',
|
|
268
|
+
'dangerous_function', 'hardcoded_secret', 'high_entropy_string',
|
|
269
|
+
'sensitive_variable', 'security_bypass', 'insecure_config',
|
|
270
|
+
'suspicious_package', 'cors_misconfiguration', 'root_container',
|
|
271
|
+
'weak_crypto', 'sensitive_url', 'ai_pattern', 'dangerous_file',
|
|
272
|
+
'data_exposure', // For logging/exposing sensitive data
|
|
273
|
+
];
|
|
274
|
+
return valid.includes(category)
|
|
275
|
+
? category
|
|
276
|
+
: 'dangerous_function';
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Get line content from file content by line number
|
|
280
|
+
*/
|
|
281
|
+
function getLineContent(content, lineNumber) {
|
|
282
|
+
const lines = content.split('\n');
|
|
283
|
+
return lines[lineNumber - 1]?.trim() || '';
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=response-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-parser.js","sourceRoot":"","sources":["../../../../src/layer3/anthropic/utils/response-parser.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA8DH,0CAiCC;AAKD,0DAkCC;AAMD,4EAwEC;AAKD,wDAiEC;AAKD,4CAKC;AAKD,4CAYC;AAKD,wCAGC;AAzTD,iDAAqD;AAErD;;;GAGG;AACH,SAAS,oBAAoB,CAAC,IAAY;IACxC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,UAAU,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IAElC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,QAA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D,CAAC,CAAC,QAAiC;QACnC,CAAC,CAAC,oBAAoB,CAAA;AAC1B,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,OAAe,EAAE,UAAkB;IAChE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjC,OAAO,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry Logic for AI API Calls
|
|
3
|
+
*
|
|
4
|
+
* Implements exponential backoff for rate limit handling.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Helper function to make Anthropic API calls with retry logic for rate limiting
|
|
8
|
+
* Implements exponential backoff for 429 (rate limit) errors
|
|
9
|
+
*/
|
|
10
|
+
export declare function makeAnthropicRequestWithRetry<T>(requestFn: () => Promise<T>, maxRetries?: number, initialDelayMs?: number): Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Helper to make OpenAI requests with retry logic for rate limits
|
|
13
|
+
*/
|
|
14
|
+
export declare function makeOpenAIRequestWithRetry<T>(requestFn: () => Promise<T>, maxRetries?: number, initialDelayMs?: number): Promise<T>;
|
|
15
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../../src/layer3/anthropic/utils/retry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,wBAAsB,6BAA6B,CAAC,CAAC,EACnD,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,UAAU,GAAE,MAAU,EACtB,cAAc,GAAE,MAAa,GAC5B,OAAO,CAAC,CAAC,CAAC,CA0BZ;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAAC,CAAC,EAChD,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,UAAU,SAAI,EACd,cAAc,SAAO,GACpB,OAAO,CAAC,CAAC,CAAC,CAyBZ"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Retry Logic for AI API Calls
|
|
4
|
+
*
|
|
5
|
+
* Implements exponential backoff for rate limit handling.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.makeAnthropicRequestWithRetry = makeAnthropicRequestWithRetry;
|
|
9
|
+
exports.makeOpenAIRequestWithRetry = makeOpenAIRequestWithRetry;
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to make Anthropic API calls with retry logic for rate limiting
|
|
12
|
+
* Implements exponential backoff for 429 (rate limit) errors
|
|
13
|
+
*/
|
|
14
|
+
async function makeAnthropicRequestWithRetry(requestFn, maxRetries = 3, initialDelayMs = 1000) {
|
|
15
|
+
let lastError = null;
|
|
16
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
17
|
+
try {
|
|
18
|
+
return await requestFn();
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
lastError = error;
|
|
22
|
+
// Check if it's a rate limit error (429)
|
|
23
|
+
const isRateLimit = error?.status === 429 || error?.message?.includes('rate limit');
|
|
24
|
+
if (isRateLimit && attempt < maxRetries) {
|
|
25
|
+
// Exponential backoff: 1s, 2s, 4s
|
|
26
|
+
const delayMs = initialDelayMs * Math.pow(2, attempt);
|
|
27
|
+
console.log(`[AI Validation] Rate limit hit, retrying in ${delayMs}ms (attempt ${attempt + 1}/${maxRetries})`);
|
|
28
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// If not rate limit or max retries reached, throw
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw lastError || new Error('Max retries exceeded');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Helper to make OpenAI requests with retry logic for rate limits
|
|
39
|
+
*/
|
|
40
|
+
async function makeOpenAIRequestWithRetry(requestFn, maxRetries = 3, initialDelayMs = 1000) {
|
|
41
|
+
let lastError = null;
|
|
42
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
43
|
+
try {
|
|
44
|
+
return await requestFn();
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
lastError = error;
|
|
48
|
+
// Check if it's a rate limit error (429) - but NOT insufficient_quota
|
|
49
|
+
const isRateLimit = error?.status === 429 && error?.code !== 'insufficient_quota';
|
|
50
|
+
if (isRateLimit && attempt < maxRetries) {
|
|
51
|
+
const delayMs = initialDelayMs * Math.pow(2, attempt);
|
|
52
|
+
console.log(`[OpenAI Validation] Rate limit hit, retrying in ${delayMs}ms (attempt ${attempt + 1}/${maxRetries})`);
|
|
53
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
// If it's a quota error or max retries reached, throw
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw lastError || new Error('Max retries exceeded');
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../../src/layer3/anthropic/utils/retry.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAMH,sEA8BC;AAKD,gEA6BC;AApED;;;GAGG;AACI,KAAK,UAAU,6BAA6B,CACjD,SAA2B,EAC3B,aAAqB,CAAC,EACtB,iBAAyB,IAAI;IAE7B,IAAI,SAAS,GAAiB,IAAI,CAAA;IAElC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,EAAE,CAAA;QA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,UAAU,EAAE,CAAC;gBACxC,MAAM,OAAO,GAAG,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;gBACrD,OAAO,CAAC,GAAG,CAAC,mDAAmD,OAAO,eAAe,OAAO,GAAG,CAAC,IAAI,UAAU,GAAG,CAAC,CAAA;gBAClH,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;gBAC1D,SAAQ;YACV,CAAC;YAED,sDAAsD;YACtD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED,MAAM,SAAS,IAAI,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;AACtD,CAAC"}
|
package/dist/layer3/index.d.ts
CHANGED
|
@@ -23,4 +23,5 @@ export interface Layer3Options {
|
|
|
23
23
|
export declare function runLayer3Scan(files: ScanFile[], options?: Layer3Options): Promise<Layer3Result>;
|
|
24
24
|
export { analyzeWithAI, batchAnalyzeWithAI, type Layer3Context } from './anthropic';
|
|
25
25
|
export { checkPackages } from './package-check';
|
|
26
|
+
export { checkPackageAdvisories } from './osv-check';
|
|
26
27
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layer3/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC1E,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layer3/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC1E,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAIpE,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,aAAa,EAAE,CAAA;IAChC,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB;AAcD,MAAM,WAAW,aAAa;IAC5B,yBAAyB;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,8CAA8C;IAC9C,cAAc,CAAC,EAAE,aAAa,CAAA;IAC9B,4CAA4C;IAC5C,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;CACtC;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,QAAQ,EAAE,EACjB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CA2FvB;AA+BD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA"}
|