@miphamai/cli 0.32.5 → 0.32.7
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/package.json +1 -1
- package/src/core/instructions.ts +14 -0
- package/src/tools/file/grep.ts +9 -1
- package/src/ui/command-picker.tsx +34 -1
- package/src/ui/input.tsx +5 -2
package/package.json
CHANGED
package/src/core/instructions.ts
CHANGED
|
@@ -139,6 +139,20 @@ When a workflow completes successfully, offer to save it:
|
|
|
139
139
|
Script format: export const meta = { name, description, phases: [...] }
|
|
140
140
|
// script body using primitives...`)
|
|
141
141
|
|
|
142
|
+
// Inject code search conventions — prefer dedicated tools over raw Bash
|
|
143
|
+
parts.push(`## Code Search Conventions
|
|
144
|
+
|
|
145
|
+
- Prefer the **Grep** tool for file-content search — it runs ripgrep (rg),
|
|
146
|
+
10× faster than grep, with automatic fallback to grep if rg is unavailable
|
|
147
|
+
- Use the **Glob** tool to find files by name pattern, then Grep to search
|
|
148
|
+
their contents — narrow scope before full-text search
|
|
149
|
+
- Use **Bash** with grep/rg/find ONLY for complex multi-step pipelines
|
|
150
|
+
(e.g., pipe to sort | uniq -c | sort -rn, or chained find + xargs)
|
|
151
|
+
- Grep tool handles rg→grep fallback automatically; no need to
|
|
152
|
+
pre-check for rg availability or manually fall back
|
|
153
|
+
- When you need to search AND read results: Glob → Grep → Read
|
|
154
|
+
(find files, search contents, then read the matching files)`)
|
|
155
|
+
|
|
142
156
|
return parts.join('\n\n---\n\n')
|
|
143
157
|
}
|
|
144
158
|
|
package/src/tools/file/grep.ts
CHANGED
|
@@ -4,7 +4,15 @@ import { resolveSafe } from '../../security/path'
|
|
|
4
4
|
|
|
5
5
|
export const grepTool: ToolDefinition = {
|
|
6
6
|
name: 'Grep',
|
|
7
|
-
description:
|
|
7
|
+
description:
|
|
8
|
+
'Search file contents using ripgrep (rg) — the recommended code search tool. ' +
|
|
9
|
+
'~10× faster than grep, with automatic fallback to grep if rg is unavailable. ' +
|
|
10
|
+
'Use this for single-shot regex searches across files. ' +
|
|
11
|
+
'Prefer Grep over Bash grep/rg for code search; use Bash only for complex ' +
|
|
12
|
+
'multi-step pipelines (e.g., pipe to sort/uniq/wc, or chained find+xargs). ' +
|
|
13
|
+
'Best practice: narrow scope with `path` (directory/file) and `include` ' +
|
|
14
|
+
'(glob pattern, e.g. "*.ts") before searching. ' +
|
|
15
|
+
'The `pattern` parameter accepts full regex syntax (e.g., "log.*Error", "\\bclass\\s+\\w+").',
|
|
8
16
|
category: 'file',
|
|
9
17
|
permission: 'auto',
|
|
10
18
|
parameters: {
|
|
@@ -17,6 +17,31 @@ interface CommandPickerProps {
|
|
|
17
17
|
|
|
18
18
|
const PAGE_SIZE = 12
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Split a string into segments, marking which substrings match the query.
|
|
22
|
+
* Case-insensitive matching. Used to bold matching characters in the picker.
|
|
23
|
+
*/
|
|
24
|
+
function highlightMatches(text: string, query: string): { text: string; match: boolean }[] {
|
|
25
|
+
if (!query) return [{ text, match: false }]
|
|
26
|
+
const lowerText = text.toLowerCase()
|
|
27
|
+
const lowerQuery = query.toLowerCase()
|
|
28
|
+
const segments: { text: string; match: boolean }[] = []
|
|
29
|
+
let pos = 0
|
|
30
|
+
while (pos < text.length) {
|
|
31
|
+
const idx = lowerText.indexOf(lowerQuery, pos)
|
|
32
|
+
if (idx === -1) {
|
|
33
|
+
segments.push({ text: text.slice(pos), match: false })
|
|
34
|
+
break
|
|
35
|
+
}
|
|
36
|
+
if (idx > pos) {
|
|
37
|
+
segments.push({ text: text.slice(pos, idx), match: false })
|
|
38
|
+
}
|
|
39
|
+
segments.push({ text: text.slice(idx, idx + query.length), match: true })
|
|
40
|
+
pos = idx + query.length
|
|
41
|
+
}
|
|
42
|
+
return segments
|
|
43
|
+
}
|
|
44
|
+
|
|
20
45
|
/**
|
|
21
46
|
* CommandPicker — interactive slash-command selector.
|
|
22
47
|
*
|
|
@@ -107,12 +132,20 @@ export function CommandPicker({
|
|
|
107
132
|
{visible.map((cmd, i) => {
|
|
108
133
|
const globalIdx = i + scrollStart
|
|
109
134
|
const isCursor = globalIdx === cursorIdx
|
|
135
|
+
const query = filter.startsWith('/') ? filter.slice(1) : filter
|
|
136
|
+
const segments = highlightMatches(cmd.name, query)
|
|
137
|
+
const padLen = Math.max(0, 20 - cmd.name.length)
|
|
110
138
|
return (
|
|
111
139
|
<Box key={cmd.name}>
|
|
112
140
|
<Text color={itemColor(isCursor)} bold={itemBold(isCursor)}>
|
|
113
141
|
{isCursor ? '▶ ' : ' '}
|
|
114
|
-
{cmd.name.padEnd(20)}
|
|
115
142
|
</Text>
|
|
143
|
+
{segments.map((seg, j) => (
|
|
144
|
+
<Text key={j} color={itemColor(isCursor)} bold={itemBold(isCursor) || seg.match}>
|
|
145
|
+
{seg.text}
|
|
146
|
+
</Text>
|
|
147
|
+
))}
|
|
148
|
+
{padLen > 0 && <Text color={itemColor(isCursor)}>{' '.repeat(padLen)}</Text>}
|
|
116
149
|
<Text dimColor>{cmd.description}</Text>
|
|
117
150
|
</Box>
|
|
118
151
|
)
|
package/src/ui/input.tsx
CHANGED
|
@@ -398,13 +398,16 @@ export function InputBar({
|
|
|
398
398
|
historyIndexRef.current = -1
|
|
399
399
|
savedDraftRef.current = ''
|
|
400
400
|
}
|
|
401
|
+
// Normalize newlines → spaces. ink-text-input is single-line; multi-line
|
|
402
|
+
// paste would trap arrow-key navigation on the first line.
|
|
403
|
+
const normalized = val.replace(/\n/g, ' ')
|
|
401
404
|
// Throttle: first keystroke renders immediately, then batch at ~30fps.
|
|
402
405
|
// During paste, the terminal may send hundreds of characters in rapid
|
|
403
406
|
// succession — without throttling, each triggers a React render+Ink write
|
|
404
407
|
// cycle that starves the event loop and freezes the UI.
|
|
405
|
-
valueRef.current =
|
|
408
|
+
valueRef.current = normalized
|
|
406
409
|
if (onChangeTimerRef.current) return // timer pending, latest value in ref
|
|
407
|
-
setValue(
|
|
410
|
+
setValue(normalized)
|
|
408
411
|
onChangeTimerRef.current = setTimeout(() => {
|
|
409
412
|
onChangeTimerRef.current = null
|
|
410
413
|
setValue(valueRef.current)
|