mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 00:35:51 +00:00
feat: 实现 ACP session/delete + message-id 两个 UNSTABLE RFD
session/delete(rfds/session-delete.mdx):
- sessionCapabilities.delete: {} 能力广告(类型增强写入,SDK 0.19.0 早于该 RFD)
- extMethod 钩子路由 session/delete → unstable_deleteSession
- 硬删除 .jsonl 文件,ENOENT 视为成功(幂等)
- 未知方法抛 RequestError.methodNotFound(JSON-RPC -32601)
message-id(rfds/message-id.mdx):
- agent_message_chunk / user_message_chunk / agent_thought_chunk 携带 messageId
- forwardSessionUpdates 维护 currentAgentMessageId,lazy 生成 UUID
- streaming text/thinking chunks 与最终 assistant message 共享同一 ID
- replayHistoryMessages per-message 生成 UUID
- PromptRequest.messageId → PromptResponse.userMessageId 回显
- tool_call / plan / subagent 不带 messageId(spec 仅规定 chunk 类型)
测试:ACP service 从 176 → 191 (+15)
- bridge.test.ts: +9 个 message-id 测试
- agent.test.ts: +6 个 session/delete + userMessageId 测试
- 总测试 5851 → 5866,全通过
审计文档:新增附录 A.2 记录两个 UNSTABLE RFD 实现状态
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
This commit is contained in:
@@ -297,6 +297,16 @@ describe('AcpAgent', () => {
|
||||
(res.agentCapabilities?._meta as any)?.claudeCode?.forkSession,
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
test('advertises session/delete capability per session-delete RFD', async () => {
|
||||
// UNSTABLE per session-delete.mdx: capability-gated session/delete.
|
||||
// SDK 0.19.0's SessionCapabilities type predates this field; we advertise
|
||||
// it via type augmentation so clients implementing the RFD can find it.
|
||||
const agent = new AcpAgent(makeConn())
|
||||
const res = await agent.initialize({} as any)
|
||||
const caps = res.agentCapabilities?.sessionCapabilities as any
|
||||
expect(caps.delete).toEqual({})
|
||||
})
|
||||
})
|
||||
|
||||
describe('authenticate', () => {
|
||||
@@ -634,6 +644,54 @@ describe('AcpAgent', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('deleteSession (session/delete via extMethod)', () => {
|
||||
test('extMethod routes session/delete to unstable_deleteSession', async () => {
|
||||
const agent = new AcpAgent(makeConn())
|
||||
const result = await agent.extMethod('session/delete', {
|
||||
sessionId: 'nonexistent-sid-for-delete-test',
|
||||
})
|
||||
// Idempotent: returns empty object even when session doesn't exist
|
||||
expect(result).toEqual({})
|
||||
})
|
||||
|
||||
test('rejects session/delete without sessionId', async () => {
|
||||
const agent = new AcpAgent(makeConn())
|
||||
await expect(agent.extMethod('session/delete', {})).rejects.toThrow(
|
||||
'non-empty sessionId',
|
||||
)
|
||||
})
|
||||
|
||||
test('rejects unknown methods with methodNotFound-style error', async () => {
|
||||
const agent = new AcpAgent(makeConn())
|
||||
await expect(
|
||||
agent.extMethod('totally/unknown/method', {}),
|
||||
).rejects.toThrow()
|
||||
})
|
||||
|
||||
test('unstable_deleteSession is idempotent for missing session', async () => {
|
||||
const agent = new AcpAgent(makeConn())
|
||||
// No file exists for this ID; both calls must succeed (per spec §Semantics)
|
||||
const r1 = await agent.unstable_deleteSession({
|
||||
sessionId: 'definitely-missing-id-1',
|
||||
})
|
||||
const r2 = await agent.unstable_deleteSession({
|
||||
sessionId: 'definitely-missing-id-2',
|
||||
})
|
||||
expect(r1).toEqual({})
|
||||
expect(r2).toEqual({})
|
||||
})
|
||||
|
||||
test('unstable_deleteSession tears down active in-memory session', async () => {
|
||||
const agent = new AcpAgent(makeConn())
|
||||
const { sessionId } = await agent.newSession({ cwd: '/tmp' } as any)
|
||||
expect(agent.sessions.has(sessionId)).toBe(true)
|
||||
// deleteSession should remove the in-memory entry even though there's
|
||||
// no on-disk file (newSession doesn't persist immediately in tests).
|
||||
await agent.unstable_deleteSession({ sessionId })
|
||||
expect(agent.sessions.has(sessionId)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('setSessionModel', () => {
|
||||
test('updates model on queryEngine', async () => {
|
||||
const agent = new AcpAgent(makeConn())
|
||||
@@ -716,6 +774,50 @@ describe('AcpAgent', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('prompt userMessageId echo (message-id RFD)', () => {
|
||||
test('echoes client-supplied messageId as userMessageId', async () => {
|
||||
// Per rfds/message-id.mdx: when the client provides a `messageId` on
|
||||
// PromptRequest, the Agent echoes it back as `userMessageId`.
|
||||
const agent = new AcpAgent(makeConn())
|
||||
const { sessionId } = await agent.newSession({ cwd: '/tmp' } as any)
|
||||
;(forwardSessionUpdates as ReturnType<typeof mock>).mockResolvedValueOnce(
|
||||
{
|
||||
stopReason: 'end_turn',
|
||||
usage: {
|
||||
inputTokens: 10,
|
||||
outputTokens: 5,
|
||||
cachedReadTokens: 0,
|
||||
cachedWriteTokens: 0,
|
||||
},
|
||||
},
|
||||
)
|
||||
const clientMessageId = '11111111-2222-3333-4444-555555555555'
|
||||
const res = await agent.prompt({
|
||||
sessionId,
|
||||
prompt: [{ type: 'text', text: 'hello' }],
|
||||
messageId: clientMessageId,
|
||||
} as any)
|
||||
expect((res as any).userMessageId).toBe(clientMessageId)
|
||||
})
|
||||
|
||||
test('omits userMessageId when client does not supply messageId', async () => {
|
||||
// Per rfds/message-id.mdx: agent MAY self-generate; we take the
|
||||
// conservative approach of staying silent when the client didn't ask.
|
||||
const agent = new AcpAgent(makeConn())
|
||||
const { sessionId } = await agent.newSession({ cwd: '/tmp' } as any)
|
||||
;(forwardSessionUpdates as ReturnType<typeof mock>).mockResolvedValueOnce(
|
||||
{
|
||||
stopReason: 'end_turn',
|
||||
},
|
||||
)
|
||||
const res = await agent.prompt({
|
||||
sessionId,
|
||||
prompt: [{ type: 'text', text: 'hello' }],
|
||||
} as any)
|
||||
expect((res as any).userMessageId).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('prompt error handling', () => {
|
||||
test('returns cancelled when session was cancelled during prompt', async () => {
|
||||
const agent = new AcpAgent(makeConn())
|
||||
|
||||
Reference in New Issue
Block a user