nia-opencode 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -123,7 +123,7 @@ NIA_DEBUG=true opencode
123
123
 
124
124
  ## Get Your API Key
125
125
 
126
- Get your Nia API key at [trynia.ai/api-keys](https://trynia.ai/api-keys)
126
+ Get your Nia API key at [app.trynia.ai](https://app.trynia.ai)
127
127
 
128
128
  ## License
129
129
 
package/dist/cli.js CHANGED
@@ -210,7 +210,7 @@ async function install(options) {
210
210
  console.log("Step 1: Configure API Key");
211
211
  let apiKey = options.apiKey || process.env.NIA_API_KEY || "";
212
212
  if (!apiKey && options.tui && rl) {
213
- console.log(`Get your API key from: https://trynia.ai/api-keys
213
+ console.log(`Get your API key from: https://app.trynia.ai
214
214
  `);
215
215
  apiKey = await prompt(rl, "Enter your Nia API key (nk_...): ");
216
216
  }
@@ -281,7 +281,7 @@ Step 4: Add Nia Instructions to AGENTS.md`);
281
281
  `);
282
282
  if (!apiKey) {
283
283
  console.log("Next steps:");
284
- console.log("1. Get your API key from: https://trynia.ai/api-keys");
284
+ console.log("1. Get your API key from: https://app.trynia.ai");
285
285
  console.log("2. Set the environment variable:");
286
286
  console.log(' export NIA_API_KEY="nk_..."');
287
287
  console.log(" Or edit ~/.config/opencode/nia.json");
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ function isConfigured() {
46
46
  // src/keywords.ts
47
47
  var CODE_BLOCK_PATTERN = /```[\s\S]*?```/g;
48
48
  var INLINE_CODE_PATTERN = /`[^`]+`/g;
49
- var DEFAULT_PATTERNS = [
49
+ var RESEARCH_PATTERNS = [
50
50
  /\b(research|look\s*up|find\s*docs?)\b/i,
51
51
  /\b(search\s+for|search\s+codebase|search\s+repo|search\s+docs?)\b/i,
52
52
  /\b(grep\s+for|grep\s+in)\b/i,
@@ -55,6 +55,14 @@ var DEFAULT_PATTERNS = [
55
55
  /\bcheck\s+(the\s+)?(docs?|documentation)\s+(for|about|on)\b/i,
56
56
  /\bfind\s+(examples?|usage)\s+(of|for)\b/i
57
57
  ];
58
+ var SAVE_PATTERNS = [
59
+ /\b(save\s+(this\s+)?(context|conversation|session|chat))\b/i,
60
+ /\b(continue\s+(this\s+)?(later|tomorrow|in\s+\w+))\b/i,
61
+ /\b(pick\s+(this\s+)?up\s+(later|tomorrow|in\s+\w+))\b/i,
62
+ /\b(hand\s*off|switch(ing)?\s+to)\s+(cursor|claude|windsurf|copilot|another\s+agent)\b/i,
63
+ /\b(save\s+for\s+later|bookmark\s+this)\b/i,
64
+ /\b(preserve|store)\s+(this\s+)?(context|conversation|session)\b/i
65
+ ];
58
66
  function removeCodeBlocks(text) {
59
67
  return text.replace(CODE_BLOCK_PATTERN, "").replace(INLINE_CODE_PATTERN, "");
60
68
  }
@@ -67,19 +75,25 @@ function compileCustomPatterns() {
67
75
  }
68
76
  }).filter((p) => p !== null);
69
77
  }
70
- function detectResearchKeyword(text) {
78
+ function detectKeyword(text) {
71
79
  if (!CONFIG.keywords.enabled) {
72
- return { detected: false };
80
+ return { type: null };
73
81
  }
74
82
  const textWithoutCode = removeCodeBlocks(text);
75
- const allPatterns = [...DEFAULT_PATTERNS, ...compileCustomPatterns()];
76
- for (const pattern of allPatterns) {
83
+ for (const pattern of SAVE_PATTERNS) {
84
+ const match = textWithoutCode.match(pattern);
85
+ if (match) {
86
+ return { type: "save", match: match[0] };
87
+ }
88
+ }
89
+ const researchPatterns = [...RESEARCH_PATTERNS, ...compileCustomPatterns()];
90
+ for (const pattern of researchPatterns) {
77
91
  const match = textWithoutCode.match(pattern);
78
92
  if (match) {
79
- return { detected: true, match: match[0] };
93
+ return { type: "research", match: match[0] };
80
94
  }
81
95
  }
82
- return { detected: false };
96
+ return { type: null };
83
97
  }
84
98
  var NIA_NUDGE_MESSAGE = `[NIA KNOWLEDGE TRIGGER]
85
99
  The user is asking for research, documentation, or codebase exploration. You have access to **Nia** tools via MCP.
@@ -99,6 +113,30 @@ The user is asking for research, documentation, or codebase exploration. You hav
99
113
  3. Read specific files if needed for deeper context
100
114
 
101
115
  Use these tools to provide accurate, up-to-date information instead of relying solely on training data.`;
116
+ var NIA_SAVE_NUDGE_MESSAGE = `[NIA CONTEXT SAVE TRIGGER]
117
+ The user wants to save this conversation to continue later or hand off to another agent.
118
+
119
+ **Use \`nia.context\` to save:**
120
+ \`\`\`
121
+ nia.context({
122
+ action: "save",
123
+ title: "Brief title describing this session",
124
+ summary: "What was accomplished and what's pending",
125
+ content: "Key decisions, code snippets, and important context",
126
+ tags: ["relevant", "tags"],
127
+ edited_files: [{ path: "file/path.ts", action: "modified" }]
128
+ })
129
+ \`\`\`
130
+
131
+ **What to include:**
132
+ - Summary of what was discussed/accomplished
133
+ - Key decisions made
134
+ - Code snippets or plans created
135
+ - Files that were edited
136
+ - Next steps or pending tasks
137
+ - Any Nia sources that were referenced
138
+
139
+ This context can be loaded in Cursor, Claude Code, Windsurf, or any agent with Nia access.`;
102
140
 
103
141
  // src/services/logger.ts
104
142
  var DEBUG = process.env.NIA_DEBUG === "true" || process.env.NIA_DEBUG === "1";
@@ -143,20 +181,21 @@ var NiaPlugin = async (ctx) => {
143
181
  messagePreview: userMessage.slice(0, 100),
144
182
  partsCount: output.parts.length
145
183
  });
146
- const { detected, match } = detectResearchKeyword(userMessage);
147
- if (detected) {
148
- log("chat.message: research keyword detected", { match });
184
+ const { type, match } = detectKeyword(userMessage);
185
+ if (type) {
186
+ const nudgeText = type === "save" ? NIA_SAVE_NUDGE_MESSAGE : NIA_NUDGE_MESSAGE;
187
+ log(`chat.message: ${type} keyword detected`, { match });
149
188
  const nudgePart = {
150
- id: `nia-nudge-${Date.now()}`,
189
+ id: `nia-${type}-nudge-${Date.now()}`,
151
190
  sessionID: input.sessionID,
152
191
  messageID: output.message.id,
153
192
  type: "text",
154
- text: NIA_NUDGE_MESSAGE,
193
+ text: nudgeText,
155
194
  synthetic: true
156
195
  };
157
196
  output.parts.push(nudgePart);
158
197
  const duration = Date.now() - start;
159
- log("chat.message: nudge injected", { duration, match });
198
+ log(`chat.message: ${type} nudge injected`, { duration, match });
160
199
  }
161
200
  } catch (error) {
162
201
  log("chat.message: ERROR", { error: String(error) });
@@ -1,5 +1,11 @@
1
+ export type KeywordType = "research" | "save" | null;
2
+ export declare function detectKeyword(text: string): {
3
+ type: KeywordType;
4
+ match?: string;
5
+ };
1
6
  export declare function detectResearchKeyword(text: string): {
2
7
  detected: boolean;
3
8
  match?: string;
4
9
  };
5
10
  export declare const NIA_NUDGE_MESSAGE = "[NIA KNOWLEDGE TRIGGER]\nThe user is asking for research, documentation, or codebase exploration. You have access to **Nia** tools via MCP.\n\n**Available Nia tools:**\n- `nia.search` - Semantic search across indexed repos, docs, and papers\n- `nia.nia_research` - Web search (quick) or deep AI research (deep/oracle modes)\n- `nia.index` - Index new GitHub repos, documentation sites, or arXiv papers\n- `nia.nia_read` - Read specific files from indexed sources\n- `nia.nia_grep` - Regex search across indexed codebases\n- `nia.nia_explore` - Browse file trees of indexed repos/docs\n- `nia.manage_resource` - List/check status of indexed sources\n\n**Workflow:**\n1. Check what's indexed: `nia.manage_resource(action: \"list\")`\n2. Search or research based on the user's question\n3. Read specific files if needed for deeper context\n\nUse these tools to provide accurate, up-to-date information instead of relying solely on training data.";
11
+ export declare const NIA_SAVE_NUDGE_MESSAGE = "[NIA CONTEXT SAVE TRIGGER]\nThe user wants to save this conversation to continue later or hand off to another agent.\n\n**Use `nia.context` to save:**\n```\nnia.context({\n action: \"save\",\n title: \"Brief title describing this session\",\n summary: \"What was accomplished and what's pending\",\n content: \"Key decisions, code snippets, and important context\",\n tags: [\"relevant\", \"tags\"],\n edited_files: [{ path: \"file/path.ts\", action: \"modified\" }]\n})\n```\n\n**What to include:**\n- Summary of what was discussed/accomplished\n- Key decisions made\n- Code snippets or plans created\n- Files that were edited\n- Next steps or pending tasks\n- Any Nia sources that were referenced\n\nThis context can be loaded in Cursor, Claude Code, Windsurf, or any agent with Nia access.";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nia-opencode",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "OpenCode plugin that integrates Nia Knowledge Agent for research and documentation",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",