@unson/brainbase-mcp 0.50.28 → 0.50.30
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 +1 -0
- package/dist/antigravity-judgment-hook.d.ts +191 -0
- package/dist/antigravity-judgment-hook.js +2042 -0
- package/dist/claude-code-judgment-hook.d.ts +23 -0
- package/dist/claude-code-judgment-hook.js +8 -5
- package/dist/cli.js +273 -6
- package/dist/graph-retrieval.d.ts +4 -0
- package/dist/graph-retrieval.js +4 -0
- package/dist/judgment-event-adapter.d.ts +37 -2
- package/dist/judgment-event-adapter.js +88 -3
- package/dist/judgment-event-outbox.d.ts +9 -1
- package/dist/judgment-event-outbox.js +45 -8
- package/dist/judgment-execution-outcome.d.ts +2 -1
- package/dist/judgment-execution-outcome.js +2 -1
- package/dist/judgment-frame.d.ts +26 -4
- package/dist/judgment-frame.js +190 -15
- package/dist/judgment-host.d.ts +30 -0
- package/dist/judgment-host.js +170 -22
- package/dist/judgment-model-outcome.d.ts +29 -1
- package/dist/judgment-model-outcome.js +69 -1
- package/dist/judgment-offline-binary-audit.d.ts +360 -0
- package/dist/judgment-offline-binary-audit.js +555 -0
- package/dist/judgment-project-binding.d.ts +1 -1
- package/dist/judgment-project-binding.js +2 -1
- package/dist/judgment-reasoning-audit.d.ts +115 -0
- package/dist/judgment-reasoning-audit.js +623 -0
- package/dist/judgment-reasoning-gate-prompt.d.ts +42 -0
- package/dist/judgment-reasoning-gate-prompt.js +83 -0
- package/dist/judgment-runtime-resolution.d.ts +2 -2
- package/dist/judgment-runtime-resolution.js +2 -2
- package/dist/judgment-runtime-resolution.public.d.ts +2 -2
- package/dist/judgment-session-world-model.d.ts +163 -0
- package/dist/judgment-session-world-model.js +408 -0
- package/dist/mcp-tool-schema-portability.d.ts +54 -0
- package/dist/mcp-tool-schema-portability.js +1013 -0
- package/dist/organization-graph.js +9 -1
- package/dist/remote-judgment-hook-http.d.ts +36 -3
- package/dist/remote-judgment-hook-http.js +94 -15
- package/package.json +14 -2
|
@@ -92,6 +92,23 @@ export declare function repositoryIdentityFromUrl(remote: string): string | null
|
|
|
92
92
|
* origin remote whose URL names a host and an owner.
|
|
93
93
|
*/
|
|
94
94
|
export declare function repositoryIdentity(repoRoot: string, env?: NodeJS.ProcessEnv): string | null;
|
|
95
|
+
export interface RepositoryScope {
|
|
96
|
+
/** A git checkout was found. */
|
|
97
|
+
inGit: boolean;
|
|
98
|
+
repository: string | null;
|
|
99
|
+
/** Real path of the checkout's shared git directory; null outside git. */
|
|
100
|
+
checkout: string | null;
|
|
101
|
+
/** In git, but git could not tell the origin: nothing is sent for it. */
|
|
102
|
+
unresolved?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* The checkout has an origin, but its URL gives no `host/owner/name`.
|
|
105
|
+
* Unlike a checkout without origin, it works for some repository the Host
|
|
106
|
+
* cannot be told about, so without --project nothing is sent for it.
|
|
107
|
+
*/
|
|
108
|
+
unidentified?: boolean;
|
|
109
|
+
}
|
|
110
|
+
export declare function resolveRepositoryScope(cwd: string, env?: NodeJS.ProcessEnv): RepositoryScope;
|
|
111
|
+
export declare function bearerTransportSafe(url: URL): boolean;
|
|
95
112
|
export interface PersonToken {
|
|
96
113
|
token: string;
|
|
97
114
|
/** The saved login's login_id; the same across renewals of one login. */
|
|
@@ -105,6 +122,10 @@ export declare function namespacedId(id: string, config: Pick<ClaudeCodeHookConf
|
|
|
105
122
|
* port, a `~` in the path, a very long name) is not sent at all.
|
|
106
123
|
*/
|
|
107
124
|
export declare function hostCanMapRepository(repository: string | null, config: Pick<ClaudeCodeHookConfig, 'project_code'>): boolean;
|
|
125
|
+
export declare function digestSummary(value: unknown): {
|
|
126
|
+
digest: string;
|
|
127
|
+
bytes: number;
|
|
128
|
+
};
|
|
108
129
|
/**
|
|
109
130
|
* The Host keeps only digests of a non-Brainbase tool's input, output and
|
|
110
131
|
* error. Sending digests keeps file bodies and command output on this machine.
|
|
@@ -130,6 +151,8 @@ export declare function shellQuote(argument: string): string;
|
|
|
130
151
|
* config file and the registration id, each quoted for the shell.
|
|
131
152
|
*/
|
|
132
153
|
export declare function claudeCodeHookCommand(nodePath: string, cliPath: string, configPath: string, registrationId: string): string;
|
|
154
|
+
/** The arguments of a command made only of single-quoted words, or null. */
|
|
155
|
+
export declare function singleQuotedWords(command: string): string[] | null;
|
|
133
156
|
/**
|
|
134
157
|
* The config path and registration id of a registration this installer
|
|
135
158
|
* wrote, or null for any other hook (a wrapper, or another hook that only
|
|
@@ -277,8 +277,7 @@ export function repositoryIdentity(repoRoot, env = process.env) {
|
|
|
277
277
|
const origin = originLookup(repoRoot, env);
|
|
278
278
|
return origin.status === 'found' ? repositoryIdentityFromUrl(origin.url) : null;
|
|
279
279
|
}
|
|
280
|
-
function
|
|
281
|
-
const cwd = typeof payload.cwd === 'string' && payload.cwd ? payload.cwd : process.cwd();
|
|
280
|
+
export function resolveRepositoryScope(cwd, env = process.env) {
|
|
282
281
|
const root = findGitRoot(cwd);
|
|
283
282
|
if (!root)
|
|
284
283
|
return { inGit: false, repository: null, checkout: null };
|
|
@@ -300,6 +299,10 @@ function eventRepository(payload, env) {
|
|
|
300
299
|
? { inGit: true, repository: null, checkout, unidentified: true }
|
|
301
300
|
: { inGit: true, repository, checkout };
|
|
302
301
|
}
|
|
302
|
+
function eventRepository(payload, env) {
|
|
303
|
+
const cwd = typeof payload.cwd === 'string' && payload.cwd ? payload.cwd : process.cwd();
|
|
304
|
+
return resolveRepositoryScope(cwd, env);
|
|
305
|
+
}
|
|
303
306
|
function isAuditedRepository(scope, config) {
|
|
304
307
|
if (!scope.inGit || scope.unresolved)
|
|
305
308
|
return false;
|
|
@@ -391,7 +394,7 @@ function promptIdOf(payload) {
|
|
|
391
394
|
return typeof payload.prompt_id === 'string' && payload.prompt_id ? payload.prompt_id : null;
|
|
392
395
|
}
|
|
393
396
|
// ---- Transport ----
|
|
394
|
-
function bearerTransportSafe(url) {
|
|
397
|
+
export function bearerTransportSafe(url) {
|
|
395
398
|
return url.protocol === 'https:'
|
|
396
399
|
|| (url.protocol === 'http:' && ['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname));
|
|
397
400
|
}
|
|
@@ -512,7 +515,7 @@ function documentedOutput(output, eventName) {
|
|
|
512
515
|
function isBrainbaseTool(payload) {
|
|
513
516
|
return typeof payload.tool_name === 'string' && payload.tool_name.startsWith('mcp__brainbase__');
|
|
514
517
|
}
|
|
515
|
-
function digestSummary(value) {
|
|
518
|
+
export function digestSummary(value) {
|
|
516
519
|
const text = JSON.stringify(value) ?? 'null';
|
|
517
520
|
return { digest: `sha256:${sha256(text)}`, bytes: Buffer.byteLength(text) };
|
|
518
521
|
}
|
|
@@ -839,7 +842,7 @@ export function claudeCodeHookCommand(nodePath, cliPath, configPath, registratio
|
|
|
839
842
|
.map(shellQuote).join(' ');
|
|
840
843
|
}
|
|
841
844
|
/** The arguments of a command made only of single-quoted words, or null. */
|
|
842
|
-
function singleQuotedWords(command) {
|
|
845
|
+
export function singleQuotedWords(command) {
|
|
843
846
|
const words = [];
|
|
844
847
|
let index = 0;
|
|
845
848
|
while (index < command.length) {
|
package/dist/cli.js
CHANGED
|
@@ -19,13 +19,14 @@ import { buildClaudeScheduledTasks, buildRoutines, parseRoutineKinds, parseRouti
|
|
|
19
19
|
import { assertPublicSafeSkillBundle, buildSkillBundle, parseSkillIds, parseSkillTarget, renderSkillsMarkdown } from './skills.js';
|
|
20
20
|
import { buildProjectRegistrationPlan, parseProjectSource, parseProjectStakeholder, renderProjectRegistrationMarkdown } from './projects.js';
|
|
21
21
|
import { renderGuidedFirstRun } from './guided-onboarding.js';
|
|
22
|
-
import { blockedJudgmentOutput, processJudgmentHook } from './judgment-host.js';
|
|
22
|
+
import { blockedJudgmentOutput, processJudgmentHook, resolveReasoningGateMode } from './judgment-host.js';
|
|
23
23
|
import { applyCanonicalWrites, buildCanonicalEdge } from './canonical-edge-builder.js';
|
|
24
24
|
import { defaultJudgmentJournalRoot } from './judgment-value-proof-review.js';
|
|
25
25
|
import { createWorldExtension, readWorldVocabulary } from './world-extension.js';
|
|
26
26
|
import { createLocalWebHost, LOCAL_WEB_DEFAULT_PORT } from './local-web-host.js';
|
|
27
27
|
import { assertCredentialsFilePath, BrainbaseLoginError, CREDENTIALS_SCHEMA_VERSION, defaultCredentialsPath, loginWithDeviceCode, normalizeServerUrl, readCredentials, removeCredentials, withCredentialsLock } from './brainbase-login.js';
|
|
28
28
|
import { CLAUDE_CODE_HOOK_CONFIG_SCHEMA, canonicalFilePath, claudeCodeHookCommand, claudeCodeJudgmentHookGroups, defaultClaudeCodeHookConfigPath, handleClaudeCodeJudgmentHook, hasInstalledClaudeCodeHooks, isClaudeCodeHookConfigText, parseClaudeCodeHookConfig, normalizeRepositoryEntry, registerClaudeCodeJudgmentHooks } from './claude-code-judgment-hook.js';
|
|
29
|
+
import { ANTIGRAVITY_HOOK_CONFIG_SCHEMA, ANTIGRAVITY_HOOK_KEY, antigravityFailOpenOutput, antigravityHookCommand, antigravityJudgmentHookEntry, defaultAntigravityHookConfigPath, defaultAntigravityHooksJsonPath, handleAntigravityJudgmentHook, hasInstalledAntigravityHooks, isAntigravityHookConfigText, normalizeAntigravityHookBaseUrl, parseAntigravityHookConfig, registerAntigravityJudgmentHooks, resolveAntigravityHookEndpoint } from './antigravity-judgment-hook.js';
|
|
29
30
|
export async function runCli(argv = process.argv.slice(2), io = process) {
|
|
30
31
|
const parsed = parseArgs(argv);
|
|
31
32
|
try {
|
|
@@ -114,6 +115,8 @@ export async function runCli(argv = process.argv.slice(2), io = process) {
|
|
|
114
115
|
return await judgmentInstall(parsed, io);
|
|
115
116
|
case 'judgment:claude-code-hook':
|
|
116
117
|
return await judgmentClaudeCodeHook(parsed, io);
|
|
118
|
+
case 'judgment:antigravity-hook':
|
|
119
|
+
return await judgmentAntigravityHook(parsed, io);
|
|
117
120
|
case 'login':
|
|
118
121
|
return await login(parsed, io);
|
|
119
122
|
case 'login:status':
|
|
@@ -152,12 +155,31 @@ function judgmentAutonomyOptions(parsed) {
|
|
|
152
155
|
...(project ? { autonomyCanaryProjects: [project] } : {})
|
|
153
156
|
};
|
|
154
157
|
}
|
|
158
|
+
function judgmentReasoningGateOptions(parsed) {
|
|
159
|
+
const rawMode = first(parsed, 'reasoning-gate-mode')?.trim();
|
|
160
|
+
const rawProjects = parsed.values.get('reasoning-gate-projects')
|
|
161
|
+
?? parsed.values.get('reasoning-gate-project');
|
|
162
|
+
const projects = rawProjects
|
|
163
|
+
? [...new Set(rawProjects.flatMap((value) => value.split(',')).map((value) => value.trim()).filter(Boolean))]
|
|
164
|
+
: undefined;
|
|
165
|
+
const resolvedMode = rawMode !== undefined
|
|
166
|
+
? resolveReasoningGateMode({ reasoningGateMode: rawMode }, {})
|
|
167
|
+
: undefined;
|
|
168
|
+
return {
|
|
169
|
+
...(resolvedMode !== undefined ? { reasoningGateMode: resolvedMode } : {}),
|
|
170
|
+
...(projects && projects.length > 0 ? { reasoningGateCanaryProjects: projects } : {})
|
|
171
|
+
};
|
|
172
|
+
}
|
|
155
173
|
async function judgmentHook(parsed, io) {
|
|
156
174
|
let payload = {};
|
|
157
175
|
try {
|
|
158
176
|
const input = await readHookStdin(io.stdin ?? process.stdin);
|
|
159
177
|
payload = JSON.parse(input || '{}');
|
|
160
|
-
|
|
178
|
+
const hookOptions = {
|
|
179
|
+
...judgmentAutonomyOptions(parsed),
|
|
180
|
+
...judgmentReasoningGateOptions(parsed)
|
|
181
|
+
};
|
|
182
|
+
write(io, `${JSON.stringify(await processJudgmentHook(payload, hookOptions))}\n`);
|
|
161
183
|
}
|
|
162
184
|
catch (error) {
|
|
163
185
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -174,10 +196,13 @@ async function judgmentInstall(parsed, io) {
|
|
|
174
196
|
const target = first(parsed, 'target');
|
|
175
197
|
if (target === 'claude-code')
|
|
176
198
|
return await judgmentInstallClaudeCode(parsed, io);
|
|
199
|
+
if (target === 'antigravity')
|
|
200
|
+
return await judgmentInstallAntigravity(parsed, io);
|
|
177
201
|
if (target !== 'codex')
|
|
178
|
-
throw new Error('judgment:install requires --target codex|claude-code');
|
|
202
|
+
throw new Error('judgment:install requires --target codex|claude-code|antigravity');
|
|
179
203
|
const cliPath = fileURLToPath(new URL('./cli.js', import.meta.url));
|
|
180
204
|
const autonomy = judgmentAutonomyOptions(parsed);
|
|
205
|
+
const reasoningGate = judgmentReasoningGateOptions(parsed);
|
|
181
206
|
const hookArguments = [
|
|
182
207
|
process.execPath,
|
|
183
208
|
cliPath,
|
|
@@ -185,6 +210,12 @@ async function judgmentInstall(parsed, io) {
|
|
|
185
210
|
...(autonomy.autonomyMode ? ['--autonomy-mode', autonomy.autonomyMode] : []),
|
|
186
211
|
...(autonomy.autonomyCanaryProjects?.[0]
|
|
187
212
|
? ['--autonomy-project', autonomy.autonomyCanaryProjects[0]]
|
|
213
|
+
: []),
|
|
214
|
+
...(reasoningGate.reasoningGateMode
|
|
215
|
+
? ['--reasoning-gate-mode', reasoningGate.reasoningGateMode]
|
|
216
|
+
: []),
|
|
217
|
+
...(reasoningGate.reasoningGateCanaryProjects?.length
|
|
218
|
+
? ['--reasoning-gate-projects', reasoningGate.reasoningGateCanaryProjects.join(',')]
|
|
188
219
|
: [])
|
|
189
220
|
];
|
|
190
221
|
const hook = {
|
|
@@ -235,6 +266,30 @@ async function judgmentClaudeCodeHook(parsed, io) {
|
|
|
235
266
|
write(io, `${JSON.stringify(output)}\n`);
|
|
236
267
|
return 0;
|
|
237
268
|
}
|
|
269
|
+
async function judgmentAntigravityHook(parsed, io) {
|
|
270
|
+
// Fail-open: whatever happens, Antigravity gets a valid hook answer and exit 0.
|
|
271
|
+
let eventName;
|
|
272
|
+
let output;
|
|
273
|
+
try {
|
|
274
|
+
const input = await readHookStdin(io.stdin ?? process.stdin, CLAUDE_CODE_HOOK_MAX_INPUT_BYTES);
|
|
275
|
+
const payload = JSON.parse(input || '{}');
|
|
276
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
277
|
+
throw new Error('judgment_hook_payload_invalid');
|
|
278
|
+
}
|
|
279
|
+
eventName = payload.hookEventName;
|
|
280
|
+
const configPath = first(parsed, 'config');
|
|
281
|
+
const registrationId = first(parsed, 'registration');
|
|
282
|
+
output = await handleAntigravityJudgmentHook(payload, {
|
|
283
|
+
...(configPath ? { configPath } : {}),
|
|
284
|
+
...(registrationId ? { registrationId } : {}),
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
output = antigravityFailOpenOutput(eventName);
|
|
289
|
+
}
|
|
290
|
+
write(io, `${JSON.stringify(output)}\n`);
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
238
293
|
const HOOK_PROJECT_CODE_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/u;
|
|
239
294
|
// Every option judgment:install --target claude-code reads. Anything else
|
|
240
295
|
// (a typo, or `--opt=value`, which parseArgs keeps whole as the key
|
|
@@ -524,7 +579,7 @@ class SettingsChangedError extends Error {
|
|
|
524
579
|
*/
|
|
525
580
|
function brainbaseFileUse(value) {
|
|
526
581
|
const schema = value.schema_version;
|
|
527
|
-
if (schema === CLAUDE_CODE_HOOK_CONFIG_SCHEMA)
|
|
582
|
+
if (schema === CLAUDE_CODE_HOOK_CONFIG_SCHEMA || schema === ANTIGRAVITY_HOOK_CONFIG_SCHEMA)
|
|
528
583
|
return '判断フックの設定';
|
|
529
584
|
if (schema === CREDENTIALS_SCHEMA_VERSION)
|
|
530
585
|
return 'brainbase login の保存ファイル';
|
|
@@ -635,6 +690,216 @@ async function applyClaudeCodeRegistration(plan, io) {
|
|
|
635
690
|
].join('\n'));
|
|
636
691
|
return 0;
|
|
637
692
|
}
|
|
693
|
+
const ANTIGRAVITY_INSTALL_VALUE_OPTIONS = new Set([
|
|
694
|
+
'target', 'settings', 'config', 'origin', 'endpoint', 'server', 'project', 'repositories', 'cwd-prefix',
|
|
695
|
+
]);
|
|
696
|
+
const ANTIGRAVITY_INSTALL_SWITCHES = new Set(['allow-non-git', 'remove', 'dry-run']);
|
|
697
|
+
const ANTIGRAVITY_INSTALL_MULTI_OPTIONS = new Set(['repositories', 'cwd-prefix']);
|
|
698
|
+
function assertAntigravityInstallOptions(parsed) {
|
|
699
|
+
for (const name of [...parsed.flags, ...parsed.values.keys()]) {
|
|
700
|
+
if (ANTIGRAVITY_INSTALL_VALUE_OPTIONS.has(name) || ANTIGRAVITY_INSTALL_SWITCHES.has(name))
|
|
701
|
+
continue;
|
|
702
|
+
const base = name.split('=')[0] ?? name;
|
|
703
|
+
if (base !== name && (ANTIGRAVITY_INSTALL_VALUE_OPTIONS.has(base) || ANTIGRAVITY_INSTALL_SWITCHES.has(base))) {
|
|
704
|
+
const hint = ANTIGRAVITY_INSTALL_SWITCHES.has(base) ? `--${base}` : `--${base} <値>`;
|
|
705
|
+
throw new Error(`--${base}=… の形は使えません。${hint} のように書いてください。何も変えずに止めました。`);
|
|
706
|
+
}
|
|
707
|
+
throw new Error(`judgment:install --target antigravity は --${name} を知りません。何も変えずに止めました。`);
|
|
708
|
+
}
|
|
709
|
+
for (const name of ANTIGRAVITY_INSTALL_SWITCHES) {
|
|
710
|
+
if (parsed.values.has(name)) {
|
|
711
|
+
throw new Error(`--${name} は値をとりません(--${name} だけを書きます)。何も変えずに止めました。`);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
for (const name of ANTIGRAVITY_INSTALL_VALUE_OPTIONS) {
|
|
715
|
+
if (!ANTIGRAVITY_INSTALL_MULTI_OPTIONS.has(name) && (parsed.values.get(name)?.length ?? 0) > 1) {
|
|
716
|
+
throw new Error(`--${name} は1回だけ書けます。何も変えずに止めました。`);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
async function judgmentInstallAntigravity(parsed, io) {
|
|
721
|
+
assertAntigravityInstallOptions(parsed);
|
|
722
|
+
const settingsPath = resolve(explicitValue(parsed, 'settings', '--settings <hooks.json>')
|
|
723
|
+
?? defaultAntigravityHooksJsonPath());
|
|
724
|
+
const configPath = resolve(explicitValue(parsed, 'config', '--config <path>')
|
|
725
|
+
?? defaultAntigravityHookConfigPath());
|
|
726
|
+
const settingsReal = canonicalFilePath(settingsPath);
|
|
727
|
+
const configReal = canonicalFilePath(configPath);
|
|
728
|
+
if (settingsReal === configReal) {
|
|
729
|
+
throw new Error('judgment:install --settings and --config must be different files');
|
|
730
|
+
}
|
|
731
|
+
if (configReal === canonicalFilePath(resolve(defaultCredentialsPath()))) {
|
|
732
|
+
throw new Error('judgment:install --config must not be the brainbase login file');
|
|
733
|
+
}
|
|
734
|
+
const remove = parsed.flags.has('remove');
|
|
735
|
+
const dryRun = parsed.flags.has('dry-run');
|
|
736
|
+
const registrationId = randomBytes(16).toString('hex');
|
|
737
|
+
let config;
|
|
738
|
+
if (!remove) {
|
|
739
|
+
const origin = explicitValue(parsed, 'origin', '--origin <baseUrl>');
|
|
740
|
+
if (!origin)
|
|
741
|
+
throw new Error('judgment:install --target antigravity requires --origin <baseUrl>');
|
|
742
|
+
const endpoint = explicitValue(parsed, 'endpoint', '--endpoint <hook URL>');
|
|
743
|
+
const projectValue = explicitValue(parsed, 'project', '--project <code>');
|
|
744
|
+
const projectCode = projectValue?.trim();
|
|
745
|
+
if (projectValue !== undefined && !HOOK_PROJECT_CODE_PATTERN.test(projectCode ?? '')) {
|
|
746
|
+
throw new Error('judgment:install --project must match [a-z0-9][a-z0-9._-]{0,63}');
|
|
747
|
+
}
|
|
748
|
+
explicitValue(parsed, 'repositories', '--repositories <host/owner/name,...>');
|
|
749
|
+
const repositoryValues = parsed.values.get('repositories');
|
|
750
|
+
const repositories = (repositoryValues ?? [])
|
|
751
|
+
.flatMap((value) => value.split(',')).map((name) => name.trim()).filter(Boolean)
|
|
752
|
+
.map((name) => {
|
|
753
|
+
const normalized = normalizeRepositoryEntry(name);
|
|
754
|
+
if (!normalized) {
|
|
755
|
+
throw new Error(`judgment:install --repositories needs host/owner/name, e.g. github.com/example-org/app (got ${name})`);
|
|
756
|
+
}
|
|
757
|
+
return normalized;
|
|
758
|
+
});
|
|
759
|
+
if ((repositoryValues !== undefined || parsed.flags.has('repositories')) && repositories.length === 0) {
|
|
760
|
+
throw new Error('judgment:install --repositories needs at least one host/owner/name; leave the option out to audit every repository');
|
|
761
|
+
}
|
|
762
|
+
explicitValue(parsed, 'cwd-prefix', '--cwd-prefix <path>');
|
|
763
|
+
const rawPrefixes = parsed.values.get('cwd-prefix');
|
|
764
|
+
const cwdPrefixes = (rawPrefixes ?? [])
|
|
765
|
+
.map((entry) => entry.trim()).filter(Boolean)
|
|
766
|
+
.map((entry) => canonicalFilePath(entry));
|
|
767
|
+
if ((rawPrefixes !== undefined || parsed.flags.has('cwd-prefix')) && cwdPrefixes.length === 0) {
|
|
768
|
+
throw new Error('judgment:install --cwd-prefix needs a non-empty directory path');
|
|
769
|
+
}
|
|
770
|
+
const allowNonGit = parsed.flags.has('allow-non-git');
|
|
771
|
+
const loginServer = explicitValue(parsed, 'server', '--server <API URL>')
|
|
772
|
+
?? (await readCredentials(defaultCredentialsPath()).catch(() => null))?.server_url;
|
|
773
|
+
if (!loginServer) {
|
|
774
|
+
throw new Error('judgment:install --target antigravity requires --server <API URL> (the server you log in to with brainbase login), or a saved login');
|
|
775
|
+
}
|
|
776
|
+
config = {
|
|
777
|
+
schema_version: ANTIGRAVITY_HOOK_CONFIG_SCHEMA,
|
|
778
|
+
origin: normalizeAntigravityHookBaseUrl(origin),
|
|
779
|
+
...(endpoint ? { endpoint: normalizeAntigravityHookBaseUrl(endpoint) } : {}),
|
|
780
|
+
login_server: normalizeServerUrl(loginServer),
|
|
781
|
+
...(projectCode ? { project_code: projectCode } : {}),
|
|
782
|
+
...(allowNonGit ? { allow_non_git: true } : {}),
|
|
783
|
+
...(cwdPrefixes.length > 0 ? { cwd_prefixes: [...new Set(cwdPrefixes)] } : {}),
|
|
784
|
+
...(repositories.length > 0 ? { repositories: [...new Set(repositories)] } : {}),
|
|
785
|
+
registration: { id: registrationId, settings: settingsReal },
|
|
786
|
+
};
|
|
787
|
+
resolveAntigravityHookEndpoint(config);
|
|
788
|
+
}
|
|
789
|
+
const cliPath = fileURLToPath(new URL('./cli.js', import.meta.url));
|
|
790
|
+
const command = antigravityHookCommand(process.execPath, cliPath, configPath, registrationId);
|
|
791
|
+
const plan = {
|
|
792
|
+
settingsPath, settingsReal, configPath, configReal, config, command, remove, dryRun,
|
|
793
|
+
};
|
|
794
|
+
const run = async () => {
|
|
795
|
+
for (let attempt = 1;; attempt += 1) {
|
|
796
|
+
try {
|
|
797
|
+
return await applyAntigravityRegistration(plan, io);
|
|
798
|
+
}
|
|
799
|
+
catch (error) {
|
|
800
|
+
if (!(error instanceof SettingsChangedError))
|
|
801
|
+
throw error;
|
|
802
|
+
if (attempt >= SETTINGS_CHANGED_ATTEMPTS) {
|
|
803
|
+
throw new Error(`${settingsPath} は登録の途中で何度も別の保存が入ったため、何も変えずに止めました。設定の保存が落ち着いてから、もう一度実行してください。`);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
return dryRun ? await run() : await withInstallLocks([settingsReal, configReal], run);
|
|
809
|
+
}
|
|
810
|
+
async function applyAntigravityRegistration(plan, io) {
|
|
811
|
+
const { settingsPath, settingsReal, configPath, configReal, config, command, remove, dryRun } = plan;
|
|
812
|
+
let hooksJson = {};
|
|
813
|
+
const settingsText = await readRegularFile(settingsPath, '--settings');
|
|
814
|
+
if (settingsText !== null) {
|
|
815
|
+
const parsedSettings = JSON.parse(settingsText);
|
|
816
|
+
if (!parsedSettings || typeof parsedSettings !== 'object' || Array.isArray(parsedSettings)) {
|
|
817
|
+
throw new Error(`Antigravity hooks.json is not a JSON object: ${settingsPath}`);
|
|
818
|
+
}
|
|
819
|
+
hooksJson = parsedSettings;
|
|
820
|
+
}
|
|
821
|
+
const otherUse = brainbaseFileUse(hooksJson);
|
|
822
|
+
if (otherUse) {
|
|
823
|
+
throw new Error(`judgment:install --settings ${settingsPath} は${otherUse}で、Antigravity の hooks.json ではありません。何も変えずに止めました。Antigravity の hooks.json を指定してください。`);
|
|
824
|
+
}
|
|
825
|
+
const previousConfig = await readRegularFile(configPath, '--config');
|
|
826
|
+
const configExists = previousConfig !== null;
|
|
827
|
+
const configOwned = configExists && isAntigravityHookConfigText(previousConfig);
|
|
828
|
+
if (!remove && configExists && !configOwned) {
|
|
829
|
+
throw new Error(`judgment:install --config ${configPath} exists and is not a brainbase antigravity hook config; choose another path`);
|
|
830
|
+
}
|
|
831
|
+
const existingConfig = configOwned ? parseAntigravityHookConfig(previousConfig) : null;
|
|
832
|
+
const registeredElsewhere = configOwned && (existingConfig
|
|
833
|
+
? canonicalFilePath(existingConfig.registration.settings) !== settingsReal
|
|
834
|
+
: !hasInstalledAntigravityHooks(hooksJson, configPath));
|
|
835
|
+
if (!remove && registeredElsewhere) {
|
|
836
|
+
throw new Error(`judgment:install --config ${configPath} is used by ${existingConfig?.registration.settings ?? 'another registration'}; choose another --config for ${settingsPath}`);
|
|
837
|
+
}
|
|
838
|
+
if (remove && !hasInstalledAntigravityHooks(hooksJson, configPath)) {
|
|
839
|
+
throw new Error(`judgment:install --remove found no registration for ${configPath} in ${settingsPath}; nothing was changed`);
|
|
840
|
+
}
|
|
841
|
+
const removedIds = new Set();
|
|
842
|
+
const next = registerAntigravityJudgmentHooks(hooksJson, { command, configPath, remove, removedIds });
|
|
843
|
+
if (dryRun) {
|
|
844
|
+
write(io, `${JSON.stringify({
|
|
845
|
+
settingsPath,
|
|
846
|
+
configPath,
|
|
847
|
+
config: config ?? null,
|
|
848
|
+
hooks: {
|
|
849
|
+
key: ANTIGRAVITY_HOOK_KEY,
|
|
850
|
+
entry: remove ? null : antigravityJudgmentHookEntry(command),
|
|
851
|
+
remove_registration_ids: [...removedIds],
|
|
852
|
+
},
|
|
853
|
+
}, null, 2)}\n`);
|
|
854
|
+
return 0;
|
|
855
|
+
}
|
|
856
|
+
if (remove) {
|
|
857
|
+
await replaceFileFollowingLinks(settingsPath, `${JSON.stringify(next, null, 2)}\n`, 0o600, settingsText);
|
|
858
|
+
const currentElsewhere = !!existingConfig && !removedIds.has(existingConfig.registration.id);
|
|
859
|
+
if (configOwned && !registeredElsewhere && !currentElsewhere)
|
|
860
|
+
await rm(configReal, { force: true });
|
|
861
|
+
write(io, [
|
|
862
|
+
`Antigravityの判断フックを外しました(${settingsPath})。`,
|
|
863
|
+
...(configExists && !configOwned ? [`${configPath} は判断フックの設定ではないため、残しました。`] : []),
|
|
864
|
+
...(registeredElsewhere ? [`${configPath} は ${existingConfig?.registration.settings ?? '別の登録'} の登録が使っているため、残しました。`] : []),
|
|
865
|
+
...(!registeredElsewhere && currentElsewhere ? [`${configPath} は外した登録とは別の、いまの登録が使っているため、残しました。`] : []),
|
|
866
|
+
''
|
|
867
|
+
].join('\n'));
|
|
868
|
+
return 0;
|
|
869
|
+
}
|
|
870
|
+
await mkdir(dirname(configPath), { recursive: true, mode: 0o700 });
|
|
871
|
+
await replaceFileFollowingLinks(configPath, `${JSON.stringify(config, null, 2)}\n`, 0o600);
|
|
872
|
+
try {
|
|
873
|
+
await replaceFileFollowingLinks(settingsPath, `${JSON.stringify(next, null, 2)}\n`, 0o600, settingsText);
|
|
874
|
+
}
|
|
875
|
+
catch (error) {
|
|
876
|
+
try {
|
|
877
|
+
if (previousConfig === null)
|
|
878
|
+
await rm(configPath, { force: true });
|
|
879
|
+
else
|
|
880
|
+
await replaceFileFollowingLinks(configPath, previousConfig, 0o600);
|
|
881
|
+
}
|
|
882
|
+
catch {
|
|
883
|
+
throw new Error(`${error instanceof Error ? error.message : String(error)}; ${configPath} could not be put back, run judgment:install again`);
|
|
884
|
+
}
|
|
885
|
+
throw error;
|
|
886
|
+
}
|
|
887
|
+
const resolvedEndpoint = resolveAntigravityHookEndpoint(config).toString();
|
|
888
|
+
write(io, [
|
|
889
|
+
`Antigravityの判断フックを登録しました(${settingsPath})。`,
|
|
890
|
+
`送り先: ${resolvedEndpoint}`,
|
|
891
|
+
`project: ${config.project_code ?? 'Hostが決める'}`,
|
|
892
|
+
...(config.allow_non_git ? ['非Gitディレクトリ: 許可(allow_non_git: true)'] : []),
|
|
893
|
+
...(config.cwd_prefixes ? [`対象ディレクトリ: ${config.cwd_prefixes.join(', ')}`] : []),
|
|
894
|
+
`対象のリポジトリ: ${config.repositories?.join(', ') ?? 'すべて'}`,
|
|
895
|
+
...(await readCredentials(defaultCredentialsPath()).catch(() => null)
|
|
896
|
+
? []
|
|
897
|
+
: ['まだログインしていません。brainbase login --server <API のURL> を実行してください。']),
|
|
898
|
+
'Antigravityを再起動すると有効になります。',
|
|
899
|
+
''
|
|
900
|
+
].join('\n'));
|
|
901
|
+
return 0;
|
|
902
|
+
}
|
|
638
903
|
/**
|
|
639
904
|
* An option the user typed must carry a value. parseArgs turns `--opt` with no
|
|
640
905
|
* value (or `--opt ''`) into a bare flag; falling back to the default there would
|
|
@@ -1929,10 +2194,12 @@ function usage() {
|
|
|
1929
2194
|
brainbase memory:list [--dir path] [--format text|json]
|
|
1930
2195
|
brainbase memory:register --id id [--id id...] [--dir path] [--write] [--format text|json]
|
|
1931
2196
|
brainbase ontology:migrate [--dir path] [--write --expected-input-digest digest]
|
|
1932
|
-
brainbase judgment:install --target codex [--autonomy-mode off|canary|on] [--autonomy-project code] [--dry-run] [--output path]
|
|
2197
|
+
brainbase judgment:install --target codex [--autonomy-mode off|canary|on] [--autonomy-project code] [--reasoning-gate-mode off|compact_4block_v3|compact_4block_with_wm] [--reasoning-gate-projects code,code] [--dry-run] [--output path]
|
|
1933
2198
|
brainbase judgment:install --target claude-code --origin url [--server url] [--project code] [--repositories name,name] [--settings path] [--config path] [--dry-run] [--remove]
|
|
2199
|
+
brainbase judgment:install --target antigravity --origin baseUrl [--server url] [--project code] [--allow-non-git] [--cwd-prefix path] [--repositories name,name] [--settings hooks.json] [--config path] [--dry-run] [--remove]
|
|
1934
2200
|
brainbase judgment:claude-code-hook [--config path]
|
|
1935
|
-
brainbase judgment:hook [--
|
|
2201
|
+
brainbase judgment:antigravity-hook [--config path] [--registration id]
|
|
2202
|
+
brainbase judgment:hook [--autonomy-mode off|canary|on] [--autonomy-project code] [--reasoning-gate-mode off|compact_4block_v3|compact_4block_with_wm] [--reasoning-gate-projects code,code]
|
|
1936
2203
|
brainbase login --server url [--credentials path]
|
|
1937
2204
|
brainbase login:status [--credentials path]
|
|
1938
2205
|
brainbase logout [--credentials path]
|
|
@@ -69,6 +69,10 @@ export interface GraphRetrievalResponse {
|
|
|
69
69
|
};
|
|
70
70
|
candidates: GraphRetrievalCandidate[];
|
|
71
71
|
results: GraphRetrievalCandidate[];
|
|
72
|
+
/** Total number of active entities in the resolved retrieval scope (denominator). Always set by retrieveGraph; optional for backward compatibility with older responses. */
|
|
73
|
+
totalScopedCount?: number;
|
|
74
|
+
/** Number of candidate results actually returned in this response. Always set by retrieveGraph; optional for backward compatibility with older responses. */
|
|
75
|
+
returnedCount?: number;
|
|
72
76
|
observedRelations: ObservedRelation[];
|
|
73
77
|
/** Alias kept explicit for consumers that call this a relation catalog. */
|
|
74
78
|
observedRelationCatalog: ObservedRelation[];
|
package/dist/graph-retrieval.js
CHANGED
|
@@ -99,6 +99,8 @@ export async function retrieveGraph(os, input, provider) {
|
|
|
99
99
|
},
|
|
100
100
|
candidates,
|
|
101
101
|
results: candidates,
|
|
102
|
+
totalScopedCount: scoped.length,
|
|
103
|
+
returnedCount: candidates.length,
|
|
102
104
|
observedRelations,
|
|
103
105
|
observedRelationCatalog,
|
|
104
106
|
traversal: {
|
|
@@ -430,6 +432,8 @@ function migrationResponse(input) {
|
|
|
430
432
|
semantic: { available: false, method: 'seed' },
|
|
431
433
|
candidates: empty,
|
|
432
434
|
results: empty,
|
|
435
|
+
totalScopedCount: 0,
|
|
436
|
+
returnedCount: 0,
|
|
433
437
|
observedRelations: [],
|
|
434
438
|
observedRelationCatalog: [],
|
|
435
439
|
traversal: { seedIds: [], steps: input.steps, maxSeeds: GRAPH_RETRIEVAL_MAX_SEEDS, maxSteps: GRAPH_RETRIEVAL_MAX_STEPS, maxLimit: GRAPH_RETRIEVAL_MAX_LIMIT },
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { type JudgmentExecutionOutcome } from './judgment-execution-outcome.js';
|
|
2
|
+
/** Default fallback project_code when an episode omits project binding. */
|
|
3
|
+
export declare const DEFAULT_JUDGMENT_EVENT_PROJECT_CODE: "brainbase";
|
|
4
|
+
/** Canonical project_code syntax shared with hook/relay/downstream API contracts. */
|
|
5
|
+
export declare const JUDGMENT_EVENT_PROJECT_CODE_PATTERN: RegExp;
|
|
2
6
|
/** Input boundary for a completed Host episode. Private runtime fields are ignored. */
|
|
3
7
|
export interface JudgmentEpisode {
|
|
4
8
|
episode_id?: unknown;
|
|
@@ -13,8 +17,30 @@ export interface JudgmentEpisode {
|
|
|
13
17
|
payload?: unknown;
|
|
14
18
|
redaction_status?: unknown;
|
|
15
19
|
execution_outcome?: unknown;
|
|
20
|
+
project_code?: unknown;
|
|
21
|
+
applicability_scope?: unknown;
|
|
16
22
|
[key: string]: unknown;
|
|
17
23
|
}
|
|
24
|
+
export interface JudgmentKnowledgeEventAdapterOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Fallback `project_code` when the episode does not carry one.
|
|
27
|
+
* Defaults to `'brainbase'` to preserve backward compatibility with callers
|
|
28
|
+
* and outbox readback contracts that require a non-empty `project_code`.
|
|
29
|
+
*/
|
|
30
|
+
fallbackProjectCode?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Optional allowlist matching the delivery token's `projectCodes` claim
|
|
33
|
+
* (downstream `requireProjectAccess`). When provided, an event is emitted
|
|
34
|
+
* only if its resolved `project_code` is included in this list.
|
|
35
|
+
*/
|
|
36
|
+
allowedProjectCodes?: readonly string[];
|
|
37
|
+
/**
|
|
38
|
+
* Behavior when the resolved `project_code` is outside `allowedProjectCodes`.
|
|
39
|
+
* - `'skip'` (default): return `null` so an out-of-scope event is not queued.
|
|
40
|
+
* - `'reject'`: throw an Error with `code = 'knowledge_project_access_denied'`.
|
|
41
|
+
*/
|
|
42
|
+
onProjectOutOfScope?: 'skip' | 'reject';
|
|
43
|
+
}
|
|
18
44
|
export interface JudgmentKnowledgeEventPayload {
|
|
19
45
|
summary?: string;
|
|
20
46
|
redaction_status?: 'needs_redaction';
|
|
@@ -41,7 +67,7 @@ export interface JudgmentKnowledgeEvent {
|
|
|
41
67
|
};
|
|
42
68
|
applicability_scope: {
|
|
43
69
|
scope: 'judgment_episode';
|
|
44
|
-
project_code:
|
|
70
|
+
project_code: string;
|
|
45
71
|
};
|
|
46
72
|
permission_snapshot: {
|
|
47
73
|
knowledge_registration: true;
|
|
@@ -63,10 +89,19 @@ export declare function sanitizeJudgmentAnswer(value: unknown): {
|
|
|
63
89
|
sensitive: false;
|
|
64
90
|
summary: string;
|
|
65
91
|
} | null;
|
|
92
|
+
/** Validate and trim a portable knowledge event project_code. */
|
|
93
|
+
export declare function normalizeJudgmentEventProjectCode(value: unknown): string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Exact-match check aligned with downstream `requireProjectAccess`
|
|
96
|
+
* (`allowed.includes(projectCode)`). Neither `projectCode` nor entries in
|
|
97
|
+
* `allowedProjectCodes` are implicitly trimmed; wildcards and invalid codes
|
|
98
|
+
* fail closed.
|
|
99
|
+
*/
|
|
100
|
+
export declare function isProjectCodeAllowed(projectCode: string | null | undefined, allowedProjectCodes: readonly string[] | null | undefined): boolean;
|
|
66
101
|
/**
|
|
67
102
|
* Project a completed Host episode into a non-authoritative knowledge event.
|
|
68
103
|
*
|
|
69
104
|
* This is a portable projection only. Organization identity, Task binding,
|
|
70
105
|
* transcript storage, and delivery/outbox behavior remain adapter concerns.
|
|
71
106
|
*/
|
|
72
|
-
export declare function toKnowledgeEventFromJudgmentEpisode(episode: JudgmentEpisode | null | undefined): JudgmentKnowledgeEvent | null;
|
|
107
|
+
export declare function toKnowledgeEventFromJudgmentEpisode(episode: JudgmentEpisode | null | undefined, options?: JudgmentKnowledgeEventAdapterOptions): JudgmentKnowledgeEvent | null;
|