pi-evals 0.2.0 → 0.3.0
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 +6 -0
- package/README.md +17 -7
- package/dist/build.js +4 -3
- package/dist/cli.js +2 -2
- package/dist/coverage.js +8 -1
- package/dist/findings.js +50 -0
- package/dist/index.js +14 -7
- package/dist/model.js +21 -10
- package/dist/ops.js +52 -22
- package/dist/query.js +32 -13
- package/dist/ranges.js +14 -0
- package/dist/render.js +14 -5
- package/dist/report/findings.js +12 -1
- package/dist/report/sections.js +3 -3
- package/dist/report/strip.js +42 -0
- package/dist/report/style.js +9 -1
- package/dist/report/timeline.js +5 -14
- package/dist/report/week.js +21 -13
- package/dist/trends.js +58 -0
- package/docs/design.md +15 -0
- package/package.json +5 -2
- package/scripts/change-impact.mjs +18 -0
- package/scripts/package-errors.mjs +10 -0
- package/scripts/query-lib.mjs +36 -0
- package/scripts/skill-days.mjs +9 -0
- package/skills/analyzing-evals/SKILL.md +21 -0
- package/src/aggregate.ts +3 -0
- package/src/build.ts +4 -3
- package/src/cli.ts +2 -2
- package/src/coverage.ts +8 -1
- package/src/findings.ts +49 -0
- package/src/index.ts +14 -9
- package/src/model.ts +22 -10
- package/src/ops.ts +49 -22
- package/src/query.ts +29 -13
- package/src/ranges.ts +15 -0
- package/src/render.ts +14 -5
- package/src/report/findings.ts +19 -1
- package/src/report/sections.ts +3 -5
- package/src/report/strip.ts +40 -0
- package/src/report/style.ts +9 -1
- package/src/report/timeline.ts +6 -22
- package/src/report/week.ts +21 -17
- package/src/trends.ts +61 -0
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { existsSync } from "node:fs";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import { Type } from "typebox";
|
|
9
|
+
import { scriptsDir } from "./findings.ts";
|
|
9
10
|
import { observe } from "./observer.ts";
|
|
10
11
|
import { context, mark, reportPath, runReport, statusText } from "./ops.ts";
|
|
11
12
|
import { query, type View, VIEWS } from "./query.ts";
|
|
@@ -22,12 +23,13 @@ export function cliPath(): { cmd: string; args: string[] } | undefined {
|
|
|
22
23
|
return found ? { cmd: process.execPath, args: [found] } : undefined;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
const SUBCOMMANDS = ["status", "extract", "report", "mark"];
|
|
26
|
+
const SUBCOMMANDS = ["status", "findings", "extract", "report", "mark"];
|
|
26
27
|
|
|
27
|
-
function parseFlags(args: string[])
|
|
28
|
-
const out: { since?: string; project?: string; rest: string[] } = { rest: [] };
|
|
28
|
+
function parseFlags(args: string[]) {
|
|
29
|
+
const out: { since?: string; days?: number; project?: string; rest: string[] } = { rest: [] };
|
|
29
30
|
for (let i = 0; i < args.length; i++) {
|
|
30
31
|
if (args[i] === "--since") out.since = args[++i];
|
|
32
|
+
else if (args[i] === "--days") out.days = Number(args[++i]);
|
|
31
33
|
else if (args[i] === "--project") out.project = args[++i];
|
|
32
34
|
else out.rest.push(args[i]);
|
|
33
35
|
}
|
|
@@ -94,7 +96,7 @@ export function createEvals(options: { env?: Env; spawnExtract?: typeof spawn; n
|
|
|
94
96
|
};
|
|
95
97
|
|
|
96
98
|
pi.registerCommand("evals", {
|
|
97
|
-
description: "Usage and process records: /evals [status|extract|report|mark <note>]",
|
|
99
|
+
description: "Usage and process records: /evals [status|findings|extract|report|mark <note>]",
|
|
98
100
|
getArgumentCompletions: (prefix: string) => {
|
|
99
101
|
const items = SUBCOMMANDS.filter((s) => s.startsWith(prefix)).map((s) => ({ value: s, label: s }));
|
|
100
102
|
return items.length ? items : null;
|
|
@@ -104,6 +106,9 @@ export function createEvals(options: { env?: Env; spawnExtract?: typeof spawn; n
|
|
|
104
106
|
const sub = words[0] ?? "status";
|
|
105
107
|
if (sub === "status") {
|
|
106
108
|
ctx.ui.notify(statusText(env), "info");
|
|
109
|
+
} else if (sub === "findings") {
|
|
110
|
+
const flags = parseFlags(words.slice(1));
|
|
111
|
+
ctx.ui.notify(query("findings", { env, ...flags }), "info");
|
|
107
112
|
} else if (sub === "extract") {
|
|
108
113
|
if (running) {
|
|
109
114
|
ctx.ui.notify("pi-evals: an extract is already running.", "warning");
|
|
@@ -120,7 +125,7 @@ export function createEvals(options: { env?: Env; spawnExtract?: typeof spawn; n
|
|
|
120
125
|
});
|
|
121
126
|
} else if (sub === "report") {
|
|
122
127
|
const flags = parseFlags(words.slice(1));
|
|
123
|
-
const out = runReport({ env, filter:
|
|
128
|
+
const out = runReport({ env, filter: flags });
|
|
124
129
|
ctx.ui.notify(out ? `pi-evals report: ${out.html}\nmodel: ${out.json}` : "pi-evals: nothing extracted yet; run /evals extract first.", out ? "info" : "warning");
|
|
125
130
|
} else if (sub === "mark") {
|
|
126
131
|
const text = words.slice(1).join(" ").trim();
|
|
@@ -139,11 +144,11 @@ export function createEvals(options: { env?: Env; spawnExtract?: typeof spawn; n
|
|
|
139
144
|
pi.registerTool({
|
|
140
145
|
name: "evals_query",
|
|
141
146
|
label: "Evals Query",
|
|
142
|
-
description: "
|
|
143
|
-
promptSnippet: "
|
|
147
|
+
description: "Start with findings for agent activity and changes; use one detail view for counts, cost or coverage.",
|
|
148
|
+
promptSnippet: "Analyze agent activity: query findings first, then one detail view",
|
|
144
149
|
parameters: Type.Object({
|
|
145
150
|
view: Type.Unsafe<View>({ type: "string", enum: [...VIEWS], description: "Which summary" }),
|
|
146
|
-
since: Type.Optional(Type.String({ description: "YYYY-MM-DD; default
|
|
151
|
+
since: Type.Optional(Type.String({ description: "YYYY-MM-DD; default last 30 UTC dates through extraction" })),
|
|
147
152
|
project: Type.Optional(Type.String({ description: "Project key, e.g. a repo name" })),
|
|
148
153
|
}),
|
|
149
154
|
async execute(_id, params) {
|
|
@@ -151,7 +156,7 @@ export function createEvals(options: { env?: Env; spawnExtract?: typeof spawn; n
|
|
|
151
156
|
if (!VIEWS.includes(view)) throw new Error(`Unknown view "${view}". Views: ${VIEWS.join(", ")}.`);
|
|
152
157
|
if (params.since && !/^\d{4}-\d{2}-\d{2}$/.test(params.since)) throw new Error("since must be YYYY-MM-DD.");
|
|
153
158
|
const text = query(view, { since: params.since, project: params.project, env });
|
|
154
|
-
return { content: [{ type: "text", text }], details: { view, report: reportPath(env) } };
|
|
159
|
+
return { content: [{ type: "text", text }], details: { view, scriptsDir, report: reportPath(env) } };
|
|
155
160
|
},
|
|
156
161
|
});
|
|
157
162
|
};
|
package/src/model.ts
CHANGED
|
@@ -10,7 +10,8 @@ import type { Coverage } from "./coverage.ts";
|
|
|
10
10
|
import { DETECTORS, ERA_START } from "./detectors.ts";
|
|
11
11
|
import { CHANGE_KIND_META, DETECTOR_META, METRICS, NOTICE_META } from "./meta.ts";
|
|
12
12
|
import { staticOwner } from "./owners.ts";
|
|
13
|
-
import {
|
|
13
|
+
import { weeklyRises } from "./trends.ts";
|
|
14
|
+
import { traceId } from "./schema.ts";
|
|
14
15
|
|
|
15
16
|
export const SMALL_SAMPLE = 20;
|
|
16
17
|
/** Data older than this (hours) is reported as stale. */
|
|
@@ -174,7 +175,7 @@ interface LabelRow {
|
|
|
174
175
|
label: string;
|
|
175
176
|
}
|
|
176
177
|
|
|
177
|
-
function labelsJoin(labelsFile: string, evalsFile: string) {
|
|
178
|
+
function labelsJoin(labelsFile: string, evalsFile: string, sessionIds?: Set<string>) {
|
|
178
179
|
if (!existsSync(labelsFile)) return { present: false, n: 0, agreement: [] as { detector: string; n: number; agree: number; rate: Rate }[] };
|
|
179
180
|
const codeLabels = existsSync(evalsFile) ? (JSON.parse(readFileSync(evalsFile, "utf8")) as Record<string, Record<string, string>>) : {};
|
|
180
181
|
const rows: LabelRow[] = readFileSync(labelsFile, "utf8")
|
|
@@ -188,7 +189,10 @@ function labelsJoin(labelsFile: string, evalsFile: string) {
|
|
|
188
189
|
}
|
|
189
190
|
});
|
|
190
191
|
const by = new Map<string, { n: number; agree: number }>();
|
|
192
|
+
let n = 0;
|
|
191
193
|
for (const row of rows) {
|
|
194
|
+
if (sessionIds && !sessionIds.has(traceId(row.session_id, "labels"))) continue;
|
|
195
|
+
n++;
|
|
192
196
|
const code = codeLabels[row.session_id]?.[row.evaluation_name];
|
|
193
197
|
if (!code || code === "na") continue;
|
|
194
198
|
const t = by.get(row.evaluation_name) ?? { n: 0, agree: 0 };
|
|
@@ -196,13 +200,15 @@ function labelsJoin(labelsFile: string, evalsFile: string) {
|
|
|
196
200
|
if (code === row.label) t.agree += 1;
|
|
197
201
|
by.set(row.evaluation_name, t);
|
|
198
202
|
}
|
|
199
|
-
return { present: true, n
|
|
203
|
+
return { present: true, n, agreement: [...by].map(([detector, t]) => ({ detector, n: t.n, agree: t.agree, rate: rate(t.agree, t.n) })) };
|
|
200
204
|
}
|
|
201
205
|
|
|
202
206
|
export function buildModel(options: {
|
|
203
207
|
index: DaysIndex;
|
|
204
208
|
rows: SessionRow[];
|
|
205
209
|
changes: Change[];
|
|
210
|
+
/** Already computed for the same index, project and comparison settings. */
|
|
211
|
+
comparisons?: (Change & { impact: ReturnType<typeof impactFromRows> | null })[];
|
|
206
212
|
filter: Filter;
|
|
207
213
|
windowDays: number;
|
|
208
214
|
labelsFile: string;
|
|
@@ -233,6 +239,11 @@ export function buildModel(options: {
|
|
|
233
239
|
const byProject = [...projectSkills.values()].sort((a, b) => b.loads - a.loads);
|
|
234
240
|
const projectRows = filter.project ? options.rows.filter((r) => r.p === filter.project) : options.rows;
|
|
235
241
|
const owner = (tool: string) => ownerFor(index, tool);
|
|
242
|
+
const inRange = (at: string) => (!filter.since || at.slice(0, 10) >= filter.since) && (!filter.until || at.slice(0, 10) <= filter.until);
|
|
243
|
+
const selected = projectRows.filter(r => inRange(r.s)), children = selected.filter(r => r.k);
|
|
244
|
+
const scoped = Boolean(filter.since || filter.until || filter.project);
|
|
245
|
+
const hasSessionIds = selected.every(r => r.id !== undefined);
|
|
246
|
+
const labelIds = scoped && existsSync(options.labelsFile) ? new Set(selected.flatMap(r => r.id ? [r.id] : [])) : undefined;
|
|
236
247
|
const calls = Object.values(total.tools).reduce((s, t) => s + t.calls, 0);
|
|
237
248
|
const errors = Object.values(total.tools).reduce((s, t) => s + t.errors, 0);
|
|
238
249
|
const tokens = total.usage.input + total.usage.output + total.usage.cacheRead + total.usage.cacheWrite;
|
|
@@ -246,11 +257,12 @@ export function buildModel(options: {
|
|
|
246
257
|
versions.set(name, list);
|
|
247
258
|
}
|
|
248
259
|
const sortedChanges = [...options.changes].sort((a, b) => a.at.localeCompare(b.at));
|
|
249
|
-
const
|
|
260
|
+
const earliest = [days[0], sortedChanges.find(c => inRange(c.at))?.at.slice(0, 10)].filter(Boolean).sort()[0];
|
|
250
261
|
return {
|
|
251
262
|
v: 1 as const,
|
|
252
263
|
generated: now.toISOString(),
|
|
253
|
-
|
|
264
|
+
weekly: weeklyRises(index, filter.since ?? earliest, filter.project),
|
|
265
|
+
window: { since: filter.since ?? earliest ?? null, until: filter.until ?? days.at(-1) ?? null, days: days.length, project: filter.project ?? null },
|
|
254
266
|
freshness: { lastExtract: lastExtract ?? null, built: index.built, stale: ageHours > STALE_HOURS, ageHours: Number.isFinite(ageHours) ? round(ageHours, 1) : null },
|
|
255
267
|
meta: { metrics: METRICS, detectors: DETECTOR_META, notices: NOTICE_META, changeKinds: CHANGE_KIND_META },
|
|
256
268
|
totals: {
|
|
@@ -308,8 +320,8 @@ export function buildModel(options: {
|
|
|
308
320
|
costByRole: Object.entries(total.subagentCost)
|
|
309
321
|
.map(([role, cost]) => ({ role, cost: round(cost, 2) }))
|
|
310
322
|
.sort((a, b) => b.cost - a.cost),
|
|
311
|
-
linked: index.sessions.linked,
|
|
312
|
-
subagentTotal: index.sessions.subagent,
|
|
323
|
+
linked: scoped ? (children.every(r => r.linked !== undefined) ? children.filter(r => r.linked).length : null) : index.sessions.linked,
|
|
324
|
+
subagentTotal: scoped ? children.length : index.sessions.subagent,
|
|
313
325
|
},
|
|
314
326
|
process: {
|
|
315
327
|
eraStart: ERA_START,
|
|
@@ -335,10 +347,10 @@ export function buildModel(options: {
|
|
|
335
347
|
.slice(0, 25)
|
|
336
348
|
.map(({ name, cost, sessions }) => ({ skill: name, cost, sessions })),
|
|
337
349
|
},
|
|
338
|
-
changes: sortedChanges
|
|
339
|
-
.filter((c) => (
|
|
350
|
+
changes: options.comparisons?.filter(c => inRange(c.at)) ?? sortedChanges
|
|
351
|
+
.filter((c) => inRange(c.at))
|
|
340
352
|
.map((c) => ({ ...c, impact: index.range.start && c.at > index.range.start ? impactFromRows(projectRows, c, sortedChanges, options.windowDays, index.range, owner) : null })),
|
|
341
|
-
labels: labelsJoin(options.labelsFile, options.sessionEvalsFile),
|
|
353
|
+
labels: { ...labelsJoin(options.labelsFile, options.sessionEvalsFile, labelIds), needsIndex: !!labelIds && !hasSessionIds },
|
|
342
354
|
coverage: options.coverage ?? null,
|
|
343
355
|
};
|
|
344
356
|
}
|
package/src/ops.ts
CHANGED
|
@@ -5,7 +5,8 @@ import { buildIndex, loadIndex, loadRows } from "./build.ts";
|
|
|
5
5
|
import { addMark, readChanges } from "./changes.ts";
|
|
6
6
|
import { coverage } from "./coverage.ts";
|
|
7
7
|
import { extract, loadCheckpoint, type Progress } from "./extract/run.ts";
|
|
8
|
-
import {
|
|
8
|
+
import { PRESETS, type Preset, rangeFilter, suffix } from "./ranges.ts";
|
|
9
|
+
import { buildModel, type Filter, type ReportModel } from "./model.ts";
|
|
9
10
|
import { agentDir, home, layout, loadSettings, stateDir } from "./paths.ts";
|
|
10
11
|
import { renderHtml, type Lang } from "./render.ts";
|
|
11
12
|
|
|
@@ -52,34 +53,60 @@ export function coverageNow(env?: Env, cutDays?: number) {
|
|
|
52
53
|
return coverage(ctx.roots, loadCheckpoint(ctx.layout.checkpoint), cutDays ?? ctx.settings.coverageDays);
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
type RangeInput = Filter & { days?: number };
|
|
57
|
+
function coverageReader(ctx: ReturnType<typeof context>, now: Date) {
|
|
58
|
+
const activity = new Map<string, { files: number; indexed: number }>();
|
|
59
|
+
const cov = coverage(ctx.roots, loadCheckpoint(ctx.layout.checkpoint), ctx.settings.coverageDays, now.getTime(), activity);
|
|
60
|
+
return (filter: Filter) => {
|
|
61
|
+
const inRange = { files: 0, indexed: 0 };
|
|
62
|
+
for (const [day, a] of activity) if ((!filter.since || day >= filter.since) && (!filter.until || day <= filter.until)) {
|
|
63
|
+
inRange.files += a.files; inRange.indexed += a.indexed;
|
|
64
|
+
}
|
|
65
|
+
return { ...cov, inRange };
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function coverageInRange(input: RangeInput, env?: Env) {
|
|
69
|
+
const ctx = context(env), now = new Date(), last = loadIndex(ctx.layout)?.lastExtract;
|
|
70
|
+
const filter = rangeFilter(input, last ?? now.toISOString());
|
|
71
|
+
return { filter, last, coverage: coverageReader(ctx, now)(filter) };
|
|
72
|
+
}
|
|
73
|
+
function snapshot(env?: Env, withCoverage = true) {
|
|
74
|
+
const ctx = context(env), index = loadIndex(ctx.layout);
|
|
75
|
+
if (!index) return;
|
|
76
|
+
const rows = loadRows(ctx.layout), changes = readChanges(ctx.layout.changes), now = new Date();
|
|
77
|
+
const cov = withCoverage ? coverageReader(ctx, now) : undefined;
|
|
78
|
+
return { index, build(input: RangeInput, preset: Preset, comparisons?: ReportModel["changes"]) {
|
|
79
|
+
const filter = rangeFilter(input, index.lastExtract ?? now.toISOString(), preset);
|
|
80
|
+
return buildModel({ index, rows, changes, comparisons, filter, now, windowDays: ctx.settings.impactWindowDays,
|
|
81
|
+
labelsFile: ctx.layout.labels, sessionEvalsFile: ctx.layout.sessionEvals, coverage: cov?.(filter) });
|
|
82
|
+
} };
|
|
83
|
+
}
|
|
84
|
+
export function indexedModel(filter: RangeInput, env?: Env, withCoverage = true) {
|
|
85
|
+
const data = snapshot(env, withCoverage);
|
|
86
|
+
return data && { report: data.build(filter, 30), index: data.index };
|
|
87
|
+
}
|
|
88
|
+
|
|
55
89
|
export function model(filter: Filter, env?: Env, withCoverage = true) {
|
|
56
|
-
|
|
57
|
-
const index = loadIndex(ctx.layout);
|
|
58
|
-
if (!index) return undefined;
|
|
59
|
-
return buildModel({
|
|
60
|
-
index,
|
|
61
|
-
rows: loadRows(ctx.layout),
|
|
62
|
-
changes: readChanges(ctx.layout.changes),
|
|
63
|
-
filter,
|
|
64
|
-
windowDays: ctx.settings.impactWindowDays,
|
|
65
|
-
labelsFile: ctx.layout.labels,
|
|
66
|
-
sessionEvalsFile: ctx.layout.sessionEvals,
|
|
67
|
-
coverage: withCoverage ? coverageNow(env) : undefined,
|
|
68
|
-
});
|
|
90
|
+
return indexedModel(filter, env, withCoverage)?.report;
|
|
69
91
|
}
|
|
70
92
|
|
|
71
93
|
/** Builds the report; returns the HTML path, or undefined when nothing was extracted yet. */
|
|
72
|
-
export function runReport(options: { env?: Env; filter?:
|
|
94
|
+
export function runReport(options: { env?: Env; filter?: RangeInput; outDir?: string; lang?: Lang } = {}): { html: string; json: string } | undefined {
|
|
73
95
|
const ctx = context(options.env);
|
|
74
|
-
const
|
|
75
|
-
if (!
|
|
96
|
+
const data = snapshot(options.env), filter = options.filter ?? {};
|
|
97
|
+
if (!data) return;
|
|
76
98
|
const dir = resolve(options.outDir ?? ctx.layout.reports);
|
|
77
99
|
mkdirSync(dir, { recursive: true });
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
100
|
+
const write = (m: ReportModel, range: Preset | "custom") => {
|
|
101
|
+
const html = join(dir, `report${suffix(range)}.html`), json = join(dir, `model${suffix(range)}.json`);
|
|
102
|
+
writeFileSync(json, JSON.stringify(m, null, 1));
|
|
103
|
+
writeFileSync(html, renderHtml(m, options.lang ?? "zh", range));
|
|
104
|
+
return { html, json };
|
|
105
|
+
};
|
|
106
|
+
if (filter.since || filter.until || filter.days !== undefined) return write(data.build(filter, 30), "custom");
|
|
107
|
+
const all = data.build(filter, "all");
|
|
108
|
+
for (const p of PRESETS) if (p !== 30) write(p === "all" ? all : data.build(filter, p, all.changes), p);
|
|
109
|
+
return write(data.build(filter, 30, all.changes), 30);
|
|
83
110
|
}
|
|
84
111
|
|
|
85
112
|
export function reportPath(env?: Env): string {
|
package/src/query.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/** `evals_query`: bounded plain-text summaries of the index for an agent (names and numbers only, under 2 KB). */
|
|
2
|
-
import {
|
|
2
|
+
import { coverageInRange, indexedModel, reportPath } from "./ops.ts";
|
|
3
|
+
import { findings } from "./findings.ts";
|
|
4
|
+
import { select } from "./report/findings.ts";
|
|
3
5
|
import type { Rate } from "./model.ts";
|
|
4
6
|
|
|
5
|
-
export const VIEWS = ["skills", "packages", "ask_user", "monitors", "subagents", "process", "cost", "changes", "coverage"] as const;
|
|
7
|
+
export const VIEWS = ["findings", "skills", "packages", "ask_user", "monitors", "subagents", "process", "cost", "changes", "coverage"] as const;
|
|
6
8
|
export type View = (typeof VIEWS)[number];
|
|
7
9
|
export const MAX_BYTES = 1900;
|
|
8
10
|
|
|
@@ -12,25 +14,34 @@ const sec = (v: number | null) => (v === null ? "n/a" : `${(v / 1000).toFixed(1)
|
|
|
12
14
|
/** Cuts text to the byte limit at a line boundary. */
|
|
13
15
|
export function bound(text: string, limit = MAX_BYTES): string {
|
|
14
16
|
if (Buffer.byteLength(text) <= limit) return text;
|
|
15
|
-
const lines = text.split("\n");
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const lines = text.split("\n"), tail = lines.at(-1) ?? "";
|
|
18
|
+
const suffix = tail.startsWith("report: ") && Buffer.byteLength(tail) < limit / 2 ? `\n…\n${tail}` : "\n…";
|
|
19
|
+
const kept: string[] = [];
|
|
20
|
+
for (const line of lines) {
|
|
21
|
+
if (Buffer.byteLength([...kept, line].join("\n") + suffix) > limit) break;
|
|
22
|
+
kept.push(line);
|
|
23
|
+
}
|
|
24
|
+
return kept.join("\n") + suffix;
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
export function query(view: View, options: { since?: string; project?: string; env?: Record<string, string | undefined> } = {}): string {
|
|
27
|
+
export function query(view: View, options: { since?: string; days?: number; project?: string; env?: Record<string, string | undefined> } = {}): string {
|
|
21
28
|
if (view === "coverage") {
|
|
22
|
-
const c =
|
|
29
|
+
const { coverage: c, filter, last } = coverageInRange(options, options.env);
|
|
23
30
|
return bound(
|
|
24
31
|
[
|
|
32
|
+
`${filter.since}..${filter.until} UTC; last extract ${last ?? "never"}; live cleanup check across all dates and projects`,
|
|
25
33
|
`coverage, sessions inactive > ${c.cutDays} days (before ${c.cutoff.slice(0, 10)}):`,
|
|
26
34
|
`indexed ${c.indexed.files}/${c.old.files} files, ${(c.indexed.bytes / 1e9).toFixed(2)} of ${(c.old.bytes / 1e9).toFixed(2)} GB; not indexed ${c.notIndexed.files}`,
|
|
35
|
+
`modified in report dates (all projects): ${c.inRange?.indexed ?? 0}/${c.inRange?.files ?? 0} files indexed`,
|
|
27
36
|
`all files: ${c.all.indexedFiles}/${c.all.files} indexed; index keeps ${c.retainedGone} sessions whose file is gone`,
|
|
28
37
|
"meaning: only indexed files keep their numbers if the session files are cleaned up",
|
|
29
38
|
].join("\n"),
|
|
30
39
|
);
|
|
31
40
|
}
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
41
|
+
const data = indexedModel(options, options.env, view === "findings");
|
|
42
|
+
if (!data) return "pi-evals: nothing extracted yet; the user can run /evals extract.";
|
|
43
|
+
const { report: m, index } = data;
|
|
44
|
+
if (view === "findings") return bound(findings(m), 1499);
|
|
34
45
|
const head = [
|
|
35
46
|
`pi-evals ${view} · ${m.window.since ?? "?"}..${m.window.until ?? "?"}${m.window.project ? ` · project ${m.window.project}` : ""} · sessions ${m.totals.sessions}`,
|
|
36
47
|
m.freshness.stale ? `STALE: last extract ${m.freshness.lastExtract ?? "never"} (${m.freshness.ageHours ?? "?"}h ago); /evals extract refreshes` : `last extract ${m.freshness.lastExtract}`,
|
|
@@ -42,6 +53,8 @@ export function query(view: View, options: { since?: string; project?: string; e
|
|
|
42
53
|
body.push(`ways: ${Object.entries(m.skills.triggers).map(([k, v]) => `${k} ${v}`).join(", ")}`);
|
|
43
54
|
body.push(`offered but never loaded (${m.skills.neverLoaded.length}/${m.skills.offered}): ${m.skills.neverLoaded.slice(0, 25).join(", ")}`);
|
|
44
55
|
} else if (view === "packages") {
|
|
56
|
+
const w = m.weekly;
|
|
57
|
+
for (const p of w?.packages.slice(0, 3) ?? []) body.push(`${p.name} weekly errors/calls: ${p.before.errors}/${p.before.calls} -> ${p.after.errors}/${p.after.calls}`);
|
|
45
58
|
body.push("package: calls, error rate, avg time");
|
|
46
59
|
for (const p of m.packages.slice(0, 15)) body.push(`${p.owner}${p.version ? `@${p.version}` : ""}: ${p.calls}, ${pct(p.errorRate)}, ${sec(p.avgMs)}`);
|
|
47
60
|
} else if (view === "ask_user") {
|
|
@@ -49,11 +62,13 @@ export function query(view: View, options: { since?: string; project?: string; e
|
|
|
49
62
|
body.push(`questions ${a.calls}; dismissed ${pct(a.cancelRate)}; avg wait for answer ${sec(a.avgWaitMs)} (n=${a.waitN}); errors ${a.errors}`);
|
|
50
63
|
body.push(`answer source: ${Object.entries(a.sources).map(([k, v]) => `${k} ${v}`).join(", ") || "n/a"}`);
|
|
51
64
|
} else if (view === "monitors") {
|
|
65
|
+
const w = m.weekly?.monitors;
|
|
66
|
+
if (w) body.push(`weekly jobs ending in error: ${w.before.errors}/${w.before.calls} -> ${w.after.errors}/${w.after.calls}`);
|
|
52
67
|
const mo = m.monitors;
|
|
53
68
|
body.push(`started ${mo.started}; ending recorded ${mo.finished}; avg duration ${sec(mo.avgMs)} (n=${mo.durationN})`);
|
|
54
69
|
body.push(`outcomes: ${Object.entries(mo.statuses).map(([k, v]) => `${k} ${v}`).join(", ") || "n/a"}`);
|
|
55
70
|
} else if (view === "subagents") {
|
|
56
|
-
body.push(`subagent sessions ${m.subagents.sessions}; linked to parent ${m.subagents.linked}/${m.subagents.subagentTotal}
|
|
71
|
+
body.push(`subagent sessions ${m.subagents.sessions}; linked to parent: ${m.subagents.linked === null ? "run /evals extract for counts in this range" : `${m.subagents.linked}/${m.subagents.subagentTotal}`}`);
|
|
57
72
|
body.push("role / model: launches");
|
|
58
73
|
for (const l of m.subagents.launches.slice(0, 12)) body.push(`${l.role} / ${l.model}: ${l.n}`);
|
|
59
74
|
body.push(`cost by role: ${m.subagents.costByRole.slice(0, 8).map((r) => `${r.role} $${r.cost}`).join(", ")}`);
|
|
@@ -71,14 +86,15 @@ export function query(view: View, options: { since?: string; project?: string; e
|
|
|
71
86
|
body.push("cost of sessions loading skill (not caused by it):");
|
|
72
87
|
for (const s of m.cost.bySkill.slice(0, 10)) body.push(`${s.skill}: $${s.cost} over ${s.sessions} sessions`);
|
|
73
88
|
} else if (view === "changes") {
|
|
74
|
-
body.push("newest changes, sessions split at the change time, metric before -> after; flags: small = <20 sessions a side, incomplete = a window runs past the data, confounded = other commits nearby");
|
|
75
|
-
|
|
89
|
+
body.push("highlighted then newest changes, sessions split at the change time, metric before -> after; flags: small = <20 sessions a side, incomplete = a window runs past the data, confounded = other commits nearby");
|
|
90
|
+
const { highlighted, folded } = select(m);
|
|
91
|
+
for (const c of [...highlighted, ...folded].slice(0, 8)) {
|
|
76
92
|
const what = c.package ? `${c.package} ${c.from ?? "-"}->${c.to ?? "-"}` : c.subject.slice(0, 60);
|
|
77
93
|
const i = c.impact;
|
|
78
94
|
const fx = i
|
|
79
95
|
? `sessions ${i.before.sessions}->${i.after.sessions}, tool errors ${pct(i.before.tool_error_rate)}->${pct(i.after.tool_error_rate)}, anchor-first ${pct(i.before.anchor_before_first_edit)}->${pct(i.after.anchor_before_first_edit)}${i.smallSample ? ", small" : ""}${i.incomplete ? `, incomplete (days with data ${i.daysWithData.before}/${i.daysWithData.after})` : ""}${i.confounded ? `, confounded ${i.confounded}` : ""}`
|
|
80
96
|
: "no data before";
|
|
81
|
-
body.push(`${c.at
|
|
97
|
+
body.push(`${c.at} ${c.kind} ${what}: ${fx}`);
|
|
82
98
|
}
|
|
83
99
|
}
|
|
84
100
|
return bound([...head, ...body, `report: ${reportPath(options.env)}`].join("\n"));
|
package/src/ranges.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Filter } from "./model.ts";
|
|
2
|
+
|
|
3
|
+
export const PRESETS = [14, 30, 90, "all"] as const;
|
|
4
|
+
export type Preset = typeof PRESETS[number];
|
|
5
|
+
export const suffix = (r: Preset | "custom") => r === 30 ? "" : typeof r === "number" ? `-${r}d` : `-${r}`;
|
|
6
|
+
|
|
7
|
+
/** Calendar ranges include the (possibly partial) UTC day of the last extraction. */
|
|
8
|
+
export function rangeFilter(input: Filter & { days?: number }, end: string, preset: Preset = 30): Filter {
|
|
9
|
+
const until = input.until ?? end.slice(0, 10), days = input.days ?? preset;
|
|
10
|
+
if (input.since && input.days !== undefined) throw new Error("Choose either --days or --since.");
|
|
11
|
+
if (days !== "all" && (!Number.isSafeInteger(days) || days < 1 || days > 365000)) throw new Error("--days must be a positive integer (at most 365000).");
|
|
12
|
+
if (input.since && (!/^\d{4}-\d\d-\d\d$/.test(input.since) || !Number.isFinite(Date.parse(input.since)) || new Date(input.since).toISOString().slice(0, 10) !== input.since)) throw new Error("since must be YYYY-MM-DD.");
|
|
13
|
+
const since = input.since ?? (days === "all" ? undefined : new Date(Date.parse(until) - (days - 1) * 86400000).toISOString().slice(0, 10));
|
|
14
|
+
return { since, until, project: input.project };
|
|
15
|
+
}
|
package/src/render.ts
CHANGED
|
@@ -5,11 +5,20 @@ import { esc, type Lang, num, words } from "./report/format.ts";
|
|
|
5
5
|
import { sections } from "./report/sections.ts";
|
|
6
6
|
import { css } from "./report/style.ts";
|
|
7
7
|
import { timeline } from "./report/timeline.ts";
|
|
8
|
-
import {
|
|
8
|
+
import { PRESETS, type Preset, suffix } from "./ranges.ts";
|
|
9
|
+
import { trendPair } from "./trends.ts";
|
|
10
|
+
import type { Words } from "./report/format.ts";
|
|
11
|
+
import { periodRows, workload } from "./report/week.ts";
|
|
9
12
|
export type { Lang } from "./report/format.ts";
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
const
|
|
14
|
+
function weeklyPanel(m: ReportModel, L: Words) {
|
|
15
|
+
const w = m.weekly, p = w?.packages[0];
|
|
16
|
+
if (!w || (!p && !w.monitors)) return "";
|
|
17
|
+
const rows = [p && `${p.name === "unknown" ? L("Tools with no known package", "套件不明的工具") : p.name} ${L("errors/calls", "錯誤數/呼叫數")} ${trendPair(p)}`, w.monitors && `${L("Failed/finished jobs", "失敗數/已結束工作數")} ${trendPair(w.monitors)}`];
|
|
18
|
+
return `<section class="panel"><h2>${L("Weekly error increases", "每週錯誤比例上升")}</h2><p>${esc(w.start)}–${esc(w.end)} UTC · ${L("Earlier week → later week", "前一週 → 後一週")}</p>${rows.filter(Boolean).map(s => `<p>${esc(s!)}</p>`).join("")}</section>`;
|
|
19
|
+
}
|
|
20
|
+
export function renderHtml(m: ReportModel, lang: Lang = "zh", range: Preset | "custom" = "custom"): string {
|
|
21
|
+
const L = words(lang), w = periodRows(m), t = timeline(m, w, lang, range), c = concepts(m, w, t.lead, L);
|
|
13
22
|
const nav = [
|
|
14
23
|
["archive", L("All changes", "所有調整")],
|
|
15
24
|
["skills", L("Skills", "技能")],
|
|
@@ -31,7 +40,7 @@ export function renderHtml(m: ReportModel, lang: Lang = "zh"): string {
|
|
|
31
40
|
}</title><style>${css}</style></head><body><header><a href="#timeline" class="brand"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><rect width="30" height="30" rx="8" fill="#174e47"/><path d="M7 22V15M15 22V8M23 22V12" fill="none" stroke="white" stroke-width="3"/></svg>pi-evals<span>${
|
|
32
41
|
L("Agent work, observed", "代理工作觀察")
|
|
33
42
|
}</span></a><small>${esc(date)} ${L("report", "更新")} / ${L("All times UTC", "時間皆為 UTC")}</small></header>
|
|
34
|
-
<main id="timeline"><div class="hero"><p class="eyebrow">${L("Change journal / Newest first", "調整紀事 / 依更新時間排列")}</p><h1>${
|
|
43
|
+
<main id="timeline"><div class="ranges">${range === "custom" ? "" : `<nav aria-label="${L("Time range", "時間範圍")}">${PRESETS.map(p => `<a href="report${suffix(p)}.html"${p === range ? ' aria-current="page"' : ""}>${p === "all" ? L("All time", "全部") : L(`Last ${p} days`, `近 ${p} 天`)}</a>`).join("")}</nav>`}<small>${esc(m.window.since ?? "—")} – ${esc(m.window.until ?? "—")} UTC</small></div>${t.strip}<div class="hero"><p class="eyebrow">${L("Change journal / Newest first", "調整紀事 / 依更新時間排列")}</p><h1>${
|
|
35
44
|
esc(t.headline)
|
|
36
45
|
}</h1><p class="deck">${esc(t.trust)}</p>${
|
|
37
46
|
m.freshness.stale
|
|
@@ -44,7 +53,7 @@ export function renderHtml(m: ReportModel, lang: Lang = "zh"): string {
|
|
|
44
53
|
L(`${t.count} changes worth a closer look`, `${t.count === 2 ? "兩" : t.count === 1 ? "一" : "零"}筆值得回看的調整`)
|
|
45
54
|
}</h2><div class="layout"><div class="rail">${
|
|
46
55
|
t.cards || `<p>${L("Nothing to highlight yet.", "還沒有適合比較的調整。")}</p>`
|
|
47
|
-
}</div><aside class="side">${workload(w, L)}${lesson(c.record, L)}${lesson(c.metric, L)}</aside></div><details><summary>${
|
|
56
|
+
}</div><aside class="side">${workload(w, L)}${weeklyPanel(m, L)}${lesson(c.record, L)}${lesson(c.metric, L)}</aside></div><details><summary>${
|
|
48
57
|
L("How to read the comparisons", "怎麼讀時間軸上的比較?")
|
|
49
58
|
}</summary><div class="notes-grid">${lesson(c.sample, L)}${lesson(c.confounding, L)}${lesson(c.check, L)}</div></details></div>
|
|
50
59
|
<nav class="jump" aria-label="${L("Report sections", "報表章節")}">${
|
package/src/report/findings.ts
CHANGED
|
@@ -41,7 +41,7 @@ export function verdict(c: Change, rs: Reading[], L: Words): string {
|
|
|
41
41
|
}
|
|
42
42
|
if (i.incomplete) notes.push(L(`less than ${i.window.days} days on one side`, `一側未滿 ${i.window.days} 天`));
|
|
43
43
|
if (!rs.some(comparable)) notes.push(L("no comparable readings", "沒有可比較的數字"));
|
|
44
|
-
const other = i.confounded ? L(`${num(i.confounded)} other changes in the same period`, `同期還有 ${num(i.confounded)} 筆別的調整`) : "";
|
|
44
|
+
const other = i.confounded ? L(`${num(i.confounded)} other changes in the same period`, `同期還有 ${num(i.confounded)} 筆別的調整`) + L("; we cannot tell which change mattered", ",無法分辨是哪一筆造成的") : "";
|
|
45
45
|
if (notes.length || other) {
|
|
46
46
|
return [notes.length ? L(`Too early to tell: ${notes.join("; ")}`, `還看不出來(${notes.join("、")})`) : "", other].filter(Boolean)
|
|
47
47
|
.join(" · ");
|
|
@@ -67,6 +67,24 @@ export function select(m: ReportModel) {
|
|
|
67
67
|
const highlighted = all.filter((c) => c === lead || c === second);
|
|
68
68
|
return { all, lead, highlighted, folded: all.filter((c) => !highlighted.includes(c)) };
|
|
69
69
|
}
|
|
70
|
+
/** Editorial choices shared by the HTML timeline and the compact query. */
|
|
71
|
+
export function overview(m: ReportModel, lang: Lang) {
|
|
72
|
+
const selected = select(m), { lead, all } = selected, L = words(lang);
|
|
73
|
+
const rs = lead ? readings(lead, m, lang) : [];
|
|
74
|
+
const headline = lead ? finding(lead, rs, L) : all.length
|
|
75
|
+
? L("Not enough sessions to compare changes yet", "這批調整的工作段數還不夠比較")
|
|
76
|
+
: L("No changes recorded in this period", "這段期間沒有調整紀錄");
|
|
77
|
+
const i = lead?.impact;
|
|
78
|
+
const trust = i?.incomplete && i.confounded && !i.smallSample ? L(
|
|
79
|
+
`There were ${num(i.confounded)} other changes, and one side has less than ${i.window.days} days of data. We cannot credit this change alone.`,
|
|
80
|
+
`同期還有 ${num(i.confounded)} 筆別的調整,一側的資料也未滿 ${i.window.days} 天;目前不能把差異歸給這次調整。`,
|
|
81
|
+
) : lead ? verdict(lead, rs, L) : L(
|
|
82
|
+
`There are ${num(m.totals.sessions)} sessions in this report, but no eligible comparison.`,
|
|
83
|
+
`報表收錄 ${num(m.totals.sessions)} 段工作,目前沒有適合放在首頁的比較。`,
|
|
84
|
+
);
|
|
85
|
+
return { ...selected, headline, trust };
|
|
86
|
+
}
|
|
87
|
+
|
|
70
88
|
export function finding(c: Change, rs: Reading[], L: Words) {
|
|
71
89
|
const r = rs.find(comparable);
|
|
72
90
|
if (!r) return L("There are not enough records to compare this change", "這次調整還沒有足夠紀錄可比較");
|
package/src/report/sections.ts
CHANGED
|
@@ -89,9 +89,7 @@ export function sections(m: ReportModel, lang: Lang, cards: ReturnType<typeof co
|
|
|
89
89
|
meta.subagent_launches.meaning[lang],
|
|
90
90
|
T([L("Role", "角色"), L("Model", "模型"), L("Launches", "啟動次數")], s.launches.slice(0, 40).map((r) => [r.role, r.model, r.n])) +
|
|
91
91
|
more(label("subagent_cost"), T([L("Role", "角色"), L("USD", "美元")], s.costByRole.map((r) => [r.role, usd(r.cost)]))) +
|
|
92
|
-
`<p>${L("Linked to a parent
|
|
93
|
-
num(s.subagentTotal)
|
|
94
|
-
}</p>`,
|
|
92
|
+
`<p>${L("Linked to a parent in this period", "這段期間能對回母工作階段的子代理")}:${s.linked === null ? L("Run /evals extract for this breakdown.", "請執行 /evals extract 更新分期統計。") : `${num(s.linked)} / ${num(s.subagentTotal)}`} </p>`,
|
|
95
93
|
);
|
|
96
94
|
const process = section(
|
|
97
95
|
"process",
|
|
@@ -145,7 +143,7 @@ export function sections(m: ReportModel, lang: Lang, cards: ReturnType<typeof co
|
|
|
145
143
|
"所有舊檔的大小和修改時間都要和索引相符,未建索引的檔案數和位元組數都歸零,才考慮開啟清理。報表不會刪檔。",
|
|
146
144
|
),
|
|
147
145
|
cov
|
|
148
|
-
? `<p>${L("Inactive days", "閒置天數")} > ${cov.cutDays} / ${L("Files indexed", "已建索引")} ${num(cov.indexed.files)} / ${
|
|
146
|
+
? `<p>${L("Files modified in the selected dates, indexed (all projects)", "選定日期內有修改的檔案,已建索引(全部專案)")}:${num(cov.inRange?.indexed ?? 0)} / ${num(cov.inRange?.files ?? 0)}</p><p>${L("Cleanup gate across all dates", "清理門檻不分日期")} · ${L("Inactive days", "閒置天數")} > ${cov.cutDays} / ${L("Files indexed", "已建索引")} ${num(cov.indexed.files)} / ${
|
|
149
147
|
num(cov.old.files)
|
|
150
148
|
}</p><p>${L("Not indexed", "未建索引")}:${num(cov.notIndexed.files)} ${L("files", "個檔案")} · ${
|
|
151
149
|
num(cov.notIndexed.bytes)
|
|
@@ -156,7 +154,7 @@ export function sections(m: ReportModel, lang: Lang, cards: ReturnType<typeof co
|
|
|
156
154
|
"labels",
|
|
157
155
|
L("Your labels", "你的標記"),
|
|
158
156
|
meta.agreement.meaning[lang],
|
|
159
|
-
m.labels.present && m.labels.n
|
|
157
|
+
m.labels.needsIndex ? `<p>${L("Run /evals extract to count labels in this period.", "請執行 /evals extract 以計算這段期間的標記。")}</p>` : m.labels.present && m.labels.n
|
|
160
158
|
? T(
|
|
161
159
|
[L("Check", "檢查"), L("Labelled", "已標記"), L("Agreement", "一致比例")],
|
|
162
160
|
m.labels.agreement.map((r) => [m.meta.detectors[r.detector]?.label[lang] ?? r.detector, r.n, pct(r.rate)]),
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ReportModel } from "../model.ts";
|
|
2
|
+
import type { Preset } from "../ranges.ts";
|
|
3
|
+
import { type Change, esc, type Lang, num, words } from "./format.ts";
|
|
4
|
+
|
|
5
|
+
const KINDS = ["pin", "model-routing", "rule", "agent-role", "skill", "manual"] as const;
|
|
6
|
+
|
|
7
|
+
/** Dense time slots get a count; every change still has its own mark and title. */
|
|
8
|
+
export function changeStrip(m: ReportModel, all: Change[], picks: Change[], ids: Map<Change, string>, lang: Lang, range: Preset | "custom") {
|
|
9
|
+
const L = words(lang), label = (k: Change["kind"]) => m.meta.changeKinds[k][lang];
|
|
10
|
+
const period = typeof range === "number" ? L(`Last ${range} days`, `近 ${range} 天`) : range === "all" ? L("All time", "全部期間") : L("Selected dates", "選定期間");
|
|
11
|
+
const since = m.window.since ?? "", until = m.window.until ?? "", start = Date.parse(since), span = Date.parse(until) + 86400000 - start;
|
|
12
|
+
const x = (c: Change) => 16 + Math.min(1, Math.max(0, (Date.parse(c.at) - start) / span)) * 968;
|
|
13
|
+
const bins = new Map<number, Change[]>(), counts = new Map<string, number>();
|
|
14
|
+
for (const c of all) {
|
|
15
|
+
const slot = Math.floor((x(c) - 16) / 30), cells = bins.get(slot) ?? [];
|
|
16
|
+
cells.push(c); bins.set(slot, cells); counts.set(c.kind, (counts.get(c.kind) ?? 0) + 1);
|
|
17
|
+
}
|
|
18
|
+
const short = { pin: "版本", "model-routing": "模型路由", rule: "規則", "agent-role": "角色", skill: "skill", manual: "手動" };
|
|
19
|
+
const breakdown = KINDS.map(k => `${L(label(k), short[k])} ${num(counts.get(k) ?? 0)}`).join(L(", ", "、"));
|
|
20
|
+
const total = L(`${period}: ${num(all.length)} changes: ${breakdown}; ${picks.length} worth a closer look.`, `${period}共 ${num(all.length)} 筆調整:${breakdown};其中 ${picks.length} 筆值得回看。`);
|
|
21
|
+
const legend = KINDS.map(k => `<span><i class="key kind-${k}"></i>${esc(label(k))}: ${num(counts.get(k) ?? 0)}</span>`).join("");
|
|
22
|
+
const base = 64, marks: string[] = [], labeled = new Map<Change, { px: number; py: number; dot: string }>();
|
|
23
|
+
for (const [slot, cells] of bins) {
|
|
24
|
+
cells.reverse(); // Earliest mark at the left of a dense slot.
|
|
25
|
+
const left = 16 + slot * 30, columns = Math.ceil(cells.length / 5);
|
|
26
|
+
cells.forEach((c, i) => {
|
|
27
|
+
const px = cells.length <= 5 ? x(c) : left + (Math.floor(i / 5) + .5) * 28 / columns;
|
|
28
|
+
const py = base - 6 - i % 5 * 5;
|
|
29
|
+
const dot = `<circle class="change-mark kind-${c.kind}" cx="${px.toFixed(1)}" cy="${py}" r="${Math.min(2.4, 13 / columns)}"><title>${esc(c.at)} · ${esc(label(c.kind))}</title></circle>`;
|
|
30
|
+
if (picks.includes(c)) labeled.set(c, { px, py, dot }); else marks.push(dot);
|
|
31
|
+
});
|
|
32
|
+
if (cells.length > 5) marks.push(`<text class="slot-count" x="${left + 14}" y="28" text-anchor="middle">×${cells.length}</text>`);
|
|
33
|
+
}
|
|
34
|
+
const links = picks.map((c,i) => {
|
|
35
|
+
const {px, py, dot} = labeled.get(c)!, end = px > 700, caption = c.package ? `${c.package} ${c.to ?? ""}` : `${label(c.kind)} · ${c.at.slice(5,16).replace("T", " ")}`;
|
|
36
|
+
const y = 87 + i * 23;
|
|
37
|
+
return `<a href="#${ids.get(c)}"><title>${esc(caption)}</title><path class="guide" d="M${px} ${py}V${y - 6}h${end ? -7 : 7}"/>${dot}<text x="${px + (end ? -10 : 10)}" y="${y}" text-anchor="${end ? "end" : "start"}">${esc(Array.from(caption).length > 48 ? Array.from(caption).slice(0, 47).join("") + "…" : caption)}</text></a>`;
|
|
38
|
+
}).join("");
|
|
39
|
+
return `<section class="change-strip"><h2>${total}</h2><div class="kind-key">${legend}</div><svg viewBox="0 0 1000 ${base + 14 + picks.length * 23}" aria-label="${esc(total)}"><path class="axis" d="M16 ${base}H984"/>${marks.join("")}${links}</svg><div class="ends"><span>${esc(since)}</span><span>${esc(until)} UTC</span></div></section>`;
|
|
40
|
+
}
|
package/src/report/style.ts
CHANGED
|
@@ -21,6 +21,8 @@ header {min-height:75px;flex-wrap:wrap}
|
|
|
21
21
|
.brand span {font-size:17px;font-weight:400;padding-left:20px;margin-left:16px;border-left:1px solid var(--line);color:var(--sub)}
|
|
22
22
|
small,.muted,.intro,.deck,.ends {color:var(--sub)}
|
|
23
23
|
small,.muted,.ends,summary,.footline,.button {font-size:15px}
|
|
24
|
+
.ranges,.ranges nav {display:flex;align-items:center;gap:6px;flex-wrap:wrap}.ranges {justify-content:space-between;margin-top:18px}
|
|
25
|
+
.ranges a {padding:5px 12px;text-decoration:none;border-radius:6px}.ranges a[aria-current] {background:var(--tint);font-weight:700}
|
|
24
26
|
.hero {padding:36px 0 20px}
|
|
25
27
|
.hero h1,.hero-title {font-size:clamp(29px,3.125vw,40px);line-height:1.25;margin:18px 0}
|
|
26
28
|
.deck,.intro {font-size:19px;margin:0}.hero .deck+.deck {margin-top:24px}
|
|
@@ -42,7 +44,13 @@ h3,.big {font-size:29px;line-height:1.35;margin:14px 0 18px}
|
|
|
42
44
|
.workload h2 {margin-bottom:0}.workload h3 {margin:25px 0 12px}.workload .muted {margin:5px 0}
|
|
43
45
|
.workload svg {width:100%;height:auto;display:block;margin-top:8px}
|
|
44
46
|
.area {fill:var(--area)}.trend {stroke:var(--green);stroke-width:2.5;stroke-linejoin:round;fill:none}
|
|
45
|
-
.
|
|
47
|
+
.ends {margin:4px 0}
|
|
48
|
+
.change-strip {margin:18px 0 0;padding:12px 0;border-block:1px solid var(--line)}.change-strip h2 {font-size:19px;margin:0 0 6px}
|
|
49
|
+
.kind-key {display:flex;flex-wrap:wrap;gap:4px 16px;font-size:14px;color:var(--sub)}.key {display:inline-block;width:.7em;height:.7em;border-radius:100%;background:var(--kind);margin-right:5px}
|
|
50
|
+
.kind-pin {--kind:#3b9090}.kind-model-routing {--kind:#736cc9}.kind-rule {--kind:#c78231}.kind-agent-role {--kind:#c16c89}.kind-skill {--kind:#718c40}.kind-manual {--kind:#477dac}
|
|
51
|
+
.change-mark,.work-mark {fill:var(--kind)}.change-strip svg {width:100%;display:block}.change-strip .axis,.change-strip .guide {stroke:var(--line);fill:none}
|
|
52
|
+
.change-strip .slot-count {fill:var(--sub);font:12px sans-serif}.change-strip a text {fill:var(--green);font-size:14px;text-decoration:underline}
|
|
53
|
+
@media(max-width:640px){.change-strip {overflow-x:auto}.change-strip svg {min-width:600px}}
|
|
46
54
|
.footline {border-top:1px solid var(--line);padding-top:13px;margin:12px 0 0}
|
|
47
55
|
.lesson,.tint,.after {background:var(--tint)}.lesson {padding:16px 19px}.lesson p {margin:5px 0 0}.side>.lesson {margin-top:16px}
|
|
48
56
|
.topic {padding:38px 0}.topic h2 {margin:9px 0}.intro {margin:0 0 18px}
|
package/src/report/timeline.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { ReportModel } from "../model.ts";
|
|
2
2
|
import { concepts, lesson } from "./concepts.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { overview, type Reading, readings, value, verdict } from "./findings.ts";
|
|
4
4
|
import { type Change, esc, type Lang, num, stamp, title, type Words, words } from "./format.ts";
|
|
5
|
+
import type { Preset } from "../ranges.ts";
|
|
6
|
+
import { changeStrip } from "./strip.ts";
|
|
5
7
|
import type { Week } from "./week.ts";
|
|
6
8
|
|
|
7
9
|
function card(c: Change, id: string, rs: Reading[], L: Words) {
|
|
@@ -91,8 +93,8 @@ ${
|
|
|
91
93
|
L("Timeline", "回時間軸")
|
|
92
94
|
}</a></section>`;
|
|
93
95
|
}
|
|
94
|
-
export function timeline(m: ReportModel, w: Week, lang: Lang) {
|
|
95
|
-
const L = words(lang), { all, lead, highlighted, folded } =
|
|
96
|
+
export function timeline(m: ReportModel, w: Week, lang: Lang, range: Preset | "custom") {
|
|
97
|
+
const L = words(lang), { all, lead, highlighted, folded, headline, trust } = overview(m, lang);
|
|
96
98
|
const ids = new Map(all.map((c, i) => [c, `change-${i + 1}`]));
|
|
97
99
|
const metrics = new Map(all.map((c) => [c, readings(c, m, lang)]));
|
|
98
100
|
const byDay = new Map<string, Change[]>(), byCommit = new Map<string, Change[]>();
|
|
@@ -108,29 +110,11 @@ export function timeline(m: ReportModel, w: Week, lang: Lang) {
|
|
|
108
110
|
byCommit.get(key)!.push(c);
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
|
-
const headline = lead
|
|
112
|
-
? finding(lead, metrics.get(lead)!, L)
|
|
113
|
-
: all.length
|
|
114
|
-
? L("Not enough sessions to compare changes yet", "這批調整的工作段數還不夠比較")
|
|
115
|
-
: L("No changes recorded in this period", "這段期間沒有調整紀錄");
|
|
116
|
-
const reason = lead?.impact;
|
|
117
|
-
const trust = lead && reason?.incomplete && reason.confounded && !reason.smallSample
|
|
118
|
-
? L(
|
|
119
|
-
`There were ${
|
|
120
|
-
num(reason.confounded)
|
|
121
|
-
} other changes, and one side has less than ${reason.window.days} days of data. We cannot credit this change alone.`,
|
|
122
|
-
`同期還有 ${num(reason.confounded)} 筆別的調整,一側的資料也未滿 ${reason.window.days} 天;目前不能把差異歸給這次調整。`,
|
|
123
|
-
)
|
|
124
|
-
: lead
|
|
125
|
-
? verdict(lead, metrics.get(lead)!, L)
|
|
126
|
-
: L(
|
|
127
|
-
`There are ${num(m.totals.sessions)} sessions in this report, but no eligible comparison.`,
|
|
128
|
-
`報表收錄 ${num(m.totals.sessions)} 段工作,目前沒有適合放在首頁的比較。`,
|
|
129
|
-
);
|
|
130
113
|
return {
|
|
131
114
|
lead,
|
|
132
115
|
headline,
|
|
133
116
|
trust,
|
|
117
|
+
strip: changeStrip(m, all, highlighted, ids, lang, range),
|
|
134
118
|
count: highlighted.length,
|
|
135
119
|
cards: highlighted.map((c) => card(c, ids.get(c)!, metrics.get(c)!, L)).join(""),
|
|
136
120
|
archive: [...byDay].map(([day, list]) =>
|