@nexface/evals 0.0.0-stage → 0.1.21-alpha.6
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/CLI.md +51 -0
- package/README.md +34 -2
- package/approved-task.mjs +32 -0
- package/cli.mjs +31 -0
- package/generated.mjs +72 -0
- package/judge.mjs +73 -0
- package/native-tools.mjs +149 -0
- package/package.json +52 -4
- package/playwright.cjs +1 -0
- package/playwright.d.mts +10 -0
- package/playwright.mjs +1 -0
- package/report-output.mjs +194 -0
- package/runner.mjs +153 -0
- package/session.mjs +89 -0
- package/site-run.mjs +127 -0
- package/spec-config.mjs +24 -0
- package/spec-reporter.mjs +63 -0
- package/spec-run.mjs +87 -0
- package/studio.html +613 -0
- package/studio.mjs +244 -0
- package/suite.mjs +112 -0
- package/task-fixture.mjs +314 -0
- package/task-session.mjs +97 -0
package/spec-run.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { atomicJson } from "./session.mjs";
|
|
8
|
+
|
|
9
|
+
import { taskRevision } from "./suite.mjs";
|
|
10
|
+
|
|
11
|
+
export async function runSpecs(root, tasks, baseURL, storageState, fingerprints) {
|
|
12
|
+
const dir = await mkdtemp(join(tmpdir(), "nexface-playwright-"));
|
|
13
|
+
try {
|
|
14
|
+
const statePath = join(dir, "auth.json");
|
|
15
|
+
if (storageState) await atomicJson(statePath, storageState);
|
|
16
|
+
await atomicJson(
|
|
17
|
+
join(dir, "selection.json"),
|
|
18
|
+
Object.fromEntries(
|
|
19
|
+
tasks.map((task) => [
|
|
20
|
+
task.id,
|
|
21
|
+
{
|
|
22
|
+
revision: taskRevision(task),
|
|
23
|
+
fingerprint: fingerprints[task.id],
|
|
24
|
+
},
|
|
25
|
+
]),
|
|
26
|
+
),
|
|
27
|
+
);
|
|
28
|
+
const options = {
|
|
29
|
+
root,
|
|
30
|
+
ids: tasks.map((task) => task.id),
|
|
31
|
+
dir,
|
|
32
|
+
baseURL,
|
|
33
|
+
storageState: storageState && statePath,
|
|
34
|
+
};
|
|
35
|
+
const cli = createRequire(import.meta.url).resolve("@playwright/test/cli");
|
|
36
|
+
const config = fileURLToPath(new URL("spec-config.mjs", import.meta.url));
|
|
37
|
+
const code = await new Promise((resolve, reject) => {
|
|
38
|
+
const child = spawn(process.execPath, [cli, "test", "--config", config], {
|
|
39
|
+
cwd: root,
|
|
40
|
+
env: { ...process.env, NEXFACE_SPEC_OPTIONS: JSON.stringify(options) },
|
|
41
|
+
stdio: "inherit",
|
|
42
|
+
});
|
|
43
|
+
child.on("error", reject);
|
|
44
|
+
child.on("close", resolve);
|
|
45
|
+
});
|
|
46
|
+
let rows = [];
|
|
47
|
+
let errors = [];
|
|
48
|
+
try {
|
|
49
|
+
({ rows, errors } = JSON.parse(await readFile(join(dir, "results.json"), "utf8")));
|
|
50
|
+
} catch (error) {
|
|
51
|
+
errors.push(
|
|
52
|
+
"Playwright did not produce a readable report (exit " + code + "): " + error.message,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
if (code !== 0 && !errors.length && rows.every((row) => row.status === "passed")) {
|
|
56
|
+
errors.push("Playwright exited before completing the run (exit " + code + ").");
|
|
57
|
+
}
|
|
58
|
+
// Join on the selection index because a redacted display ID may no longer be unique.
|
|
59
|
+
return collectResults(tasks, rows, errors);
|
|
60
|
+
} finally {
|
|
61
|
+
await rm(dir, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function collectResults(tasks, rows, errors) {
|
|
66
|
+
const results = tasks.map((task, index) => {
|
|
67
|
+
const matches = rows
|
|
68
|
+
.filter((row) => row.selectionIndex === index)
|
|
69
|
+
.map(({ selectionIndex, ...row }) => row);
|
|
70
|
+
if (matches.length === 1)
|
|
71
|
+
return { ...matches[0], id: task.id, goal: matches[0].goal ?? task.goal };
|
|
72
|
+
const reason = matches.length
|
|
73
|
+
? "Multiple tests for this task."
|
|
74
|
+
: "No result was recorded for this task.";
|
|
75
|
+
return {
|
|
76
|
+
id: task.id,
|
|
77
|
+
goal: task.goal,
|
|
78
|
+
stage: "Playwright",
|
|
79
|
+
status: "blocked",
|
|
80
|
+
calls: matches.flatMap((row) => row.calls),
|
|
81
|
+
checks: matches.flatMap((row) => row.checks),
|
|
82
|
+
...(matches.length ? { attempts: matches } : {}),
|
|
83
|
+
reason,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
return { tasks: results, errors };
|
|
87
|
+
}
|
package/studio.html
ADDED
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<meta charset="utf-8" /><meta
|
|
4
|
+
name="viewport"
|
|
5
|
+
content="width=device-width,initial-scale=1"
|
|
6
|
+
/>
|
|
7
|
+
<title>Nexface · 任务编写</title>
|
|
8
|
+
<style>
|
|
9
|
+
* {
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
}
|
|
12
|
+
body {
|
|
13
|
+
margin: 0;
|
|
14
|
+
background: #fcfcf9;
|
|
15
|
+
color: #22312a;
|
|
16
|
+
font: 16px/1.6 system-ui, sans-serif;
|
|
17
|
+
}
|
|
18
|
+
main {
|
|
19
|
+
max-width: 1240px;
|
|
20
|
+
margin: auto;
|
|
21
|
+
padding: 32px 24px;
|
|
22
|
+
}
|
|
23
|
+
header,
|
|
24
|
+
nav,
|
|
25
|
+
footer,
|
|
26
|
+
.actions {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: 12px;
|
|
30
|
+
}
|
|
31
|
+
header {
|
|
32
|
+
border-bottom: 1px solid #ccd5ca;
|
|
33
|
+
padding-bottom: 16px;
|
|
34
|
+
}
|
|
35
|
+
strong {
|
|
36
|
+
font-size: 22px;
|
|
37
|
+
}
|
|
38
|
+
nav {
|
|
39
|
+
margin-left: auto;
|
|
40
|
+
}
|
|
41
|
+
button,
|
|
42
|
+
input,
|
|
43
|
+
textarea,
|
|
44
|
+
select {
|
|
45
|
+
font: inherit;
|
|
46
|
+
}
|
|
47
|
+
button {
|
|
48
|
+
border: 1px solid #bec7bf;
|
|
49
|
+
background: white;
|
|
50
|
+
color: inherit;
|
|
51
|
+
padding: 6px 14px;
|
|
52
|
+
border-radius: 7px;
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
}
|
|
55
|
+
button:disabled {
|
|
56
|
+
opacity: 0.5;
|
|
57
|
+
cursor: default;
|
|
58
|
+
}
|
|
59
|
+
nav button {
|
|
60
|
+
background: transparent;
|
|
61
|
+
border: 0;
|
|
62
|
+
border-bottom: 2px solid transparent;
|
|
63
|
+
border-radius: 0;
|
|
64
|
+
padding: 6px 4px;
|
|
65
|
+
}
|
|
66
|
+
nav button[aria-current="step"] {
|
|
67
|
+
border-bottom-color: #255742;
|
|
68
|
+
font-weight: 600;
|
|
69
|
+
}
|
|
70
|
+
#save {
|
|
71
|
+
margin-inline-start: auto;
|
|
72
|
+
min-inline-size: 7em;
|
|
73
|
+
}
|
|
74
|
+
.primary {
|
|
75
|
+
background: #255742;
|
|
76
|
+
color: white;
|
|
77
|
+
}
|
|
78
|
+
h1 {
|
|
79
|
+
margin: 34px 0 14px;
|
|
80
|
+
font-size: 26px;
|
|
81
|
+
}
|
|
82
|
+
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 34px 0 18px; }
|
|
83
|
+
.page-heading h1 { margin: 0; }
|
|
84
|
+
.task-row {
|
|
85
|
+
display: grid;
|
|
86
|
+
grid-template-columns: auto minmax(0, 1fr) auto auto;
|
|
87
|
+
align-items: start;
|
|
88
|
+
gap: 12px;
|
|
89
|
+
padding: 18px 6px;
|
|
90
|
+
border-bottom: 1px solid #dedfd9;
|
|
91
|
+
}
|
|
92
|
+
.task-row:first-child { border-top: 1px solid #dedfd9; }
|
|
93
|
+
.task-row input { margin: 5px 0 0; width: 16px; height: 16px; accent-color: #30382e; }
|
|
94
|
+
.task-row label { margin: 0; cursor: pointer; white-space: pre-wrap; }
|
|
95
|
+
.task-row > div { overflow-wrap: anywhere; }
|
|
96
|
+
.task-row .quiet { padding: 2px 8px; }
|
|
97
|
+
.sub, #selection-count { color: #596352; font-size: 14px; }
|
|
98
|
+
.sub { margin: 5px 0 0; }
|
|
99
|
+
#save { background: #30382e; }
|
|
100
|
+
footer {
|
|
101
|
+
justify-content: space-between;
|
|
102
|
+
margin-top: 20px;
|
|
103
|
+
}
|
|
104
|
+
.actions {
|
|
105
|
+
justify-content: flex-end;
|
|
106
|
+
}
|
|
107
|
+
dialog {
|
|
108
|
+
width: min(550px, 95vw);
|
|
109
|
+
border: 1px solid #bcc6bc;
|
|
110
|
+
border-radius: 12px;
|
|
111
|
+
padding: 24px;
|
|
112
|
+
}
|
|
113
|
+
dialog::backdrop {
|
|
114
|
+
background: #16291d59;
|
|
115
|
+
}
|
|
116
|
+
label {
|
|
117
|
+
display: block;
|
|
118
|
+
margin: 10px 0;
|
|
119
|
+
}
|
|
120
|
+
input:not([type="checkbox"]),
|
|
121
|
+
textarea,
|
|
122
|
+
select {
|
|
123
|
+
display: block;
|
|
124
|
+
width: 100%;
|
|
125
|
+
padding: 8px;
|
|
126
|
+
border: 1px solid #bcc6bc;
|
|
127
|
+
border-radius: 5px;
|
|
128
|
+
}
|
|
129
|
+
textarea {
|
|
130
|
+
min-height: 70px;
|
|
131
|
+
}
|
|
132
|
+
#message {
|
|
133
|
+
min-height: 24px;
|
|
134
|
+
}
|
|
135
|
+
dialog.criteria-editor {
|
|
136
|
+
width: min(740px, 95vw);
|
|
137
|
+
max-height: 90vh;
|
|
138
|
+
padding: 0;
|
|
139
|
+
color: inherit;
|
|
140
|
+
}
|
|
141
|
+
.dialog-heading, .condition-heading {
|
|
142
|
+
display: flex;
|
|
143
|
+
justify-content: space-between;
|
|
144
|
+
align-items: center;
|
|
145
|
+
gap: 12px;
|
|
146
|
+
}
|
|
147
|
+
dialog h2, .condition-heading h3 { margin: 0; }
|
|
148
|
+
.criteria-editor .dialog-heading { padding: 20px 24px 12px; }
|
|
149
|
+
.criteria-editor[open], .criteria-editor form {
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-direction: column;
|
|
152
|
+
min-height: 0;
|
|
153
|
+
}
|
|
154
|
+
.criteria-editor #fields { padding: 0 24px 20px; overflow-y: auto; }
|
|
155
|
+
.criteria-editor .actions { padding: 14px 24px; border-top: 1px solid #d9ded8; }
|
|
156
|
+
.task-quote { padding: 12px 16px; background: #f4f5f2; border-radius: 6px; }
|
|
157
|
+
.task-quote p { margin: 2px 0 0; overflow-wrap: anywhere; }
|
|
158
|
+
.task-quote small, .quiet { color: #526158; }
|
|
159
|
+
.quiet { background: transparent; border: 0; padding: 3px 8px; }
|
|
160
|
+
.quiet:hover { background: #f1f3ef; }
|
|
161
|
+
.remove-condition { display: inline-grid; place-items: center; width: 34px; height: 34px; }
|
|
162
|
+
#close { font-size: 22px; }
|
|
163
|
+
.condition { padding: 16px 0 4px; }
|
|
164
|
+
.condition + .condition { border-top: 1px solid #e4e8e3; }
|
|
165
|
+
.condition-heading h3 { font-size: 17px; }
|
|
166
|
+
.condition label { margin-top: 4px; font-size: 14px; }
|
|
167
|
+
.condition textarea { margin-top: 5px; min-height: 76px; resize: vertical; font-size: 16px; }
|
|
168
|
+
.condition-picker { position: relative; display: inline-block; }
|
|
169
|
+
.condition-picker select {
|
|
170
|
+
appearance: none;
|
|
171
|
+
padding: 6px 36px 6px 12px;
|
|
172
|
+
background: white;
|
|
173
|
+
color: inherit;
|
|
174
|
+
cursor: pointer;
|
|
175
|
+
}
|
|
176
|
+
.condition-picker::after {
|
|
177
|
+
content: "";
|
|
178
|
+
position: absolute;
|
|
179
|
+
top: 50%;
|
|
180
|
+
right: 14px;
|
|
181
|
+
width: 6px;
|
|
182
|
+
height: 6px;
|
|
183
|
+
border: solid currentColor;
|
|
184
|
+
border-width: 0 1.5px 1.5px 0;
|
|
185
|
+
transform: translateY(-70%) rotate(45deg);
|
|
186
|
+
pointer-events: none;
|
|
187
|
+
}
|
|
188
|
+
.brand { display: flex; align-items: center; gap: 10px; }
|
|
189
|
+
.brand svg { width: 24px; height: 27px; fill: currentColor; }
|
|
190
|
+
header { display: grid; grid-template-columns: 1fr auto 1fr; }
|
|
191
|
+
nav { margin: 0; }
|
|
192
|
+
nav button { display: inline-flex; align-items: center; gap: 6px; border: 0; }
|
|
193
|
+
nav b { display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid #ccd0c7; border-radius: 50%; font: inherit; font-size: 12px; }
|
|
194
|
+
nav [aria-current="step"] b { color: white; background: #30382e; border-color: #30382e; }
|
|
195
|
+
.review #list { display: grid; grid-template-columns: minmax(180px, 25%) minmax(0, 1fr); gap: clamp(24px, 4vw, 64px); border-block: 1px solid #dedfd9; padding-block: 24px; }
|
|
196
|
+
.task-index { border-right: 1px solid #dedfd9; padding-right: 16px; }
|
|
197
|
+
.task-index h2, .goal-label { font-size: 14px; font-weight: 500; color: #596352; margin: 0 0 12px; }
|
|
198
|
+
.task-index button { display: block; width: 100%; text-align: left; padding: 12px; background: transparent; border: none; border-left: 3px solid transparent; }
|
|
199
|
+
.task-index button[aria-current="true"] { background: #edf0e7; border-color: #546a4d; }
|
|
200
|
+
.task-index button:hover { background: #f0f2eb; }
|
|
201
|
+
.task-index span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
|
|
202
|
+
.review-pane { min-width: 0; overflow-wrap: anywhere; }
|
|
203
|
+
.full-goal { white-space: pre-wrap; margin: 0 0 24px; font-size: 18px; }
|
|
204
|
+
.review-pane .condition-heading { border-top: 1px solid #dedfd9; padding-top: 16px; }
|
|
205
|
+
.review-pane h2 { margin: 0; font-size: 20px; }
|
|
206
|
+
.review-pane h3 { margin: 22px 0 6px; font-size: 16px; }
|
|
207
|
+
.review-pane ul { margin: 0; padding-inline-start: 1.4em; }
|
|
208
|
+
.review-pane li { margin: 6px 0; white-space: pre-wrap; }
|
|
209
|
+
@media (max-width: 640px) {
|
|
210
|
+
header { display: flex; justify-content: space-between; }
|
|
211
|
+
.review #list { grid-template-columns: 1fr; }
|
|
212
|
+
.task-index { border-right: 0; padding: 0 0 12px; border-bottom: 1px solid #dedfd9; }
|
|
213
|
+
}
|
|
214
|
+
</style>
|
|
215
|
+
<main>
|
|
216
|
+
<header>
|
|
217
|
+
<strong class="brand"><svg viewBox="0 0 280 312" aria-hidden="true">
|
|
218
|
+
<path d="M18 4 174 103V161L58 89V244L108 226V269L18 308Q0 315 0 296V16Q0-7 18 4Z"/>
|
|
219
|
+
<path d="M18 4 174 103V161L58 89V244L108 226V269L18 308Q0 315 0 296V16Q0-7 18 4Z" transform="rotate(180 140 156)"/>
|
|
220
|
+
</svg>Nexface</strong>
|
|
221
|
+
<nav aria-label="编写步骤">
|
|
222
|
+
<button id="tasks"><b>1</b> 任务</button>
|
|
223
|
+
<button id="criteria"><b>2</b> 验收条件</button>
|
|
224
|
+
</nav>
|
|
225
|
+
</header>
|
|
226
|
+
<div class="page-heading"><h1 id="heading"></h1><button id="add">+ 添加任务</button></div>
|
|
227
|
+
<section id="list"></section>
|
|
228
|
+
<footer>
|
|
229
|
+
<span id="selection-count" aria-live="polite"></span>
|
|
230
|
+
<button id="save" class="primary"></button>
|
|
231
|
+
</footer>
|
|
232
|
+
<p id="message" role="status"></p>
|
|
233
|
+
</main>
|
|
234
|
+
<dialog aria-labelledby="title">
|
|
235
|
+
<div class="dialog-heading">
|
|
236
|
+
<h2 id="title"></h2>
|
|
237
|
+
<button id="close" type="button" class="quiet" aria-label="关闭">×</button>
|
|
238
|
+
</div>
|
|
239
|
+
<form id="form">
|
|
240
|
+
<div id="fields"></div>
|
|
241
|
+
<div class="actions">
|
|
242
|
+
<button type="button" id="cancel">取消</button
|
|
243
|
+
><button id="apply" class="primary">确定</button>
|
|
244
|
+
</div>
|
|
245
|
+
</form>
|
|
246
|
+
</dialog>
|
|
247
|
+
<script type="module">
|
|
248
|
+
const el = (id) => document.getElementById(id);
|
|
249
|
+
const dialog = document.querySelector("dialog");
|
|
250
|
+
let state,
|
|
251
|
+
draft = [],
|
|
252
|
+
selected = new Set(),
|
|
253
|
+
activeTaskId,
|
|
254
|
+
readEditor,
|
|
255
|
+
baseRevision,
|
|
256
|
+
tab = "tasks",
|
|
257
|
+
tasksDirty = false,
|
|
258
|
+
editedCriteria = new Set();
|
|
259
|
+
const dirty = () => tasksDirty || editedCriteria.size > 0;
|
|
260
|
+
const node = (tag, text) =>
|
|
261
|
+
Object.assign(document.createElement(tag), { textContent: text ?? "" });
|
|
262
|
+
function button(text, fn) {
|
|
263
|
+
const b = node("button", text);
|
|
264
|
+
b.type = "button";
|
|
265
|
+
b.onclick = fn;
|
|
266
|
+
return b;
|
|
267
|
+
}
|
|
268
|
+
function field(parent, title, value, placeholder, tag = "input", required = false) {
|
|
269
|
+
const label = node("label", title),
|
|
270
|
+
input = node(tag);
|
|
271
|
+
input.value = value ?? "";
|
|
272
|
+
input.required = required;
|
|
273
|
+
input.placeholder = placeholder;
|
|
274
|
+
label.append(input);
|
|
275
|
+
parent.append(label);
|
|
276
|
+
return input;
|
|
277
|
+
}
|
|
278
|
+
function load(s) {
|
|
279
|
+
state = s;
|
|
280
|
+
baseRevision = s.revision;
|
|
281
|
+
draft = structuredClone(s.suite?.tasks ?? []);
|
|
282
|
+
selected = new Set(draft.map((t) => t.id));
|
|
283
|
+
tasksDirty = false;
|
|
284
|
+
editedCriteria.clear();
|
|
285
|
+
tab = [
|
|
286
|
+
"criteria",
|
|
287
|
+
"pendingCriteria",
|
|
288
|
+
"written",
|
|
289
|
+
"awaitingCriteria",
|
|
290
|
+
].includes(s.phase)
|
|
291
|
+
? "criteria"
|
|
292
|
+
: "tasks";
|
|
293
|
+
draw();
|
|
294
|
+
}
|
|
295
|
+
// Keep unconfirmed edits isolated to the project and this browser tab.
|
|
296
|
+
const storageKey = () => "nexface-studio:" + state.project;
|
|
297
|
+
function remember() {
|
|
298
|
+
if (!state) return;
|
|
299
|
+
try {
|
|
300
|
+
sessionStorage.setItem(storageKey(), JSON.stringify({
|
|
301
|
+
revision: baseRevision, tab, activeTaskId, draft, selected: [...selected], dirty: dirty(), tasksDirty, editedCriteria: [...editedCriteria],
|
|
302
|
+
editor: dialog.open ? readEditor() : null,
|
|
303
|
+
}));
|
|
304
|
+
} catch {
|
|
305
|
+
el("message").textContent = "浏览器未能保存本页草稿,刷新前请先确认修改。";
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function restore() {
|
|
309
|
+
let saved;
|
|
310
|
+
try { saved = JSON.parse(sessionStorage.getItem(storageKey())); } catch { return; }
|
|
311
|
+
if (!saved || (saved.revision !== state.revision && !saved.dirty && !saved.editor)) return;
|
|
312
|
+
baseRevision = saved.revision;
|
|
313
|
+
({ draft, tab, activeTaskId } = saved);
|
|
314
|
+
tasksDirty = saved.tasksDirty ?? (saved.dirty && tab === "tasks");
|
|
315
|
+
editedCriteria = new Set(saved.editedCriteria ?? (saved.dirty && tab === "criteria" ? draft.map(t => t.id) : []));
|
|
316
|
+
selected = new Set(saved.selected);
|
|
317
|
+
draw();
|
|
318
|
+
if (saved.editor) edit(draft.find(task => task.id === saved.editor.id), saved.editor);
|
|
319
|
+
}
|
|
320
|
+
window.addEventListener("pagehide", remember);
|
|
321
|
+
function drawTaskList() {
|
|
322
|
+
for (const t of draft) {
|
|
323
|
+
const a = node("article");
|
|
324
|
+
a.className = "task-row";
|
|
325
|
+
const content = node("div");
|
|
326
|
+
const box = node("input");
|
|
327
|
+
box.type = "checkbox";
|
|
328
|
+
box.checked = selected.has(t.id);
|
|
329
|
+
box.id = "choose-" + t.id;
|
|
330
|
+
box.onchange = () => {
|
|
331
|
+
if (box.checked) selected.add(t.id);
|
|
332
|
+
else selected.delete(t.id);
|
|
333
|
+
tasksDirty = true;
|
|
334
|
+
draw();
|
|
335
|
+
el(box.id).focus();
|
|
336
|
+
};
|
|
337
|
+
const goal = node("label", t.goal);
|
|
338
|
+
goal.htmlFor = box.id;
|
|
339
|
+
content.append(goal);
|
|
340
|
+
const editButton = button("编辑", () => edit(t));
|
|
341
|
+
editButton.className = "quiet";
|
|
342
|
+
const removeButton = button("删除", () => {
|
|
343
|
+
const index = draft.indexOf(t);
|
|
344
|
+
draft.splice(index, 1);
|
|
345
|
+
selected.delete(t.id);
|
|
346
|
+
editedCriteria.delete(t.id);
|
|
347
|
+
tasksDirty = true;
|
|
348
|
+
draw();
|
|
349
|
+
const neighbor = draft[index] ?? draft[index - 1];
|
|
350
|
+
(neighbor ? el("choose-" + neighbor.id) : el("add")).focus();
|
|
351
|
+
});
|
|
352
|
+
removeButton.className = "quiet";
|
|
353
|
+
a.append(box, content, editButton, removeButton);
|
|
354
|
+
const line = (text) => {
|
|
355
|
+
const p = node("p", text);
|
|
356
|
+
p.className = "sub";
|
|
357
|
+
content.append(p);
|
|
358
|
+
};
|
|
359
|
+
if (t.start?.route) line("起始页面 " + t.start.route);
|
|
360
|
+
const initial = t.start?.condition?.expect;
|
|
361
|
+
if (initial) line("起始状态 " + initial);
|
|
362
|
+
el("list").append(a);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function resultKind(condition) {
|
|
366
|
+
const mode = condition.check;
|
|
367
|
+
return mode === "reply" ? "reply" : "result";
|
|
368
|
+
}
|
|
369
|
+
function drawReview() {
|
|
370
|
+
const active = draft.find((task) => task.id === activeTaskId) ?? draft[0];
|
|
371
|
+
if (!active) return;
|
|
372
|
+
activeTaskId = active.id;
|
|
373
|
+
const index = node("aside");
|
|
374
|
+
index.className = "task-index";
|
|
375
|
+
index.append(node("h2", "任务"));
|
|
376
|
+
const pane = node("section");
|
|
377
|
+
pane.className = "review-pane";
|
|
378
|
+
for (const task of draft) {
|
|
379
|
+
const choice = button("", () => {
|
|
380
|
+
activeTaskId = task.id;
|
|
381
|
+
draw();
|
|
382
|
+
el("list").querySelector('[aria-current="true"]').focus();
|
|
383
|
+
});
|
|
384
|
+
choice.append(node("span", task.goal));
|
|
385
|
+
if (state.reviewTaskIds?.includes(task.id)) choice.append(node("small", "待复核"));
|
|
386
|
+
choice.setAttribute("aria-current", String(task.id === active.id));
|
|
387
|
+
index.append(choice);
|
|
388
|
+
}
|
|
389
|
+
const label = node("p", "任务原文");
|
|
390
|
+
label.className = "goal-label";
|
|
391
|
+
const goal = node("p", active.goal);
|
|
392
|
+
goal.className = "full-goal";
|
|
393
|
+
const heading = node("div");
|
|
394
|
+
heading.className = "condition-heading";
|
|
395
|
+
heading.append(node("h2", "验收条件"), button("编辑条件", () => edit(active)));
|
|
396
|
+
pane.append(label, goal, heading);
|
|
397
|
+
for (const [kind, title] of [["result", "任务结果"], ["reply", "最终回复"]]) {
|
|
398
|
+
const conditions = active.criteria?.filter((c) => resultKind(c) === kind);
|
|
399
|
+
if (!conditions?.length) continue;
|
|
400
|
+
const list = node("ul");
|
|
401
|
+
for (const c of conditions) {
|
|
402
|
+
const item = node("li");
|
|
403
|
+
item.append(node("span", c.expect));
|
|
404
|
+
list.append(item);
|
|
405
|
+
}
|
|
406
|
+
pane.append(node("h3", title), list);
|
|
407
|
+
}
|
|
408
|
+
if (!active.criteria?.length) pane.append(node("p", "尚未填写验收条件"));
|
|
409
|
+
el("list").append(index, pane);
|
|
410
|
+
}
|
|
411
|
+
function draw() {
|
|
412
|
+
const editing = tab === "tasks";
|
|
413
|
+
document.querySelector("main").classList.toggle("review", !editing);
|
|
414
|
+
el("heading").textContent = editing ? "确认任务" : "确认验收条件";
|
|
415
|
+
el("tasks").setAttribute("aria-current", editing ? "step" : "false");
|
|
416
|
+
el("criteria").setAttribute("aria-current", editing ? "false" : "step");
|
|
417
|
+
el("criteria").disabled =
|
|
418
|
+
![
|
|
419
|
+
"criteria",
|
|
420
|
+
"written",
|
|
421
|
+
"pendingCriteria",
|
|
422
|
+
"awaitingCriteria",
|
|
423
|
+
].includes(state.phase);
|
|
424
|
+
const confirmed = !tasksDirty && (editing || !editedCriteria.size) && (editing ? state.phase !== "tasks" :
|
|
425
|
+
["written", "pendingCriteria"].includes(state.phase));
|
|
426
|
+
el("save").textContent = confirmed ? (state.phase === "written" ? "已写入项目" : "已确认") :
|
|
427
|
+
(editing ? "确认任务" : "确认验收");
|
|
428
|
+
el("add").hidden = !editing;
|
|
429
|
+
el("selection-count").hidden = !editing;
|
|
430
|
+
el("selection-count").textContent = editing ? "已选 " + selected.size + " 项任务" : "";
|
|
431
|
+
el("save").disabled =
|
|
432
|
+
confirmed || state.conflict ||
|
|
433
|
+
!selected.size ||
|
|
434
|
+
(!editing && (tasksDirty || draft.some((t) => !t.criteria?.length)));
|
|
435
|
+
el("list").replaceChildren();
|
|
436
|
+
if (editing) drawTaskList();
|
|
437
|
+
else drawReview();
|
|
438
|
+
el("message").textContent = state.conflict
|
|
439
|
+
? "项目文件已变更,请回到 Coding Agent 核对差异。"
|
|
440
|
+
: !editing && tasksDirty ? "任务有修改,请先确认任务。"
|
|
441
|
+
: tasksDirty ? "任务有修改,请确认任务。"
|
|
442
|
+
: editedCriteria.size
|
|
443
|
+
? (editing ? "验收条件有修改,请回到「验收条件」确认。" : "验收条件有修改,请确认验收。")
|
|
444
|
+
: {
|
|
445
|
+
pendingTasks: "任务已确认。请回到 Coding Agent 输入「继续」,写入任务并生成验收条件。",
|
|
446
|
+
awaitingCriteria: "任务已写入项目,等待验收草案。",
|
|
447
|
+
pendingCriteria:
|
|
448
|
+
"验收条件已确认。请回到 Coding Agent 输入「继续」,将验收条件写入项目。",
|
|
449
|
+
written: "评测集已写入项目。运行 nexface eval 开始评测;需要编写工具验收时,回到 Coding Agent 输入「继续」。",
|
|
450
|
+
}[state.phase] ?? "";
|
|
451
|
+
}
|
|
452
|
+
function edit(existing, restored) {
|
|
453
|
+
const task = structuredClone(
|
|
454
|
+
restored ?? existing ?? { id: crypto.randomUUID(), goal: "", criteria: [] }
|
|
455
|
+
);
|
|
456
|
+
const f = el("fields");
|
|
457
|
+
f.replaceChildren();
|
|
458
|
+
dialog.classList.toggle("criteria-editor", tab === "criteria");
|
|
459
|
+
el("apply").textContent = tab === "criteria" ? "应用修改" : "确定";
|
|
460
|
+
let read;
|
|
461
|
+
const value = (input, trim) => trim ? input.value.trim() : input.value;
|
|
462
|
+
if (tab === "tasks") {
|
|
463
|
+
el("title").textContent = existing ? "编辑任务" : "添加任务";
|
|
464
|
+
const goal = field(f, "发给 Agent 的任务", task.goal, "列出最近一笔待发货订单中库存不足的商品。", "textarea", true),
|
|
465
|
+
route = field(f, "从哪个页面开始(可选)", task.start?.route, "/orders"),
|
|
466
|
+
state = field(f, "开始前需要满足什么条件(可选)", task.start?.condition?.expect, "有一笔订单正在等发货。");
|
|
467
|
+
read = (trim) => {
|
|
468
|
+
const start = {};
|
|
469
|
+
if (value(route, trim)) start.route = value(route, trim);
|
|
470
|
+
if (value(state, trim)) {
|
|
471
|
+
start.condition = { ...task.start?.condition, expect: value(state, trim) };
|
|
472
|
+
}
|
|
473
|
+
return { ...task, goal: value(goal, trim), start };
|
|
474
|
+
};
|
|
475
|
+
} else {
|
|
476
|
+
el("title").textContent = "编辑验收条件";
|
|
477
|
+
const quote = node("div");
|
|
478
|
+
quote.className = "task-quote";
|
|
479
|
+
quote.append(node("small", "任务原文"), node("p", task.goal));
|
|
480
|
+
f.append(quote);
|
|
481
|
+
const items = node("div");
|
|
482
|
+
f.append(items);
|
|
483
|
+
const conditions = new WeakMap();
|
|
484
|
+
function add(c) {
|
|
485
|
+
const box = node("section");
|
|
486
|
+
box.className = "condition";
|
|
487
|
+
const heading = node("div");
|
|
488
|
+
heading.className = "condition-heading";
|
|
489
|
+
const reply = resultKind(c) === "reply";
|
|
490
|
+
const kind = reply ? "最终回复" : "任务结果";
|
|
491
|
+
const remove = button("", () => box.remove());
|
|
492
|
+
remove.className = "quiet remove-condition";
|
|
493
|
+
remove.title = "移除" + kind;
|
|
494
|
+
remove.setAttribute("aria-label", remove.title);
|
|
495
|
+
remove.innerHTML = '<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18M9 6V3h6v3M5 6l1 15h12l1-15M10 10v7m4-7v7"/></svg>';
|
|
496
|
+
heading.append(node("h3", kind), remove);
|
|
497
|
+
box.append(heading);
|
|
498
|
+
conditions.set(box, { ...c, id: c.id ?? crypto.randomUUID() });
|
|
499
|
+
items.append(box);
|
|
500
|
+
|
|
501
|
+
field(
|
|
502
|
+
box,
|
|
503
|
+
reply ? "你希望 Agent 怎样回答" : "任务完成后应满足什么条件",
|
|
504
|
+
c.expect,
|
|
505
|
+
reply ? "告诉我哪件货不够,还差几件。" : "订单的包裹数量为 1。",
|
|
506
|
+
"textarea",
|
|
507
|
+
true
|
|
508
|
+
);
|
|
509
|
+
return box.querySelector("textarea");
|
|
510
|
+
}
|
|
511
|
+
for (const c of task.criteria ?? []) add(c);
|
|
512
|
+
const picker = node("select");
|
|
513
|
+
picker.setAttribute("aria-label", "添加条件");
|
|
514
|
+
picker.add(new Option("+ 添加条件", ""));
|
|
515
|
+
picker.options[0].disabled = true;
|
|
516
|
+
picker.add(new Option("任务结果", "result"));
|
|
517
|
+
picker.add(new Option("最终回复", "reply"));
|
|
518
|
+
picker.value = "";
|
|
519
|
+
picker.onchange = () => {
|
|
520
|
+
const reply = picker.value === "reply";
|
|
521
|
+
const condition = reply ? { check: "reply" } : {};
|
|
522
|
+
add(condition).focus();
|
|
523
|
+
picker.value = "";
|
|
524
|
+
};
|
|
525
|
+
const pickerWrap = node("div");
|
|
526
|
+
pickerWrap.className = "condition-picker";
|
|
527
|
+
pickerWrap.append(picker);
|
|
528
|
+
f.append(pickerWrap);
|
|
529
|
+
read = (trim) => {
|
|
530
|
+
const criteria = [...items.children].map(box => ({
|
|
531
|
+
...conditions.get(box),
|
|
532
|
+
expect: value(box.querySelector("textarea"), trim),
|
|
533
|
+
}));
|
|
534
|
+
return { ...task, criteria };
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
readEditor = () => read(false);
|
|
538
|
+
el("form").onsubmit = (e) => {
|
|
539
|
+
e.preventDefault();
|
|
540
|
+
const updated = read(true);
|
|
541
|
+
if (existing) draft[draft.indexOf(existing)] = updated;
|
|
542
|
+
else {
|
|
543
|
+
draft.push(updated);
|
|
544
|
+
selected.add(task.id);
|
|
545
|
+
}
|
|
546
|
+
if (tab === "tasks") tasksDirty = true;
|
|
547
|
+
else editedCriteria.add(updated.id);
|
|
548
|
+
dialog.close();
|
|
549
|
+
draw();
|
|
550
|
+
};
|
|
551
|
+
dialog.showModal();
|
|
552
|
+
}
|
|
553
|
+
el("add").onclick = () => edit();
|
|
554
|
+
el("close").onclick = () => dialog.close();
|
|
555
|
+
el("cancel").onclick = () => dialog.close();
|
|
556
|
+
for (const id of ["tasks", "criteria"])
|
|
557
|
+
el(id).onclick = () => {
|
|
558
|
+
if (id === tab) return;
|
|
559
|
+
tab = id;
|
|
560
|
+
draw();
|
|
561
|
+
};
|
|
562
|
+
el("save").onclick = async () => {
|
|
563
|
+
const tasks = draft.filter((t) => selected.has(t.id));
|
|
564
|
+
if (tab === "criteria") {
|
|
565
|
+
for (const task of tasks) {
|
|
566
|
+
for (const condition of task.criteria) condition.id ??= crypto.randomUUID();
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
const suite = {
|
|
570
|
+
schemaVersion: 0,
|
|
571
|
+
status: tab === "tasks" ? "draft" : "ready",
|
|
572
|
+
tasks,
|
|
573
|
+
};
|
|
574
|
+
try {
|
|
575
|
+
const r = await fetch("/draft", {
|
|
576
|
+
method: "POST",
|
|
577
|
+
headers: { "Content-Type": "application/json" },
|
|
578
|
+
body: JSON.stringify({ action: tab, revision: baseRevision, suite,
|
|
579
|
+
...(tab === "tasks" && { editedCriteriaIds: [...editedCriteria] }) }),
|
|
580
|
+
});
|
|
581
|
+
const s = await r.json();
|
|
582
|
+
if (!r.ok) throw Error(s.error);
|
|
583
|
+
load(s);
|
|
584
|
+
} catch (e) {
|
|
585
|
+
el("message").textContent = e.message;
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
async function refresh() {
|
|
589
|
+
try {
|
|
590
|
+
const previous = state;
|
|
591
|
+
const response = await fetch("/draft");
|
|
592
|
+
const s = await response.json();
|
|
593
|
+
if (!response.ok) throw new Error(s.error ?? "Draft unavailable.");
|
|
594
|
+
if (previous !== state) return;
|
|
595
|
+
if (!state) {
|
|
596
|
+
load(s);
|
|
597
|
+
restore();
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (
|
|
601
|
+
!dirty() &&
|
|
602
|
+
!dialog.open &&
|
|
603
|
+
(s.revision !== state?.revision || s.conflict !== state?.conflict)
|
|
604
|
+
)
|
|
605
|
+
load(s);
|
|
606
|
+
} catch (e) {
|
|
607
|
+
el("message").textContent = e.message;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
await refresh();
|
|
611
|
+
setInterval(refresh, 1200);
|
|
612
|
+
</script>
|
|
613
|
+
</html>
|