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