dsh-taskbridge 1.3.2 → 1.4.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 +23 -2
- package/README.md +19 -13
- package/bin/dsh-delegate-mcp.js +4 -0
- package/codex/dsh-taskbridge.toml +129 -24
- package/docs/INTRODUCTION.md +19 -15
- package/docs/INTRODUCTION.zh.md +38 -34
- package/docs/codex-integration.md +63 -20
- package/docs/plugin-market.md +1 -1
- package/docs/releases/1.4.0-token-benchmark.zh.md +40 -0
- package/docs/releases/1.4.0.zh.md +54 -0
- package/docs/releases/1.4.1.zh.md +59 -0
- package/docs/runtime-compatibility.md +17 -9
- package/docs/silent-wait.md +87 -10
- package/docs/taskbridge-upgrade.md +1 -1
- package/lib/client.js +305 -65
- package/package.json +7 -3
- package/src/client/api.js +326 -46
- package/src/client/index.jsx +226 -52
- package/src/codex/installer.js +39 -6
- package/src/config/defaults.js +12 -0
- package/src/config/settings.js +12 -10
- package/src/config/validate.js +26 -11
- package/src/http/execution-plane.js +179 -9
- package/src/http/respond.js +179 -175
- package/src/http/user-plane.js +5 -4
- package/src/index.d.ts +157 -3
- package/src/index.js +1 -1
- package/src/jobs/activity.js +1369 -1008
- package/src/jobs/diagnostics.js +15 -0
- package/src/jobs/engine.js +1029 -12
- package/src/jobs/history.js +152 -6
- package/src/jobs/review-note.js +63 -0
- package/src/mcp/server.js +345 -21
- package/src/mcp/wait.js +67 -10
package/src/client/api.js
CHANGED
|
@@ -426,9 +426,10 @@ export function conversationModeLabel(mode) {
|
|
|
426
426
|
* inconsistent pair is passed through so the operator sees what they typed and the
|
|
427
427
|
* precheck can explain it. Only a missing block, a non-object, or a non-finite value
|
|
428
428
|
* falls back to the documented default — an older stored document (no `monitoring`
|
|
429
|
-
* key) therefore opens at 300/600 s, i.e. 5/10 minutes
|
|
429
|
+
* key) therefore opens at 300/600 s, i.e. 5/10 minutes, with the repeated-failure
|
|
430
|
+
* reminder at its default of 3.
|
|
430
431
|
* @param {object | null} source - served document, draft, or raw block.
|
|
431
|
-
* @returns {{ selfCheckSeconds: number, attentionSeconds: number }} normalized block.
|
|
432
|
+
* @returns {{ selfCheckSeconds: number, attentionSeconds: number, repeatFailureThreshold: number }} normalized block.
|
|
432
433
|
*/
|
|
433
434
|
export function monitoringOf(source) {
|
|
434
435
|
const block = source?.monitoring;
|
|
@@ -437,6 +438,36 @@ export function monitoringOf(source) {
|
|
|
437
438
|
return {
|
|
438
439
|
selfCheckSeconds: whole(block.selfCheckSeconds, MONITORING_DEFAULTS.selfCheckSeconds),
|
|
439
440
|
attentionSeconds: whole(block.attentionSeconds, MONITORING_DEFAULTS.attentionSeconds),
|
|
441
|
+
repeatFailureThreshold: whole(block.repeatFailureThreshold, MONITORING_DEFAULTS.repeatFailureThreshold),
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* The RAW monitoring block of a draft, for validation only.
|
|
447
|
+
*
|
|
448
|
+
* `monitoringOf` is a display normalizer: it turns a blank or non-finite field into the
|
|
449
|
+
* documented default so the inputs still render. That is exactly wrong for validating
|
|
450
|
+
* an edit — a cleared field would silently look like the default and the save button
|
|
451
|
+
* would stay enabled. This keeps whatever the operator actually typed (including `''`),
|
|
452
|
+
* so the shared precheck can refuse it. Only a missing block falls back to the defaults.
|
|
453
|
+
*
|
|
454
|
+
* One narrow exception: a block that predates the repeated-failure count has no such key
|
|
455
|
+
* at all, and an absent key is not an operator error — it is the documented default. So
|
|
456
|
+
* `undefined` becomes the default value (making the field editable for an older document),
|
|
457
|
+
* while an explicit `''`, `null`, fractional or out-of-range value is preserved exactly so
|
|
458
|
+
* the precheck still refuses it.
|
|
459
|
+
* @param {object | null} source - draft or served document.
|
|
460
|
+
* @returns {object} the block as stored, or the defaults when there is none.
|
|
461
|
+
*/
|
|
462
|
+
export function monitoringDraftOf(source) {
|
|
463
|
+
const block = source?.monitoring;
|
|
464
|
+
if (block === null || typeof block !== 'object' || Array.isArray(block)) return { ...MONITORING_DEFAULTS };
|
|
465
|
+
return {
|
|
466
|
+
selfCheckSeconds: block.selfCheckSeconds,
|
|
467
|
+
attentionSeconds: block.attentionSeconds,
|
|
468
|
+
repeatFailureThreshold: block.repeatFailureThreshold === undefined
|
|
469
|
+
? MONITORING_DEFAULTS.repeatFailureThreshold
|
|
470
|
+
: block.repeatFailureThreshold,
|
|
440
471
|
};
|
|
441
472
|
}
|
|
442
473
|
|
|
@@ -590,10 +621,13 @@ export const LIMITS = Object.freeze({
|
|
|
590
621
|
selfCheckSecondsMax: 3600,
|
|
591
622
|
attentionSecondsMin: 31,
|
|
592
623
|
attentionSecondsMax: 7200,
|
|
624
|
+
// Repeated-failure reminder: a COUNT of consecutive identical failures, 0 = off.
|
|
625
|
+
repeatFailureThresholdMin: 0,
|
|
626
|
+
repeatFailureThresholdMax: 20,
|
|
593
627
|
});
|
|
594
628
|
|
|
595
629
|
/**
|
|
596
|
-
* Default silence thresholds, mirroring `MONITORING_DEFAULTS`.
|
|
630
|
+
* Default silence thresholds and failure count, mirroring `MONITORING_DEFAULTS`.
|
|
597
631
|
*
|
|
598
632
|
* Stored as whole SECONDS (300 / 600). The panel presents them as minutes because
|
|
599
633
|
* that is how an operator thinks about them; a value that is not a whole number of
|
|
@@ -602,6 +636,7 @@ export const LIMITS = Object.freeze({
|
|
|
602
636
|
export const MONITORING_DEFAULTS = Object.freeze({
|
|
603
637
|
selfCheckSeconds: 300,
|
|
604
638
|
attentionSeconds: 600,
|
|
639
|
+
repeatFailureThreshold: 3,
|
|
605
640
|
});
|
|
606
641
|
|
|
607
642
|
/** Chinese labels for the self-check verdicts the host publishes. */
|
|
@@ -614,6 +649,30 @@ export const SELF_CHECK_LABELS = Object.freeze({
|
|
|
614
649
|
settled: '任务已经结束',
|
|
615
650
|
});
|
|
616
651
|
|
|
652
|
+
/** Chinese label for the repeated-failure reminder kind. */
|
|
653
|
+
export const REPEATED_FAILURE_LABEL = '同一操作连续失败';
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* One line describing the repeated-failure reminder on a task page.
|
|
657
|
+
*
|
|
658
|
+
* The engine already reduced this to a tool name, a failure code and counts, so this
|
|
659
|
+
* is a formatter and nothing else: no arguments, output or error prose is available
|
|
660
|
+
* here even if a stored record somehow carried it.
|
|
661
|
+
* @param {object | null} activity - the task's activity block.
|
|
662
|
+
* @returns {string} display text.
|
|
663
|
+
*/
|
|
664
|
+
export function repeatFailureLine(activity) {
|
|
665
|
+
const block = activity?.repeatFailure;
|
|
666
|
+
if (block === null || block === undefined) return '未采集到';
|
|
667
|
+
const reported = Array.isArray(block.reported) ? block.reported : [];
|
|
668
|
+
if (reported.length === 0) {
|
|
669
|
+
return block.threshold === 0 ? '已关闭' : `尚未触发(连续 ${block.threshold} 次才提醒)`;
|
|
670
|
+
}
|
|
671
|
+
return reported
|
|
672
|
+
.map((entry) => `${entry.toolName ?? '工具'} · ${entry.failureCode ?? 'error'} 连续 ${entry.consecutive} 次`)
|
|
673
|
+
.join(';');
|
|
674
|
+
}
|
|
675
|
+
|
|
617
676
|
/** Chinese labels for the reasons a wait returns. */
|
|
618
677
|
export const WAIT_REASON_LABELS = Object.freeze({
|
|
619
678
|
heartbeat: '没有需要处理的事(内部心跳)',
|
|
@@ -1006,25 +1065,12 @@ export function precheckDraft(draft) {
|
|
|
1006
1065
|
if (!Number.isInteger(parallelism) || parallelism < LIMITS.maxParallelismMin || parallelism > LIMITS.maxParallelismMax) {
|
|
1007
1066
|
problems.push(`最大并发需为 ${LIMITS.maxParallelismMin}–${LIMITS.maxParallelismMax} 之间的整数`);
|
|
1008
1067
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
const min = field === 'selfCheckSeconds' ? LIMITS.selfCheckSecondsMin : LIMITS.attentionSecondsMin;
|
|
1016
|
-
const max = field === 'selfCheckSeconds' ? LIMITS.selfCheckSecondsMax : LIMITS.attentionSecondsMax;
|
|
1017
|
-
if (!Number.isInteger(value) || value < min || value > max) {
|
|
1018
|
-
problems.push(`${label}需为 ${min}–${max} 秒之间的整数`);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
// The ordering rule mirrors `validateMonitoringSettings`: an attention threshold at
|
|
1022
|
-
// or below the self-check one would alert about something the self-check has not
|
|
1023
|
-
// even examined yet.
|
|
1024
|
-
if (Number.isInteger(monitoring.selfCheckSeconds) && Number.isInteger(monitoring.attentionSeconds)
|
|
1025
|
-
&& monitoring.attentionSeconds <= monitoring.selfCheckSeconds) {
|
|
1026
|
-
problems.push('提醒你的间隔必须大于程序自检间隔');
|
|
1027
|
-
}
|
|
1068
|
+
// The RAW block, not the display-normalized one: a cleared field must be refused
|
|
1069
|
+
// here instead of silently becoming the documented default on save. The rules
|
|
1070
|
+
// themselves live in exactly one place — `precheckMonitoring` — so a field can never
|
|
1071
|
+
// be validated by the narrow monitoring button and forgotten by this whole-draft check
|
|
1072
|
+
// (which is what happened to the repeated-failure count).
|
|
1073
|
+
problems.push(...precheckMonitoring(monitoringDraftOf(draft)));
|
|
1028
1074
|
return problems;
|
|
1029
1075
|
}
|
|
1030
1076
|
|
|
@@ -1209,7 +1255,11 @@ export function taskActivity(task) {
|
|
|
1209
1255
|
*/
|
|
1210
1256
|
export function taskProgress(task) {
|
|
1211
1257
|
const activity = taskActivity(task);
|
|
1212
|
-
|
|
1258
|
+
// The headline must not contradict the task's own status badge. `taskOutcome` owns the
|
|
1259
|
+
// headline wording, so a recorded review (or a finished run) says THAT here instead of
|
|
1260
|
+
// repeating the raw phase label a second time.
|
|
1261
|
+
const outcome = taskOutcome(task);
|
|
1262
|
+
const phase = outcome.label;
|
|
1213
1263
|
if (activity === null) {
|
|
1214
1264
|
return {
|
|
1215
1265
|
available: false,
|
|
@@ -1297,18 +1347,67 @@ export function hasLiveTasks(tasks) {
|
|
|
1297
1347
|
}
|
|
1298
1348
|
|
|
1299
1349
|
/**
|
|
1300
|
-
*
|
|
1350
|
+
* Whether a task's RECORD may still change, which is a wider question than "is it running".
|
|
1351
|
+
*
|
|
1352
|
+
* A finished run is terminal as an execution, but its record is not settled: it waits for
|
|
1353
|
+
* the host's review, and a review written by the commander can be mid-save. The page must
|
|
1354
|
+
* keep refreshing while any of that is true, or a conclusion written from outside appears
|
|
1355
|
+
* only after a manual reload — and it must stop once the conclusion is durable, or the page
|
|
1356
|
+
* polls a row that will never change again.
|
|
1357
|
+
* @param {object} task - task view.
|
|
1358
|
+
* @returns {boolean} true while the record may still change.
|
|
1359
|
+
*/
|
|
1360
|
+
export function isTaskRecordChanging(task) {
|
|
1361
|
+
if (isLiveTask(task)) return true;
|
|
1362
|
+
if (task?.state === 'awaiting-host-review') {
|
|
1363
|
+
// A stored conclusion still waiting for confirmation is not a fixed record yet.
|
|
1364
|
+
const persistence = task.reviewPersistence;
|
|
1365
|
+
if (persistence !== null && typeof persistence === 'object') return persistence.durable !== true;
|
|
1366
|
+
return task.hostAcceptance === null || task.hostAcceptance === undefined;
|
|
1367
|
+
}
|
|
1368
|
+
return task?.reviewPersistence?.pending === true;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* Whether any of these tasks has a record that may still change.
|
|
1373
|
+
* @param {object[]} tasks - task views.
|
|
1374
|
+
* @returns {boolean} true when a refresh could still learn something.
|
|
1375
|
+
*/
|
|
1376
|
+
export function hasChangingRecords(tasks) {
|
|
1377
|
+
return Array.isArray(tasks) && tasks.some(isTaskRecordChanging);
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
/**
|
|
1381
|
+
* Pre-flight checks for the silence thresholds AND the repeated-failure count.
|
|
1301
1382
|
*
|
|
1302
1383
|
* Mirrors `validateMonitoringSettings`. Kept separate because the monitoring save has
|
|
1303
1384
|
* its own narrow button: a bad timer must not block saving the rest of the settings,
|
|
1304
1385
|
* and a bad provider block must not block saving a timer.
|
|
1305
|
-
*
|
|
1386
|
+
*
|
|
1387
|
+
* The block passed in must be the RAW one (`monitoringDraftOf`), not the display-normalized
|
|
1388
|
+
* `monitoringOf`: the latter replaces a cleared field with the documented default, which
|
|
1389
|
+
* would make an empty input look valid. This is the single validation path — `precheckDraft`
|
|
1390
|
+
* and the monitoring card both delegate here, so the count cannot be checked in one place
|
|
1391
|
+
* and forgotten in another.
|
|
1392
|
+
*
|
|
1393
|
+
* Backwards compatible with an older document or an older host that has no
|
|
1394
|
+
* `repeatFailureThreshold` at all: an ABSENT value takes the documented default, exactly as
|
|
1395
|
+
* the host validator does. A value that is present but wrong is still refused.
|
|
1396
|
+
* @param {{ selfCheckSeconds: number, attentionSeconds: number, repeatFailureThreshold?: number }} monitoring - raw block.
|
|
1306
1397
|
* @returns {string[]} Chinese problem descriptions; empty when plausible.
|
|
1307
1398
|
*/
|
|
1308
1399
|
export function precheckMonitoring(monitoring) {
|
|
1309
1400
|
const problems = [];
|
|
1310
1401
|
const self = monitoring?.selfCheckSeconds;
|
|
1311
1402
|
const attention = monitoring?.attentionSeconds;
|
|
1403
|
+
// An ABSENT count is not an operator error: a document written before this setting
|
|
1404
|
+
// existed has no such key, and the host fills in the documented default. Anything the
|
|
1405
|
+
// operator actually supplied — `''`, `null`, a fraction, an out-of-range number — is
|
|
1406
|
+
// validated exactly as given. There is deliberately no `Number()` coercion and no
|
|
1407
|
+
// rounding, so nothing is "repaired" into a value nobody chose.
|
|
1408
|
+
const repeat = monitoring?.repeatFailureThreshold === undefined
|
|
1409
|
+
? MONITORING_DEFAULTS.repeatFailureThreshold
|
|
1410
|
+
: monitoring.repeatFailureThreshold;
|
|
1312
1411
|
if (!Number.isInteger(self) || self < LIMITS.selfCheckSecondsMin || self > LIMITS.selfCheckSecondsMax) {
|
|
1313
1412
|
problems.push(`程序自检间隔需为 ${LIMITS.selfCheckSecondsMin}–${LIMITS.selfCheckSecondsMax} 秒之间的整数`);
|
|
1314
1413
|
}
|
|
@@ -1318,34 +1417,211 @@ export function precheckMonitoring(monitoring) {
|
|
|
1318
1417
|
if (Number.isInteger(self) && Number.isInteger(attention) && attention <= self) {
|
|
1319
1418
|
problems.push('提醒你的间隔必须大于程序自检间隔');
|
|
1320
1419
|
}
|
|
1420
|
+
// The repeated-failure reminder is a COUNT of consecutive identical failures; `0` is a
|
|
1421
|
+
// legal "off" value, so the range starts at zero rather than at one.
|
|
1422
|
+
if (!Number.isInteger(repeat)
|
|
1423
|
+
|| repeat < LIMITS.repeatFailureThresholdMin
|
|
1424
|
+
|| repeat > LIMITS.repeatFailureThresholdMax) {
|
|
1425
|
+
problems.push(`重复失败提醒次数需为 ${LIMITS.repeatFailureThresholdMin}–${LIMITS.repeatFailureThresholdMax} 之间的整数(0 表示关闭)`);
|
|
1426
|
+
}
|
|
1321
1427
|
return problems;
|
|
1322
1428
|
}
|
|
1323
1429
|
|
|
1324
1430
|
/**
|
|
1325
|
-
* Honest execution/acceptance summary for one task.
|
|
1431
|
+
* Honest execution/acceptance summary for one task — the ONE source of a task's headline.
|
|
1326
1432
|
*
|
|
1327
|
-
* The engine reports `awaiting-host-review` after successful execution. That is
|
|
1328
|
-
*
|
|
1329
|
-
*
|
|
1433
|
+
* The engine reports `awaiting-host-review` after successful execution. That is NOT
|
|
1434
|
+
* acceptance: `selfApproved` is always false, and only a recorded host decision with
|
|
1435
|
+
* `accepted === true` counts. A recorded `changes-requested` is a real conclusion too —
|
|
1436
|
+
* "reviewed and needs correction" — and must never read as accepted.
|
|
1437
|
+
*
|
|
1438
|
+
* `label` is what a list or a detail header shows INSTEAD of the raw state, so a task with
|
|
1439
|
+
* a recorded conclusion never keeps reading "等待宿主审查". The underlying `state` is
|
|
1440
|
+
* untouched (older clients and `continueFromTaskId` depend on it); this is presentation
|
|
1441
|
+
* only.
|
|
1330
1442
|
* @param {object} task - task view.
|
|
1331
|
-
* @returns {{ label: string, executed: boolean, accepted: boolean,
|
|
1443
|
+
* @returns {{ label: string, tone: string, executed: boolean, accepted: boolean, decided: boolean,
|
|
1444
|
+
* phaseLabel: string | null, note: string }} summary. `phaseLabel` is `null` when the
|
|
1445
|
+
* phase would repeat the label.
|
|
1332
1446
|
*/
|
|
1333
1447
|
export function taskOutcome(task) {
|
|
1334
1448
|
const state = String(task?.state ?? '');
|
|
1335
|
-
const
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1449
|
+
const acceptance = task?.hostAcceptance;
|
|
1450
|
+
const persistence = task?.reviewPersistence;
|
|
1451
|
+
// Only an explicit `accepted === true` is acceptance. The presence of an object is NOT
|
|
1452
|
+
// enough: a `changes-requested` record is also an object — and neither is a conclusion
|
|
1453
|
+
// that is still being written, which is why a non-durable record is not `decided`.
|
|
1454
|
+
const decided = (acceptance !== null && acceptance !== undefined)
|
|
1455
|
+
&& (persistence === null || persistence === undefined || persistence.durable !== false);
|
|
1456
|
+
const accepted = decided && acceptance?.accepted === true;
|
|
1457
|
+
const executed = state === 'awaiting-host-review' || decided;
|
|
1458
|
+
let label;
|
|
1459
|
+
let tone;
|
|
1460
|
+
let note;
|
|
1461
|
+
let phaseLabel;
|
|
1462
|
+
// A conclusion that is being written, or whose write was never confirmed, is its OWN
|
|
1463
|
+
// state: the page must not claim 审查通过 before the record is durable, and must not
|
|
1464
|
+
// hide a pending decision behind "等待宿主审查".
|
|
1465
|
+
const saving = persistence?.pending === true;
|
|
1466
|
+
const failedWrite = persistence?.state === 'failed';
|
|
1467
|
+
if (accepted) {
|
|
1468
|
+
label = '审查通过';
|
|
1469
|
+
tone = 'on';
|
|
1470
|
+
note = '宿主已记录验收结论:审查通过。';
|
|
1471
|
+
// The run is over AND reviewed, so the phase would only repeat itself.
|
|
1472
|
+
phaseLabel = null;
|
|
1473
|
+
} else if (decided) {
|
|
1474
|
+
label = '需要修正';
|
|
1475
|
+
tone = 'warn';
|
|
1476
|
+
note = '宿主已记录验收结论:需要修正(本任务的执行结果未被接受)。';
|
|
1477
|
+
phaseLabel = null;
|
|
1478
|
+
} else if (saving) {
|
|
1479
|
+
label = persistence.state === 'timed-out' ? '审查结论保存未确认' : '审查结论保存中';
|
|
1480
|
+
tone = 'warn';
|
|
1481
|
+
note = persistence.state === 'timed-out'
|
|
1482
|
+
? '审查结论已发出但尚未确认写入;插件会继续读取同一任务直到确认,不要重新派工。'
|
|
1483
|
+
: '审查结论正在写入,确认保存后才会显示审查通过或需要修正。';
|
|
1484
|
+
phaseLabel = null;
|
|
1485
|
+
} else if (failedWrite) {
|
|
1486
|
+
label = '审查结论保存失败';
|
|
1487
|
+
tone = 'warn';
|
|
1488
|
+
note = '审查结论未能写入,未记录为已验收;可对同一任务重试。';
|
|
1489
|
+
phaseLabel = null;
|
|
1490
|
+
} else if (state === 'awaiting-host-review') {
|
|
1491
|
+
label = '等待宿主审查';
|
|
1492
|
+
tone = 'warn';
|
|
1493
|
+
note = '执行已完成,等待宿主(Codex)审查;插件不会自行验收。';
|
|
1494
|
+
// Stated once, as the headline above; a second identical phase badge is noise.
|
|
1495
|
+
phaseLabel = null;
|
|
1496
|
+
} else if (state === 'failed') {
|
|
1497
|
+
label = taskStateLabel(state);
|
|
1498
|
+
tone = 'warn';
|
|
1499
|
+
note = '执行失败;错误详情见下方证据。';
|
|
1500
|
+
phaseLabel = null;
|
|
1501
|
+
} else if (state === 'cancelled') {
|
|
1502
|
+
label = taskStateLabel(state);
|
|
1503
|
+
tone = 'off';
|
|
1504
|
+
note = '任务已取消,未产生验收结论。';
|
|
1505
|
+
phaseLabel = null;
|
|
1506
|
+
} else {
|
|
1507
|
+
label = taskStateLabel(state);
|
|
1508
|
+
tone = state === 'running' ? 'on' : 'off';
|
|
1509
|
+
note = '任务尚未产生结果。';
|
|
1510
|
+
// A live run DOES keep a distinct phase badge: it says what is happening right now,
|
|
1511
|
+
// which the state label does not. That is information, not a contradiction.
|
|
1512
|
+
phaseLabel = taskPhaseLabel(task?.phase);
|
|
1513
|
+
}
|
|
1514
|
+
return { label, tone, executed, accepted, decided, phaseLabel, note };
|
|
1347
1515
|
}
|
|
1348
1516
|
|
|
1517
|
+
/**
|
|
1518
|
+
* The host-review badge for one task, or `null` when the headline already says it.
|
|
1519
|
+
*
|
|
1520
|
+
* `taskOutcome(...).label` is the primary status; this exists so a caller that wants a
|
|
1521
|
+
* SEPARATE review badge gets exactly the same wording and tone rather than a second,
|
|
1522
|
+
* possibly contradictory, string. It returns `null` whenever the headline already carries
|
|
1523
|
+
* the review state, which is what keeps "等待审查" from appearing twice — or alongside
|
|
1524
|
+
* "审查通过".
|
|
1525
|
+
* @param {object} task - task view.
|
|
1526
|
+
* @returns {{ label: string, tone: string } | null} badge, or null to show nothing.
|
|
1527
|
+
*/
|
|
1528
|
+
export function hostReviewBadge(task) {
|
|
1529
|
+
const acceptance = task?.hostAcceptance;
|
|
1530
|
+
if (acceptance === null || acceptance === undefined) return null;
|
|
1531
|
+
// Derive from the same helper, so the two can never disagree.
|
|
1532
|
+
const { label, tone } = taskOutcome(task);
|
|
1533
|
+
return { label, tone };
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
/**
|
|
1537
|
+
* A task's recorded review conclusion as one bounded display line.
|
|
1538
|
+
*
|
|
1539
|
+
* Only a short note and the time are shown: the stored note is already redacted, and
|
|
1540
|
+
* nothing else about the review exists.
|
|
1541
|
+
* @param {object} task - task view.
|
|
1542
|
+
* @param {(at: number) => string} formatTime - time formatter from the page.
|
|
1543
|
+
* @returns {string} display text.
|
|
1544
|
+
*/
|
|
1545
|
+
export function hostReviewLine(task, formatTime) {
|
|
1546
|
+
const acceptance = task?.hostAcceptance;
|
|
1547
|
+
if (acceptance === null || acceptance === undefined) return '未记录(插件不会自行验收)';
|
|
1548
|
+
const label = acceptance.accepted === true ? '审查通过' : '需要修正';
|
|
1549
|
+
const at = typeof acceptance.acceptedAt === 'number' ? `(${formatTime(acceptance.acceptedAt)})` : '';
|
|
1550
|
+
const note = typeof acceptance.note === 'string' && acceptance.note !== ''
|
|
1551
|
+
? `:${boundedText(acceptance.note, 200)}`
|
|
1552
|
+
: '';
|
|
1553
|
+
return `${label}${at}${note}`;
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
/**
|
|
1557
|
+
* Length of a review note in Unicode code points.
|
|
1558
|
+
* @param {unknown} value - note.
|
|
1559
|
+
* @returns {number} code-point count (0 for a non-string).
|
|
1560
|
+
*/
|
|
1561
|
+
export function reviewNoteChars(value) {
|
|
1562
|
+
return typeof value === 'string' ? Array.from(value).length : 0;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
/** How many code points of a review note a LIST shows. */
|
|
1566
|
+
export const REVIEW_NOTE_PREVIEW_CHARS = 200;
|
|
1567
|
+
|
|
1568
|
+
/**
|
|
1569
|
+
* The list preview of a recorded review note, and whether the whole note is longer.
|
|
1570
|
+
*
|
|
1571
|
+
* The preview is a display cut of the SAVED body: the body itself is never shortened (that
|
|
1572
|
+
* is a storage rule), and `truncated` tells the page to offer the full text.
|
|
1573
|
+
* @param {object} task - task view.
|
|
1574
|
+
* @returns {{ text: string, chars: number, truncated: boolean, omitted: boolean } | null} preview.
|
|
1575
|
+
*/
|
|
1576
|
+
export function reviewNotePreview(task) {
|
|
1577
|
+
const acceptance = task?.hostAcceptance;
|
|
1578
|
+
if (acceptance === null || acceptance === undefined) return null;
|
|
1579
|
+
// A note read back from a compact answer is stated as omitted: the text exists, the
|
|
1580
|
+
// answer does not carry it, so the page must offer the full read instead of "no note".
|
|
1581
|
+
if (acceptance.noteOmitted === true && typeof acceptance.note !== 'string') {
|
|
1582
|
+
const chars = Number.isFinite(acceptance.noteChars) ? acceptance.noteChars : 0;
|
|
1583
|
+
return { text: '', chars, truncated: chars > 0, omitted: true };
|
|
1584
|
+
}
|
|
1585
|
+
const note = typeof acceptance.note === 'string' ? acceptance.note : '';
|
|
1586
|
+
const all = Array.from(note);
|
|
1587
|
+
return {
|
|
1588
|
+
text: all.slice(0, REVIEW_NOTE_PREVIEW_CHARS).join(''),
|
|
1589
|
+
chars: all.length,
|
|
1590
|
+
truncated: all.length > REVIEW_NOTE_PREVIEW_CHARS,
|
|
1591
|
+
omitted: false,
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
/**
|
|
1596
|
+
* How often the page refreshes while a record may still change, in milliseconds.
|
|
1597
|
+
*
|
|
1598
|
+
* Kept here rather than in the page so the hook and the page share one number.
|
|
1599
|
+
*/
|
|
1600
|
+
export const RECORD_REFRESH_INTERVAL_MS = 5000;
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* The refresh decision for one render of the task view.
|
|
1604
|
+
*
|
|
1605
|
+
* Separates "is the execution running" (a status display question) from "may the RECORD
|
|
1606
|
+
* still change" (a polling question): a task waiting for review, or a review mid-save,
|
|
1607
|
+
* keeps the page polling even though nothing is executing — and the page stops once every
|
|
1608
|
+
* visible record is settled. Hidden pages never poll, and a page that is already loading
|
|
1609
|
+
* never starts a second request.
|
|
1610
|
+
* @param {object} input - `tasks`, `selectedTask`, `visible`, `loading`.
|
|
1611
|
+
* @returns {{ refresh: boolean, intervalMs: number, reason: string }} plan.
|
|
1612
|
+
*/
|
|
1613
|
+
export function recordRefreshPlan(input = {}) {
|
|
1614
|
+
const all = [];
|
|
1615
|
+
if (Array.isArray(input.tasks)) all.push(...input.tasks);
|
|
1616
|
+
if (input.selectedTask !== null && input.selectedTask !== undefined) all.push(input.selectedTask);
|
|
1617
|
+
const changing = hasChangingRecords(all);
|
|
1618
|
+
const intervalMs = RECORD_REFRESH_INTERVAL_MS;
|
|
1619
|
+
if (input.visible === false) return { refresh: false, intervalMs, reason: 'hidden' };
|
|
1620
|
+
if (changing !== true) return { refresh: false, intervalMs, reason: 'settled' };
|
|
1621
|
+
// One request at a time: a refresh already in flight owns the next tick.
|
|
1622
|
+
if (input.loading === true) return { refresh: false, intervalMs, reason: 'loading' };
|
|
1623
|
+
return { refresh: true, intervalMs, reason: 'changing' };
|
|
1624
|
+
}
|
|
1349
1625
|
/**
|
|
1350
1626
|
* Discoverable changed-file list in a task's diff payload.
|
|
1351
1627
|
*
|
|
@@ -2183,22 +2459,26 @@ export function createStore(options = {}) {
|
|
|
2183
2459
|
},
|
|
2184
2460
|
|
|
2185
2461
|
/**
|
|
2186
|
-
* Replace
|
|
2462
|
+
* Replace the silence thresholds and the repeated-failure count.
|
|
2187
2463
|
*
|
|
2188
2464
|
* The narrow route exists so an operator adjusting a timer cannot rewrite a
|
|
2189
2465
|
* provider list. On success the committed document is adopted for `settings` and
|
|
2190
2466
|
* the draft's monitoring block, and OTHER unsaved draft edits are left alone —
|
|
2191
2467
|
* a timer save must never discard a half-finished provider edit.
|
|
2192
|
-
*
|
|
2468
|
+
*
|
|
2469
|
+
* Order matters: the RAW block is validated first and only then normalized for the
|
|
2470
|
+
* wire. Validating the normalized block would accept a cleared field, because
|
|
2471
|
+
* `monitoringOf` replaces it with the documented default.
|
|
2472
|
+
* @param {{ selfCheckSeconds: number, attentionSeconds: number, repeatFailureThreshold: number }} monitoring - the block as the operator typed it.
|
|
2193
2473
|
* @returns {Promise<{ ok: boolean, error?: unknown }>} outcome.
|
|
2194
2474
|
*/
|
|
2195
2475
|
async saveMonitoring(monitoring) {
|
|
2196
|
-
const
|
|
2197
|
-
const problems = precheckMonitoring(normalized);
|
|
2476
|
+
const problems = precheckMonitoring(monitoring);
|
|
2198
2477
|
if (problems.length > 0) {
|
|
2199
2478
|
notify('error', `未保存:${problems.join(';')}`);
|
|
2200
2479
|
return { ok: false, problems };
|
|
2201
2480
|
}
|
|
2481
|
+
const normalized = monitoringOf({ monitoring });
|
|
2202
2482
|
return await track('monitoring', async () => {
|
|
2203
2483
|
try {
|
|
2204
2484
|
const body = await api.putMonitoring(normalized);
|