@adhdev/daemon-core 0.9.82-rc.375 → 0.9.82-rc.377
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/commands/chat-commands-debug-bundle.d.ts +14 -0
- package/dist/commands/chat-commands-read.d.ts +7 -0
- package/dist/commands/chat-commands-scope.d.ts +39 -0
- package/dist/commands/chat-commands-shared.d.ts +33 -0
- package/dist/commands/chat-commands-write.d.ts +14 -0
- package/dist/commands/chat-commands.d.ts +9 -49
- package/dist/index.js +2976 -2943
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2971 -2938
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-event-classify.d.ts +5 -0
- package/dist/mesh/mesh-event-forwarding.d.ts +18 -0
- package/dist/mesh/mesh-events-coordinator.d.ts +4 -92
- package/dist/mesh/mesh-events-utils.d.ts +3 -0
- package/dist/mesh/mesh-ledger-reconciliation.d.ts +0 -1
- package/dist/mesh/mesh-queue-assignment.d.ts +86 -0
- package/dist/mesh/mesh-runtime-store.d.ts +0 -3
- package/dist/providers/native-history/constants.d.ts +12 -0
- package/dist/runtime-defaults.d.ts +2 -0
- package/package.json +2 -2
- package/src/commands/chat-commands-debug-bundle.ts +398 -0
- package/src/commands/chat-commands-read.ts +2327 -0
- package/src/commands/chat-commands-scope.ts +54 -0
- package/src/commands/chat-commands-shared.ts +114 -0
- package/src/commands/chat-commands-write.ts +880 -0
- package/src/commands/chat-commands.ts +20 -3697
- package/src/commands/router.ts +5 -12
- package/src/mesh/mesh-event-classify.ts +51 -0
- package/src/mesh/mesh-event-forwarding.ts +1502 -0
- package/src/mesh/mesh-events-coordinator.ts +30 -2993
- package/src/mesh/mesh-events-pending.ts +1 -10
- package/src/mesh/mesh-events-stale.ts +3 -14
- package/src/mesh/mesh-events-utils.ts +52 -14
- package/src/mesh/mesh-ledger-reconciliation.ts +0 -2
- package/src/mesh/mesh-queue-assignment.ts +1457 -0
- package/src/mesh/mesh-runtime-store.ts +0 -37
- package/src/providers/cli-provider-instance.ts +40 -1
- package/src/providers/native-history/constants.ts +19 -0
- package/src/providers/native-history/dispatcher.ts +2 -3
- package/src/providers/spec/native-history-executor.ts +1 -9
- package/src/runtime-defaults.ts +39 -0
|
@@ -4,7 +4,7 @@ import { randomUUID } from 'crypto';
|
|
|
4
4
|
import { LOG } from '../logging/logger.js';
|
|
5
5
|
import { getLedgerDir, readLedgerEntries, appendLedgerEntry } from './mesh-ledger.js';
|
|
6
6
|
import { MeshRuntimeStore } from './mesh-runtime-store.js';
|
|
7
|
-
import { buildMeshSystemMessage, readNonEmptyString, readRecord, resolveEventSessionId, readMeshCompletionSummary } from './mesh-events-utils.js';
|
|
7
|
+
import { buildMeshSystemMessage, readNonEmptyString, readRecord, resolveEventSessionId, readMeshCompletionSummary, isWeakCompletionMetadata } from './mesh-events-utils.js';
|
|
8
8
|
import { expandDaemonIdForms } from '@adhdev/mesh-shared';
|
|
9
9
|
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
@@ -99,14 +99,6 @@ function hasPendingRefineTerminalEventDuplicate(event: PendingMeshCoordinatorEve
|
|
|
99
99
|
// swallowed by the earlier weak one.
|
|
100
100
|
const TERMINAL_COMPLETION_EVENTS = new Set(['agent:generating_completed', 'agent:stopped']);
|
|
101
101
|
|
|
102
|
-
function isWeakCompletionMetadata(metadata: Record<string, unknown>): boolean {
|
|
103
|
-
const evidenceLevel = readNonEmptyString(metadata.evidenceLevel);
|
|
104
|
-
if (evidenceLevel === 'insufficient' || evidenceLevel === 'weak') return true;
|
|
105
|
-
if (metadata.reviewRecommended === true) return true;
|
|
106
|
-
const diag = readRecord(metadata.completionDiagnostic);
|
|
107
|
-
return diag?.finalAssistantPresent === false || diag?.blockReason === 'missing_final_assistant';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
102
|
export function buildPendingEventFingerprint(event: PendingMeshCoordinatorEvent): string {
|
|
111
103
|
const metadata = readRecord(event.metadataEvent) || {};
|
|
112
104
|
// Bootstrap events are node-scoped: dedup by meshId+event+nodeId only.
|
|
@@ -150,7 +142,6 @@ export function buildPendingEventFingerprint(event: PendingMeshCoordinatorEvent)
|
|
|
150
142
|
// wasDirectDeliveredToCoordinator) was removed when spontaneous PTY direct-inject was retired.
|
|
151
143
|
// Delivery is now queue-drain-only: an event is consumed by exactly one drainer via the atomic
|
|
152
144
|
// SQLite drained=1 marking, so there is no PTY-vs-poll double-delivery left to dedup against.
|
|
153
|
-
// The dormant mesh_direct_delivered_events table / store helpers remain (harmless) but unused.
|
|
154
145
|
|
|
155
146
|
export function hasPendingCoordinatorEventDuplicate(event: PendingMeshCoordinatorEvent): boolean {
|
|
156
147
|
const fingerprint = buildPendingEventFingerprint(event);
|
|
@@ -3,7 +3,7 @@ import type { MeshLedgerKind } from './mesh-ledger.js';
|
|
|
3
3
|
import { updateDirectDispatchStatus, cleanupTerminalDirectDispatches } from './mesh-work-queue.js';
|
|
4
4
|
import { markSessionDeliveriesTerminal } from './mesh-delivery-policy.js';
|
|
5
5
|
import { queuePendingMeshCoordinatorEvent } from './mesh-events-pending.js';
|
|
6
|
-
import { readNonEmptyString, readRecord, resolveEventSessionId, readWorkerResultMetadata } from './mesh-events-utils.js';
|
|
6
|
+
import { readNonEmptyString, readRecord, resolveEventSessionId, readWorkerResultMetadata, isWeakCompletionEvidence } from './mesh-events-utils.js';
|
|
7
7
|
import { meshNodeIdMatches, type MeshNodeIdentified } from '@adhdev/mesh-shared';
|
|
8
8
|
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
@@ -74,17 +74,6 @@ export function hasUnterminalDirectDispatchLedgerEntry(meshId: string, sessionId
|
|
|
74
74
|
return false;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
// True when a terminal ledger payload was recorded from WEAK completion evidence (a false
|
|
78
|
-
// idle): insufficient evidence level, review-recommended, or a missing-final-assistant
|
|
79
|
-
// completion diagnostic. Mirrors isWeakTerminalLedgerPayload in mesh-events-coordinator —
|
|
80
|
-
// a weak terminal is non-authoritative and may be superseded by a genuine completion.
|
|
81
|
-
function isWeakCompletionLedgerPayload(payload: Record<string, unknown> | undefined): boolean {
|
|
82
|
-
if (!payload) return false;
|
|
83
|
-
if (payload.evidenceLevel === 'insufficient' || payload.reviewRecommended === true) return true;
|
|
84
|
-
const diag = readRecord(payload.completionDiagnostic);
|
|
85
|
-
return diag?.finalAssistantPresent === false || diag?.blockReason === 'missing_final_assistant';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
77
|
export function findTerminalLedgerEvidenceForTask(args: {
|
|
89
78
|
meshId: string;
|
|
90
79
|
taskId?: string;
|
|
@@ -100,7 +89,7 @@ export function findTerminalLedgerEvidenceForTask(args: {
|
|
|
100
89
|
if (entry.kind !== 'task_completed' && entry.kind !== 'task_failed' && entry.kind !== 'task_stalled') continue;
|
|
101
90
|
const terminalTaskId = readNonEmptyString(entry.payload?.taskId);
|
|
102
91
|
if (terminalTaskId !== taskId) continue;
|
|
103
|
-
if (entry.kind === 'task_completed' &&
|
|
92
|
+
if (entry.kind === 'task_completed' && isWeakCompletionEvidence(entry.payload)) continue;
|
|
104
93
|
if (args.sessionId && entry.sessionId && entry.sessionId !== args.sessionId) continue;
|
|
105
94
|
if (!args.sessionId && args.nodeId && entry.nodeId && !meshNodeIdMatches(entry as unknown as MeshNodeIdentified, args.nodeId)) continue;
|
|
106
95
|
return { id: entry.id, kind: entry.kind, payload: entry.payload || {}, timestamp: entry.timestamp };
|
|
@@ -160,7 +149,7 @@ function hasTerminalLedgerAfterDispatch(args: {
|
|
|
160
149
|
// evidence. Skip it so the transcript reconcile can still synthesize the GENUINE
|
|
161
150
|
// completion for a re-dispatched / prematurely-terminated direct task instead of
|
|
162
151
|
// bailing with alreadyTerminal.
|
|
163
|
-
if (entry.kind === 'task_completed' &&
|
|
152
|
+
if (entry.kind === 'task_completed' && isWeakCompletionEvidence(entry.payload)) continue;
|
|
164
153
|
const terminalTaskId = readNonEmptyString(entry.payload?.taskId);
|
|
165
154
|
if (terminalTaskId && terminalTaskId === args.taskId) return true;
|
|
166
155
|
if (terminalTaskId && terminalTaskId !== args.taskId) continue;
|
|
@@ -195,23 +195,61 @@ function readEventTimestampValue(value: unknown): number {
|
|
|
195
195
|
return 0;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
export function isWeakCompletionMetadata(metadataEvent: Record<string, unknown>): boolean {
|
|
208
|
-
const evidenceLevel = readNonEmptyString(metadataEvent.evidenceLevel);
|
|
209
|
-
if (evidenceLevel === 'insufficient' || evidenceLevel === 'weak') return true;
|
|
210
|
-
if (metadataEvent.reviewRecommended === true) return true;
|
|
211
|
-
const diag = readRecord(metadataEvent.completionDiagnostic);
|
|
198
|
+
// The completionDiagnostic "false idle" clause, extracted from the five inline copies
|
|
199
|
+
// it used to be duplicated into (the ledger / metadata weak checks and isFalseIdleCompletion).
|
|
200
|
+
// True when the worker FSM dropped to idle WITHOUT a confirmed final assistant message for
|
|
201
|
+
// the turn — a finalization timeout or a "scheduled fallback" idle. cli-provider-instance
|
|
202
|
+
// emits this as completionDiagnostic.blockReason='missing_final_assistant' /
|
|
203
|
+
// finalAssistantPresent=false. The diagnostic lives at the same `completionDiagnostic` field
|
|
204
|
+
// on both a ledger terminal payload and a live metadata event, so one helper serves both.
|
|
205
|
+
export function isMissingFinalAssistantDiagnostic(record: Record<string, unknown> | undefined): boolean {
|
|
206
|
+
const diag = readRecord(record?.completionDiagnostic);
|
|
212
207
|
return diag?.finalAssistantPresent === false || diag?.blockReason === 'missing_final_assistant';
|
|
213
208
|
}
|
|
214
209
|
|
|
210
|
+
// A false-idle completion: the provider dropped to idle WITHOUT a confirmed final assistant
|
|
211
|
+
// message (the completionDiagnostic missing-final-assistant signal). This is a strict SUBSET
|
|
212
|
+
// of weak-completion evidence — it DELIBERATELY ignores evidenceLevel/reviewRecommended,
|
|
213
|
+
// because isGenuineCompletionEvidence (coordinator) gates the truncated-terminal supersession
|
|
214
|
+
// on the false-idle distinction alone. Folding evidenceLevel/reviewRecommended in here would
|
|
215
|
+
// change that genuine-completion judgement, so keep this narrow.
|
|
216
|
+
export function isFalseIdleCompletion(record: Record<string, unknown>): boolean {
|
|
217
|
+
return isMissingFinalAssistantDiagnostic(record);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// A completion whose evidence is WEAK: the worker FSM reached idle but the turn's final
|
|
221
|
+
// assistant message was never confirmed (missing_final_assistant / finalAssistantPresent=false),
|
|
222
|
+
// or the event self-declares insufficient/weak evidence, or a review is recommended. The single
|
|
223
|
+
// source of truth that the live metadata path (mesh-events-pending fingerprint, this module's
|
|
224
|
+
// system-message builder) AND the ledger-terminal paths (mesh-events-coordinator supersession,
|
|
225
|
+
// mesh-events-stale reconcile) all share — the same evidenceLevel / reviewRecommended /
|
|
226
|
+
// completionDiagnostic fields appear on a terminal ledger payload and on a live metadata event.
|
|
227
|
+
//
|
|
228
|
+
// cli-provider-instance emits this on the CANON-C decoupled-immediate path and on a forced
|
|
229
|
+
// finalization timeout, and the structural approval-resolution gate (FALSEIDLE-a) can also let
|
|
230
|
+
// an unconfirmed approval→idle through. Such a completion is NOT trustworthy terminal evidence:
|
|
231
|
+
// a later genuine completion (live path) or a transcript reconcile (fallback path) may supersede
|
|
232
|
+
// it, and the coordinator surfaces a verify hint before declaring the task done.
|
|
233
|
+
//
|
|
234
|
+
// NOTE: this intentionally treats evidenceLevel 'weak' as weak — the ledger variants used to
|
|
235
|
+
// omit it, so a producer emitting 'weak' would have had its weak terminal misjudged as
|
|
236
|
+
// authoritative (genuine completion could no longer supersede it). Applying it uniformly here
|
|
237
|
+
// seals that latent divergence.
|
|
238
|
+
export function isWeakCompletionEvidence(record: Record<string, unknown> | undefined): boolean {
|
|
239
|
+
if (!record) return false;
|
|
240
|
+
const evidenceLevel = readNonEmptyString(record.evidenceLevel);
|
|
241
|
+
if (evidenceLevel === 'insufficient' || evidenceLevel === 'weak') return true;
|
|
242
|
+
if (record.reviewRecommended === true) return true;
|
|
243
|
+
return isMissingFinalAssistantDiagnostic(record);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Back-compat alias for the live metadata-event call sites (system-message builder below,
|
|
247
|
+
// pending-event fingerprint). Identical to isWeakCompletionEvidence; kept as a named export so
|
|
248
|
+
// the metadata-flavoured call sites read naturally.
|
|
249
|
+
export function isWeakCompletionMetadata(metadataEvent: Record<string, unknown>): boolean {
|
|
250
|
+
return isWeakCompletionEvidence(metadataEvent);
|
|
251
|
+
}
|
|
252
|
+
|
|
215
253
|
function formatCompletionMetadata(event: Record<string, unknown>): string {
|
|
216
254
|
const completionDiagnostic = event.completionDiagnostic && typeof event.completionDiagnostic === 'object'
|
|
217
255
|
? event.completionDiagnostic as Record<string, unknown>
|
|
@@ -34,7 +34,6 @@ export interface MeshLedgerReconciliationEvidence {
|
|
|
34
34
|
sourceOfTruth: {
|
|
35
35
|
kind: 'coordinator_local_sqlite';
|
|
36
36
|
p2pOnly: true;
|
|
37
|
-
cloudD1LedgerSync: false;
|
|
38
37
|
notes: string;
|
|
39
38
|
};
|
|
40
39
|
replicas: MeshLedgerReplicaEvidence[];
|
|
@@ -100,7 +99,6 @@ export function buildMeshLedgerReconciliationEvidence(meshId: string, replicas:
|
|
|
100
99
|
sourceOfTruth: {
|
|
101
100
|
kind: 'coordinator_local_sqlite',
|
|
102
101
|
p2pOnly: true,
|
|
103
|
-
cloudD1LedgerSync: false,
|
|
104
102
|
notes: 'Coordinator reconciles bounded slices from daemon-local SQLite event ledgers (mesh_event_ledger table) over P2P DataChannel; Cloud/D1 is not a ledger source of truth.',
|
|
105
103
|
},
|
|
106
104
|
replicas,
|