dsh-any-agent 0.5.0 → 0.5.1
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/CHANGELOG.md +41 -0
- package/DESIGN.md +9 -0
- package/README.md +5 -3
- package/README.zh.md +5 -3
- package/USAGE-NOTES.en.md +4 -3
- package/USAGE-NOTES.md +4 -3
- package/bin/dsh-any-agent.mjs +7 -2
- package/docs/en/reference.md +3 -1
- package/docs/en/security.md +9 -2
- package/docs/en/tests.md +7 -6
- package/docs/en/usage.md +11 -4
- package/docs/zh/reference.md +3 -1
- package/docs/zh/security.md +9 -2
- package/docs/zh/tests.md +7 -6
- package/docs/zh/usage.md +11 -4
- package/package.json +1 -1
- package/src/config.mjs +29 -0
- package/src/hub.mjs +347 -64
- package/src/ids.mjs +21 -0
- package/src/mcp.mjs +15 -7
- package/src/redact.mjs +34 -0
- package/src/review.mjs +199 -0
- package/src/tools.mjs +161 -9
package/src/tools.mjs
CHANGED
|
@@ -12,12 +12,15 @@ import {
|
|
|
12
12
|
DEFAULT_PERMISSION,
|
|
13
13
|
DEFAULT_REASONING,
|
|
14
14
|
DEFAULT_REASONING_EFFORT,
|
|
15
|
+
DEFAULT_REVIEW,
|
|
15
16
|
IDLE_TTL_MS,
|
|
16
17
|
MAX_LIVE,
|
|
17
18
|
MAX_RSS_MB,
|
|
18
19
|
PERMISSION_TIERS,
|
|
19
20
|
REASONING_EFFORTS,
|
|
20
21
|
REASONING_MODES,
|
|
22
|
+
REVIEW_MODES,
|
|
23
|
+
REVIEWS_DIR,
|
|
21
24
|
RUNS_DIR,
|
|
22
25
|
SHARED_PROCESS,
|
|
23
26
|
STATE_FILE,
|
|
@@ -31,6 +34,7 @@ import { inspectProfile } from './bootstrap.mjs';
|
|
|
31
34
|
import { audit } from './audit.mjs';
|
|
32
35
|
import { listOrphans, LOCKS_DIR } from './locks.mjs';
|
|
33
36
|
import { rssMb } from './procstat.mjs';
|
|
37
|
+
import { REVIEW_VERDICTS, normalizeReviewMode } from './review.mjs';
|
|
34
38
|
|
|
35
39
|
const S = (props, required = []) => ({ type: 'object', properties: props, required, additionalProperties: false });
|
|
36
40
|
|
|
@@ -93,8 +97,9 @@ export const TOOL_DEFS = [
|
|
|
93
97
|
},
|
|
94
98
|
title_hint: {
|
|
95
99
|
type: 'string',
|
|
100
|
+
maxLength: 200,
|
|
96
101
|
description:
|
|
97
|
-
'
|
|
102
|
+
'可读的会话标签(最长 200 字)。注意 DSH 自己的标题是首条消息的截断前缀(约 13–15 字),会优先显示;' +
|
|
98
103
|
'这里给的值不会被覆盖,而是在 dsh_get / dsh_start 里作为「标题提示」一并返回。',
|
|
99
104
|
},
|
|
100
105
|
reasoning_effort: {
|
|
@@ -102,6 +107,13 @@ export const TOOL_DEFS = [
|
|
|
102
107
|
enum: REASONING_EFFORTS,
|
|
103
108
|
description: `思考深度,默认 ${DEFAULT_REASONING_EFFORT}。注意 ACP 自身的默认是"Provider default"(不设),本服务会显式设成 max。想省钱可调低。`,
|
|
104
109
|
},
|
|
110
|
+
review: {
|
|
111
|
+
type: 'string',
|
|
112
|
+
enum: REVIEW_MODES,
|
|
113
|
+
description:
|
|
114
|
+
`调用方审核策略,默认 ${DEFAULT_REVIEW}。advisory:每次派活的结果/哨兵都会附审核单(核验清单 + 证据 + dsh_review 入口),` +
|
|
115
|
+
'但**不阻塞**后续派活;off:不生成审核单。可被单次 dsh_send 覆盖。',
|
|
116
|
+
},
|
|
105
117
|
provider: { type: 'string', description: '模型提供方名(如 deepseek-official)。留空用 profile 默认。' },
|
|
106
118
|
model: { type: 'string', description: '模型名(如 deepseek-flash)。指定时必须同时给 provider。' },
|
|
107
119
|
keep_alive: {
|
|
@@ -131,7 +143,8 @@ export const TOOL_DEFS = [
|
|
|
131
143
|
'**推荐用后台任务(Bash run_in_background + `until [ -f sentinel_file ]`)等它,跑完自动通知你,无需轮询**;' +
|
|
132
144
|
'文件出现后读它即得结果,或用 dsh_get(conversation_id, run_id) 验收,dsh_read 可中途看输出。' +
|
|
133
145
|
'默认隐藏思考内容(只返回正文 + 思考统计)。' +
|
|
134
|
-
'
|
|
146
|
+
'结果与后台收据都会带 `review` 审核单(默认 advisory):调用方核验后用 dsh_review 提交裁决。' +
|
|
147
|
+
'若会话正在忙,本工具会报错——改用 dsh_interject 插话、dsh_send(queue=true) 入队,或用 dsh_interrupt 先打断。',
|
|
135
148
|
inputSchema: S(
|
|
136
149
|
{
|
|
137
150
|
conversation_id: CONV_ID,
|
|
@@ -151,6 +164,12 @@ export const TOOL_DEFS = [
|
|
|
151
164
|
description:
|
|
152
165
|
'仅 wait=true 时的**等待**上限(毫秒),**默认 0 = 一直等**(不会凭空发明 30 分钟)。到期不会取消回合,只会转成后台并给你 run_id。',
|
|
153
166
|
},
|
|
167
|
+
review: {
|
|
168
|
+
type: 'string',
|
|
169
|
+
enum: REVIEW_MODES,
|
|
170
|
+
description:
|
|
171
|
+
'本次派活的审核策略,覆盖会话默认(默认 advisory)。advisory:结果/哨兵附审核单,提示调用方独立核验后用 dsh_review 提交裁决;off:本次不附。',
|
|
172
|
+
},
|
|
154
173
|
queue: {
|
|
155
174
|
type: 'boolean',
|
|
156
175
|
description:
|
|
@@ -159,6 +178,7 @@ export const TOOL_DEFS = [
|
|
|
159
178
|
},
|
|
160
179
|
client_run_id: {
|
|
161
180
|
type: 'string',
|
|
181
|
+
maxLength: 128,
|
|
162
182
|
description:
|
|
163
183
|
'调用方生成的幂等键(≤128 字符,作用域=本会话)。重复提交同一个键不会创建第二个 run,' +
|
|
164
184
|
'而是返回首次 run 的结果或收据(replayed=true)。用于"响应在传输层丢了、想安全重发"的场景。',
|
|
@@ -218,14 +238,15 @@ export const TOOL_DEFS = [
|
|
|
218
238
|
description:
|
|
219
239
|
'查看单个会话的详情;带 run_id 时**取那一次派活的最终结果**(异步模式的验收入口)。' +
|
|
220
240
|
'不传 run_id 则取最近一次回合。返回:标题、工作区、权限档、状态、轮数、token 用量、' +
|
|
221
|
-
'
|
|
222
|
-
'**run 记录只在内存、最多保留最近 20
|
|
241
|
+
'上下文压力、待决审批,以及该回合的完整结果(正文/工具/用量/错误)和 **review 审核单**。' +
|
|
242
|
+
'**run 记录只在内存、最多保留最近 20 条**;服务重启或记录被挤掉后会从哨兵文件回读(它落盘且扛重启)。',
|
|
223
243
|
inputSchema: S(
|
|
224
244
|
{
|
|
225
245
|
conversation_id: CONV_ID,
|
|
226
|
-
run_id: { type: 'string', description: 'dsh_send 返回的 run_id;不传则取最近一次回合。' },
|
|
246
|
+
run_id: { type: 'string', maxLength: 200, description: 'dsh_send 返回的 run_id;不传则取最近一次回合。' },
|
|
227
247
|
client_run_id: {
|
|
228
248
|
type: 'string',
|
|
249
|
+
maxLength: 128,
|
|
229
250
|
description: '按调用方幂等键取 run(与 run_id 二选一;只对仍在内存里的 run 有效,最多最近 20 条)。',
|
|
230
251
|
},
|
|
231
252
|
max_chars: {
|
|
@@ -238,6 +259,33 @@ export const TOOL_DEFS = [
|
|
|
238
259
|
['conversation_id'],
|
|
239
260
|
),
|
|
240
261
|
},
|
|
262
|
+
{
|
|
263
|
+
name: 'dsh_review',
|
|
264
|
+
description:
|
|
265
|
+
'提交对一次回合结果的**调用方审核裁决**。dsh_send / dsh_interject / 哨兵里的 result 会带 `review` 审核单' +
|
|
266
|
+
'(核验清单 + 证据摘要 + review_id)。在把结果当作完成之前,调用方应自己核验(读改动的文件、看 git diff、跑测试等),' +
|
|
267
|
+
'再调用本工具记录 pass / partial / fail。' +
|
|
268
|
+
'**默认是建议式审核**:不阻塞后续 dsh_send,也不会自动把审核意见回灌给 DSH;需要修就再 dsh_send。' +
|
|
269
|
+
'run 记录被内存挤出或服务重启后仍可提交(以哨兵文件为准)。',
|
|
270
|
+
inputSchema: S(
|
|
271
|
+
{
|
|
272
|
+
conversation_id: CONV_ID,
|
|
273
|
+
run_id: { type: 'string', maxLength: 200, description: '要审核的那次派活(审核单里的 run_id)。' },
|
|
274
|
+
verdict: {
|
|
275
|
+
type: 'string',
|
|
276
|
+
enum: REVIEW_VERDICTS,
|
|
277
|
+
description: 'pass=可直接采用;partial=部分可用、需补充;fail=不可用、需重做。fail/partial 必须说明理由。',
|
|
278
|
+
},
|
|
279
|
+
notes: { type: 'string', description: '审核理由。fail/partial 必填(或改用 findings),最多 8000 字。' },
|
|
280
|
+
findings: {
|
|
281
|
+
type: 'array',
|
|
282
|
+
items: { type: 'string' },
|
|
283
|
+
description: '逐条问题清单,可选;最多 50 条、每条 2000 字。',
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
['conversation_id', 'run_id', 'verdict'],
|
|
287
|
+
),
|
|
288
|
+
},
|
|
241
289
|
{
|
|
242
290
|
name: 'dsh_interject',
|
|
243
291
|
description:
|
|
@@ -261,8 +309,14 @@ export const TOOL_DEFS = [
|
|
|
261
309
|
description: `思考内容展示档位,默认 ${DEFAULT_REASONING}。`,
|
|
262
310
|
},
|
|
263
311
|
timeout_ms: { type: 'number', description: '新回合的**等待**上限(毫秒),**默认 0 = 一直等**;queue 模式也用它限制等待上一轮结束。忙时等待超时会报错(本次插话未发送,会话不受损);空闲时到期只转后台,不取消回合。' },
|
|
312
|
+
review: {
|
|
313
|
+
type: 'string',
|
|
314
|
+
enum: REVIEW_MODES,
|
|
315
|
+
description: '本次插话回合的审核策略,覆盖会话默认(默认 advisory);off 可关闭本次审核单。',
|
|
316
|
+
},
|
|
264
317
|
client_run_id: {
|
|
265
318
|
type: 'string',
|
|
319
|
+
maxLength: 128,
|
|
266
320
|
description: '调用方生成的幂等键(≤128 字符,作用域=本会话)。重复提交返回首次的 run,不会重复插话。',
|
|
267
321
|
},
|
|
268
322
|
},
|
|
@@ -365,7 +419,7 @@ export const TOOL_DEFS = [
|
|
|
365
419
|
{
|
|
366
420
|
conversation_id: CONV_ID,
|
|
367
421
|
action: { type: 'string', enum: ['list', 'remove', 'update', 'promote'] },
|
|
368
|
-
run_id: { type: 'string', description: 'remove / update / promote 必填' },
|
|
422
|
+
run_id: { type: 'string', maxLength: 200, description: 'remove / update / promote 必填' },
|
|
369
423
|
text: { type: 'string', description: 'update 时的新文本' },
|
|
370
424
|
},
|
|
371
425
|
['conversation_id', 'action'],
|
|
@@ -380,6 +434,43 @@ export const TOOL_DEFS = [
|
|
|
380
434
|
},
|
|
381
435
|
];
|
|
382
436
|
|
|
437
|
+
/**
|
|
438
|
+
* 把审核单渲染成调用方一眼能看到的文本块。
|
|
439
|
+
*
|
|
440
|
+
* 为什么放在正文后面而不是单独一次工具调用:MCP 调用方拿到结果后往往直接转述,
|
|
441
|
+
* 审核要求必须和结果出现在同一条消息里,才有机会改变它的下一步动作。
|
|
442
|
+
*/
|
|
443
|
+
function renderReviewSection(review) {
|
|
444
|
+
if (!review || typeof review !== 'object') return '';
|
|
445
|
+
const lines = [];
|
|
446
|
+
const pending = review.status === 'pending';
|
|
447
|
+
lines.push(`【调用方审核${pending ? ' · 待提交' : ` · ${review.status}`}】`);
|
|
448
|
+
if (review.prompt_preview) lines.push(`原任务: ${review.prompt_preview}`);
|
|
449
|
+
const ev = review.evidence ?? {};
|
|
450
|
+
const bits = [];
|
|
451
|
+
if (ev.stop_reason) bits.push(`stop=${ev.stop_reason}`);
|
|
452
|
+
if (ev.workspace_changed != null) bits.push(`工作区变化=${ev.workspace_changed ? '是' : '否'}`);
|
|
453
|
+
if (ev.changed_files != null) bits.push(`改动文件=${ev.changed_files}`);
|
|
454
|
+
if (Array.isArray(ev.tools) && ev.tools.length) bits.push(`工具=[${ev.tools.join(', ')}]`);
|
|
455
|
+
if (bits.length) lines.push(`证据: ${bits.join(' · ')}`);
|
|
456
|
+
if (pending) {
|
|
457
|
+
lines.push('在把这次结果当作完成之前,请独立核验:');
|
|
458
|
+
(review.checklist ?? []).forEach((item, i) => lines.push(`${i + 1}. ${item}`));
|
|
459
|
+
if (review.instructions) lines.push(review.instructions);
|
|
460
|
+
lines.push(
|
|
461
|
+
`提交裁决: dsh_review(conversation_id="${review.conversation_id}", run_id="${review.run_id}", ` +
|
|
462
|
+
'verdict="pass|partial|fail", notes="审核理由")',
|
|
463
|
+
);
|
|
464
|
+
} else {
|
|
465
|
+
if (review.notes) lines.push(`审核理由: ${review.notes}`);
|
|
466
|
+
if (Array.isArray(review.findings) && review.findings.length) {
|
|
467
|
+
lines.push(`审核问题: ${review.findings.join(';')}`);
|
|
468
|
+
}
|
|
469
|
+
if (review.review_file) lines.push(`审核记录: ${review.review_file}`);
|
|
470
|
+
}
|
|
471
|
+
return lines.join('\n');
|
|
472
|
+
}
|
|
473
|
+
|
|
383
474
|
/** 把结构化结果渲染成给模型看的文本。 */
|
|
384
475
|
function renderSendResult(r) {
|
|
385
476
|
const lines = [];
|
|
@@ -408,6 +499,11 @@ function renderSendResult(r) {
|
|
|
408
499
|
lines.push('');
|
|
409
500
|
lines.push(`[${meta.join(' · ')}]`);
|
|
410
501
|
|
|
502
|
+
if (r.review) {
|
|
503
|
+
lines.push('');
|
|
504
|
+
lines.push(renderReviewSection(r.review));
|
|
505
|
+
}
|
|
506
|
+
|
|
411
507
|
if (r.error) {
|
|
412
508
|
lines.push('');
|
|
413
509
|
lines.push(`⚠️ 回合失败: ${r.error}`);
|
|
@@ -423,6 +519,7 @@ function renderSendResult(r) {
|
|
|
423
519
|
function backgroundReceipt(hub, conv, res) {
|
|
424
520
|
const sentinel = res.sentinel_file ?? hub.runSentinelPath(conv.id, res.run_id);
|
|
425
521
|
const sentinelPosix = toPosixPath(sentinel);
|
|
522
|
+
const review = conv.pendingReviewTicket?.(res.run_id) ?? null;
|
|
426
523
|
const waited = res.waited_ms
|
|
427
524
|
? `已等待 ${(res.waited_ms / 1000).toFixed(0)}s 仍未结束,改为后台继续(**回合没有被取消**)。`
|
|
428
525
|
: '已在后台执行(**回合没有被取消**)。';
|
|
@@ -436,6 +533,7 @@ function backgroundReceipt(hub, conv, res) {
|
|
|
436
533
|
sentinel_file: sentinel,
|
|
437
534
|
/** Bash/MSYS 形式(D:\a\b → /d/a/b);非 Windows 等于 sentinel_file。 */
|
|
438
535
|
sentinel_file_posix: sentinelPosix,
|
|
536
|
+
...(review ? { review } : {}),
|
|
439
537
|
},
|
|
440
538
|
text:
|
|
441
539
|
`${waited}(run_id=${res.run_id})\n\n` +
|
|
@@ -448,6 +546,7 @@ function backgroundReceipt(hub, conv, res) {
|
|
|
448
546
|
` dl=$(( $(date +%s)+2100 )); until [ -f "$sent" ]; do [ $(date +%s) -ge $dl ] && { echo TIMEOUT; exit 1; }; sleep 2; done; echo DONE\n` +
|
|
449
547
|
`文件出现后:直接读它拿结果(推荐——不受内存窗口限制、还扛服务重启),或 dsh_get(conversation_id, run_id) 验收。\n` +
|
|
450
548
|
`消费完可以 rm 掉它。其它随时可用:dsh_status(是否在跑)、dsh_read(增量看输出)。` +
|
|
549
|
+
(review ? `\n\n${renderReviewSection(review)}` : '') +
|
|
451
550
|
(res.waited_ms
|
|
452
551
|
? `\n\n下次想立刻返回就传 wait=false;想等更久就调大 timeout_ms(**0 = 一直等**)。`
|
|
453
552
|
: ''),
|
|
@@ -471,6 +570,7 @@ function replayRun(hub, conv, run, wantResult) {
|
|
|
471
570
|
`\n哨兵文件: ${sentinel}`,
|
|
472
571
|
};
|
|
473
572
|
}
|
|
573
|
+
const review = conv.pendingReviewTicket?.(run.run_id) ?? null;
|
|
474
574
|
return {
|
|
475
575
|
structured: {
|
|
476
576
|
conversation_id: conv.id,
|
|
@@ -482,10 +582,12 @@ function replayRun(hub, conv, run, wantResult) {
|
|
|
482
582
|
replayed: true,
|
|
483
583
|
sentinel_file: sentinel,
|
|
484
584
|
sentinel_file_posix: sentinelPosix,
|
|
585
|
+
...(review ? { review } : {}),
|
|
485
586
|
},
|
|
486
587
|
text:
|
|
487
588
|
`(幂等命中:同一个 client_run_id 已在跑或排队,未重复派活)run_id=${run.run_id} status=${run.status}\n` +
|
|
488
|
-
`哨兵文件: ${sentinel}
|
|
589
|
+
`哨兵文件: ${sentinel}` +
|
|
590
|
+
(review ? `\n\n${renderReviewSection(review)}` : ''),
|
|
489
591
|
};
|
|
490
592
|
}
|
|
491
593
|
|
|
@@ -493,6 +595,7 @@ function replayRun(hub, conv, run, wantResult) {
|
|
|
493
595
|
function queuedReceipt(hub, conv, run, position) {
|
|
494
596
|
const sentinel = hub.runSentinelPath(conv.id, run.run_id);
|
|
495
597
|
const sentinelPosix = toPosixPath(sentinel);
|
|
598
|
+
const review = conv.pendingReviewTicket?.(run.run_id) ?? null;
|
|
496
599
|
return {
|
|
497
600
|
structured: {
|
|
498
601
|
conversation_id: conv.id,
|
|
@@ -503,11 +606,13 @@ function queuedReceipt(hub, conv, run, position) {
|
|
|
503
606
|
status: 'queued',
|
|
504
607
|
sentinel_file: sentinel,
|
|
505
608
|
sentinel_file_posix: sentinelPosix,
|
|
609
|
+
...(review ? { review } : {}),
|
|
506
610
|
},
|
|
507
611
|
text:
|
|
508
612
|
`已入队(第 ${position} 位)。当前回合结束后自动执行;**入队时不会写哨兵**,真正结束时才写:\n` +
|
|
509
613
|
` ${sentinel}\n` +
|
|
510
|
-
`用 dsh_queue list 查看/修改/删除;取消:dsh_queue(conversation_id, action="remove", run_id="${run.run_id}")
|
|
614
|
+
`用 dsh_queue list 查看/修改/删除;取消:dsh_queue(conversation_id, action="remove", run_id="${run.run_id}")。` +
|
|
615
|
+
(review ? `\n\n${renderReviewSection(review)}` : ''),
|
|
511
616
|
};
|
|
512
617
|
}
|
|
513
618
|
|
|
@@ -539,6 +644,7 @@ export function createHandlers(hub, opts = {}) {
|
|
|
539
644
|
onApproval: args.on_approval,
|
|
540
645
|
titleHint: args.title_hint,
|
|
541
646
|
reasoningEffort: args.reasoning_effort,
|
|
647
|
+
review: args.review,
|
|
542
648
|
provider: args.provider,
|
|
543
649
|
model: args.model,
|
|
544
650
|
keepAlive: args.keep_alive === true,
|
|
@@ -587,7 +693,9 @@ export function createHandlers(hub, opts = {}) {
|
|
|
587
693
|
throw new Error('prompt 不能为空:至少包含一个非空白字符');
|
|
588
694
|
}
|
|
589
695
|
const conv = await hub.get(args.conversation_id);
|
|
696
|
+
const review = args.review === undefined ? undefined : normalizeReviewMode(args.review, conv.review);
|
|
590
697
|
const opts = { reasoning: args.reasoning ?? DEFAULT_REASONING };
|
|
698
|
+
if (review !== undefined) opts.review = review;
|
|
591
699
|
if (args.timeout_ms !== undefined && args.timeout_ms !== null) opts.timeoutMs = parseTimeoutMs(args.timeout_ms);
|
|
592
700
|
|
|
593
701
|
// ── 幂等:同一个 client_run_id 直接返回首次的 run,不重复执行 ──
|
|
@@ -615,6 +723,7 @@ export function createHandlers(hub, opts = {}) {
|
|
|
615
723
|
reasoning: opts.reasoning,
|
|
616
724
|
clientRunId: args.client_run_id ?? null,
|
|
617
725
|
preview: args.prompt,
|
|
726
|
+
review: review ?? conv.review,
|
|
618
727
|
});
|
|
619
728
|
if (deduped) return replayRun(hub, conv, run, false);
|
|
620
729
|
audit('send_queued', {
|
|
@@ -633,7 +742,10 @@ export function createHandlers(hub, opts = {}) {
|
|
|
633
742
|
|
|
634
743
|
const wait = args.wait === true;
|
|
635
744
|
// 记录与预览保留调用方原文;实际派发用 promptText(可能带团队提示)。
|
|
636
|
-
const run = conv.createRun(args.prompt, {
|
|
745
|
+
const run = conv.createRun(args.prompt, {
|
|
746
|
+
clientRunId: args.client_run_id ?? null,
|
|
747
|
+
review: review ?? conv.review,
|
|
748
|
+
});
|
|
637
749
|
// prompt() 自己负责收尾与写哨兵。这里 await 是为了**同步暴露 resume/启动失败** ——
|
|
638
750
|
// 否则调用方会拿到一个 accepted 但注定失败的收据(冷启动要几秒,热会话瞬时)。
|
|
639
751
|
const r = await conv.prompt(promptText, { ...opts, run, wait });
|
|
@@ -833,6 +945,11 @@ export function createHandlers(hub, opts = {}) {
|
|
|
833
945
|
meta.push(` (思考 ${run.result.thinking_stats.chars} 字已隐藏)`);
|
|
834
946
|
}
|
|
835
947
|
if (run.result?.error) meta.push(` ⚠️ 失败: ${run.result.error}`);
|
|
948
|
+
const review = run.review ?? run.result?.review;
|
|
949
|
+
if (review) {
|
|
950
|
+
meta.push('');
|
|
951
|
+
meta.push(renderReviewSection(review));
|
|
952
|
+
}
|
|
836
953
|
}
|
|
837
954
|
const sentinelFile = run ? hub.runSentinelPath(args.conversation_id, run.run_id) : null;
|
|
838
955
|
const runView = run
|
|
@@ -848,6 +965,7 @@ export function createHandlers(hub, opts = {}) {
|
|
|
848
965
|
answer_chars: answerFull.length,
|
|
849
966
|
answer_truncated: truncated,
|
|
850
967
|
next_offset: truncated ? cap : null,
|
|
968
|
+
review: run.review ?? run.result?.review ?? null,
|
|
851
969
|
result: run.result,
|
|
852
970
|
}
|
|
853
971
|
: null;
|
|
@@ -864,6 +982,31 @@ export function createHandlers(hub, opts = {}) {
|
|
|
864
982
|
};
|
|
865
983
|
},
|
|
866
984
|
|
|
985
|
+
async dsh_review(args) {
|
|
986
|
+
const conv = await hub.get(args.conversation_id);
|
|
987
|
+
const r = conv.submitReview(args.run_id, {
|
|
988
|
+
verdict: args.verdict,
|
|
989
|
+
notes: args.notes,
|
|
990
|
+
findings: args.findings,
|
|
991
|
+
});
|
|
992
|
+
audit('review', {
|
|
993
|
+
conversation_id: conv.id,
|
|
994
|
+
run_id: args.run_id,
|
|
995
|
+
verdict: args.verdict,
|
|
996
|
+
});
|
|
997
|
+
const lines = [
|
|
998
|
+
`审核已记录:${r.run_id} → ${r.status}(${r.review_id})`,
|
|
999
|
+
r.notes ? `理由: ${r.notes}` : '理由: (未填写)',
|
|
1000
|
+
];
|
|
1001
|
+
if (Array.isArray(r.findings) && r.findings.length) {
|
|
1002
|
+
lines.push('问题:');
|
|
1003
|
+
for (const f of r.findings) lines.push(` - ${f}`);
|
|
1004
|
+
}
|
|
1005
|
+
lines.push(`审核记录: ${r.review_file}`);
|
|
1006
|
+
lines.push('审核只记录裁决,不会自动回灌给 DSH;需要修复请用 dsh_send 再派活。');
|
|
1007
|
+
return { structured: r, text: lines.join('\n') };
|
|
1008
|
+
},
|
|
1009
|
+
|
|
867
1010
|
async dsh_interject(args) {
|
|
868
1011
|
if (typeof args.message !== 'string' || args.message.trim() === '') {
|
|
869
1012
|
throw new Error('message 不能为空:至少包含一个非空白字符');
|
|
@@ -886,6 +1029,7 @@ export function createHandlers(hub, opts = {}) {
|
|
|
886
1029
|
reasoning: args.reasoning ?? DEFAULT_REASONING,
|
|
887
1030
|
clientRunId: args.client_run_id ?? null,
|
|
888
1031
|
};
|
|
1032
|
+
if (args.review !== undefined) opts.review = normalizeReviewMode(args.review, conv.review);
|
|
889
1033
|
if (args.timeout_ms !== undefined && args.timeout_ms !== null) opts.timeoutMs = parseTimeoutMs(args.timeout_ms);
|
|
890
1034
|
const r = await conv.interject(args.message, opts);
|
|
891
1035
|
conv.lastResult = r;
|
|
@@ -986,6 +1130,7 @@ export function createHandlers(hub, opts = {}) {
|
|
|
986
1130
|
const conv = await hub.get(args.conversation_id);
|
|
987
1131
|
const snap = conv.snapshot();
|
|
988
1132
|
const run = conv.getRun();
|
|
1133
|
+
const review = run ? (run.review ?? run.result?.review ?? null) : null;
|
|
989
1134
|
const bits = [`状态=${snap.state}`, `轮数=${snap.turns}`];
|
|
990
1135
|
if (snap.state === 'running') {
|
|
991
1136
|
bits.push(`已跑=${((snap.running_ms ?? 0) / 1000).toFixed(1)}s`);
|
|
@@ -993,6 +1138,9 @@ export function createHandlers(hub, opts = {}) {
|
|
|
993
1138
|
bits.push(`本轮输出=${snap.out_chars ?? 0}字`);
|
|
994
1139
|
}
|
|
995
1140
|
if (run) bits.push(`最近回合=${run.run_id}(${run.status})`);
|
|
1141
|
+
if (review) {
|
|
1142
|
+
bits.push(`审核=${review.status}${review.verdict ? `(${review.verdict})` : ''}${review.status === 'pending' ? '(待提交)' : ''}`);
|
|
1143
|
+
}
|
|
996
1144
|
bits.push(`待决审批=${snap.pending_approvals.length}`);
|
|
997
1145
|
if (snap.rss_mb != null) bits.push(`rss=${snap.rss_mb}MB`);
|
|
998
1146
|
if (snap.keep_alive) bits.push('保活=是');
|
|
@@ -1037,6 +1185,9 @@ export function createHandlers(hub, opts = {}) {
|
|
|
1037
1185
|
lock_holder: snap.lock_holder,
|
|
1038
1186
|
lock_holder_reason: snap.lock_holder_reason,
|
|
1039
1187
|
lock_conflict: snap.lock_conflict,
|
|
1188
|
+
review: review
|
|
1189
|
+
? { review_id: review.review_id, status: review.status, verdict: review.verdict ?? null }
|
|
1190
|
+
: null,
|
|
1040
1191
|
run: run
|
|
1041
1192
|
? {
|
|
1042
1193
|
run_id: run.run_id,
|
|
@@ -1175,6 +1326,7 @@ export function createHandlers(hub, opts = {}) {
|
|
|
1175
1326
|
|
|
1176
1327
|
for (const [id, dir] of [
|
|
1177
1328
|
['runs_dir', RUNS_DIR],
|
|
1329
|
+
['reviews_dir', REVIEWS_DIR],
|
|
1178
1330
|
['locks_dir', LOCKS_DIR],
|
|
1179
1331
|
]) {
|
|
1180
1332
|
try {
|