Skip to content

Commit a6d34e5

Browse files
fix(provider-muse): ship skill catalogs without structured dispatch
Structured skill input failed with protocol errors on a new thread's first message in live testing, and the cause is not yet known. Keep the picker catalogs and send skill mentions as text, as before, until a live first-message run with structured input succeeds. AI-assisted; verified with the tests and tools listed above.
1 parent a700865 commit a6d34e5

4 files changed

Lines changed: 18 additions & 120 deletions

File tree

‎docs/user/providers-muse.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ without them. Switching providers can pass conversation context as a handoff.
5555
Muse skills appear in the composer's `$` menu. Manage them with `muse skills`
5656
on the host. Skill changes may take up to five minutes to appear as you type in
5757
the composer. See [Commands and skills](./composer.md#commands-and-skills) for
58-
restarting an active agent after changes. When a message mentions several skills,
59-
T3 Code invokes the first one available in the Muse session with the full message.
60-
Follow-up steering messages stay as text.
58+
restarting an active agent after changes. A picked skill is sent to Muse as
59+
text, so Muse loads it only if the model may invoke that skill.
6160

6261
Forking a Muse conversation starts a new session with a copy of the conversation
6362
context. Conversation rewind is unavailable.

‎packages/provider-muse/src/server/adapter.test.ts‎

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -386,65 +386,6 @@ const approval = (turnId: string) => ({
386386
vi.mock("node:fs/promises", { spy: true });
387387

388388
describe("MuseAdapterV2", () => {
389-
it.effect("invokes only the first live skill with the unchanged request as arguments", () =>
390-
Effect.gen(function* () {
391-
const fake = yield* makeFakeMuse();
392-
fake.queueResponse("skill/list", {
393-
skills: [{ selector: "architect" }, { selector: "ai-ugc:ugc-mode" }],
394-
});
395-
const harness = yield* makeHarness(fake);
396-
const base = yield* turnInput(harness.providerThread);
397-
const input = {
398-
...base,
399-
message: {
400-
...base.message,
401-
text: "Please $nope then $ai-ugc:ugc-mode tidy $architect $ai-ugc:ugc-mode",
402-
},
403-
};
404-
yield* harness.runtime.startTurn(input);
405-
const call = yield* fake.takeCall("turn/start");
406-
const parts = call.params.input as Array<{
407-
type: string;
408-
selector?: string;
409-
arguments?: string;
410-
}>;
411-
assert.strictEqual(parts.length, 1);
412-
assert.strictEqual(parts[0]?.type, "skill");
413-
assert.strictEqual(parts[0]?.selector, "ai-ugc:ugc-mode");
414-
assert.isTrue(parts[0]?.arguments?.endsWith(input.message.text));
415-
assert.include(parts[0]?.arguments ?? "", "<runtime_info>");
416-
assert.include(parts[0]?.arguments ?? "", "Muse Code");
417-
assert.include(parts[0]?.arguments ?? "", MODEL);
418-
assert.strictEqual(call.params.displayText, input.message.text);
419-
assert.strictEqual(fake.calls.filter((call) => call.method === "skill/list").length, 1);
420-
}).pipe(Effect.scoped, Effect.provide(testLayer)),
421-
);
422-
423-
it.effect("keeps plain and unavailable skill requests as text", () =>
424-
Effect.gen(function* () {
425-
for (const [text, response] of [
426-
["Tidy the changes", { skills: [{ selector: "git" }] }],
427-
["$git tidy $nope", { skills: [{ selector: "architect" }] }],
428-
["$git tidy $nope", new Error("listing failed")],
429-
] as const) {
430-
const fake = yield* makeFakeMuse();
431-
fake.queueResponse("skill/list", response);
432-
const harness = yield* makeHarness(fake);
433-
const base = yield* turnInput(harness.providerThread);
434-
const input = { ...base, message: { ...base.message, text } };
435-
yield* harness.runtime.startTurn(input);
436-
const call = yield* fake.takeCall("turn/start");
437-
const parts = call.params.input as Array<{ type: string; text?: string }>;
438-
assert.isTrue(parts.every((part) => part.type === "text"));
439-
assert.strictEqual(parts.at(-1)?.text, input.message.text);
440-
assert.strictEqual(
441-
fake.calls.filter((call) => call.method === "skill/list").length,
442-
text.startsWith("$") ? 1 : 0,
443-
);
444-
}
445-
}).pipe(Effect.scoped, Effect.provide(testLayer)),
446-
);
447-
448389
it.effect("connects the thread's MCP credential on native start and resume", () =>
449390
Effect.gen(function* () {
450391
yield* (yield* McpProviderSessions.McpProviderSessions).set({
@@ -1513,14 +1454,9 @@ describe("MuseAdapterV2", () => {
15131454
runId: input.runId,
15141455
providerThread: harness.providerThread,
15151456
providerTurnId: turn.providerTurn.id,
1516-
message: { ...input.message, text: "$git focus on the parser" },
1457+
message: { ...input.message, text: "Focus on the parser" },
15171458
});
1518-
const steer = yield* fake.takeCall("turn/steer");
1519-
assert.strictEqual(steer.params.expectedTurnId, turn.nativeId);
1520-
assert.deepStrictEqual(steer.params.input, [
1521-
{ type: "text", text: "$git focus on the parser" },
1522-
]);
1523-
assert.isFalse(fake.calls.some((call) => call.method === "skill/list"));
1459+
assert.strictEqual((yield* fake.takeCall("turn/steer")).params.expectedTurnId, turn.nativeId);
15241460
const interrupt = yield* harness.runtime
15251461
.interruptTurn({
15261462
providerThread: harness.providerThread,

‎packages/provider-muse/src/server/adapter.ts‎

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
type ThreadId,
2626
} from "@t3tools/contracts";
2727
import type { MuseSettings } from "../settings.ts";
28-
import { SKILL_MENTION_PATTERN } from "@t3tools/shared/composerInlineTokens";
2928
import { AgentScope } from "@t3tools/shared/AgentScope";
3029
import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
3130
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
@@ -52,7 +51,6 @@ import {
5251
MuseDelta,
5352
MuseItemEvent,
5453
MuseSessionResult,
55-
MuseSkillList,
5654
MuseSubscriptionUsage,
5755
MuseTokenUsageEvent,
5856
MuseTodoList,
@@ -2030,27 +2028,8 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
20302028
),
20312029
);
20322030
});
2033-
const resolveSkillSelector = Effect.fnUntraced(function* (text: string) {
2034-
const mentions = [...text.matchAll(SKILL_MENTION_PATTERN)];
2035-
if (!mentions.length) return undefined;
2036-
// An optional catalog timeout must not close the host needed for the text fallback.
2037-
return yield* Effect.tryPromise({
2038-
try: () => host.connection.request("skill/list", { sessionId: nativeSessionId }),
2039-
catch: (cause) => protocolError("Muse skill/list failed", cause),
2040-
}).pipe(
2041-
Effect.flatMap((value) => decode(MuseSkillList, value)),
2042-
Effect.map(({ skills }) => {
2043-
const selectors = new Set(skills.map((skill) => skill.selector));
2044-
return mentions.find((match) => match[2] !== undefined && selectors.has(match[2]))?.[2];
2045-
}),
2046-
Effect.timeout(5_000),
2047-
Effect.orElseSucceed(() => undefined),
2048-
);
2049-
});
20502031
const prompt = Effect.fnUntraced(function* (
20512032
message: ProviderAdapter.ProviderAdapterV2TurnMessage,
2052-
runtimeInstructions?: string,
2053-
selector?: string,
20542033
) {
20552034
const parts: SendUserTurnOptions<unknown>["input"] = [];
20562035
const text = yield* providerMessageTextWithAttachmentPaths({
@@ -2059,19 +2038,7 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
20592038
resolveAttachmentPath: providerHost.resolveAttachmentPath,
20602039
resolveExtractedTextPath: providerHost.resolveExtractedTextPath,
20612040
});
2062-
if (!text && !message.attachments.some(isProviderNativeImageAttachment))
2063-
return yield* protocolError("Muse needs text or an image");
2064-
if (selector) {
2065-
// MSP permits one skill plus images, but rejects skill/text mixtures.
2066-
parts.push({
2067-
type: "skill",
2068-
selector,
2069-
arguments: [runtimeInstructions, text].filter(Boolean).join("\n\n"),
2070-
});
2071-
} else {
2072-
if (runtimeInstructions) parts.push({ type: "text", text: runtimeInstructions });
2073-
if (text) parts.push({ type: "text", text });
2074-
}
2041+
if (text) parts.push({ type: "text", text });
20752042
for (const attachment of message.attachments)
20762043
if (isProviderNativeImageAttachment(attachment)) {
20772044
const path = providerHost.resolveAttachmentPath(attachment);
@@ -2085,6 +2052,7 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
20852052
mediaType: attachment.mimeType,
20862053
});
20872054
}
2055+
if (!parts.length) return yield* protocolError("Muse needs text or an image");
20882056
return parts;
20892057
});
20902058
const validateThread = (candidate: OrchestrationV2ProviderThread) =>
@@ -2125,6 +2093,7 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
21252093
turnInput.message.creationSource === "provider";
21262094
const adopted = continuation ? wake : undefined;
21272095
const effort = continuation ? undefined : yield* selectionEffort(turnInput.modelSelection);
2096+
const parts = compact || continuation ? [] : yield* prompt(turnInput.message);
21282097
const targetModel = continuation
21292098
? undefined
21302099
: yield* resolveModel(turnInput.modelSelection);
@@ -2134,18 +2103,6 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
21342103
});
21352104
session = { ...session, model: targetModel };
21362105
}
2137-
const parts =
2138-
compact || continuation
2139-
? []
2140-
: yield* prompt(
2141-
turnInput.message,
2142-
buildRuntimeInstructions({
2143-
harness: "Muse Code",
2144-
model: session.model ?? undefined,
2145-
reasoningEffort: effort,
2146-
}),
2147-
yield* resolveSkillSelector(turnInput.message.text),
2148-
);
21492106
const nativeId = adopted?.nativeId ?? host.connection.mintCommandId();
21502107
const startedAt = yield* DateTime.now;
21512108
const providerTurn: OrchestrationV2ProviderTurn = {
@@ -2225,7 +2182,17 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
22252182
const result = yield* request(
22262183
"turn/start",
22272184
{
2228-
input: parts,
2185+
input: [
2186+
{
2187+
type: "text",
2188+
text: buildRuntimeInstructions({
2189+
harness: "Muse Code",
2190+
model: session.model ?? undefined,
2191+
reasoningEffort: effort,
2192+
}),
2193+
},
2194+
...parts,
2195+
],
22292196
displayText: turnInput.message.text || "Image attachment",
22302197
// Resumed sessions retain old roots; pin edits to the current checkout.
22312198
workspaceRoots: [workspaceRoot],

‎packages/provider-muse/src/server/protocol.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ export const MuseSessionResult = Schema.Struct({
8282
}),
8383
),
8484
});
85-
export const MuseSkillList = Schema.Struct({
86-
skills: Schema.Array(Schema.Struct({ selector: NonEmptyString })),
87-
});
88-
8985
export const MuseTurnStartResult = Schema.Struct({ turnId: NonEmptyString });
9086

9187
export const MuseApproval = Schema.Struct({

0 commit comments

Comments
 (0)