mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 14:25:51 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b205f5798 | ||
|
|
7e3d825f0e | ||
|
|
a077ec8d85 | ||
|
|
55a932df68 | ||
|
|
230eb489b5 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "claude-code-best",
|
"name": "claude-code-best",
|
||||||
"version": "2.6.9",
|
"version": "2.6.11",
|
||||||
"description": "Reverse-engineered Anthropic Claude Code CLI — interactive AI coding assistant in the terminal",
|
"description": "Reverse-engineered Anthropic Claude Code CLI — interactive AI coding assistant in the terminal",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "claude-code-best <claude-code-best@proton.me>",
|
"author": "claude-code-best <claude-code-best@proton.me>",
|
||||||
|
|||||||
@@ -1226,19 +1226,20 @@ describe('AcpAgent', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('prompt does not trigger additional switchSession for multi-session', async () => {
|
test('prompt switches global sessionId to the correct session', async () => {
|
||||||
const agent = new AcpAgent(makeConn())
|
const agent = new AcpAgent(makeConn())
|
||||||
await agent.newSession({ cwd: '/tmp' } as any)
|
await agent.newSession({ cwd: '/tmp' } as any)
|
||||||
await agent.newSession({ cwd: '/tmp' } as any)
|
await agent.newSession({ cwd: '/tmp' } as any)
|
||||||
mockSwitchSession.mockClear()
|
mockSwitchSession.mockClear()
|
||||||
|
|
||||||
// Prompts should not call switchSession — alignment happens at session creation
|
// Prompts must switch global state so recordTranscript writes to
|
||||||
|
// the correct session file in multi-session scenarios.
|
||||||
const s1 = agent.sessions.keys().next().value
|
const s1 = agent.sessions.keys().next().value
|
||||||
await agent.prompt({
|
await agent.prompt({
|
||||||
sessionId: s1,
|
sessionId: s1,
|
||||||
prompt: [{ type: 'text', text: 'hello' }],
|
prompt: [{ type: 'text', text: 'hello' }],
|
||||||
} as any)
|
} as any)
|
||||||
expect(mockSwitchSession).not.toHaveBeenCalled()
|
expect(mockSwitchSession).toHaveBeenCalledWith(s1, null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import { getEmptyToolPermissionContext } from '../../Tool.js'
|
|||||||
import type { PermissionMode } from '../../types/permissions.js'
|
import type { PermissionMode } from '../../types/permissions.js'
|
||||||
import type { Command } from '../../types/command.js'
|
import type { Command } from '../../types/command.js'
|
||||||
import { getCommands } from '../../commands.js'
|
import { getCommands } from '../../commands.js'
|
||||||
|
import { getAgentDefinitionsWithOverrides } from '@claude-code-best/builtin-tools/tools/AgentTool/loadAgentsDir.js'
|
||||||
import {
|
import {
|
||||||
setOriginalCwd,
|
setOriginalCwd,
|
||||||
switchSession,
|
switchSession,
|
||||||
@@ -299,6 +300,10 @@ export class AcpAgent implements Agent {
|
|||||||
// After a previous interrupt(), the internal controller is stuck in
|
// After a previous interrupt(), the internal controller is stuck in
|
||||||
// aborted state — without this, submitMessage() fails immediately.
|
// aborted state — without this, submitMessage() fails immediately.
|
||||||
session.queryEngine.resetAbortController()
|
session.queryEngine.resetAbortController()
|
||||||
|
// Switch global session state so recordTranscript writes to the correct
|
||||||
|
// session file. Without this, multi-session scenarios (or creating a new
|
||||||
|
// session after another) write transcript data to the wrong file.
|
||||||
|
switchSession(params.sessionId as SessionId, getSessionProjectDir())
|
||||||
|
|
||||||
const sdkMessages = session.queryEngine.submitMessage(promptInput)
|
const sdkMessages = session.queryEngine.submitMessage(promptInput)
|
||||||
|
|
||||||
@@ -549,8 +554,14 @@ export class AcpAgent implements Agent {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load commands for slash command and skill support
|
// Load commands and agent definitions for subagent support
|
||||||
const commands = await getCommands(cwd)
|
const [commands, agentDefinitionsResult] = await Promise.all([
|
||||||
|
getCommands(cwd),
|
||||||
|
getAgentDefinitionsWithOverrides(cwd),
|
||||||
|
])
|
||||||
|
|
||||||
|
// Inject agent definitions into appState
|
||||||
|
appState.agentDefinitions = agentDefinitionsResult
|
||||||
|
|
||||||
// Build QueryEngine config
|
// Build QueryEngine config
|
||||||
const engineConfig: QueryEngineConfig = {
|
const engineConfig: QueryEngineConfig = {
|
||||||
@@ -558,7 +569,7 @@ export class AcpAgent implements Agent {
|
|||||||
tools,
|
tools,
|
||||||
commands,
|
commands,
|
||||||
mcpClients: [],
|
mcpClients: [],
|
||||||
agents: [],
|
agents: agentDefinitionsResult.activeAgents,
|
||||||
canUseTool,
|
canUseTool,
|
||||||
getAppState: () => appState,
|
getAppState: () => appState,
|
||||||
setAppState: (updater: (prev: AppState) => AppState) => {
|
setAppState: (updater: (prev: AppState) => AppState) => {
|
||||||
|
|||||||
@@ -633,6 +633,7 @@ export async function forwardSessionUpdates(
|
|||||||
let lastAssistantTotalUsage: number | null = null
|
let lastAssistantTotalUsage: number | null = null
|
||||||
let lastAssistantModel: string | null = null
|
let lastAssistantModel: string | null = null
|
||||||
let lastContextWindowSize = 200000
|
let lastContextWindowSize = 200000
|
||||||
|
let streamingActive = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (!abortSignal.aborted) {
|
while (!abortSignal.aborted) {
|
||||||
@@ -788,6 +789,7 @@ export async function forwardSessionUpdates(
|
|||||||
for (const notification of notifications) {
|
for (const notification of notifications) {
|
||||||
await conn.sessionUpdate(notification)
|
await conn.sessionUpdate(notification)
|
||||||
}
|
}
|
||||||
|
streamingActive = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -827,6 +829,8 @@ export async function forwardSessionUpdates(
|
|||||||
{
|
{
|
||||||
clientCapabilities,
|
clientCapabilities,
|
||||||
cwd,
|
cwd,
|
||||||
|
parentToolUseId,
|
||||||
|
streamingActive,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
for (const notification of notifications) {
|
for (const notification of notifications) {
|
||||||
@@ -942,6 +946,7 @@ function assistantMessageToAcpNotifications(
|
|||||||
clientCapabilities?: ClientCapabilities
|
clientCapabilities?: ClientCapabilities
|
||||||
parentToolUseId?: string | null
|
parentToolUseId?: string | null
|
||||||
cwd?: string
|
cwd?: string
|
||||||
|
streamingActive?: boolean
|
||||||
},
|
},
|
||||||
): SessionNotification[] {
|
): SessionNotification[] {
|
||||||
const message = msg.message as Record<string, unknown> | undefined
|
const message = msg.message as Record<string, unknown> | undefined
|
||||||
@@ -966,8 +971,20 @@ function assistantMessageToAcpNotifications(
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When streaming is active, text/thinking were already sent via stream_event
|
||||||
|
// messages. Filter them out to avoid duplicate agent_message_chunk /
|
||||||
|
// agent_thought_chunk notifications. String content (synthetic messages)
|
||||||
|
// is unaffected — those have no corresponding stream_events.
|
||||||
|
const contentToProcess = options?.streamingActive
|
||||||
|
? content.filter(
|
||||||
|
block => block.type !== 'text' && block.type !== 'thinking',
|
||||||
|
)
|
||||||
|
: content
|
||||||
|
|
||||||
|
if (contentToProcess.length === 0) return []
|
||||||
|
|
||||||
return toAcpNotifications(
|
return toAcpNotifications(
|
||||||
content,
|
contentToProcess,
|
||||||
'assistant',
|
'assistant',
|
||||||
sessionId,
|
sessionId,
|
||||||
toolUseCache,
|
toolUseCache,
|
||||||
@@ -987,6 +1004,7 @@ function streamEventToAcpNotifications(
|
|||||||
options?: {
|
options?: {
|
||||||
clientCapabilities?: ClientCapabilities
|
clientCapabilities?: ClientCapabilities
|
||||||
cwd?: string
|
cwd?: string
|
||||||
|
streamingActive?: boolean
|
||||||
},
|
},
|
||||||
): SessionNotification[] {
|
): SessionNotification[] {
|
||||||
const event = (msg as unknown as { event: Record<string, unknown> }).event
|
const event = (msg as unknown as { event: Record<string, unknown> }).event
|
||||||
@@ -1055,6 +1073,7 @@ function toAcpNotifications(
|
|||||||
clientCapabilities?: ClientCapabilities
|
clientCapabilities?: ClientCapabilities
|
||||||
parentToolUseId?: string | null
|
parentToolUseId?: string | null
|
||||||
cwd?: string
|
cwd?: string
|
||||||
|
streamingActive?: boolean
|
||||||
},
|
},
|
||||||
): SessionNotification[] {
|
): SessionNotification[] {
|
||||||
const output: SessionNotification[] = []
|
const output: SessionNotification[] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user