@phenx-inc/ctlsurf 0.1.9 → 0.1.11
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/out/headless/index.mjs +19 -29
- package/out/headless/index.mjs.map +2 -2
- package/out/main/index.js +19 -29
- package/package.json +1 -1
- package/src/main/bridge.ts +23 -28
- package/src/main/orchestrator.ts +4 -4
package/out/headless/index.mjs
CHANGED
|
@@ -3641,16 +3641,17 @@ var CtlsurfApi = class {
|
|
|
3641
3641
|
var import_headless = __toESM(require_xterm_headless());
|
|
3642
3642
|
var ConversationBridge = class {
|
|
3643
3643
|
wsClient = null;
|
|
3644
|
-
flushTimer = null;
|
|
3645
|
-
flushIntervalMs = 3e3;
|
|
3646
3644
|
sessionActive = false;
|
|
3647
3645
|
inputBuffer = "";
|
|
3646
|
+
bytesAccumulated = 0;
|
|
3648
3647
|
// Virtual terminal for processing escape sequences into rendered text
|
|
3649
3648
|
terminal;
|
|
3650
3649
|
lastSnapshot = "";
|
|
3651
|
-
|
|
3650
|
+
// Flush after accumulating enough data or on a timer
|
|
3651
|
+
FLUSH_BYTES = 2e3;
|
|
3652
|
+
flushTimer = null;
|
|
3652
3653
|
constructor() {
|
|
3653
|
-
this.terminal = new import_headless.Terminal({ cols: 120, rows: 50, scrollback: 1e4 });
|
|
3654
|
+
this.terminal = new import_headless.Terminal({ cols: 120, rows: 50, scrollback: 1e4, allowProposedApi: true });
|
|
3654
3655
|
}
|
|
3655
3656
|
setWsClient(ws) {
|
|
3656
3657
|
this.wsClient = ws;
|
|
@@ -3658,9 +3659,11 @@ var ConversationBridge = class {
|
|
|
3658
3659
|
startSession() {
|
|
3659
3660
|
this.terminal.reset();
|
|
3660
3661
|
this.lastSnapshot = "";
|
|
3661
|
-
this.
|
|
3662
|
+
this.bytesAccumulated = 0;
|
|
3662
3663
|
this.inputBuffer = "";
|
|
3663
3664
|
this.sessionActive = true;
|
|
3665
|
+
if (this.flushTimer) clearInterval(this.flushTimer);
|
|
3666
|
+
this.flushTimer = setInterval(() => this.flush(), 5e3);
|
|
3664
3667
|
console.log("[bridge] Session started");
|
|
3665
3668
|
}
|
|
3666
3669
|
/**
|
|
@@ -3670,17 +3673,11 @@ var ConversationBridge = class {
|
|
|
3670
3673
|
*/
|
|
3671
3674
|
feedOutput(data) {
|
|
3672
3675
|
if (!this.sessionActive) return;
|
|
3673
|
-
this.
|
|
3674
|
-
this.
|
|
3675
|
-
|
|
3676
|
-
this.
|
|
3677
|
-
});
|
|
3678
|
-
}
|
|
3679
|
-
scheduleFlush() {
|
|
3680
|
-
if (this.flushTimer) {
|
|
3681
|
-
clearTimeout(this.flushTimer);
|
|
3676
|
+
this.terminal.write(data);
|
|
3677
|
+
this.bytesAccumulated += data.length;
|
|
3678
|
+
if (this.bytesAccumulated >= this.FLUSH_BYTES) {
|
|
3679
|
+
this.flush();
|
|
3682
3680
|
}
|
|
3683
|
-
this.flushTimer = setTimeout(() => this.flush(), this.flushIntervalMs);
|
|
3684
3681
|
}
|
|
3685
3682
|
feedInput(data) {
|
|
3686
3683
|
if (!this.sessionActive) return;
|
|
@@ -3701,10 +3698,6 @@ var ConversationBridge = class {
|
|
|
3701
3698
|
* Only flushes when all pending writes have completed.
|
|
3702
3699
|
*/
|
|
3703
3700
|
flush() {
|
|
3704
|
-
if (this.pendingWrites > 0) {
|
|
3705
|
-
this.scheduleFlush();
|
|
3706
|
-
return;
|
|
3707
|
-
}
|
|
3708
3701
|
const buf = this.terminal.buffer.active;
|
|
3709
3702
|
const totalLines = buf.baseY + this.terminal.rows;
|
|
3710
3703
|
const allLines = [];
|
|
@@ -3723,6 +3716,7 @@ var ConversationBridge = class {
|
|
|
3723
3716
|
}
|
|
3724
3717
|
this.lastSnapshot = currentSnapshot;
|
|
3725
3718
|
const cleaned = newContent.replace(/\n{3,}/g, "\n\n").trim();
|
|
3719
|
+
this.bytesAccumulated = 0;
|
|
3726
3720
|
if (cleaned.length === 0) return;
|
|
3727
3721
|
this.sendEntry("terminal_output", cleaned);
|
|
3728
3722
|
}
|
|
@@ -3734,15 +3728,11 @@ var ConversationBridge = class {
|
|
|
3734
3728
|
content
|
|
3735
3729
|
});
|
|
3736
3730
|
}
|
|
3737
|
-
|
|
3731
|
+
endSession() {
|
|
3738
3732
|
if (!this.sessionActive) return;
|
|
3739
|
-
if (this.pendingWrites > 0) {
|
|
3740
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
3741
|
-
}
|
|
3742
|
-
this.pendingWrites = 0;
|
|
3743
3733
|
this.flush();
|
|
3744
3734
|
if (this.flushTimer) {
|
|
3745
|
-
|
|
3735
|
+
clearInterval(this.flushTimer);
|
|
3746
3736
|
this.flushTimer = null;
|
|
3747
3737
|
}
|
|
3748
3738
|
this.sessionActive = false;
|
|
@@ -4241,7 +4231,7 @@ var Orchestrator = class {
|
|
|
4241
4231
|
// ─── PTY & Agent ────────────────────────────────
|
|
4242
4232
|
async spawnAgent(agent, cwd) {
|
|
4243
4233
|
if (this.ptyManager) {
|
|
4244
|
-
|
|
4234
|
+
this.bridge.endSession();
|
|
4245
4235
|
this.ptyManager.kill();
|
|
4246
4236
|
}
|
|
4247
4237
|
this.currentAgent = agent;
|
|
@@ -4259,7 +4249,7 @@ var Orchestrator = class {
|
|
|
4259
4249
|
const thisPtyManager = this.ptyManager;
|
|
4260
4250
|
this.ptyManager.onExit(async (exitCode) => {
|
|
4261
4251
|
this.events.onPtyExit(exitCode);
|
|
4262
|
-
|
|
4252
|
+
this.bridge.endSession();
|
|
4263
4253
|
if (thisPtyManager === this.ptyManager && this.currentAgent && isCodingAgent(this.currentAgent)) {
|
|
4264
4254
|
this.workerWs.disconnect();
|
|
4265
4255
|
}
|
|
@@ -4282,7 +4272,7 @@ var Orchestrator = class {
|
|
|
4282
4272
|
this.workerWs.sendTerminalResize(cols, rows);
|
|
4283
4273
|
}
|
|
4284
4274
|
async killAgent() {
|
|
4285
|
-
|
|
4275
|
+
this.bridge.endSession();
|
|
4286
4276
|
this.ptyManager?.kill();
|
|
4287
4277
|
this.ptyManager = null;
|
|
4288
4278
|
if (this.currentAgent && isCodingAgent(this.currentAgent)) {
|
|
@@ -4331,7 +4321,7 @@ var Orchestrator = class {
|
|
|
4331
4321
|
}
|
|
4332
4322
|
// ─── Shutdown ───────────────────────────────────
|
|
4333
4323
|
async shutdown() {
|
|
4334
|
-
|
|
4324
|
+
this.bridge.endSession();
|
|
4335
4325
|
this.ptyManager?.kill();
|
|
4336
4326
|
this.ptyManager = null;
|
|
4337
4327
|
this.workerWs.disconnect();
|