Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions src/turn.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down
Loading