Skip to content

feat: Add cross-platform detection (Claude Code + OpenCode support)#16

Open
Steffen025 wants to merge 1 commit intojcfischer:mainfrom
Steffen025:feature/platform-detection
Open

feat: Add cross-platform detection (Claude Code + OpenCode support)#16
Steffen025 wants to merge 1 commit intojcfischer:mainfrom
Steffen025:feature/platform-detection

Conversation

@Steffen025
Copy link

Summary

Adds platform detection module enabling SpecFlow to work on both Claude Code and OpenCode platforms without hardcoded paths.

Reference: This addresses the platform detection feature discussed in #8 (SpecFirst Integration Proposal), which @jcfischer welcomed for contribution.

What's Included

packages/specflow/src/lib/platform.ts (172 lines)

Function Purpose
detectPlatform() Detect Claude Code vs OpenCode via env vars or directory structure
getRootDir() Get platform root directory (~/.claude or ~/.opencode)
getPlatformInfo() Complete platform info including standard directories
resolvePath() Resolve relative paths to absolute based on platform
isOpenCode() / isClaudeCode() Platform check helpers

packages/specflow/tests/lib/platform.test.ts (303 lines)

  • 28 tests covering all functions
  • Environment variable scenarios
  • Path resolution edge cases
  • All tests passing

Detection Priority

  1. PAI_DIR environment variable (explicit override)
  2. OPENCODE_DIR environment variable (OpenCode specific)
  3. Directory structure detection (~/.claude vs ~/.opencode)
  4. Error if neither found

Usage Example

import { getRootDir, isOpenCode } from "./lib/platform";

// Instead of hardcoded:
// const envPath = `${homedir()}/.claude/.env`;

// Platform-agnostic:
const envPath = `${getRootDir()}/.env`;

// Or check platform:
if (isOpenCode()) {
  // OpenCode-specific logic
}

Testing

cd packages/specflow
bun test tests/lib/platform.test.ts
# ✓ 28 pass, 0 fail

Contributed by @Steffen025 + Jeremy (OpenCode/Claude Opus)

- Add platform.ts for detecting Claude Code vs OpenCode
- Supports PAI_DIR and OPENCODE_DIR environment variables
- Provides platform-agnostic path resolution
- Comprehensive test suite with 28 tests, all passing

Resolves jcfischer#8
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