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
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
adapt tests, only copy files if they exist
Andreas Reschecf78fbeb754
diff --git a/src/main/hive.ts b/src/main/hive.tsindex 23214782..ae4c88ef 100644--- a/src/main/hive.ts+++ b/src/main/hive.ts@@ -2170,12 +2170,16 @@ export class HiveManager {// Pi ignores it). Kept minimal and hive-authored.const manifest = { name: 'munder-hive-bridge', version: '0.3.1', main: 'extensions/hive-bridge.js', auto: true };writeFileSync(join(home, 'extensions.json'), JSON.stringify(manifest, null, 2), 'utf8');- // we need to copy models.json and models-store.json from the user's ~/.pi to the per-agent dir so Pi can load its models+const userPiDir = join(homedir(), '.pi', 'agent');- const userModelsPath = join(userPiDir, 'models.json');- writeFileSync(join(home, 'models.json'), existsSync(userModelsPath) ? readFileSync(userModelsPath, 'utf8') : '{}', 'utf8');- const modelsStorePath = join(userPiDir, 'models-store.json');- writeFileSync(join(home, 'models-store.json'), existsSync(modelsStorePath) ? readFileSync(modelsStorePath, 'utf8') : '{}', 'utf8');+ for (const fileName of ['models.json', 'models-store.json'] as const) {+ try {+ const data = readFileSync(join(userPiDir, fileName), 'utf8');+ writeFileSync(join(home, fileName), data, 'utf8');+ } catch (e) {+ if ((e as NodeJS.ErrnoException).code !== 'ENOENT') console.error(`[hive] installPiHooks copy ${fileName} failed:`, e);+ }+ }} catch (e) { console.error('[hive] installPiHooks failed:', e); }return home;}diff --git a/test/hive-pi-models.test.cjs b/test/hive-pi-models.test.cjsindex 73aed3b5..6a57dc3d 100644--- a/test/hive-pi-models.test.cjs+++ b/test/hive-pi-models.test.cjs@@ -13,117 +13,79 @@ function tmpHome() {return fs.mkdtempSync(path.join(os.tmpdir(), 'md-hive-pi-models-'));}-test('installPiHooks copies models.json from ~/.pi/agent when it exists', async (t) => {+async function setupPi(t, { get, id }) {const hiveHome = tmpHome();- t.after(() => fs.rmSync(hiveHome, { recursive: true, force: true }));-const fakeHome = tmpHome();+ t.after(() => fs.rmSync(hiveHome, { recursive: true, force: true }));t.after(() => fs.rmSync(fakeHome, { recursive: true, force: true }));const realHome = process.env.HOME;+ const realProfile = process.env.USERPROFILE;process.env.HOME = fakeHome;- t.after(() => { if (realHome === undefined) delete process.env.HOME; else process.env.HOME = realHome; });+ process.env.USERPROFILE = fakeHome;+ t.after(() => {+ if (realHome === undefined) delete process.env.HOME; else process.env.HOME = realHome;+ if (realProfile === undefined) delete process.env.USERPROFILE; else process.env.USERPROFILE = realProfile;+ });+ assert.equal(os.homedir(), fakeHome, 'home redirect failed — aborting before touching the real home');- const userPiAgentDir = path.join(fakeHome, '.pi', 'agent');- fs.mkdirSync(userPiAgentDir, { recursive: true });- const modelsData = { default: 'anthropic/claude-sonnet-4-5', custom: { 'openai/gpt-4o': {} } };- fs.writeFileSync(path.join(userPiAgentDir, 'models.json'), JSON.stringify(modelsData), 'utf8');- const storeData = { version: 2, models: [{ id: 'm1', name: 'test' }] };- fs.writeFileSync(path.join(userPiAgentDir, 'models-store.json'), JSON.stringify(storeData), 'utf8');+ if (get) {+ const dir = path.join(fakeHome, '.pi', 'agent');+ fs.mkdirSync(dir, { recursive: true });+ for (const [file, data] of Object.entries(get)) {+ fs.writeFileSync(path.join(dir, file), JSON.stringify(data), 'utf8');+ }+ }const hive = new HiveManager(() => hiveHome);- const injection = await hive.ensureAgent({- id: 'pi-1',- name: 'Pi Agent',- provider: 'pi',- cwd: hiveHome- });+ const injection = await hive.ensureAgent({ id, name: 'Pi Agent', provider: 'pi', cwd: hiveHome });+ return injection.env.PI_CODING_AGENT_DIR;+}++function assertFiles(piAgentDir, want) {+ for (const [file, w] of Object.entries(want)) {+ const p = path.join(piAgentDir, file);+ assert.equal(fs.existsSync(p), w.exists, `${file} ${w.exists ? 'should exist' : 'should not be created'}`);+ if (w.exists) assert.deepEqual(JSON.parse(fs.readFileSync(p, 'utf8')), w.data, `${file} content should match source`);+ }+}- const piAgentDir = injection.env.PI_CODING_AGENT_DIR;+test('installPiHooks copies models.json from ~/.pi/agent when it exists', async (t) => {+ const get = {+ 'models.json': { default: 'anthropic/claude-sonnet-4-5', custom: { 'openai/gpt-4o': {} } },+ 'models-store.json': { version: 2, models: [{ id: 'm1', name: 'test' }] },+ };+ const want = {+ 'models.json': { exists: true, data: get['models.json'] },+ 'models-store.json': { exists: true, data: get['models-store.json'] },+ };++ const piAgentDir = await setupPi(t, { get, id: 'pi-1' });assert.ok(piAgentDir, 'PI_CODING_AGENT_DIR should be set');- assert.equal(fs.existsSync(path.join(piAgentDir, 'models.json')), true, 'models.json should exist');- assert.equal(fs.existsSync(path.join(piAgentDir, 'models-store.json')), true, 'models-store.json should exist');- assert.deepEqual(- JSON.parse(fs.readFileSync(path.join(piAgentDir, 'models.json'), 'utf8')),- modelsData,- 'models.json content should match source'- );- assert.deepEqual(- JSON.parse(fs.readFileSync(path.join(piAgentDir, 'models-store.json'), 'utf8')),- storeData,- 'models-store.json content should match source'- );+ assertFiles(piAgentDir, want);});-test('installPiHooks writes empty {} when ~/.pi/agent models files do not exist', async (t) => {- const hiveHome = tmpHome();- t.after(() => fs.rmSync(hiveHome, { recursive: true, force: true }));-- const fakeHome = tmpHome();- t.after(() => fs.rmSync(fakeHome, { recursive: true, force: true }));+test('installPiHooks does not create models files when source is missing (lets Pi fall back to its defaults)', async (t) => {+ const get = null;+ // absent means "no user override" — must not write {} which Pi reads as "zero models"+ const want = {+ 'models.json': { exists: false },+ 'models-store.json': { exists: false },+ };- const realHome = process.env.HOME;- process.env.HOME = fakeHome;- t.after(() => { if (realHome === undefined) delete process.env.HOME; else process.env.HOME = realHome; });-- const hive = new HiveManager(() => hiveHome);- const injection = await hive.ensureAgent({- id: 'pi-2',- name: 'Pi Agent',- provider: 'pi',- cwd: hiveHome- });-- const piAgentDir = injection.env.PI_CODING_AGENT_DIR;+ const piAgentDir = await setupPi(t, { get, id: 'pi-2' });assert.ok(piAgentDir, 'PI_CODING_AGENT_DIR should be set');- assert.equal(fs.existsSync(path.join(piAgentDir, 'models.json')), true, 'models.json should exist even when source is missing');- assert.equal(fs.existsSync(path.join(piAgentDir, 'models-store.json')), true, 'models-store.json should exist even when source is missing');- assert.deepEqual(- JSON.parse(fs.readFileSync(path.join(piAgentDir, 'models.json'), 'utf8')),- {},- 'models.json should default to empty object'- );- assert.deepEqual(- JSON.parse(fs.readFileSync(path.join(piAgentDir, 'models-store.json'), 'utf8')),- {},- 'models-store.json should default to empty object'- );+ assertFiles(piAgentDir, want);});-test('installPiHooks copies models.json even when models-store.json is missing', async (t) => {- const hiveHome = tmpHome();- t.after(() => fs.rmSync(hiveHome, { recursive: true, force: true }));-- const fakeHome = tmpHome();- t.after(() => fs.rmSync(fakeHome, { recursive: true, force: true }));-- const realHome = process.env.HOME;- process.env.HOME = fakeHome;- t.after(() => { if (realHome === undefined) delete process.env.HOME; else process.env.HOME = realHome; });-- const userPiAgentDir = path.join(fakeHome, '.pi', 'agent');- fs.mkdirSync(userPiAgentDir, { recursive: true });- const modelsData = { default: 'openai/gpt-4o' };- fs.writeFileSync(path.join(userPiAgentDir, 'models.json'), JSON.stringify(modelsData), 'utf8');-- const hive = new HiveManager(() => hiveHome);- const injection = await hive.ensureAgent({- id: 'pi-3',- name: 'Pi Agent',- provider: 'pi',- cwd: hiveHome- });+test('installPiHooks copies models.json but skips missing models-store.json', async (t) => {+ const get = { 'models.json': { default: 'openai/gpt-4o' } };+ const want = {+ 'models.json': { exists: true, data: get['models.json'] },+ 'models-store.json': { exists: false },+ };- const piAgentDir = injection.env.PI_CODING_AGENT_DIR;+ const piAgentDir = await setupPi(t, { get, id: 'pi-3' });assert.ok(piAgentDir, 'PI_CODING_AGENT_DIR should be set');- assert.deepEqual(- JSON.parse(fs.readFileSync(path.join(piAgentDir, 'models.json'), 'utf8')),- modelsData,- 'models.json should be copied from source'- );- assert.deepEqual(- JSON.parse(fs.readFileSync(path.join(piAgentDir, 'models-store.json'), 'utf8')),- {},- 'models-store.json should default to empty object when source is missing'- );+ assertFiles(piAgentDir, want);});