pi-evals 0.5.2 → 0.6.1
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 +12 -0
- package/README.md +21 -3
- package/dist/ask-ai.js +58 -0
- package/dist/asks.js +53 -0
- package/dist/changes.js +15 -0
- package/dist/detectors.js +25 -3
- package/dist/extract/run.js +5 -7
- package/dist/extract/session.js +1 -1
- package/dist/index.js +3 -1
- package/dist/labels-query.js +2 -0
- package/dist/live-labels.js +7 -31
- package/dist/meta.js +11 -0
- package/dist/model.js +42 -3
- package/dist/ops.js +1 -1
- package/dist/paths.js +1 -0
- package/dist/plan-graph.js +116 -0
- package/dist/query.js +5 -0
- package/dist/report/findings.js +17 -4
- package/dist/report/sections.js +10 -3
- package/dist/report/strip.js +2 -1
- package/dist/turn-window.js +37 -0
- package/docs/design.md +5 -3
- package/docs/schema.md +14 -1
- package/package.json +1 -1
- package/skills/analyzing-evals/SKILL.md +8 -0
- package/src/ask-ai.ts +70 -0
- package/src/asks.ts +60 -0
- package/src/changes.ts +14 -0
- package/src/detectors.ts +7 -3
- package/src/extract/run.ts +11 -6
- package/src/extract/session.ts +1 -1
- package/src/index.ts +3 -1
- package/src/labels-query.ts +1 -0
- package/src/live-labels.ts +7 -30
- package/src/meta.ts +19 -0
- package/src/model.ts +41 -3
- package/src/ops.ts +1 -1
- package/src/paths.ts +3 -0
- package/src/plan-graph.ts +117 -0
- package/src/query.ts +5 -0
- package/src/report/findings.ts +16 -3
- package/src/report/sections.ts +10 -3
- package/src/report/strip.ts +3 -1
- package/src/turn-window.ts +50 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
- An extract stopped part-way after an extractor upgrade no longer passes off old results as current. Each session file's summary now records the extractor version that wrote it, and any other version is read again. Before, the first 0.6.0 extract was killed by a timeout and saved the new version mark while most summaries were still old, so the next run skipped them: check agreement read 11/20 instead of 23/24 until a full rebuild. Every session is read once more (extractor version 6).
|
|
6
|
+
- New check 「排工作時說清楚怎麼分工」 (`plan_names_graph`): whether a Straw Boss coordinator or standing main names its plan's graph (`single-loop`, `fan-out/fan-in`, `orchestrator-worker`; the todo's `graph` field or an older `metadata.graph`) when it first creates open todos. It also passes when the next todo call adds the graph after sb's planning reminder (sb 0.101.0 and later). It fails when the main keeps planning without one. Unlike the anchorloop checks, it is judged in sessions of any age, since sb mains live for weeks.
|
|
7
|
+
- The process view and report also split this check by pi-straw-boss version at session start, before and from 0.101.0. The change strip always highlights the sb pin that brings 0.101.0, including one that skips it (0.100.2 → 0.102.0, captioned 「含 0.101.0」).
|
|
8
|
+
- The analyzing-evals skill gains 「When a number looks wrong」: check freshness first, validate a detector against your labels, group misses by cause, keep a guard set, and treat hand labels as the reference.
|
|
9
|
+
|
|
10
|
+
## 0.6.0
|
|
11
|
+
|
|
12
|
+
- New command `/ask-ai <question>` has the agent answer you now instead of taking the question as a reproach and starting new work. The question goes in with a short instruction: answer first, in your language, change nothing, start no work, and end with at most one line of suggested next step. While that run lasts (until it ends or you send another message), `write`, `edit`, `subagent`, `boss_pair`, `MonitorCreate`, `LoopCreate`, `call_tower`, `todo` (except `list`/`get`) and `intercom` (`send`/`ask`/`handover`) are refused with a one-line reason; `bash`, `read` and other tools still run.
|
|
13
|
+
- Each ask is recorded in `asks.jsonl` (session, time, project, todo item; never the question or the answer). The report's 「你的標記」 section and the `labels` query view say how many times you asked and how many you followed with a label in the same session within 30 minutes.
|
|
14
|
+
|
|
3
15
|
## 0.5.2
|
|
4
16
|
|
|
5
17
|
- A later human label on the same session, rule and item replaces the earlier one in the report and agreement; `labels.jsonl` keeps both. New `source: "recheck"` for your second look at a label given after the fact (counted as 事後標). Each 「其他」 label stays its own event, and agent corrections are never replaced.
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Agents can read the same numbers through one tool, `evals_query`, and log a corr
|
|
|
11
11
|
- **Ask-user**: questions asked, how long you took to answer, how many you dismissed, and whether the answer came from the terminal or a remote channel.
|
|
12
12
|
- **Monitors**: background jobs by outcome and duration.
|
|
13
13
|
- **Subagents**: launches by role and model, and their cost by role.
|
|
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).
|
|
14
|
+
- **Process**: four checks of the anchorloop rules per session, and one of the Straw Boss planning rule (a coordinator or standing main names its plan's graph), 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
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.
|
|
17
17
|
- **Your labels and corrections**: your verdict on a process rule, given in the moment with `/evals label` or after the fact, and the corrections an agent logs when you correct how it worked.
|
|
@@ -48,13 +48,30 @@ The observer loads in every session, subagents included.
|
|
|
48
48
|
| `/evals report [--since YYYY-MM-DD \| --days N] [--project <key>]` | Builds the linked date ranges, or one custom report when a start date or day count is given. |
|
|
49
49
|
| `/evals mark <note>` | Adds a note to the change timeline, e.g. `/evals mark workers moved to gpt-6.2-astra`. |
|
|
50
50
|
| `/evals label` | Labels the current session while the work is in front of you: pick a rule (or 「其他」), then 照做, 沒照做 or 看不出來, then an optional note in your own words. |
|
|
51
|
-
| `/evals label <rule> pass\|fail\|unclear [note]` | The same in one line; `<rule>` is a check name (`anchor_before_first_edit`, `check_after_last_edit`, `todo_evidence`, `close_guard_quiet`) or `other`. |
|
|
51
|
+
| `/evals label <rule> pass\|fail\|unclear [note]` | The same in one line; `<rule>` is a check name (`anchor_before_first_edit`, `check_after_last_edit`, `todo_evidence`, `close_guard_quiet`, `plan_names_graph`) or `other`. |
|
|
52
52
|
| `/evals label <your words>` | Anything else, e.g. `/evals label 剛剛沒先跑測試就說完成`: the agent turns your words into labels with `evals_label` and says in one line what it recorded. The verdict is yours and your words are kept as the note. |
|
|
53
53
|
| `/evals label undo` | Withdraws the current session's last label given in the moment. |
|
|
54
54
|
|
|
55
55
|
A label records the session, the time, and the key of the todo item in progress, if any (its `uid`, else `<session>#<id>`, as work items are keyed).
|
|
56
56
|
It reaches the report and `evals_query` at their next read, without an extract.
|
|
57
57
|
|
|
58
|
+
### `/ask-ai`: get an answer before the agent acts
|
|
59
|
+
|
|
60
|
+
| Command | What it does |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `/ask-ai <your question>` | Has the agent answer your question now, e.g. `/ask-ai 你剛剛有照並行設計流程嗎?`. With no question it shows the usage. |
|
|
63
|
+
|
|
64
|
+
Sometimes an agent hears a question as a reproach and starts re-planning, so the moment to label how it worked passes.
|
|
65
|
+
`/ask-ai` sends your question with a short instruction: answer first, in your language; read only what the answer needs; change nothing, start no work and dispatch nothing; if the question is about how it worked, say what happened and whether that followed the rule; end with at most one line of suggested next step, and wait.
|
|
66
|
+
If the agent is working, the question goes in after its current tool calls.
|
|
67
|
+
|
|
68
|
+
Until that run ends, or you send another message, these tools are refused with a one-line reason telling the agent to answer first: `write`, `edit`, `subagent`, `boss_pair`, `MonitorCreate`, `LoopCreate`, `call_tower`, `todo` (except `list` and `get`), and `intercom` (`send`, `ask` and `handover`).
|
|
69
|
+
`bash`, `read` and every other tool still run, so the agent can look things up.
|
|
70
|
+
Only you can type the command; agents cannot call it.
|
|
71
|
+
|
|
72
|
+
pi-evals records only that you asked (session, time, project and the todo item in progress), never the question or the answer.
|
|
73
|
+
The report's 「你的標記」 section says how many times you asked and how many of those you followed with a label in the same session within 30 minutes.
|
|
74
|
+
|
|
58
75
|
The same operations run from a shell, where extraction defaults to one fewer worker than available CPUs (at least one, at most eight).
|
|
59
76
|
On either surface, `--workers 0` reads the files sequentially without worker threads:
|
|
60
77
|
|
|
@@ -133,7 +150,7 @@ Use the section links for usage, process checks, cost and cleanup coverage, or r
|
|
|
133
150
|
| --- | --- |
|
|
134
151
|
| `events/<YYYY-MM-DD>.jsonl` | Live observer records. |
|
|
135
152
|
| `index/records/<YYYY-MM>/<key>.jsonl` | Back-filled records, one file per session file. |
|
|
136
|
-
| `index/checkpoint.json` | Size, modification time and
|
|
153
|
+
| `index/checkpoint.json` | Size, modification time, summary and the extractor version that wrote it, per session file. |
|
|
137
154
|
| `index/days.json` | Aggregates by day and project. |
|
|
138
155
|
| `index/sessions.json` | A few numbers per session with its start time, for splitting sessions at a change's time. |
|
|
139
156
|
| `index/session-evals.json` | Process check results per session, for joining your labels. |
|
|
@@ -141,6 +158,7 @@ Use the section links for usage, process checks, cost and cleanup coverage, or r
|
|
|
141
158
|
| `index/lines.json` | Cached `git diff --numstat` line counts between evidence commits. |
|
|
142
159
|
| `changes.jsonl`, `marks.jsonl` | The change timeline and your notes. |
|
|
143
160
|
| `labels.jsonl` | Your labels and agents' corrections, appended one per line ([docs/schema.md](docs/schema.md#labels)). The report shows how often you and the automatic checks agree, split by labels given after the fact and in the moment; `unclear` labels are counted apart. Its 「被糾正」 section counts the corrections by rule, failure type, skill loaded and anchorloop version. |
|
|
161
|
+
| `asks.jsonl` | One row per `/ask-ai`: session, time, project and todo item, without the question ([docs/schema.md](docs/schema.md#asks)). |
|
|
144
162
|
| `reports/report.html`, `reports/model.json` | The report. |
|
|
145
163
|
|
|
146
164
|
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/ask-ai.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { appendAsk } from "./asks.js";
|
|
2
|
+
import { itemOnBranch } from "./labels.js";
|
|
3
|
+
import { context } from "./ops.js";
|
|
4
|
+
import { projectKey } from "./project.js";
|
|
5
|
+
import { turnWindow } from "./turn-window.js";
|
|
6
|
+
const always = () => true;
|
|
7
|
+
/** Tools refused during an `/ask-ai` turn, each with the inputs it is refused for; any other tool runs. */
|
|
8
|
+
export const ASK_AI_BLOCKED = {
|
|
9
|
+
write: always,
|
|
10
|
+
edit: always,
|
|
11
|
+
subagent: always,
|
|
12
|
+
boss_pair: always,
|
|
13
|
+
MonitorCreate: always,
|
|
14
|
+
LoopCreate: always,
|
|
15
|
+
call_tower: always,
|
|
16
|
+
todo: (input) => input.action !== "list" && input.action !== "get",
|
|
17
|
+
intercom: (input) => input.action === "send" || input.action === "ask" || input.action === "handover",
|
|
18
|
+
};
|
|
19
|
+
const USAGE = "pi-evals 用法:/ask-ai <你的問題>,代理人會先直接回答,不改任何東西、不開始新工作。";
|
|
20
|
+
/** The question, last and verbatim, after the instruction to answer it now and do nothing else. */
|
|
21
|
+
export function askPrompt(question) {
|
|
22
|
+
return [
|
|
23
|
+
"[/ask-ai] Answer the user's question below now, directly and first, in the user's language. Read only what you need to answer; change nothing, start no work, dispatch nothing. If it asks how you worked, say plainly what happened and whether it followed the rule. End with at most one line of suggested next step, then wait for the user.",
|
|
24
|
+
"",
|
|
25
|
+
`Question: ${question}`,
|
|
26
|
+
].join("\n");
|
|
27
|
+
}
|
|
28
|
+
export function askAi(pi, options) {
|
|
29
|
+
const { env, now } = options;
|
|
30
|
+
const asking = turnWindow(pi);
|
|
31
|
+
pi.on("tool_call", (event, ctx) => {
|
|
32
|
+
const { toolName, input } = event;
|
|
33
|
+
const refuse = Object.hasOwn(ASK_AI_BLOCKED, toolName) ? ASK_AI_BLOCKED[toolName] : undefined;
|
|
34
|
+
if (!refuse || !refuse(input ?? {}) || !asking.current(ctx.sessionManager.getSessionId()))
|
|
35
|
+
return undefined;
|
|
36
|
+
return { block: true, reason: `Refused during /ask-ai: answer the user's question first, change nothing and start no work; ${toolName} can run after the user replies.` };
|
|
37
|
+
});
|
|
38
|
+
pi.registerCommand("ask-ai", {
|
|
39
|
+
description: "Ask the agent a question and have it answer now, without starting work: /ask-ai <question>",
|
|
40
|
+
handler: async (args, ctx) => {
|
|
41
|
+
const question = args.trim();
|
|
42
|
+
if (!question)
|
|
43
|
+
return ctx.ui.notify(USAGE, "warning");
|
|
44
|
+
const c = context(env);
|
|
45
|
+
const session = ctx.sessionManager.getSessionId();
|
|
46
|
+
let branch;
|
|
47
|
+
try {
|
|
48
|
+
branch = ctx.sessionManager.getBranch?.();
|
|
49
|
+
}
|
|
50
|
+
catch { }
|
|
51
|
+
appendAsk(c.layout.asks, { session_id: session, at: new Date(now()).toISOString(), kind: "ask_ai", project: projectKey(ctx.cwd, c.home), item: itemOnBranch(branch, session) });
|
|
52
|
+
const prompt = askPrompt(question);
|
|
53
|
+
asking.arm({ session, prompt, data: undefined });
|
|
54
|
+
// While the agent works, the question goes in after its current tool calls, not after the whole run.
|
|
55
|
+
pi.sendUserMessage(prompt, ctx.isIdle() ? undefined : { deliverAs: "steer" });
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
package/dist/asks.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `asks.jsonl` (append-only): one row per `/ask-ai`, when and where it was asked. Never the question or the answer.
|
|
3
|
+
* The report counts them and how many were followed by a label in the same session within 30 minutes.
|
|
4
|
+
*/
|
|
5
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
6
|
+
import { dirname } from "node:path";
|
|
7
|
+
import { readLabels } from "./labels.js";
|
|
8
|
+
import { traceId } from "./schema.js";
|
|
9
|
+
/** How long after an ask a label in the same session counts as following it. */
|
|
10
|
+
export const ASK_LABEL_WINDOW_MS = 30 * 60 * 1000;
|
|
11
|
+
export function appendAsk(file, row) {
|
|
12
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
13
|
+
appendFileSync(file, `${JSON.stringify(row)}\n`);
|
|
14
|
+
}
|
|
15
|
+
export function readAsks(file) {
|
|
16
|
+
if (!existsSync(file))
|
|
17
|
+
return [];
|
|
18
|
+
return readFileSync(file, "utf8")
|
|
19
|
+
.split("\n")
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.flatMap((line) => {
|
|
22
|
+
try {
|
|
23
|
+
const row = JSON.parse(line);
|
|
24
|
+
return row && row.kind === "ask_ai" && typeof row.session_id === "string" && typeof row.at === "string" ? [row] : [];
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Asks in scope (a session in the index belongs by its start; one not indexed yet by the ask's own time and project),
|
|
33
|
+
* and how many a human label in the same session followed within `ASK_LABEL_WINDOW_MS`.
|
|
34
|
+
*/
|
|
35
|
+
export function asksModel(asksFile, labelsFile, scope) {
|
|
36
|
+
if (!asksFile)
|
|
37
|
+
return { n: 0, labelled: 0 };
|
|
38
|
+
const inDates = (at) => (!scope.since || at.slice(0, 10) >= scope.since) && (!scope.until || at.slice(0, 10) <= scope.until);
|
|
39
|
+
const asks = readAsks(asksFile).filter((r) => {
|
|
40
|
+
if (!scope.selected)
|
|
41
|
+
return true;
|
|
42
|
+
const id = traceId(r.session_id, "labels");
|
|
43
|
+
return scope.selected.has(id) || (!scope.indexed?.has(id) && inDates(r.at) && (!scope.project || r.project === scope.project));
|
|
44
|
+
});
|
|
45
|
+
if (!asks.length)
|
|
46
|
+
return { n: 0, labelled: 0 };
|
|
47
|
+
const labels = readLabels(labelsFile).filter((l) => l.annotator !== "agent" && typeof l.at === "string");
|
|
48
|
+
const labelled = asks.filter((a) => {
|
|
49
|
+
const t = Date.parse(a.at);
|
|
50
|
+
return labels.some((l) => l.session_id === a.session_id && Date.parse(l.at) >= t && Date.parse(l.at) - t <= ASK_LABEL_WINDOW_MS);
|
|
51
|
+
}).length;
|
|
52
|
+
return { n: asks.length, labelled };
|
|
53
|
+
}
|
package/dist/changes.js
CHANGED
|
@@ -168,3 +168,18 @@ export function versionAt(changes, pkg, at) {
|
|
|
168
168
|
}
|
|
169
169
|
return version;
|
|
170
170
|
}
|
|
171
|
+
/** Whether a dotted version is at or after `min`, by numeric parts; a version that is not dotted numbers (a git sha) is undefined. */
|
|
172
|
+
export function atLeast(version, min) {
|
|
173
|
+
const parts = (v) => (v && /^\d+(\.\d+)*$/.test(v) ? v.split(".").map(Number) : undefined);
|
|
174
|
+
const a = parts(version), b = parts(min);
|
|
175
|
+
if (!a || !b)
|
|
176
|
+
return undefined;
|
|
177
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++)
|
|
178
|
+
if ((a[i] ?? 0) !== (b[i] ?? 0))
|
|
179
|
+
return (a[i] ?? 0) > (b[i] ?? 0);
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
/** Whether a pin change brings `pkg` to `version` or past it, from a version before it (or none): a version it skipped counts. */
|
|
183
|
+
export function crosses(c, pkg, version) {
|
|
184
|
+
return c.kind === "pin" && c.package === pkg && atLeast(c.to, version) === true && atLeast(c.from, version) !== true;
|
|
185
|
+
}
|
package/dist/detectors.js
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process detectors over one session, fed entries in file order. Each yields a session-scoped
|
|
3
|
+
* `gen_ai.evaluation.result` (annotator CODE). Commands and text are held in memory only while the
|
|
4
|
+
* session is read; results carry fixed reason codes, never text.
|
|
5
|
+
*
|
|
6
|
+
* Anchor and change reading is ported from pi-anchorloop's close guard (`pi/close-guard.ts` `read()`,
|
|
7
|
+
* MIT, Copyright (c) 2026 Wei Hung, anchorloop 3.3.0 at 7614445): the last `Anchor:` line or todo anchor,
|
|
8
|
+
* backticked commands (a todo's bare value is one command), a change is a successful `write` or `edit`,
|
|
9
|
+
* a bash run passes on exit code 0 (else on `isError` false), and a run matches an anchor command when it contains it.
|
|
10
|
+
* Like the guard, an edit made through bash is not seen as a change.
|
|
11
|
+
*
|
|
12
|
+
* Unlike the guard, these read the other shapes agents state and run a check in (0.5.1, from human labels): an anchor
|
|
13
|
+
* in the brief (`Anchor:`, `Gates:`, `Checks:`, or a check command it names), a labelled check line in the agent's
|
|
14
|
+
* words (`驗證:`, `Verify:`), a todo's sb check spec, or a first change to a test file (red first); and a check run
|
|
15
|
+
* in a monitor (by its exit code), passing evidence recorded after the last change, or, when no anchor command ran,
|
|
16
|
+
* a test, build, lint or type-check run after it.
|
|
17
|
+
*/
|
|
18
|
+
import { PlanGraphTracker } from "./plan-graph.js";
|
|
1
19
|
/**
|
|
2
20
|
* anchorloop 3.0.0 (one anchor rule and the close guard) reached this setup when weihung-basic-agent pinned it
|
|
3
21
|
* (commit 9f72366, 2026-11-23T10:51:07Z). Sessions that started earlier are out of scope.
|
|
4
22
|
*/
|
|
5
23
|
export const ERA_START = "2026-11-23T10:51:07.000Z";
|
|
6
|
-
export const DETECTORS = ["anchor_before_first_edit", "check_after_last_edit", "todo_evidence", "close_guard_quiet"];
|
|
24
|
+
export const DETECTORS = ["anchor_before_first_edit", "check_after_last_edit", "todo_evidence", "close_guard_quiet", "plan_names_graph"];
|
|
7
25
|
const NOTICE_TYPE = "anchorloop-close-guard";
|
|
8
26
|
const MAX_RUNS = 5000;
|
|
9
27
|
export function noticeKind(text) {
|
|
@@ -74,10 +92,13 @@ export class ProcessTracker {
|
|
|
74
92
|
sawUser = false;
|
|
75
93
|
briefAnchor = false;
|
|
76
94
|
notices = new Map();
|
|
95
|
+
plan = new PlanGraphTracker();
|
|
77
96
|
/** Notice kinds seen so far, for `anchorloop.close_guard.notice` records. */
|
|
78
97
|
feed(raw) {
|
|
79
98
|
const entry = raw;
|
|
80
99
|
const seq = ++this.seq;
|
|
100
|
+
if (entry && typeof entry === "object")
|
|
101
|
+
this.plan.feed(entry);
|
|
81
102
|
if (entry?.type === "custom" && entry.customType === "todo/v1" && entry.data?.v === 1 && Array.isArray(entry.data.tasks)) {
|
|
82
103
|
this.tasks = entry.data.tasks;
|
|
83
104
|
return undefined;
|
|
@@ -176,9 +197,10 @@ export class ProcessTracker {
|
|
|
176
197
|
this.runs.splice(0, this.runs.length - MAX_RUNS);
|
|
177
198
|
}
|
|
178
199
|
results(inScope) {
|
|
200
|
+
// The anchorloop era bounds the anchorloop rules only; the sb planning rule is judged in every session (long-lived mains started earlier).
|
|
179
201
|
if (!inScope)
|
|
180
|
-
return DETECTORS_ALL.map((name) => ({ name, label: "na", explanation: "out_of_scope_pre_3.0" }));
|
|
181
|
-
return [this.anchorFirst(), this.checkAfter(), this.todoEvidence(), this.quiet()];
|
|
202
|
+
return [...DETECTORS_ALL.filter((name) => name !== "plan_names_graph").map((name) => ({ name, label: "na", explanation: "out_of_scope_pre_3.0" })), this.plan.results()];
|
|
203
|
+
return [this.anchorFirst(), this.checkAfter(), this.todoEvidence(), this.quiet(), this.plan.results()];
|
|
182
204
|
}
|
|
183
205
|
anchorFirst() {
|
|
184
206
|
const name = "anchor_before_first_edit";
|
package/dist/extract/run.js
CHANGED
|
@@ -6,8 +6,8 @@ import { dirname, join } from "node:path";
|
|
|
6
6
|
import { Worker } from "node:worker_threads";
|
|
7
7
|
import { fileKey } from "../schema.js";
|
|
8
8
|
import { extractFile } from "./file.js";
|
|
9
|
-
/** Bump when extraction changes what it derives;
|
|
10
|
-
export const EXTRACTOR_VERSION =
|
|
9
|
+
/** Bump when extraction changes what it derives; every summary written by another version is read again. */
|
|
10
|
+
export const EXTRACTOR_VERSION = 6;
|
|
11
11
|
export function loadCheckpoint(file) {
|
|
12
12
|
if (!existsSync(file))
|
|
13
13
|
return { v: 1, extractor: EXTRACTOR_VERSION, files: {}, catalogs: {} };
|
|
@@ -93,13 +93,11 @@ export async function extract(options) {
|
|
|
93
93
|
const started = Date.now();
|
|
94
94
|
const checkpoint = loadCheckpoint(options.layout.checkpoint);
|
|
95
95
|
const files = listSessionFiles(options.roots);
|
|
96
|
-
|
|
96
|
+
// The checkpoint-wide field only says which version last ran; staleness is per entry (an interrupted run saves both kinds).
|
|
97
97
|
checkpoint.extractor = EXTRACTOR_VERSION;
|
|
98
98
|
const changed = files.filter((f) => {
|
|
99
99
|
const known = checkpoint.files[f.path];
|
|
100
|
-
|
|
101
|
-
return true;
|
|
102
|
-
return !known || known.size !== f.size || known.mtimeMs !== f.mtimeMs;
|
|
100
|
+
return !known || known.extractor !== EXTRACTOR_VERSION || known.size !== f.size || known.mtimeMs !== f.mtimeMs;
|
|
103
101
|
});
|
|
104
102
|
const stats = { files: files.length, changed: changed.length, failed: 0, bytes: 0, records: 0, ms: 0, errors: [] };
|
|
105
103
|
const byPath = new Map(changed.map((f) => [f.path, f]));
|
|
@@ -127,7 +125,7 @@ export async function extract(options) {
|
|
|
127
125
|
else {
|
|
128
126
|
stats.records += result.records;
|
|
129
127
|
const key = fileKey(file.path);
|
|
130
|
-
checkpoint.files[file.path] = { size: file.size, mtimeMs: file.mtimeMs, key, month: monthOf(file.path), summary: result.summary };
|
|
128
|
+
checkpoint.files[file.path] = { size: file.size, mtimeMs: file.mtimeMs, key, month: monthOf(file.path), summary: result.summary, extractor: EXTRACTOR_VERSION };
|
|
131
129
|
if (result.catalog?.length) {
|
|
132
130
|
const hash = createHash("sha1").update(result.catalog.join("\n")).digest("hex").slice(0, 16);
|
|
133
131
|
result.summary.catalog = hash;
|
package/dist/extract/session.js
CHANGED
|
@@ -405,7 +405,7 @@ export class SessionReader {
|
|
|
405
405
|
const evals = {};
|
|
406
406
|
for (const result of this.tracker.results(inScope)) {
|
|
407
407
|
evals[result.name] = { label: result.label, value: result.value, explanation: result.explanation };
|
|
408
|
-
if (
|
|
408
|
+
if (result.explanation !== "out_of_scope_pre_3.0") {
|
|
409
409
|
const t = (startDay.detectors[result.name] ??= { pass: 0, fail: 0, na: 0 });
|
|
410
410
|
t[result.label] += 1;
|
|
411
411
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pi-evals: the live observer, the `/evals` command (status, extract, report, mark, label), and the `evals_query` and `evals_label` tools.
|
|
2
|
+
* pi-evals: the live observer, the `/evals` command (status, extract, report, mark, label), `/ask-ai`, and the `evals_query` and `evals_label` tools.
|
|
3
3
|
*/
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { Type } from "typebox";
|
|
8
|
+
import { askAi } from "./ask-ai.js";
|
|
8
9
|
import { scriptsDir } from "./findings.js";
|
|
9
10
|
import { liveLabels } from "./live-labels.js";
|
|
10
11
|
import { observe } from "./observer.js";
|
|
@@ -41,6 +42,7 @@ export function createEvals(options = {}) {
|
|
|
41
42
|
const ctx0 = context(env);
|
|
42
43
|
const observed = observe(pi, { layout: ctx0.layout, home: ctx0.home, now: options.now });
|
|
43
44
|
const labels = liveLabels(pi, { env, now: options.now ?? Date.now, observed });
|
|
45
|
+
askAi(pi, { env, now: options.now ?? Date.now });
|
|
44
46
|
let settingsWarned = false;
|
|
45
47
|
pi.on("session_start", (_event, ctx) => {
|
|
46
48
|
if (settingsWarned || !ctx0.settings.error)
|
package/dist/labels-query.js
CHANGED
|
@@ -14,6 +14,8 @@ export function labelsView(m) {
|
|
|
14
14
|
`human: after the fact ${l.bySource.batch} (${l.sessions.batch} sessions), in the moment ${l.bySource.live} (${l.sessions.live} sessions${l.fromWords ? `; ${l.fromWords} formatted by the agent from your words` : ""}); unclear ${l.unclear}; no code verdict ${l.noCode}; on other ${l.other}`,
|
|
15
15
|
"code vs human, agreed/compared (after the fact; in the moment):",
|
|
16
16
|
];
|
|
17
|
+
if (l.asks.n)
|
|
18
|
+
out.splice(2, 0, `/ask-ai questions: ${l.asks.n}; followed by a label in the same session within 30 min: ${l.asks.labelled}`);
|
|
17
19
|
for (const a of l.agreement)
|
|
18
20
|
out.push(`${a.detector}: ${ratio(a)} (${ratio(a.bySource.batch)}; ${ratio(a.bySource.live)})`);
|
|
19
21
|
out.push(`corrections the agent logged (not all mistakes): ${c.n} in ${c.sessions} sessions${c.n && c.n < SMALL_SAMPLE ? `; small (<${SMALL_SAMPLE}), a hint not a trend` : ""}`);
|
package/dist/live-labels.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Type } from "typebox";
|
|
|
2
2
|
import { agentLabel, appendLabel, cleanNote, FAILURE_TYPES, itemOnBranch, RULES, ruleLabel, undoLast, VERDICT_META, VERDICTS } from "./labels.js";
|
|
3
3
|
import { context } from "./ops.js";
|
|
4
4
|
import { projectKey } from "./project.js";
|
|
5
|
+
import { turnWindow } from "./turn-window.js";
|
|
5
6
|
const VERDICT_WORDS = new Map(VERDICTS.flatMap((v) => [[v, v], [VERDICT_META[v].zh, v]]));
|
|
6
7
|
const USAGE = `pi-evals 用法:/evals label(一步步選)、/evals label <規則> pass|fail|unclear [說明],或 /evals label <你的話>(交給代理人整理成標記);規則:${RULES.join("、")};/evals label undo 撤銷這段工作上一筆當下標記。`;
|
|
7
8
|
/** The turn that formats the user's words: the instruction to the agent, with the words last and verbatim. */
|
|
@@ -16,34 +17,8 @@ export function promptFor(words) {
|
|
|
16
17
|
}
|
|
17
18
|
export function liveLabels(pi, options) {
|
|
18
19
|
const { env, now, observed } = options;
|
|
19
|
-
/** The
|
|
20
|
-
|
|
21
|
-
let speaking;
|
|
22
|
-
const textOf = (content) => typeof content === "string" ? content : Array.isArray(content) ? content.map((p) => (p && typeof p === "object" && typeof p.text === "string" ? p.text : "")).join("") : "";
|
|
23
|
-
const start = (text) => {
|
|
24
|
-
if (waiting && text === waiting.prompt) {
|
|
25
|
-
speaking = { ...waiting };
|
|
26
|
-
waiting = undefined;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
pi.on("before_agent_start", (event) => start(event.prompt));
|
|
30
|
-
// A prompt queued behind a running turn starts its own run without before_agent_start: its user message opens it.
|
|
31
|
-
pi.on("message_end", (event) => {
|
|
32
|
-
const message = event.message;
|
|
33
|
-
if (message?.role !== "user")
|
|
34
|
-
return;
|
|
35
|
-
const text = textOf(message.content);
|
|
36
|
-
// Another message from the user in the same run is not part of the words the agent is formatting.
|
|
37
|
-
if (speaking && text !== speaking.prompt)
|
|
38
|
-
speaking = undefined;
|
|
39
|
-
start(text);
|
|
40
|
-
});
|
|
41
|
-
pi.on("agent_end", () => {
|
|
42
|
-
speaking = undefined;
|
|
43
|
-
});
|
|
44
|
-
pi.on("session_start", () => {
|
|
45
|
-
waiting = speaking = undefined;
|
|
46
|
-
});
|
|
20
|
+
/** The turn that may speak for the user: the one the user's words started. */
|
|
21
|
+
const speaking = turnWindow(pi);
|
|
47
22
|
const where = (ctx) => {
|
|
48
23
|
const c = context(env);
|
|
49
24
|
const session = ctx.sessionManager.getSessionId();
|
|
@@ -71,8 +46,9 @@ export function liveLabels(pi, options) {
|
|
|
71
46
|
note = words.slice(2).join(" ");
|
|
72
47
|
if (!rule || !verdict) {
|
|
73
48
|
const text = cleanNote(words.join(" "));
|
|
74
|
-
|
|
75
|
-
|
|
49
|
+
const prompt = promptFor(text);
|
|
50
|
+
speaking.arm({ session: w.session, prompt, data: { note: text } });
|
|
51
|
+
pi.sendUserMessage(prompt, ctx.isIdle() ? undefined : { deliverAs: "followUp" });
|
|
76
52
|
return say(`pi-evals:已把你的話交給代理人,請它整理成標記${ctx.isIdle() ? "" : "(等目前的工作告一段落)"};它會回報記了什麼,不對就用 /evals label undo 撤銷。`);
|
|
77
53
|
}
|
|
78
54
|
}
|
|
@@ -111,7 +87,7 @@ export function liveLabels(pi, options) {
|
|
|
111
87
|
}, { additionalProperties: false }),
|
|
112
88
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
113
89
|
const session = ctx.sessionManager.getSessionId();
|
|
114
|
-
const voice = speaking?.
|
|
90
|
+
const voice = speaking.current(session)?.data;
|
|
115
91
|
const { rule, label, type, onBehalf } = agentLabel(params, !!voice);
|
|
116
92
|
const w = where(ctx);
|
|
117
93
|
if (onBehalf) {
|
package/dist/meta.js
CHANGED
|
@@ -258,6 +258,17 @@ export const DETECTOR_META = {
|
|
|
258
258
|
fail: t("Edits and ends; the guard adds 'no passing run of `npm test`'.", "改檔就結束,收尾檢查加上「沒有 `npm test` 的通過紀錄」。"),
|
|
259
259
|
},
|
|
260
260
|
},
|
|
261
|
+
plan_names_graph: {
|
|
262
|
+
introducedIn: { package: "pi-straw-boss", version: "0.101.0" },
|
|
263
|
+
label: t("Plan says how the work splits", "排工作時說清楚怎麼分工"),
|
|
264
|
+
meaning: t("When a Straw Boss main (coordinator or standing) writes its plan as todos, it names the plan's shape: one loop it runs itself, parallel workers it merges, or an orchestrator handing work out.", "Straw Boss 的主代理(協調或常駐)把計畫寫成待辦時,有說明這份計畫的分工方式:自己一路做完、分給幾個人平行做再合併,或由主代理派工給工作者。"),
|
|
265
|
+
goodDirection: "higher",
|
|
266
|
+
howComputed: t("Passes when the open todos left by the main's first todo create carry a graph (the todo's graph field, or an older metadata.graph), or when its next todo call adds one, as sb 0.101.0 and later ask on that create. Fails when it went on planning without one. Sessions that are not such a main, or never planned, do not count.", "主代理第一次建立待辦後,還沒完成的待辦有標分工方式(待辦的 graph 欄位,或舊版的 metadata.graph)即通過;第一次沒標、但下一次動待辦時補上的也算通過(sb 0.101.0 起會在那次建立待辦時提醒)。沒標就繼續排工作的不通過。不是這類主代理、或從沒排過工作的不算。"),
|
|
267
|
+
example: {
|
|
268
|
+
pass: t("Creates three todos with graph 'fan-out/fan-in', then dispatches them.", "建立三項待辦並標上「fan-out/fan-in」,再派出去。"),
|
|
269
|
+
fail: t("Creates three todos with no graph, gets sb's reminder, and adds a fourth without one.", "建立三項待辦沒標分工方式,收到 sb 提醒後又加了第四項,仍然沒標。"),
|
|
270
|
+
},
|
|
271
|
+
},
|
|
261
272
|
};
|
|
262
273
|
export const NOTICE_META = {
|
|
263
274
|
no_anchor: t("Files changed but no Anchor was stated", "改了檔案但沒說要怎麼驗證"),
|
package/dist/model.js
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { ASK_BUCKETS, emptyDay, mergeDay } from "./aggregate.js";
|
|
7
|
-
import { versionAt } from "./changes.js";
|
|
7
|
+
import { atLeast, versionAt } from "./changes.js";
|
|
8
8
|
import { DETECTORS, ERA_START } from "./detectors.js";
|
|
9
9
|
import { CHANGE_KIND_META, CLOSE_KIND_META, DETECTOR_META, METRICS, NOTICE_META, STALL_KIND_META } from "./meta.js";
|
|
10
10
|
import { staticOwner } from "./owners.js";
|
|
11
11
|
import { weeklyRises } from "./trends.js";
|
|
12
|
+
import { asksModel } from "./asks.js";
|
|
12
13
|
import { labelsModel } from "./labels.js";
|
|
13
14
|
import { ANCHORLOOP } from "./work/join.js";
|
|
14
15
|
import { workModel } from "./work/model.js";
|
|
@@ -107,6 +108,41 @@ export function impactMetrics(rows, ownerOf, pkg) {
|
|
|
107
108
|
anchor_before_first_edit: d("anchor_before_first_edit"),
|
|
108
109
|
check_after_last_edit: d("check_after_last_edit"),
|
|
109
110
|
todo_evidence: d("todo_evidence"),
|
|
111
|
+
plan_names_graph: d("plan_names_graph"),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** Dotted versions in numeric order; anything else (unknown, a sha) after them. */
|
|
115
|
+
const byVersion = (a, b) => {
|
|
116
|
+
const pa = /^\d+(\.\d+)*$/.test(a) ? a.split(".").map(Number) : undefined, pb = /^\d+(\.\d+)*$/.test(b) ? b.split(".").map(Number) : undefined;
|
|
117
|
+
if (!pa || !pb)
|
|
118
|
+
return pa ? -1 : pb ? 1 : a.localeCompare(b);
|
|
119
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++)
|
|
120
|
+
if ((pa[i] ?? 0) !== (pb[i] ?? 0))
|
|
121
|
+
return (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
122
|
+
return 0;
|
|
123
|
+
};
|
|
124
|
+
/** A detector's results by the version of the package it measures, at each session's start, and before and from the version that brought it. */
|
|
125
|
+
export function packageSplit(rows, changes, detector, since) {
|
|
126
|
+
const versions = new Map();
|
|
127
|
+
const sides = { before: { pass: 0, fail: 0 }, after: { pass: 0, fail: 0 } };
|
|
128
|
+
for (const r of rows) {
|
|
129
|
+
const v = r.ev[detector];
|
|
130
|
+
if (v === undefined)
|
|
131
|
+
continue;
|
|
132
|
+
const version = versionAt(changes, since.package, r.s) ?? "unknown";
|
|
133
|
+
const cell = versions.get(version) ?? { pass: 0, fail: 0 };
|
|
134
|
+
cell[v ? "pass" : "fail"] += 1;
|
|
135
|
+
versions.set(version, cell);
|
|
136
|
+
const later = atLeast(version, since.version);
|
|
137
|
+
if (later !== undefined)
|
|
138
|
+
sides[later ? "after" : "before"][v ? "pass" : "fail"] += 1;
|
|
139
|
+
}
|
|
140
|
+
const withRate = (x) => ({ ...x, passRate: rate(x.pass, x.pass + x.fail) });
|
|
141
|
+
return {
|
|
142
|
+
...since,
|
|
143
|
+
versions: [...versions].sort(([a], [b]) => byVersion(a, b)).map(([version, x]) => ({ version, ...withRate(x) })),
|
|
144
|
+
before: withRate(sides.before),
|
|
145
|
+
after: withRate(sides.after),
|
|
110
146
|
};
|
|
111
147
|
}
|
|
112
148
|
/** Changes from one commit (or one mark) count once. */
|
|
@@ -186,8 +222,9 @@ export function buildModel(options) {
|
|
|
186
222
|
const selected = projectRows.filter(r => inRange(r.s)), children = selected.filter(r => r.k);
|
|
187
223
|
const scoped = Boolean(filter.since || filter.until || filter.project);
|
|
188
224
|
const hasSessionIds = selected.every(r => r.id !== undefined);
|
|
189
|
-
const labelIds = scoped && existsSync(options.labelsFile) ? new Set(selected.flatMap(r => r.id ? [r.id] : [])) : undefined;
|
|
225
|
+
const labelIds = scoped && (existsSync(options.labelsFile) || (!!options.asksFile && existsSync(options.asksFile))) ? new Set(selected.flatMap(r => r.id ? [r.id] : [])) : undefined;
|
|
190
226
|
const indexedIds = labelIds && new Set(options.rows.flatMap(r => r.id ? [r.id] : []));
|
|
227
|
+
const labelScope = { ...filter, until: options.openEnd ? undefined : filter.until, selected: labelIds, indexed: indexedIds };
|
|
191
228
|
const calls = Object.values(total.tools).reduce((s, t) => s + t.calls, 0);
|
|
192
229
|
const errors = Object.values(total.tools).reduce((s, t) => s + t.errors, 0);
|
|
193
230
|
const tokens = total.usage.input + total.usage.output + total.usage.cacheRead + total.usage.cacheWrite;
|
|
@@ -276,6 +313,7 @@ export function buildModel(options) {
|
|
|
276
313
|
return { day, pass: x.pass, fail: x.fail };
|
|
277
314
|
}),
|
|
278
315
|
byVersion: (versions.get(d.name) ?? []).map((v) => ({ ...v, passRate: rate(v.pass, v.pass + v.fail) })),
|
|
316
|
+
byPackage: DETECTOR_META[d.name]?.introducedIn ? packageSplit(selected, sortedChanges, d.name, DETECTOR_META[d.name].introducedIn) : null,
|
|
279
317
|
})),
|
|
280
318
|
notices: total.notices,
|
|
281
319
|
},
|
|
@@ -295,7 +333,8 @@ export function buildModel(options) {
|
|
|
295
333
|
.filter((c) => inRange(c.at))
|
|
296
334
|
.map((c) => ({ ...c, impact: index.range.start && c.at > index.range.start ? impactFromRows(projectRows, c, sortedChanges, options.windowDays, index.range, owner) : null })),
|
|
297
335
|
labels: {
|
|
298
|
-
...labelsModel(options.labelsFile, options.sessionEvalsFile,
|
|
336
|
+
...labelsModel(options.labelsFile, options.sessionEvalsFile, labelScope, (at) => versionAt(sortedChanges, ANCHORLOOP, at)),
|
|
337
|
+
asks: asksModel(options.asksFile, options.labelsFile, labelScope),
|
|
299
338
|
needsIndex: !!labelIds && !hasSessionIds,
|
|
300
339
|
},
|
|
301
340
|
coverage: options.coverage ?? null,
|
package/dist/ops.js
CHANGED
|
@@ -68,7 +68,7 @@ function snapshot(env, withCoverage = true) {
|
|
|
68
68
|
const filter = rangeFilter(input, index.lastExtract ?? now.toISOString(), preset);
|
|
69
69
|
// A range ends at the last extract unless the user ends it; a label given since then has no session in the index yet.
|
|
70
70
|
return buildModel({ index, rows, changes, comparisons, filter, now, windowDays: ctx.settings.impactWindowDays, openEnd: input.until === undefined,
|
|
71
|
-
labelsFile: ctx.layout.labels, sessionEvalsFile: ctx.layout.sessionEvals, coverage: cov?.(filter), work });
|
|
71
|
+
labelsFile: ctx.layout.labels, asksFile: ctx.layout.asks, sessionEvalsFile: ctx.layout.sessionEvals, coverage: cov?.(filter), work });
|
|
72
72
|
} };
|
|
73
73
|
}
|
|
74
74
|
export function indexedModel(filter, env, withCoverage = true) {
|
package/dist/paths.js
CHANGED
|
@@ -68,6 +68,7 @@ export function layout(state = stateDir()) {
|
|
|
68
68
|
changes: join(state, "changes.jsonl"),
|
|
69
69
|
marks: join(state, "marks.jsonl"),
|
|
70
70
|
labels: join(state, "labels.jsonl"),
|
|
71
|
+
asks: join(state, "asks.jsonl"),
|
|
71
72
|
status: join(state, "index", "status.json"),
|
|
72
73
|
reports: join(state, "reports"),
|
|
73
74
|
items: join(state, "index", "items.json"),
|