From 8278bb89feaf2439318deff4a31b82ba6711b38d Mon Sep 17 00:00:00 2001 From: Panat Taranat Date: Fri, 28 Aug 2026 10:39:30 -0400 Subject: [PATCH] fix: keep turn session state in ~/.cache/dw --- README.md | 5 +++-- src/turn.ts | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 70f1e81..fcdf4ca 100644 --- a/README.md +++ b/README.md @@ -145,8 +145,9 @@ dw turn check-every 3 # wandering-check cadence (default every 2 turns) dw turn end # end the session and clear state ``` -State survives between invocations in `dw-session.json` (gitignored, next to the -install). A missing or unreadable state file starts a fresh session with a note. +State survives between invocations in `~/.cache/dw/dw-session.json` (same home +as the index cache; override with `DW_SESSION`). A missing or unreadable state +file starts a fresh session with a note. ## Status diff --git a/src/turn.ts b/src/turn.ts index fc37277..8873e83 100644 --- a/src/turn.ts +++ b/src/turn.ts @@ -1,9 +1,10 @@ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { homedir } from "node:os"; import { dirname, join } from "node:path"; -// Anchored to the repo root (like pdf/config.ts) so the session follows the -// install, not the invocation directory. Gitignored as dw-session.json. -const REPO_ROOT = join(import.meta.dir, ".."); +// Same machine-local home as dw.db and the extraction cache (db.ts), so the +// session survives switching or re-cloning checkouts. +const CACHE_DIR = join(homedir(), ".cache", "dw"); export const TURN_MINUTES = 10; export const DEFAULT_CHECK_EVERY = 2; @@ -21,7 +22,7 @@ export interface TurnState { export function statePath(): string { const env = process.env.DW_SESSION?.trim(); - return env || join(REPO_ROOT, "dw-session.json"); + return env || join(CACHE_DIR, "dw-session.json"); } export function freshState(): TurnState {