tangled
alpha
login
or
join now
karitham.dev
/
langrules-opencode
1
fork
atom
this repo has no description
1
fork
atom
overview
issues
pulls
pipelines
only prompt if we know the language
karitham.dev
1 month ago
1ba8c82d
00222541
verified
This commit was signed with the committer's
known signature
.
karitham.dev
SSH Key Fingerprint:
SHA256:ODeRMGYuG7M/0G+fRF6IfwUk7r5AgG5MYdFTN+uvimc=
+34
-15
2 changed files
expand all
collapse all
unified
split
package.json
src
index.ts
+4
-3
package.json
reviewed
···
2
2
"name": "chainlink-opencode",
3
3
"private": true,
4
4
"main": "src/index.ts",
5
5
+
"scripts": {
6
6
+
"typecheck": "tsc --noEmit"
7
7
+
},
5
8
"devDependencies": {
6
6
-
"@types/bun": "latest"
7
7
-
},
8
8
-
"peerDependencies": {
9
9
+
"@types/bun": "latest",
9
10
"typescript": "^5"
10
11
},
11
12
"dependencies": {
+30
-12
src/index.ts
reviewed
···
1
1
-
import { readFileSync } from "node:fs";
1
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
106
+
* Finds the path to a rule file for the given language.
107
107
+
* Returns the path if found, null otherwise.
108
108
+
*/
109
109
+
function findRuleFile(directory: string, language: string): string | null {
110
110
+
const paths = [`${directory}/.rules/${language}.md`];
111
111
+
112
112
+
const rulesDir = process.env.LANGRULES_DIR;
113
113
+
if (rulesDir) {
114
114
+
paths.push(`${rulesDir}/${language}.md`);
115
115
+
}
116
116
+
117
117
+
for (const rulePath of paths) {
118
118
+
if (existsSync(rulePath)) {
119
119
+
return rulePath;
120
120
+
}
121
121
+
}
122
122
+
return null;
123
123
+
}
124
124
+
125
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
152
-
const paths = [`${directory}/.rules/${languageFile}.md`];
153
153
-
154
154
-
const rulesDir = process.env.LANGRULES_DIR;
155
155
-
if (rulesDir) {
156
156
-
paths.push(`${rulesDir}/${languageFile}.md`);
172
172
+
const rulePath = findRuleFile(directory, languageFile);
173
173
+
if (!rulePath) {
174
174
+
return `No rule file found for '${languageFile}'`;
157
175
}
158
176
159
159
-
for (const rulePath of paths) {
160
160
-
try {
161
161
-
const content = readFileSync(rulePath, "utf-8");
162
162
-
if (content.trim()) return content.trim();
163
163
-
} catch (error) {}
164
164
-
}
177
177
+
try {
178
178
+
const content = readFileSync(rulePath, "utf-8");
179
179
+
if (content.trim()) return content.trim();
180
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
198
+
199
199
+
if (!findRuleFile(directory, language)) return;
182
200
183
201
if (shouldPromptForRules(sessionID, language)) {
184
202
const ext = filePath.split(".").pop()?.toLowerCase() || "";