<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jason Stefanou</title>
    <description>The latest articles on DEV Community by Jason Stefanou (@jason_stefanou_94e957bd7a).</description>
    <link>https://dev.to/jason_stefanou_94e957bd7a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4249415%2Fdf8bf4e2-bb1f-41bb-a35f-678366d4667b.png</url>
      <title>DEV Community: Jason Stefanou</title>
      <link>https://dev.to/jason_stefanou_94e957bd7a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jason_stefanou_94e957bd7a"/>
    <language>en</language>
    <item>
      <title>How I built an AI terminal companion in Rust, why I deleted the PTY, and what's next</title>
      <dc:creator>Jason Stefanou</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:31:09 +0000</pubDate>
      <link>https://dev.to/jason_stefanou_94e957bd7a/how-i-built-an-ai-terminal-companion-in-rust-why-i-deleted-the-pty-and-whats-next-373f</link>
      <guid>https://dev.to/jason_stefanou_94e957bd7a/how-i-built-an-ai-terminal-companion-in-rust-why-i-deleted-the-pty-and-whats-next-373f</guid>
      <description>&lt;p&gt;A few months ago, I started building &lt;strong&gt;smart-terminal&lt;/strong&gt;. Initially, it was just meant to be a modest portfolio project—a way to build something cool with Rust and explore how LLMs could fit into a developer's daily workflow.&lt;/p&gt;

&lt;p&gt;Along the way, it became much more than that. It became my playground for learning AI agentic concepts from first principles (ReAct loops, action spaces, tool execution engines, and multi-turn planning). More importantly, it turned into a tool I actually use in my own terminal every day. It is not a crazy, over-engineered solution, but it works, it is robust, and it was shaped by months of my own iterations and real daily use.&lt;/p&gt;

&lt;p&gt;Now that I'm about to step away from active development on it, I wanted to document how it evolved, the architectural dead-ends I hit, and why anyone interested is welcome to pick it up or contribute.&lt;/p&gt;




&lt;h2&gt;
  
  
  The initial mistake: Trying to wrap the terminal (PTY)
&lt;/h2&gt;

&lt;p&gt;When I started in January, my first instinct was to build a full terminal wrapper. &lt;/p&gt;

&lt;p&gt;The idea on paper was:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Spawn a subshell (&lt;code&gt;bash&lt;/code&gt;) using &lt;code&gt;portable-pty&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Intercept raw keyboard input with &lt;code&gt;crossterm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Read raw stdout bytes from the PTY and manage buffer state internally (&lt;code&gt;PipeState&lt;/code&gt; vs &lt;code&gt;CmdlineState&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Hack around command boundaries by injecting environment variables (&lt;code&gt;PROMPT_COMMAND='echo __AGENT_DONE__:$PWD'&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It didn't take long to realize this was the wrong approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handling raw ANSI escape codes, terminal resizing, cursor coordinates, and key events is a massive, brittle maintenance burden.&lt;/li&gt;
&lt;li&gt;Worse, wrapping a terminal breaks the developer's environment—custom shell prompts, aliases, keybindings, and shell plugins broke or suffered from input latency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reinventing terminal emulation just to offer command completions was not worth it.&lt;/p&gt;




&lt;h2&gt;
  
  
  The pivot: Deleting the emulator and hooking into Zsh
&lt;/h2&gt;

&lt;p&gt;In late February, I deleted roughly 1,500 lines of emulator and PTY code in one commit (&lt;code&gt;5c240b0&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Instead of wrapping the shell, I decoupled the tool into two clean pieces:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A standalone Rust CLI&lt;/strong&gt;: It takes shell context, talks to LLM providers, and outputs recommendations over a lightweight stdout protocol.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A Zsh integration script (&lt;code&gt;smart-terminal.zsh&lt;/code&gt;)&lt;/strong&gt;: It hooks directly into the Zsh Line Editor (ZLE). Pressing &lt;code&gt;Ctrl+G&lt;/code&gt; calls the binary, renders the suggestion as inline ghost text, and pressing &lt;code&gt;Ctrl+F&lt;/code&gt; drops only the command into the editable buffer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This meant my terminal, prompt, and shell configuration remained 100% native, while suggestions stayed fast and unobtrusive.&lt;/p&gt;




&lt;h2&gt;
  
  
  Learning agentic concepts through daily use
&lt;/h2&gt;

&lt;p&gt;Once the interface was out of the way, I could focus on the actual intelligence. Because I was using the tool daily, every edge case or annoyance turned into an architectural improvement:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;next-cmd&lt;/code&gt; &amp;amp; Reversibility&lt;/strong&gt;: Suggestions based on recent history, current folder, and partial inputs were useful, but running unknown commands blindly is stressful. I added a fast reversibility heuristic that flags predictions from safe/read-only (&lt;code&gt;ls&lt;/code&gt;) to irreversible (&lt;code&gt;rm -rf&lt;/code&gt;), giving a clear visual safety cue before accepting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;investigate&lt;/code&gt;&lt;/strong&gt;: I wanted to ask questions about unfamiliar repos without leaving the terminal. Rather than just feeding context to an LLM, I built a ReAct agent loop. A planner inspects the directory structure and emits a plan, and an executor carries it out using safe shell tools (&lt;code&gt;read_file&lt;/code&gt;, &lt;code&gt;read_dir&lt;/code&gt;, &lt;code&gt;bash&lt;/code&gt;, &lt;code&gt;docker&lt;/code&gt;, &lt;code&gt;git_diff&lt;/code&gt;), keeping a durable scratchpad as it works.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;memory&lt;/code&gt;&lt;/strong&gt;: Project-scoped persistence that remembers past commands and context so suggestions sharpen over time without mixing up different workspaces.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provider layer&lt;/strong&gt;: Clean traits abstracting LLM calls across Groq (for near-instant command predictions), Google Gemini, and OpenRouter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The codebase is split into modular layers (&lt;code&gt;src/cli&lt;/code&gt;, &lt;code&gt;src/core&lt;/code&gt;, &lt;code&gt;src/agent&lt;/code&gt;, &lt;code&gt;src/persistence&lt;/code&gt;, &lt;code&gt;src/providers&lt;/code&gt;, &lt;code&gt;src/tools&lt;/code&gt;) and backed by integration tests.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why I'm opening it up
&lt;/h2&gt;

&lt;p&gt;I'm an undergraduate student at the University of Athens, and I've reached a point where I need to move on to other priorities and stop active work on this repo.&lt;/p&gt;

&lt;p&gt;What started as a small portfolio project turned into a dependable tool I use daily and a deep dive into agentic systems. Rather than letting it sit idle, I'd like to put it out there for anyone interested in hacking on it.&lt;/p&gt;

&lt;p&gt;The architecture is solid and there are a few obvious areas where contributors could take it further:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Other shell integrations&lt;/strong&gt;: The hook currently only targets Zsh. Adding Bash, Fish, or Nushell hooks would be a great addition.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local LLM support&lt;/strong&gt;: Adding an offline provider like Ollama or &lt;code&gt;llama.cpp&lt;/code&gt; so users don't need API keys.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New investigation tools&lt;/strong&gt;: Adding tools like ripgrep or test runner output parsers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintenance&lt;/strong&gt;: If someone wants to triage issues or help maintain the project, I'm happy to grant access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're interested in checking out the code or contributing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repository: &lt;a href="https://github.com/sdi2200246/smart-terminal" rel="noopener noreferrer"&gt;github.com/sdi2200246/smart-terminal&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Contributing guidelines: &lt;a href="https://github.com/sdi2200246/smart-terminal/blob/main/CONTRIBUTING.md" rel="noopener noreferrer"&gt;CONTRIBUTING.md&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PRs, questions, and feedback are all welcome.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>opensource</category>
      <category>ai</category>
      <category>terminal</category>
    </item>
  </channel>
</rss>
