Suggestion: session-pin workspace for stable macOS tool path resolution#27
Conversation
|
Frustratingly, even #11 (comment) no longer works. Write access outside of the opencode config directory did work once but it hasn't worked since. EDIT: |
9a5a975 to
a344380
Compare
|
This is waaaay better than my initial fix/patch @hawkff The problem IMO and we can't be certain unless we add some logging here but..
The Maybe Fix Use import { realpathSync } from "fs";
function getOpenCodeConfigPrefix(): string {
const configHome = process.env.XDG_CONFIG_HOME
? resolve(process.env.XDG_CONFIG_HOME)
: join(homedir(), ".config");
const configPath = join(configHome, "opencode");
try {
return realpathSync(configPath);
} catch {
return configPath;
}
}
function isWithinPath(root: string, candidate: string): boolean {
try {
const realRoot = realpathSync(root);
const realCandidate = realpathSync(candidate);
const rel = relative(realRoot, realCandidate);
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
} catch {
const rel = relative(root, candidate);
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
}
}
|
|
What it adds:
|
- add per-session workspace pinning for tool-hook path resolution\n- keep file/shell tool defaults anchored to non-config workspace paths\n- harden config-dir ancestry checks with path-relative logic\n- add regression coverage for worktree-loss within same session\n- bound session workspace cache growth
- normalize workspace/config path comparisons using realpath-aware canonicalization\n- harden macOS case-variant path handling during config-dir detection\n- add regression coverage for symlink-alias config path resolution
f1b6924 to
091d1f2
Compare
|
Hope this helps 🙈 |
Fixes #11
What
sessionIDand reuse it if later calls loseworktreepath.relative(...)ancestry checks instead of string-prefix matching~/.config/opencodewhen context is ambiguousWhy
This attempt to make workspace selection stable for the lifetime of a session, preventing path drift away from the active repo.
Tests
tests/unit/plugin-tools-hook.test.tsworktreeand reused when later context omitsworktreeand only provides config-dirdirectoryValidation
bun test tests/unit/plugin-tools-hook.test.tstmp_home=$(mktemp -d) && HOME="$tmp_home" bun run test:ci:unit && rm -rf "$tmp_home"bun run test:ci:integrationbun run build