UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

30 lines (29 loc) • 2.89 kB
function bgReapClause(sessionScoped, envIsolatedOwned) { if (!sessionScoped) return "when this task ends"; return envIsolatedOwned ? "at session end, not when this task ends — UNLESS this task's own isolated sandbox is torn down, which reaps it right then instead" : "at session end, not when this task ends: it keeps running across tasks in the same session, and a later task can still read its output or stop it"; } function bgNohupCaveat(envIsolatedOwned) { return envIsolatedOwned ? " — on a per-task isolated sandbox this only helps if the sandbox itself survives; if the deployment tears it down at task end, host the deliverable outside the sandbox instead" : ""; } function bgRetainedIsolatedNote() { return " Background processes are retained here — normally one keeps running past this task and the session. The one exception: a per-task isolated sandbox that gets torn down still reaps it right then despite the retention declaration; if the deliverable must survive that too, host it outside the sandbox instead."; } export function backgroundLifetimeNote(retained, sessionScoped, envIsolatedOwned, face = "receipt") { if (retained) return envIsolatedOwned ? bgRetainedIsolatedNote() : ""; if (face === "description") return ` Background processes do NOT survive the session — they are reaped ${bgReapClause(sessionScoped, envIsolatedOwned)}. A deliverable that must stay alive afterwards (a server, a daemon) needs a self-detaching FOREGROUND start instead: run \`nohup cmd >log 2>&1 &\` as a normal foreground command (portable; setsid does not exist on macOS), or use a service manager${bgNohupCaveat(envIsolatedOwned)}.`; return ` NOTE: background processes do NOT survive the session (reaped ${bgReapClause(sessionScoped, envIsolatedOwned)}). If this is a deliverable service that must stay alive afterwards, host it with a FOREGROUND command instead: \`nohup cmd >log 2>&1 &\` (self-detaching — survives the session)${bgNohupCaveat(envIsolatedOwned)}.`; } export const BASH_BACKGROUND_UNAVAILABLE = "Error (Bash): run_in_background is not available here — this environment cannot run background processes, or no completion would come back from one on this mount. Run the command in the foreground (with a timeout)."; export function backgroundOutputFileNote(outputFile) { return outputFile !== undefined ? ` Output file: ${outputFile} (full output is appended there — Read it any time).` : " No output file could be created for it — its completion notification says whether any of its output was kept and how to read it."; } export const ONE_SHOT_BACKGROUND_COMMAND_NOTE = "This is a one-shot submission — the engine does not wait for background commands; run it in the foreground (with a timeout) if you need its output before the submission ends.";