@agent-wiki/mcp 0.21.0 → 0.21.3
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/cobol/__tests__/field-lineage.test.js +141 -1
- package/dist/cobol/__tests__/field-lineage.test.js.map +1 -1
- package/dist/cobol/__tests__/parser.test.js +32 -0
- package/dist/cobol/__tests__/parser.test.js.map +1 -1
- package/dist/cobol/field-lineage.d.ts +21 -0
- package/dist/cobol/field-lineage.d.ts.map +1 -1
- package/dist/cobol/field-lineage.js +104 -11
- package/dist/cobol/field-lineage.js.map +1 -1
- package/dist/cobol/parser.d.ts.map +1 -1
- package/dist/cobol/parser.js +7 -0
- package/dist/cobol/parser.js.map +1 -1
- package/dist/evidence-report.d.ts +10 -0
- package/dist/evidence-report.d.ts.map +1 -1
- package/dist/evidence-report.js +23 -1
- package/dist/evidence-report.js.map +1 -1
- package/dist/evidence-report.test.js +32 -0
- package/dist/evidence-report.test.js.map +1 -1
- package/dist/evidence.d.ts +17 -3
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +33 -4
- package/dist/evidence.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +54 -20
- package/dist/server.js.map +1 -1
- package/dist/server.test.js +182 -0
- package/dist/server.test.js.map +1 -1
- package/docs/evidence-envelope.md +61 -2
- package/docs/tools.md +67 -1
- package/package.json +1 -1
|
@@ -138,7 +138,7 @@ interface WriteEvent {
|
|
|
138
138
|
|
|
139
139
|
Same rotation policy. The counter ticks on every classified `wiki_write` (system pages and bypassed writes excluded), regardless of whether the unsupported log dedupes the event. This keeps the "denominator" honest: `(unsupportedWrites + rejectedWrites) / totalWrites` reflects how often unsupported attempts occur versus total write volume — see `wouldRejectRatio` below.
|
|
140
140
|
|
|
141
|
-
**Aggregation**: Phase 4
|
|
141
|
+
**Aggregation**: Phase 4 (`wiki_admin action: "evidence-report"`, see below) reads both logs and renders the corpus-level report. `wiki_admin rebuild` continues to emit a one-line summary into `wiki/log.md` ("last 7 days: 12 unsupported + 0 rejected / 47 wiki_write(s) (5 new unsupported pages) — 25.5% blocked-or-would-block under Phase 2b") so operators see the headline ratio without running the full report. Three numerators are surfaced because they answer different questions:
|
|
142
142
|
|
|
143
143
|
- **`unsupportedWrites`** — every write that ended up unsupported in warn mode, including re-edits.
|
|
144
144
|
- **`rejectedWrites`** — every write blocked under Phase 2b reject mode.
|
|
@@ -150,6 +150,64 @@ The ratio is omitted when the counter file is empty (early deployments would oth
|
|
|
150
150
|
|
|
151
151
|
Without this hook in Phase 2a, Phase 2b is guesswork. Including it now means the data is collected from day one.
|
|
152
152
|
|
|
153
|
+
## Corpus-level evidence report (Phase 4)
|
|
154
|
+
|
|
155
|
+
Phase 4 ships as `wiki_admin action: "evidence-report"`. The handler calls `buildEvidenceReport` (`src/evidence-report.ts`) which aggregates the four telemetry sources earlier phases populate into a single `EvidenceReport` and renders it to Markdown. Pass `write: true` to also persist the rendered report to `wiki/evidence-report.md` (a system page, so the regeneration does not tick the write counter).
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
agent-wiki call wiki_admin '{"action":"evidence-report"}'
|
|
159
|
+
agent-wiki call wiki_admin '{"action":"evidence-report","write":true}'
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The response carries the structured `report` (typed `EvidenceReport`) alongside the rendered `markdown`. The four sections, in order:
|
|
163
|
+
|
|
164
|
+
### 1. Source coverage
|
|
165
|
+
|
|
166
|
+
Walks every non-system page under `wiki/`, parses frontmatter, and buckets it. Counts are mutually exclusive — order of classification matters and is fixed:
|
|
167
|
+
|
|
168
|
+
| Bucket | Frontmatter signal |
|
|
169
|
+
|--------------------|-------------------------------------------------------------------|
|
|
170
|
+
| `synthesis` | `synthesis: true` **or** `type: synthesis` |
|
|
171
|
+
| `grounded` | non-empty `sources: [...]` |
|
|
172
|
+
| `unsupported` | `unsupported: true` (Phase 2a stamp) |
|
|
173
|
+
| `legacyUnsupported`| `legacyUnsupported: true` (grandfather flag from migration) |
|
|
174
|
+
| `other` | none of the above — classifier was bypassed; investigate |
|
|
175
|
+
|
|
176
|
+
Pages with both `sources` and `synthesis: true` count as `synthesis` (a synthesis page that cites supports is still a synthesis page). Malformed frontmatter counts as `other` rather than crashing the report.
|
|
177
|
+
|
|
178
|
+
### 2. Search trust
|
|
179
|
+
|
|
180
|
+
Reads `.agent-wiki/evidence-search-log.jsonl` (rotated to 30 days). Per `SearchEvent`:
|
|
181
|
+
|
|
182
|
+
- `totalSearches` and `abstainCount` (events whose `abstainReason !== null`)
|
|
183
|
+
- `abstainRatio` = `abstainCount / totalSearches`, or `null` when no events
|
|
184
|
+
- `medianTop1Score` — median BM25 score of the top match across the window
|
|
185
|
+
- `ratioHistogram` — `top1/top2` distribution bucketed at the strong/weak boundary: `< 1.5`, `1.5–2.0`, `2.0–3.0`, `≥ 3.0`. Single-result matches (no `top2`) are excluded; they have no comparator.
|
|
186
|
+
|
|
187
|
+
The 2.0 abstain floor described above still drives the per-call decision; this section just exposes corpus-wide drift.
|
|
188
|
+
|
|
189
|
+
### 3. Lineage diagnostic surfacing
|
|
190
|
+
|
|
191
|
+
Reads `raw/parsed/cobol/field-lineage.json` if present and pulls diagnostics from three surfaces — two cross-program lineage families plus a top-level input-quality surface:
|
|
192
|
+
|
|
193
|
+
- **`fieldLineage`** — top-level `summary.diagnosticsByKind`, flagging input models the lineage builder couldn't use (e.g. `parsed-zero-data-items` from listing-extracted copybooks whose headers escaped the col-7 comment filter). Suppressed when `totalDiagnostics === 0`.
|
|
194
|
+
- **`callBound`** — caller `USING` ↔ callee `LINKAGE` flow. Surfaces `callSites`, `pairs`, and the per-kind diagnostic counts the lineage builder emitted (e.g., unresolved callee, ambiguous parameter binding).
|
|
195
|
+
- **`db2`** — writer→reader flow via shared DB2 tables. Surfaces `sharedTables`, `pairs`, and per-kind diagnostic counts.
|
|
196
|
+
|
|
197
|
+
The exact diagnostic kinds are owned by the COBOL plugin's lineage builder and may grow over time; the report surfaces whatever kinds are present in the artifact so a new diagnostic surface does not require updating the report code. Other plugins (when they add their own field-lineage artifacts) follow the same shape.
|
|
198
|
+
|
|
199
|
+
### 4. Trend (last 4 weeks)
|
|
200
|
+
|
|
201
|
+
Reads `.agent-wiki/evidence-write-counter.jsonl` and buckets events into the four most recent weekly windows aligned to `now`. Each `TrendBucket` carries:
|
|
202
|
+
|
|
203
|
+
- `weekStart` — ISO date (YYYY-MM-DD) of the bucket's start
|
|
204
|
+
- `totalWrites` — every classified write in the bucket
|
|
205
|
+
- `unsupportedOrRejected` — `kind === "unsupported" || kind === "rejected"` only
|
|
206
|
+
|
|
207
|
+
Counter-only by design: the unsupported log dedupes transitions and would produce misleading "5 unsupported / 0 writes" rows for early weeks. Pre-counter weeks display 0/0; this self-resolves within four weeks of running upgraded code.
|
|
208
|
+
|
|
209
|
+
The rendered Markdown also draws unicode sparklines over the four buckets so the trend is readable at a glance without parsing the table.
|
|
210
|
+
|
|
153
211
|
## Synthesis-page grandfather migration (Caveat 4)
|
|
154
212
|
|
|
155
213
|
Day-1 of Phase 2a, every existing compiler-generated wiki page (`wiki/cobol/system-map.md`, `field-lineage.md`, `call-graph.md`, etc.) would register as "unsupported" — flooding the signal with false positives. Migration is run **once** during the first `wiki_admin rebuild` after Phase 2a deploys.
|
|
@@ -186,7 +244,8 @@ Phase 0 itself ships only:
|
|
|
186
244
|
- **Hybrid search vector ranking**: when BM25 + vector blend produce a result, the envelope's confidence should probably reflect the blended score, not BM25 alone. Phase 1 decides.
|
|
187
245
|
- **Multi-source pages**: a wiki page citing 5 raw sources isn't 5× more credible than one citing 1. Confidence should saturate, not multiply. Phase 2a chooses the curve.
|
|
188
246
|
- **Cross-language consistency**: when future plugins (Java, Python) join, their lineage tiers may not map cleanly to the COBOL table. Each plugin documents and implements its own mapping under `src/<plugin>/`, sharing only the envelope shape from `src/evidence.ts`. The COBOL plugin's `evidence-mapping.ts` is the reference template.
|
|
189
|
-
- **User-facing explanations**: `rationale` is the only freeform field. Phase 4
|
|
247
|
+
- **User-facing explanations**: `rationale` is the only freeform field. Phase 4 ships with structured aggregates in the corpus report rather than per-envelope `evidenceFactors`; the per-envelope rationale stays a single sentence.
|
|
248
|
+
- **Search percentile cutoff**: Phase 4's `evidence-search-log.jsonl` collects the data needed to reintroduce the corpus-percentile abstain cutoff dropped in Phase 1. Decide once the log has accumulated meaningful query history.
|
|
190
249
|
|
|
191
250
|
## See also
|
|
192
251
|
|
package/docs/tools.md
CHANGED
|
@@ -21,7 +21,7 @@ agent-wiki exposes 15 public tools through the Model Context Protocol.
|
|
|
21
21
|
| `wiki_delete` | Delete a page (guards system pages). Triggers index rebuild — stale indexes and empty dirs are cleaned up. |
|
|
22
22
|
| `wiki_list` | List pages, filter by entity type or tag |
|
|
23
23
|
| `wiki_search` | Full-text search with BM25 scoring, synonym expansion, fuzzy matching, and CJK support. Use `type` or `tags` to filter without a separate `wiki_list` call. Optional hybrid BM25+vector mode: enable `search.hybrid: true` in `.agent-wiki.yaml`, then run `wiki_admin` with `action: "rebuild"` to embed all pages. Returns `knowledge_gap` when no results found — includes suggested page slug, title, type, and tags for `wiki_write`. |
|
|
24
|
-
| `wiki_admin` | Unified wiki maintenance tool. Select `action`: `init`, `config`, `rebuild`, or `
|
|
24
|
+
| `wiki_admin` | Unified wiki maintenance tool. Select `action`: `init`, `config`, `rebuild`, `lint`, or `evidence-report`. `rebuild` regenerates indexes/timeline and search vectors; `lint` runs health checks and optional auto-fixes; `evidence-report` aggregates evidence-first telemetry into a corpus-level Markdown summary (see [Evidence-first surface](#evidence-first-surface) below). |
|
|
25
25
|
|
|
26
26
|
## Code Analysis — Language Plugins
|
|
27
27
|
|
|
@@ -38,6 +38,7 @@ agent-wiki exposes 15 public tools through the Model Context Protocol.
|
|
|
38
38
|
| `impact` | Query the compiled COBOL knowledge graph for downstream impact. Returns affected nodes grouped by dependency depth, with evidence and unresolved/lower-confidence markers. |
|
|
39
39
|
| `procedure_flow` | Query PERFORM flow inside one parsed source file. Returns section-level and paragraph-level flow, plus optional focused traversal from one procedure. |
|
|
40
40
|
| `field_lineage` | Query compiled field-lineage artifacts. Returns matches across three lineage families: deterministic shared-copybook reuse, inferred cross-copybook candidates (high-confidence + ambiguous), CALL boundary field flow (caller USING ↔ callee LINKAGE), and DB2 cross-program data flow via shared tables (writer/reader pairs with host variables). Each family appears only if the corresponding parsed evidence exists. |
|
|
41
|
+
| `dataflow_edges` | Query field-level dataflow edges from a parsed source file: `MOVE`/`COMPUTE`/`ADD` assignment, `EXEC SQL` host-variable, and `CALL USING` parameter edges. Filter with `from`/`to`, or set `field` + `transitive: true` to follow chains across the full graph (bounded by `max_depth`, default 10; `direction`: `downstream` / `upstream` / `both`). |
|
|
41
42
|
|
|
42
43
|
## Orchestration
|
|
43
44
|
|
|
@@ -223,6 +224,71 @@ After setup, every `wiki_write` automatically embeds the new page — no manual
|
|
|
223
224
|
|
|
224
225
|
**Vector index persistence:** Embeddings are cached in `wiki/.search-vectors.json`. The index is invalidated and rebuilt automatically if you change `search.model`.
|
|
225
226
|
|
|
227
|
+
## Evidence-first surface
|
|
228
|
+
|
|
229
|
+
Every retrieval / query / read tool returns an `evidence: EvidenceEnvelope` field alongside its existing payload. The envelope is purely additive — agents that don't know about it can ignore it; agents that do can branch on `confidence` (`strong` / `weak` / `absent`) and `abstain` without parsing tool-specific detail. Full contract and adoption history: [`evidence-envelope.md`](evidence-envelope.md).
|
|
230
|
+
|
|
231
|
+
### Tool responses that carry `evidence`
|
|
232
|
+
|
|
233
|
+
| Tool | Envelope shape |
|
|
234
|
+
|------|----------------|
|
|
235
|
+
| `raw_read` | `strong` + `deterministic`; `provenance: [{ raw }]`. Round-trippable file read. |
|
|
236
|
+
| `raw_coverage` | `strong` + `deterministic`; rationale carries the SHA-256-based covered/total ratio. |
|
|
237
|
+
| `code_parse` | `strong` + `deterministic`; rationale carries unit/procedure/symbol/relation counts. |
|
|
238
|
+
| `code_query trace_variable` | `strong` when references found, `absent` + `abstain` when none. |
|
|
239
|
+
| `code_query procedure_flow` | `strong` when the parsed model has sections/paragraphs, `absent` + `abstain` when empty. |
|
|
240
|
+
| `code_query field_lineage` | `strong` (deterministic match), `weak` (inferred high-confidence), or `absent` + `abstain` (ambiguous-only or no match). Mapped from COBOL lineage tiers via `cobolTierToEvidence`. |
|
|
241
|
+
| `code_query impact` | `strong` + `deterministic` only when every reachable edge is deterministic and every node resolved; otherwise `weak` + `inferred` reflecting the weakest link in the path. |
|
|
242
|
+
| `code_query dataflow_edges` | `strong` for non-empty edge lists; `absent` + `abstain` when the filter matches nothing. |
|
|
243
|
+
| `wiki_search`, `wiki_search_read` | Built by `buildSearchEnvelope` from BM25 score relative to the corpus floor (2.0) and the top1/top2 ratio. `wiki_search_read` further downgrades by the top read page's metadata (no sources, `synthesis: true`, `legacyUnsupported`, staleness). |
|
|
244
|
+
|
|
245
|
+
### `wiki_write` evidence classification
|
|
246
|
+
|
|
247
|
+
Every non-system `wiki_write` is classified by frontmatter and routed through one of five outcomes. Both `.agent-wiki/evidence-write-counter.jsonl` (denominator — every classified write) and `.agent-wiki/evidence-write-log.jsonl` (numerator — distinct unsupported transitions and rejected attempts) tick accordingly. Both logs rotate at 10 MB / 30 days during `wiki_admin lint`.
|
|
248
|
+
|
|
249
|
+
| Outcome | Trigger | Effect |
|
|
250
|
+
|---------|---------|--------|
|
|
251
|
+
| `grounded` | non-empty `sources: [...]` | Counter ticks; any prior `unsupported` / `legacyUnsupported` flag is cleared. |
|
|
252
|
+
| `synthesis` | `synthesis: true` or `type: synthesis` | Counter ticks as `synthesis`; same flag-clearing as grounded. |
|
|
253
|
+
| `unsupported` | empty `sources`, no synthesis flag, page not legacy | Stamps `unsupported: true` into frontmatter; counter ticks; the unsupported log fires only on the *transition* into unsupported (deduped across re-edits). |
|
|
254
|
+
| `legacy` | empty `sources`, no synthesis flag, but page already carries `legacyUnsupported: true` | Preserves the legacy marker; counter ticks as `legacy`; unsupported log stays silent. |
|
|
255
|
+
| `rejected` | empty `sources`, no synthesis flag, **and** Phase 2b reject mode is on | `wiki_write` throws; counter ticks as `rejected`; unsupported log fires with `rejected: true` and `rejectReason: "fresh"` or `"legacy"`. |
|
|
256
|
+
|
|
257
|
+
System pages (`index.md`, `log.md`, `timeline.md`, nested `*/index.md`, `evidence-report.md`) are excluded from classification — they're synthesis by construction and would otherwise flood the signal.
|
|
258
|
+
|
|
259
|
+
#### Phase 2b reject mode
|
|
260
|
+
|
|
261
|
+
Phase 2b ships disabled. Toggle it on once the warn-mode would-reject ratio settles, via either:
|
|
262
|
+
|
|
263
|
+
```yaml
|
|
264
|
+
# .agent-wiki.yaml
|
|
265
|
+
evidence:
|
|
266
|
+
reject_unsupported_writes: true
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
export AGENT_WIKI_EVIDENCE_REJECT_UNSUPPORTED=true
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
The env var takes precedence over the YAML and accepts only `true` / `false` (case-insensitive — `1` / `yes` are intentionally **not** truthy). The error message differentiates `fresh` (a brand-new unsupported page) from `legacy` (an attempt to update a `legacyUnsupported` page without resolving its evidence status). Reads of legacy pages are unaffected — only updates require committing to grounded or synthesis.
|
|
274
|
+
|
|
275
|
+
#### Frontmatter flags written by the classifier
|
|
276
|
+
|
|
277
|
+
| Flag | Meaning |
|
|
278
|
+
|------|---------|
|
|
279
|
+
| `unsupported: true` | Stamped on writes with empty `sources` and no synthesis flag, in warn mode. Cleared automatically when the page later gains `sources` or `synthesis: true`. |
|
|
280
|
+
| `legacyUnsupported: true` | Set by the one-shot Phase 2a migration on pre-existing user-authored pages with empty sources. Preserved across edits until the page is updated to grounded or synthesis. |
|
|
281
|
+
| `synthesis: true` | Author-set or migration-set marker for legitimate synthesis pages. Equivalent to `type: synthesis` for classification purposes. |
|
|
282
|
+
|
|
283
|
+
### Corpus-level evidence report
|
|
284
|
+
|
|
285
|
+
`wiki_admin action: "evidence-report"` aggregates the four telemetry surfaces — page frontmatter, the per-write counter, the search log, and the COBOL field-lineage diagnostics artifact — into a single `EvidenceReport`. The structured report is returned alongside the rendered Markdown; pass `write: true` to also persist it to `wiki/evidence-report.md`. Section breakdown and field semantics: [`evidence-envelope.md` §"Corpus-level evidence report (Phase 4)"](evidence-envelope.md#corpus-level-evidence-report-phase-4).
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
agent-wiki call wiki_admin '{"action":"evidence-report"}'
|
|
289
|
+
agent-wiki call wiki_admin '{"action":"evidence-report","write":true}'
|
|
290
|
+
```
|
|
291
|
+
|
|
226
292
|
## Auto-Linking
|
|
227
293
|
|
|
228
294
|
Every `wiki_write` automatically scans the page body for mentions of existing page titles and injects `[[slug|text]]` links:
|
package/package.json
CHANGED