claude-ws 0.3.93 → 0.3.94
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/package.json +1 -1
- package/server.ts +32 -31
package/package.json
CHANGED
package/server.ts
CHANGED
|
@@ -142,7 +142,7 @@ app.prepare().then(async () => {
|
|
|
142
142
|
model
|
|
143
143
|
} = data;
|
|
144
144
|
|
|
145
|
-
log.info(
|
|
145
|
+
log.info({
|
|
146
146
|
taskId,
|
|
147
147
|
prompt,
|
|
148
148
|
force_create,
|
|
@@ -152,7 +152,7 @@ app.prepare().then(async () => {
|
|
|
152
152
|
projectRootPath,
|
|
153
153
|
outputFormat,
|
|
154
154
|
hasOutputSchema: !!outputSchema
|
|
155
|
-
});
|
|
155
|
+
}, '[Socket] attempt:start received');
|
|
156
156
|
|
|
157
157
|
try {
|
|
158
158
|
let task = await db.query.tasks.findFirst({
|
|
@@ -173,12 +173,12 @@ app.prepare().then(async () => {
|
|
|
173
173
|
where: eq(schema.projects.id, projectId),
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
-
log.info('[Socket] Project exists?'
|
|
176
|
+
log.info({ exists: !!project }, '[Socket] Project exists?');
|
|
177
177
|
|
|
178
178
|
// Create project if it doesn't exist
|
|
179
179
|
if (!project) {
|
|
180
180
|
log.info('[Socket] Project does not exist, checking projectName...');
|
|
181
|
-
log.info('[Socket] projectName value
|
|
181
|
+
log.info({ projectName }, '[Socket] projectName value');
|
|
182
182
|
|
|
183
183
|
if (!projectName || projectName.trim() === '') {
|
|
184
184
|
log.info('[Socket] Project name required but not provided');
|
|
@@ -197,10 +197,10 @@ app.prepare().then(async () => {
|
|
|
197
197
|
|
|
198
198
|
try {
|
|
199
199
|
await mkdir(projectPath, { recursive: true });
|
|
200
|
-
log.info('[Socket] Created project directory
|
|
200
|
+
log.info({ projectPath }, '[Socket] Created project directory');
|
|
201
201
|
} catch (mkdirError: any) {
|
|
202
202
|
if (mkdirError?.code !== 'EEXIST') {
|
|
203
|
-
log.error('[Socket] Failed to create project folder
|
|
203
|
+
log.error({ mkdirError }, '[Socket] Failed to create project folder');
|
|
204
204
|
socket.emit('error', { message: 'Failed to create project folder: ' + mkdirError.message });
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
@@ -213,9 +213,9 @@ app.prepare().then(async () => {
|
|
|
213
213
|
path: projectPath,
|
|
214
214
|
createdAt: Date.now(),
|
|
215
215
|
});
|
|
216
|
-
log.info('[Socket] Created project
|
|
216
|
+
log.info({ projectId }, '[Socket] Created project');
|
|
217
217
|
} catch (error) {
|
|
218
|
-
log.error('[Socket] Failed to create project
|
|
218
|
+
log.error({ error }, '[Socket] Failed to create project');
|
|
219
219
|
socket.emit('error', { message: 'Failed to create project' });
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
@@ -265,14 +265,14 @@ app.prepare().then(async () => {
|
|
|
265
265
|
createdAt: Date.now(),
|
|
266
266
|
updatedAt: Date.now(),
|
|
267
267
|
});
|
|
268
|
-
log.info('[Socket] Created task
|
|
268
|
+
log.info({ taskId }, '[Socket] Created task');
|
|
269
269
|
|
|
270
270
|
// Fetch the created task
|
|
271
271
|
task = await db.query.tasks.findFirst({
|
|
272
272
|
where: eq(schema.tasks.id, taskId),
|
|
273
273
|
});
|
|
274
274
|
} catch (error) {
|
|
275
|
-
log.error('[Socket] Failed to create task
|
|
275
|
+
log.error({ error }, '[Socket] Failed to create task');
|
|
276
276
|
socket.emit('error', { message: 'Failed to create task' });
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
@@ -354,7 +354,7 @@ app.prepare().then(async () => {
|
|
|
354
354
|
// Global event for all clients to track running tasks
|
|
355
355
|
io.emit('task:started', { taskId });
|
|
356
356
|
} catch (error) {
|
|
357
|
-
log.error('Error starting attempt
|
|
357
|
+
log.error({ error }, 'Error starting attempt');
|
|
358
358
|
socket.emit('error', {
|
|
359
359
|
message: error instanceof Error ? error.message : 'Unknown error',
|
|
360
360
|
});
|
|
@@ -413,7 +413,7 @@ app.prepare().then(async () => {
|
|
|
413
413
|
'question:answer',
|
|
414
414
|
async (data: { attemptId: string; toolUseId?: string; questions: unknown[]; answers: Record<string, string> }) => {
|
|
415
415
|
const { attemptId, toolUseId, questions, answers } = data;
|
|
416
|
-
log.info(
|
|
416
|
+
log.info({ attemptId, answers }, '[Server] Received answer');
|
|
417
417
|
|
|
418
418
|
// Check if there's a pending question (canUseTool callback waiting)
|
|
419
419
|
if (agentManager.hasPendingQuestion(attemptId)) {
|
|
@@ -554,7 +554,7 @@ app.prepare().then(async () => {
|
|
|
554
554
|
if (ack) ack({ success: true });
|
|
555
555
|
} catch (error) {
|
|
556
556
|
const errorMsg = error instanceof Error ? error.message : 'Failed to start edit';
|
|
557
|
-
log.error(
|
|
557
|
+
log.error({ errorMsg }, '[Server] Inline edit start error');
|
|
558
558
|
if (ack) ack({ success: false, error: errorMsg });
|
|
559
559
|
}
|
|
560
560
|
});
|
|
@@ -594,7 +594,7 @@ app.prepare().then(async () => {
|
|
|
594
594
|
if (ack) ack({ success });
|
|
595
595
|
} catch (error) {
|
|
596
596
|
const errorMsg = error instanceof Error ? error.message : 'Failed to stop shell';
|
|
597
|
-
log.error(
|
|
597
|
+
log.error({ errorMsg }, '[Server] Shell stop error');
|
|
598
598
|
if (ack) ack({ success: false, error: errorMsg });
|
|
599
599
|
}
|
|
600
600
|
});
|
|
@@ -609,7 +609,7 @@ app.prepare().then(async () => {
|
|
|
609
609
|
if (ack) ack({ logs });
|
|
610
610
|
} catch (error) {
|
|
611
611
|
const errorMsg = error instanceof Error ? error.message : 'Failed to get logs';
|
|
612
|
-
log.error(
|
|
612
|
+
log.error({ errorMsg }, '[Server] Shell getLogs error');
|
|
613
613
|
if (ack) ack({ logs: [], error: errorMsg });
|
|
614
614
|
}
|
|
615
615
|
});
|
|
@@ -622,7 +622,7 @@ app.prepare().then(async () => {
|
|
|
622
622
|
// ========================================
|
|
623
623
|
// Inline Edit Manager Event Handlers
|
|
624
624
|
// ========================================
|
|
625
|
-
log.info(
|
|
625
|
+
log.info({ instanceId: (inlineEditManager as unknown as { _id?: string })._id }, '[Server] Setting up inlineEditManager event handlers');
|
|
626
626
|
|
|
627
627
|
// Forward inline edit deltas to subscribers
|
|
628
628
|
inlineEditManager.on('delta', ({ sessionId, chunk }) => {
|
|
@@ -639,7 +639,7 @@ app.prepare().then(async () => {
|
|
|
639
639
|
|
|
640
640
|
// Forward inline edit errors to subscribers
|
|
641
641
|
inlineEditManager.on('error', ({ sessionId, error }) => {
|
|
642
|
-
log.error(
|
|
642
|
+
log.error({ sessionId, error }, '[Server] Inline edit error');
|
|
643
643
|
io.to(`inline-edit:${sessionId}`).emit('inline-edit:error', { sessionId, error });
|
|
644
644
|
});
|
|
645
645
|
|
|
@@ -674,7 +674,7 @@ app.prepare().then(async () => {
|
|
|
674
674
|
})
|
|
675
675
|
.where(eq(schema.shells.id, shellId));
|
|
676
676
|
} catch (error) {
|
|
677
|
-
log.error(
|
|
677
|
+
log.error({ shellId, error }, '[Server] Failed to update shell in database');
|
|
678
678
|
}
|
|
679
679
|
});
|
|
680
680
|
|
|
@@ -773,11 +773,12 @@ app.prepare().then(async () => {
|
|
|
773
773
|
|
|
774
774
|
// Handle AskUserQuestion detection from AgentManager
|
|
775
775
|
agentManager.on('question', ({ attemptId, toolUseId, questions }) => {
|
|
776
|
-
log.info(
|
|
776
|
+
log.info({
|
|
777
|
+
attemptId,
|
|
777
778
|
toolUseId,
|
|
778
779
|
questionCount: questions?.length,
|
|
779
780
|
questions: questions?.map((q: any) => ({ header: q.header, question: q.question?.substring(0, 50) }))
|
|
780
|
-
});
|
|
781
|
+
}, '[Server] AskUserQuestion detected');
|
|
781
782
|
io.to(`attempt:${attemptId}`).emit('question:ask', {
|
|
782
783
|
attemptId,
|
|
783
784
|
toolUseId,
|
|
@@ -873,7 +874,7 @@ app.prepare().then(async () => {
|
|
|
873
874
|
|
|
874
875
|
log.info(`[Server] Spawned background shell ${shellId} for project ${project.id}`);
|
|
875
876
|
} catch (error) {
|
|
876
|
-
log.error(
|
|
877
|
+
log.error({ error }, '[Server] Failed to spawn background shell');
|
|
877
878
|
}
|
|
878
879
|
});
|
|
879
880
|
|
|
@@ -888,7 +889,7 @@ app.prepare().then(async () => {
|
|
|
888
889
|
});
|
|
889
890
|
|
|
890
891
|
if (!attempt) {
|
|
891
|
-
log.error(
|
|
892
|
+
log.error('[Server] Cannot track process: attempt not found');
|
|
892
893
|
return;
|
|
893
894
|
}
|
|
894
895
|
|
|
@@ -897,7 +898,7 @@ app.prepare().then(async () => {
|
|
|
897
898
|
});
|
|
898
899
|
|
|
899
900
|
if (!task) {
|
|
900
|
-
log.error(
|
|
901
|
+
log.error('[Server] Cannot track process: task not found');
|
|
901
902
|
return;
|
|
902
903
|
}
|
|
903
904
|
|
|
@@ -906,7 +907,7 @@ app.prepare().then(async () => {
|
|
|
906
907
|
});
|
|
907
908
|
|
|
908
909
|
if (!project) {
|
|
909
|
-
log.error(
|
|
910
|
+
log.error('[Server] Cannot track process: project not found');
|
|
910
911
|
return;
|
|
911
912
|
}
|
|
912
913
|
|
|
@@ -931,7 +932,7 @@ app.prepare().then(async () => {
|
|
|
931
932
|
});
|
|
932
933
|
|
|
933
934
|
if (!shellId) {
|
|
934
|
-
log.error(
|
|
935
|
+
log.error({ pid }, '[Server] Failed to track process: PID not alive');
|
|
935
936
|
return;
|
|
936
937
|
}
|
|
937
938
|
|
|
@@ -948,7 +949,7 @@ app.prepare().then(async () => {
|
|
|
948
949
|
|
|
949
950
|
log.info(`[Server] Tracking external process ${shellId} (PID ${pid}) for project ${project.id}`);
|
|
950
951
|
} catch (error) {
|
|
951
|
-
log.error(
|
|
952
|
+
log.error({ error }, '[Server] Failed to track process');
|
|
952
953
|
}
|
|
953
954
|
});
|
|
954
955
|
|
|
@@ -1040,7 +1041,7 @@ app.prepare().then(async () => {
|
|
|
1040
1041
|
);
|
|
1041
1042
|
}
|
|
1042
1043
|
} catch (error) {
|
|
1043
|
-
log.error(
|
|
1044
|
+
log.error({ attemptId, error }, '[Server] Failed to create checkpoint');
|
|
1044
1045
|
}
|
|
1045
1046
|
} else if (attempt) {
|
|
1046
1047
|
// Clear checkpoint tracking on failure
|
|
@@ -1083,7 +1084,7 @@ app.prepare().then(async () => {
|
|
|
1083
1084
|
// Forward tracking module events to Socket.io clients
|
|
1084
1085
|
// Usage tracking (tokens, costs, model usage)
|
|
1085
1086
|
usageTracker.on('usage-update', ({ attemptId, usage }) => {
|
|
1086
|
-
log.info(
|
|
1087
|
+
log.info({ attemptId, totalTokens: usage.totalTokens }, '[Server] Emitting status:usage');
|
|
1087
1088
|
io.to(`attempt:${attemptId}`).emit('status:usage', {
|
|
1088
1089
|
attemptId,
|
|
1089
1090
|
usage,
|
|
@@ -1094,7 +1095,7 @@ app.prepare().then(async () => {
|
|
|
1094
1095
|
workflowTracker.on('workflow-update', ({ attemptId, workflow }) => {
|
|
1095
1096
|
const summary = workflowTracker.getWorkflowSummary(attemptId);
|
|
1096
1097
|
if (summary) {
|
|
1097
|
-
log.info(
|
|
1098
|
+
log.info({ attemptId, chain: summary.chain }, '[Server] Emitting status:workflow');
|
|
1098
1099
|
io.to(`attempt:${attemptId}`).emit('status:workflow', {
|
|
1099
1100
|
attemptId,
|
|
1100
1101
|
workflow: summary,
|
|
@@ -1138,7 +1139,7 @@ app.prepare().then(async () => {
|
|
|
1138
1139
|
});
|
|
1139
1140
|
|
|
1140
1141
|
tunnelService.on('error', ({ error }) => {
|
|
1141
|
-
log.error(
|
|
1142
|
+
log.error({ error }, '[Server] Tunnel error');
|
|
1142
1143
|
io.emit('tunnel:error', { error });
|
|
1143
1144
|
});
|
|
1144
1145
|
|
|
@@ -1152,7 +1153,7 @@ app.prepare().then(async () => {
|
|
|
1152
1153
|
|
|
1153
1154
|
// Try to auto-reconnect tunnel after server is ready
|
|
1154
1155
|
tunnelService.tryAutoReconnect().catch((err) => {
|
|
1155
|
-
log.error('[Server] Failed to auto-reconnect tunnel
|
|
1156
|
+
log.error({ err }, '[Server] Failed to auto-reconnect tunnel');
|
|
1156
1157
|
});
|
|
1157
1158
|
|
|
1158
1159
|
// Log cache stats every 5 minutes for monitoring
|