Skip to content

Shell Commands

tcsenpai edited this page Nov 28, 2026 · 4 revisions

Shell Commands

Purpose

The ringzero shell on COM1 and PS/2: how a typed line is routed to the agent, to a machine command (!name) or to a session command (/name), and what every command takes and does. Baseline of the code as of the OpenSpec adoption; the command table is CMDS in kernel/src/shell.rs and /help prints it.

Requirements

Requirement: Line routing

The shell SHALL send a line that does not start with ! or / to the agent as one user turn, with a leading @ and the spaces after it removed, and SHALL treat a line starting with ! as a machine command and a line starting with / as a session command. Source: kernel/src/shell.rs run, pre_of

Scenario: Plain text goes to the agent

  • WHEN the user types how much free memory do I have
  • THEN agent::ask receives that text and no command runs

Scenario: The old @ prefix still works

  • WHEN the user types @ hello
  • THEN the agent receives hello

Requirement: Wrong prefix and unknown command

The shell MUST NOT run a command typed with the wrong prefix; it SHALL print that the name is a machine or a session command and suggest the other prefix, and for a name that is in neither table it SHALL print unknown command '<line>'. Type /help, or type without <prefix> to ask the agent. Source: kernel/src/shell.rs run

Scenario: Session command typed with !

  • WHEN the user types undo with the ! prefix
  • THEN the shell prints 'undo' is a session command: try /undo and nothing is undone

Scenario: Unknown name

  • WHEN the user types a slash and a name that is in neither table
  • THEN the shell prints the unknown command line and the agent is not called

Requirement: Bare prefix lists commands

A line that is only ! or / SHALL print commands: followed by every command of that prefix; at the prompt, a bare ! or / left alone for 400 ms SHALL print the same list as a suggestion. Source: kernel/src/shell.rs run, readline

Scenario: Bare slash

  • WHEN the user types / and Enter
  • THEN the shell prints every session command name with its / prefix

Requirement: Line history and limits

The line editor SHALL recall the last 16 distinct lines with up and down, SHALL accept lines up to 16384 bytes at the prompt (history keeps lines up to 1024 bytes), and SHALL cancel the line on Ctrl-C. Source: kernel/src/shell.rs HIST, HIST_N, readline, LINE

Scenario: Ctrl-C cancels the line

  • WHEN the user types half a line and presses Ctrl-C
  • THEN the shell prints ^C and nothing runs

Requirement: Tab completion

Tab SHALL complete command names and the first argument from the command table: the longest common prefix, a trailing space when one candidate is left, a list when several are. Source: kernel/src/shell.rs redraw, candidates, suggest, add

Scenario: Tab completes a unique command

  • WHEN the user types /hib (a prefix of hibernate) and Tab
  • THEN the line becomes /hibernate with a trailing space

Scenario: Tab completes an argument

  • WHEN the user types !kbd u and Tab
  • THEN the line becomes !kbd us

Requirement: Confirmation questions

A y/N question SHALL confirm only on an answer of y or yes (any case, spaces trimmed); every other answer, an empty line and Ctrl-C SHALL mean no, and each answer SHALL be recorded in the kernel log as confirmation: yes or confirmation: no. Source: kernel/src/shell.rs readline, confirm

Scenario: Enter means no

  • WHEN a command asks [y/N] and the user presses Enter
  • THEN the answer is no and the action does not run

Requirement: Hidden test commands

The shell SHALL accept two commands that are not in the table or in /help, with either prefix: toks prints the boot prefix token ids, and fault reads an unmapped address to test the page fault handler (the machine halts). Source: kernel/src/shell.rs run

Scenario: Prefix token dump

  • WHEN the user types /toks
  • THEN the boot prefix token ids are printed comma separated

Requirement: Help command

!help and /help SHALL print the introduction, every machine command under ! machine commands: and every session command under / session commands:, each with its help text from the command table, then the editing and snapshot notes. Source: kernel/src/shell.rs CMDS, help, run

Scenario: Help lists both tables

  • WHEN the user types /help
  • THEN every entry of CMDS is printed once per prefix it has, /stats and !stats included

Requirement: Machine information commands

!mem SHALL print total and free memory, the model and the engine arena; !cpu the CPU model, clock and features; !uptime the time since boot; !cores [N] the cores online after setting the inference cores to N when N is given; !log [N] the last N kernel log lines, 20 when N is missing or not a number. Source: kernel/src/shell.rs CMDS, run

Scenario: Default log length

  • WHEN the user types !log
  • THEN the last 20 kernel log lines are printed

Scenario: Cores with an argument

  • WHEN the user types !cores 2
  • THEN the cores setting is applied as !set cores 2 and the core list is printed

Requirement: Keyboard command

!kbd without an argument SHALL print the current layout and (available: us, it); !kbd us or !kbd it SHALL set the layout like !set keyboard. Source: kernel/src/shell.rs CMDS, run

Scenario: Show the layout

  • WHEN the user types !kbd
  • THEN the shell prints keyboard layout it (available: us, it) on a fresh boot

Requirement: Set command

!set <key> <value> SHALL apply one setting through the same function the agent's set_setting tool uses and print its result line; the keys are specified by the settings capability. Source: kernel/src/shell.rs SETTINGS, CMDS, run

Scenario: Set a key

  • WHEN the user types !set temperature 0.7
  • THEN the shell prints temperature = 0.7 (top-p 0.95 sampling)

Requirement: Park command

!park off|idle|<usec> SHALL set worker core parking to off (always spin), idle (spin during a generation, park between requests) or always with that spin window, and SHALL print the mode; without a valid argument it SHALL only print the current mode. The default is idle. Source: kernel/src/shell.rs CMDS, run; kernel/src/smp.rs PARK

Scenario: Query parking

  • WHEN the user types !park on a fresh boot
  • THEN the shell prints [park] idle (spin during a generation, park between requests)

Requirement: Stats command

!stats and /stats SHALL print one [stats] line with threads, parked cores, wake IPIs, arena and heap use, agent context fill against the maximum, KV type and keyboard layout. Source: kernel/src/shell.rs CMDS, run

Scenario: Stats line

  • WHEN the user types !stats
  • THEN one line starting with [stats] threads is printed

Requirement: File write commands

!write PATH TEXT SHALL create or replace the file with TEXT trimmed and \n turned into new lines, and queue it for the memory index; !mkdir PATH SHALL create the directory and missing parents; !sync SHALL flush the disk. Errors SHALL print as [fs] <cmd>: <error>. Source: kernel/src/shell.rs CMDS, fs_cmd

Scenario: Write with new lines

  • WHEN the user types !write /a.txt one\ntwo
  • THEN /a.txt holds two lines and the shell prints [fs] wrote 7 bytes to /a.txt

Requirement: File read commands

!ls [PATH] SHALL list a directory (default /, (empty) for none); !cat PATH SHALL print at most the first 64 KiB and say how many bytes were shown; !df SHALL print disk size and free space. Source: kernel/src/shell.rs CMDS, fs_cmd

Scenario: Long file

  • WHEN the user types !cat on a 100 KiB file
  • THEN 65536 bytes are printed and [fs] first 65536 of 102400 bytes shown

Requirement: Delete command asks

!rm PATH SHALL refuse a non-empty directory without -r (directory is not empty (use !rm -r)), SHALL ask y/N naming the file and its size or the directory and its entry count, and SHALL delete only on yes, dropping the file's memory index chunks; on no it SHALL print [fs] kept PATH. Source: kernel/src/shell.rs CMDS, fs_cmd

Scenario: Declined delete

  • WHEN the user types !rm /a.txt and answers n
  • THEN the file stays and the shell prints [fs] kept /a.txt

Requirement: Program commands

!py CODE and !py -f PATH SHALL run MicroPython; !wasm PATH|NAME [ARGS] [< FILE] SHALL run a WASI program, NAME meaning /bin/NAME.wasm, and !run SHALL be the same command as !wasm. Limits are specified by the programs capability. Source: kernel/src/shell.rs CMDS, run

Scenario: run is wasm

  • WHEN the user types !run wc -l /demo/notes.txt
  • THEN the same code path as !wasm wc -l /demo/notes.txt runs

Requirement: Power commands

!poweroff and !reboot SHALL act at once, without a question, when typed by the user at the shell; both SHALL shut agentd down and sync the disk first, and !poweroff SHALL also write the hibernation image unless /hibernate discard turned that off. Source: kernel/src/shell.rs CMDS, run; kernel/src/sys.rs poweroff, reboot

Scenario: Poweroff from the shell

  • WHEN the user types !poweroff
  • THEN the machine powers off without a y/N question

Requirement: Conversation commands

/clear SHALL clear the screen and start a new conversation from the boot prefix, keeping the old one in /tree; /ctx SHALL print the context fill out of the maximum; /compact SHALL summarize and rebuild the context now and then print the fill; /history [N] SHALL print the last N raw transcript lines, 40 by default, kept across compactions. Source: kernel/src/shell.rs CMDS, run; kernel/src/agent.rs floor_char, ctx_info

Scenario: Clear keeps the old line

  • WHEN the user types /clear
  • THEN the shell prints [agent] new conversation from the boot prefix (the old one stays in /tree)

Requirement: Session setting shortcuts

/think on|off SHALL set the think setting and /temp <0..2> SHALL set the temperature setting, both through the settings function. Source: kernel/src/shell.rs CMDS, run

Scenario: Greedy shortcut

  • WHEN the user types /temp 0
  • THEN the shell prints temperature = 0 (greedy)

Requirement: Snapshot commands

The shell SHALL offer /undo [N] and /redo [N] (N defaults to 1), /retry, /tree [all], /branch NAME, /switch NAME|#ID, /save NAME, /load NAME (the same code as /switch), /drop NAME|#ID, /snap and /hibernate [discard|status]; /branch, /switch, /save, /load and /drop without an argument SHALL print usage: /<cmd> NAME. Their behaviour is specified by the snapshots-hibernation capability. Source: kernel/src/shell.rs CMDS, run

Scenario: Missing name

  • WHEN the user types /save
  • THEN the shell prints usage: /save NAME

Requirement: Retry command

/retry SHALL undo the last turn and ask its question again, reseeding the sampler when the temperature is above 0; with no question at the current point it SHALL print [retry] nothing to retry here (no question at this point). Source: kernel/src/shell.rs CMDS; kernel/src/agent.rs resume, retry

Scenario: Retry at temperature 0

  • WHEN the temperature is 0 and the user types /retry
  • THEN the same question is asked again from the previous point

Requirement: Memory commands

The shell SHALL offer /agentd [log [N]] (status and the last 10 decisions, or the last N decisions, 30 by default), /facts, /remember KEY VALUE (source user), /forget KEY (asks y/N, prints [facts] kept on no), /consolidate, /embed [-q] [-v] TEXT, /index add TEXT|stats|clear|dim N and /search QUERY (top 5). Their behaviour is specified by the memory capability. Source: kernel/src/shell.rs CMDS, run, set_setting, search_cmd

Scenario: Forget asks

  • WHEN the user types /forget user_name and answers n
  • THEN the fact stays and the shell prints [facts] kept

Scenario: Remember without a value

  • WHEN the user types /remember name
  • THEN the shell prints usage: /remember KEY VALUE

Requirement: Manual command

/man [TOPIC|check] SHALL search the built-in manual; its behaviour is specified by the manual capability. Source: kernel/src/shell.rs CMDS, run

Scenario: Manual lookup

  • WHEN the user types /man undo
  • THEN agentd::man runs with the argument undo

Requirement: Benchmark and debug commands

/bench SHALL run a 64-token decode bench, /fill [tokens] a prefill and decode at that fill (1024 by default), /prefill [B] [avx2|vnni] a timed boot prefix prefill, /spec [N] a check of N speculative verifier positions (16 by default) and /gen <n> <text> greedy ids with logit margins. Source: kernel/src/shell.rs CMDS, run

Scenario: gen usage

  • WHEN the user types /gen 5
  • THEN the shell prints usage: /gen <max tokens> <prompt text>

Requirement: Benches restore the conversation

Each bench and debug command SHALL run from position 0 and put the conversation back afterwards. Source: kernel/src/shell.rs run; kernel/src/agent.rs note, resume

Scenario: Conversation restored after a bench

  • WHEN the user types /bench in the middle of a conversation
  • THEN after the bench the shell prints [snap] conversation restored (ctx N) with the same N as before

Requirement: Multi-stream check command

/multi [N] [T] SHALL run N streams (all streams by default) of T greedy tokens each (64 by default, EOS ignored), first every stream alone on the agent's context and then all of them together, one row per stream per pass, and SHALL print the tok/s of both and, per stream, whether the ids and every step's logits are the same. Source: kernel/src/shell.rs CMDS, run; kernel/src/multi.rs bench

Scenario: multi-stream check

  • WHEN the user types /multi 2
  • THEN the shell prints [multi] 2 streams: the agent's context + 1 slots of 4096 positions lent by the snapshot pool (M MiB each), [multi] 2 streams x 64 tokens: alone A tok/s per stream; together B tok/s aggregate (Rx), C tok/s per stream and one [multi] stream S: prompt P tok, ids same (fnv 0x...), logits same line per stream

Source of this page: openspec/specs/shell-commands/spec.md

Clone this wiki locally