@miphamai/cli 0.72.0 → 0.73.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miphamai/cli",
3
- "version": "0.72.0",
3
+ "version": "0.73.0",
4
4
  "description": "Mipham Code — Multi-model open-core intelligent coding terminal by MiphamAI",
5
5
  "keywords": [
6
6
  "ai",
@@ -553,9 +553,7 @@ async function setupStep3(ctx: CommandContext): Promise<CommandResult> {
553
553
  lines.push(` ${p.id}${p.id === ctx.providerId ? ' ← current' : ''}`)
554
554
  for (const m of p.models.filter((m) => m.status === 'active')) {
555
555
  const marker = m.id === ctx.modelId ? ' ★' : ' '
556
- lines.push(
557
- `${marker} ${m.id.padEnd(30)} ${m.contextWindow.toLocaleString()} ctx ${m.vision ? '🖼' : '📝'}`,
558
- )
556
+ lines.push(`${marker} ${m.id.padEnd(30)} ${m.vision ? '🖼' : '📝'}`)
559
557
  }
560
558
  lines.push('')
561
559
  }
@@ -251,8 +251,37 @@ export function wildcardMatch(pattern: string, input: string): boolean {
251
251
  return new RegExp(regexStr).test(input)
252
252
  }
253
253
 
254
+ /**
255
+ * Validate a rule pattern string's structure, mirroring exactly what
256
+ * `matchBashRule` / `ruleMatches` will actually match. A pattern that is
257
+ * syntactically valid but never matches (e.g. `Bash(ls) x`, `Read(foo`,
258
+ * `Bash()`) is silently dead today — this returns a human-readable reason so
259
+ * the caller can report it as an invalid setting instead of ignoring it.
260
+ *
261
+ * Returns null when the pattern is valid, or a reason string when malformed.
262
+ */
263
+ export function validateRulePattern(pattern: string): string | null {
264
+ if (!pattern.trim()) return 'rule pattern is empty'
265
+
266
+ if (pattern.includes('(')) {
267
+ if (!pattern.includes(')')) return 'unclosed parenthesis'
268
+ // Empty parameter: `Bash()` or `Bash( )`
269
+ if (/\(\s*\)$/.test(pattern)) return 'empty parameter'
270
+ // Must be exactly `ToolName(param)` with nothing before or after.
271
+ if (!/^(\w+)\((.+)\)$/.test(pattern)) {
272
+ return 'unexpected text after the closing parenthesis'
273
+ }
274
+ return null
275
+ }
276
+
277
+ // No parenthesis → must be a plain tool name (matched via `pattern === tool.name`).
278
+ if (!/^\w+$/.test(pattern)) return 'not a single tool name'
279
+ return null
280
+ }
281
+
254
282
  /** Compile a rule pattern string into a PermissionRuleEntry. */
255
283
  export function compileRule(pattern: string, level: 'allow' | 'deny' | 'ask'): PermissionRuleEntry {
284
+ const invalid = validateRulePattern(pattern)
256
285
  const regexStr =
257
286
  '^' +
258
287
  pattern
@@ -261,5 +290,5 @@ export function compileRule(pattern: string, level: 'allow' | 'deny' | 'ask'): P
261
290
  .replace(/\\\*/g, '.*')
262
291
  .replace(/\\\?/g, '.') +
263
292
  '$'
264
- return { pattern, level, compiled: new RegExp(regexStr) }
293
+ return { pattern, level, compiled: new RegExp(regexStr), ...(invalid ? { invalid } : {}) }
265
294
  }
@@ -489,6 +489,24 @@ export class PermissionSystem {
489
489
  this.invalidateCache()
490
490
  }
491
491
 
492
+ /**
493
+ * Report any rule whose pattern is structurally invalid and can therefore
494
+ * never match (e.g. `Bash(ls) x`, `Read(foo`, `Bash()`). These are silently
495
+ * dead today — callers should surface them as invalid settings rather than
496
+ * let a deny rule fail closed without the user noticing.
497
+ */
498
+ getInvalidRules(): string[] {
499
+ const invalid: string[] = []
500
+ for (const entry of [...this.allowRules, ...this.denyRules, ...this.askRules]) {
501
+ if (entry.invalid) {
502
+ invalid.push(
503
+ `permission rule "${entry.pattern}" is invalid (${entry.invalid}) and will never match`,
504
+ )
505
+ }
506
+ }
507
+ return invalid
508
+ }
509
+
492
510
  removeRule(toolName: string): void {
493
511
  this.legacyRules.delete(toolName)
494
512
  this.removeRuleFromArrays(toolName)
@@ -95,6 +95,9 @@ export function buildDaemonPermission(
95
95
  for (const rule of rules.allow ?? []) permission.allow(rule)
96
96
  for (const rule of rules.deny ?? []) permission.deny(rule)
97
97
  }
98
+ for (const msg of permission.getInvalidRules()) {
99
+ process.stderr.write(`⚠ Mipham Code: ${msg}\n`)
100
+ }
98
101
  return permission
99
102
  }
100
103
 
package/src/index.tsx CHANGED
@@ -559,6 +559,12 @@ export async function runApp(options: RunOptions): Promise<void> {
559
559
  for (const rule of settingsJson.permissions.allow) engine.getPermission().allow(rule)
560
560
  for (const rule of settingsJson.permissions.deny) engine.getPermission().deny(rule)
561
561
 
562
+ // Surface malformed permission rules as warnings instead of silently letting
563
+ // them never match (e.g. a deny rule typed `Bash(ls) x` would fail closed).
564
+ for (const msg of engine.getPermission().getInvalidRules()) {
565
+ process.stderr.write(`⚠ Mipham Code: ${msg}\n`)
566
+ }
567
+
562
568
  // Initialize agent registry and load plugin agents/skills/MCP/hooks
563
569
  const agentRegistry = new AgentRegistry()
564
570
  agentRegistry.loadUserAgents()
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Format a model's context window (token count) into a friendly unit string.
3
+ * Decimal K/M: 16384 → "16K", 131072 → "131K", 200000 → "200K", 1000000 → "1M".
4
+ * Used only on the developer-facing `/models` command — the first-run model
5
+ * picker deliberately omits context window (raw token counts make Mipham's own
6
+ * models look small next to 1M-context competitors).
7
+ */
8
+ export function formatContextWindow(tokens: number): string {
9
+ if (tokens >= 1_000_000) {
10
+ const m = tokens / 1_000_000
11
+ return `${Number.isInteger(m) ? m : m.toFixed(1)}M`
12
+ }
13
+ if (tokens >= 1_000) return `${Math.round(tokens / 1_000)}K`
14
+ return `${tokens}`
15
+ }
@@ -11,34 +11,34 @@
11
11
  "models": [
12
12
  {
13
13
  "id": "om-v5-flash",
14
- "name": "OM V5 Flash",
14
+ "name": "om-V5-Flash",
15
15
  "providerId": "mipham",
16
16
  "contextWindow": 16384,
17
17
  "maxOutput": 4096,
18
18
  "vision": false,
19
19
  "status": "active"
20
20
  },
21
- {
22
- "id": "om-v5-pro",
23
- "name": "OM V5 Pro",
24
- "providerId": "mipham",
25
- "contextWindow": 131072,
26
- "maxOutput": 16384,
27
- "vision": false,
28
- "status": "active"
29
- },
30
21
  {
31
22
  "id": "om-v5-visual",
32
- "name": "OM V5 Visual",
23
+ "name": "om-V5-Visual",
33
24
  "providerId": "mipham",
34
25
  "contextWindow": 65536,
35
26
  "maxOutput": 4096,
36
27
  "vision": true,
37
28
  "status": "active"
38
29
  },
30
+ {
31
+ "id": "om-v5-pro",
32
+ "name": "om-V5-Pro",
33
+ "providerId": "mipham",
34
+ "contextWindow": 131072,
35
+ "maxOutput": 16384,
36
+ "vision": false,
37
+ "status": "active"
38
+ },
39
39
  {
40
40
  "id": "om-v5-apex",
41
- "name": "OM V5 Apex",
41
+ "name": "om-V5-Apex",
42
42
  "providerId": "mipham",
43
43
  "contextWindow": 200000,
44
44
  "maxOutput": 32768,
@@ -46,5 +46,5 @@
46
46
  "status": "active"
47
47
  }
48
48
  ],
49
- "synced_at": "2026-08-04T00:00:00Z"
49
+ "synced_at": "2026-09-04T02:32:33.479Z"
50
50
  }
@@ -9,7 +9,7 @@
9
9
  export const PACKAGE_NAME = '@miphamai/cli' as const
10
10
 
11
11
  /** 当前发布版本 */
12
- export const PACKAGE_VERSION = '0.72.0' as const
12
+ export const PACKAGE_VERSION = '0.73.0' as const
13
13
 
14
14
  /** npm install 全局安装命令 */
15
15
  export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` as const
@@ -315,6 +315,8 @@ export interface PermissionRuleEntry {
315
315
  pattern: string // e.g., "Bash(git:*)"
316
316
  level: 'allow' | 'deny' | 'ask'
317
317
  compiled: RegExp
318
+ /** Set when the pattern is structurally invalid and can never match. */
319
+ invalid?: string
318
320
  }
319
321
 
320
322
  export interface PermissionRule {
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import type { QueryEngine } from '../core/engine'
8
8
  import type { MiphamConfig } from '../shared/index.ts'
9
+ import { formatContextWindow } from '../shared/format'
9
10
  import type { SkillsLoader } from '../skills/loader'
10
11
  import type { PluginManager } from '../plugin/plugin-manager'
11
12
  import type { Message } from '../shared/types.js'
@@ -438,7 +439,7 @@ const modelsCmd: CommandHandler = (ctx) => {
438
439
  .filter((m) => m.status === 'active')
439
440
  .map(
440
441
  (m) =>
441
- ` ${p.id.padEnd(12)} ${m.id.padEnd(30)} ${m.contextWindow.toLocaleString()} ctx ${m.vision ? '🖼' : '📝'}`,
442
+ ` ${p.id.padEnd(12)} ${m.id.padEnd(30)} ${formatContextWindow(m.contextWindow)} ctx ${m.vision ? '🖼' : '📝'}`,
442
443
  ),
443
444
  )
444
445
 
package/src/ui/picker.tsx CHANGED
@@ -198,7 +198,7 @@ export function ModelPicker({
198
198
  </Text>
199
199
  <Text dimColor>
200
200
  {' '}
201
- {m.id} · {m.contextWindow.toLocaleString()} ctx
201
+ {m.id}
202
202
  {m.vision ? ' · 🖼 vision' : ''}
203
203
  </Text>
204
204
  </Box>