Class NbTerminal
- All Implemented Interfaces:
uno.anahata.asi.agi.context.ContextProvider, uno.anahata.asi.agi.event.PropertyChangeSource, uno.anahata.asi.persistence.Rebindable
This toolkit acts as a global ContextProvider that maintains a dynamic list
of active TerminalTabs. It manages their persistent viewport settings
and facilitates seamless interaction between the AI and the IDE's terminal system.
- Author:
- anahata
-
Field Summary
Fields inherited from class uno.anahata.asi.agi.tool.AnahataToolkit
childrenProviders, propertyChangeSupportFields inherited from class uno.anahata.asi.agi.tool.ToolContext
toolkit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncloseTerminal(long terminalTabId) Closes a specific terminal tab.private List<org.netbeans.lib.terminalemulator.Term> Searches the TopComponent window tree on the Event Dispatch Thread and returns all active Term instances.private Optional<TerminalTab> findTabById(long id) Finds a registered TerminalTab context provider by its transient identity hashcode.private voidfindTermsRecursive(Component comp, List<org.netbeans.lib.terminalemulator.Term> terms) Recursively traverses a Swing container to identify any instances ofTerm.private StringgetTabTitle(org.netbeans.lib.terminalemulator.Term term) Traverses the Swing hierarchy upwards from a Term component to retrieve its user-visible tab title.voidopenLocalTerminal(String title, String workingDirectory) Opens an interactive local terminal tab in the IDE.voidpopulateMessage(uno.anahata.asi.agi.message.RagMessage ragMessage) voidprivate voidSynchronizes terminal tabs with active Swing Term components in the window system.typeCommand(long terminalTabId, String command) Types a command sequence into a specific terminal tab and presses Enter.updateTerminalViewport(long terminalTabId, uno.anahata.asi.agi.resource.view.TextViewportSettings settings) Programmatically updates the viewport settings (tail, grep, line numbering) of a specific terminal tab.Methods inherited from class uno.anahata.asi.agi.tool.AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, isEffectivelyProviding, isProviding, rebind, setProvidingMethods inherited from class uno.anahata.asi.agi.tool.ToolContext
addAttachment, addAttachment, addAttachment, error, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsync, setToolkitMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface uno.anahata.asi.agi.context.ContextProvider
getAgi, getContextPosition, getFlattenedHierarchy, getFullyQualifiedId, getHeader, getIconId, getInstructionsTokenCount, getRagTokenCount, getSystemInstructions, setParentProvider
-
Constructor Details
-
NbTerminal
public NbTerminal()Constructs a new NbTerminal toolkit instance. The child terminal tabs are lazily and dynamically populated during the turn's sync pass.
-
-
Method Details
-
initialize
public void initialize()Performs the initial synchronization pass to register any pre-existing terminal tabs in the workspace.
- Overrides:
initializein classuno.anahata.asi.agi.tool.AnahataToolkit
-
postActivate
public void postActivate()Re-synchronizes active terminal tabs with their newly instantiated Swing Term components upon session activation, restoring their transient memory references seamlessly.
- Overrides:
postActivatein classuno.anahata.asi.agi.tool.AnahataToolkit
-
populateMessage
public void populateMessage(uno.anahata.asi.agi.message.RagMessage ragMessage) Performs a real-time synchronization scan of the terminal window layout. Appends a beautifully formatted Markdown table of all open terminal tabs, their unique IDs, display titles, and providing states (active or muted) directly into the JIT-compiled RAG message.
-
openLocalTerminal
-
typeCommand
Types a command sequence into a specific terminal tab and presses Enter.- Parameters:
terminalTabId- The unique ID of the target terminal tab.command- The command sequence to execute.- Returns:
- A status message.
- Throws:
Exception
-
updateTerminalViewport
public String updateTerminalViewport(long terminalTabId, uno.anahata.asi.agi.resource.view.TextViewportSettings settings) Programmatically updates the viewport settings (tail, grep, line numbering) of a specific terminal tab.- Parameters:
terminalTabId- The unique ID of the target terminal tab.settings- The new viewport settings.- Returns:
- A status message.
-
closeTerminal
-
syncTerminalTabs
private void syncTerminalTabs()Synchronizes terminal tabs with active Swing Term components in the window system. Matches JComponents with saved provider configurations using persistent client property UUIDs. -
findTabById
Finds a registered TerminalTab context provider by its transient identity hashcode.- Parameters:
id- The identity hashcode of the Term component.- Returns:
- An Optional containing the TerminalTab if found.
-
findActiveTerms
Searches the TopComponent window tree on the Event Dispatch Thread and returns all active Term instances. Uses runInEDTAndWait because we must block the background sync loop until the Swing crawl completes.- Returns:
- A list of active Term components.
-
findTermsRecursive
-
getTabTitle
Traverses the Swing hierarchy upwards from a Term component to retrieve its user-visible tab title.- Parameters:
term- The Term component.- Returns:
- The display name of the parent tab panel.
-

