@adhdev/daemon-core 0.9.82-rc.365 → 0.9.82-rc.366

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.
@@ -0,0 +1,3 @@
1
+ import type { HighFamilyRegistry } from './types.js';
2
+ export type { HighFamilyContext, HighFamilyHandler, HighFamilyRegistry } from './types.js';
3
+ export declare const highFamilyRegistry: HighFamilyRegistry;
@@ -0,0 +1,2 @@
1
+ import type { HighFamilyHandler } from './types.js';
2
+ export declare const meshCoordinatorLaunchHandlers: Record<string, HighFamilyHandler>;
@@ -0,0 +1,2 @@
1
+ import type { HighFamilyHandler } from './types.js';
2
+ export declare const meshEventsHandlers: Record<string, HighFamilyHandler>;
@@ -0,0 +1,2 @@
1
+ import type { HighFamilyHandler } from './types.js';
2
+ export declare const meshStatusHandlers: Record<string, HighFamilyHandler>;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * RF-ROUTER HIGH family — shared types for the extracted high-coupling command
3
+ * handlers. Like the LOW and MED families, each handler is a function of
4
+ * (context, args) that returns the exact CommandRouterResult the original
5
+ * `executeDaemonCommand` switch case returned, so the router facade is unchanged.
6
+ *
7
+ * HIGH handlers are the most router-coupled of the three families: in addition to
8
+ * the MED collaborators (mesh resolution, owner gating, inline-cache), they reach
9
+ * the router's aggregate-status memory cache and running-refine-job table — state
10
+ * the router owns and the `mesh_status` aggregate render and `get_mesh_review_inbox`
11
+ * re-entry both depend on. The router binds those onto HighFamilyContext at
12
+ * dispatch; they are NOT reachable from `deps`.
13
+ *
14
+ * Registry dispatch: DaemonCommandRouter.executeDaemonCommand looks up the cmd in
15
+ * highFamilyRegistry AFTER the LOW and MED registries and BEFORE its remaining
16
+ * switch; a hit returns the handler result, a miss falls through to the switch
17
+ * (and ultimately CommandHandler delegation).
18
+ */
19
+ import type { CommandRouterDeps, CommandRouterResult, MeshGitProbeCache, MeshRefineJobHandle } from '../router.js';
20
+ import type { ResolvedMeshForCommand } from '../med-family/types.js';
21
+ /**
22
+ * Router-private collaborators injected at dispatch. Each is a bound method or
23
+ * field of DaemonCommandRouter; handlers that don't need a given collaborator
24
+ * simply ignore it. The router owns this instance state (inline-mesh cache,
25
+ * aggregate-status memory cache, running-refine-job table, git-probe cache), so
26
+ * it cannot be read from `deps` — the registry receives bound references instead.
27
+ */
28
+ export interface HighFamilyContext {
29
+ deps: CommandRouterDeps;
30
+ /** Bound `DaemonCommandRouter.getMeshForCommand`. */
31
+ getMeshForCommand: (meshId: string, inlineMesh?: unknown, options?: {
32
+ preferInline?: boolean;
33
+ }) => Promise<ResolvedMeshForCommand>;
34
+ /** Bound `DaemonCommandRouter.getCachedAggregateMeshStatus`. */
35
+ getCachedAggregateMeshStatus: (meshId: string, mesh?: any, options?: {
36
+ requireDirectPeerTruth?: boolean;
37
+ }) => any | null;
38
+ /** Bound `DaemonCommandRouter.rememberAggregateMeshStatus`. */
39
+ rememberAggregateMeshStatus: (meshId: string, snapshot: any, refreshReason: string) => any;
40
+ /**
41
+ * Bound `DaemonCommandRouter.execute`. `get_mesh_review_inbox` re-enters the
42
+ * router with a `mesh_status` refresh to obtain computed node fields; this is
43
+ * the same self-call the inlined case made.
44
+ */
45
+ execute: (cmd: string, args: any, source?: string) => Promise<CommandRouterResult>;
46
+ /** Router's aggregate-status memory cache (`.has()` probe in mesh_status). */
47
+ aggregateMeshStatusCache: Map<string, {
48
+ builtAt: number;
49
+ snapshot: any;
50
+ queueRevision: string;
51
+ }>;
52
+ /** Router's running-refine-job table (surfaced as activeRefineJobs in mesh_status). */
53
+ runningRefineJobs: Map<string, MeshRefineJobHandle>;
54
+ /** Router's inline-mesh cache (launch_mesh_coordinator caches cloud inline mesh). */
55
+ inlineMeshCache: Map<string, any>;
56
+ /** Router's mesh git-probe cache (shared probe dedup for mesh_status). */
57
+ meshGitProbeCache: MeshGitProbeCache;
58
+ }
59
+ export type HighFamilyHandler = (ctx: HighFamilyContext, args: any) => Promise<CommandRouterResult | null>;
60
+ export type HighFamilyRegistry = Map<string, HighFamilyHandler>;
@@ -14,6 +14,7 @@ import { DaemonCliManager } from './cli-manager.js';
14
14
  import type { ProviderLoader } from '../providers/provider-loader.js';
15
15
  import type { ProviderInstanceManager } from '../providers/provider-instance-manager.js';
16
16
  import { SessionRegistry } from '../sessions/registry.js';
17
+ export declare function readProviderPriorityFromPolicy(policy: unknown): string[];
17
18
  /**
18
19
  * Normalize a providerRoles array (RepoMeshNodePolicy.providerRoles) from raw
19
20
  * tool args. Each entry binds a providerType to an optional `maxParallel` cap.
@@ -28,8 +29,42 @@ export declare function normalizeProviderRoles(value: unknown): Array<{
28
29
  }>;
29
30
  export declare function readObjectRecord(value: unknown): Record<string, any>;
30
31
  export declare function readStringValue(...values: unknown[]): string | undefined;
32
+ export declare function readBooleanValue(...values: unknown[]): boolean | undefined;
33
+ export declare function summarizeRepoMeshStatusDebug(status: any): Record<string, unknown>;
34
+ export declare function logRepoMeshStatusDebug(event: string, fields: Record<string, unknown>): void;
31
35
  export declare function buildMeshNodeDisplayLabel(node: Record<string, unknown>, nodeId: string, providerPriority: string[]): string;
32
36
  export declare function readMeshNodeMachineId(node: Record<string, unknown>): string | undefined;
37
+ export declare function readMeshNodeHostname(node: Record<string, unknown>): string | undefined;
38
+ export declare function buildMeshNodeMachineIdentity(node: Record<string, unknown>, opts: {
39
+ localMachineId?: string;
40
+ localDaemonId?: string;
41
+ coordinatorHostname?: string;
42
+ isSelfNode?: boolean;
43
+ }): Record<string, unknown>;
44
+ export declare function buildInlineMeshTransitGitStatus(node: any): Record<string, unknown> | undefined;
45
+ export declare function buildLivePeerGitConnection(connection: Record<string, unknown>, timestamp?: string): Record<string, unknown>;
46
+ export declare function recordInlineMeshDirectGitTruth(node: any, git: Record<string, unknown>, source: 'selected_coordinator_local_git' | 'selected_coordinator_mesh_p2p_git'): {
47
+ reporterPlatform: string | null;
48
+ reporterArch: string | null;
49
+ };
50
+ /**
51
+ * Persist the live self-reported platform/arch onto the local meshes.json node
52
+ * record so capability-tag os=/arch= self-heals across coordinator restarts.
53
+ *
54
+ * The in-memory stamp done by recordInlineMeshDirectGitTruth lives on the
55
+ * mesh_status assembly object and is discarded after the response; only a
56
+ * `local_config` mesh has a backing meshes.json node to write through to. Inline
57
+ * cache/bootstrap meshes have no local node to update, so we no-op for them.
58
+ * Fire-and-forget (same pattern as the worktreeBootstrap writer) — a persistence
59
+ * failure must never block the status response.
60
+ */
61
+ export declare function persistNodeReporterPlatform(meshSource: 'inline_cache' | 'inline_bootstrap' | 'local_config', mesh: any, nodeId: string | undefined, reporter: {
62
+ reporterPlatform: string | null;
63
+ reporterArch: string | null;
64
+ }): void;
65
+ export declare function deriveMeshNodeHealthFromGit(git: Record<string, unknown> | null | undefined): 'online' | 'dirty' | 'degraded';
66
+ export declare function applyInlineMeshBranchConvergence(mesh: any, node: any, status: Record<string, unknown>): void;
67
+ export declare function summarizeInlineMeshBranchConvergence(nodes: Array<Record<string, unknown>>): Record<string, unknown>;
33
68
  /**
34
69
  * Resolve the owning-node attribution for a mesh node record so a coordinator can
35
70
  * stamp the TRUE owner onto a synthetic session entry instead of letting the
@@ -43,6 +78,14 @@ export declare function resolveMeshNodeAttribution(node: unknown): {
43
78
  machineName?: string;
44
79
  };
45
80
  export declare function readCachedInlineMeshActiveSessionDetails(node: any): Array<Record<string, unknown>>;
81
+ export declare function finalizeMeshNodeStatus(args: {
82
+ status: Record<string, unknown>;
83
+ node: any;
84
+ daemonId?: string;
85
+ isSelfNode: boolean;
86
+ }): void;
87
+ export declare const MESH_DIRECT_PROBE_TIMEOUT_MS: number;
88
+ export declare const MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS: number;
46
89
  /**
47
90
  * De-duplicates and rate-limits per-peer git_status probes so a single mesh
48
91
  * refresh — or a burst of refreshes from the dashboard auto-retry loop — cannot
@@ -73,6 +116,29 @@ export declare class MeshGitProbeCache {
73
116
  */
74
117
  probe(daemonId: string, workspace: string, probe: () => Promise<Record<string, unknown> | null>): Promise<Record<string, unknown> | null>;
75
118
  }
119
+ /**
120
+ * Probe a remote peer's git_status with a bounded retry budget, but only while
121
+ * the peer is reported `connected`. A single slow (often TURN-relayed) peer can
122
+ * exceed one probe window; retrying — with the connection re-checked before each
123
+ * attempt so we abandon a peer that dropped — recovers it without blocking the
124
+ * mesh forever. Shared by the bootstrap hydrate path and the per-node render
125
+ * path so both treat a connected-but-slow peer identically.
126
+ *
127
+ * Returns the git status on success, or null if every attempt failed/timed out
128
+ * (caller decides how to classify). `getConnection` is consulted before each
129
+ * attempt; a non-`connected` state short-circuits the retry loop (the very first
130
+ * attempt always runs so a missing connection getter still gets one try).
131
+ */
132
+ export declare function probeRemoteMeshGitStatusWithRetry(args: {
133
+ dispatchMeshCommand?: (daemonId: string, cmd: string, args: Record<string, unknown>) => Promise<unknown>;
134
+ daemonId: string;
135
+ workspace: string;
136
+ timeoutMs: number;
137
+ /** Per-attempt timeout for retries (attempts > 0); defaults to timeoutMs. */
138
+ retryTimeoutMs?: number;
139
+ getConnection?: (daemonId: string) => Record<string, unknown> | null;
140
+ onConnection?: (connection: Record<string, unknown>) => void;
141
+ }): Promise<Record<string, unknown> | null>;
76
142
  export declare function hydrateInlineMeshDirectTruth(args: {
77
143
  mesh: any;
78
144
  meshSource: 'inline_cache' | 'inline_bootstrap' | 'local_config';
@@ -91,6 +157,44 @@ export declare function hydrateInlineMeshDirectTruth(args: {
91
157
  unavailableNodeIds: string[];
92
158
  deadNodeIds: string[];
93
159
  }>;
160
+ export declare function summarizeMeshSessionRecord(record: any): Record<string, unknown>;
161
+ export declare function readLiveMeshNodeWorkspace(args: {
162
+ meshId: string;
163
+ nodeId: string;
164
+ liveSessionRecords: any[];
165
+ allowCoordinatorSession?: boolean;
166
+ }): string;
167
+ export declare function collectLiveMeshSessionRecords(args: {
168
+ meshId: string;
169
+ node: any;
170
+ nodeId: string;
171
+ liveSessionRecords: any[];
172
+ allowCoordinatorSession?: boolean;
173
+ }): any[];
174
+ export declare function buildHistoricalMeshSessions(args: {
175
+ meshId: string;
176
+ nodes: any[];
177
+ liveSessionRecords: any[];
178
+ }): {
179
+ count: number;
180
+ sessions: Record<string, unknown>[];
181
+ instruction: string;
182
+ } | undefined;
183
+ export declare function applyCachedInlineMeshNodeStatus(status: Record<string, unknown>, node: any, options?: {
184
+ skipGit?: boolean;
185
+ skipError?: boolean;
186
+ skipHealth?: boolean;
187
+ }): boolean;
188
+ export declare function resolveProviderTypeFromPriority(args: {
189
+ nodeId: string;
190
+ providerPriority: string[];
191
+ providerLoader: ProviderLoader;
192
+ onStatusChange?: () => void;
193
+ }): Promise<{
194
+ providerType?: string;
195
+ error?: string;
196
+ }>;
197
+ export type MeshCoordinatorConfigFormat = 'claude_mcp_json' | 'hermes_config_yaml';
94
198
  type MeshRefineStageStatus = 'passed' | 'failed' | 'skipped';
95
199
  type MeshRefinePatchEquivalenceSummary = {
96
200
  status: MeshRefineStageStatus;
@@ -149,6 +253,38 @@ type MeshRefineSubmoduleConflictHint = {
149
253
  }>;
150
254
  nextSteps: string[];
151
255
  };
256
+ type MeshRefineAsyncJobStatus = 'accepted' | 'completed' | 'failed';
257
+ export type MeshRefineJobHandle = {
258
+ success: true;
259
+ async: true;
260
+ status: MeshRefineAsyncJobStatus;
261
+ jobId: string;
262
+ interactionId: string;
263
+ meshId: string;
264
+ nodeId: string;
265
+ targetNodeId: string;
266
+ targetDaemonId?: string;
267
+ workspace?: string;
268
+ startedAt: string;
269
+ completedAt?: string;
270
+ duplicate?: boolean;
271
+ retryOfJobId?: string;
272
+ /**
273
+ * The coordinator daemon ID that initiated this refine job.
274
+ * When set, events for this job are scoped to that coordinator's
275
+ * pending-events queue instead of the shared broadcast queue.
276
+ */
277
+ targetCoordinatorDaemonId?: string;
278
+ eventDelivery: {
279
+ pendingEvents: true;
280
+ ledger: true;
281
+ };
282
+ evidence: {
283
+ pendingEventsCommand: 'get_pending_mesh_events';
284
+ ledgerCommand: 'get_mesh_ledger_slice';
285
+ taskHistoryKind: 'task_dispatched' | 'task_completed' | 'task_failed';
286
+ };
287
+ };
152
288
  /**
153
289
  * A spawn-resolution failure is when the executable itself could not be found by
154
290
  * the OS spawn boundary — `spawn <cmd> ENOENT` — as opposed to the command
@@ -270,6 +406,16 @@ export declare function collectFastForwardGitlinkPaths(repoRoot: string, baseHea
270
406
  */
271
407
  export declare function evaluateGitlinkTrivialFastForward(repoRoot: string, baseHead: string, branchHead: string): GitlinkTrivialFastForwardEvaluation;
272
408
  export declare function buildMeshRefineValidationPlan(mesh: any, workspace: string): Record<string, unknown>;
409
+ export declare function getMcpServersKey(format: MeshCoordinatorConfigFormat): 'mcpServers' | 'mcp_servers';
410
+ export declare function parseMeshCoordinatorMcpConfig(text: string, format: MeshCoordinatorConfigFormat): Record<string, any>;
411
+ export declare function serializeMeshCoordinatorMcpConfig(config: Record<string, any>, format: MeshCoordinatorConfigFormat): string;
412
+ export declare function loadHermesCoordinatorBaseConfig(targetConfigPath: string): {
413
+ config: Record<string, any>;
414
+ sourceHome: string;
415
+ sourceConfigPath: string;
416
+ };
417
+ export declare function stripHermesCoordinatorTempModelProviderOverrides(config: Record<string, any>): Record<string, any>;
418
+ export declare function copyHermesCoordinatorCredentialFiles(sourceHome: string, targetHome: string): void;
273
419
  export interface SessionHostControlPlane {
274
420
  getDiagnostics(payload?: {
275
421
  includeSessions?: boolean;
@@ -432,6 +578,17 @@ export declare class DaemonCommandRouter {
432
578
  * executeDaemonCommand('launch_ide').
433
579
  */
434
580
  private buildMedFamilyContext;
581
+ /**
582
+ * Build the HighFamilyContext handed to RF-ROUTER HIGH family handlers. Binds
583
+ * the router-private collaborators those handlers need (mesh resolution, the
584
+ * aggregate-status memory cache + its bound read/write helpers, the
585
+ * running-refine-job table, inline-mesh + git-probe caches, and the router's
586
+ * own `execute` for the get_mesh_review_inbox mesh_status re-entry). HIGH
587
+ * handlers reach more router-owned state than MED, but the binding shape is
588
+ * the same: bound methods + direct field references, none reachable from
589
+ * `deps`.
590
+ */
591
+ private buildHighFamilyContext;
435
592
  private requireMeshHostMutationOwner;
436
593
  private updateInlineMeshNode;
437
594
  private removeInlineMeshNode;
@@ -482,7 +639,58 @@ export declare class DaemonCommandRouter {
482
639
  * so the job runs to completion automatically without coordinator intervention.
483
640
  */
484
641
  resumePendingRefineJobsOnStartup(): Promise<void>;
642
+ /**
643
+ * Synchronous refinery for a single worktree node — the gate pipeline that
644
+ * validates, preflights (patch-equivalence / submodule-reachability /
645
+ * no-op), merges, aligns submodules, cleans up the worktree node and
646
+ * (optionally) pushes. The body is a flat sequence of stage methods; each
647
+ * stage either returns a terminal CommandRouterResult (gate failure or a
648
+ * successful already-merged short-circuit) or `continue` with the extended
649
+ * context. Behavior — stage order, every early-exit, and every result shape —
650
+ * is identical to the previous single inlined body.
651
+ */
485
652
  private executeMeshRefineNodeSynchronously;
653
+ /**
654
+ * resolve_refs stage: resolve the mesh / worktree node / source node /
655
+ * repoRoot, then the worktree branch, base branch, fetched base head and
656
+ * branch head. Seeds the RefineContext consumed by every later stage.
657
+ */
658
+ private refineResolveRefsStage;
659
+ /**
660
+ * validation stage: run the refinery validation gate (typecheck / test /
661
+ * lint / build per node config) and block on failure or when no allowlisted
662
+ * command was available. On pass, stores the summary on the context.
663
+ */
664
+ private refineValidationStage;
665
+ /**
666
+ * patch_equivalence stage: preflight that the worktree branch's cumulative
667
+ * patch is equivalent to base+branch. On a "behind base" branch, auto-rebase
668
+ * once and re-check; on an empty merge-tree with real branch changes, treat as
669
+ * already-merged-via-another-path and short-circuit to cleanup. Mutates the
670
+ * context's branchHead (after rebase) and patchEquivalence (rebased gate).
671
+ */
672
+ private refinePatchEquivalenceStage;
673
+ /**
674
+ * submodule_reachability stage: verify every submodule gitlink commit that
675
+ * would land via the merge is reachable from its configured remote main
676
+ * branch (optionally auto-publishing when policy allows). Blocks the merge
677
+ * when any commit is unreachable. Stores the result on the context.
678
+ */
679
+ private refineSubmoduleReachabilityStage;
680
+ /**
681
+ * effective_diff stage (no-op guard): block a silent no-op merge where the
682
+ * branch produces no effective root-tree diff against base — typically a
683
+ * submodule that has commits but whose root-level gitlink (pointer) bump was
684
+ * never committed, so the merge would land nothing real on main.
685
+ */
686
+ private refineEffectiveDiffStage;
687
+ /**
688
+ * merge + finalize stage: perform the --no-ff merge, align submodule
689
+ * checkouts after merge, clean up (remove) the worktree node per policy,
690
+ * append the refinery ledger entry, and (unless approval is required) push the
691
+ * base branch. Always terminal — produces the final CommandRouterResult.
692
+ */
693
+ private refineMergeAndFinalizeStage;
486
694
  /**
487
695
  * Batch refinery: converge multiple sibling worktree nodes onto the base branch
488
696
  * in one sequential pipeline, absorbing the rebase + patch-equivalence churn that