Class ProjectContextLoader

java.lang.Object
com.tnsai.prompt.ProjectContextLoader

public final class ProjectContextLoader extends Object
Walks up from a starting directory looking for a project context file (.tnsai.md, TNSAI.md, or CLAUDE.md) and returns its contents for system-prompt injection.

Mirrors the Claude Code / Hermes pattern that every TnsAI module already dogfoods — each repo has its own CLAUDE.md, but the framework itself never honoured the convention at runtime. Agents started every session with zero project-specific context; users re-pasted coding conventions, domain knowledge, and persona each time.

Walk semantics

  1. Start at the given directory.
  2. At each level, probe CANDIDATE_FILENAMES in order. First match wins — returned as soon as it's found.
  3. Stop ascending at a .git boundary (repo root) or the filesystem root, whichever comes first.

Size cap

Found files above DEFAULT_MAX_BYTES (64 KiB) are rejected with a warning log. This prevents accidental injection of an entire monorepo-wide doc that the user merged into the context filename by mistake.

Security

Returned content is raw user-controlled text. Callers that inject it into LLM prompts should run it through PromptInjectionDetector (in TnsAI.Quality) first. This class does not scan — it only reads.
Since:
0.3.0
  • Field Details

    • CANDIDATE_FILENAMES

      public static final List<String> CANDIDATE_FILENAMES
      Filenames checked at each level, in priority order.
    • DEFAULT_MAX_BYTES

      public static final int DEFAULT_MAX_BYTES
      Safety cap to avoid pulling huge files into the prompt.
      See Also:
  • Constructor Details

    • ProjectContextLoader

      public ProjectContextLoader()
    • ProjectContextLoader

      public ProjectContextLoader(int maxBytes)
  • Method Details