@livx.cc/agentx 0.99.165 → 0.99.166

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.js CHANGED
@@ -3359,7 +3359,7 @@ var init_tools_shell = __esm({
3359
3359
 
3360
3360
  // cli/cli.ts
3361
3361
  import { createInterface } from "readline/promises";
3362
- import { existsSync as existsSync9, readFileSync as readFileSync10, appendFileSync as appendFileSync2, mkdirSync as mkdirSync12, writeFileSync as writeFileSync9, readdirSync as readdirSync4, statSync as statSync8, unlinkSync as unlinkSync5 } from "fs";
3362
+ import { existsSync as existsSync9, readFileSync as readFileSync10, appendFileSync as appendFileSync2, mkdirSync as mkdirSync12, writeFileSync as writeFileSync9, readdirSync as readdirSync4, statSync as statSync7, unlinkSync as unlinkSync5 } from "fs";
3363
3363
  import { homedir as homedir10 } from "os";
3364
3364
  import { spawnSync as spawnSync7 } from "child_process";
3365
3365
 
@@ -8153,6 +8153,9 @@ var VoiceEngine = class _VoiceEngine {
8153
8153
  // bumps on every aside start/cancel — a late aside of a dead hold never plays
8154
8154
  speaking = false;
8155
8155
  // audible (deltas flowing OR audio draining)
8156
+ speechStartAt = 0;
8157
+ // clock time `speaking` last turned on / off
8158
+ speechEndAt = 0;
8156
8159
  ctxOpen = false;
8157
8160
  // the current TTS context still accepts deltas (false once end-frame sent)
8158
8161
  interrupted = false;
@@ -8350,11 +8353,13 @@ var VoiceEngine = class _VoiceEngine {
8350
8353
  this.handleUtterance(k.text, language ? { [language]: k.text.length } : void 0, k.turns);
8351
8354
  };
8352
8355
  this.stt.onLevel = (rms) => this.handleLevel(rms);
8356
+ this.stt.isAudible = (agoMs = 0) => this.speakingAt(this.clock.now() - agoMs);
8353
8357
  const stt = this.stt;
8354
8358
  this.agentText = stt.agentTextInput && stt.sendAgentText ? new AgentTextFeed({
8355
8359
  clock: this.clock,
8356
8360
  playedMs: () => Math.max(0, this.player.playedMs()),
8357
8361
  send: (text, end) => {
8362
+ this.diag("agent_text", { text: text.slice(0, 80), ...end ? { end: true } : {} });
8358
8363
  try {
8359
8364
  stt.sendAgentText(text, end);
8360
8365
  } catch (e) {
@@ -8446,7 +8451,10 @@ var VoiceEngine = class _VoiceEngine {
8446
8451
  }
8447
8452
  this.diag("tts_turn_begin", { ack, gapless: this.speaking });
8448
8453
  const gapless = this.speaking;
8449
- if (!this.speaking) this.player.markTurn();
8454
+ if (!this.speaking) {
8455
+ this.player.markTurn();
8456
+ this.speechStartAt = this.clock.now();
8457
+ }
8450
8458
  this.speaking = true;
8451
8459
  this.ctxOpen = true;
8452
8460
  this.spokeDeltas = false;
@@ -8671,6 +8679,7 @@ var VoiceEngine = class _VoiceEngine {
8671
8679
  }
8672
8680
  this.drainTimer = null;
8673
8681
  this.speaking = false;
8682
+ this.speechEndAt = this.clock.now();
8674
8683
  this.agentText?.end();
8675
8684
  this.stopWordReveal(true);
8676
8685
  if (this.turnStartAt) log14.debug(`turn: ${Math.round(this.clock.now() - this.turnStartAt)}ms (incl. playback)`);
@@ -8869,6 +8878,7 @@ var VoiceEngine = class _VoiceEngine {
8869
8878
  if (this.reply || droppedQueued) this.lastInterrupted = { full: this.reply, heard, exact, queued, queuedTurn: this.queuedTurn };
8870
8879
  if (heard.length < this.reply.length || droppedQueued) this.bargedSinceDispatch = true;
8871
8880
  this.speaking = false;
8881
+ this.speechEndAt = this.clock.now();
8872
8882
  this.ctxOpen = false;
8873
8883
  this.interrupted = true;
8874
8884
  this.suspectUntil = 0;
@@ -8978,6 +8988,14 @@ var VoiceEngine = class _VoiceEngine {
8978
8988
  novelWords(text) {
8979
8989
  return this.words(text).filter((w) => !this.echoWords.has(w));
8980
8990
  }
8991
+ /** Was the assistant speaking at clock time `t` (+ PHANTOM_TAIL_MS)? Narrower than echoActive's multi-second echo
8992
+ * tail on purpose: the STT phantom guard drops low-confidence short finals here, and a real "Yes." said right after
8993
+ * a question must not land inside it. speechEndAt already trails the audio by the settle margin (~300ms). */
8994
+ speakingAt(t) {
8995
+ if (t < this.speechStartAt) return false;
8996
+ return this.speaking || t < this.speechEndAt + _VoiceEngine.PHANTOM_TAIL_MS;
8997
+ }
8998
+ static PHANTOM_TAIL_MS = 300;
8981
8999
  echoActive() {
8982
9000
  return this.speaking || this.clock.now() < this.echoUntil;
8983
9001
  }
@@ -10047,7 +10065,18 @@ var SonioxSTTOptions = class {
10047
10065
  * same socket (`sendAgentText`, which VoiceEngine drives paced to playback), so Soniox filters the leftover echo
10048
10066
  * of our own voice out of the transcript. Complements AEC — keep echo cancellation on. */
10049
10067
  agentTextInput = false;
10068
+ /** Phantom guard: when its last word fell while the assistant was speaking (`isAudible`, wired by VoiceEngine), drop a
10069
+ * final of at most `phantomMaxWords` words, all listener tokens (`phantomTokens`), whose least-sure token is below
10070
+ * `phantomMinConfidence`. stt-rt-v6 makes up backchannels ("Okay.", "Yeah.", "Mm-hmm.") from echo residue under our
10071
+ * own voice: all at confMin 0.33-0.78 (agentx session 20261111-124649). Confidence alone can't separate them from a
10072
+ * real word said over our voice — `say` clips into live Soniox under a reply's residue: 12/19 soft interjections fell
10073
+ * below 0.8 — so words that act ("Stop.", "No.", "Yes.", "Wait.") always pass; a listener token over our own speech
10074
+ * is a no-op anyway. 0 = off. */
10075
+ phantomMinConfidence = 0.8;
10076
+ phantomMaxWords = 2;
10077
+ phantomTokens = /^(?:okay|ok|yeah|yep|yup|mm-?hmm|mhm|hmm+|mm+|uh-?huh|oh|ah|right)$/i;
10050
10078
  };
10079
+ var STD_TOKEN_KEYS = /* @__PURE__ */ new Set(["text", "start_ms", "end_ms", "confidence", "is_final", "language", "speaker"]);
10051
10080
  var SonioxSTT = class {
10052
10081
  options;
10053
10082
  ws;
@@ -10072,6 +10101,9 @@ var SonioxSTT = class {
10072
10101
  * loop). The host tears voice down instead of spinning forever. */
10073
10102
  onFatal = () => {
10074
10103
  };
10104
+ /** Was the assistant speaking `agoMs` ago (+ a short tail)? Set by VoiceEngine; gates the phantom guard, asked for the
10105
+ * moment the utterance's last word was said (not when its final landed, ~1s later). */
10106
+ isAudible = () => false;
10075
10107
  /** Diagnostic tap (provider errors, ws reconnects, no-audio watchdog). Fire-and-forget: a throwing
10076
10108
  * handler disables itself — never affects transcription. Wired by VoiceIO / the lab bridge. */
10077
10109
  onDiag = () => {
@@ -10106,6 +10138,12 @@ var SonioxSTT = class {
10106
10138
  finalToks = [];
10107
10139
  // diarization only: finalized tokens of the current utterance
10108
10140
  partialToks = [];
10141
+ uttToks = [];
10142
+ // stt_final diag: finalized tokens of the current utterance
10143
+ uttPartials = [];
10144
+ // stt_final diag: its current partial tokens
10145
+ levels = [];
10146
+ // stt_final diag: recent mic RMS per chunk (~12s)
10109
10147
  constructor(options) {
10110
10148
  this.options = { ...new SonioxSTTOptions(), ...options };
10111
10149
  }
@@ -10169,10 +10207,7 @@ var SonioxSTT = class {
10169
10207
  const combined = (this.finalText + this.partialText).trim();
10170
10208
  if (!combined || now() - this.lastChangeAt < this.options.silenceEndpointMs) return;
10171
10209
  if (this.firstTokenAt) log15.debug(`stt: ${Math.round(now() - this.firstTokenAt)}ms first-token\u2192silence-endpoint, "${combined.slice(0, 60)}"`);
10172
- const language = this.language(true);
10173
- const turns = this.turns(true), ago = this.lastWordAgoMs();
10174
- this.reset();
10175
- this.onUtterance(this.stray(combined), now(), language, turns, ago);
10210
+ this.emit(combined, "silence");
10176
10211
  }, 120);
10177
10212
  this.endpointTimer.unref?.();
10178
10213
  this.startedChunksAt = now();
@@ -10198,7 +10233,10 @@ var SonioxSTT = class {
10198
10233
  const v = view.getInt16(i, true);
10199
10234
  sum += v * v;
10200
10235
  }
10201
- this.onLevel(Math.sqrt(sum / (chunk.byteLength / 2)));
10236
+ const rms = Math.sqrt(sum / (chunk.byteLength / 2));
10237
+ this.levels.push({ at: this.lastChunkAt, rms });
10238
+ if (this.levels.length > 120) this.levels.shift();
10239
+ this.onLevel(rms);
10202
10240
  if (this.ws.readyState === WebSocket.OPEN) {
10203
10241
  this.ws.send(chunk);
10204
10242
  const at = this.sentBytes / 2 / STT_SAMPLE_RATE * 1e3;
@@ -10229,6 +10267,7 @@ var SonioxSTT = class {
10229
10267
  if (t.text !== "<end>" && typeof t.end_ms === "number" && String(t.text).trim() && t.end_ms > this.lastWordEndMs) this.lastWordEndMs = t.end_ms;
10230
10268
  if (t.text === "<end>") endpoint = true;
10231
10269
  else if (t.is_final) {
10270
+ this.uttToks.push(t);
10232
10271
  this.finalText += t.text;
10233
10272
  this.countLang(this.finalLangChars, t);
10234
10273
  if (this.options.diarization) this.finalToks.push(t);
@@ -10239,6 +10278,7 @@ var SonioxSTT = class {
10239
10278
  this.partialLangChars = {};
10240
10279
  for (const t of partials) this.countLang(this.partialLangChars, t);
10241
10280
  if (this.options.diarization) this.partialToks = partials;
10281
+ this.uttPartials = partials;
10242
10282
  const combined = this.finalText + this.partialText;
10243
10283
  if (combined !== this.lastCombined) {
10244
10284
  this.lastCombined = combined;
@@ -10249,10 +10289,32 @@ var SonioxSTT = class {
10249
10289
  if (endpoint && this.finalText.trim()) {
10250
10290
  const utterance = this.finalText.trim();
10251
10291
  if (this.firstTokenAt) log15.debug(`stt: ${Math.round(now() - this.firstTokenAt)}ms first-token\u2192endpoint, "${utterance.slice(0, 60)}"`);
10252
- const language = this.language(false);
10253
- const turns = this.turns(false), ago = this.lastWordAgoMs();
10254
- this.reset();
10255
- this.onUtterance(this.stray(utterance), now(), language, turns, ago);
10292
+ this.emit(utterance, "end");
10293
+ }
10294
+ }
10295
+ /** Close the current utterance: diag, reset, then hand it to onUtterance — unless the phantom guard drops it. */
10296
+ emit(text, endpoint) {
10297
+ const withPartials = endpoint === "silence";
10298
+ const language = this.language(withPartials);
10299
+ const turns = this.turns(withPartials), ago = this.lastWordAgoMs();
10300
+ const confMin = this.finalDiag(text, endpoint, ago);
10301
+ this.reset();
10302
+ if (this.phantom(text, confMin, ago)) {
10303
+ this.diag("stt_phantom_dropped", { text: text.slice(0, 80), confMin, lastWordAgoMs: ago });
10304
+ return;
10305
+ }
10306
+ this.onUtterance(this.stray(text), now(), language, turns, ago);
10307
+ }
10308
+ phantom(text, confMin, agoMs) {
10309
+ const { phantomMinConfidence: min, phantomMaxWords: max, phantomTokens: listener } = this.options;
10310
+ if (!min || confMin === void 0 || confMin >= min) return false;
10311
+ const words5 = text.split(/[\s,.!?…]+/).filter(Boolean);
10312
+ if (!words5.length || words5.length > max || !words5.every((w) => listener.test(w))) return false;
10313
+ try {
10314
+ return this.isAudible(agoMs ?? 0);
10315
+ } catch (e) {
10316
+ log15.warn(`isAudible threw: ${e instanceof Error ? e.message : e}`);
10317
+ return false;
10256
10318
  }
10257
10319
  }
10258
10320
  /** How long ago (ms, now) the utterance's last spoken word ended: the audio sent so far minus that token's end_ms on
@@ -10285,7 +10347,29 @@ var SonioxSTT = class {
10285
10347
  const words5 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
10286
10348
  return words5.some((w) => w.spk != null) ? speakerRuns(words5) : void 0;
10287
10349
  }
10350
+ /** One `stt_final` diag per utterance: how sure Soniox was, the mic level over it, and any token fields beyond the
10351
+ * usual ones — to tell words the user said from ones the STT made up (a phantom "Okay." heard 186× over our own
10352
+ * speech, agentx session 20261111-105859). */
10353
+ finalDiag(text, endpoint, lastWordAgoMs) {
10354
+ const toks = [...this.uttToks, ...endpoint === "silence" ? this.uttPartials : []].filter((t) => String(t.text).trim());
10355
+ const conf = toks.map((t) => t.confidence).filter((c) => typeof c === "number");
10356
+ const since = (this.firstTokenAt || now()) - 1500;
10357
+ const rms = this.levels.filter((l) => l.at >= since).map((l) => l.rms).sort((a, b) => a - b);
10358
+ const extra = [...new Set(toks.flatMap((t) => Object.keys(t).filter((k) => !STD_TOKEN_KEYS.has(k))))];
10359
+ this.diag("stt_final", {
10360
+ text: text.slice(0, 80),
10361
+ endpoint,
10362
+ lastWordAgoMs,
10363
+ ...conf.length ? { confMin: +Math.min(...conf).toFixed(3), confAvg: +(conf.reduce((a, b) => a + b, 0) / conf.length).toFixed(3) } : {},
10364
+ ...rms.length ? { rmsPeak: Math.round(rms[rms.length - 1]), rmsMed: Math.round(rms[rms.length >> 1]) } : {},
10365
+ ...toks.length ? { startMs: toks[0].start_ms, endMs: toks[toks.length - 1].end_ms } : {},
10366
+ ...extra.length ? { tokenKeys: extra } : {}
10367
+ });
10368
+ return conf.length ? Math.min(...conf) : void 0;
10369
+ }
10288
10370
  reset() {
10371
+ this.uttToks = [];
10372
+ this.uttPartials = [];
10289
10373
  this.finalToks = [];
10290
10374
  this.partialToks = [];
10291
10375
  this.finalLangChars = {};
@@ -10388,7 +10472,7 @@ var now2 = () => performance.now();
10388
10472
  var CartesiaTTSOptions = class {
10389
10473
  auth = "";
10390
10474
  voiceId = "";
10391
- model = "sonic-3.5";
10475
+ model = "sonic-3.6";
10392
10476
  /** 'apiKey' (server/CLI) → `api_key=` URL param; 'token' (browser, BE-minted) → `access_token=`. */
10393
10477
  authMode = "apiKey";
10394
10478
  /** Cartesia `language` code ('en', 'he', …). Unset → field omitted (provider default). Mutable:
@@ -10490,6 +10574,16 @@ var CartesiaTTS = class _CartesiaTTS {
10490
10574
  };
10491
10575
  this.ws.onmessage = (ev) => {
10492
10576
  const m = JSON.parse(String(ev.data));
10577
+ const pr = m.context_id && this.priming.get(m.context_id);
10578
+ if (pr) {
10579
+ if (m.type === "chunk" && m.data) pr.chunks.push(base64ToBytes(m.data));
10580
+ else if (m.type === "done" || m.type === "error") {
10581
+ this.priming.delete(m.context_id);
10582
+ if (m.type === "done") this.primed.set(pr.key, pr.chunks);
10583
+ else this.primed.delete(pr.key);
10584
+ }
10585
+ return;
10586
+ }
10493
10587
  if (m.context_id && m.context_id !== this.ctxId) return;
10494
10588
  if (m.type === "chunk" && m.data) {
10495
10589
  this.consecutiveErrors = 0;
@@ -10547,7 +10641,40 @@ var CartesiaTTS = class _CartesiaTTS {
10547
10641
  this.newContext();
10548
10642
  if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame("Ok.", false));
10549
10643
  }
10644
+ /** Phrases synthesized ahead (prime): key → audio (null = still generating). */
10645
+ primed = /* @__PURE__ */ new Map();
10646
+ priming = /* @__PURE__ */ new Map();
10647
+ /** This context began with a primed phrase: its audio played from the cache; more text is synthesized after it. */
10648
+ ctxCached = false;
10649
+ ctxRest = "";
10650
+ ctxSent = false;
10651
+ static key(t) {
10652
+ return t.trim().replace(/[\s.,!?…]+$/u, "").replace(/\s+/g, " ");
10653
+ }
10654
+ /** Synthesize `text` now, in this voice and language, and keep its audio: a later utterance that is exactly this text
10655
+ * plays at once, with no TTS round trip (a call's planned opener — live: ~470ms to its first audio). */
10656
+ prime(text) {
10657
+ const key = _CartesiaTTS.key(text);
10658
+ if (!key || this.primed.has(key) || this.down) return;
10659
+ this.primed.set(key, null);
10660
+ const id = `prime-${++this.ctxSeq}`;
10661
+ const send = () => {
10662
+ const cur = this.ctxId, lang = this.ctxLanguage;
10663
+ this.ctxId = id;
10664
+ this.ctxLanguage = this.options.language;
10665
+ const f = this.frame(text, false);
10666
+ this.ctxId = cur;
10667
+ this.ctxLanguage = lang;
10668
+ this.priming.set(id, { key, chunks: [] });
10669
+ this.ws.send(f);
10670
+ };
10671
+ if (this.ws?.readyState === WebSocket.OPEN) send();
10672
+ else void this.ensureConnected().then(() => this.ws?.readyState === WebSocket.OPEN && send());
10673
+ }
10550
10674
  newContext() {
10675
+ this.ctxCached = false;
10676
+ this.ctxRest = "";
10677
+ this.ctxSent = false;
10551
10678
  this.ctxId = `ctx-${++this.ctxSeq}`;
10552
10679
  this.firstAudioAt = 0;
10553
10680
  this.ctxLanguage = this.options.language;
@@ -10573,6 +10700,19 @@ var CartesiaTTS = class _CartesiaTTS {
10573
10700
  if (this.down) return;
10574
10701
  text = cont ? this.say.feed(text) : this.say.feed(text) + this.say.flush();
10575
10702
  if (cont && !text) return;
10703
+ const hit = !this.firstAudioAt && !this.ctxCached && this.primed.get(_CartesiaTTS.key(text));
10704
+ if (hit) {
10705
+ this.ctxCached = true;
10706
+ this.firstAudioAt = now2();
10707
+ this.diag("tts_primed", { chars: text.length });
10708
+ for (const c of hit) this.onAudio(c);
10709
+ return;
10710
+ }
10711
+ if (this.ctxCached) {
10712
+ this.ctxRest += text;
10713
+ return;
10714
+ }
10715
+ this.ctxSent = true;
10576
10716
  if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame(text, cont));
10577
10717
  else void this.ensureConnected().then(() => this.ws?.readyState === WebSocket.OPEN && this.ws.send(this.frame(text, cont)));
10578
10718
  }
@@ -10586,11 +10726,27 @@ var CartesiaTTS = class _CartesiaTTS {
10586
10726
  this.ws.send(JSON.stringify({ ...JSON.parse(this.frame("", true)), flush: true }));
10587
10727
  }
10588
10728
  end() {
10589
- const held2 = this.say.flush();
10729
+ let held2 = this.say.flush();
10590
10730
  if (this.down) {
10591
10731
  this.onDone();
10592
10732
  return;
10593
10733
  }
10734
+ const hit = !this.ctxSent && !this.ctxCached && !this.firstAudioAt && this.primed.get(_CartesiaTTS.key(held2));
10735
+ if (hit) {
10736
+ this.diag("tts_primed", { chars: held2.length });
10737
+ this.firstAudioAt = now2();
10738
+ for (const c of hit) this.onAudio(c);
10739
+ queueMicrotask(() => this.onDone());
10740
+ return;
10741
+ }
10742
+ if (this.ctxCached) {
10743
+ held2 = (this.ctxRest + held2).trim();
10744
+ this.ctxRest = "";
10745
+ if (!held2) {
10746
+ queueMicrotask(() => this.onDone());
10747
+ return;
10748
+ }
10749
+ }
10594
10750
  if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame(held2, false));
10595
10751
  }
10596
10752
  cancel() {
@@ -10692,8 +10848,6 @@ var REACT = /^(?:(?:oh|and|so|wait|but|ok|okay|yeah)\s+)*(?:wow|whoa|woah|really
10692
10848
  var WH_LEAD = "^(?:(?:oh|and|so|wait|but|ok|okay|um|uh|sorry)\\s+)*";
10693
10849
  var WH_QUESTION = new RegExp(WH_LEAD + "(?:who|whom|whose|where|which|why|how|when|what|\u05DE\u05D9|\u05D0\u05D9\u05E4\u05D4|\u05DC\u05DE\u05D4|\u05D0\u05D9\u05DA|\u05DE\u05EA\u05D9|\u05DE\u05D4)\\s+\\S", "u");
10694
10850
  var WH_EXCLAIM = new RegExp(WH_LEAD + "(?:what an? |how (?:cool|nice|fun|sweet|sad|funny|weird|crazy|strange|interesting|beautiful|lovely|cute|amazing|awesome)\\b)", "u");
10695
- var BARE = /* @__PURE__ */ new Set(["yeah", "yea", "yes", "yep", "yup", "ok", "okay", "k", "right", "sure", "mm", "mmm", "hmm", "mhm", "mm-hm", "mm-hmm", "uh-huh", "um", "uh", "ah", "oh"]);
10696
- var isBareCue = (text) => BARE.has(norm2(text).replace(/^-+|-+$/g, ""));
10697
10851
  var isReaction = (text) => {
10698
10852
  const t = norm2(text);
10699
10853
  return REACT.test(t) || new RegExp("\\s\\p{L}{1,3}$", "u").test(t) && REACT.test(t.replace(new RegExp("\\s\\p{L}{1,3}$", "u"), ""));
@@ -16082,10 +16236,6 @@ var VoiceCall = class {
16082
16236
  this.barge();
16083
16237
  return "cut";
16084
16238
  }
16085
- if (isBareCue(text)) {
16086
- this.o.onMetric({ name: "drop", kind: "bare cue", text });
16087
- return "keep";
16088
- }
16089
16239
  if (this.o.mode === "live" && isReaction(text)) return this.kept(text), "keep";
16090
16240
  const d = await this.judge.judge(text);
16091
16241
  if (d.verdict === "cut") this.barge();
@@ -16130,7 +16280,7 @@ var VoiceCall = class {
16130
16280
  * fill line: never MAIN history. */
16131
16281
  aside(text) {
16132
16282
  const now4 = this.o.now();
16133
- if (isBareCue(text) || now4 - this.lastAside.at < this.o.asideGapMs) return null;
16283
+ if (now4 - this.lastAside.at < this.o.asideGapMs) return null;
16134
16284
  const line = overlapAside(text, this.lang, this.lastAside.text, void 0, this.o.mode === "live");
16135
16285
  if (!line) return null;
16136
16286
  this.lastAside = { text: line, at: now4 };
@@ -16169,10 +16319,7 @@ var VoiceCall = class {
16169
16319
  onTurn(t) {
16170
16320
  this.floor = "";
16171
16321
  this.flushKept(t.text);
16172
- if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) {
16173
- if (isBareCue(t.text)) return void this.o.onMetric({ name: "drop", id: t.id, kind: "bare cue", text: t.text });
16174
- return void this.overWork(this.cur, t);
16175
- }
16322
+ if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
16176
16323
  const prev = this.cur, quick = this.quickOn && !this.working && (t.kind === "new" || prev?.lane !== "deep");
16177
16324
  const now4 = this.o.now(), lastWord = this.lastWordAt !== null;
16178
16325
  const at = this.lastWordAt ?? this.firstFinalAt ?? now4;
@@ -17532,7 +17679,8 @@ init_logging();
17532
17679
  init_llm();
17533
17680
  init_platform();
17534
17681
  import { spawn as spawn2, spawnSync as spawnSync3 } from "child_process";
17535
- import { appendFileSync, existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync6, statSync as statSync6 } from "fs";
17682
+ import { createHash as createHash3 } from "crypto";
17683
+ import { appendFileSync, existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync, rmSync as rmSync2 } from "fs";
17536
17684
  import { homedir as homedir3 } from "os";
17537
17685
  import { dirname as dirname4, join as join8 } from "path";
17538
17686
  import { fileURLToPath } from "url";
@@ -17631,20 +17779,26 @@ function resolveAecBinary() {
17631
17779
  const plist = join8(nativeDir(), "Info.plist");
17632
17780
  if (!existsSync4(src)) return null;
17633
17781
  const cacheDir = join8(homedir3(), ".agent", "cache");
17634
- const bin = join8(cacheDir, "mic-aec");
17635
- if (existsSync4(bin) && statSync6(bin).mtimeMs >= statSync6(src).mtimeMs) return bin;
17782
+ const hash = createHash3("sha1").update(readFileSync6(src)).update(readFileSync6(plist)).digest("hex").slice(0, 10);
17783
+ const bin = join8(cacheDir, `mic-aec-${hash}`);
17784
+ if (existsSync4(bin)) return bin;
17636
17785
  if (spawnSync3("which", ["swiftc"]).status !== 0) return null;
17637
17786
  mkdirSync5(cacheDir, { recursive: true });
17638
17787
  log36.info("compiling AEC mic helper (first run)\u2026");
17639
- const build = spawnSync3("swiftc", ["-O", "-o", bin, src, "-Xlinker", "-sectcreate", "-Xlinker", "__TEXT", "-Xlinker", "__info_plist", "-Xlinker", plist], { encoding: "utf8" });
17640
- if (build.status !== 0) {
17641
- log36.warn(`AEC build failed: ${build.stderr?.slice(0, 400)}`);
17642
- return null;
17643
- }
17644
- const sign = spawnSync3("codesign", ["-fs", "-", bin], { encoding: "utf8" });
17645
- if (sign.status !== 0) {
17646
- log36.warn(`codesign failed: ${sign.stderr?.slice(0, 200)}`);
17788
+ const tmp = `${bin}.${process.pid}.tmp`;
17789
+ const fail = (msg) => {
17790
+ log36.warn(msg);
17791
+ rmSync2(tmp, { force: true });
17647
17792
  return null;
17793
+ };
17794
+ const build = spawnSync3("swiftc", ["-O", "-o", tmp, src, "-Xlinker", "-sectcreate", "-Xlinker", "__TEXT", "-Xlinker", "__info_plist", "-Xlinker", plist], { encoding: "utf8" });
17795
+ if (build.status !== 0) return fail(`AEC build failed: ${build.stderr?.slice(0, 400)}`);
17796
+ const sign = spawnSync3("codesign", ["-fs", "-", tmp], { encoding: "utf8" });
17797
+ if (sign.status !== 0) return fail(`codesign failed: ${sign.stderr?.slice(0, 200)}`);
17798
+ try {
17799
+ renameSync(tmp, bin);
17800
+ } catch (e) {
17801
+ return fail(`AEC helper install failed: ${e instanceof Error ? e.message : e}`);
17648
17802
  }
17649
17803
  return bin;
17650
17804
  }
@@ -19108,7 +19262,7 @@ function formatDiff(ops, opts = {}) {
19108
19262
  }
19109
19263
 
19110
19264
  // cli/session.ts
19111
- import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as readFileSync8, writeFileSync as writeFileSync5, readdirSync, renameSync, symlinkSync as symlinkSync2, unlinkSync, readlinkSync, statSync as statSync7 } from "fs";
19265
+ import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as readFileSync8, writeFileSync as writeFileSync5, readdirSync, renameSync as renameSync2, symlinkSync as symlinkSync2, unlinkSync, readlinkSync, statSync as statSync6 } from "fs";
19112
19266
  import { homedir as homedir6 } from "os";
19113
19267
  import { join as join11 } from "path";
19114
19268
  init_platform();
@@ -19164,7 +19318,7 @@ var SessionStore = class {
19164
19318
  const path = join11(this.dir, `${data.meta.id}.json`);
19165
19319
  const tmp = `${path}.${process.pid}.tmp`;
19166
19320
  writeFileSync5(tmp, JSON.stringify(data));
19167
- renameSync(tmp, path);
19321
+ renameSync2(tmp, path);
19168
19322
  try {
19169
19323
  const gd = globalDir();
19170
19324
  if (!existsSync6(gd)) mkdirSync8(gd, { recursive: true });
@@ -19209,7 +19363,7 @@ var SessionStore = class {
19209
19363
  for (const f of readdirSync(this.dir)) {
19210
19364
  if (!f.endsWith(".json")) continue;
19211
19365
  try {
19212
- const st = statSync7(join11(this.dir, f));
19366
+ const st = statSync6(join11(this.dir, f));
19213
19367
  out.push({ id: f.slice(0, -5), mtime: st.mtimeMs, size: st.size });
19214
19368
  } catch {
19215
19369
  }
@@ -23216,7 +23370,7 @@ function readImageParts(cwd, line) {
23216
23370
  if (!mime) continue;
23217
23371
  const abs = userPath(cwd, ref);
23218
23372
  try {
23219
- statSync8(abs);
23373
+ statSync7(abs);
23220
23374
  } catch {
23221
23375
  continue;
23222
23376
  }
@@ -23232,7 +23386,7 @@ function pastePathClassifier(cwd) {
23232
23386
  if (!PATH_LIKE.test(t)) return null;
23233
23387
  const abs = userPath(cwd, t);
23234
23388
  try {
23235
- if (!statSync8(abs).isFile()) return null;
23389
+ if (!statSync7(abs).isFile()) return null;
23236
23390
  } catch {
23237
23391
  return null;
23238
23392
  }