@adhdev/daemon-core 0.9.82-rc.135 → 0.9.82-rc.136

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.mjs CHANGED
@@ -4514,6 +4514,8 @@ function buildCliParseInput(options) {
4514
4514
  recentOutputBuffer,
4515
4515
  terminalScreenText,
4516
4516
  workingDir,
4517
+ providerSessionId,
4518
+ historySessionId,
4517
4519
  baseMessages,
4518
4520
  partialResponse,
4519
4521
  isWaitingForResponse,
@@ -4531,6 +4533,8 @@ function buildCliParseInput(options) {
4531
4533
  screenText,
4532
4534
  workspace: workingDir,
4533
4535
  workingDir,
4536
+ providerSessionId,
4537
+ historySessionId,
4534
4538
  screen: buildCliScreenSnapshot(screenText),
4535
4539
  bufferScreen: buildCliScreenSnapshot(buffer),
4536
4540
  recentScreen: buildCliScreenSnapshot(recentBuffer),
@@ -6085,6 +6089,8 @@ ${lastSnapshot}`;
6085
6089
  recentOutputBuffer: this.recentOutputBuffer,
6086
6090
  terminalScreenText: parseScreenText,
6087
6091
  workingDir: this.workingDir,
6092
+ providerSessionId: this.providerSessionId || void 0,
6093
+ historySessionId: this.providerSessionId || void 0,
6088
6094
  baseMessages: [],
6089
6095
  partialResponse: this.responseBuffer,
6090
6096
  isWaitingForResponse: this.isWaitingForResponse,
@@ -6309,6 +6315,8 @@ ${lastSnapshot}`;
6309
6315
  recentOutputBuffer: this.recentOutputBuffer,
6310
6316
  terminalScreenText: this.getParseScreenText(this.terminalScreen.getText()),
6311
6317
  workingDir: this.workingDir,
6318
+ providerSessionId: this.providerSessionId || void 0,
6319
+ historySessionId: this.providerSessionId || void 0,
6312
6320
  baseMessages: [],
6313
6321
  partialResponse: this.responseBuffer,
6314
6322
  isWaitingForResponse: this.isWaitingForResponse,
@@ -6866,6 +6874,10 @@ ${lastSnapshot}`;
6866
6874
  return this.ptyProcess.getMetadata();
6867
6875
  }
6868
6876
  updateRuntimeMeta(meta, replace = false) {
6877
+ const nextProviderSessionId = typeof meta?.providerSessionId === "string" ? meta.providerSessionId.trim() : "";
6878
+ if (nextProviderSessionId) {
6879
+ this.providerSessionId = nextProviderSessionId;
6880
+ }
6869
6881
  if (!this.ptyProcess || typeof this.ptyProcess.updateMeta !== "function") return;
6870
6882
  this.ptyProcess.updateMeta(meta, replace);
6871
6883
  }
@@ -7033,6 +7045,9 @@ ${lastSnapshot}`;
7033
7045
  await this.writeToPty(data);
7034
7046
  }
7035
7047
  resolveModal(buttonIndex) {
7048
+ if (this.lastApprovalResolvedAt && Date.now() - this.lastApprovalResolvedAt < this.timeouts.approvalCooldown) {
7049
+ return;
7050
+ }
7036
7051
  let modal = this.activeModal || this.runParseApproval(this.recentOutputBuffer);
7037
7052
  if (!modal && typeof this.cliScripts?.parseSession === "function") {
7038
7053
  try {
@@ -7074,6 +7089,10 @@ ${lastSnapshot}`;
7074
7089
  this.ptyProcess.write(keys);
7075
7090
  }
7076
7091
  }
7092
+ /** Returns true if an approval was resolved within the adapter's cooldown window. */
7093
+ isApprovalRecentlyResolved() {
7094
+ return !!(this.lastApprovalResolvedAt && Date.now() - this.lastApprovalResolvedAt < this.timeouts.approvalCooldown);
7095
+ }
7077
7096
  resize(cols, rows) {
7078
7097
  if (this.ptyProcess) {
7079
7098
  try {
@@ -14834,6 +14853,19 @@ function formatAutoApprovalMessage(modalMessage, buttonLabel) {
14834
14853
  if (cleanMessage) lines.push(cleanMessage);
14835
14854
  return lines.join("\n");
14836
14855
  }
14856
+ function looksLikeActiveApprovalPromptText(content) {
14857
+ const text = content.trim();
14858
+ if (!text || text.length > 2e3) return false;
14859
+ const hasApprovalQuestion = /do you want to (?:proceed|allow|run|make this edit|create)/i.test(text) || /this command requires approval/i.test(text) || /quick safety check/i.test(text) || /is this a project you trust/i.test(text);
14860
+ const hasNumberedChoices = /^\s*[❯›>]?\s*1[.)]\s+(?:yes|allow|proceed|run)/im.test(text) || /^\s*1[.)]\s+yes\b/im.test(text);
14861
+ if (hasApprovalQuestion && hasNumberedChoices) return true;
14862
+ const lastLines = text.split(/\r?\n/).slice(-12).join("\n");
14863
+ const hasDontAskAgain = /yes.*don'?t ask again/i.test(lastLines) || /yes.*always allow/i.test(lastLines);
14864
+ const hasNoOption = /^\s*[❯›>]?\s*\d+[.)]\s+no\b/im.test(lastLines);
14865
+ if (hasDontAskAgain && hasNoOption) return true;
14866
+ if (/what do you want to do\?/i.test(text) && /^\s*\d+[.)]\s+\S/m.test(text)) return true;
14867
+ return false;
14868
+ }
14837
14869
 
14838
14870
  // src/providers/ide-provider-instance.ts
14839
14871
  async function withTimeout(promise, timeoutMs, label) {
@@ -18843,6 +18875,10 @@ async function handleResolveAction(h, args) {
18843
18875
  if (buttonIndex < 0) {
18844
18876
  return { success: false, error: "Approval action did not match any visible button" };
18845
18877
  }
18878
+ if (typeof adapter.isApprovalRecentlyResolved === "function" && adapter.isApprovalRecentlyResolved()) {
18879
+ LOG.info("Command", `[resolveAction] CLI PTY \u2192 stale_prompt (already resolved within cooldown)`);
18880
+ return { success: true, stalePrompt: true, buttonIndex, button: buttons[buttonIndex] ?? button };
18881
+ }
18846
18882
  if (typeof adapter.resolveModal === "function") {
18847
18883
  adapter.resolveModal(buttonIndex);
18848
18884
  } else {
@@ -20647,6 +20683,9 @@ var CliProviderInstance = class {
20647
20683
  this.launchMode = options?.launchMode || "new";
20648
20684
  this.onProviderSessionResolved = options?.onProviderSessionResolved;
20649
20685
  this.adapter = new ProviderCliAdapter(provider, workingDir, cliArgs, options?.extraEnv || {}, transportFactory);
20686
+ if (this.providerSessionId) {
20687
+ this.adapter.updateRuntimeMeta({ providerSessionId: this.providerSessionId });
20688
+ }
20650
20689
  this.monitor = new StatusMonitor();
20651
20690
  this.historyWriter = new ChatHistoryWriter();
20652
20691
  }
@@ -21040,7 +21079,9 @@ var CliProviderInstance = class {
21040
21079
  const lastVisible = visibleMessages[visibleMessages.length - 1];
21041
21080
  const role = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : "";
21042
21081
  const content = lastVisible ? flattenContent(lastVisible.content).trim() : "";
21043
- return role === "assistant" && !!content;
21082
+ if (role !== "assistant" || !content) return false;
21083
+ if (looksLikeActiveApprovalPromptText(content)) return false;
21084
+ return true;
21044
21085
  }
21045
21086
  buildCompletedFinalizationDiagnostic(args) {
21046
21087
  let parsed = null;
@@ -21128,6 +21169,16 @@ var CliProviderInstance = class {
21128
21169
  }
21129
21170
  if (parsed?.activeModal || parsed?.modal) return { reason: "parsed_modal_active", terminal: true };
21130
21171
  if (!this.completionHasFinalAssistantMessage(parsed?.messages)) return { reason: "missing_final_assistant" };
21172
+ try {
21173
+ const screenText = typeof this.adapter.getScreenText === "function" ? String(this.adapter.getScreenText() || "") : "";
21174
+ if (screenText) {
21175
+ const tailLines = screenText.split(/\r?\n/).slice(-16).join("\n");
21176
+ if (looksLikeActiveApprovalPromptText(tailLines)) {
21177
+ return { reason: "screen_shows_approval_prompt", terminal: false };
21178
+ }
21179
+ }
21180
+ } catch {
21181
+ }
21131
21182
  return null;
21132
21183
  }
21133
21184
  scheduleCompletedDebounceFlush(delayMs) {
@@ -23439,7 +23490,9 @@ var DaemonCliManager = class {
23439
23490
  providerSessionId,
23440
23491
  attachExisting
23441
23492
  );
23442
- return new ProviderCliAdapter(resolvedProvider, workingDir, cliArgs, extraEnv || {}, transportFactory);
23493
+ const adapter = new ProviderCliAdapter(resolvedProvider, workingDir, cliArgs, extraEnv || {}, transportFactory);
23494
+ if (providerSessionId) adapter.updateRuntimeMeta({ providerSessionId });
23495
+ return adapter;
23443
23496
  }
23444
23497
  throw new Error(`No CLI provider found for '${cliType}'. Create a provider.js in providers/cli/${cliType}/`);
23445
23498
  }