crewbee 0.1.14 → 0.1.16

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 (66) hide show
  1. package/README.md +33 -1
  2. package/README.zh-CN.md +33 -1
  3. package/dist/opencode-plugin.mjs +330 -149
  4. package/dist/src/adapters/opencode/config-hook.d.ts +2 -2
  5. package/dist/src/adapters/opencode/config-hook.d.ts.map +1 -1
  6. package/dist/src/adapters/opencode/config-hook.js +10 -1
  7. package/dist/src/adapters/opencode/config-hook.js.map +1 -1
  8. package/dist/src/adapters/opencode/delegation/prompt.d.ts.map +1 -1
  9. package/dist/src/adapters/opencode/delegation/prompt.js +1 -0
  10. package/dist/src/adapters/opencode/delegation/prompt.js.map +1 -1
  11. package/dist/src/adapters/opencode/delegation/tools.d.ts +5 -7
  12. package/dist/src/adapters/opencode/delegation/tools.d.ts.map +1 -1
  13. package/dist/src/adapters/opencode/delegation/tools.js +96 -34
  14. package/dist/src/adapters/opencode/delegation/tools.js.map +1 -1
  15. package/dist/src/adapters/opencode/delegation/types.d.ts +6 -0
  16. package/dist/src/adapters/opencode/delegation/types.d.ts.map +1 -1
  17. package/dist/src/adapters/opencode/model-availability.d.ts +4 -0
  18. package/dist/src/adapters/opencode/model-availability.d.ts.map +1 -0
  19. package/dist/src/adapters/opencode/model-availability.js +36 -0
  20. package/dist/src/adapters/opencode/model-availability.js.map +1 -0
  21. package/dist/src/adapters/opencode/model-resolution.d.ts +3 -0
  22. package/dist/src/adapters/opencode/model-resolution.d.ts.map +1 -1
  23. package/dist/src/adapters/opencode/model-resolution.js +98 -27
  24. package/dist/src/adapters/opencode/model-resolution.js.map +1 -1
  25. package/dist/src/adapters/opencode/permission-mapper.d.ts +1 -1
  26. package/dist/src/adapters/opencode/permission-mapper.d.ts.map +1 -1
  27. package/dist/src/adapters/opencode/permission-mapper.js +10 -3
  28. package/dist/src/adapters/opencode/permission-mapper.js.map +1 -1
  29. package/dist/src/adapters/opencode/plugin.js +1 -1
  30. package/dist/src/adapters/opencode/plugin.js.map +1 -1
  31. package/dist/src/adapters/opencode/projection.d.ts +1 -0
  32. package/dist/src/adapters/opencode/projection.d.ts.map +1 -1
  33. package/dist/src/adapters/opencode/projection.js +19 -2
  34. package/dist/src/adapters/opencode/projection.js.map +1 -1
  35. package/dist/src/adapters/opencode/prompt-builder.js +1 -1
  36. package/dist/src/adapters/opencode/prompt-builder.js.map +1 -1
  37. package/dist/src/adapters/opencode/tool-hooks.d.ts +1 -6
  38. package/dist/src/adapters/opencode/tool-hooks.d.ts.map +1 -1
  39. package/dist/src/adapters/opencode/tool-hooks.js +19 -37
  40. package/dist/src/adapters/opencode/tool-hooks.js.map +1 -1
  41. package/dist/src/agent-teams/embedded/coding-team/agents/coding-executor.js +2 -2
  42. package/dist/src/agent-teams/embedded/coding-team/agents/coding-executor.js.map +1 -1
  43. package/dist/src/agent-teams/embedded/coding-team/agents/coding-leader.d.ts.map +1 -1
  44. package/dist/src/agent-teams/embedded/coding-team/agents/coding-leader.js +2 -3
  45. package/dist/src/agent-teams/embedded/coding-team/agents/coding-leader.js.map +1 -1
  46. package/dist/src/agent-teams/embedded/coding-team/agents/coordination-leader.d.ts.map +1 -1
  47. package/dist/src/agent-teams/embedded/coding-team/agents/coordination-leader.js +2 -3
  48. package/dist/src/agent-teams/embedded/coding-team/agents/coordination-leader.js.map +1 -1
  49. package/dist/src/agent-teams/embedded/coding-team/agents/principal-advisor.d.ts.map +1 -1
  50. package/dist/src/agent-teams/embedded/coding-team/agents/principal-advisor.js +0 -1
  51. package/dist/src/agent-teams/embedded/coding-team/agents/principal-advisor.js.map +1 -1
  52. package/dist/src/agent-teams/embedded/coding-team/agents/reviewer.d.ts.map +1 -1
  53. package/dist/src/agent-teams/embedded/coding-team/agents/reviewer.js +1 -2
  54. package/dist/src/agent-teams/embedded/coding-team/agents/reviewer.js.map +1 -1
  55. package/dist/src/agent-teams/filesystem.d.ts +2 -0
  56. package/dist/src/agent-teams/filesystem.d.ts.map +1 -1
  57. package/dist/src/agent-teams/filesystem.js +12 -1
  58. package/dist/src/agent-teams/filesystem.js.map +1 -1
  59. package/dist/src/cli/doctor.d.ts.map +1 -1
  60. package/dist/src/cli/doctor.js +2 -0
  61. package/dist/src/cli/doctor.js.map +1 -1
  62. package/dist/src/core/index.d.ts +3 -0
  63. package/dist/src/core/index.d.ts.map +1 -1
  64. package/dist/src/runtime/registries/plugin-tools.js +3 -3
  65. package/dist/src/runtime/registries/plugin-tools.js.map +1 -1
  66. package/package.json +1 -1
@@ -7676,14 +7676,13 @@ function createCoordinationLeaderAgent() {
7676
7676
  ]
7677
7677
  },
7678
7678
  runtimeConfig: {
7679
- requestedTools: ["read", "glob", "grep", "skill", "delegate_task", "delegate_status", "delegate_cancel", "edit", "write", "bash", "lsp_diagnostics"],
7679
+ requestedTools: ["read", "glob", "grep", "skill", "task", "delegate_status", "delegate_cancel", "edit", "write", "bash", "lsp_diagnostics"],
7680
7680
  permission: [
7681
7681
  { permission: "read", pattern: "*", action: "allow" },
7682
7682
  { permission: "glob", pattern: "*", action: "allow" },
7683
7683
  { permission: "grep", pattern: "*", action: "allow" },
7684
7684
  { permission: "skill", pattern: "*", action: "allow" },
7685
- // { permission: "task", pattern: "*", action: "allow" },
7686
- { permission: "delegate_task", pattern: "*", action: "allow" },
7685
+ { permission: "task", pattern: "*", action: "allow" },
7687
7686
  { permission: "delegate_status", pattern: "*", action: "allow" },
7688
7687
  { permission: "delegate_cancel", pattern: "*", action: "allow" },
7689
7688
  { permission: "edit", pattern: "*", action: "allow" },
@@ -8026,7 +8025,7 @@ function createCodingExecutorAgent() {
8026
8025
  ],
8027
8026
  outOfScope: [
8028
8027
  "\u591A\u4EE3\u7406\u5B9E\u73B0\u7C7B\u59D4\u6D3E",
8029
- "task tool / delegate_task \u7C7B\u7F16\u6392",
8028
+ "task tool \u7C7B\u7F16\u6392",
8030
8029
  "\u7EAF\u89C4\u5212\u5DE5\u4F5C",
8031
8030
  "\u672A\u7ECF\u660E\u786E\u8BF7\u6C42\u7684\u63D0\u4EA4",
8032
8031
  "\u7528\u7C7B\u578B\u538B\u5236\u3001\u8DF3\u8FC7\u9A8C\u8BC1\u6216\u5220\u9664\u6D4B\u8BD5\u6765\u4F2A\u9020\u5B8C\u6210"
@@ -8088,7 +8087,7 @@ function createCodingExecutorAgent() {
8088
8087
  },
8089
8088
  guardrails: {
8090
8089
  critical: [
8091
- "\u7981\u6B62 task tool / delegate_task \u7C7B\u5B9E\u73B0\u7F16\u6392\u3002",
8090
+ "\u7981\u6B62 task tool \u7C7B\u5B9E\u73B0\u7F16\u6392\u3002",
8092
8091
  "\u7814\u7A76\u53EF\u4EE5\u501F\u52A9\u5916\u90E8\u89D2\u8272\uFF0C\u6267\u884C\u4E0D\u53EF\u4EE5\u5916\u5305\u3002",
8093
8092
  "\u591A\u6B65\u9AA4\u4EFB\u52A1\u6CA1\u6709 todo = \u672A\u5B8C\u6210\u3002",
8094
8093
  "\u6CA1\u6709\u9A8C\u8BC1\u8BC1\u636E = \u672A\u5B8C\u6210\u3002",
@@ -8238,14 +8237,13 @@ function createCodingLeaderAgent() {
8238
8237
  ]
8239
8238
  },
8240
8239
  runtimeConfig: {
8241
- requestedTools: ["read", "glob", "grep", "skill", "delegate_task", "delegate_status", "delegate_cancel", "edit", "write", "bash", "lsp_diagnostics"],
8240
+ requestedTools: ["read", "glob", "grep", "skill", "task", "delegate_status", "delegate_cancel", "edit", "write", "bash", "lsp_diagnostics"],
8242
8241
  permission: [
8243
8242
  { permission: "read", pattern: "*", action: "allow" },
8244
8243
  { permission: "glob", pattern: "*", action: "allow" },
8245
8244
  { permission: "grep", pattern: "*", action: "allow" },
8246
8245
  { permission: "skill", pattern: "*", action: "allow" },
8247
- // { permission: "task", pattern: "*", action: "deny" },
8248
- { permission: "delegate_task", pattern: "*", action: "allow" },
8246
+ { permission: "task", pattern: "*", action: "allow" },
8249
8247
  { permission: "delegate_status", pattern: "*", action: "allow" },
8250
8248
  { permission: "delegate_cancel", pattern: "*", action: "allow" },
8251
8249
  { permission: "edit", pattern: "*", action: "allow" },
@@ -8752,7 +8750,6 @@ function createPrincipalAdvisorAgent() {
8752
8750
  { permission: "webfetch", pattern: "*", action: "allow" },
8753
8751
  { permission: "websearch", pattern: "*", action: "allow" },
8754
8752
  { permission: "task", pattern: "*", action: "allow" },
8755
- { permission: "delegate_task", pattern: "*", action: "deny" },
8756
8753
  { permission: "delegate_status", pattern: "*", action: "deny" },
8757
8754
  { permission: "delegate_cancel", pattern: "*", action: "deny" },
8758
8755
  { permission: "edit", pattern: "*", action: "deny" },
@@ -9034,8 +9031,7 @@ function createReviewerAgent() {
9034
9031
  { permission: "read", pattern: "*", action: "allow" },
9035
9032
  { permission: "glob", pattern: "*", action: "allow" },
9036
9033
  { permission: "grep", pattern: "*", action: "allow" },
9037
- // { permission: "task", pattern: "*", action: "allow" },
9038
- { permission: "delegate_task", pattern: "*", action: "deny" },
9034
+ { permission: "task", pattern: "*", action: "deny" },
9039
9035
  { permission: "delegate_status", pattern: "*", action: "deny" },
9040
9036
  { permission: "delegate_cancel", pattern: "*", action: "deny" },
9041
9037
  { permission: "lsp_diagnostics", pattern: "*", action: "allow" },
@@ -10538,6 +10534,13 @@ function isRecord3(value) {
10538
10534
  function getOptionalBoolean(value, fallback) {
10539
10535
  return typeof value === "boolean" ? value : fallback;
10540
10536
  }
10537
+ function getOptionalStringArray(value) {
10538
+ if (!Array.isArray(value)) {
10539
+ return void 0;
10540
+ }
10541
+ const entries = value.filter((entry) => typeof entry === "string" && entry.trim().length > 0);
10542
+ return entries.length > 0 ? entries : void 0;
10543
+ }
10541
10544
  function getOptionalPriority(value, fallback) {
10542
10545
  return typeof value === "number" && Number.isFinite(value) ? value : fallback;
10543
10546
  }
@@ -10572,10 +10575,15 @@ function normalizeConfiguredTeamModelOverride(raw) {
10572
10575
  const model = getOptionalString(value.model);
10573
10576
  const variant = getOptionalString(value.variant);
10574
10577
  const options = createProviderOptionOverrides(value);
10578
+ const fallbackModels = getOptionalStringArray(value.fallback_models ?? value.fallbackModels);
10579
+ const strictValue = value.strict;
10580
+ const strict = typeof strictValue === "boolean" ? strictValue : void 0;
10575
10581
  return [[agentId, {
10576
10582
  ...model ? { model } : {},
10577
10583
  ...variant ? { variant } : {},
10578
- ...options ? { options } : {}
10584
+ ...options ? { options } : {},
10585
+ ...fallbackModels ? { fallbackModels } : {},
10586
+ ...strict !== void 0 ? { strict } : {}
10579
10587
  }]];
10580
10588
  })
10581
10589
  ) : void 0;
@@ -10610,10 +10618,7 @@ function createDefaultCodingTeamConfigEntry() {
10610
10618
  priority: DEFAULT_EMBEDDED_TEAM_PRIORITY,
10611
10619
  model_preset: BUILTIN_CODING_TEAM_MODEL_PRESET,
10612
10620
  fallback: BUILTIN_CODING_TEAM_MODEL_FALLBACK,
10613
- fallback_to_host_default: BUILTIN_CODING_TEAM_FALLBACK_TO_HOST_DEFAULT,
10614
- agents: Object.fromEntries(
10615
- Object.entries(BUILTIN_CODING_TEAM_AGENT_MODELS).map(([agentId, model]) => [agentId, { model }])
10616
- )
10621
+ fallback_to_host_default: BUILTIN_CODING_TEAM_FALLBACK_TO_HOST_DEFAULT
10617
10622
  };
10618
10623
  }
10619
10624
  function getPackagedTemplateRootPath() {
@@ -11836,12 +11841,12 @@ function pickDefaultUserSelectableAgent(team) {
11836
11841
 
11837
11842
  // src/runtime/registries/plugin-tools.ts
11838
11843
  var CREWBEE_PLUGIN_TOOLS = {
11839
- delegate_task: {
11840
- id: "delegate_task",
11844
+ task: {
11845
+ id: "task",
11841
11846
  source: "crewbee-plugin",
11842
11847
  status: "implemented",
11843
11848
  visibility: "agent-addressable",
11844
- description: "Delegate work to a CrewBee team member with foreground or background execution.",
11849
+ description: "Delegate work to a CrewBee team member through the OpenCode-compatible task tool.",
11845
11850
  hostTargets: ["opencode"]
11846
11851
  },
11847
11852
  delegate_status: {
@@ -12027,6 +12032,7 @@ var TOOL_MAP = {
12027
12032
  patch: "edit",
12028
12033
  multiedit: "edit",
12029
12034
  lsp_diagnostics: "lsp",
12035
+ delegate_task: "task",
12030
12036
  look_at: void 0
12031
12037
  };
12032
12038
  function mapOpenCodeToolName(toolId) {
@@ -12048,9 +12054,16 @@ function mapPermissionRulesWithAvailability(permissionRules, availableTools) {
12048
12054
  };
12049
12055
  }).filter((rule) => Boolean(rule)).filter((rule) => isAvailableTool(rule.permission, availableTools));
12050
12056
  }
12051
- function createOpenCodePermissionRules(agent, availableTools) {
12052
- const rules = mapPermissionRulesWithAvailability(agent.sourceAgent.runtimeConfig.permission, availableTools).filter((rule) => rule.permission !== "task");
12057
+ function createOpenCodePermissionRules(agent, availableTools, allowedTaskTargets = []) {
12058
+ const mappedRules = mapPermissionRulesWithAvailability(agent.sourceAgent.runtimeConfig.permission, availableTools);
12059
+ const rules = mappedRules.filter((rule) => rule.permission !== "task");
12060
+ const taskAllowed = mappedRules.some((rule) => rule.permission === "task" && rule.action !== "deny");
12053
12061
  rules.push({ permission: "task", action: "deny", pattern: "*" });
12062
+ if (taskAllowed) {
12063
+ for (const target of allowedTaskTargets) {
12064
+ rules.push({ permission: "task", action: "allow", pattern: target });
12065
+ }
12066
+ }
12054
12067
  return rules;
12055
12068
  }
12056
12069
  function createOpenCodePermissionConfig(permissionRules) {
@@ -12529,7 +12542,7 @@ function createCollaborationPromptValue(agent) {
12529
12542
  delegationBoundary: [
12530
12543
  "Only delegate to agents explicitly listed in default_consults or default_handoffs for this Agent Profile.",
12531
12544
  "Do not delegate to host-provided agents, OpenCode built-in agents, agents from other Teams, or agents not listed here.",
12532
- "Use CrewBee delegate_task for delegation; do not use the host task tool for CrewBee Team delegation."
12545
+ "Use the OpenCode-compatible CrewBee task tool for delegation; it is implemented by CrewBee and constrained by this Team boundary."
12533
12546
  ]
12534
12547
  };
12535
12548
  }
@@ -12600,8 +12613,9 @@ function applyAgentModelOverride(runtime, override) {
12600
12613
  topP: runtime?.topP,
12601
12614
  variant: override.variant ?? runtime?.variant,
12602
12615
  options: mergeModelOptions(runtime?.options, override.options),
12603
- fallbackModels: runtime?.fallbackModels,
12604
- fallbackToHostDefault: runtime?.fallbackToHostDefault
12616
+ fallbackModels: override.fallbackModels ?? runtime?.fallbackModels,
12617
+ fallbackToHostDefault: runtime?.fallbackToHostDefault,
12618
+ strict: override.strict ?? runtime?.strict
12605
12619
  };
12606
12620
  }
12607
12621
  function parseProviderModel(model) {
@@ -12634,9 +12648,20 @@ function createHostDefaultTrace(input) {
12634
12648
  fallbackToHostDefault: input.fallbackToHostDefault,
12635
12649
  candidates: getCandidateModelIds(input.candidates),
12636
12650
  skipped: input.skipped,
12651
+ availability: input.availability,
12637
12652
  reason: input.reason
12638
12653
  };
12639
12654
  }
12655
+ function isBuiltinCodingTeamDefaultModel(input) {
12656
+ if (input.agent.teamId !== BUILTIN_CODING_TEAM_ID) {
12657
+ return false;
12658
+ }
12659
+ const sourceAgentId = input.agent.sourceAgent.metadata.sourceId ?? input.agent.canonicalAgentId;
12660
+ if (BUILTIN_CODING_TEAM_AGENT_MODELS[sourceAgentId] === input.model || BUILTIN_CODING_TEAM_AGENT_MODELS[input.agent.canonicalAgentId] === input.model) {
12661
+ return true;
12662
+ }
12663
+ return BUILTIN_ROLE_FALLBACKS[sourceAgentId]?.includes(input.model) === true || BUILTIN_ROLE_FALLBACKS[input.agent.canonicalAgentId]?.includes(input.model) === true;
12664
+ }
12640
12665
  function appendConfiguredModelCandidate(input) {
12641
12666
  const runtimeModel = resolveRuntimeModelId(input.runtime);
12642
12667
  const defaultRuntimeModel = resolveRuntimeModelId(input.defaultRuntime);
@@ -12644,7 +12669,9 @@ function appendConfiguredModelCandidate(input) {
12644
12669
  appendUniqueCandidate(input.candidates, {
12645
12670
  model: input.agentOverride.model,
12646
12671
  source: "crewbee-json",
12647
- runtime: applyAgentModelOverride(input.runtime ?? input.defaultRuntime, input.agentOverride)
12672
+ runtime: applyAgentModelOverride(input.runtime ?? input.defaultRuntime, input.agentOverride),
12673
+ strict: input.agentOverride.strict === true,
12674
+ allowWhenAvailabilityUnknown: input.allowWhenAvailabilityUnknown ?? true
12648
12675
  });
12649
12676
  return;
12650
12677
  }
@@ -12652,7 +12679,9 @@ function appendConfiguredModelCandidate(input) {
12652
12679
  appendUniqueCandidate(input.candidates, {
12653
12680
  model: runtimeModel,
12654
12681
  source: "team-manifest",
12655
- runtime: applyAgentModelOverride(input.runtime, input.agentOverride)
12682
+ runtime: applyAgentModelOverride(input.runtime, input.agentOverride),
12683
+ strict: input.runtime?.strict === true,
12684
+ allowWhenAvailabilityUnknown: input.runtime?.strict === true
12656
12685
  });
12657
12686
  return;
12658
12687
  }
@@ -12660,10 +12689,40 @@ function appendConfiguredModelCandidate(input) {
12660
12689
  appendUniqueCandidate(input.candidates, {
12661
12690
  model: defaultRuntimeModel,
12662
12691
  source: "team-manifest-default",
12663
- runtime: applyAgentModelOverride(input.defaultRuntime, input.agentOverride)
12692
+ runtime: applyAgentModelOverride(input.defaultRuntime, input.agentOverride),
12693
+ strict: input.defaultRuntime?.strict === true,
12694
+ allowWhenAvailabilityUnknown: input.defaultRuntime?.strict === true
12664
12695
  });
12665
12696
  }
12666
12697
  }
12698
+ function createResolvedModel(input) {
12699
+ return {
12700
+ model: {
12701
+ providerID: input.parsed.providerID,
12702
+ modelID: input.parsed.modelID,
12703
+ temperature: input.candidate.runtime?.temperature,
12704
+ topP: input.candidate.runtime?.topP,
12705
+ variant: input.candidate.runtime?.variant,
12706
+ options: input.candidate.runtime?.options,
12707
+ source: input.candidate.source,
12708
+ strict: input.candidate.strict === true
12709
+ },
12710
+ trace: {
12711
+ teamId: input.agent.teamId,
12712
+ agentId: input.agent.canonicalAgentId,
12713
+ configuredModel: input.configuredModel,
12714
+ resolvedModel: input.candidate.model,
12715
+ source: input.candidate.source,
12716
+ fallback: input.fallbackStrategy,
12717
+ fallbackToHostDefault: input.fallbackToHostDefault,
12718
+ candidates: getCandidateModelIds(input.candidates),
12719
+ skipped: input.skipped,
12720
+ availability: input.availability,
12721
+ strict: input.candidate.strict === true,
12722
+ reason: input.reason
12723
+ }
12724
+ };
12725
+ }
12667
12726
  function resolveAgentModel(input) {
12668
12727
  const { agent } = input;
12669
12728
  const teamOverride = agent.sourceTeam.modelConfigOverride;
@@ -12676,12 +12735,17 @@ function resolveAgentModel(input) {
12676
12735
  const fallbackToHostDefault = teamOverride?.fallbackToHostDefault ?? runtime?.fallbackToHostDefault ?? defaultRuntime?.fallbackToHostDefault ?? true;
12677
12736
  const runtimeModel = resolveRuntimeModelId(runtime);
12678
12737
  const configuredModel = agentOverride?.model ?? runtimeModel ?? resolveRuntimeModelId(defaultRuntime);
12738
+ const configuredIsBuiltinDefault = configuredModel ? isBuiltinCodingTeamDefaultModel({ agent, model: configuredModel }) : false;
12679
12739
  const candidates = [];
12740
+ const availableModels = input.availableModels ? new Set(input.availableModels) : void 0;
12741
+ const availability = availableModels ? "checked" : "unavailable";
12742
+ const skipped = [];
12680
12743
  appendConfiguredModelCandidate({
12681
12744
  candidates,
12682
12745
  agentOverride,
12683
12746
  runtime: runtimeWithOverride,
12684
- defaultRuntime: defaultRuntimeWithOverride
12747
+ defaultRuntime: defaultRuntimeWithOverride,
12748
+ allowWhenAvailabilityUnknown: !configuredIsBuiltinDefault
12685
12749
  });
12686
12750
  if (agentOverride?.model === HOST_DEFAULT_MODEL_ID || !agentOverride?.model && runtimeModel === HOST_DEFAULT_MODEL_ID) {
12687
12751
  return {
@@ -12692,6 +12756,7 @@ function resolveAgentModel(input) {
12692
12756
  fallbackToHostDefault,
12693
12757
  candidates,
12694
12758
  skipped: [],
12759
+ availability,
12695
12760
  reason: "host-default selected explicitly"
12696
12761
  })
12697
12762
  };
@@ -12699,15 +12764,20 @@ function resolveAgentModel(input) {
12699
12764
  const sourceAgentId = agent.sourceAgent.metadata.sourceId ?? agent.canonicalAgentId;
12700
12765
  if (fallbackStrategy === BUILTIN_CODING_TEAM_MODEL_FALLBACK && agent.teamId === BUILTIN_CODING_TEAM_ID) {
12701
12766
  for (const model of BUILTIN_ROLE_FALLBACKS[sourceAgentId] ?? BUILTIN_ROLE_FALLBACKS[agent.canonicalAgentId] ?? []) {
12702
- appendUniqueCandidate(candidates, { model, source: "builtin-role-chain", runtime: runtimeWithOverride });
12767
+ appendUniqueCandidate(candidates, { model, source: "builtin-role-chain", runtime: runtimeWithOverride, allowWhenAvailabilityUnknown: false });
12703
12768
  }
12704
12769
  } else {
12705
12770
  for (const model of runtimeWithOverride?.fallbackModels ?? defaultRuntimeWithOverride?.fallbackModels ?? []) {
12706
- appendUniqueCandidate(candidates, { model, source: "team-manifest", runtime: runtimeWithOverride ?? defaultRuntimeWithOverride });
12771
+ const fallbackRuntime = runtimeWithOverride ?? defaultRuntimeWithOverride;
12772
+ appendUniqueCandidate(candidates, {
12773
+ model,
12774
+ source: "team-manifest",
12775
+ runtime: fallbackRuntime,
12776
+ strict: fallbackRuntime?.strict === true,
12777
+ allowWhenAvailabilityUnknown: fallbackRuntime?.strict === true
12778
+ });
12707
12779
  }
12708
12780
  }
12709
- const availableModels = input.availableModels ? new Set(input.availableModels) : void 0;
12710
- const skipped = [];
12711
12781
  for (const candidate of candidates) {
12712
12782
  if (candidate.model === HOST_DEFAULT_MODEL_ID) {
12713
12783
  return {
@@ -12718,6 +12788,7 @@ function resolveAgentModel(input) {
12718
12788
  fallbackToHostDefault,
12719
12789
  candidates,
12720
12790
  skipped,
12791
+ availability,
12721
12792
  reason: "host-default selected from candidate chain"
12722
12793
  })
12723
12794
  };
@@ -12727,32 +12798,39 @@ function resolveAgentModel(input) {
12727
12798
  skipped.push({ model: candidate.model, reason: "model must use provider/model format" });
12728
12799
  continue;
12729
12800
  }
12801
+ if (candidate.strict) {
12802
+ return createResolvedModel({
12803
+ agent,
12804
+ candidate,
12805
+ parsed,
12806
+ configuredModel,
12807
+ fallbackStrategy,
12808
+ fallbackToHostDefault,
12809
+ candidates,
12810
+ skipped,
12811
+ availability,
12812
+ reason: availableModels && !availableModels.has(candidate.model) ? "strict model selected; availability check bypassed" : void 0
12813
+ });
12814
+ }
12815
+ if (!availableModels && !candidate.allowWhenAvailabilityUnknown) {
12816
+ skipped.push({ model: candidate.model, reason: "availability registry unavailable; candidate is not strict user configuration" });
12817
+ continue;
12818
+ }
12730
12819
  if (availableModels && !availableModels.has(candidate.model)) {
12731
12820
  skipped.push({ model: candidate.model, reason: "model not available in current OpenCode environment" });
12732
12821
  continue;
12733
12822
  }
12734
- return {
12735
- model: {
12736
- providerID: parsed.providerID,
12737
- modelID: parsed.modelID,
12738
- temperature: candidate.runtime?.temperature,
12739
- topP: candidate.runtime?.topP,
12740
- variant: candidate.runtime?.variant,
12741
- options: candidate.runtime?.options,
12742
- source: candidate.source
12743
- },
12744
- trace: {
12745
- teamId: agent.teamId,
12746
- agentId: agent.canonicalAgentId,
12747
- configuredModel,
12748
- resolvedModel: candidate.model,
12749
- source: candidate.source,
12750
- fallback: fallbackStrategy,
12751
- fallbackToHostDefault,
12752
- candidates: getCandidateModelIds(candidates),
12753
- skipped
12754
- }
12755
- };
12823
+ return createResolvedModel({
12824
+ agent,
12825
+ candidate,
12826
+ parsed,
12827
+ configuredModel,
12828
+ fallbackStrategy,
12829
+ fallbackToHostDefault,
12830
+ candidates,
12831
+ skipped,
12832
+ availability
12833
+ });
12756
12834
  }
12757
12835
  return {
12758
12836
  trace: createHostDefaultTrace({
@@ -12762,6 +12840,7 @@ function resolveAgentModel(input) {
12762
12840
  fallbackToHostDefault,
12763
12841
  candidates,
12764
12842
  skipped,
12843
+ availability,
12765
12844
  reason: fallbackToHostDefault ? "no usable model candidate; fallback_to_host_default enabled" : "no usable model candidate"
12766
12845
  })
12767
12846
  };
@@ -12823,7 +12902,11 @@ function createOpenCodeAgentConfig(agent, options = {}) {
12823
12902
  hidden: agent.exposure !== "user-selectable",
12824
12903
  description: agent.description,
12825
12904
  prompt: createOpenCodeAgentPrompt(agent, requestedTools),
12826
- permission: createOpenCodePermissionRules(agent, availableToolContext),
12905
+ permission: createOpenCodePermissionRules(
12906
+ agent,
12907
+ availableToolContext,
12908
+ createDelegationPolicy(agent).allowedTargets.map((target) => target.configKey)
12909
+ ),
12827
12910
  runtimeConfig: {
12828
12911
  requestedTools,
12829
12912
  permission: runtimeConfig.permission,
@@ -12862,7 +12945,6 @@ function createOpenCodeAgentDefinition(agent) {
12862
12945
  description: agent.description,
12863
12946
  mode: agent.mode,
12864
12947
  hidden: agent.hidden || void 0,
12865
- tools: { task: false },
12866
12948
  model: agent.resolvedModel ? `${agent.resolvedModel.providerID}/${agent.resolvedModel.modelID}` : void 0,
12867
12949
  temperature: agent.resolvedModel?.temperature,
12868
12950
  top_p: agent.resolvedModel?.topP,
@@ -12909,6 +12991,24 @@ function createOpenCodeAgentConfigPatch(input) {
12909
12991
  tools: {},
12910
12992
  prompt: "",
12911
12993
  permission: {}
12994
+ },
12995
+ explore: {
12996
+ name: "explore",
12997
+ description: "Disabled by CrewBee while a CrewBee Agent Team owns the session.",
12998
+ mode: "subagent",
12999
+ disable: true,
13000
+ tools: {},
13001
+ prompt: "",
13002
+ permission: {}
13003
+ },
13004
+ scout: {
13005
+ name: "scout",
13006
+ description: "Disabled by CrewBee while a CrewBee Agent Team owns the session.",
13007
+ mode: "subagent",
13008
+ disable: true,
13009
+ tools: {},
13010
+ prompt: "",
13011
+ permission: {}
12912
13012
  }
12913
13013
  };
12914
13014
  return {
@@ -13132,7 +13232,8 @@ function resolveDelegateModel(target, fallback) {
13132
13232
  if (target.resolvedModel) {
13133
13233
  return {
13134
13234
  providerID: target.resolvedModel.providerID,
13135
- modelID: target.resolvedModel.modelID
13235
+ modelID: target.resolvedModel.modelID,
13236
+ strict: target.resolvedModel.strict
13136
13237
  };
13137
13238
  }
13138
13239
  return fallback;
@@ -13311,6 +13412,39 @@ async function logCrewBee(ctx, message, extra, level = "info") {
13311
13412
  });
13312
13413
  }
13313
13414
 
13415
+ // src/adapters/opencode/model-availability.ts
13416
+ function isRecord6(value) {
13417
+ return typeof value === "object" && value !== null && !Array.isArray(value);
13418
+ }
13419
+ function getProviders(value) {
13420
+ const unwrapped = unwrapSdkResponse(value);
13421
+ if (!isRecord6(unwrapped) || !Array.isArray(unwrapped.providers)) {
13422
+ return void 0;
13423
+ }
13424
+ return unwrapped.providers;
13425
+ }
13426
+ async function listOpenCodeAvailableModels(input) {
13427
+ if (!isRecord6(input.client) || !isRecord6(input.client.config) || typeof input.client.config.providers !== "function") {
13428
+ return void 0;
13429
+ }
13430
+ const providers = input.client.config.providers;
13431
+ const response = await providers().catch(() => void 0);
13432
+ const providerList = getProviders(response);
13433
+ if (!providerList) {
13434
+ return void 0;
13435
+ }
13436
+ const models = [];
13437
+ for (const provider of providerList) {
13438
+ if (typeof provider.id !== "string" || !isRecord6(provider.models)) {
13439
+ continue;
13440
+ }
13441
+ for (const modelID of Object.keys(provider.models)) {
13442
+ models.push(`${provider.id}/${modelID}`);
13443
+ }
13444
+ }
13445
+ return [...new Set(models)].sort();
13446
+ }
13447
+
13314
13448
  // src/adapters/opencode/config-hook.ts
13315
13449
  function summarizeProjectedAgents(boot) {
13316
13450
  return boot.projectedAgents.map((agent) => ({
@@ -13346,10 +13480,14 @@ async function validateAndLogTeamLibrary(ctx, teamLibrary) {
13346
13480
  }))
13347
13481
  );
13348
13482
  }
13349
- function createInitialBootstrap(teamLibrary) {
13483
+ async function createInitialBootstrap(ctx, teamLibrary) {
13484
+ const availableModels = await listOpenCodeAvailableModels({
13485
+ client: ctx.client
13486
+ });
13350
13487
  const boot = createOpenCodeBootstrap({
13351
13488
  teamLibrary,
13352
- defaults: { defaultMode: DEFAULT_OPENCODE_EXECUTION_MODE }
13489
+ defaults: { defaultMode: DEFAULT_OPENCODE_EXECUTION_MODE },
13490
+ availableModels
13353
13491
  });
13354
13492
  return {
13355
13493
  boot,
@@ -13359,11 +13497,15 @@ function createInitialBootstrap(teamLibrary) {
13359
13497
  function createConfigHook(input) {
13360
13498
  return async (cfg) => {
13361
13499
  const current = getConfig(cfg);
13500
+ const availableModels = await listOpenCodeAvailableModels({
13501
+ client: input.ctx.client
13502
+ });
13362
13503
  const next = createOpenCodeBootstrap({
13363
13504
  teamLibrary: input.teamLibrary,
13364
13505
  defaults: { defaultMode: DEFAULT_OPENCODE_EXECUTION_MODE },
13365
13506
  existingConfig: current,
13366
- existingDefaultAgent: typeof current.default_agent === "string" ? current.default_agent : void 0
13507
+ existingDefaultAgent: typeof current.default_agent === "string" ? current.default_agent : void 0,
13508
+ availableModels
13367
13509
  });
13368
13510
  input.setBoot(next);
13369
13511
  input.setAliasIndex(createProjectedAgentAliasIndex(next.projectedAgents));
@@ -26112,8 +26254,28 @@ function createDescription(prompt) {
26112
26254
  const trimmed = prompt.trim().replace(/\s+/g, " ");
26113
26255
  return trimmed.length <= 60 ? trimmed : `${trimmed.slice(0, 57)}...`;
26114
26256
  }
26257
+ function resolveRequestedAgent(args) {
26258
+ return args.subagent_type ?? args.agent;
26259
+ }
26260
+ function resolveRequestedSessionID(args) {
26261
+ return args.task_id ?? args.session_id;
26262
+ }
26263
+ function resolveRequestedMode(args) {
26264
+ if (args.run_in_background === true) {
26265
+ return "background";
26266
+ }
26267
+ return args.mode ?? "foreground";
26268
+ }
26269
+ function createPromptModel(model) {
26270
+ return model ? { providerID: model.providerID, modelID: model.modelID } : void 0;
26271
+ }
26272
+ function isModelUnavailableError(error45) {
26273
+ const text = String(error45 instanceof Error ? `${error45.name} ${error45.message}` : error45).toLowerCase();
26274
+ return text.includes("providermodelnotfounderror") || text.includes("model not found") || text.includes("model_not_found") || text.includes("unknown model");
26275
+ }
26115
26276
  async function resolveChildSession(input) {
26116
- if (!input.args.session_id) {
26277
+ const requestedSessionID = resolveRequestedSessionID(input.args);
26278
+ if (!requestedSessionID) {
26117
26279
  const created = unwrapSdkResponse(await input.client.session.create({
26118
26280
  body: { parentID: input.parentSessionID, title: input.title }
26119
26281
  }));
@@ -26126,20 +26288,20 @@ async function resolveChildSession(input) {
26126
26288
  });
26127
26289
  return { sessionID, existing: false };
26128
26290
  }
26129
- const known = input.store.getSession(input.args.session_id);
26291
+ const known = input.store.getSession(requestedSessionID);
26130
26292
  if (!known) {
26131
- return createFailedResult(input.args.session_id, "invalid_session_id", "Use an existing delegated session_id returned by delegate_task.");
26293
+ return createFailedResult(requestedSessionID, "invalid_session_id", "Use an existing task_id/session_id returned by task.");
26132
26294
  }
26133
26295
  if (known.parentSessionID !== input.parentSessionID) {
26134
- return createFailedResult(input.args.session_id, "invalid_session_id", "Use a delegated session_id created from the current parent session.");
26296
+ return createFailedResult(requestedSessionID, "invalid_session_id", "Use a delegated task_id/session_id created from the current parent session.");
26135
26297
  }
26136
26298
  if (known.canonicalAgentId !== input.canonicalAgentId) {
26137
- return createFailedResult(input.args.session_id, "agent_session_mismatch", "The delegated session is already bound to a different agent.");
26299
+ return createFailedResult(requestedSessionID, "agent_session_mismatch", "The delegated session is already bound to a different agent.");
26138
26300
  }
26139
- await input.client.session.get({ path: { id: input.args.session_id } }).catch(() => {
26140
- throw createFailedResult(input.args.session_id, "invalid_session_id", "Use an existing delegated session_id returned by delegate_task.");
26301
+ await input.client.session.get({ path: { id: requestedSessionID } }).catch(() => {
26302
+ throw createFailedResult(requestedSessionID, "invalid_session_id", "Use an existing task_id/session_id returned by task.");
26141
26303
  });
26142
- return { sessionID: input.args.session_id, existing: true };
26304
+ return { sessionID: requestedSessionID, existing: true };
26143
26305
  }
26144
26306
  async function runForeground(input) {
26145
26307
  const anchor = await getSessionAnchor(input.client, input.sessionID);
@@ -26151,22 +26313,37 @@ async function runForeground(input) {
26151
26313
  prompt: input.args.prompt
26152
26314
  });
26153
26315
  input.store.setCheckpoint(input.sessionID, createCheckpoint(input.target, model));
26154
- await input.client.session.prompt({
26155
- path: { id: input.sessionID },
26156
- body: {
26157
- agent: input.target.configKey,
26158
- model,
26159
- parts: [{ type: "text", text: envelope }]
26316
+ try {
26317
+ await input.client.session.prompt({
26318
+ path: { id: input.sessionID },
26319
+ body: {
26320
+ agent: input.target.configKey,
26321
+ model: createPromptModel(model),
26322
+ parts: [{ type: "text", text: envelope }]
26323
+ }
26324
+ });
26325
+ } catch (error45) {
26326
+ if (!model || model.strict || !isModelUnavailableError(error45)) {
26327
+ throw error45;
26160
26328
  }
26161
- });
26329
+ input.store.setCheckpoint(input.sessionID, createCheckpoint(input.target, void 0));
26330
+ await input.client.session.prompt({
26331
+ path: { id: input.sessionID },
26332
+ body: {
26333
+ agent: input.target.configKey,
26334
+ parts: [{ type: "text", text: envelope }]
26335
+ }
26336
+ });
26337
+ }
26162
26338
  const message = await extractAssistantText(input.client, input.sessionID, anchor);
26163
26339
  const result = {
26164
26340
  status: "completed",
26165
26341
  session_id: input.sessionID,
26342
+ task_id: input.sessionID,
26166
26343
  message,
26167
26344
  resume_supported: true
26168
26345
  };
26169
- input.ctx.metadata({ title: input.title, metadata: { sessionId: input.sessionID, agent: input.target.canonicalAgentId } });
26346
+ input.ctx.metadata({ title: input.title, metadata: { sessionId: input.sessionID, taskId: input.sessionID, agent: input.target.canonicalAgentId, mode: "foreground" } });
26170
26347
  return result;
26171
26348
  }
26172
26349
  function createBackgroundRecord(input) {
@@ -26198,11 +26375,24 @@ function launchBackground(input) {
26198
26375
  path: { id: input.sessionID },
26199
26376
  body: {
26200
26377
  agent: input.target.configKey,
26201
- model,
26378
+ model: createPromptModel(model),
26202
26379
  parts: [{ type: "text", text: envelope }]
26203
26380
  }
26204
26381
  }).catch((error45) => {
26205
- input.store.setTaskStatus(input.taskRef, "failed", { lastError: String(error45), message: String(error45) });
26382
+ if (!model || model.strict || !isModelUnavailableError(error45)) {
26383
+ input.store.setTaskStatus(input.taskRef, "failed", { lastError: String(error45), message: String(error45) });
26384
+ return;
26385
+ }
26386
+ input.store.setCheckpoint(input.sessionID, createCheckpoint(input.target, void 0));
26387
+ void launcher({
26388
+ path: { id: input.sessionID },
26389
+ body: {
26390
+ agent: input.target.configKey,
26391
+ parts: [{ type: "text", text: envelope }]
26392
+ }
26393
+ }).catch((retryError) => {
26394
+ input.store.setTaskStatus(input.taskRef, "failed", { lastError: String(retryError), message: String(retryError) });
26395
+ });
26206
26396
  });
26207
26397
  }
26208
26398
  function findBoundSourceAgent(input) {
@@ -26214,24 +26404,26 @@ function findBoundSourceAgent(input) {
26214
26404
  });
26215
26405
  }
26216
26406
  function createDelegateTools(input) {
26217
- const delegate_task = createToolDefinition({
26218
- description: "Delegate work to a CrewBee team member.",
26407
+ const task = createToolDefinition({
26408
+ description: "Delegate work to a CrewBee team member. This is CrewBee's OpenCode-compatible task implementation; use subagent_type to select an allowed Team member.",
26219
26409
  args: {
26220
- agent: zod_default.string().optional().describe("CrewBee agent id or alias"),
26221
- prompt: zod_default.string().describe("Delegated objective"),
26222
- session_id: zod_default.string().optional().describe("Existing delegated session to continue"),
26223
- mode: zod_default.enum(["foreground", "background"]).optional().describe("Execution mode, defaults to foreground")
26410
+ description: zod_default.string().optional().describe("A short (3-5 words) description of the task"),
26411
+ prompt: zod_default.string().describe("The task for the CrewBee agent to perform"),
26412
+ subagent_type: zod_default.string().describe("CrewBee agent id or alias listed in the current Agent Profile collaboration section"),
26413
+ task_id: zod_default.string().optional().describe("Existing delegated session to continue"),
26414
+ run_in_background: zod_default.boolean().optional().describe("Launch the delegated task in background mode")
26224
26415
  },
26225
26416
  async execute(args, ctx) {
26226
- if (!args.agent) {
26227
- return stringifyDelegateTaskResult(createFailedResult(ctx.sessionID, "missing_agent", "Provide the CrewBee agent field when delegating work."));
26417
+ const requestedAgent = resolveRequestedAgent(args);
26418
+ if (!requestedAgent) {
26419
+ return stringifyDelegateTaskResult(createFailedResult(ctx.sessionID, "missing_agent", "Provide subagent_type when delegating work."));
26228
26420
  }
26229
26421
  if (input.store.getSession(ctx.sessionID)) {
26230
26422
  return stringifyDelegateTaskResult(
26231
26423
  createFailedResult(ctx.sessionID, "nested_delegate_forbidden", "Nested CrewBee delegation is disabled for delegated subagent sessions.")
26232
26424
  );
26233
26425
  }
26234
- const mode = args.mode ?? "foreground";
26426
+ const mode = resolveRequestedMode(args);
26235
26427
  if (mode !== "foreground" && mode !== "background") {
26236
26428
  return stringifyDelegateTaskResult(createFailedResult(ctx.sessionID, "unsupported_mode", "Use mode=foreground or mode=background."));
26237
26429
  }
@@ -26241,16 +26433,16 @@ function createDelegateTools(input) {
26241
26433
  const target = resolveDelegateAgent({
26242
26434
  agents: projectedAgents,
26243
26435
  aliasIndex: input.getAliasIndex(),
26244
- agent: args.agent,
26436
+ agent: requestedAgent,
26245
26437
  sourceAgent
26246
26438
  });
26247
26439
  if (!target) {
26248
- return stringifyDelegateTaskResult(createFailedResult(ctx.sessionID, "unknown_agent", `Unknown or disallowed CrewBee delegate target: ${args.agent}`));
26440
+ return stringifyDelegateTaskResult(createFailedResult(ctx.sessionID, "unknown_agent", `Unknown or disallowed CrewBee delegate target: ${requestedAgent}`));
26249
26441
  }
26250
26442
  if (isSelfDelegate(binding2, target.canonicalAgentId)) {
26251
26443
  return stringifyDelegateTaskResult(createFailedResult(ctx.sessionID, "self_delegate_forbidden", "Do not delegate a CrewBee session back to the same active agent."));
26252
26444
  }
26253
- const title = createDelegatedTitle(target.canonicalAgentId, args.prompt);
26445
+ const title = args.description ?? createDelegatedTitle(target.canonicalAgentId, args.prompt);
26254
26446
  const child = await resolveChildSession({
26255
26447
  args,
26256
26448
  client: input.client,
@@ -26290,6 +26482,7 @@ function createDelegateTools(input) {
26290
26482
  anchor
26291
26483
  });
26292
26484
  input.store.putTask(record2);
26485
+ input.store.setTaskStatus(record2.taskRef, "running");
26293
26486
  launchBackground({
26294
26487
  args,
26295
26488
  client: input.client,
@@ -26299,10 +26492,11 @@ function createDelegateTools(input) {
26299
26492
  sessionID,
26300
26493
  taskRef: record2.taskRef
26301
26494
  });
26302
- ctx.metadata({ title, metadata: { sessionId: sessionID, taskRef: record2.taskRef, agent: target.canonicalAgentId } });
26495
+ ctx.metadata({ title, metadata: { sessionId: sessionID, taskId: sessionID, taskRef: record2.taskRef, agent: target.canonicalAgentId, mode: "background" } });
26303
26496
  return stringifyDelegateTaskResult({
26304
26497
  status: "running",
26305
26498
  session_id: sessionID,
26499
+ task_id: sessionID,
26306
26500
  task_ref: record2.taskRef,
26307
26501
  message: "Delegated session launched in background.",
26308
26502
  resume_supported: true
@@ -26315,15 +26509,21 @@ function createDelegateTools(input) {
26315
26509
  task_ref: zod_default.string().describe("CrewBee background task reference")
26316
26510
  },
26317
26511
  async execute(args) {
26318
- const task = input.store.getTask(args.task_ref);
26319
- if (!task) {
26512
+ let task2 = input.store.getTask(args.task_ref);
26513
+ if (!task2) {
26320
26514
  return stringifyDelegateStatusResult({ status: "failed", task_ref: args.task_ref, message: "Unknown background task reference." });
26321
26515
  }
26516
+ if (task2.status === "queued" || task2.status === "running") {
26517
+ const message = await extractAssistantText(input.client, task2.sessionID, task2.anchor).catch(() => void 0);
26518
+ if (message) {
26519
+ task2 = input.store.setTaskStatus(task2.taskRef, "completed", { message }) ?? task2;
26520
+ }
26521
+ }
26322
26522
  return stringifyDelegateStatusResult({
26323
- status: task.status,
26324
- session_id: task.sessionID,
26325
- task_ref: task.taskRef,
26326
- message: task.message
26523
+ status: task2.status,
26524
+ session_id: task2.sessionID,
26525
+ task_ref: task2.taskRef,
26526
+ message: task2.message
26327
26527
  });
26328
26528
  }
26329
26529
  });
@@ -26333,37 +26533,37 @@ function createDelegateTools(input) {
26333
26533
  task_ref: zod_default.string().describe("CrewBee background task reference")
26334
26534
  },
26335
26535
  async execute(args) {
26336
- const task = input.store.getTask(args.task_ref);
26337
- if (!task) {
26536
+ const task2 = input.store.getTask(args.task_ref);
26537
+ if (!task2) {
26338
26538
  return stringifyDelegateCancelResult({ ok: false, task_ref: args.task_ref, message: "Unknown background task reference." });
26339
26539
  }
26340
- if (task.status === "completed" || task.status === "failed" || task.status === "cancelled") {
26540
+ if (task2.status === "completed" || task2.status === "failed" || task2.status === "cancelled") {
26341
26541
  return stringifyDelegateCancelResult({
26342
26542
  ok: false,
26343
- task_ref: task.taskRef,
26344
- session_id: task.sessionID,
26345
- message: `Task is already ${task.status}.`
26543
+ task_ref: task2.taskRef,
26544
+ session_id: task2.sessionID,
26545
+ message: `Task is already ${task2.status}.`
26346
26546
  });
26347
26547
  }
26348
- const aborted2 = await input.client.session.abort({ path: { id: task.sessionID } }).then(() => true).catch(() => false);
26548
+ const aborted2 = await input.client.session.abort({ path: { id: task2.sessionID } }).then(() => true).catch(() => false);
26349
26549
  if (!aborted2) {
26350
26550
  return stringifyDelegateCancelResult({
26351
26551
  ok: false,
26352
- task_ref: task.taskRef,
26353
- session_id: task.sessionID,
26552
+ task_ref: task2.taskRef,
26553
+ session_id: task2.sessionID,
26354
26554
  message: "Failed to cancel the delegated session."
26355
26555
  });
26356
26556
  }
26357
- input.store.setTaskStatus(task.taskRef, "cancelled", { message: "Delegated session cancelled." });
26557
+ input.store.setTaskStatus(task2.taskRef, "cancelled", { message: "Delegated session cancelled." });
26358
26558
  return stringifyDelegateCancelResult({
26359
26559
  ok: true,
26360
- task_ref: task.taskRef,
26361
- session_id: task.sessionID,
26560
+ task_ref: task2.taskRef,
26561
+ session_id: task2.sessionID,
26362
26562
  message: "Delegated session cancelled."
26363
26563
  });
26364
26564
  }
26365
26565
  });
26366
- return { delegate_task, delegate_status, delegate_cancel };
26566
+ return { task, delegate_status, delegate_cancel };
26367
26567
  }
26368
26568
 
26369
26569
  // src/adapters/opencode/system-transform-hook.ts
@@ -26404,36 +26604,14 @@ function createSystemTransformHook(bindings, getLoadIssues = () => []) {
26404
26604
  }
26405
26605
 
26406
26606
  // src/adapters/opencode/tool-hooks.ts
26407
- function isRecord6(value) {
26408
- return typeof value === "object" && value !== null && !Array.isArray(value);
26409
- }
26410
- function sanitizeNativeTaskParameters(value) {
26411
- if (Array.isArray(value)) {
26412
- return value.map((entry) => sanitizeNativeTaskParameters(entry));
26413
- }
26414
- if (!isRecord6(value)) {
26415
- return value;
26416
- }
26417
- const next = Object.fromEntries(
26418
- Object.entries(value).map(([key, entry]) => [key, sanitizeNativeTaskParameters(entry)])
26419
- );
26420
- const properties = next.properties;
26421
- if (isRecord6(properties) && isRecord6(properties.subagent_type)) {
26422
- properties.subagent_type = {
26423
- type: "string",
26424
- description: "Disabled for CrewBee Agent Team sessions. Use delegate_task with an agent listed in the current Agent Profile collaboration section."
26425
- };
26426
- }
26427
- return next;
26428
- }
26429
26607
  function buildRetryGuidance(result) {
26430
26608
  if (!result.error_code) {
26431
26609
  return void 0;
26432
26610
  }
26433
26611
  const fixes = {
26434
- missing_agent: 'Fix: include `agent="reviewer"` or another CrewBee member id.',
26435
- unknown_agent: "Fix: use a valid CrewBee member id or projected alias.",
26436
- invalid_session_id: "Fix: use a delegated `session_id` previously returned by `delegate_task`.",
26612
+ missing_agent: 'Fix: include `subagent_type="reviewer"` or another CrewBee member id.',
26613
+ unknown_agent: "Fix: use a valid CrewBee member id or projected alias as `subagent_type`.",
26614
+ invalid_session_id: "Fix: use a delegated `task_id` previously returned by `task`.",
26437
26615
  agent_session_mismatch: "Fix: resume with the same agent that created the delegated session.",
26438
26616
  unsupported_mode: 'Fix: use `mode="foreground"` or `mode="background"`.',
26439
26617
  nested_delegate_forbidden: "Fix: return the result to the parent session instead of delegating again from a delegated subagent.",
@@ -26444,17 +26622,17 @@ function buildRetryGuidance(result) {
26444
26622
  return void 0;
26445
26623
  }
26446
26624
  return [
26447
- "[delegate_task CALL FAILED - RETRY REQUIRED]",
26625
+ "[task CALL FAILED - RETRY REQUIRED]",
26448
26626
  `Error: ${result.error_code}`,
26449
26627
  fix,
26450
- 'Example: delegate_task(agent="reviewer", prompt="continue review")'
26628
+ 'Example: task(subagent_type="reviewer", prompt="continue review")'
26451
26629
  ].join("\n");
26452
26630
  }
26453
26631
  function withResumeHint(result) {
26454
26632
  if (result.status === "failed" || !result.session_id || result.resume_hint) {
26455
26633
  return result;
26456
26634
  }
26457
- const hint = `to continue: delegate_task(session_id="${result.session_id}", agent="${result.session_id ? "..." : "reviewer"}", prompt="...")`;
26635
+ const hint = `to continue: task(task_id="${result.session_id}", subagent_type="${result.session_id ? "..." : "reviewer"}", prompt="...")`;
26458
26636
  return {
26459
26637
  ...result,
26460
26638
  resume_hint: hint,
@@ -26488,14 +26666,7 @@ ${guidance}` : guidance
26488
26666
  };
26489
26667
  }
26490
26668
  function createToolDefinitionHook(_getAgents) {
26491
- return async (input, output) => {
26492
- if (input.toolID !== "task") {
26493
- return;
26494
- }
26495
- output.description = [
26496
- "CrewBee Agent Team boundary: this native task tool is disabled for CrewBee Team agents. Use delegate_task, and only target agents listed in the current Agent Profile collaboration section."
26497
- ].join("\n");
26498
- output.parameters = sanitizeNativeTaskParameters(output.parameters);
26669
+ return async () => {
26499
26670
  };
26500
26671
  }
26501
26672
  function createToolExecuteBeforeHook(input) {
@@ -26515,14 +26686,24 @@ function createToolExecuteBeforeHook(input) {
26515
26686
  }
26516
26687
  function createToolExecuteAfterHook() {
26517
26688
  return async (input, output) => {
26518
- if (input.tool !== "delegate_task") {
26689
+ if (input.tool !== "task") {
26519
26690
  return;
26520
26691
  }
26521
26692
  const parsed = parseDelegateTaskResult(output.output);
26522
26693
  if (!parsed) {
26523
26694
  return;
26524
26695
  }
26525
- output.output = stringifyDelegateTaskResult(withResumeHint(withRetryGuidance(withEmptyWarning(parsed))));
26696
+ const result = withResumeHint(withRetryGuidance(withEmptyWarning(parsed)));
26697
+ output.output = stringifyDelegateTaskResult(result);
26698
+ if (result.status !== "failed" && result.session_id) {
26699
+ output.title = output.title || "CrewBee task";
26700
+ output.metadata = {
26701
+ ...output.metadata,
26702
+ sessionId: result.session_id,
26703
+ taskId: result.task_id ?? result.session_id,
26704
+ taskRef: result.task_ref
26705
+ };
26706
+ }
26526
26707
  };
26527
26708
  }
26528
26709
 
@@ -26882,7 +27063,7 @@ var OpenCodeCrewBeePlugin = async (ctx) => {
26882
27063
  }
26883
27064
  const teamLibrary = loadDefaultTeamLibrary(ctx.worktree);
26884
27065
  await validateAndLogTeamLibrary(ctx, teamLibrary);
26885
- const initial = createInitialBootstrap(teamLibrary);
27066
+ const initial = await createInitialBootstrap(ctx, teamLibrary);
26886
27067
  await logCrewBee(ctx, "CrewBee plugin initialized", {
26887
27068
  worktree: ctx.worktree,
26888
27069
  projectedAgentCount: initial.boot.projectedAgents.length,