@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,173 @@
|
|
|
1
|
+
import { type AccessTokenOptions } from './brainbase-login.js';
|
|
2
|
+
export declare const CLAUDE_CODE_HOOK_CONFIG_SCHEMA = "brainbase-claude-code-judgment-hook-v1";
|
|
3
|
+
export interface ClaudeCodeHookConfig {
|
|
4
|
+
schema_version: typeof CLAUDE_CODE_HOOK_CONFIG_SCHEMA;
|
|
5
|
+
/** Origin of the hosted MCP that serves /host/judgment/hook. */
|
|
6
|
+
origin: string;
|
|
7
|
+
/**
|
|
8
|
+
* Origin of the Brainbase API the person logged in to for this Host. The
|
|
9
|
+
* hook sends the saved login's token only when that login is for this
|
|
10
|
+
* server, so a login to another environment never reaches this Host.
|
|
11
|
+
*/
|
|
12
|
+
login_server: string;
|
|
13
|
+
/** Sent as x-brainbase-project-code. Omit to let the Host decide. */
|
|
14
|
+
project_code?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Repositories to audit, as `host/owner/name` of the origin remote, e.g.
|
|
17
|
+
* `github.com/example-org/app`. The host is compared without case; the
|
|
18
|
+
* path keeps its case, except on hosts whose paths ignore case
|
|
19
|
+
* (`github.com`). Omit to audit every git repository; an empty list audits
|
|
20
|
+
* none.
|
|
21
|
+
*/
|
|
22
|
+
repositories?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* The one registration this config belongs to: a random id, also carried
|
|
25
|
+
* by the registered command, and the Claude Code settings file that holds
|
|
26
|
+
* it. A command with another id (a registration this config was taken
|
|
27
|
+
* from) sends nothing.
|
|
28
|
+
*/
|
|
29
|
+
registration: {
|
|
30
|
+
id: string;
|
|
31
|
+
settings: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export type ClaudeCodeHookPayload = Record<string, unknown>;
|
|
35
|
+
export type ClaudeCodeHookOutput = Record<string, unknown>;
|
|
36
|
+
export interface ClaudeCodeHookOptions {
|
|
37
|
+
env?: NodeJS.ProcessEnv;
|
|
38
|
+
fetch?: typeof fetch;
|
|
39
|
+
/**
|
|
40
|
+
* Overrides how the person token is obtained (tests). A bare string has no
|
|
41
|
+
* login id; a turn opened with one only continues with another bare string.
|
|
42
|
+
*/
|
|
43
|
+
accessToken?: () => Promise<string | PersonToken>;
|
|
44
|
+
credentials?: AccessTokenOptions;
|
|
45
|
+
/** The hook config file; the installer passes it as `--config`. */
|
|
46
|
+
configPath?: string;
|
|
47
|
+
/** The registration id the installer put in the command as `--registration`. */
|
|
48
|
+
registrationId?: string;
|
|
49
|
+
}
|
|
50
|
+
export declare const PRE_TOOL_USE_TOOLS: Set<string>;
|
|
51
|
+
export declare function defaultClaudeCodeHookConfigPath(env?: NodeJS.ProcessEnv): string;
|
|
52
|
+
export declare function readClaudeCodeHookConfig(path: string): ClaudeCodeHookConfig | null;
|
|
53
|
+
/** The hook config held in `text` (a file already read), or null when it is not a usable one. */
|
|
54
|
+
export declare function parseClaudeCodeHookConfig(text: string): ClaudeCodeHookConfig | null;
|
|
55
|
+
/** True when the file holds JSON with this hook config's schema (it was written by the installer). */
|
|
56
|
+
export declare function isClaudeCodeHookConfigFile(path: string): boolean;
|
|
57
|
+
/** True when `text` (a file already read) is JSON with this hook config's schema. */
|
|
58
|
+
export declare function isClaudeCodeHookConfigText(text: string): boolean;
|
|
59
|
+
export declare const REGISTRATION_ID: RegExp;
|
|
60
|
+
/**
|
|
61
|
+
* A repository named in the config: `host/owner/name`. The host is
|
|
62
|
+
* lowercased (host names ignore case). The path keeps its case, except on a
|
|
63
|
+
* host whose paths ignore case. A bare name or `owner/name` is refused,
|
|
64
|
+
* because it would also match a repository of the same name under another
|
|
65
|
+
* owner or host.
|
|
66
|
+
*/
|
|
67
|
+
export declare function normalizeRepositoryEntry(entry: string): string | null;
|
|
68
|
+
/**
|
|
69
|
+
* A `host/owner/name` identifier in its one spelling: the host lowercased,
|
|
70
|
+
* the path lowercased only on a host whose paths ignore case. Nothing is
|
|
71
|
+
* stripped, so an identifier read back from the config stays the same.
|
|
72
|
+
*/
|
|
73
|
+
export declare function canonicalRepositoryIdentifier(entry: string): string | null;
|
|
74
|
+
/**
|
|
75
|
+
* The nearest directory at or above `start` with valid git metadata. The walk
|
|
76
|
+
* starts from the real path: a link inside one checkout that points into
|
|
77
|
+
* another checkout belongs to the checkout it points into, not to the one
|
|
78
|
+
* whose directory holds the link. A start that cannot be resolved gives null,
|
|
79
|
+
* so nothing is sent for it.
|
|
80
|
+
*/
|
|
81
|
+
export declare function findGitRoot(start: string): string | null;
|
|
82
|
+
/** The git directory a linked worktree shares with its main checkout. */
|
|
83
|
+
export declare function gitCommonDir(repoRoot: string): string | null;
|
|
84
|
+
/**
|
|
85
|
+
* `host/owner/name` of a git remote URL (normalized as in the config), or null when the URL has
|
|
86
|
+
* no host or no owner. Accepts https/ssh/git URLs and scp-like `user@host:path`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function repositoryIdentityFromUrl(remote: string): string | null;
|
|
89
|
+
/**
|
|
90
|
+
* The repository a checkout works for: `host/owner/name` of its origin
|
|
91
|
+
* remote, the same for every worktree of one repository. Null without an
|
|
92
|
+
* origin remote whose URL names a host and an owner.
|
|
93
|
+
*/
|
|
94
|
+
export declare function repositoryIdentity(repoRoot: string, env?: NodeJS.ProcessEnv): string | null;
|
|
95
|
+
export interface PersonToken {
|
|
96
|
+
token: string;
|
|
97
|
+
/** The saved login's login_id; the same across renewals of one login. */
|
|
98
|
+
loginId: string | null;
|
|
99
|
+
}
|
|
100
|
+
/** `id` as this registration sends it to the Host. */
|
|
101
|
+
export declare function namespacedId(id: string, config: Pick<ClaudeCodeHookConfig, 'registration'>): string;
|
|
102
|
+
/**
|
|
103
|
+
* Whether the Host can choose the project for this repository from its
|
|
104
|
+
* mapping. Without --project, a repository it cannot look up (a host with a
|
|
105
|
+
* port, a `~` in the path, a very long name) is not sent at all.
|
|
106
|
+
*/
|
|
107
|
+
export declare function hostCanMapRepository(repository: string | null, config: Pick<ClaudeCodeHookConfig, 'project_code'>): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* The Host keeps only digests of a non-Brainbase tool's input, output and
|
|
110
|
+
* error. Sending digests keeps file bodies and command output on this machine.
|
|
111
|
+
* The success fact is kept beside the digest, because a non-empty digest
|
|
112
|
+
* object alone would read as a success.
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* Fields of a Stop input the Host reads. Claude Code also puts the session's
|
|
116
|
+
* background work in a Stop input (`background_tasks[].command`,
|
|
117
|
+
* `session_crons[].prompt`, ...), whose commands and prompts can hold
|
|
118
|
+
* secrets, so a Stop is rebuilt from this list and nothing else is sent.
|
|
119
|
+
*/
|
|
120
|
+
export declare const STOP_FORWARDED_FIELDS: readonly ["hook_event_name", "session_id", "turn_id", "prompt_id", "transcript_path", "cwd", "permission_mode", "model", "last_assistant_message", "stop_hook_active"];
|
|
121
|
+
export declare function forwardedStopPayload(payload: ClaudeCodeHookPayload): ClaudeCodeHookPayload;
|
|
122
|
+
export declare function forwardedToolPayload(payload: ClaudeCodeHookPayload): ClaudeCodeHookPayload;
|
|
123
|
+
/** Handles one Claude Code hook event. Never throws. */
|
|
124
|
+
export declare function handleClaudeCodeJudgmentHook(payload: ClaudeCodeHookPayload, options?: ClaudeCodeHookOptions): Promise<ClaudeCodeHookOutput>;
|
|
125
|
+
export declare const CLAUDE_CODE_HOOK_COMMAND = "judgment:claude-code-hook";
|
|
126
|
+
/** One argument quoted for a POSIX shell (Claude Code runs hook commands with sh). */
|
|
127
|
+
export declare function shellQuote(argument: string): string;
|
|
128
|
+
/**
|
|
129
|
+
* The command the installer registers: node, the CLI, the hook command, the
|
|
130
|
+
* config file and the registration id, each quoted for the shell.
|
|
131
|
+
*/
|
|
132
|
+
export declare function claudeCodeHookCommand(nodePath: string, cliPath: string, configPath: string, registrationId: string): string;
|
|
133
|
+
/**
|
|
134
|
+
* The config path and registration id of a registration this installer
|
|
135
|
+
* wrote, or null for any other hook (a wrapper, or another hook that only
|
|
136
|
+
* mentions the command).
|
|
137
|
+
*/
|
|
138
|
+
export declare function installedHookRegistration(hook: unknown): {
|
|
139
|
+
configPath: string;
|
|
140
|
+
registrationId: string;
|
|
141
|
+
} | null;
|
|
142
|
+
/** The config path of a registration this installer wrote, or null. */
|
|
143
|
+
export declare function installedHookConfigPath(hook: unknown): string | null;
|
|
144
|
+
/**
|
|
145
|
+
* One name for a file however it is reached: the real path, with links in
|
|
146
|
+
* every existing directory followed. For a file that does not exist yet, its
|
|
147
|
+
* nearest existing directory is resolved and the rest appended.
|
|
148
|
+
*/
|
|
149
|
+
export declare function canonicalFilePath(path: string): string;
|
|
150
|
+
/** True when the settings hold a registration this installer wrote for `configPath`. */
|
|
151
|
+
export declare function hasInstalledClaudeCodeHooks(settings: Record<string, unknown>, configPath: string): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* The hook groups one registration adds to Claude Code settings, one per
|
|
154
|
+
* event. A preview shows these, not the settings they go into, which may hold
|
|
155
|
+
* secrets (`env`, `apiKeyHelper`, other hooks' commands).
|
|
156
|
+
*/
|
|
157
|
+
export declare function claudeCodeJudgmentHookGroups(command: string): Array<{
|
|
158
|
+
event: string;
|
|
159
|
+
group: Record<string, unknown>;
|
|
160
|
+
}>;
|
|
161
|
+
/**
|
|
162
|
+
* Claude Code settings with exactly one registration per event for
|
|
163
|
+
* `configPath`, or none with `remove`. Only registrations this installer wrote
|
|
164
|
+
* for the same config file (by any path to it) are replaced; every other hook
|
|
165
|
+
* and setting is kept. The registration ids of the replaced commands are added
|
|
166
|
+
* to `removedIds`.
|
|
167
|
+
*/
|
|
168
|
+
export declare function registerClaudeCodeJudgmentHooks(settings: Record<string, unknown>, { command, configPath, remove, removedIds }: {
|
|
169
|
+
command: string;
|
|
170
|
+
configPath: string;
|
|
171
|
+
remove?: boolean;
|
|
172
|
+
removedIds?: Set<string>;
|
|
173
|
+
}): Record<string, unknown>;
|