dsh-taskbridge 1.3.2 → 1.4.0

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.
@@ -85,14 +85,17 @@ import {
85
85
  isCancellable,
86
86
  hasLiveTasks,
87
87
  formatDuration,
88
+ hostReviewLine,
88
89
  isLiveTask,
89
90
  minutesToSeconds,
91
+ monitoringDraftOf,
90
92
  monitoringOf,
91
93
  pendingPermission,
92
94
  permissionSummary,
93
95
  precheckDraft,
94
96
  precheckMonitoring,
95
97
  previewEffective,
98
+ repeatFailureLine,
96
99
  secondsToMinutes,
97
100
  SELF_CHECK_LABELS,
98
101
  taskActivity,
@@ -1454,22 +1457,45 @@ function PresetsCard({ store, snapshot }) {
1454
1457
  */
1455
1458
  function MonitoringCard({ store, snapshot }) {
1456
1459
  const draft = snapshot.draft;
1457
- const monitoring = monitoringOf(draft);
1460
+ // The RAW block is what the inputs display and what the save validates. Binding the
1461
+ // inputs to the display-normalized block instead would make a cleared field
1462
+ // immediately re-render as the documented default, hiding the edit.
1463
+ const raw = monitoringDraftOf(draft);
1458
1464
  const saved = monitoringOf(snapshot.settings);
1459
1465
  const [saving, setSaving] = useState(false);
1460
- const problems = precheckMonitoring(monitoring);
1461
- const dirty = monitoring.selfCheckSeconds !== saved.selfCheckSeconds
1462
- || monitoring.attentionSeconds !== saved.attentionSeconds;
1466
+ const problems = precheckMonitoring(raw);
1467
+ const dirty = raw.selfCheckSeconds !== saved.selfCheckSeconds
1468
+ || raw.attentionSeconds !== saved.attentionSeconds
1469
+ || raw.repeatFailureThreshold !== saved.repeatFailureThreshold;
1463
1470
 
1464
1471
  /**
1465
1472
  * Write one field, converting minutes back to the stored unit.
1473
+ *
1474
+ * The block is spread from the RAW draft, not from `monitoringOf`: normalizing here
1475
+ * would rewrite the operator's other half-typed fields (for example a cleared count)
1476
+ * back to their defaults on every keystroke.
1466
1477
  * @param {'selfCheckSeconds' | 'attentionSeconds'} field - target field.
1467
- * @param {unknown} raw - operator input, in minutes.
1478
+ * @param {unknown} rawMinutes - operator input, in minutes.
1468
1479
  * @returns {void}
1469
1480
  */
1470
- const edit = (field, raw) => {
1481
+ const edit = (field, rawMinutes) => {
1471
1482
  store.editDraft((current) => {
1472
- current.monitoring = { ...monitoringOf(current), [field]: minutesToSeconds(raw) };
1483
+ current.monitoring = { ...monitoringDraftOf(current), [field]: minutesToSeconds(rawMinutes) };
1484
+ });
1485
+ };
1486
+
1487
+ /**
1488
+ * Write the repeated-failure count. A blank field becomes `''`, which the precheck
1489
+ * reports rather than turning into an accidental default.
1490
+ * @param {unknown} value - operator input, a count.
1491
+ * @returns {void}
1492
+ */
1493
+ const editFailureCount = (value) => {
1494
+ store.editDraft((current) => {
1495
+ current.monitoring = {
1496
+ ...monitoringDraftOf(current),
1497
+ repeatFailureThreshold: value === '' ? '' : Number(value),
1498
+ };
1473
1499
  });
1474
1500
  };
1475
1501
 
@@ -1484,7 +1510,7 @@ function MonitoringCard({ store, snapshot }) {
1484
1510
  <Field
1485
1511
  label="程序自检间隔(分钟)"
1486
1512
  htmlFor="dshdg-monitoring-selfcheck"
1487
- hint={`${LIMITS.selfCheckSecondsMin / 60}–${LIMITS.selfCheckSecondsMax / 60} 分钟;存成整秒(当前 ${monitoring.selfCheckSeconds} 秒)`}
1513
+ hint={`${LIMITS.selfCheckSecondsMin / 60}–${LIMITS.selfCheckSecondsMax / 60} 分钟;存成整秒(当前 ${raw.selfCheckSeconds === '' ? '未填' : `${raw.selfCheckSeconds} 秒`})`}
1488
1514
  >
1489
1515
  <input
1490
1516
  id="dshdg-monitoring-selfcheck"
@@ -1493,17 +1519,17 @@ function MonitoringCard({ store, snapshot }) {
1493
1519
  min={LIMITS.selfCheckSecondsMin / 60}
1494
1520
  max={LIMITS.selfCheckSecondsMax / 60}
1495
1521
  step={0.5}
1496
- value={String(Number.isFinite(secondsToMinutes(monitoring.selfCheckSeconds)) ? secondsToMinutes(monitoring.selfCheckSeconds) : '')}
1522
+ value={String(Number.isFinite(secondsToMinutes(raw.selfCheckSeconds)) ? secondsToMinutes(raw.selfCheckSeconds) : '')}
1497
1523
  onChange={(event) => {
1498
- const raw = event.target.value;
1499
- edit('selfCheckSeconds', raw === '' ? '' : raw);
1524
+ const value = event.target.value;
1525
+ edit('selfCheckSeconds', value === '' ? '' : value);
1500
1526
  }}
1501
1527
  />
1502
1528
  </Field>
1503
1529
  <Field
1504
1530
  label="提醒你的间隔(分钟)"
1505
1531
  htmlFor="dshdg-monitoring-attention"
1506
- hint={`${LIMITS.attentionSecondsMin / 60}–${LIMITS.attentionSecondsMax / 60} 分钟,且必须大于自检间隔;存成整秒(当前 ${monitoring.attentionSeconds} 秒)`}
1532
+ hint={`${LIMITS.attentionSecondsMin / 60}–${LIMITS.attentionSecondsMax / 60} 分钟,且必须大于自检间隔;存成整秒(当前 ${raw.attentionSeconds === '' ? '未填' : `${raw.attentionSeconds} 秒`})`}
1507
1533
  >
1508
1534
  <input
1509
1535
  id="dshdg-monitoring-attention"
@@ -1512,18 +1538,35 @@ function MonitoringCard({ store, snapshot }) {
1512
1538
  min={LIMITS.attentionSecondsMin / 60}
1513
1539
  max={LIMITS.attentionSecondsMax / 60}
1514
1540
  step={0.5}
1515
- value={String(Number.isFinite(secondsToMinutes(monitoring.attentionSeconds)) ? secondsToMinutes(monitoring.attentionSeconds) : '')}
1541
+ value={String(Number.isFinite(secondsToMinutes(raw.attentionSeconds)) ? secondsToMinutes(raw.attentionSeconds) : '')}
1516
1542
  onChange={(event) => {
1517
- const raw = event.target.value;
1518
- edit('attentionSeconds', raw === '' ? '' : raw);
1543
+ const value = event.target.value;
1544
+ edit('attentionSeconds', value === '' ? '' : value);
1519
1545
  }}
1520
1546
  />
1521
1547
  </Field>
1548
+ <Field
1549
+ label="重复失败提醒(次)"
1550
+ htmlFor="dshdg-monitoring-repeat"
1551
+ hint={`同一工具、同一操作、同一失败连续这么多次时提醒一次;${LIMITS.repeatFailureThresholdMin} 表示关闭(当前 ${raw.repeatFailureThreshold === '' ? '未填' : `${raw.repeatFailureThreshold} 次`})`}
1552
+ >
1553
+ <input
1554
+ id="dshdg-monitoring-repeat"
1555
+ type="number"
1556
+ inputMode="numeric"
1557
+ min={LIMITS.repeatFailureThresholdMin}
1558
+ max={LIMITS.repeatFailureThresholdMax}
1559
+ step={1}
1560
+ value={String(raw.repeatFailureThreshold)}
1561
+ onChange={(event) => { editFailureCount(event.target.value); }}
1562
+ />
1563
+ </Field>
1522
1564
  </div>
1523
1565
  {problems.length === 0 ? null : <p className="dshdg-fail">{problems.join(';')}</p>}
1524
1566
  <ul className="dshdg-hint">
1525
1567
  <li>「没有新进展」本身不等于失败:插件不会因为安静、也不会因为单个工具跑得久就判定任务失败。</li>
1526
1568
  <li>只有确实没有进展、并且超过「提醒你的间隔」之后,才会把这件事报告给派工方。</li>
1569
+ <li>重复失败提醒与上面两个间隔<strong>互相独立</strong>:它数的是同一操作连续失败了几次,而不是安静了多久,所以正在忙碌地反复失败也会被提醒。它只提醒一次,不会自动取消任务、更换模型或改动超时。</li>
1527
1570
  <li>修改只影响<strong>之后新提交</strong>的任务;已经运行的任务保留它开始时的那份间隔快照。</li>
1528
1571
  <li>程序自检只读取本机已有的事实(任务是否还在、当前阶段、有没有待决定的调用、正在跑哪个工具),不读取代码差异,也不会读取你的文件内容。</li>
1529
1572
  </ul>
@@ -1534,7 +1577,9 @@ function MonitoringCard({ store, snapshot }) {
1534
1577
  onClick={async () => {
1535
1578
  setSaving(true);
1536
1579
  try {
1537
- await store.saveMonitoring(monitoring);
1580
+ // Send exactly what was validated. The button is disabled while
1581
+ // `problems` is non-empty, so this is a well-formed block by construction.
1582
+ await store.saveMonitoring(monitoringDraftOf(draft));
1538
1583
  } finally {
1539
1584
  setSaving(false);
1540
1585
  }
@@ -1753,15 +1798,15 @@ function TaskDetail({ store, task }) {
1753
1798
  const permission = permissionSummary(task);
1754
1799
  const pending = pendingPermission(task);
1755
1800
  const evidence = Array.isArray(task.permission?.evidence) ? task.permission.evidence : [];
1756
- const badgeTone = isAwaitingPermission(task)
1757
- ? 'warn'
1758
- : (task.state === 'awaiting-host-review' ? 'warn' : (task.state === 'failed' ? 'warn' : 'off'));
1801
+ // The detail header uses the SAME headline as the list, so a task that was reviewed
1802
+ // never still says "等待宿主审查" here while the list says "审查通过".
1803
+ const badgeTone = isAwaitingPermission(task) ? 'warn' : outcome.tone;
1759
1804
  return (
1760
1805
  <div className="dshdg-item">
1761
1806
  <div className="dshdg-item-head">
1762
1807
  <strong>{task.title || task.taskId}</strong>
1763
1808
  <Badge tone={badgeTone}>
1764
- {taskStateLabel(task.state)}
1809
+ {outcome.label}
1765
1810
  </Badge>
1766
1811
  {isAwaitingPermission(task) ? <Badge tone="warn">{PERMISSION_STATE_LABELS.pending}</Badge> : null}
1767
1812
  <span className="dshdg-spacer" />
@@ -1804,7 +1849,11 @@ function TaskDetail({ store, task }) {
1804
1849
  : `新开 · 工作区 ${execution.conversation.workspaceId ?? '—'}`)}
1805
1850
  </dd>
1806
1851
  <dt>阶段</dt>
1807
- <dd>{taskPhaseLabel(task.phase)}</dd>
1852
+ <dd>
1853
+ {/* A finished/reviewed run never says "waiting for host review" here: that is the
1854
+ headline's job. What remains true is that the execution is over. */}
1855
+ {outcome.decided || task.state === 'awaiting-host-review' ? '执行已结束' : taskPhaseLabel(task.phase)}
1856
+ </dd>
1808
1857
  <dt>最近进展</dt>
1809
1858
  <dd>
1810
1859
  {activity === null || activity.lastActivityAt === null
@@ -1830,6 +1879,8 @@ function TaskDetail({ store, task }) {
1830
1879
  ? '未采集到'
1831
1880
  : `自检 ${formatDuration(activity.selfCheckSeconds * 1000)} · 提醒 ${formatDuration((activity.attentionSeconds ?? 0) * 1000)}`}
1832
1881
  </dd>
1882
+ <dt>重复失败提醒</dt>
1883
+ <dd>{repeatFailureLine(activity)}</dd>
1833
1884
  <dt>创建</dt>
1834
1885
  <dd>{formatTime(task.createdAt)}</dd>
1835
1886
  <dt>结束</dt>
@@ -1844,7 +1895,7 @@ function TaskDetail({ store, task }) {
1844
1895
  : ` · ${REVIEW_VERDICT_LABELS[review.verdict] ?? review.verdict}`}
1845
1896
  </dd>
1846
1897
  <dt>宿主验收</dt>
1847
- <dd>{task.hostAcceptance === null || task.hostAcceptance === undefined ? '未记录(插件不会自行验收)' : '已由宿主记录'}</dd>
1898
+ <dd>{hostReviewLine(task, formatTime)}</dd>
1848
1899
  </dl>
1849
1900
 
1850
1901
  <h4>改动文件</h4>
@@ -2019,16 +2070,20 @@ function TasksPanel({ store, snapshot }) {
2019
2070
  <div className="dshdg-list">
2020
2071
  {tasks.map((task) => {
2021
2072
  const progress = taskProgress(task);
2073
+ // The ONE headline for this task: it already reflects a recorded review, so
2074
+ // the raw state label can never sit next to a "审查通过" badge contradicting it.
2075
+ const outcome = taskOutcome(task);
2076
+ // Only a phase that says something DIFFERENT is shown (a live run); a finished
2077
+ // or reviewed task would otherwise repeat its own headline.
2078
+ const phase = outcome.phaseLabel;
2022
2079
  return (
2023
2080
  <div className="dshdg-item" key={task.taskId}>
2024
2081
  <div className="dshdg-item-head">
2025
2082
  <span>{task.title || task.taskId}</span>
2026
- <Badge tone={isAwaitingPermission(task)
2027
- ? 'warn'
2028
- : (task.state === 'awaiting-host-review' ? 'warn' : (task.state === 'failed' ? 'warn' : 'off'))}>
2029
- {taskStateLabel(task.state)}
2083
+ <Badge tone={isAwaitingPermission(task) ? 'warn' : outcome.tone}>
2084
+ {outcome.label}
2030
2085
  </Badge>
2031
- <Badge tone={progress.tone}>{taskPhaseLabel(task.phase)}</Badge>
2086
+ {phase === null ? null : <Badge tone={progress.tone}>{phase}</Badge>}
2032
2087
  {isAwaitingPermission(task) ? <Badge tone="warn">{PERMISSION_STATE_LABELS.pending}</Badge> : null}
2033
2088
  <span className="dshdg-mono dshdg-faint">
2034
2089
  {task.config?.worker?.model ?? task.effective?.worker?.model ?? '—'}
@@ -94,7 +94,7 @@ import {
94
94
  } from './toml.js';
95
95
 
96
96
  /** Agent file name inside `$CODEX_HOME/agents`. */
97
- export const AGENT_FILENAME = 'dsh-taskbridge.toml';
97
+ export const AGENT_FILENAME = 'dsh-taskbridge.toml';
98
98
  export const LEGACY_AGENT_FILENAME = 'dsh-delegate.toml';
99
99
 
100
100
  /** MCP server entry name inside Codex's `mcp_servers` table. */
@@ -127,8 +127,8 @@ export const CODEX_ACTIONS = Object.freeze(['status', 'install', 'repair', 'remo
127
127
  * historical release in the product data.
128
128
  * @type {Array<{ version: string, sha256: string }>}
129
129
  */
130
- export const KNOWN_AGENT_TEMPLATES = [
131
- { version: '1.3.1', sha256: '2793b656be4a1906e16edfdd0103540bfad05681a413c166b578b02333ea2618' },
130
+ export const KNOWN_AGENT_TEMPLATES = [
131
+ { version: '1.3.1', sha256: '2793b656be4a1906e16edfdd0103540bfad05681a413c166b578b02333ea2618' },
132
132
  { version: '1.3.1', sha256: 'b48558d6d6acca58b94a01029d6c884c4789488c7926cdaca40cb6cd15eea2ae' },
133
133
  {
134
134
  version: '0.1.6',
@@ -308,9 +308,34 @@ export const KNOWN_AGENT_TEMPLATES = [
308
308
  version: '1.1.0',
309
309
  sha256: '93d580bd849bb6d2c30c2db6286695ef3e0356896a88e552abae5f03eafc7601',
310
310
  },
311
- // Exact published 1.3.0 bytes (archive fixture, LF and CRLF forms).
312
- { version: '1.3.0', sha256: '63695008f53aa2c19a0df9e2cb37285f631b775cb98f26c1d280cfbc54a0d9e8' },
313
- { version: '1.3.0', sha256: '31b0ba3149032058fe31e1e884e5c24a9a3d6459b7dd35df6420c7f3756d6257' },
311
+ // Exact published 1.3.0 bytes (archive fixture, LF and CRLF forms).
312
+ { version: '1.3.0', sha256: '63695008f53aa2c19a0df9e2cb37285f631b775cb98f26c1d280cfbc54a0d9e8' },
313
+ { version: '1.3.0', sha256: '31b0ba3149032058fe31e1e884e5c24a9a3d6459b7dd35df6420c7f3756d6257' },
314
+ // The published 1.3.2 companion — the file an existing 1.3.2 installation holds.
315
+ // The instruction body changed again in this release, so it is a DISTINCT published
316
+ // build: without these identities every existing 1.3.2 install would be reported
317
+ // `modified` ("somebody else's file") and never refreshed by startup or by install.
318
+ //
319
+ // Three exact byte identities, because three byte forms really exist on disk:
320
+ //
321
+ // * `46b5b98a…` — the PUBLISHED file itself, preserved byte for byte as
322
+ // `tests/fixtures/codex-agent-1.3.2.toml` (18380 bytes). It is a MIXED form, not a
323
+ // uniform one: most lines end CRLF but some end with a bare LF, so hashing it as
324
+ // "the CRLF form" would be wrong. This is what the release shipped, so it is the
325
+ // identity a real installation has.
326
+ // * `da14ba05…` — the same text with every `\r\n` turned into `\n`: the LF form a
327
+ // POSIX checkout writes (18135 bytes).
328
+ // * `055079c5…` — that LF text with every `\n` turned into `\r\n`: the fully uniform
329
+ // CRLF form an editor or a Windows checkout can produce (18382 bytes). It is a
330
+ // genuinely different file from the published bytes above, which is why it needs its
331
+ // own entry.
332
+ //
333
+ // Each is an exact content identity, never a normalized comparison: normalizing would
334
+ // also make an operator-edited file hash to a known value, which is the defect these
335
+ // digests exist to prevent.
336
+ { version: '1.3.2', sha256: '46b5b98a3489b59a9e7e437a100fea6072db6a34c1220496530efdf812117c17' },
337
+ { version: '1.3.2', sha256: 'da14ba0511ca25d9118670ccb2c39c104d7952d110b104c9b157376b330dccfc' },
338
+ { version: '1.3.2', sha256: '055079c5daf6ba44639bfaa1851c9d56b0b06e45b2f22331326117a64f350e6b' },
314
339
  // Exact published 1.2.0 bytes (archive fixture, LF and CRLF forms).
315
340
  { version: '1.2.0', sha256: '8479c8ab418d71b15fb30880aa5149fb1070d194e8444a110a2a614cebf4eaf4' },
316
341
  { version: '1.2.0', sha256: '947f3fb8a8e9ae5cc6fb3c9d379c69b595af4c46f89ac77f69aa1edf696a8f8e' },
@@ -79,6 +79,11 @@ export const LIMITS = Object.freeze({
79
79
  selfCheckSecondsMax: 60 * 60,
80
80
  attentionSecondsMin: 31,
81
81
  attentionSecondsMax: 2 * 60 * 60,
82
+ // Repeated-failure reminder. `0` disables it, so the minimum is a switch rather
83
+ // than an error; the ceiling keeps a silly value from being indistinguishable from
84
+ // "off" in practice. This is a COUNT, not a duration.
85
+ repeatFailureThresholdMin: 0,
86
+ repeatFailureThresholdMax: 20,
82
87
  promptChars: 200_000,
83
88
  reviewPromptChars: 400_000,
84
89
  });
@@ -95,6 +100,13 @@ export const MONITORING_DEFAULTS = Object.freeze({
95
100
  selfCheckSeconds: 300,
96
101
  /** Idle span after which the wait reports `attention` instead of `heartbeat`. */
97
102
  attentionSeconds: 600,
103
+ /**
104
+ * How many CONSECUTIVE identical tool failures are reported once, or `0` to disable.
105
+ *
106
+ * Independent of the two silence thresholds: a run can be busy and still be failing
107
+ * the same way, which is the case this exists for.
108
+ */
109
+ repeatFailureThreshold: 3,
98
110
  });
99
111
 
100
112
  /**
@@ -166,15 +166,16 @@ export function resolveEffectiveConfig(settings, { projectPath = null, overrides
166
166
  // snapshot therefore carries the rule rather than a stored mode, so a task
167
167
  // record states what the plugin will do instead of echoing a retired setting.
168
168
  conversation: { policy: CONVERSATION_POLICY },
169
- // The silence thresholds this task runs under, FROZEN at admission. They are
170
- // global-only (no project or per-job layer): an operator edits them rarely, and
171
- // a per-job override would let one submission ask to be watched on a different
172
- // clock than the alert thresholds the operator actually set. Freezing them here
173
- // is what makes an edit during a live run apply to the NEXT task instead of
174
- // silently retiming one already in flight.
169
+ // The silence thresholds and the repeated-failure count this task runs under,
170
+ // FROZEN at admission. They are global-only (no project or per-job layer): an
171
+ // operator edits them rarely, and a per-job override would let one submission ask
172
+ // to be watched on a different clock than the alert thresholds the operator
173
+ // actually set. Freezing them here is what makes an edit during a live run apply to
174
+ // the NEXT task instead of silently retiming one already in flight.
175
175
  monitoring: {
176
176
  selfCheckSeconds: settings.monitoring.selfCheckSeconds,
177
177
  attentionSeconds: settings.monitoring.attentionSeconds,
178
+ repeatFailureThreshold: settings.monitoring.repeatFailureThreshold,
178
179
  },
179
180
  provenance: {
180
181
  // Canonical, not the caller's spelling: a recorded snapshot must compare
@@ -532,14 +533,15 @@ export class SettingsService {
532
533
  * Replace the activity-monitoring block.
533
534
  *
534
535
  * This is the mutator a later authenticated UI endpoint calls; it is the only
535
- * write path for these two thresholds, so the bounds and the ordering rule live
536
- * in exactly one place ({@link validateMonitoringSettings}) and no caller can
537
- * persist a pair the monitor would refuse to run.
536
+ * write path for these thresholds and for the repeated-failure count, so the
537
+ * bounds and the ordering rule live in exactly one place
538
+ * ({@link validateMonitoringSettings}) and no caller can persist a block the
539
+ * monitor would refuse to run.
538
540
  *
539
541
  * The write goes through the same serialized queue as every other settings
540
542
  * mutation, so it cannot lose a concurrent edit and a fresh task admitted after
541
543
  * it freezes the new values. A task already running keeps the snapshot it froze.
542
- * @param {unknown} candidate - `{ selfCheckSeconds, attentionSeconds }`.
544
+ * @param {unknown} candidate - `{ selfCheckSeconds, attentionSeconds, repeatFailureThreshold }`.
543
545
  * @returns {Promise<object>} committed settings.
544
546
  */
545
547
  async setMonitoring(candidate) {
@@ -423,7 +423,7 @@ export function validateReviewSettings(value, providers) {
423
423
  /**
424
424
  * Validate the activity-monitoring block.
425
425
  *
426
- * Two silence thresholds, both in whole seconds, both bounded:
426
+ * Two silence thresholds and one failure-count threshold:
427
427
  *
428
428
  * * `selfCheckSeconds` is when the engine performs ONE read-only local
429
429
  * inspection of the executor it already holds (alive, phase, pending request,
@@ -431,33 +431,39 @@ export function validateReviewSettings(value, providers) {
431
431
  * call and never touches the task's state, budget or deadline.
432
432
  * * `attentionSeconds` is when a wait stops keeping quiet and reports
433
433
  * `attention` to the commander instead of `heartbeat`.
434
+ * * `repeatFailureThreshold` is how many CONSECUTIVE identical tool failures are
435
+ * reported once, or `0` to switch that reminder off. It is a count, so it is
436
+ * independent of the two silence thresholds: a busy run that keeps failing the
437
+ * same way never reaches either of them.
434
438
  *
435
439
  * A missing block is the documented default (backwards compatible: documents
436
- * written before this field existed keep loading). Everything else is refused
437
- * rather than repaired — an unknown key (a typo such as `atentionSeconds` would
438
- * otherwise silently keep the default), a wrong type, a non-integer, an
440
+ * written before this field existed keep loading, and a document that has the other
441
+ * two but not this one gets the default rather than an error). Everything else is
442
+ * refused rather than repaired — an unknown key (a typo such as `atentionSeconds`
443
+ * would otherwise silently keep the default), a wrong type, a non-integer, an
439
444
  * out-of-range value, and any pair where the attention threshold is not strictly
440
- * greater than the self-check one. A repaired value would make the two timers
441
- * disagree with what the operator stored, which is exactly the class of silent
442
- * mismatch this plugin refuses everywhere else.
445
+ * greater than the self-check one. A repaired value would make the timers disagree
446
+ * with what the operator stored, which is exactly the class of silent mismatch this
447
+ * plugin refuses everywhere else.
443
448
  * @param {unknown} value - candidate monitoring block.
444
- * @returns {{ selfCheckSeconds: number, attentionSeconds: number }} normalized block.
449
+ * @returns {{ selfCheckSeconds: number, attentionSeconds: number, repeatFailureThreshold: number }} normalized block.
445
450
  */
446
451
  export function validateMonitoringSettings(value) {
447
452
  if (value === undefined || value === null) {
448
453
  return {
449
454
  selfCheckSeconds: MONITORING_DEFAULTS.selfCheckSeconds,
450
455
  attentionSeconds: MONITORING_DEFAULTS.attentionSeconds,
456
+ repeatFailureThreshold: MONITORING_DEFAULTS.repeatFailureThreshold,
451
457
  };
452
458
  }
453
459
  if (typeof value !== 'object' || Array.isArray(value)) {
454
460
  throw new ConfigError('MONITORING_INVALID', 'monitoring settings must be an object', { field: 'monitoring' });
455
461
  }
456
462
  for (const key of Object.keys(value)) {
457
- if (key !== 'selfCheckSeconds' && key !== 'attentionSeconds') {
463
+ if (key !== 'selfCheckSeconds' && key !== 'attentionSeconds' && key !== 'repeatFailureThreshold') {
458
464
  throw new ConfigError('MONITORING_INVALID', `monitoring setting ${key} is not supported`, {
459
465
  field: `monitoring.${key}`,
460
- supported: ['selfCheckSeconds', 'attentionSeconds'],
466
+ supported: ['selfCheckSeconds', 'attentionSeconds', 'repeatFailureThreshold'],
461
467
  });
462
468
  }
463
469
  }
@@ -482,7 +488,16 @@ export function validateMonitoringSettings(value) {
482
488
  { field: 'monitoring.attentionSeconds', selfCheckSeconds, attentionSeconds },
483
489
  );
484
490
  }
485
- return { selfCheckSeconds, attentionSeconds };
491
+ const repeatFailureThreshold = requireInt(
492
+ value.repeatFailureThreshold === undefined
493
+ ? MONITORING_DEFAULTS.repeatFailureThreshold
494
+ : value.repeatFailureThreshold,
495
+ 'MONITORING_INVALID',
496
+ 'monitoring.repeatFailureThreshold',
497
+ LIMITS.repeatFailureThresholdMin,
498
+ LIMITS.repeatFailureThresholdMax,
499
+ );
500
+ return { selfCheckSeconds, attentionSeconds, repeatFailureThreshold };
486
501
  }
487
502
 
488
503
  /** Validate legacy grant TTLs kept for backwards-compatible imports. */
@@ -64,6 +64,13 @@ export function createExecutionHandler(deps) {
64
64
  // The switch gate below applies to it exactly as it does to a submission,
65
65
  // because a decision is an authorization exercise like any other.
66
66
  ['POST /tasks/permission', decidePermission],
67
+ // The commander's DELIVERY REVIEW of one finished task. It is the only write that
68
+ // records `hostAcceptance`, and it is narrow on purpose: it decides no permission,
69
+ // changes no switch/provider/model/isolation/credential, merges no file and creates
70
+ // no task. Because it only records a conclusion about a result that already exists, it
71
+ // is NOT gated by the delegation switch — like `/tasks/get` and `/tasks/cancel`, it
72
+ // stays answerable with the switch off.
73
+ ['POST /tasks/review', recordHostReview],
67
74
  // Read-only workspace inspection for a dispatcher: the facts and the isolation
68
75
  // recommendation that used to be discovered only when a job admitted. It is a
69
76
  // separate route — not a field on `/tasks` — because it neither authorizes nor
@@ -109,10 +116,11 @@ export function createExecutionHandler(deps) {
109
116
 
110
117
  let connection;
111
118
  if (deps.engine.authorizationMode === 'switch') {
112
- // Both AUTHORIZING verbs need the switch: a submission creates work and a
113
- // decision releases a paused call. Reads, cancel and preflight stay
114
- // answerable while the switch is off, so an operator can always observe and
115
- // stop what already exists.
119
+ // Only the two AUTHORIZING verbs need the switch: a submission creates work and a
120
+ // decision releases a paused call. A delivery REVIEW is not one of them: it records
121
+ // a conclusion about an already-finished result, so it stays answerable with the
122
+ // switch off, exactly like reading or cancelling a task. Reads, cancel and
123
+ // preflight are equally unaffected.
116
124
  const gated = key === 'POST /tasks' || key === 'POST /tasks/permission';
117
125
  if (gated && deps.engine.posture().authorized !== true) {
118
126
  sendJson(res, 403, {
@@ -313,6 +321,52 @@ async function decidePermission({ req, res, connection, deps }) {
313
321
  sendJson(res, 200, { ok: true, ...result });
314
322
  }
315
323
 
324
+ /** Body fields `POST /tasks/review` accepts. Everything else is refused. */
325
+ const REVIEW_FIELDS = Object.freeze(['taskId', 'decision', 'note']);
326
+
327
+ /** Longest review note the route will even read, in characters. */
328
+ const REVIEW_NOTE_MAX_CHARS = 1_000;
329
+
330
+ /**
331
+ * Record the commander's delivery review of one finished task.
332
+ *
333
+ * The body is validated here as well as in the engine and in the MCP server, because this
334
+ * route is reachable by any local caller: a closed field set, a closed decision vocabulary
335
+ * and a bounded non-empty note are refused before anything is read or written. The
336
+ * connection identity is taken from the authenticated request, never from the body, so a
337
+ * caller can only review its OWN task.
338
+ * @param {object} context - `req`, `res`, `connection`, `deps`.
339
+ * @returns {Promise<void>} resolves after the answer is sent.
340
+ */
341
+ async function recordHostReview({ req, res, connection, deps }) {
342
+ const body = await readJsonBody(req);
343
+ for (const key of Object.keys(body)) {
344
+ if (!REVIEW_FIELDS.includes(key)) {
345
+ throw new HttpError(400, 'REVIEW_ARGUMENT_UNKNOWN', `tasks/review does not accept ${JSON.stringify(key)}`);
346
+ }
347
+ }
348
+ if (typeof body.taskId !== 'string' || body.taskId.trim() === '') {
349
+ throw new HttpError(400, 'TASK_ID_REQUIRED', 'taskId is required');
350
+ }
351
+ if (body.decision !== 'accepted' && body.decision !== 'changes-requested') {
352
+ throw new HttpError(400, 'REVIEW_DECISION_INVALID', 'decision must be accepted or changes-requested');
353
+ }
354
+ if (typeof body.note !== 'string' || body.note.trim() === '') {
355
+ throw new HttpError(400, 'REVIEW_NOTE_REQUIRED', 'note must be a non-empty string');
356
+ }
357
+ if (body.note.trim().length > REVIEW_NOTE_MAX_CHARS) {
358
+ throw new HttpError(400, 'REVIEW_NOTE_TOO_LONG', `note must be at most ${REVIEW_NOTE_MAX_CHARS} characters`);
359
+ }
360
+ const result = await deps.engine.recordHostReview({
361
+ // The verified connection, not `body.connectionId`: a caller cannot name an owner.
362
+ connectionId: connection.connectionId,
363
+ taskId: body.taskId,
364
+ decision: body.decision,
365
+ note: body.note,
366
+ });
367
+ sendJson(res, 200, { ok: true, ...result });
368
+ }
369
+
316
370
  /**
317
371
  * Report a bounded observation of one task of this connection.
318
372
  *