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
@@ -1,134 +0,0 @@
1
- /** Interpret C-style escape sequences (e.g. \r → CR, \x1b → ESC). */
2
- function interpretEscapes(str) {
3
- return str.replace(/\\(x[0-9a-fA-F]{2}|r|n|t|\\|0)/g, (_, seq) => {
4
- if (seq === "r")
5
- return "\r";
6
- if (seq === "n")
7
- return "\n";
8
- if (seq === "t")
9
- return "\t";
10
- if (seq === "\\")
11
- return "\\";
12
- if (seq === "0")
13
- return "\0";
14
- if (seq.startsWith("x"))
15
- return String.fromCharCode(parseInt(seq.slice(1), 16));
16
- return seq;
17
- });
18
- }
19
- function settle(ms = 100) {
20
- return new Promise((resolve) => setTimeout(resolve, ms));
21
- }
22
- export default function activate(ctx) {
23
- const { bus, terminalBuffer: tb, registerTool, registerInstruction } = ctx;
24
- if (!tb)
25
- return; // @xterm/headless not installed
26
- registerTool({
27
- name: "terminal_read",
28
- description: "Read what is currently visible on the user's terminal screen. Returns clean text (ANSI stripped) " +
29
- "with cursor position and whether an alternate-screen program (vim, htop, less) is active. " +
30
- "Use this to observe what the user sees — helpful for answering questions about terminal output, " +
31
- "diagnosing errors on screen, or checking state before/after sending keystrokes with terminal_keys.",
32
- input_schema: {
33
- type: "object",
34
- properties: {
35
- include_scrollback: {
36
- type: "boolean",
37
- description: "If true, include scrollback buffer (content that scrolled off screen) " +
38
- "in addition to the visible viewport. Useful for capturing output from " +
39
- "long-running or streaming commands. Default: false.",
40
- },
41
- },
42
- },
43
- showOutput: true,
44
- getDisplayInfo: () => ({
45
- kind: "read",
46
- icon: "⊞",
47
- locations: [],
48
- }),
49
- async execute(args) {
50
- const includeScrollback = args.include_scrollback ?? false;
51
- const { text, altScreen, cursorX, cursorY } = tb.readScreen({ includeScrollback });
52
- const info = [
53
- altScreen ? "mode: alternate screen" : "mode: normal",
54
- `cursor: row=${cursorY} col=${cursorX}`,
55
- ].join(", ");
56
- return {
57
- content: `[${info}]\n\n${text}`,
58
- exitCode: 0,
59
- isError: false,
60
- };
61
- },
62
- });
63
- registerTool({
64
- name: "terminal_keys",
65
- description: "Send keystrokes directly into the user's live terminal PTY, as if the user typed them. " +
66
- "Use this to interact with programs already running in the terminal (vim, htop, less, ssh, REPLs, etc.) " +
67
- "or to type commands at the shell prompt. Do NOT use user_shell for this — user_shell runs a new " +
68
- "command in a subshell, while terminal_keys types into whatever is currently on screen.\n\n" +
69
- "Escape sequences for special keys:\n" +
70
- " - Escape: \\x1b\n" +
71
- " - Enter/Return: \\r\n" +
72
- " - Tab: \\t\n" +
73
- " - Ctrl+C: \\x03\n" +
74
- " - Ctrl+D: \\x04\n" +
75
- " - Ctrl+Z: \\x1a\n" +
76
- " - Arrow keys: \\x1b[A (up), \\x1b[B (down), \\x1b[C (right), \\x1b[D (left)\n" +
77
- " - Backspace: \\x7f\n\n" +
78
- "Example: to quit vim without saving, send keys=\"\\x1b:q!\\r\" (Escape, :q!, Enter).\n" +
79
- "Always call terminal_read after sending keys to verify the result.",
80
- input_schema: {
81
- type: "object",
82
- properties: {
83
- keys: {
84
- type: "string",
85
- description: "The keystrokes to send. Use \\x1b for Escape, \\r for Enter, \\t for Tab, " +
86
- "\\x03 for Ctrl+C, etc. Regular characters are sent as-is.",
87
- },
88
- settle_ms: {
89
- type: "number",
90
- description: "Milliseconds to wait after sending keys for the terminal to settle before " +
91
- "returning (default: 150). Increase for slow programs.",
92
- },
93
- },
94
- required: ["keys"],
95
- },
96
- showOutput: false,
97
- getDisplayInfo: () => ({
98
- kind: "execute",
99
- icon: "⌨",
100
- locations: [],
101
- }),
102
- formatCall: (args) => {
103
- const keys = args.keys;
104
- return keys
105
- .replace(/\\x1b|\x1b/g, "ESC")
106
- .replace(/\\r|\r/g, "⏎")
107
- .replace(/\\n|\n/g, "↵")
108
- .replace(/\\t|\t/g, "TAB")
109
- .replace(/\\x03|\x03/g, "^C")
110
- .replace(/\\x04|\x04/g, "^D")
111
- .replace(/\\x7f|\x7f/g, "BS");
112
- },
113
- async execute(args) {
114
- const raw = args.keys;
115
- const keys = interpretEscapes(raw);
116
- const settleMs = args.settle_ms ?? 150;
117
- bus.emit("shell:stdout-show", {});
118
- process.stdout.write("\n");
119
- bus.emit("shell:pty-write", { data: keys });
120
- await settle(settleMs);
121
- bus.emit("shell:stdout-hide", {});
122
- const { text, altScreen, cursorX, cursorY } = tb.readScreen();
123
- const info = [
124
- altScreen ? "mode: alternate screen" : "mode: normal",
125
- `cursor: row=${cursorY} col=${cursorX}`,
126
- ].join(", ");
127
- return {
128
- content: `Keys sent. Screen after:\n[${info}]\n\n${text}`,
129
- exitCode: 0,
130
- isError: false,
131
- };
132
- },
133
- });
134
- }