diff-sentry 0.13.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.13.0 → diff_sentry-0.15.0}/.claude/rules/monitoring.md +4 -1
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.env.example +2 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/AGENTS.md +3 -3
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/CHANGELOG.md +21 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/PKG-INFO +3 -3
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/README.md +2 -2
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/action.yml +1 -1
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/__init__.py +1 -1
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/cli.py +26 -8
- diff_sentry-0.15.0/diff_sentry/history.py +103 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/images.py +217 -55
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/indicators.py +43 -5
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/ingest.py +94 -5
- diff_sentry-0.15.0/diff_sentry/pycheck.py +88 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/releases.py +70 -19
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/watch.py +17 -3
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/docs/limits.md +1 -1
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/docs/release-watch.md +7 -2
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/docs/watch.md +5 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/pyproject.toml +1 -1
- {diff_sentry-0.13.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.13.0 → diff_sentry-0.15.0}/tests/test_images.py +276 -10
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_releases.py +16 -1
- diff_sentry-0.15.0/tests/test_workflows.py +165 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/uv.lock +1 -1
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.claude/rules/detect-setup.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.claude/rules/handoff.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.claude/rules/indicators.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.claude/rules/rubric-and-eval.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.claude/skills/release/SKILL.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.github/workflows/ci.yml +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.github/workflows/release.yml +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.gitignore +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/.python-version +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/LICENSE +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/VENDOR.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/__main__.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/actors.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/assemble.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/config.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/dbutil.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/deep_classify.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/detect.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/emit.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/fetch_tool.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/hosts.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/linewide.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/normalize.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/npm.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/response.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/rl_export.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/rubric.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/schema.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/shelllex.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/skills/ci-and-workflows.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/skills/concealment-and-provenance.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/skills/developer-autorun.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/skills/llm-directed-text.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/skills/package-and-build-hooks.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/skills/runtime-droppers-and-exfil.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/skills/triage-a-change.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/diff_sentry/snapshot.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/docs/development.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/docs/how-it-works.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/README.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/__init__.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/__main__.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/cli.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/judge.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/schema.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/score.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/diff_sentry_eval/taskset.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/pyproject.toml +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/taskset.example.json +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/tests/conftest.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/tests/test_boundary.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/tests/test_cli.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/tests/test_judge.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/tests/test_schema.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/tests/test_score.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/eval/tests/test_taskset.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/DESIGN.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/README.md +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/__init__.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/app.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/iterations.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/live.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/diff_sentry_studio/mapper.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/pyproject.toml +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/static/app.js +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/static/index.html +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/static/replay-core.js +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/static/run-core.js +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/static/style.css +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/static/trajectory.js +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/static/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/static/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/tests/replay-core.test.js +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/tests/run-core.test.js +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/tests/static-contract.test.js +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/tests/test_app.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/tests/test_iterations.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/tests/test_live.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/tests/test_mapper.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/studio/tests/trajectory.test.js +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/__init__.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/conftest.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/corpus/change_corpus.json +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/corpus/hackerbot_claw_campaign.json +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/corpus/hackerbot_claw_incident.json +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/fixtures/known-malicious.diff +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/oracle/__init__.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/oracle/grammar.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/oracle/harness.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/oracle/lexrunner.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/oracle/programs.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/oracle/runner.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_actors.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_assemble.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_campaign_replay.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_cli.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_cli_watch.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_config.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_deep_classify.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_detect.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_detection_quality.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_dogfood_gate.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_emit.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_enclosure.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_export.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_fetch_tool.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_file_scope.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_file_structure.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_forward_offline.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_gate_edges.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_grounding.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_hosts.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_incident_hackerbot_claw.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_indicators.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_ingest.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_ingest_metadata.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_injection_offline.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_inline_exec_and_bidi.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_linewide.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_lookalike_owner.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_metadata_rules.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_normalize.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_npm.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_oracle.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_oracle_harness.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_provenance.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_python_loader.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_response.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_rubric.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_schema.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_shelllex.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_snapshot.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_subscription.py +0 -0
- {diff_sentry-0.13.0 → diff_sentry-0.15.0}/tests/test_watch.py +0 -0
- {diff_sentry-0.13.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.
|
|
@@ -63,8 +65,9 @@ paths:
|
|
|
63
65
|
|
|
64
66
|
## Image watch (`images.py`, `release-watch --images`)
|
|
65
67
|
|
|
66
|
-
- **Provenance
|
|
68
|
+
- **Provenance from the attestation.** `image_provenance` reads an image's index, each BuildKit attestation manifest and its SLSA provenance layer; `provenance_facts` keeps the source repository (`vcs:source`; `owner/name` only for a URL whose host is exactly github.com, any other source as written, so a lookalike is only judged between GitHub repositories), revision, building repository, workflow without its ref, ref and ref protection. An attestation counts only when its `vnd.docker.reference.digest` is a platform image of the same index and the provenance's `subject` names that image (BuildKit always writes one); a platform image no attestation names is a note. The layers are read separately (`layer_change`, below).
|
|
67
69
|
- **Judged against what is known, never against the last image.** A repository holds images from several workflows, so `images.known` holds the sources, the builders (repository and workflow) and the workflows seen building from protected refs: seeded at first sight from the watched floating tags and the newest `_SAMPLED_VERSIONS` version tags, and extended by every image judged clean. An image that signals never extends it, so one bad image cannot vouch for the next. On GHCR the namespace (`_namespace`) is a known owner from the start. `scan_image` grades by owner, since one organisation's repositories share a trust boundary: a source or building repository whose owner imitates a known owner is `image-source-lookalike` / `image-builder-lookalike` (critical, via `indicators.lookalike_owner`); one of an unknown owner is `image-source-changed` / `image-builder-changed` (high); another repository or workflow of a known owner is `medium` (`image-workflow-changed`, a nightly or branch build); an unprotected ref under a workflow known protected is `image-ref-unprotected` (high); an image without provenance while the repository's images carry it, a single manifest included, is `image-provenance-dropped` (high); notes are `release-not-fully-read` (high). A first-sight sample whose owners imitate each other is screened as `image-source-lookalike` (critical) and learns neither: both owners are kept as `known.suspect`, every image of the repository is `image-owner-unresolved` (high) and none is learned until the state is reset, and the suspect owners count among those an image's owner is checked for imitating (`_without_lookalikes`). The first-sight alert has a fixed run id and an `image_judgments` row, so it is sent once and re-sent when refused. An empty owner (Docker Hub has no namespace; a build outside GitHub Actions has no building repository) is never a known owner, and a first sight that read nothing and learned nothing is no baseline (retried next poll). The provenance is unsigned: a match proves nothing, only a mismatch is evidence.
|
|
68
70
|
- **What is judged**: a new tag (cosign's `sha256-<digest>.sig/.att/.sbom` skipped, newest first by the version numbers a tag starts with, at most `_MAX_NEW_TAGS` a poll), a watched floating tag that points at another digest, and one of the newest `_RECHECKED_VERSIONS` plain release tags (`_releases`: no `-nightly` or `-rc` suffix, so one version's pre-releases cannot crowd the current release out) pushed again. The first-sight sample takes the newest plain releases the same way. Digests are read with HEAD requests, which Docker Hub does not count toward its pull limit.
|
|
69
71
|
- **Registries are read anonymously and only from their own hosts**: GHCR and Docker Hub (`registry-1.docker.io`), a Bearer token asked for only from a realm on an allowed host, kept per registry and repository and asked for again on a 401 (Docker Hub's expire in minutes), a blob redirect followed only to their CDN hosts (`pkg-containers.githubusercontent.com`, Docker Hub's `production.cloudfront.docker.com` and `production.cloudflare.docker.com`); every response is bounded. A 429 (`RateLimited`) stops that image's poll and counts as no failure.
|
|
72
|
+
- **Layers by content** (`layer_change`): a judged image is compared with the image it replaces, `previous` in `judge` (a moved tag's stored digest; for a new tag, `_predecessor`: the newest release tag below it by `_version_key` whose digest is stored). Per platform (`_platforms`, attestation manifests aside; a platform the previous image lacks is a note), only the layers the two do not share are downloaded (`_MAX_LAYER_BYTES` each, `DS_RELEASE_MAX_LAYER_MB`, 1 GiB; `_MAX_LAYERS_BYTES`, 4 GiB, a comparison; each checked against its sha256 digest), and each run of layers is applied as a runtime applies it (`_filesystem`: a later layer's file replaces an earlier one's, whiteouts remove what is beneath, `_layer_path` keeps the whole path and drops `..`). The two file systems go through `releases.release_files` in the same two passes as a release (digests first, then text for what changed only), labelled `<platform>/<path>`; the files join the event and its `unread_code` and `notes` join `event["release"]`, so `scan_release` and every text rule read them. A layer that is too large, zstd (`releases._decompressed` names it), not read to its end (`_MAX_LAYER_READ`, 8 GiB decompressed) or not matching its digest is a note (`release-not-fully-read`). A `.pyc` member's digest is of its code past the 16-byte header (`pyc:` prefix), which holds the source's mtime and size and changes with every rebuild. Changed `__pycache__` bytecode whose source the artifact ships is checked against it (`releases._check_bytecode`, `pycheck.check_bytecode`, wheels too): a `python3.N -I -S` process whose magic number matches the pyc (found on `PATH`, or this interpreter) compiles the source and unmarshals the bytecode, runs neither, and compares the code objects (equality ignores the file name). The same code (line numbers included, so a pyc compiled from a shifted copy of the source alerts) is not `release-code-not-read`; other code, or no interpreter of that version here, is. The child runs under `RLIMIT_AS` (2 GiB) and `RLIMIT_CPU` (`pycheck._limits`, where the platform enforces them) and a timeout, since `marshal` is not safe against crafted data. A layer's whiteouts apply to the layers beneath before its own files (an opaque whiteout never hides what its layer adds), the first image of a platform is compared and a second is a note, attestation entries are dropped before `_MAX_PLATFORMS` applies, a member past `_MAX_MEMBER_BYTES` is hashed in chunks (`releases._large_member`) and never held whole (a Python source or bytecode up to `_MAX_CHECKED_BYTES`, 16 MiB, is kept, untexted, for the bytecode check), and a new tag with no release below it is compared with a watched floating tag's image. Each platform's config blob (`_config`, digest-checked, 4 MiB) is compared even when every layer is shared: rendered as Dockerfile lines (`_render_config`) into `<platform>/{config}` for the text rules, with a changed `_RUN_KEYS` setting as `image-run-config-changed` (high) and a `_LOADER_ENV` variable or any `LD_`/`DYLD_` one set or changed as `image-loader-env` (high), both read by `scan_image`; an unreadable config, the previous image's included, is a note, and nothing is compared unless both configs were read.
|
|
70
73
|
- **Like releases**, a comparison that fails is retried on later polls and, after five, screened as not compared (`release-not-fully-read`, which alerts); an alert the SIEM did not accept is re-sent from `screened/` a few per poll.
|
|
@@ -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
|
|
@@ -82,4 +83,5 @@ DS_API_KEY=sk-...
|
|
|
82
83
|
# DS_RELEASE_NPM=@scope/name,left-pad # release-watch: npm packages (or --npm)
|
|
83
84
|
# DS_RELEASE_SOURCES=litellm=BerriAI/litellm # release-watch: the GitHub repository each package is built from, compared by tag (or --sources)
|
|
84
85
|
# DS_RELEASE_IMAGES=ghcr.io/owner/name # release-watch: container images compared by build provenance (or --images)
|
|
86
|
+
# DS_RELEASE_MAX_LAYER_MB=1024 # release-watch: a larger image layer is not read, which alerts
|
|
85
87
|
# DS_RELEASE_IMAGE_TAGS=latest # release-watch: floating tags whose moves are judged (or --image-tags)
|
|
@@ -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 and
|
|
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`, `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
|
|
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,27 @@
|
|
|
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
|
+
|
|
14
|
+
## 0.14.0
|
|
15
|
+
|
|
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.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- **`release-watch --images` compares an image's files with the image it replaces.** A moved tag is compared with the image it pointed at, and a new tag with the newest release below it. Only the layers the two do not share are downloaded and checked against their digests, then applied as a runtime applies them, and the files that changed are screened by the same rules as a release, so a `.pth` startup hook in an image's site-packages alerts as it does in a wheel. A layer it cannot read, a new platform, and two images for one platform alert that the image was not fully read. A layer can be capped with `DS_RELEASE_MAX_LAYER_MB` (1024 by default).
|
|
20
|
+
- **An image's run configuration is compared too**, even when every layer is reused: another entrypoint, command, shell, user, working directory, healthcheck or build trigger is `image-run-config-changed` (`high`), and an environment variable that loads code (`LD_PRELOAD`, `PYTHONPATH`, `PYTHONWARNINGS`, `NODE_OPTIONS`, `PATH` and the like) is `image-loader-env` (`high`).
|
|
21
|
+
- **Compiled bytecode is checked against its source**, in images and wheels. Python can run a cached `.pyc` instead of the source beside it, so a changed `.pyc` is compared with its source compiled, in a separate, bounded interpreter of the same Python version that runs neither. Bytecode that is not its source compiled alerts.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
- **A `.pyc` is compared by its code, not its header**, which every rebuild rewrites, so a rebuilt image or wheel no longer alerts on unchanged bytecode.
|
|
25
|
+
|
|
5
26
|
## 0.13.0
|
|
6
27
|
|
|
7
28
|
Upgrade from 0.12.0: `release-watch` can watch npm packages. The GitHub Action's scan is unchanged, nothing needs configuring, and `rlm-harness==1.24.0` is unchanged.
|
|
@@ -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:
|
|
@@ -33,8 +33,7 @@ async def detect_from_event(
|
|
|
33
33
|
on_event: Callable[[dict], None] | None = None,
|
|
34
34
|
extra_tools=(),
|
|
35
35
|
):
|
|
36
|
-
"""Run the classifier on one change event and return the planner's JUDGEMENT (`ChangeVerdict`).
|
|
37
|
-
Call `assemble.assemble_verdict(verdict, events)` to attach the deterministic indicators + signal."""
|
|
36
|
+
"""Run the classifier on one change event and return the planner's JUDGEMENT (`ChangeVerdict`). Call `assemble.assemble_verdict(verdict, events)` to attach the deterministic indicators + signal."""
|
|
38
37
|
import rlm_harness
|
|
39
38
|
|
|
40
39
|
from .detect import ClassifyChange, setup
|
|
@@ -241,10 +240,11 @@ def _print_run(arts: RunArtifacts) -> None:
|
|
|
241
240
|
|
|
242
241
|
|
|
243
242
|
def _cmd_pr(args) -> int:
|
|
244
|
-
from .
|
|
243
|
+
from .history import enabled
|
|
244
|
+
from .ingest import pr_event, repo_workflows
|
|
245
245
|
|
|
246
246
|
config = DetectConfig.from_env()
|
|
247
|
-
event = pr_event(args.repo, args.number)
|
|
247
|
+
event = pr_event(args.repo, args.number, history=enabled(args.account_history), workflows=repo_workflows)
|
|
248
248
|
arts = run(event, run_id=f"{args.repo.replace('/', '-')}-pr-{args.number}", outdir=args.out,
|
|
249
249
|
config=config, emit=not args.no_emit)
|
|
250
250
|
_print_run(arts)
|
|
@@ -252,10 +252,11 @@ def _cmd_pr(args) -> int:
|
|
|
252
252
|
|
|
253
253
|
|
|
254
254
|
def _cmd_issue(args) -> int:
|
|
255
|
-
from .
|
|
255
|
+
from .history import enabled
|
|
256
|
+
from .ingest import issue_event, repo_workflows
|
|
256
257
|
|
|
257
258
|
config = DetectConfig.from_env()
|
|
258
|
-
event = issue_event(args.repo, args.number)
|
|
259
|
+
event = issue_event(args.repo, args.number, history=enabled(args.account_history), workflows=repo_workflows)
|
|
259
260
|
arts = run(event, run_id=f"{args.repo.replace('/', '-')}-issue-{args.number}", outdir=args.out,
|
|
260
261
|
config=config, emit=not args.no_emit)
|
|
261
262
|
_print_run(arts)
|
|
@@ -513,7 +514,9 @@ def _cmd_watch(args) -> int:
|
|
|
513
514
|
file=sys.stderr)
|
|
514
515
|
return 2
|
|
515
516
|
try:
|
|
516
|
-
|
|
517
|
+
from .history import enabled
|
|
518
|
+
|
|
519
|
+
watcher = Watcher(config, detect, emit=not args.no_emit, history=enabled(args.account_history))
|
|
517
520
|
except RuntimeError as exc: # a state directory written by another build
|
|
518
521
|
print(f"watch: {exc}", file=sys.stderr)
|
|
519
522
|
return 2
|
|
@@ -544,6 +547,7 @@ def _cmd_watch(args) -> int:
|
|
|
544
547
|
|
|
545
548
|
def _cmd_actor(args) -> int:
|
|
546
549
|
from .actors import ActorStore, format_dossier
|
|
550
|
+
from .history import enabled
|
|
547
551
|
from .ingest import public_activity
|
|
548
552
|
|
|
549
553
|
db = os.path.join(args.state, "actors.db")
|
|
@@ -561,13 +565,19 @@ def _cmd_actor(args) -> int:
|
|
|
561
565
|
print(f"actor: nothing recorded for {args.login!r}", file=sys.stderr)
|
|
562
566
|
return 1
|
|
563
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
|
|
564
570
|
if args.json:
|
|
565
|
-
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 {})}))
|
|
566
573
|
return 0
|
|
567
574
|
print(format_dossier(dossier))
|
|
568
575
|
if live is not None:
|
|
569
576
|
print(" live public activity (GitHub keeps ~30 days / 300 events):")
|
|
570
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'}")
|
|
571
581
|
return 0
|
|
572
582
|
finally:
|
|
573
583
|
store.close()
|
|
@@ -609,6 +619,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
609
619
|
pr.add_argument("number", type=int)
|
|
610
620
|
pr.add_argument("--out", default="./output")
|
|
611
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)")
|
|
612
624
|
pr.set_defaults(func=_cmd_pr)
|
|
613
625
|
|
|
614
626
|
iss = sub.add_parser("issue", help="classify a GitHub issue")
|
|
@@ -616,6 +628,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
616
628
|
iss.add_argument("number", type=int)
|
|
617
629
|
iss.add_argument("--out", default="./output")
|
|
618
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)")
|
|
619
633
|
iss.set_defaults(func=_cmd_issue)
|
|
620
634
|
|
|
621
635
|
cl = sub.add_parser("classify", help="classify a change payload you already hold (offline ingest)")
|
|
@@ -659,6 +673,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
659
673
|
w.add_argument("--workers", type=int, default=None,
|
|
660
674
|
help="model runs at once, each in a process of its own (DS_WATCH_WORKERS, default 1)")
|
|
661
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)")
|
|
662
678
|
w.add_argument("--once", action="store_true", help="one poll, run the queue, exit")
|
|
663
679
|
w.add_argument("--stats", action="store_true", help="print the watcher's state counts and exit (read-only)")
|
|
664
680
|
w.add_argument("--requeue-failed", action="store_true",
|
|
@@ -694,6 +710,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
694
710
|
ac.add_argument("login", help="a login, or `id:<github id>`")
|
|
695
711
|
ac.add_argument("--state", default=os.getenv("DS_WATCH_STATE_DIR", "./output/state"))
|
|
696
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)")
|
|
697
715
|
ac.add_argument("--json", action="store_true")
|
|
698
716
|
ac.set_defaults(func=_cmd_actor)
|
|
699
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
|