@unson/brainbase-mcp 0.30.0 → 0.31.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.
@@ -1,4 +1,5 @@
1
1
  import { type JudgmentAutonomyEvaluation, type JudgmentAutonomyResolver } from './judgment-autonomy.js';
2
+ import { canonicalJson } from './judgment-resolution-contract.js';
2
3
  type Environment = Record<string, string | undefined>;
3
4
  export interface ConversationMessage {
4
5
  sequence?: number;
@@ -204,7 +205,7 @@ export interface JudgmentStopBlock {
204
205
  block_kind?: 'autonomy_continue' | 'audit_repair';
205
206
  reason: string;
206
207
  }
207
- export declare function canonicalJson(value: unknown): string;
208
+ export { canonicalJson };
208
209
  export declare function buildJudgmentRequest(payload: JudgmentHookPayload, { env, trustedConversationMessages }?: {
209
210
  env?: Environment;
210
211
  trustedConversationMessages?: ConversationMessage[];
@@ -223,4 +224,3 @@ export declare function blockedJudgmentOutput(reason: string): {
223
224
  suppressOutput: false;
224
225
  stopReason: string;
225
226
  };
226
- export {};
@@ -3,6 +3,7 @@ import { closeSync, constants as fsConstants, fsyncSync, linkSync, mkdirSync, op
3
3
  import { homedir } from 'node:os';
4
4
  import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
5
5
  import { evaluateJudgmentAutonomy, renderJudgmentAutonomyContinuation } from './judgment-autonomy.js';
6
+ import { canonicalJson } from './judgment-resolution-contract.js';
6
7
  const RUNTIME_VERSION = 'portable-judgment-runtime-1.0.0';
7
8
  const ZERO_CALL_DISPLAY_LINE = '📚 Brainbase未参照: 必須参照なし・実呼び出し0回 ✓';
8
9
  const PORTABLE_KNOWLEDGE_TOOLS = {
@@ -62,35 +63,8 @@ const DOMAIN_TERMS = [
62
63
  ];
63
64
  const FOLLOW_UP_TERMS = ['that', 'it', 'continue', 'do that', 'それ', 'その形', 'これ', 'こちら', '続けて', 'もう一度', 'では', 'それでいい', 'そうして'];
64
65
  const AUTHORITY_INTENTS = new Set(['implement', 'operate']);
65
- export function canonicalJson(value) {
66
- if (value === null || typeof value === 'boolean' || typeof value === 'string')
67
- return JSON.stringify(value);
68
- if (typeof value === 'number') {
69
- if (!Number.isFinite(value))
70
- throw new TypeError('canonical JSON only supports finite numbers');
71
- return JSON.stringify(value);
72
- }
73
- if (Array.isArray(value))
74
- return `[${value.map((entry) => canonicalJson(entry)).join(',')}]`;
75
- if (value && typeof value === 'object') {
76
- return `{${Object.keys(value).sort(compareCodePoints).map((key) => {
77
- const entry = value[key];
78
- if (entry === undefined)
79
- throw new TypeError('canonical JSON does not support undefined');
80
- return `${JSON.stringify(key)}:${canonicalJson(entry)}`;
81
- }).join(',')}}`;
82
- }
83
- throw new TypeError(`canonical JSON does not support ${typeof value}`);
84
- }
85
- function compareCodePoints(left, right) {
86
- const a = Array.from(left, (value) => value.codePointAt(0));
87
- const b = Array.from(right, (value) => value.codePointAt(0));
88
- for (let index = 0; index < Math.min(a.length, b.length); index += 1) {
89
- if (a[index] !== b[index])
90
- return a[index] - b[index];
91
- }
92
- return a.length - b.length;
93
- }
66
+ // canonicalJson is the shared judgment resolution contract; re-exported so existing importers keep working.
67
+ export { canonicalJson };
94
68
  function sha256(value) {
95
69
  return createHash('sha256').update(value).digest('hex');
96
70
  }
@@ -0,0 +1,14 @@
1
+ export declare function canonicalJson(value: unknown): string;
2
+ export declare function sha256Hex(value: string): string;
3
+ export declare function computeRequestDigest(rawInput: unknown): string;
4
+ export declare class JudgmentResolutionError extends Error {
5
+ readonly code: string;
6
+ readonly status: number;
7
+ constructor(code: string, message: string, status?: number);
8
+ toJSON(): {
9
+ name: string;
10
+ code: string;
11
+ status: number;
12
+ message: string;
13
+ };
14
+ }
@@ -0,0 +1,53 @@
1
+ import { createHash } from 'node:crypto';
2
+ // Shared contract between the judgment Host and the judgment resolver.
3
+ // The resolver's HTTP mount and its service must throw and recognize the
4
+ // same error class, and both sides must produce identical canonical bytes,
5
+ // so these live in one public module instead of being copied per caller.
6
+ function compareCodePoints(left, right) {
7
+ const a = Array.from(left, (value) => value.codePointAt(0));
8
+ const b = Array.from(right, (value) => value.codePointAt(0));
9
+ for (let index = 0; index < Math.min(a.length, b.length); index += 1) {
10
+ if (a[index] !== b[index])
11
+ return a[index] - b[index];
12
+ }
13
+ return a.length - b.length;
14
+ }
15
+ export function canonicalJson(value) {
16
+ if (value === null || typeof value === 'boolean' || typeof value === 'string')
17
+ return JSON.stringify(value);
18
+ if (typeof value === 'number') {
19
+ if (!Number.isFinite(value))
20
+ throw new TypeError('canonical JSON only supports finite numbers');
21
+ return JSON.stringify(value);
22
+ }
23
+ if (Array.isArray(value))
24
+ return `[${value.map((entry) => canonicalJson(entry)).join(',')}]`;
25
+ if (value && typeof value === 'object') {
26
+ return `{${Object.keys(value).sort(compareCodePoints).map((key) => {
27
+ const entry = value[key];
28
+ if (entry === undefined)
29
+ throw new TypeError('canonical JSON does not support undefined');
30
+ return `${JSON.stringify(key)}:${canonicalJson(entry)}`;
31
+ }).join(',')}}`;
32
+ }
33
+ throw new TypeError(`canonical JSON does not support ${typeof value}`);
34
+ }
35
+ export function sha256Hex(value) {
36
+ return createHash('sha256').update(value).digest('hex');
37
+ }
38
+ export function computeRequestDigest(rawInput) {
39
+ return sha256Hex(canonicalJson(rawInput));
40
+ }
41
+ export class JudgmentResolutionError extends Error {
42
+ code;
43
+ status;
44
+ constructor(code, message, status = 400) {
45
+ super(message);
46
+ this.name = 'JudgmentResolutionError';
47
+ this.code = code;
48
+ this.status = status;
49
+ }
50
+ toJSON() {
51
+ return { name: this.name, code: this.code, status: this.status, message: this.message };
52
+ }
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unson/brainbase-mcp",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "Local-first Brainbase judgment OS that lets supported AI agents reuse a user's approved goals, priorities, decisions, and judgment criteria.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -183,6 +183,10 @@
183
183
  "types": "./dist/knowledge-resolution-service.d.ts",
184
184
  "import": "./dist/knowledge-resolution-service.js"
185
185
  },
186
+ "./judgment-resolution-contract": {
187
+ "types": "./dist/judgment-resolution-contract.d.ts",
188
+ "import": "./dist/judgment-resolution-contract.js"
189
+ },
186
190
  "./canonical-document-writer": {
187
191
  "types": "./dist/canonical-document-writer.d.ts",
188
192
  "import": "./dist/canonical-document-writer.js"
@@ -451,5 +455,5 @@
451
455
  "engines": {
452
456
  "node": ">=20"
453
457
  },
454
- "gitHead": "6e6cc04041ae0745272e8e61f53fe93cc06d3e40"
458
+ "gitHead": "aeb8467e65eda4223dd092cc43d69b4ebd040f42"
455
459
  }