@bluenotelogic/harness 0.1.0
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 +215 -0
- package/README.md +123 -0
- package/dist/bundle.d.ts +69 -0
- package/dist/bundle.js +96 -0
- package/dist/bundle.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +340 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth.d.ts +96 -0
- package/dist/oauth.js +345 -0
- package/dist/oauth.js.map +1 -0
- package/dist/writers.d.ts +76 -0
- package/dist/writers.js +190 -0
- package/dist/writers.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2026 Blue Note Logic Inc.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
20
|
+
|
|
21
|
+
1. Definitions.
|
|
22
|
+
|
|
23
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
24
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
25
|
+
|
|
26
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
27
|
+
the copyright owner that is granting the License.
|
|
28
|
+
|
|
29
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
30
|
+
other entities that control, are controlled by, or are under common
|
|
31
|
+
control with that entity. For the purposes of this definition,
|
|
32
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
33
|
+
direction or management of such entity, whether by contract or
|
|
34
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
35
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
36
|
+
|
|
37
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
38
|
+
exercising permissions granted by this License.
|
|
39
|
+
|
|
40
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
41
|
+
including but not limited to software source code, documentation
|
|
42
|
+
source, and configuration files.
|
|
43
|
+
|
|
44
|
+
"Object" form shall mean any form resulting from mechanical
|
|
45
|
+
transformation or translation of a Source form, including but
|
|
46
|
+
not limited to compiled object code, generated documentation,
|
|
47
|
+
and conversions to other media types.
|
|
48
|
+
|
|
49
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
50
|
+
Object form, made available under the License, as indicated by a
|
|
51
|
+
copyright notice that is included in or attached to the work
|
|
52
|
+
(an example is provided in the Appendix below).
|
|
53
|
+
|
|
54
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
55
|
+
form, that is based on (or derived from) the Work and for which the
|
|
56
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
57
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
58
|
+
of this License, Derivative Works shall not include works that remain
|
|
59
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
60
|
+
the Work and Derivative Works thereof.
|
|
61
|
+
|
|
62
|
+
"Contribution" shall mean any work of authorship, including
|
|
63
|
+
the original version of the Work and any modifications or additions
|
|
64
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
65
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
66
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
67
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
68
|
+
means any form of electronic, verbal, or written communication sent
|
|
69
|
+
to the Licensor or its representatives, including but not limited to
|
|
70
|
+
communication on electronic mailing lists, source code control systems,
|
|
71
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
72
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
73
|
+
excluding communication that is conspicuously marked or otherwise
|
|
74
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
75
|
+
|
|
76
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
77
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
78
|
+
subsequently incorporated within the Work.
|
|
79
|
+
|
|
80
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
81
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
84
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
85
|
+
Work and such Derivative Works in Source or Object form.
|
|
86
|
+
|
|
87
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
88
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
89
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
90
|
+
(except as stated in this section) patent license to make, have made,
|
|
91
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
92
|
+
where such license applies only to those patent claims licensable
|
|
93
|
+
by such Contributor that are necessarily infringed by their
|
|
94
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
95
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
96
|
+
institute patent litigation against any entity (including a
|
|
97
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
98
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
99
|
+
or contributory patent infringement, then any patent licenses
|
|
100
|
+
granted to You under this License for that Work shall terminate
|
|
101
|
+
as of the date such litigation is filed.
|
|
102
|
+
|
|
103
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
104
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
105
|
+
modifications, and in Source or Object form, provided that You
|
|
106
|
+
meet the following conditions:
|
|
107
|
+
|
|
108
|
+
(a) You must give any other recipients of the Work or
|
|
109
|
+
Derivative Works a copy of this License; and
|
|
110
|
+
|
|
111
|
+
(b) You must cause any modified files to carry prominent notices
|
|
112
|
+
stating that You changed the files; and
|
|
113
|
+
|
|
114
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
115
|
+
that You distribute, all copyright, patent, trademark, and
|
|
116
|
+
attribution notices from the Source form of the Work,
|
|
117
|
+
excluding those notices that do not pertain to any part of
|
|
118
|
+
the Derivative Works; and
|
|
119
|
+
|
|
120
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
121
|
+
distribution, then any Derivative Works that You distribute must
|
|
122
|
+
include a readable copy of the attribution notices contained
|
|
123
|
+
within such NOTICE file, excluding those notices that do not
|
|
124
|
+
pertain to any part of the Derivative Works, in at least one
|
|
125
|
+
of the following places: within a NOTICE text file distributed
|
|
126
|
+
as part of the Derivative Works; within the Source form or
|
|
127
|
+
documentation, if provided along with the Derivative Works; or,
|
|
128
|
+
within a display generated by the Derivative Works, if and
|
|
129
|
+
wherever such third-party notices normally appear. The contents
|
|
130
|
+
of the NOTICE file are for informational purposes only and
|
|
131
|
+
do not modify the License. You may add Your own attribution
|
|
132
|
+
notices within Derivative Works that You distribute, alongside
|
|
133
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
134
|
+
that such additional attribution notices cannot be construed
|
|
135
|
+
as modifying the License.
|
|
136
|
+
|
|
137
|
+
You may add Your own copyright statement to Your modifications and
|
|
138
|
+
may provide additional or different license terms and conditions
|
|
139
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
140
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
141
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
142
|
+
the conditions stated in this License.
|
|
143
|
+
|
|
144
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
145
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
146
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
147
|
+
this License, without any additional terms or conditions.
|
|
148
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
149
|
+
the terms of any separate license agreement you may have executed
|
|
150
|
+
with Licensor regarding such Contributions.
|
|
151
|
+
|
|
152
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
153
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
154
|
+
except as required for reasonable and customary use in describing the
|
|
155
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
156
|
+
|
|
157
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
158
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
159
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
160
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
161
|
+
implied, including, without limitation, any warranties or conditions
|
|
162
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
163
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
164
|
+
appropriateness of using or redistributing the Work and assume any
|
|
165
|
+
risks associated with Your exercise of permissions under this License.
|
|
166
|
+
|
|
167
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
168
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
169
|
+
unless required by applicable law (such as deliberate and grossly
|
|
170
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
171
|
+
liable to You for damages, including any direct, indirect, special,
|
|
172
|
+
incidental, or consequential damages of any character arising as a
|
|
173
|
+
result of this License or out of the use or inability to use the
|
|
174
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
175
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
176
|
+
other commercial damages or losses), even if such Contributor
|
|
177
|
+
has been advised of the possibility of such damages.
|
|
178
|
+
|
|
179
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
180
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
181
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
182
|
+
or other liability obligations and/or rights consistent with this
|
|
183
|
+
License. However, in accepting such obligations, You may act only
|
|
184
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
185
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
186
|
+
defend, and hold each Contributor harmless for any liability
|
|
187
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
188
|
+
of your accepting any such warranty or additional liability.
|
|
189
|
+
|
|
190
|
+
END OF TERMS AND CONDITIONS
|
|
191
|
+
|
|
192
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
193
|
+
|
|
194
|
+
To apply the Apache License to your work, attach the following
|
|
195
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
196
|
+
replaced with your own identifying information. (Do not include
|
|
197
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
198
|
+
comment syntax for the file format. We also recommend that a
|
|
199
|
+
file or class name and description of purpose be included on the
|
|
200
|
+
same "printed page" as the copyright notice for easier
|
|
201
|
+
identification within third-party archives.
|
|
202
|
+
|
|
203
|
+
Copyright [yyyy] [name of copyright owner]
|
|
204
|
+
|
|
205
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
206
|
+
you may not use this file except in compliance with the License.
|
|
207
|
+
You may obtain a copy of the License at
|
|
208
|
+
|
|
209
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
210
|
+
|
|
211
|
+
Unless required by applicable law or agreed to in writing, software
|
|
212
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
213
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
214
|
+
See the License for the specific language governing permissions and
|
|
215
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @bluenotelogic/harness
|
|
2
|
+
|
|
3
|
+
Point a machine at [Blue Note Memory](https://mem.bnlgit.com) in one command.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @bluenotelogic/harness init
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
That's it. A browser opens, you sign in with your Blue Note Account, and the CLI writes a
|
|
10
|
+
working MCP config into the current repo.
|
|
11
|
+
|
|
12
|
+
## What it writes — and what it deliberately does not
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{ "mcpServers": { "mem": { "type": "http", "url": "https://mem.bnlgit.com/mcp" } } }
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**There is no token in that file.** Claude Code and VS Code discover authentication from the
|
|
19
|
+
endpoint's `401 + WWW-Authenticate`, run the OAuth flow themselves, and store their own
|
|
20
|
+
credentials in their own keychain. So the file is safe to commit, safe to share with a
|
|
21
|
+
teammate, and there is nothing in it to rotate.
|
|
22
|
+
|
|
23
|
+
That is the entire point of this tool. The setup it replaces meant pasting a bearer token by
|
|
24
|
+
hand into `.mcp.json`, `~/.claude.json`, `~/.codex/config.toml` and a VS Code roaming
|
|
25
|
+
profile — and rotating anything meant editing every one of them again.
|
|
26
|
+
|
|
27
|
+
## Codex and CI
|
|
28
|
+
|
|
29
|
+
Those hosts cannot do OAuth yet, so they need a real credential:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx @bluenotelogic/harness init --codex
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The minted token goes to `~/.codex/.env` and is referenced from `config.toml` by name
|
|
36
|
+
(`bearer_token_env_var`), so the config file stays safe to read over someone's shoulder — and
|
|
37
|
+
the token still never touches the repo. Minting is opt-in: without `--codex` or
|
|
38
|
+
`--mint-token`, this CLI creates no credential and no database row.
|
|
39
|
+
|
|
40
|
+
For CI, skip the browser entirely with a token you already hold:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx @bluenotelogic/harness init --token "$BNL_MEMORY_MCP_TOKEN"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Headless machines
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx @bluenotelogic/harness init --device
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Prints a short code and a URL to open on any other device. Standard RFC 8628 device flow.
|
|
53
|
+
|
|
54
|
+
## Options
|
|
55
|
+
|
|
56
|
+
| Flag | Effect |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `--dry-run` | Show every file that would change, write nothing |
|
|
59
|
+
| `--url <base>` | Point at a self-hosted deployment (default `https://mem.bnlgit.com`) |
|
|
60
|
+
| `--dir <path>` | Repo to configure (default: current directory) |
|
|
61
|
+
| `--device` | Device-code login for headless boxes and SSH sessions |
|
|
62
|
+
| `--token <token>` | Use an existing token instead of logging in |
|
|
63
|
+
| `--mint-token` | Also mint a token for hosts that cannot do OAuth |
|
|
64
|
+
| `--codex` | Configure Codex too (implies `--mint-token`) |
|
|
65
|
+
| `--harness-home <dir>` | Materialize hosted model routing into `<dir>/state/routing/` |
|
|
66
|
+
| `--server-name <name>` | Override the MCP server key written into `.mcp.json` |
|
|
67
|
+
| `--no-browser` | Print the login URL instead of opening a browser |
|
|
68
|
+
|
|
69
|
+
Run `--dry-run` first if you like seeing before you commit. It prints the full contents of
|
|
70
|
+
every file it would touch.
|
|
71
|
+
|
|
72
|
+
## It will not clobber your config
|
|
73
|
+
|
|
74
|
+
Every write reads what is already on disk and replaces **only** the keys it owns. An
|
|
75
|
+
unrelated MCP server in your `.mcp.json` survives untouched; so do unrelated top-level keys,
|
|
76
|
+
your Codex settings, and any hooks in `.claude/settings.local.json`.
|
|
77
|
+
|
|
78
|
+
If a file is not valid JSON, the CLI reports it and **leaves it exactly as it found it** —
|
|
79
|
+
"it looked broken" is precisely when someone's half-finished hand edit is sitting in it.
|
|
80
|
+
|
|
81
|
+
This is not theoretical caution. The shell script this replaces once overwrote three
|
|
82
|
+
`.mcp.json` files that defined unrelated servers; two were recoverable from git and one was
|
|
83
|
+
not. `test/writers.test.js` pins that behaviour so it cannot happen again.
|
|
84
|
+
|
|
85
|
+
## How it works
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
OAuth 2.1 + PKCE ──▶ Blue Note ID (identity: who are you)
|
|
89
|
+
│
|
|
90
|
+
▼
|
|
91
|
+
POST /api/oidc_exchange.php (product: do you have a subscription)
|
|
92
|
+
│
|
|
93
|
+
▼
|
|
94
|
+
GET /api/harness_bootstrap.php (config: what should this machine use)
|
|
95
|
+
│
|
|
96
|
+
▼
|
|
97
|
+
.mcp.json, routing YAML, optional Codex config
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Identity and entitlement are separate on purpose. A Blue Note Account authenticates a person;
|
|
101
|
+
it does not by itself grant memory access. If you sign in successfully but hold no
|
|
102
|
+
subscription you get a clear message saying exactly that, rather than a login error that
|
|
103
|
+
sends you looking in the wrong place.
|
|
104
|
+
|
|
105
|
+
## Requirements
|
|
106
|
+
|
|
107
|
+
Node 20 or newer. **No runtime dependencies** — PKCE, the loopback listener and the HTTP
|
|
108
|
+
client are all Node built-ins, so `npx` is fast and there is no dependency tree to audit.
|
|
109
|
+
|
|
110
|
+
## Development
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm install
|
|
114
|
+
npm test # builds, then runs the suite
|
|
115
|
+
npm run lint # tsc --noEmit
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Licence
|
|
119
|
+
|
|
120
|
+
Apache-2.0 — © 2026 Blue Note Logic Inc. See [LICENSE](LICENSE).
|
|
121
|
+
|
|
122
|
+
This CLI is free and open source. It configures a machine to talk to Blue Note
|
|
123
|
+
Memory; a Blue Note Memory subscription is a separate commercial product.
|
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetching the harness bootstrap bundle.
|
|
3
|
+
*
|
|
4
|
+
* THE TWO-STEP THAT IS EASY TO GET WRONG: `/api/harness_bootstrap.php` authenticates with
|
|
5
|
+
* `authenticateTenantToken()`, so it does NOT accept a Blue Note ID access token. The OAuth
|
|
6
|
+
* token has to be traded for a caveauMEM tenant token first:
|
|
7
|
+
*
|
|
8
|
+
* Blue Note ID access token
|
|
9
|
+
* -> POST /api/oidc_exchange.php (PHP resolves identity -> tenant, the same
|
|
10
|
+
* BlueNoteLink::resolve() the browser login uses)
|
|
11
|
+
* -> cmem_… tenant token (short-lived, ~1h)
|
|
12
|
+
* -> GET /api/harness_bootstrap.php
|
|
13
|
+
*
|
|
14
|
+
* Tenancy deliberately stays in PHP: the MCP shim cannot see the database, and one place
|
|
15
|
+
* should decide who gets in. A 403 from the exchange is a PRODUCT answer ("authenticated,
|
|
16
|
+
* but no memory subscription"), not an auth failure, and must be reported as such — telling
|
|
17
|
+
* someone their login failed when their billing lapsed sends them to the wrong place.
|
|
18
|
+
*
|
|
19
|
+
* Note the paths: Apache aliases `/api` to `api/v1`, so the live URL is
|
|
20
|
+
* `/api/oidc_exchange.php`, NOT `/api/v1/oidc_exchange.php`.
|
|
21
|
+
*/
|
|
22
|
+
export interface HarnessBundle {
|
|
23
|
+
version: number;
|
|
24
|
+
generated_at?: string;
|
|
25
|
+
endpoint: {
|
|
26
|
+
mcp_url: string;
|
|
27
|
+
base_url: string;
|
|
28
|
+
resource_metadata?: string;
|
|
29
|
+
};
|
|
30
|
+
tenant: {
|
|
31
|
+
id: number;
|
|
32
|
+
slug: string;
|
|
33
|
+
};
|
|
34
|
+
mcp_json: {
|
|
35
|
+
mcpServers: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
routing?: {
|
|
38
|
+
providers_yaml?: string;
|
|
39
|
+
profiles_yaml?: string;
|
|
40
|
+
default_profile?: string;
|
|
41
|
+
source?: string;
|
|
42
|
+
};
|
|
43
|
+
auth?: {
|
|
44
|
+
preferred?: string;
|
|
45
|
+
oauth_hosts?: string[];
|
|
46
|
+
token_hosts?: string[];
|
|
47
|
+
note?: string;
|
|
48
|
+
};
|
|
49
|
+
token?: {
|
|
50
|
+
value: string;
|
|
51
|
+
label?: string;
|
|
52
|
+
usage?: string;
|
|
53
|
+
codex_toml?: string;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** The bundle shape this CLI understands. Refuse a newer one rather than half-apply it. */
|
|
57
|
+
export declare const SUPPORTED_BUNDLE_VERSION = 1;
|
|
58
|
+
export declare class SubscriptionRequiredError extends Error {
|
|
59
|
+
}
|
|
60
|
+
export declare function exchangeForTenantToken(baseUrl: string, accessToken: string): Promise<string>;
|
|
61
|
+
export declare function fetchBundle(baseUrl: string, tenantToken: string, opts?: {
|
|
62
|
+
mintToken?: boolean;
|
|
63
|
+
}): Promise<HarnessBundle>;
|
|
64
|
+
/**
|
|
65
|
+
* Validate before writing anything. Every field below is dereferenced by a writer, and a
|
|
66
|
+
* half-written config is worse than none — better to fail with a clear message than to
|
|
67
|
+
* leave a `.mcp.json` pointing at `undefined`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function validateBundle(raw: unknown): HarnessBundle;
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetching the harness bootstrap bundle.
|
|
3
|
+
*
|
|
4
|
+
* THE TWO-STEP THAT IS EASY TO GET WRONG: `/api/harness_bootstrap.php` authenticates with
|
|
5
|
+
* `authenticateTenantToken()`, so it does NOT accept a Blue Note ID access token. The OAuth
|
|
6
|
+
* token has to be traded for a caveauMEM tenant token first:
|
|
7
|
+
*
|
|
8
|
+
* Blue Note ID access token
|
|
9
|
+
* -> POST /api/oidc_exchange.php (PHP resolves identity -> tenant, the same
|
|
10
|
+
* BlueNoteLink::resolve() the browser login uses)
|
|
11
|
+
* -> cmem_… tenant token (short-lived, ~1h)
|
|
12
|
+
* -> GET /api/harness_bootstrap.php
|
|
13
|
+
*
|
|
14
|
+
* Tenancy deliberately stays in PHP: the MCP shim cannot see the database, and one place
|
|
15
|
+
* should decide who gets in. A 403 from the exchange is a PRODUCT answer ("authenticated,
|
|
16
|
+
* but no memory subscription"), not an auth failure, and must be reported as such — telling
|
|
17
|
+
* someone their login failed when their billing lapsed sends them to the wrong place.
|
|
18
|
+
*
|
|
19
|
+
* Note the paths: Apache aliases `/api` to `api/v1`, so the live URL is
|
|
20
|
+
* `/api/oidc_exchange.php`, NOT `/api/v1/oidc_exchange.php`.
|
|
21
|
+
*/
|
|
22
|
+
/** The bundle shape this CLI understands. Refuse a newer one rather than half-apply it. */
|
|
23
|
+
export const SUPPORTED_BUNDLE_VERSION = 1;
|
|
24
|
+
export class SubscriptionRequiredError extends Error {
|
|
25
|
+
}
|
|
26
|
+
export async function exchangeForTenantToken(baseUrl, accessToken) {
|
|
27
|
+
const res = await fetch(`${baseUrl}/api/oidc_exchange.php`, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: { authorization: `Bearer ${accessToken}`, accept: "application/json" },
|
|
30
|
+
});
|
|
31
|
+
if (res.status === 403) {
|
|
32
|
+
const body = (await res.json().catch(() => ({})));
|
|
33
|
+
throw new SubscriptionRequiredError(String(body["error"] ?? "This Blue Note Account has no Blue Note Memory subscription"));
|
|
34
|
+
}
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
throw new Error(`token exchange failed: ${res.status} ${await snippet(res)}`);
|
|
37
|
+
}
|
|
38
|
+
const body = (await res.json());
|
|
39
|
+
const token = body["token"];
|
|
40
|
+
if (typeof token !== "string" || token === "") {
|
|
41
|
+
throw new Error("token exchange returned no token");
|
|
42
|
+
}
|
|
43
|
+
return token;
|
|
44
|
+
}
|
|
45
|
+
export async function fetchBundle(baseUrl, tenantToken, opts = {}) {
|
|
46
|
+
const url = new URL(`${baseUrl}/api/harness_bootstrap.php`);
|
|
47
|
+
if (opts.mintToken)
|
|
48
|
+
url.searchParams.set("mint_token", "1");
|
|
49
|
+
const res = await fetch(url, {
|
|
50
|
+
headers: { authorization: `Bearer ${tenantToken}`, accept: "application/json" },
|
|
51
|
+
});
|
|
52
|
+
if (!res.ok) {
|
|
53
|
+
throw new Error(`bootstrap fetch failed: ${res.status} ${await snippet(res)}`);
|
|
54
|
+
}
|
|
55
|
+
return validateBundle(await res.json());
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Validate before writing anything. Every field below is dereferenced by a writer, and a
|
|
59
|
+
* half-written config is worse than none — better to fail with a clear message than to
|
|
60
|
+
* leave a `.mcp.json` pointing at `undefined`.
|
|
61
|
+
*/
|
|
62
|
+
export function validateBundle(raw) {
|
|
63
|
+
if (typeof raw !== "object" || raw === null)
|
|
64
|
+
throw new Error("bootstrap response was not an object");
|
|
65
|
+
const b = raw;
|
|
66
|
+
const version = Number(b["version"] ?? 0);
|
|
67
|
+
if (!Number.isFinite(version) || version < 1)
|
|
68
|
+
throw new Error("bootstrap response has no version");
|
|
69
|
+
if (version > SUPPORTED_BUNDLE_VERSION) {
|
|
70
|
+
throw new Error(`this server speaks bundle version ${version}; this CLI understands ${SUPPORTED_BUNDLE_VERSION}. ` +
|
|
71
|
+
`Upgrade with: npm i -g @bluenotelogic/harness@latest`);
|
|
72
|
+
}
|
|
73
|
+
const endpoint = b["endpoint"];
|
|
74
|
+
const mcpUrl = endpoint && endpoint["mcp_url"];
|
|
75
|
+
if (typeof mcpUrl !== "string" || !/^https?:\/\//.test(mcpUrl)) {
|
|
76
|
+
throw new Error("bootstrap response has no usable endpoint.mcp_url");
|
|
77
|
+
}
|
|
78
|
+
const mcpJson = b["mcp_json"];
|
|
79
|
+
const servers = mcpJson && mcpJson["mcpServers"];
|
|
80
|
+
if (typeof servers !== "object" || servers === null || Array.isArray(servers)) {
|
|
81
|
+
throw new Error("bootstrap response has no mcp_json.mcpServers object");
|
|
82
|
+
}
|
|
83
|
+
if (Object.keys(servers).length === 0) {
|
|
84
|
+
throw new Error("bootstrap response returned an empty mcp_json.mcpServers");
|
|
85
|
+
}
|
|
86
|
+
return raw;
|
|
87
|
+
}
|
|
88
|
+
async function snippet(res) {
|
|
89
|
+
try {
|
|
90
|
+
return (await res.text()).slice(0, 300);
|
|
91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
|
|
2
|
+
/**
|
|
3
|
+
* bnl-harness — point this machine at Blue Note Memory in one command.
|
|
4
|
+
*
|
|
5
|
+
* npx @bluenotelogic/harness init
|
|
6
|
+
*
|
|
7
|
+
* THE PROBLEM THIS SOLVES: configuring a machine used to mean pasting a bearer token by
|
|
8
|
+
* hand into `.mcp.json`, `~/.claude.json`, `~/.codex/config.toml` and a VS Code roaming
|
|
9
|
+
* profile — and rotating anything meant editing every one of them again.
|
|
10
|
+
*
|
|
11
|
+
* THE IMPORTANT PART — the `.mcp.json` this writes carries NO TOKEN:
|
|
12
|
+
*
|
|
13
|
+
* { "mcpServers": { "mem": { "type": "http", "url": "https://mem.bnlgit.com/mcp" } } }
|
|
14
|
+
*
|
|
15
|
+
* OAuth-capable hosts (Claude Code, VS Code) discover auth from the endpoint's 401 +
|
|
16
|
+
* WWW-Authenticate, run the browser flow against Blue Note ID, and store their own
|
|
17
|
+
* credentials. Nothing secret is written into a repo file, so the file is safe to commit
|
|
18
|
+
* and there is nothing to rotate.
|
|
19
|
+
*
|
|
20
|
+
* Codex and CI cannot do that yet, so `--mint-token` exists for them — and it writes the
|
|
21
|
+
* token to `~/.codex/.env`, never into a repo. Minting is OPT-IN precisely so the default
|
|
22
|
+
* path creates no credential and no database row.
|
|
23
|
+
*/
|
|
24
|
+
export {};
|