nia-opencode 0.1.1 → 0.1.2
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/index.js +52 -13
- package/dist/keywords.d.ts +6 -0
- package/package.json +1 -1
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
|
|
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
|
|
78
|
+
function detectKeyword(text) {
|
|
71
79
|
if (!CONFIG.keywords.enabled) {
|
|
72
|
-
return {
|
|
80
|
+
return { type: null };
|
|
73
81
|
}
|
|
74
82
|
const textWithoutCode = removeCodeBlocks(text);
|
|
75
|
-
const
|
|
76
|
-
|
|
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 {
|
|
93
|
+
return { type: "research", match: match[0] };
|
|
80
94
|
}
|
|
81
95
|
}
|
|
82
|
-
return {
|
|
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 {
|
|
147
|
-
if (
|
|
148
|
-
|
|
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:
|
|
193
|
+
text: nudgeText,
|
|
155
194
|
synthetic: true
|
|
156
195
|
};
|
|
157
196
|
output.parts.push(nudgePart);
|
|
158
197
|
const duration = Date.now() - start;
|
|
159
|
-
log(
|
|
198
|
+
log(`chat.message: ${type} nudge injected`, { duration, match });
|
|
160
199
|
}
|
|
161
200
|
} catch (error) {
|
|
162
201
|
log("chat.message: ERROR", { error: String(error) });
|
package/dist/keywords.d.ts
CHANGED
|
@@ -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.";
|