@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,176 @@
1
+ /**
2
+ * turn-ipc — the turn-ledger commands: turn_observe, mesh_record, turn_cancel,
3
+ * operator_status, turn_query, mesh_index_query. Part of the turn-ipc wire
4
+ * contract (./turn-ipc.ts).
5
+ */
6
+ import { TURN_IPC_PROTOCOL_VERSION } from './turn-ipc-guards';
7
+ import { type TurnEvidence, type TurnAttemptRef, type TurnOutcome, type ProjectedScalars, type TurnReason, type TurnEvidenceKind } from './turn-evidence';
8
+ /** Reducer verdict, mirrored from the C1 reducer's `reduce()` return shape. */
9
+ export declare const TURN_OBSERVE_VERDICTS: readonly ["applied", "recorded", "rejected"];
10
+ export type TurnObserveVerdict = typeof TURN_OBSERVE_VERDICTS[number];
11
+ export interface TurnObserveRequest {
12
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
13
+ evidence: TurnEvidence;
14
+ }
15
+ export interface TurnObserveResponse {
16
+ verdict: TurnObserveVerdict;
17
+ attemptRef: TurnAttemptRef;
18
+ /** Present only when the evidence committed the attempt (verdict 'applied' + a terminal-class kind). */
19
+ outcome?: TurnOutcome;
20
+ }
21
+ export declare function decodeTurnObserveRequest(value: unknown): TurnObserveRequest | null;
22
+ export declare function decodeTurnObserveResponse(value: unknown): TurnObserveResponse | null;
23
+ /**
24
+ * Structural pin of `seqscribe/mesh-event-projection.ts` `PROJECTED_PAYLOAD_KEYS`
25
+ * (daemon-core; this leaf cannot import it). A test in this package's test
26
+ * suite AND a daemon-core test each assert their list equals this one — see
27
+ * `mesh-shared/test/turn-ipc.test.ts` and the C-W6 report's break-once table.
28
+ * Adding a key here is the SAME assertion as adding it there: non-content
29
+ * (identifier, enum, boolean, or counter), never free text.
30
+ */
31
+ export declare const MESH_RECORD_PAYLOAD_KEYS: readonly ["taskId", "deliveryId", "attemptId", "missionId", "checkpointId", "promptId", "providerSessionId", "targetNoteId", "nodeId", "sessionId", "providerType", "transport", "attemptedSessionId", "holderSessionId", "reason", "status", "outcome", "terminalKind", "event", "source", "intentionalStopReason", "retryable", "rebound", "forced", "fallback", "membershipRemoved", "requestedForce", "removedByRemoteDaemon", "completedViaReady", "intentional", "weak", "attempt", "attemptCount", "count"];
32
+ /** Maximum length of any string value in a `mesh_record` payload (mirrors `MAX_PROJECTED_STRING`). */
33
+ export declare const MAX_MESH_RECORD_STRING = 200;
34
+ export interface MeshRecordRequest {
35
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
36
+ meshId: string;
37
+ /** The original ledger `kind` string (daemon-core `MeshLedgerKind`; mesh-shared cannot import that union, so it is an identifier here). */
38
+ ledgerKind: string;
39
+ nodeId?: string;
40
+ sessionId?: string;
41
+ taskId?: string;
42
+ /** Restricted to `MESH_RECORD_PAYLOAD_KEYS` — an unknown key is a decode failure, not a silently dropped field. */
43
+ payload: ProjectedScalars;
44
+ }
45
+ export interface MeshRecordResponse {
46
+ /** `mesh.<id>.events` append coordinates, for callers that need to reference the entry (e.g. a `ref`'d handoff). */
47
+ eventId: string;
48
+ seq: number;
49
+ }
50
+ /** Every payload key must be a member of `MESH_RECORD_PAYLOAD_KEYS` — the allow-list boundary at the wire. */
51
+ export declare function isMeshRecordPayload(value: unknown): value is ProjectedScalars;
52
+ export declare function decodeMeshRecordRequest(value: unknown): MeshRecordRequest | null;
53
+ export declare function decodeMeshRecordResponse(value: unknown): MeshRecordResponse | null;
54
+ export interface TurnCancelRequest {
55
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
56
+ /** Exactly one of the two must be present — the decoder rejects both-or-neither. */
57
+ attemptId?: string;
58
+ taskId?: string;
59
+ reason: TurnReason;
60
+ }
61
+ export interface TurnCancelResponse {
62
+ attemptRef: TurnAttemptRef;
63
+ verdict: TurnObserveVerdict;
64
+ }
65
+ export declare function decodeTurnCancelRequest(value: unknown): TurnCancelRequest | null;
66
+ export declare function decodeTurnCancelResponse(value: unknown): TurnCancelResponse | null;
67
+ /**
68
+ * Fire-and-forget operator/tool-call status record — replaces
69
+ * `recordMeshCoordinatorToolCall` (10 sites, `mesh_tool_call_log`) and doubles
70
+ * as the `operator_status` evidence kind's wire shape.
71
+ *
72
+ * NAMING NOTE (flagged for the C-W6 implementer, see report §"mismatch"):
73
+ * the C-W6 brief's DELIVERABLES describes this request as
74
+ * `{taskId, status: MeshTaskStatus, reason}`, but C1's `operator_status`
75
+ * evidence kind (`turn-evidence.ts` `OPERATOR_STATUSES`) is the closed
76
+ * 2-value set `'completed' | 'failed'` — a verdict on an operator ACTION, not
77
+ * a `MeshTaskStatus` (5-value queue-row status: pending/assigned/completed/
78
+ * failed/cancelled). This contract follows `turn-evidence.ts` because that is
79
+ * what the C1 reducer actually consumes for this evidence kind; using the
80
+ * 5-value `MeshTaskStatus` here would let this request carry `pending` or
81
+ * `assigned`, which the reducer has no transition for.
82
+ */
83
+ export declare const OPERATOR_STATUS_VALUES: readonly ["completed", "failed"];
84
+ export type OperatorStatusValue = typeof OPERATOR_STATUS_VALUES[number];
85
+ export declare const OPERATOR_STATUS_REASON_VALUES: readonly ["operator_update", "refine_terminal", "validation_terminal"];
86
+ export type OperatorStatusReasonValue = typeof OPERATOR_STATUS_REASON_VALUES[number];
87
+ export interface OperatorStatusRequest {
88
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
89
+ taskId: string;
90
+ status: OperatorStatusValue;
91
+ reason: OperatorStatusReasonValue;
92
+ }
93
+ /** Acknowledgement only — this command is fire-and-forget by design (the daemon owns rate-limiting the underlying log). */
94
+ export interface OperatorStatusResponse {
95
+ accepted: true;
96
+ }
97
+ export declare function decodeOperatorStatusRequest(value: unknown): OperatorStatusRequest | null;
98
+ export declare function decodeOperatorStatusResponse(value: unknown): OperatorStatusResponse | null;
99
+ /** Row shape returned by `turn_query` — scalar projection of a `turn_attempts` row (C3 schema), never `data_json`/`payload_json` content. */
100
+ export interface TurnQueryAttemptRow {
101
+ attemptId: string;
102
+ generation: number;
103
+ meshId?: string;
104
+ taskId?: string;
105
+ sessionId: string;
106
+ nodeId?: string;
107
+ providerType?: string;
108
+ state: string;
109
+ terminalOutcome?: TurnOutcome;
110
+ terminalReason?: TurnReason;
111
+ acceptedAt: number;
112
+ terminalAt?: number;
113
+ }
114
+ /** Row shape returned by `turn_query` for the event stream — scalar projection of a `turn_events` row, `payload_json` NEVER included. */
115
+ export interface TurnQueryEventRow {
116
+ eventId: string;
117
+ attemptId?: string;
118
+ generation?: number;
119
+ sessionId: string;
120
+ kind: TurnEvidenceKind;
121
+ source: string;
122
+ verdict: TurnObserveVerdict | 'forwarded';
123
+ atMs: number;
124
+ }
125
+ export interface TurnQueryRequest {
126
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
127
+ meshId: string;
128
+ taskId?: string;
129
+ attemptId?: string;
130
+ sessionId?: string;
131
+ state?: string;
132
+ since?: number;
133
+ tail?: number;
134
+ }
135
+ export interface TurnQueryResponse {
136
+ attempts: readonly TurnQueryAttemptRow[];
137
+ events: readonly TurnQueryEventRow[];
138
+ /** C7-5: set while `mesh.<id>.events` replication is behind for this mesh — the caller must not treat a fleet-scope answer as complete. */
139
+ replicationPending?: boolean;
140
+ }
141
+ export declare function decodeTurnQueryRequest(value: unknown): TurnQueryRequest | null;
142
+ export declare function decodeTurnQueryResponse(value: unknown): TurnQueryResponse | null;
143
+ export declare const MESH_INDEX_QUERY_WRITER_SCOPES: readonly ["own", "fleet"];
144
+ export type MeshIndexQueryWriterScope = typeof MESH_INDEX_QUERY_WRITER_SCOPES[number];
145
+ export interface MeshIndexQueryRequest {
146
+ v: typeof TURN_IPC_PROTOCOL_VERSION;
147
+ meshId: string;
148
+ ledgerKind?: string;
149
+ sessionId?: string;
150
+ taskId?: string;
151
+ writer?: MeshIndexQueryWriterScope;
152
+ since?: number;
153
+ tail?: number;
154
+ }
155
+ /** Row shape returned by `mesh_index_query` — a `mesh_topic_index` row (C3 schema). */
156
+ export interface MeshTopicIndexRow {
157
+ writer: string;
158
+ seq: number;
159
+ meshId: string;
160
+ eventId: string;
161
+ kind: string;
162
+ ledgerKind?: string;
163
+ taskId?: string;
164
+ sessionId?: string;
165
+ nodeId?: string;
166
+ atMs: number;
167
+ payload: ProjectedScalars;
168
+ }
169
+ export interface MeshIndexQueryResponse {
170
+ rows: readonly MeshTopicIndexRow[];
171
+ /** C7-5: true while `mesh.<id>.events` replication is behind for this mesh. */
172
+ replicationPending?: boolean;
173
+ }
174
+ export declare function decodeMeshIndexQueryRequest(value: unknown): MeshIndexQueryRequest | null;
175
+ export declare function isMeshIndexQueryResponse(value: unknown): value is MeshIndexQueryResponse;
176
+ export declare function decodeMeshIndexQueryResponse(value: unknown): MeshIndexQueryResponse | null;