@punkcode/cli 0.1.14 → 0.1.15
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/cli.js +25 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1173,7 +1173,8 @@ async function connect(server, options) {
|
|
|
1173
1173
|
reconnection: true,
|
|
1174
1174
|
reconnectionAttempts: Infinity,
|
|
1175
1175
|
reconnectionDelay: 1e3,
|
|
1176
|
-
reconnectionDelayMax: 5e3
|
|
1176
|
+
reconnectionDelayMax: 5e3,
|
|
1177
|
+
perMessageDeflate: { threshold: 1024 }
|
|
1177
1178
|
});
|
|
1178
1179
|
const activeSessions = /* @__PURE__ */ new Map();
|
|
1179
1180
|
const sleepLock = preventIdleSleep();
|
|
@@ -1435,13 +1436,35 @@ async function handleListSessions(socket, msg, defaultCwd) {
|
|
|
1435
1436
|
logger.info({ count: sessions.length }, "Listed sessions");
|
|
1436
1437
|
}
|
|
1437
1438
|
var DEFAULT_HISTORY_LIMIT = 30;
|
|
1439
|
+
var MAX_PAYLOAD_BYTES = 19.5 * 1024 * 1024;
|
|
1440
|
+
function fitToPayloadLimit(messages) {
|
|
1441
|
+
if (Buffer.byteLength(JSON.stringify(messages), "utf8") <= MAX_PAYLOAD_BYTES) {
|
|
1442
|
+
return messages;
|
|
1443
|
+
}
|
|
1444
|
+
let lo = 0;
|
|
1445
|
+
let hi = messages.length;
|
|
1446
|
+
while (lo < hi) {
|
|
1447
|
+
const mid = Math.floor((lo + hi + 1) / 2);
|
|
1448
|
+
const slice = messages.slice(messages.length - mid);
|
|
1449
|
+
if (Buffer.byteLength(JSON.stringify(slice), "utf8") <= MAX_PAYLOAD_BYTES) {
|
|
1450
|
+
lo = mid;
|
|
1451
|
+
} else {
|
|
1452
|
+
hi = mid - 1;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
return messages.slice(messages.length - lo);
|
|
1456
|
+
}
|
|
1438
1457
|
async function handleLoadSession(socket, msg) {
|
|
1439
1458
|
const { id, sessionId, limit = DEFAULT_HISTORY_LIMIT } = msg;
|
|
1440
1459
|
const log2 = createChildLogger({ sessionId });
|
|
1441
1460
|
log2.info("Loading session...");
|
|
1442
1461
|
const all = await loadSession(sessionId);
|
|
1443
1462
|
if (all) {
|
|
1444
|
-
const
|
|
1463
|
+
const sliced = limit > 0 && all.length > limit ? all.slice(-limit) : all;
|
|
1464
|
+
const messages = fitToPayloadLimit(sliced);
|
|
1465
|
+
if (messages.length < sliced.length) {
|
|
1466
|
+
log2.warn({ requested: sliced.length, sent: messages.length }, "Session payload trimmed to fit size limit");
|
|
1467
|
+
}
|
|
1445
1468
|
send(socket, "response", { type: "history", messages, total: all.length, requestId: id });
|
|
1446
1469
|
log2.info({ count: messages.length, total: all.length }, "Session loaded");
|
|
1447
1470
|
} else {
|