@hexdecimal16/nexo 0.3.5 → 0.4.1
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/README.md +15 -0
- package/cli/src/common.js +6 -1
- package/cli/src/main.js +12 -0
- package/cli/src/review-queue.js +31 -0
- package/cli/src/search.js +50 -0
- package/cli/src/settings.js +20 -1
- package/core/src/config/schema.js +12 -2
- package/core/src/engine/context-trim.js +26 -0
- package/core/src/engine/prompts.js +5 -0
- package/core/src/engine/run.js +68 -2
- package/core/src/engine/spawn-tool.js +5 -1
- package/core/src/optimize/holdout-gate.js +19 -0
- package/core/src/optimize/optimize.js +13 -2
- package/core/src/optimize/reflect.js +1 -1
- package/core/src/settings/config-edit.js +31 -0
- package/core/src/settings/doctor.js +15 -2
- package/core/src/settings/settings.js +29 -10
- package/package.json +1 -1
- package/sdk/src/nexo.js +33 -3
- package/sdk/src/run-tree.js +6 -0
- package/sdk/src/runtime.js +2 -1
- package/store/src/index.js +1 -0
- package/store/src/review-queue.js +46 -0
- package/tools/src/builtin.js +13 -3
- package/tools/src/descriptions.js +2 -1
- package/tools/src/index.js +1 -0
- package/tools/src/policy.js +1 -1
- package/tools/src/web-search.js +251 -0
- package/tui/src/app.js +22 -1
- package/tui/src/commands.js +1 -0
- package/tui/src/index.js +1 -1
- package/tui/src/settings-screen.js +8 -2
- package/tui/src/text.js +1 -1
- package/web/public/lib/api-types.ts +18 -0
- package/web/public/lib/run-view.ts +19 -1
- package/web/public/pages/run.ts +3 -1
- package/web/public/run.html +2 -1
- package/web/src/api.js +32 -0
- package/web/src/review-queue-api.js +18 -0
- package/web/src/server.js +7 -0
package/tui/src/index.js
CHANGED
|
@@ -2,4 +2,4 @@ export { restoreTerminal, runInteractive, runSettingsScreen } from "./app.js";
|
|
|
2
2
|
export { createApprovalPrompter } from "./approvals.js";
|
|
3
3
|
export { runSessionPicker, sessionPickerItems } from "./session-picker.js";
|
|
4
4
|
export { helpText, parseSlashCommand, SLASH_COMMANDS } from "./commands.js";
|
|
5
|
-
export { escapeControl, oneLine } from "./text.js";
|
|
5
|
+
export { escapeControl, escapeControlKeepLines, oneLine } from "./text.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Input, truncateToWidth } from "@earendil-works/pi-tui";
|
|
2
2
|
import { keyStatusLabel, ON_OFF } from "../../core/src/index.js";
|
|
3
3
|
import { toErrorPayload } from "../../telemetry/src/index.js";
|
|
4
|
+
import { isSearchProvider, SEARCH_PROVIDERS } from "../../tools/src/index.js";
|
|
4
5
|
import { fitLines, MaskedInput } from "./components.js";
|
|
5
6
|
import { PickerView } from "./picker.js";
|
|
6
7
|
import { escapeControl, formatError } from "./text.js";
|
|
@@ -98,7 +99,11 @@ export class SettingsScreen {
|
|
|
98
99
|
this.setError(error);
|
|
99
100
|
}
|
|
100
101
|
const items = [
|
|
101
|
-
...keys.map((k) => ({
|
|
102
|
+
...keys.map((k) => ({
|
|
103
|
+
value: `key:${k.provider}`,
|
|
104
|
+
label: `${escapeControl(k.provider)} key${k.purpose === "search" ? " (web search)" : ""}`,
|
|
105
|
+
description: escapeControl(keyStatusLabel(k)),
|
|
106
|
+
})),
|
|
102
107
|
...views.map((v) => ({ value: `set:${v.key}`, label: escapeControl(v.label), description: settingDescription(v) })),
|
|
103
108
|
];
|
|
104
109
|
return new PickerView({
|
|
@@ -129,7 +134,8 @@ export class SettingsScreen {
|
|
|
129
134
|
this.setError(error);
|
|
130
135
|
return this.menuView();
|
|
131
136
|
}
|
|
132
|
-
const
|
|
137
|
+
const signup = isSearchProvider(provider) ? `; get one at ${SEARCH_PROVIDERS[provider].signupUrl}` : "";
|
|
138
|
+
const items = [{ value: "set", label: "Set key", description: `masked entry; stored in credentials.json (mode 600)${signup}` }];
|
|
133
139
|
if (status.inFile)
|
|
134
140
|
items.push({ value: "remove", label: "Remove key", description: "delete it from credentials.json" });
|
|
135
141
|
items.push({ value: BACK, label: "Back" });
|
package/tui/src/text.js
CHANGED
|
@@ -19,7 +19,7 @@ export function oneLine(text, max) {
|
|
|
19
19
|
const flat = text.replace(/\s+/g, " ").trim();
|
|
20
20
|
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat;
|
|
21
21
|
}
|
|
22
|
-
const SUBJECT_KEY = { bash: "command", read: "path", write: "path", edit: "path", web_fetch: "url", load_skill: "name" };
|
|
22
|
+
const SUBJECT_KEY = { bash: "command", read: "path", write: "path", edit: "path", web_fetch: "url", web_search: "query", load_skill: "name" };
|
|
23
23
|
/** `tool(args)` summary: the tool's subject argument when it has one, otherwise compact JSON; control-escaped. */
|
|
24
24
|
export function toolSummary(toolName, args, max = 80) {
|
|
25
25
|
let subject;
|
|
@@ -175,6 +175,24 @@ export interface RunDetailResponse {
|
|
|
175
175
|
escalations: Escalation[];
|
|
176
176
|
/** True when the latest judge verdict and the latest human verdict disagree. */
|
|
177
177
|
judgeDisagrees: boolean;
|
|
178
|
+
/** The memories retrieval chose for this run (or for the session turn whose set it reuses); null when none was recorded. */
|
|
179
|
+
injectedMemories: InjectedMemories | null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface InjectedMemory {
|
|
183
|
+
id: string;
|
|
184
|
+
score: number | null;
|
|
185
|
+
relevance: number | null;
|
|
186
|
+
/** The stored memory; null when it no longer exists. */
|
|
187
|
+
memory: Memory | null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface InjectedMemories {
|
|
191
|
+
/** The run whose `memory_read` span recorded the selection (an earlier turn for later turns of a session). */
|
|
192
|
+
fromRunId: string;
|
|
193
|
+
mode: string | null;
|
|
194
|
+
candidates: number | null;
|
|
195
|
+
items: InjectedMemory[];
|
|
178
196
|
}
|
|
179
197
|
|
|
180
198
|
export interface Span {
|
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import type { Feedback, ReadOnlyInfo, RunDetailResponse, RunStatus, RunSummary } from "./api-types.ts";
|
|
1
|
+
import type { Feedback, InjectedMemories, ReadOnlyInfo, RunDetailResponse, RunStatus, RunSummary } from "./api-types.ts";
|
|
2
2
|
import { renderError, runLink, sessionLink, stateClass, statusBadge, verdictBadge } from "./common-view.ts";
|
|
3
3
|
import { durationMs, formatDuration, formatTime, formatUsd, shortId, truncate } from "./format.ts";
|
|
4
4
|
import { html, type SafeHtml } from "./html.ts";
|
|
5
5
|
|
|
6
|
+
/** The memories injected into the run, with where the selection was recorded and each memory's rank score. */
|
|
7
|
+
export function renderInjectedMemories(data: InjectedMemories | null, runId: string): SafeHtml {
|
|
8
|
+
if (!data) return html`<p class="muted">No memory retrieval was recorded for this run.</p>`;
|
|
9
|
+
const origin = data.fromRunId === runId ? "" : html` Retrieved at an earlier turn of this session: <a href="${runLink(data.fromRunId)}">run ${shortId(data.fromRunId)}</a>.`;
|
|
10
|
+
const facts = html`<p class="muted">${data.mode ? `Mode ${data.mode}. ` : ""}${data.candidates !== null ? `${data.candidates} candidates. ` : ""}${origin}</p>`;
|
|
11
|
+
if (data.items.length === 0) return html`${facts}<p class="muted">Retrieval selected no memories.</p>`;
|
|
12
|
+
return html`${facts}<table class="runs memories">
|
|
13
|
+
<thead><tr><th>Scope</th><th>Type</th><th>Source</th><th>Memory</th><th class="num">Score</th><th class="num">Relevance</th></tr></thead>
|
|
14
|
+
<tbody>${data.items.map(
|
|
15
|
+
(i) => html`<tr>
|
|
16
|
+
<td class="mono">${i.memory?.scope ?? ""}</td><td>${i.memory?.type ?? ""}</td><td>${i.memory?.source ?? ""}</td>
|
|
17
|
+
<td>${i.memory ? i.memory.content : html`<span class="muted mono">${i.id} (no longer in the store)</span>`}${i.memory?.retiredAt ? html` <span class="muted">retired since</span>` : ""}${i.memory?.supersededBy ? html` <span class="muted">replaced since</span>` : ""}</td>
|
|
18
|
+
<td class="num">${i.score === null ? "" : i.score.toFixed(2)}</td><td class="num">${i.relevance === null ? "" : i.relevance.toFixed(2)}</td>
|
|
19
|
+
</tr>`,
|
|
20
|
+
)}</tbody>
|
|
21
|
+
</table>`;
|
|
22
|
+
}
|
|
23
|
+
|
|
6
24
|
export function shouldPoll(status: RunStatus): boolean {
|
|
7
25
|
return status === "running";
|
|
8
26
|
}
|
package/web/public/pages/run.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { renderError } from "../lib/common-view.ts";
|
|
|
12
12
|
import { filePath, mediaKind, renderFile, renderListing, renderMedia } from "../lib/files-view.ts";
|
|
13
13
|
import { html, type SafeHtml } from "../lib/html.ts";
|
|
14
14
|
import { createPoller } from "../lib/poller.ts";
|
|
15
|
-
import { renderChildren, renderFeedbackForm, renderRunHeader, shouldPoll } from "../lib/run-view.ts";
|
|
15
|
+
import { renderChildren, renderFeedbackForm, renderInjectedMemories, renderRunHeader, shouldPoll } from "../lib/run-view.ts";
|
|
16
16
|
import { renderEscalations, renderScores } from "../lib/score-view.ts";
|
|
17
17
|
import { findSpan, renderSpanDetail, renderSpanTree } from "../lib/span-view.ts";
|
|
18
18
|
import { renderTimeline, timelineRows } from "../lib/timeline.ts";
|
|
@@ -23,6 +23,7 @@ const header = el<HTMLElement>("#header");
|
|
|
23
23
|
const review = el<HTMLElement>("#review");
|
|
24
24
|
const scores = el<HTMLElement>("#scores");
|
|
25
25
|
const escalations = el<HTMLElement>("#escalations");
|
|
26
|
+
const injected = el<HTMLElement>("#injected-memories");
|
|
26
27
|
const children = el<HTMLElement>("#children");
|
|
27
28
|
const timeline = el<HTMLElement>("#timeline");
|
|
28
29
|
const tree = el<HTMLElement>("#tree");
|
|
@@ -140,6 +141,7 @@ async function load(): Promise<boolean> {
|
|
|
140
141
|
setHtml(review, renderFeedbackForm(run.run, run.feedback.at(-1), readOnly ?? null));
|
|
141
142
|
setHtml(scores, renderScores(run.scores, run.run.verdict, run.judgeDisagrees));
|
|
142
143
|
setHtml(escalations, renderEscalations(run.escalations));
|
|
144
|
+
setHtml(injected, renderInjectedMemories(run.injectedMemories, run.run.id));
|
|
143
145
|
setHtml(children, renderChildren(run.children, now, readOnly ?? null, run.childFeedback));
|
|
144
146
|
roots = spans.roots;
|
|
145
147
|
setHtml(timeline, renderTimeline(timelineRows(roots, now), selectedSpanId));
|
package/web/public/run.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<a class="skip" href="#main">Skip to content</a>
|
|
15
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>
|
|
16
16
|
<main id="main" tabindex="-1">
|
|
17
|
-
<nav class="run-nav" aria-label="Run sections"><a href="#sec-timeline">Timeline</a><a href="#sec-spans">Spans</a><a href="#sec-scores">Scores</a><a href="#sec-subagents">Subagents</a><a href="#sec-files">Files</a><a href="#sec-review">Review</a></nav>
|
|
17
|
+
<nav class="run-nav" aria-label="Run sections"><a href="#sec-timeline">Timeline</a><a href="#sec-spans">Spans</a><a href="#sec-scores">Scores</a><a href="#sec-memories">Memories</a><a href="#sec-subagents">Subagents</a><a href="#sec-files">Files</a><a href="#sec-review">Review</a></nav>
|
|
18
18
|
<div id="error"></div>
|
|
19
19
|
<div id="header"></div>
|
|
20
20
|
<section id="sec-timeline"><h2>Timeline</h2><div id="timeline"></div></section>
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
<div><h2>Scores</h2><div id="scores"></div></div>
|
|
27
27
|
<div><h2>Escalations</h2><div id="escalations"></div></div>
|
|
28
28
|
</section>
|
|
29
|
+
<section id="sec-memories"><h2>Memories injected</h2><div id="injected-memories"></div></section>
|
|
29
30
|
<section id="sec-subagents"><h2>Subagents</h2><div id="children"></div></section>
|
|
30
31
|
<section class="split" id="sec-files">
|
|
31
32
|
<div><h2>Files</h2><div id="files"></div></div>
|
package/web/src/api.js
CHANGED
|
@@ -105,8 +105,40 @@ export function runDetailResponse(ctx, id) {
|
|
|
105
105
|
scores: listScores(ctx.db, id).map(({ details: { rubric: _rubric, ...details }, ...score }) => ({ ...score, details })),
|
|
106
106
|
escalations: listEscalations(ctx.db, id),
|
|
107
107
|
judgeDisagrees: judgeDisagrees(ctx.db, id),
|
|
108
|
+
injectedMemories: injectedMemories(ctx, run),
|
|
108
109
|
};
|
|
109
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* The memories injected into a run. Retrieval runs once per process, at its first turn, and later turns reuse that set,
|
|
113
|
+
* so for a session turn this looks at the turn itself and then at earlier turns for the latest `memory_read` "retrieve" span.
|
|
114
|
+
*/
|
|
115
|
+
function injectedMemories(ctx, run) {
|
|
116
|
+
const turn = run.turnIndex ?? null;
|
|
117
|
+
const candidates = [run.id];
|
|
118
|
+
if (run.sessionId && turn !== null) {
|
|
119
|
+
const earlier = queryRuns(ctx.db, { sessionId: run.sessionId, limit: MAX_RUN_PAGE })
|
|
120
|
+
.runs.filter((r) => r.id !== run.id && r.turnIndex !== null && r.turnIndex <= turn)
|
|
121
|
+
.sort((a, b) => (b.turnIndex ?? 0) - (a.turnIndex ?? 0));
|
|
122
|
+
candidates.push(...earlier.map((r) => r.id));
|
|
123
|
+
}
|
|
124
|
+
const num = (v) => (typeof v === "number" ? v : null);
|
|
125
|
+
for (const runId of candidates) {
|
|
126
|
+
const span = listSpans(ctx.db, runId).find((s) => s.kind === "memory_read" && s.name === "retrieve");
|
|
127
|
+
if (!span)
|
|
128
|
+
continue;
|
|
129
|
+
const selected = Array.isArray(span.attrs.selected) ? span.attrs.selected : [];
|
|
130
|
+
const items = selected.flatMap((entry) => {
|
|
131
|
+
if (typeof entry !== "object" || entry === null)
|
|
132
|
+
return [];
|
|
133
|
+
const e = entry;
|
|
134
|
+
if (typeof e.id !== "string")
|
|
135
|
+
return [];
|
|
136
|
+
return [{ id: e.id, score: num(e.score), relevance: num(e.relevance), memory: getMemory(ctx.db, e.id) ?? null }];
|
|
137
|
+
});
|
|
138
|
+
return { fromRunId: runId, mode: typeof span.attrs.mode === "string" ? span.attrs.mode : null, candidates: num(span.attrs.candidates), items };
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
110
142
|
/** The run's own `escalation` spans, oldest first. */
|
|
111
143
|
function listEscalations(db, runId) {
|
|
112
144
|
const text = (v) => (typeof v === "string" ? v : null);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { reviewQueue } from "../../store/src/index.js";
|
|
2
|
+
import { NexoError } from "../../telemetry/src/index.js";
|
|
3
|
+
function positiveInt(params, name) {
|
|
4
|
+
const raw = params.get(name);
|
|
5
|
+
if (raw === null || raw === "")
|
|
6
|
+
return undefined;
|
|
7
|
+
const n = Number(raw);
|
|
8
|
+
if (!Number.isInteger(n) || n < 1)
|
|
9
|
+
throw new NexoError({ code: "INVALID_REQUEST", message: `${name} must be a positive integer`, context: { [name]: raw } });
|
|
10
|
+
return n;
|
|
11
|
+
}
|
|
12
|
+
/** `GET /api/review-queue?limit=&days=`: recent runs without a human verdict, worst first. */
|
|
13
|
+
export function reviewQueueResponse(ctx, params) {
|
|
14
|
+
const limit = positiveInt(params, "limit");
|
|
15
|
+
const days = positiveInt(params, "days");
|
|
16
|
+
const items = reviewQueue(ctx.db, { now: ctx.now(), ...(limit ? { limit } : {}), ...(days ? { days } : {}) });
|
|
17
|
+
return { items: items.map((i) => ({ ...i, instruction: String(ctx.redact(i.instruction)) })) };
|
|
18
|
+
}
|
package/web/src/server.js
CHANGED
|
@@ -6,6 +6,7 @@ import { costResponse, evalCasesResponse, reviewEvalCaseResponse, feedbackRespon
|
|
|
6
6
|
import { sendError, sendJson } from "./http-errors.js";
|
|
7
7
|
import { companionAnswer } from "./companion.js";
|
|
8
8
|
import { createStaticServer } from "./static.js";
|
|
9
|
+
import { reviewQueueResponse } from "./review-queue-api.js";
|
|
9
10
|
export const DEFAULT_PUBLIC_DIR = fileURLToPath(new URL("../public/", import.meta.url));
|
|
10
11
|
/** Largest accepted request body (feedback JSON). */
|
|
11
12
|
export const MAX_BODY_BYTES = 64 * 1024;
|
|
@@ -32,6 +33,7 @@ const ROUTES = {
|
|
|
32
33
|
optim: new RegExp(`^/api/optim/${RUN_ID}$`),
|
|
33
34
|
optimApprove: new RegExp(`^/api/optim/${RUN_ID}/approve$`),
|
|
34
35
|
evalCases: /^\/api\/eval-cases$/,
|
|
36
|
+
reviewQueue: /^\/api\/review-queue$/,
|
|
35
37
|
evalCaseReview: new RegExp(`^/api/eval-cases/${RUN_ID}/(accept|dismiss)$`),
|
|
36
38
|
meta: /^\/api\/meta$/,
|
|
37
39
|
companion: /^\/api\/companion\/ask$/,
|
|
@@ -242,6 +244,11 @@ export async function startWebServer(options) {
|
|
|
242
244
|
assertWritable();
|
|
243
245
|
return sendJson(res, 200, approveOptimResponse(ctx, m[1]));
|
|
244
246
|
}
|
|
247
|
+
if (ROUTES.reviewQueue.test(path)) {
|
|
248
|
+
if (method !== "GET")
|
|
249
|
+
throw methodNotAllowed(method, path, "GET");
|
|
250
|
+
return sendJson(res, 200, reviewQueueResponse(ctx, url.searchParams));
|
|
251
|
+
}
|
|
245
252
|
if (ROUTES.evalCases.test(path)) {
|
|
246
253
|
if (method !== "GET")
|
|
247
254
|
throw methodNotAllowed(method, path, "GET");
|