@unson/brainbase-mcp 0.51.4 → 0.51.6

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,24 +1,45 @@
1
- import { z } from 'zod';
2
1
  import type { JudgmentToolEvent } from './judgment-host.js';
3
- export declare const taskProgressScopeSchema: z.ZodObject<{
4
- task_ref: z.ZodString;
5
- criterion_ref: z.ZodString;
6
- contract_revision: z.ZodString;
7
- }, z.core.$strict>;
8
- export declare const taskProgressObservationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
9
- kind: z.ZodLiteral<"preparation_only">;
10
- evidence_tool_use_ids: z.ZodArray<z.ZodString>;
11
- }, z.core.$strict>, z.ZodObject<{
12
- kind: z.ZodLiteral<"waiting">;
13
- }, z.core.$strict>, z.ZodObject<{
14
- kind: z.ZodLiteral<"verified_outcome">;
15
- outcome: z.ZodEnum<{
16
- criterion_advanced: "criterion_advanced";
17
- new_negative_result: "new_negative_result";
18
- }>;
19
- evidence_tool_use_ids: z.ZodArray<z.ZodString>;
20
- verification_ref: z.ZodString;
21
- }, z.core.$strict>], "kind">;
2
+ export type TaskProgressValidationIssueCode = 'invalid_type' | 'too_small' | 'too_big' | 'unrecognized_keys' | 'invalid_union' | 'invalid_value' | 'custom';
3
+ export interface TaskProgressValidationIssue {
4
+ code?: TaskProgressValidationIssueCode;
5
+ keys?: string[];
6
+ path: (string | number)[];
7
+ message: string;
8
+ }
9
+ export declare class TaskProgressValidationError extends Error {
10
+ readonly issues: readonly TaskProgressValidationIssue[];
11
+ constructor(issues: readonly TaskProgressValidationIssue[]);
12
+ }
13
+ export type TaskProgressSafeParseResult<T> = {
14
+ success: true;
15
+ data: T;
16
+ } | {
17
+ success: false;
18
+ error: TaskProgressValidationError;
19
+ };
20
+ export interface TaskProgressSchema<T> {
21
+ parse(input: unknown): T;
22
+ safeParse(input: unknown): TaskProgressSafeParseResult<T>;
23
+ }
24
+ export interface TaskProgressScope {
25
+ task_ref: string;
26
+ criterion_ref: string;
27
+ contract_revision: string;
28
+ }
29
+ export type TaskProgressVerifiedOutcome = 'criterion_advanced' | 'new_negative_result';
30
+ export type TaskProgressObservation = {
31
+ kind: 'preparation_only';
32
+ evidence_tool_use_ids: string[];
33
+ } | {
34
+ kind: 'waiting';
35
+ } | {
36
+ kind: 'verified_outcome';
37
+ outcome: TaskProgressVerifiedOutcome;
38
+ evidence_tool_use_ids: string[];
39
+ verification_ref: string;
40
+ };
41
+ export declare const taskProgressScopeSchema: TaskProgressSchema<TaskProgressScope>;
42
+ export declare const taskProgressObservationSchema: TaskProgressSchema<TaskProgressObservation>;
22
43
  export interface JudgmentTaskProgressSnapshot {
23
44
  episode_digest: string;
24
45
  event_set_digest: string;
@@ -31,10 +52,10 @@ export interface JudgmentTaskProgressSnapshot {
31
52
  * Neither callback is provided by default or invokes a paid model internally.
32
53
  */
33
54
  export interface JudgmentTaskProgressAdapter {
34
- scope: z.infer<typeof taskProgressScopeSchema>;
35
- assess(snapshot: JudgmentTaskProgressSnapshot): Promise<z.infer<typeof taskProgressObservationSchema>>;
55
+ scope: TaskProgressScope;
56
+ assess(snapshot: JudgmentTaskProgressSnapshot): Promise<TaskProgressObservation>;
36
57
  verifyOutcome(snapshot: JudgmentTaskProgressSnapshot & {
37
- observation: Extract<z.infer<typeof taskProgressObservationSchema>, {
58
+ observation: Extract<TaskProgressObservation, {
38
59
  kind: 'verified_outcome';
39
60
  }>;
40
61
  }): Promise<boolean>;
@@ -1,18 +1,177 @@
1
- import { z } from 'zod';
2
- const reference = z.string().trim().min(1).max(512);
3
- export const taskProgressScopeSchema = z.object({
4
- task_ref: reference,
5
- criterion_ref: reference,
6
- contract_revision: reference
7
- }).strict();
8
- const evidenceIds = z.array(reference).min(1).refine((ids) => new Set(ids).size === ids.length);
9
- export const taskProgressObservationSchema = z.discriminatedUnion('kind', [
10
- z.object({ kind: z.literal('preparation_only'), evidence_tool_use_ids: evidenceIds }).strict(),
11
- z.object({ kind: z.literal('waiting') }).strict(),
12
- z.object({
13
- kind: z.literal('verified_outcome'),
14
- outcome: z.enum(['criterion_advanced', 'new_negative_result']),
15
- evidence_tool_use_ids: evidenceIds,
16
- verification_ref: reference
17
- }).strict()
18
- ]);
1
+ export class TaskProgressValidationError extends Error {
2
+ issues;
3
+ constructor(issues) {
4
+ const summary = issues
5
+ .map((issue) => (issue.path.length > 0 ? `${issue.path.join('.')}: ${issue.message}` : issue.message))
6
+ .join('; ');
7
+ super(summary || 'Invalid task progress value');
8
+ this.name = 'TaskProgressValidationError';
9
+ this.issues = issues;
10
+ }
11
+ }
12
+ const MAX_REFERENCE_LENGTH = 512;
13
+ const SCOPE_KEYS = new Set(['task_ref', 'criterion_ref', 'contract_revision']);
14
+ const PREPARATION_ONLY_KEYS = new Set(['kind', 'evidence_tool_use_ids']);
15
+ const WAITING_KEYS = new Set(['kind']);
16
+ const VERIFIED_OUTCOME_KEYS = new Set(['kind', 'outcome', 'evidence_tool_use_ids', 'verification_ref']);
17
+ const VERIFIED_OUTCOMES = new Set(['criterion_advanced', 'new_negative_result']);
18
+ function isObjectRecord(value) {
19
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
20
+ }
21
+ function collectUnknownKeyIssues(record, allowedKeys, issues) {
22
+ const seen = new Set();
23
+ const unknownKeys = [];
24
+ for (const key in record) {
25
+ if (seen.has(key)) {
26
+ continue;
27
+ }
28
+ seen.add(key);
29
+ if (!allowedKeys.has(key)) {
30
+ unknownKeys.push(key);
31
+ }
32
+ }
33
+ if (unknownKeys.length > 0) {
34
+ issues.push({
35
+ code: 'unrecognized_keys',
36
+ keys: unknownKeys,
37
+ path: [],
38
+ message: `Unrecognized key(s) in object: ${unknownKeys.map((key) => `'${key}'`).join(', ')}`
39
+ });
40
+ }
41
+ }
42
+ function parseReference(value, path, issues) {
43
+ if (typeof value !== 'string') {
44
+ issues.push({ code: 'invalid_type', path, message: 'Expected string' });
45
+ return undefined;
46
+ }
47
+ const trimmed = value.trim();
48
+ if (trimmed.length < 1) {
49
+ issues.push({ code: 'too_small', path, message: 'String must contain at least 1 character(s)' });
50
+ return undefined;
51
+ }
52
+ if (trimmed.length > MAX_REFERENCE_LENGTH) {
53
+ issues.push({ code: 'too_big', path, message: `String must contain at most ${MAX_REFERENCE_LENGTH} character(s)` });
54
+ return undefined;
55
+ }
56
+ return trimmed;
57
+ }
58
+ function parseEvidenceIds(value, path, issues) {
59
+ if (!Array.isArray(value)) {
60
+ issues.push({ code: 'invalid_type', path, message: 'Expected array' });
61
+ return undefined;
62
+ }
63
+ if (value.length < 1) {
64
+ issues.push({ code: 'too_small', path, message: 'Array must contain at least 1 element(s)' });
65
+ return undefined;
66
+ }
67
+ const parsed = [];
68
+ const startIssueCount = issues.length;
69
+ for (let index = 0; index < value.length; index += 1) {
70
+ const item = parseReference(value[index], [...path, index], issues);
71
+ if (item !== undefined) {
72
+ parsed.push(item);
73
+ }
74
+ }
75
+ if (issues.length > startIssueCount) {
76
+ return undefined;
77
+ }
78
+ if (new Set(parsed).size !== parsed.length) {
79
+ issues.push({ code: 'custom', path, message: 'Array elements must be unique' });
80
+ return undefined;
81
+ }
82
+ return parsed;
83
+ }
84
+ function createSchema(validate) {
85
+ const safeParse = (input) => {
86
+ const issues = [];
87
+ const data = validate(input, issues);
88
+ if (issues.length > 0 || data === undefined) {
89
+ return {
90
+ success: false,
91
+ error: new TaskProgressValidationError(issues.length > 0 ? issues : [{ path: [], message: 'Invalid value' }])
92
+ };
93
+ }
94
+ return { success: true, data };
95
+ };
96
+ return {
97
+ safeParse,
98
+ parse(input) {
99
+ const result = safeParse(input);
100
+ if (!result.success) {
101
+ throw result.error;
102
+ }
103
+ return result.data;
104
+ }
105
+ };
106
+ }
107
+ export const taskProgressScopeSchema = createSchema((input, issues) => {
108
+ if (!isObjectRecord(input)) {
109
+ issues.push({ code: 'invalid_type', path: [], message: 'Expected object' });
110
+ return undefined;
111
+ }
112
+ collectUnknownKeyIssues(input, SCOPE_KEYS, issues);
113
+ const task_ref = parseReference(input['task_ref'], ['task_ref'], issues);
114
+ const criterion_ref = parseReference(input['criterion_ref'], ['criterion_ref'], issues);
115
+ const contract_revision = parseReference(input['contract_revision'], ['contract_revision'], issues);
116
+ if (issues.length > 0 || task_ref === undefined || criterion_ref === undefined || contract_revision === undefined) {
117
+ return undefined;
118
+ }
119
+ return { task_ref, criterion_ref, contract_revision };
120
+ });
121
+ export const taskProgressObservationSchema = createSchema((input, issues) => {
122
+ if (!isObjectRecord(input)) {
123
+ issues.push({ code: 'invalid_type', path: [], message: 'Expected object' });
124
+ return undefined;
125
+ }
126
+ const kind = input['kind'];
127
+ if (kind === 'preparation_only') {
128
+ collectUnknownKeyIssues(input, PREPARATION_ONLY_KEYS, issues);
129
+ const evidence_tool_use_ids = parseEvidenceIds(input['evidence_tool_use_ids'], ['evidence_tool_use_ids'], issues);
130
+ if (issues.length > 0 || evidence_tool_use_ids === undefined) {
131
+ return undefined;
132
+ }
133
+ return { kind: 'preparation_only', evidence_tool_use_ids };
134
+ }
135
+ if (kind === 'waiting') {
136
+ collectUnknownKeyIssues(input, WAITING_KEYS, issues);
137
+ if (issues.length > 0) {
138
+ return undefined;
139
+ }
140
+ return { kind: 'waiting' };
141
+ }
142
+ if (kind === 'verified_outcome') {
143
+ collectUnknownKeyIssues(input, VERIFIED_OUTCOME_KEYS, issues);
144
+ const rawOutcome = input['outcome'];
145
+ let outcome;
146
+ if (typeof rawOutcome === 'string' && VERIFIED_OUTCOMES.has(rawOutcome)) {
147
+ outcome = rawOutcome;
148
+ }
149
+ else {
150
+ issues.push({
151
+ code: 'invalid_value',
152
+ path: ['outcome'],
153
+ message: "Expected 'criterion_advanced' | 'new_negative_result'"
154
+ });
155
+ }
156
+ const evidence_tool_use_ids = parseEvidenceIds(input['evidence_tool_use_ids'], ['evidence_tool_use_ids'], issues);
157
+ const verification_ref = parseReference(input['verification_ref'], ['verification_ref'], issues);
158
+ if (issues.length > 0
159
+ || outcome === undefined
160
+ || evidence_tool_use_ids === undefined
161
+ || verification_ref === undefined) {
162
+ return undefined;
163
+ }
164
+ return {
165
+ kind: 'verified_outcome',
166
+ outcome,
167
+ evidence_tool_use_ids,
168
+ verification_ref
169
+ };
170
+ }
171
+ issues.push({
172
+ code: 'invalid_union',
173
+ path: ['kind'],
174
+ message: "Invalid discriminator value. Expected 'preparation_only' | 'waiting' | 'verified_outcome'"
175
+ });
176
+ return undefined;
177
+ });
@@ -366,9 +366,11 @@ export function buildOrganizationKnowledgeEvent(request, normalized, summary, ev
366
366
  const isDecision = normalized.kind === 'decision';
367
367
  const personal = request.approval_kind === 'personal_share';
368
368
  const decisionAuthority = isDecision
369
- // A personal decision is the owner's; a candidate decision is owned by the approver
370
- // whose decision authority the organization policy verified.
371
- ? { authorized: true, decider_id: personal ? request.owner_person_id : approverPersonId, domain: normalized.decision_domain }
369
+ // Any decision promoted into the organization Graph is decided by the approver whose
370
+ // RACI decision authority the organization review policy verified — including
371
+ // `personal_share` (where `request.owner_person_id` remains the requester/owner
372
+ // for provenance, lineage, consent, and withdrawal, not the organization decider).
373
+ ? { authorized: true, decider_id: approverPersonId, domain: normalized.decision_domain }
372
374
  : { authorized: true, decider_id: approverPersonId, domain: 'organization_knowledge_review' };
373
375
  return {
374
376
  schema_version: 'knowledge_event.v1',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unson/brainbase-mcp",
3
- "version": "0.51.4",
3
+ "version": "0.51.6",
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",
@@ -673,5 +673,5 @@
673
673
  "url": "https://github.com/Unson-LLC/brainbase/issues"
674
674
  },
675
675
  "homepage": "https://github.com/Unson-LLC/brainbase#readme",
676
- "gitHead": "e743dbcbce098f7886dcf2b087a2ec78dd59fae8"
676
+ "gitHead": "e249e7f92f904b813c9725c11bed012049b8f227"
677
677
  }