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
18 changes: 17 additions & 1 deletion command-ref.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"generatedFrom": "lib/cli/reference.js COMMAND_GROUPS",
"version": "2.46.3",
"commandCount": 89,
"commandCount": 93,
"groups": [
{
"title": "AI & Nexus",
Expand All @@ -14,6 +14,22 @@
"usage": "nexus run \"<goal>\" [opts]",
"desc": "autonomous multi-level runner: -e engine, --overnight, --until, --resume"
},
{
"usage": "nexus bg [-- agent args]",
"desc": "start a background session (Nexus, or e.g. -- claude) that keeps running after you close the terminal"
},
{
"usage": "nexus ls / nexus sessions",
"desc": "every background session marked working, blocked or idle; sessions = live list (Enter attaches)"
},
{
"usage": "nexus attach <name>",
"desc": "take over a background session in this terminal; Ctrl+] detaches and leaves it running"
},
{
"usage": "nexus hub send|wait|peek|kill <name>",
"desc": "drive a session from scripts or other agents; wait --until blocked|idle|done; hub restore after a restart"
},
{
"usage": "nexus serve [port]",
"desc": "headless Nexus service: POST /run {goal} (loopback-only, token-gated)"
Expand Down
12 changes: 11 additions & 1 deletion darknode.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,12 @@ async function cliRun(args, gate) {
else if (sub === "run" || sub === "supervise" || sub === "loop") await nexusRun(rest.slice(1));
else if (sub === "overnight") await nexusRun(["--overnight"].concat(rest.slice(1)));
else if (sub === "agents" || sub === "parallel") await nexusAgents(rest.slice(1));
// Background sessions (lib/nexus/hub): bg / ls / attach / send / wait / peek / kill / sessions / hub.
else if (await require("./lib/nexus/hub/cli").claims(sub, rest.slice(1))) {
const Hub = require("./lib/nexus/hub/cli"), C = { bold, gray, cyan, yellow, green, red };
try { await (sub === "hub" ? Hub.hubMain(rest.slice(1), C) : Hub.main(sub, rest.slice(1), C)); }
catch (e) { console.error(" " + red(e.message)); process.exitCode = 1; }
}
// Operator-facing headless equivalents of the in-TUI self-check slash commands: they run the
// exact same tool engines the agent calls (via deviceTool), print the result, and exit non-zero
// when the check fails so they double as CI gates.
Expand Down Expand Up @@ -1451,7 +1457,7 @@ const CODER_SCHEMA = { type: "object", properties: { thought: { type: "string" }
// it has no tools. normalizeToolCall recovers the real name + args so tools still fire.
const TOOL_ARGKEY = { run_command: "command", run_background: "command", read_file: "path", write_file: "path", edit_file: "path", multi_edit: "path", multiedit: "path", apply_patch: "patch", patch: "patch", list_dir: "path", make_dir: "path", mkdir: "path", delete: "path", delete_file: "path", rm: "path", move: "from", copy: "from", search: "pattern", grep: "pattern", find: "glob", glob: "glob", http_fetch: "url", web_fetch: "url", fetch_url: "url", http: "url", web_search: "query", discover: "query", remember: "text", check_background: "id", stop_background: "id", list_processes: "filter", batch: "ops", batch_read: "ops", browser_read: "target", browser_page: "target", browser_eval: "expression", browser_exec: "expression", browser_screenshot: "path", browser_shot: "path", ask_user: "question", ask_question: "question", ask: "question" };
const KNOWN_ARGKEYS = new Set(["path", "command", "content", "query", "q", "url", "pattern", "glob", "find", "text", "note", "id", "filter", "to", "from", "dest", "name", "tasks", "todos", "items", "method", "replace", "recursive"]);
const KNOWN_TOOLS = new Set(["code_search", "read_file", "write_file", "edit_file", "list_dir", "run_command", "run_background", "check_background", "stop_background", "search", "grep", "find", "find_files", "glob", "http_fetch", "web_fetch", "fetch_url", "http", "web_search", "search_web", "google", "todo_write", "todos", "todo_list", "write_todos", "sysinfo", "system_info", "list_processes", "ps", "make_dir", "mkdir", "move", "rename", "move_file", "copy", "copy_file", "delete", "delete_file", "rm", "remember", "discover", "spawn_agents", "repo_map", "repomap", "multi_edit", "multiedit", "apply_patch", "patch", "verify", "run_tests", "test_project", "find_symbol", "symbol", "goto", "find_references", "references", "find_refs", "usages", "callers", "module_graph", "import_graph", "deps_graph", "dependents", "importers", "outline", "file_outline", "symbols", "read_symbol", "read_function", "show_symbol", "json_query", "jq", "read_json", "undo_edit", "replace_in_files", "wait_for", "write_stdin", "batch", "batch_read", "invariants", "check_invariants", "difflint", "attest", "attestation", "capability_attest", "bisect", "regression_bisect", "explain_break", "explainbreak", "blame_turn", "shrink", "minimize_change", "ddmin", "browser_status", "browser_tabs", "browser_list", "browser_read", "browser_page", "browser_eval", "browser_exec", "browser_screenshot", "browser_shot", "ask_user", "ask_question", "ask"]);
const KNOWN_TOOLS = new Set(["sessions", "code_search", "read_file", "write_file", "edit_file", "list_dir", "run_command", "run_background", "check_background", "stop_background", "search", "grep", "find", "find_files", "glob", "http_fetch", "web_fetch", "fetch_url", "http", "web_search", "search_web", "google", "todo_write", "todos", "todo_list", "write_todos", "sysinfo", "system_info", "list_processes", "ps", "make_dir", "mkdir", "move", "rename", "move_file", "copy", "copy_file", "delete", "delete_file", "rm", "remember", "discover", "spawn_agents", "repo_map", "repomap", "multi_edit", "multiedit", "apply_patch", "patch", "verify", "run_tests", "test_project", "find_symbol", "symbol", "goto", "find_references", "references", "find_refs", "usages", "callers", "module_graph", "import_graph", "deps_graph", "dependents", "importers", "outline", "file_outline", "symbols", "read_symbol", "read_function", "show_symbol", "json_query", "jq", "read_json", "undo_edit", "replace_in_files", "wait_for", "write_stdin", "batch", "batch_read", "invariants", "check_invariants", "difflint", "attest", "attestation", "capability_attest", "bisect", "regression_bisect", "explain_break", "explainbreak", "blame_turn", "shrink", "minimize_change", "ddmin", "browser_status", "browser_tabs", "browser_list", "browser_read", "browser_page", "browser_eval", "browser_exec", "browser_screenshot", "browser_shot", "ask_user", "ask_question", "ask"]);
// A tool "name" that is really a shell command line — weak models often emit
// {tool:"cat /etc/passwd"} or {tool:"ls /bin/*"} instead of run_command.
const SHELL_CMD = /^(sudo\s+)?(ls|cat|grep|egrep|fgrep|echo|cd|pwd|whoami|id|uname|hostname|ps|top|df|du|free|date|env|printenv|which|type|find|locate|head|tail|awk|sed|cut|tr|sort|uniq|wc|xargs|tee|curl|wget|ping|traceroute|nmap|nc|ncat|dig|host|nslookup|ip|ifconfig|iwconfig|netstat|ss|arp|route|cp|mv|rm|mkdir|rmdir|touch|ln|stat|file|chmod|chown|tar|gzip|gunzip|zip|unzip|git|make|gcc|python3?|node|npm|npx|pip3?|bash|sh|zsh|kill|pkill|killall|systemctl|service|apt|apt-get|dpkg|ssh|scp|rsync|darknode|sentinel|nexus|nikto|sqlmap|hydra|john|hashcat|gobuster|ffuf|masscan|whatweb|searchsploit|msfconsole)(\s|$)/i;
Expand Down Expand Up @@ -2489,6 +2495,7 @@ async function deviceTool(name, a, cwd) {
if (!syms.length) res.note = /\.jsonc?$/i.test(fp) ? "JSON has no symbols — use json_query {path, query, keys_only:true} to see its structure" : "no functions/classes recognized in this file type — use read_file or search";
return res;
}
if (name === "sessions") return require("./lib/nexus/hub/tool").sessionsTool(a, cwd); // background agent sessions (lib/nexus/hub)
return null;
}
// Render one of the agentic self-check tools' result objects (invariants/attest/bisect/
Expand Down Expand Up @@ -3651,6 +3658,8 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
// ---- /effort interactive slider (Claude-Code-style): a Faster↔Smarter bar
// the user nudges with ←/→ and confirms with Enter, instead of typing a level.
let pendingEffort = null; // { sel } while the picker is open
// Inside a background session (nexus bg), tell the hub whether this TUI is working, waiting on a question, or idle.
const hubPoke = require("./lib/nexus/hub/report").startReporter(() => (pendingAsk ? "blocked" : busy ? "working" : "idle"));
// ---- /god-prompt: a one-shot "maximum quality" mode for the NEXT message.
// Arming turns the composer border gold; the settings apply for that single
// turn only and revert automatically when it finishes.
Expand Down Expand Up @@ -3807,6 +3816,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
const render = () => {
pruneAgents();
if (cleaned) return; // after teardown: never touch the terminal again (a pending timer could still fire)
hubPoke();
if (_wasBusy && !busy && nextQueue.length) scheduleDrain(300);
_wasBusy = busy;
if (godActive && !busy) { godRestore(); godActive = false; } // /god-prompt reverts once its one turn finishes
Expand Down
27 changes: 27 additions & 0 deletions docs/NEXUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,33 @@ They apply to every engine. Add custom styles as `.nexus/styles/<name>.md`.
/update check for Darknode CLI updates
```

### Background sessions

Run agents in the background so they keep working after you close the terminal or lose an SSH connection. A small per-user hub (started on first use) owns each session under a real terminal. Linux and macOS.

```
nexus bg start Nexus here in the background
nexus bg --name api -- claude any agent or command after --
nexus bg --prompt "add tests" type a first prompt once it is ready
nexus ls every session: working, blocked (needs you), idle, done
nexus sessions live list: Enter attaches, n new, x stop, r restore
nexus attach api take it over in this terminal; Ctrl+] detaches
nexus hub send api "run the tests"
nexus hub wait api --until blocked|idle|done|stopped [--timeout 600]
nexus hub peek api [--lines 40 | --screen]
nexus hub kill api
nexus hub restore after a reboot: relaunch saved sessions (Nexus resumes its conversation)
nexus hub stop | status
```

`send`, `wait`, `peek` and `kill` also work without `hub` when the next word is a session name (`nexus wait api`).

- **States.** Nexus reports its own state exactly. Other agents are read from their screen: recent output (or a shell running a foreground command) means working, and a permission menu or a y/n question on the last line means blocked.
- **Notifications.** When a session nobody is attached to becomes blocked or finishes, you get a desktop notification.
- **Agents driving agents.** The `sessions` tool (list, spawn, send, wait, peek, kill) gives the agent the same control. It is available in Nexus's own loop and to Claude Code, Codex and other engines through the `nexus` MCP bridge. It goes through the same danger gate and policy as `run_command`, is blocked in plan mode, and only spawns inside the project folder.
- **Where things live.** `~/.nexus/hub/` (mode 700): the socket and `sessions.json`. `NEXUS_HUB_DIR` points it elsewhere.
- **Limits.** Processes do not survive a reboot or `nexus hub stop`; `hub restore` starts them again. Two Nexus sessions in one folder share that folder's saved conversation. Windows is not supported yet.

---

## Misc Commands
Expand Down
4 changes: 4 additions & 0 deletions lib/cli/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const COMMAND_GROUPS = [
{ title: "AI & Nexus", rows: [
["nexus [opts] [task]", "Nexus AI coder chat: -e claude|gemini|codex|opencode|aider|ollama, -y skip prompts, --print headless"],
["nexus run \"<goal>\" [opts]", "autonomous multi-level runner: -e engine, --overnight, --until, --resume"],
["nexus bg [-- agent args]", "start a background session (Nexus, or e.g. -- claude) that keeps running after you close the terminal"],
["nexus ls / nexus sessions", "every background session marked working, blocked or idle; sessions = live list (Enter attaches)"],
["nexus attach <name>", "take over a background session in this terminal; Ctrl+] detaches and leaves it running"],
["nexus hub send|wait|peek|kill <name>", "drive a session from scripts or other agents; wait --until blocked|idle|done; hub restore after a restart"],
["nexus serve [port]", "headless Nexus service: POST /run {goal} (loopback-only, token-gated)"],
["update [--check]", "self-update to the latest version (git fast-forward; --check only reports)"],
["init", "scaffold Nexus in this project (.nexus/NEXUS.md + config)"],
Expand Down
10 changes: 8 additions & 2 deletions lib/nexus/ask-mcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const ASK_TOOL = {
},
};

const SESSIONS_TOOL = (() => { const s = require("./hub/tool").SCHEMA; return { name: "sessions", description: s.description, inputSchema: { type: "object", properties: s.properties, required: s.required } }; })();

function send(msg) { try { process.stdout.write(JSON.stringify(msg) + "\n"); } catch (_) {} }
function reply(id, result) { send({ jsonrpc: "2.0", id, result }); }
function replyErr(id, code, message) { send({ jsonrpc: "2.0", id, error: { code, message } }); }
Expand Down Expand Up @@ -88,9 +90,13 @@ async function handle(msg) {
});
}
if (method === "ping") return reply(id, {}); // MCP liveness check: an empty result, never an error
if (method === "tools/list") return reply(id, { tools: [ASK_TOOL] });
if (method === "tools/list") return reply(id, { tools: [ASK_TOOL, SESSIONS_TOOL] });
if (method === "tools/call") {
const p = msg.params || {};
if (p.name === "sessions") { // background agent sessions (lib/nexus/hub/tool.js), for the engine's own model
const r = await require("./hub/tool").sessionsTool(p.arguments || {}, process.cwd());
return reply(id, { content: [{ type: "text", text: JSON.stringify(r, null, 2) }], isError: !!r.error });
}
if (p.name !== "ask_user") return replyErr(id, -32602, "Unknown tool: " + p.name); // the spec's code for an unknown tool
const a = p.arguments;
if (!a || typeof a !== "object" || typeof a.question !== "string" || !a.question.trim()) return replyErr(id, -32602, "Invalid params: ask_user needs a non-empty string question");
Expand Down Expand Up @@ -130,4 +136,4 @@ function main() {

if (require.main === module) main();

module.exports = { fmtAnswer, ASK_TOOL, handle, askNexus }; // for unit tests
module.exports = { fmtAnswer, ASK_TOOL, SESSIONS_TOOL, handle, askNexus }; // for unit tests
Loading
Loading