aoaoe 0.62.0 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import type { DaemonState, DaemonPhase, DaemonSessionState, Observation } from "./types.js";
2
+ export declare function setStateDir(dir: string): void;
2
3
  export declare function resetInternalState(): void;
3
4
  export declare function setSessionTask(sessionId: string, task: string): void;
4
5
  export declare function writeState(phase: DaemonPhase, updates?: Partial<Omit<DaemonState, "phase" | "phaseStartedAt">>): void;
@@ -6,10 +6,19 @@ import { join } from "node:path";
6
6
  import { homedir } from "node:os";
7
7
  import { toDaemonState } from "./types.js";
8
8
  import { parseTasks, formatTaskList } from "./task-parser.js";
9
- const AOAOE_DIR = join(homedir(), ".aoaoe");
10
- const STATE_FILE = join(AOAOE_DIR, "daemon-state.json");
11
- const INTERRUPT_FILE = join(AOAOE_DIR, "interrupt");
12
- const LOCK_FILE = join(AOAOE_DIR, "daemon.lock");
9
+ // default state directory — overridable via setStateDir() for test isolation
10
+ let AOAOE_DIR = join(homedir(), ".aoaoe");
11
+ let STATE_FILE = join(AOAOE_DIR, "daemon-state.json");
12
+ let INTERRUPT_FILE = join(AOAOE_DIR, "interrupt");
13
+ let LOCK_FILE = join(AOAOE_DIR, "daemon.lock");
14
+ // redirect all state file paths to a custom directory (test isolation)
15
+ export function setStateDir(dir) {
16
+ AOAOE_DIR = dir;
17
+ STATE_FILE = join(dir, "daemon-state.json");
18
+ INTERRUPT_FILE = join(dir, "interrupt");
19
+ LOCK_FILE = join(dir, "daemon.lock");
20
+ dirEnsured = false; // force re-create on next write
21
+ }
13
22
  // cache: only mkdirSync once per process (no need to stat the dir on every phase change)
14
23
  let dirEnsured = false;
15
24
  function ensureDir() {
@@ -52,14 +61,15 @@ export function setSessionTask(sessionId, task) {
52
61
  const DEBOUNCE_MS = 500;
53
62
  let lastFlushedPhase = null;
54
63
  let lastFlushTime = 0;
55
- const STATE_TMP = STATE_FILE + ".tmp";
64
+ // note: STATE_TMP is computed dynamically inside flushState() since STATE_FILE is mutable
56
65
  function flushState() {
57
66
  try {
58
67
  ensureDir();
59
68
  // atomic write: write to temp file, then rename into place.
60
69
  // prevents chat.ts from reading a partially-written JSON file.
61
- writeFileSync(STATE_TMP, JSON.stringify(currentState) + "\n");
62
- renameSync(STATE_TMP, STATE_FILE);
70
+ const tmp = STATE_FILE + ".tmp";
71
+ writeFileSync(tmp, JSON.stringify(currentState) + "\n");
72
+ renameSync(tmp, STATE_FILE);
63
73
  lastFlushedPhase = currentState.phase;
64
74
  lastFlushTime = Date.now();
65
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aoaoe",
3
- "version": "0.62.0",
3
+ "version": "0.63.0",
4
4
  "description": "Autonomous supervisor for agent-of-empires sessions using OpenCode or Claude Code",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",