agent-sh 0.15.0 → 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 (116) hide show
  1. package/docs/README.md +14 -0
  2. package/docs/agent.md +398 -0
  3. package/docs/architecture.md +196 -0
  4. package/docs/context-management.md +200 -0
  5. package/docs/extensions.md +951 -0
  6. package/docs/library.md +84 -0
  7. package/docs/troubleshooting.md +65 -0
  8. package/docs/tui-composition.md +294 -0
  9. package/docs/usage.md +306 -0
  10. package/examples/extensions/ash-scheme/package.json +1 -1
  11. package/examples/extensions/ashi/EXTENDING.md +2 -2
  12. package/examples/extensions/ashi/README.md +2 -2
  13. package/examples/extensions/ashi/docs/ui-surface-protocol.md +1 -1
  14. package/examples/extensions/ashi/package.json +5 -3
  15. package/examples/extensions/ashi/src/cli.ts +6 -5
  16. package/examples/extensions/ashi/src/renderer.ts +22 -2
  17. package/examples/extensions/ashi/src/renderers/pi-tui/tool-group.ts +5 -8
  18. package/examples/extensions/ashi-ink/package.json +2 -2
  19. package/examples/extensions/claude-code-bridge/package.json +1 -1
  20. package/examples/extensions/opencode-bridge/package.json +1 -1
  21. package/package.json +3 -1
  22. package/src/agent/agent-loop.ts +1563 -0
  23. package/src/agent/entry-format.ts +19 -0
  24. package/src/agent/events.ts +151 -0
  25. package/src/agent/extensions/rolling-history/constants.ts +1 -0
  26. package/src/agent/extensions/rolling-history/index.ts +202 -0
  27. package/src/agent/extensions/rolling-history/recall.ts +131 -0
  28. package/src/agent/extensions/rolling-history/strategy.ts +404 -0
  29. package/src/agent/host-types.ts +192 -0
  30. package/src/agent/index.ts +591 -0
  31. package/src/agent/live-view.ts +279 -0
  32. package/src/agent/llm-client.ts +111 -0
  33. package/src/agent/llm-facade.ts +43 -0
  34. package/src/agent/normalize-args.ts +61 -0
  35. package/src/agent/nuclear-form.ts +382 -0
  36. package/src/agent/providers/deepseek.ts +39 -0
  37. package/src/agent/providers/ollama.ts +92 -0
  38. package/src/agent/providers/openai-compatible.ts +36 -0
  39. package/src/agent/providers/openai.ts +52 -0
  40. package/src/agent/providers/opencode.ts +142 -0
  41. package/src/agent/providers/openrouter.ts +105 -0
  42. package/src/agent/providers/zai-coding-plan.ts +33 -0
  43. package/src/agent/session-store.ts +336 -0
  44. package/src/agent/skills.ts +228 -0
  45. package/src/agent/store.ts +310 -0
  46. package/src/agent/subagent.ts +305 -0
  47. package/src/agent/system-prompt.ts +151 -0
  48. package/src/agent/token-budget.ts +12 -0
  49. package/src/agent/tool-protocol.ts +722 -0
  50. package/src/agent/tool-registry.ts +66 -0
  51. package/src/agent/tools/bash.ts +95 -0
  52. package/src/agent/tools/edit-file.ts +154 -0
  53. package/src/agent/tools/expand-home.ts +7 -0
  54. package/src/agent/tools/glob.ts +108 -0
  55. package/src/agent/tools/grep.ts +228 -0
  56. package/src/agent/tools/list-skills.ts +37 -0
  57. package/src/agent/tools/ls.ts +81 -0
  58. package/src/agent/tools/pwsh.ts +140 -0
  59. package/src/agent/tools/read-file.ts +164 -0
  60. package/src/agent/tools/write-file.ts +72 -0
  61. package/src/agent/types.ts +149 -0
  62. package/src/cli/args.ts +91 -0
  63. package/src/cli/auth/cli.ts +244 -0
  64. package/src/cli/auth/discover.ts +52 -0
  65. package/src/cli/auth/keys.ts +143 -0
  66. package/src/cli/index.ts +295 -0
  67. package/src/cli/init.ts +74 -0
  68. package/src/cli/install.ts +439 -0
  69. package/src/cli/shell-env.ts +68 -0
  70. package/src/cli/subcommands.ts +24 -0
  71. package/src/core/event-bus.ts +252 -0
  72. package/src/core/extension-loader.ts +347 -0
  73. package/src/core/index.ts +152 -0
  74. package/src/core/settings.ts +398 -0
  75. package/src/core/types.ts +61 -0
  76. package/src/extensions/file-autocomplete.ts +71 -0
  77. package/src/extensions/index.ts +38 -0
  78. package/src/extensions/slash-commands/events.ts +14 -0
  79. package/src/extensions/slash-commands/index.ts +269 -0
  80. package/src/shell/events.ts +73 -0
  81. package/src/shell/host-types.ts +150 -0
  82. package/src/shell/index.ts +159 -0
  83. package/src/shell/input-handler.ts +505 -0
  84. package/src/shell/output-parser.ts +156 -0
  85. package/src/shell/shell-context.ts +193 -0
  86. package/src/shell/shell.ts +414 -0
  87. package/src/shell/strategies/bash.ts +83 -0
  88. package/src/shell/strategies/fish.ts +77 -0
  89. package/src/shell/strategies/index.ts +24 -0
  90. package/src/shell/strategies/types.ts +64 -0
  91. package/src/shell/strategies/zsh.ts +92 -0
  92. package/src/shell/terminal.ts +124 -0
  93. package/src/shell/tui-input-view.ts +222 -0
  94. package/src/shell/tui-renderer.ts +1126 -0
  95. package/src/utils/ansi.ts +140 -0
  96. package/src/utils/box-frame.ts +138 -0
  97. package/src/utils/compositor.ts +157 -0
  98. package/src/utils/diff-renderer.ts +829 -0
  99. package/src/utils/diff.ts +244 -0
  100. package/src/utils/executor.ts +305 -0
  101. package/src/utils/file-watcher.ts +110 -0
  102. package/src/utils/floating-panel.ts +1160 -0
  103. package/src/utils/handler-registry.ts +110 -0
  104. package/src/utils/line-editor.ts +636 -0
  105. package/src/utils/markdown.ts +437 -0
  106. package/src/utils/message-utils.ts +113 -0
  107. package/src/utils/package-version.ts +12 -0
  108. package/src/utils/palette.ts +64 -0
  109. package/src/utils/ref-counter.ts +9 -0
  110. package/src/utils/ripgrep-path.ts +17 -0
  111. package/src/utils/shell-output-spill.ts +76 -0
  112. package/src/utils/stream-transform.ts +292 -0
  113. package/src/utils/terminal-buffer.ts +213 -0
  114. package/src/utils/tool-display.ts +315 -0
  115. package/src/utils/tool-interactive.ts +71 -0
  116. package/src/utils/tty.ts +14 -0
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Named handler registry with Emacs-style advice.
3
+ *
4
+ * Built-in extensions register named handlers with `define`.
5
+ * User extensions wrap them with `advise` — each advisor receives
6
+ * `next` (the previous handler) and decides whether to call it.
7
+ *
8
+ * registry.define("render:code-block", (lang, code) => highlight(lang, code));
9
+ *
10
+ * registry.advise("render:code-block", (next, lang, code) => {
11
+ * if (lang === "latex") return renderLatex(code);
12
+ * return next(lang, code); // call original
13
+ * });
14
+ *
15
+ * Internally, each handler is stored as a base function plus an ordered
16
+ * list of advisors. `call` builds the chain on invocation, so advisors
17
+ * can be added or removed at any time without closure entanglement.
18
+ */
19
+
20
+ /* eslint-disable @typescript-eslint/no-explicit-any */
21
+
22
+ type HandlerFn = (...args: any[]) => any;
23
+ type Advisor = (next: HandlerFn, ...args: any[]) => any;
24
+
25
+ interface HandlerEntry {
26
+ base: HandlerFn;
27
+ advisors: Advisor[];
28
+ }
29
+
30
+ /** The subset of HandlerRegistry methods available to extensions. */
31
+ export interface HandlerFunctions {
32
+ define(name: string, fn: (...args: any[]) => any): void;
33
+ advise(name: string, advisor: (next: (...args: any[]) => any, ...args: any[]) => any): () => void;
34
+ call(name: string, ...args: any[]): any;
35
+ list(): string[];
36
+ }
37
+
38
+ export class HandlerRegistry {
39
+ private entries = new Map<string, HandlerEntry>();
40
+
41
+ /**
42
+ * Register a named handler. If one already exists, its base is replaced
43
+ * but existing advisors are preserved.
44
+ */
45
+ define(name: string, fn: HandlerFn): void {
46
+ const existing = this.entries.get(name);
47
+ if (existing) {
48
+ existing.base = fn;
49
+ } else {
50
+ this.entries.set(name, { base: fn, advisors: [] });
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Add an advisor to a named handler. The advisor receives `next`
56
+ * (the rest of the chain) and all original arguments.
57
+ *
58
+ * - Call `next(...args)` to invoke the rest of the chain
59
+ * - Don't call `next` to replace entirely (override)
60
+ * - Call `next` conditionally to wrap (around)
61
+ *
62
+ * Advisors run outermost-first (last added = outermost).
63
+ * Returns an unadvise function that cleanly removes this advisor.
64
+ */
65
+ advise(name: string, advisor: Advisor): () => void {
66
+ let entry = this.entries.get(name);
67
+ if (!entry) {
68
+ entry = { base: (() => undefined) as any, advisors: [] };
69
+ this.entries.set(name, entry);
70
+ }
71
+ entry.advisors.push(advisor);
72
+
73
+ let removed = false;
74
+ return () => {
75
+ if (removed) return;
76
+ removed = true;
77
+ const e = this.entries.get(name);
78
+ if (!e) return;
79
+ const idx = e.advisors.indexOf(advisor);
80
+ if (idx !== -1) e.advisors.splice(idx, 1);
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Call a named handler. Builds the advisor chain on each call:
86
+ * outermost advisor wraps the next, down to the base handler.
87
+ * Returns undefined if no handler is registered.
88
+ */
89
+ call(name: string, ...args: any[]): any {
90
+ const entry = this.entries.get(name);
91
+ if (!entry) return undefined;
92
+
93
+ // Build chain: base ← advisor[0] ← advisor[1] ← ... ← advisor[n-1]
94
+ let fn: HandlerFn = entry.base;
95
+ for (const advisor of entry.advisors) {
96
+ const next = fn;
97
+ fn = (...a: any[]) => advisor(next, ...a);
98
+ }
99
+ return fn(...args);
100
+ }
101
+
102
+ has(name: string): boolean {
103
+ return this.entries.has(name);
104
+ }
105
+
106
+ /** Names of all registered handlers — for diagnostics/introspection. */
107
+ list(): string[] {
108
+ return [...this.entries.keys()];
109
+ }
110
+ }