Skip to content

Refactor: use compiled perry binary for container session discovery#13

Merged
gricha merged 1 commit intomainfrom
fix/opencode-session-list-refresh
Jan 6, 2026
Merged

Refactor: use compiled perry binary for container session discovery#13
gricha merged 1 commit intomainfrom
fix/opencode-session-list-refresh

Conversation

@gricha
Copy link
Copy Markdown
Owner

@gricha gricha commented Jan 6, 2026

Summary

  • Add perry worker subcommand with sessions list/messages commands
  • Compile perry to standalone binary during build (bun build --compile)
  • Copy perry binary to containers during sync (/usr/local/bin/perry)
  • Remove shell script approach (perry-session-reader.sh)
  • Share opencode-storage.ts between host and worker modes
  • Fix OpenCode sessions not showing up in web UI

Problem

OpenCode sessions weren't showing up in the web UI because the container didn't have the perry-session-reader.sh script - it was added after the Docker image was built. Rather than baking more scripts into the image (which requires rebuilding), we needed a better pattern.

Solution

Instead of separate tools baked into the Docker image, we now:

  1. Compile perry to a standalone binary during bun run build using bun build --compile
  2. Copy the binary to containers during perry sync to /usr/local/bin/perry
  3. Use perry worker sessions list/messages to discover sessions inside containers

This means:

  • No need to rebuild Docker images when session discovery logic changes
  • Single codebase for host and container session reading
  • Updates propagate immediately via perry sync

Changes

File Change
package.json Add build:worker script, remove workspace config
src/index.ts Add perry worker sessions list/messages subcommand
src/sessions/agents/opencode-storage.ts New shared module for reading OpenCode sessions
src/sessions/agents/opencode.ts Call perry worker instead of perry-worker
src/workspace/manager.ts Add copyPerryWorker() to sync binary to containers
src/agent/router.ts Use shared opencode-storage.ts for host sessions
perry/Dockerfile Remove perry-session-reader.sh reference
perry/scripts/perry-session-reader.sh Deleted
AGENTS.md Add manual testing instructions for port 7391
DESIGN.md Document perry-worker pattern

Testing

# Start test agent
pkill -f "perry agent" 2>/dev/null
perry agent run --port 7391 &
perry config worker localhost:7391

# Sync and verify
perry sync test
docker exec -u workspace workspace-test perry --version  # 0.2.1
docker exec -u workspace workspace-test perry worker sessions list  # JSON output

# Test API
curl -s -X POST "http://localhost:7391/rpc/sessions/list" \
  -H "Content-Type: application/json" \
  -d '{"json":{"workspaceName":"test"}}'

All automated tests pass (bun run validate).

@gricha gricha force-pushed the fix/opencode-session-list-refresh branch from 8a41375 to 5f9410f Compare January 6, 2026 23:03
@gricha gricha changed the title Fix OpenCode sessions not showing up immediately in sessions list Refactor: use compiled perry binary for container session discovery Jan 6, 2026
Copy link
Copy Markdown
Owner Author

@gricha gricha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Good refactoring that eliminates shell script duplication in favor of shared TypeScript. A few items to address:

1. DESIGN.md doesn't match implementation

The documentation describes a packages/opencode-sessions and packages/perry-worker structure with npm-based installation:

// perry/internal/src/lib/devtools.ts
const ensurePerryWorker = async () => {
  const installResult = await runCommand("npm", ["install", "-g", "@gricha/perry-worker"]);

But the actual implementation:

  • Uses src/sessions/agents/opencode-storage.ts (not a separate package)
  • Copies a compiled binary directly (not npm install)

Please update DESIGN.md to reflect what was actually built.

2. Silent failure when binary doesn't exist

In src/workspace/manager.ts:400-410:

try {
  await fs.access(workerBinaryPath);
} catch {
  return;  // Silently continues
}

If the binary doesn't exist, sync completes successfully but session discovery will fail later with a confusing error. Consider logging a warning here.

3. Binary name collision risk

const destPath = '/usr/local/bin/perry';

This overwrites any existing perry in the container. Consider using /usr/local/bin/perry-worker to avoid potential conflicts and make the purpose clearer.


Core approach is solid. These are minor cleanups.

@gricha gricha force-pushed the fix/opencode-session-list-refresh branch from 5f9410f to c7a48ba Compare January 6, 2026 23:11
Copy link
Copy Markdown
Owner Author

@gricha gricha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review: LGTM

Previous concerns addressed:

DESIGN.md - Now matches actual implementation
Warning on missing binary - Added console.warn during sync

One minor note: bun.lock still has entries for @gricha/opencode-sessions and @gricha/perry-worker packages that don't appear to be used in the final implementation. Consider cleaning those up if they're leftover from a different approach, but not blocking.

Ready to merge.

- Add perry worker subcommand with sessions list/messages commands
- Compile perry to standalone binary during build (bun build --compile)
- Copy perry binary to containers during sync (/usr/local/bin/perry)
- Remove shell script approach (perry-session-reader.sh)
- Share opencode-storage.ts between host and worker modes
- Update AGENTS.md with manual testing instructions for port 7391
- Fix OpenCode sessions not showing up in web UI

This replaces the npm-based perry-worker package with a compiled binary
that gets synced to containers, eliminating the need to publish a
separate package and ensuring the container always has the latest code.
@gricha gricha force-pushed the fix/opencode-session-list-refresh branch from c7a48ba to b0d0621 Compare January 6, 2026 23:21
@gricha gricha merged commit e48fd27 into main Jan 6, 2026
4 checks passed
@gricha gricha deleted the fix/opencode-session-list-refresh branch January 7, 2026 06:55
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.

1 participant