dsh-taskbridge 1.5.0 → 1.5.2

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.
@@ -796,10 +796,24 @@ export class JobEngine {
796
796
  // project setting changed after its parent ran, use the parent's isolation
797
797
  // so the follow-up reaches the same checkout or the same managed worktree.
798
798
  overrides.isolation = parentIsolation;
799
+ // The Agent Teams decision follows the same rule as isolation for a CONTINUATION:
800
+ // it is inherited from the parent UNLESS the dispatcher states it explicitly, so a
801
+ // follow-up keeps the chain's team mode instead of silently flipping it. `null`
802
+ // (no choice anywhere) stays `null` and the Session keeps its own mode.
803
+ if (overrides.agentTeams === undefined && typeof task.continuationRecord.agentTeams === 'boolean') {
804
+ overrides.agentTeams = task.continuationRecord.agentTeams;
805
+ }
799
806
  }
800
807
  let effective;
801
808
  try {
802
- effective = resolveEffectiveConfig(settings, { projectPath: sourcePath, overrides });
809
+ // `agentTeams` is a per-run DSH Session choice, not a settings field: it is frozen
810
+ // on the task below and handed to the runner, and the settings validator must
811
+ // never see it.
812
+ const { agentTeams: teamChoice, ...settingsOverrides } = overrides;
813
+ effective = resolveEffectiveConfig(settings, { projectPath: sourcePath, overrides: settingsOverrides });
814
+ // Frozen on the task so the view, the run and a later continuation all state the
815
+ // SAME explicit decision. `null` = the commander made no choice for this task.
816
+ task.agentTeams = typeof teamChoice === 'boolean' ? teamChoice : null;
803
817
  } catch (error) {
804
818
  throw new JobError(JOB_CODES.routingRefused, error?.message ?? 'the effective configuration was refused', {
805
819
  cause: error?.code ?? null,
@@ -1883,8 +1897,8 @@ export class JobEngine {
1883
1897
  *
1884
1898
  * A new tree would hide the parent's uncommitted work and create a different
1885
1899
  * DSH Workspace, so this path never calls `prepare()`. After a plugin restart,
1886
- * or after explicit disposal, the in-memory registry cannot prove ownership and
1887
- * the continuation is refused rather than guessed from a directory name.
1900
+ * recover only the already-authorized identity through Git's live registry.
1901
+ * Missing, replaced or disposed trees are refused, never substituted.
1888
1902
  * @param {object} task - continuation with a stored parent identity.
1889
1903
  * @returns {Promise<object>} the existing tree metadata.
1890
1904
  * @throws {JobError} when the original tree cannot be proven reusable.
@@ -1903,16 +1917,25 @@ export class JobEngine {
1903
1917
  if (manager === null || typeof manager.get !== 'function') {
1904
1918
  throw refuse('the managed worktree service is unavailable, so the original tree cannot be proven reusable', 'no worktree registry');
1905
1919
  }
1920
+ const expectedTreeId = identity.worktreeId ?? identity.taskId;
1906
1921
  let tree;
1907
1922
  try {
1908
1923
  tree = manager.get(identity.executionPath);
1924
+ if (tree === null && typeof manager.recover === 'function') {
1925
+ tree = await manager.recover({
1926
+ taskId: expectedTreeId,
1927
+ sourcePath: identity.sourcePath,
1928
+ workspacePath: identity.executionPath,
1929
+ state: identity.worktreeState,
1930
+ signal: task.controller.signal,
1931
+ });
1932
+ }
1909
1933
  } catch (error) {
1910
1934
  throw refuse('the managed worktree service refused to report the original tree', typeof error?.code === 'string' ? error.code : 'registry read failed');
1911
1935
  }
1912
1936
  if (tree === null || typeof tree !== 'object') {
1913
1937
  throw refuse('the original worktree is no longer registered; a new tree will not be substituted', 'tree not managed here');
1914
1938
  }
1915
- const expectedTreeId = identity.worktreeId ?? identity.taskId;
1916
1939
  if (!samePath(tree.workspacePath, identity.executionPath)
1917
1940
  || !samePath(tree.sourcePath, identity.sourcePath)
1918
1941
  || (typeof expectedTreeId === 'string' && expectedTreeId !== '' && tree.taskId !== expectedTreeId)
@@ -3227,6 +3250,10 @@ export class JobEngine {
3227
3250
  // forwarded — there is no field in the summary they could travel in.
3228
3251
  // This hook is also the only execution evidence the phase trusts.
3229
3252
  onEvent: (event) => { this.onExecutionEvent(task, event); },
3253
+ // The commander's DSH Agent Teams decision for THIS task's own Session. Absent
3254
+ // when the task froze `null` (no choice): the run then keeps the Session's
3255
+ // current mode instead of guessing one.
3256
+ ...(task.agentTeams === null || task.agentTeams === undefined ? {} : { agentTeams: task.agentTeams }),
3230
3257
  });
3231
3258
  task.native.promise = pending;
3232
3259
  let run;
@@ -3256,6 +3283,10 @@ export class JobEngine {
3256
3283
  // armed bridge was the answerer behind it. Recorded per run so "did this
3257
3284
  // task ask, or did it reject without asking" is answerable from the record.
3258
3285
  approval: run.approval ?? null,
3286
+ // The Agent Teams outcome: what the commander asked for and whether DSH's own
3287
+ // service confirmed it on this run's Session. `null` for a task that made no
3288
+ // choice, so "not asked" and "asked but unapplied" stay distinguishable.
3289
+ team: run.team ?? null,
3259
3290
  // Where the conversation landed. Reported per run so an operator can tell a
3260
3291
  // fresh session from a continued one, and which Workspace group it is in.
3261
3292
  conversation: run.conversation ?? null,
@@ -3553,12 +3584,17 @@ export class JobEngine {
3553
3584
  * cancels, restarts or resumes the worker, and never disturbs another
3554
3585
  * observer of the same task.
3555
3586
  * @param {string} taskId - task to observe.
3556
- * @param {object} [options] - `connectionId`, `waitMs` (default 25000, max 25000), `signal`.
3587
+ * @param {object} [options] - `connectionId`, `waitMs` (default 25000, max 25000),
3588
+ * `signal`, `ackFailureEventId` (acknowledge one delivered repeated-failure
3589
+ * reminder by its exact `eventId`).
3557
3590
  * @returns {Promise<{ task: object, reason: string, permission: object | null,
3558
- * failure: object | null, activity: object | null,
3591
+ * failure: object | null, failureAck: object | null, activity: object | null,
3559
3592
  * selfCheck: object | null, wait: { waitMs: number, waitedMs: number, activitySinceWait: boolean } }>} observation.
3560
3593
  * `failure` is present only when `attention` reports a repeated-tool-failure
3561
- * reminder; it carries a tool name, a failure code, an operation digest and counts.
3594
+ * reminder; it carries a stable `eventId`, a tool name, a failure code, an
3595
+ * operation digest and counts, and it is REDELIVERED on later observations until
3596
+ * it is acknowledged — a lost answer does not lose the reminder.
3597
+ * `failureAck` is present only when the caller asked to acknowledge.
3562
3598
  * @throws {JobError} `JOB_TASK_NOT_FOUND` for an unknown or foreign task.
3563
3599
  */
3564
3600
  async observeTask(taskId, options = {}) {
@@ -3566,9 +3602,18 @@ export class JobEngine {
3566
3602
  const waitMs = clampObserveWait(options?.waitMs);
3567
3603
  const signal = options?.signal ?? null;
3568
3604
 
3569
- if (this.aborted) return this.observationOf(task, OBSERVE_TASK_REASONS.interrupted, null, waitMs, 0, false);
3605
+ // Acknowledgment is a write to the MONITOR'S reminder state only — never to the
3606
+ // task, its worker or its deadline — and it is bound to the exact eventId the
3607
+ // caller observed. The result travels back on this observation (`failureAck`),
3608
+ // so the caller learns whether its ack landed even when the observation itself
3609
+ // says nothing new. An unknown id changes nothing: a wrong ack must not
3610
+ // silence a live notification. An EMPTY or non-string id is an explicit
3611
+ // refusal (`event-id-required`), never a silent no-op.
3612
+ const failureAck = this.ackObservedFailure(task, options?.ackFailureEventId);
3613
+
3614
+ if (this.aborted) return this.observationOf(task, OBSERVE_TASK_REASONS.interrupted, null, waitMs, 0, false, null, failureAck);
3570
3615
  if (signal !== null && signal.aborted === true) {
3571
- return this.observationOf(task, OBSERVE_TASK_REASONS.interrupted, null, waitMs, 0, false);
3616
+ return this.observationOf(task, OBSERVE_TASK_REASONS.interrupted, null, waitMs, 0, false, null, failureAck);
3572
3617
  }
3573
3618
 
3574
3619
  // Exactly one monitor per task, created at most once (see `ensureMonitor`).
@@ -3585,9 +3630,9 @@ export class JobEngine {
3585
3630
  // timed-out review learn the outcome here, instead of re-sending a decision (or
3586
3631
  // believing the review vanished). The wait is bounded and the report is honest
3587
3632
  // either way; nothing about the task's state is touched.
3588
- const settledObservation = await this.awaitReviewSettlement(task, waitMs, signal);
3633
+ const settledObservation = await this.awaitReviewSettlement(task, waitMs, signal, failureAck);
3589
3634
  if (settledObservation !== null) return settledObservation;
3590
- return this.observationOf(task, immediate, monitor, waitMs, 0, false);
3635
+ return this.observationOf(task, immediate, monitor, waitMs, 0, false, null, failureAck);
3591
3636
  }
3592
3637
 
3593
3638
  // ONE bounded wait, and nothing more. `waitMs` is the caller's promise: a
@@ -3608,7 +3653,7 @@ export class JobEngine {
3608
3653
  // those outrank it, and a failure report must not describe a task that now needs a
3609
3654
  // different decision.
3610
3655
  const failure = reason === OBSERVE_TASK_REASONS.attention ? (outcome.failure ?? null) : null;
3611
- return this.observationOf(task, reason, monitor, waitMs, outcome.waitedMs, outcome.activitySinceWait, failure);
3656
+ return this.observationOf(task, reason, monitor, waitMs, outcome.waitedMs, outcome.activitySinceWait, failure, failureAck);
3612
3657
  }
3613
3658
 
3614
3659
  /**
@@ -3623,7 +3668,47 @@ export class JobEngine {
3623
3668
  * @param {AbortSignal | null} signal - the caller's cancellation.
3624
3669
  * @returns {Promise<object | null>} an observation when the wait changed the answer, else null.
3625
3670
  */
3626
- async awaitReviewSettlement(task, waitMs, signal) {
3671
+ /**
3672
+ * Apply (or refuse) one caller acknowledgment and return the fact the observation
3673
+ * must publish.
3674
+ *
3675
+ * `null` means the caller did not acknowledge anything (`ackFailureEventId`
3676
+ * absent), in which case NO ack block appears on the observation at all — the
3677
+ * published shape an old caller receives is unchanged. A non-empty string is
3678
+ * forwarded to the monitor; an EMPTY string is an explicit refusal
3679
+ * (`event-id-required`), not a silent no-op, so both surfaces answer with the
3680
+ * same clear fact.
3681
+ * @param {object} task - task record.
3682
+ * @param {unknown} ackFailureEventId - the ack the caller carried, if any.
3683
+ * @returns {object | null} the ack result to publish, or null.
3684
+ */
3685
+ ackObservedFailure(task, ackFailureEventId) {
3686
+ if (ackFailureEventId === undefined || ackFailureEventId === null) return null;
3687
+ if (typeof ackFailureEventId !== 'string' || ackFailureEventId === '') {
3688
+ return { acknowledged: false, eventId: typeof ackFailureEventId === 'string' ? ackFailureEventId : null, reason: 'event-id-required' };
3689
+ }
3690
+ const monitorForAck = this.ensureMonitor(task);
3691
+ try {
3692
+ return monitorForAck.ackFailureReport(ackFailureEventId);
3693
+ } catch {
3694
+ return { acknowledged: false, eventId: ackFailureEventId, reason: 'ack-failed' };
3695
+ }
3696
+ }
3697
+
3698
+ /**
3699
+ * The ack result of THIS observeTask call, passed explicitly into the settlement
3700
+ * branch. The receipt belongs to the CALL, not to the monitor: a shared store on
3701
+ * the monitor would let concurrent observations overwrite each other's verdicts
3702
+ * (a later refusal replacing an earlier success) and answer a caller that never
3703
+ * acked with another caller's receipt. Each settle wait therefore carries its own
3704
+ * ack result through its own argument.
3705
+ * @param {object} task - task record.
3706
+ * @param {number} waitMs - the caller's own wait bound.
3707
+ * @param {AbortSignal | null} signal - the caller's cancellation.
3708
+ * @param {object | null} failureAck - the ack result of THIS observation, or null.
3709
+ * @returns {Promise<object | null>} an observation when the wait changed the answer, else null.
3710
+ */
3711
+ async awaitReviewSettlement(task, waitMs, signal, failureAck = null) {
3627
3712
  const entry = this.reviewState.get(task.taskId) ?? null;
3628
3713
  if (entry === null) return null;
3629
3714
  if (entry.state !== REVIEW_PERSISTENCE_STATES.saving && entry.state !== REVIEW_PERSISTENCE_STATES.timedOut) return null;
@@ -3635,10 +3720,12 @@ export class JobEngine {
3635
3720
  if (outcome === REVIEW_OUTCOME_TIMEOUT) return null;
3636
3721
  if (signal !== null && signal.aborted === true) return null;
3637
3722
  // The write settled inside the wait: report the resulting fact (confirmed or failed)
3638
- // together with how long it took, without re-deriving the task's state.
3723
+ // together with how long it took, without re-deriving the task's state. The ack
3724
+ // result is THIS call's own (passed in as an argument, never read from shared
3725
+ // state), so concurrent observations cannot cross their receipts.
3639
3726
  const reason = this.settleReason(task) ?? OBSERVE_TASK_REASONS.attention;
3640
3727
  const waitedMs = Math.max(0, this.clock() - started);
3641
- return this.observationOf(task, reason, this.ensureMonitor(task), waitMs, waitedMs, true, null);
3728
+ return this.observationOf(task, reason, this.ensureMonitor(task), waitMs, waitedMs, true, null, failureAck);
3642
3729
  }
3643
3730
 
3644
3731
  /**
@@ -3742,9 +3829,11 @@ export class JobEngine {
3742
3829
  * @param {boolean} activitySinceWait - whether activity arrived during the wait.
3743
3830
  * @param {object | null} [failure] - the repeated-failure diagnostic, when that is
3744
3831
  * what ended the wait.
3832
+ * @param {object | null} [failureAck] - the acknowledgment result, present only when
3833
+ * the caller asked to acknowledge one delivered reminder by its `eventId`.
3745
3834
  * @returns {object} observation result.
3746
3835
  */
3747
- observationOf(task, reason, monitor, waitMs, waitedMs, activitySinceWait, failure = null) {
3836
+ observationOf(task, reason, monitor, waitMs, waitedMs, activitySinceWait, failure = null, failureAck = null) {
3748
3837
  const at = this.clock();
3749
3838
  const summary = this.observationSummary(task, at);
3750
3839
  const pending = task?.permission?.pending ?? null;
@@ -3767,8 +3856,13 @@ export class JobEngine {
3767
3856
  : null,
3768
3857
  // The typed, bounded diagnostic for a repeated-failure reminder. It is the only
3769
3858
  // thing that distinguishes that reminder from an ordinary silence report, whose
3770
- // own diagnostic is `selfCheck`.
3859
+ // own diagnostic is `selfCheck`. Its `eventId` is the identity the receiver
3860
+ // acknowledges; the reminder is redelivered until that ack lands.
3771
3861
  failure: reason === OBSERVE_TASK_REASONS.attention && failure !== null ? failure : null,
3862
+ // The acknowledgment result. Present (possibly with `acknowledged: false`) only
3863
+ // when the caller asked to acknowledge; absent otherwise, so an old caller's
3864
+ // observation shape is byte-for-byte unchanged.
3865
+ ...(failureAck === null ? {} : { failureAck }),
3772
3866
  activity: summary.activity,
3773
3867
  selfCheck,
3774
3868
  wait: { waitMs, waitedMs: Math.max(0, Math.trunc(waitedMs)), activitySinceWait: activitySinceWait === true },
@@ -3826,6 +3920,11 @@ export class JobEngine {
3826
3920
  // Where that decision is in its durable write, so a waiting host can tell "not
3827
3921
  // reviewed" from "the review is being written right now" and does not resubmit one.
3828
3922
  reviewPersistence: this.reviewPersistenceView(task),
3923
+ // The Agent Teams decision and outcome, short enough for a wait: `agentTeams` is the
3924
+ // frozen request (or null), `team` the verified result (`applied`/`enabled`) or the
3925
+ // reason it could not be applied. No team reasoning or task-board content travels.
3926
+ agentTeams: task.agentTeams ?? null,
3927
+ team: summarizedTeam(task.execution?.team ?? null),
3829
3928
  };
3830
3929
  }
3831
3930
 
@@ -4376,6 +4475,10 @@ export class JobEngine {
4376
4475
  ? worktree.worktreeId
4377
4476
  : (typeof worktree.taskId === 'string' ? worktree.taskId : task.taskId)),
4378
4477
  worktreeState: worktree === null ? null : (typeof worktree.state === 'string' ? worktree.state : null),
4478
+ // The chain's Agent Teams decision, so a follow-up in a later process inherits the
4479
+ // mode its parent ran with. `null` (no decision) is stored as "no decision", which
4480
+ // is how an old row written before this field reads back too.
4481
+ agentTeams: task.agentTeams ?? null,
4379
4482
  });
4380
4483
  task.conversationSaved = saved;
4381
4484
  task.conversationError = null;
@@ -4626,6 +4729,9 @@ export class JobEngine {
4626
4729
  conversation: task.execution.conversation ?? null,
4627
4730
  cancelCause: task.execution.cancelCause,
4628
4731
  error: task.execution.error,
4732
+ // The Agent Teams outcome this run verified (or refuses to claim). Reported inside
4733
+ // `execution` because it is a fact about THIS run, not about the task's intent.
4734
+ team: task.execution.team ?? null,
4629
4735
  },
4630
4736
  // Where the run's conversation was placed in DSH. `workspaceId` is the group an
4631
4737
  // operator sees; `kind` is `new` or `continuation`, and `continuedFromTaskId`
@@ -4652,6 +4758,12 @@ export class JobEngine {
4652
4758
  // The approval stance the run installed and read back (`never` without a
4653
4759
  // bridge, `ask` with an armed one), recorded from the run itself.
4654
4760
  approval: task.execution?.approval ?? null,
4761
+ // The Agent Teams decision: `requested` is what the dispatcher froze on the task
4762
+ // (`null` when they made no choice) and `applied` is what DSH's own service
4763
+ // confirmed on this run's Session. Kept as one block so "asked for teams" and
4764
+ // "teams actually on for this run" are never conflated.
4765
+ agentTeams: task.agentTeams ?? null,
4766
+ team: task.execution?.team ?? null,
4655
4767
  // A bounded progress summary: counts, timestamps and the tool in flight. It
4656
4768
  // carries no model text, no reasoning, no tool arguments and no diff, so the
4657
4769
  // ordinary task view can show "still working, last activity 12s ago" without
@@ -4824,11 +4936,25 @@ export function sanitizeOverrides(value) {
4824
4936
  if (typeof value !== 'object' || Array.isArray(value)) {
4825
4937
  throw new JobError(JOB_CODES.overrideInvalid, 'overrides must be an object', {});
4826
4938
  }
4827
- const allowed = ['providerId', 'model', 'reasoningEffort', 'timeoutSeconds', 'isolation'];
4939
+ // `agentTeams` is NOT part of the frozen worker configuration (it is not a settings
4940
+ // field and never reaches the settings validator); it is carried on the overrides
4941
+ // object only because that is the existing channel a dispatcher uses for per-task
4942
+ // choices. It selects DSH Agent Teams for THIS run's own Session; `undefined` means
4943
+ // the commander made no choice and the Session keeps its current mode.
4944
+ const workerKeys = ['providerId', 'model', 'reasoningEffort', 'timeoutSeconds', 'isolation'];
4828
4945
  const out = {};
4829
- for (const key of allowed) {
4946
+ for (const key of workerKeys) {
4830
4947
  if (value[key] !== undefined) out[key] = value[key];
4831
4948
  }
4949
+ if (value.agentTeams !== undefined) {
4950
+ if (typeof value.agentTeams !== 'boolean') {
4951
+ throw new JobError(JOB_CODES.overrideInvalid, 'overrides.agentTeams must be a boolean', {
4952
+ field: 'agentTeams',
4953
+ requestedType: typeof value.agentTeams,
4954
+ });
4955
+ }
4956
+ out.agentTeams = value.agentTeams;
4957
+ }
4832
4958
  return out;
4833
4959
  }
4834
4960
 
@@ -4919,3 +5045,23 @@ function summarizedAcceptance(acceptance) {
4919
5045
  noteOmitted: true,
4920
5046
  };
4921
5047
  }
5048
+
5049
+ /**
5050
+ * The Agent Teams outcome as a WAIT reports it: four booleans and one bounded reason.
5051
+ *
5052
+ * A waiting host must be able to answer "are teams on for this run, and if not why"
5053
+ * without reading the full result. Nothing else from the team machinery (task board,
5054
+ * members, messages) belongs on a wait, and its reason is a code or a one-line diagnostic.
5055
+ * @param {object | null} team - the run's `team` fact.
5056
+ * @returns {object | null} the short fact.
5057
+ */
5058
+ function summarizedTeam(team) {
5059
+ if (team === null || typeof team !== 'object') return null;
5060
+ return {
5061
+ requested: typeof team.requested === 'boolean' ? team.requested : null,
5062
+ supported: team.supported === true,
5063
+ applied: team.applied === true,
5064
+ enabled: typeof team.enabled === 'boolean' ? team.enabled : null,
5065
+ reason: typeof team.reason === 'string' ? diagnostic(team.reason, 200) : null,
5066
+ };
5067
+ }
@@ -613,6 +613,12 @@ function projectView(view, maxEntryBytes, options = {}) {
613
613
  error: errorView(view.error, ctx),
614
614
  cancelledBy: label(view.cancelledBy),
615
615
  hostAcceptance: acceptance,
616
+ // The per-task Agent Teams decision (frozen at admission) and what DSH's own service
617
+ // confirmed for the run. Booleans and a bounded reason string only: `null` means the
618
+ // dispatcher made no choice, so a restored record can tell "not asked" from "asked",
619
+ // and "applied" from "asked but unapplied".
620
+ agentTeams: typeof view.agentTeams === 'boolean' ? view.agentTeams : null,
621
+ team: teamView(view.team, ctx),
616
622
  // A completed job is not an accepted one. This is fixed, never copied.
617
623
  selfApproved: false,
618
624
  };
@@ -1067,6 +1073,28 @@ function markPermissionInterrupted(entry) {
1067
1073
  * @param {unknown} value - task `activity` block.
1068
1074
  * @returns {object | null} bounded copy, or null when the task never ran.
1069
1075
  */
1076
+ /**
1077
+ * Project one run's Agent Teams outcome for storage.
1078
+ *
1079
+ * Allow-list only: three booleans (or null) and one bounded reason. The selection itself
1080
+ * belongs to the DSH Session, not to this record, so nothing here can turn a global
1081
+ * switch on when a record is read back.
1082
+ * @param {unknown} value - run `team` fact.
1083
+ * @param {object} ctx - cut context.
1084
+ * @returns {{ requested: boolean|null, supported: boolean, applied: boolean, enabled: boolean|null, reason: string|null } | null} bounded fact.
1085
+ */
1086
+ function teamView(value, ctx) {
1087
+ if (!isPlainObject(value)) return null;
1088
+ return {
1089
+ requested: typeof value.requested === 'boolean' ? value.requested : null,
1090
+ supported: value.supported === true,
1091
+ applied: value.applied === true,
1092
+ enabled: typeof value.enabled === 'boolean' ? value.enabled : null,
1093
+ reason: boundedReason(value.reason, ctx, 'team.reason'),
1094
+ };
1095
+ }
1096
+
1097
+ /** @param {object} value - activity summary view. @returns {object|null} bounded activity view. */
1070
1098
  function activityView(value) {
1071
1099
  if (!isPlainObject(value)) return null;
1072
1100
  const tool = isPlainObject(value.currentTool) ? value.currentTool : null;
@@ -1512,6 +1540,21 @@ function label(value) {
1512
1540
  return value.slice(0, MAX_LABEL_CHARS);
1513
1541
  }
1514
1542
 
1543
+ /**
1544
+ * A short, bounded reason string (a code or a one-line diagnostic), cut once and
1545
+ * the cut stated.
1546
+ * @param {unknown} value - reason.
1547
+ * @param {object} ctx - cut context.
1548
+ * @param {string} field - field label used when the value had to be cut.
1549
+ * @returns {string | null} bounded reason, or null when absent.
1550
+ */
1551
+ function boundedReason(value, ctx, field) {
1552
+ if (typeof value !== 'string' || value === '') return null;
1553
+ if (value.length <= MAX_LABEL_CHARS) return value;
1554
+ if (ctx !== null && ctx !== undefined) ctx.fields.add(field);
1555
+ return value.slice(0, MAX_LABEL_CHARS);
1556
+ }
1557
+
1515
1558
  /**
1516
1559
  * @param {unknown} value - path.
1517
1560
  * @param {object} [ctx] - cut context; omitted for project-owned paths.