agent-sh 0.9.0 → 0.10.0

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 (78) hide show
  1. package/README.md +14 -21
  2. package/dist/agent/agent-loop.d.ts +43 -3
  3. package/dist/agent/agent-loop.js +811 -128
  4. package/dist/agent/conversation-state.d.ts +72 -21
  5. package/dist/agent/conversation-state.js +357 -150
  6. package/dist/agent/history-file.d.ts +13 -4
  7. package/dist/agent/history-file.js +110 -36
  8. package/dist/agent/nuclear-form.d.ts +28 -3
  9. package/dist/agent/nuclear-form.js +84 -3
  10. package/dist/agent/skills.d.ts +2 -4
  11. package/dist/agent/skills.js +10 -4
  12. package/dist/agent/subagent.d.ts +23 -0
  13. package/dist/agent/subagent.js +53 -11
  14. package/dist/agent/system-prompt.d.ts +34 -1
  15. package/dist/agent/system-prompt.js +96 -47
  16. package/dist/agent/token-budget.d.ts +5 -4
  17. package/dist/agent/token-budget.js +14 -19
  18. package/dist/agent/tool-protocol.d.ts +23 -1
  19. package/dist/agent/tool-protocol.js +169 -4
  20. package/dist/agent/tools/bash.js +3 -3
  21. package/dist/agent/tools/edit-file.js +9 -6
  22. package/dist/agent/tools/glob.js +4 -2
  23. package/dist/agent/tools/grep.js +27 -3
  24. package/dist/agent/tools/ls.js +5 -6
  25. package/dist/agent/types.d.ts +1 -1
  26. package/dist/context-manager.d.ts +17 -0
  27. package/dist/context-manager.js +37 -4
  28. package/dist/core.js +27 -6
  29. package/dist/event-bus.d.ts +59 -2
  30. package/dist/executor.d.ts +4 -3
  31. package/dist/executor.js +18 -15
  32. package/dist/extension-loader.js +50 -13
  33. package/dist/extensions/agent-backend.d.ts +8 -7
  34. package/dist/extensions/agent-backend.js +69 -48
  35. package/dist/extensions/index.js +0 -1
  36. package/dist/extensions/slash-commands.js +14 -9
  37. package/dist/extensions/tui-renderer.js +62 -78
  38. package/dist/index.js +25 -6
  39. package/dist/settings.d.ts +36 -5
  40. package/dist/settings.js +53 -9
  41. package/dist/shell/input-handler.d.ts +2 -1
  42. package/dist/shell/input-handler.js +82 -73
  43. package/dist/shell/shell.js +19 -2
  44. package/dist/types.d.ts +12 -0
  45. package/dist/utils/ansi.d.ts +5 -0
  46. package/dist/utils/ansi.js +1 -1
  47. package/dist/utils/compositor.d.ts +5 -0
  48. package/dist/utils/compositor.js +31 -3
  49. package/dist/utils/diff-renderer.d.ts +9 -0
  50. package/dist/utils/diff-renderer.js +221 -143
  51. package/dist/utils/diff.d.ts +21 -2
  52. package/dist/utils/diff.js +165 -89
  53. package/dist/utils/handler-registry.d.ts +5 -0
  54. package/dist/utils/handler-registry.js +6 -0
  55. package/dist/utils/line-editor.d.ts +11 -1
  56. package/dist/utils/line-editor.js +44 -5
  57. package/dist/utils/tool-display.d.ts +1 -1
  58. package/dist/utils/tool-display.js +4 -4
  59. package/examples/extensions/ash-acp-bridge/src/index.ts +4 -1
  60. package/examples/extensions/ash-mcp-bridge/index.ts +13 -3
  61. package/examples/extensions/claude-code-bridge/index.ts +198 -51
  62. package/examples/extensions/claude-code-bridge/package.json +1 -0
  63. package/examples/extensions/interactive-prompts.ts +39 -25
  64. package/examples/extensions/overlay-agent.ts +3 -3
  65. package/examples/extensions/peer-mesh.ts +115 -0
  66. package/examples/extensions/pi-bridge/index.ts +2 -2
  67. package/examples/extensions/questionnaire.ts +16 -5
  68. package/examples/extensions/subagents.ts +19 -4
  69. package/examples/extensions/terminal-buffer.ts +163 -0
  70. package/examples/extensions/user-shell.ts +136 -0
  71. package/examples/extensions/web-access.ts +8 -0
  72. package/package.json +36 -2
  73. package/dist/agent/tools/display.d.ts +0 -13
  74. package/dist/agent/tools/display.js +0 -70
  75. package/dist/agent/tools/user-shell.d.ts +0 -13
  76. package/dist/agent/tools/user-shell.js +0 -87
  77. package/dist/extensions/terminal-buffer.d.ts +0 -14
  78. 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
  [![npm version](https://img.shields.io/npm/v/agent-sh.svg)](https://www.npmjs.com/package/agent-sh)
6
6
  [![license](https://img.shields.io/npm/l/agent-sh.svg)](https://github.com/guanyilun/agent-sh/blob/main/LICENSE)
7
7
 
8
+ ![demo](assets/demo.gif)
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 # real shell command
14
- ~ $ cd ../tests && npm test # real cd, env, aliases — all just work
15
- ~ $ vim file.ts # opens vim in the same PTY
16
- ~ $ > explain the last error # agent investigates using its own tools
17
- ~ $ > deploy to staging # agent runs it in your live shell
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,7 +40,7 @@ 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, three tool categories.** Type `>` and agent-sh figures out how to help. Scratchpad tools (`bash`, `read_file`, `grep`, `glob`) for investigation. `display` to show you output. `user_shell` for commands with lasting effects in your live shell. No modes to pick — the agent reasons about which tools to use based on your intent.
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
 
@@ -42,21 +50,6 @@ Requires Node.js 18+.
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
55
  - [Usage Guide](docs/usage.md) — providers, models, configuration
@@ -27,6 +27,8 @@ export interface AgentLoopConfig {
27
27
  modes?: AgentMode[];
28
28
  initialModeIndex?: number;
29
29
  compositor?: Compositor;
30
+ /** Instance ID from core — ensures history entries match the ID in prompts. */
31
+ instanceId?: string;
30
32
  }
31
33
  export declare class AgentLoop implements AgentBackend {
32
34
  private abortController;
@@ -41,6 +43,18 @@ export declare class AgentLoop implements AgentBackend {
41
43
  private ctorListeners;
42
44
  private ctorPipeListeners;
43
45
  private lastProjectSkillNames;
46
+ private sessionStartTime;
47
+ private toolCallCounts;
48
+ private totalToolCalls;
49
+ private totalToolErrors;
50
+ private totalResolutions;
51
+ private compactionCount;
52
+ private cumulativeCompactedTokens;
53
+ private peakConversationTokens;
54
+ private queryCount;
55
+ private totalLoopIterations;
56
+ private lastErrorByTool;
57
+ private lastErrorByFile;
44
58
  private static readonly THINKING_LEVELS;
45
59
  private bus;
46
60
  private contextManager;
@@ -49,6 +63,8 @@ export declare class AgentLoop implements AgentBackend {
49
63
  private thinkingLevel;
50
64
  private compositor;
51
65
  private toolProtocol;
66
+ private instanceId;
67
+ private lastShellSeq;
52
68
  constructor(config: AgentLoopConfig);
53
69
  /** Subscribe to bus events — activates this backend. */
54
70
  wire(): void;
@@ -60,13 +76,30 @@ export declare class AgentLoop implements AgentBackend {
60
76
  unregisterTool(name: string): void;
61
77
  /** Get all registered tools. */
62
78
  getTools(): ToolDefinition[];
79
+ /** Instructions keyed by name, with extension attribution. */
63
80
  private instructions;
81
+ /** Skills keyed by name, with extension attribution. */
82
+ private skills;
83
+ /** Tool → extension name attribution. */
84
+ private toolExtensions;
64
85
  /** Register a named instruction block for the system prompt. */
65
- registerInstruction(name: string, text: string): void;
86
+ registerInstruction(name: string, text: string, extensionName: string): void;
66
87
  /** Remove a named instruction block. */
67
88
  removeInstruction(name: string): void;
68
- /** Get instruction blocks registered by extensions. */
69
- getInstructionSections(): string[];
89
+ /** Register a named skill (on-demand reference material). */
90
+ registerSkill(name: string, description: string, filePath: string, extensionName: string): void;
91
+ /** Remove a registered skill. */
92
+ removeSkill(name: string): void;
93
+ /**
94
+ * Build the system prompt grouped by extension.
95
+ *
96
+ * Each extension gets a unified block:
97
+ * ## extension-name
98
+ * ### Tools
99
+ * ### Skills
100
+ * ### Instructions
101
+ */
102
+ buildExtensionSections(): string[];
70
103
  kill(): void;
71
104
  private cancel;
72
105
  /** Check if reasoning_effort should be sent for the current model/provider. */
@@ -74,6 +107,12 @@ export declare class AgentLoop implements AgentBackend {
74
107
  private cycleMode;
75
108
  private get currentMode();
76
109
  private get currentModel();
110
+ /**
111
+ * Run compaction via the `conversation:compact` handler. After any
112
+ * compaction, emit `conversation:after-compact` so listeners
113
+ * (metrics, UI, agent-awareness notes) can react.
114
+ */
115
+ private compactWithHooks;
77
116
  private isContextOverflow;
78
117
  /** Check if an error is retryable (transient). */
79
118
  private isRetryable;
@@ -94,6 +133,7 @@ export declare class AgentLoop implements AgentBackend {
94
133
  */
95
134
  private executeLoop;
96
135
  private readonly maxRetries;
136
+ private filePathFromArgs;
97
137
  /**
98
138
  * Stream with retry logic. Handles:
99
139
  * - Context overflow → compact and retry