@miphamai/cli 0.85.48 → 0.85.49
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 +1 -1
- package/package.json +1 -1
- package/src/core/engine.ts +44 -11
- package/src/core/hooks-executor.ts +25 -2
- package/src/core/instructions.ts +12 -3
- package/src/i18n-core/locales/en-US.json +3 -0
- package/src/i18n-core/locales/zh-CN.json +3 -0
- package/src/plugin/plugin-manager.ts +12 -3
- package/src/providers/anthropic.ts +5 -0
- package/src/providers/fetch-utils.ts +16 -1
- package/src/providers/openai-compat.ts +4 -0
- package/src/shared/package-info.ts +2 -2
- package/src/skills/sanitizer.ts +16 -2
- package/src/ui/chat.tsx +9 -1
- package/src/ui/input.tsx +23 -3
- package/src/ui/picker.tsx +15 -3
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mipham Code v0.85.
|
|
1
|
+
# Mipham Code v0.85.49
|
|
2
2
|
|
|
3
3
|
**Multi-model open-core intelligent coding terminal** — 12 AI providers, 141 commands, 31 tools, 28 skills + marketplace, self-update. AI-assisted code generation, security auditing, MCP protocol, and extensible skills — in a single CLI.
|
|
4
4
|
|
package/package.json
CHANGED
package/src/core/engine.ts
CHANGED
|
@@ -1663,7 +1663,9 @@ export class QueryEngine {
|
|
|
1663
1663
|
// command failed (CC 2.1.110-027). A failed result is projected as
|
|
1664
1664
|
// `error || content`, so the warning goes where it is actually read.
|
|
1665
1665
|
if (hookWarnings.length > 0) {
|
|
1666
|
-
|
|
1666
|
+
// Same bound as compaction context: a hook (or a rule) can print a whole
|
|
1667
|
+
// file, and this text is prepended to every matching tool result.
|
|
1668
|
+
const warning = this.capHookContext(hookWarnings.join('\n'))
|
|
1667
1669
|
if (result.success) {
|
|
1668
1670
|
result.content = warning + '\n' + (result.content || '')
|
|
1669
1671
|
} else if (result.error) {
|
|
@@ -1686,9 +1688,8 @@ export class QueryEngine {
|
|
|
1686
1688
|
result.content = postResult.updatedOutput
|
|
1687
1689
|
}
|
|
1688
1690
|
if (postResult.additionalContext) {
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
: postResult.additionalContext
|
|
1691
|
+
const context = this.capHookContext(postResult.additionalContext)
|
|
1692
|
+
result.content = result.content ? result.content + '\n' + context : context
|
|
1692
1693
|
}
|
|
1693
1694
|
}
|
|
1694
1695
|
|
|
@@ -2034,11 +2035,11 @@ export class QueryEngine {
|
|
|
2034
2035
|
type: 'warning',
|
|
2035
2036
|
content: reasoningOnly
|
|
2036
2037
|
? `${activeId} returned only reasoning and no answer — retrying once`
|
|
2037
|
-
: `${activeId} failed (${failure}) — retrying once`,
|
|
2038
|
+
: `${activeId} failed (${explainTransportFailure(failure ?? 'Unknown error')}) — retrying once`,
|
|
2038
2039
|
restart: true,
|
|
2039
2040
|
}
|
|
2040
2041
|
}
|
|
2041
|
-
const detail = failure ?? 'Unknown error'
|
|
2042
|
+
const detail = explainTransportFailure(failure ?? 'Unknown error')
|
|
2042
2043
|
|
|
2043
2044
|
// Deterministic failure: re-sending it to another provider cannot change the
|
|
2044
2045
|
// answer, so surface it once rather than burning the fallback on it.
|
|
@@ -2472,8 +2473,9 @@ export class QueryEngine {
|
|
|
2472
2473
|
return
|
|
2473
2474
|
}
|
|
2474
2475
|
|
|
2475
|
-
// Feed the block reason back to the AI and continue
|
|
2476
|
-
|
|
2476
|
+
// Feed the block reason back to the AI and continue. A hook that blocks with
|
|
2477
|
+
// a whole log attached must not overflow the context it just refused to end.
|
|
2478
|
+
this.context.injectContext(block.source, this.capHookContext(block.text))
|
|
2477
2479
|
yield* this.continueWithTools(signal, roundsLeft)
|
|
2478
2480
|
}
|
|
2479
2481
|
|
|
@@ -2572,16 +2574,47 @@ function toolResultText(content: ContentBlock[]): string {
|
|
|
2572
2574
|
* Kept narrow on purpose: a false positive costs one wasted compaction (the turn
|
|
2573
2575
|
* retries either way), while a false negative ends the turn with a raw upstream
|
|
2574
2576
|
* error the user cannot act on. All of these phrasings are ones the providers
|
|
2575
|
-
* actually send — the
|
|
2576
|
-
*
|
|
2577
|
+
* actually send — the 413 family is what a proxy or gateway in front of the
|
|
2578
|
+
* provider returns when the *request* is over its limit (retrying it verbatim
|
|
2579
|
+
* fails identically; compacting is what changes the size), and the last is the
|
|
2580
|
+
* one a 1M-context model returns while the account has not enabled the charge.
|
|
2577
2581
|
*/
|
|
2578
2582
|
export function isContextOverflowError(message: string | null | undefined): boolean {
|
|
2579
2583
|
if (!message) return false
|
|
2580
|
-
return /context[_ ]length|context window|prompt is too long|input is too long|too many tokens|maximum context length|exceeds? the (?:model'?s )?(?:maximum )?context|usage credits required for 1m context/i.test(
|
|
2584
|
+
return /context[_ ]length|context window|prompt is too long|input is too long|too many tokens|maximum context length|exceeds? the (?:model'?s )?(?:maximum )?context|usage credits required for 1m context|\b413\b|payload too large|request entity too large|request (?:body |size )?too large/i.test(
|
|
2581
2585
|
message,
|
|
2582
2586
|
)
|
|
2583
2587
|
}
|
|
2584
2588
|
|
|
2589
|
+
/**
|
|
2590
|
+
* Turn a transport-level failure into words the user can act on.
|
|
2591
|
+
*
|
|
2592
|
+
* A proxy or gateway that cuts or rewrites a compressed response surfaces as
|
|
2593
|
+
* `ZlibError: incorrect header check` or a bare JSON parse failure. Those are
|
|
2594
|
+
* diagnoses for us, not for the person reading the turn — but dropping them
|
|
2595
|
+
* entirely would take away the only clue, so the plain sentence comes first and
|
|
2596
|
+
* the original follows in parentheses.
|
|
2597
|
+
*/
|
|
2598
|
+
export function explainTransportFailure(message: string): string {
|
|
2599
|
+
if (
|
|
2600
|
+
/zlib|decompress|incorrect header check|invalid (?:stored )?block type|unexpected end of (?:file|stream)/i.test(
|
|
2601
|
+
message,
|
|
2602
|
+
)
|
|
2603
|
+
) {
|
|
2604
|
+
return (
|
|
2605
|
+
'The reply was cut or damaged in transit — a proxy or gateway is the usual cause. ' +
|
|
2606
|
+
`Try again; if it keeps happening, check the proxy. (${message})`
|
|
2607
|
+
)
|
|
2608
|
+
}
|
|
2609
|
+
if (/JSON parse error|unexpected token|unexpected end of JSON input/i.test(message)) {
|
|
2610
|
+
return (
|
|
2611
|
+
"The provider's reply could not be read (malformed JSON — often a proxy or gateway " +
|
|
2612
|
+
`rewriting the response). (${message})`
|
|
2613
|
+
)
|
|
2614
|
+
}
|
|
2615
|
+
return message
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2585
2618
|
function isAbortError(err: unknown): boolean {
|
|
2586
2619
|
if (err instanceof Error && err.name === 'AbortError') return true
|
|
2587
2620
|
if (
|
|
@@ -275,6 +275,29 @@ interface HookProcessResult {
|
|
|
275
275
|
error?: { code?: string; message?: string }
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
/**
|
|
279
|
+
* How much of each hook stream is buffered before the rest is dropped.
|
|
280
|
+
*
|
|
281
|
+
* A hook printing without end used to grow this process's heap for the whole
|
|
282
|
+
* timeout window (60s by default) — the event loop stayed live, but a `yes`-style
|
|
283
|
+
* hook still turned into gigabytes. Keep the first 1 MiB of each stream, which is
|
|
284
|
+
* far more than any structured hook payload, and leave a marker so the truncation
|
|
285
|
+
* is visible rather than silently changing the answer.
|
|
286
|
+
*/
|
|
287
|
+
const MAX_HOOK_STREAM_CHARS = 1_000_000
|
|
288
|
+
|
|
289
|
+
/** Append one chunk to a capped stream buffer. Pure so the bound is testable. */
|
|
290
|
+
export function appendHookStreamChunk(
|
|
291
|
+
previous: string,
|
|
292
|
+
chunk: string,
|
|
293
|
+
cap: number = MAX_HOOK_STREAM_CHARS,
|
|
294
|
+
): string {
|
|
295
|
+
if (previous.length > cap) return previous
|
|
296
|
+
const next = previous + chunk
|
|
297
|
+
if (next.length <= cap) return next
|
|
298
|
+
return `${next.slice(0, cap)}\n[hook output truncated: exceeded ${cap.toLocaleString('en-US')} characters]\n`
|
|
299
|
+
}
|
|
300
|
+
|
|
278
301
|
/**
|
|
279
302
|
* Run a hook command to completion, bounding **both** halves of the wait.
|
|
280
303
|
*
|
|
@@ -368,10 +391,10 @@ async function runHookCommand(
|
|
|
368
391
|
}
|
|
369
392
|
|
|
370
393
|
child.stdout.on('data', (chunk: Buffer) => {
|
|
371
|
-
stdout
|
|
394
|
+
stdout = appendHookStreamChunk(stdout, chunk.toString())
|
|
372
395
|
})
|
|
373
396
|
child.stderr.on('data', (chunk: Buffer) => {
|
|
374
|
-
stderr
|
|
397
|
+
stderr = appendHookStreamChunk(stderr, chunk.toString())
|
|
375
398
|
})
|
|
376
399
|
|
|
377
400
|
child.on('error', (err: NodeJS.ErrnoException) => {
|
package/src/core/instructions.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from './crsi-producer'
|
|
16
16
|
import { miphamHome } from './paths.ts'
|
|
17
17
|
import { safeSlice } from '../shared/sanitize'
|
|
18
|
+
import { readRegularFileSync } from '../shared/regular-file'
|
|
18
19
|
|
|
19
20
|
export interface FrontmatterResult {
|
|
20
21
|
data: Record<string, unknown>
|
|
@@ -765,9 +766,13 @@ Never omit it or present the work as purely human-authored.`)
|
|
|
765
766
|
const changed: string[] = []
|
|
766
767
|
for (const inst of this.instructions) {
|
|
767
768
|
if (this.isUnsafePath(inst.path, inst.level)) continue
|
|
768
|
-
|
|
769
|
+
// Type, not existence: `existsSync` is true for a FIFO, and reading one
|
|
770
|
+
// with no writer blocks forever inside a synchronous call (the same gate
|
|
771
|
+
// `rules-loader.ts` already uses for rule files).
|
|
772
|
+
const raw = readRegularFileSync(inst.path)
|
|
773
|
+
if (raw === null) continue
|
|
769
774
|
try {
|
|
770
|
-
const { data, content } = parseFrontmatter(
|
|
775
|
+
const { data, content } = parseFrontmatter(raw)
|
|
771
776
|
const next = capInstructionContent(content, inst.path)
|
|
772
777
|
if (next !== inst.content) {
|
|
773
778
|
inst.content = next
|
|
@@ -788,8 +793,12 @@ Never omit it or present the work as purely human-authored.`)
|
|
|
788
793
|
|
|
789
794
|
if (this.isUnsafePath(path, level)) return
|
|
790
795
|
|
|
796
|
+
// A FIFO/socket/device here would block the startup read forever; treat it
|
|
797
|
+
// as "nothing to load" instead of waiting on a writer that may never come.
|
|
798
|
+
const raw = readRegularFileSync(path)
|
|
799
|
+
if (raw === null) return
|
|
800
|
+
|
|
791
801
|
try {
|
|
792
|
-
const raw = readFileSync(path, 'utf-8')
|
|
793
802
|
const { data, content } = parseFrontmatter(raw)
|
|
794
803
|
this.instructions.push({
|
|
795
804
|
path,
|
|
@@ -89,9 +89,18 @@ export class PluginManager {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
// Copy plugin directory
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
// Copy plugin directory. A copy that dies halfway used to leave a partial
|
|
93
|
+
// directory behind, and the `already installed` check above then made every
|
|
94
|
+
// retry fail — a plugin that could never be installed until the user found
|
|
95
|
+
// and deleted the wreckage by hand.
|
|
96
|
+
try {
|
|
97
|
+
mkdirSync(destDir, { recursive: true })
|
|
98
|
+
this.copyDir(sourcePath, destDir)
|
|
99
|
+
} catch (err) {
|
|
100
|
+
rmSync(destDir, { recursive: true, force: true })
|
|
101
|
+
const detail = err instanceof Error ? err.message : String(err)
|
|
102
|
+
return { success: false, message: `Failed to copy plugin: ${detail}` }
|
|
103
|
+
}
|
|
95
104
|
|
|
96
105
|
const similarWarning = this.findSimilarWarning(validation.manifest.name)
|
|
97
106
|
this.plugins.push({
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
fetchWithRetry,
|
|
12
12
|
streamIdleTimeoutMs,
|
|
13
13
|
isRetryableFailure,
|
|
14
|
+
isAbortError,
|
|
14
15
|
createAwakeTimer,
|
|
15
16
|
readErrorBody,
|
|
16
17
|
} from './fetch-utils'
|
|
@@ -263,6 +264,10 @@ export class AnthropicProvider implements ProviderInstance {
|
|
|
263
264
|
}),
|
|
264
265
|
])
|
|
265
266
|
} catch (err) {
|
|
267
|
+
// An abort is the caller leaving, not the stream stalling: wrapping it
|
|
268
|
+
// into a retryable error chunk made the engine retry a request the user
|
|
269
|
+
// had just cancelled.
|
|
270
|
+
if (isAbortError(err)) throw err
|
|
266
271
|
yield { type: 'error', error: `Stream stalled: ${String(err)}` }
|
|
267
272
|
return
|
|
268
273
|
} finally {
|
|
@@ -108,8 +108,23 @@ function tlsCertCode(err: unknown): string | undefined {
|
|
|
108
108
|
return undefined
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Was this failure the caller walking away?
|
|
113
|
+
*
|
|
114
|
+
* Providers used to wrap every stream-read rejection — aborts included — into a
|
|
115
|
+
* retryable `Stream stalled:` error chunk, which turned "the user pressed Esc"
|
|
116
|
+
* into "the request failed once, retrying". Abort has to stay an abort all the
|
|
117
|
+
* way out so the engine's own handler (and the UI) can tell the two apart.
|
|
118
|
+
*/
|
|
119
|
+
export function isAbortError(err: unknown): boolean {
|
|
120
|
+
if (err instanceof Error && err.name === 'AbortError') return true
|
|
121
|
+
return (
|
|
122
|
+
typeof DOMException !== 'undefined' && err instanceof DOMException && err.name === 'AbortError'
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
111
126
|
function isRetryableError(err: unknown): boolean {
|
|
112
|
-
if (err
|
|
127
|
+
if (isAbortError(err)) return false
|
|
113
128
|
if (tlsCertCode(err) !== undefined) return false
|
|
114
129
|
return true
|
|
115
130
|
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
fetchWithRetry,
|
|
6
6
|
streamIdleTimeoutMs,
|
|
7
7
|
isRetryableFailure,
|
|
8
|
+
isAbortError,
|
|
8
9
|
createAwakeTimer,
|
|
9
10
|
readErrorBody,
|
|
10
11
|
} from './fetch-utils'
|
|
@@ -142,6 +143,9 @@ export class OpenAICompatProvider implements ProviderInstance {
|
|
|
142
143
|
}),
|
|
143
144
|
])
|
|
144
145
|
} catch (err) {
|
|
146
|
+
// See anthropic.ts: an abort must stay an abort, not become a
|
|
147
|
+
// retryable "stream stalled" error chunk.
|
|
148
|
+
if (isAbortError(err)) throw err
|
|
145
149
|
yield { type: 'error', error: `Stream stalled: ${String(err)}` }
|
|
146
150
|
return
|
|
147
151
|
} finally {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
export const PACKAGE_NAME = '@miphamai/cli' as const
|
|
10
10
|
|
|
11
11
|
/** 当前发布版本 */
|
|
12
|
-
export const PACKAGE_VERSION = '0.85.
|
|
12
|
+
export const PACKAGE_VERSION = '0.85.49' as const
|
|
13
13
|
|
|
14
14
|
/** npm install 全局安装命令 */
|
|
15
15
|
export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` as const
|
|
@@ -90,4 +90,4 @@ export const TOOL_COUNT = 31 as const
|
|
|
90
90
|
* —— `test/e2e/full-pipeline.test.ts` 在 Linux 上整文件 skip、在 macOS 上跑 ——
|
|
91
91
|
* 但**总数相同**(两边都把被 skip 的算进去)。
|
|
92
92
|
*/
|
|
93
|
-
export const TEST_COUNT =
|
|
93
|
+
export const TEST_COUNT = 5332 as const
|
package/src/skills/sanitizer.ts
CHANGED
|
@@ -29,12 +29,19 @@ export interface ShadowCheck {
|
|
|
29
29
|
shadowed: boolean
|
|
30
30
|
/** Name of the conflicting command/tool */
|
|
31
31
|
conflictsWith: string
|
|
32
|
-
/** Type of conflict: 'command' | 'mcp-tool' */
|
|
33
|
-
conflictType: 'command' | 'mcp-tool'
|
|
32
|
+
/** Type of conflict: 'command' | 'mcp-tool' | 'reserved-name' */
|
|
33
|
+
conflictType: 'command' | 'mcp-tool' | 'reserved-name'
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// ── Constants ──
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Tool names the CLI gives a native capability. A skill with one of these names
|
|
40
|
+
* is not shadowing a slash command or an MCP tool, so it used to pass every
|
|
41
|
+
* check — and the model then had two different things called `computer-use`.
|
|
42
|
+
*/
|
|
43
|
+
const RESERVED_SKILL_NAMES = new Set(['computer-use'])
|
|
44
|
+
|
|
38
45
|
/** Known local command names that skills should not shadow */
|
|
39
46
|
const BUILTIN_COMMANDS = new Set([
|
|
40
47
|
'/help',
|
|
@@ -193,6 +200,13 @@ export function checkSkillShadow(
|
|
|
193
200
|
return { shadowed: true, conflictsWith: skillName, conflictType: 'command' }
|
|
194
201
|
}
|
|
195
202
|
|
|
203
|
+
// Names the CLI itself gives a native capability. These are tools, not slash
|
|
204
|
+
// commands, so the command check above does not see them — a same-named skill
|
|
205
|
+
// loaded silently and left the model with two different `computer-use`s.
|
|
206
|
+
if (RESERVED_SKILL_NAMES.has(skillName)) {
|
|
207
|
+
return { shadowed: true, conflictsWith: skillName, conflictType: 'reserved-name' }
|
|
208
|
+
}
|
|
209
|
+
|
|
196
210
|
// Check description for embedded command names
|
|
197
211
|
for (const cmd of BUILTIN_COMMANDS) {
|
|
198
212
|
const cmdPattern = cmd.replace(/\//g, '')
|
package/src/ui/chat.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
stripControlCharsForDisplay,
|
|
10
10
|
} from '../shared/sanitize'
|
|
11
11
|
import { homedir } from 'node:os'
|
|
12
|
+
import { isCompactionSummary } from '../core/session-log'
|
|
12
13
|
import type { UpdateStatus } from '../shared/update'
|
|
13
14
|
|
|
14
15
|
interface ChatPanelProps {
|
|
@@ -164,7 +165,14 @@ const MessageRow = React.memo(
|
|
|
164
165
|
</Box>
|
|
165
166
|
) : (
|
|
166
167
|
<>
|
|
167
|
-
{msg
|
|
168
|
+
{isCompactionSummary(msg) ? (
|
|
169
|
+
// The summary is stored as a user message (that is the role the
|
|
170
|
+
// model reads it in), but showing it under the user label made a
|
|
171
|
+
// resumed session claim the user had typed the whole thing.
|
|
172
|
+
<Text bold color="yellow">
|
|
173
|
+
⚑ {t('ui.compaction.role_label')}:
|
|
174
|
+
</Text>
|
|
175
|
+
) : msg.role === 'user' ? (
|
|
168
176
|
<Text bold color="green">
|
|
169
177
|
▸ {displayCwd()}:
|
|
170
178
|
</Text>
|
package/src/ui/input.tsx
CHANGED
|
@@ -530,7 +530,16 @@ export function InputBar({
|
|
|
530
530
|
}
|
|
531
531
|
// Idle → clear the draft (the intuitive "cancel"), keeping it recoverable:
|
|
532
532
|
// Up from the now-empty input restores it (see the arrow-key branch).
|
|
533
|
-
|
|
533
|
+
// While browsing history, the text on screen is a recalled entry, not the
|
|
534
|
+
// user's draft — save the *draft* slot instead, or Escape overwrites the
|
|
535
|
+
// only copy of what they were typing with an old prompt.
|
|
536
|
+
if (historyIndexRef.current === -1) {
|
|
537
|
+
if (valueRef.current) clearedDraftRef.current = valueRef.current
|
|
538
|
+
} else if (savedDraftRef.current) {
|
|
539
|
+
clearedDraftRef.current = savedDraftRef.current
|
|
540
|
+
}
|
|
541
|
+
historyIndexRef.current = -1
|
|
542
|
+
savedDraftRef.current = ''
|
|
534
543
|
setValue('')
|
|
535
544
|
valueRef.current = ''
|
|
536
545
|
clearSuggestion()
|
|
@@ -605,6 +614,16 @@ export function InputBar({
|
|
|
605
614
|
return
|
|
606
615
|
}
|
|
607
616
|
|
|
617
|
+
// Editing a recalled entry ends browsing but must not destroy the text
|
|
618
|
+
// that was there before the recall. Down brings that draft back instead of
|
|
619
|
+
// being a no-op (the entry used to blank `savedDraft` on the first edit).
|
|
620
|
+
if (key.downArrow && historyIndexRef.current === -1 && savedDraftRef.current) {
|
|
621
|
+
const restored = savedDraftRef.current
|
|
622
|
+
savedDraftRef.current = ''
|
|
623
|
+
setValue(restored)
|
|
624
|
+
return
|
|
625
|
+
}
|
|
626
|
+
|
|
608
627
|
const result = navigateHistory(
|
|
609
628
|
{
|
|
610
629
|
history,
|
|
@@ -698,10 +717,11 @@ export function InputBar({
|
|
|
698
717
|
<MiphamTextInput
|
|
699
718
|
value={value}
|
|
700
719
|
onChange={(val) => {
|
|
701
|
-
// Reset history browsing when user starts typing
|
|
720
|
+
// Reset history browsing when user starts typing. `savedDraft` is
|
|
721
|
+
// deliberately kept: it is the only copy of what they were writing
|
|
722
|
+
// before the recall, and Down restores it (see the arrow branch).
|
|
702
723
|
if (historyIndexRef.current !== -1) {
|
|
703
724
|
historyIndexRef.current = -1
|
|
704
|
-
savedDraftRef.current = ''
|
|
705
725
|
}
|
|
706
726
|
// ── Ghost-text 自动补全:每次输入清 suggestion + 重排防抖 ──
|
|
707
727
|
setSuggestion(null)
|
package/src/ui/picker.tsx
CHANGED
|
@@ -45,7 +45,14 @@ export function ModelPicker({
|
|
|
45
45
|
const idx = providers.findIndex((p) => p.id === currentProvider)
|
|
46
46
|
return idx >= 0 ? idx : 0
|
|
47
47
|
})
|
|
48
|
-
|
|
48
|
+
// Seed the model cursor on the model the session is actually using, so Tab
|
|
49
|
+
// into the model panel lands on it (it used to start at row 0).
|
|
50
|
+
const modelIdx = useKeyState(() => {
|
|
51
|
+
const provider = providers.find((p) => p.id === currentProvider)
|
|
52
|
+
const models = provider ? activeModels(provider) : []
|
|
53
|
+
const idx = models.findIndex((m) => m.id === currentModel)
|
|
54
|
+
return idx >= 0 ? idx : 0
|
|
55
|
+
})
|
|
49
56
|
|
|
50
57
|
const selectedProvider = providers[providerIdx.value]
|
|
51
58
|
const models = selectedProvider ? activeModels(selectedProvider) : []
|
|
@@ -54,10 +61,15 @@ export function ModelPicker({
|
|
|
54
61
|
const goToProvider = useCallback(
|
|
55
62
|
(idx: number) => {
|
|
56
63
|
providerIdx.set(wrap(idx, providers.length))
|
|
57
|
-
|
|
64
|
+
// Land on the session's current model when this is its provider; any
|
|
65
|
+
// other provider stays at row 0.
|
|
66
|
+
const provider = providers[wrap(idx, providers.length)]
|
|
67
|
+
const models = provider ? activeModels(provider) : []
|
|
68
|
+
const current = models.findIndex((m) => m.id === currentModel)
|
|
69
|
+
modelIdx.set(current >= 0 ? current : 0)
|
|
58
70
|
activePanel.set('model') // auto-switch to model panel
|
|
59
71
|
},
|
|
60
|
-
[providers
|
|
72
|
+
[providers, providerIdx, modelIdx, currentModel],
|
|
61
73
|
)
|
|
62
74
|
|
|
63
75
|
/** 相对移动 —— 按 `read()` 叠加,同一拍里的两次 ↓ 就是两步。 */
|