@exreve/exk 1.0.74 → 1.0.75

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.
@@ -1087,6 +1087,26 @@ export class AgentSessionManager {
1087
1087
  session.claudeProcessGroupId = undefined;
1088
1088
  }
1089
1089
  }
1090
+ /**
1091
+ * Compact session context — proactively clear SDK session and inject
1092
+ * a summary on the next prompt. Prevents hitting the hard context
1093
+ * window limit.
1094
+ */
1095
+ compactSession(sessionId) {
1096
+ const session = this.sessions.get(sessionId);
1097
+ if (!session)
1098
+ return false;
1099
+ // Don't compact while a prompt is actively running
1100
+ if (session.isProcessingQueue && session.activeBackendStream)
1101
+ return false;
1102
+ const prevSdkSessionId = session.sdkSessionId;
1103
+ session.sdkSessionId = undefined;
1104
+ session.contextLost = true;
1105
+ session.messages = [];
1106
+ deleteSessionState(sessionId);
1107
+ console.log(`[AgentSessionManager] Session compacted: ${sessionId} (was ${prevSdkSessionId ?? 'empty'})`);
1108
+ return true;
1109
+ }
1090
1110
  /**
1091
1111
  * Emergency stop - immediately halt all activity in a session
1092
1112
  * This is a forceful stop that kills all processes and clears state
@@ -243,6 +243,35 @@ export function registerSessionHandlers(socket, foreground, activeSessions, getS
243
243
  callback?.({ success: false, error: error.message });
244
244
  }
245
245
  });
246
+ socket.on('session:compact', async (data, callback) => {
247
+ try {
248
+ const { sessionId } = data;
249
+ if (!sessionId) {
250
+ callback?.({ success: false, message: 'Missing sessionId' });
251
+ return;
252
+ }
253
+ if (foreground) {
254
+ console.log(`[CLI] Compacting session: ${sessionId}`);
255
+ }
256
+ const compacted = agentSessionManager.compactSession(sessionId);
257
+ if (compacted) {
258
+ getSocket().emit('session:compacted', {
259
+ sessionId,
260
+ timestamp: Date.now(),
261
+ });
262
+ callback?.({ success: true, message: 'Session context compacted' });
263
+ }
264
+ else {
265
+ callback?.({ success: false, message: 'Session not found or prompt is running' });
266
+ }
267
+ }
268
+ catch (error) {
269
+ if (foreground) {
270
+ console.error(`✗ Error compacting session: ${error.message}`);
271
+ }
272
+ callback?.({ success: false, message: error.message });
273
+ }
274
+ });
246
275
  socket.on('emergency:stop', async (data, callback) => {
247
276
  try {
248
277
  const { sessionId } = data;
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exreve/exk",
3
- "version": "1.0.74",
3
+ "version": "1.0.75",
4
4
  "description": "exk - Control Claude CLI with voice and programmable interfaces",
5
5
  "type": "module",
6
6
  "bin": {