Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

6.5 KB
Raw Blame
# Single local quality gate: format + lint + code rules, scoped to files you
# changed vs origin/main (merge-base, plus uncommitted and untracked work) so
# the output is exactly what is wrong with YOUR changes — legacy findings in
# untouched files never appear. Findings print as file:line with the rule id;
# ast-grep rule ids map to docs/development/style-guide.md (its `severity: error` rules fail
# the run, warnings/hints only print). oxlint's only error rule is
# typescript/no-floating-promises, so apps/web files are linted --type-aware.
#
#   just check        fast: rustfmt + biome + oxlint + ast-grep + PII   (~seconds)
#   just check full   also runs tsc + clippy                      (~minutes)
#
# Override the diff base with CHECK_BASE=<ref> (useful in shallow clones,
# where no origin/main merge-base exists and the scope silently narrows to
# uncommitted work only).
check *ARGS:
    #!/usr/bin/env bash
    set -uo pipefail
    cd {{ justfile_directory() }}

    base="${CHECK_BASE:-$(git merge-base HEAD origin/main 2>/dev/null || true)}"
    if [ -z "$base" ]; then
      echo "note: no merge-base with origin/main (shallow clone?); checking uncommitted changes only."
      echo "      Set CHECK_BASE=<ref> to widen."
    fi
    changed=$({ [ -n "$base" ] && git diff --name-only "$base"; \
                git diff --name-only HEAD; \
                git ls-files --others --exclude-standard; } | sort -u \
              | while IFS= read -r f; do [ -f "$f" ] && printf '%s\n' "$f"; done)
    if [ -z "$changed" ]; then echo "no changed files — nothing to check"; exit 0; fi

    rs=$(grep -E '^(crates|services|tooling)/.*\.rs$' <<<"$changed" || true)
    # Match the SDK and collaboration Biome configs: preserve generator output verbatim.
    js=$(grep -E '^(apps/(web|marketing)|packages|services/(analytics-proxy|ai-editing-worker|lexical-service|websocket-service))/.*\.(ts|tsx)$' <<<"$changed" | grep -Ev '^packages/(sdk/generated|collaboration/src/sync-service/generated)/' || true)
    sg=$(grep -E '^(apps|crates|packages|services|tooling)/.*\.(rs|ts|tsx|plist)$' <<<"$changed" || true)

    fail=0
    if [ -n "$rs" ]; then
      echo "── cargo fmt (root workspace)"
      cargo fmt --check \
        || { echo "   fix: cargo fmt"; fail=1; }
    fi
    if [ -n "$js" ]; then
      # The SDK has its own Biome config and version. Running its files from
      # apps/web applies web formatting rules that contradict the SDK's formatter.
      # Absolute paths preserve literal path characters across both roots.
      js_paths=()
      web_paths=()
      sdk_paths=()
      while IFS= read -r f; do
        js_paths+=("$PWD/$f")
        if [[ "$f" == packages/sdk/* ]]; then
          sdk_paths+=("$PWD/$f")
        else
          web_paths+=("$PWD/$f")
        fi
      done <<<"$js"
      echo "── biome (changed JS/TS format + lint, same flags as CI)"
      if [ "${#web_paths[@]}" -gt 0 ]; then
        (\cd apps/web && bunx --bun @biomejs/biome ci --colors=off --no-errors-on-unmatched \
            --error-on-warnings "${web_paths[@]}") \
          || { echo "   fix: bun run fix, then re-check"; fail=1; }
      fi
      if [ "${#sdk_paths[@]}" -gt 0 ]; then
        if [ ! -x packages/sdk/node_modules/.bin/biome ]; then
          echo "   install SDK tooling: (\cd packages/sdk && bun install --frozen-lockfile)"
          fail=1
        else
          (\cd packages/sdk && ./node_modules/.bin/biome ci --colors=off --no-errors-on-unmatched \
              --error-on-warnings "${sdk_paths[@]}") \
            || { echo "   fix: (\cd packages/sdk && bun run format && bun run lint), then re-check"; fail=1; }
        fi
      fi
      # Only apps/web is linted --type-aware: tsgolint rejects apps/marketing's
      # tsconfig.
      ox_web_paths=()
      ox_other_paths=()
      while IFS= read -r f; do
        if [[ "$f" == apps/web/* ]]; then
          ox_web_paths+=("$PWD/$f")
        else
          ox_other_paths+=("$PWD/$f")
        fi
      done <<<"$js"
      # A generated-client-only web diff can be entirely ignored by oxlint.
      echo "── oxlint (docs/development/style-guide.md FE-12, FE-13)"
      if [ "${#ox_web_paths[@]}" -gt 0 ]; then
        (\cd apps/web && ../../node_modules/.bin/oxlint --type-aware --no-error-on-unmatched-pattern "${ox_web_paths[@]}") \
          || { echo "   fix: await, return, or .catch the promise; void only if it cannot reject (FE-13)"; fail=1; }
      fi
      if [ "${#ox_other_paths[@]}" -gt 0 ]; then
        (\cd apps/web && ../../node_modules/.bin/oxlint --no-error-on-unmatched-pattern "${ox_other_paths[@]}") || fail=1
      fi
    fi
    if grep -qx 'static_assets/schema.graphql' <<<"$changed"; then
      echo "── GraphQL schema compatibility (docs/guides/add-graphql-field.md step 8)"
      cargo x graphql-schema-compat --base "${base:-origin/main}" || fail=1
    fi
    if [ -n "$sg" ]; then
      echo "── ast-grep code rules (rule ids map to docs/development/style-guide.md)"
      bunx --yes @ast-grep/[email protected] scan --report-style=short $sg || fail=1
    fi
    echo "── PII scan (added lines vs merge-base)"
    python3 tooling/pii/scan.py --changed --skip-gitleaks || fail=1
    if grep -q '^tooling/pii/' <<<"$changed"; then
      echo "── PII scanner tests"
      ( \cd tooling/pii && python3 -m unittest test_scan.py ) || fail=1
    fi
    if [ "{{ ARGS }}" = "full" ]; then
      if [ -n "$js" ]; then
        echo "── tsc (apps/web)"
        bun run check || fail=1
      fi
      if [ -n "$rs" ]; then
        echo "── clippy (root workspace)"
        (RUSTFLAGS="-Dwarnings -Dclippy::disallowed_methods" \
            RUSTDOCFLAGS=-Dwarnings SQLX_OFFLINE=true cargo clippy --workspace --all-features \
            --exclude sync_service && \
         RUSTFLAGS="-Dwarnings -Dclippy::disallowed_methods" \
            RUSTDOCFLAGS=-Dwarnings SQLX_OFFLINE=true cargo clippy -p sync_service -- \
            -A clippy::unnecessary_map_or -A clippy::collapsible_if) || fail=1
      fi
    fi

    echo
    if [ "$fail" -ne 0 ]; then echo "FAIL"; exit 1; fi
    echo "OK"

#   just pr-privacy                                  commits since origin/main
#   PR_TITLE="fix(x): ..." just pr-privacy body.md   plus the PR title and body
#
# The same script CI's PR Privacy Check runs; the rule is the Privacy section
# of .agents/skills/git/SKILL.md.
# Scan branch commits (and a PR title and body) for personal or support details.
pr-privacy BODY="":
    @cd {{ justfile_directory() }} && PR_BODY_FILE="{{ BODY }}" \
      bash tooling/xtask/crates/xtask_workflows/src/workflows/scripts/pr_privacy_check.sh