n24q02m-telegram 4.23.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.
Files changed (135) hide show
  1. n24q02m_telegram-4.23.0/.claude-plugin/plugin.json +33 -0
  2. n24q02m_telegram-4.23.0/.coderabbit.yaml +23 -0
  3. n24q02m_telegram-4.23.0/.dockerignore +40 -0
  4. n24q02m_telegram-4.23.0/.editorconfig +28 -0
  5. n24q02m_telegram-4.23.0/.gitattributes +31 -0
  6. n24q02m_telegram-4.23.0/.gitguardian.yaml +16 -0
  7. n24q02m_telegram-4.23.0/.github/CODEOWNERS +2 -0
  8. n24q02m_telegram-4.23.0/.github/ISSUE_TEMPLATE/bug_report.md +34 -0
  9. n24q02m_telegram-4.23.0/.github/ISSUE_TEMPLATE/feature_request.md +19 -0
  10. n24q02m_telegram-4.23.0/.github/PULL_REQUEST_TEMPLATE.md +25 -0
  11. n24q02m_telegram-4.23.0/.github/repo-settings.json +22 -0
  12. n24q02m_telegram-4.23.0/.github/review-learnings.md +14 -0
  13. n24q02m_telegram-4.23.0/.github/rulesets/main.json +63 -0
  14. n24q02m_telegram-4.23.0/.github/workflows/bot-governance.yml +116 -0
  15. n24q02m_telegram-4.23.0/.github/workflows/cd.yml +438 -0
  16. n24q02m_telegram-4.23.0/.github/workflows/ci.yml +188 -0
  17. n24q02m_telegram-4.23.0/.gitignore +93 -0
  18. n24q02m_telegram-4.23.0/.gitleaksignore +6 -0
  19. n24q02m_telegram-4.23.0/.infisical.json +5 -0
  20. n24q02m_telegram-4.23.0/.mise.toml +51 -0
  21. n24q02m_telegram-4.23.0/.pre-commit-config.yaml +121 -0
  22. n24q02m_telegram-4.23.0/.python-version +1 -0
  23. n24q02m_telegram-4.23.0/.skret.yaml +8 -0
  24. n24q02m_telegram-4.23.0/AGENTS.md +154 -0
  25. n24q02m_telegram-4.23.0/CHANGELOG.md +3321 -0
  26. n24q02m_telegram-4.23.0/CLAUDE.md +169 -0
  27. n24q02m_telegram-4.23.0/CODE_OF_CONDUCT.md +46 -0
  28. n24q02m_telegram-4.23.0/CONTRIBUTING.md +21 -0
  29. n24q02m_telegram-4.23.0/Dockerfile +83 -0
  30. n24q02m_telegram-4.23.0/LICENSE +201 -0
  31. n24q02m_telegram-4.23.0/PKG-INFO +332 -0
  32. n24q02m_telegram-4.23.0/PRIVACY.md +29 -0
  33. n24q02m_telegram-4.23.0/README.md +299 -0
  34. n24q02m_telegram-4.23.0/SECURITY.md +15 -0
  35. n24q02m_telegram-4.23.0/coverage_output.txt +24 -0
  36. n24q02m_telegram-4.23.0/docker-compose.http.yml +14 -0
  37. n24q02m_telegram-4.23.0/docker-compose.yml +13 -0
  38. n24q02m_telegram-4.23.0/docs/HANDOVER.md +61 -0
  39. n24q02m_telegram-4.23.0/form_screenshot.png +0 -0
  40. n24q02m_telegram-4.23.0/glama.json +4 -0
  41. n24q02m_telegram-4.23.0/pyproject.toml +117 -0
  42. n24q02m_telegram-4.23.0/renovate.json +176 -0
  43. n24q02m_telegram-4.23.0/scripts/clean-venv.mjs +112 -0
  44. n24q02m_telegram-4.23.0/scripts/enforce-commit.sh +8 -0
  45. n24q02m_telegram-4.23.0/scripts/preserve-diacritics.py +293 -0
  46. n24q02m_telegram-4.23.0/scripts/repo-bootstrap/_lib.py +555 -0
  47. n24q02m_telegram-4.23.0/scripts/repo-bootstrap/verify_readme_sync.py +539 -0
  48. n24q02m_telegram-4.23.0/scripts/test_preserve_diacritics.py +184 -0
  49. n24q02m_telegram-4.23.0/semantic-release.toml +11 -0
  50. n24q02m_telegram-4.23.0/server.json +62 -0
  51. n24q02m_telegram-4.23.0/skills/channel-post/SKILL.md +79 -0
  52. n24q02m_telegram-4.23.0/skills/setup-bot/SKILL.md +68 -0
  53. n24q02m_telegram-4.23.0/smithery.yaml +12 -0
  54. n24q02m_telegram-4.23.0/src/telegram/__init__.py +10 -0
  55. n24q02m_telegram-4.23.0/src/telegram/__main__.py +16 -0
  56. n24q02m_telegram-4.23.0/src/telegram/auth/__init__.py +1 -0
  57. n24q02m_telegram-4.23.0/src/telegram/auth/telegram_auth_provider.py +157 -0
  58. n24q02m_telegram-4.23.0/src/telegram/backends/__init__.py +3 -0
  59. n24q02m_telegram-4.23.0/src/telegram/backends/base.py +156 -0
  60. n24q02m_telegram-4.23.0/src/telegram/backends/bot_backend.py +400 -0
  61. n24q02m_telegram-4.23.0/src/telegram/backends/security.py +284 -0
  62. n24q02m_telegram-4.23.0/src/telegram/backends/user_backend.py +657 -0
  63. n24q02m_telegram-4.23.0/src/telegram/cli.py +400 -0
  64. n24q02m_telegram-4.23.0/src/telegram/config.py +261 -0
  65. n24q02m_telegram-4.23.0/src/telegram/credential_state.py +150 -0
  66. n24q02m_telegram-4.23.0/src/telegram/docs/chats.md +50 -0
  67. n24q02m_telegram-4.23.0/src/telegram/docs/contacts.md +24 -0
  68. n24q02m_telegram-4.23.0/src/telegram/docs/media.md +35 -0
  69. n24q02m_telegram-4.23.0/src/telegram/docs/messages.md +53 -0
  70. n24q02m_telegram-4.23.0/src/telegram/errors.py +64 -0
  71. n24q02m_telegram-4.23.0/src/telegram/resources.py +33 -0
  72. n24q02m_telegram-4.23.0/src/telegram/security.py +114 -0
  73. n24q02m_telegram-4.23.0/src/telegram/server.py +600 -0
  74. n24q02m_telegram-4.23.0/src/telegram/sessions.py +34 -0
  75. n24q02m_telegram-4.23.0/src/telegram/tools/__init__.py +15 -0
  76. n24q02m_telegram-4.23.0/src/telegram/tools/chats.py +161 -0
  77. n24q02m_telegram-4.23.0/src/telegram/tools/config_tool.py +98 -0
  78. n24q02m_telegram-4.23.0/src/telegram/tools/contacts.py +68 -0
  79. n24q02m_telegram-4.23.0/src/telegram/tools/help_tool.py +59 -0
  80. n24q02m_telegram-4.23.0/src/telegram/tools/media.py +79 -0
  81. n24q02m_telegram-4.23.0/src/telegram/tools/messages.py +142 -0
  82. n24q02m_telegram-4.23.0/src/telegram/transports/__init__.py +1 -0
  83. n24q02m_telegram-4.23.0/src/telegram/transports/http.py +62 -0
  84. n24q02m_telegram-4.23.0/src/telegram/utils/__init__.py +0 -0
  85. n24q02m_telegram-4.23.0/src/telegram/utils/formatting.py +19 -0
  86. n24q02m_telegram-4.23.0/tests/__init__.py +0 -0
  87. n24q02m_telegram-4.23.0/tests/conftest.py +243 -0
  88. n24q02m_telegram-4.23.0/tests/conftest_e2e.py +33 -0
  89. n24q02m_telegram-4.23.0/tests/fixtures/tools_expected.json +625 -0
  90. n24q02m_telegram-4.23.0/tests/integration/__init__.py +0 -0
  91. n24q02m_telegram-4.23.0/tests/integration/test_bot_live.py +280 -0
  92. n24q02m_telegram-4.23.0/tests/integration/test_user_live.py +239 -0
  93. n24q02m_telegram-4.23.0/tests/legacy_store.py +45 -0
  94. n24q02m_telegram-4.23.0/tests/stdio_bootstrap.py +91 -0
  95. n24q02m_telegram-4.23.0/tests/structured.py +39 -0
  96. n24q02m_telegram-4.23.0/tests/test_backends/__init__.py +0 -0
  97. n24q02m_telegram-4.23.0/tests/test_backends/test_base.py +25 -0
  98. n24q02m_telegram-4.23.0/tests/test_backends/test_bot_backend.py +698 -0
  99. n24q02m_telegram-4.23.0/tests/test_backends/test_security.py +524 -0
  100. n24q02m_telegram-4.23.0/tests/test_backends/test_ssrf_whitespace.py +38 -0
  101. n24q02m_telegram-4.23.0/tests/test_backends/test_user_backend.py +1854 -0
  102. n24q02m_telegram-4.23.0/tests/test_backends/test_user_backend_string_session.py +89 -0
  103. n24q02m_telegram-4.23.0/tests/test_benchmark_io.py +53 -0
  104. n24q02m_telegram-4.23.0/tests/test_cli.py +348 -0
  105. n24q02m_telegram-4.23.0/tests/test_config.py +199 -0
  106. n24q02m_telegram-4.23.0/tests/test_config_status_storage.py +95 -0
  107. n24q02m_telegram-4.23.0/tests/test_credential_state.py +240 -0
  108. n24q02m_telegram-4.23.0/tests/test_data_dir_migration.py +211 -0
  109. n24q02m_telegram-4.23.0/tests/test_e2e.py +397 -0
  110. n24q02m_telegram-4.23.0/tests/test_errors_and_sessions.py +295 -0
  111. n24q02m_telegram-4.23.0/tests/test_full_live.py +737 -0
  112. n24q02m_telegram-4.23.0/tests/test_home_isolation_guard.py +90 -0
  113. n24q02m_telegram-4.23.0/tests/test_live_protocol.py +173 -0
  114. n24q02m_telegram-4.23.0/tests/test_main.py +19 -0
  115. n24q02m_telegram-4.23.0/tests/test_not_ready_response.py +46 -0
  116. n24q02m_telegram-4.23.0/tests/test_resources.py +75 -0
  117. n24q02m_telegram-4.23.0/tests/test_security.py +260 -0
  118. n24q02m_telegram-4.23.0/tests/test_server.py +791 -0
  119. n24q02m_telegram-4.23.0/tests/test_server_metadata.py +16 -0
  120. n24q02m_telegram-4.23.0/tests/test_startup_warnings.py +23 -0
  121. n24q02m_telegram-4.23.0/tests/test_stdio_direct.py +92 -0
  122. n24q02m_telegram-4.23.0/tests/test_telegram_auth_provider.py +276 -0
  123. n24q02m_telegram-4.23.0/tests/test_tool_parity.py +93 -0
  124. n24q02m_telegram-4.23.0/tests/test_tools/__init__.py +0 -0
  125. n24q02m_telegram-4.23.0/tests/test_tools/test_chats.py +257 -0
  126. n24q02m_telegram-4.23.0/tests/test_tools/test_config_tool.py +157 -0
  127. n24q02m_telegram-4.23.0/tests/test_tools/test_contacts.py +144 -0
  128. n24q02m_telegram-4.23.0/tests/test_tools/test_help_tool.py +126 -0
  129. n24q02m_telegram-4.23.0/tests/test_tools/test_media.py +303 -0
  130. n24q02m_telegram-4.23.0/tests/test_tools/test_messages.py +210 -0
  131. n24q02m_telegram-4.23.0/tests/test_transports/__init__.py +0 -0
  132. n24q02m_telegram-4.23.0/tests/test_transports/test_http.py +273 -0
  133. n24q02m_telegram-4.23.0/tests/test_utils/__init__.py +0 -0
  134. n24q02m_telegram-4.23.0/tests/test_utils/test_formatting.py +134 -0
  135. n24q02m_telegram-4.23.0/uv.lock +1353 -0
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "telegram",
3
+ "description": "Telegram dual-mode (Bot API + MTProto) — messages, chats, media, contacts",
4
+ "version": "4.23.0",
5
+ "userConfig": {
6
+ "TELEGRAM_BOT_TOKEN": {
7
+ "type": "string",
8
+ "title": "Bot token (bot mode)",
9
+ "description": "From @BotFather. Required for stdio bot mode. Leave empty for user mode (HTTP only).",
10
+ "sensitive": true,
11
+ "required": false
12
+ }
13
+ },
14
+ "author": {
15
+ "name": "n24q02m",
16
+ "url": "https://github.com/n24q02m"
17
+ },
18
+ "homepage": "https://github.com/n24q02m/telegram",
19
+ "mcpServers": {
20
+ "telegram": {
21
+ "command": "uvx",
22
+ "args": [
23
+ "--python",
24
+ "3.13",
25
+ "n24q02m-telegram@latest"
26
+ ],
27
+ "env": {
28
+ "MCP_TRANSPORT": "stdio",
29
+ "TELEGRAM_BOT_TOKEN": "${user_config.TELEGRAM_BOT_TOKEN}"
30
+ }
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,23 @@
1
+ language: "en-US"
2
+ reviews:
3
+ auto_review:
4
+ enabled: true
5
+ drafts: false
6
+ ignore_usernames:
7
+ - "n24q02m"
8
+ - "dependabot[bot]"
9
+ - "renovate[bot]"
10
+ - "github-actions[bot]"
11
+ - "devin-ai-integration[bot]"
12
+ - "google-labs-jules[bot]"
13
+ profile: "chill"
14
+ request_changes_workflow: false
15
+ high_level_summary: true
16
+ auto_incremental_review: true
17
+ issue_enrichment:
18
+ auto_enrich:
19
+ enabled: true
20
+ planning:
21
+ enabled: true
22
+ chat:
23
+ auto_reply: false
@@ -0,0 +1,40 @@
1
+ # Git
2
+ .git
3
+ .github
4
+
5
+ # IDE
6
+ .vscode
7
+
8
+ # Cache
9
+ .ruff_cache
10
+ .pytest_cache
11
+ __pycache__
12
+
13
+ # Development
14
+ tests/
15
+ temp/
16
+ docs/
17
+ *.md
18
+ !README.md
19
+
20
+ # Docker
21
+ Dockerfile
22
+ docker-compose.yml
23
+
24
+ # Secrets
25
+ .env
26
+ .env.*
27
+ .skret.yaml
28
+
29
+ # Config
30
+ .pre-commit-config.yaml
31
+ .editorconfig
32
+ .mise.toml
33
+ .python-version
34
+ .release-please-manifest*.json
35
+ release-please-config*.json
36
+ CODE_OF_CONDUCT.md
37
+ CONTRIBUTING.md
38
+ SECURITY.md
39
+ LICENSE
40
+ CHANGELOG.md
@@ -0,0 +1,28 @@
1
+ # Editor configuration
2
+ # https://editorconfig.org
3
+
4
+ root = true
5
+
6
+ [*]
7
+ charset = utf-8
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ trim_trailing_whitespace = true
11
+ indent_style = space
12
+ indent_size = 4
13
+
14
+ [*.py]
15
+ indent_size = 4
16
+
17
+ [*.{json,yml,yaml,toml}]
18
+ indent_size = 2
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
22
+ max_line_length = off
23
+
24
+ [Makefile]
25
+ indent_style = tab
26
+
27
+ [Dockerfile]
28
+ indent_size = 4
@@ -0,0 +1,31 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
3
+
4
+ # Python
5
+ *.py text diff=python
6
+ *.pyx text diff=python
7
+ *.pxd text diff=python
8
+
9
+ # Binary
10
+ *.png binary
11
+ *.jpg binary
12
+ *.jpeg binary
13
+ *.gif binary
14
+ *.ico binary
15
+ *.gz binary
16
+ *.tar binary
17
+ *.zip binary
18
+ *.whl binary
19
+
20
+ # Configs
21
+ *.json text
22
+ *.toml text
23
+ *.yaml text
24
+ *.yml text
25
+ *.md text
26
+ *.txt text
27
+ *.cfg text
28
+ *.ini text
29
+
30
+ # Docker
31
+ Dockerfile text
@@ -0,0 +1,16 @@
1
+ # Public-by-design app identifiers -- reviewed and deliberately kept.
2
+ # Telegram's api_id/api_hash pair embedded in src/telegram/config.py
3
+ # is the official embedded-app-credential pattern (my.telegram.org "App
4
+ # configuration" -- every client using the Telegram API, official or third
5
+ # party, ships an api_id/api_hash baked into the app). Scanner alerts on this
6
+ # exact value are a false positive. Do NOT rotate, do NOT placeholder-ize.
7
+ #
8
+ # Note: api_id (37984984) is a bare integer with no distinguishing format, so
9
+ # it is not expected to trip any secret detector and is intentionally left
10
+ # out of ignored_matches below -- add it here if a scanner ever actually
11
+ # flags it.
12
+ version: 2
13
+ secret:
14
+ ignored_matches:
15
+ - name: telegram-embedded-app-api-hash
16
+ match: "2f5f4c76c4de7c07302380c788390100"
@@ -0,0 +1,2 @@
1
+ # Default code owner — required reviewer for all PRs
2
+ * @n24q02m
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+ ---
8
+
9
+ **Describe the bug**
10
+ A clear and concise description of what the bug is.
11
+
12
+ **To Reproduce**
13
+ Steps to reproduce the behavior:
14
+
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Environment (please complete the following information):**
27
+
28
+ - OS: [e.g. macOS, Linux, Windows]
29
+ - Go version: [output of `go version`]
30
+ - telegram version: [output of `telegram --version`]
31
+ - Installation method: [e.g. go install, Docker, brew, scoop, apt, direct binary]
32
+
33
+ **Additional context**
34
+ Add any other context about the problem here.
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+ ---
8
+
9
+ **Is your feature request related to a problem? Please describe.**
10
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11
+
12
+ **Describe the solution you'd like**
13
+ A clear and concise description of what you want to happen.
14
+
15
+ **Describe alternatives you've considered**
16
+ A clear and concise description of any alternative solutions or features you've considered.
17
+
18
+ **Additional context**
19
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,25 @@
1
+ ## Description
2
+ <!-- Describe what this PR does and why -->
3
+
4
+ ## Changes
5
+ <!-- List the key changes -->
6
+ -
7
+
8
+ ## Type of Change
9
+ - [ ] Bug fix (non-breaking change which fixes an issue)
10
+ - [ ] New feature (non-breaking change which adds functionality)
11
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
12
+
13
+ ## Testing
14
+ - [ ] Existing tests pass
15
+ - [ ] Added new tests for the changes
16
+ - [ ] Tested manually
17
+
18
+ ## Screenshots
19
+ <!-- If applicable, add screenshots to help explain your changes -->
20
+
21
+ ## Checklist
22
+ - [ ] My code follows the project's coding standards
23
+ - [ ] I have commented my code where necessary
24
+ - [ ] I have updated documentation if needed
25
+ - [ ] My changes generate no new warnings
@@ -0,0 +1,22 @@
1
+ {
2
+ "schema_version": 1,
3
+ "tier": 1,
4
+ "description": "Telegram for AI agents -- messages, chats, media, and contacts across both bot and full user-account modes.",
5
+ "homepage": "https://docs.n24q02m.com/servers/telegram/",
6
+ "topics": [
7
+ "claude",
8
+ "claude-code",
9
+ "cursor",
10
+ "docker",
11
+ "mcp",
12
+ "mcp-server",
13
+ "model-context-protocol",
14
+ "open-source",
15
+ "telegram",
16
+ "ai-agents",
17
+ "ai-coding",
18
+ "python",
19
+ "telegram-bot",
20
+ "telethon"
21
+ ]
22
+ }
@@ -0,0 +1,14 @@
1
+ # Review learnings
2
+
3
+ Binding rules for the automated reviewer. It reads this file before every review
4
+ and before answering an issue, and it must obey every rule here.
5
+
6
+ Add a rule whenever the reviewer gives feedback that turns out to be wrong for
7
+ this codebase, so it never repeats that feedback. One rule per bullet, scoped by
8
+ path when it only applies in one place.
9
+
10
+ Format: `` `path/glob` `` — the rule, and the reason it exists.
11
+
12
+ ## Rules
13
+
14
+ _None recorded yet._
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "Main Branch Rules",
3
+ "target": "branch",
4
+ "enforcement": "active",
5
+ "bypass_actors": [
6
+ {
7
+ "actor_id": 5,
8
+ "actor_type": "RepositoryRole",
9
+ "bypass_mode": "always"
10
+ },
11
+ {
12
+ "actor_id": 3200052,
13
+ "actor_type": "Integration",
14
+ "bypass_mode": "always"
15
+ }
16
+ ],
17
+ "conditions": {
18
+ "ref_name": {
19
+ "exclude": [],
20
+ "include": [
21
+ "~DEFAULT_BRANCH"
22
+ ]
23
+ }
24
+ },
25
+ "rules": [
26
+ {
27
+ "type": "deletion"
28
+ },
29
+ {
30
+ "type": "non_fast_forward"
31
+ },
32
+ {
33
+ "type": "required_linear_history"
34
+ },
35
+ {
36
+ "type": "pull_request",
37
+ "parameters": {
38
+ "required_approving_review_count": 0,
39
+ "dismiss_stale_reviews_on_push": true,
40
+ "required_reviewers": [],
41
+ "require_code_owner_review": false,
42
+ "require_last_push_approval": false,
43
+ "required_review_thread_resolution": false,
44
+ "require_extra_approval_for_unattributed_changes": true,
45
+ "allowed_merge_methods": [
46
+ "squash"
47
+ ]
48
+ }
49
+ },
50
+ {
51
+ "type": "code_scanning",
52
+ "parameters": {
53
+ "code_scanning_tools": [
54
+ {
55
+ "tool": "CodeQL",
56
+ "security_alerts_threshold": "high_or_higher",
57
+ "alerts_threshold": "errors"
58
+ }
59
+ ]
60
+ }
61
+ }
62
+ ]
63
+ }
@@ -0,0 +1,116 @@
1
+ name: Bot PR Governance
2
+
3
+ on:
4
+ pull_request:
5
+ types:
6
+ - opened
7
+
8
+ permissions:
9
+ pull-requests: write
10
+ contents: read
11
+
12
+ jobs:
13
+ governance:
14
+ name: Bot PR Rate Limit & Duplicate Check
15
+ # Only govern pull requests whose branch lives in this repository.
16
+ #
17
+ # Technically: a pull_request run from a fork gets a read-only GITHUB_TOKEN
18
+ # whatever the permissions block above asks for, and `gh pr close` and
19
+ # `gh pr comment` are both unguarded under `set -e`, so the job would fail.
20
+ #
21
+ # More importantly: what it would be trying to do there is close an
22
+ # outsider's pull request because somebody else's bot spent the day's rate
23
+ # limit. Every bot this governs pushes its branch into this repository, so
24
+ # nothing is lost by not running.
25
+ #
26
+ # Comparing head.repo.full_name against the repository asks whether the
27
+ # branch lives here. head.repo.fork answers a different question — whether
28
+ # the source repository is itself a fork — which would silently disable
29
+ # governance for internal branches if this repository ever became one.
30
+ if: github.event.pull_request.head.repo.full_name == github.repository
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - name: Detect and govern bot PRs
34
+ env:
35
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36
+ BRANCH: ${{ github.head_ref }}
37
+ ACTOR: ${{ github.actor }}
38
+ PR_NUMBER: ${{ github.event.pull_request.number }}
39
+ PR_TITLE: ${{ github.event.pull_request.title }}
40
+ REPO: ${{ github.repository }}
41
+ BOT_PR_AUTOCLOSE: ${{ vars.BOT_PR_AUTOCLOSE }}
42
+ run: |
43
+ set -e
44
+
45
+ # Detect if this is a bot-created PR by branch name pattern.
46
+ # Two signals:
47
+ # 1. Explicit bot-tool prefixes (Bolt, Palette, Jules, fix/web-scraper)
48
+ # 2. Any branch ending with a long numeric task/trace ID (-[0-9]{14,})
49
+ IS_BOT_PR=false
50
+ if echo "$BRANCH" | grep -qE \
51
+ '^(bolt[-/]|palette-ux-|fix/web-scraper-|jules[-/])'; then
52
+ IS_BOT_PR=true
53
+ elif echo "$BRANCH" | grep -qE -- \
54
+ '-[0-9]{14,}$'; then
55
+ IS_BOT_PR=true
56
+ fi
57
+
58
+ if [ "$IS_BOT_PR" = "false" ]; then
59
+ echo "Not a bot PR ($BRANCH), skipping governance checks."
60
+ exit 0
61
+ fi
62
+
63
+ echo "Bot PR detected on branch: $BRANCH"
64
+ gh pr edit "$PR_NUMBER" --add-label "bot-generated" --repo "$REPO" || true
65
+
66
+ # --- Rate limit: max 5 bot PRs/actor/day ---
67
+ SINCE=$(date -u -d '24 hours ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || \
68
+ date -u -v-24H +%Y-%m-%dT%H:%M:%SZ)
69
+ COUNT=$(gh pr list --repo "$REPO" --state all --limit 1000 \
70
+ --json createdAt,headRefName,author \
71
+ --jq "[.[] |
72
+ select(.author.login == \"$ACTOR\") |
73
+ select(.createdAt > \"$SINCE\") |
74
+ select(.headRefName | test(
75
+ \"^(bolt[-/]|palette-ux-|fix/web-scraper-|jules[-/])\" +
76
+ \"|-[0-9]{14,}$\"
77
+ ))] | length" 2>/dev/null || echo 0)
78
+
79
+ echo "Bot PRs by $ACTOR in last 24h: $COUNT"
80
+
81
+ if [ "${COUNT:-0}" -gt 5 ]; then
82
+ if [ "${BOT_PR_AUTOCLOSE:-false}" != "true" ]; then
83
+ gh pr edit "$PR_NUMBER" --repo "$REPO" \
84
+ --add-label "bot-rate-limit-exceeded" || true
85
+ echo "Rate limit exceeded ($COUNT/5) but BOT_PR_AUTOCLOSE is not 'true': labelled only."
86
+ exit 0
87
+ fi
88
+ gh pr close "$PR_NUMBER" --repo "$REPO" \
89
+ --comment "**Bot rate limit exceeded**: $COUNT PRs created in the last 24 hours (limit: 5/day). This PR has been automatically closed to reduce PR backlog and CI resource waste. Please consolidate related fixes."
90
+ echo "PR #$PR_NUMBER closed: rate limit exceeded ($COUNT/5 today)"
91
+ exit 0
92
+ fi
93
+
94
+ # --- Duplicate detection by title keyword ---
95
+ KEYWORD=$(echo "$PR_TITLE" | sed 's/[^a-zA-Z0-9 _-]//g' | \
96
+ tr '[:upper:]' '[:lower:]' | cut -c1-50 | xargs)
97
+ if [ -z "$KEYWORD" ]; then
98
+ echo "No keyword extracted, skipping duplicate check."
99
+ exit 0
100
+ fi
101
+
102
+ # --state open on purpose: a closed PR is not a duplicate of an open one.
103
+ # The rate-limit count above uses --state all because a merged bot PR
104
+ # still spent the day's budget.
105
+ DUPES=$(gh pr list --repo "$REPO" --state open --search "$KEYWORD" --limit 1000 \
106
+ --json number \
107
+ --jq "[.[] | select(.number != $PR_NUMBER)] | length" \
108
+ 2>/dev/null || echo 0)
109
+
110
+ echo "Similar open PRs for '$KEYWORD': $DUPES"
111
+ if [ "${DUPES:-0}" -ge 1 ]; then
112
+ gh pr edit "$PR_NUMBER" --repo "$REPO" \
113
+ --add-label "possible-duplicate" || true
114
+ gh pr comment "$PR_NUMBER" --repo "$REPO" \
115
+ --body "**Possible duplicate**: found ${DUPES} open PR(s) with similar title ('${KEYWORD}'). Check before merging: \`gh pr list --search '${KEYWORD}' --state open --limit 1000\`"
116
+ fi