@miphamai/cli 0.85.18 → 0.85.20

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.
Files changed (43) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/agent/agent-registry.ts +2 -0
  4. package/src/agent/auto-compact.ts +72 -0
  5. package/src/agent/sub-agent.ts +26 -1
  6. package/src/agent/types.ts +18 -0
  7. package/src/agent-view/agent-view-manager.ts +50 -0
  8. package/src/core/context.ts +15 -3
  9. package/src/core/engine.ts +52 -5
  10. package/src/core/instructions.ts +78 -2
  11. package/src/daemon/channel-message.ts +8 -1
  12. package/src/daemon/session-worker.ts +17 -2
  13. package/src/i18n-core/locales/en-US.json +13 -3
  14. package/src/i18n-core/locales/zh-CN.json +13 -3
  15. package/src/index.tsx +8 -0
  16. package/src/mcp/client.ts +46 -0
  17. package/src/mcp/instructions.ts +48 -10
  18. package/src/mcp/protocol.ts +69 -2
  19. package/src/mcp/registry.ts +2 -1
  20. package/src/mcp/transport.ts +70 -9
  21. package/src/plugin/plugin-manager.ts +29 -8
  22. package/src/providers/fetch-utils.ts +47 -2
  23. package/src/security/fd.ts +18 -0
  24. package/src/shared/package-info.ts +2 -2
  25. package/src/shared/sanitize.ts +6 -2
  26. package/src/shared/types.ts +16 -0
  27. package/src/skills/marketplace.ts +15 -5
  28. package/src/skills/registry.ts +4 -1
  29. package/src/tools/agent/agent.ts +24 -0
  30. package/src/tools/agent/skill.ts +13 -0
  31. package/src/tools/exec/bash.ts +10 -0
  32. package/src/tools/file/edit.ts +13 -2
  33. package/src/tools/file/grep.ts +11 -2
  34. package/src/tools/file/read.ts +30 -6
  35. package/src/tools/file/write.ts +22 -2
  36. package/src/tools/system/tool-search.ts +2 -1
  37. package/src/ui/agent-footer.tsx +16 -3
  38. package/src/ui/app.tsx +67 -15
  39. package/src/ui/chat.tsx +73 -11
  40. package/src/ui/commands.ts +35 -11
  41. package/src/ui/copy-picker.tsx +73 -0
  42. package/src/ui/input.tsx +137 -21
  43. package/src/workflow/primitives/agent.ts +24 -3
@@ -101,6 +101,16 @@ export interface ToolResult {
101
101
  success: boolean
102
102
  content: string
103
103
  error?: string
104
+ /**
105
+ * The call was **held back, not judged** — `auto` mode asked the classifier and
106
+ * got no usable answer, so nothing ran and asking again is appropriate (296-056).
107
+ *
108
+ * It is not a third failure state: `success` stays `false` and `error` still
109
+ * carries the text the model reads. This bit exists only so the *display* can
110
+ * tell "held back" from "ran and returned this", which are otherwise the same
111
+ * shape (both are `success: false` + an error string).
112
+ */
113
+ notRun?: boolean
104
114
  }
105
115
 
106
116
  // ── Task Notification Types ──
@@ -134,6 +144,12 @@ export interface StreamChunk {
134
144
  * either the output or the error text, and the two are indistinguishable.
135
145
  */
136
146
  isError?: boolean
147
+ /**
148
+ * `type: 'tool_result'` only. The call never ran because `auto` mode's
149
+ * classifier had no usable answer — held back, not judged (296-056). Distinct
150
+ * from the `retryable` field below, which describes a *provider* error.
151
+ */
152
+ notRun?: boolean
137
153
  error?: string
138
154
  /**
139
155
  * `type: 'error'` only. `false` means the provider knows the failure is
@@ -64,20 +64,30 @@ export function isValidSkillName(name: string): boolean {
64
64
  }
65
65
 
66
66
  /**
67
- * Read the marketplace sources from disk. A missing or corrupt file falls back
68
- * to the default Anthropic sources.
67
+ * Read the marketplace sources from disk. A missing file falls back to the
68
+ * default Anthropic sources silently — that is the ordinary first run. A
69
+ * **present but unusable** file also falls back, but reports through `warn`
70
+ * when given: the fallback value is what the next write persists, so quietly
71
+ * swapping a user's sources for the defaults is a silent data loss.
69
72
  */
70
- export function readMarketplaces(readFile: (path: string) => string | null): MarketplaceSource[] {
73
+ export function readMarketplaces(
74
+ readFile: (path: string) => string | null,
75
+ warn?: (message: string) => void,
76
+ ): MarketplaceSource[] {
71
77
  const raw = readFile(MARKETPLACES_PATH)
72
78
  if (raw === null) return [...DEFAULT_MARKETPLACES]
73
79
  try {
74
80
  const parsed = JSON.parse(raw)
75
- if (!Array.isArray(parsed)) return [...DEFAULT_MARKETPLACES]
81
+ if (!Array.isArray(parsed)) {
82
+ warn?.(`Marketplace file is not a list; using defaults (${MARKETPLACES_PATH})`)
83
+ return [...DEFAULT_MARKETPLACES]
84
+ }
76
85
  return parsed.filter(
77
86
  (s): s is MarketplaceSource =>
78
87
  !!s && typeof s === 'object' && typeof s.owner === 'string' && typeof s.repo === 'string',
79
88
  )
80
- } catch {
89
+ } catch (err) {
90
+ warn?.(`Could not read marketplace file (${MARKETPLACES_PATH}): ${String(err)}`)
81
91
  return [...DEFAULT_MARKETPLACES]
82
92
  }
83
93
  }
@@ -208,7 +208,10 @@ async function installFromMarketplace(
208
208
  skillName: string,
209
209
  marketplaceConfig?: MiphamConfig['marketplace'],
210
210
  ): Promise<InstallResult> {
211
- const sources = readMarketplaces((p) => (existsSync(p) ? readFileSync(p, 'utf-8') : null))
211
+ const sources = readMarketplaces(
212
+ (p) => (existsSync(p) ? readFileSync(p, 'utf-8') : null),
213
+ (m) => console.error(`⚠ ${m}`),
214
+ )
212
215
  const found = await findSkillInMarketplaces(skillName, sources, globalThis.fetch, downloadFile)
213
216
 
214
217
  if (!found) {
@@ -5,6 +5,9 @@ import { getBackgroundAgentRegistry } from '../../agent/background-registry'
5
5
 
6
6
  const VALID_TYPES: SubAgentType[] = ['general', 'explore', 'plan', 'code-review']
7
7
 
8
+ /** Same domain as the session-level `/effort` command (`ui/commands.ts`). */
9
+ const VALID_EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max']
10
+
8
11
  /**
9
12
  * Resolve whether a sub-agent should run in the background.
10
13
  *
@@ -64,6 +67,14 @@ export const agentTool: ToolDefinition = {
64
67
  description:
65
68
  'When false, execute synchronously and return the result directly. Default: true (background).',
66
69
  },
70
+ effort: {
71
+ type: 'string',
72
+ enum: ['low', 'medium', 'high', 'xhigh', 'max'],
73
+ description:
74
+ 'Reasoning effort for this sub-agent, same levels as /effort. Higher levels get a longer ' +
75
+ 'streaming idle budget so a long thinking pass is not mistaken for a stalled connection. ' +
76
+ 'Omit to inherit the provider default.',
77
+ },
67
78
  },
68
79
  required: ['description', 'prompt'],
69
80
  },
@@ -80,6 +91,18 @@ export const agentTool: ToolDefinition = {
80
91
  }
81
92
  }
82
93
 
94
+ // Reject rather than pass through: an unrecognized level silently lands on
95
+ // the 1× timeout, i.e. it behaves exactly like omitting the parameter while
96
+ // reading as though it took effect.
97
+ const effort = params.effort as string | undefined
98
+ if (effort !== undefined && !VALID_EFFORTS.includes(effort)) {
99
+ return {
100
+ success: false,
101
+ content: '',
102
+ error: `Invalid effort "${effort}". Valid levels: ${VALID_EFFORTS.join(', ')}`,
103
+ }
104
+ }
105
+
83
106
  const registry = ctx.registry
84
107
  const toolRegistry = ctx.toolRegistry
85
108
  if (!registry || !toolRegistry) {
@@ -112,6 +135,7 @@ export const agentTool: ToolDefinition = {
112
135
  type: agentType,
113
136
  agentDef,
114
137
  runInBackground,
138
+ effort,
115
139
  // Hand the caller's services down: the sub-agent keeps running the same
116
140
  // skills/agents/artifacts, and only the fields it owns are overridden.
117
141
  toolContext: ctx,
@@ -39,6 +39,19 @@ export const skillTool: ToolDefinition = {
39
39
  }
40
40
  }
41
41
 
42
+ // A skill marked `disable-model-invocation` is reserved for the user to run
43
+ // by hand. The broadcast filter (loader.buildSystemReminder) keeps it out of
44
+ // the ambient list, but that is not a gate: the model can still name it —
45
+ // from a compaction summary, a file, or its own memory — and land here. The
46
+ // reservation only holds if it is enforced at the point of use.
47
+ if (skill.disableModelInvocation) {
48
+ return {
49
+ success: false,
50
+ content: '',
51
+ error: `Skill "${skillName}" is reserved for user invocation (disable-model-invocation: true) and cannot be run through the Skill tool. Ask the user to run it.`,
52
+ }
53
+ }
54
+
42
55
  // Extract executable assets (scripts/references) if this skill bundles them.
43
56
  // No-op for every skill that has no entry in BUNDLED_SKILL_ASSETS.
44
57
  // A write failure (EACCES/ENOSPC) must not abort invocation: the skill body
@@ -32,6 +32,16 @@ const BLOCKED_PATTERNS = [
32
32
  // `rm -rf .` and its path spellings `./` and `../` delete the working directory;
33
33
  // `./build` and `../vendor` name an entry inside it and stay allowed.
34
34
  /\brm\s+-(?:rf|fr)\s+['"]?\.\.?(?:\/)?(?=["'\s;&|>]|$)/,
35
+ // The home directory under another name is still the home directory. `$HOME`
36
+ // expands to the same tree as `~`; on Windows `C:\Users\<name>` *is* the profile
37
+ // directory, long or in its 8.3 short form (`C:\Users\GUOHUA~1`). Guarding only
38
+ // the literal spellings above leaves each of these a one-word bypass.
39
+ /\brm\s+-(?:rf|fr)\s+['"]?\$\{?HOME\}?(?:["'\s/]|$)/,
40
+ /\brm\s+-(?:rf|fr)\s+['"]?[A-Za-z]:[\\/](?=["'\s;&|>]|$)/,
41
+ /\brm\s+-(?:rf|fr)\s+['"]?[A-Za-z]:[\\/]Users[\\/][^\\/\s"']+[\\/]?(?=["'\s;&|>]|$)/i,
42
+ // cmd.exe spells the same directories with percent signs; in scope whenever a
43
+ // command hands off to cmd (`cmd /c …`).
44
+ /\brm\s+-(?:rf|fr)\s+['"]?%(?:USERPROFILE|HOMEPATH|HOMEDRIVE)%/i,
35
45
  // Filesystem manipulation
36
46
  /\bmkfs\./,
37
47
  /\bdd\s+if=/,
@@ -1,7 +1,7 @@
1
1
  import { readFileSync, closeSync, constants } from 'node:fs'
2
2
  import type { ToolDefinition } from '../../shared/index.ts'
3
3
  import { resolveSafe } from '../../security/path'
4
- import { openNoFollow, writeFileNoFollow, isSymlinkLoop } from '../../security/fd'
4
+ import { openNoFollow, writeFileNoFollow, isSymlinkLoop, isValidUtf8 } from '../../security/fd'
5
5
 
6
6
  /**
7
7
  * Characters considered part of an identifier in source code.
@@ -102,7 +102,18 @@ export const editTool: ToolDefinition = {
102
102
  }
103
103
  let content: string
104
104
  try {
105
- content = readFileSync(rfd, 'utf-8')
105
+ const raw = readFileSync(rfd)
106
+ if (!isValidUtf8(raw)) {
107
+ return {
108
+ success: false,
109
+ content: '',
110
+ error:
111
+ `File is not valid UTF-8 (likely Windows-1252 / Shift-JIS / GBK / Latin-1): ${filePath}. ` +
112
+ 'Editing it would decode invalid bytes to U+FFFD and overwrite the originals on save. ' +
113
+ 'Convert the file to UTF-8 with an external tool first.',
114
+ }
115
+ }
116
+ content = raw.toString('utf-8')
106
117
  } finally {
107
118
  closeSync(rfd)
108
119
  }
@@ -94,19 +94,28 @@ export function createGrepTool(credentialConfig?: CredentialMaskingConfig): Tool
94
94
  properties: {
95
95
  pattern: { type: 'string', description: 'Regex pattern to search for' },
96
96
  path: { type: 'string', description: 'Directory or file to search in' },
97
+ file_path: {
98
+ type: 'string',
99
+ description:
100
+ 'Alias for "path" — accepted so a caller that names the search root the way Read/Write/Edit do still lands where it meant to.',
101
+ },
97
102
  include: { type: 'string', description: 'File pattern to include (e.g., "*.ts")' },
98
103
  },
99
104
  required: ['pattern'],
100
105
  },
101
106
  async execute(params, ctx) {
102
107
  const pattern = params.pattern as string
103
- const searchPath = resolveSafe(ctx.cwd, (params.path as string) || '.')
108
+ // `file_path` is the alias callers reach for (Read/Write/Edit all use it).
109
+ // Without it the value is dropped and the search silently falls back to `cwd`
110
+ // — answering a question about the wrong tree without saying so.
111
+ const explicitPath = (params.path as string) || (params.file_path as string) || undefined
112
+ const searchPath = resolveSafe(ctx.cwd, explicitPath || '.')
104
113
  const include = params.include as string | undefined
105
114
 
106
115
  // Scope guard: a top-level search root (home or filesystem root) scans an
107
116
  // enormous tree and stalls the find fallback for minutes. Fail fast and
108
117
  // ask for a project-scoped path instead of silently scanning everything.
109
- if (!params.path && isTopLevelScope(searchPath)) {
118
+ if (!explicitPath && isTopLevelScope(searchPath)) {
110
119
  return {
111
120
  success: false,
112
121
  content: '',
@@ -20,6 +20,17 @@ const CHUNK_BYTES = 64 * 1024
20
20
  */
21
21
  const MAX_SCAN_BYTES = 50_000_000
22
22
 
23
+ /**
24
+ * Scan budget when the caller passes `allow_large: true`.
25
+ *
26
+ * Reaching a line window near the end of a multi-GB log means scanning past the
27
+ * default 50 MB. That scan is real work, so it stays opt-in — but a caller who
28
+ * knows the file is huge and wants a window deep inside it can say so instead of
29
+ * being told to shell out. Still bounded (1 GB), so `allow_large` is "scan more",
30
+ * not "scan without limit".
31
+ */
32
+ const MAX_SCAN_BYTES_LARGE = 1_000_000_000
33
+
23
34
  /** Render a line window the way the tool reports it: ` 123\ttext`. */
24
35
  function formatLines(lines: string[], offset: number): string {
25
36
  return lines.map((l, i) => `${String(offset + i + 1).padStart(6, ' ')}\t${l}`).join('\n')
@@ -63,7 +74,12 @@ function windowFromString(content: string, offset: number, limit: number): strin
63
74
  * a character. Returns null when the window cannot be located within
64
75
  * `MAX_SCAN_BYTES`.
65
76
  */
66
- function windowFromFd(fd: number, offset: number, limit: number): string[] | null {
77
+ function windowFromFd(
78
+ fd: number,
79
+ offset: number,
80
+ limit: number,
81
+ maxScanBytes: number = MAX_SCAN_BYTES,
82
+ ): string[] | null {
67
83
  if (limit <= 0) return []
68
84
 
69
85
  const buf = Buffer.allocUnsafe(CHUNK_BYTES)
@@ -73,7 +89,7 @@ function windowFromFd(fd: number, offset: number, limit: number): string[] | nul
73
89
  let windowEnd = -1
74
90
  let eof = false
75
91
 
76
- while (windowEnd === -1 && scanned < MAX_SCAN_BYTES) {
92
+ while (windowEnd === -1 && scanned < maxScanBytes) {
77
93
  const n = readSync(fd, buf, 0, buf.length, scanned)
78
94
  if (n <= 0) {
79
95
  eof = true
@@ -128,6 +144,11 @@ export function createReadTool(credentialConfig?: CredentialMaskingConfig): Tool
128
144
  file_path: { type: 'string', description: 'Absolute path to the file to read' },
129
145
  offset: { type: 'integer', description: 'Line number to start reading from' },
130
146
  limit: { type: 'integer', description: 'Number of lines to read' },
147
+ allow_large: {
148
+ type: 'boolean',
149
+ description:
150
+ 'Allow scanning past 50 MB to locate the requested window in a very large file (opt-in; default false).',
151
+ },
131
152
  },
132
153
  required: ['file_path'],
133
154
  },
@@ -179,15 +200,18 @@ export function createReadTool(credentialConfig?: CredentialMaskingConfig): Tool
179
200
  }
180
201
 
181
202
  if (result === null) {
182
- const lines = windowFromFd(fd, offset, limit)
203
+ const allowLarge = params.allow_large === true
204
+ const scanBudget = allowLarge ? MAX_SCAN_BYTES_LARGE : MAX_SCAN_BYTES
205
+ const lines = windowFromFd(fd, offset, limit, scanBudget)
183
206
  if (lines === null) {
184
207
  return {
185
208
  success: false,
186
209
  content: '',
187
210
  error:
188
- `File too large: scanned ${MAX_SCAN_BYTES / 1e6} MB without reaching the end of lines ` +
189
- `${offset}–${offset + limit - 1}. Narrow the range (smaller offset or limit), or use a ` +
190
- `shell tool to slice the file.`,
211
+ `File too large: scanned ${scanBudget / 1e6} MB without reaching the end of lines ` +
212
+ `${offset}–${offset + limit - 1}. Narrow the range (smaller offset or limit)` +
213
+ (allowLarge ? '' : ', pass allow_large: true to scan further') +
214
+ `, or use a shell tool to slice the file.`,
191
215
  }
192
216
  }
193
217
  result = formatLines(lines, offset)
@@ -1,8 +1,8 @@
1
- import { mkdirSync, existsSync, constants } from 'node:fs'
1
+ import { mkdirSync, existsSync, readFileSync, constants } from 'node:fs'
2
2
  import { dirname } from 'node:path'
3
3
  import type { ToolDefinition } from '../../shared/index.ts'
4
4
  import { resolveSafe } from '../../security/path'
5
- import { writeFileNoFollow, isSymlinkLoop } from '../../security/fd'
5
+ import { writeFileNoFollow, isSymlinkLoop, isValidUtf8 } from '../../security/fd'
6
6
 
7
7
  export const writeTool: ToolDefinition = {
8
8
  name: 'Write',
@@ -42,6 +42,26 @@ export const writeTool: ToolDefinition = {
42
42
  }
43
43
  }
44
44
 
45
+ // ── Non-UTF-8 guard: refuse to clobber a file we cannot represent ──
46
+ // A Windows-1252 / Shift-JIS / GBK file read into the model came back as
47
+ // U+FFFD garbage; writing UTF-8 content over it would erase the originals
48
+ // with no error. Same-source as the Edit guard (`isValidUtf8`).
49
+ if (fileExists) {
50
+ try {
51
+ if (!isValidUtf8(readFileSync(filePath))) {
52
+ return {
53
+ success: false,
54
+ content: '',
55
+ error:
56
+ `File "${filePath}" is not valid UTF-8 (likely Windows-1252 / Shift-JIS / GBK / Latin-1). ` +
57
+ 'Overwriting it would destroy the original bytes. Convert it to UTF-8 or delete it first.',
58
+ }
59
+ }
60
+ } catch {
61
+ // Unreadable for another reason — let the write itself surface that.
62
+ }
63
+ }
64
+
45
65
  mkdirSync(dirname(filePath), { recursive: true })
46
66
 
47
67
  // O_NOFOLLOW: reject a symlink swapped in after resolveSafe (TOCTOU) —
@@ -8,6 +8,7 @@
8
8
 
9
9
  import type { ToolDefinition } from '../../shared/index.ts'
10
10
  import { McpClient } from '../../mcp/client'
11
+ import { capMcpText } from '../../mcp/instructions'
11
12
 
12
13
  export const toolSearchTool: ToolDefinition = {
13
14
  name: 'ToolSearch',
@@ -88,7 +89,7 @@ export const toolSearchTool: ToolDefinition = {
88
89
  matches.push({
89
90
  server: serverName,
90
91
  tool: tool.name,
91
- description: (tool.description || '').slice(0, 120),
92
+ description: capMcpText(tool.description || ''),
92
93
  })
93
94
  }
94
95
  }
@@ -1,6 +1,18 @@
1
1
  import React from 'react'
2
2
  import { Box, Text } from 'ink'
3
3
  import { useI18n } from '../i18n-context'
4
+ import { sanitizeInlineField } from '../shared/sanitize'
5
+
6
+ /**
7
+ * 页脚也是本文件通往终端的一道口 —— 且它内插的字全是**模型写出来的**:
8
+ * `activeTool` 的名称与详情来自工具调用参数(`ui/app.tsx` 的 `formatToolDetail`
9
+ * 只把 Bash 那支递给 `sanitizeForDisplay`,而那个函数**不剥** ESC / BEL / C1),
10
+ * agent 的名称与描述来自子代理定义。原样内插的话,模型在命令里写一个 `\x1b[2J`
11
+ * 就会被终端当清屏序列执行,而不是当文字显示。
12
+ *
13
+ * 三处内插一律过 `sanitizeInlineField`(单行口)。姊妹件是 `ui/chat.tsx` 的
14
+ * `display()` —— 那是**多行**口(工具输出要保换行),两者只差 `\n` 一个字。
15
+ */
4
16
 
5
17
  export interface AgentEntry {
6
18
  id: string
@@ -118,7 +130,8 @@ export function AgentFooter({ agents, tick, activeTool, agentProgress }: AgentFo
118
130
  {hasTool && (
119
131
  <Box>
120
132
  <Text color={toolIndicatorColor(activeTool!.name)}>
121
- {' '}[{activeTool!.name} {activeTool!.detail.slice(0, 60)}
133
+ {' '}[{sanitizeInlineField(activeTool!.name)}{' '}
134
+ {sanitizeInlineField(activeTool!.detail).slice(0, 60)}
122
135
  {animatedDots(tick)}]
123
136
  </Text>
124
137
  <Box flexGrow={1} />
@@ -165,9 +178,9 @@ export function AgentFooter({ agents, tick, activeTool, agentProgress }: AgentFo
165
178
  {symbol}{' '}
166
179
  </Text>
167
180
  <Text bold color={isRunning ? 'cyan' : undefined} dimColor={!isRunning}>
168
- {agent.name}
181
+ {sanitizeInlineField(agent.name)}
169
182
  </Text>
170
- <Text dimColor> {desc}</Text>
183
+ <Text dimColor> {sanitizeInlineField(desc)}</Text>
171
184
  {/* Spacer pushes elapsed + tokens to the right edge */}
172
185
  <Box flexGrow={1} />
173
186
  <Text dimColor>
package/src/ui/app.tsx CHANGED
@@ -30,6 +30,7 @@ import {
30
30
  import { ChatPanel } from './chat'
31
31
  import { InputBar } from './input'
32
32
  import { ModelPicker } from './picker'
33
+ import { CopyPicker, type CopyPickerItem } from './copy-picker'
33
34
  import { AgentFooter, type AgentEntry } from './agent-footer'
34
35
  import { GraftStatusLine } from './graft-status'
35
36
  import { checkForUpdatesAsync, type UpdateStatus } from '../shared/update'
@@ -86,6 +87,8 @@ export interface ToolMeta {
86
87
  collapsed: boolean
87
88
  /** Original tool name before Claude Code display renaming (e.g. Write→Update). */
88
89
  originalName?: string
90
+ /** Held back by the auto-mode classifier — rendered as a dim "Not run" row (296-056). */
91
+ notRun?: boolean
89
92
  }
90
93
 
91
94
  export interface ChatMessage {
@@ -220,6 +223,24 @@ export function formatToolDetail(name: string, input: Record<string, unknown>):
220
223
  }
221
224
 
222
225
  /** Claude Code display name: maps Write/Edit → Update for parity. */
226
+ /**
227
+ * Put text on the system clipboard. macOS/Windows only; Linux is left alone to
228
+ * avoid a hard dependency on xclip/wl-copy. Failures are swallowed — the content
229
+ * was still shown on screen, and a clipboard miss is not worth an error frame.
230
+ */
231
+ async function writeClipboard(text: string): Promise<void> {
232
+ try {
233
+ const { execSync } = await import('node:child_process')
234
+ if (process.platform === 'darwin') {
235
+ execSync('pbcopy', { input: text })
236
+ } else if (process.platform === 'win32') {
237
+ execSync('clip', { input: text })
238
+ }
239
+ } catch {
240
+ /* content is still displayed */
241
+ }
242
+ }
243
+
223
244
  function toolDisplayName(name: string): string {
224
245
  if (name === 'Write' || name === 'Edit') return 'Update'
225
246
  return name
@@ -290,6 +311,8 @@ export function App({
290
311
  const [providerId, setProviderId] = useState(initialProvider || config.defaultProvider)
291
312
  const [modelId, setModelId] = useState(initialModel || config.defaultModel)
292
313
  const [pickerOpen, setPickerOpen] = useState(false)
314
+ /** `/copy` with no argument — candidates for the interactive copy picker. */
315
+ const [copyPicker, setCopyPicker] = useState<{ items: CopyPickerItem[] } | null>(null)
293
316
  // ↑/↓ 翻历史用的已提交输入。**必须住在这里而不是 InputBar 里** —— InputBar 会被
294
317
  // 卸载(pickerOpen 三元 / apiKeyPrompt 早退 / Ctrl+G),组件内 state 随之清零,
295
318
  // 于是「开一次模型选择器,历史就没了」(ROADMAP D7)。
@@ -749,7 +772,27 @@ export function App({
749
772
  // Sync background agents (e.g. Agent tool may have spawned them)
750
773
  syncBgAgents()
751
774
  const output = chunk.content ? String(chunk.content).trim() : ''
752
- if (output && output !== '(no matches)' && output.length > 20) {
775
+ if (chunk.notRun) {
776
+ // Held back by the classifier — it never ran. Row shape is owned by
777
+ // `chat.tsx` (`toolMeta.notRun`), which labels it "Not run" instead
778
+ // of letting it read as the tool's output (296-056). Shown even when
779
+ // the reason is short: the whole point is that this row exists.
780
+ setMessages((prev) => [
781
+ ...prev,
782
+ {
783
+ role: 'system' as const,
784
+ content: output,
785
+ toolMeta: {
786
+ name: '',
787
+ input: '',
788
+ output,
789
+ collapsed: true,
790
+ originalName: chunk.toolUse?.name,
791
+ notRun: true,
792
+ },
793
+ },
794
+ ])
795
+ } else if (output && output !== '(no matches)' && output.length > 20) {
753
796
  // Generate diff-style summary for file operations (Claude Code parity)
754
797
  let preview: string
755
798
  const isFileOp = chunk.toolUse?.name === 'Write' || chunk.toolUse?.name === 'Edit'
@@ -1114,18 +1157,10 @@ export function App({
1114
1157
  }
1115
1158
  }
1116
1159
  if (result.copyContent) {
1117
- // Copy to clipboard via pbcopy (macOS) or clip (Windows)
1118
- try {
1119
- const { execSync } = await import('node:child_process')
1120
- if (process.platform === 'darwin') {
1121
- execSync('pbcopy', { input: result.copyContent })
1122
- } else if (process.platform === 'win32') {
1123
- execSync('clip', { input: result.copyContent })
1124
- }
1125
- // Linux: xclip or wl-copy not attempted to avoid dependency issues
1126
- } catch {
1127
- // Silent fail — content is still displayed
1128
- }
1160
+ await writeClipboard(result.copyContent)
1161
+ }
1162
+ if (result.openCopyPicker) {
1163
+ setCopyPicker({ items: result.openCopyPicker })
1129
1164
  }
1130
1165
  }
1131
1166
 
@@ -1212,6 +1247,10 @@ export function App({
1212
1247
  setPickerOpen(false)
1213
1248
  return true
1214
1249
  }
1250
+ if (copyPicker) {
1251
+ setCopyPicker(null)
1252
+ return true
1253
+ }
1215
1254
  if (isLoading && abortRef.current) {
1216
1255
  abortRef.current.abort()
1217
1256
  return true
@@ -1344,7 +1383,7 @@ export function App({
1344
1383
  ) : (
1345
1384
  <>
1346
1385
  {/* Chat panel */}
1347
- <ChatPanel messages={messages} focusMode={focusMode} />
1386
+ <ChatPanel messages={messages} focusMode={focusMode} turnActive={isLoading} />
1348
1387
  {(() => {
1349
1388
  const indicator = formatThinking(
1350
1389
  config.showThinking ?? 'off',
@@ -1355,7 +1394,20 @@ export function App({
1355
1394
  })()}
1356
1395
 
1357
1396
  {/* Input with separator lines */}
1358
- {pickerOpen ? (
1397
+ {copyPicker ? (
1398
+ <CopyPicker
1399
+ items={copyPicker.items}
1400
+ onSelect={(item) => {
1401
+ void writeClipboard(item.text)
1402
+ setCopyPicker(null)
1403
+ setMessages((prev) => [
1404
+ ...prev,
1405
+ { role: 'system', content: t('commands.copy.confirmed', { count: '1' }) },
1406
+ ])
1407
+ }}
1408
+ onClose={() => setCopyPicker(null)}
1409
+ />
1410
+ ) : pickerOpen ? (
1359
1411
  <ModelPicker
1360
1412
  config={config}
1361
1413
  currentProvider={providerId}