tele-mess-core 0.3.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 (53) hide show
  1. tele_mess_core-0.3.0/LICENSE +186 -0
  2. tele_mess_core-0.3.0/PKG-INFO +365 -0
  3. tele_mess_core-0.3.0/README.md +349 -0
  4. tele_mess_core-0.3.0/pyproject.toml +30 -0
  5. tele_mess_core-0.3.0/setup.cfg +4 -0
  6. tele_mess_core-0.3.0/src/tele_mess_core/__init__.py +3 -0
  7. tele_mess_core-0.3.0/src/tele_mess_core/__main__.py +6 -0
  8. tele_mess_core-0.3.0/src/tele_mess_core/archive/__init__.py +4 -0
  9. tele_mess_core-0.3.0/src/tele_mess_core/archive/migrations.py +303 -0
  10. tele_mess_core-0.3.0/src/tele_mess_core/archive/schema.sql +410 -0
  11. tele_mess_core-0.3.0/src/tele_mess_core/archive/store.py +3268 -0
  12. tele_mess_core-0.3.0/src/tele_mess_core/cli.py +630 -0
  13. tele_mess_core-0.3.0/src/tele_mess_core/config.py +407 -0
  14. tele_mess_core-0.3.0/src/tele_mess_core/daily.py +3301 -0
  15. tele_mess_core-0.3.0/src/tele_mess_core/daily_jobs.py +516 -0
  16. tele_mess_core-0.3.0/src/tele_mess_core/logging_setup.py +32 -0
  17. tele_mess_core-0.3.0/src/tele_mess_core/maintenance.py +175 -0
  18. tele_mess_core-0.3.0/src/tele_mess_core/models.py +344 -0
  19. tele_mess_core-0.3.0/src/tele_mess_core/openai_fallback.py +331 -0
  20. tele_mess_core-0.3.0/src/tele_mess_core/runtime_paths.py +113 -0
  21. tele_mess_core-0.3.0/src/tele_mess_core/server/__init__.py +4 -0
  22. tele_mess_core-0.3.0/src/tele_mess_core/server/api.py +1540 -0
  23. tele_mess_core-0.3.0/src/tele_mess_core/server/console.html +1431 -0
  24. tele_mess_core-0.3.0/src/tele_mess_core/server/console.py +7 -0
  25. tele_mess_core-0.3.0/src/tele_mess_core/server/contracts.py +1573 -0
  26. tele_mess_core-0.3.0/src/tele_mess_core/telegram/__init__.py +6 -0
  27. tele_mess_core-0.3.0/src/tele_mess_core/telegram/auth.py +197 -0
  28. tele_mess_core-0.3.0/src/tele_mess_core/telegram/delivery.py +194 -0
  29. tele_mess_core-0.3.0/src/tele_mess_core/telegram/discovery.py +430 -0
  30. tele_mess_core-0.3.0/src/tele_mess_core/telegram/ingest.py +974 -0
  31. tele_mess_core-0.3.0/src/tele_mess_core/telegram/manager.py +469 -0
  32. tele_mess_core-0.3.0/src/tele_mess_core/telegram/runtime.py +84 -0
  33. tele_mess_core-0.3.0/src/tele_mess_core.egg-info/PKG-INFO +365 -0
  34. tele_mess_core-0.3.0/src/tele_mess_core.egg-info/SOURCES.txt +51 -0
  35. tele_mess_core-0.3.0/src/tele_mess_core.egg-info/dependency_links.txt +1 -0
  36. tele_mess_core-0.3.0/src/tele_mess_core.egg-info/entry_points.txt +2 -0
  37. tele_mess_core-0.3.0/src/tele_mess_core.egg-info/requires.txt +2 -0
  38. tele_mess_core-0.3.0/src/tele_mess_core.egg-info/top_level.txt +1 -0
  39. tele_mess_core-0.3.0/tests/test_api_contracts.py +100 -0
  40. tele_mess_core-0.3.0/tests/test_archive_store.py +1468 -0
  41. tele_mess_core-0.3.0/tests/test_cli.py +184 -0
  42. tele_mess_core-0.3.0/tests/test_config.py +328 -0
  43. tele_mess_core-0.3.0/tests/test_daily.py +1113 -0
  44. tele_mess_core-0.3.0/tests/test_daily_jobs.py +528 -0
  45. tele_mess_core-0.3.0/tests/test_maintenance.py +59 -0
  46. tele_mess_core-0.3.0/tests/test_openai_fallback.py +208 -0
  47. tele_mess_core-0.3.0/tests/test_runtime_manager.py +325 -0
  48. tele_mess_core-0.3.0/tests/test_runtime_paths.py +75 -0
  49. tele_mess_core-0.3.0/tests/test_sync_api.py +995 -0
  50. tele_mess_core-0.3.0/tests/test_telegram_auth.py +124 -0
  51. tele_mess_core-0.3.0/tests/test_telegram_delivery.py +84 -0
  52. tele_mess_core-0.3.0/tests/test_telegram_discovery.py +190 -0
  53. tele_mess_core-0.3.0/tests/test_telegram_ingest.py +891 -0
@@ -0,0 +1,186 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of
21
+ such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source, and
28
+ configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled object
32
+ code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work (an example is provided in the Appendix
37
+ below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object form,
40
+ that is based on (or derived from) the Work and for which the editorial
41
+ revisions, annotations, elaborations, or other modifications represent, as a
42
+ whole, an original work of authorship. For the purposes of this License,
43
+ Derivative Works shall not include works that remain separable from, or
44
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
45
+ Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
52
+ of this definition, "submitted" means any form of electronic, verbal, or
53
+ written communication sent to the Licensor or its representatives, including
54
+ but not limited to communication on electronic mailing lists, source code
55
+ control systems, and issue tracking systems that are managed by, or on behalf
56
+ of, the Licensor for the purpose of discussing and improving the Work, but
57
+ excluding communication that is conspicuously marked or otherwise designated
58
+ in writing by the copyright owner as "Not a Contribution."
59
+
60
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
61
+ behalf of whom a Contribution has been received by Licensor and subsequently
62
+ incorporated within the Work.
63
+
64
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
65
+ License, each Contributor hereby grants to You a perpetual, worldwide,
66
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
67
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
68
+ sublicense, and distribute the Work and such Derivative Works in Source or
69
+ Object form.
70
+
71
+ 3. Grant of Patent License. Subject to the terms and conditions of this
72
+ License, each Contributor hereby grants to You a perpetual, worldwide,
73
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
74
+ section) patent license to make, have made, use, offer to sell, sell, import,
75
+ and otherwise transfer the Work, where such license applies only to those
76
+ patent claims licensable by such Contributor that are necessarily infringed by
77
+ their Contribution(s) alone or by combination of their Contribution(s) with
78
+ the Work to which such Contribution(s) was submitted. If You institute patent
79
+ litigation against any entity (including a cross-claim or counterclaim in a
80
+ lawsuit) alleging that the Work or a Contribution incorporated within the Work
81
+ constitutes direct or contributory patent infringement, then any patent
82
+ licenses granted to You under this License for that Work shall terminate as of
83
+ the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
86
+ Derivative Works thereof in any medium, with or without modifications, and in
87
+ Source or Object form, provided that You meet the following conditions:
88
+
89
+ (a) You must give any other recipients of the Work or Derivative Works a copy
90
+ of this License; and
91
+
92
+ (b) You must cause any modified files to carry prominent notices stating that
93
+ You changed the files; and
94
+
95
+ (c) You must retain, in the Source form of any Derivative Works that You
96
+ distribute, all copyright, patent, trademark, and attribution notices from the
97
+ Source form of the Work, excluding those notices that do not pertain to any
98
+ part of the Derivative Works; and
99
+
100
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
101
+ then any Derivative Works that You distribute must include a readable copy of
102
+ the attribution notices contained within such NOTICE file, excluding those
103
+ notices that do not pertain to any part of the Derivative Works, in at least
104
+ one of the following places: within a NOTICE text file distributed as part of
105
+ the Derivative Works; within the Source form or documentation, if provided
106
+ along with the Derivative Works; or, within a display generated by the
107
+ Derivative Works, if and wherever such third-party notices normally appear.
108
+ The contents of the NOTICE file are for informational purposes only and do not
109
+ modify the License. You may add Your own attribution notices within Derivative
110
+ Works that You distribute, alongside or as an addendum to the NOTICE text from
111
+ the Work, provided that such additional attribution notices cannot be construed
112
+ as modifying the License.
113
+
114
+ You may add Your own copyright statement to Your modifications and may provide
115
+ additional or different license terms and conditions for use, reproduction, or
116
+ distribution of Your modifications, or for any such Derivative Works as a
117
+ whole, provided Your use, reproduction, and distribution of the Work otherwise
118
+ complies with the conditions stated in this License.
119
+
120
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
121
+ Contribution intentionally submitted for inclusion in the Work by You to the
122
+ Licensor shall be under the terms and conditions of this License, without any
123
+ additional terms or conditions. Notwithstanding the above, nothing herein
124
+ shall supersede or modify the terms of any separate license agreement you may
125
+ have executed with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade names,
128
+ trademarks, service marks, or product names of the Licensor, except as
129
+ required for reasonable and customary use in describing the origin of the Work
130
+ and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
133
+ writing, Licensor provides the Work (and each Contributor provides its
134
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
135
+ KIND, either express or implied, including, without limitation, any warranties
136
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
137
+ PARTICULAR PURPOSE. You are solely responsible for determining the
138
+ appropriateness of using or redistributing the Work and assume any risks
139
+ associated with Your exercise of permissions under this License.
140
+
141
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
142
+ tort (including negligence), contract, or otherwise, unless required by
143
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
144
+ writing, shall any Contributor be liable to You for damages, including any
145
+ direct, indirect, special, incidental, or consequential damages of any
146
+ character arising as a result of this License or out of the use or inability
147
+ to use the Work (including but not limited to damages for loss of goodwill,
148
+ work stoppage, computer failure or malfunction, or any and all other
149
+ commercial damages or losses), even if such Contributor has been advised of
150
+ the possibility of such damages.
151
+
152
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work
153
+ or Derivative Works thereof, You may choose to offer, and charge a fee for,
154
+ acceptance of support, warranty, indemnity, or other liability obligations
155
+ and/or rights consistent with this License. However, in accepting such
156
+ obligations, You may act only on Your own behalf and on Your sole
157
+ responsibility, not on behalf of any other Contributor, and only if You agree
158
+ to indemnify, defend, and hold each Contributor harmless for any liability
159
+ incurred by, or claims asserted against, such Contributor by reason of your
160
+ accepting any such warranty or additional liability.
161
+
162
+ END OF TERMS AND CONDITIONS
163
+
164
+ APPENDIX: How to apply the Apache License to your work.
165
+
166
+ To apply the Apache License to your work, attach the following boilerplate
167
+ notice, with the fields enclosed by brackets "[]" replaced with your own
168
+ identifying information. (Don't include the brackets!) The text should be
169
+ enclosed in the appropriate comment syntax for the file format. We also
170
+ recommend that a file or class name and description of purpose be included on
171
+ the same "printed page" as the copyright notice for easier identification
172
+ within third-party archives.
173
+
174
+ Copyright 2026 dreaifekks
175
+
176
+ Licensed under the Apache License, Version 2.0 (the "License");
177
+ you may not use this file except in compliance with the License.
178
+ You may obtain a copy of the License at
179
+
180
+ http://www.apache.org/licenses/LICENSE-2.0
181
+
182
+ Unless required by applicable law or agreed to in writing, software
183
+ distributed under the License is distributed on an "AS IS" BASIS,
184
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185
+ See the License for the specific language governing permissions and
186
+ limitations under the License.
@@ -0,0 +1,365 @@
1
+ Metadata-Version: 2.4
2
+ Name: tele-mess-core
3
+ Version: 0.3.0
4
+ Summary: Telegram message archive core with SQLite storage and sync API
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/dreaifekks/tele-mess-core
7
+ Project-URL: Repository, https://github.com/dreaifekks/tele-mess-core
8
+ Project-URL: Issues, https://github.com/dreaifekks/tele-mess-core/issues
9
+ Project-URL: Changelog, https://github.com/dreaifekks/tele-mess-core/blob/master/CHANGELOG.md
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: Telethon<2,>=1.38
14
+ Requires-Dist: PyYAML<7,>=6
15
+ Dynamic: license-file
16
+
17
+ # tele-mess-core
18
+
19
+ `tele-mess-core` is a single-user, multi-Telegram-account archive core for
20
+ future Mac and web clients.
21
+
22
+ It stores Telegram messages in SQLite and exposes sync plus management endpoints
23
+ for remote clients. The core is meant to run as a long-running local database and
24
+ control plane: clients manage account authentication, origin discovery, backup
25
+ selection, capture policy, topics, and participant metadata through the core API.
26
+
27
+ It intentionally does not forward messages to backup Telegram groups. Daily
28
+ package generation and local Codex-backed daily summaries run as local jobs
29
+ against the archive. See
30
+ [product direction](https://github.com/dreaifekks/tele-mess-core/blob/master/docs/product-direction.md)
31
+ for the management interface direction and
32
+ [daily packaging](https://github.com/dreaifekks/tele-mess-core/blob/master/docs/daily-packaging.md)
33
+ for daily package and AI analysis details.
34
+
35
+ ## Current Scope
36
+
37
+ - Telegram ingestion with Telethon.
38
+ - Multiple Telegram accounts feeding one archive.
39
+ - One supervised, long-lived Telethon client per account, shared by ingestion,
40
+ auth, discovery, participant refresh, and summary delivery.
41
+ - SQLite archive for chats, users, messages, reactions, and event cursors.
42
+ - Cursor-based HTTP sync API for LAN or Tailscale use.
43
+ - Token-protected management API for account state, origins, backup policies,
44
+ topics, participant metadata, and capture cursors.
45
+ - Built-in web console for the same management surface at `GET /console`.
46
+ - Policy-aware ingestion with bounded history backfill and reconnect catch-up.
47
+ - Live origin discovery and participant refresh endpoints for authenticated
48
+ Telegram sessions.
49
+ - Runtime operation events for Telegram auth/discovery/media-download failures.
50
+ - Server daemon mode for an always-on Linux deployment.
51
+ - macOS-oriented local CLI mode with durable jobs and no HTTP listener by
52
+ default.
53
+ - Daily package generation by origin, tag group, timezone, and local date.
54
+ - Local Codex-backed daily analysis with important-origin full-context reports,
55
+ all-origin structured message points, and point-based daily digests.
56
+ - Durable daily package-and-summary jobs with deduplication, cancellation,
57
+ restart recovery, leases, and a retryable Telegram delivery outbox.
58
+ - System-managed daily package and summary scheduling through user-level systemd
59
+ timer files.
60
+ - Optional raw Telegram JSON retention cleanup for keeping the SQLite archive
61
+ compact while preserving structured message rows.
62
+
63
+ ## Run from PyPI with uvx
64
+
65
+ [`uvx`](https://docs.astral.sh/uv/guides/tools/) installs the published package
66
+ and its Python dependencies into an isolated cache, then runs the
67
+ `tele-mess-core` command. It does not clone the repository into the current
68
+ directory, and runtime state remains in the selected workspace rather than the
69
+ tool environment.
70
+
71
+ Once a release is available on PyPI and the Mac workspace contains a valid
72
+ `config.yml`, the local core is one command:
73
+
74
+ ```bash
75
+ uvx tele-mess-core run-local
76
+ ```
77
+
78
+ Use the same stable workspace across invocations, or select one explicitly:
79
+
80
+ ```bash
81
+ uvx tele-mess-core run-local \
82
+ --workspace "$HOME/Library/Application Support/tele-mess-core-personal"
83
+ ```
84
+
85
+ For a reproducible launcher, pin the distribution while keeping the executable
86
+ name explicit:
87
+
88
+ ```bash
89
+ uvx --from "tele-mess-core==X.Y.Z" tele-mess-core run-local
90
+ ```
91
+
92
+ Maintainers can find the tag and Trusted Publishing process in the
93
+ [release guide](https://github.com/dreaifekks/tele-mess-core/blob/master/docs/releasing.md).
94
+
95
+ A fresh machine still needs Telegram API credentials and a local configuration
96
+ before `run-local` can ingest messages. In the macOS product, `mess-end` owns
97
+ that first-run UI and drives the core management/auth API for code/2FA login,
98
+ origin discovery, and capture-policy management; these are intentionally not
99
+ duplicated as interactive core CLI setup. A standalone operator may enable
100
+ `run-local --web` temporarily as a fallback. The normal local runtime keeps HTTP
101
+ disabled.
102
+
103
+ ## Source Checkout
104
+
105
+ ```bash
106
+ python3 -m venv .venv
107
+ . .venv/bin/activate
108
+ pip install -e .
109
+ cp config.example.yml config.yml
110
+ tele-mess-core init-db --config config.yml
111
+ tele-mess-core smoke-telegram --config config.yml
112
+ tele-mess-core run-server --config config.yml
113
+ ```
114
+
115
+ If no authorized Telegram session exists, use the built-in console while
116
+ `run-server` is active to request a login code and submit code/2FA credentials.
117
+ See the
118
+ [server-mode guide](https://github.com/dreaifekks/tele-mess-core/blob/master/docs/server-mode.md)
119
+ for the always-on deployment shape and client sync contract. See the
120
+ [daily-packaging guide](https://github.com/dreaifekks/tele-mess-core/blob/master/docs/daily-packaging.md)
121
+ for the daily packaging, scheduling, and staged AI analysis workflow.
122
+
123
+ ## macOS Local Mode
124
+
125
+ `run-local` starts Telegram ingestion plus the durable daily worker without
126
+ starting the HTTP API or web console. On macOS its default workspace is
127
+ `~/Library/Application Support/tele-mess-core`, so it does not depend on the
128
+ Terminal or launcher current directory.
129
+
130
+ ```bash
131
+ mkdir -p "$HOME/Library/Application Support/tele-mess-core"
132
+ cp config.example.yml "$HOME/Library/Application Support/tele-mess-core/config.yml"
133
+ tele-mess-core paths
134
+ tele-mess-core run-local
135
+ ```
136
+
137
+ Use `--workspace PATH` (alias `--work-dir`),
138
+ `TELE_MESS_CORE_WORKSPACE`, or `TELE_MESS_CORE_HOME` to select another stable
139
+ instance root. `TELE_MESS_CORE_CONFIG` or an explicit `--config` selects a
140
+ specific config. `tele-mess-core paths` prints the resolved non-secret paths
141
+ without opening the database.
142
+
143
+ HTTP remains opt-in in local mode:
144
+
145
+ ```bash
146
+ tele-mess-core run-local --web
147
+ ```
148
+
149
+ This enables the existing API and `/console`; it never opens a browser
150
+ automatically. See the
151
+ [local-mode guide](https://github.com/dreaifekks/tele-mess-core/blob/master/docs/local-mode.md)
152
+ for precedence, path semantics, first-login limitations, and configuration
153
+ examples.
154
+
155
+ Use `telegram.accounts[]` for multi-account auth/runtime configuration. Message
156
+ capture sources are managed in SQLite through origin discovery plus backup
157
+ policies; `telegram.chats` in config is no longer used.
158
+
159
+ ## Raw JSON Cleanup
160
+
161
+ Message rows keep structured fields plus a raw Telethon JSON payload for recent
162
+ forensics. The raw payload can be cleared after a retention window without
163
+ removing message text, timestamps, senders, search data, or sync cursors.
164
+
165
+ ```bash
166
+ tele-mess-core cleanup-raw-json --config config.yml --retention-days 7
167
+ tele-mess-core cleanup-raw-json --config config.yml --retention-days 7 --dry-run
168
+ tele-mess-core raw-json-cleanup-schedule --config config.yml install --activate-systemd
169
+ ```
170
+
171
+ The cleanup timer defaults to `OnCalendar=weekly` and reads
172
+ `storage.raw_json_retention_days`, which defaults to `7`. Add `--vacuum` only
173
+ when you want the SQLite file to shrink immediately; without it, SQLite reuses
174
+ the freed pages for later messages.
175
+
176
+ ## Sync API
177
+
178
+ - `GET /healthz`
179
+ - `GET /sync/state`
180
+ - `GET /sync/events?after=0&limit=500`
181
+ - `GET /sync/messages?after=0&limit=500`
182
+ - `GET /sync/accounts`
183
+ - `GET /sync/chats`
184
+ - `GET /sync/search?q=term`
185
+ - `GET /sync/media-files?account_id=main`
186
+
187
+ ## Management API
188
+
189
+ - `GET /manage/capabilities`
190
+ - `GET /manage/accounts`
191
+ - `POST /manage/accounts`
192
+ - `POST` or `PATCH /manage/accounts/auth`
193
+ - `POST /manage/accounts/auth/status`
194
+ - `POST /manage/accounts/auth/request-code`
195
+ - `POST /manage/accounts/auth/submit-code`
196
+ - `GET /manage/origins?account_id=main`
197
+ - `POST /manage/origins`
198
+ - `GET /manage/backup-policies?account_id=main`
199
+ - `POST` or `PATCH /manage/backup-policies`
200
+ - `GET /manage/participants?account_id=main&origin_id=-100123`
201
+ - `POST /manage/participants`
202
+ - `GET /manage/capture-cursors?account_id=main`
203
+ - `GET /manage/operation-events?account_id=main&status=failed`
204
+ - `GET` or `PATCH /manage/daily-package-schedule`
205
+ - `GET` or `PATCH /manage/daily-summary-delivery`
206
+ - `POST /manage/daily-packages`
207
+ - `GET /manage/daily-package-runs`
208
+ - `POST /manage/daily-summaries`
209
+ - `POST` or `GET /manage/daily-summary-jobs`
210
+ - `PATCH /manage/daily-summary-jobs/cancel`
211
+ - `GET /manage/daily-summary-runs`
212
+ - `GET /manage/daily-summary-records`
213
+ - `GET /manage/daily-summary-records/item`
214
+ - `GET /manage/daily-message-points`
215
+ - `GET /manage/daily-message-points/item`
216
+ - `POST /manage/discover-origins`
217
+ - `POST /manage/participants/refresh`
218
+ - `GET /console`
219
+
220
+ The authoritative API reference is generated from
221
+ `src/tele_mess_core/server/contracts.py`:
222
+
223
+ - `docs/api.md` for human-readable endpoint docs.
224
+ - `docs/openapi.json` for tools.
225
+ - `docs/api-agent.md` for short agent lookup.
226
+ - `GET /manage/api-manifest` for the runtime contract version/hash and route
227
+ registry.
228
+ - `GET /openapi.json` and `GET /docs/api.md` for runtime docs served by the
229
+ core process.
230
+
231
+ Regenerate and verify these files with:
232
+
233
+ ```bash
234
+ tele-mess-core generate-api-docs
235
+ tele-mess-core generate-api-docs --check
236
+ ```
237
+
238
+ `GET /console` serves the built-in management console. The page can be opened in
239
+ a browser without a token header, then the operator enters `server.token` in the
240
+ page. API calls from the console still use the same token-protected management
241
+ and sync endpoints as external clients. The console keeps the token in tab
242
+ session storage rather than persistent browser storage.
243
+
244
+ If `server.token` is configured, pass it as:
245
+
246
+ ```text
247
+ Authorization: Bearer <token>
248
+ ```
249
+
250
+ or:
251
+
252
+ ```text
253
+ X-Api-Token: <token>
254
+ ```
255
+
256
+ The server requires a token by default. An empty token is accepted only when
257
+ `server.allow_unauthenticated_localhost: true` is explicitly configured and the
258
+ server is bound to a loopback address.
259
+
260
+ ## Media Backup Semantics
261
+
262
+ Backup policy separates three media modes:
263
+
264
+ - `capture_text`: store message text.
265
+ - `capture_media_metadata`: store Telegram media metadata in the message row.
266
+ - `download_media`: download media files and expose them through `/sync/media-files`.
267
+
268
+ Media files requested by `download_media: true` are stored under a `media/`
269
+ directory next to the SQLite database. Download failures are retried according
270
+ to `telegram.media_download` and then recorded in `/manage/operation-events`
271
+ if they still fail.
272
+
273
+ ## Daily Packaging
274
+
275
+ Daily packages are generated from already archived messages. The run selects
276
+ enabled, non-removed backup origins by account, origin, topic, tag intersection,
277
+ or tag groups, then skips origins with no messages in the selected daily
278
+ window. Parent origins and forum topics are grouped together by the parent's
279
+ tags unless a topic has explicit different tags or is marked important.
280
+ When no ad hoc tag group scope is supplied, origins are grouped by their
281
+ effective CSV tag set for package navigation and point metadata. Explicit tag
282
+ groups are assigned from most-specific to least-specific, but unmatched origins
283
+ still enter the all-origin point flow. Normal tag groups no longer create their
284
+ own summary records.
285
+
286
+ Origin rows can be marked `important`; important origins are packaged separately
287
+ and analyzed in full context. Every eligible origin, including important ones,
288
+ also participates in a separate structured message-point pipeline. Daily runs
289
+ therefore produce two independent products:
290
+
291
+ - image media analysis with OCR/visual extraction through Codex image inputs;
292
+ - non-image long media such as PDF/video preserved as file references;
293
+ - message-point extraction from important and non-important origins, with time,
294
+ tags, content, Telegram links, importance, and source references;
295
+ - full-context analysis and a daily report sourced only from important origins;
296
+ - a separate daily digest sourced only from the persisted message points.
297
+
298
+ Package and summary artifacts are written under the configured daily output
299
+ directory, while SQLite stores run status, paths, counts, errors, typed summary
300
+ records, and individually queryable message points for API lookup/filtering.
301
+ Normal point queries expose completed runs; diagnostic callers can opt into
302
+ failed, canceled, or still-running run points explicitly.
303
+
304
+ When Telegram delivery is enabled, the important report and point digest are
305
+ sent as separate logical messages to the configured target. The point digest
306
+ uses the fixed searchable tag `#point`; the important report keeps its source
307
+ tags.
308
+
309
+ The default Codex CLI template selects `gpt-5.6-sol` and expands task-specific
310
+ `{model}` and `{output_schema}` placeholders before invoking the provider.
311
+
312
+ API and scheduled package-plus-summary requests use the same durable SQLite job
313
+ queue. Equivalent active or completed requests are deduplicated unless
314
+ `force: true` or CLI `--force` is supplied. Summary records and delivery outbox
315
+ chunks are committed atomically; delivery failures remain retryable without
316
+ turning an already completed summary into a failed run.
317
+
318
+ ## Runtime Architecture
319
+
320
+ - `TelegramRuntimeManager` supervises each account independently and reuses one
321
+ connected client for all Telegram operations.
322
+ - `DailyJobWorker` owns package-plus-summary execution, lease recovery,
323
+ cancellation, and delivery-outbox draining. No background job depends on an
324
+ untracked daemon thread.
325
+ - `ArchiveStore` uses WAL, busy timeouts, explicit short transactions, and one
326
+ SQLite connection per worker/request thread.
327
+ - Numbered, transactional migrations upgrade the archive schema. Job and
328
+ outbox state transitions have database-level validation triggers.
329
+ - The HTTP route/auth registry and request validation are driven by
330
+ `server/contracts.py`; generated Markdown/OpenAPI files and runtime docs share
331
+ the same contract hash.
332
+
333
+ The default AI provider is a configurable local `codex exec` command template
334
+ using `--output-last-message`. Templates can use `{output}`, `{images}`, and
335
+ `{task}`. An optional `daily.ai.fallback` can switch the remainder of a run to
336
+ an OpenAI-compatible Responses endpoint only when Codex reports a usage limit.
337
+ The API key is read from an ignored local file; transient fallback failures can
338
+ be durably retried once after a configured delay. Set `daily.ai.provider:
339
+ disabled` only for local testing or dry runs.
340
+
341
+ ## Design Boundary
342
+
343
+ The server is responsible for durable collection, sync, capture-management
344
+ state, daily packaging, and local daily analysis jobs. Client-side features such
345
+ as labels and app-specific UI state should live in the Mac app.
346
+
347
+ `mess-end` is the host-facing manager, while `tele-mess-core` remains an
348
+ independently runnable engine:
349
+
350
+ | Owner | Responsibilities |
351
+ | --- | --- |
352
+ | `tele-mess-core` | Telegram sessions, SQLite schema and migrations, ingestion, capture policy, daily jobs, delivery, and optional HTTP/API service. |
353
+ | `mess-end` | Version selection and installation, workspace selection, first-run UI, process start/stop/status, updates, and macOS LaunchAgent integration. |
354
+
355
+ `mess-end` should use the public CLI and management API rather than importing
356
+ internal Python modules or modifying the archive database directly. It should
357
+ also enforce one core process per workspace: `run-local` and `run-server` must
358
+ not own the same Telegram sessions and SQLite archive simultaneously. For a
359
+ persistent managed installation, `mess-end` should point LaunchAgent at a
360
+ stable, pinned executable rather than an incidental `uvx` cache path.
361
+
362
+ ## License
363
+
364
+ Apache-2.0. See the
365
+ [license](https://github.com/dreaifekks/tele-mess-core/blob/master/LICENSE).