@adhdev/daemon-core 0.9.82-rc.5 → 0.9.82-rc.50

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.
@@ -3,15 +3,18 @@ export interface PendingMeshCoordinatorEvent {
3
3
  event: string;
4
4
  meshId: string;
5
5
  nodeLabel: string;
6
+ nodeId?: string;
7
+ workspace?: string;
6
8
  metadataEvent: Record<string, unknown>;
7
9
  queuedAt: number;
8
10
  }
9
- /** Drain and return all pending coordinator events, clearing the queue. */
10
- export declare function drainPendingMeshCoordinatorEvents(): PendingMeshCoordinatorEvent[];
11
+ export declare function queuePendingMeshCoordinatorEvent(event: PendingMeshCoordinatorEvent): boolean;
12
+ /** Drain and return all pending coordinator events for meshId, removing them from disk. */
13
+ export declare function drainPendingMeshCoordinatorEvents(meshId?: string): PendingMeshCoordinatorEvent[];
11
14
  /** Peek at pending coordinator events without draining (non-destructive). */
12
- export declare function getPendingMeshCoordinatorEvents(): readonly PendingMeshCoordinatorEvent[];
13
- /** Explicitly clear all pending coordinator events. */
14
- export declare function clearPendingMeshCoordinatorEvents(): void;
15
+ export declare function getPendingMeshCoordinatorEvents(meshId?: string): readonly PendingMeshCoordinatorEvent[];
16
+ /** Explicitly clear all pending coordinator events for a mesh. */
17
+ export declare function clearPendingMeshCoordinatorEvents(meshId?: string): void;
15
18
  export declare function tryAssignQueueTask(components: DaemonComponents, meshId: string, nodeId: string, sessionId: string, providerType: string): boolean;
16
19
  /**
17
20
  * Triggers a queue check for all nodes in the mesh.
@@ -23,12 +26,21 @@ export declare function handleMeshForwardEvent(components: DaemonComponents, pay
23
26
  forwarded: number;
24
27
  suppressed: boolean;
25
28
  intentionalCleanupStop: boolean;
29
+ duplicateCompletion?: undefined;
30
+ error?: undefined;
31
+ } | {
32
+ success: boolean;
33
+ forwarded: number;
34
+ suppressed: boolean;
35
+ duplicateCompletion: boolean;
36
+ intentionalCleanupStop?: undefined;
26
37
  error?: undefined;
27
38
  } | {
28
39
  success: boolean;
29
40
  forwarded: number;
30
41
  suppressed?: undefined;
31
42
  intentionalCleanupStop?: undefined;
43
+ duplicateCompletion?: undefined;
32
44
  error?: undefined;
33
45
  } | {
34
46
  success: boolean;
@@ -0,0 +1,9 @@
1
+ import type { RepoMeshDaemonRole, RepoMeshHostMetadata, RepoMeshHostStatus } from '../repo-mesh-types.js';
2
+ export declare function normalizeMeshDaemonRole(value: unknown): RepoMeshDaemonRole | undefined;
3
+ export declare function resolveMeshHostStatus(mesh: unknown): RepoMeshHostStatus;
4
+ export declare function isMeshHostOwner(mesh: unknown): boolean;
5
+ export declare function buildMeshHostRequiredFailure(mesh: unknown, operation: string): Record<string, unknown>;
6
+ export declare function requireMeshHostQueueOwner(opts?: {
7
+ ownerRole?: RepoMeshDaemonRole;
8
+ }): void;
9
+ export declare function createDefaultMeshHostMetadata(): RepoMeshHostMetadata;
@@ -13,7 +13,7 @@
13
13
  * Safety: mode 0o600, atomic append via appendFileSync
14
14
  */
15
15
  import { EventEmitter } from 'events';
16
- export type MeshLedgerKind = 'task_dispatched' | 'task_completed' | 'task_failed' | 'task_stalled' | 'task_approval_needed' | 'session_launched' | 'session_auto_launch' | 'session_stopped' | 'checkpoint_created' | 'node_cloned' | 'node_removed' | 'coordinator_started' | 'recovery_attempted' | 'ledger_replicated' | 'ledger_reconciled';
16
+ export type MeshLedgerKind = 'task_dispatched' | 'task_completed' | 'task_failed' | 'task_stalled' | 'task_approval_needed' | 'session_launched' | 'session_auto_launch' | 'session_stopped' | 'checkpoint_created' | 'node_cloned' | 'node_joined' | 'node_removed' | 'coordinator_started' | 'recovery_attempted' | 'ledger_replicated' | 'ledger_reconciled';
17
17
  export interface MeshLedgerEntry {
18
18
  id: string;
19
19
  meshId: string;
@@ -1,3 +1,4 @@
1
+ import type { RepoMeshDaemonRole } from '../repo-mesh-types.js';
1
2
  export type MeshTaskStatus = 'pending' | 'assigned' | 'completed' | 'failed' | 'cancelled';
2
3
  export type MeshActiveTaskStatus = Extract<MeshTaskStatus, 'pending' | 'assigned'>;
3
4
  export type MeshHistoricalTaskStatus = Extract<MeshTaskStatus, 'completed' | 'failed' | 'cancelled'>;
@@ -37,13 +38,16 @@ export interface MeshWorkQueueEntry {
37
38
  createdAt: string;
38
39
  updatedAt: string;
39
40
  }
41
+ export interface MeshQueueMutationOptions {
42
+ ownerRole?: RepoMeshDaemonRole;
43
+ }
40
44
  /**
41
45
  * Add a new task to the mesh queue.
42
46
  */
43
47
  export declare function enqueueTask(meshId: string, message: string, opts?: {
44
48
  targetNodeId?: string;
45
49
  targetSessionId?: string;
46
- }): MeshWorkQueueEntry;
50
+ } & MeshQueueMutationOptions): MeshWorkQueueEntry;
47
51
  /**
48
52
  * Get all tasks in the queue, optionally filtered by status.
49
53
  */
@@ -58,14 +62,14 @@ export declare function claimNextTask(meshId: string, nodeId: string, sessionId:
58
62
  * Update the status of a specific task.
59
63
  * Used when a session completes, fails, or stalls.
60
64
  */
61
- export declare function updateTaskStatus(meshId: string, taskId: string, status: MeshTaskStatus): MeshWorkQueueEntry | null;
65
+ export declare function updateTaskStatus(meshId: string, taskId: string, status: MeshTaskStatus, opts?: MeshQueueMutationOptions): MeshWorkQueueEntry | null;
62
66
  export declare function recordTaskAutoLaunch(meshId: string, taskId: string, autoLaunch: Omit<NonNullable<MeshWorkQueueEntry['autoLaunch']>, 'updatedAt'>): MeshWorkQueueEntry | null;
63
67
  /**
64
68
  * Mark a queue task as manually cancelled without deleting audit history.
65
69
  */
66
70
  export declare function cancelTask(meshId: string, taskId: string, opts?: {
67
71
  reason?: string;
68
- }): MeshWorkQueueEntry | null;
72
+ } & MeshQueueMutationOptions): MeshWorkQueueEntry | null;
69
73
  /**
70
74
  * Return a queue task to pending for retry. By default, dead session targeting
71
75
  * and assigned ownership are cleared so stale assignments do not strand again.
@@ -76,11 +80,13 @@ export declare function requeueTask(meshId: string, taskId: string, opts?: {
76
80
  targetSessionId?: string;
77
81
  clearTargetNode?: boolean;
78
82
  clearTargetSession?: boolean;
79
- }): MeshWorkQueueEntry | null;
83
+ } & MeshQueueMutationOptions): MeshWorkQueueEntry | null;
80
84
  /**
81
85
  * Update the status of the task currently assigned to a specific session.
82
86
  */
83
- export declare function updateSessionTaskStatus(meshId: string, sessionId: string, status: MeshTaskStatus): MeshWorkQueueEntry | null;
87
+ export declare function updateSessionTaskStatus(meshId: string, sessionId: string, status: MeshTaskStatus, opts?: {
88
+ occurredAt?: string;
89
+ }): MeshWorkQueueEntry | null;
84
90
  export interface MeshWorkQueueStats {
85
91
  total: number;
86
92
  active: number;
@@ -0,0 +1,119 @@
1
+ export declare const MESH_REFINE_VALIDATION_CATEGORIES: readonly ["typecheck", "test", "lint", "build"];
2
+ export type MeshRefineValidationCategory = typeof MESH_REFINE_VALIDATION_CATEGORIES[number];
3
+ export interface RepoMeshRefineValidationCommandConfig {
4
+ /** Executable name or a whitespace-tokenized command string. Never executed through a shell. */
5
+ command: string;
6
+ /** Optional explicit argv. Prefer this over shell-like command strings. */
7
+ args?: string[];
8
+ category?: MeshRefineValidationCategory;
9
+ cwd?: string;
10
+ timeoutMs?: number;
11
+ env?: Record<string, string>;
12
+ }
13
+ export interface RepoMeshRefineConfig {
14
+ version: 1;
15
+ validation?: {
16
+ required?: boolean;
17
+ commands?: RepoMeshRefineValidationCommandConfig[];
18
+ };
19
+ }
20
+ export interface MeshRefineValidationCommandPlan {
21
+ command: string;
22
+ args: string[];
23
+ displayCommand: string;
24
+ category: MeshRefineValidationCategory | 'custom';
25
+ source: string;
26
+ cwd?: string;
27
+ timeoutMs?: number;
28
+ env?: Record<string, string>;
29
+ }
30
+ export interface MeshRefineConfigLoadResult {
31
+ config?: RepoMeshRefineConfig;
32
+ source: string;
33
+ sourceType: 'mesh_policy' | 'repo_file' | 'unavailable' | 'invalid';
34
+ path?: string;
35
+ error?: string;
36
+ }
37
+ export interface MeshRefineValidationPlan {
38
+ source: string;
39
+ sourceType: MeshRefineConfigLoadResult['sourceType'];
40
+ commands: MeshRefineValidationCommandPlan[];
41
+ rejectedCommands: Array<Record<string, unknown>>;
42
+ suggestions: RepoMeshRefineValidationCommandConfig[];
43
+ suggestedConfig?: RepoMeshRefineConfig;
44
+ unavailableReason?: string;
45
+ }
46
+ export declare const MESH_REFINE_CONFIG_LOCATIONS: string[];
47
+ export declare const MESH_REFINE_CONFIG_SCHEMA: {
48
+ readonly $schema: "https://json-schema.org/draft/2020-12/schema";
49
+ readonly title: "ADHDev Repo Mesh Refinery Config";
50
+ readonly type: "object";
51
+ readonly additionalProperties: false;
52
+ readonly required: readonly ["version"];
53
+ readonly properties: {
54
+ readonly version: {
55
+ readonly const: 1;
56
+ };
57
+ readonly validation: {
58
+ readonly type: "object";
59
+ readonly additionalProperties: false;
60
+ readonly properties: {
61
+ readonly required: {
62
+ readonly type: "boolean";
63
+ readonly default: true;
64
+ };
65
+ readonly commands: {
66
+ readonly type: "array";
67
+ readonly minItems: 1;
68
+ readonly maxItems: 8;
69
+ readonly items: {
70
+ readonly type: "object";
71
+ readonly additionalProperties: false;
72
+ readonly required: readonly ["command"];
73
+ readonly properties: {
74
+ readonly command: {
75
+ readonly type: "string";
76
+ readonly minLength: 1;
77
+ };
78
+ readonly args: {
79
+ readonly type: "array";
80
+ readonly items: {
81
+ readonly type: "string";
82
+ };
83
+ };
84
+ readonly category: {
85
+ readonly enum: readonly ["typecheck", "test", "lint", "build", "custom"];
86
+ };
87
+ readonly cwd: {
88
+ readonly type: "string";
89
+ };
90
+ readonly timeoutMs: {
91
+ readonly type: "number";
92
+ readonly minimum: 1000;
93
+ readonly maximum: 600000;
94
+ };
95
+ readonly env: {
96
+ readonly type: "object";
97
+ readonly additionalProperties: {
98
+ readonly type: "string";
99
+ };
100
+ };
101
+ };
102
+ };
103
+ };
104
+ };
105
+ };
106
+ };
107
+ };
108
+ export declare function validateMeshRefineConfig(config: unknown, source?: string): {
109
+ valid: boolean;
110
+ errors: string[];
111
+ commands: MeshRefineValidationCommandPlan[];
112
+ rejectedCommands: Array<Record<string, unknown>>;
113
+ };
114
+ export declare function loadMeshRefineConfig(mesh: any, workspace: string): MeshRefineConfigLoadResult;
115
+ export declare function suggestMeshRefineConfig(mesh: any, workspace: string): {
116
+ suggestions: RepoMeshRefineValidationCommandConfig[];
117
+ suggestedConfig?: RepoMeshRefineConfig;
118
+ };
119
+ export declare function resolveMeshRefineValidationPlan(mesh: any, workspace: string): MeshRefineValidationPlan;
@@ -1,4 +1,5 @@
1
1
  import type { ChatMessage } from '../types.js';
2
+ export declare const DEFAULT_FINAL_SUMMARY_MAX_CHARS = 4000;
2
3
  export declare function extractFinalSummaryFromMessages(messages: ChatMessage[] | null | undefined, maxChars?: number): string;
3
4
  export declare const BUILTIN_CHAT_MESSAGE_KINDS: readonly ["standard", "thought", "tool", "terminal", "system"];
4
5
  export type BuiltinChatMessageKind = typeof BUILTIN_CHAT_MESSAGE_KINDS[number];
@@ -19,10 +19,37 @@ export interface RepoMesh {
19
19
  defaultBranch?: string;
20
20
  policy: RepoMeshPolicy;
21
21
  coordinator: RepoMeshCoordinatorConfig;
22
+ meshHost?: RepoMeshHostMetadata;
22
23
  projectContext: ProjectContextSnapshot;
23
24
  nodes: RepoMeshNode[];
24
25
  status: 'active' | 'archived' | 'deleted';
25
26
  }
27
+ export type RepoMeshDaemonRole = 'host' | 'member';
28
+ export interface RepoMeshHostPairingMetadata {
29
+ status: 'not_configured' | 'pairing' | 'paired' | 'rejected' | 'revoked';
30
+ tokenId?: string;
31
+ joinedAt?: string;
32
+ lastPairedAt?: string;
33
+ lastRejectedAt?: string;
34
+ expiresAt?: string;
35
+ }
36
+ export interface RepoMeshHostMetadata {
37
+ /** Local daemon role for this mesh. Missing metadata defaults to host for standalone compatibility. */
38
+ role: RepoMeshDaemonRole;
39
+ /** Daemon that owns mesh truth/status/git/queue/session/ledger/coordinator ownership. */
40
+ hostDaemonId?: string;
41
+ /** Mesh node that represents the host daemon, when known. */
42
+ hostNodeId?: string;
43
+ /** Future standalone manual pairing endpoint entered by member daemons. */
44
+ hostAddress?: string;
45
+ /** Redacted pairing state only; raw join tokens must not be persisted here. */
46
+ pairing?: RepoMeshHostPairingMetadata;
47
+ }
48
+ export interface RepoMeshHostStatus extends RepoMeshHostMetadata {
49
+ canOwnCoordinator: boolean;
50
+ canOwnQueue: boolean;
51
+ defaulted: boolean;
52
+ }
26
53
  export interface RepoMeshNode {
27
54
  id: string;
28
55
  daemonId: string;
@@ -37,6 +64,7 @@ export interface RepoMeshNode {
37
64
  effectiveCapabilities: RepoMeshNodeCapabilities;
38
65
  policy: RepoMeshNodePolicy;
39
66
  health: RepoMeshNodeHealth;
67
+ role?: RepoMeshDaemonRole;
40
68
  status: 'enabled' | 'disabled' | 'removed';
41
69
  }
42
70
  export type RepoMeshNodeHealth = 'online' | 'offline' | 'degraded' | 'dirty' | 'wrong_branch' | 'unknown';
@@ -185,6 +213,7 @@ export interface LocalMeshEntry {
185
213
  defaultBranch?: string;
186
214
  policy: RepoMeshPolicy;
187
215
  coordinator: RepoMeshCoordinatorConfig;
216
+ meshHost?: RepoMeshHostMetadata;
188
217
  nodes: LocalMeshNodeEntry[];
189
218
  createdAt: string;
190
219
  updatedAt: string;
@@ -206,21 +235,152 @@ export interface LocalMeshNodeEntry {
206
235
  clonedFromNodeId?: string;
207
236
  /** Optional associated/external repos configured as node metadata. */
208
237
  relatedRepos?: RepoMeshRelatedRepo[];
238
+ role?: RepoMeshDaemonRole;
209
239
  }
210
240
  export interface RepoMeshStatus {
211
241
  meshId: string;
212
242
  meshName: string;
213
243
  repoIdentity: string;
244
+ defaultBranch?: string;
214
245
  refreshedAt: string;
246
+ meshHost?: RepoMeshHostStatus;
215
247
  nodes: RepoMeshNodeStatus[];
248
+ queue?: RepoMeshQueueStatus;
249
+ ledger?: RepoMeshLedgerStatus;
250
+ }
251
+ export interface RepoMeshSessionStatus {
252
+ sessionId: string;
253
+ providerType?: string;
254
+ state?: string;
255
+ lifecycle?: 'starting' | 'running' | 'stopping' | 'stopped' | 'failed' | 'interrupted';
256
+ surfaceKind?: 'live_runtime' | 'recovery_snapshot' | 'inactive_record';
257
+ recoveryState?: string | null;
258
+ workspace?: string | null;
259
+ title?: string | null;
260
+ lastActivityAt?: string | null;
261
+ isCached?: boolean;
262
+ }
263
+ export type RepoMeshPeerConnectionState = 'self' | 'connected' | 'connecting' | 'disconnected' | 'failed' | 'closed' | 'unknown';
264
+ export type RepoMeshPeerConnectionTransport = 'local' | 'direct' | 'relay' | 'unknown';
265
+ export interface RepoMeshPeerConnectionStatus {
266
+ perspective: 'selected_coordinator';
267
+ source: 'mesh_peer_status' | 'not_reported';
268
+ state: RepoMeshPeerConnectionState;
269
+ transport: RepoMeshPeerConnectionTransport;
270
+ reported: boolean;
271
+ reason?: string;
272
+ lastStateChangeAt?: string;
273
+ lastConnectedAt?: string;
274
+ lastCommandAt?: string;
216
275
  }
217
276
  export interface RepoMeshNodeStatus {
218
277
  nodeId: string;
219
278
  machineLabel: string;
220
279
  workspace: string;
280
+ repoRoot?: string;
281
+ daemonId?: string;
282
+ machineId?: string;
283
+ role?: RepoMeshDaemonRole;
284
+ machineStatus?: string;
285
+ isLocalWorktree?: boolean;
286
+ worktreeBranch?: string;
221
287
  health: RepoMeshNodeHealth;
222
288
  git?: GitRepoStatus;
289
+ /**
290
+ * True when the selected coordinator has evidence that a peer git probe is still
291
+ * in flight or just timed out during initial mesh handshake, so callers should
292
+ * treat missing git data as pending instead of authoritative absence.
293
+ */
294
+ gitProbePending?: boolean;
223
295
  providers: string[];
224
296
  activeSessions: string[];
297
+ activeSessionDetails?: RepoMeshSessionStatus[];
298
+ providerPriority?: string[];
299
+ launchReady?: boolean;
300
+ lastSeenAt?: string;
301
+ updatedAt?: string;
302
+ connection?: RepoMeshPeerConnectionStatus;
225
303
  error?: string;
226
304
  }
305
+ export type RepoMeshQueueTaskStatus = 'pending' | 'assigned' | 'completed' | 'failed' | 'cancelled';
306
+ export interface RepoMeshQueueTask {
307
+ id: string;
308
+ meshId: string;
309
+ message: string;
310
+ status: RepoMeshQueueTaskStatus;
311
+ targetNodeId?: string;
312
+ targetSessionId?: string;
313
+ assignedNodeId?: string;
314
+ assignedSessionId?: string;
315
+ cancelReason?: string;
316
+ cancelledAt?: string;
317
+ requeueReason?: string;
318
+ requeuedAt?: string;
319
+ requeueCount?: number;
320
+ autoLaunch?: {
321
+ status: 'skipped' | 'started' | 'failed' | 'completed';
322
+ reason?: string;
323
+ nodeId?: string;
324
+ providerType?: string;
325
+ sessionId?: string;
326
+ updatedAt: string;
327
+ };
328
+ dispatchTimestamp?: string;
329
+ createdAt: string;
330
+ updatedAt: string;
331
+ }
332
+ export interface RepoMeshQueueSummary {
333
+ total: number;
334
+ active: number;
335
+ historical: number;
336
+ pending: number;
337
+ assigned: number;
338
+ completed: number;
339
+ failed: number;
340
+ cancelled: number;
341
+ activeCounts: {
342
+ pending: number;
343
+ assigned: number;
344
+ };
345
+ historicalCounts: {
346
+ completed: number;
347
+ failed: number;
348
+ cancelled: number;
349
+ };
350
+ activeAssignments: Array<{
351
+ id: string;
352
+ nodeId?: string;
353
+ sessionId?: string;
354
+ message: string;
355
+ }>;
356
+ }
357
+ export interface RepoMeshQueueStatus {
358
+ tasks: RepoMeshQueueTask[];
359
+ summary: RepoMeshQueueSummary;
360
+ }
361
+ export interface RepoMeshLedgerEntryStatus {
362
+ id: string;
363
+ meshId: string;
364
+ timestamp: string;
365
+ kind: string;
366
+ nodeId?: string;
367
+ sessionId?: string;
368
+ providerType?: string;
369
+ payload: Record<string, unknown>;
370
+ }
371
+ export interface RepoMeshLedgerSummaryStatus {
372
+ meshId: string;
373
+ totalEntries: number;
374
+ taskDispatched: number;
375
+ taskCompleted: number;
376
+ taskFailed: number;
377
+ taskStalled: number;
378
+ sessionLaunched: number;
379
+ checkpointCreated: number;
380
+ lastActivityAt: string | null;
381
+ recentFailures: number;
382
+ }
383
+ export interface RepoMeshLedgerStatus {
384
+ entries: RepoMeshLedgerEntryStatus[];
385
+ summary: RepoMeshLedgerSummaryStatus;
386
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.82-rc.5",
3
+ "version": "0.9.82-rc.50",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -86,6 +86,8 @@ export interface DaemonInitConfig {
86
86
 
87
87
  /** Relays a command to a remote mesh node daemon */
88
88
  dispatchMeshCommand?: (daemonId: string, command: string, args: Record<string, unknown>) => Promise<any>;
89
+ /** Returns selected-coordinator mesh peer telemetry for a target daemon when available. */
90
+ getMeshPeerConnectionStatus?: (daemonId: string) => Record<string, unknown> | null;
89
91
  }
90
92
 
91
93
  // ─── Result ───
@@ -306,6 +308,8 @@ export async function initDaemonComponents(config: DaemonInitConfig): Promise<Da
306
308
  sessionHostControl: config.sessionHostControl,
307
309
  statusInstanceId: config.statusInstanceId,
308
310
  statusVersion: config.statusVersion,
311
+ getMeshPeerConnectionStatus: config.getMeshPeerConnectionStatus,
312
+ dispatchMeshCommand: config.dispatchMeshCommand,
309
313
  getCdpLogFn: config.getCdpLogFn || ((ideType: string) => LOG.forComponent(`CDP:${ideType}`).asLogFn()),
310
314
  });
311
315