Package com.tnsai.prompt
Class ProjectContextLoader
java.lang.Object
com.tnsai.prompt.ProjectContextLoader
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
- Start at the given directory.
- At each level, probe
CANDIDATE_FILENAMESin order. First match wins — returned as soon as it's found. - Stop ascending at a
.gitboundary (repo root) or the filesystem root, whichever comes first.
Size cap
Found files aboveDEFAULT_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 throughPromptInjectionDetector (in
TnsAI.Quality) first. This class does not scan — it only reads.- Since:
- 0.3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of a successful load. -
Field Summary
FieldsModifier and TypeFieldDescriptionFilenames checked at each level, in priority order.static final intSafety cap to avoid pulling huge files into the prompt. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionWalks up fromstartDirlooking for a context file.Convenience: load from the JVM's working directory.
-
Field Details
-
CANDIDATE_FILENAMES
Filenames checked at each level, in priority order. -
DEFAULT_MAX_BYTES
public static final int DEFAULT_MAX_BYTESSafety cap to avoid pulling huge files into the prompt.- See Also:
-
-
Constructor Details
-
ProjectContextLoader
public ProjectContextLoader() -
ProjectContextLoader
public ProjectContextLoader(int maxBytes)
-
-
Method Details
-
load
Walks up fromstartDirlooking for a context file. Returns the first match's content, orOptional.empty()if none is found before the walk hits.gitor the filesystem root.- Parameters:
startDir- directory to start the walk from (normally agent's cwd)- Returns:
- the project context content, or empty
-
loadFromCwd
Convenience: load from the JVM's working directory.
-