Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions darknode.js
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ const { coderShell } = require("./lib/nexus/shell-run");
// ---------- Nexus documentation (shared by `darknode docs` and the TUI /docs browser) ----------
const NEXUS_DOCS = { __proto__: null,
overview: { title: "Overview", body:
"Nexus is a terminal AI coding agent built into the Darknode CLI. It drives one of six\nengines from a single dependency-free binary:\n claude — the Claude Code CLI in the cloud (strongest; needs `claude` installed + logged in)\n gemini · codex · opencode · aider — those vendors' CLIs, same interface\n ollama — a free, private, local model on your machine (needs Ollama)\n\nIt reads & writes files, runs commands, checkpoints every change, shows real token cost\nlive, saves tokens by delegating cheap work to a weaker/local model, and keeps secrets off\nthe cloud. Launch it with `darknode nexus --tui`. Type / inside for the command menu." },
"Nexus is a terminal AI coding agent built into the Darknode CLI. It drives one of six\nengines from a single dependency-free binary:\n claude — the Claude Code CLI (needs `claude` installed + logged in)\n gemini · codex · opencode · aider — those vendors' CLIs, same interface\n ollama — a free, private, local model on your machine (needs Ollama)\n\nIt reads & writes files, runs commands, checkpoints every change, shows real token cost\nlive, saves tokens by delegating cheap work to a weaker/local model, and keeps secrets off\nthe cloud. Launch it with `darknode nexus --tui`. Type / inside for the command menu." },
quickstart: { title: "Quick start", body:
" darknode init scaffold .nexus/ (project context Nexus reads each session)\n darknode nexus --tui full-screen agent (Claude if installed, else local)\n darknode nexus --tui -e ollama drive a 100% local, private, free agent\n darknode nexus \"add tests to server.js and run them\" one-shot task\n\nFree local setup:\n curl -fsSL https://ollama.com/install.sh | sh\n ollama pull gpt-oss:20b # fast local agent (~14GB); pull gpt-oss:120b for max power (~63GB)" },
engines: { title: "Engines & models", body:
Expand Down Expand Up @@ -3033,7 +3033,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
["/ensemble", "all engines answer, then synthesize the best"], ["/settings", "all options, neatly arranged (alias /options /config)"], ["/jobs", "background commands the agent started (run_background)"], ["/loop", "autonomous goal loop: /loop [-n rounds] <goal> until GOAL-DONE"], ["/team", "multi-model workspace: architect + builder + reviewer, loops to PASS"], ["/policy", "show the enterprise security policy (org + local)"], ["/audit", "audited tool actions · /audit verify (tamper check)"], ["/bench", "speed / tokens / cost table per engine"], ["/explain", "explain the diff or a file in plain English"], ["/test", "generate & run unit tests for a file"], ["/refactor", "restructure code for clarity without changing behavior"], ["/migrate", "migrate code: /migrate <from> to <to>"], ["/pr", "AI-write a PR title+body from the diff and open it (gh)"],
["/index", "index the repo for code search; /index <question> finds the code it is about"], ["/map", "show the repo map; /map <task> ranks it for a task; /map on|off"], ["/verify", "detect + run this project's tests/build"], ["/radar", "codebase complexity + hotspot map"], ["/review-fast", "fast rule-based review of changed code (no AI)"], ["/diffexplain", "explain the current git diff"], ["/testgen", "scaffold tests for a function/file"], ["/snippet", "save / use a prompt macro"], ["/snippets", "list saved prompt macros"],
["/plan", "make & run an editable task checklist"], ["/git", "branch, status & recent commits"], ["/blame", "who last changed a file's lines"],
["/cowork", "strong model codes, weak model does cheap work"], ["/cheap", "lossless savers + measured spend vs Opus · /cheap status · /cheap off"], ["/tight", "surgical edits — change only what differs (lossless)"], ["/lean", "ask for minimal output (saves output tokens) · /lean on|off"], ["/style", "output style: concise·explanatory·review·tdd·secure·teacher"], ["/effort", "claude thinking level — interactive slider (or low|medium|high|xhigh|max|ultracode)"], ["/estimate", "rough token/cost of a prompt before sending"], ["/fallback", "auto-switch model on rate-limit"],
["/cowork", "strong model codes, weak model does cheap work"], ["/cheap", "lossless savers + measured spend · /cheap status · /cheap off"], ["/tight", "surgical edits — change only what differs (lossless)"], ["/lean", "ask for minimal output (saves output tokens) · /lean on|off"], ["/style", "output style: concise·explanatory·review·tdd·secure·teacher"], ["/effort", "claude thinking level — interactive slider (or low|medium|high|xhigh|max|ultracode)"], ["/estimate", "rough token/cost of a prompt before sending"], ["/fallback", "auto-switch model on rate-limit"],
["/guard", "preflight destructive commands (enforce|warn|off)"], ["/permissions", "allow/deny tool rules — /allow /deny <rule>"], ["/impact", "same as /savings — cost-savings analysis"], ["/savings", "cross-session cost-savings analysis + 30d projection"], ["/cache", "serve exact-repeat read-only answers free (on/off/clear)"], ["/models", "list cloud & local models"], ["/api", "drive ANY model via an OpenAI-compatible API (OpenRouter, Groq, …)"], ["/recent", "recently changed files"], ["/keys", "keyboard shortcuts"], ["/docs", "Nexus docs: /docs <topic> or /docs <words> to search every command & key"], ["/gaps", "list TODO/FIXME markers · /gaps plan"], ["/dream", "consolidate the session into NEXUS.md memory"],
["/tree", "show the project file tree"], ["/theme", "change the color theme"],
["/color", "set the accent color · /color <name|0-255|#hex> · /color reset"], ["/colors", "list accent colors"], ["/gradient", "set the logo gradient · /gradient <theme|reset>"], ["/mouse", "toggle mouse capture · /mouse off to select & copy text"],
Expand Down Expand Up @@ -5947,7 +5947,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
if (cacheOn && tightEdits && cheapSide && engine === "claude") Cheap.refreshUse(NHOME).catch(() => {});
const trimmed = Object.keys(Cheap.overridesFor(NHOME, cwd) || {}).length;
const isClaude = engine === "claude", localOnly = isClaude ? gray(" (local engines only)") : "", spend = isClaude ? Cheap.spendReport(sess.byModel) : null, usd = (n) => "$" + n.toFixed(n < 1 ? 4 : 2);
const measured = !isClaude ? "" : !spend ? "\n " + gray("no claude usage measured yet this session — send a message, then /cheap status") : "\n measured on " + cyan(spend.model) + ": " + fmtK(spend.read) + " read from cache (" + Math.round(spend.hitRate * 100) + "%), " + fmtK(spend.written) + " written, " + fmtK(spend.output) + " output = " + bold(usd(spend.cost)) + gray(" at list price") + "\n " + gray("same tokens on Opus 5.5: " + usd(spend.opus55) + " · on Opus 5: " + usd(spend.opus5) + (onPlan(engine) ? " · on a subscription these are list-price equivalents" : ""));
const measured = !isClaude ? "" : !spend ? "\n " + gray("no claude usage measured yet this session — send a message, then /cheap status") : "\n measured on " + cyan(spend.model) + ": " + fmtK(spend.read) + " read from cache (" + Math.round(spend.hitRate * 100) + "%), " + fmtK(spend.written) + " written, " + fmtK(spend.output) + " output = " + bold(usd(spend.cost)) + gray(" at list price") + "\n " + gray("same tokens on other models: " + spend.others.map((o) => o.label + " " + usd(o.cost)).join(" · ") + (onPlan(engine) ? " · on a subscription these are list-price equivalents" : ""));
const lossy = [["lean", lean], ["minimizeCalls", minimizeCalls], ["stepCap", stepCap], ["trimOutput", trimOutput], ["autoCompact", autoCompact]].filter((x) => x[1]).map((x) => x[0]);
transcript.push({ role: "system", text: "cheap mode " + (on ? green("ON") : sub === "off" ? red("OFF") : yellow("PARTIAL")) + " — token savers that keep full quality (" + green("●") + " on " + gray("○") + " off " + cyan("◆") + " always on):\n" + [
row(tightEdits, "surgical edits — change only what differs, never rewrite whole lines"),
Expand Down
4 changes: 2 additions & 2 deletions docs/NEXUS-COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ File tools are confined to the project folder; secrets are blocked from being wr
- `/git` — branch, status & recent commits
- `/blame` — who last changed a file's lines
- `/cowork` — strong model codes, weak model does cheap work
- `/cheap` — lossless savers + measured spend vs Opus · /cheap status · /cheap off
- `/cheap` — lossless savers + measured spend · /cheap status · /cheap off
- `/tight` — surgical edits — change only what differs (lossless)
- `/lean` — ask for minimal output (saves output tokens) · /lean on|off
- `/style` — output style: concise·explanatory·review·tdd·secure·teacher
Expand Down Expand Up @@ -320,7 +320,7 @@ File tools are confined to the project folder; secrets are blocked from being wr
```
Nexus is a terminal AI coding agent built into the Darknode CLI. It drives one of six
engines from a single dependency-free binary:
claude — the Claude Code CLI in the cloud (strongest; needs `claude` installed + logged in)
claude — the Claude Code CLI (needs `claude` installed + logged in)
gemini · codex · opencode · aider — those vendors' CLIs, same interface
ollama — a free, private, local model on your machine (needs Ollama)

Expand Down
14 changes: 9 additions & 5 deletions lib/nexus/cheap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
// ============================================================================

const fs = require("fs"), path = require("path");
const { costOf, priceOf, claudeKey } = require("./pricing");
const { costOf, priceOf, claudeKey, CLAUDE_LATEST } = require("./pricing");

const HOUR_MS = 60 * 60 * 1000;
const HOLD_MS = 60 * 1000; // repeat the same /model within this window to confirm
const OPUS_55 = "claude-opus-5-5", OPUS_5 = "claude-opus-5";

// Settings /cheap changes; /cheap off puts these back. Effort is deliberately
// absent: it is the user's choice, and clearing it can raise spend.
Expand Down Expand Up @@ -128,16 +127,21 @@ function mainBucket(byModel) {
return best;
}

// Real tokens, priced for the model used and for the Opus models on the same
// tokens. Returns null until something was measured.
// Real tokens, priced for the model used and, for comparison, for the latest
// model of every other family, cheapest first. Returns null until something was measured.
function otherModels(model, t) {
const own = (claudeKey(model) || {}).key;
return Object.values(CLAUDE_LATEST).filter((k) => k !== own).map((k) => ({ label: priceOf(k).label, cost: costOf(k, t) })).sort((a, b) => a.cost - b.cost);
}

function spendReport(byModel) {
const model = mainBucket(byModel);
if (!model) return null;
const t = byModel[model];
const written = (t.cacheWrite5m || 0) + (t.cacheWrite1h || 0), read = t.cacheRead || 0, input = t.input || 0, output = t.output || 0;
if (!written && !read && !input && !output) return null;
const prompt = written + read + input;
return { model, input, written, read, output, hitRate: prompt ? read / prompt : 0, cost: costOf(model, t), opus55: costOf(OPUS_55, t), opus5: costOf(OPUS_5, t) };
return { model, input, written, read, output, hitRate: prompt ? read / prompt : 0, cost: costOf(model, t), others: otherModels(model, t) };
}

// What a model switch adds: each model has its own cache, so the whole context
Expand Down
2 changes: 1 addition & 1 deletion lib/nexus/pricing.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,4 @@ function shouldDelegate(estOutTok, estInTok, strong, weak) {
return saved > overhead;
}

module.exports = { MODEL_PRICE, CLAUDE_PRICES, PRICING_SOURCE, PRICING_CHECKED, claudeKey, priceOf, costOf, usageBuckets, pricingTable, isMechanical, shouldDelegate, detectBilling, createCostTracker, BILLING_TYPES };
module.exports = { MODEL_PRICE, CLAUDE_PRICES, CLAUDE_LATEST, PRICING_SOURCE, PRICING_CHECKED, claudeKey, priceOf, costOf, usageBuckets, pricingTable, isMechanical, shouldDelegate, detectBilling, createCostTracker, BILLING_TYPES };
5 changes: 3 additions & 2 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -3766,8 +3766,9 @@ ok("shouldCheck: first launch runs; throttled within 4h; runs after", shouldChec
const r = CH.spendReport({ "claude-haiku-5-5": { input: 10, output: 10, cacheWrite5m: 0, cacheWrite1h: 0, cacheRead: 0 }, "claude-fable-5-2": t });
eq("main bucket is the costliest model", r.model, "claude-fable-5-2");
ok("list price: fable 16 + 2 + 40", Math.abs(r.cost - 58) < 1e-6);
ok("same tokens on opus 5.5: 8 + 2 + 20", Math.abs(r.opus55 - 30) < 1e-6);
ok("same tokens on opus 5: 10 + 5 + 25", Math.abs(r.opus5 - 40) < 1e-6);
const oth = Object.fromEntries(r.others.map((o) => [o.label, o.cost]));
ok("same tokens on opus 5.5: 8 + 2 + 20", Math.abs(oth["Claude Opus 5.5"] - 30) < 1e-6);
ok("compares every other family's latest model, never the one used, cheapest first", r.others.length === 4 && !("Claude Fable 5.2" in oth) && "Claude Sonnet 5.5" in oth && "Claude Haiku 5.5" in oth && r.others.every((o, i, a) => !i || a[i - 1].cost <= o.cost));
ok("nothing measured = null", CH.spendReport({}) === null);
const base = { cheap: true, engine: "claude", sid: "s", warm: true, ctxTok: 1e6, ttl: 3600000, from: "claude-opus-5-5", to: "claude-fable-5-2", pending: null, now: 1000 };
const h = CH.switchHold(base);
Expand Down
Loading