diff-sentry 0.14.0__tar.gz → 0.15.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.claude/rules/monitoring.md +2 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.env.example +1 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/AGENTS.md +3 -3
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/CHANGELOG.md +9 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/PKG-INFO +3 -3
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/README.md +2 -2
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/action.yml +1 -1
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/__init__.py +1 -1
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/cli.py +25 -6
- diff_sentry-0.15.0/diff_sentry/history.py +103 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/indicators.py +43 -5
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/ingest.py +94 -5
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/watch.py +17 -3
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/docs/limits.md +1 -1
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/docs/watch.md +5 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/pyproject.toml +1 -1
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_adversarial_input.py +1 -1
- diff_sentry-0.15.0/tests/test_history.py +111 -0
- diff_sentry-0.15.0/tests/test_workflows.py +165 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/uv.lock +1 -1
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.claude/rules/detect-setup.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.claude/rules/handoff.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.claude/rules/indicators.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.claude/rules/rubric-and-eval.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.claude/skills/release/SKILL.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.github/workflows/ci.yml +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.github/workflows/release.yml +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.gitignore +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/.python-version +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/LICENSE +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/VENDOR.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/__main__.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/actors.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/assemble.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/config.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/dbutil.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/deep_classify.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/detect.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/emit.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/fetch_tool.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/hosts.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/images.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/linewide.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/normalize.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/npm.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/pycheck.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/releases.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/response.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/rl_export.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/rubric.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/schema.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/shelllex.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/skills/ci-and-workflows.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/skills/concealment-and-provenance.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/skills/developer-autorun.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/skills/llm-directed-text.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/skills/package-and-build-hooks.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/skills/runtime-droppers-and-exfil.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/skills/triage-a-change.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/diff_sentry/snapshot.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/docs/development.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/docs/how-it-works.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/docs/release-watch.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/README.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/__init__.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/__main__.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/cli.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/judge.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/schema.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/score.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/taskset.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/pyproject.toml +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/taskset.example.json +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/tests/conftest.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/tests/test_boundary.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/tests/test_cli.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/tests/test_judge.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/tests/test_schema.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/tests/test_score.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/eval/tests/test_taskset.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/DESIGN.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/README.md +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/__init__.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/app.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/iterations.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/live.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/mapper.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/pyproject.toml +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/static/app.js +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/static/index.html +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/static/replay-core.js +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/static/run-core.js +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/static/style.css +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/static/trajectory.js +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/static/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/static/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/tests/replay-core.test.js +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/tests/run-core.test.js +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/tests/static-contract.test.js +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/tests/test_app.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/tests/test_iterations.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/tests/test_live.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/tests/test_mapper.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/studio/tests/trajectory.test.js +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/__init__.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/conftest.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/corpus/change_corpus.json +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/corpus/hackerbot_claw_campaign.json +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/corpus/hackerbot_claw_incident.json +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/fixtures/known-malicious.diff +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/oracle/__init__.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/oracle/grammar.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/oracle/harness.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/oracle/lexrunner.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/oracle/programs.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/oracle/runner.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_actors.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_assemble.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_campaign_replay.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_cli.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_cli_watch.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_config.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_deep_classify.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_detect.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_detection_quality.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_dogfood_gate.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_emit.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_enclosure.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_export.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_fetch_tool.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_file_scope.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_file_structure.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_forward_offline.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_gate_edges.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_grounding.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_hosts.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_images.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_incident_hackerbot_claw.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_indicators.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_ingest.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_ingest_metadata.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_injection_offline.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_inline_exec_and_bidi.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_linewide.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_lookalike_owner.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_metadata_rules.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_normalize.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_npm.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_oracle.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_oracle_harness.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_provenance.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_python_loader.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_releases.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_response.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_rubric.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_schema.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_shelllex.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_snapshot.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_subscription.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_watch.py +0 -0
- {diff_sentry-0.14.0 → diff_sentry-0.15.0}/tests/test_watch_pool.py +0 -0
|
@@ -39,6 +39,8 @@ paths:
|
|
|
39
39
|
- **Account age is measured as of the event.** `_age_days(created_at, as_of)` takes the event's own time; the wall clock is only the fallback for a payload with none. A replay of a historical incident must carry `created_at`, or every old attacker looks established (`test_campaign_replay` pins this).
|
|
40
40
|
- **Attacker-authored strings stay out of the MF1 sandwich.** Profile fields, branch names, and comments are bounded at ingest and rendered in the untrusted section only. Comments are text-scanned only when the change's author or an outsider wrote them and the commenter is not a `Bot`: maintainers quote install commands and release notes constantly.
|
|
41
41
|
- **Data minimization.** The `email` fields of a profile and of commits are reduced to a domain in the event and masked in the archive (`snapshot.scrub_emails`). Free text is archived as captured: it is evidence. Nothing prunes the archive, the store, or queued events.
|
|
42
|
+
- **The repository's workflows weigh the slash command** (`ingest.repo_workflows`, passed in as `workflows=` by `watch`, cached an hour per repository by `Watcher._repo_workflows`, and by `pr`/`issue`; ingest reads nothing without it). It lists the default branch's `.github/workflows` and reads each file as text, bounded (100 files, more is no facts; 512 KiB each): a file naming `issue_comment` or `pull_request_review_comment` starts on a comment, the quoted `/command` literals on its lines that read the comment are what it matches (`repo_comment_commands`; those of a file with no check on the commenter, `_COMMENTER_GATE_RE`, also in `repo_comment_commands_open`: `author_association`, `github.actor`, the sender or commenter login, a collaborator, member or membership lookup, or a call to a reusable workflow or a local action whose checks are not read), and one with none, or with a `/literal` on a line that does not read the comment (a dispatcher such as `case "$CMD" in "/deploy")`), counts as answering any comment (`repo_comment_workflows_unfiltered`), so no command steps down for it; a `pull_request_target` file that checks out the PR's own code (`ref:` to its head, its merge commit or a pull ref, `repository:` the head repo, `gh pr checkout`, `git checkout`/`switch` to it or to `FETCH_HEAD`; a `git fetch` that only reads the head is not) goes in `repo_prt_head_checkout`. A 404 listing is a fact (no workflows); any other failure, or one file unread or oversized, is no facts, so `scan_metadata` keeps its plain reading. With the facts, a command anyone can run is one step up (author within an hour: `high`, else `medium`), a matched command behind a commenter check keeps the plain reading, and with no comment workflow or no match and no open handler one step down (`low` / `info`). Only GitHub Actions is read: a command an app or outside CI answers is unseen, a sub-floor loss at worst. `scan_provenance` raises `prt-runs-fork-code` (medium) for an outsider's PR when `repo_prt_head_checkout` is non-empty.
|
|
43
|
+
- **Account history is opt-in** (`history.py`): `history.enabled(flag)` is None unless `--account-history` or `DS_ACCOUNT_HISTORY=clickhouse`, because it sends a login to a third party (ClickHouse's public playground, GH Archive's `github_events`). `ingest._provenance` asks it only for a `User` (not `ghost`) and only when a caller passed it in (`watch`, `pr`, `issue`; `actor` prints it), so tests and `scan` never reach the network. The query is parameterised (`{login:String}`, the login checked against GitHub's login shape first) and read as of the event (`param_as_of`, `param_cut` 30 days before it), so a replay sees what was true then. It records `author_history_events_before`, `_repos_before`, `_first_event` and `_last_before_days`; zero events is a fact, a failed query or an answer it cannot read no facts. GH Archive keys events by the login they were made under, so history whose first event is older than the account (`author_account_created_at`) belongs to an earlier holder of the login: it is dropped and `author_history_other_account` recorded instead; a renamed account's events under its old login are not found (a false sub-floor hit at worst). `scan_provenance` reads them: `dormant-account-reactivated` (medium, `_last_before_days` of a year or more, evidence in whole years so a re-ingest keeps the id) and `no-public-history` (low, no events before the window from an account 180 days old or more). The lookup caches each login per day.
|
|
42
44
|
- **Adding a fact:** capture it in `ingest.py` (best-effort: a failed call omits the key, unless the value feeds the digest, in which case mark the event incomplete instead of reporting "none"), put it in `provenance` (or a bounded event field), read it in `scan_provenance` / `scan_metadata` with a negative case, and keep it sub-floor unless it is standalone evidence. Replay the incident corpus.
|
|
43
45
|
- **Read-only means read-only.** `--stats` and `actor` open the state `mode=ro` (`open_versioned(read_only=True)`) and neither create, stamp, nor requeue anything. Only `serve` and `--once` call `recover()`, under the lock.
|
|
44
46
|
- **Terminal output is sanitized.** `format_dossier` replaces control characters; `_json_out` escapes the C1 range `json.dumps` leaves raw; URL and token parsing cut at the first control character. A string an attacker wrote must not be able to drive the operator's terminal.
|
|
@@ -68,6 +68,7 @@ DS_API_KEY=sk-...
|
|
|
68
68
|
# Time is the only cost with a local model, so the caps are OFF unless set.
|
|
69
69
|
# DS_WATCH_REPOS=owner/name,other/name # or --repos / --repos-file
|
|
70
70
|
# DS_WATCH_STATE_DIR=./output/state # watch.db, actors.db, snapshots/
|
|
71
|
+
# DS_ACCOUNT_HISTORY=clickhouse # watch/pr/issue/actor: look up authors' public history in GH Archive via ClickHouse's public playground (sends the login there; off by default)
|
|
71
72
|
# DS_WATCH_INTERVAL=60 # seconds between polls (raised if GitHub sends X-Poll-Interval)
|
|
72
73
|
# DS_WATCH_BACKFILL_HOURS=0 # on first sight of a repo, also examine changes this recent
|
|
73
74
|
# DS_WATCH_RECHECK_HOURS=24 # shorten the re-check schedule (15 min, 1 h, 6 h, 24 h); it cannot extend it
|
|
@@ -31,10 +31,10 @@ rlm-harness is an exact PyPI pin (`rlm-harness==X.Y.Z` in `pyproject.toml`, lock
|
|
|
31
31
|
- **The budget is hard: `max_retries=1`, no whole-RLM retry inside a run.** One change = one trajectory, so the trace stays valid training data. (`watch` may run a change again, but only when the previous attempt produced no result at all, an infrastructure failure; `cli.run` resets that run id's trace first, so exactly one trajectory per run id survives.) A failed run is infra before it is a schema bug; see `.claude/rules/detect-setup.md` for how the failure names itself.
|
|
32
32
|
- **A second model-judgement is a TOOL, never the sub-LM.** `deep_classify` (on rlm-harness's `make_model_tool`) is the swappable second-stage seam the planner chooses to call, so the decision is a `tool_call` in the trajectory. The analyst intercept (`intercept_sub_lm`) is tracing-only, zero transforms. Swapping the backend touches only `classify_backend` / `_selfclassify_chat`. The planner passes distilled findings, never the whole diff.
|
|
33
33
|
- **Sandboxed code builds no sub-agents.** In dspy 3.4.1 and later, sandboxed code can construct dspy programs that run on the host, call the analyst, can drive the task's tools, and record as one `sub_call` with no inner turns. The kit's default allows it, so `setup` passes `sandbox_sub_agents=False` explicitly, and production never injects an interpreter (which would bypass it); `test_program_offers_no_sub_agents` holds the behaviour.
|
|
34
|
-
- **GitHub ingest, monitoring, and SIEM emission are host-side plumbing, never planner tools.** `ingest.py` shells out to `gh` host-side (transport injectable); `emit.emit_signal` POSTs and never raises; `watch`, `actors` and `snapshot` poll, remember, and archive outside the trajectory, `releases` and `npm` read PyPI's and npm's own hosts, and the refs and trees of a package's GitHub repository, as data that is never installed, and `images` reads the GHCR and Docker Hub APIs only (manifests, provenance, and the layers two images do not share, as data in memory, never unpacked or run). `pycheck` compiles a release's Python source and unmarshals its bytecode in a separate interpreter to compare them, and runs neither. Only choices the policy makes are tools; delivering a finished result is plumbing. What the store learns reaches the signal only as provenance facts through `scan_provenance`, never as a second derivation (see `.claude/rules/monitoring.md`).
|
|
34
|
+
- **GitHub ingest, monitoring, and SIEM emission are host-side plumbing, never planner tools.** `ingest.py` shells out to `gh` host-side (transport injectable); `emit.emit_signal` POSTs and never raises; `watch`, `actors` and `snapshot` poll, remember, and archive outside the trajectory, `history` (opt-in, off by default: it sends a login to ClickHouse's public playground) reads an author's GH Archive history, `releases` and `npm` read PyPI's and npm's own hosts, and the refs and trees of a package's GitHub repository, as data that is never installed, and `images` reads the GHCR and Docker Hub APIs only (manifests, provenance, and the layers two images do not share, as data in memory, never unpacked or run). `pycheck` compiles a release's Python source and unmarshals its bytecode in a separate interpreter to compare them, and runs neither. Only choices the policy makes are tools; delivering a finished result is plumbing. What the store learns reaches the signal only as provenance facts through `scan_provenance`, never as a second derivation (see `.claude/rules/monitoring.md`).
|
|
35
35
|
- **This is a ROLLOUT source: trajectories, not reward.** `rl_export` passes `reward=None`; labels read the assembled verdict and metrics are objective effort counters. `deep_classify` tool_calls train the classifier; every other action is the planner's. A metric keeps ONE meaning across rlm-harness versions (the corpus mixes them; `run_start.payload.rlm_harness` names the writer): a quantity a newer kit makes observable gets a NEW key that is None where the trace cannot say (e.g. `analyst_failures`). The ATLAS rubric and the eval member stay reward-free too; see `.claude/rules/rubric-and-eval.md`.
|
|
36
36
|
- **Attack knowledge lives in `diff_sentry/skills/`, not the prompt.** The skill catalog is injected (`load_skills_as_tools(discovery="inject")`) and `read_skill(name)` pulls a body on demand. Fix a wrong convention by editing or adding a skill; `detect.INSTRUCTIONS` holds only identity, the MISSION frame, the tool cost model, the triage loop, and output-gating rules. Skills ship via `packages = ["diff_sentry"]`; a force-include duplicates them and breaks the build.
|
|
37
|
-
- **Keep the dspy-free modules dspy-free.** `config`, `schema`, `normalize`, `indicators`, `shelllex`, `linewide`, `assemble`, `response`, `emit`, `ingest`, `hosts`, `dbutil`, `actors`, `snapshot`, `watch`, `releases`, `npm`, `images`, `pycheck`, `rl_export`, and `rubric` must not import dspy at module top, and `import diff_sentry` must not import dspy (`ClassifyChange` / `setup` / `run` / `screen` / `detect_from_event` are lazy PEP 562 re-exports).
|
|
37
|
+
- **Keep the dspy-free modules dspy-free.** `config`, `schema`, `normalize`, `indicators`, `shelllex`, `linewide`, `assemble`, `response`, `emit`, `ingest`, `hosts`, `dbutil`, `actors`, `snapshot`, `watch`, `history`, `releases`, `npm`, `images`, `pycheck`, `rl_export`, and `rubric` must not import dspy at module top, and `import diff_sentry` must not import dspy (`ClassifyChange` / `setup` / `run` / `screen` / `detect_from_event` are lazy PEP 562 re-exports).
|
|
38
38
|
- **The trace self-describes the run.** `run_start` meta carries the normalized event, instructions, source echo, `baseline_indicators`, `emit_on`, role→model names, budgets, and the rubric skeleton, so an offline re-render/export re-derives the same `signal` (reading `emit_on` from meta, never current config). Any new per-run config that affects read-time derivation must ride in meta.
|
|
39
39
|
|
|
40
40
|
## Topic guides
|
|
@@ -54,5 +54,5 @@ Claude Code loads each rule automatically when you touch a matching file; other
|
|
|
54
54
|
|
|
55
55
|
- rlm-harness owns the generic cores: `make_model_tool` (chat → retry → validate → circuit-break) under `deep_classify`, and the SSRF primitives (`is_safe_url`, `resolved_host_is_safe`, `parse_cidrs`) under `fetch_tool`, which adds the GitHub allowlist, the httpx provider, and tracing.
|
|
56
56
|
- When this consumer needs a workaround, fix the reusable gap in rlm-harness generically; never special-case diff-sentry there. Consumer values (`DS_*` roles, the verdict schema, indicator rules, the SIEM payload shape) stay here.
|
|
57
|
-
- The deterministic tier ships as `cli.screen`, `watch` and `release-watch` (host-side, in front of `cli.run`). Next increments: an optional small single-shot model call inside that tier
|
|
57
|
+
- The deterministic tier ships as `cli.screen`, `watch` and `release-watch` (host-side, in front of `cli.run`). Next increments: an optional small single-shot model call inside that tier.
|
|
58
58
|
- Two workspace members, never in the `diff_sentry` wheel: `studio/` (`diff-sentry-studio`, the detection console, behind its `live` extra) and `eval/` (`diff-sentry-eval`, the reward-free scorecard). Both read the trace / `DetectionResponse` contract through the public surface only. Keep the root wheel at `packages = ["diff_sentry"]` so `uv build` never sweeps them in.
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to diff-sentry, a BewAIre-style detector that classifies one GitHub change (PR, issue or push) for malicious intent on [`rlm-harness`](https://github.com/qazbnm456/rlm-harness).
|
|
4
4
|
|
|
5
|
+
## 0.15.0
|
|
6
|
+
|
|
7
|
+
Upgrade from 0.14.0: `watch` weighs slash commands by the target repository's own workflows, and can look up an author's older public history if you turn that on. The GitHub Action's scan is unchanged, nothing needs configuring, and `rlm-harness==1.24.0` is unchanged.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **A slash command is weighed by what the repository's own workflows answer.** `watch`, `pr` and `issue` read the target repository's `.github/workflows` (its default branch, once an hour). A command that a workflow runs for anyone who comments goes one step up, to `high` when the change's author fires it within an hour of opening it, the hackerbot-claw shape. A command only some commenters can run keeps its usual weight, and one no workflow answers goes one step down. Only GitHub Actions workflows are read.
|
|
11
|
+
- **`prt-runs-fork-code`** (`medium`): an outsider's pull request into a repository whose `pull_request_target` workflow checks out the pull request's own code, which then runs with the repository's secrets.
|
|
12
|
+
- **An opt-in account history from GH Archive.** With `--account-history` (or `DS_ACCOUNT_HISTORY=clickhouse`), `watch`, `pr`, `issue` and `actor` look up an author's public events from before GitHub's 30-day window, as of the event, through ClickHouse's public playground. An account that wakes after a year without public activity is `dormant-account-reactivated` (`medium`), and an account older than 180 days with no earlier public activity is `no-public-history` (`low`); neither raises an alert on its own. The lookup is off by default because it sends the author's login to a third party, and `scan` and the GitHub Action never use it. See [Watching a watchlist](docs/watch.md).
|
|
13
|
+
|
|
5
14
|
## 0.14.0
|
|
6
15
|
|
|
7
16
|
Upgrade from 0.13.0: `release-watch --images` now reads what each image changes, and checks compiled bytecode against its source. The GitHub Action's scan is unchanged, and `rlm-harness==1.24.0` is unchanged. For the bytecode check, install the Python version an image or wheel uses (`python3.N` on `PATH`) beside the watcher; without it, changed bytecode alerts that it could not be checked.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: diff-sentry
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.0
|
|
4
4
|
Summary: Catch malicious pull requests before they merge: scan a diff for supply-chain attack patterns with deterministic evidence a model cannot suppress.
|
|
5
5
|
Author: Boik Su
|
|
6
6
|
License-Expression: MIT
|
|
@@ -43,7 +43,7 @@ jobs:
|
|
|
43
43
|
- uses: actions/checkout@v7
|
|
44
44
|
with:
|
|
45
45
|
fetch-depth: 0 # the scan diffs against the PR base
|
|
46
|
-
- uses: qazbnm456/diff-sentry@v0.
|
|
46
|
+
- uses: qazbnm456/diff-sentry@v0.15.0
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
That is the whole setup. The job fails when an indicator at or above `high` fires. Add `push` to `on:` to also scan commits pushed straight to a branch. A push that bypasses branch protection can also delete this workflow, so `watch` and `release-watch` read the repository and its releases from outside.
|
|
@@ -58,7 +58,7 @@ That is the whole setup. The job fails when an indicator at or above `high` fire
|
|
|
58
58
|
| Exfiltration | secrets reaching a network sink, cross-process `/proc/<pid>/mem` reads, OAST callback services, IPFS and permaweb gateways |
|
|
59
59
|
| Diff-presentation evasion | payloads shoved past the viewport by a long whitespace run, bidi-override and zero-width characters |
|
|
60
60
|
| Provenance | forged `[bot]` identities, bot-mimicking new accounts, accounts created days before the event, profiles that describe an autonomous agent, unsigned or identity-mismatched commits, a fork deleted after the PR |
|
|
61
|
-
| Author-controlled channels | a PR branch name carrying shell syntax, slash-command comments that fire `issue_comment` workflows |
|
|
61
|
+
| Author-controlled channels | a PR branch name carrying shell syntax, slash-command comments that fire `issue_comment` workflows (weighed by what the repository's own workflows answer) |
|
|
62
62
|
| Campaign memory (`watch` only) | an account or payload host already flagged in another repository, an edit that removes a flagged payload, a burst of changes from a new account |
|
|
63
63
|
| Prompt injection | instructions aimed at an LLM reviewer or triage workflow |
|
|
64
64
|
|
|
@@ -21,7 +21,7 @@ jobs:
|
|
|
21
21
|
- uses: actions/checkout@v7
|
|
22
22
|
with:
|
|
23
23
|
fetch-depth: 0 # the scan diffs against the PR base
|
|
24
|
-
- uses: qazbnm456/diff-sentry@v0.
|
|
24
|
+
- uses: qazbnm456/diff-sentry@v0.15.0
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
That is the whole setup. The job fails when an indicator at or above `high` fires. Add `push` to `on:` to also scan commits pushed straight to a branch. A push that bypasses branch protection can also delete this workflow, so `watch` and `release-watch` read the repository and its releases from outside.
|
|
@@ -36,7 +36,7 @@ That is the whole setup. The job fails when an indicator at or above `high` fire
|
|
|
36
36
|
| Exfiltration | secrets reaching a network sink, cross-process `/proc/<pid>/mem` reads, OAST callback services, IPFS and permaweb gateways |
|
|
37
37
|
| Diff-presentation evasion | payloads shoved past the viewport by a long whitespace run, bidi-override and zero-width characters |
|
|
38
38
|
| Provenance | forged `[bot]` identities, bot-mimicking new accounts, accounts created days before the event, profiles that describe an autonomous agent, unsigned or identity-mismatched commits, a fork deleted after the PR |
|
|
39
|
-
| Author-controlled channels | a PR branch name carrying shell syntax, slash-command comments that fire `issue_comment` workflows |
|
|
39
|
+
| Author-controlled channels | a PR branch name carrying shell syntax, slash-command comments that fire `issue_comment` workflows (weighed by what the repository's own workflows answer) |
|
|
40
40
|
| Campaign memory (`watch` only) | an account or payload host already flagged in another repository, an edit that removes a flagged payload, a burst of changes from a new account |
|
|
41
41
|
| Prompt injection | instructions aimed at an LLM reviewer or triage workflow |
|
|
42
42
|
|
|
@@ -40,7 +40,7 @@ inputs:
|
|
|
40
40
|
that PR rather than by the ones already on main.
|
|
41
41
|
required: false
|
|
42
42
|
# KEEP IN STEP WITH [project].version. release.yml fails the build if this drifts from the tag being released, because a stale default here would silently run an old scanner under a new action tag.
|
|
43
|
-
default: '0.
|
|
43
|
+
default: '0.15.0'
|
|
44
44
|
|
|
45
45
|
outputs:
|
|
46
46
|
failed:
|
|
@@ -240,10 +240,11 @@ def _print_run(arts: RunArtifacts) -> None:
|
|
|
240
240
|
|
|
241
241
|
|
|
242
242
|
def _cmd_pr(args) -> int:
|
|
243
|
-
from .
|
|
243
|
+
from .history import enabled
|
|
244
|
+
from .ingest import pr_event, repo_workflows
|
|
244
245
|
|
|
245
246
|
config = DetectConfig.from_env()
|
|
246
|
-
event = pr_event(args.repo, args.number)
|
|
247
|
+
event = pr_event(args.repo, args.number, history=enabled(args.account_history), workflows=repo_workflows)
|
|
247
248
|
arts = run(event, run_id=f"{args.repo.replace('/', '-')}-pr-{args.number}", outdir=args.out,
|
|
248
249
|
config=config, emit=not args.no_emit)
|
|
249
250
|
_print_run(arts)
|
|
@@ -251,10 +252,11 @@ def _cmd_pr(args) -> int:
|
|
|
251
252
|
|
|
252
253
|
|
|
253
254
|
def _cmd_issue(args) -> int:
|
|
254
|
-
from .
|
|
255
|
+
from .history import enabled
|
|
256
|
+
from .ingest import issue_event, repo_workflows
|
|
255
257
|
|
|
256
258
|
config = DetectConfig.from_env()
|
|
257
|
-
event = issue_event(args.repo, args.number)
|
|
259
|
+
event = issue_event(args.repo, args.number, history=enabled(args.account_history), workflows=repo_workflows)
|
|
258
260
|
arts = run(event, run_id=f"{args.repo.replace('/', '-')}-issue-{args.number}", outdir=args.out,
|
|
259
261
|
config=config, emit=not args.no_emit)
|
|
260
262
|
_print_run(arts)
|
|
@@ -512,7 +514,9 @@ def _cmd_watch(args) -> int:
|
|
|
512
514
|
file=sys.stderr)
|
|
513
515
|
return 2
|
|
514
516
|
try:
|
|
515
|
-
|
|
517
|
+
from .history import enabled
|
|
518
|
+
|
|
519
|
+
watcher = Watcher(config, detect, emit=not args.no_emit, history=enabled(args.account_history))
|
|
516
520
|
except RuntimeError as exc: # a state directory written by another build
|
|
517
521
|
print(f"watch: {exc}", file=sys.stderr)
|
|
518
522
|
return 2
|
|
@@ -543,6 +547,7 @@ def _cmd_watch(args) -> int:
|
|
|
543
547
|
|
|
544
548
|
def _cmd_actor(args) -> int:
|
|
545
549
|
from .actors import ActorStore, format_dossier
|
|
550
|
+
from .history import enabled
|
|
546
551
|
from .ingest import public_activity
|
|
547
552
|
|
|
548
553
|
db = os.path.join(args.state, "actors.db")
|
|
@@ -560,13 +565,19 @@ def _cmd_actor(args) -> int:
|
|
|
560
565
|
print(f"actor: nothing recorded for {args.login!r}", file=sys.stderr)
|
|
561
566
|
return 1
|
|
562
567
|
live = public_activity(dossier["login"]) if args.live else None
|
|
568
|
+
lookup = enabled(args.account_history)
|
|
569
|
+
past = lookup(dossier["login"]) if lookup is not None else None
|
|
563
570
|
if args.json:
|
|
564
|
-
print(_json_out({**dossier, **({"live_public_activity": live} if live is not None else {})
|
|
571
|
+
print(_json_out({**dossier, **({"live_public_activity": live} if live is not None else {}),
|
|
572
|
+
**({"account_history": past} if past is not None else {})}))
|
|
565
573
|
return 0
|
|
566
574
|
print(format_dossier(dossier))
|
|
567
575
|
if live is not None:
|
|
568
576
|
print(" live public activity (GitHub keeps ~30 days / 300 events):")
|
|
569
577
|
print(f" {json.dumps(live, ensure_ascii=False) if live else 'unavailable'}")
|
|
578
|
+
if past is not None:
|
|
579
|
+
print(" public history before the last 30 days (GH Archive, via ClickHouse):")
|
|
580
|
+
print(f" {json.dumps(past, ensure_ascii=False) if past else 'none, or unavailable'}")
|
|
570
581
|
return 0
|
|
571
582
|
finally:
|
|
572
583
|
store.close()
|
|
@@ -608,6 +619,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
608
619
|
pr.add_argument("number", type=int)
|
|
609
620
|
pr.add_argument("--out", default="./output")
|
|
610
621
|
pr.add_argument("--no-emit", action="store_true", help="do not emit a SIEM signal")
|
|
622
|
+
pr.add_argument("--account-history", action="store_true",
|
|
623
|
+
help="look up the author's public history before the last 30 days in GH Archive, via ClickHouse's public playground (sends the login there; or set DS_ACCOUNT_HISTORY=clickhouse; off by default)")
|
|
611
624
|
pr.set_defaults(func=_cmd_pr)
|
|
612
625
|
|
|
613
626
|
iss = sub.add_parser("issue", help="classify a GitHub issue")
|
|
@@ -615,6 +628,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
615
628
|
iss.add_argument("number", type=int)
|
|
616
629
|
iss.add_argument("--out", default="./output")
|
|
617
630
|
iss.add_argument("--no-emit", action="store_true", help="do not emit a SIEM signal")
|
|
631
|
+
iss.add_argument("--account-history", action="store_true",
|
|
632
|
+
help="look up the author's public history before the last 30 days in GH Archive, via ClickHouse's public playground (sends the login there; or set DS_ACCOUNT_HISTORY=clickhouse; off by default)")
|
|
618
633
|
iss.set_defaults(func=_cmd_issue)
|
|
619
634
|
|
|
620
635
|
cl = sub.add_parser("classify", help="classify a change payload you already hold (offline ingest)")
|
|
@@ -658,6 +673,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
658
673
|
w.add_argument("--workers", type=int, default=None,
|
|
659
674
|
help="model runs at once, each in a process of its own (DS_WATCH_WORKERS, default 1)")
|
|
660
675
|
w.add_argument("--no-emit", action="store_true", help="do not emit SIEM signals")
|
|
676
|
+
w.add_argument("--account-history", action="store_true",
|
|
677
|
+
help="look up the author's public history before the last 30 days in GH Archive, via ClickHouse's public playground (sends the login there; or set DS_ACCOUNT_HISTORY=clickhouse; off by default)")
|
|
661
678
|
w.add_argument("--once", action="store_true", help="one poll, run the queue, exit")
|
|
662
679
|
w.add_argument("--stats", action="store_true", help="print the watcher's state counts and exit (read-only)")
|
|
663
680
|
w.add_argument("--requeue-failed", action="store_true",
|
|
@@ -693,6 +710,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
693
710
|
ac.add_argument("login", help="a login, or `id:<github id>`")
|
|
694
711
|
ac.add_argument("--state", default=os.getenv("DS_WATCH_STATE_DIR", "./output/state"))
|
|
695
712
|
ac.add_argument("--live", action="store_true", help="also fetch the account's recent public activity")
|
|
713
|
+
ac.add_argument("--account-history", action="store_true",
|
|
714
|
+
help="also look up the account's public history before the last 30 days in GH Archive, via ClickHouse's public playground (sends the login there; or set DS_ACCOUNT_HISTORY=clickhouse; off by default)")
|
|
696
715
|
ac.add_argument("--json", action="store_true")
|
|
697
716
|
ac.set_defaults(func=_cmd_actor)
|
|
698
717
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""An account's public history before the GitHub Events API's 30 days, from GH Archive as ClickHouse serves it publicly.
|
|
2
|
+
|
|
3
|
+
GitHub's Events API keeps an account's last 30 days, so it cannot tell an account that has been active for years from one that slept for years and woke up last week, the shape a taken-over account has. GH Archive holds every public event since 2011, and ClickHouse serves it as the `github_events` table on its public playground (`play.clickhouse.com`, user `play`, no key), queried by `actor_login`. Only a login and a time go out: the account is public, and so is what we watch.
|
|
4
|
+
|
|
5
|
+
Off by default: it sends a login to a third party, so an operator turns it on (`DS_ACCOUNT_HISTORY=clickhouse`, or `--account-history` on `watch`, `pr`, `issue` and `actor`), and `scan` and the GitHub Action never reach it. Host-side plumbing like `ingest`: never a planner tool, best-effort (an empty dict on any failure), the query parameterised (`{login:String}`, never formatted into the SQL), the response bounded. Pure stdlib + httpx; no dspy.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import logging
|
|
12
|
+
import re
|
|
13
|
+
from collections.abc import Callable
|
|
14
|
+
from datetime import UTC, datetime, timedelta
|
|
15
|
+
from urllib.parse import urlencode
|
|
16
|
+
|
|
17
|
+
log = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
_ENDPOINT = "https://play.clickhouse.com/"
|
|
20
|
+
_LOGIN_RE = re.compile(r"[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})")
|
|
21
|
+
_WINDOW_DAYS = 30 # what the Events API already shows; history is what came before it
|
|
22
|
+
_MAX_RESPONSE_BYTES = 1 << 20
|
|
23
|
+
_QUERY = """
|
|
24
|
+
SELECT count() AS events,
|
|
25
|
+
min(created_at) AS first_event,
|
|
26
|
+
countIf(created_at < {cut:DateTime}) AS events_before,
|
|
27
|
+
maxIf(created_at, created_at < {cut:DateTime}) AS last_before,
|
|
28
|
+
uniqExactIf(repo_name, created_at < {cut:DateTime}) AS repos_before
|
|
29
|
+
FROM github_events
|
|
30
|
+
WHERE actor_login = {login:String} AND created_at <= {as_of:DateTime}
|
|
31
|
+
FORMAT JSONEachRow
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# A post maps (url, body, byte limit) to (status, body). Injectable, so tests need no network.
|
|
35
|
+
Post = Callable[[str, bytes, int], tuple[int, bytes]]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _httpx_post(timeout: float = 10.0) -> Post:
|
|
39
|
+
def post(url: str, body: bytes, limit: int) -> tuple[int, bytes]:
|
|
40
|
+
import httpx
|
|
41
|
+
|
|
42
|
+
if not url.startswith(_ENDPOINT):
|
|
43
|
+
raise ValueError("only ClickHouse's public playground is queried")
|
|
44
|
+
with httpx.stream("POST", url, content=body, timeout=timeout, follow_redirects=False) as resp:
|
|
45
|
+
data = bytearray()
|
|
46
|
+
for chunk in resp.iter_bytes():
|
|
47
|
+
data += chunk
|
|
48
|
+
if len(data) > limit:
|
|
49
|
+
raise ValueError("the response is larger than its bound")
|
|
50
|
+
return resp.status_code, bytes(data)
|
|
51
|
+
|
|
52
|
+
return post
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _stamp(dt: datetime) -> str:
|
|
56
|
+
return dt.astimezone(UTC).strftime("%Y-%m-%d %H:%M:%S")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def account_history(login: str, as_of: datetime | None = None, *, post: Post | None = None) -> dict:
|
|
60
|
+
"""The account's public events up to `as_of` (the event's own time, so a replay sees what was true then): how many there were before the last `_WINDOW_DAYS`, in how many repositories, the first, and how many days before `as_of` the last of them was. `{}` when the login is not a GitHub login or the query fails; no event at all is zero events, not `{}`."""
|
|
61
|
+
if not _LOGIN_RE.fullmatch(login or ""):
|
|
62
|
+
return {}
|
|
63
|
+
as_of = (as_of or datetime.now(UTC)).astimezone(UTC)
|
|
64
|
+
params = {"user": "play", "param_login": login, "param_as_of": _stamp(as_of),
|
|
65
|
+
"param_cut": _stamp(as_of - timedelta(days=_WINDOW_DAYS))}
|
|
66
|
+
try:
|
|
67
|
+
status, body = (post or _httpx_post())(f"{_ENDPOINT}?{urlencode(params)}", _QUERY.encode(), _MAX_RESPONSE_BYTES)
|
|
68
|
+
if status != 200:
|
|
69
|
+
raise ValueError(f"HTTP {status}")
|
|
70
|
+
row = json.loads(body.decode("utf-8").splitlines()[0])
|
|
71
|
+
if not int(row.get("events") or 0): # none at all, as far as GH Archive has indexed: a fact, not a failure
|
|
72
|
+
return {"events_before": 0, "repos_before": 0}
|
|
73
|
+
out = {"events_before": int(row.get("events_before") or 0), "repos_before": int(row.get("repos_before") or 0),
|
|
74
|
+
"first_event": str(row.get("first_event") or "")}
|
|
75
|
+
if out["events_before"]:
|
|
76
|
+
last = datetime.fromisoformat(str(row["last_before"])).replace(tzinfo=UTC)
|
|
77
|
+
out["last_before_days"] = (as_of - last).days
|
|
78
|
+
return out
|
|
79
|
+
except Exception as exc: # noqa: BLE001 (best-effort: a failed lookup or an answer it cannot read omits the facts)
|
|
80
|
+
log.warning("account history %s: %s", login, str(exc)[:200])
|
|
81
|
+
return {}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
_MAX_CACHED = 4096
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def enabled(flag: bool = False) -> Callable[[str, datetime | None], dict] | None:
|
|
88
|
+
"""The account-history lookup when the operator turned it on (`flag`, or `DS_ACCOUNT_HISTORY=clickhouse`), else None. The lookup remembers each account's answer for the day it was asked about, so a watch that sees one author many times asks once."""
|
|
89
|
+
import os
|
|
90
|
+
|
|
91
|
+
if not flag and os.getenv("DS_ACCOUNT_HISTORY", "").strip().lower() != "clickhouse":
|
|
92
|
+
return None
|
|
93
|
+
seen: dict[tuple[str, str], dict] = {}
|
|
94
|
+
|
|
95
|
+
def lookup(login: str, as_of: datetime | None = None) -> dict:
|
|
96
|
+
key = (login.lower(), (as_of or datetime.now(UTC)).date().isoformat())
|
|
97
|
+
if key not in seen:
|
|
98
|
+
if len(seen) >= _MAX_CACHED:
|
|
99
|
+
seen.clear()
|
|
100
|
+
seen[key] = account_history(login, as_of)
|
|
101
|
+
return seen[key]
|
|
102
|
+
|
|
103
|
+
return lookup
|
|
@@ -3040,6 +3040,12 @@ def scan_metadata(event: dict) -> list[IndicatorHit]:
|
|
|
3040
3040
|
author = str(event.get("author") or "").strip().lower()
|
|
3041
3041
|
opened = _ts(event.get("created_at"))
|
|
3042
3042
|
seen: set[str] = set()
|
|
3043
|
+
prov = event.get("provenance") or {}
|
|
3044
|
+
# what the repository's own workflows run on (`ingest.repo_workflows`), when it was read: a command no workflow can answer is one step down, one a workflow matches one step up
|
|
3045
|
+
known = prov.get("repo_workflows_read") is True
|
|
3046
|
+
handled = {str(c).lower() for c in prov.get("repo_comment_commands") or []}
|
|
3047
|
+
open_to_all = {str(c).lower() for c in prov.get("repo_comment_commands_open") or []} # no check on who commented
|
|
3048
|
+
open_handler = bool(prov.get("repo_comment_workflows_unfiltered"))
|
|
3043
3049
|
for c in _comments(event):
|
|
3044
3050
|
if not is_scanned_comment(c, author):
|
|
3045
3051
|
continue
|
|
@@ -3052,12 +3058,22 @@ def scan_metadata(event: dict) -> list[IndicatorHit]:
|
|
|
3052
3058
|
when = _ts(c["created_at"])
|
|
3053
3059
|
quick = (bool(author) and who == author and opened is not None and when is not None
|
|
3054
3060
|
and 0 <= (when - opened).total_seconds() <= _SLASH_SELF_WINDOW_S)
|
|
3061
|
+
if known and cmd in open_to_all:
|
|
3062
|
+
severity, reach = ("high" if quick else "medium"), f"; a workflow of the repository runs /{cmd} for anyone"
|
|
3063
|
+
elif known and cmd in handled: # matched, but the workflow checks who commented: the plain reading
|
|
3064
|
+
severity, reach = ("medium" if quick else "low"), f"; a workflow of the repository matches /{cmd} for some commenters"
|
|
3065
|
+
elif known and not open_handler:
|
|
3066
|
+
severity = "low" if quick else "info"
|
|
3067
|
+
reach = ("; no workflow of the repository starts on a comment" if not prov.get("repo_comment_workflows")
|
|
3068
|
+
else f"; no workflow of the repository matches /{cmd}")
|
|
3069
|
+
else:
|
|
3070
|
+
severity, reach = ("medium" if quick else "low"), ""
|
|
3055
3071
|
hits.append(_hit(
|
|
3056
|
-
"slash-command-trigger",
|
|
3057
|
-
"a slash command from the change's author or an outsider (fires `issue_comment` workflows)"
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3072
|
+
"slash-command-trigger", severity,
|
|
3073
|
+
("a slash command from the change's author or an outsider (fires `issue_comment` workflows)"
|
|
3074
|
+
if not quick else
|
|
3075
|
+
"the change's author fires a slash command within an hour of opening it "
|
|
3076
|
+
"(the `issue_comment` workflow trigger)") + reach,
|
|
3061
3077
|
f"/{cmd} by {c['author'][:40]}", # no association: it can change and would re-mint the id
|
|
3062
3078
|
location=f"comment:{c['author'][:40]}").model_copy(update={"via": c["author"]}))
|
|
3063
3079
|
return hits
|
|
@@ -3538,6 +3554,8 @@ _BOT_BASES = ("dependabot", "renovate", "github-actions", "mergify", "snyk", "gr
|
|
|
3538
3554
|
_OUTSIDER_ASSOCIATIONS = OUTSIDER_ASSOCIATIONS
|
|
3539
3555
|
_YOUNG_ACCOUNT_DAYS = 30 # younger than this is a weak newness tell (sub-floor)
|
|
3540
3556
|
_NEW_ACCOUNT_DAYS = 14 # hackerbot-claw struck 7 days after its account was created; margin for a longer wait
|
|
3557
|
+
_DORMANT_DAYS = 365 # a year without public activity, then this change
|
|
3558
|
+
_SLEEPER_DAYS = 180 # an account this old with no public activity before the last 30 days
|
|
3541
3559
|
# Thresholds for the actor-correlation facts the watcher derives from its store (see `actors.correlate`).
|
|
3542
3560
|
_BURST_PER_HOUR = 10 # AsyncAPI took 37 PRs from one account in a day
|
|
3543
3561
|
_MULTI_REPO_24H = 3
|
|
@@ -3692,6 +3710,26 @@ def scan_provenance(provenance: dict) -> list[IndicatorHit]:
|
|
|
3692
3710
|
f"the author account was created less than {_NEW_ACCOUNT_DAYS} days before the event",
|
|
3693
3711
|
f"age<{_NEW_ACCOUNT_DAYS}d created={created or 'n/a'} login={login[:80]}"))
|
|
3694
3712
|
|
|
3713
|
+
# A pull request from an outsider into a repository whose `pull_request_target` workflow checks out the PR's own code: that code runs with the repository's secrets and write token (the "pwn request" shape hackerbot-claw looked for). A fact about the repository, so a corroborator.
|
|
3714
|
+
prt = [str(x) for x in prov.get("repo_prt_head_checkout") or []]
|
|
3715
|
+
if prt and outsider and prov.get("head_sha"):
|
|
3716
|
+
hits.append(_hit("prt-runs-fork-code", "medium",
|
|
3717
|
+
"an outsider's PR into a repository whose pull_request_target workflow checks out the PR's own code",
|
|
3718
|
+
", ".join(sorted(prt))[:_MAX_EVIDENCE]))
|
|
3719
|
+
|
|
3720
|
+
# GH Archive history (`history.account_history`, opt-in): what the account did publicly before the Events API's 30 days, as of the event. A taken-over account is an old one that wakes up; a sleeper is an old one that never did anything in public. Both are common enough to stay sub-floor corroborators.
|
|
3721
|
+
last_before = prov.get("author_history_last_before_days")
|
|
3722
|
+
if is_user and isinstance(last_before, int) and not isinstance(last_before, bool) and last_before >= _DORMANT_DAYS:
|
|
3723
|
+
hits.append(_hit("dormant-account-reactivated", "medium",
|
|
3724
|
+
"the author's last public activity before the past 30 days was more than a year before the event "
|
|
3725
|
+
"(a dormant account active again, as a taken-over one is)",
|
|
3726
|
+
f"dormant>={last_before // 365}y login={login[:80]}")) # whole years: a re-ingest keeps the id
|
|
3727
|
+
if (is_user and prov.get("author_history_events_before") == 0 and isinstance(age, int) and not isinstance(age, bool)
|
|
3728
|
+
and age >= _SLEEPER_DAYS):
|
|
3729
|
+
hits.append(_hit("no-public-history", "low",
|
|
3730
|
+
f"an account older than {_SLEEPER_DAYS} days with no public activity before the past 30 days",
|
|
3731
|
+
f"age>={_SLEEPER_DAYS}d login={login[:80]}"))
|
|
3732
|
+
|
|
3695
3733
|
if prov.get("head_repo_deleted") is True:
|
|
3696
3734
|
hits.append(_hit("head-repo-deleted", "medium",
|
|
3697
3735
|
"the fork the PR came from was deleted after it was opened (the author removed the "
|
|
@@ -9,6 +9,7 @@ Pure stdlib; no dspy. `event_from_payload` is the offline path (a payload you al
|
|
|
9
9
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
|
+
import base64
|
|
12
13
|
import json
|
|
13
14
|
import re
|
|
14
15
|
from collections.abc import Callable
|
|
@@ -18,6 +19,10 @@ from typing import Any
|
|
|
18
19
|
|
|
19
20
|
# An `api` maps a `gh api <path>` argument to parsed JSON. Injectable for tests; default uses `gh`.
|
|
20
21
|
GhApi = Callable[[str], Any]
|
|
22
|
+
# An account-history lookup (`history.account_history`): (login, the event's time) to facts. Off unless a caller passes one.
|
|
23
|
+
History = Callable[[str, "datetime | None"], dict]
|
|
24
|
+
# The repository's workflow facts (`repo_workflows`, or a cache of it): (repo, the API) to facts. Off unless a caller passes one.
|
|
25
|
+
Workflows = Callable[[str, "GhApi"], dict]
|
|
21
26
|
# A `raw` maps (path, Accept media type) to the response TEXT, for the one surface that is not JSON: the `.patch` mbox, whose `Date:` headers keep the author's UTC offset (REST and GraphQL normalize it away).
|
|
22
27
|
GhRaw = Callable[[str, str], str]
|
|
23
28
|
|
|
@@ -170,7 +175,7 @@ def _mbox_offsets(text: str, limit: int = 100) -> dict[str, int]:
|
|
|
170
175
|
|
|
171
176
|
def _provenance(repo: str, number: int | None, user: dict | None, association: Any,
|
|
172
177
|
call: GhApi, *, fetch_commits: bool, as_of: Any = None,
|
|
173
|
-
raw: GhRaw | None = None) -> dict:
|
|
178
|
+
raw: GhRaw | None = None, history: History | None = None) -> dict:
|
|
174
179
|
"""Best-effort HOST-SIDE source/provenance facts for a change: author identity/association, the account's absolute `created_at` and its age as of the event, profile facts, and (PRs) commit signature counts, commit dates and UTC offsets, from `gh api`. Every enrichment call is guarded: a `gh` hiccup or a missing field just OMITS that key, never sinks the ingest. The `indicators.scan_provenance` detectors turn these into deterministic hits at baseline."""
|
|
175
180
|
user = user if isinstance(user, dict) else {}
|
|
176
181
|
login = str(user.get("login", "") or "")
|
|
@@ -197,6 +202,15 @@ def _provenance(repo: str, number: int | None, user: dict | None, association: A
|
|
|
197
202
|
prov["author_not_found"] = True # POSITIVE 404 → a fact
|
|
198
203
|
except Exception: # noqa: BLE001,S110 (transient failure: omit, never sink the ingest)
|
|
199
204
|
pass
|
|
205
|
+
if history is not None and login and prov["author_type"] == "User" and login.strip().lower() != "ghost":
|
|
206
|
+
# the account's public history before the Events API's 30 days (GH Archive), as of the event; best-effort
|
|
207
|
+
past = history(login, _parse_ts(as_of))
|
|
208
|
+
first, created = _parse_ts(str(past.get("first_event") or "").replace(" ", "T")), _parse_ts(prov.get("author_account_created_at"))
|
|
209
|
+
if first is not None and created is not None and first < created:
|
|
210
|
+
prov["author_history_other_account"] = True # events under this login before the account existed: another account's, not read
|
|
211
|
+
else:
|
|
212
|
+
for key, value in past.items():
|
|
213
|
+
prov[f"author_history_{key}"] = value
|
|
200
214
|
if fetch_commits and number is not None:
|
|
201
215
|
try:
|
|
202
216
|
commits = call(f"repos/{repo}/pulls/{number}/commits?per_page=100")
|
|
@@ -405,7 +419,8 @@ def event_from_payload(payload: dict) -> dict:
|
|
|
405
419
|
return out
|
|
406
420
|
|
|
407
421
|
|
|
408
|
-
def pr_event(repo: str, number: int, *, api: GhApi | None = None, raw: GhRaw | None = None
|
|
422
|
+
def pr_event(repo: str, number: int, *, api: GhApi | None = None, raw: GhRaw | None = None,
|
|
423
|
+
history: History | None = None, workflows: Workflows | None = None) -> dict:
|
|
409
424
|
"""Fetch a PR + its files, comments and provenance from GitHub (host-side) into a change-event dict.
|
|
410
425
|
|
|
411
426
|
`api` is injectable. The `.patch` fetch (commit UTC offsets) runs only on the real `gh` transport or an explicitly injected `raw`, so a test that fakes `api` never reaches the network."""
|
|
@@ -415,9 +430,11 @@ def pr_event(repo: str, number: int, *, api: GhApi | None = None, raw: GhRaw | N
|
|
|
415
430
|
files = _pages(call, f"repos/{repo}/pulls/{number}/files", _MAX_FILE_PAGES)
|
|
416
431
|
timeline = _timeline(pr)
|
|
417
432
|
prov = _provenance(repo, number, pr.get("user"), pr.get("author_association"),
|
|
418
|
-
call, fetch_commits=True, as_of=timeline.get("event_created_at"), raw=raw_call)
|
|
433
|
+
call, fetch_commits=True, as_of=timeline.get("event_created_at"), raw=raw_call, history=history)
|
|
419
434
|
prov.update(timeline)
|
|
420
435
|
prov.update(_head_facts(pr))
|
|
436
|
+
if workflows is not None:
|
|
437
|
+
prov.update(workflows(repo, call))
|
|
421
438
|
changed = pr.get("changed_files")
|
|
422
439
|
if isinstance(changed, int) and not isinstance(changed, bool):
|
|
423
440
|
prov["changed_files"] = changed
|
|
@@ -454,14 +471,17 @@ def pr_event(repo: str, number: int, *, api: GhApi | None = None, raw: GhRaw | N
|
|
|
454
471
|
return event
|
|
455
472
|
|
|
456
473
|
|
|
457
|
-
def issue_event(repo: str, number: int, *, api: GhApi | None = None
|
|
474
|
+
def issue_event(repo: str, number: int, *, api: GhApi | None = None, history: History | None = None,
|
|
475
|
+
workflows: Workflows | None = None) -> dict:
|
|
458
476
|
"""Fetch an issue from GitHub (host-side) into a change-event dict; the issue body is the untrusted content (the hackerbot-claw prompt-injection issues came in this shape)."""
|
|
459
477
|
call = api or _gh_cli_api()
|
|
460
478
|
issue = call(f"repos/{repo}/issues/{number}")
|
|
461
479
|
timeline = _timeline(issue)
|
|
462
480
|
prov = _provenance(repo, number, issue.get("user"), issue.get("author_association"),
|
|
463
|
-
call, fetch_commits=False, as_of=timeline.get("event_created_at"))
|
|
481
|
+
call, fetch_commits=False, as_of=timeline.get("event_created_at"), history=history)
|
|
464
482
|
prov.update(timeline)
|
|
483
|
+
if workflows is not None:
|
|
484
|
+
prov.update(workflows(repo, call))
|
|
465
485
|
event = {
|
|
466
486
|
"repo": repo,
|
|
467
487
|
"kind": "issue",
|
|
@@ -485,6 +505,75 @@ def issue_event(repo: str, number: int, *, api: GhApi | None = None) -> dict:
|
|
|
485
505
|
return event
|
|
486
506
|
|
|
487
507
|
|
|
508
|
+
# ── the repository's own workflows ───────────────────────────────────────────────────────────────────────
|
|
509
|
+
|
|
510
|
+
_MAX_WORKFLOWS = 100
|
|
511
|
+
_MAX_WORKFLOW_BYTES = 512 << 10
|
|
512
|
+
# a workflow a comment starts: an issue comment (PRs included) or a review comment
|
|
513
|
+
_COMMENT_TRIGGER_RE = re.compile(r"(?<![\w-])(?:issue_comment|pull_request_review_comment)(?![\w-])")
|
|
514
|
+
_PRT_TRIGGER_RE = re.compile(r"(?<![\w-])pull_request_target(?![\w-])")
|
|
515
|
+
# the PR's own code checked out into the workspace: `actions/checkout` with `ref:` its head or its pull ref, `gh pr checkout`, or `git checkout`/`switch` to it (a `git fetch` that only reads the head, to diff it, is not)
|
|
516
|
+
_PR_HEAD = (r"(?:github\.event\.pull_request\.(?:head\.(?:sha|ref)|merge_commit_sha)|github\.head_ref"
|
|
517
|
+
r"|refs/pull/|pull/[^\s'\"]{0,80}/(?:head|merge)|FETCH_HEAD)")
|
|
518
|
+
_HEAD_CHECKOUT_RE = re.compile(rf"\bref:[^\n]{{0,200}}{_PR_HEAD}|\brepository:[^\n]{{0,200}}github\.event\.pull_request\.head\.repo"
|
|
519
|
+
rf"|\bgh[ \t]+pr[ \t]+checkout\b|\bgit[ \t]+(?:checkout|switch)\b[^\n]{{0,200}}{_PR_HEAD}")
|
|
520
|
+
# a slash command a workflow matches: a quoted literal on a line that reads the comment (`contains(github.event.comment.body, '/format')`, `case "$COMMENT" in "/format"`)
|
|
521
|
+
_WORKFLOW_COMMAND_RE = re.compile(r"""['"]/([a-z][a-z0-9_-]{1,30})(?![a-z0-9_/-])""", re.IGNORECASE)
|
|
522
|
+
_READS_COMMENT_RE = re.compile(r"comment|body", re.IGNORECASE)
|
|
523
|
+
# a workflow that checks who commented before it acts, or hands the comment to a reusable workflow whose checks are not read here
|
|
524
|
+
_COMMENTER_GATE_RE = re.compile(r"author_association|getCollaboratorPermissionLevel|/collaborators/|/members/|/memberships/"
|
|
525
|
+
r"|github\.(?:actor|triggering_actor)\b|event\.sender\.login|event\.comment\.user\.login"
|
|
526
|
+
r"|\buses:[ \t]*[^\n]{0,200}\.github/(?:workflows|actions)/", re.IGNORECASE)
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
def repo_workflows(repo: str, call: GhApi) -> dict:
|
|
530
|
+
"""What the repository's own workflows (its default branch's `.github/workflows`) run on: how many a comment starts, the slash commands they match as quoted literals, how many match none (a handler of any comment, or one that filters some other way), and which `pull_request_target` workflows check out the PR's own code. Read as text: a token in a comment or a string counts too, which can only make a comment look more able to start a workflow. Best-effort: `{}` when the listing cannot be read, so the slash-command rule keeps its plain reading."""
|
|
531
|
+
try:
|
|
532
|
+
listing = call(f"repos/{repo}/contents/.github/workflows")
|
|
533
|
+
except GhApiError as e:
|
|
534
|
+
return {"repo_workflows_read": True, "repo_comment_workflows": 0} if e.status == 404 else {}
|
|
535
|
+
except Exception: # noqa: BLE001 (best-effort)
|
|
536
|
+
return {}
|
|
537
|
+
if not isinstance(listing, list):
|
|
538
|
+
return {}
|
|
539
|
+
files = [f for f in listing if isinstance(f, dict) and f.get("type") == "file"
|
|
540
|
+
and str(f.get("name") or "").endswith((".yml", ".yaml"))]
|
|
541
|
+
if len(files) > _MAX_WORKFLOWS:
|
|
542
|
+
return {} # not read whole: the rule keeps its plain reading
|
|
543
|
+
comment_files, unfiltered, prt = 0, 0, []
|
|
544
|
+
commands: set[str] = set()
|
|
545
|
+
open_commands: set[str] = set()
|
|
546
|
+
for f in files:
|
|
547
|
+
name = _clip(f.get("path"), 200)
|
|
548
|
+
if int(f.get("size") or 0) > _MAX_WORKFLOW_BYTES:
|
|
549
|
+
return {} # not read whole: the rule keeps its plain reading
|
|
550
|
+
try:
|
|
551
|
+
body = call(f"repos/{repo}/contents/{name}")
|
|
552
|
+
text = base64.b64decode(str(body.get("content") or "")).decode("utf-8", "replace")
|
|
553
|
+
except Exception: # noqa: BLE001 (one workflow unread: the facts are not whole, so none)
|
|
554
|
+
return {}
|
|
555
|
+
if _COMMENT_TRIGGER_RE.search(text):
|
|
556
|
+
comment_files += 1
|
|
557
|
+
found: set[str] = set()
|
|
558
|
+
elsewhere = False # a literal on a line that does not read the comment: a dispatcher (`case "$CMD" in "/deploy")`) or a path
|
|
559
|
+
for line in text.splitlines():
|
|
560
|
+
literals = {m.group(1).lower() for m in _WORKFLOW_COMMAND_RE.finditer(line)}
|
|
561
|
+
if _READS_COMMENT_RE.search(line):
|
|
562
|
+
found |= literals
|
|
563
|
+
elif literals:
|
|
564
|
+
elsewhere = True
|
|
565
|
+
commands |= found
|
|
566
|
+
if not _COMMENTER_GATE_RE.search(text):
|
|
567
|
+
open_commands |= found # anyone who comments can run these
|
|
568
|
+
unfiltered += not found or elsewhere # it may answer commands not read here: no step down
|
|
569
|
+
if _PRT_TRIGGER_RE.search(text) and _HEAD_CHECKOUT_RE.search(text):
|
|
570
|
+
prt.append(name)
|
|
571
|
+
return {"repo_workflows_read": True, "repo_comment_workflows": comment_files,
|
|
572
|
+
"repo_comment_commands": sorted(commands)[:100], "repo_comment_commands_open": sorted(open_commands)[:100],
|
|
573
|
+
"repo_comment_workflows_unfiltered": unfiltered,
|
|
574
|
+
"repo_prt_head_checkout": prt[:20]}
|
|
575
|
+
|
|
576
|
+
|
|
488
577
|
def public_activity(login: str, *, api: GhApi | None = None, pages: int = 3) -> dict:
|
|
489
578
|
"""A bounded summary of an account's recent PUBLIC activity (GitHub keeps the last 30 days / 300 events): distinct repos, event types, and the UTC hour-of-day histogram. GitHub assigns the timestamps, so the histogram is the timezone evidence to lean on, though the author still chooses when to act (commit-date offsets are only a claim). Best-effort: an empty dict on any failure."""
|
|
490
579
|
if not re.fullmatch(r"[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})", login or ""):
|