Objective
Replace hard-coded node IDs and question-pattern matching in query-engine.ts with metadata-driven configuration. The query engine should be spec-content-agnostic so that ID changes in FPF-spec.md no longer require code changes.
Problem areas:
addHeuristicSeeds() (line ~600) and heuristicInitialNodeIds() (line ~646) contain hard-coded node IDs ('C.17', 'C.18', 'A.1.1', etc.) tied to specific question phrasings
buildRouteAnswer() (line ~1247) has a hard-coded check for route.name === 'project alignment' with route-specific constraints
Proposed fix for seeds: Drive seed rules from spec metadata — add seed_hints to PatternRecord, tag patterns with semantic categories, or move heuristic seed rules into a declarative config file.
Proposed fix for route special-casing: Add an optional constraints field to RouteRecord, parse route-level constraints during compilation, use route.constraints generically.
"Done" looks like: No hard-coded FPF node IDs or route names remain in query-engine.ts; all such knowledge lives in compiled metadata.
Kind
refactor
Affected area
src/runtime/ (compiler & query engine)
Acceptance criteria
Agent-delegable?
partially — needs human review
Additional context
src/runtime/query-engine.ts lines ~600–646 (heuristic seeds), line ~1247 (route special-case)
src/runtime/types.ts: PatternRecord.queries (already exists but underused), RouteRecord (no constraints field yet)
FPF grounding:
- A.7 (Strict Distinction / Clarity Lattice, Stable): Hard-coded node IDs in the query engine conflate design-time knowledge (which IDs exist in the spec) with run-time behavior (how queries are routed). Per A.7:5.3, a MethodDescription (the compiled index describing the spec) must not be confused with the Method (the retrieval algorithm) or the Work (a specific query execution).
- A.15 (Role–Method–Work Alignment, Stable): The query engine's Method should be spec-content-agnostic. Content knowledge belongs in compiled metadata (a MethodDescription), not baked into the engine code. Hard-coding IDs is the "recipe-as-evidence" anti-pattern (A.15:8).
- A.1.1 (U.BoundedContext, Stable): Hard-coded IDs break the semantic boundary between the query engine (a system) and the spec content (an episteme). The engine should not "know" specific FPF IDs — that knowledge should be mediated through the compiled index, respecting bounded context separation.
Measurable impact
| Metric |
Before |
After (target) |
How to measure |
Hard-coded node IDs in query-engine.ts heuristic methods |
6 lines |
0 |
grep -Ec "'C\.[0-9]|'A\.[0-9]|'B\.[0-9]|'F\.[0-9]" src/runtime/query-engine.ts |
Hard-coded route name checks in query-engine.ts |
1 ('project alignment') |
0 |
grep -c "'project alignment'" src/runtime/query-engine.ts |
| Seed rules in compiled metadata or config |
0 |
≥1 (declarative config or PatternRecord.seed_hints) |
grep -Ec 'seed_hints|seedRules' src/runtime/types.ts src/runtime/*.ts |
Route constraints in RouteRecord metadata |
0 |
≥1 (constraints field) |
grep -c 'constraints' src/runtime/types.ts |
| Existing test pass rate |
all pass |
all pass (no regressions) |
bun run test |
Objective
Replace hard-coded node IDs and question-pattern matching in
query-engine.tswith metadata-driven configuration. The query engine should be spec-content-agnostic so that ID changes inFPF-spec.mdno longer require code changes.Problem areas:
addHeuristicSeeds()(line ~600) andheuristicInitialNodeIds()(line ~646) contain hard-coded node IDs ('C.17','C.18','A.1.1', etc.) tied to specific question phrasingsbuildRouteAnswer()(line ~1247) has a hard-coded check forroute.name === 'project alignment'with route-specific constraintsProposed fix for seeds: Drive seed rules from spec metadata — add
seed_hintstoPatternRecord, tag patterns with semantic categories, or move heuristic seed rules into a declarative config file.Proposed fix for route special-casing: Add an optional
constraintsfield toRouteRecord, parse route-level constraints during compilation, useroute.constraintsgenerically."Done" looks like: No hard-coded FPF node IDs or route names remain in
query-engine.ts; all such knowledge lives in compiled metadata.Kind
refactor
Affected area
src/runtime/ (compiler & query engine)
Acceptance criteria
query-engine.tsheuristic methodsbuildRouteAnswer()RouteRecordmetadataAgent-delegable?
partially — needs human review
Additional context
src/runtime/query-engine.tslines ~600–646 (heuristic seeds), line ~1247 (route special-case)src/runtime/types.ts:PatternRecord.queries(already exists but underused),RouteRecord(no constraints field yet)FPF grounding:
Measurable impact
query-engine.tsheuristic methodsgrep -Ec "'C\.[0-9]|'A\.[0-9]|'B\.[0-9]|'F\.[0-9]" src/runtime/query-engine.tsquery-engine.ts'project alignment')grep -c "'project alignment'" src/runtime/query-engine.tsPatternRecord.seed_hints)grep -Ec 'seed_hints|seedRules' src/runtime/types.ts src/runtime/*.tsRouteRecordmetadataconstraintsfield)grep -c 'constraints' src/runtime/types.tsbun run test