@miphamai/cli 0.85.33 → 0.85.35
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/services.ts +21 -0
- package/src/agent/sub-agent.ts +129 -21
- package/src/commands/environment.ts +14 -11
- package/src/commands/project.ts +43 -12
- package/src/config/loader.ts +65 -35
- package/src/core/alignment-vocabulary.json +2 -2
- package/src/core/constitution-loader.ts +85 -24
- package/src/core/context.ts +22 -5
- package/src/core/engine.ts +62 -143
- package/src/core/hooks-config.ts +32 -0
- package/src/core/memory/memory-loader.ts +2 -2
- package/src/core/permission-rules.ts +67 -12
- package/src/core/session-log.ts +26 -7
- package/src/core/session-store.ts +4 -3
- package/src/core/tool-gate.ts +222 -0
- package/src/daemon/engine-capabilities.ts +124 -2
- package/src/daemon/remote-engine.ts +3 -0
- package/src/daemon/server.ts +13 -1
- package/src/i18n-core/locales/en-US.json +1 -0
- package/src/i18n-core/locales/zh-CN.json +1 -0
- package/src/mcp/client.ts +22 -2
- package/src/plugin/plugin-manager.ts +14 -0
- package/src/shared/package-info.ts +2 -2
- package/src/shared/types.ts +8 -0
- package/src/skills/fork-executor.ts +11 -1
- package/src/skills/marketplace.ts +44 -13
- package/src/skills/registry.ts +12 -1
- package/src/tools/agent/agent.ts +3 -0
- package/src/tools/agent/enter-plan.ts +22 -4
- package/src/tools/agent/exit-plan.ts +9 -1
- package/src/tools/agent/skill.ts +1 -0
- package/src/tools/agent/workflow.ts +1 -0
- package/src/tools/exec/git.ts +113 -69
- package/src/tools/index.ts +2 -2
- package/src/ui/app.tsx +15 -0
- package/src/ui/chat.tsx +7 -4
- package/src/ui/commands.ts +140 -20
- package/src/workflow/primitives/agent.ts +12 -1
- package/src/workflow/primitives/loop.ts +14 -0
- package/src/workflow/primitives/verify.ts +13 -1
- package/src/workflow/runtime.ts +1 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mipham Code v0.85.
|
|
1
|
+
# Mipham Code v0.85.35
|
|
2
2
|
|
|
3
3
|
**Multi-model open-core intelligent coding terminal** — 12 AI providers, 138 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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { InferenceHookConfig } from '../shared/index.ts'
|
|
2
|
+
import type { ToolGateDeps } from '../core/tool-gate'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Services the engine hands to every sub-agent it can reach.
|
|
6
|
+
*
|
|
7
|
+
* The five production construction sites (`tools/agent/agent.ts`,
|
|
8
|
+
* `skills/fork-executor.ts`, `workflow/primitives/agent.ts`, and the two in
|
|
9
|
+
* `ui/commands.ts`) each used to decide for themselves what a sub-agent got.
|
|
10
|
+
* They all decided to pass `undefined`: the hook engine never reached a
|
|
11
|
+
* sub-agent, and the constitution / SIS / CRSI chain was never called there at
|
|
12
|
+
* all. Carrying the bundle on `ToolContext` and on the workflow runtime's
|
|
13
|
+
* engine stub makes the engine the single producer instead of leaving five
|
|
14
|
+
* copies of the same decision to drift.
|
|
15
|
+
*/
|
|
16
|
+
export interface SubAgentServices {
|
|
17
|
+
/** Pre-execution gates — same chain the engine's own tool loop runs. */
|
|
18
|
+
gate: ToolGateDeps
|
|
19
|
+
/** PreInference DLP config. Absent means the organization did not enable it. */
|
|
20
|
+
inferenceHook?: InferenceHookConfig
|
|
21
|
+
}
|
package/src/agent/sub-agent.ts
CHANGED
|
@@ -15,6 +15,9 @@ import { PatternAnalyzer } from './pattern-analyzer.js'
|
|
|
15
15
|
import { getWorkspaceTrust } from '../core/workspace-trust'
|
|
16
16
|
import { recordToolCall } from '../telemetry/index'
|
|
17
17
|
import type { ExperienceRuleEngine } from '../core/rule-engine.js'
|
|
18
|
+
import { runPreToolGate } from '../core/tool-gate'
|
|
19
|
+
import { buildRequest, sendInferenceCheck, isInferenceHookEnabled } from '../core/inference-hook'
|
|
20
|
+
import type { SubAgentServices } from './services'
|
|
18
21
|
|
|
19
22
|
// Singleton instances (created lazily)
|
|
20
23
|
let _patternAnalyzer: PatternAnalyzer | undefined
|
|
@@ -89,8 +92,25 @@ export class SubAgent {
|
|
|
89
92
|
private hookEngine?: HookEngine,
|
|
90
93
|
private ruleEngine?: ExperienceRuleEngine,
|
|
91
94
|
private llm?: Llm,
|
|
95
|
+
/**
|
|
96
|
+
* What the engine handed down so this loop runs the same gates as
|
|
97
|
+
* `Engine.executeTool`: hooks, CRSI rules, SIS preflight, the constitution,
|
|
98
|
+
* and the PreInference DLP checkpoint. Absent means "no engine in reach"
|
|
99
|
+
* (tests, a hand-built runtime) — the fallback is the positional
|
|
100
|
+
* `hookEngine`, which is all this loop used to have.
|
|
101
|
+
*/
|
|
102
|
+
private services?: SubAgentServices,
|
|
92
103
|
) {}
|
|
93
104
|
|
|
105
|
+
/**
|
|
106
|
+
* The hook engine to use. `services` wins when present — it comes straight
|
|
107
|
+
* from the engine, and the positional `hookEngine` is only ever populated by
|
|
108
|
+
* callers that predate it.
|
|
109
|
+
*/
|
|
110
|
+
private get hooks(): HookEngine | undefined {
|
|
111
|
+
return this.services?.gate.hookEngine ?? this.hookEngine
|
|
112
|
+
}
|
|
113
|
+
|
|
94
114
|
/**
|
|
95
115
|
* Execute a sub-agent task.
|
|
96
116
|
*
|
|
@@ -107,8 +127,8 @@ export class SubAgent {
|
|
|
107
127
|
const agentType = options.type || 'general'
|
|
108
128
|
|
|
109
129
|
// ── Fire SubagentStart hook ──
|
|
110
|
-
if (this.
|
|
111
|
-
await this.
|
|
130
|
+
if (this.hooks) {
|
|
131
|
+
await this.hooks.executeSubagentStart(agentType, description, 'sub-agent')
|
|
112
132
|
}
|
|
113
133
|
|
|
114
134
|
// ── Background execution path ──
|
|
@@ -127,8 +147,8 @@ export class SubAgent {
|
|
|
127
147
|
|
|
128
148
|
// Register completion callback for hook firing
|
|
129
149
|
bgRegistry.onComplete(taskId, (task) => {
|
|
130
|
-
if (this.
|
|
131
|
-
void this.
|
|
150
|
+
if (this.hooks) {
|
|
151
|
+
void this.hooks.executeSubagentStop(
|
|
132
152
|
agentType,
|
|
133
153
|
description,
|
|
134
154
|
taskId,
|
|
@@ -176,8 +196,8 @@ export class SubAgent {
|
|
|
176
196
|
// controller for it; without passing it down the run ignores every check
|
|
177
197
|
// inside `runExecution` and cannot be stopped from the dashboard.
|
|
178
198
|
const result = await this.runExecution(prompt, options, options.signal)
|
|
179
|
-
if (this.
|
|
180
|
-
await this.
|
|
199
|
+
if (this.hooks) {
|
|
200
|
+
await this.hooks.executeSubagentStop(agentType, description, 'sub-agent', true, result)
|
|
181
201
|
}
|
|
182
202
|
this.logSuccessExperience(agentType, description, result, options.agentDef)
|
|
183
203
|
|
|
@@ -201,8 +221,8 @@ export class SubAgent {
|
|
|
201
221
|
|
|
202
222
|
return result
|
|
203
223
|
} catch (err) {
|
|
204
|
-
if (this.
|
|
205
|
-
await this.
|
|
224
|
+
if (this.hooks) {
|
|
225
|
+
await this.hooks.executeSubagentStop(
|
|
206
226
|
agentType,
|
|
207
227
|
description,
|
|
208
228
|
'sub-agent',
|
|
@@ -514,6 +534,8 @@ export class SubAgent {
|
|
|
514
534
|
// Kept outside the loop because the answer the caller receives is the last
|
|
515
535
|
// turn's text, so that is the turn whose completeness matters.
|
|
516
536
|
let lastTurnTruncated = false
|
|
537
|
+
/** One extra request per run, only after a final answer hit the ceiling. */
|
|
538
|
+
let truncationRetryUsed = false
|
|
517
539
|
|
|
518
540
|
try {
|
|
519
541
|
for (let turn = 0; turn < MAX_TOOL_TURNS; turn++) {
|
|
@@ -561,6 +583,35 @@ export class SubAgent {
|
|
|
561
583
|
}))
|
|
562
584
|
: undefined
|
|
563
585
|
|
|
586
|
+
// ── PreInference DLP checkpoint ──
|
|
587
|
+
//
|
|
588
|
+
// The same check the engine runs before each request. This loop is a
|
|
589
|
+
// second inference path, and until now it reached the provider without
|
|
590
|
+
// passing the organization's egress hook at all: the main loop's
|
|
591
|
+
// requests were inspected, every sub-agent request was not.
|
|
592
|
+
if (this.services && isInferenceHookEnabled(this.services.inferenceHook)) {
|
|
593
|
+
const hookConfig = this.services.inferenceHook!
|
|
594
|
+
let providerId = ''
|
|
595
|
+
try {
|
|
596
|
+
providerId = this.registry.getActive().config.id
|
|
597
|
+
} catch {
|
|
598
|
+
// A hand-built registry in tests may not implement `getActive`.
|
|
599
|
+
// An empty provider name is worse than the real one, but it does
|
|
600
|
+
// not skip the check — the messages still go to the hook.
|
|
601
|
+
}
|
|
602
|
+
const request = buildRequest(
|
|
603
|
+
currentMessages,
|
|
604
|
+
'sub-agent',
|
|
605
|
+
providerId,
|
|
606
|
+
finalModel,
|
|
607
|
+
hookConfig.organization_id,
|
|
608
|
+
)
|
|
609
|
+
const verdict = await sendInferenceCheck(hookConfig, request)
|
|
610
|
+
if (!verdict.allowed) {
|
|
611
|
+
throw new Error(verdict.reason || 'Blocked by the pre-inference DLP check.')
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
564
615
|
for await (const chunk of (this.llm ?? this.registry).chat({
|
|
565
616
|
model: finalModel,
|
|
566
617
|
messages: currentMessages,
|
|
@@ -625,8 +676,36 @@ export class SubAgent {
|
|
|
625
676
|
// that never finished, and the model never saw their results.
|
|
626
677
|
if (streamError) break
|
|
627
678
|
|
|
628
|
-
// No tools used — we're done
|
|
629
|
-
|
|
679
|
+
// No tools used — we're done, unless the answer was cut off.
|
|
680
|
+
//
|
|
681
|
+
// A truncated turn looks finished: real text, a normal stop. Returning
|
|
682
|
+
// it means the caller gets a half-sentence as the verdict. One more
|
|
683
|
+
// request, telling the model exactly what happened, usually gets the
|
|
684
|
+
// whole answer back in fewer tokens than the first attempt spent. Only
|
|
685
|
+
// once: a model that hits the ceiling again has nothing better to give,
|
|
686
|
+
// and the marker below still says the result is partial. The partial
|
|
687
|
+
// text is handed back as the assistant's own turn so the retry can
|
|
688
|
+
// condense it rather than start from nothing.
|
|
689
|
+
if (toolUses.length === 0) {
|
|
690
|
+
if (turnTruncated && !truncationRetryUsed) {
|
|
691
|
+
truncationRetryUsed = true
|
|
692
|
+
// The retry replaces this text; keeping both would concatenate a
|
|
693
|
+
// half answer with the full one.
|
|
694
|
+
chunks.pop()
|
|
695
|
+
currentMessages = [
|
|
696
|
+
...currentMessages,
|
|
697
|
+
{ role: 'assistant' as const, content: turnText },
|
|
698
|
+
{
|
|
699
|
+
role: 'user' as const,
|
|
700
|
+
content:
|
|
701
|
+
'Your previous answer was cut off by the output limit. ' +
|
|
702
|
+
'Return the complete answer again, more concisely.',
|
|
703
|
+
},
|
|
704
|
+
]
|
|
705
|
+
continue
|
|
706
|
+
}
|
|
707
|
+
break
|
|
708
|
+
}
|
|
630
709
|
|
|
631
710
|
// Execute tools and build follow-up messages
|
|
632
711
|
currentMessages = [
|
|
@@ -660,14 +739,32 @@ export class SubAgent {
|
|
|
660
739
|
continue
|
|
661
740
|
}
|
|
662
741
|
|
|
663
|
-
// ──
|
|
742
|
+
// ── Pre-execution gates (before the permission check) ──
|
|
743
|
+
//
|
|
744
|
+
// Same chain `Engine.executeTool` runs, from the same definition
|
|
745
|
+
// (`core/tool-gate.ts`): PreToolUse hook → CRSI rules → SIS preflight →
|
|
746
|
+
// constitution → self-critique. This loop used to run only the hook
|
|
747
|
+
// (and only when a hook engine had been passed in, which no production
|
|
748
|
+
// call site did), so a `Write` the main loop refused for leaking a
|
|
749
|
+
// credential executed verbatim one level down.
|
|
664
750
|
let effectiveInput = tu.input
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
751
|
+
let gateWarnings: string[] = []
|
|
752
|
+
if (this.services) {
|
|
753
|
+
const outcome = await runPreToolGate(tu.name, tu.input, this.services.gate, 'sub-agent')
|
|
754
|
+
if (!outcome.ok) {
|
|
755
|
+
currentMessages.push({
|
|
756
|
+
role: 'user' as const,
|
|
757
|
+
content: `Tool "${tu.name}" blocked: ${outcome.error}`,
|
|
758
|
+
})
|
|
759
|
+
continue
|
|
760
|
+
}
|
|
761
|
+
effectiveInput = outcome.params
|
|
762
|
+
gateWarnings = outcome.warnings
|
|
763
|
+
} else if (this.hooks) {
|
|
764
|
+
// Legacy path: a caller that built a SubAgent by hand with only a
|
|
765
|
+
// hook engine still gets its PreToolUse hook. The other four gates
|
|
766
|
+
// need dependencies this path cannot reach.
|
|
767
|
+
const preResult = await this.hooks.executePreToolUse(tu.name, tu.input, 'sub-agent')
|
|
671
768
|
if (!preResult.allowed) {
|
|
672
769
|
const denialMsg = preResult.reason
|
|
673
770
|
? `Tool "${tu.name}" blocked by PreToolUse hook: ${preResult.reason}`
|
|
@@ -737,8 +834,8 @@ export class SubAgent {
|
|
|
737
834
|
|
|
738
835
|
// ── P0-5: Run PostToolUse hooks ──
|
|
739
836
|
let displayResult = result
|
|
740
|
-
if (this.
|
|
741
|
-
const postResult = await this.
|
|
837
|
+
if (this.hooks) {
|
|
838
|
+
const postResult = await this.hooks.executePostToolUse(
|
|
742
839
|
tu.name,
|
|
743
840
|
effectiveInput,
|
|
744
841
|
result,
|
|
@@ -763,6 +860,17 @@ export class SubAgent {
|
|
|
763
860
|
{ type: 'tool_use' as const, id: tu.id, name: tu.name, input: effectiveInput },
|
|
764
861
|
],
|
|
765
862
|
})
|
|
863
|
+
// A gate's warning (hook `additionalContext`, a CRSI rule, an SIS
|
|
864
|
+
// `fix`) is how the model learns the call went through under a
|
|
865
|
+
// caution. The engine prepends them to a successful result; without
|
|
866
|
+
// the same line here the warnings were produced and dropped.
|
|
867
|
+
if (gateWarnings.length > 0 && displayResult.success) {
|
|
868
|
+
displayResult = {
|
|
869
|
+
...displayResult,
|
|
870
|
+
content: gateWarnings.join('\n') + '\n' + (displayResult.content || ''),
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
766
874
|
currentMessages.push({
|
|
767
875
|
role: 'user' as const,
|
|
768
876
|
content: [
|
|
@@ -778,8 +886,8 @@ export class SubAgent {
|
|
|
778
886
|
})
|
|
779
887
|
} catch (err) {
|
|
780
888
|
// ── P0-5: Run PostToolUseFailure hooks ──
|
|
781
|
-
if (this.
|
|
782
|
-
this.
|
|
889
|
+
if (this.hooks) {
|
|
890
|
+
this.hooks
|
|
783
891
|
.executePostToolUseFailure(tu.name, effectiveInput, String(err), 'sub-agent')
|
|
784
892
|
.catch(() => {
|
|
785
893
|
// Hook failures never block execution
|
|
@@ -193,24 +193,27 @@ const terminalSetupCmd: CommandHandler = async () => {
|
|
|
193
193
|
mkdirSync(miphamDir, { recursive: true })
|
|
194
194
|
|
|
195
195
|
const shellScript = join(miphamDir, 'shell-setup.sh')
|
|
196
|
+
// 这个文件从前写三样东西,一样都不生效 —— 其中一样还有害:
|
|
197
|
+
// • `export MIPHAM_HOME=…` —— `miphamHome()` 只用 `homedir()`,从不读这个变量;
|
|
198
|
+
// • `export MIPHAM_PROVIDER=$(grep …)` —— 全仓库零读者;
|
|
199
|
+
// • `alias mipham='cd $(pwd) && npm install -g … > /dev/null 2>&1; mipham'` ——
|
|
200
|
+
// `cd $(pwd)` 是空操作,剩下那半是**每次敲 `mipham` 都静默重装一遍全局包**,
|
|
201
|
+
// 而 `npm install -g` 没有原子换手:中途被打断就一个 CLI 都不剩,且错误全被丢掉。
|
|
202
|
+
// CLI 自己读 `~/.mipham/config.yml`,shell 这边没有什么需要导出的;写清楚这件事,
|
|
203
|
+
// 比塞进三条看着像配置、实则不改任何行为的行更有用。重跑本命令会把旧文件覆盖掉。
|
|
196
204
|
const shellContent = [
|
|
197
205
|
'#!/bin/bash',
|
|
198
206
|
'# Mipham Code — Shell Integration',
|
|
199
207
|
'# Source this file in your shell profile:',
|
|
200
208
|
'# source ~/.mipham/shell-setup.sh',
|
|
201
209
|
'',
|
|
202
|
-
|
|
210
|
+
'# Mipham Code needs no environment variables: the home directory, the default',
|
|
211
|
+
'# provider and the API keys are all read from ~/.mipham/config.yml by the CLI',
|
|
212
|
+
'# itself. The only thing a shell profile may need is PATH to `mipham`, which',
|
|
213
|
+
'# the installer already sets up.',
|
|
203
214
|
'',
|
|
204
|
-
'#
|
|
205
|
-
|
|
206
|
-
'',
|
|
207
|
-
'# Or use the local development version:',
|
|
208
|
-
'# alias mipham="bun run /path/to/mipham-code/apps/cli/bin/mipham"',
|
|
209
|
-
'',
|
|
210
|
-
'# Auto-detect provider from config',
|
|
211
|
-
'if [ -f ~/.mipham/config.yml ]; then',
|
|
212
|
-
' export MIPHAM_PROVIDER=$(grep "defaultProvider:" ~/.mipham/config.yml | awk "{print \$2}")',
|
|
213
|
-
'fi',
|
|
215
|
+
'# Local development build, side by side with the installed one:',
|
|
216
|
+
'# alias mipham-dev="bun run /path/to/mipham-code/apps/cli/bin/mipham"',
|
|
214
217
|
].join('\n')
|
|
215
218
|
atomicWriteFileSync(shellScript, shellContent + '\n', { mode: 0o644 })
|
|
216
219
|
lines.push(` ✅ Generated: ${shellScript}`)
|
package/src/commands/project.ts
CHANGED
|
@@ -1191,16 +1191,50 @@ const securityCmd: CommandHandler = async () => {
|
|
|
1191
1191
|
|
|
1192
1192
|
// 2. Check for hardcoded secrets (quick grep for common patterns)
|
|
1193
1193
|
// ⚠ Security: results are redacted — only file:line locations are shown, never values
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1194
|
+
// 「grep 没找到」与「grep 没跑起来」必须分开。原来的判据是一条 shell 管道,
|
|
1195
|
+
// 末尾的 `|| echo ""` 把**任何**非零退出都变成空输出,外层 catch 又把异常说成
|
|
1196
|
+
// 「No hardcoded secrets detected (quick scan)」—— 没装 grep、正则写错、扫到一半
|
|
1197
|
+
// 超时,全都渲染成 ✅ 干净。argv 化之后退出码是精确的:1 = 无匹配(干净),
|
|
1198
|
+
// 2+ = 出错(没查),没有退出码 = 根本没跑起来(超时/被杀)。后两者进 findings。
|
|
1199
|
+
{
|
|
1200
|
+
const { execFileSync } = await import('node:child_process')
|
|
1201
|
+
let raw = ''
|
|
1202
|
+
let scanError: string | null = null
|
|
1203
|
+
try {
|
|
1204
|
+
raw = execFileSync(
|
|
1205
|
+
'grep',
|
|
1206
|
+
[
|
|
1207
|
+
'-rIn',
|
|
1208
|
+
'--include=*.ts',
|
|
1209
|
+
'--include=*.js',
|
|
1210
|
+
'--include=*.yml',
|
|
1211
|
+
'--include=*.yaml',
|
|
1212
|
+
'--include=*.json',
|
|
1213
|
+
'-E',
|
|
1214
|
+
`(API_KEY|SECRET|PASSWORD|TOKEN)\\s*=\\s*['"][^$]`,
|
|
1215
|
+
cwd,
|
|
1216
|
+
],
|
|
1217
|
+
{ encoding: 'utf-8', timeout: 5000, maxBuffer: 4 * 1024 * 1024 },
|
|
1218
|
+
)
|
|
1219
|
+
} catch (err) {
|
|
1220
|
+
const status = (err as { status?: number | null }).status
|
|
1221
|
+
// 1 是 grep 的正常「无匹配」语义,不是错误。
|
|
1222
|
+
if (status !== 1) {
|
|
1223
|
+
scanError = err instanceof Error ? err.message.split('\n')[0]! : String(err)
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
const hits = raw
|
|
1227
|
+
.split('\n')
|
|
1228
|
+
.filter((l) => l.length > 0 && !l.includes('node_modules') && !/\/\.git\//.test(l))
|
|
1229
|
+
.slice(0, 5)
|
|
1230
|
+
|
|
1231
|
+
if (scanError) {
|
|
1232
|
+
findings.push(
|
|
1233
|
+
`⚠ Could not scan for hardcoded secrets (${scanError}) — this is **not** a clean result`,
|
|
1234
|
+
)
|
|
1235
|
+
} else if (hits.length > 0) {
|
|
1201
1236
|
// Redact the actual values — only show file:line locations
|
|
1202
|
-
const redacted =
|
|
1203
|
-
.split('\n')
|
|
1237
|
+
const redacted = hits
|
|
1204
1238
|
.map((l) => {
|
|
1205
1239
|
const colonIdx = l.indexOf(':')
|
|
1206
1240
|
const secondColon = l.indexOf(':', colonIdx + 1)
|
|
@@ -1216,9 +1250,6 @@ const securityCmd: CommandHandler = async () => {
|
|
|
1216
1250
|
} else {
|
|
1217
1251
|
ok.push('No hardcoded secrets detected')
|
|
1218
1252
|
}
|
|
1219
|
-
} catch {
|
|
1220
|
-
// grep may fail if no matches — that's good
|
|
1221
|
-
ok.push('No hardcoded secrets detected (quick scan)')
|
|
1222
1253
|
}
|
|
1223
1254
|
|
|
1224
1255
|
// 3. Check for TLS in dependencies
|
package/src/config/loader.ts
CHANGED
|
@@ -401,7 +401,7 @@ export function tryRestoreFromBackup(configPath: string): boolean {
|
|
|
401
401
|
* Scans both project-level (.mipham/mcp.json) and user-level (~/.mipham/mcp.json).
|
|
402
402
|
* Config.yml entries take precedence over .mcp.json entries with the same name.
|
|
403
403
|
*/
|
|
404
|
-
function loadMcpJson(cwd: string): McpServerConfig[] {
|
|
404
|
+
function loadMcpJson(cwd: string, warn?: (message: string) => void): McpServerConfig[] {
|
|
405
405
|
const servers: McpServerConfig[] = []
|
|
406
406
|
const searchPaths = [
|
|
407
407
|
join(cwd, MIPHAM_DIR, 'mcp.json'),
|
|
@@ -410,26 +410,46 @@ function loadMcpJson(cwd: string): McpServerConfig[] {
|
|
|
410
410
|
]
|
|
411
411
|
|
|
412
412
|
for (const path of searchPaths) {
|
|
413
|
+
let raw: string | null
|
|
413
414
|
try {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
415
|
+
raw = readRegularFileSync(path)
|
|
416
|
+
} catch (err) {
|
|
417
|
+
warn?.(`could not read ${path}: ${String(err)}`)
|
|
418
|
+
continue
|
|
419
|
+
}
|
|
420
|
+
if (raw === null) continue
|
|
421
421
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
422
|
+
let parsed: unknown
|
|
423
|
+
try {
|
|
424
|
+
parsed = JSON.parse(raw)
|
|
425
|
+
} catch (err) {
|
|
426
|
+
// A malformed file used to be skipped in silence, so every server it
|
|
427
|
+
// declared simply did not exist: the user saw "no such server" with no
|
|
428
|
+
// hint that the file they had just written was never read.
|
|
429
|
+
warn?.(
|
|
430
|
+
`${path} is not valid JSON and was skipped: ${err instanceof Error ? err.message : String(err)}`,
|
|
431
|
+
)
|
|
432
|
+
continue
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const mcpServers = (parsed as { mcpServers?: unknown } | null)?.mcpServers
|
|
436
|
+
if (mcpServers === undefined) continue
|
|
437
|
+
if (!mcpServers || typeof mcpServers !== 'object' || Array.isArray(mcpServers)) {
|
|
438
|
+
warn?.(`${path}: "mcpServers" must be an object — skipped`)
|
|
439
|
+
continue
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
for (const [name, cfg] of Object.entries(mcpServers as Record<string, unknown>)) {
|
|
443
|
+
// Avoid duplicates by name
|
|
444
|
+
if (servers.some((s) => s.name === name)) continue
|
|
445
|
+
if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg)) {
|
|
446
|
+
warn?.(`${path}: server "${name}" is not an object — skipped`)
|
|
447
|
+
continue
|
|
430
448
|
}
|
|
431
|
-
|
|
432
|
-
//
|
|
449
|
+
// Spread the whole entry rather than re-listing fields: hand-rebuilding
|
|
450
|
+
// the object silently dropped request_timeout_ms and auth.
|
|
451
|
+
const entry = cfg as Partial<McpServerConfig>
|
|
452
|
+
servers.push({ ...entry, name, args: entry.args || [] })
|
|
433
453
|
}
|
|
434
454
|
}
|
|
435
455
|
|
|
@@ -934,7 +954,9 @@ export function loadConfig(cwd: string = process.cwd()): MiphamConfig {
|
|
|
934
954
|
}
|
|
935
955
|
|
|
936
956
|
// ── Load .mcp.json servers (project + user level) ──
|
|
937
|
-
|
|
957
|
+
// 与其他加载期告警同一出口(`index.tsx` 也用 process.stderr.write 报被忽略的配置);
|
|
958
|
+
// console.error 在测试里会被 vitest 接管,读不到。
|
|
959
|
+
const mcpJsonServers = loadMcpJson(cwd, (m) => process.stderr.write(`⚠ Mipham Code: ${m}\n`))
|
|
938
960
|
if (mcpJsonServers.length > 0) {
|
|
939
961
|
const existingServers = config.skills?.mcpServers ?? []
|
|
940
962
|
// Merge: config.yml servers take precedence by name
|
|
@@ -1187,24 +1209,32 @@ function decryptProviderApiKeys(providers: ProviderConfig[] | undefined): void {
|
|
|
1187
1209
|
* decrypted. Used by `/keys view` to show the plaintext key on request.
|
|
1188
1210
|
*/
|
|
1189
1211
|
export function getProviderApiKey(providerId: string, cwd: string = process.cwd()): string | null {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1212
|
+
// 两个文件都看,用户级在前(与 `loadConfig` 的合并顺序一致:项目先、用户后,
|
|
1213
|
+
// 于是用户级覆盖项目级)。
|
|
1214
|
+
//
|
|
1215
|
+
// 从前这里是 `isRegularFile(user) ? user : project` —— **只读第一个存在的文件**。
|
|
1216
|
+
// 用户级 config.yml 一旦存在(几乎总是存在),项目级里配的那把 key 就永远读不到:
|
|
1217
|
+
// `/keys view` 说「没有这个 key」,而引擎侧(`loadConfig` 两级合并)正在用它。
|
|
1218
|
+
// 同一个状态,两个读者两种答案。
|
|
1219
|
+
const paths = [join(MIPHAM_HOME, 'config.yml'), join(cwd, MIPHAM_DIR, 'config.yml')]
|
|
1193
1220
|
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1221
|
+
for (const configPath of paths) {
|
|
1222
|
+
try {
|
|
1223
|
+
const raw = readRegularFileSync(configPath)
|
|
1224
|
+
if (raw === null) continue
|
|
1225
|
+
const doc = (parseYaml(raw) as Record<string, unknown>) || {}
|
|
1226
|
+
const providers = (doc.providers as Array<Record<string, unknown>>) || []
|
|
1227
|
+
const p = providers.find((x) => x.id === providerId)
|
|
1228
|
+
if (!p || typeof p.apiKey !== 'string') continue
|
|
1229
|
+
if (!p.apiKey.startsWith(ENC_PREFIX)) return p.apiKey
|
|
1230
|
+
// 解不开会抛 —— 落到 catch 报一句,再试下一份文件。
|
|
1231
|
+
return decryptApiKey(p.apiKey, getCredentialKey(MIPHAM_HOME))
|
|
1232
|
+
} catch (err: unknown) {
|
|
1233
|
+
const msg = err instanceof Error ? err.message : String(err)
|
|
1234
|
+
process.stderr.write(`⚠ Mipham Code: failed to read API key for "${providerId}": ${msg}\n`)
|
|
1235
|
+
}
|
|
1207
1236
|
}
|
|
1237
|
+
return null
|
|
1208
1238
|
}
|
|
1209
1239
|
|
|
1210
1240
|
/**
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"text": "禁止在代码、日志、配置文件、提交信息、对话输出中写入或泄露凭据、API 密钥、令牌。",
|
|
36
36
|
"enforce": "block",
|
|
37
37
|
"facet": "vajra",
|
|
38
|
-
"audit_pattern": "(apiKey|api_key|password|secret|token|credential)\\s*[=:]\\s*['\"][^'\"]{8,}",
|
|
38
|
+
"audit_pattern": "(apiKey|api_key|password|secret|token|credential)\\s*[=:]\\s*(?:['\"][^'\"\\n]{8,}|(?=[\\w-]*\\d)[\\w-]{16,})",
|
|
39
39
|
"scope": "Write,Edit,Bash",
|
|
40
|
-
"rationale": "Rismed Ronxin Capital
|
|
40
|
+
"rationale": "Rismed Ronxin Capital 合规要求:硬编码凭据违反安全底线。无引号分支要求 16+ 字且至少含一位数字——`PASSWORD=correcthorsebattery9` 会被拦,而 `password = getPassword()`、`token = process.env.TOKEN`、`credential: SOME_CONSTANT_NAME_ABC` 不会(少了数字或长度不足),从而把误伤挡在惯用写法之外。"
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
"id": "minimal-change",
|