this repo has no description

only prompt if we know the language

karitham.dev 1ba8c82d 00222541

verified
+34 -15
+4 -3
package.json
··· 2 2 "name": "chainlink-opencode", 3 3 "private": true, 4 4 "main": "src/index.ts", 5 + "scripts": { 6 + "typecheck": "tsc --noEmit" 7 + }, 5 8 "devDependencies": { 6 - "@types/bun": "latest" 7 - }, 8 - "peerDependencies": { 9 + "@types/bun": "latest", 9 10 "typescript": "^5" 10 11 }, 11 12 "dependencies": {
+30 -12
src/index.ts
··· 1 - import { readFileSync } from "node:fs"; 1 + import { readFileSync, existsSync } from "node:fs"; 2 2 import { type Plugin, tool } from "@opencode-ai/plugin"; 3 3 4 4 /** ··· 103 103 } 104 104 105 105 /** 106 + * Finds the path to a rule file for the given language. 107 + * Returns the path if found, null otherwise. 108 + */ 109 + function findRuleFile(directory: string, language: string): string | null { 110 + const paths = [`${directory}/.rules/${language}.md`]; 111 + 112 + const rulesDir = process.env.LANGRULES_DIR; 113 + if (rulesDir) { 114 + paths.push(`${rulesDir}/${language}.md`); 115 + } 116 + 117 + for (const rulePath of paths) { 118 + if (existsSync(rulePath)) { 119 + return rulePath; 120 + } 121 + } 122 + return null; 123 + } 124 + 125 + /** 106 126 * Checks if rules should be prompted for a session/language combo. 107 127 * Returns true if this is the first time, and marks it as read. 108 128 */ ··· 149 169 } 150 170 } 151 171 152 - const paths = [`${directory}/.rules/${languageFile}.md`]; 153 - 154 - const rulesDir = process.env.LANGRULES_DIR; 155 - if (rulesDir) { 156 - paths.push(`${rulesDir}/${languageFile}.md`); 172 + const rulePath = findRuleFile(directory, languageFile); 173 + if (!rulePath) { 174 + return `No rule file found for '${languageFile}'`; 157 175 } 158 176 159 - for (const rulePath of paths) { 160 - try { 161 - const content = readFileSync(rulePath, "utf-8"); 162 - if (content.trim()) return content.trim(); 163 - } catch (error) {} 164 - } 177 + try { 178 + const content = readFileSync(rulePath, "utf-8"); 179 + if (content.trim()) return content.trim(); 180 + } catch (error) {} 165 181 166 182 return `No rule file found for '${languageFile}'`; 167 183 }, ··· 179 195 180 196 const language = getLanguageFromFilePath(filePath); 181 197 if (!language) return; 198 + 199 + if (!findRuleFile(directory, language)) return; 182 200 183 201 if (shouldPromptForRules(sessionID, language)) { 184 202 const ext = filePath.split(".").pop()?.toLowerCase() || "";