codecane 1.0.177 → 1.0.179
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/chat-storage.d.ts +1 -26
- package/dist/chat-storage.js +56 -132
- package/dist/chat-storage.js.map +1 -1
- package/dist/checkpoint-file-manager.d.ts +8 -0
- package/dist/checkpoint-file-manager.js +89 -0
- package/dist/checkpoint-file-manager.js.map +1 -0
- package/dist/checkpoints.d.ts +3 -6
- package/dist/checkpoints.js +35 -21
- package/dist/checkpoints.js.map +1 -1
- package/dist/cli.d.ts +1 -3
- package/dist/cli.js +22 -60
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +9 -11
- package/dist/client.js +25 -22
- package/dist/client.js.map +1 -1
- package/dist/code-map/tsconfig.tsbuildinfo +1 -1
- package/dist/common/actions.d.ts +195 -195
- package/dist/common/constants/tools.d.ts +2 -2
- package/dist/common/constants/tools.js +3 -2
- package/dist/common/constants/tools.js.map +1 -1
- package/dist/common/websockets/websocket-schema.d.ts +528 -528
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/xml-stream-parser.d.ts +2 -2
- package/dist/utils/xml-stream-parser.js +29 -2
- package/dist/utils/xml-stream-parser.js.map +1 -1
- package/package.json +2 -1
- package/dist/common/advanced-analyzer.d.ts +0 -19
- package/dist/common/advanced-analyzer.js +0 -140
- package/dist/common/advanced-analyzer.js.map +0 -1
- package/dist/common/message-image-handling.d.ts +0 -41
- package/dist/common/message-image-handling.js +0 -57
- package/dist/common/message-image-handling.js.map +0 -1
- package/dist/common/util/process-stream.d.ts +0 -8
- package/dist/common/util/process-stream.js +0 -102
- package/dist/common/util/process-stream.js.map +0 -1
package/dist/chat-storage.d.ts
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
1
|
import { Message } from './common/types/message';
|
|
2
|
-
|
|
3
|
-
id: string;
|
|
4
|
-
messages: Message[];
|
|
5
|
-
fileVersions: FileVersion[];
|
|
6
|
-
createdAt: string;
|
|
7
|
-
updatedAt: string;
|
|
8
|
-
timestamp: number;
|
|
9
|
-
}
|
|
10
|
-
interface FileVersion {
|
|
11
|
-
files: Record<string, string>;
|
|
12
|
-
}
|
|
13
|
-
export declare class ChatStorage {
|
|
14
|
-
private currentChat;
|
|
15
|
-
private currentVersionIndex;
|
|
16
|
-
constructor();
|
|
17
|
-
getCurrentChat(): Chat;
|
|
18
|
-
addMessage(chat: Chat, message: Message): void;
|
|
19
|
-
private saveMessagesToFile;
|
|
20
|
-
getCurrentVersion(): FileVersion | null;
|
|
21
|
-
navigateVersion(direction: 'undo' | 'redo'): boolean;
|
|
22
|
-
saveFilesChanged(filesChanged: string[]): string[];
|
|
23
|
-
saveCurrentFileState(files: Record<string, string>): void;
|
|
24
|
-
addNewFileState(files: Record<string, string>): void;
|
|
25
|
-
private createChat;
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
2
|
+
export declare function setMessages(messages: Message[]): void;
|
package/dist/chat-storage.js
CHANGED
|
@@ -23,147 +23,71 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.setMessages = setMessages;
|
|
27
27
|
const path = __importStar(require("path"));
|
|
28
28
|
const fs = __importStar(require("fs"));
|
|
29
29
|
const project_files_1 = require("./project-files");
|
|
30
30
|
const string_1 = require("./common/util/string");
|
|
31
31
|
const ts_pattern_1 = require("ts-pattern");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
getCurrentChat() {
|
|
40
|
-
return this.currentChat;
|
|
41
|
-
}
|
|
42
|
-
addMessage(chat, message) {
|
|
43
|
-
// Before adding new message, clean up any screenshots and logs in previous messages
|
|
44
|
-
// Skip the last message as it may not have been processed by the backend yet
|
|
45
|
-
const lastIndex = chat.messages.length - 1;
|
|
46
|
-
chat.messages = chat.messages.map((msg, index) => {
|
|
47
|
-
if (index === lastIndex) {
|
|
48
|
-
return msg; // Preserve the most recent message in its entirety
|
|
49
|
-
}
|
|
50
|
-
// Helper function to clean up message content
|
|
51
|
-
const cleanContent = (content) => {
|
|
52
|
-
// Keep only tool logs
|
|
53
|
-
content = (0, string_1.transformJsonInString)(content, 'logs', (logs) => logs.filter((log) => log.source === 'tool'), '(LOGS_REMOVED)');
|
|
54
|
-
// Remove metrics
|
|
55
|
-
content = (0, string_1.transformJsonInString)(content, 'metrics', () => '(METRICS_REMOVED)', '(METRICS_REMOVED)');
|
|
56
|
-
return content;
|
|
57
|
-
};
|
|
58
|
-
// Clean up message content
|
|
59
|
-
if (!msg.content)
|
|
60
|
-
return msg;
|
|
61
|
-
return (0, ts_pattern_1.match)(msg)
|
|
62
|
-
.with({ content: ts_pattern_1.P.array() }, (message) => ({
|
|
63
|
-
...message,
|
|
64
|
-
content: message.content.reduce((acc, contentObj) => [
|
|
65
|
-
...acc,
|
|
66
|
-
...(0, ts_pattern_1.match)(contentObj)
|
|
67
|
-
.with({ type: 'tool_result', content: ts_pattern_1.P.string }, (obj) => [
|
|
68
|
-
{
|
|
69
|
-
...obj,
|
|
70
|
-
content: cleanContent(obj.content),
|
|
71
|
-
},
|
|
72
|
-
])
|
|
73
|
-
.with({ type: 'text', text: ts_pattern_1.P.string }, (obj) => [
|
|
74
|
-
{
|
|
75
|
-
...obj,
|
|
76
|
-
text: cleanContent(obj.text),
|
|
77
|
-
},
|
|
78
|
-
])
|
|
79
|
-
.otherwise((obj) => [obj]),
|
|
80
|
-
], []),
|
|
81
|
-
}))
|
|
82
|
-
.with({ content: ts_pattern_1.P.string }, (message) => ({
|
|
83
|
-
...message,
|
|
84
|
-
content: cleanContent(message.content),
|
|
85
|
-
}))
|
|
86
|
-
.otherwise((message) => message);
|
|
87
|
-
});
|
|
88
|
-
// Add the new message
|
|
89
|
-
chat.messages.push(message);
|
|
90
|
-
chat.updatedAt = new Date().toISOString();
|
|
91
|
-
// Save messages to chat directory
|
|
92
|
-
this.saveMessagesToFile(chat);
|
|
93
|
-
}
|
|
94
|
-
saveMessagesToFile(chat) {
|
|
95
|
-
try {
|
|
96
|
-
const chatDir = (0, project_files_1.getCurrentChatDir)();
|
|
97
|
-
const messagesPath = path.join(chatDir, 'messages.json');
|
|
98
|
-
const messagesData = {
|
|
99
|
-
id: chat.id,
|
|
100
|
-
messages: chat.messages,
|
|
101
|
-
updatedAt: chat.updatedAt,
|
|
102
|
-
};
|
|
103
|
-
fs.writeFileSync(messagesPath, JSON.stringify(messagesData, null, 2));
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
console.error('Failed to save messages to file:', error);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
getCurrentVersion() {
|
|
110
|
-
if (this.currentVersionIndex >= 0 &&
|
|
111
|
-
this.currentVersionIndex < this.currentChat.fileVersions.length) {
|
|
112
|
-
return this.currentChat.fileVersions[this.currentVersionIndex];
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
navigateVersion(direction) {
|
|
117
|
-
if (direction === 'undo' && this.currentVersionIndex >= 0) {
|
|
118
|
-
this.currentVersionIndex--;
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
else if (direction === 'redo' &&
|
|
122
|
-
this.currentVersionIndex < this.currentChat.fileVersions.length - 1) {
|
|
123
|
-
this.currentVersionIndex++;
|
|
124
|
-
return true;
|
|
32
|
+
function setMessages(messages) {
|
|
33
|
+
// Clean up any screenshots and logs in previous messages
|
|
34
|
+
// Skip the last message as it may not have been processed by the backend yet
|
|
35
|
+
const lastIndex = messages.length - 1;
|
|
36
|
+
const cleanedMessages = messages.map((msg, index) => {
|
|
37
|
+
if (index === lastIndex) {
|
|
38
|
+
return msg; // Preserve the most recent message in its entirety
|
|
125
39
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
const newFilesChanged = filesChanged.filter((f) => !currentVersion.files[f]);
|
|
135
|
-
const updatedFiles = (0, project_files_1.getExistingFiles)(newFilesChanged);
|
|
136
|
-
currentVersion.files = { ...currentVersion.files, ...updatedFiles };
|
|
137
|
-
return Object.keys(currentVersion.files);
|
|
138
|
-
}
|
|
139
|
-
saveCurrentFileState(files) {
|
|
140
|
-
const currentVersion = this.getCurrentVersion();
|
|
141
|
-
if (currentVersion) {
|
|
142
|
-
currentVersion.files = files;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
this.addNewFileState(files);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
addNewFileState(files) {
|
|
149
|
-
const newVersion = {
|
|
150
|
-
files,
|
|
40
|
+
// Helper function to clean up message content
|
|
41
|
+
const cleanContent = (content) => {
|
|
42
|
+
// Keep only tool logs
|
|
43
|
+
content = (0, string_1.transformJsonInString)(content, 'logs', (logs) => logs.filter((log) => log.source === 'tool'), '(LOGS_REMOVED)');
|
|
44
|
+
// Remove metrics
|
|
45
|
+
content = (0, string_1.transformJsonInString)(content, 'metrics', () => '(METRICS_REMOVED)', '(METRICS_REMOVED)');
|
|
46
|
+
return content;
|
|
151
47
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
48
|
+
// Clean up message content
|
|
49
|
+
if (!msg.content)
|
|
50
|
+
return msg;
|
|
51
|
+
return (0, ts_pattern_1.match)(msg)
|
|
52
|
+
.with({ content: ts_pattern_1.P.array() }, (message) => ({
|
|
53
|
+
...message,
|
|
54
|
+
content: message.content.reduce((acc, contentObj) => [
|
|
55
|
+
...acc,
|
|
56
|
+
...(0, ts_pattern_1.match)(contentObj)
|
|
57
|
+
.with({ type: 'tool_result', content: ts_pattern_1.P.string }, (obj) => [
|
|
58
|
+
{
|
|
59
|
+
...obj,
|
|
60
|
+
content: cleanContent(obj.content),
|
|
61
|
+
},
|
|
62
|
+
])
|
|
63
|
+
.with({ type: 'text', text: ts_pattern_1.P.string }, (obj) => [
|
|
64
|
+
{
|
|
65
|
+
...obj,
|
|
66
|
+
text: cleanContent(obj.text),
|
|
67
|
+
},
|
|
68
|
+
])
|
|
69
|
+
.otherwise((obj) => [obj]),
|
|
70
|
+
], []),
|
|
71
|
+
}))
|
|
72
|
+
.with({ content: ts_pattern_1.P.string }, (message) => ({
|
|
73
|
+
...message,
|
|
74
|
+
content: cleanContent(message.content),
|
|
75
|
+
}))
|
|
76
|
+
.otherwise((message) => message);
|
|
77
|
+
});
|
|
78
|
+
// Save messages to chat directory
|
|
79
|
+
try {
|
|
80
|
+
const chatDir = (0, project_files_1.getCurrentChatDir)();
|
|
81
|
+
const messagesPath = path.join(chatDir, 'messages.json');
|
|
82
|
+
const messagesData = {
|
|
158
83
|
id: project_files_1.currentChatId,
|
|
159
|
-
messages,
|
|
160
|
-
|
|
161
|
-
createdAt: now.toISOString(),
|
|
162
|
-
updatedAt: now.toISOString(),
|
|
163
|
-
timestamp: now.getTime(),
|
|
84
|
+
messages: cleanedMessages,
|
|
85
|
+
updatedAt: new Date().toISOString(),
|
|
164
86
|
};
|
|
165
|
-
|
|
87
|
+
fs.writeFileSync(messagesPath, JSON.stringify(messagesData, null, 2));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error('Failed to save messages to file:', error);
|
|
166
91
|
}
|
|
167
92
|
}
|
|
168
|
-
exports.ChatStorage = ChatStorage;
|
|
169
93
|
//# sourceMappingURL=chat-storage.js.map
|
package/dist/chat-storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-storage.js","sourceRoot":"","sources":["../src/chat-storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chat-storage.js","sourceRoot":"","sources":["../src/chat-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;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,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAA;IAC1D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function initializeCheckpointFileManager(): Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* Stores the current state of all files in the project as a git commit
|
|
4
|
+
* @param message The commit message to use for this file state
|
|
5
|
+
* @returns A promise that resolves to the id hash that can be used to restore this file state
|
|
6
|
+
*/
|
|
7
|
+
export declare function storeFileState(message: string): Promise<string>;
|
|
8
|
+
export declare function checkoutFileState(fileStateId: string): Promise<void>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.initializeCheckpointFileManager = initializeCheckpointFileManager;
|
|
27
|
+
exports.storeFileState = storeFileState;
|
|
28
|
+
exports.checkoutFileState = checkoutFileState;
|
|
29
|
+
const crypto = __importStar(require("crypto"));
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const git = __importStar(require("isomorphic-git"));
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const project_files_1 = require("./project-files");
|
|
34
|
+
let projectDir;
|
|
35
|
+
let bareRepoPath;
|
|
36
|
+
async function initializeCheckpointFileManager() {
|
|
37
|
+
projectDir = (0, project_files_1.getProjectRoot)();
|
|
38
|
+
const bareRepoName = crypto
|
|
39
|
+
.createHash('sha256')
|
|
40
|
+
.update(projectDir)
|
|
41
|
+
.digest('hex');
|
|
42
|
+
bareRepoPath = path.join((0, project_files_1.getProjectDataDir)(), bareRepoName);
|
|
43
|
+
// Create the bare repo directory if it doesn't exist
|
|
44
|
+
fs.mkdirSync(bareRepoPath, { recursive: true });
|
|
45
|
+
try {
|
|
46
|
+
// Check if it's already a valid Git repo
|
|
47
|
+
await git.resolveRef({ fs, dir: bareRepoPath, ref: 'HEAD' });
|
|
48
|
+
return; // Exit if the repository exists
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// Bare repo doesn't exist yet
|
|
52
|
+
}
|
|
53
|
+
// Initialize a bare repository
|
|
54
|
+
await git.init({ fs, dir: bareRepoPath, bare: true });
|
|
55
|
+
// Commit the files in the bare repo
|
|
56
|
+
await storeFileState('Initial Commit');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Stores the current state of all files in the project as a git commit
|
|
60
|
+
* @param message The commit message to use for this file state
|
|
61
|
+
* @returns A promise that resolves to the id hash that can be used to restore this file state
|
|
62
|
+
*/
|
|
63
|
+
async function storeFileState(message) {
|
|
64
|
+
await git.add({
|
|
65
|
+
fs,
|
|
66
|
+
dir: projectDir,
|
|
67
|
+
gitdir: bareRepoPath,
|
|
68
|
+
filepath: '.',
|
|
69
|
+
});
|
|
70
|
+
const commitHash = await git.commit({
|
|
71
|
+
fs,
|
|
72
|
+
dir: projectDir,
|
|
73
|
+
gitdir: bareRepoPath,
|
|
74
|
+
author: { name: 'codebuff' },
|
|
75
|
+
message,
|
|
76
|
+
});
|
|
77
|
+
return commitHash;
|
|
78
|
+
}
|
|
79
|
+
async function checkoutFileState(fileStateId) {
|
|
80
|
+
// Checkout the given hash
|
|
81
|
+
await git.checkout({
|
|
82
|
+
fs,
|
|
83
|
+
dir: projectDir,
|
|
84
|
+
gitdir: bareRepoPath,
|
|
85
|
+
ref: fileStateId,
|
|
86
|
+
force: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=checkpoint-file-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint-file-manager.js","sourceRoot":"","sources":["../src/checkpoint-file-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAUA,0EAyBC;AAOD,wCAiBC;AAED,8CASC;AAtED,+CAAgC;AAChC,uCAAwB;AACxB,oDAAqC;AACrC,2CAA4B;AAE5B,mDAAmE;AAEnE,IAAI,UAAkB,CAAA;AACtB,IAAI,YAAoB,CAAA;AAEjB,KAAK,UAAU,+BAA+B;IACnD,UAAU,GAAG,IAAA,8BAAc,GAAE,CAAA;IAE7B,MAAM,YAAY,GAAG,MAAM;SACxB,UAAU,CAAC,QAAQ,CAAC;SACpB,MAAM,CAAC,UAAU,CAAC;SAClB,MAAM,CAAC,KAAK,CAAC,CAAA;IAChB,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAA,iCAAiB,GAAE,EAAE,YAAY,CAAC,CAAA;IAE3D,qDAAqD;IACrD,EAAE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
|
|
4
4
|
*/
|
|
5
5
|
export interface Checkpoint {
|
|
6
6
|
agentStateString: string;
|
|
7
|
-
|
|
7
|
+
fileStateIdPromise: Promise<string>;
|
|
8
8
|
historyLength: number;
|
|
9
9
|
id: number;
|
|
10
10
|
timestamp: number;
|
|
@@ -15,18 +15,14 @@ export interface Checkpoint {
|
|
|
15
15
|
*/
|
|
16
16
|
export declare class CheckpointManager {
|
|
17
17
|
private checkpoints;
|
|
18
|
-
private maxCheckpoints;
|
|
19
18
|
private nextId;
|
|
20
|
-
private oldestId;
|
|
21
|
-
constructor(maxCheckpoints?: number);
|
|
22
19
|
/**
|
|
23
20
|
* Add a new checkpoint
|
|
24
|
-
* TODO update this jsdoc and add comments to this function
|
|
25
21
|
* @param agentState - The agent state to checkpoint
|
|
26
22
|
* @param userInput - The user input associated with this checkpoint
|
|
27
23
|
* @returns The ID of the created checkpoint
|
|
28
24
|
*/
|
|
29
|
-
addCheckpoint(agentState: AgentState, userInput: string
|
|
25
|
+
addCheckpoint(agentState: AgentState, userInput: string): Promise<number>;
|
|
30
26
|
/**
|
|
31
27
|
* Get a checkpoint by ID
|
|
32
28
|
* @param id The checkpoint ID
|
|
@@ -43,6 +39,7 @@ export declare class CheckpointManager {
|
|
|
43
39
|
* @returns The most recent checkpoint or null if none exist
|
|
44
40
|
*/
|
|
45
41
|
getLatestCheckpoint(): Checkpoint | null;
|
|
42
|
+
restoreFileState(id: number): Promise<boolean>;
|
|
46
43
|
/**
|
|
47
44
|
* Clear all checkpoints
|
|
48
45
|
*/
|
package/dist/checkpoints.js
CHANGED
|
@@ -1,38 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.checkpointManager = exports.CheckpointManager = void 0;
|
|
4
27
|
const picocolors_1 = require("picocolors");
|
|
28
|
+
const checkpointFileManager = __importStar(require("./checkpoint-file-manager"));
|
|
5
29
|
/**
|
|
6
30
|
* Simple in-memory checkpoint manager for agent states
|
|
7
31
|
*/
|
|
8
32
|
class CheckpointManager {
|
|
9
33
|
checkpoints = new Map();
|
|
10
|
-
maxCheckpoints;
|
|
11
34
|
nextId = 1;
|
|
12
|
-
oldestId = 1;
|
|
13
|
-
constructor(maxCheckpoints = 100) {
|
|
14
|
-
this.maxCheckpoints = maxCheckpoints;
|
|
15
|
-
}
|
|
16
35
|
/**
|
|
17
36
|
* Add a new checkpoint
|
|
18
|
-
* TODO update this jsdoc and add comments to this function
|
|
19
37
|
* @param agentState - The agent state to checkpoint
|
|
20
38
|
* @param userInput - The user input associated with this checkpoint
|
|
21
39
|
* @returns The ID of the created checkpoint
|
|
22
40
|
*/
|
|
23
|
-
addCheckpoint(agentState, userInput
|
|
41
|
+
async addCheckpoint(agentState, userInput) {
|
|
24
42
|
// Use incremental ID starting at 1
|
|
25
43
|
const id = this.nextId++;
|
|
26
|
-
const
|
|
27
|
-
const currentFileVersions = agentState.fileContext.fileVersions
|
|
28
|
-
.flat()
|
|
29
|
-
.reduce((acc, { path, content }) => {
|
|
30
|
-
acc[path] = content;
|
|
31
|
-
return acc;
|
|
32
|
-
}, {});
|
|
44
|
+
const fileStateIdPromise = checkpointFileManager.storeFileState(`Checkpoint ${id}`);
|
|
33
45
|
const checkpoint = {
|
|
34
46
|
agentStateString: JSON.stringify(agentState), // Deep clone to prevent reference issues
|
|
35
|
-
|
|
47
|
+
fileStateIdPromise,
|
|
36
48
|
historyLength: agentState.messageHistory.length,
|
|
37
49
|
id,
|
|
38
50
|
timestamp: Date.now(),
|
|
@@ -40,11 +52,6 @@ class CheckpointManager {
|
|
|
40
52
|
};
|
|
41
53
|
// Add to map
|
|
42
54
|
this.checkpoints.set(id, checkpoint);
|
|
43
|
-
// If we exceed the maximum number of checkpoints, remove the oldest one
|
|
44
|
-
if (this.checkpoints.size > this.maxCheckpoints) {
|
|
45
|
-
this.checkpoints.delete(this.oldestId);
|
|
46
|
-
this.oldestId++;
|
|
47
|
-
}
|
|
48
55
|
return id;
|
|
49
56
|
}
|
|
50
57
|
/**
|
|
@@ -73,13 +80,20 @@ class CheckpointManager {
|
|
|
73
80
|
getLatestCheckpoint() {
|
|
74
81
|
return this.checkpoints.get(this.nextId - 1) || null;
|
|
75
82
|
}
|
|
83
|
+
async restoreFileState(id) {
|
|
84
|
+
const checkpoint = this.getCheckpoint(id);
|
|
85
|
+
if (!checkpoint) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
checkpointFileManager.checkoutFileState(await checkpoint.fileStateIdPromise);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
76
91
|
/**
|
|
77
92
|
* Clear all checkpoints
|
|
78
93
|
*/
|
|
79
94
|
clearCheckpoints() {
|
|
80
95
|
this.checkpoints.clear();
|
|
81
96
|
this.nextId = 1; // Reset the ID counter when clearing
|
|
82
|
-
this.oldestId = 1;
|
|
83
97
|
}
|
|
84
98
|
/**
|
|
85
99
|
* Get a formatted string representation of all checkpoints
|
package/dist/checkpoints.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoints.js","sourceRoot":"","sources":["../src/checkpoints.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"checkpoints.js","sourceRoot":"","sources":["../src/checkpoints.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CASmB;AAGnB,iFAAkE;AAclE;;GAEG;AACH,MAAa,iBAAiB;IACpB,WAAW,GAA4B,IAAI,GAAG,EAAE,CAAA;IAChD,MAAM,GAAW,CAAC,CAAA;IAE1B;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CACjB,UAAsB,EACtB,SAAiB;QAEjB,mCAAmC;QACnC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;QAExB,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,cAAc,CAC7D,cAAc,EAAE,EAAE,CACnB,CAAA;QAED,MAAM,UAAU,GAAe;YAC7B,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,yCAAyC;YACvF,kBAAkB;YAClB,aAAa,EAAE,UAAU,CAAC,cAAc,CAAC,MAAM;YAC/C,EAAE;YACF,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,SAAS;SACV,CAAA;QAED,aAAa;QACb,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,CAAA;QAEpC,OAAO,EAAE,CAAA;IACX,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,EAAiB;QAC7B,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;YAChB,OAAO,IAAI,CAAA;QACb,CAAC;QACD,MAA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EAAE,CAAC,CAAA;QACzC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,IAAA,iBAAI,EAAC,iBAAiB,EAAE,aAAa,CAAC,CAAA;QAC/C,CAAC;QAED,MAAM,KAAK,GAAa;YACtB,IAAA,iBAAI,EAAC,wCAAwC,EAAE,GAAG,CAAC;SACpD,CAAA;QAED,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;QAC3C,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;QAC3C,KAAK,CAAC,IAAI,CAAC,GAAG,IAAA,iBAAI,EAAC,YAAY,CAAC,KAAK,aAAa,EAAE,CAAC,CAAA;QAErD,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,GAAG,IAAA,iBAAI,EAAC,YAAY,CAAC,KAAK,UAAU,CAAC,SAAS,EAAE,CAAC,CAAA;QAC9D,CAAC;QAED,0DAA0D;QAC1D,MAAM,YAAY,GAAG,UAAU,CAAC,aAAa,CAAA;QAC7C,KAAK,CAAC,IAAI,CAAC,GAAG,IAAA,iBAAI,EAAC,iBAAiB,CAAC,KAAK,YAAY,WAAW,CAAC,CAAA;QAElE,yDAAyD;QAEzD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;CACF;AAnKD,8CAmKC;AAED,iEAAiE;AACpD,QAAA,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAA"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { ProjectFileContext } from './common/util/file';
|
|
|
2
2
|
import { CliOptions } from './types';
|
|
3
3
|
export declare class CLI {
|
|
4
4
|
private client;
|
|
5
|
-
private chatStorage;
|
|
6
5
|
private readyPromise;
|
|
7
6
|
private git;
|
|
8
7
|
private costMode;
|
|
@@ -14,7 +13,7 @@ export declare class CLI {
|
|
|
14
13
|
private consecutiveFastInputs;
|
|
15
14
|
private pastedContent;
|
|
16
15
|
private isPasting;
|
|
17
|
-
constructor(readyPromise: Promise<[void, ProjectFileContext]>, { git, costMode }: CliOptions);
|
|
16
|
+
constructor(readyPromise: Promise<[void, ProjectFileContext, void]>, { git, costMode }: CliOptions);
|
|
18
17
|
private setupSignalHandlers;
|
|
19
18
|
private initReadlineInterface;
|
|
20
19
|
private completer;
|
|
@@ -26,7 +25,6 @@ export declare class CLI {
|
|
|
26
25
|
private handleUserInput;
|
|
27
26
|
private beforeProcessCommand;
|
|
28
27
|
private processCommand;
|
|
29
|
-
private addAssistantMessageToChat;
|
|
30
28
|
private forwardUserInput;
|
|
31
29
|
private returnControlToUser;
|
|
32
30
|
private onWebSocketError;
|