replicas-engine 0.1.8 → 0.1.9
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.
|
@@ -24,17 +24,20 @@ export class CodexManager {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
async sendMessage(message) {
|
|
27
|
+
console.log(`[CodexManager] sendMessage called with message length: ${message.length}`);
|
|
27
28
|
if (!this.currentThread) {
|
|
28
29
|
if (this.currentThreadId) {
|
|
29
|
-
console.log(`Resuming thread ${this.currentThreadId}`);
|
|
30
|
+
console.log(`[CodexManager] Resuming existing thread: ${this.currentThreadId}`);
|
|
30
31
|
this.currentThread = this.codex.resumeThread(this.currentThreadId, {
|
|
31
32
|
workingDirectory: this.workingDirectory,
|
|
32
33
|
skipGitRepoCheck: true,
|
|
33
34
|
sandboxMode: 'danger-full-access',
|
|
34
35
|
});
|
|
36
|
+
console.log(`[CodexManager] Thread resumed successfully`);
|
|
35
37
|
}
|
|
36
38
|
else {
|
|
37
|
-
console.log('
|
|
39
|
+
console.log('[CodexManager] No existing thread, starting new thread');
|
|
40
|
+
console.log(`[CodexManager] Working directory: ${this.workingDirectory}`);
|
|
38
41
|
this.currentThread = this.codex.startThread({
|
|
39
42
|
workingDirectory: this.workingDirectory,
|
|
40
43
|
skipGitRepoCheck: true,
|
|
@@ -42,10 +45,14 @@ export class CodexManager {
|
|
|
42
45
|
});
|
|
43
46
|
if (this.currentThread.id) {
|
|
44
47
|
this.currentThreadId = this.currentThread.id;
|
|
45
|
-
console.log(`
|
|
48
|
+
console.log(`[CodexManager] New thread created with ID: ${this.currentThreadId}`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.error('[CodexManager] ERROR: Thread created but no ID available');
|
|
46
52
|
}
|
|
47
53
|
// prime the thread with system instructions if thread is new
|
|
48
54
|
const workspaceName = process.env.WORKSPACE_NAME || 'workspace';
|
|
55
|
+
console.log(`[CodexManager] Workspace name from env: ${workspaceName}`);
|
|
49
56
|
const workspaceBranchSegment = workspaceName
|
|
50
57
|
.trim()
|
|
51
58
|
.toLowerCase()
|
|
@@ -53,62 +60,97 @@ export class CodexManager {
|
|
|
53
60
|
.replace(/^-+|-+$/g, '') || 'workspace';
|
|
54
61
|
const uuid = randomUUID().slice(0, 8);
|
|
55
62
|
const branchName = `replicas/${workspaceBranchSegment}-${uuid}`;
|
|
63
|
+
console.log(`[CodexManager] Generated branch name: ${branchName}`);
|
|
56
64
|
const systemMessage = `<replicas_important_instructions>When completing solutions, push your changes to branch ${branchName} and to origin. Greet the user.</replicas_important_instructions>`;
|
|
57
|
-
console.log('
|
|
65
|
+
console.log('[CodexManager] Starting thread priming with system instructions');
|
|
66
|
+
const primingStartTime = Date.now();
|
|
58
67
|
await this.currentThread.run(systemMessage);
|
|
59
|
-
|
|
68
|
+
const primingDuration = Date.now() - primingStartTime;
|
|
69
|
+
console.log(`[CodexManager] Thread priming completed in ${primingDuration}ms`);
|
|
60
70
|
}
|
|
61
71
|
}
|
|
72
|
+
else {
|
|
73
|
+
console.log(`[CodexManager] Using existing thread object for thread ID: ${this.currentThreadId}`);
|
|
74
|
+
}
|
|
75
|
+
console.log(`[CodexManager] Running user message on thread ${this.currentThreadId}`);
|
|
76
|
+
const messageStartTime = Date.now();
|
|
62
77
|
await this.currentThread.run(message);
|
|
78
|
+
const messageDuration = Date.now() - messageStartTime;
|
|
79
|
+
console.log(`[CodexManager] User message run completed in ${messageDuration}ms`);
|
|
63
80
|
}
|
|
64
81
|
async getHistory() {
|
|
82
|
+
console.log('[CodexManager] getHistory called');
|
|
65
83
|
if (!this.currentThreadId) {
|
|
84
|
+
console.log('[CodexManager] No active thread ID, returning empty history');
|
|
66
85
|
return {
|
|
67
86
|
thread_id: null,
|
|
68
87
|
events: [],
|
|
69
88
|
};
|
|
70
89
|
}
|
|
90
|
+
console.log(`[CodexManager] Looking for session file for thread: ${this.currentThreadId}`);
|
|
71
91
|
const sessionFile = await findSessionFile(this.currentThreadId);
|
|
72
92
|
if (!sessionFile) {
|
|
73
|
-
console.warn(`Session file not found for thread ${this.currentThreadId}`);
|
|
93
|
+
console.warn(`[CodexManager] WARNING: Session file not found for thread ${this.currentThreadId}`);
|
|
74
94
|
return {
|
|
75
95
|
thread_id: this.currentThreadId,
|
|
76
96
|
events: [],
|
|
77
97
|
};
|
|
78
98
|
}
|
|
79
|
-
console.log(`Reading session file: ${sessionFile}`);
|
|
99
|
+
console.log(`[CodexManager] Reading session file: ${sessionFile}`);
|
|
80
100
|
const events = await readJSONL(sessionFile);
|
|
101
|
+
console.log(`[CodexManager] Read ${events.length} events from session file`);
|
|
81
102
|
const filteredEvents = events.filter((event) => {
|
|
82
103
|
const eventStr = JSON.stringify(event);
|
|
83
104
|
return !eventStr.includes('<replicas_important_instructions>');
|
|
84
105
|
});
|
|
106
|
+
const filteredCount = events.length - filteredEvents.length;
|
|
107
|
+
if (filteredCount > 0) {
|
|
108
|
+
console.log(`[CodexManager] Filtered out ${filteredCount} priming events`);
|
|
109
|
+
}
|
|
110
|
+
console.log(`[CodexManager] Returning ${filteredEvents.length} events`);
|
|
85
111
|
return {
|
|
86
112
|
thread_id: this.currentThreadId,
|
|
87
113
|
events: filteredEvents,
|
|
88
114
|
};
|
|
89
115
|
}
|
|
90
116
|
async getStatus() {
|
|
117
|
+
console.log('[CodexManager] getStatus called');
|
|
91
118
|
let sessionFile = null;
|
|
92
119
|
if (this.currentThreadId) {
|
|
120
|
+
console.log(`[CodexManager] Checking for session file for thread: ${this.currentThreadId}`);
|
|
93
121
|
sessionFile = await findSessionFile(this.currentThreadId);
|
|
122
|
+
if (sessionFile) {
|
|
123
|
+
console.log(`[CodexManager] Session file found: ${sessionFile}`);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.log('[CodexManager] Session file not found');
|
|
127
|
+
}
|
|
94
128
|
}
|
|
95
|
-
|
|
129
|
+
else {
|
|
130
|
+
console.log('[CodexManager] No active thread ID');
|
|
131
|
+
}
|
|
132
|
+
const status = {
|
|
96
133
|
has_active_thread: this.currentThreadId !== null,
|
|
97
134
|
thread_id: this.currentThreadId,
|
|
98
135
|
session_file: sessionFile,
|
|
99
136
|
working_directory: this.workingDirectory,
|
|
100
137
|
};
|
|
138
|
+
console.log(`[CodexManager] Status: ${JSON.stringify(status)}`);
|
|
139
|
+
return status;
|
|
101
140
|
}
|
|
102
141
|
reset() {
|
|
103
|
-
console.log(
|
|
142
|
+
console.log(`[CodexManager] Resetting thread (was: ${this.currentThreadId})`);
|
|
104
143
|
this.currentThread = null;
|
|
105
144
|
this.currentThreadId = null;
|
|
145
|
+
console.log('[CodexManager] Thread reset complete');
|
|
106
146
|
}
|
|
107
147
|
getThreadId() {
|
|
108
148
|
return this.currentThreadId;
|
|
109
149
|
}
|
|
110
150
|
async getUpdates(since) {
|
|
151
|
+
console.log(`[CodexManager] getUpdates called with since: ${since}`);
|
|
111
152
|
if (!this.currentThreadId) {
|
|
153
|
+
console.log('[CodexManager] No active thread, returning empty updates');
|
|
112
154
|
return {
|
|
113
155
|
events: [],
|
|
114
156
|
isComplete: true,
|
|
@@ -116,20 +158,24 @@ export class CodexManager {
|
|
|
116
158
|
}
|
|
117
159
|
const sessionFile = await findSessionFile(this.currentThreadId);
|
|
118
160
|
if (!sessionFile) {
|
|
161
|
+
console.log('[CodexManager] Session file not found, returning empty updates');
|
|
119
162
|
return {
|
|
120
163
|
events: [],
|
|
121
164
|
isComplete: true,
|
|
122
165
|
};
|
|
123
166
|
}
|
|
124
167
|
const allEvents = await readJSONL(sessionFile);
|
|
168
|
+
console.log(`[CodexManager] Read ${allEvents.length} total events`);
|
|
125
169
|
// Filter events that occurred after the 'since' timestamp
|
|
126
170
|
const filteredEvents = allEvents.filter((event) => {
|
|
127
171
|
return event.timestamp > since;
|
|
128
172
|
});
|
|
173
|
+
console.log(`[CodexManager] Found ${filteredEvents.length} events since ${since}`);
|
|
129
174
|
// Check if thread is complete by looking for turn.completed or error events
|
|
130
175
|
const isComplete = this.currentThread === null ||
|
|
131
176
|
allEvents.some((event) => event.type === 'event_msg' &&
|
|
132
177
|
(event.payload?.type === 'turn.completed' || event.payload?.type === 'error'));
|
|
178
|
+
console.log(`[CodexManager] Thread complete: ${isComplete}`);
|
|
133
179
|
return {
|
|
134
180
|
events: filteredEvents,
|
|
135
181
|
isComplete,
|