Co-authored-by: Guillaume <[email protected]> Co-authored-by: Cristian Uibar <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
154 lines
5.3 KiB
TypeScript
154 lines
5.3 KiB
TypeScript
import type { MuseSettings, ServerProviderModel } from "@t3tools/contracts";
|
|
import { resolveSpawnCommand } from "@t3tools/shared/shell";
|
|
import * as DateTime from "effect/DateTime";
|
|
import * as Effect from "effect/Effect";
|
|
import * as Option from "effect/Option";
|
|
import * as Result from "effect/Result";
|
|
import { ChildProcess } from "effect/process";
|
|
|
|
import { createMuseSdkHost, makeMuseEnvironment } from "./museSdk.ts";
|
|
import { parseMuseVersion } from "./museMaintenance.ts";
|
|
import { discoverMuseModels, museModelCapabilities } from "./museModelCatalog.ts";
|
|
import {
|
|
buildServerProvider,
|
|
COMPACT_SLASH_COMMAND,
|
|
DEFAULT_TIMEOUT_MS,
|
|
isCommandMissingCause,
|
|
providerModelsFromSettings,
|
|
spawnAndCollect,
|
|
type ProviderProbeResult,
|
|
} from "./providerSnapshot.ts";
|
|
|
|
const MUSE_PRESENTATION = {
|
|
displayName: "Muse Code",
|
|
showInteractionModeToggle: false,
|
|
reportsContextWindow: true,
|
|
// Muse has no native "accept edits" or reviewer-backed mode, so T3 offers only
|
|
// the two it maps directly: promptUnmatched and allowAll.
|
|
supportedRuntimeModes: ["approval-required", "full-access"],
|
|
} as const;
|
|
|
|
const FALLBACK_CAPABILITIES = museModelCapabilities();
|
|
|
|
export const makePendingMuseProvider = Effect.fn("makePendingMuseProvider")(function* (
|
|
settings: MuseSettings,
|
|
) {
|
|
return buildServerProvider({
|
|
presentation: MUSE_PRESENTATION,
|
|
enabled: settings.enabled,
|
|
checkedAt: DateTime.formatIso(yield* DateTime.now),
|
|
models: providerModelsFromSettings([], settings.customModels, FALLBACK_CAPABILITIES),
|
|
slashCommands: settings.enabled ? [COMPACT_SLASH_COMMAND] : [],
|
|
probe: {
|
|
installed: false,
|
|
version: null,
|
|
status: "warning",
|
|
auth: { status: "unknown" },
|
|
message: settings.enabled
|
|
? "Checking Muse Code CLI availability..."
|
|
: "Muse Code is disabled in T3 Code settings.",
|
|
},
|
|
});
|
|
});
|
|
|
|
export const checkMuseProviderStatus = Effect.fn("checkMuseProviderStatus")(function* (
|
|
settings: MuseSettings,
|
|
environment?: NodeJS.ProcessEnv,
|
|
cwd?: string,
|
|
createHost: typeof createMuseSdkHost = createMuseSdkHost,
|
|
) {
|
|
if (!settings.enabled) return yield* makePendingMuseProvider(settings);
|
|
const checkedAt = DateTime.formatIso(yield* DateTime.now);
|
|
// The driver passes a prepared environment; direct callers get the host's without META_API_KEY.
|
|
const museEnvironment = environment ?? makeMuseEnvironment();
|
|
const snapshot = (probe: ProviderProbeResult, models: ReadonlyArray<ServerProviderModel> = []) =>
|
|
buildServerProvider({
|
|
presentation: MUSE_PRESENTATION,
|
|
enabled: true,
|
|
checkedAt,
|
|
models: providerModelsFromSettings(models, settings.customModels, FALLBACK_CAPABILITIES),
|
|
slashCommands: [COMPACT_SLASH_COMMAND],
|
|
probe,
|
|
});
|
|
const versionResult = yield* Effect.gen(function* () {
|
|
const spawnCommand = yield* resolveSpawnCommand(settings.binaryPath, ["--version"], {
|
|
env: museEnvironment,
|
|
});
|
|
return yield* spawnAndCollect(
|
|
settings.binaryPath,
|
|
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
|
|
env: museEnvironment,
|
|
shell: spawnCommand.shell,
|
|
...(cwd ? { cwd } : {}),
|
|
}),
|
|
);
|
|
}).pipe(Effect.timeoutOption(DEFAULT_TIMEOUT_MS), Effect.result);
|
|
|
|
if (Result.isFailure(versionResult)) {
|
|
const missing = isCommandMissingCause(versionResult.failure);
|
|
return snapshot({
|
|
installed: !missing,
|
|
version: null,
|
|
status: "error",
|
|
auth: { status: "unknown" },
|
|
message: missing
|
|
? "Muse Code CLI (`muse`) was not found. Install Muse Code and run `muse login` on this T3 server host."
|
|
: "Failed to execute Muse Code CLI. Check its binary path on this T3 server host.",
|
|
});
|
|
}
|
|
if (Option.isNone(versionResult.success)) {
|
|
return snapshot({
|
|
installed: true,
|
|
version: null,
|
|
status: "error",
|
|
auth: { status: "unknown" },
|
|
message: "Muse Code CLI version check timed out.",
|
|
});
|
|
}
|
|
const versionOutput = versionResult.success.value;
|
|
const version = parseMuseVersion(`${versionOutput.stdout}\n${versionOutput.stderr}`);
|
|
if (versionOutput.code !== 0) {
|
|
return snapshot({
|
|
installed: true,
|
|
version,
|
|
status: "error",
|
|
auth: { status: "unknown" },
|
|
message: "Muse Code CLI is installed but failed to run.",
|
|
});
|
|
}
|
|
|
|
const catalog = yield* discoverMuseModels(settings, museEnvironment, cwd, createHost).pipe(
|
|
Effect.scoped,
|
|
Effect.timeoutOption(12_000),
|
|
Effect.result,
|
|
);
|
|
if (Result.isFailure(catalog) || Option.isNone(catalog.success)) {
|
|
return snapshot({
|
|
installed: true,
|
|
version,
|
|
status: "error",
|
|
auth: { status: "unknown" },
|
|
message:
|
|
"Muse Code SDK could not read the model catalog. Check your Muse installation and run `muse login` on this T3 server host.",
|
|
});
|
|
}
|
|
const models = catalog.success.value;
|
|
// MSP has no auth signal, and model/list answers from Muse's cache even when logged out.
|
|
// Auth failures surface on the first turn instead.
|
|
return snapshot(
|
|
{
|
|
installed: true,
|
|
version,
|
|
auth: { status: "unknown" },
|
|
...(models.length > 0
|
|
? { status: "ready" }
|
|
: {
|
|
status: "warning",
|
|
message:
|
|
"Muse Code returned no models. Run `muse login` on this T3 server host and refresh its status.",
|
|
}),
|
|
},
|
|
models,
|
|
);
|
|
});
|