@miphamai/cli 0.85.52 → 0.85.54
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 +3 -3
- package/package.json +6 -6
- package/src/agent/agent-registry.ts +17 -2
- package/src/commands/environment.ts +71 -35
- package/src/commands/project.ts +31 -0
- package/src/config/loader.ts +52 -3
- package/src/core/context.ts +21 -0
- package/src/core/credential-masker/matcher.ts +38 -0
- package/src/core/engine.ts +45 -4
- package/src/core/hooks.ts +18 -7
- package/src/core/instructions.ts +16 -2
- package/src/core/rules-loader.ts +4 -1
- package/src/core/session-insights.ts +262 -0
- package/src/core/session-log.ts +2 -2
- package/src/core/session-store.ts +30 -23
- package/src/daemon/launch.ts +11 -1
- package/src/i18n-core/locales/en-US.json +5 -1
- package/src/i18n-core/locales/zh-CN.json +5 -1
- package/src/index.tsx +46 -3
- package/src/mcp/transport.ts +35 -3
- package/src/providers/anthropic.ts +17 -1
- package/src/providers/openai-compat.ts +13 -1
- package/src/shared/package-info.ts +3 -3
- package/src/skills/loader.ts +9 -2
- package/src/tools/agent/workflow.ts +2 -0
- package/src/tools/exec/task.ts +41 -0
- package/src/tools/file/grep.ts +30 -1
- package/src/tools/network/web-fetch.ts +11 -2
- package/src/ui/app.tsx +32 -15
- package/src/ui/chat.tsx +17 -0
- package/src/ui/commands.ts +443 -29
- package/src/ui/picker.tsx +120 -19
- package/src/workflow/primitives/agent.ts +6 -0
- package/src/workflow/runtime.ts +45 -0
package/src/skills/loader.ts
CHANGED
|
@@ -15,7 +15,10 @@ interface FrontmatterResult {
|
|
|
15
15
|
export function parseFrontmatter(raw: string): FrontmatterResult {
|
|
16
16
|
// Strip a leading UTF-8 BOM — otherwise `^---` never matches and a
|
|
17
17
|
// BOM-prefixed file is silently treated as body text (effectively ignored).
|
|
18
|
-
|
|
18
|
+
// Normalize CRLF too: a skill authored on Windows used to match none of the
|
|
19
|
+
// `\n`-anchored fence below, so its `name`/`description` were dropped and the
|
|
20
|
+
// whole file was read as body text (CC 2.1.333-097).
|
|
21
|
+
const src = raw.replace(/^\uFEFF/, '').replace(/\r\n/g, '\n')
|
|
19
22
|
const match = src.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/)
|
|
20
23
|
if (!match) {
|
|
21
24
|
return { data: {}, content: src }
|
|
@@ -207,7 +210,11 @@ export class SkillsLoader implements Skills {
|
|
|
207
210
|
private loadDirectory(dir: string, type: 'standard' | 'mipham'): void {
|
|
208
211
|
this.scannedDirs.set(dir, type)
|
|
209
212
|
try {
|
|
210
|
-
|
|
213
|
+
// Two skill folders with the same declared name resolve last-one-wins.
|
|
214
|
+
// Directory order is filesystem-dependent, so which one wins changed from
|
|
215
|
+
// session to session; sort first so the documented precedence is stable
|
|
216
|
+
// (CC 2.1.333-130).
|
|
217
|
+
const entries = [...readdirSync(dir)].sort()
|
|
211
218
|
for (const entry of entries) {
|
|
212
219
|
const fullPath = join(dir, entry)
|
|
213
220
|
const isSkillFile = entry.endsWith('.SKILL.md') || entry.endsWith('.mipham-skill.md')
|
|
@@ -18,6 +18,8 @@ export const workflowTool: ToolDefinition = {
|
|
|
18
18
|
'## Primitives\n\n' +
|
|
19
19
|
'- agent(prompt: string, opts?: {label?, phase?, schema?, model?, effort?, isolation?}): Promise<any> — spawn a subagent. ' +
|
|
20
20
|
'Without schema, returns final text as string. With schema (JSON Schema), returns validated object — retries on mismatch.\n' +
|
|
21
|
+
'- stopAgent(id: string): number — abort the agent(s) started with `label: id`; the rest keep running. ' +
|
|
22
|
+
'Returns how many live calls were stopped (0 = already finished). The stopped call rejects with AbortError.\n' +
|
|
21
23
|
'- parallel(thunks: Array<() => Promise<any>>): Promise<any[]> — BARRIER: runs all thunks concurrently, waits for all. ' +
|
|
22
24
|
'Failed thunks resolve to null. Use filter(Boolean) before consuming results.\n' +
|
|
23
25
|
'- pipeline(items: T[], ...stages): Promise<any[]> — NO barrier: each item flows through all stages independently. ' +
|
package/src/tools/exec/task.ts
CHANGED
|
@@ -204,6 +204,18 @@ function stopBackgroundTask(
|
|
|
204
204
|
* whichever session happened to be active would let one session's ids answer
|
|
205
205
|
* for another's.
|
|
206
206
|
*/
|
|
207
|
+
/** Ids in `ids` that name no task in this session. `null` when not an array. */
|
|
208
|
+
function findMissingTaskIds(ids: unknown, tasks: Map<string, Task>): string[] | null {
|
|
209
|
+
if (!Array.isArray(ids)) return null
|
|
210
|
+
const missing = ids.map((id) => String(id)).filter((id) => !tasks.has(id))
|
|
211
|
+
return missing.length > 0 ? missing : null
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function formatMissingTaskIds(missing: string[]): string {
|
|
215
|
+
const names = missing.map((id) => `#${id}`).join(', ')
|
|
216
|
+
return `Task ${names} not found — dependency was not recorded`
|
|
217
|
+
}
|
|
218
|
+
|
|
207
219
|
function isBlocked(task: Task, tasks: Map<string, Task>): boolean {
|
|
208
220
|
if (task.blockedBy.length === 0) return false
|
|
209
221
|
return task.blockedBy.some((depId) => {
|
|
@@ -359,6 +371,21 @@ export const taskTool: ToolDefinition = {
|
|
|
359
371
|
|
|
360
372
|
// ── CREATE ──
|
|
361
373
|
if (action === 'create') {
|
|
374
|
+
// A dependency id that names no task is recorded and later reported as
|
|
375
|
+
// "all resolved": `isBlocked` treats a missing dep as not blocking. Refuse
|
|
376
|
+
// before creating anything, so the caller can correct the id instead of
|
|
377
|
+
// getting a phantom edge back (CC 2.1.335-019).
|
|
378
|
+
const missing = [
|
|
379
|
+
...(findMissingTaskIds(params.addBlocks, tasks) ?? []),
|
|
380
|
+
...(findMissingTaskIds(params.addBlockedBy, tasks) ?? []),
|
|
381
|
+
]
|
|
382
|
+
if (missing.length > 0) {
|
|
383
|
+
return {
|
|
384
|
+
success: false,
|
|
385
|
+
content: '',
|
|
386
|
+
error: formatMissingTaskIds(missing),
|
|
387
|
+
}
|
|
388
|
+
}
|
|
362
389
|
const id = String(++taskCounter)
|
|
363
390
|
const subject = (params.subject as string) || 'Untitled'
|
|
364
391
|
const task: Task = {
|
|
@@ -443,6 +470,20 @@ export const taskTool: ToolDefinition = {
|
|
|
443
470
|
const task = tasks.get(taskId)
|
|
444
471
|
if (!task) return { success: false, content: '', error: `Task #${taskId} not found` }
|
|
445
472
|
|
|
473
|
+
// Validate first: a rejected update must not leave `subject`/`status`
|
|
474
|
+
// already changed (CC 2.1.335-019).
|
|
475
|
+
const missing = [
|
|
476
|
+
...(findMissingTaskIds(params.addBlocks, tasks) ?? []),
|
|
477
|
+
...(findMissingTaskIds(params.addBlockedBy, tasks) ?? []),
|
|
478
|
+
]
|
|
479
|
+
if (missing.length > 0) {
|
|
480
|
+
return {
|
|
481
|
+
success: false,
|
|
482
|
+
content: '',
|
|
483
|
+
error: formatMissingTaskIds(missing),
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
446
487
|
if (params.subject !== undefined) task.subject = params.subject as string
|
|
447
488
|
if (params.description !== undefined) task.description = params.description as string
|
|
448
489
|
if (params.activeForm !== undefined) task.activeForm = params.activeForm as string
|
package/src/tools/file/grep.ts
CHANGED
|
@@ -25,6 +25,30 @@ const KILL_GRACE_MS = 2_000
|
|
|
25
25
|
*/
|
|
26
26
|
const PIPE_DRAIN_GRACE_MS = 2_000
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Normalize the `include` argument into individual `--glob` patterns.
|
|
30
|
+
*
|
|
31
|
+
* Accepts a comma-separated list (`*.ts,*.tsx`) without splitting the commas
|
|
32
|
+
* inside a brace alternation (`*.{ts,tsx}`), and strips a leading `./` — both
|
|
33
|
+
* forms were passed verbatim to ripgrep and matched nothing.
|
|
34
|
+
*/
|
|
35
|
+
export function splitGlobList(list: string): string[] {
|
|
36
|
+
const out: string[] = []
|
|
37
|
+
let depth = 0
|
|
38
|
+
let start = 0
|
|
39
|
+
for (let i = 0; i < list.length; i++) {
|
|
40
|
+
const ch = list[i]
|
|
41
|
+
if (ch === '{') depth++
|
|
42
|
+
else if (ch === '}') depth = Math.max(0, depth - 1)
|
|
43
|
+
else if (ch === ',' && depth === 0) {
|
|
44
|
+
out.push(list.slice(start, i))
|
|
45
|
+
start = i + 1
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
out.push(list.slice(start))
|
|
49
|
+
return out.map((s) => s.trim().replace(/^\.\//, '')).filter((s) => s.length > 0)
|
|
50
|
+
}
|
|
51
|
+
|
|
28
52
|
/** Run a search command with a kill-timer; report whether the timeout fired. */
|
|
29
53
|
export async function runSearch(
|
|
30
54
|
cmd: string[],
|
|
@@ -190,7 +214,12 @@ export function createGrepTool(credentialConfig?: CredentialMaskingConfig): Tool
|
|
|
190
214
|
'!.sl',
|
|
191
215
|
pattern,
|
|
192
216
|
]
|
|
193
|
-
|
|
217
|
+
// A comma-separated list is legal, and a brace alternation contains
|
|
218
|
+
// commas of its own. Passing the raw string made both forms match
|
|
219
|
+
// nothing (`*.{ts,tsx},*.js`, or any leading `./`) (CC 2.1.334-096).
|
|
220
|
+
if (include) {
|
|
221
|
+
for (const glob of splitGlobList(include)) rgArgs.push('--glob', glob)
|
|
222
|
+
}
|
|
194
223
|
rgArgs.push(searchPath)
|
|
195
224
|
try {
|
|
196
225
|
const { stdout, stderr, timedOut, exitCode } = await runSearch(
|
|
@@ -12,6 +12,16 @@ const MAX_RETURN_CHARS = 100_000
|
|
|
12
12
|
* real address"; a URL past it is a payload, not a page, and refusing it before
|
|
13
13
|
* the permission prompt keeps a pathological string out of every layer below.
|
|
14
14
|
*/
|
|
15
|
+
/**
|
|
16
|
+
* Header values are case-insensitive: `Text/HTML` is the same media type as
|
|
17
|
+
* `text/html`, but a case-sensitive test returned the raw markup instead of
|
|
18
|
+
* converting it (CC 2.1.334-087).
|
|
19
|
+
*/
|
|
20
|
+
export function isHtmlContentType(value: string | null | undefined): boolean {
|
|
21
|
+
const contentType = (value || '').toLowerCase()
|
|
22
|
+
return contentType.includes('text/html') || contentType.includes('application/xhtml')
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
const MAX_URL_CHARS = 2_000
|
|
16
26
|
|
|
17
27
|
interface CacheEntry {
|
|
@@ -369,8 +379,7 @@ export const webFetchTool: ToolDefinition = {
|
|
|
369
379
|
}
|
|
370
380
|
|
|
371
381
|
// Determine content type; only convert HTML to markdown
|
|
372
|
-
const
|
|
373
|
-
const isHtml = contentType.includes('text/html') || contentType.includes('application/xhtml')
|
|
382
|
+
const isHtml = isHtmlContentType(response.headers.get('content-type'))
|
|
374
383
|
|
|
375
384
|
// A 4xx/5xx is a statement about the site, not a failure of the tool:
|
|
376
385
|
// hand the status and whatever body it returned to the model as a normal
|
package/src/ui/app.tsx
CHANGED
|
@@ -13,7 +13,7 @@ import { MODE_CYCLE } from '../core/permission-config'
|
|
|
13
13
|
import { readGitBranch, resolveGitPr, prColor, type GitPr } from '../core/git-pr'
|
|
14
14
|
import type { SkillsLoader } from '../skills/loader'
|
|
15
15
|
import type { PluginManager } from '../plugin/plugin-manager'
|
|
16
|
-
import { setPreference } from '../config/preferences'
|
|
16
|
+
import { getPreference, setPreference } from '../config/preferences'
|
|
17
17
|
import { saveProviderApiKey } from '../config/loader'
|
|
18
18
|
import { recordCommand } from '../telemetry/index'
|
|
19
19
|
import { recordCrash } from '../telemetry/crash'
|
|
@@ -71,7 +71,9 @@ import {
|
|
|
71
71
|
unknownCommandMessage,
|
|
72
72
|
handleSwitch,
|
|
73
73
|
runCommandHandler,
|
|
74
|
+
statuslineVisibility,
|
|
74
75
|
type CommandContext,
|
|
76
|
+
type StatuslineMode,
|
|
75
77
|
} from './commands'
|
|
76
78
|
import { useI18n } from '../i18n-context'
|
|
77
79
|
import type { PermissionMode } from '../shared/index.ts'
|
|
@@ -93,6 +95,7 @@ interface AppProps {
|
|
|
93
95
|
version?: string
|
|
94
96
|
sessionId?: string
|
|
95
97
|
agentViewManager?: AgentViewManager
|
|
98
|
+
reloadPlugins?: () => { plugins: number; skills: number }
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
export interface ToolMeta {
|
|
@@ -354,6 +357,7 @@ export function App({
|
|
|
354
357
|
version,
|
|
355
358
|
sessionId,
|
|
356
359
|
agentViewManager,
|
|
360
|
+
reloadPlugins,
|
|
357
361
|
}: AppProps) {
|
|
358
362
|
const { t, locale } = useI18n()
|
|
359
363
|
const PERMISSION_LABELS = useMemo<Record<PermissionMode, string>>(
|
|
@@ -452,6 +456,10 @@ export function App({
|
|
|
452
456
|
const [_sessionTitle, setSessionTitle] = useState('')
|
|
453
457
|
const [_effort, setEffort] = useState('high')
|
|
454
458
|
const [focusMode, setFocusMode] = useState(false)
|
|
459
|
+
const [statuslineMode, setStatuslineMode] = useState<StatuslineMode>(() => {
|
|
460
|
+
const saved = getPreference('statuslineMode', 'full')
|
|
461
|
+
return saved === 'compact' || saved === 'off' ? saved : 'full'
|
|
462
|
+
})
|
|
455
463
|
const [_ultracodeMode, setUltracodeMode] = useState(false)
|
|
456
464
|
const [goalText, setGoalText] = useState('')
|
|
457
465
|
// 初始值取自 live 权限系统 —— 启动时 config 的模式可能已被组织级限制钳到别处
|
|
@@ -617,6 +625,7 @@ export function App({
|
|
|
617
625
|
if ('setUltracodeMode' in engine) engine.setUltracodeMode(on)
|
|
618
626
|
},
|
|
619
627
|
setUpdateStatus: (s: UpdateStatus) => setUpdateStatus(s),
|
|
628
|
+
setStatuslineMode: (mode: StatuslineMode) => setStatuslineMode(mode),
|
|
620
629
|
// Same read-back as Shift+Tab: `setMode` may clamp the request (org
|
|
621
630
|
// `maxAllowedMode` / `forbiddenModes`), so the footer and the gate must
|
|
622
631
|
// both read the mode that took effect, not the one we asked for.
|
|
@@ -627,6 +636,7 @@ export function App({
|
|
|
627
636
|
},
|
|
628
637
|
skillsLoader,
|
|
629
638
|
pluginManager,
|
|
639
|
+
reloadPlugins,
|
|
630
640
|
t,
|
|
631
641
|
locale,
|
|
632
642
|
}),
|
|
@@ -637,6 +647,7 @@ export function App({
|
|
|
637
647
|
modelId,
|
|
638
648
|
skillsLoader,
|
|
639
649
|
pluginManager,
|
|
650
|
+
reloadPlugins,
|
|
640
651
|
sessionId,
|
|
641
652
|
t,
|
|
642
653
|
locale,
|
|
@@ -1490,6 +1501,8 @@ export function App({
|
|
|
1490
1501
|
)
|
|
1491
1502
|
}
|
|
1492
1503
|
|
|
1504
|
+
const statuslineSegments = statuslineVisibility(statuslineMode)
|
|
1505
|
+
|
|
1493
1506
|
return (
|
|
1494
1507
|
<ErrorBoundary
|
|
1495
1508
|
onError={(error) => {
|
|
@@ -1686,11 +1699,13 @@ export function App({
|
|
|
1686
1699
|
/>
|
|
1687
1700
|
|
|
1688
1701
|
{/* graft status line — mirrors graft's own "◤ graft · …" bar */}
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1702
|
+
{statuslineSegments.graft && (
|
|
1703
|
+
<GraftStatusLine
|
|
1704
|
+
cwd={process.cwd()}
|
|
1705
|
+
ctxPct={contextUsagePct(engine)}
|
|
1706
|
+
tokens={sessionTokens(engine)}
|
|
1707
|
+
/>
|
|
1708
|
+
)}
|
|
1694
1709
|
|
|
1695
1710
|
{/* Update notification — green, right-aligned, mirrors Claude Code's "Update installed · Restart to apply".
|
|
1696
1711
|
While the startup banner is showing it already carries this line, so the footer copy is suppressed to avoid a duplicate. */}
|
|
@@ -1710,20 +1725,22 @@ export function App({
|
|
|
1710
1725
|
<Text color={PERMISSION_COLORS[permissionMode]}>
|
|
1711
1726
|
{permissionGlyphPrefix(permissionMode) + PERMISSION_LABELS[permissionMode]}
|
|
1712
1727
|
</Text>
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1728
|
+
{statuslineSegments.hints && (
|
|
1729
|
+
<Text dimColor>
|
|
1730
|
+
{' '}
|
|
1731
|
+
({t('ui.status.shift_tab_cycle')}:{' '}
|
|
1732
|
+
{MODE_CYCLE.map((m) => PERMISSION_LABELS[m]).join(' · ')}){' · '}
|
|
1733
|
+
{t('ui.status.esc_to_interrupt')}
|
|
1734
|
+
{' · '}
|
|
1735
|
+
{t('ui.status.left_for_agents')}
|
|
1736
|
+
</Text>
|
|
1737
|
+
)}
|
|
1721
1738
|
{ctrlC.armed && <Text color="yellow"> {t('ui.status.ctrl_c_again')}</Text>}
|
|
1722
1739
|
</Box>
|
|
1723
1740
|
</Box>
|
|
1724
1741
|
|
|
1725
1742
|
{/* Git branch — dim, bottom-most, mirrors Claude Code's "⏺ main" */}
|
|
1726
|
-
{gitBranch && (
|
|
1743
|
+
{statuslineSegments.git && gitBranch && (
|
|
1727
1744
|
<Box>
|
|
1728
1745
|
<Text dimColor>⏺ {gitBranch}</Text>
|
|
1729
1746
|
{gitPr && <Text color={prColor(gitPr)}> · PR #{gitPr.number}</Text>}
|
package/src/ui/chat.tsx
CHANGED
|
@@ -58,7 +58,24 @@ function display(text: string): string {
|
|
|
58
58
|
*/
|
|
59
59
|
const MAX_RENDERED_LINES = 50
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Render at most this many characters of a single message body.
|
|
63
|
+
*
|
|
64
|
+
* The line cap above does not bound a *single* enormous line — a resumed
|
|
65
|
+
* message carrying a data URL or a minified blob renders whole, and Ink lays it
|
|
66
|
+
* out on every streamed chunk. Say how much was dropped rather than pretending
|
|
67
|
+
* the view is complete (CC 2.1.334-018).
|
|
68
|
+
*/
|
|
69
|
+
const MAX_RENDERED_CHARS = 20_000
|
|
70
|
+
|
|
61
71
|
function capRenderedLines(text: string): string {
|
|
72
|
+
if (text.length > MAX_RENDERED_CHARS) {
|
|
73
|
+
const hidden = text.length - MAX_RENDERED_CHARS
|
|
74
|
+
return (
|
|
75
|
+
text.slice(0, MAX_RENDERED_CHARS) +
|
|
76
|
+
`\n… ${hidden.toLocaleString('en-US')} more character${hidden === 1 ? '' : 's'}`
|
|
77
|
+
)
|
|
78
|
+
}
|
|
62
79
|
let newlines = 0
|
|
63
80
|
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) === 10) newlines++
|
|
64
81
|
if (newlines < MAX_RENDERED_LINES) return text
|