oclaw/runtime/operations/scripts/create_bind_code.py
oliver 420abac9f1 refactor: root-package imports (svc/runtime/interfaces) and fix PYTHONPATH
- Rename platform/ to svc/ to avoid shadowing stdlib platform.
- Replace from oclaw.* with from svc/runtime/interfaces; update -m CLI paths.
- tests/conftest: prepend repo root to sys.path (no parent-folder package name).
- CI: paths and offline_eval script under repo root.
- Ops scripts: PYTHONPATH must be repo root for python -m runtime.* (fixes gateway/WhatsApp sidecar startup).
- Fix default oclaw.json path in tabular/file attachment limits; stabilize attachment test config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 14:51:17 +08:00

37 lines
912 B
Python

from __future__ import annotations
import secrets
import sys
from svc.config.paths import db_path
from svc.persistence.sqlite_store import SqliteStore
def main() -> int:
store = SqliteStore(db_path())
tenants = store.list_tenants(limit=1)
if tenants:
tenant_id = tenants[0]["id"]
tenant_name = tenants[0]["name"]
else:
created = store.create_tenant("Team")
tenant_id = created["id"]
tenant_name = created["name"]
role = "member"
if len(sys.argv) >= 2 and str(sys.argv[1]).strip():
role = str(sys.argv[1]).strip()
code = secrets.token_urlsafe(6)
store.create_bind_code(tenant_id=tenant_id, role=role, code=code)
print(f"tenant={tenant_name} ({tenant_id})")
print(f"role={role}")
print(f"bind_code={code}")
print(f"wecom_cmd=bind {code}")
return 0
if __name__ == "__main__":
raise SystemExit(main())