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

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/magi.d.ts DELETED
@@ -1,281 +0,0 @@
1
- /**
2
- * MAGI — Multi-Agent Ground-truth Insight.
3
- *
4
- * Pure shared types for the mesh cross-verification quorum: the per-task_kind
5
- * panel binding (machine-local config, stored in ~/.adhdev/meshes.json
6
- * `magiKindPanels`), the agent-agnostic common output schema every dispatched
7
- * replica answers with, and the synthesis result shapes. These cross the
8
- * daemon-core (storage / accessors) ↔ mcp-server (fan-out / synthesis) boundary,
9
- * so they live in the dependency-free mesh-shared leaf — no runtime, no Node/DOM APIs.
10
- *
11
- * Design: docs/design/2026-06-28-mesh-magi-review.md. Core stance: no personas,
12
- * no named lenses — a panel slot is just one `(node × provider)` target that
13
- * answers the SAME question. The value is the friction (contested / singleton /
14
- * source-coupled findings), NOT a majority vote.
15
- *
16
- * NOTE: the former named-panel model (MagiPanel / MagiPanelMember / MagiPanelMap
17
- * and inline `members`) was REMOVED. A MAGI review resolves its fan-out slots
18
- * EXCLUSIVELY from the `magiKindPanels` binding for the review's `task_kind`; an
19
- * unconfigured kind is a hard error, never a synthesized or named-panel fallback.
20
- */
21
- /**
22
- * One kind-panel slot: a `(node × provider [× model])` target. `provider` required;
23
- * `nodeId` pins a concrete mesh node; `model` optionally selects the agent model at
24
- * launch; `capabilityTags` route by tag when no nodeId is given; `n` is an optional
25
- * per-slot replica count. This is the SOLE panel-member shape — the fan-out planner
26
- * (buildMagiFanoutPlan) resolves a `MagiSlot[]` directly.
27
- *
28
- * ─── DELIBERATELY REDUCED SCHEMA — not a missing feature ─────────────────────
29
- *
30
- * A MagiSlot is a strict subset of a node's `NodeCapabilitySlot`. It accepts
31
- * `provider` + optional `model` / `nodeId` / `capabilityTags` / `n`, and it
32
- * deliberately does NOT accept the node-capability routing axes — `thinkingLevel`,
33
- * `difficulty`, `maxParallel`. That asymmetry is the design, not an oversight:
34
- *
35
- * - A node capability slot answers **"which work goes where"** — routing FITNESS.
36
- * Difficulty and thinking level exist there to match a task against the slot best
37
- * suited to run it.
38
- * - A MAGI panel slot answers **"who answers independently"** — cross-verification
39
- * DIVERSITY. Its whole value is that the replicas are NOT selected for fitness.
40
- *
41
- * Reviving the difficulty/thinking axes here would couple panel membership to routing
42
- * optimization, and the best-fitting provider would win every slot. The panel would
43
- * collapse toward one provider — which is precisely the failure MAGI exists to
44
- * prevent, since agreement among coupled agents carries no information (see the
45
- * `source_coupled` weighting in synthesis). A reduced schema is what keeps the two
46
- * axes orthogonal.
47
- *
48
- * Consistent with that, `mesh_magi_review` enqueues every replica with a fixed
49
- * `difficulty: 'freeform'` sentinel rather than a caller-chosen grade — the panel has
50
- * already pinned the (node, provider) target, so any difficulty would be inert at best
51
- * and would fight the panel's own slot selection at worst. To change how hard a
52
- * replica thinks or how much parallelism a node grants, edit that NODE's capability
53
- * slots (`mesh_node_slots` action "set"); it is a different axis, on purpose.
54
- *
55
- * Unknown keys are dropped rather than rejected, so slots written by another version
56
- * stay readable. Write paths pair the normalizer with
57
- * `collectIgnoredMagiSlotFields()` and report the drops as `ignoredFields`, so the
58
- * reduction is visible instead of silent.
59
- */
60
- export interface MagiSlot {
61
- /** Optional — pin to a specific mesh node id. Absent → route by capabilityTags + provider. */
62
- nodeId?: string;
63
- /** REQUIRED — provider type, e.g. 'claude-cli' | 'codex-cli' | 'gemini-cli'. */
64
- provider: string;
65
- /**
66
- * Optional model override applied at replica launch (e.g. 'opus' | 'sonnet' for
67
- * claude-cli). Threaded through enqueueTask → the auto-launched session's
68
- * `launch_cli` payload as `initialModel`. For ACP providers it drives
69
- * setConfigOption('model', …); for CLI providers it is expanded via the provider
70
- * manifest's `modelLaunchArgs` template into launch args (a provider with no
71
- * template silently ignores it — model is best-effort, never fatal).
72
- */
73
- model?: string;
74
- /** Optional routing tags, ANDed with the provider tag when nodeId is absent. */
75
- capabilityTags?: string[];
76
- /** Optional per-slot replica count; defaults to the kind-panel defaultN / global n / 1. */
77
- n?: number;
78
- }
79
- /**
80
- * Per-task_kind panel binding for ONE mesh, stored machine-local in
81
- * `~/.adhdev/meshes.json` under that mesh's entry (`meshes[].magiKindPanels`). The
82
- * scope is per mesh: two meshes on the same machine hold independent bindings for
83
- * the same task_kind. (It formerly sat at the config root keyed by task_kind alone,
84
- * which let one mesh's write clobber another's.) A kind absent from the map has NO
85
- * configured panel → `mesh_magi_review({task_kind})` errors with
86
- * `magi_kind_not_configured` rather than synthesizing one. `freeform` MAY be bound
87
- * like any other kind (a direct kind→slots binding).
88
- */
89
- export type MagiKindPanelMap = Partial<Record<MagiTaskKind, MagiSlot[]>>;
90
- /**
91
- * The output-schema selector a MAGI fan-out injects into every replica prompt and
92
- * the strict parser used at collection. Code-orthogonal to the panel's slot set
93
- * (the fan-out planner never reads it) — it ONLY shapes the per-replica prompt /
94
- * parse contract. SSOT lives here (mesh-shared leaf) so both daemon-core (slot
95
- * normalization) and mcp-server (resolution / prompt assembly) consume one union.
96
- *
97
- * - claim_audit (default, backward-compatible), rca, design → require evidence[].
98
- * - freeform → no schema, no evidence; contributes NO structured claims to
99
- * synthesis. It MAY still be bound as a kind-panel key (a direct kind→slots
100
- * binding), unlike the removed named-panel `defaultKind`.
101
- */
102
- export type MagiTaskKind = 'claim_audit' | 'rca' | 'design' | 'freeform';
103
- /**
104
- * Synthesis emphasis hint. Affects weighting / labels only — NEVER the agent
105
- * count or the common schema. (Per-mode weighting tuning is a deferred refinement;
106
- * the field is accepted now so callers and panels are forward-stable.)
107
- */
108
- export type MagiMode = 'rca' | 'investigation' | 'claim_audit' | 'design_review' | 'code_audit';
109
- export type MagiClaimStance = 'support' | 'oppose' | 'uncertain';
110
- /**
111
- * One claim from one agent. `evidence` carries `file:line` or external-source
112
- * strings; `confidence` is 0..1. Identical regardless of which provider/machine
113
- * produced it — this is the forced structured-output contract injected into each
114
- * dispatched task prompt.
115
- */
116
- export interface MagiClaim {
117
- claim: string;
118
- stance: MagiClaimStance;
119
- evidence: string[];
120
- confidence: number;
121
- }
122
- /** The agent-agnostic response every dispatched replica returns. */
123
- export interface MagiAgentResponse {
124
- claims: MagiClaim[];
125
- top_findings: string[];
126
- open_questions: string[];
127
- }
128
- /**
129
- * Where one response came from — the `(node × provider)` identity that backs a
130
- * claim's independence. `ok=false` marks a replica that died / produced no
131
- * parseable common-schema output (excluded from clusters, counted as missing).
132
- */
133
- export interface MagiResponseSource {
134
- /** Mesh task id of the dispatched replica. */
135
- taskId: string;
136
- nodeId?: string;
137
- provider?: string;
138
- /** False when the replica failed or its output could not be parsed. */
139
- ok: boolean;
140
- /** Reason when ok=false (timeout / failed / unparseable / stale). */
141
- error?: string;
142
- /**
143
- * True when the replica was detected STALE during collection — assigned to a
144
- * node/session no longer present in the live mesh (so it will never reach a
145
- * terminal state). Distinguishes a dead-assignment replica from one that is
146
- * merely still generating. Always implies ok=false.
147
- */
148
- stale?: boolean;
149
- /**
150
- * Git ref of the node this replica ran on, captured at collection time from the
151
- * live mesh node's compact git summary. Lets synthesis (and a dashboard) detect
152
- * GIT SKEW across the panel — if the answering replicas span different branches
153
- * or diverge (ahead/behind), their file:line evidence is comparing different code
154
- * and "agreement" is less meaningful. Best-effort; absent when the node carried
155
- * no git summary.
156
- */
157
- git?: MagiReplicaGitRef;
158
- /**
159
- * The replica's raw end-user answer text as read from its session transcript at
160
- * collection time, truncated to MAGI_RAW_ANSWER_CAP chars (with `rawAnswerTruncated`
161
- * set when it was longer). This is the human-readable original a replica produced —
162
- * useful when the structured claim parse dropped nuance, or for a cluster member that
163
- * needs the source prose. GATED: stripped from the persisted `magi_synthesis` ledger
164
- * entry (to bound ledger payload growth) and from the default mesh_magi_collect
165
- * response; surfaced ONLY in mesh_magi_collect verbose. Best-effort; absent for a
166
- * replica that produced no readable transcript (failed / stale / unparseable).
167
- */
168
- rawAnswer?: string;
169
- /** True when `rawAnswer` was truncated at MAGI_RAW_ANSWER_CAP. */
170
- rawAnswerTruncated?: boolean;
171
- }
172
- /** Max chars of a replica's raw answer retained on MagiResponseSource.rawAnswer. */
173
- export declare const MAGI_RAW_ANSWER_CAP = 4000;
174
- /** Compact git ref of the node a replica ran on (subset of GitRepoStatus). */
175
- export interface MagiReplicaGitRef {
176
- branch?: string | null;
177
- /** HEAD commit sha of the node's workspace — the exact code the replica saw. */
178
- headCommit?: string | null;
179
- ahead?: number;
180
- behind?: number;
181
- dirty?: boolean;
182
- }
183
- /**
184
- * Cross-replica git divergence assessment. `skewed` is true when the answering
185
- * replicas span more than one branch OR any replica diverges from its upstream
186
- * (ahead/behind > 0) — both mean the panel is not all looking at the same code, so
187
- * file:line evidence and agreement are git-skewed. Always present on a synthesis
188
- * (skewed=false / distinctBranches≤1 when there is nothing to flag).
189
- */
190
- export interface MagiGitSkew {
191
- skewed: boolean;
192
- /** Number of distinct branches across the answering replicas with a known branch. */
193
- distinctBranches: number;
194
- /** The distinct branch names (sorted), for display. */
195
- branches: string[];
196
- /** Replicas whose branch/divergence differs from the panel baseline. */
197
- divergentReplicas: number;
198
- note?: string;
199
- }
200
- /** A parsed replica response paired with its source identity. */
201
- export interface MagiSynthesizedResponse {
202
- source: MagiResponseSource;
203
- response: MagiAgentResponse;
204
- }
205
- /**
206
- * Synthesis category for a claim cluster. `needs_verification` is the PRIMARY
207
- * OUTPUT = contested ∪ singleton ∪ source_coupled ∪ (high-impact claims lacking
208
- * independent evidence). `agreed` is the only "safe to trust, low priority" bucket.
209
- */
210
- export type MagiClusterCategory = 'agreed' | 'contested' | 'dissent' | 'singleton' | 'source_coupled';
211
- /** One member observation inside a claim cluster. */
212
- export interface MagiClusterMember {
213
- taskId: string;
214
- nodeId?: string;
215
- provider?: string;
216
- claim: string;
217
- stance: MagiClaimStance;
218
- evidence: string[];
219
- confidence: number;
220
- }
221
- /**
222
- * A cluster of semantically-equivalent claims across responses, with its
223
- * stance tally and diversity-weighted independence assessment.
224
- */
225
- export interface MagiClaimCluster {
226
- /** Representative (first / longest) claim text for the cluster. */
227
- claim: string;
228
- category: MagiClusterCategory;
229
- members: MagiClusterMember[];
230
- stance: {
231
- support: number;
232
- oppose: number;
233
- uncertain: number;
234
- };
235
- /** Distinct providers / nodes / evidence sources backing the cluster. */
236
- distinctProviders: number;
237
- distinctNodes: number;
238
- distinctEvidence: number;
239
- /** Diversity-weighted independence score (NOT the raw agent count). */
240
- independenceScore: number;
241
- /** True when this cluster is routed to needs_verification. */
242
- needsVerification: boolean;
243
- /** Why it needs verification (contested / singleton / source_coupled / no_independent_evidence). */
244
- reasons: string[];
245
- }
246
- /** The full synthesis result — N-agnostic, diversity-weighted, not a vote. */
247
- export interface MagiSynthesis {
248
- /** How many replicas were expected vs. produced parseable output. */
249
- replicasExpected: number;
250
- replicasAnswered: number;
251
- replicasMissing: number;
252
- /** Distinct providers / nodes across the answering replicas. */
253
- distinctProviders: number;
254
- distinctNodes: number;
255
- /**
256
- * Set when the resolved panel collapsed to a single provider or single
257
- * machine — agreements are then flagged source-coupled. Null when independence
258
- * was achieved.
259
- */
260
- independenceBanner: string | null;
261
- clusters: MagiClaimCluster[];
262
- /** PRIMARY OUTPUT — clusters routed to needs_verification, highest priority first. */
263
- needsVerification: MagiClaimCluster[];
264
- /** High-independence agreements — safe to trust, lowest review priority. */
265
- agreed: MagiClaimCluster[];
266
- /** Union of every response's open_questions (deduped). */
267
- openQuestions: string[];
268
- /**
269
- * Per-replica source identity (taskId / nodeId / provider / ok / stale / git) for
270
- * every replica in the fan-out. Lets a consumer (the dashboard's extractMagiActivity)
271
- * read which node × provider answered and the git ref each ran at — the inputs behind
272
- * the gitSkew assessment.
273
- */
274
- replicas: MagiResponseSource[];
275
- /**
276
- * Cross-replica git divergence. When skewed, the answering replicas were not all
277
- * on the same code (different branches / ahead-behind), so evidence and agreement
278
- * should be read with that caveat. Always present.
279
- */
280
- gitSkew: MagiGitSkew;
281
- }
@@ -1,195 +0,0 @@
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;