agent-sh 0.14.11 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +38 -42
  2. package/dist/agent/agent-loop.d.ts +9 -17
  3. package/dist/agent/agent-loop.js +104 -136
  4. package/dist/agent/events.d.ts +8 -11
  5. package/dist/agent/host-types.d.ts +17 -11
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +38 -22
  8. package/dist/agent/providers/deepseek.js +9 -1
  9. package/dist/agent/session-store.js +1 -1
  10. package/dist/agent/system-prompt.d.ts +7 -3
  11. package/dist/agent/system-prompt.js +11 -14
  12. package/dist/agent/tool-protocol.js +0 -7
  13. package/dist/cli/args.js +2 -1
  14. package/dist/cli/install.d.ts +1 -0
  15. package/dist/cli/install.js +29 -1
  16. package/dist/cli/subcommands.js +1 -0
  17. package/dist/core/event-bus.js +0 -2
  18. package/dist/core/extension-loader.js +3 -1
  19. package/dist/core/index.d.ts +1 -1
  20. package/dist/core/index.js +3 -2
  21. package/dist/extensions/slash-commands/index.js +16 -11
  22. package/dist/shell/index.js +9 -0
  23. package/dist/shell/shell-context.d.ts +2 -2
  24. package/dist/shell/shell-context.js +26 -11
  25. package/dist/shell/tui-renderer.js +0 -1
  26. package/dist/utils/diff-renderer.js +2 -9
  27. package/dist/utils/handler-registry.d.ts +1 -6
  28. package/dist/utils/handler-registry.js +1 -6
  29. package/dist/utils/line-editor.js +0 -2
  30. package/dist/utils/palette.js +4 -4
  31. package/dist/utils/terminal-buffer.d.ts +2 -0
  32. package/dist/utils/terminal-buffer.js +4 -0
  33. package/docs/README.md +14 -0
  34. package/docs/agent.md +398 -0
  35. package/docs/architecture.md +196 -0
  36. package/docs/context-management.md +200 -0
  37. package/docs/extensions.md +951 -0
  38. package/docs/library.md +84 -0
  39. package/docs/troubleshooting.md +65 -0
  40. package/docs/tui-composition.md +294 -0
  41. package/docs/usage.md +306 -0
  42. package/examples/extensions/ash-acp-bridge/src/index.ts +11 -7
  43. package/examples/extensions/ash-scheme/index.ts +104 -74
  44. package/examples/extensions/ash-scheme/package.json +1 -1
  45. package/examples/extensions/ashi/EXTENDING.md +4 -2
  46. package/examples/extensions/ashi/README.md +17 -1
  47. package/examples/extensions/ashi/docs/ui-surface-protocol.md +163 -0
  48. package/examples/extensions/ashi/package.json +13 -3
  49. package/examples/extensions/ashi/src/capture.ts +45 -7
  50. package/examples/extensions/ashi/src/chat/assistant.ts +23 -43
  51. package/examples/extensions/ashi/src/chat/lines.ts +20 -1
  52. package/examples/extensions/ashi/src/cli.ts +26 -3
  53. package/examples/extensions/ashi/src/clipboard-image.ts +1 -1
  54. package/examples/extensions/ashi/src/dialogs.ts +67 -0
  55. package/examples/extensions/ashi/src/display-config.ts +7 -0
  56. package/examples/extensions/ashi/src/docks.ts +31 -0
  57. package/examples/extensions/ashi/src/events.ts +16 -0
  58. package/examples/extensions/ashi/src/frontend.ts +134 -27
  59. package/examples/extensions/ashi/src/hooks.ts +6 -12
  60. package/examples/extensions/ashi/src/input-prompt.ts +64 -0
  61. package/examples/extensions/ashi/src/renderer.ts +22 -2
  62. package/examples/extensions/ashi/src/renderers/pi-tui/index.ts +7 -3
  63. package/examples/extensions/ashi/src/renderers/pi-tui/nodes.ts +67 -10
  64. package/examples/extensions/ashi/src/renderers/pi-tui/schema-mount.ts +11 -1
  65. package/examples/extensions/ashi/src/renderers/pi-tui/tool-group.ts +5 -8
  66. package/examples/extensions/ashi/src/schema.ts +3 -0
  67. package/examples/extensions/ashi/src/session-commands.ts +2 -1
  68. package/examples/extensions/ashi/src/status-footer.ts +21 -3
  69. package/examples/extensions/ashi/src/ui.ts +88 -0
  70. package/examples/extensions/ashi-ink/README.md +2 -0
  71. package/examples/extensions/ashi-ink/package.json +2 -2
  72. package/examples/extensions/ashi-scheme-render.ts +8 -2
  73. package/examples/extensions/ashi-ui-demo.ts +63 -0
  74. package/examples/extensions/claude-code-bridge/package.json +1 -1
  75. package/examples/extensions/latex-images.ts +57 -9
  76. package/examples/extensions/opencode-bridge/package.json +1 -1
  77. package/examples/extensions/overlay-agent.ts +5 -5
  78. package/examples/extensions/pi-bridge/index.ts +7 -12
  79. package/package.json +3 -1
  80. package/src/agent/agent-loop.ts +1563 -0
  81. package/src/agent/entry-format.ts +19 -0
  82. package/src/agent/events.ts +151 -0
  83. package/src/agent/extensions/rolling-history/constants.ts +1 -0
  84. package/src/agent/extensions/rolling-history/index.ts +202 -0
  85. package/src/agent/extensions/rolling-history/recall.ts +131 -0
  86. package/src/agent/extensions/rolling-history/strategy.ts +404 -0
  87. package/src/agent/host-types.ts +192 -0
  88. package/src/agent/index.ts +591 -0
  89. package/src/agent/live-view.ts +279 -0
  90. package/src/agent/llm-client.ts +111 -0
  91. package/src/agent/llm-facade.ts +43 -0
  92. package/src/agent/normalize-args.ts +61 -0
  93. package/src/agent/nuclear-form.ts +382 -0
  94. package/src/agent/providers/deepseek.ts +39 -0
  95. package/src/agent/providers/ollama.ts +92 -0
  96. package/src/agent/providers/openai-compatible.ts +36 -0
  97. package/src/agent/providers/openai.ts +52 -0
  98. package/src/agent/providers/opencode.ts +142 -0
  99. package/src/agent/providers/openrouter.ts +105 -0
  100. package/src/agent/providers/zai-coding-plan.ts +33 -0
  101. package/src/agent/session-store.ts +336 -0
  102. package/src/agent/skills.ts +228 -0
  103. package/src/agent/store.ts +310 -0
  104. package/src/agent/subagent.ts +305 -0
  105. package/src/agent/system-prompt.ts +151 -0
  106. package/src/agent/token-budget.ts +12 -0
  107. package/src/agent/tool-protocol.ts +722 -0
  108. package/src/agent/tool-registry.ts +66 -0
  109. package/src/agent/tools/bash.ts +95 -0
  110. package/src/agent/tools/edit-file.ts +154 -0
  111. package/src/agent/tools/expand-home.ts +7 -0
  112. package/src/agent/tools/glob.ts +108 -0
  113. package/src/agent/tools/grep.ts +228 -0
  114. package/src/agent/tools/list-skills.ts +37 -0
  115. package/src/agent/tools/ls.ts +81 -0
  116. package/src/agent/tools/pwsh.ts +140 -0
  117. package/src/agent/tools/read-file.ts +164 -0
  118. package/src/agent/tools/write-file.ts +72 -0
  119. package/src/agent/types.ts +149 -0
  120. package/src/cli/args.ts +91 -0
  121. package/src/cli/auth/cli.ts +244 -0
  122. package/src/cli/auth/discover.ts +52 -0
  123. package/src/cli/auth/keys.ts +143 -0
  124. package/src/cli/index.ts +295 -0
  125. package/src/cli/init.ts +74 -0
  126. package/src/cli/install.ts +439 -0
  127. package/src/cli/shell-env.ts +68 -0
  128. package/src/cli/subcommands.ts +24 -0
  129. package/src/core/event-bus.ts +252 -0
  130. package/src/core/extension-loader.ts +347 -0
  131. package/src/core/index.ts +152 -0
  132. package/src/core/settings.ts +398 -0
  133. package/src/core/types.ts +61 -0
  134. package/src/extensions/file-autocomplete.ts +71 -0
  135. package/src/extensions/index.ts +38 -0
  136. package/src/extensions/slash-commands/events.ts +14 -0
  137. package/src/extensions/slash-commands/index.ts +269 -0
  138. package/src/shell/events.ts +73 -0
  139. package/src/shell/host-types.ts +150 -0
  140. package/src/shell/index.ts +159 -0
  141. package/src/shell/input-handler.ts +505 -0
  142. package/src/shell/output-parser.ts +156 -0
  143. package/src/shell/shell-context.ts +193 -0
  144. package/src/shell/shell.ts +414 -0
  145. package/src/shell/strategies/bash.ts +83 -0
  146. package/src/shell/strategies/fish.ts +77 -0
  147. package/src/shell/strategies/index.ts +24 -0
  148. package/src/shell/strategies/types.ts +64 -0
  149. package/src/shell/strategies/zsh.ts +92 -0
  150. package/src/shell/terminal.ts +124 -0
  151. package/src/shell/tui-input-view.ts +222 -0
  152. package/src/shell/tui-renderer.ts +1126 -0
  153. package/src/utils/ansi.ts +140 -0
  154. package/src/utils/box-frame.ts +138 -0
  155. package/src/utils/compositor.ts +157 -0
  156. package/src/utils/diff-renderer.ts +829 -0
  157. package/src/utils/diff.ts +244 -0
  158. package/src/utils/executor.ts +305 -0
  159. package/src/utils/file-watcher.ts +110 -0
  160. package/src/utils/floating-panel.ts +1160 -0
  161. package/src/utils/handler-registry.ts +110 -0
  162. package/src/utils/line-editor.ts +636 -0
  163. package/src/utils/markdown.ts +437 -0
  164. package/src/utils/message-utils.ts +113 -0
  165. package/src/utils/package-version.ts +12 -0
  166. package/src/utils/palette.ts +64 -0
  167. package/src/utils/ref-counter.ts +9 -0
  168. package/src/utils/ripgrep-path.ts +17 -0
  169. package/src/utils/shell-output-spill.ts +76 -0
  170. package/src/utils/stream-transform.ts +292 -0
  171. package/src/utils/terminal-buffer.ts +213 -0
  172. package/src/utils/tool-display.ts +315 -0
  173. package/src/utils/tool-interactive.ts +71 -0
  174. package/src/utils/tty.ts +14 -0
package/README.md CHANGED
@@ -5,13 +5,9 @@
5
5
 
6
6
  A composable agent runtime — pair any frontend with any agent backend, over one shared extension layer.
7
7
 
8
- ## Three example apps built on agent-sh
8
+ ## A shell with the agent one keystroke away
9
9
 
10
- agent-sh is small at its core and does its real work through extensions, so the same runtime drives very different apps. Three to start with all sharing the same agent backends, tools, providers, and `~/.agent-sh/settings.json`:
11
-
12
- ### 1. A shell with the agent one keystroke away — bundled with agent-sh
13
-
14
- A normal shell on top of node-pty — your rc config, your aliases, vim and tmux all just work. But at the start of any line, type `>` and you're talking to a small agent that already sees your cwd, your last command, and its output. Nothing to set up, no project to explain.
10
+ The frontend bundled with agent-sh: a normal shell on top of node-pty your rc config, your aliases, vim and tmux all just work. But at the start of any line, type `>` and you're talking to an agent that already sees your cwd, your last command, and its output. Nothing to set up, no project to explain.
15
11
 
16
12
  ![demo](assets/demo.gif)
17
13
 
@@ -23,42 +19,7 @@ A normal shell on top of node-pty — your rc config, your aliases, vim and tmux
23
19
  ~ $ > draft a commit message # agent reads your diff and shell history
24
20
  ```
25
21
 
26
- ```bash
27
- npm install -g agent-sh
28
- ```
29
-
30
- [Quick Start ↓](#quick-start)
31
-
32
- ### 2. ashi — a standalone coding agent
33
-
34
- [**`@guanyilun/ashi`**](examples/extensions/ashi/) is the same `ash` agent in a chat-style TUI, with no shell underneath — just the agent. Installed separately, it reuses agent-sh's backend, tools, slash commands, providers, and skills, and adds session history, in-session branching, and LLM-driven compaction.
35
-
36
- ```bash
37
- npm install -g @guanyilun/ashi
38
- ashi
39
- ```
40
-
41
- ashi makes the runtime's **decoupled rendering** concrete: the frontend is itself an extension, and even *how* it draws tool calls and results is a swappable render extension. Same agent backend, same conversation — load a different render extension and the whole TUI restyles, no code changes:
42
-
43
- | pi-style rendering | claude-code-style rendering |
44
- |---|---|
45
- | ![ashi rendering tool calls pi-style](assets/ashi-pi-style.png) | ![ashi rendering tool calls claude-code-style](assets/ashi-claude-code-style.png) |
46
-
47
- ### 3. asHub — a GUI coding agent
48
-
49
- [**firslov/asHub**](https://github.com/firslov/asHub) is a third-party cross-platform desktop app (Electron) built on the agent-sh runtime: a multi-session sidebar, persistence across restarts, and a live-streaming interface with Markdown, syntax-highlighted code, diffs, and tool-call rendering. macOS / Windows / Linux.
50
-
51
- It pushes the same decoupling one step further — the frontend isn't a terminal at all, but a full desktop GUI on the same runtime, backends, and tools:
52
-
53
- ![asHub desktop GUI](assets/ashub.png)
54
-
55
- ## How it works
56
-
57
- agent-sh is a **composable agent runtime**. At its center is a pure kernel — a typed event bus, a named-handler registry, and an extension loader — that knows nothing about terminals, LLMs, shells, or rendering. Everything else plugs into it: the agent backend, its tools, provider management, and the frontend that drives it.
58
-
59
- The frontend and the agent backend are both just components on the bus, so you **mix and match** them freely — wire several frontends to one backend, or keep one frontend and swap the backend underneath — all sharing the **same extension layer** of tools, content transforms, slash commands, and themes. `import { createCore } from "agent-sh"` gives you the headless kernel; load the pieces you want and wire your own I/O.
60
-
61
- For the kernel design in full — the bus, handlers, the compositor, and the shell ↔ agent boundary — see [Architecture](docs/architecture.md). To embed the runtime in your own frontend, see the [Library Guide](docs/library.md). The rest of this README covers the bundled shell.
22
+ **The agent behind `>` is swappable — the terminal stays the same.** Out of the box it's **`ash`**, agent-sh's own lightweight agent: it works with any OpenAI-compatible API and shares its tool surface with every extension you install. Already invested in another coding agent? The same `>` and the same shell-context wiring can host **pi**, **claude-code**, or **opencode** instead through in-the-box bridges — bring your own backend, keep the workflow. The Quick Start below walks through both.
62
23
 
63
24
  ## Quick Start
64
25
 
@@ -180,6 +141,41 @@ All three bridges receive agent-sh's per-query shell context (`<shell_events>`)
180
141
 
181
142
  **Caveat:** pi, claude-code, and opencode each manage their own tool surfaces, so agent-sh extensions that register tools (or skills, instructions, etc.) for the built-in `ash` agent generally won't be visible to a hosted backend. Frontend extensions (themes, content transforms, slash commands, the TUI renderer) keep working — only the agent-side capabilities differ. Use the bridges when you want that agent's toolset; stay on `ash` when you want agent-sh's extension ecosystem.
182
143
 
144
+ ## Same runtime, other frontends
145
+
146
+ The shell is just one frontend. Because the frontend is itself an extension on the bus, the same runtime — same agent backends, tools, providers, and `~/.agent-sh/settings.json` — drives completely different apps.
147
+
148
+ ### ashi — a standalone coding agent
149
+
150
+ [**`@guanyilun/ashi`**](examples/extensions/ashi/) is the same `ash` agent in a chat-style TUI, with no shell underneath — just the agent. Installed separately, it reuses agent-sh's backend, tools, slash commands, providers, and skills, and adds session history, in-session branching, and LLM-driven compaction.
151
+
152
+ ```bash
153
+ npm install -g @guanyilun/ashi
154
+ ashi
155
+ ```
156
+
157
+ ashi makes the runtime's **decoupled rendering** concrete: the frontend is itself an extension, and even *how* it draws tool calls and results is a swappable render extension. Same agent backend, same conversation — load a different render extension and the whole TUI restyles, no code changes:
158
+
159
+ | pi-style rendering | claude-code-style rendering |
160
+ |---|---|
161
+ | ![ashi rendering tool calls pi-style](assets/ashi-pi-style.png) | ![ashi rendering tool calls claude-code-style](assets/ashi-claude-code-style.png) |
162
+
163
+ ### asHub — a GUI coding agent
164
+
165
+ [**firslov/asHub**](https://github.com/firslov/asHub) is a third-party cross-platform desktop app (Electron) built on the agent-sh runtime: a multi-session sidebar, persistence across restarts, and a live-streaming interface with Markdown, syntax-highlighted code, diffs, and tool-call rendering. macOS / Windows / Linux.
166
+
167
+ It pushes the same decoupling one step further — the frontend isn't a terminal at all, but a full desktop GUI on the same runtime, backends, and tools:
168
+
169
+ ![asHub desktop GUI](assets/ashub.png)
170
+
171
+ ## How it works
172
+
173
+ At agent-sh's center is a pure kernel — a typed event bus, a named-handler registry, and an extension loader — that knows nothing about terminals, LLMs, shells, or rendering. Everything else plugs into it: the agent backend, its tools, provider management, and the frontend that drives it.
174
+
175
+ The frontend and the agent backend are both just components on the bus, so you **mix and match** them freely — wire several frontends to one backend, or keep one frontend and swap the backend underneath — all sharing the **same extension layer** of tools, content transforms, slash commands, and themes. The shell swapping `ash` for a bridged agent, and ashi/asHub putting a different UI on the same backend, are the same idea seen from two directions. `import { createCore } from "agent-sh"` gives you the headless kernel; load the pieces you want and wire your own I/O.
176
+
177
+ For the kernel design in full — the bus, handlers, the compositor, and the shell ↔ agent boundary — see [Architecture](docs/architecture.md). To embed the runtime in your own frontend, see the [Library Guide](docs/library.md).
178
+
183
179
  ## Documentation
184
180
 
185
181
  Start with **Usage** to get running, then **Architecture** for the mental model.
@@ -1,18 +1,10 @@
1
1
  /**
2
- * Internal agent backend — bus-driven, self-wiring.
3
- *
4
- * Subscribes to bus events in constructor:
5
- * - agent:submit → run query through LLM tool loop
6
- * - agent:cancel-request → abort current loop
7
- *
8
- * Emits bus events during execution:
9
- * - agent:query, agent:processing-start/done, agent:response-chunk/done
10
- * - agent:tool-started, agent:tool-call, agent:tool-output-chunk,
11
- * agent:tool-completed, agent:tool-output
12
- * - agent:thinking-chunk, agent:cancelled, agent:error
2
+ * Internal agent backend — bus-driven and self-wiring. wire() subscribes to
3
+ * agent:submit (run the LLM tool loop) and agent:cancel-request (abort it),
4
+ * and the loop emits the agent:* progress/response/tool event stream.
13
5
  */
14
6
  import type { EventBus } from "../core/event-bus.js";
15
- import type { AgentMode } from "./host-types.js";
7
+ import type { Model } from "./host-types.js";
16
8
  import type { LlmClient } from "./llm-client.js";
17
9
  import type { HandlerFunctions } from "../utils/handler-registry.js";
18
10
  import { type AgentBackend, type ToolDefinition } from "./types.js";
@@ -21,7 +13,7 @@ export interface AgentLoopConfig {
21
13
  bus: EventBus;
22
14
  llmClient: LlmClient;
23
15
  handlers: HandlerFunctions;
24
- initialMode?: AgentMode;
16
+ initialModel?: Model;
25
17
  compositor?: Compositor;
26
18
  /** Instance ID from core — ensures history entries match the ID in prompts. */
27
19
  instanceId?: string;
@@ -31,7 +23,8 @@ export declare class AgentLoop implements AgentBackend {
31
23
  private toolRegistry;
32
24
  private conversation;
33
25
  private fileReadCache;
34
- private activeMode;
26
+ private activeModel;
27
+ private activeEndpoint;
35
28
  private boundListeners;
36
29
  private boundPipeListeners;
37
30
  private lastProjectSkillNames;
@@ -91,10 +84,9 @@ export declare class AgentLoop implements AgentBackend {
91
84
  kill(): void;
92
85
  private cancel;
93
86
  private reasoningParams;
94
- private get currentMode();
95
- private pullModes;
87
+ private resolveEndpoint;
88
+ private pullModels;
96
89
  private emitIdentity;
97
- private get currentModel();
98
90
  /**
99
91
  * Run compaction via the `conversation:compact` handler. After any
100
92
  * compaction, emit `conversation:after-compact` so listeners