@miphamai/cli 0.85.42 → 0.85.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/agent/agent-context.ts +49 -0
- package/src/agent/agent-registry.ts +6 -0
- package/src/agent/sub-agent.ts +5 -0
- package/src/commands/project.ts +3 -1
- package/src/config/loader.ts +38 -1
- package/src/core/engine.ts +155 -16
- package/src/core/hooks-executor.ts +40 -6
- package/src/core/hooks.ts +8 -0
- package/src/core/permission-rules.ts +168 -29
- package/src/core/permission.ts +20 -0
- package/src/core/session-log.ts +39 -1
- package/src/core/session-store.ts +33 -1
- package/src/core/tool-gate.ts +7 -1
- package/src/daemon/engine-capabilities.ts +9 -1
- package/src/i18n-core/locales/en-US.json +10 -2
- package/src/i18n-core/locales/zh-CN.json +10 -2
- package/src/index.tsx +31 -6
- package/src/mcp/client.ts +27 -0
- package/src/mcp/registry.ts +18 -4
- package/src/mcp/transport.ts +15 -0
- package/src/mcp/types.ts +6 -0
- package/src/providers/anthropic.ts +14 -1
- package/src/providers/bootstrap.ts +13 -0
- package/src/providers/openai-compat.ts +6 -1
- package/src/shared/package-info.ts +3 -3
- package/src/shared/types.ts +18 -0
- package/src/skills/loader.ts +30 -0
- package/src/tools/exec/bash.ts +204 -25
- package/src/tools/file/glob.ts +58 -6
- package/src/tools/file/grep.ts +9 -1
- package/src/tools/system/tool-search.ts +2 -1
- package/src/ui/app.tsx +41 -21
- package/src/ui/command-picker.tsx +2 -5
- package/src/ui/commands.ts +143 -9
- package/src/ui/input.tsx +35 -10
- package/src/ui/picker.tsx +1 -1
package/src/ui/app.tsx
CHANGED
|
@@ -108,6 +108,40 @@ export interface ChatMessage {
|
|
|
108
108
|
toolMeta?: ToolMeta
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Compose the transcript line for a background-task notification.
|
|
113
|
+
*
|
|
114
|
+
* `chat.tsx` renders `toolMeta.output` *before* `msg.content`, so a completed
|
|
115
|
+
* task that carried the raw output preview made its own composed line
|
|
116
|
+
* (`◼ <desc> · finished`) unreachable — the user saw a truncated raw-output row
|
|
117
|
+
* and no completion statement. Running/failed tasks keep the preview (that is
|
|
118
|
+
* the live signal); a completed one reports cleanly.
|
|
119
|
+
*/
|
|
120
|
+
export function taskNotificationMessage(tn: {
|
|
121
|
+
status: 'started' | 'completed' | 'failed'
|
|
122
|
+
description: string
|
|
123
|
+
content?: string
|
|
124
|
+
error?: string
|
|
125
|
+
}): ChatMessage {
|
|
126
|
+
const isDone = tn.status === 'completed'
|
|
127
|
+
const symbol = isDone ? '◼' : '✳'
|
|
128
|
+
const preview = tn.content
|
|
129
|
+
? tn.content.slice(0, 120) + (tn.content.length > 120 ? '...' : '')
|
|
130
|
+
: tn.error
|
|
131
|
+
? `Error: ${tn.error.slice(0, 120)}`
|
|
132
|
+
: '(no output)'
|
|
133
|
+
return {
|
|
134
|
+
role: 'system',
|
|
135
|
+
content: `${symbol} ${tn.description}${isDone ? ` · finished` : ''}`,
|
|
136
|
+
toolMeta: {
|
|
137
|
+
name: isDone ? '' : 'task',
|
|
138
|
+
input: tn.description || '',
|
|
139
|
+
...(isDone ? {} : { output: preview }),
|
|
140
|
+
collapsed: false,
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
111
145
|
interface AgentProgress {
|
|
112
146
|
name: string
|
|
113
147
|
description: string
|
|
@@ -350,6 +384,9 @@ export function App({
|
|
|
350
384
|
// 卸载(pickerOpen 三元 / apiKeyPrompt 早退 / Ctrl+G),组件内 state 随之清零,
|
|
351
385
|
// 于是「开一次模型选择器,历史就没了」(ROADMAP D7)。
|
|
352
386
|
const [inputHistory, setInputHistory] = useState<string[]>([])
|
|
387
|
+
// The draft lives here for the same reason history does (see the note above):
|
|
388
|
+
// InputBar is unmounted by the picker / API-key prompt / agent view.
|
|
389
|
+
const [inputDraft, setInputDraft] = useState('')
|
|
353
390
|
const [updateStatus, setUpdateStatus] = useState<UpdateStatus | null>(null)
|
|
354
391
|
// Current git branch — read once at mount (not a git repo → null).
|
|
355
392
|
// `stdio` 显式给:默认下 git 的 stderr 是继承的,「不是仓库」这个正常路径会把
|
|
@@ -973,27 +1010,8 @@ export function App({
|
|
|
973
1010
|
}
|
|
974
1011
|
|
|
975
1012
|
if (chunk.type === 'task_notification' && chunk.taskNotification) {
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
const symbol = isDone ? '◼' : '✳'
|
|
979
|
-
const preview = tn.content
|
|
980
|
-
? tn.content.slice(0, 120) + (tn.content.length > 120 ? '...' : '')
|
|
981
|
-
: tn.error
|
|
982
|
-
? `Error: ${tn.error.slice(0, 120)}`
|
|
983
|
-
: '(no output)'
|
|
984
|
-
setMessages((prev) => [
|
|
985
|
-
...prev,
|
|
986
|
-
{
|
|
987
|
-
role: 'system',
|
|
988
|
-
content: `${symbol} ${tn.description}${isDone ? ` · finished` : ''}`,
|
|
989
|
-
toolMeta: {
|
|
990
|
-
name: isDone ? '' : 'task',
|
|
991
|
-
input: tn.description || '',
|
|
992
|
-
output: preview,
|
|
993
|
-
collapsed: isDone,
|
|
994
|
-
},
|
|
995
|
-
},
|
|
996
|
-
])
|
|
1013
|
+
const notification = chunk.taskNotification
|
|
1014
|
+
setMessages((prev) => [...prev, taskNotificationMessage(notification)])
|
|
997
1015
|
// Sync agent footer — mark completed background agents
|
|
998
1016
|
syncBgAgents()
|
|
999
1017
|
}
|
|
@@ -1599,6 +1617,8 @@ export function App({
|
|
|
1599
1617
|
isLoading={isLoading}
|
|
1600
1618
|
history={inputHistory}
|
|
1601
1619
|
onHistoryAppend={(v) => setInputHistory((prev) => [...prev, v])}
|
|
1620
|
+
draft={inputDraft}
|
|
1621
|
+
onDraftChange={setInputDraft}
|
|
1602
1622
|
llm={autocompleteLlm}
|
|
1603
1623
|
recentMessages={recentMessages}
|
|
1604
1624
|
autocompleteEnabled={
|
|
@@ -2,7 +2,7 @@ import React, { useState, useMemo, useEffect } from 'react'
|
|
|
2
2
|
import { Box, Text, useInput } from 'ink'
|
|
3
3
|
import TextInput from 'ink-text-input'
|
|
4
4
|
import { useI18n } from '../i18n-context'
|
|
5
|
-
import { getCommandList } from './commands.js'
|
|
5
|
+
import { getCommandList, rankCommandMatches } from './commands.js'
|
|
6
6
|
import { commandToken, hasInlineArgs } from './command-token.js'
|
|
7
7
|
import { useKeyState } from './use-key-state'
|
|
8
8
|
|
|
@@ -68,10 +68,7 @@ export function CommandPicker({
|
|
|
68
68
|
// full line — so "/loop 60s echo hello" still matches "/loop").
|
|
69
69
|
const filtered = useMemo(() => {
|
|
70
70
|
const q = commandToken(filter)
|
|
71
|
-
|
|
72
|
-
return allCommands.filter(
|
|
73
|
-
(cmd) => cmd.name.toLowerCase().includes(q) || cmd.description.toLowerCase().includes(q),
|
|
74
|
-
)
|
|
71
|
+
return rankCommandMatches(allCommands, q)
|
|
75
72
|
}, [filter, allCommands])
|
|
76
73
|
|
|
77
74
|
// Reset cursor when filter changes
|
package/src/ui/commands.ts
CHANGED
|
@@ -604,9 +604,60 @@ const costCmd: CommandHandler = (ctx) => {
|
|
|
604
604
|
// Model & Provider
|
|
605
605
|
// ═══════════════════════════════════════════════════════════════
|
|
606
606
|
|
|
607
|
-
const modelCmd: CommandHandler = (ctx) => {
|
|
607
|
+
const modelCmd: CommandHandler = (ctx, args) => {
|
|
608
608
|
const t = resolveT(ctx)
|
|
609
|
-
|
|
609
|
+
const requested = args[0]?.trim()
|
|
610
|
+
// `/model <name>` used to drop its argument on the floor and print the
|
|
611
|
+
// current model — a request that was refused and a request that was never
|
|
612
|
+
// made looked the same. Validate first, then switch.
|
|
613
|
+
if (!requested) {
|
|
614
|
+
return {
|
|
615
|
+
content: t('commands.model.current', { model: ctx.modelId, provider: ctx.providerId }),
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (ctx.engine.isRemote) {
|
|
619
|
+
return {
|
|
620
|
+
content:
|
|
621
|
+
`Cannot switch to ${requested}: this session is attached to a daemon, ` +
|
|
622
|
+
'and the model is chosen on the daemon side. Change it there, or start a local session.',
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
const matches = ctx.config.providers
|
|
626
|
+
.filter((p) => p.status !== 'upcoming')
|
|
627
|
+
.flatMap((p) =>
|
|
628
|
+
p.models.filter((m) => m.status === 'active').map((m) => ({ provider: p, model: m })),
|
|
629
|
+
)
|
|
630
|
+
.filter(({ model }) => model.id.toLowerCase() === requested.toLowerCase())
|
|
631
|
+
if (matches.length === 0) {
|
|
632
|
+
return { content: t('commands.model.unknown', { model: requested }) }
|
|
633
|
+
}
|
|
634
|
+
if (matches.length > 1) {
|
|
635
|
+
return {
|
|
636
|
+
content: t('commands.model.ambiguous', {
|
|
637
|
+
model: requested,
|
|
638
|
+
providers: matches.map(({ provider }) => provider.id).join(', '),
|
|
639
|
+
}),
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
const { provider, model } = matches[0]!
|
|
643
|
+
if (isApiKeyMissing(provider.apiKey)) {
|
|
644
|
+
return {
|
|
645
|
+
content: t('commands.switch.needs_api_key', { provider: provider.name }),
|
|
646
|
+
needsApiKey: {
|
|
647
|
+
providerId: provider.id,
|
|
648
|
+
modelId: model.id,
|
|
649
|
+
providerName: provider.name,
|
|
650
|
+
},
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const warning = ctx.engine.switchProvider(provider.id, model.id)
|
|
654
|
+
return {
|
|
655
|
+
content:
|
|
656
|
+
t('commands.switch.confirmed', { provider: provider.id, model: model.id }) +
|
|
657
|
+
(warning ? `\n${warning}` : ''),
|
|
658
|
+
nextProvider: provider.id,
|
|
659
|
+
nextModel: model.id,
|
|
660
|
+
}
|
|
610
661
|
}
|
|
611
662
|
|
|
612
663
|
const modelsCmd: CommandHandler = (ctx) => {
|
|
@@ -2830,11 +2881,30 @@ const changelogCmd: CommandHandler = async (ctx) => {
|
|
|
2830
2881
|
// Workflow
|
|
2831
2882
|
// ═══════════════════════════════════════════════════════════════
|
|
2832
2883
|
|
|
2833
|
-
const planCmd: CommandHandler = (
|
|
2834
|
-
const t = resolveT(
|
|
2884
|
+
const planCmd: CommandHandler = (ctx, args) => {
|
|
2885
|
+
const t = resolveT(ctx)
|
|
2835
2886
|
const description = args.join(' ') || undefined
|
|
2887
|
+
|
|
2888
|
+
// The shortcut's job is to put the session in plan mode **now**. It used to
|
|
2889
|
+
// only forward a prompt asking the model to call EnterPlanMode, so the mode
|
|
2890
|
+
// changed only if the model cooperated — a shortcut with no landing point.
|
|
2891
|
+
// Read the mode back: the organisation's ceiling can clamp the request.
|
|
2892
|
+
let modeNote = ''
|
|
2893
|
+
if (liveMode(ctx) !== 'plan') {
|
|
2894
|
+
if (!ctx.setPermissionMode) {
|
|
2895
|
+
modeNote = 'This surface cannot switch permission modes — use Shift+Tab.\n\n'
|
|
2896
|
+
} else {
|
|
2897
|
+
ctx.setPermissionMode('plan')
|
|
2898
|
+
const now = liveMode(ctx)
|
|
2899
|
+
modeNote =
|
|
2900
|
+
now === 'plan'
|
|
2901
|
+
? '✓ Plan mode on — edits stay refused until you /approve or /no-plan.\n\n'
|
|
2902
|
+
: `Plan mode was requested, but the organisation's permission limit kept the mode at ${now}.\n\n`
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2836
2906
|
return {
|
|
2837
|
-
content: t('commands.plan.content'),
|
|
2907
|
+
content: modeNote + t('commands.plan.content'),
|
|
2838
2908
|
forwardToAI: description
|
|
2839
2909
|
? `Use EnterPlanMode with description: "${description}". Then explore, design, and use ExitPlanMode when ready for approval.`
|
|
2840
2910
|
: 'Use EnterPlanMode to enter plan mode. Explore the codebase, design an approach, then use ExitPlanMode to submit for approval.',
|
|
@@ -2914,7 +2984,7 @@ const todosCmd: CommandHandler = (_ctx, args) => {
|
|
|
2914
2984
|
// Phase 1 — New Session Commands
|
|
2915
2985
|
// ═══════════════════════════════════════════════════════════════
|
|
2916
2986
|
|
|
2917
|
-
const renameCmd: CommandHandler = (ctx, args) => {
|
|
2987
|
+
const renameCmd: CommandHandler = async (ctx, args) => {
|
|
2918
2988
|
const t = resolveT(ctx)
|
|
2919
2989
|
const name = args.join(' ')
|
|
2920
2990
|
if (!name.trim()) {
|
|
@@ -2931,6 +3001,24 @@ const renameCmd: CommandHandler = (ctx, args) => {
|
|
|
2931
3001
|
if (finalName === null) {
|
|
2932
3002
|
return { content: t('commands.rename.unsaved', { name: name.trim() }) }
|
|
2933
3003
|
}
|
|
3004
|
+
// The saved transcript has its own name — `<name>.jsonl` — and `/resume`
|
|
3005
|
+
// resolves *that* namespace. Renaming only the registry/title left the two
|
|
3006
|
+
// namespaces split: `/rename Bug Fix` succeeded, yet `/resume Bug Fix`
|
|
3007
|
+
// found nothing while `/resume <old>` still did (v2.0.64-004).
|
|
3008
|
+
const log = ctx.engine.getContext().getLog?.()
|
|
3009
|
+
if (log) {
|
|
3010
|
+
const oldName = log.getName()
|
|
3011
|
+
const status = log.rename(finalName)
|
|
3012
|
+
if (status === 'renamed') {
|
|
3013
|
+
const { SessionStore } = await import('../core/session-store')
|
|
3014
|
+
SessionStore.renameEntry(oldName, finalName)
|
|
3015
|
+
} else if (status === 'conflict') {
|
|
3016
|
+
// The title/registry name changed, but the transcript already belongs to
|
|
3017
|
+
// another saved session under that name. Say so instead of claiming a
|
|
3018
|
+
// rename the user cannot resume.
|
|
3019
|
+
return { content: t('commands.rename.log_conflict', { name: finalName, old: oldName }) }
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
2934
3022
|
return { content: t('commands.rename.confirmed', { name: finalName }) }
|
|
2935
3023
|
}
|
|
2936
3024
|
|
|
@@ -3138,6 +3226,9 @@ const reloadSkillsCmd: CommandHandler = (ctx) => {
|
|
|
3138
3226
|
try {
|
|
3139
3227
|
const config = ctx.config
|
|
3140
3228
|
ctx.skillsLoader.loadBuiltin(process.cwd())
|
|
3229
|
+
// The project scope is not covered by `loadBuiltin` (that reads
|
|
3230
|
+
// `<cwd>/skills/{standard,mipham}` — the repo's own dev layout).
|
|
3231
|
+
ctx.skillsLoader.loadProjectSkills(process.cwd())
|
|
3141
3232
|
if (config.skills?.paths) {
|
|
3142
3233
|
ctx.skillsLoader.loadExternal(config.skills.paths)
|
|
3143
3234
|
}
|
|
@@ -4847,8 +4938,15 @@ const hooksListCmd: CommandHandler = async (ctx) => {
|
|
|
4847
4938
|
// Two calls, one per source: the merged list cannot say which entry came from
|
|
4848
4939
|
// which file, and the two are not governed alike — only the project file's
|
|
4849
4940
|
// entries are gated on workspace trust.
|
|
4850
|
-
const
|
|
4851
|
-
const
|
|
4941
|
+
const userSettings = loadSettingsJson(cwd)
|
|
4942
|
+
const projectSettings = loadSettingsJson(cwd, { includeProjectHooks: true })
|
|
4943
|
+
const userHooks = userSettings.hooks
|
|
4944
|
+
const projectHooks = projectSettings.projectHooks ?? {}
|
|
4945
|
+
// Listing a hook is not the claim that it runs. `disableAllHooks` stops the
|
|
4946
|
+
// wiring at both entry points, and this display reads the files, so it has to
|
|
4947
|
+
// carry the same verdict — otherwise every entry looks installed and
|
|
4948
|
+
// `found N` counts hooks that will never fire.
|
|
4949
|
+
const hooksDisabled = projectSettings.disableAllHooks === true
|
|
4852
4950
|
|
|
4853
4951
|
// Listing them is not the same claim as their running. Project hooks are
|
|
4854
4952
|
// gated, and this command renders them even when the gate is shut — so the
|
|
@@ -4895,13 +4993,14 @@ const hooksListCmd: CommandHandler = async (ctx) => {
|
|
|
4895
4993
|
const undispatchable = UNDISPATCHED_EVENTS.has(eventName)
|
|
4896
4994
|
for (const { entry, project } of bucket) {
|
|
4897
4995
|
for (const hook of entry.hooks) {
|
|
4898
|
-
if (!undispatchable) count++
|
|
4996
|
+
if (!undispatchable && !hooksDisabled) count++
|
|
4899
4997
|
const matcher = entry.matcher || '*'
|
|
4900
4998
|
const cmd = hook.type === 'command' && hook.command ? hook.command : hook.type
|
|
4901
4999
|
const source = t(project ? 'commands.hooks.source_project' : 'commands.hooks.source_user')
|
|
4902
5000
|
const markers: string[] = []
|
|
4903
5001
|
if (project && gated) markers.push(t('commands.hooks.gated'))
|
|
4904
5002
|
if (undispatchable) markers.push(t('commands.hooks.undispatched'))
|
|
5003
|
+
if (hooksDisabled) markers.push(t('commands.hooks.disabled_all'))
|
|
4905
5004
|
const suffix = markers.map((marker) => ` ${marker}`).join('')
|
|
4906
5005
|
lines.push(` [${source}] ${eventName} [${matcher}] → ${cmd}${suffix}`)
|
|
4907
5006
|
}
|
|
@@ -6813,6 +6912,7 @@ const commandsListCmd: CommandHandler = () => {
|
|
|
6813
6912
|
'/providers': 'Model & Provider',
|
|
6814
6913
|
'/switch': 'Model & Provider',
|
|
6815
6914
|
'/config': 'Model & Provider',
|
|
6915
|
+
'/settings': 'Model & Provider',
|
|
6816
6916
|
'/effort': 'Model & Provider',
|
|
6817
6917
|
'/upgrade': 'Model & Provider',
|
|
6818
6918
|
'/tools': 'Tools & Skills',
|
|
@@ -7023,6 +7123,7 @@ registry.set('/ollama-refresh', ollamaRefreshCmd)
|
|
|
7023
7123
|
registry.set('/provider', providerCmd)
|
|
7024
7124
|
registry.set('/providers', providersCmd)
|
|
7025
7125
|
registry.set('/config', configCmd)
|
|
7126
|
+
registry.set('/settings', configCmd) // CC-compatible alias
|
|
7026
7127
|
registry.set('/effort', effortCmd)
|
|
7027
7128
|
registry.set('/switch', switchCmd)
|
|
7028
7129
|
|
|
@@ -7269,6 +7370,7 @@ const COMMAND_DESCRIPTIONS: Record<string, string> = {
|
|
|
7269
7370
|
'/providers': 'List configured providers',
|
|
7270
7371
|
'/switch': 'Switch provider and model',
|
|
7271
7372
|
'/config': 'View configuration',
|
|
7373
|
+
'/settings': 'View configuration (alias of /config)',
|
|
7272
7374
|
'/effort': 'Set the stream stall budget (does not change reasoning depth)',
|
|
7273
7375
|
'/lang': 'Set display language (en-US, zh-CN)',
|
|
7274
7376
|
'/tools': 'List available tools',
|
|
@@ -7377,6 +7479,38 @@ export function getCommandList(): CommandEntry[] {
|
|
|
7377
7479
|
}))
|
|
7378
7480
|
}
|
|
7379
7481
|
|
|
7482
|
+
/**
|
|
7483
|
+
* Match and **rank** slash commands for a query.
|
|
7484
|
+
*
|
|
7485
|
+
* Both slash surfaces used to filter with `includes()` and take the first
|
|
7486
|
+
* entry of an alphabetically sorted list, so a description match could outrank
|
|
7487
|
+
* the command the user was typing: `/memory` (description match on `/dream`'s
|
|
7488
|
+
* "Background memory consolidation") selected `/dream`, and Enter ran it.
|
|
7489
|
+
*
|
|
7490
|
+
* Order: exact name > name prefix > name substring > description-only. Within
|
|
7491
|
+
* a rank the alphabetical order is kept, so the result stays predictable.
|
|
7492
|
+
* Description matches are still included (a user looking for "fork" should see
|
|
7493
|
+
* a command *described* as forking); they simply no longer outrank names.
|
|
7494
|
+
*/
|
|
7495
|
+
export function rankCommandMatches<T extends CommandEntry>(commands: T[], query: string): T[] {
|
|
7496
|
+
const q = query.trim().toLowerCase()
|
|
7497
|
+
if (!q) return commands
|
|
7498
|
+
const scored: Array<{ cmd: T; rank: number }> = []
|
|
7499
|
+
for (const cmd of commands) {
|
|
7500
|
+
const name = cmd.name.toLowerCase()
|
|
7501
|
+
const bare = name.startsWith('/') ? name.slice(1) : name
|
|
7502
|
+
let rank: number
|
|
7503
|
+
if (bare === q) rank = 0
|
|
7504
|
+
else if (bare.startsWith(q)) rank = 1
|
|
7505
|
+
else if (bare.includes(q)) rank = 2
|
|
7506
|
+
else if (cmd.description.toLowerCase().includes(q)) rank = 3
|
|
7507
|
+
else continue
|
|
7508
|
+
scored.push({ cmd, rank })
|
|
7509
|
+
}
|
|
7510
|
+
scored.sort((a, b) => a.rank - b.rank || a.cmd.name.localeCompare(b.cmd.name))
|
|
7511
|
+
return scored.map((s) => s.cmd)
|
|
7512
|
+
}
|
|
7513
|
+
|
|
7380
7514
|
export function looksLikeSlashCommand(input: string): boolean {
|
|
7381
7515
|
return input.trim().startsWith('/')
|
|
7382
7516
|
}
|
package/src/ui/input.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState, useEffect, useRef, useMemo } from 'react'
|
|
2
2
|
import { Box, Text, useInput } from 'ink'
|
|
3
|
-
import { getCommandList } from './commands.js'
|
|
3
|
+
import { getCommandList, rankCommandMatches } from './commands.js'
|
|
4
4
|
import { CommandPicker } from './command-picker.js'
|
|
5
5
|
import { useI18n } from '../i18n-context'
|
|
6
6
|
import { discoverSessions } from '../agent/cross-session/discovery'
|
|
@@ -41,6 +41,14 @@ interface InputBarProps {
|
|
|
41
41
|
autocompleteEnabled?: boolean
|
|
42
42
|
/** 默认 400ms;app.tsx 传 config.autocomplete?.debounceMs ?? 400。 */
|
|
43
43
|
autocompleteDebounceMs?: number
|
|
44
|
+
/**
|
|
45
|
+
* 草稿文本(由调用方持有)。本组件会被调用方卸载(模型选择器 / API-key 提示 /
|
|
46
|
+
* Ctrl+G 面板),草稿若只活在这里会随卸载消失;调用方持有后,重新挂载时从
|
|
47
|
+
* 这里取回。
|
|
48
|
+
*/
|
|
49
|
+
draft?: string
|
|
50
|
+
/** 每次草稿变化同步给调用方。 */
|
|
51
|
+
onDraftChange?: (value: string) => void
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
// ── Loading verb keys (i18n) ──
|
|
@@ -396,11 +404,25 @@ export function InputBar({
|
|
|
396
404
|
recentMessages,
|
|
397
405
|
autocompleteEnabled = true,
|
|
398
406
|
autocompleteDebounceMs = 400,
|
|
407
|
+
draft,
|
|
408
|
+
onDraftChange,
|
|
399
409
|
}: InputBarProps) {
|
|
400
410
|
const { t } = useI18n()
|
|
401
|
-
|
|
411
|
+
// The draft is seeded from the caller's copy and mirrored back on every change.
|
|
412
|
+
// `app.tsx` unmounts this component when the model picker / API-key prompt /
|
|
413
|
+
// agent view opens; history was hoisted above for exactly that reason, and the
|
|
414
|
+
// typed text was not — opening the picker mid-prompt silently ate it.
|
|
415
|
+
const [value, setLocalValue] = useState(draft ?? '')
|
|
416
|
+
const setValue = (next: string): void => {
|
|
417
|
+
setLocalValue(next)
|
|
418
|
+
onDraftChange?.(next)
|
|
419
|
+
}
|
|
402
420
|
// Ref mirror of value — used by useInput to read latest without stale closure.
|
|
403
421
|
const valueRef = useRef(value)
|
|
422
|
+
// Ref mirror of `pickerActive` for the same reason, and one more: the key
|
|
423
|
+
// handler is declared before the picker state below, so it must not read that
|
|
424
|
+
// variable directly.
|
|
425
|
+
const pickerActiveRef = useRef(false)
|
|
404
426
|
const [verb, setVerb] = useState(() => t(pick(LOADING_KEYS)))
|
|
405
427
|
const [completionVerb, setCompletionVerb] = useState<string | null>(null)
|
|
406
428
|
const prevLoading = useRef(isLoading)
|
|
@@ -453,12 +475,7 @@ export function InputBar({
|
|
|
453
475
|
// filter hid commands a user was plainly looking for ("fork" should surface a
|
|
454
476
|
// command described as "fork the conversation"), so the two slash surfaces now
|
|
455
477
|
// agree on one semantic.
|
|
456
|
-
return allCommands
|
|
457
|
-
.filter(
|
|
458
|
-
(c) =>
|
|
459
|
-
c.name.toLowerCase().includes(filter) || c.description.toLowerCase().includes(filter),
|
|
460
|
-
)
|
|
461
|
-
.slice(0, 8)
|
|
478
|
+
return rankCommandMatches(allCommands, filter).slice(0, 8)
|
|
462
479
|
}, [value, allCommands])
|
|
463
480
|
|
|
464
481
|
// ── @mention hints (cross-session recipients) ──
|
|
@@ -565,8 +582,11 @@ export function InputBar({
|
|
|
565
582
|
// History navigation changes value via setValue (no onChange) — clear any
|
|
566
583
|
// ghost suggestion so a stale one isn't Tab-accepted onto a recalled entry.
|
|
567
584
|
clearSuggestion()
|
|
568
|
-
// Ignore if picker is active (command picker handles
|
|
569
|
-
|
|
585
|
+
// Ignore only if the picker is actually active (the command picker handles
|
|
586
|
+
// its own arrows). The old test was `value.startsWith('/')`, so after
|
|
587
|
+
// recalling a slash command from history — picker off by default — the
|
|
588
|
+
// Up/Down keys dead-ended and the rest of the history was unreachable.
|
|
589
|
+
if (pickerActiveRef.current) return
|
|
570
590
|
|
|
571
591
|
// A draft Escape cleared is still the user's text, and it is the *only*
|
|
572
592
|
// copy: unlike a sent message or a slash command it never entered history.
|
|
@@ -623,6 +643,11 @@ export function InputBar({
|
|
|
623
643
|
valueRef.current = value
|
|
624
644
|
}, [value])
|
|
625
645
|
|
|
646
|
+
// Same for the picker: effects run before the next key event reads the ref.
|
|
647
|
+
useEffect(() => {
|
|
648
|
+
pickerActiveRef.current = pickerActive
|
|
649
|
+
}, [pickerActive])
|
|
650
|
+
|
|
626
651
|
const handleSubmit = (val: string) => {
|
|
627
652
|
// Use the latest value from the ref; `val` is the value passed by MiphamTextInput.
|
|
628
653
|
const finalValue = valueRef.current || val
|
package/src/ui/picker.tsx
CHANGED
|
@@ -106,7 +106,7 @@ export function ModelPicker({
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// Tab or right arrow → switch to model panel
|
|
109
|
-
if (key.tab || (activePanel.read() === 'provider' && input === 'l')) {
|
|
109
|
+
if (key.tab || key.rightArrow || (activePanel.read() === 'provider' && input === 'l')) {
|
|
110
110
|
activePanel.set('model')
|
|
111
111
|
return
|
|
112
112
|
}
|