@bniladridas/cursor 0.1.7
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/.clang-tidy +28 -0
- package/.dockerignore +56 -0
- package/.env.example +29 -0
- package/.github/CODEOWNERS +2 -0
- package/.github/ISSUE_TEMPLATE/blank.md +27 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
- package/.github/SECURITY.md +24 -0
- package/.github/codeql/codeql-config.yml +8 -0
- package/.github/dependabot.yml +14 -0
- package/.github/labeler.yml +50 -0
- package/.github/packaging/brand-cursor.png +0 -0
- package/.github/packaging/database/init.sql +48 -0
- package/.github/packaging/docker/Dockerfile +111 -0
- package/.github/packaging/docker/docker-compose.yml +56 -0
- package/.github/packaging/scripts/preflight.sh +413 -0
- package/.github/packaging/scripts/prepare-release.sh +141 -0
- package/.github/packaging/scripts/release.sh +22 -0
- package/.github/packaging/scripts/setup-git-hooks.sh +73 -0
- package/.github/pull_request_template.md +31 -0
- package/.github/signed.json +9 -0
- package/.github/workflows/README.md +23 -0
- package/.github/workflows/ci.yml +181 -0
- package/.github/workflows/cla.yml +33 -0
- package/.github/workflows/formula-sha.yml +63 -0
- package/.github/workflows/issue-response.yml +44 -0
- package/.github/workflows/labeler.yml +42 -0
- package/.github/workflows/pr-body.yml +49 -0
- package/.github/workflows/release.yml +176 -0
- package/.github/workflows/security.yml +94 -0
- package/.github/workflows/stale.yml +38 -0
- package/AGENTS.md +49 -0
- package/CHANGELOG.md +3 -0
- package/CMakeLists.txt +646 -0
- package/Formula/cursor.rb +46 -0
- package/LICENSE +201 -0
- package/Makefile +28 -0
- package/README.md +46 -0
- package/cli.js +16 -0
- package/include/agent.h +86 -0
- package/include/agent_mode.h +17 -0
- package/include/memory_manager.h +102 -0
- package/include/services/ai_service.h +31 -0
- package/include/services/auth_service.h +87 -0
- package/include/services/checkpoint_service.h +69 -0
- package/include/services/codebase_service.h +38 -0
- package/include/services/command_service.h +23 -0
- package/include/services/context_service.h +74 -0
- package/include/services/database_service.h +56 -0
- package/include/services/error_service.h +106 -0
- package/include/services/file_service.h +51 -0
- package/include/services/git_service.h +29 -0
- package/include/services/github_service.h +85 -0
- package/include/services/mcp_service.h +85 -0
- package/include/services/multi_file_service.h +93 -0
- package/include/services/sandbox_service.h +96 -0
- package/include/services/theme_service.h +67 -0
- package/include/services/web_service.h +52 -0
- package/include/utils/config.h +68 -0
- package/include/utils/memory_utils.h +79 -0
- package/include/utils/platform.h +56 -0
- package/include/utils/ui.h +43 -0
- package/include/utils/validation.h +63 -0
- package/include/utils/version.h.in +17 -0
- package/install.js +49 -0
- package/package.json +16 -0
- package/release/checksums.txt +3 -0
- package/release/cursor-linux/cursor_v0.1.7_linux_amd64.tar.gz +0 -0
- package/release/cursor-macos/cursor_v0.1.7_darwin_arm64.tar.gz +0 -0
- package/release/cursor-windows/cursor__windows_amd64.zip +0 -0
- package/src/agent.cpp +2026 -0
- package/src/main.cpp +97 -0
- package/src/memory_manager.cpp +814 -0
- package/src/services/ai_service.cpp +366 -0
- package/src/services/auth_service.cpp +779 -0
- package/src/services/checkpoint_service.cpp +465 -0
- package/src/services/codebase_service.cpp +233 -0
- package/src/services/command_service.cpp +82 -0
- package/src/services/context_service.cpp +348 -0
- package/src/services/database_service.cpp +148 -0
- package/src/services/error_service.cpp +438 -0
- package/src/services/file_service.cpp +349 -0
- package/src/services/git_service.cpp +148 -0
- package/src/services/github_service.cpp +435 -0
- package/src/services/mcp_service.cpp +481 -0
- package/src/services/multi_file_service.cpp +591 -0
- package/src/services/sandbox_service.cpp +678 -0
- package/src/services/theme_service.cpp +429 -0
- package/src/services/web_service.cpp +532 -0
- package/src/utils/config.cpp +77 -0
- package/src/utils/memory_utils.cpp +93 -0
- package/src/utils/ui.cpp +307 -0
- package/src/utils/validation.cpp +306 -0
- package/src/utils/version.cpp +175 -0
- package/tests/e2e/docker-compose.yml +195 -0
- package/tests/e2e/run_e2e_tests.sh +70 -0
- package/tests/e2e/run_tests_in_docker.sh +115 -0
- package/tests/main_test.cpp +16 -0
- package/tests/mocks/mock_ollama.py +98 -0
- package/tests/mocks/start_nginx.sh +64 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <map>
|
|
3
|
+
#include <string>
|
|
4
|
+
#include <vector>
|
|
5
|
+
|
|
6
|
+
namespace Services {
|
|
7
|
+
struct CheckpointInfo {
|
|
8
|
+
std::string id{};
|
|
9
|
+
std::string name{};
|
|
10
|
+
std::string timestamp{};
|
|
11
|
+
std::string description{};
|
|
12
|
+
std::vector<std::string> backed_up_files{};
|
|
13
|
+
size_t total_size{0};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
struct RestoreOptions {
|
|
17
|
+
bool create_backup_before_restore = true;
|
|
18
|
+
bool restore_memory = true;
|
|
19
|
+
bool restore_files = true;
|
|
20
|
+
std::vector<std::string> specific_files; // If empty, restore all
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
class CheckpointService {
|
|
24
|
+
private:
|
|
25
|
+
static std::string get_checkpoints_directory();
|
|
26
|
+
static std::string generate_checkpoint_id();
|
|
27
|
+
static std::string get_timestamp();
|
|
28
|
+
static void ensure_checkpoints_directory();
|
|
29
|
+
static std::vector<std::string>
|
|
30
|
+
get_project_files(const std::string &directory);
|
|
31
|
+
static void backup_file(const std::string &source_path,
|
|
32
|
+
const std::string &backup_path);
|
|
33
|
+
static void restore_file(const std::string &backup_path,
|
|
34
|
+
const std::string &target_path);
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
// Create checkpoint
|
|
38
|
+
static std::string create_checkpoint(const std::string &name,
|
|
39
|
+
const std::string &description = "",
|
|
40
|
+
const std::string &directory = ".");
|
|
41
|
+
|
|
42
|
+
// List checkpoints
|
|
43
|
+
static std::vector<CheckpointInfo> list_checkpoints();
|
|
44
|
+
|
|
45
|
+
// Get checkpoint info
|
|
46
|
+
static CheckpointInfo get_checkpoint_info(const std::string &checkpoint_id);
|
|
47
|
+
|
|
48
|
+
// Restore from checkpoint
|
|
49
|
+
static bool
|
|
50
|
+
restore_checkpoint(const std::string &checkpoint_id,
|
|
51
|
+
const RestoreOptions &options = RestoreOptions{});
|
|
52
|
+
|
|
53
|
+
// Delete checkpoint
|
|
54
|
+
static bool delete_checkpoint(const std::string &checkpoint_id);
|
|
55
|
+
|
|
56
|
+
// Get checkpoint size
|
|
57
|
+
static size_t get_checkpoint_size(const std::string &checkpoint_id);
|
|
58
|
+
|
|
59
|
+
// Cleanup old checkpoints (keep only N most recent)
|
|
60
|
+
static void cleanup_old_checkpoints(size_t keep_count = 10);
|
|
61
|
+
|
|
62
|
+
// Export checkpoint to archive
|
|
63
|
+
static bool export_checkpoint(const std::string &checkpoint_id,
|
|
64
|
+
const std::string &export_path);
|
|
65
|
+
|
|
66
|
+
// Import checkpoint from archive
|
|
67
|
+
static std::string import_checkpoint(const std::string &archive_path);
|
|
68
|
+
};
|
|
69
|
+
} // namespace Services
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <map>
|
|
4
|
+
#include <sstream>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
namespace Services {
|
|
9
|
+
|
|
10
|
+
class CodebaseService {
|
|
11
|
+
public:
|
|
12
|
+
CodebaseService();
|
|
13
|
+
|
|
14
|
+
// Analyze overall codebase structure
|
|
15
|
+
static std::string analyze_structure(const std::string &path);
|
|
16
|
+
|
|
17
|
+
// Find main components and their relationships
|
|
18
|
+
static std::string find_main_components(const std::string &path);
|
|
19
|
+
|
|
20
|
+
// Find TODO/FIXME/HACK comments
|
|
21
|
+
static std::vector<std::string> find_todos(const std::string &path);
|
|
22
|
+
|
|
23
|
+
// Get directory tree structure
|
|
24
|
+
static std::string get_directory_tree(const std::string &path,
|
|
25
|
+
int max_depth = 3);
|
|
26
|
+
|
|
27
|
+
private:
|
|
28
|
+
// Helper methods
|
|
29
|
+
static void build_tree_recursive(const std::string &path,
|
|
30
|
+
std::ostringstream &tree,
|
|
31
|
+
const std::string &prefix, int depth,
|
|
32
|
+
int max_depth);
|
|
33
|
+
static std::map<std::string, int> analyze_file_types(const std::string &path);
|
|
34
|
+
static int count_files_in_directory(const std::string &path);
|
|
35
|
+
static std::vector<std::string> find_key_files(const std::string &path);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
} // namespace Services
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <array>
|
|
3
|
+
#include <cstdio>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
namespace Services {
|
|
7
|
+
class CommandService {
|
|
8
|
+
private:
|
|
9
|
+
static const std::array<std::string, 9> dangerous_commands;
|
|
10
|
+
|
|
11
|
+
// Check if a command is considered dangerous
|
|
12
|
+
static bool is_dangerous_command(const std::string &command);
|
|
13
|
+
|
|
14
|
+
// Internal method to execute a command and capture its output
|
|
15
|
+
static std::string execute_command(const std::string &command,
|
|
16
|
+
std::FILE *pipe);
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
// Execute a shell command and return its output
|
|
20
|
+
// Returns the command output or an error message if execution fails
|
|
21
|
+
static std::string execute(const std::string &command);
|
|
22
|
+
};
|
|
23
|
+
} // namespace Services
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <map>
|
|
3
|
+
#include <string>
|
|
4
|
+
#include <vector>
|
|
5
|
+
|
|
6
|
+
namespace Services {
|
|
7
|
+
|
|
8
|
+
struct ContextFile {
|
|
9
|
+
std::string file_path{};
|
|
10
|
+
std::string content{};
|
|
11
|
+
int priority{0}; // Higher priority = loaded first
|
|
12
|
+
std::string source{}; // "global", "project", "local"
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
class ContextService {
|
|
16
|
+
public:
|
|
17
|
+
// Load hierarchical context from CURSOR.md files
|
|
18
|
+
static std::string
|
|
19
|
+
load_hierarchical_context(const std::string &working_directory = ".");
|
|
20
|
+
|
|
21
|
+
// Find all CURSOR.md files in hierarchy
|
|
22
|
+
static std::vector<ContextFile>
|
|
23
|
+
find_context_files(const std::string &working_directory = ".");
|
|
24
|
+
|
|
25
|
+
// Load global context file
|
|
26
|
+
static ContextFile load_global_context();
|
|
27
|
+
|
|
28
|
+
// Load project context files (from root to current directory)
|
|
29
|
+
static std::vector<ContextFile>
|
|
30
|
+
load_project_context(const std::string &working_directory);
|
|
31
|
+
|
|
32
|
+
// Load local context files (in current directory and subdirectories)
|
|
33
|
+
static std::vector<ContextFile>
|
|
34
|
+
load_local_context(const std::string &working_directory);
|
|
35
|
+
|
|
36
|
+
// Merge context files into single string
|
|
37
|
+
static std::string merge_context_files(const std::vector<ContextFile> &files);
|
|
38
|
+
|
|
39
|
+
// Find project root (directory with .git, package.json, CMakeLists.txt, etc.)
|
|
40
|
+
static std::string
|
|
41
|
+
find_project_root(const std::string &starting_directory = ".");
|
|
42
|
+
|
|
43
|
+
// Check if directory contains project markers
|
|
44
|
+
static bool is_project_root(const std::string &directory);
|
|
45
|
+
|
|
46
|
+
// Refresh context cache
|
|
47
|
+
static void refresh_context_cache();
|
|
48
|
+
|
|
49
|
+
// Get context file template
|
|
50
|
+
static std::string get_context_template();
|
|
51
|
+
|
|
52
|
+
// Create context file in directory
|
|
53
|
+
static bool create_context_file(const std::string &directory,
|
|
54
|
+
const std::string &content = "");
|
|
55
|
+
|
|
56
|
+
private:
|
|
57
|
+
// Cache for loaded context
|
|
58
|
+
static std::map<std::string, std::string> context_cache;
|
|
59
|
+
static std::string cached_working_directory;
|
|
60
|
+
|
|
61
|
+
// Get home directory
|
|
62
|
+
static std::string get_home_directory();
|
|
63
|
+
|
|
64
|
+
// Check if file exists and is readable
|
|
65
|
+
static bool is_readable_file(const std::string &file_path);
|
|
66
|
+
|
|
67
|
+
// Load file content safely
|
|
68
|
+
static std::string load_file_content(const std::string &file_path);
|
|
69
|
+
|
|
70
|
+
// Get relative path for display
|
|
71
|
+
static std::string get_display_path(const std::string &file_path,
|
|
72
|
+
const std::string &base_directory);
|
|
73
|
+
};
|
|
74
|
+
} // namespace Services
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#ifndef DATABASE_SERVICE_H
|
|
2
|
+
#define DATABASE_SERVICE_H
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
#ifdef HAVE_PQXX
|
|
8
|
+
#include <pqxx/pqxx>
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
#ifndef HAVE_PQXX
|
|
12
|
+
namespace pqxx {
|
|
13
|
+
class result {
|
|
14
|
+
public:
|
|
15
|
+
result() {}
|
|
16
|
+
size_t size() const { return 0; }
|
|
17
|
+
// Minimal interface for compatibility
|
|
18
|
+
};
|
|
19
|
+
class connection {
|
|
20
|
+
public:
|
|
21
|
+
connection(const std::string &) {}
|
|
22
|
+
bool is_open() const { return false; }
|
|
23
|
+
std::string dbname() const { return ""; }
|
|
24
|
+
};
|
|
25
|
+
} // namespace pqxx
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
namespace cursor {
|
|
29
|
+
|
|
30
|
+
class DatabaseService {
|
|
31
|
+
public:
|
|
32
|
+
DatabaseService();
|
|
33
|
+
~DatabaseService();
|
|
34
|
+
|
|
35
|
+
bool connect(const std::string &host, int port, const std::string &dbname,
|
|
36
|
+
const std::string &user, const std::string &password);
|
|
37
|
+
void disconnect();
|
|
38
|
+
|
|
39
|
+
bool isConnected() const;
|
|
40
|
+
|
|
41
|
+
// Example methods - extend as needed
|
|
42
|
+
bool executeQuery(const std::string &query,
|
|
43
|
+
const std::vector<std::string> ¶ms = {});
|
|
44
|
+
std::unique_ptr<pqxx::result>
|
|
45
|
+
executeSelect(const std::string &query,
|
|
46
|
+
const std::vector<std::string> ¶ms = {});
|
|
47
|
+
|
|
48
|
+
private:
|
|
49
|
+
#ifdef HAVE_PQXX
|
|
50
|
+
std::unique_ptr<pqxx::connection> connection_;
|
|
51
|
+
#endif
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
} // namespace cursor
|
|
55
|
+
|
|
56
|
+
#endif // DATABASE_SERVICE_H
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <chrono>
|
|
3
|
+
#include <functional>
|
|
4
|
+
#include <map>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
namespace Services {
|
|
9
|
+
|
|
10
|
+
enum class ErrorLevel : std::uint8_t { DEBUG, INFO, WARNING, ERROR, CRITICAL };
|
|
11
|
+
|
|
12
|
+
enum class ErrorCategory : std::uint8_t {
|
|
13
|
+
VALIDATION,
|
|
14
|
+
NETWORK,
|
|
15
|
+
FILE_SYSTEM,
|
|
16
|
+
AUTHENTICATION,
|
|
17
|
+
COMMAND_EXECUTION,
|
|
18
|
+
MEMORY_MANAGEMENT,
|
|
19
|
+
CONFIGURATION,
|
|
20
|
+
UNKNOWN
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
struct ErrorInfo {
|
|
24
|
+
std::string id{};
|
|
25
|
+
ErrorLevel level{ErrorLevel::DEBUG};
|
|
26
|
+
ErrorCategory category{ErrorCategory::VALIDATION};
|
|
27
|
+
std::string message{};
|
|
28
|
+
std::string details{};
|
|
29
|
+
std::string context{};
|
|
30
|
+
std::chrono::system_clock::time_point timestamp{};
|
|
31
|
+
std::vector<std::string> suggestions{};
|
|
32
|
+
std::map<std::string, std::string> metadata{};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
struct ValidationRule {
|
|
36
|
+
std::string name{};
|
|
37
|
+
std::function<bool(const std::string &)> validator{};
|
|
38
|
+
std::string error_message{};
|
|
39
|
+
std::vector<std::string> suggestions{};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
class ErrorService {
|
|
43
|
+
private:
|
|
44
|
+
static std::vector<ErrorInfo> error_log;
|
|
45
|
+
static std::map<std::string, ValidationRule> validation_rules;
|
|
46
|
+
static std::string get_error_log_path();
|
|
47
|
+
static void ensure_error_directory();
|
|
48
|
+
static std::string generate_error_id();
|
|
49
|
+
static void initialize_validation_rules();
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Error logging and management
|
|
53
|
+
static void initialize();
|
|
54
|
+
static std::string
|
|
55
|
+
log_error(ErrorLevel level, ErrorCategory category,
|
|
56
|
+
const std::string &message, const std::string &context = "",
|
|
57
|
+
const std::vector<std::string> &suggestions = {});
|
|
58
|
+
static std::vector<ErrorInfo> get_recent_errors(size_t count = 10);
|
|
59
|
+
static std::vector<ErrorInfo> get_errors_by_level(ErrorLevel level);
|
|
60
|
+
static std::vector<ErrorInfo> get_errors_by_category(ErrorCategory category);
|
|
61
|
+
static void clear_error_log();
|
|
62
|
+
|
|
63
|
+
// Validation framework
|
|
64
|
+
static bool validate_input(const std::string &rule_name,
|
|
65
|
+
const std::string &input,
|
|
66
|
+
std::string &error_message,
|
|
67
|
+
std::vector<std::string> &suggestions);
|
|
68
|
+
static bool validate_file_path(const std::string &path,
|
|
69
|
+
std::string &error_message);
|
|
70
|
+
static bool validate_url(const std::string &url, std::string &error_message);
|
|
71
|
+
static bool validate_command(const std::string &command,
|
|
72
|
+
std::string &error_message);
|
|
73
|
+
static bool validate_api_key(const std::string &api_key,
|
|
74
|
+
std::string &error_message);
|
|
75
|
+
static bool validate_json(const std::string &json_str,
|
|
76
|
+
std::string &error_message);
|
|
77
|
+
|
|
78
|
+
// Error recovery
|
|
79
|
+
static std::vector<std::string>
|
|
80
|
+
suggest_recovery_actions(const std::string &error_id);
|
|
81
|
+
static bool attempt_auto_recovery(const std::string &error_id);
|
|
82
|
+
static void
|
|
83
|
+
register_recovery_handler(ErrorCategory category,
|
|
84
|
+
std::function<bool(const ErrorInfo &)> handler);
|
|
85
|
+
|
|
86
|
+
// Error reporting and formatting
|
|
87
|
+
static std::string format_error(const ErrorInfo &error,
|
|
88
|
+
bool include_suggestions = true);
|
|
89
|
+
static std::string format_error_summary();
|
|
90
|
+
static void print_error_report();
|
|
91
|
+
static bool export_error_log(const std::string &export_path);
|
|
92
|
+
|
|
93
|
+
// Utility functions
|
|
94
|
+
static std::string error_level_to_string(ErrorLevel level);
|
|
95
|
+
static std::string error_category_to_string(ErrorCategory category);
|
|
96
|
+
static ErrorLevel string_to_error_level(const std::string &level_str);
|
|
97
|
+
static ErrorCategory
|
|
98
|
+
string_to_error_category(const std::string &category_str);
|
|
99
|
+
|
|
100
|
+
// Configuration
|
|
101
|
+
static void set_max_log_entries(size_t max_entries);
|
|
102
|
+
static void set_log_level(ErrorLevel min_level);
|
|
103
|
+
static bool save_error_config();
|
|
104
|
+
static bool load_error_config();
|
|
105
|
+
};
|
|
106
|
+
} // namespace Services
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <string>
|
|
3
|
+
#include <vector>
|
|
4
|
+
|
|
5
|
+
namespace Services {
|
|
6
|
+
struct FileSearchResult {
|
|
7
|
+
std::string file_path{};
|
|
8
|
+
int line_number{0};
|
|
9
|
+
std::string line_content{};
|
|
10
|
+
std::string match_context{};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
struct FileEditResult {
|
|
14
|
+
bool success{};
|
|
15
|
+
std::string message{};
|
|
16
|
+
int replacements_made{0};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
class FileService {
|
|
20
|
+
public:
|
|
21
|
+
// Basic file operations
|
|
22
|
+
static std::string read_file(const std::string &filename);
|
|
23
|
+
static std::string read_file_range(const std::string &filename,
|
|
24
|
+
int start_line = 0, int line_count = -1);
|
|
25
|
+
static std::string write_file(const std::string &filename,
|
|
26
|
+
const std::string &content);
|
|
27
|
+
static bool file_exists(const std::string &filename);
|
|
28
|
+
static std::string get_file_extension(const std::string &filename);
|
|
29
|
+
|
|
30
|
+
// Advanced file operations
|
|
31
|
+
static FileEditResult replace_text_in_file(const std::string &filename,
|
|
32
|
+
const std::string &old_text,
|
|
33
|
+
const std::string &new_text,
|
|
34
|
+
int expected_replacements = 1);
|
|
35
|
+
static std::vector<FileSearchResult>
|
|
36
|
+
search_in_file(const std::string &filename, const std::string &pattern,
|
|
37
|
+
bool case_sensitive = false);
|
|
38
|
+
static std::vector<FileSearchResult>
|
|
39
|
+
search_in_directory(const std::string &directory, const std::string &pattern,
|
|
40
|
+
const std::string &file_filter = "*",
|
|
41
|
+
bool case_sensitive = false);
|
|
42
|
+
|
|
43
|
+
// Utility functions
|
|
44
|
+
[[nodiscard]] static bool is_text_file(const std::string &filename);
|
|
45
|
+
static std::string get_relative_path(const std::string &filepath,
|
|
46
|
+
const std::string &base_path);
|
|
47
|
+
static bool is_within_directory(const std::string &filepath,
|
|
48
|
+
const std::string &base_directory);
|
|
49
|
+
static std::string normalize_path(const std::string &path);
|
|
50
|
+
};
|
|
51
|
+
} // namespace Services
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#include <vector>
|
|
5
|
+
|
|
6
|
+
namespace Services {
|
|
7
|
+
|
|
8
|
+
class GitService {
|
|
9
|
+
public:
|
|
10
|
+
GitService();
|
|
11
|
+
|
|
12
|
+
// Check if directory is a git repository
|
|
13
|
+
static bool is_git_repository(const std::string &path);
|
|
14
|
+
|
|
15
|
+
// Get git log for specified number of days
|
|
16
|
+
static std::string get_git_log(const std::string &path, int days = 7);
|
|
17
|
+
|
|
18
|
+
// Get git status
|
|
19
|
+
static std::string get_git_status(const std::string &path);
|
|
20
|
+
|
|
21
|
+
// Get list of files changed in last N days
|
|
22
|
+
static std::vector<std::string> get_changed_files(const std::string &path,
|
|
23
|
+
int days = 7);
|
|
24
|
+
|
|
25
|
+
// Analyze repository structure and recent activity
|
|
26
|
+
static std::string analyze_repository(const std::string &path);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
} // namespace Services
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "services/web_service.h"
|
|
4
|
+
#include <map>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
namespace Services {
|
|
9
|
+
|
|
10
|
+
struct GitHubIssue {
|
|
11
|
+
int number{0};
|
|
12
|
+
std::string title{};
|
|
13
|
+
std::string body{};
|
|
14
|
+
std::string state{};
|
|
15
|
+
std::vector<std::string> labels{};
|
|
16
|
+
std::vector<std::string> assignees{};
|
|
17
|
+
int milestone{0};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
struct GitHubPR {
|
|
21
|
+
int number{0};
|
|
22
|
+
std::string title{};
|
|
23
|
+
std::string body{};
|
|
24
|
+
std::string state{};
|
|
25
|
+
std::string head_branch{};
|
|
26
|
+
std::string base_branch{};
|
|
27
|
+
bool mergeable{false};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class GitHubService {
|
|
31
|
+
private:
|
|
32
|
+
static std::string get_github_token();
|
|
33
|
+
static std::string get_api_base_url();
|
|
34
|
+
static WebResponse make_github_request(const std::string &endpoint,
|
|
35
|
+
const std::string &method = "GET",
|
|
36
|
+
const std::string &body = "");
|
|
37
|
+
|
|
38
|
+
public:
|
|
39
|
+
GitHubService() = delete;
|
|
40
|
+
|
|
41
|
+
static std::string get_repo_info(const std::string &owner,
|
|
42
|
+
const std::string &repo);
|
|
43
|
+
static std::vector<GitHubIssue> get_issues(const std::string &owner,
|
|
44
|
+
const std::string &repo,
|
|
45
|
+
const std::string &state = "open");
|
|
46
|
+
static GitHubIssue create_issue(const std::string &owner,
|
|
47
|
+
const std::string &repo,
|
|
48
|
+
const std::string &title,
|
|
49
|
+
const std::string &body,
|
|
50
|
+
const std::vector<std::string> &labels = {});
|
|
51
|
+
static bool update_issue(const std::string &owner, const std::string &repo,
|
|
52
|
+
int issue_number,
|
|
53
|
+
const std::map<std::string, std::string> &updates);
|
|
54
|
+
static bool add_comment(const std::string &owner, const std::string &repo,
|
|
55
|
+
int issue_number, const std::string &comment);
|
|
56
|
+
static std::vector<GitHubPR>
|
|
57
|
+
get_pull_requests(const std::string &owner, const std::string &repo,
|
|
58
|
+
const std::string &state = "open");
|
|
59
|
+
static GitHubPR get_pull_request(const std::string &owner,
|
|
60
|
+
const std::string &repo, int pr_number);
|
|
61
|
+
static bool create_pr_comment(const std::string &owner,
|
|
62
|
+
const std::string &repo, int pr_number,
|
|
63
|
+
const std::string &comment);
|
|
64
|
+
static std::vector<std::string> get_milestones(const std::string &owner,
|
|
65
|
+
const std::string &repo);
|
|
66
|
+
static int create_milestone(const std::string &owner, const std::string &repo,
|
|
67
|
+
const std::string &title,
|
|
68
|
+
const std::string &description = "");
|
|
69
|
+
static std::vector<std::string> get_labels(const std::string &owner,
|
|
70
|
+
const std::string &repo);
|
|
71
|
+
static bool create_label(const std::string &owner, const std::string &repo,
|
|
72
|
+
const std::string &name, const std::string &color,
|
|
73
|
+
const std::string &description = "");
|
|
74
|
+
static bool create_webhook(const std::string &owner, const std::string &repo,
|
|
75
|
+
const std::string &url,
|
|
76
|
+
const std::vector<std::string> &events);
|
|
77
|
+
static std::string run_health_check(const std::string &owner,
|
|
78
|
+
const std::string &repo);
|
|
79
|
+
static std::string find_related_issues(const std::string &owner,
|
|
80
|
+
const std::string &repo,
|
|
81
|
+
const std::string &text);
|
|
82
|
+
static bool is_available();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
} // namespace Services
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <map>
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <nlohmann/json.hpp>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
namespace Services {
|
|
9
|
+
|
|
10
|
+
struct MCPResource {
|
|
11
|
+
std::string uri{};
|
|
12
|
+
std::string name{};
|
|
13
|
+
std::string description{};
|
|
14
|
+
std::string mime_type{};
|
|
15
|
+
nlohmann::json metadata{};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
struct MCPTool {
|
|
19
|
+
std::string name{};
|
|
20
|
+
std::string description{};
|
|
21
|
+
nlohmann::json input_schema{};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
struct MCPPrompt {
|
|
25
|
+
std::string name{};
|
|
26
|
+
std::string description{};
|
|
27
|
+
std::vector<std::string> arguments{};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
struct MCPServer {
|
|
31
|
+
std::string name{};
|
|
32
|
+
std::string executable{};
|
|
33
|
+
std::vector<std::string> args{};
|
|
34
|
+
std::string working_directory{};
|
|
35
|
+
std::map<std::string, std::string> env_vars{};
|
|
36
|
+
bool is_running = false;
|
|
37
|
+
int process_id = -1;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
class MCPService {
|
|
41
|
+
private:
|
|
42
|
+
static std::map<std::string, MCPServer> servers;
|
|
43
|
+
static std::string get_mcp_config_path();
|
|
44
|
+
static void ensure_mcp_directory();
|
|
45
|
+
static nlohmann::json send_mcp_request(const std::string &server_name,
|
|
46
|
+
const nlohmann::json &request);
|
|
47
|
+
static bool start_mcp_server(const std::string &server_name);
|
|
48
|
+
static bool stop_mcp_server(const std::string &server_name);
|
|
49
|
+
static nlohmann::json
|
|
50
|
+
create_mcp_request(const std::string &method,
|
|
51
|
+
const nlohmann::json ¶ms = nlohmann::json::object());
|
|
52
|
+
|
|
53
|
+
public:
|
|
54
|
+
// Server management
|
|
55
|
+
static bool register_mcp_server(const MCPServer &server);
|
|
56
|
+
static bool unregister_mcp_server(const std::string &server_name);
|
|
57
|
+
static std::vector<std::string> list_mcp_servers();
|
|
58
|
+
static MCPServer get_mcp_server(const std::string &server_name);
|
|
59
|
+
static bool is_server_running(const std::string &server_name);
|
|
60
|
+
|
|
61
|
+
// MCP Protocol operations
|
|
62
|
+
static std::vector<MCPResource>
|
|
63
|
+
list_resources(const std::string &server_name);
|
|
64
|
+
static std::string read_resource(const std::string &server_name,
|
|
65
|
+
const std::string &uri);
|
|
66
|
+
static std::vector<MCPTool> list_tools(const std::string &server_name);
|
|
67
|
+
static nlohmann::json call_tool(const std::string &server_name,
|
|
68
|
+
const std::string &tool_name,
|
|
69
|
+
const nlohmann::json &arguments);
|
|
70
|
+
static std::vector<MCPPrompt> list_prompts(const std::string &server_name);
|
|
71
|
+
static std::string get_prompt(const std::string &server_name,
|
|
72
|
+
const std::string &prompt_name,
|
|
73
|
+
const nlohmann::json &arguments);
|
|
74
|
+
|
|
75
|
+
// Configuration management
|
|
76
|
+
static bool load_server_config();
|
|
77
|
+
static bool save_server_config();
|
|
78
|
+
static void add_default_servers();
|
|
79
|
+
|
|
80
|
+
// Utility functions
|
|
81
|
+
static bool ping_server(const std::string &server_name);
|
|
82
|
+
static std::string get_server_status(const std::string &server_name);
|
|
83
|
+
static void cleanup_dead_servers();
|
|
84
|
+
};
|
|
85
|
+
} // namespace Services
|