mirror of
https://github.com/iflytek/skillhub.git
synced 2026-08-28 11:25:00 +00:00
fix(cli): treat highlighted install target as selected
Signed-off-by: SenLinLeo <1664761477@qq.com>
This commit is contained in:
parent
7e23508a32
commit
b44c65443d
2 changed files with 44 additions and 1 deletions
|
|
@ -160,6 +160,7 @@ function dedupeByRoot(candidates: AgentCandidate[]): AgentCandidate[] {
|
|||
|
||||
async function selectTargetsInteractively(candidates: AgentCandidate[]): Promise<AgentCandidate[]> {
|
||||
const prompts = await import('prompts')
|
||||
let highlightedIndex = 0
|
||||
const { selected } = await prompts.default({
|
||||
type: 'multiselect',
|
||||
name: 'selected',
|
||||
|
|
@ -167,7 +168,13 @@ async function selectTargetsInteractively(candidates: AgentCandidate[]): Promise
|
|||
choices: candidates.map(c => ({
|
||||
title: `${c.agent} (${c.rootDir})`,
|
||||
value: c
|
||||
}))
|
||||
})),
|
||||
onRender: function (this: { cursor?: number }) {
|
||||
highlightedIndex = this.cursor ?? highlightedIndex
|
||||
},
|
||||
format: (selectedTargets: AgentCandidate[]) => (
|
||||
selectedTargets.length > 0 ? selectedTargets : [candidates[highlightedIndex] ?? candidates[0]!]
|
||||
)
|
||||
})
|
||||
if (!selected || selected.length === 0) {
|
||||
throw new CliError('installation cancelled', EXIT.usage)
|
||||
|
|
|
|||
36
cli/test/unit/agents/resolver-interactive.test.ts
Normal file
36
cli/test/unit/agents/resolver-interactive.test.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { describe, expect, mock, test } from 'bun:test'
|
||||
import type { AgentCandidate } from '../../../src/agents/types'
|
||||
|
||||
interface PromptOptions {
|
||||
onRender?: (this: { cursor?: number }) => void
|
||||
format?: (selectedTargets: AgentCandidate[]) => AgentCandidate[]
|
||||
}
|
||||
|
||||
mock.module('prompts', () => ({
|
||||
default: (options: PromptOptions) => {
|
||||
options.onRender?.call({ cursor: 1 })
|
||||
return { selected: options.format?.([]) ?? [] }
|
||||
}
|
||||
}))
|
||||
|
||||
const { resolveInstallTargets } = await import('../../../src/agents/resolver')
|
||||
|
||||
describe('resolveInstallTargets interactive prompt', () => {
|
||||
test('uses the highlighted target when Enter submits an empty multiselect', async () => {
|
||||
const detected: AgentCandidate[] = [
|
||||
{ agent: 'codex', rootDir: '/repo/.codex/skills', scope: 'project', source: 'detected' },
|
||||
{ agent: 'claude-code', rootDir: '/repo/.claude/skills', scope: 'project', source: 'detected' }
|
||||
]
|
||||
const highlighted = detected[1]!
|
||||
|
||||
const targets = await resolveInstallTargets({
|
||||
cwd: '/repo',
|
||||
agents: [],
|
||||
json: false,
|
||||
interactive: true,
|
||||
detected
|
||||
})
|
||||
|
||||
expect(targets).toEqual([highlighted])
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Reference in a new issue