luminos/luminos_lib
Jeff Smith 427f66b488 refactor(ai): extract _run_dir_loop into three focused helpers (#57)
_run_dir_loop was ~160 lines holding four conceptual layers in one
function: pre-loop setup, budget check + partial-flush, API call +
response printing, and tool dispatch + done detection. Phase 3 dynamic
turn allocation will inject more state into the same code path, so
this debt is paid before that lands.

Three new helpers above _run_dir_loop:

- _build_dir_loop_context(): pure setup. Builds the dir context, child
  summaries, survey block, filtered tool list, system prompt, and seed
  user message. Returns a _DirLoopContext namedtuple.
- _flush_partial_dir_entry(): idempotent partial-cache writer for the
  budget-exceeded path. Returns the partial summary string. Idempotent
  via cache.has_entry() guard, so callers can call it without checking.
- _handle_turn_response(): per-turn response processing. Prints text
  blocks and tool decisions, appends the assistant message, dispatches
  tools (or nudges the agent to call submit_report), appends
  tool_results. Returns (done, summary).

_run_dir_loop is now a ~25-line coordinator: build context, then
for-loop calls budget check, API, and turn handler in sequence.

No behavior change. 164 tests pass. Internals.md §4 updated for the
new structure and the file:line refs that drifted.
2026-04-11 10:02:21 -06:00
..
__init__.py chore: initial project scaffold 2026-03-30 09:57:11 -06:00
ai.py refactor(ai): extract _run_dir_loop into three focused helpers (#57) 2026-04-11 10:02:21 -06:00
ast_parser.py refactor: extract AST parsing into luminos_lib/ast_parser.py 2026-03-30 14:34:02 -06:00
cache.py feat: AI investigation is the product, drop zero-dep constraint (#64) 2026-04-11 09:43:47 -06:00
code.py feat: in-place per-file progress for classify, count, and large-file steps 2026-04-06 14:26:37 -06:00
disk.py feat: add -x/--exclude flag to exclude directories from scan and AI analysis 2026-04-06 14:32:12 -06:00
filetypes.py feat(filetypes): expose raw signals to survey, remove classifier bias (#42) 2026-04-06 22:36:14 -06:00
prompts.py feat(filetypes): expose raw signals to survey, remove classifier bias (#42) 2026-04-06 22:36:14 -06:00
recency.py feat: add -x/--exclude flag to exclude directories from scan and AI analysis 2026-04-06 14:32:12 -06:00
report.py feat: add chain-of-thought observability tools 2026-03-30 13:02:19 -06:00
tree.py feat: add -x/--exclude flag to exclude directories from scan and AI analysis 2026-04-06 14:32:12 -06:00