@linxiraos/pi-stats 1.5.1 → 1.5.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/CHANGELOG.md +28 -3
- 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 +90 -89
- 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
|
@@ -648,6 +648,17 @@ export interface SpotlightGapCount {
|
|
|
648
648
|
applied: number;
|
|
649
649
|
holdout: number;
|
|
650
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* Failed results by why their Spotlight calls failed: `no_credential` (no Stencil sign-in), `timeout`, `transport`,
|
|
653
|
+
* `rate_limited`, `bad_reply`, `http_<status>`, or `unrecorded` for results journaled before pi recorded causes.
|
|
654
|
+
*/
|
|
655
|
+
export interface SpotlightFailureCause {
|
|
656
|
+
cause: string;
|
|
657
|
+
/** Results with a call that failed this way (a result with calls failing two ways counts under both). */
|
|
658
|
+
results: number;
|
|
659
|
+
/** Of the results that called Spotlight. */
|
|
660
|
+
share: number;
|
|
661
|
+
}
|
|
651
662
|
/** What shaping costs in time and reliability (all evaluated results, held-out ones included). */
|
|
652
663
|
export interface SpotlightOverhead {
|
|
653
664
|
results: number;
|
|
@@ -659,6 +670,8 @@ export interface SpotlightOverhead {
|
|
|
659
670
|
spotlightMsP90: number | null;
|
|
660
671
|
/** Results whose Spotlight calls failed or timed out (shaped by the no-score fallback). */
|
|
661
672
|
failureRate: number | null;
|
|
673
|
+
/** The failed results by cause, most first. */
|
|
674
|
+
failureCauses: SpotlightFailureCause[];
|
|
662
675
|
/** Wall time tool calls spent shaping results whose Spotlight calls failed (mostly the 5 s timeout per call). */
|
|
663
676
|
failedWaitMs: number;
|
|
664
677
|
spotlightUsd: number;
|
|
@@ -1159,3 +1172,78 @@ export interface SessionTrace {
|
|
|
1159
1172
|
tracks: TraceTrack[];
|
|
1160
1173
|
summary: TraceSummary;
|
|
1161
1174
|
}
|
|
1175
|
+
/**
|
|
1176
|
+
* What a tracking read actually found for one file or file family. The
|
|
1177
|
+
* dashboard renders these states instead of guessing: a missing status file is
|
|
1178
|
+
* not a zero-progress project.
|
|
1179
|
+
*/
|
|
1180
|
+
export type TrackingSnapshotState = "present" | "missing" | "partial" | "corrupt" | "error";
|
|
1181
|
+
/** Parsed `status.json`; every field is optional in the file, so defaults are explicit. */
|
|
1182
|
+
export interface TrackingStatusValue {
|
|
1183
|
+
phase: string;
|
|
1184
|
+
progress: string;
|
|
1185
|
+
blockers: string[];
|
|
1186
|
+
decisions: string[];
|
|
1187
|
+
lastUpdated: string;
|
|
1188
|
+
/** Current todo phase name (Tracking v2 sync_todo). */
|
|
1189
|
+
stage?: string;
|
|
1190
|
+
/** Ordered todo-phase mirror (Tracking v2 sync_todo). */
|
|
1191
|
+
phases?: {
|
|
1192
|
+
name: string;
|
|
1193
|
+
status: string;
|
|
1194
|
+
}[];
|
|
1195
|
+
/** Session that last wrote tracking state. */
|
|
1196
|
+
lastSessionId?: string | null;
|
|
1197
|
+
}
|
|
1198
|
+
export interface TrackingStatusSnapshot {
|
|
1199
|
+
state: TrackingSnapshotState;
|
|
1200
|
+
/** Null unless `state` is `present` or `partial` and the JSON parsed. */
|
|
1201
|
+
value: TrackingStatusValue | null;
|
|
1202
|
+
truncated: boolean;
|
|
1203
|
+
error: string | null;
|
|
1204
|
+
}
|
|
1205
|
+
export interface TrackingTextSnapshot {
|
|
1206
|
+
state: TrackingSnapshotState;
|
|
1207
|
+
content: string | null;
|
|
1208
|
+
truncated: boolean;
|
|
1209
|
+
error: string | null;
|
|
1210
|
+
}
|
|
1211
|
+
export interface TrackingActionRow {
|
|
1212
|
+
timestamp: string;
|
|
1213
|
+
action: string;
|
|
1214
|
+
detail?: string;
|
|
1215
|
+
}
|
|
1216
|
+
export interface TrackingActionsSnapshot {
|
|
1217
|
+
state: TrackingSnapshotState;
|
|
1218
|
+
/** Oldest first, as written. */
|
|
1219
|
+
rows: TrackingActionRow[];
|
|
1220
|
+
truncated: boolean;
|
|
1221
|
+
/** JSONL rows that did not parse; they are skipped, never invented. */
|
|
1222
|
+
invalidRows: number;
|
|
1223
|
+
error: string | null;
|
|
1224
|
+
}
|
|
1225
|
+
export interface TrackingSessionSnapshot {
|
|
1226
|
+
name: string;
|
|
1227
|
+
state: TrackingSnapshotState;
|
|
1228
|
+
content: string | null;
|
|
1229
|
+
truncated: boolean;
|
|
1230
|
+
error: string | null;
|
|
1231
|
+
}
|
|
1232
|
+
/** Read-only snapshot of `<project>/.zeta/tracking/`; independent of any agent package type. */
|
|
1233
|
+
export interface TrackingSnapshot {
|
|
1234
|
+
/** Exact project folder from the stats registry, never a caller-supplied path. */
|
|
1235
|
+
project: string;
|
|
1236
|
+
/** Resolved tracking directory the reads targeted. */
|
|
1237
|
+
trackingDir: string;
|
|
1238
|
+
/** Whether the tracking directory itself exists. */
|
|
1239
|
+
exists: boolean;
|
|
1240
|
+
/** Newest mtime among the files read, ISO; null when nothing exists. */
|
|
1241
|
+
updatedAt: string | null;
|
|
1242
|
+
status: TrackingStatusSnapshot;
|
|
1243
|
+
index: TrackingTextSnapshot;
|
|
1244
|
+
actions: TrackingActionsSnapshot;
|
|
1245
|
+
/** Newest first, at most the read limit. */
|
|
1246
|
+
sessions: TrackingSessionSnapshot[];
|
|
1247
|
+
/** State of the `sessions/` directory itself. */
|
|
1248
|
+
sessionsState: TrackingSnapshotState;
|
|
1249
|
+
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import type { Database } from "bun:sqlite";
|
|
15
15
|
import { type RangeWindow } from "./rollup.js";
|
|
16
16
|
import type { AgentType, SpotlightDashboardStats, SpotlightRecoveryKind, SpotlightAgentScope, SpotlightSessionContext, SpotlightSharePoint, SpotlightTool } from "./shared-types.js";
|
|
17
|
+
import { type SpotlightWindowFacts } from "./spotlight-ingest.js";
|
|
17
18
|
export interface SessionRow {
|
|
18
19
|
session_file: string;
|
|
19
20
|
folder: string;
|
|
@@ -60,14 +61,18 @@ export interface Result {
|
|
|
60
61
|
reread: [number, number][];
|
|
61
62
|
edit: [number, number][];
|
|
62
63
|
} | null;
|
|
63
|
-
|
|
64
|
-
/** The original window (`details.spotlight.original`): first line and line count; 0 lines without one. */
|
|
65
|
-
start: number;
|
|
64
|
+
/** The original's line count (all its windows'); 0 without one. */
|
|
66
65
|
lines: number;
|
|
67
|
-
|
|
66
|
+
/**
|
|
67
|
+
* The windows of the original (`details.spotlight.original`): its one window, or a `;`/`,` list read's several;
|
|
68
|
+
* none without an original.
|
|
69
|
+
*/
|
|
70
|
+
windows: SpotlightWindowFacts[];
|
|
68
71
|
hiddenLines: number;
|
|
69
72
|
spotlightCalls: number;
|
|
70
73
|
spotlightFailures: number;
|
|
74
|
+
/** Failed Spotlight calls by cause; null when none failed or the shape entry predates causes. */
|
|
75
|
+
spotlightFailureCauses: Record<string, number> | null;
|
|
71
76
|
spotlightMs: number;
|
|
72
77
|
spotlightUsd: number;
|
|
73
78
|
/** Wall time shaping took; null before its shape entry landed. */
|
|
@@ -182,8 +187,22 @@ export interface Evaluated {
|
|
|
182
187
|
analysis: SessionAnalysis;
|
|
183
188
|
tool: SpotlightTool;
|
|
184
189
|
}
|
|
185
|
-
/**
|
|
190
|
+
/** The dashboard for a `?range=` and `?agent=`; an unknown `agent` measures every transcript. */
|
|
191
|
+
export declare function spotlightDashboard(database: Database, range: string | null | undefined, agent: string | null | undefined): SpotlightDashboardStats;
|
|
192
|
+
/** `GET /api/stats/spotlight?range=&agent=`, built on the calling thread. */
|
|
186
193
|
export declare function getSpotlightDashboardStats(range?: string | null, agent?: string | null): Promise<SpotlightDashboardStats>;
|
|
194
|
+
/**
|
|
195
|
+
* `GET /api/stats/spotlight?range=&agent=` as JSON, built on a worker: a build takes seconds, and on the server's
|
|
196
|
+
* thread it held every other request and ingest until it ended. Aborting `signal` ends the build.
|
|
197
|
+
*/
|
|
198
|
+
export declare function buildSpotlightDashboardJson(range: string | null, agent: string | null, signal?: AbortSignal): Promise<string>;
|
|
199
|
+
/**
|
|
200
|
+
* Smoke test for `zetacode --smoke-test`: spawns a Spotlight worker, pings it, and asserts the pong, so install-method CI
|
|
201
|
+
* catches a worker that fails to load from the compiled binary or npm bundle.
|
|
202
|
+
*/
|
|
203
|
+
export declare function smokeTestSpotlightWorker({ timeoutMs }?: {
|
|
204
|
+
timeoutMs?: number;
|
|
205
|
+
}): Promise<void>;
|
|
187
206
|
/** `GET /api/stats/spotlight/session?file=`; null when the file is not an experiment session. */
|
|
188
207
|
export declare function getSpotlightSessionContext(sessionFile: string): Promise<SpotlightSessionContext | null>;
|
|
189
208
|
export {};
|
|
@@ -21,14 +21,19 @@
|
|
|
21
21
|
export declare function experimentMarker(customType: unknown, data: Record<string, unknown>): boolean;
|
|
22
22
|
/** Longest stored call target. */
|
|
23
23
|
export declare const SPOTLIGHT_TARGET_CHARS = 500;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* A window of a shaped read still collecting the lines the agent needs later (see {@link SpotlightCollector}): a
|
|
26
|
+
* `;`/`,` list read opens one per window that shows a file, all under its call.
|
|
27
|
+
*/
|
|
25
28
|
export interface SpotlightOpenRead {
|
|
26
29
|
toolCallId: string;
|
|
27
30
|
/** The read file, resolved against the session's working directory. */
|
|
28
31
|
file: string;
|
|
29
|
-
/** First file line of the
|
|
32
|
+
/** First file line of the window and its line count. */
|
|
30
33
|
start: number;
|
|
31
34
|
lines: number;
|
|
35
|
+
/** 0-based position of the window's first line in the original; absent (0) in states persisted before windows. */
|
|
36
|
+
at?: number;
|
|
32
37
|
/** `original.url`: the session artifact holding the original text. */
|
|
33
38
|
url: string | null;
|
|
34
39
|
}
|
|
@@ -91,39 +96,66 @@ export interface SpotlightShapeRow {
|
|
|
91
96
|
original: SpotlightOriginalFacts | null;
|
|
92
97
|
/** Artifact ids the result names (its text's `artifact://N` plus `original.url`); null before the result lands. */
|
|
93
98
|
artifacts: number[] | null;
|
|
94
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* Spotlight's own usage, from the shape entry; null before it lands. `failureCauses` counts failed calls by cause
|
|
101
|
+
* (`no_credential`, `timeout`, …); null when none failed or the entry predates it.
|
|
102
|
+
*/
|
|
95
103
|
spotlight: {
|
|
96
104
|
calls: number;
|
|
97
105
|
failures: number;
|
|
106
|
+
failureCauses: Record<string, number> | null;
|
|
98
107
|
ms: number;
|
|
99
108
|
costUsd: number;
|
|
100
109
|
} | null;
|
|
101
110
|
/** Wall time shaping took, from the shape entry. */
|
|
102
111
|
shapeMs: number | null;
|
|
103
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* One window of an original (`details.spotlight.original.windows`, else the one window the original is): the lines of
|
|
115
|
+
* one read it shows.
|
|
116
|
+
*/
|
|
117
|
+
export interface SpotlightWindowFacts {
|
|
118
|
+
/** The file it shows; null for text no file names. */
|
|
119
|
+
path: string | null;
|
|
120
|
+
/** Line number of its first line (1-based file line for reads, else 1). */
|
|
121
|
+
start: number;
|
|
122
|
+
lines: number;
|
|
123
|
+
/** 0-based position of its first line in the original. */
|
|
124
|
+
at: number;
|
|
125
|
+
/** Hidden absolute line ranges (numbered from {@link start}), inclusive: the window minus the kept ranges. */
|
|
126
|
+
hidden: [number, number][];
|
|
127
|
+
/**
|
|
128
|
+
* A list read's part read its file whole (no line selector): a tail of the file lies in it. Always false for a single
|
|
129
|
+
* window, whose call target tells.
|
|
130
|
+
*/
|
|
131
|
+
wholeFile: boolean;
|
|
132
|
+
}
|
|
104
133
|
export interface SpotlightOriginalFacts {
|
|
105
134
|
url: string | null;
|
|
135
|
+
/** The single window's file, start and hidden lines; of a multi-window original null, 1 and its hidden positions. */
|
|
106
136
|
path: string | null;
|
|
107
|
-
/** First original line of the window (1-based file line for reads, else 1). */
|
|
108
137
|
start: number;
|
|
109
138
|
lines: number;
|
|
110
|
-
/** Hidden absolute line ranges, inclusive: the window minus the kept ranges. */
|
|
111
139
|
hidden: [number, number][];
|
|
112
140
|
hiddenLines: number;
|
|
141
|
+
/** The windows it is made of, in order: one for an original without `windows`. */
|
|
142
|
+
windows: SpotlightWindowFacts[];
|
|
113
143
|
/** Spotlight's per-line heat (`0`–`9`, `-` unscored) over the first lines; null when the trace has none. */
|
|
114
144
|
heat: string | null;
|
|
115
145
|
/** Kept runs, 1-based positions in the original (of a held-out result: what the cut would have kept). */
|
|
116
146
|
kept: [number, number][];
|
|
117
147
|
}
|
|
118
148
|
/**
|
|
119
|
-
* `spotlight_needs` row (merged on upsert): original lines (1-based positions in the original) a shaped read's
|
|
120
|
-
* calls needed. Ranges of later parses are added to the stored ones; `open` is the latest.
|
|
149
|
+
* `spotlight_needs` row (merged on upsert): original lines (1-based positions in the whole original) a shaped read's
|
|
150
|
+
* later calls needed. Ranges of later parses are added to the stored ones; `open` is the latest. One row per call:
|
|
151
|
+
* `file` is the read's file, of a `;`/`,` list read the file of its first window that shows one (the first row
|
|
152
|
+
* stored keeps it).
|
|
121
153
|
*/
|
|
122
154
|
export interface SpotlightNeedRow {
|
|
123
155
|
sessionFile: string;
|
|
124
156
|
toolCallId: string;
|
|
125
157
|
file: string;
|
|
126
|
-
/** Still collecting: no edit, whole-file read or later shaped read
|
|
158
|
+
/** Still collecting: some window's file has no edit, whole-file read or later shaped read yet. */
|
|
127
159
|
open: boolean;
|
|
128
160
|
/** Lines later `read` selections covered. */
|
|
129
161
|
reread: [number, number][];
|
|
@@ -207,7 +239,7 @@ export interface ReadSelection {
|
|
|
207
239
|
export declare function parseReadSelection(target: string): ReadSelection;
|
|
208
240
|
/** A read selection's lines; null for the whole file. */
|
|
209
241
|
export declare function selectedLines(selection: ReadSelection): [number, number][] | null;
|
|
210
|
-
/** A path as written, resolved against the session's working directory (URLs
|
|
242
|
+
/** A path as written, resolved and normalized against the session's working directory (URLs kept). */
|
|
211
243
|
export declare function resolveReadPath(target: string, cwd: string | null): string;
|
|
212
244
|
/** One `*** Find` block of an `edit` input and the file its section edits (null: the call's `path`). */
|
|
213
245
|
export interface EditFindBlock {
|
|
@@ -228,8 +260,15 @@ export declare function locateFind(original: readonly string[], find: readonly s
|
|
|
228
260
|
export declare function mergeRanges(ranges: readonly (readonly [number, number])[]): [number, number][];
|
|
229
261
|
/** Hidden absolute ranges of a window `[start, start + lines - 1]` whose kept ranges are 1-based within it. */
|
|
230
262
|
export declare function hiddenRanges(start: number, lines: number, kept: readonly [number, number][]): [number, number][];
|
|
263
|
+
/** Ranges of 1-based original positions clipped to a window (`at + 1 … at + lines`), renumbered 1-based within it. */
|
|
264
|
+
export declare function windowRanges(ranges: readonly [number, number][], at: number, lines: number): [number, number][];
|
|
231
265
|
/** The row a `spotlight:shape` entry's data describes, or null when it names no call. */
|
|
232
266
|
export declare function shapeFromEntry(sessionFile: string, data: Record<string, unknown>, timestamp: number): SpotlightShapeRow | null;
|
|
267
|
+
/**
|
|
268
|
+
* Failed calls by cause, keeping positive finite counts; null when none is left. Normalizes both a shape entry's
|
|
269
|
+
* `failureCauses` at ingest and the decoded `sp_failure_causes` column at aggregation.
|
|
270
|
+
*/
|
|
271
|
+
export declare function parseFailureCauses(value: unknown): Record<string, number> | null;
|
|
233
272
|
/** The row a result message's `details.spotlight` describes, or null when it carries none. */
|
|
234
273
|
export declare function shapeFromDetails(sessionFile: string, toolCallId: string, details: unknown, text: string, timestamp: number): SpotlightShapeRow | null;
|
|
235
274
|
/**
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds one Spotlight dashboard for the stats server, then is terminated. A build reads every experiment session and
|
|
3
|
+
* takes seconds; on the server's thread it held every other request and ingest until it ended.
|
|
4
|
+
*
|
|
5
|
+
* The worker opens the database read-only and builds inside one read transaction, so the payload is a single snapshot
|
|
6
|
+
* while the server keeps ingesting. A `{ kind: "ping" }` request replies `{ ok: true, kind: "pong" }` for
|
|
7
|
+
* `smokeTestSpotlightWorker`, which proves the worker loads in compiled binaries and the npm bundle.
|
|
8
|
+
*/
|
|
9
|
+
export type SpotlightWorkerRequest = {
|
|
10
|
+
kind: "build";
|
|
11
|
+
dbPath: string;
|
|
12
|
+
range: string | null;
|
|
13
|
+
agent: string | null;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "ping";
|
|
16
|
+
};
|
|
17
|
+
export type SpotlightWorkerResponse = {
|
|
18
|
+
ok: true;
|
|
19
|
+
kind: "build";
|
|
20
|
+
json: string;
|
|
21
|
+
} | {
|
|
22
|
+
ok: true;
|
|
23
|
+
kind: "pong";
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
package/dist/types/trace.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class TracePathError extends Error {
|
|
|
17
17
|
* span assembly changes so browsers don't revalidate stale cached bodies
|
|
18
18
|
* against an unchanged transcript mtime.
|
|
19
19
|
*/
|
|
20
|
-
export declare const TRACE_ETAG_VERSION =
|
|
20
|
+
export declare const TRACE_ETAG_VERSION = 6;
|
|
21
21
|
/** Freshness of a root trace: root mtime+size plus the child-transcript set fingerprint. */
|
|
22
22
|
export interface TraceFingerprint {
|
|
23
23
|
rootMtimeMs: number;
|
|
@@ -73,6 +73,12 @@ export interface SubSessionTraceSnapshot extends SessionTraceSnapshot {
|
|
|
73
73
|
export declare function buildSessionTraceFromSnapshots(root: SessionTraceSnapshot, subSessions?: Readonly<Record<string, SubSessionTraceSnapshot>>): SessionTrace;
|
|
74
74
|
/** Fetch one full journal entry by id from a transcript, for the span drawer. */
|
|
75
75
|
export declare function getTraceEntry(fileParam: string, entryId: string): Promise<SessionEntry | null>;
|
|
76
|
+
export interface SessionMetadata {
|
|
77
|
+
title: string | null;
|
|
78
|
+
cwd: string | null;
|
|
79
|
+
}
|
|
80
|
+
/** Read list metadata from the fixed title slot and session header. */
|
|
81
|
+
export declare function readSessionMetadata(file: string): Promise<SessionMetadata>;
|
|
76
82
|
/**
|
|
77
83
|
* List root sessions for the Traces section, folding every synced child
|
|
78
84
|
* transcript (subagents, advisors) into its root row.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only project tracking snapshots for the stats dashboard.
|
|
3
|
+
*
|
|
4
|
+
* The tracking documents under `<project>/.zeta/tracking/` are written by the
|
|
5
|
+
* coding agent's `tracking_update` tool; this module only reads them. It does
|
|
6
|
+
* not import the agent package (types or implementation) and never creates,
|
|
7
|
+
* repairs, or rewrites a tracking file.
|
|
8
|
+
*
|
|
9
|
+
* Reads are bounded per file and per directory, and every missing, truncated,
|
|
10
|
+
* malformed or unreadable input is reported as such instead of being smoothed
|
|
11
|
+
* into a plausible-looking status.
|
|
12
|
+
*/
|
|
13
|
+
import type { TrackingSnapshot } from "./shared-types.js";
|
|
14
|
+
/** Upper bounds for one snapshot; larger files are read partially and say so. */
|
|
15
|
+
export declare const TRACKING_READ_LIMITS: {
|
|
16
|
+
readonly statusBytes: number;
|
|
17
|
+
readonly indexBytes: number;
|
|
18
|
+
readonly sessionBytes: number;
|
|
19
|
+
readonly sessionFiles: 50;
|
|
20
|
+
readonly actionBytes: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Exact registry label. The label is an opaque database key, never a path, so
|
|
24
|
+
* the caller cannot smuggle traversal into it; the server resolves the label to
|
|
25
|
+
* a session-header cwd before calling {@link readTrackingSnapshot}.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isTrackableProject(project: string, known: readonly string[]): boolean;
|
|
28
|
+
/** Read one project's tracking documents without writing anything. */
|
|
29
|
+
export declare function readTrackingSnapshot(cwd: string, project?: string): Promise<TrackingSnapshot>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -226,11 +226,11 @@ export interface AssistantTextStats {
|
|
|
226
226
|
prose: string;
|
|
227
227
|
}
|
|
228
228
|
/**
|
|
229
|
-
* Pair emitted by the parser
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* applies the link to the persisted `user_messages` row so it
|
|
233
|
-
* up in the "unknown" model bucket.
|
|
229
|
+
* Pair emitted by the parser for each assistant message that answers a user
|
|
230
|
+
* message: the first assistant message descending from it through non-message
|
|
231
|
+
* entries, whether the user message was parsed in this pass or an earlier one.
|
|
232
|
+
* The aggregator applies the link to the persisted `user_messages` row so it
|
|
233
|
+
* stops showing up in the "unknown" model bucket.
|
|
234
234
|
*/
|
|
235
235
|
export interface UserMessageLink {
|
|
236
236
|
sessionFile: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@linxiraos/pi-stats",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.11",
|
|
5
5
|
"description": "Local observability dashboard for omp AI usage statistics",
|
|
6
6
|
"homepage": "https://linxira-os.github.io/zeta/",
|
|
7
7
|
"author": "Linxira-OS",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@linxiraos/pi-ai": "1.5.
|
|
43
|
-
"@linxiraos/pi-catalog": "1.5.
|
|
44
|
-
"@linxiraos/pi-utils": "1.5.
|
|
42
|
+
"@linxiraos/pi-ai": "1.5.11",
|
|
43
|
+
"@linxiraos/pi-catalog": "1.5.11",
|
|
44
|
+
"@linxiraos/pi-utils": "1.5.11",
|
|
45
45
|
"lucide-react": "^1.24.0",
|
|
46
46
|
"react": "19.2.7",
|
|
47
47
|
"react-dom": "19.2.7"
|
package/src/aggregator.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
markSessionBackfillsComplete,
|
|
16
16
|
type ParsedSession,
|
|
17
17
|
prepareSessionSync,
|
|
18
|
+
pruneOrphanSessions,
|
|
18
19
|
} from "./db";
|
|
19
20
|
import {
|
|
20
21
|
getSessionEntry,
|
|
@@ -31,6 +32,7 @@ import {
|
|
|
31
32
|
getOverallStats,
|
|
32
33
|
getProviderHourlyBurn,
|
|
33
34
|
getProviderTimeSeries,
|
|
35
|
+
getProjectFolders,
|
|
34
36
|
getStatsByAgentType,
|
|
35
37
|
getStatsByFolder,
|
|
36
38
|
getStatsByModel,
|
|
@@ -309,6 +311,11 @@ async function syncAllSessionsLocked(
|
|
|
309
311
|
const replay = prepareSessionSync();
|
|
310
312
|
|
|
311
313
|
const files = opts?.files ?? (await orderForIngest(await listAllSessionFiles()));
|
|
314
|
+
// A full sync knows every live transcript, so rows for deleted files are
|
|
315
|
+
// stale: prune them before parsing, otherwise an orphaned row keeps
|
|
316
|
+
// inflating aggregates (and a re-created transcript doubles the usage).
|
|
317
|
+
// A targeted sync only knows its own files and must never prune the rest.
|
|
318
|
+
if (!opts?.files) pruneOrphanSessions(files);
|
|
312
319
|
let totalProcessed = 0;
|
|
313
320
|
let totalChanges = 0;
|
|
314
321
|
let filesProcessed = 0;
|
|
@@ -578,6 +585,15 @@ export async function getFolderStats(range?: string | null): Promise<FolderStats
|
|
|
578
585
|
return getStatsByFolder(getTimeRangeConfig(range).cutoff, FOLDER_LIMIT);
|
|
579
586
|
}
|
|
580
587
|
|
|
588
|
+
/**
|
|
589
|
+
* Project folders known to the stats registry. Tracking reads are scoped to
|
|
590
|
+
* this exact set: a caller cannot point the dashboard at an arbitrary path.
|
|
591
|
+
*/
|
|
592
|
+
export async function getKnownProjectFolders(): Promise<string[]> {
|
|
593
|
+
await initDb();
|
|
594
|
+
return getProjectFolders();
|
|
595
|
+
}
|
|
596
|
+
|
|
581
597
|
export async function getRecentRequests(limit?: number): Promise<MessageStats[]> {
|
|
582
598
|
await initDb();
|
|
583
599
|
return dbGetRecentRequests(limit);
|
package/src/client/App.tsx
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
RequestsRoute,
|
|
17
17
|
SpotlightRoute,
|
|
18
18
|
ToolsRoute,
|
|
19
|
+
TrackingRoute,
|
|
19
20
|
TracesRoute,
|
|
20
21
|
} from "./routes";
|
|
21
22
|
import { RequestDrawer } from "./ui/RequestDrawer";
|
|
@@ -65,6 +66,8 @@ function Dashboard() {
|
|
|
65
66
|
return <FrustrationRoute active={active} range={range} />;
|
|
66
67
|
case "projects":
|
|
67
68
|
return <ProjectsRoute active={active} range={range} />;
|
|
69
|
+
case "tracking":
|
|
70
|
+
return <TrackingRoute active={active} />;
|
|
68
71
|
case "gain":
|
|
69
72
|
return <GainRoute active={active} range={range} />;
|
|
70
73
|
case "spotlight":
|
package/src/client/api.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
SpotlightSessionContext,
|
|
20
20
|
TimeRange,
|
|
21
21
|
ToolDashboardStats,
|
|
22
|
+
TrackingSnapshot,
|
|
22
23
|
} from "./types";
|
|
23
24
|
|
|
24
25
|
const API_BASE = "/api";
|
|
@@ -177,6 +178,16 @@ export async function getFolderStats(range: TimeRange = "24h", signal?: AbortSig
|
|
|
177
178
|
return fetchJson<FolderStats[]>(`${API_BASE}/stats/folders?range=${encodeURIComponent(range)}`, { signal });
|
|
178
179
|
}
|
|
179
180
|
|
|
181
|
+
/** Project folders in the stats registry, most recently active first. */
|
|
182
|
+
export async function getTrackingProjects(signal?: AbortSignal): Promise<{ projects: string[] }> {
|
|
183
|
+
return fetchJson<{ projects: string[] }>(`${API_BASE}/tracking/projects`, { signal });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Read-only tracking snapshot for one project folder from the stats registry. */
|
|
187
|
+
export async function getTrackingSnapshot(project: string, signal?: AbortSignal): Promise<TrackingSnapshot> {
|
|
188
|
+
return fetchJson<TrackingSnapshot>(`${API_BASE}/tracking?project=${encodeURIComponent(project)}`, { signal });
|
|
189
|
+
}
|
|
190
|
+
|
|
180
191
|
export async function getGainDashboardStats(
|
|
181
192
|
range: TimeRange = "24h",
|
|
182
193
|
project?: string | null,
|
package/src/client/app/nav.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Activity,
|
|
3
3
|
CircleAlert,
|
|
4
|
+
ClipboardList,
|
|
4
5
|
Coins,
|
|
5
6
|
Cpu,
|
|
6
7
|
FolderGit2,
|
|
@@ -26,6 +27,7 @@ export type DashboardSection =
|
|
|
26
27
|
| "tools"
|
|
27
28
|
| "frustration"
|
|
28
29
|
| "projects"
|
|
30
|
+
| "tracking"
|
|
29
31
|
| "gain"
|
|
30
32
|
| "spotlight";
|
|
31
33
|
|
|
@@ -69,6 +71,7 @@ export const NAV: readonly NavGroup[] = [
|
|
|
69
71
|
{ id: "tools", labelKey: "nav.tools", icon: Wrench, hotkey: "l" },
|
|
70
72
|
{ id: "frustration", labelKey: "nav.frustration", icon: Frown, hotkey: "f" },
|
|
71
73
|
{ id: "projects", labelKey: "nav.projects", icon: FolderGit2, hotkey: "j" },
|
|
74
|
+
{ id: "tracking", labelKey: "nav.tracking", icon: ClipboardList, hotkey: "k" },
|
|
72
75
|
{ id: "gain", labelKey: "nav.gain", icon: Sparkles, hotkey: "g" },
|
|
73
76
|
{ id: "spotlight", labelKey: "nav.spotlight", icon: ScanSearch, hotkey: "s" },
|
|
74
77
|
],
|
|
@@ -157,21 +157,21 @@ export function formatTimestamp(timestamp: number): string {
|
|
|
157
157
|
return formatter.format(timestamp);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
const
|
|
160
|
+
const localDayFormatters = new Map<string, Intl.DateTimeFormat>();
|
|
161
161
|
|
|
162
|
-
/**
|
|
163
|
-
export function
|
|
162
|
+
/** Local day label for the cost/gain charts; `long` adds the weekday and year. */
|
|
163
|
+
export function formatLocalDay(timestamp: number, long = false): string {
|
|
164
164
|
const locale = getLocale();
|
|
165
165
|
const key = `${locale}:${long ? "long" : "short"}`;
|
|
166
|
-
let formatter =
|
|
166
|
+
let formatter = localDayFormatters.get(key);
|
|
167
167
|
if (!formatter) {
|
|
168
168
|
formatter = new Intl.DateTimeFormat(
|
|
169
169
|
locale,
|
|
170
170
|
long
|
|
171
|
-
? { weekday: "short", month: "short", day: "numeric", year: "numeric"
|
|
172
|
-
: { month: "short", day: "numeric"
|
|
171
|
+
? { weekday: "short", month: "short", day: "numeric", year: "numeric" }
|
|
172
|
+
: { month: "short", day: "numeric" },
|
|
173
173
|
);
|
|
174
|
-
|
|
174
|
+
localDayFormatters.set(key, formatter);
|
|
175
175
|
}
|
|
176
176
|
return formatter.format(timestamp);
|
|
177
177
|
}
|
package/src/client/data/range.ts
CHANGED
|
@@ -74,10 +74,11 @@ export function formatTick(timestamp: number, bucketMs: number): string {
|
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* Contiguous, ascending bucket starts covering `range`, aligned like the
|
|
77
|
-
* server's
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
77
|
+
* server's series buckets: day buckets start at local midnight (a DST day is
|
|
78
|
+
* 23 or 25 hours long), shorter buckets at `(timestamp / bucketMs) * bucketMs`.
|
|
79
|
+
* For all time the axis starts at the earliest data point, so gaps between
|
|
80
|
+
* sessions still render as zeros; it is capped at {@link MAX_BUCKETS} so a
|
|
81
|
+
* stray epoch-zero timestamp cannot explode the axis into decades of empty days.
|
|
81
82
|
*/
|
|
82
83
|
export function bucketAxis(
|
|
83
84
|
range: TimeRange,
|
|
@@ -85,18 +86,30 @@ export function bucketAxis(
|
|
|
85
86
|
bucketMs = RANGE_META[range].bucketMs,
|
|
86
87
|
now = Date.now(),
|
|
87
88
|
): number[] {
|
|
88
|
-
const
|
|
89
|
+
const daily = bucketMs === DAY_MS;
|
|
90
|
+
const align = (ts: number) => (daily ? new Date(ts).setHours(0, 0, 0, 0) : Math.floor(ts / bucketMs) * bucketMs);
|
|
91
|
+
const last = align(now);
|
|
89
92
|
const span = RANGE_META[range].spanMs;
|
|
90
93
|
let first: number;
|
|
91
94
|
if (span !== null) {
|
|
92
|
-
first =
|
|
95
|
+
first = align(now - span);
|
|
93
96
|
} else {
|
|
94
97
|
first = last;
|
|
95
98
|
for (const ts of dataTimestamps) if (ts < first) first = ts;
|
|
96
|
-
first =
|
|
99
|
+
first = align(first);
|
|
97
100
|
}
|
|
98
|
-
first = Math.max(first, last - (MAX_BUCKETS - 1) * bucketMs);
|
|
101
|
+
first = Math.max(first, align(last - (MAX_BUCKETS - 1) * bucketMs));
|
|
99
102
|
const buckets: number[] = [];
|
|
100
|
-
for (let t = first; t <= last;
|
|
103
|
+
for (let t = first; t <= last;) {
|
|
104
|
+
buckets.push(t);
|
|
105
|
+
if (daily) {
|
|
106
|
+
const next = new Date(t);
|
|
107
|
+
next.setDate(next.getDate() + 1);
|
|
108
|
+
// Re-align: on a day whose midnight DST skips, `t` is 01:00 and would carry forward.
|
|
109
|
+
t = next.setHours(0, 0, 0, 0);
|
|
110
|
+
} else {
|
|
111
|
+
t += bucketMs;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
101
114
|
return buckets;
|
|
102
115
|
}
|