@adhdev/daemon-core 0.7.42 → 0.7.43
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-adapters/provider-cli-adapter.d.ts +2 -4
- package/dist/cli-adapters/pty-transport.d.ts +1 -0
- package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +4 -0
- package/dist/cli-adapters/terminal-backends/types.d.ts +4 -0
- package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +4 -0
- package/dist/cli-adapters/terminal-screen.d.ts +4 -0
- package/dist/config/chat-history.d.ts +0 -3
- package/dist/index.js +72 -116
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -116
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider-instance.d.ts +0 -1
- package/dist/status/normalize.js +0 -7
- package/dist/status/normalize.js.map +1 -1
- package/dist/status/normalize.mjs +0 -7
- package/dist/status/normalize.mjs.map +1 -1
- package/node_modules/@adhdev/session-host-core/dist/index.js +2 -2
- package/node_modules/@adhdev/session-host-core/dist/index.js.map +1 -1
- package/node_modules/@adhdev/session-host-core/dist/index.mjs +2 -2
- package/node_modules/@adhdev/session-host-core/dist/index.mjs.map +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +79 -70
- package/src/cli-adapters/pty-transport.ts +2 -0
- package/src/cli-adapters/session-host-transport.ts +1 -0
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +5 -0
- package/src/cli-adapters/terminal-backends/types.ts +1 -0
- package/src/cli-adapters/terminal-backends/xterm-backend.ts +10 -0
- package/src/cli-adapters/terminal-screen.ts +4 -0
- package/src/config/chat-history.ts +3 -55
- package/src/providers/cli-provider-instance.ts +1 -11
- package/src/providers/provider-instance.d.ts +0 -1
- package/src/providers/provider-instance.ts +0 -1
- package/src/status/normalize.ts +0 -4
|
@@ -29,7 +29,6 @@ export interface CliSessionStatus {
|
|
|
29
29
|
message: string;
|
|
30
30
|
buttons: string[];
|
|
31
31
|
} | null;
|
|
32
|
-
terminalHistory?: string;
|
|
33
32
|
}
|
|
34
33
|
/**
|
|
35
34
|
* CLI Script Functions.
|
|
@@ -65,7 +64,6 @@ export interface CliScriptInput {
|
|
|
65
64
|
rawBuffer: string;
|
|
66
65
|
recentBuffer: string;
|
|
67
66
|
screenText: string;
|
|
68
|
-
terminalHistory?: string;
|
|
69
67
|
messages: CliChatMessage[];
|
|
70
68
|
partialResponse: string;
|
|
71
69
|
}
|
|
@@ -140,6 +138,7 @@ export declare class ProviderCliAdapter implements CliAdapter {
|
|
|
140
138
|
private pendingOutputParseTimer;
|
|
141
139
|
private ptyOutputBuffer;
|
|
142
140
|
private ptyOutputFlushTimer;
|
|
141
|
+
private pendingTerminalQueryTail;
|
|
143
142
|
private serverConn;
|
|
144
143
|
private logBuffer;
|
|
145
144
|
private lastApprovalResolvedAt;
|
|
@@ -165,8 +164,6 @@ export declare class ProviderCliAdapter implements CliAdapter {
|
|
|
165
164
|
private accumulatedRawBuffer;
|
|
166
165
|
/** Current visible terminal screen snapshot */
|
|
167
166
|
private terminalScreen;
|
|
168
|
-
/** Rolling append-only terminal transcript built from screen snapshots */
|
|
169
|
-
private terminalHistory;
|
|
170
167
|
/** Max accumulated buffer size (last 50KB) */
|
|
171
168
|
private static readonly MAX_ACCUMULATED_BUFFER;
|
|
172
169
|
private currentTurnScope;
|
|
@@ -227,4 +224,5 @@ export declare class ProviderCliAdapter implements CliAdapter {
|
|
|
227
224
|
resolveModal(buttonIndex: number): void;
|
|
228
225
|
resize(cols: number, rows: number): void;
|
|
229
226
|
getDebugState(): Record<string, any>;
|
|
227
|
+
private respondToTerminalQueries;
|
|
230
228
|
}
|
|
@@ -24,6 +24,7 @@ export interface PtyRuntimeMetadata {
|
|
|
24
24
|
export interface PtyRuntimeTransport {
|
|
25
25
|
readonly pid: number;
|
|
26
26
|
readonly ready: Promise<void>;
|
|
27
|
+
readonly terminalQueriesHandled?: boolean;
|
|
27
28
|
write(data: string): void;
|
|
28
29
|
resize(cols: number, rows: number): void;
|
|
29
30
|
kill(): void;
|
|
@@ -8,5 +8,9 @@ export declare class GhosttyVtTerminalBackend implements TerminalViewportBackend
|
|
|
8
8
|
resize(rows: number, cols: number): void;
|
|
9
9
|
write(data: string): void;
|
|
10
10
|
getText(): string;
|
|
11
|
+
getCursorPosition(): {
|
|
12
|
+
col: number;
|
|
13
|
+
row: number;
|
|
14
|
+
};
|
|
11
15
|
dispose(): void;
|
|
12
16
|
}
|
|
@@ -8,6 +8,10 @@ export declare class XtermTerminalBackend implements TerminalViewportBackend {
|
|
|
8
8
|
resize(rows: number, cols: number): void;
|
|
9
9
|
write(data: string): void;
|
|
10
10
|
getText(): string;
|
|
11
|
+
getCursorPosition(): {
|
|
12
|
+
col: number;
|
|
13
|
+
row: number;
|
|
14
|
+
};
|
|
11
15
|
dispose(): void;
|
|
12
16
|
private createTerminal;
|
|
13
17
|
}
|
|
@@ -22,8 +22,6 @@ export declare class ChatHistoryWriter {
|
|
|
22
22
|
private lastSeenCounts;
|
|
23
23
|
/** Last seen message hash per agent (deduplication) */
|
|
24
24
|
private lastSeenHashes;
|
|
25
|
-
/** Last seen append-only terminal transcript per agent */
|
|
26
|
-
private lastSeenTerminal;
|
|
27
25
|
private rotated;
|
|
28
26
|
/**
|
|
29
27
|
* Append new messages to history
|
|
@@ -38,7 +36,6 @@ export declare class ChatHistoryWriter {
|
|
|
38
36
|
content: string;
|
|
39
37
|
receivedAt?: number;
|
|
40
38
|
}>, sessionTitle?: string, instanceId?: string): void;
|
|
41
|
-
appendTerminalHistory(agentType: string, terminalHistory: string, sessionTitle?: string, instanceId?: string): void;
|
|
42
39
|
/** Called when agent session is explicitly changed */
|
|
43
40
|
onSessionChange(agentType: string): void;
|
|
44
41
|
/** Delete history files older than 30 days */
|
package/dist/index.js
CHANGED
|
@@ -520,6 +520,9 @@ var init_ghostty_vt_backend = __esm({
|
|
|
520
520
|
getText() {
|
|
521
521
|
return this.terminal.formatPlainText({ trim: true }) || "";
|
|
522
522
|
}
|
|
523
|
+
getCursorPosition() {
|
|
524
|
+
return this.terminal.getCursorPosition();
|
|
525
|
+
}
|
|
523
526
|
dispose() {
|
|
524
527
|
this.terminal.dispose();
|
|
525
528
|
}
|
|
@@ -577,6 +580,13 @@ var init_xterm_backend = __esm({
|
|
|
577
580
|
while (last > first && !lines[last - 1]?.trim()) last--;
|
|
578
581
|
return lines.slice(first, last).join("\n");
|
|
579
582
|
}
|
|
583
|
+
getCursorPosition() {
|
|
584
|
+
const buffer = this.terminal.buffer.active;
|
|
585
|
+
return {
|
|
586
|
+
col: Math.max(0, buffer.cursorX || 0),
|
|
587
|
+
row: Math.max(0, buffer.cursorY || 0)
|
|
588
|
+
};
|
|
589
|
+
}
|
|
580
590
|
dispose() {
|
|
581
591
|
this.terminal.dispose();
|
|
582
592
|
}
|
|
@@ -663,6 +673,9 @@ var init_terminal_screen = __esm({
|
|
|
663
673
|
getText() {
|
|
664
674
|
return this.terminal.getText();
|
|
665
675
|
}
|
|
676
|
+
getCursorPosition() {
|
|
677
|
+
return this.terminal.getCursorPosition();
|
|
678
|
+
}
|
|
666
679
|
dispose() {
|
|
667
680
|
this.terminal.dispose();
|
|
668
681
|
}
|
|
@@ -693,6 +706,7 @@ var init_pty_transport = __esm({
|
|
|
693
706
|
this.handle = handle;
|
|
694
707
|
}
|
|
695
708
|
ready = Promise.resolve();
|
|
709
|
+
terminalQueriesHandled = false;
|
|
696
710
|
get pid() {
|
|
697
711
|
return this.handle.pid;
|
|
698
712
|
}
|
|
@@ -746,6 +760,32 @@ function stripTerminalNoise(str) {
|
|
|
746
760
|
function sanitizeTerminalText(str) {
|
|
747
761
|
return stripTerminalNoise(stripAnsi(str));
|
|
748
762
|
}
|
|
763
|
+
function buildCliSpawnEnv(baseEnv, overrides) {
|
|
764
|
+
const env = {};
|
|
765
|
+
const source = { ...baseEnv, ...overrides || {} };
|
|
766
|
+
for (const [key, value] of Object.entries(source)) {
|
|
767
|
+
if (typeof value !== "string") continue;
|
|
768
|
+
env[key] = value;
|
|
769
|
+
}
|
|
770
|
+
for (const key of Object.keys(env)) {
|
|
771
|
+
if (key === "INIT_CWD" || key === "NO_COLOR" || key === "FORCE_COLOR" || key === "npm_command" || key === "npm_execpath" || key === "npm_node_execpath" || key.startsWith("npm_") || key.startsWith("npm_config_") || key.startsWith("npm_package_") || key.startsWith("npm_lifecycle_") || key.startsWith("PNPM_") || key.startsWith("YARN_") || key.startsWith("BUN_")) {
|
|
772
|
+
delete env[key];
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return env;
|
|
776
|
+
}
|
|
777
|
+
function computeTerminalQueryTail(buffer) {
|
|
778
|
+
const prefixes = ["\x1B[6n", "\x1B[?6n"];
|
|
779
|
+
const maxLength = prefixes.reduce((n, value) => Math.max(n, value.length), 0) - 1;
|
|
780
|
+
const start = Math.max(0, buffer.length - maxLength);
|
|
781
|
+
for (let i = start; i < buffer.length; i++) {
|
|
782
|
+
const suffix = buffer.slice(i);
|
|
783
|
+
if (prefixes.some((pattern) => suffix.length < pattern.length && pattern.startsWith(suffix))) {
|
|
784
|
+
return suffix;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return "";
|
|
788
|
+
}
|
|
749
789
|
function findBinary(name) {
|
|
750
790
|
const isWin = os12.platform() === "win32";
|
|
751
791
|
try {
|
|
@@ -832,36 +872,6 @@ function promptLikelyVisible(screenText, promptSnippet) {
|
|
|
832
872
|
).length;
|
|
833
873
|
return matched >= required;
|
|
834
874
|
}
|
|
835
|
-
function splitHistoryLines(text) {
|
|
836
|
-
return String(text || "").split("\n").map((line) => line.replace(/\s+$/, ""));
|
|
837
|
-
}
|
|
838
|
-
function normalizeHistoryLine(line) {
|
|
839
|
-
return String(line || "").replace(/\s+/g, " ").trim();
|
|
840
|
-
}
|
|
841
|
-
function mergeTerminalHistory(existing, snapshot) {
|
|
842
|
-
const next = String(snapshot || "").trim();
|
|
843
|
-
if (!next) return existing;
|
|
844
|
-
const prev = String(existing || "").trim();
|
|
845
|
-
if (!prev) return next;
|
|
846
|
-
if (prev === next || prev.endsWith(next)) return prev;
|
|
847
|
-
const prevLines = splitHistoryLines(prev);
|
|
848
|
-
const nextLines = splitHistoryLines(next);
|
|
849
|
-
const prevNorm = prevLines.map(normalizeHistoryLine);
|
|
850
|
-
const nextNorm = nextLines.map(normalizeHistoryLine);
|
|
851
|
-
const maxOverlap = Math.min(prevLines.length, nextLines.length);
|
|
852
|
-
for (let overlap = maxOverlap; overlap >= 1; overlap -= 1) {
|
|
853
|
-
const prevTail = prevNorm.slice(prevNorm.length - overlap);
|
|
854
|
-
const nextHead = nextNorm.slice(0, overlap);
|
|
855
|
-
if (prevTail.every((line, index) => line === nextHead[index])) {
|
|
856
|
-
return [...prevLines, ...nextLines.slice(overlap)].join("\n").trim();
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
const compactPrev = prevNorm.join("\n");
|
|
860
|
-
const compactNext = nextNorm.join("\n");
|
|
861
|
-
if (compactPrev.includes(compactNext)) return prev;
|
|
862
|
-
return `${prev}
|
|
863
|
-
${next}`.trim();
|
|
864
|
-
}
|
|
865
875
|
function parsePatternEntry(x) {
|
|
866
876
|
if (x instanceof RegExp) return x;
|
|
867
877
|
if (x && typeof x === "object" && typeof x.source === "string") {
|
|
@@ -976,6 +986,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
976
986
|
pendingOutputParseTimer = null;
|
|
977
987
|
ptyOutputBuffer = "";
|
|
978
988
|
ptyOutputFlushTimer = null;
|
|
989
|
+
pendingTerminalQueryTail = "";
|
|
979
990
|
// Server log forwarding
|
|
980
991
|
serverConn = null;
|
|
981
992
|
logBuffer = [];
|
|
@@ -1007,9 +1018,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
1007
1018
|
/** Full accumulated raw PTY output (with ANSI) */
|
|
1008
1019
|
accumulatedRawBuffer = "";
|
|
1009
1020
|
/** Current visible terminal screen snapshot */
|
|
1010
|
-
terminalScreen = new TerminalScreen(
|
|
1011
|
-
/** Rolling append-only terminal transcript built from screen snapshots */
|
|
1012
|
-
terminalHistory = "";
|
|
1021
|
+
terminalScreen = new TerminalScreen(30, 100);
|
|
1013
1022
|
/** Max accumulated buffer size (last 50KB) */
|
|
1014
1023
|
static MAX_ACCUMULATED_BUFFER = 5e4;
|
|
1015
1024
|
currentTurnScope = null;
|
|
@@ -1031,15 +1040,13 @@ var init_provider_cli_adapter = __esm({
|
|
|
1031
1040
|
return text.slice(start);
|
|
1032
1041
|
}
|
|
1033
1042
|
buildParseInput(baseMessages, partialResponse, scope) {
|
|
1034
|
-
const buffer = scope ? this.sliceFromOffset(this.
|
|
1043
|
+
const buffer = scope ? this.sliceFromOffset(this.accumulatedBuffer, scope.bufferStart) || this.accumulatedBuffer : this.accumulatedBuffer;
|
|
1035
1044
|
const rawBuffer = scope ? this.sliceFromOffset(this.accumulatedRawBuffer, scope.rawBufferStart) || this.accumulatedRawBuffer : this.accumulatedRawBuffer;
|
|
1036
|
-
const terminalHistory = scope ? this.sliceFromOffset(this.terminalHistory, scope.terminalHistoryStart) || this.terminalHistory : this.terminalHistory;
|
|
1037
1045
|
return {
|
|
1038
1046
|
buffer,
|
|
1039
1047
|
rawBuffer,
|
|
1040
1048
|
recentBuffer: buffer.slice(-1e3) || this.recentOutputBuffer,
|
|
1041
1049
|
screenText: this.terminalScreen.getText(),
|
|
1042
|
-
terminalHistory,
|
|
1043
1050
|
messages: [...baseMessages],
|
|
1044
1051
|
partialResponse
|
|
1045
1052
|
};
|
|
@@ -1117,13 +1124,10 @@ var init_provider_cli_adapter = __esm({
|
|
|
1117
1124
|
shellArgs = allArgs;
|
|
1118
1125
|
}
|
|
1119
1126
|
const ptyOpts = {
|
|
1120
|
-
cols:
|
|
1121
|
-
rows:
|
|
1127
|
+
cols: 100,
|
|
1128
|
+
rows: 30,
|
|
1122
1129
|
cwd: this.workingDir,
|
|
1123
|
-
env:
|
|
1124
|
-
...process.env,
|
|
1125
|
-
...spawnConfig.env
|
|
1126
|
-
}
|
|
1130
|
+
env: buildCliSpawnEnv(process.env, spawnConfig.env)
|
|
1127
1131
|
};
|
|
1128
1132
|
try {
|
|
1129
1133
|
this.ptyProcess = this.transportFactory.spawn(shellCmd, shellArgs, ptyOpts);
|
|
@@ -1141,8 +1145,8 @@ var init_provider_cli_adapter = __esm({
|
|
|
1141
1145
|
}
|
|
1142
1146
|
this.ptyProcess.onData((data) => {
|
|
1143
1147
|
if (Date.now() < this.resizeSuppressUntil) return;
|
|
1144
|
-
if (
|
|
1145
|
-
this.
|
|
1148
|
+
if (!this.ptyProcess?.terminalQueriesHandled) {
|
|
1149
|
+
this.respondToTerminalQueries(data);
|
|
1146
1150
|
}
|
|
1147
1151
|
this.pendingOutputParseBuffer += data;
|
|
1148
1152
|
if (!this.pendingOutputParseTimer) {
|
|
@@ -1177,8 +1181,8 @@ var init_provider_cli_adapter = __esm({
|
|
|
1177
1181
|
this.spawnAt = Date.now();
|
|
1178
1182
|
this.startupParseGate = true;
|
|
1179
1183
|
this.startupBuffer = "";
|
|
1180
|
-
this.terminalScreen.reset(
|
|
1181
|
-
this.
|
|
1184
|
+
this.terminalScreen.reset(30, 100);
|
|
1185
|
+
this.pendingTerminalQueryTail = "";
|
|
1182
1186
|
this.currentTurnScope = null;
|
|
1183
1187
|
this.ready = false;
|
|
1184
1188
|
await this.ptyProcess.ready;
|
|
@@ -1188,7 +1192,6 @@ var init_provider_cli_adapter = __esm({
|
|
|
1188
1192
|
// ─── Output Handling ────────────────────────────
|
|
1189
1193
|
handleOutput(rawData) {
|
|
1190
1194
|
this.terminalScreen.write(rawData);
|
|
1191
|
-
this.terminalHistory = mergeTerminalHistory(this.terminalHistory, this.terminalScreen.getText());
|
|
1192
1195
|
const cleanData = sanitizeTerminalText(rawData);
|
|
1193
1196
|
if (this.isWaitingForResponse && cleanData) {
|
|
1194
1197
|
this.responseBuffer = (this.responseBuffer + cleanData).slice(-8e3);
|
|
@@ -1464,8 +1467,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
1464
1467
|
status: this.currentStatus,
|
|
1465
1468
|
messages: [...this.committedMessages],
|
|
1466
1469
|
workingDir: this.workingDir,
|
|
1467
|
-
activeModal: this.activeModal
|
|
1468
|
-
terminalHistory: this.terminalHistory
|
|
1470
|
+
activeModal: this.activeModal
|
|
1469
1471
|
};
|
|
1470
1472
|
}
|
|
1471
1473
|
/**
|
|
@@ -1483,7 +1485,6 @@ var init_provider_cli_adapter = __esm({
|
|
|
1483
1485
|
id: parsed.id || "cli_session",
|
|
1484
1486
|
status: parsed.status || this.currentStatus,
|
|
1485
1487
|
title: parsed.title || this.cliName,
|
|
1486
|
-
terminalHistory: this.terminalHistory,
|
|
1487
1488
|
messages: parsed.messages,
|
|
1488
1489
|
activeModal: parsed.activeModal ?? this.activeModal
|
|
1489
1490
|
};
|
|
@@ -1493,7 +1494,6 @@ var init_provider_cli_adapter = __esm({
|
|
|
1493
1494
|
id: "cli_session",
|
|
1494
1495
|
status: this.currentStatus,
|
|
1495
1496
|
title: this.cliName,
|
|
1496
|
-
terminalHistory: this.terminalHistory,
|
|
1497
1497
|
messages: messages.slice(-50).map((message, index) => ({
|
|
1498
1498
|
id: `msg_${index}`,
|
|
1499
1499
|
role: message.role,
|
|
@@ -1561,10 +1561,9 @@ ${data.message || ""}`.trim();
|
|
|
1561
1561
|
prompt: text,
|
|
1562
1562
|
startedAt: Date.now(),
|
|
1563
1563
|
bufferStart: this.accumulatedBuffer.length,
|
|
1564
|
-
rawBufferStart: this.accumulatedRawBuffer.length
|
|
1565
|
-
terminalHistoryStart: this.terminalHistory.length
|
|
1564
|
+
rawBufferStart: this.accumulatedRawBuffer.length
|
|
1566
1565
|
};
|
|
1567
|
-
LOG.info("CLI", `[${this.cliType}] sendMessage turn scope buffer=${this.currentTurnScope.bufferStart} raw=${this.currentTurnScope.rawBufferStart}
|
|
1566
|
+
LOG.info("CLI", `[${this.cliType}] sendMessage turn scope buffer=${this.currentTurnScope.bufferStart} raw=${this.currentTurnScope.rawBufferStart} prompt=${JSON.stringify(text).slice(0, 120)}`);
|
|
1568
1567
|
this.submitRetryUsed = false;
|
|
1569
1568
|
this.submitRetryPromptSnippet = extractPromptRetrySnippet(text);
|
|
1570
1569
|
const normalizedPromptSnippet = normalizePromptText(this.submitRetryPromptSnippet);
|
|
@@ -1749,6 +1748,7 @@ ${data.message || ""}`.trim();
|
|
|
1749
1748
|
this.pendingOutputParseTimer = null;
|
|
1750
1749
|
}
|
|
1751
1750
|
this.pendingOutputParseBuffer = "";
|
|
1751
|
+
this.pendingTerminalQueryTail = "";
|
|
1752
1752
|
if (this.ptyOutputFlushTimer) {
|
|
1753
1753
|
clearTimeout(this.ptyOutputFlushTimer);
|
|
1754
1754
|
this.ptyOutputFlushTimer = null;
|
|
@@ -1788,6 +1788,7 @@ ${data.message || ""}`.trim();
|
|
|
1788
1788
|
this.pendingOutputParseTimer = null;
|
|
1789
1789
|
}
|
|
1790
1790
|
this.pendingOutputParseBuffer = "";
|
|
1791
|
+
this.pendingTerminalQueryTail = "";
|
|
1791
1792
|
if (this.ptyOutputFlushTimer) {
|
|
1792
1793
|
clearTimeout(this.ptyOutputFlushTimer);
|
|
1793
1794
|
this.ptyOutputFlushTimer = null;
|
|
@@ -1814,7 +1815,6 @@ ${data.message || ""}`.trim();
|
|
|
1814
1815
|
this.syncMessageViews();
|
|
1815
1816
|
this.accumulatedBuffer = "";
|
|
1816
1817
|
this.accumulatedRawBuffer = "";
|
|
1817
|
-
this.terminalHistory = "";
|
|
1818
1818
|
this.currentTurnScope = null;
|
|
1819
1819
|
this.submitRetryUsed = false;
|
|
1820
1820
|
this.submitRetryPromptSnippet = "";
|
|
@@ -1823,6 +1823,7 @@ ${data.message || ""}`.trim();
|
|
|
1823
1823
|
this.pendingOutputParseTimer = null;
|
|
1824
1824
|
}
|
|
1825
1825
|
this.pendingOutputParseBuffer = "";
|
|
1826
|
+
this.pendingTerminalQueryTail = "";
|
|
1826
1827
|
if (this.ptyOutputFlushTimer) {
|
|
1827
1828
|
clearTimeout(this.ptyOutputFlushTimer);
|
|
1828
1829
|
this.ptyOutputFlushTimer = null;
|
|
@@ -1884,7 +1885,6 @@ ${data.message || ""}`.trim();
|
|
|
1884
1885
|
structuredMessages: this.structuredMessages.slice(-20),
|
|
1885
1886
|
messageCount: this.committedMessages.length,
|
|
1886
1887
|
screenText: sanitizeTerminalText(this.terminalScreen.getText()).slice(-4e3),
|
|
1887
|
-
terminalHistory: this.terminalHistory.slice(-8e3),
|
|
1888
1888
|
currentTurnScope: this.currentTurnScope,
|
|
1889
1889
|
startupBuffer: this.startupBuffer.slice(-4e3),
|
|
1890
1890
|
recentOutputBuffer: this.recentOutputBuffer.slice(-500),
|
|
@@ -1912,6 +1912,20 @@ ${data.message || ""}`.trim();
|
|
|
1912
1912
|
ptyAlive: !!this.ptyProcess
|
|
1913
1913
|
};
|
|
1914
1914
|
}
|
|
1915
|
+
respondToTerminalQueries(data) {
|
|
1916
|
+
if (!this.ptyProcess || !data) return;
|
|
1917
|
+
const combined = this.pendingTerminalQueryTail + data;
|
|
1918
|
+
const regex = /\x1b\[(\?)?6n/g;
|
|
1919
|
+
let match;
|
|
1920
|
+
while ((match = regex.exec(combined)) !== null) {
|
|
1921
|
+
const cursor = this.terminalScreen.getCursorPosition();
|
|
1922
|
+
const row = Math.max(1, (cursor.row | 0) + 1);
|
|
1923
|
+
const col = Math.max(1, (cursor.col | 0) + 1);
|
|
1924
|
+
const response = match[1] ? `\x1B[?${row};${col}R` : `\x1B[${row};${col}R`;
|
|
1925
|
+
this.ptyProcess.write(response);
|
|
1926
|
+
}
|
|
1927
|
+
this.pendingTerminalQueryTail = computeTerminalQueryTail(combined);
|
|
1928
|
+
}
|
|
1915
1929
|
};
|
|
1916
1930
|
}
|
|
1917
1931
|
});
|
|
@@ -4006,8 +4020,6 @@ var ChatHistoryWriter = class {
|
|
|
4006
4020
|
lastSeenCounts = /* @__PURE__ */ new Map();
|
|
4007
4021
|
/** Last seen message hash per agent (deduplication) */
|
|
4008
4022
|
lastSeenHashes = /* @__PURE__ */ new Map();
|
|
4009
|
-
/** Last seen append-only terminal transcript per agent */
|
|
4010
|
-
lastSeenTerminal = /* @__PURE__ */ new Map();
|
|
4011
4023
|
rotated = false;
|
|
4012
4024
|
/**
|
|
4013
4025
|
* Append new messages to history
|
|
@@ -4065,51 +4077,10 @@ var ChatHistoryWriter = class {
|
|
|
4065
4077
|
} catch {
|
|
4066
4078
|
}
|
|
4067
4079
|
}
|
|
4068
|
-
appendTerminalHistory(agentType, terminalHistory, sessionTitle, instanceId) {
|
|
4069
|
-
const next = String(terminalHistory || "");
|
|
4070
|
-
if (!next.trim()) return;
|
|
4071
|
-
try {
|
|
4072
|
-
const dedupKey = instanceId ? `${agentType}:${instanceId}:terminal` : `${agentType}:terminal`;
|
|
4073
|
-
const prev = this.lastSeenTerminal.get(dedupKey) || "";
|
|
4074
|
-
if (prev === next) return;
|
|
4075
|
-
let delta = "";
|
|
4076
|
-
if (!prev) {
|
|
4077
|
-
delta = next;
|
|
4078
|
-
} else if (next.startsWith(prev)) {
|
|
4079
|
-
delta = next.slice(prev.length);
|
|
4080
|
-
} else if (prev.includes(next)) {
|
|
4081
|
-
this.lastSeenTerminal.set(dedupKey, next);
|
|
4082
|
-
return;
|
|
4083
|
-
} else {
|
|
4084
|
-
delta = `
|
|
4085
|
-
|
|
4086
|
-
[terminal snapshot reset ${(/* @__PURE__ */ new Date()).toISOString()} | ${sessionTitle || agentType}]
|
|
4087
|
-
${next}`;
|
|
4088
|
-
}
|
|
4089
|
-
if (!delta) {
|
|
4090
|
-
this.lastSeenTerminal.set(dedupKey, next);
|
|
4091
|
-
return;
|
|
4092
|
-
}
|
|
4093
|
-
const dir = path4.join(HISTORY_DIR, this.sanitize(agentType));
|
|
4094
|
-
fs3.mkdirSync(dir, { recursive: true });
|
|
4095
|
-
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
4096
|
-
const filePrefix = instanceId ? `${this.sanitize(instanceId)}_` : "";
|
|
4097
|
-
const filePath = path4.join(dir, `${filePrefix}${date}.terminal.log`);
|
|
4098
|
-
fs3.appendFileSync(filePath, delta, "utf-8");
|
|
4099
|
-
this.lastSeenTerminal.set(dedupKey, next);
|
|
4100
|
-
if (!this.rotated) {
|
|
4101
|
-
this.rotated = true;
|
|
4102
|
-
this.rotateOldFiles().catch(() => {
|
|
4103
|
-
});
|
|
4104
|
-
}
|
|
4105
|
-
} catch {
|
|
4106
|
-
}
|
|
4107
|
-
}
|
|
4108
4080
|
/** Called when agent session is explicitly changed */
|
|
4109
4081
|
onSessionChange(agentType) {
|
|
4110
4082
|
this.lastSeenHashes.delete(agentType);
|
|
4111
4083
|
this.lastSeenCounts.delete(agentType);
|
|
4112
|
-
this.lastSeenTerminal.delete(`${agentType}:terminal`);
|
|
4113
4084
|
}
|
|
4114
4085
|
/** Delete history files older than 30 days */
|
|
4115
4086
|
async rotateOldFiles() {
|
|
@@ -4962,7 +4933,6 @@ var STATUS_ACTIVE_CHAT_MESSAGE_LIMIT = 60;
|
|
|
4962
4933
|
var STATUS_ACTIVE_CHAT_TOTAL_BYTES_LIMIT = 96 * 1024;
|
|
4963
4934
|
var STATUS_ACTIVE_CHAT_STRING_LIMIT = 4 * 1024;
|
|
4964
4935
|
var STATUS_ACTIVE_CHAT_FALLBACK_STRING_LIMIT = 1024;
|
|
4965
|
-
var STATUS_TERMINAL_HISTORY_LIMIT = 8 * 1024;
|
|
4966
4936
|
var STATUS_INPUT_CONTENT_LIMIT = 2 * 1024;
|
|
4967
4937
|
var STATUS_MODAL_MESSAGE_LIMIT = 2 * 1024;
|
|
4968
4938
|
var STATUS_MODAL_BUTTON_LIMIT = 120;
|
|
@@ -4971,11 +4941,6 @@ function truncateString(value, maxChars) {
|
|
|
4971
4941
|
if (maxChars <= 12) return value.slice(0, Math.max(0, maxChars));
|
|
4972
4942
|
return `${value.slice(0, maxChars - 12)}...[truncated]`;
|
|
4973
4943
|
}
|
|
4974
|
-
function truncateStringTail(value, maxChars) {
|
|
4975
|
-
if (value.length <= maxChars) return value;
|
|
4976
|
-
if (maxChars <= 12) return value.slice(value.length - Math.max(0, maxChars));
|
|
4977
|
-
return `...[truncated]${value.slice(value.length - (maxChars - 12))}`;
|
|
4978
|
-
}
|
|
4979
4944
|
function trimStructuredStrings(value, maxChars) {
|
|
4980
4945
|
if (typeof value === "string") return truncateString(value, maxChars);
|
|
4981
4946
|
if (Array.isArray(value)) return value.map((item) => trimStructuredStrings(item, maxChars));
|
|
@@ -5049,7 +5014,6 @@ function normalizeActiveChatData(activeChat) {
|
|
|
5049
5014
|
(button) => truncateString(String(button || ""), STATUS_MODAL_BUTTON_LIMIT)
|
|
5050
5015
|
)
|
|
5051
5016
|
} : activeChat.activeModal,
|
|
5052
|
-
terminalHistory: activeChat.terminalHistory ? truncateStringTail(activeChat.terminalHistory, STATUS_TERMINAL_HISTORY_LIMIT) : activeChat.terminalHistory,
|
|
5053
5017
|
inputContent: activeChat.inputContent ? truncateString(activeChat.inputContent, STATUS_INPUT_CONTENT_LIMIT) : activeChat.inputContent
|
|
5054
5018
|
};
|
|
5055
5019
|
}
|
|
@@ -9363,7 +9327,7 @@ var CliProviderInstance = class {
|
|
|
9363
9327
|
this.cliArgs = cliArgs;
|
|
9364
9328
|
this.type = provider.type;
|
|
9365
9329
|
this.instanceId = instanceId || crypto3.randomUUID();
|
|
9366
|
-
this.presentationMode = "
|
|
9330
|
+
this.presentationMode = "chat";
|
|
9367
9331
|
this.adapter = new ProviderCliAdapter(provider, workingDir, cliArgs, transportFactory);
|
|
9368
9332
|
this.monitor = new StatusMonitor();
|
|
9369
9333
|
this.historyWriter = new ChatHistoryWriter();
|
|
@@ -9410,14 +9374,6 @@ var CliProviderInstance = class {
|
|
|
9410
9374
|
const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
|
|
9411
9375
|
const runtime = this.adapter.getRuntimeMetadata();
|
|
9412
9376
|
const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
|
|
9413
|
-
if (adapterStatus.terminalHistory?.trim()) {
|
|
9414
|
-
this.historyWriter.appendTerminalHistory(
|
|
9415
|
-
this.type,
|
|
9416
|
-
adapterStatus.terminalHistory,
|
|
9417
|
-
`${this.provider.name} \xB7 ${dirName}`,
|
|
9418
|
-
this.instanceId
|
|
9419
|
-
);
|
|
9420
|
-
}
|
|
9421
9377
|
return {
|
|
9422
9378
|
type: this.type,
|
|
9423
9379
|
name: this.provider.name,
|
|
@@ -9430,7 +9386,6 @@ var CliProviderInstance = class {
|
|
|
9430
9386
|
status: parsedStatus?.status || adapterStatus.status,
|
|
9431
9387
|
messages: Array.isArray(parsedStatus?.messages) ? parsedStatus.messages : [],
|
|
9432
9388
|
activeModal: parsedStatus?.activeModal ?? adapterStatus.activeModal,
|
|
9433
|
-
terminalHistory: adapterStatus.terminalHistory,
|
|
9434
9389
|
inputContent: ""
|
|
9435
9390
|
},
|
|
9436
9391
|
workspace: this.workingDir,
|
|
@@ -16014,6 +15969,7 @@ var SessionHostRuntimeTransport = class {
|
|
|
16014
15969
|
this.ready = this.boot();
|
|
16015
15970
|
}
|
|
16016
15971
|
ready;
|
|
15972
|
+
terminalQueriesHandled = true;
|
|
16017
15973
|
client;
|
|
16018
15974
|
dataCallbacks = /* @__PURE__ */ new Set();
|
|
16019
15975
|
exitCallbacks = /* @__PURE__ */ new Set();
|