diff --git a/lib/formula-session.sh b/lib/formula-session.sh index c596d8a..b75ae80 100644 --- a/lib/formula-session.sh +++ b/lib/formula-session.sh @@ -205,6 +205,28 @@ read_scratch_context() { fi } +# ── Graph report helper ─────────────────────────────────────────────────── + +# build_graph_section +# Runs build-graph.py and sets GRAPH_SECTION to a markdown block containing +# the JSON report. Sets GRAPH_SECTION="" on failure (non-fatal). +# Requires globals: PROJECT_NAME, FACTORY_ROOT, PROJECT_REPO_ROOT, LOG_FILE. +build_graph_section() { + local report="/tmp/${PROJECT_NAME}-graph-report.json" + # shellcheck disable=SC2034 # consumed by the calling script's PROMPT + GRAPH_SECTION="" + if python3 "$FACTORY_ROOT/lib/build-graph.py" \ + --project-root "$PROJECT_REPO_ROOT" \ + --output "$report" 2>>"$LOG_FILE"; then + # shellcheck disable=SC2034 + GRAPH_SECTION=$(printf '\n## Structural analysis\n```json\n%s\n```\n' \ + "$(cat "$report")") + log "graph report generated: $(jq -r '.stats | "\(.nodes) nodes, \(.edges) edges"' "$report")" + else + log "WARN: build-graph.py failed — continuing without structural analysis" + fi +} + # ── Prompt + monitor helpers ────────────────────────────────────────────── # build_prompt_footer [EXTRA_API_LINES] diff --git a/planner/planner-run.sh b/planner/planner-run.sh index 0b2e22d..c529aa9 100755 --- a/planner/planner-run.sh +++ b/planner/planner-run.sh @@ -49,17 +49,7 @@ load_formula "$FACTORY_ROOT/formulas/run-planner.toml" build_context_block VISION.md AGENTS.md RESOURCES.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 +build_graph_section # ── Read planner memory ───────────────────────────────────────────────── MEMORY_BLOCK="" diff --git a/predictor/predictor-run.sh b/predictor/predictor-run.sh index 1cf0b63..989576d 100755 --- a/predictor/predictor-run.sh +++ b/predictor/predictor-run.sh @@ -51,17 +51,7 @@ 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 +build_graph_section # ── Read scratch file (compaction survival) ─────────────────────────────── SCRATCH_CONTEXT=$(read_scratch_context "$SCRATCH_FILE")