@miphamai/cli 0.85.25 → 0.85.27
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/bin/mipham.ts +34 -24
- package/package.json +1 -1
- package/src/agent/agent-context.ts +23 -3
- package/src/agent/sub-agent.ts +42 -15
- package/src/core/context.ts +32 -0
- package/src/core/engine.ts +182 -20
- package/src/core/instructions.ts +64 -17
- package/src/core/memory/memory-audit.ts +105 -0
- package/src/core/memory/memory-manager.ts +78 -53
- package/src/core/merge-gate.ts +158 -0
- package/src/core/number-provenance.ts +106 -0
- package/src/core/permission-rule-ack.ts +67 -0
- package/src/daemon/engine-capabilities.ts +2 -0
- package/src/daemon/remote-engine.ts +11 -5
- package/src/daemon/schedule-manager.ts +32 -3
- package/src/daemon/server.ts +6 -0
- package/src/i18n-core/locales/en-US.json +11 -3
- package/src/i18n-core/locales/zh-CN.json +11 -3
- package/src/index.tsx +36 -4
- package/src/mcp/client.ts +37 -2
- package/src/mcp/http-transport.ts +20 -1
- package/src/mcp/protocol.ts +13 -5
- package/src/mcp/registry.ts +8 -3
- package/src/mcp/transport.ts +40 -3
- package/src/providers/anthropic.ts +3 -1
- package/src/providers/fetch-utils.ts +40 -6
- package/src/providers/openai-compat.ts +2 -1
- package/src/shared/package-info.ts +2 -2
- package/src/shared/types.ts +9 -0
- package/src/tools/exec/bash.ts +1 -1
- package/src/tools/exec/task.ts +144 -21
- package/src/tools/network/web-fetch.ts +7 -7
- package/src/tools/network/web-search.ts +6 -5
- package/src/ui/commands.ts +43 -3
|
@@ -93,15 +93,42 @@ const NON_RETRYABLE_ERROR_TYPES = new Set([
|
|
|
93
93
|
'content_policy_violation',
|
|
94
94
|
])
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* The provider's own verdict on whether this response may be re-sent, if it gave one.
|
|
98
|
+
*
|
|
99
|
+
* Anthropic answers some 429/5xx responses with `x-should-retry: false` — it is
|
|
100
|
+
* saying the failure will repeat (an exhausted quota, not a burst). A status-only
|
|
101
|
+
* rule sends it again anyway, and a turn sitting on a retry ladder that cannot
|
|
102
|
+
* succeed looks exactly like a slow response. `true` is honoured the same way, in
|
|
103
|
+
* the opposite direction: the server knows things the status code does not.
|
|
104
|
+
*
|
|
105
|
+
* Absent or unrecognised ⇒ `undefined`, i.e. no opinion: status rules decide, so a
|
|
106
|
+
* provider (or a test double) that never sends the header behaves as before.
|
|
107
|
+
*/
|
|
108
|
+
export function parseShouldRetry(headers: Headers): boolean | undefined {
|
|
109
|
+
const raw = headers.get('x-should-retry')?.trim().toLowerCase()
|
|
110
|
+
if (raw === 'true') return true
|
|
111
|
+
if (raw === 'false') return false
|
|
112
|
+
return undefined
|
|
113
|
+
}
|
|
114
|
+
|
|
96
115
|
/**
|
|
97
116
|
* Should the engine re-send a turn the provider reported as failed?
|
|
98
117
|
*
|
|
99
|
-
*
|
|
118
|
+
* Three call shapes: an HTTP status (optionally with the response headers, so the
|
|
119
|
+
* server's `x-should-retry` verdict wins over the status rule), or a provider
|
|
120
|
+
* error object's `type`/`code`.
|
|
100
121
|
* Statuses follow the same rule as `fetchWithRetry` (429 and 5xx are transient).
|
|
101
122
|
* For an error type, only the *known* deterministic ones say no — an unrecognised
|
|
102
123
|
* type stays retryable, because guessing "final" would lose a recoverable turn.
|
|
103
124
|
*/
|
|
104
|
-
export function isRetryableFailure(
|
|
125
|
+
export function isRetryableFailure(
|
|
126
|
+
status: number | undefined,
|
|
127
|
+
errorType?: string,
|
|
128
|
+
headers?: Headers,
|
|
129
|
+
): boolean {
|
|
130
|
+
const verdict = headers ? parseShouldRetry(headers) : undefined
|
|
131
|
+
if (verdict !== undefined) return verdict
|
|
105
132
|
if (status !== undefined) return RETRYABLE_STATUSES.has(status) || status >= 500
|
|
106
133
|
if (errorType === undefined) return true
|
|
107
134
|
return !NON_RETRYABLE_ERROR_TYPES.has(errorType)
|
|
@@ -187,10 +214,17 @@ export async function fetchWithRetry(
|
|
|
187
214
|
try {
|
|
188
215
|
const response = await fetch(url, { ...init, signal })
|
|
189
216
|
|
|
190
|
-
// 429 / 5xx → retry
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
217
|
+
// 429 / 5xx → retry, unless the server itself said which way to go.
|
|
218
|
+
// `x-should-retry: false` on a 503 means "this will fail again"; re-sending
|
|
219
|
+
// it only holds the turn. Only error statuses are eligible either way — a
|
|
220
|
+
// 200 carrying `true` is not a failure to re-issue.
|
|
221
|
+
if (!response.ok) {
|
|
222
|
+
const verdict = parseShouldRetry(response.headers)
|
|
223
|
+
const retryable = verdict ?? RETRYABLE_STATUSES.has(response.status)
|
|
224
|
+
if (retryable && attempt < maxRetries) {
|
|
225
|
+
await sleep(retryDelayMs(response.headers.get('Retry-After'), attempt, baseDelay))
|
|
226
|
+
continue
|
|
227
|
+
}
|
|
194
228
|
}
|
|
195
229
|
|
|
196
230
|
return response
|
|
@@ -59,7 +59,8 @@ export class OpenAICompatProvider implements ProviderInstance {
|
|
|
59
59
|
yield {
|
|
60
60
|
type: 'error',
|
|
61
61
|
error: `OpenAI API error ${response.status}: ${errText}`,
|
|
62
|
-
|
|
62
|
+
// 网关可能替上游把 `x-should-retry` 带回来;给了就压过状态规则。
|
|
63
|
+
retryable: isRetryableFailure(response.status, undefined, response.headers),
|
|
63
64
|
}
|
|
64
65
|
return
|
|
65
66
|
}
|
|
@@ -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.27' 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 = 4585 as const
|
package/src/shared/types.ts
CHANGED
|
@@ -661,6 +661,15 @@ export interface ToolContext {
|
|
|
661
661
|
* consume a background handle, so its default flips to synchronous.
|
|
662
662
|
*/
|
|
663
663
|
isSubAgent?: boolean
|
|
664
|
+
/**
|
|
665
|
+
* The session a sub-agent is running on behalf of.
|
|
666
|
+
*
|
|
667
|
+
* `sessionId` is the literal `'sub-agent'` one level down, so anything keyed by
|
|
668
|
+
* it would put every nested call — from every session — into one bucket. Set by
|
|
669
|
+
* `SubAgent.runExecution` from the caller's context; absent for the main
|
|
670
|
+
* session, where `sessionId` is already the answer.
|
|
671
|
+
*/
|
|
672
|
+
parentSessionId?: string
|
|
664
673
|
/**
|
|
665
674
|
* The agent's own name, when this call is being executed by a sub-agent.
|
|
666
675
|
*
|
package/src/tools/exec/bash.ts
CHANGED
|
@@ -421,7 +421,7 @@ const CD_COMMANDS = new Set(['cd', 'pushd'])
|
|
|
421
421
|
* Over-splitting is the safe direction here: a word that is not really a
|
|
422
422
|
* command word simply fails to match `cd`.
|
|
423
423
|
*/
|
|
424
|
-
function shellWords(segment: string): string[] {
|
|
424
|
+
export function shellWords(segment: string): string[] {
|
|
425
425
|
const words: string[] = []
|
|
426
426
|
let cur = ''
|
|
427
427
|
let started = false
|
package/src/tools/exec/task.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, unlinkSync } from 'node:fs'
|
|
3
|
+
import { dirname } from 'node:path'
|
|
1
4
|
import type { ToolDefinition } from '../../shared/index.ts'
|
|
2
5
|
import type { BackgroundAgentRegistry, BackgroundTask } from '../../agent/background-registry'
|
|
3
6
|
import { hasSupportedEvidenceSince } from '../../core/working-memory'
|
|
7
|
+
import { atomicWriteFileSync } from '../../shared/atomic-write'
|
|
8
|
+
import { miphamHome } from '../../core/paths'
|
|
4
9
|
|
|
5
10
|
export interface Task {
|
|
6
11
|
id: string
|
|
@@ -19,12 +24,108 @@ export interface Task {
|
|
|
19
24
|
outputError?: string
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Task lists are **per session and on disk**.
|
|
29
|
+
*
|
|
30
|
+
* The list used to be one process-global Map with nothing behind it. That made a
|
|
31
|
+
* resumed conversation (`--resume` / `--continue` / `/resume`) start with no tasks
|
|
32
|
+
* at all — the work plan the user just watched being made simply vanished — while a
|
|
33
|
+
* `/clear` kept the *old* list alive in the same process. Both are the same defect
|
|
34
|
+
* seen from two sides: the store's lifetime was "this process", not "this session".
|
|
35
|
+
*
|
|
36
|
+
* Keyed by session id and cached per process (the daemon runs several sessions at
|
|
37
|
+
* once — a single global "current" map would leak one session's tasks into another).
|
|
38
|
+
* Readers without a session id (the TUI's goal panel, the memory tool) use the
|
|
39
|
+
* last session the tool touched, which **is** the session on screen.
|
|
40
|
+
*/
|
|
41
|
+
const stores = new Map<string, Map<string, Task>>()
|
|
42
|
+
let activeSessionId = ''
|
|
23
43
|
let taskCounter = 0
|
|
24
44
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
45
|
+
function storePath(sessionId: string): string {
|
|
46
|
+
// Hashed: the id is operator input (`--resume <id>`), and a `../` must not walk
|
|
47
|
+
// out of the tasks directory.
|
|
48
|
+
const name = createHash('sha256').update(sessionId).digest('hex').slice(0, 32)
|
|
49
|
+
return miphamHome('tasks', `${name}.json`)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The session's map, loading it from disk the first time it is asked for. */
|
|
53
|
+
function storeFor(sessionId: string): Map<string, Task> {
|
|
54
|
+
activeSessionId = sessionId
|
|
55
|
+
const cached = stores.get(sessionId)
|
|
56
|
+
if (cached) return cached
|
|
57
|
+
|
|
58
|
+
const map = new Map<string, Task>()
|
|
59
|
+
const path = storePath(sessionId)
|
|
60
|
+
if (existsSync(path)) {
|
|
61
|
+
try {
|
|
62
|
+
const parsed = JSON.parse(readFileSync(path, 'utf-8')) as { tasks?: Task[] }
|
|
63
|
+
for (const t of parsed.tasks ?? []) {
|
|
64
|
+
if (!t || typeof t.id !== 'string') continue
|
|
65
|
+
// Dependency walks index these fields unconditionally.
|
|
66
|
+
map.set(t.id, { ...t, blocks: t.blocks ?? [], blockedBy: t.blockedBy ?? [] })
|
|
67
|
+
const n = Number(t.id)
|
|
68
|
+
if (Number.isFinite(n)) taskCounter = Math.max(taskCounter, n)
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
// An unreadable store reads as empty — a corrupt file must not make the
|
|
72
|
+
// tool throw on a session that otherwise works.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
stores.set(sessionId, map)
|
|
76
|
+
return map
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Persist the session's map. A failed write must not fail the tool call. */
|
|
80
|
+
function saveStore(sessionId: string): void {
|
|
81
|
+
const map = stores.get(sessionId)
|
|
82
|
+
if (!map) return
|
|
83
|
+
try {
|
|
84
|
+
const path = storePath(sessionId)
|
|
85
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
86
|
+
atomicWriteFileSync(path, `${JSON.stringify({ tasks: [...map.values()] }, null, 2)}\n`, {
|
|
87
|
+
mode: 0o600,
|
|
88
|
+
})
|
|
89
|
+
} catch {
|
|
90
|
+
/* the in-memory list is still correct for this process */
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Make `sessionId` the one that session-less readers see, loading its tasks. */
|
|
95
|
+
export function setActiveTaskSession(sessionId: string): void {
|
|
96
|
+
if (!sessionId) return
|
|
97
|
+
storeFor(sessionId)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The map a reader means: the named session's, or the one on screen. */
|
|
101
|
+
function resolveStore(sessionId?: string): Map<string, Task> {
|
|
102
|
+
if (sessionId !== undefined) return storeFor(sessionId)
|
|
103
|
+
return stores.get(activeSessionId) ?? new Map()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Read accessor for a session's task store — returns all non-deleted tasks.
|
|
108
|
+
* Without an id: the session the Task tool last touched.
|
|
109
|
+
*/
|
|
110
|
+
export function getTasks(sessionId?: string): Task[] {
|
|
111
|
+
return Array.from(resolveStore(sessionId).values()).filter((t) => t.status !== 'deleted')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Drop a session's task list — the store and the file behind it.
|
|
116
|
+
*
|
|
117
|
+
* `/clear` means "start this conversation over"; leaving the old plan in place is
|
|
118
|
+
* how a fresh context came back showing tasks nobody had asked for in it.
|
|
119
|
+
*/
|
|
120
|
+
export function clearTasks(sessionId: string): void {
|
|
121
|
+
if (!sessionId) return
|
|
122
|
+
stores.delete(sessionId)
|
|
123
|
+
try {
|
|
124
|
+
const path = storePath(sessionId)
|
|
125
|
+
if (existsSync(path)) unlinkSync(path)
|
|
126
|
+
} catch {
|
|
127
|
+
/* a file we cannot remove is still not in this process's list */
|
|
128
|
+
}
|
|
28
129
|
}
|
|
29
130
|
|
|
30
131
|
function formatTask(t: Task): string {
|
|
@@ -95,8 +196,15 @@ function stopBackgroundTask(
|
|
|
95
196
|
}
|
|
96
197
|
}
|
|
97
198
|
|
|
98
|
-
/**
|
|
99
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Check if a task is blocked — has unresolved dependencies.
|
|
201
|
+
*
|
|
202
|
+
* The map is passed in rather than read from a module global: dependencies only
|
|
203
|
+
* mean anything **within one session's list**, and resolving them against
|
|
204
|
+
* whichever session happened to be active would let one session's ids answer
|
|
205
|
+
* for another's.
|
|
206
|
+
*/
|
|
207
|
+
function isBlocked(task: Task, tasks: Map<string, Task>): boolean {
|
|
100
208
|
if (task.blockedBy.length === 0) return false
|
|
101
209
|
return task.blockedBy.some((depId) => {
|
|
102
210
|
const dep = tasks.get(depId)
|
|
@@ -105,7 +213,7 @@ function isBlocked(task: Task): boolean {
|
|
|
105
213
|
}
|
|
106
214
|
|
|
107
215
|
/** Get the list of blocking task IDs (unresolved dependencies). */
|
|
108
|
-
function getBlockingIds(task: Task): string[] {
|
|
216
|
+
function getBlockingIds(task: Task, tasks: Map<string, Task>): string[] {
|
|
109
217
|
return task.blockedBy.filter((depId) => {
|
|
110
218
|
const dep = tasks.get(depId)
|
|
111
219
|
return dep && dep.status !== 'completed' && dep.status !== 'deleted'
|
|
@@ -120,8 +228,9 @@ function getBlockingIds(task: Task): string[] {
|
|
|
120
228
|
* both go through here. A second renderer for the panel would be the "two
|
|
121
229
|
* paths, one wired" mistake this repo has already paid for once.
|
|
122
230
|
*/
|
|
123
|
-
export function formatTaskList(): string {
|
|
124
|
-
const
|
|
231
|
+
export function formatTaskList(sessionId?: string): string {
|
|
232
|
+
const map = resolveStore(sessionId)
|
|
233
|
+
const all = Array.from(map.values()).filter((t) => t.status !== 'deleted')
|
|
125
234
|
if (all.length === 0) return '(no tasks)'
|
|
126
235
|
|
|
127
236
|
// Sort by availability: in_progress → pending(available) → pending(blocked) → completed
|
|
@@ -138,8 +247,8 @@ export function formatTaskList(): string {
|
|
|
138
247
|
if (orderA !== orderB) return orderA - orderB
|
|
139
248
|
// Within same status: available before blocked
|
|
140
249
|
if (a.status === 'pending' && b.status === 'pending') {
|
|
141
|
-
const aBlocked = isBlocked(a)
|
|
142
|
-
const bBlocked = isBlocked(b)
|
|
250
|
+
const aBlocked = isBlocked(a, map)
|
|
251
|
+
const bBlocked = isBlocked(b, map)
|
|
143
252
|
if (aBlocked !== bBlocked) return aBlocked ? 1 : -1
|
|
144
253
|
}
|
|
145
254
|
return 0
|
|
@@ -165,15 +274,15 @@ export function formatTaskList(): string {
|
|
|
165
274
|
lines.push(`${statusInfo.emoji} ${currentStatus} (${count}):`)
|
|
166
275
|
}
|
|
167
276
|
|
|
168
|
-
const blocked = isBlocked(t)
|
|
277
|
+
const blocked = isBlocked(t, map)
|
|
169
278
|
const prefix = blocked && t.status === 'pending' ? '🚫 ' : ' '
|
|
170
|
-
const blockingNote = blocked ? ` 🚫 阻塞中 (等待: ${getBlockingIds(t).join(', ')})` : ''
|
|
279
|
+
const blockingNote = blocked ? ` 🚫 阻塞中 (等待: ${getBlockingIds(t, map).join(', ')})` : ''
|
|
171
280
|
lines.push(`${prefix}${formatTask(t)}${blockingNote}`)
|
|
172
281
|
}
|
|
173
282
|
|
|
174
283
|
// Summary footer
|
|
175
|
-
const available = all.filter((t) => t.status === 'pending' && !isBlocked(t)).length
|
|
176
|
-
const blockedCount = all.filter((t) => t.status === 'pending' && isBlocked(t)).length
|
|
284
|
+
const available = all.filter((t) => t.status === 'pending' && !isBlocked(t, map)).length
|
|
285
|
+
const blockedCount = all.filter((t) => t.status === 'pending' && isBlocked(t, map)).length
|
|
177
286
|
if (blockedCount > 0) {
|
|
178
287
|
lines.push('')
|
|
179
288
|
lines.push(
|
|
@@ -238,6 +347,15 @@ export const taskTool: ToolDefinition = {
|
|
|
238
347
|
|
|
239
348
|
async execute(params, _ctx) {
|
|
240
349
|
const action = params.action as string
|
|
350
|
+
// The list this call works on. A sub-agent reports to its parent's list —
|
|
351
|
+
// `sessionId` is the literal 'sub-agent' one level down, so keying off it
|
|
352
|
+
// alone would put every nested task, from every session, in one bucket that
|
|
353
|
+
// no session panel reads.
|
|
354
|
+
// `|| … || 'default'` rather than `??`: a context assembled without a
|
|
355
|
+
// session id (tests, embedders) must still get a working list, and hashing
|
|
356
|
+
// `undefined` would throw instead.
|
|
357
|
+
const sid = _ctx.parentSessionId || _ctx.sessionId || 'default'
|
|
358
|
+
const tasks = storeFor(sid)
|
|
241
359
|
|
|
242
360
|
// ── CREATE ──
|
|
243
361
|
if (action === 'create') {
|
|
@@ -269,15 +387,16 @@ export const taskTool: ToolDefinition = {
|
|
|
269
387
|
}
|
|
270
388
|
|
|
271
389
|
tasks.set(id, task)
|
|
272
|
-
|
|
273
|
-
|
|
390
|
+
saveStore(sid)
|
|
391
|
+
const blockedNote = isBlocked(task, tasks)
|
|
392
|
+
? ` (blocked — waiting on: ${getBlockingIds(task, tasks).join(', ')})`
|
|
274
393
|
: ''
|
|
275
394
|
return { success: true, content: `Task #${id} created: ${subject}${blockedNote}` }
|
|
276
395
|
}
|
|
277
396
|
|
|
278
397
|
// ── LIST ──
|
|
279
398
|
if (action === 'list') {
|
|
280
|
-
return { success: true, content: formatTaskList() }
|
|
399
|
+
return { success: true, content: formatTaskList(sid) }
|
|
281
400
|
}
|
|
282
401
|
|
|
283
402
|
// ── GET ──
|
|
@@ -299,7 +418,7 @@ export const taskTool: ToolDefinition = {
|
|
|
299
418
|
if (task.owner) lines.push(`Owner: ${task.owner}`)
|
|
300
419
|
if (task.blocks.length) lines.push(`Blocks: ${task.blocks.join(', ')}`)
|
|
301
420
|
if (task.blockedBy.length) {
|
|
302
|
-
const blocking = getBlockingIds(task)
|
|
421
|
+
const blocking = getBlockingIds(task, tasks)
|
|
303
422
|
if (blocking.length > 0) {
|
|
304
423
|
lines.push(
|
|
305
424
|
`Blocked by: ${task.blockedBy.join(', ')} (active blockers: ${blocking.join(', ')})`,
|
|
@@ -359,8 +478,9 @@ export const taskTool: ToolDefinition = {
|
|
|
359
478
|
}
|
|
360
479
|
}
|
|
361
480
|
|
|
362
|
-
|
|
363
|
-
|
|
481
|
+
saveStore(sid)
|
|
482
|
+
const blockedNote = isBlocked(task, tasks)
|
|
483
|
+
? ` (blocked — waiting on: ${getBlockingIds(task, tasks).join(', ')})`
|
|
364
484
|
: ''
|
|
365
485
|
const unverifiedNote =
|
|
366
486
|
task.status === 'completed' && task.completionEvidence === 'unverified'
|
|
@@ -379,6 +499,7 @@ export const taskTool: ToolDefinition = {
|
|
|
379
499
|
const task = tasks.get(taskId)
|
|
380
500
|
if (!task) return { success: false, content: '', error: `Task #${taskId} not found` }
|
|
381
501
|
task.status = 'deleted'
|
|
502
|
+
saveStore(sid)
|
|
382
503
|
return { success: true, content: `Task #${taskId} deleted.` }
|
|
383
504
|
}
|
|
384
505
|
|
|
@@ -447,6 +568,7 @@ export const taskTool: ToolDefinition = {
|
|
|
447
568
|
if (task.status === 'pending') {
|
|
448
569
|
// Cancel a pending task
|
|
449
570
|
task.status = 'deleted'
|
|
571
|
+
saveStore(sid)
|
|
450
572
|
return { success: true, content: `Task #${taskId} cancelled (was pending).` }
|
|
451
573
|
}
|
|
452
574
|
|
|
@@ -455,6 +577,7 @@ export const taskTool: ToolDefinition = {
|
|
|
455
577
|
// the registry owns.
|
|
456
578
|
task.status = 'failed'
|
|
457
579
|
task.outputError = 'Task stopped by user.'
|
|
580
|
+
saveStore(sid)
|
|
458
581
|
|
|
459
582
|
return { success: true, content: `Task #${taskId} stopped.` }
|
|
460
583
|
}
|
|
@@ -250,10 +250,12 @@ export const webFetchTool: ToolDefinition = {
|
|
|
250
250
|
return { success: false, content: '', error: validationError }
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
+
// The timer spans the body read, not just the headers: a server that sends
|
|
254
|
+
// headers and then stalls mid-body would otherwise hang the tool forever —
|
|
255
|
+
// the abort signal is only consulted while `fetch` itself is running.
|
|
256
|
+
const controller = new AbortController()
|
|
257
|
+
const timer = setTimeout(() => controller.abort(), 30_000) // 30s timeout
|
|
253
258
|
try {
|
|
254
|
-
const controller = new AbortController()
|
|
255
|
-
const timer = setTimeout(() => controller.abort(), 30_000) // 30s timeout
|
|
256
|
-
|
|
257
259
|
// Manual redirect handling: follow same-host redirects one hop at a time,
|
|
258
260
|
// validating the target BEFORE each request (closes the SSRF-via-redirect gap).
|
|
259
261
|
let currentUrl = url
|
|
@@ -280,7 +282,6 @@ export const webFetchTool: ToolDefinition = {
|
|
|
280
282
|
// SSRF defense: validate the redirect target BEFORE following
|
|
281
283
|
const redirectError = await validateUrl(nextUrl)
|
|
282
284
|
if (redirectError) {
|
|
283
|
-
clearTimeout(timer)
|
|
284
285
|
return {
|
|
285
286
|
success: false,
|
|
286
287
|
content: '',
|
|
@@ -290,7 +291,6 @@ export const webFetchTool: ToolDefinition = {
|
|
|
290
291
|
|
|
291
292
|
// Cross-host redirects are returned to the caller (tool contract)
|
|
292
293
|
if (new URL(nextUrl).hostname !== originalHost) {
|
|
293
|
-
clearTimeout(timer)
|
|
294
294
|
return {
|
|
295
295
|
success: true,
|
|
296
296
|
content: `Redirected to: ${nextUrl}\n\nFetch from this URL directly to retrieve content.`,
|
|
@@ -301,8 +301,6 @@ export const webFetchTool: ToolDefinition = {
|
|
|
301
301
|
currentUrl = nextUrl
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
clearTimeout(timer)
|
|
305
|
-
|
|
306
304
|
// Determine content type; only convert HTML to markdown
|
|
307
305
|
const contentType = response.headers.get('content-type') || ''
|
|
308
306
|
const isHtml = contentType.includes('text/html') || contentType.includes('application/xhtml')
|
|
@@ -352,6 +350,8 @@ export const webFetchTool: ToolDefinition = {
|
|
|
352
350
|
? 'Request timed out (30s)'
|
|
353
351
|
: `Fetch failed: ${String(err)}. If direct network is blocked, retry via the web-access skill (CDP through the user's logged-in Chrome).`
|
|
354
352
|
return { success: false, content: '', error: message }
|
|
353
|
+
} finally {
|
|
354
|
+
clearTimeout(timer)
|
|
355
355
|
}
|
|
356
356
|
},
|
|
357
357
|
}
|
|
@@ -132,14 +132,15 @@ export const webSearchTool: ToolDefinition = {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
// The timer spans the body read too: headers followed by a stalled body is
|
|
136
|
+
// the same hang as a request that never answers.
|
|
137
|
+
const controller = new AbortController()
|
|
138
|
+
const timer = setTimeout(() => controller.abort(), 15_000) // 15s timeout
|
|
135
139
|
try {
|
|
136
140
|
const url = new URL(BRAVE_API)
|
|
137
141
|
url.searchParams.set('q', query)
|
|
138
142
|
url.searchParams.set('count', String(MAX_RESULTS))
|
|
139
143
|
|
|
140
|
-
const controller = new AbortController()
|
|
141
|
-
const timer = setTimeout(() => controller.abort(), 15_000) // 15s timeout
|
|
142
|
-
|
|
143
144
|
const response = await fetch(url.toString(), {
|
|
144
145
|
headers: {
|
|
145
146
|
Accept: 'application/json',
|
|
@@ -149,8 +150,6 @@ export const webSearchTool: ToolDefinition = {
|
|
|
149
150
|
signal: controller.signal,
|
|
150
151
|
})
|
|
151
152
|
|
|
152
|
-
clearTimeout(timer)
|
|
153
|
-
|
|
154
153
|
if (!response.ok) {
|
|
155
154
|
const body = await response.text().catch(() => '')
|
|
156
155
|
// 429 = rate limit, 401 = bad key
|
|
@@ -207,6 +206,8 @@ export const webSearchTool: ToolDefinition = {
|
|
|
207
206
|
? 'Search timed out (15s). Try a more specific query.'
|
|
208
207
|
: `Search failed: ${String(err)}. If direct network is blocked, retry via the web-access skill (CDP through the user's logged-in Chrome).`
|
|
209
208
|
return { success: false, content: '', error: message }
|
|
209
|
+
} finally {
|
|
210
|
+
clearTimeout(timer)
|
|
210
211
|
}
|
|
211
212
|
},
|
|
212
213
|
}
|
package/src/ui/commands.ts
CHANGED
|
@@ -76,6 +76,7 @@ import { getPreference, setPreference } from '../config/preferences'
|
|
|
76
76
|
import { loadCrossSessionConfig, tryRestoreFromBackup } from '../config/loader'
|
|
77
77
|
import { getWorkspaceTrust } from '../core/workspace-trust'
|
|
78
78
|
import { getMemoryManager } from '../core/memory/memory-loader'
|
|
79
|
+
import { auditMemoryDir } from '../core/memory/memory-audit'
|
|
79
80
|
import {
|
|
80
81
|
resolveTelemetry,
|
|
81
82
|
readTelemetrySettings,
|
|
@@ -119,7 +120,7 @@ import { listActiveAutoloops, formatLoopRows } from '../commands/autoloop-journa
|
|
|
119
120
|
import { execSync } from 'node:child_process'
|
|
120
121
|
import { MIPHAM_DIR, OLLAMA_PRESET_MODELS } from '../shared/constants'
|
|
121
122
|
import { renameActiveSession } from '../agent/cross-session/discovery'
|
|
122
|
-
import { formatTaskList } from '../tools/exec/task'
|
|
123
|
+
import { clearTasks, formatTaskList } from '../tools/exec/task'
|
|
123
124
|
|
|
124
125
|
export interface CommandContext {
|
|
125
126
|
engine: QueryEngine
|
|
@@ -340,6 +341,10 @@ const versionCmd: CommandHandler = (ctx) => {
|
|
|
340
341
|
|
|
341
342
|
const clearCmd: CommandHandler = (ctx) => {
|
|
342
343
|
ctx.engine.getContext().clear()
|
|
344
|
+
// The task list outlives the process now, so "start over" has to say so
|
|
345
|
+
// explicitly — otherwise the old plan comes back on resume and the panel keeps
|
|
346
|
+
// showing tasks from a conversation the user just discarded.
|
|
347
|
+
clearTasks(ctx.sessionId)
|
|
343
348
|
const t = resolveT(ctx)
|
|
344
349
|
return { content: t('commands.clear.confirmed'), clearMessages: true }
|
|
345
350
|
}
|
|
@@ -3096,7 +3101,7 @@ const tasksCmd: CommandHandler = (ctx) => {
|
|
|
3096
3101
|
// 却有历史时又会说「检测到 N 次任务操作」。面板自称 "Background tasks"、标题写
|
|
3097
3102
|
// 「后台任务」、空态写「尚未跟踪任何任务」—— 全是登记表词汇,而登记表就在
|
|
3098
3103
|
// 一步之外(`getTasks()`,`GoalProgress` 早就接了)。
|
|
3099
|
-
const taskList = formatTaskList()
|
|
3104
|
+
const taskList = formatTaskList(ctx.sessionId)
|
|
3100
3105
|
const hasTasks = taskList !== '(no tasks)'
|
|
3101
3106
|
|
|
3102
3107
|
return {
|
|
@@ -3830,7 +3835,11 @@ const codeReviewCmd = gitDiffBridgeCmd({
|
|
|
3830
3835
|
: maxFindings.value === 'default'
|
|
3831
3836
|
? ''
|
|
3832
3837
|
: ` Report at most ${maxFindings.value} findings, most severe first.`
|
|
3833
|
-
|
|
3838
|
+
// 档位放在**最前**:它是这一轮的工作量,后面那句「查哪七个维度」是它的宾语。
|
|
3839
|
+
// 写成句末时模型容易先按默认深度铺开、再拿档位去追认。`max` 另有一句上限:
|
|
3840
|
+
// 仓里存的可能是上一轮自己挑的,而不是用户这一轮要的 —— 只有**用户点名**才用。
|
|
3841
|
+
const effort = getPreference('lastCodeReviewEffort', 'high')
|
|
3842
|
+
return `Use effort level: ${effort} — settle this before you start; never pick max on your own, only when the user asked for it. Then use the code-review skill to review all uncommitted changes. Check all 7 dimensions: correctness, security, performance, code quality, architecture & design, testing, and language-specific issues.${cap}`
|
|
3834
3843
|
},
|
|
3835
3844
|
})
|
|
3836
3845
|
|
|
@@ -4636,6 +4645,37 @@ const memoryCmd: CommandHandler = async (ctx, args) => {
|
|
|
4636
4645
|
return { content: lines.join('\n') }
|
|
4637
4646
|
}
|
|
4638
4647
|
|
|
4648
|
+
// /memory doctor — 只读体检:找出「盘上有、系统看不见」的分歧,不动任何文件
|
|
4649
|
+
if (args[0]?.toLowerCase() === 'doctor') {
|
|
4650
|
+
const issues = auditMemoryDir(memoryDir)
|
|
4651
|
+
const lines: string[] = [t('commands.memories.doctor_title'), '']
|
|
4652
|
+
|
|
4653
|
+
if (issues.length === 0) {
|
|
4654
|
+
const count = existsSync(memoryDir)
|
|
4655
|
+
? readdirSync(memoryDir).filter((f) => f.endsWith('.md') && f !== 'MEMORY.md').length
|
|
4656
|
+
: 0
|
|
4657
|
+
lines.push(t('commands.memories.doctor_clean', { count: String(count) }))
|
|
4658
|
+
return { content: lines.join('\n') }
|
|
4659
|
+
}
|
|
4660
|
+
|
|
4661
|
+
const order = ['invisible', 'duplicate-name', 'broken-link', 'index-drift'] as const
|
|
4662
|
+
const headers: Record<(typeof order)[number], string> = {
|
|
4663
|
+
invisible: 'commands.memories.doctor_invisible',
|
|
4664
|
+
'duplicate-name': 'commands.memories.doctor_duplicate',
|
|
4665
|
+
'broken-link': 'commands.memories.doctor_broken_link',
|
|
4666
|
+
'index-drift': 'commands.memories.doctor_index',
|
|
4667
|
+
}
|
|
4668
|
+
for (const kind of order) {
|
|
4669
|
+
const group = issues.filter((i) => i.kind === kind)
|
|
4670
|
+
if (group.length === 0) continue
|
|
4671
|
+
lines.push(t(headers[kind], { count: String(group.length) }))
|
|
4672
|
+
lines.push(...group.map((i) => ` • ${i.subject} — ${i.detail}`))
|
|
4673
|
+
lines.push('')
|
|
4674
|
+
}
|
|
4675
|
+
lines.push(t('commands.memories.doctor_footer'))
|
|
4676
|
+
return { content: lines.join('\n') }
|
|
4677
|
+
}
|
|
4678
|
+
|
|
4639
4679
|
if (!existsSync(memoryDir)) {
|
|
4640
4680
|
return { content: t('commands.memories.no_memories') }
|
|
4641
4681
|
}
|