Repository navigation
Fix packaged skills CLI runtime ownership - #11627
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
src/shared/node-cli-command-resolution.ts (1)
134-170: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueRedundant double-search in
resolveCliCommand.
getVersionManagerDirectoriesalready runsfindFirstExecutableacross all nvm version dirs (sorted newest-first) just tounshiftthe one matching directory;resolveCliCommandthen re-runsfindFirstExecutableover the resulting list, re-verifying the same file. SincegetNvmVersionDirectoriesis already newest-first, concatenating it directly with the base dirs (asresolveCliCommandsdoes) 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
executableNamesparameter from callers.src/shared/windows-batch-spawn.ts (1)
1-4: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueHardcoded path separator instead of a path utility.
Per coding guidelines, path construction should use utilities like
path.joinrather 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.joinspecifically (not plainjoin), 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.joininstead of hardcoded separators."Source: Coding guidelines
config/scripts/verify-skills-cli-runtime.cjs (1)
6-6: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winRegex-based import scanning will hard-fail release builds on benign matches.
RUNTIME_IMPORTmatches anyrequire('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 fromnode_modulesto warnings (keep hard failures for first-partyout/**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
📒 Files selected for processing (22)
config/electron-builder.config.cjsconfig/scripts/electron-builder-config.test.mjsconfig/scripts/smoke-packaged-cli.mjsconfig/scripts/verify-skills-cli-runtime.cjsconfig/scripts/verify-skills-cli-runtime.test.mjsconfig/tsconfig.cli.jsonelectron.vite.config.tspackage.jsonsrc/cli/handlers/account.test.tssrc/cli/handlers/account.tssrc/cli/handlers/skills.tssrc/cli/main-module-bundle-parity.test.tssrc/cli/skills.test.tssrc/main/codex-cli/command.tssrc/main/ipc/local-agent-install-dir-detection.tssrc/main/ipc/preflight.test.tssrc/main/ipc/tui-agent-detection-commands.tssrc/main/win32-utils.tssrc/shared/local-agent-install-dir-detection.tssrc/shared/node-cli-command-resolution.tssrc/shared/tui-agent-detection-commands.tssrc/shared/windows-batch-spawn.ts
💤 Files with no reviewable changes (1)
- config/tsconfig.cli.json
Greptile SummaryThis PR fixes a packaging bug where the bundled CLI failed at load time because
Confidence Score: 5/5Safe 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.
|
| 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
Reviews (3): Last reviewed commit: "ci(cli): smoke packaged skills on Window..." | Re-trigger Greptile
* 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]>
Summary
The installed
1.4.163-rc.0CLI fails before anyorca skillscommand can dispatch becauseout/cli/handlers/skills.jseagerly requires source-shapedout/main/*files that are absent after Electron's bundled-main build.Latest
mainalready avoids the immediate crash with a copy-based Electron-entry workaround. This PR replaces that fragile packaging synchronization with an ownership fix:src/sharedmodulesskillsand relevantaccounthandlers import the CLI-safe owners directlyasarUnpackcopiesskills list, both bundledgetguides, install dry-run, and update dry-run during release builds andafterPackRoot cause
build:cliemitted direct CommonJS requires for foursrc/mainmodules. The laterbuild:electron-vitestep replacesout/mainwith 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
mainmakes 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-vitenode out/cli/index.js skills list --json→ exit 1node out/cli/index.js skills get orca-cli→ exit 1out/main/codex-cli/command.js; artifact inspection independently found all four requiredout/mainfiles absentCandidate:
Disabled fix:
skills.tsmain import while leaving copied entries removed makes the identical oracle exit 1 withmissing runtime import "../../main/codex-cli/command"Validation
pnpm typecheckpnpm lintGIT_CONFIG_COUNT=2; the file passes 10/10 with those ambient variables removedpnpm run test:repro:skills-cli-runtimepnpm run build:macproduced x64 and arm64 apps, ZIPs, and DMGs; bothafterPackgates passednode config/scripts/smoke-packaged-cli.mjs --app-dir=dist/mac-arm64/Orca.appPlatform 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.