@adhdev/daemon-core 0.9.82-rc.310 → 0.9.82-rc.312

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.
@@ -91,6 +91,93 @@ export type RepoMeshNodeHealth =
91
91
  export type RepoMeshSessionCleanupMode = 'preserve' | 'stop' | 'delete_stopped' | 'stop_and_delete';
92
92
  export type RepoMeshSpawnedSessionVisibility = 'visible' | 'hidden';
93
93
 
94
+ /**
95
+ * Mesh-wide tie-break strategy for distributing untargeted queue work across
96
+ * eligible nodes. This ONLY governs the final tie-break stage of the scheduler
97
+ * pipeline (TAG hard-filter → MAX-ALLOC capacity gate → PRIORITY soft score →
98
+ * TIE-BREAK); eligibility/capacity/priority are evaluated identically for every
99
+ * strategy.
100
+ *
101
+ * - 'first_eligible' (DEFAULT): preserve today's behavior exactly. Nodes are
102
+ * visited in config/array order and the first that can launch wins. No
103
+ * load-spreading. This is the strict no-change default — a mesh that never
104
+ * sets schedulingStrategy behaves identically to before this feature.
105
+ * - 'least_loaded': prefer the eligible node with the fewest active assignments,
106
+ * so untargeted work spreads instead of piling onto whichever node asks first.
107
+ * - 'round_robin': among nodes tied at the least load, rotate the winner using a
108
+ * per-mesh cursor so distribution stays fair across passes.
109
+ * - 'priority_only': rank purely by schedulingPriority (then config order),
110
+ * ignoring load — always send to the highest-priority eligible node.
111
+ *
112
+ * Distribution is explicit opt-in: a strategy other than 'first_eligible' must be
113
+ * configured for any load-spreading to occur.
114
+ */
115
+ export type RepoMeshSchedulingStrategy =
116
+ | 'first_eligible'
117
+ | 'least_loaded'
118
+ | 'round_robin'
119
+ | 'priority_only';
120
+
121
+ export const MESH_SCHEDULING_STRATEGIES: RepoMeshSchedulingStrategy[] = [
122
+ 'first_eligible',
123
+ 'least_loaded',
124
+ 'round_robin',
125
+ 'priority_only',
126
+ ];
127
+
128
+ export const DEFAULT_MESH_SCHEDULING_STRATEGY: RepoMeshSchedulingStrategy = 'first_eligible';
129
+
130
+ /**
131
+ * Normalize an unknown scheduling-strategy value to a valid strategy, defaulting
132
+ * to 'first_eligible' (strict no-change) for anything missing/blank/unrecognized.
133
+ */
134
+ export function normalizeMeshSchedulingStrategy(value: unknown): RepoMeshSchedulingStrategy {
135
+ if (typeof value !== 'string') return DEFAULT_MESH_SCHEDULING_STRATEGY;
136
+ const trimmed = value.trim() as RepoMeshSchedulingStrategy;
137
+ return (MESH_SCHEDULING_STRATEGIES as string[]).includes(trimmed)
138
+ ? trimmed
139
+ : DEFAULT_MESH_SCHEDULING_STRATEGY;
140
+ }
141
+
142
+ /**
143
+ * Resolve a node's soft scheduling priority — a single scalar used as the PRIORITY
144
+ * stage rank key (higher = preferred). It is NOT an eligibility gate (the MAX-ALLOC
145
+ * capacity gate alone decides whether a node can take work). Missing/blank/NaN
146
+ * resolves to 0 so unconfigured nodes all share the same neutral priority.
147
+ */
148
+ export function resolveNodeSchedulingPriority(
149
+ nodePolicy: Pick<RepoMeshNodePolicy, 'schedulingPriority'> | null | undefined,
150
+ ): number {
151
+ const raw = Number(nodePolicy?.schedulingPriority);
152
+ return Number.isFinite(raw) ? raw : 0;
153
+ }
154
+
155
+ /**
156
+ * Synthetic capability tag advertised by every mesh node describing how it can land
157
+ * its work onto the base branch:
158
+ * - converge=refine: a local worktree node (on any machine — refine_mesh_node
159
+ * forwards to the owning daemon) can run the Refinery merge → push → cleanup.
160
+ * - converge=fast_forward: a non-worktree node (the machine itself) can only
161
+ * fast-forward/push an already-converged branch.
162
+ * Emitted by buildMeshNodeCapabilityTags and matched through the ordinary
163
+ * required-tags filter.
164
+ */
165
+ export const MESH_CONVERGE_REFINE_TAG = 'converge=refine';
166
+ export const MESH_CONVERGE_FAST_FORWARD_TAG = 'converge=fast_forward';
167
+
168
+ /**
169
+ * Resolve whether the load-balancing scheduler should auto-inject a
170
+ * `converge=refine` required tag onto code_change tasks so they hard-filter onto
171
+ * refine-capable (worktree) nodes only. Strict opt-in: defaults to false, so a mesh
172
+ * that does not set it behaves exactly as before (code_change routes to any eligible
173
+ * node, including a non-worktree machine node when no worktree exists).
174
+ */
175
+ export function resolveAutoConvergeCodeChange(
176
+ policy: Pick<RepoMeshPolicy, 'autoConvergeCodeChange'> | null | undefined,
177
+ ): boolean {
178
+ return policy?.autoConvergeCodeChange === true;
179
+ }
180
+
94
181
  export interface RepoMeshAutoFastForwardPolicy {
95
182
  /** Defaults to true. Set false to disable daemon-initiated idle fast-forwards. */
96
183
  enabled: boolean;
@@ -115,6 +202,24 @@ export interface RepoMeshPolicy {
115
202
  dirtyWorkspaceBehavior: 'block' | 'warn' | 'checkpoint_then_continue';
116
203
  maxParallelTasks: number;
117
204
  allowedProviders?: string[];
205
+ /**
206
+ * Mesh-wide tie-break strategy for distributing untargeted queue work across
207
+ * eligible nodes. Defaults to 'first_eligible' (today's exact behavior — no
208
+ * load-spreading). Set to 'least_loaded' / 'round_robin' / 'priority_only' to
209
+ * opt into distribution. Only governs the final tie-break stage; eligibility,
210
+ * capacity, and priority are evaluated identically regardless of strategy.
211
+ */
212
+ schedulingStrategy?: RepoMeshSchedulingStrategy;
213
+ /**
214
+ * Convergence routing opt-in: when true, the scheduler auto-injects a
215
+ * `converge=refine` required tag onto every code_change task at enqueue time, so
216
+ * code_change work hard-filters onto refine-capable worktree nodes (on any
217
+ * machine — refine_mesh_node forwards to the owning daemon) and never lands on a
218
+ * non-worktree machine node. Explicit target_node_id routing and any
219
+ * caller-supplied required_tags are preserved (the tag is merged, not replaced).
220
+ * Defaults to false: code_change routing is unchanged unless opted in.
221
+ */
222
+ autoConvergeCodeChange?: boolean;
118
223
  /**
119
224
  * Whether sessions spawned by mesh/coordinator policy should auto-open as visible
120
225
  * dashboard tabs or start hidden. Defaults to 'visible' to preserve existing
@@ -163,12 +268,17 @@ export interface RepoMeshRelatedRepo {
163
268
  *
164
269
  * `role` is a free-form resource-pool label (recommended values:
165
270
  * 'investigation' | 'coding' | 'orchestration') describing what this
166
- * (node, provider) combination is *for*. It is a label/hint only it is
167
- * surfaced to the coordinator and dashboards but the daemon does NOT route
168
- * tasks by role (task routing stays driven by taskMode + requiredTags +
169
- * targetNode/targetSession). role is intentionally orthogonal to taskMode:
170
- * taskMode classifies the *work* (code_change vs live_debug_readonly), role
171
- * classifies the *resource pool*.
271
+ * (node, provider) combination is *for*. As of the load-balancing scheduler it
272
+ * is ALSO routable: each declared role is advertised as a synthetic `role=<x>`
273
+ * capability tag (see buildMeshNodeCapabilityTags), so a task enqueued with
274
+ * requiredTags: ["role=validation"] is hard-filtered to nodes/providers that
275
+ * declare that role — through the same nodeSatisfiesRequiredTags path as any
276
+ * other tag. There is intentionally no separate "advertisedRoles" field: the
277
+ * label and the routing tag are one mechanism. A task that does not require a
278
+ * `role=` tag ignores roles entirely (opt-in, fully backward compatible).
279
+ *
280
+ * role is intentionally orthogonal to taskMode: taskMode classifies the *work*
281
+ * (code_change vs live_debug_readonly), role classifies the *resource pool*.
172
282
  *
173
283
  * `maxParallel` is the only enforced field: the queue will not assign a task
174
284
  * to this (node, provider) once it already has `maxParallel` active
@@ -190,15 +300,24 @@ export interface RepoMeshNodePolicy {
190
300
  readOnly?: boolean;
191
301
  canPush?: boolean;
192
302
  maxConcurrentSessions?: number;
303
+ /**
304
+ * Soft scheduling priority used as the PRIORITY rank key (higher = preferred)
305
+ * when the mesh schedulingStrategy spreads work across nodes. Defaults to 0.
306
+ * This is NOT an eligibility gate — a node with a high priority that is at its
307
+ * capacity (MAX-ALLOC gate) is still skipped; priority only orders nodes that
308
+ * can actually take work. Ignored entirely under 'first_eligible'.
309
+ */
310
+ schedulingPriority?: number;
193
311
  /** Ordered provider preference used when mesh_launch_session omits an explicit type. */
194
312
  providerPriority?: string[];
195
313
  /**
196
314
  * Per-(node, provider) role + parallelism declarations. Each entry binds a
197
315
  * providerType on THIS node to an optional free-form role label and an
198
- * optional maxParallel cap. Only maxParallel is enforced (as an additional,
316
+ * optional maxParallel cap. maxParallel is enforced (as an additional,
199
317
  * stricter-wins constraint on top of the global maxParallelTasks/taskMode
200
- * caps); role is a label/hint surfaced to the coordinator. Missing/empty:
201
- * the node behaves exactly as before (global caps only).
318
+ * caps); role is advertised as a routable `role=<x>` capability tag so tasks
319
+ * can hard-filter by required role. Missing/empty: the node behaves exactly
320
+ * as before (global caps only, no role tags).
202
321
  */
203
322
  providerRoles?: RepoMeshProviderRole[];
204
323
  /**
@@ -512,6 +631,12 @@ export interface RepoMeshPeerConnectionStatus {
512
631
  transport: RepoMeshPeerConnectionTransport;
513
632
  reported: boolean;
514
633
  reason?: string;
634
+ /**
635
+ * Round-trip time in ms for the selected candidate pair, as sampled by the
636
+ * coordinator daemon when connected. Optional — older daemons and not_reported
637
+ * fallbacks omit it; the dashboard must treat it as best-effort telemetry.
638
+ */
639
+ rttMs?: number;
515
640
  lastStateChangeAt?: string;
516
641
  lastConnectedAt?: string;
517
642
  lastCommandAt?: string;