@miphamai/cli 0.85.53 → 0.85.55
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 +6 -6
- package/src/agent/agent-registry.ts +17 -2
- package/src/agent/sub-agent.ts +18 -2
- package/src/agent/types.ts +9 -0
- package/src/commands/environment.ts +71 -35
- package/src/commands/project.ts +31 -0
- package/src/config/loader.ts +112 -3
- package/src/core/command-taps.ts +10 -0
- package/src/core/credential-masker/matcher.ts +38 -0
- package/src/core/engine.ts +351 -6
- package/src/core/hooks.ts +18 -7
- package/src/core/instructions.ts +17 -3
- package/src/core/review-gate.ts +192 -0
- package/src/core/rules-loader.ts +4 -1
- package/src/core/session-insights.ts +8 -2
- package/src/core/session-store.ts +30 -23
- package/src/core/task-performance-tasks.json +18 -0
- package/src/core/verification-baseline.ts +277 -0
- package/src/core/write-paths.ts +19 -0
- package/src/daemon/engine-capabilities.ts +22 -1
- package/src/daemon/launch.ts +11 -1
- package/src/i18n-core/locales/en-US.json +9 -1
- package/src/i18n-core/locales/zh-CN.json +9 -1
- package/src/index.tsx +35 -3
- package/src/mcp/transport.ts +35 -3
- package/src/providers/anthropic.ts +17 -1
- package/src/providers/openai-compat.ts +13 -1
- package/src/shared/package-info.ts +2 -2
- package/src/shared/types.ts +11 -0
- package/src/skills/fork-executor.ts +3 -2
- package/src/skills/loader.ts +9 -2
- package/src/tools/agent/skill.ts +1 -0
- package/src/tools/agent/workflow.ts +3 -0
- package/src/tools/exec/task.ts +41 -0
- package/src/tools/file/grep.ts +30 -1
- package/src/tools/network/web-fetch.ts +11 -2
- package/src/ui/chat.tsx +17 -0
- package/src/ui/commands.ts +280 -29
- package/src/ui/picker.tsx +120 -19
- package/src/workflow/primitives/agent.ts +10 -1
- package/src/workflow/runtime.ts +49 -0
package/src/ui/commands.ts
CHANGED
|
@@ -27,6 +27,8 @@ import { miphamHome, workflowScriptDir, workflowScriptDirs, worktreeRoot } from
|
|
|
27
27
|
import { fixDoctor, fixConfig, fixCache, selectRepoClaudeFiles } from '../core/fix'
|
|
28
28
|
import { fixCodeTarget } from '../core/fix-code'
|
|
29
29
|
import { homedir } from 'node:os'
|
|
30
|
+
import { readFileSync } from 'node:fs'
|
|
31
|
+
import { join } from 'node:path'
|
|
30
32
|
import {
|
|
31
33
|
runCrsiModification,
|
|
32
34
|
approvePending,
|
|
@@ -110,7 +112,12 @@ import {
|
|
|
110
112
|
} from '../core/improvement-track'
|
|
111
113
|
import { NPM_UPDATE_COMMAND, PACKAGE_VERSION, COAUTHOR_TRAILER } from '../shared/index.ts'
|
|
112
114
|
import { getPreference, setPreference } from '../config/preferences'
|
|
113
|
-
import {
|
|
115
|
+
import {
|
|
116
|
+
loadCrossSessionConfig,
|
|
117
|
+
tryRestoreFromBackup,
|
|
118
|
+
loadDisabledMcpServers,
|
|
119
|
+
saveDisabledMcpServers,
|
|
120
|
+
} from '../config/loader'
|
|
114
121
|
import { getWorkspaceTrust } from '../core/workspace-trust'
|
|
115
122
|
import { getMemoryManager } from '../core/memory/memory-loader'
|
|
116
123
|
import { auditMemoryDir } from '../core/memory/memory-audit'
|
|
@@ -588,6 +595,18 @@ const approveCmd: CommandHandler = async (ctx) => {
|
|
|
588
595
|
}
|
|
589
596
|
}
|
|
590
597
|
|
|
598
|
+
/**
|
|
599
|
+
* One line for `/status`: whether this session is sending anything, and where.
|
|
600
|
+
* The endpoint can be empty for two different reasons (`off` vs the `none`
|
|
601
|
+
* sentinel), so say which instead of printing a bare blank (CC 2.1.335-085).
|
|
602
|
+
*/
|
|
603
|
+
function telemetryStatus(_ctx: CommandContext): string {
|
|
604
|
+
const consent = getTelemetryConsent() ?? resolveTelemetry()
|
|
605
|
+
if (!consent.enabled) return `disabled (set by ${consent.source})`
|
|
606
|
+
const destination = consent.endpoint || `nothing (${consent.endpointSource})`
|
|
607
|
+
return `enabled → ${destination} (set by ${consent.source})`
|
|
608
|
+
}
|
|
609
|
+
|
|
591
610
|
const statusCmd: CommandHandler = async (ctx) => {
|
|
592
611
|
const t = resolveT(ctx)
|
|
593
612
|
const c = ctx.engine.getContext()
|
|
@@ -601,6 +620,13 @@ const statusCmd: CommandHandler = async (ctx) => {
|
|
|
601
620
|
.filter((p) => p.status !== 'upcoming')
|
|
602
621
|
.map((p) => `${p.id} ${health.get(p.id) ? '🟢' : '🔴'}`)
|
|
603
622
|
.join(' ')
|
|
623
|
+
// Only the engine knows what it actually wired. A remote stub without the
|
|
624
|
+
// accessor omits the row instead of showing a guess.
|
|
625
|
+
const selfCheck = (
|
|
626
|
+
ctx.engine as QueryEngine & {
|
|
627
|
+
getSelfCheckStatus?: () => { reviewGate: boolean; verification: boolean }
|
|
628
|
+
}
|
|
629
|
+
).getSelfCheckStatus?.()
|
|
604
630
|
|
|
605
631
|
return {
|
|
606
632
|
content: stripIndent`
|
|
@@ -611,6 +637,8 @@ const statusCmd: CommandHandler = async (ctx) => {
|
|
|
611
637
|
${t('commands.status.tokens')} ~${c.getEstimatedTokens().toLocaleString()} / ${c.getMaxTokens().toLocaleString()}
|
|
612
638
|
${t('commands.status.tools')} ${tools.size} ${t('commands.status.loaded')}
|
|
613
639
|
${t('commands.status.permission')} ${liveMode(ctx)}
|
|
640
|
+
${selfCheck ? `Self-check review=${selfCheck.reviewGate ? 'on' : 'off'} verification=${selfCheck.verification ? 'on' : 'off'}` : ''}
|
|
641
|
+
Telemetry ${telemetryStatus(ctx)}
|
|
614
642
|
|
|
615
643
|
${t('commands.status.system_title')}
|
|
616
644
|
${t('commands.status.platform')} ${process.platform} ${process.arch}
|
|
@@ -998,6 +1026,13 @@ const configCmd: CommandHandler = (ctx) => {
|
|
|
998
1026
|
'',
|
|
999
1027
|
`crossSessionInbound: ${xs.crossSessionInbound}`,
|
|
1000
1028
|
`dialogExpiry: ${xs.dialogExpiry}s`,
|
|
1029
|
+
// The threshold `/autocompact` writes lived only in that command's output;
|
|
1030
|
+
// `/config` — where people look for it — showed nothing (CC 2.1.334-003).
|
|
1031
|
+
`autoCompact: ${
|
|
1032
|
+
getPreference('autocompactThreshold', '')
|
|
1033
|
+
? `${(Number.parseFloat(getPreference('autocompactThreshold', '')) * 100).toFixed(0)}% (set by /autocompact)`
|
|
1034
|
+
: 'window-derived (see /autocompact)'
|
|
1035
|
+
}`,
|
|
1001
1036
|
]
|
|
1002
1037
|
return {
|
|
1003
1038
|
content: `${t('commands.config.title')}\n${lines.join('\n')}\n\n${t('commands.config.edit')}`,
|
|
@@ -3984,14 +4019,34 @@ const copyCmd: CommandHandler = (ctx, args) => {
|
|
|
3984
4019
|
* folds index and worktree into one view; untracked files need `ls-files`
|
|
3985
4020
|
* because no `git diff` sees them.
|
|
3986
4021
|
*/
|
|
3987
|
-
|
|
4022
|
+
export interface GitChangeView {
|
|
4023
|
+
stat: string
|
|
4024
|
+
untracked: string[]
|
|
4025
|
+
/** 改动文件的仓库相对路径(含已删除的文件 —— 它们的目录仍可能有 REVIEW.md)。 */
|
|
4026
|
+
files: string[]
|
|
4027
|
+
/** 仓库根(`git rev-parse --show-toplevel`);拿不到时为空串。 */
|
|
4028
|
+
root: string
|
|
4029
|
+
}
|
|
4030
|
+
|
|
4031
|
+
async function readGitChangeSummary(): Promise<GitChangeView> {
|
|
3988
4032
|
const { execSync } = await import('node:child_process')
|
|
3989
4033
|
let stat = ''
|
|
4034
|
+
let files: string[] = []
|
|
3990
4035
|
try {
|
|
3991
4036
|
stat = execSync('git diff --stat HEAD', { encoding: 'utf-8', timeout: 5000 }).trim()
|
|
4037
|
+
files = execSync('git diff --name-only HEAD', { encoding: 'utf-8', timeout: 5000 })
|
|
4038
|
+
.split('\n')
|
|
4039
|
+
.filter(Boolean)
|
|
3992
4040
|
} catch {
|
|
3993
4041
|
// No HEAD yet (fresh repository) — fall back to the index/worktree diff.
|
|
3994
4042
|
stat = execSync('git diff --stat', { encoding: 'utf-8', timeout: 5000 }).trim()
|
|
4043
|
+
try {
|
|
4044
|
+
files = execSync('git diff --name-only', { encoding: 'utf-8', timeout: 5000 })
|
|
4045
|
+
.split('\n')
|
|
4046
|
+
.filter(Boolean)
|
|
4047
|
+
} catch {
|
|
4048
|
+
files = []
|
|
4049
|
+
}
|
|
3995
4050
|
}
|
|
3996
4051
|
let untracked: string[] = []
|
|
3997
4052
|
try {
|
|
@@ -4005,7 +4060,67 @@ async function readGitChangeSummary(): Promise<{ stat: string; untracked: string
|
|
|
4005
4060
|
// Not a repository / git unavailable — the stat call above already decided
|
|
4006
4061
|
// whether there is anything to report.
|
|
4007
4062
|
}
|
|
4008
|
-
|
|
4063
|
+
let root = ''
|
|
4064
|
+
try {
|
|
4065
|
+
root = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8', timeout: 5000 }).trim()
|
|
4066
|
+
} catch {
|
|
4067
|
+
// Not a repository — no folder-level REVIEW.md discovery.
|
|
4068
|
+
}
|
|
4069
|
+
return { stat, untracked, files: [...files, ...untracked], root }
|
|
4070
|
+
}
|
|
4071
|
+
|
|
4072
|
+
const REVIEW_DOC_NAME = 'REVIEW.md'
|
|
4073
|
+
/** 单份 REVIEW.md 的读取上限 —— 评审指令不是被评审的代码,不需要整本进提示词。 */
|
|
4074
|
+
const REVIEW_DOC_MAX_CHARS = 8_000
|
|
4075
|
+
/** 所有 REVIEW.md 合计上限 —— 防止大仓里几十份文档把提示词挤爆。 */
|
|
4076
|
+
const REVIEW_DOCS_TOTAL_MAX_CHARS = 32_000
|
|
4077
|
+
|
|
4078
|
+
/**
|
|
4079
|
+
* 改动文件祖先目录里的 REVIEW.md(仓库根 → 由外到内)。
|
|
4080
|
+
*
|
|
4081
|
+
* 语义与 `CLAUDE.md` 的加载链一致:外层先读、内层后读,越具体越靠后。
|
|
4082
|
+
* 同一份文件被多个改动文件共享时只收一次。`readFile` 返回 `null` 表示不存在,
|
|
4083
|
+
* 由调用方提供,因此这条发现逻辑不碰真文件系统也能测。
|
|
4084
|
+
*/
|
|
4085
|
+
export function collectReviewDocs(
|
|
4086
|
+
files: string[],
|
|
4087
|
+
readFile: (relativePath: string) => string | null,
|
|
4088
|
+
): Array<{ path: string; content: string }> {
|
|
4089
|
+
const dirs = new Set<string>([''])
|
|
4090
|
+
for (const file of files) {
|
|
4091
|
+
const norm = file.replace(/\\/g, '/').replace(/^\.\//, '')
|
|
4092
|
+
if (norm === '') continue
|
|
4093
|
+
const parts = norm.split('/')
|
|
4094
|
+
let cur = ''
|
|
4095
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
4096
|
+
cur = cur === '' ? parts[i]! : `${cur}/${parts[i]!}`
|
|
4097
|
+
dirs.add(cur)
|
|
4098
|
+
}
|
|
4099
|
+
}
|
|
4100
|
+
const depth = (dir: string) => (dir === '' ? 0 : dir.split('/').length)
|
|
4101
|
+
const ordered = [...dirs].sort((a, b) => depth(a) - depth(b) || a.localeCompare(b))
|
|
4102
|
+
const docs: Array<{ path: string; content: string }> = []
|
|
4103
|
+
let budget = REVIEW_DOCS_TOTAL_MAX_CHARS
|
|
4104
|
+
for (const dir of ordered) {
|
|
4105
|
+
if (budget <= 0) break
|
|
4106
|
+
const path = dir === '' ? REVIEW_DOC_NAME : `${dir}/${REVIEW_DOC_NAME}`
|
|
4107
|
+
const content = readFile(path)
|
|
4108
|
+
if (content === null || content.trim() === '') continue
|
|
4109
|
+
const clipped = content.slice(0, Math.min(REVIEW_DOC_MAX_CHARS, budget))
|
|
4110
|
+
budget -= clipped.length
|
|
4111
|
+
docs.push({ path, content: clipped })
|
|
4112
|
+
}
|
|
4113
|
+
return docs
|
|
4114
|
+
}
|
|
4115
|
+
|
|
4116
|
+
/** 把收集到的 REVIEW.md 拼成提示词里的一段;没有文档时返回空串。 */
|
|
4117
|
+
function formatReviewDocs(docs: Array<{ path: string; content: string }>): string {
|
|
4118
|
+
if (docs.length === 0) return ''
|
|
4119
|
+
const blocks = docs.map((d) => `### ${d.path}\n${d.content}`).join('\n\n')
|
|
4120
|
+
return (
|
|
4121
|
+
`\n\nFolder-level review instructions — REVIEW.md files in folders above the changed files. ` +
|
|
4122
|
+
`Outer folders come first, inner folders last; where they conflict, the inner one wins.\n\n${blocks}`
|
|
4123
|
+
)
|
|
4009
4124
|
}
|
|
4010
4125
|
|
|
4011
4126
|
const diffCmd: CommandHandler = async (_ctx) => {
|
|
@@ -4843,21 +4958,22 @@ function gitDiffBridgeCmd(opts: {
|
|
|
4843
4958
|
noChangesKey: string
|
|
4844
4959
|
runningKey: string
|
|
4845
4960
|
errorKey: string
|
|
4846
|
-
/** Either a fixed prompt, or a builder that reads the command args
|
|
4847
|
-
* may return an `{ error }` envelope instead — used
|
|
4848
|
-
* unusable, so the command reports that rather than
|
|
4849
|
-
* user's flag never reached. */
|
|
4850
|
-
forwardToAI: string | ((args: string[]) => string | { error: string })
|
|
4961
|
+
/** Either a fixed prompt, or a builder that reads the command args and the
|
|
4962
|
+
* change view. A builder may return an `{ error }` envelope instead — used
|
|
4963
|
+
* when the args are unusable, so the command reports that rather than
|
|
4964
|
+
* forwarding a prompt the user's flag never reached. */
|
|
4965
|
+
forwardToAI: string | ((args: string[], change: GitChangeView) => string | { error: string })
|
|
4851
4966
|
}): CommandHandler {
|
|
4852
4967
|
return async (ctx, args) => {
|
|
4853
4968
|
const t = resolveT(ctx)
|
|
4854
4969
|
try {
|
|
4855
|
-
const
|
|
4970
|
+
const change = await readGitChangeSummary()
|
|
4971
|
+
const { stat, untracked } = change
|
|
4856
4972
|
if (!stat && untracked.length === 0) {
|
|
4857
4973
|
return { content: `─ ${opts.label} ─\n\n${t(opts.noChangesKey)}` }
|
|
4858
4974
|
}
|
|
4859
4975
|
const forwarded =
|
|
4860
|
-
typeof opts.forwardToAI === 'function' ? opts.forwardToAI(args) : opts.forwardToAI
|
|
4976
|
+
typeof opts.forwardToAI === 'function' ? opts.forwardToAI(args, change) : opts.forwardToAI
|
|
4861
4977
|
if (typeof forwarded === 'object') {
|
|
4862
4978
|
return { content: `─ ${opts.label} ─\n\n${forwarded.error}` }
|
|
4863
4979
|
}
|
|
@@ -4933,9 +5049,19 @@ const codeReviewCmd = gitDiffBridgeCmd({
|
|
|
4933
5049
|
noChangesKey: 'commands.code_review.no_changes',
|
|
4934
5050
|
runningKey: 'commands.code_review.running',
|
|
4935
5051
|
errorKey: 'commands.code_review.error',
|
|
4936
|
-
forwardToAI: (args) => {
|
|
5052
|
+
forwardToAI: (args, change) => {
|
|
4937
5053
|
const maxFindings = resolveMaxFindings(args)
|
|
4938
5054
|
if (!maxFindings.ok) return { error: maxFindings.error }
|
|
5055
|
+
const baseDir = change.root !== '' ? change.root : process.cwd()
|
|
5056
|
+
const reviewDocs = formatReviewDocs(
|
|
5057
|
+
collectReviewDocs(change.files, (rel) => {
|
|
5058
|
+
try {
|
|
5059
|
+
return readFileSync(join(baseDir, rel), 'utf-8')
|
|
5060
|
+
} catch {
|
|
5061
|
+
return null
|
|
5062
|
+
}
|
|
5063
|
+
}),
|
|
5064
|
+
)
|
|
4939
5065
|
const cap =
|
|
4940
5066
|
maxFindings.value === 'all'
|
|
4941
5067
|
? ' Report every finding, however many there are.'
|
|
@@ -4955,7 +5081,7 @@ const codeReviewCmd = gitDiffBridgeCmd({
|
|
|
4955
5081
|
`Do not report reuse, simplification, efficiency, architecture or test-coverage cleanups — /simplify owns those. ` +
|
|
4956
5082
|
`Mark each finding with exactly one severity: important (this change introduced or worsened it), ` +
|
|
4957
5083
|
`pre_existing (it was already there before this change), or nit (minor). ` +
|
|
4958
|
-
`End the summary with one suggested fix. If there is nothing to report, write exactly: "Code review found no issues."${cap}`
|
|
5084
|
+
`End the summary with one suggested fix. If there is nothing to report, write exactly: "Code review found no issues."${cap}${reviewDocs}`
|
|
4959
5085
|
)
|
|
4960
5086
|
},
|
|
4961
5087
|
})
|
|
@@ -5289,10 +5415,10 @@ const cdCmd: CommandHandler = async (ctx, args) => {
|
|
|
5289
5415
|
ctx.setGitBranch?.((await import('../core/git-pr')).readGitBranch())
|
|
5290
5416
|
|
|
5291
5417
|
// `/cd` 只搬了 cwd,而**按目录装载的闸门**分两半:
|
|
5292
|
-
// • 能在这里重放的 —— `.mipham/rules/*.md
|
|
5293
|
-
//
|
|
5294
|
-
//
|
|
5295
|
-
//
|
|
5418
|
+
// • 能在这里重放的 —— `.mipham/rules/*.md`、settings.json 的 permission 规则,
|
|
5419
|
+
// 以及指令文件(CLAUDE.md 链,`reloadInstructions` 重新锚定装载器并重刷系统提示);
|
|
5420
|
+
// • 启动时一次性装载、搬不动的 —— config.yml 的 permissionRules 与 hooks。
|
|
5421
|
+
// 后者必须说出口:否则用户以为自己已经在新项目的策略下,而实际生效的
|
|
5296
5422
|
// 是上一个仓库的那一套。重放前半段是纯收紧/纯重放,不会放宽任何东西。
|
|
5297
5423
|
const notes: string[] = []
|
|
5298
5424
|
try {
|
|
@@ -5330,13 +5456,23 @@ const cdCmd: CommandHandler = async (ctx, args) => {
|
|
|
5330
5456
|
notes.push(`Applied ${applied} settings.json permission rule(s) from this directory.`)
|
|
5331
5457
|
ctx.engine.setRulesLoader(new RulesLoader(resolved))
|
|
5332
5458
|
notes.push('Project rules now read from this directory.')
|
|
5459
|
+
// The instruction chain is loaded once at startup and the loader that
|
|
5460
|
+
// built the prompt still points at the directory the session opened in.
|
|
5461
|
+
// Re-root it in place; the context rebuilder re-reads from the same
|
|
5462
|
+
// loader instance, so the base prompt (and the per-path nested lookup)
|
|
5463
|
+
// both move to the new directory.
|
|
5464
|
+
notes.push(
|
|
5465
|
+
ctx.engine.reloadInstructions(resolved)
|
|
5466
|
+
? 'Instruction files (CLAUDE.md chain) now read from this directory.'
|
|
5467
|
+
: 'Instruction files could not be reloaded in this mode.',
|
|
5468
|
+
)
|
|
5333
5469
|
}
|
|
5334
5470
|
} catch (err) {
|
|
5335
5471
|
notes.push(`Could not reload this directory's policy: ${(err as Error).message}`)
|
|
5336
5472
|
}
|
|
5337
5473
|
notes.push(
|
|
5338
5474
|
'Loaded at startup and still belonging to the original directory until restart: ' +
|
|
5339
|
-
'config.yml permissionRules
|
|
5475
|
+
'config.yml permissionRules and hooks.',
|
|
5340
5476
|
)
|
|
5341
5477
|
|
|
5342
5478
|
try {
|
|
@@ -5395,6 +5531,13 @@ const hooksListCmd: CommandHandler = async (ctx) => {
|
|
|
5395
5531
|
// display has to name the source and say which entries will not run.
|
|
5396
5532
|
const gated = !getWorkspaceTrust().isTrusted(cwd)
|
|
5397
5533
|
|
|
5534
|
+
// Plugin hooks are registered in the engine, not in settings.json. Reading
|
|
5535
|
+
// only the two settings files hid them: `/hooks` could report "no hooks"
|
|
5536
|
+
// while a plugin's hook still fired (CC 2.1.334-077).
|
|
5537
|
+
const pluginHooks = (ctx.engine?.getHookEngine?.()?.listHooks() ?? []).filter(
|
|
5538
|
+
(hook) => hook.source !== undefined,
|
|
5539
|
+
)
|
|
5540
|
+
|
|
5398
5541
|
type Entry = { matcher?: string; hooks: Array<{ type: string; command?: string }> }
|
|
5399
5542
|
const sources: Array<{ project: boolean; hooks: Record<string, Entry[]> }> = [
|
|
5400
5543
|
{ project: true, hooks: projectHooks as Record<string, Entry[]> },
|
|
@@ -5413,7 +5556,7 @@ const hooksListCmd: CommandHandler = async (ctx) => {
|
|
|
5413
5556
|
}
|
|
5414
5557
|
}
|
|
5415
5558
|
|
|
5416
|
-
if (byEvent.size === 0) {
|
|
5559
|
+
if (byEvent.size === 0 && pluginHooks.length === 0) {
|
|
5417
5560
|
return { content: t('commands.hooks.no_hooks') }
|
|
5418
5561
|
}
|
|
5419
5562
|
|
|
@@ -5449,6 +5592,15 @@ const hooksListCmd: CommandHandler = async (ctx) => {
|
|
|
5449
5592
|
}
|
|
5450
5593
|
}
|
|
5451
5594
|
|
|
5595
|
+
for (const hook of pluginHooks) {
|
|
5596
|
+
if (!hooksDisabled) count++
|
|
5597
|
+
const matcher = hook.toolName || '*'
|
|
5598
|
+
const suffix = hooksDisabled ? ` ${t('commands.hooks.disabled_all')}` : ''
|
|
5599
|
+
lines.push(
|
|
5600
|
+
` [${t('commands.hooks.source_plugin')}: ${hook.source}] ${hook.event} [${matcher}] → plugin-handler${suffix}`,
|
|
5601
|
+
)
|
|
5602
|
+
}
|
|
5603
|
+
|
|
5452
5604
|
lines.push('')
|
|
5453
5605
|
lines.push(t('commands.hooks.found', { count: String(count) }))
|
|
5454
5606
|
return { content: lines.join('\n') }
|
|
@@ -6480,6 +6632,13 @@ const mcpCmd: CommandHandler = async (ctx, args) => {
|
|
|
6480
6632
|
content: `Server "${sanitizeInlineField(name)}" not found in config.\n\nConfigured: ${mcpServers.map((s) => sanitizeInlineField(s.name)).join(', ') || '(none)'}`,
|
|
6481
6633
|
}
|
|
6482
6634
|
}
|
|
6635
|
+
// Disabled is a gate on starting it, so an explicit connect must not tunnel
|
|
6636
|
+
// through it — otherwise "off" lasts exactly until the next `/mcp connect`.
|
|
6637
|
+
if (loadDisabledMcpServers().has(name)) {
|
|
6638
|
+
return {
|
|
6639
|
+
content: `Server "${sanitizeInlineField(name)}" is disabled. Run \`/mcp enable ${sanitizeInlineField(name)}\` first.`,
|
|
6640
|
+
}
|
|
6641
|
+
}
|
|
6483
6642
|
const isOAuth = config.auth?.type === 'oauth'
|
|
6484
6643
|
const label = isOAuth ? `${name} (OAuth)` : name
|
|
6485
6644
|
try {
|
|
@@ -6595,7 +6754,13 @@ const mcpCmd: CommandHandler = async (ctx, args) => {
|
|
|
6595
6754
|
|
|
6596
6755
|
const toolsMap = ctx.engine.getTools()
|
|
6597
6756
|
const lines: string[] = ['── MCP Reload ──', '']
|
|
6757
|
+
const disabled = loadDisabledMcpServers()
|
|
6598
6758
|
for (const config of mcpServers) {
|
|
6759
|
+
if (disabled.has(config.name)) {
|
|
6760
|
+
unregisterMcpServerTools(config.name, toolsMap)
|
|
6761
|
+
lines.push(`⏸ ${sanitizeInlineField(config.name)} — disabled, skipped.`)
|
|
6762
|
+
continue
|
|
6763
|
+
}
|
|
6599
6764
|
// Tools live in the engine registry, not in the connection: drop them before
|
|
6600
6765
|
// reconnecting so a server that no longer offers a tool does not leave a
|
|
6601
6766
|
// dead entry registered.
|
|
@@ -6613,9 +6778,90 @@ const mcpCmd: CommandHandler = async (ctx, args) => {
|
|
|
6613
6778
|
return { content: lines.join('\n') }
|
|
6614
6779
|
}
|
|
6615
6780
|
|
|
6781
|
+
// /mcp enable|disable <name|all>
|
|
6782
|
+
if (sub === 'enable' || sub === 'disable') {
|
|
6783
|
+
const disabling = sub === 'disable'
|
|
6784
|
+
const heading = `MCP ${disabling ? 'Disable' : 'Enable'}`
|
|
6785
|
+
const mcpServers = ctx.config.skills?.mcpServers ?? []
|
|
6786
|
+
if (mcpServers.length === 0) {
|
|
6787
|
+
return { content: `── ${heading} ──\n\nNo MCP servers configured.` }
|
|
6788
|
+
}
|
|
6789
|
+
const disabled = loadDisabledMcpServers()
|
|
6790
|
+
const target = args[1]
|
|
6791
|
+
|
|
6792
|
+
// 没有服务器名时 CC 会打开 MCP 屏幕;这里没有屏幕,就把当前状态列出来并给
|
|
6793
|
+
// 用法。假装打开了一个不会出现的界面,比什么都不做更坏。
|
|
6794
|
+
if (!target) {
|
|
6795
|
+
const lines = [`── ${heading} ──`, '']
|
|
6796
|
+
for (const s of mcpServers) {
|
|
6797
|
+
const state = disabled.has(s.name) ? '⏸ disabled' : '● enabled '
|
|
6798
|
+
lines.push(` ${state} ${sanitizeInlineField(s.name)}`)
|
|
6799
|
+
}
|
|
6800
|
+
lines.push('', `Usage: /mcp ${sub} <server-name> | /mcp ${sub} all`)
|
|
6801
|
+
return { content: lines.join('\n') }
|
|
6802
|
+
}
|
|
6803
|
+
|
|
6804
|
+
if (target !== 'all' && !mcpServers.some((s) => s.name === target)) {
|
|
6805
|
+
return {
|
|
6806
|
+
content: [
|
|
6807
|
+
`── ${heading} ──`,
|
|
6808
|
+
'',
|
|
6809
|
+
`Server "${sanitizeInlineField(target)}" not found in config.`,
|
|
6810
|
+
`Configured: ${mcpServers.map((s) => sanitizeInlineField(s.name)).join(', ')}`,
|
|
6811
|
+
].join('\n'),
|
|
6812
|
+
}
|
|
6813
|
+
}
|
|
6814
|
+
|
|
6815
|
+
const targets = target === 'all' ? mcpServers.map((s) => s.name) : [target]
|
|
6816
|
+
const next = new Set(disabled)
|
|
6817
|
+
for (const name of targets) {
|
|
6818
|
+
if (disabling) next.add(name)
|
|
6819
|
+
else next.delete(name)
|
|
6820
|
+
}
|
|
6821
|
+
|
|
6822
|
+
// Persist the gate **before** acting on connections: if the write fails, a
|
|
6823
|
+
// server that looked disabled would come straight back next session.
|
|
6824
|
+
let savedPath: string
|
|
6825
|
+
try {
|
|
6826
|
+
savedPath = saveDisabledMcpServers(next)
|
|
6827
|
+
} catch (err) {
|
|
6828
|
+
return {
|
|
6829
|
+
content: `── ${heading} ──\n\nFailed to update settings.json: ${sanitizeInlineField(String(err))}`,
|
|
6830
|
+
}
|
|
6831
|
+
}
|
|
6832
|
+
|
|
6833
|
+
const lines = [
|
|
6834
|
+
`── ${heading}: ${target === 'all' ? 'all' : sanitizeInlineField(target)} ──`,
|
|
6835
|
+
'',
|
|
6836
|
+
]
|
|
6837
|
+
for (const name of targets) {
|
|
6838
|
+
if (disabling) {
|
|
6839
|
+
client.disconnect(name)
|
|
6840
|
+
unregisterMcpServerTools(name, ctx.engine.getTools())
|
|
6841
|
+
lines.push(
|
|
6842
|
+
`⏸ ${sanitizeInlineField(name)} — disabled; it will not start in future sessions.`,
|
|
6843
|
+
)
|
|
6844
|
+
} else {
|
|
6845
|
+
const config = mcpServers.find((s) => s.name === name)!
|
|
6846
|
+
try {
|
|
6847
|
+
await client.connect(config)
|
|
6848
|
+
const registered = registerMcpServerTools(name, ctx.engine.getTools())
|
|
6849
|
+
lines.push(`🟢 ${sanitizeInlineField(name)} — enabled; ${registered} tool(s) registered.`)
|
|
6850
|
+
} catch (err) {
|
|
6851
|
+
lines.push(
|
|
6852
|
+
`🔴 ${sanitizeInlineField(name)} — enabled, but connecting failed: ${sanitizeInlineField(String(err))}`,
|
|
6853
|
+
)
|
|
6854
|
+
}
|
|
6855
|
+
}
|
|
6856
|
+
}
|
|
6857
|
+
lines.push('', `Saved to ${savedPath}.`)
|
|
6858
|
+
return { content: lines.join('\n') }
|
|
6859
|
+
}
|
|
6860
|
+
|
|
6616
6861
|
// /mcp (default status)
|
|
6617
6862
|
const configuredServers = ctx.config.skills?.mcpServers ?? []
|
|
6618
6863
|
const liveConnections = client.listConnections()
|
|
6864
|
+
const disabledServers = loadDisabledMcpServers()
|
|
6619
6865
|
|
|
6620
6866
|
const lines: string[] = ['── MCP Servers ──', '']
|
|
6621
6867
|
|
|
@@ -6624,16 +6870,19 @@ const mcpCmd: CommandHandler = async (ctx, args) => {
|
|
|
6624
6870
|
lines.push('')
|
|
6625
6871
|
for (const s of configuredServers) {
|
|
6626
6872
|
const live = liveConnections.find((c) => c.config.name === s.name)
|
|
6627
|
-
const
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6873
|
+
const isDisabled = disabledServers.has(s.name)
|
|
6874
|
+
const statusIcon = isDisabled
|
|
6875
|
+
? '⏸'
|
|
6876
|
+
: live
|
|
6877
|
+
? live.status === 'connected'
|
|
6878
|
+
? '🟢'
|
|
6879
|
+
: live.status === 'connecting'
|
|
6880
|
+
? '🟡'
|
|
6881
|
+
: live.status === 'error'
|
|
6882
|
+
? '🔴'
|
|
6883
|
+
: '⚪'
|
|
6884
|
+
: '⚪'
|
|
6885
|
+
const statusLabel = isDisabled ? 'disabled' : live ? live.status : 'not started'
|
|
6637
6886
|
const oauthTag = s.auth?.type === 'oauth' ? ' [OAuth]' : ''
|
|
6638
6887
|
lines.push(` ${statusIcon} ${sanitizeInlineField(s.name)}${oauthTag} [${statusLabel}]`)
|
|
6639
6888
|
const transportInfo = s.url
|
|
@@ -6655,6 +6904,8 @@ const mcpCmd: CommandHandler = async (ctx, args) => {
|
|
|
6655
6904
|
lines.push(' /mcp disconnect <name> Disconnect from a server')
|
|
6656
6905
|
lines.push(' /mcp reconnect <name> Reconnect a dropped server (with backoff)')
|
|
6657
6906
|
lines.push(' /mcp reload Disconnect all and reconnect')
|
|
6907
|
+
lines.push(' /mcp enable <name|all> Enable a disabled server (persisted, user level)')
|
|
6908
|
+
lines.push(' /mcp disable <name|all> Disable a server so it stops starting')
|
|
6658
6909
|
lines.push('')
|
|
6659
6910
|
lines.push('── Protocol ──')
|
|
6660
6911
|
lines.push('MCP stdio transport (JSON-RPC 2.0) — fully implemented.')
|
|
@@ -7871,7 +8122,7 @@ const COMMAND_DESCRIPTIONS: Record<string, string> = {
|
|
|
7871
8122
|
'/marketplace': 'Manage marketplace sources (add/list/remove)',
|
|
7872
8123
|
'/browse-marketplace': 'Browse skills across all marketplace sources',
|
|
7873
8124
|
'/remove-skill': 'Remove an installed skill',
|
|
7874
|
-
'/mcp': 'MCP server status',
|
|
8125
|
+
'/mcp': 'MCP server status; enable/disable servers',
|
|
7875
8126
|
'/plugins': 'List installed plugins',
|
|
7876
8127
|
'/plugin':
|
|
7877
8128
|
'List plugins (alias of /plugins; use /install-plugin, /remove-plugin, /plugin-enable, /plugin-disable to manage)',
|