@eminent337/aery 0.1.44 → 0.1.53
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/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/compaction.md +18 -18
- package/docs/custom-provider.md +21 -21
- package/docs/extensions.md +104 -102
- package/docs/json.md +5 -5
- package/docs/keybindings.md +3 -3
- package/docs/models.md +2 -2
- package/docs/packages.md +21 -21
- package/docs/prompt-templates.md +1 -1
- package/docs/providers.md +3 -1
- package/docs/rpc.md +1 -1
- package/docs/sdk.md +7 -5
- package/docs/session.md +4 -4
- package/docs/skills.md +2 -2
- package/docs/terminal-setup.md +1 -1
- package/docs/themes.md +1 -1
- package/docs/tree.md +1 -1
- package/docs/tui.md +7 -7
- package/package.json +1 -1
package/docs/compaction.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# Compaction & Branch Summarization
|
|
2
2
|
|
|
3
|
-
LLMs have limited context windows. When conversations grow too long,
|
|
3
|
+
LLMs have limited context windows. When conversations grow too long, The agent uses compaction to summarize older content while preserving recent work. This page covers both auto-compaction and branch summarization.
|
|
4
4
|
|
|
5
5
|
**Source files** ([aery](https://github.com/eminent337/aery)):
|
|
6
|
-
- [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/
|
|
7
|
-
- [`packages/coding-agent/src/core/compaction/branch-summarization.ts`](https://github.com/
|
|
8
|
-
- [`packages/coding-agent/src/core/compaction/utils.ts`](https://github.com/
|
|
9
|
-
- [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/
|
|
10
|
-
- [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/
|
|
6
|
+
- [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) - Auto-compaction logic
|
|
7
|
+
- [`packages/coding-agent/src/core/compaction/branch-summarization.ts`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) - Branch summarization
|
|
8
|
+
- [`packages/coding-agent/src/core/compaction/utils.ts`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
|
|
9
|
+
- [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
|
|
10
|
+
- [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/extensions/types.ts) - Extension event types
|
|
11
11
|
|
|
12
12
|
For TypeScript definitions in your project, inspect `node_modules/@eminent337/aery/dist/`.
|
|
13
13
|
|
|
@@ -102,7 +102,7 @@ Split turn (one huge turn exceeds budget):
|
|
|
102
102
|
turnPrefixMessages = [usr, ass, tool, ass, tool, tool]
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
For split turns,
|
|
105
|
+
For split turns, The agent generates two summaries and merges them:
|
|
106
106
|
1. **History summary**: Previous context (if any)
|
|
107
107
|
2. **Turn prefix summary**: The early part of the split turn
|
|
108
108
|
|
|
@@ -118,7 +118,7 @@ Never cut at tool results (they must stay with their tool call).
|
|
|
118
118
|
|
|
119
119
|
### CompactionEntry Structure
|
|
120
120
|
|
|
121
|
-
Defined in [`session-manager.ts`](https://github.com/
|
|
121
|
+
Defined in [`session-manager.ts`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts):
|
|
122
122
|
|
|
123
123
|
```typescript
|
|
124
124
|
interface CompactionEntry<T = unknown> {
|
|
@@ -142,13 +142,13 @@ interface CompactionDetails {
|
|
|
142
142
|
|
|
143
143
|
Extensions can store any JSON-serializable data in `details`. The default compaction tracks file operations, but custom extension implementations can use their own structure.
|
|
144
144
|
|
|
145
|
-
See [`prepareCompaction()`](https://github.com/
|
|
145
|
+
See [`prepareCompaction()`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) and [`compact()`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) for the implementation.
|
|
146
146
|
|
|
147
147
|
## Branch Summarization
|
|
148
148
|
|
|
149
149
|
### When It Triggers
|
|
150
150
|
|
|
151
|
-
When you use `/tree` to navigate to a different branch,
|
|
151
|
+
When you use `/tree` to navigate to a different branch, The agent offers to summarize the work you're leaving. This injects context from the left branch into the new branch.
|
|
152
152
|
|
|
153
153
|
### How It Works
|
|
154
154
|
|
|
@@ -177,7 +177,7 @@ After navigation with summary:
|
|
|
177
177
|
|
|
178
178
|
### Cumulative File Tracking
|
|
179
179
|
|
|
180
|
-
Both compaction and branch summarization track files cumulatively. When generating a summary,
|
|
180
|
+
Both compaction and branch summarization track files cumulatively. When generating a summary, The agent extracts file operations from:
|
|
181
181
|
- Tool calls in the messages being summarized
|
|
182
182
|
- Previous compaction or branch summary `details` (if any)
|
|
183
183
|
|
|
@@ -185,7 +185,7 @@ This means file tracking accumulates across multiple compactions or nested branc
|
|
|
185
185
|
|
|
186
186
|
### BranchSummaryEntry Structure
|
|
187
187
|
|
|
188
|
-
Defined in [`session-manager.ts`](https://github.com/
|
|
188
|
+
Defined in [`session-manager.ts`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts):
|
|
189
189
|
|
|
190
190
|
```typescript
|
|
191
191
|
interface BranchSummaryEntry<T = unknown> {
|
|
@@ -208,7 +208,7 @@ interface BranchSummaryDetails {
|
|
|
208
208
|
|
|
209
209
|
Same as compaction, extensions can store custom data in `details`.
|
|
210
210
|
|
|
211
|
-
See [`collectEntriesForBranchSummary()`](https://github.com/
|
|
211
|
+
See [`collectEntriesForBranchSummary()`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), [`prepareBranchEntries()`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), and [`generateBranchSummary()`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) for the implementation.
|
|
212
212
|
|
|
213
213
|
## Summary Format
|
|
214
214
|
|
|
@@ -252,7 +252,7 @@ path/to/changed.ts
|
|
|
252
252
|
|
|
253
253
|
### Message Serialization
|
|
254
254
|
|
|
255
|
-
Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/
|
|
255
|
+
Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/compaction/utils.ts):
|
|
256
256
|
|
|
257
257
|
```
|
|
258
258
|
[User]: What they said
|
|
@@ -268,14 +268,14 @@ Tool results are truncated to 2000 characters during serialization. Content beyo
|
|
|
268
268
|
|
|
269
269
|
## Custom Summarization via Extensions
|
|
270
270
|
|
|
271
|
-
Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/
|
|
271
|
+
Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/core/extensions/types.ts) for event type definitions.
|
|
272
272
|
|
|
273
273
|
### session_before_compact
|
|
274
274
|
|
|
275
275
|
Fired before auto-compaction or `/compact`. Can cancel or provide custom summary. See `SessionBeforeCompactEvent` and `CompactionPreparation` in the types file.
|
|
276
276
|
|
|
277
277
|
```typescript
|
|
278
|
-
|
|
278
|
+
pi.on("session_before_compact", async (event, ctx) => {
|
|
279
279
|
const { preparation, branchEntries, customInstructions, signal } = event;
|
|
280
280
|
|
|
281
281
|
// preparation.messagesToSummarize - messages to summarize
|
|
@@ -311,7 +311,7 @@ To generate a summary with your own model, convert messages to text using `seria
|
|
|
311
311
|
```typescript
|
|
312
312
|
import { convertToLlm, serializeConversation } from "@eminent337/aery";
|
|
313
313
|
|
|
314
|
-
|
|
314
|
+
pi.on("session_before_compact", async (event, ctx) => {
|
|
315
315
|
const { preparation } = event;
|
|
316
316
|
|
|
317
317
|
// Convert AgentMessage[] to Message[], then serialize to text
|
|
@@ -345,7 +345,7 @@ See [custom-compaction.ts](../examples/extensions/custom-compaction.ts) for a co
|
|
|
345
345
|
Fired before `/tree` navigation. Always fires regardless of whether user chose to summarize. Can cancel navigation or provide custom summary.
|
|
346
346
|
|
|
347
347
|
```typescript
|
|
348
|
-
|
|
348
|
+
pi.on("session_before_tree", async (event, ctx) => {
|
|
349
349
|
const { preparation, signal } = event;
|
|
350
350
|
|
|
351
351
|
// preparation.targetId - where we're navigating to
|
package/docs/custom-provider.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Custom Providers
|
|
2
2
|
|
|
3
|
-
Extensions can register custom model providers via `
|
|
3
|
+
Extensions can register custom model providers via `pi.registerProvider()`. This enables:
|
|
4
4
|
|
|
5
5
|
- **Proxies** - Route requests through corporate proxies or API gateways
|
|
6
6
|
- **Custom endpoints** - Use self-hosted or private model deployments
|
|
@@ -35,12 +35,12 @@ import type { ExtensionAPI } from "@eminent337/aery";
|
|
|
35
35
|
|
|
36
36
|
export default function (aery: ExtensionAPI) {
|
|
37
37
|
// Override baseUrl for existing provider
|
|
38
|
-
|
|
38
|
+
pi.registerProvider("anthropic", {
|
|
39
39
|
baseUrl: "https://proxy.example.com"
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
// Register new provider with models
|
|
43
|
-
|
|
43
|
+
pi.registerProvider("my-provider", {
|
|
44
44
|
baseUrl: "https://api.example.com",
|
|
45
45
|
apiKey: "MY_API_KEY",
|
|
46
46
|
api: "openai-completions",
|
|
@@ -59,7 +59,7 @@ export default function (aery: ExtensionAPI) {
|
|
|
59
59
|
}
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
The extension factory can also be `async`. For dynamic model discovery, fetch and register models in the factory instead of `session_start`.
|
|
62
|
+
The extension factory can also be `async`. For dynamic model discovery, fetch and register models in the factory instead of `session_start`. pi waits for the factory before startup continues, so the provider is available during interactive startup and to `aery --list-models`.
|
|
63
63
|
|
|
64
64
|
## Override Existing Provider
|
|
65
65
|
|
|
@@ -67,19 +67,19 @@ The simplest use case: redirect an existing provider through a proxy.
|
|
|
67
67
|
|
|
68
68
|
```typescript
|
|
69
69
|
// All Anthropic requests now go through your proxy
|
|
70
|
-
|
|
70
|
+
pi.registerProvider("anthropic", {
|
|
71
71
|
baseUrl: "https://proxy.example.com"
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
// Add custom headers to OpenAI requests
|
|
75
|
-
|
|
75
|
+
pi.registerProvider("openai", {
|
|
76
76
|
headers: {
|
|
77
77
|
"X-Custom-Header": "value"
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
// Both baseUrl and headers
|
|
82
|
-
|
|
82
|
+
pi.registerProvider("google", {
|
|
83
83
|
baseUrl: "https://ai-gateway.corp.com/google",
|
|
84
84
|
headers: {
|
|
85
85
|
"X-Corp-Auth": "CORP_AUTH_TOKEN" // env var or literal
|
|
@@ -109,7 +109,7 @@ export default async function (aery: ExtensionAPI) {
|
|
|
109
109
|
}>;
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
pi.registerProvider("local-openai", {
|
|
113
113
|
baseUrl: "http://localhost:1234/v1",
|
|
114
114
|
apiKey: "LOCAL_OPENAI_API_KEY",
|
|
115
115
|
api: "openai-completions",
|
|
@@ -129,7 +129,7 @@ export default async function (aery: ExtensionAPI) {
|
|
|
129
129
|
This registers the fetched models before startup finishes.
|
|
130
130
|
|
|
131
131
|
```typescript
|
|
132
|
-
|
|
132
|
+
pi.registerProvider("my-llm", {
|
|
133
133
|
baseUrl: "https://api.my-llm.com/v1",
|
|
134
134
|
apiKey: "MY_LLM_API_KEY", // env var name or literal value
|
|
135
135
|
api: "openai-completions", // which streaming API to use
|
|
@@ -156,11 +156,11 @@ When `models` is provided, it **replaces** all existing models for that provider
|
|
|
156
156
|
|
|
157
157
|
## Unregister Provider
|
|
158
158
|
|
|
159
|
-
Use `aery.unregisterProvider(name)` to remove a provider that was previously registered via `
|
|
159
|
+
Use `aery.unregisterProvider(name)` to remove a provider that was previously registered via `pi.registerProvider(name, ...)`:
|
|
160
160
|
|
|
161
161
|
```typescript
|
|
162
162
|
// Register
|
|
163
|
-
|
|
163
|
+
pi.registerProvider("my-llm", {
|
|
164
164
|
baseUrl: "https://api.my-llm.com/v1",
|
|
165
165
|
apiKey: "MY_LLM_API_KEY",
|
|
166
166
|
api: "openai-completions",
|
|
@@ -211,7 +211,7 @@ models: [{
|
|
|
211
211
|
compat: {
|
|
212
212
|
supportsDeveloperRole: false, // use "system" instead of "developer"
|
|
213
213
|
supportsReasoningEffort: true,
|
|
214
|
-
reasoningEffortMap: { // map
|
|
214
|
+
reasoningEffortMap: { // map aery-ai levels to provider values
|
|
215
215
|
minimal: "default",
|
|
216
216
|
low: "default",
|
|
217
217
|
medium: "default",
|
|
@@ -238,7 +238,7 @@ Use `cacheControlFormat: "anthropic"` for OpenAI-compatible providers that expos
|
|
|
238
238
|
If your provider expects `Authorization: Bearer <key>` but doesn't use a standard API, set `authHeader: true`:
|
|
239
239
|
|
|
240
240
|
```typescript
|
|
241
|
-
|
|
241
|
+
pi.registerProvider("custom-api", {
|
|
242
242
|
baseUrl: "https://api.example.com",
|
|
243
243
|
apiKey: "MY_API_KEY",
|
|
244
244
|
authHeader: true, // adds Authorization: Bearer header
|
|
@@ -254,7 +254,7 @@ Add OAuth/SSO authentication that integrates with `/login`:
|
|
|
254
254
|
```typescript
|
|
255
255
|
import type { OAuthCredentials, OAuthLoginCallbacks } from "@eminent337/aery-ai";
|
|
256
256
|
|
|
257
|
-
|
|
257
|
+
pi.registerProvider("corporate-ai", {
|
|
258
258
|
baseUrl: "https://ai.corp.com/v1",
|
|
259
259
|
api: "openai-responses",
|
|
260
260
|
models: [...],
|
|
@@ -345,12 +345,12 @@ interface OAuthCredentials {
|
|
|
345
345
|
For providers with non-standard APIs, implement `streamSimple`. Study the existing provider implementations before writing your own:
|
|
346
346
|
|
|
347
347
|
**Reference implementations:**
|
|
348
|
-
- [anthropic.ts](https://github.com/
|
|
349
|
-
- [mistral.ts](https://github.com/
|
|
350
|
-
- [openai-completions.ts](https://github.com/
|
|
351
|
-
- [openai-responses.ts](https://github.com/
|
|
352
|
-
- [google.ts](https://github.com/
|
|
353
|
-
- [amazon-bedrock.ts](https://github.com/
|
|
348
|
+
- [anthropic.ts](https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/providers/anthropic.ts) - Anthropic Messages API
|
|
349
|
+
- [mistral.ts](https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/providers/mistral.ts) - Mistral Conversations API
|
|
350
|
+
- [openai-completions.ts](https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/providers/openai-completions.ts) - OpenAI Chat Completions
|
|
351
|
+
- [openai-responses.ts](https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/providers/openai-responses.ts) - OpenAI Responses API
|
|
352
|
+
- [google.ts](https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/providers/google.ts) - Google Generative AI
|
|
353
|
+
- [amazon-bedrock.ts](https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/providers/amazon-bedrock.ts) - AWS Bedrock
|
|
354
354
|
|
|
355
355
|
### Stream Pattern
|
|
356
356
|
|
|
@@ -511,7 +511,7 @@ calculateCost(model, output.usage);
|
|
|
511
511
|
Register your stream function:
|
|
512
512
|
|
|
513
513
|
```typescript
|
|
514
|
-
|
|
514
|
+
pi.registerProvider("my-provider", {
|
|
515
515
|
baseUrl: "https://api.example.com",
|
|
516
516
|
apiKey: "MY_API_KEY",
|
|
517
517
|
api: "my-custom-api",
|