fix: extract build_graph_section helper to eliminate duplicate code (#667)
Move graph report generation into build_graph_section() in lib/formula-session.sh. Both planner-run.sh and predictor-run.sh now call the shared helper instead of duplicating the same 11 lines. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1e8e4e5112
commit
12d871c865
3 changed files with 24 additions and 22 deletions
|
|
@ -205,6 +205,28 @@ read_scratch_context() {
|
||||||
fi
|
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 ──────────────────────────────────────────────
|
# ── Prompt + monitor helpers ──────────────────────────────────────────────
|
||||||
|
|
||||||
# build_prompt_footer [EXTRA_API_LINES]
|
# build_prompt_footer [EXTRA_API_LINES]
|
||||||
|
|
|
||||||
|
|
@ -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_context_block VISION.md AGENTS.md RESOURCES.md planner/prerequisite-tree.md
|
||||||
|
|
||||||
# ── Build structural analysis graph ──────────────────────────────────────
|
# ── Build structural analysis graph ──────────────────────────────────────
|
||||||
GRAPH_REPORT="/tmp/${PROJECT_NAME}-graph-report.json"
|
build_graph_section
|
||||||
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 planner memory ─────────────────────────────────────────────────
|
# ── Read planner memory ─────────────────────────────────────────────────
|
||||||
MEMORY_BLOCK=""
|
MEMORY_BLOCK=""
|
||||||
|
|
|
||||||
|
|
@ -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_context_block AGENTS.md RESOURCES.md VISION.md planner/prerequisite-tree.md
|
||||||
|
|
||||||
# ── Build structural analysis graph ──────────────────────────────────────
|
# ── Build structural analysis graph ──────────────────────────────────────
|
||||||
GRAPH_REPORT="/tmp/${PROJECT_NAME}-graph-report.json"
|
build_graph_section
|
||||||
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) ───────────────────────────────
|
# ── Read scratch file (compaction survival) ───────────────────────────────
|
||||||
SCRATCH_CONTEXT=$(read_scratch_context "$SCRATCH_FILE")
|
SCRATCH_CONTEXT=$(read_scratch_context "$SCRATCH_FILE")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue