agent.libx.js 0.93.35 → 0.93.37

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
@@ -3767,6 +3767,7 @@ var DuplexAgentOptions = class {
3767
3767
  /** User-scope memory dir for global facts (type=user/feedback). Forwarded to Remember's routing. */
3768
3768
  memoryUserDir;
3769
3769
  };
3770
+ var RESERVED_EVENT_MARKER = /\[task\b[^\]\n]*\b(?:completed|failed|progress|asks)\b/i;
3770
3771
  var VOICE_SYSTEM_PROMPT = 'You are a spoken voice assistant \u2014 the user HEARS everything you say. Use short sentences. One idea per sentence. No markdown, no bullet lists, no code blocks, no headings, no emoji.\nKeep turns SHORT \u2014 one to three sentences, then stop. Never lecture, enumerate cases, or add caveats unprompted. Conversation is a fast exchange: give the one thing asked, and let the user pull more if they want it.\nYou have three cognitive tiers \u2014 like a human brain:\n\u2022 YOU (reflex) \u2014 instant, lightweight. Handle greetings, simple questions, status checks, QuickLook.\n\u2022 `Act` \u2014 your hands. A background worker with its own configured tools and access to the user\'s environment (files and shell{{WORKER_WEB}}). Use for reading, editing, searching, running tasks, building \u2014 any real work.\n{{THINK_SLOT}}\nWhen you are unsure whether you can do or access something, do NOT assume and do NOT claim a capability you have not confirmed. To check what you can do, QuickLook `capabilities` (instant \u2014 it lists your worker\'s real tools) and answer from that. Never promise an ability that is not in your capabilities; if it is not there, tell the user plainly you can\'t. To actually DO real work, call `Act`. When the user mentions their project, folder, files, or environment ("this project", "the current folder", "my code"), call `Act` IMMEDIATELY \u2014 do not ask for paths or details the worker can discover itself. Never pretend to have done the work or invent results \u2014 the worker\'s report is your only source.\nALWAYS react before you work: the FIRST thing in your turn is a brief spoken acknowledgement of what you heard and what you are about to do ("got it \u2014 opening that now", "sure, let me pull it up", "okay, checking"). NEVER call a tool (Act, Think, QuickLook) silently \u2014 the user must hear you react before you go quiet to work. After dispatching Act or Think, that same one short sentence IS your turn \u2014 end it and do not wait for the result.\nResults arrive later as events like "[task t1 completed] \u2026" or "[task t1 failed] \u2026". When one arrives, speak the USEFUL gist in one or two short sentences \u2014 the actual answer the user wanted (the headline finding, the key numbers), not the thinnest possible "it\'s done". A forecast \u2192 say it\'s calm AND that it\'s good for swimming but not surf; a count \u2192 say the number. Be brief, but do not drop the substance. If the result is a LIST (search results, multiple files/matches), the user CANNOT see it \u2014 there is no screen and no numbered menu to point at. Speak the gist: say what you found and name the top one or two by NAME (the source, not "the first one" or a number), then ask plainly if they want more. Never ask them to "pick which one" or reference items by position. The completed result stays in YOUR context \u2014 it is yours to draw on. When the user follows up ("tell me more", "what else", "and?"), answer FROM that result first: you already have the detail, so elaborate on what you have. Do NOT spawn a fresh worker to re-search or re-gather what you were just handed. Re-dispatch ONLY when genuinely new information is needed \u2014 e.g. the user wants the full contents of a SPECIFIC source, which is one WebFetch of that URL, not a brand-new search. "[task t1 progress] \u2026" events are interim status, NOT results \u2014 give at most a half-sentence aside ("still on it \u2014 running tests now") and end your turn. Never present progress as a finished result.\nCRITICAL: while a task is still running you have NO answer yet \u2014 never state a specific result of any kind (a number, size, count, name, path, or value). The real answer arrives ONLY in the "[task \u2026 completed]" event; inventing one meanwhile (a made-up disk size, commit count, etc.) is a serious error. Until then, only acknowledge and wait.\nNever read raw file paths, diffs, or code aloud verbatim.\n"[task t1 asks] \u2026" events are QUESTIONS from a background task \u2014 relay to the user in your own words, short, then end your turn. When the user answers, call `AnswerTask` with that id and their answer. NEVER answer on the user\'s behalf for permissions or risky operations; if their reply is ambiguous, confirm first.\nIf the user\'s message sounds INCOMPLETE \u2014 trailing off mid-sentence, a fragment that needs more context ("and then we", "but the problem is"), hesitation fillers ("uh", "um") \u2014 call `Hold` instead of answering. This keeps listening for the rest of their thought. Only respond with substance when you have a complete question or request.\nDispatch discipline: send ONE self-contained task per request \u2014 a single worker with the full brief beats several workers with fragments (each worker starts fresh and re-discovers context). NEVER dispatch a worker just to read files or gather information \u2014 workers explore and discover context themselves; pass on what you already know and let one worker do the whole job. Split into parallel tasks only when the user asks for genuinely independent things. When a task completes, report its result and stop \u2014 do NOT dispatch follow-up work (verification, polish, extras) the user did not ask for, unless the report itself signals failure or doubt.\nDo not fire a second Act/Think for work already in flight, and NEVER spawn a second task to re-count, cross-check, or verify a result a worker already gave you \u2014 trust its answer; a single question gets ONE task. Call `TaskStatus` at most ONCE per turn; if a task is still running, just say "still on it" and end the turn \u2014 never poll it again and again in a loop. Use `CancelTask` when the user asks to stop something.\nPRIORITY: when the user says goodbye or wants to end/finish/wrap up the session ("ok bye", "that\'s all", "let\'s finish", "let\'s end", "goodnight", "exit", "wrap up"), call `ExitSession` IMMEDIATELY \u2014 do not act, do not check status, just exit.\nFor TRIVIAL instant lookups only \u2014 current time, git branch, listing a folder, peeking at a small file, or checking your own `capabilities`/tools \u2014 use `QuickLook` (instant, no task). Whenever the user asks what you can do or whether you have some ability, QuickLook `capabilities` and answer from that \u2014 never guess. Anything requiring searching, reasoning, running commands, or editing goes through `Act`.\n{{MEMORY_SLOT}}\nUser messages may arrive via speech-to-text and can carry transcription artifacts \u2014 odd words, cut-offs, homophones ("for you" vs "folder"). Read for INTENT, not surface text. If a message seems garbled or surprising, briefly confirm what they meant ("did you mean\u2026?") instead of answering the literal words.';
3771
3772
  var THINK_GUIDANCE = "\u2022 `Think` \u2014 your brain. A premium reasoning model, FAR more expensive than Act. Reserve it for open-ended architecture/design questions, or a problem Act already FAILED at. ALL implementation work \u2014 coding, refactoring, debugging, edge cases, tests \u2014 goes to Act; Act is highly capable. Never send the same work to both.";
3772
3773
  var THINK_DISABLED_GUIDANCE = "(Think tier is not available \u2014 use Act for all escalations.)";
@@ -3790,6 +3791,12 @@ var DuplexAgent = class {
3790
3791
  // any non-empty text_delta streamed this turn
3791
3792
  nudging = false;
3792
3793
  // re-ack pass in flight: block ALL tools, prevent recursion
3794
+ reflexBuf = "";
3795
+ // accumulated reflex text this turn (fabricated-event detection)
3796
+ reflexForwarded = 0;
3797
+ // chars of reflexBuf already forwarded to the host/TTS
3798
+ fabricationCut = false;
3799
+ // reflex emitted a reserved [task …] marker → suppress its tail
3793
3800
  /** Parked worker questions awaiting a (voice-relayed) user answer, keyed by ask id. */
3794
3801
  pendingAsks = /* @__PURE__ */ new Map();
3795
3802
  /** Lazily resolved memory tools (async loadMemory runs in initMemory). */
@@ -3828,7 +3835,23 @@ Today's date: ${(/* @__PURE__ */ new Date()).toDateString()}.`;
3828
3835
  ask: host.ask ? (q2) => host.ask(q2) : void 0,
3829
3836
  confirm: host.confirm ? (p, m) => host.confirm(p, m) : void 0,
3830
3837
  notify: (ev) => {
3831
- if (ev?.kind === "text_delta" && typeof ev.message === "string" && ev.message.trim()) this.spokeThisTurn = true;
3838
+ if (ev?.kind === "text_delta" && typeof ev.message === "string") {
3839
+ if (this.fabricationCut) return;
3840
+ const msg = ev.message;
3841
+ this.reflexBuf += msg;
3842
+ const m = this.reflexBuf.match(RESERVED_EVENT_MARKER);
3843
+ if (m) {
3844
+ this.fabricationCut = true;
3845
+ log7.warn(`reflex fabricated a [task \u2026] event in its spoken stream \u2014 cutting it (kept ${m.index} chars)`);
3846
+ const safe = this.reflexBuf.slice(this.reflexForwarded, m.index);
3847
+ if (!safe) return;
3848
+ if (safe.trim()) this.spokeThisTurn = true;
3849
+ host.notify?.({ ...ev, message: safe });
3850
+ return;
3851
+ }
3852
+ this.reflexForwarded = this.reflexBuf.length;
3853
+ if (msg.trim()) this.spokeThisTurn = true;
3854
+ }
3832
3855
  host.notify?.(ev);
3833
3856
  }
3834
3857
  };
@@ -3865,6 +3888,9 @@ Today's date: ${(/* @__PURE__ */ new Date()).toDateString()}.`;
3865
3888
  this.turnDispatched = false;
3866
3889
  this.turnBriefs.clear();
3867
3890
  this.spokeThisTurn = false;
3891
+ this.reflexBuf = "";
3892
+ this.reflexForwarded = 0;
3893
+ this.fabricationCut = false;
3868
3894
  this.voice.options.toolChoice = void 0;
3869
3895
  }
3870
3896
  /** preToolUse guard on the reflex: once it has dispatched this turn, a dispatch is "said my piece,
@@ -9078,6 +9104,47 @@ async function repl(args, ai, cfg, cwd) {
9078
9104
  persistModel(cwd, m);
9079
9105
  err(dim(" model \u2192 " + m + "\n"));
9080
9106
  };
9107
+ const applyReflexModel = (id) => {
9108
+ const m = resolveModelOrNewest(id);
9109
+ dx.options.reflexModel = m;
9110
+ dx.voice.options.model = m;
9111
+ err(green(` \u2713 reflex model \u2192 ${m}
9112
+ `));
9113
+ };
9114
+ const applyThinkModel = (id) => {
9115
+ const m = resolveModelOrNewest(id);
9116
+ dx.setThinkModel(m);
9117
+ err(green(` \u2713 think model \u2192 ${m}
9118
+ `));
9119
+ };
9120
+ const pickModelByTier = async () => {
9121
+ const thinkLabel = dx.options.thinkModel === false ? "off" : String(dx.options.thinkModel);
9122
+ const tier = await selectMenu(process.stderr, { title: "Set model for which tier?", items: [
9123
+ { label: "Reflex (voice)", value: "reflex", desc: dx.options.reflexModel },
9124
+ { label: "Act (worker)", value: "act", desc: work.model },
9125
+ { label: "Think", value: "think", desc: thinkLabel }
9126
+ ] });
9127
+ if (!tier) return;
9128
+ if (tier === "think") {
9129
+ const sub = await selectMenu(process.stderr, { title: "Think tier", items: [
9130
+ { label: "Choose a model\u2026", value: "__pick__", desc: thinkLabel === "off" ? "currently off" : `current: ${thinkLabel}` },
9131
+ { label: "Disable Think tier", value: "__off__" }
9132
+ ] });
9133
+ if (!sub) return;
9134
+ if (sub === "__off__") {
9135
+ dx.setThinkModel(false);
9136
+ err(green(" \u2713 think tier disabled\n"));
9137
+ return;
9138
+ }
9139
+ const picked2 = await pickModel(dx.options.thinkModel === false ? "anthropic/claude-opus-4-6" : String(dx.options.thinkModel));
9140
+ if (picked2) applyThinkModel(picked2);
9141
+ return;
9142
+ }
9143
+ const picked = await pickModel(tier === "reflex" ? dx.options.reflexModel : work.model);
9144
+ if (!picked) return;
9145
+ if (tier === "reflex") applyReflexModel(picked);
9146
+ else setModel(picked);
9147
+ };
9081
9148
  const addWorkTools = (ts) => {
9082
9149
  if (duplex) work.tools = [...work.tools ?? [], ...ts];
9083
9150
  else agent.addTools(ts);
@@ -9454,15 +9521,19 @@ ${extra}` : body);
9454
9521
  }
9455
9522
  },
9456
9523
  model: {
9457
- desc: "switch model \u2014 /model <id>, or /model alone for an interactive picker (duplex: the worker model)",
9524
+ desc: "switch model \u2014 /model <id> (duplex: the worker), or /model alone for a picker (duplex: pick a tier first)",
9458
9525
  run: async (a) => {
9459
9526
  if (a[0]) {
9460
9527
  setModel(a[0]);
9461
9528
  return;
9462
9529
  }
9530
+ if (duplex) {
9531
+ await pickModelByTier();
9532
+ return;
9533
+ }
9463
9534
  const picked = await pickModel(work.model);
9464
9535
  if (picked) setModel(picked);
9465
- else err(dim(" " + (duplex ? `reflex ${dx.options.reflexModel} \xB7 act ${work.model}${dx.options.thinkModel !== false ? ` \xB7 think ${dx.options.thinkModel}` : ""}` : work.model) + "\n"));
9536
+ else err(dim(" " + work.model + "\n"));
9466
9537
  }
9467
9538
  },
9468
9539
  ...duplex ? { workers: {
@@ -9489,19 +9560,12 @@ ${extra}` : body);
9489
9560
  }, "voice-model": {
9490
9561
  desc: "switch the reflex (voice) model \u2014 /voice-model <id>, or alone for a picker",
9491
9562
  run: async (a) => {
9492
- const apply = (id) => {
9493
- const m = resolveModelOrNewest(id);
9494
- dx.options.reflexModel = m;
9495
- dx.voice.options.model = m;
9496
- err(green(` \u2713 reflex model \u2192 ${m}
9497
- `));
9498
- };
9499
9563
  if (a[0]) {
9500
- apply(a[0]);
9564
+ applyReflexModel(a[0]);
9501
9565
  return;
9502
9566
  }
9503
9567
  const picked = await pickModel(dx.options.reflexModel);
9504
- if (picked) apply(picked);
9568
+ if (picked) applyReflexModel(picked);
9505
9569
  else err(dim(` reflex ${dx.options.reflexModel}
9506
9570
  `));
9507
9571
  }
@@ -9514,19 +9578,13 @@ ${extra}` : body);
9514
9578
  `));
9515
9579
  return;
9516
9580
  }
9517
- const apply = (id) => {
9518
- const m = resolveModelOrNewest(id);
9519
- dx.setThinkModel(m);
9520
- err(green(` \u2713 think model \u2192 ${m}
9521
- `));
9522
- };
9523
9581
  if (a[0]) {
9524
- apply(a[0]);
9582
+ applyThinkModel(a[0]);
9525
9583
  return;
9526
9584
  }
9527
9585
  const current = dx.options.thinkModel === false ? void 0 : dx.options.thinkModel;
9528
9586
  const picked = await pickModel(current ?? "anthropic/claude-opus-4-6");
9529
- if (picked) apply(picked);
9587
+ if (picked) applyThinkModel(picked);
9530
9588
  else err(dim(` think ${dx.options.thinkModel === false ? "off" : dx.options.thinkModel}
9531
9589
  `));
9532
9590
  }