@unson/brainbase-mcp 0.51.9 → 0.51.11

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.
@@ -41,6 +41,50 @@ const KIND_PALETTE = ['#1261ad', '#b07a1f', '#35684c', '#6b4fa0', '#a8433a', '#2
41
41
  const UNCLASSIFIED_COLOR = '#69746d';
42
42
  const HEX_COLOR = /^#[0-9a-f]{6}$/iu;
43
43
  const ACTIVITY_WINDOW_DAYS = 30;
44
+ /** Lifecycle states that are no longer a business on the map (as the organization Graph records them). */
45
+ const INACTIVE_LIFECYCLE = new Set(['retired', 'merged', 'inactive', 'superseded']);
46
+ /** Record statuses of a business that is over (the same words the project directory treats as archived). */
47
+ const ARCHIVED_STATUS = new Set(['archived', 'completed', 'closed']);
48
+ /**
49
+ * Names of the probes and acceptance runs that were left in Graphs as active projects. A project whose
50
+ * code or name matches one is kept off the map by default (layer 2; layer 1 is the record's own flags).
51
+ */
52
+ export const WORLD_TEST_PROJECT_PATTERNS = Object.freeze([
53
+ /^zz[\s_-]*probe/iu,
54
+ /^agent-live-acceptance-/iu,
55
+ /^codex-(crud|lock-probe)/iu,
56
+ /(^|[-_])(e2e|smoke|test)[-_]/iu,
57
+ ]);
58
+ function lowerText(value) {
59
+ return text(value)?.toLowerCase() ?? null;
60
+ }
61
+ /**
62
+ * Why a project is kept off the world by default, or null when it is drawn. `top` is true for a
63
+ * business (a city): a finished business is kept off, while a finished engagement inside a city stays
64
+ * as its empty lot (story-world-size-and-activity-v1).
65
+ */
66
+ export function worldProjectFilterReason(entity, { top = true } = {}) {
67
+ const metadata = entity.metadata ?? {};
68
+ if (INACTIVE_LIFECYCLE.has(lowerText(metadata.lifecycle_status) ?? ''))
69
+ return 'lifecycle';
70
+ if (metadata.is_test === true)
71
+ return 'test_flag';
72
+ if (lowerText(metadata.world_visibility) === 'hidden')
73
+ return 'hidden';
74
+ if (top && [metadata.status, metadata.operational_status, metadata.record_status].some((value) => ARCHIVED_STATUS.has(lowerText(value) ?? '')))
75
+ return 'archived';
76
+ const names = [text(metadata.code), text(entity.name)].filter((value) => value !== null);
77
+ if (names.some((value) => WORLD_TEST_PROJECT_PATTERNS.some((pattern) => pattern.test(value))))
78
+ return 'test_name';
79
+ return null;
80
+ }
81
+ /**
82
+ * The AI agents a host projects onto the world (story-world-agents-step1-v1, design item #707 §1.3).
83
+ * It is an execution-state projection (for example Orca run receipts), never Brainbase's judgment record:
84
+ * the plaza (判断) is not touched by it, and the world says where it came from. This package only draws
85
+ * it; the host computes the states on its server, with its own organization and member boundaries.
86
+ */
87
+ export const WORLD_AGENTS_CONTRACT_VERSION = 'world-agents.v1';
44
88
  function isRecord(value) {
45
89
  return value !== null && typeof value === 'object' && !Array.isArray(value);
46
90
  }
@@ -64,9 +108,34 @@ function engagementOf(entity) {
64
108
  * Nothing here knows any organization's words: kinds and statuses are the
65
109
  * Graph's own values.
66
110
  */
67
- export function projectWorldFromGraph(graph, now = new Date()) {
111
+ export function projectWorldFromGraph(graph, now = new Date(), options = {}) {
68
112
  const projects = graph.entities.filter((entity) => entity.type === 'project');
69
- const active = projects.filter((entity) => !entity.validTo || Date.parse(entity.validTo) > now.getTime());
113
+ const current = projects.filter((entity) => !entity.validTo || Date.parse(entity.validTo) > now.getTime());
114
+ // The display filter (two layers: the record's own flags, then test-like names). A project under a
115
+ // filtered one goes with it, so it is not miscounted as an engagement whose business is missing.
116
+ const filtered = new Set();
117
+ if (!options.includeTest) {
118
+ const currentById = new Map(current.map((entity) => [entity.id, entity]));
119
+ const isTop = (entity) => {
120
+ const parentId = text(entity.metadata?.parent_project_id);
121
+ return !parentId || parentId === entity.id || !currentById.has(parentId);
122
+ };
123
+ for (const entity of current) {
124
+ if (worldProjectFilterReason(entity, { top: isTop(entity) }))
125
+ filtered.add(entity.id);
126
+ }
127
+ for (let grew = filtered.size > 0; grew;) {
128
+ grew = false;
129
+ for (const entity of current) {
130
+ const parentId = text(entity.metadata?.parent_project_id);
131
+ if (!filtered.has(entity.id) && parentId && filtered.has(parentId)) {
132
+ filtered.add(entity.id);
133
+ grew = true;
134
+ }
135
+ }
136
+ }
137
+ }
138
+ const active = current.filter((entity) => !filtered.has(entity.id));
70
139
  const byId = new Map(active.map((entity) => [entity.id, entity]));
71
140
  // A district hangs on its top-level ancestor, so nested projects stay in one city.
72
141
  const topOf = (entity) => {
@@ -163,7 +232,8 @@ export function projectWorldFromGraph(graph, now = new Date()) {
163
232
  return {
164
233
  businesses: businesses.sort((a, b) => a.name.localeCompare(b.name, 'ja')),
165
234
  unplaced,
166
- excluded: { inactive: projects.length - active.length },
235
+ excluded: { inactive: projects.length - current.length },
236
+ filtered_out_count: filtered.size,
167
237
  };
168
238
  }
169
239
  /**
@@ -270,7 +340,7 @@ export async function readWorldBusinesses(context, options = {}) {
270
340
  catch (error) {
271
341
  return { status: 'unavailable', version: WORLD_EXTENSION_VERSION, reason: error instanceof Error ? error.message : 'graph_unreadable' };
272
342
  }
273
- const projection = projectWorldFromGraph(graph, now);
343
+ const projection = projectWorldFromGraph(graph, now, { includeTest: options.includeTest === true });
274
344
  return {
275
345
  status: 'ok',
276
346
  version: WORLD_EXTENSION_VERSION,
@@ -292,7 +362,7 @@ export function projectOrganizationWorld(records, options) {
292
362
  memberOf: [],
293
363
  assignedTo: [],
294
364
  });
295
- const projection = projectWorldFromGraph(graph, now);
365
+ const projection = projectWorldFromGraph(graph, now, { includeTest: options.includeTest === true });
296
366
  return {
297
367
  status: 'ok',
298
368
  version: WORLD_EXTENSION_VERSION,
@@ -342,10 +412,12 @@ function createWorldModule(context, read) {
342
412
  async handle(request, response) {
343
413
  if (request.method !== 'GET')
344
414
  return false;
345
- const path = requestUrl(request).pathname;
415
+ const url = requestUrl(request);
416
+ const path = url.pathname;
346
417
  if (path === `/api/extensions/${WORLD_EXTENSION_ID}/businesses`) {
347
418
  response.setHeader('Cache-Control', 'no-store');
348
- writeJson(response, 200, await read());
419
+ // The single owner may look at what the display filter keeps off the map (for checking only).
420
+ writeJson(response, 200, await read({ includeTest: url.searchParams.get('include_test') === '1' }));
349
421
  return true;
350
422
  }
351
423
  // This Mac keeps no Canonical Task store, so the work inside a city is not connected here
@@ -372,6 +444,6 @@ export function createWorldExtension(options = {}) {
372
444
  screenEntry: 'world-view.js',
373
445
  // P17: the world sits above the home and opens first.
374
446
  navPosition: 'first',
375
- createModule: (context) => createWorldModule(context, () => readWorldBusinesses(context, { vocabulary: options.vocabulary, now: context.now })),
447
+ createModule: (context) => createWorldModule(context, (read) => readWorldBusinesses(context, { vocabulary: options.vocabulary, now: context.now, ...read })),
376
448
  };
377
449
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unson/brainbase-mcp",
3
- "version": "0.51.9",
3
+ "version": "0.51.11",
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",
@@ -159,6 +159,14 @@
159
159
  "types": "./dist/canonical-task-operations.d.ts",
160
160
  "import": "./dist/canonical-task-operations.js"
161
161
  },
162
+ "./canonical-task-comment-tools": {
163
+ "types": "./dist/canonical-task-comment-tools.d.ts",
164
+ "import": "./dist/canonical-task-comment-tools.js"
165
+ },
166
+ "./canonical-task-list-tools": {
167
+ "types": "./dist/canonical-task-list-tools.d.ts",
168
+ "import": "./dist/canonical-task-list-tools.js"
169
+ },
162
170
  "./canonical-task-store-config": {
163
171
  "types": "./dist/canonical-task-store-config.d.ts",
164
172
  "import": "./dist/canonical-task-store-config.js"
@@ -673,5 +681,5 @@
673
681
  "url": "https://github.com/Unson-LLC/brainbase/issues"
674
682
  },
675
683
  "homepage": "https://github.com/Unson-LLC/brainbase#readme",
676
- "gitHead": "d86936d501ce4b634538a82b4af0f9ab7ae0a3dd"
684
+ "gitHead": "560d58fe291180e921a11bb50aec595292dc5dd8"
677
685
  }
@@ -390,3 +390,27 @@
390
390
 
391
391
  /* A real record without a visible lot remains readable as detached details. */
392
392
  .bb-world-canvas-ui .bb-world-canvas-task.is-unanchored::after { display: none; }
393
+
394
+ /* Tier B (story-world-agents-step1-v1): the standing limits gathered behind one chip under the actionable
395
+ rows. Folded by default, never removed; it opens itself while a read has failed. */
396
+ .bb-world-canvas-ui .bb-world-canvas-constraints {
397
+ display: grid;
398
+ justify-items: start;
399
+ gap: 6px;
400
+ max-width: 100%;
401
+ pointer-events: auto;
402
+ }
403
+ .bb-world-canvas-ui .bb-world-canvas-constraints-toggle {
404
+ padding: 4px 10px;
405
+ border: 1px dashed rgb(255 255 255 / 55%);
406
+ border-radius: 999px;
407
+ background: rgb(13 25 46 / 62%);
408
+ color: #fff;
409
+ font: inherit;
410
+ font-size: 12px;
411
+ cursor: pointer;
412
+ }
413
+ .bb-world-canvas-ui .bb-world-canvas-constraints.has-incident .bb-world-canvas-constraints-toggle { border-style: solid; border-color: #f0b648; }
414
+ .bb-world-canvas-ui .bb-world-canvas-constraints-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
415
+ .bb-world-canvas-ui .bb-world-canvas-constraints-list { display: grid; justify-items: start; gap: 6px; max-width: 100%; }
416
+ .bb-world-canvas-ui .bb-world-canvas-constraints-list[hidden] { display: none; }
@@ -59,6 +59,13 @@ const nodeList = (nodes) => (Array.isArray(nodes) ? nodes : [nodes]).filter((nod
59
59
  * remains in help. No summary is inferred from a long or nonurgent notice.
60
60
  * A quest with a `link` or an `action` is pressable as a whole row; one without
61
61
  * is drawn flat and may say its `reason` (why nothing opens from it).
62
+ *
63
+ * Tiers (story-world-agents-step1-v1): a quest with `tier: 'constraint'` is a standing limit of what the
64
+ * screen is connected to (未接続, 一部だけ読めた); it is never hidden, but gathered behind one chip
65
+ * (`計器の制約 N件 ▾`) that opens every row in one press. Other quests are the actionable exceptions; at
66
+ * most `questLimit` of them stand at the top and the rest are counted on the same chip. A quest with
67
+ * `incident: true` (a read that failed now) opens the chip by itself until the viewer folds it.
68
+ * @param {number} [options.questLimit] At most this many actionable rows stand at the top (default: all).
62
69
  */
63
70
  export function createWorldCanvasUI({
64
71
  doc,
@@ -69,6 +76,7 @@ export function createWorldCanvasUI({
69
76
  onSky,
70
77
  onDismissTask,
71
78
  context = {},
79
+ questLimit = Number.POSITIVE_INFINITY,
72
80
  }) {
73
81
  const id = `bb-world-canvas-${++instanceId}`;
74
82
  const listeners = [];
@@ -174,6 +182,30 @@ export function createWorldCanvasUI({
174
182
  });
175
183
  contextRoot.append(contextNextAction);
176
184
  const quests = element('div', 'bb-world-canvas-quests', null, { 'aria-live': 'polite', 'aria-label': '確認が必要なこと' });
185
+ // Tier B: the standing limits (and the actionable rows past the limit) behind one chip, never hidden.
186
+ const constraints = element('div', 'bb-world-canvas-constraints');
187
+ const constraintsToggle = element('button', 'bb-world-canvas-constraints-toggle', '', { type: 'button', 'aria-expanded': 'false', 'aria-controls': `${id}-constraints` });
188
+ const constraintsList = element('div', 'bb-world-canvas-constraints-list', null, { id: `${id}-constraints` });
189
+ constraintsList.hidden = true;
190
+ constraints.append(constraintsToggle, constraintsList);
191
+ const tiers = { actionable: 0, constraint: 0, overflow: 0, incident: 0 };
192
+ let constraintsOpen = null;
193
+ function renderConstraints() {
194
+ const count = tiers.constraint + tiers.overflow;
195
+ if (count === 0) {
196
+ constraints.remove();
197
+ return;
198
+ }
199
+ const open = constraintsOpen ?? tiers.incident > 0;
200
+ const parts = [tiers.constraint ? `計器の制約 ${tiers.constraint}件` : null, tiers.overflow ? `ほかの確認 ${tiers.overflow}件` : null].filter(Boolean);
201
+ constraintsToggle.textContent = `${parts.join('・')} ${open ? '▴' : '▾'}`;
202
+ constraintsToggle.setAttribute('aria-expanded', String(open));
203
+ constraintsToggle.setAttribute('aria-label', `${parts.join('・')}(${open ? 'たたむ' : '理由を全部見る'})`);
204
+ constraints.classList.toggle('is-open', open);
205
+ constraints.classList.toggle('has-incident', tiers.incident > 0);
206
+ constraintsList.hidden = !open;
207
+ quests.append(constraints);
208
+ }
177
209
 
178
210
  const edge = button('bb-world-canvas-edge', '都市の詳細を開く', '');
179
211
  edge.setAttribute('aria-controls', `${id}-rail`);
@@ -376,7 +408,7 @@ export function createWorldCanvasUI({
376
408
  activate('help', help);
377
409
  focus(helpTitle);
378
410
  }
379
- function addNote({ label = '', text = '', tone = '', summary, link = null, action = null, reason = null } = {}) {
411
+ function addNote({ label = '', text = '', tone = '', summary, link = null, action = null, reason = null, tier = null, incident = false } = {}) {
380
412
  if (disposed) return;
381
413
  const note = element('section', 'bb-world-canvas-note');
382
414
  if (label) note.append(element('h3', '', label));
@@ -405,11 +437,25 @@ export function createWorldCanvasUI({
405
437
  // Why nothing opens from here (未接続 and the like), said in the row instead of only in help.
406
438
  quest.append(element('span', 'bb-world-canvas-quest-reason', reason.trim()));
407
439
  }
408
- quests.append(quest);
440
+ if (incident) tiers.incident += 1;
441
+ if (tier === 'constraint') {
442
+ tiers.constraint += 1;
443
+ quest.classList.add('is-constraint');
444
+ constraintsList.append(quest);
445
+ } else if (tiers.actionable >= questLimit) {
446
+ tiers.overflow += 1;
447
+ constraintsList.append(quest);
448
+ } else {
449
+ tiers.actionable += 1;
450
+ quests.append(quest);
451
+ }
452
+ renderConstraints();
409
453
  }
410
454
  function clearNotes() {
411
455
  if (disposed) return;
412
456
  quests.replaceChildren();
457
+ constraintsList.replaceChildren();
458
+ Object.assign(tiers, { actionable: 0, constraint: 0, overflow: 0, incident: 0 });
413
459
  notes.replaceChildren();
414
460
  }
415
461
  function dismissOverlay() {
@@ -448,6 +494,10 @@ export function createWorldCanvasUI({
448
494
  listen(railClose, 'click', closeRail);
449
495
  listen(taskClose, 'click', dismissTask);
450
496
  listen(helpButton, 'click', toggleHelp);
497
+ listen(constraintsToggle, 'click', () => {
498
+ constraintsOpen = !(constraintsOpen ?? tiers.incident > 0);
499
+ renderConstraints();
500
+ });
451
501
  listen(helpClose, 'click', closeHelp);
452
502
  listen(root, 'keydown', (event) => {
453
503
  if (event.key === 'Escape' && !event.defaultPrevented && dismissOverlay()) {
@@ -1093,3 +1093,60 @@ button.bb-world-pulse-crumb:hover { background: var(--bb-color-accent-soft); col
1093
1093
  .bb-world-actor-mark.is-running::after { animation: none; }
1094
1094
  .bb-world-pulse-row { transition: none; }
1095
1095
  }
1096
+
1097
+ /* --- AI agents (story-world-agents-step1-v1) -------------------------------------------------------
1098
+ The overview stays quiet: needs_you (amber, "?") is the strongest, blocked (vermilion, "!", another
1099
+ shape) the second, working a low teal, idle melts in. Unconfirmed is grey and dashed, never idle.
1100
+ Nothing here blinks or moves. */
1101
+ .bb-world-label.is-agent-hq {
1102
+ border-style: dashed;
1103
+ color: var(--bb-color-muted);
1104
+ font-size: 11px;
1105
+ }
1106
+ .bb-world-label.is-agent { font-size: 11px; color: var(--bb-color-muted); background: rgb(255 255 255 / 72%); }
1107
+ .bb-world-label.is-agent.is-needs_you { border: 2px solid #e8a10c; color: #7a4f00; background: #fff6df; font-weight: var(--bb-font-weight-medium); }
1108
+ .bb-world-label.is-agent.is-blocked { border: 2px solid #d2462b; border-radius: 2px; color: #8f2a17; background: #fff0ec; font-weight: var(--bb-font-weight-medium); }
1109
+ .bb-world-label.is-agent.is-working { border-color: #9cc9bd; }
1110
+ .bb-world-label.is-agent.is-unconfirmed,
1111
+ .bb-world-label.is-agent.is-stale { border-style: dashed; color: #7d8589; }
1112
+ .bb-world-label.is-agent.is-caution { outline: 1px dashed #6f6a60; outline-offset: 2px; }
1113
+
1114
+ .bb-world-pulse-agents { margin: 4px 0 6px; padding: 6px 8px; border-left: 3px solid #9cc9bd; background: rgb(255 255 255 / 60%); }
1115
+ .bb-world-pulse-agents.is-attention { border-left-color: #e8a10c; }
1116
+ .bb-world-pulse-agents.is-unconfirmed { border-left: 3px dashed #9aa3a6; }
1117
+ .bb-world-pulse-agents p { margin: 0; }
1118
+ .bb-world-pulse-agents-count { font-size: 12px; }
1119
+ .bb-world-pulse-agents-source { font-size: 10px; color: var(--bb-color-muted); }
1120
+
1121
+ .bb-world-agent-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
1122
+ .bb-world-agent-row {
1123
+ display: grid;
1124
+ grid-template-columns: 1.4em minmax(0, 1fr);
1125
+ gap: 2px 6px;
1126
+ width: 100%;
1127
+ padding: 6px 8px;
1128
+ border: 1px solid var(--bb-color-border);
1129
+ border-radius: 6px;
1130
+ background: var(--bb-color-surface, #fff);
1131
+ color: inherit;
1132
+ font: inherit;
1133
+ text-align: start;
1134
+ cursor: pointer;
1135
+ }
1136
+ .bb-world-agent-row .bb-world-agent-name { grid-column: 2; font-weight: var(--bb-font-weight-medium); }
1137
+ .bb-world-agent-row .bb-world-agent-row-state { grid-column: 2; font-size: 12px; color: var(--bb-color-muted); }
1138
+ .bb-world-agent-mark { grid-row: 1 / span 2; align-self: center; font-weight: 700; text-align: center; }
1139
+ .bb-world-agent-row.is-needs_you { border: 2px solid #e8a10c; }
1140
+ .bb-world-agent-row.is-needs_you .bb-world-agent-mark { color: #b07600; }
1141
+ .bb-world-agent-row.is-blocked { border: 2px solid #d2462b; border-radius: 2px; }
1142
+ .bb-world-agent-row.is-blocked .bb-world-agent-mark { color: #b3361f; }
1143
+ .bb-world-agent-row.is-unconfirmed,
1144
+ .bb-world-agent-row.is-stale { border-style: dashed; }
1145
+ .bb-world-agent-row:focus-visible { outline: 2px solid var(--bb-color-accent, #087d62); outline-offset: 2px; }
1146
+ .bb-world-agent-drilldown.is-unavailable { color: var(--bb-color-muted); cursor: not-allowed; }
1147
+ .bb-world-agent-source { margin: 8px 0 0; font-size: 11px; color: var(--bb-color-muted); }
1148
+ .bb-world-agent-state.is-needs_you dd:first-of-type { color: #7a4f00; font-weight: var(--bb-font-weight-medium); }
1149
+ .bb-world-agent-state.is-blocked dd:first-of-type { color: #8f2a17; font-weight: var(--bb-font-weight-medium); }
1150
+ .bb-world-agent-state.is-unconfirmed dd:first-of-type,
1151
+ .bb-world-agent-state.is-stale dd:first-of-type { color: #6b7377; }
1152
+ .bb-world-label.is-agent-hq.has-exception { border-style: solid; border-color: #e8a10c; color: var(--bb-color-ink); }