feat(providers): run Muse Code as a native provider #17082
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 18 commits into
main fromrefs/pull/17082/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
juliusmarminge added labelsmacroscope-review
- apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.ts line 1432OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1412,21 @@1412+ selected,1413+ );1414+ });1415+ const start = Effect.fnUntraced(function* (1416+ turnInput: ProviderAdapterV2TurnInput,1417+ compact = false,1418+ ) {1419+ if (!validateThread(turnInput.providerThread) || broken || closed)1420+ return yield* protocolError("Muse thread is not attached to this host");1421+ if (active)1422+ return yield* protocolError(1423+ "Muse already has an active turn; queue through the orchestrator",1424+ );1425+ if (turnInput.runtimePolicy.interactionMode === "plan")1426+ return yield* protocolError("Muse does not support dedicated Plan mode");1427+ if (turnInput.runtimePolicy.runtimeMode !== input.runtimePolicy.runtimeMode)1428+ return yield* protocolError("Runtime policy changes require a fresh Muse host");1429+ const effort = yield* selectionEffort(turnInput.modelSelection);1430+ const parts = compact ? [] : yield* prompt(turnInput.message);1431+ if (1432+ turnInput.modelSelection.model !== MUSE_DEFAULT_MODEL &&
- apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.ts line 1365OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1345,21 @@1345+ }),1346+ driver: MUSE_PROVIDER,1347+ providerInstanceId: options.instanceId,1348+ providerSessionId: input.providerSessionId,1349+ appThreadId: args.threadId,1350+ ownerNodeId: null,1351+ nativeThreadRef: nativeRef(nativeSessionId),1352+ nativeConversationHeadRef: null,1353+ status: "idle",1354+ firstRunOrdinal: null,1355+ lastRunOrdinal: null,1356+ handoffIds: [],1357+ forkedFrom: null,1358+ createdAt,1359+ updatedAt: createdAt,1360+ };1361+ session = {1362+ ...session,1363+ model: result.session.modelId ?? args.modelSelection.model,1364+ };1365+ switchedModel = args.modelSelection.model !== MUSE_DEFAULT_MODEL;apps/server/src/provider/museMaintenance.ts lines 31 to 37OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +17,21 @@17+import { parseGenericCliVersion } from "./providerSnapshot.ts";18+19+const DRIVER = ProviderDriverKind.make("muse");20+/** Mirrors the official launcher, which reads MUSE_CHANNEL and accepts only these two. */21+const MUSE_CHANNELS = new Set(["muse-stable", "muse-canary"]);22+const ChannelManifest = Schema.Struct({23+ version: Schema.String.check(Schema.isPattern(/^\d+\.\d+\.\d+-R\d+(?:\.\d+)?$/)),24+});25+26+/** Muse prints both a display version and a release revision; prefer the latter. */27+export function parseMuseVersion(output: string): string | null {28+ return output.match(/\b\d+\.\d+\.\d+-R\d+(?:\.\d+)?\b/)?.[0] ?? parseGenericCliVersion(output);29+}30+31+function comparableMuseVersion(version: string): string {32+ // Make the release sequence numeric for semver comparison (R9 precedes R10).33+ return version.replace(/-R(\d+)(?:\.(\d+))?$/, "-release.$1.$2").replace(/\.$/, ".0");34+}35+36+export const compareMuseVersions = (current: string, latest: string) =>37+ compareSemverVersions(comparableMuseVersion(current), comparableMuseVersion(latest));apps/server/src/textGeneration/MuseTextGeneration.ts lines 223 to 230OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +210,21 @@210+ const fileSystem = yield* FileSystem.FileSystem;211+ const runMuseJson = Effect.fn("runMuseJson")(function* <S extends Schema.Top>(input: {212+ operation: Operation;213+ prompt: string;214+ outputSchema: S;215+ modelSelection: ModelSelection;216+ }): Effect.fn.Return<S["Type"], TextGenerationError, S["DecodingServices"]> {217+ const { operation } = input;218+ if (!settings.enabled) {219+ return yield* new TextGenerationError({ operation, detail: "Muse Code is disabled." });220+ }221+ const selectedModel = input.modelSelection.model.trim();222+ // Without a model, Muse starts the session on the account's default.223+ const modelId =224+ selectedModel && selectedModel !== MUSE_DEFAULT_MODEL ? selectedModel : undefined;225+ const models = yield* modelCatalog;226+ const reasoningEffort = resolveMuseReasoningEffort(227+ models.find((model) => model.slug === modelId)?.capabilities ?? museModelCapabilities(),228+ getModelSelectionStringOptionValue(input.modelSelection, "reasoningEffort") ??229+ DEFAULT_TEXT_GENERATION_REASONING_EFFORT,230+ );
t3dotgg(GitHub profile, opens in a new tab) changed the title
- apps/server/scripts/record-muse-msp-replay-fixture.ts lines 159 to 159Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +137,21 @@137+ const label = museRecordLabel(138+ frame,139+ type,140+ type === "emit_inbound" ? clientRequests : serverRequests,141+ hostOrdinal,142+ );143+ entries.push({ type, ...(label === undefined ? {} : { label }), frame });144+ };145+ record("expect_outbound", { type: "host_start", args });146+ const child = NodeChildProcess.spawn(options.binaryPath, args, {147+ cwd: options.cwd,148+ env: options.environment ?? makeMuseEnvironment(),149+ stdio: ["pipe", "pipe", "inherit"],150+ });151+ const exited = new Promise<{ code: number | null; signal: null }>((resolve) =>152+ child.once("exit", (code) => resolve({ code, signal: null })),153+ );154+ async function* incoming() {155+ let buffer = "";156+ for await (const chunk of child.stdout) {157+ buffer += String(chunk);apps/server/scripts/record-muse-msp-replay-fixture.ts lines 146 to 146OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +126,21 @@126+ commandIds: Array<Array<string>>,127+): Parameters<typeof museReplayLayer>[0]["createHost"] {128+ return async (options) => {129+ const hostOrdinal = commandIds.length + 1;130+ const minted: Array<string> = [];131+ commandIds.push(minted);132+ const mint = createUuidV7Mint();133+ const args = museServeArgs(options);134+ const clientRequests = new Map<unknown, string>();135+ const serverRequests = new Map<unknown, string>();136+ const record = (type: "expect_outbound" | "emit_inbound", frame: unknown) => {137+ const label = museRecordLabel(138+ frame,139+ type,140+ type === "emit_inbound" ? clientRequests : serverRequests,141+ hostOrdinal,142+ );143+ entries.push({ type, ...(label === undefined ? {} : { label }), frame });144+ };145+ record("expect_outbound", { type: "host_start", args });146+ const child = NodeChildProcess.spawn(options.binaryPath, args, {
- apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.ts line 912Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +731,21 @@731+ "Muse requests permission",732+ options: museApprovalOptions(native.value),733+ }734+ : {735+ ...base,736+ type: "user_input_request",737+ requestId,738+ questions: native.value.questions.map((question) => ({739+ id: question.id,740+ header: question.header || "Question",741+ question: question.question,742+ options: question.options.map((option) => ({743+ label: option.label,744+ description: option.description || option.label,745+ })),746+ multiSelect: question.selection.mode === "multiple",747+ allowCustomAnswer: true,748+ required: true,749+ })),750+ };751+ pending.set(requestId, { native, request: runtimeRequest, node, item });
t3dotgg(GitHub profile, opens in a new tab) changed the title
- @@ -0,0 +825,21 @@825+ updatedAt,826+ };827+ yield* updateThread({ contextUsage: tokenUsage });828+ if (currentTurn) {829+ const updated = { ...currentTurn, tokenUsage };830+ if (active) active.providerTurn = updated;831+ else lastProviderTurn = updated;832+ yield* emit({833+ type: "provider_turn.updated",834+ driver: MUSE_PROVIDER,835+ providerTurn: updated,836+ });837+ }838+ return;839+ }840+ const itemEvent = ["item/started", "item/updated", "item/completed"].includes(method)841+ ? (yield* decode(MuseItemEvent, params)).item842+ : undefined;843+ if (itemEvent) {844+ const owner = observedChildren.get(itemEvent.itemId);845+ if (owner && owner !== active && itemEvent.turnId === owner.nativeId) {
- @@ -0,0 +571,21 @@571+ const latest = new Map((item.children ?? []).map((child) => [child.childId, child]));572+ for (const [index, child] of [...latest.values()].entries()) {573+ const time = yield* DateTime.now;574+ const base = baseItem(turn, `${item.itemId}:agent:${child.childId}`, time);575+ const status: OrchestrationV2TurnItemStatus =576+ child.terminal === "completed"577+ ? "completed"578+ : child.terminal === "cancelled"579+ ? "cancelled"580+ : child.terminal !== undefined581+ ? "failed"582+ : workflowStatus !== "running"583+ ? workflowStatus584+ : child.status === "scheduled"585+ ? "pending"586+ : "running";587+ const settled = status !== "running" && status !== "pending";588+ // Children are re-sent on every workflow change; keep each one's first end time.589+ const endKey = `${item.itemId}:${child.childId}:${child.attempt}`;590+ if (settled && !agentEndedAt.has(endKey)) agentEndedAt.set(endKey, time);591+ const title = child.label?.trim() || `Agent ${index + 1}`;
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed