agent-sh 0.9.0 → 0.10.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.
- package/README.md +25 -30
- package/dist/agent/agent-loop.d.ts +43 -6
- package/dist/agent/agent-loop.js +817 -157
- package/dist/agent/conversation-state.d.ts +72 -21
- package/dist/agent/conversation-state.js +364 -151
- package/dist/agent/history-file.d.ts +13 -4
- package/dist/agent/history-file.js +110 -36
- package/dist/agent/nuclear-form.d.ts +28 -3
- package/dist/agent/nuclear-form.js +84 -3
- package/dist/agent/skills.d.ts +2 -4
- package/dist/agent/skills.js +10 -4
- package/dist/agent/subagent.d.ts +23 -0
- package/dist/agent/subagent.js +53 -11
- package/dist/agent/system-prompt.d.ts +34 -1
- package/dist/agent/system-prompt.js +96 -47
- package/dist/agent/token-budget.d.ts +10 -13
- package/dist/agent/token-budget.js +6 -46
- package/dist/agent/tool-protocol.d.ts +23 -1
- package/dist/agent/tool-protocol.js +169 -4
- package/dist/agent/tools/bash.js +3 -3
- package/dist/agent/tools/edit-file.js +9 -6
- package/dist/agent/tools/glob.js +4 -2
- package/dist/agent/tools/grep.js +27 -3
- package/dist/agent/tools/ls.js +5 -6
- package/dist/agent/types.d.ts +1 -2
- package/dist/context-manager.d.ts +16 -19
- package/dist/context-manager.js +48 -152
- package/dist/core.js +27 -6
- package/dist/event-bus.d.ts +59 -3
- package/dist/executor.d.ts +4 -3
- package/dist/executor.js +18 -15
- package/dist/extension-loader.js +75 -17
- package/dist/extensions/agent-backend.d.ts +8 -7
- package/dist/extensions/agent-backend.js +72 -50
- package/dist/extensions/index.js +0 -2
- package/dist/extensions/slash-commands.js +14 -9
- package/dist/extensions/tui-renderer.js +67 -80
- package/dist/index.js +25 -6
- package/dist/settings.d.ts +39 -16
- package/dist/settings.js +51 -11
- package/dist/shell/input-handler.d.ts +2 -1
- package/dist/shell/input-handler.js +84 -76
- package/dist/shell/shell.js +19 -2
- package/dist/types.d.ts +15 -0
- package/dist/utils/ansi.d.ts +7 -0
- package/dist/utils/ansi.js +69 -8
- package/dist/utils/box-frame.js +8 -2
- package/dist/utils/compositor.d.ts +5 -0
- package/dist/utils/compositor.js +31 -3
- package/dist/utils/diff-renderer.d.ts +9 -0
- package/dist/utils/diff-renderer.js +221 -143
- package/dist/utils/diff.d.ts +21 -2
- package/dist/utils/diff.js +165 -89
- package/dist/utils/handler-registry.d.ts +5 -0
- package/dist/utils/handler-registry.js +6 -0
- package/dist/utils/line-editor.d.ts +11 -1
- package/dist/utils/line-editor.js +44 -5
- package/dist/utils/markdown.js +23 -8
- package/dist/utils/package-version.d.ts +1 -0
- package/dist/utils/package-version.js +10 -0
- package/dist/utils/shell-output-spill.d.ts +2 -0
- package/dist/utils/shell-output-spill.js +81 -0
- package/dist/utils/tool-display.d.ts +1 -1
- package/dist/utils/tool-display.js +4 -4
- package/examples/extensions/ash-acp-bridge/src/index.ts +4 -1
- package/examples/extensions/ash-mcp-bridge/index.ts +13 -3
- package/examples/extensions/claude-code-bridge/README.md +14 -0
- package/examples/extensions/claude-code-bridge/index.ts +204 -145
- package/examples/extensions/claude-code-bridge/package.json +1 -0
- package/examples/extensions/interactive-prompts.ts +39 -25
- package/examples/extensions/overlay-agent.ts +3 -3
- package/examples/extensions/peer-mesh.ts +115 -0
- package/examples/extensions/pi-bridge/README.md +16 -0
- package/examples/extensions/pi-bridge/index.ts +9 -155
- package/examples/extensions/questionnaire.ts +16 -5
- package/examples/extensions/subagents.ts +19 -4
- package/examples/extensions/terminal-buffer.ts +163 -0
- package/examples/extensions/user-shell.ts +136 -0
- package/examples/extensions/web-access.ts +8 -0
- package/package.json +36 -2
- package/dist/agent/tools/display.d.ts +0 -13
- package/dist/agent/tools/display.js +0 -70
- package/dist/agent/tools/user-shell.d.ts +0 -13
- package/dist/agent/tools/user-shell.js +0 -87
- package/dist/extensions/shell-recall.d.ts +0 -9
- package/dist/extensions/shell-recall.js +0 -8
- package/dist/extensions/terminal-buffer.d.ts +0 -14
- package/dist/extensions/terminal-buffer.js +0 -134
package/README.md
CHANGED
|
@@ -5,16 +5,18 @@ An agent that lives in a shell — not a shell that lives in an agent.
|
|
|
5
5
|
[](https://www.npmjs.com/package/agent-sh)
|
|
6
6
|
[](https://github.com/guanyilun/agent-sh/blob/main/LICENSE)
|
|
7
7
|
|
|
8
|
+

|
|
9
|
+
|
|
8
10
|
Most AI terminal tools get this backwards: the LLM drives the experience and the shell is bolted on as an afterthought. No real PTY, no job control, no vim, fragile `cd` tracking. The agent is the main character and your terminal is a prop.
|
|
9
11
|
|
|
10
12
|
agent-sh flips this. It's your shell first — full PTY, your rc config, your aliases, everything just works. But type `>` at the start of a line, and you're talking to an agent that has full context of what you've been doing.
|
|
11
13
|
|
|
12
14
|
```
|
|
13
|
-
~ $ ls -la
|
|
14
|
-
~ $ cd ../tests && npm test
|
|
15
|
-
~ $ vim file.ts
|
|
16
|
-
~ $ > explain the last error
|
|
17
|
-
~ $ >
|
|
15
|
+
~ $ ls -la # real shell command
|
|
16
|
+
~ $ cd ../tests && npm test # real cd, env, aliases — all just work
|
|
17
|
+
~ $ vim file.ts # opens vim in the same PTY
|
|
18
|
+
~ $ > explain the last error # agent investigates using its own tools
|
|
19
|
+
~ $ > draft a commit message # agent reads your diff and shell history
|
|
18
20
|
```
|
|
19
21
|
|
|
20
22
|
## Quick Start
|
|
@@ -24,6 +26,12 @@ npm install -g agent-sh
|
|
|
24
26
|
agent-sh
|
|
25
27
|
```
|
|
26
28
|
|
|
29
|
+
Tip: add an alias to your shell config for quick access:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
alias ash="agent-sh"
|
|
33
|
+
```
|
|
34
|
+
|
|
27
35
|
Set `OPENAI_API_KEY` in your environment (or configure providers in `~/.agent-sh/settings.json`). Works with any OpenAI-compatible API — see the [Usage Guide](docs/usage.md) for provider examples (OpenAI, Ollama, OpenRouter, Together, Groq, LM Studio, vLLM).
|
|
28
36
|
|
|
29
37
|
Requires Node.js 18+.
|
|
@@ -32,41 +40,28 @@ Requires Node.js 18+.
|
|
|
32
40
|
|
|
33
41
|
**Real terminal, zero compromise.** Full PTY with your shell config, aliases, and environment. Shell starts instantly — the agent connects asynchronously in the background.
|
|
34
42
|
|
|
35
|
-
**One entry point,
|
|
43
|
+
**One entry point, smart tool selection.** Type `>` and agent-sh figures out how to help. Scratchpad tools (`bash`, `read_file`, `grep`, `glob`) for investigation. Extensions add capabilities like running commands in your live shell. No modes to pick — the agent reasons about which tools to use based on your intent.
|
|
36
44
|
|
|
37
45
|
**Context that just works.** Every query includes your cwd, recent commands, and their output. Run a failing test, type `> fix this`, and agent-sh knows exactly what happened. Context management works like shell history — continuous, persistent across restarts, no sessions to manage. See [Context Management](docs/context-management.md).
|
|
38
46
|
|
|
39
|
-
**Any LLM, any backend.** agent-sh works with any OpenAI-compatible API out of the box. Define multiple providers in settings and
|
|
47
|
+
**Any LLM, any backend.** agent-sh works with any OpenAI-compatible API out of the box. Define multiple providers in settings and switch models at runtime with `/model <name>`. Or swap in a completely different agent — [Claude Code](examples/extensions/claude-code-bridge/) and [pi](examples/extensions/pi-bridge/) run as drop-in backend extensions.
|
|
40
48
|
|
|
41
49
|
**Extensible by design.** The entire system is built on a typed event bus. Extensions can add custom input modes, content transforms (render LaTeX as images, Mermaid as diagrams), themes, slash commands, or replace the agent backend entirely. The built-in TUI renderer is itself just an extension.
|
|
42
50
|
|
|
43
51
|
**Embeddable as a library.** The core is a headless kernel — `import { createCore } from "agent-sh"` to build WebSocket servers, REST APIs, Electron apps, or test harnesses. No terminal required.
|
|
44
52
|
|
|
45
|
-
## Slash Commands
|
|
46
|
-
|
|
47
|
-
| Command | Description |
|
|
48
|
-
|---|---|
|
|
49
|
-
| `/help` | Show available commands |
|
|
50
|
-
| `/model [name]` | Cycle to the next model, or switch to a specific one |
|
|
51
|
-
| `/backend [name]` | List backends, or switch to a named backend |
|
|
52
|
-
| `/compact` | Compact conversation (free up context space) |
|
|
53
|
-
| `/context` | Show context budget usage |
|
|
54
|
-
| `/thinking [level]` | Set reasoning effort (off, low, medium, high) |
|
|
55
|
-
|
|
56
|
-
## Configuration
|
|
57
|
-
|
|
58
|
-
Configure via `~/.agent-sh/settings.json`. See the [Usage Guide](docs/usage.md#configuration) for the full settings reference.
|
|
59
|
-
|
|
60
53
|
## Documentation
|
|
61
54
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
Start with **Usage** to get running, then **Architecture** for the mental model.
|
|
56
|
+
|
|
57
|
+
1. [Usage Guide](docs/usage.md) — install, run, configure providers and models
|
|
58
|
+
2. [Architecture](docs/architecture.md) — pure kernel + extensions, the shell ↔ agent boundary
|
|
59
|
+
3. [The Built-in Agent: ash](docs/agent.md) — query flow, tools, system prompt, model switching
|
|
60
|
+
4. [Context Management](docs/context-management.md) — shell-output spill, three-tier conversation compaction, recall APIs
|
|
61
|
+
5. [Extensions](docs/extensions.md) — event bus, content transforms, custom agent backends, theming
|
|
62
|
+
6. [TUI Composition](docs/tui-composition.md) — compositor, render surfaces, stream routing
|
|
63
|
+
7. [Library Usage](docs/library.md) — embedding agent-sh in your own apps
|
|
64
|
+
8. [Troubleshooting](docs/troubleshooting.md) — common errors and debug mode
|
|
70
65
|
|
|
71
66
|
## Development
|
|
72
67
|
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Subscribes to bus events in constructor:
|
|
5
5
|
* - agent:submit → run query through LLM tool loop
|
|
6
6
|
* - agent:cancel-request → abort current loop
|
|
7
|
-
* - config:cycle → cycle through modes
|
|
8
7
|
*
|
|
9
8
|
* Emits bus events during execution:
|
|
10
9
|
* - agent:query, agent:processing-start/done, agent:response-chunk/done
|
|
@@ -27,6 +26,8 @@ export interface AgentLoopConfig {
|
|
|
27
26
|
modes?: AgentMode[];
|
|
28
27
|
initialModeIndex?: number;
|
|
29
28
|
compositor?: Compositor;
|
|
29
|
+
/** Instance ID from core — ensures history entries match the ID in prompts. */
|
|
30
|
+
instanceId?: string;
|
|
30
31
|
}
|
|
31
32
|
export declare class AgentLoop implements AgentBackend {
|
|
32
33
|
private abortController;
|
|
@@ -34,13 +35,24 @@ export declare class AgentLoop implements AgentBackend {
|
|
|
34
35
|
private historyFile;
|
|
35
36
|
private conversation;
|
|
36
37
|
private fileReadCache;
|
|
37
|
-
private tokenBudget;
|
|
38
38
|
private modes;
|
|
39
39
|
private currentModeIndex;
|
|
40
40
|
private boundListeners;
|
|
41
41
|
private ctorListeners;
|
|
42
42
|
private ctorPipeListeners;
|
|
43
43
|
private lastProjectSkillNames;
|
|
44
|
+
private sessionStartTime;
|
|
45
|
+
private toolCallCounts;
|
|
46
|
+
private totalToolCalls;
|
|
47
|
+
private totalToolErrors;
|
|
48
|
+
private totalResolutions;
|
|
49
|
+
private compactionCount;
|
|
50
|
+
private cumulativeCompactedTokens;
|
|
51
|
+
private peakConversationTokens;
|
|
52
|
+
private queryCount;
|
|
53
|
+
private totalLoopIterations;
|
|
54
|
+
private lastErrorByTool;
|
|
55
|
+
private lastErrorByFile;
|
|
44
56
|
private static readonly THINKING_LEVELS;
|
|
45
57
|
private bus;
|
|
46
58
|
private contextManager;
|
|
@@ -49,6 +61,8 @@ export declare class AgentLoop implements AgentBackend {
|
|
|
49
61
|
private thinkingLevel;
|
|
50
62
|
private compositor;
|
|
51
63
|
private toolProtocol;
|
|
64
|
+
private instanceId;
|
|
65
|
+
private lastShellSeq;
|
|
52
66
|
constructor(config: AgentLoopConfig);
|
|
53
67
|
/** Subscribe to bus events — activates this backend. */
|
|
54
68
|
wire(): void;
|
|
@@ -60,20 +74,42 @@ export declare class AgentLoop implements AgentBackend {
|
|
|
60
74
|
unregisterTool(name: string): void;
|
|
61
75
|
/** Get all registered tools. */
|
|
62
76
|
getTools(): ToolDefinition[];
|
|
77
|
+
/** Instructions keyed by name, with extension attribution. */
|
|
63
78
|
private instructions;
|
|
79
|
+
/** Skills keyed by name, with extension attribution. */
|
|
80
|
+
private skills;
|
|
81
|
+
/** Tool → extension name attribution. */
|
|
82
|
+
private toolExtensions;
|
|
64
83
|
/** Register a named instruction block for the system prompt. */
|
|
65
|
-
registerInstruction(name: string, text: string): void;
|
|
84
|
+
registerInstruction(name: string, text: string, extensionName: string): void;
|
|
66
85
|
/** Remove a named instruction block. */
|
|
67
86
|
removeInstruction(name: string): void;
|
|
68
|
-
/**
|
|
69
|
-
|
|
87
|
+
/** Register a named skill (on-demand reference material). */
|
|
88
|
+
registerSkill(name: string, description: string, filePath: string, extensionName: string): void;
|
|
89
|
+
/** Remove a registered skill. */
|
|
90
|
+
removeSkill(name: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Build the system prompt grouped by extension.
|
|
93
|
+
*
|
|
94
|
+
* Each extension gets a unified block:
|
|
95
|
+
* ## extension-name
|
|
96
|
+
* ### Tools
|
|
97
|
+
* ### Skills
|
|
98
|
+
* ### Instructions
|
|
99
|
+
*/
|
|
100
|
+
buildExtensionSections(): string[];
|
|
70
101
|
kill(): void;
|
|
71
102
|
private cancel;
|
|
72
103
|
/** Check if reasoning_effort should be sent for the current model/provider. */
|
|
73
104
|
private shouldSendReasoningEffort;
|
|
74
|
-
private cycleMode;
|
|
75
105
|
private get currentMode();
|
|
76
106
|
private get currentModel();
|
|
107
|
+
/**
|
|
108
|
+
* Run compaction via the `conversation:compact` handler. After any
|
|
109
|
+
* compaction, emit `conversation:after-compact` so listeners
|
|
110
|
+
* (metrics, UI, agent-awareness notes) can react.
|
|
111
|
+
*/
|
|
112
|
+
private compactWithHooks;
|
|
77
113
|
private isContextOverflow;
|
|
78
114
|
/** Check if an error is retryable (transient). */
|
|
79
115
|
private isRetryable;
|
|
@@ -94,6 +130,7 @@ export declare class AgentLoop implements AgentBackend {
|
|
|
94
130
|
*/
|
|
95
131
|
private executeLoop;
|
|
96
132
|
private readonly maxRetries;
|
|
133
|
+
private filePathFromArgs;
|
|
97
134
|
/**
|
|
98
135
|
* Stream with retry logic. Handles:
|
|
99
136
|
* - Context overflow → compact and retry
|