@miphamai/cli 0.85.39 → 0.85.40

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.
@@ -123,11 +123,8 @@ export const webSearchTool: ToolDefinition = {
123
123
  '',
124
124
  '3. Restart Mipham Code and try again.',
125
125
  '',
126
- 'Alternatives (add API key for any):',
127
- ' TAVILY_API_KEY — https://tavily.com',
128
- ' SERPAPI_API_KEY — https://serpapi.com',
129
- '',
130
126
  'No API key? Use the web-access skill (CDP through your logged-in Chrome) for live web search.',
127
+ 'Do not scrape search-engine result pages with WebFetch/curl — they answer 403/429 or a captcha.',
131
128
  ].join('\n'),
132
129
  }
133
130
  }
package/src/ui/app.tsx CHANGED
@@ -29,6 +29,7 @@ import {
29
29
  } from '../agent/cross-session/discovery'
30
30
  import { ChatPanel } from './chat'
31
31
  import { InputBar } from './input'
32
+ import { recordKeyEvent, recordRenderCommit } from './input-debug'
32
33
  import { ModelPicker } from './picker'
33
34
  import { CopyPicker, type CopyPickerItem } from './copy-picker'
34
35
  import { AgentFooter, type AgentEntry } from './agent-footer'
@@ -1388,7 +1389,14 @@ export function App({
1388
1389
  // Ctrl+C 的「再按一次才退」,语义与计时器见 ui/ctrl-c-confirm.ts
1389
1390
  const ctrlC = useCtrlCConfirm()
1390
1391
 
1392
+ // 诊断(`MIPHAM_DEBUG_INPUT=1`):冻结时区分「输入没送达」与「送达但没渲染」。
1393
+ // 默认关闭时只是一次缓存布尔判断,见 ui/input-debug.ts。
1394
+ useEffect(() => {
1395
+ recordRenderCommit()
1396
+ })
1397
+
1391
1398
  useInput((input, key) => {
1399
+ recordKeyEvent(input, key)
1392
1400
  // Ctrl+C:先关最上面那一层;没得关时**不退出**,只提示「再按一次」。
1393
1401
  //
1394
1402
  // 从前这里没有这个分支,而 Ink 自己的 Ctrl+C 处理(`exitOnCtrlC`,默认
@@ -0,0 +1,164 @@
1
+ /**
2
+ * 输入诊断开关:`MIPHAM_DEBUG_INPUT=1`。
3
+ *
4
+ * 「窗口冻结」从进程外看只有一种样子:进程活着、主线程停在 `kevent`、终端还留在
5
+ * raw 模式、按键没有反应。但它至少是两种完全不同的故障:
6
+ *
7
+ * A. 按键**没有送达应用**(stdin 侧:监听被摘掉、流被暂停、子进程抢了 tty)
8
+ * B. 按键送达了,但**没有组件处理或没有渲染**(React 侧:树被替换、handler 早退)
9
+ *
10
+ * 两者的补救方向相反,而进程外无法区分。所以这里在「应用看见每个按键的那一刻」
11
+ * 与「每次提交渲染」各记一笔,按秒汇总成一行写进 `~/.mipham/input-debug.log`:
12
+ *
13
+ * 有 keys、有 renders → 应用在处理(问题在输出/终端侧)
14
+ * 有 keys、无 renders → 渲染死了(B)
15
+ * 一个 key 都没有 → 输入没送达(A)
16
+ *
17
+ * 只记**计数与按键类别**,不记文本内容(与遥测的 no-free-text 约束一致)。
18
+ * 默认关闭;关闭时每条路径只是一次缓存过的布尔判断,不产生任何 I/O。
19
+ */
20
+
21
+ import { statSync, truncateSync } from 'node:fs'
22
+ import { miphamHome } from '../core/paths.ts'
23
+ import { appendRegularFileSync, isRegularFile } from '../shared/regular-file.ts'
24
+
25
+ /** 超过这个大小就在启动时截断:诊断日志不该成为磁盘问题。 */
26
+ const MAX_BYTES = 2 * 1024 * 1024
27
+ /** 汇总行间隔。1s 足够区分「冻结后还有没有活动」。 */
28
+ export const FLUSH_INTERVAL_MS = 1000
29
+
30
+ /** 只取本模块关心的字段,避免把 Ink 的 Key 类型搬进来。 */
31
+ export interface DebugKeyShape {
32
+ ctrl?: boolean
33
+ shift?: boolean
34
+ escape?: boolean
35
+ return?: boolean
36
+ tab?: boolean
37
+ upArrow?: boolean
38
+ downArrow?: boolean
39
+ leftArrow?: boolean
40
+ rightArrow?: boolean
41
+ backspace?: boolean
42
+ delete?: boolean
43
+ }
44
+
45
+ export interface InputDebugOptions {
46
+ /** 写入的文件;默认 `~/.mipham/input-debug.log`。 */
47
+ filePath?: string
48
+ /** 测试注入。 */
49
+ now?: () => number
50
+ pid?: number
51
+ }
52
+
53
+ export interface InputDebug {
54
+ recordKey(input: string, key: DebugKeyShape): void
55
+ recordRender(): void
56
+ /** 把当前窗口的计数写成一行(无新事件时不写)。 */
57
+ flush(): void
58
+ dispose(): void
59
+ }
60
+
61
+ /** 按键的人类可读类别 —— 只有类别,没有文本内容。 */
62
+ export function describeKey(input: string, key: DebugKeyShape): string {
63
+ if (key.ctrl) return `ctrl:${input || '?'}`
64
+ if (key.escape) return 'escape'
65
+ if (key.return) return 'return'
66
+ if (key.tab) return 'tab'
67
+ if (key.upArrow) return 'up'
68
+ if (key.downArrow) return 'down'
69
+ if (key.leftArrow) return 'left'
70
+ if (key.rightArrow) return 'right'
71
+ if (key.backspace) return 'backspace'
72
+ if (key.delete) return 'delete'
73
+ // 整串都可打印才叫文本;混进控制字符(ESC 序列等)就只报长度,
74
+ // 避免把终端逃逸序列原样写进日志。
75
+ const allPrintable = /^[\x20-\x7e\u0080-￿]+$/.test(input)
76
+ return `${allPrintable ? 'text' : 'raw'}:${input.length}`
77
+ }
78
+
79
+ export function createInputDebug(opts: InputDebugOptions = {}): InputDebug {
80
+ const filePath = opts.filePath ?? miphamHome('input-debug.log')
81
+ const now = opts.now ?? Date.now
82
+ const pid = opts.pid ?? process.pid
83
+
84
+ let keys = 0
85
+ let renders = 0
86
+ let bytes = 0
87
+ let last = 'none'
88
+ let dirty = false
89
+
90
+ // 启动标记:一个文件里能分出「这是哪一次进程、从哪一刻开始」。
91
+ try {
92
+ // 只在**普通文件**上截断:`truncateSync` 同样会打开目标,撞上 FIFO 就挂住
93
+ // (见 shared/regular-file.ts 的来由)。
94
+ if (isRegularFile(filePath) && statSync(filePath).size > MAX_BYTES) truncateSync(filePath, 0)
95
+ const wrote = appendRegularFileSync(
96
+ filePath,
97
+ `--- start pid=${pid} at=${new Date(now()).toISOString()} ---\n`,
98
+ )
99
+ if (!wrote) throw new Error('not a regular file')
100
+ } catch {
101
+ // 写不了诊断日志不是运行时错误:静默降级为「不诊断」。
102
+ return {
103
+ recordKey() {},
104
+ recordRender() {},
105
+ flush() {},
106
+ dispose() {},
107
+ }
108
+ }
109
+
110
+ return {
111
+ recordKey(input: string, key: DebugKeyShape): void {
112
+ keys += 1
113
+ bytes += input.length
114
+ last = describeKey(input, key)
115
+ dirty = true
116
+ },
117
+ recordRender(): void {
118
+ renders += 1
119
+ dirty = true
120
+ },
121
+ flush(): void {
122
+ if (!dirty) return
123
+ dirty = false
124
+ const line =
125
+ `${new Date(now()).toISOString()} pid=${pid} ` +
126
+ `keys=${keys} renders=${renders} bytes=${bytes} last=${last}\n`
127
+ try {
128
+ appendRegularFileSync(filePath, line)
129
+ } catch {
130
+ /* 同上:诊断失败不影响主流程 */
131
+ }
132
+ keys = 0
133
+ renders = 0
134
+ bytes = 0
135
+ },
136
+ dispose(): void {
137
+ this.flush()
138
+ },
139
+ }
140
+ }
141
+
142
+ // ── 进程级单例(接线点用;关闭时缓存的 null 让每次调用只是一次比较) ──
143
+
144
+ let singleton: InputDebug | null | undefined
145
+
146
+ export function getInputDebug(): InputDebug | null {
147
+ if (singleton !== undefined) return singleton
148
+ if (process.env.MIPHAM_DEBUG_INPUT !== '1') {
149
+ singleton = null
150
+ return null
151
+ }
152
+ singleton = createInputDebug()
153
+ const timer = setInterval(() => singleton?.flush(), FLUSH_INTERVAL_MS)
154
+ timer.unref?.()
155
+ return singleton
156
+ }
157
+
158
+ export function recordKeyEvent(input: string, key: DebugKeyShape): void {
159
+ getInputDebug()?.recordKey(input, key)
160
+ }
161
+
162
+ export function recordRenderCommit(): void {
163
+ getInputDebug()?.recordRender()
164
+ }