@adhdev/daemon-core 0.9.82-rc.136 → 0.9.82-rc.137
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.
- package/dist/cli-adapters/cli-script-runner.d.ts +45 -0
- package/dist/cli-adapters/cli-state-engine.d.ts +154 -0
- package/dist/cli-adapters/provider-cli-adapter.d.ts +73 -74
- package/dist/cli-adapters/provider-cli-shared.d.ts +4 -0
- package/dist/config/chat-history.d.ts +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2591 -1966
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2594 -1974
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/beads-db.d.ts +54 -0
- package/dist/mesh/mesh-active-work.d.ts +7 -1
- package/dist/mesh/mesh-events.d.ts +10 -4
- package/dist/mesh/mesh-ledger.d.ts +21 -1
- package/dist/mesh/mesh-refine-status.d.ts +2 -3
- package/dist/mesh/mesh-work-queue.d.ts +17 -0
- package/dist/mesh/worktree-bootstrap-config.d.ts +2 -4
- package/dist/repo-mesh-types.d.ts +5 -0
- package/package.json +1 -1
- package/src/cli-adapters/cli-script-runner.ts +145 -0
- package/src/cli-adapters/cli-state-engine.ts +957 -0
- package/src/cli-adapters/provider-cli-adapter.d.ts +0 -1
- package/src/cli-adapters/provider-cli-adapter.ts +365 -1397
- package/src/cli-adapters/provider-cli-shared.ts +4 -0
- package/src/commands/chat-commands.ts +17 -1
- package/src/commands/router.ts +8 -0
- package/src/config/chat-history.ts +7 -3
- package/src/git/git-worktree.ts +8 -1
- package/src/index.ts +3 -2
- package/src/mesh/beads-db.ts +305 -2
- package/src/mesh/coordinator-prompt.ts +12 -17
- package/src/mesh/mesh-active-work.ts +162 -59
- package/src/mesh/mesh-events.ts +198 -53
- package/src/mesh/mesh-ledger.ts +321 -105
- package/src/mesh/mesh-refine-status.ts +2 -3
- package/src/mesh/mesh-work-queue.ts +116 -120
- package/src/mesh/worktree-bootstrap-config.ts +17 -4
- package/src/providers/provider-schema.ts +2 -0
- package/src/repo-mesh-types.ts +10 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MeshLedgerEntry } from './mesh-ledger.js';
|
|
2
|
-
import type { MeshWorkQueueEntry } from './mesh-work-queue.js';
|
|
2
|
+
import type { MeshWorkQueueEntry, DirectDispatchRecord } from './mesh-work-queue.js';
|
|
3
3
|
|
|
4
4
|
export type MeshActiveWorkSource = 'queue' | 'direct';
|
|
5
5
|
export type MeshActiveWorkStatus = 'pending' | 'assigned' | 'generating' | 'idle' | 'failed' | 'awaiting_approval';
|
|
@@ -69,6 +69,12 @@ export interface BuildMeshActiveWorkOptions {
|
|
|
69
69
|
meshId: string;
|
|
70
70
|
queue?: MeshWorkQueueEntry[];
|
|
71
71
|
ledgerEntries?: MeshLedgerEntry[];
|
|
72
|
+
/**
|
|
73
|
+
* Active direct dispatches from BeadsDB. When provided, these are used instead of
|
|
74
|
+
* scanning ledger entries for direct dispatches — eliminates the O(n_ledger) scan.
|
|
75
|
+
* Falls back to ledger scanning when not provided.
|
|
76
|
+
*/
|
|
77
|
+
directDispatches?: DirectDispatchRecord[];
|
|
72
78
|
nodes?: any[];
|
|
73
79
|
now?: number;
|
|
74
80
|
/** Include terminal direct rows (idle/failed) for handoff/recent-work surfaces. Defaults false. */
|
|
@@ -218,66 +224,163 @@ export function buildMeshActiveWork(opts: BuildMeshActiveWorkOptions): { activeW
|
|
|
218
224
|
});
|
|
219
225
|
}
|
|
220
226
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
227
|
+
// When BeadsDB direct dispatches are provided, use them for LOCAL dispatches (O(1) indexed).
|
|
228
|
+
// ALSO scan ledger for remote dispatches (P2P) whose taskIds are not in BeadsDB — these
|
|
229
|
+
// are never written to the local BeadsDB since they're dispatched from a remote daemon.
|
|
230
|
+
if (opts.directDispatches !== undefined) {
|
|
231
|
+
const dbTaskIds = new Set(opts.directDispatches.map(d => d.taskId));
|
|
232
|
+
for (const dispatch of opts.directDispatches) {
|
|
233
|
+
const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId ?? undefined, dispatch.sessionId ?? undefined);
|
|
234
|
+
const dbStatus = dispatch.status; // 'dispatched' | 'acked' | 'completed' | 'failed' | 'stale'
|
|
235
|
+
const isTerminal = dbStatus === 'completed' || dbStatus === 'failed' || dbStatus === 'stale';
|
|
236
|
+
const status: MeshActiveWorkStatus = isTerminal
|
|
237
|
+
? (dbStatus === 'completed' ? 'idle' : 'failed')
|
|
238
|
+
: live.status || (dbStatus === 'acked' ? 'generating' : 'assigned');
|
|
239
|
+
const isNoTransition = !isTerminal && !live.status;
|
|
240
|
+
const isIdleUnacknowledged = status === 'idle' && !isTerminal;
|
|
241
|
+
const ledgerOnlyStaleReason = !isTerminal && (isIdleUnacknowledged || isNoTransition || (dispatch.dispatchedToIdleSession && isIdleUnacknowledged))
|
|
242
|
+
? 'direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition'
|
|
243
|
+
: undefined;
|
|
244
|
+
const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !live.staleReason);
|
|
245
|
+
const { title, summary } = summarizeMessage(dispatch.message || '');
|
|
246
|
+
const record: MeshActiveWorkRecord = {
|
|
247
|
+
taskId: dispatch.taskId,
|
|
248
|
+
source: 'direct',
|
|
249
|
+
status,
|
|
250
|
+
nodeId: dispatch.nodeId ?? undefined,
|
|
251
|
+
sessionId: dispatch.sessionId ?? undefined,
|
|
252
|
+
providerType: dispatch.providerType ?? undefined,
|
|
253
|
+
taskTitle: title,
|
|
254
|
+
taskSummary: summary,
|
|
255
|
+
message: dispatch.message,
|
|
256
|
+
taskMode: dispatch.taskMode ?? undefined,
|
|
257
|
+
createdAt: dispatch.dispatchedAt,
|
|
258
|
+
updatedAt: dispatch.updatedAt,
|
|
259
|
+
dispatchedAt: dispatch.dispatchedAt,
|
|
260
|
+
elapsedMs: elapsedSince(dispatch.dispatchedAt, now),
|
|
261
|
+
terminal: isTerminal,
|
|
262
|
+
terminalKind: isTerminal ? (dbStatus === 'completed' ? 'task_completed' : 'task_failed') : undefined,
|
|
263
|
+
terminalAt: isTerminal ? dispatch.updatedAt : undefined,
|
|
264
|
+
staleReason: live.staleReason || ledgerOnlyStaleReason,
|
|
265
|
+
...(isFreshUnacknowledged ? { staleDispatchUnacknowledged: true } : {}),
|
|
266
|
+
};
|
|
267
|
+
if (isTerminal) {
|
|
268
|
+
terminalDirectWork.push(record);
|
|
269
|
+
if (opts.includeTerminalDirect !== true) continue;
|
|
270
|
+
}
|
|
271
|
+
if ((live.staleReason || ledgerOnlyStaleReason) && !isTerminal) {
|
|
272
|
+
staleDirectWork.push(record);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
records.push(record);
|
|
276
|
+
}
|
|
277
|
+
// Also scan ledger for remote dispatches (via p2p_direct) whose taskIds are NOT in BeadsDB.
|
|
278
|
+
// Remote daemons write their own local BeadsDB; this coordinator's BeadsDB only has local dispatches.
|
|
279
|
+
const ledgerEntries = (opts.ledgerEntries || []).slice().sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
|
280
|
+
const terminals = ledgerEntries.filter(entry => TERMINAL_LEDGER_KINDS.has(entry.kind) || entry.kind === 'task_approval_needed');
|
|
281
|
+
for (const dispatch of ledgerEntries.filter(isDirectDispatch)) {
|
|
282
|
+
const taskId = directDispatchTaskId(dispatch);
|
|
283
|
+
if (dbTaskIds.has(taskId)) continue; // already covered by BeadsDB path above
|
|
284
|
+
const terminal = terminals
|
|
285
|
+
.filter(entry => new Date(entry.timestamp).getTime() >= new Date(dispatch.timestamp).getTime())
|
|
286
|
+
.find(entry => terminalMatchesDispatch(entry, dispatch, taskId));
|
|
287
|
+
const terminalStatus = terminal ? statusFromTerminal(terminal) : undefined;
|
|
288
|
+
const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
|
|
289
|
+
const status = terminalStatus || live.status || 'assigned';
|
|
290
|
+
const terminalRow = Boolean(terminal && terminal.kind !== 'task_approval_needed');
|
|
291
|
+
const dispatchedToIdleSession = dispatch.payload?.dispatchedToIdleSession === true;
|
|
292
|
+
const isNoTransition = !terminalStatus && !live.status;
|
|
293
|
+
const isIdleUnacknowledged = status === 'idle';
|
|
294
|
+
const ledgerOnlyStaleReason = !terminalRow && (isIdleUnacknowledged || isNoTransition || (dispatchedToIdleSession && isIdleUnacknowledged))
|
|
295
|
+
? 'direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition'
|
|
296
|
+
: undefined;
|
|
297
|
+
const message = readString(dispatch.payload?.message) || readString(dispatch.payload?.summary) || '';
|
|
298
|
+
const { title, summary } = summarizeMessage(message);
|
|
299
|
+
const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !live.staleReason);
|
|
300
|
+
const record: MeshActiveWorkRecord = {
|
|
301
|
+
taskId,
|
|
302
|
+
source: 'direct',
|
|
303
|
+
status,
|
|
304
|
+
nodeId: dispatch.nodeId,
|
|
305
|
+
sessionId: dispatch.sessionId,
|
|
306
|
+
providerType: dispatch.providerType || readString(dispatch.payload?.providerType),
|
|
307
|
+
taskTitle: readString(dispatch.payload?.taskTitle) || title,
|
|
308
|
+
taskSummary: readString(dispatch.payload?.taskSummary) || summary,
|
|
309
|
+
message,
|
|
310
|
+
taskMode: readString(dispatch.payload?.taskMode),
|
|
311
|
+
createdAt: dispatch.timestamp,
|
|
312
|
+
updatedAt: terminal?.timestamp || dispatch.timestamp,
|
|
313
|
+
dispatchedAt: dispatch.timestamp,
|
|
314
|
+
elapsedMs: elapsedSince(dispatch.timestamp, now),
|
|
315
|
+
terminal: terminalRow,
|
|
316
|
+
terminalKind: terminal?.kind,
|
|
317
|
+
terminalAt: terminal?.timestamp,
|
|
318
|
+
staleReason: live.staleReason || ledgerOnlyStaleReason,
|
|
319
|
+
...(isFreshUnacknowledged ? { staleDispatchUnacknowledged: true } : {}),
|
|
320
|
+
};
|
|
321
|
+
if (terminalRow) {
|
|
322
|
+
terminalDirectWork.push(record);
|
|
323
|
+
if (opts.includeTerminalDirect !== true) continue;
|
|
324
|
+
}
|
|
325
|
+
if ((live.staleReason || ledgerOnlyStaleReason) && !terminalRow) {
|
|
326
|
+
staleDirectWork.push(record);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
records.push(record);
|
|
275
330
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
331
|
+
} else {
|
|
332
|
+
// Full ledger scan: no BeadsDB direct dispatches available (standalone mode or empty).
|
|
333
|
+
const ledgerEntries = (opts.ledgerEntries || []).slice().sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
|
334
|
+
const terminals = ledgerEntries.filter(entry => TERMINAL_LEDGER_KINDS.has(entry.kind) || entry.kind === 'task_approval_needed');
|
|
335
|
+
for (const dispatch of ledgerEntries.filter(isDirectDispatch)) {
|
|
336
|
+
const taskId = directDispatchTaskId(dispatch);
|
|
337
|
+
const terminal = terminals
|
|
338
|
+
.filter(entry => new Date(entry.timestamp).getTime() >= new Date(dispatch.timestamp).getTime())
|
|
339
|
+
.find(entry => terminalMatchesDispatch(entry, dispatch, taskId));
|
|
340
|
+
const terminalStatus = terminal ? statusFromTerminal(terminal) : undefined;
|
|
341
|
+
const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
|
|
342
|
+
const status = terminalStatus || live.status || 'assigned';
|
|
343
|
+
const terminalRow = Boolean(terminal && terminal.kind !== 'task_approval_needed');
|
|
344
|
+
const dispatchedToIdleSession = dispatch.payload?.dispatchedToIdleSession === true;
|
|
345
|
+
const isNoTransition = !terminalStatus && !live.status;
|
|
346
|
+
const isIdleUnacknowledged = status === 'idle';
|
|
347
|
+
const ledgerOnlyStaleReason = !terminalRow && (isIdleUnacknowledged || isNoTransition || (dispatchedToIdleSession && isIdleUnacknowledged))
|
|
348
|
+
? 'direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition'
|
|
349
|
+
: undefined;
|
|
350
|
+
const message = readString(dispatch.payload?.message) || readString(dispatch.payload?.summary) || '';
|
|
351
|
+
const { title, summary } = summarizeMessage(message);
|
|
352
|
+
const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !live.staleReason);
|
|
353
|
+
const record: MeshActiveWorkRecord = {
|
|
354
|
+
taskId,
|
|
355
|
+
source: 'direct',
|
|
356
|
+
status,
|
|
357
|
+
nodeId: dispatch.nodeId,
|
|
358
|
+
sessionId: dispatch.sessionId,
|
|
359
|
+
providerType: dispatch.providerType || readString(dispatch.payload?.providerType),
|
|
360
|
+
taskTitle: readString(dispatch.payload?.taskTitle) || title,
|
|
361
|
+
taskSummary: readString(dispatch.payload?.taskSummary) || summary,
|
|
362
|
+
message,
|
|
363
|
+
taskMode: readString(dispatch.payload?.taskMode),
|
|
364
|
+
createdAt: dispatch.timestamp,
|
|
365
|
+
updatedAt: terminal?.timestamp || dispatch.timestamp,
|
|
366
|
+
dispatchedAt: dispatch.timestamp,
|
|
367
|
+
elapsedMs: elapsedSince(dispatch.timestamp, now),
|
|
368
|
+
terminal: terminalRow,
|
|
369
|
+
terminalKind: terminal?.kind,
|
|
370
|
+
terminalAt: terminal?.timestamp,
|
|
371
|
+
staleReason: live.staleReason || ledgerOnlyStaleReason,
|
|
372
|
+
...(isFreshUnacknowledged ? { staleDispatchUnacknowledged: true } : {}),
|
|
373
|
+
};
|
|
374
|
+
if (terminalRow) {
|
|
375
|
+
terminalDirectWork.push(record);
|
|
376
|
+
if (opts.includeTerminalDirect !== true) continue;
|
|
377
|
+
}
|
|
378
|
+
if ((live.staleReason || ledgerOnlyStaleReason) && !terminalRow) {
|
|
379
|
+
staleDirectWork.push(record);
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
records.push(record);
|
|
279
383
|
}
|
|
280
|
-
records.push(record);
|
|
281
384
|
}
|
|
282
385
|
|
|
283
386
|
records.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|