969b06253c
Part B: Model Pricing, Hook Configuration and CLAUDE_HOME move from Settings → Dashboard to the Claude Code tab's AgentHub sub-tab (ClaudeAgentHubSettings.tsx); CODEX_HOME is editable in Codex → AgentHub. A home that is or contains the OS home is refused (EBADHOME). Settings persistence: dashboard-saved settings go to ~/.config/agenthub/settings.env (AGENTHUB_SETTINGS_FILE), outside the plugin cache an update wipes. Load order: real env > the checkout's .env > that file. The first CLAUDE_HOME change pins DASHBOARD_DATA_DIR so the DB stays put. C1: codex-usage.js reads Codex rollout journals into sessions (new column tool) and token_usage, tracked per file in codex_rollouts; forks deduped by total vector, sub-agent threads folded into the root; pricing-sync also prices OpenAI models; PricingSettings with a vendor filter. C2: codex-hooks.js installs AgentHub's hooks into $CODEX_HOME/hooks.json on a click, through a stable forwarder; Codex trust is never written. The hook route creates tool='codex' sessions and folds sub-agent hooks into the root. D: antigravity-usage.js reads agy's per-conversation SQLite files (tokens from ModelUsageStats) into tool='antigravity' sessions; antigravity-hooks.js installs the named hook `agenthub` (PreInvocation, PostToolUse, Stop — never PreToolUse) into ~/.gemini/config/hooks.json; Settings → Antigravity tab; Gemini pricing. Whole-change review fixes: sameOriginGuard on both home PUTs, routers.missing on a CLAUDE_HOME change, reset-pricing scope, GET /api/sessions?tool=, clear-data covering the new tables, Codex child-thread events moving no status, hooks owning status only while current, EFOREIGN for a forwarder that is not ours, agy quiet window and turn rules, AGENTHUB_SETTINGS_FILE honoured from .env. Docs, OpenAPI and the CLAUDE.md marker updated. Server 2141, client 779.
87 lines
2.7 KiB
JavaScript
87 lines
2.7 KiB
JavaScript
/**
|
|
* @file Centralized Codex home directory path management. Resolves the Codex
|
|
* home directory, project-level Codex surfaces, and project roots. Supports a
|
|
* custom root via the CODEX_HOME environment variable so the dashboard can
|
|
* track non-standard Codex installations, and changes it at runtime
|
|
* (`setCodexHome`, persisted to the settings file).
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const os = require("node:os");
|
|
|
|
/**
|
|
* The Codex home directory. Resolves to $CODEX_HOME if set, else
|
|
* ~/.codex. Always reads process.env at call time so tests can inject.
|
|
*
|
|
* @returns {string} Absolute path to the Codex home directory.
|
|
*/
|
|
function getCodexHome() {
|
|
return process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
}
|
|
|
|
/**
|
|
* CODEX_HOME as given and, when a symlink makes it differ, as resolved — so a
|
|
* path Codex reports (it may canonicalize) matches either.
|
|
*
|
|
* @returns {string[]} one or two absolute paths.
|
|
*/
|
|
function codexHomes() {
|
|
const raw = path.resolve(getCodexHome());
|
|
try {
|
|
const real = fs.realpathSync(raw);
|
|
return real === raw ? [raw] : [raw, real];
|
|
} catch {
|
|
return [raw];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The directory where Codex stores per-project surfaces (rollout journals,
|
|
* SQLite mirrors, etc.) for a project at the given working directory.
|
|
*
|
|
* @param {string} cwd Absolute path to a project root.
|
|
* @returns {string} Absolute path to <cwd>/.codex.
|
|
*/
|
|
function getProjectCodexDir(cwd) {
|
|
return path.join(cwd, ".codex");
|
|
}
|
|
|
|
/**
|
|
* The project root. For now, this is just an identity function — cwd is
|
|
* the project root. Exists as a contract for consistency with claude-home.js
|
|
* and to anchor the path-resolution hierarchy.
|
|
*
|
|
* @param {string} cwd Absolute path to a project root (where AGENTS.md lives).
|
|
* @returns {string} The same cwd.
|
|
*/
|
|
function getProjectRoot(cwd) {
|
|
return cwd;
|
|
}
|
|
|
|
/**
|
|
* Update CODEX_HOME at runtime: `process.env` changes at once and the value
|
|
* persists to the settings file (see `settings-env.js`). The path passes the
|
|
* shared guard that refuses anything that is or contains the user's home
|
|
* (`EBADHOME`). A codex pane gets this value through tmux `-e` at its next
|
|
* start; one already running keeps the home it started with.
|
|
*
|
|
* @param {string} newPath absolute path, `~/` expanded.
|
|
* @returns {string} the resolved absolute path.
|
|
*/
|
|
function setCodexHome(newPath) {
|
|
const { validateHomeDir, applySetting } = require("./settings-env");
|
|
const resolved = validateHomeDir("CODEX_HOME", newPath);
|
|
applySetting("CODEX_HOME", resolved);
|
|
return resolved;
|
|
}
|
|
|
|
module.exports = {
|
|
codexHomes,
|
|
getCodexHome,
|
|
setCodexHome,
|
|
getProjectCodexDir,
|
|
getProjectRoot,
|
|
};
|