@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
package/src/tools/exec/git.ts
CHANGED
|
@@ -106,6 +106,85 @@ function isOutsideWorktree(command: string, cwd: string): string | null {
|
|
|
106
106
|
*/
|
|
107
107
|
const PROGRAM_EXECUTING_OPTIONS = ['--upload-pack', '--receive-pack', '--exec-path']
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* `git filter-branch` options whose value is a shell command. `--subdirectory-filter`
|
|
111
|
+
* is deliberately absent: it names a directory, not a program.
|
|
112
|
+
*/
|
|
113
|
+
const FILTER_BRANCH_EXEC_OPTIONS = new Set([
|
|
114
|
+
'--setup',
|
|
115
|
+
'--env-filter',
|
|
116
|
+
'--tree-filter',
|
|
117
|
+
'--index-filter',
|
|
118
|
+
'--parent-filter',
|
|
119
|
+
'--msg-filter',
|
|
120
|
+
'--commit-filter',
|
|
121
|
+
'--tag-name-filter',
|
|
122
|
+
])
|
|
123
|
+
|
|
124
|
+
/** Options that consume the next argv token and take no value of interest here. */
|
|
125
|
+
const GLOBAL_OPTIONS_WITH_VALUE = new Set([
|
|
126
|
+
'-c',
|
|
127
|
+
'--config',
|
|
128
|
+
'-C',
|
|
129
|
+
'--git-dir',
|
|
130
|
+
'--work-tree',
|
|
131
|
+
'--namespace',
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
/** Index of the git subcommand, skipping global options and their values. */
|
|
135
|
+
function subcommandIndex(argv: string[]): number {
|
|
136
|
+
for (let i = 0; i < argv.length; i++) {
|
|
137
|
+
const arg = argv[i]!
|
|
138
|
+
if (GLOBAL_OPTIONS_WITH_VALUE.has(arg)) {
|
|
139
|
+
i++
|
|
140
|
+
continue
|
|
141
|
+
}
|
|
142
|
+
if (arg.startsWith('-')) continue
|
|
143
|
+
return i
|
|
144
|
+
}
|
|
145
|
+
return -1
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Subcommands whose *own* argument is a program for git to run:
|
|
150
|
+
* `bisect run <cmd>`, `submodule foreach <cmd>`, `rebase --exec <cmd>`,
|
|
151
|
+
* and `filter-branch`'s `--*-filter <cmd>` options. Like the option list above,
|
|
152
|
+
* these are code execution reached without the approval prompt Bash would have
|
|
153
|
+
* shown. `maintenance register` only takes a config file; `scalar` is not a git
|
|
154
|
+
* subcommand, so neither is listed.
|
|
155
|
+
*/
|
|
156
|
+
function findProgramExecutingSubcommand(argv: string[]): string | null {
|
|
157
|
+
const at = subcommandIndex(argv)
|
|
158
|
+
if (at === -1) return null
|
|
159
|
+
const sub = argv[at]!
|
|
160
|
+
const next = argv[at + 1]
|
|
161
|
+
|
|
162
|
+
if (sub === 'bisect' && next === 'run') {
|
|
163
|
+
return `bisect run ${argv[at + 2] ?? ''}`.trim()
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if ((sub === 'submodule' || sub === 'submodule--helper') && next === 'foreach') {
|
|
167
|
+
return `${sub} foreach ${argv[at + 2] ?? ''}`.trim()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (sub === 'rebase') {
|
|
171
|
+
for (const arg of argv.slice(at + 1)) {
|
|
172
|
+
// `-x` and `--exec` run a command; short flags may be combined (`-ix`).
|
|
173
|
+
if (arg === '--exec' || /^-[a-zA-Z]*x[a-zA-Z]*$/.test(arg)) return `rebase ${arg}`
|
|
174
|
+
if (arg.startsWith('--exec=')) return arg
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (sub === 'filter-branch') {
|
|
179
|
+
for (const arg of argv.slice(at + 1)) {
|
|
180
|
+
const name = arg.includes('=') ? arg.slice(0, arg.indexOf('=')) : arg
|
|
181
|
+
if (FILTER_BRANCH_EXEC_OPTIONS.has(name)) return `filter-branch ${arg}`
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return null
|
|
186
|
+
}
|
|
187
|
+
|
|
109
188
|
/** Config keys whose value git runs as a program. */
|
|
110
189
|
const PROGRAM_EXECUTING_CONFIG_KEY =
|
|
111
190
|
/^(?:core\.(?:sshCommand|pager|askpass|editor)|alias\.|credential\.helper)/i
|
|
@@ -120,6 +199,9 @@ const PROGRAM_EXECUTING_CONFIG_KEY =
|
|
|
120
199
|
* is what git actually gets, so it has no such gap.
|
|
121
200
|
*/
|
|
122
201
|
export function findProgramExecutingArg(argv: string[]): string | null {
|
|
202
|
+
const subcommand = findProgramExecutingSubcommand(argv)
|
|
203
|
+
if (subcommand !== null) return subcommand
|
|
204
|
+
|
|
123
205
|
for (let i = 0; i < argv.length; i++) {
|
|
124
206
|
const arg = argv[i]!
|
|
125
207
|
|
|
@@ -7,6 +7,13 @@ import { validateUrl } from '../../security/url'
|
|
|
7
7
|
/** Most characters returned in one call. Past this the caller pages with `offset`. */
|
|
8
8
|
const MAX_RETURN_CHARS = 100_000
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Longest URL accepted. 2,000 is the anchor RFC 7230 gives for "longer than any
|
|
12
|
+
* real address"; a URL past it is a payload, not a page, and refusing it before
|
|
13
|
+
* the permission prompt keeps a pathological string out of every layer below.
|
|
14
|
+
*/
|
|
15
|
+
const MAX_URL_CHARS = 2_000
|
|
16
|
+
|
|
10
17
|
interface CacheEntry {
|
|
11
18
|
content: string
|
|
12
19
|
timestamp: number
|
|
@@ -278,6 +285,19 @@ export const webFetchTool: ToolDefinition = {
|
|
|
278
285
|
const rawUrl = params.url as string
|
|
279
286
|
const prompt = (params.prompt as string) || ''
|
|
280
287
|
const offset = Math.max(0, Number(params.offset) || 0)
|
|
288
|
+
// Refuse before any parsing, DNS lookup or permission prompt: past this
|
|
289
|
+
// length the URL is not a page address anyone can read (the length itself
|
|
290
|
+
// has been used to make URL parsers backtrack for minutes).
|
|
291
|
+
if (rawUrl.length > MAX_URL_CHARS) {
|
|
292
|
+
return {
|
|
293
|
+
success: false,
|
|
294
|
+
content: '',
|
|
295
|
+
error:
|
|
296
|
+
`URL is ${rawUrl.length.toLocaleString('en-US')} characters — longer than the ` +
|
|
297
|
+
`${MAX_URL_CHARS.toLocaleString('en-US')}-character limit. Truncate it to the address ` +
|
|
298
|
+
`the page actually needs (query strings can be dropped and re-added after fetching).`,
|
|
299
|
+
}
|
|
300
|
+
}
|
|
281
301
|
const url = upgradeToHttps(rawUrl)
|
|
282
302
|
|
|
283
303
|
// Check cache — an incomplete entry (first 100k only) cannot answer a
|
package/src/ui/app.tsx
CHANGED
|
@@ -56,7 +56,9 @@ import {
|
|
|
56
56
|
getCommand,
|
|
57
57
|
looksLikeSlashCommand,
|
|
58
58
|
parseSlashCommand,
|
|
59
|
+
unknownCommandMessage,
|
|
59
60
|
handleSwitch,
|
|
61
|
+
runCommandHandler,
|
|
60
62
|
type CommandContext,
|
|
61
63
|
} from './commands'
|
|
62
64
|
import { useI18n } from '../i18n-context'
|
|
@@ -307,7 +309,7 @@ export function App({
|
|
|
307
309
|
sessionId,
|
|
308
310
|
agentViewManager,
|
|
309
311
|
}: AppProps) {
|
|
310
|
-
const { t } = useI18n()
|
|
312
|
+
const { t, locale } = useI18n()
|
|
311
313
|
const PERMISSION_LABELS = useMemo<Record<PermissionMode, string>>(
|
|
312
314
|
() => ({
|
|
313
315
|
default: t('ui.permission.manual'),
|
|
@@ -565,8 +567,16 @@ export function App({
|
|
|
565
567
|
engine.setEffort(level)
|
|
566
568
|
},
|
|
567
569
|
setFocusMode: (on: boolean) => setFocusMode(on),
|
|
570
|
+
getFocusMode: () => focusMode,
|
|
568
571
|
setGoal: (text: string) => setGoalText(text),
|
|
569
|
-
setUltracodeMode: (on: boolean) =>
|
|
572
|
+
setUltracodeMode: (on: boolean) => {
|
|
573
|
+
setUltracodeMode(on)
|
|
574
|
+
// The mode must reach the engine: the React state is display-only, and
|
|
575
|
+
// the previous wiring left the instruction alive for exactly one turn.
|
|
576
|
+
// Attached sessions have no local engine to configure (the command
|
|
577
|
+
// refuses there); the guard keeps that a runtime no-op, not a crash.
|
|
578
|
+
if ('setUltracodeMode' in engine) engine.setUltracodeMode(on)
|
|
579
|
+
},
|
|
570
580
|
setUpdateStatus: (s: UpdateStatus) => setUpdateStatus(s),
|
|
571
581
|
// Same read-back as Shift+Tab: `setMode` may clamp the request (org
|
|
572
582
|
// `maxAllowedMode` / `forbiddenModes`), so the footer and the gate must
|
|
@@ -579,6 +589,7 @@ export function App({
|
|
|
579
589
|
skillsLoader,
|
|
580
590
|
pluginManager,
|
|
581
591
|
t,
|
|
592
|
+
locale,
|
|
582
593
|
}),
|
|
583
594
|
[
|
|
584
595
|
engine,
|
|
@@ -589,7 +600,11 @@ export function App({
|
|
|
589
600
|
pluginManager,
|
|
590
601
|
sessionId,
|
|
591
602
|
t,
|
|
603
|
+
locale,
|
|
592
604
|
setPermissionMode,
|
|
605
|
+
// `/focus` reads the live value through `getFocusMode`; without the dep
|
|
606
|
+
// the memoised ctx would keep returning the state it was born with.
|
|
607
|
+
focusMode,
|
|
593
608
|
],
|
|
594
609
|
)
|
|
595
610
|
|
|
@@ -1154,9 +1169,9 @@ export function App({
|
|
|
1154
1169
|
const { command, args } = parseSlashCommand(input)
|
|
1155
1170
|
|
|
1156
1171
|
// Counted here rather than at the registry lookup below: /switch, /pick,
|
|
1157
|
-
// /model-picker, /exit
|
|
1158
|
-
//
|
|
1159
|
-
//
|
|
1172
|
+
// /model-picker, /exit and /quit are special-cased and return before
|
|
1173
|
+
// ever reaching it, so counting there would silently under-report five
|
|
1174
|
+
// of the most-used commands.
|
|
1160
1175
|
//
|
|
1161
1176
|
// `commandLabelFor` collapses unrecognised names into `/unknown` — see it
|
|
1162
1177
|
// for why an unbounded `command_name` is not a cosmetic problem.
|
|
@@ -1197,28 +1212,33 @@ export function App({
|
|
|
1197
1212
|
void exitSession(0)
|
|
1198
1213
|
}
|
|
1199
1214
|
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1215
|
+
let forwardToAI: string | undefined
|
|
1216
|
+
|
|
1217
|
+
const handler = getCommand(command)
|
|
1218
|
+
if (!handler) {
|
|
1219
|
+
// An unrecognised command used to fall through to `return` without
|
|
1220
|
+
// pushing a message — the input vanished and nothing explained it.
|
|
1204
1221
|
setMessages((prev) => [
|
|
1205
1222
|
...prev,
|
|
1206
1223
|
{ role: 'user', content: input },
|
|
1207
|
-
{
|
|
1208
|
-
role: 'system',
|
|
1209
|
-
content: nextFocus
|
|
1210
|
-
? '✓ Focus mode ON — showing only the most recent exchange. Type /focus again to show all.'
|
|
1211
|
-
: '✓ Focus mode OFF — showing all messages.',
|
|
1212
|
-
},
|
|
1224
|
+
{ role: 'system', content: unknownCommandMessage(command) },
|
|
1213
1225
|
])
|
|
1214
1226
|
return
|
|
1215
1227
|
}
|
|
1216
|
-
|
|
1217
|
-
let forwardToAI: string | undefined
|
|
1218
|
-
|
|
1219
|
-
const handler = getCommand(command)
|
|
1220
1228
|
if (handler) {
|
|
1221
|
-
|
|
1229
|
+
// A handler that throws is not a crash of the session — see
|
|
1230
|
+
// `runCommandHandler`: the failure is reported as that command's
|
|
1231
|
+
// answer and the session continues.
|
|
1232
|
+
const outcome = await runCommandHandler(handler, mkCtx(), args)
|
|
1233
|
+
if (!outcome.ok) {
|
|
1234
|
+
setMessages((prev) => [
|
|
1235
|
+
...prev,
|
|
1236
|
+
{ role: 'user', content: input },
|
|
1237
|
+
{ role: 'system', content: `❌ ${command} failed: ${outcome.message}` },
|
|
1238
|
+
])
|
|
1239
|
+
return
|
|
1240
|
+
}
|
|
1241
|
+
const result = outcome.result
|
|
1222
1242
|
forwardToAI = result.forwardToAI
|
|
1223
1243
|
// Handle API key prompt from command result
|
|
1224
1244
|
if (result.needsApiKey) {
|