@hexdecimal16/nexo 0.4.6 → 0.4.8

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.
Files changed (57) hide show
  1. package/cli/src/areas.js +49 -0
  2. package/cli/src/common.js +2 -1
  3. package/cli/src/history.js +32 -0
  4. package/cli/src/interactive.js +6 -1
  5. package/cli/src/main.js +7 -0
  6. package/cli/src/optimize.js +2 -5
  7. package/core/src/config/schema.js +1 -0
  8. package/core/src/engine/charged-completion.js +9 -4
  9. package/core/src/engine/errors.js +29 -2
  10. package/core/src/engine/messages.js +3 -3
  11. package/core/src/engine/prompts.js +1 -1
  12. package/core/src/engine/run.js +9 -4
  13. package/core/src/index.js +3 -0
  14. package/core/src/learn/areas.js +179 -0
  15. package/core/src/learn/job.js +13 -0
  16. package/core/src/learn/wiki.js +15 -10
  17. package/core/src/optimize/climb.js +0 -2
  18. package/core/src/optimize/optimize.js +1 -4
  19. package/core/src/session/mentions.js +95 -0
  20. package/core/src/session/prompt-history.js +13 -0
  21. package/core/src/session/session.js +2 -1
  22. package/optimize/src/engine.js +1 -22
  23. package/optimize/src/index.js +0 -1
  24. package/optimize/src/report.js +0 -2
  25. package/package.json +1 -1
  26. package/sdk/src/nexo.js +5 -1
  27. package/skills/bundled/wiki/SKILL.md +21 -11
  28. package/store/src/eval-cases.js +12 -6
  29. package/store/src/index.js +1 -0
  30. package/store/src/paths.js +1 -0
  31. package/store/src/prompt-history.js +64 -0
  32. package/tools/src/index.js +1 -0
  33. package/tools/src/wiki-page.js +78 -0
  34. package/tui/src/app.js +42 -5
  35. package/tui/src/file-autocomplete.js +166 -0
  36. package/tui/src/questions.js +31 -0
  37. package/web/public/area.html +23 -0
  38. package/web/public/cost.html +1 -1
  39. package/web/public/home.html +23 -0
  40. package/web/public/index.html +1 -1
  41. package/web/public/judge.html +1 -1
  42. package/web/public/learning.html +1 -1
  43. package/web/public/lib/api-types.ts +0 -2
  44. package/web/public/lib/optim-view.ts +1 -1
  45. package/web/public/lib/wikis-view.ts +3 -1
  46. package/web/public/optim.html +1 -1
  47. package/web/public/pages/area.ts +49 -0
  48. package/web/public/pages/home.ts +60 -0
  49. package/web/public/pages/wikis.ts +43 -6
  50. package/web/public/run.html +1 -1
  51. package/web/public/sessions.html +1 -1
  52. package/web/public/style.css +31 -0
  53. package/web/public/wikis.html +1 -1
  54. package/web/src/api.js +11 -6
  55. package/web/src/home-api.js +99 -0
  56. package/web/src/server.js +6 -0
  57. package/optimize/src/merge.js +0 -73
package/tui/src/app.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { homedir } from "node:os";
2
2
  import { sep } from "node:path";
3
- import { CombinedAutocompleteProvider, Container, Editor, isKeyRelease, isKeyRepeat, Loader, matchesKey, ProcessTerminal, setCapabilityOverrides, TuiMainScreen, } from "@earendil-works/pi-tui";
3
+ import { Container, Editor, isKeyRelease, isKeyRepeat, Loader, matchesKey, ProcessTerminal, setCapabilityOverrides, TuiMainScreen, } from "@earendil-works/pi-tui";
4
4
  import { listSessions, projectRoots } from "../../core/src/index.js";
5
5
  import { getSessionRow, reviewQueue, sessionNotFound } from "../../store/src/index.js";
6
6
  import { toErrorPayload } from "../../telemetry/src/index.js";
@@ -8,6 +8,7 @@ import { describeSessionRule } from "../../tools/src/index.js";
8
8
  import { createApprovalPrompter } from "./approvals.js";
9
9
  import { helpText, isSkillCommand, parseSlashCommand, SLASH_COMMANDS, skillSlashCommands } from "./commands.js";
10
10
  import { Block, DynamicLine, QueuedList, SafeContainer, SafeMarkdown, SubagentLine, Ticker, ToolLine, ViewMode } from "./components.js";
11
+ import { createAutocompleteProvider } from "./file-autocomplete.js";
11
12
  import { createSessionPickerScreen } from "./session-picker.js";
12
13
  import { SettingsScreen } from "./settings-screen.js";
13
14
  import { escapeControl, escapeControlKeepLines, formatError, oneLine, toolSummary, usd } from "./text.js";
@@ -130,6 +131,8 @@ class InteractiveApp {
130
131
  loader = null;
131
132
  lastCtrlC = Number.NEGATIVE_INFINITY;
132
133
  lastEscape = Number.NEGATIVE_INFINITY;
134
+ /** Set after the first failed history write, so a read-only home reports once instead of on every prompt. */
135
+ historySaveFailed = false;
133
136
  defaultModel = "";
134
137
  /** Model and effort of the running turn's root run, from its run_start and escalation events; null between turns. */
135
138
  liveModel = null;
@@ -187,7 +190,9 @@ class InteractiveApp {
187
190
  throw error;
188
191
  }
189
192
  this.refreshDefaults();
190
- this.editor.setAutocompleteProvider(new CombinedAutocompleteProvider([...SLASH_COMMANDS, ...skillSlashCommands(this.session.skills())], this.session.cwd));
193
+ // Only the first session seeds the editor; /resume keeps the history already loaded (see switchTo).
194
+ this.loadPromptHistory(this.session.cwd);
195
+ this.editor.setAutocompleteProvider(createAutocompleteProvider([...SLASH_COMMANDS, ...skillSlashCommands(this.session.skills())], this.session.cwd));
191
196
  this.renderHeader(this.session);
192
197
  this.showEditor();
193
198
  await this.exitRequested;
@@ -369,7 +374,8 @@ class InteractiveApp {
369
374
  const text = this.editor.getText();
370
375
  const now = this.now();
371
376
  if (text.trim() !== "" && now - this.lastEscape <= DOUBLE_ESC_MS) {
372
- this.editor.addToHistory(text.trim());
377
+ // Saved to disk too, so a draft cleared by mistake is still recoverable after a restart.
378
+ this.remember(text.trim());
373
379
  this.editor.setText("");
374
380
  this.lastEscape = Number.NEGATIVE_INFINITY;
375
381
  this.tui.requestRender();
@@ -402,7 +408,8 @@ class InteractiveApp {
402
408
  const text = raw.trim();
403
409
  if (!text || !this.session)
404
410
  return;
405
- this.editor.addToHistory(text);
411
+ // Before slash/shell/turn dispatch, so commands and `!` lines are recalled with Up as well as plain messages.
412
+ this.remember(text);
406
413
  const command = parseSlashCommand(text);
407
414
  // `/<skill> …` is a turn (the session pins the skill), so it queues and runs like any message.
408
415
  if (command && !isSkillCommand(command.name, this.session.skills())) {
@@ -423,6 +430,35 @@ class InteractiveApp {
423
430
  }
424
431
  this.dispatch(text);
425
432
  }
433
+ /** Seeds the editor's up-arrow history from earlier runs. A history file that cannot be read is reported, not fatal. */
434
+ loadPromptHistory(cwd) {
435
+ const history = this.options.promptHistory;
436
+ if (!history)
437
+ return;
438
+ try {
439
+ for (const text of history.recent(cwd))
440
+ this.editor.addToHistory(text);
441
+ }
442
+ catch (error) {
443
+ this.sayError(toErrorPayload(error));
444
+ }
445
+ }
446
+ /** Adds a prompt to the editor's history and the saved history; a failed save is reported once per process. */
447
+ remember(text) {
448
+ this.editor.addToHistory(text);
449
+ const session = this.session;
450
+ if (!this.options.promptHistory || !session)
451
+ return;
452
+ try {
453
+ this.options.promptHistory.record({ text, cwd: session.cwd, sessionId: session.id });
454
+ }
455
+ catch (error) {
456
+ if (this.historySaveFailed)
457
+ return;
458
+ this.historySaveFailed = true;
459
+ this.sayError(toErrorPayload(error));
460
+ }
461
+ }
426
462
  /** Starts a `!` command or a turn for one message, whether typed just now or taken from the queue. */
427
463
  dispatch(text) {
428
464
  const session = this.session;
@@ -901,6 +937,7 @@ class InteractiveApp {
901
937
  this.tui.requestRender();
902
938
  return;
903
939
  }
940
+ // The editor's up-arrow history is deliberately not reloaded here: it belongs to the project nexo was started in.
904
941
  this.session = next;
905
942
  this.turnCost = 0;
906
943
  this.lastTurnCost = 0;
@@ -910,7 +947,7 @@ class InteractiveApp {
910
947
  this.liveModel = null;
911
948
  this.tools.clear();
912
949
  this.subagents.clear();
913
- this.editor.setAutocompleteProvider(new CombinedAutocompleteProvider([...SLASH_COMMANDS, ...skillSlashCommands(next.skills())], next.cwd));
950
+ this.editor.setAutocompleteProvider(createAutocompleteProvider([...SLASH_COMMANDS, ...skillSlashCommands(next.skills())], next.cwd));
914
951
  this.chat.clear();
915
952
  this.renderHeader(next);
916
953
  this.tui.requestRender(true);
@@ -0,0 +1,166 @@
1
+ import { execFile } from "node:child_process";
2
+ import { existsSync, readdirSync } from "node:fs";
3
+ import { delimiter, join } from "node:path";
4
+ import { CombinedAutocompleteProvider, } from "@earendil-works/pi-tui";
5
+ const MAX_FILES = 20_000;
6
+ const MAX_DEPTH = 8;
7
+ const MAX_RESULTS = 20;
8
+ const CACHE_MS = 3000;
9
+ const SKIP_DIRS = new Set([".git", "node_modules", ".hg", ".svn", "dist", "build", "target", ".next", ".cache", "__pycache__", ".venv", "venv"]);
10
+ /** An `@` token that starts a word (or follows an opening bracket): `@src/ap` or an unclosed `@"my fi`. */
11
+ const AT_TOKEN = /(?:^|[\s([{<`])(@"[^"]*|@[^\s"]*)$/;
12
+ /** Finds the `fd` binary (`fd`, `fdfind` on Debian/Ubuntu, `fd.exe` on Windows) on PATH; null when absent. */
13
+ export function findFd(env = process.env, platform = process.platform) {
14
+ const names = platform === "win32" ? ["fd.exe"] : ["fd", "fdfind"];
15
+ const pathVar = env.PATH ?? env.Path ?? "";
16
+ for (const dir of pathVar.split(delimiter)) {
17
+ if (!dir)
18
+ continue;
19
+ for (const name of names) {
20
+ const candidate = join(dir, name);
21
+ if (existsSync(candidate))
22
+ return candidate;
23
+ }
24
+ }
25
+ return null;
26
+ }
27
+ function gitFiles(cwd) {
28
+ return new Promise((resolve) => {
29
+ execFile("git", ["ls-files", "-co", "--exclude-standard", "-z"], { cwd, maxBuffer: 64 * 1024 * 1024, timeout: 5000, windowsHide: true }, (error, stdout) => {
30
+ if (error)
31
+ return resolve(null);
32
+ const files = stdout.split("\0").filter(Boolean);
33
+ resolve(files.length > 0 ? files.slice(0, MAX_FILES) : null);
34
+ });
35
+ });
36
+ }
37
+ /** Breadth-first directory walk used outside git repos. Skips dependency and build directories; bounded by depth and file count. */
38
+ export function walkFiles(cwd) {
39
+ const files = [];
40
+ const queue = [{ rel: "", depth: 0 }];
41
+ while (queue.length > 0 && files.length < MAX_FILES) {
42
+ const { rel, depth } = queue.shift();
43
+ let dirents;
44
+ try {
45
+ dirents = readdirSync(rel ? join(cwd, rel) : cwd, { withFileTypes: true });
46
+ }
47
+ catch {
48
+ continue;
49
+ }
50
+ for (const d of dirents) {
51
+ const childRel = rel ? `${rel}/${d.name}` : d.name;
52
+ if (d.isDirectory()) {
53
+ if (!SKIP_DIRS.has(d.name) && depth < MAX_DEPTH)
54
+ queue.push({ rel: childRel, depth: depth + 1 });
55
+ }
56
+ else if (d.isFile()) {
57
+ files.push(childRel);
58
+ if (files.length >= MAX_FILES)
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ return files;
64
+ }
65
+ /** Files plus every parent directory, as forward-slash paths relative to the project root (directories end in `/`). */
66
+ export function withDirectories(files) {
67
+ const dirs = new Set();
68
+ for (const file of files) {
69
+ const parts = file.split("/");
70
+ for (let i = 1; i < parts.length; i++)
71
+ dirs.add(`${parts.slice(0, i).join("/")}/`);
72
+ }
73
+ return [...[...dirs].map((path) => ({ path, isDirectory: true })), ...files.map((path) => ({ path, isDirectory: false }))];
74
+ }
75
+ function isSubsequence(text, query) {
76
+ let i = 0;
77
+ for (const ch of text)
78
+ if (ch === query[i] && ++i === query.length)
79
+ return true;
80
+ return query.length === 0;
81
+ }
82
+ export function scoreEntry(path, isDirectory, query) {
83
+ if (!query)
84
+ return 1;
85
+ const p = path.toLowerCase();
86
+ const name = (isDirectory ? p.slice(0, -1) : p).split("/").pop() ?? p;
87
+ let score;
88
+ if (name.startsWith(query))
89
+ score = 100;
90
+ else if (name.includes(query))
91
+ score = 80;
92
+ else if (p.includes(query))
93
+ score = 60;
94
+ else if (isSubsequence(p, query))
95
+ score = 30;
96
+ else
97
+ return 0;
98
+ return isDirectory ? score + 5 : score;
99
+ }
100
+ /**
101
+ * Autocomplete for slash commands and `@file` mentions that needs no external binary. `@` suggestions come from
102
+ * `git ls-files` (respects .gitignore) or a bounded directory walk; everything else is delegated to pi-tui.
103
+ */
104
+ class NodeFileAutocompleteProvider {
105
+ inner;
106
+ cwd;
107
+ cache = null;
108
+ constructor(commands, cwd) {
109
+ this.cwd = cwd;
110
+ this.inner = new CombinedAutocompleteProvider(commands, cwd, null);
111
+ }
112
+ entries() {
113
+ const now = Date.now();
114
+ if (this.cache && now - this.cache.at < CACHE_MS)
115
+ return this.cache.entries;
116
+ const entries = (async () => withDirectories((await gitFiles(this.cwd)) ?? walkFiles(this.cwd)))();
117
+ this.cache = { at: now, entries };
118
+ return entries;
119
+ }
120
+ async getSuggestions(lines, cursorLine, cursorCol, options) {
121
+ const before = (lines[cursorLine] ?? "").slice(0, cursorCol);
122
+ const match = AT_TOKEN.exec(before);
123
+ if (!match)
124
+ return this.inner.getSuggestions(lines, cursorLine, cursorCol, options);
125
+ const prefix = match[1];
126
+ const quoted = prefix.startsWith('@"');
127
+ const query = prefix.slice(quoted ? 2 : 1).replace(/\\/g, "/").toLowerCase();
128
+ const entries = await this.entries();
129
+ if (options.signal.aborted)
130
+ return null;
131
+ const depth = (path) => path.split("/").filter(Boolean).length;
132
+ const ranked = entries
133
+ .map((entry) => ({ entry, score: scoreEntry(entry.path, entry.isDirectory, query) }))
134
+ .filter((r) => r.score > 0)
135
+ .sort((a, b) => b.score - a.score || depth(a.entry.path) - depth(b.entry.path) || a.entry.path.length - b.entry.path.length || a.entry.path.localeCompare(b.entry.path))
136
+ .slice(0, MAX_RESULTS);
137
+ if (ranked.length === 0)
138
+ return null;
139
+ const items = ranked.map(({ entry }) => {
140
+ const bare = entry.isDirectory ? entry.path.slice(0, -1) : entry.path;
141
+ const name = bare.split("/").pop() ?? bare;
142
+ const needsQuotes = quoted || /\s/.test(entry.path);
143
+ return {
144
+ value: needsQuotes ? `@"${entry.path}"` : `@${entry.path}`,
145
+ label: entry.isDirectory ? `${name}/` : name,
146
+ description: bare,
147
+ };
148
+ });
149
+ return { items, prefix };
150
+ }
151
+ applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
152
+ return this.inner.applyCompletion(lines, cursorLine, cursorCol, item, prefix);
153
+ }
154
+ shouldTriggerFileCompletion(lines, cursorLine, cursorCol) {
155
+ return this.inner.shouldTriggerFileCompletion(lines, cursorLine, cursorCol);
156
+ }
157
+ }
158
+ /**
159
+ * Slash-command and `@file` autocomplete for the editor. Uses `fd` when it is installed (faster on huge trees);
160
+ * otherwise falls back to a Node implementation so `@` works on every platform without extra installs.
161
+ */
162
+ export function createAutocompleteProvider(commands, cwd, fdPath = findFd()) {
163
+ if (fdPath)
164
+ return new CombinedAutocompleteProvider(commands, cwd, fdPath);
165
+ return new NodeFileAutocompleteProvider(commands, cwd);
166
+ }
@@ -5,6 +5,8 @@ const UP = "\u001b[A";
5
5
  const DOWN = "\u001b[B";
6
6
  const ESC = "\u001b";
7
7
  const OTHER_LABEL = "Type your own answer";
8
+ const PASTE_START = "\u001b[200~";
9
+ const PASTE_END = "\u001b[201~";
8
10
  /**
9
11
  * An `ask_user` box: one question at a time, ↑↓ to move, space to toggle (multi-select), enter to answer, and a
10
12
  * "Type your own answer" row that opens a one-line text field. Esc declines the whole request.
@@ -15,6 +17,8 @@ export class QuestionBox extends Container {
15
17
  picked = new Set();
16
18
  typing = false;
17
19
  draft = "";
20
+ inPaste = false;
21
+ pasteBuffer = "";
18
22
  answers = [];
19
23
  request;
20
24
  onDone;
@@ -34,6 +38,10 @@ export class QuestionBox extends Container {
34
38
  const q = this.question;
35
39
  const other = q.options.length;
36
40
  if (this.typing) {
41
+ if (this.inPaste || data.includes(PASTE_START)) {
42
+ this.paste(data);
43
+ return;
44
+ }
37
45
  if (data === "\r" || data === "\n") {
38
46
  if (this.draft.trim())
39
47
  this.commit([], this.draft.trim());
@@ -75,6 +83,27 @@ export class QuestionBox extends Container {
75
83
  else if (data === ESC)
76
84
  this.onDone(null);
77
85
  }
86
+ /** Bracketed paste (the terminal wraps pasted text in ESC[200~ … ESC[201~), possibly split across chunks. */
87
+ paste(data) {
88
+ const start = data.indexOf(PASTE_START);
89
+ if (start !== -1) {
90
+ this.inPaste = true;
91
+ this.pasteBuffer = "";
92
+ data = data.slice(start + PASTE_START.length);
93
+ }
94
+ this.pasteBuffer += data;
95
+ const end = this.pasteBuffer.indexOf(PASTE_END);
96
+ if (end === -1)
97
+ return;
98
+ const text = this.pasteBuffer.slice(0, end);
99
+ const rest = this.pasteBuffer.slice(end + PASTE_END.length);
100
+ this.inPaste = false;
101
+ this.pasteBuffer = "";
102
+ // One-line field: newlines and tabs become spaces, other control characters are dropped.
103
+ this.draft += text.replace(/[\r\n\t]+/g, " ").replace(/[\u0000-\u001f\u007f]/g, "");
104
+ if (rest)
105
+ this.handleInput(rest);
106
+ }
78
107
  commit(selected, text) {
79
108
  this.answers.push({ question: this.question.question, selected, ...(text ? { text } : {}) });
80
109
  this.index++;
@@ -82,6 +111,8 @@ export class QuestionBox extends Container {
82
111
  this.picked = new Set();
83
112
  this.typing = false;
84
113
  this.draft = "";
114
+ this.inPaste = false;
115
+ this.pasteBuffer = "";
85
116
  if (this.index >= this.request.questions.length)
86
117
  this.onDone({ answers: [...this.answers] });
87
118
  }
@@ -0,0 +1,23 @@
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 · area</title>
8
+ <link rel="stylesheet" href="/style.css">
9
+ <script type="module" src="/lib/theme.ts"></script>
10
+ <script type="module" src="/pages/companion.ts"></script>
11
+ <script type="module" src="/pages/area.ts"></script>
12
+ </head>
13
+ <body>
14
+ <a class="skip" href="#main">Skip to content</a>
15
+ <nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html" aria-current="page">Home</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>
16
+ <main id="main" tabindex="-1">
17
+ <p class="muted"><a href="/home.html">&larr; Home</a></p>
18
+ <h1 id="area-title">Area</h1>
19
+ <div id="error"></div>
20
+ <div id="area"></div>
21
+ </main>
22
+ </body>
23
+ </html>
@@ -12,7 +12,7 @@
12
12
  </head>
13
13
  <body>
14
14
  <a class="skip" href="#main">Skip to content</a>
15
- <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
+ <nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html">Home</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>
16
16
  <main id="main" tabindex="-1">
17
17
  <h1>Cost</h1>
18
18
  <form id="cost-form" class="filters">
@@ -0,0 +1,23 @@
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 · home</title>
8
+ <link rel="stylesheet" href="/style.css">
9
+ <script type="module" src="/lib/theme.ts"></script>
10
+ <script type="module" src="/pages/companion.ts"></script>
11
+ <script type="module" src="/pages/home.ts"></script>
12
+ </head>
13
+ <body>
14
+ <a class="skip" href="#main">Skip to content</a>
15
+ <nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html" aria-current="page">Home</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>
16
+ <main id="main" tabindex="-1">
17
+ <h1>Home</h1>
18
+ <div id="error"></div>
19
+ <input id="home-search" class="home-search" type="search" placeholder="Search areas, wikis, recent activity and decisions" aria-label="Search">
20
+ <div id="home"></div>
21
+ </main>
22
+ </body>
23
+ </html>
@@ -12,7 +12,7 @@
12
12
  </head>
13
13
  <body>
14
14
  <a class="skip" href="#main">Skip to content</a>
15
- <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
+ <nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html">Home</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>
16
16
  <main id="main" tabindex="-1">
17
17
  <h1>Runs</h1>
18
18
  <div id="session-filter"></div>
@@ -12,7 +12,7 @@
12
12
  </head>
13
13
  <body>
14
14
  <a class="skip" href="#main">Skip to content</a>
15
- <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
+ <nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html">Home</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>
16
16
  <main id="main" tabindex="-1">
17
17
  <h1>Judge calibration</h1>
18
18
  <div id="error"></div>
@@ -12,7 +12,7 @@
12
12
  </head>
13
13
  <body>
14
14
  <a class="skip" href="#main">Skip to content</a>
15
- <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
+ <nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html">Home</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>
16
16
  <main id="main" tabindex="-1">
17
17
  <h1>Learning</h1>
18
18
  <div id="error"></div>
@@ -554,8 +554,6 @@ export interface OptimReport {
554
554
  spentUsd: number;
555
555
  rollouts: number;
556
556
  iterations: number;
557
- merges: number;
558
- mergeNote: string | null;
559
557
  climb?: { caseId: string; guardIds: string[]; outcome: string; critique: string | null; comparisons: { label: string; winner: "A" | "B" | "tie" }[] };
560
558
  createdAt: string;
561
559
  }
@@ -46,7 +46,7 @@ ${h.wins} win${h.wins === 1 ? "" : "s"}, ${h.losses} loss${h.losses === 1 ? "" :
46
46
  ${report.improved ? "" : html`<span class="muted">No candidate beat the starting version.</span>`}</p>
47
47
  <table class="runs holdout"><thead><tr><th>Case</th><th>Before</th><th>After</th><th>Outcome</th></tr></thead>
48
48
  <tbody>${h.cases.map((c) => html`<tr><td>${truncate(c.input, 120)}</td><td>${scoreCell(c.before)}</td><td>${scoreCell(c.after)}</td><td><span class="badge outcome-${c.outcome}">${c.outcome}</span></td></tr>`)}</tbody></table>
49
- <p class="muted">Stopped by ${report.stopReason} after ${report.iterations} iteration${report.iterations === 1 ? "" : "s"} and ${report.rollouts} rollouts (${formatUsd(report.spentUsd)}); ${report.merges} merge${report.merges === 1 ? "" : "s"}${report.mergeNote ? ` (${report.mergeNote})` : ""}.</p>`;
49
+ <p class="muted">Stopped by ${report.stopReason} after ${report.iterations} iteration${report.iterations === 1 ? "" : "s"} and ${report.rollouts} rollouts (${formatUsd(report.spentUsd)}).</p>`;
50
50
  }
51
51
 
52
52
  /** The base → best text diff, one line per row. */
@@ -239,7 +239,9 @@ export function renderWikiTree(pages: readonly WikiPageItem[], activeWiki: strin
239
239
 
240
240
  /** Renders a full wiki page view with breadcrumbs, summary box, rendered content and metadata. */
241
241
  export function renderWikiPage(page: WikiPageResponse, activeWiki: string): SafeHtml {
242
- const renderedContent = renderMarkdown(page.content, activeWiki);
242
+ const renderedContent = page.path.endsWith(".html")
243
+ ? new SafeHtml(`<div class="wiki-html" id="wiki-html-body"></div>`)
244
+ : renderMarkdown(page.content, activeWiki);
243
245
  return html`<article class="wiki-page">
244
246
  <header class="wiki-page-header">
245
247
  <div class="wiki-crumbs mono">
@@ -12,7 +12,7 @@
12
12
  </head>
13
13
  <body>
14
14
  <a class="skip" href="#main">Skip to content</a>
15
- <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
+ <nav class="top" aria-label="Primary"><a href="/" class="brand">nexo</a><a href="/home.html">Home</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>
16
16
  <main id="main" tabindex="-1">
17
17
  <h1>Optimization</h1>
18
18
  <div id="error"></div>
@@ -0,0 +1,49 @@
1
+ import { renderError } from "../lib/common-view.ts";
2
+ import { formatTime } from "../lib/format.ts";
3
+ import { html, type SafeHtml } from "../lib/html.ts";
4
+ import { asErrorBody, el, getJson } from "./api.ts";
5
+
6
+ interface HomeWiki { name: string; summary?: string; pageCount: number }
7
+ interface HomeArea { id: string; name: string; scope: string; wikis: HomeWiki[]; recent: number }
8
+ interface HomeFeedItem { at: string; text: string; areaId: string | null; wiki: string | null; sessionId: string | null; runId: string; verified: boolean }
9
+ interface HomeDecision { at: string; choice: string; reason: string; areaId: string | null; wiki: string | null; sessionId: string | null; runId: string }
10
+ interface HomeSession { id: string; title: string; cwd: string; updatedAt: string; areaId: string | null }
11
+ interface Home { areas: HomeArea[]; feed: HomeFeedItem[]; decisions: HomeDecision[]; sessions: HomeSession[] }
12
+
13
+ const box = el<HTMLDivElement>("#area");
14
+ const title = el<HTMLHeadingElement>("#area-title");
15
+ const errorBox = el<HTMLDivElement>("#error");
16
+
17
+ function list(items: SafeHtml[], empty: string): SafeHtml {
18
+ return items.length > 0 ? html`<ul class="home-list">${items}</ul>` : html`<p class="muted">${empty}</p>`;
19
+ }
20
+
21
+ function render(d: Home, id: string): void {
22
+ const a = d.areas.find((x) => x.id === id);
23
+ if (!a) {
24
+ title.textContent = "Area not found";
25
+ box.innerHTML = html`<p class="muted">No active area "${id}". <a href="/home.html">Back to Home</a>.</p>`.value;
26
+ return;
27
+ }
28
+ title.textContent = a.name;
29
+ document.title = `nexo · ${a.name}`;
30
+ const wikis = a.wikis.map((w) => html`<li><a href="/wikis.html#${encodeURIComponent(w.name)}/index">${w.name}</a> <span class="muted">${String(w.pageCount)} pages${w.summary ? ` · ${w.summary}` : ""}</span></li>`);
31
+ const feed = d.feed.filter((f) => f.areaId === a.id).slice(0, 30).map((f) => {
32
+ const link = f.sessionId ? html`<a href="/?session=${encodeURIComponent(f.sessionId)}">session</a>` : html`<a href="/run.html?id=${encodeURIComponent(f.runId)}">run</a>`;
33
+ return html`<li><span class="muted mono">${formatTime(f.at)}</span> ${f.text}${f.verified ? "" : html` <span class="home-tag">unverified</span>`}${f.wiki ? html` <span class="muted">· ${f.wiki}</span>` : ""} ${link}</li>`;
34
+ });
35
+ const decisions = d.decisions.filter((x) => x.areaId === a.id).map((x) => html`<li><span class="muted mono">${formatTime(x.at)}</span> <strong>${x.choice}</strong>${x.reason ? html` <span class="muted">because ${x.reason}</span>` : ""}</li>`);
36
+ const sessions = d.sessions.filter((s) => s.areaId === a.id).map((s) => html`<li><a href="/?session=${encodeURIComponent(s.id)}">${s.title || s.id}</a> <span class="muted">${s.cwd} · ${formatTime(s.updatedAt)}</span></li>`);
37
+ box.innerHTML = html`<p class="home-note">${a.scope}</p>
38
+ <section><h2>Wikis</h2>${list(wikis, "No wikis in this area yet.")}</section>
39
+ <section><h2>Recent</h2>${list(feed, "Nothing filed here yet. Finished tasks appear here after they are scored.")}</section>
40
+ <section><h2>Decisions</h2>${list(decisions, "No decisions recorded here yet.")}</section>
41
+ <section><h2>Sessions</h2>${list(sessions, "No linked sessions yet.")}</section>`.value;
42
+ }
43
+
44
+ const id = new URLSearchParams(location.search).get("id") ?? "";
45
+ getJson<Home>("/api/home")
46
+ .then((d) => render(d, id))
47
+ .catch((error) => {
48
+ errorBox.innerHTML = renderError(asErrorBody(error)).value;
49
+ });
@@ -0,0 +1,60 @@
1
+ import { renderError } from "../lib/common-view.ts";
2
+ import { formatTime } from "../lib/format.ts";
3
+ import { html, type SafeHtml } from "../lib/html.ts";
4
+ import { asErrorBody, el, getJson } from "./api.ts";
5
+
6
+ interface HomeWiki { name: string; summary?: string; pageCount: number }
7
+ interface HomeArea { id: string; name: string; scope: string; wikis: HomeWiki[]; recent: number }
8
+ interface HomeFeedItem { at: string; text: string; areaId: string | null; wiki: string | null; sessionId: string | null; runId: string; verified: boolean }
9
+ interface HomeDecision { at: string; choice: string; reason: string; areaId: string | null; wiki: string | null; sessionId: string | null; runId: string }
10
+ interface HomeSession { id: string; title: string; cwd: string; updatedAt: string; areaId: string | null }
11
+ interface Home { areas: HomeArea[]; proposed: { id: string; name: string }[]; unsorted: number; feed: HomeFeedItem[]; decisions: HomeDecision[]; sessions: HomeSession[] }
12
+
13
+ const box = el<HTMLDivElement>("#home");
14
+ const errorBox = el<HTMLDivElement>("#error");
15
+ const search = el<HTMLInputElement>("#home-search");
16
+ let data: Home | null = null;
17
+
18
+ const hit = (q: string, ...parts: (string | null | undefined)[]) => !q || parts.some((p) => (p ?? "").toLowerCase().includes(q));
19
+ const areaName = (id: string | null) => data?.areas.find((a) => a.id === id)?.name ?? "unsorted";
20
+
21
+ function feedItem(f: HomeFeedItem): SafeHtml {
22
+ const link = f.sessionId ? html`<a href="/?session=${encodeURIComponent(f.sessionId)}">session</a>` : html`<a href="/run.html?id=${encodeURIComponent(f.runId)}">run</a>`;
23
+ return html`<li><span class="muted mono">${formatTime(f.at)}</span> ${f.text}${f.verified ? "" : html` <span class="home-tag">unverified</span>`} <span class="muted">· ${areaName(f.areaId)}${f.wiki ? ` · ${f.wiki}` : ""}</span> ${link}</li>`;
24
+ }
25
+
26
+ function list(items: SafeHtml[], empty: string): SafeHtml {
27
+ return items.length > 0 ? html`<ul class="home-list">${items}</ul>` : html`<p class="muted">${empty}</p>`;
28
+ }
29
+
30
+ function areaCard(a: HomeArea): SafeHtml {
31
+ return html`<a class="home-area" href="/area.html?id=${encodeURIComponent(a.id)}"><strong>${a.name}</strong> <span class="muted">${String(a.recent)} this week · ${String(a.wikis.length)} wikis</span><span class="home-scope muted">${a.scope}</span></a>`;
32
+ }
33
+
34
+ function render(): void {
35
+ if (!data) return;
36
+ const d = data;
37
+ const q = search.value.trim().toLowerCase();
38
+ const feed = d.feed.filter((f) => hit(q, f.text, f.wiki, areaName(f.areaId)));
39
+ const decisions = d.decisions.filter((x) => hit(q, x.choice, x.reason, x.wiki, areaName(x.areaId)));
40
+ const areas = d.areas.filter((a) => hit(q, a.name, a.scope, ...a.wikis.map((w) => `${w.name} ${w.summary ?? ""}`)) || (q !== "" && feed.some((f) => f.areaId === a.id)));
41
+ const sessions = d.sessions.filter((s) => hit(q, s.title, s.cwd, areaName(s.areaId)));
42
+ const pending = d.proposed.length > 0 ? html`<p class="home-note">${String(d.proposed.length)} proposed area(s) waiting for approval: ${d.proposed.map((p) => p.name).join(", ")}. Run <code>nexo areas list</code>.</p>` : "";
43
+ const decisionItems = decisions.slice(0, 20).map((x) => html`<li><span class="muted mono">${formatTime(x.at)}</span> <strong>${x.choice}</strong>${x.reason ? html` <span class="muted">because ${x.reason}</span>` : ""} <span class="muted">· ${areaName(x.areaId)}</span></li>`);
44
+ const sessionItems = sessions.map((s) => html`<li><a href="/?session=${encodeURIComponent(s.id)}">${s.title || s.id}</a> <span class="muted">${s.cwd} · ${formatTime(s.updatedAt)}</span></li>`);
45
+ box.innerHTML = html`${pending}
46
+ <section><h2>Areas</h2><div class="home-areas">${areas.map((a) => areaCard(a))}</div></section>
47
+ <section><h2>Recent</h2>${list(feed.slice(0, 20).map(feedItem), "No activity yet. Each finished task adds a line here after it is scored.")}</section>
48
+ <section><h2>Decisions</h2>${list(decisionItems, "No decisions recorded yet.")}</section>
49
+ <section><h2>Recent sessions</h2>${list(sessionItems, "No sessions.")}</section>`.value;
50
+ }
51
+
52
+ search.addEventListener("input", render);
53
+ getJson<Home>("/api/home")
54
+ .then((d) => {
55
+ data = d;
56
+ render();
57
+ })
58
+ .catch((error) => {
59
+ errorBox.innerHTML = renderError(asErrorBody(error)).value;
60
+ });