@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,257 @@
|
|
|
1
|
+
import type { WikiItem, WikiPageItem, WikiPageResponse } from "./api-types.ts";
|
|
2
|
+
import { formatTime } from "./format.ts";
|
|
3
|
+
import { esc, html, SafeHtml } from "./html.ts";
|
|
4
|
+
|
|
5
|
+
function formatSize(bytes: number): string {
|
|
6
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
7
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
8
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Renders inline markdown: bold, italic, code, links, and wikilinks. Input must already have special characters escaped or handled. */
|
|
12
|
+
function renderInline(text: string, activeWiki: string): string {
|
|
13
|
+
const codeTokens: string[] = [];
|
|
14
|
+
let s = text.replace(/`([^`]+)`/g, (_m, code: string) => {
|
|
15
|
+
const idx = codeTokens.length;
|
|
16
|
+
codeTokens.push(`<code>${esc(code)}</code>`);
|
|
17
|
+
return `\x00CODE_${idx}\x00`;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
s = esc(s);
|
|
21
|
+
|
|
22
|
+
// Wikilinks: [[target|label]] or [[target]]
|
|
23
|
+
s = s.replace(/\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g, (_match, rawTarget: string, rawLabel?: string) => {
|
|
24
|
+
const target = rawTarget.trim().replace(/\.md$/, "");
|
|
25
|
+
const label = (rawLabel ?? rawTarget).trim();
|
|
26
|
+
const href = `#${encodeURIComponent(activeWiki)}/${target.split("/").map(encodeURIComponent).join("/")}`;
|
|
27
|
+
return `<a href="${href}" class="wikilink" data-wiki-nav="${esc(target)}">${esc(label)}</a>`;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Standard links: [text](url) - only allow http, https, or in-page hash links
|
|
31
|
+
s = s.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, label: string, url: string) => {
|
|
32
|
+
const cleanUrl = url.trim();
|
|
33
|
+
if (/^(https?:|\/|#)/i.test(cleanUrl)) {
|
|
34
|
+
return `<a href="${esc(cleanUrl)}" target="_blank" rel="noopener noreferrer">${esc(label)}</a>`;
|
|
35
|
+
}
|
|
36
|
+
return esc(label);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Bold: **text**
|
|
40
|
+
s = s.replace(/\*\*([^*]+)\*\*/g, (_match, content: string) => `<strong>${content}</strong>`);
|
|
41
|
+
|
|
42
|
+
// Italic: *text*
|
|
43
|
+
s = s.replace(/(^|[^\*])\*([^*]+)\*/g, (_match, prefix: string, content: string) => `${prefix}<em>${content}</em>`);
|
|
44
|
+
|
|
45
|
+
// Restore code tokens
|
|
46
|
+
s = s.replace(/\x00CODE_(\d+)\x00/g, (_m, idxStr: string) => {
|
|
47
|
+
const idx = Number(idxStr);
|
|
48
|
+
return codeTokens[idx] ?? "";
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return s;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Parses markdown text and returns sanitized SafeHtml, supporting frontmatter summaries and [[wikilinks]]. */
|
|
55
|
+
export function renderMarkdown(content: string, activeWiki: string): SafeHtml {
|
|
56
|
+
let body = content;
|
|
57
|
+
|
|
58
|
+
// Strip frontmatter if present
|
|
59
|
+
if (body.startsWith("---")) {
|
|
60
|
+
const end = body.indexOf("\n---", 3);
|
|
61
|
+
if (end !== -1) {
|
|
62
|
+
body = body.slice(end + 4).trimStart();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const lines = body.split("\n");
|
|
67
|
+
const out: string[] = [];
|
|
68
|
+
let inCodeBlock = false;
|
|
69
|
+
let codeLang = "";
|
|
70
|
+
let codeLines: string[] = [];
|
|
71
|
+
let inList: "ul" | "ol" | null = null;
|
|
72
|
+
let inBlockquote = false;
|
|
73
|
+
let quoteLines: string[] = [];
|
|
74
|
+
|
|
75
|
+
const flushList = () => {
|
|
76
|
+
if (inList) {
|
|
77
|
+
out.push(`</${inList}>`);
|
|
78
|
+
inList = null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const flushQuote = () => {
|
|
83
|
+
if (inBlockquote) {
|
|
84
|
+
out.push(`<blockquote><p>${quoteLines.map((l) => renderInline(l, activeWiki)).join("<br>")}</p></blockquote>`);
|
|
85
|
+
inBlockquote = false;
|
|
86
|
+
quoteLines = [];
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
for (let i = 0; i < lines.length; i++) {
|
|
91
|
+
const line = lines[i] ?? "";
|
|
92
|
+
|
|
93
|
+
// Code block delimiter
|
|
94
|
+
if (line.startsWith("```")) {
|
|
95
|
+
if (inCodeBlock) {
|
|
96
|
+
out.push(`<pre class="code-block"><code>${esc(codeLines.join("\n"))}</code></pre>`);
|
|
97
|
+
inCodeBlock = false;
|
|
98
|
+
codeLines = [];
|
|
99
|
+
} else {
|
|
100
|
+
flushList();
|
|
101
|
+
flushQuote();
|
|
102
|
+
inCodeBlock = true;
|
|
103
|
+
codeLang = line.slice(3).trim();
|
|
104
|
+
codeLines = [];
|
|
105
|
+
}
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (inCodeBlock) {
|
|
110
|
+
codeLines.push(line);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Empty line
|
|
115
|
+
if (!line.trim()) {
|
|
116
|
+
flushList();
|
|
117
|
+
flushQuote();
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Headings (# Heading)
|
|
122
|
+
const headingMatch = /^(#{1,6})\s+(.+)$/.exec(line);
|
|
123
|
+
if (headingMatch) {
|
|
124
|
+
flushList();
|
|
125
|
+
flushQuote();
|
|
126
|
+
const level = (headingMatch[1] ?? "#").length;
|
|
127
|
+
const text = headingMatch[2] ?? "";
|
|
128
|
+
out.push(`<h${level}>${renderInline(text, activeWiki)}</h${level}>`);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Blockquotes (> Quote)
|
|
133
|
+
if (line.startsWith(">")) {
|
|
134
|
+
flushList();
|
|
135
|
+
inBlockquote = true;
|
|
136
|
+
quoteLines.push(line.replace(/^>\s?/, ""));
|
|
137
|
+
continue;
|
|
138
|
+
} else if (inBlockquote) {
|
|
139
|
+
flushQuote();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Unordered list (- Item or * Item)
|
|
143
|
+
const ulMatch = /^[-*]\s+(.+)$/.exec(line);
|
|
144
|
+
if (ulMatch) {
|
|
145
|
+
flushQuote();
|
|
146
|
+
if (inList !== "ul") {
|
|
147
|
+
flushList();
|
|
148
|
+
out.push("<ul>");
|
|
149
|
+
inList = "ul";
|
|
150
|
+
}
|
|
151
|
+
out.push(`<li>${renderInline(ulMatch[1] ?? "", activeWiki)}</li>`);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Ordered list (1. Item)
|
|
156
|
+
const olMatch = /^\d+\.\s+(.+)$/.exec(line);
|
|
157
|
+
if (olMatch) {
|
|
158
|
+
flushQuote();
|
|
159
|
+
if (inList !== "ol") {
|
|
160
|
+
flushList();
|
|
161
|
+
out.push("<ol>");
|
|
162
|
+
inList = "ol";
|
|
163
|
+
}
|
|
164
|
+
out.push(`<li>${renderInline(olMatch[1] ?? "", activeWiki)}</li>`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Regular paragraph
|
|
169
|
+
flushList();
|
|
170
|
+
flushQuote();
|
|
171
|
+
out.push(`<p>${renderInline(line, activeWiki)}</p>`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (inCodeBlock) {
|
|
175
|
+
out.push(`<pre class="code-block"><code>${esc(codeLines.join("\n"))}</code></pre>`);
|
|
176
|
+
}
|
|
177
|
+
flushList();
|
|
178
|
+
flushQuote();
|
|
179
|
+
|
|
180
|
+
return new SafeHtml(out.join("\n"));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Renders the wiki selector dropdown and summary facts. */
|
|
184
|
+
export function renderWikiSelector(wikis: readonly WikiItem[], activeWiki: string | null): SafeHtml {
|
|
185
|
+
if (wikis.length === 0) {
|
|
186
|
+
return html`<p class="muted">No wikis created yet. Ask nexo to create one with the <code>wiki</code> skill.</p>`;
|
|
187
|
+
}
|
|
188
|
+
return html`<div class="wiki-selector">
|
|
189
|
+
<label>Wiki <select id="wiki-select">
|
|
190
|
+
${wikis.map((w) => html`<option value="${w.name}" ${w.name === activeWiki ? "selected" : ""}>${w.name} (${w.pageCount} pages)</option>`)}
|
|
191
|
+
</select></label>
|
|
192
|
+
</div>`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Groups wiki pages by directory/folder and renders a navigable tree sidebar. */
|
|
196
|
+
export function renderWikiTree(pages: readonly WikiPageItem[], activeWiki: string, activePath: string): SafeHtml {
|
|
197
|
+
if (pages.length === 0) {
|
|
198
|
+
return html`<p class="muted">Wiki is empty.</p>`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Group into root files and folder files
|
|
202
|
+
const rootPages: WikiPageItem[] = [];
|
|
203
|
+
const folders = new Map<string, WikiPageItem[]>();
|
|
204
|
+
|
|
205
|
+
for (const p of pages) {
|
|
206
|
+
if (p.folder) {
|
|
207
|
+
const list = folders.get(p.folder) ?? [];
|
|
208
|
+
list.push(p);
|
|
209
|
+
folders.set(p.folder, list);
|
|
210
|
+
} else {
|
|
211
|
+
rootPages.push(p);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return html`<nav class="wiki-tree">
|
|
216
|
+
<div class="wiki-tree-section">
|
|
217
|
+
<div class="wiki-tree-title">Pages</div>
|
|
218
|
+
<ul class="wiki-tree-list">
|
|
219
|
+
${rootPages.map((p) => html`<li class="wiki-tree-item ${p.path === activePath ? "active" : ""}">
|
|
220
|
+
<a href="#${encodeURIComponent(activeWiki)}/${encodeURIComponent(p.slug)}" data-page-path="${p.path}">${p.slug}</a>
|
|
221
|
+
${p.summary ? html`<span class="wiki-item-summary muted">${p.summary}</span>` : ""}
|
|
222
|
+
</li>`)}
|
|
223
|
+
</ul>
|
|
224
|
+
</div>
|
|
225
|
+
${[...folders.entries()].map(([folder, folderPages]) => html`<div class="wiki-tree-section">
|
|
226
|
+
<div class="wiki-tree-folder">${folder}/</div>
|
|
227
|
+
<ul class="wiki-tree-list">
|
|
228
|
+
${folderPages.map((p) => {
|
|
229
|
+
const itemSlug = p.slug.startsWith(folder + "/") ? p.slug.slice(folder.length + 1) : p.slug;
|
|
230
|
+
return html`<li class="wiki-tree-item ${p.path === activePath ? "active" : ""}">
|
|
231
|
+
<a href="#${encodeURIComponent(activeWiki)}/${encodeURIComponent(p.slug)}" data-page-path="${p.path}">${itemSlug}</a>
|
|
232
|
+
${p.summary ? html`<span class="wiki-item-summary muted">${p.summary}</span>` : ""}
|
|
233
|
+
</li>`;
|
|
234
|
+
})}
|
|
235
|
+
</ul>
|
|
236
|
+
</div>`)}
|
|
237
|
+
</nav>`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Renders a full wiki page view with breadcrumbs, summary box, rendered content and metadata. */
|
|
241
|
+
export function renderWikiPage(page: WikiPageResponse, activeWiki: string): SafeHtml {
|
|
242
|
+
const renderedContent = renderMarkdown(page.content, activeWiki);
|
|
243
|
+
return html`<article class="wiki-page">
|
|
244
|
+
<header class="wiki-page-header">
|
|
245
|
+
<div class="wiki-crumbs mono">
|
|
246
|
+
<a href="#${encodeURIComponent(activeWiki)}/index">${activeWiki}</a> / <span>${page.path}</span>
|
|
247
|
+
</div>
|
|
248
|
+
<div class="wiki-meta muted mono">
|
|
249
|
+
${formatSize(page.size)} · updated ${formatTime(page.modifiedAt)}
|
|
250
|
+
</div>
|
|
251
|
+
</header>
|
|
252
|
+
${page.summary ? html`<div class="wiki-summary-box"><div class="wiki-summary-label">summary</div><p>${page.summary}</p></div>` : ""}
|
|
253
|
+
<div class="wiki-prose">
|
|
254
|
+
${renderedContent}
|
|
255
|
+
</div>
|
|
256
|
+
</article>`;
|
|
257
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 · optimization</title>
|
|
8
|
+
<link rel="stylesheet" href="/style.css">
|
|
9
|
+
<script type="module" src="/lib/theme.ts"></script>
|
|
10
|
+
<script type="module" src="/pages/optim.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>Optimization</h1>
|
|
17
|
+
<div id="error"></div>
|
|
18
|
+
<section>
|
|
19
|
+
<h2>Proposed eval cases</h2>
|
|
20
|
+
<div id="eval-proposed"></div>
|
|
21
|
+
</section>
|
|
22
|
+
<section>
|
|
23
|
+
<h2>Runs</h2>
|
|
24
|
+
<div id="optim-runs"></div>
|
|
25
|
+
<div id="pager"></div>
|
|
26
|
+
</section>
|
|
27
|
+
<section id="optim-detail"></section>
|
|
28
|
+
</main>
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Fetch helpers for the pages. The token comes from the <meta name="nexo-token"> tag the server fills in.
|
|
2
|
+
import type { ApiErrorBody } from "../lib/api-types.ts";
|
|
3
|
+
|
|
4
|
+
export class ApiError extends Error {
|
|
5
|
+
readonly body: ApiErrorBody;
|
|
6
|
+
|
|
7
|
+
constructor(body: ApiErrorBody) {
|
|
8
|
+
super(body.message);
|
|
9
|
+
this.body = body;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function token(): string {
|
|
14
|
+
return document.querySelector<HTMLMetaElement>('meta[name="nexo-token"]')?.content ?? "";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function failure(res: Response): Promise<ApiError> {
|
|
18
|
+
try {
|
|
19
|
+
const body = (await res.json()) as { error?: ApiErrorBody };
|
|
20
|
+
if (body.error) return new ApiError(body.error);
|
|
21
|
+
} catch {
|
|
22
|
+
// Falls through to the generic error below.
|
|
23
|
+
}
|
|
24
|
+
return new ApiError({ code: "INTERNAL", message: `HTTP ${res.status}`, retryable: res.status >= 500 });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function getJson<T>(path: string): Promise<T> {
|
|
28
|
+
const res = await fetch(path, { headers: { accept: "application/json" } });
|
|
29
|
+
if (!res.ok) throw await failure(res);
|
|
30
|
+
return (await res.json()) as T;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function getText(path: string): Promise<{ text: string; truncatedSize: number | null }> {
|
|
34
|
+
const res = await fetch(path);
|
|
35
|
+
if (!res.ok) throw await failure(res);
|
|
36
|
+
const truncated = res.headers.get("x-nexo-truncated");
|
|
37
|
+
return { text: await res.text(), truncatedSize: truncated === null ? null : Number(truncated) };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function postJson<T>(path: string, body: unknown): Promise<T> {
|
|
41
|
+
const res = await fetch(path, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "content-type": "application/json", "x-nexo-token": token() },
|
|
44
|
+
body: JSON.stringify(body),
|
|
45
|
+
});
|
|
46
|
+
if (!res.ok) throw await failure(res);
|
|
47
|
+
return (await res.json()) as T;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function asErrorBody(error: unknown): ApiErrorBody {
|
|
51
|
+
if (error instanceof ApiError) return error.body;
|
|
52
|
+
return { code: "INTERNAL", message: error instanceof Error ? error.message : String(error), retryable: false };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Looks up an element the page's HTML is required to contain. */
|
|
56
|
+
export function el<T extends HTMLElement>(selector: string): T {
|
|
57
|
+
const found = document.querySelector<T>(selector);
|
|
58
|
+
if (!found) throw new Error(`Missing element ${selector}`);
|
|
59
|
+
return found;
|
|
60
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CostResponse, MetaResponse } from "../lib/api-types.ts";
|
|
2
|
+
import { renderError } from "../lib/common-view.ts";
|
|
3
|
+
import { costQuery, renderCostTable, renderDimensionOptions } from "../lib/cost-view.ts";
|
|
4
|
+
import { asErrorBody, el, getJson } from "./api.ts";
|
|
5
|
+
|
|
6
|
+
const form = el<HTMLFormElement>("#cost-form");
|
|
7
|
+
const by = el<HTMLSelectElement>("#cost-by");
|
|
8
|
+
const out = el<HTMLElement>("#cost-table");
|
|
9
|
+
|
|
10
|
+
async function load(): Promise<void> {
|
|
11
|
+
const data = new FormData(form);
|
|
12
|
+
try {
|
|
13
|
+
const report = await getJson<CostResponse>(costQuery(String(data.get("by") ?? ""), String(data.get("since") ?? "")));
|
|
14
|
+
out.innerHTML = renderCostTable(report).value;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
out.innerHTML = renderError(asErrorBody(error)).value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function init(): Promise<void> {
|
|
21
|
+
try {
|
|
22
|
+
const meta = await getJson<MetaResponse>("/api/meta");
|
|
23
|
+
by.innerHTML = renderDimensionOptions(meta.costDimensions, "day").value;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
out.innerHTML = renderError(asErrorBody(error)).value;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
await load();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
form.addEventListener("submit", (event) => {
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
void load();
|
|
34
|
+
});
|
|
35
|
+
form.addEventListener("change", () => void load());
|
|
36
|
+
void init();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { JudgeCalibrationResponse } from "../lib/api-types.ts";
|
|
2
|
+
import { renderError } from "../lib/common-view.ts";
|
|
3
|
+
import { renderCalibration } from "../lib/judge-view.ts";
|
|
4
|
+
import { asErrorBody, el, getJson } from "./api.ts";
|
|
5
|
+
|
|
6
|
+
const target = el<HTMLElement>("#calibration");
|
|
7
|
+
const errorBox = el<HTMLDivElement>("#error");
|
|
8
|
+
|
|
9
|
+
getJson<JudgeCalibrationResponse>("/api/judge/calibration")
|
|
10
|
+
.then((data) => {
|
|
11
|
+
target.innerHTML = renderCalibration(data).value;
|
|
12
|
+
})
|
|
13
|
+
.catch((error: unknown) => {
|
|
14
|
+
errorBox.innerHTML = renderError(asErrorBody(error)).value;
|
|
15
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { LearnJobsResponse, MemoryDetailResponse, MemoryListResponse, MetaResponse, PlaybookListResponse, PlaybookResponse } from "../lib/api-types.ts";
|
|
2
|
+
import { renderError } from "../lib/common-view.ts";
|
|
3
|
+
import { jobsQuery, memoriesQuery, renderJobs, renderMemories, renderMemoryHistory, renderPlaybook, renderPlaybookList } from "../lib/learning-view.ts";
|
|
4
|
+
import { DEFAULT_PAGE_SIZE, type Page, renderPager } from "../lib/pager.ts";
|
|
5
|
+
import { asErrorBody, el, getJson, postJson } from "./api.ts";
|
|
6
|
+
import { bindPager } from "./paging.ts";
|
|
7
|
+
|
|
8
|
+
const errorBox = el<HTMLDivElement>("#error");
|
|
9
|
+
const filters = el<HTMLFormElement>("#memory-filters");
|
|
10
|
+
const memoriesBox = el<HTMLDivElement>("#memories");
|
|
11
|
+
const memoriesPager = el<HTMLDivElement>("#memories-pager");
|
|
12
|
+
const historyBox = el<HTMLDivElement>("#memory-history");
|
|
13
|
+
const playbooksBox = el<HTMLDivElement>("#playbooks");
|
|
14
|
+
const playbookBox = el<HTMLDivElement>("#playbook");
|
|
15
|
+
const jobsBox = el<HTMLDivElement>("#jobs");
|
|
16
|
+
const jobsPager = el<HTMLDivElement>("#jobs-pager");
|
|
17
|
+
|
|
18
|
+
let readOnly = false;
|
|
19
|
+
let openSkill: string | null = null;
|
|
20
|
+
const memoriesPage: Page = { offset: 0, limit: DEFAULT_PAGE_SIZE };
|
|
21
|
+
const jobsPage: Page = { offset: 0, limit: DEFAULT_PAGE_SIZE };
|
|
22
|
+
|
|
23
|
+
function showError(error: unknown): void {
|
|
24
|
+
errorBox.innerHTML = renderError(asErrorBody(error)).value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Loads the current page of memories for the current filters. */
|
|
28
|
+
async function loadMemories(): Promise<void> {
|
|
29
|
+
const form = new FormData(filters);
|
|
30
|
+
const data = await getJson<MemoryListResponse>(memoriesQuery(String(form.get("scope") ?? ""), String(form.get("type") ?? ""), form.get("all") === "on", memoriesPage));
|
|
31
|
+
memoriesBox.innerHTML = renderMemories(data.memories, readOnly).value;
|
|
32
|
+
memoriesPager.innerHTML = renderPager({ ...memoriesPage, total: data.total ?? data.memories.length }).value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function loadPlaybooks(): Promise<void> {
|
|
36
|
+
playbooksBox.innerHTML = renderPlaybookList(await getJson<PlaybookListResponse>("/api/playbooks")).value;
|
|
37
|
+
if (openSkill) await loadPlaybook(openSkill);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function loadPlaybook(skill: string): Promise<void> {
|
|
41
|
+
openSkill = skill;
|
|
42
|
+
const data = await getJson<PlaybookResponse>(`/api/playbooks/${encodeURIComponent(skill)}?all=1`);
|
|
43
|
+
playbookBox.innerHTML = renderPlaybook(data, readOnly).value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function loadJobs(): Promise<void> {
|
|
47
|
+
const data = await getJson<LearnJobsResponse>(jobsQuery(jobsPage));
|
|
48
|
+
jobsBox.innerHTML = renderJobs(data).value;
|
|
49
|
+
jobsPager.innerHTML = renderPager({ ...jobsPage, total: data.total ?? data.jobs.length }).value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function loadAll(): Promise<void> {
|
|
53
|
+
errorBox.innerHTML = "";
|
|
54
|
+
readOnly = (await getJson<MetaResponse>("/api/meta")).readOnly !== null;
|
|
55
|
+
await Promise.all([loadMemories(), loadPlaybooks(), loadJobs()]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
filters.addEventListener("submit", (event) => {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
memoriesPage.offset = 0;
|
|
61
|
+
loadMemories().catch(showError);
|
|
62
|
+
});
|
|
63
|
+
bindPager(memoriesPager, memoriesPage, () => loadMemories().catch(showError));
|
|
64
|
+
bindPager(jobsPager, jobsPage, () => loadJobs().catch(showError));
|
|
65
|
+
|
|
66
|
+
document.addEventListener("click", (event) => {
|
|
67
|
+
const target = event.target instanceof HTMLElement ? event.target.closest<HTMLElement>("button") : null;
|
|
68
|
+
if (!target) return;
|
|
69
|
+
const { retireMemory, memoryHistory, playbook, retireItem, skill } = target.dataset;
|
|
70
|
+
if (retireMemory) {
|
|
71
|
+
if (!window.confirm("Retire this memory? Runs stop seeing it; it stays in the history.")) return;
|
|
72
|
+
postJson(`/api/memories/${encodeURIComponent(retireMemory)}/retire`, {})
|
|
73
|
+
.then(() => loadMemories())
|
|
74
|
+
.catch(showError);
|
|
75
|
+
} else if (memoryHistory) {
|
|
76
|
+
getJson<MemoryDetailResponse>(`/api/memories/${encodeURIComponent(memoryHistory)}`)
|
|
77
|
+
.then((data) => {
|
|
78
|
+
historyBox.innerHTML = renderMemoryHistory(data.memory, data.history).value;
|
|
79
|
+
historyBox.scrollIntoView({ block: "nearest" });
|
|
80
|
+
})
|
|
81
|
+
.catch(showError);
|
|
82
|
+
} else if (playbook) {
|
|
83
|
+
loadPlaybook(playbook).catch(showError);
|
|
84
|
+
} else if (retireItem && skill) {
|
|
85
|
+
if (!window.confirm(`Retire ${skill}/${retireItem}? The next playbook version leaves it out.`)) return;
|
|
86
|
+
postJson(`/api/playbooks/${encodeURIComponent(skill)}/items/${encodeURIComponent(retireItem)}/retire`, {})
|
|
87
|
+
.then(() => loadPlaybooks())
|
|
88
|
+
.catch(showError);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
loadAll().catch(showError);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { EvalCasesResponse, MetaResponse, OptimDetailResponse, OptimListResponse } from "../lib/api-types.ts";
|
|
2
|
+
import { renderError } from "../lib/common-view.ts";
|
|
3
|
+
import { optimQuery, renderOptimDetail, renderOptimList, renderProposedCases } from "../lib/optim-view.ts";
|
|
4
|
+
import { DEFAULT_PAGE_SIZE, type Page, renderPager } from "../lib/pager.ts";
|
|
5
|
+
import { asErrorBody, el, getJson, postJson } from "./api.ts";
|
|
6
|
+
import { bindPager } from "./paging.ts";
|
|
7
|
+
|
|
8
|
+
const errorBox = el<HTMLDivElement>("#error");
|
|
9
|
+
const listBox = el<HTMLDivElement>("#optim-runs");
|
|
10
|
+
const listPager = el<HTMLDivElement>("#pager");
|
|
11
|
+
const proposedBox = el<HTMLDivElement>("#eval-proposed");
|
|
12
|
+
const detailBox = el<HTMLDivElement>("#optim-detail");
|
|
13
|
+
|
|
14
|
+
let readOnly = false;
|
|
15
|
+
const page: Page = { offset: 0, limit: DEFAULT_PAGE_SIZE };
|
|
16
|
+
|
|
17
|
+
function showError(error: unknown): void {
|
|
18
|
+
errorBox.innerHTML = renderError(asErrorBody(error)).value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Loads and renders the current page of optimizations. */
|
|
22
|
+
async function loadList(): Promise<void> {
|
|
23
|
+
const result = await getJson<OptimListResponse>(optimQuery(page));
|
|
24
|
+
listBox.innerHTML = renderOptimList(result.runs).value;
|
|
25
|
+
listPager.innerHTML = renderPager({ ...page, total: result.total ?? result.runs.length }).value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function loadProposed(): Promise<void> {
|
|
29
|
+
proposedBox.innerHTML = renderProposedCases((await getJson<EvalCasesResponse>("/api/eval-cases?status=proposed")).cases, readOnly).value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function loadDetail(id: string): Promise<void> {
|
|
33
|
+
const data = await getJson<OptimDetailResponse>(`/api/optim/${encodeURIComponent(id)}`);
|
|
34
|
+
detailBox.innerHTML = renderOptimDetail(data, readOnly).value;
|
|
35
|
+
if (location.hash !== `#${id}`) history.replaceState(null, "", `#${id}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function loadAll(): Promise<void> {
|
|
39
|
+
errorBox.innerHTML = "";
|
|
40
|
+
readOnly = (await getJson<MetaResponse>("/api/meta")).readOnly !== null;
|
|
41
|
+
await loadProposed();
|
|
42
|
+
await loadList();
|
|
43
|
+
const id = location.hash.slice(1);
|
|
44
|
+
if (/^[0-9A-Za-z]{1,64}$/.test(id)) await loadDetail(id);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
document.addEventListener("click", (event) => {
|
|
48
|
+
const target = event.target instanceof HTMLElement ? event.target.closest<HTMLElement>("button") : null;
|
|
49
|
+
if (!target) return;
|
|
50
|
+
const { optim, approve, accept, dismiss } = target.dataset;
|
|
51
|
+
if (optim) {
|
|
52
|
+
errorBox.innerHTML = "";
|
|
53
|
+
loadDetail(optim).catch(showError);
|
|
54
|
+
} else if (approve) {
|
|
55
|
+
if (!window.confirm("Approve this candidate? It becomes the active version; the current one is retired (rollback: nexo optimize rollback).")) return;
|
|
56
|
+
postJson(`/api/optim/${encodeURIComponent(approve)}/approve`, {})
|
|
57
|
+
.then(() => Promise.all([loadList(), loadDetail(approve)]))
|
|
58
|
+
.catch(showError);
|
|
59
|
+
} else if (accept || dismiss) {
|
|
60
|
+
const id = (accept ?? dismiss) as string;
|
|
61
|
+
postJson(`/api/eval-cases/${encodeURIComponent(id)}/${accept ? "accept" : "dismiss"}`, {})
|
|
62
|
+
.then(loadProposed)
|
|
63
|
+
.catch(showError);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
bindPager(listPager, page, () => loadList().catch(showError));
|
|
68
|
+
loadAll().catch(showError);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Page } from "../lib/pager.ts";
|
|
2
|
+
|
|
3
|
+
/** Wires a pager container: page buttons set the offset, the rows-per-page select goes back to the first page; `reload` re-renders. */
|
|
4
|
+
export function bindPager(container: HTMLElement, page: Page, reload: () => void): void {
|
|
5
|
+
container.addEventListener("click", (event) => {
|
|
6
|
+
const button = (event.target as HTMLElement).closest<HTMLButtonElement>("button[data-page-offset]");
|
|
7
|
+
if (!button || button.disabled) return;
|
|
8
|
+
page.offset = Number(button.dataset.pageOffset);
|
|
9
|
+
reload();
|
|
10
|
+
});
|
|
11
|
+
container.addEventListener("change", (event) => {
|
|
12
|
+
const select = (event.target as HTMLElement).closest<HTMLSelectElement>("select[data-page-size]");
|
|
13
|
+
if (!select) return;
|
|
14
|
+
page.limit = Number(select.value);
|
|
15
|
+
page.offset = 0;
|
|
16
|
+
reload();
|
|
17
|
+
});
|
|
18
|
+
}
|