@linxiraos/pi-stats 1.5.0 → 1.5.10
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/CHANGELOG.md +25 -2
- package/THIRD-PARTY-NOTICES.txt +22 -11
- package/dist/client/favicon.ico +0 -0
- package/dist/client/index.css +1 -1
- package/dist/client/index.js +95 -94
- package/dist/types/aggregator.d.ts +5 -0
- package/dist/types/client/api.d.ts +7 -1
- package/dist/types/client/app/nav.d.ts +1 -1
- package/dist/types/client/data/formatters.d.ts +2 -2
- package/dist/types/client/data/range.d.ts +5 -4
- package/dist/types/client/data/series.d.ts +14 -2
- package/dist/types/client/i18n/messages/costs.d.ts +4 -4
- package/dist/types/client/i18n/messages/en.d.ts +86 -6
- package/dist/types/client/i18n/messages/gain.d.ts +2 -2
- package/dist/types/client/i18n/messages/nav.d.ts +2 -0
- package/dist/types/client/i18n/messages/tracking.d.ts +89 -0
- package/dist/types/client/i18n/messages/zh-CN.d.ts +1 -1
- package/dist/types/client/routes/TrackingRoute.d.ts +10 -0
- package/dist/types/client/routes/index.d.ts +1 -0
- package/dist/types/db.d.ts +20 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/parser.d.ts +7 -1
- package/dist/types/rollup.d.ts +4 -0
- package/dist/types/shared-types.d.ts +88 -0
- package/dist/types/spotlight-aggregator.d.ts +24 -5
- package/dist/types/spotlight-ingest.d.ts +48 -9
- package/dist/types/spotlight-worker.d.ts +27 -0
- package/dist/types/trace.d.ts +7 -1
- package/dist/types/tracking.d.ts +29 -0
- package/dist/types/types.d.ts +5 -5
- package/package.json +4 -4
- package/src/aggregator.ts +16 -0
- package/src/client/App.tsx +3 -0
- package/src/client/api.ts +11 -0
- package/src/client/app/nav.ts +3 -0
- package/src/client/data/formatters.ts +7 -7
- package/src/client/data/range.ts +22 -9
- package/src/client/data/series.ts +33 -14
- package/src/client/favicon.ico +0 -0
- package/src/client/i18n/messages/costs.ts +4 -4
- package/src/client/i18n/messages/en.ts +2 -0
- package/src/client/i18n/messages/gain.ts +2 -2
- package/src/client/i18n/messages/nav.ts +2 -0
- package/src/client/i18n/messages/tracking.ts +91 -0
- package/src/client/i18n/messages/zh-CN.ts +2 -0
- package/src/client/routes/CostsRoute.tsx +4 -4
- package/src/client/routes/GainRoute.tsx +5 -4
- package/src/client/routes/ProvidersRoute.tsx +4 -4
- package/src/client/routes/TrackingRoute.tsx +262 -0
- package/src/client/routes/index.ts +1 -0
- package/src/client/routes/tracking.css +94 -0
- package/src/client/spotlight/Overhead.tsx +46 -1
- package/src/db.ts +105 -21
- package/src/gain-aggregator.ts +3 -6
- package/src/index.ts +5 -1
- package/src/parser.ts +75 -10
- package/src/rollup.ts +67 -14
- package/src/server.ts +57 -16
- package/src/shared-types.ts +98 -0
- package/src/spotlight-aggregator.ts +207 -45
- package/src/spotlight-ingest.ts +141 -37
- package/src/spotlight-measures.ts +117 -85
- package/src/spotlight-worker.ts +45 -0
- package/src/trace.ts +56 -20
- package/src/tracking.ts +394 -0
- package/src/types.ts +5 -5
|
@@ -7,17 +7,42 @@ import type { ChartSeries } from "../charts/types";
|
|
|
7
7
|
import { t } from "../i18n";
|
|
8
8
|
import { OTHER_COLOR, SERIES_COLORS } from "./colors";
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Index of the last bucket starting at or before `timestamp`, or -1 before the
|
|
12
|
+
* axis. Matching by floor instead of exact key keeps data visible when the
|
|
13
|
+
* server's day buckets start at a different midnight than the browser's axis
|
|
14
|
+
* (the two run in different timezones): the day shifts rather than vanishing.
|
|
15
|
+
*/
|
|
16
|
+
export function bucketAt(buckets: readonly number[], timestamp: number): number {
|
|
17
|
+
let lo = 0;
|
|
18
|
+
let hi = buckets.length - 1;
|
|
19
|
+
let found = -1;
|
|
20
|
+
while (lo <= hi) {
|
|
21
|
+
const mid = (lo + hi) >> 1;
|
|
22
|
+
if (buckets[mid] <= timestamp) {
|
|
23
|
+
found = mid;
|
|
24
|
+
lo = mid + 1;
|
|
25
|
+
} else {
|
|
26
|
+
hi = mid - 1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Sum `value(point)` into a dense array aligned to `buckets`. Points before
|
|
34
|
+
* the first bucket are dropped; points after the last bucket start land in the
|
|
35
|
+
* last bucket.
|
|
36
|
+
*/
|
|
11
37
|
export function densify<P extends { timestamp: number }>(
|
|
12
38
|
points: readonly P[],
|
|
13
39
|
buckets: readonly number[],
|
|
14
40
|
value: (point: P) => number,
|
|
15
41
|
): number[] {
|
|
16
|
-
const index = bucketIndex(buckets);
|
|
17
42
|
const out = Array.from({ length: buckets.length }, () => 0);
|
|
18
43
|
for (const point of points) {
|
|
19
|
-
const i =
|
|
20
|
-
if (i
|
|
44
|
+
const i = bucketAt(buckets, point.timestamp);
|
|
45
|
+
if (i >= 0) out[i] += value(point);
|
|
21
46
|
}
|
|
22
47
|
return out;
|
|
23
48
|
}
|
|
@@ -37,17 +62,17 @@ export interface PivotOptions<P> {
|
|
|
37
62
|
|
|
38
63
|
/**
|
|
39
64
|
* Pivot long rows into one dense series per key, ranked by total (largest
|
|
40
|
-
* first). Series beyond `limit` merge into a trailing "Other" series.
|
|
65
|
+
* first). Series beyond `limit` merge into a trailing "Other" series. Points
|
|
66
|
+
* are placed like `densify`: dropped before the axis, last bucket after it.
|
|
41
67
|
*/
|
|
42
68
|
export function pivotSeries<P extends { timestamp: number }>(
|
|
43
69
|
points: readonly P[],
|
|
44
70
|
opts: PivotOptions<P>,
|
|
45
71
|
): ChartSeries[] {
|
|
46
|
-
const index = bucketIndex(opts.buckets);
|
|
47
72
|
const byKey = new Map<string, number[]>();
|
|
48
73
|
for (const point of points) {
|
|
49
|
-
const i =
|
|
50
|
-
if (i
|
|
74
|
+
const i = bucketAt(opts.buckets, point.timestamp);
|
|
75
|
+
if (i < 0) continue;
|
|
51
76
|
const key = opts.key(point);
|
|
52
77
|
let values = byKey.get(key);
|
|
53
78
|
if (!values) {
|
|
@@ -83,9 +108,3 @@ export function pivotSeries<P extends { timestamp: number }>(
|
|
|
83
108
|
}
|
|
84
109
|
return series;
|
|
85
110
|
}
|
|
86
|
-
|
|
87
|
-
function bucketIndex(buckets: readonly number[]): Map<number, number> {
|
|
88
|
-
const index = new Map<number, number>();
|
|
89
|
-
for (let i = 0; i < buckets.length; i++) index.set(buckets[i], i);
|
|
90
|
-
return index;
|
|
91
|
-
}
|
package/src/client/favicon.ico
CHANGED
|
Binary file
|
|
@@ -12,8 +12,8 @@ export const costs = {
|
|
|
12
12
|
"costs.empty-hint": "Pick a wider range in the top bar.",
|
|
13
13
|
// ── daily estimate card ─────────────────────────────────────────────
|
|
14
14
|
"costs.daily-estimate": "Daily estimate",
|
|
15
|
-
"costs.daily-by-model": "Per
|
|
16
|
-
"costs.daily-by-component": "Per
|
|
15
|
+
"costs.daily-by-model": "Per day, stacked by model",
|
|
16
|
+
"costs.daily-by-component": "Per day, stacked by billing component",
|
|
17
17
|
"costs.split-by": "Split by",
|
|
18
18
|
"costs.by-model": "By model",
|
|
19
19
|
"costs.by-component": "By component",
|
|
@@ -61,8 +61,8 @@ export const costs = {
|
|
|
61
61
|
"costs.empty-hint": "请在顶栏选择更宽的时间范围。",
|
|
62
62
|
// ── daily estimate card ─────────────────────────────────────────────
|
|
63
63
|
"costs.daily-estimate": "每日估算",
|
|
64
|
-
"costs.daily-by-model": "
|
|
65
|
-
"costs.daily-by-component": "
|
|
64
|
+
"costs.daily-by-model": "按本地日统计,按模型堆叠",
|
|
65
|
+
"costs.daily-by-component": "按本地日统计,按计费组件堆叠",
|
|
66
66
|
"costs.split-by": "拆分依据",
|
|
67
67
|
"costs.by-model": "按模型",
|
|
68
68
|
"costs.by-component": "按组件",
|
|
@@ -10,6 +10,7 @@ import { traces } from "./traces";
|
|
|
10
10
|
import { tools } from "./tools";
|
|
11
11
|
import { frustration } from "./frustration";
|
|
12
12
|
import { projects } from "./projects";
|
|
13
|
+
import { tracking } from "./tracking";
|
|
13
14
|
import { gain } from "./gain";
|
|
14
15
|
import { ui } from "./ui";
|
|
15
16
|
import { charts } from "./charts";
|
|
@@ -28,6 +29,7 @@ export const enMessages = {
|
|
|
28
29
|
...tools.en,
|
|
29
30
|
...frustration.en,
|
|
30
31
|
...projects.en,
|
|
32
|
+
...tracking.en,
|
|
31
33
|
...gain.en,
|
|
32
34
|
...ui.en,
|
|
33
35
|
...charts.en,
|
|
@@ -20,7 +20,7 @@ export const gain = {
|
|
|
20
20
|
"gain.hits": "Hits",
|
|
21
21
|
"gain.saved-per-hit": "Saved per hit",
|
|
22
22
|
"gain.savings-over-time": "Savings over time",
|
|
23
|
-
"gain.savings-over-time-description": "Tokens saved per
|
|
23
|
+
"gain.savings-over-time-description": "Tokens saved per day, with the running total",
|
|
24
24
|
"gain.saved-per-day": "Saved per day",
|
|
25
25
|
"gain.cumulative": "Cumulative",
|
|
26
26
|
"gain.by-source": "By source",
|
|
@@ -44,7 +44,7 @@ export const gain = {
|
|
|
44
44
|
"gain.hits": "命中次数",
|
|
45
45
|
"gain.saved-per-hit": "每次命中节省",
|
|
46
46
|
"gain.savings-over-time": "节省趋势",
|
|
47
|
-
"gain.savings-over-time-description": "
|
|
47
|
+
"gain.savings-over-time-description": "按本地日统计节省的 Token,以及累计总量",
|
|
48
48
|
"gain.saved-per-day": "每日节省",
|
|
49
49
|
"gain.cumulative": "累计",
|
|
50
50
|
"gain.by-source": "按来源",
|
|
@@ -17,6 +17,7 @@ export const nav = {
|
|
|
17
17
|
"nav.tools": "Tools",
|
|
18
18
|
"nav.frustration": "Frustration",
|
|
19
19
|
"nav.projects": "Projects",
|
|
20
|
+
"nav.tracking": "Tracking",
|
|
20
21
|
"nav.gain": "Gain",
|
|
21
22
|
"nav.spotlight": "Spotlight",
|
|
22
23
|
"nav.dashboard": "zetacode stats",
|
|
@@ -38,6 +39,7 @@ export const nav = {
|
|
|
38
39
|
"nav.tools": "工具",
|
|
39
40
|
"nav.frustration": "情绪压力",
|
|
40
41
|
"nav.projects": "项目",
|
|
42
|
+
"nav.tracking": "追踪",
|
|
41
43
|
"nav.gain": "收益",
|
|
42
44
|
"nav.spotlight": "亮点",
|
|
43
45
|
"nav.dashboard": "zeta 统计",
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project tracking panel copy. Keys are slugs (`tracking.<name>`); English is
|
|
3
|
+
* the source of truth and `zh-CN` overrides it. Technical terms (`status.json`,
|
|
4
|
+
* `INDEX.md`, `tracking_update`) stay verbatim.
|
|
5
|
+
*/
|
|
6
|
+
export const tracking = {
|
|
7
|
+
en: {
|
|
8
|
+
"tracking.title": "Tracking",
|
|
9
|
+
"tracking.description": "Read-only snapshot of a project's tracking documents: process state, not learned facts.",
|
|
10
|
+
"tracking.project": "Project",
|
|
11
|
+
"tracking.select-project": "Select a project…",
|
|
12
|
+
"tracking.no-projects": "No projects in the stats registry",
|
|
13
|
+
"tracking.no-projects-hint": "Tracking is scoped to folders the stats database has seen.",
|
|
14
|
+
"tracking.read-only": "The dashboard only reads these files; it never writes tracking.",
|
|
15
|
+
"tracking.directory": "Directory",
|
|
16
|
+
"tracking.updated": "Updated",
|
|
17
|
+
"tracking.none": "None",
|
|
18
|
+
"tracking.no-documents": "No tracking documents",
|
|
19
|
+
"tracking.no-documents-hint":
|
|
20
|
+
"Tracking is opt-in. Run /tracking on, or enable tools → Project Tracking (tracking.enabled) in /settings, then /tracking start.",
|
|
21
|
+
"tracking.status": "Status",
|
|
22
|
+
"tracking.index": "Index",
|
|
23
|
+
"tracking.actions": "Actions",
|
|
24
|
+
"tracking.sessions": "Sessions",
|
|
25
|
+
"tracking.phase": "Phase",
|
|
26
|
+
"tracking.progress": "Progress",
|
|
27
|
+
"tracking.blockers": "Blockers",
|
|
28
|
+
"tracking.decisions": "Decisions",
|
|
29
|
+
"tracking.stage": "Stage",
|
|
30
|
+
"tracking.phases": "Todo phases",
|
|
31
|
+
"tracking.last-updated": "Last updated",
|
|
32
|
+
"tracking.last-session": "Last session",
|
|
33
|
+
"tracking.missing": "Missing",
|
|
34
|
+
"tracking.partial": "Partial",
|
|
35
|
+
"tracking.corrupt": "Corrupt",
|
|
36
|
+
"tracking.error": "Error",
|
|
37
|
+
"tracking.truncated": "Truncated read",
|
|
38
|
+
"tracking.status-missing": "status.json is missing",
|
|
39
|
+
"tracking.status-corrupt": "status.json is not valid JSON",
|
|
40
|
+
"tracking.status-error": "Could not read status.json",
|
|
41
|
+
"tracking.index-missing": "INDEX.md is missing",
|
|
42
|
+
"tracking.actions-missing": "No action log yet",
|
|
43
|
+
"tracking.sessions-missing": "No sessions directory yet",
|
|
44
|
+
"tracking.sessions-empty": "No session documents",
|
|
45
|
+
"tracking.invalid-rows": "{count} malformed action rows skipped",
|
|
46
|
+
"tracking.actions-empty": "The action log has no readable rows",
|
|
47
|
+
"tracking.document-empty": "This document is empty",
|
|
48
|
+
},
|
|
49
|
+
"zh-CN": {
|
|
50
|
+
"tracking.title": "追踪",
|
|
51
|
+
"tracking.description": "项目追踪文档的只读快照:这里是过程状态,不是学到的知识事实。",
|
|
52
|
+
"tracking.project": "项目",
|
|
53
|
+
"tracking.select-project": "选择项目…",
|
|
54
|
+
"tracking.no-projects": "统计注册表中没有项目",
|
|
55
|
+
"tracking.no-projects-hint": "追踪只读取统计数据库见过的项目文件夹。",
|
|
56
|
+
"tracking.read-only": "仪表盘只读取这些文件,绝不写入追踪。",
|
|
57
|
+
"tracking.directory": "目录",
|
|
58
|
+
"tracking.updated": "更新时间",
|
|
59
|
+
"tracking.none": "无",
|
|
60
|
+
"tracking.no-documents": "没有追踪文档",
|
|
61
|
+
"tracking.no-documents-hint":
|
|
62
|
+
"追踪是可选功能。运行 /tracking on,或在 /settings → tools → Project Tracking(tracking.enabled)中启用,然后执行 /tracking start。",
|
|
63
|
+
"tracking.status": "状态",
|
|
64
|
+
"tracking.index": "索引",
|
|
65
|
+
"tracking.actions": "操作",
|
|
66
|
+
"tracking.sessions": "会话",
|
|
67
|
+
"tracking.phase": "阶段",
|
|
68
|
+
"tracking.progress": "进度",
|
|
69
|
+
"tracking.blockers": "阻塞",
|
|
70
|
+
"tracking.decisions": "决策",
|
|
71
|
+
"tracking.stage": "当前阶段",
|
|
72
|
+
"tracking.phases": "待办阶段",
|
|
73
|
+
"tracking.last-updated": "最近更新",
|
|
74
|
+
"tracking.last-session": "最近会话",
|
|
75
|
+
"tracking.missing": "缺失",
|
|
76
|
+
"tracking.partial": "不完整",
|
|
77
|
+
"tracking.corrupt": "损坏",
|
|
78
|
+
"tracking.error": "错误",
|
|
79
|
+
"tracking.truncated": "读取已截断",
|
|
80
|
+
"tracking.status-missing": "status.json 缺失",
|
|
81
|
+
"tracking.status-corrupt": "status.json 不是有效 JSON",
|
|
82
|
+
"tracking.status-error": "无法读取 status.json",
|
|
83
|
+
"tracking.index-missing": "INDEX.md 缺失",
|
|
84
|
+
"tracking.actions-missing": "还没有操作日志",
|
|
85
|
+
"tracking.sessions-missing": "还没有 sessions 目录",
|
|
86
|
+
"tracking.sessions-empty": "没有会话文档",
|
|
87
|
+
"tracking.invalid-rows": "已跳过 {count} 行格式错误的操作记录",
|
|
88
|
+
"tracking.actions-empty": "操作日志没有可读记录",
|
|
89
|
+
"tracking.document-empty": "该文档为空",
|
|
90
|
+
},
|
|
91
|
+
} as const;
|
|
@@ -11,6 +11,7 @@ import { traces } from "./traces";
|
|
|
11
11
|
import { tools } from "./tools";
|
|
12
12
|
import { frustration } from "./frustration";
|
|
13
13
|
import { projects } from "./projects";
|
|
14
|
+
import { tracking } from "./tracking";
|
|
14
15
|
import { gain } from "./gain";
|
|
15
16
|
import { ui } from "./ui";
|
|
16
17
|
import { charts } from "./charts";
|
|
@@ -34,6 +35,7 @@ export const zhCNMessages: Partial<Record<MessageKey, string>> = {
|
|
|
34
35
|
...tools["zh-CN"],
|
|
35
36
|
...frustration["zh-CN"],
|
|
36
37
|
...projects["zh-CN"],
|
|
38
|
+
...tracking["zh-CN"],
|
|
37
39
|
...gain["zh-CN"],
|
|
38
40
|
...ui["zh-CN"],
|
|
39
41
|
...charts["zh-CN"],
|
|
@@ -4,7 +4,7 @@ import { getCostDashboardStats } from "../api";
|
|
|
4
4
|
import { t } from "../i18n";
|
|
5
5
|
import { Chart, type ChartSeries, Legend, ShareBar, useHiddenSeries } from "../charts";
|
|
6
6
|
import { buildModelColorLookup, modelKey, OTHER_COLOR, SERIES_COLORS } from "../data/colors";
|
|
7
|
-
import { formatCost, formatEstimatedCost, formatInteger, formatPercent,
|
|
7
|
+
import { formatCost, formatEstimatedCost, formatInteger, formatPercent, formatLocalDay } from "../data/formatters";
|
|
8
8
|
import { useQuery } from "../data/query";
|
|
9
9
|
import { bucketAxis, rangeMeta } from "../data/range";
|
|
10
10
|
import { densify, pivotSeries } from "../data/series";
|
|
@@ -46,7 +46,7 @@ function splitOptions() {
|
|
|
46
46
|
/** Models stacked individually in the daily chart; the rest fold into "Other". */
|
|
47
47
|
const MODEL_LIMIT = 6;
|
|
48
48
|
|
|
49
|
-
/** The cost series is bucketed by
|
|
49
|
+
/** The cost series is bucketed by local calendar day on the server. */
|
|
50
50
|
const DAY_MS = 86_400_000;
|
|
51
51
|
|
|
52
52
|
function components(): readonly { key: keyof CostComponents; label: string; color: string }[] {
|
|
@@ -106,8 +106,8 @@ export function CostsRoute({ active, range }: CostsRouteProps) {
|
|
|
106
106
|
<div className="stack" style={{ gap: 12 }}>
|
|
107
107
|
<Chart
|
|
108
108
|
slots={view.buckets.length}
|
|
109
|
-
tickLabel={i =>
|
|
110
|
-
tooltipTitle={i =>
|
|
109
|
+
tickLabel={i => formatLocalDay(view.buckets[i])}
|
|
110
|
+
tooltipTitle={i => formatLocalDay(view.buckets[i], true)}
|
|
111
111
|
series={series}
|
|
112
112
|
hidden={hidden}
|
|
113
113
|
height={280}
|
|
@@ -2,7 +2,7 @@ import { useMemo, useState } from "react";
|
|
|
2
2
|
import { getGainDashboardStats } from "../api";
|
|
3
3
|
import { t } from "../i18n";
|
|
4
4
|
import { Chart, type ChartSeries, Legend } from "../charts";
|
|
5
|
-
import { formatBytes, formatCompact, formatInteger, formatPercent,
|
|
5
|
+
import { formatBytes, formatCompact, formatInteger, formatPercent, formatLocalDay } from "../data/formatters";
|
|
6
6
|
import { useQuery } from "../data/query";
|
|
7
7
|
import { bucketAxis, rangeMeta } from "../data/range";
|
|
8
8
|
import { densify } from "../data/series";
|
|
@@ -29,7 +29,7 @@ const DAY_MS = 86_400_000;
|
|
|
29
29
|
|
|
30
30
|
const SOURCE_LABEL: Record<GainSource, string> = { snapcompact: "Snapcompact" };
|
|
31
31
|
|
|
32
|
-
/** The server buckets gain by
|
|
32
|
+
/** The server buckets gain by local calendar day (`YYYY-MM-DD`). */
|
|
33
33
|
interface SourceRow extends GainSourceTotals {
|
|
34
34
|
source: GainSource;
|
|
35
35
|
/** Share of all saved tokens (0-1). */
|
|
@@ -45,7 +45,8 @@ export function GainRoute({ active, range }: GainRouteProps) {
|
|
|
45
45
|
const data = gain.data;
|
|
46
46
|
|
|
47
47
|
const series = useMemo(() => {
|
|
48
|
-
|
|
48
|
+
// A date-time string without an offset parses as local midnight.
|
|
49
|
+
const points = (data?.timeSeries ?? []).map(p => ({ ...p, timestamp: Date.parse(`${p.date}T00:00:00`) }));
|
|
49
50
|
const buckets = bucketAxis(
|
|
50
51
|
range,
|
|
51
52
|
points.map(p => p.timestamp),
|
|
@@ -164,7 +165,7 @@ export function GainRoute({ active, range }: GainRouteProps) {
|
|
|
164
165
|
>
|
|
165
166
|
<Chart
|
|
166
167
|
slots={series.buckets.length}
|
|
167
|
-
tickLabel={i =>
|
|
168
|
+
tickLabel={i => formatLocalDay(series.buckets[i])}
|
|
168
169
|
series={chartSeries}
|
|
169
170
|
height={260}
|
|
170
171
|
formatTooltip={formatInteger}
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from "../data/formatters";
|
|
17
17
|
import { type QueryResult, useQuery } from "../data/query";
|
|
18
18
|
import { bucketAxis, formatBucket, formatTick, rangeMeta } from "../data/range";
|
|
19
|
-
import { densify, pivotSeries } from "../data/series";
|
|
19
|
+
import { bucketAt, densify, pivotSeries } from "../data/series";
|
|
20
20
|
import type {
|
|
21
21
|
ProviderAggregate,
|
|
22
22
|
ProviderHourlyPoint,
|
|
@@ -982,7 +982,6 @@ function buildUtilization(accounts: UsageWindowSeries[], names: ReadonlyMap<stri
|
|
|
982
982
|
const span = last - first;
|
|
983
983
|
const bucketMs = UTIL_STEPS.find(step => span / step < MAX_UTIL_SLOTS) ?? DAY_MS;
|
|
984
984
|
const buckets = bucketAxis("all", [first], bucketMs, last);
|
|
985
|
-
const index = (ts: number) => Math.floor((ts - buckets[0]) / bucketMs);
|
|
986
985
|
const exhausted = buckets.map((): string[] => []);
|
|
987
986
|
let max = 0;
|
|
988
987
|
|
|
@@ -993,8 +992,9 @@ function buildUtilization(accounts: UsageWindowSeries[], names: ReadonlyMap<stri
|
|
|
993
992
|
const values: (number | null)[] = buckets.map(() => null);
|
|
994
993
|
const readAt: number[] = buckets.map(() => 0);
|
|
995
994
|
for (const p of account.points) {
|
|
996
|
-
|
|
997
|
-
|
|
995
|
+
// Floor search: day buckets start at local midnight, so they are not uniform.
|
|
996
|
+
const i = bucketAt(buckets, p.timestamp);
|
|
997
|
+
if (i < 0) continue;
|
|
998
998
|
if (p.exhausted && !exhausted[i].includes(nameOf(account))) exhausted[i].push(nameOf(account));
|
|
999
999
|
if (p.usedFraction === null || p.timestamp < readAt[i]) continue;
|
|
1000
1000
|
values[i] = p.usedFraction;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { getTrackingProjects, getTrackingSnapshot } from "../api";
|
|
3
|
+
import { t } from "../i18n";
|
|
4
|
+
import { formatInteger, formatRelativeTime, formatTimestamp } from "../data/formatters";
|
|
5
|
+
import { useQuery } from "../data/query";
|
|
6
|
+
import type { TrackingSnapshotState, TrackingStatusValue } from "../types";
|
|
7
|
+
import { Badge, Card, EmptyState, KeyValues, PageHeader, QueryView, Skeleton, TableSkeleton, type Tone } from "../ui";
|
|
8
|
+
import "./tracking.css";
|
|
9
|
+
|
|
10
|
+
export interface TrackingRouteProps {
|
|
11
|
+
active: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const STATE_KEY = {
|
|
15
|
+
missing: "tracking.missing",
|
|
16
|
+
partial: "tracking.partial",
|
|
17
|
+
corrupt: "tracking.corrupt",
|
|
18
|
+
error: "tracking.error",
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
function stateTone(state: TrackingSnapshotState): Tone {
|
|
22
|
+
if (state === "present") return "ok";
|
|
23
|
+
if (state === "partial") return "warn";
|
|
24
|
+
if (state === "corrupt" || state === "error") return "bad";
|
|
25
|
+
return "neutral";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function StateBadge({ state, truncated }: { state: TrackingSnapshotState; truncated?: boolean }) {
|
|
29
|
+
if (state === "present" && !truncated) return null;
|
|
30
|
+
return <Badge tone={stateTone(state)}>{state === "present" ? t("tracking.truncated") : t(STATE_KEY[state])}</Badge>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function statusItems(status: TrackingStatusValue) {
|
|
34
|
+
return [
|
|
35
|
+
{ key: "phase", label: t("tracking.phase"), value: status.phase || t("tracking.none") },
|
|
36
|
+
{ key: "progress", label: t("tracking.progress"), value: status.progress || t("tracking.none") },
|
|
37
|
+
...(status.stage ? [{ key: "stage", label: t("tracking.stage"), value: status.stage }] : []),
|
|
38
|
+
{
|
|
39
|
+
key: "blockers",
|
|
40
|
+
label: t("tracking.blockers"),
|
|
41
|
+
value: status.blockers.length ? status.blockers.join("; ") : t("tracking.none"),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
key: "decisions",
|
|
45
|
+
label: t("tracking.decisions"),
|
|
46
|
+
value: status.decisions.length ? status.decisions.join("; ") : t("tracking.none"),
|
|
47
|
+
},
|
|
48
|
+
{ key: "updated", label: t("tracking.last-updated"), value: status.lastUpdated || t("tracking.none") },
|
|
49
|
+
...(status.lastSessionId
|
|
50
|
+
? [
|
|
51
|
+
{
|
|
52
|
+
key: "session",
|
|
53
|
+
label: t("tracking.last-session"),
|
|
54
|
+
value: <span className="mono">{status.lastSessionId}</span>,
|
|
55
|
+
},
|
|
56
|
+
]
|
|
57
|
+
: []),
|
|
58
|
+
...(status.phases?.length
|
|
59
|
+
? [
|
|
60
|
+
{
|
|
61
|
+
key: "phases",
|
|
62
|
+
label: t("tracking.phases"),
|
|
63
|
+
value: status.phases.map(phase => `${phase.name} · ${phase.status}`).join("; "),
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
: []),
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function errorLine(error: string | null) {
|
|
71
|
+
if (!error) return null;
|
|
72
|
+
return <p className="tracking-error">{error}</p>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Read-only Tracking page: one project from the stats registry at a time, with
|
|
77
|
+
* the same files the agent's `tracking_update` tool writes. Missing/corrupt
|
|
78
|
+
* inputs render as those states rather than as an empty or healthy project.
|
|
79
|
+
*/
|
|
80
|
+
export function TrackingRoute({ active }: TrackingRouteProps) {
|
|
81
|
+
const folders = useQuery(["tracking-projects"], ({ signal }) => getTrackingProjects(signal), { enabled: active });
|
|
82
|
+
const projects = folders.data?.projects ?? [];
|
|
83
|
+
const [selected, setSelected] = useState<string | null>(null);
|
|
84
|
+
const project = selected !== null && projects.includes(selected) ? selected : (projects[0] ?? null);
|
|
85
|
+
const snapshot = useQuery(["tracking", project], ({ signal }) => getTrackingSnapshot(project ?? "", signal), {
|
|
86
|
+
enabled: active && project !== null,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<div className="page">
|
|
91
|
+
<PageHeader title={t("tracking.title")} description={t("tracking.description")} />
|
|
92
|
+
<Card index={0}>
|
|
93
|
+
<div className="tracking-toolbar">
|
|
94
|
+
<label className="tracking-project">
|
|
95
|
+
<span className="section-label">{t("tracking.project")}</span>
|
|
96
|
+
{folders.data === null ? (
|
|
97
|
+
<Skeleton width={280} height={30} />
|
|
98
|
+
) : (
|
|
99
|
+
<select
|
|
100
|
+
className="tracking-select"
|
|
101
|
+
value={project ?? ""}
|
|
102
|
+
aria-label={t("tracking.project")}
|
|
103
|
+
onChange={event => setSelected(event.target.value)}
|
|
104
|
+
disabled={projects.length === 0}
|
|
105
|
+
>
|
|
106
|
+
{projects.length === 0 && <option value="">{t("tracking.no-projects")}</option>}
|
|
107
|
+
{projects.map(folder => (
|
|
108
|
+
<option key={folder} value={folder}>
|
|
109
|
+
{folder}
|
|
110
|
+
</option>
|
|
111
|
+
))}
|
|
112
|
+
</select>
|
|
113
|
+
)}
|
|
114
|
+
</label>
|
|
115
|
+
<p className="tracking-note">{t("tracking.read-only")}</p>
|
|
116
|
+
</div>
|
|
117
|
+
</Card>
|
|
118
|
+
|
|
119
|
+
{folders.data !== null && projects.length === 0 ? (
|
|
120
|
+
<Card index={1}>
|
|
121
|
+
<EmptyState title={t("tracking.no-projects")} hint={t("tracking.no-projects-hint")} />
|
|
122
|
+
</Card>
|
|
123
|
+
) : (
|
|
124
|
+
<QueryView
|
|
125
|
+
query={snapshot}
|
|
126
|
+
skeleton={<TableSkeleton rows={5} />}
|
|
127
|
+
isEmpty={data => !data.exists}
|
|
128
|
+
empty={
|
|
129
|
+
<EmptyState
|
|
130
|
+
title={t("tracking.no-documents")}
|
|
131
|
+
hint={`${t("tracking.no-documents-hint")}\n${snapshot.data?.trackingDir ?? ""}`}
|
|
132
|
+
/>
|
|
133
|
+
}
|
|
134
|
+
>
|
|
135
|
+
{data => (
|
|
136
|
+
<div className="grid grid-main-side">
|
|
137
|
+
<Card index={1} title={t("tracking.status")} flush>
|
|
138
|
+
<div className="tracking-panel">
|
|
139
|
+
<div className="row tracking-meta">
|
|
140
|
+
<span className="mono dim">{data.trackingDir}</span>
|
|
141
|
+
<span className="row">
|
|
142
|
+
{data.updatedAt && (
|
|
143
|
+
<span className="dim" title={formatTimestamp(Date.parse(data.updatedAt))}>
|
|
144
|
+
{t("tracking.updated")}: {formatRelativeTime(Date.parse(data.updatedAt))}
|
|
145
|
+
</span>
|
|
146
|
+
)}
|
|
147
|
+
<StateBadge state={data.status.state} truncated={data.status.truncated} />
|
|
148
|
+
</span>
|
|
149
|
+
</div>
|
|
150
|
+
{data.status.value ? (
|
|
151
|
+
<KeyValues items={statusItems(data.status.value)} />
|
|
152
|
+
) : (
|
|
153
|
+
<EmptyState
|
|
154
|
+
title={
|
|
155
|
+
data.status.state === "missing"
|
|
156
|
+
? t("tracking.status-missing")
|
|
157
|
+
: data.status.state === "corrupt"
|
|
158
|
+
? t("tracking.status-corrupt")
|
|
159
|
+
: t("tracking.status-error")
|
|
160
|
+
}
|
|
161
|
+
/>
|
|
162
|
+
)}
|
|
163
|
+
{errorLine(data.status.error)}
|
|
164
|
+
</div>
|
|
165
|
+
</Card>
|
|
166
|
+
|
|
167
|
+
<Card index={2} title={t("tracking.index")} flush>
|
|
168
|
+
<div className="tracking-panel">
|
|
169
|
+
<div className="row tracking-meta">
|
|
170
|
+
<span className="dim">{t("tracking.index")}</span>
|
|
171
|
+
<StateBadge state={data.index.state} truncated={data.index.truncated} />
|
|
172
|
+
</div>
|
|
173
|
+
{data.index.content !== null ? (
|
|
174
|
+
<pre className="tracking-doc">{data.index.content || t("tracking.document-empty")}</pre>
|
|
175
|
+
) : (
|
|
176
|
+
<EmptyState title={t("tracking.index-missing")} />
|
|
177
|
+
)}
|
|
178
|
+
{errorLine(data.index.error)}
|
|
179
|
+
</div>
|
|
180
|
+
</Card>
|
|
181
|
+
|
|
182
|
+
<Card index={3} title={t("tracking.actions")} flush>
|
|
183
|
+
<div className="tracking-panel">
|
|
184
|
+
<div className="row tracking-meta">
|
|
185
|
+
<span className="dim">
|
|
186
|
+
{t("tracking.actions")} · {formatInteger(data.actions.rows.length)}
|
|
187
|
+
</span>
|
|
188
|
+
<StateBadge state={data.actions.state} truncated={data.actions.truncated} />
|
|
189
|
+
</div>
|
|
190
|
+
{data.actions.invalidRows > 0 && (
|
|
191
|
+
<p className="tracking-error">
|
|
192
|
+
{t("tracking.invalid-rows", { count: formatInteger(data.actions.invalidRows) })}
|
|
193
|
+
</p>
|
|
194
|
+
)}
|
|
195
|
+
{data.actions.rows.length === 0 ? (
|
|
196
|
+
<EmptyState
|
|
197
|
+
title={
|
|
198
|
+
data.actions.state === "missing"
|
|
199
|
+
? t("tracking.actions-missing")
|
|
200
|
+
: t("tracking.actions-empty")
|
|
201
|
+
}
|
|
202
|
+
/>
|
|
203
|
+
) : (
|
|
204
|
+
<ul className="tracking-list">
|
|
205
|
+
{[...data.actions.rows].reverse().map((row, index) => (
|
|
206
|
+
<li className="tracking-list-row" key={`${row.timestamp}:${row.action}:${index}`}>
|
|
207
|
+
<span className="mono dim">{row.timestamp || "—"}</span>
|
|
208
|
+
<span>{row.action}</span>
|
|
209
|
+
{row.detail !== undefined && <span className="muted">{row.detail}</span>}
|
|
210
|
+
</li>
|
|
211
|
+
))}
|
|
212
|
+
</ul>
|
|
213
|
+
)}
|
|
214
|
+
{errorLine(data.actions.error)}
|
|
215
|
+
</div>
|
|
216
|
+
</Card>
|
|
217
|
+
|
|
218
|
+
<Card index={4} title={t("tracking.sessions")} flush>
|
|
219
|
+
<div className="tracking-panel">
|
|
220
|
+
<div className="row tracking-meta">
|
|
221
|
+
<span className="dim">
|
|
222
|
+
{t("tracking.sessions")} · {formatInteger(data.sessions.length)}
|
|
223
|
+
</span>
|
|
224
|
+
<StateBadge state={data.sessionsState} />
|
|
225
|
+
</div>
|
|
226
|
+
{data.sessions.length === 0 ? (
|
|
227
|
+
<EmptyState
|
|
228
|
+
title={
|
|
229
|
+
data.sessionsState === "missing"
|
|
230
|
+
? t("tracking.sessions-missing")
|
|
231
|
+
: t("tracking.sessions-empty")
|
|
232
|
+
}
|
|
233
|
+
/>
|
|
234
|
+
) : (
|
|
235
|
+
<div className="stack">
|
|
236
|
+
{data.sessions.map(session => (
|
|
237
|
+
<details className="tracking-session" key={session.name}>
|
|
238
|
+
<summary className="row">
|
|
239
|
+
<span className="mono">{session.name}</span>
|
|
240
|
+
<StateBadge state={session.state} truncated={session.truncated} />
|
|
241
|
+
</summary>
|
|
242
|
+
{session.content !== null ? (
|
|
243
|
+
<pre className="tracking-doc">
|
|
244
|
+
{session.content || t("tracking.document-empty")}
|
|
245
|
+
</pre>
|
|
246
|
+
) : (
|
|
247
|
+
<EmptyState title={t("tracking.sessions-empty")} />
|
|
248
|
+
)}
|
|
249
|
+
{errorLine(session.error)}
|
|
250
|
+
</details>
|
|
251
|
+
))}
|
|
252
|
+
</div>
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
</Card>
|
|
256
|
+
</div>
|
|
257
|
+
)}
|
|
258
|
+
</QueryView>
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
);
|
|
262
|
+
}
|