Skip to content

Conversation

@shuv1337
Copy link
Collaborator

@shuv1337 shuv1337 commented Jan 7, 2026

Summary

  • Sync with upstream sst/opencode v1.1.6 including new truncation system, permission enhancements, and console billing features
  • Fix grep tool memory exhaustion by streaming ripgrep output instead of buffering
  • Show spinner indicator for running tool calls and subagent tasks
  • Lock iOS viewport to prevent overscroll bounce in PWA mode
  • Handle bundled AWS SDK export shapes from Bun for Bedrock provider

Changes

Features

  • Upstream v1.1.6 sync with truncation system, permission improvements, and Zed extension updates
  • Console billing infrastructure (Stripe webhook, black tier support, migrations)
  • Desktop Tauri entitlements and enhanced lib.rs

Fixes

  • fix(grep): Stream ripgrep output to prevent memory exhaustion on large codebases
  • fix: Show spinner for running tool calls and subagent tasks
  • fix(pwa): Lock viewport on iOS to prevent overscroll bounce
  • fix(bedrock): Handle bundled AWS SDK export shapes from Bun
  • fix: Resolve TypeScript errors in theme.tsx and prompt.ts

Refactoring

  • Cleaned up old CONTEXT plan files
  • Updated fork-features.json with regression prevention markers

Breaking Changes

None

Testing

  • Bedrock bundled module export tests added
  • Truncation tests added
  • Permission task tests added
  • Existing tests cover remaining changes

Greptile Summary

This PR merges upstream v1.1.6 and includes critical bug fixes for memory exhaustion, iOS PWA viewport issues, and AWS SDK bundling compatibility.

Key Changes:

  • Grep streaming optimization (PR fix(grep): stream ripgrep output to prevent memory exhaustion anomalyco/opencode#5432): Refactored grep.ts to stream ripgrep output instead of buffering all results in memory. Implements proper line-ending handling (Unix/Windows), early process termination at MATCH_LIMIT (100), and prevents memory exhaustion on large codebases.

  • New truncation system: Introduced truncation.ts with configurable limits (2000 lines, 50KB bytes) and head/tail direction support. Integrated into tool execution wrapper (tool.ts) to automatically truncate all tool outputs.

  • Spinner for running tools: Added visual feedback in TUI for running tool calls and subagent tasks. Properly tracks status === "running" and displays animated spinner in primary theme color.

  • iOS PWA viewport locking: Fixed rubber-banding/overscroll bounce in PWA standalone mode by applying position:fixed and overscroll-behavior:none to html/body/root elements. Scoped correctly to @media (display-mode: standalone).

  • AWS SDK bundling fix: Resolved Bedrock provider compatibility with Bun bundling by handling multiple export shapes (unbundled, default.fn, default.default.fn) using robust coalescing logic.

  • TypeScript fixes: Resolved errors in theme.tsx (using onMount instead of createEffect for initialization) and prompt.ts (import cleanup).

  • Console billing infrastructure: Added Stripe webhook handlers for checkout completion, subscription lifecycle, payment methods, and refunds.

  • Upstream v1.1.6 sync: Includes permission enhancements with PermissionNext, Zed extension updates, and desktop Tauri entitlements.

Test Coverage:

Excellent test coverage added for:

  • Bedrock config precedence and bundled export shapes (amazon-bedrock.test.ts)
  • Truncation system with various limits and directions (truncation.test.ts)
  • Permission task filtering with wildcards and config integration (permission-task.test.ts)

Fork Feature Tracking:

Updated fork-features.json with regression prevention markers for grep streaming and spinner implementation to help maintain these features during future upstream merges.

Confidence Score: 5/5

  • This PR is safe to merge with high confidence
  • All critical bugs have comprehensive fixes with proper test coverage. The grep streaming fix prevents a real production issue (memory exhaustion), the PWA viewport fix is correctly scoped to standalone mode only, and the AWS SDK bundling fix handles all edge cases. TypeScript errors are resolved, and the upstream sync brings well-tested improvements. No security issues, breaking changes, or unresolved edge cases detected.
  • No files require special attention

Important Files Changed

Filename Overview
packages/opencode/src/tool/grep.ts Implements streaming ripgrep output to prevent memory exhaustion. Handles line endings correctly, implements proper truncation at MATCH_LIMIT, and kills process early when limit reached.
packages/opencode/src/provider/provider.ts Fixes AWS SDK credential provider export handling for Bun bundling. Robust coalescing logic handles unbundled, single-wrapped, and double-wrapped default exports.
packages/app/src/index.css Adds critical iOS PWA viewport locking with position:fixed, overscroll-behavior:none to prevent rubber-banding. Properly scopes fixes to PWA standalone mode only.
packages/opencode/src/session/truncation.ts New truncation system for tool outputs. Limits by lines (2000) and bytes (50KB), supports head/tail direction, properly handles UTF-8.
packages/opencode/src/cli/cmd/tui/routes/session/index.tsx Adds spinner animation for running tool calls and subagent tasks. Properly tracks isRunning state and displays spinner in primary theme color.
packages/console/app/src/routes/stripe/webhook.ts Implements Stripe webhook handlers for billing: checkout.session.completed, customer.updated, charge.refunded, invoice.payment_succeeded, subscription lifecycle.

Sequence Diagram

sequenceDiagram
    participant User
    participant Agent
    participant GrepTool
    participant Ripgrep
    participant TruncationSystem
    participant UI

    Note over User,UI: Grep Streaming Fix (PR #5432)
    
    User->>Agent: Request code search
    Agent->>GrepTool: Execute grep(pattern, path)
    GrepTool->>Ripgrep: spawn([rgPath, ...args])
    
    Note over Ripgrep,GrepTool: Stream output instead of buffering
    
    loop Stream chunks until MATCH_LIMIT or done
        Ripgrep-->>GrepTool: ReadableStream chunk
        GrepTool->>GrepTool: decoder.decode(value, {stream: true})
        GrepTool->>GrepTool: buffer += decoded, split by \r?\n
        GrepTool->>GrepTool: Parse lines into matches[]
        
        alt matches.length >= MATCH_LIMIT
            GrepTool->>Ripgrep: proc.kill()
            Note over GrepTool: Early termination saves resources
        end
    end
    
    GrepTool->>TruncationSystem: Truncate.output(result)
    TruncationSystem->>TruncationSystem: Check MAX_LINES (2000) & MAX_BYTES (50KB)
    TruncationSystem-->>GrepTool: {content, truncated: bool}
    
    GrepTool-->>Agent: Tool result with metadata
    Agent->>UI: Display results with spinner
    
    Note over UI: Spinner shows for running tools
    
    UI->>UI: createMemo(() => part.state.status === "running")
    UI->>UI: Show spinner in theme.primary color
    
    UI-->>User: Results displayed with visual feedback
Loading

Resolved merge conflicts between upstream v1.1.6 and shuvcode fork:

Build & CLI:
- packages/opencode/script/build.ts: Keep fork's shuvcode binary naming, add upstream's --use-system-ca flag

Desktop App:
- packages/desktop/src-tauri/src/lib.rs: Preserve Shuvcode branding, adopt upstream's async server startup pattern
- packages/desktop/src/index.tsx: Accept upstream's auto-zoom fix and serverReady integration

App Core:
- packages/app/src/app.tsx: Preserve fork's __SHUVCODE__ window interface, add upstream's serverReady property
- packages/app/src/components/terminal.tsx: Keep fork's MobileTerminalInput, add upstream's withAlpha/HexColor
- packages/app/src/context/layout.tsx: Merge fork's theme/font imports with upstream's Persist/removePersisted
- packages/app/src/context/server.tsx: Migrate to upstream's Persist.global() with ["server.v4", "server.v3"] migration
- packages/app/src/pages/layout.tsx: Adopt upstream's improved projectSessions() with sandbox support

TUI & Session:
- packages/opencode/src/cli/cmd/tui/routes/session/index.tsx: Fix duplicate RGBA import, merge fork's dialog/renderer with upstream's local/iconColor
- packages/opencode/src/cli/cmd/tui/attach.ts: Keep fork's explicit directory resolution
- packages/opencode/src/session/prompt.ts: Accept upstream's permission system improvements
- packages/opencode/src/tool/task.ts: Merge fork's Provider import with upstream's filterSubagents()

VSCode Extension:
- sdks/vscode/package.json: Preserve fork branding (name=shuvcode, publisher=latitudes-dev), update version to 1.1.6

Dependencies:
- bun.lock: Accept upstream version, regenerated with bun install

Upstream features merged:
- Night Owl theme support
- iOS Safari auto-zoom fix
- Theme reload functionality
- Non-ASCII path encoding fix
- Session truncation improvements
- Permission system enhancements
- Billing/migration updates
- Add missing onMount import in theme.tsx
- Add null check for command object in prompt.ts to prevent 'possibly undefined' errors
Add spinner animation to InlineTool and BlockTool components when tool
state is 'running'. Previously spinner only showed in sidebar and for
bash commands. Now all tool types display the configurable spinner.
Cherry-pick from upstream PR anomalyco#5432 (anomalyco/opencode).

- Stream ripgrep output line-by-line instead of buffering into memory
- Kill ripgrep early after 100 matches to save resources
- Remove per-file stat() calls for significant performance improvement
- Handle Windows line endings in streaming context

Trade-off: Results no longer sorted by modification time.
@shuv1337 shuv1337 merged commit d1f98e1 into integration Jan 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants