fix: anchor session-injection hooks to the host-injected project dir - #37
Merged
Conversation
Hook CWD is not a cross-host contract: a host may run hooks from outside
the project directory, and orbit's CWD-based workspace detection then
silently skips <orbit-context> injection ("not in a workspace" is a
designed silent no-op, so nothing surfaces).
- hooks/session-start.sh / session-resume.sh: cd to CLAUDE_PROJECT_DIR
(Claude Code's documented contract, also injected by Qoder), falling
back to QODER_PROJECT_DIR (Qoder's documented contract) — guarded by
[ -n ]/[ -d ] so empty/unset/invalid values and env-less hosts (codex
sets hook CWD correctly by contract) pass through unchanged; stdout
and stderr of the cd are both suppressed.
- .opencode-plugin/plugin.ts: rawContext() anchors its shell to the
SDK-provided PluginInput.directory via .cwd(...) instead of
inheriting the opencode process cwd; the directory is per-instance,
so the anchor names the session's project in every run mode.
- tests: bats contract for the anchor chain (order, guards,
fallthrough); node test pinning the plugin's .cwd(directory) call.
- docs: spec-hooks states the host-CWD anchoring contract; CHANGELOG
entry under Bug or Regression.
Signed-off-by: Zheng Weihao <zheng-weihao@outlook.com>
Signed-off-by: Zheng Weihao <zheng-weihao@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hook CWD is not a cross-host contract: a host may run hooks from outside the project directory, and orbit's CWD-based workspace detection then silently skips
<orbit-context>injection for the whole session ("not in a workspace" is a designed silent no-op, so nothing ever surfaces).CLAUDE_PROJECT_DIR(Claude Code's documented contract, also injected by Qoder), thenQODER_PROJECT_DIR(Qoder's documented fallback). Guarded by[ -n ]/[ -d ]so empty/unset/invalid values and env-less hosts (codex sets hook CWD correctly by contract) pass through as a silent no-op; thecdsuppresses stdout and stderr alike.rawContext()anchors its BunShell to the SDK-providedPluginInput.directoryvia.cwd(...)instead of inheriting the opencode process cwd (which equals the project only when opencode was launched from it).directoryis per-instance in opencode (plugin state is materialized per project directory, serve mode included), so the anchor names the session's project in every run mode.Test plan
tests/26_hook_cwd_anchor.batspins the anchor chain across both shared scripts: fallback order, empty-string fallthrough, unset no-op, nonexistent/not-a-dir refusal (7 tests, 14 hook runs — all green)..opencode-plugin/plugin.test.tspins the.cwd(directory)call and output passthrough (18/18 green).