store project-relative paths for cross-environment portability - #59
Open
lshgdut wants to merge 1 commit into
Open
store project-relative paths for cross-environment portability#59lshgdut wants to merge 1 commit into
lshgdut wants to merge 1 commit into
Conversation
… for ledger portability
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
sessions[].reads[].fileandsessions[].writes[].fileintoken-ledger.jsonpreviously recorded absolute paths (e.g./Users/hua/Desktop/01github/openwolf/src/hooks/stop.ts). This made the ledger non-portable across environments — when a user switches machines, clones the project to a different location, or runs inside a container/devcontainer, historical session paths immediately become invalid.This change converts absolute paths to project-relative paths when writing the ledger, so the data remains reproducible in any environment.
What Changed
getProjectDir()helper (which handles theCLAUDE_PROJECT_DIR/CODEX_PROJECT_ROOT/OPENWOLF_PROJECT_ROOT/process.cwd()priority chain)filefield viapath.relative()when buildingsessionEntry; introduces a smalltoRelative()helperDesign Decisions
getProjectDir()— no reimplementation of project-root resolution; the existing env-var priority chain is preserved (other hooks already depend on it).session.files_read/session.files_writtenkeep absolute paths unchanged, because downstream checks in the same function (checkForMissingBugLogs,checkStatusFreshness,checkSemanticSummaries, etc.) rely on absolute paths forfs.statSyncandincludes()matching. Minimal blast radius.path.relative(): if the result starts with..or is still absolute (cross-drive / different root on Windows), the file lives outside the project and we keep the absolute path rather than losing the information. Rare, but robust.sessionEntryis still the last step before disk; downstream consumers (dashboard tables, token stats) only care about file existence and token counts, not full paths.Compatibility & Migration
path.isAbsolute()heuristic (out of scope for this change).Testing
Manually verified scenarios:
src/hooks/stop.ts~/.zshrc) → fall back to absolute pathpath.relative()behavior matches the documented contract (a non-empty..prefix indicates outside-the-project)Checklist
session.files_read/session.files_written)getProjectDiris already exported, no lint warnings)