diff --git a/AGENTS.md b/AGENTS.md index 229dc60..39e5b4a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -317,7 +317,7 @@ bridges/ standalone third-party API bridges (SimpleX, the LLM bridge, OneDrive files, plus the OAuth2 device-code + refresh flow. No daemon (stdlib-only `urllib`); tokens stored under `.runtime/outlook/token.json` and seeded once with - `scripts/outlook-auth.py`; connection from `bridges.outlook`. + `packs/outlook/scripts/outlook-auth.py`; connection from `bridges.outlook`. browser.py + browser_client.py: BrowserBridge — real browser automation via Playwright (open/read/click/fill/screenshot), owning a persistent browser profile; optional heavy dep @@ -916,7 +916,7 @@ CLI, unit tests (24) + integration tests (2). `config.json` fields the operator edits; with an empty allowlist the gateway denies everyone (the safe default until the human adds their contact id). `--copy-data SRC` rsyncs a prior host's `data/` for continuity. - Bootstrap then runs `scripts/simplex-address.py` to create/print the command + Bootstrap then runs `packs/simplex/scripts/simplex-address.py` to create/print the command bot's contact address (and the forwarding bot's, via `--ws-url`). - First run downloads the 2.8G GGUF and builds `llama-cpp-python` from source (~10 min on 6 cores); reruns are fast no-ops. @@ -1276,7 +1276,7 @@ CLI, unit tests (24) + integration tests (2). unit wraps it in `script -q -e -c '…' /dev/null` to allocate a PTY: a TTY-less process (plain `ExecStart=` under systemd) accepts the socket but never emits `receivedContactRequest`/`newChatItems`, so contact requests hang forever. - `python scripts/simplex-address.py` then shows (creating on first run, via + `python packs/simplex/scripts/simplex-address.py` then shows (creating on first run, via `/_address` / `/_show_address `) the bot's user contact link, which a human adds in their SimpleX app to start a DM. `bootstrap.sh` prints it at the end of provisioning. @@ -1631,7 +1631,7 @@ CLI, unit tests (24) + integration tests (2). HTTPS) and is stdlib-only (`urllib` + `json` + `ssl` + `base64`), so `check_requirements` is always `(True, None)` and it starts instantly inside `semif-bridge.service`. Authorization is the OAuth2 **device code flow** (a - public client, no secret): `scripts/outlook-auth.py` runs it once and stores + public client, no secret): `packs/outlook/scripts/outlook-auth.py` runs it once and stores the access + refresh tokens 0600 under the checkout's `.runtime/outlook/token.json` (override with `bridges.outlook.token_path`); the client refreshes on expiry/401. The bridge starts without a token — an @@ -1674,7 +1674,7 @@ CLI, unit tests (24) + integration tests (2). host with an IPv6 address but no global IPv6 route — Playwright's downloader forces `autoSelectFamily` + a dual-stack resolver that prefers IPv6 and hangs instead of falling back to IPv4), bootstrap falls back to - `scripts/playwright-browsers.py`, which fetches the same pinned artifacts over + `packs/browser/scripts/playwright-browsers.py`, which fetches the same pinned artifacts over IPv4 and lays them out where Playwright expects. `bridges.browser.channel` / `executable_path` instead launch an already-installed browser (a Playwright channel like `chrome`/`msedge`, or a specific binary) and skip the managed @@ -1747,7 +1747,7 @@ covered. Deferred follow-ups: - [x] **6. Outlook / Microsoft Graph bridge** (`bridges/outlook.py` + `bridges/outlook_client.py`). Shipped: the `OutlookBridge` exposes mail, calendar, Microsoft To Do, contacts, and OneDrive over one JSON surface in - front of Graph; OAuth2 device-code + refresh (`scripts/outlook-auth.py`, tokens + front of Graph; OAuth2 device-code + refresh (`packs/outlook/scripts/outlook-auth.py`, tokens under `.runtime/outlook/token.json`); seven `packs/outlook/skills/outlook/*` skills (`next_message`, `send_message` confirm-gated, `next_event`, `create_event`, `create_task`, `list_contacts`, `list_files`). Deferred: writing/reusing diff --git a/PACKGEN.md b/PACKGEN.md index e399574..12f8489 100644 --- a/PACKGEN.md +++ b/PACKGEN.md @@ -55,6 +55,8 @@ packs// manifest.json # {"description": "..."} navigation text contract.json # mirror of the body's CONTRACT — TESTGEN.md skill.test.py # hermetic mechanics test — TESTGEN.md + scripts/ # optional concern helpers (e.g. an auth or + # setup script), run from the checkout ``` - The `` directory name is the tree bucket; the `` directory diff --git a/README.md b/README.md index 893cffd..a2a13b2 100644 --- a/README.md +++ b/README.md @@ -406,7 +406,7 @@ semif_agent/ packs.py SkillPack + PackRegistry (bundles skills by concern/bridge) packs/ skill packs, each cloned from its own repo (pack.) into this gitignored dir — see packs.json + PACKGEN.md -scripts/ bootstrap.sh, simplex-address.py, systemd/*.in +scripts/ bootstrap.sh, config_merge.py, voice-*.py, systemd/*.in requirements/ staging.txt — the pinned engine deps tests/ stdlib unit tests + tests/integration (real engine + LLM) CODEGEN.md the contract fed to the skill-body codegen model @@ -670,7 +670,7 @@ without it). `allowed_users` entries match a numeric contactId or a display name. The daemon must run in **bot mode** (`simplex-chat -p PORT --create-bot-display-name NAME`), not `--headless`/`--relay` — in v7 those mean "chat relay" and yield a relay address, not a user contact address. Add the -bot's contact link to reach it: `scripts/simplex-address.py` shows/creates it +bot's contact link to reach it: `packs/simplex/scripts/simplex-address.py` shows/creates it (bootstrap prints it), and the gateway prints it once on connect. **LXMF (Reticulum).** Runs **in-process — there is no external daemon**; @@ -842,7 +842,7 @@ calendar events, Microsoft To Do tasks, contacts, and OneDrive files. Like Nextcloud it has **no service daemon** (Graph is plain HTTPS) and is stdlib-only, so it starts instantly in the same `semif-bridge` process. Authorization is the OAuth2 **device code flow**: register an Entra ID public-client app, put its -`client_id` in `bridges.outlook`, and run `scripts/outlook-auth.py` once — the +`client_id` in `bridges.outlook`, and run `packs/outlook/scripts/outlook-auth.py` once — the tokens are stored (0600) under the checkout's `.runtime/outlook/token.json` and refreshed automatically. The bridge starts without a token; an unauthenticated route returns `503` telling the operator to run that helper. Skills call it at the @@ -884,7 +884,7 @@ installed with `scripts/bootstrap.sh --browser` (Playwright + Chromium land unde `.runtime/browser`; the bridge sets `PLAYWRIGHT_BROWSERS_PATH` there at launch). If `playwright install` fails — notably on a host with an IPv6 address but no global IPv6 route, where Playwright's downloader prefers IPv6 and hangs — -bootstrap falls back to `scripts/playwright-browsers.py`, which downloads the +bootstrap falls back to `packs/browser/scripts/playwright-browsers.py`, which downloads the same pinned artifacts over IPv4. To skip the managed download altogether, set `bridges.browser.channel` (a Playwright channel such as `chrome`/`msedge`) or `bridges.browser.executable_path` (a browser binary) to use an already-installed diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index d6d0cb2..107a7d9 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -461,10 +461,10 @@ PY # no working global IPv6 route, even though the CDN serves over IPv4. The # helper fetches the same pinned artifacts over IPv4 and lays them out # where Playwright expects them, so the install becomes a no-op. - echo "== retrying over IPv4 (scripts/playwright-browsers.py)" >&2 - PLAYWRIGHT_BROWSERS_PATH="$BROWSERS" "$PYTHON" "$REPO_ROOT/scripts/playwright-browsers.py" \ + echo "== retrying over IPv4 (packs/browser/scripts/playwright-browsers.py)" >&2 + PLAYWRIGHT_BROWSERS_PATH="$BROWSERS" "$PYTHON" "$REPO_ROOT/packs/browser/scripts/playwright-browsers.py" \ --browsers-path "$BROWSERS" --engine "$BROWSER_ENGINE" \ - || echo "WARN: browser priming failed; re-run: $PYTHON scripts/playwright-browsers.py --browsers-path $BROWSERS" >&2 + || echo "WARN: browser priming failed; re-run: $PYTHON packs/browser/scripts/playwright-browsers.py --browsers-path $BROWSERS" >&2 else echo "WARN: re-run: PLAYWRIGHT_BROWSERS_PATH=$BROWSERS $PYTHON -m playwright install $BROWSER_ENGINE" >&2 fi @@ -581,14 +581,14 @@ if command -v systemctl >/dev/null 2>&1; then if systemctl --user is-active --quiet semif-simplex.service 2>/dev/null; then echo "== ensuring the SimpleX bot contact address exists" for _ in 1 2 3 4 5 6 7 8 9 10; do - if SIMPLEX_ADDRESS="$("$PYTHON" "$REPO_ROOT/scripts/simplex-address.py" 2>/dev/null)"; then + if SIMPLEX_ADDRESS="$("$PYTHON" "$REPO_ROOT/packs/simplex/scripts/simplex-address.py" 2>/dev/null)"; then printf '%s\n' "$SIMPLEX_ADDRESS" | sed 's/^/ /' break fi sleep 2 done if [[ -z "$SIMPLEX_ADDRESS" ]]; then - echo "WARN: bot address not ready; run: $PYTHON scripts/simplex-address.py" >&2 + echo "WARN: bot address not ready; run: $PYTHON packs/simplex/scripts/simplex-address.py" >&2 fi fi fi @@ -610,7 +610,7 @@ if [[ -n "$BRIDGE_FORWARD_WS" ]] && command -v systemctl >/dev/null 2>&1; then if systemctl --user is-active --quiet semif-simplex-forward.service 2>/dev/null; then echo "== ensuring the forwarding bridge contact address exists" for _ in 1 2 3 4 5 6 7 8 9 10; do - if FORWARD_ADDRESS="$("$PYTHON" "$REPO_ROOT/scripts/simplex-address.py" --ws-url "$BRIDGE_FORWARD_WS" 2>/dev/null)"; then + if FORWARD_ADDRESS="$("$PYTHON" "$REPO_ROOT/packs/simplex/scripts/simplex-address.py" --ws-url "$BRIDGE_FORWARD_WS" 2>/dev/null)"; then printf '%s\n' "$FORWARD_ADDRESS" | sed 's/^/ /' break fi @@ -713,7 +713,7 @@ SimpleX command gateway (commands only): systemctl --user status semif-simplex semif-gateway journalctl --user -u semif-gateway -f - Its user contact address is printed above; re-print (creating if needed) with: - "$PYTHON" scripts/simplex-address.py + "$PYTHON" packs/simplex/scripts/simplex-address.py Add that address as a contact in your SimpleX app. - Then put your contactId/display name in config.json gateway.simplex.allowed_users (discover the id from a 'gateway_denied' trace @@ -739,7 +739,7 @@ SimpleX forwarding bridge (messaging UX for skills): - Runs as 'semif-simplex-forward' (a second bot daemon/profile, port $SIMPLEX_FORWARD_PORT) and 'semif-bridge' (the standalone bridge API). Its contact address is printed above; re-print with: - "$PYTHON" scripts/simplex-address.py --ws-url ws://127.0.0.1:$SIMPLEX_FORWARD_PORT + "$PYTHON" packs/simplex/scripts/simplex-address.py --ws-url ws://127.0.0.1:$SIMPLEX_FORWARD_PORT - Skills reach it over HTTP at the address derived from bridges.simplex (host/port, default http://127.0.0.1:5227); simplex.connect_link shows its address and simplex.next_message reads messages sent to it. diff --git a/scripts/outlook-auth.py b/scripts/outlook-auth.py deleted file mode 100644 index 258b61b..0000000 --- a/scripts/outlook-auth.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env python3 -"""Authorize the Outlook bridge with Microsoft (OAuth2 device code flow). - -The bridge reads the user's Microsoft account through Microsoft Graph; that -needs an access token, obtained once here with the **device code flow** (a public -client, no secret): - - 1. register an Entra ID app (see below) and put its client id in - `config.json` under `bridges.outlook.client_id`; - 2. run this script; - 3. open the printed URL on any device, enter the printed code, and sign in; - 4. the resulting tokens are saved (0600) to `.runtime/outlook/token.json`, - which the bridge loads and refreshes automatically. - -One-time app registration (Entra ID / Azure AD): - - - "App registrations" -> "New registration". - - Supported account types: include personal Microsoft accounts if the user - has an @outlook.com/@hotmail.com account (e.g. "Accounts in any - organizational directory and personal Microsoft accounts"). - - Authentication -> "Allow public client flows" = Yes (no redirect URI is - needed for device code). - - No API permissions need adding by hand: the script requests the delegated - scopes it needs and the user consents during sign-in. - -Usage (from the checkout): - - .runtime/venv/bin/python scripts/outlook-auth.py [--config config.json] - [--client-id ID] - [--tenant common] - [--token-path PATH] -""" - -from __future__ import annotations - -import argparse -import json -import sys -from pathlib import Path - -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) - -from semif_agent.bridges.outlook_client import ( # noqa: E402 - DEFAULT_TENANT, - OutlookError, - run_device_code_flow, - save_token, -) - -DEFAULT_TOKEN_PATH = str(REPO_ROOT / ".runtime" / "outlook" / "token.json") - - -def _block(config_path: str) -> dict: - try: - with open(config_path, encoding="utf-8") as handle: - config = json.load(handle) - except (OSError, ValueError): - return {} - block = (config.get("bridges", {}) or {}).get("outlook", {}) or {} - return block if isinstance(block, dict) else {} - - -def main(argv: list[str] | None = None) -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--config", default="config.json") - parser.add_argument("--client-id", default=None, help="override bridges.outlook.client_id") - parser.add_argument("--tenant", default=None, help="override bridges.outlook.tenant (default common)") - parser.add_argument("--token-path", default=None, help="where to save the tokens") - args = parser.parse_args(argv) - - block = _block(args.config) - client_id = str(args.client_id or block.get("client_id") or "").strip() - tenant = str(args.tenant or block.get("tenant") or DEFAULT_TENANT).strip() or DEFAULT_TENANT - token_path = str(args.token_path or block.get("token_path") or DEFAULT_TOKEN_PATH) - scopes = block.get("scopes") or None - - if not client_id: - print( - "no Microsoft client id configured: set bridges.outlook.client_id in " - f"{args.config} (or pass --client-id)", - file=sys.stderr, - ) - return 1 - - try: - token = run_device_code_flow(client_id, tenant, scopes) - except OutlookError as exc: - print(f"authorization failed: {exc}", file=sys.stderr) - return 1 - except KeyboardInterrupt: - print("\ncancelled", file=sys.stderr) - return 1 - - save_token(token_path, token) - print(f"saved Outlook authorization to {token_path}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/playwright-browsers.py b/scripts/playwright-browsers.py deleted file mode 100755 index 3b8b745..0000000 --- a/scripts/playwright-browsers.py +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env python3 -"""Prime Playwright's browser cache over IPv4 (a fallback for `playwright install`). - -`playwright install` downloads through Playwright's own Node fetcher, which -forces `autoSelectFamily` with a custom dual-stack resolver that prefers IPv6. -On a host that has an IPv6 address (often a ULA) but no working global IPv6 -route, that first IPv6 connection hangs instead of falling back to IPv4, so the -download stalls until the socket timeout and `playwright install` fails even -though the CDN is reachable over IPv4. - -This helper downloads the exact pinned artifacts Playwright expects, forcing -IPv4, and lays them out under `PLAYWRIGHT_BROWSERS_PATH` with the -`INSTALLATION_COMPLETE` marker Playwright checks, so the normal install (and the -browser bridge) then works. It reads revisions/versions from the installed -Playwright's own `browsers.json`, so it tracks version bumps automatically. - -Idempotent: an artifact with its marker present is skipped. Only Chromium (plus -its headless shell and ffmpeg) is handled; Firefox/WebKit have no such helper. - -Usage: - scripts/playwright-browsers.py --browsers-path .runtime/browser - scripts/playwright-browsers.py --browsers-path .runtime/browser --engine chromium -""" - -from __future__ import annotations - -import argparse -import json -import os -import platform -import shutil -import stat -import subprocess -import sys -import tempfile -import urllib.request -import zipfile -from pathlib import Path - -#: The CDN mirror Playwright's fetcher falls back to and that serves the exact -#: Chrome-for-Testing layout over a redirect (IPv4 works). -CDN = "https://cdn.playwright.dev" - -#: Executables that must stay executable after a pure-Python unzip (which does -#: not preserve permissions). Relative to each browser's directory. -_EXECUTABLES = { - "chromium": ("chrome-linux64/chrome",), - "chromium_headless_shell": ("chrome-headless-shell-linux64/chrome-headless-shell",), - "ffmpeg": ("ffmpeg-linux",), -} - - -def _arch_suffix() -> str: - machine = platform.machine().lower() - return "arm64" if machine in ("aarch64", "arm64") else "x64" - - -def _cft_paths(arch: str) -> dict[str, str]: - if arch == "arm64": - return { - "chromium": "linux-arm64/chrome-linux-arm64.zip", - "chromium_headless_shell": "linux-arm64/chrome-headless-shell-linux-arm64.zip", - "ffmpeg": "ffmpeg-linux-arm64.zip", - } - return { - "chromium": "linux64/chrome-linux64.zip", - "chromium_headless_shell": "linux64/chrome-headless-shell-linux64.zip", - "ffmpeg": "ffmpeg-linux.zip", - } - - -def _browsers_json() -> dict: - import playwright # the package the venv already has - - path = Path(playwright.__file__).resolve().parent / "driver" / "package" / "browsers.json" - with open(path) as handle: - return json.load(handle) - - -def _artifacts(browsers_json: dict, arch: str) -> list[tuple[str, str]]: - """List of `(directory_name, download_path)` Playwright expects.""" - suffixes = _cft_paths(arch) - wanted = { - "chromium": ("chromium", "chromium"), - "chromium-headless-shell": ("chromium_headless_shell", "chromium_headless_shell"), - "ffmpeg": ("ffmpeg", "ffmpeg"), - } - out: list[tuple[str, str]] = [] - for browser in browsers_json.get("browsers", []): - name = browser.get("name") - if name not in wanted or not browser.get("installByDefault", True): - continue - slug, key = wanted[name] - revision = browser["revision"] - if key == "ffmpeg": - path = f"builds/ffmpeg/{revision}/{suffixes['ffmpeg']}" - else: - path = f"builds/cft/{browser['browserVersion']}/{suffixes[key]}" - out.append((f"{slug}-{revision}", path)) - return out - - -def _download(url: str, dest: str) -> None: - if shutil.which("curl"): - subprocess.run( - ["curl", "-4", "-fL", "--retry", "3", "-m", "600", "-o", dest, url], - check=True, - ) - return - # No curl: urllib may pick IPv6 on a broken host, but it is the best we have. - print(f" (curl not found; using urllib for {url})", flush=True) - request = urllib.request.Request(url, headers={"User-Agent": "semif-bootstrap"}) - with urllib.request.urlopen(request, timeout=600) as response, open(dest, "wb") as handle: - shutil.copyfileobj(response, handle) - - -def _extract(archive: str, target: Path, directory_name: str) -> None: - if shutil.which("unzip"): - subprocess.run(["unzip", "-q", "-o", archive, "-d", str(target)], check=True) - else: - with zipfile.ZipFile(archive) as zf: - zf.extractall(target) - for relative in _EXECUTABLES.get(directory_name.split("-")[0], ()): - candidate = target / relative - if candidate.is_file(): - candidate.chmod(candidate.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) - - -def _install_one(browsers_path: Path, directory_name: str, download_path: str) -> bool: - target = browsers_path / directory_name - marker = target / "INSTALLATION_COMPLETE" - if marker.is_file(): - print(f" = {directory_name} already installed") - return True - url = f"{CDN}/{download_path}" - print(f" + {directory_name} <- {url}") - target.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(prefix="semif-browser-") as tmp: - archive = os.path.join(tmp, "download.zip") - _download(url, archive) - _extract(archive, target, directory_name) - marker.write_text("") - return True - - -def main(argv: list[str] | None = None) -> int: - parser = argparse.ArgumentParser(description="Prime Playwright's browser cache over IPv4.") - parser.add_argument("--browsers-path", required=True, help="PLAYWRIGHT_BROWSERS_PATH to populate") - parser.add_argument("--engine", default="chromium", help="only 'chromium' is supported by this helper") - args = parser.parse_args(argv) - - if args.engine != "chromium": - print(f"helper only primes chromium, not {args.engine!r}; nothing to do", file=sys.stderr) - return 0 - - browsers_path = Path(args.browsers_path).expanduser().resolve() - browsers_path.mkdir(parents=True, exist_ok=True) - arch = _arch_suffix() - artifacts = _artifacts(_browsers_json(), arch) - if not artifacts: - print("no chromium artifacts found in playwright's browsers.json", file=sys.stderr) - return 1 - - print(f"priming Playwright browsers into {browsers_path} ({arch}, IPv4)") - for directory_name, download_path in artifacts: - _install_one(browsers_path, directory_name, download_path) - print("done; 'playwright install chromium' should now be a no-op") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/simplex-address.py b/scripts/simplex-address.py deleted file mode 100644 index f6569a7..0000000 --- a/scripts/simplex-address.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env python3 -"""Print (creating if needed) the SimpleX bot's contact address. - -The gateway talks to a local `simplex-chat` daemon running as a bot -(`--create-bot-display-name`, see simplex_chat in config.json). To connect a -phone/client to the bot you need the bot's *user* contact address, not a chat -relay address; this queries the daemon's WebSocket API, creating the address on -first run, and prints the short link (and full link). Requires the daemon to be -running. - -Usage: - .runtime/venv/bin/python scripts/simplex-address.py [--config config.json] - [--ws-url ws://...] - [--user-id 1] -""" - -from __future__ import annotations - -import argparse -import asyncio -import json -import sys - - -def _ws_url(config_path: str) -> str: - try: - with open(config_path) as fh: - cfg = json.load(fh) - except (OSError, ValueError): - return "ws://127.0.0.1:5226" - return str(cfg.get("gateway", {}).get("simplex", {}).get("ws_url") or "ws://127.0.0.1:5226") - - -async def _resolve(ws_url: str, user_id: int) -> dict: - try: - import websockets - except ImportError: - raise SystemExit("the `websockets` package is required (pip install websockets)") - async with websockets.connect(ws_url, max_size=None) as ws: - - async def cmd(command: str) -> dict: - await ws.send(json.dumps({"corrId": "addr", "cmd": command})) - raw = await asyncio.wait_for(ws.recv(), timeout=20) - return json.loads(raw).get("resp", {}) or {} - - resp = await cmd(f"/_show_address {user_id}") - if resp.get("type") == "userContactLink": - return resp.get("contactLink", {}) or {} - # No address yet -> create one (APICreateMyAddress). - resp = await cmd(f"/_address {user_id}") - if resp.get("type") == "userContactLinkCreated": - return {"connLinkContact": resp.get("connLinkContact", {}) or {}} - raise SystemExit(f"could not read or create address: {json.dumps(resp)[:300]}") - - -def main() -> int: - ap = argparse.ArgumentParser(description=__doc__) - ap.add_argument("--config", default="config.json") - ap.add_argument("--ws-url", default=None) - ap.add_argument("--user-id", type=int, default=1) - args = ap.parse_args() - - ws_url = args.ws_url or _ws_url(args.config) - try: - link = asyncio.run(_resolve(ws_url, args.user_id)) - except OSError as exc: - print(f"cannot reach simplex-chat at {ws_url}: {exc}", file=sys.stderr) - return 1 - except asyncio.TimeoutError: - print(f"simplex-chat at {ws_url} did not answer", file=sys.stderr) - return 1 - - conn = link.get("connLinkContact", {}) or link - short = conn.get("connShortLink") - full = conn.get("connFullLink") - if short: - print(short) - if full: - print(full) - if not (short or full): - print("no contact address found", file=sys.stderr) - return 1 - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/semif_agent/bridges/outlook.py b/semif_agent/bridges/outlook.py index 11573d5..8adf239 100644 --- a/semif_agent/bridges/outlook.py +++ b/semif_agent/bridges/outlook.py @@ -10,7 +10,7 @@ and `outlook_bridge_token` from `ctx.config` and calls a documented route. There is no service daemon and no third-party dependency: Graph is plain HTTPS, so the bridge is stdlib-only (`urllib`) and starts instantly, like Nextcloud. Authorization is the OAuth2 device code flow, run once with -`scripts/outlook-auth.py`; the resulting tokens are stored (0600) under the +`packs/outlook/scripts/outlook-auth.py`; the resulting tokens are stored (0600) under the checkout's `.runtime/outlook/token.json`. The bridge starts without them and an unauthenticated route returns 503 telling the operator to run that helper. @@ -116,7 +116,7 @@ class OutlookBridge(BridgeService): "any request -> 401 {\"error\": \"unauthorized\"} when the token is " "configured and the auth header is missing or wrong", "503 {\"error\": \"...\"} when the bridge is not authenticated " - "(run scripts/outlook-auth.py) or has no client id configured; 502 " + "(run packs/outlook/scripts/outlook-auth.py) or has no client id configured; 502 " "{\"error\": \"...\"} on a real Microsoft Graph failure (transport, " "HTTP error, or bad reply)", ), @@ -198,7 +198,7 @@ class OutlookBridge(BridgeService): return 503, { "error": ( "the Outlook bridge has no connection configured (set " - "bridges.outlook.client_id, then run scripts/outlook-auth.py)" + "bridges.outlook.client_id, then run packs/outlook/scripts/outlook-auth.py)" ) } diff --git a/semif_agent/bridges/outlook_client.py b/semif_agent/bridges/outlook_client.py index b2418c1..894f045 100644 --- a/semif_agent/bridges/outlook_client.py +++ b/semif_agent/bridges/outlook_client.py @@ -10,7 +10,7 @@ Authorization is the OAuth2 **device code flow** (a public client: no secret): `run_device_code_flow` prints a code the user enters at a Microsoft URL, then stores the resulting access + refresh tokens. The bridge starts without a token; the first authenticated call raises `OutlookAuthRequired`, which the bridge maps -to a 503 telling the operator to run `scripts/outlook-auth.py`. Every other +to a 503 telling the operator to run `packs/outlook/scripts/outlook-auth.py`. Every other failure is an `OutlookError` carrying the HTTP status when there was one, so the bridge maps it to a 502 (a real Graph failure) rather than a fabricated success. @@ -49,7 +49,7 @@ DEFAULT_SCOPES = ( TOKEN_REFRESH_SKEW = 120.0 MAX_PAGES = 20 MAX_RETRIES = 3 -AUTH_HINT = "run scripts/outlook-auth.py to authorize Outlook" +AUTH_HINT = "run packs/outlook/scripts/outlook-auth.py to authorize Outlook" class OutlookError(Exception): diff --git a/semif_agent/cli.py b/semif_agent/cli.py index b774000..79932cf 100644 --- a/semif_agent/cli.py +++ b/semif_agent/cli.py @@ -715,7 +715,7 @@ def _gateway_address_callback(adapter): """Return an `on_connected` coroutine that prints the bot's contact link once. A human cannot reach the gateway without the bot's SimpleX contact address, - and the only thing that surfaced it before was `scripts/simplex-address.py` + and the only thing that surfaced it before was `packs/simplex/scripts/simplex-address.py` run once at provision time. Print it on connect, from the operator front end (the CLI), through the daemon the gateway already owns — show-or-create, no second connection, no new transport surface. The lookup is best-effort: a diff --git a/tests/test_outlook_bridge.py b/tests/test_outlook_bridge.py index 3921817..0960da6 100644 --- a/tests/test_outlook_bridge.py +++ b/tests/test_outlook_bridge.py @@ -590,7 +590,7 @@ def test_bridge_auth_required_is_503(): configured = True def list_messages(self, *args, **kwargs): - raise OutlookAuthRequired("run scripts/outlook-auth.py") + raise OutlookAuthRequired("run packs/outlook/scripts/outlook-auth.py") bridge = OutlookBridge({"client_id": "c"}, client=Unauthorized()) status, payload = bridge.handle_get("/mail/messages", {})