@hasna/bridge 0.1.0 → 0.1.1

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 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
@@ -89,6 +89,7 @@ Override with `BRIDGE_HOME` or `BRIDGE_CONFIG`.
89
89
  Telegram bot tokens should stay in environment variables; config stores the env
90
90
  var name, not the token value. Telegram channels fail closed unless
91
91
  `allowedChatIds` are set or `allowAllChats` is explicitly enabled.
92
- Channel-level `allowedChatIds` are enforced before route matching, and long-poll
93
- offsets are persisted in `~/.hasna/bridge/state.json` so restarts do not replay
94
- already-seen updates.
92
+ Disabled channels do not match or deliver routes. Channel-level `allowedChatIds`
93
+ are enforced before route matching, and long-poll offsets are persisted in
94
+ `~/.hasna/bridge/state.json` so restarts do not replay already-seen updates.
95
+ MCP config inspection redacts profile and agent environment values.
package/dist/cli/index.js CHANGED
@@ -6305,7 +6305,54 @@ async function upsertRoute(route, configPath = defaultConfigPath()) {
6305
6305
  return config;
6306
6306
  }
6307
6307
  // src/lib/doctor.ts
6308
- import { access } from "fs/promises";
6308
+ import { stat } from "fs/promises";
6309
+
6310
+ // src/lib/state.ts
6311
+ import { chmod as chmod2, mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
6312
+ import { dirname as dirname2, join as join2 } from "path";
6313
+ function defaultStatePath() {
6314
+ return process.env["BRIDGE_STATE"] || join2(bridgeHome(), "state.json");
6315
+ }
6316
+ function emptyState() {
6317
+ return { telegramOffsets: {} };
6318
+ }
6319
+ async function loadState(statePath = defaultStatePath()) {
6320
+ try {
6321
+ const raw = await readFile2(statePath, "utf-8");
6322
+ const parsed = JSON.parse(raw);
6323
+ return {
6324
+ telegramOffsets: parsed.telegramOffsets && typeof parsed.telegramOffsets === "object" ? parsed.telegramOffsets : {}
6325
+ };
6326
+ } catch (err) {
6327
+ if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") {
6328
+ return emptyState();
6329
+ }
6330
+ throw err;
6331
+ }
6332
+ }
6333
+ async function saveState(state, statePath = defaultStatePath()) {
6334
+ await mkdir2(dirname2(statePath), { recursive: true, mode: 448 });
6335
+ await writeFile2(statePath, `${JSON.stringify(state, null, 2)}
6336
+ `, { encoding: "utf-8", mode: 384 });
6337
+ await chmod2(statePath, 384);
6338
+ }
6339
+
6340
+ // src/lib/doctor.ts
6341
+ function isNotFound(err) {
6342
+ return Boolean(err && typeof err === "object" && "code" in err && err.code === "ENOENT");
6343
+ }
6344
+ async function privateFileCheck(name, path) {
6345
+ try {
6346
+ const info = await stat(path);
6347
+ const mode = info.mode & 511;
6348
+ const ok = (mode & 63) === 0;
6349
+ return { name, ok, detail: `${path} mode=${mode.toString(8)}` };
6350
+ } catch (err) {
6351
+ if (isNotFound(err))
6352
+ return { name, ok: true, detail: `not created yet: ${path}` };
6353
+ return { name, ok: false, detail: `${path}: ${err instanceof Error ? err.message : String(err)}` };
6354
+ }
6355
+ }
6309
6356
  async function commandExists(command) {
6310
6357
  const proc = Bun.spawn(["sh", "-lc", `command -v ${command} >/dev/null 2>&1`], {
6311
6358
  stdout: "ignore",
@@ -6313,15 +6360,11 @@ async function commandExists(command) {
6313
6360
  });
6314
6361
  return await proc.exited === 0;
6315
6362
  }
6316
- async function doctor(configPath = defaultConfigPath()) {
6363
+ async function doctor(configPath = defaultConfigPath(), statePath = defaultStatePath()) {
6317
6364
  const checks = [];
6318
6365
  let config = await loadConfig(configPath);
6319
- try {
6320
- await access(configPath);
6321
- checks.push({ name: "config", ok: true, detail: configPath });
6322
- } catch {
6323
- checks.push({ name: "config", ok: true, detail: `not created yet: ${configPath}` });
6324
- }
6366
+ checks.push(await privateFileCheck("config", configPath));
6367
+ checks.push(await privateFileCheck("state", statePath));
6325
6368
  for (const command of ["bridge", "codewith", "claude", "aicopilot"]) {
6326
6369
  checks.push({
6327
6370
  name: `command:${command}`,
@@ -6413,6 +6456,8 @@ function telegramUpdateToMessage(channelId, update) {
6413
6456
  // src/lib/router.ts
6414
6457
  function matchingRoutes(config, message) {
6415
6458
  const channel = config.channels[message.channelId];
6459
+ if (!channel || channel.enabled === false)
6460
+ return [];
6416
6461
  if (channel?.kind === "telegram" && !telegramChatAllowed(channel, message.chatId)) {
6417
6462
  return [];
6418
6463
  }
@@ -6440,6 +6485,10 @@ async function routeMessage(config, message, options = {}) {
6440
6485
  let deliveredResponse = false;
6441
6486
  const channel = responseChannel(config, route, message);
6442
6487
  const responseText = agent.stdout.trim();
6488
+ if (channel?.enabled === false) {
6489
+ results.push({ route, agent, deliveredResponse });
6490
+ continue;
6491
+ }
6443
6492
  if (responseText && channel?.kind === "telegram" && message.chatId) {
6444
6493
  if (!telegramChatAllowed(channel, message.chatId)) {
6445
6494
  results.push({ route, agent, deliveredResponse });
@@ -6456,35 +6505,6 @@ async function routeMessage(config, message, options = {}) {
6456
6505
  }
6457
6506
  return results;
6458
6507
  }
6459
- // src/lib/state.ts
6460
- import { chmod as chmod2, mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
6461
- import { dirname as dirname2, join as join2 } from "path";
6462
- function defaultStatePath() {
6463
- return process.env["BRIDGE_STATE"] || join2(bridgeHome(), "state.json");
6464
- }
6465
- function emptyState() {
6466
- return { telegramOffsets: {} };
6467
- }
6468
- async function loadState(statePath = defaultStatePath()) {
6469
- try {
6470
- const raw = await readFile2(statePath, "utf-8");
6471
- const parsed = JSON.parse(raw);
6472
- return {
6473
- telegramOffsets: parsed.telegramOffsets && typeof parsed.telegramOffsets === "object" ? parsed.telegramOffsets : {}
6474
- };
6475
- } catch (err) {
6476
- if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") {
6477
- return emptyState();
6478
- }
6479
- throw err;
6480
- }
6481
- }
6482
- async function saveState(state, statePath = defaultStatePath()) {
6483
- await mkdir2(dirname2(statePath), { recursive: true, mode: 448 });
6484
- await writeFile2(statePath, `${JSON.stringify(state, null, 2)}
6485
- `, { encoding: "utf-8", mode: 384 });
6486
- await chmod2(statePath, 384);
6487
- }
6488
6508
  // src/cli/index.ts
6489
6509
  function version() {
6490
6510
  try {
package/dist/index.js CHANGED
@@ -4099,6 +4099,7 @@ function defaultConfigPath() {
4099
4099
  }
4100
4100
 
4101
4101
  // src/lib/config.ts
4102
+ var REDACTED_VALUE = "[redacted]";
4102
4103
  var channelSchema = exports_external.discriminatedUnion("kind", [
4103
4104
  exports_external.object({
4104
4105
  id: exports_external.string().min(1),
@@ -4186,6 +4187,31 @@ function parseConfig(value) {
4186
4187
  const parsed = configSchema.parse(value);
4187
4188
  return parsed;
4188
4189
  }
4190
+ function redactEnv(env) {
4191
+ if (!env)
4192
+ return;
4193
+ return Object.fromEntries(Object.keys(env).map((key) => [key, REDACTED_VALUE]));
4194
+ }
4195
+ function redactEnvRecord(items) {
4196
+ return Object.fromEntries(Object.entries(items).map(([id, item]) => {
4197
+ const clone = { ...item };
4198
+ if (item.env)
4199
+ clone.env = redactEnv(item.env);
4200
+ return [id, clone];
4201
+ }));
4202
+ }
4203
+ function redactConfig(config) {
4204
+ return {
4205
+ ...config,
4206
+ channels: Object.fromEntries(Object.entries(config.channels).map(([id, channel]) => [id, { ...channel }])),
4207
+ profiles: redactEnvRecord(config.profiles),
4208
+ agents: redactEnvRecord(config.agents),
4209
+ routes: config.routes.map((route) => ({
4210
+ ...route,
4211
+ match: route.match ? { ...route.match, chatIds: route.match.chatIds ? [...route.match.chatIds] : undefined } : undefined
4212
+ }))
4213
+ };
4214
+ }
4189
4215
  async function loadConfig(configPath = defaultConfigPath()) {
4190
4216
  try {
4191
4217
  const raw = await readFile(configPath, "utf-8");
@@ -4234,7 +4260,54 @@ async function upsertRoute(route, configPath = defaultConfigPath()) {
4234
4260
  return config;
4235
4261
  }
4236
4262
  // src/lib/doctor.ts
4237
- import { access } from "fs/promises";
4263
+ import { stat } from "fs/promises";
4264
+
4265
+ // src/lib/state.ts
4266
+ import { chmod as chmod2, mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
4267
+ import { dirname as dirname2, join as join2 } from "path";
4268
+ function defaultStatePath() {
4269
+ return process.env["BRIDGE_STATE"] || join2(bridgeHome(), "state.json");
4270
+ }
4271
+ function emptyState() {
4272
+ return { telegramOffsets: {} };
4273
+ }
4274
+ async function loadState(statePath = defaultStatePath()) {
4275
+ try {
4276
+ const raw = await readFile2(statePath, "utf-8");
4277
+ const parsed = JSON.parse(raw);
4278
+ return {
4279
+ telegramOffsets: parsed.telegramOffsets && typeof parsed.telegramOffsets === "object" ? parsed.telegramOffsets : {}
4280
+ };
4281
+ } catch (err) {
4282
+ if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") {
4283
+ return emptyState();
4284
+ }
4285
+ throw err;
4286
+ }
4287
+ }
4288
+ async function saveState(state, statePath = defaultStatePath()) {
4289
+ await mkdir2(dirname2(statePath), { recursive: true, mode: 448 });
4290
+ await writeFile2(statePath, `${JSON.stringify(state, null, 2)}
4291
+ `, { encoding: "utf-8", mode: 384 });
4292
+ await chmod2(statePath, 384);
4293
+ }
4294
+
4295
+ // src/lib/doctor.ts
4296
+ function isNotFound(err) {
4297
+ return Boolean(err && typeof err === "object" && "code" in err && err.code === "ENOENT");
4298
+ }
4299
+ async function privateFileCheck(name, path) {
4300
+ try {
4301
+ const info = await stat(path);
4302
+ const mode = info.mode & 511;
4303
+ const ok = (mode & 63) === 0;
4304
+ return { name, ok, detail: `${path} mode=${mode.toString(8)}` };
4305
+ } catch (err) {
4306
+ if (isNotFound(err))
4307
+ return { name, ok: true, detail: `not created yet: ${path}` };
4308
+ return { name, ok: false, detail: `${path}: ${err instanceof Error ? err.message : String(err)}` };
4309
+ }
4310
+ }
4238
4311
  async function commandExists(command) {
4239
4312
  const proc = Bun.spawn(["sh", "-lc", `command -v ${command} >/dev/null 2>&1`], {
4240
4313
  stdout: "ignore",
@@ -4242,15 +4315,11 @@ async function commandExists(command) {
4242
4315
  });
4243
4316
  return await proc.exited === 0;
4244
4317
  }
4245
- async function doctor(configPath = defaultConfigPath()) {
4318
+ async function doctor(configPath = defaultConfigPath(), statePath = defaultStatePath()) {
4246
4319
  const checks = [];
4247
4320
  let config = await loadConfig(configPath);
4248
- try {
4249
- await access(configPath);
4250
- checks.push({ name: "config", ok: true, detail: configPath });
4251
- } catch {
4252
- checks.push({ name: "config", ok: true, detail: `not created yet: ${configPath}` });
4253
- }
4321
+ checks.push(await privateFileCheck("config", configPath));
4322
+ checks.push(await privateFileCheck("state", statePath));
4254
4323
  for (const command of ["bridge", "codewith", "claude", "aicopilot"]) {
4255
4324
  checks.push({
4256
4325
  name: `command:${command}`,
@@ -4342,6 +4411,8 @@ function telegramUpdateToMessage(channelId, update) {
4342
4411
  // src/lib/router.ts
4343
4412
  function matchingRoutes(config, message) {
4344
4413
  const channel = config.channels[message.channelId];
4414
+ if (!channel || channel.enabled === false)
4415
+ return [];
4345
4416
  if (channel?.kind === "telegram" && !telegramChatAllowed(channel, message.chatId)) {
4346
4417
  return [];
4347
4418
  }
@@ -4369,6 +4440,10 @@ async function routeMessage(config, message, options = {}) {
4369
4440
  let deliveredResponse = false;
4370
4441
  const channel = responseChannel(config, route, message);
4371
4442
  const responseText = agent.stdout.trim();
4443
+ if (channel?.enabled === false) {
4444
+ results.push({ route, agent, deliveredResponse });
4445
+ continue;
4446
+ }
4372
4447
  if (responseText && channel?.kind === "telegram" && message.chatId) {
4373
4448
  if (!telegramChatAllowed(channel, message.chatId)) {
4374
4449
  results.push({ route, agent, deliveredResponse });
@@ -4385,35 +4460,6 @@ async function routeMessage(config, message, options = {}) {
4385
4460
  }
4386
4461
  return results;
4387
4462
  }
4388
- // src/lib/state.ts
4389
- import { chmod as chmod2, mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
4390
- import { dirname as dirname2, join as join2 } from "path";
4391
- function defaultStatePath() {
4392
- return process.env["BRIDGE_STATE"] || join2(bridgeHome(), "state.json");
4393
- }
4394
- function emptyState() {
4395
- return { telegramOffsets: {} };
4396
- }
4397
- async function loadState(statePath = defaultStatePath()) {
4398
- try {
4399
- const raw = await readFile2(statePath, "utf-8");
4400
- const parsed = JSON.parse(raw);
4401
- return {
4402
- telegramOffsets: parsed.telegramOffsets && typeof parsed.telegramOffsets === "object" ? parsed.telegramOffsets : {}
4403
- };
4404
- } catch (err) {
4405
- if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") {
4406
- return emptyState();
4407
- }
4408
- throw err;
4409
- }
4410
- }
4411
- async function saveState(state, statePath = defaultStatePath()) {
4412
- await mkdir2(dirname2(statePath), { recursive: true, mode: 448 });
4413
- await writeFile2(statePath, `${JSON.stringify(state, null, 2)}
4414
- `, { encoding: "utf-8", mode: 384 });
4415
- await chmod2(statePath, 384);
4416
- }
4417
4463
  export {
4418
4464
  upsertRoute,
4419
4465
  upsertProfile,
@@ -4428,6 +4474,7 @@ export {
4428
4474
  runAgent,
4429
4475
  routeMessage,
4430
4476
  resolveAgent,
4477
+ redactConfig,
4431
4478
  parseConfig,
4432
4479
  matchingRoutes,
4433
4480
  loadState,
@@ -1,6 +1,7 @@
1
1
  import { type AgentConfig, type BridgeConfig, type ChannelConfig, type ProfileConfig, type RouteConfig } from "../types.js";
2
2
  export declare function emptyConfig(): BridgeConfig;
3
3
  export declare function parseConfig(value: unknown): BridgeConfig;
4
+ export declare function redactConfig(config: BridgeConfig): BridgeConfig;
4
5
  export declare function loadConfig(configPath?: string): Promise<BridgeConfig>;
5
6
  export declare function saveConfig(config: BridgeConfig, configPath?: string): Promise<void>;
6
7
  export declare function ensureConfig(configPath?: string): Promise<BridgeConfig>;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAmF5I,wBAAgB,WAAW,IAAI,YAAY,CAQ1C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAGxD;AAED,wBAAsB,UAAU,CAAC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Y,CAAC,CAI1F;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,SAAsB,GAAG,OAAO,CAAC,YAAY,CAAC,CAKnH;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,SAAsB,GAAG,OAAO,CAAC,YAAY,CAAC,CAKnH;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,UAAU,SAAsB,GAAG,OAAO,CAAC,YAAY,CAAC,CAK7G;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,UAAU,SAAsB,GAAG,OAAO,CAAC,YAAY,CAAC,CAK7G"}
@@ -1,3 +1,3 @@
1
1
  import type { DoctorReport } from "../types.js";
2
- export declare function doctor(configPath?: string): Promise<DoctorReport>;
2
+ export declare function doctor(configPath?: string, statePath?: string): Promise<DoctorReport>;
3
3
  //# sourceMappingURL=doctor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/lib/doctor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AAU7D,wBAAsB,MAAM,CAAC,UAAU,SAAsB,GAAG,OAAO,CAAC,YAAY,CAAC,CA2CpF"}
1
+ {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/lib/doctor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AA0B7D,wBAAsB,MAAM,CAAC,UAAU,SAAsB,EAAE,SAAS,SAAqB,GAAG,OAAO,CAAC,YAAY,CAAC,CAuCpH"}
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/lib/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAiB,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAChH,OAAO,EAAE,Q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,CAgChC"}
package/dist/mcp/index.js CHANGED
@@ -4101,6 +4101,7 @@ function defaultConfigPath() {
4101
4101
  }
4102
4102
 
4103
4103
  // src/lib/config.ts
4104
+ var REDACTED_VALUE = "[redacted]";
4104
4105
  var channelSchema = exports_external.discriminatedUnion("kind", [
4105
4106
  exports_external.object({
4106
4107
  id: exports_external.string().min(1),
@@ -4188,6 +4189,31 @@ function parseConfig(value) {
4188
4189
  const parsed = configSchema.parse(value);
4189
4190
  return parsed;
4190
4191
  }
4192
+ function redactEnv(env) {
4193
+ if (!env)
4194
+ return;
4195
+ return Object.fromEntries(Object.keys(env).map((key) => [key, REDACTED_VALUE]));
4196
+ }
4197
+ function redactEnvRecord(items) {
4198
+ return Object.fromEntries(Object.entries(items).map(([id, item]) => {
4199
+ const clone = { ...item };
4200
+ if (item.env)
4201
+ clone.env = redactEnv(item.env);
4202
+ return [id, clone];
4203
+ }));
4204
+ }
4205
+ function redactConfig(config) {
4206
+ return {
4207
+ ...config,
4208
+ channels: Object.fromEntries(Object.entries(config.channels).map(([id, channel]) => [id, { ...channel }])),
4209
+ profiles: redactEnvRecord(config.profiles),
4210
+ agents: redactEnvRecord(config.agents),
4211
+ routes: config.routes.map((route) => ({
4212
+ ...route,
4213
+ match: route.match ? { ...route.match, chatIds: route.match.chatIds ? [...route.match.chatIds] : undefined } : undefined
4214
+ }))
4215
+ };
4216
+ }
4191
4217
  async function loadConfig(configPath = defaultConfigPath()) {
4192
4218
  try {
4193
4219
  const raw = await readFile(configPath, "utf-8");
@@ -4200,7 +4226,30 @@ async function loadConfig(configPath = defaultConfigPath()) {
4200
4226
  }
4201
4227
  }
4202
4228
  // src/lib/doctor.ts
4203
- import { access } from "fs/promises";
4229
+ import { stat } from "fs/promises";
4230
+
4231
+ // src/lib/state.ts
4232
+ import { dirname, join as join2 } from "path";
4233
+ function defaultStatePath() {
4234
+ return process.env["BRIDGE_STATE"] || join2(bridgeHome(), "state.json");
4235
+ }
4236
+
4237
+ // src/lib/doctor.ts
4238
+ function isNotFound(err) {
4239
+ return Boolean(err && typeof err === "object" && "code" in err && err.code === "ENOENT");
4240
+ }
4241
+ async function privateFileCheck(name, path) {
4242
+ try {
4243
+ const info = await stat(path);
4244
+ const mode = info.mode & 511;
4245
+ const ok = (mode & 63) === 0;
4246
+ return { name, ok, detail: `${path} mode=${mode.toString(8)}` };
4247
+ } catch (err) {
4248
+ if (isNotFound(err))
4249
+ return { name, ok: true, detail: `not created yet: ${path}` };
4250
+ return { name, ok: false, detail: `${path}: ${err instanceof Error ? err.message : String(err)}` };
4251
+ }
4252
+ }
4204
4253
  async function commandExists(command) {
4205
4254
  const proc = Bun.spawn(["sh", "-lc", `command -v ${command} >/dev/null 2>&1`], {
4206
4255
  stdout: "ignore",
@@ -4208,15 +4257,11 @@ async function commandExists(command) {
4208
4257
  });
4209
4258
  return await proc.exited === 0;
4210
4259
  }
4211
- async function doctor(configPath = defaultConfigPath()) {
4260
+ async function doctor(configPath = defaultConfigPath(), statePath = defaultStatePath()) {
4212
4261
  const checks = [];
4213
4262
  let config = await loadConfig(configPath);
4214
- try {
4215
- await access(configPath);
4216
- checks.push({ name: "config", ok: true, detail: configPath });
4217
- } catch {
4218
- checks.push({ name: "config", ok: true, detail: `not created yet: ${configPath}` });
4219
- }
4263
+ checks.push(await privateFileCheck("config", configPath));
4264
+ checks.push(await privateFileCheck("state", statePath));
4220
4265
  for (const command of ["bridge", "codewith", "claude", "aicopilot"]) {
4221
4266
  checks.push({
4222
4267
  name: `command:${command}`,
@@ -4279,6 +4324,8 @@ async function sendTelegramMessage(token, chatId, text) {
4279
4324
  // src/lib/router.ts
4280
4325
  function matchingRoutes(config, message) {
4281
4326
  const channel = config.channels[message.channelId];
4327
+ if (!channel || channel.enabled === false)
4328
+ return [];
4282
4329
  if (channel?.kind === "telegram" && !telegramChatAllowed(channel, message.chatId)) {
4283
4330
  return [];
4284
4331
  }
@@ -4306,6 +4353,10 @@ async function routeMessage(config, message, options = {}) {
4306
4353
  let deliveredResponse = false;
4307
4354
  const channel = responseChannel(config, route, message);
4308
4355
  const responseText = agent.stdout.trim();
4356
+ if (channel?.enabled === false) {
4357
+ results.push({ route, agent, deliveredResponse });
4358
+ continue;
4359
+ }
4309
4360
  if (responseText && channel?.kind === "telegram" && message.chatId) {
4310
4361
  if (!telegramChatAllowed(channel, message.chatId)) {
4311
4362
  results.push({ route, agent, deliveredResponse });
@@ -4327,9 +4378,9 @@ function text(value) {
4327
4378
  return { content: [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value, null, 2) }] };
4328
4379
  }
4329
4380
  function buildServer() {
4330
- const server = new McpServer({ name: "bridge", version: "0.1.0" });
4381
+ const server = new McpServer({ name: "bridge", version: "0.1.1" });
4331
4382
  server.tool("bridge_status", {}, async () => text(await doctor()));
4332
- server.tool("bridge_config", {}, async () => text(await loadConfig()));
4383
+ server.tool("bridge_config", {}, async () => text(redactConfig(await loadConfig())));
4333
4384
  server.tool("bridge_route_message", {
4334
4385
  channelId: exports_external.string(),
4335
4386
  text: exports_external.string(),
@@ -43,5 +43,9 @@ Telegram channels fail closed unless `allowedChatIds` are configured or
43
43
  before route matching. Routes can also add narrower `match.chatIds` filters, but
44
44
  they cannot expand beyond the channel allowlist.
45
45
 
46
+ Disabled channels do not match inbound routes and do not deliver responses.
47
+ MCP config inspection redacts profile and agent environment values so local
48
+ secrets are not exposed through `bridge_config`.
49
+
46
50
  Long-poll offsets are persisted in a private state file so process restarts do
47
51
  not replay already-seen updates and re-run agents.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/bridge",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Agent messaging bridge for Telegram and other channels",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "dev:cli": "bun run src/cli/index.ts",
30
30
  "dev:mcp": "bun run src/mcp/index.ts",
31
31
  "prepublishOnly": "bun run build",
32
- "postinstall": "bun -e \"const fs=require('node:fs');const path=require('node:path');const dir=path.join(process.env.HOME||process.cwd(),'.hasna','bridge');fs.mkdirSync(dir,{recursive:true,mode:0o700});try{fs.chmodSync(dir,0o700)}catch{}\""
32
+ "postinstall": "node -e \"const fs=require('node:fs');const path=require('node:path');const dir=path.join(process.env.HOME||process.cwd(),'.hasna','bridge');fs.mkdirSync(dir,{recursive:true,mode:0o700});try{fs.chmodSync(dir,0o700)}catch{}\""
33
33
  },
34
34
  "keywords": [
35
35
  "bridge",