mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-11-08 09:23:05 +08:00
feat(prompt-hook): graph-derived gate tier + confidence-tiered injection + gate telemetry (#1136)
The keyword gate (#1126) can never know a repo's domain nouns. This adds the graph-derived tier the design discussion converged on: symbol names are split into prose segments at index time (name_segment_vocab, riding the insertNode write path), and the hook verifies a prompt's plain words against them — "the state machine des commandes" → OrderStateMachine, in any language whose technical nouns are Latin script. Confidence now decides HOW MUCH to inject, not just whether: - HIGH (keyword, or index-verified code token): full explore injection, unchanged — the validated adoption lever. - MEDIUM (segment matches only): a ~500-byte pointer naming the matching symbols; the AGENT writes the explore query. Never runs explore, so a fuzzy match can't inject 16KB of wrong-feature context. - Silent otherwise, as before. Precision is derived from the repo's own naming statistics plus measured FP fixes: co-occurrence (≥2 words on one name) always qualifies; a single word must be ≥5 chars, cluster across 2–25 names (singletons are prose coincidence: "deploy to production" → matchesNonProductionDir), match a multi-segment name, and not be an English function/filler word (the one place a word list is honest: identifiers are English, so only English prose collides). Every candidate is re-verified against nodes before being surfaced — vocab rows are proposals, deletions leave orphans by design, a full index rebuilds from scratch, and sync heals pre-upgrade databases (batched + yielding; emptiness captured at sync ENTRY so the sync's own writes can't mask the backfill). Schema v7 migration is DDL-only (instant; none of the #1067 row-churn hazards). Gate outcomes roll up as anonymous usage counters (prompt-hook-gate-<outcome>, names only, never content) through the existing telemetry pipeline — recall becomes measurable, and the counters are the agreed kill-criterion data for ever revisiting a local classifier. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
317e7f4d3d
commit
e699ee9686
@@ -123,6 +123,25 @@ CREATE TRIGGER IF NOT EXISTS nodes_au AFTER UPDATE ON nodes BEGIN
|
||||
VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature);
|
||||
END;
|
||||
|
||||
-- Prose-word → symbol-name lookup for the prompt hook's graph-derived gate.
|
||||
-- One row per (segment, name): segment is a lowercased word of a symbol name
|
||||
-- ("OrderStateMachine" → order, state, machine — see identifier-segments.ts),
|
||||
-- which lets natural-language prompt words be verified against the graph in
|
||||
-- any language whose technical nouns are Latin script. File nodes are
|
||||
-- excluded — a file's basename duplicates the symbols inside it and skews the
|
||||
-- singleton-vs-cluster rarity statistics. FTS can't serve this lookup (its
|
||||
-- tokenizer keeps camelCase names as single tokens), so segments are
|
||||
-- materialized on the node write path.
|
||||
-- Deletions leave orphan rows ON PURPOSE: rows are PROPOSALS, always
|
||||
-- re-verified against nodes before being surfaced (CodeGraph.getSegmentMatches),
|
||||
-- and a full index clears the table at its start. Populated lazily on old
|
||||
-- databases (empty until the next index/sync heals it).
|
||||
CREATE TABLE IF NOT EXISTS name_segment_vocab (
|
||||
segment TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
PRIMARY KEY (segment, name)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
-- Edge indexes.
|
||||
-- idx_edges_source / idx_edges_target are intentionally omitted —
|
||||
-- the (source, kind) and (target, kind) composites below cover the
|
||||
|
||||
Reference in New Issue
Block a user