@obtoai/agent-bridge 0.1.0-beta.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 ADDED
@@ -0,0 +1,190 @@
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,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising 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
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 OBTO Inc.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # @obtoai/agent-bridge
2
+
3
+ A local daemon that lets a coding agent — [Claude Code](https://claude.ai/code) or [OpenAI Codex](https://developers.openai.com/codex) — running on your machine be driven from the [OBTO Agent Bridge](https://obto.co) web UI, even when you're away from the keyboard.
4
+
5
+ You post a message on a thread from your phone or laptop. The daemon (running on your Mac, no port forwarding required) receives it over a long-lived HTTPS stream, spawns or resumes an agent session in your project directory, and the response posts back to the bridge thread within seconds.
6
+
7
+ ## Status
8
+
9
+ **Closed beta.** Need an invite? Email **support@obto.co** with your name and a short note about what you'd use it for. We'll provision an account and mail you credentials.
10
+
11
+ ## What you'll need
12
+
13
+ - macOS or Linux, **Node.js 18.17+** (Windows support is in testing)
14
+ - One coding agent installed, with your own auth:
15
+ - **Claude** — Claude Code / the Claude Agent SDK, billed to your Anthropic account; or
16
+ - **Codex** — the `codex` CLI (`npm i -g @openai/codex`), signed in to your OpenAI/ChatGPT account
17
+ - An invite from `support@obto.co` (gives you an `accountId`, browser username/password, and an API token)
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install -g @obtoai/agent-bridge
23
+ ```
24
+
25
+ Or run without installing:
26
+
27
+ ```bash
28
+ npx @obtoai/agent-bridge <command>
29
+ ```
30
+
31
+ ## Setup
32
+
33
+ ```bash
34
+ obto-bridge init
35
+ ```
36
+
37
+ Walks you through a few questions: your account ID, API token, an agent name (to distinguish multiple machines on one account), which coding agent to drive (`claude` or `codex`), the project directory to work in, and whether to relay tool-permission requests via the bridge. (The server URL is a built-in default; advanced / self-hosted users can override it with the `BRIDGE_BASE_URL` env var.)
38
+
39
+ Config lands at `~/.obto-bridge/config.json` (mode 0600). Safe to commit your account ID; **never commit the `apiToken`**.
40
+
41
+ ### claude vs codex
42
+
43
+ Both drive real coding work on your machine; they differ in how they report back:
44
+
45
+ - **claude** — the fuller integration. Posts status updates, questions, and results as it works (via an in-process MCP tool), and supports the human-in-the-loop tool-permission relay.
46
+ - **codex** — runs the task and delivers one final answer per turn. No mid-task updates and no per-tool relay (the Codex SDK exposes neither); it runs unattended inside a sandbox (`workspace-write` by default, override with `BRIDGE_CODEX_SANDBOX`).
47
+
48
+ One daemon drives one agent. To run both, use two daemons on two accounts.
49
+
50
+ ## Run
51
+
52
+ ```bash
53
+ obto-bridge start
54
+ ```
55
+
56
+ You'll see two log lines and then the daemon waits silently:
57
+
58
+ ```
59
+ {"msg":"starting daemon","data":{"accountId":"acc_...","agentId":"my-mac",...}}
60
+ {"msg":"sse stream connected","data":{"status":200}}
61
+ ```
62
+
63
+ Now open the bridge UI in any browser, log in with the browser credentials from your invite, and either:
64
+
65
+ - Reply on an existing thread — daemon resumes the session bound to that thread
66
+ - Start a new thread via the **+ New thread** button — daemon spawns a fresh session in your project directory
67
+
68
+ Within ~5–10 seconds you should see Claude's reply appear back on the thread.
69
+
70
+ ## Other commands
71
+
72
+ | Command | What it does |
73
+ |---|---|
74
+ | `obto-bridge whoami` | Verify your token works + show your account info |
75
+ | `obto-bridge status` | List active thread→session bindings |
76
+ | `obto-bridge logout` | Wipe `~/.obto-bridge/config.json` |
77
+
78
+ ## How it actually works
79
+
80
+ ```
81
+ Your phone OBTO server Your Mac
82
+ ───────── ─────────── ────────
83
+ [reply form] ──► /api/reply ─► Mongo (durable)
84
+ └─► RabbitMQ (publish bridge.<acct>.reply.<thread>)
85
+ ◄── /api/bridge/stream (SSE, Bearer auth)
86
+ └─► daemon process
87
+ └─► Claude Agent SDK
88
+ └─► session JSONL in
89
+ ~/.claude/projects/...
90
+ /api/message ◄──── bridge_post (in-process MCP tool from daemon)
91
+ [poll: /api/messages] ◄──── (4s loop)
92
+ ```
93
+
94
+ Key bits:
95
+
96
+ - The daemon **never** holds RabbitMQ credentials; broker access stays server-side. Per-account routing key isolation enforced by `BridgeAuth`.
97
+ - The daemon's spawned Claude session uses an **in-process MCP server** (`mcp__bridge__bridge_post`) — not the platform's hosted MCP, so the daemon's tools don't depend on a long-lived OBTO MCP proxy session.
98
+ - Each bridge **thread** binds to its own agent **session ID** at first message. Subsequent messages on the same thread resume the same session, so the agent keeps full context. Your interactive sessions are unaffected — they live in separate session stores.
99
+ - Per-thread serialization means rapid bursts on the same thread are handled in order, never racing the same session.
100
+ - With **codex**, there is no in-process MCP tool — the Codex SDK can't auto-approve a write tool when run unattended, so the daemon captures Codex's final response and posts it to the thread on the agent's behalf.
101
+
102
+ ## Agent costs
103
+
104
+ The daemon runs your chosen agent on your machine with **your** credentials — Anthropic for `claude` (whatever Claude Code uses: `ANTHROPIC_API_KEY` or your Claude.ai session), or your OpenAI/ChatGPT account for `codex`. Every bridge-driven turn is a normal API call billed to you. We don't proxy.
105
+
106
+ ## Privacy and what we store
107
+
108
+ - Every message you and the agent post on a thread is stored in OBTO's Mongo. Bridge threads are strictly scoped to your account; we cannot see other tenants' threads.
109
+ - Your daemon's `apiToken` is stored locally only; on the server we store a SHA-256 hash.
110
+ - Right of erasure: email `support@obto.co` to delete your account and all associated messages.
111
+
112
+ ## License
113
+
114
+ Apache-2.0. See [LICENSE](./LICENSE).
115
+
116
+ ## Reporting issues
117
+
118
+ `https://github.com/obto-inc/agent-bridge/issues`
119
+
120
+ Daemon-side issues: please include the relevant section of daemon stdout (it's structured JSON; redact your `apiToken` if it appears).
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const subcommands = {
5
+ init: '../cli/init',
6
+ start: '../cli/start',
7
+ status: '../cli/status',
8
+ whoami: '../cli/whoami',
9
+ logout: '../cli/logout',
10
+ 'rotate-token': '../cli/rotate-token',
11
+ };
12
+
13
+ const usage = () => {
14
+ console.error('Usage: obto-bridge <command>');
15
+ console.error('');
16
+ console.error('Commands:');
17
+ console.error(' init One-time setup: paste credentials, choose agent name + project dir.');
18
+ console.error(' start Run the daemon (foreground).');
19
+ console.error(' status Print active thread/session bindings.');
20
+ console.error(' whoami Verify config and show your account info from the server.');
21
+ console.error(' rotate-token Rotate your API token; old token is invalidated, config is updated.');
22
+ console.error(' logout Wipe local credentials at ~/.obto-bridge/config.json.');
23
+ console.error('');
24
+ console.error('Flags:');
25
+ console.error(' --version, -v Print the installed package version.');
26
+ console.error(' --help, -h Show this help.');
27
+ console.error('');
28
+ console.error('Get an invite: support@obto.co');
29
+ };
30
+
31
+ const cmd = process.argv[2];
32
+
33
+ if (cmd === '--version' || cmd === '-v') {
34
+ const pkg = require('../package.json');
35
+ console.log(pkg.version);
36
+ process.exit(0);
37
+ }
38
+
39
+ const target = subcommands[cmd];
40
+
41
+ if (!target) {
42
+ if (cmd === '--help' || cmd === '-h' || cmd === undefined) {
43
+ usage();
44
+ process.exit(cmd === undefined ? 2 : 0);
45
+ }
46
+ console.error('obto-bridge: unknown command: ' + cmd);
47
+ console.error('');
48
+ usage();
49
+ process.exit(2);
50
+ }
51
+
52
+ require(target);
package/cli/init.js ADDED
@@ -0,0 +1,157 @@
1
+ 'use strict';
2
+
3
+ // `obto-bridge init` — interactive setup wizard. Prompts for credentials,
4
+ // writes ~/.obto-bridge/config.json with mode 0600, then validates the token
5
+ // against the server via GET /api/bridge/whoami so the user knows immediately
6
+ // if anything is wrong.
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const os = require('os');
11
+ const readline = require('readline');
12
+
13
+ const CONFIG_DIR = path.join(os.homedir(), '.obto-bridge');
14
+ const CONFIG_PATH = path.join(CONFIG_DIR, 'config.json');
15
+
16
+ const DEFAULTS = {
17
+ baseUrl: 'https://agent-bridge.obto.co',
18
+ originHost: 'agent-bridge.obto.co',
19
+ relayPermissions: true,
20
+ };
21
+
22
+ const loadExisting = () => {
23
+ try { return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8')); }
24
+ catch (_) { return {}; }
25
+ };
26
+
27
+ const ask = (rl, prompt, def) =>
28
+ new Promise((resolve) => {
29
+ const suffix = def
30
+ ? ' [' + (typeof def === 'string' && def.length > 30 ? def.slice(0, 8) + '…' : def) + ']'
31
+ : '';
32
+ rl.question(prompt + suffix + ': ', (answer) => {
33
+ const v = answer.trim();
34
+ resolve(v || (def != null ? def : ''));
35
+ });
36
+ });
37
+
38
+ const validateAgainstServer = async (cfg) => {
39
+ const url = cfg.baseUrl.replace(/\/$/, '') + '/api/bridge/whoami';
40
+ const res = await fetch(url, {
41
+ method: 'GET',
42
+ headers: {
43
+ Accept: 'application/json',
44
+ 'OBTO-ORIGIN-HOST': cfg.originHost,
45
+ Authorization: 'Bearer ' + cfg.apiToken,
46
+ },
47
+ cache: 'no-store',
48
+ });
49
+ const text = await res.text();
50
+ let parsed;
51
+ try { parsed = JSON.parse(text); } catch (_) { parsed = { _rawBody: text }; }
52
+ return { status: res.status, ok: res.ok, parsed };
53
+ };
54
+
55
+ const main = async () => {
56
+ console.log('OBTO Agent Bridge — setup');
57
+ console.log('-------------------------');
58
+ console.log('Need credentials? Email support@obto.co for an invite.');
59
+ console.log('Config will be written to: ' + CONFIG_PATH);
60
+ console.log('');
61
+
62
+ const existing = loadExisting();
63
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
64
+
65
+ // Server base URL and OBTO-ORIGIN-HOST are constants of the platform, not
66
+ // per-user config — every daemon talks to the same bridge app. They are no
67
+ // longer prompted. Advanced / self-hosted users can still override them via
68
+ // the BRIDGE_BASE_URL / BRIDGE_ORIGIN_HOST env vars or by editing config.json.
69
+ const baseUrl = process.env.BRIDGE_BASE_URL || existing.baseUrl || DEFAULTS.baseUrl;
70
+ const originHost = process.env.BRIDGE_ORIGIN_HOST || existing.originHost || DEFAULTS.originHost;
71
+ const accountId = await ask(rl, 'Account ID (acc_…)', existing.accountId || '');
72
+ const apiToken = await ask(rl, 'API token (obto_…)', existing.apiToken || '');
73
+ const agentId = await ask(rl, 'Agent name (e.g. my-mac)', existing.agentId || os.hostname().split('.')[0] || 'unnamed-agent');
74
+ const projectDir = await ask(rl, 'Project working dir', existing.projectDir || process.cwd());
75
+ const agentAns = await ask(rl, 'Coding agent — claude or codex', existing.agent || 'claude');
76
+ const agent = String(agentAns).trim().toLowerCase() === 'codex' ? 'codex' : 'claude';
77
+ const relayAns = await ask(rl, 'Relay permission requests via bridge? (y/n)', existing.relayPermissions !== false ? 'y' : 'n');
78
+ const relayPermissions = String(relayAns).toLowerCase().startsWith('y');
79
+
80
+ rl.close();
81
+
82
+ if (!accountId || !apiToken) {
83
+ console.error('\nerror: accountId and apiToken are both required.');
84
+ process.exit(1);
85
+ }
86
+ if (!/^acc_[a-z0-9]+$/i.test(accountId)) {
87
+ console.error('\nerror: accountId should look like "acc_xxxxxxxxxxxx".');
88
+ process.exit(1);
89
+ }
90
+ if (!/^obto_[a-z0-9]+$/i.test(apiToken)) {
91
+ console.error('\nerror: apiToken should look like "obto_xxxxxxxxxxxx".');
92
+ process.exit(1);
93
+ }
94
+
95
+ const cfg = {
96
+ baseUrl,
97
+ originHost,
98
+ accountId,
99
+ apiToken,
100
+ agentId,
101
+ agent,
102
+ projectDir: path.resolve(projectDir),
103
+ relayPermissions,
104
+ };
105
+
106
+ try {
107
+ fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
108
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(cfg, null, 2), { mode: 0o600 });
109
+ fs.chmodSync(CONFIG_PATH, 0o600);
110
+ } catch (err) {
111
+ console.error('error: failed to write config: ' + (err && err.message ? err.message : err));
112
+ process.exit(1);
113
+ }
114
+
115
+ console.log('');
116
+ console.log('✓ Config saved to ' + CONFIG_PATH);
117
+
118
+ // Validate against the server. Non-fatal on network failure — user might be
119
+ // offline. Fatal on 401/403 (wrong creds) so they fix it now.
120
+ console.log(' Verifying credentials with ' + baseUrl + ' ...');
121
+ let result;
122
+ try {
123
+ result = await validateAgainstServer(cfg);
124
+ } catch (err) {
125
+ console.warn(' ⚠ could not reach the server: ' + (err && err.message ? err.message : err));
126
+ console.warn(' Config is saved; run `obto-bridge whoami` once you have a network.');
127
+ console.log('');
128
+ console.log('Next: obto-bridge start');
129
+ return;
130
+ }
131
+
132
+ if (result.ok && result.parsed && result.parsed.account) {
133
+ const a = result.parsed.account;
134
+ console.log(' ✓ Authenticated as @' + a.basicAuthUser + ' (' + a.accountId + ', status: ' + a.status + ')');
135
+ console.log('');
136
+ console.log('Next: obto-bridge start');
137
+ return;
138
+ }
139
+
140
+ if (result.status === 401) {
141
+ console.error(' ✗ Server rejected the API token (HTTP 401). Double-check that you pasted the full token from your invite email.');
142
+ process.exit(2);
143
+ }
144
+ if (result.status === 403) {
145
+ console.error(' ✗ Account is suspended (HTTP 403). Contact support@obto.co.');
146
+ process.exit(2);
147
+ }
148
+ console.error(' ✗ Validation failed: HTTP ' + result.status);
149
+ if (result.parsed && result.parsed.error) console.error(' ' + result.parsed.error);
150
+ console.error(' Config is saved at ' + CONFIG_PATH + '; edit it manually or rerun `obto-bridge init`.');
151
+ process.exit(2);
152
+ };
153
+
154
+ main().catch((err) => {
155
+ console.error('init failed: ' + (err && err.message ? err.message : err));
156
+ process.exit(1);
157
+ });
package/cli/logout.js ADDED
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ // `obto-bridge logout` — wipe ~/.obto-bridge/config.json.
4
+ // Does NOT touch ~/.agent-bridge-daemon/ (your thread→session bindings stay,
5
+ // in case you log back into the same account).
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const os = require('os');
10
+
11
+ const CONFIG_PATH = path.join(os.homedir(), '.obto-bridge', 'config.json');
12
+
13
+ try {
14
+ fs.unlinkSync(CONFIG_PATH);
15
+ console.log('✓ Removed ' + CONFIG_PATH);
16
+ } catch (err) {
17
+ if (err && err.code === 'ENOENT') {
18
+ console.log('No config to remove (' + CONFIG_PATH + ' did not exist).');
19
+ } else {
20
+ console.error('logout failed: ' + (err && err.message ? err.message : err));
21
+ process.exit(1);
22
+ }
23
+ }
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ // `obto-bridge rotate-token` — call POST /api/bridge/rotate-token with the
4
+ // current bearer token, update ~/.obto-bridge/config.json with the new one,
5
+ // keep a backup of the previous config at config.json.bak.<unix-ts>.
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const os = require('os');
10
+
11
+ const CONFIG_PATH = path.join(os.homedir(), '.obto-bridge', 'config.json');
12
+
13
+ const main = async () => {
14
+ let raw, cfg;
15
+ try {
16
+ raw = fs.readFileSync(CONFIG_PATH, 'utf8');
17
+ cfg = JSON.parse(raw);
18
+ } catch (err) {
19
+ console.error('error: no config at ' + CONFIG_PATH);
20
+ console.error('Run `obto-bridge init` first.');
21
+ process.exit(1);
22
+ }
23
+ if (!cfg.apiToken || !cfg.baseUrl) {
24
+ console.error('error: config is missing apiToken or baseUrl. Re-run `obto-bridge init`.');
25
+ process.exit(1);
26
+ }
27
+
28
+ const url = cfg.baseUrl.replace(/\/$/, '') + '/api/bridge/rotate-token';
29
+ console.log('Rotating token at ' + url + ' ...');
30
+
31
+ let res;
32
+ try {
33
+ res = await fetch(url, {
34
+ method: 'POST',
35
+ headers: {
36
+ 'Content-Type': 'application/json',
37
+ Accept: 'application/json',
38
+ 'OBTO-ORIGIN-HOST': cfg.originHost || 'ob-agent-bridge.obto.co',
39
+ Authorization: 'Bearer ' + cfg.apiToken,
40
+ },
41
+ body: '{}',
42
+ cache: 'no-store',
43
+ });
44
+ } catch (err) {
45
+ console.error('error: cannot reach the server: ' + (err && err.message ? err.message : err));
46
+ process.exit(2);
47
+ }
48
+
49
+ const text = await res.text();
50
+ let parsed;
51
+ try { parsed = JSON.parse(text); } catch (_) { parsed = { _rawBody: text }; }
52
+
53
+ if (!res.ok || !parsed || !parsed.ok || !parsed.apiToken) {
54
+ console.error('HTTP ' + res.status + ' — rotation failed');
55
+ if (parsed && parsed.error) console.error(' ' + parsed.error);
56
+ if (res.status === 401) {
57
+ console.error('Your current API token is invalid. Email support@obto.co.');
58
+ }
59
+ process.exit(3);
60
+ }
61
+
62
+ // Backup, then atomic-rewrite the config with the new token.
63
+ const newCfg = Object.assign({}, cfg, { apiToken: parsed.apiToken });
64
+ const backup = CONFIG_PATH + '.bak.' + Math.floor(Date.now() / 1000);
65
+ try {
66
+ fs.writeFileSync(backup, raw, { mode: 0o600 });
67
+ const tmp = CONFIG_PATH + '.tmp';
68
+ fs.writeFileSync(tmp, JSON.stringify(newCfg, null, 2), { mode: 0o600 });
69
+ fs.chmodSync(tmp, 0o600);
70
+ fs.renameSync(tmp, CONFIG_PATH);
71
+ } catch (err) {
72
+ console.error('error: rotated successfully on the server but local config update failed:');
73
+ console.error(' ' + (err && err.message ? err.message : err));
74
+ console.error(' Save this new token manually before exiting:');
75
+ console.error(' ' + parsed.apiToken);
76
+ process.exit(4);
77
+ }
78
+
79
+ console.log('✓ Token rotated. Previous config backed up to:');
80
+ console.log(' ' + backup);
81
+ console.log('');
82
+ console.log('If the daemon is running, restart it to pick up the new token.');
83
+ };
84
+
85
+ main().catch((err) => {
86
+ console.error('rotate-token failed: ' + (err && err.message ? err.message : err));
87
+ process.exit(1);
88
+ });
package/cli/start.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ // `obto-bridge start` — just loads the daemon. daemon.js runs on import.
4
+ require('../src/daemon');