@unson/brainbase-mcp 0.48.2 → 0.48.4

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.
@@ -0,0 +1,457 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { closeSync, existsSync, linkSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { checkJudgmentPublicFrame, judgmentFramePublicFrameDigest, containsJudgmentFrameCredential, publicFrameTextHasControlCharacters } from './judgment-frame.js';
5
+ import { canonicalJson } from './judgment-history.js';
6
+ /**
7
+ * RQ-119 Story S1: the common emission port that turns a Worker turn into the
8
+ * shared judgment receipt contract, derives its idempotency keys, and writes it
9
+ * to a local outbox before any delivery. Delivery is an injected transport; the
10
+ * OSS default is local-only (nothing is sent). Tool-specific adapters (S2/S3),
11
+ * the organization transport and receiving endpoint (S4), and retry/visibility
12
+ * (S5) are intentionally out of this module.
13
+ */
14
+ export const WORKER_JUDGMENT_RECEIPT_SCHEMA = 'brainbase-worker-judgment-receipt-v1';
15
+ export const WORKER_JUDGMENT_OUTBOX_SCHEMA = 'brainbase-worker-judgment-outbox-v1';
16
+ export const WORKER_JUDGMENT_SKIP_SCHEMA = 'brainbase-worker-judgment-skip-v1';
17
+ /** The presence of a `<resolution_id>.json.sent` marker is the authoritative "delivered" signal; the outbox body is never rewritten on success. */
18
+ export const WORKER_JUDGMENT_SENT_SCHEMA = 'brainbase-worker-judgment-sent-v1';
19
+ /** Only Worker tools emit through this port. `opencode` is the shared enum value for DeepSeek via opencode. */
20
+ export const WORKER_JUDGMENT_ENTRYPOINTS = Object.freeze(['claude_code', 'opencode']);
21
+ export class WorkerJudgmentEmitterError extends Error {
22
+ code;
23
+ constructor(code, message) {
24
+ super(message);
25
+ this.name = 'WorkerJudgmentEmitterError';
26
+ this.code = code;
27
+ }
28
+ }
29
+ /** Raised when the same resolution id is already stored with a different receipt (§6 conflict). We never overwrite. */
30
+ export class WorkerJudgmentConflictError extends WorkerJudgmentEmitterError {
31
+ resolution_id;
32
+ constructor(resolutionId) {
33
+ super('worker_judgment_receipt_conflict', `A different receipt is already stored for resolution ${resolutionId}`);
34
+ this.name = 'WorkerJudgmentConflictError';
35
+ this.resolution_id = resolutionId;
36
+ }
37
+ }
38
+ const MAX_META_TEXT = 200;
39
+ const DEFAULT_MAX_FUTURE_SKEW_MS = 24 * 60 * 60 * 1000;
40
+ function sha256Hex(value) {
41
+ return createHash('sha256').update(value, 'utf8').digest('hex');
42
+ }
43
+ /**
44
+ * Accept only an explicit calendar date-time that carries a timezone (`Z` or a
45
+ * numeric offset). A zone-less value like `2026-10-01T00:00:00` would otherwise
46
+ * be read in the host timezone, so the §8 boundary and the receipt_digest would
47
+ * differ between a UTC runner and an Asia/Tokyo laptop. Calendar fields are
48
+ * checked against a UTC round-trip so a rolled-over date (`2026-02-30`,
49
+ * hour `25`) is rejected rather than silently carried forward. The accepted
50
+ * value is returned normalized to a UTC ISO string; it is never rewritten
51
+ * beyond that canonicalization.
52
+ */
53
+ const ISO_DATETIME_WITH_TZ = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;
54
+ function normalizeIso(value) {
55
+ if (typeof value !== 'string')
56
+ return null;
57
+ const trimmed = value.trim();
58
+ const match = ISO_DATETIME_WITH_TZ.exec(trimmed);
59
+ if (!match)
60
+ return null;
61
+ const [, y, mo, d, h, mi, s] = match;
62
+ const year = Number(y);
63
+ const month = Number(mo);
64
+ const day = Number(d);
65
+ const hour = Number(h);
66
+ const minute = Number(mi);
67
+ const second = Number(s);
68
+ const check = new Date(Date.UTC(year, month - 1, day, hour, minute, second));
69
+ if (check.getUTCFullYear() !== year || check.getUTCMonth() !== month - 1 || check.getUTCDate() !== day
70
+ || check.getUTCHours() !== hour || check.getUTCMinutes() !== minute || check.getUTCSeconds() !== second) {
71
+ return null;
72
+ }
73
+ const ms = Date.parse(trimmed);
74
+ if (!Number.isFinite(ms))
75
+ return null;
76
+ return new Date(ms).toISOString();
77
+ }
78
+ function requireId(value, field) {
79
+ if (typeof value !== 'string' || !value.trim()) {
80
+ throw new WorkerJudgmentEmitterError('worker_judgment_input_invalid', `${field} is required`);
81
+ }
82
+ return value;
83
+ }
84
+ /** `null` = not provided; a string = accepted; `undefined` = provided but unusable (rejected). */
85
+ function normalizeMetaField(value) {
86
+ if (value === undefined || value === null)
87
+ return null;
88
+ if (typeof value !== 'string' || !value.trim() || value.length > MAX_META_TEXT
89
+ || publicFrameTextHasControlCharacters(value) || containsJudgmentFrameCredential(value)) {
90
+ return undefined;
91
+ }
92
+ return value;
93
+ }
94
+ /**
95
+ * `project_code` is stored in the receipt and handed to any injected transport,
96
+ * so it gets the same secret/control-character/length screen as meta. An absent,
97
+ * null, or blank string is "not recorded" (`null`); a value of the wrong type
98
+ * (e.g. a number smuggled in from a CLI JSON payload), or a non-empty string
99
+ * that fails the screen, is rejected (`undefined`) instead of being silently
100
+ * dropped to `null` and losing the project link.
101
+ */
102
+ function normalizeProjectCode(value) {
103
+ if (value === undefined || value === null)
104
+ return null;
105
+ if (typeof value !== 'string')
106
+ return undefined;
107
+ if (!value.trim())
108
+ return null;
109
+ if (value.length > MAX_META_TEXT || publicFrameTextHasControlCharacters(value) || containsJudgmentFrameCredential(value)) {
110
+ return undefined;
111
+ }
112
+ return value;
113
+ }
114
+ /**
115
+ * Build the deterministic receipt from a turn, or decide not to send it.
116
+ * Pure: the same input and `effectiveAfter` always yield the same receipt and
117
+ * the same `resolution_id`. `now` only bounds how far into the future a
118
+ * `resolved_at` may sit; it never enters the receipt.
119
+ */
120
+ export function buildWorkerJudgmentReceipt(input, config) {
121
+ if (!WORKER_JUDGMENT_ENTRYPOINTS.includes(input.entrypoint)) {
122
+ throw new WorkerJudgmentEmitterError('worker_judgment_entrypoint_invalid', `entrypoint must be one of ${WORKER_JUDGMENT_ENTRYPOINTS.join(', ')}`);
123
+ }
124
+ const sessionId = requireId(input.session_id, 'session_id');
125
+ const turnId = requireId(input.turn_id, 'turn_id');
126
+ const boundary = normalizeIso(config.effectiveAfter);
127
+ if (!boundary) {
128
+ throw new WorkerJudgmentEmitterError('worker_judgment_effective_after_invalid', 'effectiveAfter must be an ISO time');
129
+ }
130
+ const frameCheck = checkJudgmentPublicFrame(input.public_frame);
131
+ if (!frameCheck.ok) {
132
+ const reason_code = frameCheck.code === 'frame_public_absent'
133
+ ? 'worker_public_frame_absent'
134
+ : 'frame_public_invalid';
135
+ return { outcome: 'skipped', reason_code, detail: frameCheck.detail };
136
+ }
137
+ const model = normalizeMetaField(input.meta?.model);
138
+ const agentMemberId = normalizeMetaField(input.meta?.agent_member_id);
139
+ if (model === undefined || agentMemberId === undefined) {
140
+ return { outcome: 'skipped', reason_code: 'worker_meta_invalid', detail: 'meta contains an invalid or credential-like value' };
141
+ }
142
+ const projectCode = normalizeProjectCode(input.project_code);
143
+ if (projectCode === undefined) {
144
+ return { outcome: 'skipped', reason_code: 'worker_project_code_invalid', detail: 'project_code is invalid or credential-like' };
145
+ }
146
+ if (input.resolved_at === undefined || input.resolved_at === null
147
+ || (typeof input.resolved_at === 'string' && !input.resolved_at.trim())) {
148
+ return { outcome: 'skipped', reason_code: 'worker_resolved_at_missing', detail: 'resolved_at was not provided' };
149
+ }
150
+ const resolvedAt = normalizeIso(input.resolved_at);
151
+ if (!resolvedAt) {
152
+ return { outcome: 'skipped', reason_code: 'worker_resolved_at_invalid', detail: 'resolved_at is not a valid ISO time' };
153
+ }
154
+ const now = (config.now ?? (() => new Date()))();
155
+ const skew = config.maxFutureSkewMs ?? DEFAULT_MAX_FUTURE_SKEW_MS;
156
+ if (Date.parse(resolvedAt) > now.getTime() + skew) {
157
+ return { outcome: 'skipped', reason_code: 'worker_resolved_at_invalid', detail: 'resolved_at is too far in the future' };
158
+ }
159
+ if (Date.parse(resolvedAt) < Date.parse(boundary)) {
160
+ return { outcome: 'skipped', reason_code: 'worker_resolved_at_before_boundary', detail: 'resolved_at is before the activation boundary' };
161
+ }
162
+ const contentDigest = judgmentFramePublicFrameDigest(frameCheck.frame);
163
+ const resolutionId = sha256Hex(canonicalJson({
164
+ content_digest: contentDigest,
165
+ entrypoint: input.entrypoint,
166
+ session_id: sessionId,
167
+ turn_id: turnId
168
+ }));
169
+ const core = {
170
+ schema_version: WORKER_JUDGMENT_RECEIPT_SCHEMA,
171
+ resolution_id: resolutionId,
172
+ entrypoint: input.entrypoint,
173
+ turn_ref: `${sha256Hex(sessionId)}/${sha256Hex(turnId)}`,
174
+ project_code: projectCode,
175
+ resolved_at: resolvedAt,
176
+ public_frame: frameCheck.frame,
177
+ content_digest: contentDigest,
178
+ meta: { model, agent_member_id: agentMemberId }
179
+ };
180
+ const receiptDigest = sha256Hex(canonicalJson(core));
181
+ return { outcome: 'receipt', receipt: { ...core, receipt_digest: receiptDigest } };
182
+ }
183
+ /** Resolve the per-turn outbox directory. Session and turn are hashed so neither raw id reaches the path. */
184
+ export function resolveWorkerJudgmentTurnDir(journalRoot, sessionId, turnId) {
185
+ return join(journalRoot, sha256Hex(requireId(sessionId, 'session_id')), sha256Hex(requireId(turnId, 'turn_id')));
186
+ }
187
+ /**
188
+ * A per-process counter so two writes that share a pid and an injected (fixed)
189
+ * clock still get distinct temp names. Without it, two concurrent writers under a
190
+ * test clock would collide on the temp path.
191
+ */
192
+ let outboxTempSequence = 0;
193
+ function nextTempPath(target, now) {
194
+ outboxTempSequence += 1;
195
+ return `${target}.${process.pid}.${now().getTime()}.${outboxTempSequence}.tmp`;
196
+ }
197
+ function atomicWriteReplace(target, value, now) {
198
+ const temporary = nextTempPath(target, now);
199
+ writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 });
200
+ renameSync(temporary, target);
201
+ }
202
+ /**
203
+ * Publish a receipt without replacing one another writer created. The temp file
204
+ * is complete before the hard link makes it visible, so a reader sees either the
205
+ * old file or the complete new file — the same discipline as the judgment event
206
+ * outbox.
207
+ */
208
+ function atomicPublishNoReplace(target, value, now) {
209
+ const temporary = nextTempPath(target, now);
210
+ writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 });
211
+ try {
212
+ linkSync(temporary, target);
213
+ }
214
+ finally {
215
+ try {
216
+ unlinkSync(temporary);
217
+ }
218
+ catch { /* publication may have failed */ }
219
+ }
220
+ }
221
+ function isErrno(error, code) {
222
+ return Boolean(error && typeof error === 'object' && 'code' in error && error.code === code);
223
+ }
224
+ const DELIVERY_STATUSES = ['pending', 'saved', 'already_saved', 'blocked_credential', 'failed'];
225
+ /** A delivery state a later re-emit must never silently undo. */
226
+ function isSuccessStatus(status) {
227
+ return status === 'saved' || status === 'already_saved';
228
+ }
229
+ /** Raised when a stored outbox file exists but is corrupt. We never re-send or overwrite over corruption (§ fail loudly). */
230
+ export class WorkerJudgmentOutboxCorruptError extends WorkerJudgmentEmitterError {
231
+ constructor(path, detail) {
232
+ super('worker_judgment_outbox_corrupt', `Stored outbox ${path} ${detail}`);
233
+ this.name = 'WorkerJudgmentOutboxCorruptError';
234
+ }
235
+ }
236
+ /** Recompute the receipt_digest from the receipt body so a tampered or truncated body cannot ride on a stale digest string. */
237
+ function recomputeReceiptDigest(receipt) {
238
+ const core = { ...receipt };
239
+ delete core.receipt_digest;
240
+ return sha256Hex(canonicalJson(core));
241
+ }
242
+ /**
243
+ * Read the digest and the recorded delivery state of a receipt already on disk.
244
+ * A re-emit must compare the digest (§6 conflict) and must not undo delivery
245
+ * progress, so the stored status is read too. The stored digest string is not
246
+ * trusted on its own: the receipt_digest is recomputed from the receipt body,
247
+ * the outbox schema and the delivery status are verified, and any mismatch is a
248
+ * loud `WorkerJudgmentOutboxCorruptError` rather than a silent re-send or
249
+ * overwrite. Returns `null` only when the file is genuinely absent.
250
+ */
251
+ function readStoredOutboxState(path) {
252
+ let raw;
253
+ try {
254
+ raw = readFileSync(path, 'utf8');
255
+ }
256
+ catch (error) {
257
+ if (isErrno(error, 'ENOENT'))
258
+ return null;
259
+ throw new WorkerJudgmentOutboxCorruptError(path, 'could not be read');
260
+ }
261
+ let parsed;
262
+ try {
263
+ parsed = JSON.parse(raw);
264
+ }
265
+ catch {
266
+ throw new WorkerJudgmentOutboxCorruptError(path, 'is not valid JSON');
267
+ }
268
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
269
+ throw new WorkerJudgmentOutboxCorruptError(path, 'is not an object');
270
+ }
271
+ if (parsed.schema_version !== WORKER_JUDGMENT_OUTBOX_SCHEMA) {
272
+ throw new WorkerJudgmentOutboxCorruptError(path, 'has an unexpected schema_version');
273
+ }
274
+ const receipt = parsed.receipt;
275
+ if (!receipt || typeof receipt !== 'object' || Array.isArray(receipt)) {
276
+ throw new WorkerJudgmentOutboxCorruptError(path, 'is missing its receipt');
277
+ }
278
+ const digest = receipt.receipt_digest;
279
+ if (typeof digest !== 'string' || !digest) {
280
+ throw new WorkerJudgmentOutboxCorruptError(path, 'is missing its receipt_digest');
281
+ }
282
+ let recomputed;
283
+ try {
284
+ recomputed = recomputeReceiptDigest(receipt);
285
+ }
286
+ catch {
287
+ throw new WorkerJudgmentOutboxCorruptError(path, 'has a receipt body that cannot be canonicalized');
288
+ }
289
+ if (recomputed !== digest) {
290
+ throw new WorkerJudgmentOutboxCorruptError(path, 'has a receipt_digest that does not match its body');
291
+ }
292
+ const delivery = parsed.delivery;
293
+ if (!delivery || typeof delivery !== 'object' || Array.isArray(delivery)) {
294
+ throw new WorkerJudgmentOutboxCorruptError(path, 'is missing its delivery state');
295
+ }
296
+ const rawStatus = delivery.status;
297
+ if (!DELIVERY_STATUSES.includes(rawStatus)) {
298
+ throw new WorkerJudgmentOutboxCorruptError(path, 'has an invalid delivery status');
299
+ }
300
+ const status = rawStatus;
301
+ const rawError = delivery.last_error_code;
302
+ if (rawError !== undefined && typeof rawError !== 'string') {
303
+ throw new WorkerJudgmentOutboxCorruptError(path, 'has an invalid last_error_code');
304
+ }
305
+ return { receipt_digest: digest, status, ...(typeof rawError === 'string' ? { last_error_code: rawError } : {}) };
306
+ }
307
+ /**
308
+ * Record a successful delivery as a separate marker file created exclusively
309
+ * (`wx`). The outbox body is never rewritten on success, so a slow concurrent
310
+ * failure cannot clobber a recorded success: the marker's presence — not a body
311
+ * status — is the authoritative "delivered" signal, and a marker, once created,
312
+ * is never removed. Creating a marker that already exists is treated as success:
313
+ * another writer, or an earlier crash, already delivered it. The marker carries
314
+ * no judgment body, only a schema tag and the time it was recorded, and its
315
+ * content is never read: presence alone means saved, so a crash between creating
316
+ * and writing the marker still reads as delivered.
317
+ */
318
+ function recordDeliverySuccess(markerPath, now) {
319
+ let fd;
320
+ try {
321
+ fd = openSync(markerPath, 'wx', 0o600);
322
+ }
323
+ catch (error) {
324
+ if (isErrno(error, 'EEXIST'))
325
+ return;
326
+ throw error;
327
+ }
328
+ try {
329
+ writeFileSync(fd, `${JSON.stringify({ schema_version: WORKER_JUDGMENT_SENT_SCHEMA, recorded_at: now().toISOString() })}\n`);
330
+ }
331
+ finally {
332
+ closeSync(fd);
333
+ }
334
+ }
335
+ /** True when a success marker is present. Presence is the only signal; the content is never read. */
336
+ function deliverySucceeded(markerPath) {
337
+ return existsSync(markerPath);
338
+ }
339
+ /**
340
+ * Turn a Worker turn into a receipt and write it to the local outbox, then —
341
+ * only if a transport is injected — attempt a single delivery and record its
342
+ * status. With no transport the receipt stays `pending` locally. Re-emitting
343
+ * the identical turn is idempotent; a different receipt under the same
344
+ * resolution id is a loud conflict. Nothing here writes the raw session/turn
345
+ * ids, the prompt, the response, or any credential.
346
+ */
347
+ export async function emitWorkerJudgment(input, options) {
348
+ if (!options.journalRoot)
349
+ throw new WorkerJudgmentEmitterError('worker_judgment_journal_root_required', 'journalRoot is required');
350
+ const now = options.now ?? (() => new Date());
351
+ const built = buildWorkerJudgmentReceipt(input, {
352
+ effectiveAfter: options.effectiveAfter,
353
+ now,
354
+ maxFutureSkewMs: options.maxFutureSkewMs
355
+ });
356
+ const dir = resolveWorkerJudgmentTurnDir(options.journalRoot, input.session_id, input.turn_id);
357
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
358
+ if (built.outcome === 'skipped') {
359
+ const target = join(dir, 'skip.json');
360
+ atomicWriteReplace(target, {
361
+ schema_version: WORKER_JUDGMENT_SKIP_SCHEMA,
362
+ entrypoint: input.entrypoint,
363
+ turn_ref: `${sha256Hex(input.session_id)}/${sha256Hex(input.turn_id)}`,
364
+ reason_code: built.reason_code,
365
+ recorded_at: now().toISOString()
366
+ }, now);
367
+ return { outcome: 'skipped', reason_code: built.reason_code, path: target };
368
+ }
369
+ const receipt = built.receipt;
370
+ const target = join(dir, `${receipt.resolution_id}.json`);
371
+ const markerPath = `${target}.sent`;
372
+ let deduped = false;
373
+ let stored = null;
374
+ try {
375
+ atomicPublishNoReplace(target, {
376
+ schema_version: WORKER_JUDGMENT_OUTBOX_SCHEMA,
377
+ receipt,
378
+ delivery: { status: 'pending', attempt: 1, queued_at: now().toISOString() }
379
+ }, now);
380
+ }
381
+ catch (error) {
382
+ if (!isErrno(error, 'EEXIST'))
383
+ throw error;
384
+ stored = readStoredOutboxState(target);
385
+ if (!stored || stored.receipt_digest !== receipt.receipt_digest)
386
+ throw new WorkerJudgmentConflictError(receipt.resolution_id);
387
+ deduped = true;
388
+ }
389
+ // A delivered receipt is marked by a `.sent` file, never by the outbox body:
390
+ // if the marker is present the receipt was already saved and must not be
391
+ // re-sent or downgraded, whatever the body or a later transport says.
392
+ if (deliverySucceeded(markerPath)) {
393
+ return { outcome: 'emitted', status: 'saved', receipt, path: target, deduped };
394
+ }
395
+ // Legacy success: an outbox written before the `.sent` marker existed recorded
396
+ // delivery only in its body. A marker-less `saved` / `already_saved` body is
397
+ // still an authoritative success, so honor it exactly like a marker — never
398
+ // re-send through the transport, and never let a later failure downgrade it.
399
+ if (stored && isSuccessStatus(stored.status)) {
400
+ return {
401
+ outcome: 'emitted',
402
+ status: stored.status,
403
+ receipt,
404
+ path: target,
405
+ deduped,
406
+ ...(stored.last_error_code ? { last_error_code: stored.last_error_code } : {})
407
+ };
408
+ }
409
+ if (!options.transport) {
410
+ // No transport: the receipt keeps whatever the body already recorded
411
+ // (`pending` on a first write, or a prior `failed`), never a fresh success.
412
+ const status = stored ? stored.status : 'pending';
413
+ return {
414
+ outcome: 'emitted',
415
+ status,
416
+ receipt,
417
+ path: target,
418
+ deduped,
419
+ ...(stored?.last_error_code ? { last_error_code: stored.last_error_code } : {})
420
+ };
421
+ }
422
+ let status = 'pending';
423
+ let lastErrorCode;
424
+ try {
425
+ const result = await options.transport.send(receipt);
426
+ status = result.status;
427
+ if (result.status === 'blocked_credential' || result.status === 'failed')
428
+ lastErrorCode = result.reason_code;
429
+ }
430
+ catch (error) {
431
+ status = 'failed';
432
+ lastErrorCode = error instanceof WorkerJudgmentEmitterError ? error.code : 'worker_judgment_transport_error';
433
+ }
434
+ if (isSuccessStatus(status)) {
435
+ // Success is recorded only by exclusively creating the marker; the body is
436
+ // left as published. An already-present marker means a concurrent writer (or
437
+ // an earlier crash mid-delivery) already recorded success, which is fine.
438
+ recordDeliverySuccess(markerPath, now);
439
+ return { outcome: 'emitted', status, receipt, path: target, deduped };
440
+ }
441
+ // Delivery failed. If a concurrent re-emit already recorded success, keep that
442
+ // success and neither record the failure in the body nor touch the marker.
443
+ if (deliverySucceeded(markerPath)) {
444
+ return { outcome: 'emitted', status: 'saved', receipt, path: target, deduped };
445
+ }
446
+ atomicWriteReplace(target, {
447
+ schema_version: WORKER_JUDGMENT_OUTBOX_SCHEMA,
448
+ receipt,
449
+ delivery: {
450
+ status,
451
+ attempt: 1,
452
+ queued_at: now().toISOString(),
453
+ ...(lastErrorCode ? { last_error_code: lastErrorCode } : {})
454
+ }
455
+ }, now);
456
+ return { outcome: 'emitted', status, receipt, path: target, deduped, ...(lastErrorCode ? { last_error_code: lastErrorCode } : {}) };
457
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unson/brainbase-mcp",
3
- "version": "0.48.2",
3
+ "version": "0.48.4",
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",
@@ -624,5 +624,5 @@
624
624
  "url": "https://github.com/Unson-LLC/brainbase/issues"
625
625
  },
626
626
  "homepage": "https://github.com/Unson-LLC/brainbase#readme",
627
- "gitHead": "3f46f634582ced92909c3e8e26432ac021b99326"
627
+ "gitHead": "28e45e4b142af07f8ece86fc4068e2121ebe4bbc"
628
628
  }
package/ui/area-nav.css CHANGED
@@ -75,6 +75,7 @@
75
75
  border-radius: 999px;
76
76
  padding: 0 6px;
77
77
  background: var(--bb-color-accent-soft);
78
+ --bb-color-muted: var(--bb-color-muted-on-surface);
78
79
  color: var(--bb-color-accent);
79
80
  font-size: 11px;
80
81
  font-weight: var(--bb-font-weight-medium);
@@ -11,8 +11,18 @@
11
11
  * Status colors retain their semantic meaning; hosts can still override tokens.
12
12
  */
13
13
  :root {
14
+ /* Shared motion curves and dismissal durations. */
15
+ --bb-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
16
+ --bb-ease-in-out: cubic-bezier(0.77, 0, 0.175, 1); /* On-screen movement/position swaps only, not enter/exit. */
17
+ --bb-ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
18
+ --bb-ease-drawer-in: ease-out;
19
+ --bb-duration-drawer-in: 180ms;
20
+ --bb-duration-drawer-out: 150ms;
21
+ --bb-duration-toast-out: 200ms;
14
22
  --bb-color-ink: #202939;
15
23
  --bb-color-muted: #6b7280;
24
+ /* Small secondary text on tinted surfaces needs a slightly darker mix. */
25
+ --bb-color-muted-on-surface: color-mix(in srgb, var(--bb-color-muted) 92%, var(--bb-color-ink));
16
26
  --bb-color-quiet: #6b7280;
17
27
  --bb-color-border: #dce4e7;
18
28
  --bb-color-border-strong: #dce4e7;
@@ -109,6 +119,8 @@
109
119
  --bb-tab-line-height: 20px;
110
120
  --bb-tab-font-weight: 500;
111
121
  --bb-tab-indicator-size: 2px;
122
+ --bb-tab-indicator-duration: 260ms;
123
+ --bb-tab-indicator-ease: cubic-bezier(.2, .8, .2, 1);
112
124
  --bb-tab-count-size: 20px;
113
125
  --bb-tab-count-font-size: 12px;
114
126
  /* Opt-in search band: dimensions and interaction surfaces. */
@@ -232,7 +232,8 @@
232
232
 
233
233
  .bb-fov-objective-ledger .bb-ws-ledger-row { grid-template-columns: minmax(180px,1.2fr) minmax(200px,1.3fr) minmax(150px,1fr) 110px; }
234
234
  .bb-fov-objective-ledger .bb-ws-ledger-row > span { white-space: normal; line-height: 1.7; }
235
- .bb-fov-objective-ledger .bb-ws-ledger-row:is(.is-selected,:hover) { background: var(--bb-color-accent-soft); box-shadow: inset 3px 0 var(--bb-color-accent); }
235
+ .bb-fov-objective-ledger .bb-ws-ledger-row:is(.is-selected,:hover) { background: var(--bb-color-accent-soft);
236
+ --bb-color-muted: var(--bb-color-muted-on-surface); box-shadow: inset 3px 0 var(--bb-color-accent); }
236
237
  .bb-fov .bb-ws-section-title { display: flex; align-items: center; gap: 8px; }
237
238
  .bb-fov-philosophy-grid { grid-template-columns: minmax(0,1fr); }
238
239
  .bb-fov-philosophy-card { border-top: 0; width: 100%; box-sizing: border-box; }
@@ -71,6 +71,7 @@
71
71
  border-radius: 999px;
72
72
  padding: 3px 6px 3px 10px;
73
73
  background: var(--bb-color-accent-soft);
74
+ --bb-color-muted: var(--bb-color-muted-on-surface);
74
75
  color: var(--bb-color-ink);
75
76
  font: inherit;
76
77
  font-size: 12px;
@@ -1,4 +1,4 @@
1
- import { workspaceTabList } from './workspace-kit.js';
1
+ import { workspaceTabStrip } from './workspace-kit.js';
2
2
  /*
3
3
  * 「情報と関係」: what the local Graph holds, how records are connected, and
4
4
  * where to correct a mistake so the next MCP use sees the fix.
@@ -469,7 +469,7 @@ export function createGraphRegistryView({
469
469
  .map(({ id }) => id)
470
470
  .filter((id) => id === selected || counts.get(id)?.count !== 0);
471
471
  const tabs = makeElement(doc, 'div', { className: 'bb-gr-tabs', attrs: { role: 'tablist', 'aria-label': '種類' } });
472
- workspaceTabList(tabs);
472
+ workspaceTabStrip(tabs, { memoryKey: 'graph-registry-kinds' });
473
473
  for (const id of ['', ...ids]) {
474
474
  const item = counts.get(id);
475
475
  const count = Number.isInteger(item?.count) ? String(item.count)
@@ -114,6 +114,7 @@
114
114
  border-radius: var(--bb-radius-sm);
115
115
  color: var(--bb-color-accent-strong);
116
116
  background: var(--bb-color-accent-soft);
117
+ --bb-color-muted: var(--bb-color-muted-on-surface);
117
118
  font-size: 15px;
118
119
  font-weight: var(--bb-font-weight-medium);
119
120
  line-height: 1;
@@ -256,7 +257,8 @@
256
257
  .bb-graph-badge.is-success { color: var(--bb-color-accent-strong); background: var(--bb-color-success-soft); }
257
258
  .bb-graph-badge.is-warning { color: var(--bb-color-warning); background: var(--bb-color-warning-soft); }
258
259
  .bb-graph-badge.is-danger { color: var(--bb-color-danger); background: var(--bb-color-danger-soft); }
259
- .bb-graph-badge.is-accent { color: var(--bb-color-accent-strong); background: var(--bb-color-accent-soft); }
260
+ .bb-graph-badge.is-accent { color: var(--bb-color-accent-strong); background: var(--bb-color-accent-soft);
261
+ --bb-color-muted: var(--bb-color-muted-on-surface); }
260
262
 
261
263
  /* Inline messages inside the correction form. */
262
264
  .bb-graph-notice,
@@ -268,11 +270,13 @@
268
270
  overflow-wrap: anywhere;
269
271
  }
270
272
 
271
- .bb-graph-notice.is-muted { border-left-color: var(--bb-color-border-strong); color: var(--bb-color-muted); background: var(--bb-color-surface); }
273
+ .bb-graph-notice.is-muted { border-left-color: var(--bb-color-border-strong); color: var(--bb-color-muted); background: var(--bb-color-surface);
274
+ --bb-color-muted: var(--bb-color-muted-on-surface); }
272
275
  .bb-graph-notice.is-warning { border-left-color: var(--bb-color-warning); color: var(--bb-color-warning); background: var(--bb-color-warning-soft); }
273
276
  .bb-graph-notice.is-danger { border-left-color: var(--bb-color-danger); color: var(--bb-color-danger); background: var(--bb-color-danger-soft); }
274
277
  .bb-graph-notice.is-success,
275
- .bb-graph-notice.is-accent { border-left-color: var(--bb-color-accent); color: var(--bb-color-accent-strong); background: var(--bb-color-accent-soft); }
278
+ .bb-graph-notice.is-accent { border-left-color: var(--bb-color-accent); color: var(--bb-color-accent-strong); background: var(--bb-color-accent-soft);
279
+ --bb-color-muted: var(--bb-color-muted-on-surface); }
276
280
 
277
281
  /* A name that opens a record. */
278
282
  .bb-graph-link {
@@ -318,6 +322,7 @@
318
322
  /* The selected row keeps its soft green while the pointer is on it. */
319
323
  .bb-graph .bb-ws-ledger-row.is-selected:hover {
320
324
  background: var(--bb-color-accent-soft);
325
+ --bb-color-muted: var(--bb-color-muted-on-surface);
321
326
  }
322
327
 
323
328
  .bb-graph-facts {
package/ui/inbox.css CHANGED
@@ -12,6 +12,7 @@
12
12
  border-radius: 999px;
13
13
  padding: 0 6px;
14
14
  background: var(--bb-color-accent-soft);
15
+ --bb-color-muted: var(--bb-color-muted-on-surface);
15
16
  color: var(--bb-color-accent);
16
17
  font-size: 11px;
17
18
  font-weight: var(--bb-font-weight-medium);
@@ -24,6 +25,7 @@
24
25
  margin: 0 0 10px;
25
26
  overflow: hidden;
26
27
  background: var(--bb-color-accent-soft);
28
+ --bb-color-muted: var(--bb-color-muted-on-surface);
27
29
  color: transparent;
28
30
  font-size: 0;
29
31
  }
@@ -73,6 +75,7 @@
73
75
  border-radius: var(--bb-radius-md);
74
76
  padding: var(--bb-space-2) var(--bb-space-3);
75
77
  background: var(--bb-color-accent-soft);
78
+ --bb-color-muted: var(--bb-color-muted-on-surface);
76
79
  color: var(--bb-color-ink);
77
80
  font-size: 13px;
78
81
  }
@@ -151,7 +154,7 @@ a.bb-inbox-title:focus-visible {
151
154
  border-radius: 999px;
152
155
  padding: 0 8px;
153
156
  background: var(--bb-color-danger-soft);
154
- color: var(--bb-color-danger);
157
+ color: var(--bb-color-inline-error);
155
158
  font-weight: var(--bb-font-weight-medium);
156
159
  }
157
160
 
package/ui/inbox.js CHANGED
@@ -1,4 +1,4 @@
1
- import { workspaceTabList } from './workspace-kit.js';
1
+ import { workspaceTabStrip } from './workspace-kit.js';
2
2
  /*
3
3
  * 受信箱 (story-inbox-stage1-v1, docs/specs/inbox-stage1.md).
4
4
  *
@@ -647,7 +647,7 @@ export function createInboxUI({
647
647
 
648
648
  function renderTabs(waitingCount) {
649
649
  const bar = el(doc, 'div', { className: 'bb-inbox-tabs', attrs: { role: 'tablist', 'aria-label': '受信箱' } });
650
- workspaceTabList(bar);
650
+ workspaceTabStrip(bar, { memoryKey: 'inbox-tabs' });
651
651
  for (const [id, label] of [['waiting', '対応待ち'], ['notices', 'お知らせ']]) {
652
652
  const selected = state.route.tab === id;
653
653
  const tab = el(doc, 'button', {
@@ -898,7 +898,7 @@ export function createInboxUI({
898
898
  if (!notices || notices.phase === 'not_collected') {
899
899
  view.append(el(doc, 'p', { className: 'bb-inbox-uncollected', text: 'お知らせはまだ集めていません。AIに任せた仕事の終わり・議事録ができたこと・申請の結果は、これから集めます。' }));
900
900
  } else if (notices.phase === 'unavailable') {
901
- view.append(workspaceErrorCard(doc, { title: 'お知らせを読めませんでした', message: `理由: ${reasonText(notices.reason)}。0件ではありません。` }));
901
+ view.append(workspaceErrorCard(doc, { title: 'お知らせを読めませんでした', message: `理由: ${reasonText(notices.reason)}。0件ではありません。`, open: true }));
902
902
  } else if (notices.items.length === 0) {
903
903
  view.append(el(doc, 'p', { className: 'bb-inbox-empty', text: 'お知らせはありません。' }));
904
904
  }
@@ -947,7 +947,7 @@ export function createInboxUI({
947
947
  if (!isToday && state.route.tab === 'notices') {
948
948
  view.append(renderNotices());
949
949
  } else if (state.phase === 'error' && !shown) {
950
- view.append(workspaceErrorCard(doc, { title: '受信箱を読めませんでした', message: `理由: ${reasonText(state.reason)}。0件ではありません。`, onRetry: () => void load() }));
950
+ view.append(workspaceErrorCard(doc, { title: '受信箱を読めませんでした', message: `理由: ${reasonText(state.reason)}。0件ではありません。`, onRetry: () => void load(), open: true }));
951
951
  } else if (shown) {
952
952
  if (isToday) view.append(state.route.view === 'waiting' ? renderTodayWaiting(shown) : renderSet(shown, state.route.view));
953
953
  else view.append(state.route.view === 'waiting' ? renderWaiting(shown) : renderSet(shown, state.route.view));
@@ -738,6 +738,7 @@
738
738
  .bb-jh-owner.is-applied {
739
739
  border-color: var(--bb-color-accent);
740
740
  background: var(--bb-color-accent-soft);
741
+ --bb-color-muted: var(--bb-color-muted-on-surface);
741
742
  }
742
743
 
743
744
  .bb-jh-owner strong {
@@ -767,6 +768,7 @@
767
768
  .bb-jh-owner-badge.is-applied {
768
769
  border-color: var(--bb-color-accent);
769
770
  background: var(--bb-color-accent-soft);
771
+ --bb-color-muted: var(--bb-color-muted-on-surface);
770
772
  color: var(--bb-color-accent-strong);
771
773
  font-weight: var(--bb-font-weight-medium);
772
774
  }