@miphamai/cli 0.85.53 → 0.85.54
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 +1 -1
- package/package.json +6 -6
- package/src/agent/agent-registry.ts +17 -2
- package/src/commands/environment.ts +71 -35
- package/src/commands/project.ts +31 -0
- package/src/config/loader.ts +52 -3
- package/src/core/credential-masker/matcher.ts +38 -0
- package/src/core/engine.ts +45 -4
- package/src/core/hooks.ts +18 -7
- package/src/core/instructions.ts +16 -2
- package/src/core/rules-loader.ts +4 -1
- package/src/core/session-insights.ts +8 -2
- package/src/core/session-store.ts +30 -23
- package/src/daemon/launch.ts +11 -1
- package/src/i18n-core/locales/en-US.json +5 -1
- package/src/i18n-core/locales/zh-CN.json +5 -1
- package/src/index.tsx +10 -3
- package/src/mcp/transport.ts +35 -3
- package/src/providers/anthropic.ts +17 -1
- package/src/providers/openai-compat.ts +13 -1
- package/src/shared/package-info.ts +2 -2
- package/src/skills/loader.ts +9 -2
- package/src/tools/agent/workflow.ts +2 -0
- package/src/tools/exec/task.ts +41 -0
- package/src/tools/file/grep.ts +30 -1
- package/src/tools/network/web-fetch.ts +11 -2
- package/src/ui/chat.tsx +17 -0
- package/src/ui/commands.ts +272 -29
- package/src/ui/picker.tsx +120 -19
- package/src/workflow/primitives/agent.ts +6 -0
- package/src/workflow/runtime.ts +45 -0
package/src/daemon/launch.ts
CHANGED
|
@@ -258,9 +258,19 @@ export async function startDetachedDaemon(
|
|
|
258
258
|
if (status) return { ok: true, pid: status.pid, port: status.port }
|
|
259
259
|
if (exitCode !== null) {
|
|
260
260
|
const tail = tailLog(plan.logPath)
|
|
261
|
+
// A denied folder is the macOS failure users hit most, and the log line
|
|
262
|
+
// is a bare EPERM/EACCES. Name the setting to check instead of leaving
|
|
263
|
+
// them to guess which sandbox refused (CC 2.1.333-158).
|
|
264
|
+
const privacyHint =
|
|
265
|
+
process.platform === 'darwin' &&
|
|
266
|
+
/eacces|eperm|operation not permitted|permission denied/i.test(tail)
|
|
267
|
+
? '\nOn macOS this can mean the daemon may not read the project folder — check ' +
|
|
268
|
+
'System Settings → Privacy & Security → Files and Folders (or Full Disk Access) ' +
|
|
269
|
+
'for your terminal.'
|
|
270
|
+
: ''
|
|
261
271
|
return {
|
|
262
272
|
ok: false,
|
|
263
|
-
reason: `daemon exited with code ${exitCode}${tail ? `:\n${tail}` : ''}`,
|
|
273
|
+
reason: `daemon exited with code ${exitCode}${tail ? `:\n${tail}` : ''}${privacyHint}`,
|
|
264
274
|
}
|
|
265
275
|
}
|
|
266
276
|
}
|
|
@@ -496,6 +496,7 @@
|
|
|
496
496
|
"location": "Location: {path}",
|
|
497
497
|
"source_user": "user",
|
|
498
498
|
"source_project": "project",
|
|
499
|
+
"source_plugin": "plugin",
|
|
499
500
|
"gated": "⚠️ workspace not trusted — will not run",
|
|
500
501
|
"undispatched": "⚠️ no dispatch point in this version — will not run",
|
|
501
502
|
"disabled_all": "⚠️ disableAllHooks is set — will not run",
|
|
@@ -795,7 +796,10 @@
|
|
|
795
796
|
"select_provider_hint": "Select a provider → Enter to see models",
|
|
796
797
|
"select_model_hint": "Select a model → Enter to switch",
|
|
797
798
|
"needs_api_key": "{provider} requires an API Key",
|
|
798
|
-
"api_key_placeholder": "Paste API Key and press Enter..."
|
|
799
|
+
"api_key_placeholder": "Paste API Key and press Enter...",
|
|
800
|
+
"search_placeholder": "Type to filter...",
|
|
801
|
+
"search_no_match": "(no matching models)",
|
|
802
|
+
"search_hint": "Type to filter · ↑↓ move · Enter select · Esc clears search"
|
|
799
803
|
},
|
|
800
804
|
"command_picker": {
|
|
801
805
|
"title": "Commands",
|
|
@@ -496,6 +496,7 @@
|
|
|
496
496
|
"location": "位置: {path}",
|
|
497
497
|
"source_user": "用户级",
|
|
498
498
|
"source_project": "项目级",
|
|
499
|
+
"source_plugin": "插件",
|
|
499
500
|
"gated": "⚠️ 工作区未受信任,不会运行",
|
|
500
501
|
"undispatched": "⚠️ 本版本没有派发点,不会运行",
|
|
501
502
|
"disabled_all": "⚠️ 已设 disableAllHooks,不会运行",
|
|
@@ -795,7 +796,10 @@
|
|
|
795
796
|
"select_provider_hint": "选择提供商 → Enter 查看模型",
|
|
796
797
|
"select_model_hint": "选择模型 → Enter 切换",
|
|
797
798
|
"needs_api_key": "{provider} 需要 API Key",
|
|
798
|
-
"api_key_placeholder": "粘贴 API Key 后按 Enter..."
|
|
799
|
+
"api_key_placeholder": "粘贴 API Key 后按 Enter...",
|
|
800
|
+
"search_placeholder": "输入以筛选...",
|
|
801
|
+
"search_no_match": "(无匹配模型)",
|
|
802
|
+
"search_hint": "输入筛选 · ↑↓ 移动 · Enter 选择 · Esc 清空搜索"
|
|
799
803
|
},
|
|
800
804
|
"command_picker": {
|
|
801
805
|
"title": "命令",
|
package/src/index.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
loadCrossSessionConfig,
|
|
12
12
|
loadSettingsJson,
|
|
13
13
|
settingsPathFor,
|
|
14
|
+
loadDisabledMcpServers,
|
|
14
15
|
} from './config/loader'
|
|
15
16
|
import { getPreference } from './config/preferences'
|
|
16
17
|
import {
|
|
@@ -315,7 +316,13 @@ async function connectMcpServers(
|
|
|
315
316
|
mcpServers: McpServerConfig[],
|
|
316
317
|
tools: ReturnType<typeof createToolRegistry>,
|
|
317
318
|
): Promise<McpConnectFailure[]> {
|
|
318
|
-
|
|
319
|
+
// `/mcp disable` is a gate on *starting* a server, not just on its tools:
|
|
320
|
+
// disabled entries are filtered before any process is spawned. The filter
|
|
321
|
+
// lives here (the single startup path) so a future caller cannot connect a
|
|
322
|
+
// disabled server by forgetting a check of its own.
|
|
323
|
+
const disabled = loadDisabledMcpServers()
|
|
324
|
+
const activeServers = mcpServers.filter((s) => !disabled.has(s.name))
|
|
325
|
+
if (activeServers.length === 0) return []
|
|
319
326
|
const mcp = McpClient.getInstance()
|
|
320
327
|
// A server that dies mid-session should come back on its own; the retry is
|
|
321
328
|
// bounded and stops early on a definitive refusal. `MIPHAM_MCP_AUTO_RECONNECT=0`
|
|
@@ -324,7 +331,7 @@ async function connectMcpServers(
|
|
|
324
331
|
// Wire runtime tool-list changes before connect so mid-connect updates land.
|
|
325
332
|
syncMcpToolsOnChange(mcp, tools)
|
|
326
333
|
const results = await Promise.allSettled(
|
|
327
|
-
|
|
334
|
+
activeServers.map(async (server) => {
|
|
328
335
|
await mcp.connect(server)
|
|
329
336
|
registerMcpServerTools(server.name, tools)
|
|
330
337
|
}),
|
|
@@ -333,7 +340,7 @@ async function connectMcpServers(
|
|
|
333
340
|
for (let i = 0; i < results.length; i++) {
|
|
334
341
|
const result = results[i]!
|
|
335
342
|
if (result.status === 'rejected') {
|
|
336
|
-
const name =
|
|
343
|
+
const name = activeServers[i]!.name
|
|
337
344
|
const reason = String(result.reason)
|
|
338
345
|
failures.push({ name, reason })
|
|
339
346
|
// Say the retry out loud when there is one: the client is already trying
|
package/src/mcp/transport.ts
CHANGED
|
@@ -35,6 +35,30 @@ export const DEFAULT_REQUEST_TIMEOUT_MS = 60_000
|
|
|
35
35
|
*/
|
|
36
36
|
export const MCP_SHUTDOWN_GRACE_MS = 300
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Cap on one un-terminated stdio line. A server that keeps writing without a
|
|
40
|
+
* newline — a log line, or output without JSON-RPC framing — would otherwise
|
|
41
|
+
* grow `buffer` without bound for as long as the session runs (CC 2.1.333-085).
|
|
42
|
+
*/
|
|
43
|
+
export const MAX_STDIO_LINE_CHARS = 8 * 1024 * 1024
|
|
44
|
+
|
|
45
|
+
/** Split a stdio chunk into complete lines, dropping an oversized partial line. */
|
|
46
|
+
export function takeStdioLines(
|
|
47
|
+
buffer: string,
|
|
48
|
+
chunk: string,
|
|
49
|
+
max = MAX_STDIO_LINE_CHARS,
|
|
50
|
+
): { lines: string[]; rest: string; overflow: boolean } {
|
|
51
|
+
const combined = buffer + chunk
|
|
52
|
+
const lines = combined.split('\n')
|
|
53
|
+
let rest = lines.pop() || ''
|
|
54
|
+
let overflow = false
|
|
55
|
+
if (rest.length > max) {
|
|
56
|
+
rest = ''
|
|
57
|
+
overflow = true
|
|
58
|
+
}
|
|
59
|
+
return { lines, rest, overflow }
|
|
60
|
+
}
|
|
61
|
+
|
|
38
62
|
/** Resolve when `proc` exits, or after `ms` — whichever comes first. */
|
|
39
63
|
function waitForExit(proc: ChildProcess, ms: number): Promise<void> {
|
|
40
64
|
if (proc.exitCode !== null || proc.signalCode !== null) return Promise.resolve()
|
|
@@ -224,6 +248,7 @@ export class StdioTransport implements Transport {
|
|
|
224
248
|
>()
|
|
225
249
|
private notificationHandlers: NotificationHandler[] = []
|
|
226
250
|
private buffer = ''
|
|
251
|
+
private oversizeWarned = false
|
|
227
252
|
private closed = false
|
|
228
253
|
|
|
229
254
|
async start(command: string, args: string[], env?: Record<string, string>): Promise<void> {
|
|
@@ -243,9 +268,16 @@ export class StdioTransport implements Transport {
|
|
|
243
268
|
})
|
|
244
269
|
|
|
245
270
|
child.stdout?.on('data', (data: Buffer) => {
|
|
246
|
-
this.buffer
|
|
247
|
-
|
|
248
|
-
|
|
271
|
+
const chunk = takeStdioLines(this.buffer, data.toString())
|
|
272
|
+
this.buffer = chunk.rest
|
|
273
|
+
if (chunk.overflow && !this.oversizeWarned) {
|
|
274
|
+
this.oversizeWarned = true
|
|
275
|
+
process.stderr.write(
|
|
276
|
+
`[mcp] dropped a stdio message longer than ${MAX_STDIO_LINE_CHARS} characters ` +
|
|
277
|
+
'without a newline\n',
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
const lines = chunk.lines
|
|
249
281
|
|
|
250
282
|
for (const line of lines) {
|
|
251
283
|
const trimmed = line.trim()
|
|
@@ -352,7 +352,23 @@ export class AnthropicProvider implements ProviderInstance {
|
|
|
352
352
|
|
|
353
353
|
let parsedInput: Record<string, unknown> = {}
|
|
354
354
|
try {
|
|
355
|
-
|
|
355
|
+
const parsed: unknown = accumulatedToolInput
|
|
356
|
+
? JSON.parse(accumulatedToolInput)
|
|
357
|
+
: {}
|
|
358
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
359
|
+
parsedInput = parsed as Record<string, unknown>
|
|
360
|
+
} else {
|
|
361
|
+
// `null`, a number, a string or an array is not a tool
|
|
362
|
+
// input. Storing it verbatim poisoned the session: every
|
|
363
|
+
// later request re-serialized it as this call's
|
|
364
|
+
// `arguments` (CC 2.1.334-017).
|
|
365
|
+
parsedInput = {
|
|
366
|
+
_parseError:
|
|
367
|
+
`tool input must be a JSON object; received ` +
|
|
368
|
+
`${JSON.stringify(parsed)?.slice(0, 80) ?? String(parsed)}`,
|
|
369
|
+
_raw: accumulatedToolInput,
|
|
370
|
+
}
|
|
371
|
+
}
|
|
356
372
|
} catch (err) {
|
|
357
373
|
// Same tag as the OpenAI-compatible path: a bare fragment
|
|
358
374
|
// reaches the validator as "missing required parameter",
|
|
@@ -549,7 +549,19 @@ export class OpenAICompatProvider implements ProviderInstance {
|
|
|
549
549
|
private safeParseJson(raw: string): Record<string, unknown> {
|
|
550
550
|
if (!raw) return {}
|
|
551
551
|
try {
|
|
552
|
-
|
|
552
|
+
const parsed: unknown = JSON.parse(raw)
|
|
553
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
554
|
+
return parsed as Record<string, unknown>
|
|
555
|
+
}
|
|
556
|
+
// A non-object (`null`, `5`, `"x"`, `[]`) must not reach history: it is
|
|
557
|
+
// re-serialized as this call's `arguments` on every later request and
|
|
558
|
+
// poisons the session (CC 2.1.334-017).
|
|
559
|
+
return {
|
|
560
|
+
_parseError:
|
|
561
|
+
`tool input must be a JSON object; received ` +
|
|
562
|
+
`${JSON.stringify(parsed)?.slice(0, 80) ?? String(parsed)}`,
|
|
563
|
+
_raw: raw,
|
|
564
|
+
}
|
|
553
565
|
} catch (err) {
|
|
554
566
|
// Tag the failure instead of handing back a bare fragment: the tool's
|
|
555
567
|
// validator would then report "missing required parameter", and the model
|
|
@@ -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.
|
|
12
|
+
export const PACKAGE_VERSION = '0.85.54' as const
|
|
13
13
|
|
|
14
14
|
/** npm install 全局安装命令 */
|
|
15
15
|
export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` 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 =
|
|
93
|
+
export const TEST_COUNT = 5540 as const
|
package/src/skills/loader.ts
CHANGED
|
@@ -15,7 +15,10 @@ interface FrontmatterResult {
|
|
|
15
15
|
export function parseFrontmatter(raw: string): FrontmatterResult {
|
|
16
16
|
// Strip a leading UTF-8 BOM — otherwise `^---` never matches and a
|
|
17
17
|
// BOM-prefixed file is silently treated as body text (effectively ignored).
|
|
18
|
-
|
|
18
|
+
// Normalize CRLF too: a skill authored on Windows used to match none of the
|
|
19
|
+
// `\n`-anchored fence below, so its `name`/`description` were dropped and the
|
|
20
|
+
// whole file was read as body text (CC 2.1.333-097).
|
|
21
|
+
const src = raw.replace(/^\uFEFF/, '').replace(/\r\n/g, '\n')
|
|
19
22
|
const match = src.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/)
|
|
20
23
|
if (!match) {
|
|
21
24
|
return { data: {}, content: src }
|
|
@@ -207,7 +210,11 @@ export class SkillsLoader implements Skills {
|
|
|
207
210
|
private loadDirectory(dir: string, type: 'standard' | 'mipham'): void {
|
|
208
211
|
this.scannedDirs.set(dir, type)
|
|
209
212
|
try {
|
|
210
|
-
|
|
213
|
+
// Two skill folders with the same declared name resolve last-one-wins.
|
|
214
|
+
// Directory order is filesystem-dependent, so which one wins changed from
|
|
215
|
+
// session to session; sort first so the documented precedence is stable
|
|
216
|
+
// (CC 2.1.333-130).
|
|
217
|
+
const entries = [...readdirSync(dir)].sort()
|
|
211
218
|
for (const entry of entries) {
|
|
212
219
|
const fullPath = join(dir, entry)
|
|
213
220
|
const isSkillFile = entry.endsWith('.SKILL.md') || entry.endsWith('.mipham-skill.md')
|
|
@@ -18,6 +18,8 @@ export const workflowTool: ToolDefinition = {
|
|
|
18
18
|
'## Primitives\n\n' +
|
|
19
19
|
'- agent(prompt: string, opts?: {label?, phase?, schema?, model?, effort?, isolation?}): Promise<any> — spawn a subagent. ' +
|
|
20
20
|
'Without schema, returns final text as string. With schema (JSON Schema), returns validated object — retries on mismatch.\n' +
|
|
21
|
+
'- stopAgent(id: string): number — abort the agent(s) started with `label: id`; the rest keep running. ' +
|
|
22
|
+
'Returns how many live calls were stopped (0 = already finished). The stopped call rejects with AbortError.\n' +
|
|
21
23
|
'- parallel(thunks: Array<() => Promise<any>>): Promise<any[]> — BARRIER: runs all thunks concurrently, waits for all. ' +
|
|
22
24
|
'Failed thunks resolve to null. Use filter(Boolean) before consuming results.\n' +
|
|
23
25
|
'- pipeline(items: T[], ...stages): Promise<any[]> — NO barrier: each item flows through all stages independently. ' +
|
package/src/tools/exec/task.ts
CHANGED
|
@@ -204,6 +204,18 @@ function stopBackgroundTask(
|
|
|
204
204
|
* whichever session happened to be active would let one session's ids answer
|
|
205
205
|
* for another's.
|
|
206
206
|
*/
|
|
207
|
+
/** Ids in `ids` that name no task in this session. `null` when not an array. */
|
|
208
|
+
function findMissingTaskIds(ids: unknown, tasks: Map<string, Task>): string[] | null {
|
|
209
|
+
if (!Array.isArray(ids)) return null
|
|
210
|
+
const missing = ids.map((id) => String(id)).filter((id) => !tasks.has(id))
|
|
211
|
+
return missing.length > 0 ? missing : null
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function formatMissingTaskIds(missing: string[]): string {
|
|
215
|
+
const names = missing.map((id) => `#${id}`).join(', ')
|
|
216
|
+
return `Task ${names} not found — dependency was not recorded`
|
|
217
|
+
}
|
|
218
|
+
|
|
207
219
|
function isBlocked(task: Task, tasks: Map<string, Task>): boolean {
|
|
208
220
|
if (task.blockedBy.length === 0) return false
|
|
209
221
|
return task.blockedBy.some((depId) => {
|
|
@@ -359,6 +371,21 @@ export const taskTool: ToolDefinition = {
|
|
|
359
371
|
|
|
360
372
|
// ── CREATE ──
|
|
361
373
|
if (action === 'create') {
|
|
374
|
+
// A dependency id that names no task is recorded and later reported as
|
|
375
|
+
// "all resolved": `isBlocked` treats a missing dep as not blocking. Refuse
|
|
376
|
+
// before creating anything, so the caller can correct the id instead of
|
|
377
|
+
// getting a phantom edge back (CC 2.1.335-019).
|
|
378
|
+
const missing = [
|
|
379
|
+
...(findMissingTaskIds(params.addBlocks, tasks) ?? []),
|
|
380
|
+
...(findMissingTaskIds(params.addBlockedBy, tasks) ?? []),
|
|
381
|
+
]
|
|
382
|
+
if (missing.length > 0) {
|
|
383
|
+
return {
|
|
384
|
+
success: false,
|
|
385
|
+
content: '',
|
|
386
|
+
error: formatMissingTaskIds(missing),
|
|
387
|
+
}
|
|
388
|
+
}
|
|
362
389
|
const id = String(++taskCounter)
|
|
363
390
|
const subject = (params.subject as string) || 'Untitled'
|
|
364
391
|
const task: Task = {
|
|
@@ -443,6 +470,20 @@ export const taskTool: ToolDefinition = {
|
|
|
443
470
|
const task = tasks.get(taskId)
|
|
444
471
|
if (!task) return { success: false, content: '', error: `Task #${taskId} not found` }
|
|
445
472
|
|
|
473
|
+
// Validate first: a rejected update must not leave `subject`/`status`
|
|
474
|
+
// already changed (CC 2.1.335-019).
|
|
475
|
+
const missing = [
|
|
476
|
+
...(findMissingTaskIds(params.addBlocks, tasks) ?? []),
|
|
477
|
+
...(findMissingTaskIds(params.addBlockedBy, tasks) ?? []),
|
|
478
|
+
]
|
|
479
|
+
if (missing.length > 0) {
|
|
480
|
+
return {
|
|
481
|
+
success: false,
|
|
482
|
+
content: '',
|
|
483
|
+
error: formatMissingTaskIds(missing),
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
446
487
|
if (params.subject !== undefined) task.subject = params.subject as string
|
|
447
488
|
if (params.description !== undefined) task.description = params.description as string
|
|
448
489
|
if (params.activeForm !== undefined) task.activeForm = params.activeForm as string
|
package/src/tools/file/grep.ts
CHANGED
|
@@ -25,6 +25,30 @@ const KILL_GRACE_MS = 2_000
|
|
|
25
25
|
*/
|
|
26
26
|
const PIPE_DRAIN_GRACE_MS = 2_000
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Normalize the `include` argument into individual `--glob` patterns.
|
|
30
|
+
*
|
|
31
|
+
* Accepts a comma-separated list (`*.ts,*.tsx`) without splitting the commas
|
|
32
|
+
* inside a brace alternation (`*.{ts,tsx}`), and strips a leading `./` — both
|
|
33
|
+
* forms were passed verbatim to ripgrep and matched nothing.
|
|
34
|
+
*/
|
|
35
|
+
export function splitGlobList(list: string): string[] {
|
|
36
|
+
const out: string[] = []
|
|
37
|
+
let depth = 0
|
|
38
|
+
let start = 0
|
|
39
|
+
for (let i = 0; i < list.length; i++) {
|
|
40
|
+
const ch = list[i]
|
|
41
|
+
if (ch === '{') depth++
|
|
42
|
+
else if (ch === '}') depth = Math.max(0, depth - 1)
|
|
43
|
+
else if (ch === ',' && depth === 0) {
|
|
44
|
+
out.push(list.slice(start, i))
|
|
45
|
+
start = i + 1
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
out.push(list.slice(start))
|
|
49
|
+
return out.map((s) => s.trim().replace(/^\.\//, '')).filter((s) => s.length > 0)
|
|
50
|
+
}
|
|
51
|
+
|
|
28
52
|
/** Run a search command with a kill-timer; report whether the timeout fired. */
|
|
29
53
|
export async function runSearch(
|
|
30
54
|
cmd: string[],
|
|
@@ -190,7 +214,12 @@ export function createGrepTool(credentialConfig?: CredentialMaskingConfig): Tool
|
|
|
190
214
|
'!.sl',
|
|
191
215
|
pattern,
|
|
192
216
|
]
|
|
193
|
-
|
|
217
|
+
// A comma-separated list is legal, and a brace alternation contains
|
|
218
|
+
// commas of its own. Passing the raw string made both forms match
|
|
219
|
+
// nothing (`*.{ts,tsx},*.js`, or any leading `./`) (CC 2.1.334-096).
|
|
220
|
+
if (include) {
|
|
221
|
+
for (const glob of splitGlobList(include)) rgArgs.push('--glob', glob)
|
|
222
|
+
}
|
|
194
223
|
rgArgs.push(searchPath)
|
|
195
224
|
try {
|
|
196
225
|
const { stdout, stderr, timedOut, exitCode } = await runSearch(
|
|
@@ -12,6 +12,16 @@ const MAX_RETURN_CHARS = 100_000
|
|
|
12
12
|
* real address"; a URL past it is a payload, not a page, and refusing it before
|
|
13
13
|
* the permission prompt keeps a pathological string out of every layer below.
|
|
14
14
|
*/
|
|
15
|
+
/**
|
|
16
|
+
* Header values are case-insensitive: `Text/HTML` is the same media type as
|
|
17
|
+
* `text/html`, but a case-sensitive test returned the raw markup instead of
|
|
18
|
+
* converting it (CC 2.1.334-087).
|
|
19
|
+
*/
|
|
20
|
+
export function isHtmlContentType(value: string | null | undefined): boolean {
|
|
21
|
+
const contentType = (value || '').toLowerCase()
|
|
22
|
+
return contentType.includes('text/html') || contentType.includes('application/xhtml')
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
const MAX_URL_CHARS = 2_000
|
|
16
26
|
|
|
17
27
|
interface CacheEntry {
|
|
@@ -369,8 +379,7 @@ export const webFetchTool: ToolDefinition = {
|
|
|
369
379
|
}
|
|
370
380
|
|
|
371
381
|
// Determine content type; only convert HTML to markdown
|
|
372
|
-
const
|
|
373
|
-
const isHtml = contentType.includes('text/html') || contentType.includes('application/xhtml')
|
|
382
|
+
const isHtml = isHtmlContentType(response.headers.get('content-type'))
|
|
374
383
|
|
|
375
384
|
// A 4xx/5xx is a statement about the site, not a failure of the tool:
|
|
376
385
|
// hand the status and whatever body it returned to the model as a normal
|
package/src/ui/chat.tsx
CHANGED
|
@@ -58,7 +58,24 @@ function display(text: string): string {
|
|
|
58
58
|
*/
|
|
59
59
|
const MAX_RENDERED_LINES = 50
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Render at most this many characters of a single message body.
|
|
63
|
+
*
|
|
64
|
+
* The line cap above does not bound a *single* enormous line — a resumed
|
|
65
|
+
* message carrying a data URL or a minified blob renders whole, and Ink lays it
|
|
66
|
+
* out on every streamed chunk. Say how much was dropped rather than pretending
|
|
67
|
+
* the view is complete (CC 2.1.334-018).
|
|
68
|
+
*/
|
|
69
|
+
const MAX_RENDERED_CHARS = 20_000
|
|
70
|
+
|
|
61
71
|
function capRenderedLines(text: string): string {
|
|
72
|
+
if (text.length > MAX_RENDERED_CHARS) {
|
|
73
|
+
const hidden = text.length - MAX_RENDERED_CHARS
|
|
74
|
+
return (
|
|
75
|
+
text.slice(0, MAX_RENDERED_CHARS) +
|
|
76
|
+
`\n… ${hidden.toLocaleString('en-US')} more character${hidden === 1 ? '' : 's'}`
|
|
77
|
+
)
|
|
78
|
+
}
|
|
62
79
|
let newlines = 0
|
|
63
80
|
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) === 10) newlines++
|
|
64
81
|
if (newlines < MAX_RENDERED_LINES) return text
|