@hexdecimal16/nexo 0.2.0 → 0.2.2
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 +3 -0
- package/cli/src/common.js +4 -2
- package/cli/src/main.js +9 -1
- package/cli/src/optimize.js +2 -2
- package/cli/src/update.js +78 -0
- package/cli/src/version.js +19 -0
- package/core/src/engine/run.js +16 -2
- package/core/src/optimize/optimize.js +8 -0
- package/optimize/src/proposer.js +2 -0
- package/optimize/src/target.js +2 -0
- package/package.json +1 -1
- package/store/src/db.js +26 -8
- package/store/src/eval-cases.js +6 -2
- package/store/src/migrations/009_tool_description_artifacts.sql +22 -0
- package/tools/src/descriptions.js +11 -0
- package/tools/src/index.js +1 -0
- package/tui/src/app.js +17 -0
- package/tui/src/commands.js +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# nexo
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@hexdecimal16/nexo)
|
|
4
|
+
[](https://github.com/hexdecimal16/nexo/actions/workflows/test.yml)
|
|
5
|
+
|
|
3
6
|
An AI agent engine that runs on your machine. It tracks what each run costs, scores the results, and keeps every run inspectable. Use it from the terminal, from a web run inspector, or from Node code.
|
|
4
7
|
|
|
5
8
|
Requires Node 22.19 or newer.
|
package/cli/src/common.js
CHANGED
|
@@ -6,6 +6,7 @@ export const USAGE = `Usage:
|
|
|
6
6
|
without --workspace each turn works in its own run folder (files carried over
|
|
7
7
|
from the previous turn); --workspace . works in the current folder
|
|
8
8
|
nexo sessions [--limit <n>]
|
|
9
|
+
nexo --version print the installed version
|
|
9
10
|
nexo settings open the settings screen (needs a terminal)
|
|
10
11
|
nexo settings get <key>
|
|
11
12
|
nexo settings set <key> <value> keys: models.s1|s2|judge|reflector|embedding, budgets.*, tools.policy.*, tools.autoApprove, tools.nonInteractiveAsk, models.approver, scoring.judge, learning.*, memory.*, optimize.minCases|patience|minJudgeKappa|noveltySimilarity|offspringAlpha
|
|
@@ -21,8 +22,8 @@ export const USAGE = `Usage:
|
|
|
21
22
|
nexo eval accept <case-id> [--expected <text>]
|
|
22
23
|
nexo eval dismiss <case-id>
|
|
23
24
|
nexo eval golden revert <case-id>
|
|
24
|
-
nexo optimize --target skill:<name>|system_prompt|planner_prompt|judge_rubric [--budget-usd <n>] [--max-rollouts <n>] [--merge] [--seed <n>]
|
|
25
|
-
nexo optimize climb --target skill:<name>|system_prompt|planner_prompt [--case <id>] [--guards <0-10>] [--budget-usd <n>] [--seed <n>]
|
|
25
|
+
nexo optimize --target skill:<name>|tool:<name>|system_prompt|planner_prompt|judge_rubric [--budget-usd <n>] [--max-rollouts <n>] [--merge] [--seed <n>]
|
|
26
|
+
nexo optimize climb --target skill:<name>|tool:<name>|system_prompt|planner_prompt [--case <id>] [--guards <0-10>] [--budget-usd <n>] [--seed <n>]
|
|
26
27
|
nexo optimize list
|
|
27
28
|
nexo optimize show <id> [--diff]
|
|
28
29
|
nexo optimize approve <id> promote the best candidate (refused on weak evidence)
|
|
@@ -36,6 +37,7 @@ export const USAGE = `Usage:
|
|
|
36
37
|
nexo playbook retire <skill> <key>
|
|
37
38
|
nexo init [--yes] [--s1 <provider/id>] [--s2 <provider/id>] [--skip-test] guided first-time setup with a test call
|
|
38
39
|
nexo doctor [--json] check Node, config, keys and the data directory (exit 1 on a failure)
|
|
40
|
+
nexo update check npm for a newer version and print the install command
|
|
39
41
|
nexo ui [--port <n>]
|
|
40
42
|
`;
|
|
41
43
|
export const EXIT_SIGINT = 130;
|
package/cli/src/main.js
CHANGED
|
@@ -15,6 +15,8 @@ import { interactiveCommand, settingsScreenCommand } from "./interactive.js";
|
|
|
15
15
|
import { sessionsCommand } from "./sessions.js";
|
|
16
16
|
import { doctorCommand } from "./doctor.js";
|
|
17
17
|
import { initCommand } from "./init.js";
|
|
18
|
+
import { updateCommand } from "./update.js";
|
|
19
|
+
import { nexoVersion } from "./version.js";
|
|
18
20
|
import { settingsCommand } from "./settings.js";
|
|
19
21
|
import { escapeControl } from "../../tui/src/index.js";
|
|
20
22
|
import { runUi } from "./ui.js";
|
|
@@ -210,7 +212,7 @@ export async function runCli(argv, io, options = {}) {
|
|
|
210
212
|
const [command, ...rest] = argv;
|
|
211
213
|
const stdio = options.stdio ?? process;
|
|
212
214
|
try {
|
|
213
|
-
if (command === undefined || (command.startsWith("-") && command !== "--help" && command !== "-h")) {
|
|
215
|
+
if (command === undefined || (command.startsWith("-") && command !== "--help" && command !== "-h" && command !== "--version" && command !== "-v")) {
|
|
214
216
|
return await interactiveCommand(argv, io, options, stdio);
|
|
215
217
|
}
|
|
216
218
|
switch (command) {
|
|
@@ -234,6 +236,8 @@ export async function runCli(argv, io, options = {}) {
|
|
|
234
236
|
return doctorCommand(rest, io, options);
|
|
235
237
|
case "init":
|
|
236
238
|
return await initCommand(rest, io, options, stdio);
|
|
239
|
+
case "update":
|
|
240
|
+
return await updateCommand(io, options);
|
|
237
241
|
case "sessions":
|
|
238
242
|
return sessionsCommand(rest, io, options);
|
|
239
243
|
case "settings":
|
|
@@ -247,6 +251,10 @@ export async function runCli(argv, io, options = {}) {
|
|
|
247
251
|
case "-h":
|
|
248
252
|
io.stdout.write(USAGE);
|
|
249
253
|
return 0;
|
|
254
|
+
case "--version":
|
|
255
|
+
case "-v":
|
|
256
|
+
io.stdout.write(`${nexoVersion()}\n`);
|
|
257
|
+
return 0;
|
|
250
258
|
default:
|
|
251
259
|
throw usageError(`Unknown command "${command}"`);
|
|
252
260
|
}
|
package/cli/src/optimize.js
CHANGED
|
@@ -128,7 +128,7 @@ async function runOptimize(args, io, options) {
|
|
|
128
128
|
options: { target: { type: "string" }, "budget-usd": { type: "string" }, "max-rollouts": { type: "string" }, merge: { type: "boolean" }, seed: { type: "string" } },
|
|
129
129
|
});
|
|
130
130
|
if (!values.target)
|
|
131
|
-
throw usageError("nexo optimize needs --target skill:<name>|system_prompt|planner_prompt|judge_rubric");
|
|
131
|
+
throw usageError("nexo optimize needs --target skill:<name>|tool:<name>|system_prompt|planner_prompt|judge_rubric");
|
|
132
132
|
const seed = values.seed === undefined ? undefined : Number(values.seed);
|
|
133
133
|
if (seed !== undefined && !(Number.isInteger(seed) && seed >= 0))
|
|
134
134
|
throw usageError("--seed must be a non-negative integer");
|
|
@@ -171,7 +171,7 @@ export function climbEventLine(event) {
|
|
|
171
171
|
async function runClimb(args, io, options) {
|
|
172
172
|
const { values } = parseArgs({ args, options: { target: { type: "string" }, case: { type: "string" }, guards: { type: "string" }, "budget-usd": { type: "string" }, seed: { type: "string" } } });
|
|
173
173
|
if (!values.target)
|
|
174
|
-
throw usageError("nexo optimize climb needs --target skill:<name>|system_prompt|planner_prompt");
|
|
174
|
+
throw usageError("nexo optimize climb needs --target skill:<name>|tool:<name>|system_prompt|planner_prompt");
|
|
175
175
|
const guards = values.guards === undefined ? undefined : Number(values.guards);
|
|
176
176
|
if (guards !== undefined && !(Number.isInteger(guards) && guards >= 0 && guards <= 10))
|
|
177
177
|
throw usageError("--guards must be an integer from 0 to 10");
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { NexoError } from "../../telemetry/src/index.js";
|
|
4
|
+
import { nexoVersion } from "./version.js";
|
|
5
|
+
const DEFAULT_PACKAGE = "@hexdecimal16/nexo";
|
|
6
|
+
const REGISTRY = "https://registry.npmjs.org";
|
|
7
|
+
const TIMEOUT_MS = 10_000;
|
|
8
|
+
/** The published package name: read from the installed package.json, or the default when running from the repo. */
|
|
9
|
+
function packageName() {
|
|
10
|
+
for (const relative of ["../../package.json", "../package.json"]) {
|
|
11
|
+
try {
|
|
12
|
+
const json = JSON.parse(readFileSync(fileURLToPath(new URL(relative, import.meta.url)), "utf8"));
|
|
13
|
+
if (typeof json.name === "string" && !json.name.startsWith("@nexo" + "/"))
|
|
14
|
+
return json.name;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// not at this location; try the next one
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return DEFAULT_PACKAGE;
|
|
21
|
+
}
|
|
22
|
+
function parse(version) {
|
|
23
|
+
const m = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
24
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
25
|
+
}
|
|
26
|
+
/** Negative when a < b, 0 when equal, positive when a > b; null when either is not x.y.z. */
|
|
27
|
+
export function compareVersions(a, b) {
|
|
28
|
+
const pa = parse(a);
|
|
29
|
+
const pb = parse(b);
|
|
30
|
+
if (!pa || !pb)
|
|
31
|
+
return null;
|
|
32
|
+
for (let i = 0; i < 3; i++) {
|
|
33
|
+
const d = pa[i] - pb[i];
|
|
34
|
+
if (d !== 0)
|
|
35
|
+
return d;
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `nexo update`: compares the installed version with the registry's `latest` dist-tag and prints the command to
|
|
41
|
+
* update. It never installs anything. Exit 0 when up to date or when an update is available, 1 when the registry
|
|
42
|
+
* cannot be reached.
|
|
43
|
+
*/
|
|
44
|
+
export async function updateCommand(io, options = {}) {
|
|
45
|
+
const name = options.name ?? packageName();
|
|
46
|
+
const current = options.current ?? nexoVersion();
|
|
47
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
48
|
+
const signal = AbortSignal.any([AbortSignal.timeout(TIMEOUT_MS), ...(options.signal ? [options.signal] : [])]);
|
|
49
|
+
let latest;
|
|
50
|
+
try {
|
|
51
|
+
const response = await doFetch(`${REGISTRY}/${name.replace("/", "%2f")}/latest`, { signal });
|
|
52
|
+
if (!response.ok)
|
|
53
|
+
throw new Error(`the registry answered HTTP ${response.status}`);
|
|
54
|
+
const body = (await response.json());
|
|
55
|
+
if (typeof body.version !== "string")
|
|
56
|
+
throw new Error("the registry reply has no version");
|
|
57
|
+
latest = body.version;
|
|
58
|
+
}
|
|
59
|
+
catch (cause) {
|
|
60
|
+
throw new NexoError({
|
|
61
|
+
code: "PROVIDER_UNAVAILABLE",
|
|
62
|
+
message: `Could not check ${name} on npm: ${cause.message}`,
|
|
63
|
+
hint: `Check your connection, or run: npm view ${name} version`,
|
|
64
|
+
cause,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const order = compareVersions(current, latest);
|
|
68
|
+
if (order === null) {
|
|
69
|
+
io.stdout.write(`Installed: ${current}, latest: ${latest}\nRun: npm install -g ${name}@latest\n`);
|
|
70
|
+
}
|
|
71
|
+
else if (order >= 0) {
|
|
72
|
+
io.stdout.write(`nexo ${current} is up to date (latest on npm: ${latest}).\n`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
io.stdout.write(`Update available: ${current} -> ${latest}\nRun: npm install -g ${name}@latest\n`);
|
|
76
|
+
}
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
/**
|
|
4
|
+
* nexo's version. In the repo it is packages/cli/package.json (one level above src); in the published package the
|
|
5
|
+
* compiled file sits in cli/src and the package.json is at the package root (two levels above).
|
|
6
|
+
*/
|
|
7
|
+
export function nexoVersion() {
|
|
8
|
+
for (const relative of ["../package.json", "../../package.json"]) {
|
|
9
|
+
try {
|
|
10
|
+
const json = JSON.parse(readFileSync(fileURLToPath(new URL(relative, import.meta.url)), "utf8"));
|
|
11
|
+
if (typeof json.version === "string")
|
|
12
|
+
return json.version;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// not at this location; try the next one
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return "unknown";
|
|
19
|
+
}
|
package/core/src/engine/run.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createModelRegistry, DEFAULT_ROUTER_POLICY, ESCALATION_BLOCK_REASONS, e
|
|
|
4
4
|
import { createLoadSkillTool, formatSkillIndex, parseSkillFile } from "../../../skills/src/index.js";
|
|
5
5
|
import { createArtifactSet, enqueueLearnJob, getActiveArtifact, insertRun, isPidAlive, listPlaybookItems, listSpans, newId, recoverCrashedRuns, resolveSourcedArtifact, RunDir, sessionRunDirs, updateRun, } from "../../../store/src/index.js";
|
|
6
6
|
import { NexoError, toErrorPayload } from "../../../telemetry/src/index.js";
|
|
7
|
-
import { createBuiltinTools, createChangeTracker, createPolicy, FileLeases, TOOL_OUTPUT_PREFIX, } from "../../../tools/src/index.js";
|
|
7
|
+
import { builtinToolDescriptions, createBuiltinTools, createChangeTracker, createPolicy, FileLeases, TOOL_OUTPUT_PREFIX, } from "../../../tools/src/index.js";
|
|
8
8
|
import { realpathSync, statSync } from "node:fs";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import { createApprovalClassifier } from "../approval/classifier.js";
|
|
@@ -254,6 +254,8 @@ export async function executeRun(env, input) {
|
|
|
254
254
|
};
|
|
255
255
|
let systemPromptText = DEFAULT_SYSTEM_PROMPT;
|
|
256
256
|
let plannerPromptText = DEFAULT_PLANNER_PROMPT;
|
|
257
|
+
/** Descriptions that replace a built-in tool's own: the rollout's candidate, else a promoted version. Empty for a normal run. */
|
|
258
|
+
const toolDescriptionOverrides = new Map();
|
|
257
259
|
/** The `--skill` skill with the body this run uses. */
|
|
258
260
|
let runSkill = skill;
|
|
259
261
|
const recorder = new Recorder({ db, runDir, runId, now, redact: deps.redact });
|
|
@@ -318,6 +320,16 @@ export async function executeRun(env, input) {
|
|
|
318
320
|
runSkill = effective.skill;
|
|
319
321
|
snapshot(effective.artifact, effective.skill.content, `skills/${skill.name}/SKILL.md`);
|
|
320
322
|
}
|
|
323
|
+
for (const toolName of Object.keys(builtinToolDescriptions())) {
|
|
324
|
+
const candidate = rolloutCandidate && rolloutCandidate.kind === "tool_description" && rolloutCandidate.name === toolName ? rolloutCandidate : undefined;
|
|
325
|
+
const version = candidate ?? getActiveArtifact(db, "tool_description", toolName);
|
|
326
|
+
// A manual version mirrors the built-in text, so only a promoted or candidate version changes what the agent sees.
|
|
327
|
+
if (!version || (version.origin === "manual" && !candidate))
|
|
328
|
+
continue;
|
|
329
|
+
snapshot(version, version.content, `tools/${toolName}.md`);
|
|
330
|
+
if (version.origin !== "manual")
|
|
331
|
+
toolDescriptionOverrides.set(toolName, version.content);
|
|
332
|
+
}
|
|
321
333
|
if (skill && startPlaybook?.content.trim()) {
|
|
322
334
|
members.push({ kind: "playbook", name: skill.name, artifactId: startPlaybook.id, version: startPlaybook.version });
|
|
323
335
|
runDir.writeArtifact(`playbooks/${skill.name}.md`, startPlaybook.content);
|
|
@@ -568,7 +580,9 @@ export async function executeRun(env, input) {
|
|
|
568
580
|
baseTools.push(...factory(toolCtx));
|
|
569
581
|
if (deps.mcp)
|
|
570
582
|
baseTools.push(...(await deps.mcp.tools()));
|
|
571
|
-
const tools = baseTools
|
|
583
|
+
const tools = baseTools
|
|
584
|
+
.map((t) => (toolDescriptionOverrides.has(t.name) ? { ...t, description: toolDescriptionOverrides.get(t.name) } : t))
|
|
585
|
+
.map(withToolErrorCodes);
|
|
572
586
|
// Retrieval at run start (spec §8.3); the query embedding is charged to this run like any of its calls.
|
|
573
587
|
memoryDeps = {
|
|
574
588
|
env,
|
|
@@ -11,6 +11,7 @@ import { createEngineEnv } from "../engine/run.js";
|
|
|
11
11
|
import { judgeKey, judgeModels, loadJudgeRubric } from "../scoring/sources.js";
|
|
12
12
|
import { mineQuietly } from "./mine.js";
|
|
13
13
|
import { readScratchpad, writeScratchpad } from "./scratchpad-wiki.js";
|
|
14
|
+
import { builtinToolDescriptions } from "../../../tools/src/index.js";
|
|
14
15
|
import { assertReflectionFits } from "./reflect.js";
|
|
15
16
|
import { createOptimAdapter } from "./adapter.js";
|
|
16
17
|
import { closeOptimizerRun, openOptimizerRun } from "./optimizer-run.js";
|
|
@@ -32,6 +33,13 @@ export function baseVersion(env, target, nowIso) {
|
|
|
32
33
|
return resolveSourcedArtifact(db, "system_prompt", "default", redact(DEFAULT_SYSTEM_PROMPT), nowIso);
|
|
33
34
|
case "planner_prompt":
|
|
34
35
|
return resolveSourcedArtifact(db, "planner_prompt", "default", redact(DEFAULT_PLANNER_PROMPT), nowIso);
|
|
36
|
+
case "tool_description": {
|
|
37
|
+
const description = builtinToolDescriptions()[target.name];
|
|
38
|
+
if (description === undefined) {
|
|
39
|
+
throw new NexoError({ code: "INVALID_REQUEST", message: `Unknown built-in tool "${target.name}"`, hint: `Available: ${Object.keys(builtinToolDescriptions()).join(", ")}` });
|
|
40
|
+
}
|
|
41
|
+
return resolveSourcedArtifact(db, "tool_description", target.name, redact(description), nowIso);
|
|
42
|
+
}
|
|
35
43
|
case "judge_rubric":
|
|
36
44
|
return loadJudgeRubric(db, config, nowIso, redact).artifact;
|
|
37
45
|
}
|
package/optimize/src/proposer.js
CHANGED
|
@@ -28,6 +28,8 @@ function describe(target) {
|
|
|
28
28
|
return "the agent's system prompt ({{workspace}} is replaced by the workspace path; keep that placeholder)";
|
|
29
29
|
case "planner_prompt":
|
|
30
30
|
return "the planner prompt that tells the agent when and how to split work into parallel subagents";
|
|
31
|
+
case "tool_description":
|
|
32
|
+
return `the description of the tool "${target.name}", which the agent reads when it decides whether and how to call the tool (the tool's name and parameters are fixed; describe only what it does, when to use it and its limits)`;
|
|
31
33
|
case "judge_rubric":
|
|
32
34
|
return "the rubric an LLM judge grades the agent's work against; each example shows the judge's verdict next to the human's done / not done verdict, which is the ground truth";
|
|
33
35
|
}
|
package/optimize/src/target.js
CHANGED
package/package.json
CHANGED
package/store/src/db.js
CHANGED
|
@@ -4,6 +4,8 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { NexoError } from "../../telemetry/src/index.js";
|
|
6
6
|
const MIGRATIONS_DIR = fileURLToPath(new URL("./migrations/", import.meta.url));
|
|
7
|
+
/** A migration whose first line is this marker rebuilds a table that others reference: it runs with foreign keys off and is checked with foreign_key_check before it commits. */
|
|
8
|
+
const FK_OFF_MARKER = "-- nexo:foreign-keys-off";
|
|
7
9
|
export function openDb(path) {
|
|
8
10
|
try {
|
|
9
11
|
if (path !== ":memory:")
|
|
@@ -41,14 +43,30 @@ export function migrate(db) {
|
|
|
41
43
|
for (const file of files) {
|
|
42
44
|
const version = Number(file.slice(0, 3));
|
|
43
45
|
const sql = readFileSync(join(MIGRATIONS_DIR, file), "utf8");
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const fkOff = sql.startsWith(FK_OFF_MARKER);
|
|
47
|
+
// PRAGMA foreign_keys is a no-op inside a transaction, so it is switched outside it.
|
|
48
|
+
if (fkOff)
|
|
49
|
+
db.exec("PRAGMA foreign_keys = OFF");
|
|
50
|
+
let ran;
|
|
51
|
+
try {
|
|
52
|
+
ran = transaction(db, () => {
|
|
53
|
+
const current = Number(db.prepare("SELECT COALESCE(MAX(version), 0) AS v FROM schema_migrations").get()?.v ?? 0);
|
|
54
|
+
if (version <= current)
|
|
55
|
+
return false;
|
|
56
|
+
db.exec(sql);
|
|
57
|
+
if (fkOff) {
|
|
58
|
+
const broken = db.prepare("PRAGMA foreign_key_check").all();
|
|
59
|
+
if (broken.length > 0)
|
|
60
|
+
throw new Error(`Migration ${file} left ${broken.length} foreign key violations`);
|
|
61
|
+
}
|
|
62
|
+
db.prepare("INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)").run(version, file, new Date().toISOString());
|
|
63
|
+
return true;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
if (fkOff)
|
|
68
|
+
db.exec("PRAGMA foreign_keys = ON");
|
|
69
|
+
}
|
|
52
70
|
if (ran)
|
|
53
71
|
applied.push(version);
|
|
54
72
|
}
|
package/store/src/eval-cases.js
CHANGED
|
@@ -12,6 +12,7 @@ export const MAX_EVAL_INPUT_CHARS = 20_000;
|
|
|
12
12
|
/** Most runs listed when an eval set is too small or a promotion needs more human verdicts. */
|
|
13
13
|
export const RUNS_TO_REVIEW = 10;
|
|
14
14
|
const SKILL_TARGET = /^skill:([a-z0-9]+(-[a-z0-9]+)*)$/;
|
|
15
|
+
const TOOL_TARGET = /^tool:([a-z][a-z0-9_]{0,63})$/;
|
|
15
16
|
/**
|
|
16
17
|
* Parses an optimization target. `router_policy` is refused: it is a JSON policy of numeric thresholds, not prose.
|
|
17
18
|
* Throws INVALID_REQUEST.
|
|
@@ -20,12 +21,15 @@ export function parseOptimTarget(text) {
|
|
|
20
21
|
const skill = SKILL_TARGET.exec(text);
|
|
21
22
|
if (skill && skill[1].length <= 64)
|
|
22
23
|
return { key: text, kind: "skill", name: skill[1] };
|
|
24
|
+
const tool = TOOL_TARGET.exec(text);
|
|
25
|
+
if (tool)
|
|
26
|
+
return { key: text, kind: "tool_description", name: tool[1] };
|
|
23
27
|
if (text === "system_prompt" || text === "planner_prompt" || text === "judge_rubric")
|
|
24
28
|
return { key: text, kind: text, name: "default" };
|
|
25
29
|
if (text === "router_policy") {
|
|
26
|
-
throw invalidRequest("router_policy is not an optimization target yet: it is a JSON policy of numeric thresholds, not prose, and evaluating one needs S2 escalation rollouts on every case", { target: text }, "Optimize skill:<name>, system_prompt, planner_prompt or judge_rubric; edit router thresholds with router.policy = file:<path>");
|
|
30
|
+
throw invalidRequest("router_policy is not an optimization target yet: it is a JSON policy of numeric thresholds, not prose, and evaluating one needs S2 escalation rollouts on every case", { target: text }, "Optimize skill:<name>, tool:<name>, system_prompt, planner_prompt or judge_rubric; edit router thresholds with router.policy = file:<path>");
|
|
27
31
|
}
|
|
28
|
-
throw invalidRequest(`Unknown optimization target "${text}"`, { target: text }, "Use skill:<name>, system_prompt, planner_prompt or judge_rubric");
|
|
32
|
+
throw invalidRequest(`Unknown optimization target "${text}"`, { target: text }, "Use skill:<name>, tool:<name>, system_prompt, planner_prompt or judge_rubric");
|
|
29
33
|
}
|
|
30
34
|
/** The text a case's split is derived from: trimmed, whitespace collapsed, lower-cased. */
|
|
31
35
|
export function normalizeCaseInput(input) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
-- nexo:foreign-keys-off
|
|
2
|
+
-- Tool descriptions become an optimization target (artifact kind 'tool_description', name = the tool's name).
|
|
3
|
+
-- artifacts is rebuilt because SQLite cannot widen a CHECK in place. optim_runs and optim_candidates reference it,
|
|
4
|
+
-- so the runner switches foreign keys off for this file and runs foreign_key_check before it commits.
|
|
5
|
+
CREATE TABLE artifacts_new (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
kind TEXT NOT NULL CHECK (kind IN ('system_prompt','skill','playbook','router_policy','judge_rubric','planner_prompt','tool_description')),
|
|
8
|
+
name TEXT NOT NULL,
|
|
9
|
+
version INTEGER NOT NULL,
|
|
10
|
+
content TEXT NOT NULL,
|
|
11
|
+
content_hash TEXT NOT NULL,
|
|
12
|
+
parent_version_id TEXT REFERENCES artifacts(id),
|
|
13
|
+
origin TEXT NOT NULL CHECK (origin IN ('manual','ace','gepa')),
|
|
14
|
+
status TEXT NOT NULL CHECK (status IN ('active','candidate','retired')),
|
|
15
|
+
created_at TEXT NOT NULL,
|
|
16
|
+
UNIQUE (kind, name, version)
|
|
17
|
+
);
|
|
18
|
+
INSERT INTO artifacts_new (id, kind, name, version, content, content_hash, parent_version_id, origin, status, created_at)
|
|
19
|
+
SELECT id, kind, name, version, content, content_hash, parent_version_id, origin, status, created_at FROM artifacts;
|
|
20
|
+
DROP TABLE artifacts;
|
|
21
|
+
ALTER TABLE artifacts_new RENAME TO artifacts;
|
|
22
|
+
CREATE UNIQUE INDEX artifacts_one_active ON artifacts(kind, name) WHERE status = 'active';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { tmpdir } from "node:os";
|
|
2
|
+
import { createBuiltinTools } from "./builtin.js";
|
|
3
|
+
import { FileLeases } from "./leases.js";
|
|
4
|
+
/**
|
|
5
|
+
* The built-in tools' own descriptions by tool name: the text an optimization of `tool:<name>` starts from and a run
|
|
6
|
+
* uses when no promoted or candidate description replaces it. Read from the tools themselves, so there is one copy.
|
|
7
|
+
*/
|
|
8
|
+
export function builtinToolDescriptions() {
|
|
9
|
+
const tools = createBuiltinTools({ workspaceRoot: tmpdir(), holder: "descriptions", leases: new FileLeases(), bashTimeoutMs: 1 });
|
|
10
|
+
return Object.fromEntries(tools.map((t) => [t.name, t.description]));
|
|
11
|
+
}
|
package/tools/src/index.js
CHANGED
package/tui/src/app.js
CHANGED
|
@@ -24,6 +24,8 @@ function filesLine(session) {
|
|
|
24
24
|
return `files: ${escapeControl(tildePath(session.runsDir))}/<turn id>/workspace (carried over each turn)`;
|
|
25
25
|
}
|
|
26
26
|
const DOUBLE_CTRL_C_MS = 1000;
|
|
27
|
+
/** Two Esc presses within this window on an idle prompt clear the draft (and keep it in history). */
|
|
28
|
+
const DOUBLE_ESC_MS = 800;
|
|
27
29
|
/** Last lines of a `!` command's output shown in the chat (the model gets more). */
|
|
28
30
|
const SHELL_SCREEN_LINES = 200;
|
|
29
31
|
/** Time given to paint the "opening…" footer before the synchronous session open blocks the loop (one render interval and a margin). */
|
|
@@ -127,6 +129,7 @@ class InteractiveApp {
|
|
|
127
129
|
tickTimer = null;
|
|
128
130
|
loader = null;
|
|
129
131
|
lastCtrlC = Number.NEGATIVE_INFINITY;
|
|
132
|
+
lastEscape = Number.NEGATIVE_INFINITY;
|
|
130
133
|
defaultModel = "";
|
|
131
134
|
/** Model and effort of the running turn's root run, from its run_start and escalation events; null between turns. */
|
|
132
135
|
liveModel = null;
|
|
@@ -361,6 +364,20 @@ class InteractiveApp {
|
|
|
361
364
|
this.turnAbort?.abort();
|
|
362
365
|
return { consume: true };
|
|
363
366
|
}
|
|
367
|
+
if (matchesKey(data, "escape") && !this.running && this.screen === "chat" && this.session && !this.editor.isShowingAutocomplete()) {
|
|
368
|
+
// Idle prompt, like Claude Code: a second Esc clears the draft but saves it to history, so Up brings it back.
|
|
369
|
+
const text = this.editor.getText();
|
|
370
|
+
const now = this.now();
|
|
371
|
+
if (text.trim() !== "" && now - this.lastEscape <= DOUBLE_ESC_MS) {
|
|
372
|
+
this.editor.addToHistory(text.trim());
|
|
373
|
+
this.editor.setText("");
|
|
374
|
+
this.lastEscape = Number.NEGATIVE_INFINITY;
|
|
375
|
+
this.tui.requestRender();
|
|
376
|
+
return { consume: true };
|
|
377
|
+
}
|
|
378
|
+
this.lastEscape = text.trim() !== "" ? now : Number.NEGATIVE_INFINITY;
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
364
381
|
if (matchesKey(data, "ctrl+o") && this.screen === "chat") {
|
|
365
382
|
if (isKeyRepeat(data))
|
|
366
383
|
return { consume: true };
|
package/tui/src/commands.js
CHANGED
|
@@ -33,6 +33,6 @@ export function helpText() {
|
|
|
33
33
|
const width = Math.max(...SLASH_COMMANDS.map((c) => `/${c.name}${c.argumentHint ? ` ${c.argumentHint}` : ""}`.length));
|
|
34
34
|
const lines = SLASH_COMMANDS.map((c) => `${`/${c.name}${c.argumentHint ? ` ${c.argumentHint}` : ""}`.padEnd(width)} ${c.description ?? ""}`);
|
|
35
35
|
lines.push("", `${"!<command>".padEnd(width)} Run a shell command; its output goes to the model with your next message`);
|
|
36
|
-
lines.push("", "enter send · shift+enter newline · ↑↓ history · ctrl+o expand tool output · esc/ctrl-c stop a turn · ctrl-c twice or ctrl-d quit");
|
|
36
|
+
lines.push("", "enter send · shift+enter newline · ↑↓ history · ctrl+o expand tool output · esc/ctrl-c stop a turn · esc twice clears the draft (↑ recalls it) · ctrl-c twice or ctrl-d quit");
|
|
37
37
|
return lines.join("\n");
|
|
38
38
|
}
|