From 47c55c2ea1c9873f0e5caaf3267f06e3924a68f9 Mon Sep 17 00:00:00 2001 From: Darknode-Official Date: Sat, 31 Oct 2026 15:41:40 -0700 Subject: [PATCH 1/2] Add /help usage cards for every slash command Each command already has a one-line description in the CMDS table; what a one-liner can't carry is the argument syntax and a concrete example. This adds that as structured data and surfaces it on demand. - lib/cli/command-help.js: per-command usage, argument notes, examples and "see also", for all 142 slash commands. Descriptions still come from CMDS (one source of truth); this only adds the extra detail. usageLine() gives a handler one consistent usage string so the help a user reads and the error they hit can't drift. - /help now renders a card (usage, arguments, examples, see also); /help still falls back to the full-text search for non-commands. The main /help footer points at it. - An unknown slash command's "did you mean" hint now also offers /help for that command's usage. - test/command-help.test.js checks the table against the real command list: no stale entries, every "see also" and example is a real command, every command renders a card. Wired into npm test. --- darknode.js | 18 +++-- lib/cli/command-help.js | 153 ++++++++++++++++++++++++++++++++++++++ package.json | 2 +- test/command-help.test.js | 52 +++++++++++++ 4 files changed, 219 insertions(+), 6 deletions(-) create mode 100644 lib/cli/command-help.js create mode 100644 test/command-help.test.js diff --git a/darknode.js b/darknode.js index 77040c4..f06ab0f 100755 --- a/darknode.js +++ b/darknode.js @@ -86,6 +86,7 @@ const { totp, secondsRemaining } = require("./lib/toolkit/totp"); // TOTP 2FA co const { SERVICES } = require("./lib/toolkit/ports"); // port<->service map, used by scan (lib/ports.js) const { digests, genPass } = require("./lib/toolkit/hashing"); // hash digests + password gen (lib/hashing.js) const { COMMAND_GROUPS, renderCommands, documentedVerbs, nearestCommands, nearestFlag } = require("./lib/cli/reference"); // help catalog = single source of truth (lib/reference.js) +const CmdHelp = require("./lib/cli/command-help"); // per-command usage + examples: `/help ` cards + shared usage lines // Documented darknode verbs NOT bridged into the Nexus TUI as /commands: they // block (server/listener), prompt for input, or already have a richer in-TUI // handler. Everything else documented becomes a slash command automatically. @@ -5153,13 +5154,20 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { const clearWasPending = clearPending; if (cmd !== "/clear" && cmd !== "/new") clearPending = false; if (aliases[cmd] && !builtinNames().has(cmd)) { let body = String(aliases[cmd]).replace(/\$ARGUMENTS/g, argstr).replace(/\$(\d+)/g, (_, n) => argstr.split(/\s+/)[+n - 1] || ""); if (!/\$ARGUMENTS|\$\d/.test(aliases[cmd]) && argstr) body += " " + argstr; if (body.trim()[0] === "/") { if (_aliasDepth >= 5) { transcript.push({ role: "system", text: "alias " + cmd + " loops back on itself (aliases calling aliases more than 5 deep) — fix it with /alias" }); return; } _aliasDepth++; try { handleSlash(body.trim()); } finally { _aliasDepth--; } } else submit(body.trim()); return; } if (customCmds[cmd]) { let body = customCmds[cmd].body.replace(/\$ARGUMENTS/g, argstr).replace(/\$(\d+)/g, (_, n) => argstr.split(/\s+/)[+n - 1] || ""); submit(body); return; } - if (cmd === "/help" && argstr.trim()) { // /help : every command, key and guide line that mentions it (same search as /docs) - const q = argstr.trim(), hits = NexusDocs.search(nexusRef(), q); - transcript.push({ role: "system", dismissable: true, text: hits.length ? bold("help — \"" + q + "\"") + "\n\n" + hits.map((h) => /^## /.test(h) ? cyan(h.slice(3)) : " " + h.replace(/^- /, "").replace(/`([^`]+)`/g, (_, c) => cyan(c))).join("\n") : "no help mentions \"" + q + "\" — /help lists every command, / searches them by name" }); + if (cmd === "/help" && argstr.trim()) { // /help : an exact command → its usage card; otherwise search every command, key & guide line (same search as /docs) + const q = argstr.trim(); + const hit = CmdHelp.resolve(q.split(/\s+/)[0], builtinNames()); + if (hit) { + const row = allCmds().find((c) => c[0] === hit); + transcript.push({ role: "system", dismissable: true, text: CmdHelp.card(hit, row ? row[1] : "", { name: (t) => bold(cyan(t)), head: (t) => gray(t), dim: gray, flag: cyan }) }); + } else { + const hits = NexusDocs.search(nexusRef(), q); + transcript.push({ role: "system", dismissable: true, text: hits.length ? bold("help — \"" + q + "\"") + "\n\n" + hits.map((h) => /^## /.test(h) ? cyan(h.slice(3)) : " " + h.replace(/^- /, "").replace(/`([^`]+)`/g, (_, c) => cyan(c))).join("\n") : "no command or help text matches \"" + q + "\" — /help lists every command, / searches them by name" }); + } } else if (cmd === "/help") { const HS = HELP_SECTIONS; - transcript.push({ role: "system", dismissable: true, lines: helpLines(HS, cols() - 4, { heading: (t) => bold(cyan(t)), name: (t) => cyan(t), desc: gray }).concat(["", gray(" " + allCmds().length + " commands in total — type / to search them, or /keys for shortcuts."), gray(" (Esc closes this)")]) }); + transcript.push({ role: "system", dismissable: true, lines: helpLines(HS, cols() - 4, { heading: (t) => bold(cyan(t)), name: (t) => cyan(t), desc: gray }).concat(["", gray(" " + allCmds().length + " commands in total — type / to search them, " + cyan("/help ") + gray(" for its usage & examples, or /keys for shortcuts.")), gray(" (Esc closes this)")]) }); } else if (cmd === "/commands") { const ks = Object.keys(customCmds); transcript.push({ role: "system", text: ks.length ? ("custom commands (from .nexus/commands or .claude/commands):\n" + ks.map((k) => " " + k + " " + customCmds[k].desc.replace(/ \(custom\)$/, "")).join("\n")) : "no custom commands yet — add a file like .nexus/commands/review.md, then use /review" }); } @@ -6192,7 +6200,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { child.on("error", (e) => { blk.text = "failed to run `darknode " + verb + "`: " + (e && e.message || e); render(); }); } catch (e) { blk.text = "failed: " + (e && e.message || e); render(); } } - else { const near = (fuzzyCmds(cmd) || []).slice(0, 3).map((c) => c[0]); transcript.push({ role: "system", text: "unknown command '" + cmd + "'" + (near.length ? " — did you mean " + near.map((n) => cyan(n)).join(gray(", ")) + "?" : "") + gray(" (/help lists them all)") }); } + else { const near = (fuzzyCmds(cmd) || []).slice(0, 3).map((c) => c[0]); transcript.push({ role: "system", text: "unknown command '" + cmd + "'" + (near.length ? " — did you mean " + near.map((n) => cyan(n)).join(gray(", ")) + "?" + gray(" (/help " + near[0].replace(/^\//, "") + " for its usage)") : gray(" (/help lists them all)")) }); } }; // ---- input / keys ---- const setMouse = (on) => { mouseOn = on; try { out.write(on ? ESC + "[?1000h" + ESC + "[?1006h" : ESC + "[?1000l" + ESC + "[?1006l"); } catch (_) {} }; diff --git a/lib/cli/command-help.js b/lib/cli/command-help.js new file mode 100644 index 0000000..d26aa23 --- /dev/null +++ b/lib/cli/command-help.js @@ -0,0 +1,153 @@ +"use strict"; +// ============================================================================ +// command-help — per-slash-command usage + examples for the TUI. +// +// The one-line DESCRIPTION of every command still lives in the CMDS table in +// darknode.js (single source of truth); this module adds only the extra two +// things a one-liner can't carry: the argument SYNTAX and a couple of concrete +// EXAMPLES. `/help ` renders a card from both, and a handler that +// rejects bad input can show the SAME usage line (usageLine) so the help a user +// reads and the error they hit never drift. +// +// Entry shape, all optional: +// u usage/argument syntax shown after the command name +// a [[arg, what-it-means], …] — notes on individual arguments/values +// ex ["/cmd …", …] — runnable examples +// see ["/other", …] — related commands +// A command with no entry still gets a card (name + description); it just has +// no args to explain. +// ============================================================================ + +const HELP = { + "/help": { u: "[word]", ex: ["/help", "/help cost", "/help /model"], see: ["/docs", "/keys"] }, + "/connect": { u: "", ex: ["/connect"], see: ["/engine", "/model", "/api"] }, + "/alias": { u: " = ", a: [["name", "the shortcut you'll type"], ["= …", "what it expands to — plain text or another /command"]], ex: ["/alias ship = /commit", "/alias rv = review this diff for security"] }, + "/retry": { u: "", ex: ["/retry"] }, + "/budget": { u: "|off", a: [["", "stop warning past this session spend"], ["off", "remove the cap"]], ex: ["/budget 5", "/budget off"], see: ["/cost", "/savings"] }, + "/report": { u: "[json|save|since ]", a: [["json", "machine-readable output"], ["save", "write it to a file"], ["since ", "only usage on/after YYYY-MM-DD"]], ex: ["/report", "/report json", "/report since 2026-10-01"], see: ["/cost", "/compliance"] }, + "/compliance": { u: "[verify ]", a: [["verify ", "check a bundle's signature + hash chain"]], ex: ["/compliance", "/compliance verify audit.json"], see: ["/audit", "/report"] }, + "/rewind": { u: "[N]", a: [["N", "checkpoint number (see /checkpoints); omit for a picker"]], ex: ["/rewind", "/rewind 3"], see: ["/checkpoints", "/undo", "/redo"] }, + "/bisect": { u: "[test command]", a: [["test command", "how to tell pass from fail; auto-detected if omitted"]], ex: ["/bisect", "/bisect npm test"], see: ["/whatbroke", "/shrink"] }, + "/shrink": { u: "[test command]", ex: ["/shrink", "/shrink npm test"], see: ["/bisect", "/whatbroke"] }, + "/branch": { u: "[new |]", a: [["new ", "fork a new conversation branch"], ["", "switch to an existing branch"]], ex: ["/branch", "/branch new spike", "/branch main"], see: ["/resume"] }, + "/export": { u: "[file]", a: [["file", "where to write the markdown; omit for a default name"]], ex: ["/export", "/export chat.md"], see: ["/copy"] }, + "/fixshell": { u: "[check|all]", a: [["check", "report only, change nothing"], ["all", "also clear the larger shell state"]], ex: ["/fixshell", "/fixshell check"] }, + "/model": { u: "[name|number]", a: [["name|number", "pick from the catalog; omit to list it"]], ex: ["/model", "/model 3", "/model sonnet"], see: ["/models", "/engine", "/compat"] }, + "/engine": { u: "[claude|gemini|codex|opencode|aider|ollama]", ex: ["/engine", "/engine claude", "/engine ollama"], see: ["/model", "/connect"] }, + "/agents": { u: " ;; ;; …", a: [[";;", "separates independent tasks run in parallel"]], ex: ["/agents add tests ;; write docs ;; fix lint"], see: ["/team", "/race"] }, + "/race": { u: "", ex: ["/race explain this bug"], see: ["/review", "/ensemble", "/bench"] }, + "/review": { u: "[prompt]", ex: ["/review", "/review focus on error handling"], see: ["/codereview", "/review-fast", "/ultrareview"] }, + "/codereview": { u: "[low|medium|high|xhigh|max] [file|branch|PR#] [--fix] [--comment] [--max-findings n|all|default]", a: [["level", "few sure findings → many, some uncertain"], ["--fix", "apply fixes to the working tree"], ["--comment", "post inline PR comments"]], ex: ["/codereview", "/codereview high", "/codereview max 42 --comment"], see: ["/ultrareview", "/review-fast"] }, + "/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"] }, + "/watch": { u: "", 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"] }, + "/pin": { u: "", ex: ["/pin src/app.js"], see: ["/pins", "/unpin"] }, + "/unpin": { u: "", ex: ["/unpin src/app.js"], see: ["/pins", "/pin"] }, + "/ensemble": { u: "", ex: ["/ensemble design a cache layer"], see: ["/race", "/team"] }, + "/loop": { u: "[-n rounds] ", a: [["-n rounds", "max iterations (default keeps going until GOAL-DONE)"], ["goal", "what 'done' means"]], ex: ["/loop make the tests green", "/loop -n 5 wire up auth"], see: ["/team", "/plan", "/next"] }, + "/team": { u: "", a: [["goal", "architect + builder + reviewer loop until the reviewer says PASS"]], ex: ["/team add rate limiting to the API"], see: ["/loop", "/agents", "/cowork"] }, + "/policy": { u: "", ex: ["/policy"], see: ["/audit", "/guard", "/permissions"] }, + "/audit": { u: "[verify]", a: [["verify", "check the hash chain; exits non-zero if tampered"]], ex: ["/audit", "/audit verify"], see: ["/attest", "/compliance"] }, + "/explain": { u: "[file]", a: [["file", "explain a file; omit to explain the current diff"]], ex: ["/explain", "/explain src/app.js"], see: ["/diffexplain", "/blame"] }, + "/test": { u: "", ex: ["/test src/util.js"], see: ["/testgen", "/verify", "/watch"] }, + "/refactor": { u: " [goal]", ex: ["/refactor src/app.js", "/refactor src/app.js split the parser out"] }, + "/migrate": { u: " to ", ex: ["/migrate commonjs to esm", "/migrate react 17 to 18"] }, + "/pr": { u: "[base]", a: [["base", "base branch for the PR (default: the repo default)"]], ex: ["/pr", "/pr develop"], see: ["/commit", "/changelog"] }, + "/index": { u: "[question]", a: [["question", "find the code behind it; omit to (re)build the index"]], ex: ["/index", "/index where is login handled"], see: ["/map", "/find"] }, + "/map": { u: "[task|on|off]", a: [["task", "rank the repo map for a task"], ["on|off", "keep the map in context each turn"]], ex: ["/map", "/map add caching", "/map off"], see: ["/index", "/tree", "/radar"] }, + "/verify": { u: "", ex: ["/verify"], see: ["/test", "/watch"] }, + "/review-fast": { u: "", ex: ["/review-fast"], see: ["/codereview", "/review"] }, + "/testgen": { u: "", ex: ["/testgen src/util.js", "/testgen parseDate"], see: ["/test"] }, + "/snippet": { u: " [= ] | ", a: [["name = text", "save a prompt macro"], ["name", "use a saved macro"]], ex: ["/snippet triage = review the diff for bugs", "/snippet triage"], see: ["/snippets", "/alias"] }, + "/plan": { u: "[goal]", ex: ["/plan", "/plan ship the export feature"], see: ["/loop", "/team"] }, + "/blame": { u: "", ex: ["/blame src/app.js"], see: ["/explain", "/git"] }, + "/cheap": { u: "[status|off]", ex: ["/cheap", "/cheap status", "/cheap off"], see: ["/tight", "/lean", "/costtips", "/savings"] }, + "/lean": { u: "on|off", ex: ["/lean on", "/lean off"], see: ["/cheap", "/tight"] }, + "/style": { u: "", ex: ["/style concise", "/style secure"] }, + "/effort": { u: "[low|medium|high|xhigh|max|ultracode]", a: [["(Claude only)", "thinking depth; omit for the slider"]], ex: ["/effort", "/effort high"], see: ["/mode", "/god-prompt"] }, + "/estimate": { u: "", ex: ["/estimate refactor the auth module"], see: ["/tokens", "/cost"] }, + "/fallback": { u: "[on|off]", ex: ["/fallback on", "/fallback off"] }, + "/guard": { u: "[enforce|warn|off]", ex: ["/guard", "/guard enforce", "/guard off"], see: ["/permissions", "/policy"] }, + "/permissions": { u: "— use /allow and /deny ", ex: ["/permissions", "/allow run_command(git*)", "/deny write_file(.env)"], see: ["/guard", "/policy"] }, + "/cache": { u: "[on|off|clear]", ex: ["/cache", "/cache on", "/cache clear"], see: ["/warm", "/cheap"] }, + "/api": { u: " [key]", a: [["base-url", "any OpenAI-compatible endpoint"]], ex: ["/api https://openrouter.ai/api/v1 meta-llama/llama-3-70b"], see: ["/engine", "/models"] }, + "/docs": { u: "[topic|words]", ex: ["/docs", "/docs modes", "/docs how do I undo"], see: ["/help", "/keys"] }, + "/gaps": { u: "[plan]", a: [["plan", "turn the TODO/FIXME markers into a task plan"]], ex: ["/gaps", "/gaps plan"], see: ["/todo", "/plan"] }, + "/color": { u: "|reset", ex: ["/color teal", "/color 208", "/color #c0ffee", "/color reset"], see: ["/colors", "/theme", "/gradient"] }, + "/gradient": { u: "", ex: ["/gradient aurora", "/gradient reset"], see: ["/color", "/theme"] }, + "/mouse": { u: "[off]", a: [["off", "release the mouse so you can select & copy text"]], ex: ["/mouse", "/mouse off"] }, + "/theme": { u: "[name]", ex: ["/theme", "/theme mono"], see: ["/color", "/colors", "/gradient"] }, + "/pentest": { u: " [--authorized]", a: [["target", "host/app you are AUTHORIZED to test"], ["--authorized", "confirm you have written permission"]], ex: ["/pentest 10.0.0.5 --authorized"], see: ["/hack", "/scan"] }, + "/scan": { u: "", ex: ["/scan example.com"], see: ["/pentest"] }, + "/offline": { u: "on|off", ex: ["/offline on", "/offline off"], see: ["/redact"] }, + "/todo": { u: "[TAG]", a: [["TAG", "filter, e.g. FIXME or HACK; omit for all"]], ex: ["/todo", "/todo FIXME"], see: ["/gaps", "/stats"] }, + "/login": { u: "[code|google|github]", ex: ["/login", "/login google"], see: ["/logout", "/whoami"] }, + "/setup": { u: "", ex: ["/setup"], see: ["/engine", "/doctor"] }, + "/update": { u: "[apply|--check]", a: [["apply", "install the newer version now"]], ex: ["/update", "/update apply"], see: ["/autoupdate", "/restart"] }, + "/autoupdate": { u: "on|check|off", ex: ["/autoupdate on", "/autoupdate off"] }, + "/next": { u: " | clear | rm ", ex: ["/next run the tests", "/next clear"], see: ["/loop"] }, + "/find": { u: "", a: [["n/N", "step through matches"], ["q", "close"]], ex: ["/find TODO", "/find race condition"], see: ["/pager", "/index"] }, + "/pager": { u: "[n]", a: [["n", "which recent tool output; omit for the newest"]], ex: ["/pager", "/pager 2"], see: ["/find", "/expand"] }, + "/mode": { u: "power|cost|speed|reset", ex: ["/mode power", "/mode reset"], see: ["/effort", "/model"] }, + "/autocompact": { u: "auto|off|", ex: ["/autocompact auto", "/autocompact off", "/autocompact 80%"], see: ["/compact", "/recap"] }, + "/recap": { u: "[on|off]", a: [["(no arg)", "recap now"], ["on|off", "toggle the after-task recap"]], ex: ["/recap", "/recap off"] }, + "/title": { u: "[text|on|off]", ex: ["/title", "/title auth refactor", "/title off"] }, + "/feature": { u: "create | remove | list", ex: ["/feature list", "/feature create triage review the diff for bugs", "/feature remove triage"], see: ["/alias", "/snippet", "/commands"] }, + "/cron": { u: "list | add \"\" | remove ", a: [["schedule", "cron expression, e.g. 0 9 * * *"]], ex: ["/cron list", "/cron add \"0 9 * * *\" run the nightly audit"] }, + "/expand": { u: "", ex: ["/expand"], see: ["/pager"] }, + "/vim": { u: "on|off", ex: ["/vim on", "/vim off"] }, + "/terminal-setup": { u: "[off]", ex: ["/terminal-setup", "/terminal-setup off"] }, + "/trust": { u: "", ex: ["/trust"], see: ["/policy", "/permissions"] }, + "/tokens": { u: "<@file|@dir>", ex: ["/tokens @src", "/tokens @README.md"], see: ["/estimate", "/context"] }, + "/dashboard": { u: "[stop]", ex: ["/dashboard", "/dashboard stop"], see: ["/open"] }, +}; + +// The description still comes from CMDS (passed in); this only adds usage/examples. +function get(name) { return HELP[name] || null; } + +// A single consistent usage line a handler can print on bad input, so the error +// a user hits matches the `/help ` card exactly. Returns "" if no syntax. +function usageLine(name) { + const h = HELP[name]; + if (!h || !h.u) return ""; + return "usage: " + name + (h.u.startsWith("—") || h.u === "" ? (h.u ? " " + h.u : "") : " " + h.u); +} + +// Render a help card. `desc` is the CMDS one-liner; C is an optional color kit +// { name, head, dim, flag } of (s)=>string formatters (identity if absent). +function card(name, desc, C) { + C = C || {}; + const id = (s) => s; + const name_ = C.name || id, head = C.head || id, dim = C.dim || id, flag = C.flag || id; + const h = HELP[name]; + const out = []; + out.push(name_(name) + (desc ? " " + dim("— " + desc) : "")); + if (h && h.u) out.push(" " + head("usage ") + name + (h.u.startsWith("—") ? " " + h.u : " " + h.u)); + else out.push(" " + head("usage ") + name + dim(" (no arguments)")); + if (h && h.a && h.a.length) { + out.push(" " + head("arguments")); + const w = Math.min(28, Math.max(...h.a.map((r) => r[0].length))); + for (const [k, v] of h.a) out.push(" " + flag(k.padEnd(w)) + " " + dim(v)); + } + if (h && h.ex && h.ex.length) { + out.push(" " + head("examples")); + for (const e of h.ex) out.push(" " + e); + } + if (h && h.see && h.see.length) out.push(" " + head("see also ") + h.see.join(" ")); + return out.join("\n"); +} + +// Is `tok` (with or without a leading slash) a command we can card? Returns the +// normalized "/name" or null. `names` is the live Set/array of real commands. +function resolve(tok, names) { + if (!tok) return null; + const t = tok.trim().replace(/^\/+/, ""); + const cand = "/" + t.toLowerCase(); + const has = names instanceof Set ? (n) => names.has(n) : (n) => names.indexOf(n) >= 0; + return has(cand) ? cand : null; +} + +module.exports = { HELP, get, usageLine, card, resolve }; diff --git a/package.json b/package.json index dcd8b58..0d63e80 100644 --- a/package.json +++ b/package.json @@ -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", + "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", "postinstall": "node scripts/postinstall.js", "docs": "node scripts/gen-nexus-docs.js" }, diff --git a/test/command-help.test.js b/test/command-help.test.js new file mode 100644 index 0000000..d9c3424 --- /dev/null +++ b/test/command-help.test.js @@ -0,0 +1,52 @@ +"use strict"; +// command-help suite (lib/cli/command-help.js + its /help wiring). +// Keeps the usage/examples table honest against the REAL command list parsed +// out of darknode.js, so a renamed or removed command can't leave a stale card. +const fs = require("fs"), path = require("path"); +const CmdHelp = require("../lib/cli/command-help"); + +let pass = 0, fail = 0; +const ok = (name, cond) => { if (cond) pass++; else { fail++; console.log(" \x1b[31mFAIL\x1b[0m " + name); } }; + +// Real command names: the CMDS table in darknode.js is the source of truth. +const src = fs.readFileSync(path.join(__dirname, "..", "darknode.js"), "utf8"); +const block = src.match(/const CMDS = \[([\s\S]*?)\n \];/); +ok("found the CMDS table", !!block); +const menu = new Set([...block[1].matchAll(/\["(\/[a-z0-9-]+)"/g)].map((m) => m[1])); +ok("CMDS has the expected scale (>120)", menu.size > 120); +// The full command set also includes handler-dispatched commands not in the menu +// (e.g. /allow, /deny) — same union builtinNames() builds at runtime. +const names = new Set([...menu, ...[...src.matchAll(/cmd === "(\/[a-z0-9-]+)"/g)].map((m) => m[1])]); + +// Every documented command is a real command. +const unknown = Object.keys(CmdHelp.HELP).filter((k) => !names.has(k)); +ok("every HELP key is a real command" + (unknown.length ? " (stray: " + unknown.join(", ") + ")" : ""), unknown.length === 0); + +// Every `see also` points at a real command. +const badSee = []; +for (const [k, h] of Object.entries(CmdHelp.HELP)) for (const s of (h.see || [])) if (!names.has(s)) badSee.push(k + "→" + s); +ok("every 'see also' target exists" + (badSee.length ? " (" + badSee.join(", ") + ")" : ""), badSee.length === 0); + +// Every example is a runnable slash command (its own, or a sibling it references +// — e.g. /permissions shows /allow and /deny). Catches typos and non-commands. +const startsWithCmd = (e) => { const first = e.split(/\s+/)[0]; return names.has(first); }; +const badEx = []; +for (const [k, h] of Object.entries(CmdHelp.HELP)) for (const e of (h.ex || [])) if (!startsWithCmd(e)) badEx.push(k + ": " + e); +ok("every example is a real slash command" + (badEx.length ? " (" + badEx.join(" | ") + ")" : ""), badEx.length === 0); + +// card() renders for EVERY real command (documented or not) without throwing. +let threw = null; +for (const n of menu) { try { const c = CmdHelp.card(n, "desc here"); if (!c.includes(n)) threw = n + " (missing name)"; } catch (e) { threw = n + " (" + e.message + ")"; } } +ok("card() renders every command" + (threw ? " — failed at " + threw : ""), threw === null); + +// usageLine echoes the command and is empty only when there are no args. +ok("usageLine includes the command", CmdHelp.usageLine("/loop").includes("/loop") && CmdHelp.usageLine("/loop").includes("")); +ok("usageLine is empty for an argless/unknown command", CmdHelp.usageLine("/clear") === "" && CmdHelp.usageLine("/nope") === ""); + +// resolve() accepts bare or slashed tokens, rejects unknowns. +ok("resolve maps a bare word to its command", CmdHelp.resolve("model", names) === "/model" && CmdHelp.resolve("/model", names) === "/model"); +ok("resolve is case-insensitive and trims", CmdHelp.resolve(" MODEL ", names) === "/model"); +ok("resolve returns null for an unknown token", CmdHelp.resolve("definitely-not", names) === null && CmdHelp.resolve("", names) === null); + +if (fail) { console.log("command-help: " + pass + " passed, " + fail + " FAILED"); process.exit(1); } +console.log("command-help: " + pass + " passed"); From 79e2bd0bf2f231c7d459598ed4c20c772bdb64ce Mon Sep 17 00:00:00 2001 From: Darknode-Official Date: Sat, 31 Oct 2026 16:25:52 -0700 Subject: [PATCH 2/2] Correct and complete the /help command cards After checking each card against the handler it documents: - fixed cards that listed the wrong arguments: /fallback (|off, not on|off), /snippet (save//del, not "name = text"), /api (adds key/off), /alias (adds rm), /branch (adds delete), /plan (add/done/clear/run); - added cards that were missing for arg-taking commands: /mcp, /marketplace, /cowork, /bench, /btw, /whatbroke, /ai-prompt. --- lib/cli/command-help.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/cli/command-help.js b/lib/cli/command-help.js index d26aa23..952e36c 100644 --- a/lib/cli/command-help.js +++ b/lib/cli/command-help.js @@ -21,7 +21,7 @@ const HELP = { "/help": { u: "[word]", ex: ["/help", "/help cost", "/help /model"], see: ["/docs", "/keys"] }, "/connect": { u: "", ex: ["/connect"], see: ["/engine", "/model", "/api"] }, - "/alias": { u: " = ", a: [["name", "the shortcut you'll type"], ["= …", "what it expands to — plain text or another /command"]], ex: ["/alias ship = /commit", "/alias rv = review this diff for security"] }, + "/alias": { u: " = | rm ", a: [["name = …", "what it expands to — plain text or another /command"], ["rm ", "delete an alias (bare /alias lists them)"]], ex: ["/alias ship = /commit", "/alias rv = review this diff for security", "/alias rm ship"] }, "/retry": { u: "", ex: ["/retry"] }, "/budget": { u: "|off", a: [["", "stop warning past this session spend"], ["off", "remove the cap"]], ex: ["/budget 5", "/budget off"], see: ["/cost", "/savings"] }, "/report": { u: "[json|save|since ]", a: [["json", "machine-readable output"], ["save", "write it to a file"], ["since ", "only usage on/after YYYY-MM-DD"]], ex: ["/report", "/report json", "/report since 2026-10-01"], see: ["/cost", "/compliance"] }, @@ -29,7 +29,7 @@ const HELP = { "/rewind": { u: "[N]", a: [["N", "checkpoint number (see /checkpoints); omit for a picker"]], ex: ["/rewind", "/rewind 3"], see: ["/checkpoints", "/undo", "/redo"] }, "/bisect": { u: "[test command]", a: [["test command", "how to tell pass from fail; auto-detected if omitted"]], ex: ["/bisect", "/bisect npm test"], see: ["/whatbroke", "/shrink"] }, "/shrink": { u: "[test command]", ex: ["/shrink", "/shrink npm test"], see: ["/bisect", "/whatbroke"] }, - "/branch": { u: "[new |]", a: [["new ", "fork a new conversation branch"], ["", "switch to an existing branch"]], ex: ["/branch", "/branch new spike", "/branch main"], see: ["/resume"] }, + "/branch": { u: "[new | | delete ]", a: [["new ", "fork a new conversation branch"], ["", "switch to an existing branch"], ["delete ", "remove a branch (not the current one)"]], ex: ["/branch", "/branch new spike", "/branch main", "/branch delete spike"], see: ["/resume"] }, "/export": { u: "[file]", a: [["file", "where to write the markdown; omit for a default name"]], ex: ["/export", "/export chat.md"], see: ["/copy"] }, "/fixshell": { u: "[check|all]", a: [["check", "report only, change nothing"], ["all", "also clear the larger shell state"]], ex: ["/fixshell", "/fixshell check"] }, "/model": { u: "[name|number]", a: [["name|number", "pick from the catalog; omit to list it"]], ex: ["/model", "/model 3", "/model sonnet"], see: ["/models", "/engine", "/compat"] }, @@ -61,19 +61,19 @@ const HELP = { "/verify": { u: "", ex: ["/verify"], see: ["/test", "/watch"] }, "/review-fast": { u: "", ex: ["/review-fast"], see: ["/codereview", "/review"] }, "/testgen": { u: "", ex: ["/testgen src/util.js", "/testgen parseDate"], see: ["/test"] }, - "/snippet": { u: " [= ] | ", a: [["name = text", "save a prompt macro"], ["name", "use a saved macro"]], ex: ["/snippet triage = review the diff for bugs", "/snippet triage"], see: ["/snippets", "/alias"] }, - "/plan": { u: "[goal]", ex: ["/plan", "/plan ship the export feature"], see: ["/loop", "/team"] }, + "/snippet": { u: "save | [args] | del ", a: [["save ", "save a prompt macro ($1 $2 $ARGUMENTS expand)"], [" [args]", "run a saved macro"], ["del ", "delete one"]], ex: ["/snippet save triage review the diff for bugs", "/snippet triage", "/snippet del triage"], see: ["/snippets", "/alias"] }, + "/plan": { u: "[goal] | add | done | clear | run", a: [["goal", "generate an editable checklist for it"], ["add ", "append a task"], ["done ", "toggle task n"], ["run", "work the checklist"]], ex: ["/plan ship the export feature", "/plan add write the migration", "/plan done 2", "/plan run"], see: ["/loop", "/team"] }, "/blame": { u: "", ex: ["/blame src/app.js"], see: ["/explain", "/git"] }, "/cheap": { u: "[status|off]", ex: ["/cheap", "/cheap status", "/cheap off"], see: ["/tight", "/lean", "/costtips", "/savings"] }, "/lean": { u: "on|off", ex: ["/lean on", "/lean off"], see: ["/cheap", "/tight"] }, "/style": { u: "", ex: ["/style concise", "/style secure"] }, "/effort": { u: "[low|medium|high|xhigh|max|ultracode]", a: [["(Claude only)", "thinking depth; omit for the slider"]], ex: ["/effort", "/effort high"], see: ["/mode", "/god-prompt"] }, "/estimate": { u: "", ex: ["/estimate refactor the auth module"], see: ["/tokens", "/cost"] }, - "/fallback": { u: "[on|off]", ex: ["/fallback on", "/fallback off"] }, + "/fallback": { u: "|off", a: [["", "auto-switch to it when the main model is rate-limited"], ["off", "clear the fallback"]], ex: ["/fallback sonnet", "/fallback off"], see: ["/model", "/mode"] }, "/guard": { u: "[enforce|warn|off]", ex: ["/guard", "/guard enforce", "/guard off"], see: ["/permissions", "/policy"] }, "/permissions": { u: "— use /allow and /deny ", ex: ["/permissions", "/allow run_command(git*)", "/deny write_file(.env)"], see: ["/guard", "/policy"] }, "/cache": { u: "[on|off|clear]", ex: ["/cache", "/cache on", "/cache clear"], see: ["/warm", "/cheap"] }, - "/api": { u: " [key]", a: [["base-url", "any OpenAI-compatible endpoint"]], ex: ["/api https://openrouter.ai/api/v1 meta-llama/llama-3-70b"], see: ["/engine", "/models"] }, + "/api": { u: " | key | off", a: [["base-url", "any OpenAI-compatible endpoint"], ["key ", "set the API key for this session"], ["off", "stop using the custom endpoint"]], ex: ["/api https://openrouter.ai/api/v1 meta-llama/llama-3-70b", "/api key sk-...", "/api off"], see: ["/engine", "/models"] }, "/docs": { u: "[topic|words]", ex: ["/docs", "/docs modes", "/docs how do I undo"], see: ["/help", "/keys"] }, "/gaps": { u: "[plan]", a: [["plan", "turn the TODO/FIXME markers into a task plan"]], ex: ["/gaps", "/gaps plan"], see: ["/todo", "/plan"] }, "/color": { u: "|reset", ex: ["/color teal", "/color 208", "/color #c0ffee", "/color reset"], see: ["/colors", "/theme", "/gradient"] }, @@ -103,6 +103,13 @@ const HELP = { "/trust": { u: "", ex: ["/trust"], see: ["/policy", "/permissions"] }, "/tokens": { u: "<@file|@dir>", ex: ["/tokens @src", "/tokens @README.md"], see: ["/estimate", "/context"] }, "/dashboard": { u: "[stop]", ex: ["/dashboard", "/dashboard stop"], see: ["/open"] }, + "/mcp": { u: "[list | add | remove | connect ]", a: [["list", "show configured MCP servers (default)"], ["add ", "add one from the catalog"], ["connect ", "(re)connect a server"]], ex: ["/mcp", "/mcp list", "/mcp add filesystem"], see: ["/hooks", "/trust"] }, + "/marketplace": { u: "[list | install | remove | init | publish]", a: [["list", "browse available agents/skills/hooks/pipelines"], ["install ", "install one"], ["init", "scaffold your own to publish"]], ex: ["/marketplace list", "/marketplace install code-review", "/marketplace init"] }, + "/cowork": { u: " ", a: [["strong", "the capable model that writes code"], ["weak", "a cheaper model for grunt work — haiku|sonnet|opus||ollama:"]], ex: ["/cowork opus haiku", "/cowork sonnet ollama:qwen2.5-coder"], see: ["/team", "/model"] }, + "/bench": { u: "", a: [["prompt", "run it on each engine; reports a speed / tokens / cost table"]], ex: ["/bench write a haiku about caches"], see: ["/race", "/ensemble"] }, + "/btw": { u: "", a: [["question", "answered from the conversation so far; NOT saved to history"]], ex: ["/btw what did we decide about retries?"], see: ["/find"] }, + "/whatbroke": { u: "[test command]", a: [["test command", "the failing test to blame; auto-detected if omitted"]], ex: ["/whatbroke", "/whatbroke npm test"], see: ["/bisect", "/shrink"] }, + "/ai-prompt": { u: "", a: [["rough prompt", "the AI rewrites & sharpens it, then drops the result in your input box to edit or send"]], ex: ["/ai-prompt make the login page nicer"], see: ["/god-prompt"] }, }; // The description still comes from CMDS (passed in); this only adds usage/examples.