@adhdev/daemon-core 0.9.82-rc.364 → 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.
Files changed (41) hide show
  1. package/dist/commands/high-family/index.d.ts +3 -0
  2. package/dist/commands/high-family/mesh-coordinator-launch.d.ts +2 -0
  3. package/dist/commands/high-family/mesh-events.d.ts +2 -0
  4. package/dist/commands/high-family/mesh-status.d.ts +2 -0
  5. package/dist/commands/high-family/types.d.ts +60 -0
  6. package/dist/commands/med-family/cli-agent.d.ts +2 -0
  7. package/dist/commands/med-family/fast-forward.d.ts +2 -0
  8. package/dist/commands/med-family/ide.d.ts +10 -0
  9. package/dist/commands/med-family/index.d.ts +3 -0
  10. package/dist/commands/med-family/mesh-crud.d.ts +2 -0
  11. package/dist/commands/med-family/mesh-host-pairing.d.ts +2 -0
  12. package/dist/commands/med-family/mesh-queue.d.ts +2 -0
  13. package/dist/commands/med-family/types.d.ts +116 -0
  14. package/dist/commands/router.d.ts +291 -0
  15. package/dist/index.js +3824 -3565
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +3811 -3553
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/mesh/mesh-events-coordinator.d.ts +8 -0
  20. package/dist/system/hash.d.ts +8 -0
  21. package/package.json +2 -2
  22. package/src/commands/cli-manager.ts +30 -3
  23. package/src/commands/high-family/index.ts +28 -0
  24. package/src/commands/high-family/mesh-coordinator-launch.ts +592 -0
  25. package/src/commands/high-family/mesh-events.ts +47 -0
  26. package/src/commands/high-family/mesh-status.ts +639 -0
  27. package/src/commands/high-family/types.ts +76 -0
  28. package/src/commands/med-family/cli-agent.ts +218 -0
  29. package/src/commands/med-family/fast-forward.ts +198 -0
  30. package/src/commands/med-family/ide.ts +163 -0
  31. package/src/commands/med-family/index.ts +35 -0
  32. package/src/commands/med-family/mesh-crud.ts +788 -0
  33. package/src/commands/med-family/mesh-host-pairing.ts +234 -0
  34. package/src/commands/med-family/mesh-queue.ts +131 -0
  35. package/src/commands/med-family/types.ts +120 -0
  36. package/src/commands/mesh-coordinator.ts +2 -2
  37. package/src/commands/router.ts +328 -2847
  38. package/src/config/mesh-config.ts +3 -2
  39. package/src/mesh/mesh-active-work.ts +59 -81
  40. package/src/mesh/mesh-events-coordinator.ts +35 -1
  41. package/src/system/hash.ts +23 -0
@@ -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>;
@@ -0,0 +1,2 @@
1
+ import type { MedFamilyHandler } from './types.js';
2
+ export declare const cliAgentHandlers: Record<string, MedFamilyHandler>;
@@ -0,0 +1,2 @@
1
+ import type { MedFamilyHandler } from './types.js';
2
+ export declare const fastForwardHandlers: Record<string, MedFamilyHandler>;
@@ -0,0 +1,10 @@
1
+ import type { CommandRouterResult } from '../router.js';
2
+ import type { MedFamilyContext, MedFamilyHandler } from './types.js';
3
+ /**
4
+ * IDE launch + CDP connect. Lifted verbatim from the original `launch_ide` switch
5
+ * case so restart_session / restart_ide can call it directly instead of recursing
6
+ * through executeDaemonCommand. Reads the router's CDP managers and detection
7
+ * caches via ctx.deps.
8
+ */
9
+ export declare function launchIde(ctx: MedFamilyContext, args: any): Promise<CommandRouterResult>;
10
+ export declare const ideHandlers: Record<string, MedFamilyHandler>;
@@ -0,0 +1,3 @@
1
+ import type { MedFamilyRegistry } from './types.js';
2
+ export type { MedFamilyContext, MedFamilyHandler, MedFamilyRegistry } from './types.js';
3
+ export declare const medFamilyRegistry: MedFamilyRegistry;
@@ -0,0 +1,2 @@
1
+ import type { MedFamilyHandler } from './types.js';
2
+ export declare const meshCrudHandlers: Record<string, MedFamilyHandler>;
@@ -0,0 +1,2 @@
1
+ import type { MedFamilyHandler } from './types.js';
2
+ export declare const meshHostPairingHandlers: Record<string, MedFamilyHandler>;
@@ -0,0 +1,2 @@
1
+ import type { MedFamilyHandler } from './types.js';
2
+ export declare const meshQueueHandlers: Record<string, MedFamilyHandler>;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * RF-ROUTER MED family — shared types for the extracted medium-coupling command
3
+ * handlers. Like the LOW family, each handler is a function of (context, args)
4
+ * that returns the exact CommandRouterResult the original `executeDaemonCommand`
5
+ * switch case returned, so the router facade is unchanged.
6
+ *
7
+ * Unlike the LOW family, MED handlers need a handful of router-private
8
+ * collaborators (mesh resolution, owner gating, inline-cache mutation, worktree /
9
+ * session cleanup, refine job starters, IDE launch). The router binds these onto
10
+ * MedFamilyContext at dispatch; they are NOT reachable from `deps`. The IDE family
11
+ * also needs `launchIde` to break the original `launch_ide`/`restart_*`
12
+ * self-recursion through executeDaemonCommand.
13
+ *
14
+ * Registry dispatch: DaemonCommandRouter.executeDaemonCommand looks up the cmd in
15
+ * medFamilyRegistry BEFORE its switch; a hit returns the handler result, a miss
16
+ * falls through to the remaining switch (and ultimately CommandHandler delegation).
17
+ */
18
+ import type { CommandRouterDeps, CommandRouterResult, MeshGitProbeCache } from '../router.js';
19
+ import type { RepoMeshSessionCleanupMode } from '../../repo-mesh-types.js';
20
+ import type { WorktreeBootstrapState } from '../../mesh/worktree-bootstrap-config.js';
21
+ /** Mesh record resolved from the router's inline-mesh cache + local config. */
22
+ export type ResolvedMeshForCommand = {
23
+ mesh: any;
24
+ inline: boolean;
25
+ source: 'inline_cache' | 'inline_bootstrap' | 'local_config';
26
+ } | null;
27
+ /** Result of the router's local worktree-node cleanup. */
28
+ export type CleanupLocalWorktreeNodeResult = {
29
+ success: true;
30
+ skipped?: boolean;
31
+ removedPath?: string;
32
+ repoRoot?: string;
33
+ reason?: string;
34
+ fallback?: string;
35
+ forced?: boolean;
36
+ convergence?: Record<string, unknown>;
37
+ recovered?: boolean;
38
+ residue?: boolean;
39
+ residueWarning?: string;
40
+ residueError?: string;
41
+ } | {
42
+ success: false;
43
+ code: string;
44
+ error: string;
45
+ recoveryHint: string;
46
+ convergence?: Record<string, unknown>;
47
+ };
48
+ /**
49
+ * Router-private collaborators injected at dispatch. Each is a bound method or
50
+ * field of DaemonCommandRouter; handlers that don't need a given collaborator
51
+ * simply ignore it. The router owns this instance state (inline-mesh cache,
52
+ * aggregate-status cache, session/worktree cleanup, refine jobs), so it cannot be
53
+ * read from `deps` — the registry receives bound references instead.
54
+ */
55
+ export interface MedFamilyContext {
56
+ deps: CommandRouterDeps;
57
+ /** Bound `DaemonCommandRouter.getMeshForCommand`. */
58
+ getMeshForCommand: (meshId: string, inlineMesh?: unknown, options?: {
59
+ preferInline?: boolean;
60
+ }) => Promise<ResolvedMeshForCommand>;
61
+ /** Bound `DaemonCommandRouter.getCachedInlineMesh`. */
62
+ getCachedInlineMesh: (meshId: string, inlineMesh?: unknown) => any | undefined;
63
+ /** Bound `DaemonCommandRouter.requireMeshHostMutationOwner` (owner gate). */
64
+ requireMeshHostMutationOwner: (meshId: string, inlineMesh: unknown, operation: string) => Promise<CommandRouterResult | null>;
65
+ /** Bound `DaemonCommandRouter.invalidateAggregateMeshStatus`. */
66
+ invalidateAggregateMeshStatus: (meshId: string) => void;
67
+ /** Bound `DaemonCommandRouter.updateInlineMeshNode`. */
68
+ updateInlineMeshNode: (meshId: string, mesh: any, node: any) => void;
69
+ /** Bound `DaemonCommandRouter.removeInlineMeshNode`. */
70
+ removeInlineMeshNode: (meshId: string, mesh: any, nodeId: string) => boolean;
71
+ /** Bound `DaemonCommandRouter.normalizeMeshSessionCleanupMode`. */
72
+ normalizeMeshSessionCleanupMode: (value: unknown) => RepoMeshSessionCleanupMode;
73
+ /** Bound `DaemonCommandRouter.cleanupMeshSessions`. */
74
+ cleanupMeshSessions: (args: {
75
+ meshId: string;
76
+ nodeId: string;
77
+ node: any;
78
+ mode: RepoMeshSessionCleanupMode;
79
+ sessionIds?: string[];
80
+ dryRun?: boolean;
81
+ source?: 'mesh_cleanup_sessions' | 'mesh_remove_node';
82
+ }) => Promise<{
83
+ success: boolean;
84
+ [key: string]: unknown;
85
+ }>;
86
+ /** Bound `DaemonCommandRouter.cleanupLocalWorktreeNode`. */
87
+ cleanupLocalWorktreeNode: (args: {
88
+ mesh: any;
89
+ node: any;
90
+ nodeId: string;
91
+ force?: boolean;
92
+ }) => Promise<CleanupLocalWorktreeNodeResult>;
93
+ /** Bound `DaemonCommandRouter.startMeshRefineJob` (async execute path). */
94
+ startMeshRefineJob: (meshId: string, nodeId: string, args: any) => Promise<CommandRouterResult>;
95
+ /** Bound `DaemonCommandRouter.batchRefineMeshNodes` (dry-run batch plan). */
96
+ batchRefineMeshNodes: (meshId: string, requestedNodeIds: string[] | undefined, args: any) => Promise<CommandRouterResult>;
97
+ /** Bound `DaemonCommandRouter.startMeshRefineBatchJob` (async batch execute). */
98
+ startMeshRefineBatchJob: (meshId: string, requestedNodeIds: string[] | undefined, args: any) => Promise<CommandRouterResult>;
99
+ /** Bound `DaemonCommandRouter.stopIde` (CDP disconnect + cleanup + optional kill). */
100
+ stopIde: (ideType: string, killProcess?: boolean) => Promise<void>;
101
+ /**
102
+ * Module-level `launchIde` helper bound to this context. The original
103
+ * `launch_ide` case body, lifted into a free function so `restart_session` /
104
+ * `restart_ide` can invoke the IDE launch directly instead of recursing
105
+ * through `executeDaemonCommand('launch_ide')` (which would re-enter the
106
+ * registry). Byte-identical to the original case body.
107
+ */
108
+ launchIde: (args: any) => Promise<CommandRouterResult>;
109
+ /** Router's inline-mesh cache (read/write of resolved mesh records). */
110
+ inlineMeshCache: Map<string, any>;
111
+ /** Router's mesh git-probe cache (reused direct-truth probes for get_mesh). */
112
+ meshGitProbeCache: MeshGitProbeCache;
113
+ }
114
+ export type MedFamilyHandler = (ctx: MedFamilyContext, args: any) => Promise<CommandRouterResult | null>;
115
+ export type MedFamilyRegistry = Map<string, MedFamilyHandler>;
116
+ export type { WorktreeBootstrapState };
@@ -14,7 +14,57 @@ 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[];
18
+ /**
19
+ * Normalize a providerRoles array (RepoMeshNodePolicy.providerRoles) from raw
20
+ * tool args. Each entry binds a providerType to an optional `maxParallel` cap.
21
+ * Entries without a usable providerType are dropped; the last entry wins on
22
+ * duplicate providerType. Returns [] when no valid entries — callers then omit
23
+ * the field entirely (full backward compat). Routing is governed by required_tags;
24
+ * any legacy `role` field on the input is ignored.
25
+ */
26
+ export declare function normalizeProviderRoles(value: unknown): Array<{
27
+ providerType: string;
28
+ maxParallel?: number;
29
+ }>;
30
+ export declare function readObjectRecord(value: unknown): Record<string, any>;
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;
17
35
  export declare function buildMeshNodeDisplayLabel(node: Record<string, unknown>, nodeId: string, providerPriority: string[]): string;
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>;
18
68
  /**
19
69
  * Resolve the owning-node attribution for a mesh node record so a coordinator can
20
70
  * stamp the TRUE owner onto a synthetic session entry instead of letting the
@@ -28,6 +78,123 @@ export declare function resolveMeshNodeAttribution(node: unknown): {
28
78
  machineName?: string;
29
79
  };
30
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;
89
+ /**
90
+ * De-duplicates and rate-limits per-peer git_status probes so a single mesh
91
+ * refresh — or a burst of refreshes from the dashboard auto-retry loop — cannot
92
+ * launch a storm of concurrent/back-to-back `refreshUpstream:true` commands to
93
+ * the same slow peer.
94
+ *
95
+ * Two gates, both keyed by `daemonId::workspace`:
96
+ * - In-flight dedup: a second probe for a key with a probe already running
97
+ * shares (awaits) the in-flight promise instead of issuing a second command.
98
+ * - Recently-probed reuse: a successful probe younger than `reuseMs` is reused
99
+ * verbatim instead of issuing a fresh probe. Failures are NOT cached (so a
100
+ * transient timeout doesn't pin a peer to "no truth" for the whole window).
101
+ *
102
+ * Lives on the router instance so the gate spans separate mesh_status calls,
103
+ * which is exactly where the refresh storm happens.
104
+ */
105
+ export declare class MeshGitProbeCache {
106
+ private readonly reuseMs;
107
+ private readonly now;
108
+ private inflight;
109
+ private recent;
110
+ constructor(reuseMs: number, now?: () => number);
111
+ private key;
112
+ /**
113
+ * Run `probe` for this peer, but reuse a fresh recent result or an in-flight
114
+ * probe for the same key when one is available. `probe` is only invoked when
115
+ * neither gate is satisfied.
116
+ */
117
+ probe(daemonId: string, workspace: string, probe: () => Promise<Record<string, unknown> | null>): Promise<Record<string, unknown> | null>;
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>;
142
+ export declare function hydrateInlineMeshDirectTruth(args: {
143
+ mesh: any;
144
+ meshSource: 'inline_cache' | 'inline_bootstrap' | 'local_config';
145
+ dispatchMeshCommand?: (daemonId: string, cmd: string, args: Record<string, unknown>) => Promise<unknown>;
146
+ getMeshPeerConnectionStatus?: (daemonId: string) => Record<string, unknown> | null;
147
+ statusInstanceId?: string;
148
+ localMachineId?: string;
149
+ probeRemotePeers: boolean;
150
+ probeCache?: MeshGitProbeCache;
151
+ }): Promise<{
152
+ directEvidenceCount: number;
153
+ localConfirmedCount: number;
154
+ peerAttemptedCount: number;
155
+ peerConfirmedCount: number;
156
+ standingEvidenceCount: number;
157
+ unavailableNodeIds: string[];
158
+ deadNodeIds: string[];
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';
31
198
  type MeshRefineStageStatus = 'passed' | 'failed' | 'skipped';
32
199
  type MeshRefinePatchEquivalenceSummary = {
33
200
  status: MeshRefineStageStatus;
@@ -86,6 +253,38 @@ type MeshRefineSubmoduleConflictHint = {
86
253
  }>;
87
254
  nextSteps: string[];
88
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
+ };
89
288
  /**
90
289
  * A spawn-resolution failure is when the executable itself could not be found by
91
290
  * the OS spawn boundary — `spawn <cmd> ENOENT` — as opposed to the command
@@ -206,6 +405,17 @@ export declare function collectFastForwardGitlinkPaths(repoRoot: string, baseHea
206
405
  * passes a regular-file conflict or a diverged (non-ff) gitlink.
207
406
  */
208
407
  export declare function evaluateGitlinkTrivialFastForward(repoRoot: string, baseHead: string, branchHead: string): GitlinkTrivialFastForwardEvaluation;
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;
209
419
  export interface SessionHostControlPlane {
210
420
  getDiagnostics(payload?: {
211
421
  includeSessions?: boolean;
@@ -275,6 +485,15 @@ export interface CommandRouterResult {
275
485
  success: boolean;
276
486
  [key: string]: unknown;
277
487
  }
488
+ /**
489
+ * Confine a spec path to ~/.adhdev/providers, defeating both prefix-bypass
490
+ * (e.g. ".../providers-evil") and symlink escape. Resolves the real path of
491
+ * the *parent* directory (the file may not exist yet for writes), requires the
492
+ * basename to be a literal `*.json`, and re-joins under the verified parent so
493
+ * the returned path can't point outside the tree. Used by get/write_spec_source.
494
+ */
495
+ export declare function normalizeStandaloneHostCommandUrl(hostAddress: string): string;
496
+ export declare function buildMemberJoinNode(mesh: any, args: any, fallbackDaemonId?: string): Record<string, unknown> | null;
278
497
  export declare class DaemonCommandRouter {
279
498
  private deps;
280
499
  /** In-memory cache for cloud-originating meshes passed via inlineMesh.
@@ -349,6 +568,27 @@ export declare class DaemonCommandRouter {
349
568
  private warmInlineMeshCache;
350
569
  private getMeshForCommand;
351
570
  private invalidateAggregateMeshStatus;
571
+ /**
572
+ * Build the MedFamilyContext handed to RF-ROUTER MED family handlers. Binds the
573
+ * router-private collaborators those handlers need (mesh resolution, owner
574
+ * gating, inline-cache mutation, worktree / session cleanup, refine job
575
+ * starters, IDE stop/launch) plus the inline-mesh and git-probe caches. The
576
+ * `launchIde` field closes over the freshly-built context so restart_session /
577
+ * restart_ide invoke the IDE launch directly instead of recursing through
578
+ * executeDaemonCommand('launch_ide').
579
+ */
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;
352
592
  private requireMeshHostMutationOwner;
353
593
  private updateInlineMeshNode;
354
594
  private removeInlineMeshNode;
@@ -399,7 +639,58 @@ export declare class DaemonCommandRouter {
399
639
  * so the job runs to completion automatically without coordinator intervention.
400
640
  */
401
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
+ */
402
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;
403
694
  /**
404
695
  * Batch refinery: converge multiple sibling worktree nodes onto the base branch
405
696
  * in one sequential pipeline, absorbing the rebase + patch-equivalence churn that