@unson/brainbase-mcp 0.48.3 → 0.49.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.
- package/dist/entity-indexer.d.ts +291 -0
- package/dist/entity-indexer.js +288 -0
- package/dist/judgment-frame.d.ts +24 -0
- package/dist/judgment-frame.js +45 -3
- package/dist/judgment-history.d.ts +1 -1
- package/dist/judgment-history.js +1 -0
- package/dist/worker-judgment-emit-cli.d.ts +18 -0
- package/dist/worker-judgment-emit-cli.js +98 -0
- package/dist/worker-judgment-emitter.d.ts +136 -0
- package/dist/worker-judgment-emitter.js +457 -0
- package/package.json +6 -2
- package/ui/brainbase-tokens.css +10 -0
- package/ui/graph-registry-view.js +2 -2
- package/ui/inbox.css +1 -1
- package/ui/inbox.js +4 -4
- package/ui/local-web-shell.css +1 -1
- package/ui/people-and-companies-view.css +0 -11
- package/ui/project-workspace.js +3 -2
- package/ui/workspace-kit.css +26 -6
- package/ui/workspace-kit.js +119 -5
- package/ui/world/world-canvas-ui.css +2 -2
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/** Reusable, source-independent entity index builder. */
|
|
2
|
+
/** Source-projected evidence; interpretation remains with the consumer. */
|
|
3
|
+
export type RetrievalEvidence = Partial<Record<'content' | 'statement' | 'decision' | 'rationale' | 'body' | 'markdown' | 'body_summary' | 'summary' | 'description' | 'notes' | 'source_pointer' | 'provenance', unknown>>;
|
|
4
|
+
export interface BaseEntity {
|
|
5
|
+
graph_entity_id?: string;
|
|
6
|
+
retrieval_evidence?: RetrievalEvidence;
|
|
7
|
+
id: string;
|
|
8
|
+
filePath: string;
|
|
9
|
+
updated?: string;
|
|
10
|
+
project_code?: string;
|
|
11
|
+
source?: string;
|
|
12
|
+
source_path?: string;
|
|
13
|
+
legacy_source_path?: string;
|
|
14
|
+
lifecycle_status?: string;
|
|
15
|
+
lifecycle_state?: string;
|
|
16
|
+
semantic_state?: string;
|
|
17
|
+
canonical_entity_id?: string;
|
|
18
|
+
version?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface Project extends BaseEntity {
|
|
21
|
+
type: 'project';
|
|
22
|
+
project_id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
aliases?: string[];
|
|
25
|
+
status: 'active' | 'paused' | 'archived' | string;
|
|
26
|
+
team: string[];
|
|
27
|
+
orgs: string[];
|
|
28
|
+
apps: string[];
|
|
29
|
+
customers: string[];
|
|
30
|
+
content: string;
|
|
31
|
+
beta_partners?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface Person extends BaseEntity {
|
|
34
|
+
type: 'person';
|
|
35
|
+
name: string;
|
|
36
|
+
role: string;
|
|
37
|
+
org: string;
|
|
38
|
+
org_tags: string[];
|
|
39
|
+
projects: string[];
|
|
40
|
+
aliases: string[];
|
|
41
|
+
status: 'active' | 'inactive' | 'stakeholder' | string;
|
|
42
|
+
content: string;
|
|
43
|
+
}
|
|
44
|
+
export interface Organization extends BaseEntity {
|
|
45
|
+
type: 'org';
|
|
46
|
+
org_id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
aliases: string[];
|
|
49
|
+
orgType: 'legal_entity' | 'brand' | 'internal' | 'partner' | string;
|
|
50
|
+
content: string;
|
|
51
|
+
}
|
|
52
|
+
export interface Brand extends BaseEntity {
|
|
53
|
+
type: 'brand';
|
|
54
|
+
name: string;
|
|
55
|
+
scope?: 'org' | 'product' | 'personal' | 'campaign' | string;
|
|
56
|
+
owner_entity_id?: string;
|
|
57
|
+
related_orgs: string[];
|
|
58
|
+
related_apps: string[];
|
|
59
|
+
tagline?: string;
|
|
60
|
+
positioning?: string;
|
|
61
|
+
voice?: string | string[];
|
|
62
|
+
do: string[];
|
|
63
|
+
dont: string[];
|
|
64
|
+
visual_assets: string[];
|
|
65
|
+
aliases: string[];
|
|
66
|
+
content: string;
|
|
67
|
+
}
|
|
68
|
+
export interface RACI extends BaseEntity {
|
|
69
|
+
type: 'raci';
|
|
70
|
+
org_id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
members: string[];
|
|
73
|
+
positions: PositionEntry[];
|
|
74
|
+
decisions: DecisionEntry[];
|
|
75
|
+
assignments: AssignmentEntry[];
|
|
76
|
+
products: string[];
|
|
77
|
+
content: string;
|
|
78
|
+
entries?: RACIEntry[];
|
|
79
|
+
project_id?: string;
|
|
80
|
+
}
|
|
81
|
+
export interface PositionEntry {
|
|
82
|
+
person: string;
|
|
83
|
+
assets: string;
|
|
84
|
+
authority: string;
|
|
85
|
+
}
|
|
86
|
+
export interface DecisionEntry {
|
|
87
|
+
domain: string;
|
|
88
|
+
decider: string;
|
|
89
|
+
}
|
|
90
|
+
export interface AssignmentEntry {
|
|
91
|
+
person: string;
|
|
92
|
+
areas: string;
|
|
93
|
+
}
|
|
94
|
+
export interface RACIEntry {
|
|
95
|
+
item: string;
|
|
96
|
+
responsible: string;
|
|
97
|
+
accountable: string;
|
|
98
|
+
consulted: string;
|
|
99
|
+
informed: string;
|
|
100
|
+
}
|
|
101
|
+
export interface AppRepositoryRef {
|
|
102
|
+
owner?: string;
|
|
103
|
+
repo?: string;
|
|
104
|
+
url?: string;
|
|
105
|
+
ref?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface AppEnvironmentEndpoints {
|
|
108
|
+
api?: string;
|
|
109
|
+
health?: string;
|
|
110
|
+
nocodb?: string;
|
|
111
|
+
ssot_graph?: string;
|
|
112
|
+
url?: string;
|
|
113
|
+
worker?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface AppEnvironmentProfile {
|
|
116
|
+
mode?: string;
|
|
117
|
+
host?: string;
|
|
118
|
+
region?: string;
|
|
119
|
+
instance?: string;
|
|
120
|
+
url?: string;
|
|
121
|
+
ui_url?: string;
|
|
122
|
+
worktree_ui_url?: string;
|
|
123
|
+
endpoint?: string;
|
|
124
|
+
worker?: string;
|
|
125
|
+
runtime?: string;
|
|
126
|
+
ai_service?: string;
|
|
127
|
+
data_services?: string[];
|
|
128
|
+
async_services?: string[];
|
|
129
|
+
mobile_runtime?: string;
|
|
130
|
+
functions?: string[];
|
|
131
|
+
purpose?: string;
|
|
132
|
+
endpoints?: AppEnvironmentEndpoints;
|
|
133
|
+
}
|
|
134
|
+
export interface AppOperationalProfileCoverage {
|
|
135
|
+
available_fields: string[];
|
|
136
|
+
omitted_fields: string[];
|
|
137
|
+
}
|
|
138
|
+
export interface App extends BaseEntity {
|
|
139
|
+
type: 'app';
|
|
140
|
+
app_id: string;
|
|
141
|
+
name: string;
|
|
142
|
+
project: string;
|
|
143
|
+
orgs: string[];
|
|
144
|
+
status: string;
|
|
145
|
+
description: string;
|
|
146
|
+
summary?: string;
|
|
147
|
+
projects?: string[];
|
|
148
|
+
repository?: AppRepositoryRef;
|
|
149
|
+
parent_project?: string;
|
|
150
|
+
parent_project_entity_id?: string;
|
|
151
|
+
environments?: Record<string, AppEnvironmentProfile>;
|
|
152
|
+
record_class?: string;
|
|
153
|
+
service_profile_eligible?: boolean;
|
|
154
|
+
operational_profile_coverage?: AppOperationalProfileCoverage;
|
|
155
|
+
}
|
|
156
|
+
export interface Customer extends BaseEntity {
|
|
157
|
+
type: 'customer';
|
|
158
|
+
customer_id: string;
|
|
159
|
+
name: string;
|
|
160
|
+
salesOrg: string;
|
|
161
|
+
implOrg: string;
|
|
162
|
+
project: string;
|
|
163
|
+
contractType: string;
|
|
164
|
+
upfront: string;
|
|
165
|
+
status: string;
|
|
166
|
+
notes: string;
|
|
167
|
+
}
|
|
168
|
+
export interface Partner extends BaseEntity {
|
|
169
|
+
type: 'partner';
|
|
170
|
+
name: string;
|
|
171
|
+
status: string;
|
|
172
|
+
org: string;
|
|
173
|
+
projects: string[];
|
|
174
|
+
aliases: string[];
|
|
175
|
+
content: string;
|
|
176
|
+
}
|
|
177
|
+
export interface Decision extends BaseEntity {
|
|
178
|
+
type: 'decision';
|
|
179
|
+
decision_id: string;
|
|
180
|
+
title: string;
|
|
181
|
+
content: string;
|
|
182
|
+
decided_at: string;
|
|
183
|
+
decider: string;
|
|
184
|
+
project_id?: string;
|
|
185
|
+
meeting_id?: string;
|
|
186
|
+
status: 'active' | 'superseded' | 'deprecated' | string;
|
|
187
|
+
tags: string[];
|
|
188
|
+
}
|
|
189
|
+
export interface GlossaryTerm extends BaseEntity {
|
|
190
|
+
type: 'glossary_term';
|
|
191
|
+
term: string;
|
|
192
|
+
name: string;
|
|
193
|
+
canonical?: string;
|
|
194
|
+
aliases: string[];
|
|
195
|
+
description: string;
|
|
196
|
+
content: string;
|
|
197
|
+
}
|
|
198
|
+
export interface Document extends BaseEntity {
|
|
199
|
+
type: 'document';
|
|
200
|
+
title: string;
|
|
201
|
+
name: string;
|
|
202
|
+
path?: string;
|
|
203
|
+
tags: string[];
|
|
204
|
+
content: string;
|
|
205
|
+
}
|
|
206
|
+
export interface ExtensionEntity extends BaseEntity {
|
|
207
|
+
type: string;
|
|
208
|
+
name: string;
|
|
209
|
+
title?: string;
|
|
210
|
+
status?: string;
|
|
211
|
+
payload: Record<string, unknown>;
|
|
212
|
+
content: string;
|
|
213
|
+
}
|
|
214
|
+
export type Entity = Project | Person | Organization | Brand | RACI | App | Customer | Partner | Decision | GlossaryTerm | Document;
|
|
215
|
+
export type EntityType = 'project' | 'person' | 'org' | 'brand' | 'raci' | 'app' | 'customer' | 'partner' | 'decision' | 'glossary_term' | 'document';
|
|
216
|
+
export interface EntityIndex {
|
|
217
|
+
projects: Map<string, Project>;
|
|
218
|
+
people: Map<string, Person>;
|
|
219
|
+
orgs: Map<string, Organization>;
|
|
220
|
+
brands: Map<string, Brand>;
|
|
221
|
+
raci: Map<string, RACI>;
|
|
222
|
+
apps: Map<string, App>;
|
|
223
|
+
customers: Map<string, Customer>;
|
|
224
|
+
partners: Map<string, Partner>;
|
|
225
|
+
decisions: Map<string, Decision>;
|
|
226
|
+
glossaryTerms: Map<string, GlossaryTerm>;
|
|
227
|
+
documents: Map<string, Document>;
|
|
228
|
+
extensions: Map<string, Map<string, ExtensionEntity>>;
|
|
229
|
+
aliasToPersonId: Map<string, string>;
|
|
230
|
+
aliasToOrgId: Map<string, string>;
|
|
231
|
+
aliasToBrandId: Map<string, string>;
|
|
232
|
+
replacedIdToCanonicalId: Map<EntityType, Map<string, string>>;
|
|
233
|
+
}
|
|
234
|
+
export type EntityTypeCategory = 'core' | 'extension';
|
|
235
|
+
export type EntityTypeRegistration = {
|
|
236
|
+
type: string;
|
|
237
|
+
category: EntityTypeCategory;
|
|
238
|
+
storageType?: string;
|
|
239
|
+
displayName: string;
|
|
240
|
+
description: string;
|
|
241
|
+
defaultSearch: boolean;
|
|
242
|
+
};
|
|
243
|
+
export declare const CORE_ENTITY_TYPES: readonly ["project", "person", "org", "brand", "app", "customer", "partner", "decision", "raci", "glossary_term", "document"];
|
|
244
|
+
export declare const EXTENSION_ENTITY_TYPES: readonly ["contact", "frame", "story", "infrastructure_environment", "speaking", "media_appearance", "role_assignment", "product", "initiative", "publication", "press_mention"];
|
|
245
|
+
export type CoreEntityType = typeof CORE_ENTITY_TYPES[number];
|
|
246
|
+
export type ExtensionEntityType = typeof EXTENSION_ENTITY_TYPES[number] | string;
|
|
247
|
+
export declare const ENTITY_TYPE_REGISTRY: EntityTypeRegistration[];
|
|
248
|
+
export declare const EXTENSION_ENTITY_TYPE_SET: Set<string>;
|
|
249
|
+
export declare function getStorageType(publicType: string): string;
|
|
250
|
+
export declare function getPublicType(storageType: string): string;
|
|
251
|
+
export declare function getExtensionRegistrations(): EntityTypeRegistration[];
|
|
252
|
+
export declare function getGraphFetchTypes(): string[];
|
|
253
|
+
export interface EntitySource {
|
|
254
|
+
initialize(): Promise<void>;
|
|
255
|
+
getProjects(): Promise<Project[]>;
|
|
256
|
+
getPeople(): Promise<Person[]>;
|
|
257
|
+
getOrganizations(): Promise<Organization[]>;
|
|
258
|
+
getBrands(): Promise<Brand[]>;
|
|
259
|
+
getRACIs(): Promise<RACI[]>;
|
|
260
|
+
getApps(): Promise<App[]>;
|
|
261
|
+
getCustomers(): Promise<Customer[]>;
|
|
262
|
+
getPartners(): Promise<Partner[]>;
|
|
263
|
+
getDecisions(): Promise<Decision[]>;
|
|
264
|
+
getGlossaryTerms(): Promise<GlossaryTerm[]>;
|
|
265
|
+
getDocuments(): Promise<Document[]>;
|
|
266
|
+
getExtensionTypeRegistrations(): Promise<EntityTypeRegistration[]>;
|
|
267
|
+
getExtensionEntities(type: string): Promise<ExtensionEntity[]>;
|
|
268
|
+
}
|
|
269
|
+
export interface LifecycleRecord {
|
|
270
|
+
lifecycle_status?: unknown;
|
|
271
|
+
lifecycle_state?: unknown;
|
|
272
|
+
semantic_state?: unknown;
|
|
273
|
+
status?: unknown;
|
|
274
|
+
payload?: unknown;
|
|
275
|
+
}
|
|
276
|
+
/** Return false only when a record explicitly carries a known inactive state. */
|
|
277
|
+
export declare function isActiveLifecycle(record: LifecycleRecord): boolean;
|
|
278
|
+
/** A person is active only when both identity status and lifecycle are active. */
|
|
279
|
+
export declare function isActiveCanonicalPerson(person: LifecycleRecord): boolean;
|
|
280
|
+
export declare function createEmptyIndex(): EntityIndex;
|
|
281
|
+
export declare function isReplacedLifecycle(entity: {
|
|
282
|
+
lifecycle_status?: string;
|
|
283
|
+
lifecycle_state?: string;
|
|
284
|
+
}): boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Build the complete entity index from EntitySource
|
|
287
|
+
* Host revision must be cheap, stable, and change on every indexed create/update/retire/delete.
|
|
288
|
+
* Without such a marker, rebuild per refresh or use a rejecting cache revision (no commit).
|
|
289
|
+
* Never use fresh random/timestamp revisions: before/after mismatch throws after 3 builds.
|
|
290
|
+
*/
|
|
291
|
+
export declare function buildIndex(source: EntitySource): Promise<EntityIndex>;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/** Reusable, source-independent entity index builder. */
|
|
2
|
+
export const CORE_ENTITY_TYPES = [
|
|
3
|
+
'project',
|
|
4
|
+
'person',
|
|
5
|
+
'org',
|
|
6
|
+
'brand',
|
|
7
|
+
'app',
|
|
8
|
+
'customer',
|
|
9
|
+
'partner',
|
|
10
|
+
'decision',
|
|
11
|
+
'raci',
|
|
12
|
+
'glossary_term',
|
|
13
|
+
'document',
|
|
14
|
+
];
|
|
15
|
+
export const EXTENSION_ENTITY_TYPES = [
|
|
16
|
+
'contact',
|
|
17
|
+
'frame',
|
|
18
|
+
'story',
|
|
19
|
+
'infrastructure_environment',
|
|
20
|
+
'speaking',
|
|
21
|
+
'media_appearance',
|
|
22
|
+
'role_assignment',
|
|
23
|
+
'product',
|
|
24
|
+
'initiative',
|
|
25
|
+
'publication',
|
|
26
|
+
'press_mention',
|
|
27
|
+
];
|
|
28
|
+
export const ENTITY_TYPE_REGISTRY = [
|
|
29
|
+
{ type: 'project', category: 'core', displayName: 'Project', description: 'Work, product, or engagement context.', defaultSearch: true },
|
|
30
|
+
{ type: 'person', category: 'core', displayName: 'Person', description: 'Human stakeholder or team member.', defaultSearch: true },
|
|
31
|
+
{ type: 'org', category: 'core', displayName: 'Organization', description: 'Legal entity, team, or organization context.', defaultSearch: true },
|
|
32
|
+
{ type: 'brand', category: 'core', displayName: 'Brand', description: 'Naming, positioning, voice, and public promise context.', defaultSearch: true },
|
|
33
|
+
{ type: 'app', category: 'core', displayName: 'App', description: 'Application or software product.', defaultSearch: true },
|
|
34
|
+
{ type: 'customer', category: 'core', displayName: 'Customer', description: 'Customer or account context.', defaultSearch: true },
|
|
35
|
+
{ type: 'partner', category: 'core', displayName: 'Partner', description: 'Partner organization or person.', defaultSearch: true },
|
|
36
|
+
{ type: 'decision', category: 'core', displayName: 'Decision', description: 'Decision record.', defaultSearch: true },
|
|
37
|
+
{ type: 'raci', category: 'core', storageType: 'raci_assignment', displayName: 'RACI', description: 'Responsibility, authority, and assignment context.', defaultSearch: true },
|
|
38
|
+
{ type: 'glossary_term', category: 'core', displayName: 'Glossary Term', description: 'Canonical term, alias, and correction context.', defaultSearch: true },
|
|
39
|
+
{ type: 'document', category: 'core', displayName: 'Document', description: 'Operational or knowledge document.', defaultSearch: true },
|
|
40
|
+
{ type: 'contact', category: 'extension', displayName: 'Contact', description: 'Business-card contact awaiting operational promotion to a person.', defaultSearch: false },
|
|
41
|
+
{ type: 'frame', category: 'extension', displayName: 'Frame', description: 'Organization-specific framework or mental model.', defaultSearch: false },
|
|
42
|
+
{ type: 'story', category: 'extension', displayName: 'Story', description: 'Story-to-ship or task story record.', defaultSearch: false },
|
|
43
|
+
{ type: 'infrastructure_environment', category: 'extension', displayName: 'Infrastructure Environment', description: 'Deployment or runtime environment detail.', defaultSearch: false },
|
|
44
|
+
{ type: 'speaking', category: 'extension', displayName: 'Speaking', description: 'Speaking engagement profile record.', defaultSearch: false },
|
|
45
|
+
{ type: 'media_appearance', category: 'extension', displayName: 'Media Appearance', description: 'Media appearance profile record.', defaultSearch: false },
|
|
46
|
+
{ type: 'role_assignment', category: 'extension', displayName: 'Role Assignment', description: 'Profile or organization-specific role assignment.', defaultSearch: false },
|
|
47
|
+
{ type: 'product', category: 'extension', displayName: 'Product', description: 'Profile or organization-specific product record.', defaultSearch: false },
|
|
48
|
+
{ type: 'initiative', category: 'extension', displayName: 'Initiative', description: 'Cross-project program or strategic initiative.', defaultSearch: false },
|
|
49
|
+
{ type: 'publication', category: 'extension', displayName: 'Publication', description: 'Publication profile record.', defaultSearch: false },
|
|
50
|
+
{ type: 'press_mention', category: 'extension', displayName: 'Press Mention', description: 'Press mention profile record.', defaultSearch: false },
|
|
51
|
+
];
|
|
52
|
+
export const EXTENSION_ENTITY_TYPE_SET = new Set(EXTENSION_ENTITY_TYPES);
|
|
53
|
+
export function getStorageType(publicType) {
|
|
54
|
+
return ENTITY_TYPE_REGISTRY.find((item) => item.type === publicType)?.storageType || publicType;
|
|
55
|
+
}
|
|
56
|
+
export function getPublicType(storageType) {
|
|
57
|
+
return ENTITY_TYPE_REGISTRY.find((item) => item.storageType === storageType)?.type || storageType;
|
|
58
|
+
}
|
|
59
|
+
export function getExtensionRegistrations() {
|
|
60
|
+
return ENTITY_TYPE_REGISTRY.filter((item) => item.category === 'extension');
|
|
61
|
+
}
|
|
62
|
+
export function getGraphFetchTypes() {
|
|
63
|
+
return Array.from(new Set(ENTITY_TYPE_REGISTRY.map((item) => item.storageType || item.type)));
|
|
64
|
+
}
|
|
65
|
+
const INACTIVE_LIFECYCLE_STATES = new Set(['inactive', 'retired', 'superseded', 'merged']);
|
|
66
|
+
function lifecyclePayloadRecord(value) {
|
|
67
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
68
|
+
? value
|
|
69
|
+
: undefined;
|
|
70
|
+
}
|
|
71
|
+
function isInactiveLifecycleState(value) {
|
|
72
|
+
return typeof value === 'string'
|
|
73
|
+
&& INACTIVE_LIFECYCLE_STATES.has(value.trim().toLowerCase());
|
|
74
|
+
}
|
|
75
|
+
/** Return false only when a record explicitly carries a known inactive state. */
|
|
76
|
+
export function isActiveLifecycle(record) {
|
|
77
|
+
const payload = lifecyclePayloadRecord(record.payload);
|
|
78
|
+
return [
|
|
79
|
+
record.lifecycle_status,
|
|
80
|
+
record.lifecycle_state,
|
|
81
|
+
record.semantic_state,
|
|
82
|
+
record.status,
|
|
83
|
+
payload?.lifecycle_status,
|
|
84
|
+
payload?.lifecycle_state,
|
|
85
|
+
payload?.semantic_state,
|
|
86
|
+
payload?.status,
|
|
87
|
+
].some(isInactiveLifecycleState) === false;
|
|
88
|
+
}
|
|
89
|
+
/** A person is active only when both identity status and lifecycle are active. */
|
|
90
|
+
export function isActiveCanonicalPerson(person) {
|
|
91
|
+
return isActiveLifecycle(person);
|
|
92
|
+
}
|
|
93
|
+
function assertCollection(type, value) {
|
|
94
|
+
if (!Array.isArray(value))
|
|
95
|
+
throw new TypeError(`${type} collection must be an array`);
|
|
96
|
+
}
|
|
97
|
+
function validateEntities(type, entities) {
|
|
98
|
+
assertCollection(type, entities);
|
|
99
|
+
const activeIds = new Set();
|
|
100
|
+
for (const entity of entities) {
|
|
101
|
+
if (!entity || typeof entity.id !== 'string' || entity.id.trim() === '') {
|
|
102
|
+
throw new TypeError(`${type} entity requires a non-empty id`);
|
|
103
|
+
}
|
|
104
|
+
if (!isReplacedLifecycle(entity)) {
|
|
105
|
+
if (activeIds.has(entity.id))
|
|
106
|
+
throw new TypeError(`${type} duplicate active id: ${entity.id}`);
|
|
107
|
+
activeIds.add(entity.id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export function createEmptyIndex() {
|
|
112
|
+
return {
|
|
113
|
+
projects: new Map(),
|
|
114
|
+
people: new Map(),
|
|
115
|
+
orgs: new Map(),
|
|
116
|
+
brands: new Map(),
|
|
117
|
+
raci: new Map(),
|
|
118
|
+
apps: new Map(),
|
|
119
|
+
customers: new Map(),
|
|
120
|
+
partners: new Map(),
|
|
121
|
+
decisions: new Map(),
|
|
122
|
+
glossaryTerms: new Map(),
|
|
123
|
+
documents: new Map(),
|
|
124
|
+
extensions: new Map(),
|
|
125
|
+
aliasToPersonId: new Map(),
|
|
126
|
+
aliasToOrgId: new Map(),
|
|
127
|
+
aliasToBrandId: new Map(),
|
|
128
|
+
replacedIdToCanonicalId: new Map(),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// Graph lifecycle states of records that must not answer as the current entity.
|
|
132
|
+
// merge_entities leaves the source as superseded with payload.canonical_entity_id.
|
|
133
|
+
const REPLACED_LIFECYCLE_STATES = new Set(['superseded', 'merged', 'retired']);
|
|
134
|
+
export function isReplacedLifecycle(entity) {
|
|
135
|
+
return [entity.lifecycle_status, entity.lifecycle_state].some(value => typeof value === 'string' && REPLACED_LIFECYCLE_STATES.has(value.trim().toLowerCase()));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Index only current records. A replaced record never overwrites an active one
|
|
139
|
+
* that shares its display id (for example payload.org_id), and its ids are kept
|
|
140
|
+
* as pointers to the canonical record named by canonical_entity_id.
|
|
141
|
+
*/
|
|
142
|
+
function populateCurrentEntities(index, type, target, entities) {
|
|
143
|
+
validateEntities(type, entities);
|
|
144
|
+
const replaced = [];
|
|
145
|
+
for (const entity of entities) {
|
|
146
|
+
if (isReplacedLifecycle(entity)) {
|
|
147
|
+
replaced.push(entity);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
target.set(entity.id, entity);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const indexKeyByGraphId = new Map();
|
|
154
|
+
for (const [key, entity] of target) {
|
|
155
|
+
indexKeyByGraphId.set(entity.graph_entity_id || entity.id, key);
|
|
156
|
+
}
|
|
157
|
+
const pointers = new Map();
|
|
158
|
+
for (const entity of replaced) {
|
|
159
|
+
const canonical = entity.canonical_entity_id;
|
|
160
|
+
const canonicalKey = canonical ? indexKeyByGraphId.get(canonical) ?? (target.has(canonical) ? canonical : undefined) : undefined;
|
|
161
|
+
if (!canonicalKey)
|
|
162
|
+
continue;
|
|
163
|
+
for (const replacedId of [entity.graph_entity_id, entity.id]) {
|
|
164
|
+
if (replacedId && !target.has(replacedId))
|
|
165
|
+
pointers.set(replacedId, canonicalKey);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
index.replacedIdToCanonicalId.set(type, pointers);
|
|
169
|
+
// Keep terminal person rows in the local projection as negative evidence.
|
|
170
|
+
// Resolver consumers filter them through the shared active-person predicate,
|
|
171
|
+
// while Personal KG can distinguish an explicitly inactive identity from an
|
|
172
|
+
// actually empty projection before applying its canonical-ID fallback. Add
|
|
173
|
+
// them after pointer construction so legacy IDs still resolve to the active
|
|
174
|
+
// canonical row through replacedIdToCanonicalId.
|
|
175
|
+
if (type === 'person') {
|
|
176
|
+
for (const entity of replaced) {
|
|
177
|
+
if (!target.has(entity.id))
|
|
178
|
+
target.set(entity.id, entity);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Build alias mappings for people
|
|
184
|
+
*/
|
|
185
|
+
function buildPersonAliases(index) {
|
|
186
|
+
for (const person of index.people.values()) {
|
|
187
|
+
if (!isActiveCanonicalPerson(person))
|
|
188
|
+
continue;
|
|
189
|
+
// Map name -> personId
|
|
190
|
+
if (person.name) {
|
|
191
|
+
index.aliasToPersonId.set(person.name, person.id);
|
|
192
|
+
// Also map name without spaces (for Japanese names)
|
|
193
|
+
const noSpace = person.name.replace(/\s+/g, '');
|
|
194
|
+
if (noSpace !== person.name) {
|
|
195
|
+
index.aliasToPersonId.set(noSpace, person.id);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Map each alias -> personId
|
|
199
|
+
for (const alias of person.aliases) {
|
|
200
|
+
index.aliasToPersonId.set(alias, person.id);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Build alias mappings for orgs
|
|
206
|
+
*/
|
|
207
|
+
function buildOrgAliases(index) {
|
|
208
|
+
for (const org of index.orgs.values()) {
|
|
209
|
+
// Map name -> orgId
|
|
210
|
+
if (org.name) {
|
|
211
|
+
index.aliasToOrgId.set(org.name, org.org_id);
|
|
212
|
+
}
|
|
213
|
+
// Map each alias -> orgId
|
|
214
|
+
for (const alias of org.aliases) {
|
|
215
|
+
index.aliasToOrgId.set(alias, org.org_id);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function buildBrandAliases(index) {
|
|
220
|
+
for (const brand of index.brands.values()) {
|
|
221
|
+
if (brand.name) {
|
|
222
|
+
index.aliasToBrandId.set(brand.name, brand.id);
|
|
223
|
+
}
|
|
224
|
+
for (const alias of brand.aliases) {
|
|
225
|
+
index.aliasToBrandId.set(alias, brand.id);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Build the complete entity index from EntitySource
|
|
231
|
+
* Host revision must be cheap, stable, and change on every indexed create/update/retire/delete.
|
|
232
|
+
* Without such a marker, rebuild per refresh or use a rejecting cache revision (no commit).
|
|
233
|
+
* Never use fresh random/timestamp revisions: before/after mismatch throws after 3 builds.
|
|
234
|
+
*/
|
|
235
|
+
export async function buildIndex(source) {
|
|
236
|
+
const index = createEmptyIndex();
|
|
237
|
+
// Initialize source
|
|
238
|
+
await source.initialize();
|
|
239
|
+
// Load all entities in parallel
|
|
240
|
+
const [projects, people, orgs, brands, racis, apps, customers, partners, decisions, glossaryTerms, documents, extensionTypeRegistrations] = await Promise.all([
|
|
241
|
+
source.getProjects(),
|
|
242
|
+
source.getPeople(),
|
|
243
|
+
source.getOrganizations(),
|
|
244
|
+
source.getBrands(),
|
|
245
|
+
source.getRACIs(),
|
|
246
|
+
source.getApps(),
|
|
247
|
+
source.getCustomers(),
|
|
248
|
+
source.getPartners(),
|
|
249
|
+
source.getDecisions(),
|
|
250
|
+
source.getGlossaryTerms(),
|
|
251
|
+
source.getDocuments(),
|
|
252
|
+
source.getExtensionTypeRegistrations(),
|
|
253
|
+
]);
|
|
254
|
+
// Populate index
|
|
255
|
+
populateCurrentEntities(index, 'project', index.projects, projects);
|
|
256
|
+
populateCurrentEntities(index, 'person', index.people, people);
|
|
257
|
+
populateCurrentEntities(index, 'org', index.orgs, orgs);
|
|
258
|
+
populateCurrentEntities(index, 'brand', index.brands, brands);
|
|
259
|
+
populateCurrentEntities(index, 'raci', index.raci, racis);
|
|
260
|
+
populateCurrentEntities(index, 'app', index.apps, apps);
|
|
261
|
+
populateCurrentEntities(index, 'customer', index.customers, customers);
|
|
262
|
+
populateCurrentEntities(index, 'partner', index.partners, partners);
|
|
263
|
+
populateCurrentEntities(index, 'decision', index.decisions, decisions);
|
|
264
|
+
populateCurrentEntities(index, 'glossary_term', index.glossaryTerms, glossaryTerms);
|
|
265
|
+
populateCurrentEntities(index, 'document', index.documents, documents);
|
|
266
|
+
await populateExtensionEntities(index, source, extensionTypeRegistrations);
|
|
267
|
+
// Build alias mappings
|
|
268
|
+
buildPersonAliases(index);
|
|
269
|
+
buildOrgAliases(index);
|
|
270
|
+
buildBrandAliases(index);
|
|
271
|
+
return index;
|
|
272
|
+
}
|
|
273
|
+
async function populateExtensionEntities(index, source, registrations) {
|
|
274
|
+
assertCollection('extension registrations', registrations);
|
|
275
|
+
const extensions = registrations.length > 0 ? registrations : getExtensionRegistrations();
|
|
276
|
+
const extensionEntries = await Promise.all(extensions.map(async (registration) => {
|
|
277
|
+
const entities = await source.getExtensionEntities(registration.type);
|
|
278
|
+
return [registration.type, entities];
|
|
279
|
+
}));
|
|
280
|
+
for (const [type, entities] of extensionEntries) {
|
|
281
|
+
validateEntities(type, entities);
|
|
282
|
+
const byId = new Map();
|
|
283
|
+
for (const entity of entities) {
|
|
284
|
+
byId.set(entity.id, entity);
|
|
285
|
+
}
|
|
286
|
+
index.extensions.set(type, byId);
|
|
287
|
+
}
|
|
288
|
+
}
|
package/dist/judgment-frame.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export type JudgmentFrameRole = 'constraint' | 'criterion' | 'prediction';
|
|
|
19
19
|
export type JudgmentFrameConstraintVerdict = 'satisfied' | 'violated' | 'tension';
|
|
20
20
|
/** Each kind is used in exactly one way inside an option evaluation. */
|
|
21
21
|
export declare const JUDGMENT_FRAME_ROLE_BY_KIND: Readonly<Record<JudgmentFrameKind, JudgmentFrameRole>>;
|
|
22
|
+
export declare const MAX_PUBLIC_FRAME_TEXT = 2000;
|
|
22
23
|
/**
|
|
23
24
|
* A caller-provided summary that may be projected to an owner-only history.
|
|
24
25
|
* Core never derives this value from an answer, tool response, or body.
|
|
@@ -120,8 +121,31 @@ export interface JudgmentFrameValidation {
|
|
|
120
121
|
readonly issues: readonly JudgmentFrameIssue[];
|
|
121
122
|
readonly escalations: readonly JudgmentFrameEscalation[];
|
|
122
123
|
}
|
|
124
|
+
export declare const PUBLIC_FRAME_KEYS: readonly ["summary", "reason"];
|
|
123
125
|
/** True when text looks like it carries a credential. Shared by public frames and outcome records. */
|
|
124
126
|
export declare function containsJudgmentFrameCredential(value: string): boolean;
|
|
127
|
+
/** True when text carries control characters that must never reach a public projection. */
|
|
128
|
+
export declare function publicFrameTextHasControlCharacters(value: string): boolean;
|
|
129
|
+
/** The single rejection code every writer uses for an unusable explicit public frame. */
|
|
130
|
+
export type JudgmentPublicFrameRejectionCode = 'frame_public_absent' | 'frame_public_invalid';
|
|
131
|
+
export type JudgmentPublicFrameCheck = {
|
|
132
|
+
readonly ok: true;
|
|
133
|
+
readonly frame: JudgmentFramePublicFrame;
|
|
134
|
+
} | {
|
|
135
|
+
readonly ok: false;
|
|
136
|
+
readonly code: JudgmentPublicFrameRejectionCode;
|
|
137
|
+
readonly detail: string;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Validate a standalone explicit public frame with the exact acceptance
|
|
141
|
+
* boundary enforced inside a frame record: only the `summary`/`reason` keys,
|
|
142
|
+
* each a non-empty string of at most MAX_PUBLIC_FRAME_TEXT characters, free of
|
|
143
|
+
* control characters and credential-like values. A missing or empty frame is
|
|
144
|
+
* reported as `frame_public_absent` so a caller can keep "nothing recorded"
|
|
145
|
+
* distinct from "recorded but invalid". The value is never trimmed, stripped,
|
|
146
|
+
* or rewritten; an unusable frame is rejected, not repaired.
|
|
147
|
+
*/
|
|
148
|
+
export declare function checkJudgmentPublicFrame(value: unknown): JudgmentPublicFrameCheck;
|
|
125
149
|
/**
|
|
126
150
|
* Compute the digest for the exact two-field public projection.
|
|
127
151
|
* The response adds this digest; it is intentionally separate from the
|