npm package diff

Package: @forge/lint

Versions: 5.12.0-next.6 - 5.12.0-next.7

File: package/out/lint/linters/llm-module-linter/llm-module-linter.js

Index: package/out/lint/linters/llm-module-linter/llm-module-linter.js
===================================================================
--- package/out/lint/linters/llm-module-linter/llm-module-linter.js
+++ package/out/lint/linters/llm-module-linter/llm-module-linter.js
@@ -0,0 +1,49 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.LlmModuleLinter = void 0;
+const tslib_1 = require("tslib");
+const base_linter_1 = tslib_1.__importDefault(require("../../base-linter"));
+const llm_node_visitor_1 = require("./llm-node-visitor");
+const llm_verifier_1 = require("./llm-verifier");
+const DEFAULT_LLM_MODULES = [{ key: 'llm', model: ['claude'] }];
+class LlmModuleLinter extends base_linter_1.default {
+    manifest;
+    constructor(environment, manifest, logger) {
+        super(environment, logger);
+        this.manifest = manifest;
+    }
+    addLintCriteriaMatch(usage, filepath) {
+        const criteriaMatches = this.matches.get(filepath);
+        criteriaMatches?.llm.push(usage);
+    }
+    async bootstrap() {
+        this.nodeVisitors = [new llm_node_visitor_1.LlmNodeVisitor()];
+        this.verifiers = {
+            llm: new llm_verifier_1.LlmVerifier(this.environment, this.manifest)
+        };
+    }
+    setupMatchesMap(filePath) {
+        this.matches.set(filePath, {
+            llm: []
+        });
+    }
+    getFixer() {
+        return this.applyFixes;
+    }
+    async applyFixes(_errors, warnings, state) {
+        if (warnings?.length > 0) {
+            const currentModules = (await state.configFile.readConfig())?.modules ?? {};
+            const isLLMModuleMissing = warnings.find((warning) => warning.metadata?.missingLLMModule === 'llm') !== undefined;
+            if (isLLMModuleMissing && !currentModules.llm) {
+                const newModules = {
+                    ...currentModules,
+                    llm: DEFAULT_LLM_MODULES
+                };
+                await state.configFile.writeToConfigFile('modules', newModules);
+                state.warningsFixed += 1;
+            }
+        }
+        return state;
+    }
+}
+exports.LlmModuleLinter = LlmModuleLinter;