@unson/brainbase-mcp 0.50.19 → 0.50.21

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,4 +1,4 @@
1
- import { assertFoundationCatalog, cloneFoundationCatalog, cloneFoundationDefinition, digestFoundationDefinition, findFoundationRecord, findLatestFoundationRecord, foundationCatalogOrEmpty, foundationKey, foundationRef, nextFoundationRevision } from './foundation-catalog.js';
1
+ import { cloneFoundationCatalog, cloneFoundationDefinition, digestFoundationDefinition, findFoundationRecord, findLatestFoundationRecord, foundationCatalogOrEmpty, foundationKey, foundationRef, nextFoundationRevision } from './foundation-catalog.js';
2
2
  import { validateFoundationDefinition, validateFoundationRelation } from './ontology-foundation.js';
3
3
  import { loadPersonalOs, mutatePersonalOs } from './ssot.js';
4
4
  export class FoundationStoreError extends Error {
@@ -342,7 +342,8 @@ function readCatalog(os) {
342
342
  throw new FoundationStoreError('unsupported_graph', 'Foundation catalog writes require canonical Graph v2');
343
343
  }
344
344
  try {
345
- assertFoundationCatalog(os.graph.foundation);
345
+ // foundationCatalogOrEmpty validates the whole catalog (shape and every digest)
346
+ // before it clones it. A second assertFoundationCatalog here repeated that work.
346
347
  return foundationCatalogOrEmpty(os.graph.foundation);
347
348
  }
348
349
  catch (error) {
@@ -34,13 +34,32 @@ export class PersonalMemoryRegistrationError extends Error {
34
34
  /** Read both local memory stores and each memory's registration state. Never uses the network. */
35
35
  export async function listLocalMemories(dataDirInput) {
36
36
  const dataDir = resolveDataDir(dataDirInput);
37
- const [current, legacy, receipts] = await Promise.all([
37
+ // A malformed receipt rejects while the legacy read is still inside the
38
+ // canonical SSOT lock. Promise.all would return that rejection immediately
39
+ // and leave the lock to be created and removed afterwards. Wait for every
40
+ // read, then throw the rejection that happened first: the same one Promise.all
41
+ // would have thrown, once the other reads have released what they held.
42
+ const [current, legacy, receipts] = await awaitFirstRejection([
38
43
  readCurrentStore(dataDir),
39
44
  readLegacyStore(dataDir),
40
45
  readMemoryRegistrationReceipts(dataDir)
41
46
  ]);
42
47
  return [...current, ...legacy].map((memory) => withStatus(memory, receipts));
43
48
  }
49
+ /** The fulfilled values, or the earliest rejection, after every promise has settled. */
50
+ async function awaitFirstRejection(promises) {
51
+ let rejected = false;
52
+ let firstReason;
53
+ const values = await Promise.all(promises.map((promise) => promise.then((value) => value, (reason) => {
54
+ if (!rejected) {
55
+ rejected = true;
56
+ firstReason = reason;
57
+ }
58
+ })));
59
+ if (rejected)
60
+ throw firstReason;
61
+ return values;
62
+ }
44
63
  /** Pick exactly the requested memories, in request order, or fail before anything is sent. */
45
64
  export function selectLocalMemories(memories, ids) {
46
65
  const requested = [...new Set(ids.map((id) => id.trim()).filter(Boolean))];
package/dist/ssot.js CHANGED
@@ -164,13 +164,25 @@ function blockMigrationWrite(plan, issue) {
164
164
  };
165
165
  }
166
166
  async function loadPersonalOsUnlocked(dataDir) {
167
- const graph = parseGraph(await readJson(join(dataDir, 'graph.json')));
168
- const relationships = relationshipsSchema.parse(await readJson(join(dataDir, 'relationships.json')));
169
- const personalKg = await readJsonl(join(dataDir, 'personal-kg.jsonl'), personalKgSchema, 'personal-kg.jsonl');
170
- const decisions = await readJsonl(join(dataDir, 'decisions.jsonl'), decisionSchema, 'decisions.jsonl');
171
- const sourceCount = await countSources(dataDir);
167
+ // Read and validate the files at the same time, but report a failure in the same
168
+ // file order as before so the first broken canonical file is the one named.
169
+ const [graph, relationships, personalKg, decisions, sourceCount] = await settleInOrder([
170
+ readJson(join(dataDir, 'graph.json')).then(parseGraph),
171
+ readJson(join(dataDir, 'relationships.json')).then((value) => relationshipsSchema.parse(value)),
172
+ readJsonl(join(dataDir, 'personal-kg.jsonl'), personalKgSchema, 'personal-kg.jsonl'),
173
+ readJsonl(join(dataDir, 'decisions.jsonl'), decisionSchema, 'decisions.jsonl'),
174
+ countSources(dataDir)
175
+ ]);
172
176
  return { dataDir, graph, personalKg, relationships, decisions, sourceCount };
173
177
  }
178
+ async function settleInOrder(promises) {
179
+ const results = await Promise.allSettled(promises);
180
+ for (const result of results) {
181
+ if (result.status === 'rejected')
182
+ throw result.reason;
183
+ }
184
+ return results.map((result) => result.value);
185
+ }
174
186
  async function commitAggregate(dataDir, next, mode, sidecars = []) {
175
187
  validateAggregate(next);
176
188
  const id = randomUUID();
@@ -341,33 +353,69 @@ async function copyCanonicalSet(sourceDir, targetDir) {
341
353
  }
342
354
  }
343
355
  async function ensureAncillaryDirectories(dataDir) {
344
- for (const relative of ['sources', 'sources/gmail', 'sources/calendar', 'sources/drive', 'sources/tasks', 'candidates', 'schemas']) {
345
- await mkdir(join(dataDir, relative), { recursive: true });
356
+ // This runs on every initialization, including for an existing directory, so the
357
+ // independent directories and schema files are created at the same time.
358
+ await Promise.all(['sources/gmail', 'sources/calendar', 'sources/drive', 'sources/tasks', 'candidates', 'schemas']
359
+ .map((relative) => mkdir(join(dataDir, relative), { recursive: true })));
360
+ await Promise.all(Object.entries(schemaTemplates).map(([fileName, schema]) => (writeFile(join(dataDir, 'schemas', fileName), `${JSON.stringify(schema, null, 2)}\n`, { flag: 'wx' }).catch((error) => {
361
+ if (error.code !== 'EEXIST')
362
+ throw error;
363
+ }))));
364
+ }
365
+ /**
366
+ * Callers in this process that wait for the same lock directory, in arrival order.
367
+ * The directory lock still guards other processes. Without this queue, callers in
368
+ * one process (for example the parallel checks in execution-authority) polled the
369
+ * directory lock every retry interval, so each one waited longer than the holder
370
+ * worked, and the polling added file operations while the holder was still writing.
371
+ */
372
+ const inProcessLockQueues = new Map();
373
+ async function withSsotLock(dataDir, operation) {
374
+ const deadline = Date.now() + parsePositiveInteger(process.env.BRAINBASE_SSOT_LOCK_TIMEOUT_MS, 5_000);
375
+ const lockDir = join(dataDir, lockName);
376
+ const queueKey = resolve(lockDir);
377
+ const previous = inProcessLockQueues.get(queueKey);
378
+ let finishTurn;
379
+ const turn = new Promise((resolveTurn) => { finishTurn = resolveTurn; });
380
+ // A caller that gives up still keeps its place until the callers before it finish,
381
+ // so the next caller never starts while an earlier holder is working.
382
+ const queueTail = previous ? previous.then(() => turn) : turn;
383
+ inProcessLockQueues.set(queueKey, queueTail);
384
+ try {
385
+ await mkdir(dataDir, { recursive: true });
386
+ if (previous)
387
+ await waitForInProcessTurn(previous, deadline, lockDir);
388
+ const owner = await acquireLock(dataDir, deadline);
389
+ try {
390
+ return await operation();
391
+ }
392
+ finally {
393
+ await releaseLock(dataDir, owner).catch((error) => {
394
+ warnCleanupFailure(`canonical SSOT lock ${lockDir}`, error);
395
+ });
396
+ }
346
397
  }
347
- for (const [fileName, schema] of Object.entries(schemaTemplates)) {
348
- await writeFile(join(dataDir, 'schemas', fileName), `${JSON.stringify(schema, null, 2)}\n`, { flag: 'wx' }).catch((error) => {
349
- if (error.code !== 'EEXIST')
350
- throw error;
351
- });
398
+ finally {
399
+ finishTurn();
400
+ if (inProcessLockQueues.get(queueKey) === queueTail)
401
+ inProcessLockQueues.delete(queueKey);
352
402
  }
353
403
  }
354
- async function withSsotLock(dataDir, operation) {
355
- await mkdir(dataDir, { recursive: true });
356
- const owner = await acquireLock(dataDir);
404
+ async function waitForInProcessTurn(previous, deadline, lockDir) {
405
+ let timer;
406
+ const timedOut = new Promise((_resolve, reject) => {
407
+ timer = setTimeout(() => reject(new Error(`Timed out waiting for canonical SSOT lock ${lockDir}`)), Math.max(0, deadline - Date.now()));
408
+ });
357
409
  try {
358
- return await operation();
410
+ await Promise.race([previous, timedOut]);
359
411
  }
360
412
  finally {
361
- await releaseLock(dataDir, owner).catch((error) => {
362
- warnCleanupFailure(`canonical SSOT lock ${join(dataDir, lockName)}`, error);
363
- });
413
+ clearTimeout(timer);
364
414
  }
365
415
  }
366
- async function acquireLock(dataDir) {
416
+ async function acquireLock(dataDir, deadline) {
367
417
  const lockDir = join(dataDir, lockName);
368
- const timeoutMs = parsePositiveInteger(process.env.BRAINBASE_SSOT_LOCK_TIMEOUT_MS, 5_000);
369
418
  const retryMs = parsePositiveInteger(process.env.BRAINBASE_SSOT_LOCK_RETRY_MS, 20);
370
- const deadline = Date.now() + timeoutMs;
371
419
  const owner = { token: randomUUID(), pid: process.pid, hostname: hostname() };
372
420
  while (true) {
373
421
  try {
@@ -432,12 +480,8 @@ function isProcessAlive(pid) {
432
480
  }
433
481
  }
434
482
  async function canonicalPresence(dataDir) {
435
- const result = [];
436
- for (const fileName of canonicalFiles) {
437
- if (await exists(join(dataDir, fileName)))
438
- result.push(fileName);
439
- }
440
- return result;
483
+ const present = await Promise.all(canonicalFiles.map((fileName) => exists(join(dataDir, fileName))));
484
+ return canonicalFiles.filter((_fileName, index) => present[index]);
441
485
  }
442
486
  function assertCompleteCanonicalSet(dataDir, present) {
443
487
  if (present.length !== canonicalFiles.length) {
@@ -532,11 +576,13 @@ async function countSources(dataDir) {
532
576
  }
533
577
  async function countSourceFiles(sourceDir) {
534
578
  try {
535
- const entries = await readdir(sourceDir);
536
- const counts = await Promise.all(entries.filter((entry) => !entry.startsWith('.')).map(async (entry) => {
537
- const entryPath = join(sourceDir, entry);
538
- const entryStat = await stat(entryPath);
539
- return entryStat.isDirectory() ? countSourceFiles(entryPath) : entryStat.isFile() ? 1 : 0;
579
+ const entries = await readdir(sourceDir, { withFileTypes: true });
580
+ const counts = await Promise.all(entries.filter((entry) => !entry.name.startsWith('.')).map(async (entry) => {
581
+ const entryPath = join(sourceDir, entry.name);
582
+ // The directory listing already says what most entries are. Only links and
583
+ // unknown types need stat, which follows the link as before.
584
+ const kind = entry.isDirectory() || entry.isFile() ? entry : await stat(entryPath);
585
+ return kind.isDirectory() ? countSourceFiles(entryPath) : kind.isFile() ? 1 : 0;
540
586
  }));
541
587
  return counts.reduce((sum, count) => sum + count, 0);
542
588
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unson/brainbase-mcp",
3
- "version": "0.50.19",
3
+ "version": "0.50.21",
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",
@@ -657,5 +657,5 @@
657
657
  "url": "https://github.com/Unson-LLC/brainbase/issues"
658
658
  },
659
659
  "homepage": "https://github.com/Unson-LLC/brainbase#readme",
660
- "gitHead": "bf9c68fa85fbb56c74133fab383bd39248fdae92"
660
+ "gitHead": "0398c2e149a8de4c1913d8f4a98656558c24256d"
661
661
  }
@@ -109,10 +109,10 @@
109
109
 
110
110
  .bb-jh-controls {
111
111
  display: flex;
112
- flex-wrap: nowrap;
112
+ flex-wrap: wrap;
113
113
  align-items: center;
114
- gap: 8px;
115
- margin: 0 0 6px;
114
+ gap: var(--bb-space-2);
115
+ margin: 0 0 var(--bb-space-2);
116
116
  }
117
117
 
118
118
  .bb-jh-toolbar-status {
@@ -135,9 +135,9 @@
135
135
  }
136
136
 
137
137
  .bb-jh-summary {
138
- margin: 4px 0 6px;
139
- color: #3b4148;
140
- font-size: 12.5px;
138
+ margin: var(--bb-space-1) 0 var(--bb-space-2);
139
+ color: var(--bb-color-muted);
140
+ font-size: var(--bb-font-size-xs, 12px);
141
141
  }
142
142
 
143
143
  .bb-jh-summary strong {
@@ -589,11 +589,16 @@
589
589
  .bb-jh > .bb-ws-page { margin-bottom: var(--bb-space-6, 32px); }
590
590
  .bb-jh-controls { margin-bottom: var(--bb-space-4, 16px); }
591
591
  .bb-jh-checked { font-size: 11px; font-variant-numeric: tabular-nums; }
592
- .bb-jh-filter-fields { display: grid; gap: 16px; }
593
- .bb-jh-filter-fields .bb-jh-periods { flex-wrap: wrap; gap: 6px; }
594
- .bb-jh-filter-fields .bb-jh-normal-filters { display: grid; flex: none; gap: 16px; }
595
- .bb-jh-filter-fields .bb-jh-filter { display: grid; gap: 6px; }
596
- .bb-jh-filter-fields select { width: 100%; }
592
+ .bb-jh-filter-fields { display: flex; flex-wrap: wrap; align-items: center; gap: var(--bb-space-2); min-width: 0; }
593
+ .bb-jh-filter-fields .bb-jh-periods { flex-wrap: wrap; gap: var(--bb-space-1); }
594
+ .bb-jh-filter-fields .bb-jh-normal-filters { flex: none; flex-direction: row; min-width: 0; }
595
+ .bb-jh-filter-fields .bb-jh-filter { display: grid; gap: var(--bb-space-1); max-width: 100%; white-space: normal; }
596
+ .bb-jh-filter-fields .bb-ws-combobox-trigger { max-width: 100%; }
597
+ @media (max-width: 760px) {
598
+ .bb-jh-filter-fields { flex: 1 1 100%; }
599
+ .bb-jh-filter-fields .bb-jh-normal-filters { flex: 1 1 100%; }
600
+ .bb-jh-filter-fields .bb-jh-filter { flex: 1 1 0; }
601
+ }
597
602
  .bb-jh-refresh { display: grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 6px; }
598
603
  .bb-jh-refresh-mark { display: block; width: 16px; height: 16px; }
599
604
  .bb-jh-notifications { display: grid; gap: 8px; }
@@ -15,7 +15,6 @@ const {
15
15
  makeWorkspaceElement,
16
16
  workspaceButton,
17
17
  workspaceDialog,
18
- workspaceFilterPopover,
19
18
  workspaceErrorCard,
20
19
  workspaceCombobox,
21
20
  workspaceDefinition,
@@ -1872,15 +1871,23 @@ function loadingLine(doc) {
1872
1871
  });
1873
1872
  }
1874
1873
 
1875
- function summaryLine(doc, aggregate, { loading = false } = {}) {
1876
- const retrieved = Number.isInteger(aggregate?.retrievedCount) ? aggregate.retrievedCount : (aggregate?.rows?.length ?? 0);
1877
- const complete = aggregate?.countComplete === true && Number.isInteger(aggregate?.totalCount);
1878
- const showCount = complete || retrieved > 0;
1879
- if (loading && !showCount) return loadingLine(doc);
1880
- const line = makeWorkspaceElement(doc, 'p', { className: 'bb-jh-summary' });
1881
- line.append(makeWorkspaceElement(doc, 'strong', { text: `${complete ? aggregate.totalCount : retrieved}件` }));
1882
- line.append(makeWorkspaceElement(doc, 'span', { text: loading ? ' 届きました(続きを読み込んでいます…)' : ' 取得済み' }));
1883
- if (loading) return line;
1874
+ function summaryLine(doc, aggregate, { loading = false, retrievedCount } = {}) {
1875
+ const retrieved = retrievedCount ?? aggregate?.retrievedCount ?? aggregate?.rows?.length ?? 0;
1876
+ const normal = aggregate?.mode === 'normal';
1877
+ const complete = normal
1878
+ ? aggregate?.totalCount !== null && Number.isInteger(aggregate?.totalCount)
1879
+ : aggregate?.status === 'available';
1880
+ if (loading && retrieved === 0) return loadingLine(doc);
1881
+ const visible = aggregate?.rows?.length ?? 0;
1882
+ const line = makeWorkspaceElement(doc, 'p', { className: 'bb-jh-summary', attrs: { 'aria-live': 'polite' } });
1883
+ const total = complete ? `${aggregate.totalCount}件${aggregate.query ? '(検索前)' : ''}` : '未確認';
1884
+ line.append(makeWorkspaceElement(doc, 'span', {
1885
+ text: `取得済み ${retrieved}件 · 条件一致 ${visible}件${aggregate.query && normal ? '(取得済みの範囲)' : ''} · 表示 ${visible ? `1–${visible}` : '0'}件 · 総数 ${total}`,
1886
+ }));
1887
+ if (loading) {
1888
+ line.append(makeWorkspaceElement(doc, 'span', { text: ' 届きました(続きを読み込んでいます…)' }));
1889
+ return line;
1890
+ }
1884
1891
  const references = aggregate?.stats?.referenceCount ?? aggregate?.stats?.references;
1885
1892
  const confirmed = aggregate?.stats?.confirmedOutcomes ?? aggregate?.stats?.outcomes;
1886
1893
  line.append(makeWorkspaceElement(doc, 'span', { text: ' ・ 使った参照 ' }));
@@ -1983,11 +1990,9 @@ export function createJudgmentHistoryUI({
1983
1990
  personalMemories: new Map(),
1984
1991
  };
1985
1992
 
1986
- let filterPopover = null;
1987
1993
  let filterComboboxes = [];
1988
1994
  // The record details stay open across redraws of the same screen.
1989
1995
  let recordDetailsOpen = false;
1990
- let filterExpanded = false;
1991
1996
  let drawer = null;
1992
1997
  let drawerContent = null;
1993
1998
  let drawerKey = null;
@@ -2399,14 +2404,11 @@ export function createJudgmentHistoryUI({
2399
2404
  root.replaceChildren(pending);
2400
2405
  return;
2401
2406
  }
2402
- const focusedFilter = filterExpanded && filterPopover
2403
- ? findFirst(filterPopover.panel, node => node === doc.activeElement) : null;
2407
+ const focusedFilter = findFirst(root, node => node === doc.activeElement && (attributeValue(node, 'data-filter') || attributeValue(node, 'data-period')));
2404
2408
  const filterFocus = focusedFilter && {
2405
2409
  filter: attributeValue(focusedFilter, 'data-filter'),
2406
2410
  label: attributeValue(focusedFilter, 'aria-label'), period: attributeValue(focusedFilter, 'data-period'),
2407
2411
  };
2408
- filterPopover?.destroy();
2409
- filterPopover = null;
2410
2412
  for (const combobox of filterComboboxes) combobox.destroy();
2411
2413
  filterComboboxes = [];
2412
2414
  const previousSearchInput = findFirst(root, isSearchInput);
@@ -2445,7 +2447,7 @@ export function createJudgmentHistoryUI({
2445
2447
  if (!nativeDrawer) renderRail(doc, rail, null, null);
2446
2448
  return;
2447
2449
  }
2448
- const controls = makeWorkspaceElement(doc, 'div', { className: 'bb-jh-controls' });
2450
+ const controls = makeWorkspaceElement(doc, 'div', { className: 'bb-jh-controls', attrs: { role: 'group', 'aria-label': '判断の履歴の絞り込み' } });
2449
2451
  const filterFields = makeWorkspaceElement(doc, 'div', { className: 'bb-jh-filter-fields' });
2450
2452
  filterFields.append(periodButtons(doc, state.period, (period) => {
2451
2453
  state.period = period;
@@ -2471,11 +2473,7 @@ export function createJudgmentHistoryUI({
2471
2473
  if (searchable) state.aggregate = aggregateJudgmentHistory(searchable, { now: readNow(), period: state.period, query: state.query });
2472
2474
  render();
2473
2475
  }));
2474
- filterPopover = workspaceFilterPopover(doc, {
2475
- content: filterFields, open: filterExpanded,
2476
- onToggle: value => { filterExpanded = value; },
2477
- });
2478
- controls.append(filterPopover.root);
2476
+ controls.append(filterFields);
2479
2477
  const toolbarStatus = makeWorkspaceElement(doc, 'div', { className: 'bb-jh-toolbar-status' });
2480
2478
  if (state.checkedAt) {
2481
2479
  const stamp = formatCheckedAt(state.checkedAt);
@@ -2504,7 +2502,9 @@ export function createJudgmentHistoryUI({
2504
2502
  toolbarStatus.append(reloadButton);
2505
2503
  controls.append(toolbarStatus);
2506
2504
  wrapper.append(controls);
2507
- wrapper.append(summaryLine(doc, aggregate, { loading }));
2505
+ wrapper.append(summaryLine(doc, aggregate, {
2506
+ loading, retrievedCount: (sourceHome?.mode === 'normal' ? sourceHome.records : sourceHome?.items)?.length ?? 0,
2507
+ }));
2508
2508
  const emptyText = loading ? '' : state.home?.status === 'partial' || (normalMode() && !aggregate.countComplete)
2509
2509
  ? 'この期間に取得できた判断履歴はありません。全件数が未確認のため0件とは確認できません。'
2510
2510
  : 'この期間の判断履歴はありません。';
@@ -2539,8 +2539,8 @@ export function createJudgmentHistoryUI({
2539
2539
  replaceNode(nextSearchInput, previousSearchInput);
2540
2540
  }
2541
2541
  root.replaceChildren(wrapper);
2542
- if (filterExpanded && filterFocus) {
2543
- const field = findFirst(filterPopover.panel, node => (filterFocus.filter
2542
+ if (filterFocus) {
2543
+ const field = findFirst(controls, node => (filterFocus.filter
2544
2544
  ? attributeValue(node, 'data-filter') === filterFocus.filter
2545
2545
  : filterFocus.label
2546
2546
  ? attributeValue(node, 'aria-label') === filterFocus.label
@@ -2731,7 +2731,6 @@ export function createJudgmentHistoryUI({
2731
2731
  state.disposed = true;
2732
2732
  state.generation += 1;
2733
2733
  clearLoadTimers();
2734
- filterPopover?.destroy();
2735
2734
  for (const combobox of filterComboboxes) combobox.destroy();
2736
2735
  notifications.remove?.();
2737
2736
  disposeDrawer();
@@ -1022,9 +1022,15 @@
1022
1022
  .bb-ws-filter-anchor[data-pointer-focus] .bb-ws-filter-popover select:focus-visible { outline: none; box-shadow: none; }
1023
1023
 
1024
1024
  /* Common page chrome; caller-owned tabs and tools retain their lifecycle. */
1025
- .bb-ws-topbar { height: var(--bb-page-header-height); min-height: var(--bb-page-header-height); padding: 0 24px; gap: 8px; box-shadow: inset 0 -1px 0 var(--bb-color-border); }
1026
- .bb-ws-topbar.has-query { gap: 8px; padding: 0 24px; padding-inline-end:var(--bb-page-header-inline-end, var(--bb-space-5)); }
1027
- .bb-ws-topbar.has-tabs > h1 { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
1025
+ .bb-ws-topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; height: auto; min-height: var(--bb-page-header-height); padding: 0 var(--bb-space-6); column-gap: var(--bb-space-2); row-gap: 0; box-shadow: none; }
1026
+ .bb-ws-topbar:is(.has-tabs, .has-query, .has-tools) { grid-template-rows: var(--bb-page-header-height) minmax(var(--bb-page-header-height), auto); }
1027
+ .bb-ws-topbar > h1 { grid-column: 1 / -1; grid-row: 1; display: flex; align-items: center; min-width: 0; min-height: var(--bb-page-header-height); border: 0; box-shadow: none; }
1028
+ .bb-ws-topbar > .bb-ws-topbar-tabs { grid-column: 1; grid-row: 2; }
1029
+ .bb-ws-topbar > .bb-ws-search-control { grid-column: 2; grid-row: 2; align-self: center; }
1030
+ .bb-ws-topbar > .bb-ws-topbar-tools { grid-column: 3; grid-row: 2; }
1031
+ .bb-ws-topbar.has-tabs { box-shadow: inset 0 -1px 0 var(--bb-color-border); }
1032
+ .bb-ws-topbar.has-query { column-gap: var(--bb-space-2); row-gap: 0; padding: 0 var(--bb-space-6); padding-inline-end:var(--bb-page-header-inline-end, var(--bb-space-5)); }
1033
+ /* Tabs do not hide the page title; the second grid row owns all controls. */
1028
1034
  .bb-ws-topbar-tabs { display: flex; align-self: stretch; min-width: 0; }
1029
1035
  .bb-ws-topbar-tools { display: flex; align-items: center; flex: none; gap: 8px; margin-left: auto; }
1030
1036
  .bb-ws-topbar.has-query .bb-ws-topbar-tools { margin-left: 0; }
@@ -1193,9 +1199,11 @@
1193
1199
  .bb-ws-tabs--header > :is([role="tab"],a,button) { display:block; line-height:1.6; }
1194
1200
  .bb-ws-tabs--header .bb-ws-tab-count { line-height:1.6; }
1195
1201
  @media(max-width:1200px) {
1196
- .bb-ws-topbar.bb-ws-topbar--wrap { flex-wrap:wrap; height:auto; min-height:52px; padding-bottom:8px; }
1197
- .bb-ws-topbar--wrap .bb-ws-topbar-tabs { flex-basis:100%; height:52px; }
1198
- .bb-ws-topbar--wrap .bb-ws-search-control { flex:1; min-width:72px; }
1202
+ .bb-ws-topbar.bb-ws-topbar--wrap { grid-template-columns: minmax(0, 1fr) auto; height:auto; min-height:var(--bb-page-header-height); padding-bottom:0; }
1203
+ .bb-ws-topbar--wrap.has-tabs:is(.has-query, .has-tools) { grid-template-rows: var(--bb-page-header-height) var(--bb-page-header-height) minmax(var(--bb-page-header-height), auto); }
1204
+ .bb-ws-topbar--wrap.has-tabs > .bb-ws-topbar-tabs { grid-column: 1 / -1; }
1205
+ .bb-ws-topbar--wrap.has-tabs > .bb-ws-search-control { grid-column: 1; grid-row: 3; min-width: 0; width: auto; margin-left: 0; }
1206
+ .bb-ws-topbar--wrap.has-tabs > .bb-ws-topbar-tools { grid-column: 2; grid-row: 3; }
1199
1207
  }
1200
1208
 
1201
1209
  .bb-ws-tabs--header .bb-ws-tab-count { font-feature-settings:normal; font-variant-numeric:normal; }
@@ -1277,3 +1285,14 @@
1277
1285
  .bb-ws-button.is-icon .bb-ws-action-icon,
1278
1286
  .bb-ws-topbar.has-tabs .bb-ws-topbar-tools > .bb-ws-button.is-icon .bb-ws-action-icon { width:16px; height:16px; }
1279
1287
  .bb-ws-button.is-icon:focus-visible { outline:2px solid var(--bb-color-focus); outline-offset:2px; }
1288
+
1289
+ /* A narrow header keeps the title and tabs full width before its controls. */
1290
+ @media (max-width: 760px) {
1291
+ .bb-ws-topbar, .bb-ws-topbar.has-query { grid-template-columns: minmax(0, 1fr) auto; padding-inline: var(--bb-space-3); padding-inline-start: var(--bb-page-header-inline-start, var(--bb-space-3)); }
1292
+ .bb-ws-topbar > .bb-ws-search-control { grid-column: 1; min-width: 0; width: auto; margin-left: 0; }
1293
+ .bb-ws-topbar > .bb-ws-topbar-tools { grid-column: 2; min-width: 0; }
1294
+ .bb-ws-topbar.has-tabs > .bb-ws-topbar-tabs { grid-column: 1 / -1; }
1295
+ .bb-ws-topbar.has-tabs:is(.has-query, .has-tools) { grid-template-rows: var(--bb-page-header-height) var(--bb-page-header-height) minmax(var(--bb-page-header-height), auto); }
1296
+ .bb-ws-topbar.has-tabs > :is(.bb-ws-search-control, .bb-ws-topbar-tools) { grid-row: 3; }
1297
+ .bb-ws-topbar.has-tabs:not(.has-query) > .bb-ws-topbar-tools { grid-column: 1 / -1; justify-content: flex-end; }
1298
+ }