fix: Project knowledge graph for structural defect detection (#629)

Add lib/build-graph.py that builds a NetworkX DiGraph from project docs
and forge API, runs structural analyses (orphans, cycles, disconnected
clusters, thin objectives, bottlenecks), and outputs a JSON report.

Predictor and reviewer agents now call build-graph.py before launching
their Claude sessions and inject the report as context.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-24 21:24:20 +00:00
parent e0b70d67f4
commit 3a7b95046d
4 changed files with 590 additions and 1 deletions

View file

@ -50,6 +50,19 @@ log "--- Predictor run start ---"
load_formula "$FACTORY_ROOT/formulas/run-predictor.toml"
build_context_block AGENTS.md RESOURCES.md VISION.md planner/prerequisite-tree.md
# ── Build structural analysis graph ──────────────────────────────────────
GRAPH_REPORT="/tmp/${PROJECT_NAME}-graph-report.json"
GRAPH_SECTION=""
if python3 "$FACTORY_ROOT/lib/build-graph.py" \
--project-root "$PROJECT_REPO_ROOT" \
--output "$GRAPH_REPORT" 2>>"$LOG_FILE"; then
GRAPH_SECTION=$(printf '\n## Structural analysis\n```json\n%s\n```\n' \
"$(cat "$GRAPH_REPORT")")
log "graph report generated: $(jq -r '.stats | "\(.nodes) nodes, \(.edges) edges"' "$GRAPH_REPORT")"
else
log "WARN: build-graph.py failed — continuing without structural analysis"
fi
# ── Read scratch file (compaction survival) ───────────────────────────────
SCRATCH_CONTEXT=$(read_scratch_context "$SCRATCH_FILE")
SCRATCH_INSTRUCTION=$(build_scratch_instruction "$SCRATCH_FILE")
@ -73,6 +86,7 @@ and tools only, not general news). Limit to 3 web searches per run.
## Project context
${CONTEXT_BLOCK}
${GRAPH_SECTION}
${SCRATCH_CONTEXT}
## Formula
${FORMULA_CONTENT}