Skip to content

Local-first 🧠 memory for Hermes Agent that lives in your Obsidian vault and remembers project context. Nightly 😴 dream passes turn repeat corrections into confirmed preferences with measurable confidence. Adapters ship for Claude Code, Codex, and OpenClaw, with an MCP server for anything else.

TypeScript
4.0 KB
Raw Blame
/**
 * Timezone presentation wiring (t_2ccadc6a): with `timezone:` in the
 * plugin config, the brief-family JSON envelopes (daily, weekly,
 * monthly, morning, timeline) gain additive `timezone` + `local_time`
 * fields; without it, output stays byte-identical to 0.45.0. Storage
 * timestamps inside every envelope remain canonical UTC.
 */

import { afterEach, beforeEach, expect, setDefaultTimeout, test } from "bun:test";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

import { bootstrapBrain } from "../../src/core/brain/init.ts";
import { runCli, type RunResult } from "../helpers/run-cli.ts";
import { CLI_SPAWN_BUDGET_MS } from "../helpers/cli-timeout.ts";

// Tests here spawn processes; see tests/helpers/cli-timeout.ts.
setDefaultTimeout(CLI_SPAWN_BUDGET_MS);

let tmp: string;
let vault: string;
let configPath: string;
const savedEnv: Record<string, string | undefined> = {};

beforeEach(() => {
  tmp = mkdtempSync(join(tmpdir(), "o2b-cli-tz-"));
  vault = join(tmp, "vault");
  configPath = join(tmp, "config.yaml");
  for (const key of ["OPEN_SECOND_BRAIN_CONFIG", "VAULT_TIMEZONE", "VAULT_DIR"]) {
    savedEnv[key] = process.env[key];
    delete process.env[key];
  }
  process.env["OPEN_SECOND_BRAIN_CONFIG"] = configPath;
  writeFileSync(configPath, `vault: ${vault}\nagent_name: claude\n`);
  bootstrapBrain(vault, { configPath });
});

afterEach(() => {
  rmSync(tmp, { recursive: true, force: true });
  for (const [key, value] of Object.entries(savedEnv)) {
    if (value === undefined) delete process.env[key];
    else process.env[key] = value;
  }
});

function enableTimezone(tz: string): void {
  writeFileSync(configPath, `vault: ${vault}\nagent_name: claude\ntimezone: ${tz}\n`);
}

test("daily brief JSON gains timezone + local_time when configured", async () => {
  enableTimezone("Europe/Berlin");
  const r = await runCli(["brain", "daily", "--date", "2026-06-05", "--vault", vault, "--json"], {
    env: { OPEN_SECOND_BRAIN_CONFIG: configPath },
  });
  expect(r.returncode).toBe(0);
  const parsed = JSON.parse(r.stdout) as Record<string, unknown>;
  expect(parsed["timezone"]).toBe("Europe/Berlin");
  expect(String(parsed["local_time"])).toMatch(/[+-]\d{2}:\d{2}$/);
  // Stored window stays canonical UTC.
  expect(JSON.stringify(parsed["window"])).toContain("Z");
});

test("without a configured timezone the envelope carries no local fields", async () => {
  const r = await runCli(["brain", "daily", "--date", "2026-06-05", "--vault", vault, "--json"], {
    env: { OPEN_SECOND_BRAIN_CONFIG: configPath },
  });
  expect(r.returncode).toBe(0);
  const parsed = JSON.parse(r.stdout) as Record<string, unknown>;
  expect(parsed["timezone"]).toBeUndefined();
  expect(parsed["local_time"]).toBeUndefined();
});

test("weekly, monthly, and timeline envelopes localize the same way", async () => {
  enableTimezone("Asia/Tokyo");
  const env = { OPEN_SECOND_BRAIN_CONFIG: configPath };
  // Sequential on purpose: an in-process run swaps process.env, the working
  // directory and both output streams, so overlapping runs restore each
  // other’s saved state and corrupt both the captured output and the
  // environment every later test file reads. runCli refuses to overlap.
  const results: RunResult[] = [];
  for (const argv of [
    ["brain", "weekly", "--week-end", "2026-06-05", "--vault", vault, "--json"],
    ["brain", "monthly", "--month", "2026-06", "--vault", vault, "--json"],
    ["brain", "timeline", "--vault", vault, "--json"],
  ]) {
    // The rule suggests Promise.all, which is exactly the overlap runCli
    // now refuses; see the comment above this loop.
    // eslint-disable-next-line no-await-in-loop
    results.push(await runCli(argv, { env }));
  }
  for (const r of results) {
    expect(r.returncode).toBe(0);
    const parsed = JSON.parse(r.stdout) as Record<string, unknown>;
    expect(parsed["timezone"]).toBe("Asia/Tokyo");
    expect(String(parsed["local_time"])).toContain("+09:00");
  }
});