@gagik.co/snippet-agent 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/package.json +5 -1
- package/.eslintrc.js +0 -13
- package/.prettierrc.json +0 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -8
- package/dist/src/project-agent.d.ts +0 -1
- package/dist/src/project-agent.js +0 -36
- package/src/agent-class.ts +0 -393
- package/src/banner.ts +0 -36
- package/src/confirmation-extension.ts +0 -297
- package/src/index.ts +0 -137
- package/src/mongosh-interactive-mode.ts +0 -420
- package/src/shell-context.ts +0 -97
- package/src/skills-loader.ts +0 -37
- package/src/stdout-patcher.ts +0 -48
- package/src/tools/index.ts +0 -4
- package/src/tools/mongosh-eval.ts +0 -115
- package/src/tools/search-docs.ts +0 -115
- package/src/tools/types.ts +0 -15
- package/src/types.ts +0 -23
- package/tsconfig-lint.json +0 -4
- package/tsconfig.json +0 -20
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import type { ShellContext } from '../shell-context';
|
|
2
|
-
import type { Tool } from './types';
|
|
3
|
-
|
|
4
|
-
export type CreateMongoshEvalToolOptions = {
|
|
5
|
-
shellContext: ShellContext;
|
|
6
|
-
debugLogging: boolean;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export async function createMongoshEvalTool(
|
|
10
|
-
options: CreateMongoshEvalToolOptions,
|
|
11
|
-
): Promise<Tool> {
|
|
12
|
-
const { shellContext, debugLogging } = options;
|
|
13
|
-
const { defineTool } = await import('@earendil-works/pi-coding-agent');
|
|
14
|
-
const { Type } = await import('@sinclair/typebox');
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
shellEvaluator,
|
|
18
|
-
originalEval,
|
|
19
|
-
formatResultValue,
|
|
20
|
-
instanceState,
|
|
21
|
-
capturedPrintOutput,
|
|
22
|
-
} = shellContext;
|
|
23
|
-
|
|
24
|
-
return defineTool({
|
|
25
|
-
name: 'mongosh_eval',
|
|
26
|
-
label: 'mongosh eval',
|
|
27
|
-
description:
|
|
28
|
-
'Execute a mongosh shell expression against the connected MongoDB instance. ' +
|
|
29
|
-
'Supports the full mongosh API: queries, aggregations, admin commands ' +
|
|
30
|
-
'The expression runs in the same context as the interactive mongosh REPL.' +
|
|
31
|
-
'Note: make sure to double-check with the user before running destructive or risky operations.',
|
|
32
|
-
parameters: Type.Object({
|
|
33
|
-
expression: Type.String({
|
|
34
|
-
description:
|
|
35
|
-
'The mongosh expression to evaluate. Never run `use` to switch databases and instead refer to the database name explicitly. Examples: "db.getMongo()", "db.users.find().limit(5)", "db.serverStatus()", "db.getSiblingDB(\'movies\')". The last line of the output will be the result of the tool call.',
|
|
36
|
-
}),
|
|
37
|
-
}),
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
execute: async (_toolCallId: string, params: any) => {
|
|
40
|
-
const expr: string = params.expression;
|
|
41
|
-
|
|
42
|
-
// Clear captured output before execution
|
|
43
|
-
capturedPrintOutput.length = 0;
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
let rawValue = await shellEvaluator.customEval(
|
|
47
|
-
originalEval,
|
|
48
|
-
expr,
|
|
49
|
-
instanceState.context,
|
|
50
|
-
'mongosh_eval',
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
// Auto-call functions that take no arguments (e.g., `history` -> `history()`)
|
|
54
|
-
// This provides shell-like behavior for zero-argument functions
|
|
55
|
-
if (typeof rawValue === 'function') {
|
|
56
|
-
try {
|
|
57
|
-
rawValue = await rawValue();
|
|
58
|
-
} catch {
|
|
59
|
-
// If calling fails, keep the original function reference
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const formatted = await formatResultValue(rawValue);
|
|
64
|
-
|
|
65
|
-
// Build output: captured print output takes priority, then add formatted result if present
|
|
66
|
-
let output: string;
|
|
67
|
-
if (capturedPrintOutput.length > 0) {
|
|
68
|
-
// Has captured print output - use it as primary output
|
|
69
|
-
output = capturedPrintOutput.join('\n');
|
|
70
|
-
// Also append formatted result if it's meaningful (not empty/undefined)
|
|
71
|
-
if (formatted) {
|
|
72
|
-
output += '\n' + formatted;
|
|
73
|
-
}
|
|
74
|
-
} else if (formatted) {
|
|
75
|
-
// No captured output, but has formatted result
|
|
76
|
-
output = formatted;
|
|
77
|
-
} else {
|
|
78
|
-
// Nothing to show
|
|
79
|
-
output = '(no output)';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (debugLogging) {
|
|
83
|
-
process.stderr.write(
|
|
84
|
-
`[mongosh_eval] Output: ${output.substring(0, 200)}\n`,
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
content: [{ type: 'text' as const, text: output }],
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
|
-
details: { expression: expr } as any,
|
|
92
|
-
};
|
|
93
|
-
} catch (err) {
|
|
94
|
-
const errorMsg =
|
|
95
|
-
err instanceof Error ? `${err.name}: ${err.message}` : String(err);
|
|
96
|
-
|
|
97
|
-
if (debugLogging) {
|
|
98
|
-
process.stderr.write(`[mongosh_eval] Error: ${errorMsg}\n`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const parts: string[] = [];
|
|
102
|
-
if (capturedPrintOutput.length > 0) {
|
|
103
|
-
parts.push(capturedPrintOutput.join('\n'));
|
|
104
|
-
}
|
|
105
|
-
parts.push(`Error: ${errorMsg}`);
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
content: [{ type: 'text' as const, text: parts.join('\n') }],
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
-
details: { error: errorMsg, expression: expr } as any,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
}
|
package/src/tools/search-docs.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import type { Tool, SearchDocsResult } from './types';
|
|
2
|
-
|
|
3
|
-
export async function createSearchDocsTool(): Promise<Tool> {
|
|
4
|
-
const { defineTool } = await import('@earendil-works/pi-coding-agent');
|
|
5
|
-
const { Type } = await import('@sinclair/typebox');
|
|
6
|
-
|
|
7
|
-
return defineTool({
|
|
8
|
-
name: 'search_docs',
|
|
9
|
-
label: 'search docs',
|
|
10
|
-
description:
|
|
11
|
-
'Search for information in the MongoDB documentation and knowledge base. ' +
|
|
12
|
-
'This includes official documentation, curated expert guidance, and other resources provided by MongoDB.',
|
|
13
|
-
parameters: Type.Object({
|
|
14
|
-
query: Type.String({
|
|
15
|
-
description:
|
|
16
|
-
'A natural language query to search for in the MongoDB knowledge base. ' +
|
|
17
|
-
'This should be a single question or a topic that is relevant to the MongoDB use case.',
|
|
18
|
-
}),
|
|
19
|
-
limit: Type.Optional(
|
|
20
|
-
Type.Number({
|
|
21
|
-
description: 'The maximum number of results to return (1-100)',
|
|
22
|
-
default: 5,
|
|
23
|
-
minimum: 1,
|
|
24
|
-
maximum: 100,
|
|
25
|
-
}),
|
|
26
|
-
),
|
|
27
|
-
}),
|
|
28
|
-
execute: async (_toolCallId: string, params: { query: string; limit?: number }) => {
|
|
29
|
-
const { query, limit = 5 } = params;
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const response = await fetch('https://knowledge.mongodb.com/api/v1/content/search', {
|
|
33
|
-
method: 'POST',
|
|
34
|
-
headers: {
|
|
35
|
-
'Content-Type': 'application/json',
|
|
36
|
-
'X-Request-Origin': 'mongodb-mongosh',
|
|
37
|
-
'User-Agent': 'mongodb-mongosh',
|
|
38
|
-
},
|
|
39
|
-
body: JSON.stringify({
|
|
40
|
-
query,
|
|
41
|
-
limit,
|
|
42
|
-
}),
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
if (!response.ok) {
|
|
46
|
-
const errorText = await response.text();
|
|
47
|
-
return {
|
|
48
|
-
content: [
|
|
49
|
-
{
|
|
50
|
-
type: 'text' as const,
|
|
51
|
-
text: `Failed to search docs: ${response.status} ${response.statusText}${errorText ? `\n${errorText}` : ''}`,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
isError: true,
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
-
details: { query, limit, error: errorText } as any,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const data = (await response.json()) as SearchDocsResult;
|
|
61
|
-
|
|
62
|
-
if (!data.results || data.results.length === 0) {
|
|
63
|
-
return {
|
|
64
|
-
content: [
|
|
65
|
-
{
|
|
66
|
-
type: 'text' as const,
|
|
67
|
-
text: 'No results found for this query.',
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
-
details: { query, limit, resultCount: 0 } as any,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const formattedResults = data.results
|
|
76
|
-
.map((result, index) => {
|
|
77
|
-
const lines: string[] = [];
|
|
78
|
-
lines.push(`${index + 1}. ${result.title}`);
|
|
79
|
-
lines.push(` URL: ${result.url}`);
|
|
80
|
-
if (result.metadata?.tags?.length) {
|
|
81
|
-
lines.push(` Tags: ${result.metadata.tags.join(', ')}`);
|
|
82
|
-
}
|
|
83
|
-
lines.push('');
|
|
84
|
-
lines.push(result.text.split('\n').map((line) => ` ${line}`).join('\n'));
|
|
85
|
-
return lines.join('\n');
|
|
86
|
-
})
|
|
87
|
-
.join('\n\n');
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
content: [
|
|
91
|
-
{
|
|
92
|
-
type: 'text' as const,
|
|
93
|
-
text: `Found ${data.results.length} result${data.results.length === 1 ? '' : 's'} in MongoDB documentation:\n\n${formattedResults}`,
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
-
details: { query, limit, resultCount: data.results.length } as any,
|
|
98
|
-
};
|
|
99
|
-
} catch (err) {
|
|
100
|
-
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
101
|
-
return {
|
|
102
|
-
content: [
|
|
103
|
-
{
|
|
104
|
-
type: 'text' as const,
|
|
105
|
-
text: `Error searching docs: ${errorMsg}`,
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
isError: true,
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
-
details: { query, limit, error: errorMsg } as any,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
}
|
package/src/tools/types.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type Tool = ReturnType<
|
|
2
|
-
typeof import('@earendil-works/pi-coding-agent').defineTool
|
|
3
|
-
>;
|
|
4
|
-
|
|
5
|
-
export type SearchDocsResult = {
|
|
6
|
-
results: Array<{
|
|
7
|
-
url: string;
|
|
8
|
-
title: string;
|
|
9
|
-
text: string;
|
|
10
|
-
metadata: {
|
|
11
|
-
tags: string[];
|
|
12
|
-
[key: string]: unknown;
|
|
13
|
-
};
|
|
14
|
-
}>;
|
|
15
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type ShellInstanceState = {
|
|
2
|
-
evaluationListener: {
|
|
3
|
-
setConfig: (key: string, value: unknown) => void;
|
|
4
|
-
getConfig: <T>(key: string) => Promise<T>;
|
|
5
|
-
};
|
|
6
|
-
shellApi: Record<string, unknown>;
|
|
7
|
-
context: Record<string, unknown>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type CliContext = {
|
|
11
|
-
db: {
|
|
12
|
-
_mongo: {
|
|
13
|
-
_instanceState: ShellInstanceState;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type Skill = {
|
|
19
|
-
name: string;
|
|
20
|
-
description: string;
|
|
21
|
-
content: string;
|
|
22
|
-
source: string;
|
|
23
|
-
};
|
package/tsconfig-lint.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"outDir": "./dist",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"allowSyntheticDefaultImports": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"forceConsistentCasingInFileNames": true,
|
|
14
|
-
"types": ["node"],
|
|
15
|
-
"allowJs": true,
|
|
16
|
-
"resolveJsonModule": true
|
|
17
|
-
},
|
|
18
|
-
"include": ["src/**/*.ts"],
|
|
19
|
-
"exclude": ["src/**/*.test.ts"]
|
|
20
|
-
}
|