@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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/package.json +6 -6
  3. package/src/agent/agent-registry.ts +17 -2
  4. package/src/agent/sub-agent.ts +18 -2
  5. package/src/agent/types.ts +9 -0
  6. package/src/commands/environment.ts +71 -35
  7. package/src/commands/project.ts +31 -0
  8. package/src/config/loader.ts +112 -3
  9. package/src/core/command-taps.ts +10 -0
  10. package/src/core/credential-masker/matcher.ts +38 -0
  11. package/src/core/engine.ts +351 -6
  12. package/src/core/hooks.ts +18 -7
  13. package/src/core/instructions.ts +17 -3
  14. package/src/core/review-gate.ts +192 -0
  15. package/src/core/rules-loader.ts +4 -1
  16. package/src/core/session-insights.ts +8 -2
  17. package/src/core/session-store.ts +30 -23
  18. package/src/core/task-performance-tasks.json +18 -0
  19. package/src/core/verification-baseline.ts +277 -0
  20. package/src/core/write-paths.ts +19 -0
  21. package/src/daemon/engine-capabilities.ts +22 -1
  22. package/src/daemon/launch.ts +11 -1
  23. package/src/i18n-core/locales/en-US.json +9 -1
  24. package/src/i18n-core/locales/zh-CN.json +9 -1
  25. package/src/index.tsx +35 -3
  26. package/src/mcp/transport.ts +35 -3
  27. package/src/providers/anthropic.ts +17 -1
  28. package/src/providers/openai-compat.ts +13 -1
  29. package/src/shared/package-info.ts +2 -2
  30. package/src/shared/types.ts +11 -0
  31. package/src/skills/fork-executor.ts +3 -2
  32. package/src/skills/loader.ts +9 -2
  33. package/src/tools/agent/skill.ts +1 -0
  34. package/src/tools/agent/workflow.ts +3 -0
  35. package/src/tools/exec/task.ts +41 -0
  36. package/src/tools/file/grep.ts +30 -1
  37. package/src/tools/network/web-fetch.ts +11 -2
  38. package/src/ui/chat.tsx +17 -0
  39. package/src/ui/commands.ts +280 -29
  40. package/src/ui/picker.tsx +120 -19
  41. package/src/workflow/primitives/agent.ts +10 -1
  42. package/src/workflow/runtime.ts +49 -0
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Mipham Code v0.85.53
1
+ # Mipham Code v0.85.55
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miphamai/cli",
3
- "version": "0.85.53",
3
+ "version": "0.85.55",
4
4
  "description": "Mipham Code — Multi-model open-core intelligent coding terminal by MiphamAI",
5
5
  "keywords": [
6
6
  "ai",
@@ -44,7 +44,7 @@
44
44
  "mutate": "stryker run"
45
45
  },
46
46
  "dependencies": {
47
- "@larksuiteoapi/node-sdk": "^1.76.0",
47
+ "@larksuiteoapi/node-sdk": "^1.77.0",
48
48
  "commander": "^13.1.0",
49
49
  "ink": "^7.1.1",
50
50
  "ink-text-input": "^6.0.0",
@@ -56,10 +56,10 @@
56
56
  "@mipham/shared": "workspace:*",
57
57
  "@stryker-mutator/core": "10.1.1",
58
58
  "@stryker-mutator/vitest-runner": "10.0.0",
59
- "@types/bun": "^1.4.4",
60
- "@types/node": "^22.20.5",
61
- "@types/react": "^19.3.0",
62
- "@vitest/coverage-v8": "^5.0.5",
59
+ "@types/bun": "^1.4.5",
60
+ "@types/node": "^22.20.7",
61
+ "@types/react": "^19.3.3",
62
+ "@vitest/coverage-v8": "^5.1.2",
63
63
  "ink-testing-library": "^4.0.0",
64
64
  "vitest": "^5.0.5"
65
65
  }
@@ -13,13 +13,28 @@ interface FrontmatterResult {
13
13
  function parseFrontmatter(raw: string): FrontmatterResult {
14
14
  // Strip a leading UTF-8 BOM — otherwise `^---` never matches and a
15
15
  // BOM-prefixed file is silently treated as body text (effectively ignored).
16
- const src = raw.replace(/^\uFEFF/, '')
16
+ // Normalize CRLF: a Windows-authored agent file used to match none of the
17
+ // `\n`-anchored fence below, so its declared name/description were dropped
18
+ // (CC 2.1.333-097).
19
+ const src = raw.replace(/^\uFEFF/, '').replace(/\r\n/g, '\n')
17
20
  const match = src.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/)
18
21
  if (!match) {
19
22
  return { data: {}, content: src }
20
23
  }
24
+ let data: Record<string, unknown> = {}
25
+ try {
26
+ const parsed = parseYaml(match[1] || '')
27
+ data =
28
+ parsed && typeof parsed === 'object' && !Array.isArray(parsed)
29
+ ? (parsed as Record<string, unknown>)
30
+ : {}
31
+ } catch {
32
+ // Hand-written headers can contain an unquoted `Fix: a bug`, which strict
33
+ // YAML rejects. Dropping the header is better than dropping the file: the
34
+ // body still loads, and `name` falls back to the file name.
35
+ }
21
36
  return {
22
- data: parseYaml(match[1] || '') as Record<string, unknown>,
37
+ data,
23
38
  content: (match[2] || '').trim(),
24
39
  }
25
40
  }
@@ -16,6 +16,8 @@ import { getWorkspaceTrust } from '../core/workspace-trust'
16
16
  import { recordToolCall } from '../telemetry/index'
17
17
  import type { ExperienceRuleEngine } from '../core/rule-engine.js'
18
18
  import { runPreToolGate } from '../core/tool-gate'
19
+ import { writtenPathsFor } from '../core/write-paths'
20
+ import { commandFor } from '../core/command-taps'
19
21
  import { buildRequest, sendInferenceCheck, isInferenceHookEnabled } from '../core/inference-hook'
20
22
  import type { SubAgentServices } from './services'
21
23
 
@@ -320,8 +322,8 @@ export class SubAgent {
320
322
  // The cap is never silent: say which agent asked for what and what it got instead.
321
323
  reportAgentCapWarnings(gate, agentDef?.name)
322
324
 
323
- // Resolve execution directory: worktree isolation or process cwd
324
- const execCwd = options.worktreePath || process.cwd()
325
+ // Resolve execution directory: explicit cwd, worktree isolation, or process cwd
326
+ const execCwd = options.cwd || options.worktreePath || process.cwd()
325
327
 
326
328
  // Check workspace trust for the execution directory.
327
329
  // For worktree-isolated agents, auto-trust the worktree if the parent is trusted.
@@ -840,6 +842,20 @@ export class SubAgent {
840
842
  try {
841
843
  const result = await tool.execute(effectiveInput, toolContext)
842
844
 
845
+ // Second write path for the review gate: this loop bypasses
846
+ // `Engine.executeTool`, so the engine's own tracker never sees it.
847
+ if (result.success) {
848
+ for (const p of writtenPathsFor(tu.name, effectiveInput)) {
849
+ toolContext.onFileWrite?.(p)
850
+ }
851
+ }
852
+
853
+ // Command tap for the verification baseline. Deliberately outside
854
+ // the success branch: a failed run is a reading, not evidence that
855
+ // the check never ran.
856
+ const command = commandFor(tu.name, effectiveInput)
857
+ if (command !== undefined) toolContext.onCommand?.(command, result.success)
858
+
843
859
  if (sisFixSignature) {
844
860
  this.services?.gate.preflight?.()?.recordOutcome(sisFixSignature, result.success)
845
861
  sisOutcomeRecorded = true
@@ -71,6 +71,15 @@ export interface SubAgentOptions {
71
71
  onTokenUsage?: (totalTokens: number) => void
72
72
  /** When set, tool executions use this path as cwd (git worktree isolation). */
73
73
  worktreePath?: string
74
+ /**
75
+ * Tool-execution cwd.
76
+ *
77
+ * Unlike `worktreePath` this does NOT enter the worktree branch and does NOT
78
+ * write a workspace-trust entry. Daemon sessions need it: their session cwd is
79
+ * not `process.cwd()`, and passing `worktreePath` there would persist a trust
80
+ * record for the session directory as a side effect of reviewing it.
81
+ */
82
+ cwd?: string
74
83
  /** Seed the sub-agent with a parent conversation prefix (e.g., fork inheritance). */
75
84
  inheritContext?: { messages: Message[] }
76
85
  /**
@@ -66,40 +66,56 @@ const ideCmd: CommandHandler = async (_ctx) => {
66
66
  // (and `keybindings.json` is commonly JSONC, so an unparseable file must be
67
67
  // left alone rather than replaced).
68
68
  const { readRegularFileSync } = await import('../shared/regular-file')
69
- const readJson = (path: string): unknown => {
69
+ // `undefined` used to mean both "no file yet" (safe to create) and "a file we
70
+ // could not parse" (must not be touched). The caller treated both as empty,
71
+ // so a JSONC `settings.json` — trailing commas or comments — was replaced
72
+ // with a fresh `{}` plus one profile, destroying every other key. Distinguish
73
+ // the two states and skip the file when we cannot parse it (CC 2.1.335-031).
74
+ type ReadResult =
75
+ { kind: 'missing' } | { kind: 'parsed'; value: unknown } | { kind: 'unparseable' }
76
+ const readJson = (path: string): ReadResult => {
70
77
  const raw = readRegularFileSync(path)
71
- if (raw === null) return undefined
78
+ if (raw === null) return { kind: 'missing' }
72
79
  try {
73
- return JSON.parse(raw)
80
+ return { kind: 'parsed', value: JSON.parse(raw) }
74
81
  } catch {
75
- return undefined // JSONC / hand-edited — refuse to rewrite
82
+ return { kind: 'unparseable' }
76
83
  }
77
84
  }
78
85
  const isObject = (v: unknown): v is Record<string, unknown> =>
79
86
  v !== null && typeof v === 'object' && !Array.isArray(v)
87
+ const skipped: string[] = []
80
88
 
81
89
  // ── settings.json: terminal profile ──
82
90
  const settingsPath = join(vscodeDir, 'settings.json')
83
- const existingSettings = readJson(settingsPath)
84
- const settings: Record<string, unknown> = isObject(existingSettings) ? existingSettings : {}
85
- const profiles = isObject(settings['terminal.integrated.profiles.osx'])
86
- ? (settings['terminal.integrated.profiles.osx'] as Record<string, unknown>)
87
- : {}
88
- profiles.mipham = {
89
- path: bunPath,
90
- args: ['run', 'mipham'],
91
- cwd: '${workspaceFolder}',
91
+ const settingsState = readJson(settingsPath)
92
+ if (settingsState.kind === 'unparseable') {
93
+ skipped.push('.vscode/settings.json (JSONC or hand-edited — left unchanged)')
94
+ } else {
95
+ const settings: Record<string, unknown> =
96
+ settingsState.kind === 'parsed' && isObject(settingsState.value) ? settingsState.value : {}
97
+ const profiles = isObject(settings['terminal.integrated.profiles.osx'])
98
+ ? (settings['terminal.integrated.profiles.osx'] as Record<string, unknown>)
99
+ : {}
100
+ profiles.mipham = {
101
+ path: bunPath,
102
+ args: ['run', 'mipham'],
103
+ cwd: '${workspaceFolder}',
104
+ }
105
+ settings['terminal.integrated.profiles.osx'] = profiles
106
+ atomicWriteFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', { mode: 0o644 })
107
+ files.push('.vscode/settings.json')
92
108
  }
93
- settings['terminal.integrated.profiles.osx'] = profiles
94
- atomicWriteFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', { mode: 0o644 })
95
- files.push('.vscode/settings.json')
96
109
 
97
110
  // ── keybindings.json: Cmd+Esc launch ──
98
111
  const keybindingsPath = join(vscodeDir, 'keybindings.json')
99
- const existingKeybindings = readJson(keybindingsPath)
100
- const keybindings: Record<string, unknown>[] = Array.isArray(existingKeybindings)
101
- ? (existingKeybindings as Record<string, unknown>[])
102
- : []
112
+ const keybindingsState = readJson(keybindingsPath)
113
+ const keybindings: Record<string, unknown>[] = []
114
+ if (keybindingsState.kind === 'unparseable') {
115
+ skipped.push('.vscode/keybindings.json (JSONC or hand-edited — left unchanged)')
116
+ } else if (keybindingsState.kind === 'parsed' && Array.isArray(keybindingsState.value)) {
117
+ keybindings.push(...(keybindingsState.value as Record<string, unknown>[]))
118
+ }
103
119
  const wanted = [
104
120
  {
105
121
  key: 'cmd+escape',
@@ -111,27 +127,40 @@ const ideCmd: CommandHandler = async (_ctx) => {
111
127
  command: 'workbench.action.terminal.new',
112
128
  },
113
129
  ]
114
- for (const entry of wanted) {
115
- if (!keybindings.some((k) => k.key === entry.key && k.command === entry.command)) {
116
- keybindings.push(entry)
130
+ if (keybindingsState.kind !== 'unparseable') {
131
+ for (const entry of wanted) {
132
+ if (!keybindings.some((k) => k.key === entry.key && k.command === entry.command)) {
133
+ keybindings.push(entry)
134
+ }
117
135
  }
136
+ atomicWriteFileSync(keybindingsPath, JSON.stringify(keybindings, null, 2) + '\n', {
137
+ mode: 0o644,
138
+ })
139
+ files.push('.vscode/keybindings.json')
118
140
  }
119
- atomicWriteFileSync(keybindingsPath, JSON.stringify(keybindings, null, 2) + '\n', { mode: 0o644 })
120
- files.push('.vscode/keybindings.json')
121
141
 
122
142
  // ── extensions.json: recommended ──
123
143
  const extensionsPath = join(vscodeDir, 'extensions.json')
124
- const existingExtensions = readJson(extensionsPath)
125
- const extensions: Record<string, unknown> = isObject(existingExtensions) ? existingExtensions : {}
126
- const recommendations = Array.isArray(extensions.recommendations)
127
- ? (extensions.recommendations as unknown[])
128
- : []
129
- if (!recommendations.includes('miphamai.mipham-code')) {
130
- recommendations.push('miphamai.mipham-code')
144
+ const extensionsState = readJson(extensionsPath)
145
+ if (extensionsState.kind === 'unparseable') {
146
+ skipped.push('.vscode/extensions.json (JSONC or hand-edited — left unchanged)')
147
+ } else {
148
+ const extensions: Record<string, unknown> =
149
+ extensionsState.kind === 'parsed' && isObject(extensionsState.value)
150
+ ? extensionsState.value
151
+ : {}
152
+ const recommendations = Array.isArray(extensions.recommendations)
153
+ ? (extensions.recommendations as unknown[])
154
+ : []
155
+ if (!recommendations.includes('miphamai.mipham-code')) {
156
+ recommendations.push('miphamai.mipham-code')
157
+ }
158
+ extensions.recommendations = recommendations
159
+ atomicWriteFileSync(extensionsPath, JSON.stringify(extensions, null, 2) + '\n', {
160
+ mode: 0o644,
161
+ })
162
+ files.push('.vscode/extensions.json')
131
163
  }
132
- extensions.recommendations = recommendations
133
- atomicWriteFileSync(extensionsPath, JSON.stringify(extensions, null, 2) + '\n', { mode: 0o644 })
134
- files.push('.vscode/extensions.json')
135
164
 
136
165
  return {
137
166
  content: [
@@ -139,6 +168,13 @@ const ideCmd: CommandHandler = async (_ctx) => {
139
168
  '',
140
169
  `Generated in ${vscodeDir}:`,
141
170
  ...files.map((f) => ` ✅ ${f}`),
171
+ ...(skipped.length > 0
172
+ ? [
173
+ '',
174
+ 'Left unchanged (could not parse as JSON — comments or trailing commas):',
175
+ ...skipped.map((f) => ` ⚠ ${f}`),
176
+ ]
177
+ : []),
142
178
  '',
143
179
  'What was configured:',
144
180
  ' • Terminal profile "mipham" — opens Mipham Code in integrated terminal',
@@ -1025,6 +1025,37 @@ const promptAuditCmd: CommandHandler = async () => {
1025
1025
  message: 'Overly verbose constraint language',
1026
1026
  suggestion: 'Replace "you must ensure that" with imperative: "Ensure".',
1027
1027
  },
1028
+ // These three are the patterns that make a capable model stop thinking:
1029
+ // ask-first for everything, delegate everything, and treat any earlier
1030
+ // answer as permanently settled. Deliberately no rule flags "stop early"
1031
+ // or "stop when the answer is clear" — that guidance is what keeps a model
1032
+ // from grinding past a decision it has already made (CC 2.1.335-069).
1033
+ {
1034
+ id: 'broad-ask-first',
1035
+ pattern:
1036
+ /\b(ask|check with|confirm with)\s+(the user|me|them)\b.{0,40}\b(first|before|whenever|any ?time)\b/i,
1037
+ severity: 'medium',
1038
+ message: 'Broad ask-first rule',
1039
+ suggestion:
1040
+ 'Name the actions that genuinely need confirmation instead of asking before everything.',
1041
+ },
1042
+ {
1043
+ id: 'always-delegate',
1044
+ pattern:
1045
+ /\b(always|whenever|every time)\b.{0,60}\b(delegate|spawn|use)\b.{0,30}\b(sub-?agent|agent)\b/i,
1046
+ severity: 'medium',
1047
+ message: 'Always-delegate instruction',
1048
+ suggestion: 'Delegation is a judgment call. Say when it pays off, not "always".',
1049
+ },
1050
+ {
1051
+ id: 'earlier-answers-done',
1052
+ pattern:
1053
+ /\b(treat|consider|regard|take)\b.{0,40}\b(earlier|previous|prior)\b.{0,30}\b(answer|response|reply)s?\b.{0,20}\b(as )?(done|settled|final|answered)\b/i,
1054
+ severity: 'medium',
1055
+ message: 'Instruction to treat earlier answers as done',
1056
+ suggestion:
1057
+ 'An earlier answer can stop holding when facts change. Say what counts as a change.',
1058
+ },
1028
1059
  ]
1029
1060
 
1030
1061
  // Files to scan
@@ -421,7 +421,10 @@ function loadMcpJson(cwd: string, warn?: (message: string) => void): McpServerCo
421
421
 
422
422
  let parsed: unknown
423
423
  try {
424
- parsed = JSON.parse(raw)
424
+ // Editors on Windows often save a UTF-8 BOM. `JSON.parse` rejects it, and
425
+ // the file is then reported as malformed and skipped — every server it
426
+ // declared silently disappears (CC 2.1.334-074).
427
+ parsed = JSON.parse(raw.replace(/^\uFEFF/, ''))
425
428
  } catch (err) {
426
429
  // A malformed file used to be skipped in silence, so every server it
427
430
  // declared simply did not exist: the user saw "no such server" with no
@@ -642,7 +645,7 @@ export function loadSettingsJson(
642
645
  }
643
646
  continue
644
647
  }
645
- const parsed = JSON.parse(raw) as {
648
+ const parsed = JSON.parse(raw.replace(/^\uFEFF/, '')) as {
646
649
  hooks?: Record<string, unknown>
647
650
  disableAllHooks?: unknown
648
651
  permissions?: {
@@ -909,7 +912,7 @@ export function readSettingsDoc(path: string): Record<string, unknown> {
909
912
  if (raw === null) return {}
910
913
  let parsed: unknown
911
914
  try {
912
- parsed = JSON.parse(raw)
915
+ parsed = JSON.parse(raw.replace(/^\uFEFF/, ''))
913
916
  } catch (err) {
914
917
  throw new Error(
915
918
  `${path} is not valid JSON — ${jsonErrorDetail(raw, err)}. Fix or remove it, then retry.`,
@@ -990,6 +993,112 @@ export function removeSettingsRule(
990
993
  return null
991
994
  }
992
995
 
996
+ /**
997
+ * settings.json key holding the MCP server names the user turned off with
998
+ * `/mcp disable` (user level only — see `loadDisabledMcpServers`).
999
+ */
1000
+ export const DISABLED_MCP_KEY = 'disabledMcpServers'
1001
+
1002
+ /**
1003
+ * MCP servers the user turned off, read from the **user-level** settings.json.
1004
+ *
1005
+ * User level only on purpose: a project-level file would let a repository
1006
+ * silently disable the operator's own servers for every session in that tree —
1007
+ * the same trust problem `permissions.allow` has, resolved the same way (the
1008
+ * loader only reads the user's file).
1009
+ *
1010
+ * A malformed settings.json yields an empty set here rather than an error: this
1011
+ * runs on the startup path, where throwing would take the session down before
1012
+ * the user could fix the file. The writer (`saveDisabledMcpServers`) still
1013
+ * refuses to clobber it.
1014
+ */
1015
+ export function loadDisabledMcpServers(): Set<string> {
1016
+ try {
1017
+ const doc = readSettingsDoc(settingsPathFor('user'))
1018
+ const list = doc[DISABLED_MCP_KEY]
1019
+ if (!Array.isArray(list)) return new Set()
1020
+ return new Set(list.filter((v): v is string => typeof v === 'string'))
1021
+ } catch {
1022
+ return new Set()
1023
+ }
1024
+ }
1025
+
1026
+ export interface ReviewGateSettings {
1027
+ enabled: boolean
1028
+ maxRounds: number
1029
+ }
1030
+
1031
+ /** Review gate defaults: on, at most two reviews per turn. */
1032
+ export const DEFAULT_REVIEW_GATE: ReviewGateSettings = { enabled: true, maxRounds: 2 }
1033
+
1034
+ /**
1035
+ * Review gate config, read from the **user-level** settings.json.
1036
+ *
1037
+ * User level only, same reason as `loadDisabledMcpServers`: a project file must
1038
+ * not be able to silently turn the self-check off (that would be a widening).
1039
+ * A malformed file yields the defaults rather than throwing — this runs on the
1040
+ * startup path, where a throw takes the session down before it can be fixed.
1041
+ */
1042
+ export function loadReviewGateConfig(): ReviewGateSettings {
1043
+ try {
1044
+ const doc = readSettingsDoc(settingsPathFor('user'))
1045
+ const raw = doc.reviewGate
1046
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return { ...DEFAULT_REVIEW_GATE }
1047
+ const obj = raw as Record<string, unknown>
1048
+ const enabled = typeof obj.enabled === 'boolean' ? obj.enabled : DEFAULT_REVIEW_GATE.enabled
1049
+ const maxRounds =
1050
+ typeof obj.maxRounds === 'number' && Number.isFinite(obj.maxRounds)
1051
+ ? Math.min(5, Math.max(1, Math.trunc(obj.maxRounds)))
1052
+ : DEFAULT_REVIEW_GATE.maxRounds
1053
+ return { enabled, maxRounds }
1054
+ } catch {
1055
+ return { ...DEFAULT_REVIEW_GATE }
1056
+ }
1057
+ }
1058
+
1059
+ export interface VerificationSettings {
1060
+ enabled: boolean
1061
+ }
1062
+
1063
+ /** Verification baseline defaults: on. */
1064
+ export const DEFAULT_VERIFICATION: VerificationSettings = { enabled: true }
1065
+
1066
+ /**
1067
+ * Verification baseline config, read from the **user-level** settings.json.
1068
+ *
1069
+ * User level only: a project file must not be able to turn the self-check off.
1070
+ * A malformed file yields the defaults rather than throwing — startup path.
1071
+ */
1072
+ export function loadVerificationConfig(): VerificationSettings {
1073
+ try {
1074
+ const doc = readSettingsDoc(settingsPathFor('user'))
1075
+ const raw = doc.verification
1076
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return { ...DEFAULT_VERIFICATION }
1077
+ const obj = raw as Record<string, unknown>
1078
+ return {
1079
+ enabled: typeof obj.enabled === 'boolean' ? obj.enabled : DEFAULT_VERIFICATION.enabled,
1080
+ }
1081
+ } catch {
1082
+ return { ...DEFAULT_VERIFICATION }
1083
+ }
1084
+ }
1085
+
1086
+ /**
1087
+ * Persist the full disabled-server set (sorted, deduped). An empty set removes
1088
+ * the key entirely, so "never disabled anything" and "edited it back" look the
1089
+ * same in the file. Returns the path written; throws if settings.json is not
1090
+ * valid JSON or is not an object — the user's other settings live there.
1091
+ */
1092
+ export function saveDisabledMcpServers(names: Iterable<string>): string {
1093
+ const path = settingsPathFor('user')
1094
+ const doc = readSettingsDoc(path)
1095
+ const sorted = [...new Set(names)].sort()
1096
+ if (sorted.length === 0) delete doc[DISABLED_MCP_KEY]
1097
+ else doc[DISABLED_MCP_KEY] = sorted
1098
+ writeSettingsDoc(path, doc)
1099
+ return path
1100
+ }
1101
+
993
1102
  export function loadConfig(cwd: string = process.cwd()): MiphamConfig {
994
1103
  // `null` when cwd is the home directory, where the "project" config *is* the user
995
1104
  // config read further down (`MIPHAM_HOME` and `join(cwd, MIPHAM_DIR)` coincide) —
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 从工具调用里提取「实际执行的 shell 命令」。只认 Bash 的 `command` 参数;
3
+ * 其余工具一律返回 undefined —— 验证基线只观察能对得上检查清单的命令。
4
+ */
5
+ export function commandFor(toolName: string, params: Record<string, unknown>): string | undefined {
6
+ if (toolName !== 'Bash') return undefined
7
+ const command = params.command
8
+ if (typeof command !== 'string' || command.trim() === '') return undefined
9
+ return command
10
+ }
@@ -97,6 +97,26 @@ export function globToRegexSource(pattern: string): string {
97
97
  i++
98
98
  continue
99
99
  }
100
+ if (ch === '{') {
101
+ // Brace alternation, nesting included: `src/{a,b/{c,d}}/*.ts`. Escaped
102
+ // literally before, so a rule's `paths:` silently matched none of the
103
+ // files it named (CC 2.1.334-101).
104
+ let depth = 1
105
+ let j = i + 1
106
+ while (j < pattern.length && depth > 0) {
107
+ if (pattern[j] === '{') depth++
108
+ else if (pattern[j] === '}') depth--
109
+ j++
110
+ }
111
+ if (depth === 0) {
112
+ const inner = pattern.slice(i + 1, j - 1)
113
+ const alternatives = splitBraceAlternatives(inner)
114
+ regexStr += '(?:' + alternatives.map((p) => globToRegexSource(p)).join('|') + ')'
115
+ i = j
116
+ continue
117
+ }
118
+ // Unbalanced `{` — fall through and treat it literally.
119
+ }
100
120
  // Escape regex special chars
101
121
  if ('\\^$.|+()[]{}'.includes(ch)) {
102
122
  regexStr += '\\' + ch
@@ -108,6 +128,24 @@ export function globToRegexSource(pattern: string): string {
108
128
  return regexStr
109
129
  }
110
130
 
131
+ /** Split a brace alternation's body on commas that are not inside nested braces. */
132
+ function splitBraceAlternatives(inner: string): string[] {
133
+ const out: string[] = []
134
+ let depth = 0
135
+ let start = 0
136
+ for (let i = 0; i < inner.length; i++) {
137
+ const ch = inner[i]
138
+ if (ch === '{') depth++
139
+ else if (ch === '}') depth--
140
+ else if (ch === ',' && depth === 0) {
141
+ out.push(inner.slice(start, i))
142
+ start = i + 1
143
+ }
144
+ }
145
+ out.push(inner.slice(start))
146
+ return out
147
+ }
148
+
111
149
  /**
112
150
  * Convert a glob pattern to a full-path-anchored RegExp (see `globToRegexSource`
113
151
  * for the `*`/`**`/`?` translation and escaping rules).