@miphamai/cli 0.85.44 → 0.85.45
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/commands/git.ts +149 -1
- package/src/core/engine.ts +15 -0
- package/src/i18n-core/locales/en-US.json +6 -1
- package/src/i18n-core/locales/zh-CN.json +6 -1
- package/src/mcp/transport.ts +24 -4
- package/src/providers/anthropic.ts +48 -4
- package/src/providers/openai-compat.ts +58 -19
- package/src/providers/registry.ts +41 -0
- package/src/shared/constants.ts +11 -0
- package/src/shared/package-info.ts +3 -3
- package/src/shared/sanitize.ts +17 -0
- package/src/ui/chat.tsx +8 -4
- package/src/ui/commands.ts +44 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Mipham Code v0.85.
|
|
1
|
+
# Mipham Code v0.85.45
|
|
2
2
|
|
|
3
|
-
**Multi-model open-core intelligent coding terminal** — 12 AI providers,
|
|
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
|
|
|
5
5
|
Built by [One Mipham Corporation](https://onemipham.com) (北京华安麦逄科技有限公司) | Brand: MiphamAI
|
|
6
6
|
|
|
@@ -16,7 +16,7 @@ Requirements: **Bun 1.2+** (recommended) or **Node.js 22+**
|
|
|
16
16
|
## Features
|
|
17
17
|
|
|
18
18
|
- **12 AI Providers** — Anthropic Claude · OpenAI GPT · DeepSeek · Kimi (Moonshot) · Google Gemini · Doubao 豆包 · Tencent Hunyuan 混元 · Qwen 通义千问 · MiniMax(国内 / 国际)· Ollama(本地)· MiphamAI
|
|
19
|
-
- **
|
|
19
|
+
- **141 Slash Commands** — Interactive command picker (↑↓ Enter Esc), intuitive command interface, zero re-learning
|
|
20
20
|
- **31 Built-in Tools** — File ops, shell execution, agent dispatch, MCP integration, web search
|
|
21
21
|
- **28 Skills + Marketplace** — 22 standard + 6 Mipham-exclusive skills. `/browse-skills` `/install-skill` community marketplace
|
|
22
22
|
- **Self-Update** — `mipham update` / `/upgrade` — one command to check, backup config, upgrade, restore. API keys preserved
|
package/package.json
CHANGED
package/src/commands/git.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { CommandHandler } from '../ui/commands.js'
|
|
8
8
|
|
|
9
|
-
export { commitCmd, pushCmd, prCmd, issueCmd }
|
|
9
|
+
export { commitCmd, pushCmd, prCmd, issueCmd, shipCmd }
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Run a git command asynchronously — avoids blocking the TUI event loop.
|
|
@@ -189,6 +189,154 @@ const issueCmd: CommandHandler = async (_ctx, args) => {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
// ═══════════════════════════════════════════════════════════════
|
|
193
|
+
// /ship — the whole after-you-write-it loop (Claude Ship beta borrow)
|
|
194
|
+
// ═══════════════════════════════════════════════════════════════
|
|
195
|
+
|
|
196
|
+
export interface ShipContext {
|
|
197
|
+
branch: string
|
|
198
|
+
defaultBranch: string
|
|
199
|
+
staged: number
|
|
200
|
+
unstaged: number
|
|
201
|
+
untracked: number
|
|
202
|
+
ahead: string
|
|
203
|
+
gh: boolean
|
|
204
|
+
/** Whatever the user typed after `/ship` (e.g. `--draft`). */
|
|
205
|
+
args: string
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The plan `/ship` hands to the model.
|
|
210
|
+
*
|
|
211
|
+
* Split out from the handler so the parts that are policy — never commit to the
|
|
212
|
+
* default branch, never merge, report an undo command after each push — can be
|
|
213
|
+
* asserted without spawning git or gh. The handler only gathers facts.
|
|
214
|
+
*/
|
|
215
|
+
export function buildShipPlan(c: ShipContext): { content: string; forwardToAI?: string } {
|
|
216
|
+
if (!c.branch) {
|
|
217
|
+
return {
|
|
218
|
+
content:
|
|
219
|
+
'── Ship ──\n\n' +
|
|
220
|
+
'HEAD is detached, so there is no branch to ship. Check out a branch first, then run /ship again.',
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const onDefault = c.branch === c.defaultBranch
|
|
225
|
+
// Only a known zero means nothing is ahead. An empty string means the
|
|
226
|
+
// upstream count could not be read (no origin, or no upstream branch) — that
|
|
227
|
+
// is "unknown", not "nothing", and the loop must not claim there is no work.
|
|
228
|
+
const nothingToDo = c.staged === 0 && c.unstaged === 0 && c.untracked === 0 && c.ahead === '0'
|
|
229
|
+
|
|
230
|
+
const header = [
|
|
231
|
+
'── Ship ──',
|
|
232
|
+
'',
|
|
233
|
+
`Branch: ${c.branch}${onDefault ? ` (the default branch)` : ''}`,
|
|
234
|
+
`Changes: ${c.staged} staged, ${c.unstaged} unstaged, ${c.untracked} untracked`,
|
|
235
|
+
`Ahead: ${c.ahead || 'unknown'} commit(s) of origin/${c.branch}`,
|
|
236
|
+
`gh: ${c.gh ? 'available' : 'not found'}`,
|
|
237
|
+
].join('\n')
|
|
238
|
+
|
|
239
|
+
if (nothingToDo) {
|
|
240
|
+
return {
|
|
241
|
+
content:
|
|
242
|
+
`${header}\n\n` + `Nothing to ship: no changes and nothing ahead of origin/${c.branch}.`,
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const forwardToAI = `Ship this branch end-to-end with the git and Bash tools. Every push and PR step is permission-checked — do not bypass that layer.
|
|
247
|
+
|
|
248
|
+
Context:
|
|
249
|
+
- Branch: ${c.branch}
|
|
250
|
+
- Default branch: ${c.defaultBranch}
|
|
251
|
+
- Staged / unstaged / untracked: ${c.staged} / ${c.unstaged} / ${c.untracked}
|
|
252
|
+
- Commits ahead of origin/${c.branch}: ${c.ahead || '0'}
|
|
253
|
+
- gh CLI: ${c.gh ? 'available' : 'not found'}
|
|
254
|
+
- User arguments: ${c.args || '(none)'}
|
|
255
|
+
|
|
256
|
+
Steps:
|
|
257
|
+
1. Inspect git status, the diff, and the commits ahead of ${c.defaultBranch}. Never discard the user's uncommitted work.
|
|
258
|
+
2. If HEAD is on ${c.defaultBranch} or detached, create a feature branch named mipham/ship-<short-slug> first. Never commit directly to ${c.defaultBranch}.
|
|
259
|
+
3. Stage only the intended changes and write a Conventional Commits message. If there is nothing to commit, skip this step.
|
|
260
|
+
4. Push the branch you are on with \`git push -u origin <branch>\` (the feature branch from step 2 if you created one).
|
|
261
|
+
5. If gh is available and authenticated, open a pull request with \`gh pr create --base ${c.defaultBranch} --head <branch>\`; use --draft if the user asked for one. If gh is missing or not authenticated, stop after the push and say the PR was not opened.
|
|
262
|
+
6. Review the PR diff with the code-review skill. Report findings with severity (important / pre_existing / nit) and file:line. If CI checks fail, read the failing logs (\`gh pr checks <n>\`, \`gh run view --log-failed\`) and fix the cause; if the branch conflicts with the base, bring the base in and resolve the conflicts carefully.
|
|
263
|
+
7. Fix only defects that are safe and in scope; push each round. Never force-push.
|
|
264
|
+
8. After every push, state what changed and the exact undo command (\`git revert <sha>\`).
|
|
265
|
+
9. Finish with: the PR URL, what was reviewed and fixed, and anything that needs a human decision.
|
|
266
|
+
|
|
267
|
+
Never merge, approve, or change branch protection. If a step fails, stop and name the step and its error. Do not claim a step succeeded unless its command exited 0.`
|
|
268
|
+
|
|
269
|
+
const notes = [
|
|
270
|
+
onDefault
|
|
271
|
+
? 'On the default branch — Claude will create a feature branch before committing.'
|
|
272
|
+
: '',
|
|
273
|
+
c.gh ? '' : 'gh not found — Claude will stop after pushing; no PR will be opened.',
|
|
274
|
+
].filter(Boolean)
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
content: notes.length ? `${header}\n\n${notes.map((n) => `• ${n}`).join('\n')}` : header,
|
|
278
|
+
forwardToAI,
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** `gh --version` with a short bound; a hung binary must not hang the command. */
|
|
283
|
+
async function commandExists(command: string): Promise<boolean> {
|
|
284
|
+
try {
|
|
285
|
+
const proc = Bun.spawn([command, '--version'], { stdout: 'pipe', stderr: 'pipe' })
|
|
286
|
+
const exitCode = await Promise.race([
|
|
287
|
+
proc.exited,
|
|
288
|
+
new Promise<number>((resolve) => setTimeout(() => resolve(143), 2000)),
|
|
289
|
+
])
|
|
290
|
+
if (exitCode === 143) {
|
|
291
|
+
proc.kill()
|
|
292
|
+
return false
|
|
293
|
+
}
|
|
294
|
+
return exitCode === 0
|
|
295
|
+
} catch {
|
|
296
|
+
return false
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const shipCmd: CommandHandler = async (_ctx, args) => {
|
|
301
|
+
try {
|
|
302
|
+
// `git()` maps every failure to '', so "not a repository" and "detached
|
|
303
|
+
// HEAD" would otherwise print the same thing. Ask explicitly.
|
|
304
|
+
const inside = await git(['rev-parse', '--is-inside-work-tree'], 3000)
|
|
305
|
+
if (inside !== 'true') {
|
|
306
|
+
return {
|
|
307
|
+
content: '── Ship ──\n\nNot a git repository. Run /ship from a repository checkout.',
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const branch = await git(['branch', '--show-current'], 3000)
|
|
311
|
+
const remote = await git(['remote', 'show', 'origin'], 3000)
|
|
312
|
+
const defaultBranch = remote.match(/HEAD branch:\s*(\S+)/)?.[1] || 'main'
|
|
313
|
+
|
|
314
|
+
const [stagedRaw, unstagedRaw, untrackedRaw, aheadRaw] = await Promise.all([
|
|
315
|
+
git(['diff', '--cached', '--name-only'], 3000),
|
|
316
|
+
git(['diff', '--name-only'], 3000),
|
|
317
|
+
git(['ls-files', '--others', '--exclude-standard'], 3000),
|
|
318
|
+
branch ? git(['rev-list', '--count', `origin/${branch}..HEAD`], 3000) : Promise.resolve(''),
|
|
319
|
+
])
|
|
320
|
+
|
|
321
|
+
const count = (s: string): number => s.split('\n').filter(Boolean).length
|
|
322
|
+
|
|
323
|
+
return buildShipPlan({
|
|
324
|
+
branch,
|
|
325
|
+
defaultBranch,
|
|
326
|
+
staged: count(stagedRaw),
|
|
327
|
+
unstaged: count(unstagedRaw),
|
|
328
|
+
untracked: count(untrackedRaw),
|
|
329
|
+
ahead: aheadRaw || '0',
|
|
330
|
+
gh: await commandExists('gh'),
|
|
331
|
+
args: args.join(' ').trim(),
|
|
332
|
+
})
|
|
333
|
+
} catch {
|
|
334
|
+
return {
|
|
335
|
+
content: '── Ship ──\n\nCould not inspect the repository. Are you in a git repository?',
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
192
340
|
// ═══════════════════════════════════════════════════════════════
|
|
193
341
|
// Code Quality — bridge slash commands to skills (Claude Code parity)
|
|
194
342
|
// ═══════════════════════════════════════════════════════════════
|
package/src/core/engine.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
ContentBlock,
|
|
10
10
|
} from '../shared/index.ts'
|
|
11
11
|
import { ProviderRegistry } from '../providers/registry'
|
|
12
|
+
import { UNNAMED_TOOL_CALL } from '../shared/constants'
|
|
12
13
|
import { createAwakeTimer } from '../providers/fetch-utils'
|
|
13
14
|
import type { ChatRequest } from '../providers/registry'
|
|
14
15
|
import type { Llm } from '../providers/llm'
|
|
@@ -1517,6 +1518,20 @@ export class QueryEngine {
|
|
|
1517
1518
|
getMetrics().toolCalls.inc({ tool_name: name })
|
|
1518
1519
|
const tool = this.tools.get(name)
|
|
1519
1520
|
if (!tool) {
|
|
1521
|
+
// A provider that sends a tool call with no name is not a tool lookup
|
|
1522
|
+
// failure the model can guess its way out of. Say what happened; the
|
|
1523
|
+
// result goes back as a normal tool_result, so the turn continues and the
|
|
1524
|
+
// model can re-issue the call (331-038).
|
|
1525
|
+
if (name === UNNAMED_TOOL_CALL) {
|
|
1526
|
+
return {
|
|
1527
|
+
success: false,
|
|
1528
|
+
content: '',
|
|
1529
|
+
error:
|
|
1530
|
+
'The provider returned a tool call with no name, so the call was not dispatched. ' +
|
|
1531
|
+
'Re-issue the call with a tool name and its arguments.',
|
|
1532
|
+
notRun: true,
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1520
1535
|
// P2-4: Provide a more helpful error for unavailable tools
|
|
1521
1536
|
const isMcpTool = name.startsWith('mcp__')
|
|
1522
1537
|
const hint = isMcpTool
|
|
@@ -513,7 +513,12 @@
|
|
|
513
513
|
"skills_unavailable": " (skills info unavailable)",
|
|
514
514
|
"audit_section": "── CLAUDE.md Audit ──",
|
|
515
515
|
"audit_clean": " ✓ no code-derivable sections found",
|
|
516
|
-
"audit_found": "Add the sections above to the `prompt-exclude` frontmatter to stop sending them to the model."
|
|
516
|
+
"audit_found": "Add the sections above to the `prompt-exclude` frontmatter to stop sending them to the model.",
|
|
517
|
+
"api_section": "── API ──",
|
|
518
|
+
"api_target": " {provider} ({model})",
|
|
519
|
+
"api_not_tested": " ⚪ not tested — {reason}",
|
|
520
|
+
"api_reachable": " 🟢 reachable — {detail}",
|
|
521
|
+
"api_unreachable": " 🔴 unreachable — {detail}"
|
|
517
522
|
},
|
|
518
523
|
"skillDoctor": {
|
|
519
524
|
"title": "── Skill Doctor ──",
|
|
@@ -513,7 +513,12 @@
|
|
|
513
513
|
"skills_unavailable": " (技能信息不可用)",
|
|
514
514
|
"audit_section": "── CLAUDE.md 审计 ──",
|
|
515
515
|
"audit_clean": " ✓ 未发现可从代码推断的冗余章节",
|
|
516
|
-
"audit_found": "将上述章节加入 `prompt-exclude` frontmatter,可停止发送给模型、节省 token。"
|
|
516
|
+
"audit_found": "将上述章节加入 `prompt-exclude` frontmatter,可停止发送给模型、节省 token。",
|
|
517
|
+
"api_section": "── API ──",
|
|
518
|
+
"api_target": " {provider}({model})",
|
|
519
|
+
"api_not_tested": " ⚪ 未测试 — {reason}",
|
|
520
|
+
"api_reachable": " 🟢 可连接 — {detail}",
|
|
521
|
+
"api_unreachable": " 🔴 不可连接 — {detail}"
|
|
517
522
|
},
|
|
518
523
|
"skillDoctor": {
|
|
519
524
|
"title": "── 技能体检 ──",
|
package/src/mcp/transport.ts
CHANGED
|
@@ -90,6 +90,25 @@ function killProcessTree(proc: ChildProcess): void {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* The request id a response line answers, if any.
|
|
95
|
+
*
|
|
96
|
+
* Our requests carry **numeric** ids, but a server is free to stringify them on
|
|
97
|
+
* the way back (`"id": "7"`). That response used to match nothing, so the
|
|
98
|
+
* request stayed pending until the full request timeout — a malformed reply
|
|
99
|
+
* that reads as a slow server. Numeric-string ids are the one spelling we can
|
|
100
|
+
* map back safely; anything else (a non-numeric string, `null`, an object) names
|
|
101
|
+
* a request we never sent and must not settle someone else's promise.
|
|
102
|
+
*/
|
|
103
|
+
function matchResponseId(value: unknown): number | null {
|
|
104
|
+
if (typeof value === 'number' && Number.isInteger(value)) return value
|
|
105
|
+
if (typeof value === 'string' && /^\d+$/.test(value)) {
|
|
106
|
+
const id = Number(value)
|
|
107
|
+
return Number.isSafeInteger(id) ? id : null
|
|
108
|
+
}
|
|
109
|
+
return null
|
|
110
|
+
}
|
|
111
|
+
|
|
93
112
|
/** Every descendant of `root`, parents before children. */
|
|
94
113
|
function descendantPids(root: number): number[] {
|
|
95
114
|
let listing: string
|
|
@@ -232,12 +251,13 @@ export class StdioTransport implements Transport {
|
|
|
232
251
|
const msg = JSON.parse(trimmed)
|
|
233
252
|
|
|
234
253
|
// Check if it's a response (has id and result/error)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const entry = this.pending.get(
|
|
254
|
+
const responseId = matchResponseId(msg.id)
|
|
255
|
+
if (responseId !== null && ('result' in msg || 'error' in msg)) {
|
|
256
|
+
const entry = this.pending.get(responseId)
|
|
238
257
|
if (entry) {
|
|
239
258
|
clearTimeout(entry.timer)
|
|
240
|
-
this.pending.delete(
|
|
259
|
+
this.pending.delete(responseId)
|
|
260
|
+
const response = msg as JsonRpcResponse
|
|
241
261
|
if (response.error) {
|
|
242
262
|
entry.reject(
|
|
243
263
|
new Error(`MCP error ${response.error.code}: ${response.error.message}`),
|
|
@@ -5,7 +5,8 @@ import type {
|
|
|
5
5
|
StreamChunk,
|
|
6
6
|
ContentBlock,
|
|
7
7
|
} from '../shared/index.ts'
|
|
8
|
-
import type { ProviderInstance, ChatRequest } from './registry'
|
|
8
|
+
import type { ProviderInstance, ChatRequest, ConnectivityProbe } from './registry'
|
|
9
|
+
import { UNNAMED_TOOL_CALL } from '../shared/constants'
|
|
9
10
|
import {
|
|
10
11
|
fetchWithRetry,
|
|
11
12
|
streamIdleTimeoutMs,
|
|
@@ -326,7 +327,12 @@ export class AnthropicProvider implements ProviderInstance {
|
|
|
326
327
|
// tool_calls 落在同一个响应体里)。**这是有意的不对称,不是漏做**:
|
|
327
328
|
// 要在这里丢弃,就得把 `tool_use` 缓冲到 `message_stop` 再发 ——
|
|
328
329
|
// 那是一次行为变更,不属本次范围。
|
|
329
|
-
|
|
330
|
+
// A named call needs accumulated input (the old shape). A *nameless*
|
|
331
|
+
// block is malformed on its own, so it is emitted regardless of
|
|
332
|
+
// whether any input arrived: dropping it left the turn as a silent
|
|
333
|
+
// short answer with nothing for the model to correct (331-038).
|
|
334
|
+
const nameless = !!currentToolId && !currentToolName
|
|
335
|
+
if ((currentToolId && currentToolName && accumulatedToolInput) || nameless) {
|
|
330
336
|
// A replayed block carries the id it was first sent with, so the
|
|
331
337
|
// id is what tells a second call apart from the same call twice.
|
|
332
338
|
if (!emittedToolIds.has(currentToolId)) {
|
|
@@ -334,7 +340,7 @@ export class AnthropicProvider implements ProviderInstance {
|
|
|
334
340
|
|
|
335
341
|
let parsedInput: Record<string, unknown> = {}
|
|
336
342
|
try {
|
|
337
|
-
parsedInput = JSON.parse(accumulatedToolInput)
|
|
343
|
+
parsedInput = accumulatedToolInput ? JSON.parse(accumulatedToolInput) : {}
|
|
338
344
|
} catch (err) {
|
|
339
345
|
// Same tag as the OpenAI-compatible path: a bare fragment
|
|
340
346
|
// reaches the validator as "missing required parameter",
|
|
@@ -350,7 +356,7 @@ export class AnthropicProvider implements ProviderInstance {
|
|
|
350
356
|
toolUse: {
|
|
351
357
|
type: 'tool_use',
|
|
352
358
|
id: currentToolId,
|
|
353
|
-
name: currentToolName,
|
|
359
|
+
name: currentToolName || UNNAMED_TOOL_CALL,
|
|
354
360
|
input: parsedInput,
|
|
355
361
|
},
|
|
356
362
|
}
|
|
@@ -446,6 +452,44 @@ export class AnthropicProvider implements ProviderInstance {
|
|
|
446
452
|
return apiKey.length > 0 && apiKey.startsWith('sk-ant-')
|
|
447
453
|
}
|
|
448
454
|
|
|
455
|
+
/**
|
|
456
|
+
* Detailed reachability for `/doctor` (331-003).
|
|
457
|
+
*
|
|
458
|
+
* `healthCheck` above only inspects the key's shape — it never touches the
|
|
459
|
+
* network, so the "reachable" it backs is really "configured". This probe
|
|
460
|
+
* asks the API: any HTTP answer (200, 401, 404) proves the endpoint is there,
|
|
461
|
+
* and the status tells the user which problem they have.
|
|
462
|
+
*/
|
|
463
|
+
async probeConnectivity(): Promise<ConnectivityProbe> {
|
|
464
|
+
const apiKey = this.resolveApiKey(this.config.apiKey)
|
|
465
|
+
if (!apiKey) return { tested: false, ok: false, detail: 'no API key configured' }
|
|
466
|
+
const url = `${this.baseUrl}/models`
|
|
467
|
+
try {
|
|
468
|
+
const res = await fetchWithRetry(
|
|
469
|
+
url,
|
|
470
|
+
{
|
|
471
|
+
headers: {
|
|
472
|
+
'x-api-key': apiKey,
|
|
473
|
+
'anthropic-version': '2023-06-01',
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
{ timeout: 5000, maxRetries: 0 },
|
|
477
|
+
)
|
|
478
|
+
try {
|
|
479
|
+
await res.body?.cancel()
|
|
480
|
+
} catch {
|
|
481
|
+
/* body already gone */
|
|
482
|
+
}
|
|
483
|
+
return { tested: true, ok: true, detail: `HTTP ${res.status} from ${url}` }
|
|
484
|
+
} catch (err) {
|
|
485
|
+
return {
|
|
486
|
+
tested: true,
|
|
487
|
+
ok: false,
|
|
488
|
+
detail: `${err instanceof Error ? err.message : String(err)} (${url})`,
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
449
493
|
/**
|
|
450
494
|
* Mark the stable conversation prefix for prompt caching. The breakpoint is
|
|
451
495
|
* placed on the last block of the second-to-last message, leaving only the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process'
|
|
2
2
|
import type { ProviderConfig, ModelInfo, Message, StreamChunk } from '../shared/index.ts'
|
|
3
|
-
import type { ProviderInstance, ChatRequest } from './registry'
|
|
3
|
+
import type { ProviderInstance, ChatRequest, ConnectivityProbe } from './registry'
|
|
4
4
|
import {
|
|
5
5
|
fetchWithRetry,
|
|
6
6
|
streamIdleTimeoutMs,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
createAwakeTimer,
|
|
9
9
|
readErrorBody,
|
|
10
10
|
} from './fetch-utils'
|
|
11
|
-
import { OLLAMA_PRESET_MODELS } from '../shared/constants'
|
|
11
|
+
import { OLLAMA_PRESET_MODELS, UNNAMED_TOOL_CALL } from '../shared/constants'
|
|
12
12
|
import { toWellFormed } from '../shared/sanitize'
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -160,14 +160,17 @@ export class OpenAICompatProvider implements ProviderInstance {
|
|
|
160
160
|
const data = trimmed.slice(6)
|
|
161
161
|
if (data === '[DONE]') {
|
|
162
162
|
// Emit any pending tool calls before stopping
|
|
163
|
-
for (const [, tc] of pendingToolCalls) {
|
|
164
|
-
|
|
163
|
+
for (const [idx, tc] of pendingToolCalls) {
|
|
164
|
+
// A nameless call is still a call the model wrote. Dropping it made
|
|
165
|
+
// the turn end as a short answer with no explanation; the synthetic
|
|
166
|
+
// name reaches the engine's unknown-tool path, which returns an
|
|
167
|
+
// error result the model can act on (331-038).
|
|
165
168
|
yield {
|
|
166
169
|
type: 'tool_use',
|
|
167
170
|
toolUse: {
|
|
168
171
|
type: 'tool_use',
|
|
169
|
-
id: tc.id || `call_${Date.now()}`,
|
|
170
|
-
name: tc.name,
|
|
172
|
+
id: tc.id || `call_${Date.now()}_${idx}`,
|
|
173
|
+
name: tc.name || UNNAMED_TOOL_CALL,
|
|
171
174
|
input: this.safeParseJson(tc.arguments),
|
|
172
175
|
},
|
|
173
176
|
}
|
|
@@ -242,14 +245,15 @@ export class OpenAICompatProvider implements ProviderInstance {
|
|
|
242
245
|
|
|
243
246
|
if (choice.finish_reason === 'tool_calls') {
|
|
244
247
|
// Emit fully accumulated tool calls
|
|
245
|
-
for (const [, tc] of pendingToolCalls) {
|
|
246
|
-
|
|
248
|
+
for (const [idx, tc] of pendingToolCalls) {
|
|
249
|
+
// Same treatment as the `[DONE]` path above: a nameless call gets
|
|
250
|
+
// the synthetic name instead of being dropped on the floor.
|
|
247
251
|
yield {
|
|
248
252
|
type: 'tool_use',
|
|
249
253
|
toolUse: {
|
|
250
254
|
type: 'tool_use',
|
|
251
|
-
id: tc.id || `call_${Date.now()}`,
|
|
252
|
-
name: tc.name,
|
|
255
|
+
id: tc.id || `call_${Date.now()}_${idx}`,
|
|
256
|
+
name: tc.name || UNNAMED_TOOL_CALL,
|
|
253
257
|
input: this.safeParseJson(tc.arguments),
|
|
254
258
|
},
|
|
255
259
|
}
|
|
@@ -340,16 +344,9 @@ export class OpenAICompatProvider implements ProviderInstance {
|
|
|
340
344
|
|
|
341
345
|
async healthCheck(): Promise<boolean> {
|
|
342
346
|
try {
|
|
343
|
-
const
|
|
344
|
-
const baseUrl =
|
|
345
|
-
this.resolveEnvTemplate(
|
|
346
|
-
rawBase?.replace(/\/+$/, '') || '',
|
|
347
|
-
'OpenAI-compatible provider: baseUrl',
|
|
348
|
-
) || 'https://api.openai.com/v1'
|
|
349
|
-
const apiKey = this.resolveApiKey(this.config.apiKey)
|
|
350
|
-
// 5s timeout so a down endpoint doesn't hang health checks (v2.1.229 alignment)
|
|
347
|
+
const { url, apiKey } = this.modelsEndpoint()
|
|
351
348
|
const res = await fetchWithRetry(
|
|
352
|
-
|
|
349
|
+
url,
|
|
353
350
|
{ headers: { Authorization: `Bearer ${apiKey}` } },
|
|
354
351
|
{ timeout: 5000, maxRetries: 0 },
|
|
355
352
|
)
|
|
@@ -359,6 +356,48 @@ export class OpenAICompatProvider implements ProviderInstance {
|
|
|
359
356
|
}
|
|
360
357
|
}
|
|
361
358
|
|
|
359
|
+
/**
|
|
360
|
+
* Detailed reachability for `/doctor`. Unlike `healthCheck`, any HTTP answer
|
|
361
|
+
* counts as reachable: a 401 from a live endpoint means "the endpoint is
|
|
362
|
+
* here and refused this key", which is a different problem from "nothing
|
|
363
|
+
* answered".
|
|
364
|
+
*/
|
|
365
|
+
async probeConnectivity(): Promise<ConnectivityProbe> {
|
|
366
|
+
const { url, apiKey } = this.modelsEndpoint()
|
|
367
|
+
if (!apiKey) return { tested: false, ok: false, detail: 'no API key configured' }
|
|
368
|
+
try {
|
|
369
|
+
// 5s timeout so a down endpoint doesn't hang the doctor screen.
|
|
370
|
+
const res = await fetchWithRetry(
|
|
371
|
+
url,
|
|
372
|
+
{ headers: { Authorization: `Bearer ${apiKey}` } },
|
|
373
|
+
{ timeout: 5000, maxRetries: 0 },
|
|
374
|
+
)
|
|
375
|
+
try {
|
|
376
|
+
await res.body?.cancel()
|
|
377
|
+
} catch {
|
|
378
|
+
/* body already gone */
|
|
379
|
+
}
|
|
380
|
+
return { tested: true, ok: true, detail: `HTTP ${res.status} from ${url}` }
|
|
381
|
+
} catch (err) {
|
|
382
|
+
return {
|
|
383
|
+
tested: true,
|
|
384
|
+
ok: false,
|
|
385
|
+
detail: `${err instanceof Error ? err.message : String(err)} (${url})`,
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** `/models` on the configured base — the one endpoint both checks share. */
|
|
391
|
+
private modelsEndpoint(): { url: string; apiKey: string } {
|
|
392
|
+
const rawBase = (this.config as any).baseUrl || (this.config as any).baseURL
|
|
393
|
+
const baseUrl =
|
|
394
|
+
this.resolveEnvTemplate(
|
|
395
|
+
rawBase?.replace(/\/+$/, '') || '',
|
|
396
|
+
'OpenAI-compatible provider: baseUrl',
|
|
397
|
+
) || 'https://api.openai.com/v1'
|
|
398
|
+
return { url: `${baseUrl}/models`, apiKey: this.resolveApiKey(this.config.apiKey) }
|
|
399
|
+
}
|
|
400
|
+
|
|
362
401
|
private convertMessages(messages: Message[], systemPrompt?: string): Record<string, unknown>[] {
|
|
363
402
|
const result: Record<string, unknown>[] = []
|
|
364
403
|
|
|
@@ -43,11 +43,27 @@ export function resolveClassifierModel(
|
|
|
43
43
|
return choice
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Detail behind a reachability check, for `/doctor` (331-003).
|
|
48
|
+
*
|
|
49
|
+
* `healthCheck` answers a boolean the status line consumes; it cannot say *what*
|
|
50
|
+
* happened. This shape can: `tested: false` means the check was skipped and
|
|
51
|
+
* `detail` is the reason (no key, no endpoint), never a silent "unreachable".
|
|
52
|
+
*/
|
|
53
|
+
export interface ConnectivityProbe {
|
|
54
|
+
tested: boolean
|
|
55
|
+
/** Reachability, not authentication: any HTTP response means the endpoint answered. */
|
|
56
|
+
ok: boolean
|
|
57
|
+
detail: string
|
|
58
|
+
}
|
|
59
|
+
|
|
46
60
|
export interface ProviderInstance {
|
|
47
61
|
config: ProviderConfig
|
|
48
62
|
chat(req: ChatRequest): AsyncGenerator<StreamChunk>
|
|
49
63
|
listModels(): Promise<ModelInfo[]>
|
|
50
64
|
healthCheck(): Promise<boolean>
|
|
65
|
+
/** Optional detailed probe; `healthCheck` remains the only required contract. */
|
|
66
|
+
probeConnectivity?(): Promise<ConnectivityProbe>
|
|
51
67
|
}
|
|
52
68
|
|
|
53
69
|
export interface ChatRequest {
|
|
@@ -164,6 +180,31 @@ export class ProviderRegistry implements Llm {
|
|
|
164
180
|
}
|
|
165
181
|
}
|
|
166
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Detailed reachability for `/doctor`. Falls back to the boolean health check
|
|
185
|
+
* when a provider has no probe, and says so — "reachable" with no detail is
|
|
186
|
+
* still information; "unreachable" invented from a missing method is not.
|
|
187
|
+
*/
|
|
188
|
+
async probeConnectivity(id: string): Promise<ConnectivityProbe | undefined> {
|
|
189
|
+
const provider = this.providers.get(id)
|
|
190
|
+
if (!provider) return undefined
|
|
191
|
+
if (provider.probeConnectivity) {
|
|
192
|
+
try {
|
|
193
|
+
return await provider.probeConnectivity()
|
|
194
|
+
} catch (err) {
|
|
195
|
+
return {
|
|
196
|
+
tested: true,
|
|
197
|
+
ok: false,
|
|
198
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const ok = await this.healthStatus(id)
|
|
203
|
+
return ok === undefined
|
|
204
|
+
? undefined
|
|
205
|
+
: { tested: false, ok, detail: 'this provider has no detailed probe' }
|
|
206
|
+
}
|
|
207
|
+
|
|
167
208
|
/**
|
|
168
209
|
* Health of all registered providers, checked concurrently.
|
|
169
210
|
* Returns a Map of provider id → reachable boolean.
|
package/src/shared/constants.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { ProviderConfig, ModelInfo } from './types'
|
|
2
2
|
import miphamModelsSnapshot from './mipham-models.json' with { type: 'json' }
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Synthetic tool name for a provider response that carried a tool call with no
|
|
6
|
+
* name (a custom endpoint, or a malformed stream).
|
|
7
|
+
*
|
|
8
|
+
* Dropping such a call silently left the turn looking like a short answer: the
|
|
9
|
+
* model wrote a call, nothing dispatched, and the user got no explanation. Give
|
|
10
|
+
* it a name so the ordinary "Unknown tool" path hands the model an error result
|
|
11
|
+
* it can correct on the next round — the turn continues instead of vanishing.
|
|
12
|
+
*/
|
|
13
|
+
export const UNNAMED_TOOL_CALL = '(tool call without a name)'
|
|
14
|
+
|
|
4
15
|
// Build MiphamAI provider from synced model definitions.
|
|
5
16
|
// Source of truth: Engine GET /v1/mipham-models → packages/shared/src/mipham-models.json
|
|
6
17
|
// Run `bun run scripts/sync-mipham-models.ts` to update from Engine.
|
|
@@ -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.45' as const
|
|
13
13
|
|
|
14
14
|
/** npm install 全局安装命令 */
|
|
15
15
|
export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` as const
|
|
@@ -75,7 +75,7 @@ export const COMPANY_SHORT = '华安麦逄科技' as const
|
|
|
75
75
|
*/
|
|
76
76
|
|
|
77
77
|
/** Slash 命令总数(真源:`getCommandNames().length`,`apps/cli/src/ui/commands.ts`) */
|
|
78
|
-
export const SLASH_COMMAND_COUNT =
|
|
78
|
+
export const SLASH_COMMAND_COUNT = 141 as const
|
|
79
79
|
|
|
80
80
|
/** 内置提供商总数(真源:`DEFAULT_PROVIDERS.length`,`apps/cli/src/shared/constants.ts`) */
|
|
81
81
|
export const PROVIDER_COUNT = 12 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 = 5195 as const
|
package/src/shared/sanitize.ts
CHANGED
|
@@ -311,6 +311,23 @@ export function safeSlice(text: string, max: number): string {
|
|
|
311
311
|
return text.slice(0, end)
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
+
/**
|
|
315
|
+
* `safeSlice` for **display only** — appends `…` when it actually cut something.
|
|
316
|
+
*
|
|
317
|
+
* A bare `safeSlice` at a render site leaves a long tool result looking like the
|
|
318
|
+
* whole output: the reader has no way to tell "the tool said this" from "the
|
|
319
|
+
* tool said more and we stopped". Never use this where the string is stored or
|
|
320
|
+
* sent (session JSONL, tool arguments, prompts) — the ellipsis would become part
|
|
321
|
+
* of the data. `safeSlice` remains the right call there.
|
|
322
|
+
*/
|
|
323
|
+
export function safeSliceWithEllipsis(text: string, max: number): string {
|
|
324
|
+
const clipped = safeSlice(text, max)
|
|
325
|
+
// `max <= 0` means "show nothing", not "show an ellipsis" — and an empty input
|
|
326
|
+
// cannot have been cut.
|
|
327
|
+
if (max <= 0 || clipped === text) return clipped
|
|
328
|
+
return `${clipped}…`
|
|
329
|
+
}
|
|
330
|
+
|
|
314
331
|
/**
|
|
315
332
|
* Replace lone UTF-16 surrogates with U+FFFD, leaving valid pairs untouched.
|
|
316
333
|
*
|
package/src/ui/chat.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { useI18n } from '../i18n-context'
|
|
|
4
4
|
import type { ChatMessage } from './app'
|
|
5
5
|
import {
|
|
6
6
|
decodeDisplayEntities,
|
|
7
|
-
|
|
7
|
+
safeSliceWithEllipsis,
|
|
8
8
|
sanitizeInlineField,
|
|
9
9
|
stripControlCharsForDisplay,
|
|
10
10
|
} from '../shared/sanitize'
|
|
@@ -123,7 +123,9 @@ const MessageRow = React.memo(
|
|
|
123
123
|
{msg.toolMeta.name ? (
|
|
124
124
|
<Text color={toolColor(msg.toolMeta.name)}>
|
|
125
125
|
{msg.toolMeta.collapsed ? '⏺' : '⏺ ▼'} {sanitizeInlineField(msg.toolMeta.name)}
|
|
126
|
-
{msg.toolMeta.input
|
|
126
|
+
{msg.toolMeta.input
|
|
127
|
+
? ` (${safeSliceWithEllipsis(display(msg.toolMeta.input), 120)})`
|
|
128
|
+
: ''}
|
|
127
129
|
</Text>
|
|
128
130
|
) : null}
|
|
129
131
|
{/* Tool result line: ⎿ summary text */}
|
|
@@ -134,7 +136,9 @@ const MessageRow = React.memo(
|
|
|
134
136
|
<Text dimColor>
|
|
135
137
|
{' ⎿ '}
|
|
136
138
|
{t('ui.tool.not_run')}
|
|
137
|
-
{msg.toolMeta.output
|
|
139
|
+
{msg.toolMeta.output
|
|
140
|
+
? ` — ${safeSliceWithEllipsis(display(msg.toolMeta.output), 300)}`
|
|
141
|
+
: ''}
|
|
138
142
|
</Text>
|
|
139
143
|
) : msg.toolMeta.noResult ? (
|
|
140
144
|
// The call ended without output. Saying so is the point: an empty
|
|
@@ -147,7 +151,7 @@ const MessageRow = React.memo(
|
|
|
147
151
|
) : msg.toolMeta.output ? (
|
|
148
152
|
<Text dimColor>
|
|
149
153
|
{' ⎿ '}
|
|
150
|
-
{
|
|
154
|
+
{safeSliceWithEllipsis(display(msg.toolMeta.output), 300)}
|
|
151
155
|
</Text>
|
|
152
156
|
) : msg.content && !msg.toolMeta.collapsed ? (
|
|
153
157
|
<Text dimColor>{display(msg.content)}</Text>
|
package/src/ui/commands.ts
CHANGED
|
@@ -140,7 +140,7 @@ import {
|
|
|
140
140
|
trustCmd,
|
|
141
141
|
} from '../commands/project.js'
|
|
142
142
|
import { releaseNotesCmd, ideCmd, terminalSetupCmd } from '../commands/environment.js'
|
|
143
|
-
import { commitCmd, pushCmd, prCmd, issueCmd } from '../commands/git.js'
|
|
143
|
+
import { commitCmd, pushCmd, prCmd, issueCmd, shipCmd } from '../commands/git.js'
|
|
144
144
|
import { suggestDirectories } from '../commands/cd-suggest.js'
|
|
145
145
|
import { keysCmd } from '../commands/keys'
|
|
146
146
|
import { workflowViewCmd, workflowWatchCmd } from '../commands/workflow-view.js'
|
|
@@ -4150,10 +4150,48 @@ const doctorCmd: CommandHandler = async (ctx) => {
|
|
|
4150
4150
|
`Provider ${ctx.providerId} / ${ctx.modelId}`,
|
|
4151
4151
|
`Permission ${liveMode(ctx)}`,
|
|
4152
4152
|
`Providers ${ctx.config.providers.length} configured (${ctx.config.providers.filter((p) => p.status !== 'upcoming').length} active)`,
|
|
4153
|
-
'',
|
|
4154
|
-
t('commands.doctor.session_section'),
|
|
4155
4153
|
]
|
|
4156
4154
|
|
|
4155
|
+
// ── API connectivity (331-003) ──
|
|
4156
|
+
// A boolean status line cannot tell "the endpoint answered 401" from "nothing
|
|
4157
|
+
// answered". Ask the provider for the detail, and name the three non-answers
|
|
4158
|
+
// (no registry, upcoming provider, untested probe) instead of rendering them
|
|
4159
|
+
// as a red dot.
|
|
4160
|
+
lines.push('')
|
|
4161
|
+
lines.push(t('commands.doctor.api_section'))
|
|
4162
|
+
const registry = ctx.engine.getRegistry?.()
|
|
4163
|
+
const activeConfig = ctx.config.providers.find((p) => p.id === ctx.providerId)
|
|
4164
|
+
lines.push(t('commands.doctor.api_target', { provider: ctx.providerId, model: ctx.modelId }))
|
|
4165
|
+
if (!registry) {
|
|
4166
|
+
lines.push(
|
|
4167
|
+
t('commands.doctor.api_not_tested', { reason: 'no provider registry in this session' }),
|
|
4168
|
+
)
|
|
4169
|
+
} else if (typeof registry.probeConnectivity !== 'function') {
|
|
4170
|
+
// A daemon proxy exposes a narrower registry; say the probe is unavailable
|
|
4171
|
+
// rather than calling a method that is not there.
|
|
4172
|
+
lines.push(
|
|
4173
|
+
t('commands.doctor.api_not_tested', { reason: 'this registry has no connectivity probe' }),
|
|
4174
|
+
)
|
|
4175
|
+
} else if (!activeConfig || activeConfig.status === 'upcoming') {
|
|
4176
|
+
lines.push(
|
|
4177
|
+
t('commands.doctor.api_not_tested', { reason: 'the active provider is not configured' }),
|
|
4178
|
+
)
|
|
4179
|
+
} else {
|
|
4180
|
+
const probe = await registry.probeConnectivity(ctx.providerId)
|
|
4181
|
+
if (!probe) {
|
|
4182
|
+
lines.push(t('commands.doctor.api_not_tested', { reason: 'provider not registered' }))
|
|
4183
|
+
} else if (!probe.tested) {
|
|
4184
|
+
lines.push(t('commands.doctor.api_not_tested', { reason: probe.detail }))
|
|
4185
|
+
} else if (probe.ok) {
|
|
4186
|
+
lines.push(t('commands.doctor.api_reachable', { detail: probe.detail }))
|
|
4187
|
+
} else {
|
|
4188
|
+
lines.push(t('commands.doctor.api_unreachable', { detail: probe.detail }))
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
4191
|
+
|
|
4192
|
+
lines.push('')
|
|
4193
|
+
lines.push(t('commands.doctor.session_section'))
|
|
4194
|
+
|
|
4157
4195
|
const c = ctx.engine.getContext()
|
|
4158
4196
|
const tokens = c.getEstimatedTokens()
|
|
4159
4197
|
const maxTokens = c.getMaxTokens()
|
|
@@ -6994,6 +7032,7 @@ const commandsListCmd: CommandHandler = () => {
|
|
|
6994
7032
|
'/commit': 'Workflow',
|
|
6995
7033
|
'/push': 'Workflow',
|
|
6996
7034
|
'/pr': 'Workflow',
|
|
7035
|
+
'/ship': 'Workflow',
|
|
6997
7036
|
'/issue': 'Workflow',
|
|
6998
7037
|
'/code-review': 'Code Quality',
|
|
6999
7038
|
'/simplify': 'Code Quality',
|
|
@@ -7241,6 +7280,7 @@ registry.set('/schedule', scheduleCmd)
|
|
|
7241
7280
|
registry.set('/commit', commitCmd)
|
|
7242
7281
|
registry.set('/push', pushCmd)
|
|
7243
7282
|
registry.set('/pr', prCmd)
|
|
7283
|
+
registry.set('/ship', shipCmd)
|
|
7244
7284
|
registry.set('/issue', issueCmd)
|
|
7245
7285
|
|
|
7246
7286
|
// Code Quality (Claude Code parity)
|
|
@@ -7455,6 +7495,7 @@ const COMMAND_DESCRIPTIONS: Record<string, string> = {
|
|
|
7455
7495
|
'/commit': 'Draft a commit message from staged changes',
|
|
7456
7496
|
'/push': 'Show push status and the command to run',
|
|
7457
7497
|
'/pr': 'Draft a pull request title and body',
|
|
7498
|
+
'/ship': 'Commit, push, open a PR, review and fix it — never merges',
|
|
7458
7499
|
'/issue': 'Draft a GitHub issue from your description',
|
|
7459
7500
|
'/code-review': 'Review code for bugs, security, performance (7 dimensions)',
|
|
7460
7501
|
'/simplify': 'Cleanup-only review: reuse, simplification, efficiency, abstraction',
|