Repository navigation
fix(paths): one ~/.perp path helper; HOME unset is an error, not ./~/.perp - #101
Merged
Merged
Conversation
…n error `resolve(process.env.HOME || "~", ".perp")` does not expand "~": with HOME unset (cron, systemd, containers) settings, Aster/RISEx nonces, the execution log, the bot quarantine, arb state, agent locks and keystores were read from and written to ./~/.perp in the working directory (SSOT Rule #2). src/paths.ts (homeDir/perpDir/perpPath/owsPath) resolves at call time from HOME, or USERPROFILE on Windows when HOME is unset, and throws INVALID_PARAMS with remediation otherwise (also for a non-absolute HOME). os.homedir() is not used: its passwd fallback would reach the real home when HOME is cleared. Module-level path constants become functions; QUARANTINE_FILE becomes quarantineFile(). Catch blocks that only report a failure (execution log, quarantine persist / fail-closed entry) name the path literally so they never throw from the error path. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… the helper - perp / perp-mcp load ~/.perp/.env via perpPath(); the CLI loads it inside loadStartupSettings() so an unset HOME is printed like a bad settings.json (text or --json envelope, exit 1). - commands/init ENV_FILE becomes envFile(); wallet.json store and the OWS CLI lookup (~/.ows/bin/ows, which could run a binary under ./~/.ows/bin in the working directory) go through perpPath()/owsPath(). - jobs, equity history, bot logs, trade journal and funding history used os.homedir(); they now resolve at call time from the same helper. - funding-history.test points HOME at its temp dir instead of mocking os. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s.ts Source-scanning test (readme-cli-sync style): fails if `HOME || "~"` / `HOME ?? "~"`, a direct process.env.HOME read or an os.homedir() call reappears in src outside src/paths.ts. CHANGELOG [Unreleased] entry for the behaviour change (HOME unset now errors). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Runs without HOME left quarantine entries, Aster/RISEx nonces, Lighter keystores and settings in <cwd>/~/.perp. Reading ~/.perp instead would un-quarantine symbols and restart nonces (fail-open). assertNoLegacyCwdPerpDir() refuses with INVALID_PARAMS naming both directories; nothing is moved (Rule #2). One existsSync at CLI / MCP startup, before any command, never on an order path. Only the cwd can be checked (noted in the CHANGELOG). Also: perp-mcp reports HOME / legacy errors as one stderr line + exit 1 instead of a stack trace; `perp --help` / `--version` work without HOME; win32 HOME-before-USERPROFILE order explained in paths.ts and CHANGELOG. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… test
The execution-log / quarantine catch blocks name $HOME/.perp/... (they must
not call the throwing helper). The guard also rejects `const { HOME } =
process.env` and a literal "~" segment before ".perp" / ".ows".
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
If it holds more than one logical change, consider splitting it for review. |
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <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.
What does this PR do?
resolve(process.env.HOME || "~", ".perp")appeared in 18 places.path.resolvedoes not expand "~", so when HOME was unset (cron, a systemd unit withoutUser=/Environment=HOME, some containers) perp-cli silently wrote settings, nonces, the execution log, agent keystores and the bot quarantine under./~/.perpin the current directory. That is a fallback SSOT Rule #2 forbids, on files that guard funds.src/paths.ts(homeDir(),perpDir(),perpPath(),owsPath()): 31 sites in 23 files now use it. Paths are computed at call time, not at module import.INVALID_PARAMSwith a remediation (how to set HOME in systemd / crontab). A relative HOME such as "~" is refused too. Nothing is written to the cwd.os.homedir()is deliberately not used: on POSIX with HOME unset it falls back to the passwd entry, so a process or a test that cleared HOME would silently reach the real home's nonce / quarantine / keystore files. On Windows,USERPROFILEis used when HOME is not set../~/.ows/bin/owsin the cwd could be executed and put on PATH. Fixed withowsPath().HOME || "~", a directprocess.env.HOMEread, a{ HOME }destructure orhomedir()reappears outsidesrc/paths.ts.For a user with HOME set, every path is the same as before (the reviewer compared the old and new expression at each site), so existing keystores, nonces and settings are found unchanged.
Behaviour changes — please read
homedir()before and so kept working (equity history, jobs, bot logs, trade journal, funding history). Users running bots from cron or systemd without HOME must set it.perp --helpand--versionstill work.<cwd>/~/.perp(for systemd,/~/.perp). Once HOME is set, that state would no longer be read: quarantined symbols would become tradable again and nonces would restart. Soperpandperp-mcprefuse at startup while<cwd>/~/.perpexists, naming both directories, what to merge (quarantine entries, the higher nonces,lighter-agents/keystores) and how to dismiss it (remove or rename the legacy directory). Nothing is moved automatically.homedir()callers (equity / funding history, jobs, bot logs, trade journal) now follow HOME like the rest of the state. The funds-guarding files always followed HOME and do not move.QUARANTINE_FILE→quarantineFile(),ENV_FILE→envFile(). All uses insrcand tests are updated. The package exports only./ws, so no external consumer is affected.After an order is sent, a path failure cannot turn a fill into a reported failure: the execution log only warns, a failed quarantine write stays in memory, a failed quarantine read counts the symbol as quarantined (fail-closed), and nonce paths resolve before signing. The reviewer traced each of these.
Size: 39 files, +555 / −206. This is above the 500-line guideline. It was not split because a partial migration leaves the guard test red; most lines are a mechanical constant-to-function change.
Reported only, not changed (pre-existing):
scripts/e2e/lib.ts:15-17still useshomedir().src/risk.tsfalls back to default limits whenrisk.jsonis malformed (a Rule v0.2.1: scaled TP, pnl/liquidation alerts, bot fix #2 violation of its own).wallet.tsloadStorereturns an empty store on a parse failure.Checklist
pnpm testpasses (337 files / 7281 tests; 22 new)tsc --noEmitandtypecheck:testpassTesting standard (docs/TESTING.md §7)
test.skip/.only; tests run in a temp cwd with an isolated HOME and never touch the real~/.perpor~/.owsorigin/mainsources by the author and again by the reviewer). Exceptions, stated plainly: the--help/--versiontests only fail against the first commits of this branch, since those already worked on main; the "~" literal guard matches 21 places on main but nothing on the previous branch head.An independent review approved the first three commits and raised one MEDIUM (orphaned legacy state) and five LOW items. All are applied in the last two commits, which were read by the session lead but not re-reviewed.
Live ↔ Unit Test Cross-Validation
The reviewer ran
perp --jsonandperp-mcpwith HOME cleared in a scratch cwd: a clean error, exit 1, and no./~directory. Not tested on Windows.Merge note
CHANGELOG.md[Unreleased]conflicts with the other open PRs (keep both sides). This PR touches many files lightly, so small textual conflicts with #97, #99 and #100 are likely.🤖 Generated with Claude Code