mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-01 06:31:27 +00:00
* feat(web): feature-flagged rich composer for inline session @ mentions Custom segmented contenteditable (not TipTap) inserts caret-local session atoms from the existing @ picker and serializes to markdown links on send. Textarea path remains default until flag parity dogfood. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): rich composer mention boundary + #1215 refs Treat U+FFFC mirror atoms as word boundaries so @ after a session token still opens autocomplete. Point comments at Fixes #1215. Co-authored-by: Cursor <cursoragent@cursor.com> * test(web): peer-stack e2e for rich composer session @ mentions (#1215) Smoke: flag on, @ picker inserts inline session atom chip (not prose dump). Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): preserve newlines in rich composer Enter-newline mode Chromium splits contenteditable on Enter into block divs; serialize those as \\n and insert <br> when parent leaves Enter unhandled (Shift+Enter / enter-inserts-newline). Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): show @ badge when rich composer mentions flag is on Dogfood was invisible: flag-off looks like a normal textarea, and flag-on had no chrome. Surface a small @ badge when enabled. * fix(web): rich session composer on by default (not a user setting) The plan dual-path was an engineering kill-switch, not an opt-in. Default to the segmented composer; only richMentions=0 disables. Drop the flag badge and record a peer-stack motion proof covering chips + baseline UX. * fix(web): make rich composer Shift+Enter create a visible newline Trailing <br>+empty text node was a silent no-op at EOL. Use insertLineBreak (ZWSP pad fallback), assert real \\n in peer e2e. * feat(web): hover tooltips on rich composer session chips Show full title, status, short id, and path on chip hover via a portal bubble fed by live useSessions lookup (drafts fall back to title + id). * fix(web): dismiss rich composer chip tooltips on mouse leave contenteditable pointerout/relatedTarget was flaky so tips stuck after leaving the chip. Hit-test on pointermove, clear on prose/input/leave. * fix(web): address cold-review Blocker/Majors on rich composer Exclude peer e2e from default Playwright; force plain-text paste; restore newline hard-stop in findActiveWord; fix root-anchored selection mapping and nested-block serialize; cover with unit tests. * chore: drop accidental .cursor files from rich-composer tip * fix(web): close remaining cold-review gaps on rich composer Drop absolute peer e2e tooling imports, prove chip→markdown send, and harden paste/EOL/focus/tooltip/Enter edges before Meta rematerialize. Co-authored-by: Cursor <cursoragent@cursor.com> * chore: absorb soup playwright.config union for clean remat Keep fork peer-stack timeouts/annotated-video wiring and add testIgnore for e2e/peer so the next driver rematerialize does not conflict. Co-authored-by: Cursor <cursoragent@cursor.com> * revert: drop fork playwright tooling from upstreamable tip Peer-stack annotated-video + HAPI_PEER wiring stay on fork main / soup. Product tip only needs testIgnore for e2e/peer (see docs/tooling/peer-stack.md). Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): fix rich composer Shift+Enter double newline and paste space Prefer manual newline+pad over execCommand insertLineBreak, and stop applying autocomplete trailing-space on paste/drop paths. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): pad EOL Shift+Enter after Range.insertNode split insertNode always leaves an empty text sibling, so !nextSibling never saw EOL; detect meaningful trailing content and cover with jsdom tests. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): drop custom onDrop from rich composer Intercepting drop without caretRangeFromPoint landed text at EOF or no-oped in-editor moves. Native CE drop is enough for #1215; paste still forces plain text. Co-authored-by: Cursor <cursoragent@cursor.com> * feat(web): sidebar-parity tooltips on rich composer session chips Reuse SessionRowSummary (flavor, thinking/attention, schedule, todos, relative ago, path) for chip hover so the tip matches the session list. Co-authored-by: Cursor <cursoragent@cursor.com> * chore: keep peer-stack e2e off the upstreamable tip Peer specs and playwright.peer.config stay on fork main per docs/tooling/peer-stack.md; default config still testIgnore's e2e/peer. Co-authored-by: Cursor <cursoragent@cursor.com> * feat: cite sessions with UUID wire + inspect_peer for agent/overseer Rich composer chips already serialize to [title](/sessions/<id>); flush before send so the agent prompt never gets title-only chip text. Add inspect_peer (MCP + hapi inspect-peer) as the read twin of ping_peer so that same id is immediately usable for overseer/agent peer lookup, with system-prompt glue from citations to inspect/ping. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cli): gate inspect_peer behind permission approval Cross-session history reads need the same prompt path as ping_peer: keep inspect_peer off Claude --allowedTools and treat it as sensitive in ACP/OpenCode read-only mode so prompt injection cannot silently enumerate peer transcripts. Co-authored-by: Cursor <cursoragent@cursor.com> * chore: clarify playwright peer testIgnore is upstream-safe Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): keep session UUIDs on rich composer copy/cut/paste Copy/cut write wire markdown so chips do not collapse to @title-only clipboard text; paste reparses session links back into atoms. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
190 lines
6.3 KiB
TypeScript
190 lines
6.3 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const harness = vi.hoisted(() => ({
|
|
sendSessionDeath: vi.fn(),
|
|
userMessageHandler: null as null | ((message: { content: { text: string; attachments: unknown[] } }, localId: string) => void),
|
|
promptError: null as Error | null,
|
|
cancelPrompt: vi.fn(async () => {}),
|
|
cancelAll: vi.fn(async () => {}),
|
|
stopServer: vi.fn(),
|
|
disconnect: vi.fn(async () => {}),
|
|
prompts: [] as unknown[][],
|
|
startHappyServerOptions: null as unknown,
|
|
bridgeArgs: [] as string[],
|
|
newSessionOptions: null as unknown,
|
|
killHandler: null as null | (() => Promise<void>)
|
|
}))
|
|
|
|
vi.mock('@/agent/sessionFactory', () => ({
|
|
bootstrapSession: vi.fn(async () => ({
|
|
session: {
|
|
updateAgentState: vi.fn(),
|
|
onUserMessage: vi.fn((handler) => {
|
|
harness.userMessageHandler = handler
|
|
}),
|
|
onCancelQueuedMessage: vi.fn(),
|
|
keepAlive: vi.fn(),
|
|
sendSessionEvent: vi.fn(),
|
|
sendAgentMessage: vi.fn(),
|
|
sendSessionDeath: harness.sendSessionDeath,
|
|
flush: vi.fn(async () => {}),
|
|
close: vi.fn(),
|
|
rpcHandlerManager: {
|
|
registerHandler: vi.fn()
|
|
}
|
|
},
|
|
sessionInfo: {
|
|
permissionMode: 'default'
|
|
}
|
|
}))
|
|
}))
|
|
|
|
vi.mock('@/agent/AgentRegistry', () => ({
|
|
AgentRegistry: {
|
|
create: vi.fn(() => ({
|
|
initialize: vi.fn(async () => {}),
|
|
newSession: vi.fn(async (options: unknown) => {
|
|
harness.newSessionOptions = options
|
|
return 'agent-session-1'
|
|
}),
|
|
prompt: vi.fn(async (_sessionId: string, content: unknown[]) => {
|
|
harness.prompts.push(content)
|
|
if (harness.promptError) {
|
|
throw harness.promptError
|
|
}
|
|
}),
|
|
cancelPrompt: harness.cancelPrompt,
|
|
respondToPermission: vi.fn(async () => {}),
|
|
onPermissionRequest: vi.fn(),
|
|
disconnect: harness.disconnect
|
|
}))
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/agent/permissionAdapter', () => ({
|
|
PermissionAdapter: vi.fn(function PermissionAdapter() {
|
|
return {
|
|
cancelAll: harness.cancelAll
|
|
}
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/claude/utils/startHappyServer', () => ({
|
|
startHappyServer: vi.fn(async (_session: unknown, options: unknown) => {
|
|
harness.startHappyServerOptions = options
|
|
return {
|
|
url: 'http://127.0.0.1:1234',
|
|
toolNames: ['change_title', 'display_image', 'ping_peer', 'inspect_peer', 'skill_lookup'],
|
|
stop: harness.stopServer
|
|
}
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/utils/spawnHappyCLI', () => ({
|
|
getHappyCliCommand: vi.fn((args: string[]) => {
|
|
harness.bridgeArgs = args
|
|
return { command: 'hapi', args, env: [] }
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/claude/registerKillSessionHandler', () => ({
|
|
registerKillSessionHandler: vi.fn((_manager: unknown, handler: () => Promise<void>) => {
|
|
harness.killHandler = handler
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/utils/invokedCwd', () => ({
|
|
getInvokedCwd: vi.fn(() => '/tmp/project')
|
|
}))
|
|
|
|
vi.mock('@/ui/logger', () => ({
|
|
logger: {
|
|
debug: vi.fn(),
|
|
warn: vi.fn()
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/utils/attachmentFormatter', () => ({
|
|
formatMessageWithAttachments: vi.fn((text: string) => text)
|
|
}))
|
|
|
|
import { runAgentSession } from './runAgentSession'
|
|
|
|
describe('runAgentSession', () => {
|
|
beforeEach(() => {
|
|
harness.sendSessionDeath.mockClear()
|
|
harness.userMessageHandler = null
|
|
harness.promptError = null
|
|
harness.cancelPrompt.mockClear()
|
|
harness.cancelAll.mockClear()
|
|
harness.stopServer.mockClear()
|
|
harness.disconnect.mockClear()
|
|
harness.prompts = []
|
|
harness.startHappyServerOptions = null
|
|
harness.bridgeArgs = []
|
|
harness.newSessionOptions = null
|
|
harness.killHandler = null
|
|
})
|
|
|
|
it('reports unhandled ACP runner failures as error, not completed', async () => {
|
|
harness.cancelAll.mockImplementationOnce(async () => {
|
|
throw new Error('cancel failed')
|
|
})
|
|
|
|
const running = runAgentSession({ agentType: 'acp' })
|
|
for (let i = 0; i < 5; i++) {
|
|
await Promise.resolve()
|
|
}
|
|
expect(harness.userMessageHandler).not.toBeNull()
|
|
harness.userMessageHandler?.({ content: { text: 'hello', attachments: [] } }, 'local-1')
|
|
|
|
await expect(running).rejects.toThrow('cancel failed')
|
|
|
|
expect(harness.sendSessionDeath).toHaveBeenCalledWith('error')
|
|
expect(harness.sendSessionDeath).not.toHaveBeenCalledWith('completed')
|
|
})
|
|
|
|
it('enables skill lookup and injects its instruction only on the first prompt', async () => {
|
|
const running = runAgentSession({ agentType: 'acp' })
|
|
await vi.waitFor(() => expect(harness.userMessageHandler).not.toBeNull())
|
|
|
|
harness.userMessageHandler?.({ content: { text: 'first', attachments: [] } }, 'local-1')
|
|
await vi.waitFor(() => expect(harness.prompts).toHaveLength(1))
|
|
harness.userMessageHandler?.({ content: { text: 'second', attachments: [] } }, 'local-2')
|
|
await vi.waitFor(() => expect(harness.prompts).toHaveLength(2))
|
|
|
|
await harness.killHandler?.()
|
|
await running
|
|
|
|
expect(harness.startHappyServerOptions).toEqual({
|
|
skillLookup: {
|
|
workingDirectory: '/tmp/project',
|
|
flavor: 'acp'
|
|
}
|
|
})
|
|
expect(harness.bridgeArgs).toEqual([
|
|
'mcp',
|
|
'--url',
|
|
'http://127.0.0.1:1234',
|
|
'--tools',
|
|
'change_title,display_image,ping_peer,inspect_peer,skill_lookup'
|
|
])
|
|
expect(harness.newSessionOptions).toMatchObject({
|
|
cwd: '/tmp/project',
|
|
mcpServers: [{
|
|
name: 'happy',
|
|
command: 'hapi',
|
|
args: harness.bridgeArgs
|
|
}]
|
|
})
|
|
|
|
const firstPrompt = JSON.stringify(harness.prompts[0])
|
|
const secondPrompt = JSON.stringify(harness.prompts[1])
|
|
expect(firstPrompt).toContain('first')
|
|
expect(firstPrompt).not.toContain('skill_lookup')
|
|
expect(firstPrompt).not.toContain('$name')
|
|
expect(secondPrompt).toContain('second')
|
|
expect(secondPrompt).not.toContain('skill_lookup')
|
|
})
|
|
})
|