feat(rumpk): Sovereign Core enhancements - NexShell IPC hardening & NipBox utility expansion
- Improved NexShell signal integrity by consolidating ION packet transmission. - Added 'ls' and enhanced 'matrix' control to NipBox (Sovereign Coreutils). - Added emergency matrix override to NexShell kernel mode. - Fixed 'command not found' errors caused by IPC fragmentation.
This commit is contained in:
parent
f6a49db00f
commit
c279744dc6
|
|
@ -0,0 +1,89 @@
|
|||
# src/npl/nipbox/nipbox.nim
|
||||
import std/[strutils, tables]
|
||||
|
||||
# --- COMMANDS ---
|
||||
|
||||
proc do_echo(args: seq[string]) =
|
||||
echo args.join(" ")
|
||||
|
||||
proc do_ls(args: seq[string]) =
|
||||
# A Sovereign 'ls' - eventually this will query the NPL filesystem
|
||||
echo ". .."
|
||||
echo "kernel subject"
|
||||
echo "matrix ion"
|
||||
echo "vault pki"
|
||||
|
||||
const CMD_GPU_MATRIX = 0x100
|
||||
const CMD_GPU_CLEAR = 0x101
|
||||
|
||||
proc nexus_syscall(cmd: uint32, arg: uint32): cint {.importc, cdecl.}
|
||||
|
||||
proc do_matrix(args: seq[string]) =
|
||||
let enable = if args.len > 0 and args[0] == "off": 0'u32 else: 1'u32
|
||||
let state = if enable == 1: "ON" else: "OFF"
|
||||
echo "[NipBox] Matrix Protocol: Setting state to " & state
|
||||
if nexus_syscall(CMD_GPU_MATRIX, enable) != 0:
|
||||
echo "[Error] Command Ring Full!"
|
||||
else:
|
||||
echo "[NipBox] Command Sent Successfully."
|
||||
|
||||
proc do_help(args: seq[string]) =
|
||||
echo "NipBox v0.1 (Sovereign Coreutils)"
|
||||
echo " echo [args...] : Print arguments"
|
||||
echo " ls : List sovereign objects"
|
||||
echo " matrix [on/off]: Toggle visualizer"
|
||||
echo " help : Show this message"
|
||||
echo " version : Show version info"
|
||||
|
||||
proc do_version(args: seq[string]) =
|
||||
echo "NipBox v0.1.0"
|
||||
echo "Built: 2025-12-31"
|
||||
echo "Architect: Markus Maiwald | Voxis Forge (AI)"
|
||||
|
||||
const CMD_GET_GPU_STATUS = 0x102
|
||||
|
||||
proc do_status(args: seq[string]) =
|
||||
echo "[NipBox] Querying GPU Status..."
|
||||
let status = nexus_syscall(CMD_GET_GPU_STATUS, 0)
|
||||
echo "GPU Status: ", if status == 1: "ONLINE (Retina Active)" else: "OFFLINE"
|
||||
|
||||
# --- DISPATCHER ---
|
||||
|
||||
const commands = {
|
||||
"echo": do_echo,
|
||||
"ls": do_ls,
|
||||
"matrix": do_matrix,
|
||||
"status": do_status,
|
||||
"help": do_help,
|
||||
"version": do_version
|
||||
}.toTable
|
||||
|
||||
proc main() =
|
||||
proc nexus_yield() {.importc, cdecl.}
|
||||
echo "\n[NipBox] Shell Ready. Waiting for orders..."
|
||||
|
||||
while true:
|
||||
stdout.write("root@nexus:# ")
|
||||
stdout.flushFile()
|
||||
|
||||
let line = try: stdin.readLine() except: ""
|
||||
|
||||
if line.len == 0:
|
||||
nexus_yield()
|
||||
continue
|
||||
|
||||
let parts = line.split(' ')
|
||||
if parts.len == 0: continue
|
||||
let cmd = parts[0]
|
||||
let args = if parts.len > 1: parts[1..^1] else: @[]
|
||||
|
||||
if commands.hasKey(cmd):
|
||||
commands[cmd](args)
|
||||
elif cmd == "exit":
|
||||
echo "[NipBox] Dropping to Kernel View..."
|
||||
break
|
||||
else:
|
||||
echo "nipbox: command not found: ", cmd
|
||||
|
||||
when isMainModule:
|
||||
main()
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
const std = @import("std");
|
||||
|
||||
// NEXUS IMMUNE SYSTEM (NPL) - THE VOICE & COMMAND PLANE
|
||||
// Markus Maiwald (Architect) | Voxis Forge (AI)
|
||||
|
||||
const std = @import("std");
|
||||
const ION_BASE = 0x83000000;
|
||||
|
||||
const IonPacket = extern struct {
|
||||
|
|
@ -32,10 +31,13 @@ const SysTable = extern struct {
|
|||
s_tx: *RingBuffer(IonPacket),
|
||||
s_event: *RingBuffer(IonPacket),
|
||||
s_cmd: *RingBuffer(CmdPacket),
|
||||
s_input: *RingBuffer(IonPacket),
|
||||
};
|
||||
|
||||
const CMD_ION_STOP = 1;
|
||||
const CMD_ION_START = 2;
|
||||
const CMD_GPU_MATRIX = 0x100;
|
||||
const CMD_GET_GPU_STATUS = 0x102;
|
||||
|
||||
// The Main Loop for the NexShell Fiber
|
||||
export fn nexshell_main() void {
|
||||
|
|
@ -93,19 +95,55 @@ export fn nexshell_main() void {
|
|||
}
|
||||
}
|
||||
|
||||
var forward_mode: bool = true;
|
||||
|
||||
fn process_command(cmd_text: []const u8, cmd_ring: *RingBuffer(CmdPacket)) void {
|
||||
if (cmd_text.len == 0) return;
|
||||
|
||||
if (forward_mode) {
|
||||
const is_toggle = std.mem.eql(u8, cmd_text, "kernel") or std.mem.eql(u8, cmd_text, "exit");
|
||||
|
||||
// ALWAYS FORWARD TO USERLAND first so it can process its own exit
|
||||
print("[NexShell] Forwarding to Subject...\n");
|
||||
|
||||
// Combine command + newline to avoid fragmentation
|
||||
if (cmd_text.len > 0) {
|
||||
var forward_buf: [128]u8 = undefined;
|
||||
const copy_len = if (cmd_text.len > 126) 126 else cmd_text.len;
|
||||
@memcpy(forward_buf[0..copy_len], cmd_text[0..copy_len]);
|
||||
forward_buf[copy_len] = '\n';
|
||||
ion_push_stdin(forward_buf[0 .. copy_len + 1].ptr, copy_len + 1);
|
||||
}
|
||||
|
||||
if (is_toggle) {
|
||||
forward_mode = false;
|
||||
print("[NexShell] Dropping to Kernel Debug Mode.\n");
|
||||
}
|
||||
} else {
|
||||
if (std.mem.eql(u8, cmd_text, "subject") or std.mem.eql(u8, cmd_text, "nipbox")) {
|
||||
forward_mode = true;
|
||||
print("[NexShell] Resuming Subject Pipe.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (std.mem.eql(u8, cmd_text, "io stop") or std.mem.eql(u8, cmd_text, "ion stop")) {
|
||||
print("[NexShell] Pushing CMD_ION_STOP...\n");
|
||||
push_cmd(cmd_ring, CMD_ION_STOP, 0);
|
||||
} else if (std.mem.eql(u8, cmd_text, "io start") or std.mem.eql(u8, cmd_text, "ion start")) {
|
||||
print("[NexShell] Pushing CMD_ION_START...\n");
|
||||
push_cmd(cmd_ring, CMD_ION_START, 0);
|
||||
} else if (cmd_text.len > 0) {
|
||||
print("[NexShell] Unknown Command: ");
|
||||
} else if (std.mem.eql(u8, cmd_text, "matrix on")) {
|
||||
print("[NexShell] Engaging Matrix Protocol (Emergency Override)...\n");
|
||||
push_cmd(cmd_ring, CMD_GPU_MATRIX, 1);
|
||||
} else if (std.mem.eql(u8, cmd_text, "matrix off")) {
|
||||
print("[NexShell] Disengaging Matrix Protocol...\n");
|
||||
push_cmd(cmd_ring, CMD_GPU_MATRIX, 0);
|
||||
} else if (std.mem.eql(u8, cmd_text, "matrix status")) {} else if (std.mem.eql(u8, cmd_text, "help")) {
|
||||
print("[NexShell] Kernel Commands: io stop, matrix on/off, matrix status, subject, help\n");
|
||||
} else {
|
||||
print("[NexShell] Unknown Kernel Command: ");
|
||||
print(cmd_text);
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn push_cmd(ring: *RingBuffer(CmdPacket), kind: u32, arg: u32) void {
|
||||
const head = @atomicLoad(u32, &ring.head, .acquire);
|
||||
|
|
@ -124,6 +162,7 @@ fn push_cmd(ring: *RingBuffer(CmdPacket), kind: u32, arg: u32) void {
|
|||
// OS Shims
|
||||
extern fn write(fd: c_int, buf: [*]const u8, count: usize) isize;
|
||||
extern fn console_read() c_int;
|
||||
extern fn ion_push_stdin(ptr: [*]const u8, len: usize) void;
|
||||
extern fn fiber_yield() void;
|
||||
|
||||
fn print(text: []const u8) void {
|
||||
|
|
|
|||
Loading…
Reference in New Issue