Files
multi-agent-mux/.agents/skills/lib_py/agents/__main__.py
T
Godopu b4821fafa8 feat(a4,c3b): complete A-4 Phase 2 agent knowledge migration & Option B isolation removal
- Option B / C-3b: Deprecate isolation.root and remove its 4 legacy consumers in lib.sh, workspace_uuid.py, verify_session.py, and stop_session.sh.
- M2~M7 Migration: Implement artifact_path, verify_artifact, purge_artifacts, spawn_spec, resume_spec, auth_ok, discover, ready_tokens, exit_key, and delegate_agent_key across BaseAgentAdapter and all 4 adapters (Claude, Agy, Hermes, Cline).
- Migrate shell duplications in lib.sh, create_session.sh, resume_session.sh, stop_session.sh, and reconcile.sh to python -m lib_py.agents facts.
- Hardening & Corrections: Fix Cline resume_spec flag to '-i --id', apply shlex.quote across all facts variables with MAM_ prefix, add safe fallback in wait_for_tui_ready.
- Add comprehensive contract tests in tests/test_a4_adapter_contract.py and sync IMPROVEMENTS.md / LOG.md.
- Verified: 100% PASS across unit, component, contract, and integration tests.
2026-08-16 23:15:24 +09:00

55 lines
1.9 KiB
Python

# __main__.py — CLI bridge for lib_py.agents facts and resolution (N4)
import sys, json, shlex
from lib_py.agents.registry import get_adapter, own_key, agent_of_row
def main():
if len(sys.argv) < 2:
print("Usage: python -m lib_py.agents <facts|resolve> [args...]", file=sys.stderr)
sys.exit(1)
cmd = sys.argv[1]
if cmd == 'facts':
agent_name = sys.argv[2] if len(sys.argv) > 2 else ''
adapter = get_adapter(agent_name)
if not adapter:
print(f"ERROR: Unknown agent {agent_name!r}", file=sys.stderr)
sys.exit(1)
# Emit shell-eval friendly facts
q = shlex.quote
print(f"MAM_AGENT_NAME={q(adapter.name)}")
print(f"MAM_OWN_KEY={q(adapter.own_key)}")
print(f"MAM_INPUT_PROMPT={q(adapter.input_prompt or '')}")
print(f"MAM_INPUT_PLACEHOLDER={q(adapter.input_placeholder or '')}")
print(f"MAM_INPUT_RULE_PATTERN={q(adapter.input_rule_pattern or '')}")
print(f"MAM_READY_TOKENS={q(adapter.ready_tokens)}")
print(f"MAM_EXIT_KEY={q(adapter.exit_key)}")
print(f"MAM_DELEGATE_AGENT_KEY={q(adapter.delegate_agent_key)}")
elif cmd == 'resolve':
name = sys.argv[2] if len(sys.argv) > 2 else ''
resolved = agent_of_row({}, session_name=name)
if resolved:
print(resolved)
sys.exit(0)
sys.exit(1)
elif cmd == 'input-region':
agent_name = sys.argv[2] if len(sys.argv) > 2 else ''
pane_text = sys.stdin.read()
from lib_py.agents.input_region import extract_input_region
try:
region = extract_input_region(pane_text, agent_name)
print(region)
sys.exit(0)
except Exception as ex:
print(f"ERROR: {ex}", file=sys.stderr)
sys.exit(5)
else:
print(f"ERROR: Unknown CLI command {cmd!r}", file=sys.stderr)
sys.exit(1)
if __name__ == '__main__':
main()