crewbee 0.1.11 → 0.1.12

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 (48) hide show
  1. package/dist/opencode-plugin.mjs +560 -305
  2. package/dist/src/adapters/opencode/bootstrap.d.ts +1 -0
  3. package/dist/src/adapters/opencode/bootstrap.d.ts.map +1 -1
  4. package/dist/src/adapters/opencode/bootstrap.js +1 -0
  5. package/dist/src/adapters/opencode/bootstrap.js.map +1 -1
  6. package/dist/src/adapters/opencode/model-resolution.d.ts +33 -0
  7. package/dist/src/adapters/opencode/model-resolution.d.ts.map +1 -0
  8. package/dist/src/adapters/opencode/model-resolution.js +180 -0
  9. package/dist/src/adapters/opencode/model-resolution.js.map +1 -0
  10. package/dist/src/adapters/opencode/projection.d.ts +4 -1
  11. package/dist/src/adapters/opencode/projection.d.ts.map +1 -1
  12. package/dist/src/adapters/opencode/projection.js +7 -12
  13. package/dist/src/adapters/opencode/projection.js.map +1 -1
  14. package/dist/src/agent-teams/canonical-agent-id.d.ts.map +1 -1
  15. package/dist/src/agent-teams/canonical-agent-id.js +11 -0
  16. package/dist/src/agent-teams/canonical-agent-id.js.map +1 -1
  17. package/dist/src/agent-teams/constants.d.ts +4 -0
  18. package/dist/src/agent-teams/constants.d.ts.map +1 -1
  19. package/dist/src/agent-teams/constants.js +14 -1
  20. package/dist/src/agent-teams/constants.js.map +1 -1
  21. package/dist/src/agent-teams/embedded/coding-team.d.ts.map +1 -1
  22. package/dist/src/agent-teams/embedded/coding-team.js +20 -10
  23. package/dist/src/agent-teams/embedded/coding-team.js.map +1 -1
  24. package/dist/src/agent-teams/filesystem.d.ts +10 -0
  25. package/dist/src/agent-teams/filesystem.d.ts.map +1 -1
  26. package/dist/src/agent-teams/filesystem.js +32 -0
  27. package/dist/src/agent-teams/filesystem.js.map +1 -1
  28. package/dist/src/agent-teams/library.d.ts.map +1 -1
  29. package/dist/src/agent-teams/library.js +7 -2
  30. package/dist/src/agent-teams/library.js.map +1 -1
  31. package/dist/src/agent-teams/parsers.d.ts.map +1 -1
  32. package/dist/src/agent-teams/parsers.js +7 -1
  33. package/dist/src/agent-teams/parsers.js.map +1 -1
  34. package/dist/src/agent-teams/validation.d.ts.map +1 -1
  35. package/dist/src/agent-teams/validation.js +14 -0
  36. package/dist/src/agent-teams/validation.js.map +1 -1
  37. package/dist/src/cli/doctor.d.ts.map +1 -1
  38. package/dist/src/cli/doctor.js +13 -0
  39. package/dist/src/cli/doctor.js.map +1 -1
  40. package/dist/src/core/index.d.ts +13 -1
  41. package/dist/src/core/index.d.ts.map +1 -1
  42. package/dist/src/install/doctor.d.ts.map +1 -1
  43. package/dist/src/install/doctor.js +7 -0
  44. package/dist/src/install/doctor.js.map +1 -1
  45. package/dist/src/install/types.d.ts +2 -0
  46. package/dist/src/install/types.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/templates/crewbee.json +30 -1
@@ -7331,6 +7331,19 @@ var BUILTIN_CODING_TEAM_ID = "coding-team";
7331
7331
  var DEFAULT_EMBEDDED_TEAM_PRIORITY = 0;
7332
7332
  var DEFAULT_FILE_TEAM_PRIORITY = 1;
7333
7333
  var EMBEDDED_TEAM_IDS = [BUILTIN_CODING_TEAM_ID];
7334
+ var BUILTIN_CODING_TEAM_MODEL_PRESET = "sota-2026-05";
7335
+ var BUILTIN_CODING_TEAM_MODEL_FALLBACK = "builtin-role-chain";
7336
+ var BUILTIN_CODING_TEAM_FALLBACK_TO_HOST_DEFAULT = true;
7337
+ var BUILTIN_CODING_TEAM_AGENT_MODELS = {
7338
+ "coding-leader": "openai/gpt-5.5",
7339
+ "coordination-leader": "openai/gpt-5.5",
7340
+ "coding-executor": "openai/gpt-5.5",
7341
+ "codebase-explorer": "openai/gpt-5.4-mini",
7342
+ "web-researcher": "google/gemini-3.1-pro-preview",
7343
+ reviewer: "anthropic/claude-opus-4-7",
7344
+ "principal-advisor": "anthropic/claude-opus-4-7",
7345
+ "multimodal-looker": "google/gemini-3.1-pro-preview"
7346
+ };
7334
7347
 
7335
7348
  // src/agent-teams/documentation.ts
7336
7349
  import { existsSync, readdirSync } from "node:fs";
@@ -9492,7 +9505,27 @@ function createCodingTeamAgents() {
9492
9505
  }
9493
9506
 
9494
9507
  // src/agent-teams/embedded/coding-team.ts
9508
+ var CODING_TEAM_RUNTIME_PROFILES = {
9509
+ "coding-leader": { temperature: 0.2, topP: 0.85, variant: "long-context" },
9510
+ "coordination-leader": { temperature: 0.15, topP: 0.75 },
9511
+ "coding-executor": { temperature: 0.25, topP: 0.9 },
9512
+ "codebase-explorer": { temperature: 0.1, topP: 0.8 },
9513
+ "web-researcher": { temperature: 0.2, topP: 0.85 },
9514
+ reviewer: { temperature: 0.15, topP: 0.75 },
9515
+ "principal-advisor": { temperature: 0.15, topP: 0.75 },
9516
+ "multimodal-looker": { temperature: 0.2, topP: 0.85 }
9517
+ };
9495
9518
  function createEmbeddedCodingTeam() {
9519
+ const runtime = Object.fromEntries(
9520
+ Object.entries(BUILTIN_CODING_TEAM_AGENT_MODELS).map(([agentId, model]) => [
9521
+ agentId,
9522
+ {
9523
+ model,
9524
+ ...CODING_TEAM_RUNTIME_PROFILES[agentId],
9525
+ fallbackToHostDefault: BUILTIN_CODING_TEAM_FALLBACK_TO_HOST_DEFAULT
9526
+ }
9527
+ ])
9528
+ );
9496
9529
  const manifest = {
9497
9530
  id: "coding-team",
9498
9531
  version: "1.0.0",
@@ -9601,16 +9634,7 @@ function createEmbeddedCodingTeam() {
9601
9634
  "\u4ED3\u5E93\u5185\u7814\u7A76\u4E0E\u5916\u90E8\u7814\u7A76\u5FC5\u987B\u5206\u79BB"
9602
9635
  ]
9603
9636
  },
9604
- agentRuntime: {
9605
- "coding-leader": { provider: "openai", model: "gpt-5.5", temperature: 0.2, topP: 0.85, variant: "long-context" },
9606
- "coordination-leader": { provider: "openai", model: "gpt-5.5", temperature: 0.15, topP: 0.75 },
9607
- "coding-executor": { provider: "openai", model: "gpt-5.5", temperature: 0.25, topP: 0.9 },
9608
- "codebase-explorer": { provider: "openai", model: "gpt-5.5", temperature: 0.1, topP: 0.8 },
9609
- "web-researcher": { provider: "openai", model: "gpt-5.5", temperature: 0.2, topP: 0.85 },
9610
- reviewer: { provider: "openai", model: "gpt-5.5", temperature: 0.15, topP: 0.75 },
9611
- "principal-advisor": { provider: "openai", model: "gpt-5.5", temperature: 0.15, topP: 0.75 },
9612
- "multimodal-looker": { provider: "openai", model: "gpt-5.5", temperature: 0.2, topP: 0.85 }
9613
- },
9637
+ agentRuntime: runtime,
9614
9638
  tags: ["\u4EE3\u7801", "leader\u9A71\u52A8", "\u4E0A\u4E0B\u6587\u8FDE\u7EED\u6027", "\u4E3B\u6267\u884C\u8005\u4E2D\u5FC3", "\u8BC4\u5BA1\u4E2D\u5FC3", "\u8BC1\u636E\u9A71\u52A8"]
9615
9639
  };
9616
9640
  const agents = createCodingTeamAgents();
@@ -10228,12 +10252,14 @@ function mapAgentRuntime(raw) {
10228
10252
  const record2 = asRecord(value, `agent_runtime.${agentId}`);
10229
10253
  const options = asOptionalRecord(record2.options);
10230
10254
  const runtime = {
10231
- provider: asString(record2.provider, `agent_runtime.${agentId}.provider`),
10255
+ provider: record2.provider !== void 0 ? asString(record2.provider, `agent_runtime.${agentId}.provider`) : void 0,
10232
10256
  model: asString(record2.model, `agent_runtime.${agentId}.model`),
10233
10257
  temperature: record2.temperature !== void 0 ? Number(record2.temperature) : void 0,
10234
10258
  topP: record2.top_p !== void 0 || record2.topP !== void 0 ? Number(record2.top_p ?? record2.topP) : void 0,
10235
10259
  variant: asOptionalString(record2.variant),
10236
- options: options ? { ...options } : void 0
10260
+ options: options ? { ...options } : void 0,
10261
+ fallbackModels: record2.fallback_models || record2.fallbackModels ? asStringArray(record2.fallback_models ?? record2.fallbackModels, `agent_runtime.${agentId}.fallback_models`) : void 0,
10262
+ fallbackToHostDefault: record2.fallback_to_host_default !== void 0 || record2.fallbackToHostDefault !== void 0 ? asBoolean(record2.fallback_to_host_default ?? record2.fallbackToHostDefault, `agent_runtime.${agentId}.fallback_to_host_default`) : void 0
10237
10263
  };
10238
10264
  return [agentId, runtime];
10239
10265
  })
@@ -10492,6 +10518,31 @@ function getOptionalPriority(value, fallback) {
10492
10518
  function getOptionalString(value) {
10493
10519
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
10494
10520
  }
10521
+ function normalizeConfiguredTeamModelOverride(raw) {
10522
+ const modelPreset = getOptionalString(raw.model_preset ?? raw.modelPreset);
10523
+ const fallback = getOptionalString(raw.fallback);
10524
+ const fallbackToHostDefaultValue = raw.fallback_to_host_default ?? raw.fallbackToHostDefault;
10525
+ const fallbackToHostDefault = typeof fallbackToHostDefaultValue === "boolean" ? fallbackToHostDefaultValue : void 0;
10526
+ const agents = isRecord3(raw.agents) ? Object.fromEntries(
10527
+ Object.entries(raw.agents).flatMap(([agentId, value]) => {
10528
+ if (!isRecord3(value)) {
10529
+ return [];
10530
+ }
10531
+ const model = getOptionalString(value.model);
10532
+ return [[agentId, { ...model ? { model } : {} }]];
10533
+ })
10534
+ ) : void 0;
10535
+ const normalizedAgents = agents && Object.keys(agents).length > 0 ? agents : void 0;
10536
+ if (!modelPreset && !fallback && fallbackToHostDefault === void 0 && !normalizedAgents) {
10537
+ return void 0;
10538
+ }
10539
+ return {
10540
+ modelPreset,
10541
+ fallback,
10542
+ fallbackToHostDefault,
10543
+ agents: normalizedAgents
10544
+ };
10545
+ }
10495
10546
  function createDefaultCodingTeamSource(input) {
10496
10547
  return {
10497
10548
  kind: "embedded",
@@ -10501,14 +10552,21 @@ function createDefaultCodingTeamSource(input) {
10501
10552
  order: -1,
10502
10553
  sourceScope: input.sourceScope,
10503
10554
  sourcePrecedence: input.sourcePrecedence,
10504
- configPath: input.configPath
10555
+ configPath: input.configPath,
10556
+ modelConfigOverride: normalizeConfiguredTeamModelOverride(createDefaultCodingTeamConfigEntry())
10505
10557
  };
10506
10558
  }
10507
10559
  function createDefaultCodingTeamConfigEntry() {
10508
10560
  return {
10509
10561
  id: BUILTIN_CODING_TEAM_ID,
10510
10562
  enabled: true,
10511
- priority: DEFAULT_EMBEDDED_TEAM_PRIORITY
10563
+ priority: DEFAULT_EMBEDDED_TEAM_PRIORITY,
10564
+ model_preset: BUILTIN_CODING_TEAM_MODEL_PRESET,
10565
+ fallback: BUILTIN_CODING_TEAM_MODEL_FALLBACK,
10566
+ fallback_to_host_default: BUILTIN_CODING_TEAM_FALLBACK_TO_HOST_DEFAULT,
10567
+ agents: Object.fromEntries(
10568
+ Object.entries(BUILTIN_CODING_TEAM_AGENT_MODELS).map(([agentId, model]) => [agentId, { model }])
10569
+ )
10512
10570
  };
10513
10571
  }
10514
10572
  function getPackagedTemplateRootPath() {
@@ -10752,7 +10810,8 @@ function normalizeConfiguredTeamEntry(input) {
10752
10810
  order: input.index,
10753
10811
  sourceScope: input.sourceScope,
10754
10812
  sourcePrecedence: input.sourcePrecedence,
10755
- configPath: input.configPath
10813
+ configPath: input.configPath,
10814
+ modelConfigOverride: normalizeConfiguredTeamModelOverride(raw)
10756
10815
  },
10757
10816
  issues: []
10758
10817
  };
@@ -10767,7 +10826,8 @@ function normalizeConfiguredTeamEntry(input) {
10767
10826
  order: input.index,
10768
10827
  sourceScope: input.sourceScope,
10769
10828
  sourcePrecedence: input.sourcePrecedence,
10770
- configPath: input.configPath
10829
+ configPath: input.configPath,
10830
+ modelConfigOverride: normalizeConfiguredTeamModelOverride(raw)
10771
10831
  },
10772
10832
  issues: []
10773
10833
  };
@@ -11068,6 +11128,15 @@ function normalizeTeamAgentIds(input) {
11068
11128
  ])
11069
11129
  ) : void 0
11070
11130
  },
11131
+ modelConfigOverride: input.team.modelConfigOverride ? {
11132
+ ...input.team.modelConfigOverride,
11133
+ agents: input.team.modelConfigOverride.agents ? Object.fromEntries(
11134
+ Object.entries(input.team.modelConfigOverride.agents).map(([agentId, override]) => [
11135
+ agentIdMap.get(agentId) ?? agentId,
11136
+ override
11137
+ ])
11138
+ ) : void 0
11139
+ } : void 0,
11071
11140
  agents: input.team.agents.map((agent) => {
11072
11141
  const canonicalAgentId = agentIdMap.get(agent.metadata.id) ?? agent.metadata.id;
11073
11142
  return {
@@ -11148,6 +11217,9 @@ function validateTeamDefinition(team) {
11148
11217
  return issues;
11149
11218
  }
11150
11219
  for (const [agentId] of Object.entries(manifest.agentRuntime ?? {})) {
11220
+ if (agentId === "$default") {
11221
+ continue;
11222
+ }
11151
11223
  if (!agentIds.has(agentId)) {
11152
11224
  issues.push({
11153
11225
  level: "warning",
@@ -11158,6 +11230,17 @@ function validateTeamDefinition(team) {
11158
11230
  });
11159
11231
  }
11160
11232
  }
11233
+ for (const [agentId] of Object.entries(team.modelConfigOverride?.agents ?? {})) {
11234
+ if (!agentIds.has(agentId)) {
11235
+ issues.push({
11236
+ level: "warning",
11237
+ code: "team_agent_model_override_target_missing",
11238
+ path: `teams.${manifest.id}.agents.${agentId}`,
11239
+ message: `Agent model override '${agentId}' is not defined in Team '${manifest.id}'.`,
11240
+ suggestion: "Remove this model override or add the target Agent profile."
11241
+ });
11242
+ }
11243
+ }
11161
11244
  for (const agent of team.agents) {
11162
11245
  const requestedTools = new Set(agent.runtimeConfig.requestedTools);
11163
11246
  const collaborationTargets = [
@@ -11299,7 +11382,10 @@ function loadDefaultTeamLibrary(input = process.cwd()) {
11299
11382
  continue;
11300
11383
  }
11301
11384
  pendingTeams.push({
11302
- loader: () => ({ team: embeddedTeam.team, issues: [] }),
11385
+ loader: () => ({
11386
+ team: embeddedTeam.team ? { ...embeddedTeam.team, modelConfigOverride: source.modelConfigOverride } : void 0,
11387
+ issues: []
11388
+ }),
11303
11389
  priority: source.priority,
11304
11390
  order: source.order,
11305
11391
  sourcePrecedence: source.sourcePrecedence,
@@ -11313,7 +11399,7 @@ function loadDefaultTeamLibrary(input = process.cwd()) {
11313
11399
  try {
11314
11400
  const loaded = loadTeamDefinitionFromDirectoryWithIssues(source.teamDir, baseDir);
11315
11401
  return {
11316
- team: loaded.team,
11402
+ team: { ...loaded.team, modelConfigOverride: source.modelConfigOverride },
11317
11403
  issues: loaded.issues
11318
11404
  };
11319
11405
  } catch (error45) {
@@ -11717,56 +11803,108 @@ function shouldEmitCrewBeeLog(level = "info") {
11717
11803
  return level === "error" || level === "warn" || isCrewBeeLoggingEnabled();
11718
11804
  }
11719
11805
 
11720
- // src/adapters/opencode/delegation/prompt.ts
11721
- function truncatePrompt(value) {
11722
- const trimmed = value.trim().replace(/\s+/g, " ");
11723
- return trimmed.length <= 80 ? trimmed : `${trimmed.slice(0, 77)}...`;
11806
+ // src/adapters/opencode/capabilities.ts
11807
+ function createOpenCodeCapabilityContract() {
11808
+ return {
11809
+ supportsAgentRegistration: true,
11810
+ supportsAgentSwitching: true,
11811
+ supportsNativeAgentSelection: true,
11812
+ supportsNativeModelSelection: true,
11813
+ supportsCliOverrides: true,
11814
+ supportsSingleExecutorMode: true,
11815
+ supportsTeamCollaboration: false,
11816
+ supportsRuntimeEvents: true,
11817
+ supportsToolDomainInjection: false,
11818
+ supportsSessionLogExport: false
11819
+ };
11724
11820
  }
11725
- function createDelegatedTitle(agent, prompt) {
11726
- return `${agent}: ${truncatePrompt(prompt)}`;
11821
+
11822
+ // src/adapters/opencode/ownership.ts
11823
+ function isRecord4(value) {
11824
+ return typeof value === "object" && value !== null;
11727
11825
  }
11728
- function resolveDelegateModel(target, fallback) {
11729
- if (target.resolvedModel) {
11730
- return {
11731
- providerID: target.resolvedModel.providerID,
11732
- modelID: target.resolvedModel.modelID
11733
- };
11826
+ function isManagedCrewBeeAgentDefinition(value) {
11827
+ if (!isRecord4(value)) {
11828
+ return false;
11734
11829
  }
11735
- return fallback;
11830
+ const options = value.options;
11831
+ if (!isRecord4(options)) {
11832
+ return false;
11833
+ }
11834
+ const crewbee = options.crewbee;
11835
+ return isRecord4(crewbee) && crewbee.managed === true;
11736
11836
  }
11737
- function createDelegationEnvelope(input) {
11738
- return [
11739
- `You are continuing work as CrewBee team member: ${input.agent}.`,
11740
- "",
11741
- `Parent session: ${input.parentSessionID}`,
11742
- `Delegated session: ${input.sessionID}`,
11743
- "",
11744
- "Your delegated objective:",
11745
- input.prompt.trim(),
11746
- "",
11747
- "Execution rules:",
11748
- "- Work only on this delegated objective",
11749
- "- Do not broaden scope",
11750
- "- If you need a skill, decide and load it yourself based on the task",
11751
- "- Prefer a compact result focused on outcome, files changed, blockers, and next step",
11752
- "",
11753
- "Return:",
11754
- "1. Result / conclusion",
11755
- "2. Files changed or inspected",
11756
- "3. Remaining risk or blocker",
11757
- "4. Recommended next step"
11758
- ].join("\n");
11837
+ function createManagedCrewBeeAgentOptions(input) {
11838
+ return {
11839
+ ...input.existingOptions ?? {},
11840
+ crewbee: {
11841
+ managed: true,
11842
+ teamId: input.teamId,
11843
+ canonicalAgentId: input.canonicalAgentId
11844
+ }
11845
+ };
11759
11846
  }
11760
- function createCheckpoint(agent, model) {
11847
+
11848
+ // src/adapters/opencode/config-merge.ts
11849
+ function applyOpenCodeAgentConfigPatch(config2, patch) {
11850
+ const patchKeys = new Set(Object.keys(patch.agent));
11851
+ const nextAgents = Object.fromEntries(
11852
+ Object.entries(config2.agent ?? {}).filter(([key, definition]) => {
11853
+ if (isManagedCrewBeeAgentDefinition(definition) && !patchKeys.has(key)) {
11854
+ return false;
11855
+ }
11856
+ return true;
11857
+ })
11858
+ );
11859
+ const insertedAgentKeys = [];
11860
+ const updatedAgentKeys = [];
11861
+ const skippedAgentKeys = [];
11862
+ for (const [key, definition] of Object.entries(patch.agent)) {
11863
+ if (!(key in nextAgents)) {
11864
+ nextAgents[key] = definition;
11865
+ insertedAgentKeys.push(key);
11866
+ continue;
11867
+ }
11868
+ const existingDefinition = nextAgents[key];
11869
+ if (isManagedCrewBeeAgentDefinition(existingDefinition)) {
11870
+ nextAgents[key] = definition;
11871
+ updatedAgentKeys.push(key);
11872
+ continue;
11873
+ }
11874
+ skippedAgentKeys.push(key);
11875
+ }
11876
+ const nextConfig = {
11877
+ ...config2,
11878
+ agent: nextAgents
11879
+ };
11880
+ if (patch.defaultAgent) {
11881
+ nextConfig.default_agent = patch.defaultAgent;
11882
+ }
11761
11883
  return {
11762
- agent: agent.configKey,
11763
- model,
11764
- tools: [...agent.runtimeConfig.requestedTools]
11884
+ config: nextConfig,
11885
+ insertedAgentKeys,
11886
+ updatedAgentKeys,
11887
+ skippedAgentKeys
11765
11888
  };
11766
11889
  }
11767
11890
 
11768
- // src/adapters/opencode/defaults.ts
11769
- var DEFAULT_OPENCODE_EXECUTION_MODE = "single-executor";
11891
+ // src/adapters/opencode/coexistence.ts
11892
+ function createOpenCodeCoexistencePolicy() {
11893
+ return {
11894
+ pluginId: "crewbee",
11895
+ dependsOnOhMyOpenCode: false,
11896
+ featureDevelopmentMode: "mutually-exclusive",
11897
+ safeWhenCoInstalled: true,
11898
+ reservedConfigKeyPrefix: "",
11899
+ neverMutateForeignAgents: true
11900
+ };
11901
+ }
11902
+ function detectOpenCodeProjectionCollisions(input) {
11903
+ const existingConfigKeys = new Set(input.existingConfigKeys ?? []);
11904
+ return {
11905
+ configKeyCollisions: input.projectedAgents.filter((agent) => existingConfigKeys.has(agent.configKey)).map((agent) => agent.configKey)
11906
+ };
11907
+ }
11770
11908
 
11771
11909
  // src/adapters/opencode/permission-mapper.ts
11772
11910
  var TOOL_MAP = {
@@ -11818,32 +11956,6 @@ function createOpenCodePermissionConfig(permissionRules) {
11818
11956
  return permission;
11819
11957
  }
11820
11958
 
11821
- // src/adapters/opencode/ownership.ts
11822
- function isRecord4(value) {
11823
- return typeof value === "object" && value !== null;
11824
- }
11825
- function isManagedCrewBeeAgentDefinition(value) {
11826
- if (!isRecord4(value)) {
11827
- return false;
11828
- }
11829
- const options = value.options;
11830
- if (!isRecord4(options)) {
11831
- return false;
11832
- }
11833
- const crewbee = options.crewbee;
11834
- return isRecord4(crewbee) && crewbee.managed === true;
11835
- }
11836
- function createManagedCrewBeeAgentOptions(input) {
11837
- return {
11838
- ...input.existingOptions ?? {},
11839
- crewbee: {
11840
- managed: true,
11841
- teamId: input.teamId,
11842
- canonicalAgentId: input.canonicalAgentId
11843
- }
11844
- };
11845
- }
11846
-
11847
11959
  // src/normalize/build-agent-prompt-source.ts
11848
11960
  function isRecord5(value) {
11849
11961
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
@@ -12321,13 +12433,188 @@ function createOpenCodeAgentPrompt(agent, _requestedTools) {
12321
12433
  return [renderPart("Team Contract", teamPart), renderPart("Agent Contract", agentPart)].filter((block) => Boolean(block)).join("\n\n");
12322
12434
  }
12323
12435
 
12436
+ // src/adapters/opencode/model-resolution.ts
12437
+ var HOST_DEFAULT_MODEL_ID = "host-default";
12438
+ var TEAM_MANIFEST_FALLBACK_STRATEGY = "team-manifest";
12439
+ var BUILTIN_ROLE_FALLBACKS = {
12440
+ "coding-leader": ["openai/gpt-5.5-pro", "anthropic/claude-opus-4-7", "google/gemini-3.1-pro-preview"],
12441
+ "coordination-leader": ["anthropic/claude-opus-4-7", "google/gemini-3.1-pro-preview", "openai/gpt-5.4-mini"],
12442
+ "coding-executor": ["openai/gpt-5.5-pro", "anthropic/claude-opus-4-7", "google/gemini-3.1-pro-preview"],
12443
+ "codebase-explorer": ["google/gemini-3.1-flash-lite-preview", "openai/gpt-5.5", "google/gemini-3.1-pro-preview"],
12444
+ "web-researcher": ["openai/gpt-5.5", "anthropic/claude-opus-4-7", "google/gemini-3.1-flash-lite-preview"],
12445
+ reviewer: ["openai/gpt-5.5-pro", "openai/gpt-5.5", "google/gemini-3.1-pro-preview"],
12446
+ "principal-advisor": ["openai/gpt-5.5-pro", "openai/gpt-5.5", "google/gemini-3.1-pro-preview"],
12447
+ "multimodal-looker": ["openai/gpt-5.5", "anthropic/claude-opus-4-7"],
12448
+ "task-orchestrator": ["anthropic/claude-opus-4-7", "google/gemini-3.1-pro-preview", "openai/gpt-5.4-mini"]
12449
+ };
12450
+ function resolveRuntimeModelId(runtime) {
12451
+ if (!runtime?.model) {
12452
+ return void 0;
12453
+ }
12454
+ if (runtime.model === HOST_DEFAULT_MODEL_ID || runtime.model.includes("/")) {
12455
+ return runtime.model;
12456
+ }
12457
+ return runtime.provider ? `${runtime.provider}/${runtime.model}` : runtime.model;
12458
+ }
12459
+ function parseProviderModel(model) {
12460
+ const separator = model.indexOf("/");
12461
+ if (separator <= 0 || separator >= model.length - 1) {
12462
+ return void 0;
12463
+ }
12464
+ return {
12465
+ providerID: model.slice(0, separator),
12466
+ modelID: model.slice(separator + 1)
12467
+ };
12468
+ }
12469
+ function appendUniqueCandidate(candidates, candidate) {
12470
+ if (candidates.some((entry) => entry.model === candidate.model)) {
12471
+ return;
12472
+ }
12473
+ candidates.push(candidate);
12474
+ }
12475
+ function getCandidateModelIds(candidates) {
12476
+ return candidates.map((candidate) => candidate.model);
12477
+ }
12478
+ function createHostDefaultTrace(input) {
12479
+ return {
12480
+ teamId: input.agent.teamId,
12481
+ agentId: input.agent.canonicalAgentId,
12482
+ configuredModel: input.configuredModel,
12483
+ resolvedModel: HOST_DEFAULT_MODEL_ID,
12484
+ source: "host-default",
12485
+ fallback: input.fallbackStrategy,
12486
+ fallbackToHostDefault: input.fallbackToHostDefault,
12487
+ candidates: getCandidateModelIds(input.candidates),
12488
+ skipped: input.skipped,
12489
+ reason: input.reason
12490
+ };
12491
+ }
12492
+ function appendConfiguredModelCandidate(input) {
12493
+ const runtimeModel = resolveRuntimeModelId(input.runtime);
12494
+ const defaultRuntimeModel = resolveRuntimeModelId(input.defaultRuntime);
12495
+ if (input.agentOverrideModel) {
12496
+ appendUniqueCandidate(input.candidates, { model: input.agentOverrideModel, source: "crewbee-json", runtime: input.runtime });
12497
+ return;
12498
+ }
12499
+ if (runtimeModel) {
12500
+ appendUniqueCandidate(input.candidates, { model: runtimeModel, source: "team-manifest", runtime: input.runtime });
12501
+ return;
12502
+ }
12503
+ if (defaultRuntimeModel) {
12504
+ appendUniqueCandidate(input.candidates, { model: defaultRuntimeModel, source: "team-manifest-default", runtime: input.defaultRuntime });
12505
+ }
12506
+ }
12507
+ function resolveAgentModel(input) {
12508
+ const { agent } = input;
12509
+ const teamOverride = agent.sourceTeam.modelConfigOverride;
12510
+ const agentOverride = teamOverride?.agents?.[agent.canonicalAgentId];
12511
+ const runtime = agent.sourceTeam.manifest.agentRuntime?.[agent.canonicalAgentId];
12512
+ const defaultRuntime = agent.sourceTeam.manifest.agentRuntime?.$default;
12513
+ const fallbackStrategy = teamOverride?.fallback ?? (agent.teamId === BUILTIN_CODING_TEAM_ID ? BUILTIN_CODING_TEAM_MODEL_FALLBACK : TEAM_MANIFEST_FALLBACK_STRATEGY);
12514
+ const fallbackToHostDefault = teamOverride?.fallbackToHostDefault ?? runtime?.fallbackToHostDefault ?? defaultRuntime?.fallbackToHostDefault ?? true;
12515
+ const runtimeModel = resolveRuntimeModelId(runtime);
12516
+ const configuredModel = agentOverride?.model ?? runtimeModel ?? resolveRuntimeModelId(defaultRuntime);
12517
+ const candidates = [];
12518
+ appendConfiguredModelCandidate({
12519
+ candidates,
12520
+ agentOverrideModel: agentOverride?.model,
12521
+ runtime,
12522
+ defaultRuntime
12523
+ });
12524
+ if (agentOverride?.model === HOST_DEFAULT_MODEL_ID || !agentOverride?.model && runtimeModel === HOST_DEFAULT_MODEL_ID) {
12525
+ return {
12526
+ trace: createHostDefaultTrace({
12527
+ agent,
12528
+ configuredModel,
12529
+ fallbackStrategy,
12530
+ fallbackToHostDefault,
12531
+ candidates,
12532
+ skipped: [],
12533
+ reason: "host-default selected explicitly"
12534
+ })
12535
+ };
12536
+ }
12537
+ const sourceAgentId = agent.sourceAgent.metadata.sourceId ?? agent.canonicalAgentId;
12538
+ if (fallbackStrategy === BUILTIN_CODING_TEAM_MODEL_FALLBACK && agent.teamId === BUILTIN_CODING_TEAM_ID) {
12539
+ for (const model of BUILTIN_ROLE_FALLBACKS[sourceAgentId] ?? BUILTIN_ROLE_FALLBACKS[agent.canonicalAgentId] ?? []) {
12540
+ appendUniqueCandidate(candidates, { model, source: "builtin-role-chain", runtime });
12541
+ }
12542
+ } else {
12543
+ for (const model of runtime?.fallbackModels ?? defaultRuntime?.fallbackModels ?? []) {
12544
+ appendUniqueCandidate(candidates, { model, source: "team-manifest", runtime });
12545
+ }
12546
+ }
12547
+ const availableModels = input.availableModels ? new Set(input.availableModels) : void 0;
12548
+ const skipped = [];
12549
+ for (const candidate of candidates) {
12550
+ if (candidate.model === HOST_DEFAULT_MODEL_ID) {
12551
+ return {
12552
+ trace: createHostDefaultTrace({
12553
+ agent,
12554
+ configuredModel,
12555
+ fallbackStrategy,
12556
+ fallbackToHostDefault,
12557
+ candidates,
12558
+ skipped,
12559
+ reason: "host-default selected from candidate chain"
12560
+ })
12561
+ };
12562
+ }
12563
+ const parsed = parseProviderModel(candidate.model);
12564
+ if (!parsed) {
12565
+ skipped.push({ model: candidate.model, reason: "model must use provider/model format" });
12566
+ continue;
12567
+ }
12568
+ if (availableModels && !availableModels.has(candidate.model)) {
12569
+ skipped.push({ model: candidate.model, reason: "model not available in current OpenCode environment" });
12570
+ continue;
12571
+ }
12572
+ return {
12573
+ model: {
12574
+ providerID: parsed.providerID,
12575
+ modelID: parsed.modelID,
12576
+ temperature: candidate.runtime?.temperature,
12577
+ topP: candidate.runtime?.topP,
12578
+ variant: candidate.runtime?.variant,
12579
+ options: candidate.runtime?.options,
12580
+ source: candidate.source
12581
+ },
12582
+ trace: {
12583
+ teamId: agent.teamId,
12584
+ agentId: agent.canonicalAgentId,
12585
+ configuredModel,
12586
+ resolvedModel: candidate.model,
12587
+ source: candidate.source,
12588
+ fallback: fallbackStrategy,
12589
+ fallbackToHostDefault,
12590
+ candidates: getCandidateModelIds(candidates),
12591
+ skipped
12592
+ }
12593
+ };
12594
+ }
12595
+ return {
12596
+ trace: createHostDefaultTrace({
12597
+ agent,
12598
+ configuredModel,
12599
+ fallbackStrategy,
12600
+ fallbackToHostDefault,
12601
+ candidates,
12602
+ skipped,
12603
+ reason: fallbackToHostDefault ? "no usable model candidate; fallback_to_host_default enabled" : "no usable model candidate"
12604
+ })
12605
+ };
12606
+ }
12607
+
12324
12608
  // src/adapters/opencode/projection.ts
12325
12609
  function createOpenCodeConfigKey(agent) {
12326
12610
  return agent.canonicalAgentId;
12327
12611
  }
12328
12612
  function createOpenCodeAgentConfig(agent, options = {}) {
12329
12613
  const runtimeConfig = agent.sourceAgent.runtimeConfig;
12330
- const runtimeOverride = agent.sourceTeam.manifest.agentRuntime?.[agent.canonicalAgentId];
12614
+ const modelResolution = resolveAgentModel({
12615
+ agent,
12616
+ availableModels: options.availableModels
12617
+ });
12331
12618
  const availableToolContext = createAvailableToolContext(options.availableTools);
12332
12619
  const requestedTools = mapOpenCodeToolNames(runtimeConfig.requestedTools);
12333
12620
  const availableTools = availableToolContext.hasExplicitTools ? requestedTools.filter((toolId) => isAvailableTool(toolId, availableToolContext)) : [...requestedTools];
@@ -12350,15 +12637,8 @@ function createOpenCodeAgentConfig(agent, options = {}) {
12350
12637
  memory: runtimeConfig.memory,
12351
12638
  hooks: runtimeConfig.hooks
12352
12639
  },
12353
- resolvedModel: runtimeOverride ? {
12354
- providerID: runtimeOverride.provider,
12355
- modelID: runtimeOverride.model,
12356
- temperature: runtimeOverride.temperature,
12357
- topP: runtimeOverride.topP,
12358
- variant: runtimeOverride.variant,
12359
- options: runtimeOverride.options,
12360
- source: "team-manifest"
12361
- } : void 0,
12640
+ resolvedModel: modelResolution.model,
12641
+ modelResolution: modelResolution.trace,
12362
12642
  resolvedTooling: {
12363
12643
  requestedTools,
12364
12644
  availableTools,
@@ -12454,215 +12734,10 @@ function createProjectedAgentTaskAliasHelpLines(agents) {
12454
12734
  });
12455
12735
  }
12456
12736
 
12457
- // src/adapters/opencode/chat-message-hook.ts
12458
- function getDefaultAgent(boot) {
12459
- return boot.mergedConfig?.default_agent ?? boot.configPatch.defaultAgent;
12460
- }
12461
- function resolveModel(agent, model) {
12462
- if (model) {
12463
- return model;
12464
- }
12465
- if (!agent.resolvedModel) {
12466
- return void 0;
12467
- }
12468
- return {
12469
- providerID: agent.resolvedModel.providerID,
12470
- modelID: agent.resolvedModel.modelID
12471
- };
12472
- }
12473
- function createChatMessageHook(input) {
12474
- return async (message, _output) => {
12475
- const boot = input.getBoot();
12476
- const selected = message.agent ?? getDefaultAgent(boot);
12477
- if (!selected) {
12478
- return;
12479
- }
12480
- const agent = resolveProjectedAgentSelection(boot.projectedAgents, {
12481
- configKey: selected
12482
- });
12483
- if (!agent) {
12484
- return;
12485
- }
12486
- const binding2 = createSessionRuntimeBinding({
12487
- projection: boot.projection,
12488
- sessionID: message.sessionID,
12489
- teamId: agent.teamId,
12490
- canonicalAgentId: agent.canonicalAgentId,
12491
- mode: DEFAULT_OPENCODE_EXECUTION_MODE,
12492
- source: message.agent ? "host-agent-selection" : "plugin-default"
12493
- });
12494
- input.bindings.set(message.sessionID, binding2);
12495
- input.store.setCheckpoint(message.sessionID, createCheckpoint(agent, resolveModel(agent, message.model)));
12496
- };
12497
- }
12498
-
12499
- // src/adapters/opencode/delegation/sdk-response.ts
12500
- function unwrapSdkResponse(value) {
12501
- if (typeof value === "object" && value !== null && "data" in value) {
12502
- return value.data;
12503
- }
12504
- return value;
12505
- }
12506
-
12507
- // src/adapters/opencode/delegation/continuity.ts
12508
- function formatDelegatedSessions(store, sessionID) {
12509
- const sessions = store.getSessionsByParent(sessionID);
12510
- if (sessions.length === 0) {
12511
- return "- None";
12512
- }
12513
- return sessions.map((session) => {
12514
- const task = store.getTaskBySession(session.sessionID);
12515
- return [
12516
- `- ${session.canonicalAgentId}`,
12517
- task?.status ?? "completed",
12518
- task?.description ?? "foreground delegation",
12519
- `session_id=${session.sessionID}`,
12520
- "resume, don't restart"
12521
- ].join(" | ");
12522
- }).join("\n");
12523
- }
12524
- function formatTodoSnapshot(store, sessionID) {
12525
- const todos = store.getTodos(sessionID);
12526
- if (todos.length === 0) {
12527
- return "- None";
12528
- }
12529
- return todos.map((todo) => `- [${todo.status}][${todo.priority ?? "medium"}] ${todo.content}`).join("\n");
12530
- }
12531
- function formatCheckpointSummary(store, sessionID) {
12532
- const checkpoint = store.getCheckpoint(sessionID);
12533
- if (!checkpoint) {
12534
- return "- None";
12535
- }
12536
- return [
12537
- `- agent=${checkpoint.agent}`,
12538
- checkpoint.model ? `- model=${checkpoint.model.providerID}/${checkpoint.model.modelID}` : void 0,
12539
- checkpoint.tools.length > 0 ? `- tools=${checkpoint.tools.join(", ")}` : "- tools=None"
12540
- ].filter(Boolean).join("\n");
12541
- }
12542
- async function captureTodoSnapshot(ctx, store, sessionID) {
12543
- const result = unwrapSdkResponse(await ctx.client.session.todo({ path: { id: sessionID } }).catch(() => []));
12544
- store.setTodos(sessionID, Array.isArray(result) ? result : []);
12545
- }
12546
- function buildCompactionContext(store, sessionID) {
12547
- return [
12548
- "[CrewBee Continuity Context]",
12549
- "",
12550
- "When summarizing this session, preserve the sections below in the compacted summary.",
12551
- "",
12552
- "1. User Requests / Final Goal",
12553
- "2. Work Completed",
12554
- "3. Remaining Tasks",
12555
- "4. Active Working Context",
12556
- "5. Explicit Constraints",
12557
- "6. Agent Verification State",
12558
- "7. Checkpointed Agent Configuration",
12559
- " - include current agent / source agent / model / enabled tools when known",
12560
- "8. Todo Snapshot",
12561
- " - preserve outstanding todos and their status/priority",
12562
- "9. Delegated Agent Sessions",
12563
- " - include agent, status, description, session_id",
12564
- " - instruction: resume, don't restart",
12565
- "",
12566
- "[Checkpointed agent configuration]",
12567
- formatCheckpointSummary(store, sessionID),
12568
- "",
12569
- "[Todo snapshot]",
12570
- formatTodoSnapshot(store, sessionID),
12571
- "",
12572
- "[Runtime-carried delegated sessions]",
12573
- formatDelegatedSessions(store, sessionID)
12574
- ].join("\n");
12575
- }
12576
-
12577
- // src/adapters/opencode/compaction-hook.ts
12578
- function createCompactionHook(ctx, store) {
12579
- return async (input, output) => {
12580
- await captureTodoSnapshot(ctx, store, input.sessionID);
12581
- output.context.push(buildCompactionContext(store, input.sessionID));
12582
- };
12583
- }
12584
-
12585
- // src/adapters/opencode/capabilities.ts
12586
- function createOpenCodeCapabilityContract() {
12587
- return {
12588
- supportsAgentRegistration: true,
12589
- supportsAgentSwitching: true,
12590
- supportsNativeAgentSelection: true,
12591
- supportsNativeModelSelection: true,
12592
- supportsCliOverrides: true,
12593
- supportsSingleExecutorMode: true,
12594
- supportsTeamCollaboration: false,
12595
- supportsRuntimeEvents: true,
12596
- supportsToolDomainInjection: false,
12597
- supportsSessionLogExport: false
12598
- };
12599
- }
12600
-
12601
- // src/adapters/opencode/config-merge.ts
12602
- function applyOpenCodeAgentConfigPatch(config2, patch) {
12603
- const patchKeys = new Set(Object.keys(patch.agent));
12604
- const nextAgents = Object.fromEntries(
12605
- Object.entries(config2.agent ?? {}).filter(([key, definition]) => {
12606
- if (isManagedCrewBeeAgentDefinition(definition) && !patchKeys.has(key)) {
12607
- return false;
12608
- }
12609
- return true;
12610
- })
12611
- );
12612
- const insertedAgentKeys = [];
12613
- const updatedAgentKeys = [];
12614
- const skippedAgentKeys = [];
12615
- for (const [key, definition] of Object.entries(patch.agent)) {
12616
- if (!(key in nextAgents)) {
12617
- nextAgents[key] = definition;
12618
- insertedAgentKeys.push(key);
12619
- continue;
12620
- }
12621
- const existingDefinition = nextAgents[key];
12622
- if (isManagedCrewBeeAgentDefinition(existingDefinition)) {
12623
- nextAgents[key] = definition;
12624
- updatedAgentKeys.push(key);
12625
- continue;
12626
- }
12627
- skippedAgentKeys.push(key);
12628
- }
12629
- const nextConfig = {
12630
- ...config2,
12631
- agent: nextAgents
12632
- };
12633
- if (patch.defaultAgent) {
12634
- nextConfig.default_agent = patch.defaultAgent;
12635
- }
12636
- return {
12637
- config: nextConfig,
12638
- insertedAgentKeys,
12639
- updatedAgentKeys,
12640
- skippedAgentKeys
12641
- };
12642
- }
12643
-
12644
- // src/adapters/opencode/coexistence.ts
12645
- function createOpenCodeCoexistencePolicy() {
12646
- return {
12647
- pluginId: "crewbee",
12648
- dependsOnOhMyOpenCode: false,
12649
- featureDevelopmentMode: "mutually-exclusive",
12650
- safeWhenCoInstalled: true,
12651
- reservedConfigKeyPrefix: "",
12652
- neverMutateForeignAgents: true
12653
- };
12654
- }
12655
- function detectOpenCodeProjectionCollisions(input) {
12656
- const existingConfigKeys = new Set(input.existingConfigKeys ?? []);
12657
- return {
12658
- configKeyCollisions: input.projectedAgents.filter((agent) => existingConfigKeys.has(agent.configKey)).map((agent) => agent.configKey)
12659
- };
12660
- }
12661
-
12662
- // src/adapters/opencode/tool-domain.ts
12663
- function createOpenCodeToolDomainPlan() {
12664
- const implementedTools = listImplementedCrewBeePluginTools().filter((tool) => tool.hostTargets.includes("opencode"));
12665
- const reservedTools = listCrewBeePluginTools().filter((tool) => tool.hostTargets.includes("opencode"));
12737
+ // src/adapters/opencode/tool-domain.ts
12738
+ function createOpenCodeToolDomainPlan() {
12739
+ const implementedTools = listImplementedCrewBeePluginTools().filter((tool) => tool.hostTargets.includes("opencode"));
12740
+ const reservedTools = listCrewBeePluginTools().filter((tool) => tool.hostTargets.includes("opencode"));
12666
12741
  return {
12667
12742
  hostId: "opencode",
12668
12743
  reservedTools,
@@ -12764,7 +12839,8 @@ function createOpenCodeBootstrap(input) {
12764
12839
  const projection = createTeamLibraryProjection(input.teamLibrary);
12765
12840
  const toolDomainPlan = createOpenCodeToolDomainPlan();
12766
12841
  const projectedAgents = createOpenCodeAgentConfigs(projection, {
12767
- availableTools: input.availableTools
12842
+ availableTools: input.availableTools,
12843
+ availableModels: input.availableModels
12768
12844
  });
12769
12845
  const foreignCollisions = getForeignCollisionInputs({
12770
12846
  existingConfig: input.existingConfig,
@@ -12815,6 +12891,185 @@ function createOpenCodeBootstrap(input) {
12815
12891
  };
12816
12892
  }
12817
12893
 
12894
+ // src/adapters/opencode/defaults.ts
12895
+ var DEFAULT_OPENCODE_EXECUTION_MODE = "single-executor";
12896
+
12897
+ // src/adapters/opencode/delegation/prompt.ts
12898
+ function truncatePrompt(value) {
12899
+ const trimmed = value.trim().replace(/\s+/g, " ");
12900
+ return trimmed.length <= 80 ? trimmed : `${trimmed.slice(0, 77)}...`;
12901
+ }
12902
+ function createDelegatedTitle(agent, prompt) {
12903
+ return `${agent}: ${truncatePrompt(prompt)}`;
12904
+ }
12905
+ function resolveDelegateModel(target, fallback) {
12906
+ if (target.resolvedModel) {
12907
+ return {
12908
+ providerID: target.resolvedModel.providerID,
12909
+ modelID: target.resolvedModel.modelID
12910
+ };
12911
+ }
12912
+ return fallback;
12913
+ }
12914
+ function createDelegationEnvelope(input) {
12915
+ return [
12916
+ `You are continuing work as CrewBee team member: ${input.agent}.`,
12917
+ "",
12918
+ `Parent session: ${input.parentSessionID}`,
12919
+ `Delegated session: ${input.sessionID}`,
12920
+ "",
12921
+ "Your delegated objective:",
12922
+ input.prompt.trim(),
12923
+ "",
12924
+ "Execution rules:",
12925
+ "- Work only on this delegated objective",
12926
+ "- Do not broaden scope",
12927
+ "- If you need a skill, decide and load it yourself based on the task",
12928
+ "- Prefer a compact result focused on outcome, files changed, blockers, and next step",
12929
+ "",
12930
+ "Return:",
12931
+ "1. Result / conclusion",
12932
+ "2. Files changed or inspected",
12933
+ "3. Remaining risk or blocker",
12934
+ "4. Recommended next step"
12935
+ ].join("\n");
12936
+ }
12937
+ function createCheckpoint(agent, model) {
12938
+ return {
12939
+ agent: agent.configKey,
12940
+ model,
12941
+ tools: [...agent.runtimeConfig.requestedTools]
12942
+ };
12943
+ }
12944
+
12945
+ // src/adapters/opencode/chat-message-hook.ts
12946
+ function getDefaultAgent(boot) {
12947
+ return boot.mergedConfig?.default_agent ?? boot.configPatch.defaultAgent;
12948
+ }
12949
+ function resolveModel(agent, model) {
12950
+ if (model) {
12951
+ return model;
12952
+ }
12953
+ if (!agent.resolvedModel) {
12954
+ return void 0;
12955
+ }
12956
+ return {
12957
+ providerID: agent.resolvedModel.providerID,
12958
+ modelID: agent.resolvedModel.modelID
12959
+ };
12960
+ }
12961
+ function createChatMessageHook(input) {
12962
+ return async (message, _output) => {
12963
+ const boot = input.getBoot();
12964
+ const selected = message.agent ?? getDefaultAgent(boot);
12965
+ if (!selected) {
12966
+ return;
12967
+ }
12968
+ const agent = resolveProjectedAgentSelection(boot.projectedAgents, {
12969
+ configKey: selected
12970
+ });
12971
+ if (!agent) {
12972
+ return;
12973
+ }
12974
+ const binding2 = createSessionRuntimeBinding({
12975
+ projection: boot.projection,
12976
+ sessionID: message.sessionID,
12977
+ teamId: agent.teamId,
12978
+ canonicalAgentId: agent.canonicalAgentId,
12979
+ mode: DEFAULT_OPENCODE_EXECUTION_MODE,
12980
+ source: message.agent ? "host-agent-selection" : "plugin-default"
12981
+ });
12982
+ input.bindings.set(message.sessionID, binding2);
12983
+ input.store.setCheckpoint(message.sessionID, createCheckpoint(agent, resolveModel(agent, message.model)));
12984
+ };
12985
+ }
12986
+
12987
+ // src/adapters/opencode/delegation/sdk-response.ts
12988
+ function unwrapSdkResponse(value) {
12989
+ if (typeof value === "object" && value !== null && "data" in value) {
12990
+ return value.data;
12991
+ }
12992
+ return value;
12993
+ }
12994
+
12995
+ // src/adapters/opencode/delegation/continuity.ts
12996
+ function formatDelegatedSessions(store, sessionID) {
12997
+ const sessions = store.getSessionsByParent(sessionID);
12998
+ if (sessions.length === 0) {
12999
+ return "- None";
13000
+ }
13001
+ return sessions.map((session) => {
13002
+ const task = store.getTaskBySession(session.sessionID);
13003
+ return [
13004
+ `- ${session.canonicalAgentId}`,
13005
+ task?.status ?? "completed",
13006
+ task?.description ?? "foreground delegation",
13007
+ `session_id=${session.sessionID}`,
13008
+ "resume, don't restart"
13009
+ ].join(" | ");
13010
+ }).join("\n");
13011
+ }
13012
+ function formatTodoSnapshot(store, sessionID) {
13013
+ const todos = store.getTodos(sessionID);
13014
+ if (todos.length === 0) {
13015
+ return "- None";
13016
+ }
13017
+ return todos.map((todo) => `- [${todo.status}][${todo.priority ?? "medium"}] ${todo.content}`).join("\n");
13018
+ }
13019
+ function formatCheckpointSummary(store, sessionID) {
13020
+ const checkpoint = store.getCheckpoint(sessionID);
13021
+ if (!checkpoint) {
13022
+ return "- None";
13023
+ }
13024
+ return [
13025
+ `- agent=${checkpoint.agent}`,
13026
+ checkpoint.model ? `- model=${checkpoint.model.providerID}/${checkpoint.model.modelID}` : void 0,
13027
+ checkpoint.tools.length > 0 ? `- tools=${checkpoint.tools.join(", ")}` : "- tools=None"
13028
+ ].filter(Boolean).join("\n");
13029
+ }
13030
+ async function captureTodoSnapshot(ctx, store, sessionID) {
13031
+ const result = unwrapSdkResponse(await ctx.client.session.todo({ path: { id: sessionID } }).catch(() => []));
13032
+ store.setTodos(sessionID, Array.isArray(result) ? result : []);
13033
+ }
13034
+ function buildCompactionContext(store, sessionID) {
13035
+ return [
13036
+ "[CrewBee Continuity Context]",
13037
+ "",
13038
+ "When summarizing this session, preserve the sections below in the compacted summary.",
13039
+ "",
13040
+ "1. User Requests / Final Goal",
13041
+ "2. Work Completed",
13042
+ "3. Remaining Tasks",
13043
+ "4. Active Working Context",
13044
+ "5. Explicit Constraints",
13045
+ "6. Agent Verification State",
13046
+ "7. Checkpointed Agent Configuration",
13047
+ " - include current agent / source agent / model / enabled tools when known",
13048
+ "8. Todo Snapshot",
13049
+ " - preserve outstanding todos and their status/priority",
13050
+ "9. Delegated Agent Sessions",
13051
+ " - include agent, status, description, session_id",
13052
+ " - instruction: resume, don't restart",
13053
+ "",
13054
+ "[Checkpointed agent configuration]",
13055
+ formatCheckpointSummary(store, sessionID),
13056
+ "",
13057
+ "[Todo snapshot]",
13058
+ formatTodoSnapshot(store, sessionID),
13059
+ "",
13060
+ "[Runtime-carried delegated sessions]",
13061
+ formatDelegatedSessions(store, sessionID)
13062
+ ].join("\n");
13063
+ }
13064
+
13065
+ // src/adapters/opencode/compaction-hook.ts
13066
+ function createCompactionHook(ctx, store) {
13067
+ return async (input, output) => {
13068
+ await captureTodoSnapshot(ctx, store, input.sessionID);
13069
+ output.context.push(buildCompactionContext(store, input.sessionID));
13070
+ };
13071
+ }
13072
+
12818
13073
  // src/adapters/opencode/logging.ts
12819
13074
  async function logCrewBee(ctx, message, extra, level = "info") {
12820
13075
  if (!shouldEmitCrewBeeLog(level)) {