@unson/brainbase-mcp 0.50.24 → 0.50.26
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/contracts/brainbase-public-contract.v1.json +4 -0
- package/dist/brainbase-login.d.ts +238 -0
- package/dist/brainbase-login.js +1345 -0
- package/dist/claude-code-judgment-hook.d.ts +173 -0
- package/dist/claude-code-judgment-hook.js +1003 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +714 -9
- package/dist/judgment-journal-turn-publisher.js +14 -5
- package/package.json +10 -2
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
export declare const CREDENTIALS_SCHEMA_VERSION = "brainbase-credentials-v1";
|
|
2
|
+
export interface BrainbaseCredentials {
|
|
3
|
+
schema_version: typeof CREDENTIALS_SCHEMA_VERSION;
|
|
4
|
+
/**
|
|
5
|
+
* Random id of the `brainbase login` that produced this file. A renewal
|
|
6
|
+
* keeps it; a new login replaces it. A renewal only writes back over the
|
|
7
|
+
* same login, so a logout or a switch to another account is never undone.
|
|
8
|
+
*/
|
|
9
|
+
login_id: string;
|
|
10
|
+
server_url: string;
|
|
11
|
+
access_token: string;
|
|
12
|
+
refresh_token?: string;
|
|
13
|
+
/** ISO time at which the access token stops being accepted. */
|
|
14
|
+
expires_at: string;
|
|
15
|
+
}
|
|
16
|
+
export interface DeviceAuthorizationPrompt {
|
|
17
|
+
verificationUri: string;
|
|
18
|
+
verificationUriComplete?: string;
|
|
19
|
+
userCode?: string;
|
|
20
|
+
expiresInSeconds: number;
|
|
21
|
+
}
|
|
22
|
+
type FetchLike = typeof fetch;
|
|
23
|
+
export interface LoginOptions {
|
|
24
|
+
serverUrl: string;
|
|
25
|
+
credentialsPath?: string;
|
|
26
|
+
fetch?: FetchLike;
|
|
27
|
+
now?: () => number;
|
|
28
|
+
sleep?: (ms: number) => Promise<void>;
|
|
29
|
+
onPrompt: (prompt: DeviceAuthorizationPrompt) => void;
|
|
30
|
+
onWaiting?: () => void;
|
|
31
|
+
}
|
|
32
|
+
export interface AccessTokenOptions {
|
|
33
|
+
credentialsPath?: string;
|
|
34
|
+
fetch?: FetchLike;
|
|
35
|
+
now?: () => number;
|
|
36
|
+
/** Renew when the token expires within this many milliseconds. */
|
|
37
|
+
refreshSkewMs?: number;
|
|
38
|
+
}
|
|
39
|
+
export declare class BrainbaseLoginError extends Error {
|
|
40
|
+
readonly code: string;
|
|
41
|
+
constructor(code: string, message?: string);
|
|
42
|
+
}
|
|
43
|
+
export declare function defaultCredentialsPath(env?: NodeJS.ProcessEnv): string;
|
|
44
|
+
/**
|
|
45
|
+
* The server URL a person typed, reduced to its origin. A bearer token is only
|
|
46
|
+
* ever sent over HTTPS, or over HTTP to this machine's loopback address.
|
|
47
|
+
*/
|
|
48
|
+
export declare function normalizeServerUrl(value: string): string;
|
|
49
|
+
/** The `exp` claim of a JWT, read without verifying it (the server verifies). */
|
|
50
|
+
export declare function jwtExpiryMs(token: string): number | undefined;
|
|
51
|
+
export declare function readCredentials(path?: string): Promise<BrainbaseCredentials | null>;
|
|
52
|
+
export declare function newLoginId(): string;
|
|
53
|
+
/**
|
|
54
|
+
* The saved login is a file, so its path must name one. `dir/` or `dir/.`
|
|
55
|
+
* would otherwise lose its last part in dirname()/basename() and point at a
|
|
56
|
+
* different file (logout would delete `dir`'s neighbour). Refused before any
|
|
57
|
+
* lock or file is touched.
|
|
58
|
+
*/
|
|
59
|
+
export declare function assertCredentialsFilePath(path: string): void;
|
|
60
|
+
/** What the lock holder found left by a save or logout that stopped half way. */
|
|
61
|
+
export interface InterruptedWork {
|
|
62
|
+
/** A logout had moved the saved login aside: it was deleted now. */
|
|
63
|
+
logoutFinished: boolean;
|
|
64
|
+
/** A save had moved the saved login aside and placed nothing: it was put back. */
|
|
65
|
+
saveRolledBack: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Where a save goes, resolved once: the physical file (see physicalPath) and
|
|
69
|
+
* which folder holds it. A later lock taken with this destination refuses to
|
|
70
|
+
* act on any other file or folder, so a folder on the path swapped for a link
|
|
71
|
+
* (or for another folder) in between is caught instead of followed.
|
|
72
|
+
*/
|
|
73
|
+
export interface CredentialsDestination {
|
|
74
|
+
readonly target: string;
|
|
75
|
+
readonly folder: FolderIdentity;
|
|
76
|
+
}
|
|
77
|
+
/** Which folder sits at a path: same values = the same folder. */
|
|
78
|
+
export interface FolderIdentity {
|
|
79
|
+
readonly dev: bigint;
|
|
80
|
+
readonly ino: bigint;
|
|
81
|
+
}
|
|
82
|
+
export interface CredentialsTargetCheck {
|
|
83
|
+
/** The file and folder the save must go to; pass it to withCredentialsLock. */
|
|
84
|
+
destination: CredentialsDestination;
|
|
85
|
+
/**
|
|
86
|
+
* Which saved login is there now (see SavedLoginKey); pass it to
|
|
87
|
+
* writeCredentials as `expected`, so the save replaces only that login.
|
|
88
|
+
*/
|
|
89
|
+
saved: SavedLoginKey;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Fails before anything is asked of the server or of the person when a login
|
|
93
|
+
* could not be saved to `path`: the file there is not a saved login, or the
|
|
94
|
+
* lock cannot be taken because something that is no brainbase lock is in its
|
|
95
|
+
* way. Returns where the save goes and which login is there, so the save
|
|
96
|
+
* after the approval goes to the same file and replaces the same login.
|
|
97
|
+
*/
|
|
98
|
+
export declare function checkCredentialsTarget(path: string): Promise<CredentialsTargetCheck>;
|
|
99
|
+
export interface WriteCredentialsOptions {
|
|
100
|
+
/**
|
|
101
|
+
* The lock this write runs under. The file it locked (lock.target) is the
|
|
102
|
+
* one written, `path` must name that same file, and the lock is checked to
|
|
103
|
+
* be still held, and to still lock that file, right before it is replaced.
|
|
104
|
+
* Without a lock, the write takes one itself: every save runs under the lock.
|
|
105
|
+
*/
|
|
106
|
+
lock?: CredentialsLock;
|
|
107
|
+
/**
|
|
108
|
+
* The saved login that may be replaced (see SavedLoginKey): null for "no
|
|
109
|
+
* file there". Checked on the file itself right before it is replaced, so
|
|
110
|
+
* a login saved by anyone else since the caller looked is never overwritten
|
|
111
|
+
* (`login_changed`). Left out, any saved brainbase login may be replaced.
|
|
112
|
+
*/
|
|
113
|
+
expected?: SavedLoginKey;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Writes the file atomically: data and rename are flushed to disk, and so are
|
|
117
|
+
* the directories above it that hold this user's entries, before this
|
|
118
|
+
* returns. A new file is 0600, a new directory 0700. `durable` is false when
|
|
119
|
+
* the platform could not flush a directory, so the file may not survive a
|
|
120
|
+
* crash; a real I/O error is thrown instead.
|
|
121
|
+
*/
|
|
122
|
+
export declare function writeCredentials(path: string, credentials: BrainbaseCredentials, options?: WriteCredentialsOptions): Promise<{
|
|
123
|
+
durable: boolean;
|
|
124
|
+
}>;
|
|
125
|
+
export interface CredentialsLock {
|
|
126
|
+
/**
|
|
127
|
+
* The saved-login file this lock covers, resolved once when the lock was
|
|
128
|
+
* taken (see physicalPath). Everything done under the lock reads, writes and
|
|
129
|
+
* removes this path, not a new resolution of the path it was asked for.
|
|
130
|
+
*/
|
|
131
|
+
readonly target: string;
|
|
132
|
+
/** lock.target with the folder that held it when the lock was taken. */
|
|
133
|
+
readonly destination: CredentialsDestination;
|
|
134
|
+
/**
|
|
135
|
+
* What a save or logout that stopped half way had left, and was finished or
|
|
136
|
+
* rolled back right after this lock was taken (see finishInterrupted).
|
|
137
|
+
*/
|
|
138
|
+
readonly interrupted: InterruptedWork;
|
|
139
|
+
/**
|
|
140
|
+
* Fails with `login_lock_lost` when the lock file no longer carries this
|
|
141
|
+
* holder's id, and with `login_changed` when the path the lock was taken for
|
|
142
|
+
* now leads to another directory (a folder on it was replaced by a link or
|
|
143
|
+
* by another folder).
|
|
144
|
+
*/
|
|
145
|
+
assertHeld(): Promise<void>;
|
|
146
|
+
}
|
|
147
|
+
export interface LockTiming {
|
|
148
|
+
/** How long to wait for another holder before failing with `login_busy`. */
|
|
149
|
+
waitMs: number;
|
|
150
|
+
/** Appended to the real path of the locked file to name the lock (default `.lock`). */
|
|
151
|
+
suffix?: string;
|
|
152
|
+
}
|
|
153
|
+
export interface LockOptions extends LockTiming {
|
|
154
|
+
/**
|
|
155
|
+
* Where an earlier check resolved the path to (checkCredentialsTarget). The
|
|
156
|
+
* lock is then taken only when the path still leads to that same file in
|
|
157
|
+
* that same folder, and fails with `login_changed` otherwise: the work
|
|
158
|
+
* under the lock never moves to a file the earlier check did not see.
|
|
159
|
+
*/
|
|
160
|
+
destination?: CredentialsDestination;
|
|
161
|
+
/**
|
|
162
|
+
* Whether taking the lock first finishes or rolls back a save or logout of
|
|
163
|
+
* a login that stopped half way (finishInterrupted; default true). A lock
|
|
164
|
+
* on a file that is no saved login, such as the Claude Code settings that
|
|
165
|
+
* judgment:install locks, passes false: it never moves or deletes the
|
|
166
|
+
* files next to that path.
|
|
167
|
+
*/
|
|
168
|
+
recover?: boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Fails with `login_storage_unsupported` when the folder of `path` cannot hold
|
|
172
|
+
* the lock, before anything is asked of the server or of the person.
|
|
173
|
+
*/
|
|
174
|
+
export declare function checkCredentialsStorage(path: string): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Serialises changes to the credentials file between processes on this
|
|
177
|
+
* machine: login, logout, and a renewal from its request to its write-back.
|
|
178
|
+
* The lock file holds the holder's random id, process id and host name. It is
|
|
179
|
+
* held until the holder removes it: another process only removes it when the
|
|
180
|
+
* holder's process no longer runs, so the lock covers every read, write and
|
|
181
|
+
* removal of the credentials file done under it.
|
|
182
|
+
*/
|
|
183
|
+
export declare function withCredentialsLock<T>(path: string, task: (lock: CredentialsLock) => Promise<T>, timing?: Partial<LockOptions>): Promise<T>;
|
|
184
|
+
export interface RemoveCredentialsResult {
|
|
185
|
+
/** A saved login was there. */
|
|
186
|
+
existed: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* The removal is flushed to disk. False only where the platform cannot
|
|
189
|
+
* flush a directory; a real I/O error is thrown instead.
|
|
190
|
+
*/
|
|
191
|
+
durable: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Which saved login a file holds, to tell whether it is still the same one:
|
|
195
|
+
* `login:<login_id>` for a saved login (a renewal keeps it, any new login
|
|
196
|
+
* gets a new one), `file:<sha256>` for a saved login too broken to carry a
|
|
197
|
+
* login_id, null for no file.
|
|
198
|
+
*/
|
|
199
|
+
export type SavedLoginKey = string | null;
|
|
200
|
+
/** The SavedLoginKey of a login: equal for the login and its renewals. */
|
|
201
|
+
export declare function loginKeyOf(credentials: BrainbaseCredentials): SavedLoginKey;
|
|
202
|
+
/**
|
|
203
|
+
* Removes the saved login and flushes the directory that held it, under the
|
|
204
|
+
* lock, before this returns. Without the flush, a power loss right after a
|
|
205
|
+
* logout could bring the old login back. The directory is flushed even when
|
|
206
|
+
* no file was there, since an earlier logout may have stopped before its flush.
|
|
207
|
+
* Only a file that is a saved login is removed (see savedLoginKey); any other
|
|
208
|
+
* file is left as it is and `login_credentials_unrecognized` is thrown.
|
|
209
|
+
*/
|
|
210
|
+
export declare function removeCredentials(path?: string): Promise<RemoveCredentialsResult>;
|
|
211
|
+
/**
|
|
212
|
+
* Runs the Device Code Flow against `serverUrl` and saves the person token.
|
|
213
|
+
* Asks for a receipt so the server issues the token once and forgets it only
|
|
214
|
+
* after this machine has stored it.
|
|
215
|
+
*/
|
|
216
|
+
export declare function loginWithDeviceCode(options: LoginOptions): Promise<BrainbaseCredentials>;
|
|
217
|
+
/**
|
|
218
|
+
* The person token for this machine, renewed first when it is about to expire.
|
|
219
|
+
* Fails with a `login_*` code when there is no usable login.
|
|
220
|
+
*
|
|
221
|
+
* A renewal holds the credentials lock from its request to its write-back, so
|
|
222
|
+
* two renewals never race on a rotating refresh token, and a logout or another
|
|
223
|
+
* login waits for it and then wins.
|
|
224
|
+
*/
|
|
225
|
+
export declare function getAccessToken(options?: AccessTokenOptions): Promise<{
|
|
226
|
+
token: string;
|
|
227
|
+
serverUrl: string;
|
|
228
|
+
}>;
|
|
229
|
+
/**
|
|
230
|
+
* getAccessToken, with the saved login's login_id. A renewal keeps the
|
|
231
|
+
* login_id; another `brainbase login` (as anyone) gets a new one.
|
|
232
|
+
*/
|
|
233
|
+
export declare function getAccessTokenOfLogin(options?: AccessTokenOptions): Promise<{
|
|
234
|
+
token: string;
|
|
235
|
+
serverUrl: string;
|
|
236
|
+
loginId: string;
|
|
237
|
+
}>;
|
|
238
|
+
export {};
|