harbor run -t openthoughts/tasktrove-exp-rpt-multifile-multifile-4821harbor download openthoughts/tasktrove-exp-rpt-multifile-multifile-4821# Unified Multi-Module Project Task Instruction
Project overview
- Build a cohesive Python-based project distributed across three modules under /app/:
- core.py: foundational utilities (inspired by Task 1 concepts)
- processor.py: data processing logic that uses core.py (inspired by Task 2 concepts)
- integration.py: integration layer that uses both core.py and processor.py (inspired by Task 3 concepts)
- Each module should be self-contained, yet designed to collaborate as a coherent system.
- Target code size: roughly 30-80 lines per module to keep the implementation compact and readable.
- Deliverables are source files in /app/ and a demonstration of their interoperability via the Example Usage section.
Detailed specification for each module
1) /app/core.py — foundational utilities
Purpose
- Provide portable, reusable utilities that can be consumed by both processor.py and integration.py.
- Emphasize small, well-defined functions with clear error handling.
Required functionality
- Directory and file helpers
- ensure_dir(path): create the directory and parents if missing.
- is_executable(path): return True if path exists and is executable.
- Go-related (Task 1 inspiration; kept generic)
- is_go_installed(): return True if the Go toolchain is available in PATH.
- compile_go(source_path, output_path): if Go is installed, run: go build -o output_path source_path; raise a clear exception on failure.
- run_executable(executable_path, log_path): run the executable, redirect stdout and stderr to log_path (overwrite each run); return exit code.
- build_and_run_go_pipeline(source_path, binary_path, log_path): a convenience wrapper that ensures directories exist, compiles, runs, and returns the exit code.
- File utilities
- find_home_files(depths=[1,2], include_hidden=False): discover regular files located in the current user’s home directory at the specified depth(s) (depth 1 = immediately under HOME; depth 2 = one subdirectory deep). Optionally exclude hidden files.
- random_name(length=16): generate a cryptographically reasonable random alphanumeric name.
- copy_file_preserve(src, dst): copy a file while preserving metadata as available (e.g., permissions, timestamps).
Constraints
- Keep dependencies minimal (standard library only).
- Functions should raise informative exceptions on failure rather than returning opaque codes when appropriate.
- Provide clear, concise docstrings or comments to explain intent.
2) /app/processor.py — data processing that uses core.py
Purpose
- Implement a small data-processing capability that can analyze an input text (simulated “explain plan”) and return structured results.
- Demonstrate interaction with core.py by importing and using at least one function from core.py.
Required functionality
- Import from core
- from core import random_name
- Core processing functionality
- analyze_explain(plan_text): Accept a PostgreSQL-like explain plan as a string and:
- Determine the scan type (Index Scan, Bitmap Index Scan, or Seq Scan) by inspecting the top-level plan line.
- Return a structured dict with keys:
- scan_type: "Index Scan", "Bitmap Index Scan", "Seq Scan" or "Unknown"
- optimizations: a list of short, actionable optimization recommendations tailored to the detected scan type.
- annotate_explanation(plan_text): Use random_name to attach a small, unique tag to the plan text and return a tuple (tagged_text, analysis) or similar, showcasing usage of core functionality.
- Optional helper
- A tiny wrapper that demonstrates using analyze_explain in combination with annotate_explanation.
Constraints
- Keep the module lean (roughly 30-80 lines).
- Ensure analyze_explain is robust to common explain formats with a simple heuristic (top-level line detection).
- Demonstrate usage of at least one core function (random_name) to satisfy the dependency requirement.
3) /app/integration.py — integration layer (uses both core.py and processor.py)
Purpose
- Provide an orchestration layer that ties together core utilities and processor logic to implement a small, end-to-end workflow.
- Demonstrate cross-module interaction: integrate function(s) should import from both core and processor and utilize them together.
Required functionality
- Import dependencies
- from core import random_name, find_home_files, copy_file_preserve
- from processor import analyze_explain
- Core workflow
- copy_random_home_file_to_tmp(depths=[1,2], include_hidden=False):
- Use find_home_files to gather candidate files under HOME at depth 1 or 2.
- If no candidates, exit non-zero with a helpful message.
- Randomly select a candidate file (using Python’s random module).
- Generate a 16-character random name via random_name.
- Copy the selected file to /tmp with the generated name (clone contents exactly; metadata preservation is optional but encouraged via copy_file_preserve).
- Print the destination path and the generated 16-character name for verification.
- Return (dest_path, name) for programmatic use.
- Processor integration
- analyze_example_plan(plan_text): Convenience wrapper that calls analyze_explain(plan_text) and returns the analysis result, demonstrating interoperability.
Constraints
- All copy operations should preserve contents (the instruction notes this is sufficient; you may or may not preserve the original extension).
- Handle edge cases gracefully:
- No candidate files found in HOME at the requested depths → exit with non-zero status and a helpful message.
- Insufficient permissions → fail gracefully with a message.
- Use only standard POSIX tools if demonstrated on the shell side; the Python module itself should rely on Python and the standard library.
Import dependencies between modules
- core.py is the foundational utility layer.
- processor.py imports and uses core.py (e.g., random_name) to fulfill its dependency requirement.
- integration.py imports from both core.py and processor.py and uses functions from both to demonstrate a cohesive workflow.
- The modules are designed to be invoked in a Python environment where /app is added to the Python path (e.g., sys.path.insert(0, "/app")) so they can be imported as core, processor, and integration or via explicit path manipulation in a caller script.
Example usage showing how the modules work together
- Setup (conceptual, to run in your environment):
- Ensure /app exists and contains:
- /app/core.py
- /app/processor.py
- /app/integration.py
- From a Python shell or a small driver script:
- import sys
sys.path.insert(0, "/app")
import core, processor, integration
- End-to-end (Task 1-inspired flow using core)
- if not core.is_go_installed(): print("Go not installed; skipping compilation step.")
- try:
binary = "/app/hello_bin"
log = "/app/output.txt"
core.compile_go("/app/src/hello.go", binary)
rc = core.run_executable(binary, log)
print("Go run exit code:", rc)
except Exception as e:
print("Go pipeline failed:", e)
- Processor usage (Task 2-inspired)
- plan = "Seq Scan on public.mytable (cost=...)" # sample text
- analysis = processor.analyze_explain(plan)
- print(analysis["scan_type"])
- for opt in analysis["optimizations"]: print("-", opt)
- Integration usage (Task 3-inspired)
- dest_path, name = integration.copy_random_home_file_to_tmp()
- print("Copied to:", dest_path)
- print("Generated name:", name)
- option: integration.analyze_example_plan(plan) to demonstrate downstream usage of both modules
Deliverables
- Three Python source files under /app/:
- /app/core.py
- /app/processor.py
- /app/integration.py
- Each file should be implemented with the behaviors described above and stay within roughly 30-80 lines.
- The project should be runnable in a minimal environment with Python standard library only.
Notes and constraints
- The agent is expected to implement these files directly at /app/.
- The design favors portability and simplicity, avoiding external dependencies beyond Python’s standard library.
- The example usage section is for illustration; adapt paths and environment as needed for your setup.