@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.
Files changed (208) hide show
  1. package/LICENSE +75 -0
  2. package/README.md +75 -2
  3. package/cli/src/bin.js +12 -0
  4. package/cli/src/common.js +77 -0
  5. package/cli/src/doctor.js +27 -0
  6. package/cli/src/eval-cases.js +65 -0
  7. package/cli/src/eval.js +67 -0
  8. package/cli/src/init.js +186 -0
  9. package/cli/src/interactive.js +171 -0
  10. package/cli/src/learn.js +178 -0
  11. package/cli/src/main.js +261 -0
  12. package/cli/src/optimize.js +289 -0
  13. package/cli/src/prompter.js +47 -0
  14. package/cli/src/review.js +120 -0
  15. package/cli/src/runtime.js +2 -0
  16. package/cli/src/sessions.js +34 -0
  17. package/cli/src/settings.js +169 -0
  18. package/cli/src/ui.js +112 -0
  19. package/core/src/approval/classifier.js +152 -0
  20. package/core/src/config/load.js +283 -0
  21. package/core/src/config/schema.js +186 -0
  22. package/core/src/cost/admission.js +90 -0
  23. package/core/src/cost/budget.js +67 -0
  24. package/core/src/cost/pricing.js +53 -0
  25. package/core/src/engine/charged-completion.js +79 -0
  26. package/core/src/engine/errors.js +77 -0
  27. package/core/src/engine/mcp.js +11 -0
  28. package/core/src/engine/messages.js +86 -0
  29. package/core/src/engine/prompts.js +32 -0
  30. package/core/src/engine/provider-gate.js +33 -0
  31. package/core/src/engine/recorder.js +61 -0
  32. package/core/src/engine/run.js +1115 -0
  33. package/core/src/engine/semaphore.js +45 -0
  34. package/core/src/engine/spawn-tool.js +119 -0
  35. package/core/src/engine/task-graph.js +153 -0
  36. package/core/src/index.js +32 -0
  37. package/core/src/learn/caller.js +171 -0
  38. package/core/src/learn/context.js +112 -0
  39. package/core/src/learn/embedder.js +216 -0
  40. package/core/src/learn/job.js +196 -0
  41. package/core/src/learn/wiki.js +116 -0
  42. package/core/src/learn/worker.js +141 -0
  43. package/core/src/optimize/adapter.js +250 -0
  44. package/core/src/optimize/climb.js +338 -0
  45. package/core/src/optimize/mine.js +95 -0
  46. package/core/src/optimize/optimize.js +377 -0
  47. package/core/src/optimize/optimizer-run.js +67 -0
  48. package/core/src/optimize/reflect.js +100 -0
  49. package/core/src/optimize/scratchpad-wiki.js +69 -0
  50. package/core/src/providers/claude-p.js +363 -0
  51. package/core/src/providers/kiro-p.js +408 -0
  52. package/core/src/providers/models.js +10 -0
  53. package/core/src/scoring/calibration.js +31 -0
  54. package/core/src/scoring/continuation.js +24 -0
  55. package/core/src/scoring/runner.js +322 -0
  56. package/core/src/scoring/sources.js +88 -0
  57. package/core/src/session/lock.js +88 -0
  58. package/core/src/session/session.js +647 -0
  59. package/core/src/session/shell.js +26 -0
  60. package/core/src/session/transcript.js +86 -0
  61. package/core/src/settings/config-edit.js +472 -0
  62. package/core/src/settings/credentials.js +120 -0
  63. package/core/src/settings/doctor.js +103 -0
  64. package/core/src/settings/settings.js +265 -0
  65. package/mcp/src/hub.js +184 -0
  66. package/mcp/src/index.js +1 -0
  67. package/memory/src/curate.js +121 -0
  68. package/memory/src/index.js +4 -0
  69. package/memory/src/prompts.js +143 -0
  70. package/memory/src/retrieval.js +91 -0
  71. package/memory/src/similarity.js +47 -0
  72. package/optimize/src/engine.js +206 -0
  73. package/optimize/src/index.js +8 -0
  74. package/optimize/src/merge.js +73 -0
  75. package/optimize/src/novelty.js +37 -0
  76. package/optimize/src/pareto.js +83 -0
  77. package/optimize/src/proposer.js +148 -0
  78. package/optimize/src/report.js +107 -0
  79. package/optimize/src/rng.js +34 -0
  80. package/optimize/src/target.js +34 -0
  81. package/package.json +47 -4
  82. package/router/src/effort.js +5 -0
  83. package/router/src/escalation.js +171 -0
  84. package/router/src/index.js +4 -0
  85. package/router/src/registry.js +21 -0
  86. package/router/src/resolve.js +117 -0
  87. package/scorers/src/deterministic.js +194 -0
  88. package/scorers/src/family.js +48 -0
  89. package/scorers/src/index.js +6 -0
  90. package/scorers/src/judge.js +284 -0
  91. package/scorers/src/regex-worker.js +3 -0
  92. package/scorers/src/spec.js +147 -0
  93. package/scorers/src/trajectory.js +22 -0
  94. package/scorers/src/types.js +1 -0
  95. package/sdk/src/index.js +3 -0
  96. package/sdk/src/nexo.js +94 -0
  97. package/sdk/src/runtime.js +39 -0
  98. package/skills/bundled/browser/SKILL.md +57 -0
  99. package/skills/bundled/wiki/SKILL.md +73 -0
  100. package/skills/src/frontmatter.js +25 -0
  101. package/skills/src/index.js +3 -0
  102. package/skills/src/load-skill-tool.js +41 -0
  103. package/skills/src/loader.js +95 -0
  104. package/store/src/artifacts.js +124 -0
  105. package/store/src/budget-ledger.js +18 -0
  106. package/store/src/cost-report.js +46 -0
  107. package/store/src/cursor.js +35 -0
  108. package/store/src/db.js +83 -0
  109. package/store/src/errors.js +9 -0
  110. package/store/src/eval-cases.js +255 -0
  111. package/store/src/feedback.js +154 -0
  112. package/store/src/goldens.js +61 -0
  113. package/store/src/ids.js +6 -0
  114. package/store/src/index.js +25 -0
  115. package/store/src/judge-calibration.js +182 -0
  116. package/store/src/learn-jobs.js +145 -0
  117. package/store/src/memories.js +261 -0
  118. package/store/src/migrations/001_init.sql +81 -0
  119. package/store/src/migrations/002_feedback.sql +9 -0
  120. package/store/src/migrations/003_sessions.sql +19 -0
  121. package/store/src/migrations/004_scoring.sql +22 -0
  122. package/store/src/migrations/005_judge_calibration.sql +27 -0
  123. package/store/src/migrations/006_learning.sql +77 -0
  124. package/store/src/migrations/007_optimize.sql +55 -0
  125. package/store/src/migrations/008_mined_cases_and_climb.sql +46 -0
  126. package/store/src/mine.js +51 -0
  127. package/store/src/optim.js +291 -0
  128. package/store/src/paths.js +22 -0
  129. package/store/src/playbooks.js +199 -0
  130. package/store/src/reindex.js +143 -0
  131. package/store/src/run-dir.js +151 -0
  132. package/store/src/runs.js +310 -0
  133. package/store/src/scores.js +92 -0
  134. package/store/src/sessions.js +304 -0
  135. package/store/src/span-tree.js +98 -0
  136. package/store/src/spans.js +84 -0
  137. package/store/src/sql.js +13 -0
  138. package/store/src/workspace-copy.js +80 -0
  139. package/telemetry/src/errors.js +32 -0
  140. package/telemetry/src/index.js +3 -0
  141. package/telemetry/src/logger.js +39 -0
  142. package/telemetry/src/redact.js +106 -0
  143. package/tools/src/builtin.js +269 -0
  144. package/tools/src/change-tracker.js +57 -0
  145. package/tools/src/confine.js +101 -0
  146. package/tools/src/index.js +7 -0
  147. package/tools/src/leases.js +57 -0
  148. package/tools/src/policy.js +162 -0
  149. package/tools/src/read-only.js +338 -0
  150. package/tools/src/session-rules.js +140 -0
  151. package/tui/src/app.js +948 -0
  152. package/tui/src/approvals.js +96 -0
  153. package/tui/src/commands.js +38 -0
  154. package/tui/src/components.js +248 -0
  155. package/tui/src/index.js +5 -0
  156. package/tui/src/picker.js +78 -0
  157. package/tui/src/session-picker.js +100 -0
  158. package/tui/src/settings-screen.js +346 -0
  159. package/tui/src/text.js +70 -0
  160. package/tui/src/theme.js +44 -0
  161. package/web/public/cost.html +25 -0
  162. package/web/public/fonts/GeistMono-400.woff2 +0 -0
  163. package/web/public/fonts/GeistMono-600.woff2 +0 -0
  164. package/web/public/fonts/InstrumentSans-400.woff2 +0 -0
  165. package/web/public/fonts/InstrumentSans-600.woff2 +0 -0
  166. package/web/public/index.html +39 -0
  167. package/web/public/judge.html +21 -0
  168. package/web/public/learning.html +46 -0
  169. package/web/public/lib/api-types.ts +616 -0
  170. package/web/public/lib/common-view.ts +47 -0
  171. package/web/public/lib/cost-view.ts +35 -0
  172. package/web/public/lib/files-view.ts +90 -0
  173. package/web/public/lib/format.ts +35 -0
  174. package/web/public/lib/html.ts +51 -0
  175. package/web/public/lib/judge-view.ts +62 -0
  176. package/web/public/lib/learning-view.ts +102 -0
  177. package/web/public/lib/optim-view.ts +148 -0
  178. package/web/public/lib/pager.ts +56 -0
  179. package/web/public/lib/poller.ts +79 -0
  180. package/web/public/lib/run-view.ts +61 -0
  181. package/web/public/lib/runs-view.ts +87 -0
  182. package/web/public/lib/score-view.ts +94 -0
  183. package/web/public/lib/sessions-view.ts +28 -0
  184. package/web/public/lib/span-view.ts +90 -0
  185. package/web/public/lib/theme.ts +60 -0
  186. package/web/public/lib/timeline.ts +97 -0
  187. package/web/public/lib/wikis-view.ts +257 -0
  188. package/web/public/optim.html +30 -0
  189. package/web/public/pages/api.ts +60 -0
  190. package/web/public/pages/cost.ts +36 -0
  191. package/web/public/pages/judge.ts +15 -0
  192. package/web/public/pages/learning.ts +92 -0
  193. package/web/public/pages/optim.ts +68 -0
  194. package/web/public/pages/paging.ts +18 -0
  195. package/web/public/pages/run.ts +221 -0
  196. package/web/public/pages/runs.ts +91 -0
  197. package/web/public/pages/sessions.ts +25 -0
  198. package/web/public/pages/wikis.ts +103 -0
  199. package/web/public/run.html +36 -0
  200. package/web/public/sessions.html +28 -0
  201. package/web/public/style.css +288 -0
  202. package/web/public/wikis.html +25 -0
  203. package/web/src/api.js +682 -0
  204. package/web/src/http-errors.js +60 -0
  205. package/web/src/index.js +5 -0
  206. package/web/src/server.js +292 -0
  207. package/web/src/static.js +86 -0
  208. package/web/src/strip.js +22 -0
@@ -0,0 +1,346 @@
1
+ import { Input, truncateToWidth } from "@earendil-works/pi-tui";
2
+ import { keyStatusLabel, ON_OFF } from "../../core/src/index.js";
3
+ import { toErrorPayload } from "../../telemetry/src/index.js";
4
+ import { fitLines, MaskedInput } from "./components.js";
5
+ import { PickerView } from "./picker.js";
6
+ import { escapeControl, formatError } from "./text.js";
7
+ import { style } from "./theme.js";
8
+ const RESET = "\u0000reset";
9
+ const BACK = "\u0000back";
10
+ /** A single-line text entry (plain or masked). */
11
+ class EntryView {
12
+ title;
13
+ hint;
14
+ input;
15
+ constructor(options) {
16
+ this.title = options.title;
17
+ this.hint = options.hint;
18
+ this.input = options.input;
19
+ this.input.focused = true;
20
+ }
21
+ handleInput(data) {
22
+ this.input.handleInput(data);
23
+ }
24
+ render(width) {
25
+ return fitLines(this.input.render(width), width);
26
+ }
27
+ invalidate() { }
28
+ }
29
+ function valueText(view) {
30
+ return view.value === null ? "unset" : String(view.value);
31
+ }
32
+ function settingDescription(view) {
33
+ const source = view.source === "unset" ? "" : ` (${view.source})`;
34
+ const notice = view.notice ? ` · ${view.notice}` : "";
35
+ return escapeControl(`${valueText(view)}${source}${notice}`);
36
+ }
37
+ /**
38
+ * The settings screen: provider key status and masked key entry, the editable settings with their source and
39
+ * project-override notice, and the first-run setup flow. All reads and writes go through the core `Settings` service.
40
+ */
41
+ export class SettingsScreen {
42
+ settings;
43
+ mode;
44
+ rows;
45
+ requestRender;
46
+ onClose;
47
+ view;
48
+ status = null;
49
+ intro = null;
50
+ closed = false;
51
+ constructor(options) {
52
+ this.settings = options.settings;
53
+ this.mode = options.mode;
54
+ this.rows = options.rows;
55
+ this.requestRender = options.requestRender;
56
+ this.onClose = options.onClose;
57
+ if (this.mode === "setup") {
58
+ this.intro = "Welcome to nexo. Pick the two models it works with (s1 for most work, s2 for harder steps) and enter their provider's API key.";
59
+ this.view = this.nextSetupStep() ?? this.menuView();
60
+ }
61
+ else {
62
+ this.view = this.menuView();
63
+ }
64
+ }
65
+ listRows() {
66
+ return Math.max(3, Math.min(20, this.rows() - 10));
67
+ }
68
+ show(view) {
69
+ this.view = view;
70
+ this.requestRender();
71
+ }
72
+ setError(error, secret) {
73
+ let text = formatError(toErrorPayload(error));
74
+ if (secret && secret.length >= 4)
75
+ text = text.split(secret).join("•••");
76
+ this.status = { kind: "error", text };
77
+ this.requestRender();
78
+ }
79
+ setInfo(text) {
80
+ this.status = { kind: "info", text: escapeControl(text) };
81
+ this.requestRender();
82
+ }
83
+ close(completed) {
84
+ if (this.closed)
85
+ return;
86
+ this.closed = true;
87
+ this.onClose(completed);
88
+ }
89
+ // Menu
90
+ menuView() {
91
+ let keys = [];
92
+ let views = [];
93
+ try {
94
+ keys = this.settings.keyProviders();
95
+ views = this.settings.settings();
96
+ }
97
+ catch (error) {
98
+ this.setError(error);
99
+ }
100
+ const items = [
101
+ ...keys.map((k) => ({ value: `key:${k.provider}`, label: `${escapeControl(k.provider)} key`, description: escapeControl(keyStatusLabel(k)) })),
102
+ ...views.map((v) => ({ value: `set:${v.key}`, label: escapeControl(v.label), description: settingDescription(v) })),
103
+ ];
104
+ return new PickerView({
105
+ title: "Settings",
106
+ items,
107
+ maxVisible: () => this.listRows(),
108
+ hint: "type to filter · ↑↓ move · enter edit · esc close",
109
+ onPick: (value) => {
110
+ this.status = null;
111
+ if (value.startsWith("key:"))
112
+ this.show(this.keyActionsView(value.slice(4)));
113
+ else
114
+ this.editSetting(value.slice(4));
115
+ },
116
+ onCancel: () => this.close(true),
117
+ });
118
+ }
119
+ backToMenu() {
120
+ this.show(this.menuView());
121
+ }
122
+ // Keys
123
+ keyActionsView(provider) {
124
+ let status;
125
+ try {
126
+ status = this.settings.keyStatus(provider);
127
+ }
128
+ catch (error) {
129
+ this.setError(error);
130
+ return this.menuView();
131
+ }
132
+ const items = [{ value: "set", label: "Set key", description: "masked entry; stored in credentials.json (mode 600)" }];
133
+ if (status.inFile)
134
+ items.push({ value: "remove", label: "Remove key", description: "delete it from credentials.json" });
135
+ items.push({ value: BACK, label: "Back" });
136
+ return new PickerView({
137
+ title: escapeControl(`${provider} key: ${keyStatusLabel(status)}${status.state === "env" && status.envVar ? ` (${status.envVar} wins over the file)` : ""}`),
138
+ items,
139
+ maxVisible: () => 3,
140
+ onPick: (value) => {
141
+ if (value === "set")
142
+ this.show(this.keyEntryView(provider, () => this.backToMenu(), () => this.backToMenu()));
143
+ else if (value === "remove") {
144
+ try {
145
+ const after = this.settings.removeKey(provider);
146
+ this.setInfo(`${provider} key removed; now ${keyStatusLabel(after)}`);
147
+ }
148
+ catch (error) {
149
+ this.setError(error);
150
+ }
151
+ this.backToMenu();
152
+ }
153
+ else
154
+ this.backToMenu();
155
+ },
156
+ onCancel: () => this.backToMenu(),
157
+ });
158
+ }
159
+ keyEntryView(provider, onDone, onCancel) {
160
+ const input = new MaskedInput(style.gray("key> "));
161
+ input.onSubmit = (value) => {
162
+ if (!value.trim()) {
163
+ this.setInfo("No key entered");
164
+ return;
165
+ }
166
+ try {
167
+ const status = this.settings.setKey(provider, value);
168
+ this.setInfo(`${provider} key ${keyStatusLabel(status)}`);
169
+ onDone();
170
+ }
171
+ catch (error) {
172
+ this.setError(error, value.trim());
173
+ }
174
+ };
175
+ input.onCancel = onCancel;
176
+ return new EntryView({
177
+ title: `API key for ${escapeControl(provider)} (input hidden)`,
178
+ hint: "paste or type the key · enter save · esc cancel",
179
+ input,
180
+ });
181
+ }
182
+ // Settings
183
+ editSetting(key) {
184
+ let view;
185
+ try {
186
+ view = this.settings.getSetting(key);
187
+ }
188
+ catch (error) {
189
+ this.setError(error);
190
+ return;
191
+ }
192
+ const type = view.type;
193
+ if (type.kind === "number")
194
+ this.show(this.numberView(view));
195
+ else if (type.kind === "enum")
196
+ this.show(this.enumView(view, type.values));
197
+ else if (type.kind === "boolean" || type.kind === "scorerToggle")
198
+ this.show(this.enumView(view, ON_OFF));
199
+ else if (type.kind === "models")
200
+ this.show(this.modelsView(view));
201
+ else
202
+ this.show(this.modelView(view, () => this.backToMenu(), () => this.backToMenu(), true));
203
+ }
204
+ apply(write) {
205
+ try {
206
+ const after = write();
207
+ this.setInfo(`${after.label} = ${valueText(after)}${after.notice ? ` (${after.notice})` : ""}`);
208
+ return true;
209
+ }
210
+ catch (error) {
211
+ this.setError(error);
212
+ return false;
213
+ }
214
+ }
215
+ numberView(view) {
216
+ return this.textView(view, "enter save · empty resets to the default · esc back");
217
+ }
218
+ /** A list of models typed as `provider/id`, several joined with `+`. */
219
+ modelsView(view) {
220
+ return this.textView(view, "provider/id, several joined with + · enter save · empty resets · esc back");
221
+ }
222
+ textView(view, hint) {
223
+ const input = new Input({ prompt: style.gray("> ") });
224
+ input.setValue(view.userValue === null ? "" : String(view.userValue));
225
+ input.onSubmit = (raw) => {
226
+ const ok = raw.trim() === "" ? this.apply(() => this.settings.resetSetting(view.key)) : this.apply(() => this.settings.setSettingFromString(view.key, raw.trim()));
227
+ if (ok)
228
+ this.backToMenu();
229
+ };
230
+ input.onEscape = () => this.backToMenu();
231
+ return new EntryView({
232
+ title: `${escapeControl(view.label)}: ${escapeControl(view.description)} (now ${settingDescription(view)})`,
233
+ hint,
234
+ input,
235
+ });
236
+ }
237
+ enumView(view, values) {
238
+ const items = values.map((v) => ({ value: v, label: escapeControl(v), description: v === view.value ? "current" : undefined }));
239
+ items.push({ value: RESET, label: "reset to default", description: "remove it from your user config" });
240
+ return new PickerView({
241
+ title: `${escapeControl(view.label)}: ${escapeControl(view.description)}`,
242
+ items,
243
+ maxVisible: () => this.listRows(),
244
+ onPick: (value) => {
245
+ const ok = value === RESET ? this.apply(() => this.settings.resetSetting(view.key)) : this.apply(() => this.settings.setSetting(view.key, value));
246
+ if (ok)
247
+ this.backToMenu();
248
+ },
249
+ onCancel: () => this.backToMenu(),
250
+ });
251
+ }
252
+ modelItems(withReset, roles) {
253
+ const items = roles
254
+ ? [
255
+ { value: "s1", label: "s1", description: "the default model" },
256
+ { value: "s2", label: "s2", description: "the stronger model" },
257
+ ]
258
+ : [];
259
+ try {
260
+ for (const provider of this.settings.modelCatalog()) {
261
+ for (const model of provider.models) {
262
+ items.push({ value: model.ref, label: escapeControl(model.ref), description: escapeControl(`${model.name} · ${Math.round(model.contextWindow / 1000)}k ctx`) });
263
+ }
264
+ }
265
+ }
266
+ catch (error) {
267
+ this.setError(error);
268
+ }
269
+ if (withReset)
270
+ items.push({ value: RESET, label: "reset to default", description: "remove it from your user config" });
271
+ return items;
272
+ }
273
+ modelView(view, onDone, onCancel, withReset) {
274
+ return new PickerView({
275
+ title: escapeControl(`${this.mode === "setup" ? `Choose ${view.label.toLowerCase()}` : view.label}: ${view.description}`),
276
+ items: this.modelItems(withReset, view.type.kind === "modelOrRef"),
277
+ freeText: true,
278
+ maxVisible: () => this.listRows(),
279
+ hint: "type to filter or enter provider/model-id · enter select · esc back",
280
+ onPick: (value) => {
281
+ const ok = value === RESET ? this.apply(() => this.settings.resetSetting(view.key)) : this.apply(() => this.settings.setSetting(view.key, value));
282
+ if (ok)
283
+ onDone();
284
+ },
285
+ onCancel,
286
+ });
287
+ }
288
+ // First-run setup
289
+ skippedKeys = new Set();
290
+ nextSetupStep() {
291
+ const status = this.settings.setupStatus();
292
+ if (status.error) {
293
+ this.status = { kind: "error", text: formatError(status.error) };
294
+ return null;
295
+ }
296
+ const role = status.missingModels[0];
297
+ if (role) {
298
+ let view;
299
+ try {
300
+ view = this.settings.getSetting(`models.${role}`);
301
+ }
302
+ catch (error) {
303
+ this.setError(error);
304
+ return null;
305
+ }
306
+ return this.modelView(view, () => this.advanceSetup(), () => this.close(false), false);
307
+ }
308
+ const provider = status.providersWithoutKey.find((p) => !this.skippedKeys.has(p));
309
+ if (provider) {
310
+ return this.keyEntryView(provider, () => this.advanceSetup(), () => {
311
+ this.skippedKeys.add(provider);
312
+ this.setInfo(`Skipped the ${provider} key (fine for keyless or local providers)`);
313
+ this.advanceSetup();
314
+ });
315
+ }
316
+ return null;
317
+ }
318
+ advanceSetup() {
319
+ const next = this.nextSetupStep();
320
+ if (next)
321
+ this.show(next);
322
+ else
323
+ this.close(true);
324
+ }
325
+ handleInput(data) {
326
+ if (this.closed)
327
+ return;
328
+ this.view.handleInput(data);
329
+ this.requestRender();
330
+ }
331
+ render(width) {
332
+ const title = this.view.title;
333
+ const lines = [""];
334
+ lines.push(truncateToWidth(style.bold(style.cyan(this.mode === "setup" ? "nexo setup" : "Settings")), width));
335
+ if (this.intro)
336
+ lines.push(truncateToWidth(style.gray(this.intro), width));
337
+ if (title !== "Settings")
338
+ lines.push(truncateToWidth(style.bold(title), width));
339
+ lines.push(...this.view.render(width));
340
+ if (this.status)
341
+ lines.push(truncateToWidth(this.status.kind === "error" ? style.red(this.status.text) : style.green(this.status.text), width));
342
+ lines.push(truncateToWidth(style.gray(this.view.hint), width));
343
+ return fitLines(lines, width);
344
+ }
345
+ invalidate() { }
346
+ }
@@ -0,0 +1,70 @@
1
+ /** Bidi overrides and isolates, and zero-width characters: invisible, but they reorder or hide text. */
2
+ const INVISIBLE = "\u200b-\u200f\u202a-\u202e\u2060-\u2069\ufeff";
3
+ const CONTROL = new RegExp(`[\u0000-\u001f\u007f-\u009f${INVISIBLE}]`, "g");
4
+ const CONTROL_EXCEPT_LINES = new RegExp(`[\u0000-\u0008\u000b-\u001f\u007f-\u009f${INVISIBLE}]`, "g");
5
+ function visible(c) {
6
+ const code = c.charCodeAt(0);
7
+ return code <= 0xff ? `\\x${code.toString(16).padStart(2, "0")}` : `\\u${code.toString(16).padStart(4, "0")}`;
8
+ }
9
+ /** Replaces control characters (ANSI escapes, carriage returns, newlines) and bidi/zero-width characters with visible text. */
10
+ export function escapeControl(text) {
11
+ return text.replace(CONTROL, visible);
12
+ }
13
+ /** Like `escapeControl`, but keeps newlines and tabs (for multi-line agent text). */
14
+ export function escapeControlKeepLines(text) {
15
+ return text.replace(/\r\n/g, "\n").replace(CONTROL_EXCEPT_LINES, visible);
16
+ }
17
+ /** Collapses text to one line and cuts it to `max` characters. */
18
+ export function oneLine(text, max) {
19
+ const flat = text.replace(/\s+/g, " ").trim();
20
+ return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat;
21
+ }
22
+ const SUBJECT_KEY = { bash: "command", read: "path", write: "path", edit: "path", web_fetch: "url", load_skill: "name" };
23
+ /** `tool(args)` summary: the tool's subject argument when it has one, otherwise compact JSON; control-escaped. */
24
+ export function toolSummary(toolName, args, max = 80) {
25
+ let subject;
26
+ const key = SUBJECT_KEY[toolName];
27
+ const record = typeof args === "object" && args !== null ? args : null;
28
+ if (key && record && typeof record[key] === "string")
29
+ subject = record[key];
30
+ else if (toolName === "spawn" && record && Array.isArray(record.tasks)) {
31
+ const ids = record.tasks.map((t) => (t && typeof t === "object" && typeof t.id === "string" ? t.id : "?"));
32
+ subject = `${ids.length} task${ids.length === 1 ? "" : "s"}: ${ids.join(", ")}`;
33
+ }
34
+ else {
35
+ try {
36
+ subject = JSON.stringify(args ?? {}) ?? "";
37
+ }
38
+ catch {
39
+ subject = "…";
40
+ }
41
+ }
42
+ return `${escapeControl(toolName)}(${escapeControl(oneLine(subject, max))})`;
43
+ }
44
+ /** The non-empty lines of a tool result, control-escaped. */
45
+ export function resultLines(output) {
46
+ return output
47
+ .split(/\r?\n/)
48
+ .map((l) => l.trimEnd())
49
+ .filter((l) => l.length > 0)
50
+ .map((l) => escapeControl(l.replace(/\t/g, " ")));
51
+ }
52
+ /** The first `maxLines` non-empty lines of a tool result, control-escaped. */
53
+ export function previewLines(preview, maxLines = 3) {
54
+ const lines = resultLines(preview);
55
+ const out = lines.slice(0, maxLines);
56
+ if (lines.length > maxLines)
57
+ out.push(`… ${lines.length - maxLines} more line${lines.length - maxLines === 1 ? "" : "s"} (ctrl+o to expand)`);
58
+ return out;
59
+ }
60
+ export function usd(value) {
61
+ return `$${value.toFixed(2)}`;
62
+ }
63
+ export function duration(ms) {
64
+ return ms < 1000 ? `${Math.round(ms)}ms` : `${(ms / 1000).toFixed(1)}s`;
65
+ }
66
+ /** `error [CODE] message — hint`, control-escaped. */
67
+ export function formatError(error) {
68
+ const hint = error.hint ? ` — ${error.hint}` : "";
69
+ return escapeControl(`error [${error.code}] ${error.message}${hint}`);
70
+ }
@@ -0,0 +1,44 @@
1
+ const sgr = (open, close) => (text) => `\x1b[${open}m${text}\x1b[${close}m`;
2
+ export const style = {
3
+ bold: sgr("1", "22"),
4
+ dim: sgr("2", "22"),
5
+ italic: sgr("3", "23"),
6
+ underline: sgr("4", "24"),
7
+ strike: sgr("9", "29"),
8
+ red: sgr("31", "39"),
9
+ green: sgr("32", "39"),
10
+ yellow: sgr("33", "39"),
11
+ blue: sgr("34", "39"),
12
+ magenta: sgr("35", "39"),
13
+ cyan: sgr("36", "39"),
14
+ gray: sgr("90", "39"),
15
+ };
16
+ export const markdownTheme = {
17
+ heading: (t) => style.bold(style.cyan(t)),
18
+ link: style.underline,
19
+ linkUrl: style.gray,
20
+ code: style.yellow,
21
+ codeBlock: (t) => t,
22
+ codeBlockBorder: style.gray,
23
+ quote: style.italic,
24
+ quoteBorder: style.gray,
25
+ hr: style.gray,
26
+ listBullet: style.cyan,
27
+ bold: style.bold,
28
+ italic: style.italic,
29
+ strikethrough: style.strike,
30
+ underline: style.underline,
31
+ };
32
+ export const selectListTheme = {
33
+ selectedPrefix: style.cyan,
34
+ selectedText: (t) => style.bold(style.cyan(t)),
35
+ description: style.gray,
36
+ scrollInfo: style.gray,
37
+ noMatch: style.gray,
38
+ };
39
+ /** Editor border and footer color while the input is a `!` shell command. */
40
+ export const shellBorder = style.magenta;
41
+ export const editorTheme = {
42
+ borderColor: style.dim,
43
+ selectList: selectListTheme,
44
+ };
@@ -0,0 +1,25 @@
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 · cost</title>
8
+ <link rel="stylesheet" href="/style.css">
9
+ <script type="module" src="/lib/theme.ts"></script>
10
+ <script type="module" src="/pages/cost.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>Cost</h1>
17
+ <form id="cost-form" class="filters">
18
+ <label>Group by <select name="by" id="cost-by"></select></label>
19
+ <label>Since <input name="since" type="date"></label>
20
+ <button type="submit">Apply</button>
21
+ </form>
22
+ <div id="cost-table"></div>
23
+ </main>
24
+ </body>
25
+ </html>
@@ -0,0 +1,39 @@
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 · runs</title>
8
+ <link rel="stylesheet" href="/style.css">
9
+ <script type="module" src="/lib/theme.ts"></script>
10
+ <script type="module" src="/pages/runs.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>Runs</h1>
17
+ <div id="session-filter"></div>
18
+ <div class="tabs" role="tablist">
19
+ <button type="button" role="tab" data-tab="all" aria-selected="true">All runs</button>
20
+ <button type="button" role="tab" data-tab="review" aria-selected="false">Review queue</button>
21
+ </div>
22
+ <form id="filters" class="filters">
23
+ <label>Status <select name="status" id="status-filter"><option value="">any</option></select></label>
24
+ <label>Skill <input name="skill" type="text" placeholder="any"></label>
25
+ <label>Since <input name="since" type="date"></label>
26
+ <label>Scored <select name="scored"><option value="">any</option><option value="true">scored</option><option value="false">not scored</option></select></label>
27
+ <button type="submit">Apply</button>
28
+ </form>
29
+ <div id="error"></div>
30
+ <div class="table-wrap">
31
+ <table class="runs">
32
+ <thead><tr><th>Started (UTC)</th><th>Instruction</th><th>Skill</th><th>Status</th><th>Model</th><th class="num">Duration</th><th class="num">Cost</th><th>Score</th><th>Verdict</th></tr></thead>
33
+ <tbody id="runs-body"></tbody>
34
+ </table>
35
+ </div>
36
+ <div id="pager"></div>
37
+ </main>
38
+ </body>
39
+ </html>
@@ -0,0 +1,21 @@
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 · judge</title>
8
+ <link rel="stylesheet" href="/style.css">
9
+ <script type="module" src="/lib/theme.ts"></script>
10
+ <script type="module" src="/pages/judge.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>Judge calibration</h1>
17
+ <div id="error"></div>
18
+ <div id="calibration"></div>
19
+ </main>
20
+ </body>
21
+ </html>
@@ -0,0 +1,46 @@
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 · learning</title>
8
+ <link rel="stylesheet" href="/style.css">
9
+ <script type="module" src="/lib/theme.ts"></script>
10
+ <script type="module" src="/pages/learning.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>Learning</h1>
17
+ <div id="error"></div>
18
+ <section>
19
+ <h2>Memories</h2>
20
+ <form id="memory-filters" class="filters">
21
+ <label>Scope <input name="scope" placeholder="user, global or skill:name"></label>
22
+ <label>Type <select name="type"><option value="">any</option><option>fact</option><option>preference</option><option>lesson</option><option>workflow</option></select></label>
23
+ <label><input type="checkbox" name="all"> include replaced and retired</label>
24
+ <button type="submit">Filter</button>
25
+ </form>
26
+ <div id="memories"></div>
27
+ <div id="memories-pager"></div>
28
+ <div id="memory-history"></div>
29
+ </section>
30
+ <section>
31
+ <h2>Playbooks</h2>
32
+ <div id="playbooks"></div>
33
+ <div id="playbook"></div>
34
+ </section>
35
+ <section>
36
+ <h2>Learn jobs</h2>
37
+ <div id="jobs"></div>
38
+ <div id="jobs-pager"></div>
39
+ </section>
40
+ <section>
41
+ <h2>Judge calibration</h2>
42
+ <p>How often the judge agrees with your verdicts: <a href="/judge.html">Judge calibration</a>.</p>
43
+ </section>
44
+ </main>
45
+ </body>
46
+ </html>