diff --git a/FORK.md b/FORK.md index 039069c2ac58f..0c589dc17fd14 100644 --- a/FORK.md +++ b/FORK.md @@ -529,7 +529,7 @@ migrations after upstream migrations. 106. Deferred Crew assignments ([#745](https://github.com/Jacksondr5/j5code/issues/745)): `orchestration-v2/runtimeLayer.ts` wraps the shared orchestrator with J5-owned `CrewDeliveryContext.ts` for first-assignment workspace preparation and guards, and supplies J5-owned `CrewTurnContext.ts` to provider turn start and provider turn control. `orchestration-v2/ProviderTurnStartService.ts` asks that service whether the thread is a Crew seat (one indexed read) and delegates only a seat's selected assignment text to it immediately around provider delivery; every other thread keeps upstream's fast path and delivery unchanged, and `CrewDeliveryContext.ts` likewise passes any non-seat thread's dispatch straight through. `orchestration-v2/ProviderTurnControlService.ts` wraps the live session with the service's `steering`, one hook beside upstream's `steerTurn` call, so a message steered into a busy seat carries the current context too. The service builds the approved introduction or net roster changes from the current roster, sends the full introduction again when the provider conversation it reached is replaced (a model or provider switch, or a missing native session rebuilt from history), and records what it sent only after the provider accepts the prompt; a send that never happens (the run was stopped or superseded before `startTurn`) leaves it owed. Editable messages and shared author prefixes stay unchanged, so queued edits, cancellations and reordering cannot consume context. Waiting seats whose Crew is retired fail visibly; a retained worktree guard applies even after retirement. J5 migration 49 owns the context, and `CrewSeatPreparation.ts` uses upstream's persisted preparation path. `orchestration-v2/ProviderTurnStartService.test.ts` and `ProviderTurnControlService.test.ts` exercise the hooks against the real seat context, including a retained and a replaced native conversation and a Stop before the provider send. A seat's thread also keeps what it was told (register D43): after the provider accepts a prompt that carried the introduction or a roster change, `CrewTurnContext.ts` dispatches the server-only `platform-message.record` command with that text, ids derived from the conversation and the text so a retry records once, and a failure to post is logged without failing the turn. `packages/contracts/src/orchestrationV2.ts` appends the command to the internal command union; `orchestration-v2/Orchestrator.ts` adds one `commandThreadId` case, one `dispatch` case and `dispatchPlatformMessageRecord`, which emits the existing `message.updated` and `turn-item.updated` events for the named run with no run created or queued; `ProviderTurnStartService.ts` adds `runId: run.id` to the delivery it already hands the seat service; and `runtimeLayer.ts` builds the orchestrator layers above the two turn services so `CrewTurnContext.layer` can depend on the orchestrator. The client side is J5-owned: `presentCrewContext` in `packages/client-runtime/src/j5/crewNotices.ts`, `CrewNoticeRenderer.tsx` on web and `timeline.tsx` on mobile. `Orchestrator.platform-message.test.ts` proves the command, and `CrewDeliveryContext.test.ts` and its integration test prove the posting. On an advance, retain the hooks at actual delivery and steering after queue selection, shared by every provider and transport, and the internal command with its one decision function. -107. Models for custom members ([#744](https://github.com/Jacksondr5/j5code/issues/744), register D42, Bryant's approval of the upstream edit to `delegateTask`): `packages/contracts/src/settings.ts` imports J5's `CrewMemberModels` schema (`packages/contracts/src/j5/crewMemberModels.ts`) and registers `crewMemberModels`, a nullable list of checked `(providerInstanceId, model)` pairs (never saved is `null`, every model eligible), in the project-scoped key list, project overrides (also in the nullable-override list), server settings and patches. `apps/server/src/mcp/OrchestratorMcpService.ts` gives `delegateTask` an optional `authorizeTarget` input, called right after `resolveTargetRechecking` with the child's project and resolved model selection unless the command already has a receipt, so a plain `delegate_task` is checked on the model the child will actually run on, inherited included. Upstream behavior is unchanged when no hook is passed; J5's `agents/agentDelegation.ts` passes one that calls the J5-owned `CrewMemberModels` service (`apps/server/src/j5/agents/crewMemberModels.ts`), which Crew launches and `j5_spawn_agent` also call. `apps/server/src/mcp/toolkits/worktree/registration.test.ts` stubs that service among the J5 tool dependencies, and `packages/shared/src/projectSettings.test.ts` gains one case for the key's whole-list replace and project override. On an advance, keep the one call after the target resolves and before anything is created. +107. Models for custom members ([#744](https://github.com/Jacksondr5/j5code/issues/744), register D42, Bryant's approval of the upstream edit to `delegateTask`): `packages/contracts/src/settings.ts` imports J5's `CrewMemberModels` and `CrewMemberReasoning` schemas (`packages/contracts/src/j5/crewMemberModels.ts`, `crewMemberReasoning.ts`) and registers `crewMemberModels`, a nullable list of checked `(providerInstanceId, model)` pairs, and `crewMemberReasoning`, the same for `(providerInstanceId, level)` pairs (never saved is `null`, everything eligible), each in the project-scoped key list, project overrides (also in the nullable-override list), server settings and patches: one import line and five lines per key, the second key beside the first. `apps/server/src/mcp/OrchestratorMcpService.ts` gives `delegateTask` an optional `authorizeTarget` input, called right after `resolveTargetRechecking` with the child's project and resolved model selection unless the command already has a receipt, so a plain `delegate_task` is checked on the model the child will actually run on, inherited included. Upstream behavior is unchanged when no hook is passed; J5's `agents/agentDelegation.ts` passes one that calls the J5-owned `CrewMemberModels` service (`apps/server/src/j5/agents/crewMemberModels.ts`), which Crew launches and `j5_spawn_agent` also call; the service checks the model and then the reasoning level of the same resolved selection, so the one hook covers both lists. `apps/server/src/mcp/toolkits/worktree/registration.test.ts` stubs that service among the J5 tool dependencies, and `packages/shared/src/projectSettings.test.ts` gains one case for each key's whole-list replace and project override. On an advance, keep the one call after the target resolves and before anything is created. ## Pin and upstream advance runbook diff --git a/apps/server/src/j5/a2a/CrewLaunchService.test.ts b/apps/server/src/j5/a2a/CrewLaunchService.test.ts index 3bba281f006ac..b30fcbeac8b33 100644 --- a/apps/server/src/j5/a2a/CrewLaunchService.test.ts +++ b/apps/server/src/j5/a2a/CrewLaunchService.test.ts @@ -85,7 +85,14 @@ const createdAt = DateTime.makeUnsafe("2026-09-09T16:00:00.000Z"); const provider = ( instanceId: string, driver: string, - models: ReadonlyArray<{ slug: string; options: ReadonlyArray }>, + models: ReadonlyArray<{ + slug: string; + options: ReadonlyArray; + /** The option the model runs at when a selection names none. */ + defaultOption?: string; + /** A model that advertises no reasoning option at all. */ + noReasoning?: true; + }>, ): ServerProvider => ({ instanceId: ProviderInstanceId.make(instanceId), driver: ProviderDriverKind.make(driver), @@ -103,14 +110,20 @@ const provider = ( name: model.slug, isCustom: false, capabilities: { - optionDescriptors: [ - { - id: driver === "codex" ? "reasoningEffort" : "effort", - label: "Reasoning", - type: "select", - options: model.options.map((id) => ({ id, label: id })), - }, - ], + optionDescriptors: model.noReasoning + ? [] + : [ + { + id: driver === "codex" ? "reasoningEffort" : "effort", + label: "Reasoning", + type: "select", + options: model.options.map((id) => ({ + id, + label: id, + ...(id === model.defaultOption ? { isDefault: true } : {}), + })), + }, + ], }, })), }); @@ -2456,15 +2469,16 @@ it.effect("a persona keeps its own model off the list, until its model is overri model: own!.modelSelection.model, }; // Editing a field on the roster card freezes the persona's model into the seat; it is the - // same model, so the seat still keeps it, with or without the options the card carried. + // same model and level, so the seat still keeps it. const [frozen] = yield* launcher.resolveSeats(captain, [ { ...persona, modelSelection: own!.modelSelection, runtimeMode: "approval-required" }, ]); assert.equal(frozen!.modelSelection.model, personaModel.model); - const [bare] = yield* launcher.resolveSeats(captain, [ - { ...persona, modelSelection: personaModel }, - ]); - assert.equal(bare!.modelSelection.model, personaModel.model); + // Naming no reasoning value is not keeping the persona's: it runs at the model's default. + const bare = yield* launcher + .resolveSeats(captain, [{ ...persona, modelSelection: personaModel }]) + .pipe(Effect.flip); + assert.equal(bare._tag, "CrewLaunchModelNotEligibleError"); // A different model on the card makes it a custom choice, held to the list. const other = ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"].find( (model) => model !== personaModel.model, @@ -2518,3 +2532,222 @@ it.effect( }).pipe(Effect.provide(layer)); }).pipe(Effect.scoped), ); + +it.effect("a persona seat on either route's level is unchanged; another level is checked", () => + Effect.gen(function* () { + const { layer, captain } = yield* eligibilityFixture({ + providers: [ + codexModels("gpt-5.6-sol"), + provider("claudeAgent", "claudeAgent", [ + { slug: "claude-opus-5", options: ["high", "low"] }, + ]), + ], + settings: { crewMemberReasoning: [] }, + }); + yield* Effect.gen(function* () { + const launcher = yield* CrewLaunchService; + const seat = (level: string) => ({ + workspace: { type: "shared" as const }, + name: "builder", + agentId: "builder", + reason: "Builds", + runtimeMode: "approval-required" as const, + modelSelection: { + instanceId: ProviderInstanceId.make("claudeAgent"), + model: "claude-opus-5", + options: [{ id: "effort", value: level }], + }, + }); + yield* launcher.resolveSeats(captain, [seat("high")]); + const refused = yield* launcher.resolveSeats(captain, [seat("low")]).pipe(Effect.flip); + assert.equal(refused._tag, "CrewLaunchModelNotEligibleError"); + assert.include(refused.message, "Reasoning level low"); + }).pipe(Effect.provide(layer)); + }).pipe(Effect.scoped), +); + +const codexLevel = (level: string) => ({ instanceId: ProviderInstanceId.make("codex"), level }); +const solAt = (value: string) => ({ ...sol, options: [{ id: "reasoningEffort", value }] }); +const terraAt = (value: string) => ({ ...terra, options: [{ id: "reasoningEffort", value }] }); +// The Captain runs on gpt-5.6-sol with no explicit level, so it runs at the model's default. +const reasoningProviders = [ + provider("codex", "codex", [ + { slug: "gpt-5.6-sol", options: ["low", "medium", "high"], defaultOption: "medium" }, + { slug: "gpt-5.6-terra", options: ["high", "xhigh"] }, + { slug: "gpt-5.6-luna", options: [], noReasoning: true }, + ]), +]; + +it.effect( + "a saved level list holds a custom seat to its checked levels and names what to use", + () => + Effect.gen(function* () { + const { layer, captain, commands } = yield* eligibilityFixture({ + providers: reasoningProviders, + settings: { crewMemberReasoning: [codexLevel("low"), codexLevel("high")] }, + }); + yield* Effect.gen(function* () { + const launcher = yield* CrewLaunchService; + const checked = yield* launcher.resolveSeats(captain, [ + customSeat("low", solAt("low")), + customSeat("high", solAt("high")), + ]); + assert.lengthOf(checked, 2); + const refused = yield* launcher + .resolveSeats(captain, [customSeat("medium", solAt("medium"))]) + .pipe(Effect.flip); + assert.equal(refused._tag, "CrewLaunchModelNotEligibleError"); + for (const part of [ + "Reasoning level medium of gpt-5.6-sol on codex", + "Billing Migration", + "Models for custom members in Agent Setup", + "Eligible levels for gpt-5.6-sol: low, high.", + ]) + assert.include(refused.message, part); + // Another model's levels are listed for that model, not this one's. + const terraRefused = yield* launcher + .resolveSeats(captain, [customSeat("terra", terraAt("xhigh"))]) + .pipe(Effect.flip); + assert.include(terraRefused.message, "Eligible levels for gpt-5.6-terra: high."); + // Approving the roster goes through the same check, and nothing is created. + const launched = yield* launcher + .launch({ + providerSessionId: "session", + requestKey: "launch-ineligible-level", + captain, + displayName: "Crew", + seats: [customSeat("medium", solAt("medium"))], + brief: "Work.", + }) + .pipe(Effect.flip); + assert.equal(launched._tag, "CrewLaunchModelNotEligibleError"); + assert.lengthOf(yield* Ref.get(commands), 0); + }).pipe(Effect.provide(layer)); + }).pipe(Effect.scoped), +); + +it.effect( + "a custom seat with no explicit level runs at the model's default, which is checked", + () => + Effect.gen(function* () { + // The Captain's own selection names no level, so a seat that inherits it runs at medium. + const refusing = yield* eligibilityFixture({ + providers: reasoningProviders, + settings: { crewMemberReasoning: [codexLevel("high")] }, + }); + yield* Effect.gen(function* () { + const launcher = yield* CrewLaunchService; + const refused = yield* launcher + .resolveSeats(refusing.captain, [customSeat("inherits")]) + .pipe(Effect.flip); + assert.include(refused.message, "Reasoning level medium of gpt-5.6-sol"); + }).pipe(Effect.provide(refusing.layer)); + const allowing = yield* eligibilityFixture({ + providers: reasoningProviders, + settings: { crewMemberReasoning: [codexLevel("medium")] }, + }); + yield* Effect.gen(function* () { + const launcher = yield* CrewLaunchService; + yield* launcher.resolveSeats(allowing.captain, [customSeat("inherits")]); + }).pipe(Effect.provide(allowing.layer)); + }).pipe(Effect.scoped), +); + +it.effect( + "a saved empty level list makes no level eligible, but a model with none is not held", + () => + Effect.gen(function* () { + const { layer, captain } = yield* eligibilityFixture({ + providers: reasoningProviders, + settings: { crewMemberReasoning: [] }, + }); + yield* Effect.gen(function* () { + const launcher = yield* CrewLaunchService; + const refused = yield* launcher + .resolveSeats(captain, [customSeat("inherits")]) + .pipe(Effect.flip); + assert.include(refused.message, "No reasoning level of gpt-5.6-sol is eligible"); + yield* launcher.resolveSeats(captain, [ + customSeat("plain", { instanceId: sol.instanceId, model: "gpt-5.6-luna" }), + ]); + }).pipe(Effect.provide(layer)); + }).pipe(Effect.scoped), +); + +it.effect( + "the model list is checked before the level, and a level new to the catalog starts unchecked", + () => + Effect.gen(function* () { + const { layer, captain } = yield* eligibilityFixture({ + providers: reasoningProviders, + // Saved when terra offered only xhigh; high arrived later. + settings: { + crewMemberModels: [terra], + crewMemberReasoning: [codexLevel("xhigh")], + }, + }); + yield* Effect.gen(function* () { + const launcher = yield* CrewLaunchService; + const modelFirst = yield* launcher + .resolveSeats(captain, [customSeat("sol", solAt("high"))]) + .pipe(Effect.flip); + assert.include(modelFirst.message, "Model gpt-5.6-sol on codex"); + yield* launcher.resolveSeats(captain, [customSeat("known", terraAt("xhigh"))]); + const fresh = yield* launcher + .resolveSeats(captain, [customSeat("fresh", terraAt("high"))]) + .pipe(Effect.flip); + assert.include(fresh.message, "Reasoning level high of gpt-5.6-terra"); + }).pipe(Effect.provide(layer)); + }).pipe(Effect.scoped), +); + +it.effect("a persona keeps its own level off the list, until its level is changed", () => + Effect.gen(function* () { + const levels = ["low", "medium", "high", "xhigh"]; + const { layer, captain } = yield* eligibilityFixture({ + providers: [ + provider( + "codex", + "codex", + ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"].map((slug) => ({ + slug, + options: levels, + })), + ), + ], + settings: { crewMemberReasoning: [] }, + }); + yield* Effect.gen(function* () { + const launcher = yield* CrewLaunchService; + const persona = { + workspace: { type: "shared" as const }, + name: "builder", + agentId: "builder", + reason: "Builds", + }; + const [own] = yield* launcher.resolveSeats(captain, [persona]); + // The card freezes the persona's whole selection into the seat; unchanged, it is not held. + yield* launcher.resolveSeats(captain, [ + { ...persona, modelSelection: own!.modelSelection, runtimeMode: "approval-required" }, + ]); + const personaLevel = own!.modelSelection.options?.find( + (option) => option.id === "reasoningEffort", + )?.value; + const otherLevel = levels.find((level) => level !== personaLevel)!; + const refused = yield* launcher + .resolveSeats(captain, [ + { + ...persona, + modelSelection: { + instanceId: own!.modelSelection.instanceId, + model: own!.modelSelection.model, + options: [{ id: "reasoningEffort", value: otherLevel }], + }, + }, + ]) + .pipe(Effect.flip); + assert.equal(refused._tag, "CrewLaunchModelNotEligibleError"); + assert.include(refused.message, `Reasoning level ${otherLevel}`); + }).pipe(Effect.provide(layer)); + }).pipe(Effect.scoped), +); diff --git a/apps/server/src/j5/a2a/CrewLaunchService.ts b/apps/server/src/j5/a2a/CrewLaunchService.ts index 831df5ce5ab1f..cccca393fcb3e 100644 --- a/apps/server/src/j5/a2a/CrewLaunchService.ts +++ b/apps/server/src/j5/a2a/CrewLaunchService.ts @@ -1,4 +1,4 @@ -import { CrewSeatWorkspace } from "@t3tools/contracts/j5"; +import { CrewSeatWorkspace, crewMemberSelectionLevel } from "@t3tools/contracts/j5"; import { describeCrewSeatRuntime, materializeCrewModelSelection, @@ -187,7 +187,7 @@ class CrewLaunchSeatUnavailableError extends Data.TaggedError("CrewLaunchSeatUna } } -/** A custom seat's model is not on the project's "Models for custom members" list. */ +/** A custom seat's model or reasoning level is not on the project's "Models for custom members" lists. */ class CrewLaunchModelNotEligibleError extends Data.TaggedError("CrewLaunchModelNotEligibleError")<{ readonly seatName: string; readonly detail: string; @@ -319,8 +319,17 @@ export const layer = Layer.effect( ), ); const resolved: Array = []; - // `custom` seats run on whatever the project's list of models for custom members allows. A - // persona seat that keeps its persona's own model is not custom and skips the list. + // The reasoning level a selection runs at on its model, explicit or the model's default. + const levelOf = (selection: ModelSelection) => + crewMemberSelectionLevel( + providers + .find((candidate) => candidate.instanceId === selection.instanceId) + ?.models.find((model) => model.slug === selection.model), + selection.options, + ); + // `custom` seats run on whatever the project's lists of models and reasoning levels for + // custom members allow. A persona seat that keeps its persona's own model and level is not + // custom and skips the lists. const resolveSelection = Effect.fn("j5.a2a.crewLaunch.resolveSelection")(function* ( seat: CrewLaunchSeat, selection: ModelSelection, @@ -433,15 +442,18 @@ export const layer = Layer.effect( const definition = catalog.definitions.find(({ id }) => id === agentId); // Editing any field on the roster card freezes the model it showed into the seat, and // that is the fallback route when the primary's provider was signed out at proposal - // time. A seat counts as keeping the persona's model by matching either route, never by - // its absence. + // time. A seat counts as keeping the persona's model and level by matching either route, + // never by its absence. const frozen = seat.modelSelection; const frozenDriver = providers.find( (candidate) => candidate.instanceId === frozen.instanceId, )?.driver; const keepsPersonaModel = definition?.modelRoute.some( - (target) => target.driver === frozenDriver && target.model === frozen.model, + (target) => + target.driver === frozenDriver && + target.model === frozen.model && + target.reasoningEffort === levelOf(frozen), ) ?? false; const { modelSelection, provider } = yield* resolveSelection( seat, diff --git a/apps/server/src/j5/a2a/SpawnAgentService.ts b/apps/server/src/j5/a2a/SpawnAgentService.ts index 549fb547c35c5..36a14f2597f8c 100644 --- a/apps/server/src/j5/a2a/SpawnAgentService.ts +++ b/apps/server/src/j5/a2a/SpawnAgentService.ts @@ -479,8 +479,9 @@ const spawn = Effect.fn("j5.a2a.spawnAgent")(function* ( }), ), ); - // A persona runs on its own model. A plain agent runs on one the project's list allows, and a - // retry finishes the agent its first attempt created, so only a first attempt is held to it. + // A persona runs on its own model. A plain agent runs on a model and level the project's + // lists allow, and a retry finishes the agent its first attempt created, so only a first + // attempt is held to them. if (persona === undefined && firstAttempt) yield* (yield* CrewMemberModels) .assertEligible({ projectId: target, selection: modelSelection }) @@ -488,7 +489,7 @@ const spawn = Effect.fn("j5.a2a.spawnAgent")(function* ( Effect.mapError((error) => stateError( error.message, - "Retry j5_spawn_agent with one of the eligible models, or name a persona.", + "Retry j5_spawn_agent with one of the eligible models or levels, or name a persona.", ), ), ); diff --git a/apps/server/src/j5/a2a/mcp/handlers.ts b/apps/server/src/j5/a2a/mcp/handlers.ts index b14e6a10c1286..6ad677a7289c4 100644 --- a/apps/server/src/j5/a2a/mcp/handlers.ts +++ b/apps/server/src/j5/a2a/mcp/handlers.ts @@ -228,7 +228,7 @@ const crewProposalNextStep = (error: CrewProposalError) => : error._tag === "CrewLaunchSeatUnavailableError" ? "Choose a different persona from j5_list_personas or ask the user to fix that persona, then retry." : error._tag === "CrewLaunchModelNotEligibleError" - ? "Give that custom member one of the eligible models above, or leave its model unset to use yours if yours is eligible, then retry." + ? "Give that custom member one of the eligible models or levels above, or leave its model unset to use yours if yours is eligible, then retry." : error._tag === "CrewLaunchCapError" ? "The crew is full. Work with the seats it has, or propose a new crew for the extra work." : error._tag === "CrewLaunchSeatConflictError" diff --git a/apps/server/src/j5/a2a/mcp/tools.ts b/apps/server/src/j5/a2a/mcp/tools.ts index 0bb759c336fcc..4ac5400c31e2b 100644 --- a/apps/server/src/j5/a2a/mcp/tools.ts +++ b/apps/server/src/j5/a2a/mcp/tools.ts @@ -576,16 +576,16 @@ export const J5ArchiveCrewFailure = Schema.Struct({ export type J5ArchiveCrewFailure = typeof J5ArchiveCrewFailure.Type; export const J5_SPAWN_AGENT_DESCRIPTION = - "Spawn a Peer Agent: a full-citizen teammate with its own top-level thread, starting on your brief as its first turn. It joins your project unless you name another with project_id or set scratch for none, and records you as its immutable spawner; in your own project it is placed under you. It is addressable the moment this returns. In your brief, tell the new agent what it should do first and whether it should reply to you. Choose provider, model, and reasoning for the work in the brief; see orchestrator_capabilities for what's available. To run a persona from j5_list_personas, set `persona` to its id: the spawn gets that persona's instructions and runtime policy, and provider, model, and reasoning must be one of that persona's declared routes. Without a persona it runs in your permission and interaction modes, or in narrower ones you set with runtime_mode and interaction_mode. Without a persona its model must be one the project's Models for custom members list allows; an ineligible one is refused with the eligible models. Attach files to the brief with attachments. Choose its workspace every time (see the workspace field). A new worktree is prepared after this returns, and the agent begins once it is bound, possibly while the project's setup script is still running; if preparing it fails, the agent's thread shows why, and it is not retried. Reuse client_request_id to retry the same spawn safely; reusing it with any change to the request is refused, so use a fresh one for new work."; + "Spawn a Peer Agent: a full-citizen teammate with its own top-level thread, starting on your brief as its first turn. It joins your project unless you name another with project_id or set scratch for none, and records you as its immutable spawner; in your own project it is placed under you. It is addressable the moment this returns. In your brief, tell the new agent what it should do first and whether it should reply to you. Choose provider, model, and reasoning for the work in the brief; see orchestrator_capabilities for what's available. To run a persona from j5_list_personas, set `persona` to its id: the spawn gets that persona's instructions and runtime policy, and provider, model, and reasoning must be one of that persona's declared routes. Without a persona it runs in your permission and interaction modes, or in narrower ones you set with runtime_mode and interaction_mode. Without a persona its model and reasoning level must be ones the project's Models for custom members lists allow; an ineligible one is refused with the eligible ones. Attach files to the brief with attachments. Choose its workspace every time (see the workspace field). A new worktree is prepared after this returns, and the agent begins once it is bound, possibly while the project's setup script is still running; if preparing it fails, the agent's thread shows why, and it is not retried. Reuse client_request_id to retry the same spawn safely; reusing it with any change to the request is refused, so use a fresh one for new work."; const J5_LIST_AGENTS_DESCRIPTION = "List the personas in this environment: id, purpose, runtime policy, whether each can start now, and the provider, model, and reasoning it would run on. Read this before choosing a persona for j5_spawn_agent or a crew roster so the choice fits the task and the user's budget. Read-only."; export const J5_PROPOSE_CREW_DESCRIPTION = - "Propose the crew you need for the brief you were given. Use it when the user asks for a crew or the work splits into distinct responsibilities that should run at once. Mix saved personas and custom seats in the same roster: call j5_list_personas when choosing a saved persona, or leave persona unset for a custom seat with its own instructions (required) and the brief. Custom seats inherit your harness, model, and reasoning by default and run with full-access unless you set runtime_mode; to choose different ones, set model_selection (instanceId, model, options) and/or runtime_mode using orchestrator_capabilities. A custom seat's model, yours included, must be one the project's Models for custom members list allows; an ineligible one is refused with the eligible models. Saved personas are proposed with their own configuration; only the human may override their runtime before approval. To have the crew follow a playbook, set playbook to a name from j5_playbook_list and give seats the step ids they own (steps, from j5_playbook_read); a step has one owner, steps no seat owns are yours as Captain, and the result reports unowned steps and any step whose persona differs from its seat's. For a crew built from a playbook, staff one seat per distinct persona its steps name, each owning that persona's steps, and propose a custom seat, noted in its reason, where a named persona isn't available. Every seat names its workspace, with the same three choices as j5_spawn_agent. Name the crew for what it is for and give each seat a short lowercase-hyphen name like code-reviewer. By default the user reviews and edits the roster in this thread, then approves or declines. If Auto-approve new Crews is on for your project, the proposed roster is created immediately with no approval card. The result says whether it is open or approved; the launch report arrives here once creation finishes or fails. Approval creates seats without starting turns. Send each member its first assignment when it has work; reuse finished members for follow-up work in the same thread. Each seat keeps its configured access and tool approvals, which may exceed yours. You become the crew's Captain and may command several crews at once; later requests, stops, and archives name the crew they mean. Use j5_send_message for member-to-member, member-to-Captain, and Captain-to-Captain coordination, including findings and direct results; artifacts do not gate these conversations. Reuse client_request_id to retry safely; a changed request is refused, so use a fresh one for new work. This tool works under every sandbox and approval policy, including approval policy never; never refuse the brief because approvals are disabled."; + "Propose the crew you need for the brief you were given. Use it when the user asks for a crew or the work splits into distinct responsibilities that should run at once. Mix saved personas and custom seats in the same roster: call j5_list_personas when choosing a saved persona, or leave persona unset for a custom seat with its own instructions (required) and the brief. Custom seats inherit your harness, model, and reasoning by default and run with full-access unless you set runtime_mode; to choose different ones, set model_selection (instanceId, model, options) and/or runtime_mode using orchestrator_capabilities. A custom seat's model and reasoning level, yours included, must be ones the project's Models for custom members lists allow; an ineligible one is refused with the eligible ones. Saved personas are proposed with their own configuration; only the human may override their runtime before approval. To have the crew follow a playbook, set playbook to a name from j5_playbook_list and give seats the step ids they own (steps, from j5_playbook_read); a step has one owner, steps no seat owns are yours as Captain, and the result reports unowned steps and any step whose persona differs from its seat's. For a crew built from a playbook, staff one seat per distinct persona its steps name, each owning that persona's steps, and propose a custom seat, noted in its reason, where a named persona isn't available. Every seat names its workspace, with the same three choices as j5_spawn_agent. Name the crew for what it is for and give each seat a short lowercase-hyphen name like code-reviewer. By default the user reviews and edits the roster in this thread, then approves or declines. If Auto-approve new Crews is on for your project, the proposed roster is created immediately with no approval card. The result says whether it is open or approved; the launch report arrives here once creation finishes or fails. Approval creates seats without starting turns. Send each member its first assignment when it has work; reuse finished members for follow-up work in the same thread. Each seat keeps its configured access and tool approvals, which may exceed yours. You become the crew's Captain and may command several crews at once; later requests, stops, and archives name the crew they mean. Use j5_send_message for member-to-member, member-to-Captain, and Captain-to-Captain coordination, including findings and direct results; artifacts do not gate these conversations. Reuse client_request_id to retry safely; a changed request is refused, so use a fresh one for new work. This tool works under every sandbox and approval policy, including approval policy never; never refuse the brief because approvals are disabled."; export const J5_REQUEST_CREW_MEMBER_DESCRIPTION = - "Add one seat directly to a running crew you command when the work needs expertise the roster lacks. No human approval is needed, regardless of Auto-approve new Crews. Give a seat name, a persona id from j5_list_personas or required instructions for a custom seat, a reason identifying the missing expertise, and its workspace (the same choices as j5_propose_crew). Custom seats inherit your model selection and run with full-access unless you set model_selection or runtime_mode; a custom seat's model must be one the project's Models for custom members list allows, and saved personas use their own configuration. Optionally give a brief; otherwise the seat gets the Crew's brief. On a playbook Crew, steps may claim only unowned step ids from j5_playbook_read. The result returns the updated roster or refuses the seat with its name and reason; creation is reported separately here. The new member waits for its first assignment; send it with j5_send_message when the work is ready. Each member's configured access still controls tool approvals. Captain-only: a member sends the concern to its Captain with j5_send_message. Reuse client_request_id to retry safely; a changed request is refused, so use a fresh one for new work. Works under every approval policy, including approval policy never."; + "Add one seat directly to a running crew you command when the work needs expertise the roster lacks. No human approval is needed, regardless of Auto-approve new Crews. Give a seat name, a persona id from j5_list_personas or required instructions for a custom seat, a reason identifying the missing expertise, and its workspace (the same choices as j5_propose_crew). Custom seats inherit your model selection and run with full-access unless you set model_selection or runtime_mode; a custom seat's model and reasoning level must be ones the project's Models for custom members lists allow, and saved personas use their own configuration. Optionally give a brief; otherwise the seat gets the Crew's brief. On a playbook Crew, steps may claim only unowned step ids from j5_playbook_read. The result returns the updated roster or refuses the seat with its name and reason; creation is reported separately here. The new member waits for its first assignment; send it with j5_send_message when the work is ready. Each member's configured access still controls tool approvals. Captain-only: a member sends the concern to its Captain with j5_send_message. Reuse client_request_id to retry safely; a changed request is refused, so use a fresh one for new work. Works under every approval policy, including approval policy never."; export const J5_STOP_AGENT_DESCRIPTION = "Stop one Peer Agent the way a user Stop does: its running turn is interrupted now, turns already queued behind it, messages you sent it included, are held until a person resumes its queue or the next message reaches it (that message resumes the queue and runs after them, in order), its pull request watches end, and the tasks it delegated stop too. The agent remains, stays readable, and can be messaged again later: stopping halts work, it retires nothing. It reaches any agent on this server, in any project. Reuse client_request_id to retry safely."; diff --git a/apps/server/src/j5/a2a/spawnWorkspace.test.ts b/apps/server/src/j5/a2a/spawnWorkspace.test.ts index fbbeb397111df..72dd3e5f094b7 100644 --- a/apps/server/src/j5/a2a/spawnWorkspace.test.ts +++ b/apps/server/src/j5/a2a/spawnWorkspace.test.ts @@ -371,7 +371,7 @@ const spawnHarness = (input: { { id: "gpt-5.6-sol", label: "GPT-5.6 Sol", - options: [{ id: "reasoningEffort", values: ["high"] }], + options: [{ id: "reasoningEffort", values: ["low", "high"] }], }, ], canRunChildTask: true, @@ -653,6 +653,80 @@ it.effect( }), ); +const codexWithLevels = { + ...codexSolAndTerra, + models: ["gpt-5.6-sol", "gpt-5.6-terra"].map((slug) => ({ + slug, + name: slug, + capabilities: { + optionDescriptors: [ + { + id: "reasoningEffort", + label: "Reasoning", + type: "select", + options: [ + { id: "low", label: "Low" }, + { id: "high", label: "High" }, + ], + }, + ], + }, + })), +} as unknown as ServerProvider; +const lowOnly = { + crewMemberReasoning: [{ instanceId: ProviderInstanceId.make("codex"), level: "low" }], +}; + +it.effect("a plain spawn runs at a reasoning level its project's list allows", () => + Effect.gen(function* () { + const { layer, call, commands } = yield* spawnHarness({ + checkout: { isRepo: true, refName: "j5/main" }, + memberModels: crewMemberModelsLayer({ + providers: [codexWithLevels], + settings: lowOnly, + projectTitle: "Billing Migration", + }), + }); + yield* Effect.gen(function* () { + const refused = yield* call({ ...spawnArgs, client_request_id: "off-list-level" }); + assert.isTrue(refused.isFailure); + for (const part of [ + "Reasoning level high of gpt-5.6-sol on codex", + "Billing Migration", + "Models for custom members in Agent Setup", + "Eligible levels for gpt-5.6-sol: low.", + ]) + assert.include(message(refused), part); + assert.lengthOf(yield* Ref.get(commands), 0, "a refused spawn creates nothing"); + const allowed = yield* call({ + ...spawnArgs, + reasoning: "low", + client_request_id: "on-list-level", + }); + assert.isFalse(allowed.isFailure); + }).pipe(Effect.provide(layer)); + }), +); + +it.effect( + "a retry of a spawn that already created its agent is not held to a level list saved since", + () => + Effect.gen(function* () { + const { layer, call } = yield* spawnHarness({ + checkout: { isRepo: true, refName: "j5/main" }, + existingChildRuntimeMode: "full-access", + memberModels: crewMemberModelsLayer({ + providers: [codexWithLevels], + settings: lowOnly, + }), + }); + yield* Effect.gen(function* () { + const replayed = yield* call({ ...spawnArgs, client_request_id: "already-created" }); + assert.isFalse(replayed.isFailure); + }).pipe(Effect.provide(layer)); + }), +); + it.effect("spawns an agent with no project into a folder of its own", () => Effect.gen(function* () { const { layer, call, commands } = yield* spawnHarness({ diff --git a/apps/server/src/j5/agents/agentDelegation.ts b/apps/server/src/j5/agents/agentDelegation.ts index dd3a029671112..3fa5de4098a15 100644 --- a/apps/server/src/j5/agents/agentDelegation.ts +++ b/apps/server/src/j5/agents/agentDelegation.ts @@ -38,7 +38,7 @@ export type J5DelegateTaskInput = typeof J5DelegateTaskInput.Type; * fallback. */ export const J5_DELEGATE_TASK_DESCRIPTION = - "Start one child agent with only `task`. No parent history. Pass persona=ID when the user writes @persona:ID or asks for a persona by name: the server pins that persona's instructions, provider, model, reasoning, and runtime policy, so omit target and runtimeMode. Give the persona a self-contained task, and if that call fails, report the error instead of substituting a plain child. Without persona, this is a plain J5-tracked child for cross-provider work, for same-provider work the native subagent tool cannot run, or for work the user wants tracked as a J5 task; for an ordinary subagent request, use your provider's native subagent mechanism instead. Without persona the child's model, an inherited one included, must be one the project's Models for custom members list allows; a refusal lists the eligible models to retry with in `target`. Separate checkout or PR per child: `isolation:'worktree'`. Keep `taskId` for `task_status` and `task_cancel`."; + "Start one child agent with only `task`. No parent history. Pass persona=ID when the user writes @persona:ID or asks for a persona by name: the server pins that persona's instructions, provider, model, reasoning, and runtime policy, so omit target and runtimeMode. Give the persona a self-contained task, and if that call fails, report the error instead of substituting a plain child. Without persona, this is a plain J5-tracked child for cross-provider work, for same-provider work the native subagent tool cannot run, or for work the user wants tracked as a J5 task; for an ordinary subagent request, use your provider's native subagent mechanism instead. Without persona the child's model and reasoning level, inherited ones included, must be ones the project's Models for custom members lists allow; a refusal lists the eligible ones to retry with in `target`. Separate checkout or PR per child: `isolation:'worktree'`. Keep `taskId` for `task_status` and `task_cancel`."; /** J5's delegate_task: the upstream tool with the persona extension, registered in place of it. */ export const J5DelegateTaskTool = Tool.make("delegate_task", { @@ -52,7 +52,7 @@ export const J5DelegateTaskTool = Tool.make("delegate_task", { OrchestratorMcpService, ThreadManagementService, ProviderRegistry.ProviderRegistry, - // A plain child's model is held to the project's list of models for custom members. + // A plain child's model and reasoning level are held to the project's lists for custom members. CrewMemberModels, ], }) @@ -67,7 +67,8 @@ export const delegateTask = Effect.fn("j5.delegateTask")(function* (input: J5Del const service = yield* OrchestratorMcpService; const memberModels = yield* CrewMemberModels; // A persona runs on its own model; a plain child, even one that inherits its parent's model, - // runs on one the project's list allows. Upstream calls this with the model it resolved. + // runs on a model and level the project's lists allow. Upstream calls this with the model it + // resolved. return yield* service.delegateTask(scope, { ...delegate, authorizeTarget: ({ projectId, modelSelection }) => @@ -76,7 +77,10 @@ export const delegateTask = Effect.fn("j5.delegateTask")(function* (input: J5Del (error) => new OrchestratorMcpFailure({ code: "model_unavailable", - message: `${error.message} Retry with target set to one of them as providerInstanceId and model.`, + message: + error._tag === "CrewMemberModelNotEligibleError" + ? `${error.message} Retry with target set to one of them as providerInstanceId and model.` + : `${error.message} Retry with target options setting the model's reasoning option to one of them.`, }), ), ), diff --git a/apps/server/src/j5/agents/agentSubagent.integration.test.ts b/apps/server/src/j5/agents/agentSubagent.integration.test.ts index f2edc98c3895f..b2be3912584ee 100644 --- a/apps/server/src/j5/agents/agentSubagent.integration.test.ts +++ b/apps/server/src/j5/agents/agentSubagent.integration.test.ts @@ -49,6 +49,7 @@ const modelSelection = { model: BUILT_IN_AGENT_PERSONAS.scout.modelRoute[0].model, }; const otherModel = "gpt-5.6-other"; +const plainModel = "gpt-5.6-plain"; const provider: ServerProvider = { instanceId: modelSelection.instanceId, driver: ProviderDriverKind.make("codex"), @@ -61,21 +62,28 @@ const provider: ServerProvider = { availability: "available", slashCommands: [], skills: [], - models: [modelSelection.model, otherModel].map((slug) => ({ - slug, - name: "Model", - isCustom: false, - capabilities: { - optionDescriptors: [ - { - id: "reasoningEffort", - label: "Reasoning", - type: "select" as const, - options: [{ id: "high", label: "High" }], - }, - ], - }, - })), + models: [ + ...[modelSelection.model, otherModel].map((slug) => ({ + slug, + name: "Model", + isCustom: false, + capabilities: { + optionDescriptors: [ + { + id: "reasoningEffort", + label: "Reasoning", + type: "select" as const, + options: [ + { id: "high", label: "High", isDefault: true }, + { id: "low", label: "Low" }, + ], + }, + ], + }, + })), + // A model that advertises no reasoning option has no level to hold. + { slug: plainModel, name: "Plain", isCustom: false, capabilities: null }, + ], }; const adapter = { instanceId: modelSelection.instanceId, @@ -329,3 +337,73 @@ it.effect("holds a plain delegated child to the list, inherited model included", assert.include(none.message, "nothing is checked"); }).pipe(Effect.provide(listedLayer)), ); + +it.effect("holds a plain delegated child to the level list, an inherited level included", () => + Effect.gen(function* () { + const { orchestrator, scope } = yield* runningParent; + const settings = yield* ServerSettings.ServerSettingsService; + const asParent = Effect.provideService(McpInvocationContext, scope); + const plain = ( + clientRequestId: string, + target?: { readonly model: string; readonly level?: string }, + ) => + delegateTask({ + task: "Plain child work.", + clientRequestId, + ...(target === undefined + ? {} + : { + target: { + providerInstanceId: modelSelection.instanceId, + model: target.model, + ...(target.level === undefined + ? {} + : { options: [{ id: "reasoningEffort", value: target.level }] }), + }, + }), + }).pipe(asParent); + const level = { instanceId: modelSelection.instanceId, level: "low" }; + + // The parent runs on its model's default level, high, which this list leaves out. + yield* settings.updateSettings({ crewMemberReasoning: [level] }); + const refused = yield* plain("inherits").pipe(Effect.flip); + assert.equal(refused.code, "model_unavailable"); + for (const part of [ + `Reasoning level high of ${modelSelection.model}`, + "Billing Migration", + "Models for custom members in Agent Setup", + `Eligible levels for ${modelSelection.model}: low.`, + "Retry with target options", + ]) + assert.include(refused.message, part); + + // A persona runs on its own level, a model with no reasoning option has nothing to hold, and + // an explicit checked level works. + const persona = yield* delegateTask({ + task: "Return a short evidence brief.", + persona: "scout", + clientRequestId: "persona", + }).pipe(asParent); + assert.equal( + (yield* orchestrator.getThreadProjection(persona.childThreadId)).thread.modelSelection.model, + modelSelection.model, + ); + yield* plain("plain-model", { model: plainModel }); + const explicit = yield* plain("explicit", { model: otherModel, level: "low" }); + assert.equal( + (yield* orchestrator.getThreadProjection(explicit.childThreadId)).thread.modelSelection.model, + otherModel, + ); + const unchecked = yield* plain("unchecked", { model: otherModel, level: "high" }).pipe( + Effect.flip, + ); + assert.include(unchecked.message, `Reasoning level high of ${otherModel}`); + + // A list saved afterwards does not refuse the retry of a delegation already accepted. + yield* settings.updateSettings({ crewMemberReasoning: [] }); + const replayed = yield* plain("explicit", { model: otherModel, level: "low" }); + assert.equal(replayed.childThreadId, explicit.childThreadId); + const none = yield* plain("fresh", { model: otherModel, level: "low" }).pipe(Effect.flip); + assert.include(none.message, "No reasoning level"); + }).pipe(Effect.provide(listedLayer)), +); diff --git a/apps/server/src/j5/agents/crewMemberModels.ts b/apps/server/src/j5/agents/crewMemberModels.ts index 0d5d3ec1c0068..02faf8994f8f2 100644 --- a/apps/server/src/j5/agents/crewMemberModels.ts +++ b/apps/server/src/j5/agents/crewMemberModels.ts @@ -1,7 +1,11 @@ import type { ModelSelection, ProjectId } from "@t3tools/contracts"; import { crewMemberModelRefusal, + crewMemberReasoningRefusal, + crewMemberSelectionLevel, + eligibleCrewMemberLevelsForModel, eligibleCrewMemberModels, + isCrewMemberLevelChecked, isCrewMemberModelChecked, } from "@t3tools/contracts/j5"; import { resolveProjectSettings } from "@t3tools/shared/projectSettings"; @@ -37,18 +41,42 @@ export class CrewMemberModelNotEligibleError extends Schema.TaggedError()( + "CrewMemberReasoningNotEligibleError", + { + projectId: Schema.String, + projectTitle: Schema.String, + instanceId: Schema.String, + model: Schema.String, + level: Schema.String, + eligible: Schema.Array(Schema.Struct({ level: Schema.String, label: Schema.String })), + }, +) { + override get message(): string { + return crewMemberReasoningRefusal({ + selection: this, + projectTitle: this.projectTitle, + eligible: this.eligible, + }); + } +} + /** - * The one place that decides whether a resolved model may run a custom worker in a project: a - * Crew's custom member, a plain `j5_spawn_agent`, or a plain `delegate_task`. Persona seats that - * keep their persona's model never reach it. + * The one place that decides whether a resolved model and reasoning level may run a custom worker + * in a project: a Crew's custom member, a plain `j5_spawn_agent`, or a plain `delegate_task`. + * Persona seats that keep their persona's selection never reach it. */ export class CrewMemberModels extends Context.Service< CrewMemberModels, { readonly assertEligible: (input: { readonly projectId: ProjectId; - readonly selection: Pick; - }) => Effect.Effect; + readonly selection: Pick; + }) => Effect.Effect< + void, + CrewMemberModelNotEligibleError | CrewMemberReasoningNotEligibleError + >; } >()("t3/j5/agents/crewMemberModels") {} @@ -58,26 +86,48 @@ export const layer = Layer.effect( const settings = yield* ServerSettings.ServerSettingsService; const registry = yield* ProviderRegistry; const projects = yield* ProjectService; + const projectTitleOf = (projectId: ProjectId) => + projects.getById(projectId).pipe( + Effect.map(Option.map((project) => project.title)), + Effect.map(Option.getOrElse(() => projectId as string)), + Effect.orElseSucceed(() => projectId as string), + ); const assertEligible: CrewMemberModels["Service"]["assertEligible"] = Effect.fn( "j5.crewMemberModels.assertEligible", )(function* ({ projectId, selection }) { - const list = yield* settings.getSettings.pipe( - Effect.map((all) => resolveProjectSettings(all, projectId).settings.crewMemberModels), + const resolved = yield* settings.getSettings.pipe( + Effect.map((all) => resolveProjectSettings(all, projectId).settings), Effect.orDie, ); - if (isCrewMemberModelChecked(list, selection)) return; - const eligible = eligibleCrewMemberModels(list, yield* registry.getProviders); - const projectTitle = yield* projects.getById(projectId).pipe( - Effect.map(Option.map((project) => project.title)), - Effect.map(Option.getOrElse(() => projectId as string)), - Effect.orElseSucceed(() => projectId as string), + const list = resolved.crewMemberModels; + if (!isCrewMemberModelChecked(list, selection)) { + return yield* new CrewMemberModelNotEligibleError({ + projectId, + projectTitle: yield* projectTitleOf(projectId), + instanceId: selection.instanceId, + model: selection.model, + eligible: eligibleCrewMemberModels(list, yield* registry.getProviders), + }); + } + // With no saved list every level is eligible, so the catalog is not read at all. + const levels = resolved.crewMemberReasoning; + if (levels === null) return; + const provider = (yield* registry.getProviders).find( + (candidate) => candidate.instanceId === selection.instanceId, + ); + const level = crewMemberSelectionLevel( + provider?.models.find((model) => model.slug === selection.model), + selection.options, ); - return yield* new CrewMemberModelNotEligibleError({ + if (provider === undefined || level === null) return; + if (isCrewMemberLevelChecked(levels, { instanceId: provider.instanceId, level })) return; + return yield* new CrewMemberReasoningNotEligibleError({ projectId, - projectTitle, + projectTitle: yield* projectTitleOf(projectId), instanceId: selection.instanceId, model: selection.model, - eligible, + level, + eligible: eligibleCrewMemberLevelsForModel(levels, provider, selection.model), }); }); return CrewMemberModels.of({ assertEligible }); diff --git a/apps/web/src/j5/crew/CrewMemberModelsSettings.tsx b/apps/web/src/j5/crew/CrewMemberModelsSettings.tsx index 745ed94acc5c3..3d882fb423f6f 100644 --- a/apps/web/src/j5/crew/CrewMemberModelsSettings.tsx +++ b/apps/web/src/j5/crew/CrewMemberModelsSettings.tsx @@ -1,15 +1,20 @@ import { useAtomValue } from "@effect/atom-react"; import type { EnvironmentId, ServerProvider } from "@t3tools/contracts"; import { + crewMemberLevelCounts, crewMemberModelCounts, + crewMemberProviderLevels, + isCrewMemberLevelChecked, isCrewMemberModelChecked, isCrewMemberProviderSetUp, type CrewMemberModel, type CrewMemberModels, + type CrewMemberReasoning, + type CrewMemberReasoningLevel, } from "@t3tools/contracts/j5"; import { Link } from "@tanstack/react-router"; import { AlertTriangleIcon, ChevronDownIcon, ChevronRightIcon } from "lucide-react"; -import { useState } from "react"; +import { useState, type ReactNode } from "react"; import { ProviderInstanceIcon } from "../../components/chat/ProviderInstanceIcon"; import { SettingResetButton, SettingsRow } from "../../components/settings/settingsLayout"; @@ -26,16 +31,20 @@ import { serverEnvironment } from "../../state/server"; import { useEnvironmentQuery } from "../../state/query"; import { agentPersonaEnvironment } from "../agents/agentPersonaAtoms"; import { + crewMemberLevelsSummary, crewMemberModelLabel, crewMemberModelsSummary, + crewMemberProviderSummary, personasOffCrewMemberModels, + setCrewMemberLevelChecked, setCrewMemberModelChecked, setCrewMemberProviderChecked, + setCrewMemberProviderLevelsChecked, } from "./crewMemberModels.logic"; const NO_ENVIRONMENT = "" as EnvironmentId; -/** One model: solid when allowed. Every chip fills its grid cell, so they all match in size. */ +/** One model or level: solid when allowed. Every chip fills its grid cell, so they all match in size. */ function ModelChip(props: { readonly name: string; readonly checked: boolean; @@ -57,17 +66,40 @@ function ModelChip(props: { ); } +interface CrewMemberListsPatch { + readonly crewMemberModels?: ReadonlyArray; + readonly crewMemberReasoning?: ReadonlyArray; +} + +function ChipGroup(props: { readonly label: string; readonly children: ReactNode }) { + return ( +
+

+ {props.label} +

+
    + {props.children} +
+
+ ); +} + function ProviderModels(props: { readonly provider: ServerProvider; readonly providers: ReadonlyArray; readonly entry: ReturnType[number]; readonly list: CrewMemberModels; + readonly reasoning: CrewMemberReasoning; readonly open: boolean; readonly onOpenChange: (open: boolean) => void; - readonly onChange: (next: ReadonlyArray) => void; + readonly onChange: (patch: CrewMemberListsPatch) => void; }) { - const { provider, entry, list } = props; - const { checked, total } = crewMemberModelCounts(list, [provider]); + const { provider, entry, list, reasoning } = props; + const levels = crewMemberProviderLevels(provider); + const modelCounts = crewMemberModelCounts(list, [provider]); + const levelCounts = crewMemberLevelCounts(reasoning, [provider]); + const allChecked = + modelCounts.checked === modelCounts.total && levelCounts.checked === levelCounts.total; const Chevron = props.open ? ChevronDownIcon : ChevronRightIcon; return (
@@ -84,37 +116,86 @@ function ProviderModels(props: { {entry.displayName} - {checked} of {total} + {crewMemberProviderSummary(provider, list, reasoning)}
-
    - {provider.models.map((model) => { - const pair = { instanceId: provider.instanceId, model: model.slug }; - return ( -
  • - - props.onChange(setCrewMemberModelChecked(list, props.providers, pair, next)) - } - /> -
  • - ); - })} -
+
+ + {provider.models.map((model) => { + const pair = { instanceId: provider.instanceId, model: model.slug }; + return ( +
  • + + props.onChange({ + crewMemberModels: setCrewMemberModelChecked( + list, + props.providers, + pair, + next, + ), + }) + } + /> +
  • + ); + })} +
    + {levels.length === 0 ? null : ( + + {levels.map((level) => { + const key = { instanceId: provider.instanceId, level: level.level }; + return ( +
  • + + props.onChange({ + crewMemberReasoning: setCrewMemberLevelChecked( + reasoning, + props.providers, + key, + next, + ), + }) + } + /> +
  • + ); + })} +
    + )} +
    @@ -122,17 +203,18 @@ function ProviderModels(props: { } /** - * Which models custom Crew members, and plain agents started without a persona, may run on. - * Personas keep their own model, and native subagents are outside the list on every provider - * (docs/j5/product/crews.md). + * Which models and reasoning levels custom Crew members, and plain agents started without a + * persona, may use. Personas keep their own model and level, and native subagents are outside the + * lists on every provider (docs/j5/product/crews.md). */ export function CrewMemberModelsSettings() { const settings = useScopedSettings(); - const mixed = useScopedSettingsMixed(["crewMemberModels"]); + const mixed = useScopedSettingsMixed(["crewMemberModels", "crewMemberReasoning"]); const updateSettings = useUpdateScopedSettings(); const { target } = useSettingsScope(); const environmentId = target?.environmentId ?? null; const list = settings.crewMemberModels; + const reasoning = settings.crewMemberReasoning; const [open, setOpen] = useState(false); const [openProvider, setOpenProvider] = useState(null); const providers = useAtomValue( @@ -146,32 +228,35 @@ export function CrewMemberModelsSettings() { const setUp = entries.filter((entry) => isCrewMemberProviderSetUp(entry.snapshot)); const notSetUp = entries.filter((entry) => !isCrewMemberProviderSetUp(entry.snapshot)); const summary = crewMemberModelsSummary(list, known); + const levelSummary = crewMemberLevelsSummary(reasoning, known); const offList = personasOffCrewMemberModels(catalog.data, list); - const save = (next: ReadonlyArray) => updateSettings({ crewMemberModels: next }); + const save = (patch: CrewMemberListsPatch) => updateSettings(patch); const Chevron = open ? ChevronDownIcon : ChevronRightIcon; return (