Skip to content

fix(windows): resolve absolute opencode binary for schtasks tasks - #26

Open
CENFARG wants to merge 2 commits into
different-ai:mainfrom
CENFARG:fix/windows-schtasks-binary-resolution
Open

CENFARG wants to merge 2 commits into
different-ai:mainfrom
CENFARG:fix/windows-schtasks-binary-resolution

Conversation

@CENFARG

@CENFARG CENFARG commented Sep 10, 2026 •

Copy link
Copy Markdown

Closes #25

Summary

  • Windows schtasks tasks now invoke the absolute opencode binary instead of a bare opencode name that Task Scheduler cannot resolve (LastResult 2147942402 / 0x80070002).
  • Tasks redirect output to the scoped log via a cmd wrapper, matching the launchd/systemd backends.
  • Not done: schtasks /Create has no WorkingDirectory flag; tracked as follow-up via XML import. This PR fixes resolution + log redirect only.

Changes

File Change
src/index.ts Add findOpencodeWindows() (scoop shim dir, default install locations, where.exe); wire into findOpencode() on win32; cmd-wrapper log redirect for schtasks tasks (55 lines)
README.md Document Windows binary resolution (1 line)

Test plan

  • Typecheck passes
  • Build passes
  • Canary schtasks job verified: LastResult 0 with absolute path (was 2147942402 with bare binary)
  • schtasks-only change; launchd/systemd/cron paths untouched
  • Local branch only; main untouched (2 commits on top of cd0b623)

Before/after /TR:

Before: /TR bare "opencode run ..." -> LastResult 2147942402 (0x80070002). After: /TR con ruta absoluta via cmd wrapper -> LastResult 0.

Known limitation

Paths with spaces + npm shim .cmd untested; the canary used the scoop .exe shim.

Example generated /TR command (captured output)

cmd.exe /c "C:\Users\canary\scoop\shims\opencode.exe run -- "hello canary" >> C:\Users\canary\.cache\opencode\logs\scheduler\scope-abc123\nightly.log 2>&1"

findOpencode() gains a win32 branch (findOpencodeWindows): OPENCODE_SCHEDULER_OPENCODE_PATH override first, then where.exe over the enhanced Windows PATH, then well-known locations (scoop shims opencode.exe, npm-global opencode.cmd, LocalAppData opencode.exe, ~/.opencode/bin), else bare opencode. getEnhancedPath() returns ;-joined Windows dirs (System32, scoop shims, APPDATA/npm, LOCALAPPDATA/Programs/opencode/bin, ~/.opencode/bin) on win32; POSIX output unchanged. POSIX body of findOpencode() byte-identical.
…pper

buildWindowsTaskCommand wraps the quoted invocation in cmd.exe append-redirect form using quoteWindowsArg and getLogPath; single TR argv via execFileSync unchanged so LastResult still reflects the opencode exit code. README: stale bare-binary tasks must be re-saved to regenerate invocations.
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.

Windows schtasks jobs fail with FILE NOT FOUND (bare opencode binary)

1 participant