Class Projects
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
This toolkit acts as a bridge between the model-agnostic Anahata core framework and the IntelliJ Platform, providing real-time visibility into open projects, directory structures, and project lifecycle management operations.
- Author:
- anahata
-
Field Summary
Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportFields inherited from class ToolContext
toolkit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendDirectoryStructure(Path dir, StringBuilder sb, String indent) Recursively appends a clean, machine-readable directory structure to the builder.autoConfigureProjectSdk(String projectPath) Automatically discovers the best available JDK on the system and assigns it as the Project SDK.buildProject(String projectPath, boolean rebuild) Compiles a project and returns a synchronous build result (error/warning counts).voidcloseProjects(List<String> projectPaths) Closes specific open projects in the IDE.private com.intellij.openapi.projectRoots.SdkensureProjectSdkConfigured(com.intellij.openapi.project.Project project) Ensures that the specified project has a valid Project SDK attached, auto-detecting and registering one if needed.private com.intellij.openapi.project.ProjectfindProjectByPath(String projectPath) Resolves an openProjectby its canonical base path.Gets the list of immediate child context providers.Returns a list of absolute paths of all currently open IntelliJ projects.getProjectProvider(String projectPath) Returns a project context provider by path.getProjectSdk(String projectPath) Returns information about the currently configured Project SDK for an open project.Gets a list of system instruction strings provided by this context provider.Lists all JDKs registered in IntelliJ's ProjectJdkTable as well as suggested system JDK paths.openProject(String projectPath) Opens a project directory programmatically in the IntelliJ IDE.voidpopulateMessage(RagMessage ragMessage) Populates the givenRagMessagewith dynamic, just-in-time context parts.Persists all unsaved editor documents across the IDE to disk.voidsetProjectProviderEnabled(String projectPath, boolean enabled) Toggles the context provider state for a specific project.setProjectSdk(String projectPath, String sdkNameOrHomePath) Configures the project SDK for an open project.private voidSynchronizes project context providers with currently open IDE projects.Methods inherited from class AnahataToolkit
getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, initialize, isEffectivelyProviding, postActivate, rebindMethods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, addAttachment, error, error, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsyncMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContextProvider
getAgi, getContextPosition, getFlattenedHierarchy, getFullyQualifiedId, getHeader, getIconId, getInstructionsTokenCount, getRagTokenCount, isProviding, setParentProvider, setProviding
-
Constructor Details
-
Projects
public Projects()Default constructor for the IntelliJ Projects toolkit.
-
-
Method Details
-
getChildrenProviders
Gets the list of immediate child context providers.Returns the list of active project child providers, implementing a dynamic synchronization pattern that captures newly opened or closed projects in real-time.
- Specified by:
getChildrenProvidersin interfaceContextProvider- Overrides:
getChildrenProvidersin classAnahataToolkit- Returns:
- A list of context providers.
-
syncProjects
private void syncProjects()Synchronizes project context providers with currently open IDE projects. -
getProjectProvider
Returns a project context provider by path.- Parameters:
projectPath- The absolute path of the project.- Returns:
- An Optional containing the provider.
-
getSystemInstructions
Gets a list of system instruction strings provided by this context provider. These are typically prepended to the conversation as high-level guidance.Returns the master instruction guide on how to resolve files, folders, and structures within the active IntelliJ IDE workspace.
- Returns:
- A list of system instruction strings.
- Throws:
Exception- if an error occurs during instruction generation.
-
populateMessage
Populates the givenRagMessagewith dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG).Scans all open projects in the IntelliJ Platform, extracts their base paths, and appends their physical file-system trees to the RAG message to provide full workspace observability.
- Parameters:
ragMessage- The message to be augmented with context.
-
appendDirectoryStructure
Recursively appends a clean, machine-readable directory structure to the builder.Implements smart filtering to skip heavy target, out, and hidden folders, and utilizes a depth control threshold to prevent context-window token blowup.
- Parameters:
dir- The active directory path.sb- The string builder workspace.indent- The prefix indent spacer.- Throws:
IOException- if directory reading fails.
-
getOpenProjects
-
closeProjects
-
openProject
Opens a project directory programmatically in the IntelliJ IDE.Performs a thread-safe operation on the Event Dispatch Thread (EDT) and uses progressive API resolution with reflection to guarantee compatibility across different IntelliJ platform versions.
- Parameters:
projectPath- The absolute path of the project directory to open.- Returns:
- A status message describing the outcome of the open operation.
-
setProjectProviderEnabled
Toggles the context provider state for a specific project.Locates the appropriate provider by its canonical path and updates its activation state.
- Parameters:
projectPath- The absolute path of the project.enabled- Whether to enable the context provider.
-
buildProject
Compiles a project and returns a synchronous build result (error/warning counts).Mirrors the NetBeans
Projects.invokeActionbuild/rebuild capability using IntelliJ'sCompilerManager. Compilation is triggered on the EDT and this method blocks on a latch off the EDT until the asynchronous build completes, so the model receives the actual outcome rather than a fire-and-forget acknowledgement.- Parameters:
projectPath- the absolute path of the open project to build.rebuild-trueto force a full rebuild;falsefor an incremental make.- Returns:
- a human-readable build summary.
- Throws:
AgiToolException- if the project is not open or the build is interrupted.
-
saveAllDocuments
Persists all unsaved editor documents across the IDE to disk.Useful before a build or an external tool run so on-disk state matches the editor.
- Returns:
- a confirmation message.
-
findProjectByPath
Resolves an openProjectby its canonical base path.- Parameters:
projectPath- the absolute base path.- Returns:
- the matching open project, or
nullif none is open at that path.
-
getProjectSdk
Returns information about the currently configured Project SDK for an open project.- Parameters:
projectPath- The absolute path of the open project.- Returns:
- A formatted summary of the configured SDK, or an unconfigured warning.
- Throws:
AgiToolException- if the project is not open.
-
listAvailableSdks
Lists all JDKs registered in IntelliJ's ProjectJdkTable as well as suggested system JDK paths.- Returns:
- A formatted list of available SDKs and detected system JDK paths.
-
setProjectSdk
Configures the project SDK for an open project.If an existing registered SDK name is supplied (e.g.
"21"or"corretto-25"), it is attached directly to the project. If a directory path to a JDK home is supplied, the JDK is first registered inProjectJdkTableand then attached to the project.- Parameters:
projectPath- The absolute path of the open project.sdkNameOrHomePath- The registered SDK name or absolute path to a JDK home directory.- Returns:
- A confirmation message describing the configured SDK.
- Throws:
AgiToolException- if the project is not open or the SDK could not be configured.
-
autoConfigureProjectSdk
Automatically discovers the best available JDK on the system and assigns it as the Project SDK.- Parameters:
projectPath- The absolute path of the open project.- Returns:
- A status message describing the configured SDK.
- Throws:
AgiToolException- if the project is not open or no JDK can be found.
-
ensureProjectSdkConfigured
private com.intellij.openapi.projectRoots.Sdk ensureProjectSdkConfigured(com.intellij.openapi.project.Project project) Ensures that the specified project has a valid Project SDK attached, auto-detecting and registering one if needed.- Parameters:
project- The open project to inspect.- Returns:
- The active or newly configured Sdk, or
nullif no JDK could be found.
-

