Commit Graph

355 Commits

Author SHA1 Message Date
Peter Steinberger
43c7f5036a fix(tools): keep tool errors concise 2026-01-07 19:08:13 +00:00
alejandro maza
579828b2d5 Handle 413 context overflow errors gracefully
When the conversation context exceeds the model's limit, instead of
throwing an opaque error or returning raw JSON, we now:

1. Detect context overflow errors (413, request_too_large, etc.)
2. Return a user-friendly message explaining the issue
3. Suggest using /new or /reset to start fresh

This prevents the assistant from becoming completely unresponsive
when context grows too large (e.g., from many screenshots or long
tool outputs).

Addresses issue #394
2026-01-07 19:08:13 +00:00
Max Sumrall
5ddf9b2c65 fix(agent): protect bootstrap prefix from pruning 2026-01-07 18:17:18 +00:00
Peter Steinberger
c3b3f571e9 fix(tools): finalize Vertex schema flattening (#409) 2026-01-07 17:54:19 +00:00
Kit
a2b3f2c18a fix(tools): flatten nested anyOf schemas for Vertex AI compatibility
Claude API on Vertex AI (Cloud Code Assist) rejects nested anyOf schemas
as invalid JSON Schema draft 2020-12. This change:

- Add tryFlattenLiteralAnyOf() to convert Type.Union([Type.Literal(...)])
  patterns from anyOf with const values to flat enum arrays
- Update stringEnum helper in bash-tools to use Type.Unsafe with flat enum
- Flatten BrowserActSchema from discriminated union to single object
- Simplify TelegramToolSchema to use Type.String() for IDs

Fixes 400 errors when sending messages through WhatsApp/Telegram providers.
2026-01-07 17:51:16 +00:00
Max Sumrall
f9118bd21c test(agent): cover context pruning 2026-01-07 18:00:14 +01:00
Max Sumrall
eeaa6ea46f feat(agent): opt-in tool-result context pruning 2026-01-07 18:00:14 +01:00
Peter Steinberger
573fe74a9c fix: per-agent sandbox overrides 2026-01-07 17:31:40 +01:00
sheeek
22db83a04c test(tools): add tests for agent-specific tool filtering
Add 5 tests for agent-specific tool restrictions:
- Apply global tool policy when no agent-specific policy exists
- Apply agent-specific tool policy
- Allow different tool policies for different agents
- Combine global and agent-specific deny lists
- Work with sandbox tools filtering

All tests pass.
2026-01-07 17:31:40 +01:00
sheeek
1178c65226 test(sandbox): add tests for agent-specific sandbox override
Add 6 tests for agent-specific sandbox configuration:
- Use global sandbox config when no agent-specific config exists
- Override with agent-specific sandbox mode 'off'
- Use agent-specific sandbox mode 'all'
- Use agent-specific scope
- Use agent-specific workspaceRoot
- Prefer agent config over global for multiple agents

All tests pass.
2026-01-07 17:31:40 +01:00
sheeek
5a51a9b0d6 test(agent-scope): add tests for sandbox and tools config resolution
Add 7 tests for resolveAgentConfig():
- Return undefined when no agents config exists
- Return undefined when agent id does not exist
- Return basic agent config (name, workspace, agentDir, model)
- Return agent-specific sandbox config
- Return agent-specific tools config
- Return both sandbox and tools config
- Normalize agent id

All tests pass.
2026-01-07 17:31:40 +01:00
sheeek
a8c153ec78 feat(tools): add agent-specific tool filtering
Add tool filtering layer for per-agent restrictions:
- Extract agentId from sessionKey
- Load routing.agents[agentId].tools via resolveAgentConfig()
- Apply agent-specific allow/deny before sandbox filtering

Filtering order:
1. Global (agent.tools)
2. Agent-specific (routing.agents[id].tools) ← NEW
3. Sandbox (agent.sandbox.tools)
4. Subagent policy

This enables different tool permissions per agent
(e.g., main: all tools, family: read only).
2026-01-07 17:31:40 +01:00
sheeek
a375a81919 feat(sandbox): support agent-specific sandbox config override
Changes to defaultSandboxConfig():
- Add optional agentId parameter
- Load routing.agents[agentId].sandbox if available
- Prefer agent-specific settings over global agent.sandbox

Update callers in resolveSandboxContext() and
ensureSandboxWorkspaceForSession() to extract agentId
from sessionKey and pass it to defaultSandboxConfig().

This enables per-agent sandbox modes (e.g., main: off, family: all).
2026-01-07 17:31:40 +01:00
sheeek
ebd96f2971 feat(agent-scope): extend resolveAgentConfig to return sandbox and tools
Return newly added fields from routing.agents config:
- sandbox: agent-specific sandbox configuration
- tools: agent-specific tool restrictions

This makes per-agent sandbox and tool settings accessible
to other parts of the codebase.
2026-01-07 17:31:40 +01:00
Peter Steinberger
77024cf776 fix(agents): make sessions_spawn non-blocking 2026-01-07 16:14:25 +00:00
Peter Steinberger
61f720b945 feat: add skill filter + group system prompt plumbing 2026-01-07 11:44:37 +01:00
Josh Palmer
4e14123edd Merge pull request #378 from timkrase/system-prompt-weekday
Agents: add weekday to user time (codex assisted)
2026-01-07 11:27:07 +01:00
Peter Steinberger
a700f9896d feat: telegram draft streaming 2026-01-07 11:08:32 +01:00
Peter Steinberger
e8420bd047 fix: refine bootstrap injections 2026-01-07 10:04:23 +00:00
Tobias Bischoff
412990a139 Reduce prompt token overhead with leaner context injections 2026-01-07 10:04:23 +00:00
Tim Krase
e58e13708d Agents: add weekday to user time 2026-01-07 11:02:39 +01:00
Peter Steinberger
7a917602c5 feat(auth): sync OAuth from Claude/Codex CLIs
Add source profiles anthropic:claude-cli and openai-codex:codex-cli; surface them in onboarding/configure.

Co-authored-by: pepicrft <pepicrft@users.noreply.github.com>
2026-01-07 10:47:57 +01:00
Peter Steinberger
0914517ee3 feat(sandbox): add workspace access mode 2026-01-07 09:33:38 +00:00
Peter Steinberger
7973fd4caf feat: add agents command 2026-01-07 10:03:53 +01:00
Peter Steinberger
e5dbe1db9d fix: ensure output for non-streaming models (#369)
Co-authored-by: mneves75 <mneves75@users.noreply.github.com>
2026-01-07 07:47:18 +00:00
Peter Steinberger
7176b114da fix(auth): harden legacy auth.json cleanup 2026-01-07 06:51:17 +00:00
Peter Steinberger
0707b1e487 Merge PR #368: delete legacy auth.json after migration 2026-01-07 06:47:46 +00:00
Peter Steinberger
2937c4861f fix(auth): doctor-migrate anthropic oauth profiles 2026-01-07 06:31:02 +00:00
Matthew Dicembrino
4f10279ac3 fix: delete legacy auth.json after migration to prevent stale token overwrites (#363) 2026-01-07 01:15:38 -05:00
Peter Steinberger
50dec39d13 fix: honor sandboxed built-in tools 2026-01-07 06:12:56 +00:00
Peter Steinberger
03928106c7 fix: order reasoning before reply text 2026-01-07 07:05:07 +01:00
Peter Steinberger
75c66acfd8 feat: update subagent announce + archive 2026-01-07 06:53:01 +01:00
Peter Steinberger
1673a221f8 feat: add /reasoning reasoning visibility 2026-01-07 06:17:31 +01:00
Peter Steinberger
3668388912 fix(routing): harden originating reply routing 2026-01-07 05:02:34 +00:00
Peter Steinberger
514fcfe77e fix: harden sub-agent model overrides 2026-01-07 04:48:37 +00:00
Peter Steinberger
12d57da53a fix: normalize provider aliases in auth order 2026-01-07 05:43:32 +01:00
mneves75
3550dc294d fix: normalize z.ai provider ids in auth profiles 2026-01-07 05:31:01 +01:00
mneves75
8954f7719c Test: cover z.ai normalization 2026-01-07 05:30:06 +01:00
mneves75
0ddfbf5534 Feat: normalize z.ai provider ids 2026-01-07 05:30:06 +01:00
Peter Steinberger
8ef0609f8e refactor: share reaction schemas and notes 2026-01-07 04:24:11 +01:00
Peter Steinberger
3afef2d504 feat: unify provider reaction tools 2026-01-07 04:16:39 +01:00
Sash Zats
551a8d5683 Add WhatsApp reactions support
Summary:

Test Plan:
2026-01-07 04:16:39 +01:00
Peter Steinberger
4bf5f37a44 refactor: streamline outbound payload handling 2026-01-07 02:30:42 +00:00
Peter Steinberger
467d4e17fe feat: add sandbox scope default 2026-01-07 02:52:41 +01:00
Erik
cd4e2023ab fix(agent): capture compaction retry AbortError for model fallback
Wrap waitForCompactionRetry() in try/catch to capture AbortError
that was escaping and bypassing the model fallback mechanism.

When a timeout fires, session.abort() causes both session.prompt()
and waitForCompactionRetry() to throw AbortError. Previously only
the prompt error was captured, allowing the compaction error to
escape to model-fallback.ts where it was immediately re-thrown
(line 199: isAbortError check), bypassing fallback model attempts.

Fixes #313
2026-01-07 01:44:37 +01:00
Peter Steinberger
19c95d0ff7 fix(auth): serialize profile stats updates 2026-01-07 01:06:51 +01:00
Peter Steinberger
96d72ff91e fix(auth): lock auth profile updates 2026-01-07 01:00:47 +01:00
Muhammed Mukhthar CM
eb5f758f6b fix(auth): improve multi-account round-robin rotation and 429 handling
This commit fixes several issues with multi-account OAuth rotation that
were causing slow responses and inefficient account cycling.

## Changes

### 1. Fix usageStats race condition (auth-profiles.ts)

The `markAuthProfileUsed`, `markAuthProfileCooldown`, `markAuthProfileGood`,
and `clearAuthProfileCooldown` functions were using a stale in-memory store
passed as a parameter. Long-running sessions would overwrite usageStats
updates from concurrent sessions when saving.

**Fix:** Re-read the store from disk before each update to get fresh
usageStats from other sessions, then merge the update.

### 2. Capture AbortError from waitForCompactionRetry (pi-embedded-runner.ts)

When a request timed out, `session.abort()` was called which throws an
`AbortError`. The code structure was:

```javascript
try {
  await session.prompt(params.prompt);
} catch (err) {
  promptError = err;  // Catches AbortError here
}
await waitForCompactionRetry();  // But THIS also throws AbortError!
```

The second `AbortError` from `waitForCompactionRetry()` escaped and
bypassed the rotation/fallback logic entirely.

**Fix:** Wrap `waitForCompactionRetry()` in its own try/catch to capture
the error as `promptError`, enabling proper timeout handling.

Root cause analysis and fix proposed by @erikpr1994 in #313.

Fixes #313

### 3. Fail fast on 429 rate limits (pi-ai patch)

The pi-ai library was retrying 429 errors up to 3 times with exponential
backoff before throwing. This meant a rate-limited account would waste
30+ seconds retrying before our rotation code could try the next account.

**Fix:** Patch google-gemini-cli.js to:
- Throw immediately on first 429 (no retries)
- Not catch and retry 429 errors in the network error handler

This allows the caller to rotate to the next account instantly on rate limit.

Note: We submitted this fix upstream (https://github.com/badlogic/pi-mono/pull/504)
but it was closed without merging. Keeping as a local patch for now.

## Testing

With 6 Antigravity accounts configured:
- Accounts rotate properly based on lastUsed (round-robin)
- 429s trigger immediate rotation to next account
- usageStats persist correctly across concurrent sessions
- Cooldown tracking works as expected

## Before/After

**Before:** Multiple 429 retries on same account, 30-90s delays
**After:** Instant rotation on 429, responses in seconds
2026-01-07 00:56:32 +01:00
Peter Steinberger
b57d36f49c fix(sessions_spawn): hard-fail invalid model overrides 2026-01-06 23:17:35 +00:00
Azade
0429a4b63b test(sessions_spawn): add test for model parameter 2026-01-06 23:17:35 +00:00