codebuff 1.0.176 → 1.0.178
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 +73 -0
- package/dist/checkpoints/checkpoint-manager.js +193 -0
- package/dist/checkpoints/checkpoint-manager.js.map +1 -0
- package/dist/{checkpoint-file-manager.d.ts → checkpoints/file-manager.d.ts} +10 -0
- package/dist/{checkpoint-file-manager.js → checkpoints/file-manager.js} +92 -35
- package/dist/checkpoints/file-manager.js.map +1 -0
- package/dist/cli.js +20 -18
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +7 -6
- package/dist/client.js +20 -15
- package/dist/client.js.map +1 -1
- package/dist/common/actions.d.ts +120 -120
- package/dist/common/advanced-analyzer.d.ts +19 -0
- package/dist/common/advanced-analyzer.js +140 -0
- package/dist/common/advanced-analyzer.js.map +1 -0
- package/dist/common/browser-actions.d.ts +44 -44
- package/dist/common/message-image-handling.d.ts +41 -0
- package/dist/common/message-image-handling.js +57 -0
- package/dist/common/message-image-handling.js.map +1 -0
- package/dist/common/types/agent-state.d.ts +26 -26
- package/dist/common/types/message.d.ts +14 -14
- package/dist/common/types/usage.d.ts +2 -2
- package/dist/common/util/credentials.d.ts +2 -2
- package/dist/common/util/process-stream.d.ts +8 -0
- package/dist/common/util/process-stream.js +102 -0
- package/dist/common/util/process-stream.js.map +1 -0
- package/dist/common/websockets/websocket-schema.d.ts +368 -368
- 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 -2
- package/dist/project-files.js.map +1 -1
- package/dist/workers/checkpoint-worker.js +47 -0
- package/dist/workers/checkpoint-worker.js.map +1 -0
- package/dist/workers/project-context.d.ts +1 -0
- package/dist/{worker-script-project-context.js → workers/project-context.js} +5 -5
- package/dist/workers/project-context.js.map +1 -0
- package/package.json +1 -1
- package/dist/checkpoint-file-manager.js.map +0 -1
- package/dist/checkpoints.d.ts +0 -64
- package/dist/checkpoints.js +0 -162
- package/dist/checkpoints.js.map +0 -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
- package/dist/worker-script-project-context.js.map +0 -1
- /package/dist/{worker-script-project-context.d.ts → workers/checkpoint-worker.d.ts} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AgentState } from '../common/types/agent-state';
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a checkpoint of agent state
|
|
4
|
+
*/
|
|
5
|
+
export interface Checkpoint {
|
|
6
|
+
agentStateString: string;
|
|
7
|
+
/** Promise resolving to the git commit hash for this checkpoint */
|
|
8
|
+
fileStateIdPromise: Promise<string>;
|
|
9
|
+
/** Number of messages in the agent's history at checkpoint time */
|
|
10
|
+
historyLength: number;
|
|
11
|
+
id: number;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
/** User input that triggered this checkpoint */
|
|
14
|
+
userInput: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Manages checkpoints of agent state and file state using git operations in a worker thread.
|
|
18
|
+
* Each checkpoint contains both the agent's conversation state and a git commit
|
|
19
|
+
* representing the state of all tracked files at that point.
|
|
20
|
+
*/
|
|
21
|
+
export declare class CheckpointManager {
|
|
22
|
+
checkpoints: Array<Checkpoint>;
|
|
23
|
+
private bareRepoPath;
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
/** Worker thread for git operations */
|
|
26
|
+
private worker;
|
|
27
|
+
/**
|
|
28
|
+
* Initialize or return the existing worker thread
|
|
29
|
+
* @returns The worker thread instance
|
|
30
|
+
*/
|
|
31
|
+
private initWorker;
|
|
32
|
+
/**
|
|
33
|
+
* Execute an operation in the worker thread with timeout handling
|
|
34
|
+
* @param message - The message describing the operation to perform
|
|
35
|
+
* @returns A promise that resolves with the operation result
|
|
36
|
+
* @throws Error if the operation fails or times out
|
|
37
|
+
*/
|
|
38
|
+
private runWorkerOperation;
|
|
39
|
+
/**
|
|
40
|
+
* Get the path to the bare git repository used for storing file states
|
|
41
|
+
* @returns The bare repo path
|
|
42
|
+
*/
|
|
43
|
+
private getBareRepoPath;
|
|
44
|
+
/**
|
|
45
|
+
* Add a new checkpoint of the current agent and file state
|
|
46
|
+
* @param agentState - The current agent state to checkpoint
|
|
47
|
+
* @param userInput - The user input that triggered this checkpoint
|
|
48
|
+
* @returns The created checkpoint, or null if checkpointing is disabled
|
|
49
|
+
*/
|
|
50
|
+
addCheckpoint(agentState: AgentState, userInput: string): Promise<Checkpoint | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Get the most recent checkpoint
|
|
53
|
+
* @returns The most recent checkpoint or null if none exist
|
|
54
|
+
*/
|
|
55
|
+
getLatestCheckpoint(): Checkpoint | null;
|
|
56
|
+
/**
|
|
57
|
+
* Restore the file state from a specific checkpoint
|
|
58
|
+
* @param id - The ID of the checkpoint to restore
|
|
59
|
+
* @returns True if restoration succeeded, false if checkpoint not found
|
|
60
|
+
*/
|
|
61
|
+
restoreCheckointFileState(id: number): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Clear all checkpoints
|
|
64
|
+
*/
|
|
65
|
+
clearCheckpoints(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Get a formatted string representation of all checkpoints
|
|
68
|
+
* @param detailed Whether to include detailed information about each checkpoint
|
|
69
|
+
* @returns A formatted string representation of all checkpoints
|
|
70
|
+
*/
|
|
71
|
+
getCheckpointsAsString(detailed?: boolean): string;
|
|
72
|
+
}
|
|
73
|
+
export declare const checkpointManager: CheckpointManager;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkpointManager = exports.CheckpointManager = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const picocolors_1 = require("picocolors");
|
|
6
|
+
const worker_threads_1 = require("worker_threads");
|
|
7
|
+
const project_file_tree_1 = require("../common/project-file-tree");
|
|
8
|
+
const file_manager_1 = require("./file-manager");
|
|
9
|
+
const project_files_1 = require("../project-files");
|
|
10
|
+
/**
|
|
11
|
+
* Manages checkpoints of agent state and file state using git operations in a worker thread.
|
|
12
|
+
* Each checkpoint contains both the agent's conversation state and a git commit
|
|
13
|
+
* representing the state of all tracked files at that point.
|
|
14
|
+
*/
|
|
15
|
+
class CheckpointManager {
|
|
16
|
+
checkpoints = [];
|
|
17
|
+
bareRepoPath = null;
|
|
18
|
+
enabled = true;
|
|
19
|
+
/** Worker thread for git operations */
|
|
20
|
+
worker = null;
|
|
21
|
+
/**
|
|
22
|
+
* Initialize or return the existing worker thread
|
|
23
|
+
* @returns The worker thread instance
|
|
24
|
+
*/
|
|
25
|
+
initWorker() {
|
|
26
|
+
if (!this.worker) {
|
|
27
|
+
// NOTE: Uses the built worker-script-project-context.js within dist.
|
|
28
|
+
// So you need to run `bun run build` before running locally.
|
|
29
|
+
const workerPath = __filename.endsWith('.ts')
|
|
30
|
+
? (0, path_1.join)(__dirname, '../../dist', 'workers/checkpoint-worker.js')
|
|
31
|
+
: (0, path_1.join)(__dirname, '../workers/checkpoint-worker.js');
|
|
32
|
+
this.worker = new worker_threads_1.Worker(workerPath);
|
|
33
|
+
}
|
|
34
|
+
return this.worker;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Execute an operation in the worker thread with timeout handling
|
|
38
|
+
* @param message - The message describing the operation to perform
|
|
39
|
+
* @returns A promise that resolves with the operation result
|
|
40
|
+
* @throws Error if the operation fails or times out
|
|
41
|
+
*/
|
|
42
|
+
async runWorkerOperation(message) {
|
|
43
|
+
const worker = this.initWorker();
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const timeoutMs = 30000; // 30 seconds timeout
|
|
46
|
+
const handler = (response) => {
|
|
47
|
+
if (response.success) {
|
|
48
|
+
resolve(response.result);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
reject(new Error(response.error));
|
|
52
|
+
}
|
|
53
|
+
worker.off('message', handler);
|
|
54
|
+
};
|
|
55
|
+
worker.on('message', handler);
|
|
56
|
+
worker.postMessage(message);
|
|
57
|
+
// Add timeout
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
worker.off('message', handler);
|
|
60
|
+
reject(new Error('Worker operation timed out'));
|
|
61
|
+
}, timeoutMs);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the path to the bare git repository used for storing file states
|
|
66
|
+
* @returns The bare repo path
|
|
67
|
+
*/
|
|
68
|
+
getBareRepoPath() {
|
|
69
|
+
if (!this.bareRepoPath) {
|
|
70
|
+
this.bareRepoPath = (0, file_manager_1.getBareRepoPath)((0, project_files_1.getProjectRoot)());
|
|
71
|
+
}
|
|
72
|
+
return this.bareRepoPath;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Add a new checkpoint of the current agent and file state
|
|
76
|
+
* @param agentState - The current agent state to checkpoint
|
|
77
|
+
* @param userInput - The user input that triggered this checkpoint
|
|
78
|
+
* @returns The created checkpoint, or null if checkpointing is disabled
|
|
79
|
+
*/
|
|
80
|
+
async addCheckpoint(agentState, userInput) {
|
|
81
|
+
if (!this.enabled) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const id = this.checkpoints.length + 1;
|
|
85
|
+
const projectDir = (0, project_files_1.getProjectRoot)();
|
|
86
|
+
const bareRepoPath = this.getBareRepoPath();
|
|
87
|
+
const relativeFilepaths = (0, project_file_tree_1.getAllFilePaths)(agentState.fileContext.fileTree);
|
|
88
|
+
if (relativeFilepaths.length >= project_file_tree_1.DEFAULT_MAX_FILES) {
|
|
89
|
+
this.enabled = false;
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const needToStage = await (0, file_manager_1.hasUnsavedChanges)({
|
|
93
|
+
projectDir,
|
|
94
|
+
bareRepoPath,
|
|
95
|
+
relativeFilepaths,
|
|
96
|
+
});
|
|
97
|
+
if (!needToStage && this.checkpoints.length > 0) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const fileStateIdPromise = needToStage
|
|
101
|
+
? this.runWorkerOperation({
|
|
102
|
+
type: 'store',
|
|
103
|
+
projectDir,
|
|
104
|
+
bareRepoPath,
|
|
105
|
+
message: `Checkpoint ${id}`,
|
|
106
|
+
relativeFilepaths,
|
|
107
|
+
})
|
|
108
|
+
: (0, file_manager_1.getLatestCommit)({ bareRepoPath });
|
|
109
|
+
const checkpoint = {
|
|
110
|
+
agentStateString: JSON.stringify(agentState),
|
|
111
|
+
fileStateIdPromise,
|
|
112
|
+
historyLength: agentState.messageHistory.length,
|
|
113
|
+
id,
|
|
114
|
+
timestamp: Date.now(),
|
|
115
|
+
userInput,
|
|
116
|
+
};
|
|
117
|
+
this.checkpoints.push(checkpoint);
|
|
118
|
+
return checkpoint;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get the most recent checkpoint
|
|
122
|
+
* @returns The most recent checkpoint or null if none exist
|
|
123
|
+
*/
|
|
124
|
+
getLatestCheckpoint() {
|
|
125
|
+
if (!this.enabled) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return this.checkpoints.length === 0
|
|
129
|
+
? null
|
|
130
|
+
: this.checkpoints[this.checkpoints.length - 1];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Restore the file state from a specific checkpoint
|
|
134
|
+
* @param id - The ID of the checkpoint to restore
|
|
135
|
+
* @returns True if restoration succeeded, false if checkpoint not found
|
|
136
|
+
*/
|
|
137
|
+
async restoreCheckointFileState(id) {
|
|
138
|
+
const checkpoint = this.checkpoints[id - 1];
|
|
139
|
+
if (!checkpoint) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
const relativeFilepaths = (0, project_file_tree_1.getAllFilePaths)(JSON.parse(checkpoint.agentStateString).fileContext
|
|
143
|
+
.fileTree);
|
|
144
|
+
await this.runWorkerOperation({
|
|
145
|
+
type: 'restore',
|
|
146
|
+
projectDir: (0, project_files_1.getProjectRoot)(),
|
|
147
|
+
bareRepoPath: this.getBareRepoPath(),
|
|
148
|
+
commit: await checkpoint.fileStateIdPromise,
|
|
149
|
+
relativeFilepaths,
|
|
150
|
+
});
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Clear all checkpoints
|
|
155
|
+
*/
|
|
156
|
+
clearCheckpoints() {
|
|
157
|
+
this.checkpoints = [];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get a formatted string representation of all checkpoints
|
|
161
|
+
* @param detailed Whether to include detailed information about each checkpoint
|
|
162
|
+
* @returns A formatted string representation of all checkpoints
|
|
163
|
+
*/
|
|
164
|
+
getCheckpointsAsString(detailed = false) {
|
|
165
|
+
if (!this.enabled) {
|
|
166
|
+
return (0, picocolors_1.red)('Checkpoints not enabled: project too large.');
|
|
167
|
+
}
|
|
168
|
+
if (this.checkpoints.length === 0) {
|
|
169
|
+
return (0, picocolors_1.yellow)('No checkpoints available.');
|
|
170
|
+
}
|
|
171
|
+
const lines = [(0, picocolors_1.bold)((0, picocolors_1.underline)('Agent State Checkpoints:')), ''];
|
|
172
|
+
this.checkpoints.forEach((checkpoint) => {
|
|
173
|
+
const date = new Date(checkpoint.timestamp);
|
|
174
|
+
const formattedDate = date.toLocaleString();
|
|
175
|
+
const userInputOneLine = checkpoint.userInput.replaceAll('\n', ' ');
|
|
176
|
+
const userInput = userInputOneLine.length > 50
|
|
177
|
+
? userInputOneLine.substring(0, 47) + '...'
|
|
178
|
+
: userInputOneLine;
|
|
179
|
+
lines.push(`${(0, picocolors_1.cyan)((0, picocolors_1.bold)(`#${checkpoint.id}`))} ${(0, picocolors_1.gray)(`[${formattedDate}]`)}:`);
|
|
180
|
+
lines.push(` ${(0, picocolors_1.blue)('Input')}: ${userInput}`);
|
|
181
|
+
if (detailed) {
|
|
182
|
+
const messageCount = checkpoint.historyLength;
|
|
183
|
+
lines.push(` ${(0, picocolors_1.blue)('Messages')}: ${messageCount}`);
|
|
184
|
+
}
|
|
185
|
+
lines.push(''); // Empty line between checkpoints
|
|
186
|
+
});
|
|
187
|
+
return lines.join('\n');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.CheckpointManager = CheckpointManager;
|
|
191
|
+
// Export a singleton instance for use throughout the application
|
|
192
|
+
exports.checkpointManager = new CheckpointManager();
|
|
193
|
+
//# sourceMappingURL=checkpoint-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint-manager.js","sourceRoot":"","sources":["../../src/checkpoints/checkpoint-manager.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAC3B,2CAA2E;AAC3E,mDAAuC;AAEvC,gEAA6E;AAE7E,iDAIuB;AACvB,oDAAiD;AA6CjD;;;;GAIG;AACH,MAAa,iBAAiB;IAC5B,WAAW,GAAsB,EAAE,CAAA;IAC3B,YAAY,GAAkB,IAAI,CAAA;IAC1C,OAAO,GAAY,IAAI,CAAA;IACvB,uCAAuC;IAC/B,MAAM,GAAkB,IAAI,CAAA;IAEpC;;;OAGG;IACK,UAAU;QAChB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,qEAAqE;YACrE,6DAA6D;YAC7D,MAAM,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAC3C,CAAC,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,YAAY,EAAE,8BAA8B,CAAC;gBAC/D,CAAC,CAAC,IAAA,WAAI,EAAC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D,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA,CAAC,iCAAiC;QAClD,CAAC,CAAC,CAAA;QAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;CACF;AAlND,8CAkNC;AAED,iEAAiE;AACpD,QAAA,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAA"}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
1
2
|
export declare function getBareRepoPath(dir: string): string;
|
|
3
|
+
export declare function hasUnsavedChanges({ projectDir, bareRepoPath, relativeFilepaths, }: {
|
|
4
|
+
projectDir: string;
|
|
5
|
+
bareRepoPath: string;
|
|
6
|
+
relativeFilepaths: Array<string>;
|
|
7
|
+
}): Promise<boolean>;
|
|
8
|
+
export declare function getLatestCommit({ bareRepoPath, }: {
|
|
9
|
+
bareRepoPath: string;
|
|
10
|
+
}): Promise<string>;
|
|
2
11
|
export declare function initializeCheckpointFileManager({ projectDir, relativeFilepaths, }: {
|
|
3
12
|
projectDir: string;
|
|
4
13
|
relativeFilepaths: Array<string>;
|
|
@@ -29,3 +38,4 @@ export declare function restoreFileState({ projectDir, bareRepoPath, commit, rel
|
|
|
29
38
|
commit: string;
|
|
30
39
|
relativeFilepaths: Array<string>;
|
|
31
40
|
}): Promise<void>;
|
|
41
|
+
export { fs };
|
|
@@ -3,29 +3,88 @@ 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;
|
|
8
|
+
exports.hasUnsavedChanges = hasUnsavedChanges;
|
|
9
|
+
exports.getLatestCommit = getLatestCommit;
|
|
7
10
|
exports.initializeCheckpointFileManager = initializeCheckpointFileManager;
|
|
8
11
|
exports.storeFileState = storeFileState;
|
|
9
12
|
exports.restoreFileState = restoreFileState;
|
|
10
13
|
const crypto_1 = require("crypto");
|
|
11
14
|
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
exports.fs = fs_1.default;
|
|
12
16
|
const isomorphic_git_1 = require("isomorphic-git");
|
|
13
17
|
const path_1 = require("path");
|
|
14
18
|
const child_process_1 = require("child_process");
|
|
15
|
-
const project_files_1 = require("
|
|
19
|
+
const project_files_1 = require("../project-files");
|
|
20
|
+
let cachedGitAvailable = null;
|
|
16
21
|
function gitCommandIsAvailable() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
if (cachedGitAvailable === null) {
|
|
23
|
+
try {
|
|
24
|
+
(0, child_process_1.execFileSync)('git', ['--version']);
|
|
25
|
+
cachedGitAvailable = true;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
cachedGitAvailable = false;
|
|
29
|
+
}
|
|
23
30
|
}
|
|
31
|
+
return cachedGitAvailable;
|
|
24
32
|
}
|
|
25
33
|
function getBareRepoPath(dir) {
|
|
26
34
|
const bareRepoName = (0, crypto_1.createHash)('sha256').update(dir).digest('hex');
|
|
27
35
|
return (0, path_1.join)((0, project_files_1.getProjectDataDir)(), bareRepoName);
|
|
28
36
|
}
|
|
37
|
+
async function hasUnsavedChanges({ projectDir, bareRepoPath, relativeFilepaths, }) {
|
|
38
|
+
if (gitCommandIsAvailable()) {
|
|
39
|
+
try {
|
|
40
|
+
const output = (0, child_process_1.execFileSync)('git', [
|
|
41
|
+
'--git-dir',
|
|
42
|
+
bareRepoPath,
|
|
43
|
+
'--work-tree',
|
|
44
|
+
projectDir,
|
|
45
|
+
'status',
|
|
46
|
+
'--porcelain',
|
|
47
|
+
]).toString();
|
|
48
|
+
return output.trim().length > 0;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// error running git
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const [, , workdirStatus, stageStatus] of await (0, isomorphic_git_1.statusMatrix)({
|
|
55
|
+
fs: fs_1.default,
|
|
56
|
+
dir: projectDir,
|
|
57
|
+
gitdir: bareRepoPath,
|
|
58
|
+
filepaths: relativeFilepaths,
|
|
59
|
+
})) {
|
|
60
|
+
if (workdirStatus !== stageStatus) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
async function getLatestCommit({ bareRepoPath, }) {
|
|
67
|
+
if (gitCommandIsAvailable()) {
|
|
68
|
+
try {
|
|
69
|
+
return (0, child_process_1.execFileSync)('git', [
|
|
70
|
+
'--git-dir',
|
|
71
|
+
bareRepoPath,
|
|
72
|
+
'rev-parse',
|
|
73
|
+
'HEAD',
|
|
74
|
+
])
|
|
75
|
+
.toString()
|
|
76
|
+
.trim();
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
// unable to get head
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return await (0, isomorphic_git_1.resolveRef)({
|
|
83
|
+
fs: fs_1.default,
|
|
84
|
+
dir: bareRepoPath,
|
|
85
|
+
ref: 'HEAD',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
29
88
|
async function initializeCheckpointFileManager({ projectDir, relativeFilepaths, }) {
|
|
30
89
|
const bareRepoPath = getBareRepoPath(projectDir);
|
|
31
90
|
// Create the bare repo directory if it doesn't exist
|
|
@@ -46,7 +105,26 @@ async function initializeCheckpointFileManager({ projectDir, relativeFilepaths,
|
|
|
46
105
|
relativeFilepaths,
|
|
47
106
|
});
|
|
48
107
|
}
|
|
49
|
-
async function
|
|
108
|
+
async function stageFiles({ projectDir, bareRepoPath, relativeFilepaths, }) {
|
|
109
|
+
if (gitCommandIsAvailable()) {
|
|
110
|
+
try {
|
|
111
|
+
(0, child_process_1.execFileSync)('git', [
|
|
112
|
+
'--git-dir',
|
|
113
|
+
bareRepoPath,
|
|
114
|
+
'--work-tree',
|
|
115
|
+
projectDir,
|
|
116
|
+
'-C',
|
|
117
|
+
projectDir,
|
|
118
|
+
'add',
|
|
119
|
+
'.',
|
|
120
|
+
]);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
// Failed to add .
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Stage files with isomorphic-git
|
|
50
128
|
// Get status of all files in the project directory
|
|
51
129
|
const currStatusMatrix = await (0, isomorphic_git_1.statusMatrix)({
|
|
52
130
|
fs: fs_1.default,
|
|
@@ -85,32 +163,11 @@ async function stageFilesIndividually({ projectDir, bareRepoPath, relativeFilepa
|
|
|
85
163
|
* @returns A promise that resolves to the id hash that can be used to restore this file state
|
|
86
164
|
*/
|
|
87
165
|
async function storeFileState({ projectDir, bareRepoPath, message, relativeFilepaths: relativeFilepaths, }) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
bareRepoPath,
|
|
94
|
-
'--work-tree',
|
|
95
|
-
projectDir,
|
|
96
|
-
'-C',
|
|
97
|
-
projectDir,
|
|
98
|
-
'add',
|
|
99
|
-
'.',
|
|
100
|
-
]);
|
|
101
|
-
added = true;
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
// Failed to add .
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (!added) {
|
|
108
|
-
await stageFilesIndividually({
|
|
109
|
-
projectDir,
|
|
110
|
-
bareRepoPath,
|
|
111
|
-
relativeFilepaths,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
166
|
+
await stageFiles({
|
|
167
|
+
projectDir,
|
|
168
|
+
bareRepoPath,
|
|
169
|
+
relativeFilepaths,
|
|
170
|
+
});
|
|
114
171
|
const commitHash = await (0, isomorphic_git_1.commit)({
|
|
115
172
|
fs: fs_1.default,
|
|
116
173
|
dir: projectDir,
|
|
@@ -174,4 +231,4 @@ async function restoreFileState({ projectDir, bareRepoPath, commit, relativeFile
|
|
|
174
231
|
})));
|
|
175
232
|
}
|
|
176
233
|
}
|
|
177
|
-
//# sourceMappingURL=
|
|
234
|
+
//# sourceMappingURL=file-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-manager.js","sourceRoot":"","sources":["../../src/checkpoints/file-manager.ts"],"names":[],"mappings":";;;;;;AA+BA,0CAGC;AAED,8CAoCC;AAED,0CAwBC;AAED,0EA2BC;AAoED,wCAkCC;AAUD,4CAqDC;AApSD,mCAAmC;AACnC,4CAAmB;AAsSV,aAtSF,YAAE,CAsSE;AArSX,mDASuB;AACvB,+BAA2B;AAC3B,iDAA4C;AAE5C,oDAAoD;AAEpD,IAAI,kBAAkB,GAAmB,IAAI,CAAA;AAC7C,SAAS,qBAAqB;IAC5B,IAAI,kBAAkB,KAAK,IAAI,EAAE,CAAC;QAChC,IAAI,CAAC;YACH,IAAA,4BAAY,EAAC,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;YAClC,kBAAkB,GAAG,IAAI,CAAA;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,kBAAkB,GAAG,KAAK,CAAA;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,kBAAkB,CAAA;AAC3B,CAAC;AAED,SAAgB,eAAe,CAAC,GAAW;IACzC,MAAM,YAAY,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACnE,OAAO,IAAA,WAAI,EAAC,IAAA,iCAAiB,GAAE,EAAE,YAAY,CAAC,CAAA;AAChD,CAAC;AAEM,KAAK,UAAU,iBAAiB,CAAC,EACtC,UAAU,EACV,YAAY,EACZ,iBAAiB,GAKlB;IACC,IAAI,qBAAqB,EAAE,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAA,4BAAY,EAAC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;;;;;;GAOG;AACI,KAAK,UAAU,gBAAgB,CAAC,EACrC,UAAU,EACV,YAAY,EACZ,MAAM,EACN,iBAAiB,GAMlB;IACC,IAAI,SAAS,GAAG,KAAK,CAAA;IACrB,IAAI,qBAAqB,EAAE,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,IAAA,4BAAY,EAAC,KAAK,EAAE;gBAClB,WAAW;gBACX,YAAY;gBACZ,aAAa;gBACb,UAAU;gBACV,OAAO;gBACP,QAAQ;gBACR,MAAM;aACP,CAAC,CAAA;YACF,SAAS,GAAG,IAAI,CAAA;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,+DAA+D;QACjE,CAAC;IACH,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,+DAA+D;QAC/D,MAAM,IAAA,yBAAQ,EAAC;YACb,EAAE,EAAF,YAAE;YACF,GAAG,EAAE,UAAU;YACf,MAAM,EAAE,YAAY;YACpB,GAAG,EAAE,MAAM;YACX,SAAS,EAAE,iBAAiB;YAC5B,KAAK,EAAE,IAAI;SACZ,CAAC,CAAA;QAEF,gDAAgD;QAChD,MAAM,OAAO,CAAC,GAAG,CACf,iBAAiB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CACjC,IAAA,2BAAU,EAAC;YACT,EAAE,EAAF,YAAE;YACF,GAAG,EAAE,UAAU;YACf,MAAM,EAAE,YAAY;YACpB,QAAQ;YACR,GAAG,EAAE,MAAM;SACZ,CAAC,CACH,CACF,CAAA;IACH,CAAC;AACH,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ const constants_1 = require("./common/constants");
|
|
|
31
31
|
const project_file_tree_1 = require("./common/project-file-tree");
|
|
32
32
|
const string_1 = require("./common/util/string");
|
|
33
33
|
const chat_storage_1 = require("./chat-storage");
|
|
34
|
-
const
|
|
34
|
+
const checkpoint_manager_1 = require("./checkpoints/checkpoint-manager");
|
|
35
35
|
const client_1 = require("./client");
|
|
36
36
|
const config_1 = require("./config");
|
|
37
37
|
const menu_1 = require("./menu");
|
|
@@ -171,12 +171,14 @@ class CLI {
|
|
|
171
171
|
spinner_1.Spinner.get().start();
|
|
172
172
|
await this.readyPromise;
|
|
173
173
|
spinner_1.Spinner.get().stop();
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
174
|
+
if (checkpoint_manager_1.checkpointManager.enabled) {
|
|
175
|
+
// Make sure the previous checkpoint is done
|
|
176
|
+
await checkpoint_manager_1.checkpointManager.getLatestCheckpoint()?.fileStateIdPromise;
|
|
177
|
+
// Save the current agent state
|
|
178
|
+
const checkpoint = await checkpoint_manager_1.checkpointManager.addCheckpoint(this.client.agentState, userInput);
|
|
179
|
+
if (checkpoint) {
|
|
180
|
+
console.log((0, picocolors_1.green)(`Checkpoint #${checkpoint.id} saved!`));
|
|
181
|
+
}
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
async processCommand(userInput) {
|
|
@@ -289,7 +291,7 @@ class CLI {
|
|
|
289
291
|
}
|
|
290
292
|
async handleUndo() {
|
|
291
293
|
// Get previous checkpoint number (not including undo command)
|
|
292
|
-
const checkpointId =
|
|
294
|
+
const checkpointId = checkpoint_manager_1.checkpointManager.getLatestCheckpoint().id - 1;
|
|
293
295
|
if (checkpointId < 1) {
|
|
294
296
|
console.log((0, picocolors_1.red)('Nothing to undo.'));
|
|
295
297
|
this.rl.prompt();
|
|
@@ -530,24 +532,24 @@ class CLI {
|
|
|
530
532
|
}
|
|
531
533
|
// Checkpoint command handlers
|
|
532
534
|
async handleCheckpoints() {
|
|
533
|
-
console.log(
|
|
535
|
+
console.log(checkpoint_manager_1.checkpointManager.getCheckpointsAsString());
|
|
534
536
|
this.rl.prompt();
|
|
535
537
|
}
|
|
536
538
|
async handleRestoreCheckpoint(id) {
|
|
537
|
-
|
|
539
|
+
if (!checkpoint_manager_1.checkpointManager.enabled) {
|
|
540
|
+
console.log((0, picocolors_1.red)(`Checkpoints not enabled: project too large`));
|
|
541
|
+
this.rl.prompt();
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const checkpoint = checkpoint_manager_1.checkpointManager.checkpoints[id - 1];
|
|
538
545
|
if (!checkpoint) {
|
|
539
546
|
console.log((0, picocolors_1.red)(`Checkpoint #${id} not found.`));
|
|
540
547
|
this.rl.prompt();
|
|
541
548
|
return;
|
|
542
549
|
}
|
|
543
550
|
// Wait for save before trying to restore checkpoint
|
|
544
|
-
const latestCheckpoint =
|
|
551
|
+
const latestCheckpoint = checkpoint_manager_1.checkpointManager.getLatestCheckpoint();
|
|
545
552
|
await latestCheckpoint?.fileStateIdPromise;
|
|
546
|
-
if (!latestCheckpoint?.enabled) {
|
|
547
|
-
console.log((0, picocolors_1.red)(`Checkpoints not enabled: project too large`));
|
|
548
|
-
this.rl.prompt();
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
553
|
await this.restoreAgentStateAndFiles(checkpoint);
|
|
552
554
|
console.log((0, picocolors_1.green)(`Restored to checkpoint #${id}.`));
|
|
553
555
|
// Insert the original user input that created this checkpoint
|
|
@@ -558,14 +560,14 @@ class CLI {
|
|
|
558
560
|
// Restore the agentState
|
|
559
561
|
this.client.agentState = JSON.parse(checkpoint.agentStateString);
|
|
560
562
|
// Restore file state
|
|
561
|
-
if (!(await
|
|
563
|
+
if (!(await checkpoint_manager_1.checkpointManager.restoreCheckointFileState(checkpoint.id))) {
|
|
562
564
|
throw new assert_1.AssertionError({
|
|
563
565
|
message: `Internal error: checkpoint ${checkpoint.id} not found`,
|
|
564
566
|
});
|
|
565
567
|
}
|
|
566
568
|
}
|
|
567
569
|
async handleClearCheckpoints() {
|
|
568
|
-
|
|
570
|
+
checkpoint_manager_1.checkpointManager.clearCheckpoints();
|
|
569
571
|
this.rl.prompt();
|
|
570
572
|
}
|
|
571
573
|
}
|