pi-evals 0.3.0 → 0.4.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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+
5
+ - The report has a 「工作」 section: every todo item with its cost (subagents exact, main agent split evenly among items in progress at the same time), minutes in progress, how it closed (reviewer approval, a landed car, a wrap, evidence) and where it stalled, by what woke the main agent. A comparison of like with like says whether one model, role or anchorloop version costs less per item and per 100 changed lines, or that there are too few items to tell. Open items show where they stopped, on whom they wait, and for how long. Two concept cards explain cost attribution and fair comparison with this report's numbers.
6
+ - Back-fill rebuilds work items from `todo/v1` snapshots, never merging tasks across a `clear` or a `/tree` branch, and writes `pi.workitem` and `pi.stall` records. It reads todo `uid`, `origin` and evidence `ref`, the review thread's `item` and `closed`, and the sb ledger when they exist, and joins by names otherwise.
7
+ - A work item's title (its todo subject, at most 80 characters) is the only source text pi-evals stores.
8
+ - `evals_query` has an `items` view, and `findings` adds a line when a like-with-like difference or a long wait stands out.
9
+ - A label of `unclear` is left out of the agreement rate and counted on its own (「看不出來」).
10
+ - Re-extracts every session once (extractor version 4).
11
+
3
12
  ## 0.3.0
4
13
 
5
14
  - Open the report on the last 30 days and switch to 14 days, 90 days or all time without scripts. For other dates use `--since` or `--days`.
package/README.md CHANGED
@@ -13,6 +13,7 @@ Agents can read the same numbers through one tool, `evals_query`.
13
13
  - **Subagents**: launches by role and model, and their cost by role.
14
14
  - **Process**: four checks of the anchorloop rules per session, for sessions started after anchorloop 3.0.0 was pinned (2026-11-23T10:51:07Z); see [docs/design.md](docs/design.md#process-detectors).
15
15
  - **Cost**: model cost and tokens, and the cost of the sessions that loaded each skill.
16
+ - **Work items**: each todo task from the moment it is switched to in progress until it is done or deleted: what it cost (subagents exactly, the main agent as an even share), where it closed (reviewer approval, a landed car, a wrap, evidence), where it stalled and on whom, and whether one way of working is cheaper than another of the same kind.
16
17
  - **Your changes**: package pins, model routing, rules, skills and agent roles from the git history of your setup repositories, version changes seen live, and notes you add with `/evals mark`, each with the same numbers in the days before and after.
17
18
 
18
19
  ## Privacy
@@ -20,7 +21,8 @@ Agents can read the same numbers through one tool, `evals_query`.
20
21
  Records hold derived facts only: names (tools, skills, packages, models, roles, project keys), counts, durations, exit codes, outcomes, and token and cost numbers.
21
22
  They never hold transcript text, tool arguments, file contents, commands, questions, or answers.
22
23
  Every string written to a record must look like a name (no spaces, no line breaks, at most 160 characters), or it is stored as `redacted`.
23
- A test plants a secret in every text field of a session and checks that it reaches no output file and no query result.
24
+ The one exception is a work item's title: its todo subject, cut to one line of at most 80 characters.
25
+ A test plants a secret in every text field of a session and checks that it reaches no output file and no query result outside a title field.
24
26
 
25
27
  Everything stays on your machine, under `$XDG_STATE_HOME/pi-evals` (default `~/.local/state/pi-evals`).
26
28
  Session files are only read, never written.
@@ -58,7 +60,7 @@ pi-evals mark <note>
58
60
  ### The `evals_query` tool
59
61
 
60
62
  Start with `findings` (under 1,500 bytes), then follow one pointer if you need the counts.
61
- An agent calls `evals_query` with a `view` (`findings`, `skills`, `packages`, `ask_user`, `monitors`, `subagents`, `process`, `cost`, `changes`, `coverage`) and optional `since` and `project`.
63
+ An agent calls `evals_query` with a `view` (`findings`, `items`, `skills`, `packages`, `ask_user`, `monitors`, `subagents`, `process`, `cost`, `changes`, `coverage`) and optional `since` and `project`.
62
64
  The result is plain text under 2 KB, covering the latest 30 UTC dates through the last extract unless you give `since`.
63
65
  `findings` flags the biggest package error-rate rise and a rise in jobs ending in error when the later of two complete weeks is at least five percentage points higher, with at least 20 calls or endings in **each** week.
64
66
  It also counts offered skills with no loads in the selected period and checks whether all old files are indexed.
@@ -116,8 +118,10 @@ Use the section links for usage, process checks, cost and cleanup coverage, or r
116
118
  | `index/days.json` | Aggregates by day and project. |
117
119
  | `index/sessions.json` | A few numbers per session with its start time, for splitting sessions at a change's time. |
118
120
  | `index/session-evals.json` | Process check results per session, for joining your labels. |
121
+ | `index/items.json`, `index/workitems.jsonl` | Work items joined across sessions, and their `pi.workitem` and `pi.stall` records. |
122
+ | `index/lines.json` | Cached `git diff --numstat` line counts between evidence commits. |
119
123
  | `changes.jsonl`, `marks.jsonl` | The change timeline and your notes. |
120
- | `labels.jsonl` | Your labels, when you add them (a later phase): `{ "session_id", "evaluation_name", "label": "pass" \| "fail" }` per line. The report then shows how often you and the automatic checks agree. |
124
+ | `labels.jsonl` | Your labels, when you add them (a later phase): `{ "session_id", "evaluation_name", "label": "pass" \| "fail" \| "unclear" }` per line. The report then shows how often you and the automatic checks agree; `unclear` labels are counted apart. |
121
125
  | `reports/report.html`, `reports/model.json` | The report. |
122
126
 
123
127
  The record format is in [docs/schema.md](docs/schema.md); the decisions behind it are in [docs/design.md](docs/design.md).
package/dist/build.js CHANGED
@@ -11,7 +11,8 @@ import { buildChanges, versionAt, writeChanges } from "./changes.js";
11
11
  import { dayOf } from "./paths.js";
12
12
  import { NAMES, traceId } from "./schema.js";
13
13
  import { liveFiles, readRecords } from "./store.js";
14
- export const ANCHORLOOP_PACKAGES = ["pi-anchorloop", "pi-aaaav", "aaaav"];
14
+ import { ANCHORLOOP, joinWork, Lines, sbDirOf, writeWork } from "./work/join.js";
15
+ export const ANCHORLOOP_PACKAGES = ANCHORLOOP;
15
16
  function atomicWrite(file, text) {
16
17
  mkdirSync(dirname(file), { recursive: true });
17
18
  const tmp = `${file}.${process.pid}.tmp`;
@@ -249,6 +250,14 @@ export function buildIndex(options) {
249
250
  atomicWrite(layout.days, JSON.stringify(index));
250
251
  atomicWrite(layout.sessionRows, JSON.stringify(rows));
251
252
  atomicWrite(layout.sessionEvals, JSON.stringify(sessionEvals));
253
+ const now = options.now?.() ?? new Date();
254
+ try {
255
+ const work = joinWork({ summaries, changes, sbDir: sbDirOf(options.agentDir), repos: options.settings.changeRepos, lines: new Lines(layout.lines, now), now });
256
+ writeWork(layout, work);
257
+ }
258
+ catch (error) {
259
+ errors.push(`work items: ${error instanceof Error ? error.message : String(error)}`);
260
+ }
252
261
  return { index, changes, errors };
253
262
  }
254
263
  export function loadRows(layout) {
@@ -7,7 +7,7 @@ import { Worker } from "node:worker_threads";
7
7
  import { fileKey } from "../schema.js";
8
8
  import { extractFile } from "./file.js";
9
9
  /** Bump when extraction changes what it derives; a checkpoint from another version re-reads every file. */
10
- export const EXTRACTOR_VERSION = 2;
10
+ export const EXTRACTOR_VERSION = 4;
11
11
  export function loadCheckpoint(file) {
12
12
  if (!existsSync(file))
13
13
  return { v: 1, extractor: EXTRACTOR_VERSION, files: {}, catalogs: {} };
@@ -10,9 +10,14 @@ import { dayOf } from "../paths.js";
10
10
  import { projectKey } from "../project.js";
11
11
  import { NAMES, record, safeName, spanId, traceId } from "../schema.js";
12
12
  import { skillFromPath, skillsFromBlocks, skillsFromCatalog, skillsFromCommand } from "../skills.js";
13
+ import { WorkTracker } from "../work/track.js";
13
14
  const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
14
15
  const CHILD_FILE = new RegExp(`_(${UUID})-[0-9a-f]{8}-[0-9a-f]{8}-[0-9a-f]{4}\\.jsonl$`);
15
16
  const BRIEF_PARENT = new RegExp(`/artifacts/(${UUID})/context/`);
17
+ /** The subagent name in a brief path `…/context/<name>-<YYYY-MM-DDTHH-MM-SS>.md`. */
18
+ const BRIEF_NAME = new RegExp(`/artifacts/${UUID}/context/([A-Za-z0-9_.-]+?)-\\d{4}-\\d{2}-\\d{2}T[0-9-]+\\.md`);
19
+ /** Question tools: the main waits on a person while one runs. */
20
+ const HUMAN_WAIT = new Set(["ask_user_question", "ask_user", "secret_drop"]);
16
21
  const ASK_TOOLS = new Set(["ask_user_question", "ask_user"]);
17
22
  const obj = (v) => (v && typeof v === "object" ? v : {});
18
23
  const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : 0);
@@ -48,6 +53,9 @@ export class SessionReader {
48
53
  notices = {};
49
54
  firstUser = true;
50
55
  model;
56
+ childName;
57
+ cwd;
58
+ work = new WorkTracker();
51
59
  logicalId;
52
60
  home;
53
61
  emit;
@@ -86,6 +94,7 @@ export class SessionReader {
86
94
  if (!this.start && ts)
87
95
  this.start = ts;
88
96
  const kind = this.tracker.feed(entry);
97
+ this.work.entry(entry, ts);
89
98
  if (type === "model_change") {
90
99
  this.model = safeName(`${str(entry.provider) ?? "?"}/${str(entry.modelId) ?? "?"}`);
91
100
  }
@@ -113,6 +122,9 @@ export class SessionReader {
113
122
  this.sessionId = safeName(str(entry.id) ?? "");
114
123
  this.start = str(entry.timestamp) ?? this.start;
115
124
  this.project = safeName(projectKey(str(entry.cwd), this.home));
125
+ const cwd = str(entry.cwd);
126
+ if (cwd && safeName(cwd) === cwd)
127
+ this.cwd = cwd;
116
128
  }
117
129
  system(message) {
118
130
  const sections = obj(message.sections);
@@ -124,9 +136,13 @@ export class SessionReader {
124
136
  const text = textOf(message.content);
125
137
  if (this.firstUser) {
126
138
  this.firstUser = false;
127
- const parent = text.slice(0, 2000).match(BRIEF_PARENT)?.[1];
139
+ const head = text.slice(0, 2000);
140
+ const parent = head.match(BRIEF_PARENT)?.[1];
128
141
  if (parent && this.logicalId)
129
142
  this.parentId = parent;
143
+ const name = head.match(BRIEF_NAME)?.[1];
144
+ if (name && this.logicalId)
145
+ this.childName = safeName(name);
130
146
  }
131
147
  const anchor = str(entry.id) ?? ts;
132
148
  this.closeTrace();
@@ -179,6 +195,7 @@ export class SessionReader {
179
195
  day.usage.calls += 1;
180
196
  bump(day.models, model);
181
197
  this.cost += u.cost;
198
+ this.work.assistant(ts, u.cost, message.stopReason);
182
199
  this.tokens += num(usage.totalTokens) || u.input + u.output + u.cacheRead + u.cacheWrite;
183
200
  if (this.traceUsage) {
184
201
  this.traceUsage.input += u.input;
@@ -261,9 +278,23 @@ export class SessionReader {
261
278
  attrs["gen_ai.request.model"] = model;
262
279
  attrs["pi.subagent.logical_id"] = child;
263
280
  bump(day.subagents, `${role}|${model}`);
264
- if (child)
265
- this.spawned.push({ id: child, role, model });
281
+ if (child) {
282
+ const name = str(details.name) ? safeName(details.name) : undefined;
283
+ const item = str(details.item) ? safeName(details.item) : undefined;
284
+ this.spawned.push({ id: child, role, model, name });
285
+ this.work.launch({ id: child, name, role, model, item, at: ts });
286
+ }
287
+ }
288
+ if (!isError && call && HUMAN_WAIT.has(name))
289
+ this.work.wait(call.ts, ts, "human");
290
+ if (!isError && name === "subagent_resume" && str(details.name))
291
+ this.work.child(ts, String(details.name), "resume");
292
+ if (!isError && name === "boss_pair" && str(details.thread)) {
293
+ const opt = (v) => (str(v) ? safeName(v) : undefined);
294
+ this.work.pair({ thread: safeName(details.thread), worker: opt(details.worker), reviewer: opt(details.reviewer), item: opt(details.item), at: ts });
266
295
  }
296
+ if (!isError && name === "boss_wrap")
297
+ this.work.wrap(ts, details.wrapped === true);
267
298
  if (call?.monitor && !isError) {
268
299
  const monitorId = textOf(message.content).concat(" ", str(details.summary) ?? "").match(/Monitor #(\d+)/)?.[1];
269
300
  day.monitors.started += 1;
@@ -306,6 +337,9 @@ export class SessionReader {
306
337
  for (const skill of skillsFromBlocks(textOf(entry.content)))
307
338
  this.skillLoad(skill, "declared", ts);
308
339
  }
340
+ else if (type === "subagent_result" && str(obj(entry.details).name)) {
341
+ this.work.child(ts, String(obj(entry.details).name), "result");
342
+ }
309
343
  else if (kind) {
310
344
  bump(this.notices, kind);
311
345
  bump(this.day(ts).notices, kind);
@@ -417,6 +451,9 @@ export class SessionReader {
417
451
  kind: this.logicalId ? "subagent" : "interactive",
418
452
  logicalId: this.logicalId,
419
453
  parentId: this.parentId,
454
+ model: this.model,
455
+ childName: this.childName,
456
+ cwd: this.cwd,
420
457
  spawned: this.spawned,
421
458
  cost: this.cost,
422
459
  tokens: this.tokens,
@@ -425,6 +462,9 @@ export class SessionReader {
425
462
  notices: this.notices,
426
463
  days: this.days,
427
464
  };
465
+ const work = this.work.finish(this.sessionId, !!this.logicalId);
466
+ if (work)
467
+ summary.work = work;
428
468
  return { summary, catalog: this.catalog };
429
469
  }
430
470
  }
package/dist/findings.js CHANGED
@@ -3,6 +3,7 @@ import { overview, readings, value, verdict } from "./report/findings.js";
3
3
  import { words } from "./report/format.js";
4
4
  import { safeName } from "./schema.js";
5
5
  import { trendPair } from "./trends.js";
6
+ import { itemsFinding } from "./work/query.js";
6
7
  export const scriptsDir = fileURLToPath(new URL("../scripts", import.meta.url));
7
8
  /** Shorten only identifiers, never a verdict or its drill-down pointer. */
8
9
  function name(s) {
@@ -34,6 +35,9 @@ export function findings(m) {
34
35
  const gate = !cov ? "not measured" : !cov.old.files ? "no old files" : cov.notIndexed.files || cov.notIndexed.bytes
35
36
  ? `blocked: ${cov.notIndexed.files}/${cov.old.files} old files not indexed` : `all ${cov.old.files} old files indexed`;
36
37
  lines.push(`Cleanup (all projects/dates): ${gate} → coverage`);
38
+ const work = itemsFinding(m.work);
39
+ if (work)
40
+ lines.push(work);
37
41
  const w = m.weekly;
38
42
  if (!w)
39
43
  lines.push("Need two weeks in range for error trends → packages / monitors");
package/dist/meta.js CHANGED
@@ -142,7 +142,7 @@ export const METRICS = {
142
142
  label: t("Your verdict matches the automatic check", "你的判斷與自動檢查一致"),
143
143
  meaning: t("How far the automatic check can be trusted: it is the share of sessions you labelled where you and it gave the same verdict.", "自動檢查有多可信:在你標記過的工作階段中,你和它判斷相同的比例。"),
144
144
  goodDirection: "higher",
145
- howComputed: t("Sessions where your label equals the check's label, divided by sessions you labelled for that check.", "你的標記與檢查結果相同的工作階段數,除以你為該檢查標記的工作階段數。"),
145
+ howComputed: t("Sessions where your label equals the check's label, divided by sessions you labelled pass or fail for that check; labels marked unclear are counted apart.", "你的標記與檢查結果相同的工作階段數,除以你為該檢查標成通過或未通過的工作階段數;標成「看不出來」的另外計數。"),
146
146
  },
147
147
  coverage: {
148
148
  label: t("Old sessions already indexed", "已建索引的舊工作階段"),
@@ -174,6 +174,48 @@ export const METRICS = {
174
174
  goodDirection: "none",
175
175
  howComputed: t("Set when the window before starts before the first session or the window after ends after the last extract; the days with data on each side are shown.", "變更前的期間早於第一個工作階段、或變更後的期間晚於上次抽取時標記;並列出兩邊各有資料的天數。"),
176
176
  },
177
+ item_cost: {
178
+ label: t("Cost of a work item", "一項工作的花費"),
179
+ meaning: t("What one todo item cost from start to close: the subagents that worked on it plus its share of the main agent.", "一項待辦從開始到收尾花了多少:做它的子代理,加上主代理分給它的部分。"),
180
+ goodDirection: "lower",
181
+ howComputed: t("Child cost is exact (every reply of each joined subagent session added up); main cost is the main's replies while the item was in progress, each split evenly among the items in progress at that moment.", "子代理費用是精確的(每個對到的子代理工作階段,每次回覆的費用加總);主代理費用取這項工作進行中時主代理的每次回覆,平均分給當下所有進行中的工作。"),
182
+ },
183
+ item_minutes: {
184
+ label: t("Minutes in progress", "進行中的分鐘數"),
185
+ meaning: t("How long the item was marked in progress; queue time before it started is not counted.", "這項工作標成「進行中」的時間;開始前排隊等待的時間不算。"),
186
+ goodDirection: "none",
187
+ howComputed: t("From each switch to in_progress to the next switch away from it, added up.", "每次切到「進行中」到下一次離開它的時間,加總。"),
188
+ },
189
+ item_stall: {
190
+ label: t("Stall time", "停頓時間"),
191
+ meaning: t("Time inside an item's window when the main agent sat idle for two minutes or more, by what woke it.", "工作進行中,主代理閒著超過兩分鐘的時間,依叫醒它的是誰分類。"),
192
+ goodDirection: "lower",
193
+ howComputed: t("A stall starts when the main ends a turn (or asks you a question) and ends at the next prompt, peer message, subagent result, timer or job ending; gaps under two minutes are left out.", "主代理結束一輪(或開始問你問題)時開始,下一個提示、其他工作階段的訊息、子代理結果、排程或背景工作結束時結束;少於兩分鐘不算。"),
194
+ },
195
+ item_per_100_lines: {
196
+ label: t("Cost per 100 changed lines", "每百行改動的花費"),
197
+ meaning: t("Cost scaled by the size of the change, so a big item and a small one can be compared.", "把花費除以改動大小,大工作和小工作才比得起來。"),
198
+ goodDirection: "lower",
199
+ howComputed: t("Item cost divided by added plus deleted lines (git) from the previous item's last evidence commit to this item's last, times 100; only items whose evidence names commits.", "工作花費除以從上一項工作最後的證據提交到這項最後的證據提交之間,git 增刪的行數,再乘 100;只算證據有記提交的工作。"),
200
+ },
201
+ };
202
+ export const CLOSE_KIND_META = {
203
+ review_done: t("Reviewer approved", "審查通過"),
204
+ landed: t("Car landed", "車已進站(合併)"),
205
+ wrap: t("Closed at a wrap", "收工時結束"),
206
+ evidence: t("Done with evidence", "附證據完成"),
207
+ unproven: t("Marked done, no evidence", "標完成,沒附證據"),
208
+ deleted: t("Deleted", "刪除"),
209
+ open: t("Still open", "還開著"),
210
+ };
211
+ export const STALL_KIND_META = {
212
+ human: t("waiting for you", "等你"),
213
+ peer: t("waiting for another session", "等其他工作階段"),
214
+ child: t("waiting for a subagent", "等子代理"),
215
+ timer: t("waiting for a timer", "等排程喚醒"),
216
+ ci: t("waiting for a background job", "等背景工作"),
217
+ device: t("waiting for another device", "等其他裝置"),
218
+ working: t("still working (never stopped)", "還在做(沒停下來)"),
177
219
  };
178
220
  export const DETECTOR_META = {
179
221
  anchor_before_first_edit: {
package/dist/model.js CHANGED
@@ -5,10 +5,11 @@
5
5
  import { existsSync, readFileSync } from "node:fs";
6
6
  import { ASK_BUCKETS, emptyDay, mergeDay } from "./aggregate.js";
7
7
  import { DETECTORS, ERA_START } from "./detectors.js";
8
- import { CHANGE_KIND_META, DETECTOR_META, METRICS, NOTICE_META } from "./meta.js";
8
+ import { CHANGE_KIND_META, CLOSE_KIND_META, DETECTOR_META, METRICS, NOTICE_META, STALL_KIND_META } from "./meta.js";
9
9
  import { staticOwner } from "./owners.js";
10
10
  import { weeklyRises } from "./trends.js";
11
11
  import { traceId } from "./schema.js";
12
+ import { workModel } from "./work/model.js";
12
13
  export const SMALL_SAMPLE = 20;
13
14
  /** Data older than this (hours) is reported as stale. */
14
15
  export const STALE_HOURS = 24;
@@ -154,7 +155,7 @@ export function impactFromRows(rows, change, all, windowDays, range, ownerOf) {
154
155
  }
155
156
  function labelsJoin(labelsFile, evalsFile, sessionIds) {
156
157
  if (!existsSync(labelsFile))
157
- return { present: false, n: 0, agreement: [] };
158
+ return { present: false, n: 0, unclear: 0, agreement: [] };
158
159
  const codeLabels = existsSync(evalsFile) ? JSON.parse(readFileSync(evalsFile, "utf8")) : {};
159
160
  const rows = readFileSync(labelsFile, "utf8")
160
161
  .split("\n")
@@ -169,20 +170,28 @@ function labelsJoin(labelsFile, evalsFile, sessionIds) {
169
170
  });
170
171
  const by = new Map();
171
172
  let n = 0;
173
+ let unclear = 0;
172
174
  for (const row of rows) {
173
175
  if (sessionIds && !sessionIds.has(traceId(row.session_id, "labels")))
174
176
  continue;
175
177
  n++;
178
+ const t = by.get(row.evaluation_name) ?? { n: 0, agree: 0, unclear: 0 };
179
+ // "Cannot tell" is the reader's honest answer, not a disagreement: count it apart from the agreement rate.
180
+ if (row.label === "unclear") {
181
+ unclear += 1;
182
+ t.unclear += 1;
183
+ by.set(row.evaluation_name, t);
184
+ continue;
185
+ }
176
186
  const code = codeLabels[row.session_id]?.[row.evaluation_name];
177
187
  if (!code || code === "na")
178
188
  continue;
179
- const t = by.get(row.evaluation_name) ?? { n: 0, agree: 0 };
180
189
  t.n += 1;
181
190
  if (code === row.label)
182
191
  t.agree += 1;
183
192
  by.set(row.evaluation_name, t);
184
193
  }
185
- return { present: true, n, agreement: [...by].map(([detector, t]) => ({ detector, n: t.n, agree: t.agree, rate: rate(t.agree, t.n) })) };
194
+ return { present: true, n, unclear, agreement: [...by].map(([detector, t]) => ({ detector, n: t.n, agree: t.agree, rate: rate(t.agree, t.n), unclear: t.unclear })) };
186
195
  }
187
196
  export function buildModel(options) {
188
197
  const { index, filter } = options;
@@ -236,7 +245,7 @@ export function buildModel(options) {
236
245
  weekly: weeklyRises(index, filter.since ?? earliest, filter.project),
237
246
  window: { since: filter.since ?? earliest ?? null, until: filter.until ?? days.at(-1) ?? null, days: days.length, project: filter.project ?? null },
238
247
  freshness: { lastExtract: lastExtract ?? null, built: index.built, stale: ageHours > STALE_HOURS, ageHours: Number.isFinite(ageHours) ? round(ageHours, 1) : null },
239
- meta: { metrics: METRICS, detectors: DETECTOR_META, notices: NOTICE_META, changeKinds: CHANGE_KIND_META },
248
+ meta: { metrics: METRICS, detectors: DETECTOR_META, notices: NOTICE_META, changeKinds: CHANGE_KIND_META, closeKinds: CLOSE_KIND_META, stallKinds: STALL_KIND_META },
240
249
  totals: {
241
250
  sessions: total.sessions,
242
251
  subagentSessions: total.subagentSessions,
@@ -324,5 +333,6 @@ export function buildModel(options) {
324
333
  .map((c) => ({ ...c, impact: index.range.start && c.at > index.range.start ? impactFromRows(projectRows, c, sortedChanges, options.windowDays, index.range, owner) : null })),
325
334
  labels: { ...labelsJoin(options.labelsFile, options.sessionEvalsFile, labelIds), needsIndex: !!labelIds && !hasSessionIds },
326
335
  coverage: options.coverage ?? null,
336
+ work: workModel(options.work, filter),
327
337
  };
328
338
  }
package/dist/ops.js CHANGED
@@ -9,6 +9,7 @@ import { PRESETS, rangeFilter, suffix } from "./ranges.js";
9
9
  import { buildModel } from "./model.js";
10
10
  import { agentDir, home, layout, loadSettings, stateDir } from "./paths.js";
11
11
  import { renderHtml } from "./render.js";
12
+ import { loadWork } from "./work/join.js";
12
13
  export function context(env = process.env) {
13
14
  const settings = loadSettings(env);
14
15
  const lay = layout(stateDir(env));
@@ -61,12 +62,12 @@ function snapshot(env, withCoverage = true) {
61
62
  const ctx = context(env), index = loadIndex(ctx.layout);
62
63
  if (!index)
63
64
  return;
64
- const rows = loadRows(ctx.layout), changes = readChanges(ctx.layout.changes), now = new Date();
65
+ const rows = loadRows(ctx.layout), changes = readChanges(ctx.layout.changes), now = new Date(), work = loadWork(ctx.layout);
65
66
  const cov = withCoverage ? coverageReader(ctx, now) : undefined;
66
67
  return { index, build(input, preset, comparisons) {
67
68
  const filter = rangeFilter(input, index.lastExtract ?? now.toISOString(), preset);
68
69
  return buildModel({ index, rows, changes, comparisons, filter, now, windowDays: ctx.settings.impactWindowDays,
69
- labelsFile: ctx.layout.labels, sessionEvalsFile: ctx.layout.sessionEvals, coverage: cov?.(filter) });
70
+ labelsFile: ctx.layout.labels, sessionEvalsFile: ctx.layout.sessionEvals, coverage: cov?.(filter), work });
70
71
  } };
71
72
  }
72
73
  export function indexedModel(filter, env, withCoverage = true) {
package/dist/paths.js CHANGED
@@ -70,6 +70,9 @@ export function layout(state = stateDir()) {
70
70
  labels: join(state, "labels.jsonl"),
71
71
  status: join(state, "index", "status.json"),
72
72
  reports: join(state, "reports"),
73
+ items: join(state, "index", "items.json"),
74
+ itemRecords: join(state, "index", "workitems.jsonl"),
75
+ lines: join(state, "index", "lines.json"),
73
76
  };
74
77
  }
75
78
  /** UTC day of an epoch-ms or ISO time. */
package/dist/query.js CHANGED
@@ -2,7 +2,8 @@
2
2
  import { coverageInRange, indexedModel, reportPath } from "./ops.js";
3
3
  import { findings } from "./findings.js";
4
4
  import { select } from "./report/findings.js";
5
- export const VIEWS = ["findings", "skills", "packages", "ask_user", "monitors", "subagents", "process", "cost", "changes", "coverage"];
5
+ import { itemsView } from "./work/query.js";
6
+ export const VIEWS = ["findings", "items", "skills", "packages", "ask_user", "monitors", "subagents", "process", "cost", "changes", "coverage"];
6
7
  export const MAX_BYTES = 1900;
7
8
  const pct = (r) => (r && r.value !== null ? `${(r.value * 100).toFixed(1)}% (n=${r.n})` : `n/a (n=${r?.n ?? 0})`);
8
9
  const sec = (v) => (v === null ? "n/a" : `${(v / 1000).toFixed(1)}s`);
@@ -95,6 +96,9 @@ export function query(view, options = {}) {
95
96
  for (const s of m.cost.bySkill.slice(0, 10))
96
97
  body.push(`${s.skill}: $${s.cost} over ${s.sessions} sessions`);
97
98
  }
99
+ else if (view === "items") {
100
+ body.push(...itemsView(m.work));
101
+ }
98
102
  else if (view === "changes") {
99
103
  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");
100
104
  const { highlighted, folded } = select(m);
package/dist/render.js CHANGED
@@ -16,6 +16,7 @@ function weeklyPanel(m, L) {
16
16
  export function renderHtml(m, lang = "zh", range = "custom") {
17
17
  const L = words(lang), w = periodRows(m), t = timeline(m, w, lang, range), c = concepts(m, w, t.lead, L);
18
18
  const nav = [
19
+ ["work", L("Work items", "工作")],
19
20
  ["archive", L("All changes", "所有調整")],
20
21
  ["skills", L("Skills", "技能")],
21
22
  ["packages", L("Tools", "套件與工具")],
@@ -1,4 +1,25 @@
1
- import { esc, num } from "./format.js";
1
+ import { esc, num, usd } from "./format.js";
2
+ import { verdictText } from "./work.js";
3
+ /** The two work-item ideas, with this report's own numbers. */
4
+ function workCards(m, L) {
5
+ const w = m.work;
6
+ if (!w) {
7
+ const none = L("Run /evals extract to see the numbers.", "請執行 /evals extract 看這段期間的數字。");
8
+ return { attribution: [L("Who a cost belongs to", "花費歸屬"), none], cheaper: [L("When is one way cheaper?", "怎麼比才算比較省"), none] };
9
+ }
10
+ const first = w.compare.find((c) => c.kind === "delegated") ?? w.compare[0];
11
+ const now = first ? verdictText(first, first.verdict, L) : L("No finished items to compare yet.", "還沒有完成的工作可以比。");
12
+ return {
13
+ attribution: [
14
+ L("Who a cost belongs to", "花費歸屬"),
15
+ L(`Subagent cost is exact: every reply of every subagent session joined to an item is added up, ${usd(w.cost.child)} over ${num(w.delegated)} items handed to subagents here. Main-agent cost is an estimate: the main looks after several items at once, so each of its replies is split evenly among the items in progress at that moment (two at once: half each; ${num(w.shared)} items overlapped another), ${usd(w.cost.main)} in all. ${usd(w.cost.unattributed)} of main cost fell outside every item and belongs to none.`, `子代理的花費是精確的:對到某項工作的子代理工作階段,每次回覆的費用全部加起來;這段期間 ${num(w.delegated)} 件交給子代理的工作共 ${usd(w.cost.child)}。主代理的花費是估算:主代理同時照顧好幾件事,所以它每次回覆的費用,平均分給當下進行中的工作(同時兩件就各算一半;有 ${num(w.shared)} 件和別件重疊),共 ${usd(w.cost.main)}。另有 ${usd(w.cost.unattributed)} 的主代理費用不在任何工作進行中,不算進任何一件。`),
16
+ ],
17
+ cheaper: [
18
+ L("When is one way cheaper?", "怎麼比才算比較省"),
19
+ L(`Three things must hold. Compare like with like (work handed to subagents with the same, work the main did with the same). Account for size: cost per 100 changed lines, which ${num(w.withLines)} of ${num(w.completed)} finished items have. Have enough items: at least ${w.minItems} per group. Now: ${now}`, `三件事都要做到。一、只比同類:交給子代理的跟交給子代理的比,主代理自己做的跟自己做的比。二、看規模:用每百行改動的花費,這段期間 ${num(w.completed)} 件完成的工作裡有 ${num(w.withLines)} 件算得出行數。三、件數要夠:每組至少 ${w.minItems} 件。目前:${now}`),
20
+ ],
21
+ };
22
+ }
2
23
  export function concepts(m, week, c, L) {
3
24
  const i = c?.impact, n = num(week.reduce((s, r) => s + r.sessions, 0)), d = m.process.detectors.find((r) => r.name === "anchor_before_first_edit");
4
25
  return {
@@ -22,6 +43,7 @@ export function concepts(m, week, c, L) {
22
43
  ? L(`There were ${num(i.confounded)} other changes in these windows. If a rule and a package changed together, their effects cannot be separated here.`, `這段期間另有 ${num(i.confounded)} 筆調整。規則和套件若一起改,只比前後分不出哪一項影響了結果。`)
23
44
  : L(`There are ${num(m.changes.length)} changes on this timeline. Check what else changed before crediting a new version.`, `時間軸有 ${num(m.changes.length)} 筆調整。要把差異歸給某個版本,得先查同一期間還改了什麼。`),
24
45
  ],
46
+ ...workCards(m, L),
25
47
  check: [
26
48
  L("Code check", "程式檢查"),
27
49
  L(`In ${num(d?.passRate.n ?? 0)} eligible sessions, code checked whether the agent named a check before editing. It cannot judge whether that check tested the right thing.`, `程式在 ${num(d?.passRate.n ?? 0)} 段適用的工作裡查「改檔前有沒有先說怎麼驗證」。它看得出先後順序,判斷不了方法好不好。`),
@@ -1,5 +1,6 @@
1
1
  import { lesson, selfCheck } from "./concepts.js";
2
2
  import { duration, esc, num, pct, table, usd, words } from "./format.js";
3
+ import { workSection } from "./work.js";
3
4
  export function sections(m, lang, cards) {
4
5
  const L = words(lang), meta = m.meta.metrics;
5
6
  const label = (id) => meta[id].label[lang];
@@ -44,9 +45,10 @@ export function sections(m, lang, cards) {
44
45
  ? `<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", "閒置天數")} &gt; ${cov.cutDays} / ${L("Files indexed", "已建索引")} ${num(cov.indexed.files)} / ${num(cov.old.files)}</p><p>${L("Not indexed", "未建索引")}:${num(cov.notIndexed.files)} ${L("files", "個檔案")} · ${num(cov.notIndexed.bytes)} bytes</p>`
45
46
  : `<p>${L("Coverage not measured; keep cleanup off.", "沒有索引覆蓋資料,請勿開啟清理。")}</p>`);
46
47
  const labels = section("labels", L("Your labels", "你的標記"), meta.agreement.meaning[lang], m.labels.needsIndex ? `<p>${L("Run /evals extract to count labels in this period.", "請執行 /evals extract 以計算這段期間的標記。")}</p>` : m.labels.present && m.labels.n
47
- ? T([L("Check", "檢查"), L("Labelled", "已標記"), L("Agreement", "一致比例")], m.labels.agreement.map((r) => [m.meta.detectors[r.detector]?.label[lang] ?? r.detector, r.n, pct(r.rate)]))
48
+ ? T([L("Check", "檢查"), L("Labelled", "已標記"), L("Agreement", "一致比例"), L("Cannot tell", "看不出來")], m.labels.agreement.map((r) => [m.meta.detectors[r.detector]?.label[lang] ?? r.detector, r.n, pct(r.rate), r.unclear])) + `<p class="muted">${L(`Cannot tell ${num(m.labels.unclear)}: labels marked unclear are left out of the agreement rate.`, `看不出來 ${num(m.labels.unclear)}:標成「看不出來」的不算進一致比例。`)}</p>`
48
49
  : `<p>${L("No labels yet. In phase 2 you will judge sessions yourself and compare your answers with the code checks.", "還沒有標記。第二階段會讓你親自判讀工作紀錄,再對照程式與你的判斷是否一致。")}</p>`);
49
50
  return [
51
+ workSection(m, lang, cards, lesson),
50
52
  skills,
51
53
  packages,
52
54
  ask,
@@ -56,6 +58,6 @@ export function sections(m, lang, cards) {
56
58
  cost,
57
59
  coverage,
58
60
  labels,
59
- section("concepts", L("Concepts", "概念"), L("Use these five ideas when you read the next report.", "下次讀報表時,可以用這五個概念判讀數字。"), `<div class="notes-grid">${Object.values(cards).map((c) => lesson(c, L)).join("")}</div>${selfCheck(L)}`),
61
+ section("concepts", L("Concepts", "概念"), L(`Use these ${Object.keys(cards).length} ideas when you read the next report.`, `下次讀報表時,可以用這 ${Object.keys(cards).length} 個概念判讀數字。`), `<div class="notes-grid">${Object.values(cards).map((c) => lesson(c, L)).join("")}</div>${selfCheck(L)}`),
60
62
  ].join("");
61
63
  }
@@ -59,6 +59,10 @@ h3,.big {font-size:29px;line-height:1.35;margin:14px 0 18px}
59
59
  .scroll {overflow-x:auto}table {width:100%;border-collapse:collapse;margin:.4rem 0;background:var(--paper)}
60
60
  th,td {text-align:start;padding:7px 12px;border-bottom:1px solid var(--line)}th {font-size:15px;color:var(--green)}
61
61
  .pair,.notes-grid {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:20px}
62
+ .tiles {display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px;margin:18px 0 6px}.tiles .panel {padding:16px 18px}.tiles .big {font-size:27px;margin:6px 0}.tiles .muted {margin:0}
63
+ #work h3 {font-size:22px;margin:30px 0 10px}#work .pair {margin-top:14px}#work .lesson {margin:0}
64
+ table.items td {vertical-align:top}table.items td small {display:block;color:var(--sub);font-size:13px}table.items .item-title {min-width:14em;font-weight:600}table.items .nowrap {white-space:nowrap}
65
+ #work .panel th,#work .panel td {white-space:nowrap}#work .panel td:first-child {white-space:normal}
62
66
  .checks {margin-top:18px}.checks h3,.topic .panel h3 {font-size:22px}
63
67
  .detail {display:none;padding-bottom:24px;scroll-margin-top:75px}.detail:target {display:block;outline:none}
64
68
  body:has(.detail:target) main {display:none}.back {float:right;font-size:15px}
@@ -73,6 +77,7 @@ body:has(.detail:target) main {display:none}.back {float:right;font-size:15px}
73
77
  .notes-grid {margin:16px 0}.notes-grid .lesson {font-size:16px}
74
78
  footer {font-size:14px;margin-top:24px;padding:18px 0 25px;color:var(--sub);border-top:1px solid var(--line)}
75
79
  @media(max-width:850px) {
80
+ .tiles {grid-template-columns:repeat(2,minmax(0,1fr))}
76
81
  .layout,.pair,.notes-grid {grid-template-columns:1fr}.layout {gap:22px}.rail {padding-left:27px}.rail:before {left:7px}.card:before {left:-26px}
77
82
  .reading {flex-wrap:wrap}.ruler-head,footer {align-items:flex-start;flex-direction:column}
78
83
  }
@@ -0,0 +1,59 @@
1
+ import { esc, num, usd, words } from "./format.js";
2
+ const SHOWN = 15;
3
+ export function span(minutes, L) {
4
+ if (minutes < 90)
5
+ return L(`${Math.round(minutes)} min`, `${Math.round(minutes)} 分`);
6
+ if (minutes < 48 * 60)
7
+ return L(`${(minutes / 60).toFixed(1)} h`, `${(minutes / 60).toFixed(1)} 小時`);
8
+ return L(`${(minutes / 1440).toFixed(1)} days`, `${(minutes / 1440).toFixed(1)} 天`);
9
+ }
10
+ const pct = (v) => `${Math.round(v * 100)}%`;
11
+ export function verdictText(c, v, L, lines = false) {
12
+ const g = (value) => c.groups.find((x) => x.value === value);
13
+ const n = (value) => (lines ? g(value)?.nLines : g(value)?.n) ?? 0;
14
+ const what = lines ? L("per 100 changed lines", "每百行") : L("per item", "每件");
15
+ if (v.kind === "single")
16
+ return v.a ? L(`Only one group (${v.a}): nothing to compare it with.`, `只有一組(${v.a}),沒有可比的對象。`) : L("No items with a line count.", "沒有算得出行數的工作。");
17
+ if (v.kind === "few")
18
+ return L(`Too few items to tell yet (${v.a} ${n(v.a)}, ${v.b} ${n(v.b)}; each group needs 5).`, `件數太少,還看不出來(${v.a} ${n(v.a)} 件、${v.b} ${n(v.b)} 件,每組至少要 5 件)。`);
19
+ if (v.kind === "same")
20
+ return L(`${v.a} and ${v.b} cost about the same ${what} (less than 20% apart).`, `${v.a} 和 ${v.b} ${what}花費差不到兩成,看不出差別。`);
21
+ return L(`${v.a} costs ${pct(v.by ?? 0)} less ${what} than ${v.b} (median of ${n(v.a)} and ${n(v.b)} items of the same kind). This is a difference, not its cause.`, `${v.a} ${what}比 ${v.b} 便宜 ${pct(v.by ?? 0)}(同類工作的中位數,各 ${n(v.a)}、${n(v.b)} 件)。這是差異,不是原因。`);
22
+ }
23
+ function stallText(stalls, m, lang) {
24
+ const L = words(lang);
25
+ const parts = Object.entries(stalls)
26
+ .sort((a, b) => b[1] - a[1])
27
+ .map(([k, v]) => `${m.meta.stallKinds[k]?.[lang] ?? k} ${span(v, L)}`);
28
+ return parts.join(L(", ", "、")) || "—";
29
+ }
30
+ export function workSection(m, lang, cards, lesson) {
31
+ const L = words(lang);
32
+ const w = m.work;
33
+ const head = `<section id="work" class="topic"><p class="eyebrow">PI-EVALS / ${L("Work items", "工作")}</p><h2>${L("Work items: what each cost, where it closed, where it stalled", "工作:每一項花多少、在哪裡收尾、卡在哪裡")}</h2>`;
34
+ if (!w)
35
+ return `${head}<p class="intro">${L("Run /evals extract to build the work items.", "請執行 /evals extract 建立工作項目。")}</p></section>`;
36
+ const meta = m.meta.metrics;
37
+ const close = (k) => m.meta.closeKinds[k]?.[lang] ?? k;
38
+ const dims = { role: L("role", "角色"), model: L("model", "模型"), anchorloop: L("anchorloop version", "anchorloop 版本") };
39
+ const kinds = { delegated: L("Work handed to subagents", "交給子代理做的工作"), self: L("Work the main agent did itself", "主代理自己做的工作") };
40
+ const stallTotal = Object.values(w.stallMs).reduce((s, v) => s + v, 0);
41
+ const row = (r) => `<tr><td class="item-title">${esc(r.title || r.key)}</td><td>${esc(r.owner ?? "—")}</td><td class="nowrap">${usd(r.main + r.child)}<small>${r.child > 0 ? `${L("main", "主")} ${usd(r.main)}+${L("sub", "子")} ${usd(r.child)}` : L("main agent only", "只有主代理")}</small></td><td class="nowrap">${esc(span(r.minutes, L))}</td><td>${esc(close(r.closeKind))}${r.thread ? `<small>${esc(r.thread)}</small>` : ""}</td><td>${esc(stallText(r.stalls, m, lang))}</td></tr>`;
42
+ const listHead = `<thead><tr><th scope="col">${L("Item", "工作")}</th><th scope="col">${L("Owner", "誰做")}</th><th scope="col">${L("Cost (main + subagents)", "花費(主+子)")}</th><th scope="col">${L("In progress", "進行")}</th><th scope="col">${L("Closed by", "收尾方式")}</th><th scope="col">${L("Stalls", "停頓")}</th></tr></thead>`;
43
+ const list = w.list.length
44
+ ? `<div class="scroll"><table class="items">${listHead}<tbody>${w.list.slice(0, SHOWN).map(row).join("")}</tbody></table></div>${w.list.length > SHOWN ? `<details><summary>${L(`${w.list.length - SHOWN} more`, `再看 ${w.list.length - SHOWN} 項`)}</summary><div class="scroll"><table class="items">${listHead}<tbody>${w.list.slice(SHOWN).map(row).join("")}</tbody></table></div></details>` : ""}`
45
+ : `<p class="muted">${L("No item closed in this period.", "這段期間沒有收尾的工作。")}</p>`;
46
+ const compare = w.compare.length
47
+ ? w.compare
48
+ .map((c) => `<article class="panel"><h3>${esc(kinds[c.kind])} / ${L("by", "依")}${esc(dims[c.dimension])}</h3><div class="scroll"><table><thead><tr><th scope="col">${esc(dims[c.dimension])}</th><th scope="col">${L("Items", "件數")}</th><th scope="col">${L("Median per item", "每件中位數")}</th><th scope="col">${L("Per 100 lines (items)", "每百行(件數)")}</th></tr></thead><tbody>${c.groups.map((g) => `<tr><td>${esc(g.value)}</td><td>${num(g.n)}</td><td>${usd(g.median)}</td><td>${g.per100 === null ? "—" : `${usd(g.per100)}(${num(g.nLines)})`}</td></tr>`).join("")}</tbody></table></div><p class="verdict">${esc(verdictText(c, c.verdict, L))}</p><p class="muted">${esc(verdictText(c, c.verdictLines, L, true))}</p></article>`)
49
+ .join("")
50
+ : `<p class="muted">${L("No finished items to compare.", "沒有可比較的已完成工作。")}</p>`;
51
+ const open = w.open.length
52
+ ? `<div class="scroll"><table class="items"><thead><tr><th scope="col">${L("Item", "工作")}</th><th scope="col">${L("Stopped at", "停在哪")}</th><th scope="col">${L("Waiting on", "等誰")}</th><th scope="col">${L("For how long", "多久")}</th></tr></thead><tbody>${w.open
53
+ .map((o) => `<tr><td class="item-title">${esc(o.title || o.key)}</td><td>${esc(m.meta.stallKinds[o.kind]?.[lang] ?? o.kind)}</td><td>${esc(o.on ?? (o.kind === "human" ? L("you (next prompt)", "你(下一個指示)") : "—"))}${o.owner && o.owner !== o.on ? `<small>${esc(o.owner)}</small>` : ""}</td><td>${esc(span(o.waitMinutes, L))}<small>${L("since", "自")} ${esc(o.since.slice(5, 16).replace("T", " "))} UTC</small></td></tr>`)
54
+ .join("")}</tbody></table></div>`
55
+ : `<p class="muted">${L("Nothing open in this period.", "這段期間沒有還開著的工作。")}</p>`;
56
+ const tile = (label, big, note) => `<article class="panel"><p class="eyebrow">${esc(label)}</p><p class="big">${big}</p><p class="muted">${note}</p></article>`;
57
+ const kindRows = Object.entries(w.closeKinds).filter(([, n]) => n > 0).map(([k, n]) => `${esc(close(k))} ${num(n)}`).join(L(", ", "、"));
58
+ return `${head}<p class="intro">${L("A work item is one todo task, from the moment it was switched to in progress until it was marked done or deleted. Time spent waiting in the queue before that does not count.", "一項工作就是待辦清單上的一列:從它被切到「進行中」開始,到標成完成或刪除為止。開始前排隊的時間不算。")}</p><div class="tiles">${tile(L("Items", "件數"), num(w.completed), L(`finished; ${num(w.inProgress)} in progress, ${num(w.pending)} not started, ${num(w.deleted)} deleted`, `件完成;進行中 ${num(w.inProgress)}、還沒開始 ${num(w.pending)}、刪掉 ${num(w.deleted)}`))}${tile(L("Cost of finished items", "完成工作的總花費"), usd(w.cost.main + w.cost.child), L(`subagents ${usd(w.cost.child)} (exact) + main ${usd(w.cost.main)} (estimated)`, `子代理 ${usd(w.cost.child)}(精確)+主代理 ${usd(w.cost.main)}(估算)`))}${tile(L("Median item", "每件中位數"), usd(w.cost.median), L(`${w.cost.medianMinutes === null ? "—" : span(w.cost.medianMinutes, L)} in progress`, `進行 ${w.cost.medianMinutes === null ? "—" : span(w.cost.medianMinutes, L)}`))}${tile(meta.item_stall.label[lang], span(stallTotal / 60_000, L), L(`of ${span(w.activeMs / 60_000, L)} in progress`, `占進行中 ${span(w.activeMs / 60_000, L)}`) + "<br>" + esc(stallText(Object.fromEntries(Object.entries(w.stallMs).filter(([, v]) => v > 0).map(([k, v]) => [k, v / 60_000])), m, lang)))}</div><p class="muted">${L("How items closed", "收尾方式")}:${kindRows || "—"}</p><h3>${L("Latest finished items", "最近完成的工作")}</h3>${list}<p class="muted">${esc(meta.item_stall.howComputed[lang])}</p><div class="pair">${lesson(cards.attribution, L)}${lesson(cards.cheaper, L)}</div><h3>${L("Is one way cheaper?", "有沒有比較省?")}</h3><p class="intro">${L("Each panel compares only items of the same kind; a group needs at least 5 items.", "每一格只比同一類的工作;每組至少 5 件才下結論。")}</p><div class="pair">${compare}</div><h3>${L("Still open: stopped where, waiting on whom, for how long", "還開著的工作:停在哪、等誰、多久")}</h3>${open}</section>`;
59
+ }