@clemrig/factory 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +198 -2
- package/dist/app/doctor.d.ts +20 -0
- package/dist/app/doctor.js +38 -0
- package/dist/app/doctor.js.map +1 -0
- package/dist/app/factory.d.ts +12 -0
- package/dist/app/factory.js +22 -0
- package/dist/app/factory.js.map +1 -0
- package/dist/app/init.d.ts +6 -0
- package/dist/app/init.js +15 -0
- package/dist/app/init.js.map +1 -0
- package/dist/app/run.d.ts +24 -0
- package/dist/app/run.js +100 -0
- package/dist/app/run.js.map +1 -0
- package/dist/app/runs.d.ts +36 -0
- package/dist/app/runs.js +66 -0
- package/dist/app/runs.js.map +1 -0
- package/dist/cli/application.d.ts +6 -0
- package/dist/cli/application.js +63 -0
- package/dist/cli/application.js.map +1 -0
- package/dist/cli/args.d.ts +12 -0
- package/dist/cli/args.js +45 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/doctor.d.ts +5 -0
- package/dist/cli/doctor.js +33 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/help.d.ts +1 -0
- package/dist/cli/help.js +17 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/init.d.ts +6 -0
- package/dist/cli/init.js +18 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/launcher.d.ts +5 -0
- package/dist/cli/launcher.js +55 -0
- package/dist/cli/launcher.js.map +1 -0
- package/dist/cli/reporter.d.ts +17 -0
- package/dist/cli/reporter.js +123 -0
- package/dist/cli/reporter.js.map +1 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.js +39 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/status.d.ts +4 -0
- package/dist/cli/status.js +15 -0
- package/dist/cli/status.js.map +1 -0
- package/dist/cli/ui.d.ts +3 -0
- package/dist/cli/ui.js +18 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/engine/metrics.d.ts +45 -0
- package/dist/engine/metrics.js +60 -0
- package/dist/engine/metrics.js.map +1 -0
- package/dist/engine/primitives.d.ts +34 -0
- package/dist/engine/primitives.js +81 -0
- package/dist/engine/primitives.js.map +1 -0
- package/dist/engine/profiles.d.ts +53 -0
- package/dist/engine/profiles.js +117 -0
- package/dist/engine/profiles.js.map +1 -0
- package/dist/engine/runner.d.ts +13 -0
- package/dist/engine/runner.js +157 -0
- package/dist/engine/runner.js.map +1 -0
- package/dist/engine/types.d.ts +194 -0
- package/dist/engine/types.js +2 -0
- package/dist/engine/types.js.map +1 -0
- package/dist/engine/workflow.d.ts +18 -0
- package/dist/engine/workflow.js +196 -0
- package/dist/engine/workflow.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -0
- package/dist/system/environment.d.ts +2 -0
- package/dist/system/environment.js +13 -0
- package/dist/system/environment.js.map +1 -0
- package/dist/system/factory.d.ts +16 -0
- package/dist/system/factory.js +62 -0
- package/dist/system/factory.js.map +1 -0
- package/dist/system/process.d.ts +21 -0
- package/dist/system/process.js +238 -0
- package/dist/system/process.js.map +1 -0
- package/dist/system/runtimes/adapter.d.ts +90 -0
- package/dist/system/runtimes/adapter.js +20 -0
- package/dist/system/runtimes/adapter.js.map +1 -0
- package/dist/system/runtimes/agent-runtime.d.ts +45 -0
- package/dist/system/runtimes/agent-runtime.js +184 -0
- package/dist/system/runtimes/agent-runtime.js.map +1 -0
- package/dist/system/runtimes/claude-code.d.ts +10 -0
- package/dist/system/runtimes/claude-code.js +383 -0
- package/dist/system/runtimes/claude-code.js.map +1 -0
- package/dist/system/runtimes/inspect.d.ts +25 -0
- package/dist/system/runtimes/inspect.js +129 -0
- package/dist/system/runtimes/inspect.js.map +1 -0
- package/dist/system/runtimes/pi.d.ts +7 -0
- package/dist/system/runtimes/pi.js +235 -0
- package/dist/system/runtimes/pi.js.map +1 -0
- package/dist/system/runtimes/protocol.d.ts +9 -0
- package/dist/system/runtimes/protocol.js +38 -0
- package/dist/system/runtimes/protocol.js.map +1 -0
- package/dist/system/runtimes/registry.d.ts +5 -0
- package/dist/system/runtimes/registry.js +5 -0
- package/dist/system/runtimes/registry.js.map +1 -0
- package/dist/system/store.d.ts +20 -0
- package/dist/system/store.js +126 -0
- package/dist/system/store.js.map +1 -0
- package/dist/system/templates.d.ts +8 -0
- package/dist/system/templates.js +30 -0
- package/dist/system/templates.js.map +1 -0
- package/dist/ui/server.d.ts +8 -0
- package/dist/ui/server.js +111 -0
- package/dist/ui/server.js.map +1 -0
- package/dist/ui/static/dashboard.js +266 -0
- package/dist/ui/static/follow.js +67 -0
- package/dist/ui/static/index.html +20 -0
- package/dist/ui/static/style.css +166 -0
- package/dist/ui/static/timeline.js +180 -0
- package/package.json +52 -4
- package/templates/init/factory.ts +4 -0
- package/templates/init/gitignore +3 -0
- package/templates/init/tsconfig.json +13 -0
- package/templates/init/workflows/ask/index.ts +57 -0
- package/templates/init/workflows/ask/prompts/answer.md +7 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/ui/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL,YAAY,GAIb,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EACL,QAAQ,EACR,OAAO,EACP,aAAa,EACb,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,gEAAgE;AAChE,KAAK,UAAU,IAAI,CAAC,OAAgB;IAClC,OAAO;QACL,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC;QACjC,IAAI,EAAE,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,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G,EAAE,CACV,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC7D,MAAM,CAAC,mBAAmB,EAAE,CAAC;QAC/B,CAAC,CAAC;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* The dashboard: the run list every 2 seconds, and the selected run as
|
|
4
|
+
* `follow.js` follows it. Text only, never HTML.
|
|
5
|
+
*/
|
|
6
|
+
import { follower } from "./follow.js";
|
|
7
|
+
import { cost, duration, timeline } from "./timeline.js";
|
|
8
|
+
|
|
9
|
+
/** @typedef {import("../../engine/types.js").RunEvent} RunEvent */
|
|
10
|
+
/** @typedef {import("./timeline.js").Block} Block */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {object} Summary
|
|
14
|
+
* @property {string} id
|
|
15
|
+
* @property {string} [workflow]
|
|
16
|
+
* @property {string} [status]
|
|
17
|
+
* @property {string} [stage]
|
|
18
|
+
* @property {number | null} [durationMs]
|
|
19
|
+
* @property {number | null} [costUsd]
|
|
20
|
+
* @property {boolean} [partial]
|
|
21
|
+
* @property {string} [updatedAt]
|
|
22
|
+
* @property {string} [error] Why the run cannot be read.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} Detail
|
|
27
|
+
* @property {Required<Omit<Summary, "error">>} run
|
|
28
|
+
* @property {Record<string, string>} runtimes
|
|
29
|
+
* @property {string | null} error
|
|
30
|
+
* @property {RunEvent[]} events
|
|
31
|
+
* @property {number} next
|
|
32
|
+
* @property {{ key: string; count: number; max: number | null }[]} corrections
|
|
33
|
+
* @property {string[]} result
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
const LIST_EVERY_MS = 2000;
|
|
37
|
+
const DETAIL_EVERY_MS = 1000;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} id
|
|
41
|
+
* @returns {HTMLElement}
|
|
42
|
+
*/
|
|
43
|
+
function byId(id) {
|
|
44
|
+
const found = document.getElementById(id);
|
|
45
|
+
if (!found) throw new Error(`Missing element #${id}`);
|
|
46
|
+
return found;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} tag
|
|
51
|
+
* @param {string} [text]
|
|
52
|
+
* @param {string} [className]
|
|
53
|
+
* @returns {HTMLElement}
|
|
54
|
+
*/
|
|
55
|
+
function el(tag, text, className) {
|
|
56
|
+
const node = document.createElement(tag);
|
|
57
|
+
if (text !== undefined) node.textContent = text;
|
|
58
|
+
if (className) node.className = className;
|
|
59
|
+
return node;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @param {string} iso */
|
|
63
|
+
function time(iso) {
|
|
64
|
+
const date = new Date(iso);
|
|
65
|
+
return Number.isNaN(date.getTime())
|
|
66
|
+
? iso
|
|
67
|
+
: date.toLocaleString(undefined, {
|
|
68
|
+
dateStyle: "short",
|
|
69
|
+
timeStyle: "medium",
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** @param {import("../../engine/metrics.js").TokenCounts} tokens */
|
|
74
|
+
function tokenLine(tokens) {
|
|
75
|
+
return `${tokens.input} input · ${tokens.output} output · ${tokens.cacheRead} cache read · ${tokens.cacheWrite} cache write tokens`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {string} path
|
|
80
|
+
* @returns {Promise<any>}
|
|
81
|
+
*/
|
|
82
|
+
async function load(path) {
|
|
83
|
+
const response = await fetch(path, { cache: "no-store" });
|
|
84
|
+
if (!response.ok)
|
|
85
|
+
throw Object.assign(
|
|
86
|
+
new Error((await response.text()) || `HTTP ${response.status}`),
|
|
87
|
+
{ status: response.status },
|
|
88
|
+
);
|
|
89
|
+
return response.json();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The run the address names, or none when it cannot be read. */
|
|
93
|
+
function fromHash() {
|
|
94
|
+
try {
|
|
95
|
+
return decodeURIComponent(location.hash.slice(1));
|
|
96
|
+
} catch {
|
|
97
|
+
return "";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let selected = fromHash();
|
|
102
|
+
|
|
103
|
+
/** @param {Summary[]} runs */
|
|
104
|
+
function showRuns(runs) {
|
|
105
|
+
byId("none").hidden = runs.length > 0;
|
|
106
|
+
byId("runs").replaceChildren(
|
|
107
|
+
...runs.map((run) => {
|
|
108
|
+
const row = el("tr");
|
|
109
|
+
row.title = run.id;
|
|
110
|
+
if (run.id === selected) row.className = "selected";
|
|
111
|
+
if (run.error !== undefined) {
|
|
112
|
+
const cause = el("td", run.error);
|
|
113
|
+
cause.setAttribute("colspan", "4");
|
|
114
|
+
row.append(el("td", run.id), el("td", "unreadable", "failed"), cause);
|
|
115
|
+
} else
|
|
116
|
+
row.append(
|
|
117
|
+
el("td", run.workflow),
|
|
118
|
+
el("td", run.status, run.status),
|
|
119
|
+
el("td", run.stage),
|
|
120
|
+
el("td", duration(run.durationMs ?? null)),
|
|
121
|
+
el("td", cost(run.costUsd ?? null, run.partial ?? false)),
|
|
122
|
+
el("td", time(run.updatedAt ?? "")),
|
|
123
|
+
);
|
|
124
|
+
row.addEventListener("click", () => select(run.id));
|
|
125
|
+
return row;
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** @param {Block} block */
|
|
131
|
+
function showBlock(block) {
|
|
132
|
+
const item = el("li", undefined, "block");
|
|
133
|
+
const head = el("p");
|
|
134
|
+
head.append(
|
|
135
|
+
`${block.kind} ${block.stage} · `,
|
|
136
|
+
el("span", block.status, block.status),
|
|
137
|
+
block.durationMs === null ? "" : ` · ${duration(block.durationMs)}`,
|
|
138
|
+
);
|
|
139
|
+
item.append(head);
|
|
140
|
+
const line = (/** @type {string} */ text, className = "line") =>
|
|
141
|
+
item.append(el("p", text, className));
|
|
142
|
+
const { call } = block;
|
|
143
|
+
if (call?.model)
|
|
144
|
+
line(`${call.runtime} ${call.model} · session ${call.session}`);
|
|
145
|
+
for (const tool of block.tools)
|
|
146
|
+
line(
|
|
147
|
+
tool.status === "running"
|
|
148
|
+
? `${tool.name} …`
|
|
149
|
+
: `${tool.name}${tool.status === "failed" ? " failed" : ""} ${((tool.durationMs ?? 0) / 1000).toFixed(1)} s`,
|
|
150
|
+
);
|
|
151
|
+
if (call?.usage)
|
|
152
|
+
line(
|
|
153
|
+
`${call.scope === "session" ? "Session total" : "Call"}: ${tokenLine(call.usage)} · ${cost(call.usage.costUsd, false)}`,
|
|
154
|
+
);
|
|
155
|
+
else if (block.tokens)
|
|
156
|
+
line(
|
|
157
|
+
`So far: ${tokenLine(block.tokens)}${block.provisional ? " (provisional)" : ""}`,
|
|
158
|
+
);
|
|
159
|
+
for (const warning of block.warnings) line(warning, "line warning");
|
|
160
|
+
for (const entry of block.journal) line(`${time(entry.at)} ${entry.message}`);
|
|
161
|
+
if (block.decision) {
|
|
162
|
+
const { verdict, reason, destination } = block.decision;
|
|
163
|
+
const retry = block.retry
|
|
164
|
+
? ` [${block.retry.key} ${block.retry.count}/${block.retry.max}]`
|
|
165
|
+
: "";
|
|
166
|
+
line(`${verdict} — ${reason} → ${destination ?? "end"}${retry}`);
|
|
167
|
+
}
|
|
168
|
+
if (block.detail) line(block.detail, "line failed");
|
|
169
|
+
return item;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @param {Detail} detail
|
|
174
|
+
* @param {RunEvent[]} events Every event received for the run.
|
|
175
|
+
*/
|
|
176
|
+
function showDetail(detail, events) {
|
|
177
|
+
const { run } = detail;
|
|
178
|
+
const summary = el("section");
|
|
179
|
+
const line = el("p", undefined, "empty");
|
|
180
|
+
line.append(
|
|
181
|
+
el("span", run.status, run.status),
|
|
182
|
+
` · ${run.stage} · ${duration(run.durationMs)} · ${cost(run.costUsd, run.partial)}`,
|
|
183
|
+
);
|
|
184
|
+
summary.append(el("h3", `${run.workflow} · ${run.id}`), line);
|
|
185
|
+
for (const runtime of Object.values(detail.runtimes))
|
|
186
|
+
summary.append(el("p", runtime, "line"));
|
|
187
|
+
if (detail.error) summary.append(el("pre", detail.error, "failed"));
|
|
188
|
+
const stages = el("section");
|
|
189
|
+
const blocks = el("ol");
|
|
190
|
+
blocks.append(...timeline(events).map(showBlock));
|
|
191
|
+
stages.append(el("h2", "Timeline"), blocks);
|
|
192
|
+
const sections = [summary, stages];
|
|
193
|
+
if (detail.corrections.length) {
|
|
194
|
+
const corrections = el("section");
|
|
195
|
+
corrections.append(el("h2", "Corrections"));
|
|
196
|
+
for (const { key, count, max } of detail.corrections)
|
|
197
|
+
corrections.append(el("p", `${key} ${count}/${max ?? "?"}`, "line"));
|
|
198
|
+
sections.push(corrections);
|
|
199
|
+
}
|
|
200
|
+
const result = el("section");
|
|
201
|
+
result.append(el("h2", "Result"), el("pre", detail.result.join("\n")));
|
|
202
|
+
sections.push(result);
|
|
203
|
+
byId("detail").replaceChildren(...sections);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** @param {string} message */
|
|
207
|
+
function updated(message) {
|
|
208
|
+
byId("updated").textContent = message;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function refreshRuns() {
|
|
212
|
+
try {
|
|
213
|
+
const { repository, runs } = await load("/api/runs");
|
|
214
|
+
byId("repository").textContent = repository;
|
|
215
|
+
showRuns(runs);
|
|
216
|
+
updated(`Updated ${new Date().toLocaleTimeString()}`);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
unavailable(error);
|
|
219
|
+
}
|
|
220
|
+
setTimeout(refreshRuns, LIST_EVERY_MS);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** @param {unknown} error */
|
|
224
|
+
const unavailable = (error) =>
|
|
225
|
+
updated(
|
|
226
|
+
`Unavailable: ${error instanceof Error ? error.message : String(error)}`,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
/** @param {string} text */
|
|
230
|
+
const placeholder = (text) =>
|
|
231
|
+
byId("detail").replaceChildren(el("p", text, "empty"));
|
|
232
|
+
|
|
233
|
+
const follow = follower({
|
|
234
|
+
load,
|
|
235
|
+
schedule: (work) => setTimeout(work, DETAIL_EVERY_MS),
|
|
236
|
+
cancel: (timer) => clearTimeout(timer),
|
|
237
|
+
show: (detail, events) => showDetail(detail, events),
|
|
238
|
+
fail: (error) => {
|
|
239
|
+
const { status } = /** @type {{ status?: number }} */ (error);
|
|
240
|
+
// The follower stops on a run that does not exist and retries the rest.
|
|
241
|
+
if (status === 404) placeholder("This run does not exist.");
|
|
242
|
+
else if (status)
|
|
243
|
+
placeholder(
|
|
244
|
+
`This run cannot be read: ${error instanceof Error ? error.message : String(error)}`,
|
|
245
|
+
);
|
|
246
|
+
else unavailable(error);
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
/** @param {string} id */
|
|
251
|
+
function select(id) {
|
|
252
|
+
if (id === selected) return;
|
|
253
|
+
selected = id;
|
|
254
|
+
if (fromHash() !== id) location.hash = encodeURIComponent(id);
|
|
255
|
+
placeholder(id ? "Loading…" : "Select a run.");
|
|
256
|
+
for (const row of byId("runs").children)
|
|
257
|
+
row.className =
|
|
258
|
+
/** @type {HTMLElement} */ (row).title === id ? "selected" : "";
|
|
259
|
+
follow.select(id);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// A link or the history can change the selected run without reloading the page.
|
|
263
|
+
window.addEventListener("hashchange", () => select(fromHash()));
|
|
264
|
+
refreshRuns();
|
|
265
|
+
if (selected) placeholder("Loading…");
|
|
266
|
+
follow.select(selected);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* Follows the selected run: asks only for the events not received yet, one
|
|
4
|
+
* request after the answer to the previous one, drops an answer for a selection
|
|
5
|
+
* that has changed since, and stops once the run has ended or does not exist.
|
|
6
|
+
* Requests and timers are given, so that this logic is tested without a browser.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @typedef {import("../../engine/types.js").RunEvent} RunEvent */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {object} Answer
|
|
13
|
+
* @property {{ status: string }} run
|
|
14
|
+
* @property {RunEvent[]} events Events from the index the request asked for.
|
|
15
|
+
* @property {number} next The index to ask for next.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @template Timer
|
|
20
|
+
* @param {object} options
|
|
21
|
+
* @param {(path: string) => Promise<any>} options.load Rejects with `status` set on an HTTP error.
|
|
22
|
+
* @param {(work: () => void) => Timer} options.schedule Runs `work` after the polling interval.
|
|
23
|
+
* @param {(timer: Timer | undefined) => void} options.cancel
|
|
24
|
+
* @param {(answer: any, events: RunEvent[]) => void} options.show The latest answer and every event received.
|
|
25
|
+
* @param {(error: unknown) => void} options.fail
|
|
26
|
+
*/
|
|
27
|
+
export function follower({ load, schedule, cancel, show, fail }) {
|
|
28
|
+
/** One selection: a new object each time, so that an old answer never matches. */
|
|
29
|
+
let current = { id: "", events: /** @type {RunEvent[]} */ ([]), next: 0 };
|
|
30
|
+
/** @type {Timer | undefined} */
|
|
31
|
+
let timer;
|
|
32
|
+
|
|
33
|
+
/** @param {typeof current} target */
|
|
34
|
+
async function refresh(target) {
|
|
35
|
+
if (!target.id) return;
|
|
36
|
+
/** @type {Answer} */
|
|
37
|
+
let answer;
|
|
38
|
+
try {
|
|
39
|
+
answer = await load(
|
|
40
|
+
`/api/runs/${encodeURIComponent(target.id)}?after=${target.next}`,
|
|
41
|
+
);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (target !== current) return;
|
|
44
|
+
fail(error);
|
|
45
|
+
// A run that does not exist will not appear later.
|
|
46
|
+
const status = /** @type {{ status?: number }} */ (error).status;
|
|
47
|
+
if (status !== 404) timer = schedule(() => refresh(target));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (target !== current) return;
|
|
51
|
+
target.events.push(...answer.events);
|
|
52
|
+
target.next = answer.next;
|
|
53
|
+
show(answer, target.events);
|
|
54
|
+
if (answer.run.status === "running")
|
|
55
|
+
timer = schedule(() => refresh(target));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
/** @param {string} id */
|
|
60
|
+
select(id) {
|
|
61
|
+
if (id === current.id) return;
|
|
62
|
+
cancel(timer);
|
|
63
|
+
current = { id, events: [], next: 0 };
|
|
64
|
+
refresh(current);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>factory</title>
|
|
7
|
+
<link rel="stylesheet" href="/style.css">
|
|
8
|
+
<script type="module" src="/dashboard.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<header><h1>factory</h1><span id="repository"></span><span id="updated"></span></header>
|
|
12
|
+
<main>
|
|
13
|
+
<div>
|
|
14
|
+
<div class="table"><table><thead><tr><th>Workflow</th><th>Status</th><th>Stage</th><th>Duration</th><th>Cost</th><th>Updated</th></tr></thead><tbody id="runs"></tbody></table></div>
|
|
15
|
+
<p id="none" class="empty" hidden>No run yet.</p>
|
|
16
|
+
</div>
|
|
17
|
+
<div id="detail"><p class="empty">Select a run.</p></div>
|
|
18
|
+
</main>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color-scheme: light dark;
|
|
3
|
+
--bg: #f7f7f5;
|
|
4
|
+
--panel: #fff;
|
|
5
|
+
--fg: #1d1d1b;
|
|
6
|
+
--muted: #6f6e69;
|
|
7
|
+
--line: #e4e3df;
|
|
8
|
+
--accent: #2557d6;
|
|
9
|
+
--ok: #19773a;
|
|
10
|
+
--bad: #b42318;
|
|
11
|
+
--run: #a15c07;
|
|
12
|
+
}
|
|
13
|
+
@media (prefers-color-scheme: dark) {
|
|
14
|
+
:root {
|
|
15
|
+
--bg: #111110;
|
|
16
|
+
--panel: #1b1b19;
|
|
17
|
+
--fg: #e8e7e3;
|
|
18
|
+
--muted: #9b9a94;
|
|
19
|
+
--line: #2c2c29;
|
|
20
|
+
--accent: #7aa2ff;
|
|
21
|
+
--ok: #5bd28a;
|
|
22
|
+
--bad: #ff7a6b;
|
|
23
|
+
--run: #f2b14c;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
* {
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
}
|
|
29
|
+
body {
|
|
30
|
+
margin: 0;
|
|
31
|
+
background: var(--bg);
|
|
32
|
+
color: var(--fg);
|
|
33
|
+
font:
|
|
34
|
+
14px / 1.45 ui-sans-serif,
|
|
35
|
+
system-ui,
|
|
36
|
+
-apple-system,
|
|
37
|
+
sans-serif;
|
|
38
|
+
}
|
|
39
|
+
header {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-wrap: wrap;
|
|
42
|
+
gap: 4px 12px;
|
|
43
|
+
align-items: baseline;
|
|
44
|
+
padding: 12px 16px;
|
|
45
|
+
border-bottom: 1px solid var(--line);
|
|
46
|
+
}
|
|
47
|
+
header h1 {
|
|
48
|
+
margin: 0;
|
|
49
|
+
font-size: 16px;
|
|
50
|
+
}
|
|
51
|
+
header span {
|
|
52
|
+
color: var(--muted);
|
|
53
|
+
font-size: 13px;
|
|
54
|
+
}
|
|
55
|
+
#updated {
|
|
56
|
+
margin-left: auto;
|
|
57
|
+
}
|
|
58
|
+
main {
|
|
59
|
+
display: grid;
|
|
60
|
+
grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
|
|
61
|
+
gap: 16px;
|
|
62
|
+
padding: 16px;
|
|
63
|
+
}
|
|
64
|
+
@media (max-width: 900px) {
|
|
65
|
+
main {
|
|
66
|
+
grid-template-columns: minmax(0, 1fr);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
.table {
|
|
70
|
+
overflow-x: auto;
|
|
71
|
+
background: var(--panel);
|
|
72
|
+
border: 1px solid var(--line);
|
|
73
|
+
border-radius: 6px;
|
|
74
|
+
}
|
|
75
|
+
table {
|
|
76
|
+
width: 100%;
|
|
77
|
+
border-collapse: collapse;
|
|
78
|
+
}
|
|
79
|
+
th,
|
|
80
|
+
td {
|
|
81
|
+
padding: 7px 10px;
|
|
82
|
+
border-bottom: 1px solid var(--line);
|
|
83
|
+
text-align: left;
|
|
84
|
+
white-space: nowrap;
|
|
85
|
+
}
|
|
86
|
+
th {
|
|
87
|
+
color: var(--muted);
|
|
88
|
+
font-size: 12px;
|
|
89
|
+
font-weight: 500;
|
|
90
|
+
}
|
|
91
|
+
tbody tr {
|
|
92
|
+
cursor: pointer;
|
|
93
|
+
}
|
|
94
|
+
tbody tr:hover,
|
|
95
|
+
tbody tr.selected {
|
|
96
|
+
background: color-mix(in srgb, var(--accent) 12%, transparent);
|
|
97
|
+
}
|
|
98
|
+
.completed,
|
|
99
|
+
.passed {
|
|
100
|
+
color: var(--ok);
|
|
101
|
+
}
|
|
102
|
+
.failed {
|
|
103
|
+
color: var(--bad);
|
|
104
|
+
}
|
|
105
|
+
.running {
|
|
106
|
+
color: var(--run);
|
|
107
|
+
}
|
|
108
|
+
section {
|
|
109
|
+
margin-bottom: 12px;
|
|
110
|
+
padding: 10px 12px;
|
|
111
|
+
background: var(--panel);
|
|
112
|
+
border: 1px solid var(--line);
|
|
113
|
+
border-radius: 6px;
|
|
114
|
+
}
|
|
115
|
+
h2 {
|
|
116
|
+
margin: 0 0 8px;
|
|
117
|
+
color: var(--muted);
|
|
118
|
+
font-size: 12px;
|
|
119
|
+
font-weight: 600;
|
|
120
|
+
letter-spacing: 0.04em;
|
|
121
|
+
text-transform: uppercase;
|
|
122
|
+
}
|
|
123
|
+
h3 {
|
|
124
|
+
margin: 0 0 4px;
|
|
125
|
+
font-size: 14px;
|
|
126
|
+
overflow-wrap: anywhere;
|
|
127
|
+
}
|
|
128
|
+
ol {
|
|
129
|
+
margin: 0;
|
|
130
|
+
padding: 0;
|
|
131
|
+
list-style: none;
|
|
132
|
+
}
|
|
133
|
+
.block {
|
|
134
|
+
padding: 6px 0;
|
|
135
|
+
border-bottom: 1px dotted var(--line);
|
|
136
|
+
}
|
|
137
|
+
.block:last-child {
|
|
138
|
+
border-bottom: 0;
|
|
139
|
+
}
|
|
140
|
+
.block > p {
|
|
141
|
+
margin: 0;
|
|
142
|
+
}
|
|
143
|
+
.line,
|
|
144
|
+
pre {
|
|
145
|
+
font:
|
|
146
|
+
12px / 1.45 ui-monospace,
|
|
147
|
+
SFMono-Regular,
|
|
148
|
+
Menlo,
|
|
149
|
+
monospace;
|
|
150
|
+
overflow-wrap: anywhere;
|
|
151
|
+
}
|
|
152
|
+
.line {
|
|
153
|
+
margin: 2px 0 0 16px;
|
|
154
|
+
color: var(--muted);
|
|
155
|
+
}
|
|
156
|
+
.warning {
|
|
157
|
+
color: var(--run);
|
|
158
|
+
}
|
|
159
|
+
pre {
|
|
160
|
+
margin: 0;
|
|
161
|
+
white-space: pre-wrap;
|
|
162
|
+
}
|
|
163
|
+
.empty {
|
|
164
|
+
margin: 0;
|
|
165
|
+
color: var(--muted);
|
|
166
|
+
}
|