From 98bd872ad86f8a4ab6a801cd5824753c7295cd97 Mon Sep 17 00:00:00 2001 From: CakeCN Date: Tue, 19 Aug 2025 20:47:02 +0800 Subject: [PATCH] plugin --- Html/config.ini | 4 +- plugin/raw-AgentHands.js | 191 +++++++++++++++++++++ study/cake/algorithm/binary_search/cake.py | 2 + 3 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 plugin/raw-AgentHands.js create mode 100644 study/cake/algorithm/binary_search/cake.py diff --git a/Html/config.ini b/Html/config.ini index 6e4eecf..15070d8 100644 --- a/Html/config.ini +++ b/Html/config.ini @@ -4,9 +4,9 @@ api_key = sk-B31NVWeWuvbkEnUgA5913e4c63Ac40E7A1B084742299E57f [VSCODE_WEB] -url = http://127.0.0.1:8181 +url = http://127.0.0.1:8181 #http://asengine.net:8282 [VSCODE_WEB_PATH] -is_wsl = true +is_wsl = false windows_path = F:/ wsl_path = /mnt/f/ [USER_DATA] diff --git a/plugin/raw-AgentHands.js b/plugin/raw-AgentHands.js new file mode 100644 index 0000000..cfc43de --- /dev/null +++ b/plugin/raw-AgentHands.js @@ -0,0 +1,191 @@ +const vscode = require('vscode'); +const fs = require('fs'); +const path = require('path'); +const io = require('socket.io-client'); +let debounceTimeout; +let vs_socket= null; +let config = {}; +// 发送数据到 Flask 服务器,并携带 session 作为 Cookie +async function sendToServer(data) { + try { + if (!vs_socket) { + return; + } + // const response = await axios.post('http://localhost:5000/vscode_data', data, { + // }); + // console.log('Data sent to Flask server:', response.data); + vs_socket.emit('message', data) + } catch (error) { + console.error('Error sending data to Flask server:', error); + } +} + + +// Reads and parses key-value pairs from the .config file +function readConfigFile(folderPath) { + const configFilePath = path.join(folderPath, '.config'); + if (!fs.existsSync(configFilePath)) { + vscode.window.showErrorMessage('No .config file found in the workspace folder.'); + return null; + } + + try { + const configContent = fs.readFileSync(configFilePath, 'utf-8'); + return JSON.parse(configContent); + } catch (error) { + console.error('Error reading the .config file:', error); + return null; + } +} +function establishSocketConnection(){ + vscode.window.showInformationMessage('Connecting to server...'); + + vs_socket = io('ws://59.78.194.131:5000/vscode'); + vs_socket.on('connect', () => { + vscode.window.showInformationMessage('Connected to server'); + vs_socket.emit('login', { config: config }); + }); + vs_socket.on('disconnect', () => { + vscode.window.showInformationMessage('Disconnected from server'); + }); + vs_socket.on('terminal',(data)=>{ + vscode.window.showInformationMessage('Terminal command received'+data); + const terminal = vscode.window.createTerminal('New Terminal'); + + // 在终端中执行命令 + terminal.sendText(data.data); + + // 显示终端 + terminal.show(); + }) +} +// 激活插件时调用此函数 +function activate(context) { + const workspaceFolders = vscode.workspace.workspaceFolders; + if (!workspaceFolders) { + vscode.window.showErrorMessage('No workspace folder is open.'); + return; + } + + const folderPath = workspaceFolders[0].uri.fsPath; + config = readConfigFile(folderPath); + if (config) { + console.log('Config file loaded:', config); + establishSocketConnection(); + } + + + vscode.window.onDidChangeActiveTextEditor(editor => { + if (editor) { + const filePath = editor.document.uri.fsPath; + console.log(`Current open file: ${filePath}`); + sendToServer({ + type: 'activeFile', + filePath: filePath, + config: config, + }); + } + }); + + // 监听文件内容变化 + vscode.workspace.onDidChangeTextDocument(event => { + const filePath = event.document.uri.fsPath; + const changes = event.contentChanges; + + // 检查是否有大段文本插入,判断为粘贴操作 + changes.forEach(change => { + if (change.text.length > 20 && !change.rangeLength) { // 设置长度阈值为20字符,且非删除操作 + console.log(`Detected paste action in file ${filePath}. Sending content...`); + + sendToServer({ + type: 'paste', + filePath: filePath, + content: change.text, + config: config, + }); + } + }); + + // 防抖处理非粘贴的编辑操作 + const content = event.document.getText(); + debounceSendToServer({ + type: 'fileEdit', + filePath: filePath, + content: content, + config: config, + }, 5000); + }); + + // 监听工作区的变化 + vscode.workspace.onDidChangeWorkspaceFolders(event => { + console.log('Workspace folders changed'); + const workspaceFolders = vscode.workspace.workspaceFolders; + if (workspaceFolders) { + workspaceFolders.forEach(folder => { + const fileTree = getFileTree(folder.uri); + console.log(`File Tree for ${folder.uri.fsPath}:`, fileTree); + sendToServer({ + type: 'workspaceFolders', + fileTree: fileTree, + config: config, + }); + }); + } + }); + + if (workspaceFolders) { + workspaceFolders.forEach(folder => { + const fileTree = getFileTree(folder.uri); + console.log(`File Tree for ${folder.uri.fsPath}:`, fileTree); + sendToServer({ + type: 'workspaceFolders', + fileTree: fileTree, + config: config, + }); + }); + } +} + +// 缓冲器函数(防抖) +function debounceSendToServer(data, delay) { + if (debounceTimeout) { + clearTimeout(debounceTimeout); + } + debounceTimeout = setTimeout(() => { + sendToServer(data); + }, delay); +} + +// 递归获取文件树 +function getFileTree(uri) { + let result = []; + const files = fs.readdirSync(uri.fsPath); + + files.forEach(file => { + const filePath = path.join(uri.fsPath, file); + const stat = fs.statSync(filePath); + + if (stat.isDirectory()) { + result.push({ + name: file, + type: 'folder', + children: getFileTree(vscode.Uri.file(filePath)) + }); + } else { + result.push({ + name: file, + type: 'file' + }); + } + }); + + return result; +} + +// 禁用插件时调用此函数 +function deactivate() {} + +module.exports = { + activate, + deactivate +}; diff --git a/study/cake/algorithm/binary_search/cake.py b/study/cake/algorithm/binary_search/cake.py new file mode 100644 index 0000000..31afebc --- /dev/null +++ b/study/cake/algorithm/binary_search/cake.py @@ -0,0 +1,2 @@ +123123 +def \ No newline at end of file