Files
AgentHub/server/lib/antigravity-home.js
nntrivi2001 969b06253c feat: per-tool settings, persistent settings file, Codex and Antigravity sessions, tokens and hooks (#40 B, C1, C2, D)
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.
2026-09-29 16:09:19 +07:00

43 lines
1.4 KiB
JavaScript

/**
* @file Where Antigravity's CLI (`agy`) keeps its data. `agy` has no home
* override of its own — everything is under `~/.gemini`: its conversations and
* transcripts in `antigravity-cli/`, and the user's global hooks in
* `config/hooks.json`, shared with the Antigravity IDE. `AGENTHUB_GEMINI_DIR`
* points AgentHub elsewhere (tests; a pane whose HOME differs). `agyCliDirs`
* also names the resolved path when a symlink leads elsewhere, since agy may
* report either in a hook.
* @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");
/** `~/.gemini`, or `AGENTHUB_GEMINI_DIR`; read at call time. */
function getGeminiDir() {
return process.env.AGENTHUB_GEMINI_DIR || path.join(os.homedir(), ".gemini");
}
/** The CLI's own data: `conversations/<id>.db`, `brain/<id>/…`. */
function getAgyCliDir() {
return path.join(getGeminiDir(), "antigravity-cli");
}
/** The CLI dir as configured and, when a symlink leads elsewhere, as resolved. */
function agyCliDirs() {
const raw = path.resolve(getAgyCliDir());
let real = raw;
try {
real = fs.realpathSync(raw);
} catch {
try {
real = path.join(fs.realpathSync(getGeminiDir()), "antigravity-cli");
} catch {
/* neither exists yet */
}
}
return real === raw ? [raw] : [raw, real];
}
module.exports = { getGeminiDir, getAgyCliDir, agyCliDirs };