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
11 changes: 8 additions & 3 deletions darknode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,9 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
const S = settingsStore.value, Ssrc = settingsStore.source;
const saveSetting = (k, v) => { try { settingsStore.set(k, v); } catch (_) {} };
if (settingsStore.corrupt) transcript.push({ role: "system", text: "your settings file (~/.nexus/settings.json) was unreadable, so Nexus started with defaults. The old file was kept as " + settingsStore.corrupt + " — fix it and copy it back to restore your settings." });
// Signed in to Darknode: let the site owner's admin panel count this account as a Nexus user
// (version + OS, at most every 6 hours; /shareusage off). Fire and forget.
setTimeout(() => { try { const _fb = firebaseCfg() || {}; require("./lib/nexus/usage-ping").pingUsage({ readAuth: nexusAuth, saveAuth: (a) => writeGlobal("auth.json", a), refresh: firebaseRefresh, post: (url, body, headers) => httpReq({ url, method: "POST", body, headers, timeout: 8000 }), readState: () => readGlobal("usage-ping.json", {}), writeState: (st) => writeGlobal("usage-ping.json", st), version: VERSION, platform: process.platform, env: process.env, enabled: S.shareUsage !== false, api: _fb.apiUrl }).catch(() => {}); } catch (_) {} }, 3000).unref();
try { const _a = settingsStore.getSaved("aliases"); if (_a && typeof _a === "object" && !Array.isArray(_a)) aliases = _a; } catch (_) {}
// Per-project command history, loaded from disk (dedup + capped) and driven
// by the pure ComposerModel. `history`/`hIdx` stay as compatibility mirrors.
Expand Down Expand Up @@ -3017,7 +3020,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
["/agents", "run tasks in parallel: /agents a ;; b ;; c"], ["/mcp", "list / connect MCP servers"], ["/hooks", "show configured tool hooks"],
["/race", "run a prompt on every engine at once"], ["/review", "second opinion from a different engine"], ["/codereview", "multi-agent bug review: parallel reviewers, each finding verified · /codereview [low|medium|high|xhigh|max] [file|branch|PR#] [--fix] [--comment] [--max-findings n|all]"], ["/redo", "reapply an undone change"],
["/ultrareview", "rigorous multi-lens review of the working diff (severity-ranked)"], ["/changelog", "release notes from git history, grouped by type"],
["/secrets", "scan the repo for leaked credentials"], ["/scan", "quick TCP port scan of a host"], ["/notify", "bell + desktop alert on long turns and questions · /notify on|off"],
["/secrets", "scan the repo for leaked credentials"], ["/scan", "quick TCP port scan of a host"], ["/notify", "bell + desktop alert on long turns and questions · /notify on|off"], ["/shareusage", "tell Darknode this account uses Nexus (version + OS) · /shareusage on|off"],
["/watch", "run a cmd; auto-fix & re-run until it passes"], ["/commit", "AI commit message + commit the diff"], ["/diff", "colored word-level diff · /diff <file> · /diff --staged"],
["/pin", "keep a file in context every turn"], ["/pins", "list pinned files"], ["/unpin", "remove a pinned file"], ["/redact", "mask secrets before cloud sends"],
["/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)"],
Expand Down Expand Up @@ -3614,7 +3617,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
"/autocompact": () => [["auto", "Nexus picks when to shrink"], ["off", "only when the context overflows"], ["40k", "or any token amount"]],
"/autoupdate": () => [["on", "update on launch"], ["check", "just say when one is out"], ["off", "never check"]],
"/report": () => [["json", "machine-readable"], ["save", "write it to a file"], ["since", "since <date>"]],
...Object.fromEntries([["/map", "repo map"], ["/recap", "after-task recap"], ["/title", "AI-named terminal tab"], ["/vim", "vim editing in the input box"], ["/notify", "bell + desktop alert"], ["/mouse", "mouse capture (off = select & copy)"], ["/lean", "minimal-output mode"], ["/offline", "local-only privacy lock"]].map(([c, what]) => [c, () => [["on", what + " on"], ["off", what + " off"]]])),
...Object.fromEntries([["/map", "repo map"], ["/recap", "after-task recap"], ["/title", "AI-named terminal tab"], ["/vim", "vim editing in the input box"], ["/notify", "bell + desktop alert"], ["/shareusage", "usage sharing"], ["/mouse", "mouse capture (off = select & copy)"], ["/lean", "minimal-output mode"], ["/offline", "local-only privacy lock"]].map(([c, what]) => [c, () => [["on", what + " on"], ["off", what + " off"]]])),
"/cache": () => [["on", "serve exact repeats free"], ["off", "always ask the model"], ["clear", "forget cached answers"]],
};
const argMatches = () => {
Expand Down Expand Up @@ -3966,6 +3969,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
const toggleState = (nm) => {
switch (nm) {
case "/notify": return notify;
case "/shareusage": return settingsStore.value.shareUsage !== false;
case "/map": return repoMapOn;
case "/lean": return lean;
case "/cache": return cacheOn;
Expand Down Expand Up @@ -5569,6 +5573,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
else if (cmd === "/changelog") { (async () => { const range = arg && arg.trim() ? arg.trim() : null; let rng = range; if (!rng) { const t = await sh(["describe", "--tags", "--abbrev=0"]); const tag = (t.stdout || "").trim(); rng = tag ? tag + "..HEAD" : ""; } const lg = await sh(["log", "--no-color", "--no-merges", "--pretty=%h%x09%s%x1f%b%x1e"].concat(rng ? [rng] : ["-40"])); if (lg.err) { transcript.push({ role: "system", text: "git log failed" + (rng ? " for " + rng : "") + ": " + String(lg.stderr || lg.err.message).trim().split("\n")[0] }); render(); return; } const commits = parseCommits(lg.stdout || ""); const md = renderChangelog(commits, { title: "Changelog", range: rng || "recent" }); transcript.push({ role: "system", text: commits.length ? md : "no commits found" + (rng ? " in " + rng : "") }); render(); })(); }
else if (cmd === "/secrets") { try { const all = _cp.execSync("git ls-files -z --cached --others --exclude-standard", { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] }).split("\0").filter(Boolean); const files = all.slice(0, 5000); const found = []; /* tracked + new untracked (not ignored) files: a key in a file about to be committed counts too */ for (const f of files) { try { if (fs.statSync(path.join(cwd, f)).size > 400000) continue; const hits = scanSecrets(fs.readFileSync(path.join(cwd, f), "utf8")); if (hits.length) found.push(" " + f + " — " + hits.join(", ")); } catch (_) {} } transcript.push({ role: "system", text: found.length ? ("possible secrets found (tracked + untracked, not ignored):\n" + found.slice(0, 40).join("\n")) : "scanned " + files.length + " file" + (files.length === 1 ? "" : "s") + " (tracked + untracked, not ignored) — no obvious secrets found" }); if (all.length > files.length) transcript.push({ role: "system", text: "only the first " + files.length + " of " + all.length + " files were scanned" }); } catch (_) { transcript.push({ role: "system", text: "/secrets needs a git repo (uses git ls-files)" }); } }
else if (cmd === "/scan") { const host = (arg || "").trim().split(/\s+/)[0] || "127.0.0.1"; const COMMON = [21, 22, 23, 25, 53, 80, 110, 143, 443, 445, 3306, 3389, 5432, 6379, 8080, 8443, 9000]; transcript.push({ role: "system", text: "scanning " + host + " (" + COMMON.length + " common TCP ports)…" }); render(); quickScan(host, COMMON).then((open) => { transcript.push({ role: "system", text: open.length ? ("open on " + host + ": " + open.join(", ")) : open.unresolved ? "could not resolve " + host + " — nothing was scanned" : "no common ports open on " + host }); render(); }); }
else if (cmd === "/shareusage") { const a = (arg || "").trim().toLowerCase(); if (a && a !== "on" && a !== "off") { transcript.push({ role: "system", text: "usage: /shareusage [on|off] (no argument toggles)" }); render(); return; } const on = a === "on" ? true : a === "off" ? false : settingsStore.value.shareUsage === false; saveSetting("shareUsage", on); transcript.push({ role: "system", text: "usage sharing " + (on ? "ON — while you are signed in, Nexus tells Darknode once every 6 hours that this account uses it (version and OS only)" : "off — Nexus sends nothing about your usage") }); }
else if (cmd === "/notify") { const a = (arg || "").trim().toLowerCase(); if (a && a !== "on" && a !== "off") { transcript.push({ role: "system", text: "usage: /notify [on|off] (no argument toggles)" }); render(); return; } notify = a === "on" ? true : a === "off" ? false : !notify; saveSetting("notify", notify); transcript.push({ role: "system", text: "completion notifications " + (notify ? "ON — a bell rings (and a desktop notification) when a turn over ~15s finishes or Nexus stops to ask you something, so you can step away" : "off") }); }
else if (cmd === "/watch") { if (!argstr) transcript.push({ role: "system", text: "usage: /watch <command> — runs it, and if it fails has " + engine + " fix the code and re-run, up to 5 times (e.g. /watch npm test)" }); else watchFix(argstr); }
else if (cmd === "/commit") commitChanges();
Expand Down Expand Up @@ -5706,7 +5711,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
}
render(); return;
}
const v = { engine, model: (sess.model && sess.model !== engine ? sess.model : ""), effort, fallback, style, lean, cowork, costCap, cost: sess.cost, mode: (MODES[mode] && MODES[mode].k) || "auto-accept", guard, policyOrg: policy.org, audit: policy.audit, redact, offline, notify, ctxPct: sess.ctxWindow ? Math.min(100, Math.round((sess.ctxUsed / sess.ctxWindow) * 100)) : null, pins: pinned.size, bgRunning: bgJobs.running() };
const v = { engine, model: (sess.model && sess.model !== engine ? sess.model : ""), effort, fallback, style, lean, cowork, costCap, cost: sess.cost, mode: (MODES[mode] && MODES[mode].k) || "auto-accept", guard, policyOrg: policy.org, audit: policy.audit, redact, offline, notify, shareUsage: settingsStore.value.shareUsage, ctxPct: sess.ctxWindow ? Math.min(100, Math.round((sess.ctxUsed / sess.ctxWindow) * 100)) : null, pins: pinned.size, bgRunning: bgJobs.running() };
// on/off values read green/red at a glance, matching the slash-menu toggle colours
const onOff = (x) => /^on\b/i.test(x) ? green(x) : /^off$/i.test(x) ? red(x) : x;
let text = bold("Settings") + gray(" change any option with the command shown");
Expand Down
1 change: 1 addition & 0 deletions docs/NEXUS-COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ File tools are confined to the project folder; secrets are blocked from being wr
- `/secrets` — scan the repo for leaked credentials
- `/scan` — quick TCP port scan of a host
- `/notify` — bell + desktop alert on long turns and questions · /notify on|off
- `/shareusage` — tell Darknode this account uses Nexus (version + OS) · /shareusage on|off
- `/watch` — run a cmd; auto-fix & re-run until it passes
- `/commit` — AI commit message + commit the diff
- `/diff` — colored word-level diff · /diff <file> · /diff --staged
Expand Down
1 change: 1 addition & 0 deletions lib/cli/command-help.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const HELP = {
"/ultrareview": { u: "[file|branch|PR#]", ex: ["/ultrareview", "/ultrareview HEAD~3"], see: ["/codereview"] },
"/changelog": { u: "[git range]", ex: ["/changelog", "/changelog v1.0..HEAD"] },
"/notify": { u: "on|off", ex: ["/notify on", "/notify off"] },
"/shareusage": { u: "on|off", ex: ["/shareusage off", "/shareusage on"] },
"/watch": { u: "<command>", a: [["command", "re-run and auto-fix until it exits 0"]], ex: ["/watch npm test"], see: ["/verify", "/test"] },
"/commit": { u: "[message]", a: [["message", "override the AI-written message"]], ex: ["/commit", "/commit fix: null guard"], see: ["/pr", "/diff"] },
"/diff": { u: "[file] [--staged]", ex: ["/diff", "/diff src/app.js", "/diff --staged"], see: ["/explain", "/commit"] },
Expand Down
1 change: 1 addition & 0 deletions lib/cli/nexus-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const DEFAULTS = {
mode: null, // null = keep the launch default
model: "", // "" = the engine default; persists the user's /model choice
syntaxGate: "warn", // after an edit, warn (never block) if it introduced a syntax error; "off" disables
shareUsage: true, // signed in: tell Darknode this account uses Nexus (version + OS, every 6h); /shareusage off
};

// Env vars that pin a key for THIS launch (highest precedence). A present +
Expand Down
1 change: 1 addition & 0 deletions lib/cli/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const SETTINGS = [
{ group: "Privacy", items: [
{ label: "Redact secrets to cloud", cmd: "/redact", get: (v) => (v.redact ? "on" : "off") },
{ label: "Offline lock", cmd: "/offline", get: (v) => (v.offline ? "on" : "off") },
{ label: "Share usage", cmd: "/shareusage", get: (v) => (v.shareUsage === false ? "off" : "on") },
] },
{ group: "Session", items: [
{ label: "Desktop notify", cmd: "/notify", get: (v) => (v.notify ? "on" : "off") },
Expand Down
40 changes: 40 additions & 0 deletions lib/nexus/usage-ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";
// usage-ping — tells Darknode that a signed-in person uses Nexus, so the site owner's admin
// panel can list Nexus users (with version and OS). Sent only when a Darknode sign-in exists
// (/login), at most every 6 hours, never with prompts, files, paths or project names.
// Off with /shareusage off (saved in ~/.nexus/settings.json), NEXUS_SHARE_USAGE=0 or
// DO_NOT_TRACK=1. Never throws; the TUI fires it and forgets it.

const DEFAULT_API = "https://darknode-proxy.darknode-ai.workers.dev";
const EVERY_MS = 6 * 3600e3;
const OSES = new Set(["linux", "darwin", "win32"]);

const claims = (t) => { try { return JSON.parse(Buffer.from(String(t).split(".")[1].replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8")); } catch (_) { return null; } };

// deps: { readAuth, saveAuth, refresh(refreshToken) -> { id_token, refresh_token }, post(url, body, headers) -> { status },
// readState() -> { at }, writeState(s), version, platform, env, enabled, now, api }
// -> "sent" | "off" | "signed-out" | "skipped" | "failed"
async function pingUsage(deps) {
try {
const env = deps.env || {}, now = deps.now || Date.now();
if (deps.enabled === false || /^(0|false|off|no)$/i.test(String(env.NEXUS_SHARE_USAGE || "").trim()) || /^(1|true)$/i.test(String(env.DO_NOT_TRACK || "").trim())) return "off";
const a = deps.readAuth();
if (!a || !a.idToken || !a.uid) return "signed-out";
const st = deps.readState() || {};
if (st.at && now - st.at < EVERY_MS && st.uid === a.uid) return "skipped";
let tok = a.idToken; const c = claims(tok);
if (!c || !c.exp || c.exp * 1000 - now < 120000) {
const r = await deps.refresh(a.refreshToken).catch(() => null);
if (!r || !r.id_token) return "failed";
tok = r.id_token;
deps.saveAuth(Object.assign({}, a, { idToken: tok, refreshToken: r.refresh_token || a.refreshToken, ts: now }));
}
const body = { product: "nexus", version: String(deps.version || ""), os: OSES.has(deps.platform) ? deps.platform : "" };
const r = await deps.post((deps.api || env.DARKNODE_API || DEFAULT_API) + "/api/v1/usage", body, { Authorization: "Bearer " + tok, "Content-Type": "application/json" });
if (!r || r.status < 200 || r.status >= 300) return "failed";
deps.writeState({ at: now, uid: a.uid });
return "sent";
} catch (_) { return "failed"; }
}

module.exports = { pingUsage, EVERY_MS };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"scripts": {
"start": "node darknode.js",
"build": "pkg . --out-path dist",
"test": "node test/run.js && node test/authz.test.js && node test/composer.test.js && node test/term.test.js && node test/md-render.test.js && node test/links.test.js && node test/pager.test.js && node test/tool-tail.test.js && node test/os-notify.test.js && node test/repo-map-rank.test.js && node test/bm25.test.js && node test/danger-audit.test.js && node test/url-guard-audit.test.js && node test/edit-audit.test.js && node test/jail-audit.test.js && node test/mcp-audit.test.js && node test/git-search-audit.test.js && node test/state-audit.test.js && node test/exec-audit.test.js && node test/cli-audit.test.js && node test/governance-audit.test.js && node test/toolkit-audit.test.js && node test/devhelpers-audit.test.js && node test/radar-audit.test.js && node test/pentest-audit.test.js && node test/shellfix-audit.test.js && node test/convo-lifecycle-audit.test.js && node test/local-loop-audit.test.js && node test/undo-audit.test.js && node test/at-mentions-audit.test.js && node test/clipboard-audit.test.js && node test/notes-audit.test.js && node test/snippets-audit.test.js && node test/typed-names-audit.test.js && node test/sighup-audit.test.js && node test/tui-stderr-audit.test.js && node test/piped-stdin-audit.test.js && node test/oneshot-escape-audit.test.js && node test/hot-path-speed-audit.test.js && node test/command-help.test.js && node test/session-save.test.js && node test/agents-panel.test.js && node test/tui-layout.test.js && node test/hub.test.js",
"test": "node test/run.js && node test/usage-ping.test.js && node test/authz.test.js && node test/composer.test.js && node test/term.test.js && node test/md-render.test.js && node test/links.test.js && node test/pager.test.js && node test/tool-tail.test.js && node test/os-notify.test.js && node test/repo-map-rank.test.js && node test/bm25.test.js && node test/danger-audit.test.js && node test/url-guard-audit.test.js && node test/edit-audit.test.js && node test/jail-audit.test.js && node test/mcp-audit.test.js && node test/git-search-audit.test.js && node test/state-audit.test.js && node test/exec-audit.test.js && node test/cli-audit.test.js && node test/governance-audit.test.js && node test/toolkit-audit.test.js && node test/devhelpers-audit.test.js && node test/radar-audit.test.js && node test/pentest-audit.test.js && node test/shellfix-audit.test.js && node test/convo-lifecycle-audit.test.js && node test/local-loop-audit.test.js && node test/undo-audit.test.js && node test/at-mentions-audit.test.js && node test/clipboard-audit.test.js && node test/notes-audit.test.js && node test/snippets-audit.test.js && node test/typed-names-audit.test.js && node test/sighup-audit.test.js && node test/tui-stderr-audit.test.js && node test/piped-stdin-audit.test.js && node test/oneshot-escape-audit.test.js && node test/hot-path-speed-audit.test.js && node test/command-help.test.js && node test/session-save.test.js && node test/agents-panel.test.js && node test/tui-layout.test.js && node test/hub.test.js",
"postinstall": "node scripts/postinstall.js",
"docs": "node scripts/gen-nexus-docs.js"
},
Expand Down
Loading
Loading