@miphamai/cli 0.85.53 → 0.85.55
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/agent/sub-agent.ts +18 -2
- package/src/agent/types.ts +9 -0
- package/src/commands/environment.ts +71 -35
- package/src/commands/project.ts +31 -0
- package/src/config/loader.ts +112 -3
- package/src/core/command-taps.ts +10 -0
- package/src/core/credential-masker/matcher.ts +38 -0
- package/src/core/engine.ts +351 -6
- package/src/core/hooks.ts +18 -7
- package/src/core/instructions.ts +17 -3
- package/src/core/review-gate.ts +192 -0
- 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/core/task-performance-tasks.json +18 -0
- package/src/core/verification-baseline.ts +277 -0
- package/src/core/write-paths.ts +19 -0
- package/src/daemon/engine-capabilities.ts +22 -1
- package/src/daemon/launch.ts +11 -1
- package/src/i18n-core/locales/en-US.json +9 -1
- package/src/i18n-core/locales/zh-CN.json +9 -1
- package/src/index.tsx +35 -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/shared/types.ts +11 -0
- package/src/skills/fork-executor.ts +3 -2
- package/src/skills/loader.ts +9 -2
- package/src/tools/agent/skill.ts +1 -0
- package/src/tools/agent/workflow.ts +3 -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 +280 -29
- package/src/ui/picker.tsx +120 -19
- package/src/workflow/primitives/agent.ts +10 -1
- package/src/workflow/runtime.ts +49 -0
|
@@ -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",
|
|
@@ -1013,6 +1017,10 @@
|
|
|
1013
1017
|
"turn_refused": "The model declined this request and did not answer. This is not a failure — resending it to the same model will usually be declined again.",
|
|
1014
1018
|
"turn_refused_reason": "The model declined this request: {reason}",
|
|
1015
1019
|
"stop_hook_budget_spent": "The Stop hook asked for more work (\"{reason}\"), but this turn has used all {max} of its tool-calling rounds — stopping here. Send another message to continue.",
|
|
1020
|
+
"review_gate_error": "Review gate could not run: {message}. Continuing without a review.",
|
|
1021
|
+
"verification_missing": "This turn wrote source files after the last mechanical check — these baseline checks have not run since the last edit: {missing}. Run them now, or end with two explicit sections: Verified / Not verified.",
|
|
1022
|
+
"verification_budget_spent": "All tool-calling rounds for this turn are used, so these baseline checks were not run: {missing}.",
|
|
1023
|
+
"review_gate_budget_spent": "Review gate reached its {max}-review limit for this turn; continuing without another review.",
|
|
1016
1024
|
"mcp_not_connected": "Error: MCP server \"{server}\" not connected",
|
|
1017
1025
|
"mcp_tool_error": "MCP tool error: {error}",
|
|
1018
1026
|
"mcp_auth_required": "MCP server \"{server}\" needs authorization for this tool (the server asked for more OAuth scope). Re-authenticate with: /mcp connect {server}",
|
|
@@ -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": "命令",
|
|
@@ -1013,6 +1017,10 @@
|
|
|
1013
1017
|
"turn_refused": "模型拒绝了这次请求,没有作答。这不是故障:重发给同一个模型通常还是会被拒。",
|
|
1014
1018
|
"turn_refused_reason": "模型拒绝了这次请求:{reason}",
|
|
1015
1019
|
"stop_hook_budget_spent": "Stop 钩子要求继续({reason}),但本轮 {max} 轮工具调用已用尽 —— 就此停下。再发一条消息即可继续。",
|
|
1020
|
+
"review_gate_error": "评审闸门无法运行:{message}。本次未评审,继续。",
|
|
1021
|
+
"verification_missing": "本轮写入了源码,但以下基线检查没有在最后一次修改之后运行:{missing}。请先运行它们,或在最终答复中按「已验证 / 未验证」两栏说明。",
|
|
1022
|
+
"verification_budget_spent": "本轮工具调用轮次已用尽,以下验证基线未执行:{missing}。",
|
|
1023
|
+
"review_gate_budget_spent": "评审闸门本轮已达 {max} 次上限,不再评审,继续。",
|
|
1016
1024
|
"mcp_not_connected": "错误:MCP 服务器 \"{server}\" 未连接",
|
|
1017
1025
|
"mcp_tool_error": "MCP 工具错误:{error}",
|
|
1018
1026
|
"mcp_auth_required": "MCP 服务器 \"{server}\" 需要为该工具授权(服务器要求更多 OAuth 作用域)。请重新认证:/mcp connect {server}",
|
package/src/index.tsx
CHANGED
|
@@ -10,7 +10,10 @@ import {
|
|
|
10
10
|
loadCredentialMaskingConfig,
|
|
11
11
|
loadCrossSessionConfig,
|
|
12
12
|
loadSettingsJson,
|
|
13
|
+
loadReviewGateConfig,
|
|
14
|
+
loadVerificationConfig,
|
|
13
15
|
settingsPathFor,
|
|
16
|
+
loadDisabledMcpServers,
|
|
14
17
|
} from './config/loader'
|
|
15
18
|
import { getPreference } from './config/preferences'
|
|
16
19
|
import {
|
|
@@ -42,6 +45,7 @@ import { SkillsLoader } from './skills/loader'
|
|
|
42
45
|
import { PluginManager } from './plugin/plugin-manager'
|
|
43
46
|
import { loadPlugins } from './plugin/plugin-loader'
|
|
44
47
|
import { createToolRegistry } from './tools'
|
|
48
|
+
import { createReviewRunner } from './core/review-gate'
|
|
45
49
|
import { Context } from './vajra'
|
|
46
50
|
import { mountSkills, SKILLS_KEY } from './skills/seam'
|
|
47
51
|
import { mountLlm, LLM_KEY } from './providers/llm'
|
|
@@ -315,7 +319,13 @@ async function connectMcpServers(
|
|
|
315
319
|
mcpServers: McpServerConfig[],
|
|
316
320
|
tools: ReturnType<typeof createToolRegistry>,
|
|
317
321
|
): Promise<McpConnectFailure[]> {
|
|
318
|
-
|
|
322
|
+
// `/mcp disable` is a gate on *starting* a server, not just on its tools:
|
|
323
|
+
// disabled entries are filtered before any process is spawned. The filter
|
|
324
|
+
// lives here (the single startup path) so a future caller cannot connect a
|
|
325
|
+
// disabled server by forgetting a check of its own.
|
|
326
|
+
const disabled = loadDisabledMcpServers()
|
|
327
|
+
const activeServers = mcpServers.filter((s) => !disabled.has(s.name))
|
|
328
|
+
if (activeServers.length === 0) return []
|
|
319
329
|
const mcp = McpClient.getInstance()
|
|
320
330
|
// A server that dies mid-session should come back on its own; the retry is
|
|
321
331
|
// bounded and stops early on a definitive refusal. `MIPHAM_MCP_AUTO_RECONNECT=0`
|
|
@@ -324,7 +334,7 @@ async function connectMcpServers(
|
|
|
324
334
|
// Wire runtime tool-list changes before connect so mid-connect updates land.
|
|
325
335
|
syncMcpToolsOnChange(mcp, tools)
|
|
326
336
|
const results = await Promise.allSettled(
|
|
327
|
-
|
|
337
|
+
activeServers.map(async (server) => {
|
|
328
338
|
await mcp.connect(server)
|
|
329
339
|
registerMcpServerTools(server.name, tools)
|
|
330
340
|
}),
|
|
@@ -333,7 +343,7 @@ async function connectMcpServers(
|
|
|
333
343
|
for (let i = 0; i < results.length; i++) {
|
|
334
344
|
const result = results[i]!
|
|
335
345
|
if (result.status === 'rejected') {
|
|
336
|
-
const name =
|
|
346
|
+
const name = activeServers[i]!.name
|
|
337
347
|
const reason = String(result.reason)
|
|
338
348
|
failures.push({ name, reason })
|
|
339
349
|
// Say the retry out loud when there is one: the client is already trying
|
|
@@ -867,6 +877,28 @@ export async function runApp(options: RunOptions): Promise<void> {
|
|
|
867
877
|
const inferenceHookConfig = loadInferenceHookConfig()
|
|
868
878
|
engine.setInferenceHookConfig(inferenceHookConfig)
|
|
869
879
|
|
|
880
|
+
// Review gate: after a turn that wrote files, a fresh-context reviewer checks
|
|
881
|
+
// the artifact before the turn is allowed to end. The runner is the same
|
|
882
|
+
// factory the daemon uses, so both entry points carry the same capability.
|
|
883
|
+
// Must come **after** `setInferenceHookConfig`: `getSubAgentServices()` is a
|
|
884
|
+
// snapshot, and wiring earlier would give the reviewer a DLP-free services
|
|
885
|
+
// object — a second uninspected inference path.
|
|
886
|
+
engine.setReviewGate({
|
|
887
|
+
...loadReviewGateConfig(),
|
|
888
|
+
cwd: () => process.cwd(),
|
|
889
|
+
runner: createReviewRunner({
|
|
890
|
+
registry,
|
|
891
|
+
toolRegistry: tools,
|
|
892
|
+
permission,
|
|
893
|
+
services: engine.getSubAgentServices(),
|
|
894
|
+
}),
|
|
895
|
+
})
|
|
896
|
+
|
|
897
|
+
engine.setVerificationBaseline({
|
|
898
|
+
...loadVerificationConfig(),
|
|
899
|
+
cwd: () => process.cwd(),
|
|
900
|
+
})
|
|
901
|
+
|
|
870
902
|
// `config.permission` / `permissionRestrictions` are applied up top, on the instance
|
|
871
903
|
// handed to `new QueryEngine(...)` — the same one whose mode the system prompt reads.
|
|
872
904
|
|
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.55' 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 = 5607 as const
|
package/src/shared/types.ts
CHANGED
|
@@ -700,6 +700,17 @@ export interface ToolContext {
|
|
|
700
700
|
* than silently behaving like `general`.
|
|
701
701
|
*/
|
|
702
702
|
parentMessages?: Message[]
|
|
703
|
+
/**
|
|
704
|
+
* Called after a tool successfully wrote a file.
|
|
705
|
+
*
|
|
706
|
+
* The review gate has two write paths: `Engine.executeTool` (which tracks its
|
|
707
|
+
* own calls) and sub-agent loops (which call `tool.execute` directly and never
|
|
708
|
+
* pass through the engine). Without this callback a delegated implementation
|
|
709
|
+
* leaves the gate's counter at zero and the gate silently never fires.
|
|
710
|
+
*/
|
|
711
|
+
onFileWrite?: (path: string) => void
|
|
712
|
+
/** Report an executed Bash command (success or failure). The verification baseline observes these. */
|
|
713
|
+
onCommand?: (command: string, ok: boolean) => void
|
|
703
714
|
/**
|
|
704
715
|
* Cancellation for the turn this tool call belongs to.
|
|
705
716
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SubAgent } from '../agent/sub-agent'
|
|
2
2
|
import type { ProviderRegistry } from '../providers/registry'
|
|
3
3
|
import type { Llm } from '../providers/llm'
|
|
4
|
-
import type { ToolDefinition, SkillDefinition } from '../shared/index.ts'
|
|
4
|
+
import type { ToolDefinition, SkillDefinition, ToolContext } from '../shared/index.ts'
|
|
5
5
|
import type { AgentDefinition } from '../agent/types'
|
|
6
6
|
import type { PermissionSystem } from '../core/permission'
|
|
7
7
|
import type { SubAgentServices } from '../agent/services'
|
|
@@ -24,6 +24,7 @@ export async function executeForkedSkill(
|
|
|
24
24
|
permissionSystem?: PermissionSystem,
|
|
25
25
|
llm?: Llm,
|
|
26
26
|
services?: SubAgentServices,
|
|
27
|
+
toolContext?: Partial<ToolContext>,
|
|
27
28
|
): Promise<string> {
|
|
28
29
|
const agentDef: AgentDefinition = {
|
|
29
30
|
name: `skill:${skill.name}`,
|
|
@@ -49,7 +50,7 @@ export async function executeForkedSkill(
|
|
|
49
50
|
? `Execute the "${skill.name}" skill with arguments: ${args}`
|
|
50
51
|
: `Execute the "${skill.name}" skill.`
|
|
51
52
|
|
|
52
|
-
return sub.execute(prompt, `skill:${skill.name}`, { agentDef })
|
|
53
|
+
return sub.execute(prompt, `skill:${skill.name}`, { agentDef, toolContext })
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
function buildSkillSystemPrompt(skill: SkillDefinition): string {
|
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')
|
package/src/tools/agent/skill.ts
CHANGED
|
@@ -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. ' +
|
|
@@ -105,6 +107,7 @@ export const workflowTool: ToolDefinition = {
|
|
|
105
107
|
getPermission: () => ctx.permissionSystem,
|
|
106
108
|
getLlm: () => ctx.llm,
|
|
107
109
|
getSubAgentServices: () => ctx.subAgentServices,
|
|
110
|
+
getToolContext: () => ctx,
|
|
108
111
|
} as unknown as QueryEngine
|
|
109
112
|
|
|
110
113
|
try {
|
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
|