33 Commits

Author SHA1 Message Date
Will Sather
be582e90c3
fix: disconnected github dialog and failed connection info (#847)
* fix: disconnected github dialog and failed connection info

* fix: lint

* fix: tests
2026-04-22 20:22:06 -07:00
open-agents-bot[bot]
9679c867ce
chore: rename open-harness to open-agents (#703)
* refactor: rename open-harness to open-agents

* refactor: replace ai-sdk import with inline FetchFunction type

* refactor: rename "Open Agents" to "Open Agent"

* fix: align chat runtime package imports

---------

Co-authored-by: willsather <56037657+willsather@users.noreply.github.com>
Co-authored-by: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>
2026-04-20 23:09:41 -05:00
Will Sather
cee13abfaa
feat: replace manual oauth with better-auth (#820)
* feat: replace manual oauth with better-auth

* fix: lint

* chore: refactor accounts to unify github + vercel

* feat: enhance auth config with host allowlisting

Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>

* fix: add newline at end of manifest.json

Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>

* fix: update betterAuth database schema mappings

Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>

* fix: sanitize redirects and preserve destination in github flow

Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>

* feat: enhance GitHub app callback with installation sync tracking

Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>

* build: add BETTER_AUTH_SECRET to turbo env

Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>

* refactor: update sign-in callback to skip onboarding

Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>

---------

Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
Co-authored-by: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>
2026-04-20 15:40:13 +01:00
Will Sather
d221c58c2d
fix: remove sensitive data from error logs (#740)
Co-authored-by: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>
2026-04-14 11:38:50 +02:00
willsather
d428542158 fix: await async getAppCoAuthorTrailer call and fetch bot user ID 2026-04-14 01:49:43 +00:00
willsather
6d5ff74f3a feat: add co-author trailer for agent in commits 2026-04-14 01:36:53 +00:00
open-agents-bot[bot]
4628543292
refactor: migrate GitHub operations to use OAuth tokens (#723)
* refactor: remove unused GitHub repos API and installation endpoints

* refactor(github): prefer user OAuth tokens for user-initiated actions

* refactor: migrate user GitHub ops to OAuth tokens

* refactor: simplify OAuth token handling with single token

---------

Co-authored-by: willsather <56037657+willsather@users.noreply.github.com>
Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
2026-04-14 03:18:32 +02:00
nicoalbanese
b2cd4dab1d fix: github scope issues 2026-04-13 22:44:09 +01:00
open-agents-bot[bot]
66aa7e5032
fix: unstable_cache on github api (#716)
* refactor: remove cached-api in favor of direct fetch functions

* fix: update auto-pr test mocks for cached-api removal

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: willsather <56037657+willsather@users.noreply.github.com>
Co-authored-by: willsather <will@sather.ws>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 21:19:57 +01:00
Nico Albanese
5044d03bcf
remove cache on installations (#715)
* remove cache on installations

* update

* format fix

* update
2026-04-13 19:52:47 +00:00
open-agents-bot[bot]
0441f1f49c
feat: add GitHub installation reconnection flow (#692)
* docs: revise plan for live GitHub connection health checks

* feat: add GitHub installation reconnection flow

* feat: improve GitHub auth detection and handle connection loading

---------

Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
2026-04-10 18:23:59 +01:00
open-agents-bot[bot]
d430e52b91
fix: improve GitHub connected accounts loading and UI components (#693)
* fix: handle expired tokens in GitHub connected accounts

* fix: use GitHub orgs API instead of memberships for org list

* fix: add debug logging for GitHub API errors in install-status

* fix: improve GitHub connected accounts UI and avatar handling

* fix: improve connected accounts loading and UI components

* style: format code for improved readability

---------

Co-authored-by: willsather <56037657+willsather@users.noreply.github.com>
2026-04-10 16:58:59 +00:00
open-agents-bot[bot]
998327b6aa
feat: add branch search with query parameter (#672)
* feat: add branch search with query parameter

* style: add newline at end of manifest.json

---------

Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
2026-04-10 13:31:53 +00:00
willsather
01ef5a1dc9 refactor: consolidate accounts and usage into profile page 2026-04-09 14:36:07 +00:00
openharness[bot]
8929159159
feat: add branch limiting support to GitHub API (#625)
Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
2026-04-07 17:35:59 +00:00
openharness[bot]
dfcc315ecf
feat: auto-archive sessions on PR closure (#393)
* feat: auto-archive sessions when PR is closed

* refactor: extract session archival logic into reusable helper

* chore: upgrade @types/bun and bun-types to 1.3.11

* feat: add archive finalization failure recovery

* fix: setup module mocking before test imports

---------

Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
2026-03-19 10:20:29 -07:00
openharness[bot]
59909f1bf0
refactor: extract API helpers and consolidate session context logic (#446)
* test: add comprehensive tests for delete message endpoint

* refactor: extract session auth checks into reusable helpers

* docs: add test:verbose script and align formatting in AGENTS.md

* style: format test file with consistent indentation

* test: add isolated test runner and update sandbox status mocks

* refactor: consolidate session auth checks into reusable helpers

* feat: extract PR generation helpers into separate module

* test: add comprehensive test coverage for PR generation helpers

* docs: remove completed API refactoring plan

* style: format function signatures and long lines

* test: refactor session API route mocks to use session-context

---------

Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
2026-03-13 22:48:18 +00:00
openharness[bot]
bd35727d16
fix: resolve manage repo access 404 by using app slug (#326)
Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
2026-03-02 14:26:12 +00:00
openharness[bot]
f401b3c761
feat: use GitHub account data for git user configuration (#312)
Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
2026-02-26 11:10:37 +00:00
openharness[bot]
5d1748c166
fix: remove duplicate bot co-author trailer in commits (#211)
Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com>
Co-authored-by: openharness[bot] <2836518+openharness[bot]@users.noreply.github.com>
2026-02-20 18:30:29 +01:00
Nico Albanese
6603081f4d
feat: add co-author trailer for GitHub App commits (#204)
* feat: add co-author trailer for GitHub App commits

* chore: format api routes
2026-02-20 16:58:21 +01:00
Nico Albanese
049c86dcbd
Improve React performance, loading states, and session layout (#198)
* Improve React performance: parallelize fetches, dynamic imports, memoization

- Parallelize independent server-side data fetches with Promise.all in page.tsx
- Add next/dynamic for DiffViewer, CreatePRDialog, CreateRepoDialog modals
- Add optimizePackageImports for lucide-react in next.config.ts
- Memoize SessionChatContext provider value (36 properties)
- Memoize derived state (renderMessages, lastMessage, showThinkingIndicator)
- Convert sandboxUiStatus IIFE to useMemo
- Use messages.length in scroll effect dependency array
- Update audit doc to mark fixed items

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Address remaining React best practices audit items

- Add loading.tsx/error.tsx for key route segments (Suspense boundaries)
- Replace hasMounted useState+useEffect with useSyncExternalStore
- Extract ChatSidebar component from monolithic SessionChatContent
- Replace direct fetch with SWR in CreateRepoDialog for cache sharing
- Convert conditional && rendering to explicit ternaries
- Remove unused react-hook-form, @hookform/resolvers, form.tsx, chat-context.tsx

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Move sidebar to session layout so it persists during chat navigation

The loading spinner was replacing the entire page (including sidebar)
when switching between chats, causing a jarring flash. By introducing a
Next.js layout at the session level, the sidebar stays mounted and only
the chat content area shows the loading state during navigation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Show session name and input shell in chat loading state

Instead of a full-page spinner, the chat loading state now preserves
the header (with real session/repo name from layout context) and an
input area shell so only the messages area shows the loading spinner.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix input height mismatch in loading skeleton and suppress overlay flash

Use a real disabled textarea in the loading skeleton so height matches
the actual input exactly. Also hide the sandbox overlay during initial
reconnection (idle state) to prevent the Resume/Create buttons from
flashing briefly on navigation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Improve web chat route responsiveness by removing fetch waterfalls, caching repeated setup work, and trimming initial session payloads.

* Improve chat UI responsiveness with memoized message grouping and smarter polling backoff.

* Improve GitHub repo fetch performance with cached installation queries

* Fix chat auto-scroll during streaming updates

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 16:27:48 +01:00
Nico Albanese
11fc722ed7
fix: refresh expired GitHub OAuth tokens instead of silently failing (#192)
* fix: refresh expired GitHub OAuth tokens instead of silently failing

GitHub Apps with expiring user tokens issue tokens that expire after ~8h.
The OAuth exchange was ignoring refresh_token and expires_in from GitHub's
response, so after expiration all GitHub API calls returned 401, causing
the connector page to show a blank state.

Store refresh_token/expiresAt during OAuth exchange, and add inline token
refresh logic to getUserGitHubToken (mirroring the existing Vercel token
refresh pattern). Existing users will need to reconnect GitHub once to
pick up a refresh token.

* fix: harden GitHub token refresh against DB persistence failures

Return the refreshed token even if persisting to the database fails,
preventing a permanently broken GitHub connection when the refresh
token has already been consumed. Also add response.ok check before
parsing the refresh response body.
2026-02-18 16:10:39 +01:00
Nico Albanese
68e5f53a34
Fix PR generation fork fallback and permission error detection (#187)
* Improve public repo PR flow with fork and compare fallbacks

* fix: preserve fork head owner when branch is already pushed

* fix: gate fork fallback on permission errors only

Non-permission push failures (e.g. rejected/non-fast-forward) now fall
through to informative error handling instead of triggering fork creation.

* fix: tighten permission error heuristic and use actual fork repo name

- Replace broad substring matches ('permission', '403', 'denied') in
  isPermissionPushError with specific git error patterns to avoid false
  positives from commit messages or ref names.
- Parse actual fork repo name from GitHub API response in ensureForkExists
  instead of assuming it matches the upstream repo name, handling cases
  where GitHub appends a suffix due to naming conflicts.
2026-02-18 12:40:18 +01:00
Nico Albanese
829fccae13
fix: resolve GitHub App install redirect loop (#176)
* fix: resolve GitHub App install redirect loop

The install flow was stuck in a circular loop because `cookies()` from
`next/headers` combined with `Response.redirect()` silently drops
Set-Cookie headers — the state cookie was never sent to the browser, so
CSRF validation always failed on the callback.

- Switch install and callback routes to `NextResponse.redirect()` with
  `response.cookies.set()` to ensure cookies are in redirect responses
- Add three-path install routing: OAuth for unlinked accounts,
  direct install for linked accounts without installations,
  select_target picker for accounts with existing installations
- Chain OAuth callback to install flow when code arrives without
  installation_id, so account linking + app install is one continuous flow
- Relax state validation to only require matching state when an OAuth
  code is present (not for installation-only callbacks)
- Return GitHub user ID from OAuth exchange for install chaining
- Add externalUserId to getGitHubAccount return type

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix GitHub app install flow sync gaps

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 22:33:49 +01:00
Nico Albanese
8ba6551e46
Fix GitHub App install flow to use OAuth for initial connect (#166)
* Update GitHub App install flow documentation

* Refactor GitHub App install route flow logic
2026-02-11 10:29:27 +01:00
Nico Albanese
a6177acd41
feat: unified GitHub App install + OAuth flow with per-org install UI (#165)
* feat: unified GitHub App install + OAuth flow with per-org install UI

Replaces the two-step OAuth-then-install flow with a single GitHub App
installation flow that handles OAuth authorization inline (via GitHub's
'Request user authorization during installation' setting).

- Add app callback OAuth code exchange so install + account link happen
  in one redirect
- Use /installations/select_target URL to always show the account/org
  picker (fixes redirect to existing personal install settings)
- Add per-org install via target_id for direct org install links
- Add /api/github/orgs/install-status endpoint returning per-org
  install state with GitHub IDs
- Rebuild accounts settings page with per-org status rows, install/
  configure actions, request-access guidance, and post-return toasts
- Delete the separate OAuth link routes (no longer needed)
- Add sonner for toast notifications
- Update repo-selector-compact wording to 'Install to organization'
- Document GitHub App setup requirements (public app, OAuth during
  install, callback URL) in .env.example and AGENTS.md

* Fix GitHub app callback auth and installation sync pagination

* Fix GitHub reconnect after disconnect skipping install page

After disconnecting GitHub, the app only revoked the OAuth token but the
GitHub App installation remained. Clicking Connect again sent users to
the install page which redirected to existing installation settings
instead of re-authorizing.

Use a github_reconnect cookie set during disconnect to route reconnects
through the OAuth authorize URL, re-linking the account and syncing
existing installations without requiring a fresh app install.

* Fix installation upsert conflict and initial repo push token

* Fix repo creation to use installation tokens and add owner picker

Use installation tokens for org repo creation (createInOrg) and user
OAuth tokens for personal accounts. Add account/org picker to the
create repo dialog so users select where to create the repository.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix repo creation push token and missing installation handling

Return an error when the requested owner has no GitHub App installation
instead of silently falling back to the user's personal account. Use
installation token for push only on org repos — personal accounts use
the OAuth token that created the repo to avoid permission gaps when the
installation has "selected repositories" access.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 20:43:44 +01:00
Nico Albanese
6474c269ef
web: add repo search limits and cache revalidation (#148) 2026-02-05 18:57:42 +00:00
Nico Albanese
0f272a7fff
refactor: migrate from tasks to sessions/chats model (#147)
* refactor: migrate from tasks to sessions/chats model

Restructure the data model to support sessions containing multiple chats
that share a sandbox. This enables multi-chat workflows within a single
session context.

- Rename tasks to sessions throughout the codebase
- Add chats table with foreign key to sessions
- Update all API routes to use session/chat ownership verification
- Migrate hooks from use-tasks to use-sessions/use-session-chats
- Add new session-starter and session-list components
- Update sandbox management to work with session-based model

* style: fix formatting issues in web app
2026-02-05 12:32:32 +00:00
Nico Albanese
9ccd4c82f1
Replace sandbox state null checks with active state validation (#108)
* Add token usage reporting for subagents

Display input tokens inline in task views next to tool count and duration.
Shows tokens while streaming and final count on completion.

Changes:
- Add messageMetadata callback to task tool to attach usage data
- Add token display to TUI and web task-group-view components
- Add tokens to task-renderer completion views
- Refactor web task-renderer to use proper types instead of casts
- Switch tool-call.tsx to narrow on part.type instead of derived string
- Add SubagentUIMessage type for proper typing of subagent output

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Consolidate formatTokens and improve type safety

- Move formatTokens to shared package to eliminate duplication across 4 files
- Add getToolSummary helper with proper type narrowing (replaces unsafe cast)
- Simplify IIFE patterns to ternary expressions in task renderers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Migrate from custom blob snapshots to native Vercel snapshots

Replace the custom tarball-based snapshot system with Vercel's native
snapshot API. This simplifies the codebase and removes the @vercel/blob
dependency.

Key changes:
- snapshot() now uses native SDK method (automatically stops sandbox)
- Restoration happens at sandbox creation via source: { type: 'snapshot' }
- Added backwards compatibility for legacy blob URLs (https://)
- Removed SnapshotOptions, renamed RestoreOptions to LegacyRestoreOptions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix code review issues from snapshot migration

- Configure git user after native snapshot restoration in vercel and hybrid sandboxes
- Only render expanded input when non-empty in task-renderer
- Restore getToolSummary fallback for unknown tool types
- Remove legacy blob snapshot code (isLegacySnapshot, restoreLegacySnapshot, LegacyRestoreOptions)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Extract configureGitUser utility and remove legacy blob comments

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add sandbox snapshot reliability plan

Documents two approaches for ensuring sandboxes are snapshotted before
timeout even when clients are inactive:
- Approach A: Snapshot after every assistant response + auto-extend
- Approach B: Cron-based snapshot for sandboxes near expiration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Preserve sandbox type on stop/snapshot for correct restoration

- Add isSandboxActive() type guard and clearSandboxState() helper
- Update API routes to use isSandboxActive() for active sandbox checks
- Preserve sandbox type in sandboxState when stopping/snapshotting
- Fix snapshot restoration to not create sandbox first (was preventing
  snapshot restore due to sandboxId taking precedence over snapshotId)
- Update frontend task context to preserve type on state clearing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add expiresAt tracking to sandbox state for client-side expiration checks

Store expiresAt timestamp in persisted sandbox state so the client can
immediately determine if a sandbox has expired without making a network
call. This fixes the issue where the UI shows "active" for expired
sandboxes until a network call fails.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix sandbox timeout snapshot and cleanup flow

- Add canOperateOnSandbox() to allow operations on expired sandboxes
- Make DELETE /api/sandbox idempotent (return success if already stopped)
- Fix snapshot response parsing to use snapshotId instead of downloadUrl

The client was looking for 'downloadUrl' but the API returns 'snapshotId',
causing the task's snapshotUrl to never be updated locally. This made the
UI show "Create sandbox" instead of "Resume sandbox" after timeout.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* add comment

* Fix sandbox utils type safety and snapshot restore race condition

- Add comprehensive JSDoc comments to isSandboxActive and canOperateOnSandbox
- Extract hasRuntimeState helper to reduce code duplication
- Fix clearSandboxState to use explicit switch instead of type cast
- Add null check for getState result in extend route
- Prevent snapshot restore while sandbox is running (race condition fix)
- Only pass type and snapshotId when restoring (avoid stale sandboxId)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Consolidate sandbox timeout configuration into single file

- Create apps/web/lib/sandbox/config.ts with timeout constants
- Replace hardcoded 300_000 values across web app with shared constants
- DEFAULT_SANDBOX_TIMEOUT_MS for new sandboxes
- EXTEND_TIMEOUT_DURATION_MS for timeout extensions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix sandbox timeout propagation and client display on refresh

- Add timeout option to ConnectOptions and pass through to Vercel SDK
- Pass DEFAULT_SANDBOX_TIMEOUT_MS when creating sandboxes in web app
- Return expiresAt from reconnect endpoint for accurate client display
- Calculate remaining timeout from expiresAt on reconnect (not default)
- Pass remainingTimeout when restoring from snapshot
- Display remaining seconds next to sandbox status indicator

Previously, the timeout was only sent to the client but not to the SDK,
causing sandboxes to use the SDK's 300s default. On refresh, the client
would also reset to the default instead of showing actual remaining time.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* update

* Fix timeout propagation when restoring hybrid sandbox from snapshot

Pass remainingTimeout to VercelSandbox.connect() during snapshot restoration,
matching the pattern in vercel/connect.ts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 23:08:28 +00:00
Nico Albanese
312e644102
Replace hardcoded Vercel imports with unified connectSandbox API (#91)
* Add hybrid sandbox architecture research and test scripts

- Document hybrid sandbox design for eliminating cloud sandbox startup latency
- Add test scripts validating JustBash + Vercel parallel startup approach
- Test tarball loading, handoff mechanism, serialization, and pending ops replay
- Document serialization API design decision (class-level methods on JustBashSandbox)
- Add tar dependency for GitHub tarball extraction

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add serialization API to JustBashSandbox for serverless persistence

Implement serialize() and fromSnapshot() methods to enable JustBash state
persistence across serverless request boundaries. This is a key building
block for the hybrid sandbox architecture.

Changes:
- Add serialize() instance method to export sandbox state
- Add fromSnapshot() static factory to restore from snapshot
- Export JustBashSnapshot type from @open-harness/sandbox
- Update createJustBashSandbox() return type to JustBashSandbox
- Use FsEntry type directly from just-bash library

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add JustBash persistence for serverless (Milestone 1)

- Add justBashSnapshot column to tasks table for storing serialized
  JustBash state across serverless request boundaries
- Fix JustBashSandbox to use native bash.readFile/writeFile methods
  instead of shell commands (preserves whitespace correctly)
- Fix fromSnapshot to restore empty directories
- Add test endpoint at /api/test/justbash-persistence to validate
  persistence flow (create -> serialize -> restore -> verify)

Results: 6ms restore time, 769 bytes state size, all files persist

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add GitHub repo loading in JustBash (Milestone 2)

- Add tarball utility to download and extract GitHub repos
- Filter binary files and lock files to reduce snapshot size by 87%
- Add JustBash init endpoint (/api/sandbox/justbash)
- Add test endpoint (/api/test/justbash-repo)
- Integrate JustBash support into chat route
- Support both JustBash and Vercel sandbox modes

Milestone 2 results:
- Tarball load: 345ms (target < 500ms)
- Restore time: 2ms (target < 10ms)
- Full repo + modifications persist across requests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add JustBash web integration experiment notes

Documents the experimental changes tested to bypass Vercel sandbox
and use JustBash directly in the web app. Includes warnings that
this is not a production-ready approach.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add background Vercel startup (Milestone 3)

- Add vercelStatus, vercelStartedAt, vercelError fields to tasks schema
- Create /api/sandbox/vercel-background endpoint for background startup
- Create /api/test/hybrid-background test endpoint
- Add test script: scripts/test-milestone3.ts

Results: JustBash ready in 727ms, Vercel in 8.75s (12x speedup)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add seamless handoff from JustBash to Vercel (Milestone 4)

- Add pendingOperations and sandboxMode columns to tasks schema
- Create HybridSandbox wrapper class that tracks write operations
- Add handoff API endpoint (GET status, POST perform handoff)
- Add test endpoint and script for Milestone 4 validation

Results: All writes replay correctly (5 ops), files verified in Vercel,
git works after handoff, handoff time 2.98s (< 5s target).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add Milestone 5: Chat route integration plan

Documents the steps needed to integrate HybridSandbox into the
web chat route for seamless automatic handoff from JustBash to Vercel.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Implement hybrid sandbox for instant startup (Milestone 5)

- Modify /api/sandbox to use JustBash immediately (~300-500ms) instead of
  blocking for Vercel (~10s). Vercel starts in background.
- Update /api/chat to wrap JustBash in HybridSandbox for write tracking
- Add automatic handoff: when Vercel ready, replays pending ops and switches
- Fix sandbox validation to handle hybrid placeholder IDs after handoff
- Add test endpoint and script for Milestone 5 validation

User can now start chatting immediately after task creation. Vercel
capabilities (git, npm) become available after background startup completes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Keep reconnects on Vercel-only path for now

Hybrid approach only for new tasks. Reconnects use Vercel directly
to preserve uncommitted changes. Hybrid reconnect with snapshot
restoration is a future improvement.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* add sandbox consumer abstraction desing

* Rename sandbox abstraction concepts for clarity

- getSandbox() → connectSandbox() (better conveys connection semantics)
- SandboxPayload → SandboxState (captures round-trip nature)
- JustBashState/VercelState/HybridState → *Config (these are init params)
- Flatten discriminated union (remove nested state property)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add folder restructure as prerequisite for sandbox abstraction

- Create sandbox-folder-restructure.md documenting the reorganization
  of sandbox implementations from single files into self-contained folders
- Update sandbox-abstraction-design.md to reference the folder
  restructure as a prerequisite and colocate state types with
  their implementations (*/connect.ts pattern)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Rename state.ts to factory.ts in sandbox design docs

Factory better describes the purpose - it's a factory function that
takes config and returns the right sandbox instance.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Restructure sandbox package into self-contained folders

Reorganize sandbox implementations from single files into folders to
enable cleaner separation between sandbox classes, config types, and
future connect functions for the abstraction layer.

- Add shared types.ts with Source, FileEntry, PendingOperation
- Move LocalSandbox to local/sandbox.ts with index.ts re-export
- Move VercelSandbox to vercel/sandbox.ts with config.ts for types
- Move JustBashSandbox to just-bash/sandbox.ts with snapshot.ts
- Update package.json exports for bundler compatibility
- Use extensionless imports for Next.js Turbopack compatibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Mark sandbox folder restructure as complete in docs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Update todos

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Implement unified sandbox abstraction layer

Add connectSandbox() factory function that provides a single entry point
for creating, restoring, or reconnecting to any sandbox type. The state
shape determines behavior internally.

Changes:
- Add SandboxState union type and ConnectOptions interface
- Add state types (JustBashState, VercelState, HybridState)
- Add connect functions for each implementation
- Add getState() and status to all sandbox classes
- Move HybridSandbox from apps/web to packages/sandbox/hybrid/
- Add SandboxStatus type for lifecycle tracking

The consumer API is now:
  const sandbox = await connectSandbox(state, { env, gitUser, hooks });
  const newState = sandbox.getState(); // round-trip ready

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Update AGENTS.md: do not use .js extensions in imports

The .js extension causes module resolution issues with Next.js/Turbopack.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add technical debt note for .js extension cleanup

packages/shared still uses .js extensions in imports which can cause
issues with Next.js/Turbopack.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* update todos

* step 8 migrate web ui to unified sandbox

* Improve hybrid sandbox reconnect and handoff handling

- Simplify ReconnectResponse type and handle pre-handoff hybrid state
- Add race condition documentation and stop unused Vercel sandboxes
- Add error tracking for pending operation replay during handoff
- Fix missing sandboxInfo dependency in handleKillSandbox callback

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Mark sandbox abstraction migration steps 7-8 as complete

Web app now uses unified sandboxState API and old schema fields
have been removed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* add plans

* Implement hybrid sandbox completion plan with unified API

- Add HybridHooks interface with onCloudSandboxReady/onCloudSandboxFailed
- Add SandboxConnectConfig discriminated union for type-safe config
- Add HybridConnectOptions with registerBackgroundTask support
- Update connectHybrid to automatically start cloud sandbox in background
- Migrate web app sandbox route to use unified connectSandbox API
- Remove direct provider imports from web app (now uses abstraction)
- Export new types: HybridHooks, HybridConnectOptions, SandboxConnectConfig

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Replace registerBackgroundTask with callback-based scheduleBackgroundWork

Change the background task API from promise-based to callback-based for
framework-agnostic serverless support:

- Next.js after(): scheduleBackgroundWork: (cb) => after(cb)
- Vercel waitUntil(): scheduleBackgroundWork: (cb) => waitUntil(cb())
- Cloudflare Workers: scheduleBackgroundWork: (cb) => ctx.waitUntil(cb())

The callback approach defers execution until the runtime invokes it,
allowing each framework to control when work begins.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Always use hybrid sandbox and spin up cloud in background

- Simplify sandbox route to always use hybrid mode (remove Vercel fallback)
- Start cloud sandbox in background even without a source/repo
- Add getState() to Sandbox interface to avoid instanceof checks
- Add debug logging for background sandbox startup flow

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix null safety issues in HybridSandbox state transitions

- Fix potential null pointer dereference in `current` getter by adding
  explicit null checks instead of non-null assertion
- Handle "switching" state properly in both `current` and `getState()`
- Throw descriptive error if sandbox reaches invalid state
- Ensure vercel-based state is returned during/after handoff to prevent
  stale JustBash state from being persisted

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add sandbox type switcher to task input

Add a dropdown selector in the task input toolbar that allows users to
choose between hybrid, vercel, and just-bash sandbox types. The selected
type is passed via URL parameter to the task detail page where it's used
when creating the sandbox. The sandbox type is shown in the header tooltip
when hovering over the active indicator.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* add potential plan

* update sandbox labels

* Add documentation for git simulation in in-memory sandboxes

Documents the approach, architecture, and implementation details for
simulating git commands in in-memory sandboxes. Includes rationale for
why this approach is NOT appropriate for scratchpad-style sandboxes
(like JustBash) where a file browser is more suitable.

Preserved for future reference if needed for sandboxes where changes
are meant to be integrated into real codebases.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Disable diff button for in-memory sandboxes

The diff feature relies on git which isn't available in just-bash mode.
Button is now disabled with a tooltip explaining the limitation.
Also fixed the button to be disabled by default until diff data exists.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix sandbox status indicator for in-memory sandboxes

Update sandbox type in client state immediately after creation instead
of requiring a page refresh. Hide the stop/pause button for just-bash
sandboxes since they're in-memory and don't need to be stopped.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Disable timeout for in-memory sandboxes

Return timeout: null for just-bash sandboxes from the API. The client
now respects this by skipping the countdown timer and showing the
sandbox as always-active with an "in-memory" label.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Hide create repo button for in-memory sandboxes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Remove hybrid sandbox test files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* update lock

* Fix sandbox state persistence for all sandbox types

The chat route was only persisting state for HybridSandbox instances,
causing file modifications to be lost when using just-bash or vercel
sandbox types. Changed to check for getState method existence instead,
matching the pattern in /api/sandbox/route.ts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* do not open diff panel for just-bash

* Skip snapshot save for just-bash sandboxes

just-bash sandboxes persist state via getState() after each message,
so filesystem snapshots are unnecessary and unsupported.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix race condition in hybrid sandbox state persistence

The chat route's onFinish was overwriting the sandboxId set by
background work. Now checks if background work has already set
a sandboxId before persisting state, preventing the race condition.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 10:28:52 +00:00
Nico Albanese
1b69da92e7
Add GitHub repository creation feature for tasks (#67)
* Make sandbox creation work without a repository

* Add createRepository function to GitHub client

* Add create-repo API endpoint with git operations

* Add Switch component from radix-ui

* Add CreateRepoDialog component

* Support sandboxes without repos and add create repo flow

* fix: security and validation improvements for create-repo flow

- Fix command injection vulnerability in git config commands by escaping shell args
- Add explicit validation for cloneUrl/owner/repoName after repo creation
- Improve error messages to inform users when repo was created but push failed
- Sanitize taskTitle input (limit length, strip special chars) for AI prompt
- Align UI validation text with server-side rules (include periods)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Update apps/web/app/api/github/create-repo/route.ts

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>

* Initialize git repo in empty sandboxes for diff viewer compatibility

Empty sandboxes (no source repo) now get git init + an empty initial commit,
allowing git diff HEAD to work consistently. This fixes the diff viewer
failing with "not a git repository" for tasks created without a clone URL.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
2026-01-12 16:26:59 +00:00
Nico Albanese
0d28d0105a
Add GitHub authentication and repository management (#63)
* Add GitHub OAuth authentication routes

* Add GitHub API endpoints for repos and user data

* Add session and crypto utilities

* Add database schema and client setup

* Add database migrations

* Add GitHub utility functions and client

* Add authentication components and hooks

* Add repo info to chat context

* Add GitHub token to sandbox API

* Pass GitHub token to chat sandbox

* Integrate repo selection and display in chat

* Add dependencies for auth and database

* Add branch selector API endpoint

* Create branch selector component

* Add UI component library base components

* Add cmdk and popover dependencies

* Replace input field with branch selector component

* update repo selector to be combo box

* fix scroll gutter bg

* update branch selector component width

* remove storage and update todos

* fix cc comments

* add caching

* cc fixes
2026-01-11 18:32:06 +00:00