@hexdecimal16/nexo 0.0.0-stage → 0.2.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 +75 -0
- package/README.md +75 -2
- package/cli/src/bin.js +12 -0
- package/cli/src/common.js +77 -0
- package/cli/src/doctor.js +27 -0
- package/cli/src/eval-cases.js +65 -0
- package/cli/src/eval.js +67 -0
- package/cli/src/init.js +186 -0
- package/cli/src/interactive.js +171 -0
- package/cli/src/learn.js +178 -0
- package/cli/src/main.js +261 -0
- package/cli/src/optimize.js +289 -0
- package/cli/src/prompter.js +47 -0
- package/cli/src/review.js +120 -0
- package/cli/src/runtime.js +2 -0
- package/cli/src/sessions.js +34 -0
- package/cli/src/settings.js +169 -0
- package/cli/src/ui.js +112 -0
- package/core/src/approval/classifier.js +152 -0
- package/core/src/config/load.js +283 -0
- package/core/src/config/schema.js +186 -0
- package/core/src/cost/admission.js +90 -0
- package/core/src/cost/budget.js +67 -0
- package/core/src/cost/pricing.js +53 -0
- package/core/src/engine/charged-completion.js +79 -0
- package/core/src/engine/errors.js +77 -0
- package/core/src/engine/mcp.js +11 -0
- package/core/src/engine/messages.js +86 -0
- package/core/src/engine/prompts.js +32 -0
- package/core/src/engine/provider-gate.js +33 -0
- package/core/src/engine/recorder.js +61 -0
- package/core/src/engine/run.js +1115 -0
- package/core/src/engine/semaphore.js +45 -0
- package/core/src/engine/spawn-tool.js +119 -0
- package/core/src/engine/task-graph.js +153 -0
- package/core/src/index.js +32 -0
- package/core/src/learn/caller.js +171 -0
- package/core/src/learn/context.js +112 -0
- package/core/src/learn/embedder.js +216 -0
- package/core/src/learn/job.js +196 -0
- package/core/src/learn/wiki.js +116 -0
- package/core/src/learn/worker.js +141 -0
- package/core/src/optimize/adapter.js +250 -0
- package/core/src/optimize/climb.js +338 -0
- package/core/src/optimize/mine.js +95 -0
- package/core/src/optimize/optimize.js +377 -0
- package/core/src/optimize/optimizer-run.js +67 -0
- package/core/src/optimize/reflect.js +100 -0
- package/core/src/optimize/scratchpad-wiki.js +69 -0
- package/core/src/providers/claude-p.js +363 -0
- package/core/src/providers/kiro-p.js +408 -0
- package/core/src/providers/models.js +10 -0
- package/core/src/scoring/calibration.js +31 -0
- package/core/src/scoring/continuation.js +24 -0
- package/core/src/scoring/runner.js +322 -0
- package/core/src/scoring/sources.js +88 -0
- package/core/src/session/lock.js +88 -0
- package/core/src/session/session.js +647 -0
- package/core/src/session/shell.js +26 -0
- package/core/src/session/transcript.js +86 -0
- package/core/src/settings/config-edit.js +472 -0
- package/core/src/settings/credentials.js +120 -0
- package/core/src/settings/doctor.js +103 -0
- package/core/src/settings/settings.js +265 -0
- package/mcp/src/hub.js +184 -0
- package/mcp/src/index.js +1 -0
- package/memory/src/curate.js +121 -0
- package/memory/src/index.js +4 -0
- package/memory/src/prompts.js +143 -0
- package/memory/src/retrieval.js +91 -0
- package/memory/src/similarity.js +47 -0
- package/optimize/src/engine.js +206 -0
- package/optimize/src/index.js +8 -0
- package/optimize/src/merge.js +73 -0
- package/optimize/src/novelty.js +37 -0
- package/optimize/src/pareto.js +83 -0
- package/optimize/src/proposer.js +148 -0
- package/optimize/src/report.js +107 -0
- package/optimize/src/rng.js +34 -0
- package/optimize/src/target.js +34 -0
- package/package.json +47 -4
- package/router/src/effort.js +5 -0
- package/router/src/escalation.js +171 -0
- package/router/src/index.js +4 -0
- package/router/src/registry.js +21 -0
- package/router/src/resolve.js +117 -0
- package/scorers/src/deterministic.js +194 -0
- package/scorers/src/family.js +48 -0
- package/scorers/src/index.js +6 -0
- package/scorers/src/judge.js +284 -0
- package/scorers/src/regex-worker.js +3 -0
- package/scorers/src/spec.js +147 -0
- package/scorers/src/trajectory.js +22 -0
- package/scorers/src/types.js +1 -0
- package/sdk/src/index.js +3 -0
- package/sdk/src/nexo.js +94 -0
- package/sdk/src/runtime.js +39 -0
- package/skills/bundled/browser/SKILL.md +57 -0
- package/skills/bundled/wiki/SKILL.md +73 -0
- package/skills/src/frontmatter.js +25 -0
- package/skills/src/index.js +3 -0
- package/skills/src/load-skill-tool.js +41 -0
- package/skills/src/loader.js +95 -0
- package/store/src/artifacts.js +124 -0
- package/store/src/budget-ledger.js +18 -0
- package/store/src/cost-report.js +46 -0
- package/store/src/cursor.js +35 -0
- package/store/src/db.js +83 -0
- package/store/src/errors.js +9 -0
- package/store/src/eval-cases.js +255 -0
- package/store/src/feedback.js +154 -0
- package/store/src/goldens.js +61 -0
- package/store/src/ids.js +6 -0
- package/store/src/index.js +25 -0
- package/store/src/judge-calibration.js +182 -0
- package/store/src/learn-jobs.js +145 -0
- package/store/src/memories.js +261 -0
- package/store/src/migrations/001_init.sql +81 -0
- package/store/src/migrations/002_feedback.sql +9 -0
- package/store/src/migrations/003_sessions.sql +19 -0
- package/store/src/migrations/004_scoring.sql +22 -0
- package/store/src/migrations/005_judge_calibration.sql +27 -0
- package/store/src/migrations/006_learning.sql +77 -0
- package/store/src/migrations/007_optimize.sql +55 -0
- package/store/src/migrations/008_mined_cases_and_climb.sql +46 -0
- package/store/src/mine.js +51 -0
- package/store/src/optim.js +291 -0
- package/store/src/paths.js +22 -0
- package/store/src/playbooks.js +199 -0
- package/store/src/reindex.js +143 -0
- package/store/src/run-dir.js +151 -0
- package/store/src/runs.js +310 -0
- package/store/src/scores.js +92 -0
- package/store/src/sessions.js +304 -0
- package/store/src/span-tree.js +98 -0
- package/store/src/spans.js +84 -0
- package/store/src/sql.js +13 -0
- package/store/src/workspace-copy.js +80 -0
- package/telemetry/src/errors.js +32 -0
- package/telemetry/src/index.js +3 -0
- package/telemetry/src/logger.js +39 -0
- package/telemetry/src/redact.js +106 -0
- package/tools/src/builtin.js +269 -0
- package/tools/src/change-tracker.js +57 -0
- package/tools/src/confine.js +101 -0
- package/tools/src/index.js +7 -0
- package/tools/src/leases.js +57 -0
- package/tools/src/policy.js +162 -0
- package/tools/src/read-only.js +338 -0
- package/tools/src/session-rules.js +140 -0
- package/tui/src/app.js +948 -0
- package/tui/src/approvals.js +96 -0
- package/tui/src/commands.js +38 -0
- package/tui/src/components.js +248 -0
- package/tui/src/index.js +5 -0
- package/tui/src/picker.js +78 -0
- package/tui/src/session-picker.js +100 -0
- package/tui/src/settings-screen.js +346 -0
- package/tui/src/text.js +70 -0
- package/tui/src/theme.js +44 -0
- package/web/public/cost.html +25 -0
- package/web/public/fonts/GeistMono-400.woff2 +0 -0
- package/web/public/fonts/GeistMono-600.woff2 +0 -0
- package/web/public/fonts/InstrumentSans-400.woff2 +0 -0
- package/web/public/fonts/InstrumentSans-600.woff2 +0 -0
- package/web/public/index.html +39 -0
- package/web/public/judge.html +21 -0
- package/web/public/learning.html +46 -0
- package/web/public/lib/api-types.ts +616 -0
- package/web/public/lib/common-view.ts +47 -0
- package/web/public/lib/cost-view.ts +35 -0
- package/web/public/lib/files-view.ts +90 -0
- package/web/public/lib/format.ts +35 -0
- package/web/public/lib/html.ts +51 -0
- package/web/public/lib/judge-view.ts +62 -0
- package/web/public/lib/learning-view.ts +102 -0
- package/web/public/lib/optim-view.ts +148 -0
- package/web/public/lib/pager.ts +56 -0
- package/web/public/lib/poller.ts +79 -0
- package/web/public/lib/run-view.ts +61 -0
- package/web/public/lib/runs-view.ts +87 -0
- package/web/public/lib/score-view.ts +94 -0
- package/web/public/lib/sessions-view.ts +28 -0
- package/web/public/lib/span-view.ts +90 -0
- package/web/public/lib/theme.ts +60 -0
- package/web/public/lib/timeline.ts +97 -0
- package/web/public/lib/wikis-view.ts +257 -0
- package/web/public/optim.html +30 -0
- package/web/public/pages/api.ts +60 -0
- package/web/public/pages/cost.ts +36 -0
- package/web/public/pages/judge.ts +15 -0
- package/web/public/pages/learning.ts +92 -0
- package/web/public/pages/optim.ts +68 -0
- package/web/public/pages/paging.ts +18 -0
- package/web/public/pages/run.ts +221 -0
- package/web/public/pages/runs.ts +91 -0
- package/web/public/pages/sessions.ts +25 -0
- package/web/public/pages/wikis.ts +103 -0
- package/web/public/run.html +36 -0
- package/web/public/sessions.html +28 -0
- package/web/public/style.css +288 -0
- package/web/public/wikis.html +25 -0
- package/web/src/api.js +682 -0
- package/web/src/http-errors.js +60 -0
- package/web/src/index.js +5 -0
- package/web/src/server.js +292 -0
- package/web/src/static.js +86 -0
- package/web/src/strip.js +22 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DirListing,
|
|
3
|
+
FeedbackResponse,
|
|
4
|
+
MetaResponse,
|
|
5
|
+
ReadOnlyInfo,
|
|
6
|
+
RunDetailResponse,
|
|
7
|
+
SpanNode,
|
|
8
|
+
SpanResponse,
|
|
9
|
+
SpanTreeResponse,
|
|
10
|
+
} from "../lib/api-types.ts";
|
|
11
|
+
import { renderError } from "../lib/common-view.ts";
|
|
12
|
+
import { filePath, mediaKind, renderFile, renderListing, renderMedia } from "../lib/files-view.ts";
|
|
13
|
+
import { html, type SafeHtml } from "../lib/html.ts";
|
|
14
|
+
import { createPoller } from "../lib/poller.ts";
|
|
15
|
+
import { renderChildren, renderFeedbackForm, renderRunHeader, shouldPoll } from "../lib/run-view.ts";
|
|
16
|
+
import { renderEscalations, renderScores } from "../lib/score-view.ts";
|
|
17
|
+
import { findSpan, renderSpanDetail, renderSpanTree } from "../lib/span-view.ts";
|
|
18
|
+
import { renderTimeline, timelineRows } from "../lib/timeline.ts";
|
|
19
|
+
import { asErrorBody, el, getJson, getText, postJson } from "./api.ts";
|
|
20
|
+
|
|
21
|
+
const runId = new URLSearchParams(location.search).get("id") ?? "";
|
|
22
|
+
const header = el<HTMLElement>("#header");
|
|
23
|
+
const review = el<HTMLElement>("#review");
|
|
24
|
+
const scores = el<HTMLElement>("#scores");
|
|
25
|
+
const escalations = el<HTMLElement>("#escalations");
|
|
26
|
+
const children = el<HTMLElement>("#children");
|
|
27
|
+
const timeline = el<HTMLElement>("#timeline");
|
|
28
|
+
const tree = el<HTMLElement>("#tree");
|
|
29
|
+
const detail = el<HTMLElement>("#span-detail");
|
|
30
|
+
const files = el<HTMLElement>("#files");
|
|
31
|
+
const fileView = el<HTMLElement>("#file-view");
|
|
32
|
+
const errorBox = el<HTMLDivElement>("#error");
|
|
33
|
+
|
|
34
|
+
let roots: SpanNode[] = [];
|
|
35
|
+
let selectedSpanId: string | null = null;
|
|
36
|
+
let filesLoaded = false;
|
|
37
|
+
let readOnly: ReadOnlyInfo | null | undefined;
|
|
38
|
+
|
|
39
|
+
/** What a refresh must not throw away: expanded span-tree nodes, unsent verdict forms and the focused comment box. */
|
|
40
|
+
interface ViewState {
|
|
41
|
+
open: Map<string, boolean>;
|
|
42
|
+
forms: Map<string, { verdict: string; comment: string }>;
|
|
43
|
+
focus: { run: string; start: number; end: number } | null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function summarySpanId(details: HTMLDetailsElement): string | undefined {
|
|
47
|
+
return details.querySelector<HTMLElement>(":scope > summary")?.dataset.spanId;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function captureState(): ViewState {
|
|
51
|
+
const open = new Map<string, boolean>();
|
|
52
|
+
for (const details of tree.querySelectorAll<HTMLDetailsElement>("details")) {
|
|
53
|
+
const id = summarySpanId(details);
|
|
54
|
+
if (id) open.set(id, details.open);
|
|
55
|
+
}
|
|
56
|
+
const forms = new Map<string, { verdict: string; comment: string }>();
|
|
57
|
+
for (const form of document.querySelectorAll<HTMLFormElement>("form[data-feedback-run]")) {
|
|
58
|
+
const data = new FormData(form);
|
|
59
|
+
forms.set(form.dataset.feedbackRun ?? "", { verdict: String(data.get("verdict") ?? ""), comment: String(data.get("comment") ?? "") });
|
|
60
|
+
}
|
|
61
|
+
const active = document.activeElement;
|
|
62
|
+
const focusRun = active instanceof HTMLTextAreaElement ? active.form?.dataset.feedbackRun : undefined;
|
|
63
|
+
const focus = focusRun && active instanceof HTMLTextAreaElement ? { run: focusRun, start: active.selectionStart, end: active.selectionEnd } : null;
|
|
64
|
+
return { open, forms, focus };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function restoreState(state: ViewState): void {
|
|
68
|
+
for (const details of tree.querySelectorAll<HTMLDetailsElement>("details")) {
|
|
69
|
+
const id = summarySpanId(details);
|
|
70
|
+
const wasOpen = id === undefined ? undefined : state.open.get(id);
|
|
71
|
+
if (wasOpen !== undefined) details.open = wasOpen;
|
|
72
|
+
}
|
|
73
|
+
for (const form of document.querySelectorAll<HTMLFormElement>("form[data-feedback-run]")) {
|
|
74
|
+
const run = form.dataset.feedbackRun ?? "";
|
|
75
|
+
const saved = state.forms.get(run);
|
|
76
|
+
const comment = form.querySelector<HTMLTextAreaElement>("textarea[name=comment]");
|
|
77
|
+
if (saved) {
|
|
78
|
+
if (comment) comment.value = saved.comment;
|
|
79
|
+
for (const radio of form.querySelectorAll<HTMLInputElement>("input[name=verdict]")) radio.checked = radio.value === saved.verdict;
|
|
80
|
+
}
|
|
81
|
+
if (comment && state.focus?.run === run && document.activeElement !== comment) {
|
|
82
|
+
comment.focus();
|
|
83
|
+
comment.setSelectionRange(state.focus.start, state.focus.end);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const rendered = new WeakMap<HTMLElement, string>();
|
|
89
|
+
|
|
90
|
+
/** Replaces a region only when its markup changed, so an unchanged form keeps its DOM, focus and typed text. */
|
|
91
|
+
function setHtml(target: HTMLElement, markup: SafeHtml): void {
|
|
92
|
+
if (rendered.get(target) === markup.value) return;
|
|
93
|
+
target.innerHTML = markup.value;
|
|
94
|
+
rendered.set(target, markup.value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function showError(error: unknown, target: HTMLElement = errorBox): void {
|
|
98
|
+
target.innerHTML = renderError(asErrorBody(error)).value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function loadDir(path: string): Promise<void> {
|
|
102
|
+
try {
|
|
103
|
+
files.innerHTML = renderListing(await getJson<DirListing>(filePath(runId, path))).value;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
showError(error, files);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function loadFile(fileRunId: string, path: string, full = false): Promise<void> {
|
|
110
|
+
const kind = mediaKind(path);
|
|
111
|
+
if (kind) {
|
|
112
|
+
fileView.innerHTML = renderMedia(path, kind, filePath(fileRunId, path)).value;
|
|
113
|
+
fileView.dataset.run = fileRunId;
|
|
114
|
+
fileView.scrollIntoView({ block: "nearest" });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
const { text, truncatedSize } = await getText(filePath(fileRunId, path, full));
|
|
119
|
+
fileView.innerHTML = renderFile(path, text, truncatedSize).value;
|
|
120
|
+
fileView.dataset.run = fileRunId;
|
|
121
|
+
fileView.scrollIntoView({ block: "nearest" });
|
|
122
|
+
} catch (error) {
|
|
123
|
+
showError(error, fileView);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Loads and renders the run once; resolves true while the run is still running. */
|
|
128
|
+
async function load(): Promise<boolean> {
|
|
129
|
+
const [run, spans, meta] = await Promise.all([
|
|
130
|
+
getJson<RunDetailResponse>(`/api/runs/${encodeURIComponent(runId)}`),
|
|
131
|
+
getJson<SpanTreeResponse>(`/api/runs/${encodeURIComponent(runId)}/spans`),
|
|
132
|
+
readOnly === undefined ? getJson<MetaResponse>("/api/meta") : Promise.resolve(null),
|
|
133
|
+
]);
|
|
134
|
+
if (meta) readOnly = meta.readOnly;
|
|
135
|
+
const now = Date.now();
|
|
136
|
+
const state = captureState();
|
|
137
|
+
errorBox.innerHTML = "";
|
|
138
|
+
document.title = `nexo · ${run.run.instruction.slice(0, 60)}`;
|
|
139
|
+
setHtml(header, renderRunHeader(run, now));
|
|
140
|
+
setHtml(review, renderFeedbackForm(run.run, run.feedback.at(-1), readOnly ?? null));
|
|
141
|
+
setHtml(scores, renderScores(run.scores, run.run.verdict, run.judgeDisagrees));
|
|
142
|
+
setHtml(escalations, renderEscalations(run.escalations));
|
|
143
|
+
setHtml(children, renderChildren(run.children, now, readOnly ?? null, run.childFeedback));
|
|
144
|
+
roots = spans.roots;
|
|
145
|
+
setHtml(timeline, renderTimeline(timelineRows(roots, now), selectedSpanId));
|
|
146
|
+
setHtml(tree, html`${spans.truncated ? html`<p class="warn">This run has ${spans.total} spans; only the earliest are shown.</p>` : ""}${renderSpanTree(roots, now, 2, selectedSpanId)}`);
|
|
147
|
+
restoreState(state);
|
|
148
|
+
if (!filesLoaded && !run.dirMissing) {
|
|
149
|
+
filesLoaded = true;
|
|
150
|
+
await loadDir("");
|
|
151
|
+
}
|
|
152
|
+
return shouldPoll(run.run.status);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const poller = createPoller({
|
|
156
|
+
task: load,
|
|
157
|
+
onError: (error) => showError(error),
|
|
158
|
+
setTimer: (callback, ms) => window.setTimeout(callback, ms),
|
|
159
|
+
clearTimer: (handle) => window.clearTimeout(handle as number),
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/** Marks one span as selected in the tree and the timeline without re-rendering them (a poll re-renders with the same mark). */
|
|
163
|
+
function selectSpan(id: string): void {
|
|
164
|
+
selectedSpanId = id;
|
|
165
|
+
for (const marked of document.querySelectorAll<HTMLElement>("[data-span-id]")) {
|
|
166
|
+
if (marked.dataset.spanId === id) marked.setAttribute("aria-current", "true");
|
|
167
|
+
else marked.removeAttribute("aria-current");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Dataset values are decoded raw strings: they only reach lookups, encodeURIComponent or filePath, never markup.
|
|
172
|
+
document.addEventListener("click", (event) => {
|
|
173
|
+
const target = (event.target as HTMLElement).closest<HTMLElement>("[data-span-id],[data-full-span],[data-dir],[data-file],[data-file-path],[data-file-full]");
|
|
174
|
+
if (!target) return;
|
|
175
|
+
const d = target.dataset;
|
|
176
|
+
if (d.spanId !== undefined) {
|
|
177
|
+
const node = findSpan(roots, d.spanId);
|
|
178
|
+
if (node) {
|
|
179
|
+
selectSpan(d.spanId);
|
|
180
|
+
detail.innerHTML = renderSpanDetail(node.span, node.attrsTruncated, Date.now()).value;
|
|
181
|
+
detail.scrollIntoView({ block: "nearest" });
|
|
182
|
+
}
|
|
183
|
+
} else if (d.fullSpan !== undefined) {
|
|
184
|
+
getJson<SpanResponse>(`/api/runs/${encodeURIComponent(runId)}/spans/${encodeURIComponent(d.fullSpan)}`)
|
|
185
|
+
.then((res) => (detail.innerHTML = renderSpanDetail(res.span, false, Date.now()).value))
|
|
186
|
+
.catch((error: unknown) => showError(error, detail));
|
|
187
|
+
} else if (d.dir !== undefined) {
|
|
188
|
+
void loadDir(d.dir);
|
|
189
|
+
} else if (d.file !== undefined) {
|
|
190
|
+
void loadFile(runId, d.file);
|
|
191
|
+
} else if (d.filePath !== undefined) {
|
|
192
|
+
void loadFile(d.fileRun ?? runId, d.filePath);
|
|
193
|
+
} else if (d.fileFull !== undefined) {
|
|
194
|
+
void loadFile(fileView.dataset.run ?? runId, d.fileFull, true);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
document.addEventListener("submit", (event) => {
|
|
199
|
+
const form = (event.target as HTMLElement).closest<HTMLFormElement>("form[data-feedback-run]");
|
|
200
|
+
if (!form) return;
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
const data = new FormData(form);
|
|
203
|
+
const status = form.querySelector<HTMLElement>(".form-status");
|
|
204
|
+
postJson<FeedbackResponse>(`/api/runs/${encodeURIComponent(form.dataset.feedbackRun ?? "")}/feedback`, {
|
|
205
|
+
verdict: String(data.get("verdict") ?? ""),
|
|
206
|
+
comment: String(data.get("comment") ?? ""),
|
|
207
|
+
})
|
|
208
|
+
.then(async () => {
|
|
209
|
+
form.reset();
|
|
210
|
+
await poller.refresh();
|
|
211
|
+
// The refresh re-renders the form with its new latest-verdict line, so the status is looked up again.
|
|
212
|
+
const saved = document.querySelector<HTMLElement>(`form[data-feedback-run="${CSS.escape(form.dataset.feedbackRun ?? "")}"] .form-status`);
|
|
213
|
+
if (saved) saved.textContent = "Saved.";
|
|
214
|
+
})
|
|
215
|
+
.catch((error: unknown) => {
|
|
216
|
+
if (status) status.innerHTML = renderError(asErrorBody(error)).value;
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
if (runId) void poller.refresh();
|
|
221
|
+
else showError({ code: "INVALID_REQUEST", message: "No run id in the address", retryable: false });
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { MetaResponse, RunListResponse } from "../lib/api-types.ts";
|
|
2
|
+
import { renderError } from "../lib/common-view.ts";
|
|
3
|
+
import { DEFAULT_PAGE_SIZE, type Page, renderPager } from "../lib/pager.ts";
|
|
4
|
+
import { type RunFilters, readRunFilters, renderEmptyRuns, renderRunRows, renderRunsNote, renderSessionFilter, renderStatusOptions, runsPageSearch, runsQuery } from "../lib/runs-view.ts";
|
|
5
|
+
import { asErrorBody, el, getJson } from "./api.ts";
|
|
6
|
+
import { bindPager } from "./paging.ts";
|
|
7
|
+
|
|
8
|
+
const filters: RunFilters = readRunFilters(location.search);
|
|
9
|
+
const page: Page = { offset: 0, limit: DEFAULT_PAGE_SIZE };
|
|
10
|
+
|
|
11
|
+
const body = el<HTMLTableSectionElement>("#runs-body");
|
|
12
|
+
const pager = el<HTMLDivElement>("#pager");
|
|
13
|
+
const errorBox = el<HTMLDivElement>("#error");
|
|
14
|
+
const form = el<HTMLFormElement>("#filters");
|
|
15
|
+
const statusFilter = el<HTMLSelectElement>("#status-filter");
|
|
16
|
+
const sessionFilter = el<HTMLDivElement>("#session-filter");
|
|
17
|
+
|
|
18
|
+
/** Loads and renders the current page of the current tab and filters. */
|
|
19
|
+
async function load(): Promise<void> {
|
|
20
|
+
errorBox.innerHTML = "";
|
|
21
|
+
try {
|
|
22
|
+
const result = await getJson<RunListResponse>(runsQuery(filters, page));
|
|
23
|
+
body.innerHTML = (result.runs.length === 0 ? renderEmptyRuns(filters.tab) : renderRunRows(result.runs, Date.now())).value;
|
|
24
|
+
sessionFilter.innerHTML = `${renderSessionFilter(filters.session, result.runs[0]?.sessionTitle ?? null).value}${renderRunsNote(filters).value}`;
|
|
25
|
+
pager.innerHTML = renderPager({ ...page, total: result.total ?? result.runs.length }).value;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
errorBox.innerHTML = renderError(asErrorBody(error)).value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function loadStatuses(): Promise<void> {
|
|
32
|
+
try {
|
|
33
|
+
const meta = await getJson<MetaResponse>("/api/meta");
|
|
34
|
+
statusFilter.innerHTML = renderStatusOptions(meta.runStatuses, filters.status).value;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
errorBox.innerHTML = renderError(asErrorBody(error)).value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function showTab(): void {
|
|
41
|
+
for (const t of document.querySelectorAll<HTMLButtonElement>("[data-tab]")) {
|
|
42
|
+
const selected = (t.dataset.tab === "review" ? "review" : "all") === filters.tab;
|
|
43
|
+
t.setAttribute("aria-selected", String(selected));
|
|
44
|
+
t.tabIndex = selected ? 0 : -1;
|
|
45
|
+
}
|
|
46
|
+
const search = runsPageSearch(filters);
|
|
47
|
+
if (location.search !== search) history.replaceState(null, "", `${location.pathname}${search}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const tab of document.querySelectorAll<HTMLButtonElement>("[data-tab]")) {
|
|
51
|
+
tab.addEventListener("click", () => {
|
|
52
|
+
filters.tab = tab.dataset.tab === "review" ? "review" : "all";
|
|
53
|
+
page.offset = 0;
|
|
54
|
+
showTab();
|
|
55
|
+
void load();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Arrow keys move between tabs (roving tabindex), as the tab role promises.
|
|
60
|
+
const tabButtons = [...document.querySelectorAll<HTMLButtonElement>("[data-tab]")];
|
|
61
|
+
for (const tab of tabButtons) {
|
|
62
|
+
tab.addEventListener("keydown", (event) => {
|
|
63
|
+
const step = event.key === "ArrowRight" ? 1 : event.key === "ArrowLeft" ? -1 : 0;
|
|
64
|
+
if (step === 0) return;
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
const next = tabButtons[(tabButtons.indexOf(tab) + step + tabButtons.length) % tabButtons.length];
|
|
67
|
+
next?.focus();
|
|
68
|
+
next?.click();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
form.addEventListener("submit", (event) => {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
const data = new FormData(form);
|
|
75
|
+
filters.status = String(data.get("status") ?? "");
|
|
76
|
+
filters.skill = String(data.get("skill") ?? "");
|
|
77
|
+
filters.since = String(data.get("since") ?? "");
|
|
78
|
+
filters.scored = String(data.get("scored") ?? "");
|
|
79
|
+
page.offset = 0;
|
|
80
|
+
void load();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Selects and the date apply as soon as they change; the skill text field waits for Enter or Apply.
|
|
84
|
+
form.addEventListener("change", (event) => {
|
|
85
|
+
if (event.target instanceof HTMLSelectElement || (event.target instanceof HTMLInputElement && event.target.type === "date")) form.requestSubmit();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
bindPager(pager, page, () => void load());
|
|
89
|
+
showTab();
|
|
90
|
+
void loadStatuses();
|
|
91
|
+
void load();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SessionListResponse } from "../lib/api-types.ts";
|
|
2
|
+
import { renderError } from "../lib/common-view.ts";
|
|
3
|
+
import { DEFAULT_PAGE_SIZE, type Page, renderPager } from "../lib/pager.ts";
|
|
4
|
+
import { renderSessionRows, sessionsQuery } from "../lib/sessions-view.ts";
|
|
5
|
+
import { asErrorBody, el, getJson } from "./api.ts";
|
|
6
|
+
import { bindPager } from "./paging.ts";
|
|
7
|
+
|
|
8
|
+
const body = el<HTMLTableSectionElement>("#sessions-body");
|
|
9
|
+
const pager = el<HTMLDivElement>("#pager");
|
|
10
|
+
const errorBox = el<HTMLDivElement>("#error");
|
|
11
|
+
const page: Page = { offset: 0, limit: DEFAULT_PAGE_SIZE };
|
|
12
|
+
|
|
13
|
+
async function load(): Promise<void> {
|
|
14
|
+
errorBox.innerHTML = "";
|
|
15
|
+
try {
|
|
16
|
+
const result = await getJson<SessionListResponse>(sessionsQuery(page));
|
|
17
|
+
body.innerHTML = renderSessionRows(result.sessions).value;
|
|
18
|
+
pager.innerHTML = renderPager({ ...page, total: result.total ?? result.sessions.length }).value;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
errorBox.innerHTML = renderError(asErrorBody(error)).value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
bindPager(pager, page, () => void load());
|
|
25
|
+
void load();
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { WikiListResponse, WikiPageResponse, WikiPagesResponse } from "../lib/api-types.ts";
|
|
2
|
+
import { renderError } from "../lib/common-view.ts";
|
|
3
|
+
import { renderWikiPage, renderWikiSelector, renderWikiTree } from "../lib/wikis-view.ts";
|
|
4
|
+
import { asErrorBody, el, getJson } from "./api.ts";
|
|
5
|
+
|
|
6
|
+
const errorBox = el<HTMLDivElement>("#error");
|
|
7
|
+
const selectorBox = el<HTMLDivElement>("#wiki-selector-container");
|
|
8
|
+
const treeBox = el<HTMLDivElement>("#wiki-tree-container");
|
|
9
|
+
const pageBox = el<HTMLDivElement>("#wiki-page-container");
|
|
10
|
+
|
|
11
|
+
let currentWikis: string[] = [];
|
|
12
|
+
let activeWiki: string | null = null;
|
|
13
|
+
let activePath: string = "index.md";
|
|
14
|
+
|
|
15
|
+
function showError(error: unknown): void {
|
|
16
|
+
errorBox.innerHTML = renderError(asErrorBody(error)).value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseHash(): { wiki: string | null; pagePath: string } {
|
|
20
|
+
const hash = window.location.hash.replace(/^#\/?/, "");
|
|
21
|
+
if (!hash) return { wiki: null, pagePath: "index.md" };
|
|
22
|
+
const slash = hash.indexOf("/");
|
|
23
|
+
if (slash === -1) {
|
|
24
|
+
return { wiki: decodeURIComponent(hash), pagePath: "index.md" };
|
|
25
|
+
}
|
|
26
|
+
const wiki = decodeURIComponent(hash.slice(0, slash));
|
|
27
|
+
let page = decodeURIComponent(hash.slice(slash + 1));
|
|
28
|
+
if (!page.endsWith(".md")) page += ".md";
|
|
29
|
+
return { wiki, pagePath: page };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function loadPage(wiki: string, path: string): Promise<void> {
|
|
33
|
+
activeWiki = wiki;
|
|
34
|
+
activePath = path;
|
|
35
|
+
errorBox.innerHTML = "";
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const [pagesData, pageData] = await Promise.all([
|
|
39
|
+
getJson<WikiPagesResponse>(`/api/wikis/${encodeURIComponent(wiki)}/pages`),
|
|
40
|
+
getJson<WikiPageResponse>(`/api/wikis/${encodeURIComponent(wiki)}/page?path=${encodeURIComponent(path)}`),
|
|
41
|
+
]);
|
|
42
|
+
treeBox.innerHTML = renderWikiTree(pagesData.pages, wiki, path).value;
|
|
43
|
+
pageBox.innerHTML = renderWikiPage(pageData, wiki).value;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
// If index.md doesn't exist, try loading the first available page
|
|
46
|
+
try {
|
|
47
|
+
const pagesData = await getJson<WikiPagesResponse>(`/api/wikis/${encodeURIComponent(wiki)}/pages`);
|
|
48
|
+
treeBox.innerHTML = renderWikiTree(pagesData.pages, wiki, path).value;
|
|
49
|
+
if (pagesData.pages.length > 0 && pagesData.pages[0]) {
|
|
50
|
+
const firstPage = pagesData.pages[0];
|
|
51
|
+
activePath = firstPage.path;
|
|
52
|
+
const pageData = await getJson<WikiPageResponse>(`/api/wikis/${encodeURIComponent(wiki)}/page?path=${encodeURIComponent(firstPage.path)}`);
|
|
53
|
+
pageBox.innerHTML = renderWikiPage(pageData, wiki).value;
|
|
54
|
+
} else {
|
|
55
|
+
pageBox.innerHTML = '<p class="muted">No pages found in this wiki.</p>';
|
|
56
|
+
}
|
|
57
|
+
} catch (innerError) {
|
|
58
|
+
showError(innerError);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function loadWiki(wiki: string, pagePath = "index.md"): Promise<void> {
|
|
64
|
+
activeWiki = wiki;
|
|
65
|
+
await loadPage(wiki, pagePath);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function loadAll(): Promise<void> {
|
|
69
|
+
errorBox.innerHTML = "";
|
|
70
|
+
const list = await getJson<WikiListResponse>("/api/wikis");
|
|
71
|
+
currentWikis = list.wikis.map((w) => w.name);
|
|
72
|
+
|
|
73
|
+
const parsed = parseHash();
|
|
74
|
+
const targetWiki = (parsed.wiki && currentWikis.includes(parsed.wiki)) ? parsed.wiki : (currentWikis[0] ?? null);
|
|
75
|
+
|
|
76
|
+
selectorBox.innerHTML = renderWikiSelector(list.wikis, targetWiki).value;
|
|
77
|
+
|
|
78
|
+
if (targetWiki) {
|
|
79
|
+
await loadWiki(targetWiki, parsed.pagePath);
|
|
80
|
+
} else {
|
|
81
|
+
treeBox.innerHTML = "";
|
|
82
|
+
pageBox.innerHTML = '<p class="muted">No wikis available.</p>';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
window.addEventListener("hashchange", () => {
|
|
87
|
+
const parsed = parseHash();
|
|
88
|
+
if (parsed.wiki && currentWikis.includes(parsed.wiki)) {
|
|
89
|
+
if (parsed.wiki !== activeWiki || parsed.pagePath !== activePath) {
|
|
90
|
+
loadPage(parsed.wiki, parsed.pagePath).catch(showError);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
selectorBox.addEventListener("change", (event) => {
|
|
96
|
+
const select = event.target as HTMLSelectElement;
|
|
97
|
+
if (select && select.id === "wiki-select") {
|
|
98
|
+
const newWiki = select.value;
|
|
99
|
+
window.location.hash = `#${encodeURIComponent(newWiki)}/index`;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
loadAll().catch(showError);
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
<meta name="nexo-token" content="{{NEXO_TOKEN}}">
|
|
7
|
+
<title>nexo · run</title>
|
|
8
|
+
<link rel="stylesheet" href="/style.css">
|
|
9
|
+
<script type="module" src="/lib/theme.ts"></script>
|
|
10
|
+
<script type="module" src="/pages/run.ts"></script>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<a class="skip" href="#main">Skip to content</a>
|
|
14
|
+
<nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/">Runs</a><a href="/sessions.html">Sessions</a><a href="/cost.html">Cost</a><a href="/learning.html">Learning</a><a href="/judge.html">Judge</a><a href="/optim.html">Optimization</a><a href="/wikis.html">Wikis</a></nav>
|
|
15
|
+
<main id="main" tabindex="-1">
|
|
16
|
+
<nav class="run-nav" aria-label="Run sections"><a href="#sec-timeline">Timeline</a><a href="#sec-spans">Spans</a><a href="#sec-scores">Scores</a><a href="#sec-subagents">Subagents</a><a href="#sec-files">Files</a><a href="#sec-review">Review</a></nav>
|
|
17
|
+
<div id="error"></div>
|
|
18
|
+
<div id="header"></div>
|
|
19
|
+
<section id="sec-timeline"><h2>Timeline</h2><div id="timeline"></div></section>
|
|
20
|
+
<section class="split" id="sec-spans">
|
|
21
|
+
<div><h2>Spans</h2><div id="tree"></div></div>
|
|
22
|
+
<div><h2>Span detail</h2><div id="span-detail"><p class="muted">Select a span.</p></div></div>
|
|
23
|
+
</section>
|
|
24
|
+
<section class="split" id="sec-scores">
|
|
25
|
+
<div><h2>Scores</h2><div id="scores"></div></div>
|
|
26
|
+
<div><h2>Escalations</h2><div id="escalations"></div></div>
|
|
27
|
+
</section>
|
|
28
|
+
<section id="sec-subagents"><h2>Subagents</h2><div id="children"></div></section>
|
|
29
|
+
<section class="split" id="sec-files">
|
|
30
|
+
<div><h2>Files</h2><div id="files"></div></div>
|
|
31
|
+
<div><h2>File</h2><div id="file-view"><p class="muted">Select a file.</p></div></div>
|
|
32
|
+
</section>
|
|
33
|
+
<section id="sec-review"><h2>Review</h2><div id="review"></div></section>
|
|
34
|
+
</main>
|
|
35
|
+
</body>
|
|
36
|
+
</html>
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
<meta name="nexo-token" content="{{NEXO_TOKEN}}">
|
|
7
|
+
<title>nexo · sessions</title>
|
|
8
|
+
<link rel="stylesheet" href="/style.css">
|
|
9
|
+
<script type="module" src="/lib/theme.ts"></script>
|
|
10
|
+
<script type="module" src="/pages/sessions.ts"></script>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<a class="skip" href="#main">Skip to content</a>
|
|
14
|
+
<nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/">Runs</a><a href="/sessions.html">Sessions</a><a href="/cost.html">Cost</a><a href="/learning.html">Learning</a><a href="/judge.html">Judge</a><a href="/optim.html">Optimization</a><a href="/wikis.html">Wikis</a></nav>
|
|
15
|
+
<main id="main" tabindex="-1">
|
|
16
|
+
<h1>Sessions</h1>
|
|
17
|
+
<p class="muted">Each chat message is a turn. Open a session to see its turns and review them.</p>
|
|
18
|
+
<div id="error"></div>
|
|
19
|
+
<div class="table-wrap">
|
|
20
|
+
<table class="runs">
|
|
21
|
+
<thead><tr><th>Title</th><th>Status</th><th class="num">Turns</th><th class="num">Cost</th><th class="num">Unreviewed</th><th>Last turn</th><th>Updated (UTC)</th></tr></thead>
|
|
22
|
+
<tbody id="sessions-body"></tbody>
|
|
23
|
+
</table>
|
|
24
|
+
</div>
|
|
25
|
+
<div id="pager"></div>
|
|
26
|
+
</main>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|