Class NbTerminal

java.lang.Object
uno.anahata.asi.agi.tool.ToolContext
uno.anahata.asi.agi.tool.AnahataToolkit
uno.anahata.asi.nb.tools.terminal.NbTerminal
All Implemented Interfaces:
uno.anahata.asi.agi.context.ContextProvider, uno.anahata.asi.agi.event.PropertyChangeSource, uno.anahata.asi.persistence.Rebindable

public class NbTerminal extends uno.anahata.asi.agi.tool.AnahataToolkit
A NetBeans-integrated toolkit for managing, tracking, and typing into native terminal tabs.

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, propertyChangeSupport

    Fields inherited from class uno.anahata.asi.agi.tool.ToolContext

    toolkit
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new NbTerminal toolkit instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    closeTerminal(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.
    findTabById(long id)
    Finds a registered TerminalTab context provider by its transient identity hashcode.
    private void
    findTermsRecursive(Component comp, List<org.netbeans.lib.terminalemulator.Term> terms)
    Recursively traverses a Swing container to identify any instances of Term.
    private String
    getTabTitle(org.netbeans.lib.terminalemulator.Term term)
    Traverses the Swing hierarchy upwards from a Term component to retrieve its user-visible tab title.
    void
    openLocalTerminal(String title, String workingDirectory)
    Opens an interactive local terminal tab in the IDE.
    void
    populateMessage(uno.anahata.asi.agi.message.RagMessage ragMessage)
    void
    private void
    Synchronizes 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, setProviding

    Methods 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, setToolkit

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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:
      initialize in class uno.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:
      postActivate in class uno.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

      public String openLocalTerminal(String title, String workingDirectory) throws Exception
      Opens an interactive local terminal tab in the IDE.
      Parameters:
      title - The title for the terminal tab.
      workingDirectory - The initial working directory.
      Returns:
      A confirmation message.
      Throws:
      Exception
    • typeCommand

      public String typeCommand(long terminalTabId, String command) throws Exception
      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

      public String closeTerminal(long terminalTabId) throws Exception
      Closes a specific terminal tab.
      Parameters:
      terminalTabId - The unique ID of the target terminal tab.
      Returns:
      A status message.
      Throws:
      Exception
    • 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

      private Optional<TerminalTab> findTabById(long id)
      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

      private List<org.netbeans.lib.terminalemulator.Term> 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

      private void findTermsRecursive(Component comp, List<org.netbeans.lib.terminalemulator.Term> terms)
      Recursively traverses a Swing container to identify any instances of Term.
      Parameters:
      comp - The parent component.
      terms - The output list of found Term components.
    • getTabTitle

      private String getTabTitle(org.netbeans.lib.terminalemulator.Term term)
      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.