adhdev 0.7.42 → 0.7.44

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/index.js CHANGED
@@ -2532,8 +2532,6 @@ var init_chat_history = __esm({
2532
2532
  lastSeenCounts = /* @__PURE__ */ new Map();
2533
2533
  /** Last seen message hash per agent (deduplication) */
2534
2534
  lastSeenHashes = /* @__PURE__ */ new Map();
2535
- /** Last seen append-only terminal transcript per agent */
2536
- lastSeenTerminal = /* @__PURE__ */ new Map();
2537
2535
  rotated = false;
2538
2536
  /**
2539
2537
  * Append new messages to history
@@ -2591,51 +2589,10 @@ var init_chat_history = __esm({
2591
2589
  } catch {
2592
2590
  }
2593
2591
  }
2594
- appendTerminalHistory(agentType, terminalHistory, sessionTitle, instanceId) {
2595
- const next = String(terminalHistory || "");
2596
- if (!next.trim()) return;
2597
- try {
2598
- const dedupKey = instanceId ? `${agentType}:${instanceId}:terminal` : `${agentType}:terminal`;
2599
- const prev = this.lastSeenTerminal.get(dedupKey) || "";
2600
- if (prev === next) return;
2601
- let delta = "";
2602
- if (!prev) {
2603
- delta = next;
2604
- } else if (next.startsWith(prev)) {
2605
- delta = next.slice(prev.length);
2606
- } else if (prev.includes(next)) {
2607
- this.lastSeenTerminal.set(dedupKey, next);
2608
- return;
2609
- } else {
2610
- delta = `
2611
-
2612
- [terminal snapshot reset ${(/* @__PURE__ */ new Date()).toISOString()} | ${sessionTitle || agentType}]
2613
- ${next}`;
2614
- }
2615
- if (!delta) {
2616
- this.lastSeenTerminal.set(dedupKey, next);
2617
- return;
2618
- }
2619
- const dir = path4.join(HISTORY_DIR, this.sanitize(agentType));
2620
- fs3.mkdirSync(dir, { recursive: true });
2621
- const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
2622
- const filePrefix = instanceId ? `${this.sanitize(instanceId)}_` : "";
2623
- const filePath = path4.join(dir, `${filePrefix}${date5}.terminal.log`);
2624
- fs3.appendFileSync(filePath, delta, "utf-8");
2625
- this.lastSeenTerminal.set(dedupKey, next);
2626
- if (!this.rotated) {
2627
- this.rotated = true;
2628
- this.rotateOldFiles().catch(() => {
2629
- });
2630
- }
2631
- } catch {
2632
- }
2633
- }
2634
2592
  /** Called when agent session is explicitly changed */
2635
2593
  onSessionChange(agentType) {
2636
2594
  this.lastSeenHashes.delete(agentType);
2637
2595
  this.lastSeenCounts.delete(agentType);
2638
- this.lastSeenTerminal.delete(`${agentType}:terminal`);
2639
2596
  }
2640
2597
  /** Delete history files older than 30 days */
2641
2598
  async rotateOldFiles() {
@@ -3328,11 +3285,6 @@ function truncateString(value, maxChars) {
3328
3285
  if (maxChars <= 12) return value.slice(0, Math.max(0, maxChars));
3329
3286
  return `${value.slice(0, maxChars - 12)}...[truncated]`;
3330
3287
  }
3331
- function truncateStringTail(value, maxChars) {
3332
- if (value.length <= maxChars) return value;
3333
- if (maxChars <= 12) return value.slice(value.length - Math.max(0, maxChars));
3334
- return `...[truncated]${value.slice(value.length - (maxChars - 12))}`;
3335
- }
3336
3288
  function trimStructuredStrings(value, maxChars) {
3337
3289
  if (typeof value === "string") return truncateString(value, maxChars);
3338
3290
  if (Array.isArray(value)) return value.map((item) => trimStructuredStrings(item, maxChars));
@@ -3400,11 +3352,10 @@ function normalizeActiveChatData(activeChat) {
3400
3352
  (button) => truncateString(String(button || ""), STATUS_MODAL_BUTTON_LIMIT)
3401
3353
  )
3402
3354
  } : activeChat.activeModal,
3403
- terminalHistory: activeChat.terminalHistory ? truncateStringTail(activeChat.terminalHistory, STATUS_TERMINAL_HISTORY_LIMIT) : activeChat.terminalHistory,
3404
3355
  inputContent: activeChat.inputContent ? truncateString(activeChat.inputContent, STATUS_INPUT_CONTENT_LIMIT) : activeChat.inputContent
3405
3356
  };
3406
3357
  }
3407
- var WORKING_STATUSES, STATUS_ACTIVE_CHAT_MESSAGE_LIMIT, STATUS_ACTIVE_CHAT_TOTAL_BYTES_LIMIT, STATUS_ACTIVE_CHAT_STRING_LIMIT, STATUS_ACTIVE_CHAT_FALLBACK_STRING_LIMIT, STATUS_TERMINAL_HISTORY_LIMIT, STATUS_INPUT_CONTENT_LIMIT, STATUS_MODAL_MESSAGE_LIMIT, STATUS_MODAL_BUTTON_LIMIT;
3358
+ var WORKING_STATUSES, STATUS_ACTIVE_CHAT_MESSAGE_LIMIT, STATUS_ACTIVE_CHAT_TOTAL_BYTES_LIMIT, STATUS_ACTIVE_CHAT_STRING_LIMIT, STATUS_ACTIVE_CHAT_FALLBACK_STRING_LIMIT, STATUS_INPUT_CONTENT_LIMIT, STATUS_MODAL_MESSAGE_LIMIT, STATUS_MODAL_BUTTON_LIMIT;
3408
3359
  var init_normalize = __esm({
3409
3360
  "../../oss/packages/daemon-core/src/status/normalize.ts"() {
3410
3361
  "use strict";
@@ -3420,7 +3371,6 @@ var init_normalize = __esm({
3420
3371
  STATUS_ACTIVE_CHAT_TOTAL_BYTES_LIMIT = 96 * 1024;
3421
3372
  STATUS_ACTIVE_CHAT_STRING_LIMIT = 4 * 1024;
3422
3373
  STATUS_ACTIVE_CHAT_FALLBACK_STRING_LIMIT = 1024;
3423
- STATUS_TERMINAL_HISTORY_LIMIT = 8 * 1024;
3424
3374
  STATUS_INPUT_CONTENT_LIMIT = 2 * 1024;
3425
3375
  STATUS_MODAL_MESSAGE_LIMIT = 2 * 1024;
3426
3376
  STATUS_MODAL_BUTTON_LIMIT = 120;
@@ -8891,6 +8841,9 @@ var init_ghostty_vt_backend = __esm({
8891
8841
  getText() {
8892
8842
  return this.terminal.formatPlainText({ trim: true }) || "";
8893
8843
  }
8844
+ getCursorPosition() {
8845
+ return this.terminal.getCursorPosition();
8846
+ }
8894
8847
  dispose() {
8895
8848
  this.terminal.dispose();
8896
8849
  }
@@ -18043,6 +17996,13 @@ var init_xterm_backend = __esm({
18043
17996
  while (last > first && !lines[last - 1]?.trim()) last--;
18044
17997
  return lines.slice(first, last).join("\n");
18045
17998
  }
17999
+ getCursorPosition() {
18000
+ const buffer = this.terminal.buffer.active;
18001
+ return {
18002
+ col: Math.max(0, buffer.cursorX || 0),
18003
+ row: Math.max(0, buffer.cursorY || 0)
18004
+ };
18005
+ }
18046
18006
  dispose() {
18047
18007
  this.terminal.dispose();
18048
18008
  }
@@ -18129,6 +18089,9 @@ var init_terminal_screen = __esm({
18129
18089
  getText() {
18130
18090
  return this.terminal.getText();
18131
18091
  }
18092
+ getCursorPosition() {
18093
+ return this.terminal.getCursorPosition();
18094
+ }
18132
18095
  dispose() {
18133
18096
  this.terminal.dispose();
18134
18097
  }
@@ -18294,6 +18257,27 @@ var init_snapshot = __esm({
18294
18257
  }
18295
18258
  });
18296
18259
 
18260
+ // ../../oss/packages/daemon-core/src/commands/upgrade-helper.ts
18261
+ function spawnDetachedDaemonUpgradeHelper(payload) {
18262
+ const env = { ...process.env, [UPGRADE_HELPER_ENV]: JSON.stringify(payload) };
18263
+ const child = (0, import_child_process5.spawn)(process.execPath, process.argv.slice(1), {
18264
+ detached: true,
18265
+ stdio: "ignore",
18266
+ windowsHide: true,
18267
+ cwd: payload.cwd || process.cwd(),
18268
+ env
18269
+ });
18270
+ child.unref();
18271
+ }
18272
+ var import_child_process5, UPGRADE_HELPER_ENV;
18273
+ var init_upgrade_helper = __esm({
18274
+ "../../oss/packages/daemon-core/src/commands/upgrade-helper.ts"() {
18275
+ "use strict";
18276
+ import_child_process5 = require("child_process");
18277
+ UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
18278
+ }
18279
+ });
18280
+
18297
18281
  // ../../oss/packages/daemon-core/src/commands/router.ts
18298
18282
  var fs8, CHAT_COMMANDS, READ_DEBUG_ENABLED2, DaemonCommandRouter;
18299
18283
  var init_router = __esm({
@@ -18311,6 +18295,7 @@ var init_router = __esm({
18311
18295
  init_logger();
18312
18296
  init_builders();
18313
18297
  init_snapshot();
18298
+ init_upgrade_helper();
18314
18299
  fs8 = __toESM(require("fs"));
18315
18300
  CHAT_COMMANDS = [
18316
18301
  "send_chat",
@@ -18531,31 +18516,35 @@ var init_router = __esm({
18531
18516
  const pkgName = isStandalone ? "@adhdev/daemon-standalone" : "adhdev";
18532
18517
  const latest = execSync6(`npm view ${pkgName} version`, { encoding: "utf-8", timeout: 1e4 }).trim();
18533
18518
  LOG.info("Upgrade", `Latest ${pkgName}: v${latest}`);
18534
- execSync6(`npm install -g ${pkgName}@latest --force`, {
18535
- encoding: "utf-8",
18536
- timeout: 12e4,
18537
- stdio: ["pipe", "pipe", "pipe"]
18519
+ let currentInstalled = null;
18520
+ try {
18521
+ const currentJson = execSync6(`npm ls -g ${pkgName} --depth=0 --json`, {
18522
+ encoding: "utf-8",
18523
+ timeout: 1e4,
18524
+ stdio: ["pipe", "pipe", "pipe"]
18525
+ }).trim();
18526
+ const parsed = JSON.parse(currentJson);
18527
+ currentInstalled = parsed?.dependencies?.[pkgName]?.version || null;
18528
+ } catch {
18529
+ }
18530
+ if (currentInstalled === latest) {
18531
+ LOG.info("Upgrade", `Already on latest version v${latest}; skipping install`);
18532
+ return { success: true, upgraded: false, alreadyLatest: true, version: latest };
18533
+ }
18534
+ spawnDetachedDaemonUpgradeHelper({
18535
+ packageName: pkgName,
18536
+ targetVersion: latest,
18537
+ parentPid: process.pid,
18538
+ restartArgv: process.argv.slice(1),
18539
+ cwd: process.cwd(),
18540
+ sessionHostAppName: process.env.ADHDEV_SESSION_HOST_NAME || "adhdev"
18538
18541
  });
18539
- LOG.info("Upgrade", `\u2705 Upgraded to v${latest}`);
18542
+ LOG.info("Upgrade", `Scheduled detached upgrade to v${latest}`);
18540
18543
  setTimeout(() => {
18541
- LOG.info("Upgrade", "Restarting daemon with new version...");
18542
- try {
18543
- const path18 = require("path");
18544
- const fs16 = require("fs");
18545
- const pidFile = path18.join(process.env.HOME || process.env.USERPROFILE || "", ".adhdev", "daemon.pid");
18546
- if (fs16.existsSync(pidFile)) fs16.unlinkSync(pidFile);
18547
- } catch {
18548
- }
18549
- const { spawn: spawn4 } = require("child_process");
18550
- const child = spawn4(process.execPath, process.argv.slice(1), {
18551
- detached: true,
18552
- stdio: "ignore",
18553
- env: { ...process.env }
18554
- });
18555
- child.unref();
18544
+ LOG.info("Upgrade", "Exiting daemon so detached upgrader can continue...");
18556
18545
  process.exit(0);
18557
18546
  }, 3e3);
18558
- return { success: true, upgraded: true, version: latest };
18547
+ return { success: true, upgraded: true, version: latest, restarting: true };
18559
18548
  } catch (e) {
18560
18549
  LOG.error("Upgrade", `Failed: ${e.message}`);
18561
18550
  return { success: false, error: e.message };
@@ -18873,6 +18862,7 @@ var init_pty_transport = __esm({
18873
18862
  this.handle = handle;
18874
18863
  }
18875
18864
  ready = Promise.resolve();
18865
+ terminalQueriesHandled = false;
18876
18866
  get pid() {
18877
18867
  return this.handle.pid;
18878
18868
  }
@@ -18926,11 +18916,37 @@ function stripTerminalNoise(str) {
18926
18916
  function sanitizeTerminalText(str) {
18927
18917
  return stripTerminalNoise(stripAnsi(str));
18928
18918
  }
18919
+ function buildCliSpawnEnv(baseEnv, overrides) {
18920
+ const env = {};
18921
+ const source = { ...baseEnv, ...overrides || {} };
18922
+ for (const [key, value] of Object.entries(source)) {
18923
+ if (typeof value !== "string") continue;
18924
+ env[key] = value;
18925
+ }
18926
+ for (const key of Object.keys(env)) {
18927
+ 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_")) {
18928
+ delete env[key];
18929
+ }
18930
+ }
18931
+ return env;
18932
+ }
18933
+ function computeTerminalQueryTail(buffer) {
18934
+ const prefixes = ["\x1B[6n", "\x1B[?6n"];
18935
+ const maxLength = prefixes.reduce((n, value) => Math.max(n, value.length), 0) - 1;
18936
+ const start = Math.max(0, buffer.length - maxLength);
18937
+ for (let i = start; i < buffer.length; i++) {
18938
+ const suffix = buffer.slice(i);
18939
+ if (prefixes.some((pattern) => suffix.length < pattern.length && pattern.startsWith(suffix))) {
18940
+ return suffix;
18941
+ }
18942
+ }
18943
+ return "";
18944
+ }
18929
18945
  function findBinary(name) {
18930
18946
  const isWin = os13.platform() === "win32";
18931
18947
  try {
18932
18948
  const cmd = isWin ? `where ${name}` : `which ${name}`;
18933
- return (0, import_child_process5.execSync)(cmd, { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }).trim().split("\n")[0].trim();
18949
+ return (0, import_child_process6.execSync)(cmd, { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }).trim().split("\n")[0].trim();
18934
18950
  } catch {
18935
18951
  return isWin ? `${name}.cmd` : name;
18936
18952
  }
@@ -19012,36 +19028,6 @@ function promptLikelyVisible(screenText, promptSnippet) {
19012
19028
  ).length;
19013
19029
  return matched >= required2;
19014
19030
  }
19015
- function splitHistoryLines(text) {
19016
- return String(text || "").split("\n").map((line) => line.replace(/\s+$/, ""));
19017
- }
19018
- function normalizeHistoryLine(line) {
19019
- return String(line || "").replace(/\s+/g, " ").trim();
19020
- }
19021
- function mergeTerminalHistory(existing, snapshot) {
19022
- const next = String(snapshot || "").trim();
19023
- if (!next) return existing;
19024
- const prev = String(existing || "").trim();
19025
- if (!prev) return next;
19026
- if (prev === next || prev.endsWith(next)) return prev;
19027
- const prevLines = splitHistoryLines(prev);
19028
- const nextLines = splitHistoryLines(next);
19029
- const prevNorm = prevLines.map(normalizeHistoryLine);
19030
- const nextNorm = nextLines.map(normalizeHistoryLine);
19031
- const maxOverlap = Math.min(prevLines.length, nextLines.length);
19032
- for (let overlap = maxOverlap; overlap >= 1; overlap -= 1) {
19033
- const prevTail = prevNorm.slice(prevNorm.length - overlap);
19034
- const nextHead = nextNorm.slice(0, overlap);
19035
- if (prevTail.every((line, index) => line === nextHead[index])) {
19036
- return [...prevLines, ...nextLines.slice(overlap)].join("\n").trim();
19037
- }
19038
- }
19039
- const compactPrev = prevNorm.join("\n");
19040
- const compactNext = nextNorm.join("\n");
19041
- if (compactPrev.includes(compactNext)) return prev;
19042
- return `${prev}
19043
- ${next}`.trim();
19044
- }
19045
19031
  function parsePatternEntry(x) {
19046
19032
  if (x instanceof RegExp) return x;
19047
19033
  if (x && typeof x === "object" && typeof x.source === "string") {
@@ -19066,13 +19052,13 @@ function normalizeCliProviderForRuntime(raw) {
19066
19052
  }
19067
19053
  };
19068
19054
  }
19069
- var os13, path9, import_child_process5, pty2, ProviderCliAdapter;
19055
+ var os13, path9, import_child_process6, pty2, ProviderCliAdapter;
19070
19056
  var init_provider_cli_adapter = __esm({
19071
19057
  "../../oss/packages/daemon-core/src/cli-adapters/provider-cli-adapter.ts"() {
19072
19058
  "use strict";
19073
19059
  os13 = __toESM(require("os"));
19074
19060
  path9 = __toESM(require("path"));
19075
- import_child_process5 = require("child_process");
19061
+ import_child_process6 = require("child_process");
19076
19062
  init_logger();
19077
19063
  init_terminal_screen();
19078
19064
  init_pty_transport();
@@ -19156,6 +19142,7 @@ var init_provider_cli_adapter = __esm({
19156
19142
  pendingOutputParseTimer = null;
19157
19143
  ptyOutputBuffer = "";
19158
19144
  ptyOutputFlushTimer = null;
19145
+ pendingTerminalQueryTail = "";
19159
19146
  // Server log forwarding
19160
19147
  serverConn = null;
19161
19148
  logBuffer = [];
@@ -19187,9 +19174,7 @@ var init_provider_cli_adapter = __esm({
19187
19174
  /** Full accumulated raw PTY output (with ANSI) */
19188
19175
  accumulatedRawBuffer = "";
19189
19176
  /** Current visible terminal screen snapshot */
19190
- terminalScreen = new TerminalScreen(40, 120);
19191
- /** Rolling append-only terminal transcript built from screen snapshots */
19192
- terminalHistory = "";
19177
+ terminalScreen = new TerminalScreen(30, 100);
19193
19178
  /** Max accumulated buffer size (last 50KB) */
19194
19179
  static MAX_ACCUMULATED_BUFFER = 5e4;
19195
19180
  currentTurnScope = null;
@@ -19211,15 +19196,13 @@ var init_provider_cli_adapter = __esm({
19211
19196
  return text.slice(start);
19212
19197
  }
19213
19198
  buildParseInput(baseMessages, partialResponse, scope) {
19214
- const buffer = scope ? this.sliceFromOffset(this.terminalHistory, scope.terminalHistoryStart) || this.sliceFromOffset(this.accumulatedBuffer, scope.bufferStart) || this.accumulatedBuffer : this.accumulatedBuffer;
19199
+ const buffer = scope ? this.sliceFromOffset(this.accumulatedBuffer, scope.bufferStart) || this.accumulatedBuffer : this.accumulatedBuffer;
19215
19200
  const rawBuffer = scope ? this.sliceFromOffset(this.accumulatedRawBuffer, scope.rawBufferStart) || this.accumulatedRawBuffer : this.accumulatedRawBuffer;
19216
- const terminalHistory = scope ? this.sliceFromOffset(this.terminalHistory, scope.terminalHistoryStart) || this.terminalHistory : this.terminalHistory;
19217
19201
  return {
19218
19202
  buffer,
19219
19203
  rawBuffer,
19220
19204
  recentBuffer: buffer.slice(-1e3) || this.recentOutputBuffer,
19221
19205
  screenText: this.terminalScreen.getText(),
19222
- terminalHistory,
19223
19206
  messages: [...baseMessages],
19224
19207
  partialResponse
19225
19208
  };
@@ -19297,13 +19280,10 @@ var init_provider_cli_adapter = __esm({
19297
19280
  shellArgs = allArgs;
19298
19281
  }
19299
19282
  const ptyOpts = {
19300
- cols: 120,
19301
- rows: 40,
19283
+ cols: 100,
19284
+ rows: 30,
19302
19285
  cwd: this.workingDir,
19303
- env: {
19304
- ...process.env,
19305
- ...spawnConfig.env
19306
- }
19286
+ env: buildCliSpawnEnv(process.env, spawnConfig.env)
19307
19287
  };
19308
19288
  try {
19309
19289
  this.ptyProcess = this.transportFactory.spawn(shellCmd, shellArgs, ptyOpts);
@@ -19321,8 +19301,8 @@ var init_provider_cli_adapter = __esm({
19321
19301
  }
19322
19302
  this.ptyProcess.onData((data) => {
19323
19303
  if (Date.now() < this.resizeSuppressUntil) return;
19324
- if (data.includes("\x1B[6n") || data.includes("\x1B[?6n")) {
19325
- this.ptyProcess?.write("\x1B[1;1R");
19304
+ if (!this.ptyProcess?.terminalQueriesHandled) {
19305
+ this.respondToTerminalQueries(data);
19326
19306
  }
19327
19307
  this.pendingOutputParseBuffer += data;
19328
19308
  if (!this.pendingOutputParseTimer) {
@@ -19357,8 +19337,8 @@ var init_provider_cli_adapter = __esm({
19357
19337
  this.spawnAt = Date.now();
19358
19338
  this.startupParseGate = true;
19359
19339
  this.startupBuffer = "";
19360
- this.terminalScreen.reset(40, 120);
19361
- this.terminalHistory = "";
19340
+ this.terminalScreen.reset(30, 100);
19341
+ this.pendingTerminalQueryTail = "";
19362
19342
  this.currentTurnScope = null;
19363
19343
  this.ready = false;
19364
19344
  await this.ptyProcess.ready;
@@ -19368,7 +19348,6 @@ var init_provider_cli_adapter = __esm({
19368
19348
  // ─── Output Handling ────────────────────────────
19369
19349
  handleOutput(rawData) {
19370
19350
  this.terminalScreen.write(rawData);
19371
- this.terminalHistory = mergeTerminalHistory(this.terminalHistory, this.terminalScreen.getText());
19372
19351
  const cleanData = sanitizeTerminalText(rawData);
19373
19352
  if (this.isWaitingForResponse && cleanData) {
19374
19353
  this.responseBuffer = (this.responseBuffer + cleanData).slice(-8e3);
@@ -19644,8 +19623,7 @@ var init_provider_cli_adapter = __esm({
19644
19623
  status: this.currentStatus,
19645
19624
  messages: [...this.committedMessages],
19646
19625
  workingDir: this.workingDir,
19647
- activeModal: this.activeModal,
19648
- terminalHistory: this.terminalHistory
19626
+ activeModal: this.activeModal
19649
19627
  };
19650
19628
  }
19651
19629
  /**
@@ -19663,7 +19641,6 @@ var init_provider_cli_adapter = __esm({
19663
19641
  id: parsed.id || "cli_session",
19664
19642
  status: parsed.status || this.currentStatus,
19665
19643
  title: parsed.title || this.cliName,
19666
- terminalHistory: this.terminalHistory,
19667
19644
  messages: parsed.messages,
19668
19645
  activeModal: parsed.activeModal ?? this.activeModal
19669
19646
  };
@@ -19673,7 +19650,6 @@ var init_provider_cli_adapter = __esm({
19673
19650
  id: "cli_session",
19674
19651
  status: this.currentStatus,
19675
19652
  title: this.cliName,
19676
- terminalHistory: this.terminalHistory,
19677
19653
  messages: messages.slice(-50).map((message, index) => ({
19678
19654
  id: `msg_${index}`,
19679
19655
  role: message.role,
@@ -19741,10 +19717,9 @@ ${data.message || ""}`.trim();
19741
19717
  prompt: text,
19742
19718
  startedAt: Date.now(),
19743
19719
  bufferStart: this.accumulatedBuffer.length,
19744
- rawBufferStart: this.accumulatedRawBuffer.length,
19745
- terminalHistoryStart: this.terminalHistory.length
19720
+ rawBufferStart: this.accumulatedRawBuffer.length
19746
19721
  };
19747
- LOG.info("CLI", `[${this.cliType}] sendMessage turn scope buffer=${this.currentTurnScope.bufferStart} raw=${this.currentTurnScope.rawBufferStart} terminal=${this.currentTurnScope.terminalHistoryStart} prompt=${JSON.stringify(text).slice(0, 120)}`);
19722
+ LOG.info("CLI", `[${this.cliType}] sendMessage turn scope buffer=${this.currentTurnScope.bufferStart} raw=${this.currentTurnScope.rawBufferStart} prompt=${JSON.stringify(text).slice(0, 120)}`);
19748
19723
  this.submitRetryUsed = false;
19749
19724
  this.submitRetryPromptSnippet = extractPromptRetrySnippet(text);
19750
19725
  const normalizedPromptSnippet = normalizePromptText(this.submitRetryPromptSnippet);
@@ -19929,6 +19904,7 @@ ${data.message || ""}`.trim();
19929
19904
  this.pendingOutputParseTimer = null;
19930
19905
  }
19931
19906
  this.pendingOutputParseBuffer = "";
19907
+ this.pendingTerminalQueryTail = "";
19932
19908
  if (this.ptyOutputFlushTimer) {
19933
19909
  clearTimeout(this.ptyOutputFlushTimer);
19934
19910
  this.ptyOutputFlushTimer = null;
@@ -19968,6 +19944,7 @@ ${data.message || ""}`.trim();
19968
19944
  this.pendingOutputParseTimer = null;
19969
19945
  }
19970
19946
  this.pendingOutputParseBuffer = "";
19947
+ this.pendingTerminalQueryTail = "";
19971
19948
  if (this.ptyOutputFlushTimer) {
19972
19949
  clearTimeout(this.ptyOutputFlushTimer);
19973
19950
  this.ptyOutputFlushTimer = null;
@@ -19994,7 +19971,6 @@ ${data.message || ""}`.trim();
19994
19971
  this.syncMessageViews();
19995
19972
  this.accumulatedBuffer = "";
19996
19973
  this.accumulatedRawBuffer = "";
19997
- this.terminalHistory = "";
19998
19974
  this.currentTurnScope = null;
19999
19975
  this.submitRetryUsed = false;
20000
19976
  this.submitRetryPromptSnippet = "";
@@ -20003,6 +19979,7 @@ ${data.message || ""}`.trim();
20003
19979
  this.pendingOutputParseTimer = null;
20004
19980
  }
20005
19981
  this.pendingOutputParseBuffer = "";
19982
+ this.pendingTerminalQueryTail = "";
20006
19983
  if (this.ptyOutputFlushTimer) {
20007
19984
  clearTimeout(this.ptyOutputFlushTimer);
20008
19985
  this.ptyOutputFlushTimer = null;
@@ -20064,7 +20041,6 @@ ${data.message || ""}`.trim();
20064
20041
  structuredMessages: this.structuredMessages.slice(-20),
20065
20042
  messageCount: this.committedMessages.length,
20066
20043
  screenText: sanitizeTerminalText(this.terminalScreen.getText()).slice(-4e3),
20067
- terminalHistory: this.terminalHistory.slice(-8e3),
20068
20044
  currentTurnScope: this.currentTurnScope,
20069
20045
  startupBuffer: this.startupBuffer.slice(-4e3),
20070
20046
  recentOutputBuffer: this.recentOutputBuffer.slice(-500),
@@ -20092,6 +20068,20 @@ ${data.message || ""}`.trim();
20092
20068
  ptyAlive: !!this.ptyProcess
20093
20069
  };
20094
20070
  }
20071
+ respondToTerminalQueries(data) {
20072
+ if (!this.ptyProcess || !data) return;
20073
+ const combined = this.pendingTerminalQueryTail + data;
20074
+ const regex = /\x1b\[(\?)?6n/g;
20075
+ let match;
20076
+ while ((match = regex.exec(combined)) !== null) {
20077
+ const cursor = this.terminalScreen.getCursorPosition();
20078
+ const row = Math.max(1, (cursor.row | 0) + 1);
20079
+ const col = Math.max(1, (cursor.col | 0) + 1);
20080
+ const response = match[1] ? `\x1B[?${row};${col}R` : `\x1B[${row};${col}R`;
20081
+ this.ptyProcess.write(response);
20082
+ }
20083
+ this.pendingTerminalQueryTail = computeTerminalQueryTail(combined);
20084
+ }
20095
20085
  };
20096
20086
  }
20097
20087
  });
@@ -20113,7 +20103,7 @@ var init_cli_provider_instance = __esm({
20113
20103
  this.cliArgs = cliArgs;
20114
20104
  this.type = provider.type;
20115
20105
  this.instanceId = instanceId || crypto3.randomUUID();
20116
- this.presentationMode = "terminal";
20106
+ this.presentationMode = "chat";
20117
20107
  this.adapter = new ProviderCliAdapter(provider, workingDir, cliArgs, transportFactory);
20118
20108
  this.monitor = new StatusMonitor();
20119
20109
  this.historyWriter = new ChatHistoryWriter();
@@ -20160,14 +20150,6 @@ var init_cli_provider_instance = __esm({
20160
20150
  const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
20161
20151
  const runtime = this.adapter.getRuntimeMetadata();
20162
20152
  const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
20163
- if (adapterStatus.terminalHistory?.trim()) {
20164
- this.historyWriter.appendTerminalHistory(
20165
- this.type,
20166
- adapterStatus.terminalHistory,
20167
- `${this.provider.name} \xB7 ${dirName}`,
20168
- this.instanceId
20169
- );
20170
- }
20171
20153
  return {
20172
20154
  type: this.type,
20173
20155
  name: this.provider.name,
@@ -20180,7 +20162,6 @@ var init_cli_provider_instance = __esm({
20180
20162
  status: parsedStatus?.status || adapterStatus.status,
20181
20163
  messages: Array.isArray(parsedStatus?.messages) ? parsedStatus.messages : [],
20182
20164
  activeModal: parsedStatus?.activeModal ?? adapterStatus.activeModal,
20183
- terminalHistory: adapterStatus.terminalHistory,
20184
20165
  inputContent: ""
20185
20166
  },
20186
20167
  workspace: this.workingDir,
@@ -36665,12 +36646,12 @@ var init_contracts = __esm({
36665
36646
  });
36666
36647
 
36667
36648
  // ../../oss/packages/daemon-core/src/providers/acp-provider-instance.ts
36668
- var import_stream, import_child_process6, AcpProviderInstance;
36649
+ var import_stream, import_child_process7, AcpProviderInstance;
36669
36650
  var init_acp_provider_instance = __esm({
36670
36651
  "../../oss/packages/daemon-core/src/providers/acp-provider-instance.ts"() {
36671
36652
  "use strict";
36672
36653
  import_stream = require("stream");
36673
- import_child_process6 = require("child_process");
36654
+ import_child_process7 = require("child_process");
36674
36655
  init_acp();
36675
36656
  init_contracts();
36676
36657
  init_status_monitor();
@@ -36994,7 +36975,7 @@ var init_acp_provider_instance = __esm({
36994
36975
  this.errorMessage = null;
36995
36976
  this.errorReason = null;
36996
36977
  this.stderrBuffer = [];
36997
- this.process = (0, import_child_process6.spawn)(command, args, {
36978
+ this.process = (0, import_child_process7.spawn)(command, args, {
36998
36979
  cwd: this.workingDir,
36999
36980
  env,
37000
36981
  stdio: ["pipe", "pipe", "pipe"],
@@ -38949,7 +38930,7 @@ var init_provider_instance_manager = __esm({
38949
38930
  // ../../oss/packages/daemon-core/src/providers/version-archive.ts
38950
38931
  function runCommand(cmd, timeout = 1e4) {
38951
38932
  try {
38952
- return (0, import_child_process7.execSync)(cmd, {
38933
+ return (0, import_child_process8.execSync)(cmd, {
38953
38934
  encoding: "utf-8",
38954
38935
  timeout,
38955
38936
  stdio: ["pipe", "pipe", "pipe"]
@@ -39056,14 +39037,14 @@ async function detectAllVersions(loader, archive) {
39056
39037
  }
39057
39038
  return results;
39058
39039
  }
39059
- var fs9, path11, os15, import_child_process7, import_os3, ARCHIVE_PATH, MAX_ENTRIES_PER_PROVIDER, VersionArchive;
39040
+ var fs9, path11, os15, import_child_process8, import_os3, ARCHIVE_PATH, MAX_ENTRIES_PER_PROVIDER, VersionArchive;
39060
39041
  var init_version_archive = __esm({
39061
39042
  "../../oss/packages/daemon-core/src/providers/version-archive.ts"() {
39062
39043
  "use strict";
39063
39044
  fs9 = __toESM(require("fs"));
39064
39045
  path11 = __toESM(require("path"));
39065
39046
  os15 = __toESM(require("os"));
39066
- import_child_process7 = require("child_process");
39047
+ import_child_process8 = require("child_process");
39067
39048
  import_os3 = require("os");
39068
39049
  ARCHIVE_PATH = path11.join(os15.homedir(), ".adhdev", "version-history.json");
39069
39050
  MAX_ENTRIES_PER_PROVIDER = 20;
@@ -40842,8 +40823,8 @@ async function handleAutoImplement(ctx, type, req, res) {
40842
40823
  fs11.writeFileSync(promptFile, prompt, "utf-8");
40843
40824
  ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
40844
40825
  const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
40845
- const spawn4 = agentProvider?.spawn;
40846
- if (!spawn4?.command) {
40826
+ const spawn5 = agentProvider?.spawn;
40827
+ if (!spawn5?.command) {
40847
40828
  try {
40848
40829
  fs11.unlinkSync(promptFile);
40849
40830
  } catch {
@@ -40853,21 +40834,21 @@ async function handleAutoImplement(ctx, type, req, res) {
40853
40834
  }
40854
40835
  const agentCategory = agentProvider?.category;
40855
40836
  if (agentCategory === "acp") {
40856
- sendAutoImplSSE(ctx, { event: "progress", data: { function: "_init", status: "spawning", message: `Spawning ACP agent: ${spawn4.command} ${(spawn4.args || []).join(" ")}` } });
40837
+ sendAutoImplSSE(ctx, { event: "progress", data: { function: "_init", status: "spawning", message: `Spawning ACP agent: ${spawn5.command} ${(spawn5.args || []).join(" ")}` } });
40857
40838
  ctx.autoImplStatus = { running: true, type, progress: [] };
40858
40839
  const { ClientSideConnection: ClientSideConnection2, ndJsonStream: ndJsonStream2, PROTOCOL_VERSION: PROTOCOL_VERSION2 } = await Promise.resolve().then(() => (init_acp(), acp_exports));
40859
40840
  const { Readable: Readable3, Writable: Writable2 } = await import("stream");
40860
40841
  const { spawn: spawnFn2 } = await import("child_process");
40861
- const acpArgs = [...spawn4.args || []];
40842
+ const acpArgs = [...spawn5.args || []];
40862
40843
  if (model) {
40863
40844
  acpArgs.push("--model", model);
40864
40845
  ctx.log(`Auto-implement ACP using model: ${model}`);
40865
40846
  }
40866
- const child2 = spawnFn2(spawn4.command, acpArgs, {
40847
+ const child2 = spawnFn2(spawn5.command, acpArgs, {
40867
40848
  cwd: providerDir,
40868
40849
  stdio: ["pipe", "pipe", "pipe"],
40869
- shell: spawn4.shell ?? false,
40870
- env: { ...process.env, ...spawn4.env || {} }
40850
+ shell: spawn5.shell ?? false,
40851
+ env: { ...process.env, ...spawn5.env || {} }
40871
40852
  });
40872
40853
  ctx.autoImplProcess = child2;
40873
40854
  child2.stderr?.on("data", (d) => {
@@ -40977,7 +40958,7 @@ async function handleAutoImplement(ctx, type, req, res) {
40977
40958
  ctx.json(res, 202, {
40978
40959
  started: true,
40979
40960
  type,
40980
- agent: spawn4.command,
40961
+ agent: spawn5.command,
40981
40962
  functions,
40982
40963
  providerDir,
40983
40964
  message: "ACP Auto-implement started. Connect to SSE for progress.",
@@ -40985,9 +40966,9 @@ async function handleAutoImplement(ctx, type, req, res) {
40985
40966
  });
40986
40967
  return;
40987
40968
  }
40988
- const command = spawn4.command;
40969
+ const command = spawn5.command;
40989
40970
  const interactiveFlags = ["--yolo", "--interactive", "-i"];
40990
- const baseArgs = [...spawn4.args || []].filter((a) => !interactiveFlags.includes(a));
40971
+ const baseArgs = [...spawn5.args || []].filter((a) => !interactiveFlags.includes(a));
40991
40972
  let shellCmd;
40992
40973
  const isWin = os16.platform() === "win32";
40993
40974
  const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
@@ -41038,7 +41019,7 @@ async function handleAutoImplement(ctx, type, req, res) {
41038
41019
  cols: 120,
41039
41020
  rows: 40,
41040
41021
  cwd: providerDir,
41041
- env: { ...process.env, ...spawn4.env || {} }
41022
+ env: { ...process.env, ...spawn5.env || {} }
41042
41023
  });
41043
41024
  isPty = true;
41044
41025
  } catch (err) {
@@ -41050,7 +41031,7 @@ async function handleAutoImplement(ctx, type, req, res) {
41050
41031
  stdio: ["pipe", "pipe", "pipe"],
41051
41032
  env: {
41052
41033
  ...process.env,
41053
- ...spawn4.env || {},
41034
+ ...spawn5.env || {},
41054
41035
  ...command === "gemini" ? { SANDBOX: "1", GEMINI_CLI_NO_RELAUNCH: "1" } : {}
41055
41036
  }
41056
41037
  });
@@ -41902,16 +41883,16 @@ var init_dev_server = __esm({
41902
41883
  this.json(res, 404, { error: `Provider not found: ${type}` });
41903
41884
  return;
41904
41885
  }
41905
- const spawn4 = provider.spawn;
41906
- if (!spawn4) {
41886
+ const spawn5 = provider.spawn;
41887
+ if (!spawn5) {
41907
41888
  this.json(res, 400, { error: `Provider ${type} has no spawn config` });
41908
41889
  return;
41909
41890
  }
41910
41891
  const { spawn: spawnFn } = await import("child_process");
41911
41892
  const start = Date.now();
41912
41893
  try {
41913
- const child = spawnFn(spawn4.command, [...spawn4.args || []], {
41914
- shell: spawn4.shell ?? false,
41894
+ const child = spawnFn(spawn5.command, [...spawn5.args || []], {
41895
+ shell: spawn5.shell ?? false,
41915
41896
  timeout: 5e3,
41916
41897
  stdio: ["pipe", "pipe", "pipe"]
41917
41898
  });
@@ -41943,7 +41924,7 @@ var init_dev_server = __esm({
41943
41924
  const elapsed = Date.now() - start;
41944
41925
  this.json(res, 200, {
41945
41926
  success: true,
41946
- command: `${spawn4.command} ${(spawn4.args || []).join(" ")}`,
41927
+ command: `${spawn5.command} ${(spawn5.args || []).join(" ")}`,
41947
41928
  elapsed,
41948
41929
  stdout: stdout.trim(),
41949
41930
  stderr: stderr.trim(),
@@ -41953,7 +41934,7 @@ var init_dev_server = __esm({
41953
41934
  const elapsed = Date.now() - start;
41954
41935
  this.json(res, 200, {
41955
41936
  success: false,
41956
- command: `${spawn4.command} ${(spawn4.args || []).join(" ")}`,
41937
+ command: `${spawn5.command} ${(spawn5.args || []).join(" ")}`,
41957
41938
  elapsed,
41958
41939
  error: e.message
41959
41940
  });
@@ -42422,20 +42403,20 @@ var init_dev_server = __esm({
42422
42403
  this.json(res, 404, { error: `Provider not found: ${type}` });
42423
42404
  return;
42424
42405
  }
42425
- const spawn4 = provider.spawn;
42426
- if (!spawn4) {
42406
+ const spawn5 = provider.spawn;
42407
+ if (!spawn5) {
42427
42408
  this.json(res, 400, { error: `Provider ${type} has no spawn config` });
42428
42409
  return;
42429
42410
  }
42430
42411
  const { spawn: spawnFn } = await import("child_process");
42431
42412
  const start = Date.now();
42432
42413
  try {
42433
- const args = [...spawn4.args || [], message];
42434
- const child = spawnFn(spawn4.command, args, {
42435
- shell: spawn4.shell ?? false,
42414
+ const args = [...spawn5.args || [], message];
42415
+ const child = spawnFn(spawn5.command, args, {
42416
+ shell: spawn5.shell ?? false,
42436
42417
  timeout,
42437
42418
  stdio: ["pipe", "pipe", "pipe"],
42438
- env: { ...process.env, ...spawn4.env || {} }
42419
+ env: { ...process.env, ...spawn5.env || {} }
42439
42420
  });
42440
42421
  let stdout = "";
42441
42422
  let stderr = "";
@@ -43320,6 +43301,7 @@ var init_session_host_transport = __esm({
43320
43301
  this.ready = this.boot();
43321
43302
  }
43322
43303
  ready;
43304
+ terminalQueriesHandled = true;
43323
43305
  client;
43324
43306
  dataCallbacks = /* @__PURE__ */ new Set();
43325
43307
  exitCallbacks = /* @__PURE__ */ new Set();
@@ -43997,6 +43979,7 @@ var init_src = __esm({
43997
43979
  init_initializer();
43998
43980
  init_handler();
43999
43981
  init_router();
43982
+ init_upgrade_helper();
44000
43983
  init_reporter();
44001
43984
  init_builders();
44002
43985
  init_snapshot();
@@ -45325,7 +45308,7 @@ async function ensureSessionHostReady2() {
45325
45308
  appName: SESSION_HOST_APP_NAME,
45326
45309
  spawnHost: () => {
45327
45310
  const entry = resolveSessionHostEntry();
45328
- const child = (0, import_child_process8.spawn)(process.execPath, [entry], {
45311
+ const child = (0, import_child_process9.spawn)(process.execPath, [entry], {
45329
45312
  detached: true,
45330
45313
  stdio: "ignore",
45331
45314
  windowsHide: true,
@@ -45341,11 +45324,11 @@ async function ensureSessionHostReady2() {
45341
45324
  async function listHostedCliRuntimes2(endpoint) {
45342
45325
  return listHostedCliRuntimes(endpoint);
45343
45326
  }
45344
- var import_child_process8, fs14, path16, SESSION_HOST_APP_NAME;
45327
+ var import_child_process9, fs14, path16, SESSION_HOST_APP_NAME;
45345
45328
  var init_session_host = __esm({
45346
45329
  "src/session-host.ts"() {
45347
45330
  "use strict";
45348
- import_child_process8 = require("child_process");
45331
+ import_child_process9 = require("child_process");
45349
45332
  fs14 = __toESM(require("fs"));
45350
45333
  path16 = __toESM(require("path"));
45351
45334
  init_src();
@@ -45413,7 +45396,7 @@ var init_adhdev_daemon = __esm({
45413
45396
  fs15 = __toESM(require("fs"));
45414
45397
  path17 = __toESM(require("path"));
45415
45398
  import_chalk2 = __toESM(require("chalk"));
45416
- pkgVersion = "0.7.42";
45399
+ pkgVersion = "0.7.44";
45417
45400
  if (pkgVersion === "unknown") {
45418
45401
  try {
45419
45402
  const possiblePaths = [