Skip to content

Commit 6ba6a0d

Browse files
t3dotggclaude
andauthored
fix(provider-muse): run on Muse 1.4.6, with linked web search hits and workflow results (#18409)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 2783962 commit 6ba6a0d

11 files changed

Lines changed: 193 additions & 71 deletions

File tree

‎apps/server/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@effect/platform-node": "catalog:",
3535
"@effect/platform-node-shared": "catalog:",
3636
"@ff-labs/fff-node": "0.11.0",
37-
"@muse-code/sdk": "1.4.2",
37+
"@muse-code/sdk": "1.4.6",
3838
"@napi-rs/keyring": "^1.3.0",
3939
"@opencode-ai/sdk": "^1.3.15",
4040
"@t3tools/provider-acp": "workspace:*",

‎apps/server/src/orchestration-v2/testkit/fixtures/muse_workflow/muse_transcript.ndjson‎

Lines changed: 60 additions & 59 deletions
Large diffs are not rendered by default.

‎apps/server/src/orchestration-v2/testkit/fixtures/muse_workflow/output.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ export function assertMuseWorkflowOutput(
3939
assert.isDefined(workflow, "the workflow shows as a row");
4040
assert.equal(workflow.status, "completed");
4141
assert.equal(workflow.runId, projection.runs[0]?.id);
42+
// The settled row shows the workflow's own result, not its generic label.
43+
const finalSummary = transcript.entries
44+
.map((entry) =>
45+
entry.type === "emit_inbound"
46+
? Reflect.get(Reflect.get(Object(entry.frame).params ?? {}, "item") ?? {}, "finalSummary")
47+
: undefined,
48+
)
49+
.findLast((summary) => typeof summary === "string");
50+
assert.isString(finalSummary, "Muse reports the workflow's result");
51+
assert.equal(workflow.type === "dynamic_tool" ? workflow.output : undefined, finalSummary);
4252

4353
const report = projection.messages.filter(
4454
(message) => message.role === "assistant" && message.runId === projection.runs[1]?.id,

‎packages/provider-muse/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"test": "vp test run --config ../../vite.config.ts --dir ."
2626
},
2727
"dependencies": {
28-
"@muse-code/sdk": "1.4.2",
28+
"@muse-code/sdk": "1.4.6",
2929
"@t3tools/contracts": "workspace:*",
3030
"@t3tools/provider-core": "workspace:*",
3131
"@t3tools/shared": "workspace:*",

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,4 +1216,34 @@ describe("MuseAdapterV2", () => {
12161216
assert.strictEqual(started.subagent.title, "ping");
12171217
}).pipe(Effect.scoped, Effect.provide(testLayer)),
12181218
);
1219+
1220+
it.effect("shows a workflow child that completed with a failure kind as failed", () =>
1221+
Effect.gen(function* () {
1222+
const fake = yield* makeFakeMuse();
1223+
const harness = yield* makeHarness(fake);
1224+
const { nativeId } = yield* startConversation(harness, fake);
1225+
yield* fake.emit("item/started", {
1226+
turnId: nativeId,
1227+
item: {
1228+
itemId: "wf-1",
1229+
kind: "workflow",
1230+
revision: 1,
1231+
status: "inProgress",
1232+
turnId: nativeId,
1233+
children: [
1234+
{
1235+
childId: "c1",
1236+
attempt: 1,
1237+
status: "finished",
1238+
terminal: "completed",
1239+
failureKind: "budget_exhausted",
1240+
},
1241+
],
1242+
},
1243+
});
1244+
const child = yield* harness.takeEvent("subagent.updated");
1245+
assert.strictEqual(child.subagent.status, "failed");
1246+
assert.strictEqual(child.subagent.result, "budget_exhausted");
1247+
}).pipe(Effect.scoped, Effect.provide(testLayer)),
1248+
);
12191249
});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,9 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
830830
for (const [index, child] of [...latest.values()].entries()) {
831831
const time = yield* DateTime.now;
832832
const base = baseItem(turn, `${item.itemId}:agent:${child.childId}`, time);
833+
// Muse marks a failed attempt with `failureKind`, even when its terminal is `completed`.
833834
const status: OrchestrationV2TurnItemStatus =
834-
child.terminal === "completed"
835+
child.terminal === "completed" && child.failureKind === undefined
835836
? "completed"
836837
: child.terminal === "cancelled"
837838
? "cancelled"
@@ -849,7 +850,7 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
849850
// Later revisions drop the label; keep the last one seen.
850851
if (child.label?.trim()) agentTitles.set(endKey, child.label.trim());
851852
const title = agentTitles.get(endKey) || `Agent ${index + 1}`;
852-
const result = child.failureReason ?? null;
853+
const result = child.failureReason ?? child.failureKind ?? null;
853854
const subagent: OrchestrationV2Subagent = {
854855
id: base.nodeId,
855856
threadId: base.threadId,

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,51 @@ describe("Muse item presentation", () => {
7373
expect(museItemStatus(item({ status: "cancelled" }))).toBe("cancelled");
7474
});
7575

76+
it("lists each web search hit and links a fetched page", () => {
77+
const search = item({
78+
tool: "web_search",
79+
args: JSON.stringify({ query: "node lts" }),
80+
visibleOutput: JSON.stringify({
81+
query: "node lts",
82+
results: [
83+
{ url: "https://nodejs.org/", title: "Node.js", snippet: "Node 24 is LTS", extra: 1 },
84+
{ url: "", title: "", snippet: "No link" },
85+
],
86+
}),
87+
});
88+
expect(museToolPresentation(search)).toEqual({
89+
status: "completed",
90+
title: "web_search",
91+
type: "web_search",
92+
patterns: ["node lts"],
93+
results: [
94+
{ url: "https://nodejs.org/", title: "Node.js", snippet: "Node 24 is LTS" },
95+
{ snippet: "No link" },
96+
],
97+
});
98+
const fetch = item({
99+
tool: "web_fetch",
100+
args: JSON.stringify({ url: "https://nodejs.org/en/about" }),
101+
visibleOutput: "About Node.js",
102+
});
103+
expect(museToolPresentation(fetch)).toMatchObject({
104+
type: "web_search",
105+
results: [{ url: "https://nodejs.org/en/about", snippet: "About Node.js" }],
106+
});
107+
});
108+
109+
it("shows a settled workflow's result instead of its generic label", () => {
110+
expect(
111+
museToolPresentation(
112+
item({
113+
kind: "workflow",
114+
fallbackText: "Workflow: model-chosen generated workflow",
115+
finalSummary: "Both checks passed",
116+
}),
117+
),
118+
).toMatchObject({ type: "dynamic_tool", output: "Both checks passed" });
119+
});
120+
76121
it.each(["failed", "noop"])(
77122
"keeps %s compaction outcomes from appearing completed",
78123
(outcome) => {

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
import type { OrchestrationV2TurnItem, OrchestrationV2TurnItemStatus } from "@t3tools/contracts";
2+
import * as Option from "effect/Option";
23
import * as Schema from "effect/Schema";
34

45
import type { MuseItem } from "./protocol.ts";
56

67
const decodeToolArgs = Schema.decodeUnknownSync(
78
Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown)),
89
);
10+
/** Muse's `web_search` tool output: the query and its hits, as JSON. */
11+
const decodeWebSearchOutput = Schema.decodeUnknownOption(
12+
Schema.fromJsonString(
13+
Schema.Struct({
14+
results: Schema.Array(
15+
Schema.Struct({
16+
url: Schema.optional(Schema.String),
17+
title: Schema.optional(Schema.String),
18+
snippet: Schema.optional(Schema.String),
19+
}),
20+
),
21+
}),
22+
),
23+
);
924

1025
type Fields<
1126
T extends OrchestrationV2TurnItem["type"],
@@ -68,6 +83,7 @@ export function museToolPresentation(
6883
item.result?.summary ??
6984
item.text ??
7085
item.summary?.join("\n") ??
86+
item.finalSummary ??
7187
item.fallbackText ??
7288
item.objective ??
7389
"";
@@ -100,11 +116,25 @@ export function museToolPresentation(
100116
}
101117
if (item.kind === "toolCall" && /web|browse|fetch/i.test(toolName)) {
102118
const query = stringArg("query", "url", "pattern")?.trim();
119+
const pageUrl = stringArg("url")?.trim();
120+
// A search lists its hits; a page fetch (or a failure) shows its text under the page's link.
121+
const hits =
122+
item.tool === "web_search" && !detail
123+
? Option.getOrUndefined(decodeWebSearchOutput(text))?.results.map(
124+
({ url, title, snippet }) => ({
125+
...(url?.trim() ? { url: url.trim() } : {}),
126+
...(title?.trim() ? { title: title.trim() } : {}),
127+
...(snippet ? { snippet } : {}),
128+
}),
129+
)
130+
: undefined;
131+
const results =
132+
hits ?? (output ? [{ ...(pageUrl ? { url: pageUrl } : {}), snippet: output }] : []);
103133
return {
104134
...shared,
105135
type: "web_search",
106136
...(query ? { patterns: [query] } : {}),
107-
...(output ? { results: [{ snippet: output }] } : {}),
137+
...(results.length ? { results } : {}),
108138
};
109139
}
110140
return {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ export const MuseItem = Schema.Struct({
2525
label: Schema.optional(Schema.String),
2626
terminal: Schema.optional(Schema.String),
2727
durationMs: Schema.optional(Schema.Finite),
28+
/** Present on a failed attempt, even one whose `terminal` is `completed`. */
29+
failureKind: Schema.optional(Schema.String),
2830
failureReason: Schema.optional(Schema.String),
2931
}),
3032
),
3133
),
34+
/** `workflow`: the run's result, once it settles. */
35+
finalSummary: Schema.optional(Schema.String),
3236
itemId: NonEmptyString,
3337
kind: NonEmptyString,
3438
revision: Schema.Int.check(Schema.isGreaterThan(0)),

‎pnpm-lock.yaml‎

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)