dsh-taskbridge 1.6.0 → 1.7.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.
- package/CHANGELOG.md +10 -1
- package/README.md +41 -41
- package/THIRD_PARTY_NOTICES.txt +23 -0
- package/codex/dsh-taskbridge.toml +140 -71
- package/docs/INTRODUCTION.md +44 -22
- package/docs/INTRODUCTION.zh.md +32 -26
- package/docs/codex-integration.md +90 -10
- package/docs/contracts-stage-b.md +4 -4
- package/docs/conversation-placement.md +25 -7
- package/docs/plugin-market.md +1 -1
- package/docs/releases/1.7.0.zh.md +11 -0
- package/docs/runtime-compatibility.md +4 -11
- package/docs/silent-wait.md +69 -31
- package/docs/taskbridge-upgrade.md +1 -1
- package/docs/worker-permissions.md +4 -14
- package/docs/workspace-grouping.md +126 -0
- package/lib/client.d.ts +365 -3
- package/lib/client.js +260 -5
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +7 -19
- package/src/client/api.js +550 -90
- package/src/client/index.jsx +699 -307
- package/src/client/sidebar.jsx +6 -5
- package/src/client/styles.js +251 -0
- package/src/client/task-cleanup.js +304 -0
- package/src/client/task-records-table.jsx +217 -0
- package/src/client/task-view.js +226 -10
- package/src/client/workspace-groups.js +482 -0
- package/src/client/workspaces-browser.jsx +770 -0
- package/src/codex/agent-ownership.js +270 -0
- package/src/codex/installer.js +525 -35
- package/src/codex/seam.js +5 -0
- package/src/config/defaults.js +63 -17
- package/src/config/settings.js +60 -62
- package/src/config/validate.js +126 -71
- package/src/http/respond.js +8 -0
- package/src/http/user-plane.js +197 -2
- package/src/index.js +50 -42
- package/src/jobs/activity.js +968 -78
- package/src/jobs/engine.js +784 -230
- package/src/jobs/history.js +188 -12
- package/src/jobs/plan-store.js +5 -0
- package/src/jobs/record-cleanup.js +196 -0
- package/src/jobs/task-tree.js +5 -3
- package/src/jobs/title.js +129 -12
- package/src/mcp/server.js +16 -8
- package/src/mcp/wait.js +64 -5
- package/src/runtime/agent-runner.js +53 -15
- package/src/runtime/worker-prompt.js +53 -0
- package/src/workspace/locks.js +288 -167
- package/docs/releases/1.4.0-token-benchmark.zh.md +0 -40
- package/docs/releases/1.4.0.zh.md +0 -54
- package/docs/releases/1.4.1.zh.md +0 -59
- package/docs/releases/1.4.2.zh.md +0 -23
- package/docs/releases/1.5.0-token-benchmark.zh.md +0 -73
- package/docs/releases/1.5.0.zh.md +0 -51
- package/docs/releases/1.5.1.zh.md +0 -70
- package/docs/releases/1.5.2.zh.md +0 -30
- package/docs/releases/1.5.3-test.1.zh.md +0 -28
- package/docs/releases/1.5.3-test.2.zh.md +0 -24
- package/docs/releases/1.5.3.zh.md +0 -33
- package/docs/releases/1.5.4.zh.md +0 -25
- package/src/review/preset.js +0 -868
- package/src/review/prompts.js +0 -145
- package/src/review/reviewer.js +0 -933
package/src/config/validate.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { posix, win32 } from 'node:path';
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
+
DEFAULT_AGENT_TEAMS_FOR_NEW_TASKS,
|
|
12
13
|
DEFAULT_ISOLATION,
|
|
13
14
|
EFFORT_ORDER,
|
|
14
15
|
ISOLATION_MODES,
|
|
@@ -356,6 +357,26 @@ function validateIsolation(value, code, field) {
|
|
|
356
357
|
return isolation;
|
|
357
358
|
}
|
|
358
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Normalize the LEGACY `worker.timeoutSeconds` value.
|
|
362
|
+
*
|
|
363
|
+
* The field is retired as a knob — the settings page no longer offers it and an
|
|
364
|
+
* ordinary run is not bounded by it — but a stored document that carries one must
|
|
365
|
+
* still open. The rule is therefore "read it, never refuse it": a whole number
|
|
366
|
+
* inside the documented bounds is preserved (so a reader can still see what the
|
|
367
|
+
* old document said), and anything else — out of range, fractional, textual, a
|
|
368
|
+
* negative number — falls back to the documented default. Nothing is clamped into
|
|
369
|
+
* a different number nobody chose, and nothing here can make a task fail to start.
|
|
370
|
+
* @param {unknown} value - stored legacy value.
|
|
371
|
+
* @returns {number} a whole number of seconds inside the documented bounds.
|
|
372
|
+
*/
|
|
373
|
+
export function legacyTimeoutSeconds(value) {
|
|
374
|
+
const candidate = typeof value === 'number' ? value : (typeof value === 'string' && value.trim() !== '' ? Number(value) : Number.NaN);
|
|
375
|
+
if (!Number.isSafeInteger(candidate)) return 1800;
|
|
376
|
+
if (candidate < LIMITS.timeoutSecondsMin || candidate > LIMITS.timeoutSecondsMax) return 1800;
|
|
377
|
+
return candidate;
|
|
378
|
+
}
|
|
379
|
+
|
|
359
380
|
/**
|
|
360
381
|
* Validate the worker execution settings block.
|
|
361
382
|
* @param {unknown} value - candidate worker block.
|
|
@@ -368,13 +389,13 @@ export function validateWorkerSettings(value, providers) {
|
|
|
368
389
|
throw new ConfigError('WORKER_INVALID', 'worker settings must be an object', {});
|
|
369
390
|
}
|
|
370
391
|
const selection = validateSelection(source, providers, 'worker');
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
);
|
|
392
|
+
// `timeoutSeconds` is a LEGACY field: it is no longer offered in the settings
|
|
393
|
+
// page and no longer bounds an ordinary run, but a document written by an older
|
|
394
|
+
// build (or an older client that still sends it) must keep loading. So the value
|
|
395
|
+
// is READ AND NORMALIZED, never refused: an out-of-range, fractional or
|
|
396
|
+
// non-numeric legacy value falls back to the documented default instead of
|
|
397
|
+
// failing the whole document, and the run is not limited by it either way.
|
|
398
|
+
const timeoutSeconds = legacyTimeoutSeconds(source.timeoutSeconds);
|
|
378
399
|
const maxParallelism = requireInt(
|
|
379
400
|
source.maxParallelism ?? 1,
|
|
380
401
|
'WORKER_PARALLELISM_INVALID',
|
|
@@ -395,56 +416,40 @@ export function validateWorkerSettings(value, providers) {
|
|
|
395
416
|
};
|
|
396
417
|
}
|
|
397
418
|
|
|
398
|
-
/**
|
|
399
|
-
* Validate the additional-review block. Review is off unless explicitly enabled
|
|
400
|
-
* and it owns a fully separate provider/model/effort triple.
|
|
401
|
-
* @param {unknown} value - candidate review block.
|
|
402
|
-
* @param {object[]} providers - validated providers.
|
|
403
|
-
* @returns {object} normalized review block.
|
|
404
|
-
*/
|
|
405
|
-
export function validateReviewSettings(value, providers) {
|
|
406
|
-
const source = value ?? {};
|
|
407
|
-
if (typeof source !== 'object' || Array.isArray(source)) {
|
|
408
|
-
throw new ConfigError('REVIEW_INVALID', 'review settings must be an object', {});
|
|
409
|
-
}
|
|
410
|
-
const enabled = requireBool(source.enabled ?? false, 'REVIEW_INVALID', 'review.enabled');
|
|
411
|
-
if (!enabled) {
|
|
412
|
-
return { enabled: false, providerId: null, model: null, reasoningEffort: null };
|
|
413
|
-
}
|
|
414
|
-
const selection = validateSelection(source, providers, 'review');
|
|
415
|
-
return {
|
|
416
|
-
enabled: true,
|
|
417
|
-
providerId: selection.providerId,
|
|
418
|
-
model: selection.model,
|
|
419
|
-
reasoningEffort: selection.reasoningEffort,
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
|
|
423
419
|
/**
|
|
424
420
|
* Validate the activity-monitoring block.
|
|
425
421
|
*
|
|
426
|
-
* Two
|
|
422
|
+
* Two no-progress thresholds and one failure-count threshold. Each is INDEPENDENT and
|
|
423
|
+
* each can be switched off with `0`. There is exactly ONE time base — consecutive time
|
|
424
|
+
* without real progress — and nothing here depends on total runtime:
|
|
427
425
|
*
|
|
428
426
|
* * `selfCheckSeconds` is when the engine performs ONE read-only local
|
|
429
427
|
* inspection of the executor it already holds (alive, phase, pending request,
|
|
430
428
|
* current tool) and reports it on an internal re-wait. It never starts an LLM
|
|
431
|
-
* call and never touches the task's state, budget or deadline.
|
|
432
|
-
* * `attentionSeconds` is when a wait stops keeping quiet and reports
|
|
433
|
-
*
|
|
429
|
+
* call and never touches the task's state, budget or deadline. Default 10 min.
|
|
430
|
+
* * `attentionSeconds` is when a wait stops keeping quiet and reports ONE run
|
|
431
|
+
* progress check to the commander — `reason: "attention"` with
|
|
432
|
+
* `checkpoint: "progress"` — instead of `heartbeat`. It is a report, never an
|
|
433
|
+
* action: the run is not cancelled, restarted or resubmitted. Default 40 min.
|
|
434
434
|
* * `repeatFailureThreshold` is how many CONSECUTIVE identical tool failures are
|
|
435
435
|
* reported once, or `0` to switch that reminder off. It is a count, so it is
|
|
436
|
-
* independent of the two
|
|
436
|
+
* independent of the two duration thresholds: a busy run that keeps failing the
|
|
437
437
|
* same way never reaches either of them.
|
|
438
438
|
*
|
|
439
439
|
* A missing block is the documented default (backwards compatible: documents
|
|
440
440
|
* written before this field existed keep loading, and a document that has the other
|
|
441
|
-
*
|
|
442
|
-
* refused rather than repaired — an unknown key (a typo such as
|
|
443
|
-
* would otherwise silently keep the default), a wrong type, a
|
|
444
|
-
* out-of-range value, and any pair where
|
|
445
|
-
*
|
|
446
|
-
* with what the operator stored, which is exactly the class of
|
|
447
|
-
* plugin refuses everywhere else.
|
|
441
|
+
* keys but not one of them gets that key's default rather than an error). Everything
|
|
442
|
+
* else is refused rather than repaired — an unknown key (a typo such as
|
|
443
|
+
* `atentionSeconds` would otherwise silently keep the default), a wrong type, a
|
|
444
|
+
* non-integer, an out-of-range value, and any pair where BOTH thresholds are enabled
|
|
445
|
+
* and the progress check is not strictly after the self-check. A repaired value would make
|
|
446
|
+
* the timers disagree with what the operator stored, which is exactly the class of
|
|
447
|
+
* silent mismatch this plugin refuses everywhere else.
|
|
448
|
+
*
|
|
449
|
+
* A stored document that still carries a value the earlier build offered as its own
|
|
450
|
+
* progress cadence is READ AND DROPPED rather than refused: that value was never
|
|
451
|
+
* published, it is not a second clock, and refusing the document would make an
|
|
452
|
+
* operator's settings unreadable over a field no longer shown anywhere.
|
|
448
453
|
* @param {unknown} value - candidate monitoring block.
|
|
449
454
|
* @returns {{ selfCheckSeconds: number, attentionSeconds: number, repeatFailureThreshold: number }} normalized block.
|
|
450
455
|
*/
|
|
@@ -460,6 +465,7 @@ export function validateMonitoringSettings(value) {
|
|
|
460
465
|
throw new ConfigError('MONITORING_INVALID', 'monitoring settings must be an object', { field: 'monitoring' });
|
|
461
466
|
}
|
|
462
467
|
for (const key of Object.keys(value)) {
|
|
468
|
+
if (key === 'progressCheckSeconds') continue;
|
|
463
469
|
if (key !== 'selfCheckSeconds' && key !== 'attentionSeconds' && key !== 'repeatFailureThreshold') {
|
|
464
470
|
throw new ConfigError('MONITORING_INVALID', `monitoring setting ${key} is not supported`, {
|
|
465
471
|
field: `monitoring.${key}`,
|
|
@@ -481,10 +487,12 @@ export function validateMonitoringSettings(value) {
|
|
|
481
487
|
LIMITS.attentionSecondsMin,
|
|
482
488
|
LIMITS.attentionSecondsMax,
|
|
483
489
|
);
|
|
484
|
-
|
|
490
|
+
// Ordering matters only when BOTH reminders are on. A disabled threshold has no
|
|
491
|
+
// instant of its own, so `0` can never be "too early" for the other one.
|
|
492
|
+
if (selfCheckSeconds > 0 && attentionSeconds > 0 && attentionSeconds <= selfCheckSeconds) {
|
|
485
493
|
throw new ConfigError(
|
|
486
494
|
'MONITORING_TIMING_INVALID',
|
|
487
|
-
'monitoring.attentionSeconds must be greater than monitoring.selfCheckSeconds',
|
|
495
|
+
'monitoring.attentionSeconds must be greater than monitoring.selfCheckSeconds when both are enabled',
|
|
488
496
|
{ field: 'monitoring.attentionSeconds', selfCheckSeconds, attentionSeconds },
|
|
489
497
|
);
|
|
490
498
|
}
|
|
@@ -500,8 +508,53 @@ export function validateMonitoringSettings(value) {
|
|
|
500
508
|
return { selfCheckSeconds, attentionSeconds, repeatFailureThreshold };
|
|
501
509
|
}
|
|
502
510
|
|
|
503
|
-
/**
|
|
504
|
-
|
|
511
|
+
/**
|
|
512
|
+
* Validate the operator's execution-choice block.
|
|
513
|
+
*
|
|
514
|
+
* Today it holds exactly one decision: whether a new delegated task should have
|
|
515
|
+
* DSH Agent Teams on when its dispatcher states no per-task choice. The rules:
|
|
516
|
+
*
|
|
517
|
+
* * the block is optional — a document written before it existed, and a host
|
|
518
|
+
* that never served one, both load at the documented OFF default, so an
|
|
519
|
+
* upgrade can never turn collaboration on by itself;
|
|
520
|
+
* * the value must be a real boolean. `"false"`, `0` and `null` are REFUSED
|
|
521
|
+
* rather than coerced: a value that reads as "off" to a reader but is not a
|
|
522
|
+
* boolean would be stored as an intention nobody can honour;
|
|
523
|
+
* * an unknown key is refused, not ignored (a typo such as
|
|
524
|
+
* `agentTeamDefault` would otherwise silently keep the default).
|
|
525
|
+
*
|
|
526
|
+
* The block is a TASK default only. It is not DSH's global switch and nothing
|
|
527
|
+
* here writes a global setting.
|
|
528
|
+
* @param {unknown} value - candidate `execution` block.
|
|
529
|
+
* @returns {{ agentTeamsDefault: boolean }} normalized block.
|
|
530
|
+
*/
|
|
531
|
+
export function validateExecutionSettings(value) {
|
|
532
|
+
if (value === undefined || value === null) {
|
|
533
|
+
return { agentTeamsDefault: DEFAULT_AGENT_TEAMS_FOR_NEW_TASKS };
|
|
534
|
+
}
|
|
535
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
536
|
+
throw new ConfigError('EXECUTION_SETTINGS_INVALID', 'execution settings must be an object', {
|
|
537
|
+
field: 'execution',
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
for (const key of Object.keys(value)) {
|
|
541
|
+
if (key !== 'agentTeamsDefault') {
|
|
542
|
+
throw new ConfigError('EXECUTION_SETTINGS_INVALID', `execution setting ${key} is not supported`, {
|
|
543
|
+
field: `execution.${key}`,
|
|
544
|
+
supported: ['agentTeamsDefault'],
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
agentTeamsDefault: requireBool(
|
|
550
|
+
value.agentTeamsDefault === undefined ? DEFAULT_AGENT_TEAMS_FOR_NEW_TASKS : value.agentTeamsDefault,
|
|
551
|
+
'EXECUTION_SETTINGS_INVALID',
|
|
552
|
+
'execution.agentTeamsDefault',
|
|
553
|
+
),
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** Validate legacy grant TTLs kept for backwards-compatible imports. */export function validateAuthorizationSettings(value) {
|
|
505
558
|
const source = value ?? {};
|
|
506
559
|
if (typeof source !== 'object' || Array.isArray(source)) {
|
|
507
560
|
throw new ConfigError('AUTHORIZATION_INVALID', 'authorization settings must be an object', {});
|
|
@@ -563,6 +616,11 @@ export function validateJobOverrides(value, providers) {
|
|
|
563
616
|
out.reasoningEffort = null;
|
|
564
617
|
}
|
|
565
618
|
if (value.timeoutSeconds !== undefined) {
|
|
619
|
+
// The ONE compatibility path that still bounds a run: a caller that explicitly
|
|
620
|
+
// asks for a per-job cap gets exactly that cap. It is deliberately not offered
|
|
621
|
+
// in the settings page (a stored global value never bounds a task), so an
|
|
622
|
+
// operator can never inherit an unintended deadline — only a dispatch that
|
|
623
|
+
// names one states it.
|
|
566
624
|
out.timeoutSeconds = requireInt(
|
|
567
625
|
value.timeoutSeconds,
|
|
568
626
|
'WORKER_TIMEOUT_INVALID',
|
|
@@ -589,7 +647,6 @@ export function validateProjectOverride(value, providers) {
|
|
|
589
647
|
}
|
|
590
648
|
const out = {};
|
|
591
649
|
if (value.worker !== undefined) out.worker = validateWorkerSettings(value.worker, providers);
|
|
592
|
-
if (value.review !== undefined) out.review = validateReviewSettings(value.review, providers);
|
|
593
650
|
return out;
|
|
594
651
|
}
|
|
595
652
|
|
|
@@ -655,6 +712,8 @@ export function validateProjectOverrides(value, providers) {
|
|
|
655
712
|
const seen = new Map();
|
|
656
713
|
for (const [projectPath, block] of Object.entries(raw)) {
|
|
657
714
|
const { key, display } = canonicalProjectKey(projectPath, 'projectOverrides key');
|
|
715
|
+
const override = validateProjectOverride(block, providers);
|
|
716
|
+
if (block.review !== undefined && override.worker === undefined) continue;
|
|
658
717
|
const existing = seen.get(key);
|
|
659
718
|
if (existing !== undefined) {
|
|
660
719
|
throw new ConfigError('PROJECT_OVERRIDE_DUPLICATE', 'two project overrides name the same project', {
|
|
@@ -663,18 +722,17 @@ export function validateProjectOverrides(value, providers) {
|
|
|
663
722
|
});
|
|
664
723
|
}
|
|
665
724
|
seen.set(key, display);
|
|
666
|
-
out[display] =
|
|
725
|
+
out[display] = override;
|
|
667
726
|
}
|
|
668
727
|
return out;
|
|
669
728
|
}
|
|
670
729
|
|
|
671
730
|
/**
|
|
672
|
-
* Validate one named preset
|
|
673
|
-
*
|
|
674
|
-
* settings, so a preset can never store a combination that settings would refuse.
|
|
731
|
+
* Validate one named worker preset. Older presets that configured only the
|
|
732
|
+
* retired model review are omitted without validating their unused selection.
|
|
675
733
|
* @param {unknown} value - candidate preset.
|
|
676
734
|
* @param {object[]} providers - validated providers.
|
|
677
|
-
* @returns {{ id: string, name: string, worker: object
|
|
735
|
+
* @returns {{ id: string, name: string, worker: object } | null} normalized preset.
|
|
678
736
|
*/
|
|
679
737
|
export function validatePreset(value, providers) {
|
|
680
738
|
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
@@ -682,15 +740,11 @@ export function validatePreset(value, providers) {
|
|
|
682
740
|
}
|
|
683
741
|
const id = requireString(value.id, 'PRESET_INVALID', 'preset.id', { max: 40, pattern: ID_PATTERN });
|
|
684
742
|
const name = requireString(value.name ?? id, 'PRESET_INVALID', 'preset.name', { max: 80 });
|
|
685
|
-
if (value.worker === undefined
|
|
686
|
-
|
|
743
|
+
if (value.worker === undefined || value.worker === null) {
|
|
744
|
+
if (value.review !== undefined && value.review !== null) return null;
|
|
745
|
+
throw new ConfigError('PRESET_INVALID', 'preset must contain worker settings', { id });
|
|
687
746
|
}
|
|
688
|
-
return {
|
|
689
|
-
id,
|
|
690
|
-
name,
|
|
691
|
-
worker: value.worker === undefined ? null : validateWorkerSettings(value.worker, providers),
|
|
692
|
-
review: value.review === undefined ? null : validateReviewSettings(value.review, providers),
|
|
693
|
-
};
|
|
747
|
+
return { id, name, worker: validateWorkerSettings(value.worker, providers) };
|
|
694
748
|
}
|
|
695
749
|
|
|
696
750
|
/**
|
|
@@ -707,7 +761,7 @@ export function validatePresets(value, providers) {
|
|
|
707
761
|
if (raw.length > LIMITS.presets) {
|
|
708
762
|
throw new ConfigError('PRESET_INVALID', `presets exceeds ${LIMITS.presets} entries`, {});
|
|
709
763
|
}
|
|
710
|
-
const presets = raw.map((entry) => validatePreset(entry, providers));
|
|
764
|
+
const presets = raw.map((entry) => validatePreset(entry, providers)).filter((preset) => preset !== null);
|
|
711
765
|
const seen = new Set();
|
|
712
766
|
for (const preset of presets) {
|
|
713
767
|
if (seen.has(preset.id)) throw new ConfigError('PRESET_DUPLICATE', `duplicate preset id ${preset.id}`, { id: preset.id });
|
|
@@ -724,8 +778,6 @@ export function validatePresets(value, providers) {
|
|
|
724
778
|
function isUnconfiguredSelection(value) {
|
|
725
779
|
if (value === null || value === undefined) return true;
|
|
726
780
|
if (typeof value !== 'object' || Array.isArray(value)) return false;
|
|
727
|
-
const enabled = value.enabled;
|
|
728
|
-
if (enabled === true) return false;
|
|
729
781
|
return (value.providerId ?? null) === null;
|
|
730
782
|
}
|
|
731
783
|
|
|
@@ -752,13 +804,14 @@ export function validateSettings(value, options = {}) {
|
|
|
752
804
|
// fresh install can add its first provider before choosing a worker. It is
|
|
753
805
|
// never legal to RUN: resolveEffectiveConfig refuses it, which keeps the
|
|
754
806
|
// refusal at the job boundary instead of at every settings edit.
|
|
807
|
+
//
|
|
808
|
+
// The default block is used as the BASE, not as a replacement: a legacy document
|
|
809
|
+
// that still carries `worker.timeoutSeconds` must keep that value verbatim even
|
|
810
|
+
// before a provider is chosen, or a settings save would silently rewrite a field
|
|
811
|
+
// nobody touched.
|
|
755
812
|
const worker = isUnconfiguredSelection(value.worker)
|
|
756
|
-
? defaultSettings().worker
|
|
813
|
+
? { ...defaultSettings().worker, timeoutSeconds: legacyTimeoutSeconds(value.worker?.timeoutSeconds) }
|
|
757
814
|
: validateWorkerSettings(value.worker ?? {}, providers);
|
|
758
|
-
const review = isUnconfiguredSelection(value.review)
|
|
759
|
-
? defaultSettings().review
|
|
760
|
-
: validateReviewSettings(value.review ?? {}, providers);
|
|
761
|
-
|
|
762
815
|
if (options.requireProviders === true && providers.length === 0) {
|
|
763
816
|
throw new ConfigError('SETTINGS_NO_PROVIDERS', 'no provider profile is configured', {});
|
|
764
817
|
}
|
|
@@ -768,8 +821,10 @@ export function validateSettings(value, options = {}) {
|
|
|
768
821
|
delegationEnabled: requireBool(value.delegationEnabled ?? false, 'SETTINGS_INVALID', 'delegationEnabled'),
|
|
769
822
|
providers,
|
|
770
823
|
worker,
|
|
771
|
-
review,
|
|
772
824
|
authorization: validateAuthorizationSettings(value.authorization),
|
|
825
|
+
// The operator's default for NEW tasks. An absent block is the documented
|
|
826
|
+
// OFF default, which is also what an upgraded document loads as.
|
|
827
|
+
execution: validateExecutionSettings(value.execution),
|
|
773
828
|
monitoring: validateMonitoringSettings(value.monitoring),
|
|
774
829
|
projectOverrides: validateProjectOverrides(value.projectOverrides, providers),
|
|
775
830
|
presets: validatePresets(value.presets, providers),
|
package/src/http/respond.js
CHANGED
|
@@ -174,6 +174,14 @@ function statusForCode(code) {
|
|
|
174
174
|
return 400;
|
|
175
175
|
}
|
|
176
176
|
if (code.startsWith('PLAN_')) return 409;
|
|
177
|
+
// Task-record cleanup. A batch that cannot be honoured is a state conflict (the
|
|
178
|
+
// operator re-reads and retries), an unusable request is the caller's mistake, a
|
|
179
|
+
// capability the host does not have is 503 and a failed document write is 502.
|
|
180
|
+
if (code === 'CLEANUP_CHAIN_NOT_FOUND') return 404;
|
|
181
|
+
if (code === 'CLEANUP_INVALID') return 400;
|
|
182
|
+
if (code === 'CLEANUP_UNAVAILABLE') return 503;
|
|
183
|
+
if (code === 'CLEANUP_FAILED') return 502;
|
|
184
|
+
if (code.startsWith('CLEANUP_')) return 409;
|
|
177
185
|
if (code.startsWith('JOB_')) return 409;
|
|
178
186
|
// The credential seam is a separate service. "It is not installed here" is a
|
|
179
187
|
// capability gap (503), "the backend refused the write" is an upstream failure
|
package/src/http/user-plane.js
CHANGED
|
@@ -41,6 +41,7 @@ import { sameRecordedDirectory } from '../jobs/continuation-identity.js';
|
|
|
41
41
|
import { buildTaskTree } from '../jobs/task-tree.js';
|
|
42
42
|
import { findDisplayNode } from '../jobs/task-display.js';
|
|
43
43
|
import { MAX_PLAN_BATCH, PLAN_CODES } from '../jobs/plan-store.js';
|
|
44
|
+
import { cleanupOverview, runCleanup } from '../jobs/record-cleanup.js';
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
47
|
* Route prefix, already below `/api` because the native exact-route registry
|
|
@@ -157,6 +158,45 @@ export function userPlaneRoutes(deps) {
|
|
|
157
158
|
});
|
|
158
159
|
},
|
|
159
160
|
},
|
|
161
|
+
// One narrow route for the operator's execution choices — today, the Agent Teams
|
|
162
|
+
// default a NEW task gets when its dispatcher states no per-task choice.
|
|
163
|
+
//
|
|
164
|
+
// Like the monitoring route it is on the AUTHENTICATED operator plane, and the MCP
|
|
165
|
+
// surface never gains a settings write. It is deliberately narrow: it can set ONE
|
|
166
|
+
// task default and nothing else. It cannot turn on DSH's global agent-teams switch,
|
|
167
|
+
// cannot change a provider, a model, an effort, an isolation mode, a grant or the
|
|
168
|
+
// delegation switch, and it cannot change a task that already ran — those froze their
|
|
169
|
+
// own decision at admission. `setExecution` validates its own block.
|
|
170
|
+
{
|
|
171
|
+
path: `${USER_PLANE_PREFIX}/execution`,
|
|
172
|
+
methods: ['POST'],
|
|
173
|
+
requestBody: BODY_MODE,
|
|
174
|
+
fetch: async (request) => {
|
|
175
|
+
const body = await readJsonRequest(request);
|
|
176
|
+
if (body.execution === undefined) {
|
|
177
|
+
throw new HttpError(400, 'EXECUTION_SETTINGS_MISSING', 'an execution block is required');
|
|
178
|
+
}
|
|
179
|
+
// A refused block is the caller's mistake, not a server fault: the shared
|
|
180
|
+
// translator would render the validator's unlisted code as a 500, so it is
|
|
181
|
+
// re-thrown here as a 400 that keeps the original code and its field details.
|
|
182
|
+
// Nothing is written when this throws.
|
|
183
|
+
let committed;
|
|
184
|
+
try {
|
|
185
|
+
committed = await deps.settings.setExecution(body.execution);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
const code = typeof error?.code === 'string' ? error.code : '';
|
|
188
|
+
if (!code.startsWith('EXECUTION_')) throw error;
|
|
189
|
+
throw new HttpError(400, code, String(error?.message ?? 'the execution block is invalid'), error?.details ?? {});
|
|
190
|
+
}
|
|
191
|
+
return jsonResponse(200, {
|
|
192
|
+
ok: true,
|
|
193
|
+
execution: { ...committed.execution },
|
|
194
|
+
// The whole document is returned too, because the page adopts it after a
|
|
195
|
+
// narrow save and must not have to issue a second read to stay truthful.
|
|
196
|
+
settings: publicSettings(committed),
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
},
|
|
160
200
|
// One path, two methods. `GET` reads the stored document, `POST` replaces it.
|
|
161
201
|
// There is deliberately no `PUT`: the native registry cannot express it.
|
|
162
202
|
{
|
|
@@ -331,6 +371,10 @@ export function userPlaneRoutes(deps) {
|
|
|
331
371
|
// projection is read-only in both directions: it neither dispatches work
|
|
332
372
|
// nor rewrites the document.
|
|
333
373
|
//
|
|
374
|
+
// Removal of those records is its own route (`POST /tasks/cleanup`, below). The
|
|
375
|
+
// list only PUBLISHES, per execution chain, whether that chain may be removed;
|
|
376
|
+
// it never deletes anything, so refreshing the page cannot destroy a record.
|
|
377
|
+
//
|
|
334
378
|
// A history document that cannot be read is a *visible refusal*, never an
|
|
335
379
|
// empty success: answering `tasks: []` for an unreadable archive would tell
|
|
336
380
|
// an operator that nothing ever ran.
|
|
@@ -358,6 +402,47 @@ export function userPlaneRoutes(deps) {
|
|
|
358
402
|
});
|
|
359
403
|
},
|
|
360
404
|
},
|
|
405
|
+
// The session-placement map, narrowed to the fields the sidebar's grouped
|
|
406
|
+
// workspaces view needs to PROVE which real DSH sessions this plugin created.
|
|
407
|
+
//
|
|
408
|
+
// It exists because the grouped view runs in the browser, where a task record may
|
|
409
|
+
// already have been cleaned or hidden, while the durable map is the one document
|
|
410
|
+
// that still says "TaskBridge drove session X in workspace Y for source path S".
|
|
411
|
+
// Without it, a session whose records are gone has to be guessed at — and that is
|
|
412
|
+
// exactly the guess the sidebar must never make.
|
|
413
|
+
//
|
|
414
|
+
// What crosses the boundary is identity only, and it is the map's own field list
|
|
415
|
+
// (`RECORD_FIELDS`): task/source/execution paths, their digests, the Workspace,
|
|
416
|
+
// the Session, the isolation and the managed-tree facts. Never a prompt, a
|
|
417
|
+
// transcript, a model output, a token or a credential — none of them is in the
|
|
418
|
+
// document. This route is a read: it writes nothing and drives nothing.
|
|
419
|
+
{
|
|
420
|
+
path: `${USER_PLANE_PREFIX}/session-map`,
|
|
421
|
+
methods: ['GET'],
|
|
422
|
+
requestBody: BODY_MODE,
|
|
423
|
+
fetch: async () => {
|
|
424
|
+
const store = deps.sessionStore ?? null;
|
|
425
|
+
if (store === null || store === undefined || typeof store.list !== 'function') {
|
|
426
|
+
throw new HttpError(
|
|
427
|
+
503,
|
|
428
|
+
'SESSION_MAP_UNAVAILABLE',
|
|
429
|
+
'this deployment keeps no task-to-conversation identity, so the sidebar cannot be grouped by it',
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
let rows;
|
|
433
|
+
try {
|
|
434
|
+
rows = await store.list();
|
|
435
|
+
} catch (error) {
|
|
436
|
+
throw new HttpError(
|
|
437
|
+
503,
|
|
438
|
+
'SESSION_MAP_UNREADABLE',
|
|
439
|
+
'the stored task-to-conversation identity could not be read',
|
|
440
|
+
{ cause: typeof error?.code === 'string' ? error.code : 'SESSION_MAP_UNREADABLE' },
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
return jsonResponse(200, { ok: true, sessions: projectSessionMap(rows) });
|
|
444
|
+
},
|
|
445
|
+
},
|
|
361
446
|
{
|
|
362
447
|
path: `${USER_PLANE_PREFIX}/tasks/display-archive`,
|
|
363
448
|
methods: ['POST'],
|
|
@@ -480,6 +565,34 @@ export function userPlaneRoutes(deps) {
|
|
|
480
565
|
});
|
|
481
566
|
},
|
|
482
567
|
},
|
|
568
|
+
// ---- task record cleanup (one narrow, explicit write) --------------------
|
|
569
|
+
// The operator selected finished execution chains in the task tree and confirmed.
|
|
570
|
+
// The body names those chains and their exact rounds and nothing else:
|
|
571
|
+
//
|
|
572
|
+
// { confirm: true, chains: [{ chainId, taskIds: [...] }] }
|
|
573
|
+
//
|
|
574
|
+
// There is no time window, no path, no "delete all" flag and no per-node id: a
|
|
575
|
+
// caller cannot express "remove whatever finished last week", which is what makes
|
|
576
|
+
// the batch reviewable before it is sent. `runCleanup` re-reads the UNFILTERED
|
|
577
|
+
// current records and refuses the batch whole when any named chain is unknown,
|
|
578
|
+
// changed, live, undurable, still being reviewed, or still depended on by a
|
|
579
|
+
// continuation or a planning node — so a refusal writes nothing at all.
|
|
580
|
+
//
|
|
581
|
+
// What it removes is the durable record (and with it the review conclusion).
|
|
582
|
+
// It creates nothing else: no native Session, Workspace, worktree or source file
|
|
583
|
+
// is touched, no plan node is deleted or orphaned, and no other data file is
|
|
584
|
+
// written. It is a user-plane route only — the execution plane, the MCP surface
|
|
585
|
+
// and the native fence pick up no new capability from it.
|
|
586
|
+
{
|
|
587
|
+
path: `${USER_PLANE_PREFIX}/tasks/cleanup`,
|
|
588
|
+
methods: ['POST'],
|
|
589
|
+
requestBody: BODY_MODE,
|
|
590
|
+
fetch: async (request) => {
|
|
591
|
+
const body = await readJsonRequest(request);
|
|
592
|
+
const outcome = await runCleanup(deps, body);
|
|
593
|
+
return jsonResponse(200, { ok: true, ...outcome });
|
|
594
|
+
},
|
|
595
|
+
},
|
|
483
596
|
{
|
|
484
597
|
path: `${USER_PLANE_PREFIX}/tasks/cancel`,
|
|
485
598
|
methods: ['POST'],
|
|
@@ -932,6 +1045,26 @@ async function readTaskRecords(deps, options = {}) {
|
|
|
932
1045
|
}
|
|
933
1046
|
merged.sort(compareNewestFirst);
|
|
934
1047
|
const tree = buildTaskTree({ planNodes: planState.nodes, tasks: merged });
|
|
1048
|
+
// Every chain of the projection carries its own cleanup facts, computed from the
|
|
1049
|
+
// SAME unfiltered records above. The page draws a checkbox from this block and the
|
|
1050
|
+
// delete route re-checks the very same rules before writing, so a row the operator
|
|
1051
|
+
// can tick is a row whose server-side check will pass. A chain the projection could
|
|
1052
|
+
// not describe (no facts) is left untouched and is therefore not selectable.
|
|
1053
|
+
if (deps.history !== null && deps.history !== undefined && typeof deps.history.deleteMany === 'function') {
|
|
1054
|
+
try {
|
|
1055
|
+
const overview = await cleanupOverview(deps);
|
|
1056
|
+
attachCleanupFacts(tree, overview.chains);
|
|
1057
|
+
} catch (error) {
|
|
1058
|
+
// A tree that cannot describe removal is still a readable tree; the page then
|
|
1059
|
+
// shows the chains without the cleanup action instead of a broken list.
|
|
1060
|
+
deps.logger?.warn?.('dsh-delegate: record cleanup facts could not be computed', error?.code ?? 'CLEANUP_UNAVAILABLE');
|
|
1061
|
+
tree.cleanupAvailable = false;
|
|
1062
|
+
tree.cleanupError = typeof error?.code === 'string' ? error.code : 'CLEANUP_UNAVAILABLE';
|
|
1063
|
+
}
|
|
1064
|
+
} else {
|
|
1065
|
+
tree.cleanupAvailable = false;
|
|
1066
|
+
tree.cleanupError = 'CLEANUP_UNAVAILABLE';
|
|
1067
|
+
}
|
|
935
1068
|
if (deps.taskDisplay) {
|
|
936
1069
|
try {
|
|
937
1070
|
await deps.taskDisplay.project(tree);
|
|
@@ -961,8 +1094,70 @@ async function readTaskRecords(deps, options = {}) {
|
|
|
961
1094
|
};
|
|
962
1095
|
}
|
|
963
1096
|
|
|
964
|
-
|
|
965
|
-
|
|
1097
|
+
/**
|
|
1098
|
+
* Attach the cleanup facts of one chain to every chain object of a projected tree.
|
|
1099
|
+
*
|
|
1100
|
+
* The chains inside `roots` are the projection's own objects, so this writes the
|
|
1101
|
+
* block onto them in place instead of rebuilding the tree: `flatNodes` deliberately
|
|
1102
|
+
* carries no chain detail and must not be widened (it is the transport shape an
|
|
1103
|
+
* execution-plane reader sees).
|
|
1104
|
+
* @param {object} tree - `buildTaskTree` result.
|
|
1105
|
+
* @param {object[]} facts - `cleanupOverview(...).chains`.
|
|
1106
|
+
* @returns {void}
|
|
1107
|
+
*/
|
|
1108
|
+
function attachCleanupFacts(tree, facts) {
|
|
1109
|
+
const byId = new Map((Array.isArray(facts) ? facts : []).map((entry) => [entry.chainId, entry]));
|
|
1110
|
+
const walk = (node) => {
|
|
1111
|
+
const chains = node?.kind === 'plan' ? (node.executions ?? []) : (node?.chain ? [node.chain] : []);
|
|
1112
|
+
for (const chain of chains) {
|
|
1113
|
+
const fact = byId.get(chain.chainId) ?? null;
|
|
1114
|
+
// No facts means "this host cannot say", which the page reads as not selectable.
|
|
1115
|
+
if (fact === null) continue;
|
|
1116
|
+
chain.cleanup = {
|
|
1117
|
+
eligible: fact.eligible === true,
|
|
1118
|
+
blockers: Array.isArray(fact.blockers) ? [...fact.blockers] : [],
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
for (const child of Array.isArray(node?.children) ? node.children : []) walk(child);
|
|
1122
|
+
};
|
|
1123
|
+
for (const root of Array.isArray(tree?.roots) ? tree.roots : []) walk(root);
|
|
1124
|
+
tree.cleanupAvailable = true;
|
|
1125
|
+
tree.cleanupError = null;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// The identity fields the grouped sidebar needs, and nothing else. This is the
|
|
1129
|
+
// session map's own field list narrowed to what a VIEW model consumes; an unknown
|
|
1130
|
+
// future field on a stored row is dropped here rather than published by accident.
|
|
1131
|
+
const SESSION_MAP_VIEW_FIELDS = Object.freeze([
|
|
1132
|
+
'taskId', 'sourcePath', 'executionPath', 'sourcePathDigest', 'executionPathDigest',
|
|
1133
|
+
'workspaceId', 'sessionId', 'isolation', 'worktreeId', 'worktreeState', 'updatedAt',
|
|
1134
|
+
]);
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* Project the session-placement map onto the grouped sidebar's view fields.
|
|
1138
|
+
*
|
|
1139
|
+
* A row that cannot name a session or a Workspace proves nothing about the sidebar, so
|
|
1140
|
+
* it is dropped instead of published half-formed: the browser would otherwise have to
|
|
1141
|
+
* decide what a partially usable row means, and the answer could only be a guess.
|
|
1142
|
+
* @param {unknown} rows - `SessionStore.list()` result.
|
|
1143
|
+
* @returns {object[]} bounded rows, newest first.
|
|
1144
|
+
*/
|
|
1145
|
+
function projectSessionMap(rows) {
|
|
1146
|
+
const usable = (Array.isArray(rows) ? rows : []).filter((row) => row !== null && typeof row === 'object'
|
|
1147
|
+
&& typeof row.sessionId === 'string' && row.sessionId !== ''
|
|
1148
|
+
&& typeof row.workspaceId === 'string' && row.workspaceId !== '');
|
|
1149
|
+
const projected = usable.map((row) => {
|
|
1150
|
+
const view = {};
|
|
1151
|
+
for (const field of SESSION_MAP_VIEW_FIELDS) {
|
|
1152
|
+
if (row[field] !== undefined) view[field] = row[field];
|
|
1153
|
+
}
|
|
1154
|
+
return view;
|
|
1155
|
+
});
|
|
1156
|
+
projected.sort((left, right) => (Number(right.updatedAt) || 0) - (Number(left.updatedAt) || 0));
|
|
1157
|
+
return projected;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// Older review writes could drop the top-level session id while retaining the// placement and paths. Only the operator's task list needs this navigation link.
|
|
966
1161
|
async function restoreSidebarSessionIds(tasks, sessionStore) {
|
|
967
1162
|
const needsLink = (task) => task.archived === true && task.sessionId == null
|
|
968
1163
|
&& typeof task.execution?.conversation?.workspaceId === 'string';
|