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.
Files changed (88) hide show
  1. package/README.md +25 -30
  2. package/dist/agent/agent-loop.d.ts +43 -6
  3. package/dist/agent/agent-loop.js +817 -157
  4. package/dist/agent/conversation-state.d.ts +72 -21
  5. package/dist/agent/conversation-state.js +364 -151
  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 +10 -13
  17. package/dist/agent/token-budget.js +6 -46
  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 -2
  26. package/dist/context-manager.d.ts +16 -19
  27. package/dist/context-manager.js +48 -152
  28. package/dist/core.js +27 -6
  29. package/dist/event-bus.d.ts +59 -3
  30. package/dist/executor.d.ts +4 -3
  31. package/dist/executor.js +18 -15
  32. package/dist/extension-loader.js +75 -17
  33. package/dist/extensions/agent-backend.d.ts +8 -7
  34. package/dist/extensions/agent-backend.js +72 -50
  35. package/dist/extensions/index.js +0 -2
  36. package/dist/extensions/slash-commands.js +14 -9
  37. package/dist/extensions/tui-renderer.js +67 -80
  38. package/dist/index.js +25 -6
  39. package/dist/settings.d.ts +39 -16
  40. package/dist/settings.js +51 -11
  41. package/dist/shell/input-handler.d.ts +2 -1
  42. package/dist/shell/input-handler.js +84 -76
  43. package/dist/shell/shell.js +19 -2
  44. package/dist/types.d.ts +15 -0
  45. package/dist/utils/ansi.d.ts +7 -0
  46. package/dist/utils/ansi.js +69 -8
  47. package/dist/utils/box-frame.js +8 -2
  48. package/dist/utils/compositor.d.ts +5 -0
  49. package/dist/utils/compositor.js +31 -3
  50. package/dist/utils/diff-renderer.d.ts +9 -0
  51. package/dist/utils/diff-renderer.js +221 -143
  52. package/dist/utils/diff.d.ts +21 -2
  53. package/dist/utils/diff.js +165 -89
  54. package/dist/utils/handler-registry.d.ts +5 -0
  55. package/dist/utils/handler-registry.js +6 -0
  56. package/dist/utils/line-editor.d.ts +11 -1
  57. package/dist/utils/line-editor.js +44 -5
  58. package/dist/utils/markdown.js +23 -8
  59. package/dist/utils/package-version.d.ts +1 -0
  60. package/dist/utils/package-version.js +10 -0
  61. package/dist/utils/shell-output-spill.d.ts +2 -0
  62. package/dist/utils/shell-output-spill.js +81 -0
  63. package/dist/utils/tool-display.d.ts +1 -1
  64. package/dist/utils/tool-display.js +4 -4
  65. package/examples/extensions/ash-acp-bridge/src/index.ts +4 -1
  66. package/examples/extensions/ash-mcp-bridge/index.ts +13 -3
  67. package/examples/extensions/claude-code-bridge/README.md +14 -0
  68. package/examples/extensions/claude-code-bridge/index.ts +204 -145
  69. package/examples/extensions/claude-code-bridge/package.json +1 -0
  70. package/examples/extensions/interactive-prompts.ts +39 -25
  71. package/examples/extensions/overlay-agent.ts +3 -3
  72. package/examples/extensions/peer-mesh.ts +115 -0
  73. package/examples/extensions/pi-bridge/README.md +16 -0
  74. package/examples/extensions/pi-bridge/index.ts +9 -155
  75. package/examples/extensions/questionnaire.ts +16 -5
  76. package/examples/extensions/subagents.ts +19 -4
  77. package/examples/extensions/terminal-buffer.ts +163 -0
  78. package/examples/extensions/user-shell.ts +136 -0
  79. package/examples/extensions/web-access.ts +8 -0
  80. package/package.json +36 -2
  81. package/dist/agent/tools/display.d.ts +0 -13
  82. package/dist/agent/tools/display.js +0 -70
  83. package/dist/agent/tools/user-shell.d.ts +0 -13
  84. package/dist/agent/tools/user-shell.js +0 -87
  85. package/dist/extensions/shell-recall.d.ts +0 -9
  86. package/dist/extensions/shell-recall.js +0 -8
  87. package/dist/extensions/terminal-buffer.d.ts +0 -14
  88. package/dist/extensions/terminal-buffer.js +0 -134
@@ -1,14 +1,47 @@
1
1
  import type { ChatCompletionMessageParam } from "../utils/llm-client.js";
2
2
  import { type NuclearEntry } from "./nuclear-form.js";
3
- import type { HistoryFile } from "./history-file.js";
3
+ import type { HandlerFunctions } from "../utils/handler-registry.js";
4
+ /** Search hit shape returned by the `history:search` handler. */
5
+ export interface HistoryHit {
6
+ entry: NuclearEntry;
7
+ line: string;
8
+ }
9
+ export interface CompactResult {
10
+ before: number;
11
+ after: number;
12
+ evictedCount: number;
13
+ [extra: string]: unknown;
14
+ }
15
+ /**
16
+ * Conversation state with eager nucleation — shell-history shaped.
17
+ *
18
+ * Every add nucleates into a one-line NuclearEntry and flushes to disk.
19
+ * Compaction evicts turns, replacing them with their nuclear one-liners
20
+ * in context; the originals stay searchable via `conversation_recall`
21
+ * and survive restarts in `~/.agent-sh/history`.
22
+ *
23
+ * Nucleation and history I/O go through advisable handlers — extensions
24
+ * swap strategies without touching this class. When no handlers are
25
+ * provided (subagents, tests), both become no-ops and this becomes a
26
+ * plain message buffer.
27
+ */
4
28
  export declare class ConversationState {
5
29
  private messages;
30
+ private messagesDirty;
31
+ private cachedMessagesJson;
32
+ private toolErrors;
6
33
  private nuclearEntries;
34
+ private nuclearBySeq;
7
35
  private recallArchive;
8
- private historyFile;
36
+ readonly instanceId: string;
37
+ private readonly handlers;
9
38
  private nextSeq;
10
- constructor(historyFile?: HistoryFile);
11
- get instanceId(): string;
39
+ private lastApiTokenCount;
40
+ private lastApiMessageCount;
41
+ constructor(handlers?: HandlerFunctions, instanceId?: string);
42
+ /** Get JSON.stringify of messages, cached until next mutation. */
43
+ private getMessagesJson;
44
+ private invalidateMessagesCache;
12
45
  addUserMessage(text: string): void;
13
46
  addAssistantMessage(content: string | null, toolCalls?: {
14
47
  id: string;
@@ -17,43 +50,61 @@ export declare class ConversationState {
17
50
  arguments: string;
18
51
  };
19
52
  }[]): void;
20
- addToolResult(toolCallId: string, content: string): void;
53
+ addToolResult(toolCallId: string, content: string, isError?: boolean): void;
21
54
  /** Add tool results as a user message (for inline tool protocol). */
22
55
  addToolResultInline(content: string): void;
23
56
  addSystemNote(text: string): void;
24
57
  getMessages(): ChatCompletionMessageParam[];
25
- estimateTokens(): number;
26
58
  /**
27
- * Priority-based compaction. Evicts lowest-priority turns, replacing
28
- * them with nuclear one-liner summaries that stay in the conversation.
29
- * Read-only tool results are dropped entirely.
59
+ * Replace the messages array wholesale — the write side for custom
60
+ * compaction strategies. Invalidates API token baseline since the
61
+ * new array's token count is unknown.
30
62
  */
31
- compact(targetTokens: number, recentTurnsToKeep?: number, force?: boolean): {
32
- before: number;
33
- after: number;
34
- } | null;
63
+ replaceMessages(messages: ChatCompletionMessageParam[]): void;
64
+ private pruneToolErrors;
65
+ private eagerNucleateUser;
66
+ /** Nucleate an agent text response. Called by agent-loop when the loop finishes without tool calls. */
67
+ eagerNucleateAgent(text: string): void;
68
+ /** Nucleate tool call results. One entry per tool call, enriched with result. */
69
+ eagerNucleateTools(results: Array<{
70
+ toolName: string;
71
+ args: Record<string, unknown>;
72
+ content: string;
73
+ isError: boolean;
74
+ }>): void;
75
+ /** Track an entry in memory (nuclear list + recall archive). */
76
+ private recordNuclearEntry;
77
+ private appendToHistory;
78
+ updateApiTokenCount(promptTokens: number): void;
79
+ estimatePromptTokens(): number;
80
+ estimateTokens(): number;
35
81
  /**
36
- * Flush oldest nuclear entries to the history file when the
37
- * in-context nuclear block grows too large.
82
+ * Two-tier pin compaction: evict lowest-priority turns (replaced by
83
+ * their nuclear one-liners), slim the window before the last verbatim
84
+ * turn, drop read-only tool results entirely. Extensions replace the
85
+ * whole strategy by advising `conversation:compact` and skipping next.
38
86
  */
39
- flush(): Promise<void>;
87
+ compact(maxPromptTokens: number, recentTurnsToKeep?: number, force?: boolean): CompactResult | null;
40
88
  /**
41
- * Inject prior session history from the history file as a context note.
89
+ * Inject prior session history as a context preamble. The preamble
90
+ * layout goes through the `conversation:format-prior-history` handler,
91
+ * so extensions can swap the flat list for grouped/richer rendering.
42
92
  */
43
93
  loadPriorHistory(entries: NuclearEntry[]): void;
44
- /** Search Tier 2 archive + Tier 3 history file. */
45
94
  search(query: string): Promise<string>;
46
- /** Expand full content of a nuclear entry by seq number. */
47
95
  expand(seq: number): Promise<string>;
48
- /** Browse nuclear entries (Tier 2) + recent history (Tier 3). */
49
96
  browse(): Promise<string>;
97
+ getNuclearEntries(): readonly NuclearEntry[];
50
98
  getNuclearEntryCount(): number;
99
+ getNuclearSummary(): string | null;
51
100
  getRecallArchiveSize(): number;
52
101
  clear(): void;
53
102
  private buildNuclearBlock;
103
+ /** Index of the nuclear block in messages[], or -1 if not present. */
104
+ private nuclearBlockIdx;
54
105
  private updateNuclearBlockInMessages;
106
+ private slimTurn;
55
107
  private parseTurns;
56
108
  private inferPriority;
57
- private searchArchive;
58
109
  private turnToText;
59
110
  }