* feat(MCP): follow agent activity in canvas * feat(collab): show MCP, ACP, and harness sessions as agents MCP clients worked on the document unseen: only the built-in chat had a presence, and following agent activity meant a separate setting that moved the viewport after every MCP tool. Each MCP session now shows as an agent with a callsign in its owner's color, like the chat: the MCP server forwards the session and the client's name with each tool call, the app's own ACP and Pi harness chats mark their sessions with a header, and the agent points at the layers each call reads or changes on their page. It rests after a quiet spell, leaves when its session ends or the server disconnects, and collaborators see it through awareness. Following it works like following anyone else, from the avatars, so the default-on follow setting and its viewport fitting go. Co-authored-by: Victor Wads <victor@wads.dev> * feat(ai): move the chat's agent through JSX as it streams While the built-in chat streamed a render call, its preview grew on the canvas but the agent stood still until the tool finished. The preview now reports, after each update, the element that appeared last and the bounds of what the JSX builds; the agent's cursor follows that element and its outline traces the preview, for collaborators too, until the tool runs and the agent outlines the real layers. Peers' outlines are validated and capped like their selections. Co-authored-by: Victor Wads <victor@wads.dev> * feat(collab): glide cursors and the followed view instead of jumping People's and agents' cursors jumped to each new point, which with throttled awareness and an agent streaming JSX made them stutter, and following re-centered the view in one jump on every update. Cursors now ease to each new point from wherever they are drawn, and following pans and zooms the view there the same way, stopping in place when you take over. With animations off or reduced motion, both move at once. Each cursor carries an id so it keeps its glide between updates. Co-authored-by: Victor Wads <victor@wads.dev> * test(collab): cover MCP agents and the streaming agent in the browser Test runs send MCP requests through the bridge's own command handler, so a browser test can show an MCP session as an agent to the editor and to a collaborator without a separate server. The streaming JSX test checks that the chat's agent cursor and outline follow the newest element. Co-authored-by: Victor Wads <victor@wads.dev> * docs: describe agent sessions, streaming cursors, and gliding follow Co-authored-by: Victor Wads <victor@wads.dev> * fix(ai): keep the streaming agent's name off the text it writes The chat's agent sat at the newest streamed element's top-left corner, so its name label covered the text being written. It now sits at the element's trailing corner, where content grows. Co-authored-by: Victor Wads <victor@wads.dev> * fix(collab): end only a closed connection's own MCP sessions When the app's connection to the MCP server closed, every MCP session's agent left, including sessions that never came over that connection, such as a second editor's. The bridge now remembers the sessions each connection carried and ends only those. Co-authored-by: Victor Wads <victor@wads.dev> * feat(ai): follow your agents automatically while they work Agents spun up from the chat or an MCP client worked out of sight and then went idle, so people had to find what changed, and the agent skill told agents to move the user's view and selection after every edit. A Follow agents toggle in the AI panel's header, on by default, now has the view follow our agents from the start of each run: whichever starts first, then the next one at work once the followed agent rests. Leaving the page, moving the view, Escape, or Stop following leaves that agent alone until it rests; people are never followed this way. The skill no longer asks agents to select and zoom to their work. Co-authored-by: Victor Wads <victor@wads.dev> * fix(collab): keep an MCP agent when a restarted bridge carries its session Restarting MCP disconnects the old bridge and opens a new one at once, but the browser reports the old socket's close only after its close handshake. A tool call that reached the new connection in between was undone by that close, which ended the session and removed its agent. Sessions now record every connection their calls came over, across bridges, and end only when the last of them closes. The docs no longer say that following an agent keeps it from editing out of sight: following moves your view, and the stale variables and follow bullets the changelog's union merge brought back are removed. Co-authored-by: Victor Wads <victor@wads.dev> * test(collab): record what the bridge sends instead of an empty fake method Co-authored-by: Victor Wads <victor@wads.dev> --------- Co-authored-by: Danila Poyarkov <dev@dannote.net>
144 lines
5 KiB
TypeScript
144 lines
5 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
|
|
import { startAgent } from '#tests/helpers/collab/agent'
|
|
import {
|
|
collaborationErrors,
|
|
connect,
|
|
share,
|
|
createPeer,
|
|
startRelay,
|
|
type Peer
|
|
} from '#tests/helpers/collab/room'
|
|
|
|
function pageNames(peer: Peer) {
|
|
return peer.page.evaluate(
|
|
() =>
|
|
window.openPencil
|
|
?.getStore?.()
|
|
.graph.getPages()
|
|
.map((page) => page.name) ?? []
|
|
)
|
|
}
|
|
|
|
test("a guest's agent shows on their avatar and can be followed until Escape", async ({
|
|
browser
|
|
}) => {
|
|
const relay = await startRelay()
|
|
let host: Peer | null = null
|
|
let guest: Peer | null = null
|
|
try {
|
|
host = await createPeer(browser, 'Host', relay.url)
|
|
guest = await createPeer(browser, 'Guest', relay.url)
|
|
await share(host)
|
|
await connect(guest)
|
|
await expect
|
|
.poll(() => host?.page.evaluate(() => window.openPencil?.test?.collab?.peerCount()))
|
|
.toBe(1)
|
|
|
|
await host.page.evaluate(() => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
store.graph.addPage('Checkout')
|
|
})
|
|
const peer = guest
|
|
await expect.poll(() => pageNames(peer)).toContain('Checkout')
|
|
const agent = await startAgent(guest.page, 'Checkout', 300, 200)
|
|
|
|
// The guest's avatar carries a count of their agents; hovering lists them.
|
|
const avatar = host.page.getByTestId('collab-peer-avatar')
|
|
await expect(avatar).toContainText('1')
|
|
await avatar.hover()
|
|
const card = host.page.getByTestId('collab-peer-card')
|
|
await expect(card.getByText(agent.name)).toBeVisible()
|
|
await expect(card.getByText('Editing · Checkout')).toBeVisible()
|
|
|
|
await card.getByRole('button', { name: `Follow ${agent.name}` }).click()
|
|
await expect
|
|
.poll(() => host?.page.evaluate(() => window.openPencil?.getStore?.().state.currentPageId))
|
|
.toBe(agent.pageId)
|
|
const frame = host.page.getByTestId('follow-frame')
|
|
await expect(frame).toContainText(`Following ${agent.name}`)
|
|
|
|
await host.page.keyboard.press('Escape')
|
|
await expect(frame).toHaveCount(0)
|
|
expect(collaborationErrors(host)).toEqual([])
|
|
} finally {
|
|
await host?.context.close()
|
|
await guest?.context.close()
|
|
await relay.close()
|
|
}
|
|
})
|
|
|
|
test('an MCP session shows as an agent at the layers it touches, to collaborators too', async ({
|
|
browser
|
|
}) => {
|
|
// Two peers in a room, a tool call, and following it, stopping, and following again.
|
|
test.setTimeout(90_000)
|
|
const relay = await startRelay()
|
|
let host: Peer | null = null
|
|
let guest: Peer | null = null
|
|
try {
|
|
host = await createPeer(browser, 'Host', relay.url)
|
|
guest = await createPeer(browser, 'Guest', relay.url)
|
|
await share(host)
|
|
await connect(guest)
|
|
const nodeId = await host.page.evaluate(() => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
return store.graph.createNode('FRAME', store.state.currentPageId, {
|
|
name: 'Card',
|
|
x: 240,
|
|
y: 160,
|
|
width: 200,
|
|
height: 120
|
|
}).id
|
|
})
|
|
|
|
// A tool call as the MCP bridge delivers it, from a session of an outside client.
|
|
await host.page.evaluate(
|
|
(id) =>
|
|
window.openPencil?.test?.automation?.('tool', {
|
|
name: 'rename_node',
|
|
args: { id, name: 'Checkout card' },
|
|
agent: { session: 'session-1', kind: 'mcp', client: 'claude-code' }
|
|
}),
|
|
nodeId
|
|
)
|
|
const agent = await host.page.evaluate(() => {
|
|
const cursor = window.openPencil
|
|
?.getStore?.()
|
|
.state.presenceCursors.find((entry) => entry.kind === 'agent')
|
|
return cursor ? { name: cursor.name, x: cursor.x, y: cursor.y } : null
|
|
})
|
|
expect(agent).toMatchObject({ x: 240, y: 160 })
|
|
const name = agent?.name ?? ''
|
|
|
|
// With Follow agents on, as by default, its owner's view follows it as soon as it works.
|
|
const frame = host.page.getByTestId('follow-frame')
|
|
await expect(frame).toContainText(`Following ${name}`)
|
|
await frame.getByRole('button', { name: 'Stop following' }).click()
|
|
await expect(frame).toHaveCount(0)
|
|
|
|
// Its owner lists it on their avatar and can follow it again like any agent.
|
|
await host.page.getByTestId('collab-local-avatar').click()
|
|
const menu = host.page.getByTestId('collab-self-menu')
|
|
await expect(menu.getByText(name)).toBeVisible()
|
|
await menu.getByRole('button', { name: `Follow ${name}` }).click()
|
|
await expect(frame).toContainText(`Following ${name}`)
|
|
|
|
// Collaborators see it on its owner's avatar.
|
|
await expect(guest.page.getByTestId('collab-peer-avatar')).toContainText('1')
|
|
|
|
// When the session ends, the agent leaves.
|
|
await host.page.evaluate(() =>
|
|
window.openPencil?.test?.automation?.('agent_session_closed', { session: 'session-1' })
|
|
)
|
|
await expect(frame).toHaveCount(0)
|
|
expect(collaborationErrors(host)).toEqual([])
|
|
} finally {
|
|
await host?.context.close()
|
|
await guest?.context.close()
|
|
await relay.close()
|
|
}
|
|
})
|