nia-opencode 0.1.0 → 0.1.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/dist/cli.js +59 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,28 @@ import { homedir } from "node:os";
|
|
|
7
7
|
import * as readline from "node:readline";
|
|
8
8
|
var OPENCODE_CONFIG_DIR = join(homedir(), ".config", "opencode");
|
|
9
9
|
var NIA_CONFIG_PATH = join(OPENCODE_CONFIG_DIR, "nia.json");
|
|
10
|
+
var AGENTS_MD_PATH = join(OPENCODE_CONFIG_DIR, "AGENTS.md");
|
|
10
11
|
var PLUGIN_NAME = "nia-opencode@latest";
|
|
12
|
+
var NIA_AGENTS_INSTRUCTIONS = `
|
|
13
|
+
# How to use Nia
|
|
14
|
+
|
|
15
|
+
Nia provides tools for indexing and searching external repositories, research papers, local folders, documentation, packages, and performing AI-powered research. Its primary goal is to reduce hallucinations in LLMs and provide up-to-date context for AI agents.
|
|
16
|
+
|
|
17
|
+
## Deterministic Workflow
|
|
18
|
+
|
|
19
|
+
1. Check if the source is already indexed using manage_resource (when listing sources, use targeted query to save tokens since users can have multiple sources indexed) or check any nia.md files for already indexed sources.
|
|
20
|
+
2. If it is indexed, check the tree of the source or ls relevant directories.
|
|
21
|
+
3. After getting the grasp of the structure (tree), use 'search', 'nia_grep', 'nia_read' for targeted searches.
|
|
22
|
+
4. If helpful, use the context tool to save your research findings to make them reusable for future conversations.
|
|
23
|
+
5. Save your findings in an .md file to track: source indexed, used, its ID, and link so you won't have to list sources in the future and can get straight to work.
|
|
24
|
+
|
|
25
|
+
## Notes
|
|
26
|
+
|
|
27
|
+
- DO NOT USE WEB RESEARCH TOOLS IF INFORMATION IS INDEXED IN NIA BY USING 'manage_resource' tool.
|
|
28
|
+
- If the source isn't indexed, index it. Note that for docs you should always index the root link like docs.stripe.com so it will always scrape all pages.
|
|
29
|
+
- If you need to index something but don't know the link for that source, use nia_research (quick or deep modes).
|
|
30
|
+
- Once you use the index tool, do not expect it to finish in 1-3 seconds. Stop your work or do something that will make your work pause for 1-5 minutes until the source is indexed, then run manage_resource again to check its status. You can also prompt the user to wait if needed.
|
|
31
|
+
`;
|
|
11
32
|
function stripJsoncComments(content) {
|
|
12
33
|
return content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
13
34
|
}
|
|
@@ -155,6 +176,32 @@ function createNiaConfig(apiKey) {
|
|
|
155
176
|
console.log(` Created ${NIA_CONFIG_PATH}`);
|
|
156
177
|
return true;
|
|
157
178
|
}
|
|
179
|
+
function updateAgentsMd() {
|
|
180
|
+
mkdirSync(OPENCODE_CONFIG_DIR, { recursive: true });
|
|
181
|
+
try {
|
|
182
|
+
if (existsSync(AGENTS_MD_PATH)) {
|
|
183
|
+
const content = readFileSync(AGENTS_MD_PATH, "utf-8");
|
|
184
|
+
if (content.includes("# How to use Nia")) {
|
|
185
|
+
console.log(" Nia instructions already in AGENTS.md");
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
const newContent = content.trimEnd() + `
|
|
189
|
+
|
|
190
|
+
` + NIA_AGENTS_INSTRUCTIONS.trim() + `
|
|
191
|
+
`;
|
|
192
|
+
writeFileSync(AGENTS_MD_PATH, newContent);
|
|
193
|
+
console.log(" Appended Nia instructions to AGENTS.md");
|
|
194
|
+
} else {
|
|
195
|
+
writeFileSync(AGENTS_MD_PATH, NIA_AGENTS_INSTRUCTIONS.trim() + `
|
|
196
|
+
`);
|
|
197
|
+
console.log(` Created ${AGENTS_MD_PATH} with Nia instructions`);
|
|
198
|
+
}
|
|
199
|
+
return true;
|
|
200
|
+
} catch (err) {
|
|
201
|
+
console.error(" Failed to update AGENTS.md:", err);
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
158
205
|
async function install(options) {
|
|
159
206
|
console.log(`
|
|
160
207
|
Nia OpenCode Plugin Installer
|
|
@@ -216,6 +263,18 @@ Step 3: Configure OpenCode`);
|
|
|
216
263
|
}
|
|
217
264
|
}
|
|
218
265
|
console.log(`
|
|
266
|
+
Step 4: Add Nia Instructions to AGENTS.md`);
|
|
267
|
+
if (options.tui && rl) {
|
|
268
|
+
const shouldUpdate = await confirm(rl, "Add Nia usage instructions to ~/.config/opencode/AGENTS.md?");
|
|
269
|
+
if (shouldUpdate) {
|
|
270
|
+
updateAgentsMd();
|
|
271
|
+
} else {
|
|
272
|
+
console.log(" Skipped.");
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
updateAgentsMd();
|
|
276
|
+
}
|
|
277
|
+
console.log(`
|
|
219
278
|
` + "-".repeat(50));
|
|
220
279
|
console.log(`
|
|
221
280
|
Setup Complete!
|