codecane 1.0.202 → 1.0.204
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/dist/checkpoints/checkpoint-manager.d.ts +35 -13
- package/dist/checkpoints/checkpoint-manager.js +77 -41
- package/dist/checkpoints/checkpoint-manager.js.map +1 -1
- package/dist/checkpoints/file-manager.d.ts +43 -10
- package/dist/checkpoints/file-manager.js +129 -58
- package/dist/checkpoints/file-manager.js.map +1 -1
- package/dist/cli.d.ts +5 -1
- package/dist/cli.js +59 -30
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +5 -4
- package/dist/client.js +24 -13
- package/dist/client.js.map +1 -1
- package/dist/code-map/languages.d.ts +1 -1
- package/dist/code-map/languages.js +22 -19
- package/dist/code-map/languages.js.map +1 -1
- package/dist/code-map/parse.d.ts +1 -1
- package/dist/code-map/parse.js +1 -2
- package/dist/code-map/parse.js.map +1 -1
- package/dist/code-map/tsconfig.tsbuildinfo +1 -1
- package/dist/common/actions.d.ts +54 -54
- package/dist/common/types/agent-state.d.ts +2 -2
- package/dist/common/types/message.d.ts +6 -6
- package/dist/common/types/usage.d.ts +2 -2
- package/dist/common/util/credentials.d.ts +2 -2
- package/dist/common/util/saxy.js +1 -1
- package/dist/common/util/saxy.js.map +1 -1
- package/dist/common/util/string.d.ts +4 -0
- package/dist/common/util/string.js +10 -2
- package/dist/common/util/string.js.map +1 -1
- package/dist/common/websockets/websocket-schema.d.ts +232 -232
- package/dist/index.js +1 -1
- package/dist/menu.js +1 -1
- package/dist/menu.js.map +1 -1
- package/dist/project-files.js +2 -0
- package/dist/project-files.js.map +1 -1
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/logger.js +33 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/terminal.js +1 -1
- package/dist/utils/terminal.js.map +1 -1
- package/dist/workers/checkpoint-worker.d.ts +1 -0
- package/dist/workers/checkpoint-worker.js +47 -0
- package/dist/workers/checkpoint-worker.js.map +1 -0
- package/package.json +1 -1
- package/dist/common/logger.d.ts +0 -1
- package/dist/common/logger.js +0 -7
- package/dist/common/logger.js.map +0 -1
- package/dist/common/util/constants.d.ts +0 -1
- package/dist/common/util/constants.js +0 -7
- package/dist/common/util/constants.js.map +0 -1
- package/dist/common/util/helpers.d.ts +0 -1
- package/dist/common/util/helpers.js +0 -6
- package/dist/common/util/helpers.js.map +0 -1
- package/dist/common/util/token-counter.d.ts +0 -3
- package/dist/common/util/token-counter.js +0 -27
- package/dist/common/util/token-counter.js.map +0 -1
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fs = void 0;
|
|
6
7
|
exports.getBareRepoPath = getBareRepoPath;
|
|
7
8
|
exports.hasUnsavedChanges = hasUnsavedChanges;
|
|
8
9
|
exports.getLatestCommit = getLatestCommit;
|
|
@@ -11,15 +12,21 @@ exports.storeFileState = storeFileState;
|
|
|
11
12
|
exports.restoreFileState = restoreFileState;
|
|
12
13
|
const crypto_1 = require("crypto");
|
|
13
14
|
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
exports.fs = fs_1.default;
|
|
14
16
|
const isomorphic_git_1 = require("isomorphic-git");
|
|
15
17
|
const path_1 = require("path");
|
|
16
18
|
const child_process_1 = require("child_process");
|
|
17
19
|
const project_files_1 = require("../project-files");
|
|
20
|
+
/**
|
|
21
|
+
* Checks if the native git command is available on the system.
|
|
22
|
+
* Caches the result to avoid repeated checks.
|
|
23
|
+
* @returns boolean indicating if git command is available
|
|
24
|
+
*/
|
|
18
25
|
let cachedGitAvailable = null;
|
|
19
26
|
function gitCommandIsAvailable() {
|
|
20
27
|
if (cachedGitAvailable === null) {
|
|
21
28
|
try {
|
|
22
|
-
(0, child_process_1.execFileSync)('git', ['--version']);
|
|
29
|
+
(0, child_process_1.execFileSync)('git', ['--version'], { stdio: 'ignore' });
|
|
23
30
|
cachedGitAvailable = true;
|
|
24
31
|
}
|
|
25
32
|
catch (error) {
|
|
@@ -28,10 +35,24 @@ function gitCommandIsAvailable() {
|
|
|
28
35
|
}
|
|
29
36
|
return cachedGitAvailable;
|
|
30
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Generates a unique path for storing the bare git repository based on the project directory.
|
|
40
|
+
* Uses SHA-256 hashing to create a unique identifier.
|
|
41
|
+
* @param dir - The project directory path to hash
|
|
42
|
+
* @returns The full path where the bare repo should be stored
|
|
43
|
+
*/
|
|
31
44
|
function getBareRepoPath(dir) {
|
|
32
45
|
const bareRepoName = (0, crypto_1.createHash)('sha256').update(dir).digest('hex');
|
|
33
46
|
return (0, path_1.join)((0, project_files_1.getProjectDataDir)(), bareRepoName);
|
|
34
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Checks if there are any uncommitted changes in the working directory.
|
|
50
|
+
* First attempts to use native git commands, falling back to isomorphic-git if unavailable.
|
|
51
|
+
* @param projectDir - The working tree directory path
|
|
52
|
+
* @param bareRepoPath - The bare git repository path
|
|
53
|
+
* @param relativeFilepaths - Array of file paths relative to projectDir to check
|
|
54
|
+
* @returns Promise resolving to true if there are uncommitted changes, false otherwise
|
|
55
|
+
*/
|
|
35
56
|
async function hasUnsavedChanges({ projectDir, bareRepoPath, relativeFilepaths, }) {
|
|
36
57
|
if (gitCommandIsAvailable()) {
|
|
37
58
|
try {
|
|
@@ -61,15 +82,16 @@ async function hasUnsavedChanges({ projectDir, bareRepoPath, relativeFilepaths,
|
|
|
61
82
|
}
|
|
62
83
|
return false;
|
|
63
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets the hash of the latest commit in the repository.
|
|
87
|
+
* First attempts to use native git commands, falling back to isomorphic-git if unavailable.
|
|
88
|
+
* @param bareRepoPath - The bare git repository path
|
|
89
|
+
* @returns Promise resolving to the commit hash
|
|
90
|
+
*/
|
|
64
91
|
async function getLatestCommit({ bareRepoPath, }) {
|
|
65
92
|
if (gitCommandIsAvailable()) {
|
|
66
93
|
try {
|
|
67
|
-
return (0, child_process_1.execFileSync)('git', [
|
|
68
|
-
'--git-dir',
|
|
69
|
-
bareRepoPath,
|
|
70
|
-
'rev-parse',
|
|
71
|
-
'HEAD',
|
|
72
|
-
])
|
|
94
|
+
return (0, child_process_1.execFileSync)('git', ['--git-dir', bareRepoPath, 'rev-parse', 'HEAD'], { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
73
95
|
.toString()
|
|
74
96
|
.trim();
|
|
75
97
|
}
|
|
@@ -79,21 +101,34 @@ async function getLatestCommit({ bareRepoPath, }) {
|
|
|
79
101
|
}
|
|
80
102
|
return await (0, isomorphic_git_1.resolveRef)({
|
|
81
103
|
fs: fs_1.default,
|
|
82
|
-
|
|
104
|
+
gitdir: bareRepoPath,
|
|
83
105
|
ref: 'HEAD',
|
|
84
106
|
});
|
|
85
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Initializes a bare git repository for tracking file changes.
|
|
110
|
+
* Creates the repository if it doesn't exist, otherwise uses the existing one.
|
|
111
|
+
* Makes an initial commit of the current file state.
|
|
112
|
+
* @param projectDir - The working tree directory path
|
|
113
|
+
* @param relativeFilepaths - Array of file paths relative to projectDir to track
|
|
114
|
+
*/
|
|
86
115
|
async function initializeCheckpointFileManager({ projectDir, relativeFilepaths, }) {
|
|
87
116
|
const bareRepoPath = getBareRepoPath(projectDir);
|
|
88
117
|
// Create the bare repo directory if it doesn't exist
|
|
89
118
|
fs_1.default.mkdirSync(bareRepoPath, { recursive: true });
|
|
90
119
|
try {
|
|
91
120
|
// Check if it's already a valid Git repo
|
|
92
|
-
await (0, isomorphic_git_1.resolveRef)({ fs: fs_1.default,
|
|
121
|
+
await (0, isomorphic_git_1.resolveRef)({ fs: fs_1.default, gitdir: bareRepoPath, ref: 'HEAD' });
|
|
93
122
|
}
|
|
94
123
|
catch (error) {
|
|
95
124
|
// Bare repo doesn't exist yet
|
|
96
|
-
await (0, isomorphic_git_1.init)({
|
|
125
|
+
await (0, isomorphic_git_1.init)({
|
|
126
|
+
fs: fs_1.default,
|
|
127
|
+
dir: projectDir,
|
|
128
|
+
gitdir: bareRepoPath,
|
|
129
|
+
bare: true,
|
|
130
|
+
defaultBranch: 'master',
|
|
131
|
+
});
|
|
97
132
|
}
|
|
98
133
|
// Commit the files in the bare repo
|
|
99
134
|
await storeFileState({
|
|
@@ -103,7 +138,14 @@ async function initializeCheckpointFileManager({ projectDir, relativeFilepaths,
|
|
|
103
138
|
relativeFilepaths,
|
|
104
139
|
});
|
|
105
140
|
}
|
|
106
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Stages all changes in the working directory.
|
|
143
|
+
* First attempts to use native git commands, falling back to isomorphic-git if unavailable.
|
|
144
|
+
* @param projectDir - The working tree directory path
|
|
145
|
+
* @param bareRepoPath - The bare git repository path
|
|
146
|
+
* @param relativeFilepaths - Array of file paths relative to projectDir to stage
|
|
147
|
+
*/
|
|
148
|
+
async function gitAddAll({ projectDir, bareRepoPath, relativeFilepaths, }) {
|
|
107
149
|
if (gitCommandIsAvailable()) {
|
|
108
150
|
try {
|
|
109
151
|
(0, child_process_1.execFileSync)('git', [
|
|
@@ -115,11 +157,11 @@ async function stageFiles({ projectDir, bareRepoPath, relativeFilepaths, }) {
|
|
|
115
157
|
projectDir,
|
|
116
158
|
'add',
|
|
117
159
|
'.',
|
|
118
|
-
]);
|
|
160
|
+
], { stdio: 'ignore' });
|
|
119
161
|
return;
|
|
120
162
|
}
|
|
121
163
|
catch (error) {
|
|
122
|
-
// Failed to add
|
|
164
|
+
// Failed to `git add .`
|
|
123
165
|
}
|
|
124
166
|
}
|
|
125
167
|
// Stage files with isomorphic-git
|
|
@@ -154,41 +196,72 @@ async function stageFiles({ projectDir, bareRepoPath, relativeFilepaths, }) {
|
|
|
154
196
|
}
|
|
155
197
|
}
|
|
156
198
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
199
|
+
async function gitCommit({ projectDir, bareRepoPath, message, }) {
|
|
200
|
+
if (gitCommandIsAvailable()) {
|
|
201
|
+
try {
|
|
202
|
+
(0, child_process_1.execFileSync)('git', [
|
|
203
|
+
'--git-dir',
|
|
204
|
+
bareRepoPath,
|
|
205
|
+
'--work-tree',
|
|
206
|
+
projectDir,
|
|
207
|
+
'commit',
|
|
208
|
+
'-m',
|
|
209
|
+
message,
|
|
210
|
+
], { stdio: 'ignore' });
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
// Failed to commit, continue to isomorphic-git implementation
|
|
214
|
+
}
|
|
215
|
+
}
|
|
169
216
|
const commitHash = await (0, isomorphic_git_1.commit)({
|
|
170
217
|
fs: fs_1.default,
|
|
171
218
|
dir: projectDir,
|
|
172
219
|
gitdir: bareRepoPath,
|
|
173
220
|
author: { name: 'codebuff' },
|
|
174
|
-
ref: 'refs/heads/master',
|
|
175
221
|
message,
|
|
222
|
+
ref: '/refs/heads/master',
|
|
176
223
|
});
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
224
|
+
if (gitCommandIsAvailable()) {
|
|
225
|
+
try {
|
|
226
|
+
(0, child_process_1.execFileSync)('git', [
|
|
227
|
+
'--git-dir',
|
|
228
|
+
bareRepoPath,
|
|
229
|
+
'--work-tree',
|
|
230
|
+
projectDir,
|
|
231
|
+
'checkout',
|
|
232
|
+
'master',
|
|
233
|
+
], { stdio: 'ignore' });
|
|
234
|
+
}
|
|
235
|
+
catch (error) { }
|
|
236
|
+
}
|
|
237
|
+
await (0, isomorphic_git_1.checkout)({ fs: fs_1.default, dir: projectDir, gitdir: bareRepoPath, ref: 'master' });
|
|
183
238
|
return commitHash;
|
|
184
239
|
}
|
|
185
240
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* @param
|
|
190
|
-
* @param
|
|
191
|
-
* @param
|
|
241
|
+
* Creates a new commit with the current state of all tracked files.
|
|
242
|
+
* Stages all changes and creates a commit with the specified message.
|
|
243
|
+
* @param projectDir - The working tree directory path
|
|
244
|
+
* @param bareRepoPath - The bare git repository path
|
|
245
|
+
* @param message - The commit message
|
|
246
|
+
* @param relativeFilepaths - Array of file paths relative to projectDir to commit
|
|
247
|
+
* @returns Promise resolving to the new commit's hash
|
|
248
|
+
*/
|
|
249
|
+
async function storeFileState({ projectDir, bareRepoPath, message, relativeFilepaths: relativeFilepaths, }) {
|
|
250
|
+
await gitAddAll({
|
|
251
|
+
projectDir,
|
|
252
|
+
bareRepoPath,
|
|
253
|
+
relativeFilepaths,
|
|
254
|
+
});
|
|
255
|
+
return await gitCommit({ projectDir, bareRepoPath, message });
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Restores the working directory and index to match the specified commit.
|
|
259
|
+
* Equivalent to `git reset --hard`
|
|
260
|
+
* First attempts to use native git commands, falling back to isomorphic-git if unavailable.
|
|
261
|
+
* @param projectDir - The working tree directory path
|
|
262
|
+
* @param bareRepoPath - The bare git repository path
|
|
263
|
+
* @param commit - The commit hash to restore to
|
|
264
|
+
* @param relativeFilepaths - Array of file paths relative to projectDir to restore
|
|
192
265
|
*/
|
|
193
266
|
async function restoreFileState({ projectDir, bareRepoPath, commit, relativeFilepaths, }) {
|
|
194
267
|
let resetDone = false;
|
|
@@ -203,30 +276,28 @@ async function restoreFileState({ projectDir, bareRepoPath, commit, relativeFile
|
|
|
203
276
|
'--hard',
|
|
204
277
|
commit,
|
|
205
278
|
]);
|
|
206
|
-
|
|
279
|
+
return;
|
|
207
280
|
}
|
|
208
281
|
catch (error) {
|
|
209
282
|
// Failed to use git, continue to isomorphic-git implementation
|
|
210
283
|
}
|
|
211
284
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
})));
|
|
230
|
-
}
|
|
285
|
+
// Update the working directory to reflect the specified commit
|
|
286
|
+
await (0, isomorphic_git_1.checkout)({
|
|
287
|
+
fs: fs_1.default,
|
|
288
|
+
dir: projectDir,
|
|
289
|
+
gitdir: bareRepoPath,
|
|
290
|
+
ref: commit,
|
|
291
|
+
filepaths: relativeFilepaths,
|
|
292
|
+
force: true,
|
|
293
|
+
});
|
|
294
|
+
// Reset the index to match the specified commit
|
|
295
|
+
await Promise.all(relativeFilepaths.map((filepath) => (0, isomorphic_git_1.resetIndex)({
|
|
296
|
+
fs: fs_1.default,
|
|
297
|
+
dir: projectDir,
|
|
298
|
+
gitdir: bareRepoPath,
|
|
299
|
+
filepath,
|
|
300
|
+
ref: commit,
|
|
301
|
+
})));
|
|
231
302
|
}
|
|
232
303
|
//# sourceMappingURL=file-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-manager.js","sourceRoot":"","sources":["../../src/checkpoints/file-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-manager.js","sourceRoot":"","sources":["../../src/checkpoints/file-manager.ts"],"names":[],"mappings":";;;;;;AA0CA,0CAGC;AAUD,8CAoCC;AAQD,0CAuBC;AASD,0EAiCC;AA8ID,wCAkBC;AAWD,4CAmDC;AAlYD,mCAAmC;AACnC,4CAAmB;AAoYV,aApYF,YAAE,CAoYE;AAnYX,mDASuB;AACvB,+BAA2B;AAC3B,iDAA4C;AAE5C,oDAAoD;AAEpD;;;;GAIG;AACH,IAAI,kBAAkB,GAAmB,IAAI,CAAA;AAC7C,SAAS,qBAAqB;IAC5B,IAAI,kBAAkB,KAAK,IAAI,EAAE,C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ACT,EAAE,EAAF,YAAE;QACF,GAAG,EAAE,UAAU;QACf,MAAM,EAAE,YAAY;QACpB,QAAQ;QACR,GAAG,EAAE,MAAM;KACZ,CAAC,CACH,CACF,CAAA;AACH,CAAC"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -18,11 +18,15 @@ export declare class CLI {
|
|
|
18
18
|
private initReadlineInterface;
|
|
19
19
|
private completer;
|
|
20
20
|
private setPrompt;
|
|
21
|
+
/**
|
|
22
|
+
* Prompts the user with a clean prompt state
|
|
23
|
+
*/
|
|
24
|
+
private freshPrompt;
|
|
21
25
|
printInitialPrompt(initialInput?: string): Promise<void>;
|
|
22
26
|
printDiff(): Promise<void>;
|
|
23
27
|
private handleLine;
|
|
24
28
|
private handleUserInput;
|
|
25
|
-
private
|
|
29
|
+
private saveCheckpoint;
|
|
26
30
|
private processCommand;
|
|
27
31
|
private forwardUserInput;
|
|
28
32
|
private returnControlToUser;
|
package/dist/cli.js
CHANGED
|
@@ -40,6 +40,7 @@ const spinner_1 = require("./utils/spinner");
|
|
|
40
40
|
const terminal_1 = require("./utils/terminal");
|
|
41
41
|
const web_scraper_1 = require("./web-scraper");
|
|
42
42
|
const assert_1 = require("assert");
|
|
43
|
+
const restoreCheckpointRegex = /^checkpoint\s+(\d+)$/;
|
|
43
44
|
class CLI {
|
|
44
45
|
client;
|
|
45
46
|
readyPromise;
|
|
@@ -124,6 +125,16 @@ class CLI {
|
|
|
124
125
|
setPrompt() {
|
|
125
126
|
this.rl.setPrompt((0, picocolors_1.green)(`${(0, path_1.parse)((0, project_files_1.getProjectRoot)()).base} > `));
|
|
126
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Prompts the user with a clean prompt state
|
|
130
|
+
*/
|
|
131
|
+
freshPrompt() {
|
|
132
|
+
spinner_1.Spinner.get().stop();
|
|
133
|
+
readline.cursorTo(process.stdout, 0);
|
|
134
|
+
this.rl.line = '';
|
|
135
|
+
this.setPrompt();
|
|
136
|
+
this.rl.prompt();
|
|
137
|
+
}
|
|
127
138
|
async printInitialPrompt(initialInput) {
|
|
128
139
|
if (this.client.user) {
|
|
129
140
|
(0, menu_1.displayGreeting)(this.costMode, this.client.user.name);
|
|
@@ -133,7 +144,7 @@ class CLI {
|
|
|
133
144
|
await this.client.login();
|
|
134
145
|
return;
|
|
135
146
|
}
|
|
136
|
-
this.
|
|
147
|
+
this.freshPrompt();
|
|
137
148
|
if (initialInput) {
|
|
138
149
|
process.stdout.write(initialInput + '\n');
|
|
139
150
|
this.handleUserInput(initialInput);
|
|
@@ -141,7 +152,7 @@ class CLI {
|
|
|
141
152
|
}
|
|
142
153
|
async printDiff() {
|
|
143
154
|
this.handleDiff();
|
|
144
|
-
this.
|
|
155
|
+
this.freshPrompt();
|
|
145
156
|
}
|
|
146
157
|
async handleLine(line) {
|
|
147
158
|
this.detectPasting();
|
|
@@ -167,34 +178,35 @@ class CLI {
|
|
|
167
178
|
}
|
|
168
179
|
await this.forwardUserInput(userInput);
|
|
169
180
|
}
|
|
170
|
-
async
|
|
181
|
+
async saveCheckpoint(userInput) {
|
|
182
|
+
if (checkpoint_manager_1.checkpointManager.disabledReason !== null) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
171
185
|
spinner_1.Spinner.get().start();
|
|
172
186
|
await this.readyPromise;
|
|
173
187
|
spinner_1.Spinner.get().stop();
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
console.log((0, picocolors_1.green)(`Checkpoint #${checkpoint.id} saved!`));
|
|
181
|
-
}
|
|
188
|
+
// Make sure the previous checkpoint is done
|
|
189
|
+
await checkpoint_manager_1.checkpointManager.getLatestCheckpoint()?.fileStateIdPromise;
|
|
190
|
+
// Save the current agent state
|
|
191
|
+
const checkpoint = await checkpoint_manager_1.checkpointManager.addCheckpoint(this.client.agentState, userInput);
|
|
192
|
+
if (checkpoint) {
|
|
193
|
+
console.log(`[checkpoint #${checkpoint.id} saved]`);
|
|
182
194
|
}
|
|
183
195
|
}
|
|
184
196
|
async processCommand(userInput) {
|
|
185
|
-
await this.beforeProcessCommand(userInput);
|
|
186
197
|
if (userInput === 'help' || userInput === 'h') {
|
|
187
198
|
(0, menu_1.displayMenu)();
|
|
188
|
-
this.
|
|
199
|
+
this.freshPrompt();
|
|
189
200
|
return true;
|
|
190
201
|
}
|
|
191
202
|
if (userInput === 'login' || userInput === 'signin') {
|
|
192
203
|
await this.client.login();
|
|
204
|
+
checkpoint_manager_1.checkpointManager.clearCheckpoints();
|
|
193
205
|
return true;
|
|
194
206
|
}
|
|
195
207
|
if (userInput === 'logout' || userInput === 'signout') {
|
|
196
208
|
await this.client.logout();
|
|
197
|
-
this.
|
|
209
|
+
this.freshPrompt();
|
|
198
210
|
return true;
|
|
199
211
|
}
|
|
200
212
|
if (userInput.startsWith('ref-')) {
|
|
@@ -206,6 +218,7 @@ class CLI {
|
|
|
206
218
|
return true;
|
|
207
219
|
}
|
|
208
220
|
if (userInput === 'undo' || userInput === 'u') {
|
|
221
|
+
await this.saveCheckpoint(userInput);
|
|
209
222
|
this.handleUndo();
|
|
210
223
|
return true;
|
|
211
224
|
}
|
|
@@ -215,7 +228,7 @@ class CLI {
|
|
|
215
228
|
}
|
|
216
229
|
if (['diff', 'doff', 'dif', 'iff', 'd'].includes(userInput)) {
|
|
217
230
|
this.handleDiff();
|
|
218
|
-
this.
|
|
231
|
+
this.freshPrompt();
|
|
219
232
|
return true;
|
|
220
233
|
}
|
|
221
234
|
if (userInput === 'uuddlrlrba' ||
|
|
@@ -226,12 +239,14 @@ class CLI {
|
|
|
226
239
|
}
|
|
227
240
|
// Checkpoint commands
|
|
228
241
|
if (userInput === 'checkpoint list' || userInput === 'checkpoints') {
|
|
242
|
+
await this.saveCheckpoint(userInput);
|
|
229
243
|
this.handleCheckpoints();
|
|
230
244
|
return true;
|
|
231
245
|
}
|
|
232
|
-
const restoreMatch = userInput.match(
|
|
246
|
+
const restoreMatch = userInput.match(restoreCheckpointRegex);
|
|
233
247
|
if (restoreMatch) {
|
|
234
248
|
const id = parseInt(restoreMatch[1], 10);
|
|
249
|
+
await this.saveCheckpoint(userInput);
|
|
235
250
|
await this.handleRestoreCheckpoint(id);
|
|
236
251
|
return true;
|
|
237
252
|
}
|
|
@@ -242,6 +257,7 @@ class CLI {
|
|
|
242
257
|
return false;
|
|
243
258
|
}
|
|
244
259
|
async forwardUserInput(userInput) {
|
|
260
|
+
await this.saveCheckpoint(userInput);
|
|
245
261
|
spinner_1.Spinner.get().start();
|
|
246
262
|
this.client.lastChanges = [];
|
|
247
263
|
const urls = (0, web_scraper_1.parseUrlsFromContent)(userInput);
|
|
@@ -266,15 +282,14 @@ class CLI {
|
|
|
266
282
|
}
|
|
267
283
|
this.client.showUsageWarning();
|
|
268
284
|
console.log();
|
|
269
|
-
this.
|
|
285
|
+
this.freshPrompt();
|
|
270
286
|
}
|
|
271
287
|
returnControlToUser() {
|
|
272
|
-
this.
|
|
288
|
+
this.freshPrompt();
|
|
273
289
|
this.isReceivingResponse = false;
|
|
274
290
|
if (this.stopResponse) {
|
|
275
291
|
this.stopResponse();
|
|
276
292
|
}
|
|
277
|
-
spinner_1.Spinner.get().stop();
|
|
278
293
|
}
|
|
279
294
|
onWebSocketError() {
|
|
280
295
|
spinner_1.Spinner.get().stop();
|
|
@@ -290,11 +305,22 @@ class CLI {
|
|
|
290
305
|
this.returnControlToUser();
|
|
291
306
|
}
|
|
292
307
|
async handleUndo() {
|
|
308
|
+
if (checkpoint_manager_1.checkpointManager.disabledReason !== null) {
|
|
309
|
+
console.log((0, picocolors_1.red)(`Checkpoints not enabled: ${checkpoint_manager_1.checkpointManager.disabledReason}`));
|
|
310
|
+
this.freshPrompt();
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const checkpoint = checkpoint_manager_1.checkpointManager.getLatestCheckpoint();
|
|
314
|
+
if (checkpoint === null) {
|
|
315
|
+
console.log((0, picocolors_1.red)('Unable to undo: internal error: no checkpoints found'));
|
|
316
|
+
this.freshPrompt();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
293
319
|
// Get previous checkpoint number (not including undo command)
|
|
294
|
-
const checkpointId =
|
|
320
|
+
const checkpointId = checkpoint.id - 1;
|
|
295
321
|
if (checkpointId < 1) {
|
|
296
322
|
console.log((0, picocolors_1.red)('Nothing to undo.'));
|
|
297
|
-
this.
|
|
323
|
+
this.freshPrompt();
|
|
298
324
|
return;
|
|
299
325
|
}
|
|
300
326
|
await this.handleRestoreCheckpoint(checkpointId);
|
|
@@ -337,7 +363,7 @@ class CLI {
|
|
|
337
363
|
else {
|
|
338
364
|
this.lastSigintTime = now;
|
|
339
365
|
console.log('\nPress Ctrl-C again to exit');
|
|
340
|
-
this.
|
|
366
|
+
this.freshPrompt();
|
|
341
367
|
}
|
|
342
368
|
}
|
|
343
369
|
}
|
|
@@ -533,18 +559,18 @@ class CLI {
|
|
|
533
559
|
// Checkpoint command handlers
|
|
534
560
|
async handleCheckpoints() {
|
|
535
561
|
console.log(checkpoint_manager_1.checkpointManager.getCheckpointsAsString());
|
|
536
|
-
this.
|
|
562
|
+
this.freshPrompt();
|
|
537
563
|
}
|
|
538
564
|
async handleRestoreCheckpoint(id) {
|
|
539
|
-
if (
|
|
540
|
-
console.log((0, picocolors_1.red)(`Checkpoints not enabled:
|
|
541
|
-
this.
|
|
565
|
+
if (checkpoint_manager_1.checkpointManager.disabledReason !== null) {
|
|
566
|
+
console.log((0, picocolors_1.red)(`Checkpoints not enabled: ${checkpoint_manager_1.checkpointManager.disabledReason}`));
|
|
567
|
+
this.freshPrompt();
|
|
542
568
|
return;
|
|
543
569
|
}
|
|
544
570
|
const checkpoint = checkpoint_manager_1.checkpointManager.checkpoints[id - 1];
|
|
545
571
|
if (!checkpoint) {
|
|
546
572
|
console.log((0, picocolors_1.red)(`Checkpoint #${id} not found.`));
|
|
547
|
-
this.
|
|
573
|
+
this.freshPrompt();
|
|
548
574
|
return;
|
|
549
575
|
}
|
|
550
576
|
// Wait for save before trying to restore checkpoint
|
|
@@ -553,8 +579,10 @@ class CLI {
|
|
|
553
579
|
await this.restoreAgentStateAndFiles(checkpoint);
|
|
554
580
|
console.log((0, picocolors_1.green)(`Restored to checkpoint #${id}.`));
|
|
555
581
|
// Insert the original user input that created this checkpoint
|
|
556
|
-
this.
|
|
557
|
-
|
|
582
|
+
this.freshPrompt();
|
|
583
|
+
if (!checkpoint.userInput.match(restoreCheckpointRegex)) {
|
|
584
|
+
this.rl.write(checkpoint.userInput);
|
|
585
|
+
}
|
|
558
586
|
}
|
|
559
587
|
async restoreAgentStateAndFiles(checkpoint) {
|
|
560
588
|
// Restore the agentState
|
|
@@ -568,7 +596,8 @@ class CLI {
|
|
|
568
596
|
}
|
|
569
597
|
async handleClearCheckpoints() {
|
|
570
598
|
checkpoint_manager_1.checkpointManager.clearCheckpoints();
|
|
571
|
-
|
|
599
|
+
console.log('Cleared all checkpoints.');
|
|
600
|
+
this.freshPrompt();
|
|
572
601
|
}
|
|
573
602
|
}
|
|
574
603
|
exports.CLI = CLI;
|