@miphamai/cli 0.85.14 → 0.85.16

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.
@@ -14,7 +14,7 @@ import type { PluginManager } from '../plugin/plugin-manager'
14
14
  import type { Message } from '../shared/types.js'
15
15
  import type { InstallState, UpdateStatus } from '../shared/update'
16
16
  import { McpClient } from '../mcp/client'
17
- import { unregisterMcpServerTools } from '../mcp/registry'
17
+ import { registerMcpServerTools, unregisterMcpServerTools } from '../mcp/registry'
18
18
  import { buildCapabilityReport } from '../core/capability-inventory'
19
19
  import { InstructionsLoader } from '../core/instructions'
20
20
  import { findDerivableSections, DERIVABLE_HINTS } from '../core/claude-md-audit'
@@ -70,7 +70,7 @@ import {
70
70
  shouldBlockApproval,
71
71
  } from '../core/improvement-track'
72
72
  import { NPM_UPDATE_COMMAND, PACKAGE_VERSION, COAUTHOR_TRAILER } from '../shared/index.ts'
73
- import { getPreference } from '../config/preferences'
73
+ import { getPreference, setPreference } from '../config/preferences'
74
74
  import { loadCrossSessionConfig, tryRestoreFromBackup } from '../config/loader'
75
75
  import { getWorkspaceTrust } from '../core/workspace-trust'
76
76
  import { getMemoryManager } from '../core/memory/memory-loader'
@@ -128,7 +128,6 @@ export interface CommandContext {
128
128
  sessionId: string
129
129
  // Callbacks for commands that mutate App state
130
130
  setSessionTitle: (title: string) => void
131
- setFastMode: (on: boolean) => void
132
131
  setEffort: (level: string) => void
133
132
  setFocusMode: (on: boolean) => void
134
133
  setGoal: (text: string) => void
@@ -225,7 +224,6 @@ const helpCmd: CommandHandler = (ctx) => {
225
224
  /providers List configured providers
226
225
  /switch <p> <m> Switch provider and model
227
226
  /config View configuration
228
- /fast [on|off] Toggle fast mode
229
227
  /effort <lvl> Set reasoning effort (low|medium|high|xhigh|max)
230
228
  /theme [dark|light|auto] Set terminal theme
231
229
  /ollama-refresh Refresh Ollama model list at runtime
@@ -2954,22 +2952,6 @@ const diffCmd: CommandHandler = async (_ctx) => {
2954
2952
  // Phase 1 — Model Control Commands
2955
2953
  // ═══════════════════════════════════════════════════════════════
2956
2954
 
2957
- const fastCmd: CommandHandler = (ctx, args) => {
2958
- const t = resolveT(ctx)
2959
- const arg = args[0]?.toLowerCase()
2960
- if (arg === 'on') {
2961
- ctx.setFastMode(true)
2962
- return { content: t('commands.fast.on') }
2963
- } else if (arg === 'off') {
2964
- ctx.setFastMode(false)
2965
- return { content: t('commands.fast.off') }
2966
- } else if (arg) {
2967
- return { content: t('commands.fast.usage') }
2968
- } else {
2969
- return { content: t('commands.fast.unknown') }
2970
- }
2971
- }
2972
-
2973
2955
  const effortCmd: CommandHandler = (ctx, args) => {
2974
2956
  const t = resolveT(ctx)
2975
2957
  const VALID_LEVELS = ['low', 'medium', 'high', 'xhigh', 'max']
@@ -3687,9 +3669,13 @@ function gitDiffBridgeCmd(opts: {
3687
3669
  noChangesKey: string
3688
3670
  runningKey: string
3689
3671
  errorKey: string
3690
- forwardToAI: string | (() => string)
3672
+ /** Either a fixed prompt, or a builder that reads the command args. A builder
3673
+ * may return an `{ error }` envelope instead — used when the args are
3674
+ * unusable, so the command reports that rather than forwarding a prompt the
3675
+ * user's flag never reached. */
3676
+ forwardToAI: string | ((args: string[]) => string | { error: string })
3691
3677
  }): CommandHandler {
3692
- return async (ctx) => {
3678
+ return async (ctx, args) => {
3693
3679
  const t = resolveT(ctx)
3694
3680
  try {
3695
3681
  const { execSync } = await import('node:child_process')
@@ -3697,9 +3683,14 @@ function gitDiffBridgeCmd(opts: {
3697
3683
  if (!diff) {
3698
3684
  return { content: `─ ${opts.label} ─\n\n${t(opts.noChangesKey)}` }
3699
3685
  }
3686
+ const forwarded =
3687
+ typeof opts.forwardToAI === 'function' ? opts.forwardToAI(args) : opts.forwardToAI
3688
+ if (typeof forwarded === 'object') {
3689
+ return { content: `─ ${opts.label} ─\n\n${forwarded.error}` }
3690
+ }
3700
3691
  return {
3701
3692
  content: `─ ${opts.label} ─\n\n${t(opts.runningKey)}\n\nChanged files:\n${diff}`,
3702
- forwardToAI: typeof opts.forwardToAI === 'function' ? opts.forwardToAI() : opts.forwardToAI,
3693
+ forwardToAI: forwarded,
3703
3694
  }
3704
3695
  } catch {
3705
3696
  return { content: `─ ${opts.label} ─\n\n${t(opts.errorKey)}` }
@@ -3707,13 +3698,60 @@ function gitDiffBridgeCmd(opts: {
3707
3698
  }
3708
3699
  }
3709
3700
 
3701
+ /**
3702
+ * `/code-review --max-findings <n>|all|default` — how many findings to report.
3703
+ *
3704
+ * The choice is persisted like the effort level and reused by the next
3705
+ * `/code-review` until `--max-findings default` restores the usual limit.
3706
+ * `all` means "no cap"; a positive integer caps the count. An unusable value is
3707
+ * reported back rather than ignored: silently dropping it would leave the user
3708
+ * believing the cap took effect when it never left the command line.
3709
+ */
3710
+ function resolveMaxFindings(
3711
+ args: string[],
3712
+ ): { ok: true; value: string } | { ok: false; error: string } {
3713
+ let token: string | undefined
3714
+ for (let i = 0; i < args.length; i++) {
3715
+ const a = args[i]!
3716
+ if (a === '--max-findings') {
3717
+ token = args[i + 1]
3718
+ break
3719
+ }
3720
+ if (a.startsWith('--max-findings=')) {
3721
+ token = a.slice('--max-findings='.length)
3722
+ break
3723
+ }
3724
+ }
3725
+ if (token === undefined) {
3726
+ // No flag this time — reuse whatever was chosen last.
3727
+ return { ok: true, value: getPreference('lastCodeReviewMaxFindings', 'default') }
3728
+ }
3729
+ if (token === 'all' || token === 'default' || /^[1-9]\d*$/.test(token)) {
3730
+ setPreference('lastCodeReviewMaxFindings', token)
3731
+ return { ok: true, value: token }
3732
+ }
3733
+ return {
3734
+ ok: false,
3735
+ error: `--max-findings expects a positive integer, "all", or "default" (got "${token}")`,
3736
+ }
3737
+ }
3738
+
3710
3739
  const codeReviewCmd = gitDiffBridgeCmd({
3711
3740
  label: 'Code Review',
3712
3741
  noChangesKey: 'commands.code_review.no_changes',
3713
3742
  runningKey: 'commands.code_review.running',
3714
3743
  errorKey: 'commands.code_review.error',
3715
- forwardToAI: () =>
3716
- `use the code-review skill to review all uncommitted changes. Check all 7 dimensions: correctness, security, performance, code quality, architecture & design, testing, and language-specific issues. Use effort level: ${getPreference('lastCodeReviewEffort', 'high')}.`,
3744
+ forwardToAI: (args) => {
3745
+ const maxFindings = resolveMaxFindings(args)
3746
+ if (!maxFindings.ok) return { error: maxFindings.error }
3747
+ const cap =
3748
+ maxFindings.value === 'all'
3749
+ ? ' Report every finding, however many there are.'
3750
+ : maxFindings.value === 'default'
3751
+ ? ''
3752
+ : ` Report at most ${maxFindings.value} findings, most severe first.`
3753
+ return `use the code-review skill to review all uncommitted changes. Check all 7 dimensions: correctness, security, performance, code quality, architecture & design, testing, and language-specific issues. Use effort level: ${getPreference('lastCodeReviewEffort', 'high')}.${cap}`
3754
+ },
3717
3755
  })
3718
3756
 
3719
3757
  const simplifyCmd = gitDiffBridgeCmd({
@@ -4952,31 +4990,53 @@ const mcpCmd: CommandHandler = async (ctx, args) => {
4952
4990
  content: `Server "${sanitizeInlineField(name)}" not found in config.\n\nConfigured: ${mcpServers.map((s) => sanitizeInlineField(s.name)).join(', ') || '(none)'}`,
4953
4991
  }
4954
4992
  }
4955
- if (config.auth?.type === 'oauth') {
4993
+ const isOAuth = config.auth?.type === 'oauth'
4994
+ const label = isOAuth ? `${name} (OAuth)` : name
4995
+ try {
4996
+ // Connect here rather than handing the AI a prompt to "call
4997
+ // McpClient.getInstance().connect(config)". No tool exposes that call, so
4998
+ // the prompt was unactionable and the command connected nothing — it just
4999
+ // printed a status line. `/mcp reconnect` already awaits in the handler;
5000
+ // this is the same shape.
5001
+ //
5002
+ // An already-connected OAuth server is the re-authenticate case: the only
5003
+ // reason to ask again is that the current token was refused.
5004
+ if (isOAuth && client.getConnection(name)?.status === 'connected') {
5005
+ await client.reauthenticate(config)
5006
+ } else {
5007
+ await client.connect(config)
5008
+ }
5009
+ const registered = registerMcpServerTools(name, ctx.engine.getTools())
5010
+ const lines = [`── MCP Connect: ${sanitizeInlineField(label)} ──`, '']
5011
+ lines.push(
5012
+ isOAuth
5013
+ ? 'Authenticated via OAuth PKCE.'
5014
+ : `Connected via ${config.url ? 'HTTP' : 'stdio'}.`,
5015
+ )
5016
+ lines.push(
5017
+ registered > 0 ? `${registered} tool(s) registered.` : 'No tools reported by the server.',
5018
+ )
5019
+ if (config.url) {
5020
+ const headerKeys = config.headers ? Object.keys(config.headers) : []
5021
+ if (headerKeys.length > 0) {
5022
+ lines.push('')
5023
+ lines.push(
5024
+ `⚠️ These headers were sent to ${sanitizeInlineField(config.url)}: ${headerKeys.join(', ')}`,
5025
+ )
5026
+ }
5027
+ }
5028
+ return { content: lines.join('\n') }
5029
+ } catch (err) {
4956
5030
  return {
4957
5031
  content: [
4958
- `── MCP Connect: ${name} (OAuth) ──`,
5032
+ `── MCP Connect: ${sanitizeInlineField(label)} ──`,
5033
+ '',
5034
+ `Failed: ${sanitizeInlineField(String(err))}`,
4959
5035
  '',
4960
- 'Starting OAuth PKCE flow...',
4961
- `Authorization: ${config.auth.authorizationUrl}`,
4962
- `Scopes: ${config.auth.scopes?.join(', ') || '(default)'}`,
5036
+ `Check the server with /mcp, or retry with backoff: /mcp reconnect ${sanitizeInlineField(name)}`,
4963
5037
  ].join('\n'),
4964
- forwardToAI: `Connect to MCP server "${name}" using OAuth. Call McpClient.getInstance().connectWithOAuth() with the server config, then register its tools. Report the result.`,
4965
5038
  }
4966
5039
  }
4967
- const via = config.url ? 'HTTP' : 'stdio'
4968
- if (config.url) {
4969
- const headerKeys = config.headers ? Object.keys(config.headers) : []
4970
- const headerLine = headerKeys.length > 0 ? `\nHeaders to send: ${headerKeys.join(', ')}` : ''
4971
- return {
4972
- content: `── MCP Connect: ${sanitizeInlineField(name)} ──\n\nConnecting via HTTP\nURL: ${sanitizeInlineField(config.url)}${headerLine}\n\n⚠️ Verify the URL — any configured headers (e.g. Authorization) will be sent to this server.`,
4973
- forwardToAI: `Connect to MCP server "${name}" using McpClient.getInstance().connect(config), then register its tools. Report the result.`,
4974
- }
4975
- }
4976
- return {
4977
- content: `── MCP Connect: ${name} ──\n\nConnecting via ${via}...`,
4978
- forwardToAI: `Connect to MCP server "${name}" using McpClient.getInstance().connect(config), then register its tools. Report the result.`,
4979
- }
4980
5040
  }
4981
5041
 
4982
5042
  // /mcp disconnect <name>
@@ -5030,11 +5090,37 @@ const mcpCmd: CommandHandler = async (ctx, args) => {
5030
5090
 
5031
5091
  // /mcp reload
5032
5092
  if (sub === 'reload') {
5033
- return {
5034
- content: '── MCP Reload ──\n\nDisconnecting all and reconnecting...',
5035
- forwardToAI:
5036
- 'Disconnect all MCP servers via McpClient.getInstance().closeAll(), then reconnect all configured servers. Report each status.',
5093
+ const mcpServers = ctx.config.skills?.mcpServers ?? []
5094
+ // Same defect `/mcp connect` had: the forwarded prompt told the AI to call
5095
+ // `McpClient.getInstance().closeAll()` — an internal method no tool exposes —
5096
+ // so the command disconnected and reconnected nothing, it only printed a
5097
+ // status line. Do the work in the handler, like `/mcp reconnect` already does.
5098
+ await client.closeAll()
5099
+ // `closeAll()` nulls the singleton, so the reference captured above is spent.
5100
+ const fresh = McpClient.getInstance()
5101
+
5102
+ if (mcpServers.length === 0) {
5103
+ return { content: '── MCP Reload ──\n\nNo MCP servers configured.' }
5037
5104
  }
5105
+
5106
+ const toolsMap = ctx.engine.getTools()
5107
+ const lines: string[] = ['── MCP Reload ──', '']
5108
+ for (const config of mcpServers) {
5109
+ // Tools live in the engine registry, not in the connection: drop them before
5110
+ // reconnecting so a server that no longer offers a tool does not leave a
5111
+ // dead entry registered.
5112
+ unregisterMcpServerTools(config.name, toolsMap)
5113
+ try {
5114
+ await fresh.connect(config)
5115
+ const registered = registerMcpServerTools(config.name, toolsMap)
5116
+ lines.push(`🟢 ${sanitizeInlineField(config.name)} — ${registered} tool(s) registered.`)
5117
+ } catch (err) {
5118
+ lines.push(
5119
+ `🔴 ${sanitizeInlineField(config.name)} — Failed: ${sanitizeInlineField(String(err))}`,
5120
+ )
5121
+ }
5122
+ }
5123
+ return { content: lines.join('\n') }
5038
5124
  }
5039
5125
 
5040
5126
  // /mcp (default status)
@@ -5739,7 +5825,6 @@ const commandsListCmd: CommandHandler = () => {
5739
5825
  '/providers': 'Model & Provider',
5740
5826
  '/switch': 'Model & Provider',
5741
5827
  '/config': 'Model & Provider',
5742
- '/fast': 'Model & Provider',
5743
5828
  '/effort': 'Model & Provider',
5744
5829
  '/theme': 'Model & Provider',
5745
5830
  '/upgrade': 'Model & Provider',
@@ -5901,7 +5986,6 @@ registry.set('/ollama-refresh', ollamaRefreshCmd)
5901
5986
  registry.set('/provider', providerCmd)
5902
5987
  registry.set('/providers', providersCmd)
5903
5988
  registry.set('/config', configCmd)
5904
- registry.set('/fast', fastCmd)
5905
5989
  registry.set('/effort', effortCmd)
5906
5990
  registry.set('/switch', switchCmd)
5907
5991
 
@@ -6135,7 +6219,6 @@ const COMMAND_DESCRIPTIONS: Record<string, string> = {
6135
6219
  '/providers': 'List configured providers',
6136
6220
  '/switch': 'Switch provider and model',
6137
6221
  '/config': 'View configuration',
6138
- '/fast': 'Toggle fast mode',
6139
6222
  '/effort': 'Set reasoning effort',
6140
6223
  '/theme': 'Set terminal theme',
6141
6224
  '/lang': 'Set display language (en-US, zh-CN)',