Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

Merge origin/main into fix/codex-usage-discovery

fangweijing7b570c2c000f
diff --cc test/hive-hook-node.test.cjs
index 3e7a9963,d68e3564..f8debeb1
--- a/test/hive-hook-node.test.cjs
+++ b/test/hive-hook-node.test.cjs
@@@ -142,7 -124,8 +142,8 @@@ test('every hook installer routes throu
hive.installAgyHooks();
hive.installGrokHooks();
+ hive.installGeminiHooks(path.join(home, 'hive/agents/a1'));
- hive.installCodexHooks(path.join(home, 'hive/agents/a1'));
+ hive.installCodexHooks(path.join(home, 'hive/agents/a1'), 'a1');
const launcher = launcherIn(home);
const commands = hookCommandsUnder(home);
@@@ -156,120 -139,32 +157,146 @@@
}
});
+test('Codex rollouts remain isolated and are visible under the standard scan roots', (t) => {
+ const { home, harness } = isolatedHomes(t);
+ const hive = new HiveManager(() => harness);
+ hive.ensureHive();
+ const agentDir = path.join(harness, 'hive', 'agents', 'a1');
+ const codexHome = path.join(agentDir, '.codex');
+ const files = {
+ sessions: path.join('2026', '08', '21', 'rollout-live.jsonl'),
+ archived_sessions: 'rollout-archived.jsonl'
+ };
+ for (const [kind, relative] of Object.entries(files)) {
+ const file = path.join(codexHome, kind, relative);
+ fs.mkdirSync(path.dirname(file), { recursive: true });
+ fs.writeFileSync(file, `${kind}\n`, 'utf8');
+ }
+
+ hive.installCodexHooks(agentDir, 'a1');
+
+ const targets = {};
+ for (const [kind, relative] of Object.entries(files)) {
+ const isolated = path.join(codexHome, kind);
+ assert.equal(fs.lstatSync(isolated).isSymbolicLink(), true,
+ `${kind} must stay reachable from the isolated CODEX_HOME`);
+ targets[kind] = fs.realpathSync(isolated);
+ assert.equal(targets[kind].startsWith(
+ path.join(fs.realpathSync(home), '.codex', kind, 'munder-difflin') + path.sep
+ ), true, `${targets[kind]} is outside the standard Codex scan root under ${home}`);
+ assert.equal(fs.readFileSync(path.join(isolated, relative), 'utf8'), `${kind}\n`,
+ `existing ${kind} data was lost during exposure`);
+ }
+
+ hive.installCodexHooks(agentDir, 'a1');
+ for (const kind of Object.keys(files)) {
+ assert.equal(fs.realpathSync(path.join(codexHome, kind)), targets[kind],
+ `reinstalling hooks moved ${kind} again`);
+ }
+});
+
+test('bootstrap exposes archived Codex agents without respawning them', (t) => {
+ const { home, harness } = isolatedHomes(t);
+ const root = path.join(harness, 'hive');
+ const agentDir = path.join(root, 'agents', 'a1');
+ const sessions = path.join(agentDir, '.codex', 'sessions');
+ fs.mkdirSync(sessions, { recursive: true });
+ fs.writeFileSync(path.join(sessions, 'rollout-old.jsonl'), 'old\n', 'utf8');
+ fs.writeFileSync(path.join(root, 'registry.json'), JSON.stringify({
+ godId: null,
+ agents: { a1: { id: 'a1', name: 'A', provider: 'codex', cwd: harness, archived: true } }
+ }), 'utf8');
+
+ new HiveManager(() => harness).ensureHive();
+
+ assert.equal(fs.lstatSync(sessions).isSymbolicLink(), true,
+ 'an archived agent is never respawned, so bootstrap must expose its rollouts');
+ assert.equal(fs.realpathSync(sessions).startsWith(
+ path.join(fs.realpathSync(home), '.codex', 'sessions', 'munder-difflin') + path.sep
+ ), true);
+ assert.equal(fs.readFileSync(path.join(sessions, 'rollout-old.jsonl'), 'utf8'), 'old\n');
+});
+
+test('a missing exposed directory is repaired on the next spawn', (t) => {
+ const { home, harness } = isolatedHomes(t);
+ const hive = new HiveManager(() => harness);
+ hive.ensureHive();
+ const agentDir = path.join(harness, 'hive', 'agents', 'a1');
+ const sessions = path.join(agentDir, '.codex', 'sessions');
+ const staleTarget = path.join(home, '.codex', 'sessions', 'munder-difflin', 'stale', 'a1');
+ fs.mkdirSync(staleTarget, { recursive: true });
+ fs.mkdirSync(path.dirname(sessions), { recursive: true });
+ fs.symlinkSync(staleTarget, sessions, process.platform === 'win32' ? 'junction' : 'dir');
+ fs.rmSync(staleTarget, { recursive: true, force: true });
+
+ hive.installCodexHooks(agentDir, 'a1');
+
+ assert.equal(fs.lstatSync(sessions).isSymbolicLink(), true);
+ assert.equal(fs.statSync(sessions).isDirectory(), true, 'the stale link still has no writable target');
+});
+
+test('an unsafe agent id cannot escape the Munder scan namespace', (t) => {
+ const { home, harness } = isolatedHomes(t);
+ const hive = new HiveManager(() => harness);
+ hive.ensureHive();
+ const codexHome = path.join(harness, 'hive', 'agents', 'safe', '.codex');
+ const sessions = path.join(codexHome, 'sessions');
+ fs.mkdirSync(sessions, { recursive: true });
+ fs.writeFileSync(path.join(sessions, 'rollout.jsonl'), 'safe\n', 'utf8');
+
+ assert.throws(() => hive.exposeCodexDataDir(
+ codexHome, path.join(home, '.codex'), '../outside', 'sessions'
+ ), /invalid agent id/);
+ assert.equal(fs.readFileSync(path.join(sessions, 'rollout.jsonl'), 'utf8'), 'safe\n');
+ assert.equal(fs.existsSync(path.join(home, '.codex', 'sessions', 'munder-difflin', 'outside')), false);
+});
+
+test('reset cleanup removes only exposed Munder rollouts', (t) => {
+ const { home, harness } = isolatedHomes(t);
+ const hive = new HiveManager(() => harness);
+ hive.ensureHive();
+ const agentDir = path.join(harness, 'hive', 'agents', 'a1');
+ const isolated = path.join(agentDir, '.codex', 'sessions');
+ fs.mkdirSync(isolated, { recursive: true });
+ fs.writeFileSync(path.join(isolated, 'rollout-munder.jsonl'), 'munder\n', 'utf8');
+ const personal = path.join(home, '.codex', 'sessions', '2026', '08', '21', 'rollout-personal.jsonl');
+ fs.mkdirSync(path.dirname(personal), { recursive: true });
+ fs.writeFileSync(personal, 'personal\n', 'utf8');
+ hive.installCodexHooks(agentDir, 'a1');
+ const exposed = fs.realpathSync(isolated);
+
+ hive.removeExposedCodexData();
+
+ assert.equal(fs.existsSync(exposed), false, 'reset left Munder rollout data behind');
+ assert.equal(fs.readFileSync(personal, 'utf8'), 'personal\n', 'reset touched a personal Codex session');
+});
+
+ test('Gemini gets isolated lifecycle settings and an interactive protocol seed', async (t) => {
+ const home = tmpHome();
+ t.after(() => fs.rmSync(home, { recursive: true, force: true }));
+ const hive = new HiveManager(() => home);
+ const injection = await hive.ensureAgent({
+ id: 'gemini-1',
+ name: 'Gemini',
+ provider: 'gemini',
+ cwd: home
+ });
+
+ const settingsPath = injection.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH;
+ assert.equal(typeof settingsPath, 'string');
+ assert.ok(settingsPath.startsWith(path.join(home, 'hive', 'agents', 'gemini-1')));
+ const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
+ assert.deepEqual(
+ Object.keys(settings.hooks),
+ ['SessionStart', 'BeforeAgent', 'BeforeTool', 'AfterTool', 'AfterAgent']
+ );
+ assert.equal(settings.hooksConfig.enabled, true);
+ assert.equal(settings.hooks.BeforeTool[0].matcher, '.*');
+ assert.ok(settings.hooks.AfterAgent[0].hooks[0].command.includes('gemini-hook.cjs'));
+ assert.equal(injection.args[0], '-i');
+ assert.match(injection.args[1], /HIVE PROTOCOL/);
+ });
+
test('a hook fires with NO node on PATH, and its payload reaches HIVE_SOCK', { skip: !POSIX }, async (t) => {
const home = tmpHome();
t.after(() => fs.rmSync(home, { recursive: true, force: true }));