@unson/brainbase-mcp 0.43.0 → 0.44.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.
Files changed (74) hide show
  1. package/contracts/canonical-task/operation-schema.sql +58 -0
  2. package/contracts/canonical-task/search-indexes.sql +10 -0
  3. package/contracts/canonical-task/store-schema.sql +77 -0
  4. package/dist/automation-run.d.ts +213 -0
  5. package/dist/automation-run.js +479 -0
  6. package/dist/canonical-task-operations.d.ts +205 -0
  7. package/dist/canonical-task-operations.js +700 -0
  8. package/dist/canonical-task-postgres.d.ts +139 -0
  9. package/dist/canonical-task-postgres.js +554 -0
  10. package/dist/canonical-task-service.d.ts +13 -0
  11. package/dist/canonical-task-service.js +55 -3
  12. package/dist/canonical-task-store-config.d.ts +31 -0
  13. package/dist/canonical-task-store-config.js +53 -0
  14. package/dist/config-parser.d.ts +298 -0
  15. package/dist/config-parser.js +593 -0
  16. package/dist/connected-onboarding.d.ts +57 -0
  17. package/dist/connected-onboarding.js +37 -0
  18. package/dist/durable-wait-http.d.ts +3 -1
  19. package/dist/durable-wait-http.js +73 -6
  20. package/dist/durable-waits.d.ts +93 -3
  21. package/dist/durable-waits.js +320 -8
  22. package/dist/honcho.d.ts +25 -0
  23. package/dist/honcho.js +81 -0
  24. package/dist/judgment-event-adapter.d.ts +72 -0
  25. package/dist/judgment-event-adapter.js +114 -0
  26. package/dist/judgment-event-outbox.d.ts +182 -0
  27. package/dist/judgment-event-outbox.js +568 -0
  28. package/dist/judgment-execution-outcome.d.ts +46 -0
  29. package/dist/judgment-execution-outcome.js +149 -0
  30. package/dist/judgment-host.d.ts +18 -7
  31. package/dist/judgment-host.js +82 -34
  32. package/dist/judgment-lifecycle-core.d.ts +198 -0
  33. package/dist/judgment-lifecycle-core.js +464 -0
  34. package/dist/judgment-node-evidence.d.ts +57 -0
  35. package/dist/judgment-node-evidence.js +297 -0
  36. package/dist/judgment-runtime-resolution.d.ts +264 -0
  37. package/dist/judgment-runtime-resolution.js +1248 -0
  38. package/dist/judgment-runtime-resolution.public.d.ts +255 -0
  39. package/dist/knowledge-event.d.ts +28 -0
  40. package/dist/knowledge-event.js +114 -0
  41. package/dist/mcp-runtime.d.ts +75 -0
  42. package/dist/mcp-runtime.js +188 -0
  43. package/dist/meeting-automation-runtime.d.ts +102 -0
  44. package/dist/meeting-automation-runtime.js +249 -0
  45. package/dist/meeting-automation.d.ts +155 -0
  46. package/dist/meeting-automation.js +341 -0
  47. package/dist/meeting-minutes-context-receipt.d.ts +91 -0
  48. package/dist/meeting-minutes-context-receipt.js +280 -0
  49. package/dist/meeting-source-sync.d.ts +89 -0
  50. package/dist/meeting-source-sync.js +230 -0
  51. package/dist/mesh.d.ts +58 -0
  52. package/dist/mesh.js +134 -0
  53. package/dist/onboarding-runtime.d.ts +47 -0
  54. package/dist/onboarding-runtime.js +4719 -0
  55. package/dist/routine-cycle.d.ts +51 -0
  56. package/dist/routine-cycle.js +153 -0
  57. package/dist/routine-liveness.d.ts +49 -0
  58. package/dist/routine-liveness.js +227 -0
  59. package/dist/routine-runtime.d.ts +101 -0
  60. package/dist/routine-runtime.js +237 -0
  61. package/dist/routines.d.ts +3 -0
  62. package/dist/routines.js +3 -0
  63. package/dist/run-receipt.d.ts +40 -0
  64. package/dist/run-receipt.js +635 -0
  65. package/dist/runtime-host.d.ts +64 -0
  66. package/dist/runtime-host.js +70 -0
  67. package/dist/world-work.d.ts +16 -0
  68. package/package.json +115 -3
  69. package/ui/meeting-minutes.css +122 -0
  70. package/ui/meeting-minutes.js +316 -0
  71. package/ui/objective-editor.js +47 -11
  72. package/ui/world/world-district.js +18 -3
  73. package/ui/world/world-placement.js +13 -0
  74. package/ui/world/world-work-rail.js +7 -1
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Portable evidence-chain contract for judgment nodes.
3
+ *
4
+ * The Host owns event binding and decides which events count as business
5
+ * evidence. This module only validates the small node result and evaluates
6
+ * ordered references; it never reads a transcript, Task, or private store.
7
+ */
8
+ export declare const JUDGMENT_NODE_EVIDENCE_SCHEMA_VERSION: "brainbase-judgment-node-result-v1";
9
+ export declare const JUDGMENT_NODE_EVIDENCE_CONTRACT: "judgment-node-evidence-v1";
10
+ export type JudgmentNodeStatus = 'supported' | 'insufficient';
11
+ export type JudgmentNodeEvaluationStatus = 'not_required' | 'host_unsupported' | 'missing' | 'invalid' | 'insufficient' | 'ready';
12
+ export interface JudgmentNodeResult {
13
+ schema_version: typeof JUDGMENT_NODE_EVIDENCE_SCHEMA_VERSION;
14
+ node_id: string;
15
+ status: JudgmentNodeStatus;
16
+ finding: string;
17
+ evidence_fit: string;
18
+ unknowns: string[];
19
+ evidence_tool_use_ids: string[];
20
+ previous_result_tool_use_id: string | null;
21
+ next_action: string;
22
+ }
23
+ export interface JudgmentNodeDefinition {
24
+ id: string;
25
+ instruction?: unknown;
26
+ execution_contract?: unknown;
27
+ [key: string]: unknown;
28
+ }
29
+ export type JudgmentNodeResultRecord = Omit<JudgmentNodeResult, 'status'> & {
30
+ status: JudgmentNodeStatus | 'invalid';
31
+ tool_use_id: string | null;
32
+ event_sequence: number;
33
+ };
34
+ export interface JudgmentNodeEvidenceEvaluation {
35
+ required: boolean;
36
+ ready: boolean;
37
+ status: JudgmentNodeEvaluationStatus;
38
+ next_node: string | null;
39
+ next_action: string | null;
40
+ results: JudgmentNodeResultRecord[];
41
+ unsupported_node_ids?: string[];
42
+ }
43
+ /** Normalize a result stored in a successful node-evidence event. */
44
+ export declare function normalizeJudgmentNodeResult(value: unknown): JudgmentNodeResult | null;
45
+ /** Return opted-in node ids in the order their results must be chained. */
46
+ export declare function judgmentNodeEvidenceNodeIds(receipt: unknown): string[];
47
+ /** Return whether an event is usable business evidence for a node. */
48
+ export declare function isSuccessfulJudgmentEvidenceEvent(event: unknown): boolean;
49
+ /**
50
+ * Evaluate the ordered result chain for a route receipt.
51
+ *
52
+ * Returned result entries contain only the normalized node result and its
53
+ * binding event id/sequence; event response bodies stay outside this module.
54
+ */
55
+ export declare function evaluateJudgmentNodeEvidence(events: unknown, receipt: unknown, { hostSupported }?: {
56
+ hostSupported?: boolean;
57
+ }): JudgmentNodeEvidenceEvaluation;
@@ -0,0 +1,297 @@
1
+ /**
2
+ * Portable evidence-chain contract for judgment nodes.
3
+ *
4
+ * The Host owns event binding and decides which events count as business
5
+ * evidence. This module only validates the small node result and evaluates
6
+ * ordered references; it never reads a transcript, Task, or private store.
7
+ */
8
+ export const JUDGMENT_NODE_EVIDENCE_SCHEMA_VERSION = 'brainbase-judgment-node-result-v1';
9
+ export const JUDGMENT_NODE_EVIDENCE_CONTRACT = 'judgment-node-evidence-v1';
10
+ const NODE_STATUSES = new Set(['supported', 'insufficient']);
11
+ const CONTROL_EVENT_KINDS = new Set([
12
+ 'control', 'route', 'evidence', 'node_evidence', 'state', 'value_proof',
13
+ 'turn_resolution', 'ignored', 'personal_answer', 'frame_catalog', 'frame_read', 'frame'
14
+ ]);
15
+ const NON_BUSINESS_TOOL_PATTERN = /(?:^|__)(?:get_goal|update_goal|create_goal|search_tools|tools_search|tool_search|list_tools|list_mcp_resources|list_mcp_resource_templates|curr_time|current_time|get_time|clock|sleep)$/u;
16
+ const MAX_NODE_ID_LENGTH = 160;
17
+ const MAX_TEXT_LENGTH = 2000;
18
+ const MAX_UNKNOWN_LENGTH = 800;
19
+ const MAX_ITEMS = 24;
20
+ const SECRET_PATTERN = /\b(?:api[_-]?key|password|passwd|secret|token)\s*[:=]\s*\S+|\b(?:sk-[a-z0-9_-]{8,}|ghp_[a-z0-9_]{8,}|github_pat_[a-z0-9_]{8,}|xox[a-z]-[a-z0-9-]{8,})\b/iu;
21
+ const INPUT_KEYS = Object.freeze([
22
+ 'node_id', 'status', 'finding', 'evidence_fit', 'unknowns',
23
+ 'evidence_tool_use_ids', 'previous_result_tool_use_id', 'next_action'
24
+ ]);
25
+ const RESULT_KEYS = Object.freeze(['schema_version', ...INPUT_KEYS]);
26
+ function isRecord(value) {
27
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
28
+ }
29
+ function exactKeys(value, keys) {
30
+ if (!isRecord(value))
31
+ return false;
32
+ const actual = Object.keys(value).sort();
33
+ const expected = [...keys].sort();
34
+ return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
35
+ }
36
+ function cleanText(value, limit, { nullable = false } = {}) {
37
+ if (value === null && nullable)
38
+ return null;
39
+ if (typeof value !== 'string')
40
+ return undefined;
41
+ const text = value.replace(/[\u0000-\u001f\u007f]+/gu, ' ').replace(/\s+/gu, ' ').trim();
42
+ if (!text || [...text].length > limit || SECRET_PATTERN.test(text))
43
+ return undefined;
44
+ return text;
45
+ }
46
+ function cleanId(value, options = {}) {
47
+ return cleanText(value, MAX_NODE_ID_LENGTH, options);
48
+ }
49
+ function cleanStringArray(value, limit, { maxItems = MAX_ITEMS } = {}) {
50
+ if (!Array.isArray(value) || value.length > maxItems)
51
+ return undefined;
52
+ const result = [];
53
+ for (const entry of value) {
54
+ const text = cleanText(entry, limit);
55
+ if (typeof text !== 'string' || result.includes(text))
56
+ return undefined;
57
+ result.push(text);
58
+ }
59
+ return result;
60
+ }
61
+ function normalizeInput(value, { includeSchemaVersion = true } = {}) {
62
+ const expectedKeys = includeSchemaVersion ? RESULT_KEYS : INPUT_KEYS;
63
+ if (!exactKeys(value, expectedKeys))
64
+ return null;
65
+ if (includeSchemaVersion && value.schema_version !== JUDGMENT_NODE_EVIDENCE_SCHEMA_VERSION)
66
+ return null;
67
+ const nodeId = cleanId(value.node_id);
68
+ const status = value.status;
69
+ const finding = cleanText(value.finding, MAX_TEXT_LENGTH);
70
+ const evidenceFit = cleanText(value.evidence_fit, MAX_TEXT_LENGTH);
71
+ const unknowns = cleanStringArray(value.unknowns, MAX_UNKNOWN_LENGTH);
72
+ const evidenceIds = cleanStringArray(value.evidence_tool_use_ids, MAX_NODE_ID_LENGTH);
73
+ const previous = cleanId(value.previous_result_tool_use_id, { nullable: true });
74
+ const nextAction = cleanText(value.next_action, MAX_TEXT_LENGTH);
75
+ if (typeof nodeId !== 'string'
76
+ || !NODE_STATUSES.has(status)
77
+ || typeof finding !== 'string'
78
+ || typeof evidenceFit !== 'string'
79
+ || !unknowns
80
+ || !evidenceIds
81
+ || previous === undefined
82
+ || typeof nextAction !== 'string')
83
+ return null;
84
+ if (status === 'insufficient' && unknowns.length === 0)
85
+ return null;
86
+ const base = {
87
+ node_id: nodeId,
88
+ status: status,
89
+ finding,
90
+ evidence_fit: evidenceFit,
91
+ unknowns,
92
+ evidence_tool_use_ids: evidenceIds,
93
+ previous_result_tool_use_id: previous,
94
+ next_action: nextAction
95
+ };
96
+ return includeSchemaVersion
97
+ ? { schema_version: JUDGMENT_NODE_EVIDENCE_SCHEMA_VERSION, ...base }
98
+ : base;
99
+ }
100
+ /** Normalize a result stored in a successful node-evidence event. */
101
+ export function normalizeJudgmentNodeResult(value) {
102
+ return normalizeInput(value, { includeSchemaVersion: true });
103
+ }
104
+ function contractNodes(receipt) {
105
+ if (!isRecord(receipt) || !Array.isArray(receipt.active_node_definitions))
106
+ return [];
107
+ return receipt.active_node_definitions.filter((node) => (isRecord(node)
108
+ && node.execution_contract === JUDGMENT_NODE_EVIDENCE_CONTRACT
109
+ && typeof node.id === 'string'
110
+ && node.id.trim().length > 0));
111
+ }
112
+ /** Return opted-in node ids in the order their results must be chained. */
113
+ export function judgmentNodeEvidenceNodeIds(receipt) {
114
+ return contractNodes(receipt).map((node) => node.id);
115
+ }
116
+ function eventSequence(event, fallback) {
117
+ const record = isRecord(event) ? event : null;
118
+ return record && Number.isSafeInteger(record.event_sequence) ? record.event_sequence : fallback;
119
+ }
120
+ function sortEvents(events) {
121
+ return (Array.isArray(events) ? events : [])
122
+ .map((event, index) => ({ event, index, sequence: eventSequence(event, index) }))
123
+ .sort((left, right) => left.sequence - right.sequence || left.index - right.index);
124
+ }
125
+ function eventId(event) {
126
+ const record = isRecord(event) ? event : null;
127
+ return typeof record?.tool_use_id === 'string' && record.tool_use_id.trim() ? record.tool_use_id : null;
128
+ }
129
+ /** Return whether an event is usable business evidence for a node. */
130
+ export function isSuccessfulJudgmentEvidenceEvent(event) {
131
+ if (!isRecord(event) || event.success !== true || !eventId(event))
132
+ return false;
133
+ if (CONTROL_EVENT_KINDS.has(event.event_kind))
134
+ return false;
135
+ const toolName = typeof event.tool_name === 'string' ? event.tool_name : '';
136
+ if (NON_BUSINESS_TOOL_PATTERN.test(toolName))
137
+ return false;
138
+ if (/(?:^|__)(?:brainbase_projects|brainbase_admin_read|brainbase_run_receipt_inbox|brainbase_run_receipt_history|authorize_tenant_resource)$/u.test(toolName)
139
+ && !/^mcp__brainbase(?:-|_)personal__brainbase_admin_read$/u.test(toolName))
140
+ return false;
141
+ if (/brainbase_(?:judgment_(?:node|audit|state|value_proof|frame)|knowledge_(?:resolve|evidence)|personal_kg_answer)(?:_|$)/u.test(toolName)) {
142
+ return false;
143
+ }
144
+ const safeMetadata = isRecord(event.safe_metadata) ? event.safe_metadata : undefined;
145
+ const retrievalOutcome = safeMetadata?.retrieval_outcome;
146
+ if (retrievalOutcome !== undefined && retrievalOutcome !== null && retrievalOutcome !== 'result')
147
+ return false;
148
+ if (isRecord(safeMetadata?.retrieval_evidence)
149
+ && safeMetadata.retrieval_evidence.status !== 'retrieved')
150
+ return false;
151
+ return true;
152
+ }
153
+ function isEarlierEvent(candidate, resultEvent) {
154
+ return eventSequence(candidate, 0) < eventSequence(resultEvent, Number.MAX_SAFE_INTEGER);
155
+ }
156
+ function evidenceForResult(result, resultEvent, eventsById, { required = true } = {}) {
157
+ if (required && result.status === 'supported' && result.evidence_tool_use_ids.length === 0)
158
+ return false;
159
+ return result.evidence_tool_use_ids.every((id) => {
160
+ const event = eventsById.get(id);
161
+ return Boolean(event && isEarlierEvent(event, resultEvent) && isSuccessfulJudgmentEvidenceEvent(event));
162
+ });
163
+ }
164
+ function resultRecord(result, event, sequence) {
165
+ return {
166
+ ...result,
167
+ tool_use_id: eventId(event),
168
+ event_sequence: sequence
169
+ };
170
+ }
171
+ function missingAction(node) {
172
+ const instruction = cleanText(node.instruction, MAX_TEXT_LENGTH);
173
+ return typeof instruction === 'string'
174
+ ? `実行: ${instruction}。完了後にこの段階の判断結果を記録してください。`
175
+ : `実行してから ${node.id} の判断結果を記録してください。`;
176
+ }
177
+ /**
178
+ * Evaluate the ordered result chain for a route receipt.
179
+ *
180
+ * Returned result entries contain only the normalized node result and its
181
+ * binding event id/sequence; event response bodies stay outside this module.
182
+ */
183
+ export function evaluateJudgmentNodeEvidence(events, receipt, { hostSupported = true } = {}) {
184
+ const nodes = contractNodes(receipt);
185
+ if (nodes.length === 0) {
186
+ return { required: false, ready: true, status: 'not_required', next_node: null, next_action: null, results: [] };
187
+ }
188
+ if (!hostSupported) {
189
+ return {
190
+ required: false,
191
+ ready: true,
192
+ status: 'host_unsupported',
193
+ next_node: null,
194
+ next_action: null,
195
+ results: [],
196
+ unsupported_node_ids: nodes.map((node) => node.id)
197
+ };
198
+ }
199
+ const orderedEvents = sortEvents(events);
200
+ const eventsById = new Map();
201
+ for (const entry of orderedEvents) {
202
+ const id = eventId(entry.event);
203
+ if (id && isRecord(entry.event) && !eventsById.has(id))
204
+ eventsById.set(id, entry.event);
205
+ }
206
+ const recordsByNode = new Map();
207
+ for (const entry of orderedEvents) {
208
+ if (!isRecord(entry.event))
209
+ continue;
210
+ if (entry.event.event_kind !== 'node_evidence' || entry.event.success !== true)
211
+ continue;
212
+ const safeMetadata = isRecord(entry.event.safe_metadata) ? entry.event.safe_metadata : undefined;
213
+ const normalized = normalizeJudgmentNodeResult(safeMetadata?.node_result);
214
+ if (!normalized)
215
+ continue;
216
+ const node = nodes.find((candidate) => candidate.id === normalized.node_id);
217
+ if (!node || !eventId(entry.event))
218
+ continue;
219
+ const record = { result: normalized, event: entry.event, sequence: entry.sequence };
220
+ const records = recordsByNode.get(normalized.node_id) ?? [];
221
+ records.push(record);
222
+ recordsByNode.set(normalized.node_id, records);
223
+ }
224
+ const latestResults = [];
225
+ let firstProblem = null;
226
+ let priorCurrentToolUseId = null;
227
+ let priorCurrentNodeId = null;
228
+ let priorCurrentSequence = null;
229
+ for (const node of nodes) {
230
+ const records = recordsByNode.get(node.id) ?? [];
231
+ const latest = records.at(-1) ?? null;
232
+ if (!latest) {
233
+ firstProblem = { status: 'missing', node, next_action: missingAction(node) };
234
+ break;
235
+ }
236
+ const normalized = latest.result;
237
+ const latestToolUseId = eventId(latest.event);
238
+ let valid = true;
239
+ let status = normalized.status;
240
+ let action = normalized.next_action;
241
+ if (normalized.previous_result_tool_use_id !== priorCurrentToolUseId
242
+ || (priorCurrentSequence !== null && latest.sequence <= priorCurrentSequence)) {
243
+ valid = false;
244
+ status = 'invalid';
245
+ action = `前段 ${priorCurrentNodeId ?? '開始'} の最新結果に結び直してから ${node.id} を再評価してください。`;
246
+ }
247
+ const evidenceRequired = node.id !== 'problem-frame';
248
+ if (valid && !evidenceForResult(normalized, latest.event, eventsById, { required: evidenceRequired })) {
249
+ valid = false;
250
+ status = 'invalid';
251
+ action = 'この段階の結論に対応する、先に実行した成功済み業務tool_use_idを記録して再評価してください。';
252
+ }
253
+ const priorInsufficient = [...records].reverse().find((record) => record !== latest && record.result.status === 'insufficient');
254
+ if (valid && priorInsufficient) {
255
+ const priorIds = new Set(priorInsufficient.result.evidence_tool_use_ids);
256
+ const hasNewEvidence = normalized.evidence_tool_use_ids.some((id) => {
257
+ const evidence = eventsById.get(id);
258
+ return Boolean(!priorIds.has(id)
259
+ && evidence
260
+ && eventSequence(evidence, -1) > priorInsufficient.sequence
261
+ && isEarlierEvent(evidence, latest.event)
262
+ && isSuccessfulJudgmentEvidenceEvent(evidence));
263
+ });
264
+ if (!hasNewEvidence) {
265
+ valid = false;
266
+ status = 'insufficient';
267
+ action = `不足した根拠を追加取得して ${node.id} を再評価してください。`;
268
+ }
269
+ }
270
+ if (!valid || normalized.status === 'insufficient') {
271
+ firstProblem = {
272
+ status: normalized.status === 'insufficient'
273
+ ? 'insufficient'
274
+ : status === 'insufficient' ? 'insufficient' : 'invalid',
275
+ node,
276
+ next_action: action
277
+ };
278
+ }
279
+ latestResults.push(resultRecord({ ...normalized, status }, latest.event, latest.sequence));
280
+ if (firstProblem)
281
+ break;
282
+ priorCurrentToolUseId = latestToolUseId;
283
+ priorCurrentNodeId = node.id;
284
+ priorCurrentSequence = latest.sequence;
285
+ }
286
+ if (firstProblem) {
287
+ return {
288
+ required: true,
289
+ ready: false,
290
+ status: firstProblem.status,
291
+ next_node: firstProblem.node.id,
292
+ next_action: firstProblem.next_action,
293
+ results: latestResults
294
+ };
295
+ }
296
+ return { required: true, ready: true, status: 'ready', next_node: null, next_action: null, results: latestResults };
297
+ }
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Pure judgment runtime resolver core.
3
+ *
4
+ * This module is intentionally free of filesystem, transport, authentication,
5
+ * tenant, Host binding, policy authorization, TaskGraph persistence, and
6
+ * receipt I/O. Callers must validate and authorize those inputs in an adapter,
7
+ * then pass only the normalized request and already-applicable policies here.
8
+ * The implementation is kept behaviorally aligned with the former Unson
9
+ * service so the Host can opt into it without changing live behavior.
10
+ */
11
+ import { JudgmentResolutionError, canonicalJson, computeRequestDigest, sha256Hex } from './judgment-resolution-contract.js';
12
+ export { JudgmentResolutionError, canonicalJson, computeRequestDigest, sha256Hex };
13
+ /**
14
+ * Public contract for the pure runtime resolver.
15
+ *
16
+ * The implementation below is intentionally kept in the compatibility layer
17
+ * while it is being moved out of the Unson service. These types describe the
18
+ * normalized boundary explicitly so a Host/Organization adapter cannot pass
19
+ * raw, unauthorised state by accident. Internal legacy helpers remain covered
20
+ * by the narrowly scoped `@ts-nocheck` migration exception above.
21
+ */
22
+ export type JudgmentRuntimeIntent = 'answer' | 'investigate' | 'diagnose' | 'design' | 'implement' | 'review' | 'operate';
23
+ export type JudgmentRuntimeDomain = 'general' | 'knowledge' | 'personal_judgment' | 'engineering' | 'organization' | 'operations';
24
+ export type JudgmentRuntimeSignal = 'cumulative_effect' | 'complexity_growth' | 'threshold_proposal' | 'parallel_exploration' | 'authority_boundary' | 'problem_frame_uncertain' | 'external_outcome';
25
+ export type JudgmentRuntimeActionKind = 'none' | 'read' | 'write' | 'external';
26
+ export type JudgmentRuntimeRisk = 'low' | 'medium' | 'high' | 'critical';
27
+ export type JudgmentRuntimeConfidence = 'confirmed' | 'inferred' | 'unknown';
28
+ export type JudgmentRuntimeStatus = 'resolved' | 'needs_classification' | 'needs_policy_resolution';
29
+ export type JudgmentRuntimeAutonomyDecision = 'continue' | 'escalate';
30
+ export interface JudgmentRuntimeClassification {
31
+ intent: JudgmentRuntimeIntent;
32
+ domains: JudgmentRuntimeDomain[];
33
+ action_kind: JudgmentRuntimeActionKind;
34
+ risk: JudgmentRuntimeRisk;
35
+ confidence: JudgmentRuntimeConfidence;
36
+ signals: JudgmentRuntimeSignal[];
37
+ }
38
+ export interface JudgmentRuntimeMessage {
39
+ sequence: number;
40
+ turn_id: string | null;
41
+ role: 'user' | 'assistant';
42
+ phase: string | null;
43
+ text: string;
44
+ }
45
+ export interface JudgmentRuntimePriorReceipt {
46
+ turn_id: string;
47
+ resolution_id: string;
48
+ request_digest: string;
49
+ context_digest: string | null;
50
+ plan_digest: string;
51
+ classification: JudgmentRuntimeClassification;
52
+ selected_dag_ids: string[];
53
+ }
54
+ export interface JudgmentRuntimeRuntimeContext {
55
+ host: 'codex' | 'claude-code';
56
+ entrypoint?: 'codex' | 'claude_code' | 'mana' | 'company_os' | 'unknown';
57
+ model: string | null;
58
+ permission_mode: string | null;
59
+ project_binding: string | null;
60
+ }
61
+ export interface JudgmentRuntimeInstructionBinding {
62
+ scope: string;
63
+ source_ref: string;
64
+ digest: string;
65
+ }
66
+ export interface JudgmentRuntimeConversationContext {
67
+ schema_version: 'brainbase-conversation-context-v1';
68
+ session_ref: string;
69
+ messages: JudgmentRuntimeMessage[];
70
+ prior_receipts: JudgmentRuntimePriorReceipt[];
71
+ runtime: JudgmentRuntimeRuntimeContext;
72
+ instruction_bindings: JudgmentRuntimeInstructionBinding[];
73
+ completeness: 'complete' | 'partial';
74
+ source_digest: string;
75
+ }
76
+ export interface JudgmentRuntimeInput {
77
+ request: string;
78
+ turn_id: string;
79
+ project_code: string | null;
80
+ conversation_context: JudgmentRuntimeConversationContext;
81
+ model_interpretation: JudgmentRuntimeClassification | null;
82
+ }
83
+ export interface JudgmentRuntimeManifestLockEntry {
84
+ runtime_version: string;
85
+ manifest_digest: string;
86
+ }
87
+ export interface JudgmentRuntimeManifestLock {
88
+ schema_version: 'brainbase-judgment-manifest-lock-v1';
89
+ entries: JudgmentRuntimeManifestLockEntry[];
90
+ }
91
+ export interface JudgmentRuntimeHostBinding {
92
+ adapter_id: string;
93
+ adapter_version: string;
94
+ status?: string;
95
+ [key: string]: unknown;
96
+ }
97
+ export interface JudgmentRuntimePolicyScope {
98
+ type: 'global' | 'organization' | 'project' | 'owner';
99
+ id: string | null;
100
+ }
101
+ export interface JudgmentRuntimePolicyEffect {
102
+ target: string;
103
+ decision: 'require' | 'forbid' | 'prefer';
104
+ }
105
+ export interface JudgmentRuntimeHumanApproval {
106
+ action_kinds?: JudgmentRuntimeActionKind[];
107
+ risks?: JudgmentRuntimeRisk[];
108
+ }
109
+ export interface JudgmentRuntimePolicy {
110
+ id: string;
111
+ version: string;
112
+ priority: number;
113
+ strength: 'hard' | 'soft';
114
+ scope: JudgmentRuntimePolicyScope;
115
+ visibility: 'organization' | 'owner';
116
+ owner_person_id: string | null;
117
+ evidence_requirement: string;
118
+ effect: JudgmentRuntimePolicyEffect;
119
+ instruction: string;
120
+ human_approval?: JudgmentRuntimeHumanApproval;
121
+ [key: string]: unknown;
122
+ }
123
+ export type JudgmentRuntimeNodeKind = 'common' | 'judgment' | 'capability' | 'constraint' | 'fail_closed';
124
+ export interface JudgmentRuntimeNode {
125
+ id: string;
126
+ kind: JudgmentRuntimeNodeKind;
127
+ instruction: string;
128
+ required_capability_template: string | null;
129
+ execution_contract?: string;
130
+ [key: string]: unknown;
131
+ }
132
+ export interface JudgmentRuntimeDag {
133
+ id: string;
134
+ kind: 'domain' | 'constraint' | 'fail_closed';
135
+ path: string[];
136
+ policy_ids: string[];
137
+ [key: string]: unknown;
138
+ }
139
+ export interface JudgmentRuntimeSelectors {
140
+ domain_order: JudgmentRuntimeDomain[];
141
+ signal_order: JudgmentRuntimeSignal[];
142
+ domain_dags: Record<JudgmentRuntimeDomain, string>;
143
+ signal_dags: Record<JudgmentRuntimeSignal, string>;
144
+ engineering_implementation_dag?: string;
145
+ authority_dag: string;
146
+ clarification_dag: string;
147
+ [key: string]: unknown;
148
+ }
149
+ export interface JudgmentRuntimeSemanticMatchers {
150
+ intents: Record<JudgmentRuntimeIntent, string[]>;
151
+ domains: Record<Exclude<JudgmentRuntimeDomain, 'general'>, string[]>;
152
+ signals: Record<JudgmentRuntimeSignal, string[]>;
153
+ safety: Record<'write' | 'external' | 'critical', string[]>;
154
+ positive_commands: string[];
155
+ follow_up: string[];
156
+ [key: string]: unknown;
157
+ }
158
+ export interface JudgmentRuntimeAutonomyPolicy {
159
+ schema_version: 'brainbase-autonomy-policy-v1';
160
+ continue_risks: JudgmentRuntimeRisk[];
161
+ escalate_risks: JudgmentRuntimeRisk[];
162
+ escalate_action_kinds: JudgmentRuntimeActionKind[];
163
+ runtime_escalation_reasons: string[];
164
+ [key: string]: unknown;
165
+ }
166
+ export interface JudgmentRuntimeManifest {
167
+ schema_version: 'brainbase-judgment-runtime-v1';
168
+ runtime_version: string;
169
+ host_bindings: JudgmentRuntimeHostBinding[];
170
+ policies: JudgmentRuntimePolicy[];
171
+ nodes: JudgmentRuntimeNode[];
172
+ dags: JudgmentRuntimeDag[];
173
+ composition_edges: Array<[string, string]>;
174
+ selectors: JudgmentRuntimeSelectors;
175
+ semantic_matchers: JudgmentRuntimeSemanticMatchers;
176
+ autonomy: JudgmentRuntimeAutonomyPolicy;
177
+ [key: string]: unknown;
178
+ }
179
+ export interface JudgmentRuntimeReconciliation {
180
+ status: 'resolved' | 'needs_classification';
181
+ classification: JudgmentRuntimeClassification | null;
182
+ assurance: 'verified' | 'bounded' | 'unknown';
183
+ reasons: string[];
184
+ evidence: Record<string, unknown>;
185
+ }
186
+ export interface JudgmentRuntimeAutonomyResolution {
187
+ autonomy_decision: JudgmentRuntimeAutonomyDecision;
188
+ autonomy_reason_code: 'routine_in_scope' | 'classification_missing' | 'policy_conflict' | 'risk_or_external';
189
+ allowed_runtime_escalation_reasons: string[];
190
+ autonomy_policy_ids: string[];
191
+ }
192
+ export interface JudgmentRuntimeGraph {
193
+ active_nodes: string[];
194
+ active_edges: Array<[string, string]>;
195
+ }
196
+ export interface JudgmentRuntimeCapability {
197
+ capability: string;
198
+ status: string;
199
+ input: Record<string, unknown>;
200
+ receipt_required: boolean;
201
+ [key: string]: unknown;
202
+ }
203
+ export interface JudgmentRuntimeSuppressedPolicy {
204
+ policy_id: string;
205
+ suppressed_by_policy_id: string;
206
+ reason: string;
207
+ }
208
+ export interface JudgmentRuntimePolicyMerge {
209
+ applicable: JudgmentRuntimePolicy[];
210
+ suppressed: JudgmentRuntimeSuppressedPolicy[];
211
+ conflict: boolean;
212
+ }
213
+ export interface JudgmentRuntimeResolutionPlan extends JudgmentRuntimeAutonomyResolution, JudgmentRuntimeGraph {
214
+ status: JudgmentRuntimeStatus;
215
+ reconciliation: JudgmentRuntimeReconciliation;
216
+ selected_dag_ids: string[];
217
+ applicable_policies: JudgmentRuntimePolicy[];
218
+ suppressed_policies: JudgmentRuntimeSuppressedPolicy[];
219
+ policy_conflict: boolean;
220
+ required_capabilities: JudgmentRuntimeCapability[];
221
+ active_node_definitions: JudgmentRuntimeNode[];
222
+ unresolved: string[];
223
+ rationale: string[];
224
+ }
225
+ export interface JudgmentRuntimeCoreInput {
226
+ input: JudgmentRuntimeInput;
227
+ manifest: JudgmentRuntimeManifest;
228
+ /** Policies already filtered by the Organization/Host authorization adapter. */
229
+ applicablePolicies?: JudgmentRuntimePolicy[];
230
+ ownerPersonId?: string | null;
231
+ clientCapabilities?: string[];
232
+ }
233
+ export interface JudgmentRuntimeGraphOptions {
234
+ clarification?: boolean;
235
+ }
236
+ export interface JudgmentRuntimeActiveNodeOptions {
237
+ evidenceRequired?: boolean;
238
+ }
239
+ export declare function validateManifestLock(lock: JudgmentRuntimeManifestLock, previous?: JudgmentRuntimeManifestLock | null, current?: {
240
+ runtimeVersion: string;
241
+ manifestDigest: string;
242
+ } | null): true;
243
+ export declare function validateManifest(manifest: JudgmentRuntimeManifest, lock: JudgmentRuntimeManifestLock): string;
244
+ export declare function autonomyResolution(status: JudgmentRuntimeStatus, classification: JudgmentRuntimeClassification | null, manifest: JudgmentRuntimeManifest, applicablePolicies?: JudgmentRuntimePolicy[]): JudgmentRuntimeAutonomyResolution;
245
+ export declare function validateRuntimeInput(rawInput: unknown, manifest: JudgmentRuntimeManifest): JudgmentRuntimeInput;
246
+ export declare function reconcileModelInterpretation(input: JudgmentRuntimeInput, manifest: JudgmentRuntimeManifest): JudgmentRuntimeReconciliation;
247
+ export declare function classify(input: JudgmentRuntimeInput, manifest: JudgmentRuntimeManifest): JudgmentRuntimeReconciliation;
248
+ export declare function materializePolicy(policy: JudgmentRuntimePolicy, ownerPersonId: string | null): JudgmentRuntimePolicy;
249
+ export declare function mergePolicies(policies: JudgmentRuntimePolicy[]): JudgmentRuntimePolicyMerge;
250
+ export declare function selectedDags(classification: JudgmentRuntimeClassification, manifest: JudgmentRuntimeManifest): string[];
251
+ export declare function buildGraph(dagIds: string[], manifest: JudgmentRuntimeManifest, { clarification }?: JudgmentRuntimeGraphOptions): JudgmentRuntimeGraph;
252
+ export declare function materializeActiveNodeDefinitions(activeNodes: string[], manifest: JudgmentRuntimeManifest, { evidenceRequired }?: JudgmentRuntimeActiveNodeOptions): JudgmentRuntimeNode[];
253
+ export declare function topologicallySortNodes(nodes: string[], edges: Array<[string, string]>): string[];
254
+ export declare const JUDGMENT_FRAME_CAPABILITY = "judgment.frame";
255
+ export declare function isJudgmentBearing(classification: JudgmentRuntimeClassification | null): boolean;
256
+ export declare function frameCapabilities(input: JudgmentRuntimeInput, classification: JudgmentRuntimeClassification | null, clientCapabilities: ReadonlySet<string>, status: JudgmentRuntimeStatus): JudgmentRuntimeCapability[];
257
+ export declare function knowledgeCapabilities(input: JudgmentRuntimeInput, classification: JudgmentRuntimeClassification | null): JudgmentRuntimeCapability[];
258
+ /**
259
+ * Resolve the deterministic runtime plan from normalized, already-authorized
260
+ * inputs. `applicablePolicies` must have been filtered by the Org/Host adapter;
261
+ * this core deliberately has no access or tenant lookup and never broadens a
262
+ * deny decision.
263
+ */
264
+ export declare function resolveJudgmentRuntimeCore({ input, manifest, applicablePolicies, ownerPersonId, clientCapabilities }: JudgmentRuntimeCoreInput): JudgmentRuntimeResolutionPlan;