@mariozechner/pi-coding-agent 0.23.2 → 0.23.4

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 (43) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +89 -148
  3. package/dist/core/agent-session.d.ts +3 -1
  4. package/dist/core/agent-session.d.ts.map +1 -1
  5. package/dist/core/agent-session.js +27 -6
  6. package/dist/core/agent-session.js.map +1 -1
  7. package/dist/core/custom-tools/loader.d.ts.map +1 -1
  8. package/dist/core/custom-tools/loader.js +4 -2
  9. package/dist/core/custom-tools/loader.js.map +1 -1
  10. package/dist/core/hooks/loader.d.ts.map +1 -1
  11. package/dist/core/hooks/loader.js +29 -3
  12. package/dist/core/hooks/loader.js.map +1 -1
  13. package/dist/core/hooks/types.d.ts +2 -1
  14. package/dist/core/hooks/types.d.ts.map +1 -1
  15. package/dist/core/hooks/types.js.map +1 -1
  16. package/dist/core/system-prompt.d.ts.map +1 -1
  17. package/dist/core/system-prompt.js +3 -3
  18. package/dist/core/system-prompt.js.map +1 -1
  19. package/dist/modes/interactive/components/diff.d.ts +12 -0
  20. package/dist/modes/interactive/components/diff.d.ts.map +1 -0
  21. package/dist/modes/interactive/components/diff.js +133 -0
  22. package/dist/modes/interactive/components/diff.js.map +1 -0
  23. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  24. package/dist/modes/interactive/components/tool-execution.js +26 -20
  25. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  26. package/dist/modes/interactive/theme/dark.json +9 -9
  27. package/dist/modes/interactive/theme/light.json +9 -9
  28. package/dist/modes/interactive/theme/theme.d.ts +10 -0
  29. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  30. package/dist/modes/interactive/theme/theme.js +131 -3
  31. package/dist/modes/interactive/theme/theme.js.map +1 -1
  32. package/docs/custom-tools.md +19 -1
  33. package/docs/hooks.md +39 -19
  34. package/docs/rpc.md +14 -0
  35. package/docs/skills.md +148 -52
  36. package/docs/theme.md +23 -21
  37. package/package.json +6 -6
  38. package/docs/compaction-new.md +0 -387
  39. package/docs/compaction-strategies.ts +0 -502
  40. package/docs/compaction.md +0 -519
  41. package/docs/gemini.md +0 -255
  42. package/docs/truncation.md +0 -235
  43. package/docs/undercompaction.md +0 -313
package/docs/gemini.md DELETED
@@ -1,255 +0,0 @@
1
- # Gemini OAuth Integration Guide
2
-
3
- This document provides a comprehensive analysis of how OAuth authentication could be implemented for Google Gemini in the pi coding-agent, based on the existing Anthropic OAuth implementation and the Gemini CLI's approach.
4
-
5
- ## Table of Contents
6
-
7
- 1. [Current Anthropic OAuth Implementation](#current-anthropic-oauth-implementation)
8
- 2. [Gemini CLI Authentication Analysis](#gemini-cli-authentication-analysis)
9
- 3. [Gemini API Capabilities](#gemini-api-capabilities)
10
- 4. [Gemini API Endpoints](#gemini-api-endpoints)
11
- 5. [Implementation Plan](#implementation-plan)
12
-
13
- ## Current Anthropic OAuth Implementation
14
-
15
- The pi coding-agent implements OAuth for Anthropic with the following architecture:
16
-
17
- ### Key Components
18
-
19
- 1. **OAuth Flow** (`packages/coding-agent/src/core/oauth/anthropic.ts`):
20
- - Uses PKCE (Proof Key for Code Exchange) flow for security
21
- - Client ID: `9d1c250a-e61b-44d9-88ed-5944d1962f5e`
22
- - Authorization URL: `https://claude.ai/oauth/authorize`
23
- - Token URL: `https://console.anthropic.com/v1/oauth/token`
24
- - Scopes: `org:create_api_key user:profile user:inference`
25
-
26
- 2. **Token Storage** (`packages/coding-agent/src/core/oauth/storage.ts`):
27
- - Stores credentials in `~/.pi/agent/oauth.json`
28
- - File permissions set to 0600 (owner read/write only)
29
- - Format: `{ provider: { type: "oauth", refresh: string, access: string, expires: number } }`
30
-
31
- 3. **Token Management** (`packages/coding-agent/src/core/oauth/index.ts`):
32
- - Auto-refresh tokens when expired (with 5-minute buffer)
33
- - Supports multiple providers through `SupportedOAuthProvider` type
34
- - Provider info includes id, name, and availability status
35
-
36
- 4. **Model Integration** (`packages/coding-agent/src/core/model-config.ts`):
37
- - Checks OAuth tokens first, then environment variables
38
- - OAuth status cached to avoid repeated file reads
39
- - Maps providers to OAuth providers via `providerToOAuthProvider`
40
-
41
- ### Authentication Flow
42
-
43
- 1. User initiates login with `pi auth login`
44
- 2. Authorization URL is generated with PKCE challenge
45
- 3. User opens URL in browser and authorizes
46
- 4. User copies authorization code (format: `code#state`)
47
- 5. Code is exchanged for access/refresh tokens
48
- 6. Tokens are saved encrypted with expiry time
49
-
50
- ## Gemini CLI Authentication Analysis
51
-
52
- The Gemini CLI uses a more complex OAuth implementation with several key differences:
53
-
54
- ### Authentication Methods
55
-
56
- Gemini supports multiple authentication types:
57
- - `LOGIN_WITH_GOOGLE` (OAuth personal account)
58
- - `USE_GEMINI` (API key)
59
- - `USE_VERTEX_AI` (Vertex AI)
60
- - `COMPUTE_ADC` (Application Default Credentials)
61
-
62
- ### OAuth Implementation Details
63
-
64
- 1. **OAuth Configuration**:
65
- - Client ID and Secret: See [google-gemini/gemini-cli oauth2.ts](https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/code_assist/oauth2.ts) (public for installed apps per Google's OAuth docs)
66
- - Scopes:
67
- - `https://www.googleapis.com/auth/cloud-platform`
68
- - `https://www.googleapis.com/auth/userinfo.email`
69
- - `https://www.googleapis.com/auth/userinfo.profile`
70
-
71
- 2. **Authentication Flows**:
72
- - **Web Flow**: Opens browser, runs local HTTP server for callback
73
- - **User Code Flow**: For environments without browser (NO_BROWSER=true)
74
- - Uses Google's `google-auth-library` for OAuth handling
75
-
76
- 3. **Token Storage**:
77
- - Supports encrypted storage via `OAuthCredentialStorage`
78
- - Falls back to plain JSON storage
79
- - Stores user info (email) separately
80
-
81
- 4. **API Integration**:
82
- - Uses `CodeAssistServer` for API calls
83
- - Endpoint: `https://cloudcode-pa.googleapis.com`
84
- - Includes user tier information (FREE, STANDARD, etc.)
85
-
86
- ## Gemini API Capabilities
87
-
88
- Based on the Gemini CLI analysis:
89
-
90
- ### System Prompts
91
- ✅ **Yes, Gemini supports system prompts**
92
- - Implemented via `getCoreSystemPrompt()` in the codebase
93
- - System instructions are part of the `GenerateContentParameters`
94
-
95
- ### Tools/Function Calling
96
- ✅ **Yes, Gemini supports tools and function calling**
97
- - Uses the `Tool` type from `@google/genai`
98
- - Extensive tool support including:
99
- - File system operations (read, write, edit)
100
- - Web search and fetch
101
- - MCP (Model Context Protocol) tools
102
- - Custom tool registration
103
-
104
- ### Content Generation
105
- - Supports streaming and non-streaming generation
106
- - Token counting capabilities
107
- - Embedding support
108
- - Context compression for long conversations
109
-
110
- ## Gemini API Endpoints
111
-
112
- When using OAuth tokens, the Gemini CLI talks to:
113
-
114
- ### Primary Endpoint
115
- - **Base URL**: `https://cloudcode-pa.googleapis.com`
116
- - **API Version**: `v1internal`
117
-
118
- ### Key Methods
119
- - `generateContent` - Non-streaming content generation
120
- - `streamGenerateContent` - Streaming content generation
121
- - `countTokens` - Token counting
122
- - `embedContent` - Text embeddings
123
- - `loadCodeAssist` - User setup and tier information
124
- - `onboardUser` - User onboarding
125
-
126
- ### Authentication
127
- - OAuth tokens are passed via `AuthClient` from `google-auth-library`
128
- - Tokens are automatically refreshed by the library
129
- - Project ID and session ID included in requests
130
-
131
- ## Implementation Plan
132
-
133
- ### 1. Add Gemini OAuth Provider Support
134
-
135
- **File**: `packages/coding-agent/src/core/oauth/gemini.ts`
136
-
137
- ```typescript
138
- import { OAuth2Client } from 'google-auth-library';
139
- import { type OAuthCredentials, saveOAuthCredentials } from "./storage.js";
140
-
141
- // OAuth credentials from google-gemini/gemini-cli:
142
- // https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/code_assist/oauth2.ts
143
- const SCOPES = [
144
- "https://www.googleapis.com/auth/cloud-platform",
145
- "https://www.googleapis.com/auth/userinfo.email",
146
- "https://www.googleapis.com/auth/userinfo.profile"
147
- ];
148
-
149
- export async function loginGemini(
150
- onAuthUrl: (url: string) => void,
151
- onPromptCode: () => Promise<string>,
152
- ): Promise<void> {
153
- // Implementation similar to Anthropic but using google-auth-library
154
- }
155
-
156
- export async function refreshGeminiToken(refreshToken: string): Promise<OAuthCredentials> {
157
- // Use google-auth-library for refresh
158
- }
159
- ```
160
-
161
- ### 2. Update OAuth Index
162
-
163
- **File**: `packages/coding-agent/src/core/oauth/index.ts`
164
-
165
- ```typescript
166
- export type SupportedOAuthProvider = "anthropic" | "github-copilot" | "gemini";
167
-
168
- // Add Gemini to provider list
169
- {
170
- id: "gemini",
171
- name: "Google Gemini (Code Assist)",
172
- available: true,
173
- }
174
-
175
- // Add cases for Gemini in login/refresh functions
176
- ```
177
-
178
- ### 3. Create Gemini API Client
179
-
180
- **File**: `packages/ai/src/providers/gemini-oauth.ts`
181
-
182
- ```typescript
183
- export class GeminiOAuthProvider implements Provider {
184
- // Implement Provider interface
185
- // Use CodeAssistServer approach from Gemini CLI
186
- // Map to standard pi-ai API format
187
- }
188
- ```
189
-
190
- ### 4. Update Model Configuration
191
-
192
- **File**: `packages/coding-agent/src/core/model-config.ts`
193
-
194
- ```typescript
195
- // Add to providerToOAuthProvider mapping
196
- gemini: "gemini",
197
-
198
- // Add Gemini OAuth token check
199
- if (model.provider === "gemini") {
200
- const oauthToken = await getOAuthToken("gemini");
201
- if (oauthToken) return oauthToken;
202
- const oauthEnv = process.env.GEMINI_OAUTH_TOKEN;
203
- if (oauthEnv) return oauthEnv;
204
- }
205
- ```
206
-
207
- ### 5. Dependencies
208
-
209
- Add to `package.json`:
210
- ```json
211
- {
212
- "dependencies": {
213
- "google-auth-library": "^9.0.0"
214
- }
215
- }
216
- ```
217
-
218
- ### 6. Environment Variables
219
-
220
- Support these environment variables:
221
- - `GEMINI_OAUTH_TOKEN` - Manual OAuth token
222
- - `GOOGLE_CLOUD_PROJECT` - For project-specific features
223
- - `NO_BROWSER` - Force user code flow
224
-
225
- ### Key Differences from Anthropic Implementation
226
-
227
- 1. **Authentication Library**: Use `google-auth-library` instead of manual OAuth
228
- 2. **Multiple Auth Types**: Support OAuth, API key, and ADC
229
- 3. **User Info**: Fetch and cache user email/profile
230
- 4. **Project Context**: Include project ID in API calls
231
- 5. **Tier Management**: Handle user tier (FREE/STANDARD) responses
232
-
233
- ### Challenges and Considerations
234
-
235
- 1. **API Access**: The Code Assist API (`cloudcode-pa.googleapis.com`) might require special access or be in preview
236
- 2. **Model Naming**: Need to map Gemini model names to Code Assist equivalents
237
- 3. **Rate Limits**: Handle tier-based rate limits
238
- 4. **Error Handling**: Map Google-specific errors to pi error types
239
- 5. **Token Scopes**: Ensure scopes are sufficient for all operations
240
-
241
- ### Testing Plan
242
-
243
- 1. Test OAuth flow (browser and NO_BROWSER modes)
244
- 2. Test token refresh
245
- 3. Test API calls with OAuth tokens
246
- 4. Test fallback to API keys
247
- 5. Test error scenarios (invalid tokens, network errors)
248
- 6. Test model switching and tier limits
249
-
250
- ### Migration Path
251
-
252
- 1. Users with `GEMINI_API_KEY` continue working unchanged
253
- 2. New `pi auth login gemini` command for OAuth
254
- 3. OAuth takes precedence over API keys when available
255
- 4. Clear messaging about benefits (higher limits, better features)
@@ -1,235 +0,0 @@
1
- # Tool Output Truncation
2
-
3
- ## Limits
4
-
5
- - **Line limit**: 2000 lines
6
- - **Byte limit**: 30KB
7
- - **Grep line limit**: 500 chars per match line
8
-
9
- Whichever limit is hit first wins. **Never return partial lines** (except bash edge case).
10
-
11
- ---
12
-
13
- ## read
14
-
15
- Head truncation (first N lines). Has offset/limit params for continuation.
16
-
17
- ### Scenarios
18
-
19
- **First line > 30KB:**
20
- ```
21
- LLM sees:
22
- [Line 1 is 50KB, exceeds 30KB limit. Use bash to read: head -c 30000 path/to/file]
23
-
24
- Details:
25
- { truncation: { truncated: true, truncatedBy: "bytes", outputLines: 0, ... } }
26
- ```
27
-
28
- **Hit line limit (2000 lines, < 30KB):**
29
- ```
30
- LLM sees:
31
- [lines 1-2000 content]
32
-
33
- [Showing lines 1-2000 of 5000. Use offset=2001 to continue]
34
-
35
- Details:
36
- { truncation: { truncated: true, truncatedBy: "lines", outputLines: 2000, totalLines: 5000 } }
37
- ```
38
-
39
- **Hit byte limit (< 2000 lines, 30KB):**
40
- ```
41
- LLM sees:
42
- [lines 1-500 content]
43
-
44
- [Showing lines 1-500 of 5000 (30KB limit). Use offset=501 to continue]
45
-
46
- Details:
47
- { truncation: { truncated: true, truncatedBy: "bytes", outputLines: 500, totalLines: 5000 } }
48
- ```
49
-
50
- **With offset, hit line limit (e.g., offset=1000):**
51
- ```
52
- LLM sees:
53
- [lines 1000-2999 content]
54
-
55
- [Showing lines 1000-2999 of 5000. Use offset=3000 to continue]
56
-
57
- Details:
58
- { truncation: { truncatedBy: "lines", ... } }
59
- ```
60
-
61
- **With offset, hit byte limit (e.g., offset=1000, 30KB after 500 lines):**
62
- ```
63
- LLM sees:
64
- [lines 1000-1499 content]
65
-
66
- [Showing lines 1000-1499 of 5000 (30KB limit). Use offset=1500 to continue]
67
-
68
- Details:
69
- { truncation: { truncatedBy: "bytes", outputLines: 500, ... } }
70
- ```
71
-
72
- **With offset, first line at offset > 30KB (e.g., offset=1000, line 1000 is 50KB):**
73
- ```
74
- LLM sees:
75
- [Line 1000 is 50KB, exceeds 30KB limit. Use bash: sed -n '1000p' file | head -c 30000]
76
-
77
- Details:
78
- { truncation: { truncated: true, truncatedBy: "bytes", outputLines: 0 } }
79
- ```
80
-
81
- ---
82
-
83
- ## bash
84
-
85
- Tail truncation (last N lines). Writes full output to temp file if truncated.
86
-
87
- ### Scenarios
88
-
89
- **Hit line limit (2000 lines):**
90
- ```
91
- LLM sees:
92
- [lines 48001-50000 content]
93
-
94
- [Showing lines 48001-50000 of 50000. Full output: /tmp/pi-bash-xxx.log]
95
-
96
- Details:
97
- { truncation: { truncated: true, truncatedBy: "lines", outputLines: 2000, totalLines: 50000 }, fullOutputPath: "/tmp/..." }
98
- ```
99
-
100
- **Hit byte limit (< 2000 lines, 30KB):**
101
- ```
102
- LLM sees:
103
- [lines 49501-50000 content]
104
-
105
- [Showing lines 49501-50000 of 50000 (30KB limit). Full output: /tmp/pi-bash-xxx.log]
106
-
107
- Details:
108
- { truncation: { truncatedBy: "bytes", ... }, fullOutputPath: "/tmp/..." }
109
- ```
110
-
111
- **Last line alone > 30KB (edge case, partial OK here):**
112
- ```
113
- LLM sees:
114
- [last 30KB of final line]
115
-
116
- [Showing last 30KB of line 50000 (line is 100KB). Full output: /tmp/pi-bash-xxx.log]
117
-
118
- Details:
119
- { truncation: { truncatedBy: "bytes", lastLinePartial: true }, fullOutputPath: "/tmp/..." }
120
- ```
121
-
122
- ---
123
-
124
- ## grep
125
-
126
- Head truncation. Primary limit: 100 matches. Each match line truncated to 500 chars.
127
-
128
- ### Scenarios
129
-
130
- **Hit match limit (100 matches):**
131
- ```
132
- LLM sees:
133
- file.ts:10: matching content here...
134
- file.ts:25: another match...
135
- ...
136
-
137
- [100 matches limit reached. Use limit=200 for more, or refine pattern]
138
-
139
- Details:
140
- { matchLimitReached: 100 }
141
- ```
142
-
143
- **Hit byte limit (< 100 matches, 30KB):**
144
- ```
145
- LLM sees:
146
- [matches that fit in 30KB]
147
-
148
- [30KB limit reached (50 of 100+ matches shown)]
149
-
150
- Details:
151
- { truncation: { truncatedBy: "bytes", ... } }
152
- ```
153
-
154
- **Match lines truncated (any line > 500 chars):**
155
- ```
156
- LLM sees:
157
- file.ts:10: very long matching content that exceeds 500 chars gets cut off here... [truncated]
158
- file.ts:25: normal match
159
-
160
- [Some lines truncated to 500 chars. Use read tool to see full lines]
161
-
162
- Details:
163
- { linesTruncated: true }
164
- ```
165
-
166
- ---
167
-
168
- ## find
169
-
170
- Head truncation. Primary limit: 1000 results. File paths only (never > 30KB each).
171
-
172
- ### Scenarios
173
-
174
- **Hit result limit (1000 results):**
175
- ```
176
- LLM sees:
177
- src/file1.ts
178
- src/file2.ts
179
- [998 more paths]
180
-
181
- [1000 results limit reached. Use limit=2000 for more, or refine pattern]
182
-
183
- Details:
184
- { resultLimitReached: 1000 }
185
- ```
186
-
187
- **Hit byte limit (unlikely, < 1000 results, 30KB):**
188
- ```
189
- LLM sees:
190
- [paths that fit]
191
-
192
- [30KB limit reached]
193
-
194
- Details:
195
- { truncation: { truncatedBy: "bytes", ... } }
196
- ```
197
-
198
- ---
199
-
200
- ## ls
201
-
202
- Head truncation. Primary limit: 500 entries. Entry names only (never > 30KB each).
203
-
204
- ### Scenarios
205
-
206
- **Hit entry limit (500 entries):**
207
- ```
208
- LLM sees:
209
- .gitignore
210
- README.md
211
- src/
212
- [497 more entries]
213
-
214
- [500 entries limit reached. Use limit=1000 for more]
215
-
216
- Details:
217
- { entryLimitReached: 500 }
218
- ```
219
-
220
- **Hit byte limit (unlikely):**
221
- ```
222
- LLM sees:
223
- [entries that fit]
224
-
225
- [30KB limit reached]
226
-
227
- Details:
228
- { truncation: { truncatedBy: "bytes", ... } }
229
- ```
230
-
231
- ---
232
-
233
- ## TUI Display
234
-
235
- `tool-execution.ts` reads `details.truncation` and related fields to display truncation notices in warning color. The LLM text content and TUI display show the same information.