@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
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source and Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright (c) 2026 bniladridas
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/Makefile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
.PHONY: build install uninstall clean
|
|
2
|
+
|
|
3
|
+
PREFIX ?= /usr/local
|
|
4
|
+
|
|
5
|
+
build:
|
|
6
|
+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
|
7
|
+
cmake --build build --config Release
|
|
8
|
+
|
|
9
|
+
install: build
|
|
10
|
+
@if [ -w "$(PREFIX)/bin" ] 2>/dev/null; then \
|
|
11
|
+
install -d $(PREFIX)/bin; \
|
|
12
|
+
install build/bin/cursor-agent $(PREFIX)/bin/cursor; \
|
|
13
|
+
else \
|
|
14
|
+
echo "Need root access to install to $(PREFIX)/bin"; \
|
|
15
|
+
sudo install -d $(PREFIX)/bin; \
|
|
16
|
+
sudo install build/bin/cursor-agent $(PREFIX)/bin/cursor; \
|
|
17
|
+
fi
|
|
18
|
+
@echo "Installed! Run 'cursor' to start."
|
|
19
|
+
|
|
20
|
+
uninstall:
|
|
21
|
+
@if [ -w "$(PREFIX)/bin" ] 2>/dev/null; then \
|
|
22
|
+
rm -f $(PREFIX)/bin/cursor; \
|
|
23
|
+
else \
|
|
24
|
+
sudo rm -f $(PREFIX)/bin/cursor; \
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
clean:
|
|
28
|
+
rm -rf build
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Cursor
|
|
2
|
+
|
|
3
|
+
Cursor is a terminal-based agent for macOS, Linux, and containerized environments.
|
|
4
|
+
|
|
5
|
+
It works with codebases, files, commands, and repositories through a CLI interface.
|
|
6
|
+
|
|
7
|
+
Homebrew:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
brew install cursor
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
npm:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm i -g @bniladridas/cursor
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Build from source:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cmake -S . -B build
|
|
23
|
+
cmake --build build
|
|
24
|
+
./build/cursor-tests
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The project is written in C++20 and uses CMake for building and testing.
|
|
28
|
+
|
|
29
|
+
Source layout:
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
src/
|
|
33
|
+
agent.cpp
|
|
34
|
+
memory_manager.cpp
|
|
35
|
+
services/
|
|
36
|
+
utils/
|
|
37
|
+
|
|
38
|
+
include/
|
|
39
|
+
agent.h
|
|
40
|
+
services/
|
|
41
|
+
utils/
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
License: Apache 2.0
|
|
45
|
+
|
|
46
|
+

|
package/cli.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawn } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
const binaryDir = path.join(__dirname, 'binary');
|
|
7
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
8
|
+
const binary = path.join(binaryDir, `cursor-agent${ext}`);
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(binary)) {
|
|
11
|
+
console.error('cursor binary not found. Run `npm install` to download it.');
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const proc = spawn(binary, process.argv.slice(2), { stdio: 'inherit' });
|
|
16
|
+
proc.on('exit', (code) => process.exit(code));
|
package/include/agent.h
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "agent_mode.h"
|
|
3
|
+
#include "utils/config.h" // For CURSOR_API
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
// Forward declarations for our own types
|
|
9
|
+
|
|
10
|
+
namespace Data {
|
|
11
|
+
class MemoryManager;
|
|
12
|
+
}
|
|
13
|
+
namespace Services {
|
|
14
|
+
class AIService;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
namespace Core {
|
|
18
|
+
class CURSOR_API Agent {
|
|
19
|
+
public:
|
|
20
|
+
using Mode = AgentMode; // Type alias for backward compatibility
|
|
21
|
+
|
|
22
|
+
private:
|
|
23
|
+
Mode mode_{Mode::MODE_UNSET};
|
|
24
|
+
std::string api_key_;
|
|
25
|
+
bool shell_mode_{false};
|
|
26
|
+
// Using raw pointers with PIMPL idiom would be better for ABI stability
|
|
27
|
+
std::unique_ptr<Data::MemoryManager> memory_;
|
|
28
|
+
std::unique_ptr<Services::AIService> ai_service_;
|
|
29
|
+
int command_count_{0};
|
|
30
|
+
long long token_usage_{0};
|
|
31
|
+
|
|
32
|
+
public:
|
|
33
|
+
// Move operations
|
|
34
|
+
Agent(Agent &&) noexcept = default;
|
|
35
|
+
Agent &operator=(Agent &&) noexcept = default;
|
|
36
|
+
|
|
37
|
+
// Disable copying
|
|
38
|
+
Agent(const Agent &) = delete;
|
|
39
|
+
Agent &operator=(const Agent &) = delete;
|
|
40
|
+
|
|
41
|
+
void initialize_mode();
|
|
42
|
+
int get_user_choice(const std::string &prompt,
|
|
43
|
+
const std::vector<int> &valid_choices,
|
|
44
|
+
int default_choice);
|
|
45
|
+
void process_user_input(const std::string &input);
|
|
46
|
+
void handle_direct_command(const std::string &input);
|
|
47
|
+
void handle_ai_chat(const std::string &input);
|
|
48
|
+
void handle_file_injection_command(const std::string &input);
|
|
49
|
+
void handle_shell_command(const std::string &input);
|
|
50
|
+
void handle_meta_command(const std::string &input);
|
|
51
|
+
|
|
52
|
+
// File injection helpers
|
|
53
|
+
std::string process_file_injections(const std::string &input);
|
|
54
|
+
std::string read_file_or_directory(const std::string &path);
|
|
55
|
+
|
|
56
|
+
// Shell mode management
|
|
57
|
+
void toggle_shell_mode();
|
|
58
|
+
|
|
59
|
+
// Helper methods
|
|
60
|
+
bool should_skip_file(const std::string &file_path, const std::string &ext);
|
|
61
|
+
void show_meta_help();
|
|
62
|
+
void clear_screen();
|
|
63
|
+
void handle_chat_management(const std::string &command);
|
|
64
|
+
void show_available_tools();
|
|
65
|
+
void show_memory_context();
|
|
66
|
+
void add_to_memory(const std::string &text);
|
|
67
|
+
void compress_context();
|
|
68
|
+
void show_session_stats();
|
|
69
|
+
void handle_context_management(const std::string &command);
|
|
70
|
+
void handle_multi_file_command(const std::string &command);
|
|
71
|
+
void handle_web_fetch_command(const std::string &command);
|
|
72
|
+
void handle_checkpoint_command(const std::string &command);
|
|
73
|
+
void handle_mcp_command(const std::string &command);
|
|
74
|
+
void handle_theme_command(const std::string &command);
|
|
75
|
+
void handle_auth_command(const std::string &command);
|
|
76
|
+
void handle_sandbox_command(const std::string &command);
|
|
77
|
+
void handle_error_command(const std::string &command);
|
|
78
|
+
|
|
79
|
+
[[nodiscard]] bool is_online_mode() const;
|
|
80
|
+
|
|
81
|
+
Agent();
|
|
82
|
+
~Agent();
|
|
83
|
+
|
|
84
|
+
void run();
|
|
85
|
+
};
|
|
86
|
+
} // namespace Core
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <cstdint>
|
|
3
|
+
|
|
4
|
+
namespace Core {
|
|
5
|
+
enum class AgentMode : std::uint8_t {
|
|
6
|
+
MODE_UNSET = 0,
|
|
7
|
+
MODE_TOGETHER = 1,
|
|
8
|
+
MODE_LLAMA_3B = 2,
|
|
9
|
+
MODE_CEREBRAS = 3,
|
|
10
|
+
MODE_LLAMA_LATEST = 4,
|
|
11
|
+
MODE_LLAMA_31 = 5,
|
|
12
|
+
MODE_FIREWORKS = 6,
|
|
13
|
+
MODE_GROQ = 7,
|
|
14
|
+
MODE_DEEPSEEK = 8,
|
|
15
|
+
MODE_OPENAI = 9
|
|
16
|
+
};
|
|
17
|
+
} // namespace Core
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "utils/memory_utils.h"
|
|
3
|
+
#include <chrono>
|
|
4
|
+
#include <deque>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <string_view>
|
|
7
|
+
#include <unordered_map>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace Data {
|
|
11
|
+
struct MemoryEntry {
|
|
12
|
+
std::string content{};
|
|
13
|
+
std::string timestamp{};
|
|
14
|
+
std::string type{}; // "interaction", "fact", "preference", etc.
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
class MemoryManager {
|
|
18
|
+
private:
|
|
19
|
+
std::string memory_file_;
|
|
20
|
+
std::string global_memory_file_;
|
|
21
|
+
|
|
22
|
+
// Memory optimization constants
|
|
23
|
+
static constexpr size_t max_memory_size = 50 * 1024 * 1024; // 50MB
|
|
24
|
+
static constexpr size_t max_entries = 10000; // Maximum number of entries
|
|
25
|
+
static constexpr size_t recent_entries_limit =
|
|
26
|
+
100; // Lazy load recent entries only
|
|
27
|
+
static constexpr size_t lru_cache_size = 500; // LRU cache for parsed data
|
|
28
|
+
|
|
29
|
+
// LRU Cache for parsed entries
|
|
30
|
+
mutable std::unordered_map<size_t, MemoryEntry> entry_cache_;
|
|
31
|
+
mutable std::deque<size_t> lru_order_; // Track access order for LRU
|
|
32
|
+
mutable size_t current_memory_usage_ = 0;
|
|
33
|
+
mutable std::chrono::steady_clock::time_point last_file_check_;
|
|
34
|
+
mutable size_t cached_file_size_ = 0;
|
|
35
|
+
|
|
36
|
+
// Index for efficient searching (O(1) instead of O(n))
|
|
37
|
+
mutable std::unordered_map<std::string, std::vector<size_t>> content_index_;
|
|
38
|
+
mutable bool index_dirty_ = true;
|
|
39
|
+
|
|
40
|
+
void ensure_memory_directory() const;
|
|
41
|
+
std::string get_timestamp() const;
|
|
42
|
+
std::string get_global_memory_path() const;
|
|
43
|
+
void evict_old_entries() const;
|
|
44
|
+
size_t calculate_entry_size(const MemoryEntry &entry) const;
|
|
45
|
+
|
|
46
|
+
// LRU Cache management
|
|
47
|
+
void update_lru_access(size_t entry_id) const;
|
|
48
|
+
void evict_lru_entries() const;
|
|
49
|
+
bool is_cache_valid() const;
|
|
50
|
+
void rebuild_index() const;
|
|
51
|
+
|
|
52
|
+
// Lazy loading helpers
|
|
53
|
+
std::vector<MemoryEntry> load_recent_entries_only() const;
|
|
54
|
+
MemoryEntry parse_entry_from_line(std::string_view line,
|
|
55
|
+
size_t line_number) const;
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
MemoryManager(const std::string &filename = "data/memory.txt");
|
|
59
|
+
|
|
60
|
+
// Basic memory operations (optimized)
|
|
61
|
+
std::vector<std::string>
|
|
62
|
+
load_memory() const; // Legacy - use load_recent_entries_only()
|
|
63
|
+
void save_interaction(const std::string &user_input,
|
|
64
|
+
const std::string &response);
|
|
65
|
+
void clear_memory();
|
|
66
|
+
std::string get_context_string() const; // Uses lazy loading
|
|
67
|
+
size_t get_memory_size() const; // Cached file size check
|
|
68
|
+
|
|
69
|
+
// Enhanced memory operations
|
|
70
|
+
void save_fact(const std::string &fact);
|
|
71
|
+
void save_preference(const std::string &preference);
|
|
72
|
+
std::vector<MemoryEntry> load_structured_memory() const;
|
|
73
|
+
std::string get_facts_context() const;
|
|
74
|
+
std::string get_preferences_context() const;
|
|
75
|
+
|
|
76
|
+
// Global memory (persistent across sessions)
|
|
77
|
+
void save_global_fact(const std::string &fact);
|
|
78
|
+
std::string get_global_context() const;
|
|
79
|
+
void clear_global_memory();
|
|
80
|
+
|
|
81
|
+
// Memory search and management (optimized with indexing)
|
|
82
|
+
std::vector<MemoryEntry>
|
|
83
|
+
search_memory(const std::string &query) const; // O(1) indexed search
|
|
84
|
+
std::vector<MemoryEntry> search_memory_by_type(const std::string &type) const;
|
|
85
|
+
void export_memory(const std::string &filename) const;
|
|
86
|
+
bool import_memory(const std::string &filename);
|
|
87
|
+
|
|
88
|
+
// Memory statistics and monitoring
|
|
89
|
+
size_t get_cache_hit_ratio() const;
|
|
90
|
+
void print_memory_stats() const;
|
|
91
|
+
|
|
92
|
+
// Conversation state management
|
|
93
|
+
void save_conversation_state(const std::string &tag);
|
|
94
|
+
bool resume_conversation_state(const std::string &tag);
|
|
95
|
+
std::vector<std::string> list_conversation_states() const;
|
|
96
|
+
void delete_conversation_state(const std::string &tag);
|
|
97
|
+
|
|
98
|
+
// Context compression
|
|
99
|
+
void compress_memory(const std::string &compressed_summary);
|
|
100
|
+
std::string get_compressible_context() const;
|
|
101
|
+
};
|
|
102
|
+
} // namespace Data
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <nlohmann/json.hpp>
|
|
3
|
+
#include <string>
|
|
4
|
+
|
|
5
|
+
// Forward declarations
|
|
6
|
+
namespace Core {
|
|
7
|
+
enum class AgentMode : std::uint8_t;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
namespace Services {
|
|
11
|
+
class AIService {
|
|
12
|
+
private:
|
|
13
|
+
Core::AgentMode mode_;
|
|
14
|
+
std::string api_key_;
|
|
15
|
+
|
|
16
|
+
[[nodiscard]] bool is_online_mode() const;
|
|
17
|
+
nlohmann::json create_standard_payload(const std::string &model,
|
|
18
|
+
const std::string &user_input,
|
|
19
|
+
const std::string &context);
|
|
20
|
+
nlohmann::json create_payload(const std::string &user_input,
|
|
21
|
+
const std::string &context);
|
|
22
|
+
std::string get_api_url();
|
|
23
|
+
std::string parse_cerebras_stream(const std::string &response);
|
|
24
|
+
|
|
25
|
+
public:
|
|
26
|
+
AIService(Core::AgentMode mode, const std::string &api_key = "");
|
|
27
|
+
|
|
28
|
+
std::string chat(const std::string &user_input, const std::string &context);
|
|
29
|
+
bool is_available();
|
|
30
|
+
};
|
|
31
|
+
} // namespace Services
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <array>
|
|
3
|
+
#include <map>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
namespace Services {
|
|
9
|
+
|
|
10
|
+
struct AuthProvider {
|
|
11
|
+
std::string name{};
|
|
12
|
+
std::string display_name{};
|
|
13
|
+
std::string api_key{};
|
|
14
|
+
std::string base_url{};
|
|
15
|
+
std::string model{};
|
|
16
|
+
bool is_active = false;
|
|
17
|
+
bool is_valid = false;
|
|
18
|
+
std::map<std::string, std::string> additional_config{};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
class AuthService {
|
|
22
|
+
private:
|
|
23
|
+
static constexpr size_t key_size = 32; // 256 bits for AES-256
|
|
24
|
+
static constexpr size_t iv_size = 12; // 96 bits for GCM
|
|
25
|
+
static constexpr size_t tag_size = 16; // 128-bit authentication tag
|
|
26
|
+
static constexpr size_t SALT_SIZE = 32; // 256-bit salt for key derivation
|
|
27
|
+
static constexpr size_t ITERATIONS = 100000; // Key derivation iterations
|
|
28
|
+
|
|
29
|
+
static std::map<std::string, AuthProvider> providers;
|
|
30
|
+
static std::string active_provider;
|
|
31
|
+
static std::vector<unsigned char> encryption_key;
|
|
32
|
+
static std::string key_file_path;
|
|
33
|
+
|
|
34
|
+
static std::string get_auth_config_path();
|
|
35
|
+
static void ensure_auth_directory();
|
|
36
|
+
static std::string encrypt_credential(const std::string &credential);
|
|
37
|
+
static std::string
|
|
38
|
+
decrypt_credential(const std::string &encrypted_credential);
|
|
39
|
+
static void initialize_default_providers();
|
|
40
|
+
|
|
41
|
+
// Secure key management
|
|
42
|
+
static bool initialize_encryption_key();
|
|
43
|
+
static bool load_or_generate_key();
|
|
44
|
+
static bool save_encryption_key();
|
|
45
|
+
static bool derive_key(const std::string &password,
|
|
46
|
+
const std::vector<unsigned char> &salt,
|
|
47
|
+
std::vector<unsigned char> &key);
|
|
48
|
+
static std::vector<unsigned char> generate_random_bytes(size_t length);
|
|
49
|
+
static std::string bytes_to_hex(const std::vector<unsigned char> &bytes);
|
|
50
|
+
static std::vector<unsigned char> hex_to_bytes(const std::string &hex);
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Provider management
|
|
54
|
+
static void initialize();
|
|
55
|
+
static bool add_provider(const AuthProvider &provider);
|
|
56
|
+
static bool remove_provider(const std::string &provider_name);
|
|
57
|
+
static bool set_active_provider(const std::string &provider_name);
|
|
58
|
+
static std::string get_active_provider();
|
|
59
|
+
static std::vector<std::string> list_providers();
|
|
60
|
+
static AuthProvider get_provider_info(const std::string &provider_name);
|
|
61
|
+
|
|
62
|
+
// Credential management
|
|
63
|
+
static bool set_api_key(const std::string &provider_name,
|
|
64
|
+
const std::string &api_key);
|
|
65
|
+
static std::string get_api_key(const std::string &provider_name = "");
|
|
66
|
+
static bool validate_credentials(const std::string &provider_name);
|
|
67
|
+
static void clear_credentials(const std::string &provider_name);
|
|
68
|
+
|
|
69
|
+
// Configuration management
|
|
70
|
+
static bool save_auth_config();
|
|
71
|
+
static bool load_auth_config();
|
|
72
|
+
static bool
|
|
73
|
+
update_provider_config(const std::string &provider_name,
|
|
74
|
+
const std::map<std::string, std::string> &config);
|
|
75
|
+
|
|
76
|
+
// Health checks
|
|
77
|
+
static bool test_provider_connection(const std::string &provider_name);
|
|
78
|
+
static std::string get_provider_status(const std::string &provider_name);
|
|
79
|
+
static void refresh_all_provider_status();
|
|
80
|
+
|
|
81
|
+
// Security utilities
|
|
82
|
+
static bool is_credential_secure();
|
|
83
|
+
static void generate_encryption_key();
|
|
84
|
+
static bool backup_credentials(const std::string &backup_path);
|
|
85
|
+
static bool restore_credentials(const std::string &backup_path);
|
|
86
|
+
};
|
|
87
|
+
} // namespace Services
|