Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

12.0 KB
Raw Blame
#!/usr/bin/env python3
"""Classify a change set into CI lanes (the orchestrator's ``detect`` job).

Reads newline-separated changed paths (repo-relative, forward slashes) from
stdin or ``--files-from``, decides which CI lanes the change can affect, and
writes ``lane=true|false`` lines to ``$GITHUB_OUTPUT`` (and stdout).

Contract — FAIL OPEN, never closed. A lane may run without need; it must
never be skipped when the change could break it:

* ``--full`` (push to main, nightly, release, manual dispatch) or an EMPTY
  change set turns every lane on. An empty set means the diff could not be
  computed, never "nothing changed".
* A change under ``.github/`` or ``scripts/ci/`` turns every lane on: it
  rewires the pipeline itself.
* ``python`` is a DENYLIST: it is off only when every path is provably
  outside what the test suite reads. Tests read docs/, the frontend source,
  install/ and assets/, so those keep it on.
* ``--proven`` is the one way every lane goes off: the caller verified that
  the merge queue already passed this exact commit (``plan_run.py proven``),
  so nothing is left to prove on the push that lands it.

Outputs beyond the lanes:

* ``full``           — every lane forced on (the caller also widens matrices).
* ``changed_count``  — number of changed paths (0 = unknown).

Usage::

    git diff --name-only BASE HEAD | python scripts/ci/classify_changes.py
    python scripts/ci/classify_changes.py --full
"""

from __future__ import annotations

import argparse
import os
import sys
from collections.abc import Iterable
from pathlib import Path

_REPO_ROOT = Path(__file__).resolve().parents[2]
if str(_REPO_ROOT) not in sys.path:
    sys.path.insert(0, str(_REPO_ROOT))

from scripts.ci import agent_runtime_suite  # noqa: E402

# Trees the Python suite never reads (verified by grepping tests/ for each).
# Everything NOT listed keeps the python lane on — unknown means relevant.
_PY_IRRELEVANT_PREFIXES = (
    "wiki-video/",
    "board-backend/",
    "qa/",
    "skillbook/",
    "keyproxy/",
    ".github/ISSUE_TEMPLATE/",
)
_PY_IRRELEVANT_FILES = {
    ".github/PULL_REQUEST_TEMPLATE.md",
    ".github/dependabot.yml",
    "CODE_OF_CONDUCT.md",
    "SECURITY.md",
}

_PIPELINE_PREFIXES = (".github/workflows/", ".github/actions/", "scripts/ci/")

# The package directory as every table below spells it. A changed path under
# any name the directory has had is read as this spelling first, so renaming
# the directory can never turn a lane off: neither for the commit that moves
# it nor for a branch that still carries the other layout.
_PACKAGE_PREFIX = "dodaios/"
_PACKAGE_NAMES = ("jarvis", "dodaios")

_FRONTEND_PREFIXES = ("dodaios/ui/web/frontend/",)
_FRONTEND_FILES = {"scripts/ci/check_frontend_bundle_budget.py"}

_DEPS_FILES = {
    "pyproject.toml",
    "requirements.in",
    "requirements.txt",
    "uv.lock",
    "packaging/native-crypto.json",
    "packaging/native-crypto-uv.toml",
    "dodaios/assets/browser/pyproject.toml",
    "dodaios/assets/browser/requirements.in",
    "dodaios/assets/browser/requirements.lock",
    "scripts/native_crypto_index.py",
    "scripts/pip_install.py",
    "scripts/build_native_crypto.py",
    "tests/contract/test_native_crypto.py",
    "tests/contract/test_native_ssh.py",
    "dodaios/computers/ssh_packet_guard.py",
}

_REALTIME_PREFIXES = (
    "dodaios/realtime/",
    "dodaios/plugins/realtime/",
    "dodaios/audio/",
    "dodaios/speech/",
    "dodaios/live/",
    "dodaios/core/",
    "tests/contract/test_realtime",
    "tests/contract/test_gpt_live",
)
_REALTIME_FILES = {"scripts/realtime_reliability_gate.py"} | _DEPS_FILES

_CLI_PREFIXES = ("dodaios/cli_ctl/", "dodaios/commands/", "tests/unit/cli_ctl/")

_DRAGDROP_FILES = {
    "dodaios/overlay/drop_target.py",
    "dodaios/overlay/drop_bridge.py",
    "scripts/crossplatform/verify_drop_target.py",
}

_BROWSER_PREFIXES = (
    "dodaios/society/browser/",
    "tests/contract/test_browser",
    "tests/unit/society/test_browser",
)
_BROWSER_FILES = {
    "dodaios/ui/web/society_browser_routes.py",
    "dodaios/ui/web/mcp_server_routes.py",
    "dodaios/agent_chat/runner_cli.py",
    "dodaios/brain/tool_gateway.py",
    "dodaios/society/approvals.py",
}

# Native macOS surface: permissions, bundle, autostart, Computer-Use. The old
# standalone workflow also matched all of tests/** and dodaios/ui/**, which put
# three 45-minute macOS jobs behind nearly every PR; the lane keeps the
# platform code and the exact test files that job runs.
#
# The just-in-time permission service is called from many consumers, so the
# lane also covers every directory that asks for, or acts on, a macOS
# permission: capture and speech (dodaios/audio/), computer use (dodaios/cu/),
# screenshots (dodaios/vision/, dodaios/screen_context/), dictation
# (dodaios/dictation/), global shortcuts (dodaios/trigger/, which includes
# dodaios/trigger/backends/) and the permission port, the service and window
# control (dodaios/platform/: permissions.py, permission_service.py,
# window_state.py). Packaging is covered too: the spec, packaging/macos/ and the
# single usage-string table both bundles load. The tool plugins that capture or
# type (screenshot, type_text, verify_localhost), the appshot gesture, the speech
# diagnosis, the screen-context routes, the CLI relay and the bundle-id constants
# are consumers too and are listed by file.
_MACOS_PREFIXES = (
    "install/",
    "dodaios/admin/",
    "dodaios/appshot/",
    "dodaios/audio/",
    "dodaios/autostart/",
    "dodaios/cu/",
    "dodaios/dictation/",
    "dodaios/platform/",
    "dodaios/screen_context/",
    "dodaios/setup/",
    "dodaios/trigger/",
    "dodaios/vision/",
    "dodaios/ui/desktop",
    "packaging/macos/",
    "tests/unit/platform/",
    "tests/unit/audio/",
    "tests/unit/autostart/",
    "tests/unit/cu/",
    "tests/unit/setup/",
    "tests/unit/trigger/",
    "tests/unit/ui/web/test_permissions_",
    "tests/unit/vision/",
)
_MACOS_FILES = {
    "pyproject.toml",
    "uv.lock",
    ".githooks/pre-push",
    "dodaios.spec",
    "dodaios/core/macos_privacy_strings.py",
    "dodaios/core/branding.py",
    "dodaios/core/events.py",
    "dodaios/core/protocols.py",
    "dodaios/cli_ctl/commands/permissions.py",
    "dodaios/plugins/harness/computer_use.py",
    "dodaios/plugins/tool/screen_snapshot.py",
    "dodaios/plugins/tool/type_text.py",
    "dodaios/plugins/tool/verify_localhost.py",
    "dodaios/speech/diagnose.py",
    "dodaios/speech/pipeline.py",
    "dodaios/tasks/event_catalog.py",
    "dodaios/ui/web/permissions_routes.py",
    "dodaios/ui/web/screen_context_routes.py",
    "dodaios/ui/web/settings_routes.py",
    "tests/contract/test_permission_service_contract.py",
    "tests/fakes/fake_permission_service.py",
    "tests/fakes/fake_tcc.py",
    "tests/unit/ci/test_check_frozen_macos_app.py",
    "tests/unit/ci/test_macos_desktop_permission_step.py",
    "tests/unit/ui/web/test_keybinds_input_monitoring_ask.py",
    "tests/unit/core/test_permission_events.py",
    "scripts/measure_boot.py",
    "scripts/measure_desktop_boot.py",
}

# Installer smoke: the raw install path a downloader runs.
_INSTALLER_PREFIXES = ("install/",)
_INSTALLER_FILES = {
    "pyproject.toml",
    "requirements.txt",
    "dodaios/__main__.py",
    "dodaios/setup/prefetch.py",
    "dodaios/setup/model_report.py",
    "dodaios/speech/wake_model_fetch.py",
    "tests/unit/install/test_install_sh_stage1.py",
    ".github/workflows/sign-installer.yml",
}

# In-app updater: status, download + verify, native handover, the restart
# helper that finishes it, and the installer scripts it hands over to. Each
# OS replaces a running app differently, so this lane runs on all three.
_UPDATER_PREFIXES = (
    "dodaios/core/installer_update",
    "dodaios/core/frozen",
    "dodaios/ui/relauncher",
    "dodaios/ui/web/update_routes",
    "packaging/",
    "tests/fakes/fake_installer_update",
    "tests/integration/test_update_",
    "tests/unit/core/test_installer_update",
    "tests/unit/install/test_installer_update",
    "tests/unit/ui/test_relauncher",
    "tests/unit/ui/web/test_launcher_update_handoff",
    "tests/unit/ui/web/test_update_routes",
    "tests/unit/web/test_update_",
)
_UPDATER_FILES = {
    "dodaios/__main__.py",
    "dodaios/ui/desktop_app.py",
    "dodaios/ui/web/launcher.py",
    "dodaios/ui/web/settings_routes.py",
    ".github/workflows/desktop-installers.yml",
} | _DEPS_FILES

LANES = (
    "python",
    "frontend",
    "deps",
    "realtime",
    "cli",
    "dragdrop",
    "browser",
    "macos_desktop",
    "installer",
    "updater",
    "agent_runtimes",
)


def _normalize(paths: Iterable[str]) -> list[str]:
    out: list[str] = []
    for raw in paths:
        path = raw.strip().replace("\\", "/")
        if path.startswith("./"):
            path = path[2:]
        head, slash, rest = path.partition("/")
        if slash and head in _PACKAGE_NAMES:
            path = _PACKAGE_PREFIX + rest
        if path:
            out.append(path)
    return out


def _any(paths: list[str], prefixes: tuple[str, ...] = (), files: set[str] | None = None) -> bool:
    files = files or set()
    return any(p.startswith(prefixes) or p in files for p in paths)


def _python_relevant(path: str) -> bool:
    return not (path.startswith(_PY_IRRELEVANT_PREFIXES) or path in _PY_IRRELEVANT_FILES)


def classify(paths: Iterable[str], *, full: bool = False, proven: bool = False) -> dict[str, bool]:
    """Return ``{lane: bool}`` plus ``full`` for a change set."""
    if proven:
        return {**{lane: False for lane in LANES}, "full": False}
    changed = _normalize(paths)
    force = full or not changed or _any(changed, _PIPELINE_PREFIXES)
    if force:
        result = {lane: True for lane in LANES}
        result["full"] = True
        return result
    return {
        "python": any(_python_relevant(p) for p in changed),
        "frontend": _any(changed, _FRONTEND_PREFIXES, _FRONTEND_FILES),
        "deps": _any(changed, (), _DEPS_FILES),
        "realtime": _any(changed, _REALTIME_PREFIXES, _REALTIME_FILES),
        "cli": _any(changed, _CLI_PREFIXES)
        or any(p.startswith("dodaios/ui/web/") and p.endswith("_routes.py") for p in changed),
        "dragdrop": _any(changed, (), _DRAGDROP_FILES),
        "browser": _any(changed, _BROWSER_PREFIXES, _BROWSER_FILES),
        "macos_desktop": _any(changed, _MACOS_PREFIXES, _MACOS_FILES),
        "installer": _any(changed, _INSTALLER_PREFIXES, _INSTALLER_FILES),
        "updater": _any(changed, _UPDATER_PREFIXES, _UPDATER_FILES),
        # Hermes / OpenClaw agents, proven on all three OSes and with the
        # real runtimes (scripts/ci/agent_runtime_suite.py owns the table).
        "agent_runtimes": any(agent_runtime_suite.touches(p) for p in changed)
        or _any(changed, (), _DEPS_FILES),
        "full": False,
    }


def _emit(result: dict[str, bool], changed_count: int) -> list[str]:
    lines = [f"{key}={'true' if value else 'false'}" for key, value in result.items()]
    lines.append(f"changed_count={changed_count}")
    return lines


def main(argv: list[str] | None = None) -> int:
    parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
    parser.add_argument("--full", action="store_true", help="Force every lane on.")
    parser.add_argument(
        "--proven",
        action="store_true",
        help="Every lane off: the merge queue already passed this exact commit.",
    )
    parser.add_argument("--files-from", type=Path, help="Read paths from this file, not stdin.")
    args = parser.parse_args(argv)

    if args.full:
        paths: list[str] = []
    elif args.files_from:
        paths = args.files_from.read_text(encoding="utf-8").splitlines()
    else:
        paths = [] if sys.stdin is None or sys.stdin.isatty() else sys.stdin.read().splitlines()
    changed = _normalize(paths)
    result = classify(changed, full=args.full, proven=args.proven)
    lines = _emit(result, len(changed))

    output = os.environ.get("GITHUB_OUTPUT")
    if output:
        with open(output, "a", encoding="utf-8") as handle:
            handle.write("\n".join(lines) + "\n")
    print("\n".join(lines))
    return 0


if __name__ == "__main__":
    sys.exit(main())