Skip to content
Open
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
11 changes: 10 additions & 1 deletion packages/eliza-harness/src/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ export const repository =(function rootOf(directory: string): string {

const lock = JSON.parse(fs.readFileSync(path.join(repository, "eliza.lock.json"), "utf8")) as Lock;

/** Resolve a cache directory from `overrideEnv` when non-blank, else `$XDG_CACHE_HOME/alpha/<segments>` (falling back to `~/.cache/alpha/<segments>` when `XDG_CACHE_HOME` is unset, blank, or relative). @throws {never} */
export function alphaCacheDir(overrideEnv: string, ...segments: readonly string[]): string {
const override = process.env[overrideEnv]?.trim();
if (override !== undefined && override.length > 0) return override;
const xdg = process.env.XDG_CACHE_HOME?.trim();
const base = xdg !== undefined && xdg.length > 0 && path.isAbsolute(xdg) ? xdg : path.join(os.homedir(), ".cache");
return path.join(base, "alpha", ...segments);
}

/** @throws {never} */
export function checkout(): Checkout {
const root = process.env.ALPHA_ELIZA_DIR ?? path.join(os.homedir(), ".cache/alpha/eliza-vibestack", lock.commit.slice(0, 12));
const root = alphaCacheDir("ALPHA_ELIZA_DIR", "eliza-vibestack", lock.commit.slice(0, 12));
return { commit: lock.commit, root, bundle: path.join(root, ".alpha/agent"), cloud: path.join(root, "packages/cloud-worker") };
}

Expand Down
5 changes: 2 additions & 3 deletions packages/eliza-harness/src/pack.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { createHash, randomBytes } from "node:crypto";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { Schema } from "effect";
import { alone, checkout, hasCommit, headCommit, repository, run } from "./checkout.ts";
import { alone, alphaCacheDir, checkout, hasCommit, headCommit, repository, run } from "./checkout.ts";

/**
* A private clone of the pinned eliza that the agent pack is built from, as Alpha's old phone build prepared its own
Expand All @@ -25,7 +24,7 @@ const worktreeKey = createHash("sha256").update(repository).digest("hex").slice(

/** Where the pack's clone for `commit` lives, shared across worktrees like `.eliza`, outside `node_modules` and outside the repo. @throws {never} */
export function packRoot(commit = checkout().commit): string {
return process.env.ALPHA_ELIZA_PACK_DIR ?? path.join(os.homedir(), ".cache/alpha/eliza-pack", commit.slice(0, 12));
return alphaCacheDir("ALPHA_ELIZA_PACK_DIR", "eliza-pack", commit.slice(0, 12));
}

const stampOf = (root: string) => path.join(root, ".alpha/pack.json");
Expand Down
4 changes: 2 additions & 2 deletions packages/eliza-harness/src/qa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { randomBytes } from "node:crypto";
import fs from "node:fs";
import http, { type IncomingMessage, type ServerResponse } from "node:http";
import type { AddressInfo } from "node:net";
import os from "node:os";
import path from "node:path";
import { Effect } from "effect";
import { alphaCacheDir } from "./checkout.ts";
import { builtPack } from "./pack.ts";
import { qaGmail } from "./providers/google-gmail.ts";
import { qaMaps } from "./providers/google-maps.ts";
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface QaServices {
export interface QaAgent { readonly id: string; readonly origin: string; readonly token: string; readonly key: DeviceKey }

/** The state directory of the QA services, outside the repository: `ALPHA_QA_STATE`, as the lever names it for its worktree. */
export const qaState = () => process.env.ALPHA_QA_STATE ?? path.join(os.homedir(), ".cache/alpha/qa/default");
export const qaState = () => alphaCacheDir("ALPHA_QA_STATE", "qa", "default");

const owner = { email: "owner@alpha.test", credits: 2_000_000_000 };
const gmailOwner = { email: "gmail@alpha.test", credits: 2_000_000_000 };
Expand Down
52 changes: 51 additions & 1 deletion packages/eliza-harness/test/harness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { randomBytes } from "node:crypto";
import fs from "node:fs";
import http from "node:http";
import type { AddressInfo } from "node:net";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "@effect/vitest";
import { Effect } from "effect";
import { alone, checkout, prepared } from "../src/checkout.ts";
import { packEntryName, stagePackEntry } from "../src/pack.ts";
import { packEntryName, packRoot, stagePackEntry } from "../src/pack.ts";
import { pinnedCheckout } from "../src/pinned.vibe";
import { qaState } from "../src/qa.ts";
import { type Cloud, type RealModel, said, scratch, startCloud } from "../src/services.ts";

const repository = path.join(import.meta.dirname, "../../..");
Expand Down Expand Up @@ -76,6 +78,54 @@ const holding = (directory: string, secret: string) => (fs.readdirSync(directory
.filter((file) => fs.statSync(path.join(directory, file)).isFile() && fs.readFileSync(path.join(directory, file)).includes(secret));

describe("the eliza harness", () => {
it("resolves shared checkout, pack, and QA cache paths from XDG_CACHE_HOME with clean fallback to ~/.cache", () => {
const keys = ["XDG_CACHE_HOME", "ALPHA_ELIZA_DIR", "ALPHA_ELIZA_PACK_DIR", "ALPHA_QA_STATE"] as const;
const saved = Object.fromEntries(keys.map((key) => [key, process.env[key]])) as Record<(typeof keys)[number], string | undefined>;
const commit = "0123456789abcdef0123456789abcdef01234567";
const lock = JSON.parse(fs.readFileSync(path.join(repository, "eliza.lock.json"), "utf8")) as { commit: string };
const shortLock = lock.commit.slice(0, 12);
const defaultBase = path.join(os.homedir(), ".cache");
const customBase = path.resolve(path.sep, "var", "cache", "alpha-depot");
const resolved = () => [checkout().root, packRoot(commit), qaState()];
const expectedUnder = (base: string) => [
path.join(base, "alpha", "eliza-vibestack", shortLock),
path.join(base, "alpha", "eliza-pack", commit.slice(0, 12)),
path.join(base, "alpha", "qa", "default"),
];
try {
for (const key of keys) delete process.env[key];
expect(resolved()).toEqual(expectedUnder(defaultBase));

process.env.XDG_CACHE_HOME = ` ${customBase} `;
expect(resolved()).toEqual(expectedUnder(customBase));

for (const invalid of ["", " ", "relative/cache"]) {
process.env.XDG_CACHE_HOME = invalid;
expect(resolved()).toEqual(expectedUnder(defaultBase));
}

process.env.XDG_CACHE_HOME = customBase;
process.env.ALPHA_ELIZA_DIR = " ";
process.env.ALPHA_ELIZA_PACK_DIR = " ";
process.env.ALPHA_QA_STATE = " ";
expect(resolved()).toEqual(expectedUnder(customBase));

const explicit = [
path.resolve(path.sep, "srv", "eliza"),
path.resolve(path.sep, "srv", "eliza-pack"),
path.resolve(path.sep, "srv", "qa-state"),
];
[process.env.ALPHA_ELIZA_DIR, process.env.ALPHA_ELIZA_PACK_DIR, process.env.ALPHA_QA_STATE] = explicit;
expect(resolved()).toEqual(explicit);
} finally {
for (const key of keys) {
const value = saved[key];
if (value === undefined) delete process.env[key];
else process.env[key] = value;
}
}
});

it("finds the pinned checkout built and linked as .eliza", async () => {
const lock = JSON.parse(fs.readFileSync(path.join(repository, "eliza.lock.json"), "utf8")) as { commit: string };
const at = prepared();
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://turborepo.dev/schema.json",
"globalPassThroughEnv": ["ALPHA_ELIZA_DIR", "QUINT_HOME"],
"globalPassThroughEnv": ["ALPHA_ELIZA_DIR", "QUINT_HOME", "XDG_CACHE_HOME"],
"globalDependencies": [
".nvmrc",
"pnpm-workspace.yaml",
Expand Down