Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
261 changes: 247 additions & 14 deletions apps/server/src/j5/a2a/CrewLaunchService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> }>,
models: ReadonlyArray<{
slug: string;
options: ReadonlyArray<string>;
/** 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),
Expand All @@ -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 } : {}),
})),
},
],
},
})),
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
);
Loading
Loading