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
|
@@ -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 {
|
|
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
|
-
|
|
36
|
+
readonly instanceId: string;
|
|
37
|
+
private readonly handlers;
|
|
9
38
|
private nextSeq;
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
*
|
|
37
|
-
*
|
|
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
|
-
|
|
87
|
+
compact(maxPromptTokens: number, recentTurnsToKeep?: number, force?: boolean): CompactResult | null;
|
|
40
88
|
/**
|
|
41
|
-
* Inject prior session history
|
|
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
|
}
|