@unson/brainbase-mcp 0.1.0 → 0.2.1

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([
@@ -203,11 +204,33 @@ export function buildGuidedFirstRun(input) {
203
204
  ]
204
205
  };
205
206
  }
206
- export function renderGuidedFirstRun(input, format) {
207
+ export function renderGuidedFirstRun(input, format, details = false) {
207
208
  const guide = buildGuidedFirstRun(input);
208
209
  if (format === 'json') {
209
210
  return `${JSON.stringify(guide, null, 2)}\n`;
210
211
  }
212
+ if (!details) {
213
+ const next = guide.currentStatus.missing.length > 0
214
+ ? guide.nextCommands.find((item) => item.id === 'self-seed')
215
+ : guide.nextCommands.find((item) => item.id === 'first-value-demo');
216
+ return [
217
+ '# Brainbase 初回オンボーディング',
218
+ '',
219
+ `- 状態: ${guide.currentStatus.missing.length > 0 ? '最小文脈の保存待ち' : '初回価値を確認できます'}`,
220
+ `- データ: \`${guide.dataDir}\``,
221
+ `- 不足: ${guide.currentStatus.missing.length > 0 ? guide.currentStatus.missing.map(canonicalAreaLabel).join('、') : 'なし'}`,
222
+ '',
223
+ '## 次に実行',
224
+ next ? `\`${next.command}\`` : '次の操作はありません。',
225
+ '',
226
+ '## 確認できる価値',
227
+ guide.firstValueExperience.expectedValue,
228
+ '',
229
+ '- この案内だけではデータを書き込みません。seed実行時も既存データは削除しません。',
230
+ `- 詳細を見る: \`${command(['brainbase', 'onboard:start', '--target', guide.target, '--dir', guide.dataDir, '--details'])}\``,
231
+ ''
232
+ ].join('\n');
233
+ }
211
234
  const lines = [
212
235
  '# Brainbase 初回オンボーディング開始',
213
236
  '',
@@ -216,7 +239,7 @@ export function renderGuidedFirstRun(input, format) {
216
239
  `- 対象エージェント: ${targetLabel(guide.target)}`,
217
240
  `- データディレクトリ: \`${guide.dataDir}\``,
218
241
  `- 正本ファクト書き込み: ${guide.initialized.canonicalFactWrites ? 'あり' : 'なし'}`,
219
- `- 現在の不足: ${guide.currentStatus.missing.length > 0 ? guide.currentStatus.missing.join(', ') : 'なし'}`,
242
+ `- 現在の不足: ${guide.currentStatus.missing.length > 0 ? guide.currentStatus.missing.map(canonicalAreaLabel).join('、') : 'なし'}`,
220
243
  '',
221
244
  '## まず試すこと',
222
245
  guide.firstValueExperience.title,
@@ -449,6 +472,15 @@ function statusLabel(status) {
449
472
  return '追加の許可範囲が必要';
450
473
  return '未設定';
451
474
  }
475
+ function canonicalAreaLabel(area) {
476
+ if (area === 'self')
477
+ return '本人の前提';
478
+ if (area === 'work')
479
+ return '今の仕事';
480
+ if (area === 'relationships')
481
+ return '関係者';
482
+ return area;
483
+ }
452
484
  function translateRequiredInput(value) {
453
485
  if (value.includes('GoG'))
454
486
  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 {};