#!/usr/bin/env python3 """Native Pi discovery controls using owned source copies and real guard modules. No provider, session, private goal read or live mutation. The optional first argument is the installed brain root supplying wrapper/core/unslop modules. """ import json import os from pathlib import Path import shutil import subprocess import sys import tempfile repo = Path(__file__).resolve().parent.parent brain = Path(sys.argv[1]) if len(sys.argv) > 1 else Path.home() / '.mosaic' with tempfile.TemporaryDirectory(prefix='goal58-native-') as temp: root = Path(temp) for name in ['goal', 'mosaic-core']: shutil.copytree(repo / 'extensions' / name, root / '.pi/extensions' / name) legacy = root / 'fleet/extensions/goal' shutil.copytree(repo / 'extensions/goal', legacy) for name in ['wrapper-guard', 'mosaic-core']: (root / 'fleet/extensions' / name).symlink_to(brain / 'fleet/extensions' / name) (root / 'tools').mkdir() (root / 'tools/unslop-hook').symlink_to(brain / 'tools/unslop-hook') (root / '.goal-discovery-owned-fixture').write_text('synthetic goal58 fixture') settings = root / 'settings.json' def check(cwd, mode, guard='wrapper-guard'): settings.write_text(json.dumps({'extensions': [str(legacy), str(root / 'fleet/extensions' / guard)]})) subprocess.run(['node', str(repo / 'scripts/test-goal-discovery.mjs'), str(cwd), str(settings), mode, str(root)], check=True, timeout=30, env={**os.environ, 'MOSAIC_GOAL_DISCOVERY_FIXTURE_ROOT': str(root)}) check(root, 'conflict') legacy.rename(root / 'old-goal-source') legacy.symlink_to(root / '.pi/extensions/goal') check(root, 'unified') check(root, 'unified', 'mosaic-core') for relative in ['fleet/agents/topher', 'fleet/roles/interact']: cwd = root / relative (cwd / '.pi').mkdir(parents=True) (cwd / '.pi/extensions').symlink_to(root / '.pi/extensions') check(cwd, 'unified') velma = root / 'fleet/agents/velma' (velma / '.pi/extensions').mkdir(parents=True) (velma / '.pi/extensions/goal').symlink_to(root / '.pi/extensions/goal') shutil.copytree(repo / 'extensions/mosaic-core', velma / '.pi/extensions/mosaic-core') check(velma, 'unified') isolated = root / 'isolated' isolated.mkdir() check(isolated, 'unified') print('PASS native negative control and six unified discovery cases; no live source/state changes')