@miphamai/cli 0.85.24 → 0.85.25
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 +1 -1
- package/src/artifacts/server.ts +5 -1
- package/src/commands/git.ts +9 -1
- package/src/commands/project.ts +34 -17
- package/src/core/context-token.ts +55 -3
- package/src/core/context.ts +22 -42
- package/src/core/crsi-sandbox.ts +5 -1
- package/src/core/engine.ts +5 -1
- package/src/core/instructions.ts +69 -2
- package/src/core/permission-rules.ts +141 -25
- package/src/plugin/plugin-manager.ts +23 -2
- package/src/providers/registry.ts +23 -1
- package/src/shared/git-env.ts +18 -0
- package/src/shared/package-info.ts +3 -3
- package/src/shared/sanitize.ts +21 -0
- package/src/skills/loader.ts +14 -0
- package/src/tools/exec/bash.ts +168 -6
- package/src/tools/exec/enter-worktree.ts +26 -2
- package/src/ui/app.tsx +22 -7
- package/src/ui/chat.tsx +3 -2
- package/src/ui/commands.ts +54 -2
- package/src/workflow/primitives/agent.ts +17 -1
package/src/ui/app.tsx
CHANGED
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
} from './commands'
|
|
62
62
|
import { useI18n } from '../i18n-context'
|
|
63
63
|
import type { PermissionMode } from '../shared/index.ts'
|
|
64
|
-
import { sanitizeForDisplay } from '../shared/sanitize.ts'
|
|
64
|
+
import { safeSlice, sanitizeForDisplay } from '../shared/sanitize.ts'
|
|
65
65
|
import { recordLoopTurn, readAutoloopJournal } from '../commands/autoloop-journal.js'
|
|
66
66
|
import { cancelAllSessionTimers, resumeWakeups } from '../tools/scheduling/schedule-wakeup.js'
|
|
67
67
|
import type { LostWakeup } from '../tools/scheduling/schedule-wakeup.js'
|
|
@@ -188,10 +188,7 @@ export function cyclePermissionMode(
|
|
|
188
188
|
/** 预览截断按 UTF-16 码元计数,落点若正好夹在一个代理对中间,切完就留下
|
|
189
189
|
* **半个** emoji(终端渲染成 U+FFFD)。落点是高代理时后退一个码元即可。 */
|
|
190
190
|
export function truncateForDisplay(text: string, max: number): string {
|
|
191
|
-
|
|
192
|
-
const last = text.charCodeAt(max - 1)
|
|
193
|
-
const end = last >= 0xd800 && last <= 0xdbff ? max - 1 : max
|
|
194
|
-
return text.slice(0, end)
|
|
191
|
+
return safeSlice(text, max)
|
|
195
192
|
}
|
|
196
193
|
|
|
197
194
|
/** Format a tool's input parameters into a compact one-line detail string.
|
|
@@ -539,11 +536,29 @@ export function App({
|
|
|
539
536
|
setGoal: (text: string) => setGoalText(text),
|
|
540
537
|
setUltracodeMode: (on: boolean) => setUltracodeMode(on),
|
|
541
538
|
setUpdateStatus: (s: UpdateStatus) => setUpdateStatus(s),
|
|
539
|
+
// Same read-back as Shift+Tab: `setMode` may clamp the request (org
|
|
540
|
+
// `maxAllowedMode` / `forbiddenModes`), so the footer and the gate must
|
|
541
|
+
// both read the mode that took effect, not the one we asked for.
|
|
542
|
+
setPermissionMode: (mode: PermissionMode) => {
|
|
543
|
+
const permission = engine.getPermission() as PermissionSource
|
|
544
|
+
permission.setMode(mode)
|
|
545
|
+
setPermissionMode(permission.getMode())
|
|
546
|
+
},
|
|
542
547
|
skillsLoader,
|
|
543
548
|
pluginManager,
|
|
544
549
|
t,
|
|
545
550
|
}),
|
|
546
|
-
[
|
|
551
|
+
[
|
|
552
|
+
engine,
|
|
553
|
+
config,
|
|
554
|
+
providerId,
|
|
555
|
+
modelId,
|
|
556
|
+
skillsLoader,
|
|
557
|
+
pluginManager,
|
|
558
|
+
sessionId,
|
|
559
|
+
t,
|
|
560
|
+
setPermissionMode,
|
|
561
|
+
],
|
|
547
562
|
)
|
|
548
563
|
|
|
549
564
|
const handleApiKeySubmit = useCallback(
|
|
@@ -806,7 +821,7 @@ export function App({
|
|
|
806
821
|
const lineCount = newContent.split('\n').length
|
|
807
822
|
preview = `Updated ${filePath} · ${lineCount} lines`
|
|
808
823
|
} else {
|
|
809
|
-
const firstLine = output.split('\n')[0]
|
|
824
|
+
const firstLine = safeSlice(output.split('\n')[0]!, 200)
|
|
810
825
|
preview = firstLine.length < output.length ? `${firstLine}...` : firstLine
|
|
811
826
|
}
|
|
812
827
|
setMessages((prev) => [
|
package/src/ui/chat.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { useI18n } from '../i18n-context'
|
|
|
4
4
|
import type { ChatMessage } from './app'
|
|
5
5
|
import {
|
|
6
6
|
decodeDisplayEntities,
|
|
7
|
+
safeSlice,
|
|
7
8
|
sanitizeInlineField,
|
|
8
9
|
stripControlCharsForDisplay,
|
|
9
10
|
} from '../shared/sanitize'
|
|
@@ -130,12 +131,12 @@ const MessageRow = React.memo(
|
|
|
130
131
|
<Text dimColor>
|
|
131
132
|
{' ⎿ '}
|
|
132
133
|
{t('ui.tool.not_run')}
|
|
133
|
-
{msg.toolMeta.output ? ` — ${display(msg.toolMeta.output)
|
|
134
|
+
{msg.toolMeta.output ? ` — ${safeSlice(display(msg.toolMeta.output), 300)}` : ''}
|
|
134
135
|
</Text>
|
|
135
136
|
) : msg.toolMeta.output ? (
|
|
136
137
|
<Text dimColor>
|
|
137
138
|
{' ⎿ '}
|
|
138
|
-
{display(msg.toolMeta.output)
|
|
139
|
+
{safeSlice(display(msg.toolMeta.output), 300)}
|
|
139
140
|
</Text>
|
|
140
141
|
) : msg.content && !msg.toolMeta.collapsed ? (
|
|
141
142
|
<Text dimColor>{display(msg.content)}</Text>
|
package/src/ui/commands.ts
CHANGED
|
@@ -8,10 +8,11 @@ import type { QueryEngine } from '../core/engine'
|
|
|
8
8
|
import type { MiphamConfig } from '../shared/index.ts'
|
|
9
9
|
import { formatContextWindow } from '../shared/format'
|
|
10
10
|
import { sanitizeInlineField } from '../shared/sanitize'
|
|
11
|
+
import { internalGitEnv } from '../shared/git-env'
|
|
11
12
|
import { truncateSkillDescription, type SkillsLoader } from '../skills/loader'
|
|
12
13
|
import { loadSkillUsage } from '../skills/usage'
|
|
13
14
|
import type { PluginManager } from '../plugin/plugin-manager'
|
|
14
|
-
import type { Message } from '../shared/types.js'
|
|
15
|
+
import type { Message, PermissionMode } from '../shared/types.js'
|
|
15
16
|
import type { CopyPickerItem } from './copy-picker'
|
|
16
17
|
import type { InstallState, UpdateStatus } from '../shared/update'
|
|
17
18
|
import { McpClient } from '../mcp/client'
|
|
@@ -134,6 +135,10 @@ export interface CommandContext {
|
|
|
134
135
|
setGoal: (text: string) => void
|
|
135
136
|
setUltracodeMode: (on: boolean) => void
|
|
136
137
|
setUpdateStatus: (s: UpdateStatus) => void
|
|
138
|
+
/** Request a permission-mode change and let the App read back the mode that
|
|
139
|
+
* actually took effect (org limits can clamp it). Absent on surfaces that
|
|
140
|
+
* cannot switch modes (e.g. a remote attach stub). */
|
|
141
|
+
setPermissionMode?: (mode: PermissionMode) => void
|
|
137
142
|
skillsLoader?: SkillsLoader
|
|
138
143
|
pluginManager?: PluginManager
|
|
139
144
|
/** i18n translate function — populated from React tree via useI18n().
|
|
@@ -281,7 +286,7 @@ const helpCmd: CommandHandler = (ctx) => {
|
|
|
281
286
|
/setup Guided project setup wizard
|
|
282
287
|
/recommend Analyze project + recommend setup
|
|
283
288
|
/permissions Show or persist permission rules
|
|
284
|
-
/add-dir <dir>
|
|
289
|
+
/add-dir <dir> Check a path + how access is decided
|
|
285
290
|
/security Security review checklist
|
|
286
291
|
/audit Same as /security
|
|
287
292
|
|
|
@@ -408,6 +413,48 @@ function liveMode(ctx: CommandContext): string {
|
|
|
408
413
|
return ctx.engine.getPermission().getMode()
|
|
409
414
|
}
|
|
410
415
|
|
|
416
|
+
/**
|
|
417
|
+
* `ExitPlanMode` tells the model, in its tool result, that the user can approve
|
|
418
|
+
* by saying "approved" **or `/approve`**. Before this handler existed that second
|
|
419
|
+
* half was advice with no landing point: `/approve` fell through to the
|
|
420
|
+
* unknown-command path, nothing switched modes, and the next turn began in the
|
|
421
|
+
* same limited mode the model had just been told would lift.
|
|
422
|
+
*
|
|
423
|
+
* Only `plan` is approvable. Every other mode either has no plan pending, or is
|
|
424
|
+
* already wider than what approval grants — silently widening those would make a
|
|
425
|
+
* stray `/approve` a permission escalation.
|
|
426
|
+
*/
|
|
427
|
+
const approveCmd: CommandHandler = async (ctx) => {
|
|
428
|
+
const mode = liveMode(ctx)
|
|
429
|
+
if (mode !== 'plan') {
|
|
430
|
+
return {
|
|
431
|
+
content:
|
|
432
|
+
`Nothing to approve — not in plan mode (current mode: ${mode}).\n` +
|
|
433
|
+
'Approval only switches a plan under review to acceptEdits.',
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (!ctx.setPermissionMode) {
|
|
437
|
+
return {
|
|
438
|
+
content:
|
|
439
|
+
'This surface cannot switch permission modes. Use Shift+Tab to cycle to acceptEdits.',
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
ctx.setPermissionMode('acceptEdits')
|
|
443
|
+
const now = liveMode(ctx)
|
|
444
|
+
if (now !== 'acceptEdits') {
|
|
445
|
+
return {
|
|
446
|
+
content:
|
|
447
|
+
`Plan approved, but the organisation's permission limit kept the mode at ${now} ` +
|
|
448
|
+
'(not acceptEdits) — edits will still be refused.',
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
content:
|
|
453
|
+
'✓ Plan approved — switched to acceptEdits. File writes and edits are applied without ' +
|
|
454
|
+
'prompting; commands still follow the usual rules. Shift+Tab to narrow it again.',
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
411
458
|
const statusCmd: CommandHandler = async (ctx) => {
|
|
412
459
|
const t = resolveT(ctx)
|
|
413
460
|
const c = ctx.engine.getContext()
|
|
@@ -4318,10 +4365,13 @@ const prCommentsCmd: CommandHandler = async () => {
|
|
|
4318
4365
|
encoding: 'utf-8',
|
|
4319
4366
|
timeout: 3000,
|
|
4320
4367
|
}).trim()
|
|
4368
|
+
// The pipeline greps the English header, so git must not localize it:
|
|
4369
|
+
// a Chinese git prints `HEAD 分支:` and this silently lands on `main`.
|
|
4321
4370
|
const mainBranch =
|
|
4322
4371
|
execSync('git remote show origin 2>/dev/null | grep "HEAD branch" | cut -d: -f2', {
|
|
4323
4372
|
encoding: 'utf-8',
|
|
4324
4373
|
timeout: 3000,
|
|
4374
|
+
env: { ...process.env, LC_ALL: 'C', LANG: 'C' },
|
|
4325
4375
|
}).trim() || 'main'
|
|
4326
4376
|
|
|
4327
4377
|
// Get diff stats vs main
|
|
@@ -5594,6 +5644,7 @@ const forkCmd: CommandHandler = async (ctx, args) => {
|
|
|
5594
5644
|
execFileSync('git', ['worktree', 'add', '-b', branch, wtPath, 'HEAD'], {
|
|
5595
5645
|
stdio: 'ignore',
|
|
5596
5646
|
timeout: 30_000,
|
|
5647
|
+
env: internalGitEnv(),
|
|
5597
5648
|
})
|
|
5598
5649
|
} catch (err) {
|
|
5599
5650
|
try {
|
|
@@ -6097,6 +6148,7 @@ registry.set('/init', initCmd)
|
|
|
6097
6148
|
registry.set('/setup', setupCmd)
|
|
6098
6149
|
registry.set('/recommend', recommendCmd)
|
|
6099
6150
|
registry.set('/permissions', permissionsCmd)
|
|
6151
|
+
registry.set('/approve', approveCmd)
|
|
6100
6152
|
registry.set('/add-dir', addDirCmd)
|
|
6101
6153
|
registry.set('/security', securityCmd)
|
|
6102
6154
|
registry.set('/audit', securityCmd)
|
|
@@ -5,8 +5,12 @@ import type { Llm } from '../../providers/llm'
|
|
|
5
5
|
import type { ToolDefinition } from '../../shared/index.ts'
|
|
6
6
|
import type { PermissionSystem } from '../../core/permission'
|
|
7
7
|
import { worktreeRoot } from '../../core/paths.ts'
|
|
8
|
+
import { internalGitEnv } from '../../shared/git-env'
|
|
8
9
|
import { validateJSONSchema, formatValidationErrors } from '../schema-validator'
|
|
9
10
|
|
|
11
|
+
/** Upper bound for `git worktree add` — a hung fetch must not hang the run. */
|
|
12
|
+
const WORKTREE_ADD_TIMEOUT_MS = 60_000
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Effective model for a workflow agent.
|
|
12
16
|
*
|
|
@@ -80,8 +84,20 @@ export async function workflowAgent(
|
|
|
80
84
|
const proc = Bun.spawn(['git', 'worktree', 'add', '-b', worktreeBranch, worktreePath, 'HEAD'], {
|
|
81
85
|
stdout: 'pipe',
|
|
82
86
|
stderr: 'pipe',
|
|
87
|
+
env: internalGitEnv(),
|
|
83
88
|
})
|
|
84
|
-
|
|
89
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
90
|
+
const exitCode = await Promise.race([
|
|
91
|
+
proc.exited,
|
|
92
|
+
new Promise<number>((resolve) => {
|
|
93
|
+
timer = setTimeout(() => resolve(-1), WORKTREE_ADD_TIMEOUT_MS)
|
|
94
|
+
}),
|
|
95
|
+
])
|
|
96
|
+
clearTimeout(timer)
|
|
97
|
+
if (exitCode === -1) {
|
|
98
|
+
proc.kill()
|
|
99
|
+
throw new Error(`Worktree creation timed out after ${WORKTREE_ADD_TIMEOUT_MS / 1000}s`)
|
|
100
|
+
}
|
|
85
101
|
if (exitCode !== 0) {
|
|
86
102
|
const stderr = await new Response(proc.stderr).text()
|
|
87
103
|
throw new Error(`Worktree creation failed: ${stderr.slice(0, 500)}`)
|