@sema-agent/core
Version:
Stateless, task-oriented AI agent core
23 lines (22 loc) • 2.07 kB
JavaScript
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)}.`;
}