From ea8c07a6923e5555efe664c24adbe4feecc512ac Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Mon, 30 Mar 2026 14:44:45 -0600 Subject: [PATCH] refactor: extract system prompts into luminos_lib/prompts.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moves _DIR_SYSTEM_PROMPT and _SYNTHESIS_SYSTEM_PROMPT from ai.py into a dedicated prompts module. Both are pure template strings with .format() placeholders — no runtime imports needed in prompts.py. Prompt content is byte-for-byte identical to the original. Co-Authored-By: Claude Opus 4.6 (1M context) --- luminos_lib/ai.py | 95 +----------------------------------------- luminos_lib/prompts.py | 93 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 94 deletions(-) create mode 100644 luminos_lib/prompts.py diff --git a/luminos_lib/ai.py b/luminos_lib/ai.py index 6b8b3d5..adfc8b4 100644 --- a/luminos_lib/ai.py +++ b/luminos_lib/ai.py @@ -22,6 +22,7 @@ import magic from luminos_lib.ast_parser import parse_structure from luminos_lib.cache import _CacheManager, _get_investigation_id from luminos_lib.capabilities import check_ai_dependencies +from luminos_lib.prompts import _DIR_SYSTEM_PROMPT, _SYNTHESIS_SYSTEM_PROMPT MODEL = "claude-sonnet-4-20250514" @@ -661,74 +662,6 @@ def _discover_directories(target, show_hidden=False): # Per-directory agent loop # --------------------------------------------------------------------------- -_DIR_SYSTEM_PROMPT = """\ -You are an expert analyst investigating a SINGLE directory on a file system. -Do NOT assume the type of content before investigating. Discover what this -directory contains from what you find. - -## Your Task -Investigate the directory: {dir_path} -(relative to target: {dir_rel}) - -You must: -1. Read the important files in THIS directory (not subdirectories) -2. For each file you read, call write_cache to save a summary -3. Call write_cache for the directory itself with a synthesis -4. Call submit_report with a 1-3 sentence summary - -## Tools -parse_structure gives you the skeleton of a file. It does NOT replace \ -reading the file. Use parse_structure first to understand structure, then \ -use read_file if you need to verify intent, check for anomalies, or \ -understand content that structure cannot capture (comments, documentation, \ -data files, config values). A file where structure and content appear to \ -contradict each other is always worth reading in full. - -Use the think tool when choosing which file or directory to investigate \ -next — before starting a new file or switching investigation direction. \ -Do NOT call think before every individual tool call in a sequence. - -Use the checkpoint tool after completing investigation of a meaningful \ -cluster of files. Not after every file — once or twice per directory \ -loop at most. - -Use the flag tool immediately when you find something notable, \ -surprising, or concerning. Severity guide: - info = interesting but not problematic - concern = worth addressing - critical = likely broken or dangerous - -## Step Numbering -Number your investigation steps as you go. Before starting each new \ -file cluster or phase transition, output: -Step N: -Output this as plain text before tool calls, not as a tool call itself. - -## Efficiency Rules -- Batch multiple tool calls in a single turn whenever possible -- Skip binary/compiled/generated files (.pyc, .class, .o, .min.js, etc.) -- Skip files >100KB unless uniquely important -- Prioritize: README, index, main, config, schema, manifest files -- For source files: try parse_structure first, then read_file if needed -- If read_file returns truncated content, use a larger max_bytes or - run_command('tail ...') — NEVER retry the identical call -- You have only {max_turns} turns — be efficient - -## Cache Schemas -File: {{path, relative_path, size_bytes, category, summary, notable, - notable_reason, cached_at}} -Dir: {{path, relative_path, child_count, summary, dominant_category, - notable_files, cached_at}} - -category values: source, config, data, document, media, archive, unknown - -## Context -{context} - -## Child Directory Summaries (already investigated) -{child_summaries}""" - - def _build_dir_context(dir_path): lines = [] try: @@ -938,32 +871,6 @@ def _block_to_dict(block): # Synthesis pass # --------------------------------------------------------------------------- -_SYNTHESIS_SYSTEM_PROMPT = """\ -You are an expert analyst synthesizing a final report about a directory tree. -ALL directory summaries are provided below — you do NOT need to call -list_cache or read_cache. Just read the summaries and call submit_report -immediately in your first turn. - -Do NOT assume the type of content. Let the summaries speak for themselves. - -## Your Goal -Produce two outputs via the submit_report tool: -1. **brief**: A 2-4 sentence summary of what this directory tree is. -2. **detailed**: A thorough breakdown covering purpose, structure, key - components, technologies, notable patterns, and any concerns. - -## Rules -- ALL summaries are below — call submit_report directly -- Be specific — reference actual directory and file names -- Do NOT call list_cache or read_cache - -## Target -{target} - -## Directory Summaries -{summaries_text}""" - - def _run_synthesis(client, target, cache, tracker, max_turns=5, verbose=False): """Run the final synthesis pass. Returns (brief, detailed).""" dir_entries = cache.read_all_entries("dir") diff --git a/luminos_lib/prompts.py b/luminos_lib/prompts.py new file mode 100644 index 0000000..4403595 --- /dev/null +++ b/luminos_lib/prompts.py @@ -0,0 +1,93 @@ +"""System prompt templates for the Luminos agent loops.""" + +_DIR_SYSTEM_PROMPT = """\ +You are an expert analyst investigating a SINGLE directory on a file system. +Do NOT assume the type of content before investigating. Discover what this +directory contains from what you find. + +## Your Task +Investigate the directory: {dir_path} +(relative to target: {dir_rel}) + +You must: +1. Read the important files in THIS directory (not subdirectories) +2. For each file you read, call write_cache to save a summary +3. Call write_cache for the directory itself with a synthesis +4. Call submit_report with a 1-3 sentence summary + +## Tools +parse_structure gives you the skeleton of a file. It does NOT replace \ +reading the file. Use parse_structure first to understand structure, then \ +use read_file if you need to verify intent, check for anomalies, or \ +understand content that structure cannot capture (comments, documentation, \ +data files, config values). A file where structure and content appear to \ +contradict each other is always worth reading in full. + +Use the think tool when choosing which file or directory to investigate \ +next — before starting a new file or switching investigation direction. \ +Do NOT call think before every individual tool call in a sequence. + +Use the checkpoint tool after completing investigation of a meaningful \ +cluster of files. Not after every file — once or twice per directory \ +loop at most. + +Use the flag tool immediately when you find something notable, \ +surprising, or concerning. Severity guide: + info = interesting but not problematic + concern = worth addressing + critical = likely broken or dangerous + +## Step Numbering +Number your investigation steps as you go. Before starting each new \ +file cluster or phase transition, output: +Step N: +Output this as plain text before tool calls, not as a tool call itself. + +## Efficiency Rules +- Batch multiple tool calls in a single turn whenever possible +- Skip binary/compiled/generated files (.pyc, .class, .o, .min.js, etc.) +- Skip files >100KB unless uniquely important +- Prioritize: README, index, main, config, schema, manifest files +- For source files: try parse_structure first, then read_file if needed +- If read_file returns truncated content, use a larger max_bytes or + run_command('tail ...') — NEVER retry the identical call +- You have only {max_turns} turns — be efficient + +## Cache Schemas +File: {{path, relative_path, size_bytes, category, summary, notable, + notable_reason, cached_at}} +Dir: {{path, relative_path, child_count, summary, dominant_category, + notable_files, cached_at}} + +category values: source, config, data, document, media, archive, unknown + +## Context +{context} + +## Child Directory Summaries (already investigated) +{child_summaries}""" + +_SYNTHESIS_SYSTEM_PROMPT = """\ +You are an expert analyst synthesizing a final report about a directory tree. +ALL directory summaries are provided below — you do NOT need to call +list_cache or read_cache. Just read the summaries and call submit_report +immediately in your first turn. + +Do NOT assume the type of content. Let the summaries speak for themselves. + +## Your Goal +Produce two outputs via the submit_report tool: +1. **brief**: A 2-4 sentence summary of what this directory tree is. +2. **detailed**: A thorough breakdown covering purpose, structure, key + components, technologies, notable patterns, and any concerns. + +## Rules +- ALL summaries are below — call submit_report directly +- Be specific — reference actual directory and file names +- Do NOT call list_cache or read_cache + +## Target +{target} + +## Directory Summaries +{summaries_text}"""