Skip to content

Fix packaged skills CLI runtime ownership - #11627

Merged
Jinwoo-H merged 3 commits into
mainfrom
fix-packaged-cli-skill-loader
Jul 31, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
fix-packaged-cli-skill-loader

Conversation

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Summary

The installed 1.4.163-rc.0 CLI fails before any orca skills command can dispatch because out/cli/handlers/skills.js eagerly requires source-shaped out/main/* files that are absent after Electron's bundled-main build.

Latest main already avoids the immediate crash with a copy-based Electron-entry workaround. This PR replaces that fragile packaging synchronization with an ownership fix:

  • move reusable Node-only command resolution, agent detection, and Windows batch spawning into concrete src/shared modules
  • keep the old main-process paths as compatibility re-exports
  • have skills and relevant account handlers import the CLI-safe owners directly
  • remove the accidental standalone Electron entries and asarUnpack copies
  • verify the real final CLI dependency closure and execute skills list, both bundled get guides, install dry-run, and update dry-run during release builds and afterPack

Root cause

build:cli emitted direct CommonJS requires for four src/main modules. The later build:electron-vite step replaces out/main with bundled/hash-chunk output, so those source-shaped paths disappeared. Read-only commands failed at handler load time even though they did not need mutation-time discovery or spawning.

The copy workaround on current main makes three manifests own the same dependency boundary: CLI TypeScript inputs, Electron main entries, and package unpack rules. Moving reusable functions to CLI-safe shared owners removes that synchronization requirement and keeps the Electron main graph out of the CLI.

Deterministic evidence

Affected release baseline 967edeb49a19271a64ccd006598878000b63c79f:

  • pnpm run build:cli && pnpm run build:electron-vite
  • node out/cli/index.js skills list --json → exit 1
  • node out/cli/index.js skills get orca-cli → exit 1
  • missing out/main/codex-cli/command.js; artifact inspection independently found all four required out/main files absent

Candidate:

  • identical release-order oracle passes
  • 379 confined closure files and five command executions pass
  • packaged macOS arm64 launcher passes help, list, both gets, install dry-run, and update dry-run outside the repository

Disabled fix:

  • restoring the old skills.ts main import while leaving copied entries removed makes the identical oracle exit 1 with missing runtime import "../../main/codex-cli/command"

Validation

  • pnpm typecheck
  • pnpm lint
  • focused suite: 11 files / 221 tests
  • full suite: 3,944 files passed, 9 skipped; 41,753 tests passed, 71 skipped
    • two unrelated relay assertions failed only with Orca's ambient GIT_CONFIG_COUNT=2; the file passes 10/10 with those ambient variables removed
  • pnpm run test:repro:skills-cli-runtime
  • pnpm run build:mac produced x64 and arm64 apps, ZIPs, and DMGs; both afterPack gates passed
  • node config/scripts/smoke-packaged-cli.mjs --app-dir=dist/mac-arm64/Orca.app
  • final architecture, adversarial package/reproduction, and performance reviews all clean

Platform coverage and risk

The real packaged launcher was executed on macOS arm64. macOS x64 was built and passed afterPack. Linux and Windows package execution was not available locally; path containment, separators, optional dependencies, command discovery, Windows batch spawning, SSH/headless behavior, and missing-resource failure are covered by shared runtime checks and tests.

The release gate adds five short Node subprocesses plus a bounded closure scan at build/package time only. Final performance review found no actionable regression. The main remaining risk is platform-specific packaging behavior not reproduced locally; CI packaging now runs the same closure and execution oracle for each artifact.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 22d8aeae-e2cd-4756-8eab-9779b98fe3f1

📥 Commits

Reviewing files that changed from the base of the PR and between 10b12ed and 59deda5.

📒 Files selected for processing (3)
  • .github/workflows/pr.yml
  • config/scripts/pr-workflow-parallelism.test.mjs
  • config/scripts/skills-cli-package-workflow.test.mjs

📝 Walkthrough

Walkthrough

The change centralizes CLI command resolution, TUI agent detection, local-agent install detection, and Windows batch spawning in shared modules while retaining compatibility re-exports. It adds AST-based runtime dependency validation and bounded command verification for the packaged Skills CLI. Electron packaging now unpacks the Codex runtime, rejects missing resources, and runs architecture-aware post-packaging verification. Build scripts, fixtures, smoke tests, bundle-parity checks, and Windows packaging workflow checks are updated accordingly.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.24% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: correcting packaged Skills CLI runtime ownership.
Description check ✅ Passed The description thoroughly covers the summary, root cause, implementation, validation, and platform risks, though several template sections are implicit or missing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (3)
src/shared/node-cli-command-resolution.ts (1)

134-170: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Redundant double-search in resolveCliCommand.

getVersionManagerDirectories already runs findFirstExecutable across all nvm version dirs (sorted newest-first) just to unshift the one matching directory; resolveCliCommand then re-runs findFirstExecutable over the resulting list, re-verifying the same file. Since getNvmVersionDirectories is already newest-first, concatenating it directly with the base dirs (as resolveCliCommands does) yields an identical result in a single pass, without the extra search/verification round-trip.

♻️ Simplification
-function getVersionManagerDirectories(
-  platform: NodeJS.Platform,
-  homePath: string,
-  executableNames: string[]
-): string[] {
-  const directories = getBaseVersionManagerDirectories(platform, homePath)
-  const firstNvmMatch = findFirstExecutable(
-    platform,
-    getNvmVersionDirectories(homePath),
-    executableNames
-  )
-  if (firstNvmMatch) {
-    directories.unshift(dirname(firstNvmMatch))
-  }
-  return directories
-}
+function getVersionManagerDirectories(
+  platform: NodeJS.Platform,
+  homePath: string
+): string[] {
+  return [...getNvmVersionDirectories(homePath), ...getBaseVersionManagerDirectories(platform, homePath)]
+}

Then drop the now-unused executableNames parameter from callers.

src/shared/windows-batch-spawn.ts (1)

1-4: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Hardcoded path separator instead of a path utility.

Per coding guidelines, path construction should use utilities like path.join rather than hardcoded separators. This builds a Windows path via a literal \\ template.

♻️ Suggested fix
+import { win32 } from 'node:path'
+
 /** Full path to cmd.exe for GUI and service-launched processes. */
 export function getCmdExePath(): string {
-  return process.env.ComSpec || `${process.env.SystemRoot ?? 'C:\\Windows'}\\System32\\cmd.exe`
+  return process.env.ComSpec || win32.join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'cmd.exe')
 }

Note: use path.win32.join specifically (not plain join), since this must always produce a Windows-style path regardless of the host OS running the code (e.g. in tests on macOS/Linux).

As per coding guidelines: "path utilities such as path.join instead of hardcoded separators."

Source: Coding guidelines

config/scripts/verify-skills-cli-runtime.cjs (1)

6-6: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Regex-based import scanning will hard-fail release builds on benign matches.

RUNTIME_IMPORT matches any require('x')/import('x') text, including occurrences inside comments, string literals, and unreachable branches of bundled third-party code. Every unresolvable hit throws unless the nearest manifest declares it optional, so a single such occurrence anywhere in the closure blocks packaging. Consider downgrading unresolved bare specifiers originating from node_modules to warnings (keep hard failures for first-party out/** files, which is the regression this verifier targets).

Also applies to: 13-15, 51-75


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e6d6789-fb9d-4331-af44-754bbf777a38

📥 Commits

Reviewing files that changed from the base of the PR and between abec358 and d5ddd8e.

📒 Files selected for processing (22)
  • config/electron-builder.config.cjs
  • config/scripts/electron-builder-config.test.mjs
  • config/scripts/smoke-packaged-cli.mjs
  • config/scripts/verify-skills-cli-runtime.cjs
  • config/scripts/verify-skills-cli-runtime.test.mjs
  • config/tsconfig.cli.json
  • electron.vite.config.ts
  • package.json
  • src/cli/handlers/account.test.ts
  • src/cli/handlers/account.ts
  • src/cli/handlers/skills.ts
  • src/cli/main-module-bundle-parity.test.ts
  • src/cli/skills.test.ts
  • src/main/codex-cli/command.ts
  • src/main/ipc/local-agent-install-dir-detection.ts
  • src/main/ipc/preflight.test.ts
  • src/main/ipc/tui-agent-detection-commands.ts
  • src/main/win32-utils.ts
  • src/shared/local-agent-install-dir-detection.ts
  • src/shared/node-cli-command-resolution.ts
  • src/shared/tui-agent-detection-commands.ts
  • src/shared/windows-batch-spawn.ts
💤 Files with no reviewable changes (1)
  • config/tsconfig.cli.json

Comment thread config/electron-builder.config.cjs Resolved
Comment thread src/shared/windows-batch-spawn.ts Resolved
@greptile-apps

greptile-apps Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a packaging bug where the bundled CLI failed at load time because build:electron-vite overwrites out/main/ with chunk-hashed output, deleting the four src/main files that out/cli/handlers/skills.js had required directly. The fix moves the shared, Node-only logic into src/shared/ modules and makes the src/main/ files thin re-exports, so the CLI dependency graph never crosses into the Electron-only build output.

  • Four new src/shared/ modules (node-cli-command-resolution, windows-batch-spawn, local-agent-install-dir-detection, tui-agent-detection-commands) own the CLI-safe implementation; src/main/ counterparts become one-line re-exports preserving Electron-main callers unchanged.
  • A new verify-skills-cli-runtime.cjs script (TypeScript-AST-based closure walker + five CLI smoke commands) is wired into build:desktop, build:release, and afterPack, giving deterministic per-build and per-artifact verification.
  • A new required package_windows CI job (windows-2022, 30 min) runs the full packaging + smoke oracle on every PR, closing the previously untested Windows packaging path.

Confidence Score: 5/5

Safe to merge — the root cause is clearly identified, the fix is mechanically straightforward (import-path redirection), and the new closure verifier plus five-command smoke oracle run at build, release, and package time to prevent the same class of regression from silently reappearing.

The change is a well-scoped ownership move: no logic was altered in the four shared modules (they are identical copies or thin wrappers), the src/main/ re-exports preserve backward compatibility for Electron-main callers, and the dual-layer verification gives strong structural confidence. The () addition to the Windows batch unsafe-syntax set is correct and explicitly tested. Full test suite (41k+ tests) and macOS arm64 packaged execution both passed.

Files Needing Attention: No files require special attention. The most scrutiny-worthy path is config/scripts/verify-skills-cli-runtime.cjs (the new closure oracle), which has comprehensive unit test coverage including optional-dependency, cross-artifact, and timeout edge cases.

Important Files Changed

Filename Overview
src/shared/node-cli-command-resolution.ts New authoritative home for CLI command resolution (moved from src/main/codex-cli/command.ts); public API is identical, resolveCliCommand has a minor internal refactor (nvm dirs searched separately before base dirs) that is behavior-equivalent.
src/shared/windows-batch-spawn.ts Extracted Windows batch-spawn helpers from src/main/win32-utils.ts; adds () to the unsafe-syntax regex, which is a correct security tightening since unquoted parentheses are cmd.exe group metacharacters.
config/scripts/verify-skills-cli-runtime.cjs New closure verifier: parses JS with TypeScript AST (typescript-api alias for TS 6.0.3), walks the CLI dependency graph from out/cli/index.js, enforces artifact boundary containment, and optionally spawns five CLI smoke commands. Well-covered by verify-skills-cli-runtime.test.mjs.
config/electron-builder.config.cjs Removes the four asarUnpack copy entries that were keeping src/main files alive post-electron-vite; afterPack now calls verifySkillsCliRuntime before daemon boot; silent early-return on missing resources dir replaced by a throw.
.github/workflows/pr.yml Adds package_windows (windows-2022, 30 min timeout) as a required gate in the verify aggregate; Windows job runs build:release to ensure-native-runtime to electron-builder --dir to smoke-packaged-cli.
src/cli/handlers/skills.ts Import sources updated from src/main/* to src/shared/* - the root cause fix that breaks the CLI dependency on post-electron-vite-deleted main files.
src/main/codex-cli/command.ts Reduced to a single re-export line pointing at src/shared/node-cli-command-resolution; existing Electron-main callers continue to work without changes.
package.json Adds verify:built-skills-cli and test:repro:skills-cli-runtime scripts; both build:desktop and build:release now include verify:built-skills-cli after build:electron-vite, ensuring the verification always runs in the correct post-vite order.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph CLI["CLI Handlers (src/cli/handlers/)"]
        S[skills.ts]
        A[account.ts]
    end

    subgraph Shared["src/shared/ (new - CLI-safe)"]
        NCR[node-cli-command-resolution.ts]
        WBS[windows-batch-spawn.ts]
        LAID[local-agent-install-dir-detection.ts]
        TAD[tui-agent-detection-commands.ts]
    end

    subgraph Main["src/main/ (re-exports only)"]
        CMD[codex-cli/command.ts]
        W32[win32-utils.ts]
        LAIDI[ipc/local-agent-install-dir-detection.ts]
        TADI[ipc/tui-agent-detection-commands.ts]
    end

    subgraph Verify["Build-time verification"]
        VR[verify-skills-cli-runtime.cjs]
        SM[smoke-packaged-cli.mjs]
    end

    S -->|import| NCR
    S -->|import| WBS
    S -->|import| LAID
    S -->|import| TAD
    A -->|import| NCR
    A -->|import| WBS

    CMD -->|export * from| NCR
    W32 -->|export * from| WBS
    LAIDI -->|export from| LAID
    TADI -->|export * from| TAD

    VR -->|closure walk + 5 CLI commands| S
    SM -->|help + skills list/get/install/update| S

    style Shared fill:#d4edda,stroke:#28a745
    style Main fill:#fff3cd,stroke:#ffc107
    style Verify fill:#cce5ff,stroke:#004085
Loading

Reviews (3): Last reviewed commit: "ci(cli): smoke packaged skills on Window..." | Re-trigger Greptile

@Jinwoo-H
Jinwoo-H merged commit 8f7692a into main Jul 31, 2026
52 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(cli): make packaged skills runtime self-contained

* fix(cli): address packaged skills review feedback

* ci(cli): smoke packaged skills on Windows

---------

Co-authored-by: OrcaWin <[email protected]>
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