@sideboard-ai/core 0.1.310 → 0.1.311

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.
@@ -18,6 +18,7 @@ import {
18
18
  import {
19
19
  REVIEW_TAB_TITLE,
20
20
  applyWorktreePkgCacheEnv,
21
+ askBlockStillWaiting,
21
22
  buildBrightsySessionSeed,
22
23
  buildForkTranscriptAttachment,
23
24
  buildSessionSeed,
@@ -55,7 +56,7 @@ import {
55
56
  worktreeDevProcessKey,
56
57
  worktreeRunProcessKey,
57
58
  worktreeSetupProcessKey
58
- } from "./chunk-VBVSJUM2.js";
59
+ } from "./chunk-QC2TQMPJ.js";
59
60
  import {
60
61
  applyAgentEvent,
61
62
  clipAgentEventForPaint,
@@ -1643,6 +1644,11 @@ function visibleAgentBlock(thread) {
1643
1644
  const block = thread.agentBlock;
1644
1645
  if (!block?.reason?.trim()) return null;
1645
1646
  if (isDismissedAskUserBlock(block, thread.dismissedQuestionSignature)) return null;
1647
+ if (block.source === "ask_user") {
1648
+ const inFlight = thread.status === "running" || thread.status === "queued";
1649
+ if (inFlight && !block.onScreen) return null;
1650
+ if (!askBlockStillWaiting(block, thread.messages)) return null;
1651
+ }
1646
1652
  return block;
1647
1653
  }
1648
1654
  function worktreeAgentBlock(group) {
@@ -1817,6 +1823,7 @@ function decisionBlockFromParts(parts, planMode, at = (/* @__PURE__ */ new Date(
1817
1823
  const reason = pending ? formatAskUserNotifyMessage(pending.questions) : "Waiting for an answer in that chat.";
1818
1824
  return {
1819
1825
  ...makeAgentBlock("ask_user", reason, at),
1826
+ onScreen: true,
1820
1827
  ...pending ? { questionSignature: pending.signature, questions: pending.questions } : {}
1821
1828
  };
1822
1829
  }
@@ -1874,6 +1881,38 @@ function dismissAskUserQuestion(threadId, signature) {
1874
1881
  ...clearBlock ? { agentBlock: null } : {}
1875
1882
  });
1876
1883
  }
1884
+ function askBlocksEqual(a, b) {
1885
+ if (a === b) return true;
1886
+ if (!a || !b) return false;
1887
+ return a.source === b.source && a.reason === b.reason && a.at === b.at && a.onScreen === b.onScreen && a.questionSignature === b.questionSignature;
1888
+ }
1889
+ function askBlockAfterLiveParts(existing, parts) {
1890
+ const last = lastTopLevelTool(parts);
1891
+ if (last?.type === "tool" && isAskUserToolName(last.name)) {
1892
+ if (existing?.source === "ask_user" && existing.onScreen) return existing;
1893
+ const pending = extractPendingPlanQuestions(parts);
1894
+ const questions = pending?.questions ?? existing?.questions;
1895
+ if (!questions?.length) {
1896
+ return existing?.source === "ask_user" ? { ...existing, onScreen: true } : existing ?? null;
1897
+ }
1898
+ const at = existing?.source === "ask_user" ? existing.at : void 0;
1899
+ return {
1900
+ ...makeAgentBlock("ask_user", formatAskUserNotifyMessage(questions), at),
1901
+ onScreen: true,
1902
+ questionSignature: pending?.signature ?? existing?.questionSignature,
1903
+ questions
1904
+ };
1905
+ }
1906
+ if (last && existing?.source === "ask_user") return null;
1907
+ return existing ?? null;
1908
+ }
1909
+ function syncAskUserBlockFromLive(threadId, parts) {
1910
+ const thread = readThread(threadId);
1911
+ if (!thread || thread.status === "archived") return;
1912
+ const next = askBlockAfterLiveParts(thread.agentBlock, parts);
1913
+ if (askBlocksEqual(thread.agentBlock, next)) return;
1914
+ updateThread(threadId, { agentBlock: next });
1915
+ }
1877
1916
  function writeAgentBlock(threadId, block) {
1878
1917
  const thread = readThread(threadId);
1879
1918
  if (!thread || thread.status === "archived") return;
@@ -3419,6 +3458,7 @@ function noteTurnLiveEvent(threadId, event) {
3419
3458
  const prev = buffers.get(threadId) ?? { parts: [], timer: null };
3420
3459
  prev.parts = trimParts(applyAgentEvent(prev.parts, event));
3421
3460
  buffers.set(threadId, prev);
3461
+ syncAskUserBlockFromLive(threadId, prev.parts);
3422
3462
  if (event.type === "exit") {
3423
3463
  flush(threadId);
3424
3464
  const cur = buffers.get(threadId);
@@ -6741,7 +6781,7 @@ function formatScheduledPrompt(name, prompt) {
6741
6781
  ${prompt}`;
6742
6782
  }
6743
6783
  async function defaultDeps() {
6744
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-XFE3U3RP.js");
6784
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-2CCFGYAA.js");
6745
6785
  const orch = getOrchestrator2();
6746
6786
  return {
6747
6787
  findThread: (id) => findThreadByRef(id),
@@ -31,6 +31,7 @@ import {
31
31
  import {
32
32
  REVIEW_TAB_TITLE,
33
33
  applyWorktreePkgCacheEnv,
34
+ askBlockStillWaiting,
34
35
  buildBrightsySessionSeed,
35
36
  buildForkTranscriptAttachment,
36
37
  buildSessionSeed,
@@ -68,7 +69,7 @@ import {
68
69
  worktreeDevProcessKey,
69
70
  worktreeRunProcessKey,
70
71
  worktreeSetupProcessKey
71
- } from "./chunk-AILQRQ26.js";
72
+ } from "./chunk-ZW7RSQHY.js";
72
73
  import {
73
74
  applyAgentEvent,
74
75
  clipAgentEventForPaint,
@@ -1546,6 +1547,11 @@ function visibleAgentBlock(thread) {
1546
1547
  const block = thread.agentBlock;
1547
1548
  if (!block?.reason?.trim()) return null;
1548
1549
  if (isDismissedAskUserBlock(block, thread.dismissedQuestionSignature)) return null;
1550
+ if (block.source === "ask_user") {
1551
+ const inFlight = thread.status === "running" || thread.status === "queued";
1552
+ if (inFlight && !block.onScreen) return null;
1553
+ if (!askBlockStillWaiting(block, thread.messages)) return null;
1554
+ }
1549
1555
  return block;
1550
1556
  }
1551
1557
  function worktreeAgentBlock(group) {
@@ -1703,6 +1709,7 @@ function decisionBlockFromParts(parts, planMode, at = (/* @__PURE__ */ new Date(
1703
1709
  const reason = pending ? formatAskUserNotifyMessage(pending.questions) : "Waiting for an answer in that chat.";
1704
1710
  return {
1705
1711
  ...makeAgentBlock("ask_user", reason, at),
1712
+ onScreen: true,
1706
1713
  ...pending ? { questionSignature: pending.signature, questions: pending.questions } : {}
1707
1714
  };
1708
1715
  }
@@ -1760,6 +1767,38 @@ function dismissAskUserQuestion(threadId, signature) {
1760
1767
  ...clearBlock ? { agentBlock: null } : {}
1761
1768
  });
1762
1769
  }
1770
+ function askBlocksEqual(a, b) {
1771
+ if (a === b) return true;
1772
+ if (!a || !b) return false;
1773
+ return a.source === b.source && a.reason === b.reason && a.at === b.at && a.onScreen === b.onScreen && a.questionSignature === b.questionSignature;
1774
+ }
1775
+ function askBlockAfterLiveParts(existing, parts) {
1776
+ const last = lastTopLevelTool(parts);
1777
+ if (last?.type === "tool" && isAskUserToolName(last.name)) {
1778
+ if (existing?.source === "ask_user" && existing.onScreen) return existing;
1779
+ const pending = extractPendingPlanQuestions(parts);
1780
+ const questions = pending?.questions ?? existing?.questions;
1781
+ if (!questions?.length) {
1782
+ return existing?.source === "ask_user" ? { ...existing, onScreen: true } : existing ?? null;
1783
+ }
1784
+ const at = existing?.source === "ask_user" ? existing.at : void 0;
1785
+ return {
1786
+ ...makeAgentBlock("ask_user", formatAskUserNotifyMessage(questions), at),
1787
+ onScreen: true,
1788
+ questionSignature: pending?.signature ?? existing?.questionSignature,
1789
+ questions
1790
+ };
1791
+ }
1792
+ if (last && existing?.source === "ask_user") return null;
1793
+ return existing ?? null;
1794
+ }
1795
+ function syncAskUserBlockFromLive(threadId, parts) {
1796
+ const thread = readThread(threadId);
1797
+ if (!thread || thread.status === "archived") return;
1798
+ const next = askBlockAfterLiveParts(thread.agentBlock, parts);
1799
+ if (askBlocksEqual(thread.agentBlock, next)) return;
1800
+ updateThread(threadId, { agentBlock: next });
1801
+ }
1763
1802
  function writeAgentBlock(threadId, block) {
1764
1803
  const thread = readThread(threadId);
1765
1804
  if (!thread || thread.status === "archived") return;
@@ -3117,6 +3156,7 @@ function noteTurnLiveEvent(threadId, event) {
3117
3156
  const prev = buffers.get(threadId) ?? { parts: [], timer: null };
3118
3157
  prev.parts = trimParts(applyAgentEvent(prev.parts, event));
3119
3158
  buffers.set(threadId, prev);
3159
+ syncAskUserBlockFromLive(threadId, prev.parts);
3120
3160
  if (event.type === "exit") {
3121
3161
  flush(threadId);
3122
3162
  const cur = buffers.get(threadId);
@@ -6389,7 +6429,7 @@ function formatScheduledPrompt(name, prompt) {
6389
6429
  ${prompt}`;
6390
6430
  }
6391
6431
  async function defaultDeps() {
6392
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-7374OI7T.js");
6432
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-3W5S6TNP.js");
6393
6433
  const orch = getOrchestrator2();
6394
6434
  return {
6395
6435
  findThread: (id) => findThreadByRef(id),
@@ -1288,6 +1288,19 @@ function isAskUserToolName(name) {
1288
1288
  const base = name.replace(/^mcp__sideboard__/i, "");
1289
1289
  return ASK_USER_TOOL_RE.test(name) || /^ask_user$/i.test(base);
1290
1290
  }
1291
+ function lastTopLevelToolIsAskUser(parts) {
1292
+ if (!parts?.length) return false;
1293
+ for (let i = parts.length - 1; i >= 0; i--) {
1294
+ const part = parts[i];
1295
+ if (part.type === "tool" && !part.parentId) {
1296
+ return isAskUserToolName(part.name);
1297
+ }
1298
+ }
1299
+ return false;
1300
+ }
1301
+ function hasTopLevelTool(parts) {
1302
+ return Boolean(parts?.some((part) => part.type === "tool" && !part.parentId));
1303
+ }
1291
1304
  function questionsFromToolPart(part) {
1292
1305
  const fromInput = parsePlanQuestionsInput(part.input);
1293
1306
  if (fromInput.length) return fromInput;
@@ -1330,6 +1343,7 @@ function pendingFromAskBlock(block, dismissedQuestionSignature) {
1330
1343
  };
1331
1344
  }
1332
1345
  function askBlockStillWaiting(block, messages) {
1346
+ if (!messages?.length) return Boolean(block?.at);
1333
1347
  const askedAt = block?.at;
1334
1348
  if (!askedAt) return false;
1335
1349
  for (let i = messages.length - 1; i >= 0; i--) {
@@ -1342,19 +1356,21 @@ function askBlockStillWaiting(block, messages) {
1342
1356
  }
1343
1357
  function latestPendingPlanQuestions(input) {
1344
1358
  if (input.userReplied) return null;
1345
- const fromLive = extractPendingPlanQuestions(input.liveParts);
1346
- if (fromLive) return fromLive;
1359
+ const fromBlock = () => pendingFromAskBlock(input.agentBlock, input.dismissedQuestionSignature);
1360
+ if (lastTopLevelToolIsAskUser(input.liveParts)) {
1361
+ return extractPendingPlanQuestions(input.liveParts) ?? fromBlock();
1362
+ }
1347
1363
  const last = input.messages[input.messages.length - 1];
1348
- if (last?.role === "agent") {
1349
- const fromParts = extractPendingPlanQuestions(last.parts);
1350
- if (fromParts) return fromParts;
1364
+ if (last?.role === "agent" && lastTopLevelToolIsAskUser(last.parts)) {
1365
+ return extractPendingPlanQuestions(last.parts) ?? fromBlock();
1351
1366
  }
1352
- const fromBlock = pendingFromAskBlock(
1353
- input.agentBlock,
1354
- input.dismissedQuestionSignature
1355
- );
1356
- if (fromBlock && askBlockStillWaiting(input.agentBlock, input.messages)) {
1357
- return fromBlock;
1367
+ if (hasTopLevelTool(input.liveParts) || last?.role === "agent" && hasTopLevelTool(last.parts)) {
1368
+ return null;
1369
+ }
1370
+ if (input.status === "running" || input.status === "queued") return null;
1371
+ const stamped = fromBlock();
1372
+ if (stamped && askBlockStillWaiting(input.agentBlock, input.messages)) {
1373
+ return stamped;
1358
1374
  }
1359
1375
  return null;
1360
1376
  }
@@ -1407,14 +1423,7 @@ function needsCoordinatorAction(state) {
1407
1423
  return isIncompleteTaskState(state) || state === "input-required";
1408
1424
  }
1409
1425
  function endedOnAskUser(parts) {
1410
- if (!parts?.length) return false;
1411
- for (let i = parts.length - 1; i >= 0; i--) {
1412
- const p = parts[i];
1413
- if (p.type === "tool" && !p.parentId) {
1414
- return isAskUserToolName(p.name);
1415
- }
1416
- }
1417
- return false;
1426
+ return lastTopLevelToolIsAskUser(parts);
1418
1427
  }
1419
1428
  function deriveTaskState(input) {
1420
1429
  if (input.stillRunning) {
@@ -1823,7 +1832,7 @@ var PORT_RANGE_SIZE = 10;
1823
1832
  var RECLAIM_RETRY_DELAY_MS = 40;
1824
1833
  var RECLAIM_TRIES = 8;
1825
1834
  async function killReclaimable(ports, worktreePath, signal) {
1826
- const { killListenersOnPorts: killListenersOnPorts2, killStaleWorktreeListeners: killStaleWorktreeListeners2 } = await import("./conductor-OFXA5BST.js");
1835
+ const { killListenersOnPorts: killListenersOnPorts2, killStaleWorktreeListeners: killStaleWorktreeListeners2 } = await import("./conductor-YOBSYPLT.js");
1827
1836
  if (worktreePath) killStaleWorktreeListeners2(ports, worktreePath, signal);
1828
1837
  else killListenersOnPorts2(ports);
1829
1838
  }
@@ -2507,7 +2516,9 @@ export {
2507
2516
  planQuestionsSignature,
2508
2517
  parsePlanQuestionsInput,
2509
2518
  isAskUserToolName,
2519
+ lastTopLevelToolIsAskUser,
2510
2520
  extractPendingPlanQuestions,
2521
+ askBlockStillWaiting,
2511
2522
  latestPendingPlanQuestions,
2512
2523
  PLAN_QUESTION_ANSWERS_PREFIX,
2513
2524
  isPlanQuestionAnswersMessage,
@@ -1235,6 +1235,16 @@ function isAskUserToolName(name) {
1235
1235
  const base = name.replace(/^mcp__sideboard__/i, "");
1236
1236
  return ASK_USER_TOOL_RE.test(name) || /^ask_user$/i.test(base);
1237
1237
  }
1238
+ function lastTopLevelToolIsAskUser(parts) {
1239
+ if (!parts?.length) return false;
1240
+ for (let i = parts.length - 1; i >= 0; i--) {
1241
+ const part = parts[i];
1242
+ if (part.type === "tool" && !part.parentId) {
1243
+ return isAskUserToolName(part.name);
1244
+ }
1245
+ }
1246
+ return false;
1247
+ }
1238
1248
  function questionsFromToolPart(part) {
1239
1249
  const fromInput = parsePlanQuestionsInput(part.input);
1240
1250
  if (fromInput.length) return fromInput;
@@ -1262,6 +1272,18 @@ function extractPendingPlanQuestions(parts) {
1262
1272
  }
1263
1273
  return null;
1264
1274
  }
1275
+ function askBlockStillWaiting(block, messages) {
1276
+ if (!messages?.length) return Boolean(block?.at);
1277
+ const askedAt = block?.at;
1278
+ if (!askedAt) return false;
1279
+ for (let i = messages.length - 1; i >= 0; i--) {
1280
+ const message = messages[i];
1281
+ if (message.role !== "user" || message.origin === "continue") continue;
1282
+ if (!message.ts) return true;
1283
+ return askedAt > message.ts;
1284
+ }
1285
+ return true;
1286
+ }
1265
1287
 
1266
1288
  // src/orchestrator/task-state.ts
1267
1289
  function isIncompleteTaskState(state) {
@@ -1271,14 +1293,7 @@ function needsCoordinatorAction(state) {
1271
1293
  return isIncompleteTaskState(state) || state === "input-required";
1272
1294
  }
1273
1295
  function endedOnAskUser(parts) {
1274
- if (!parts?.length) return false;
1275
- for (let i = parts.length - 1; i >= 0; i--) {
1276
- const p = parts[i];
1277
- if (p.type === "tool" && !p.parentId) {
1278
- return isAskUserToolName(p.name);
1279
- }
1280
- }
1281
- return false;
1296
+ return lastTopLevelToolIsAskUser(parts);
1282
1297
  }
1283
1298
  function deriveTaskState(input) {
1284
1299
  if (input.stillRunning) {
@@ -1687,7 +1702,7 @@ var PORT_RANGE_SIZE = 10;
1687
1702
  var RECLAIM_RETRY_DELAY_MS = 40;
1688
1703
  var RECLAIM_TRIES = 8;
1689
1704
  async function killReclaimable(ports, worktreePath, signal) {
1690
- const { killListenersOnPorts: killListenersOnPorts2, killStaleWorktreeListeners: killStaleWorktreeListeners2 } = await import("./conductor-AMZ5SKG2.js");
1705
+ const { killListenersOnPorts: killListenersOnPorts2, killStaleWorktreeListeners: killStaleWorktreeListeners2 } = await import("./conductor-CTWR6NH4.js");
1691
1706
  if (worktreePath) killStaleWorktreeListeners2(ports, worktreePath, signal);
1692
1707
  else killListenersOnPorts2(ports);
1693
1708
  }
@@ -2372,6 +2387,7 @@ export {
2372
2387
  parsePlanQuestionsInput,
2373
2388
  isAskUserToolName,
2374
2389
  extractPendingPlanQuestions,
2390
+ askBlockStillWaiting,
2375
2391
  needsCoordinatorAction,
2376
2392
  deriveTaskState,
2377
2393
  mcpWaitForTurnTimeoutMs,
@@ -34,7 +34,7 @@ import {
34
34
  tryReservePort,
35
35
  tryReservePorts,
36
36
  worktreeRunPortsPath
37
- } from "./chunk-AILQRQ26.js";
37
+ } from "./chunk-ZW7RSQHY.js";
38
38
  import "./chunk-I5TESHDN.js";
39
39
  import "./chunk-X3FSWWW2.js";
40
40
  import "./chunk-DLGGLV2M.js";
@@ -32,7 +32,7 @@ import {
32
32
  tryReservePort,
33
33
  tryReservePorts,
34
34
  worktreeRunPortsPath
35
- } from "./chunk-VBVSJUM2.js";
35
+ } from "./chunk-QC2TQMPJ.js";
36
36
  import "./chunk-7Q327QF2.js";
37
37
  import "./chunk-5QX2NYXL.js";
38
38
  import "./chunk-BIPXOHZI.js";