Tweak programs, filesystem, overlays

This commit is contained in:
osmarks 2024-09-03 10:34:52 +01:00
parent 991dd92c5b
commit 233bd28aab
7 changed files with 81 additions and 38 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,60 @@
local prefixes = {
{-12, "p"},
{-9, "n"},
{-6, "u"},
{-3, "m"},
{0, ""},
{3, "k"},
{6, "M"}
}
local function SI_prefix(value, unit)
local x = math.log(value, 10)
local last
for _, t in ipairs(prefixes) do
if t[1] > x then
break
end
last = t
end
local dp = 2 - math.floor(x - last[1])
return (("%%.%df%%s%%s"):format(dp)):format(value / 10^(last[1]), last[2], unit)
end
local w = term.getSize()
local rows = {}
for _, info in pairs(process.list()) do
textutils.pagedPrint(("%s %f %f"):format(info.name or info.ID, info.execution_time, info.ctime))
table.insert(rows, { info.name or tostring(info.ID), SI_prefix(info.execution_time, "s"), SI_prefix(info.ctime, "s") })
end
local max_width_per_column = {}
for _, row in ipairs(rows) do
for i, cell in ipairs(row) do
max_width_per_column[i] = math.max(max_width_per_column[i] or 0, cell:len() + 1)
end
end
local vw_width = 0
for i = #max_width_per_column, 1, -1 do
if i > 1 then
vw_width = vw_width + max_width_per_column[i]
end
end
local fw_start = w - vw_width
for _, row in ipairs(rows) do
local s
for i, cell in ipairs(row) do
if i == 1 then
s = cell:sub(1, fw_start - 1) .. (" "):rep((fw_start - 1) - cell:len())
else
cell = " " .. cell
s = s .. (" "):rep(max_width_per_column[i] - cell:len()) .. cell
end
end
textutils.pagedPrint(s)
end

View File

@ -24,7 +24,7 @@ print()
print(snd)
print()
if arg == "headless" then
ccemux.echo "ready"
if ccemux then ccemux.echo "ready" end
while true do coroutine.yield() end
else
print "Press a key to continue..."

View File

@ -405,30 +405,11 @@ local gf, sf = getfenv, setfenv
-- a map of paths to either strings containing their contents or functions returning them
-- and a table of extra APIs and partial overrides for existing APIs
local function make_environment(API_overrides, current_process)
local env_host = string.format("YAFSS on %s", _HOST)
local environment = copy_some_keys(allowed_APIs)(_G)
-- if function is not from within the VM, return env from within sandbox
function environment.getfenv(arg)
local env
if type(arg) == "number" then return gf() end
if not env or type(env._HOST) ~= "string" or not env._HOST == env_host then
return gf()
else
return env
end
end
--[[
Fix PS#AD2A532C
Allowing `setfenv` to operate on any function meant that privileged code could in some cases be manipulated to leak information or operate undesirably. Due to this, we restrict it, similarly to getfenv.
]]
function environment.setfenv(fn, env)
local nenv = gf(fn)
if not nenv or type(nenv._HOST) ~= "string" or not nenv._HOST == env_host then
return false
end
return sf(fn, env)
end
-- I sure hope this doesn't readd the security issues!
environment.getfenv = getfenv
environment.setfenv = setfenv
local load = load
function environment.load(code, file, mode, env)
@ -437,7 +418,6 @@ Allowing `setfenv` to operate on any function meant that privileged code could i
environment._G = environment
environment._ENV = environment
environment._HOST = env_host
function environment.os.shutdown()
process.IPC(current_process, "power_state", "shutdown")
@ -485,4 +465,4 @@ local function run(API_overrides, init, logger)
end
end
return { run = run, create_FS = create_FS }
return { run = run, create_FS = create_FS }

View File

@ -459,13 +459,18 @@ local old_error = error
local old_os_shutdown = os.shutdown
local old_term_redirect = term.redirect
local old_term_native = term.native
local old_printError = printError
function error() end
function term.redirect() end
function term.native() end
function printError() end
function os.shutdown()
error = old_error
_G.error = old_error
_ENV.error = old_error
printError = old_printError
_G.printError = old_printError
_ENV.printError = old_printError
term.native = old_term_native
term.redirect = old_term_redirect
os.shutdown = old_os_shutdown

View File

@ -391,6 +391,12 @@ do
local native = term.native()
local last_redirected
-- horrors
local idmap = {}
local function termid(t)
return idmap[tostring(t.blit)]
end
local ix = 0
process.spawn(function()
while true do
@ -408,17 +414,11 @@ do
ix = ix + 1
process.queue_in(process.get_running().parent, "term_resize", true)
elseif ev == "ipc" and arg2 == "redraw_native" then
potatOS.framebuffers[native.id].redraw()
potatOS.framebuffers[termid(native)].redraw()
end
end
end, "termd")
-- horrors
local idmap = {}
local function termid(t)
return idmap[tostring(t.blit)]
end
local function assignid(t)
if not termid(t) then idmap[tostring(t.blit)] = potatOS.gen_uuid() end
end
@ -1245,7 +1245,8 @@ function potatOS.llm(prompt, max_tokens, stop_sequences)
local res, err = http.post("https://gpt.osmarks.net/v1/completions", json.encode {
prompt = prompt,
max_tokens = max_tokens,
stop = stop_sequences
stop = stop_sequences,
client = "potatOS"
}, {["content-type"]="application/json"}, true)
if err then
error("Server error: " .. err) -- is this right? I forgot.
@ -1608,7 +1609,7 @@ function potatOS.threat_update()
table.insert(out, description)
table.insert(out, "")
end
return (potatOS.llm(table.concat(out, "\n"), 100, {"\n\n"}):gsub("^\n", ""):gsub("\n$", ""))
return "current threat level is" .. (potatOS.llm(table.concat(out, "\n") .. "\ncurrent threat level is", 100, {"\n\n"}):gsub("^\n", ""):gsub("\n$", ""))
end
local fixed_context = {

View File

@ -57,7 +57,7 @@ button {
<h1>Welcome to PotatOS!</h1>
<img src="/potatos.gif" id="im">
<div>
Current build: <code>361bc871</code> (adjust LLM interface), version 771, built 2024-02-28 19:50:26 (UTC).
Current build: <code>9331d6eb</code> (misc fixes to ctime, filesystem, overlays), version 784, built 2024-09-03 09:34:30 (UTC).
</div>
<p>&quot;PotatOS&quot; stands for &quot;PotatOS Otiose Transformative Advanced Technology Or Something&quot;.
<a href="https://git.osmarks.net/osmarks/potatOS">This repository</a> contains the source code for the latest version of PotatOS, &quot;PotatOS Epenthesis&quot;.