@miphamai/cli 0.85.35 → 0.85.36

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.
@@ -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.35' as const
12
+ export const PACKAGE_VERSION = '0.85.36' 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 = 138 as const
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 = 4814 as const
93
+ export const TEST_COUNT = 4928 as const
@@ -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
 
package/src/ui/app.tsx CHANGED
@@ -56,6 +56,7 @@ import {
56
56
  getCommand,
57
57
  looksLikeSlashCommand,
58
58
  parseSlashCommand,
59
+ unknownCommandMessage,
59
60
  handleSwitch,
60
61
  type CommandContext,
61
62
  } from './commands'
@@ -307,7 +308,7 @@ export function App({
307
308
  sessionId,
308
309
  agentViewManager,
309
310
  }: AppProps) {
310
- const { t } = useI18n()
311
+ const { t, locale } = useI18n()
311
312
  const PERMISSION_LABELS = useMemo<Record<PermissionMode, string>>(
312
313
  () => ({
313
314
  default: t('ui.permission.manual'),
@@ -565,8 +566,16 @@ export function App({
565
566
  engine.setEffort(level)
566
567
  },
567
568
  setFocusMode: (on: boolean) => setFocusMode(on),
569
+ getFocusMode: () => focusMode,
568
570
  setGoal: (text: string) => setGoalText(text),
569
- setUltracodeMode: (on: boolean) => setUltracodeMode(on),
571
+ setUltracodeMode: (on: boolean) => {
572
+ setUltracodeMode(on)
573
+ // The mode must reach the engine: the React state is display-only, and
574
+ // the previous wiring left the instruction alive for exactly one turn.
575
+ // Attached sessions have no local engine to configure (the command
576
+ // refuses there); the guard keeps that a runtime no-op, not a crash.
577
+ if ('setUltracodeMode' in engine) engine.setUltracodeMode(on)
578
+ },
570
579
  setUpdateStatus: (s: UpdateStatus) => setUpdateStatus(s),
571
580
  // Same read-back as Shift+Tab: `setMode` may clamp the request (org
572
581
  // `maxAllowedMode` / `forbiddenModes`), so the footer and the gate must
@@ -579,6 +588,7 @@ export function App({
579
588
  skillsLoader,
580
589
  pluginManager,
581
590
  t,
591
+ locale,
582
592
  }),
583
593
  [
584
594
  engine,
@@ -589,7 +599,11 @@ export function App({
589
599
  pluginManager,
590
600
  sessionId,
591
601
  t,
602
+ locale,
592
603
  setPermissionMode,
604
+ // `/focus` reads the live value through `getFocusMode`; without the dep
605
+ // the memoised ctx would keep returning the state it was born with.
606
+ focusMode,
593
607
  ],
594
608
  )
595
609
 
@@ -1154,9 +1168,9 @@ export function App({
1154
1168
  const { command, args } = parseSlashCommand(input)
1155
1169
 
1156
1170
  // Counted here rather than at the registry lookup below: /switch, /pick,
1157
- // /model-picker, /exit, /quit and /focus are special-cased and return
1158
- // before ever reaching it, so counting there would silently under-report
1159
- // six of the most-used commands.
1171
+ // /model-picker, /exit and /quit are special-cased and return before
1172
+ // ever reaching it, so counting there would silently under-report five
1173
+ // of the most-used commands.
1160
1174
  //
1161
1175
  // `commandLabelFor` collapses unrecognised names into `/unknown` — see it
1162
1176
  // for why an unbounded `command_name` is not a cosmetic problem.
@@ -1197,26 +1211,19 @@ export function App({
1197
1211
  void exitSession(0)
1198
1212
  }
1199
1213
 
1200
- // /focus toggle
1201
- if (command === '/focus') {
1202
- const nextFocus = !focusMode
1203
- setFocusMode(nextFocus)
1214
+ let forwardToAI: string | undefined
1215
+
1216
+ const handler = getCommand(command)
1217
+ if (!handler) {
1218
+ // An unrecognised command used to fall through to `return` without
1219
+ // pushing a message — the input vanished and nothing explained it.
1204
1220
  setMessages((prev) => [
1205
1221
  ...prev,
1206
1222
  { 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
- },
1223
+ { role: 'system', content: unknownCommandMessage(command) },
1213
1224
  ])
1214
1225
  return
1215
1226
  }
1216
-
1217
- let forwardToAI: string | undefined
1218
-
1219
- const handler = getCommand(command)
1220
1227
  if (handler) {
1221
1228
  const result = await handler(mkCtx(), args)
1222
1229
  forwardToAI = result.forwardToAI