@adhdev/mesh-shared 1.0.60-rc.72 → 1.0.60-rc.73

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,195 @@
1
+ /**
2
+ * turn-ipc — graph gates, task stats and maintenance commands: graph_gate_claim,
3
+ * graph_gate_release, graph_gate_abandon, graph_node_patch, graph_view_query,
4
+ * task_stats_query, prune_stale_direct, orphaned_pin_notify. Part of the turn-ipc
5
+ * wire contract (./turn-ipc.ts).
6
+ */
7
+ import { TURN_IPC_PROTOCOL_VERSION } from './turn-ipc-guards';
8
+ export interface GraphGateClaimRequest {
9
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
10
+ meshId: string;
11
+ gateId: string;
12
+ coordinatorSessionId: string;
13
+ leaseSeconds?: number;
14
+ extendDeadlineSeconds?: number;
15
+ /** Also collect `collectGateConvergenceEvidence` on a successful claim (mesh_graph_gate action=claim's own behavior). */
16
+ probeConvergenceEvidence?: boolean;
17
+ }
18
+ export interface GraphGateClaimResponse {
19
+ claimed: boolean;
20
+ /** gate_not_found / gate_not_eligible / gate_not_awaiting / gate_lease_held / gate_claim_race / gate_terminal:<state> / gate_not_claimable, when `claimed: false`. */
21
+ reason?: string;
22
+ /** `MeshGraphGateRow`, JSON passthrough; present whenever the core found the gate. */
23
+ gate?: Record<string, unknown>;
24
+ leaseGeneration?: number;
25
+ fencingToken?: string;
26
+ leaseExpiresAt?: string;
27
+ deadlineAt?: string;
28
+ ambiguousExternalOutcome?: boolean;
29
+ previousLeaseOwnerSessionId?: string;
30
+ /** `GateConvergenceEvidence`, JSON passthrough; present only when requested and found. */
31
+ convergenceEvidence?: Record<string, unknown>;
32
+ }
33
+ export declare function decodeGraphGateClaimRequest(value: unknown): GraphGateClaimRequest | null;
34
+ export declare function decodeGraphGateClaimResponse(value: unknown): GraphGateClaimResponse | null;
35
+ export interface GraphGateReleaseRequest {
36
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
37
+ meshId: string;
38
+ gateId: string;
39
+ fencingToken: string;
40
+ leaseGeneration: number;
41
+ idempotencyKey: string;
42
+ outcome: string;
43
+ /** Action-specific structured result/evidence the CALLER supplied — JSON passthrough, echoed back unmodified. */
44
+ result?: unknown;
45
+ evidence?: unknown;
46
+ patches?: readonly {
47
+ node: string;
48
+ baseSpecPatch: Record<string, unknown>;
49
+ }[];
50
+ }
51
+ export type GraphGateReleaseResponse = {
52
+ released: true;
53
+ duplicate: boolean;
54
+ gate?: Record<string, unknown>;
55
+ materializedNodeIds: readonly string[];
56
+ downstreamNodeCount?: number;
57
+ graphCompleted?: boolean;
58
+ } | {
59
+ released: false;
60
+ refusalCode?: string;
61
+ message: string;
62
+ };
63
+ export declare function decodeGraphGateReleaseRequest(value: unknown): GraphGateReleaseRequest | null;
64
+ export declare function decodeGraphGateReleaseResponse(value: unknown): GraphGateReleaseResponse | null;
65
+ export interface GraphGateAbandonRequest {
66
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
67
+ meshId: string;
68
+ gateId: string;
69
+ reason: string;
70
+ coordinatorSessionId?: string;
71
+ force?: boolean;
72
+ }
73
+ export interface GraphGateAbandonResponse {
74
+ abandoned: boolean;
75
+ /** gate_not_found / gate_lease_held / gate_abandon_race / gate_terminal:<state> / gate_not_abandonable, when `abandoned: false`. */
76
+ reason?: string;
77
+ gate?: Record<string, unknown>;
78
+ cancelledNodeIds: readonly string[];
79
+ cancelledTaskIds: readonly string[];
80
+ graphStatus?: string;
81
+ }
82
+ export declare function decodeGraphGateAbandonRequest(value: unknown): GraphGateAbandonRequest | null;
83
+ export declare function decodeGraphGateAbandonResponse(value: unknown): GraphGateAbandonResponse | null;
84
+ export interface GraphNodePatchRequest {
85
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
86
+ meshId: string;
87
+ node: string;
88
+ graphId?: string;
89
+ /** Only {@link MESH_NODE_PATCH_KEYS}-shaped keys are permitted; the daemon enforces the allow-list. */
90
+ baseSpecPatch: Record<string, unknown>;
91
+ }
92
+ export type GraphNodePatchResponse = {
93
+ patched: true;
94
+ graphId: string;
95
+ nodeId: string;
96
+ ref?: string;
97
+ queueTaskId?: string;
98
+ materializationVersion: number;
99
+ state: string;
100
+ /** `SettleOutcome['kind']` — materialized / deferred / skipped / error. */
101
+ outcomeKind: string;
102
+ /** Present when `outcomeKind === 'skipped'`. */
103
+ skippedReason?: string;
104
+ blockedReason?: string;
105
+ } | {
106
+ patched: false;
107
+ refusalCode?: string;
108
+ message: string;
109
+ };
110
+ export declare function decodeGraphNodePatchRequest(value: unknown): GraphNodePatchRequest | null;
111
+ export declare function decodeGraphNodePatchResponse(value: unknown): GraphNodePatchResponse | null;
112
+ export interface GraphViewQueryRequest {
113
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
114
+ meshId: string;
115
+ graphId?: string;
116
+ batchId?: string;
117
+ /** Default true: only graphs that still need attention. */
118
+ activeOnly?: boolean;
119
+ limit?: number;
120
+ /** Attach `collectGateConvergenceEvidence` to the first few waiting gates (mesh_graph_view's G4 opt-in probe). */
121
+ probeGateEvidence?: boolean;
122
+ }
123
+ export interface GraphViewQueryResponse {
124
+ /** `MeshGraphView[]`, JSON passthrough — see this section's content-boundary note. */
125
+ graphs: readonly Record<string, unknown>[];
126
+ }
127
+ export declare function isGraphViewQueryRequest(value: unknown): value is GraphViewQueryRequest;
128
+ export declare function decodeGraphViewQueryRequest(value: unknown): GraphViewQueryRequest | null;
129
+ export declare function decodeGraphViewQueryResponse(value: unknown): GraphViewQueryResponse | null;
130
+ export interface TaskStatsQueryRequest {
131
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
132
+ meshId: string;
133
+ taskIds?: readonly string[];
134
+ missionId?: string;
135
+ tail?: number;
136
+ /** Also compute `computeMeshMissionStats` — requires `missionId`. */
137
+ rollup?: boolean;
138
+ /**
139
+ * Batch rollups: `computeMeshMissionStats` for every id, over ONE queue read and
140
+ * ONE record read (answers `missions`, `tasks` empty). Exclusive with
141
+ * `taskIds`/`missionId`. An older daemon rejects the key.
142
+ */
143
+ missionIds?: readonly string[];
144
+ }
145
+ export interface TaskStatsQueryResponse {
146
+ /** `MeshTaskStats[]`, JSON passthrough. */
147
+ tasks: readonly Record<string, unknown>[];
148
+ /** `MeshMissionStats`, JSON passthrough; present only when `rollup: true` was requested and satisfiable. */
149
+ mission?: Record<string, unknown>;
150
+ /** Batch mode: `MeshMissionStats` per requested mission id, JSON passthrough. */
151
+ missions?: Record<string, Record<string, unknown>>;
152
+ }
153
+ export declare function decodeTaskStatsQueryRequest(value: unknown): TaskStatsQueryRequest | null;
154
+ export declare function decodeTaskStatsQueryResponse(value: unknown): TaskStatsQueryResponse | null;
155
+ export interface PruneStaleDirectRequest {
156
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
157
+ meshId: string;
158
+ execute?: boolean;
159
+ includeTerminal?: boolean;
160
+ source?: string;
161
+ }
162
+ export interface PruneStaleDirectResponse {
163
+ mode: 'execute' | 'dry_run';
164
+ includeTerminal: boolean;
165
+ candidateCount: number;
166
+ /** `MeshActiveWorkRecord[]`, JSON passthrough. */
167
+ prunable: readonly Record<string, unknown>[];
168
+ prunedCount: number;
169
+ preservedUnacknowledged: readonly Record<string, unknown>[];
170
+ preservedLedgerOnly: readonly Record<string, unknown>[];
171
+ preservedNotOrphan: readonly Record<string, unknown>[];
172
+ }
173
+ export declare function decodePruneStaleDirectRequest(value: unknown): PruneStaleDirectRequest | null;
174
+ export declare function decodePruneStaleDirectResponse(value: unknown): PruneStaleDirectResponse | null;
175
+ export interface OrphanedPinNotifyRequest {
176
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
177
+ meshId: string;
178
+ stoppedSessionId: string;
179
+ excludeTaskId?: string;
180
+ cause?: string;
181
+ nodeId?: string;
182
+ coordinatorSessionId?: string;
183
+ }
184
+ export interface OrphanedPinnedTaskWire {
185
+ taskId: string;
186
+ title: string;
187
+ targetSessionId: string;
188
+ targetNodeId?: string;
189
+ missionId?: string;
190
+ }
191
+ export interface OrphanedPinNotifyResponse {
192
+ orphans: readonly OrphanedPinnedTaskWire[];
193
+ }
194
+ export declare function decodeOrphanedPinNotifyRequest(value: unknown): OrphanedPinNotifyRequest | null;
195
+ export declare function decodeOrphanedPinNotifyResponse(value: unknown): OrphanedPinNotifyResponse | null;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * turn-ipc shared runtime-guard primitives (the protocol version stamp and the
3
+ * small structural checks every command decoder composes). Part of the turn-ipc
4
+ * wire contract (./turn-ipc.ts).
5
+ */
6
+ /** Every request in this file is versioned so a responder can reject a shape it predates. */
7
+ export declare const TURN_IPC_PROTOCOL_VERSION: 1;
8
+ export declare function isFiniteNumber(value: unknown): value is number;
9
+ export declare function isNonNegativeInt(value: unknown): value is number;
10
+ export declare function isOptionalId(value: unknown): boolean;
11
+ export declare function hasOnlyKeys(value: Record<string, unknown>, allowed: readonly string[]): boolean;
12
+ export declare function makeGuard<T extends readonly string[]>(values: T): (value: unknown) => value is T[number];
13
+ export declare function isStringArray(value: unknown): value is readonly string[];
14
+ export declare function isOptionalShortString(value: unknown, max?: number): boolean;
15
+ export declare function isRecordArray(value: unknown): value is readonly Record<string, unknown>[];
16
+ export declare function isOptionalRecord(value: unknown): boolean;
17
+ export declare function isOptionalBoolean(value: unknown): boolean;
18
+ export declare function isOptionalString(value: unknown): boolean;
@@ -0,0 +1,257 @@
1
+ /**
2
+ * turn-ipc — mission, note, tool-call and ledger commands: mission_upsert,
3
+ * mission_query, mission_list_query, note_upsert, note_forget, tool_call_record,
4
+ * ledger_query. Part of the turn-ipc wire contract (./turn-ipc.ts).
5
+ */
6
+ import { TURN_IPC_PROTOCOL_VERSION } from './turn-ipc-guards';
7
+ export declare const MESH_MISSION_STATUSES: readonly ["active", "paused", "completed", "abandoned"];
8
+ export type MeshMissionStatusValue = typeof MESH_MISSION_STATUSES[number];
9
+ export declare const isMeshMissionStatusValue: (value: unknown) => value is "active" | "completed" | "paused" | "abandoned";
10
+ export declare const MESH_MISSION_SOURCES: readonly ["magi", "coordinator"];
11
+ export type MeshMissionSourceValue = typeof MESH_MISSION_SOURCES[number];
12
+ export interface MissionBriefWire {
13
+ goal: string;
14
+ constraints?: readonly string[];
15
+ doneCriteria?: readonly string[];
16
+ handoffNotes?: readonly string[];
17
+ ownedPaths?: readonly string[];
18
+ }
19
+ export interface MissionUpsertRequest {
20
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
21
+ meshId: string;
22
+ /** Omitted = create a new mission; present = update (must resolve to an existing mission — see mesh-missions.ts MISSION-UPSERT-SILENT-CREATE). */
23
+ id?: string;
24
+ title: string;
25
+ /** Free text — see file-header note on why this is fine over local IPC. */
26
+ goal?: string;
27
+ status?: MeshMissionStatusValue;
28
+ source?: MeshMissionSourceValue;
29
+ /**
30
+ * H2: `undefined` = do not touch the stored brief. `null` = explicitly clear it.
31
+ * A present object with no usable `goal` is treated by the daemon's own
32
+ * `normalizeMissionBrief` as "no brief" (see mesh-missions.ts upsertMeshMission) —
33
+ * this wire guard only checks SHAPE, not that decision.
34
+ */
35
+ brief?: MissionBriefWire | null;
36
+ }
37
+ export interface MeshMissionRecordWire {
38
+ id: string;
39
+ meshId: string;
40
+ title: string;
41
+ goal: string;
42
+ status: MeshMissionStatusValue;
43
+ source?: MeshMissionSourceValue;
44
+ /** H2: absent = no brief attached to this mission. */
45
+ brief?: MissionBriefWire;
46
+ }
47
+ export interface MissionUpsertResponse {
48
+ mission: MeshMissionRecordWire;
49
+ }
50
+ export declare function decodeMissionUpsertRequest(value: unknown): MissionUpsertRequest | null;
51
+ export declare function isMissionUpsertResponse(value: unknown): value is MissionUpsertResponse;
52
+ export declare function decodeMissionUpsertResponse(value: unknown): MissionUpsertResponse | null;
53
+ export interface MissionQueryRequest {
54
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
55
+ meshId: string;
56
+ /** Omitted = every status. */
57
+ statuses?: readonly MeshMissionStatusValue[];
58
+ /** Single-mission lookup (mesh-missions.ts `getMeshMission`'s shape) — mutually exclusive with `statuses`. */
59
+ id?: string;
60
+ }
61
+ export interface MissionQueryResponse {
62
+ missions: readonly MeshMissionRecordWire[];
63
+ }
64
+ export declare function decodeMissionQueryRequest(value: unknown): MissionQueryRequest | null;
65
+ export declare function decodeMissionQueryResponse(value: unknown): MissionQueryResponse | null;
66
+ export interface MissionListQueryRequest {
67
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
68
+ meshId: string;
69
+ statuses?: readonly MeshMissionStatusValue[];
70
+ verbose?: boolean;
71
+ includeMagi?: boolean;
72
+ withStats?: boolean;
73
+ limit?: number;
74
+ historyIdLimit?: number;
75
+ /**
76
+ * The mesh_status mission projection, computed in the daemon (the MCP no longer
77
+ * opens the daemon's store for it): 'compact' = `getMeshStatusMissionsCompact`
78
+ * (live missions goal-elided + folded history), 'verbose' =
79
+ * `getMeshStatusMissionSummaries({verbose: true})` (live + capped history, full
80
+ * goal, no stats — stats ride one batched `task_stats_query`). Rows then also
81
+ * carry `createdAt`/`updatedAt`/`closeCandidateEmittedAt`. When set, every other
82
+ * option except `historyIdLimit` is ignored. An older daemon rejects the key.
83
+ */
84
+ meshStatusView?: 'compact' | 'verbose';
85
+ }
86
+ export interface MeshMissionTaskAggregateWire {
87
+ total: number;
88
+ pending: number;
89
+ assigned: number;
90
+ completed: number;
91
+ failed: number;
92
+ cancelled: number;
93
+ blocked: number;
94
+ lastActivityAt: string | null;
95
+ }
96
+ export interface MeshMissionStatsWire {
97
+ missionId: string;
98
+ taskCount: number;
99
+ completed: number;
100
+ failed: number;
101
+ totalDurationMs: number;
102
+ wallClockMs: number | null;
103
+ retries: number;
104
+ incompleteTaskIds: readonly string[];
105
+ }
106
+ /** Verbose (full-goal) mission row. `goal` present, `goalPreview`/`goalTruncated` absent. */
107
+ export interface MissionListSummaryVerboseWire {
108
+ id: string;
109
+ meshId: string;
110
+ title: string;
111
+ goal: string;
112
+ status: MeshMissionStatusValue;
113
+ source?: MeshMissionSourceValue;
114
+ tasks: MeshMissionTaskAggregateWire;
115
+ stats?: MeshMissionStatsWire;
116
+ /** H2: absent = no brief attached. */
117
+ brief?: MissionBriefWire;
118
+ /** `meshStatusView` rows only. */
119
+ createdAt?: string;
120
+ updatedAt?: string;
121
+ closeCandidateEmittedAt?: string | null;
122
+ }
123
+ /** Compact (default) mission row. `goalPreview`/`goalTruncated` present, `goal` absent. */
124
+ export interface MissionListSummarySlimWire {
125
+ id: string;
126
+ meshId: string;
127
+ title: string;
128
+ goalPreview: string;
129
+ goalTruncated: boolean;
130
+ status: MeshMissionStatusValue;
131
+ source?: MeshMissionSourceValue;
132
+ tasks: MeshMissionTaskAggregateWire;
133
+ stats?: MeshMissionStatsWire;
134
+ /** H2: absent = no brief attached. */
135
+ brief?: MissionBriefWire;
136
+ /** `meshStatusView` rows only. */
137
+ createdAt?: string;
138
+ updatedAt?: string;
139
+ closeCandidateEmittedAt?: string | null;
140
+ }
141
+ export type MissionListSummaryWire = MissionListSummaryVerboseWire | MissionListSummarySlimWire;
142
+ export interface MeshMissionHistoryFoldWire {
143
+ count: number;
144
+ byStatus: Record<string, number>;
145
+ missionIds: readonly string[];
146
+ note: string;
147
+ }
148
+ export interface MissionListQueryResponse {
149
+ missions: readonly MissionListSummaryWire[];
150
+ historyFold: MeshMissionHistoryFoldWire | null;
151
+ truncated: boolean;
152
+ matched: number;
153
+ overflowIds?: readonly string[];
154
+ }
155
+ export declare function decodeMissionListQueryRequest(value: unknown): MissionListQueryRequest | null;
156
+ export declare function decodeMissionListQueryResponse(value: unknown): MissionListQueryResponse | null;
157
+ export declare const OPERATING_NOTE_CATEGORIES: readonly ["provider_quirk", "pattern_to_avoid", "recovery_lesson"];
158
+ export type OperatingNoteCategory = typeof OPERATING_NOTE_CATEGORIES[number];
159
+ export interface NoteUpsertRequest {
160
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
161
+ meshId: string;
162
+ /** Free text (local IPC — see the section note). */
163
+ text: string;
164
+ category?: OperatingNoteCategory;
165
+ pinned?: boolean;
166
+ /** Explicit expiry, ISO-8601. */
167
+ expiresAt?: string;
168
+ /** Note id (or subject key) this note supersedes. */
169
+ supersedes?: string;
170
+ subjectKey?: string;
171
+ /** Best-effort identity of the recording coordinator (session id / daemon id / host). */
172
+ sourceCoordinator?: string;
173
+ }
174
+ export interface NoteUpsertResponse {
175
+ noteId: string;
176
+ /** True when the same text was already among the recent live notes (no new note). */
177
+ deduped: boolean;
178
+ createdAt: string;
179
+ }
180
+ export declare function decodeNoteUpsertRequest(value: unknown): NoteUpsertRequest | null;
181
+ export declare function decodeNoteUpsertResponse(value: unknown): NoteUpsertResponse | null;
182
+ export interface NoteForgetRequest {
183
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
184
+ meshId: string;
185
+ /** At least one of `noteId` / `text` (a text forget retracts every note with that exact text, and any recorded later). */
186
+ noteId?: string;
187
+ text?: string;
188
+ reason?: string;
189
+ }
190
+ export interface NoteForgetResponse {
191
+ /** Live notes this forget hid. */
192
+ matched: number;
193
+ tombstoneId: string;
194
+ }
195
+ export declare function decodeNoteForgetRequest(value: unknown): NoteForgetRequest | null;
196
+ export declare function decodeNoteForgetResponse(value: unknown): NoteForgetResponse | null;
197
+ export declare const TOOL_CALLER_ROLES: readonly ["coordinator", "unknown"];
198
+ export type ToolCallerRole = typeof TOOL_CALLER_ROLES[number];
199
+ export interface ToolCallRecordRequest {
200
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
201
+ meshId: string;
202
+ /** The mesh tool name, e.g. `mesh_status` (identifier, not free text — always a fixed tool-name string). */
203
+ tool: string;
204
+ sessionId?: string;
205
+ callerRole: ToolCallerRole;
206
+ }
207
+ export interface ToolCallRecordResponse {
208
+ rateLimitExceeded: boolean;
209
+ callsInWindow: number;
210
+ /** Short machine-oriented advisory string, or null. Never free text describing content. */
211
+ advisory: string | null;
212
+ }
213
+ export declare function decodeToolCallRecordRequest(value: unknown): ToolCallRecordRequest | null;
214
+ export declare function decodeToolCallRecordResponse(value: unknown): ToolCallRecordResponse | null;
215
+ export interface LedgerQueryRequest {
216
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
217
+ meshId: string;
218
+ /** One or more ledger `kind` strings (daemon-core `MeshLedgerKind`; mesh-shared cannot import that union, so these are identifiers here). Omitted = every kind. */
219
+ kind?: readonly string[];
220
+ /** ISO-8601 or epoch-ms-as-string — passed through to `readLedgerEntries`'s `since` (parsed via `new Date()`). */
221
+ since?: string;
222
+ /** Filter to entries whose nodeId is equivalent to this daemon id (matched via `daemonIdsEquivalent` daemon-side, not raw `===`). */
223
+ node?: string;
224
+ tail?: number;
225
+ /** Also return `getLedgerSummary(meshId)` alongside the entries — saves a second round trip for callers that want both (the common case: every existing call site fetches both together). */
226
+ includeSummary?: boolean;
227
+ }
228
+ export interface LedgerQueryEntryWire {
229
+ id: string;
230
+ meshId: string;
231
+ timestamp: string;
232
+ kind: string;
233
+ nodeId?: string;
234
+ sessionId?: string;
235
+ providerType?: string;
236
+ taskId?: string;
237
+ /** Unbounded JSON passthrough — see file section's CONTENT BOUNDARY note. */
238
+ payload: Record<string, unknown>;
239
+ }
240
+ export interface LedgerQuerySummaryWire {
241
+ meshId: string;
242
+ totalEntries: number;
243
+ taskDispatched: number;
244
+ taskCompleted: number;
245
+ taskFailed: number;
246
+ taskStalled: number;
247
+ sessionLaunched: number;
248
+ checkpointCreated: number;
249
+ lastActivityAt: string | null;
250
+ recentFailures: number;
251
+ }
252
+ export interface LedgerQueryResponse {
253
+ entries: readonly LedgerQueryEntryWire[];
254
+ summary?: LedgerQuerySummaryWire;
255
+ }
256
+ export declare function decodeLedgerQueryRequest(value: unknown): LedgerQueryRequest | null;
257
+ export declare function decodeLedgerQueryResponse(value: unknown): LedgerQueryResponse | null;
@@ -0,0 +1,221 @@
1
+ /**
2
+ * turn-ipc — local records, queue composites and active work (C-W9a):
3
+ * record_local, queue_query, queue_enqueue, queue_enqueue_graph, queue_cancel,
4
+ * queue_requeue, direct_dispatch_record, graph_audit_record, active_work_query,
5
+ * recovery_context_query. Part of the turn-ipc wire contract (./turn-ipc.ts).
6
+ */
7
+ import { TURN_IPC_PROTOCOL_VERSION } from './turn-ipc-guards';
8
+ /** A queue row as the daemon's `getQueue` returns it — a JSON passthrough (see the section note). */
9
+ export type QueueEntryWire = Record<string, unknown> & {
10
+ id: string;
11
+ status: string;
12
+ };
13
+ export interface RecordLocalRequest {
14
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
15
+ meshId: string;
16
+ /** A `MeshLedgerKind` (daemon-core); an identifier here (mesh-shared cannot import that union). */
17
+ kind: string;
18
+ nodeId?: string;
19
+ sessionId?: string;
20
+ providerType?: string;
21
+ taskId?: string;
22
+ payload: Record<string, unknown>;
23
+ }
24
+ export interface RecordLocalResponse {
25
+ eventId: string;
26
+ timestamp: string;
27
+ storedLocally: boolean;
28
+ published: boolean;
29
+ }
30
+ export declare function decodeRecordLocalRequest(value: unknown): RecordLocalRequest | null;
31
+ export declare function decodeRecordLocalResponse(value: unknown): RecordLocalResponse | null;
32
+ export interface QueueQueryRequest {
33
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
34
+ meshId: string;
35
+ /** Status filter (queue statuses); omitted = every row. */
36
+ statuses?: readonly string[];
37
+ /** One row by id (returns 0 or 1 entries). */
38
+ taskId?: string;
39
+ /** Project for a VIEW surface: the persisted input envelope → `inputSummary` (summarizeQueueEntryInputForView). */
40
+ view?: boolean;
41
+ /**
42
+ * Also return the per-status row counts of the WHOLE mesh queue (columns only,
43
+ * no payload parse) — lets a view read only the rows it shows yet report
44
+ * mesh-wide counts. An older daemon rejects the key.
45
+ */
46
+ withCounts?: boolean;
47
+ /** With `withCounts`: also count terminal rows whose `updated_at` is older than this age. */
48
+ historicalOlderThanMs?: number;
49
+ /**
50
+ * Also return `dependencyHeads`: id/status/blockedReason/cancelReason of every
51
+ * row the returned entries list in `dependsOn` that is not itself returned —
52
+ * enough to annotate dependency state without reading the whole queue.
53
+ */
54
+ withDependencyHeads?: boolean;
55
+ }
56
+ /** A dependency row reduced to the fields dependency-state annotation reads. */
57
+ export interface QueueDependencyHeadWire {
58
+ id: string;
59
+ status: string;
60
+ blockedReason?: string;
61
+ cancelReason?: string;
62
+ }
63
+ export interface QueueQueryResponse {
64
+ entries: readonly QueueEntryWire[];
65
+ /** `withCounts`: row count per status over the whole mesh queue. */
66
+ counts?: Record<string, number>;
67
+ /** `withCounts` + `historicalOlderThanMs`: terminal rows older than that age. */
68
+ oldHistoricalCount?: number;
69
+ /** `withDependencyHeads`. */
70
+ dependencyHeads?: readonly QueueDependencyHeadWire[];
71
+ }
72
+ export declare function decodeQueueQueryRequest(value: unknown): QueueQueryRequest | null;
73
+ export declare function decodeQueueQueryResponse(value: unknown): QueueQueryResponse | null;
74
+ export interface QueueEnqueueRequest {
75
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
76
+ meshId: string;
77
+ /** Free text (the task message — see the section note). */
78
+ message: string;
79
+ options?: Record<string, unknown>;
80
+ /** `recordSingleEnqueueDecision` args minus `taskId` (the daemon fills it). */
81
+ decision?: Record<string, unknown>;
82
+ }
83
+ export interface QueueEnqueueResponse {
84
+ entry: QueueEntryWire;
85
+ }
86
+ export declare function decodeQueueEnqueueRequest(value: unknown): QueueEnqueueRequest | null;
87
+ export declare function decodeQueueEnqueueResponse(value: unknown): QueueEnqueueResponse | null;
88
+ export interface QueueEnqueueGraphRequest {
89
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
90
+ meshId: string;
91
+ mode: 'compat' | 'graph';
92
+ /** compat: `MeshTaskGraphEntrySpec[]` (JSON passthrough). */
93
+ specs?: readonly Record<string, unknown>[];
94
+ /** graph: `commitMeshGraphPlan` input minus `meshId` (JSON passthrough). */
95
+ plan?: Record<string, unknown>;
96
+ /** Audit context: batchId / missionId / coordinatorSessionId / onDependencyFailure / orchestrationDecision / taskCount. */
97
+ audit?: Record<string, unknown>;
98
+ }
99
+ export type QueueEnqueueGraphResponse = {
100
+ ok: true;
101
+ tasks: readonly QueueEntryWire[];
102
+ graph?: Record<string, unknown>;
103
+ } | {
104
+ ok: false;
105
+ refusalCode?: string;
106
+ message: string;
107
+ extra?: Record<string, unknown>;
108
+ };
109
+ export declare function decodeQueueEnqueueGraphRequest(value: unknown): QueueEnqueueGraphRequest | null;
110
+ export declare function decodeQueueEnqueueGraphResponse(value: unknown): QueueEnqueueGraphResponse | null;
111
+ export interface QueueCancelRequest {
112
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
113
+ meshId: string;
114
+ taskId: string;
115
+ /** Operator reason (free text, local IPC). */
116
+ reason?: string;
117
+ }
118
+ export interface QueueCancelResponse {
119
+ /** The cancelled row, or null when no such task. */
120
+ task: QueueEntryWire | null;
121
+ /** The row as it was BEFORE the cancel (its assignment is what a caller stops). */
122
+ before: QueueEntryWire | null;
123
+ }
124
+ export declare function decodeQueueCancelRequest(value: unknown): QueueCancelRequest | null;
125
+ export declare function decodeQueueCancelResponse(value: unknown): QueueCancelResponse | null;
126
+ export interface QueueRequeueRequest {
127
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
128
+ meshId: string;
129
+ taskId: string;
130
+ /** `requeueTask` options (reason / targetNodeId / targetSessionId / clear* / force / message / maxRetries / notBefore), JSON passthrough. */
131
+ options?: Record<string, unknown>;
132
+ }
133
+ export interface QueueRequeueResponse {
134
+ task: QueueEntryWire | null;
135
+ }
136
+ export declare function decodeQueueRequeueRequest(value: unknown): QueueRequeueRequest | null;
137
+ export declare function decodeQueueRequeueResponse(value: unknown): QueueRequeueResponse | null;
138
+ export interface DirectDispatchRecordRequest {
139
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
140
+ meshId: string;
141
+ taskId: string;
142
+ /** Free text (the authored task message — the materialised row keeps it). */
143
+ message: string;
144
+ /** `recordDirectDispatchTask` options minus `id` (JSON passthrough). */
145
+ task?: Record<string, unknown>;
146
+ /** `recordDirectDispatchDecision` args minus `taskId` (JSON passthrough). */
147
+ decision?: Record<string, unknown>;
148
+ }
149
+ export interface DirectDispatchRecordResponse {
150
+ taskRecorded: boolean;
151
+ decisionRecorded: boolean;
152
+ }
153
+ export declare function decodeDirectDispatchRecordRequest(value: unknown): DirectDispatchRecordRequest | null;
154
+ export declare function decodeDirectDispatchRecordResponse(value: unknown): DirectDispatchRecordResponse | null;
155
+ export declare const GRAPH_AUDIT_EVENTS: readonly ["gate_claimed", "gate_released", "gate_abandoned", "node_patched"];
156
+ export type GraphAuditEvent = typeof GRAPH_AUDIT_EVENTS[number];
157
+ export interface GraphAuditRecordRequest {
158
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
159
+ meshId: string;
160
+ event: GraphAuditEvent;
161
+ fields: Record<string, unknown>;
162
+ }
163
+ export interface GraphAuditRecordResponse {
164
+ recorded: boolean;
165
+ }
166
+ export declare function decodeGraphAuditRecordRequest(value: unknown): GraphAuditRecordRequest | null;
167
+ export declare function decodeGraphAuditRecordResponse(value: unknown): GraphAuditRecordResponse | null;
168
+ export interface ActiveWorkQueryRequest {
169
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
170
+ meshId: string;
171
+ /** Live node probe results (`buildMeshActiveWork`'s `nodes`), JSON passthrough. */
172
+ nodes?: readonly Record<string, unknown>[];
173
+ /** Substitute queue rows (default: the daemon's `getQueue`). */
174
+ queue?: readonly Record<string, unknown>[];
175
+ /** Record tail fed to active work (default 200). */
176
+ recordTail?: number;
177
+ includeTerminalDirect?: boolean;
178
+ /** Default true. */
179
+ compute?: boolean;
180
+ includeInputs?: boolean;
181
+ includeSummary?: boolean;
182
+ includeSchedulingRuntime?: boolean;
183
+ /**
184
+ * The caller's mesh snapshot for the scheduling runtime, JSON passthrough.
185
+ * Optional since the daemon resolves its own mesh record when it is absent;
186
+ * an older daemon rejects `includeSchedulingRuntime` without it (the caller's
187
+ * feature-detect signal to resend with the mesh).
188
+ */
189
+ mesh?: Record<string, unknown>;
190
+ }
191
+ export interface ActiveWorkQueryResponse {
192
+ /** `MeshActiveWorkEvidence` (daemon-core), JSON passthrough; absent when `compute: false`. */
193
+ activeWork?: Record<string, unknown>;
194
+ records?: readonly Record<string, unknown>[];
195
+ directDispatches?: readonly Record<string, unknown>[];
196
+ /** `MeshLedgerSummary`-shaped record summary. */
197
+ summary?: Record<string, unknown>;
198
+ schedulingRuntime?: Record<string, unknown>;
199
+ }
200
+ export declare function decodeActiveWorkQueryRequest(value: unknown): ActiveWorkQueryRequest | null;
201
+ export declare function decodeActiveWorkQueryResponse(value: unknown): ActiveWorkQueryResponse | null;
202
+ export interface RecoveryContextQueryRequest {
203
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
204
+ meshId: string;
205
+ nodeId?: string;
206
+ sessionId?: string;
207
+ maxRetries?: number;
208
+ /**
209
+ * Batch: one context per node id, computed over ONE record read (answers
210
+ * `contexts`). Exclusive with `nodeId`/`sessionId`. An older daemon rejects it.
211
+ */
212
+ nodeIds?: readonly string[];
213
+ }
214
+ export interface RecoveryContextQueryResponse {
215
+ /** Single mode (nodeId/sessionId). */
216
+ context?: Record<string, unknown>;
217
+ /** Batch mode (`nodeIds`): context per node id. */
218
+ contexts?: Record<string, Record<string, unknown>>;
219
+ }
220
+ export declare function decodeRecoveryContextQueryRequest(value: unknown): RecoveryContextQueryRequest | null;
221
+ export declare function decodeRecoveryContextQueryResponse(value: unknown): RecoveryContextQueryResponse | null;