@unson/brainbase-mcp 0.1.0 → 0.2.2

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.
@@ -94,4 +94,4 @@ export interface GuidedFirstRun {
94
94
  completionCheck: string[];
95
95
  }
96
96
  export declare function buildGuidedFirstRun(input: GuidedFirstRunInput): GuidedFirstRun;
97
- export declare function renderGuidedFirstRun(input: GuidedFirstRunInput, format: GuidedFormat): string;
97
+ export declare function renderGuidedFirstRun(input: GuidedFirstRunInput, format: GuidedFormat, details?: boolean): string;
@@ -61,6 +61,7 @@ export function buildGuidedFirstRun(input) {
61
61
  '--name', input.name || '<あなたの名前>',
62
62
  ...values.flatMap((value) => ['--value', value]),
63
63
  '--project', input.project?.name || '<最初に登録するプロジェクト>',
64
+ ...(input.project?.decisionPrinciples ?? []).flatMap((value) => ['--decision-principle', value]),
64
65
  '--relationship', firstRelationshipArg
65
66
  ]);
66
67
  const demoCommand = command([
@@ -69,6 +70,7 @@ export function buildGuidedFirstRun(input) {
69
70
  '--dir', input.dataDir,
70
71
  '--scenario', firstValueScenario
71
72
  ]);
73
+ const actualAgentPrompt = `Brainbaseのget_contextとsearchを使い、保存済み文脈を根拠に「${firstValueScenario}」へ回答してください。使った前提と未確認事項を分けてください。`;
72
74
  const projectDryRunCommand = project
73
75
  ? projectCommand(input.dataDir, project.project.name, input.project, project.project.sources, false)
74
76
  : undefined;
@@ -118,44 +120,50 @@ export function buildGuidedFirstRun(input) {
118
120
  nextCommands: [
119
121
  {
120
122
  id: 'self-seed',
121
- title: '最初のデモに必要な最小文脈を正本化する',
123
+ title: '最初の実利用に必要な最小文脈を正本化する',
122
124
  when: '名前、価値観、最初のプロジェクト、関係者文脈を本人が確認した後',
123
125
  command: selfSeedCommand
124
126
  },
127
+ {
128
+ id: 'install',
129
+ title: `${targetLabel(input.target)} 用のMCP設定を実configへmergeする`,
130
+ when: '最小文脈のseed直後。dry-runを確認し、承認後に実configへ反映する',
131
+ command: operationalization.pending.find((item) => item.id === 'mcp-config')?.command ?? command(['brainbase', 'onboard:install', '--target', input.target, '--dir', input.dataDir, '--dry-run'])
132
+ },
133
+ {
134
+ id: 'doctor',
135
+ title: 'doctor と MCP get_context/search で確認する',
136
+ when: 'MCP設定を実configへmergeし、対象エージェントを再起動した後',
137
+ command: operationalization.pending.find((item) => item.id === 'verification')?.command ?? command(['brainbase', 'doctor', '--dir', input.dataDir])
138
+ },
139
+ {
140
+ id: 'actual-agent-value',
141
+ title: '実エージェントで現実の依頼を試し、本人が価値を判断する',
142
+ when: 'MCP設定反映後の新しいエージェントセッション',
143
+ command: actualAgentPrompt
144
+ },
125
145
  {
126
146
  id: 'first-value-demo',
127
- title: '最初の価値体験を実行する',
128
- when: '最小文脈のseed直後。接続診断より先に実行する',
147
+ title: '必要ならCLI文脈プレビューを見る',
148
+ when: '実接続前に保存文脈から作れるサンプルだけ確認したい時。完了証拠にはしない',
129
149
  command: demoCommand
130
150
  },
131
151
  {
132
152
  id: 'skills',
133
153
  title: '公開オンボーディングskillsを配置する',
134
- when: 'first value demoを見せた後。agentが次回も同じ運用を辿れるようにする',
154
+ when: '実エージェントの回答を本人が役立つと確認した後',
135
155
  command: operationalization.pending.find((item) => item.id === 'public-skills')?.command ?? 'brainbase onboard:skills --target codex'
136
156
  },
137
157
  {
138
158
  id: 'routines',
139
159
  title: 'ohayo / oyasumi / retroを確認付きで登録する',
140
- when: 'first value demoを見せた後。最初はPAUSEDまたは確認付きで登録する',
160
+ when: '初回価値確認後、継続運用が必要になった時',
141
161
  command: operationalization.pending.find((item) => item.id === 'routines')?.command ?? 'brainbase onboard:routines --target codex --cwd <brainbase-checkout>'
142
162
  },
143
- {
144
- id: 'install',
145
- title: `${targetLabel(input.target)} 用のMCP設定を実configへmergeする`,
146
- when: 'first value demoとskills/routines確認後。dry-runをプレビューにして承認後に実configへ反映する',
147
- command: operationalization.pending.find((item) => item.id === 'mcp-config')?.command ?? command(['brainbase', 'onboard:install', '--target', input.target, '--dir', input.dataDir, '--dry-run'])
148
- },
149
- {
150
- id: 'doctor',
151
- title: 'doctor と MCP get_context/search で確認する',
152
- when: 'MCP設定を実configへmergeし、対象エージェントを再起動した後',
153
- command: operationalization.pending.find((item) => item.id === 'verification')?.command ?? command(['brainbase', 'doctor', '--dir', input.dataDir])
154
- },
155
163
  ...(projectDryRunCommand ? [{
156
164
  id: 'project-dry-run',
157
165
  title: 'プロジェクト登録内容を確認する',
158
- when: '最初のデモ後、プロジェクト詳細を追加したい時',
166
+ when: '実エージェントの回答確認後、プロジェクト詳細を追加したい時',
159
167
  command: projectDryRunCommand
160
168
  }] : []),
161
169
  ...(projectWriteCommand ? [{
@@ -167,13 +175,13 @@ export function buildGuidedFirstRun(input) {
167
175
  {
168
176
  id: 'source-diagnosis',
169
177
  title: 'メール・カレンダー・ドライブ・タスクの接続準備を診断する',
170
- when: '最初の価値体験の後、追加文脈が必要だと分かった時',
178
+ when: '実エージェントの回答を確認した後、追加文脈が必要だと分かった時',
171
179
  command: diagnoseCommand
172
180
  },
173
181
  {
174
182
  id: 'candidates',
175
183
  title: '候補ファクトをレビュー用に作る',
176
- when: '最初のデモ後、聞き取り内容をまだ正本化せずレビュー材料にしたい時',
184
+ when: '実エージェントの回答を確認した後、聞き取り内容をまだ正本化せずレビュー材料にしたい時',
177
185
  command: command([
178
186
  'brainbase',
179
187
  'onboard:candidates',
@@ -186,16 +194,16 @@ export function buildGuidedFirstRun(input) {
186
194
  ],
187
195
  approvalGates: [
188
196
  'OAuth token、password、API key、refresh tokenはチャットへ貼らない。',
189
- '接続診断や候補JSONを初回オンボーディングの完了扱いにしない。最初の価値体験を先に見る。',
197
+ '接続診断や候補JSONを初回オンボーディングの完了扱いにしない。実エージェントの回答と本人の価値判断を先に確認する。',
190
198
  'メール、カレンダー、ドライブ、タスクは最初はmetadata-firstで扱う。',
191
199
  'Google Driveとローカルファイルは明示されたfolder allowlistだけを見る。',
192
200
  'sources/ と candidates/ は二次材料であり、本人承認前にMCPの正本文脈へ入れない。',
193
201
  'プロジェクト、関係者、判断基準はdry-run確認後だけ --write または onboard:seed で正本化する。'
194
202
  ],
195
203
  completionCheck: [
196
- 'brainbase onboard:demo が、保存済み文脈を使った自然なプロンプトとサンプル回答を返す。',
197
- 'ready=true / first_value_demo_ready だけで完了扱いにせず、ユーザーが「説明し直さなくてよい」と分かる回答を見る。',
198
- 'doctor の valueDemo.ready が true になる。',
204
+ 'CLIサンプルは接続前プレビューであり、初回価値の達成証拠にしない。',
205
+ '新しい実エージェントがBrainbase MCPのget_context/searchを使って現実の依頼へ回答する。',
206
+ '実回答を見た本人が役立ったかを判断する。',
199
207
  '完了報告には、公開skills、ohayo/oyasumi/retro、MCP実config merge、source allowlist/import/candidate review、MCP get_context/search確認の未完了タスクを必ず出す。',
200
208
  `${targetLabel(input.target)} のMCP設定に Brainbase が実登録されている。`,
201
209
  '最初のプロジェクトが get_context/search で見える。',
@@ -203,11 +211,33 @@ export function buildGuidedFirstRun(input) {
203
211
  ]
204
212
  };
205
213
  }
206
- export function renderGuidedFirstRun(input, format) {
214
+ export function renderGuidedFirstRun(input, format, details = false) {
207
215
  const guide = buildGuidedFirstRun(input);
208
216
  if (format === 'json') {
209
217
  return `${JSON.stringify(guide, null, 2)}\n`;
210
218
  }
219
+ if (!details) {
220
+ const next = guide.currentStatus.missing.length > 0
221
+ ? guide.nextCommands.find((item) => item.id === 'self-seed')
222
+ : guide.nextCommands.find((item) => item.id === 'install');
223
+ return [
224
+ '# Brainbase 初回オンボーディング',
225
+ '',
226
+ `- 状態: ${guide.currentStatus.missing.length > 0 ? '最小文脈の保存待ち' : '実エージェント接続待ち'}`,
227
+ `- データ: \`${guide.dataDir}\``,
228
+ `- 不足: ${guide.currentStatus.missing.length > 0 ? guide.currentStatus.missing.map(canonicalAreaLabel).join('、') : 'なし'}`,
229
+ '',
230
+ '## 次に実行',
231
+ next ? `\`${next.command}\`` : '次の操作はありません。',
232
+ '',
233
+ '## 確認できる価値',
234
+ guide.firstValueExperience.expectedValue,
235
+ '',
236
+ '- この案内だけではデータを書き込みません。seed実行時も既存データは削除しません。',
237
+ `- 詳細を見る: \`${command(['brainbase', 'onboard:start', '--target', guide.target, '--dir', guide.dataDir, '--details'])}\``,
238
+ ''
239
+ ].join('\n');
240
+ }
211
241
  const lines = [
212
242
  '# Brainbase 初回オンボーディング開始',
213
243
  '',
@@ -216,15 +246,15 @@ export function renderGuidedFirstRun(input, format) {
216
246
  `- 対象エージェント: ${targetLabel(guide.target)}`,
217
247
  `- データディレクトリ: \`${guide.dataDir}\``,
218
248
  `- 正本ファクト書き込み: ${guide.initialized.canonicalFactWrites ? 'あり' : 'なし'}`,
219
- `- 現在の不足: ${guide.currentStatus.missing.length > 0 ? guide.currentStatus.missing.join(', ') : 'なし'}`,
249
+ `- 現在の不足: ${guide.currentStatus.missing.length > 0 ? guide.currentStatus.missing.map(canonicalAreaLabel).join('、') : 'なし'}`,
220
250
  '',
221
- '## まず試すこと',
251
+ '## 接続後に実エージェントで試すこと',
222
252
  guide.firstValueExperience.title,
223
253
  '',
224
254
  `- 試すプロンプト: 「${guide.firstValueExperience.tryPrompt}」`,
225
255
  `- 期待する価値: ${guide.firstValueExperience.expectedValue}`,
226
256
  '',
227
- '### サンプル回答',
257
+ '### 回答イメージ(接続前プレビュー)',
228
258
  guide.firstValueExperience.sampleResult,
229
259
  '',
230
260
  '## まだ残っている運用化',
@@ -243,7 +273,7 @@ export function renderGuidedFirstRun(input, format) {
243
273
  ...section.questions.map((question) => `- ${question}`)
244
274
  ]),
245
275
  '',
246
- '## 接続準備(デモ後の任意ステップ)',
276
+ '## 追加接続(初回価値確認後の任意ステップ)',
247
277
  ...guide.sourceReadiness.flatMap((source) => [
248
278
  '',
249
279
  `### ${source.title}`,
@@ -277,11 +307,11 @@ function buildJapaneseInterview() {
277
307
  return [
278
308
  {
279
309
  id: 'value_target',
280
- title: '最初の価値体験',
310
+ title: '本人が価値を判断できる最初の実利用',
281
311
  questions: [
282
312
  'Codex / Claude Code に毎回説明し直したくない仕事文脈は何ですか?',
283
313
  '今日のオンボーディングで「これは便利」と判断できる実リクエストは何ですか?',
284
- '最初のデモは仕事前提、関係者、判断基準、プロジェクトのどれを使えれば成功ですか?'
314
+ '最初の実回答は仕事前提、関係者、判断基準、プロジェクトのどれを使えれば役立ったと判断できますか?'
285
315
  ]
286
316
  },
287
317
  {
@@ -290,7 +320,7 @@ function buildJapaneseInterview() {
290
320
  questions: [
291
321
  'あなたの名前、呼ばれ方、Codex / Claude Code に覚えてほしい仕事上の前提は何ですか?',
292
322
  '判断基準、重視する価値観、避けたい進め方は何ですか?',
293
- '最初のデモに必要な関係者は誰で、どういう文脈を覚えておくべきですか?'
323
+ '最初の実利用に必要な関係者は誰で、どういう文脈を覚えておくべきですか?'
294
324
  ]
295
325
  },
296
326
  {
@@ -306,24 +336,24 @@ function buildJapaneseInterview() {
306
336
  id: 'approval',
307
337
  title: '正本化の承認',
308
338
  questions: [
309
- '最初のデモに必要な本人、仕事、関係性の事実をこのままローカル正本に入れてよいですか?',
339
+ '最初の実利用に必要な本人、仕事、関係性の事実をこのままローカル正本に入れてよいですか?',
310
340
  '候補JSONではなく、会話上の要約として承認できますか?',
311
341
  'まだ正本化しない事実や除外したい文脈はありますか?'
312
342
  ]
313
343
  },
314
344
  {
315
345
  id: 'first_value_demo',
316
- title: 'デモ確認',
346
+ title: '実エージェント回答の確認',
317
347
  questions: [
318
- 'seed直後に brainbase onboard:demo を実行し、説明し直しが減ったか確認してください。',
319
- 'デモが足りない場合、どの文脈が不足していましたか?'
348
+ 'MCP設定反映と再起動後、実エージェントへ現実の依頼を送り、説明し直しが減ったか確認してください。',
349
+ '実回答が役立たない場合、どの文脈が不足していましたか?'
320
350
  ]
321
351
  },
322
352
  {
323
353
  id: 'sources',
324
- title: 'デモ後のメール・カレンダー・ドライブ・タスク',
354
+ title: '初回価値確認後のメール・カレンダー・ドライブ・タスク',
325
355
  questions: [
326
- '最初のデモ後に追加文脈が必要なら、メールは Gmail / Google Workspace / Outlook / Apple Mail / その他のどれですか?',
356
+ '初回価値確認後に追加文脈が必要なら、メールは Gmail / Google Workspace / Outlook / Apple Mail / その他のどれですか?',
327
357
  'カレンダーは Google Calendar / Outlook Calendar / Apple Calendar / その他のどれですか?',
328
358
  'ドキュメントは Google Drive / OneDrive / Dropbox / Notion / ローカルフォルダのどこにありますか?',
329
359
  'タスク管理は Notion / Todoist / Linear / GitHub Issues / NocoDB / CSV / カレンダーやメモ散在 / なし のどれですか?',
@@ -358,7 +388,7 @@ function buildFirstValueExperience(projectName, person) {
358
388
  '背景説明をもう一度求めず、保存した仕事メモを前提に最初の作業メモを出します。'
359
389
  ].join('\n');
360
390
  return {
361
- title: '最小メモを保存したら、まずこの一問で価値を確認します。',
391
+ title: '最小メモを保存して接続したら、実エージェントへこの一問を依頼します。',
362
392
  tryPrompt,
363
393
  expectedValue,
364
394
  sampleResult
@@ -449,6 +479,15 @@ function statusLabel(status) {
449
479
  return '追加の許可範囲が必要';
450
480
  return '未設定';
451
481
  }
482
+ function canonicalAreaLabel(area) {
483
+ if (area === 'self')
484
+ return '本人の前提';
485
+ if (area === 'work')
486
+ return '今の仕事';
487
+ if (area === 'relationships')
488
+ return '関係者';
489
+ return area;
490
+ }
452
491
  function translateRequiredInput(value) {
453
492
  if (value.includes('GoG'))
454
493
  return value.replace('Install or configure local GoG command', 'ローカルGoGコマンドをインストールまたは設定する');
@@ -102,6 +102,7 @@ export interface ApplyResult {
102
102
  id: string;
103
103
  kind: string;
104
104
  summary: string;
105
+ canonicalIds: string[];
105
106
  }[];
106
107
  skipped: {
107
108
  id: string;
@@ -328,7 +328,7 @@ export function planApply(candidates, selection, base, now) {
328
328
  ownerName = name;
329
329
  upsertEntity(graphEntities, { id: 'self', type: 'person', name, summary: 'Owner of this local Brainbase Personal OS.', tags: ['self'] });
330
330
  personalKgAdditions.push({ id: `self-${stableHash(name)}`, type: 'self', text: `I am ${name}.`, tags: ['self'], source: candidate.id, updatedAt: now });
331
- applied.push({ id: candidate.id, kind: candidate.kind, summary: name });
331
+ applied.push({ id: candidate.id, kind: candidate.kind, summary: name, canonicalIds: ['self', `self-${stableHash(name)}`] });
332
332
  break;
333
333
  }
334
334
  case 'person':
@@ -344,7 +344,14 @@ export function planApply(candidates, selection, base, now) {
344
344
  if (candidate.kind === 'relationship' && !relationships.some((relationship) => relationship.person === person && relationship.context === context)) {
345
345
  relationships.push({ id: `relationship-${stableHash(`${person}|${context}`)}`, person, role: role || undefined, context, tags: ['relationship'], updatedAt: now });
346
346
  }
347
- applied.push({ id: candidate.id, kind: candidate.kind, summary: person });
347
+ applied.push({
348
+ id: candidate.id,
349
+ kind: candidate.kind,
350
+ summary: person,
351
+ canonicalIds: candidate.kind === 'relationship'
352
+ ? [`person-${stableHash(person)}`, `relationship-${stableHash(`${person}|${context}`)}`]
353
+ : [`person-${stableHash(person)}`]
354
+ });
348
355
  break;
349
356
  }
350
357
  case 'org': {
@@ -354,7 +361,7 @@ export function planApply(candidates, selection, base, now) {
354
361
  break;
355
362
  }
356
363
  upsertEntity(graphEntities, { id: `org-${stableHash(name)}`, type: 'org', name, summary: 'Imported from onboarding sources.', tags: ['org'] });
357
- applied.push({ id: candidate.id, kind: candidate.kind, summary: name });
364
+ applied.push({ id: candidate.id, kind: candidate.kind, summary: name, canonicalIds: [`org-${stableHash(name)}`] });
358
365
  break;
359
366
  }
360
367
  case 'project': {
@@ -365,7 +372,7 @@ export function planApply(candidates, selection, base, now) {
365
372
  }
366
373
  upsertEntity(graphEntities, { id: `project-${stableHash(name)}`, type: 'project', name, summary: 'Imported from onboarding sources.', tags: ['work'] });
367
374
  personalKgAdditions.push({ id: `work-${stableHash(name)}`, type: 'work', text: name, tags: ['work'], source: candidate.id, updatedAt: now });
368
- applied.push({ id: candidate.id, kind: candidate.kind, summary: name });
375
+ applied.push({ id: candidate.id, kind: candidate.kind, summary: name, canonicalIds: [`project-${stableHash(name)}`, `work-${stableHash(name)}`] });
369
376
  break;
370
377
  }
371
378
  case 'value': {
@@ -375,7 +382,7 @@ export function planApply(candidates, selection, base, now) {
375
382
  break;
376
383
  }
377
384
  personalKgAdditions.push({ id: `value-${stableHash(text)}`, type: 'value', text, tags: ['onboarding'], source: candidate.id, updatedAt: now });
378
- applied.push({ id: candidate.id, kind: candidate.kind, summary: text });
385
+ applied.push({ id: candidate.id, kind: candidate.kind, summary: text, canonicalIds: [`value-${stableHash(text)}`] });
379
386
  break;
380
387
  }
381
388
  case 'next_action': {
@@ -385,7 +392,7 @@ export function planApply(candidates, selection, base, now) {
385
392
  break;
386
393
  }
387
394
  personalKgAdditions.push({ id: `next-action-${stableHash(text)}`, type: 'work', text, tags: ['next-action'], source: candidate.id, updatedAt: now });
388
- applied.push({ id: candidate.id, kind: candidate.kind, summary: text });
395
+ applied.push({ id: candidate.id, kind: candidate.kind, summary: text, canonicalIds: [`next-action-${stableHash(text)}`] });
389
396
  break;
390
397
  }
391
398
  case 'decision': {
@@ -394,8 +401,23 @@ export function planApply(candidates, selection, base, now) {
394
401
  skipped.push({ id: candidate.id, reason: 'decision candidate missing decision text' });
395
402
  break;
396
403
  }
397
- decisionAdditions.push({ id: `decision-${stableHash(text)}`, title: 'Promoted decision principle', decision: text, tags: ['principle'], updatedAt: now });
398
- applied.push({ id: candidate.id, kind: candidate.kind, summary: text });
404
+ const topic = payloadString(payload, 'topic');
405
+ const effectiveAt = payloadString(payload, 'effectiveAt');
406
+ const rationale = payloadString(payload, 'rationale');
407
+ const supersedes = readStringArray(payload, ['supersedes']);
408
+ const tags = readStringArray(payload, ['tags']);
409
+ decisionAdditions.push({
410
+ id: `decision-${stableHash(text)}`,
411
+ title: payloadString(payload, 'title') || 'Promoted decision principle',
412
+ decision: text,
413
+ topic: topic || undefined,
414
+ supersedes: supersedes.length > 0 ? supersedes : undefined,
415
+ effectiveAt: effectiveAt || undefined,
416
+ rationale: rationale || undefined,
417
+ tags: tags.length > 0 ? tags : ['principle'],
418
+ updatedAt: now
419
+ });
420
+ applied.push({ id: candidate.id, kind: candidate.kind, summary: text, canonicalIds: [`decision-${stableHash(text)}`] });
399
421
  break;
400
422
  }
401
423
  default:
@@ -0,0 +1,205 @@
1
+ type Environment = Record<string, string | undefined>;
2
+ export interface ConversationMessage {
3
+ sequence?: number;
4
+ turn_id?: string | null;
5
+ role: 'user' | 'assistant';
6
+ phase?: string | null;
7
+ text: string;
8
+ }
9
+ export interface JudgmentHookPayload {
10
+ hook_event_name?: string;
11
+ hookEventName?: string;
12
+ prompt?: string;
13
+ session_id?: string;
14
+ turn_id?: string;
15
+ transcript_path?: string;
16
+ cwd?: string;
17
+ model?: string;
18
+ permission_mode?: string;
19
+ tool_use_id?: string;
20
+ tool_name?: string;
21
+ tool_input?: unknown;
22
+ tool_response?: unknown;
23
+ last_assistant_message?: string;
24
+ stop_hook_active?: boolean;
25
+ }
26
+ export interface JudgmentRequest {
27
+ request: string;
28
+ turn_id: string;
29
+ project_code?: string;
30
+ conversation_context: {
31
+ schema_version: 'brainbase-conversation-context-v1';
32
+ session_ref: string;
33
+ messages: Required<ConversationMessage>[];
34
+ prior_receipts: Array<Record<string, unknown>>;
35
+ runtime: {
36
+ host: string;
37
+ model: string | null;
38
+ permission_mode: string | null;
39
+ project_binding: string | null;
40
+ };
41
+ instruction_bindings: Array<{
42
+ scope: string;
43
+ source_ref: string;
44
+ digest: string;
45
+ }>;
46
+ completeness: 'complete' | 'partial';
47
+ source_digest: string;
48
+ };
49
+ }
50
+ export interface JudgmentClassification {
51
+ intent: 'answer' | 'investigate' | 'diagnose' | 'design' | 'implement' | 'review' | 'operate';
52
+ domains: Array<'general' | 'knowledge' | 'engineering' | 'organization' | 'operations' | 'personal_judgment'>;
53
+ confidence: 'confirmed' | 'inferred';
54
+ }
55
+ export interface JudgmentNodeDefinition {
56
+ id: string;
57
+ kind: 'common' | 'judgment' | 'constraint' | 'clarification';
58
+ instruction: string;
59
+ }
60
+ export interface JudgmentReceipt {
61
+ resolution_id: string;
62
+ resolved_at: string;
63
+ turn_id: string;
64
+ request_digest: string;
65
+ context_digest: string;
66
+ plan_digest: string;
67
+ status: 'resolved' | 'needs_clarification';
68
+ runtime_version: string;
69
+ manifest_digest: string;
70
+ host_binding: {
71
+ adapter_id: 'brainbase-local';
72
+ adapter_version: '1';
73
+ status: 'managed';
74
+ enforcement_level: 'host_contract';
75
+ };
76
+ project_code?: string;
77
+ classification: JudgmentClassification | null;
78
+ classification_evidence: {
79
+ source: 'current_request' | 'prior_message' | 'prior_receipt' | 'resolver';
80
+ source_turn_ids: string[];
81
+ matcher_ids: string[];
82
+ };
83
+ reconciliation_reasons: string[];
84
+ selected_dag_ids: string[];
85
+ applicable_policies: Array<{
86
+ id: string;
87
+ instruction: string;
88
+ }>;
89
+ active_nodes: string[];
90
+ active_edges: Array<[string, string]>;
91
+ active_node_definitions: JudgmentNodeDefinition[];
92
+ unresolved: string[];
93
+ rationale: string[];
94
+ }
95
+ export interface JudgmentHookOutput {
96
+ continue: true;
97
+ suppressOutput: true;
98
+ receipt: JudgmentReceipt;
99
+ hookSpecificOutput: {
100
+ hookEventName: 'UserPromptSubmit';
101
+ additionalContext: string;
102
+ };
103
+ }
104
+ export interface JudgmentHostOptions {
105
+ env?: Environment;
106
+ resolver?: (request: JudgmentRequest) => Promise<JudgmentReceipt>;
107
+ trustedConversationMessages?: ConversationMessage[];
108
+ }
109
+ interface LocalResolverOptions {
110
+ now?: () => Date;
111
+ id?: () => string;
112
+ }
113
+ export interface JudgmentOwnerAudit {
114
+ schema_version: 'brainbase-owner-audit-v1';
115
+ renderer_version: '1';
116
+ locale: 'ja-JP';
117
+ historical_exact: boolean;
118
+ source_receipt_digest: string;
119
+ source_kind: 'current_request' | 'prior_turn' | 'prior_turn_fallback' | 'prior_turn_unavailable';
120
+ source_turn_ids: string[];
121
+ source_excerpt: string;
122
+ decision: string;
123
+ display_line: string;
124
+ text_digest: string;
125
+ }
126
+ interface JudgmentAdoptionEntry {
127
+ schema_version: 'brainbase-judgment-adoption-v1' | 'brainbase-judgment-adoption-v2';
128
+ accepted_at: string;
129
+ request_text_digest: string;
130
+ request: JudgmentRequest;
131
+ receipt: JudgmentReceipt;
132
+ receipt_digest?: string;
133
+ owner_audit: JudgmentOwnerAudit;
134
+ }
135
+ export interface JudgmentEpisode {
136
+ schema_version: 'brainbase-judgment-episode-v1';
137
+ session_ref: string;
138
+ turn_id: string;
139
+ started_at: string;
140
+ request_text_digest: string;
141
+ initial_receipt_digest: string;
142
+ adoption: JudgmentAdoptionEntry;
143
+ audit_contract: {
144
+ schema_version: 'brainbase-owner-audit-contract-v1';
145
+ repair_body_policy: 'preserve';
146
+ zero_call_display_line: string | null;
147
+ zero_call_display_line_digest: string | null;
148
+ };
149
+ episode_digest: string;
150
+ }
151
+ export interface JudgmentToolEvent {
152
+ schema_version: 'brainbase-judgment-tool-event-v1';
153
+ session_ref: string;
154
+ turn_id: string;
155
+ sequence: number;
156
+ recorded_at: string;
157
+ tool_use_id: string;
158
+ tool_name: string;
159
+ tool_input: unknown;
160
+ tool_response: unknown;
161
+ audit_kind: 'routing' | 'search' | 'retrieval';
162
+ success: boolean;
163
+ satisfies: string[];
164
+ display_line: string;
165
+ event_fingerprint: string;
166
+ event_digest: string;
167
+ }
168
+ export interface JudgmentFinalReceipt {
169
+ schema_version: 'brainbase-judgment-final-v1';
170
+ session_ref: string;
171
+ turn_id: string;
172
+ finalized_at: string;
173
+ initial_receipt_digest: string;
174
+ event_count: number;
175
+ event_set_digest: string;
176
+ answer_digest: string;
177
+ completion_status?: 'complete';
178
+ owner_audit_complete?: boolean;
179
+ owner_audit_line_count?: number;
180
+ final_digest: string;
181
+ }
182
+ export interface JudgmentStopBlock {
183
+ decision: 'block';
184
+ reason: string;
185
+ }
186
+ export declare function canonicalJson(value: unknown): string;
187
+ export declare function buildJudgmentRequest(payload: JudgmentHookPayload, { env, trustedConversationMessages }?: {
188
+ env?: Environment;
189
+ trustedConversationMessages?: ConversationMessage[];
190
+ }): JudgmentRequest;
191
+ export declare function resolveLocalJudgment(request: JudgmentRequest, options?: LocalResolverOptions): Promise<JudgmentReceipt>;
192
+ export declare function buildOwnerAudit(request: JudgmentRequest, receipt: JudgmentReceipt, { historicalExact }?: {
193
+ historicalExact?: boolean;
194
+ }): JudgmentOwnerAudit;
195
+ export declare function buildOwnerReferenceLine(request: JudgmentRequest, receipt: JudgmentReceipt): string;
196
+ export declare function runJudgmentHost(payload: JudgmentHookPayload, options?: JudgmentHostOptions): Promise<JudgmentHookOutput>;
197
+ export declare function processJudgmentHook(payload: JudgmentHookPayload, options?: JudgmentHostOptions): Promise<JudgmentHookOutput | JudgmentFinalReceipt | JudgmentStopBlock | {
198
+ systemMessage: string;
199
+ } | Record<string, never>>;
200
+ export declare function blockedJudgmentOutput(reason: string): {
201
+ continue: false;
202
+ suppressOutput: false;
203
+ stopReason: string;
204
+ };
205
+ export {};