feat(walkthrough): open the change walkthrough from an agent tool call

This commit is contained in:
Chris Scott committed 2026-10-09 11:03:21 -04:00
1 parent 3eb0b02203
commit aa1da8d608
26 files changed
+1367 -175

No files matched your search

@@ -17,7 +17,9 @@ type JsonSchema = {
required?: string[]
additionalProperties?: boolean
anyOf?: JsonSchema[]
oneOf?: JsonSchema[]
enum?: string[]
const?: string
maxLength?: number
minLength?: number
}
@@ -41,9 +43,23 @@ function requestParamsSchema(tool: GeneratedTool): JsonSchema {
return toolInputSchema(tool).properties?.params?.anyOf?.[1] ?? {}
}
async function runTool(tool: GeneratedTool, input: unknown): Promise<string> {
const result = (await tool.execute!(input, { signal: new AbortController().signal })) as { content: string }
return result.content
function walkthroughParamsSchema(tool: GeneratedTool): JsonSchema {
return toolInputSchema(tool).properties?.params?.anyOf?.[2] ?? {}
}
async function runToolResult(
tool: GeneratedTool,
input: unknown,
context: { sessionID?: string } = {},
): Promise<{ content: string; metadata?: Record<string, unknown> }> {
return (await tool.execute!(input, { signal: new AbortController().signal, sessionID: context.sessionID })) as {
content: string
metadata?: Record<string, unknown>
}
}
async function runTool(tool: GeneratedTool, input: unknown, context: { sessionID?: string } = {}): Promise<string> {
return (await runToolResult(tool, input, context)).content
}
function jsonResponse(body: unknown, { ok = true, status = 200 } = {}) {
@@ -92,14 +108,31 @@ describe('ocm-manager plugin', () => {
expect(schema.type).toBe('object')
expect(schema.required).toEqual(['action', 'params'])
expect(schema.additionalProperties).toBe(false)
expect(schema.properties?.action?.enum).toEqual(['send_notification', 'request'])
expect(schema.properties?.params?.anyOf).toHaveLength(2)
expect(schema.properties?.action?.enum).toEqual(['send_notification', 'request', 'open_walkthrough'])
expect(schema.properties?.params?.anyOf).toHaveLength(3)
expect(notificationParamsSchema(tool).required).toEqual(['title', 'body'])
expect(requestParamsSchema(tool).required).toEqual(['method', 'path'])
expect(walkthroughParamsSchema(tool).required).toBeUndefined()
expect(notificationParamsSchema(tool).additionalProperties).toBe(false)
expect(requestParamsSchema(tool).additionalProperties).toBe(false)
expect(walkthroughParamsSchema(tool).additionalProperties).toBe(false)
expect(notificationParamsSchema(tool).properties?.priority?.enum).toEqual(['normal', 'high'])
expect(requestParamsSchema(tool).properties?.method?.enum).toEqual(['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
expect(walkthroughParamsSchema(tool).properties?.source?.oneOf?.map((variant) => variant.properties?.kind?.const)).toEqual([
'session',
'uncommitted',
'staged',
'unstaged',
'branch',
'pullRequest',
])
})
it('lists the open_walkthrough action in the description', async () => {
const tool = await loadTool(configHome)
expect(tool.description).toContain('open_walkthrough')
expect(tool.description).toContain("open the change Walkthrough panel for the current session in the user's Manager window")
})
it('enforces the notification limits the internal API enforces', async () => {
@@ -191,6 +224,52 @@ describe('ocm-manager plugin', () => {
expect(fetchMock).not.toHaveBeenCalled()
})
it('opens the walkthrough for the current session with the requested source', async () => {
const fetchMock = jsonResponse({ walkthrough: { stops: [{}, {}] }, currentDiffHash: 'h', stale: false, generating: false, error: null })
vi.stubGlobal('fetch', fetchMock)
const tool = await loadTool(configHome)
const result = await runToolResult(
tool,
{ action: 'open_walkthrough', params: { source: { kind: 'staged' } } },
{ sessionID: 'ses_abc' },
)
expect(fetchMock).toHaveBeenCalledTimes(1)
const [url, init] = fetchMock.mock.calls[0] ?? []
expect(url).toBe('http://localhost:5003/api/internal/change-walkthroughs/ses_abc')
expect(init.method).toBe('POST')
expect(init.headers.Authorization).toBe('Bearer secret-token')
expect(init.headers['content-type']).toBe('application/json')
expect(JSON.parse(init.body)).toEqual({ source: { kind: 'staged' } })
expect(result.content).toBe('Opened the walkthrough (2 stops).')
expect(result.metadata).toEqual({ openPanel: 'walkthrough', source: { kind: 'staged' } })
})
it('reports that the walkthrough is generating', async () => {
vi.stubGlobal('fetch', jsonResponse({ walkthrough: null, currentDiffHash: 'h', stale: false, generating: true, error: null }))
const tool = await loadTool(configHome)
const result = await runToolResult(tool, { action: 'open_walkthrough', params: {} }, { sessionID: 'ses_abc' })
expect(result.content).toBe('Opened the walkthrough. It is generating; the user can page through it as stops are explained.')
expect(result.metadata).toEqual({ openPanel: 'walkthrough' })
})
it('opens the walkthrough without a body when no source is given', async () => {
const fetchMock = jsonResponse({ walkthrough: null, currentDiffHash: 'h', stale: false, generating: true, error: null })
vi.stubGlobal('fetch', fetchMock)
const tool = await loadTool(configHome)
await runTool(tool, { action: 'open_walkthrough', params: {} }, { sessionID: 'ses_abc' })
expect(fetchMock).toHaveBeenCalledTimes(1)
const [url, init] = fetchMock.mock.calls[0] ?? []
expect(url).toBe('http://localhost:5003/api/internal/change-walkthroughs/ses_abc')
expect(init.headers['content-type']).toBeUndefined()
expect(init.body).toBeUndefined()
})
it('sends an allow-listed GET request with a query string and no body', async () => {
const fetchMock = jsonResponse({ userId: 'default', theme: 'dark' })
vi.stubGlobal('fetch', fetchMock)
@@ -522,7 +601,7 @@ describe.skipIf(SHIPPED_OPENCODE_BIN === null)('ocm-manager plugin against the s
expect(managerTool?.function?.parameters).toMatchObject({
type: 'object',
properties: {
action: { type: 'string', enum: ['send_notification', 'request'] },
action: { type: 'string', enum: ['send_notification', 'request', 'open_walkthrough'] },
params: {
anyOf: [
{
@@ -545,6 +624,13 @@ describe.skipIf(SHIPPED_OPENCODE_BIN === null)('ocm-manager plugin against the s
body: { type: 'object' },
},
},
{
type: 'object',
additionalProperties: false,
properties: {
source: expect.anything(),
},
},
],
},
},