Skip to content

Commit e69f447

Browse files
committed
Add prebuilt native index probe, provenance convention, version 5 bump, and dedupe MODE-OFF invariant fix
Change-Id: Id5a7011205086169ebf1a891e167e423c7e472ff
1 parent 0ec1b28 commit e69f447

5 files changed

Lines changed: 59 additions & 21 deletions

File tree

‎mantis-dedupe/SKILL.md‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ Execute your task as follows:
188188

189189
- **MATCHED** (both present and equal): soft-delete the current finding as a
190190
loop-duplicate exactly as before — set `"status": "DUPLICATE"` and
191-
`"duplicate_of": "<archived_uuid>"`, ensure
192-
`mkdir -p workspace/findings/.trash/`, move it there, and log a
193-
`loop_filter` transaction in `workspace/.tx_log.jsonl`. If the current
194-
finding lacks `lineage_id` but the archived finding has one, inherit the
195-
archived finding's `lineage_id` onto the current finding before moving it
196-
(so the lineage chain is preserved across the merge).
191+
`"duplicate_of": "<archived_uuid>"`, clear `possible_duplicate_of` if
192+
present, ensure `mkdir -p workspace/findings/.trash/`, move it there, and
193+
log a `loop_filter` transaction in `workspace/.tx_log.jsonl`. If the
194+
current finding lacks `lineage_id` but the archived finding has one,
195+
inherit the archived finding's `lineage_id` onto the current finding before
196+
moving it (so the lineage chain is preserved across the merge).
197197
- **NOT_MATCHED** (differ, or either absent): do NOT set `DUPLICATE` and do
198198
NOT move to trash. Keep the current finding ACTIVE and set
199199
`"possible_duplicate_of": "<archived_uuid>"` (a soft, non-terminal hint).
@@ -208,9 +208,10 @@ Execute your task as follows:
208208
> pointing to the same target UUID.
209209
> - `status = "DUPLICATE"` MUST NOT coexist with `possible_duplicate_of`
210210
> pointing to the same target UUID.
211-
> - Under **NOT_MATCHED**, the finding's `status` MUST remain active (e.g.
212-
> `VALID`, `PROVISIONALLY_VALID`, `NEEDS_RESEARCH`), `duplicate_of` MUST
213-
> NOT be set, and the finding MUST NOT be moved to `.trash/`. Setting
211+
> - Under **NOT_MATCHED** (outside the MODE-OFF fallback exception), the
212+
> finding's `status` MUST remain active (e.g. `VALID`,
213+
> `PROVISIONALLY_VALID`, `NEEDS_RESEARCH`), `duplicate_of` MUST NOT be set,
214+
> and the finding MUST NOT be moved to `.trash/`. Setting
214215
> `possible_duplicate_of` is a non-terminal hint only.
215216
216217
- **POSSIBLE REGRESSION:** if the archived match has a RESOLVED status

‎mantis-pipeline-adapter/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ Two implementations are supported, sharing the same query contract:
10231023

10241024
- **Option A (Default — Skill-Based):** The `mantis-structural-index` skill
10251025
generates and runs helper scripts (`build_structural_index.py` and
1026-
`query_structural_index.py`, both `# MANTIS_HELPER_VERSION = 4`) using
1026+
`query_structural_index.py`, both `# MANTIS_HELPER_VERSION = 5`) using
10271027
capability-based per-partition backend selection, degrading to grep.
10281028
- **Option B (Maximum Power — MCP-Based):** The harness owns a persistent
10291029
structural index serving `find_callers(symbol)`, `find_callees(function)`,

‎mantis-plan/SKILL.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ Execute the planning stage as follows:
474474
NEVER cause a file to be dropped from the audit scope.
475475
- Every result carries `precision` and `backend` fields — use
476476
`precision` (`semantic` > `typecheck` > `ast` > `symbol-only` >
477-
`heuristic` > `coverage-only`) to weight trust in the result.
477+
`heuristic` > `deferred` > `coverage-only`) to weight trust in the
478+
result.
478479
- If the structural index is absent (no `manifest.json`), empty, or the
479480
query helper is missing: fall back to grep-based discovery (today's
480481
behavior). The structural index is a coverage HINT only.

‎mantis-researcher/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Execute the research stage as follows:
209209
MUST run exhaustive grep.
210210
- Use the `precision` and `backend` fields on every result to weight
211211
trust (`semantic` > `typecheck` > `ast` > `symbol-only` > `heuristic` >
212-
`coverage-only`).
212+
`deferred` > `coverage-only`).
213213

214214
- **Wave 1 (Rapid Triage):** Use `find_callers()` to SUPPLEMENT grep as a
215215
ranking HINT — ORDER, never MEMBERSHIP. Structural index results

‎mantis-structural-index/SKILL.md‎

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ exposed through a bounded query helper.
4646
manifest absent).
4747
- `workspace/kb/structural_index/units/` (content-addressed cache for
4848
incremental unit reuse).
49+
- `workspace/kb/structural_index/native/` and sidecar `provenance.json` files
50+
(prebuilt index attachments and metadata manifests).
4951
- CODE_ROOT source files (via generated helper script — the script parses all
5052
source files under `CODE_ROOT`).
5153
- **Writes**:
@@ -186,6 +188,39 @@ helper probes each tier per partition and selects the highest available:
186188
grep; no structural index is written. Manifest records `status: "empty"`.
187189
Consumers fall back to grep-based discovery (today's behavior byte-for-byte).
188190

191+
**Native Index Probing & Resolution Rules**:
192+
193+
- **Probe instruction**: Before evaluating per-partition backends, probe
194+
`workspace/kb/structural_index/native/` and subdirectories
195+
`native/{scip,lsif,kythe}/` for prebuilt index files.
196+
- **Snapshot-declaration convention**: Because native formats (SCIP, LSIF,
197+
Kythe) do not embed snapshot identity directly in their binary payload,
198+
prebuilt indexes MUST declare their target snapshot using a sidecar
199+
`provenance.json` manifest located at
200+
`workspace/kb/structural_index/native/provenance.json` or
201+
`native/<kind>/provenance.json`. The manifest contains an array of
202+
attachments:
203+
`[{"kind": "scip|lsif|kythe", "path": "...", "snapshot_id": "...", "root_fingerprint": "...", "language": "...", "indexer": "...", "precision": "semantic", "files": [...]}]`.
204+
A native index is matched if its declared `snapshot_id` equals `SNAPSHOT_ID`
205+
(when `SNAPSHOT_ID != "unknown"`) or its `root_fingerprint` matches the
206+
workspace's calculated root fingerprint. If the `files` array is absent or
207+
empty, treat the native index as covering no individual files directly (record
208+
in `manifest.native_indexes` but do not update `coverage` rows; fall through
209+
to lower tiers for all files).
210+
- **Record-and-Defer Ingestion Rule**: Parsing raw binary native indexes (e.g.
211+
SCIP protobuf) in pure Python without dependencies is costly and complex.
212+
Option A builder scripts MUST detect matching prebuilt native indexes, record
213+
their entries in `manifest.native_indexes`, and set the `coverage` table
214+
`backend` (e.g., `"scip"` or `"scip-clangd"`) for all files listed in the
215+
provenance manifest. If `catalog.sqlite` is NOT populated with symbols from
216+
the native index (raw binary deferred to harness/MCP readers), set
217+
`coverage.status = "deferred"` and `precision = "deferred"` (with
218+
`indexed_files = 0`). This prevents the query helper from claiming an
219+
un-ingested partition is "authoritative empty" at `semantic` precision,
220+
ensuring consumers run the mandatory grep fallback. When `catalog.sqlite` IS
221+
populated (e.g., via Option B pre-ingestion or `scip-to-sqlite`), set
222+
`precision = "semantic"` and `status = "indexed"`.
223+
189224
**LSP is NOT equivalent to SCIP / LSIF.** LSP is an interactive protocol whose
190225
workspace state may be partial or mutable. Use it only when the server can
191226
demonstrate snapshot identity AND complete workspace coverage. A running
@@ -198,7 +233,7 @@ indexers (e.g., a SCIP index for Go + tree-sitter for Python) within a single
198233
catalog.
199234

200235
The determinism lives in a runtime-generated versioned helper
201-
(`build_structural_index.py`, `# MANTIS_HELPER_VERSION = 4`, grep-and-regenerate
236+
(`build_structural_index.py`, `# MANTIS_HELPER_VERSION = 5`, grep-and-regenerate
202237
on reuse) that probes and selects backends per partition. No shipped binaries;
203238
air-gapped-safe.
204239

@@ -231,8 +266,8 @@ a different integer, REGENERATE.
231266
#### Builder: `build_structural_index.py`
232267

233268
1. Write the builder to `workspace/helpers/build_structural_index.py`. The FIRST
234-
LINE MUST be exactly `# MANTIS_HELPER_VERSION = 4`. Before reusing an
235-
existing helper, grep its first lines for `MANTIS_HELPER_VERSION = 4`; if
269+
LINE MUST be exactly `# MANTIS_HELPER_VERSION = 5`. Before reusing an
270+
existing helper, grep its first lines for `MANTIS_HELPER_VERSION = 5`; if
236271
that marker is absent or a different integer, REGENERATE the helper.
237272
2. The builder partitions the codebase into semantic units (see Per-Language
238273
Semantic Units), computes content-addressed cache keys, checks `units/` for
@@ -261,8 +296,8 @@ a different integer, REGENERATE.
261296
#### Query helper: `query_structural_index.py`
262297

263298
1. Write the query helper to `workspace/helpers/query_structural_index.py`. The
264-
FIRST LINE MUST be exactly `# MANTIS_HELPER_VERSION = 4`. Before reusing an
265-
existing helper, grep its first lines for `MANTIS_HELPER_VERSION = 4`; if
299+
FIRST LINE MUST be exactly `# MANTIS_HELPER_VERSION = 5`. Before reusing an
300+
existing helper, grep its first lines for `MANTIS_HELPER_VERSION = 5`; if
266301
absent or a different integer, REGENERATE.
267302
2. The query helper provides bounded, paginated operations against
268303
`catalog.sqlite` (or a remote endpoint — identical API). It IS the
@@ -316,13 +351,14 @@ workspace/kb/structural_index/
316351
├── shards/ # Partitioned serving data (large corpora)
317352
│ └── shard_0000.sqlite
318353
├── native/ # Prebuilt index attachments (SCIP, Kythe, LSIF)
354+
│ ├── provenance.json # Prebuilt index provenance manifest
319355
│ ├── scip/
320356
│ └── kythe/
321357
└── tmp/ # Temporary objects during build
322358
323359
workspace/helpers/
324-
├── build_structural_index.py # Builder (MANTIS_HELPER_VERSION = 4)
325-
└── query_structural_index.py # Query helper (MANTIS_HELPER_VERSION = 4)
360+
├── build_structural_index.py # Builder (MANTIS_HELPER_VERSION = 5)
361+
└── query_structural_index.py # Query helper (MANTIS_HELPER_VERSION = 5)
326362
327363
workspace/kb/structural_index.jsonl # Compatibility pointer
328364
```
@@ -347,7 +383,7 @@ workspace/kb/structural_index.jsonl # Compatibility pointer
347383
"coverage": {"total_files": 0, "indexed_files": 0, "failed_files": 0, "deferred_files": 0},
348384
"shards": [{"id": "", "path": "", "checksum": "", "partition_key": "", "symbol_count": 0, "edge_count": 0}],
349385
"deferred_units": [{"unit_id": "", "language": "", "files": [], "priority": 4, "reason": ""}],
350-
"native_indexes": [{"kind": "scip", "path": "", "language": "", "indexer": "", "precision": ""}],
386+
"native_indexes": [{"kind": "scip", "path": "", "snapshot_id": "", "root_fingerprint": "", "language": "", "indexer": "", "precision": ""}],
351387
"baseline": {"source": "ci|local|none", "snapshot_id": "", "manifest_path": ""},
352388
"overlay": {"units_added": 0, "units_modified": 0, "files": []},
353389
"compat_pointer": {"path": "structural_index.jsonl", "full_export": true, "symbol_count": 0},
@@ -379,7 +415,7 @@ CREATE TABLE IF NOT EXISTS symbols (
379415
kind TEXT NOT NULL,
380416
signature TEXT,
381417
backend TEXT NOT NULL,
382-
precision TEXT NOT NULL CHECK (precision IN ('semantic','typecheck','ast','symbol-only','heuristic','coverage-only')),
418+
precision TEXT NOT NULL CHECK (precision IN ('semantic','typecheck','ast','symbol-only','heuristic','deferred','coverage-only')),
383419
corpus TEXT DEFAULT 'default',
384420
partition_key TEXT,
385421
unit_cache_key TEXT,

0 commit comments

Comments
 (0)