@miphamai/cli 0.85.56 → 0.85.57
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/index.tsx +4 -1
- package/src/mcp/client.ts +106 -9
- package/src/shared/package-info.ts +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mipham Code v0.85.
|
|
1
|
+
# Mipham Code v0.85.57
|
|
2
2
|
|
|
3
3
|
**Multi-model open-core intelligent coding terminal** — 12 AI providers, 150 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/index.tsx
CHANGED
|
@@ -51,7 +51,7 @@ import { mountSkills, SKILLS_KEY } from './skills/seam'
|
|
|
51
51
|
import { mountLlm, LLM_KEY } from './providers/llm'
|
|
52
52
|
import { mountConstitution, createConstitution } from './core/constitution-seam'
|
|
53
53
|
import { ConstitutionLoader } from './core/constitution-loader'
|
|
54
|
-
import { McpClient } from './mcp/client'
|
|
54
|
+
import { McpClient, describeSlowConnect } from './mcp/client'
|
|
55
55
|
import { buildMcpInstructionsBlock } from './mcp/instructions'
|
|
56
56
|
import { registerMcpServerTools, syncMcpToolsOnChange } from './mcp/registry'
|
|
57
57
|
import { formatMcpConnectFailures, type McpConnectFailure } from './mcp/connect-failures'
|
|
@@ -331,6 +331,9 @@ async function connectMcpServers(
|
|
|
331
331
|
// bounded and stops early on a definitive refusal. `MIPHAM_MCP_AUTO_RECONNECT=0`
|
|
332
332
|
// turns it off (e.g. for a scripted session that must not spawn processes).
|
|
333
333
|
mcp.setAutoReconnect(process.env.MIPHAM_MCP_AUTO_RECONNECT !== '0')
|
|
334
|
+
// A package-manager launch can spend the whole budget inside npx. Say which
|
|
335
|
+
// package is being resolved instead of staying silent until the timeout.
|
|
336
|
+
mcp.setSlowConnectReporter((notice) => console.error(describeSlowConnect(notice)))
|
|
334
337
|
// Wire runtime tool-list changes before connect so mid-connect updates land.
|
|
335
338
|
syncMcpToolsOnChange(mcp, tools)
|
|
336
339
|
const results = await Promise.allSettled(
|
package/src/mcp/client.ts
CHANGED
|
@@ -68,6 +68,77 @@ export function connectTimeoutMs(command?: string): number {
|
|
|
68
68
|
: DEFAULT_CONNECT_TIMEOUT_MS
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/** How long a handshake may run before the client says what it is waiting on. */
|
|
72
|
+
export const SLOW_CONNECT_NOTICE_MS = 3_000
|
|
73
|
+
|
|
74
|
+
/** Subcommands that sit between `npm`/`pnpm` and the package word. */
|
|
75
|
+
const PACKAGE_MANAGER_SUBCOMMANDS = new Set(['exec', 'x', 'dlx', 'run', 'run-script'])
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The package a package-manager launch is resolving — the first word that is
|
|
79
|
+
* neither a flag nor a subcommand. Used only in messages; `undefined` when the
|
|
80
|
+
* args carry no package word (then the message simply omits it).
|
|
81
|
+
*/
|
|
82
|
+
export function packageSpecOf(args: string[] = []): string | undefined {
|
|
83
|
+
for (const arg of args) {
|
|
84
|
+
if (!arg || arg.startsWith('-')) continue
|
|
85
|
+
if (PACKAGE_MANAGER_SUBCOMMANDS.has(arg)) continue
|
|
86
|
+
return arg
|
|
87
|
+
}
|
|
88
|
+
return undefined
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Timeout message with the one thing the bare text cannot carry: that the
|
|
93
|
+
* budget may have been spent in package resolution, not in the server.
|
|
94
|
+
*
|
|
95
|
+
* A pinned absolute path removes that cost entirely; the env override is the
|
|
96
|
+
* escape hatch when the user wants to keep `npx`.
|
|
97
|
+
*/
|
|
98
|
+
export function describeConnectTimeout(
|
|
99
|
+
name: string,
|
|
100
|
+
timeoutMs: number,
|
|
101
|
+
command?: string,
|
|
102
|
+
args: string[] = [],
|
|
103
|
+
): string {
|
|
104
|
+
const base = `MCP connect timed out for "${name}" after ${timeoutMs}ms`
|
|
105
|
+
if (!isPackageManagerCommand(command)) return base
|
|
106
|
+
const pm = basename(command!).replace(/\.(cmd|exe|ps1)$/i, '')
|
|
107
|
+
const pkg = packageSpecOf(args)
|
|
108
|
+
const target = pkg ? ` (${pkg})` : ''
|
|
109
|
+
return (
|
|
110
|
+
`${base} — it was started via ${pm}${target}, whose package resolution runs before the ` +
|
|
111
|
+
`handshake and can exceed this budget even when the server is fine. Pin an absolute path ` +
|
|
112
|
+
`(e.g. command "node" with the server's dist entry) or raise MIPHAM_MCP_CONNECT_TIMEOUT_MS.`
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface SlowConnectNotice {
|
|
117
|
+
name: string
|
|
118
|
+
command?: string
|
|
119
|
+
args: string[]
|
|
120
|
+
elapsedMs: number
|
|
121
|
+
timeoutMs: number
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* One line while the budget is still running: which server, which package (if a
|
|
126
|
+
* package manager is resolving one), how long so far, and how long it is
|
|
127
|
+
* allowed. Without it a 45 s npx download looks exactly like a hang, and the
|
|
128
|
+
* only message the user ever sees is the failure.
|
|
129
|
+
*/
|
|
130
|
+
export function describeSlowConnect(notice: SlowConnectNotice): string {
|
|
131
|
+
const elapsed = `${Math.max(1, Math.round(notice.elapsedMs / 1000))}s`
|
|
132
|
+
const budget = `${Math.round(notice.timeoutMs / 1000)}s`
|
|
133
|
+
if (isPackageManagerCommand(notice.command)) {
|
|
134
|
+
const pm = basename(notice.command!).replace(/\.(cmd|exe|ps1)$/i, '')
|
|
135
|
+
const pkg = packageSpecOf(notice.args)
|
|
136
|
+
const target = pkg ? ` ${pkg}` : ''
|
|
137
|
+
return `[mcp] "${notice.name}" is still starting — resolving ${pm} package${target} (${elapsed} elapsed, ${budget} budget)`
|
|
138
|
+
}
|
|
139
|
+
return `[mcp] "${notice.name}" is still starting (${elapsed} elapsed, ${budget} budget)`
|
|
140
|
+
}
|
|
141
|
+
|
|
71
142
|
/**
|
|
72
143
|
* Will retrying this connect failure change the answer?
|
|
73
144
|
*
|
|
@@ -167,6 +238,8 @@ export class McpClient {
|
|
|
167
238
|
* is only about *when* it is called — not how it behaves.
|
|
168
239
|
*/
|
|
169
240
|
private autoReconnect = false
|
|
241
|
+
/** Reports a handshake that is still running after `SLOW_CONNECT_NOTICE_MS`. */
|
|
242
|
+
private slowConnectReporter?: (notice: SlowConnectNotice) => void
|
|
170
243
|
/** Servers with an auto-reconnect in flight — one at a time per name. */
|
|
171
244
|
private reconnecting = new Set<string>()
|
|
172
245
|
/** Set by `closeAll` so a teardown is never undone by an in-flight reconnect. */
|
|
@@ -216,6 +289,14 @@ export class McpClient {
|
|
|
216
289
|
this.autoReconnect = enabled
|
|
217
290
|
}
|
|
218
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Where to say "still starting" while a handshake is inside its budget.
|
|
294
|
+
* Installed by the CLI entry point; unset in tests and headless callers.
|
|
295
|
+
*/
|
|
296
|
+
setSlowConnectReporter(reporter?: (notice: SlowConnectNotice) => void): void {
|
|
297
|
+
this.slowConnectReporter = reporter
|
|
298
|
+
}
|
|
299
|
+
|
|
219
300
|
/**
|
|
220
301
|
* Obtain the credentials a server's config calls for, as transport env.
|
|
221
302
|
*
|
|
@@ -496,7 +577,7 @@ export class McpClient {
|
|
|
496
577
|
// is what an unauthenticated request gets rejected on.
|
|
497
578
|
const env = await this.envWithAuth(config)
|
|
498
579
|
|
|
499
|
-
await this.withConnectTimeout(config
|
|
580
|
+
await this.withConnectTimeout(config, async () => {
|
|
500
581
|
// Start the transport (transport-specific), then perform the handshake.
|
|
501
582
|
if (transport instanceof HttpTransport) {
|
|
502
583
|
await transport.start(config.url ?? '', config.headers, env)
|
|
@@ -546,32 +627,48 @@ export class McpClient {
|
|
|
546
627
|
* server registers no tools — never give `markIfTransportLost` a chance to
|
|
547
628
|
* reconnect. The server is fine; only the clock moved.
|
|
548
629
|
*/
|
|
549
|
-
private async withConnectTimeout<T>(
|
|
550
|
-
|
|
551
|
-
command: string | undefined,
|
|
552
|
-
fn: () => Promise<T>,
|
|
553
|
-
): Promise<T> {
|
|
554
|
-
const timeoutMs = connectTimeoutMs(command)
|
|
630
|
+
private async withConnectTimeout<T>(config: McpServerConfig, fn: () => Promise<T>): Promise<T> {
|
|
631
|
+
const timeoutMs = connectTimeoutMs(config.command)
|
|
555
632
|
// Held in an object, not a `let`: the timer is armed inside the Promise
|
|
556
633
|
// executor, and assignments made there are invisible to control-flow
|
|
557
634
|
// narrowing — TS keeps the variable typed `null` and the cleanup call below
|
|
558
635
|
// is a type error rather than code.
|
|
559
|
-
const timer: { cancel?: () => void } = {}
|
|
636
|
+
const timer: { cancel?: () => void; notice?: ReturnType<typeof setTimeout> } = {}
|
|
560
637
|
// Swallow a late rejection: if the timeout wins, transport.close() in the
|
|
561
638
|
// caller's catch makes fn()'s pending request reject after we've moved on.
|
|
562
639
|
const work = fn()
|
|
563
640
|
work.catch(() => {})
|
|
641
|
+
// Say what is being waited on while the budget is still running. The delay
|
|
642
|
+
// scales down with the budget, so a test-sized timeout still gets a notice
|
|
643
|
+
// and a 45 s npx budget is not narrowed by the progress line itself.
|
|
644
|
+
const startedAt = Date.now()
|
|
645
|
+
const noticeDelay = Math.min(SLOW_CONNECT_NOTICE_MS, Math.max(1, Math.floor(timeoutMs / 3)))
|
|
646
|
+
timer.notice = setTimeout(() => {
|
|
647
|
+
this.slowConnectReporter?.({
|
|
648
|
+
name: config.name,
|
|
649
|
+
command: config.command,
|
|
650
|
+
args: config.args ?? [],
|
|
651
|
+
elapsedMs: Date.now() - startedAt,
|
|
652
|
+
timeoutMs,
|
|
653
|
+
})
|
|
654
|
+
}, noticeDelay)
|
|
655
|
+
timer.notice.unref?.()
|
|
564
656
|
try {
|
|
565
657
|
return await Promise.race([
|
|
566
658
|
work,
|
|
567
659
|
new Promise<never>((_, reject) => {
|
|
568
660
|
timer.cancel = createAwakeTimer(timeoutMs, () =>
|
|
569
|
-
reject(
|
|
661
|
+
reject(
|
|
662
|
+
new Error(
|
|
663
|
+
describeConnectTimeout(config.name, timeoutMs, config.command, config.args ?? []),
|
|
664
|
+
),
|
|
665
|
+
),
|
|
570
666
|
)
|
|
571
667
|
}),
|
|
572
668
|
])
|
|
573
669
|
} finally {
|
|
574
670
|
timer.cancel?.()
|
|
671
|
+
if (timer.notice) clearTimeout(timer.notice)
|
|
575
672
|
}
|
|
576
673
|
}
|
|
577
674
|
|
|
@@ -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.57' 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 = 5658 as const
|