Repository navigation
fix(shell-mode): cd does not update footer cwd (LAC-3732) - #44
Merged
Merged
Conversation
…ctory (LAC-3732)
The session prompt runs under Effect InstanceRef, not the ambient
AsyncLocalStorage instance context (only CLI bootstrap enters that), so
the cwd.updated emit in setCwd hit the NotFound catch and was silently
skipped — the TUI footer cwd never updated after a shell-mode cd.
setCwd now accepts an optional { directory } that bypasses the ambient
context lookup, and the session prompt passes the instance directory it
already has in scope. Emission still falls back to the ambient context
for bootstrap-scoped callers and is skipped only when neither is
available.
Includes regression tests covering emit-without-ambient-context and the
event's directory field.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.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
Fixes LAC-3732 — QA defect from LAC-3268: submitting
cd /tmpin Shell mode did not update the footershortenedWorkingDir.Root cause:
setCwd()inpackages/opencode/plugin/shell-mode/cwd.tsonly emittedcwd.updatedwhen the ambient AsyncLocalStorage instance context was present (instanceContext.use()), swallowing theNotFoundthrow in a barecatch. But the session prompt (the live shell-mode path) runs under Effect'sInstanceRef— the ambient context is only entered by CLIbootstrap(), as the docstring ongetCwd()in the same file already warns. So the emit silently never fired: the event chain (GlobalBus → worker RPCglobal.event→ TUI sync store → footer) is intact, it just never received the event. This also explains why the QA repro logged nothing.Changes
setCwd(dir, options?: { directory?: string })— an explicit directory bypasses the ambient-context lookup; falls back to ambient context as before; still skips emission when neither is available.session/prompt.tsthreadsctx.directory(already in scope for thegetCwdfallbacks) through to the sentinel-parsesetCwdcall.test/plugin/cwd.test.ts): emit fires without ambient context when directory is passed; event carries the caller's directory; no emit when neither source is available. The two new emit tests fail on the old code.Not changed:
session-shell.ts:296also callssetCwdwithout a directory, butSessionShellExecutehas no production callers today — behavior there is unchanged (works iff ambient context exists, same as before).Testing
bun test test/plugin/cwd.test.ts— 23 pass (new tests failed before the fix, TDD).bun test test/plugin/shell-mode.test.ts— 32 pass.bun run typecheck(packages/opencode) — clean.cd /tmp→ footer updates to/private/tmp;pwdconfirms. Before-fix behavior documented in LAC-3268 QA transcript.🤖 Generated with Claude Code