@sideboard-ai/core 0.1.107 → 0.1.110

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.
Files changed (44) hide show
  1. package/dist/agents/cursor-runner.cjs +87 -12
  2. package/dist/agents/cursor-runner.js +38 -12
  3. package/dist/{agents-T4RHL5UX.js → agents-MQDW3YXL.js} +6 -6
  4. package/dist/{agents-4XQANGFO.js → agents-WK54VP7J.js} +8 -8
  5. package/dist/{app-settings-2WH6DVOW.js → app-settings-5XAGNDX7.js} +3 -1
  6. package/dist/{app-settings-6AXBWM3K.js → app-settings-J4LUWIRN.js} +4 -2
  7. package/dist/{chunk-HUKCGRAT.js → chunk-3UOKB6VQ.js} +47 -2
  8. package/dist/{chunk-SMWVSSE5.js → chunk-4EWPKYOU.js} +4 -4
  9. package/dist/{chunk-7ZTQHC2Q.js → chunk-4NR5FL46.js} +11 -1
  10. package/dist/{chunk-TLPJHLLM.js → chunk-4TR3HZFT.js} +1 -1
  11. package/dist/{chunk-VTTTV2LM.js → chunk-7KWYXGIU.js} +2 -2
  12. package/dist/{chunk-KGSVLZV6.js → chunk-A4VZXJEJ.js} +2 -0
  13. package/dist/{chunk-5XUKY2JY.js → chunk-AROMOP3C.js} +8 -16
  14. package/dist/{chunk-PZVA2VDF.js → chunk-C4KHDW3U.js} +2 -2
  15. package/dist/{chunk-3SIFRHJ3.js → chunk-EAAB4EK5.js} +1597 -1704
  16. package/dist/{chunk-GYFNFU62.js → chunk-KQBI5HNT.js} +8 -16
  17. package/dist/{chunk-P3BQ5DOL.js → chunk-KYOTBZ6S.js} +2 -0
  18. package/dist/{chunk-6HRR4T4P.js → chunk-RSIWPLRG.js} +483 -46
  19. package/dist/{chunk-EX4NZN3O.js → chunk-SGEVS5SY.js} +11 -1
  20. package/dist/{chunk-THXSFETX.js → chunk-VOD3HFLP.js} +4 -4
  21. package/dist/{chunk-XOYH3OMI.js → chunk-VOJSO3RM.js} +484 -55
  22. package/dist/{chunk-MMI4RJ5I.js → chunk-WIHKHR5R.js} +14 -3
  23. package/dist/{chunk-XEFHG6VG.js → chunk-XOZDAVOP.js} +1449 -1518
  24. package/dist/{chunk-LRO7YVLJ.js → chunk-YFAXVUY2.js} +2 -2
  25. package/dist/{chunk-6JJTMI7G.js → chunk-YXDR43ZC.js} +2 -2
  26. package/dist/{coordinator-prompt-4TUQUEHY.js → coordinator-prompt-AR66L3N4.js} +5 -5
  27. package/dist/{coordinator-prompt-YQWRXCPX.js → coordinator-prompt-BHMLWL64.js} +4 -4
  28. package/dist/{global-workspace-H37LFFXI.js → global-workspace-SKFODUQQ.js} +5 -5
  29. package/dist/{global-workspace-V6TMECDU.js → global-workspace-XSUFEIAQ.js} +6 -6
  30. package/dist/index.cjs +2388 -2006
  31. package/dist/index.d.cts +115 -26
  32. package/dist/index.d.ts +115 -26
  33. package/dist/index.js +141 -98
  34. package/dist/mcp/run-stdio.cjs +2354 -1988
  35. package/dist/mcp/run-stdio.js +90 -82
  36. package/dist/{orchestrator-DEHSKERK.js → orchestrator-FCZVCKBK.js} +11 -11
  37. package/dist/{orchestrator-2P7DX44Q.js → orchestrator-SCATSB3O.js} +8 -8
  38. package/dist/{thread-store-DQJGDKIJ.js → thread-store-LPTBVW5C.js} +1 -1
  39. package/dist/{thread-store-4OUEQ2DB.js → thread-store-OEALWU7Y.js} +1 -1
  40. package/dist/{workspaces-UPEVANU4.js → workspaces-HV3J4TTW.js} +7 -7
  41. package/dist/{workspaces-JU3P6FHB.js → workspaces-XAQVKTLO.js} +6 -6
  42. package/dist/{worktree-6MFKE465.js → worktree-N2EV24EE.js} +3 -3
  43. package/dist/{worktree-NR5YJG2E.js → worktree-XFJED3VU.js} +4 -4
  44. package/package.json +1 -1
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-2GO3YKBA.js";
8
8
  import {
9
9
  isOrchestratorThread
10
- } from "./chunk-SMWVSSE5.js";
10
+ } from "./chunk-4EWPKYOU.js";
11
11
  import {
12
12
  applyNodeLaunch,
13
13
  cursorRipgrepEnv,
@@ -19,23 +19,23 @@ import {
19
19
  packagedMcpStdioPath,
20
20
  parseCursorRunnerLine,
21
21
  resolveNodeLaunch
22
- } from "./chunk-HUKCGRAT.js";
22
+ } from "./chunk-3UOKB6VQ.js";
23
23
  import {
24
24
  codexUnattendedGitConfigArgs,
25
25
  mergeAgentGitAuthEnv,
26
26
  resolveAgentGitAuthEnv,
27
27
  resolveCodexGitWritableRoots
28
- } from "./chunk-PZVA2VDF.js";
28
+ } from "./chunk-C4KHDW3U.js";
29
29
  import {
30
30
  claudeChromeEnabled,
31
31
  loadAppSettings,
32
32
  resolveAgentExecutable,
33
33
  resolveClaudeExecutable
34
- } from "./chunk-7ZTQHC2Q.js";
34
+ } from "./chunk-4NR5FL46.js";
35
35
  import {
36
36
  isElectronLikeCommand,
37
37
  unwrapStrippedElectronLaunch
38
- } from "./chunk-TLPJHLLM.js";
38
+ } from "./chunk-4TR3HZFT.js";
39
39
  import {
40
40
  appDataDir
41
41
  } from "./chunk-QZQEXME2.js";
@@ -527,6 +527,295 @@ function mcpAuthWarnings(servers) {
527
527
  ];
528
528
  }
529
529
 
530
+ // src/agents/message-parts.ts
531
+ function asRecord(input) {
532
+ if (input && typeof input === "object" && !Array.isArray(input)) {
533
+ return input;
534
+ }
535
+ return void 0;
536
+ }
537
+ function str(v) {
538
+ return typeof v === "string" && v.trim() ? v : void 0;
539
+ }
540
+ function toolDetail(name, input) {
541
+ if (!input) return void 0;
542
+ const command = str(input.command) ?? str(input.cmd);
543
+ if (command) return command;
544
+ const path = str(input.file_path) ?? str(input.path) ?? str(input.filePath) ?? str(input.filename);
545
+ if (path) return path;
546
+ const pattern = str(input.pattern) ?? str(input.glob) ?? str(input.glob_pattern);
547
+ if (pattern) return pattern;
548
+ const query = str(input.query) ?? str(input.prompt);
549
+ if (query) return query.length > 80 ? `${query.slice(0, 77)}\u2026` : query;
550
+ try {
551
+ const raw = JSON.stringify(input);
552
+ return raw.length > 80 ? `${raw.slice(0, 77)}\u2026` : raw;
553
+ } catch {
554
+ return name;
555
+ }
556
+ }
557
+ function toolDescription(name, input) {
558
+ const n = name.replace(/^mcp__/, "").replace(/__/g, " \xB7 ");
559
+ if (/^get_record_types$|recordTypes/i.test(name)) return "List record types";
560
+ if (/connectedAgentRequest/i.test(name)) {
561
+ return str(input?.agent_id) ? `Ask connected agent` : "Ask connected agent";
562
+ }
563
+ if (/present_artifact$/i.test(name)) {
564
+ return str(input?.title) ? `Present ${str(input?.title)}` : "Present artifact";
565
+ }
566
+ if (/present_plan$/i.test(name)) {
567
+ return str(input?.title) ? `Plan ${str(input?.title)}` : "Present plan";
568
+ }
569
+ if (/present_schema$/i.test(name)) {
570
+ return str(input?.title) ? `Schema ${str(input?.title)}` : "Present schema";
571
+ }
572
+ if (/present_files$/i.test(name)) {
573
+ return str(input?.title) ? `Files ${str(input?.title)}` : "Present files";
574
+ }
575
+ if (isSubagentToolName(name)) {
576
+ const desc = str(input?.description);
577
+ const sub = asRecord(input?.subagentType);
578
+ const kind = str(sub?.name) ?? str(sub?.kind) ?? str(input?.subagent_type) ?? str(input?.subagentType);
579
+ if (/^spawn_agent$/i.test(name)) {
580
+ return str(input?.prompt) ?? desc ?? "Subagent";
581
+ }
582
+ if (/connectedAgentRequest/i.test(name)) {
583
+ return str(input?.agent_id) ? `Ask connected agent` : "Ask connected agent";
584
+ }
585
+ if (desc && kind) return `${kind}: ${desc}`;
586
+ if (desc) return desc;
587
+ return "Subagent";
588
+ }
589
+ if (/^(create|update)_artifact$/i.test(name.replace(/^mcp__[^_]+__/, ""))) {
590
+ return str(input?.title) ? `Artifact ${str(input?.title)}` : "Artifact";
591
+ }
592
+ if (!input) return n;
593
+ if (/bash|shell|terminal/i.test(name) && str(input.command)) {
594
+ const cmd = str(input.command);
595
+ if (/git\s+fetch/i.test(cmd)) return "Fetch latest from origin and check status";
596
+ if (/git\s+status/i.test(cmd)) return "Check git status";
597
+ if (/git\s+log/i.test(cmd)) return "Inspect recent commits";
598
+ if (/git\s+branch/i.test(cmd)) return "List branches";
599
+ if (/grep|rg\b/i.test(cmd)) return "Search repository";
600
+ return "Run shell command";
601
+ }
602
+ if (/edit|write|apply/i.test(name)) {
603
+ const path = str(input.file_path) ?? str(input.path);
604
+ return path ? `Edit ${path.split("/").pop()}` : "Edit file";
605
+ }
606
+ if (/read/i.test(name)) {
607
+ const path = str(input.file_path) ?? str(input.path);
608
+ return path ? `Read ${path.split("/").pop()}` : "Read file";
609
+ }
610
+ if (/grep/i.test(name)) return "Search files";
611
+ if (/glob/i.test(name)) return "Find files";
612
+ return n;
613
+ }
614
+ function isSubagentToolName(name) {
615
+ const n = (name ?? "").trim();
616
+ if (/^(task|agent|spawn_agent)$/i.test(n)) return true;
617
+ return /connectedAgentRequest/i.test(n);
618
+ }
619
+ function messagePartParentId(part) {
620
+ if ("parentId" in part && typeof part.parentId === "string" && part.parentId.trim()) {
621
+ return part.parentId;
622
+ }
623
+ return void 0;
624
+ }
625
+ function sameParentId(a, b) {
626
+ return (a ?? "") === (b ?? "");
627
+ }
628
+ function withEventParentId(event, parentId) {
629
+ if (!parentId) return event;
630
+ if (event.type === "stdout" || event.type === "thinking" || event.type === "tool_use" || event.type === "tool_result") {
631
+ return { ...event, parentId: event.parentId ?? parentId };
632
+ }
633
+ return event;
634
+ }
635
+ function withEventsParentId(events, parentId) {
636
+ if (!parentId) return events;
637
+ return events.map((event) => withEventParentId(event, parentId));
638
+ }
639
+ function toolFilePath(input) {
640
+ if (!input) return void 0;
641
+ return str(input.file_path) ?? str(input.path) ?? str(input.filePath) ?? str(input.filename);
642
+ }
643
+ function countLines(text) {
644
+ if (!text) return 0;
645
+ return text.split("\n").length;
646
+ }
647
+ function diffFromInput(input) {
648
+ if (!input) return {};
649
+ const oldS = str(input.old_string) ?? str(input.oldString);
650
+ const newS = str(input.new_string) ?? str(input.newString) ?? str(input.content);
651
+ if (oldS != null || newS != null) {
652
+ return {
653
+ additions: countLines(newS),
654
+ deletions: countLines(oldS)
655
+ };
656
+ }
657
+ return {};
658
+ }
659
+ function parseDiffStat(result) {
660
+ if (!result) return {};
661
+ const paired = result.match(/\+(\d+)\s+-(\d+)/);
662
+ if (paired) {
663
+ return {
664
+ additions: Number(paired[1]),
665
+ deletions: Number(paired[2])
666
+ };
667
+ }
668
+ const verbose = result.match(
669
+ /(\d+)\s+insertions?(?:,\s*(\d+)\s+deletions?)?/i
670
+ );
671
+ if (verbose) {
672
+ return {
673
+ additions: Number(verbose[1]),
674
+ deletions: verbose[2] != null ? Number(verbose[2]) : void 0
675
+ };
676
+ }
677
+ return {};
678
+ }
679
+ function applyAgentEvent(parts, event) {
680
+ if (event.type === "stdout") {
681
+ const data = event.data;
682
+ if (!data) return parts;
683
+ const next = [...parts];
684
+ const last = next[next.length - 1];
685
+ if (last?.type === "text" && sameParentId(last.parentId, event.parentId)) {
686
+ next[next.length - 1] = {
687
+ type: "text",
688
+ text: last.text + data,
689
+ ...event.parentId ? { parentId: event.parentId } : {}
690
+ };
691
+ } else {
692
+ next.push({
693
+ type: "text",
694
+ text: data,
695
+ ...event.parentId ? { parentId: event.parentId } : {}
696
+ });
697
+ }
698
+ return next;
699
+ }
700
+ if (event.type === "thinking") {
701
+ const data = event.data;
702
+ if (!data) return parts;
703
+ const next = [...parts];
704
+ const last = next[next.length - 1];
705
+ if (last?.type === "thinking" && sameParentId(last.parentId, event.parentId)) {
706
+ next[next.length - 1] = {
707
+ type: "thinking",
708
+ text: last.text + data,
709
+ ...event.parentId ? { parentId: event.parentId } : {}
710
+ };
711
+ } else {
712
+ next.push({
713
+ type: "thinking",
714
+ text: data,
715
+ ...event.parentId ? { parentId: event.parentId } : {}
716
+ });
717
+ }
718
+ return next;
719
+ }
720
+ if (event.type === "tool_use") {
721
+ const input = asRecord(event.input);
722
+ const diff = diffFromInput(input);
723
+ const existing = parts.findIndex((p) => p.type === "tool" && p.id === event.id);
724
+ if (existing >= 0) {
725
+ const prev = parts[existing];
726
+ const next = [...parts];
727
+ const mergedInput = input && Object.keys(input).length > 0 ? input : prev.input ?? input;
728
+ next[existing] = {
729
+ ...prev,
730
+ name: event.name || prev.name,
731
+ input: mergedInput,
732
+ description: toolDescription(event.name || prev.name, mergedInput),
733
+ detail: toolDetail(event.name || prev.name, mergedInput) ?? prev.detail,
734
+ filePath: toolFilePath(mergedInput) ?? prev.filePath,
735
+ additions: diff.additions ?? prev.additions,
736
+ deletions: diff.deletions ?? prev.deletions,
737
+ parentId: event.parentId ?? prev.parentId
738
+ };
739
+ return next;
740
+ }
741
+ return [
742
+ ...parts,
743
+ {
744
+ type: "tool",
745
+ id: event.id,
746
+ name: event.name,
747
+ input,
748
+ description: toolDescription(event.name, input),
749
+ detail: toolDetail(event.name, input),
750
+ status: "running",
751
+ filePath: toolFilePath(input),
752
+ ...event.parentId ? { parentId: event.parentId } : {},
753
+ ...diff
754
+ }
755
+ ];
756
+ }
757
+ if (event.type === "tool_result") {
758
+ const existing = parts.findIndex((p) => p.type === "tool" && p.id === event.id);
759
+ const fromResult = parseDiffStat(event.content);
760
+ if (existing < 0) {
761
+ return [
762
+ ...parts,
763
+ {
764
+ type: "tool",
765
+ id: event.id,
766
+ name: "tool",
767
+ description: "tool",
768
+ status: event.isError ? "error" : "done",
769
+ result: event.content,
770
+ ...event.parentId ? { parentId: event.parentId } : {},
771
+ ...fromResult.additions != null ? { additions: fromResult.additions } : {},
772
+ ...fromResult.deletions != null ? { deletions: fromResult.deletions } : {}
773
+ }
774
+ ];
775
+ }
776
+ return parts.map((p, i) => {
777
+ if (i !== existing || p.type !== "tool") return p;
778
+ return {
779
+ ...p,
780
+ status: event.isError ? "error" : "done",
781
+ result: event.content,
782
+ ...fromResult.additions != null ? { additions: fromResult.additions } : {},
783
+ ...fromResult.deletions != null ? { deletions: fromResult.deletions } : {}
784
+ };
785
+ });
786
+ }
787
+ return parts;
788
+ }
789
+ function partsToAssistantText(parts) {
790
+ return parts.filter(
791
+ (p) => p.type === "text" && !messagePartParentId(p)
792
+ ).map((p) => p.text).join("").trim();
793
+ }
794
+ function stripBrightsyNdjsonNoise(text) {
795
+ if (!text || !text.includes('"type"')) return text;
796
+ let out = text;
797
+ out = out.replace(
798
+ /\{"type":"(?:tool_use|tool_result|tool|thinking|usage|done|error)"[\s\S]*?\}\s*(?=\{"type":"|$|(?=[A-Za-z*#]))/g,
799
+ ""
800
+ );
801
+ out = out.replace(/\{"type":"(?:tool_use|tool_result|tool)"[\s\S]*$/g, "");
802
+ return out.trim();
803
+ }
804
+ function isBrightsyNdjsonLine(line) {
805
+ const t = line.trim();
806
+ if (!t.startsWith("{")) return false;
807
+ return /"type"\s*:\s*"(tool_use|tool_result|tool|thinking|usage|done|error|text)"/.test(t);
808
+ }
809
+ function finalizeParts(parts) {
810
+ return parts.map(
811
+ (p) => p.type === "tool" && p.status === "running" ? { ...p, status: "done" } : p
812
+ );
813
+ }
814
+ function normalizeParseResult(parsed) {
815
+ if (!parsed) return [];
816
+ return Array.isArray(parsed) ? parsed : [parsed];
817
+ }
818
+
530
819
  // src/agents/injected-mcp.ts
531
820
  import { existsSync as existsSync2, mkdtempSync, writeFileSync } from "fs";
532
821
  import { createRequire } from "module";
@@ -536,6 +825,13 @@ import { fileURLToPath } from "url";
536
825
 
537
826
  // src/mcp/profile.ts
538
827
  var SIDEBOARD_MCP_PROFILE_ENV = "SIDEBOARD_MCP_PROFILE";
828
+ var WORKTREE_MCP_TOOLS = [
829
+ "present_artifact",
830
+ "ask_user",
831
+ "present_plan",
832
+ "present_schema",
833
+ "present_files"
834
+ ];
539
835
  function sideboardMcpProfile(env = process.env) {
540
836
  return env[SIDEBOARD_MCP_PROFILE_ENV]?.trim().toLowerCase() === "worktree" ? "worktree" : "orchestration";
541
837
  }
@@ -550,14 +846,7 @@ var SIDEBOARD_ARTIFACT_MCP_ALLOWED_TOOLS = [
550
846
  "mcp__sideboard__present_schema",
551
847
  "mcp__sideboard__present_files",
552
848
  "mcp__sideboard__ask_user",
553
- "mcp__sideboard__present_plan",
554
- "mcp__sideboard__list_teams",
555
- "mcp__sideboard__slack_list_channels",
556
- "mcp__sideboard__slack_list_users",
557
- "mcp__sideboard__slack_search",
558
- "mcp__sideboard__slack_read",
559
- "mcp__sideboard__slack_post",
560
- "mcp__sideboard__slack_replies"
849
+ "mcp__sideboard__present_plan"
561
850
  ];
562
851
  var BRIGHTSY_MCP_ALLOWED_TOOLS = [
563
852
  "mcp__brightsy",
@@ -877,7 +1166,10 @@ var BASE_ALLOWED_TOOLS = [
877
1166
  "Glob",
878
1167
  "Grep",
879
1168
  "WebFetch",
880
- "WebSearch"
1169
+ "WebSearch",
1170
+ // Subagents (Claude Code v2.1.63 renamed Task → Agent; allow both).
1171
+ "Task",
1172
+ "Agent"
881
1173
  ];
882
1174
  var CLAUDE_CHROME_ALLOWED_TOOLS = [
883
1175
  "mcp__claude-in-chrome",
@@ -929,42 +1221,59 @@ function claudeResultErrorDetail(obj) {
929
1221
  }
930
1222
  return "Claude turn failed";
931
1223
  }
932
- function eventsFromContentBlocks(blocks) {
1224
+ function eventsFromContentBlocks(blocks, parentId) {
933
1225
  if (!blocks?.length) return [];
934
1226
  const out = [];
935
1227
  for (const block of blocks) {
936
1228
  if (!block?.type) continue;
937
1229
  if (block.type === "text" && block.text) {
938
- out.push({ type: "stdout", data: block.text });
1230
+ out.push(withEventParentId({ type: "stdout", data: block.text }, parentId));
939
1231
  continue;
940
1232
  }
941
1233
  if ((block.type === "thinking" || block.type === "redacted_thinking") && block.thinking) {
942
- out.push({ type: "thinking", data: block.thinking });
1234
+ out.push(withEventParentId({ type: "thinking", data: block.thinking }, parentId));
943
1235
  continue;
944
1236
  }
945
1237
  if (block.type === "tool_use" && block.id && block.name) {
946
- out.push({
947
- type: "tool_use",
948
- id: block.id,
949
- name: block.name,
950
- input: block.input
951
- });
1238
+ out.push(
1239
+ withEventParentId(
1240
+ {
1241
+ type: "tool_use",
1242
+ id: block.id,
1243
+ name: block.name,
1244
+ input: block.input
1245
+ },
1246
+ parentId
1247
+ )
1248
+ );
952
1249
  continue;
953
1250
  }
954
1251
  if (block.type === "tool_result" && block.tool_use_id) {
955
1252
  const content = typeof block.content === "string" ? block.content : Array.isArray(block.content) ? block.content.map(
956
1253
  (c) => typeof c === "string" ? c : c && typeof c === "object" && "text" in c ? String(c.text ?? "") : ""
957
1254
  ).join("") : block.content != null ? JSON.stringify(block.content) : void 0;
958
- out.push({
959
- type: "tool_result",
960
- id: block.tool_use_id,
961
- content,
962
- isError: Boolean(block.is_error)
963
- });
1255
+ out.push(
1256
+ withEventParentId(
1257
+ {
1258
+ type: "tool_result",
1259
+ id: block.tool_use_id,
1260
+ content,
1261
+ isError: Boolean(block.is_error)
1262
+ },
1263
+ parentId
1264
+ )
1265
+ );
964
1266
  }
965
1267
  }
966
1268
  return out;
967
1269
  }
1270
+ function claudeParentToolUseId(obj) {
1271
+ const nested = obj.event && typeof obj.event === "object" && !Array.isArray(obj.event) ? obj.event : void 0;
1272
+ for (const id of [obj.parent_tool_use_id, nested?.parent_tool_use_id]) {
1273
+ if (typeof id === "string" && id.trim()) return id.trim();
1274
+ }
1275
+ return void 0;
1276
+ }
968
1277
  var claudeAdapter = {
969
1278
  kind: "claude",
970
1279
  async detect() {
@@ -1019,7 +1328,7 @@ var claudeAdapter = {
1019
1328
  );
1020
1329
  }
1021
1330
  const mode = permissionMode(thread);
1022
- const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-V6TMECDU.js");
1331
+ const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-XSUFEIAQ.js");
1023
1332
  const isOrchestrator = isOrchestratorThread2(thread);
1024
1333
  const injectedServers = await buildInjectedMcpServers({
1025
1334
  includeSideboard: true,
@@ -1085,7 +1394,9 @@ var claudeAdapter = {
1085
1394
  args,
1086
1395
  cwd: thread.worktreePath,
1087
1396
  stdin: useStdin ? `${promptText}
1088
- ` : void 0
1397
+ ` : void 0,
1398
+ // Nested Task/Agent thinking+text in stream-json (Claude Code 2.1.211+).
1399
+ env: { CLAUDE_CODE_FORWARD_SUBAGENT_TEXT: "1" }
1089
1400
  };
1090
1401
  },
1091
1402
  parseEvent(line) {
@@ -1102,8 +1413,9 @@ var claudeAdapter = {
1102
1413
  return { type: "session_id", data: obj.session_id };
1103
1414
  }
1104
1415
  if (obj.type === "assistant" || obj.type === "user") {
1416
+ const parentId = claudeParentToolUseId(obj);
1105
1417
  const message = obj.message;
1106
- const events = eventsFromContentBlocks(message?.content);
1418
+ const events = eventsFromContentBlocks(message?.content, parentId);
1107
1419
  if (obj.type === "assistant") {
1108
1420
  const usage = usageFromClaude(message?.usage);
1109
1421
  if (usage) events.push({ type: "usage", data: usage, scope: "request" });
@@ -1112,34 +1424,45 @@ var claudeAdapter = {
1112
1424
  return events.length === 1 ? events[0] : events;
1113
1425
  }
1114
1426
  if (obj.type === "stream_event") {
1427
+ const parentId = claudeParentToolUseId(obj);
1115
1428
  const event = obj.event;
1116
1429
  if (!event) return null;
1117
1430
  if (event.type === "content_block_start" && event.content_block) {
1118
1431
  const block = event.content_block;
1119
1432
  if (block.type === "tool_use" && block.id && block.name) {
1120
- return {
1121
- type: "tool_use",
1122
- id: block.id,
1123
- name: block.name,
1124
- input: block.input
1125
- };
1433
+ return withEventParentId(
1434
+ {
1435
+ type: "tool_use",
1436
+ id: block.id,
1437
+ name: block.name,
1438
+ input: block.input
1439
+ },
1440
+ parentId
1441
+ );
1126
1442
  }
1127
1443
  if (block.type === "thinking" && block.thinking) {
1128
- return { type: "thinking", data: block.thinking };
1444
+ return withEventParentId({ type: "thinking", data: block.thinking }, parentId);
1129
1445
  }
1130
1446
  return null;
1131
1447
  }
1132
1448
  if (event.type === "content_block_delta" && event.delta) {
1133
- if (event.delta.text) return { type: "stdout", data: event.delta.text };
1134
- if (event.delta.thinking) return { type: "thinking", data: event.delta.thinking };
1449
+ if (event.delta.text) {
1450
+ return withEventParentId({ type: "stdout", data: event.delta.text }, parentId);
1451
+ }
1452
+ if (event.delta.thinking) {
1453
+ return withEventParentId({ type: "thinking", data: event.delta.thinking }, parentId);
1454
+ }
1135
1455
  return null;
1136
1456
  }
1137
1457
  return null;
1138
1458
  }
1139
1459
  if (obj.type === "content_block_delta") {
1460
+ const parentId = claudeParentToolUseId(obj);
1140
1461
  const delta = obj.delta;
1141
- if (delta?.text) return { type: "stdout", data: delta.text };
1142
- if (delta?.thinking) return { type: "thinking", data: delta.thinking };
1462
+ if (delta?.text) return withEventParentId({ type: "stdout", data: delta.text }, parentId);
1463
+ if (delta?.thinking) {
1464
+ return withEventParentId({ type: "thinking", data: delta.thinking }, parentId);
1465
+ }
1143
1466
  return null;
1144
1467
  }
1145
1468
  if (obj.type === "result") {
@@ -1308,7 +1631,7 @@ function unwrapCodexMcpResult(result) {
1308
1631
  return String(result);
1309
1632
  }
1310
1633
  }
1311
- function asRecord(value) {
1634
+ function asRecord2(value) {
1312
1635
  if (value && typeof value === "object" && !Array.isArray(value)) {
1313
1636
  return value;
1314
1637
  }
@@ -1447,7 +1770,7 @@ var codexAdapter = {
1447
1770
  }
1448
1771
  if (itemType === "mcp_tool_call" && item.id && item.server && item.tool) {
1449
1772
  const name = `mcp__${item.server}__${item.tool}`;
1450
- const input = asRecord(item.arguments);
1773
+ const input = asRecord2(item.arguments);
1451
1774
  const events = [
1452
1775
  { type: "tool_use", id: item.id, name, input }
1453
1776
  ];
@@ -1478,6 +1801,36 @@ var codexAdapter = {
1478
1801
  }
1479
1802
  return events.length === 1 ? events[0] : events;
1480
1803
  }
1804
+ if (itemType === "collab_tool_call" && item.id) {
1805
+ const rawTool = typeof item.tool === "string" ? item.tool : "spawn_agent";
1806
+ const name = /spawn/i.test(rawTool) ? "spawn_agent" : rawTool;
1807
+ const input = {};
1808
+ if (item.prompt) input.prompt = item.prompt;
1809
+ if (Array.isArray(item.receiver_thread_ids)) {
1810
+ input.receiver_thread_ids = item.receiver_thread_ids;
1811
+ }
1812
+ const events = [{ type: "tool_use", id: item.id, name, input }];
1813
+ const finished = type === "item.completed" || item.status === "completed" || item.status === "failed";
1814
+ if (finished) {
1815
+ const nested = [];
1816
+ if (item.agents_states && typeof item.agents_states === "object") {
1817
+ for (const value of Object.values(item.agents_states)) {
1818
+ const msg = value && typeof value === "object" && typeof value.message === "string" ? value.message.trim() : "";
1819
+ if (msg) nested.push(msg);
1820
+ }
1821
+ }
1822
+ for (const text of nested) {
1823
+ events.push({ type: "stdout", data: text, parentId: item.id });
1824
+ }
1825
+ events.push({
1826
+ type: "tool_result",
1827
+ id: item.id,
1828
+ content: nested.join("\n") || void 0,
1829
+ isError: item.status === "failed"
1830
+ });
1831
+ }
1832
+ return events.length === 1 ? events[0] : events;
1833
+ }
1481
1834
  if (item.status === "failed") {
1482
1835
  const detail = item.message?.trim() || extractJsonErrorMessage(item) || `Codex ${itemType ?? "item"} failed`;
1483
1836
  return { type: "stderr", data: detail };
@@ -1727,6 +2080,24 @@ var FALLBACK_OPENCODE_MODELS = [
1727
2080
  ];
1728
2081
  var cachedOpencodeModels = null;
1729
2082
  var OPENCODE_MODEL_CACHE_MS = 5 * 60 * 1e3;
2083
+ function asRecord3(value) {
2084
+ if (value && typeof value === "object" && !Array.isArray(value)) {
2085
+ return value;
2086
+ }
2087
+ return void 0;
2088
+ }
2089
+ function str2(v) {
2090
+ return typeof v === "string" && v.trim() ? v.trim() : void 0;
2091
+ }
2092
+ function opencodeToolId(name, callId, metadata) {
2093
+ const sessionId = str2(metadata?.sessionId) ?? str2(metadata?.sessionID);
2094
+ if (name === "task" && sessionId) return sessionId;
2095
+ return callId || `tool-${Date.now()}`;
2096
+ }
2097
+ function withTaskParent(parentId, nested) {
2098
+ const events = Array.isArray(nested) ? nested : [nested];
2099
+ return [{ type: "tool_use", id: parentId, name: "task" }, ...events];
2100
+ }
1730
2101
  function displayNameFromOpencodeId(id) {
1731
2102
  const slash = id.indexOf("/");
1732
2103
  if (slash <= 0) return id;
@@ -1884,10 +2255,15 @@ var opencodeAdapter = {
1884
2255
  }
1885
2256
  if (obj.type === "tool_use") {
1886
2257
  const part = obj.part;
1887
- const id = part?.callID ?? part?.id ?? obj.id ?? `tool-${Date.now()}`;
1888
2258
  const name = part?.tool ?? part?.name ?? obj.tool ?? obj.name ?? "tool";
1889
2259
  const state = part?.state;
1890
2260
  const input = (state?.input && typeof state.input === "object" ? state.input : void 0) ?? part?.input ?? obj.input;
2261
+ const metadata = asRecord3(state?.metadata);
2262
+ const id = opencodeToolId(
2263
+ name,
2264
+ part?.callID ?? part?.id ?? obj.id,
2265
+ metadata
2266
+ );
1891
2267
  const events = [{ type: "tool_use", id, name, input }];
1892
2268
  const output = state?.output;
1893
2269
  if (output != null || state?.status === "completed" || state?.status === "error") {
@@ -1901,6 +2277,53 @@ var opencodeAdapter = {
1901
2277
  }
1902
2278
  return events.length === 1 ? events[0] : events;
1903
2279
  }
2280
+ if (obj.type === "subtask_delta") {
2281
+ const parentId = str2(obj.childSessionID) ?? str2(obj.childSessionId);
2282
+ const delta = str2(obj.delta);
2283
+ if (parentId && delta) {
2284
+ return withTaskParent(
2285
+ parentId,
2286
+ withEventParentId({ type: "thinking", data: delta }, parentId)
2287
+ );
2288
+ }
2289
+ return null;
2290
+ }
2291
+ if (obj.type === "subtask_event") {
2292
+ const parentId = str2(obj.childSessionID) ?? str2(obj.childSessionId);
2293
+ const part = asRecord3(obj.part);
2294
+ if (!parentId || !part) return null;
2295
+ if (part.type === "text" && str2(part.text)) {
2296
+ return withTaskParent(
2297
+ parentId,
2298
+ withEventParentId({ type: "stdout", data: str2(part.text) }, parentId)
2299
+ );
2300
+ }
2301
+ if (part.type === "tool" || str2(part.tool)) {
2302
+ const name = str2(part.tool) ?? str2(part.name) ?? "tool";
2303
+ const id = str2(part.callID) ?? str2(part.id) ?? `${parentId}-${name}`;
2304
+ const state = asRecord3(part.state);
2305
+ const input = asRecord3(state?.input) ?? asRecord3(part.input);
2306
+ const nested = [
2307
+ withEventParentId({ type: "tool_use", id, name, input }, parentId)
2308
+ ];
2309
+ const output = state?.output ?? part.output;
2310
+ if (output != null || state?.status === "completed" || state?.status === "error") {
2311
+ nested.push(
2312
+ withEventParentId(
2313
+ {
2314
+ type: "tool_result",
2315
+ id,
2316
+ content: typeof output === "string" ? output : output != null ? JSON.stringify(output) : void 0,
2317
+ isError: state?.status === "error" || state?.status === "failed"
2318
+ },
2319
+ parentId
2320
+ )
2321
+ );
2322
+ }
2323
+ return withTaskParent(parentId, nested);
2324
+ }
2325
+ return null;
2326
+ }
1904
2327
  if (obj.type === "tool_result") {
1905
2328
  const part = obj.part;
1906
2329
  const id = part?.tool_use_id ?? part?.id ?? obj.tool_use_id ?? obj.id;
@@ -2442,7 +2865,21 @@ export {
2442
2865
  sanitizeMcpServerName,
2443
2866
  mcpAllowTools,
2444
2867
  mcpAuthWarnings,
2868
+ toolDetail,
2869
+ toolDescription,
2870
+ isSubagentToolName,
2871
+ messagePartParentId,
2872
+ withEventParentId,
2873
+ withEventsParentId,
2874
+ toolFilePath,
2875
+ applyAgentEvent,
2876
+ partsToAssistantText,
2877
+ stripBrightsyNdjsonNoise,
2878
+ isBrightsyNdjsonLine,
2879
+ finalizeParts,
2880
+ normalizeParseResult,
2445
2881
  SIDEBOARD_MCP_PROFILE_ENV,
2882
+ WORKTREE_MCP_TOOLS,
2446
2883
  sideboardMcpProfile,
2447
2884
  SIDEBOARD_MCP_ALLOWED_TOOLS,
2448
2885
  BRIGHTSY_MCP_ALLOWED_TOOLS,