sam-coder-cli 1.0.0
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 +59 -0
- package/ai-assistant-0.0.1.vsix +0 -0
- package/bin/agi-cli.js +815 -0
- package/bin/agi-cli.js.bak +352 -0
- package/bin/agi-cli.js.new +328 -0
- package/bin/config.json +3 -0
- package/bin/ui.js +42 -0
- package/dist/agentUtils.js +539 -0
- package/dist/agentUtils.js.map +1 -0
- package/dist/aiAssistantViewProvider.js +2098 -0
- package/dist/aiAssistantViewProvider.js.map +1 -0
- package/dist/extension.js +117 -0
- package/dist/extension.js.map +1 -0
- package/dist/fetch-polyfill.js +9 -0
- package/dist/fetch-polyfill.js.map +1 -0
- package/foldersnake/snake_game.py +125 -0
- package/media/ai-icon.png +0 -0
- package/media/ai-icon.svg +5 -0
- package/media/infinity-icon.svg +4 -0
- package/out/agentUtils.d.ts +28 -0
- package/out/agentUtils.d.ts.map +1 -0
- package/out/agentUtils.js +539 -0
- package/out/agentUtils.js.map +1 -0
- package/out/aiAssistantViewProvider.d.ts +58 -0
- package/out/aiAssistantViewProvider.d.ts.map +1 -0
- package/out/aiAssistantViewProvider.js +2098 -0
- package/out/aiAssistantViewProvider.js.map +1 -0
- package/out/extension.d.ts +4 -0
- package/out/extension.d.ts.map +1 -0
- package/out/extension.js +117 -0
- package/out/extension.js.map +1 -0
- package/out/fetch-polyfill.d.ts +11 -0
- package/out/fetch-polyfill.d.ts.map +1 -0
- package/out/fetch-polyfill.js +9 -0
- package/out/fetch-polyfill.js.map +1 -0
- package/package.json +31 -0
- package/src/agentUtils.ts +583 -0
- package/src/aiAssistantViewProvider.ts +2264 -0
- package/src/cliAgentUtils.js +73 -0
- package/src/extension.ts +112 -0
- package/src/fetch-polyfill.ts +11 -0
- package/tsconfig.json +24 -0
- package/webpack.config.js +45 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const fs = require('fs').promises;
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { exec } = require('child_process');
|
|
4
|
+
const util = require('util');
|
|
5
|
+
const execPromise = util.promisify(exec);
|
|
6
|
+
|
|
7
|
+
class CLIAgentUtils {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.workspaceRoot = process.cwd();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Log to console
|
|
13
|
+
log(message) {
|
|
14
|
+
console.log(`[AGENT] ${message}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Read a file
|
|
18
|
+
async readFile(filePath, maxTokens) {
|
|
19
|
+
try {
|
|
20
|
+
const resolvedPath = this._resolveFilePath(filePath);
|
|
21
|
+
const content = await fs.readFile(resolvedPath, 'utf-8');
|
|
22
|
+
|
|
23
|
+
if (maxTokens && content.length > maxTokens) {
|
|
24
|
+
return content.substring(0, maxTokens) + '... [truncated]';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return content;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw new Error(`Error reading file: ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Write to a file
|
|
34
|
+
async writeFile(filePath, content) {
|
|
35
|
+
try {
|
|
36
|
+
const resolvedPath = this._resolveFilePath(filePath);
|
|
37
|
+
const dir = path.dirname(resolvedPath);
|
|
38
|
+
|
|
39
|
+
// Create directory if it doesn't exist
|
|
40
|
+
await fs.mkdir(dir, { recursive: true });
|
|
41
|
+
|
|
42
|
+
// Write file
|
|
43
|
+
await fs.writeFile(resolvedPath, content, 'utf-8');
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new Error(`Error writing file: ${error.message}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Run a command
|
|
50
|
+
async runCommand(command) {
|
|
51
|
+
try {
|
|
52
|
+
const { stdout, stderr } = await execPromise(command, { cwd: this.workspaceRoot });
|
|
53
|
+
|
|
54
|
+
if (stderr) {
|
|
55
|
+
console.error(`Command stderr: ${stderr}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return stdout;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw new Error(`Command failed: ${error.message}\n${error.stderr || ''}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Resolve file path (relative to workspace root if not absolute)
|
|
65
|
+
_resolveFilePath(filePath) {
|
|
66
|
+
if (path.isAbsolute(filePath)) {
|
|
67
|
+
return filePath;
|
|
68
|
+
}
|
|
69
|
+
return path.resolve(this.workspaceRoot, filePath);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { CLIAgentUtils };
|
package/src/extension.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as vscode from 'vscode';
|
|
2
|
+
import { AIAssistantViewProvider } from './aiAssistantViewProvider';
|
|
3
|
+
|
|
4
|
+
export function activate(context: vscode.ExtensionContext) {
|
|
5
|
+
console.log('AI Assistant extension activated');
|
|
6
|
+
|
|
7
|
+
// Create the provider instance
|
|
8
|
+
const aiAssistantProvider = new AIAssistantViewProvider(context.extensionUri);
|
|
9
|
+
|
|
10
|
+
// Register the webview view provider first before anything else
|
|
11
|
+
context.subscriptions.push(
|
|
12
|
+
vscode.window.registerWebviewViewProvider(
|
|
13
|
+
'aiAssistantView', // This must match exactly with the id in package.json
|
|
14
|
+
aiAssistantProvider,
|
|
15
|
+
{
|
|
16
|
+
webviewOptions: {
|
|
17
|
+
retainContextWhenHidden: true,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// Register commands
|
|
24
|
+
context.subscriptions.push(
|
|
25
|
+
vscode.commands.registerCommand('aiAssistant.sendQuery', () => {
|
|
26
|
+
vscode.window.showInputBox({
|
|
27
|
+
placeHolder: 'Enter your question for the AI Assistant',
|
|
28
|
+
prompt: 'Press Enter to send'
|
|
29
|
+
}).then((query: string | undefined) => {
|
|
30
|
+
if (query) {
|
|
31
|
+
aiAssistantProvider.sendQueryToAI(query);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
context.subscriptions.push(
|
|
38
|
+
vscode.commands.registerCommand('aiAssistant.clear', () => {
|
|
39
|
+
aiAssistantProvider.clearConversation();
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
context.subscriptions.push(
|
|
44
|
+
vscode.commands.registerCommand('aiAssistant.toggleLanguage', () => {
|
|
45
|
+
aiAssistantProvider.toggleLanguage();
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// Test command to verify file writing
|
|
50
|
+
context.subscriptions.push(
|
|
51
|
+
vscode.commands.registerCommand('aiAssistant.testFileWrite', async () => {
|
|
52
|
+
try {
|
|
53
|
+
const utils = aiAssistantProvider.getAgentUtils();
|
|
54
|
+
await utils.writeFile('test_file.txt', 'This is a test file to verify writing capabilities.');
|
|
55
|
+
vscode.window.showInformationMessage('Test file created successfully!');
|
|
56
|
+
} catch (error) {
|
|
57
|
+
vscode.window.showErrorMessage(`Error creating test file: ${error instanceof Error ? error.message : String(error)}`);
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// Create a status bar item to indicate when AI Assistant is ready
|
|
63
|
+
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
|
|
64
|
+
statusBarItem.text = "$(zap) AI";
|
|
65
|
+
statusBarItem.tooltip = "AI Assistant (Ctrl+L to activate)";
|
|
66
|
+
statusBarItem.command = "aiAssistant.showView";
|
|
67
|
+
statusBarItem.show();
|
|
68
|
+
context.subscriptions.push(statusBarItem);
|
|
69
|
+
|
|
70
|
+
// Register command to show the AI Assistant view
|
|
71
|
+
context.subscriptions.push(
|
|
72
|
+
vscode.commands.registerCommand('aiAssistant.showView', async () => {
|
|
73
|
+
try {
|
|
74
|
+
// First try to focus the view directly
|
|
75
|
+
await vscode.commands.executeCommand('aiAssistantView.focus');
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error('Error focusing AI Assistant view:', error);
|
|
78
|
+
|
|
79
|
+
// If that fails, try to show the view container first
|
|
80
|
+
try {
|
|
81
|
+
await vscode.commands.executeCommand('workbench.view.extension.ai-assistant-view');
|
|
82
|
+
|
|
83
|
+
// Then try to focus the view again
|
|
84
|
+
setTimeout(async () => {
|
|
85
|
+
try {
|
|
86
|
+
await vscode.commands.executeCommand('aiAssistantView.focus');
|
|
87
|
+
} catch (focusError) {
|
|
88
|
+
console.error('Error focusing view after showing container:', focusError);
|
|
89
|
+
}
|
|
90
|
+
}, 100);
|
|
91
|
+
} catch (fallbackError) {
|
|
92
|
+
console.error('Fallback also failed:', fallbackError);
|
|
93
|
+
vscode.window.showErrorMessage('Failed to open AI Assistant view.');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Ensure the view provider is activated immediately
|
|
100
|
+
vscode.commands.executeCommand('setContext', 'aiAssistantViewEnabled', true);
|
|
101
|
+
|
|
102
|
+
// Force activation of the view after a short delay
|
|
103
|
+
setTimeout(() => {
|
|
104
|
+
try {
|
|
105
|
+
vscode.commands.executeCommand('workbench.view.extension.ai-assistant-view');
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('Failed to show AI Assistant view on startup:', error);
|
|
108
|
+
}
|
|
109
|
+
}, 1000);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function deactivate() { }
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"target": "ES2020",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"lib": ["ES2020"],
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"rootDir": "src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"noImplicitAny": false,
|
|
17
|
+
"noUnusedLocals": true,
|
|
18
|
+
"noUnusedParameters": true,
|
|
19
|
+
"noImplicitReturns": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true
|
|
21
|
+
},
|
|
22
|
+
"include": ["src/**/*"],
|
|
23
|
+
"exclude": ["node_modules", ".vscode-test", "bin", "**/*.test.ts"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
/**@type {import('webpack').Configuration}*/
|
|
7
|
+
const config = {
|
|
8
|
+
target: 'node',
|
|
9
|
+
entry: './src/extension.ts',
|
|
10
|
+
output: {
|
|
11
|
+
path: path.resolve(__dirname, 'out'),
|
|
12
|
+
filename: 'extension.js',
|
|
13
|
+
libraryTarget: 'commonjs2'
|
|
14
|
+
},
|
|
15
|
+
devtool: 'source-map',
|
|
16
|
+
externals: {
|
|
17
|
+
vscode: 'commonjs vscode'
|
|
18
|
+
},
|
|
19
|
+
resolve: {
|
|
20
|
+
extensions: ['.ts', '.js']
|
|
21
|
+
},
|
|
22
|
+
module: {
|
|
23
|
+
rules: [
|
|
24
|
+
{
|
|
25
|
+
test: /\.ts$/,
|
|
26
|
+
exclude: /node_modules/,
|
|
27
|
+
use: [
|
|
28
|
+
{
|
|
29
|
+
loader: 'ts-loader',
|
|
30
|
+
options: {
|
|
31
|
+
compilerOptions: {
|
|
32
|
+
module: 'commonjs'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
performance: {
|
|
41
|
+
hints: false
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = config;
|