Skip to content

Commit b923cf1

Browse files
JimCodeyclaude
andcommitted
feat(mesh): steer managed agents and view fresh-session transcripts
Reuse shared Buzz prompt/core memory; retire idle sessions without restart resume. Adapt transcript projection from Goose plugin PR #1010 while retaining Mesh inference and the managed tool bridge. Co-authored-by: Salman Mohammed <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: JimCodey <fab731feb32f528977dec0f8e40b557d552d1c795ae5c8d75e7dc071c2b05aa0@meshllm.communities.buzz.xyz>
1 parent 952f533 commit b923cf1

10 files changed

Lines changed: 1576 additions & 171 deletions

‎src/bundled/mesh-compute/MESH_AGENT.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,14 @@ bin/pnpm tauri build --features mesh --bundles app \
6969
- Release packaging: the sidecar build and mesh Tauri config are explicit steps;
7070
the current `.github/workflows` do not invoke them. Packaged real-mesh
7171
acceptance remains required before declaring this path validated.
72-
- Turns are queued per conversation, not steered into an active turn.
72+
- Agent turns accept mid-turn steering for the same conversation/configuration;
73+
a finished run falls back to the next turn. Chat stays sequential.
74+
- Idle sessions close after 15 minutes. App/process restart starts fresh from
75+
recent Buzz conversation history, not `session/load`. Tool-enabled agents
76+
receive fresh core memory via the shared agent-harness reader.
77+
- The Transcripts tab reads recent saved sessions through the managed binary,
78+
without preparing inference. It shows a read-only snapshot (Refresh for new
79+
activity), up to 50 sessions within five pages and 50 turns per session.
80+
Older builds did not label sessions with stable agent/place metadata, so their
81+
sessions are not listed. Chat has no Goose tool transcript.
7382
- Triggering verified only for explicit owner mentions.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// @vitest-environment jsdom
2+
import "@testing-library/jest-dom/vitest";
3+
import { act, cleanup, render, screen, waitFor } from "@testing-library/react";
4+
import userEvent from "@testing-library/user-event";
5+
import { afterEach, expect, it, vi } from "vitest";
6+
import type { AgentViewProps } from "../../features/agents/service";
7+
import { meshAgentConfig, type MeshAgentConfig } from "./meshAgent";
8+
import type { MeshHistory } from "./meshTranscript";
9+
import { createMeshTranscriptTab } from "./MeshTranscriptTab";
10+
11+
afterEach(cleanup);
12+
const props = {
13+
agent: { pubkey: "agent", name: "Mesh helper", config: meshAgentConfig({}) },
14+
save: vi.fn(),
15+
} as unknown as AgentViewProps<MeshAgentConfig>;
16+
const row = {
17+
sessionId: "s1",
18+
title: "saved",
19+
at: 1791940000000,
20+
channelId: "channel",
21+
};
22+
const transcript = { turns: [], unknownThread: 0, more: false };
23+
24+
it("shows a held read, then a read-only saved transcript using host components", async () => {
25+
let release!: (value: typeof transcript) => void;
26+
let entered!: () => void;
27+
const started = new Promise<void>((resolve) => {
28+
entered = resolve;
29+
});
30+
const gate = new Promise<typeof transcript>((resolve) => {
31+
release = resolve;
32+
});
33+
const history = {
34+
recent: vi.fn(async () => [row]),
35+
transcript: vi.fn(() => {
36+
entered();
37+
return gate;
38+
}),
39+
};
40+
const Tab = createMeshTranscriptTab(history as unknown as MeshHistory);
41+
render(<Tab {...props} />);
42+
try {
43+
await waitFor(() => expect(history.transcript).toHaveBeenCalled());
44+
await started;
45+
expect(screen.getByRole("status")).toHaveTextContent(
46+
"Reading saved Mesh sessions",
47+
);
48+
expect(screen.getByRole("button", { name: "Refresh" })).toHaveAttribute(
49+
"aria-disabled",
50+
"true",
51+
);
52+
await act(async () => {
53+
release(transcript);
54+
await gate;
55+
});
56+
expect(await screen.findByText(/Saved snapshot/)).toBeVisible();
57+
expect(screen.getByRole("button", { name: "Refresh" })).toBeEnabled();
58+
} finally {
59+
release(transcript);
60+
}
61+
});
62+
63+
it("offers refresh after a read failure and distinguishes empty history", async () => {
64+
const history = {
65+
recent: vi
66+
.fn()
67+
.mockRejectedValueOnce(new Error("offline"))
68+
.mockResolvedValueOnce([]),
69+
transcript: vi.fn(),
70+
};
71+
const Tab = createMeshTranscriptTab(history as unknown as MeshHistory);
72+
render(<Tab {...props} />);
73+
expect(await screen.findByRole("alert")).toHaveTextContent("offline");
74+
await userEvent.click(screen.getByRole("button", { name: "Refresh" }));
75+
expect(await screen.findByText(/No matching Mesh sessions/)).toBeVisible();
76+
expect(history.transcript).not.toHaveBeenCalled();
77+
});
78+
79+
it("does not display a late result after the viewed agent changes", async () => {
80+
let release!: (value: typeof transcript) => void;
81+
let entered!: () => void;
82+
const started = new Promise<void>((resolve) => {
83+
entered = resolve;
84+
});
85+
const gate = new Promise<typeof transcript>((resolve) => {
86+
release = resolve;
87+
});
88+
const history = {
89+
recent: vi.fn().mockResolvedValueOnce([row]).mockResolvedValueOnce([]),
90+
transcript: vi.fn(() => {
91+
entered();
92+
return gate;
93+
}),
94+
};
95+
const Tab = createMeshTranscriptTab(history as unknown as MeshHistory);
96+
const mounted = render(<Tab {...props} />);
97+
try {
98+
await waitFor(() => expect(history.transcript).toHaveBeenCalled());
99+
await started;
100+
mounted.rerender(
101+
<Tab {...props} agent={{ ...props.agent, pubkey: "other" }} />,
102+
);
103+
await screen.findByText(/No matching Mesh sessions/);
104+
await act(async () => {
105+
release(transcript);
106+
await gate;
107+
});
108+
expect(screen.queryByText(/Saved snapshot/)).not.toBeInTheDocument();
109+
} finally {
110+
release(transcript);
111+
}
112+
});
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import { useEffect, useState } from "react";
2+
import type { AgentViewProps } from "../../features/agents/service";
3+
import { ActivityTranscript } from "../../features/agents/ActivityTranscript";
4+
import { Button } from "../../shared/design-system/ui/Button";
5+
import { Select } from "../../shared/design-system/ui/Select";
6+
import { meshAgentConfig, type MeshAgentConfig } from "./meshAgent";
7+
import type {
8+
GooseTranscript,
9+
MeshHistory,
10+
MeshHistoryRow,
11+
} from "./meshTranscript";
12+
13+
/** The Agents/profile host owns framing and tabs; this body only reads history. */
14+
export function createMeshTranscriptTab(history: MeshHistory) {
15+
return function MeshTranscriptTab({
16+
agent,
17+
conversation,
18+
}: AgentViewProps<MeshAgentConfig>) {
19+
const workspace = meshAgentConfig(agent.config).workspace;
20+
const [rows, setRows] = useState<MeshHistoryRow[]>();
21+
const [selected, setSelected] = useState("");
22+
const [transcript, setTranscript] = useState<GooseTranscript>();
23+
const [error, setError] = useState<string>();
24+
const [loading, setLoading] = useState(true);
25+
const [attempt, setAttempt] = useState(0);
26+
// biome-ignore lint/correctness/useExhaustiveDependencies: attempt is the explicit refresh.
27+
useEffect(() => {
28+
const abort = new AbortController();
29+
setRows(undefined);
30+
setSelected("");
31+
setTranscript(undefined);
32+
setError(undefined);
33+
setLoading(true);
34+
void history.recent(agent.pubkey, workspace, abort.signal).then(
35+
(found) => {
36+
if (abort.signal.aborted) return;
37+
setRows(found);
38+
const nearby = found.find(
39+
(row) =>
40+
row.channelId === conversation?.channelId &&
41+
(!row.root || row.root === conversation?.rootId),
42+
);
43+
setSelected((nearby ?? found[0])?.sessionId ?? "");
44+
setLoading(false);
45+
},
46+
(reason: unknown) => {
47+
if (abort.signal.aborted) return;
48+
setError(String(reason));
49+
setLoading(false);
50+
},
51+
);
52+
return () => abort.abort();
53+
}, [
54+
agent.pubkey,
55+
workspace,
56+
conversation?.channelId,
57+
conversation?.rootId,
58+
attempt,
59+
]);
60+
useEffect(() => {
61+
const row = rows?.find((item) => item.sessionId === selected);
62+
if (!row) return;
63+
const abort = new AbortController();
64+
setLoading(true);
65+
setTranscript(undefined);
66+
setError(undefined);
67+
void history.transcript(agent.pubkey, workspace, row, abort.signal).then(
68+
(found) => {
69+
if (abort.signal.aborted) return;
70+
setTranscript(found);
71+
setLoading(false);
72+
},
73+
(reason: unknown) => {
74+
if (abort.signal.aborted) return;
75+
setError(String(reason));
76+
setLoading(false);
77+
},
78+
);
79+
return () => abort.abort();
80+
}, [rows, selected, agent.pubkey, workspace]);
81+
return (
82+
<div className="grid gap-4">
83+
<div>
84+
<Button
85+
variant="ghost"
86+
loading={loading}
87+
onClick={() => setAttempt((value) => value + 1)}
88+
>
89+
Refresh
90+
</Button>
91+
</div>
92+
{rows && rows.length > 0 && (
93+
<Select
94+
label="Session"
95+
variant="field"
96+
value={selected}
97+
onValueChange={setSelected}
98+
groups={[
99+
{
100+
label: "Recent sessions",
101+
options: rows.map((row) => ({
102+
value: row.sessionId,
103+
label: `${new Date(row.at).toLocaleString()} · ${row.root ? "Thread" : "Channel"} ${row.channelId.slice(0, 8)}`,
104+
})),
105+
},
106+
]}
107+
/>
108+
)}
109+
{error ? (
110+
<p role="alert" className="m-0 text-body-sm">
111+
Could not read the transcript: {error}. Try Refresh.
112+
</p>
113+
) : loading ? (
114+
<p role="status" className="m-0 text-body-sm text-subtle">
115+
Reading saved Mesh sessions…
116+
</p>
117+
) : rows?.length === 0 ? (
118+
<p className="m-0 text-body-sm text-subtle">
119+
No matching Mesh sessions in recent history for this workspace. Chat
120+
mode has no tool transcript. Sessions from older builds may not be
121+
listed.
122+
</p>
123+
) : (
124+
transcript && (
125+
<ActivityTranscript
126+
transcript={transcript}
127+
agentName={agent.name}
128+
state={() => "unknown"}
129+
before={
130+
<p className="m-0 text-body-sm text-subtle">
131+
Saved snapshot; Refresh to see newer activity.
132+
{transcript.more ? " Showing the latest 50 turns." : ""}
133+
</p>
134+
}
135+
/>
136+
)
137+
)}
138+
</div>
139+
);
140+
};
141+
}

‎src/bundled/mesh-compute/index.test.tsx‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,3 +1626,52 @@ it("prepares a background agent against its own community, not the foreground",
16261626
for (const cleanup of cleanups.reverse()) cleanup();
16271627
}
16281628
});
1629+
1630+
it("releases the host queue while retaining Agent work for mid-turn delivery", async () => {
1631+
const { MeshAgentRuntime } = await import("./meshAgent");
1632+
let release!: () => void;
1633+
const pending = new Promise<void>((resolve) => {
1634+
release = resolve;
1635+
});
1636+
const runRuntime = vi
1637+
.spyOn(MeshAgentRuntime.prototype, "run")
1638+
.mockReturnValue(pending);
1639+
let run!: (
1640+
delivery: import("../../features/agents/service").Delivery,
1641+
) => unknown;
1642+
const cleanups: (() => void)[] = [];
1643+
const snapshot = { status: "idle" };
1644+
apply({
1645+
relay: { snapshot: () => snapshot, subscribe: () => () => {} },
1646+
host: { spawn: vi.fn() },
1647+
agents: {
1648+
register: (type: { run: typeof run }) => {
1649+
run = type.run;
1650+
},
1651+
},
1652+
effect: (setup: () => () => void) => {
1653+
cleanups.push(setup());
1654+
},
1655+
settingsCards: { register: () => {} },
1656+
} as unknown as Parameters<PluginModule["apply"]>[0]);
1657+
try {
1658+
const workingUntil = vi.fn();
1659+
expect(
1660+
run({
1661+
config: { mode: "agent" },
1662+
workingUntil,
1663+
} as unknown as import("../../features/agents/service").Delivery),
1664+
).toBeUndefined();
1665+
expect(workingUntil).toHaveBeenCalledWith(pending);
1666+
expect(
1667+
run({
1668+
config: { mode: "chat" },
1669+
workingUntil,
1670+
} as unknown as import("../../features/agents/service").Delivery),
1671+
).toBe(pending);
1672+
} finally {
1673+
release();
1674+
runRuntime.mockRestore();
1675+
for (const cleanup of cleanups.reverse()) cleanup();
1676+
}
1677+
});

0 commit comments

Comments
 (0)