@miphamai/cli 0.85.21 → 0.85.22
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 +1 -1
- package/src/commands/project.ts +9 -3
- package/src/core/permission-rules.ts +29 -3
- package/src/core/permission.ts +54 -6
- package/src/daemon/server.ts +6 -0
- package/src/index.tsx +7 -0
- package/src/shared/package-info.ts +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mipham Code v0.85.
|
|
1
|
+
# Mipham Code v0.85.22
|
|
2
2
|
|
|
3
3
|
**Multi-model open-core intelligent coding terminal** — 12 AI providers, 137 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
package/src/commands/project.ts
CHANGED
|
@@ -248,17 +248,23 @@ const permissionsCmd: CommandHandler = async (ctx, args) => {
|
|
|
248
248
|
}
|
|
249
249
|
// A rule that can't match is worse than no rule: it reads as protection
|
|
250
250
|
// that isn't there. Validate every rule before writing any of them.
|
|
251
|
+
//
|
|
252
|
+
// Judged against the permission system's own tool set (`getKnownTools`), not a
|
|
253
|
+
// second copy — that set is what plain-name rules are matched against, so the
|
|
254
|
+
// verdict here and the matching there cannot drift. It is `undefined` in a
|
|
255
|
+
// context nobody told about the registry, in which case the check is structural
|
|
256
|
+
// only, exactly as before.
|
|
257
|
+
const perm = ctx.engine.getPermission()
|
|
251
258
|
if (verb !== 'remove') {
|
|
259
|
+
const knownTools = perm.getKnownTools()
|
|
252
260
|
for (const rule of rules) {
|
|
253
|
-
const invalid = validateRulePattern(rule)
|
|
261
|
+
const invalid = validateRulePattern(rule, knownTools)
|
|
254
262
|
if (invalid) {
|
|
255
263
|
return { content: `Invalid rule "${rule}": ${invalid}.\n\n${usage}` }
|
|
256
264
|
}
|
|
257
265
|
}
|
|
258
266
|
}
|
|
259
267
|
|
|
260
|
-
const perm = ctx.engine.getPermission()
|
|
261
|
-
|
|
262
268
|
if (verb === 'remove') {
|
|
263
269
|
const parts: string[] = []
|
|
264
270
|
// Both scopes, named one first. `remove` does not know which list holds the
|
|
@@ -786,9 +786,21 @@ export function wildcardMatch(pattern: string, input: string): boolean {
|
|
|
786
786
|
* 能否匹配任何东西 —— `Bash(zzz *)` 合法、装得上、只是不会命中,那是用户自己的
|
|
787
787
|
* 选择,不是配置错误。
|
|
788
788
|
*
|
|
789
|
+
* `knownTools` —— 注册表里实际存在的工具名集合(可选)。给了它,裸名分支才会判
|
|
790
|
+
* **存在性**:裸名的匹配是大小写敏感的 `pattern === tool.name`,所以 `bash` / `bahs`
|
|
791
|
+
* 与 `Bash(ls) x` 是同一类**静默空防护**(语法合法、装得上、永远不命中,而用户以为
|
|
792
|
+
* 配了保护)。不给它则只判结构(拿不到注册表的调用点不凭空给存在性判决)。
|
|
793
|
+
*
|
|
794
|
+
* **`mcp__` 前缀一律放行**:MCP 服务器是后台异步连接的(`connectMcpServers`),
|
|
795
|
+
* 规则加载那一刻它们的工具还没进注册表 —— 按当时的注册表判,会把每条 mcp 规则
|
|
796
|
+
* 都误报成「未知工具」。
|
|
797
|
+
*
|
|
789
798
|
* Returns null when the pattern is valid, or a reason string when malformed.
|
|
790
799
|
*/
|
|
791
|
-
export function validateRulePattern(
|
|
800
|
+
export function validateRulePattern(
|
|
801
|
+
pattern: string,
|
|
802
|
+
knownTools?: ReadonlySet<string>,
|
|
803
|
+
): string | null {
|
|
792
804
|
if (!pattern.trim()) return 'rule pattern is empty'
|
|
793
805
|
|
|
794
806
|
if (pattern.includes('(')) {
|
|
@@ -811,12 +823,26 @@ export function validateRulePattern(pattern: string): string | null {
|
|
|
811
823
|
|
|
812
824
|
// No parenthesis → must be a plain tool name (matched via `pattern === tool.name`).
|
|
813
825
|
if (!/^\w+$/.test(pattern)) return 'not a single tool name'
|
|
826
|
+
if (knownTools && !pattern.startsWith('mcp__')) {
|
|
827
|
+
if (knownTools.has(pattern)) return null
|
|
828
|
+
// 大小写错的名字有唯一的正确写法,把它带出来 —— 拒绝消息的价值就在于照抄能用。
|
|
829
|
+
// 只在**全名大小写相等**时给建议:那是个恒等改写,不可能指错工具。更远的东西
|
|
830
|
+
// (`bahs` → `Bash`)不猜,猜错会把用户引到另一个工具上。
|
|
831
|
+
const exact = [...knownTools].find((t) => t.toLowerCase() === pattern.toLowerCase())
|
|
832
|
+
return exact
|
|
833
|
+
? `unknown tool "${pattern}" — tool names are case-sensitive; did you mean "${exact}"?`
|
|
834
|
+
: `unknown tool "${pattern}"`
|
|
835
|
+
}
|
|
814
836
|
return null
|
|
815
837
|
}
|
|
816
838
|
|
|
817
839
|
/** Compile a rule pattern string into a PermissionRuleEntry. */
|
|
818
|
-
export function compileRule(
|
|
819
|
-
|
|
840
|
+
export function compileRule(
|
|
841
|
+
pattern: string,
|
|
842
|
+
level: 'allow' | 'deny' | 'ask',
|
|
843
|
+
knownTools?: ReadonlySet<string>,
|
|
844
|
+
): PermissionRuleEntry {
|
|
845
|
+
const invalid = validateRulePattern(pattern, knownTools)
|
|
820
846
|
const regexStr =
|
|
821
847
|
'^' +
|
|
822
848
|
pattern
|
package/src/core/permission.ts
CHANGED
|
@@ -229,6 +229,13 @@ export class PermissionSystem {
|
|
|
229
229
|
*/
|
|
230
230
|
private classifier: PermissionClassifier | undefined = undefined
|
|
231
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Tool names the registry holds, for judging a plain-name rule's existence (see
|
|
234
|
+
* `setKnownTools`). Absent is a legal state: a system nobody told about the
|
|
235
|
+
* registry judges structure only, which is the behavior every caller had before.
|
|
236
|
+
*/
|
|
237
|
+
private knownTools: ReadonlySet<string> | undefined = undefined
|
|
238
|
+
|
|
232
239
|
// ── Org-level restrictions (P0 security) ──
|
|
233
240
|
private restrictions: PermissionRestrictions | undefined = undefined
|
|
234
241
|
|
|
@@ -267,6 +274,35 @@ export class PermissionSystem {
|
|
|
267
274
|
this.invalidateCache()
|
|
268
275
|
}
|
|
269
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Hand in the tool names the registry actually holds, so a plain-name rule can be
|
|
279
|
+
* judged on **existence** and not just on structure. Plain names match by
|
|
280
|
+
* `pattern === tool.name` (case-sensitive), so `bash` / `bahs` load fine and match
|
|
281
|
+
* nothing — the same silent-dead-rule class as `Bash(ls) x`, and the one that
|
|
282
|
+
* reached a user's settings.json as `allow: ["bash", "bahs"]`.
|
|
283
|
+
*
|
|
284
|
+
* Must be called **before** the rules it should judge: the verdict is stamped onto
|
|
285
|
+
* each entry at compile time (`compileRule`), which is also what `getInvalidRules`
|
|
286
|
+
* reads back. `mcp__`-prefixed names are exempt inside `validateRulePattern`.
|
|
287
|
+
*
|
|
288
|
+
* Like `setClassifier`, this seam lives on the permission system rather than the
|
|
289
|
+
* engine — an engine-side setter would be a new engine capability the daemon would
|
|
290
|
+
* have to match (`test/integrity/daemon-capability-parity.test.ts`).
|
|
291
|
+
*/
|
|
292
|
+
setKnownTools(names: Iterable<string>): void {
|
|
293
|
+
this.knownTools = new Set(names)
|
|
294
|
+
this.invalidateCache()
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The set plain-name rules are validated against, or `undefined` when nobody
|
|
299
|
+
* handed one in. Public so the `/permissions` command judges a rule against
|
|
300
|
+
* **the same set this system will match it against** instead of a second copy.
|
|
301
|
+
*/
|
|
302
|
+
getKnownTools(): ReadonlySet<string> | undefined {
|
|
303
|
+
return this.knownTools
|
|
304
|
+
}
|
|
305
|
+
|
|
270
306
|
/** Whether an `auto`-mode classifier is attached. For diagnostics, not decisions. */
|
|
271
307
|
hasClassifier(): boolean {
|
|
272
308
|
return this.classifier !== undefined
|
|
@@ -370,6 +406,14 @@ export class PermissionSystem {
|
|
|
370
406
|
subPerm.setRestrictions(this.restrictions)
|
|
371
407
|
}
|
|
372
408
|
|
|
409
|
+
// The tool set travels too, and before the rules below: the deny rules are
|
|
410
|
+
// re-added through the same compile path, so without it a rule the parent had
|
|
411
|
+
// flagged would come back as "structurally valid" and its warning would vanish
|
|
412
|
+
// by travelling — a rule silently degrading one hop down.
|
|
413
|
+
if (this.knownTools) {
|
|
414
|
+
subPerm.setKnownTools(this.knownTools)
|
|
415
|
+
}
|
|
416
|
+
|
|
373
417
|
// Propagate deny rules (org safety policies must always apply)
|
|
374
418
|
for (const denyEntry of this.denyRules) {
|
|
375
419
|
subPerm.deny(denyEntry.pattern)
|
|
@@ -460,17 +504,17 @@ export class PermissionSystem {
|
|
|
460
504
|
// ── Rule management ──
|
|
461
505
|
|
|
462
506
|
allow(rule: string): void {
|
|
463
|
-
this.allowRules.push(compileRule(rule, 'allow'))
|
|
507
|
+
this.allowRules.push(compileRule(rule, 'allow', this.knownTools))
|
|
464
508
|
this.invalidateCache()
|
|
465
509
|
}
|
|
466
510
|
|
|
467
511
|
deny(rule: string): void {
|
|
468
|
-
this.denyRules.push(compileRule(rule, 'deny'))
|
|
512
|
+
this.denyRules.push(compileRule(rule, 'deny', this.knownTools))
|
|
469
513
|
this.invalidateCache()
|
|
470
514
|
}
|
|
471
515
|
|
|
472
516
|
ask(rule: string): void {
|
|
473
|
-
this.askRules.push(compileRule(rule, 'ask'))
|
|
517
|
+
this.askRules.push(compileRule(rule, 'ask', this.knownTools))
|
|
474
518
|
this.invalidateCache()
|
|
475
519
|
}
|
|
476
520
|
|
|
@@ -501,10 +545,10 @@ export class PermissionSystem {
|
|
|
501
545
|
this.askRules = []
|
|
502
546
|
|
|
503
547
|
for (const rule of config.allow) {
|
|
504
|
-
this.allowRules.push(compileRule(rule, 'allow'))
|
|
548
|
+
this.allowRules.push(compileRule(rule, 'allow', this.knownTools))
|
|
505
549
|
}
|
|
506
550
|
for (const rule of config.deny) {
|
|
507
|
-
this.denyRules.push(compileRule(rule, 'deny'))
|
|
551
|
+
this.denyRules.push(compileRule(rule, 'deny', this.knownTools))
|
|
508
552
|
}
|
|
509
553
|
|
|
510
554
|
this.invalidateCache()
|
|
@@ -1049,7 +1093,11 @@ export class PermissionSystem {
|
|
|
1049
1093
|
} else {
|
|
1050
1094
|
const rule = toolNameOrRule
|
|
1051
1095
|
if (rule.pattern) {
|
|
1052
|
-
const entry = compileRule(
|
|
1096
|
+
const entry = compileRule(
|
|
1097
|
+
rule.pattern,
|
|
1098
|
+
rule.level === 'bypass' ? 'allow' : 'ask',
|
|
1099
|
+
this.knownTools,
|
|
1100
|
+
)
|
|
1053
1101
|
if (rule.level === 'bypass') this.allowRules.push(entry)
|
|
1054
1102
|
else this.askRules.push(entry)
|
|
1055
1103
|
} else {
|
package/src/daemon/server.ts
CHANGED
|
@@ -111,9 +111,14 @@ function resolveDaemonPermission(): PermissionMode {
|
|
|
111
111
|
export function buildDaemonPermission(
|
|
112
112
|
restrictions?: PermissionRestrictions,
|
|
113
113
|
rules?: { allow?: string[]; deny?: string[] },
|
|
114
|
+
tools?: Iterable<string>,
|
|
114
115
|
): PermissionSystem {
|
|
115
116
|
const permission = new PermissionSystem(resolveDaemonPermission())
|
|
116
117
|
if (restrictions) permission.setRestrictions(restrictions)
|
|
118
|
+
// Before the rules, like the CLI entry: the verdict is stamped at compile time.
|
|
119
|
+
// Without it a `permissionRules` typo in `config.yml` stays a silent dead rule in
|
|
120
|
+
// the daemon — the same failure, one wiring site over.
|
|
121
|
+
if (tools) permission.setKnownTools(tools)
|
|
117
122
|
if (rules) {
|
|
118
123
|
for (const rule of rules.allow ?? []) permission.allow(rule)
|
|
119
124
|
for (const rule of rules.deny ?? []) permission.deny(rule)
|
|
@@ -269,6 +274,7 @@ export function createServer(config: ServerConfig): Server<WsData> {
|
|
|
269
274
|
const permission = buildDaemonPermission(
|
|
270
275
|
daemonConfig.permissionRestrictions,
|
|
271
276
|
daemonConfig.permissionRules,
|
|
277
|
+
sharedTools.keys(),
|
|
272
278
|
)
|
|
273
279
|
// After `setRestrictions` (inside the builder) so this goes through the same clamp the
|
|
274
280
|
// first engine did — see `sessionModes`. Absent entry ⇒ env mode, unchanged.
|
package/src/index.tsx
CHANGED
|
@@ -791,6 +791,13 @@ export async function runApp(options: RunOptions): Promise<void> {
|
|
|
791
791
|
// `config.permission` / `permissionRestrictions` are applied up top, on the instance
|
|
792
792
|
// handed to `new QueryEngine(...)` — the same one whose mode the system prompt reads.
|
|
793
793
|
|
|
794
|
+
// Hand the registry's tool names to the permission system **before** any rule is
|
|
795
|
+
// loaded, so a plain-name rule is judged on existence and not only on structure
|
|
796
|
+
// (`bash` / `bahs` are structurally fine and match nothing — see `setKnownTools`).
|
|
797
|
+
// `mcp__` names are exempt inside `validateRulePattern`: those servers are still
|
|
798
|
+
// connecting in the background at this point.
|
|
799
|
+
engine.getPermission().setKnownTools(tools.keys())
|
|
800
|
+
|
|
794
801
|
// Apply user-defined permission rules (allow/deny) — wire the rule system into runtime
|
|
795
802
|
if (config.permissionRules) {
|
|
796
803
|
for (const rule of config.permissionRules.allow ?? []) engine.getPermission().allow(rule)
|
|
@@ -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.22' as const
|
|
13
13
|
|
|
14
14
|
/** npm install 全局安装命令 */
|
|
15
15
|
export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` 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 = 4247 as const
|