Skip to content

Commit ecd079e

Browse files
committed
feat: TSG v1.0.0 — Terminal State Guard
0 parents  commit ecd079e

File tree

17 files changed

+1279
-0
lines changed

17 files changed

+1279
-0
lines changed

.github/workflows/release.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Release to NuGet
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
workflow_dispatch:
7+
8+
env:
9+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
10+
11+
jobs:
12+
build-and-publish:
13+
runs-on: windows-latest
14+
permissions:
15+
contents: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup .NET 10
21+
uses: actions/setup-dotnet@v4
22+
with:
23+
dotnet-version: '10.0.x'
24+
25+
- name: Extract version
26+
id: ver
27+
shell: pwsh
28+
run: |
29+
$v = "${{ github.ref_name }}" -replace '^v', ''
30+
if (-not $v) { $v = "1.0.0" }
31+
"VERSION=$v" >> $env:GITHUB_OUTPUT
32+
33+
- name: Build
34+
run: dotnet build src/TSG/TSG.csproj -c Release -p:Version=${{ steps.ver.outputs.VERSION }}
35+
36+
- name: Pack
37+
run: dotnet pack src/TSG/TSG.csproj -c Release -o artifacts -p:Version=${{ steps.ver.outputs.VERSION }}
38+
39+
- name: Push to NuGet
40+
run: dotnet nuget push artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
41+
42+
- name: GitHub Release
43+
uses: softprops/action-gh-release@v2
44+
if: startsWith(github.ref, 'refs/tags/')
45+
with:
46+
files: artifacts/*.nupkg
47+
generate_release_notes: true

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bin/
2+
obj/
3+
artifacts/
4+
*.nupkg
5+
*.user
6+
.vs/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 sbay-dev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<div align="center">
2+
3+
# ⚡ TSG — Terminal State Guard
4+
5+
### Cross-platform CLI for Copilot Performance Boosting, Safe Monitoring & Session Recovery
6+
7+
[![NuGet](https://img.shields.io/nuget/v/TerminalStateGuard?style=for-the-badge&logo=nuget&color=004880)](https://www.nuget.org/packages/TerminalStateGuard)
8+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](LICENSE)
9+
[![.NET 10](https://img.shields.io/badge/.NET-10.0-512BD4?style=for-the-badge&logo=dotnet)](https://dotnet.microsoft.com)
10+
[![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux-blue?style=for-the-badge)]()
11+
12+
**One command to install. Keyboard shortcuts ready. Zero config.**
13+
14+
[Installation](#-installation) · [Commands](#-commands) · [Monitor](#-safe-monitor) · [Recovery](#-session-recovery) · [Doctor](#-doctor)
15+
16+
---
17+
18+
</div>
19+
20+
## 🚀 Installation
21+
22+
```bash
23+
dotnet tool install -g TerminalStateGuard
24+
tsg install
25+
```
26+
27+
**Done.** Reopen your terminal — shortcuts and integration are active.
28+
29+
### What `tsg install` does:
30+
31+
| Platform | Action |
32+
|----------|--------|
33+
| **Windows** | Installs [Windows Terminal Fragment](https://learn.microsoft.com/en-us/windows/terminal/json-fragment-extensions) for native shortcut integration |
34+
| **Windows** | Configures PSReadLine keyboard shortcuts in PowerShell profile |
35+
| **Linux** | Adds shell aliases and keybindings to `.bashrc`/`.zshrc` |
36+
| **Both** | Deploys monitoring scripts to `~/.tsg/` |
37+
38+
## ⌨️ Commands
39+
40+
```bash
41+
tsg install # Setup scripts, shortcuts & terminal integration
42+
tsg boost # ⚡ Elevate Copilot process priority (Admin/sudo)
43+
tsg monitor # 📊 Safe live monitor with diagnostics
44+
tsg status # 📋 Quick health check
45+
tsg recover # 🔄 Recover terminal tabs + Copilot sessions
46+
tsg restore # 🔄 Revert all priority changes
47+
tsg doctor # 🩺 Diagnose environment issues
48+
tsg uninstall # 🗑️ Remove configuration
49+
```
50+
51+
### Keyboard Shortcuts
52+
53+
| Shortcut | Action |
54+
|----------|--------|
55+
| `Ctrl+Alt+B` | Boost |
56+
| `Ctrl+Alt+M` | Monitor |
57+
| `Ctrl+Alt+S` | Status |
58+
| `Ctrl+Alt+F` | Recover |
59+
| `Ctrl+Alt+R` | Restore |
60+
61+
## 📊 Safe Monitor
62+
63+
**100% read-only** — never modifies Copilot's internal files.
64+
65+
```
66+
⚡ TSG MONITOR 06:30:00 [🟢 BOOSTED] [4/4]
67+
══════════════════════════════════════════════════════
68+
PID 221120 | copilot | 180 MB | H: 234 | Δ 0.3s | 🟢 IDLE
69+
📂 MyProject — Implement auth system
70+
📄 Events: 2.1MB | Last: assistant.turn_end | ok
71+
PID 52300 | copilot-ls | 16 MB | H: 120 | Δ 0.0s | 🟢 IDLE
72+
🟣 Visual Studio
73+
══════════════════════════════════════════════════════
74+
TOTAL: 196 MB | CPU: 125.3s | Threads: 31
75+
```
76+
77+
### Diagnostic Indicators
78+
79+
| State | Meaning | Action |
80+
|-------|---------|--------|
81+
| 🟢 IDLE | Healthy, idle | None |
82+
| 🟡 ACTIVE | Processing | Wait |
83+
| 🔴 HIGH CPU | Heavy computation | Wait or close → resume |
84+
| 🔴 HANDLE LEAK | events.jsonl too large | Close tab → `copilot --resume` |
85+
| ❄️ STUCK | Turn never completed | Close tab → resume (auto-recovers) |
86+
87+
## 🔄 Session Recovery
88+
89+
```bash
90+
tsg recover
91+
```
92+
93+
Scans Windows Terminal state + Copilot sessions and reopens tabs with `copilot --resume`:
94+
95+
```
96+
🔄 Session Recovery
97+
✅ 8 tabs (5 copilot)
98+
99+
[1] 🤖 MyProject (Win 1)
100+
💬 Implement auth system
101+
[2] 📂 Documents (Win 1)
102+
[3] 🤖 WebApp (Win 2)
103+
💬 Fix DllNotFoundException
104+
```
105+
106+
## 🩺 Doctor
107+
108+
```bash
109+
tsg doctor
110+
```
111+
112+
Checks environment, finds stuck sessions, validates setup:
113+
114+
```
115+
🩺 TSG Doctor — Environment Check
116+
117+
✅ .NET 10.0.0
118+
✅ Shell: C:\Program Files\PowerShell\7\pwsh.exe
119+
✅ TSG dir: C:\Users\you\.tsg
120+
✅ Copilot sessions: 12
121+
⚠️ 1 session(s) > 20MB — may cause slowness
122+
✅ Windows Terminal Fragment installed
123+
✅ Terminal state: 2 windows, 8 tabs
124+
125+
🎉 All checks passed!
126+
```
127+
128+
## 🛡️ Safety
129+
130+
> **TSG never modifies Copilot's internal files.**
131+
132+
- ✅ All monitoring is **read-only** — only reads metadata
133+
- ✅ Never deletes, trims, or edits `events.jsonl`
134+
- ✅ Session recovery uses native `copilot --resume`
135+
- ✅ Diagnostics show root cause + safe manual recommendations
136+
137+
## ⚡ Architecture
138+
139+
```
140+
tsg (dotnet tool)
141+
├── Platform/
142+
│ ├── IPlatformHost.cs — Cross-platform abstraction
143+
│ ├── WindowsHost.cs — Windows Terminal Fragment + PSReadLine
144+
│ └── LinuxHost.cs — bash/zsh aliases + keybindings
145+
├── Scripts/
146+
│ ├── windows/*.ps1 — PowerShell monitoring scripts
147+
│ └── linux/*.sh — Bash monitoring scripts
148+
├── CommandRegistry.cs — Lambda-based command routing
149+
├── Installer.cs — Script deployment + profile config
150+
├── ScriptRunner.cs — Cross-platform script execution
151+
└── Diagnostics.cs — Environment health checks
152+
```
153+
154+
**Built with:** .NET 10 · C# 14 · Windows Terminal Fragments API
155+
156+
## 📦 Requirements
157+
158+
| Platform | Requirements |
159+
|----------|-------------|
160+
| **Windows** | Windows Terminal, PowerShell 7+, .NET 10 Runtime |
161+
| **Linux** | bash/zsh, .NET 10 Runtime |
162+
| **Both** | GitHub Copilot CLI (`npm i -g @github/copilot`) |
163+
164+
## 🗑️ Uninstall
165+
166+
```bash
167+
tsg uninstall
168+
dotnet tool uninstall -g TerminalStateGuard
169+
```
170+
171+
## 📄 License
172+
173+
[MIT](LICENSE) — Made with ⚡ by [sbay-dev](https://github.com/sbay-dev)

src/TSG/CommandRegistry.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
namespace TSG;
2+
3+
using TSG.Platform;
4+
5+
/// <summary>
6+
/// Registry of all CLI commands using C# 14 lambda delegates.
7+
/// </summary>
8+
public static class CommandRegistry
9+
{
10+
public static Dictionary<string, Func<string[], Task<int>>> Build(IPlatformHost host)
11+
{
12+
var installer = new Installer(host);
13+
var runner = new ScriptRunner(host);
14+
15+
return new(StringComparer.OrdinalIgnoreCase)
16+
{
17+
["install"] = async _ => { await installer.InstallAsync(); return 0; },
18+
["uninstall"] = async _ => { await installer.UninstallAsync(); return 0; },
19+
["boost"] = args => runner.RunAsync("boost", args),
20+
["monitor"] = args => runner.RunAsync("monitor", args),
21+
["status"] = args => runner.RunAsync("status", args),
22+
["recover"] = args => runner.RunAsync("recover", args),
23+
["restore"] = args => runner.RunAsync("restore", args),
24+
["doctor"] = async _ => { await Diagnostics.RunDoctorAsync(host); return 0; },
25+
["version"] = _ => { Console.WriteLine($"tsg {Assembly.GetExecutingAssembly().GetName().Version}"); return Task.FromResult(0); },
26+
["help"] = _ => { PrintHelp(); return Task.FromResult(0); },
27+
["--help"] = _ => { PrintHelp(); return Task.FromResult(0); },
28+
["-h"] = _ => { PrintHelp(); return Task.FromResult(0); },
29+
["-v"] = _ => { Console.WriteLine($"tsg {Assembly.GetExecutingAssembly().GetName().Version}"); return Task.FromResult(0); },
30+
};
31+
}
32+
33+
static void PrintHelp()
34+
{
35+
var os = OperatingSystem.IsWindows() ? "Windows" : "Linux/macOS";
36+
Console.WriteLine($"""
37+
38+
████████╗███████╗ ██████╗
39+
╚══██╔══╝██╔════╝██╔════╝
40+
██║ ███████╗██║ ███╗
41+
██║ ╚════██║██║ ██║
42+
██║ ███████║╚██████╔╝
43+
╚═╝ ╚══════╝ ╚═════╝
44+
⚡ Terminal State Guard v1.0 ⚡
45+
Platform: {os} | .NET {Environment.Version}
46+
47+
USAGE:
48+
tsg install Setup scripts, shortcuts & terminal integration
49+
tsg uninstall Remove configuration
50+
tsg boost Elevate Copilot priority (Admin/sudo)
51+
tsg monitor Safe live monitor with diagnostics
52+
tsg status Quick health check
53+
tsg recover Recover terminal sessions
54+
tsg restore Restore original priorities
55+
tsg doctor Diagnose environment issues
56+
tsg version Show version
57+
58+
SHORTCUTS (after install):
59+
Ctrl+Alt+B Boost Ctrl+Alt+M Monitor
60+
Ctrl+Alt+S Status Ctrl+Alt+F Recover
61+
Ctrl+Alt+R Restore Ctrl+Alt+H Help
62+
63+
SAFETY:
64+
⛔ Monitor is READ-ONLY — never modifies Copilot files
65+
⛔ NEVER delete events.jsonl — destroys session history
66+
67+
""");
68+
}
69+
}
70+
71+
file static class Assembly
72+
{
73+
public static System.Reflection.Assembly GetExecutingAssembly()
74+
=> System.Reflection.Assembly.GetExecutingAssembly();
75+
}

0 commit comments

Comments
 (0)