@miphamai/cli 0.85.35 → 0.85.37
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 +4 -4
- package/package.json +1 -1
- package/src/commands/environment.ts +53 -69
- package/src/commands/git.ts +53 -16
- package/src/commands/keys.ts +28 -17
- package/src/commands/project.ts +10 -17
- package/src/commands/workflow-view.ts +24 -6
- package/src/config/loader.ts +81 -4
- package/src/core/engine.ts +29 -2
- package/src/core/hooks-executor.ts +15 -0
- package/src/core/improvement-track.ts +37 -1
- package/src/core/meta-rule-engine.ts +3 -1
- package/src/core/permission-rules.ts +60 -0
- package/src/core/permission.ts +17 -5
- package/src/core/rule-engine.ts +11 -5
- package/src/core/task-performance.ts +41 -0
- package/src/daemon/attach-protocol.ts +25 -0
- package/src/daemon/remote-engine.ts +161 -4
- package/src/daemon/session-worker.ts +50 -0
- package/src/i18n-core/detect.ts +16 -4
- package/src/i18n-core/locales/en-US.json +6 -5
- package/src/i18n-core/locales/zh-CN.json +6 -5
- package/src/i18n-core/preference.ts +55 -0
- package/src/index.tsx +3 -2
- package/src/mcp/registry.ts +66 -14
- package/src/shared/package-info.ts +3 -3
- package/src/skills/loader.ts +30 -0
- package/src/skills/seam.ts +7 -0
- package/src/tools/agent/report-findings.ts +20 -2
- package/src/tools/agent/skill.ts +9 -1
- package/src/tools/exec/bash.ts +59 -0
- package/src/tools/exec/git.ts +82 -0
- package/src/tools/network/web-fetch.ts +20 -0
- package/src/ui/app.tsx +40 -20
- package/src/ui/commands.ts +539 -98
- package/src/ui/strip-indent.ts +9 -4
|
@@ -34,6 +34,7 @@ import type {
|
|
|
34
34
|
ServerDoneMessage,
|
|
35
35
|
ServerErrorMessage,
|
|
36
36
|
ServerSessionStateMessage,
|
|
37
|
+
ServerStatsMessage,
|
|
37
38
|
} from './attach-protocol'
|
|
38
39
|
|
|
39
40
|
// ── Session State Snapshot ────────────────────────────────────────────────
|
|
@@ -89,6 +90,7 @@ export class SessionWorker {
|
|
|
89
90
|
addClient(ws: ServerWebSocket<unknown>): void {
|
|
90
91
|
this.clients.add(ws)
|
|
91
92
|
this.sendState(ws)
|
|
93
|
+
this.sendStats(ws)
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
/** Remove a WebSocket client from this session's broadcast set. */
|
|
@@ -225,6 +227,9 @@ export class SessionWorker {
|
|
|
225
227
|
stopReason,
|
|
226
228
|
}
|
|
227
229
|
this.broadcast(doneMsg)
|
|
230
|
+
// 一轮之后读数变了(消息、token、checkpoint)。命令在客户端本地跑,
|
|
231
|
+
// 它们读到的是**最近一帧**;不补这一帧,用户在下一轮前看到的永远是 attach 时的旧数。
|
|
232
|
+
this.broadcastStats()
|
|
228
233
|
|
|
229
234
|
this.currentController = null
|
|
230
235
|
this.processing = false
|
|
@@ -469,6 +474,51 @@ export class SessionWorker {
|
|
|
469
474
|
}
|
|
470
475
|
}
|
|
471
476
|
|
|
477
|
+
/**
|
|
478
|
+
* Read the engine's context numbers for a stats frame. Every reader is optional
|
|
479
|
+
* and guarded: the frame is advisory, and one engine (or one older checkout of
|
|
480
|
+
* the context) missing a reader must not take the whole turn down with it.
|
|
481
|
+
*/
|
|
482
|
+
private buildStats(): Omit<ServerStatsMessage, 'type' | 'sessionId'> {
|
|
483
|
+
const ctx = this.engine.getContext()
|
|
484
|
+
const read = (fn: (() => number | undefined) | undefined): number => {
|
|
485
|
+
if (typeof fn !== 'function') return 0
|
|
486
|
+
try {
|
|
487
|
+
const value = fn()
|
|
488
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : 0
|
|
489
|
+
} catch {
|
|
490
|
+
return 0
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
estimatedTokens: read(() => ctx.getEstimatedTokens?.()),
|
|
495
|
+
maxTokens: read(() => ctx.getMaxTokens?.()),
|
|
496
|
+
compactionThreshold: read(() => ctx.getCompactionThreshold?.()),
|
|
497
|
+
messageCount: read(() => ctx.getMessages?.().length),
|
|
498
|
+
checkpointCount: read(() => ctx.getCheckpoints?.().length),
|
|
499
|
+
cachedTokens: read(() => ctx.getCacheStatus?.().cachedTokens),
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** Send the current stats to one client (used right after its snapshot). */
|
|
504
|
+
private sendStats(ws: ServerWebSocket<unknown>): void {
|
|
505
|
+
const msg: ServerStatsMessage = {
|
|
506
|
+
type: 'stats',
|
|
507
|
+
sessionId: this.session.id,
|
|
508
|
+
...this.buildStats(),
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
ws.send(JSON.stringify(msg))
|
|
512
|
+
} catch {
|
|
513
|
+
this.clients.delete(ws)
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/** Broadcast the current stats to every attached client. */
|
|
518
|
+
private broadcastStats(): void {
|
|
519
|
+
this.broadcast({ type: 'stats', sessionId: this.session.id, ...this.buildStats() })
|
|
520
|
+
}
|
|
521
|
+
|
|
472
522
|
/** Build an error ServerMessage for the current session. */
|
|
473
523
|
private errorMessage(message: string): ServerErrorMessage {
|
|
474
524
|
return {
|
package/src/i18n-core/detect.ts
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
import type { Locale } from './types'
|
|
2
2
|
import { execSync } from 'node:child_process'
|
|
3
3
|
|
|
4
|
-
export function detectLocale(opts?: {
|
|
4
|
+
export function detectLocale(opts?: {
|
|
5
|
+
lang?: string
|
|
6
|
+
/** The user's persisted `/lang` choice (read by the caller; see preference.ts). */
|
|
7
|
+
settingsLocale?: string | null
|
|
8
|
+
cwd?: string
|
|
9
|
+
}): Locale {
|
|
5
10
|
// 1. CLI --lang flag
|
|
6
11
|
if (opts?.lang) {
|
|
7
12
|
const normalized = normalizeLocale(opts.lang)
|
|
8
13
|
if (normalized) return normalized as Locale
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
// 2.
|
|
16
|
+
// 2. Explicit user preference — beats the environment, or LANG=zh_CN would
|
|
17
|
+
// silently override someone who chose en-US.
|
|
18
|
+
if (opts?.settingsLocale) {
|
|
19
|
+
const normalized = normalizeLocale(opts.settingsLocale)
|
|
20
|
+
if (normalized) return normalized as Locale
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 3. LANG / LC_ALL env vars
|
|
12
24
|
const langEnv = process.env.LC_ALL || process.env.LANG || ''
|
|
13
25
|
const envLocale = parseLangEnv(langEnv)
|
|
14
26
|
if (envLocale) return envLocale
|
|
15
27
|
|
|
16
|
-
//
|
|
28
|
+
// 4. OS detection
|
|
17
29
|
const osLocale = detectOSLocale()
|
|
18
30
|
if (osLocale) return osLocale
|
|
19
31
|
|
|
20
|
-
//
|
|
32
|
+
// 5. Fallback
|
|
21
33
|
return 'en-US'
|
|
22
34
|
}
|
|
23
35
|
|
|
@@ -265,11 +265,12 @@
|
|
|
265
265
|
"confirmed": "✓ Rewound to checkpoint \"{label}\"\nRestored {count} messages.\n\nRemaining checkpoints: {remaining}\nUse /rewind again to go back further, or continue chatting."
|
|
266
266
|
},
|
|
267
267
|
"effort": {
|
|
268
|
-
"usage": "Usage: /effort <level>\n\
|
|
269
|
-
"confirmed": "✓
|
|
268
|
+
"usage": "Usage: /effort <level>\n\nSets the streaming stall budget — how long a silent stream may run before it is\ntreated as dead. It does NOT change how hard the model reasons:\n low — 90s idle budget\n medium — 90s\n high — 180s\n xhigh — 270s\n max — 360s\n\nCurrent model: {model}",
|
|
269
|
+
"confirmed": "✓ Stream stall budget set to \"{level}\" (timeout only — reasoning depth comes from the provider/model)"
|
|
270
270
|
},
|
|
271
271
|
"focus": {
|
|
272
|
-
"on": "✓ Focus mode ON — showing only the most recent exchange.\nPrevious messages are hidden but preserved.\nType /focus again to exit focus mode and show all messages."
|
|
272
|
+
"on": "✓ Focus mode ON — showing only the most recent exchange.\nPrevious messages are hidden but preserved.\nType /focus again to exit focus mode and show all messages.",
|
|
273
|
+
"off": "✓ Focus mode OFF — showing all messages."
|
|
273
274
|
},
|
|
274
275
|
"ultracode": {
|
|
275
276
|
"on": "✓ Ultracode mode ON — multi-agent workflow orchestration enabled.\n\nThe AI will use Workflow tool to fan out, verify, and synthesize for all substantive tasks.",
|
|
@@ -279,7 +280,7 @@
|
|
|
279
280
|
"branch": {
|
|
280
281
|
"no_conversation": "No conversation to branch. Start a conversation first.",
|
|
281
282
|
"title": "── Branch Created ──",
|
|
282
|
-
"details": "Name: \"{name}\"\nCheckpoint: #{checkpoint}\nMessages: {messages} saved\n\nCurrent conversation continues from this point.\nTo return to this branch point later, use:\n /rewind\n\nNote:
|
|
283
|
+
"details": "Name: \"{name}\"\nCheckpoint: #{checkpoint}\nMessages: {messages} saved\n\nCurrent conversation continues from this point.\nTo return to this branch point later, use:\n /rewind\n\nNote: this saves a named checkpoint you can rewind to. It does not create a separate concurrent session — Mipham Code has no such mode today."
|
|
283
284
|
},
|
|
284
285
|
"memories": {
|
|
285
286
|
"title": "─ Memory ─",
|
|
@@ -325,7 +326,7 @@
|
|
|
325
326
|
"unverified": "⚠ Installed, but could not verify the new version: {reason}"
|
|
326
327
|
},
|
|
327
328
|
"no_plan": {
|
|
328
|
-
"confirmed": "✓ Plan mode exited. Your plan
|
|
329
|
+
"confirmed": "✓ Plan mode exited. Your plan was not applied (the plan file is kept for reference).\n\nContinue chatting as normal, or type /plan to start a new plan."
|
|
329
330
|
},
|
|
330
331
|
"mcp": {
|
|
331
332
|
"usage_connect": "Usage: /mcp connect <server-name>",
|
|
@@ -265,11 +265,12 @@
|
|
|
265
265
|
"confirmed": "✓ 已回退到检查点 \"{label}\"\n已恢复 {count} 条消息。\n\n剩余检查点: {remaining}\n再次使用 /rewind 继续回退,或继续对话。"
|
|
266
266
|
},
|
|
267
267
|
"effort": {
|
|
268
|
-
"usage": "用法: /effort <level>\n\n
|
|
269
|
-
"confirmed": "✓
|
|
268
|
+
"usage": "用法: /effort <level>\n\n设置流式空闲预算 —— 流静默多久后被判定为断流。它不改变模型的推理深度:\n low — 90 秒空闲预算\n medium — 90 秒\n high — 180 秒\n xhigh — 270 秒\n max — 360 秒\n\n当前模型: {model}",
|
|
269
|
+
"confirmed": "✓ 流式空闲预算已设为 \"{level}\"(仅超时;推理深度由提供商/模型决定)"
|
|
270
270
|
},
|
|
271
271
|
"focus": {
|
|
272
|
-
"on": "✓ 聚焦模式已开启 — 仅显示最近一次交流。\n之前的消息已隐藏但保留。\n再次输入 /focus 退出聚焦模式并显示所有消息。"
|
|
272
|
+
"on": "✓ 聚焦模式已开启 — 仅显示最近一次交流。\n之前的消息已隐藏但保留。\n再次输入 /focus 退出聚焦模式并显示所有消息。",
|
|
273
|
+
"off": "✓ 聚焦模式已关闭 — 显示所有消息。"
|
|
273
274
|
},
|
|
274
275
|
"ultracode": {
|
|
275
276
|
"on": "✓ Ultracode 模式已开启 — 多 Agent 工作流编排已启用。\n\nAI 将使用 Workflow 工具对所有实质性任务进行分发、验证和综合。",
|
|
@@ -279,7 +280,7 @@
|
|
|
279
280
|
"branch": {
|
|
280
281
|
"no_conversation": "没有可分支的对话。请先开始对话。",
|
|
281
282
|
"title": "── 分支已创建 ──",
|
|
282
|
-
"details": "名称: \"{name}\"\n检查点: #{checkpoint}\n消息: {messages} 已保存\n\n当前对话从此刻继续。\n以后返回此分支点,使用:\n /rewind\n\n注意:
|
|
283
|
+
"details": "名称: \"{name}\"\n检查点: #{checkpoint}\n消息: {messages} 已保存\n\n当前对话从此刻继续。\n以后返回此分支点,使用:\n /rewind\n\n注意: 这会保存一个可回退的命名检查点,不会创建独立的并发会话 —— 目前没有这种模式。"
|
|
283
284
|
},
|
|
284
285
|
"memories": {
|
|
285
286
|
"title": "─ 记忆 ─",
|
|
@@ -325,7 +326,7 @@
|
|
|
325
326
|
"unverified": "⚠ 已安装,但无法验证新版本: {reason}"
|
|
326
327
|
},
|
|
327
328
|
"no_plan": {
|
|
328
|
-
"confirmed": "✓
|
|
329
|
+
"confirmed": "✓ 计划模式已退出。计划未被执行(计划文件仍保留供参考)。\n\n继续正常对话,或输入 /plan 开始新计划。"
|
|
329
330
|
},
|
|
330
331
|
"mcp": {
|
|
331
332
|
"usage_connect": "用法: /mcp connect <server-name>",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The user's persisted locale choice (`/lang`).
|
|
3
|
+
*
|
|
4
|
+
* Lives in `~/.mipham/settings.json` — the same file telemetry consent uses —
|
|
5
|
+
* because it is the only config writer that preserves keys it does not model.
|
|
6
|
+
* `detectLocale` reads this before `LANG`, so an explicit choice is not
|
|
7
|
+
* overridden by the shell's environment on the next start.
|
|
8
|
+
*/
|
|
9
|
+
import { mkdirSync } from 'node:fs'
|
|
10
|
+
import { dirname } from 'node:path'
|
|
11
|
+
import { atomicWriteFileSync } from '../shared/atomic-write'
|
|
12
|
+
import { readRegularFileSync } from '../shared/regular-file'
|
|
13
|
+
import { miphamHome } from '../core/paths.ts'
|
|
14
|
+
import { SUPPORTED_LOCALES, type Locale } from './types'
|
|
15
|
+
|
|
16
|
+
function settingsPath(): string {
|
|
17
|
+
return miphamHome('settings.json')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The saved locale, or null when absent / unsupported / unreadable. */
|
|
21
|
+
export function readLocalePreference(): Locale | null {
|
|
22
|
+
try {
|
|
23
|
+
const raw = readRegularFileSync(settingsPath())
|
|
24
|
+
if (raw === null) return null
|
|
25
|
+
const parsed: unknown = JSON.parse(raw)
|
|
26
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return null
|
|
27
|
+
const value = (parsed as { locale?: unknown }).locale
|
|
28
|
+
return typeof value === 'string' && (SUPPORTED_LOCALES as string[]).includes(value)
|
|
29
|
+
? (value as Locale)
|
|
30
|
+
: null
|
|
31
|
+
} catch {
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Persist the choice, preserving unrelated keys. Returns false on write failure. */
|
|
37
|
+
export function saveLocalePreference(locale: Locale): boolean {
|
|
38
|
+
try {
|
|
39
|
+
let doc: Record<string, unknown> = {}
|
|
40
|
+
const raw = readRegularFileSync(settingsPath())
|
|
41
|
+
if (raw !== null) {
|
|
42
|
+
const parsed: unknown = JSON.parse(raw)
|
|
43
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
44
|
+
doc = parsed as Record<string, unknown>
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
doc.locale = locale
|
|
48
|
+
const path = settingsPath()
|
|
49
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
50
|
+
atomicWriteFileSync(path, JSON.stringify(doc, null, 2) + '\n', { mode: 0o644 })
|
|
51
|
+
return true
|
|
52
|
+
} catch {
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -73,6 +73,7 @@ import { AgentViewManager } from './agent-view/agent-view-manager'
|
|
|
73
73
|
import { AgentsStandalone } from './agent-view/agents-standalone'
|
|
74
74
|
import { createT } from './i18n-core/t'
|
|
75
75
|
import { detectLocale } from './i18n-core/detect'
|
|
76
|
+
import { readLocalePreference } from './i18n-core/preference'
|
|
76
77
|
import { I18nProvider } from './i18n-context'
|
|
77
78
|
import { ConfigWizard } from './ui/config-wizard'
|
|
78
79
|
import enUS from './i18n-core/locales/en-US.json' with { type: 'json' }
|
|
@@ -374,7 +375,7 @@ export async function runApp(options: RunOptions): Promise<void> {
|
|
|
374
375
|
if (options.permission) engine.getPermission().setMode(options.permission)
|
|
375
376
|
|
|
376
377
|
// Detect locale and create translation function (same as local path)
|
|
377
|
-
const locale = detectLocale({ lang: options.lang })
|
|
378
|
+
const locale = detectLocale({ lang: options.lang, settingsLocale: readLocalePreference() })
|
|
378
379
|
const t = createT(localeBundles[locale] || enUS, enUS)
|
|
379
380
|
|
|
380
381
|
// Set terminal window title
|
|
@@ -493,7 +494,7 @@ export async function runApp(options: RunOptions): Promise<void> {
|
|
|
493
494
|
}
|
|
494
495
|
|
|
495
496
|
// Detect locale and create translation function
|
|
496
|
-
const locale = detectLocale({ lang: options.lang })
|
|
497
|
+
const locale = detectLocale({ lang: options.lang, settingsLocale: readLocalePreference() })
|
|
497
498
|
const t = createT(localeBundles[locale] || enUS, enUS)
|
|
498
499
|
|
|
499
500
|
// Bootstrap providers
|
package/src/mcp/registry.ts
CHANGED
|
@@ -52,6 +52,48 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
|
52
52
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
function hasProperties(node: Record<string, unknown>): boolean {
|
|
56
|
+
return isPlainObject(node.properties) && Object.keys(node.properties).length > 0
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface ArgumentSurface {
|
|
60
|
+
properties: Record<string, unknown>
|
|
61
|
+
required?: string[]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function surfaceOf(node: Record<string, unknown>): ArgumentSurface {
|
|
65
|
+
const required = Array.isArray(node.required)
|
|
66
|
+
? node.required.filter((name): name is string => typeof name === 'string')
|
|
67
|
+
: undefined
|
|
68
|
+
return {
|
|
69
|
+
properties: isPlainObject(node.properties) ? node.properties : {},
|
|
70
|
+
...(required && required.length > 0 ? { required } : {}),
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Every argument surface a schema offers.
|
|
76
|
+
*
|
|
77
|
+
* A server may put the union at the root (`anyOf`/`oneOf`). Reading only
|
|
78
|
+
* `root.properties` made that tool reach the model with **no parameters at
|
|
79
|
+
* all** — callable, but every argument invisible. Following only the *first*
|
|
80
|
+
* branch fixed that and introduced the next defect one step in: a branch that
|
|
81
|
+
* takes an id as a number and another that takes it as a string are two
|
|
82
|
+
* spellings of one argument, and showing only the first taught the model that
|
|
83
|
+
* the second was invalid. Every branch is surfaced; nested unions included.
|
|
84
|
+
* The root wins when it declares properties itself, so a schema that has both
|
|
85
|
+
* is not rewritten.
|
|
86
|
+
*/
|
|
87
|
+
function collectSurfaces(schema: unknown, depth = 0): ArgumentSurface[] {
|
|
88
|
+
const node = isPlainObject(schema) ? schema : {}
|
|
89
|
+
if (hasProperties(node)) return [surfaceOf(node)]
|
|
90
|
+
if (depth >= 8) return []
|
|
91
|
+
const branches = (
|
|
92
|
+
Array.isArray(node.anyOf) ? node.anyOf : Array.isArray(node.oneOf) ? node.oneOf : []
|
|
93
|
+
).filter(isPlainObject)
|
|
94
|
+
return branches.flatMap((branch) => collectSurfaces(branch, depth + 1))
|
|
95
|
+
}
|
|
96
|
+
|
|
55
97
|
/**
|
|
56
98
|
* Coerce a server-declared `inputSchema` into a shape every provider accepts.
|
|
57
99
|
*
|
|
@@ -61,28 +103,38 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
|
61
103
|
* unusable — not just the one tool. Only the top level is repaired: property
|
|
62
104
|
* schemas that are themselves objects are kept verbatim, so this narrows
|
|
63
105
|
* malformed input without rewriting a server's intent.
|
|
106
|
+
*
|
|
107
|
+
* A root-level `anyOf`/`oneOf` is not malformed, but it is a shape no provider
|
|
108
|
+
* accepts as tool parameters — the first branch that declares properties is
|
|
109
|
+
* surfaced instead of dropping the tool's whole argument surface.
|
|
64
110
|
*/
|
|
65
111
|
export function sanitizeInputSchema(schema: unknown): {
|
|
66
112
|
properties: Record<string, unknown>
|
|
67
113
|
required?: string[]
|
|
68
114
|
} {
|
|
69
|
-
const
|
|
70
|
-
const rawProperties = isPlainObject(root.properties) ? root.properties : {}
|
|
115
|
+
const surfaces = collectSurfaces(schema)
|
|
71
116
|
const properties: Record<string, unknown> = {}
|
|
72
|
-
for (const
|
|
73
|
-
|
|
117
|
+
for (const surface of surfaces) {
|
|
118
|
+
for (const [name, property] of Object.entries(surface.properties)) {
|
|
119
|
+
// First spelling wins on a name collision; the later branch is another
|
|
120
|
+
// way to say the same argument, not a second argument.
|
|
121
|
+
if (isPlainObject(property) && !Object.prototype.hasOwnProperty.call(properties, name)) {
|
|
122
|
+
properties[name] = property
|
|
123
|
+
}
|
|
124
|
+
}
|
|
74
125
|
}
|
|
75
126
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
127
|
+
// A name is required only when **every** surface that mentions requirements
|
|
128
|
+
// requires it. One branch needing `id` and another not is not a reason to
|
|
129
|
+
// demand `id` for a call the second branch accepts.
|
|
130
|
+
let required = surfaces[0]?.required ? [...surfaces[0].required] : []
|
|
131
|
+
for (const surface of surfaces.slice(1)) {
|
|
132
|
+
const set = new Set(surface.required ?? [])
|
|
133
|
+
required = required.filter((name) => set.has(name))
|
|
134
|
+
}
|
|
135
|
+
required = [...new Set(required)].filter((name) =>
|
|
136
|
+
Object.prototype.hasOwnProperty.call(properties, name),
|
|
137
|
+
)
|
|
86
138
|
|
|
87
139
|
return required.length > 0 ? { properties, required } : { properties }
|
|
88
140
|
}
|
|
@@ -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.37' as const
|
|
13
13
|
|
|
14
14
|
/** npm install 全局安装命令 */
|
|
15
15
|
export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` as const
|
|
@@ -75,7 +75,7 @@ export const COMPANY_SHORT = '华安麦逄科技' as const
|
|
|
75
75
|
*/
|
|
76
76
|
|
|
77
77
|
/** Slash 命令总数(真源:`getCommandNames().length`,`apps/cli/src/ui/commands.ts`) */
|
|
78
|
-
export const SLASH_COMMAND_COUNT =
|
|
78
|
+
export const SLASH_COMMAND_COUNT = 139 as const
|
|
79
79
|
|
|
80
80
|
/** 内置提供商总数(真源:`DEFAULT_PROVIDERS.length`,`apps/cli/src/shared/constants.ts`) */
|
|
81
81
|
export const PROVIDER_COUNT = 12 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 = 4969 as const
|
package/src/skills/loader.ts
CHANGED
|
@@ -48,6 +48,8 @@ export class SkillsLoader implements Skills {
|
|
|
48
48
|
private skills = new Map<string, SkillDefinition>()
|
|
49
49
|
/** File each loaded skill came from — so a name collision can name both sides. */
|
|
50
50
|
private sources = new Map<string, string>()
|
|
51
|
+
/** Paths this loader has scanned, with the type they were loaded as — what `reload()` re-reads. */
|
|
52
|
+
private scannedDirs = new Map<string, 'standard' | 'mipham'>()
|
|
51
53
|
|
|
52
54
|
loadBuiltin(basePath: string): void {
|
|
53
55
|
// Load standard skills (*.SKILL.md)
|
|
@@ -97,11 +99,38 @@ export class SkillsLoader implements Skills {
|
|
|
97
99
|
this.loadDirectory(p, 'standard')
|
|
98
100
|
} else if (stat.isFile()) {
|
|
99
101
|
this.tryLoad(p, 'standard')
|
|
102
|
+
this.scannedDirs.set(p, 'standard')
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Re-scan every directory/file this loader already read, and return the total
|
|
110
|
+
* skill count.
|
|
111
|
+
*
|
|
112
|
+
* The Skill tool calls this once on a miss: a skill written **during** the
|
|
113
|
+
* session (by the model itself, or by a command it ran) was invisible until a
|
|
114
|
+
* restart or `/reload-skills`, and "not found" was the same answer whether the
|
|
115
|
+
* name was wrong or the file was new. Rescanning only on a miss keeps the
|
|
116
|
+
* happy path unchanged.
|
|
117
|
+
*/
|
|
118
|
+
reload(): number {
|
|
119
|
+
for (const [p, type] of this.scannedDirs) {
|
|
120
|
+
try {
|
|
121
|
+
if (!existsSync(p)) continue
|
|
122
|
+
if (statSync(p).isDirectory()) {
|
|
123
|
+
this.loadDirectory(p, type)
|
|
124
|
+
} else {
|
|
125
|
+
this.tryLoad(p, type)
|
|
126
|
+
}
|
|
127
|
+
} catch {
|
|
128
|
+
// A path that became unreadable is not a reload failure for the rest.
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return this.skills.size
|
|
132
|
+
}
|
|
133
|
+
|
|
105
134
|
/** Load a single skill file by path (used by Claude plugins: `skills/<name>/SKILL.md`). */
|
|
106
135
|
loadSkillFile(path: string, type: 'standard' | 'mipham' = 'standard'): void {
|
|
107
136
|
this.tryLoad(path, type)
|
|
@@ -137,6 +166,7 @@ export class SkillsLoader implements Skills {
|
|
|
137
166
|
}
|
|
138
167
|
|
|
139
168
|
private loadDirectory(dir: string, type: 'standard' | 'mipham'): void {
|
|
169
|
+
this.scannedDirs.set(dir, type)
|
|
140
170
|
try {
|
|
141
171
|
const entries = readdirSync(dir)
|
|
142
172
|
for (const entry of entries) {
|
package/src/skills/seam.ts
CHANGED
|
@@ -7,6 +7,13 @@ export interface Skills {
|
|
|
7
7
|
list(): SkillDefinition[]
|
|
8
8
|
has(name: string): boolean
|
|
9
9
|
buildSystemReminder(maxTokens?: number): string
|
|
10
|
+
/**
|
|
11
|
+
* Re-scan the directories this loader already knows about. Optional: the Skill
|
|
12
|
+
* tool calls it once when a name is not found, so a skill written during the
|
|
13
|
+
* session is found without restarting (`/reload-skills` still exists for a
|
|
14
|
+
* deliberate full reload). A provider with no on-disk sources simply omits it.
|
|
15
|
+
*/
|
|
16
|
+
reload?(): number
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
/** 缝键:ctx.skills。 */
|
|
@@ -34,7 +34,7 @@ export const reportFindingsTool: ToolDefinition = {
|
|
|
34
34
|
},
|
|
35
35
|
summary: {
|
|
36
36
|
type: 'string',
|
|
37
|
-
description: '
|
|
37
|
+
description: 'Statement of the defect.',
|
|
38
38
|
},
|
|
39
39
|
short_summary: {
|
|
40
40
|
type: 'string',
|
|
@@ -51,6 +51,14 @@ export const reportFindingsTool: ToolDefinition = {
|
|
|
51
51
|
description:
|
|
52
52
|
'Short kebab-case slug: correctness, security, performance, simplification, test-coverage, etc.',
|
|
53
53
|
},
|
|
54
|
+
severity: {
|
|
55
|
+
type: 'string',
|
|
56
|
+
enum: ['important', 'pre_existing', 'nit'],
|
|
57
|
+
description:
|
|
58
|
+
'Set when the review instructions ask for it. important: a bug the change adds ' +
|
|
59
|
+
'or makes worse; pre_existing: a bug that was there before the change; nit: a ' +
|
|
60
|
+
'minor issue.',
|
|
61
|
+
},
|
|
54
62
|
verdict: {
|
|
55
63
|
type: 'string',
|
|
56
64
|
enum: ['CONFIRMED', 'PLAUSIBLE'],
|
|
@@ -104,6 +112,12 @@ export const reportFindingsTool: ToolDefinition = {
|
|
|
104
112
|
if (f.outcome && !['fixed', 'skipped', 'no_change_needed'].includes(f.outcome as string)) {
|
|
105
113
|
errors.push(`findings[${i}]: "outcome" must be fixed, skipped, or no_change_needed`)
|
|
106
114
|
}
|
|
115
|
+
if (
|
|
116
|
+
f.severity !== undefined &&
|
|
117
|
+
!['important', 'pre_existing', 'nit'].includes(f.severity as string)
|
|
118
|
+
) {
|
|
119
|
+
errors.push(`findings[${i}]: "severity" must be important, pre_existing, or nit`)
|
|
120
|
+
}
|
|
107
121
|
}
|
|
108
122
|
|
|
109
123
|
if (errors.length > 0) {
|
|
@@ -154,9 +168,13 @@ export const reportFindingsTool: ToolDefinition = {
|
|
|
154
168
|
lines.push(`${icon} ${category} (${items.length}):`)
|
|
155
169
|
for (const f of items) {
|
|
156
170
|
const verdict = f.verdict ? ` [${f.verdict}]` : ''
|
|
171
|
+
// The severity is what tells a reader whether the change made this worse
|
|
172
|
+
// or merely inherited it; accepting it without showing it would make the
|
|
173
|
+
// field an inert attribute (nothing downstream reads it).
|
|
174
|
+
const severity = f.severity ? ` [severity: ${f.severity}]` : ''
|
|
157
175
|
const outcome = f.outcome ? ` → ${f.outcome}` : ''
|
|
158
176
|
const lineRef = f.line ? `:${f.line}` : ''
|
|
159
|
-
lines.push(` • ${f.file}${lineRef}${verdict}${outcome}`)
|
|
177
|
+
lines.push(` • ${f.file}${lineRef}${verdict}${severity}${outcome}`)
|
|
160
178
|
lines.push(` ${f.summary}`)
|
|
161
179
|
if (f.failure_scenario) {
|
|
162
180
|
const scenario =
|
package/src/tools/agent/skill.ts
CHANGED
|
@@ -26,7 +26,15 @@ export const skillTool: ToolDefinition = {
|
|
|
26
26
|
// Try to load the skill via SkillsLoader if available
|
|
27
27
|
const loader = ctx.skillsLoader
|
|
28
28
|
if (loader) {
|
|
29
|
-
|
|
29
|
+
let skill = loader.get(skillName)
|
|
30
|
+
if (!skill && loader.reload) {
|
|
31
|
+
// A skill written during this session was not in the loader's snapshot:
|
|
32
|
+
// before answering "not found", re-scan the directories it already
|
|
33
|
+
// knows. A genuinely wrong name costs one directory walk; a new file
|
|
34
|
+
// stops being indistinguishable from a typo.
|
|
35
|
+
loader.reload()
|
|
36
|
+
skill = loader.get(skillName)
|
|
37
|
+
}
|
|
30
38
|
if (!skill) {
|
|
31
39
|
const available = loader
|
|
32
40
|
.list()
|
package/src/tools/exec/bash.ts
CHANGED
|
@@ -207,6 +207,49 @@ export function isBlocked(command: string): string | null {
|
|
|
207
207
|
return null // safe
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Git commands that rewrite refs a worktree **shares with the main checkout**.
|
|
212
|
+
*
|
|
213
|
+
* A worktree is not a sandbox for `.git`: every worktree of one repository reads
|
|
214
|
+
* and writes the same `refs/` (and the same `packed-refs`). A subagent isolated
|
|
215
|
+
* in a worktree can therefore move `main` — delete it, force it, point it at a
|
|
216
|
+
* different commit — and the main checkout follows, without a single file in the
|
|
217
|
+
* worktree changing. The `cd` escape guard does not see this: the command runs
|
|
218
|
+
* inside the worktree and reaches out through git's own directories.
|
|
219
|
+
*
|
|
220
|
+
* Only judged for **subagents inside a worktree**: the main session in a
|
|
221
|
+
* worktree is the user's own checkout and keeps every command it had. This list
|
|
222
|
+
* is a floor of demonstrated forms; widening it costs one blocked command.
|
|
223
|
+
*/
|
|
224
|
+
const SHARED_REF_REWRITES: Array<{ pattern: RegExp; description: string }> = [
|
|
225
|
+
{ pattern: /\bupdate-ref\b/, description: 'update-ref (writes a ref directly)' },
|
|
226
|
+
{ pattern: /\bsymbolic-ref\b/, description: 'symbolic-ref (repoints a ref)' },
|
|
227
|
+
{
|
|
228
|
+
pattern: /\bbranch\s+.*(?:-f\b|--force\b|-m\b|-M\b|--move\b|-d\b|-D\b|--delete\b)/,
|
|
229
|
+
description: 'branch -f/-m/-d (force-move, rename or delete a branch)',
|
|
230
|
+
},
|
|
231
|
+
{ pattern: /\bcheckout\b[^;&|]*\s-B\b/, description: 'checkout -B (reset a branch)' },
|
|
232
|
+
{ pattern: /\bswitch\b[^;&|]*\s-C\b/, description: 'switch -C (reset a branch)' },
|
|
233
|
+
{
|
|
234
|
+
pattern: /\bworktree\s+(?:remove|prune)\b/,
|
|
235
|
+
description: 'worktree remove/prune (removes a sibling checkout)',
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
pattern: /\btag\s+.*(?:-f\b|--force\b|-d\b|--delete\b)/,
|
|
239
|
+
description: 'tag -f/-d (force-move or delete a tag)',
|
|
240
|
+
},
|
|
241
|
+
]
|
|
242
|
+
|
|
243
|
+
/** First shared-ref rewrite in `command`, or `null`. */
|
|
244
|
+
export function detectSharedRefRewrite(command: string): { description: string } | null {
|
|
245
|
+
// Same gate the dangerous-git scan uses: the command must actually invoke git.
|
|
246
|
+
if (!/(?:^|[\s;&|(])(?:sudo\s+)?git\s+/.test(command)) return null
|
|
247
|
+
for (const { pattern, description } of SHARED_REF_REWRITES) {
|
|
248
|
+
if (pattern.test(command)) return { description }
|
|
249
|
+
}
|
|
250
|
+
return null
|
|
251
|
+
}
|
|
252
|
+
|
|
210
253
|
/**
|
|
211
254
|
* Detect sandbox violations from stderr output.
|
|
212
255
|
* Parses common OS-level error patterns indicating denied access.
|
|
@@ -604,6 +647,22 @@ export function createBashTool(credentialConfig?: CredentialMaskingConfig): Tool
|
|
|
604
647
|
`Attempted: ${escapeTarget}. Use tools within the worktree only.`,
|
|
605
648
|
}
|
|
606
649
|
}
|
|
650
|
+
// Worktrees share `refs/` with the main checkout, so "stay inside the
|
|
651
|
+
// directory" is not enough: `git update-ref refs/heads/main …` moves a
|
|
652
|
+
// branch the main checkout is standing on. A subagent gets no vote on
|
|
653
|
+
// shared refs; the main session in a worktree keeps its own commands.
|
|
654
|
+
if (ctx.isSubAgent) {
|
|
655
|
+
const rewrite = detectSharedRefRewrite(command)
|
|
656
|
+
if (rewrite) {
|
|
657
|
+
return {
|
|
658
|
+
success: false,
|
|
659
|
+
content: '',
|
|
660
|
+
error:
|
|
661
|
+
`Worktree isolation: "${rewrite.description}" rewrites a ref shared with the ` +
|
|
662
|
+
`main checkout. Ask the main session to run it if that is what you intend.`,
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
607
666
|
}
|
|
608
667
|
|
|
609
668
|
// Security: check command against deny list
|