@hasna/bridge 0.1.0 → 0.1.2
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.
- package/LICENSE +168 -1
- package/README.md +85 -3
- package/dist/cli/index.js +865 -95
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +787 -73
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/daemon.d.ts +123 -0
- package/dist/lib/daemon.d.ts.map +1 -0
- package/dist/lib/doctor.d.ts +1 -1
- package/dist/lib/doctor.d.ts.map +1 -1
- package/dist/lib/router.d.ts.map +1 -1
- package/dist/lib/telegram.d.ts +6 -0
- package/dist/lib/telegram.d.ts.map +1 -1
- package/dist/mcp/index.js +327 -38
- package/docs/architecture.md +35 -0
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -2,13 +2,180 @@ Apache License
|
|
|
2
2
|
Version 2.0, January 2004
|
|
3
3
|
http://www.apache.org/licenses/
|
|
4
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 copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
36
|
+
below).
|
|
37
|
+
|
|
38
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
39
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
40
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
41
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
42
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
43
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
44
|
+
|
|
45
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
46
|
+
version of the Work and any modifications or additions to that Work or
|
|
47
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
48
|
+
inclusion in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes of this
|
|
50
|
+
definition, "submitted" means any form of electronic, verbal, or written
|
|
51
|
+
communication sent to the Licensor or its representatives, including but not
|
|
52
|
+
limited to communication on electronic mailing lists, source code control
|
|
53
|
+
systems, and issue tracking systems that are managed by, or on behalf of, the
|
|
54
|
+
Licensor for the purpose of discussing and improving the Work, but excluding
|
|
55
|
+
communication that is conspicuously marked or otherwise designated in writing by
|
|
56
|
+
the copyright owner as "Not a Contribution."
|
|
57
|
+
|
|
58
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
59
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
60
|
+
incorporated within the Work.
|
|
61
|
+
|
|
62
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
63
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
64
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
65
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
66
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
67
|
+
Object form.
|
|
68
|
+
|
|
69
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
70
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
71
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
|
|
72
|
+
section) patent license to make, have made, use, offer to sell, sell, import,
|
|
73
|
+
and otherwise transfer the Work, where such license applies only to those patent
|
|
74
|
+
claims licensable by such Contributor that are necessarily infringed by their
|
|
75
|
+
Contribution(s) alone or by combination of their Contribution(s) with the Work
|
|
76
|
+
to which such Contribution(s) was submitted. If You institute patent litigation
|
|
77
|
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
|
78
|
+
alleging that the Work or a Contribution incorporated within the Work
|
|
79
|
+
constitutes direct or contributory patent infringement, then any patent licenses
|
|
80
|
+
granted to You under this License for that Work shall terminate as of the date
|
|
81
|
+
such litigation is filed.
|
|
82
|
+
|
|
83
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
84
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
85
|
+
Source or Object form, provided that You meet the following conditions:
|
|
86
|
+
|
|
87
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy
|
|
88
|
+
of this License; and
|
|
89
|
+
|
|
90
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
91
|
+
You changed the files; and
|
|
92
|
+
|
|
93
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
94
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
95
|
+
Source form of the Work, excluding those notices that do not pertain to any part
|
|
96
|
+
of the Derivative Works; and
|
|
97
|
+
|
|
98
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
99
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
102
|
+
following places: within a NOTICE text file distributed as part of the
|
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
104
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
|
106
|
+
the NOTICE file are for informational purposes only and do not modify the
|
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
|
110
|
+
modifying the License.
|
|
111
|
+
|
|
112
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
113
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
114
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
115
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
116
|
+
with the conditions stated in this License.
|
|
117
|
+
|
|
118
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
119
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
120
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
121
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
122
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
123
|
+
executed with Licensor regarding such Contributions.
|
|
124
|
+
|
|
125
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
126
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
127
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
128
|
+
reproducing the content of the NOTICE file.
|
|
129
|
+
|
|
130
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
131
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
132
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
133
|
+
KIND, either express or implied, including, without limitation, any warranties or
|
|
134
|
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
135
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
136
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
137
|
+
associated with Your exercise of permissions under this License.
|
|
138
|
+
|
|
139
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
140
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
141
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
142
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
143
|
+
direct, indirect, special, incidental, or consequential damages of any character
|
|
144
|
+
arising as a result of this License or out of the use or inability to use the
|
|
145
|
+
Work (including but not limited to damages for loss of goodwill, work stoppage,
|
|
146
|
+
computer failure or malfunction, or any and all other commercial damages or
|
|
147
|
+
losses), even if such Contributor has been advised of the possibility of such
|
|
148
|
+
damages.
|
|
149
|
+
|
|
150
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
151
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
152
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
153
|
+
and/or rights consistent with this License. However, in accepting such
|
|
154
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
155
|
+
responsibility, not on behalf of any other Contributor, and only if You agree to
|
|
156
|
+
indemnify, defend, and hold each Contributor harmless for any liability incurred
|
|
157
|
+
by, or claims asserted against, such Contributor by reason of your accepting any
|
|
158
|
+
such warranty or additional liability.
|
|
159
|
+
|
|
160
|
+
END OF TERMS AND CONDITIONS
|
|
161
|
+
|
|
162
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
163
|
+
|
|
164
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
165
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
|
166
|
+
identifying information. (Do not include the brackets!) The text should be
|
|
167
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
168
|
+
recommend that a file or class name and description of purpose be included on
|
|
169
|
+
the same "printed page" as the copyright notice for easier identification within
|
|
170
|
+
third-party archives.
|
|
171
|
+
|
|
5
172
|
Copyright 2026 Hasna
|
|
6
173
|
|
|
7
174
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
175
|
you may not use this file except in compliance with the License.
|
|
9
176
|
You may obtain a copy of the License at
|
|
10
177
|
|
|
11
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
178
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
179
|
|
|
13
180
|
Unless required by applicable law or agreed to in writing, software
|
|
14
181
|
distributed under the License is distributed on an "AS IS" BASIS,
|
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ bridge profiles add codewith-main --agent-kind codewith --auth-profile account00
|
|
|
20
20
|
bridge agents add codewith --kind codewith --profile codewith-main
|
|
21
21
|
bridge routes add telegram-codewith --from telegram-main --to codewith --chat-ids 123456789
|
|
22
22
|
bridge serve
|
|
23
|
+
bridge daemon start
|
|
23
24
|
```
|
|
24
25
|
|
|
25
26
|
Useful inspection commands:
|
|
@@ -41,6 +42,48 @@ bridge ask codewith "summarize this repo"
|
|
|
41
42
|
bridge route-message --channel telegram-main --chat-id 123456789 --text "status" --json
|
|
42
43
|
```
|
|
43
44
|
|
|
45
|
+
Daemon operations:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
bridge daemon start
|
|
49
|
+
bridge daemon status
|
|
50
|
+
bridge daemon logs --lines 100
|
|
51
|
+
bridge daemon restart
|
|
52
|
+
bridge daemon stop
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`bridge daemon start` uses the process supervisor by default. It starts
|
|
56
|
+
`bridge serve` in the background, inherits the current environment, and writes
|
|
57
|
+
private metadata and logs under `~/.hasna/bridge/daemon`.
|
|
58
|
+
|
|
59
|
+
For login-started services:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
bridge daemon install --supervisor auto
|
|
63
|
+
bridge daemon start --supervisor auto
|
|
64
|
+
bridge daemon stop --supervisor auto
|
|
65
|
+
bridge daemon uninstall --supervisor auto
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`install` writes a user `launchd` file on macOS or a user `systemd` file on
|
|
69
|
+
Linux. Telegram token values are not written to those files. Make token
|
|
70
|
+
environment variables available to the user service manager before starting an
|
|
71
|
+
installed daemon.
|
|
72
|
+
|
|
73
|
+
macOS:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
launchctl setenv TELEGRAM_BOT_TOKEN "$TELEGRAM_BOT_TOKEN"
|
|
77
|
+
bridge daemon start --supervisor launchd
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Linux:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
systemctl --user import-environment TELEGRAM_BOT_TOKEN
|
|
84
|
+
bridge daemon start --supervisor systemd
|
|
85
|
+
```
|
|
86
|
+
|
|
44
87
|
## Profiles
|
|
45
88
|
|
|
46
89
|
Profiles let one bridge process route messages to multiple accounts without
|
|
@@ -89,6 +132,45 @@ Override with `BRIDGE_HOME` or `BRIDGE_CONFIG`.
|
|
|
89
132
|
Telegram bot tokens should stay in environment variables; config stores the env
|
|
90
133
|
var name, not the token value. Telegram channels fail closed unless
|
|
91
134
|
`allowedChatIds` are set or `allowAllChats` is explicitly enabled.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
already-seen updates.
|
|
135
|
+
Disabled channels do not match or deliver routes. Channel-level `allowedChatIds`
|
|
136
|
+
are enforced before route matching, and long-poll offsets are persisted in
|
|
137
|
+
`~/.hasna/bridge/state.json` so restarts do not replay already-seen updates.
|
|
138
|
+
MCP config inspection redacts profile and agent environment values.
|
|
139
|
+
|
|
140
|
+
Daemon metadata and logs are private as well. Logs can contain prompts and agent
|
|
141
|
+
responses, so treat them as sensitive.
|
|
142
|
+
|
|
143
|
+
## Telegram Smoke Test
|
|
144
|
+
|
|
145
|
+
Create a bot with BotFather and set the token only in your shell:
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
export TELEGRAM_BOT_TOKEN='123456:...'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Send any message to the bot from the Telegram account or group you want to use,
|
|
152
|
+
then find the chat id:
|
|
153
|
+
|
|
154
|
+
```sh
|
|
155
|
+
curl "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates"
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Configure one allowed chat and a test shell agent:
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
bridge init
|
|
162
|
+
bridge channels add-telegram telegram-main --token-env TELEGRAM_BOT_TOKEN --allowed-chat-ids CHAT_ID --default-chat-id CHAT_ID
|
|
163
|
+
bridge profiles add shell-echo --agent-kind shell --command printf --arg 'bridge ok: {prompt}'
|
|
164
|
+
bridge agents add echo --kind shell --profile shell-echo
|
|
165
|
+
bridge routes add telegram-echo --from telegram-main --to echo --chat-ids CHAT_ID
|
|
166
|
+
bridge doctor
|
|
167
|
+
bridge daemon start
|
|
168
|
+
bridge daemon status
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Send a Telegram message to the bot. It should reply with `bridge ok: ...`.
|
|
172
|
+
Inspect logs with `bridge daemon logs`, then stop it with `bridge daemon stop`.
|
|
173
|
+
|
|
174
|
+
For the first live test, use the default process supervisor above because it
|
|
175
|
+
inherits `TELEGRAM_BOT_TOKEN` from your shell. Move to launchd/systemd after that
|
|
176
|
+
works.
|