- tsconfig.json 加 baseUrl 修复 dev 模式子进程 src/* 路径别名解析 - waitReady/initReject 修复:子进程退出时正确 reject,避免永久 pending - POST /session 等待子进程 ready 后再返回,避免立即发 prompt 崩溃 - transcriptReader pathCache 不缓存 null,文件未写入时下次可重新查找 - session/status 用 prompting 判断 busy/idle,prompt 结束后正确变为 idle - /agent 接口补充默认 build 模式 - message.ts 使用 spawnCwd 定位 transcript 文件 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import { Hono } from 'hono'
|
|
import { execSync } from 'child_process'
|
|
import { homedir } from 'os'
|
|
import { getClaudeConfigHomeDir } from '../../utils/envUtils.js'
|
|
import { getCommands } from '../../commands.js'
|
|
import { getCommandName } from '../../types/command.js'
|
|
import type { SessionManager } from '../sessionManager.js'
|
|
import { getBuiltInAgents } from '@claude-code-best/builtin-tools/tools/AgentTool/builtInAgents.js'
|
|
|
|
export function createInfoRoutes(sessionManager: SessionManager): Hono {
|
|
return new Hono()
|
|
.get('/path', c => {
|
|
return c.json({
|
|
home: homedir(),
|
|
state: getClaudeConfigHomeDir(),
|
|
config: getClaudeConfigHomeDir(),
|
|
directory: process.cwd(),
|
|
})
|
|
})
|
|
.get('/vcs', c => {
|
|
let branch = ''
|
|
try {
|
|
branch = execSync('git rev-parse --abbrev-ref HEAD', {
|
|
encoding: 'utf-8',
|
|
timeout: 5000,
|
|
}).trim()
|
|
} catch {}
|
|
return c.json({ branch })
|
|
})
|
|
.get('/command', async c => {
|
|
try {
|
|
const commands = await getCommands(process.cwd())
|
|
return c.json(
|
|
commands
|
|
.filter(cmd => !cmd.isHidden)
|
|
.map(cmd => ({
|
|
name: getCommandName(cmd),
|
|
description: cmd.description,
|
|
argumentHint: cmd.argumentHint,
|
|
})),
|
|
)
|
|
} catch {
|
|
return c.json([])
|
|
}
|
|
})
|
|
.get('/agent', c => {
|
|
const allAgents = getBuiltInAgents()
|
|
const defaultMode = {
|
|
name: 'build',
|
|
description: 'Default mode for software engineering tasks: writing code, editing files, running commands, and building projects.',
|
|
mode: 'primary' as const,
|
|
hidden: false,
|
|
options: {},
|
|
permission: [],
|
|
}
|
|
return c.json([
|
|
defaultMode,
|
|
...allAgents.map(a => ({
|
|
name: a.agentType,
|
|
description: a.whenToUse,
|
|
mode: a.isMainThread ? ('primary' as const) : ('subagent' as const),
|
|
hidden: false,
|
|
options: {},
|
|
permission: [],
|
|
})),
|
|
])
|
|
})
|
|
.get('/mcp', async c => {
|
|
for (const handle of sessionManager.getAllSessions()) {
|
|
if (handle.status === 'running') {
|
|
try {
|
|
const servers = await handle.getMcpStatus()
|
|
return c.json({ servers })
|
|
} catch {
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
return c.json({ servers: [] })
|
|
})
|
|
}
|