adhdev 0.8.20 → 0.8.22

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/index.js CHANGED
@@ -4184,6 +4184,24 @@ function isRecentDuplicateSend(key) {
4184
4184
  recentSendByTarget.set(key, now);
4185
4185
  return false;
4186
4186
  }
4187
+ function parseMaybeJson(value) {
4188
+ if (typeof value !== "string") return value;
4189
+ try {
4190
+ return JSON.parse(value);
4191
+ } catch {
4192
+ return value;
4193
+ }
4194
+ }
4195
+ function didProviderConfirmSend(result) {
4196
+ const parsed = parseMaybeJson(result);
4197
+ if (parsed === true) return true;
4198
+ if (typeof parsed === "string") {
4199
+ const normalized = parsed.trim().toLowerCase();
4200
+ return normalized === "ok" || normalized === "sent" || normalized === "success" || normalized === "true";
4201
+ }
4202
+ if (!parsed || typeof parsed !== "object") return false;
4203
+ return parsed.sent === true || parsed.success === true || parsed.ok === true || parsed.submitted === true || parsed.dispatched === true;
4204
+ }
4187
4205
  async function handleChatHistory(h, args) {
4188
4206
  const { agentType, offset, limit } = args;
4189
4207
  const historySessionId = getHistorySessionId(h, args);
@@ -4366,14 +4384,8 @@ async function handleSendChat(h, args) {
4366
4384
  try {
4367
4385
  const evalResult = await h.evaluateProviderScript("sendMessage", { MESSAGE: text }, 3e4);
4368
4386
  if (evalResult?.result) {
4369
- let parsed = evalResult.result;
4370
- if (typeof parsed === "string") {
4371
- try {
4372
- parsed = JSON.parse(parsed);
4373
- } catch {
4374
- }
4375
- }
4376
- if (parsed?.sent) {
4387
+ const parsed = parseMaybeJson(evalResult.result);
4388
+ if (didProviderConfirmSend(parsed)) {
4377
4389
  _log(`Extension script sent OK`);
4378
4390
  return _logSendSuccess("extension-script");
4379
4391
  }
@@ -4405,14 +4417,8 @@ async function handleSendChat(h, args) {
4405
4417
  if (sendScript) {
4406
4418
  try {
4407
4419
  const result = await targetCdp.evaluate(sendScript, 3e4);
4408
- let parsed = result;
4409
- if (typeof result === "string") {
4410
- try {
4411
- parsed = JSON.parse(result);
4412
- } catch {
4413
- }
4414
- }
4415
- if (parsed?.sent) {
4420
+ const parsed = parseMaybeJson(result);
4421
+ if (didProviderConfirmSend(parsed)) {
4416
4422
  _log(`sendMessage script OK`);
4417
4423
  return _logSendSuccess("script");
4418
4424
  }
@@ -4457,14 +4463,8 @@ async function handleSendChat(h, args) {
4457
4463
  const matchText = provider.webviewMatchText;
4458
4464
  const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
4459
4465
  const wvResult = await targetCdp.evaluateInWebviewFrame(webviewScript, matchFn);
4460
- let wvParsed = wvResult;
4461
- if (typeof wvResult === "string") {
4462
- try {
4463
- wvParsed = JSON.parse(wvResult);
4464
- } catch {
4465
- }
4466
- }
4467
- if (wvParsed?.sent) {
4466
+ const wvParsed = parseMaybeJson(wvResult);
4467
+ if (didProviderConfirmSend(wvParsed)) {
4468
4468
  _log(`webviewSendMessage OK`);
4469
4469
  return _logSendSuccess("webview-script");
4470
4470
  }
@@ -4486,14 +4486,8 @@ async function handleSendChat(h, args) {
4486
4486
  const matchText = provider.webviewMatchText;
4487
4487
  const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
4488
4488
  const wvResult = await targetCdp.evaluateInWebviewFrame(webviewScript, matchFn);
4489
- let wvParsed = wvResult;
4490
- if (typeof wvResult === "string") {
4491
- try {
4492
- wvParsed = JSON.parse(wvResult);
4493
- } catch {
4494
- }
4495
- }
4496
- if (wvParsed?.sent) {
4489
+ const wvParsed = parseMaybeJson(wvResult);
4490
+ if (didProviderConfirmSend(wvParsed)) {
4497
4491
  _log(`webviewSendMessage OK`);
4498
4492
  return _logSendSuccess("webview-script");
4499
4493
  }
@@ -7185,7 +7179,7 @@ var init_provider_cli_adapter = __esm({
7185
7179
  let shellArgs;
7186
7180
  const useShellUnix = !isWin && (!!spawnConfig.shell || !path7.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
7187
7181
  const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
7188
- const useShellWin = isCmdShim || !path7.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
7182
+ const useShellWin = !!spawnConfig.shell || isCmdShim || !path7.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
7189
7183
  const useShell = isWin ? useShellWin : useShellUnix;
7190
7184
  if (useShell) {
7191
7185
  if (!spawnConfig.shell && !isWin) {
@@ -7396,6 +7390,40 @@ var init_provider_cli_adapter = __esm({
7396
7390
  if (!text.trim()) return false;
7397
7391
  return /(^|\n)\s*[❯›>]\s*(?:\n|$)/m.test(text) || /⏎\s+send/i.test(text) || /\?\s*for\s*shortcuts/i.test(text) || /Type your message(?:\s+or\s+@path\/to\/file)?/i.test(text) || /workspace\s*\(\/directory\)/i.test(text) || /for\s*shortcuts/i.test(text);
7398
7392
  }
7393
+ findLastMatchingLineIndex(lines, predicate) {
7394
+ for (let index = lines.length - 1; index >= 0; index -= 1) {
7395
+ if (predicate(lines[index])) return index;
7396
+ }
7397
+ return -1;
7398
+ }
7399
+ looksLikeClaudeGeneratingLine(line) {
7400
+ const trimmed = String(line || "").trim();
7401
+ if (!trimmed) return false;
7402
+ if (/esc to (cancel|interrupt|stop)/i.test(trimmed)) return true;
7403
+ if (/^[✻✶✳✢✽⠂⠐⠒⠓⠦⠴⠶⠷⠿]+\s+\S+.*\b(?:thinking|thought for \d+s?)\b/i.test(trimmed)) return true;
7404
+ if (/^[✻✶✳✢✽⠂⠐⠒⠓⠦⠴⠶⠷⠿]+\s+[A-Z][A-Za-z-]{3,}ing\b.*(?:…|\.{3})/u.test(trimmed)) return true;
7405
+ if (/^[⏺•]\s+(?:Reading|Writing|Editing|Searching|Inspecting|Planning|Analyzing|Synthesizing|Drafting|Running|Listing|Scanning|Matching)\b.*(?:…|\.{3})/i.test(trimmed)) {
7406
+ return /ctrl\+o to expand/i.test(trimmed) || /\b\d+\s+(?:file|files|pattern|patterns|director(?:y|ies)|match|matches|result|results)\b/i.test(trimmed);
7407
+ }
7408
+ return false;
7409
+ }
7410
+ detectClaudeGeneratingOverride(screenText, tail) {
7411
+ if (this.cliType !== "claude-cli") return false;
7412
+ const source = sanitizeTerminalText(screenText || tail || "");
7413
+ if (!source.trim()) return false;
7414
+ const allLines = source.split(/\r\n|\n|\r/g).map((line) => line.trim()).filter(Boolean);
7415
+ if (allLines.length === 0) return false;
7416
+ const recentLines = allLines.slice(-12);
7417
+ const promptIndex = this.findLastMatchingLineIndex(recentLines, (line) => /^[❯›>]\s*$/.test(line));
7418
+ const activeRegion = promptIndex >= 0 ? recentLines.slice(promptIndex + 1) : recentLines;
7419
+ if (activeRegion.length === 0) return false;
7420
+ return activeRegion.some((line) => this.looksLikeClaudeGeneratingLine(line));
7421
+ }
7422
+ refineDetectedStatus(status, tail, screenText) {
7423
+ if (status === "waiting_approval") return status;
7424
+ if (this.detectClaudeGeneratingOverride(screenText || "", tail)) return "generating";
7425
+ return status;
7426
+ }
7399
7427
  looksLikeVisibleAssistantCandidate(screenText) {
7400
7428
  const lines = sanitizeTerminalText(String(screenText || "")).split(/\r\n|\n|\r/g);
7401
7429
  for (const line of lines) {
@@ -7793,11 +7821,13 @@ var init_provider_cli_adapter = __esm({
7793
7821
  runDetectStatus(text) {
7794
7822
  if (!this.cliScripts?.detectStatus) return null;
7795
7823
  try {
7796
- return this.cliScripts.detectStatus({
7824
+ const screenText = this.terminalScreen.getText();
7825
+ const status = this.cliScripts.detectStatus({
7797
7826
  tail: text.slice(-500),
7798
- screenText: this.terminalScreen.getText(),
7827
+ screenText,
7799
7828
  rawBuffer: this.accumulatedRawBuffer
7800
7829
  });
7830
+ return this.refineDetectedStatus(status, text, screenText || "");
7801
7831
  } catch (e) {
7802
7832
  LOG.warn("CLI", `[${this.cliType}] detectStatus error: ${e.message}`);
7803
7833
  return null;
@@ -7867,6 +7897,10 @@ var init_provider_cli_adapter = __esm({
7867
7897
  try {
7868
7898
  const input = this.buildParseInput(baseMessages, partialResponse, scope);
7869
7899
  const parsed = this.cliScripts.parseOutput(input);
7900
+ const refinedStatus = this.refineDetectedStatus(typeof parsed?.status === "string" ? parsed.status : null, input.recentBuffer, input.screenText);
7901
+ if (parsed && refinedStatus && parsed.status !== refinedStatus) {
7902
+ parsed.status = refinedStatus;
7903
+ }
7870
7904
  const promptForTrim = scope?.prompt || getLastUserPromptText(baseMessages);
7871
7905
  if (parsed && Array.isArray(parsed.messages) && promptForTrim) {
7872
7906
  const lastAssistant = [...parsed.messages].reverse().find((message) => message?.role === "assistant" && typeof message.content === "string");
@@ -46591,7 +46625,7 @@ var init_adhdev_daemon = __esm({
46591
46625
  import_ws3 = require("ws");
46592
46626
  import_chalk2 = __toESM(require("chalk"));
46593
46627
  init_version();
46594
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.20" });
46628
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.22" });
46595
46629
  DANGEROUS_PATTERNS = [
46596
46630
  /\brm\s+(-[a-z]*f|-[a-z]*r|--force|--recursive)/i,
46597
46631
  /\bsudo\b/i,