Compare commits

...

5 Commits

Author SHA1 Message Date
Ed Zynda 8840cbfabc feat: show spinner during shell command execution (! and !!)
Shell commands (! and !!) now display the KITT spinner animation while
running, matching the behavior of LLM agent steps and compaction.

On shellCommandMsg: transition to stateWorking and start the spinner.
On shellCommandResultMsg: stop the spinner and return to stateInput.
2026-03-18 17:48:15 +03:00
Ed Zynda a11b41cda4 fix: prevent duplicate spinner tick loops causing double-speed animation
The KITT spinner animation would sometimes run at 2x (or higher) speed
because multiple concurrent tick loops could accumulate in the Bubble Tea
command queue.

The problematic sequence: SpinnerEvent{Show:true} starts tick loop A,
SpinnerEvent{Show:false} sets spinning=false but tick A is still
in-flight, then ToolExecutionEvent restarts spinning and starts tick
loop B. When the stale tick A fires, spinning is true again so it
continues — now two loops advance spinnerFrame simultaneously.

Fix: add a generation counter (uint64) to StreamComponent. Each
streamSpinnerTickMsg carries the generation it was created for. The tick
handler only processes ticks matching the current generation — stale
ticks from previous start/stop cycles are silently discarded.

Generation is bumped on every spinner start, stop, and Reset() to
ensure at most one tick loop is ever active.
2026-03-18 17:44:11 +03:00
Ed Zynda 8b7be8b735 fix: use immediate parent dir for main.go extension names
deriveExtensionName was using the full directory path (e.g.
examples/extensions/kit-telegram) to derive the display name for
main.go extensions, producing verbose names like 'Examples Extensions
Kit Telegram Extension'. Now uses filepath.Base(dir) so only the
immediate parent directory is used, giving 'Kit Telegram Extension'.

Also fix TestLoadExtensions_SkipsBadFiles which was flaky when
globally-installed git packages existed — isolate the test from the
host environment by overriding XDG_CONFIG_HOME, XDG_DATA_HOME, and
the working directory.
2026-03-18 17:36:06 +03:00
Ed Zynda caa6d1c178 Add kit-telegram example extension
- Copy Telegram relay extension from ../kit-telegram
- Add README with quickstart, commands, API reference, and architecture
- Update examples/extensions/README.md with Integrations section and details
2026-03-18 17:14:47 +03:00
Ed Zynda 001156053d chore: untrack .agents and skills-lock.json, update skills SKILL.md 2026-03-18 17:05:03 +03:00
14 changed files with 2645 additions and 1102 deletions
-64
View File
@@ -1,64 +0,0 @@
---
name: btca-cli
description: Operate the btca CLI for local resources and source-first answers. Use when setting up btca in a project, connecting a provider, adding or managing resources, and asking questions via btca commands. Invoke this skill when the user says "use btca" or needs to do more detailed research on a specific library or framework.
---
# btca CLI
`btca` is a source-first research CLI. It hydrates resources (git, local, npm) into searchable context, then answers questions grounded in those sources. Use configured resources for ongoing work, or one-off anonymous resources directly in `btca ask`.
Full CLI reference: https://docs.btca.dev/guides/cli-reference
Add resources:
```bash
# Git resource
btca add -n svelte-dev https://github.com/sveltejs/svelte.dev
# Local directory
btca add -n my-docs -t local /absolute/path/to/docs
# npm package
btca add npm:@types/node@22.10.1 -n node-types -t npm
```
Verify resources:
```bash
btca resources
```
Ask a question:
```bash
btca ask -r svelte-dev -q "How do I define remote functions?"
```
## Common Tasks
- Ask with multiple resources:
```bash
btca ask -r react -r typescript -q "How do I type useState?"
```
- Ask with anonymous one-off resources (not saved to config):
```bash
# One-off git repo
btca ask -r https://github.com/sveltejs/svelte -q "Where is the implementation of writable stores?"
# One-off npm package
btca ask -r npm:react@19.0.0 -q "How is useTransition exported?"
```
## Config Overview
- Config lives in `btca.config.jsonc` (project) and `~/.config/btca/btca.config.jsonc` (global).
- Project config overrides global and controls provider/model and resources.
## Troubleshooting
- "No resources configured": add resources with `btca add ...` and re-run `btca resources`.
- "Provider not connected": run `btca connect` and follow the prompts.
- "Unknown resource": use `btca resources` for configured names, or pass a valid HTTPS git URL / `npm:<package>` as an anonymous one-off in `btca ask`.
@@ -1,3 +0,0 @@
interface:
display_name: "BTCA CLI"
short_description: "Help with BTCA CLI setup and usage workflows"
File diff suppressed because it is too large Load Diff
+2
View File
@@ -12,3 +12,5 @@ dist/
contribute/output/
CONTEXT.md
output/
.agents/
skills-lock.json
+17
View File
@@ -77,6 +77,12 @@ kit install github.com/mark3labs/kit/examples/extensions --local
| `subagent-widget.go` | Widget with subagent updates | Goroutines + widgets |
| `dev-reload.go` | Hot reload extensions | `ReloadExtensions` |
### Integrations
| Extension | Description | Key API |
|-----------|-------------|---------|
| `kit-telegram/` | Telegram relay for remote monitoring & control | `RegisterCommand`, `OnAgentStart/End`, `SetStatus`, `SendMessage` |
### Rendering
| Extension | Description | Key API |
@@ -122,6 +128,17 @@ Complex real-world example:
- File watching
- Diagnostics aggregation
### kit-telegram/
Full-featured Telegram integration:
- Slash command with subcommands and tab completion
- Interactive guided setup flow with prompts
- Background long-polling goroutine
- Progress message rendering edited in place
- Message queue with edit-before-dispatch
- Remote command handling from Telegram
- Status bar and widget updates
- Config persistence with atomic writes
## Multi-File Extension Example
The `kit-kit-agents/` directory demonstrates the multi-file pattern:
+111
View File
@@ -0,0 +1,111 @@
# kit-telegram
A Kit extension that relays all Kit agent runs to Telegram and lets approved Telegram users reply back into Kit.
## What it does
- Relays **all Kit runs** to one Telegram chat while connected
- Edits one Telegram progress message in place during a run
- Lets approved Telegram users send normal text replies back into Kit
- Shows `Telegram Connected` or `Telegram Disconnected` in the status bar
- Shows a small spinner animation as `⠋ Telegram Connecting` only while the relay is still connecting
- On startup with an already validated enabled config, sends a short Telegram connection message to confirm the relay is up
## Requirements
- `kit` installed and working
- A Telegram bot token from `@BotFather`
- Either:
- A Telegram chat where you can message the bot, or
- A numeric Telegram chat id you want to enter manually
- For group chats, one or more allowed Telegram user ids
## Quickstart
### 1. Install the extension
```bash
kit install github.com/mark3labs/kit/examples/extensions/kit-telegram
```
Or run directly:
```bash
kit -e path/to/kit-telegram/main.go
```
### 2. Start Kit and connect Telegram
```bash
kit
```
Inside Kit, run:
```
/telegram connect
```
You will be prompted for:
- Bot token from `@BotFather`
- Whether to auto-detect the chat by messaging the bot or enter the chat id manually
- Allowed user ids when needed
### 3. Verify the relay
```
/telegram test
```
Reply in Telegram with the code from the test message.
## Commands
| Command | Description |
|---------|-------------|
| `/telegram` | Human-friendly overview and subcommand list |
| `/telegram status` | Raw deterministic relay state |
| `/telegram test` | Verify outbound and inbound relay |
| `/telegram toggle` | Enable or disable relay without deleting credentials |
| `/telegram logout` | Remove saved credentials and disconnect relay |
| `/telegram connect` | Run the setup flow again |
| `/telegram clear` | Clear Telegram status and working messages from the TUI |
## Remote commands (from Telegram)
| Command | Description |
|---------|-------------|
| `/telegram` | Sends the overview back to Telegram |
| `/telegram status` | Sends the deterministic state report to Telegram |
| `/telegram test` | Sends a reply-code test message from Telegram |
| `/telegram toggle` | Flips the enabled flag |
| `/telegram logout yes` | Logs out (requires `yes` confirmation) |
| `/telegram clear` | Clears the TUI footer and working messages |
## Key APIs Used
- `RegisterCommand` — Slash command with subcommands and tab completion
- `OnSessionStart` / `OnSessionShutdown` — Lifecycle management
- `OnAgentStart` / `OnAgentEnd` — Run tracking and progress rendering
- `OnToolCall` / `OnToolResult` — Action tracking
- `OnMessageEnd` — Capture assistant responses
- `OnInput` — Mirror local messages to Telegram
- `SetStatus` / `RemoveStatus` — Status bar indicators
- `SetWidget` / `RemoveWidget` — Working message display
- `PromptInput` / `PromptSelect` / `PromptConfirm` — Interactive setup flow
- `SendMessage` — Inject Telegram replies as Kit prompts
## Architecture
Single Go file interpreted by Yaegi at runtime. Core components:
- **Telegram Bot API client** — HTTP calls via `net/http` for getMe, getChat, getChatMember, getUpdates (long-polling), sendMessage, editMessageText
- **Config persistence** — JSON file at `.kit/kit-telegram.json` with atomic writes
- **Long-polling goroutine** — Background polling for Telegram updates with warmup poll, retry, and client-side timeouts
- **Message queue** — In-memory FIFO queue for Telegram prompt input with edit-before-dispatch support
- **Progress rendering** — `⏳ elapsed · step N` with action lines, edited in place
- **Final rendering** — `✅/❌ elapsed` with response text, split into chunks for long output
## Debug mode
Set environment variable `KIT_TELEGRAM_DEBUG=1` to enable verbose debug logging.
File diff suppressed because it is too large Load Diff
+9
View File
@@ -304,6 +304,15 @@ func Init(api ext.API) {
func TestLoadExtensions_SkipsBadFiles(t *testing.T) {
dir := t.TempDir()
// Isolate from host environment so globally-installed extensions
// are not discovered alongside the test fixtures.
isolated := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", filepath.Join(isolated, "config"))
t.Setenv("XDG_DATA_HOME", filepath.Join(isolated, "data"))
origWd, _ := os.Getwd()
_ = os.Chdir(isolated)
t.Cleanup(func() { _ = os.Chdir(origWd) })
// Good extension
good := `package main
import "kit/ext"
+2 -2
View File
@@ -383,8 +383,8 @@ func deriveExtensionName(relPath string, isMain bool) string {
base := filepath.Base(relPath)
if isMain && dir != "." {
// Use directory name for main.go files
name := strings.ReplaceAll(dir, "/", " ")
// Use immediate parent directory name for main.go files
name := filepath.Base(dir)
name = strings.ReplaceAll(name, "_", " ")
name = strings.ReplaceAll(name, "-", " ")
return cases.Title(language.English).String(name) + " Extension"
+40 -2
View File
@@ -560,9 +560,10 @@ func TestStreamComponent_SpinnerTick_AdvancesFrame(t *testing.T) {
// Start spinning first.
c = sendStreamMsg(c, app.SpinnerEvent{Show: true})
initialFrame := c.spinnerFrame
gen := c.spinnerGeneration
// Send a tick.
_, cmd := c.Update(streamSpinnerTickMsg{})
// Send a tick with the current generation.
_, cmd := c.Update(streamSpinnerTickMsg{generation: gen})
if c.spinnerFrame != initialFrame+1 {
t.Fatalf("expected spinnerFrame=%d, got %d", initialFrame+1, c.spinnerFrame)
@@ -583,3 +584,40 @@ func TestStreamComponent_SpinnerTick_NoReschedule_WhenNotSpinning(t *testing.T)
t.Fatal("expected no tick reschedule when not spinning")
}
}
// TestStreamComponent_StaleTick_Discarded verifies that a tick from a previous
// spinner generation is silently discarded, preventing duplicate concurrent
// tick loops that would double the animation speed.
func TestStreamComponent_StaleTick_Discarded(t *testing.T) {
c := newTestStream()
// Start spinner → generation 1.
c = sendStreamMsg(c, app.SpinnerEvent{Show: true})
staleGen := c.spinnerGeneration
// Stop spinner → generation bumped to 2.
c = sendStreamMsg(c, app.SpinnerEvent{Show: false})
// Restart spinner → generation bumped to 3.
c = sendStreamMsg(c, app.SpinnerEvent{Show: true})
currentGen := c.spinnerGeneration
frameBefore := c.spinnerFrame
// Simulate a stale tick from the first spinner session arriving.
_, cmd := c.Update(streamSpinnerTickMsg{generation: staleGen})
if c.spinnerFrame != frameBefore {
t.Fatalf("stale tick should not advance frame: expected %d, got %d", frameBefore, c.spinnerFrame)
}
if cmd != nil {
t.Fatal("stale tick should not reschedule")
}
// A tick from the current generation should still work.
_, cmd = c.Update(streamSpinnerTickMsg{generation: currentGen})
if c.spinnerFrame != frameBefore+1 {
t.Fatalf("current-gen tick should advance frame: expected %d, got %d", frameBefore+1, c.spinnerFrame)
}
if cmd == nil {
t.Fatal("current-gen tick should reschedule")
}
}
+12
View File
@@ -1130,10 +1130,22 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// ── Shell command (! / !!) ───────────────────────────────────────────────
case shellCommandMsg:
// Show spinner while the shell command runs.
m.state = stateWorking
if m.stream != nil {
_, cmd := m.stream.Update(app.SpinnerEvent{Show: true})
cmds = append(cmds, cmd)
}
// Execute the shell command asynchronously so the TUI stays responsive.
cmds = append(cmds, m.executeShellCommand(msg))
case shellCommandResultMsg:
// Stop spinner now that the command has finished.
if m.stream != nil {
_, cmd := m.stream.Update(app.SpinnerEvent{Show: false})
cmds = append(cmds, cmd)
}
m.state = stateInput
cmds = append(cmds, m.handleShellCommandResult(msg))
// ── App layer events ─────────────────────────────────────────────────────
+35 -10
View File
@@ -59,14 +59,20 @@ func knightRiderFrames() []string {
}
// streamSpinnerTickMsg is the internal tick message that drives the KITT-style
// spinner animation inside StreamComponent.
type streamSpinnerTickMsg struct{}
// spinner animation inside StreamComponent. The generation field ties each tick
// to the spinner session that created it so that stale ticks from a previous
// start/stop cycle are silently discarded instead of creating a second
// concurrent tick loop (which doubles the animation speed).
type streamSpinnerTickMsg struct {
generation uint64
}
// streamSpinnerTickCmd returns a tea.Cmd that fires streamSpinnerTickMsg at the
// KITT animation frame rate (14 fps).
func streamSpinnerTickCmd() tea.Cmd {
// KITT animation frame rate (14 fps). The generation parameter is embedded in
// the message so the receiver can verify it matches the current spinner session.
func streamSpinnerTickCmd(generation uint64) tea.Cmd {
return tea.Tick(time.Second/14, func(_ time.Time) tea.Msg {
return streamSpinnerTickMsg{}
return streamSpinnerTickMsg{generation: generation}
})
}
@@ -128,6 +134,15 @@ type StreamComponent struct {
// remains visible alongside streaming text until Reset().
spinning bool
// spinnerGeneration is incremented each time a new spinner tick loop
// is started. Tick messages carry the generation they were created for;
// if a tick's generation doesn't match the current one, it is a stale
// tick from a previous start/stop cycle and is silently discarded.
// This prevents multiple concurrent tick loops from accumulating when
// the spinner is rapidly stopped and restarted (e.g. SpinnerEvent
// hide → ToolExecutionEvent start before the old tick fires).
spinnerGeneration uint64
// spinnerFrames are the pre-rendered KITT animation frames.
spinnerFrames []string
@@ -233,6 +248,7 @@ func (s *StreamComponent) SetHeight(h int) {
func (s *StreamComponent) Reset() {
s.phase = streamPhaseIdle
s.spinning = false
s.spinnerGeneration++ // invalidate any in-flight tick commands
s.spinnerFrame = 0
s.activeTools = nil
s.streamContent.Reset()
@@ -313,11 +329,15 @@ func (s *StreamComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
s.renderDirty = true
case streamSpinnerTickMsg:
if s.spinning {
// Only continue the tick loop if this tick belongs to the current
// spinner session. Stale ticks from a previous start/stop cycle
// are silently dropped, preventing duplicate concurrent tick loops
// that would double (or worse) the animation speed.
if s.spinning && msg.generation == s.spinnerGeneration {
s.spinnerFrame++
return s, streamSpinnerTickCmd()
return s, streamSpinnerTickCmd(s.spinnerGeneration)
}
// Spinning stopped; let the tick loop die naturally.
// Spinning stopped or generation mismatch; let the tick loop die.
// ── App-layer events ──────────────────────────────────────────────────
@@ -325,13 +345,17 @@ func (s *StreamComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.Show && !s.spinning {
s.phase = streamPhaseActive
s.spinning = true
s.spinnerGeneration++ // new session; invalidate any stale ticks
s.spinnerFrame = 0
if s.timestamp.IsZero() {
s.timestamp = time.Now()
}
return s, streamSpinnerTickCmd()
return s, streamSpinnerTickCmd(s.spinnerGeneration)
} else if !msg.Show && s.spinning {
s.spinning = false
// Bump generation so any in-flight tick from this session is
// discarded if spinning is restarted before it fires.
s.spinnerGeneration++
}
case streamFlushTickMsg:
@@ -376,7 +400,8 @@ func (s *StreamComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !s.spinning {
s.phase = streamPhaseActive
s.spinning = true
return s, streamSpinnerTickCmd()
s.spinnerGeneration++ // new session; invalidate stale ticks
return s, streamSpinnerTickCmd(s.spinnerGeneration)
}
} else {
// Tool finished — remove from active list but keep spinning if others remain.
-15
View File
@@ -1,15 +0,0 @@
{
"version": 1,
"skills": {
"btca-cli": {
"source": "davis7dotsh/better-context",
"sourceType": "github",
"computedHash": "99bc5301f4f839a6f3be99d98955f32f1cd576c218731fa05fa54a003bd20e9b"
},
"kit-extensions": {
"source": "mark3labs/kit",
"sourceType": "github",
"computedHash": "9347a88bec46dd52727a672b6c8d058955f9f50dfe98708e0c63b85e0779ba96"
}
}
}
+153
View File
@@ -7,6 +7,8 @@ description: Guide for creating Kit extensions. Use when the user asks to build,
Kit extensions are single-file Go programs interpreted at runtime by Yaegi. They hook into Kit's lifecycle, register custom tools and slash commands, display widgets, intercept editor input, render tool output, and more.
Extensions can be distributed via git repositories using `kit install`. Repos can contain single extensions or collections of multiple extensions.
## Extension Structure
Every extension must export a `package main` with an `Init(api ext.API)` function:
@@ -772,6 +774,157 @@ kit extensions init
---
## Distributing Extensions via Git Repositories
Extensions can be distributed and installed from git repositories using `kit install`. This enables sharing extensions with others and maintaining versioned collections.
### Repository Structure
Extensions support two organization patterns within a repo:
**Single-file extensions** (simple, standalone):
```
my-extension-repo/
├── weather.go # Single extension file
├── todo.go # Another extension
└── README.md # Installation and usage docs
```
**Multi-file extensions** (with `main.go` entry point):
```
my-extension-repo/
├── git-tools/
│ ├── main.go # Entry point
│ ├── helpers.go # Supporting code
│ └── config.go # Configuration
├── todo/
│ ├── main.go # Entry point
│ └── storage.go # Storage logic
└── README.md
```
**Hybrid approach** (single files + subdirectories with main.go):
```
my-extensions/
├── weather.go # Single file extension
├── calculator.go # Single file extension
├── git-tools/
│ ├── main.go # Multi-file extension
│ └── utils.go
└── README.md
```
### Installing from Git
Users install extensions using the `kit install` command:
```bash
# Install from GitHub (latest)
kit install github.com/user/repo
# Pin to a specific version/tag
kit install github.com/user/repo@v1.0.0
kit install github.com/user/repo@main
kit install github.com/user/repo@abc1234
# Install locally in project (./.kit/git/)
kit install github.com/user/repo --local
# Interactive selection for repos with multiple extensions
kit install github.com/user/collection --select
```
Supported URL formats:
- `github.com/user/repo` — Shorthand (defaults to HTTPS)
- `git:github.com/user/repo` — Git prefix format
- `https://github.com/user/repo` — HTTPS URL
- `ssh://git@github.com/user/repo` — SSH URL
- `git@github.com:user/repo` — SSH shorthand
### Managing Installed Extensions
```bash
# Update an installed extension (skips pinned versions)
kit install github.com/user/repo --update
# Remove an installed extension
kit install github.com/user/repo --uninstall
# List all loaded extensions
kit extensions list
# Validate all extensions
kit extensions validate
```
### Extension Selection
For repos containing multiple extensions, users can select which to install:
```bash
# Interactive selection
kit install github.com/user/collection --select
```
This prompts the user to choose which extensions to install. Selected extensions are recorded in the manifest, and only those are loaded at runtime (others in the repo are ignored).
### README Template for Extension Repos
Include this in your extension repo's README.md:
```markdown
# My Kit Extensions
A collection of extensions for [Kit](https://github.com/mark3labs/kit).
## Installation
### Install all extensions
\`\`\`bash
kit install github.com/username/repo
\`\`\`
### Install specific extensions
\`\`\`bash
kit install github.com/username/repo --select
\`\`\`
### Install locally in a project
\`\`\`bash
kit install github.com/username/repo --local
\`\`\`
## Extensions
### Extension Name
Description of what it does.
- **Path**: `./ext-name/main.go` or `./ext-name.go`
- **Commands**: `/command-name`
- **Tools**: `tool_name`
## Requirements
- Kit vX.Y.Z+
- Any other dependencies
## Update
\`\`\`bash
kit install github.com/username/repo --update
\`\`\`
```
### Storage Locations
Installed extensions are stored at:
- **Global**: `~/.local/share/kit/git/<host>/<owner>/<repo>/`
- **Project-local**: `./.kit/git/<host>/<owner>/<repo>/`
- **Manifest**: `packages.json` in respective directories
---
## Complete Example: Plan Mode
A full extension that restricts the agent to read-only tools, with a slash command, keyboard shortcut, option, status bar indicator, and system prompt injection: