agy-family 0.2.9 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agy-family",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "Zero-privacy-leak transparent usage dashboard, /family slash command, and fair-use budget guardrail for Google One / Antigravity family groups.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -47,7 +47,7 @@ import {
47
47
  writeHostConfig,
48
48
  } from '../src/host.mjs';
49
49
 
50
- const CLI_VERSION = '0.2.9';
50
+ const CLI_VERSION = '0.2.11';
51
51
  const THIS_CLI_PATH = fileURLToPath(import.meta.url);
52
52
  const PACKAGE_ROOT = resolve(dirname(THIS_CLI_PATH), '..', '..', '..');
53
53
 
@@ -716,7 +716,7 @@ export async function runHeadlessSync({ cfg, fullSync = false, home = homedir(),
716
716
  const { payload, scan, nextSyncedHashes, nextAccountLedger } = await buildSyncPayload({
717
717
  deviceId,
718
718
  clientKind: 'cli',
719
- clientVersion: '0.2.9',
719
+ clientVersion: '0.2.11',
720
720
  home,
721
721
  fileCache: cache,
722
722
  syncedHashes: prevHashes,
@@ -107,7 +107,7 @@ export function buildWranglerConfig({
107
107
  workerName = 'agy-family',
108
108
  databaseName = 'agy-family-db',
109
109
  databaseId = '',
110
- boardTitle = 'Antigravity Family Board',
110
+ boardTitle = 'Antigravity 家庭组',
111
111
  defaultDailyCapUsd = 10,
112
112
  defaultWeeklyCapUsd = 50,
113
113
  defaultCycleCapUsd = 150,
@@ -127,7 +127,7 @@ export function buildWranglerConfig({
127
127
  },
128
128
  ],
129
129
  vars: {
130
- BOARD_TITLE: String(boardTitle || 'Antigravity Family Board').trim(),
130
+ BOARD_TITLE: String(boardTitle || 'Antigravity 家庭组').trim(),
131
131
  DEFAULT_DAILY_CAP_USD: String(defaultDailyCapUsd),
132
132
  DEFAULT_WEEKLY_CAP_USD: String(defaultWeeklyCapUsd),
133
133
  DEFAULT_CYCLE_CAP_USD: String(defaultCycleCapUsd),
@@ -291,7 +291,7 @@ export async function deployToCloudflare({
291
291
  const finalDbName = String(
292
292
  databaseName || (existing.workerName === finalWorkerName ? existing.databaseName : '') || `${finalWorkerName}-db`,
293
293
  ).trim();
294
- const finalTitle = String(boardTitle || existing.boardTitle || 'Antigravity Family Board').trim();
294
+ const finalTitle = String(boardTitle || existing.boardTitle || 'Antigravity 家庭组').trim();
295
295
 
296
296
  const explicitAdminKey = String(adminKey || '').trim();
297
297
  const reusedKey = !rotateKey && !explicitAdminKey && existing.adminKey && (!existing.workerName || existing.workerName === finalWorkerName);
@@ -82,7 +82,7 @@ export function diffSyncBuckets(buckets, syncedHashes = null, { fullSync = false
82
82
  export async function buildSyncPayload({
83
83
  deviceId,
84
84
  clientKind = 'cli',
85
- clientVersion = '0.2.9',
85
+ clientVersion = '0.2.11',
86
86
  home,
87
87
  roots = null,
88
88
  sourceFilter = 'all',
@@ -155,7 +155,7 @@ export async function buildSyncPayload({
155
155
  deviceId: String(deviceId || deriveAnonymousDeviceId()).slice(0, 32),
156
156
  client: {
157
157
  kind: clientKind === 'extension' ? 'extension' : 'cli',
158
- version: String(clientVersion || '0.2.9').slice(0, 24),
158
+ version: String(clientVersion || '0.2.11').slice(0, 24),
159
159
  },
160
160
  account: {
161
161
  emailHash: effectiveReportedHash,
@@ -20,10 +20,10 @@ import {
20
20
  roundUsd,
21
21
  syncServerPricingCache,
22
22
  } from './stats.mjs';
23
- import { renderDashboardHtml } from './ui.mjs';
23
+ import { FAVICON_SVG, renderDashboardHtml } from './ui.mjs';
24
24
  import { dispatchWebhook, sendDedupedAlert, validateWebhookUrl } from './webhooks.mjs';
25
25
 
26
- export const SERVER_VERSION = '0.2.9';
26
+ export const SERVER_VERSION = '0.2.11';
27
27
  const MAX_BUCKETS_PER_SYNC = 1000;
28
28
  const MAX_DEVICES_PER_MEMBER = 8;
29
29
  const MAX_TOKENS_PER_BUCKET = 500_000_000;
@@ -325,6 +325,18 @@ export function createApp({
325
325
  return jsonRes({ ok: true, version: SERVER_VERSION, runtime, time: now });
326
326
  }
327
327
 
328
+ // Favicon (SVG icon served at both /favicon.svg and /favicon.ico)
329
+ if (request.method === 'GET' && (path === '/favicon.svg' || path === '/favicon.ico')) {
330
+ return new Response(FAVICON_SVG, {
331
+ status: 200,
332
+ headers: {
333
+ 'Content-Type': 'image/svg+xml; charset=utf-8',
334
+ 'Cache-Control': 'public, max-age=86400',
335
+ 'X-Content-Type-Options': 'nosniff',
336
+ },
337
+ });
338
+ }
339
+
328
340
  // Public Transparent Dashboard UI
329
341
  if (request.method === 'GET' && path === '/') {
330
342
  const settings = await loadSettings(db, envDefaults);
@@ -336,13 +348,18 @@ export function createApp({
336
348
  const settings = await loadSettings(db, envDefaults);
337
349
  const viewErr = await requireViewKeyIfEnabled(request, url, settings, now);
338
350
  if (viewErr) return viewErr;
339
- const period = ['today', '7d', 'cycle', '30d'].includes(url.searchParams.get('period'))
340
- ? url.searchParams.get('period')
341
- : 'today';
351
+ const from = (url.searchParams.get('from') || '').trim();
352
+ const to = (url.searchParams.get('to') || '').trim();
353
+ const rawPeriod = url.searchParams.get('period');
354
+ const period = ['today', 'yesterday', '7d', 'cycle', '30d', 'custom'].includes(rawPeriod)
355
+ ? rawPeriod
356
+ : from
357
+ ? 'custom'
358
+ : 'today';
342
359
  const source = ['desktop', 'cli'].includes(url.searchParams.get('source'))
343
360
  ? url.searchParams.get('source')
344
361
  : 'all';
345
- const board = await buildBoardPayload(db, { period, source, envDefaults, now });
362
+ const board = await buildBoardPayload(db, { period, from, to, source, envDefaults, now });
346
363
  return jsonRes(board);
347
364
  }
348
365
 
@@ -351,19 +368,25 @@ export function createApp({
351
368
  const settings = await loadSettings(db, envDefaults);
352
369
  const viewErr = await requireViewKeyIfEnabled(request, url, settings, now);
353
370
  if (viewErr) return viewErr;
354
- const period = ['today', '7d', 'cycle', '30d'].includes(url.searchParams.get('period'))
355
- ? url.searchParams.get('period')
356
- : 'cycle';
371
+ const from = (url.searchParams.get('from') || '').trim();
372
+ const to = (url.searchParams.get('to') || '').trim();
373
+ const rawPeriod = url.searchParams.get('period');
374
+ const period = ['today', 'yesterday', '7d', 'cycle', '30d', 'custom'].includes(rawPeriod)
375
+ ? rawPeriod
376
+ : from
377
+ ? 'custom'
378
+ : 'cycle';
357
379
  const source = ['desktop', 'cli'].includes(url.searchParams.get('source'))
358
380
  ? url.searchParams.get('source')
359
381
  : 'all';
360
- const board = await buildBoardPayload(db, { period, source, envDefaults, now });
382
+ const board = await buildBoardPayload(db, { period, from, to, source, envDefaults, now });
361
383
  const csv = buildBoardCsv(board);
384
+ const fileTag = period === 'custom' && board.window ? `${board.window.fromDate}_${board.window.toDate}` : period;
362
385
  return new Response(csv, {
363
386
  status: 200,
364
387
  headers: {
365
388
  'Content-Type': 'text/csv; charset=utf-8',
366
- 'Content-Disposition': `attachment; filename="agy-family-${period}.csv"`,
389
+ 'Content-Disposition': `attachment; filename="agy-family-${fileTag}.csv"`,
367
390
  'Cache-Control': 'no-store',
368
391
  'Referrer-Policy': 'no-referrer',
369
392
  'X-Content-Type-Options': 'nosniff',
@@ -378,10 +401,15 @@ export function createApp({
378
401
  const viewErr = await requireViewKeyIfEnabled(request, url, settings, now);
379
402
  if (viewErr) return viewErr;
380
403
  const memberId = decodeURIComponent(boardMemberMatch[1]);
381
- const period = ['today', '7d', 'cycle', '30d'].includes(url.searchParams.get('period'))
382
- ? url.searchParams.get('period')
383
- : 'today';
384
- const detail = await buildMemberDetailPayload(db, memberId, { period, envDefaults, now });
404
+ const from = (url.searchParams.get('from') || '').trim();
405
+ const to = (url.searchParams.get('to') || '').trim();
406
+ const rawPeriod = url.searchParams.get('period');
407
+ const period = ['today', 'yesterday', '7d', 'cycle', '30d', 'custom'].includes(rawPeriod)
408
+ ? rawPeriod
409
+ : from
410
+ ? 'custom'
411
+ : 'today';
412
+ const detail = await buildMemberDetailPayload(db, memberId, { period, from, to, envDefaults, now });
385
413
  if (!detail) return jsonRes({ error: 'Member not found.' }, 404);
386
414
  return jsonRes(detail);
387
415
  }
@@ -88,7 +88,7 @@ export const SCHEMA_STATEMENTS = Object.freeze([
88
88
  ]);
89
89
 
90
90
  export const DEFAULT_SETTINGS = Object.freeze({
91
- boardTitle: 'Antigravity Family Board',
91
+ boardTitle: 'Antigravity 家庭组',
92
92
  defaultDailyCapUsd: 10,
93
93
  defaultWeeklyCapUsd: 50,
94
94
  defaultCycleCapUsd: 150,
@@ -261,7 +261,27 @@ export function computeCycleInfo({ now = Date.now(), timezoneOffsetMin = 480, cy
261
261
  };
262
262
  }
263
263
 
264
- export function getPeriodWindow(period, { now = Date.now(), timezoneOffsetMin = 480, cycleResetDay = 1 } = {}) {
264
+ function parseIsoDateParts(raw) {
265
+ const m = String(raw || '').trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);
266
+ if (!m) return null;
267
+ const y = Number(m[1]);
268
+ const mo = Number(m[2]);
269
+ const d = Number(m[3]);
270
+ if (y < 2020 || y > 2100 || mo < 1 || mo > 12 || d < 1 || d > 31) return null;
271
+ const check = new Date(Date.UTC(y, mo - 1, d));
272
+ if (check.getUTCFullYear() !== y || check.getUTCMonth() !== mo - 1 || check.getUTCDate() !== d) return null;
273
+ return { y, mo, d, key: `${y}-${String(mo).padStart(2, '0')}-${String(d).padStart(2, '0')}` };
274
+ }
275
+
276
+ function formatLocalDateKey(utcMs, offsetMs) {
277
+ const dt = new Date(utcMs + offsetMs);
278
+ return `${dt.getUTCFullYear()}-${String(dt.getUTCMonth() + 1).padStart(2, '0')}-${String(dt.getUTCDate()).padStart(2, '0')}`;
279
+ }
280
+
281
+ export function getPeriodWindow(
282
+ period,
283
+ { now = Date.now(), timezoneOffsetMin = 480, cycleResetDay = 1, from = '', to = '' } = {},
284
+ ) {
265
285
  const offsetMs = (Number(timezoneOffsetMin) || 0) * 60 * 1000;
266
286
  const localNow = new Date(now + offsetMs);
267
287
  const y = localNow.getUTCFullYear();
@@ -271,15 +291,67 @@ export function getPeriodWindow(period, { now = Date.now(), timezoneOffsetMin =
271
291
  const localDayStartUtc = Date.UTC(y, m, d, 0, 0, 0) - offsetMs;
272
292
  const dateKey = `${y}-${String(m + 1).padStart(2, '0')}-${String(d).padStart(2, '0')}`;
273
293
 
294
+ if (period === 'custom' || (from && parseIsoDateParts(from))) {
295
+ const pFrom = parseIsoDateParts(from);
296
+ const pTo = parseIsoDateParts(to) || pFrom;
297
+ if (pFrom && pTo) {
298
+ let startDayUtc = Date.UTC(pFrom.y, pFrom.mo - 1, pFrom.d, 0, 0, 0) - offsetMs;
299
+ let endDayUtc = Date.UTC(pTo.y, pTo.mo - 1, pTo.d, 0, 0, 0) - offsetMs;
300
+ if (startDayUtc > endDayUtc) {
301
+ const tmp = startDayUtc;
302
+ startDayUtc = endDayUtc;
303
+ endDayUtc = tmp;
304
+ }
305
+ // Cap custom window at 366 days
306
+ if (endDayUtc - startDayUtc > 365 * DAY_MS) {
307
+ startDayUtc = endDayUtc - 365 * DAY_MS;
308
+ }
309
+ const endMs = endDayUtc + DAY_MS - 1;
310
+ const fromDate = formatLocalDateKey(startDayUtc, offsetMs);
311
+ const toDate = formatLocalDateKey(endDayUtc, offsetMs);
312
+ const days = Math.max(1, Math.round((endDayUtc - startDayUtc) / DAY_MS) + 1);
313
+ return {
314
+ period: 'custom',
315
+ startMs: startDayUtc,
316
+ endMs,
317
+ fromDate,
318
+ toDate,
319
+ days,
320
+ dateKey,
321
+ windowKey: `custom:${fromDate}..${toDate}`,
322
+ };
323
+ }
324
+ }
325
+
326
+ if (period === 'yesterday') {
327
+ const startMs = localDayStartUtc - DAY_MS;
328
+ const endMs = localDayStartUtc - 1;
329
+ const yKey = formatLocalDateKey(startMs, offsetMs);
330
+ return {
331
+ period: 'yesterday',
332
+ startMs,
333
+ endMs,
334
+ fromDate: yKey,
335
+ toDate: yKey,
336
+ days: 1,
337
+ dateKey,
338
+ windowKey: `yesterday:${yKey}`,
339
+ };
340
+ }
341
+
274
342
  if (period === '7d') {
275
343
  // ISO week key for alert deduplication (Monday-start local week)
276
344
  const dow = (localNow.getUTCDay() + 6) % 7;
277
345
  const weekStartDate = new Date(Date.UTC(y, m, d - dow, 0, 0, 0));
278
346
  const weekKey = `${weekStartDate.getUTCFullYear()}-${String(weekStartDate.getUTCMonth() + 1).padStart(2, '0')}-${String(weekStartDate.getUTCDate()).padStart(2, '0')}`;
347
+ const startMs = localDayStartUtc - 6 * DAY_MS;
279
348
  return {
280
349
  period: '7d',
281
- startMs: localDayStartUtc - 6 * DAY_MS,
350
+ startMs,
282
351
  endMs: now,
352
+ fromDate: formatLocalDateKey(startMs, offsetMs),
353
+ toDate: dateKey,
354
+ days: 7,
283
355
  dateKey,
284
356
  weekKey,
285
357
  windowKey: `7d:${weekKey}`,
@@ -287,10 +359,14 @@ export function getPeriodWindow(period, { now = Date.now(), timezoneOffsetMin =
287
359
  }
288
360
 
289
361
  if (period === '30d') {
362
+ const startMs = localDayStartUtc - 29 * DAY_MS;
290
363
  return {
291
364
  period: '30d',
292
- startMs: localDayStartUtc - 29 * DAY_MS,
365
+ startMs,
293
366
  endMs: now,
367
+ fromDate: formatLocalDateKey(startMs, offsetMs),
368
+ toDate: dateKey,
369
+ days: 30,
294
370
  dateKey,
295
371
  windowKey: `30d:${dateKey}`,
296
372
  };
@@ -309,10 +385,14 @@ export function getPeriodWindow(period, { now = Date.now(), timezoneOffsetMin =
309
385
  }
310
386
  const startMs = Date.UTC(cy, cm, resetDay, 0, 0, 0) - offsetMs;
311
387
  const cycleKey = `${cy}-${String(cm + 1).padStart(2, '0')}-${String(resetDay).padStart(2, '0')}`;
388
+ const days = Math.max(1, Math.floor((localDayStartUtc - startMs) / DAY_MS) + 1);
312
389
  return {
313
390
  period: 'cycle',
314
391
  startMs,
315
392
  endMs: now,
393
+ fromDate: cycleKey,
394
+ toDate: dateKey,
395
+ days,
316
396
  dateKey,
317
397
  windowKey: `cycle:${cycleKey}`,
318
398
  };
@@ -322,6 +402,9 @@ export function getPeriodWindow(period, { now = Date.now(), timezoneOffsetMin =
322
402
  period: 'today',
323
403
  startMs: localDayStartUtc,
324
404
  endMs: now,
405
+ fromDate: dateKey,
406
+ toDate: dateKey,
407
+ days: 1,
325
408
  dateKey,
326
409
  windowKey: `today:${dateKey}`,
327
410
  };
@@ -575,7 +658,10 @@ export async function computeCreditsReconciliation(db, members, settings, cycleI
575
658
  };
576
659
  }
577
660
 
578
- export async function buildBoardPayload(db, { period = 'today', source = 'all', envDefaults = {}, now = Date.now() } = {}) {
661
+ export async function buildBoardPayload(
662
+ db,
663
+ { period = 'today', from = '', to = '', source = 'all', envDefaults = {}, now = Date.now() } = {},
664
+ ) {
579
665
  const settings = await loadSettings(db, envDefaults);
580
666
  const sourceFilter = ['desktop', 'cli'].includes(source) ? source : 'all';
581
667
  const offsetMs = (Number(settings.timezoneOffsetMin) || 0) * 60 * 1000;
@@ -583,6 +669,8 @@ export async function buildBoardPayload(db, { period = 'today', source = 'all',
583
669
  now,
584
670
  timezoneOffsetMin: settings.timezoneOffsetMin,
585
671
  cycleResetDay: settings.cycleResetDay,
672
+ from,
673
+ to,
586
674
  });
587
675
  const cycleInfo = computeCycleInfo({
588
676
  now,
@@ -600,14 +688,20 @@ export async function buildBoardPayload(db, { period = 'today', source = 'all',
600
688
  cycleResetDay: settings.cycleResetDay,
601
689
  }).startMs;
602
690
 
603
- // Daily trend spans 7d for today/7d, 30d for 30d, and cycle start -> today (up to 31d) for cycle.
604
- const trendStartMs =
605
- win.period === '30d'
606
- ? win.startMs
607
- : win.period === 'cycle'
608
- ? Math.max(cycleInfo.cycleStartMs, todayStartMs - 30 * DAY_MS)
609
- : sevenDaysStart;
610
- const trendDaysCount = Math.max(1, Math.min(31, Math.floor((todayStartMs - trendStartMs) / DAY_MS) + 1));
691
+ // Daily trend spans selected custom range (up to 45d), 30d for 30d, cycle start->today for cycle, or 7d.
692
+ let trendStartMs = sevenDaysStart;
693
+ let trendEndDayStartMs = todayStartMs;
694
+ if (win.period === '30d') {
695
+ trendStartMs = win.startMs;
696
+ } else if (win.period === 'cycle') {
697
+ trendStartMs = Math.max(cycleInfo.cycleStartMs, todayStartMs - 30 * DAY_MS);
698
+ } else if (win.period === 'custom') {
699
+ const customEndDay = win.endMs + 1 - DAY_MS;
700
+ trendEndDayStartMs = customEndDay;
701
+ trendStartMs = Math.max(win.startMs, customEndDay - 44 * DAY_MS);
702
+ }
703
+ const trendDaysCount = Math.max(1, Math.min(45, Math.floor((trendEndDayStartMs - trendStartMs) / DAY_MS) + 1));
704
+ const trendEndMs = trendStartMs + trendDaysCount * DAY_MS - 1;
611
705
 
612
706
  const membersRaw = await db.all(
613
707
  'SELECT id, name, role, color, quota_pct, expected_email_hash, last_account_status, daily_cap_usd, weekly_cap_usd, cycle_cap_usd, active, created_at, last_seen_at, last_client_kind, last_client_version FROM members WHERE active = 1 ORDER BY created_at ASC',
@@ -641,12 +735,19 @@ export async function buildBoardPayload(db, { period = 'today', source = 'all',
641
735
  });
642
736
  }
643
737
 
644
- // Build 24h timeline slots
738
+ // Build 24h timeline slots (exact 00:00..23:00 for single-day yesterday/custom, rolling 24h otherwise)
645
739
  const curHour = Math.floor(now / HOUR_MS) * HOUR_MS;
646
740
  const hourlyMap = new Map();
647
- for (let i = 23; i >= 0; i--) {
648
- const h = curHour - i * HOUR_MS;
649
- hourlyMap.set(h, { hourMs: h, usd: 0, tokens: 0, steps: 0 });
741
+ if (win.period === 'yesterday' || (win.period === 'custom' && win.days === 1)) {
742
+ for (let i = 0; i < 24; i++) {
743
+ const h = win.startMs + i * HOUR_MS;
744
+ hourlyMap.set(h, { hourMs: h, usd: 0, tokens: 0, steps: 0 });
745
+ }
746
+ } else {
747
+ for (let i = 23; i >= 0; i--) {
748
+ const h = curHour - i * HOUR_MS;
749
+ hourlyMap.set(h, { hourMs: h, usd: 0, tokens: 0, steps: 0 });
750
+ }
650
751
  }
651
752
 
652
753
  // Build daily trend slots
@@ -696,7 +797,7 @@ export async function buildBoardPayload(db, { period = 'today', source = 'all',
696
797
  slot.steps += steps;
697
798
  }
698
799
 
699
- if (b.bucket_hour_ms >= trendStartMs) {
800
+ if (b.bucket_hour_ms >= trendStartMs && b.bucket_hour_ms <= trendEndMs) {
700
801
  const dayIdx = Math.floor((b.bucket_hour_ms - trendStartMs) / DAY_MS);
701
802
  const dayKey = trendStartMs + dayIdx * DAY_MS;
702
803
  const dSlot = dailyTrendMap.get(dayKey);
@@ -713,7 +814,7 @@ export async function buildBoardPayload(db, { period = 'today', source = 'all',
713
814
  cycleUsedUsd += usd;
714
815
  }
715
816
 
716
- if (b.bucket_hour_ms < win.startMs) continue;
817
+ if (b.bucket_hour_ms < win.startMs || b.bucket_hour_ms > win.endMs) continue;
717
818
 
718
819
  const entry = byMember.get(b.member_id);
719
820
  if (!entry) continue;
@@ -911,6 +1012,14 @@ export async function buildBoardPayload(db, { period = 'today', source = 'all',
911
1012
  period: win.period,
912
1013
  source: sourceFilter,
913
1014
  windowStartMs: win.startMs,
1015
+ windowEndMs: win.endMs,
1016
+ window: {
1017
+ startMs: win.startMs,
1018
+ endMs: win.endMs,
1019
+ fromDate: win.fromDate,
1020
+ toDate: win.toDate,
1021
+ days: win.days,
1022
+ },
914
1023
  generatedAt: now,
915
1024
  rules: {
916
1025
  maxMembers: MAX_FAMILY_MEMBERS,
@@ -1037,7 +1146,11 @@ export async function checkOfflineMembersAndAlert(
1037
1146
  };
1038
1147
  }
1039
1148
 
1040
- export async function buildMemberDetailPayload(db, memberId, { period = 'today', envDefaults = {}, now = Date.now() } = {}) {
1149
+ export async function buildMemberDetailPayload(
1150
+ db,
1151
+ memberId,
1152
+ { period = 'today', from = '', to = '', envDefaults = {}, now = Date.now() } = {},
1153
+ ) {
1041
1154
  const member = await db.get(
1042
1155
  'SELECT id, name, role, color, quota_pct, expected_email_hash, last_account_status, daily_cap_usd, weekly_cap_usd, cycle_cap_usd, active, created_at, last_seen_at, last_client_kind, last_client_version FROM members WHERE id = ? AND active = 1',
1043
1156
  [memberId],
@@ -1057,6 +1170,8 @@ export async function buildMemberDetailPayload(db, memberId, { period = 'today',
1057
1170
  now,
1058
1171
  timezoneOffsetMin: settings.timezoneOffsetMin,
1059
1172
  cycleResetDay: settings.cycleResetDay,
1173
+ from,
1174
+ to,
1060
1175
  });
1061
1176
  const todayWin = getPeriodWindow('today', {
1062
1177
  now,
@@ -1092,7 +1207,7 @@ export async function buildMemberDetailPayload(db, memberId, { period = 'today',
1092
1207
  if (gr.bucket_hour_ms >= todayWin.startMs) groupTodayUsd += u;
1093
1208
  if (gr.bucket_hour_ms >= weeklyWin.startMs) groupWeeklyUsd += u;
1094
1209
  if (gr.bucket_hour_ms >= cycleWin.startMs) groupCycleUsd += u;
1095
- if (gr.bucket_hour_ms >= win.startMs) groupPeriodUsd += u;
1210
+ if (gr.bucket_hour_ms >= win.startMs && gr.bucket_hour_ms <= win.endMs) groupPeriodUsd += u;
1096
1211
  }
1097
1212
  groupTodayUsd = roundUsd(groupTodayUsd);
1098
1213
  groupWeeklyUsd = roundUsd(groupWeeklyUsd);
@@ -1167,7 +1282,7 @@ export async function buildMemberDetailPayload(db, memberId, { period = 'today',
1167
1282
  }
1168
1283
  }
1169
1284
 
1170
- if (b.bucket_hour_ms < win.startMs) continue;
1285
+ if (b.bucket_hour_ms < win.startMs || b.bucket_hour_ms > win.endMs) continue;
1171
1286
  const devId = String(b.device_id || 'unknown');
1172
1287
  const dev = deviceMap.get(devId) || {
1173
1288
  deviceId: devId,
@@ -6,7 +6,16 @@
6
6
  // - Signature AI-timeline pastel palette (#dfa88f, #9fc9a2, #9fbbe0, #c0a8dd, #c08532) scoped to telemetry visualizations
7
7
  // - Engineered to fit 1920x1080 (viewport ~940-1080px) in one single glanceable screen without page scrolling.
8
8
 
9
- export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' } = {}) {
9
+ export const FAVICON_SVG =
10
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none">' +
11
+ '<rect x="0.75" y="0.75" width="30.5" height="30.5" rx="7.5" fill="#26251e" stroke="#454339" stroke-width="1.5"/>' +
12
+ '<path d="M9.2 22.8L16 8.2L22.8 22.8" stroke="#f7f7f4" stroke-width="2.7" stroke-linecap="round" stroke-linejoin="round"/>' +
13
+ '<circle cx="16" cy="20.4" r="2.7" fill="#f54e00"/>' +
14
+ '</svg>';
15
+
16
+ const FAVICON_DATA_URI = 'data:image/svg+xml,' + encodeURIComponent(FAVICON_SVG);
17
+
18
+ export function renderDashboardHtml({ boardTitle = 'Antigravity 家庭组' } = {}) {
10
19
  const safeTitle = String(boardTitle)
11
20
  .replaceAll('&', '&amp;')
12
21
  .replaceAll('<', '&lt;')
@@ -18,7 +27,12 @@ export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' }
18
27
  <head>
19
28
  <meta charset="utf-8" />
20
29
  <meta name="viewport" content="width=device-width, initial-scale=1" />
21
- <title>${safeTitle} — agy-family</title>
30
+ <title>${safeTitle}</title>
31
+ <link rel="icon" type="image/svg+xml" href="${FAVICON_DATA_URI}" />
32
+ <link rel="shortcut icon" type="image/svg+xml" href="/favicon.svg" />
33
+ <link rel="apple-touch-icon" href="/favicon.svg" />
34
+ <meta name="theme-color" content="#f7f7f4" media="(prefers-color-scheme: light)" />
35
+ <meta name="theme-color" content="#171612" media="(prefers-color-scheme: dark)" />
22
36
  <style>
23
37
  :root {
24
38
  --primary: #f54e00;
@@ -128,22 +142,15 @@ export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' }
128
142
  width: 24px;
129
143
  height: 24px;
130
144
  border-radius: 6px;
131
- background: var(--ink);
132
- color: var(--canvas);
133
- display: grid;
134
- place-items: center;
145
+ display: inline-flex;
146
+ align-items: center;
147
+ justify-content: center;
135
148
  flex-shrink: 0;
136
- position: relative;
137
149
  }
138
- .brand-mark::after {
139
- content: "";
140
- position: absolute;
141
- top: 4px;
142
- right: 4px;
143
- width: 5px;
144
- height: 5px;
145
- border-radius: 50%;
146
- background: var(--primary);
150
+ .brand-mark svg {
151
+ width: 24px;
152
+ height: 24px;
153
+ display: block;
147
154
  }
148
155
  .brand-title {
149
156
  font-size: 15px;
@@ -227,7 +234,12 @@ export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' }
227
234
  color: var(--ink);
228
235
  box-shadow: 0 0 0 1px var(--hairline);
229
236
  }
237
+ .seg-group button.is-tab-loading::after,
238
+ .range-trigger.is-tab-loading .range-chev {
239
+ display: none;
240
+ }
230
241
  .seg-group button.is-tab-loading::after {
242
+ display: inline-block;
231
243
  content: "";
232
244
  width: 9px;
233
245
  height: 9px;
@@ -237,6 +249,223 @@ export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' }
237
249
  animation: agf-spin 0.65s linear infinite;
238
250
  flex-shrink: 0;
239
251
  }
252
+ .range-picker {
253
+ position: relative;
254
+ display: inline-flex;
255
+ }
256
+ .range-trigger {
257
+ display: inline-flex;
258
+ align-items: center;
259
+ gap: 6px;
260
+ height: 28px;
261
+ padding: 0 10px;
262
+ border-radius: var(--r-md);
263
+ background: var(--surface-card);
264
+ border: 1px solid var(--hairline-strong);
265
+ color: var(--ink);
266
+ font-size: 12.5px;
267
+ font-weight: 500;
268
+ cursor: pointer;
269
+ white-space: nowrap;
270
+ line-height: 1;
271
+ transition: border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease;
272
+ }
273
+ .range-trigger:hover {
274
+ background: var(--canvas-soft);
275
+ border-color: var(--muted);
276
+ }
277
+ .range-picker.open .range-trigger {
278
+ border-color: var(--primary);
279
+ box-shadow: 0 0 0 2px rgba(245, 78, 0, 0.12);
280
+ }
281
+ .range-ico { color: var(--muted); flex-shrink: 0; }
282
+ .range-picker.open .range-ico { color: var(--primary); }
283
+ .range-dates {
284
+ font-size: 11.5px;
285
+ color: var(--muted);
286
+ font-weight: 400;
287
+ }
288
+ .range-dates:empty { display: none; }
289
+ .range-dates::before { content: "· "; opacity: 0.7; }
290
+ .range-chev {
291
+ color: var(--muted);
292
+ flex-shrink: 0;
293
+ transition: transform 0.16s ease;
294
+ }
295
+ .range-picker.open .range-chev { transform: rotate(180deg); color: var(--ink); }
296
+ .range-trigger.is-tab-loading::after {
297
+ content: "";
298
+ width: 10px;
299
+ height: 10px;
300
+ border-radius: 50%;
301
+ border: 1.5px solid var(--hairline-strong);
302
+ border-top-color: var(--primary);
303
+ animation: agf-spin 0.65s linear infinite;
304
+ flex-shrink: 0;
305
+ }
306
+ .range-popover {
307
+ display: none;
308
+ position: absolute;
309
+ top: calc(100% + 6px);
310
+ left: 0;
311
+ z-index: 180;
312
+ background: var(--surface-card);
313
+ border: 1px solid var(--hairline-strong);
314
+ border-radius: var(--r-lg);
315
+ box-shadow: 0 12px 32px rgba(0, 0, 0, 0.11), 0 2px 6px rgba(0, 0, 0, 0.05);
316
+ width: 416px;
317
+ max-width: calc(100vw - 24px);
318
+ overflow: hidden;
319
+ }
320
+ [data-theme="dark"] .range-popover {
321
+ box-shadow: 0 16px 38px rgba(0, 0, 0, 0.45);
322
+ }
323
+ .range-picker.open .range-popover {
324
+ display: flex;
325
+ animation: agf-pane-in 0.15s cubic-bezier(0.22, 1, 0.36, 1);
326
+ }
327
+ .range-presets {
328
+ width: 124px;
329
+ flex-shrink: 0;
330
+ padding: 10px 8px;
331
+ background: var(--canvas-soft);
332
+ border-right: 1px solid var(--hairline);
333
+ display: flex;
334
+ flex-direction: column;
335
+ gap: 2px;
336
+ }
337
+ .range-presets-title {
338
+ font-size: 10.5px;
339
+ font-weight: 600;
340
+ color: var(--muted);
341
+ padding: 2px 8px 6px;
342
+ letter-spacing: 0.02em;
343
+ }
344
+ .range-presets button {
345
+ display: flex;
346
+ align-items: center;
347
+ justify-content: space-between;
348
+ width: 100%;
349
+ border: none;
350
+ background: transparent;
351
+ color: var(--body);
352
+ font-size: 12.5px;
353
+ font-weight: 500;
354
+ padding: 6px 8px;
355
+ border-radius: 6px;
356
+ cursor: pointer;
357
+ text-align: left;
358
+ transition: background-color 0.13s ease, color 0.13s ease;
359
+ }
360
+ .range-presets button:hover {
361
+ background: var(--hover);
362
+ color: var(--ink);
363
+ }
364
+ .range-presets button.active {
365
+ background: var(--surface-card);
366
+ color: var(--primary);
367
+ box-shadow: 0 0 0 1px var(--hairline);
368
+ }
369
+ .range-cal {
370
+ flex: 1;
371
+ padding: 11px 12px 10px;
372
+ display: flex;
373
+ flex-direction: column;
374
+ gap: 8px;
375
+ min-width: 0;
376
+ }
377
+ .cal-head {
378
+ display: flex;
379
+ align-items: center;
380
+ justify-content: space-between;
381
+ gap: 6px;
382
+ }
383
+ .cal-month-title {
384
+ font-size: 12.5px;
385
+ font-weight: 600;
386
+ color: var(--ink);
387
+ }
388
+ .cal-nav-btn {
389
+ width: 24px;
390
+ height: 24px;
391
+ display: inline-flex;
392
+ align-items: center;
393
+ justify-content: center;
394
+ border: 1px solid var(--hairline);
395
+ background: var(--surface-card);
396
+ color: var(--body);
397
+ border-radius: 6px;
398
+ cursor: pointer;
399
+ font-size: 13px;
400
+ line-height: 1;
401
+ }
402
+ .cal-nav-btn:hover { background: var(--hover); color: var(--ink); }
403
+ .cal-nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
404
+ .cal-weekdays, .cal-days {
405
+ display: grid;
406
+ grid-template-columns: repeat(7, 1fr);
407
+ gap: 2px;
408
+ }
409
+ .cal-weekdays span {
410
+ text-align: center;
411
+ font-size: 10.5px;
412
+ color: var(--muted);
413
+ padding: 2px 0;
414
+ }
415
+ .cal-day {
416
+ height: 28px;
417
+ border: none;
418
+ background: transparent;
419
+ color: var(--ink);
420
+ font-size: 12px;
421
+ font-family: var(--font-mono);
422
+ border-radius: 6px;
423
+ cursor: pointer;
424
+ position: relative;
425
+ transition: background-color 0.1s ease, color 0.1s ease;
426
+ }
427
+ .cal-day:hover:not(:disabled):not(.edge) {
428
+ background: var(--hover);
429
+ }
430
+ .cal-day.other-month { color: var(--muted); opacity: 0.45; }
431
+ .cal-day:disabled { opacity: 0.28; cursor: not-allowed; }
432
+ .cal-day.is-today:not(.edge)::after {
433
+ content: "";
434
+ position: absolute;
435
+ bottom: 3px;
436
+ left: 50%;
437
+ transform: translateX(-50%);
438
+ width: 4px;
439
+ height: 4px;
440
+ border-radius: 50%;
441
+ background: var(--primary);
442
+ }
443
+ .cal-day.in-range {
444
+ background: rgba(245, 78, 0, 0.12);
445
+ color: var(--ink);
446
+ border-radius: 3px;
447
+ }
448
+ .cal-day.edge {
449
+ background: var(--primary);
450
+ color: #fff;
451
+ font-weight: 600;
452
+ border-radius: 6px;
453
+ }
454
+ .cal-foot {
455
+ display: flex;
456
+ align-items: center;
457
+ justify-content: space-between;
458
+ gap: 8px;
459
+ padding-top: 8px;
460
+ border-top: 1px solid var(--hairline);
461
+ }
462
+ .cal-summary {
463
+ font-size: 11px;
464
+ color: var(--muted);
465
+ overflow: hidden;
466
+ text-overflow: ellipsis;
467
+ white-space: nowrap;
468
+ }
240
469
 
241
470
  .header-actions {
242
471
  display: flex;
@@ -1232,6 +1461,7 @@ export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' }
1232
1461
  @media (prefers-reduced-motion: reduce) {
1233
1462
  .top-progress-bar, .panel-load-line::after, .skel, .inline-spin,
1234
1463
  .btn.btn-loading::before, .seg-group button.is-tab-loading::after,
1464
+ .range-trigger.is-tab-loading::after, .range-picker.open .range-popover,
1235
1465
  .icon-refresh.spinning svg, .tab-pane.active, .agf-reveal, .svg-chart.chart-pop {
1236
1466
  animation: none !important;
1237
1467
  }
@@ -1252,6 +1482,10 @@ export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' }
1252
1482
  .kpi-grid { grid-template-columns: 1fr; }
1253
1483
  .row-2, .row-3 { grid-template-columns: 1fr; }
1254
1484
  .detail-grid { grid-template-columns: 1fr; }
1485
+ .range-picker.open .range-popover { flex-direction: column; width: min(320px, calc(100vw - 24px)); }
1486
+ .range-presets { width: 100%; border-right: none; border-bottom: 1px solid var(--hairline); flex-direction: row; flex-wrap: wrap; }
1487
+ .range-presets-title { width: 100%; }
1488
+ .range-presets button { width: auto; }
1255
1489
  }
1256
1490
  </style>
1257
1491
  </head>
@@ -1259,11 +1493,7 @@ export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' }
1259
1493
  <div class="top-progress" id="topProgress" aria-hidden="true"><div class="top-progress-bar"></div></div>
1260
1494
  <header class="topbar">
1261
1495
  <div class="brand-cluster">
1262
- <div class="brand-mark" aria-hidden="true">
1263
- <svg width="13" height="13" viewBox="0 0 16 16" fill="none">
1264
- <path d="M3 11.5L8 3L13 11.5H3Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/>
1265
- </svg>
1266
- </div>
1496
+ <div class="brand-mark" aria-hidden="true">${FAVICON_SVG}</div>
1267
1497
  <h1 class="brand-title" id="boardTitle">${safeTitle}</h1>
1268
1498
  <span class="sync-pill">
1269
1499
  <span class="sync-dot"></span>
@@ -1277,11 +1507,41 @@ export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' }
1277
1507
  </div>
1278
1508
 
1279
1509
  <div class="header-controls">
1280
- <div class="seg-group" id="periodTabs">
1281
- <button data-p="today" class="active" data-i18n="today">今日</button>
1282
- <button data-p="7d" data-i18n="week">近 7 天</button>
1283
- <button data-p="cycle" data-i18n="cycle">本周期</button>
1284
- <button data-p="30d" data-i18n="days30">30 天</button>
1510
+ <div class="range-picker" id="rangePicker">
1511
+ <button type="button" class="range-trigger" id="rangeTrigger" aria-haspopup="dialog" aria-expanded="false">
1512
+ <svg class="range-ico" width="13" height="13" viewBox="0 0 16 16" fill="none" aria-hidden="true">
1513
+ <rect x="2" y="3.2" width="12" height="10.8" rx="2" stroke="currentColor" stroke-width="1.4"/>
1514
+ <path d="M2 6.5H14M5.3 1.8V4.2M10.7 1.8V4.2" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/>
1515
+ </svg>
1516
+ <span class="range-label" id="rangeLabel">今日</span>
1517
+ <span class="range-dates mono" id="rangeDates"></span>
1518
+ <svg class="range-chev" width="11" height="11" viewBox="0 0 16 16" fill="none" aria-hidden="true">
1519
+ <path d="M4.5 6.5L8 10L11.5 6.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
1520
+ </svg>
1521
+ </button>
1522
+ <div class="range-popover" id="rangePopover" role="dialog" aria-label="Date range">
1523
+ <div class="range-presets" id="periodPresets">
1524
+ <div class="range-presets-title" id="rangePresetsTitle">快捷范围</div>
1525
+ <button type="button" data-p="today" class="active" data-i18n="today">今日</button>
1526
+ <button type="button" data-p="yesterday" id="presetYesterdayBtn">昨日</button>
1527
+ <button type="button" data-p="7d" data-i18n="week">近 7 天</button>
1528
+ <button type="button" data-p="cycle" data-i18n="cycle">本周期</button>
1529
+ <button type="button" data-p="30d" data-i18n="days30">30 天</button>
1530
+ </div>
1531
+ <div class="range-cal">
1532
+ <div class="cal-head">
1533
+ <button type="button" class="cal-nav-btn" id="calPrevBtn" aria-label="Previous month">‹</button>
1534
+ <span class="cal-month-title mono" id="calMonthTitle"></span>
1535
+ <button type="button" class="cal-nav-btn" id="calNextBtn" aria-label="Next month">›</button>
1536
+ </div>
1537
+ <div class="cal-weekdays" id="calWeekdays"></div>
1538
+ <div class="cal-days" id="calDays"></div>
1539
+ <div class="cal-foot">
1540
+ <span class="cal-summary mono" id="calSummary"></span>
1541
+ <button type="button" class="btn btn-primary btn-sm" id="calApplyBtn">应用</button>
1542
+ </div>
1543
+ </div>
1544
+ </div>
1285
1545
  </div>
1286
1546
  <div class="seg-group" id="sourceFilter">
1287
1547
  <button data-src="all" class="active" data-i18n="srcAll">全部</button>
@@ -1416,7 +1676,7 @@ export function renderDashboardHtml({ boardTitle = 'Antigravity Family Board' }
1416
1676
 
1417
1677
  <footer class="foot">
1418
1678
  <span data-i18n="privacyNote">隐私承诺:客户端仅只读扫描本地 SQLite 数值元数据,绝不上传 Prompt、代码、文件路径或 Google 凭据。</span>
1419
- <span class="mono">agy-family v0.2.9 · MIT</span>
1679
+ <span class="mono">agy-family v0.2.11 · MIT</span>
1420
1680
  </footer>
1421
1681
  </main>
1422
1682
 
@@ -1730,6 +1990,14 @@ const I18N = {
1730
1990
  let lang = localStorage.getItem('agf_lang') || (navigator.language?.startsWith('zh') ? 'zh' : 'en');
1731
1991
  let theme = localStorage.getItem('agf_theme') || 'light';
1732
1992
  let period = 'today';
1993
+ let customFrom = '';
1994
+ let customTo = '';
1995
+ let boardTzOffsetMin = 480;
1996
+ let calYear = new Date().getFullYear();
1997
+ let calMonth = new Date().getMonth();
1998
+ let draftFrom = '';
1999
+ let draftTo = '';
2000
+ let hoverDay = '';
1733
2001
  let sourceFilter = 'all';
1734
2002
  let sortKey = 'usd';
1735
2003
  let sortDir = 'desc';
@@ -1858,6 +2126,13 @@ function applyI18n() {
1858
2126
  const k = el.getAttribute('data-i18n');
1859
2127
  if (I18N[lang][k]) el.textContent = I18N[lang][k];
1860
2128
  });
2129
+ const pt = document.getElementById('rangePresetsTitle');
2130
+ if (pt) pt.textContent = lang === 'zh' ? '快捷范围' : 'Presets';
2131
+ const yb = document.getElementById('presetYesterdayBtn');
2132
+ if (yb) yb.textContent = lang === 'zh' ? '昨日' : 'Yesterday';
2133
+ const ab = document.getElementById('calApplyBtn');
2134
+ if (ab) ab.textContent = lang === 'zh' ? '应用' : 'Apply';
2135
+ updateRangeTriggerLabel(lastBoardData?.window || null);
1861
2136
  updateAdminHeaderTitle();
1862
2137
  renderGuideBody();
1863
2138
  }
@@ -1908,8 +2183,20 @@ function setTopProgress(loading) {
1908
2183
  }
1909
2184
  }
1910
2185
 
2186
+ function buildBoardQueryParams(includeSource) {
2187
+ const qs = new URLSearchParams({ period });
2188
+ if (period === 'custom' && customFrom) {
2189
+ qs.set('from', customFrom);
2190
+ qs.set('to', customTo || customFrom);
2191
+ }
2192
+ if (includeSource && sourceFilter !== 'all') qs.set('source', sourceFilter);
2193
+ return qs;
2194
+ }
2195
+
1911
2196
  function clearTabLoadingSpinners() {
1912
- document.querySelectorAll('.seg-group button.is-tab-loading').forEach((b) => b.classList.remove('is-tab-loading'));
2197
+ document.querySelectorAll('.seg-group button.is-tab-loading, .range-trigger.is-tab-loading').forEach((b) => {
2198
+ b.classList.remove('is-tab-loading');
2199
+ });
1913
2200
  }
1914
2201
 
1915
2202
  async function withBtnLoading(btn, fn) {
@@ -1998,8 +2285,7 @@ async function fetchBoard(opts) {
1998
2285
  }
1999
2286
  }
2000
2287
 
2001
- const qs = new URLSearchParams({ period });
2002
- if (sourceFilter !== 'all') qs.set('source', sourceFilter);
2288
+ const qs = buildBoardQueryParams(true);
2003
2289
  try {
2004
2290
  const res = await fetch('/api/board?' + qs.toString(), { headers: viewHeaders() });
2005
2291
  if (seq !== boardReqSeq) return;
@@ -2058,7 +2344,20 @@ function renderActivityChart(d) {
2058
2344
  if (head) {
2059
2345
  if (isDaily) {
2060
2346
  const nDays = (d.dailyTrend || []).length || 7;
2061
- head.textContent = lang === 'zh' ? '近 ' + nDays + ' 天每日占比走势' : 'Daily usage share (' + nDays + 'd)';
2347
+ if (d.period === 'custom' && d.window?.fromDate) {
2348
+ const sLbl = fmtShortDate(d.window.fromDate);
2349
+ const eLbl = fmtShortDate(d.window.toDate || d.window.fromDate);
2350
+ head.textContent = lang === 'zh'
2351
+ ? (sLbl === eLbl ? sLbl : sLbl + '–' + eLbl) + ' 每日占比走势'
2352
+ : 'Daily share (' + (sLbl === eLbl ? sLbl : sLbl + '–' + eLbl) + ')';
2353
+ } else {
2354
+ head.textContent = lang === 'zh' ? '近 ' + nDays + ' 天每日占比走势' : 'Daily usage share (' + nDays + 'd)';
2355
+ }
2356
+ } else if (d.period === 'yesterday') {
2357
+ head.textContent = lang === 'zh' ? '昨日 24 小时用量占比节律' : 'Yesterday 24h usage rhythm';
2358
+ } else if (d.period === 'custom' && d.window?.days === 1 && d.window?.fromDate) {
2359
+ const sLbl = fmtShortDate(d.window.fromDate);
2360
+ head.textContent = lang === 'zh' ? sLbl + ' 24 小时用量占比节律' : sLbl + ' 24h usage rhythm';
2062
2361
  } else {
2063
2362
  head.textContent = t('hourlyTitle');
2064
2363
  }
@@ -2149,7 +2448,7 @@ async function loadMemberDetail(memberId) {
2149
2448
  '<div class="detail-col"><div class="skel" style="width:88px;height:11px;margin-bottom:8px"></div><div class="skel" style="width:100%;height:12px;margin-bottom:6px"></div><div class="skel" style="width:74%;height:12px"></div></div>' +
2150
2449
  '</div>' +
2151
2450
  '</div>';
2152
- const qs = new URLSearchParams({ period });
2451
+ const qs = buildBoardQueryParams(false);
2153
2452
  try {
2154
2453
  const res = await fetch('/api/board/member/' + encodeURIComponent(memberId) + '?' + qs.toString(), { headers: viewHeaders() });
2155
2454
  if (seq !== detailReqSeq) return;
@@ -2407,9 +2706,9 @@ function renderMemberRows(d) {
2407
2706
  }
2408
2707
 
2409
2708
  function renderBoard(d) {
2410
- const title = d.boardTitle || 'Antigravity Family Board';
2709
+ const title = d.boardTitle || 'Antigravity 家庭组';
2411
2710
  document.getElementById('boardTitle').textContent = title;
2412
- document.title = title + ' — agy-family';
2711
+ document.title = title;
2413
2712
  document.getElementById('updatedLine').textContent = new Date(d.generatedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
2414
2713
 
2415
2714
  const s = d.summary || {};
@@ -2419,19 +2718,33 @@ function renderBoard(d) {
2419
2718
  const isPoolMode = s.quotaMode === 'pool';
2420
2719
  const maxSeats = d.rules.maxMembers || 6;
2421
2720
 
2721
+ if (d.rules && Number.isFinite(Number(d.rules.timezoneOffsetMin))) {
2722
+ boardTzOffsetMin = Number(d.rules.timezoneOffsetMin);
2723
+ }
2724
+ updateRangeTriggerLabel(d.window || null);
2725
+
2422
2726
  // KPI 1: Hero Usage / Pool %
2727
+ const winFromShort = d.window?.fromDate ? fmtShortDate(d.window.fromDate) : '';
2728
+ const winToShort = d.window?.toDate ? fmtShortDate(d.window.toDate) : winFromShort;
2729
+ const customRangeTitle = winFromShort
2730
+ ? (winFromShort === winToShort ? winFromShort : winFromShort + ' – ' + winToShort)
2731
+ : (lang === 'zh' ? '自定义范围' : 'Custom range');
2423
2732
  const periodNames = isPoolMode
2424
2733
  ? {
2425
2734
  today: lang === 'zh' ? '今日共享总池已用' : 'Today pool used',
2735
+ yesterday: lang === 'zh' ? '昨日共享总池已用' : 'Yesterday pool used',
2426
2736
  '7d': lang === 'zh' ? '近 7 天共享总池已用' : '7d pool used',
2427
2737
  cycle: lang === 'zh' ? '本周期共享总池已用' : 'Cycle pool used',
2428
2738
  '30d': lang === 'zh' ? '近 30 天共享总池已用' : '30d pool used',
2739
+ custom: lang === 'zh' ? customRangeTitle + ' 共享总池已用' : customRangeTitle + ' pool used',
2429
2740
  }
2430
2741
  : {
2431
2742
  today: lang === 'zh' ? '今日家庭组总用量' : 'Today family usage',
2743
+ yesterday: lang === 'zh' ? '昨日家庭组总用量' : 'Yesterday family usage',
2432
2744
  '7d': lang === 'zh' ? '近 7 天家庭组总用量' : '7-day family usage',
2433
2745
  cycle: lang === 'zh' ? '本周期家庭组总用量' : 'Cycle family usage',
2434
2746
  '30d': lang === 'zh' ? '近 30 天家庭组总用量' : '30-day family usage',
2747
+ custom: lang === 'zh' ? customRangeTitle + ' 家庭组总用量' : customRangeTitle + ' usage',
2435
2748
  };
2436
2749
  document.getElementById('heroEyebrow').textContent = periodNames[d.period] || t('heroSpend');
2437
2750
  document.getElementById('heroPacingReset').textContent = cyc.nextResetLabel
@@ -3067,19 +3380,273 @@ document.getElementById('checkOfflineBtn').addEventListener('click', async () =>
3067
3380
 
3068
3381
  document.getElementById('refreshBtn')?.addEventListener('click', () => fetchBoard());
3069
3382
 
3070
- document.querySelectorAll('#periodTabs button').forEach((btn) => {
3383
+ function fmtShortDate(isoKey) {
3384
+ const parts = String(isoKey || '').split('-');
3385
+ if (parts.length !== 3) return String(isoKey || '');
3386
+ return parts[1] + '/' + parts[2];
3387
+ }
3388
+
3389
+ function getTodayBoardKey() {
3390
+ const d = new Date(Date.now() + (Number(boardTzOffsetMin) || 0) * 60000);
3391
+ return d.getUTCFullYear() + '-' + String(d.getUTCMonth() + 1).padStart(2, '0') + '-' + String(d.getUTCDate()).padStart(2, '0');
3392
+ }
3393
+
3394
+ function isoDateDiffDays(aKey, bKey) {
3395
+ const pa = String(aKey || '').split('-').map(Number);
3396
+ const pb = String(bKey || '').split('-').map(Number);
3397
+ if (pa.length !== 3 || pb.length !== 3) return 1;
3398
+ const ta = Date.UTC(pa[0], pa[1] - 1, pa[2]);
3399
+ const tb = Date.UTC(pb[0], pb[1] - 1, pb[2]);
3400
+ return Math.round(Math.abs(tb - ta) / 86400000) + 1;
3401
+ }
3402
+
3403
+ function updateRangeTriggerLabel(winObj) {
3404
+ const lblEl = document.getElementById('rangeLabel');
3405
+ const datesEl = document.getElementById('rangeDates');
3406
+ if (!lblEl || !datesEl) return;
3407
+
3408
+ const wFrom = winObj?.fromDate || (period === 'custom' ? customFrom : '');
3409
+ const wTo = winObj?.toDate || (period === 'custom' ? (customTo || customFrom) : '');
3410
+ const presetLabels = {
3411
+ today: t('today'),
3412
+ yesterday: lang === 'zh' ? '昨日' : 'Yesterday',
3413
+ '7d': t('week'),
3414
+ cycle: t('cycle'),
3415
+ '30d': t('days30'),
3416
+ };
3417
+
3418
+ if (period === 'custom' && wFrom) {
3419
+ const s = fmtShortDate(wFrom);
3420
+ const e = fmtShortDate(wTo || wFrom);
3421
+ const days = winObj?.days || isoDateDiffDays(wFrom, wTo || wFrom);
3422
+ lblEl.textContent = s === e ? s : s + ' – ' + e;
3423
+ datesEl.textContent = days === 1
3424
+ ? (lang === 'zh' ? '单日' : '1d')
3425
+ : (lang === 'zh' ? days + ' 天' : days + 'd');
3426
+ } else {
3427
+ lblEl.textContent = presetLabels[period] || t('today');
3428
+ if (wFrom) {
3429
+ const s = fmtShortDate(wFrom);
3430
+ const e = fmtShortDate(wTo || wFrom);
3431
+ datesEl.textContent = s === e ? s : s + '–' + e;
3432
+ } else {
3433
+ datesEl.textContent = '';
3434
+ }
3435
+ }
3436
+
3437
+ document.querySelectorAll('#periodPresets button').forEach((b) => {
3438
+ b.classList.toggle('active', b.getAttribute('data-p') === period);
3439
+ });
3440
+ }
3441
+
3442
+ function renderRangeCalendar() {
3443
+ const titleEl = document.getElementById('calMonthTitle');
3444
+ const wkEl = document.getElementById('calWeekdays');
3445
+ const daysEl = document.getElementById('calDays');
3446
+ const sumEl = document.getElementById('calSummary');
3447
+ const applyBtn = document.getElementById('calApplyBtn');
3448
+ const nextBtn = document.getElementById('calNextBtn');
3449
+ if (!titleEl || !wkEl || !daysEl) return;
3450
+
3451
+ const todayKey = getTodayBoardKey();
3452
+ const todayParts = todayKey.split('-').map(Number);
3453
+ const enMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
3454
+ titleEl.textContent = lang === 'zh'
3455
+ ? calYear + '年 ' + String(calMonth + 1).padStart(2, '0') + '月'
3456
+ : enMonths[calMonth] + ' ' + calYear;
3457
+
3458
+ if (nextBtn) {
3459
+ nextBtn.disabled = calYear > todayParts[0] || (calYear === todayParts[0] && calMonth >= todayParts[1] - 1);
3460
+ }
3461
+
3462
+ const wds = lang === 'zh' ? ['一', '二', '三', '四', '五', '六', '日'] : ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
3463
+ wkEl.innerHTML = wds.map((w) => '<span>' + w + '</span>').join('');
3464
+
3465
+ const firstDow = (new Date(Date.UTC(calYear, calMonth, 1)).getUTCDay() + 6) % 7;
3466
+ const daysInMonth = new Date(Date.UTC(calYear, calMonth + 1, 0)).getUTCDate();
3467
+ const prevMonthDays = new Date(Date.UTC(calYear, calMonth, 0)).getUTCDate();
3468
+
3469
+ let rangeA = draftFrom;
3470
+ let rangeB = draftTo || (draftFrom && hoverDay ? hoverDay : '');
3471
+ if (rangeA && rangeB && rangeA > rangeB) {
3472
+ const tmp = rangeA;
3473
+ rangeA = rangeB;
3474
+ rangeB = tmp;
3475
+ }
3476
+
3477
+ const cells = [];
3478
+ for (let i = 0; i < 42; i++) {
3479
+ let y = calYear;
3480
+ let m = calMonth;
3481
+ let d = 1;
3482
+ let isOther = false;
3483
+ if (i < firstDow) {
3484
+ isOther = true;
3485
+ m -= 1;
3486
+ if (m < 0) { m = 11; y -= 1; }
3487
+ d = prevMonthDays - firstDow + i + 1;
3488
+ } else if (i >= firstDow + daysInMonth) {
3489
+ isOther = true;
3490
+ m += 1;
3491
+ if (m > 11) { m = 0; y += 1; }
3492
+ d = i - firstDow - daysInMonth + 1;
3493
+ } else {
3494
+ d = i - firstDow + 1;
3495
+ }
3496
+ const key = y + '-' + String(m + 1).padStart(2, '0') + '-' + String(d).padStart(2, '0');
3497
+ const isFuture = key > todayKey;
3498
+ const isEdge = Boolean((rangeA && key === rangeA) || (rangeB && key === rangeB));
3499
+ const inRange = Boolean(rangeA && rangeB && key > rangeA && key < rangeB);
3500
+ const cls = ['cal-day'];
3501
+ if (isOther) cls.push('other-month');
3502
+ if (key === todayKey) cls.push('is-today');
3503
+ if (isEdge) cls.push('edge');
3504
+ else if (inRange) cls.push('in-range');
3505
+ cells.push(
3506
+ '<button type="button" class="' + cls.join(' ') + '" data-day="' + key + '"' + (isFuture ? ' disabled' : '') + '>' + d + '</button>',
3507
+ );
3508
+ }
3509
+ daysEl.innerHTML = cells.join('');
3510
+
3511
+ if (sumEl) {
3512
+ if (draftFrom && draftTo) {
3513
+ const a = draftFrom <= draftTo ? draftFrom : draftTo;
3514
+ const b = draftFrom <= draftTo ? draftTo : draftFrom;
3515
+ const cnt = isoDateDiffDays(a, b);
3516
+ sumEl.textContent = a === b
3517
+ ? fmtShortDate(a) + (lang === 'zh' ? ' (单日)' : ' (1d)')
3518
+ : fmtShortDate(a) + ' → ' + fmtShortDate(b) + ' · ' + cnt + (lang === 'zh' ? ' 天' : 'd');
3519
+ } else if (draftFrom) {
3520
+ sumEl.textContent = lang === 'zh'
3521
+ ? '起点 ' + fmtShortDate(draftFrom) + ',再点选结束日'
3522
+ : 'Start ' + fmtShortDate(draftFrom) + ', pick end date';
3523
+ } else {
3524
+ sumEl.textContent = lang === 'zh' ? '点击日期选择起止范围' : 'Click start & end dates';
3525
+ }
3526
+ }
3527
+ if (applyBtn) {
3528
+ applyBtn.disabled = !draftFrom;
3529
+ }
3530
+ }
3531
+
3532
+ function openRangePopover() {
3533
+ const picker = document.getElementById('rangePicker');
3534
+ const trigger = document.getElementById('rangeTrigger');
3535
+ if (!picker || !trigger) return;
3536
+ const win = lastBoardData?.window;
3537
+ const todayKey = getTodayBoardKey();
3538
+ draftFrom = period === 'custom' && customFrom ? customFrom : (win?.fromDate || todayKey);
3539
+ draftTo = period === 'custom' && (customTo || customFrom) ? (customTo || customFrom) : (win?.toDate || todayKey);
3540
+ hoverDay = '';
3541
+ const anchorParts = (draftTo || todayKey).split('-').map(Number);
3542
+ if (anchorParts.length === 3) {
3543
+ calYear = anchorParts[0];
3544
+ calMonth = anchorParts[1] - 1;
3545
+ }
3546
+ renderRangeCalendar();
3547
+ picker.classList.add('open');
3548
+ trigger.setAttribute('aria-expanded', 'true');
3549
+ }
3550
+
3551
+ function closeRangePopover() {
3552
+ const picker = document.getElementById('rangePicker');
3553
+ const trigger = document.getElementById('rangeTrigger');
3554
+ if (picker) picker.classList.remove('open');
3555
+ if (trigger) trigger.setAttribute('aria-expanded', 'false');
3556
+ }
3557
+
3558
+ document.getElementById('rangeTrigger')?.addEventListener('click', (e) => {
3559
+ e.stopPropagation();
3560
+ const picker = document.getElementById('rangePicker');
3561
+ if (picker?.classList.contains('open')) closeRangePopover();
3562
+ else openRangePopover();
3563
+ });
3564
+
3565
+ document.getElementById('rangePopover')?.addEventListener('click', (e) => {
3566
+ e.stopPropagation();
3567
+ });
3568
+
3569
+ document.addEventListener('click', () => {
3570
+ closeRangePopover();
3571
+ });
3572
+ document.addEventListener('keydown', (e) => {
3573
+ if (e.key === 'Escape') closeRangePopover();
3574
+ });
3575
+
3576
+ document.querySelectorAll('#periodPresets button').forEach((btn) => {
3071
3577
  btn.addEventListener('click', () => {
3072
- const nextPeriod = btn.dataset.p;
3073
- document.querySelectorAll('#periodTabs button').forEach((b) => b.classList.remove('active'));
3074
- btn.classList.add('active');
3578
+ const nextPeriod = btn.getAttribute('data-p') || 'today';
3075
3579
  period = nextPeriod;
3580
+ customFrom = '';
3581
+ customTo = '';
3076
3582
  if (!chartModeManual) {
3077
- chartMode = period === 'today' ? 'hourly' : 'daily';
3583
+ chartMode = (period === 'today' || period === 'yesterday') ? 'hourly' : 'daily';
3078
3584
  }
3079
- fetchBoard({ triggerBtn: btn });
3585
+ updateRangeTriggerLabel(null);
3586
+ closeRangePopover();
3587
+ fetchBoard({ triggerBtn: document.getElementById('rangeTrigger') });
3080
3588
  });
3081
3589
  });
3082
3590
 
3591
+ document.getElementById('calPrevBtn')?.addEventListener('click', () => {
3592
+ calMonth -= 1;
3593
+ if (calMonth < 0) { calMonth = 11; calYear -= 1; }
3594
+ renderRangeCalendar();
3595
+ });
3596
+ document.getElementById('calNextBtn')?.addEventListener('click', () => {
3597
+ calMonth += 1;
3598
+ if (calMonth > 11) { calMonth = 0; calYear += 1; }
3599
+ renderRangeCalendar();
3600
+ });
3601
+
3602
+ document.getElementById('calDays')?.addEventListener('click', (e) => {
3603
+ const btn = e.target.closest('button.cal-day');
3604
+ if (!btn || btn.disabled) return;
3605
+ const day = btn.getAttribute('data-day');
3606
+ if (!day) return;
3607
+ if (!draftFrom || (draftFrom && draftTo)) {
3608
+ draftFrom = day;
3609
+ draftTo = '';
3610
+ hoverDay = '';
3611
+ } else {
3612
+ if (day < draftFrom) {
3613
+ draftTo = draftFrom;
3614
+ draftFrom = day;
3615
+ } else {
3616
+ draftTo = day;
3617
+ }
3618
+ hoverDay = '';
3619
+ }
3620
+ renderRangeCalendar();
3621
+ });
3622
+
3623
+ document.getElementById('calDays')?.addEventListener('mouseover', (e) => {
3624
+ if (!draftFrom || draftTo) return;
3625
+ const btn = e.target.closest('button.cal-day');
3626
+ if (!btn || btn.disabled) return;
3627
+ const day = btn.getAttribute('data-day') || '';
3628
+ if (day !== hoverDay) {
3629
+ hoverDay = day;
3630
+ renderRangeCalendar();
3631
+ }
3632
+ });
3633
+
3634
+ document.getElementById('calApplyBtn')?.addEventListener('click', () => {
3635
+ if (!draftFrom) return;
3636
+ const a = draftTo && draftTo < draftFrom ? draftTo : draftFrom;
3637
+ const b = draftTo ? (draftTo < draftFrom ? draftFrom : draftTo) : draftFrom;
3638
+ period = 'custom';
3639
+ customFrom = a;
3640
+ customTo = b;
3641
+ const days = isoDateDiffDays(a, b);
3642
+ if (!chartModeManual) {
3643
+ chartMode = days === 1 ? 'hourly' : 'daily';
3644
+ }
3645
+ updateRangeTriggerLabel({ fromDate: a, toDate: b, days });
3646
+ closeRangePopover();
3647
+ fetchBoard({ triggerBtn: document.getElementById('rangeTrigger') });
3648
+ });
3649
+
3083
3650
  document.querySelectorAll('#sourceFilter button').forEach((btn) => {
3084
3651
  btn.addEventListener('click', () => {
3085
3652
  const nextSrc = btn.getAttribute('data-src') || 'all';
@@ -3119,8 +3686,7 @@ document.getElementById('memberTableHead')?.addEventListener('click', (e) => {
3119
3686
  document.getElementById('exportCsvBtn').addEventListener('click', async () => {
3120
3687
  const btn = document.getElementById('exportCsvBtn');
3121
3688
  await withBtnLoading(btn, async () => {
3122
- const qs = new URLSearchParams({ period });
3123
- if (sourceFilter !== 'all') qs.set('source', sourceFilter);
3689
+ const qs = buildBoardQueryParams(true);
3124
3690
  try {
3125
3691
  const res = await fetch('/api/board/export.csv?' + qs.toString(), { headers: viewHeaders() });
3126
3692
  if (!res.ok) return;
@@ -3128,7 +3694,8 @@ document.getElementById('exportCsvBtn').addEventListener('click', async () => {
3128
3694
  const objUrl = URL.createObjectURL(blob);
3129
3695
  const a = document.createElement('a');
3130
3696
  a.href = objUrl;
3131
- a.download = 'agy-family-' + period + (sourceFilter !== 'all' ? '-' + sourceFilter : '') + '.csv';
3697
+ const tag = period === 'custom' && customFrom ? (customFrom + '_' + (customTo || customFrom)) : period;
3698
+ a.download = 'agy-family-' + tag + (sourceFilter !== 'all' ? '-' + sourceFilter : '') + '.csv';
3132
3699
  document.body.appendChild(a);
3133
3700
  a.click();
3134
3701
  document.body.removeChild(a);
package/wrangler.jsonc CHANGED
@@ -20,7 +20,7 @@
20
20
  }
21
21
  ],
22
22
  "vars": {
23
- "BOARD_TITLE": "Antigravity Family Board",
23
+ "BOARD_TITLE": "Antigravity 家庭组",
24
24
  "DEFAULT_DAILY_CAP_USD": "10",
25
25
  "DEFAULT_WEEKLY_CAP_USD": "50",
26
26
  "DEFAULT_CYCLE_CAP_USD": "150"