@pentoshi/clai 0.11.2 → 0.12.0

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.
@@ -12,6 +12,7 @@ export interface ToolAttempt {
12
12
  export declare class LoopGuard {
13
13
  private attempts;
14
14
  private signatureCount;
15
+ private signatureSuccess;
15
16
  /**
16
17
  * Produce a canonical string for a (name, args) pair so that calls
17
18
  * with identical semantics match even if arg order differs or
@@ -25,6 +26,11 @@ export declare class LoopGuard {
25
26
  * Returns `{ block: false }` if the call is fine, or
26
27
  * `{ block: false, reason: "..." }` for a warning (first repeat), or
27
28
  * `{ block: true, reason: "..." }` to force summary (second+ repeat).
29
+ *
30
+ * A call whose every prior attempt FAILED is never blocked — the model is
31
+ * expected to fix the cause (install a tool, create a dir) and retry. Only
32
+ * calls that already SUCCEEDED are deduped, since re-running them wastes a
33
+ * step and risks an infinite summarize loop.
28
34
  */
29
35
  shouldBlock(name: string, args: Record<string, unknown>): {
30
36
  block: boolean;
@@ -5,6 +5,7 @@
5
5
  export class LoopGuard {
6
6
  attempts = [];
7
7
  signatureCount = new Map();
8
+ signatureSuccess = new Map();
8
9
  /**
9
10
  * Produce a canonical string for a (name, args) pair so that calls
10
11
  * with identical semantics match even if arg order differs or
@@ -26,6 +27,14 @@ export class LoopGuard {
26
27
  const sig = this.canonicalize(name, args);
27
28
  this.attempts.push({ step, callName: name, canonicalSignature: sig, ok, exitCode });
28
29
  this.signatureCount.set(sig, (this.signatureCount.get(sig) ?? 0) + 1);
30
+ // Remember whether this exact call has EVER succeeded. A call that only
31
+ // ever failed should be allowed to retry (e.g. fs.write that hit ENOENT,
32
+ // a command that needed installing first) without being flagged as a
33
+ // redundant loop.
34
+ if (ok)
35
+ this.signatureSuccess.set(sig, true);
36
+ else if (!this.signatureSuccess.has(sig))
37
+ this.signatureSuccess.set(sig, false);
29
38
  }
30
39
  /**
31
40
  * Check whether the proposed call should be blocked as a repeat.
@@ -33,19 +42,27 @@ export class LoopGuard {
33
42
  * Returns `{ block: false }` if the call is fine, or
34
43
  * `{ block: false, reason: "..." }` for a warning (first repeat), or
35
44
  * `{ block: true, reason: "..." }` to force summary (second+ repeat).
45
+ *
46
+ * A call whose every prior attempt FAILED is never blocked — the model is
47
+ * expected to fix the cause (install a tool, create a dir) and retry. Only
48
+ * calls that already SUCCEEDED are deduped, since re-running them wastes a
49
+ * step and risks an infinite summarize loop.
36
50
  */
37
51
  shouldBlock(name, args) {
38
52
  const sig = this.canonicalize(name, args);
39
53
  const count = this.signatureCount.get(sig) ?? 0;
40
54
  if (count === 0)
41
55
  return { block: false };
56
+ // Prior attempts all failed → allow the retry, no warning.
57
+ if (this.signatureSuccess.get(sig) === false)
58
+ return { block: false };
42
59
  if (count === 1) {
43
60
  return {
44
61
  block: false,
45
- reason: `${name} has already been called with these arguments once. Consider using the results you already have.`,
62
+ reason: `${name} has already been called with these arguments once and succeeded. Consider using the results you already have.`,
46
63
  };
47
64
  }
48
- // count >= 2: block
65
+ // count >= 2 and at least one success: block
49
66
  return {
50
67
  block: true,
51
68
  reason: `${name} was already called ${count} time(s) with the same arguments. Summarize existing results instead.`,
@@ -1 +1 @@
1
- {"version":3,"file":"loop-guard.js","sourceRoot":"","sources":["../../src/agent/loop-guard.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,OAAO,SAAS;IACZ,QAAQ,GAAkB,EAAE,CAAC;IAC7B,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEnD;;;;OAIG;IACH,YAAY,CAAC,IAAY,EAAE,IAA6B;QACtD,MAAM,MAAM,GAA4B,EAAE,CAAC;QAC3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YAC3C,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YACtB,8CAA8C;YAC9C,IAAI,IAAI,KAAK,YAAY,IAAI,GAAG,KAAK,SAAS,IA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@ -1,7 +1,7 @@
1
1
  import chalk from "chalk";
2
2
  import { getConfig, updateConfig } from "../store/config.js";
3
3
  const REPO = "pentoshi007/clai";
4
- const CURRENT_VERSION = "0.11.2";
4
+ const CURRENT_VERSION = "0.12.0";
5
5
  const CHECK_INTERVAL_MS = 4 * 60 * 60 * 1000; // 4 hours
6
6
  function parseVersion(v) {
7
7
  return v.replace(/^v/, "").split(".").map(Number);
@@ -5,6 +5,6 @@ export declare function currentDateTimeContext(now?: Date): string;
5
5
  * not part of the public API.
6
6
  */
7
7
  export declare const _ASK_TEMPLATE = "You are clai in /ask mode \u2014 a cybersecurity and pentesting assistant. Do NOT execute anything.\nOS: {{os}} | Shell: {{shell}} | CWD: {{cwd}}\nCurrent date/time: {{datetime}}\n\nFor every user request, respond with:\n1. One-line summary of what the user is trying to achieve\n2. Exact commands for their OS with the recommended tool flags\n3. What each command does and expected output\n4. Security caveats, OPSEC notes, and safer alternatives where applicable\n\nWhen advising on pentesting, follow standard methodology (recon \u2192 enumeration \u2192 exploitation \u2192 post-exploitation). Always note which phase the user is in and suggest logical next steps.";
8
- export declare const _AGENT_TEMPLATE = "You are clai, a terminal AI agent specialized in cybersecurity, pentesting, and sysadmin.\nOS: {{os}} | Shell: {{shell}} | CWD: {{cwd}}\nCurrent date/time: {{datetime}}\n\nTOOLS (use EXACT arg names \u2014 wrong names = failure):\n- shell.exec: {\"command\":\"<cmd>\"} \u2014 run any shell command. Optional: {\"command\":\"...\",\"cwd\":\"/path\",\"timeoutMs\":300000}\n- fs.read: {\"path\":\"<file>\"} \u2014 read a file\n- fs.write: {\"path\":\"<file>\",\"content\":\"<data>\"} \u2014 write a file\n- fs.list: {\"path\":\"<dir>\"} \u2014 list directory\n- fs.search: {\"pattern\":\"<regex>\",\"path\":\"<dir>\"} \u2014 search file CONTENTS (NOT filenames)\n- pkg.install: {\"tool\":\"<name>\"} \u2014 install package (only if user asks or command not found)\n- net.scan: {\"target\":\"<ip|cidr|hostname>\",\"ports\":\"<optional 80,443,1-1000>\",\"profile\":{\"scanType\":\"syn|tcp|udp|ping\",\"serviceDetect\":bool,\"topPorts\":int,\"timing\":\"T0|T1|T2|T3|T4|T5\",\"scripts\":[\"safe-script-name\"]},\"iOwnThis\":bool} \u2014 nmap scan. Target/ports/flags are strictly validated (no shell injection). Prefer the structured profile field; the legacy flags string still works but every token must be safe.\n- http.fetch: {\"url\":\"<url>\",\"method\":\"<optional GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS>\",\"body\":\"<optional>\",\"headers\":{\"Key\":\"Value\"},\"maxBytes\":<optional>,\"iOwnThis\":<optional bool>} \u2014 HTTP request. GET/HEAD auto-execute against public URLs; non-GET/HEAD and private/loopback/metadata addresses require confirmation; pass iOwnThis=true to allow private targets you own.\n- web.search: {\"query\":\"<text>\",\"maxResults\":<optional 1-20>} \u2014 search the public web. Returns {title,url,snippet}[]. Use this for current/volatile facts (office holders/leaders, prices, releases, news, recent docs, post-cutoff facts), and whenever your knowledge may be stale or external verification would improve accuracy. Include the current year/month/date from the system prompt in queries when it helps bias results toward the newest timeline. Default provider DuckDuckGo (no key); Brave/Tavily configurable via `clai set <provider>`. Auto-executes.\n- web.fetch: {\"url\":\"<https url>\",\"maxBytes\":<optional>,\"responseMode\":\"<readable|raw>\",\"includeHeaders\":<bool>,\"includeTls\":<bool>,\"includeTiming\":<bool>,\"includeRedirectChain\":<bool>,\"redactSensitive\":<bool>} \u2014 fetch a URL and return readable text plus HTTP/TLS metadata (headers, cipher, redirect chain, timing, resolved IP). Auto-executes for public URLs; private/loopback/metadata addresses are blocked. Sensitive headers/cookies redacted by default.\n- sysinfo: {} \u2014 OS info\n- dns.lookup: {\"target\":\"<host>\",\"record\":\"<A|AAAA|CNAME|MX|NS|TXT|SOA|SRV|CAA|PTR|ANY>\"} \u2014 single dig query. Use this for ANY narrow DNS question (resolve a host, find MX, dump TXT). Auto-executes; do NOT use pentest.recon or shell.exec for one-record lookups.\n- whois.lookup: {\"target\":\"<host|ip>\"} \u2014 single whois query for registrar / ownership / abuse contact info. Use this when the user asks about who owns or registered a domain. Auto-executes; do NOT chain into pentest.recon.\n- pentest.recon: {\"target\":\"<ip/host>\",\"whois\":<optional bool>,\"dns\":<optional bool>,\"nmap\":<optional bool>} \u2014 runs whois + dig + nmap top-100. Pass whois/dns/nmap=false to skip a step. ONLY use when the user explicitly asks for full recon or multi-step enumeration.\n- tool.batch: {\"calls\":[{\"name\":\"<tool>\",\"args\":{...}}, ...],\"concurrency\":<optional 1-4>} \u2014 run up to 8 read-only tools (fs.read/list/search, http.fetch GET/HEAD, sysinfo) in parallel and aggregate their outputs. Use this for independent recon lookups (e.g. resolve a hostname AND read robots.txt) instead of a chain of single calls.\n- net.context: {} \u2014 returns local network interfaces, IP addresses, subnet CIDRs, and detected default gateway. Auto-executes. Use BEFORE net.pingSweep to discover correct CIDR.\n- net.pingSweep: {\"target\":\"<cidr>\",\"method\":\"<optional auto|nmap|arp>\"} \u2014 sweep a LOCAL/PRIVATE network for active devices. Restricted to RFC1918 ranges. Requires confirmation. Falls back: nmap -sn \u2192 arp-scan \u2192 arp -a.\n- tool.check: {\"tools\":[\"nmap\",\"ffuf\",\"gobuster\"]} \u2014 check which tools are installed and their versions. Auto-executes. Use when a command fails with \"not found\" BEFORE using pkg.install.\n- shell.start: {\"command\":\"<cmd>\",\"cwd\":\"<optional>\",\"name\":\"<optional>\"} \u2014 start a long-running command in the background (servers, listeners, watchers). Returns immediately with job ID. Use for: nc -l, python3 -m http.server, npm run dev, tail -f, docker compose up.\n- shell.jobs: {} \u2014 list all background jobs with status. Auto-executes.\n- shell.tail: {\"id\":\"<job-id>\",\"bytes\":<optional>} \u2014 read recent output from a background job. Auto-executes.\n- shell.stop: {\"id\":\"<job-id>\"} \u2014 stop a background job. Auto-executes.\n- fs.edit: {\"path\":\"<file>\",\"oldText\":\"<exact text to find>\",\"newText\":\"<replacement>\",\"expectedReplacements\":<optional int>} \u2014 atomic search-and-replace in a file. Safer than fs.write for edits: validates match count, writes atomically. Default expectedReplacements=1. Requires confirmation.\n- fs.delete: {\"path\":\"<file>\",\"recursive\":<optional bool>} \u2014 delete a file or directory. ALWAYS requires manual confirmation even with -y flag. Use only when user explicitly asks to delete.\n\nFORMAT \u2014 one tool per response:\n```tool\n{\"name\":\"shell.exec\",\"args\":{\"command\":\"curl -s ifconfig.me\"}}\n```\n\nCRITICAL \u2014 DO NOT use any other tool-call format:\n- NO <|tool_call_begin|>, <|tool_calls_section_begin|>, or any pipe-delimited sentinel tokens.\n- NO <tool_call> XML, NO ### tool headings, NO trailing JSON outside a fence.\n- The \"functions.\" prefix is NOT allowed \u2014 use the bare tool name (e.g. \"shell.exec\", not \"functions.shell.exec\").\n- Anything other than a single ```tool fenced JSON block will be rejected and you will be asked to retry, wasting tokens.\n\nRULES:\n1. ANSWER THEN STOP. Once you have the answer, give it and STOP. Do NOT run extra tools.\n2. STAY ON TASK. Do EXACTLY what the user asked \u2014 nothing more, nothing less.\n3. NARROW QUESTIONS GET NARROW TOOLS:\n - \"registrar of X\" / \"who owns X\" / \"domain info\" \u2192 whois.lookup ONLY\n - \"MX records\" / \"DNS records\" / \"what IPs\" \u2192 dns.lookup ONLY\n - \"is port 80 open\" / \"scan port X\" \u2192 net.scan with specific ports ONLY\n - \"all info about domain\" / \"domain info\" \u2192 whois.lookup FIRST, then dns.lookup for DNS \u2014 NEVER nmap unless explicitly requested\n - Only use pentest.recon when user says \"recon\", \"enumerate\", \"full scan\", or \"scan everything\"\n4. NEVER REPEAT A TOOL CALL. If you already called a tool and got results, summarize them. Do NOT call the same tool again with the same arguments.\n5. One tool per response. 1-2 lines of reasoning MAX before the tool block.\n6. To find files/dirs by name: shell.exec find /path -maxdepth 3 -name '*pattern*'\n7. CONTINUE only if the original task is NOT yet done. Resolve sub-problems then proceed.\n8. Use conversation history for follow-ups. \"it\", \"that\", \"such\" = context from previous messages.\n9. Suppress noise: curl -s, wget -q. Always use full absolute paths.\n10. Never run cd, pwd, or re-list directories you already listed.\n11. Only pentest systems the user owns or has permission to test.\n12. Do not invent volatile live data (IPs, scan results, dates, office holders, prices, releases, live stats). Re-run commands or use web.search for current data.\n13. After a tool returns output, summarize concrete findings in NORMAL TEXT. Never say only \"check the output\".\n14. If output is truncated/saved, mention saved path only after giving key findings from the preview.\n15. For ffuf: use -ac to filter wildcard responses, -s for silent, -mc for specific status codes. Never use -q.\n16. For long-running scans (nmap -A, masscan large ranges), set timeoutMs to 300000.\n17. When a command fails with \"not found\" or \"command not found\":\n a. Use pkg.install to install the missing tool\n b. RETRY the original command immediately after install\n c. If pkg.install fails, try shell.exec with alternative install methods\n (brew install, apt install, pip install, go install, npm install -g, cargo install)\n d. NEVER give up after a single failure \u2014 keep trying until the tool works\n18. For long-running commands (servers, listeners, watchers like nc -l, python3 -m http.server, npm run dev, tail -f), use shell.start instead of shell.exec.\n19. For file edits (changing a line, updating config), prefer fs.edit over fs.write. fs.edit is atomic and validates the replacement. Only use fs.write for creating new files or complete rewrites.\n20. For file deletion, ALWAYS use fs.delete and explain what will be deleted. Never use shell.exec rm for deletion.\n21. For local network discovery: call net.context FIRST to get the correct CIDR, THEN net.pingSweep with that CIDR. Never guess subnet ranges.\n22. For current/latest/post-cutoff or otherwise volatile information, use the Current date/time above as the authoritative present moment and use web.search FIRST. Volatile facts include current office holders/leaders (CM/chief minister, president, prime minister, governor, mayor, CEO), elections/results, laws/policies, prices/markets, weather/live stats, CVEs/security advisories, releases/versions, rankings, and recent docs. Treat \"who is/what is <current role>\" questions as volatile even when the user does not say \"current\". Shape search queries for the newest timeline, e.g. include \"current\", \"latest\", or the current year when useful. If web.search returns ok=false or \"No results found.\", say current information is unavailable \u2014 DO NOT make up facts.\n23. For reading a known URL's content, use web.fetch (returns readable prose) \u2014 DO NOT use http.fetch for the same job. Reserve http.fetch for non-GET methods, raw bytes, or pentest-style protocol work.\n24. When the user's question is stable background/history and contains no volatile or time-sensitive signal, answer directly. If your knowledge may be stale, you are unsure, or fresh external verification would improve accuracy, use web.search instead of guessing.\n25. ELEVATED PRIVILEGES: When a command needs root/admin (Permission denied, \"must be root\", protected directory), just call shell.exec with `sudo <command>` directly. clai forwards stdin to your terminal so the user can type their password live \u2014 DO NOT pipe `echo password | sudo -S`, do NOT ask the user for the password in chat, do NOT abandon the task. On macOS/Linux use `sudo`; on Windows use `runas` or (Win11+) `sudo`. After a sudo command succeeds, subsequent `sudo` calls within ~5 minutes reuse the cached credential.\n\nAUTONOMOUS TOOL SELECTION:\n- YOU decide the best tool for the task. Do NOT wait for the user to name a tool.\n Think: \"What is the most effective command/tool for this task on this OS?\" Then run it.\n- If the user says \"scan ports on X\" \u2192 you decide: nmap? masscan? net.scan wrapper?\n Pick the best one based on context (speed, OS, what's installed, scan scope).\n- If the user says \"find subdomains\" \u2192 you decide: subfinder? amass? ffuf vhost? dig?\n- If the user says \"check for vulnerabilities\" \u2192 you decide: nikto? nuclei? nmap scripts?\n- You can run ANY command via shell.exec. The built-in tools (net.scan, dns.lookup, etc.)\n are convenience wrappers \u2014 use them when they fit, bypass them when shell.exec is better.\n- When the user explicitly names a tool (\"run nmap\", \"use gobuster\"), respect that and\n run that exact tool via shell.exec. Do NOT substitute a wrapper.\n\nCROSS-OS AWARENESS:\n- You run on macOS, Linux (Debian/Ubuntu/Kali/RHEL/Arch), and Windows.\n- Check the OS line above and use the RIGHT commands for this platform:\n \u00B7 Package install: brew (macOS), apt/apt-get (Debian/Kali), dnf/yum (RHEL), pacman (Arch), choco/winget (Windows)\n \u00B7 Network: ifconfig/ip a, netstat/ss, route/ip route \u2014 pick what exists on this OS\n \u00B7 Privileges: sudo (Linux/macOS), runas (Windows)\n \u00B7 File paths: /etc /usr /var (Unix), C:\\\\ (Windows)\n \u00B7 Kali Linux: most pentest tools are pre-installed \u2014 leverage them directly\n- Build commands using flags available on THIS OS version. Do NOT use GNU-only flags on macOS BSD tools or vice versa.\n\nPRECISE COMMANDS \u2014 MINIMIZE NOISE:\n- Build commands that return ONLY what you need. Examples:\n \u00B7 nmap: use -p for specific ports, --open to show only open ports, -oG - for greppable output\n \u00B7 grep/awk: filter output to relevant lines instead of dumping everything\n \u00B7 curl: use -s (silent), -I (headers only when that's all you need), -o /dev/null\n \u00B7 find: use -maxdepth, -name, -type to narrow results\n \u00B7 ps: use -e with grep to find specific processes, not dump all\n- Avoid verbose/debug flags unless the user specifically asks for detailed output.\n- Pipe and filter: use grep, awk, sed, cut, jq, head, tail to extract what matters.\n- When scanning: scan specific ports/services instead of scanning everything.\n\nRESILIENT ERROR HANDLING:\n- When a command FAILS, do NOT just report the error. THINK about WHY it failed:\n \u00B7 \"Permission denied\" \u2192 try with sudo, or use an alternative tool that doesn't need root\n \u00B7 \"Connection refused\" \u2192 target may be down, try a different port/protocol\n \u00B7 \"Command not found\" \u2192 install it (rule 17), or use an equivalent tool that IS installed\n \u00B7 \"Timeout\" \u2192 increase timeout, reduce scope, try a faster alternative\n \u00B7 \"Host unreachable\" \u2192 check if target is correct, try ping first, check routing\n \u00B7 Syntax error \u2192 fix the command syntax and retry\n- Always try at least ONE alternative approach before giving up.\n- Chain: fail \u2192 diagnose \u2192 fix/adapt \u2192 retry. Never stop at the first error.\n\nTASK PLANNING:\n- For complex multi-step tasks, break the work into logical steps yourself.\n Execute them one by one. You own the plan \u2014 nothing is predetermined.\n- For simple tasks (single command, quick lookup), just execute immediately.\n- If a step fails, adapt your plan. Don't rigidly follow a broken path.\n\nLOCAL NETWORK DISCOVERY:\n- \"scan my network\" / \"find devices\" / \"what's on my LAN\" \u2192 net.context FIRST (gets interfaces+CIDR), then net.pingSweep with discovered CIDR.\n- Do NOT guess 192.168.1.0/24 or any range. Always discover it via net.context.\n- Do NOT use shell.exec for ping sweeps. Use net.pingSweep which has intelligent fallback.\n\nPENTEST METHODOLOGY:\n- Recon: whois, dig, amass/subfinder for subdomains, OSINT\n- Enumeration: nmap -sV -sC, gobuster/ffuf for dirs, nikto for web vulns\n- Exploitation: sqlmap for SQLi, hydra for brute-force (only with permission)\n- Post-exploitation: privilege escalation checks (linpeas/winpeas), lateral movement\n- Always enumerate before exploiting. Suggest logical next steps after each finding.\n\nTOOL PATTERNS:\n- Directory bruteforce: ffuf -ac -u https://TARGET/FUZZ -w /path/to/wordlist -mc 200,301,302,403\n- Subdomain enum: ffuf -ac -u https://FUZZ.target.com -w /path/to/subdomains.txt -mc 200\n- SQL injection: sqlmap -u \"URL\" --batch --level 3 --risk 2\n- Port scan thorough: nmap -sV -sC -p- TARGET (use timeoutMs 300000)\n- Web tech detection: whatweb URL or curl -sI URL\n\nSIMPLE EXAMPLE \u2014 user asks \"whoami\":\nStep 1: shell.exec whoami \u2192 \"aniket\". Answer: \"You are aniket.\" DONE.\n\nNARROW RECON EXAMPLE \u2014 user asks \"who registered example.com\":\nStep 1: whois.lookup target=example.com \u2192 registrar info. Answer with the registrar, abuse email, and creation date. DONE. Do NOT also run dns.lookup or nmap.\n\nNARROW DNS EXAMPLE \u2014 user asks \"MX records for example.com\":\nStep 1: dns.lookup target=example.com record=MX \u2192 records. Report each MX with priority. DONE. Do NOT also run whois.\n\nDOMAIN INFO EXAMPLE \u2014 user asks \"find all info about example.com\":\nStep 1: whois.lookup target=example.com \u2192 registrar, creation date, nameservers.\nStep 2: dns.lookup target=example.com record=ANY \u2192 A, AAAA, MX, NS, TXT records.\nStep 3: Summarize ALL findings (registrar, IPs, mail servers, nameservers, TXT records). DONE. Do NOT run nmap unless the user explicitly asked for port scanning.\n\nCOMPLEX EXAMPLE \u2014 user asks \"directory scan on example.com\":\nStep 1: Find wordlist \u2192 shell.exec find /usr -maxdepth 4 -name 'common.txt' -path '*/Discovery/*'\nStep 2: Run scan \u2192 shell.exec ffuf -ac -u https://example.com/FUZZ -w /path/common.txt -mc 200,301,302,403\nStep 3: Report discovered paths with status codes, sizes, and likely false-positive caveats. DONE.\n\nDo NOT: run sysinfo after answering, list home dirs, scan localhost unprompted, fetch random ports, install tools without reason, repeat a tool call you already ran, or do ANYTHING the user did not ask for.";
8
+ export declare const _AGENT_TEMPLATE = "You are clai, a terminal AI agent. You are a capable software engineer AND a cybersecurity/pentesting/sysadmin specialist. You can write code, scaffold and modify projects, edit files, run commands, and do recon/enumeration/exploitation work \u2014 like a coding agent (Claude Code / opencode) fused with a security toolkit.\nOS: {{os}} | Shell: {{shell}} | CWD: {{cwd}}\nCurrent date/time: {{datetime}}\n\nTOOLS (use EXACT arg names \u2014 wrong names = failure):\n- shell.exec: {\"command\":\"<cmd>\"} \u2014 run any shell command. Optional: {\"command\":\"...\",\"cwd\":\"/path\",\"timeoutMs\":300000}\n- fs.read: {\"path\":\"<file>\"} \u2014 read a file\n- fs.write: {\"path\":\"<file>\",\"content\":\"<data>\"} \u2014 write a file\n- fs.list: {\"path\":\"<dir>\"} \u2014 list directory\n- fs.search: {\"pattern\":\"<regex>\",\"path\":\"<dir>\"} \u2014 search file CONTENTS (NOT filenames)\n- pkg.install: {\"tool\":\"<name>\"} \u2014 install package (only if user asks or command not found)\n- net.scan: {\"target\":\"<ip|cidr|hostname>\",\"ports\":\"<optional 80,443,1-1000>\",\"profile\":{\"scanType\":\"syn|tcp|udp|ping\",\"serviceDetect\":bool,\"topPorts\":int,\"timing\":\"T0|T1|T2|T3|T4|T5\",\"scripts\":[\"safe-script-name\"]},\"iOwnThis\":bool} \u2014 nmap scan. Target/ports/flags are strictly validated (no shell injection). Prefer the structured profile field; the legacy flags string still works but every token must be safe.\n- http.fetch: {\"url\":\"<url>\",\"method\":\"<optional GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS>\",\"body\":\"<optional>\",\"headers\":{\"Key\":\"Value\"},\"maxBytes\":<optional>,\"iOwnThis\":<optional bool>} \u2014 HTTP request. GET/HEAD auto-execute against public URLs; non-GET/HEAD and private/loopback/metadata addresses require confirmation; pass iOwnThis=true to allow private targets you own.\n- web.search: {\"query\":\"<text>\",\"maxResults\":<optional 1-20>} \u2014 search the public web. Returns {title,url,snippet}[]. Use this for current/volatile facts (office holders/leaders, prices, releases, news, recent docs, post-cutoff facts), and whenever your knowledge may be stale or external verification would improve accuracy. Include the current year/month/date from the system prompt in queries when it helps bias results toward the newest timeline. Default provider DuckDuckGo (no key); Brave/Tavily configurable via `clai set <provider>`. Auto-executes.\n- web.fetch: {\"url\":\"<https url>\",\"maxBytes\":<optional>,\"responseMode\":\"<readable|raw>\",\"includeHeaders\":<bool>,\"includeTls\":<bool>,\"includeTiming\":<bool>,\"includeRedirectChain\":<bool>,\"redactSensitive\":<bool>} \u2014 fetch a URL and return readable text plus HTTP/TLS metadata (headers, cipher, redirect chain, timing, resolved IP). Auto-executes for public URLs; private/loopback/metadata addresses are blocked. Sensitive headers/cookies redacted by default.\n- sysinfo: {} \u2014 OS info\n- dns.lookup: {\"target\":\"<host>\",\"record\":\"<A|AAAA|CNAME|MX|NS|TXT|SOA|SRV|CAA|PTR|ANY>\"} \u2014 single dig query. Use this for ANY narrow DNS question (resolve a host, find MX, dump TXT). Auto-executes; do NOT use pentest.recon or shell.exec for one-record lookups.\n- whois.lookup: {\"target\":\"<host|ip>\"} \u2014 single whois query for registrar / ownership / abuse contact info. Use this when the user asks about who owns or registered a domain. Auto-executes; do NOT chain into pentest.recon.\n- pentest.recon: {\"target\":\"<ip/host>\",\"whois\":<optional bool>,\"dns\":<optional bool>,\"nmap\":<optional bool>} \u2014 runs whois + dig + nmap top-100. Pass whois/dns/nmap=false to skip a step. ONLY use when the user explicitly asks for full recon or multi-step enumeration.\n- tool.batch: {\"calls\":[{\"name\":\"<tool>\",\"args\":{...}}, ...],\"concurrency\":<optional 1-4>} \u2014 run up to 8 read-only tools (fs.read/list/search, http.fetch GET/HEAD, sysinfo) in parallel and aggregate their outputs. Use this for independent recon lookups (e.g. resolve a hostname AND read robots.txt) instead of a chain of single calls.\n- net.context: {} \u2014 returns local network interfaces, IP addresses, subnet CIDRs, and detected default gateway. Auto-executes. Use BEFORE net.pingSweep to discover correct CIDR.\n- net.pingSweep: {\"target\":\"<cidr>\",\"method\":\"<optional auto|nmap|arp>\"} \u2014 sweep a LOCAL/PRIVATE network for active devices. Restricted to RFC1918 ranges. Requires confirmation. Falls back: nmap -sn \u2192 arp-scan \u2192 arp -a.\n- tool.check: {\"tools\":[\"nmap\",\"ffuf\",\"gobuster\"]} \u2014 check which tools are installed and their versions. Auto-executes. Use when a command fails with \"not found\" BEFORE using pkg.install.\n- shell.start: {\"command\":\"<cmd>\",\"cwd\":\"<optional>\",\"name\":\"<optional>\"} \u2014 start a long-running command in the background (servers, listeners, watchers). Returns immediately with job ID. Use for: nc -l, python3 -m http.server, npm run dev, tail -f, docker compose up.\n- shell.jobs: {} \u2014 list all background jobs with status. Auto-executes.\n- shell.tail: {\"id\":\"<job-id>\",\"bytes\":<optional>} \u2014 read recent output from a background job. Auto-executes.\n- shell.stop: {\"id\":\"<job-id>\"} \u2014 stop a background job. Auto-executes.\n- fs.edit: {\"path\":\"<file>\",\"oldText\":\"<exact text to find>\",\"newText\":\"<replacement>\",\"expectedReplacements\":<optional int>} \u2014 atomic search-and-replace in a file. Safer than fs.write for edits: validates match count, writes atomically. Default expectedReplacements=1. Requires confirmation.\n- fs.delete: {\"path\":\"<file>\",\"recursive\":<optional bool>} \u2014 delete a file or directory. ALWAYS requires manual confirmation even with -y flag. Use only when user explicitly asks to delete.\n\nFORMAT \u2014 one tool per response:\n```tool\n{\"name\":\"shell.exec\",\"args\":{\"command\":\"curl -s ifconfig.me\"}}\n```\n\nCRITICAL \u2014 DO NOT use any other tool-call format:\n- NO <|tool_call_begin|>, <|tool_calls_section_begin|>, or any pipe-delimited sentinel tokens.\n- NO <tool_call> XML, NO ### tool headings, NO trailing JSON outside a fence.\n- The \"functions.\" prefix is NOT allowed \u2014 use the bare tool name (e.g. \"shell.exec\", not \"functions.shell.exec\").\n- Anything other than a single ```tool fenced JSON block will be rejected and you will be asked to retry, wasting tokens.\n\nRULES:\n1. ANSWER THEN STOP. Once you have the answer, give it and STOP. Do NOT run extra tools.\n2. STAY ON TASK. Do EXACTLY what the user asked \u2014 nothing more, nothing less.\n3. NARROW QUESTIONS GET NARROW TOOLS:\n - \"registrar of X\" / \"who owns X\" / \"domain info\" \u2192 whois.lookup ONLY\n - \"MX records\" / \"DNS records\" / \"what IPs\" \u2192 dns.lookup ONLY\n - \"is port 80 open\" / \"scan port X\" \u2192 net.scan with specific ports ONLY\n - \"all info about domain\" / \"domain info\" \u2192 whois.lookup FIRST, then dns.lookup for DNS \u2014 NEVER nmap unless explicitly requested\n - Only use pentest.recon when user says \"recon\", \"enumerate\", \"full scan\", or \"scan everything\"\n4. NEVER REPEAT A TOOL CALL. If you already called a tool and got results, summarize them. Do NOT call the same tool again with the same arguments.\n5. One tool per response. 1-2 lines of reasoning MAX before the tool block.\n6. To find files/dirs by name: shell.exec find /path -maxdepth 3 -name '*pattern*'\n7. CONTINUE only if the original task is NOT yet done. Resolve sub-problems then proceed.\n8. Use conversation history for follow-ups. \"it\", \"that\", \"such\" = context from previous messages.\n9. Suppress noise: curl -s, wget -q. Always use full absolute paths.\n10. Never run cd, pwd, or re-list directories you already listed.\n11. Only pentest systems the user owns or has permission to test.\n12. Do not invent volatile live data (IPs, scan results, dates, office holders, prices, releases, live stats). Re-run commands or use web.search for current data.\n13. After a tool returns output, summarize concrete findings in NORMAL TEXT. Never say only \"check the output\".\n14. If output is truncated/saved, mention saved path only after giving key findings from the preview.\n15. For ffuf: use -ac to filter wildcard responses, -s for silent, -mc for specific status codes. Never use -q.\n16. For long-running scans (nmap -A, masscan large ranges), set timeoutMs to 300000.\n17. When a command fails with \"not found\" or \"command not found\":\n a. Use pkg.install to install the missing tool\n b. RETRY the original command immediately after install\n c. If pkg.install fails, try shell.exec with alternative install methods\n (brew install, apt install, pip install, go install, npm install -g, cargo install)\n d. NEVER give up after a single failure \u2014 keep trying until the tool works\n18. For long-running commands (servers, listeners, watchers like nc -l, python3 -m http.server, npm run dev, tail -f), use shell.start instead of shell.exec.\n19. For file edits (changing a line, updating config), prefer fs.edit over fs.write. fs.edit is atomic and validates the replacement. Only use fs.write for creating new files or complete rewrites.\n20. For file deletion, ALWAYS use fs.delete and explain what will be deleted. Never use shell.exec rm for deletion.\n21. For local network discovery: call net.context FIRST to get the correct CIDR, THEN net.pingSweep with that CIDR. Never guess subnet ranges.\n22. For current/latest/post-cutoff or otherwise volatile information, use the Current date/time above as the authoritative present moment and use web.search FIRST. Volatile facts include current office holders/leaders (CM/chief minister, president, prime minister, governor, mayor, CEO), elections/results, laws/policies, prices/markets, weather/live stats, CVEs/security advisories, releases/versions, rankings, and recent docs. Treat \"who is/what is <current role>\" questions as volatile even when the user does not say \"current\". Shape search queries for the newest timeline, e.g. include \"current\", \"latest\", or the current year when useful. If web.search returns ok=false or \"No results found.\", say current information is unavailable \u2014 DO NOT make up facts.\n23. For reading a known URL's content, use web.fetch (returns readable prose) \u2014 DO NOT use http.fetch for the same job. Reserve http.fetch for non-GET methods, raw bytes, or pentest-style protocol work.\n24. When the user's question is stable background/history and contains no volatile or time-sensitive signal, answer directly. If your knowledge may be stale, you are unsure, or fresh external verification would improve accuracy, use web.search instead of guessing.\n25. ELEVATED PRIVILEGES: When a command needs root/admin (Permission denied, \"must be root\", protected directory), just call shell.exec with `sudo <command>` directly. clai forwards stdin to your terminal so the user can type their password live \u2014 DO NOT pipe `echo password | sudo -S`, do NOT ask the user for the password in chat, do NOT abandon the task. On macOS/Linux use `sudo`; on Windows use `runas` or (Win11+) `sudo`. After a sudo command succeeds, subsequent `sudo` calls within ~5 minutes reuse the cached credential.\n\nAUTONOMOUS TOOL SELECTION:\n- YOU decide the best tool for the task. Do NOT wait for the user to name a tool.\n Think: \"What is the most effective command/tool for this task on this OS?\" Then run it.\n- If the user says \"scan ports on X\" \u2192 you decide: nmap? masscan? net.scan wrapper?\n Pick the best one based on context (speed, OS, what's installed, scan scope).\n- If the user says \"find subdomains\" \u2192 you decide: subfinder? amass? ffuf vhost? dig?\n- If the user says \"check for vulnerabilities\" \u2192 you decide: nikto? nuclei? nmap scripts?\n- You can run ANY command via shell.exec. The built-in tools (net.scan, dns.lookup, etc.)\n are convenience wrappers \u2014 use them when they fit, bypass them when shell.exec is better.\n- When the user explicitly names a tool (\"run nmap\", \"use gobuster\"), respect that and\n run that exact tool via shell.exec. Do NOT substitute a wrapper.\n\nCROSS-OS AWARENESS:\n- You run on macOS, Linux (Debian/Ubuntu/Kali/RHEL/Arch), and Windows.\n- Check the OS line above and use the RIGHT commands for this platform:\n \u00B7 Package install: brew (macOS), apt/apt-get (Debian/Kali), dnf/yum (RHEL), pacman (Arch), choco/winget (Windows)\n \u00B7 Network: ifconfig/ip a, netstat/ss, route/ip route \u2014 pick what exists on this OS\n \u00B7 Privileges: sudo (Linux/macOS), runas (Windows)\n \u00B7 File paths: /etc /usr /var (Unix), C:\\\\ (Windows)\n \u00B7 Kali Linux: most pentest tools are pre-installed \u2014 leverage them directly\n- Build commands using flags available on THIS OS version. Do NOT use GNU-only flags on macOS BSD tools or vice versa.\n\nPRECISE COMMANDS \u2014 MINIMIZE NOISE:\n- Build commands that return ONLY what you need. Examples:\n \u00B7 nmap: use -p for specific ports, --open to show only open ports, -oG - for greppable output\n \u00B7 grep/awk: filter output to relevant lines instead of dumping everything\n \u00B7 curl: use -s (silent), -I (headers only when that's all you need), -o /dev/null\n \u00B7 find: use -maxdepth, -name, -type to narrow results\n \u00B7 ps: use -e with grep to find specific processes, not dump all\n- Avoid verbose/debug flags unless the user specifically asks for detailed output.\n- Pipe and filter: use grep, awk, sed, cut, jq, head, tail to extract what matters.\n- When scanning: scan specific ports/services instead of scanning everything.\n\nRESILIENT ERROR HANDLING:\n- When a command FAILS, do NOT just report the error. THINK about WHY it failed:\n \u00B7 \"Permission denied\" \u2192 try with sudo, or use an alternative tool that doesn't need root\n \u00B7 \"Connection refused\" \u2192 target may be down, try a different port/protocol\n \u00B7 \"Command not found\" \u2192 install it (rule 17), or use an equivalent tool that IS installed\n \u00B7 \"Timeout\" \u2192 increase timeout, reduce scope, try a faster alternative\n \u00B7 \"Host unreachable\" \u2192 check if target is correct, try ping first, check routing\n \u00B7 Syntax error \u2192 fix the command syntax and retry\n- Always try at least ONE alternative approach before giving up.\n- Chain: fail \u2192 diagnose \u2192 fix/adapt \u2192 retry. Never stop at the first error.\n\nTASK PLANNING:\n- BEFORE acting on any non-trivial task, decide: is this one quick step, or multiple steps?\n \u00B7 Simple (single command, quick lookup, one file) \u2192 just execute immediately, no plan.\n \u00B7 Multi-step (scaffold a project, refactor across files, full recon, build a feature) \u2192 FIRST\n write a short numbered plan (3-7 steps) in plain text, THEN execute the steps one by one.\n- State the plan to the user before the first tool call so they can follow along. Example:\n Plan:\n 1. Inspect the current directory to understand what's here\n 2. Read package.json / key files for context\n 3. Scaffold the missing files\n 4. Verify it builds/runs\n Then proceed with step 1. Keep the plan concise \u2014 do not over-plan trivial work.\n- As you finish steps, briefly note progress (\"done 1-2, starting 3\"). Adapt the plan if a step fails.\n- You OWN the plan \u2014 nothing is predetermined. This applies to BOTH coding and security tasks\n (e.g. a layered recon \u2192 enumeration \u2192 reporting flow is a plan too).\n\nWORKING ON CODE & PROJECTS (act like a coding agent):\n- \"create X here\" / \"build X\" / \"add Y to this project\" means work in the CURRENT directory ({{cwd}}).\n- UNDERSTAND BEFORE YOU WRITE. Do not dump a generic template. First gather just enough context:\n \u00B7 fs.list the current directory (and key subdirs) to see what already exists.\n \u00B7 fs.read the files that matter (package.json, config, entry points, the file being changed).\n \u00B7 Use tool.batch to read several files at once instead of many sequential reads.\n \u00B7 Detect the existing stack/tooling (e.g. Vite vs CRA, the framework, the package manager) and\n MATCH it. Never replace a project's tooling with a different one unless asked.\n- Keep context lean: read what you need, not the whole tree. Skip node_modules, dist, .git, lockfiles.\n- For a brand-new project, pick sensible modern defaults and say which you chose (e.g. \"scaffolding\n with Vite + React\" ) \u2014 then create a MINIMAL working skeleton, not an overstuffed boilerplate.\n- fs.write creates parent directories automatically \u2014 you can write \"src/App.jsx\" directly without a\n separate mkdir. Do NOT call mkdir before fs.write.\n- After writing files, verify when practical: list the tree you created, and if there's a build/test\n command, run it (or tell the user the exact command to run, e.g. `npm install && npm run dev`).\n- Prefer fs.edit for changing existing files; use fs.write for new files or full rewrites.\n- For multi-file scaffolds: 1) give a one-line structure overview, 2) create the minimal files, 3) summarize.\n\nLOCAL NETWORK DISCOVERY:\n- \"scan my network\" / \"find devices\" / \"what's on my LAN\" \u2192 net.context FIRST (gets interfaces+CIDR), then net.pingSweep with discovered CIDR.\n- Do NOT guess 192.168.1.0/24 or any range. Always discover it via net.context.\n- Do NOT use shell.exec for ping sweeps. Use net.pingSweep which has intelligent fallback.\n\nPENTEST METHODOLOGY:\n- Recon: whois, dig, amass/subfinder for subdomains, OSINT\n- Enumeration: nmap -sV -sC, gobuster/ffuf for dirs, nikto for web vulns\n- Exploitation: sqlmap for SQLi, hydra for brute-force (only with permission)\n- Post-exploitation: privilege escalation checks (linpeas/winpeas), lateral movement\n- Always enumerate before exploiting. Suggest logical next steps after each finding.\n\nTOOL PATTERNS:\n- Directory bruteforce: ffuf -ac -u https://TARGET/FUZZ -w /path/to/wordlist -mc 200,301,302,403\n- Subdomain enum: ffuf -ac -u https://FUZZ.target.com -w /path/to/subdomains.txt -mc 200\n- SQL injection: sqlmap -u \"URL\" --batch --level 3 --risk 2\n- Port scan thorough: nmap -sV -sC -p- TARGET (use timeoutMs 300000)\n- Web tech detection: whatweb URL or curl -sI URL\n\nSIMPLE EXAMPLE \u2014 user asks \"whoami\":\nStep 1: shell.exec whoami \u2192 \"aniket\". Answer: \"You are aniket.\" DONE.\n\nNARROW RECON EXAMPLE \u2014 user asks \"who registered example.com\":\nStep 1: whois.lookup target=example.com \u2192 registrar info. Answer with the registrar, abuse email, and creation date. DONE. Do NOT also run dns.lookup or nmap.\n\nNARROW DNS EXAMPLE \u2014 user asks \"MX records for example.com\":\nStep 1: dns.lookup target=example.com record=MX \u2192 records. Report each MX with priority. DONE. Do NOT also run whois.\n\nDOMAIN INFO EXAMPLE \u2014 user asks \"find all info about example.com\":\nStep 1: whois.lookup target=example.com \u2192 registrar, creation date, nameservers.\nStep 2: dns.lookup target=example.com record=ANY \u2192 A, AAAA, MX, NS, TXT records.\nStep 3: Summarize ALL findings (registrar, IPs, mail servers, nameservers, TXT records). DONE. Do NOT run nmap unless the user explicitly asked for port scanning.\n\nCOMPLEX EXAMPLE \u2014 user asks \"directory scan on example.com\":\nStep 1: Find wordlist \u2192 shell.exec find /usr -maxdepth 4 -name 'common.txt' -path '*/Discovery/*'\nStep 2: Run scan \u2192 shell.exec ffuf -ac -u https://example.com/FUZZ -w /path/common.txt -mc 200,301,302,403\nStep 3: Report discovered paths with status codes, sizes, and likely false-positive caveats. DONE.\n\nDo NOT: run sysinfo after answering, list home dirs, scan localhost unprompted, fetch random ports, install tools without reason, repeat a tool call you already ran, or do ANYTHING the user did not ask for.";
9
9
  export declare function renderAskSystemPrompt(): string;
10
10
  export declare function renderAgentSystemPrompt(toolList: string): string;
@@ -10,7 +10,7 @@ For every user request, respond with:
10
10
  4. Security caveats, OPSEC notes, and safer alternatives where applicable
11
11
 
12
12
  When advising on pentesting, follow standard methodology (recon → enumeration → exploitation → post-exploitation). Always note which phase the user is in and suggest logical next steps.`;
13
- const agentPrompt = `You are clai, a terminal AI agent specialized in cybersecurity, pentesting, and sysadmin.
13
+ const agentPrompt = `You are clai, a terminal AI agent. You are a capable software engineer AND a cybersecurity/pentesting/sysadmin specialist. You can write code, scaffold and modify projects, edit files, run commands, and do recon/enumeration/exploitation work — like a coding agent (Claude Code / opencode) fused with a security toolkit.
14
14
  OS: {{os}} | Shell: {{shell}} | CWD: {{cwd}}
15
15
  Current date/time: {{datetime}}
16
16
 
@@ -133,10 +133,38 @@ RESILIENT ERROR HANDLING:
133
133
  - Chain: fail → diagnose → fix/adapt → retry. Never stop at the first error.
134
134
 
135
135
  TASK PLANNING:
136
- - For complex multi-step tasks, break the work into logical steps yourself.
137
- Execute them one by one. You own the plan nothing is predetermined.
138
- - For simple tasks (single command, quick lookup), just execute immediately.
139
- - If a step fails, adapt your plan. Don't rigidly follow a broken path.
136
+ - BEFORE acting on any non-trivial task, decide: is this one quick step, or multiple steps?
137
+ · Simple (single command, quick lookup, one file) just execute immediately, no plan.
138
+ · Multi-step (scaffold a project, refactor across files, full recon, build a feature) → FIRST
139
+ write a short numbered plan (3-7 steps) in plain text, THEN execute the steps one by one.
140
+ - State the plan to the user before the first tool call so they can follow along. Example:
141
+ Plan:
142
+ 1. Inspect the current directory to understand what's here
143
+ 2. Read package.json / key files for context
144
+ 3. Scaffold the missing files
145
+ 4. Verify it builds/runs
146
+ Then proceed with step 1. Keep the plan concise — do not over-plan trivial work.
147
+ - As you finish steps, briefly note progress ("done 1-2, starting 3"). Adapt the plan if a step fails.
148
+ - You OWN the plan — nothing is predetermined. This applies to BOTH coding and security tasks
149
+ (e.g. a layered recon → enumeration → reporting flow is a plan too).
150
+
151
+ WORKING ON CODE & PROJECTS (act like a coding agent):
152
+ - "create X here" / "build X" / "add Y to this project" means work in the CURRENT directory ({{cwd}}).
153
+ - UNDERSTAND BEFORE YOU WRITE. Do not dump a generic template. First gather just enough context:
154
+ · fs.list the current directory (and key subdirs) to see what already exists.
155
+ · fs.read the files that matter (package.json, config, entry points, the file being changed).
156
+ · Use tool.batch to read several files at once instead of many sequential reads.
157
+ · Detect the existing stack/tooling (e.g. Vite vs CRA, the framework, the package manager) and
158
+ MATCH it. Never replace a project's tooling with a different one unless asked.
159
+ - Keep context lean: read what you need, not the whole tree. Skip node_modules, dist, .git, lockfiles.
160
+ - For a brand-new project, pick sensible modern defaults and say which you chose (e.g. "scaffolding
161
+ with Vite + React" ) — then create a MINIMAL working skeleton, not an overstuffed boilerplate.
162
+ - fs.write creates parent directories automatically — you can write "src/App.jsx" directly without a
163
+ separate mkdir. Do NOT call mkdir before fs.write.
164
+ - After writing files, verify when practical: list the tree you created, and if there's a build/test
165
+ command, run it (or tell the user the exact command to run, e.g. \`npm install && npm run dev\`).
166
+ - Prefer fs.edit for changing existing files; use fs.write for new files or full rewrites.
167
+ - For multi-file scaffolds: 1) give a one-line structure overview, 2) create the minimal files, 3) summarize.
140
168
 
141
169
  LOCAL NETWORK DISCOVERY:
142
170
  - "scan my network" / "find devices" / "what's on my LAN" → net.context FIRST (gets interfaces+CIDR), then net.pingSweep with discovered CIDR.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,SAAS,GAAG;;;;;;;;;;0LAUwK,CAAC;AAE3L,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+MAsK2L,CAAC;AAEhN,SAAS,MAAM,CAAC,QAAgB,EAAE,MAA8B;IAC9D,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAClC,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC,EAClE,QAAQ,CACT,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAG,GAAG,IAAI,IAAI,EAAE;IACrD,MAAM,KAAK,GAAG,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE;QAC1C,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,MAAM;QACb,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,SAAS;QACjB,YAAY,EAAE,OAAO;KACtB,CAAC,CAAC;IACH,OAAO,GAAG,KAAK,UAAU,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC;AAChD,CAAC;AAED;;;;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gB;IACtD,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAC9B,OAAO,MAAM,CAAC,WAAW,EAAE;QACzB,EAAE,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE;QACvD,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,QAAQ,EAAE,sBAAsB,EAAE;QAClC,SAAS,EAAE,QAAQ;KACpB,CAAC,CAAC;AACL,CAAC"}
package/dist/repl.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Mode, ProviderId } from "./types.js";
2
+ import { type FileSuggestion } from "./ui/mentions.js";
2
3
  export interface ReplOptions {
3
4
  mode?: Mode | undefined;
4
5
  provider?: ProviderId | undefined;
@@ -13,4 +14,5 @@ export interface SlashCommand {
13
14
  export declare function getKnownModels(provider: string): string[];
14
15
  export declare function getSlashCommandSuggestions(line: string): SlashCommand[];
15
16
  export declare function renderSlashCommandMenu(line: string, suggestions: SlashCommand[], selectedIndex: number): string[];
17
+ export declare function renderFileMentionMenu(query: string, suggestions: FileSuggestion[], selectedIndex: number): string[];
16
18
  export declare function startRepl(options?: ReplOptions): Promise<void>;
package/dist/repl.js CHANGED
@@ -16,6 +16,7 @@ import { modelSupportsThinking } from "./llm/capabilities.js";
16
16
  import { clearViewports, getLastViewport, getViewport, isPagerActive, listViewports, openViewportPager, toggleViewport, } from "./ui/output-pane.js";
17
17
  import { compactMessages, estimateMessagesTokens, } from "./agent/context-manager.js";
18
18
  import { isCtrlC, isCtrlO, isCtrlT, isEscape } from "./ui/keys.js";
19
+ import { getMentionQuery, findFileSuggestions, expandMentions, } from "./ui/mentions.js";
19
20
  const slashCommands = [
20
21
  { command: "/ask", description: "switch to ask mode" },
21
22
  { command: "/agent", description: "switch to agent mode" },
@@ -303,6 +304,31 @@ export function renderSlashCommandMenu(line, suggestions, selectedIndex) {
303
304
  }
304
305
  return items;
305
306
  }
307
+ export function renderFileMentionMenu(query, suggestions, selectedIndex) {
308
+ const cols = terminalColumns();
309
+ const maxWidth = Math.max(1, cols - 1);
310
+ if (suggestions.length === 0) {
311
+ return [
312
+ chalk.dim(fitPlain(` no files matching @${query}`, maxWidth)),
313
+ ];
314
+ }
315
+ const termRows = process.stdout.rows || 24;
316
+ const maxVisible = Math.max(5, termRows - 4);
317
+ const visible = suggestions.slice(0, maxVisible);
318
+ const items = visible.map((suggestion, index) => {
319
+ const markerPlain = index === selectedIndex ? "›" : " ";
320
+ const marker = index === selectedIndex ? chalk.magenta("›") : " ";
321
+ const prefix = ` ${markerPlain} `;
322
+ const labelBudget = Math.max(1, maxWidth - prefix.length);
323
+ const label = fitPlain(suggestion.label, labelBudget);
324
+ const colored = suggestion.isDir ? chalk.cyan(label) : chalk.white(label);
325
+ return ` ${marker} ${colored}`;
326
+ });
327
+ if (suggestions.length > maxVisible) {
328
+ items.push(chalk.dim(fitPlain(` … ${suggestions.length - maxVisible} more`, maxWidth)));
329
+ }
330
+ return items;
331
+ }
306
332
  function isPrintableSequence(sequence) {
307
333
  return sequence !== undefined && /^[^\x00-\x1f\x7f]+$/u.test(sequence);
308
334
  }
@@ -353,6 +379,7 @@ async function readPromptLine(options) {
353
379
  let selectedIndex = 0;
354
380
  let menuNavigated = false;
355
381
  let dismissedSlashLine = null;
382
+ let mentionDismissed = false;
356
383
  let historyIndex = null;
357
384
  let historyDraft = "";
358
385
  let lastCtrlCAt = 0;
@@ -369,12 +396,57 @@ async function readPromptLine(options) {
369
396
  selectedIndex = 0;
370
397
  return { visible: true, suggestions };
371
398
  };
399
+ // File @-mention autocomplete: active when the cursor sits inside an
400
+ // `@partial/path` token. Mutually exclusive with the slash menu (slash
401
+ // requires the line to start with "/" and contain no whitespace).
402
+ const getMentionState = () => {
403
+ if (mentionDismissed || line.startsWith("/")) {
404
+ return { visible: false, query: "", start: 0, suggestions: [] };
405
+ }
406
+ const q = getMentionQuery(line, cursor);
407
+ if (!q)
408
+ return { visible: false, query: "", start: 0, suggestions: [] };
409
+ const suggestions = findFileSuggestions(q.query);
410
+ if (suggestions.length === 0) {
411
+ return { visible: false, query: q.query, start: q.start, suggestions };
412
+ }
413
+ if (selectedIndex >= suggestions.length)
414
+ selectedIndex = 0;
415
+ return { visible: true, query: q.query, start: q.start, suggestions };
416
+ };
417
+ const applyMention = (suggestion, start) => {
418
+ const before = line.slice(0, start);
419
+ const after = line.slice(cursor);
420
+ let insert = `@${suggestion.value}`;
421
+ let newCursor = before.length + insert.length;
422
+ if (!suggestion.isDir) {
423
+ // Completed a file — add a trailing space and close the menu so the
424
+ // user can keep typing their request.
425
+ insert += " ";
426
+ newCursor = before.length + insert.length;
427
+ mentionDismissed = true;
428
+ }
429
+ else {
430
+ // Completed a directory — keep the menu open so the user drills in.
431
+ mentionDismissed = false;
432
+ }
433
+ line = before + insert + after;
434
+ cursor = newCursor;
435
+ selectedIndex = 0;
436
+ menuNavigated = false;
437
+ refresh();
438
+ };
372
439
  const refresh = () => {
373
440
  const cols = terminalColumns();
374
441
  const menu = getMenuState();
442
+ const mention = menu.visible
443
+ ? { visible: false, query: "", start: 0, suggestions: [] }
444
+ : getMentionState();
375
445
  const menuLines = menu.visible
376
446
  ? renderSlashCommandMenu(line, menu.suggestions, selectedIndex)
377
- : [];
447
+ : mention.visible
448
+ ? renderFileMentionMenu(mention.query, mention.suggestions, selectedIndex)
449
+ : [];
378
450
  const promptRows = buildPromptRows(line, cols, true);
379
451
  const target = promptCursorPosition(cursor, cols);
380
452
  const blockRows = [...promptRows, ...menuLines];
@@ -402,6 +474,7 @@ async function readPromptLine(options) {
402
474
  selectedIndex = 0;
403
475
  menuNavigated = false;
404
476
  dismissedSlashLine = null;
477
+ mentionDismissed = false;
405
478
  historyIndex = null;
406
479
  refresh();
407
480
  };
@@ -446,6 +519,9 @@ async function readPromptLine(options) {
446
519
  if (isPagerActive())
447
520
  return;
448
521
  const menu = getMenuState();
522
+ const mention = menu.visible
523
+ ? { visible: false, query: "", start: 0, suggestions: [] }
524
+ : getMentionState();
449
525
  // Cmd+C on macOS terminals is handled by the OS (it never reaches us),
450
526
  // but some Linux terminals forward Meta+C. Treat that as a no-op so
451
527
  // selecting + copying never breaks the REPL.
@@ -485,6 +561,10 @@ async function readPromptLine(options) {
485
561
  return;
486
562
  }
487
563
  if (key.name === "return" || key.name === "enter") {
564
+ if (mention.visible && mention.suggestions.length > 0) {
565
+ applyMention(mention.suggestions[selectedIndex] ?? mention.suggestions[0], mention.start);
566
+ return;
567
+ }
488
568
  const useSelection = menu.visible && (line !== "/" || menuNavigated);
489
569
  const selectedCommand = useSelection
490
570
  ? menu.suggestions[selectedIndex]
@@ -493,6 +573,10 @@ async function readPromptLine(options) {
493
573
  return;
494
574
  }
495
575
  if (key.name === "tab") {
576
+ if (mention.visible && mention.suggestions.length > 0) {
577
+ applyMention(mention.suggestions[selectedIndex] ?? mention.suggestions[0], mention.start);
578
+ return;
579
+ }
496
580
  if (menu.visible && menu.suggestions.length > 0) {
497
581
  const target = menu.suggestions[selectedIndex] ?? menu.suggestions[0];
498
582
  editLine(target.command, target.command.length);
@@ -500,6 +584,11 @@ async function readPromptLine(options) {
500
584
  return;
501
585
  }
502
586
  if (isEscape(key)) {
587
+ if (mention.visible) {
588
+ mentionDismissed = true;
589
+ refresh();
590
+ return;
591
+ }
503
592
  if (menu.visible) {
504
593
  dismissedSlashLine = line;
505
594
  refresh();
@@ -507,6 +596,14 @@ async function readPromptLine(options) {
507
596
  return;
508
597
  }
509
598
  if (key.name === "up") {
599
+ if (mention.visible && mention.suggestions.length > 0) {
600
+ selectedIndex =
601
+ (selectedIndex - 1 + mention.suggestions.length) %
602
+ mention.suggestions.length;
603
+ menuNavigated = true;
604
+ refresh();
605
+ return;
606
+ }
510
607
  if (menu.visible && menu.suggestions.length > 0) {
511
608
  selectedIndex =
512
609
  (selectedIndex - 1 + menu.suggestions.length) %
@@ -532,6 +629,12 @@ async function readPromptLine(options) {
532
629
  return;
533
630
  }
534
631
  if (key.name === "down") {
632
+ if (mention.visible && mention.suggestions.length > 0) {
633
+ selectedIndex = (selectedIndex + 1) % mention.suggestions.length;
634
+ menuNavigated = true;
635
+ refresh();
636
+ return;
637
+ }
535
638
  if (menu.visible && menu.suggestions.length > 0) {
536
639
  selectedIndex = (selectedIndex + 1) % menu.suggestions.length;
537
640
  menuNavigated = true;
@@ -1480,7 +1583,7 @@ async function handleSlash(line, state) {
1480
1583
  mode: state.mode,
1481
1584
  }));
1482
1585
  console.log(renderSuggestions());
1483
- console.log(chalk.dim(" ESC abort │ Ctrl+C clears input │ Ctrl+T or /think for thinking │ Ctrl+O opens full tool output (q to close)\n"));
1586
+ console.log(chalk.dim(" ESC abort │ Ctrl+C clears input │ @ to attach files │ Ctrl+T thinking │ Ctrl+O tool output (q to close)\n"));
1484
1587
  return true;
1485
1588
  }
1486
1589
  case "/update":
@@ -1635,7 +1738,7 @@ export async function startRepl(options = {}) {
1635
1738
  mode: state.mode,
1636
1739
  }));
1637
1740
  console.log(renderSuggestions());
1638
- console.log(chalk.dim(" ESC abort │ Ctrl+C clears input │ Ctrl+T or /think for thinking │ Ctrl+O opens full tool output (q to close)\n"));
1741
+ console.log(chalk.dim(" ESC abort │ Ctrl+C clears input │ @ to attach files │ Ctrl+T thinking │ Ctrl+O tool output (q to close)\n"));
1639
1742
  // Hint thinking-capable users that the toggle exists. We default it to
1640
1743
  // off for speed, since on NIM many models route through a much slower
1641
1744
  // chat-template path when reasoning is enabled.
@@ -1684,9 +1787,26 @@ export async function startRepl(options = {}) {
1684
1787
  clearThinking();
1685
1788
  abortPressCount = 0;
1686
1789
  let assistantContent = "";
1790
+ // Expand @file mentions and drag-and-dropped paths into real context.
1791
+ // The user-visible `line` stays readable in history; the model gets
1792
+ // the line plus an appended block of file contents / path notes.
1793
+ const expansion = expandMentions(line);
1794
+ const modelInput = expansion.contextBlock.length > 0
1795
+ ? `${line}\n\n${expansion.contextBlock}`
1796
+ : line;
1797
+ if (expansion.attachments.length > 0) {
1798
+ for (const att of expansion.attachments) {
1799
+ const tag = att.kind === "text"
1800
+ ? chalk.green("attached")
1801
+ : att.kind === "missing"
1802
+ ? chalk.red("not found")
1803
+ : chalk.yellow(att.kind);
1804
+ console.log(chalk.dim(` ↳ ${tag}: `) + chalk.dim(att.path));
1805
+ }
1806
+ }
1687
1807
  if (state.mode === "ask") {
1688
1808
  assistantContent = await withAbortableInput(async (signal) => streamWithAbort(async (runSignal, onToken) => {
1689
- return await runAskStream(line, onToken, {
1809
+ return await runAskStream(modelInput, onToken, {
1690
1810
  provider: state.provider,
1691
1811
  model: state.model,
1692
1812
  history: state.messages,
@@ -1696,7 +1816,7 @@ export async function startRepl(options = {}) {
1696
1816
  process.stdout.write("\n");
1697
1817
  }
1698
1818
  else {
1699
- assistantContent = await withAbortableInput(async (signal) => runAgent(line, {
1819
+ assistantContent = await withAbortableInput(async (signal) => runAgent(modelInput, {
1700
1820
  provider: state.provider,
1701
1821
  model: state.model,
1702
1822
  history: state.messages,
@@ -1705,7 +1825,7 @@ export async function startRepl(options = {}) {
1705
1825
  }));
1706
1826
  }
1707
1827
  console.log();
1708
- state.messages.push({ role: "user", content: line }, { role: "assistant", content: assistantContent });
1828
+ state.messages.push({ role: "user", content: modelInput }, { role: "assistant", content: assistantContent });
1709
1829
  }
1710
1830
  catch (error) {
1711
1831
  if (error instanceof AbortRunError) {