@miphamai/cli 0.85.54 → 0.85.56
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/agent/sub-agent.ts +18 -2
- package/src/agent/types.ts +9 -0
- package/src/config/loader.ts +60 -0
- package/src/core/approval-prompt.ts +123 -0
- package/src/core/command-taps.ts +10 -0
- package/src/core/engine.ts +492 -25
- package/src/core/instructions.ts +1 -1
- package/src/core/permission-classifier.ts +66 -6
- package/src/core/permission.ts +2 -1
- package/src/core/review-gate.ts +192 -0
- package/src/core/task-performance-tasks.json +18 -0
- package/src/core/user-intent.ts +91 -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/i18n-core/locales/en-US.json +14 -1
- package/src/i18n-core/locales/zh-CN.json +14 -1
- package/src/index.tsx +25 -0
- 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/tools/agent/skill.ts +1 -0
- package/src/tools/agent/workflow.ts +1 -0
- package/src/ui/app.tsx +49 -1
- package/src/ui/approval-prompt.tsx +107 -0
- package/src/ui/commands.ts +8 -0
- package/src/workflow/primitives/agent.ts +4 -1
- package/src/workflow/runtime.ts +4 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mipham Code v0.85.
|
|
1
|
+
# Mipham Code v0.85.56
|
|
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
package/src/agent/sub-agent.ts
CHANGED
|
@@ -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
|
package/src/agent/types.ts
CHANGED
|
@@ -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
|
/**
|
package/src/config/loader.ts
CHANGED
|
@@ -1023,6 +1023,66 @@ export function loadDisabledMcpServers(): Set<string> {
|
|
|
1023
1023
|
}
|
|
1024
1024
|
}
|
|
1025
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
|
+
|
|
1026
1086
|
/**
|
|
1027
1087
|
* Persist the full disabled-server set (sorted, deduped). An empty set removes
|
|
1028
1088
|
* the key entirely, so "never disabled anything" and "edited it back" look the
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interactive approval prompt — the other half of Claude Code parity.
|
|
3
|
+
*
|
|
4
|
+
* Mipham's `default` mode has always behaved like CC's `dontAsk`: there is no
|
|
5
|
+
* prompt behind the gate, so an `ask` is a flat refusal and the user has to
|
|
6
|
+
* either switch modes (Shift+Tab) or pre-approve the tool with
|
|
7
|
+
* `/permissions allow`. CC's `default` instead *asks*. This module is the seam
|
|
8
|
+
* that lets the CLI do the same, and it is deliberately only a seam: the
|
|
9
|
+
* engine, the Ink UI and the tests each own one side of it.
|
|
10
|
+
*
|
|
11
|
+
* ## What may be prompted
|
|
12
|
+
*
|
|
13
|
+
* Only an ordinary `ask` in a prompting mode. A decision a human already wrote
|
|
14
|
+
* down (`deny-rule`) is never negotiable, the structural gates
|
|
15
|
+
* (`dangerous-rm`, `world-writable-chmod`) refuse an *outcome* no allow rule can
|
|
16
|
+
* bound, and `plan` / `auto` / `bypassPermissions` keep their existing meaning.
|
|
17
|
+
* The allowlist lives here so the engine and any future caller cannot drift.
|
|
18
|
+
*
|
|
19
|
+
* ## What "always allow" writes
|
|
20
|
+
*
|
|
21
|
+
* The narrowest rule that still covers the call. For Bash that means an
|
|
22
|
+
* **exact command** — and only for a simple command: `Bash(cat:*)` does not
|
|
23
|
+
* cover `cat x | jq .` (an allow rule must match every segment), and a
|
|
24
|
+
* full-line pattern matches no segment at all. When no honest rule exists we
|
|
25
|
+
* offer no standing option rather than persist one that can never fire.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { PermissionDenialReason } from './permission'
|
|
29
|
+
import type { PermissionMode, ToolDefinition } from '../shared/index.ts'
|
|
30
|
+
import { validateRulePattern } from './permission-rules'
|
|
31
|
+
|
|
32
|
+
export type ApprovalChoice = 'allow-once' | 'allow-always' | 'deny'
|
|
33
|
+
|
|
34
|
+
export interface ApprovalRequest {
|
|
35
|
+
tool: string
|
|
36
|
+
input: Record<string, unknown>
|
|
37
|
+
mode: PermissionMode
|
|
38
|
+
reason: PermissionDenialReason
|
|
39
|
+
/** The exact user-level rule "always allow" would persist, when one can be derived. */
|
|
40
|
+
rule?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ApprovalPrompter = (request: ApprovalRequest) => Promise<ApprovalChoice>
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Reasons that are a *refusal*, not an approval request.
|
|
47
|
+
*
|
|
48
|
+
* `deny-rule` — a human wrote it; overriding it from a prompt would make the
|
|
49
|
+
* one rule that outranks every mode negotiable.
|
|
50
|
+
* `dangerous-rm` / `world-writable-chmod` — the call does not name what it will
|
|
51
|
+
* affect, so no allow rule can bound the outcome.
|
|
52
|
+
* `classifier-deny` — `auto` mode's ruling; `auto` never prompts.
|
|
53
|
+
*/
|
|
54
|
+
const NON_PROMPTABLE: ReadonlySet<PermissionDenialReason> = new Set<PermissionDenialReason>([
|
|
55
|
+
'deny-rule',
|
|
56
|
+
'dangerous-rm',
|
|
57
|
+
'world-writable-chmod',
|
|
58
|
+
'classifier-deny',
|
|
59
|
+
])
|
|
60
|
+
|
|
61
|
+
/** Modes in which a human is present to answer. */
|
|
62
|
+
const PROMPTING_MODES: ReadonlySet<PermissionMode> = new Set<PermissionMode>([
|
|
63
|
+
'default',
|
|
64
|
+
'acceptEdits',
|
|
65
|
+
])
|
|
66
|
+
|
|
67
|
+
export function isPromptable(
|
|
68
|
+
mode: PermissionMode,
|
|
69
|
+
reason: PermissionDenialReason | undefined,
|
|
70
|
+
): boolean {
|
|
71
|
+
if (!reason) return false
|
|
72
|
+
return PROMPTING_MODES.has(mode) && !NON_PROMPTABLE.has(reason)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Constructs that make a shell line more than one command. An exact-command
|
|
77
|
+
* allow rule cannot cover them (see the module header), so no standing rule is
|
|
78
|
+
* offered. Conservative on purpose: a false positive costs one extra prompt,
|
|
79
|
+
* a false negative writes a rule that never fires.
|
|
80
|
+
*/
|
|
81
|
+
const SHELL_COMPOUND = /[;&|<>`\n\r]|\$\(|\(|\)/
|
|
82
|
+
|
|
83
|
+
function valid(rule: string, knownTools: ReadonlySet<string> | undefined): boolean {
|
|
84
|
+
return validateRulePattern(rule, knownTools) === null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The rule "always allow" should persist, or `undefined` when no honest one
|
|
89
|
+
* exists.
|
|
90
|
+
*
|
|
91
|
+
* `knownTools` is passed through to the validator so a rule naming a tool the
|
|
92
|
+
* permission system does not know is rejected here rather than persisted as a
|
|
93
|
+
* silent no-op.
|
|
94
|
+
*/
|
|
95
|
+
export function deriveAllowRule(
|
|
96
|
+
tool: Pick<ToolDefinition, 'name'>,
|
|
97
|
+
input: Record<string, unknown>,
|
|
98
|
+
knownTools?: ReadonlySet<string>,
|
|
99
|
+
): string | undefined {
|
|
100
|
+
if (tool.name === 'Bash') {
|
|
101
|
+
if (typeof input.command !== 'string') return undefined
|
|
102
|
+
const command = input.command
|
|
103
|
+
if (!command.trim()) return undefined
|
|
104
|
+
// A simple command only: a compound line's allow rule must match every
|
|
105
|
+
// segment, and a full-line pattern matches none of them.
|
|
106
|
+
if (SHELL_COMPOUND.test(command)) return undefined
|
|
107
|
+
const rule = `Bash(${command})`
|
|
108
|
+
return valid(rule, knownTools) ? rule : undefined
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (tool.name === 'Edit' || tool.name === 'Write') {
|
|
112
|
+
const filePath = input.file_path
|
|
113
|
+
if (typeof filePath === 'string' && filePath.trim()) {
|
|
114
|
+
const scoped = `${tool.name}(${filePath})`
|
|
115
|
+
if (valid(scoped, knownTools)) return scoped
|
|
116
|
+
}
|
|
117
|
+
return valid(tool.name, knownTools) ? tool.name : undefined
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// MCP tools are advertised by exact name; a server-wide grant
|
|
121
|
+
// (`mcp__server__*`) is deliberately not derived from one call.
|
|
122
|
+
return valid(tool.name, knownTools) ? tool.name : undefined
|
|
123
|
+
}
|
|
@@ -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
|
+
}
|