@hyperwindmill/caretaker-cli 0.16.0 → 0.17.0

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.
@@ -18492,27 +18492,33 @@ ${text}</tr>
18492
18492
  if (event.mode === "dictate") return "idle";
18493
18493
  return event.empty ? "recording" : "awaiting";
18494
18494
  case "awaiting":
18495
+ if (event.kind === "speechQueued") return event.canSpeak ? "speaking" : phase;
18495
18496
  if (event.kind !== "turnFinished") return phase;
18497
+ if (event.pendingSpeech > 0 && event.canSpeak) return "speaking";
18496
18498
  if (!event.turnComplete) return phase;
18497
18499
  if (!event.sawStreaming) return phase;
18498
18500
  if (event.confirmPending) return phase;
18499
18501
  return event.canSpeak ? "speaking" : "recording";
18500
18502
  case "speaking":
18501
- return event.kind === "playbackEnded" ? "recording" : phase;
18503
+ if (event.kind === "playbackEnded") return event.turnComplete ? "recording" : "awaiting";
18504
+ return phase;
18502
18505
  }
18503
18506
  }
18504
18507
  function stripMarkdownForSpeech(md) {
18505
18508
  return md.replace(/```[\s\S]*?```\n?/g, "").replace(/`([^`]+)`/g, "$1").replace(/!\[[^\]]*\]\([^)]*\)/g, "").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/^#{1,6}\s+/gm, "").replace(/^\s*[-*+]\s+/gm, "").replace(/\*\*([^*]+)\*\*/g, "$1").replace(/\*([^*]+)\*/g, "$1").replace(/_([^_]+)_/g, "$1").replace(/\n{3,}/g, "\n\n").trim();
18506
18509
  }
18507
- function lastSpokenText(items) {
18508
- for (let i = items.length - 1; i >= 0; i -= 1) {
18509
- const item = items[i];
18510
- if (item.kind !== "assistant") continue;
18511
- if (item.streaming) continue;
18512
- const text = (item.text ?? "").trim();
18513
- return text.length > 0 ? text : null;
18510
+ function isFinal(items, i) {
18511
+ return i < items.length - 1 || items[i].streaming !== true;
18512
+ }
18513
+ function takeFinalizedBubbles(items, cursor) {
18514
+ const texts = [];
18515
+ let i = Math.max(0, Math.min(cursor, items.length));
18516
+ for (; i < items.length && isFinal(items, i); i += 1) {
18517
+ if (items[i].kind !== "assistant") continue;
18518
+ const text = (items[i].text ?? "").trim();
18519
+ if (text) texts.push(text);
18514
18520
  }
18515
- return null;
18521
+ return { texts, cursor: i };
18516
18522
  }
18517
18523
  function voiceSignature(v) {
18518
18524
  if (!v) return "";
@@ -19579,6 +19585,25 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
19579
19585
  setTaskError("Failed to update task setting");
19580
19586
  }
19581
19587
  };
19588
+ const handleSaveTaskDetails = async (task, title, objective) => {
19589
+ setTaskError(null);
19590
+ try {
19591
+ const res = await fetch(`/api/tasks/${task.id}`, {
19592
+ method: "PATCH",
19593
+ headers: { "Content-Type": "application/json" },
19594
+ body: JSON.stringify({ title, objective })
19595
+ });
19596
+ if (res.ok) {
19597
+ if (selectedProjectId !== null) fetchTasks(selectedProjectId);
19598
+ } else {
19599
+ const data = await res.json().catch(() => ({}));
19600
+ setTaskError(data.error || "Failed to save task details");
19601
+ }
19602
+ } catch (err) {
19603
+ console.error("Failed to save task details:", err);
19604
+ setTaskError("Failed to save task details");
19605
+ }
19606
+ };
19582
19607
  const backToList = () => {
19583
19608
  setView("list");
19584
19609
  setSelectedTaskId(null);
@@ -19676,6 +19701,7 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
19676
19701
  onSetAgent: handleSetTaskAgent,
19677
19702
  onSetFlag: handleSetTaskFlag,
19678
19703
  onSetMaxRun: handleSetTaskMaxRun,
19704
+ onSaveDetails: handleSaveTaskDetails,
19679
19705
  onOpenLog: () => setView("log"),
19680
19706
  statusColor
19681
19707
  }
@@ -20265,19 +20291,60 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20265
20291
  onSetAgent,
20266
20292
  onSetFlag,
20267
20293
  onSetMaxRun,
20294
+ onSaveDetails,
20268
20295
  onOpenLog,
20269
20296
  statusColor
20270
20297
  }) {
20271
20298
  const isRunning = task.status === "active" || task.status === "reviewing" || task.status === "planning";
20299
+ const [draftTitle, setDraftTitle] = (0, import_react14.useState)(task.title);
20300
+ const [draftObjective, setDraftObjective] = (0, import_react14.useState)(task.objective);
20301
+ const [lastTaskId, setLastTaskId] = (0, import_react14.useState)(task.id);
20302
+ const trimmedTitle = draftTitle.trim();
20303
+ const isDirty = trimmedTitle !== task.title.trim() || draftObjective.trim() !== task.objective.trim();
20304
+ (0, import_react14.useEffect)(() => {
20305
+ if (task.id !== lastTaskId) {
20306
+ setDraftTitle(task.title);
20307
+ setDraftObjective(task.objective);
20308
+ setLastTaskId(task.id);
20309
+ } else if (!isDirty) {
20310
+ setDraftTitle(task.title);
20311
+ setDraftObjective(task.objective);
20312
+ }
20313
+ }, [task.id, task.title, task.objective]);
20314
+ const canSave = isDirty && trimmedTitle.length > 0;
20315
+ const resetDraft = () => {
20316
+ setDraftTitle(task.title);
20317
+ setDraftObjective(task.objective);
20318
+ };
20272
20319
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { style: { flex: 1, display: "flex", flexDirection: "column", height: "100%", overflowY: "auto" }, children: [
20273
20320
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "task-view__sub-header", style: { padding: "12px 14px", display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
20274
20321
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "10px" }, children: [
20275
20322
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { className: "settings-panel__back-btn", onClick: onBack, title: "Back to task list", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ArrowLeft, { size: 13 }) }),
20276
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("h3", { style: { margin: 0, fontSize: "15px", fontWeight: 700 }, children: [
20277
- "Task #",
20278
- task.id,
20279
- ": ",
20280
- task.title
20323
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("h3", { style: { margin: 0, fontSize: "15px", fontWeight: 700, display: "flex", alignItems: "center", gap: "6px" }, children: [
20324
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { style: { opacity: 0.6 }, children: [
20325
+ "Task #",
20326
+ task.id
20327
+ ] }),
20328
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
20329
+ "input",
20330
+ {
20331
+ value: draftTitle,
20332
+ onChange: (e) => setDraftTitle(e.target.value),
20333
+ "aria-label": "Task title",
20334
+ title: "Task title",
20335
+ style: {
20336
+ background: "var(--vscode-input-background, #252526)",
20337
+ color: "var(--vscode-input-foreground)",
20338
+ border: "1px solid var(--vscode-input-border, #3c3c3c)",
20339
+ borderRadius: "4px",
20340
+ padding: "3px 6px",
20341
+ fontSize: "14px",
20342
+ fontWeight: 700,
20343
+ outline: "none",
20344
+ minWidth: "240px"
20345
+ }
20346
+ }
20347
+ )
20281
20348
  ] }),
20282
20349
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
20283
20350
  "span",
@@ -20364,7 +20431,47 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20364
20431
  ] }),
20365
20432
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { style: { marginBottom: "16px" }, children: [
20366
20433
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("h4", { style: { margin: "0 0 6px 0", fontSize: "10px", textTransform: "uppercase", letterSpacing: "0.08em", opacity: 0.6 }, children: "Objective" }),
20367
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { style: { fontSize: "12px", background: "rgba(255,255,255,0.02)", padding: "10px", borderRadius: "6px", border: "1px solid rgba(255,255,255,0.05)", whiteSpace: "pre-wrap" }, children: task.objective })
20434
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
20435
+ "textarea",
20436
+ {
20437
+ value: draftObjective,
20438
+ onChange: (e) => setDraftObjective(e.target.value),
20439
+ rows: 6,
20440
+ "aria-label": "Task objective",
20441
+ title: "What the agent should achieve. Read at the start of every cycle, so an edit applies from the next one.",
20442
+ style: {
20443
+ width: "100%",
20444
+ boxSizing: "border-box",
20445
+ fontSize: "12px",
20446
+ fontFamily: "inherit",
20447
+ lineHeight: 1.5,
20448
+ background: "var(--vscode-input-background, #252526)",
20449
+ color: "var(--vscode-input-foreground)",
20450
+ border: "1px solid var(--vscode-input-border, #3c3c3c)",
20451
+ borderRadius: "6px",
20452
+ padding: "10px",
20453
+ outline: "none",
20454
+ resize: "vertical"
20455
+ }
20456
+ }
20457
+ ),
20458
+ isDirty && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { style: { display: "flex", gap: "6px", alignItems: "center", marginTop: "8px" }, children: [
20459
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
20460
+ "button",
20461
+ {
20462
+ className: "confirm__btn confirm__btn--primary",
20463
+ onClick: () => {
20464
+ void onSaveDetails(task, trimmedTitle, draftObjective.trim());
20465
+ },
20466
+ disabled: !canSave,
20467
+ title: canSave ? "Save title and objective" : "The title cannot be empty",
20468
+ style: { padding: "3px 10px", fontSize: "10px" },
20469
+ children: "Save"
20470
+ }
20471
+ ),
20472
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { className: "confirm__btn", onClick: resetDraft, style: { padding: "3px 10px", fontSize: "10px" }, children: "Cancel" }),
20473
+ isRunning && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { style: { fontSize: "10px", opacity: 0.6 }, children: "Applies from the next cycle." })
20474
+ ] })
20368
20475
  ] }),
20369
20476
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { style: { marginBottom: "16px" }, children: [
20370
20477
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("h4", { style: { margin: "0 0 6px 0", fontSize: "10px", textTransform: "uppercase", letterSpacing: "0.08em", opacity: 0.6 }, children: "Assigned Agent" }),
@@ -20589,6 +20696,8 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20589
20696
  onTranscriptRef.current = onTranscript;
20590
20697
  const itemsRef = (0, import_react15.useRef)(items);
20591
20698
  itemsRef.current = items;
20699
+ const chatStatusRef = (0, import_react15.useRef)(chatStatus);
20700
+ chatStatusRef.current = chatStatus;
20592
20701
  const streamRef = (0, import_react15.useRef)(null);
20593
20702
  const recorderRef = (0, import_react15.useRef)(null);
20594
20703
  const chunksRef = (0, import_react15.useRef)([]);
@@ -20597,7 +20706,8 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20597
20706
  const idleTimerRef = (0, import_react15.useRef)(null);
20598
20707
  const heardSpeechRef = (0, import_react15.useRef)(false);
20599
20708
  const sawStreamingRef = (0, import_react15.useRef)(false);
20600
- const spokenBaselineRef = (0, import_react15.useRef)(null);
20709
+ const cursorRef = (0, import_react15.useRef)(0);
20710
+ const queueRef = (0, import_react15.useRef)([]);
20601
20711
  const apply = (0, import_react15.useCallback)((event) => {
20602
20712
  setPhase((current) => nextPhase(current, event));
20603
20713
  }, []);
@@ -20655,7 +20765,8 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20655
20765
  if (trimmed) {
20656
20766
  if (currentMode === "conversation") {
20657
20767
  sawStreamingRef.current = false;
20658
- spokenBaselineRef.current = lastSpokenText(itemsRef.current);
20768
+ cursorRef.current = itemsRef.current.length;
20769
+ queueRef.current = [];
20659
20770
  }
20660
20771
  onTranscriptRef.current(trimmed, currentMode);
20661
20772
  }
@@ -20712,9 +20823,13 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20712
20823
  }
20713
20824
  }, [apply, fail, finishRecording, teardownCapture]);
20714
20825
  const speakReply = (0, import_react15.useCallback)(async () => {
20715
- const text = lastSpokenText(itemsRef.current);
20716
- if (!text || text === spokenBaselineRef.current) {
20717
- apply({ kind: "playbackEnded", mode: "conversation" });
20826
+ const text = queueRef.current.shift();
20827
+ if (!text) {
20828
+ apply({
20829
+ kind: "playbackEnded",
20830
+ mode: "conversation",
20831
+ turnComplete: chatStatusRef.current === "idle"
20832
+ });
20718
20833
  return;
20719
20834
  }
20720
20835
  try {
@@ -20730,7 +20845,17 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20730
20845
  audio.onended = () => {
20731
20846
  URL.revokeObjectURL(url);
20732
20847
  audioRef.current = null;
20733
- setTimeout(() => apply({ kind: "playbackEnded", mode: "conversation" }), POST_PLAYBACK_MS);
20848
+ setTimeout(() => {
20849
+ if (queueRef.current.length > 0) {
20850
+ void speakReply();
20851
+ } else {
20852
+ apply({
20853
+ kind: "playbackEnded",
20854
+ mode: "conversation",
20855
+ turnComplete: chatStatusRef.current === "idle"
20856
+ });
20857
+ }
20858
+ }, POST_PLAYBACK_MS);
20734
20859
  };
20735
20860
  audio.onerror = () => {
20736
20861
  URL.revokeObjectURL(url);
@@ -20744,6 +20869,15 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20744
20869
  (0, import_react15.useEffect)(() => {
20745
20870
  if (chatStatus === "streaming") sawStreamingRef.current = true;
20746
20871
  }, [chatStatus]);
20872
+ (0, import_react15.useEffect)(() => {
20873
+ if (modeRef.current !== "conversation") return;
20874
+ if (phaseRef.current === "idle") return;
20875
+ const { texts, cursor } = takeFinalizedBubbles(items, cursorRef.current);
20876
+ cursorRef.current = cursor;
20877
+ if (texts.length === 0) return;
20878
+ queueRef.current.push(...texts);
20879
+ apply({ kind: "speechQueued", mode: "conversation", canSpeak });
20880
+ }, [items, canSpeak, apply]);
20747
20881
  (0, import_react15.useEffect)(() => {
20748
20882
  if (phase !== "awaiting") return;
20749
20883
  if (chatStatus === "error") {
@@ -20759,7 +20893,11 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20759
20893
  // the loop advances mid-stream and speaks the previous reply.
20760
20894
  turnComplete: chatStatus === "idle",
20761
20895
  sawStreaming: sawStreamingRef.current,
20762
- confirmPending: pendingConfirmCount > 0
20896
+ confirmPending: pendingConfirmCount > 0,
20897
+ // Text queued but not yet played. Non-zero drives awaiting → speaking
20898
+ // regardless of turnComplete, so a bubble closed in the same commit as
20899
+ // the turn ending is never lost to effect ordering.
20900
+ pendingSpeech: queueRef.current.length
20763
20901
  });
20764
20902
  }, [phase, chatStatus, pendingConfirmCount, canSpeak, apply]);
20765
20903
  const prevPhase = (0, import_react15.useRef)("idle");
@@ -20772,6 +20910,7 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
20772
20910
  if (phase === "idle") {
20773
20911
  teardownCapture();
20774
20912
  stopPlayback();
20913
+ queueRef.current = [];
20775
20914
  }
20776
20915
  }, [phase, startRecording, speakReply, teardownCapture, stopPlayback]);
20777
20916
  (0, import_react15.useEffect)(
@@ -21083,11 +21222,11 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
21083
21222
  pendingConfirmCount: chatState.pendingConfirms.length,
21084
21223
  items: chatState.items,
21085
21224
  onTranscript: (text, mode) => {
21086
- if (mode === "conversation") onSend(text);
21225
+ if (mode === "conversation") onSend(text, void 0, true);
21087
21226
  else setComposerDraft((draft) => draft ? `${draft} ${text}` : text);
21088
21227
  }
21089
21228
  });
21090
- const onSend = (text, attachments) => {
21229
+ const onSend = (text, attachments, voice2) => {
21091
21230
  const trimmed = text.trim();
21092
21231
  if (!trimmed && (!attachments || attachments.length === 0)) return;
21093
21232
  if (chatState.status === "streaming") return;
@@ -21098,7 +21237,9 @@ ${msg.content}`, streaming: false, label: msg.agentLabel || labels?.reviewer });
21098
21237
  base64: att.base64
21099
21238
  }));
21100
21239
  dispatch({ kind: "send-user", text: trimmed, attachments: localAttachments });
21101
- postMessage({ type: "start", prompt: trimmed, attachments });
21240
+ const msg = { type: "start", prompt: trimmed, attachments };
21241
+ if (voice2) msg.voice = true;
21242
+ postMessage(msg);
21102
21243
  };
21103
21244
  const onConfirm = (id, decision) => {
21104
21245
  dispatch({ kind: "permission-resolved", id });